Annotation of loncom/interface/loncommon.pm, revision 1.1469
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1469 ! raeburn 4: # $Id: loncommon.pm,v 1.1468 2025/03/02 05:22:45 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.1383 raeburn 64: use Apache::lonnavmaps();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1409 raeburn 74: use LONCAPA::ltiutils;
1.1280 raeburn 75: use LONCAPA::LWPReq;
1.1395 raeburn 76: use LONCAPA::map();
1.1328 raeburn 77: use HTTP::Request;
1.657 raeburn 78: use DateTime::TimeZone;
1.1241 raeburn 79: use DateTime::Locale;
1.1220 raeburn 80: use Encode();
1.1091 foxr 81: use Text::Aspell;
1.1094 raeburn 82: use Authen::Captcha;
83: use Captcha::reCAPTCHA;
1.1234 raeburn 84: use JSON::DWIW;
1.1174 raeburn 85: use Crypt::DES;
86: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 87: use MIME::Lite;
88: use MIME::Types;
1.1292 raeburn 89: use File::Copy();
1.1300 raeburn 90: use File::Path();
1.1309 raeburn 91: use String::CRC32();
92: use Short::URL();
1.117 www 93:
1.517 raeburn 94: # ---------------------------------------------- Designs
95: use vars qw(%defaultdesign);
96:
1.22 www 97: my $readit;
98:
1.517 raeburn 99:
1.157 matthew 100: ##
101: ## Global Variables
102: ##
1.46 matthew 103:
1.643 foxr 104:
105: # ----------------------------------------------- SSI with retries:
106: #
107:
108: =pod
109:
1.648 raeburn 110: =head1 Server Side include with retries:
1.643 foxr 111:
112: =over 4
113:
1.648 raeburn 114: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 115:
116: Performs an ssi with some number of retries. Retries continue either
117: until the result is ok or until the retry count supplied by the
118: caller is exhausted.
119:
120: Inputs:
1.648 raeburn 121:
122: =over 4
123:
1.643 foxr 124: resource - Identifies the resource to insert.
1.648 raeburn 125:
1.643 foxr 126: retries - Count of the number of retries allowed.
1.648 raeburn 127:
1.643 foxr 128: form - Hash that identifies the rendering options.
129:
1.648 raeburn 130: =back
131:
132: Returns:
133:
134: =over 4
135:
1.643 foxr 136: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 137:
1.643 foxr 138: response - The response from the last attempt (which may or may not have been successful.
139:
1.648 raeburn 140: =back
141:
142: =back
143:
1.643 foxr 144: =cut
145:
146: sub ssi_with_retries {
147: my ($resource, $retries, %form) = @_;
148:
149:
150: my $ok = 0; # True if we got a good response.
151: my $content;
152: my $response;
153:
154: # Try to get the ssi done. within the retries count:
155:
156: do {
157: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
158: $ok = $response->is_success;
1.650 www 159: if (!$ok) {
160: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
161: }
1.643 foxr 162: $retries--;
163: } while (!$ok && ($retries > 0));
164:
165: if (!$ok) {
166: $content = ''; # On error return an empty content.
167: }
168: return ($content, $response);
169:
170: }
171:
172:
173:
1.20 www 174: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 175: my %language;
1.124 www 176: my %supported_language;
1.1088 foxr 177: my %supported_codes;
1.1048 foxr 178: my %latex_language; # For choosing hyphenation in <transl..>
179: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 180: my %cprtag;
1.192 taceyjo1 181: my %scprtag;
1.351 www 182: my %fe; my %fd; my %fm;
1.41 ng 183: my %category_extensions;
1.12 harris41 184:
1.46 matthew 185: # ---------------------------------------------- Thesaurus variables
1.144 matthew 186: #
187: # %Keywords:
188: # A hash used by &keyword to determine if a word is considered a keyword.
189: # $thesaurus_db_file
190: # Scalar containing the full path to the thesaurus database.
1.46 matthew 191:
192: my %Keywords;
193: my $thesaurus_db_file;
194:
1.144 matthew 195: #
196: # Initialize values from language.tab, copyright.tab, filetypes.tab,
197: # thesaurus.tab, and filecategories.tab.
198: #
1.18 www 199: BEGIN {
1.46 matthew 200: # Variable initialization
201: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
202: #
1.22 www 203: unless ($readit) {
1.12 harris41 204: # ------------------------------------------------------------------- languages
205: {
1.158 raeburn 206: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
207: '/language.tab';
1.1317 raeburn 208: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 209: while (my $line = <$fh>) {
210: next if ($line=~/^\#/);
211: chomp($line);
1.1088 foxr 212: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 213: $language{$key}=$val.' - '.$enc;
214: if ($sup) {
215: $supported_language{$key}=$sup;
1.1088 foxr 216: $supported_codes{$key} = $code;
1.158 raeburn 217: }
1.1048 foxr 218: if ($latex) {
219: $latex_language_bykey{$key} = $latex;
1.1088 foxr 220: $latex_language{$code} = $latex;
1.1048 foxr 221: }
1.158 raeburn 222: }
223: close($fh);
224: }
1.12 harris41 225: }
226: # ------------------------------------------------------------------ copyrights
227: {
1.158 raeburn 228: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
229: '/copyright.tab';
1.1317 raeburn 230: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 231: while (my $line = <$fh>) {
232: next if ($line=~/^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 235: $cprtag{$key}=$val;
236: }
237: close($fh);
238: }
1.12 harris41 239: }
1.351 www 240: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 241: {
242: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
243: '/source_copyright.tab';
1.1317 raeburn 244: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 249: $scprtag{$key}=$val;
250: }
251: close($fh);
252: }
253: }
1.63 www 254:
1.517 raeburn 255: # -------------------------------------------------------------- default domain designs
1.63 www 256: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 257: my $designfile = $designdir.'/default.tab';
1.1317 raeburn 258: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 259: while (my $line = <$fh>) {
260: next if ($line =~ /^\#/);
261: chomp($line);
262: my ($key,$val)=(split(/\=/,$line));
263: if ($val) { $defaultdesign{$key}=$val; }
264: }
265: close($fh);
1.63 www 266: }
267:
1.15 harris41 268: # ------------------------------------------------------------- file categories
269: {
1.158 raeburn 270: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
271: '/filecategories.tab';
1.1317 raeburn 272: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 273: while (my $line = <$fh>) {
274: next if ($line =~ /^\#/);
275: chomp($line);
276: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 277: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 278: }
279: close($fh);
280: }
281:
1.15 harris41 282: }
1.12 harris41 283: # ------------------------------------------------------------------ file types
284: {
1.158 raeburn 285: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
286: '/filetypes.tab';
1.1317 raeburn 287: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 288: while (my $line = <$fh>) {
289: next if ($line =~ /^\#/);
290: chomp($line);
291: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 292: if ($descr ne '') {
293: $fe{$ending}=lc($emb);
294: $fd{$ending}=$descr;
1.351 www 295: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 296: }
297: }
298: close($fh);
299: }
1.12 harris41 300: }
1.22 www 301: &Apache::lonnet::logthis(
1.705 tempelho 302: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 303: $readit=1;
1.46 matthew 304: } # end of unless($readit)
1.32 matthew 305:
306: }
1.112 bowersj2 307:
1.42 matthew 308: ###############################################################
309: ## HTML and Javascript Helper Functions ##
310: ###############################################################
311:
312: =pod
313:
1.112 bowersj2 314: =head1 HTML and Javascript Functions
1.42 matthew 315:
1.112 bowersj2 316: =over 4
317:
1.648 raeburn 318: =item * &browser_and_searcher_javascript()
1.112 bowersj2 319:
320: X<browsing, javascript>X<searching, javascript>Returns a string
321: containing javascript with two functions, C<openbrowser> and
322: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
323: tags.
1.42 matthew 324:
1.648 raeburn 325: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 326:
327: inputs: formname, elementname, only, omit
328:
329: formname and elementname indicate the name of the html form and name of
330: the element that the results of the browsing selection are to be placed in.
331:
332: Specifying 'only' will restrict the browser to displaying only files
1.185 www 333: with the given extension. Can be a comma separated list.
1.42 matthew 334:
335: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 336: with the given extension. Can be a comma separated list.
1.42 matthew 337:
1.648 raeburn 338: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 339:
340: Inputs: formname, elementname
341:
342: formname and elementname specify the name of the html form and the name
343: of the element the selection from the search results will be placed in.
1.542 raeburn 344:
1.42 matthew 345: =cut
346:
347: sub browser_and_searcher_javascript {
1.199 albertel 348: my ($mode)=@_;
349: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 350: my $resurl=&escape_single(&lastresurl());
1.42 matthew 351: return <<END;
1.219 albertel 352: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 353: var editbrowser = null;
1.135 albertel 354: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 355: var url = '$resurl/?';
1.42 matthew 356: if (editbrowser == null) {
357: url += 'launch=1&';
358: }
359: url += 'catalogmode=interactive&';
1.199 albertel 360: url += 'mode=$mode&';
1.611 albertel 361: url += 'inhibitmenu=yes&';
1.42 matthew 362: url += 'form=' + formname + '&';
363: if (only != null) {
364: url += 'only=' + only + '&';
1.217 albertel 365: } else {
366: url += 'only=&';
367: }
1.42 matthew 368: if (omit != null) {
369: url += 'omit=' + omit + '&';
1.217 albertel 370: } else {
371: url += 'omit=&';
372: }
1.135 albertel 373: if (titleelement != null) {
374: url += 'titleelement=' + titleelement + '&';
1.217 albertel 375: } else {
376: url += 'titleelement=&';
377: }
1.42 matthew 378: url += 'element=' + elementname + '';
379: var title = 'Browser';
1.435 albertel 380: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 381: options += ',width=700,height=600';
382: editbrowser = open(url,title,options,'1');
383: editbrowser.focus();
384: }
385: var editsearcher;
1.135 albertel 386: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 387: var url = '/adm/searchcat?';
388: if (editsearcher == null) {
389: url += 'launch=1&';
390: }
391: url += 'catalogmode=interactive&';
1.199 albertel 392: url += 'mode=$mode&';
1.42 matthew 393: url += 'form=' + formname + '&';
1.135 albertel 394: if (titleelement != null) {
395: url += 'titleelement=' + titleelement + '&';
1.217 albertel 396: } else {
397: url += 'titleelement=&';
398: }
1.42 matthew 399: url += 'element=' + elementname + '';
400: var title = 'Search';
1.435 albertel 401: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 402: options += ',width=700,height=600';
403: editsearcher = open(url,title,options,'1');
404: editsearcher.focus();
405: }
1.219 albertel 406: // END LON-CAPA Internal -->
1.42 matthew 407: END
1.170 www 408: }
409:
410: sub lastresurl {
1.258 albertel 411: if ($env{'environment.lastresurl'}) {
412: return $env{'environment.lastresurl'}
1.170 www 413: } else {
414: return '/res';
415: }
416: }
417:
418: sub storeresurl {
419: my $resurl=&Apache::lonnet::clutter(shift);
420: unless ($resurl=~/^\/res/) { return 0; }
421: $resurl=~s/\/$//;
422: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 423: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 424: return 1;
1.42 matthew 425: }
426:
1.74 www 427: sub studentbrowser_javascript {
1.111 www 428: unless (
1.258 albertel 429: (($env{'request.course.id'}) &&
1.302 albertel 430: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
431: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
432: '/'.$env{'request.course.sec'})
433: ))
1.258 albertel 434: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 435: ) { return ''; }
1.74 www 436: return (<<'ENDSTDBRW');
1.776 bisitz 437: <script type="text/javascript" language="Javascript">
1.824 bisitz 438: // <![CDATA[
1.74 www 439: var stdeditbrowser;
1.1413 raeburn 440: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv,uident) {
1.74 www 441: var url = '/adm/pickstudent?';
442: var filter;
1.558 albertel 443: if (!ignorefilter) {
444: eval('filter=document.'+formname+'.'+uname+'.value;');
445: }
1.74 www 446: if (filter != null) {
447: if (filter != '') {
448: url += 'filter='+filter+'&';
449: }
450: }
451: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 452: '&udomelement='+udom+
453: '&clicker='+clicker;
1.111 www 454: if (roleflag) { url+="&roles=1"; }
1.1337 raeburn 455: if (courseadv == 'condition') {
456: if (document.getElementById('courseadv')) {
457: courseadv = document.getElementById('courseadv').value;
458: }
459: }
460: if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.1413 raeburn 461: if (uident !== '') { url+="&identelement="+uident; }
1.102 www 462: var title = 'Student_Browser';
1.74 www 463: var options = 'scrollbars=1,resizable=1,menubar=0';
464: options += ',width=700,height=600';
465: stdeditbrowser = open(url,title,options,'1');
466: stdeditbrowser.focus();
467: }
1.824 bisitz 468: // ]]>
1.74 www 469: </script>
470: ENDSTDBRW
471: }
1.42 matthew 472:
1.1003 www 473: sub resourcebrowser_javascript {
474: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 475: return (<<'ENDRESBRW');
1.1003 www 476: <script type="text/javascript" language="Javascript">
477: // <![CDATA[
478: var reseditbrowser;
1.1004 www 479: function openresbrowser(formname,reslink) {
1.1005 www 480: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 481: var title = 'Resource_Browser';
482: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 483: options += ',width=700,height=500';
1.1004 www 484: reseditbrowser = open(url,title,options,'1');
485: reseditbrowser.focus();
1.1003 www 486: }
487: // ]]>
488: </script>
1.1004 www 489: ENDRESBRW
1.1003 www 490: }
491:
1.74 www 492: sub selectstudent_link {
1.1413 raeburn 493: my ($form,$unameele,$udomele,$courseadv,$clickerid,$identelem)=@_;
1.999 www 494: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
495: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
496: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 497: if ($env{'request.course.id'}) {
1.302 albertel 498: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
499: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
500: '/'.$env{'request.course.sec'})) {
1.111 www 501: return '';
502: }
1.999 www 503: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1337 raeburn 504: if ($courseadv eq 'only') {
505: $callargs .= ",'',1,'$courseadv'";
506: } elsif ($courseadv eq 'none') {
507: $callargs .= ",'','','$courseadv'";
508: } elsif ($courseadv eq 'condition') {
509: $callargs .= ",'','','$courseadv'";
1.1413 raeburn 510: } elsif ($identelem ne '') {
511: $callargs .= ",'','',''";
512: }
513: if ($identelem ne '') {
514: $callargs .= ",'".&Apache::lonhtmlcommon::entity_encode($identelem)."'";
1.793 raeburn 515: }
516: return '<span class="LC_nobreak">'.
517: '<a href="javascript:openstdbrowser('.$callargs.');">'.
518: &mt('Select User').'</a></span>';
1.74 www 519: }
1.258 albertel 520: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 521: $callargs .= ",'',1";
1.793 raeburn 522: return '<span class="LC_nobreak">'.
523: '<a href="javascript:openstdbrowser('.$callargs.');">'.
524: &mt('Select User').'</a></span>';
1.111 www 525: }
526: return '';
1.91 www 527: }
528:
1.1004 www 529: sub selectresource_link {
530: my ($form,$reslink,$arg)=@_;
531:
532: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
533: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
534: unless ($env{'request.course.id'}) { return $arg; }
535: return '<span class="LC_nobreak">'.
536: '<a href="javascript:openresbrowser('.$callargs.');">'.
537: $arg.'</a></span>';
538: }
539:
540:
541:
1.653 raeburn 542: sub authorbrowser_javascript {
543: return <<"ENDAUTHORBRW";
1.776 bisitz 544: <script type="text/javascript" language="JavaScript">
1.824 bisitz 545: // <![CDATA[
1.653 raeburn 546: var stdeditbrowser;
547:
548: function openauthorbrowser(formname,udom) {
549: var url = '/adm/pickauthor?';
550: url += 'form='+formname+'&roledom='+udom;
551: var title = 'Author_Browser';
552: var options = 'scrollbars=1,resizable=1,menubar=0';
553: options += ',width=700,height=600';
554: stdeditbrowser = open(url,title,options,'1');
555: stdeditbrowser.focus();
556: }
557:
1.824 bisitz 558: // ]]>
1.653 raeburn 559: </script>
560: ENDAUTHORBRW
561: }
562:
1.91 www 563: sub coursebrowser_javascript {
1.1116 raeburn 564: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 565: $credits_element,$instcode) = @_;
1.932 raeburn 566: my $wintitle = 'Course_Browser';
1.931 raeburn 567: if ($crstype eq 'Community') {
1.932 raeburn 568: $wintitle = 'Community_Browser';
1.909 raeburn 569: }
1.876 raeburn 570: my $id_functions = &javascript_index_functions();
571: my $output = '
1.776 bisitz 572: <script type="text/javascript" language="JavaScript">
1.824 bisitz 573: // <![CDATA[
1.468 raeburn 574: var stdeditbrowser;'."\n";
1.876 raeburn 575:
576: $output .= <<"ENDSTDBRW";
1.909 raeburn 577: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 578: var url = '/adm/pickcourse?';
1.895 raeburn 579: var formid = getFormIdByName(formname);
1.876 raeburn 580: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 581: if (domainfilter != null) {
582: if (domainfilter != '') {
583: url += 'domainfilter='+domainfilter+'&';
584: }
585: }
1.91 www 586: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 587: '&cdomelement='+udom+
588: '&cnameelement='+desc;
1.468 raeburn 589: if (extra_element !=null && extra_element != '') {
1.594 raeburn 590: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 591: url += '&roleelement='+extra_element;
592: if (domainfilter == null || domainfilter == '') {
593: url += '&domainfilter='+extra_element;
594: }
1.234 raeburn 595: }
1.468 raeburn 596: else {
597: if (formname == 'portform') {
598: url += '&setroles='+extra_element;
1.800 raeburn 599: } else {
600: if (formname == 'rules') {
601: url += '&fixeddom='+extra_element;
602: }
1.468 raeburn 603: }
604: }
1.230 raeburn 605: }
1.909 raeburn 606: if (type != null && type != '') {
607: url += '&type='+type;
608: }
609: if (type_elem != null && type_elem != '') {
610: url += '&typeelement='+type_elem;
611: }
1.872 raeburn 612: if (formname == 'ccrs') {
613: var ownername = document.forms[formid].ccuname.value;
614: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 615: url += '&cloner='+ownername+':'+ownerdom;
616: if (type == 'Course') {
617: url += '&crscode='+document.forms[formid].crscode.value;
618: }
1.1221 raeburn 619: }
620: if (formname == 'requestcrs') {
621: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 622: }
1.293 raeburn 623: if (multflag !=null && multflag != '') {
624: url += '&multiple='+multflag;
625: }
1.909 raeburn 626: var title = '$wintitle';
1.91 www 627: var options = 'scrollbars=1,resizable=1,menubar=0';
628: options += ',width=700,height=600';
629: stdeditbrowser = open(url,title,options,'1');
630: stdeditbrowser.focus();
631: }
1.876 raeburn 632: $id_functions
633: ENDSTDBRW
1.1116 raeburn 634: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
635: $output .= &setsec_javascript($sec_element,$formname,$role_element,
636: $credits_element);
1.876 raeburn 637: }
638: $output .= '
639: // ]]>
640: </script>';
641: return $output;
642: }
643:
644: sub javascript_index_functions {
645: return <<"ENDJS";
646:
647: function getFormIdByName(formname) {
648: for (var i=0;i<document.forms.length;i++) {
649: if (document.forms[i].name == formname) {
650: return i;
651: }
652: }
653: return -1;
654: }
655:
656: function getIndexByName(formid,item) {
657: for (var i=0;i<document.forms[formid].elements.length;i++) {
658: if (document.forms[formid].elements[i].name == item) {
659: return i;
660: }
661: }
662: return -1;
663: }
1.468 raeburn 664:
1.876 raeburn 665: function getDomainFromSelectbox(formname,udom) {
666: var userdom;
667: var formid = getFormIdByName(formname);
668: if (formid > -1) {
669: var domid = getIndexByName(formid,udom);
670: if (domid > -1) {
671: if (document.forms[formid].elements[domid].type == 'select-one') {
672: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
673: }
674: if (document.forms[formid].elements[domid].type == 'hidden') {
675: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 676: }
677: }
678: }
1.876 raeburn 679: return userdom;
680: }
681:
682: ENDJS
1.468 raeburn 683:
1.876 raeburn 684: }
685:
1.1017 raeburn 686: sub javascript_array_indexof {
1.1018 raeburn 687: return <<ENDJS;
1.1017 raeburn 688: <script type="text/javascript" language="JavaScript">
689: // <![CDATA[
690:
691: if (!Array.prototype.indexOf) {
692: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
693: "use strict";
694: if (this === void 0 || this === null) {
695: throw new TypeError();
696: }
697: var t = Object(this);
698: var len = t.length >>> 0;
699: if (len === 0) {
700: return -1;
701: }
702: var n = 0;
703: if (arguments.length > 0) {
704: n = Number(arguments[1]);
1.1088 foxr 705: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 706: n = 0;
707: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
708: n = (n > 0 || -1) * Math.floor(Math.abs(n));
709: }
710: }
711: if (n >= len) {
712: return -1;
713: }
714: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
715: for (; k < len; k++) {
716: if (k in t && t[k] === searchElement) {
717: return k;
718: }
719: }
720: return -1;
721: }
722: }
723:
724: // ]]>
725: </script>
726:
727: ENDJS
728:
729: }
730:
1.876 raeburn 731: sub userbrowser_javascript {
732: my $id_functions = &javascript_index_functions();
733: return <<"ENDUSERBRW";
734:
1.888 raeburn 735: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 736: var url = '/adm/pickuser?';
737: var userdom = getDomainFromSelectbox(formname,udom);
738: if (userdom != null) {
739: if (userdom != '') {
740: url += 'srchdom='+userdom+'&';
741: }
742: }
743: url += 'form=' + formname + '&unameelement='+uname+
744: '&udomelement='+udom+
745: '&ulastelement='+ulast+
746: '&ufirstelement='+ufirst+
747: '&uemailelement='+uemail+
1.881 raeburn 748: '&hideudomelement='+hideudom+
749: '&coursedom='+crsdom;
1.888 raeburn 750: if ((caller != null) && (caller != undefined)) {
751: url += '&caller='+caller;
752: }
1.876 raeburn 753: var title = 'User_Browser';
754: var options = 'scrollbars=1,resizable=1,menubar=0';
755: options += ',width=700,height=600';
756: var stdeditbrowser = open(url,title,options,'1');
757: stdeditbrowser.focus();
758: }
759:
1.888 raeburn 760: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 761: var formid = getFormIdByName(formname);
762: if (formid > -1) {
1.888 raeburn 763: var unameid = getIndexByName(formid,uname);
1.876 raeburn 764: var domid = getIndexByName(formid,udom);
765: var hidedomid = getIndexByName(formid,origdom);
766: if (hidedomid > -1) {
767: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 768: var unameval = document.forms[formid].elements[unameid].value;
769: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
770: if (domid > -1) {
771: var slct = document.forms[formid].elements[domid];
772: if (slct.type == 'select-one') {
773: var i;
774: for (i=0;i<slct.length;i++) {
775: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
776: }
777: }
778: if (slct.type == 'hidden') {
779: slct.value = fixeddom;
1.876 raeburn 780: }
781: }
1.468 raeburn 782: }
783: }
784: }
1.876 raeburn 785: return;
786: }
787:
788: $id_functions
789: ENDUSERBRW
1.468 raeburn 790: }
791:
792: sub setsec_javascript {
1.1116 raeburn 793: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 794: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
795: $communityrolestr);
796: if ($role_element ne '') {
797: my @allroles = ('st','ta','ep','in','ad');
798: foreach my $crstype ('Course','Community') {
799: if ($crstype eq 'Community') {
800: foreach my $role (@allroles) {
801: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
802: }
803: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
804: } else {
805: foreach my $role (@allroles) {
806: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
807: }
808: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
809: }
810: }
811: $rolestr = '"'.join('","',@allroles).'"';
812: $courserolestr = '"'.join('","',@courserolenames).'"';
813: $communityrolestr = '"'.join('","',@communityrolenames).'"';
814: }
1.468 raeburn 815: my $setsections = qq|
816: function setSect(sectionlist) {
1.629 raeburn 817: var sectionsArray = new Array();
818: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
819: sectionsArray = sectionlist.split(",");
820: }
1.468 raeburn 821: var numSections = sectionsArray.length;
822: document.$formname.$sec_element.length = 0;
823: if (numSections == 0) {
824: document.$formname.$sec_element.multiple=false;
825: document.$formname.$sec_element.size=1;
826: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
827: } else {
828: if (numSections == 1) {
829: document.$formname.$sec_element.multiple=false;
830: document.$formname.$sec_element.size=1;
831: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
832: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
833: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
834: } else {
835: for (var i=0; i<numSections; i++) {
836: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
837: }
838: document.$formname.$sec_element.multiple=true
839: if (numSections < 3) {
840: document.$formname.$sec_element.size=numSections;
841: } else {
842: document.$formname.$sec_element.size=3;
843: }
844: document.$formname.$sec_element.options[0].selected = false
845: }
846: }
1.91 www 847: }
1.905 raeburn 848:
849: function setRole(crstype) {
1.468 raeburn 850: |;
1.905 raeburn 851: if ($role_element eq '') {
852: $setsections .= ' return;
853: }
854: ';
855: } else {
856: $setsections .= qq|
857: var elementLength = document.$formname.$role_element.length;
858: var allroles = Array($rolestr);
859: var courserolenames = Array($courserolestr);
860: var communityrolenames = Array($communityrolestr);
861: if (elementLength != undefined) {
862: if (document.$formname.$role_element.options[5].value == 'cc') {
863: if (crstype == 'Course') {
864: return;
865: } else {
866: allroles[5] = 'co';
867: for (var i=0; i<6; i++) {
868: document.$formname.$role_element.options[i].value = allroles[i];
869: document.$formname.$role_element.options[i].text = communityrolenames[i];
870: }
871: }
872: } else {
873: if (crstype == 'Community') {
874: return;
875: } else {
876: allroles[5] = 'cc';
877: for (var i=0; i<6; i++) {
878: document.$formname.$role_element.options[i].value = allroles[i];
879: document.$formname.$role_element.options[i].text = courserolenames[i];
880: }
881: }
882: }
883: }
884: return;
885: }
886: |;
887: }
1.1116 raeburn 888: if ($credits_element) {
889: $setsections .= qq|
890: function setCredits(defaultcredits) {
891: document.$formname.$credits_element.value = defaultcredits;
892: return;
893: }
894: |;
895: }
1.468 raeburn 896: return $setsections;
897: }
898:
1.91 www 899: sub selectcourse_link {
1.909 raeburn 900: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
901: $typeelement) = @_;
902: my $type = $selecttype;
1.871 raeburn 903: my $linktext = &mt('Select Course');
904: if ($selecttype eq 'Community') {
1.909 raeburn 905: $linktext = &mt('Select Community');
1.1239 raeburn 906: } elsif ($selecttype eq 'Placement') {
907: $linktext = &mt('Select Placement Test');
1.906 raeburn 908: } elsif ($selecttype eq 'Course/Community') {
909: $linktext = &mt('Select Course/Community');
1.909 raeburn 910: $type = '';
1.1019 raeburn 911: } elsif ($selecttype eq 'Select') {
912: $linktext = &mt('Select');
913: $type = '';
1.871 raeburn 914: }
1.787 bisitz 915: return '<span class="LC_nobreak">'
916: ."<a href='"
917: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
918: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 919: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 920: ."'>".$linktext.'</a>'
1.787 bisitz 921: .'</span>';
1.74 www 922: }
1.42 matthew 923:
1.653 raeburn 924: sub selectauthor_link {
925: my ($form,$udom)=@_;
926: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
927: &mt('Select Author').'</a>';
928: }
929:
1.876 raeburn 930: sub selectuser_link {
1.881 raeburn 931: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 932: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 933: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 934: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 935: ');">'.$linktext.'</a>';
1.876 raeburn 936: }
937:
1.273 raeburn 938: sub check_uncheck_jscript {
939: my $jscript = <<"ENDSCRT";
940: function checkAll(field) {
941: if (field.length > 0) {
942: for (i = 0; i < field.length; i++) {
1.1093 raeburn 943: if (!field[i].disabled) {
944: field[i].checked = true;
945: }
1.273 raeburn 946: }
947: } else {
1.1093 raeburn 948: if (!field.disabled) {
949: field.checked = true;
950: }
1.273 raeburn 951: }
952: }
953:
954: function uncheckAll(field) {
955: if (field.length > 0) {
956: for (i = 0; i < field.length; i++) {
957: field[i].checked = false ;
1.543 albertel 958: }
959: } else {
1.273 raeburn 960: field.checked = false ;
961: }
962: }
963: ENDSCRT
964: return $jscript;
965: }
966:
1.656 www 967: sub select_timezone {
1.1387 raeburn 968: my ($name,$selected,$onchange,$includeempty,$id,$disabled)=@_;
1.1469 ! raeburn 969: my $labeltext = &HTML::Entities::encode(&mt('Select Time Zone'));
! 970: my $output='<select name="'.$name.'" '.$id.$onchange.$disabled.
! 971: ' aria-label="'.$labeltext.'">'."\n";
1.659 raeburn 972: if ($includeempty) {
973: $output .= '<option value=""';
974: if (($selected eq '') || ($selected eq 'local')) {
975: $output .= ' selected="selected" ';
976: }
977: $output .= '> </option>';
978: }
1.657 raeburn 979: my @timezones = DateTime::TimeZone->all_names;
980: foreach my $tzone (@timezones) {
981: $output.= '<option value="'.$tzone.'"';
982: if ($tzone eq $selected) {
983: $output.=' selected="selected"';
984: }
985: $output.=">$tzone</option>\n";
1.656 www 986: }
987: $output.="</select>";
988: return $output;
989: }
1.273 raeburn 990:
1.687 raeburn 991: sub select_datelocale {
1.1256 raeburn 992: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
993: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 994: if ($includeempty) {
995: $output .= '<option value=""';
996: if ($selected eq '') {
997: $output .= ' selected="selected" ';
998: }
999: $output .= '> </option>';
1000: }
1.1241 raeburn 1001: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 1002: my (@possibles,%locale_names);
1.1241 raeburn 1003: my @locales = DateTime::Locale->ids();
1004: foreach my $id (@locales) {
1005: if ($id ne '') {
1006: my ($en_terr,$native_terr);
1007: my $loc = DateTime::Locale->load($id);
1008: if (ref($loc)) {
1009: $en_terr = $loc->name();
1010: $native_terr = $loc->native_name();
1.687 raeburn 1011: if (grep(/^en$/,@languages) || !@languages) {
1012: if ($en_terr ne '') {
1013: $locale_names{$id} = '('.$en_terr.')';
1014: } elsif ($native_terr ne '') {
1015: $locale_names{$id} = $native_terr;
1016: }
1017: } else {
1018: if ($native_terr ne '') {
1019: $locale_names{$id} = $native_terr.' ';
1020: } elsif ($en_terr ne '') {
1021: $locale_names{$id} = '('.$en_terr.')';
1022: }
1023: }
1.1220 raeburn 1024: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1025: push(@possibles,$id);
1026: }
1.687 raeburn 1027: }
1028: }
1029: foreach my $item (sort(@possibles)) {
1030: $output.= '<option value="'.$item.'"';
1031: if ($item eq $selected) {
1032: $output.=' selected="selected"';
1033: }
1034: $output.=">$item";
1035: if ($locale_names{$item} ne '') {
1.1220 raeburn 1036: $output.=' '.$locale_names{$item};
1.687 raeburn 1037: }
1038: $output.="</option>\n";
1039: }
1040: $output.="</select>";
1041: return $output;
1042: }
1043:
1.792 raeburn 1044: sub select_language {
1.1256 raeburn 1045: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1046: my %langchoices;
1047: if ($includeempty) {
1.1117 raeburn 1048: %langchoices = ('' => 'No language preference');
1.792 raeburn 1049: }
1050: foreach my $id (&languageids()) {
1051: my $code = &supportedlanguagecode($id);
1052: if ($code) {
1053: $langchoices{$code} = &plainlanguagedescription($id);
1054: }
1055: }
1.1117 raeburn 1056: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1057: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1058: }
1059:
1.42 matthew 1060: =pod
1.36 matthew 1061:
1.1088 foxr 1062:
1063: =item * &list_languages()
1064:
1065: Returns an array reference that is suitable for use in language prompters.
1066: Each array element is itself a two element array. The first element
1067: is the language code. The second element a descsriptiuon of the
1068: language itself. This is suitable for use in e.g.
1069: &Apache::edit::select_arg (once dereferenced that is).
1070:
1071: =cut
1072:
1073: sub list_languages {
1074: my @lang_choices;
1075:
1076: foreach my $id (&languageids()) {
1077: my $code = &supportedlanguagecode($id);
1078: if ($code) {
1079: my $selector = $supported_codes{$id};
1080: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1081: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1082: }
1083: }
1084: return \@lang_choices;
1085: }
1086:
1087: =pod
1088:
1.648 raeburn 1089: =item * &linked_select_forms(...)
1.36 matthew 1090:
1091: linked_select_forms returns a string containing a <script></script> block
1092: and html for two <select> menus. The select menus will be linked in that
1093: changing the value of the first menu will result in new values being placed
1094: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1095: order unless a defined order is provided.
1.36 matthew 1096:
1097: linked_select_forms takes the following ordered inputs:
1098:
1099: =over 4
1100:
1.112 bowersj2 1101: =item * $formname, the name of the <form> tag
1.36 matthew 1102:
1.112 bowersj2 1103: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1104:
1.112 bowersj2 1105: =item * $firstdefault, the default value for the first menu
1.36 matthew 1106:
1.112 bowersj2 1107: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1108:
1.112 bowersj2 1109: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1110:
1.112 bowersj2 1111: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1112:
1.609 raeburn 1113: =item * $menuorder, the order of values in the first menu
1114:
1.1115 raeburn 1115: =item * $onchangefirst, additional javascript call to execute for an onchange
1116: event for the first <select> tag
1117:
1118: =item * $onchangesecond, additional javascript call to execute for an onchange
1119: event for the second <select> tag
1120:
1.1245 raeburn 1121: =item * $suffix, to differentiate separate uses of select2data javascript
1122: objects in a page.
1123:
1.41 ng 1124: =back
1125:
1.36 matthew 1126: Below is an example of such a hash. Only the 'text', 'default', and
1127: 'select2' keys must appear as stated. keys(%menu) are the possible
1128: values for the first select menu. The text that coincides with the
1.41 ng 1129: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1130: and text for the second menu are given in the hash pointed to by
1131: $menu{$choice1}->{'select2'}.
1132:
1.112 bowersj2 1133: my %menu = ( A1 => { text =>"Choice A1" ,
1134: default => "B3",
1135: select2 => {
1136: B1 => "Choice B1",
1137: B2 => "Choice B2",
1138: B3 => "Choice B3",
1139: B4 => "Choice B4"
1.609 raeburn 1140: },
1141: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1142: },
1143: A2 => { text =>"Choice A2" ,
1144: default => "C2",
1145: select2 => {
1146: C1 => "Choice C1",
1147: C2 => "Choice C2",
1148: C3 => "Choice C3"
1.609 raeburn 1149: },
1150: order => ['C2','C1','C3'],
1.112 bowersj2 1151: },
1152: A3 => { text =>"Choice A3" ,
1153: default => "D6",
1154: select2 => {
1155: D1 => "Choice D1",
1156: D2 => "Choice D2",
1157: D3 => "Choice D3",
1158: D4 => "Choice D4",
1159: D5 => "Choice D5",
1160: D6 => "Choice D6",
1161: D7 => "Choice D7"
1.609 raeburn 1162: },
1163: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1164: }
1165: );
1.36 matthew 1166:
1167: =cut
1168:
1169: sub linked_select_forms {
1170: my ($formname,
1171: $middletext,
1172: $firstdefault,
1173: $firstselectname,
1174: $secondselectname,
1.609 raeburn 1175: $hashref,
1176: $menuorder,
1.1115 raeburn 1177: $onchangefirst,
1.1245 raeburn 1178: $onchangesecond,
1.1450 raeburn 1179: $suffix,
1180: $haslabel
1.36 matthew 1181: ) = @_;
1182: my $second = "document.$formname.$secondselectname";
1183: my $first = "document.$formname.$firstselectname";
1184: # output the javascript to do the changing
1185: my $result = '';
1.776 bisitz 1186: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1187: $result.="// <![CDATA[\n";
1.1245 raeburn 1188: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1189: $" = '","';
1190: my $debug = '';
1191: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1192: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1193: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1194: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1195: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1196: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1197: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1198: @s2values = @{$hashref->{$s1}->{'order'}};
1199: }
1.36 matthew 1200: $result.="\"@s2values\");\n";
1.1245 raeburn 1201: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1202: my @s2texts;
1203: foreach my $value (@s2values) {
1.1263 raeburn 1204: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1205: }
1206: $result.="\"@s2texts\");\n";
1207: }
1208: $"=' ';
1209: $result.= <<"END";
1210:
1.1245 raeburn 1211: function select1${suffix}_changed() {
1.36 matthew 1212: // Determine new choice
1.1245 raeburn 1213: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1214: // update select2
1.1245 raeburn 1215: var values = select2data${suffix}[newvalue].values;
1216: var texts = select2data${suffix}[newvalue].texts;
1217: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1218: var i;
1219: // out with the old
1.1245 raeburn 1220: $second.options.length = 0;
1221: // in with the new
1.36 matthew 1222: for (i=0;i<values.length; i++) {
1223: $second.options[i] = new Option(values[i]);
1.143 matthew 1224: $second.options[i].value = values[i];
1.36 matthew 1225: $second.options[i].text = texts[i];
1226: if (values[i] == select2def) {
1227: $second.options[i].selected = true;
1228: }
1229: }
1230: }
1.824 bisitz 1231: // ]]>
1.36 matthew 1232: </script>
1233: END
1234: # output the initial values for the selection lists
1.1245 raeburn 1235: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1236: my @order = sort(keys(%{$hashref}));
1237: if (ref($menuorder) eq 'ARRAY') {
1238: @order = @{$menuorder};
1239: }
1240: foreach my $value (@order) {
1.36 matthew 1241: $result.=" <option value=\"$value\" ";
1.253 albertel 1242: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1243: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1244: }
1245: $result .= "</select>\n";
1.1450 raeburn 1246: if ($haslabel) {
1247: $result .= '</label>';
1248: }
1.1400 raeburn 1249: my %select2;
1250: if (ref($hashref->{$firstdefault}) eq 'HASH') {
1251: if (ref($hashref->{$firstdefault}->{'select2'}) eq 'HASH') {
1252: %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1253: }
1254: }
1.1450 raeburn 1255: if ($middletext ne '') {
1.1452 raeburn 1256: $result .= '<label>'.$middletext;
1.1450 raeburn 1257: }
1.1115 raeburn 1258: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1259: if ($onchangesecond) {
1260: $result .= ' onchange="'.$onchangesecond.'"';
1261: }
1262: $result .= ">\n";
1.36 matthew 1263: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1264:
1265: my @secondorder = sort(keys(%select2));
1266: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1267: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1268: }
1269: foreach my $value (@secondorder) {
1.36 matthew 1270: $result.=" <option value=\"$value\" ";
1.253 albertel 1271: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1272: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1273: }
1274: $result .= "</select>\n";
1.1450 raeburn 1275: if ($middletext ne '') {
1276: $result .= '</label>';
1277: }
1.36 matthew 1278: # return $debug;
1279: return $result;
1280: } # end of sub linked_select_forms {
1281:
1.45 matthew 1282: =pod
1.44 bowersj2 1283:
1.1381 raeburn 1284: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid,$links_target)
1.44 bowersj2 1285:
1.112 bowersj2 1286: Returns a string corresponding to an HTML link to the given help
1287: $topic, where $topic corresponds to the name of a .tex file in
1288: /home/httpd/html/adm/help/tex, with underscores replaced by
1289: spaces.
1290:
1291: $text will optionally be linked to the same topic, allowing you to
1292: link text in addition to the graphic. If you do not want to link
1293: text, but wish to specify one of the later parameters, pass an
1294: empty string.
1295:
1296: $stayOnPage is a value that will be interpreted as a boolean. If true,
1297: the link will not open a new window. If false, the link will open
1298: a new window using Javascript. (Default is false.)
1299:
1300: $width and $height are optional numerical parameters that will
1301: override the width and height of the popped up window, which may
1.973 raeburn 1302: be useful for certain help topics with big pictures included.
1303:
1304: $imgid is the id of the img tag used for the help icon. This may be
1305: used in a javascript call to switch the image src. See
1306: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1307:
1.1381 raeburn 1308: $links_target will optionally be set to a target (_top, _parent or _self).
1309:
1.44 bowersj2 1310: =cut
1311:
1312: sub help_open_topic {
1.1381 raeburn 1313: my ($topic, $text, $stayOnPage, $width, $height, $imgid, $links_target) = @_;
1.48 bowersj2 1314: $text = "" if (not defined $text);
1.44 bowersj2 1315: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1316: $width = 500 if (not defined $width);
1.44 bowersj2 1317: $height = 400 if (not defined $height);
1318: my $filename = $topic;
1319: $filename =~ s/ /_/g;
1320:
1.48 bowersj2 1321: my $template = "";
1322: my $link;
1.572 banghart 1323:
1.159 www 1324: $topic=~s/\W/\_/g;
1.44 bowersj2 1325:
1.572 banghart 1326: if (!$stayOnPage) {
1.1033 www 1327: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1328: } elsif ($stayOnPage eq 'popup') {
1329: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1330: } else {
1.48 bowersj2 1331: $link = "/adm/help/${filename}.hlp";
1332: }
1333:
1334: # Add the text
1.1314 raeburn 1335: my $target = ' target="_top"';
1.1381 raeburn 1336: if ($links_target) {
1337: $target = ' target="'.$links_target.'"';
1338: } elsif ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1339: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1340: $target = '';
1.1378 raeburn 1341: }
1.1380 raeburn 1342: if ($text ne "") {
1.763 bisitz 1343: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1344: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1345: .$text.'</a>';
1.48 bowersj2 1346: }
1347:
1.763 bisitz 1348: # (Always) Add the graphic
1.179 matthew 1349: my $title = &mt('Online Help');
1.667 raeburn 1350: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1351: if ($imgid ne '') {
1352: $imgid = ' id="'.$imgid.'"';
1353: }
1.1314 raeburn 1354: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1355: .'<img src="'.$helpicon.'" border="0"'
1.1469 ! raeburn 1356: .' alt="'.&mt('Help icon').'"'
1.973 raeburn 1357: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1358: .' /></a>';
1359: if ($text ne "") {
1360: $template.='</span>';
1361: }
1.44 bowersj2 1362: return $template;
1363:
1.106 bowersj2 1364: }
1365:
1366: # This is a quicky function for Latex cheatsheet editing, since it
1367: # appears in at least four places
1368: sub helpLatexCheatsheet {
1.1037 www 1369: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1370: my $out;
1.106 bowersj2 1371: my $addOther = '';
1.732 raeburn 1372: if ($topic) {
1.1037 www 1373: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1374: }
1375: $out = '<span>' # Start cheatsheet
1376: .$addOther
1377: .'<span>'
1.1037 www 1378: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1379: .'</span> <span>'
1.1037 www 1380: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1381: .'</span>';
1.732 raeburn 1382: unless ($not_author) {
1.1186 kruse 1383: $out .= '<span>'
1384: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1385: .'</span> <span>'
1.1424 raeburn 1386: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.763 bisitz 1387: .'</span>';
1.732 raeburn 1388: }
1.763 bisitz 1389: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1390: return $out;
1.172 www 1391: }
1392:
1.430 albertel 1393: sub general_help {
1394: my $helptopic='Student_Intro';
1395: if ($env{'request.role'}=~/^(ca|au)/) {
1396: $helptopic='Authoring_Intro';
1.907 raeburn 1397: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1398: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1399: } elsif ($env{'request.role'}=~/^dc/) {
1400: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1401: }
1402: return $helptopic;
1403: }
1404:
1405: sub update_help_link {
1406: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1407: my $origurl = $ENV{'REQUEST_URI'};
1408: $origurl=~s|^/~|/priv/|;
1409: my $timestamp = time;
1410: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1411: $$datum = &escape($$datum);
1412: }
1413:
1414: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1415: my $output .= <<"ENDOUTPUT";
1416: <script type="text/javascript">
1.824 bisitz 1417: // <![CDATA[
1.430 albertel 1418: banner_link = '$banner_link';
1.824 bisitz 1419: // ]]>
1.430 albertel 1420: </script>
1421: ENDOUTPUT
1422: return $output;
1423: }
1424:
1425: # now just updates the help link and generates a blue icon
1.193 raeburn 1426: sub help_open_menu {
1.1381 raeburn 1427: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text,$links_target)
1.552 banghart 1428: = @_;
1.949 droeschl 1429: $stayOnPage = 1;
1.430 albertel 1430: my $output;
1431: if ($component_help) {
1432: if (!$text) {
1433: $output=&help_open_topic($component_help,undef,$stayOnPage,
1.1381 raeburn 1434: $width,$height,'',$links_target);
1.430 albertel 1435: } else {
1436: my $help_text;
1437: $help_text=&unescape($topic);
1438: $output='<table><tr><td>'.
1439: &help_open_topic($component_help,$help_text,$stayOnPage,
1.1381 raeburn 1440: $width,$height,'',$links_target).'</td></tr></table>';
1.430 albertel 1441: }
1442: }
1443: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1444: return $output.$banner_link;
1445: }
1446:
1447: sub top_nav_help {
1.1369 raeburn 1448: my ($text,$linkattr) = @_;
1.436 albertel 1449: $text = &mt($text);
1.949 droeschl 1450: my $stay_on_page = 1;
1451:
1.1168 raeburn 1452: my ($link,$banner_link);
1453: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1454: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1455: : "javascript:helpMenu('open')";
1456: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1457: }
1.201 raeburn 1458: my $title = &mt('Get help');
1.1168 raeburn 1459: if ($link) {
1460: return <<"END";
1.436 albertel 1461: $banner_link
1.1369 raeburn 1462: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1463: END
1.1168 raeburn 1464: } else {
1.1459 raeburn 1465: return ' <h1 class="LC_helpmenu">'.$text.'</h1> ';
1.1168 raeburn 1466: }
1.436 albertel 1467: }
1468:
1469: sub help_menu_js {
1.1154 raeburn 1470: my ($httphost) = @_;
1.949 droeschl 1471: my $stayOnPage = 1;
1.436 albertel 1472: my $width = 620;
1473: my $height = 600;
1.430 albertel 1474: my $helptopic=&general_help();
1.1154 raeburn 1475: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1476: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.1459 raeburn 1477: my $bannertitle = &mt('Help Menu');
1478: &js_escape(\$bannertitle);
1479: my $bodytitle = &mt('Documentation');
1480: &js_escape(\$bodytitle);
1.331 albertel 1481: my $start_page =
1482: &Apache::loncommon::start_page('Help Menu', undef,
1483: {'frameset' => 1,
1484: 'js_ready' => 1,
1.1154 raeburn 1485: 'use_absolute' => $httphost,
1.331 albertel 1486: 'add_entries' => {
1.1168 raeburn 1487: 'border' => '0',
1.579 raeburn 1488: 'rows' => "110,*",},});
1.331 albertel 1489: my $end_page =
1490: &Apache::loncommon::end_page({'frameset' => 1,
1491: 'js_ready' => 1,});
1.436 albertel 1492: my $template .= <<"ENDTEMPLATE";
1493: <script type="text/javascript">
1.877 bisitz 1494: // <![CDATA[
1.253 albertel 1495: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1496: var banner_link = '';
1.243 raeburn 1497: function helpMenu(target) {
1498: var caller = this;
1499: if (target == 'open') {
1500: var newWindow = null;
1501: try {
1.262 albertel 1502: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1503: }
1504: catch(error) {
1505: writeHelp(caller);
1506: return;
1507: }
1508: if (newWindow) {
1509: caller = newWindow;
1510: }
1.193 raeburn 1511: }
1.243 raeburn 1512: writeHelp(caller);
1513: return;
1514: }
1515: function writeHelp(caller) {
1.1459 raeburn 1516: caller.document.writeln('$start_page\\n<frame name="bannerframe" title="$bannertitle" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1517: caller.document.writeln('<frame name="bodyframe" title="$bodytitle" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1.1168 raeburn 1518: caller.document.close();
1519: caller.focus();
1.193 raeburn 1520: }
1.877 bisitz 1521: // END LON-CAPA Internal -->
1.253 albertel 1522: // ]]>
1.436 albertel 1523: </script>
1.193 raeburn 1524: ENDTEMPLATE
1525: return $template;
1526: }
1527:
1.172 www 1528: sub help_open_bug {
1529: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1530: unless ($env{'user.adv'}) { return ''; }
1.172 www 1531: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1532: $text = "" if (not defined $text);
1533: $stayOnPage=1;
1.184 albertel 1534: $width = 600 if (not defined $width);
1535: $height = 600 if (not defined $height);
1.172 www 1536:
1537: $topic=~s/\W+/\+/g;
1538: my $link='';
1539: my $template='';
1.379 albertel 1540: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1541: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1542: if (!$stayOnPage)
1543: {
1544: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1545: }
1546: else
1547: {
1548: $link = $url;
1549: }
1.1314 raeburn 1550:
1.1382 raeburn 1551: my $target = '_top';
1552: if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1553: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1554: $target = '_blank';
1.1378 raeburn 1555: }
1.1382 raeburn 1556:
1.172 www 1557: # Add the text
1558: if ($text ne "")
1559: {
1560: $template .=
1561: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1382 raeburn 1562: "<td bgcolor='#FF5555'><a target=\"$target\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1563: }
1564:
1565: # Add the graphic
1.179 matthew 1566: my $title = &mt('Report a Bug');
1.215 albertel 1567: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1568: $template .= <<"ENDTEMPLATE";
1.1382 raeburn 1569: <a target="$target" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1570: ENDTEMPLATE
1571: if ($text ne '') { $template.='</td></tr></table>' };
1572: return $template;
1573:
1574: }
1575:
1576: sub help_open_faq {
1577: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1578: unless ($env{'user.adv'}) { return ''; }
1.172 www 1579: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1580: $text = "" if (not defined $text);
1581: $stayOnPage=1;
1582: $width = 350 if (not defined $width);
1583: $height = 400 if (not defined $height);
1584:
1585: $topic=~s/\W+/\+/g;
1586: my $link='';
1587: my $template='';
1588: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1589: if (!$stayOnPage)
1590: {
1591: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1592: }
1593: else
1594: {
1595: $link = $url;
1596: }
1597:
1598: # Add the text
1599: if ($text ne "")
1600: {
1601: $template .=
1.173 www 1602: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1603: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1604: }
1605:
1606: # Add the graphic
1.179 matthew 1607: my $title = &mt('View the FAQ');
1.215 albertel 1608: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1609: $template .= <<"ENDTEMPLATE";
1.436 albertel 1610: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1611: ENDTEMPLATE
1612: if ($text ne '') { $template.='</td></tr></table>' };
1613: return $template;
1614:
1.44 bowersj2 1615: }
1.37 matthew 1616:
1.180 matthew 1617: ###############################################################
1618: ###############################################################
1619:
1.45 matthew 1620: =pod
1621:
1.648 raeburn 1622: =item * &change_content_javascript():
1.256 matthew 1623:
1624: This and the next function allow you to create small sections of an
1625: otherwise static HTML page that you can update on the fly with
1626: Javascript, even in Netscape 4.
1627:
1628: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1629: must be written to the HTML page once. It will prove the Javascript
1630: function "change(name, content)". Calling the change function with the
1631: name of the section
1632: you want to update, matching the name passed to C<changable_area>, and
1633: the new content you want to put in there, will put the content into
1634: that area.
1635:
1636: B<Note>: Netscape 4 only reserves enough space for the changable area
1637: to contain room for the original contents. You need to "make space"
1638: for whatever changes you wish to make, and be B<sure> to check your
1639: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1640: it's adequate for updating a one-line status display, but little more.
1641: This script will set the space to 100% width, so you only need to
1642: worry about height in Netscape 4.
1643:
1644: Modern browsers are much less limiting, and if you can commit to the
1645: user not using Netscape 4, this feature may be used freely with
1646: pretty much any HTML.
1647:
1648: =cut
1649:
1650: sub change_content_javascript {
1651: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1652: if ($env{'browser.type'} eq 'netscape' &&
1653: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1654: return (<<NETSCAPE4);
1655: function change(name, content) {
1656: doc = document.layers[name+"___escape"].layers[0].document;
1657: doc.open();
1658: doc.write(content);
1659: doc.close();
1660: }
1661: NETSCAPE4
1662: } else {
1663: # Otherwise, we need to use semi-standards-compliant code
1664: # (technically, "innerHTML" isn't standard but the equivalent
1665: # is really scary, and every useful browser supports it
1666: return (<<DOMBASED);
1667: function change(name, content) {
1668: element = document.getElementById(name);
1669: element.innerHTML = content;
1670: }
1671: DOMBASED
1672: }
1673: }
1674:
1675: =pod
1676:
1.648 raeburn 1677: =item * &changable_area($name,$origContent):
1.256 matthew 1678:
1679: This provides a "changable area" that can be modified on the fly via
1680: the Javascript code provided in C<change_content_javascript>. $name is
1681: the name you will use to reference the area later; do not repeat the
1682: same name on a given HTML page more then once. $origContent is what
1683: the area will originally contain, which can be left blank.
1684:
1685: =cut
1686:
1687: sub changable_area {
1688: my ($name, $origContent) = @_;
1689:
1.258 albertel 1690: if ($env{'browser.type'} eq 'netscape' &&
1691: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1692: # If this is netscape 4, we need to use the Layer tag
1693: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1694: } else {
1695: return "<span id='$name'>$origContent</span>";
1696: }
1697: }
1698:
1699: =pod
1700:
1.648 raeburn 1701: =item * &viewport_geometry_js
1.590 raeburn 1702:
1703: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1704:
1705: =cut
1706:
1707:
1708: sub viewport_geometry_js {
1709: return <<"GEOMETRY";
1710: var Geometry = {};
1711: function init_geometry() {
1712: if (Geometry.init) { return };
1713: Geometry.init=1;
1714: if (window.innerHeight) {
1715: Geometry.getViewportHeight = function() { return window.innerHeight; };
1716: Geometry.getViewportWidth = function() { return window.innerWidth; };
1717: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1718: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1719: }
1720: else if (document.documentElement && document.documentElement.clientHeight) {
1721: Geometry.getViewportHeight =
1722: function() { return document.documentElement.clientHeight; };
1723: Geometry.getViewportWidth =
1724: function() { return document.documentElement.clientWidth; };
1725:
1726: Geometry.getHorizontalScroll =
1727: function() { return document.documentElement.scrollLeft; };
1728: Geometry.getVerticalScroll =
1729: function() { return document.documentElement.scrollTop; };
1730: }
1731: else if (document.body.clientHeight) {
1732: Geometry.getViewportHeight =
1733: function() { return document.body.clientHeight; };
1734: Geometry.getViewportWidth =
1735: function() { return document.body.clientWidth; };
1736: Geometry.getHorizontalScroll =
1737: function() { return document.body.scrollLeft; };
1738: Geometry.getVerticalScroll =
1739: function() { return document.body.scrollTop; };
1740: }
1741: }
1742:
1743: GEOMETRY
1744: }
1745:
1746: =pod
1747:
1.648 raeburn 1748: =item * &viewport_size_js()
1.590 raeburn 1749:
1750: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1751:
1752: =cut
1753:
1754: sub viewport_size_js {
1755: my $geometry = &viewport_geometry_js();
1756: return <<"DIMS";
1757:
1758: $geometry
1759:
1760: function getViewportDims(width,height) {
1761: init_geometry();
1762: width.value = Geometry.getViewportWidth();
1763: height.value = Geometry.getViewportHeight();
1764: return;
1765: }
1766:
1767: DIMS
1768: }
1769:
1770: =pod
1771:
1.648 raeburn 1772: =item * &resize_textarea_js()
1.565 albertel 1773:
1774: emits the needed javascript to resize a textarea to be as big as possible
1775:
1776: creates a function resize_textrea that takes two IDs first should be
1777: the id of the element to resize, second should be the id of a div that
1778: surrounds everything that comes after the textarea, this routine needs
1779: to be attached to the <body> for the onload and onresize events.
1780:
1781: =cut
1782:
1783: sub resize_textarea_js {
1.590 raeburn 1784: my $geometry = &viewport_geometry_js();
1.565 albertel 1785: return <<"RESIZE";
1786: <script type="text/javascript">
1.824 bisitz 1787: // <![CDATA[
1.590 raeburn 1788: $geometry
1.565 albertel 1789:
1.588 albertel 1790: function getX(element) {
1791: var x = 0;
1792: while (element) {
1793: x += element.offsetLeft;
1794: element = element.offsetParent;
1795: }
1796: return x;
1797: }
1798: function getY(element) {
1799: var y = 0;
1800: while (element) {
1801: y += element.offsetTop;
1802: element = element.offsetParent;
1803: }
1804: return y;
1805: }
1806:
1807:
1.565 albertel 1808: function resize_textarea(textarea_id,bottom_id) {
1809: init_geometry();
1810: var textarea = document.getElementById(textarea_id);
1811: //alert(textarea);
1812:
1.588 albertel 1813: var textarea_top = getY(textarea);
1.565 albertel 1814: var textarea_height = textarea.offsetHeight;
1815: var bottom = document.getElementById(bottom_id);
1.588 albertel 1816: var bottom_top = getY(bottom);
1.565 albertel 1817: var bottom_height = bottom.offsetHeight;
1818: var window_height = Geometry.getViewportHeight();
1.588 albertel 1819: var fudge = 23;
1.565 albertel 1820: var new_height = window_height-fudge-textarea_top-bottom_height;
1821: if (new_height < 300) {
1822: new_height = 300;
1823: }
1824: textarea.style.height=new_height+'px';
1825: }
1.824 bisitz 1826: // ]]>
1.565 albertel 1827: </script>
1828: RESIZE
1829:
1830: }
1831:
1.1205 golterma 1832: sub colorfuleditor_js {
1.1248 raeburn 1833: my $browse_or_search;
1834: my $respath;
1835: my ($cnum,$cdom) = &crsauthor_url();
1836: if ($cnum) {
1837: $respath = "/res/$cdom/$cnum/";
1838: my %js_lt = &Apache::lonlocal::texthash(
1839: sunm => 'Sub-directory name',
1840: save => 'Save page to make this permanent',
1841: );
1842: &js_escape(\%js_lt);
1.1400 raeburn 1843: my $showfile_js = &show_crsfiles_js();
1.1248 raeburn 1844: $browse_or_search = <<"END";
1845:
1.1400 raeburn 1846: $showfile_js
1847:
1.1248 raeburn 1848: function toggleChooser(form,element,titleid,only,search) {
1849: var disp = 'none';
1850: if (document.getElementById('chooser_'+element)) {
1851: var curr = document.getElementById('chooser_'+element).style.display;
1852: if (curr == 'none') {
1853: disp='inline';
1854: if (form.elements['chooser_'+element].length) {
1855: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1856: form.elements['chooser_'+element][i].checked = false;
1857: }
1858: }
1859: toggleResImport(form,element);
1860: }
1861: document.getElementById('chooser_'+element).style.display = disp;
1.1400 raeburn 1862: var dirsel = '';
1863: var filesel = '';
1864: if (document.getElementById('chooser_'+element+'_crsres')) {
1865: var currcrsres = document.getElementById('chooser_'+element+'_crsres').style.display;
1866: if (currcrsres == 'none') {
1867: dirsel = 'coursepath_'+element;
1868: var filesel = 'coursefile_'+element;
1869: var include;
1870: if (document.getElementById('crsres_include_'+element)) {
1871: include = document.getElementById('crsres_include_'+element).value;
1872: }
1.1402 raeburn 1873: populateCrsSelects(form,dirsel,filesel,1,include,1,0,1,1,0);
1.1400 raeburn 1874: }
1875: }
1876: if (document.getElementById('chooser_'+element+'_upload')) {
1877: var currcrsupload = document.getElementById('chooser_'+element+'_upload').style.display;
1878: if (currcrsupload == 'none') {
1879: dirsel = 'crsauthorpath_'+element;
1880: filesel = '';
1.1402 raeburn 1881: populateCrsSelects(form,dirsel,filesel,0,'',1,0,1,0,1);
1.1400 raeburn 1882: }
1883: }
1.1248 raeburn 1884: }
1885: }
1886:
1.1400 raeburn 1887: function toggleCrsFile(form,element) {
1.1248 raeburn 1888: if (document.getElementById('chooser_'+element+'_crsres')) {
1889: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1890: if (curr == 'none') {
1.1400 raeburn 1891: if (document.getElementById('coursepath_'+element)) {
1892: var numdirs;
1893: if (document.getElementById('coursepath_'+element).length) {
1894: numdirs = document.getElementById('coursepath_'+element).length;
1895: }
1.1402 raeburn 1896: if ((document.getElementById('hascrsres_'+element)) &&
1897: (document.getElementById('nocrsres_'+element))) {
1898: if (numdirs) {
1899: document.getElementById('hascrsres_'+element).style.display='inline-block';
1900: document.getElementById('nocrsres_'+element).style.display='none';
1901: } else {
1902: document.getElementById('hascrsres_'+element).style.display='none';
1903: document.getElementById('nocrsres_'+element).style.display='inline-block';
1904: }
1905: }
1.1248 raeburn 1906: form.elements['coursepath_'+element].selectedIndex = 0;
1907: if (numdirs > 1) {
1.1400 raeburn 1908: var selelem = form.elements['coursefile_'+element];
1909: var i, len = selelem.options.length -1;
1910: if (len >=0) {
1911: for (i = len; i >= 0; i--) {
1912: selelem.remove(i);
1913: }
1914: selelem.options[0] = new Option('','');
1915: }
1.1248 raeburn 1916: }
1917: }
1.1400 raeburn 1918: }
1.1248 raeburn 1919: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1920: }
1921: if (document.getElementById('chooser_'+element+'_upload')) {
1922: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1923: if (document.getElementById('uploadcrsres_'+element)) {
1924: document.getElementById('uploadcrsres_'+element).value = '';
1925: }
1926: }
1927: return;
1928: }
1929:
1.1400 raeburn 1930: function toggleCrsUpload(form,element) {
1.1248 raeburn 1931: if (document.getElementById('chooser_'+element+'_crsres')) {
1932: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1933: }
1934: if (document.getElementById('chooser_'+element+'_upload')) {
1935: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1936: if (curr == 'none') {
1.1400 raeburn 1937: form.elements['newsubdir_'+element][0].checked = true;
1938: toggleNewsubdir(form,element);
1939: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1940: if (document.getElementById('uploadcrsres_'+element)) {
1941: document.getElementById('uploadcrsres_'+element).value = '';
1.1248 raeburn 1942: }
1943: }
1944: }
1945: return;
1946: }
1947:
1948: function toggleResImport(form,element) {
1949: var choices = new Array('crsres','upload');
1950: for (var i=0; i<choices.length; i++) {
1951: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1952: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1953: }
1954: }
1955: }
1956:
1957: function toggleNewsubdir(form,element) {
1958: var newsub = form.elements['newsubdir_'+element];
1959: if (newsub) {
1960: if (newsub.length) {
1961: for (var j=0; j<newsub.length; j++) {
1962: if (newsub[j].checked) {
1963: if (document.getElementById('newsubdirname_'+element)) {
1964: if (newsub[j].value == '1') {
1965: document.getElementById('newsubdirname_'+element).type = "text";
1966: if (document.getElementById('newsubdir_'+element)) {
1967: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1968: }
1969: } else {
1970: document.getElementById('newsubdirname_'+element).type = "hidden";
1971: document.getElementById('newsubdirname_'+element).value = "";
1972: document.getElementById('newsubdir_'+element).innerHTML = "";
1973: }
1974: }
1975: break;
1976: }
1977: }
1978: }
1979: }
1980: }
1981:
1982: function updateCrsFile(form,element) {
1983: var directory = form.elements['coursepath_'+element];
1984: var filename = form.elements['coursefile_'+element];
1985: var path = directory.options[directory.selectedIndex].value;
1986: var file = filename.options[filename.selectedIndex].value;
1.1400 raeburn 1987: if (file != '') {
1988: form.elements[element].value = '$respath';
1989: if (path == '/') {
1990: form.elements[element].value += file;
1991: } else {
1992: form.elements[element].value += path+'/'+file;
1993: }
1994: unClean();
1995: if (document.getElementById('previewimg_'+element)) {
1996: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1997: var newsrc = document.getElementById('previewimg_'+element).src;
1998: }
1999: if (document.getElementById('showimg_'+element)) {
2000: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
2001: }
1.1248 raeburn 2002: }
2003: toggleChooser(form,element);
2004: return;
2005: }
2006:
2007: function uploadDone(suffix,name) {
2008: if (name) {
2009: document.forms["lonhomework"].elements[suffix].value = name;
2010: unClean();
2011: toggleChooser(document.forms["lonhomework"],suffix);
2012: }
2013: }
2014:
2015: \$(document).ready(function(){
2016:
2017: \$(document).delegate('form :submit', 'click', function( event ) {
2018: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
2019: var buttonId = this.id;
2020: var suffix = buttonId.toString();
2021: suffix = suffix.replace(/^crsupload_/,'');
2022: event.preventDefault();
2023: document.lonhomework.target = 'crsupload_target_'+suffix;
2024: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
2025: \$(this.form).submit();
2026: document.lonhomework.target = '';
2027: if (document.getElementById('crsuploadto_'+suffix)) {
2028: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
2029: }
2030: return false;
2031: }
2032: });
2033: });
2034: END
2035: }
1.1205 golterma 2036: return <<"COLORFULEDIT"
2037: <script type="text/javascript">
2038: // <![CDATA[>
2039: function fold_box(curDepth, lastresource){
2040:
2041: // we need a list because there can be several blocks you need to fold in one tag
2042: var block = document.getElementsByName('foldblock_'+curDepth);
2043: // but there is only one folding button per tag
2044: var foldbutton = document.getElementById('folding_btn_'+curDepth);
2045:
2046: if(block.item(0).style.display == 'none'){
2047:
2048: foldbutton.value = '@{[&mt("Hide")]}';
2049: for (i = 0; i < block.length; i++){
2050: block.item(i).style.display = '';
2051: }
2052: }else{
2053:
2054: foldbutton.value = '@{[&mt("Show")]}';
2055: for (i = 0; i < block.length; i++){
2056: // block.item(i).style.visibility = 'collapse';
2057: block.item(i).style.display = 'none';
2058: }
2059: };
2060: saveState(lastresource);
2061: }
2062:
2063: function saveState (lastresource) {
2064:
2065: var tag_list = getTagList();
2066: if(tag_list != null){
2067: var timestamp = new Date().getTime();
2068: var key = lastresource;
2069:
2070: // the value pattern is: 'time;key1,value1;key2,value2; ... '
2071: // starting with timestamp
2072: var value = timestamp+';';
2073:
2074: // building the list of key-value pairs
2075: for(var i = 0; i < tag_list.length; i++){
2076: value += tag_list[i]+',';
2077: value += document.getElementsByName(tag_list[i])[0].style.display+';';
2078: }
2079:
2080: // only iterate whole storage if nothing to override
2081: if(localStorage.getItem(key) == null){
2082:
2083: // prevent storage from growing large
2084: if(localStorage.length > 50){
2085: var regex_getTimestamp = /^(?:\d)+;/;
2086: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2087: var oldest_key;
2088:
2089: for(var i = 1; i < localStorage.length; i++){
2090: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2091: oldest_key = localStorage.key(i);
2092: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2093: }
2094: }
2095: localStorage.removeItem(oldest_key);
2096: }
2097: }
2098: localStorage.setItem(key,value);
2099: }
2100: }
2101:
2102: // restore folding status of blocks (on page load)
2103: function restoreState (lastresource) {
2104: if(localStorage.getItem(lastresource) != null){
2105: var key = lastresource;
2106: var value = localStorage.getItem(key);
2107: var regex_delTimestamp = /^\d+;/;
2108:
2109: value.replace(regex_delTimestamp, '');
2110:
2111: var valueArr = value.split(';');
2112: var pairs;
2113: var elements;
2114: for (var i = 0; i < valueArr.length; i++){
2115: pairs = valueArr[i].split(',');
2116: elements = document.getElementsByName(pairs[0]);
2117:
2118: for (var j = 0; j < elements.length; j++){
2119: elements[j].style.display = pairs[1];
2120: if (pairs[1] == "none"){
2121: var regex_id = /([_\\d]+)\$/;
2122: regex_id.exec(pairs[0]);
2123: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2124: }
2125: }
2126: }
2127: }
2128: }
2129:
2130: function getTagList () {
2131:
2132: var stringToSearch = document.lonhomework.innerHTML;
2133:
2134: var ret = new Array();
2135: var regex_findBlock = /(foldblock_.*?)"/g;
2136: var tag_list = stringToSearch.match(regex_findBlock);
2137:
2138: if(tag_list != null){
2139: for(var i = 0; i < tag_list.length; i++){
2140: ret.push(tag_list[i].replace(/"/, ''));
2141: }
2142: }
2143: return ret;
2144: }
2145:
2146: function saveScrollPosition (resource) {
2147: var tag_list = getTagList();
2148:
2149: // we dont always want to jump to the first block
2150: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2151: if(\$(window).scrollTop() > 170){
2152: if(tag_list != null){
2153: var result;
2154: for(var i = 0; i < tag_list.length; i++){
2155: if(isElementInViewport(tag_list[i])){
2156: result += tag_list[i]+';';
2157: }
2158: }
2159: sessionStorage.setItem('anchor_'+resource, result);
2160: }
2161: } else {
2162: // we dont need to save zero, just delete the item to leave everything tidy
2163: sessionStorage.removeItem('anchor_'+resource);
2164: }
2165: }
2166:
2167: function restoreScrollPosition(resource){
2168:
2169: var elem = sessionStorage.getItem('anchor_'+resource);
2170: if(elem != null){
2171: var tag_list = elem.split(';');
2172: var elem_list;
2173:
2174: for(var i = 0; i < tag_list.length; i++){
2175: elem_list = document.getElementsByName(tag_list[i]);
2176:
2177: if(elem_list.length > 0){
2178: elem = elem_list[0];
2179: break;
2180: }
2181: }
2182: elem.scrollIntoView();
2183: }
2184: }
2185:
2186: function isElementInViewport(el) {
2187:
2188: // change to last element instead of first
2189: var elem = document.getElementsByName(el);
2190: var rect = elem[0].getBoundingClientRect();
2191:
2192: return (
2193: rect.top >= 0 &&
2194: rect.left >= 0 &&
2195: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2196: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2197: );
2198: }
2199:
2200: function autosize(depth){
2201: var cmInst = window['cm'+depth];
2202: var fitsizeButton = document.getElementById('fitsize'+depth);
2203:
2204: // is fixed size, switching to dynamic
2205: if (sessionStorage.getItem("autosized_"+depth) == null) {
2206: cmInst.setSize("","auto");
2207: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2208: sessionStorage.setItem("autosized_"+depth, "yes");
2209:
2210: // is dynamic size, switching to fixed
2211: } else {
2212: cmInst.setSize("","300px");
2213: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2214: sessionStorage.removeItem("autosized_"+depth);
2215: }
2216: }
2217:
1.1248 raeburn 2218: $browse_or_search
1.1205 golterma 2219:
2220: // ]]>
2221: </script>
2222: COLORFULEDIT
2223: }
2224:
2225: sub xmleditor_js {
2226: return <<XMLEDIT
2227: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2228: <script type="text/javascript">
2229: // <![CDATA[>
2230:
2231: function saveScrollPosition (resource) {
2232:
2233: var scrollPos = \$(window).scrollTop();
2234: sessionStorage.setItem(resource,scrollPos);
2235: }
2236:
2237: function restoreScrollPosition(resource){
2238:
2239: var scrollPos = sessionStorage.getItem(resource);
2240: \$(window).scrollTop(scrollPos);
2241: }
2242:
2243: // unless internet explorer
2244: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2245:
2246: \$(document).ready(function() {
2247: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2248: });
2249: }
2250:
2251: // inserts text at cursor position into codemirror (xml editor only)
2252: function insertText(text){
2253: cm.focus();
2254: var curPos = cm.getCursor();
2255: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2256: }
2257: // ]]>
2258: </script>
2259: XMLEDIT
2260: }
2261:
2262: sub insert_folding_button {
2263: my $curDepth = $Apache::lonxml::curdepth;
2264: my $lastresource = $env{'request.ambiguous'};
2265:
2266: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2267: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2268: }
2269:
1.1248 raeburn 2270: sub crsauthor_url {
2271: my ($url) = @_;
2272: if ($url eq '') {
2273: $url = $ENV{'REQUEST_URI'};
2274: }
2275: my ($cnum,$cdom);
2276: if ($env{'request.course.id'}) {
2277: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2278: if ($audom ne '' && $auname ne '') {
2279: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2280: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2281: $cnum = $auname;
2282: $cdom = $audom;
2283: }
2284: }
2285: }
2286: return ($cnum,$cdom);
2287: }
2288:
2289: sub import_crsauthor_form {
1.1400 raeburn 2290: my ($firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2291: return (0) unless ($env{'request.course.id'});
2292: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2293: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2294: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2295: return (0) unless (($cnum ne '') && ($cdom ne ''));
2296: my @ids=&Apache::lonnet::current_machine_ids();
1.1400 raeburn 2297: my ($output,$is_home,$toppath,%subdirs,%files,%selimport_menus,$include,$exclude);
1.1402 raeburn 2298:
1.1248 raeburn 2299: if (grep(/^\Q$crshome\E$/,@ids)) {
2300: $is_home = 1;
2301: }
1.1400 raeburn 2302: $toppath = "/priv/$cdom/$cnum";
2303: my $nonemptydir = 1;
2304: my $js_only;
2305: if ($only) {
2306: map { $include->{$_} = 1; } split(/\s*,\s*/,$only);
2307: $js_only = join(',',map { &js_escape($_); } sort(keys(%{$include})));
2308: }
2309: $exclude = &Apache::lonnet::priv_exclude();
1.1402 raeburn 2310: &Apache::lonnet::recursedirs($is_home,1,$include,$exclude,1,0,$toppath,'',\%subdirs,\%files);
1.1400 raeburn 2311: my $numdirs = scalar(keys(%files));
1.1248 raeburn 2312: my %lt = &Apache::lonlocal::texthash (
2313: fnam => 'Filename',
2314: dire => 'Directory',
1.1400 raeburn 2315: se => 'Select',
1.1248 raeburn 2316: );
1.1450 raeburn 2317: $output = '<label>'.$lt{'dire'}.': '.
1.1400 raeburn 2318: '<select id="'.$firstselectname.'" name="'.$firstselectname.'" '.
1.1402 raeburn 2319: 'onchange="populateCrsSelects(this.form,'."'$firstselectname','$secondselectname',1,'$js_only',0,1,0,0,0".');">'.
1.1400 raeburn 2320: '<option value="" selected="selected">'.$lt{'se'}.'</option>';
1.1402 raeburn 2321: if ($files{'/'}) {
2322: $output .= '<option value="/">/</option>'."\n";
2323: }
1.1400 raeburn 2324: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
1.1402 raeburn 2325: next if ($key eq '/');
1.1400 raeburn 2326: $output .= '<option value="'.$key.'">'.$key.'</option>'."\n";
2327: }
1.1450 raeburn 2328: $output .= '</select></label><br /><label>'."\n".
1.1402 raeburn 2329: $lt{'fnam'}.': <select id="'.$secondselectname.'" name="'.$secondselectname.'">'."\n".
1.1400 raeburn 2330: '<option value="" selected="selected"></option>'."\n".
1.1450 raeburn 2331: '</select></label>'."\n".
1.1402 raeburn 2332: '<input type="hidden" id="crsres_include_'.$suffix.'" value="'.$only.'" />';
1.1400 raeburn 2333: return ($numdirs,$output);
2334: }
2335:
2336: sub show_crsfiles_js {
2337: my $excluderef = &Apache::lonnet::priv_exclude();
2338: my $se = &js_escape(&mt('Select'));
2339: my $exclude;
2340: if (ref($excluderef) eq 'HASH') {
2341: $exclude = join(',', map { &js_escape($_); } sort(keys(%{$excluderef})));
2342: }
2343: my $js = <<"END";
2344:
2345:
1.1402 raeburn 2346: function populateCrsSelects (form,dirsel,filesel,exc,include,setdir,setfile,recurse,nonemptydir,addtopdir) {
1.1400 raeburn 2347: var relpath = '';
2348: if ((setfile) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2349: var currdir = form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value;
2350: if (currdir == '') {
2351: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2352: selelem = form.elements[filesel];
2353: var j, numfiles = selelem.options.length -1;
2354: if (numfiles >=0) {
2355: for (j = numfiles; j >= 0; j--) {
2356: selelem.remove(j);
2357: }
2358: }
2359: if (selelem.options.length == 0) {
2360: selelem.options[selelem.options.length] = new Option('','');
2361: selelem.selectedIndex = 0;
1.1248 raeburn 2362: }
2363: }
1.1400 raeburn 2364: return;
2365: } else {
2366: relpath = encodeURIComponent(form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value);
1.1248 raeburn 2367: }
2368: }
1.1400 raeburn 2369: var http = new XMLHttpRequest();
2370: var url = "/adm/courseauthor";
2371: var crsrole = "$env{'request.role'}";
2372: var exclude = '';
2373: if (exc) {
2374: exclude = '$exclude';
2375: }
1.1402 raeburn 2376: var params = "role=course&files=1&rec="+recurse+"&nonempty="+nonemptydir+"&exc="+exclude+"&inc="+include+"&addtop="+addtopdir+"&path="+relpath;
1.1400 raeburn 2377: http.open("POST", url, true);
2378: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
2379: http.onreadystatechange = function() {
2380: if (http.readyState == 4 && http.status == 200) {
2381: var data = JSON.parse(http.responseText);
2382: var selelem;
2383: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2384: if (Array.isArray(data.dirs)) {
2385: selelem = form.elements[dirsel];
2386: var i, numdirs = selelem.options.length -1;
2387: if (numdirs >=0) {
2388: for (i = numdirs; i >= 0; i--) {
2389: selelem.remove(i);
2390: }
2391: }
2392: var len = data.dirs.length;
2393: if (len) {
1.1402 raeburn 2394: selelem.options[selelem.options.length] = new Option('$se','');
1.1400 raeburn 2395: var j;
2396: for (j = 0; j < len; j++) {
2397: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
2398: }
2399: selelem.selectedIndex = 0;
2400: }
2401: if (!setfile) {
2402: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2403: selelem = form.elements[filesel];
2404: var j, numfiles = selelem.options.length -1;
2405: if (numfiles >=0) {
2406: for (j = numfiles; j >= 0; j--) {
2407: selelem.remove(j);
2408: }
2409: }
2410: if (selelem.options.length == 0) {
2411: selelem.options[selelem.options.length] = new Option('','');
2412: selelem.selectedIndex = 0;
2413: }
2414: }
2415: }
2416: }
2417: }
2418: if ((setfile) && (filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2419: selelem = form.elements[filesel];
2420: var i, numfiles = selelem.options.length -1;
2421: if (numfiles >=0) {
2422: for (i = numfiles; i >= 0; i--) {
2423: selelem.remove(i);
2424: }
2425: }
2426: var x;
2427: for (x in data.files) {
2428: if (Array.isArray(data.files[x])) {
2429: if (data.files[x].length > 1) {
2430: selelem.options[selelem.options.length] = new Option('$se','');
2431: }
2432: var len = data.files[x].length;
2433: if (len) {
2434: var k;
2435: for (k = 0; k < len; k++) {
2436: selelem.options[selelem.options.length] = new Option(data.files[x][k],data.files[x][k]);
2437: }
2438: selelem.selectedIndex = 0;
2439: }
2440: }
2441: }
2442: if (selelem.options.length == 0) {
2443: selelem.options[selelem.options.length] = new Option('','');
2444: selelem.selectedIndex = 0;
2445: }
1.1248 raeburn 2446: }
2447: }
2448: }
1.1400 raeburn 2449: http.send(params);
1.1248 raeburn 2450: }
1.1400 raeburn 2451: END
1.1248 raeburn 2452: }
2453:
1.1426 raeburn 2454: sub crsauthor_rights {
2455: my ($rightsfile,$path,$docroot,$cnum,$cdom) = @_;
2456: my $sourcerights = "$path/$rightsfile";
2457: my $now = time;
2458: if (!-e $sourcerights) {
2459: my $cid = $cdom.'_'.$cnum;
2460: if (!-e "$docroot/priv/$cdom") {
2461: mkdir("$docroot/priv/$cdom",0755);
2462: }
2463: if (!-e "$docroot/priv/$cdom/$cnum") {
2464: mkdir("$docroot/priv/$cdom/$cnum",0755);
2465: }
2466: if (open(my $fh,">$sourcerights")) {
2467: print $fh <<END;
2468: <accessrule effect="deny" realm="" type="course" role="" />
2469: <accessrule effect="allow" realm="$cid" type="course" role="" />
2470: END
2471: close($fh);
2472: }
2473: }
2474: if (!-e "$sourcerights.meta") {
2475: if (open(my $fh,">$sourcerights.meta")) {
2476: my $author=$env{'environment.firstname'}.' '.
2477: $env{'environment.middlename'}.' '.
2478: $env{'environment.lastname'}.' '.
2479: $env{'environment.generation'};
2480: $author =~ s/\s+$//;
2481: print $fh <<"END";
2482:
2483: <abstract></abstract>
2484: <author>$author</author>
2485: <authorspace>$cnum:$cdom</authorspace>
2486: <copyright>private</copyright>
2487: <creationdate>$now</creationdate>
2488: <customdistributionfile></customdistributionfile>
2489: <dependencies></dependencies>
2490: <domain>$cdom</domain>
2491: <highestgradelevel>0</highestgradelevel>
2492: <keywords></keywords>
1.1445 raeburn 2493: <language>notset</language>
1.1426 raeburn 2494: <lastrevisiondate>$now</lastrevisiondate>
2495: <lowestgradelevel>0</lowestgradelevel>
2496: <mime>rights</mime>
2497: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
2498: <notes></notes>
2499: <obsolete></obsolete>
2500: <obsoletereplacement></obsoletereplacement>
2501: <owner>$cnum:$cdom</owner>
2502: <rule>deny:::course,allow:$cid::course</rule>
2503: <sourceavail></sourceavail>
2504: <standards></standards>
2505: <subject></subject>
2506: <title>Course Authoring Rights</title>
2507: END
2508: close($fh);
2509: }
2510: }
2511: return;
2512: }
2513:
1.565 albertel 2514: =pod
2515:
1.1420 raeburn 2516: =item * &iframe_wrapper_headjs()
2517:
1.1425 raeburn 2518: emits javascript containing two global vars to facilitate handling of resizing
2519: by code in iframe_wrapper_resizejs() used when an iframe is present in a page
2520: with standard LON-CAPA menus.
2521:
2522: =cut
2523:
1.1420 raeburn 2524: #
2525: # Where iframe is in use, if window.onload() executes before the custom resize function
2526: # has been defined (jQuery), two global javascript vars (LCnotready and LCresizedef)
2527: # are used to ensure document.ready() triggers a call to resize, so the iframe contents
2528: # do not obscure the Functions menu.
2529: #
2530:
2531: sub iframe_wrapper_headjs {
2532: return <<"ENDJS";
2533: <script type="text/javascript">
2534: // <![CDATA[
2535: var LCnotready = 0;
2536: var LCresizedef = 0;
2537: // ]]>
2538: </script>
2539:
2540: ENDJS
2541:
2542: }
2543:
2544: =pod
2545:
2546: =item * &iframe_wrapper_resizejs()
2547:
1.1425 raeburn 2548: emits javascript used to handle resizing for a page containing
2549: an iframe, to ensure that the iframe does not obscure any
2550: standard LON-CAPA menu items.
2551:
2552: =back
2553:
2554: =cut
2555:
1.1420 raeburn 2556: #
2557: # jQuery to use when iframe is in use and a page resize occurs.
2558: # This script will ensure that the iframe does not obscure any
2559: # standard LON-CAPA inline menus (primary, secondary, and/or
2560: # breadcrumbs and Functions menus. Expects javascript from
2561: # &iframe_wrapper_headjs() to be in head portion of the web page,
2562: # e.g., by inclusion in second arg passed to &start_page().
2563: #
2564:
2565: sub iframe_wrapper_resizejs {
2566: my $offset = 5;
2567: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
2568: if (($env{'form.inhibitmenu'} eq 'yes') || ($env{'form.only_body'})) {
2569: $offset = 0;
2570: }
2571: return &Apache::lonhtmlcommon::scripttag(<<SCRIPT);
2572: \$(document).ready( function() {
2573: \$(window).unbind('resize').resize(function(){
2574: var header = null;
2575: var offset = $offset;
2576: var height = 0;
2577: var hdrtop = 0;
1.1421 raeburn 2578: if (\$('div.LC_menus_content:first').length) {
2579: if (\$('div.LC_menus_content:first').hasClass ("shown")) {
2580: header = \$('div.LC_menus_content:first');
1.1423 raeburn 2581: offset = 12;
1.1421 raeburn 2582: }
2583: } else if (\$('div.LC_head_subbox:first').length) {
1.1420 raeburn 2584: header = \$('div.LC_head_subbox:first');
2585: offset = 9;
2586: } else {
2587: if (\$('#LC_breadcrumbs').length) {
2588: header = \$('#LC_breadcrumbs');
2589: }
2590: }
2591: if (header != null && header.length) {
2592: height = header.height();
2593: hdrtop = header.position().top;
2594: }
2595: var pos = height + hdrtop + offset;
2596: \$('.LC_iframecontainer').css('top', pos);
2597: });
2598: LCresizedef = 1;
2599: if (LCnotready == 1) {
2600: LCnotready = 0;
2601: \$(window).trigger('resize');
2602: }
2603: });
2604: window.onload = function(){
2605: if (LCresizedef) {
2606: LCnotready = 0;
2607: \$(window).trigger('resize');
2608: } else {
2609: LCnotready = 1;
2610: }
2611: };
2612: SCRIPT
2613:
2614: }
2615:
2616: =pod
2617:
1.256 matthew 2618: =head1 Excel and CSV file utility routines
2619:
2620: =cut
2621:
2622: ###############################################################
2623: ###############################################################
2624:
2625: =pod
2626:
1.1162 raeburn 2627: =over 4
2628:
1.648 raeburn 2629: =item * &csv_translate($text)
1.37 matthew 2630:
1.185 www 2631: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2632: format.
2633:
2634: =cut
2635:
1.180 matthew 2636: ###############################################################
2637: ###############################################################
1.37 matthew 2638: sub csv_translate {
2639: my $text = shift;
2640: $text =~ s/\"/\"\"/g;
1.209 albertel 2641: $text =~ s/\n/ /g;
1.37 matthew 2642: return $text;
2643: }
1.180 matthew 2644:
2645: ###############################################################
2646: ###############################################################
2647:
2648: =pod
2649:
1.648 raeburn 2650: =item * &define_excel_formats()
1.180 matthew 2651:
2652: Define some commonly used Excel cell formats.
2653:
2654: Currently supported formats:
2655:
2656: =over 4
2657:
2658: =item header
2659:
2660: =item bold
2661:
2662: =item h1
2663:
2664: =item h2
2665:
2666: =item h3
2667:
1.256 matthew 2668: =item h4
2669:
2670: =item i
2671:
1.180 matthew 2672: =item date
2673:
2674: =back
2675:
2676: Inputs: $workbook
2677:
2678: Returns: $format, a hash reference.
2679:
1.1057 foxr 2680:
1.180 matthew 2681: =cut
2682:
2683: ###############################################################
2684: ###############################################################
2685: sub define_excel_formats {
2686: my ($workbook) = @_;
2687: my $format;
2688: $format->{'header'} = $workbook->add_format(bold => 1,
2689: bottom => 1,
2690: align => 'center');
2691: $format->{'bold'} = $workbook->add_format(bold=>1);
2692: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2693: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2694: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2695: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2696: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2697: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2698: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2699: return $format;
2700: }
2701:
2702: ###############################################################
2703: ###############################################################
1.113 bowersj2 2704:
2705: =pod
2706:
1.648 raeburn 2707: =item * &create_workbook()
1.255 matthew 2708:
2709: Create an Excel worksheet. If it fails, output message on the
2710: request object and return undefs.
2711:
2712: Inputs: Apache request object
2713:
2714: Returns (undef) on failure,
2715: Excel worksheet object, scalar with filename, and formats
2716: from &Apache::loncommon::define_excel_formats on success
2717:
2718: =cut
2719:
2720: ###############################################################
2721: ###############################################################
2722: sub create_workbook {
2723: my ($r) = @_;
2724: #
2725: # Create the excel spreadsheet
2726: my $filename = '/prtspool/'.
1.258 albertel 2727: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2728: time.'_'.rand(1000000000).'.xls';
2729: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2730: if (! defined($workbook)) {
2731: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2732: $r->print(
2733: '<p class="LC_error">'
2734: .&mt('Problems occurred in creating the new Excel file.')
2735: .' '.&mt('This error has been logged.')
2736: .' '.&mt('Please alert your LON-CAPA administrator.')
2737: .'</p>'
2738: );
1.255 matthew 2739: return (undef);
2740: }
2741: #
1.1014 foxr 2742: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2743: #
2744: my $format = &Apache::loncommon::define_excel_formats($workbook);
2745: return ($workbook,$filename,$format);
2746: }
2747:
2748: ###############################################################
2749: ###############################################################
2750:
2751: =pod
2752:
1.648 raeburn 2753: =item * &create_text_file()
1.113 bowersj2 2754:
1.542 raeburn 2755: Create a file to write to and eventually make available to the user.
1.256 matthew 2756: If file creation fails, outputs an error message on the request object and
2757: return undefs.
1.113 bowersj2 2758:
1.256 matthew 2759: Inputs: Apache request object, and file suffix
1.113 bowersj2 2760:
1.256 matthew 2761: Returns (undef) on failure,
2762: Filehandle and filename on success.
1.113 bowersj2 2763:
2764: =cut
2765:
1.256 matthew 2766: ###############################################################
2767: ###############################################################
2768: sub create_text_file {
2769: my ($r,$suffix) = @_;
2770: if (! defined($suffix)) { $suffix = 'txt'; };
2771: my $fh;
2772: my $filename = '/prtspool/'.
1.258 albertel 2773: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2774: time.'_'.rand(1000000000).'.'.$suffix;
2775: $fh = Apache::File->new('>/home/httpd'.$filename);
2776: if (! defined($fh)) {
2777: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2778: $r->print(
2779: '<p class="LC_error">'
2780: .&mt('Problems occurred in creating the output file.')
2781: .' '.&mt('This error has been logged.')
2782: .' '.&mt('Please alert your LON-CAPA administrator.')
2783: .'</p>'
2784: );
1.113 bowersj2 2785: }
1.256 matthew 2786: return ($fh,$filename)
1.113 bowersj2 2787: }
2788:
2789:
1.256 matthew 2790: =pod
1.113 bowersj2 2791:
2792: =back
2793:
2794: =cut
1.37 matthew 2795:
2796: ###############################################################
1.33 matthew 2797: ## Home server <option> list generating code ##
2798: ###############################################################
1.35 matthew 2799:
1.169 www 2800: # ------------------------------------------
2801:
2802: sub domain_select {
1.1289 raeburn 2803: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2804: my @possdoms;
2805: if (ref($incdoms) eq 'ARRAY') {
2806: @possdoms = @{$incdoms};
2807: } else {
2808: @possdoms = &Apache::lonnet::all_domains();
2809: }
2810:
1.169 www 2811: my %domains=map {
1.514 albertel 2812: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2813: } @possdoms;
2814:
2815: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2816: foreach my $dom (@{$excdoms}) {
2817: delete($domains{$dom});
2818: }
2819: }
2820:
1.169 www 2821: if ($multiple) {
2822: $domains{''}=&mt('Any domain');
1.550 albertel 2823: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2824: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2825: } else {
1.550 albertel 2826: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2827: return &select_form($name,$value,\%domains);
1.169 www 2828: }
2829: }
2830:
1.282 albertel 2831: #-------------------------------------------
2832:
2833: =pod
2834:
1.519 raeburn 2835: =head1 Routines for form select boxes
2836:
2837: =over 4
2838:
1.648 raeburn 2839: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2840:
2841: Returns a string containing a <select> element int multiple mode
2842:
2843:
2844: Args:
2845: $name - name of the <select> element
1.506 raeburn 2846: $value - scalar or array ref of values that should already be selected
1.282 albertel 2847: $size - number of rows long the select element is
1.283 albertel 2848: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2849: (shown text should already have been &mt())
1.506 raeburn 2850: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2851:
1.282 albertel 2852: =cut
2853:
2854: #-------------------------------------------
1.169 www 2855: sub multiple_select_form {
1.284 albertel 2856: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2857: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2858: my $output='';
1.191 matthew 2859: if (! defined($size)) {
2860: $size = 4;
1.283 albertel 2861: if (scalar(keys(%$hash))<4) {
2862: $size = scalar(keys(%$hash));
1.191 matthew 2863: }
2864: }
1.734 bisitz 2865: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2866: my @order;
1.506 raeburn 2867: if (ref($order) eq 'ARRAY') {
2868: @order = @{$order};
2869: } else {
2870: @order = sort(keys(%$hash));
1.501 banghart 2871: }
2872: if (exists($$hash{'select_form_order'})) {
2873: @order = @{$$hash{'select_form_order'}};
2874: }
2875:
1.284 albertel 2876: foreach my $key (@order) {
1.356 albertel 2877: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2878: $output.='selected="selected" ' if ($selected{$key});
2879: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2880: }
2881: $output.="</select>\n";
2882: return $output;
2883: }
2884:
1.88 www 2885: #-------------------------------------------
2886:
2887: =pod
2888:
1.1254 raeburn 2889: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2890:
2891: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2892: allow a user to select options from a ref to a hash containing:
2893: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2894: a javascript onchange item, e.g., onchange="this.form.submit();".
2895: An optional arg -- $readonly -- if true will cause the select form
2896: to be disabled, e.g., for the case where an instructor has a section-
2897: specific role, and is viewing/modifying parameters.
1.970 raeburn 2898:
1.88 www 2899: See lonrights.pm for an example invocation and use.
2900:
2901: =cut
2902:
2903: #-------------------------------------------
2904: sub select_form {
1.1228 raeburn 2905: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2906: return unless (ref($hashref) eq 'HASH');
2907: if ($onchange) {
2908: $onchange = ' onchange="'.$onchange.'"';
2909: }
1.1228 raeburn 2910: my $disabled;
2911: if ($readonly) {
2912: $disabled = ' disabled="disabled"';
2913: }
2914: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2915: my @keys;
1.970 raeburn 2916: if (exists($hashref->{'select_form_order'})) {
2917: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2918: } else {
1.970 raeburn 2919: @keys=sort(keys(%{$hashref}));
1.128 albertel 2920: }
1.356 albertel 2921: foreach my $key (@keys) {
2922: $selectform.=
2923: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2924: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2925: ">".$hashref->{$key}."</option>\n";
1.88 www 2926: }
2927: $selectform.="</select>";
2928: return $selectform;
2929: }
2930:
1.475 www 2931: # For display filters
2932:
2933: sub display_filter {
1.1074 raeburn 2934: my ($context) = @_;
1.475 www 2935: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2936: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2937: my $phraseinput = 'hidden';
2938: my $includeinput = 'hidden';
2939: my ($checked,$includetypestext);
2940: if ($env{'form.displayfilter'} eq 'containing') {
2941: $phraseinput = 'text';
2942: if ($context eq 'parmslog') {
2943: $includeinput = 'checkbox';
2944: if ($env{'form.includetypes'}) {
2945: $checked = ' checked="checked"';
2946: }
2947: $includetypestext = &mt('Include parameter types');
2948: }
2949: } else {
2950: $includetypestext = ' ';
2951: }
2952: my ($additional,$secondid,$thirdid);
2953: if ($context eq 'parmslog') {
2954: $additional =
2955: '<label><input type="'.$includeinput.'" name="includetypes"'.
2956: $checked.' name="includetypes" value="1" id="includetypes" />'.
2957: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2958: '</label>';
2959: $secondid = 'includetypes';
2960: $thirdid = 'includetypestext';
2961: }
2962: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2963: '$secondid','$thirdid')";
2964: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.1403 raeburn 2965: &Apache::lonmeta::selectbox('show',$env{'form.show'},'',undef,
1.475 www 2966: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2967: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2968: &mt('Filter: [_1]',
1.477 www 2969: &select_form($env{'form.displayfilter'},
2970: 'displayfilter',
1.970 raeburn 2971: {'currentfolder' => 'Current folder/page',
1.477 www 2972: 'containing' => 'Containing phrase',
1.1074 raeburn 2973: 'none' => 'None'},$onchange)).' '.
2974: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2975: &HTML::Entities::encode($env{'form.containingphrase'}).
2976: '" />'.$additional;
2977: }
2978:
2979: sub display_filter_js {
2980: my $includetext = &mt('Include parameter types');
2981: return <<"ENDJS";
2982:
2983: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2984: var firstType = 'hidden';
2985: if (setter.options[setter.selectedIndex].value == 'containing') {
2986: firstType = 'text';
2987: }
2988: firstObject = document.getElementById(firstid);
2989: if (typeof(firstObject) == 'object') {
2990: if (firstObject.type != firstType) {
2991: changeInputType(firstObject,firstType);
2992: }
2993: }
2994: if (context == 'parmslog') {
2995: var secondType = 'hidden';
2996: if (firstType == 'text') {
2997: secondType = 'checkbox';
2998: }
2999: secondObject = document.getElementById(secondid);
3000: if (typeof(secondObject) == 'object') {
3001: if (secondObject.type != secondType) {
3002: changeInputType(secondObject,secondType);
3003: }
3004: }
3005: var textItem = document.getElementById(thirdid);
3006: var currtext = textItem.innerHTML;
3007: var newtext;
3008: if (firstType == 'text') {
3009: newtext = '$includetext';
3010: } else {
3011: newtext = ' ';
3012: }
3013: if (currtext != newtext) {
3014: textItem.innerHTML = newtext;
3015: }
3016: }
3017: return;
3018: }
3019:
3020: function changeInputType(oldObject,newType) {
3021: var newObject = document.createElement('input');
3022: newObject.type = newType;
3023: if (oldObject.size) {
3024: newObject.size = oldObject.size;
3025: }
3026: if (oldObject.value) {
3027: newObject.value = oldObject.value;
3028: }
3029: if (oldObject.name) {
3030: newObject.name = oldObject.name;
3031: }
3032: if (oldObject.id) {
3033: newObject.id = oldObject.id;
3034: }
3035: oldObject.parentNode.replaceChild(newObject,oldObject);
3036: return;
3037: }
3038:
3039: ENDJS
1.475 www 3040: }
3041:
1.167 www 3042: sub gradeleveldescription {
3043: my $gradelevel=shift;
3044: my %gradelevels=(0 => 'Not specified',
3045: 1 => 'Grade 1',
3046: 2 => 'Grade 2',
3047: 3 => 'Grade 3',
3048: 4 => 'Grade 4',
3049: 5 => 'Grade 5',
3050: 6 => 'Grade 6',
3051: 7 => 'Grade 7',
3052: 8 => 'Grade 8',
3053: 9 => 'Grade 9',
3054: 10 => 'Grade 10',
3055: 11 => 'Grade 11',
3056: 12 => 'Grade 12',
3057: 13 => 'Grade 13',
3058: 14 => '100 Level',
3059: 15 => '200 Level',
3060: 16 => '300 Level',
3061: 17 => '400 Level',
3062: 18 => 'Graduate Level');
3063: return &mt($gradelevels{$gradelevel});
3064: }
3065:
1.163 www 3066: sub select_level_form {
3067: my ($deflevel,$name)=@_;
3068: unless ($deflevel) { $deflevel=0; }
1.167 www 3069: my $selectform = "<select name=\"$name\" size=\"1\">\n";
3070: for (my $i=0; $i<=18; $i++) {
3071: $selectform.="<option value=\"$i\" ".
1.253 albertel 3072: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 3073: ">".&gradeleveldescription($i)."</option>\n";
3074: }
3075: $selectform.="</select>";
3076: return $selectform;
1.163 www 3077: }
1.167 www 3078:
1.35 matthew 3079: #-------------------------------------------
3080:
1.45 matthew 3081: =pod
3082:
1.1453 raeburn 3083: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled,$id)
1.35 matthew 3084:
3085: Returns a string containing a <select name='$name' size='1'> form to
3086: allow a user to select the domain to preform an operation in.
3087: See loncreateuser.pm for an example invocation and use.
3088:
1.90 www 3089: If the $includeempty flag is set, it also includes an empty choice ("no domain
3090: selected");
3091:
1.743 raeburn 3092: If the $showdomdesc flag is set, the domain name is followed by the domain description.
3093:
1.910 raeburn 3094: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
3095:
1.1121 raeburn 3096: The optional $incdoms is a reference to an array of domains which will be the only available options.
3097:
3098: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 3099:
1.1256 raeburn 3100: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
3101:
1.1453 raeburn 3102: The option $id argument is the value (if any) to set as the (unique) id attribute for the select tag.
3103:
1.35 matthew 3104: =cut
3105:
3106: #-------------------------------------------
1.34 matthew 3107: sub select_dom_form {
1.1453 raeburn 3108: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled,$id) = @_;
1.872 raeburn 3109: if ($onchange) {
1.874 raeburn 3110: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 3111: }
1.1256 raeburn 3112: if ($disabled) {
3113: $disabled = ' disabled="disabled"';
3114: }
1.1453 raeburn 3115: if ($id ne '') {
3116: $id = ' id="'.$id.'"';
3117: }
1.1121 raeburn 3118: my (@domains,%exclude);
1.910 raeburn 3119: if (ref($incdoms) eq 'ARRAY') {
3120: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
3121: } else {
3122: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
3123: }
1.90 www 3124: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 3125: if (ref($excdoms) eq 'ARRAY') {
3126: map { $exclude{$_} = 1; } @{$excdoms};
3127: }
1.1453 raeburn 3128: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled$id>\n";
1.356 albertel 3129: foreach my $dom (@domains) {
1.1121 raeburn 3130: next if ($exclude{$dom});
1.356 albertel 3131: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 3132: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
3133: if ($showdomdesc) {
3134: if ($dom ne '') {
3135: my $domdesc = &Apache::lonnet::domain($dom,'description');
3136: if ($domdesc ne '') {
3137: $selectdomain .= ' ('.$domdesc.')';
3138: }
3139: }
3140: }
3141: $selectdomain .= "</option>\n";
1.34 matthew 3142: }
3143: $selectdomain.="</select>";
3144: return $selectdomain;
3145: }
3146:
1.35 matthew 3147: #-------------------------------------------
3148:
1.45 matthew 3149: =pod
3150:
1.648 raeburn 3151: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 3152:
1.586 raeburn 3153: input: 4 arguments (two required, two optional) -
3154: $domain - domain of new user
3155: $name - name of form element
3156: $default - Value of 'default' causes a default item to be first
3157: option, and selected by default.
3158: $hide - Value of 'hide' causes hiding of the name of the server,
3159: if 1 server found, or default, if 0 found.
1.594 raeburn 3160: output: returns 2 items:
1.586 raeburn 3161: (a) form element which contains either:
3162: (i) <select name="$name">
3163: <option value="$hostid1">$hostid $servers{$hostid}</option>
3164: <option value="$hostid2">$hostid $servers{$hostid}</option>
3165: </select>
3166: form item if there are multiple library servers in $domain, or
3167: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
3168: if there is only one library server in $domain.
3169:
3170: (b) number of library servers found.
3171:
3172: See loncreateuser.pm for example of use.
1.35 matthew 3173:
3174: =cut
3175:
3176: #-------------------------------------------
1.586 raeburn 3177: sub home_server_form_item {
3178: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 3179: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 3180: my $result;
3181: my $numlib = keys(%servers);
3182: if ($numlib > 1) {
3183: $result .= '<select name="'.$name.'" />'."\n";
3184: if ($default) {
1.804 bisitz 3185: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 3186: '</option>'."\n";
3187: }
3188: foreach my $hostid (sort(keys(%servers))) {
3189: $result.= '<option value="'.$hostid.'">'.
3190: $hostid.' '.$servers{$hostid}."</option>\n";
3191: }
3192: $result .= '</select>'."\n";
3193: } elsif ($numlib == 1) {
3194: my $hostid;
3195: foreach my $item (keys(%servers)) {
3196: $hostid = $item;
3197: }
3198: $result .= '<input type="hidden" name="'.$name.'" value="'.
3199: $hostid.'" />';
3200: if (!$hide) {
3201: $result .= $hostid.' '.$servers{$hostid};
3202: }
3203: $result .= "\n";
3204: } elsif ($default) {
3205: $result .= '<input type="hidden" name="'.$name.
3206: '" value="default" />';
3207: if (!$hide) {
3208: $result .= &mt('default');
3209: }
3210: $result .= "\n";
1.33 matthew 3211: }
1.586 raeburn 3212: return ($result,$numlib);
1.33 matthew 3213: }
1.112 bowersj2 3214:
3215: =pod
3216:
1.534 albertel 3217: =back
3218:
1.112 bowersj2 3219: =cut
1.87 matthew 3220:
3221: ###############################################################
1.112 bowersj2 3222: ## Decoding User Agent ##
1.87 matthew 3223: ###############################################################
3224:
3225: =pod
3226:
1.112 bowersj2 3227: =head1 Decoding the User Agent
3228:
3229: =over 4
3230:
3231: =item * &decode_user_agent()
1.87 matthew 3232:
3233: Inputs: $r
3234:
3235: Outputs:
3236:
3237: =over 4
3238:
1.112 bowersj2 3239: =item * $httpbrowser
1.87 matthew 3240:
1.112 bowersj2 3241: =item * $clientbrowser
1.87 matthew 3242:
1.112 bowersj2 3243: =item * $clientversion
1.87 matthew 3244:
1.112 bowersj2 3245: =item * $clientmathml
1.87 matthew 3246:
1.112 bowersj2 3247: =item * $clientunicode
1.87 matthew 3248:
1.112 bowersj2 3249: =item * $clientos
1.87 matthew 3250:
1.1137 raeburn 3251: =item * $clientmobile
3252:
1.1141 raeburn 3253: =item * $clientinfo
3254:
1.1194 raeburn 3255: =item * $clientosversion
3256:
1.87 matthew 3257: =back
3258:
1.157 matthew 3259: =back
3260:
1.87 matthew 3261: =cut
3262:
3263: ###############################################################
3264: ###############################################################
3265: sub decode_user_agent {
1.247 albertel 3266: my ($r)=@_;
1.87 matthew 3267: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
3268: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
3269: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 3270: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 3271: my $clientbrowser='unknown';
3272: my $clientversion='0';
3273: my $clientmathml='';
3274: my $clientunicode='0';
1.1137 raeburn 3275: my $clientmobile=0;
1.1194 raeburn 3276: my $clientosversion='';
1.87 matthew 3277: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 3278: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 3279: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
3280: $clientbrowser=$bname;
3281: $httpbrowser=~/$vreg/i;
3282: $clientversion=$1;
3283: $clientmathml=($clientversion>=$minv);
3284: $clientunicode=($clientversion>=$univ);
3285: }
3286: }
3287: my $clientos='unknown';
1.1141 raeburn 3288: my $clientinfo;
1.87 matthew 3289: if (($httpbrowser=~/linux/i) ||
3290: ($httpbrowser=~/unix/i) ||
3291: ($httpbrowser=~/ux/i) ||
3292: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
3293: if (($httpbrowser=~/vax/i) ||
3294: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
3295: if ($httpbrowser=~/next/i) { $clientos='next'; }
3296: if (($httpbrowser=~/mac/i) ||
3297: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 3298: if ($httpbrowser=~/win/i) {
3299: $clientos='win';
3300: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
3301: $clientosversion = $1;
3302: }
3303: }
1.87 matthew 3304: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 3305: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
3306: $clientmobile=lc($1);
3307: }
1.1141 raeburn 3308: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
3309: $clientinfo = 'firefox-'.$1;
3310: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3311: $clientinfo = 'chromeframe-'.$1;
3312: }
1.87 matthew 3313: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3314: $clientunicode,$clientos,$clientmobile,$clientinfo,
3315: $clientosversion);
1.87 matthew 3316: }
3317:
1.32 matthew 3318: ###############################################################
3319: ## Authentication changing form generation subroutines ##
3320: ###############################################################
3321: ##
3322: ## All of the authform_xxxxxxx subroutines take their inputs in a
3323: ## hash, and have reasonable default values.
3324: ##
3325: ## formname = the name given in the <form> tag.
1.35 matthew 3326: #-------------------------------------------
3327:
1.45 matthew 3328: =pod
3329:
1.112 bowersj2 3330: =head1 Authentication Routines
3331:
3332: =over 4
3333:
1.648 raeburn 3334: =item * &authform_xxxxxx()
1.35 matthew 3335:
3336: The authform_xxxxxx subroutines provide javascript and html forms which
3337: handle some of the conveniences required for authentication forms.
3338: This is not an optimal method, but it works.
3339:
3340: =over 4
3341:
1.112 bowersj2 3342: =item * authform_header
1.35 matthew 3343:
1.112 bowersj2 3344: =item * authform_authorwarning
1.35 matthew 3345:
1.112 bowersj2 3346: =item * authform_nochange
1.35 matthew 3347:
1.112 bowersj2 3348: =item * authform_kerberos
1.35 matthew 3349:
1.112 bowersj2 3350: =item * authform_internal
1.35 matthew 3351:
1.112 bowersj2 3352: =item * authform_filesystem
1.35 matthew 3353:
1.1310 raeburn 3354: =item * authform_lti
3355:
1.35 matthew 3356: =back
3357:
1.648 raeburn 3358: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3359:
1.35 matthew 3360: =cut
3361:
3362: #-------------------------------------------
1.32 matthew 3363: sub authform_header{
3364: my %in = (
3365: formname => 'cu',
1.80 albertel 3366: kerb_def_dom => '',
1.32 matthew 3367: @_,
3368: );
3369: $in{'formname'} = 'document.' . $in{'formname'};
3370: my $result='';
1.80 albertel 3371:
3372: #---------------------------------------------- Code for upper case translation
3373: my $Javascript_toUpperCase;
3374: unless ($in{kerb_def_dom}) {
3375: $Javascript_toUpperCase =<<"END";
3376: switch (choice) {
3377: case 'krb': currentform.elements[choicearg].value =
3378: currentform.elements[choicearg].value.toUpperCase();
3379: break;
3380: default:
3381: }
3382: END
3383: } else {
3384: $Javascript_toUpperCase = "";
3385: }
3386:
1.165 raeburn 3387: my $radioval = "'nochange'";
1.591 raeburn 3388: if (defined($in{'curr_authtype'})) {
3389: if ($in{'curr_authtype'} ne '') {
3390: $radioval = "'".$in{'curr_authtype'}."arg'";
3391: }
1.174 matthew 3392: }
1.165 raeburn 3393: my $argfield = 'null';
1.591 raeburn 3394: if (defined($in{'mode'})) {
1.165 raeburn 3395: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3396: if (defined($in{'curr_autharg'})) {
3397: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3398: $argfield = "'$in{'curr_autharg'}'";
3399: }
3400: }
3401: }
3402: }
3403:
1.32 matthew 3404: $result.=<<"END";
3405: var current = new Object();
1.165 raeburn 3406: current.radiovalue = $radioval;
3407: current.argfield = $argfield;
1.32 matthew 3408:
3409: function changed_radio(choice,currentform) {
3410: var choicearg = choice + 'arg';
3411: // If a radio button in changed, we need to change the argfield
3412: if (current.radiovalue != choice) {
3413: current.radiovalue = choice;
3414: if (current.argfield != null) {
3415: currentform.elements[current.argfield].value = '';
3416: }
3417: if (choice == 'nochange') {
3418: current.argfield = null;
3419: } else {
3420: current.argfield = choicearg;
3421: switch(choice) {
3422: case 'krb':
3423: currentform.elements[current.argfield].value =
3424: "$in{'kerb_def_dom'}";
3425: break;
3426: default:
3427: break;
3428: }
3429: }
3430: }
3431: return;
3432: }
1.22 www 3433:
1.32 matthew 3434: function changed_text(choice,currentform) {
3435: var choicearg = choice + 'arg';
3436: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3437: $Javascript_toUpperCase
1.32 matthew 3438: // clear old field
3439: if ((current.argfield != choicearg) && (current.argfield != null)) {
3440: currentform.elements[current.argfield].value = '';
3441: }
3442: current.argfield = choicearg;
3443: }
3444: set_auth_radio_buttons(choice,currentform);
3445: return;
1.20 www 3446: }
1.32 matthew 3447:
3448: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3449: var numauthchoices = currentform.login.length;
3450: if (typeof numauthchoices == "undefined") {
3451: return;
3452: }
1.32 matthew 3453: var i=0;
1.986 raeburn 3454: while (i < numauthchoices) {
1.32 matthew 3455: if (currentform.login[i].value == newvalue) { break; }
3456: i++;
3457: }
1.986 raeburn 3458: if (i == numauthchoices) {
1.32 matthew 3459: return;
3460: }
3461: current.radiovalue = newvalue;
3462: currentform.login[i].checked = true;
3463: return;
3464: }
3465: END
3466: return $result;
3467: }
3468:
1.1106 raeburn 3469: sub authform_authorwarning {
1.32 matthew 3470: my $result='';
1.144 matthew 3471: $result='<i>'.
3472: &mt('As a general rule, only authors or co-authors should be '.
3473: 'filesystem authenticated '.
3474: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3475: return $result;
3476: }
3477:
1.1106 raeburn 3478: sub authform_nochange {
1.32 matthew 3479: my %in = (
3480: formname => 'document.cu',
3481: kerb_def_dom => 'MSU.EDU',
3482: @_,
3483: );
1.1106 raeburn 3484: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3485: my $result;
1.1104 raeburn 3486: if (!$authnum) {
1.1105 raeburn 3487: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3488: } else {
3489: $result = '<label>'.&mt('[_1] Do not change login data',
3490: '<input type="radio" name="login" value="nochange" '.
3491: 'checked="checked" onclick="'.
1.281 albertel 3492: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3493: '</label>';
1.586 raeburn 3494: }
1.32 matthew 3495: return $result;
3496: }
3497:
1.591 raeburn 3498: sub authform_kerberos {
1.32 matthew 3499: my %in = (
3500: formname => 'document.cu',
3501: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3502: kerb_def_auth => 'krb4',
1.32 matthew 3503: @_,
3504: );
1.586 raeburn 3505: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3506: $autharg,$jscall,$disabled);
1.1106 raeburn 3507: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3508: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3509: $check5 = ' checked="checked"';
1.80 albertel 3510: } else {
1.772 bisitz 3511: $check4 = ' checked="checked"';
1.80 albertel 3512: }
1.1259 raeburn 3513: if ($in{'readonly'}) {
3514: $disabled = ' disabled="disabled"';
3515: }
1.165 raeburn 3516: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3517: if (defined($in{'curr_authtype'})) {
3518: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3519: $krbcheck = ' checked="checked"';
1.623 raeburn 3520: if (defined($in{'mode'})) {
3521: if ($in{'mode'} eq 'modifyuser') {
3522: $krbcheck = '';
3523: }
3524: }
1.591 raeburn 3525: if (defined($in{'curr_kerb_ver'})) {
3526: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3527: $check5 = ' checked="checked"';
1.591 raeburn 3528: $check4 = '';
3529: } else {
1.772 bisitz 3530: $check4 = ' checked="checked"';
1.591 raeburn 3531: $check5 = '';
3532: }
1.586 raeburn 3533: }
1.591 raeburn 3534: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3535: $krbarg = $in{'curr_autharg'};
3536: }
1.586 raeburn 3537: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3538: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3539: $result =
3540: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3541: $in{'curr_autharg'},$krbver);
3542: } else {
3543: $result =
3544: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3545: }
3546: return $result;
3547: }
3548: }
3549: } else {
3550: if ($authnum == 1) {
1.784 bisitz 3551: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3552: }
3553: }
1.586 raeburn 3554: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3555: return;
1.587 raeburn 3556: } elsif ($authtype eq '') {
1.591 raeburn 3557: if (defined($in{'mode'})) {
1.587 raeburn 3558: if ($in{'mode'} eq 'modifycourse') {
3559: if ($authnum == 1) {
1.1259 raeburn 3560: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3561: }
3562: }
3563: }
1.586 raeburn 3564: }
3565: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3566: if ($authtype eq '') {
3567: $authtype = '<input type="radio" name="login" value="krb" '.
3568: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3569: $krbcheck.$disabled.' />';
1.586 raeburn 3570: }
3571: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3572: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3573: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3574: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3575: $in{'curr_authtype'} eq 'krb4')) {
3576: $result .= &mt
1.144 matthew 3577: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3578: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3579: '<label>'.$authtype,
1.281 albertel 3580: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3581: 'value="'.$krbarg.'" '.
1.1259 raeburn 3582: 'onchange="'.$jscall.'"'.$disabled.' />',
3583: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3584: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3585: '</label>');
1.586 raeburn 3586: } elsif ($can_assign{'krb4'}) {
3587: $result .= &mt
3588: ('[_1] Kerberos authenticated with domain [_2] '.
3589: '[_3] Version 4 [_4]',
3590: '<label>'.$authtype,
3591: '</label><input type="text" size="10" name="krbarg" '.
3592: 'value="'.$krbarg.'" '.
1.1259 raeburn 3593: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3594: '<label><input type="hidden" name="krbver" value="4" />',
3595: '</label>');
3596: } elsif ($can_assign{'krb5'}) {
3597: $result .= &mt
3598: ('[_1] Kerberos authenticated with domain [_2] '.
3599: '[_3] Version 5 [_4]',
3600: '<label>'.$authtype,
3601: '</label><input type="text" size="10" name="krbarg" '.
3602: 'value="'.$krbarg.'" '.
1.1259 raeburn 3603: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3604: '<label><input type="hidden" name="krbver" value="5" />',
3605: '</label>');
3606: }
1.32 matthew 3607: return $result;
3608: }
3609:
1.1106 raeburn 3610: sub authform_internal {
1.586 raeburn 3611: my %in = (
1.32 matthew 3612: formname => 'document.cu',
3613: kerb_def_dom => 'MSU.EDU',
3614: @_,
3615: );
1.1259 raeburn 3616: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3617: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3618: if ($in{'readonly'}) {
3619: $disabled = ' disabled="disabled"';
3620: }
1.591 raeburn 3621: if (defined($in{'curr_authtype'})) {
3622: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3623: if ($can_assign{'int'}) {
1.772 bisitz 3624: $intcheck = 'checked="checked" ';
1.623 raeburn 3625: if (defined($in{'mode'})) {
3626: if ($in{'mode'} eq 'modifyuser') {
3627: $intcheck = '';
3628: }
3629: }
1.591 raeburn 3630: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3631: $intarg = $in{'curr_autharg'};
3632: }
3633: } else {
3634: $result = &mt('Currently internally authenticated.');
3635: return $result;
1.165 raeburn 3636: }
3637: }
1.586 raeburn 3638: } else {
3639: if ($authnum == 1) {
1.784 bisitz 3640: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3641: }
3642: }
3643: if (!$can_assign{'int'}) {
3644: return;
1.587 raeburn 3645: } elsif ($authtype eq '') {
1.591 raeburn 3646: if (defined($in{'mode'})) {
1.587 raeburn 3647: if ($in{'mode'} eq 'modifycourse') {
3648: if ($authnum == 1) {
1.1259 raeburn 3649: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3650: }
3651: }
3652: }
1.165 raeburn 3653: }
1.586 raeburn 3654: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3655: if ($authtype eq '') {
3656: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3657: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3658: }
1.605 bisitz 3659: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3660: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3661: $result = &mt
1.144 matthew 3662: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3663: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3664: $result.='<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>';
1.32 matthew 3665: return $result;
3666: }
3667:
1.1104 raeburn 3668: sub authform_local {
1.32 matthew 3669: my %in = (
3670: formname => 'document.cu',
3671: kerb_def_dom => 'MSU.EDU',
3672: @_,
3673: );
1.1259 raeburn 3674: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3675: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3676: if ($in{'readonly'}) {
3677: $disabled = ' disabled="disabled"';
3678: }
1.591 raeburn 3679: if (defined($in{'curr_authtype'})) {
3680: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3681: if ($can_assign{'loc'}) {
1.772 bisitz 3682: $loccheck = 'checked="checked" ';
1.623 raeburn 3683: if (defined($in{'mode'})) {
3684: if ($in{'mode'} eq 'modifyuser') {
3685: $loccheck = '';
3686: }
3687: }
1.591 raeburn 3688: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3689: $locarg = $in{'curr_autharg'};
3690: }
3691: } else {
3692: $result = &mt('Currently using local (institutional) authentication.');
3693: return $result;
1.165 raeburn 3694: }
3695: }
1.586 raeburn 3696: } else {
3697: if ($authnum == 1) {
1.784 bisitz 3698: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3699: }
3700: }
3701: if (!$can_assign{'loc'}) {
3702: return;
1.587 raeburn 3703: } elsif ($authtype eq '') {
1.591 raeburn 3704: if (defined($in{'mode'})) {
1.587 raeburn 3705: if ($in{'mode'} eq 'modifycourse') {
3706: if ($authnum == 1) {
1.1259 raeburn 3707: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3708: }
3709: }
3710: }
1.165 raeburn 3711: }
1.586 raeburn 3712: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3713: if ($authtype eq '') {
3714: $authtype = '<input type="radio" name="login" value="loc" '.
3715: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3716: $jscall.'"'.$disabled.' />';
1.586 raeburn 3717: }
3718: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3719: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3720: $result = &mt('[_1] Local Authentication with argument [_2]',
3721: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3722: return $result;
3723: }
3724:
1.1106 raeburn 3725: sub authform_filesystem {
1.32 matthew 3726: my %in = (
3727: formname => 'document.cu',
3728: kerb_def_dom => 'MSU.EDU',
3729: @_,
3730: );
1.1259 raeburn 3731: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3732: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3733: if ($in{'readonly'}) {
3734: $disabled = ' disabled="disabled"';
3735: }
1.591 raeburn 3736: if (defined($in{'curr_authtype'})) {
3737: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3738: if ($can_assign{'fsys'}) {
1.772 bisitz 3739: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3740: if (defined($in{'mode'})) {
3741: if ($in{'mode'} eq 'modifyuser') {
3742: $fsyscheck = '';
3743: }
3744: }
1.586 raeburn 3745: } else {
3746: $result = &mt('Currently Filesystem Authenticated.');
3747: return $result;
1.1259 raeburn 3748: }
1.586 raeburn 3749: }
3750: } else {
3751: if ($authnum == 1) {
1.784 bisitz 3752: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3753: }
3754: }
3755: if (!$can_assign{'fsys'}) {
3756: return;
1.587 raeburn 3757: } elsif ($authtype eq '') {
1.591 raeburn 3758: if (defined($in{'mode'})) {
1.587 raeburn 3759: if ($in{'mode'} eq 'modifycourse') {
3760: if ($authnum == 1) {
1.1259 raeburn 3761: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3762: }
3763: }
3764: }
1.586 raeburn 3765: }
3766: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3767: if ($authtype eq '') {
3768: $authtype = '<input type="radio" name="login" value="fsys" '.
3769: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3770: $jscall.'"'.$disabled.' />';
1.586 raeburn 3771: }
1.1310 raeburn 3772: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3773: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3774: $result = &mt
1.144 matthew 3775: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3776: '<label>'.$authtype,'</label>'.$autharg);
3777: return $result;
3778: }
3779:
3780: sub authform_lti {
3781: my %in = (
3782: formname => 'document.cu',
3783: kerb_def_dom => 'MSU.EDU',
3784: @_,
3785: );
3786: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3787: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3788: if ($in{'readonly'}) {
3789: $disabled = ' disabled="disabled"';
3790: }
3791: if (defined($in{'curr_authtype'})) {
3792: if ($in{'curr_authtype'} eq 'lti') {
3793: if ($can_assign{'lti'}) {
3794: $lticheck = 'checked="checked" ';
3795: if (defined($in{'mode'})) {
3796: if ($in{'mode'} eq 'modifyuser') {
3797: $lticheck = '';
3798: }
3799: }
3800: } else {
3801: $result = &mt('Currently LTI Authenticated.');
3802: return $result;
3803: }
3804: }
3805: } else {
3806: if ($authnum == 1) {
3807: $authtype = '<input type="hidden" name="login" value="lti" />';
3808: }
3809: }
3810: if (!$can_assign{'lti'}) {
3811: return;
3812: } elsif ($authtype eq '') {
3813: if (defined($in{'mode'})) {
3814: if ($in{'mode'} eq 'modifycourse') {
3815: if ($authnum == 1) {
3816: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3817: }
3818: }
3819: }
3820: }
3821: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3822: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3823: $authtype = '<input type="radio" name="login" value="lti" '.
3824: $lticheck.' onchange="'.$jscall.'" onclick="'.
3825: $jscall.'"'.$disabled.' />';
3826: }
3827: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3828: if ($authtype) {
3829: $result = &mt('[_1] LTI Authenticated',
3830: '<label>'.$authtype.'</label>'.$autharg);
3831: } else {
3832: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3833: $autharg;
3834: }
1.32 matthew 3835: return $result;
3836: }
3837:
1.586 raeburn 3838: sub get_assignable_auth {
3839: my ($dom) = @_;
3840: if ($dom eq '') {
3841: $dom = $env{'request.role.domain'};
3842: }
3843: my %can_assign = (
3844: krb4 => 1,
3845: krb5 => 1,
3846: int => 1,
3847: loc => 1,
1.1310 raeburn 3848: lti => 1,
1.586 raeburn 3849: );
3850: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3851: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3852: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3853: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3854: my $context;
3855: if ($env{'request.role'} =~ /^au/) {
3856: $context = 'author';
1.1259 raeburn 3857: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3858: $context = 'domain';
3859: } elsif ($env{'request.course.id'}) {
3860: $context = 'course';
3861: }
3862: if ($context) {
3863: if (ref($authhash->{$context}) eq 'HASH') {
3864: %can_assign = %{$authhash->{$context}};
3865: }
3866: }
3867: }
3868: }
3869: my $authnum = 0;
3870: foreach my $key (keys(%can_assign)) {
3871: if ($can_assign{$key}) {
3872: $authnum ++;
3873: }
3874: }
3875: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3876: $authnum --;
3877: }
3878: return ($authnum,%can_assign);
3879: }
3880:
1.1331 raeburn 3881: sub check_passwd_rules {
3882: my ($domain,$plainpass) = @_;
3883: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3884: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3885: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3886: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3887: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3888: if ($passwdconf{'min'} > $min) {
3889: $min = $passwdconf{'min'};
3890: }
1.1331 raeburn 3891: }
3892: if ($passwdconf{'max'} =~ /^\d+$/) {
3893: $max = $passwdconf{'max'};
3894: }
3895: @chars = @{$passwdconf{'chars'}};
3896: }
3897: if (($min) && (length($plainpass) < $min)) {
3898: push(@brokerule,'min');
3899: }
3900: if (($max) && (length($plainpass) > $max)) {
3901: push(@brokerule,'max');
3902: }
3903: if (@chars) {
3904: my %rules;
3905: map { $rules{$_} = 1; } @chars;
3906: if ($rules{'uc'}) {
3907: unless ($plainpass =~ /[A-Z]/) {
3908: push(@brokerule,'uc');
3909: }
3910: }
3911: if ($rules{'lc'}) {
1.1332 raeburn 3912: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3913: push(@brokerule,'lc');
3914: }
3915: }
3916: if ($rules{'num'}) {
3917: unless ($plainpass =~ /\d/) {
3918: push(@brokerule,'num');
3919: }
3920: }
3921: if ($rules{'spec'}) {
3922: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3923: push(@brokerule,'spec');
3924: }
3925: }
3926: }
3927: if (@brokerule) {
3928: my %rulenames = &Apache::lonlocal::texthash(
3929: uc => 'At least one upper case letter',
3930: lc => 'At least one lower case letter',
3931: num => 'At least one number',
3932: spec => 'At least one non-alphanumeric',
3933: );
3934: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3935: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3936: $rulenames{'num'} .= ': 0123456789';
3937: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3938: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3939: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3940: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1336 raeburn 3941: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1331 raeburn 3942: if (grep(/^$rule$/,@brokerule)) {
3943: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3944: }
3945: }
3946: $warning .= '</ul>';
3947: }
1.1332 raeburn 3948: if (wantarray) {
3949: return @brokerule;
3950: }
1.1331 raeburn 3951: return $warning;
3952: }
3953:
1.1376 raeburn 3954: sub passwd_validation_js {
1.1377 raeburn 3955: my ($currpasswdval,$domain,$context,$id) = @_;
3956: my (%passwdconf,$alertmsg);
3957: if ($context eq 'linkprot') {
3958: my %domconfig = &Apache::lonnet::get_dom('configuration',['ltisec'],$domain);
3959: if (ref($domconfig{'ltisec'}) eq 'HASH') {
3960: if (ref($domconfig{'ltisec'}{'rules'}) eq 'HASH') {
3961: %passwdconf = %{$domconfig{'ltisec'}{'rules'}};
3962: }
3963: }
3964: if ($id eq 'add') {
3965: $alertmsg = &mt('Secret for added launcher did not satisfy requirement(s):').'\n\n';
3966: } elsif ($id =~ /^\d+$/) {
3967: my $pos = $id+1;
3968: $alertmsg = &mt('Secret for launcher [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3969: } else {
3970: $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3971: }
1.1434 raeburn 3972: } elsif ($context eq 'ltitools') {
3973: my %domconfig = &Apache::lonnet::get_dom('configuration',['toolsec'],$domain);
3974: if (ref($domconfig{'toolsec'}) eq 'HASH') {
3975: if (ref($domconfig{'toolsec'}{'rules'}) eq 'HASH') {
3976: %passwdconf = %{$domconfig{'toolsec'}{'rules'}};
3977: }
3978: }
3979: if ($id eq 'add') {
3980: $alertmsg = &mt('Secret for added external tool did not satisfy requirement(s):').'\n\n';
3981: } elsif ($id =~ /^\d+$/) {
3982: my $pos = $id+1;
3983: $alertmsg = &mt('Secret for external tool [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3984: } else {
3985: $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3986: }
1.1377 raeburn 3987: } else {
3988: %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3989: $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
3990: }
1.1376 raeburn 3991: my ($min,$max,@chars,$numrules,$intargjs,%alert);
3992: $numrules = 0;
3993: $min = $Apache::lonnet::passwdmin;
3994: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3995: if ($passwdconf{'min'} =~ /^\d+$/) {
3996: if ($passwdconf{'min'} > $min) {
3997: $min = $passwdconf{'min'};
3998: }
3999: }
4000: if ($passwdconf{'max'} =~ /^\d+$/) {
4001: $max = $passwdconf{'max'};
4002: $numrules ++;
4003: }
4004: @chars = @{$passwdconf{'chars'}};
4005: if (@chars) {
4006: $numrules ++;
4007: }
4008: }
4009: if ($min > 0) {
4010: $numrules ++;
4011: }
4012: if (($min > 0) || ($max ne '') || (@chars > 0)) {
4013: if ($min) {
4014: $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
4015: }
4016: if ($max) {
4017: $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
4018: }
4019: my (@charalerts,@charrules);
4020: if (@chars) {
4021: if (grep(/^uc$/,@chars)) {
4022: push(@charalerts,&mt('contain at least one upper case letter'));
4023: push(@charrules,'uc');
4024: }
4025: if (grep(/^lc$/,@chars)) {
4026: push(@charalerts,&mt('contain at least one lower case letter'));
4027: push(@charrules,'lc');
4028: }
4029: if (grep(/^num$/,@chars)) {
4030: push(@charalerts,&mt('contain at least one number'));
4031: push(@charrules,'num');
4032: }
4033: if (grep(/^spec$/,@chars)) {
4034: push(@charalerts,&mt('contain at least one non-alphanumeric'));
4035: push(@charrules,'spec');
4036: }
4037: }
4038: $intargjs = qq| var rulesmsg = '';\n|.
4039: qq| var currpwval = $currpasswdval;\n|;
4040: if ($min) {
4041: $intargjs .= qq|
4042: if (currpwval.length < $min) {
4043: rulesmsg += ' - $alert{min}';
4044: }
4045: |;
4046: }
4047: if ($max) {
4048: $intargjs .= qq|
4049: if (currpwval.length > $max) {
4050: rulesmsg += ' - $alert{max}';
4051: }
4052: |;
4053: }
4054: if (@chars > 0) {
4055: my $charrulestr = '"'.join('","',@charrules).'"';
4056: my $charalertstr = '"'.join('","',@charalerts).'"';
4057: $intargjs .= qq| var brokerules = new Array();\n|.
4058: qq| var charrules = new Array($charrulestr);\n|.
4059: qq| var charalerts = new Array($charalertstr);\n|;
4060: my %rules;
4061: map { $rules{$_} = 1; } @chars;
4062: if ($rules{'uc'}) {
4063: $intargjs .= qq|
4064: var ucRegExp = /[A-Z]/;
4065: if (!ucRegExp.test(currpwval)) {
4066: brokerules.push('uc');
4067: }
4068: |;
4069: }
4070: if ($rules{'lc'}) {
4071: $intargjs .= qq|
4072: var lcRegExp = /[a-z]/;
4073: if (!lcRegExp.test(currpwval)) {
4074: brokerules.push('lc');
4075: }
4076: |;
4077: }
4078: if ($rules{'num'}) {
4079: $intargjs .= qq|
4080: var numRegExp = /[0-9]/;
4081: if (!numRegExp.test(currpwval)) {
4082: brokerules.push('num');
4083: }
4084: |;
4085: }
4086: if ($rules{'spec'}) {
4087: $intargjs .= q|
4088: var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
4089: if (!specRegExp.test(currpwval)) {
4090: brokerules.push('spec');
4091: }
4092: |;
4093: }
4094: $intargjs .= qq|
4095: if (brokerules.length > 0) {
4096: for (var i=0; i<brokerules.length; i++) {
4097: for (var j=0; j<charrules.length; j++) {
4098: if (brokerules[i] == charrules[j]) {
4099: rulesmsg += ' - '+charalerts[j]+'\\n';
4100: break;
4101: }
4102: }
4103: }
4104: }
4105: |;
4106: }
4107: $intargjs .= qq|
4108: if (rulesmsg != '') {
4109: rulesmsg = '$alertmsg'+rulesmsg;
4110: alert(rulesmsg);
4111: return false;
4112: }
4113: |;
4114: }
4115: return ($numrules,$intargjs);
4116: }
4117:
1.80 albertel 4118: ###############################################################
4119: ## Get Kerberos Defaults for Domain ##
4120: ###############################################################
4121: ##
4122: ## Returns default kerberos version and an associated argument
4123: ## as listed in file domain.tab. If not listed, provides
4124: ## appropriate default domain and kerberos version.
4125: ##
4126: #-------------------------------------------
4127:
4128: =pod
4129:
1.648 raeburn 4130: =item * &get_kerberos_defaults()
1.80 albertel 4131:
4132: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 4133: version and domain. If not found, it defaults to version 4 and the
4134: domain of the server.
1.80 albertel 4135:
1.648 raeburn 4136: =over 4
4137:
1.80 albertel 4138: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
4139:
1.648 raeburn 4140: =back
4141:
4142: =back
4143:
1.80 albertel 4144: =cut
4145:
4146: #-------------------------------------------
4147: sub get_kerberos_defaults {
4148: my $domain=shift;
1.641 raeburn 4149: my ($krbdef,$krbdefdom);
4150: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
4151: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
4152: $krbdef = $domdefaults{'auth_def'};
4153: $krbdefdom = $domdefaults{'auth_arg_def'};
4154: } else {
1.80 albertel 4155: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
4156: my $krbdefdom=$1;
4157: $krbdefdom=~tr/a-z/A-Z/;
4158: $krbdef = "krb4";
4159: }
4160: return ($krbdef,$krbdefdom);
4161: }
1.112 bowersj2 4162:
1.32 matthew 4163:
1.46 matthew 4164: ###############################################################
4165: ## Thesaurus Functions ##
4166: ###############################################################
1.20 www 4167:
1.46 matthew 4168: =pod
1.20 www 4169:
1.112 bowersj2 4170: =head1 Thesaurus Functions
4171:
4172: =over 4
4173:
1.648 raeburn 4174: =item * &initialize_keywords()
1.46 matthew 4175:
4176: Initializes the package variable %Keywords if it is empty. Uses the
4177: package variable $thesaurus_db_file.
4178:
4179: =cut
4180:
4181: ###################################################
4182:
4183: sub initialize_keywords {
4184: return 1 if (scalar keys(%Keywords));
4185: # If we are here, %Keywords is empty, so fill it up
4186: # Make sure the file we need exists...
4187: if (! -e $thesaurus_db_file) {
4188: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
4189: " failed because it does not exist");
4190: return 0;
4191: }
4192: # Set up the hash as a database
4193: my %thesaurus_db;
4194: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 4195: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 4196: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
4197: $thesaurus_db_file);
4198: return 0;
4199: }
4200: # Get the average number of appearances of a word.
4201: my $avecount = $thesaurus_db{'average.count'};
4202: # Put keywords (those that appear > average) into %Keywords
4203: while (my ($word,$data)=each (%thesaurus_db)) {
4204: my ($count,undef) = split /:/,$data;
4205: $Keywords{$word}++ if ($count > $avecount);
4206: }
4207: untie %thesaurus_db;
4208: # Remove special values from %Keywords.
1.356 albertel 4209: foreach my $value ('total.count','average.count') {
4210: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 4211: }
1.46 matthew 4212: return 1;
4213: }
4214:
4215: ###################################################
4216:
4217: =pod
4218:
1.648 raeburn 4219: =item * &keyword($word)
1.46 matthew 4220:
4221: Returns true if $word is a keyword. A keyword is a word that appears more
4222: than the average number of times in the thesaurus database. Calls
4223: &initialize_keywords
4224:
4225: =cut
4226:
4227: ###################################################
1.20 www 4228:
4229: sub keyword {
1.46 matthew 4230: return if (!&initialize_keywords());
4231: my $word=lc(shift());
4232: $word=~s/\W//g;
4233: return exists($Keywords{$word});
1.20 www 4234: }
1.46 matthew 4235:
4236: ###############################################################
4237:
4238: =pod
1.20 www 4239:
1.648 raeburn 4240: =item * &get_related_words()
1.46 matthew 4241:
1.160 matthew 4242: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 4243: an array of words. If the keyword is not in the thesaurus, an empty array
4244: will be returned. The order of the words returned is determined by the
4245: database which holds them.
4246:
4247: Uses global $thesaurus_db_file.
4248:
1.1057 foxr 4249:
1.46 matthew 4250: =cut
4251:
4252: ###############################################################
4253: sub get_related_words {
4254: my $keyword = shift;
4255: my %thesaurus_db;
4256: if (! -e $thesaurus_db_file) {
4257: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
4258: "failed because the file does not exist");
4259: return ();
4260: }
4261: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 4262: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 4263: return ();
4264: }
4265: my @Words=();
1.429 www 4266: my $count=0;
1.46 matthew 4267: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 4268: # The first element is the number of times
4269: # the word appears. We do not need it now.
1.429 www 4270: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
4271: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
4272: my $threshold=$mostfrequentcount/10;
4273: foreach my $possibleword (@RelatedWords) {
4274: my ($word,$wordcount)=split(/\,/,$possibleword);
4275: if ($wordcount>$threshold) {
4276: push(@Words,$word);
4277: $count++;
4278: if ($count>10) { last; }
4279: }
1.20 www 4280: }
4281: }
1.46 matthew 4282: untie %thesaurus_db;
4283: return @Words;
1.14 harris41 4284: }
1.1090 foxr 4285: ###############################################################
4286: #
4287: # Spell checking
4288: #
4289:
4290: =pod
4291:
1.1142 raeburn 4292: =back
4293:
1.1090 foxr 4294: =head1 Spell checking
4295:
4296: =over 4
4297:
4298: =item * &check_spelling($wordlist $language)
4299:
4300: Takes a string containing words and feeds it to an external
4301: spellcheck program via a pipeline. Returns a string containing
4302: them mis-spelled words.
4303:
4304: Parameters:
4305:
4306: =over 4
4307:
4308: =item - $wordlist
4309:
4310: String that will be fed into the spellcheck program.
4311:
4312: =item - $language
4313:
4314: Language string that specifies the language for which the spell
4315: check will be performed.
4316:
4317: =back
4318:
4319: =back
4320:
4321: Note: This sub assumes that aspell is installed.
4322:
4323:
4324: =cut
4325:
1.46 matthew 4326:
1.1090 foxr 4327: sub check_spelling {
4328: my ($wordlist, $language) = @_;
1.1091 foxr 4329: my @misspellings;
4330:
4331: # Generate the speller and set the langauge.
4332: # if explicitly selected:
1.1090 foxr 4333:
1.1091 foxr 4334: my $speller = Text::Aspell->new;
1.1090 foxr 4335: if ($language) {
1.1091 foxr 4336: $speller->set_option('lang', $language);
1.1090 foxr 4337: }
4338:
1.1091 foxr 4339: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 4340:
1.1091 foxr 4341: my @words = split(/\s+/, $wordlist);
1.1090 foxr 4342:
1.1091 foxr 4343: foreach my $word (@words) {
4344: if(! $speller->check($word)) {
4345: push(@misspellings, $word);
1.1090 foxr 4346: }
4347: }
1.1091 foxr 4348: return join(' ', @misspellings);
4349:
1.1090 foxr 4350: }
4351:
1.61 www 4352: # -------------------------------------------------------------- Plaintext name
1.81 albertel 4353: =pod
4354:
1.112 bowersj2 4355: =head1 User Name Functions
4356:
4357: =over 4
4358:
1.648 raeburn 4359: =item * &plainname($uname,$udom,$first)
1.81 albertel 4360:
1.112 bowersj2 4361: Takes a users logon name and returns it as a string in
1.226 albertel 4362: "first middle last generation" form
4363: if $first is set to 'lastname' then it returns it as
4364: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 4365:
4366: =cut
1.61 www 4367:
1.295 www 4368:
1.81 albertel 4369: ###############################################################
1.61 www 4370: sub plainname {
1.226 albertel 4371: my ($uname,$udom,$first)=@_;
1.537 albertel 4372: return if (!defined($uname) || !defined($udom));
1.295 www 4373: my %names=&getnames($uname,$udom);
1.226 albertel 4374: my $name=&Apache::lonnet::format_name($names{'firstname'},
4375: $names{'middlename'},
4376: $names{'lastname'},
4377: $names{'generation'},$first);
4378: $name=~s/^\s+//;
1.62 www 4379: $name=~s/\s+$//;
4380: $name=~s/\s+/ /g;
1.353 albertel 4381: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 4382: return $name;
1.61 www 4383: }
1.66 www 4384:
4385: # -------------------------------------------------------------------- Nickname
1.81 albertel 4386: =pod
4387:
1.648 raeburn 4388: =item * &nickname($uname,$udom)
1.81 albertel 4389:
4390: Gets a users name and returns it as a string as
4391:
4392: ""nickname""
1.66 www 4393:
1.81 albertel 4394: if the user has a nickname or
4395:
4396: "first middle last generation"
4397:
4398: if the user does not
4399:
4400: =cut
1.66 www 4401:
4402: sub nickname {
4403: my ($uname,$udom)=@_;
1.537 albertel 4404: return if (!defined($uname) || !defined($udom));
1.295 www 4405: my %names=&getnames($uname,$udom);
1.68 albertel 4406: my $name=$names{'nickname'};
1.66 www 4407: if ($name) {
4408: $name='"'.$name.'"';
4409: } else {
4410: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
4411: $names{'lastname'}.' '.$names{'generation'};
4412: $name=~s/\s+$//;
4413: $name=~s/\s+/ /g;
4414: }
4415: return $name;
4416: }
4417:
1.295 www 4418: sub getnames {
4419: my ($uname,$udom)=@_;
1.537 albertel 4420: return if (!defined($uname) || !defined($udom));
1.433 albertel 4421: if ($udom eq 'public' && $uname eq 'public') {
4422: return ('lastname' => &mt('Public'));
4423: }
1.295 www 4424: my $id=$uname.':'.$udom;
4425: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
4426: if ($cached) {
4427: return %{$names};
4428: } else {
4429: my %loadnames=&Apache::lonnet::get('environment',
4430: ['firstname','middlename','lastname','generation','nickname'],
4431: $udom,$uname);
4432: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
4433: return %loadnames;
4434: }
4435: }
1.61 www 4436:
1.542 raeburn 4437: # -------------------------------------------------------------------- getemails
1.648 raeburn 4438:
1.542 raeburn 4439: =pod
4440:
1.648 raeburn 4441: =item * &getemails($uname,$udom)
1.542 raeburn 4442:
4443: Gets a user's email information and returns it as a hash with keys:
4444: notification, critnotification, permanentemail
4445:
4446: For notification and critnotification, values are comma-separated lists
1.648 raeburn 4447: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 4448:
1.648 raeburn 4449:
1.542 raeburn 4450: =cut
4451:
1.648 raeburn 4452:
1.466 albertel 4453: sub getemails {
4454: my ($uname,$udom)=@_;
4455: if ($udom eq 'public' && $uname eq 'public') {
4456: return;
4457: }
1.467 www 4458: if (!$udom) { $udom=$env{'user.domain'}; }
4459: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 4460: my $id=$uname.':'.$udom;
4461: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
4462: if ($cached) {
4463: return %{$names};
4464: } else {
4465: my %loadnames=&Apache::lonnet::get('environment',
4466: ['notification','critnotification',
4467: 'permanentemail'],
4468: $udom,$uname);
4469: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
4470: return %loadnames;
4471: }
4472: }
4473:
1.551 albertel 4474: sub flush_email_cache {
4475: my ($uname,$udom)=@_;
4476: if (!$udom) { $udom =$env{'user.domain'}; }
4477: if (!$uname) { $uname=$env{'user.name'}; }
4478: return if ($udom eq 'public' && $uname eq 'public');
4479: my $id=$uname.':'.$udom;
4480: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4481: }
4482:
1.728 raeburn 4483: # -------------------------------------------------------------------- getlangs
4484:
4485: =pod
4486:
4487: =item * &getlangs($uname,$udom)
4488:
4489: Gets a user's language preference and returns it as a hash with key:
4490: language.
4491:
4492: =cut
4493:
4494:
4495: sub getlangs {
4496: my ($uname,$udom) = @_;
4497: if (!$udom) { $udom =$env{'user.domain'}; }
4498: if (!$uname) { $uname=$env{'user.name'}; }
4499: my $id=$uname.':'.$udom;
4500: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4501: if ($cached) {
4502: return %{$langs};
4503: } else {
4504: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4505: $udom,$uname);
4506: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4507: return %loadlangs;
4508: }
4509: }
4510:
4511: sub flush_langs_cache {
4512: my ($uname,$udom)=@_;
4513: if (!$udom) { $udom =$env{'user.domain'}; }
4514: if (!$uname) { $uname=$env{'user.name'}; }
4515: return if ($udom eq 'public' && $uname eq 'public');
4516: my $id=$uname.':'.$udom;
4517: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4518: }
4519:
1.61 www 4520: # ------------------------------------------------------------------ Screenname
1.81 albertel 4521:
4522: =pod
4523:
1.648 raeburn 4524: =item * &screenname($uname,$udom)
1.81 albertel 4525:
4526: Gets a users screenname and returns it as a string
4527:
4528: =cut
1.61 www 4529:
4530: sub screenname {
4531: my ($uname,$udom)=@_;
1.258 albertel 4532: if ($uname eq $env{'user.name'} &&
4533: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4534: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4535: return $names{'screenname'};
1.62 www 4536: }
4537:
1.212 albertel 4538:
1.802 bisitz 4539: # ------------------------------------------------------------- Confirm Wrapper
4540: =pod
4541:
1.1142 raeburn 4542: =item * &confirmwrapper($message)
1.802 bisitz 4543:
4544: Wrap messages about completion of operation in box
4545:
4546: =cut
4547:
4548: sub confirmwrapper {
4549: my ($message)=@_;
4550: if ($message) {
4551: return "\n".'<div class="LC_confirm_box">'."\n"
4552: .$message."\n"
4553: .'</div>'."\n";
4554: } else {
4555: return $message;
4556: }
4557: }
4558:
1.62 www 4559: # ------------------------------------------------------------- Message Wrapper
4560:
4561: sub messagewrapper {
1.369 www 4562: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4563: return
1.441 albertel 4564: '<a href="/adm/email?compose=individual&'.
4565: 'recname='.$username.'&recdom='.$domain.
4566: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4567: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4568: }
1.802 bisitz 4569:
1.74 www 4570: # --------------------------------------------------------------- Notes Wrapper
4571:
4572: sub noteswrapper {
4573: my ($link,$un,$do)=@_;
4574: return
1.896 amueller 4575: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4576: }
1.802 bisitz 4577:
1.62 www 4578: # ------------------------------------------------------------- Aboutme Wrapper
4579:
4580: sub aboutmewrapper {
1.1070 raeburn 4581: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4582: if (!defined($username) && !defined($domain)) {
4583: return;
4584: }
1.1096 raeburn 4585: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4586: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4587: }
4588:
4589: # ------------------------------------------------------------ Syllabus Wrapper
4590:
4591: sub syllabuswrapper {
1.707 bisitz 4592: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4593: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4594: }
1.14 harris41 4595:
1.1397 raeburn 4596: # -----------------------------------------------------------------------------
4597:
1.1396 raeburn 4598: sub aboutme_on {
4599: my ($uname,$udom)=@_;
4600: unless ($uname) { $uname=$env{'user.name'}; }
4601: unless ($udom) { $udom=$env{'user.domain'}; }
4602: return if ($udom eq 'public' && $uname eq 'public');
4603: my $hashkey=$uname.':'.$udom;
4604: my ($aboutme,$cached)=&Apache::lonnet::is_cached_new('aboutme',$hashkey);
4605: if ($cached) {
4606: return $aboutme;
4607: }
4608: $aboutme = &Apache::lonnet::usertools_access($uname,$udom,'aboutme');
4609: &Apache::lonnet::do_cache_new('aboutme',$hashkey,$aboutme,3600);
4610: return $aboutme;
4611: }
4612:
4613: sub devalidate_aboutme_cache {
4614: my ($uname,$udom)=@_;
4615: if (!$udom) { $udom =$env{'user.domain'}; }
4616: if (!$uname) { $uname=$env{'user.name'}; }
4617: return if ($udom eq 'public' && $uname eq 'public');
4618: my $id=$uname.':'.$udom;
4619: &Apache::lonnet::devalidate_cache_new('aboutme',$id);
4620: }
4621:
1.208 matthew 4622: sub track_student_link {
1.887 raeburn 4623: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4624: my $link ="/adm/trackstudent?";
1.208 matthew 4625: my $title = 'View recent activity';
4626: if (defined($sname) && $sname !~ /^\s*$/ &&
4627: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4628: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4629: $title .= ' of this student';
1.268 albertel 4630: }
1.208 matthew 4631: if (defined($target) && $target !~ /^\s*$/) {
4632: $target = qq{target="$target"};
4633: } else {
4634: $target = '';
4635: }
1.268 albertel 4636: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4637: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4638: $title = &mt($title);
4639: $linktext = &mt($linktext);
1.448 albertel 4640: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4641: &help_open_topic('View_recent_activity');
1.208 matthew 4642: }
4643:
1.781 raeburn 4644: sub slot_reservations_link {
4645: my ($linktext,$sname,$sdom,$target) = @_;
4646: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4647: my $title = 'View slot reservation history';
4648: if (defined($sname) && $sname !~ /^\s*$/ &&
4649: defined($sdom) && $sdom !~ /^\s*$/) {
4650: $link .= "&uname=$sname&udom=$sdom";
4651: $title .= ' of this student';
4652: }
4653: if (defined($target) && $target !~ /^\s*$/) {
4654: $target = qq{target="$target"};
4655: } else {
4656: $target = '';
4657: }
4658: $title = &mt($title);
4659: $linktext = &mt($linktext);
4660: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4661: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4662:
4663: }
4664:
1.508 www 4665: # ===================================================== Display a student photo
4666:
4667:
1.509 albertel 4668: sub student_image_tag {
1.508 www 4669: my ($domain,$user)=@_;
4670: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4671: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4672: return '<img src="'.$imgsrc.'" align="right" />';
4673: } else {
4674: return '';
4675: }
4676: }
4677:
1.112 bowersj2 4678: =pod
4679:
4680: =back
4681:
4682: =head1 Access .tab File Data
4683:
4684: =over 4
4685:
1.648 raeburn 4686: =item * &languageids()
1.112 bowersj2 4687:
4688: returns list of all language ids
4689:
4690: =cut
4691:
1.14 harris41 4692: sub languageids {
1.16 harris41 4693: return sort(keys(%language));
1.14 harris41 4694: }
4695:
1.112 bowersj2 4696: =pod
4697:
1.648 raeburn 4698: =item * &languagedescription()
1.112 bowersj2 4699:
4700: returns description of a specified language id
4701:
4702: =cut
4703:
1.14 harris41 4704: sub languagedescription {
1.125 www 4705: my $code=shift;
4706: return ($supported_language{$code}?'* ':'').
4707: $language{$code}.
1.126 www 4708: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4709: }
4710:
1.1048 foxr 4711: =pod
4712:
4713: =item * &plainlanguagedescription
4714:
4715: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4716: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4717:
4718: =cut
4719:
1.145 www 4720: sub plainlanguagedescription {
4721: my $code=shift;
4722: return $language{$code};
4723: }
4724:
1.1048 foxr 4725: =pod
4726:
4727: =item * &supportedlanguagecode
4728:
4729: Returns the supported language code (e.g. sptutf maps to pt) given a language
4730: code.
4731:
4732: =cut
4733:
1.145 www 4734: sub supportedlanguagecode {
4735: my $code=shift;
4736: return $supported_language{$code};
1.97 www 4737: }
4738:
1.112 bowersj2 4739: =pod
4740:
1.1048 foxr 4741: =item * &latexlanguage()
4742:
4743: Given a language key code returns the correspondnig language to use
4744: to select the correct hyphenation on LaTeX printouts. This is undef if there
4745: is no supported hyphenation for the language code.
4746:
4747: =cut
4748:
4749: sub latexlanguage {
4750: my $code = shift;
4751: return $latex_language{$code};
4752: }
4753:
4754: =pod
4755:
4756: =item * &latexhyphenation()
4757:
4758: Same as above but what's supplied is the language as it might be stored
4759: in the metadata.
4760:
4761: =cut
4762:
4763: sub latexhyphenation {
4764: my $key = shift;
4765: return $latex_language_bykey{$key};
4766: }
4767:
4768: =pod
4769:
1.648 raeburn 4770: =item * ©rightids()
1.112 bowersj2 4771:
4772: returns list of all copyrights
4773:
4774: =cut
4775:
4776: sub copyrightids {
4777: return sort(keys(%cprtag));
4778: }
4779:
4780: =pod
4781:
1.648 raeburn 4782: =item * ©rightdescription()
1.112 bowersj2 4783:
4784: returns description of a specified copyright id
4785:
4786: =cut
4787:
4788: sub copyrightdescription {
1.166 www 4789: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4790: }
1.197 matthew 4791:
4792: =pod
4793:
1.648 raeburn 4794: =item * &source_copyrightids()
1.192 taceyjo1 4795:
4796: returns list of all source copyrights
4797:
4798: =cut
4799:
4800: sub source_copyrightids {
4801: return sort(keys(%scprtag));
4802: }
4803:
4804: =pod
4805:
1.648 raeburn 4806: =item * &source_copyrightdescription()
1.192 taceyjo1 4807:
4808: returns description of a specified source copyright id
4809:
4810: =cut
4811:
4812: sub source_copyrightdescription {
4813: return &mt($scprtag{shift(@_)});
4814: }
1.112 bowersj2 4815:
4816: =pod
4817:
1.648 raeburn 4818: =item * &filecategories()
1.112 bowersj2 4819:
4820: returns list of all file categories
4821:
4822: =cut
4823:
4824: sub filecategories {
4825: return sort(keys(%category_extensions));
4826: }
4827:
4828: =pod
4829:
1.648 raeburn 4830: =item * &filecategorytypes()
1.112 bowersj2 4831:
4832: returns list of file types belonging to a given file
4833: category
4834:
4835: =cut
4836:
4837: sub filecategorytypes {
1.356 albertel 4838: my ($cat) = @_;
1.1248 raeburn 4839: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4840: return @{$category_extensions{lc($cat)}};
4841: } else {
4842: return ();
4843: }
1.112 bowersj2 4844: }
4845:
4846: =pod
4847:
1.648 raeburn 4848: =item * &fileembstyle()
1.112 bowersj2 4849:
4850: returns embedding style for a specified file type
4851:
4852: =cut
4853:
4854: sub fileembstyle {
4855: return $fe{lc(shift(@_))};
1.169 www 4856: }
4857:
1.351 www 4858: sub filemimetype {
4859: return $fm{lc(shift(@_))};
4860: }
4861:
1.169 www 4862:
4863: sub filecategoryselect {
4864: my ($name,$value)=@_;
1.189 matthew 4865: return &select_form($value,$name,
1.970 raeburn 4866: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4867: }
4868:
4869: =pod
4870:
1.648 raeburn 4871: =item * &filedescription()
1.112 bowersj2 4872:
4873: returns description for a specified file type
4874:
4875: =cut
4876:
4877: sub filedescription {
1.188 matthew 4878: my $file_description = $fd{lc(shift())};
4879: $file_description =~ s:([\[\]]):~$1:g;
4880: return &mt($file_description);
1.112 bowersj2 4881: }
4882:
4883: =pod
4884:
1.648 raeburn 4885: =item * &filedescriptionex()
1.112 bowersj2 4886:
4887: returns description for a specified file type with
4888: extra formatting
4889:
4890: =cut
4891:
4892: sub filedescriptionex {
4893: my $ex=shift;
1.188 matthew 4894: my $file_description = $fd{lc($ex)};
4895: $file_description =~ s:([\[\]]):~$1:g;
4896: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4897: }
4898:
4899: # End of .tab access
4900: =pod
4901:
4902: =back
4903:
4904: =cut
4905:
4906: # ------------------------------------------------------------------ File Types
4907: sub fileextensions {
4908: return sort(keys(%fe));
4909: }
4910:
1.97 www 4911: # ----------------------------------------------------------- Display Languages
4912: # returns a hash with all desired display languages
4913: #
4914:
4915: sub display_languages {
4916: my %languages=();
1.695 raeburn 4917: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4918: $languages{$lang}=1;
1.97 www 4919: }
4920: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4921: if ($env{'form.displaylanguage'}) {
1.356 albertel 4922: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4923: $languages{$lang}=1;
1.97 www 4924: }
4925: }
4926: return %languages;
1.14 harris41 4927: }
4928:
1.582 albertel 4929: sub languages {
4930: my ($possible_langs) = @_;
1.695 raeburn 4931: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4932: if (!ref($possible_langs)) {
4933: if( wantarray ) {
4934: return @preferred_langs;
4935: } else {
4936: return $preferred_langs[0];
4937: }
4938: }
4939: my %possibilities = map { $_ => 1 } (@$possible_langs);
4940: my @preferred_possibilities;
4941: foreach my $preferred_lang (@preferred_langs) {
4942: if (exists($possibilities{$preferred_lang})) {
4943: push(@preferred_possibilities, $preferred_lang);
4944: }
4945: }
4946: if( wantarray ) {
4947: return @preferred_possibilities;
4948: }
4949: return $preferred_possibilities[0];
4950: }
4951:
1.742 raeburn 4952: sub user_lang {
4953: my ($touname,$toudom,$fromcid) = @_;
4954: my @userlangs;
4955: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4956: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4957: $env{'course.'.$fromcid.'.languages'}));
4958: } else {
4959: my %langhash = &getlangs($touname,$toudom);
4960: if ($langhash{'languages'} ne '') {
4961: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4962: } else {
4963: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4964: if ($domdefs{'lang_def'} ne '') {
4965: @userlangs = ($domdefs{'lang_def'});
4966: }
4967: }
4968: }
4969: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4970: my $user_lh = Apache::localize->get_handle(@languages);
4971: return $user_lh;
4972: }
4973:
4974:
1.112 bowersj2 4975: ###############################################################
4976: ## Student Answer Attempts ##
4977: ###############################################################
4978:
4979: =pod
4980:
4981: =head1 Alternate Problem Views
4982:
4983: =over 4
4984:
1.648 raeburn 4985: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4986: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4987:
4988: Return string with previous attempt on problem. Arguments:
4989:
4990: =over 4
4991:
4992: =item * $symb: Problem, including path
4993:
4994: =item * $username: username of the desired student
4995:
4996: =item * $domain: domain of the desired student
1.14 harris41 4997:
1.112 bowersj2 4998: =item * $course: Course ID
1.14 harris41 4999:
1.112 bowersj2 5000: =item * $getattempt: Leave blank for all attempts, otherwise put
5001: something
1.14 harris41 5002:
1.112 bowersj2 5003: =item * $regexp: if string matches this regexp, the string will be
5004: sent to $gradesub
1.14 harris41 5005:
1.112 bowersj2 5006: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 5007:
1.1199 raeburn 5008: =item * $usec: section of the desired student
5009:
5010: =item * $identifier: counter for student (multiple students one problem) or
5011: problem (one student; whole sequence).
5012:
1.112 bowersj2 5013: =back
1.14 harris41 5014:
1.112 bowersj2 5015: The output string is a table containing all desired attempts, if any.
1.16 harris41 5016:
1.112 bowersj2 5017: =cut
1.1 albertel 5018:
5019: sub get_previous_attempt {
1.1199 raeburn 5020: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 5021: my $prevattempts='';
1.43 ng 5022: no strict 'refs';
1.1 albertel 5023: if ($symb) {
1.3 albertel 5024: my (%returnhash)=
5025: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 5026: if ($returnhash{'version'}) {
5027: my %lasthash=();
5028: my $version;
5029: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 5030: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
5031: if ($key =~ /\.rawrndseed$/) {
5032: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
5033: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
5034: } else {
5035: $lasthash{$key}=$returnhash{$version.':'.$key};
5036: }
1.19 harris41 5037: }
1.1 albertel 5038: }
1.596 albertel 5039: $prevattempts=&start_data_table().&start_data_table_header_row();
5040: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 5041: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 5042: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 5043: foreach my $key (sort(keys(%lasthash))) {
5044: my ($ign,@parts) = split(/\./,$key);
1.41 ng 5045: if ($#parts > 0) {
1.31 albertel 5046: my $data=$parts[-1];
1.989 raeburn 5047: next if ($data eq 'foilorder');
1.31 albertel 5048: pop(@parts);
1.1010 www 5049: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 5050: if ($data eq 'type') {
5051: unless ($showsurv) {
5052: my $id = join(',',@parts);
5053: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 5054: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
5055: $lasthidden{$ign.'.'.$id} = 1;
5056: }
1.945 raeburn 5057: }
1.1199 raeburn 5058: if ($identifier ne '') {
5059: my $id = join(',',@parts);
5060: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
5061: $domain,$username,$usec,undef,$course) =~ /^no/) {
5062: $hidestatus{$ign.'.'.$id} = 1;
5063: }
5064: }
5065: } elsif ($data eq 'regrader') {
5066: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 5067: my $id = join(',',@parts);
5068: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 5069: }
1.1010 www 5070: }
1.31 albertel 5071: } else {
1.41 ng 5072: if ($#parts == 0) {
5073: $prevattempts.='<th>'.$parts[0].'</th>';
5074: } else {
5075: $prevattempts.='<th>'.$ign.'</th>';
5076: }
1.31 albertel 5077: }
1.16 harris41 5078: }
1.596 albertel 5079: $prevattempts.=&end_data_table_header_row();
1.40 ng 5080: if ($getattempt eq '') {
1.1199 raeburn 5081: my (%solved,%resets,%probstatus);
1.1200 raeburn 5082: if (($identifier ne '') && (keys(%regraded) > 0)) {
5083: for ($version=1;$version<=$returnhash{'version'};$version++) {
5084: foreach my $id (keys(%regraded)) {
5085: if (($returnhash{$version.':'.$id.'.regrader'}) &&
5086: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
5087: ($returnhash{$version.':'.$id.'.award'} eq '')) {
5088: push(@{$resets{$id}},$version);
1.1199 raeburn 5089: }
5090: }
5091: }
1.1200 raeburn 5092: }
5093: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 5094: my (@hidden,@unsolved);
1.945 raeburn 5095: if (%typeparts) {
5096: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 5097: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
5098: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 5099: push(@hidden,$id);
1.1199 raeburn 5100: } elsif ($identifier ne '') {
5101: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
5102: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
5103: ($hidestatus{$id})) {
1.1200 raeburn 5104: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 5105: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
5106: push(@{$solved{$id}},$version);
5107: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
5108: (ref($solved{$id}) eq 'ARRAY')) {
5109: my $skip;
5110: if (ref($resets{$id}) eq 'ARRAY') {
5111: foreach my $reset (@{$resets{$id}}) {
5112: if ($reset > $solved{$id}[-1]) {
5113: $skip=1;
5114: last;
5115: }
5116: }
5117: }
5118: unless ($skip) {
5119: my ($ign,$partslist) = split(/\./,$id,2);
5120: push(@unsolved,$partslist);
5121: }
5122: }
5123: }
1.945 raeburn 5124: }
5125: }
5126: }
5127: $prevattempts.=&start_data_table_row().
1.1199 raeburn 5128: '<td>'.&mt('Transaction [_1]',$version);
5129: if (@unsolved) {
5130: $prevattempts .= '<span class="LC_nobreak"><label>'.
5131: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
5132: &mt('Hide').'</label></span>';
5133: }
5134: $prevattempts .= '</td>';
1.945 raeburn 5135: if (@hidden) {
5136: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 5137: next if ($key =~ /\.foilorder$/);
1.945 raeburn 5138: my $hide;
5139: foreach my $id (@hidden) {
5140: if ($key =~ /^\Q$id\E/) {
5141: $hide = 1;
5142: last;
5143: }
5144: }
5145: if ($hide) {
5146: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
5147: if (($data eq 'award') || ($data eq 'awarddetail')) {
5148: my $value = &format_previous_attempt_value($key,
5149: $returnhash{$version.':'.$key});
1.1173 kruse 5150: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5151: } else {
5152: $prevattempts.='<td> </td>';
5153: }
5154: } else {
5155: if ($key =~ /\./) {
1.1212 raeburn 5156: my $value = $returnhash{$version.':'.$key};
5157: if ($key =~ /\.rndseed$/) {
5158: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
5159: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
5160: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
5161: }
5162: }
5163: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
5164: ' </td>';
1.945 raeburn 5165: } else {
5166: $prevattempts.='<td> </td>';
5167: }
5168: }
5169: }
5170: } else {
5171: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 5172: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 5173: my $value = $returnhash{$version.':'.$key};
5174: if ($key =~ /\.rndseed$/) {
5175: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
5176: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
5177: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
5178: }
5179: }
5180: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
5181: ' </td>';
1.945 raeburn 5182: }
5183: }
5184: $prevattempts.=&end_data_table_row();
1.40 ng 5185: }
1.1 albertel 5186: }
1.945 raeburn 5187: my @currhidden = keys(%lasthidden);
1.596 albertel 5188: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 5189: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 5190: next if ($key =~ /\.foilorder$/);
1.945 raeburn 5191: if (%typeparts) {
5192: my $hidden;
5193: foreach my $id (@currhidden) {
5194: if ($key =~ /^\Q$id\E/) {
5195: $hidden = 1;
5196: last;
5197: }
5198: }
5199: if ($hidden) {
5200: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
5201: if (($data eq 'award') || ($data eq 'awarddetail')) {
5202: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5203: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5204: $value = &$gradesub($value);
5205: }
1.1173 kruse 5206: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 5207: } else {
5208: $prevattempts.='<td> </td>';
5209: }
5210: } else {
5211: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5212: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5213: $value = &$gradesub($value);
5214: }
1.1173 kruse 5215: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5216: }
5217: } else {
5218: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5219: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5220: $value = &$gradesub($value);
5221: }
1.1173 kruse 5222: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5223: }
1.16 harris41 5224: }
1.596 albertel 5225: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 5226: } else {
1.1305 raeburn 5227: my $msg;
5228: if ($symb =~ /ext\.tool$/) {
5229: $msg = &mt('No grade passed back.');
5230: } else {
5231: $msg = &mt('Nothing submitted - no attempts.');
5232: }
1.596 albertel 5233: $prevattempts=
5234: &start_data_table().&start_data_table_row().
1.1305 raeburn 5235: '<td>'.$msg.'</td>'.
1.596 albertel 5236: &end_data_table_row().&end_data_table();
1.1 albertel 5237: }
5238: } else {
1.596 albertel 5239: $prevattempts=
5240: &start_data_table().&start_data_table_row().
5241: '<td>'.&mt('No data.').'</td>'.
5242: &end_data_table_row().&end_data_table();
1.1 albertel 5243: }
1.10 albertel 5244: }
5245:
1.581 albertel 5246: sub format_previous_attempt_value {
5247: my ($key,$value) = @_;
1.1011 www 5248: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 5249: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 5250: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 5251: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 5252: } elsif ($key =~ /answerstring$/) {
5253: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 5254: my @answer = %answers;
5255: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 5256: my @anskeys = sort(keys(%answers));
5257: if (@anskeys == 1) {
5258: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 5259: if ($answer =~ m{\0}) {
5260: $answer =~ s{\0}{,}g;
1.988 raeburn 5261: }
5262: my $tag_internal_answer_name = 'INTERNAL';
5263: if ($anskeys[0] eq $tag_internal_answer_name) {
5264: $value = $answer;
5265: } else {
5266: $value = $anskeys[0].'='.$answer;
5267: }
5268: } else {
5269: foreach my $ans (@anskeys) {
5270: my $answer = $answers{$ans};
1.1001 raeburn 5271: if ($answer =~ m{\0}) {
5272: $answer =~ s{\0}{,}g;
1.988 raeburn 5273: }
5274: $value .= $ans.'='.$answer.'<br />';;
5275: }
5276: }
1.581 albertel 5277: } else {
1.1173 kruse 5278: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 5279: }
5280: return $value;
5281: }
5282:
5283:
1.107 albertel 5284: sub relative_to_absolute {
5285: my ($url,$output)=@_;
5286: my $parser=HTML::TokeParser->new(\$output);
5287: my $token;
5288: my $thisdir=$url;
5289: my @rlinks=();
5290: while ($token=$parser->get_token) {
5291: if ($token->[0] eq 'S') {
5292: if ($token->[1] eq 'a') {
5293: if ($token->[2]->{'href'}) {
5294: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
5295: }
5296: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
5297: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
5298: } elsif ($token->[1] eq 'base') {
5299: $thisdir=$token->[2]->{'href'};
5300: }
5301: }
5302: }
5303: $thisdir=~s-/[^/]*$--;
1.356 albertel 5304: foreach my $link (@rlinks) {
1.726 raeburn 5305: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 5306: ($link=~/^\//) ||
5307: ($link=~/^javascript:/i) ||
5308: ($link=~/^mailto:/i) ||
5309: ($link=~/^\#/)) {
5310: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
5311: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 5312: }
5313: }
5314: # -------------------------------------------------- Deal with Applet codebases
5315: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
5316: return $output;
5317: }
5318:
1.112 bowersj2 5319: =pod
5320:
1.648 raeburn 5321: =item * &get_student_view()
1.112 bowersj2 5322:
5323: show a snapshot of what student was looking at
5324:
5325: =cut
5326:
1.10 albertel 5327: sub get_student_view {
1.186 albertel 5328: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 5329: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5330: my (%form);
1.10 albertel 5331: my @elements=('symb','courseid','domain','username');
5332: foreach my $element (@elements) {
1.186 albertel 5333: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5334: }
1.186 albertel 5335: if (defined($moreenv)) {
5336: %form=(%form,%{$moreenv});
5337: }
1.236 albertel 5338: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 5339: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 5340: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
5341: $feedurl =~ s{^/adm/wrapper}{};
5342: }
1.650 www 5343: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 5344: $userview=~s/\<body[^\>]*\>//gi;
5345: $userview=~s/\<\/body\>//gi;
5346: $userview=~s/\<html\>//gi;
5347: $userview=~s/\<\/html\>//gi;
5348: $userview=~s/\<head\>//gi;
5349: $userview=~s/\<\/head\>//gi;
1.1460 raeburn 5350: $userview=~s/\Q<div class="LC_landmark" role="main"\E/<div class="LC_landmark"/;
1.11 albertel 5351: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 5352: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 5353: if (wantarray) {
5354: return ($userview,$response);
5355: } else {
5356: return $userview;
5357: }
5358: }
5359:
5360: sub get_student_view_with_retries {
5361: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
5362:
5363: my $ok = 0; # True if we got a good response.
5364: my $content;
5365: my $response;
5366:
5367: # Try to get the student_view done. within the retries count:
5368:
5369: do {
5370: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
5371: $ok = $response->is_success;
5372: if (!$ok) {
5373: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
5374: }
5375: $retries--;
5376: } while (!$ok && ($retries > 0));
5377:
5378: if (!$ok) {
5379: $content = ''; # On error return an empty content.
5380: }
1.651 www 5381: if (wantarray) {
5382: return ($content, $response);
5383: } else {
5384: return $content;
5385: }
1.11 albertel 5386: }
5387:
1.1349 raeburn 5388: sub css_links {
5389: my ($currsymb,$level) = @_;
5390: my ($links,@symbs,%cssrefs,%httpref);
5391: if ($level eq 'map') {
5392: my $navmap = Apache::lonnavmaps::navmap->new();
5393: if (ref($navmap)) {
5394: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
5395: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
5396: foreach my $res (@resources) {
5397: if (ref($res) && $res->symb()) {
5398: push(@symbs,$res->symb());
5399: }
5400: }
5401: }
5402: } else {
5403: @symbs = ($currsymb);
5404: }
5405: foreach my $symb (@symbs) {
5406: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
5407: if ($css_href =~ /\S/) {
5408: unless ($css_href =~ m{https?://}) {
5409: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
5410: my $proburl = &Apache::lonnet::clutter($url);
5411: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
5412: unless ($css_href =~ m{^/}) {
5413: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
5414: }
5415: if ($css_href =~ m{^/(res|uploaded)/}) {
5416: unless (($httpref{'httpref.'.$css_href}) ||
5417: (&Apache::lonnet::is_on_map($css_href))) {
5418: my $thisurl = $proburl;
5419: if ($env{'httpref.'.$proburl}) {
5420: $thisurl = $env{'httpref.'.$proburl};
5421: }
5422: $httpref{'httpref.'.$css_href} = $thisurl;
5423: }
5424: }
5425: }
5426: $cssrefs{$css_href} = 1;
5427: }
5428: }
5429: if (keys(%httpref)) {
5430: &Apache::lonnet::appenv(\%httpref);
5431: }
5432: if (keys(%cssrefs)) {
5433: foreach my $css_href (keys(%cssrefs)) {
5434: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
5435: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
5436: }
5437: }
5438: return $links;
5439: }
5440:
1.112 bowersj2 5441: =pod
5442:
1.648 raeburn 5443: =item * &get_student_answers()
1.112 bowersj2 5444:
5445: show a snapshot of how student was answering problem
5446:
5447: =cut
5448:
1.11 albertel 5449: sub get_student_answers {
1.100 sakharuk 5450: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 5451: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5452: my (%moreenv);
1.11 albertel 5453: my @elements=('symb','courseid','domain','username');
5454: foreach my $element (@elements) {
1.186 albertel 5455: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5456: }
1.186 albertel 5457: $moreenv{'grade_target'}='answer';
5458: %moreenv=(%form,%moreenv);
1.497 raeburn 5459: $feedurl = &Apache::lonnet::clutter($feedurl);
5460: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 5461: return $userview;
1.1 albertel 5462: }
1.116 albertel 5463:
5464: =pod
5465:
5466: =item * &submlink()
5467:
1.242 albertel 5468: Inputs: $text $uname $udom $symb $target
1.116 albertel 5469:
5470: Returns: A link to grades.pm such as to see the SUBM view of a student
5471:
5472: =cut
5473:
5474: ###############################################
5475: sub submlink {
1.242 albertel 5476: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 5477: if (!($uname && $udom)) {
5478: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5479: &Apache::lonnet::whichuser($symb);
1.116 albertel 5480: if (!$symb) { $symb=$cursymb; }
5481: }
1.254 matthew 5482: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5483: $symb=&escape($symb);
1.960 bisitz 5484: if ($target) { $target=" target=\"$target\""; }
5485: return
5486: '<a href="/adm/grades?command=submission'.
5487: '&symb='.$symb.
5488: '&student='.$uname.
5489: '&userdom='.$udom.'"'.
5490: $target.'>'.$text.'</a>';
1.242 albertel 5491: }
5492: ##############################################
5493:
5494: =pod
5495:
5496: =item * &pgrdlink()
5497:
5498: Inputs: $text $uname $udom $symb $target
5499:
5500: Returns: A link to grades.pm such as to see the PGRD view of a student
5501:
5502: =cut
5503:
5504: ###############################################
5505: sub pgrdlink {
5506: my $link=&submlink(@_);
5507: $link=~s/(&command=submission)/$1&showgrading=yes/;
5508: return $link;
5509: }
5510: ##############################################
5511:
5512: =pod
5513:
5514: =item * &pprmlink()
5515:
5516: Inputs: $text $uname $udom $symb $target
5517:
5518: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 5519: student and a specific resource
1.242 albertel 5520:
5521: =cut
5522:
5523: ###############################################
5524: sub pprmlink {
5525: my ($text,$uname,$udom,$symb,$target)=@_;
5526: if (!($uname && $udom)) {
5527: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5528: &Apache::lonnet::whichuser($symb);
1.242 albertel 5529: if (!$symb) { $symb=$cursymb; }
5530: }
1.254 matthew 5531: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5532: $symb=&escape($symb);
1.242 albertel 5533: if ($target) { $target="target=\"$target\""; }
1.595 albertel 5534: return '<a href="/adm/parmset?command=set&'.
5535: 'symb='.$symb.'&uname='.$uname.
5536: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 5537: }
5538: ##############################################
1.37 matthew 5539:
1.112 bowersj2 5540: =pod
5541:
5542: =back
5543:
5544: =cut
5545:
1.37 matthew 5546: ###############################################
1.51 www 5547:
5548:
5549: sub timehash {
1.687 raeburn 5550: my ($thistime) = @_;
5551: my $timezone = &Apache::lonlocal::gettimezone();
5552: my $dt = DateTime->from_epoch(epoch => $thistime)
5553: ->set_time_zone($timezone);
5554: my $wday = $dt->day_of_week();
5555: if ($wday == 7) { $wday = 0; }
5556: return ( 'second' => $dt->second(),
5557: 'minute' => $dt->minute(),
5558: 'hour' => $dt->hour(),
5559: 'day' => $dt->day_of_month(),
5560: 'month' => $dt->month(),
5561: 'year' => $dt->year(),
5562: 'weekday' => $wday,
5563: 'dayyear' => $dt->day_of_year(),
5564: 'dlsav' => $dt->is_dst() );
1.51 www 5565: }
5566:
1.370 www 5567: sub utc_string {
5568: my ($date)=@_;
1.371 www 5569: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5570: }
5571:
1.51 www 5572: sub maketime {
5573: my %th=@_;
1.687 raeburn 5574: my ($epoch_time,$timezone,$dt);
5575: $timezone = &Apache::lonlocal::gettimezone();
5576: eval {
5577: $dt = DateTime->new( year => $th{'year'},
5578: month => $th{'month'},
5579: day => $th{'day'},
5580: hour => $th{'hour'},
5581: minute => $th{'minute'},
5582: second => $th{'second'},
5583: time_zone => $timezone,
5584: );
5585: };
5586: if (!$@) {
5587: $epoch_time = $dt->epoch;
5588: if ($epoch_time) {
5589: return $epoch_time;
5590: }
5591: }
1.51 www 5592: return POSIX::mktime(
5593: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5594: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5595: }
5596:
5597: #########################################
1.51 www 5598:
5599: sub findallcourses {
1.482 raeburn 5600: my ($roles,$uname,$udom) = @_;
1.355 albertel 5601: my %roles;
5602: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5603: my %courses;
1.51 www 5604: my $now=time;
1.482 raeburn 5605: if (!defined($uname)) {
5606: $uname = $env{'user.name'};
5607: }
5608: if (!defined($udom)) {
5609: $udom = $env{'user.domain'};
5610: }
5611: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5612: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5613: if (!%roles) {
5614: %roles = (
5615: cc => 1,
1.907 raeburn 5616: co => 1,
1.482 raeburn 5617: in => 1,
5618: ep => 1,
5619: ta => 1,
5620: cr => 1,
5621: st => 1,
5622: );
5623: }
5624: foreach my $entry (keys(%roleshash)) {
5625: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5626: if ($trole =~ /^cr/) {
5627: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5628: } else {
5629: next if (!exists($roles{$trole}));
5630: }
5631: if ($tend) {
5632: next if ($tend < $now);
5633: }
5634: if ($tstart) {
5635: next if ($tstart > $now);
5636: }
1.1058 raeburn 5637: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5638: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5639: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5640: if ($secpart eq '') {
5641: ($cnum,$role) = split(/_/,$cnumpart);
5642: $sec = 'none';
1.1058 raeburn 5643: $value .= $cnum.'/';
1.482 raeburn 5644: } else {
5645: $cnum = $cnumpart;
5646: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5647: $value .= $cnum.'/'.$sec;
5648: }
5649: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5650: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5651: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5652: }
5653: } else {
5654: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5655: }
1.482 raeburn 5656: }
5657: } else {
5658: foreach my $key (keys(%env)) {
1.483 albertel 5659: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5660: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5661: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5662: next if ($role eq 'ca' || $role eq 'aa');
5663: next if (%roles && !exists($roles{$role}));
5664: my ($starttime,$endtime)=split(/\./,$env{$key});
5665: my $active=1;
5666: if ($starttime) {
5667: if ($now<$starttime) { $active=0; }
5668: }
5669: if ($endtime) {
5670: if ($now>$endtime) { $active=0; }
5671: }
5672: if ($active) {
1.1058 raeburn 5673: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5674: if ($sec eq '') {
5675: $sec = 'none';
1.1058 raeburn 5676: } else {
5677: $value .= $sec;
5678: }
5679: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5680: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5681: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5682: }
5683: } else {
5684: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5685: }
1.474 raeburn 5686: }
5687: }
1.51 www 5688: }
5689: }
1.474 raeburn 5690: return %courses;
1.51 www 5691: }
1.37 matthew 5692:
1.54 www 5693: ###############################################
1.474 raeburn 5694:
5695: sub blockcheck {
1.1372 raeburn 5696: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
5697: unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
5698: my ($has_evb,$check_ipaccess);
5699: my $dom = $env{'user.domain'};
5700: if ($env{'request.course.id'}) {
5701: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5702: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5703: my $checkrole = "cm./$cdom/$cnum";
5704: my $sec = $env{'request.course.sec'};
5705: if ($sec ne '') {
5706: $checkrole .= "/$sec";
5707: }
5708: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
5709: ($env{'request.role'} !~ /^st/)) {
5710: $has_evb = 1;
5711: }
5712: unless ($has_evb) {
5713: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
1.1444 raeburn 5714: ($activity eq 'index') || ($activity eq 'boards') || ($activity eq 'groups') ||
5715: ($activity eq 'chat')) {
1.1372 raeburn 5716: if ($udom eq $cdom) {
5717: $check_ipaccess = 1;
5718: }
5719: }
5720: }
1.1375 raeburn 5721: } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
5722: ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
5723: my $checkrole;
5724: if ($env{'request.role.domain'} eq '') {
5725: $checkrole = "cm./$env{'user.domain'}/";
5726: } else {
5727: $checkrole = "cm./$env{'request.role.domain'}/";
5728: }
5729: if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
5730: $has_evb = 1;
5731: }
1.1372 raeburn 5732: }
5733: unless ($has_evb || $check_ipaccess) {
5734: my @machinedoms = &Apache::lonnet::current_machine_domains();
5735: if (($dom eq 'public') && ($activity eq 'port')) {
5736: $dom = $udom;
5737: }
5738: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5739: $check_ipaccess = 1;
5740: } else {
5741: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5742: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5743: my $prim = &Apache::lonnet::domain($dom,'primary');
5744: my $intdom = &Apache::lonnet::internet_dom($prim);
5745: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5746: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5747: $check_ipaccess = 1;
5748: }
5749: }
5750: }
5751: }
5752: if ($check_ipaccess) {
5753: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5754: unless (defined($cached)) {
5755: my %domconfig =
5756: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5757: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5758: }
5759: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5760: foreach my $id (keys(%{$ipaccessref})) {
5761: if (ref($ipaccessref->{$id}) eq 'HASH') {
5762: my $range = $ipaccessref->{$id}->{'ip'};
5763: if ($range) {
5764: if (&Apache::lonnet::ip_match($clientip,$range)) {
5765: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5766: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5767: return ('','','',$id,$dom);
5768: last;
5769: }
5770: }
5771: }
5772: }
5773: }
5774: }
5775: }
5776: }
1.1373 raeburn 5777: if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5778: return ();
5779: }
1.1372 raeburn 5780: }
1.1189 raeburn 5781: if (defined($udom) && defined($uname)) {
5782: # If uname and udom are for a course, check for blocks in the course.
5783: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5784: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5785: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 5786: return ($startblock,$endblock,$triggerblock);
5787: }
5788: } else {
1.490 raeburn 5789: $udom = $env{'user.domain'};
5790: $uname = $env{'user.name'};
5791: }
5792:
1.502 raeburn 5793: my $startblock = 0;
5794: my $endblock = 0;
1.1062 raeburn 5795: my $triggerblock = '';
1.1373 raeburn 5796: my %live_courses;
5797: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5798: %live_courses = &findallcourses(undef,$uname,$udom);
5799: }
1.474 raeburn 5800:
1.490 raeburn 5801: # If uname is for a user, and activity is course-specific, i.e.,
5802: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5803:
1.490 raeburn 5804: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5805: $activity eq 'groups' || $activity eq 'printout' ||
1.1444 raeburn 5806: $activity eq 'search' || $activity eq 'index' ||
5807: $activity eq 'reinit' || $activity eq 'alert') &&
1.1189 raeburn 5808: ($env{'request.course.id'})) {
1.490 raeburn 5809: foreach my $key (keys(%live_courses)) {
5810: if ($key ne $env{'request.course.id'}) {
5811: delete($live_courses{$key});
5812: }
5813: }
5814: }
5815:
5816: my $otheruser = 0;
5817: my %own_courses;
5818: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5819: # Resource belongs to user other than current user.
5820: $otheruser = 1;
5821: # Gather courses for current user
5822: %own_courses =
5823: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5824: }
5825:
5826: # Gather active course roles - course coordinator, instructor,
5827: # exam proctor, ta, student, or custom role.
1.474 raeburn 5828:
5829: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5830: my ($cdom,$cnum);
5831: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5832: $cdom = $env{'course.'.$course.'.domain'};
5833: $cnum = $env{'course.'.$course.'.num'};
5834: } else {
1.490 raeburn 5835: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5836: }
5837: my $no_ownblock = 0;
5838: my $no_userblock = 0;
1.533 raeburn 5839: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5840: # Check if current user has 'evb' priv for this
5841: if (defined($own_courses{$course})) {
5842: foreach my $sec (keys(%{$own_courses{$course}})) {
5843: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5844: if ($sec ne 'none') {
5845: $checkrole .= '/'.$sec;
5846: }
5847: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5848: $no_ownblock = 1;
5849: last;
5850: }
5851: }
5852: }
5853: # if they have 'evb' priv and are currently not playing student
5854: next if (($no_ownblock) &&
5855: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5856: }
1.474 raeburn 5857: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5858: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5859: if ($sec ne 'none') {
1.482 raeburn 5860: $checkrole .= '/'.$sec;
1.474 raeburn 5861: }
1.490 raeburn 5862: if ($otheruser) {
5863: # Resource belongs to user other than current user.
5864: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5865: my (%allroles,%userroles);
5866: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5867: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5868: my ($trole,$tdom,$tnum,$tsec);
5869: if ($entry =~ /^cr/) {
5870: ($trole,$tdom,$tnum,$tsec) =
5871: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5872: } else {
5873: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5874: }
5875: my ($spec,$area,$trest);
5876: $area = '/'.$tdom.'/'.$tnum;
5877: $trest = $tnum;
5878: if ($tsec ne '') {
5879: $area .= '/'.$tsec;
5880: $trest .= '/'.$tsec;
5881: }
5882: $spec = $trole.'.'.$area;
5883: if ($trole =~ /^cr/) {
5884: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5885: $tdom,$spec,$trest,$area);
5886: } else {
5887: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5888: $tdom,$spec,$trest,$area);
5889: }
5890: }
1.1276 raeburn 5891: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5892: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5893: if ($1) {
5894: $no_userblock = 1;
5895: last;
5896: }
1.486 raeburn 5897: }
5898: }
1.490 raeburn 5899: } else {
5900: # Resource belongs to current user
5901: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5902: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5903: $no_ownblock = 1;
5904: last;
5905: }
1.474 raeburn 5906: }
5907: }
5908: # if they have the evb priv and are currently not playing student
1.482 raeburn 5909: next if (($no_ownblock) &&
1.491 albertel 5910: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5911: next if ($no_userblock);
1.474 raeburn 5912:
1.1303 raeburn 5913: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5914: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5915:
1.1062 raeburn 5916: my ($start,$end,$trigger) =
1.1347 raeburn 5917: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5918: if (($start != 0) &&
5919: (($startblock == 0) || ($startblock > $start))) {
5920: $startblock = $start;
1.1062 raeburn 5921: if ($trigger ne '') {
5922: $triggerblock = $trigger;
5923: }
1.502 raeburn 5924: }
5925: if (($end != 0) &&
5926: (($endblock == 0) || ($endblock < $end))) {
5927: $endblock = $end;
1.1062 raeburn 5928: if ($trigger ne '') {
5929: $triggerblock = $trigger;
5930: }
1.502 raeburn 5931: }
1.490 raeburn 5932: }
1.1062 raeburn 5933: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5934: }
5935:
5936: sub get_blocks {
1.1347 raeburn 5937: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5938: my $startblock = 0;
5939: my $endblock = 0;
1.1062 raeburn 5940: my $triggerblock = '';
1.490 raeburn 5941: my $course = $cdom.'_'.$cnum;
5942: $setters->{$course} = {};
5943: $setters->{$course}{'staff'} = [];
5944: $setters->{$course}{'times'} = [];
1.1062 raeburn 5945: $setters->{$course}{'triggers'} = [];
5946: my (@blockers,%triggered);
5947: my $now = time;
5948: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5949: if ($activity eq 'docs') {
1.1348 raeburn 5950: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5951: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5952: $blocked = 1;
5953: $nosymbcache = 1;
1.1348 raeburn 5954: $noenccheck = 1;
1.1347 raeburn 5955: }
1.1348 raeburn 5956: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5957: foreach my $block (@blockers) {
5958: if ($block =~ /^firstaccess____(.+)$/) {
5959: my $item = $1;
5960: my $type = 'map';
5961: my $timersymb = $item;
5962: if ($item eq 'course') {
5963: $type = 'course';
5964: } elsif ($item =~ /___\d+___/) {
5965: $type = 'resource';
5966: } else {
5967: $timersymb = &Apache::lonnet::symbread($item);
5968: }
5969: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5970: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5971: $triggered{$block} = {
5972: start => $start,
5973: end => $end,
5974: type => $type,
5975: };
5976: }
5977: }
5978: } else {
5979: foreach my $block (keys(%commblocks)) {
5980: if ($block =~ m/^(\d+)____(\d+)$/) {
5981: my ($start,$end) = ($1,$2);
5982: if ($start <= time && $end >= time) {
5983: if (ref($commblocks{$block}) eq 'HASH') {
5984: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5985: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5986: unless(grep(/^\Q$block\E$/,@blockers)) {
5987: push(@blockers,$block);
5988: }
5989: }
5990: }
5991: }
5992: }
5993: } elsif ($block =~ /^firstaccess____(.+)$/) {
5994: my $item = $1;
5995: my $timersymb = $item;
5996: my $type = 'map';
5997: if ($item eq 'course') {
5998: $type = 'course';
5999: } elsif ($item =~ /___\d+___/) {
6000: $type = 'resource';
6001: } else {
6002: $timersymb = &Apache::lonnet::symbread($item);
6003: }
6004: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
6005: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
6006: if ($start && $end) {
6007: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 6008: if (ref($commblocks{$block}) eq 'HASH') {
6009: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
6010: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
6011: unless(grep(/^\Q$block\E$/,@blockers)) {
6012: push(@blockers,$block);
6013: $triggered{$block} = {
6014: start => $start,
6015: end => $end,
6016: type => $type,
6017: };
6018: }
6019: }
6020: }
1.1062 raeburn 6021: }
6022: }
1.490 raeburn 6023: }
1.1062 raeburn 6024: }
6025: }
6026: }
6027: foreach my $blocker (@blockers) {
6028: my ($staff_name,$staff_dom,$title,$blocks) =
6029: &parse_block_record($commblocks{$blocker});
6030: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
6031: my ($start,$end,$triggertype);
6032: if ($blocker =~ m/^(\d+)____(\d+)$/) {
6033: ($start,$end) = ($1,$2);
6034: } elsif (ref($triggered{$blocker}) eq 'HASH') {
6035: $start = $triggered{$blocker}{'start'};
6036: $end = $triggered{$blocker}{'end'};
6037: $triggertype = $triggered{$blocker}{'type'};
6038: }
6039: if ($start) {
6040: push(@{$$setters{$course}{'times'}}, [$start,$end]);
6041: if ($triggertype) {
6042: push(@{$$setters{$course}{'triggers'}},$triggertype);
6043: } else {
6044: push(@{$$setters{$course}{'triggers'}},0);
6045: }
6046: if ( ($startblock == 0) || ($startblock > $start) ) {
6047: $startblock = $start;
6048: if ($triggertype) {
6049: $triggerblock = $blocker;
1.474 raeburn 6050: }
6051: }
1.1062 raeburn 6052: if ( ($endblock == 0) || ($endblock < $end) ) {
6053: $endblock = $end;
6054: if ($triggertype) {
6055: $triggerblock = $blocker;
6056: }
6057: }
1.474 raeburn 6058: }
6059: }
1.1062 raeburn 6060: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 6061: }
6062:
6063: sub parse_block_record {
6064: my ($record) = @_;
6065: my ($setuname,$setudom,$title,$blocks);
6066: if (ref($record) eq 'HASH') {
6067: ($setuname,$setudom) = split(/:/,$record->{'setter'});
6068: $title = &unescape($record->{'event'});
6069: $blocks = $record->{'blocks'};
6070: } else {
6071: my @data = split(/:/,$record,3);
6072: if (scalar(@data) eq 2) {
6073: $title = $data[1];
6074: ($setuname,$setudom) = split(/@/,$data[0]);
6075: } else {
6076: ($setuname,$setudom,$title) = @data;
6077: }
6078: $blocks = { 'com' => 'on' };
6079: }
6080: return ($setuname,$setudom,$title,$blocks);
6081: }
6082:
1.854 kalberla 6083: sub blocking_status {
1.1372 raeburn 6084: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 6085: my %setters;
1.890 droeschl 6086:
1.1061 raeburn 6087: # check for active blocking
1.1372 raeburn 6088: if ($clientip eq '') {
6089: $clientip = &Apache::lonnet::get_requestor_ip();
6090: }
6091: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
6092: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 6093: my $blocked = 0;
1.1372 raeburn 6094: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 6095: $blocked = 1;
6096: }
1.890 droeschl 6097:
1.1061 raeburn 6098: # caller just wants to know whether a block is active
6099: if (!wantarray) { return $blocked; }
6100:
6101: # build a link to a popup window containing the details
6102: my $querystring = "?activity=$activity";
1.1351 raeburn 6103: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
6104: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1232 raeburn 6105: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
6106: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 6107: } elsif ($activity eq 'docs') {
1.1347 raeburn 6108: my $showurl = &Apache::lonenc::check_encrypt($url);
6109: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
6110: if ($symb) {
6111: my $showsymb = &Apache::lonenc::check_encrypt($symb);
6112: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
6113: }
1.1062 raeburn 6114: }
1.1061 raeburn 6115:
6116: my $output .= <<'END_MYBLOCK';
6117: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
6118: var options = "width=" + w + ",height=" + h + ",";
6119: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
6120: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
6121: var newWin = window.open(url, wdwName, options);
6122: newWin.focus();
6123: }
1.890 droeschl 6124: END_MYBLOCK
1.854 kalberla 6125:
1.1061 raeburn 6126: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 6127:
1.1061 raeburn 6128: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 6129: my $text = &mt('Communication Blocked');
1.1217 raeburn 6130: my $class = 'LC_comblock';
1.1062 raeburn 6131: if ($activity eq 'docs') {
6132: $text = &mt('Content Access Blocked');
1.1217 raeburn 6133: $class = '';
1.1063 raeburn 6134: } elsif ($activity eq 'printout') {
6135: $text = &mt('Printing Blocked');
1.1232 raeburn 6136: } elsif ($activity eq 'passwd') {
6137: $text = &mt('Password Changing Blocked');
1.1345 raeburn 6138: } elsif ($activity eq 'grades') {
6139: $text = &mt('Gradebook Blocked');
1.1346 raeburn 6140: } elsif ($activity eq 'search') {
6141: $text = &mt('Search Blocked');
1.1444 raeburn 6142: } elsif ($activity eq 'index') {
6143: $text = &mt('Content Index Blocked');
1.1282 raeburn 6144: } elsif ($activity eq 'alert') {
6145: $text = &mt('Checking Critical Messages Blocked');
6146: } elsif ($activity eq 'reinit') {
6147: $text = &mt('Checking Course Update Blocked');
1.1351 raeburn 6148: } elsif ($activity eq 'about') {
6149: $text = &mt('Access to User Information Pages Blocked');
1.1373 raeburn 6150: } elsif ($activity eq 'wishlist') {
6151: $text = &mt('Access to Stored Links Blocked');
6152: } elsif ($activity eq 'annotate') {
6153: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 6154: }
1.1061 raeburn 6155: $output .= <<"END_BLOCK";
1.1217 raeburn 6156: <div class='$class'>
1.869 kalberla 6157: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 6158: title='$text'>
6159: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 6160: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 6161: title='$text'>$text</a>
1.867 kalberla 6162: </div>
6163:
6164: END_BLOCK
1.474 raeburn 6165:
1.1061 raeburn 6166: return ($blocked, $output);
1.854 kalberla 6167: }
1.490 raeburn 6168:
1.60 matthew 6169: ###############################################
6170:
1.682 raeburn 6171: sub check_ip_acc {
1.1201 raeburn 6172: my ($acc,$clientip)=@_;
1.682 raeburn 6173: &Apache::lonxml::debug("acc is $acc");
6174: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
6175: return 1;
6176: }
1.1339 raeburn 6177: my ($ip,$allowed);
6178: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
6179: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
6180: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
6181: } else {
1.1350 raeburn 6182: my $remote_ip = &Apache::lonnet::get_requestor_ip();
6183: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1339 raeburn 6184: }
1.682 raeburn 6185:
6186: my $name;
1.1219 raeburn 6187: my %access = (
6188: allowfrom => 1,
6189: denyfrom => 0,
6190: );
6191: my @allows;
6192: my @denies;
6193: foreach my $item (split(',',$acc)) {
6194: $item =~ s/^\s*//;
6195: $item =~ s/\s*$//;
6196: my $pattern;
6197: if ($item =~ /^\!(.+)$/) {
6198: push(@denies,$1);
6199: } else {
6200: push(@allows,$item);
6201: }
6202: }
6203: my $numdenies = scalar(@denies);
6204: my $numallows = scalar(@allows);
6205: my $count = 0;
6206: foreach my $pattern (@denies,@allows) {
6207: $count ++;
6208: my $acctype = 'allowfrom';
6209: if ($count <= $numdenies) {
6210: $acctype = 'denyfrom';
6211: }
1.682 raeburn 6212: if ($pattern =~ /\*$/) {
6213: #35.8.*
6214: $pattern=~s/\*//;
1.1219 raeburn 6215: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6216: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
6217: #35.8.3.[34-56]
6218: my $low=$2;
6219: my $high=$3;
6220: $pattern=$1;
6221: if ($ip =~ /^\Q$pattern\E/) {
6222: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 6223: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 6224: }
6225: } elsif ($pattern =~ /^\*/) {
6226: #*.msu.edu
6227: $pattern=~s/\*//;
6228: if (!defined($name)) {
6229: use Socket;
6230: my $netaddr=inet_aton($ip);
6231: ($name)=gethostbyaddr($netaddr,AF_INET);
6232: }
1.1219 raeburn 6233: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 6234: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
6235: #127.0.0.1
1.1219 raeburn 6236: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6237: } else {
6238: #some.name.com
6239: if (!defined($name)) {
6240: use Socket;
6241: my $netaddr=inet_aton($ip);
6242: ($name)=gethostbyaddr($netaddr,AF_INET);
6243: }
1.1219 raeburn 6244: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
6245: }
6246: if ($allowed =~ /^(0|1)$/) { last; }
6247: }
6248: if ($allowed eq '') {
6249: if ($numdenies && !$numallows) {
6250: $allowed = 1;
6251: } else {
6252: $allowed = 0;
1.682 raeburn 6253: }
6254: }
6255: return $allowed;
6256: }
6257:
6258: ###############################################
6259:
1.60 matthew 6260: =pod
6261:
1.112 bowersj2 6262: =head1 Domain Template Functions
6263:
6264: =over 4
6265:
6266: =item * &determinedomain()
1.60 matthew 6267:
6268: Inputs: $domain (usually will be undef)
6269:
1.63 www 6270: Returns: Determines which domain should be used for designs
1.60 matthew 6271:
6272: =cut
1.54 www 6273:
1.60 matthew 6274: ###############################################
1.63 www 6275: sub determinedomain {
6276: my $domain=shift;
1.531 albertel 6277: if (! $domain) {
1.60 matthew 6278: # Determine domain if we have not been given one
1.893 raeburn 6279: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 6280: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
6281: if ($env{'request.role.domain'}) {
6282: $domain=$env{'request.role.domain'};
1.60 matthew 6283: }
6284: }
1.63 www 6285: return $domain;
6286: }
6287: ###############################################
1.517 raeburn 6288:
1.518 albertel 6289: sub devalidate_domconfig_cache {
6290: my ($udom)=@_;
6291: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
6292: }
6293:
6294: # ---------------------- Get domain configuration for a domain
6295: sub get_domainconf {
6296: my ($udom) = @_;
6297: my $cachetime=1800;
6298: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
6299: if (defined($cached)) { return %{$result}; }
6300:
6301: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 6302: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 6303: my (%designhash,%legacy);
1.518 albertel 6304: if (keys(%domconfig) > 0) {
6305: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 6306: if (keys(%{$domconfig{'login'}})) {
6307: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 6308: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 6309: if (($key eq 'loginvia') || ($key eq 'headtag')) {
6310: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6311: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
6312: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
6313: if ($key eq 'loginvia') {
6314: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
6315: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
6316: $designhash{$udom.'.login.loginvia'} = $server;
6317: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
6318:
6319: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
6320: } else {
6321: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
6322: }
1.948 raeburn 6323: }
1.1208 raeburn 6324: } elsif ($key eq 'headtag') {
6325: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
6326: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 6327: }
1.946 raeburn 6328: }
1.1208 raeburn 6329: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
6330: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
6331: }
1.946 raeburn 6332: }
6333: }
6334: }
1.1366 raeburn 6335: } elsif ($key eq 'saml') {
6336: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6337: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
6338: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
6339: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
1.1386 raeburn 6340: foreach my $item ('text','img','alt','url','title','window','notsso') {
1.1366 raeburn 6341: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
6342: }
6343: }
6344: }
6345: }
1.946 raeburn 6346: } else {
6347: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
6348: $designhash{$udom.'.login.'.$key.'_'.$img} =
6349: $domconfig{'login'}{$key}{$img};
6350: }
1.699 raeburn 6351: }
6352: } else {
6353: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
6354: }
1.632 raeburn 6355: }
6356: } else {
6357: $legacy{'login'} = 1;
1.518 albertel 6358: }
1.632 raeburn 6359: } else {
6360: $legacy{'login'} = 1;
1.518 albertel 6361: }
6362: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 6363: if (keys(%{$domconfig{'rolecolors'}})) {
6364: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
6365: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
6366: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
6367: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
6368: }
1.518 albertel 6369: }
6370: }
1.632 raeburn 6371: } else {
6372: $legacy{'rolecolors'} = 1;
1.518 albertel 6373: }
1.632 raeburn 6374: } else {
6375: $legacy{'rolecolors'} = 1;
1.518 albertel 6376: }
1.948 raeburn 6377: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6378: if ($domconfig{'autoenroll'}{'co-owners'}) {
6379: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
6380: }
6381: }
1.632 raeburn 6382: if (keys(%legacy) > 0) {
6383: my %legacyhash = &get_legacy_domconf($udom);
6384: foreach my $item (keys(%legacyhash)) {
6385: if ($item =~ /^\Q$udom\E\.login/) {
6386: if ($legacy{'login'}) {
6387: $designhash{$item} = $legacyhash{$item};
6388: }
6389: } else {
6390: if ($legacy{'rolecolors'}) {
6391: $designhash{$item} = $legacyhash{$item};
6392: }
1.518 albertel 6393: }
6394: }
6395: }
1.632 raeburn 6396: } else {
6397: %designhash = &get_legacy_domconf($udom);
1.518 albertel 6398: }
6399: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
6400: $cachetime);
6401: return %designhash;
6402: }
6403:
1.632 raeburn 6404: sub get_legacy_domconf {
6405: my ($udom) = @_;
6406: my %legacyhash;
6407: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
6408: my $designfile = $designdir.'/'.$udom.'.tab';
6409: if (-e $designfile) {
1.1317 raeburn 6410: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 6411: while (my $line = <$fh>) {
6412: next if ($line =~ /^\#/);
6413: chomp($line);
6414: my ($key,$val)=(split(/\=/,$line));
6415: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
6416: }
6417: close($fh);
6418: }
6419: }
1.1026 raeburn 6420: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 6421: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
6422: }
6423: return %legacyhash;
6424: }
6425:
1.63 www 6426: =pod
6427:
1.112 bowersj2 6428: =item * &domainlogo()
1.63 www 6429:
6430: Inputs: $domain (usually will be undef)
6431:
6432: Returns: A link to a domain logo, if the domain logo exists.
6433: If the domain logo does not exist, a description of the domain.
6434:
6435: =cut
1.112 bowersj2 6436:
1.63 www 6437: ###############################################
6438: sub domainlogo {
1.517 raeburn 6439: my $domain = &determinedomain(shift);
1.518 albertel 6440: my %designhash = &get_domainconf($domain);
1.517 raeburn 6441: # See if there is a logo
6442: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 6443: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 6444: if ($imgsrc =~ m{^/(adm|res)/}) {
6445: if ($imgsrc =~ m{^/res/}) {
6446: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
6447: &Apache::lonnet::repcopy($local_name);
6448: }
6449: $imgsrc = &lonhttpdurl($imgsrc);
1.1374 raeburn 6450: }
6451: my $alttext = $domain;
6452: if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
6453: $alttext = $designhash{$domain.'.login.alttext_domlogo'};
6454: }
6455: return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 6456: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
6457: return &Apache::lonnet::domain($domain,'description');
1.59 www 6458: } else {
1.60 matthew 6459: return '';
1.59 www 6460: }
6461: }
1.63 www 6462: ##############################################
6463:
6464: =pod
6465:
1.112 bowersj2 6466: =item * &designparm()
1.63 www 6467:
6468: Inputs: $which parameter; $domain (usually will be undef)
6469:
6470: Returns: value of designparamter $which
6471:
6472: =cut
1.112 bowersj2 6473:
1.397 albertel 6474:
1.400 albertel 6475: ##############################################
1.397 albertel 6476: sub designparm {
6477: my ($which,$domain)=@_;
6478: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 6479: return $env{'environment.color.'.$which};
1.96 www 6480: }
1.63 www 6481: $domain=&determinedomain($domain);
1.1016 raeburn 6482: my %domdesign;
6483: unless ($domain eq 'public') {
6484: %domdesign = &get_domainconf($domain);
6485: }
1.520 raeburn 6486: my $output;
1.517 raeburn 6487: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 6488: $output = $domdesign{$domain.'.'.$which};
1.63 www 6489: } else {
1.520 raeburn 6490: $output = $defaultdesign{$which};
6491: }
6492: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 6493: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 6494: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 6495: if ($output =~ m{^/res/}) {
6496: my $local_name = &Apache::lonnet::filelocation('',$output);
6497: &Apache::lonnet::repcopy($local_name);
6498: }
1.520 raeburn 6499: $output = &lonhttpdurl($output);
6500: }
1.63 www 6501: }
1.520 raeburn 6502: return $output;
1.63 www 6503: }
1.59 www 6504:
1.822 bisitz 6505: ##############################################
6506: =pod
6507:
1.832 bisitz 6508: =item * &authorspace()
6509:
1.1028 raeburn 6510: Inputs: $url (usually will be undef).
1.832 bisitz 6511:
1.1132 raeburn 6512: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 6513: directory being viewed (or for which action is being taken).
6514: If $url is provided, and begins /priv/<domain>/<uname>
6515: the path will be that portion of the $context argument.
6516: Otherwise the path will be for the author space of the current
6517: user when the current role is author, or for that of the
6518: co-author/assistant co-author space when the current role
6519: is co-author or assistant co-author.
1.832 bisitz 6520:
6521: =cut
6522:
6523: sub authorspace {
1.1028 raeburn 6524: my ($url) = @_;
6525: if ($url ne '') {
6526: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
6527: return $1;
6528: }
6529: }
1.832 bisitz 6530: my $caname = '';
1.1024 www 6531: my $cadom = '';
1.1028 raeburn 6532: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 6533: ($cadom,$caname) =
1.832 bisitz 6534: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 6535: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 6536: $caname = $env{'user.name'};
1.1024 www 6537: $cadom = $env{'user.domain'};
1.832 bisitz 6538: }
1.1028 raeburn 6539: if (($caname ne '') && ($cadom ne '')) {
6540: return "/priv/$cadom/$caname/";
6541: }
6542: return;
1.832 bisitz 6543: }
6544:
6545: ##############################################
6546: =pod
6547:
1.822 bisitz 6548: =item * &head_subbox()
6549:
6550: Inputs: $content (contains HTML code with page functions, etc.)
6551:
6552: Returns: HTML div with $content
6553: To be included in page header
6554:
6555: =cut
6556:
6557: sub head_subbox {
6558: my ($content)=@_;
6559: my $output =
1.993 raeburn 6560: '<div class="LC_head_subbox">'
1.822 bisitz 6561: .$content
6562: .'</div>'
6563: }
6564:
6565: ##############################################
6566: =pod
6567:
6568: =item * &CSTR_pageheader()
6569:
1.1026 raeburn 6570: Input: (optional) filename from which breadcrumb trail is built.
6571: In most cases no input as needed, as $env{'request.filename'}
6572: is appropriate for use in building the breadcrumb trail.
1.1379 raeburn 6573: frameset flag
6574: If page header is being requested for use in a frameset, then
6575: the second (option) argument -- frameset will be true, and
6576: the target attribute set for links should be target="_parent".
1.1433 raeburn 6577: If $title is supplied as the third arg, that will be used to
1.1407 raeburn 6578: the left of the breadcrumbs tail for the current path.
1.822 bisitz 6579:
6580: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 6581: To be included on Authoring Space pages
1.822 bisitz 6582:
6583: =cut
6584:
6585: sub CSTR_pageheader {
1.1407 raeburn 6586: my ($trailfile,$frameset,$title) = @_;
1.1026 raeburn 6587: if ($trailfile eq '') {
6588: $trailfile = $env{'request.filename'};
6589: }
6590:
6591: # this is for resources; directories have customtitle, and crumbs
6592: # and select recent are created in lonpubdir.pm
6593:
6594: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 6595: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 6596: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 6597: my $formaction = "/priv/$udom/$uname/$thisdisfn";
6598: $formaction =~ s{/+}{/}g;
1.822 bisitz 6599:
6600: my $parentpath = '';
6601: my $lastitem = '';
6602: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
6603: $parentpath = $1;
6604: $lastitem = $2;
6605: } else {
6606: $lastitem = $thisdisfn;
6607: }
1.921 bisitz 6608:
1.1406 raeburn 6609: my $crsauthor;
1.1246 raeburn 6610: if (($env{'request.course.id'}) &&
6611: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 6612: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 6613: $crsauthor = 1;
1.1406 raeburn 6614: if ($title eq '') {
6615: $title = &mt('Course Authoring Space');
6616: }
6617: } elsif ($title eq '') {
1.1246 raeburn 6618: $title = &mt('Authoring Space');
6619: }
6620:
1.1379 raeburn 6621: my ($target,$crumbtarget) = (' target="_top"','_top');
6622: if ($frameset) {
6623: $target = ' target="_parent"';
6624: $crumbtarget = '_parent';
6625: } elsif (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 6626: $target = '';
6627: $crumbtarget = '';
1.1379 raeburn 6628: } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {
1.1378 raeburn 6629: $target = ' target="'.$env{'request.deeplink.target'}.'"';
6630: $crumbtarget = $env{'request.deeplink.target'};
6631: }
1.1313 raeburn 6632:
1.921 bisitz 6633: my $output =
1.1407 raeburn 6634: '<div>'
1.822 bisitz 6635: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 6636: .'<b>'.$title.'</b> '
1.1314 raeburn 6637: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6638: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6639:
6640: if ($lastitem) {
6641: $output .=
6642: '<span class="LC_filename">'
6643: .$lastitem
6644: .'</span>';
6645: }
1.1245 raeburn 6646:
1.1246 raeburn 6647: if ($crsauthor) {
1.1379 raeburn 6648: $output .= '</form>'.&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6649: } else {
6650: $output .=
6651: '<br />'
1.1314 raeburn 6652: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 6653: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6654: .'</form>'
1.1379 raeburn 6655: .&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6656: }
1.1407 raeburn 6657: $output .= '</div>';
1.921 bisitz 6658:
6659: return $output;
1.822 bisitz 6660: }
6661:
1.1419 raeburn 6662: ##############################################
6663: =pod
6664:
6665: =item * &nocodemirror()
6666:
6667: Input: None
6668:
6669: Returns: 1 if CodeMirror is deactivated based on
6670: user's preference, or domain default,
6671: if user indicated use of default.
6672:
6673: =cut
6674:
1.1416 raeburn 6675: sub nocodemirror {
6676: my $nocodem = $env{'environment.nocodemirror'};
6677: unless ($nocodem) {
6678: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
6679: if ($domdefs{'nocodemirror'}) {
6680: $nocodem = 'yes';
6681: }
6682: }
1.1417 raeburn 6683: if ($nocodem eq 'yes') {
6684: return 1;
6685: }
6686: return;
1.1416 raeburn 6687: }
6688:
1.1419 raeburn 6689: ##############################################
6690: =pod
6691:
6692: =item * &permitted_editors()
6693:
1.1422 raeburn 6694: Input: $uri (optional)
1.1419 raeburn 6695:
6696: Returns: %editors hash in which keys are editors
1.1429 raeburn 6697: permitted in current Authoring Space,
6698: or in current course for web pages
6699: created in a course.
6700:
1.1419 raeburn 6701: Value for each key is 1. Possible keys
1.1429 raeburn 6702: are: edit, xml, and daxe.
6703:
6704: For a regular Authoring Space, if no specific
1.1419 raeburn 6705: set of editors has been set for the Author
6706: who owns the Authoring Space, then the
6707: domain default will be used. If no domain
6708: default has been set, then the keys will be
6709: edit and xml.
6710:
1.1429 raeburn 6711: For a course author, or for web pages created
6712: in a course, if no specific set of editors has
6713: been set for the course, then the domain
6714: course default will be used. If no domain
6715: course default has been set, then the keys
6716: will be edit and xml.
6717:
1.1419 raeburn 6718: =cut
6719:
1.1418 raeburn 6720: sub permitted_editors {
1.1422 raeburn 6721: my ($uri) = @_;
1.1429 raeburn 6722: my ($is_author,$is_coauthor,$is_course,$auname,$audom,%editors);
1.1418 raeburn 6723: if ($env{'request.role'} =~ m{^au\./}) {
6724: $is_author = 1;
6725: } elsif ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)}) {
6726: ($audom,$auname) = ($1,$2);
6727: if (($audom ne '') && ($auname ne '')) {
6728: if (($env{'user.domain'} eq $audom) &&
6729: ($env{'user.name'} eq $auname)) {
6730: $is_author = 1;
6731: } else {
6732: $is_coauthor = 1;
6733: }
6734: }
6735: } elsif ($env{'request.course.id'}) {
1.1429 raeburn 6736: my ($cdom,$cnum);
6737: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6738: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6739: if (($env{'request.editurl'} =~ m{^/priv/\Q$cdom/$cnum\E/}) ||
1.1430 raeburn 6740: ($env{'request.editurl'} =~ m{^/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/}) ||
6741: ($uri =~ m{^/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/})) {
1.1429 raeburn 6742: $is_course = 1;
6743: } elsif ($env{'request.editurl'} =~ m{^/priv/($match_domain)/($match_username)/}) {
1.1418 raeburn 6744: ($audom,$auname) = ($1,$2);
6745: } elsif ($env{'request.uri'} =~ m{^/priv/($match_domain)/($match_username)/}) {
6746: ($audom,$auname) = ($1,$2);
1.1422 raeburn 6747: } elsif (($uri eq '/daxesave') &&
1.1429 raeburn 6748: (($env{'form.path'} =~ m{^/daxeopen/priv/\Q$cdom/$cnum\E/}) ||
6749: ($env{'form.path'} =~ m{^/daxeopen/uploaded/\Q$cdom/$cnum\E/(docs|supplemental)/}))) {
6750: $is_course = 1;
6751: } elsif (($uri eq '/daxesave') &&
1.1422 raeburn 6752: ($env{'form.path'} =~ m{^/daxeopen/priv/($match_domain)/($match_username)/})) {
6753: ($audom,$auname) = ($1,$2);
1.1418 raeburn 6754: }
1.1429 raeburn 6755: unless ($is_course) {
6756: if (($audom ne '') && ($auname ne '')) {
6757: if (($env{'user.domain'} eq $audom) &&
6758: ($env{'user.name'} eq $auname)) {
6759: $is_author = 1;
6760: } else {
6761: $is_coauthor = 1;
6762: }
1.1418 raeburn 6763: }
6764: }
6765: }
6766: if ($is_author) {
6767: if (exists($env{'environment.editors'})) {
6768: map { $editors{$_} = 1; } split(/,/,$env{'environment.editors'});
6769: } else {
6770: %editors = ( edit => 1,
6771: xml => 1,
6772: );
6773: }
6774: } elsif ($is_coauthor) {
6775: if (exists($env{"environment.internal.editors./$audom/$auname"})) {
6776: map { $editors{$_} = 1; } split(/,/,$env{"environment.internal.editors./$audom/$auname"});
6777: } else {
6778: %editors = ( edit => 1,
6779: xml => 1,
6780: );
6781: }
1.1429 raeburn 6782: } elsif ($is_course) {
6783: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.crseditors'})) {
6784: map { $editors{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.crseditors'});
6785: } else {
6786: my %domdefaults = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
6787: if (exists($domdefaults{'crseditors'})) {
6788: map { $editors{$_} = 1; } split(/,/,$domdefaults{'crseditors'});
6789: } else {
6790: %editors = ( edit => 1,
6791: xml => 1,
6792: );
6793: }
6794: }
1.1418 raeburn 6795: } else {
6796: %editors = ( edit => 1,
6797: xml => 1,
6798: );
6799: }
6800: return %editors;
6801: }
6802:
1.60 matthew 6803: ###############################################
6804: ###############################################
6805:
6806: =pod
6807:
1.112 bowersj2 6808: =back
6809:
1.549 albertel 6810: =head1 HTML Helpers
1.112 bowersj2 6811:
6812: =over 4
6813:
6814: =item * &bodytag()
1.60 matthew 6815:
6816: Returns a uniform header for LON-CAPA web pages.
6817:
6818: Inputs:
6819:
1.112 bowersj2 6820: =over 4
6821:
6822: =item * $title, A title to be displayed on the page.
6823:
6824: =item * $function, the current role (can be undef).
6825:
6826: =item * $addentries, extra parameters for the <body> tag.
6827:
6828: =item * $bodyonly, if defined, only return the <body> tag.
6829:
6830: =item * $domain, if defined, force a given domain.
6831:
6832: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6833: text interface only)
1.60 matthew 6834:
1.814 bisitz 6835: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6836: navigational links
1.317 albertel 6837:
1.338 albertel 6838: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6839:
1.460 albertel 6840: =item * $args, optional argument valid values are
6841: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6842: use_absolute -> for external resource or syllabus, this will
6843: contain https://<hostname> if server uses
6844: https (as per hosts.tab), but request is for http
6845: hostname -> hostname, from $r->hostname().
1.460 albertel 6846:
1.1096 raeburn 6847: =item * $advtoolsref, optional argument, ref to an array containing
6848: inlineremote items to be added in "Functions" menu below
6849: breadcrumbs.
6850:
1.1316 raeburn 6851: =item * $ltiscope, optional argument, will be one of: resource, map or
6852: course, if LON-CAPA is in LTI Provider context. Value is
6853: the scope of use, i.e., launch was for access to a single, a map
6854: or the entire course.
6855:
6856: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6857: context, this will contain the URL for the landing item in
6858: the course, after launch from an LTI Consumer
6859:
1.1318 raeburn 6860: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6861: context, this will contain a reference to hash of items
6862: to be included in the page header and/or inline menu.
6863:
1.1385 raeburn 6864: =item * $menucoll, optional argument, if specific menu collection is in
6865: effect, either set as the default for the course, or set for
6866: the deeplink paramater for $env{'request.deeplink.login'}
6867: then $menucoll will be the number of that collection.
6868:
6869: =item * $menuref, optional argument, reference to a hash, containing the
6870: menu options included for the menu in effect, based on the
6871: configuration for the numbered menu collection in use.
6872:
6873: =item * $showncrumbsref, reference to a scalar. Calls to lonmenu::innerregister
6874: within &bodytag() can result in calls to lonhtmlcommon::breadcrumbs(),
6875: if so, $showncrumbsref is set there to 1, and will propagate back
6876: via &bodytag() to &start_page(), to prevent lonhtmlcommon::breadcrumbs()
6877: being called a second time.
6878:
1.112 bowersj2 6879: =back
6880:
1.60 matthew 6881: Returns: A uniform header for LON-CAPA web pages.
6882: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6883: If $bodyonly is undef or zero, an html string containing a <body> tag and
6884: other decorations will be returned.
6885:
6886: =cut
6887:
1.54 www 6888: sub bodytag {
1.831 bisitz 6889: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1359 raeburn 6890: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,
1.1385 raeburn 6891: $ltimenu,$menucoll,$menuref,$showncrumbsref)=@_;
1.339 albertel 6892:
1.954 raeburn 6893: my $public;
6894: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6895: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6896: $public = 1;
6897: }
1.460 albertel 6898: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6899: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6900: my $hostname = $args->{'hostname'};
1.339 albertel 6901:
1.183 matthew 6902: $function = &get_users_function() if (!$function);
1.339 albertel 6903: my $font = &designparm($function.'.font',$domain);
6904: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6905:
1.803 bisitz 6906: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6907: 'bgcolor' => $pgbg,
1.339 albertel 6908: 'text' => $font,
6909: 'alink' => &designparm($function.'.alink',$domain),
6910: 'vlink' => &designparm($function.'.vlink',$domain),
6911: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6912: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6913:
1.63 www 6914: # role and realm
1.1178 raeburn 6915: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6916: if ($realm) {
6917: $realm = '/'.$realm;
6918: }
1.1357 raeburn 6919: if ($role eq 'ca') {
1.479 albertel 6920: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6921: $realm = &plainname($rname,$rdom);
1.378 raeburn 6922: }
1.55 www 6923: # realm
1.1357 raeburn 6924: my ($cid,$sec);
1.258 albertel 6925: if ($env{'request.course.id'}) {
1.1357 raeburn 6926: $cid = $env{'request.course.id'};
6927: if ($env{'request.course.sec'}) {
6928: $sec = $env{'request.course.sec'};
6929: }
6930: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6931: if (&Apache::lonnet::is_course($1,$2)) {
6932: $cid = $1.'_'.$2;
6933: $sec = $3;
6934: }
6935: }
6936: if ($cid) {
1.378 raeburn 6937: if ($env{'request.role'} !~ /^cr/) {
6938: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6939: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6940: if ($env{'request.role.desc'}) {
6941: $role = $env{'request.role.desc'};
6942: } else {
6943: $role = &mt('Helpdesk[_1]',' '.$2);
6944: }
1.1257 raeburn 6945: } else {
6946: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6947: }
1.1357 raeburn 6948: if ($sec) {
6949: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6950: }
1.1357 raeburn 6951: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6952: } else {
6953: $role = &Apache::lonnet::plaintext($role);
1.54 www 6954: }
1.433 albertel 6955:
1.438 albertel 6956: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6957:
1.101 www 6958: # construct main body tag
1.359 albertel 6959: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6960: &Apache::lontexconvert::init_math_support();
1.252 albertel 6961:
1.1131 raeburn 6962: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6963:
1.1130 raeburn 6964: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6965: return $bodytag;
1.1130 raeburn 6966: }
1.359 albertel 6967:
1.954 raeburn 6968: if ($public) {
1.433 albertel 6969: undef($role);
6970: }
1.1318 raeburn 6971:
1.1359 raeburn 6972: my $showcrstitle = 1;
1.1357 raeburn 6973: if (($cid) && ($env{'request.lti.login'})) {
1.1318 raeburn 6974: if (ref($ltimenu) eq 'HASH') {
6975: unless ($ltimenu->{'role'}) {
6976: undef($role);
6977: }
6978: unless ($ltimenu->{'coursetitle'}) {
1.1359 raeburn 6979: $showcrstitle = 0;
6980: }
6981: }
6982: } elsif (($cid) && ($menucoll)) {
6983: if (ref($menuref) eq 'HASH') {
6984: unless ($menuref->{'role'}) {
6985: undef($role);
6986: }
6987: unless ($menuref->{'crs'}) {
6988: $showcrstitle = 0;
1.1318 raeburn 6989: }
6990: }
6991: }
6992:
1.762 bisitz 6993: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6994: #
6995: # Extra info if you are the DC
6996: my $dc_info = '';
1.1359 raeburn 6997: if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1357 raeburn 6998: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6999: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 7000: $dc_info =~ s/\s+$//;
1.359 albertel 7001: }
7002:
1.1237 raeburn 7003: my $crstype;
1.1357 raeburn 7004: if ($cid) {
7005: $crstype = $env{'course.'.$cid.'.type'};
1.1237 raeburn 7006: } elsif ($args->{'crstype'}) {
7007: $crstype = $args->{'crstype'};
7008: }
7009: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
7010: undef($role);
7011: } else {
1.1242 raeburn 7012: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 7013: }
1.853 droeschl 7014:
1.903 droeschl 7015: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
7016:
7017: # if ($env{'request.state'} eq 'construct') {
7018: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
7019: # }
7020:
1.1440 raeburn 7021: my $need_endlcint;
7022: unless ($args->{'switchserver'}) {
7023: $bodytag .= Apache::lonhtmlcommon::scripttag(
7024: Apache::lonmenu::utilityfunctions($httphost), 'start');
7025: $need_endlcint = 1;
7026: }
1.359 albertel 7027:
1.1427 raeburn 7028: my $collapsible;
1.1423 raeburn 7029: if ($args->{'collapsible_header'} ne '') {
1.1427 raeburn 7030: $collapsible = 1;
7031: my ($menustate,$tiptext,$divclass);
7032: if ($args->{'start_collapsed'}) {
7033: $menustate = 'collapsed';
7034: $tiptext = 'display';
7035: $divclass = 'hidden';
7036: } else {
7037: $menustate = 'expanded';
7038: $tiptext = 'hide';
7039: $divclass = 'shown';
7040: }
7041: my $alttext = &mt('menu state: '.$menustate);
7042: my $tooltip = &mt($tiptext.' standard menus');
1.1421 raeburn 7043: $bodytag .= <<"END";
1.1461 raeburn 7044: <div id="LC_expandingContainer" style="display:inline;" role="navigation">
1.1421 raeburn 7045: <div id="LC_collapsible" class="LC_collapse_trigger" style="position: absolute;top: -5px;left: 0px; z-index:101; display:inline;">
1.1427 raeburn 7046: <a href="#" style="text-decoration:none;"><img class="LC_collapsible_indicator" alt="$alttext" title="$tooltip" src="/res/adm/pages/$menustate.png" style="border:0;margin:0;padding:0;max-width:100%;height:auto" /></a></div>
7047: <div class="LC_menus_content $divclass">
1.1421 raeburn 7048: END
7049: }
1.1318 raeburn 7050: unless ($args->{'no_primary_menu'}) {
1.1369 raeburn 7051: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
1.1380 raeburn 7052: $args->{'links_disabled'},
1.1421 raeburn 7053: $args->{'links_target'},
1.1427 raeburn 7054: $collapsible);
1.1454 raeburn 7055: my $labeltext = &HTML::Entities::encode(&mt('Primary links'));
1.1318 raeburn 7056: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
7057: if ($dc_info) {
7058: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
7059: }
1.1456 raeburn 7060: $bodytag .= qq|<div id="LC_nav_bar" role="navigation" aria-label="$labeltext">$left $role</div>|;
1.1454 raeburn 7061: unless (($realm eq '') && ($dc_info eq '')) {
7062: $bodytag .= qq|<div id="LC_realm" role="complementary"><em>$realm</em> $dc_info</div>|;
7063: }
1.1440 raeburn 7064: if ($need_endlcint) {
7065: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
7066: }
1.1318 raeburn 7067: return $bodytag;
7068: }
1.894 droeschl 7069:
1.1457 raeburn 7070: $bodytag .= '<div class="LC_landmark" style="margin: 3px 0 0 0;" role="navigation" aria-label="'.$labeltext.'">';
1.1318 raeburn 7071: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
7072: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
7073: }
1.916 droeschl 7074:
1.1454 raeburn 7075: $bodytag .= $right.'</div>';
1.852 droeschl 7076:
1.1318 raeburn 7077: if ($dc_info) {
7078: $dc_info = &dc_courseid_toggle($dc_info);
7079: }
1.1454 raeburn 7080: unless (($realm eq '') && ($dc_info eq '')) {
1.1457 raeburn 7081: $bodytag .= qq|<div id="LC_realm" role="complementary">$realm $dc_info</div>|;
1.1454 raeburn 7082: }
1.1457 raeburn 7083: $bodytag .= qq|<div style="clear: both; margin: 5px 0 0 0;"></div>|;
1.917 raeburn 7084: }
1.916 droeschl 7085:
1.1169 raeburn 7086: #if directed to not display the secondary menu, don't.
1.1168 raeburn 7087: if ($args->{'no_secondary_menu'}) {
1.1440 raeburn 7088: if ($need_endlcint) {
7089: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
7090: }
1.1168 raeburn 7091: return $bodytag;
7092: }
1.1169 raeburn 7093: #don't show menus for public users
1.954 raeburn 7094: if (!$public){
1.1318 raeburn 7095: unless ($args->{'no_inline_menu'}) {
1.1459 raeburn 7096: $bodytag .= '<div class="LC_landmark" role="navigation" aria-label="Secondary Links">'.
7097: Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
1.1359 raeburn 7098: $args->{'no_primary_menu'},
1.1369 raeburn 7099: $menucoll,$menuref,
1.1380 raeburn 7100: $args->{'links_disabled'},
1.1459 raeburn 7101: $args->{'links_target'}).
1.1460 raeburn 7102: '</div>';
1.1318 raeburn 7103: }
1.903 droeschl 7104: $bodytag .= Apache::lonmenu::serverform();
1.1440 raeburn 7105: if ($need_endlcint) {
7106: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
7107: }
1.920 raeburn 7108: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 7109: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1385 raeburn 7110: $args->{'bread_crumbs'},'','',$hostname,
7111: $ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 7112: } elsif ($forcereg) {
7113: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1385 raeburn 7114: $args->{'group'},$args->{'hide_buttons'},
7115: $hostname,$ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 7116: } else {
1.1459 raeburn 7117: $bodytag .=
1.1096 raeburn 7118: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
7119: $forcereg,$args->{'group'},
7120: $args->{'bread_crumbs'},
1.1274 raeburn 7121: $advtoolsref,'',$hostname);
1.920 raeburn 7122: }
1.1440 raeburn 7123: } else {
7124: # this is to separate menu from content when there's no secondary
1.1441 raeburn 7125: # menu. Especially needed for publicly accessible resources.
1.1459 raeburn 7126: $bodytag .= '<hr style="clear:both" role="complementary" />';
1.1440 raeburn 7127: if ($need_endlcint) {
7128: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
7129: }
1.235 raeburn 7130: }
1.1423 raeburn 7131: if ($args->{'collapsible_header'} ne '') {
7132: $bodytag .= $args->{'collapsible_header'}.
7133: '<div id="LC_collapsible_separator"></div>'.
1.1421 raeburn 7134: '</div></div>';
7135: }
1.235 raeburn 7136: return $bodytag;
1.182 matthew 7137: }
7138:
1.917 raeburn 7139: sub dc_courseid_toggle {
7140: my ($dc_info) = @_;
1.980 raeburn 7141: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 7142: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 7143: &mt('(More ...)').'</a></span>'.
7144: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
7145: }
7146:
1.330 albertel 7147: sub make_attr_string {
7148: my ($register,$attr_ref) = @_;
7149:
7150: if ($attr_ref && !ref($attr_ref)) {
7151: die("addentries Must be a hash ref ".
7152: join(':',caller(1))." ".
7153: join(':',caller(0))." ");
7154: }
7155:
7156: if ($register) {
1.339 albertel 7157: my ($on_load,$on_unload);
7158: foreach my $key (keys(%{$attr_ref})) {
7159: if (lc($key) eq 'onload') {
7160: $on_load.=$attr_ref->{$key}.';';
7161: delete($attr_ref->{$key});
7162:
7163: } elsif (lc($key) eq 'onunload') {
7164: $on_unload.=$attr_ref->{$key}.';';
7165: delete($attr_ref->{$key});
7166: }
7167: }
1.953 droeschl 7168: $attr_ref->{'onload'} = $on_load;
7169: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 7170: }
1.339 albertel 7171:
1.330 albertel 7172: my $attr_string;
1.1159 raeburn 7173: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 7174: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
7175: }
7176: return $attr_string;
7177: }
7178:
7179:
1.182 matthew 7180: ###############################################
1.251 albertel 7181: ###############################################
7182:
7183: =pod
7184:
7185: =item * &endbodytag()
7186:
7187: Returns a uniform footer for LON-CAPA web pages.
7188:
1.635 raeburn 7189: Inputs: 1 - optional reference to an args hash
7190: If in the hash, key for noredirectlink has a value which evaluates to true,
7191: a 'Continue' link is not displayed if the page contains an
7192: internal redirect in the <head></head> section,
7193: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 7194:
7195: =cut
7196:
7197: sub endbodytag {
1.635 raeburn 7198: my ($args) = @_;
1.1080 raeburn 7199: my $endbodytag;
7200: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
7201: $endbodytag='</body>';
7202: }
1.315 albertel 7203: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 7204: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
1.1386 raeburn 7205: my ($endbodyjs,$idattr);
7206: if ($env{'internal.head.to_opener'}) {
7207: my $linkid = 'LC_continue_link';
7208: $idattr = ' id="'.$linkid.'"';
7209: my $redirect_for_js = &js_escape($env{'internal.head.redirect'});
7210: $endbodyjs=<<ENDJS;
7211: <script type="text/javascript">
7212: // <![CDATA[
7213: function ebFunction(evt) {
7214: evt.preventDefault();
7215: var dest = '$redirect_for_js';
7216: if (window.opener != null && !window.opener.closed) {
7217: window.opener.location.href=dest;
7218: window.close();
7219: } else {
7220: window.location.href=dest;
7221: }
7222: return false;
7223: }
7224:
7225: \$(document).ready(function () {
7226: if (document.getElementById('$linkid')) {
7227: var clickelem = document.getElementById('$linkid');
7228: clickelem.addEventListener('click',ebFunction,false);
7229: }
7230: });
7231: // ]]>
7232: </script>
7233: ENDJS
7234: }
1.635 raeburn 7235: $endbodytag=
1.1386 raeburn 7236: "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".
1.635 raeburn 7237: &mt('Continue').'</a>'.
7238: $endbodytag;
7239: }
1.315 albertel 7240: }
1.1411 raeburn 7241: if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
7242: $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
7243: }
1.251 albertel 7244: return $endbodytag;
7245: }
7246:
1.352 albertel 7247: =pod
7248:
7249: =item * &standard_css()
7250:
7251: Returns a style sheet
7252:
7253: Inputs: (all optional)
7254: domain -> force to color decorate a page for a specific
7255: domain
7256: function -> force usage of a specific rolish color scheme
7257: bgcolor -> override the default page bgcolor
7258:
7259: =cut
7260:
1.343 albertel 7261: sub standard_css {
1.345 albertel 7262: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 7263: $function = &get_users_function() if (!$function);
7264: my $tabbg = &designparm($function.'.tabbg', $domain);
7265: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 7266: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 7267: #second colour for later usage
1.345 albertel 7268: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 7269: my $pgbg_or_bgcolor =
7270: $bgcolor ||
1.352 albertel 7271: &designparm($function.'.pgbg', $domain);
1.382 albertel 7272: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 7273: my $alink = &designparm($function.'.alink', $domain);
7274: my $vlink = &designparm($function.'.vlink', $domain);
7275: my $link = &designparm($function.'.link', $domain);
7276:
1.602 albertel 7277: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 7278: my $mono = 'monospace';
1.850 bisitz 7279: my $data_table_head = $sidebg;
7280: my $data_table_light = '#FAFAFA';
1.1060 bisitz 7281: my $data_table_dark = '#E0E0E0';
1.470 banghart 7282: my $data_table_darker = '#CCCCCC';
1.349 albertel 7283: my $data_table_highlight = '#FFFF00';
1.352 albertel 7284: my $mail_new = '#FFBB77';
7285: my $mail_new_hover = '#DD9955';
7286: my $mail_read = '#BBBB77';
7287: my $mail_read_hover = '#999944';
7288: my $mail_replied = '#AAAA88';
7289: my $mail_replied_hover = '#888855';
7290: my $mail_other = '#99BBBB';
7291: my $mail_other_hover = '#669999';
1.391 albertel 7292: my $table_header = '#DDDDDD';
1.489 raeburn 7293: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 7294: my $lg_border_color = '#C8C8C8';
1.952 onken 7295: my $button_hover = '#BF2317';
1.392 albertel 7296:
1.608 albertel 7297: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 7298: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
7299: : '0 3px 0 4px';
1.448 albertel 7300:
1.523 albertel 7301:
1.343 albertel 7302: return <<END;
1.947 droeschl 7303:
7304: /* needed for iframe to allow 100% height in FF */
7305: body, html {
7306: margin: 0;
7307: padding: 0 0.5%;
7308: height: 99%; /* to avoid scrollbars */
7309: }
7310:
1.795 www 7311: body {
1.911 bisitz 7312: font-family: $sans;
7313: line-height:130%;
7314: font-size:0.83em;
7315: color:$font;
1.1436 raeburn 7316: background-color: $pgbg_or_bgcolor;
1.795 www 7317: }
7318:
1.959 onken 7319: a:focus,
7320: a:focus img {
1.795 www 7321: color: red;
7322: }
1.698 harmsja 7323:
1.911 bisitz 7324: form, .inline {
7325: display: inline;
1.795 www 7326: }
1.721 harmsja 7327:
1.1453 raeburn 7328: .LC_landmark {
7329: margin: 0;
7330: padding: 0;
7331: border: none;
7332: }
7333:
1.1443 raeburn 7334: .LC_visually_hidden:not(:focus):not(:active) {
7335: clip-path: inset(50%);
7336: height: 1px;
7337: overflow: hidden;
7338: position: absolute;
7339: white-space: nowrap;
7340: width: 1px;
7341: display: inline;
7342: }
7343:
1.1453 raeburn 7344: .LC_heading_2 {
7345: font-size: 1.17em;
7346: }
7347:
1.1458 raeburn 7348: .LC_heading_3 {
7349: font-size: 1.0em;
7350: }
7351:
1.1421 raeburn 7352: .LC_menus_content.shown{
1.1428 raeburn 7353: display: block;
1.1421 raeburn 7354: }
7355:
7356: .LC_menus_content.hidden {
7357: display: none;
7358: }
7359:
1.795 www 7360: .LC_right {
1.911 bisitz 7361: text-align:right;
1.795 www 7362: }
7363:
1.1449 raeburn 7364: .LC_center {
7365: text-align:center;
7366: }
7367:
1.795 www 7368: .LC_middle {
1.911 bisitz 7369: vertical-align:middle;
1.795 www 7370: }
1.721 harmsja 7371:
1.1130 raeburn 7372: .LC_floatleft {
7373: float: left;
7374: }
7375:
7376: .LC_floatright {
7377: float: right;
7378: }
7379:
1.911 bisitz 7380: .LC_400Box {
7381: width:400px;
7382: }
1.721 harmsja 7383:
1.1421 raeburn 7384: #LC_collapsible_separator {
7385: border: 1px solid black;
7386: width: 99.9%;
7387: height: 0px;
7388: }
7389:
1.947 droeschl 7390: .LC_iframecontainer {
7391: width: 98%;
7392: margin: 0;
7393: position: fixed;
7394: top: 8.5em;
7395: bottom: 0;
7396: }
7397:
7398: .LC_iframecontainer iframe{
7399: border: none;
7400: width: 100%;
7401: height: 100%;
7402: }
7403:
1.778 bisitz 7404: .LC_filename {
7405: font-family: $mono;
7406: white-space:pre;
1.921 bisitz 7407: font-size: 120%;
1.778 bisitz 7408: }
7409:
7410: .LC_fileicon {
7411: border: none;
7412: height: 1.3em;
7413: vertical-align: text-bottom;
7414: margin-right: 0.3em;
7415: text-decoration:none;
7416: }
7417:
1.1008 www 7418: .LC_setting {
7419: text-decoration:underline;
7420: }
7421:
1.350 albertel 7422: .LC_error {
7423: color: red;
7424: }
1.795 www 7425:
1.1097 bisitz 7426: .LC_warning {
7427: color: darkorange;
7428: }
7429:
1.457 albertel 7430: .LC_diff_removed {
1.733 bisitz 7431: color: red;
1.394 albertel 7432: }
1.532 albertel 7433:
7434: .LC_info,
1.457 albertel 7435: .LC_success,
7436: .LC_diff_added {
1.350 albertel 7437: color: green;
7438: }
1.795 www 7439:
1.802 bisitz 7440: div.LC_confirm_box {
7441: background-color: #FAFAFA;
7442: border: 1px solid $lg_border_color;
7443: margin-right: 0;
7444: padding: 5px;
7445: }
7446:
7447: div.LC_confirm_box .LC_error img,
7448: div.LC_confirm_box .LC_success img {
7449: vertical-align: middle;
7450: }
7451:
1.1242 raeburn 7452: .LC_maxwidth {
7453: max-width: 100%;
7454: height: auto;
7455: }
7456:
1.1243 raeburn 7457: .LC_textsize_mobile {
7458: \@media only screen and (max-device-width: 480px) {
7459: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
7460: }
7461: }
7462:
1.440 albertel 7463: .LC_icon {
1.771 droeschl 7464: border: none;
1.790 droeschl 7465: vertical-align: middle;
1.771 droeschl 7466: }
7467:
1.543 albertel 7468: .LC_docs_spacer {
7469: width: 25px;
7470: height: 1px;
1.771 droeschl 7471: border: none;
1.543 albertel 7472: }
1.346 albertel 7473:
1.532 albertel 7474: .LC_internal_info {
1.735 bisitz 7475: color: #999999;
1.532 albertel 7476: }
7477:
1.794 www 7478: .LC_discussion {
1.1050 www 7479: background: $data_table_dark;
1.911 bisitz 7480: border: 1px solid black;
7481: margin: 2px;
1.794 www 7482: }
7483:
7484: .LC_disc_action_left {
1.1050 www 7485: background: $sidebg;
1.911 bisitz 7486: text-align: left;
1.1050 www 7487: padding: 4px;
7488: margin: 2px;
1.794 www 7489: }
7490:
7491: .LC_disc_action_right {
1.1050 www 7492: background: $sidebg;
1.911 bisitz 7493: text-align: right;
1.1050 www 7494: padding: 4px;
7495: margin: 2px;
1.794 www 7496: }
7497:
7498: .LC_disc_new_item {
1.911 bisitz 7499: background: white;
7500: border: 2px solid red;
1.1050 www 7501: margin: 4px;
7502: padding: 4px;
1.794 www 7503: }
7504:
7505: .LC_disc_old_item {
1.911 bisitz 7506: background: white;
1.1050 www 7507: margin: 4px;
7508: padding: 4px;
1.794 www 7509: }
7510:
1.1468 raeburn 7511: .LC_pastsubmission {
1.458 albertel 7512: border: 1px solid black;
7513: margin: 2px;
1.1468 raeburn 7514: padding: 2px;
1.458 albertel 7515: }
7516:
1.924 bisitz 7517: table#LC_menubuttons {
1.345 albertel 7518: width: 100%;
7519: background: $pgbg;
1.392 albertel 7520: border: 2px;
1.402 albertel 7521: border-collapse: separate;
1.803 bisitz 7522: padding: 0;
1.345 albertel 7523: }
1.392 albertel 7524:
1.801 tempelho 7525: table#LC_title_bar a {
7526: color: $fontmenu;
7527: }
1.836 bisitz 7528:
1.807 droeschl 7529: table#LC_title_bar {
1.819 tempelho 7530: clear: both;
1.836 bisitz 7531: display: none;
1.807 droeschl 7532: }
7533:
1.795 www 7534: table#LC_title_bar,
1.933 droeschl 7535: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 7536: table#LC_title_bar.LC_with_remote {
1.359 albertel 7537: width: 100%;
1.392 albertel 7538: border-color: $pgbg;
7539: border-style: solid;
7540: border-width: $border;
1.379 albertel 7541: background: $pgbg;
1.801 tempelho 7542: color: $fontmenu;
1.392 albertel 7543: border-collapse: collapse;
1.803 bisitz 7544: padding: 0;
1.819 tempelho 7545: margin: 0;
1.359 albertel 7546: }
1.795 www 7547:
1.933 droeschl 7548: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 7549: margin: 0;
7550: padding: 0;
1.933 droeschl 7551: position: relative;
7552: list-style: none;
1.913 droeschl 7553: }
1.933 droeschl 7554: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 7555: display: inline;
7556: }
1.933 droeschl 7557:
7558: .LC_breadcrumb_tools_navigation {
1.913 droeschl 7559: padding: 0;
1.933 droeschl 7560: margin: 0;
7561: float: left;
1.913 droeschl 7562: }
1.933 droeschl 7563: .LC_breadcrumb_tools_tools {
7564: padding: 0;
7565: margin: 0;
1.913 droeschl 7566: float: right;
7567: }
7568:
1.1240 raeburn 7569: .LC_placement_prog {
7570: padding-right: 20px;
7571: font-weight: bold;
7572: font-size: 90%;
7573: }
7574:
1.359 albertel 7575: table#LC_title_bar td {
7576: background: $tabbg;
7577: }
1.795 www 7578:
1.911 bisitz 7579: table#LC_menubuttons img {
1.803 bisitz 7580: border: none;
1.346 albertel 7581: }
1.795 www 7582:
1.842 droeschl 7583: .LC_breadcrumbs_component {
1.911 bisitz 7584: float: right;
7585: margin: 0 1em;
1.357 albertel 7586: }
1.842 droeschl 7587: .LC_breadcrumbs_component img {
1.911 bisitz 7588: vertical-align: middle;
1.777 tempelho 7589: }
1.795 www 7590:
1.1243 raeburn 7591: .LC_breadcrumbs_hoverable {
7592: background: $sidebg;
7593: }
7594:
1.383 albertel 7595: td.LC_table_cell_checkbox {
7596: text-align: center;
7597: }
1.795 www 7598:
7599: .LC_fontsize_small {
1.911 bisitz 7600: font-size: 70%;
1.705 tempelho 7601: }
7602:
1.844 bisitz 7603: #LC_breadcrumbs {
1.911 bisitz 7604: clear:both;
7605: background: $sidebg;
7606: border-bottom: 1px solid $lg_border_color;
7607: line-height: 2.5em;
1.933 droeschl 7608: overflow: hidden;
1.911 bisitz 7609: margin: 0;
7610: padding: 0;
1.995 raeburn 7611: text-align: left;
1.819 tempelho 7612: }
1.862 bisitz 7613:
1.1098 bisitz 7614: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 7615: clear:both;
7616: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 7617: border: 1px solid $sidebg;
1.1098 bisitz 7618: margin: 0 0 10px 0;
1.966 bisitz 7619: padding: 3px;
1.995 raeburn 7620: text-align: left;
1.822 bisitz 7621: }
7622:
1.795 www 7623: .LC_fontsize_medium {
1.911 bisitz 7624: font-size: 85%;
1.705 tempelho 7625: }
7626:
1.795 www 7627: .LC_fontsize_large {
1.911 bisitz 7628: font-size: 120%;
1.705 tempelho 7629: }
7630:
1.346 albertel 7631: .LC_menubuttons_inline_text {
7632: color: $font;
1.698 harmsja 7633: font-size: 90%;
1.701 harmsja 7634: padding-left:3px;
1.346 albertel 7635: }
7636:
1.934 droeschl 7637: .LC_menubuttons_inline_text img{
7638: vertical-align: middle;
7639: }
7640:
1.1051 www 7641: li.LC_menubuttons_inline_text img {
1.951 onken 7642: cursor:pointer;
1.1002 droeschl 7643: text-decoration: none;
1.951 onken 7644: }
7645:
1.526 www 7646: .LC_menubuttons_link {
7647: text-decoration: none;
7648: }
1.795 www 7649:
1.522 albertel 7650: .LC_menubuttons_category {
1.521 www 7651: color: $font;
1.526 www 7652: background: $pgbg;
1.521 www 7653: font-size: larger;
7654: font-weight: bold;
7655: }
7656:
1.346 albertel 7657: td.LC_menubuttons_text {
1.911 bisitz 7658: color: $font;
1.346 albertel 7659: }
1.706 harmsja 7660:
1.346 albertel 7661: .LC_current_location {
7662: background: $tabbg;
7663: }
1.795 www 7664:
1.1286 raeburn 7665: td.LC_zero_height {
7666: line-height: 0;
7667: cellpadding: 0;
7668: }
7669:
1.938 bisitz 7670: table.LC_data_table {
1.347 albertel 7671: border: 1px solid #000000;
1.402 albertel 7672: border-collapse: separate;
1.426 albertel 7673: border-spacing: 1px;
1.610 albertel 7674: background: $pgbg;
1.347 albertel 7675: }
1.795 www 7676:
1.422 albertel 7677: .LC_data_table_dense {
7678: font-size: small;
7679: }
1.795 www 7680:
1.507 raeburn 7681: table.LC_nested_outer {
7682: border: 1px solid #000000;
1.589 raeburn 7683: border-collapse: collapse;
1.803 bisitz 7684: border-spacing: 0;
1.507 raeburn 7685: width: 100%;
7686: }
1.795 www 7687:
1.879 raeburn 7688: table.LC_innerpickbox,
1.507 raeburn 7689: table.LC_nested {
1.803 bisitz 7690: border: none;
1.589 raeburn 7691: border-collapse: collapse;
1.803 bisitz 7692: border-spacing: 0;
1.507 raeburn 7693: width: 100%;
7694: }
1.795 www 7695:
1.911 bisitz 7696: table.LC_data_table tr th,
7697: table.LC_calendar tr th,
1.879 raeburn 7698: table.LC_prior_tries tr th,
7699: table.LC_innerpickbox tr th {
1.349 albertel 7700: font-weight: bold;
7701: background-color: $data_table_head;
1.801 tempelho 7702: color:$fontmenu;
1.701 harmsja 7703: font-size:90%;
1.347 albertel 7704: }
1.795 www 7705:
1.879 raeburn 7706: table.LC_innerpickbox tr th,
7707: table.LC_innerpickbox tr td {
7708: vertical-align: top;
7709: }
7710:
1.711 raeburn 7711: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 7712: background-color: #CCCCCC;
1.711 raeburn 7713: font-weight: bold;
7714: text-align: left;
7715: }
1.795 www 7716:
1.912 bisitz 7717: table.LC_data_table tr.LC_odd_row > td {
7718: background-color: $data_table_light;
7719: padding: 2px;
7720: vertical-align: top;
7721: }
7722:
1.809 bisitz 7723: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 7724: background-color: $data_table_light;
1.912 bisitz 7725: vertical-align: top;
7726: }
7727:
7728: table.LC_data_table tr.LC_even_row > td {
7729: background-color: $data_table_dark;
1.425 albertel 7730: padding: 2px;
1.900 bisitz 7731: vertical-align: top;
1.347 albertel 7732: }
1.795 www 7733:
1.809 bisitz 7734: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 7735: background-color: $data_table_dark;
1.900 bisitz 7736: vertical-align: top;
1.347 albertel 7737: }
1.795 www 7738:
1.425 albertel 7739: table.LC_data_table tr.LC_data_table_highlight td {
7740: background-color: $data_table_darker;
7741: }
1.795 www 7742:
1.639 raeburn 7743: table.LC_data_table tr td.LC_leftcol_header {
7744: background-color: $data_table_head;
7745: font-weight: bold;
7746: }
1.795 www 7747:
1.451 albertel 7748: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 7749: table.LC_nested tr.LC_empty_row td {
1.421 albertel 7750: font-weight: bold;
7751: font-style: italic;
7752: text-align: center;
7753: padding: 8px;
1.347 albertel 7754: }
1.795 www 7755:
1.1114 raeburn 7756: table.LC_data_table tr.LC_empty_row td,
7757: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 7758: background-color: $sidebg;
7759: }
7760:
7761: table.LC_nested tr.LC_empty_row td {
7762: background-color: #FFFFFF;
7763: }
7764:
1.890 droeschl 7765: table.LC_caption {
7766: }
7767:
1.1469 ! raeburn 7768: caption.LC_caption_prefs {
! 7769: font-weight: normal;
! 7770: text-align: left;
! 7771: padding-bottom: 0.8em;
! 7772: }
! 7773:
1.507 raeburn 7774: table.LC_nested tr.LC_empty_row td {
1.465 albertel 7775: padding: 4ex
7776: }
1.795 www 7777:
1.507 raeburn 7778: table.LC_nested_outer tr th {
7779: font-weight: bold;
1.801 tempelho 7780: color:$fontmenu;
1.507 raeburn 7781: background-color: $data_table_head;
1.701 harmsja 7782: font-size: small;
1.507 raeburn 7783: border-bottom: 1px solid #000000;
7784: }
1.795 www 7785:
1.507 raeburn 7786: table.LC_nested_outer tr td.LC_subheader {
7787: background-color: $data_table_head;
7788: font-weight: bold;
7789: font-size: small;
7790: border-bottom: 1px solid #000000;
7791: text-align: right;
1.451 albertel 7792: }
1.795 www 7793:
1.507 raeburn 7794: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7795: background-color: #CCCCCC;
1.451 albertel 7796: font-weight: bold;
7797: font-size: small;
1.507 raeburn 7798: text-align: center;
7799: }
1.795 www 7800:
1.589 raeburn 7801: table.LC_nested tr.LC_info_row td.LC_left_item,
7802: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7803: text-align: left;
1.451 albertel 7804: }
1.795 www 7805:
1.507 raeburn 7806: table.LC_nested td {
1.735 bisitz 7807: background-color: #FFFFFF;
1.451 albertel 7808: font-size: small;
1.507 raeburn 7809: }
1.795 www 7810:
1.507 raeburn 7811: table.LC_nested_outer tr th.LC_right_item,
7812: table.LC_nested tr.LC_info_row td.LC_right_item,
7813: table.LC_nested tr.LC_odd_row td.LC_right_item,
7814: table.LC_nested tr td.LC_right_item {
1.451 albertel 7815: text-align: right;
7816: }
7817:
1.507 raeburn 7818: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7819: background-color: #EEEEEE;
1.451 albertel 7820: }
7821:
1.473 raeburn 7822: table.LC_createuser {
7823: }
7824:
7825: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7826: font-size: small;
1.473 raeburn 7827: }
7828:
7829: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7830: background-color: #CCCCCC;
1.473 raeburn 7831: font-weight: bold;
7832: text-align: center;
7833: }
7834:
1.349 albertel 7835: table.LC_calendar {
7836: border: 1px solid #000000;
7837: border-collapse: collapse;
1.917 raeburn 7838: width: 98%;
1.349 albertel 7839: }
1.795 www 7840:
1.349 albertel 7841: table.LC_calendar_pickdate {
7842: font-size: xx-small;
7843: }
1.795 www 7844:
1.349 albertel 7845: table.LC_calendar tr td {
7846: border: 1px solid #000000;
7847: vertical-align: top;
1.917 raeburn 7848: width: 14%;
1.349 albertel 7849: }
1.795 www 7850:
1.349 albertel 7851: table.LC_calendar tr td.LC_calendar_day_empty {
7852: background-color: $data_table_dark;
7853: }
1.795 www 7854:
1.779 bisitz 7855: table.LC_calendar tr td.LC_calendar_day_current {
7856: background-color: $data_table_highlight;
1.777 tempelho 7857: }
1.795 www 7858:
1.938 bisitz 7859: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7860: background-color: $mail_new;
7861: }
1.795 www 7862:
1.938 bisitz 7863: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7864: background-color: $mail_new_hover;
7865: }
1.795 www 7866:
1.938 bisitz 7867: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7868: background-color: $mail_read;
7869: }
1.795 www 7870:
1.938 bisitz 7871: /*
7872: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7873: background-color: $mail_read_hover;
7874: }
1.938 bisitz 7875: */
1.795 www 7876:
1.938 bisitz 7877: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7878: background-color: $mail_replied;
7879: }
1.795 www 7880:
1.938 bisitz 7881: /*
7882: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7883: background-color: $mail_replied_hover;
7884: }
1.938 bisitz 7885: */
1.795 www 7886:
1.938 bisitz 7887: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7888: background-color: $mail_other;
7889: }
1.795 www 7890:
1.938 bisitz 7891: /*
7892: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7893: background-color: $mail_other_hover;
7894: }
1.938 bisitz 7895: */
1.494 raeburn 7896:
1.777 tempelho 7897: table.LC_data_table tr > td.LC_browser_file,
7898: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7899: background: #AAEE77;
1.389 albertel 7900: }
1.795 www 7901:
1.777 tempelho 7902: table.LC_data_table tr > td.LC_browser_file_locked,
7903: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7904: background: #FFAA99;
1.387 albertel 7905: }
1.795 www 7906:
1.777 tempelho 7907: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7908: background: #888888;
1.779 bisitz 7909: }
1.795 www 7910:
1.777 tempelho 7911: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7912: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7913: background: #F8F866;
1.777 tempelho 7914: }
1.795 www 7915:
1.696 bisitz 7916: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7917: background: #E0E8FF;
1.387 albertel 7918: }
1.696 bisitz 7919:
1.707 bisitz 7920: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7921: /* background: #77FF77; */
1.707 bisitz 7922: }
1.795 www 7923:
1.707 bisitz 7924: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7925: border-right: 8px solid #FFFF77;
1.707 bisitz 7926: }
1.795 www 7927:
1.707 bisitz 7928: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7929: border-right: 8px solid #FFAA77;
1.707 bisitz 7930: }
1.795 www 7931:
1.707 bisitz 7932: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7933: border-right: 8px solid #FF7777;
1.707 bisitz 7934: }
1.795 www 7935:
1.707 bisitz 7936: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7937: border-right: 8px solid #AAFF77;
1.707 bisitz 7938: }
1.795 www 7939:
1.707 bisitz 7940: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7941: border-right: 8px solid #11CC55;
1.707 bisitz 7942: }
7943:
1.1469 ! raeburn 7944: table.LC_data_table tr.LC_prefs_row {
! 7945: line-height: 250%;
! 7946: }
! 7947:
1.388 albertel 7948: span.LC_current_location {
1.701 harmsja 7949: font-size:larger;
1.388 albertel 7950: background: $pgbg;
7951: }
1.387 albertel 7952:
1.1029 www 7953: span.LC_current_nav_location {
7954: font-weight:bold;
7955: background: $sidebg;
7956: }
7957:
1.395 albertel 7958: span.LC_parm_menu_item {
7959: font-size: larger;
7960: }
1.795 www 7961:
1.395 albertel 7962: span.LC_parm_scope_all {
7963: color: red;
7964: }
1.795 www 7965:
1.395 albertel 7966: span.LC_parm_scope_folder {
7967: color: green;
7968: }
1.795 www 7969:
1.395 albertel 7970: span.LC_parm_scope_resource {
7971: color: orange;
7972: }
1.795 www 7973:
1.395 albertel 7974: span.LC_parm_part {
7975: color: blue;
7976: }
1.795 www 7977:
1.911 bisitz 7978: span.LC_parm_folder,
7979: span.LC_parm_symb {
1.395 albertel 7980: font-size: x-small;
7981: font-family: $mono;
7982: color: #AAAAAA;
7983: }
7984:
1.977 bisitz 7985: ul.LC_parm_parmlist li {
7986: display: inline-block;
7987: padding: 0.3em 0.8em;
7988: vertical-align: top;
7989: width: 150px;
7990: border-top:1px solid $lg_border_color;
7991: }
7992:
1.795 www 7993: td.LC_parm_overview_level_menu,
7994: td.LC_parm_overview_map_menu,
7995: td.LC_parm_overview_parm_selectors,
7996: td.LC_parm_overview_restrictions {
1.396 albertel 7997: border: 1px solid black;
7998: border-collapse: collapse;
7999: }
1.795 www 8000:
1.1285 raeburn 8001: span.LC_parm_recursive,
8002: td.LC_parm_recursive {
8003: font-weight: bold;
8004: font-size: smaller;
8005: }
8006:
1.396 albertel 8007: table.LC_parm_overview_restrictions td {
8008: border-width: 1px 4px 1px 4px;
8009: border-style: solid;
8010: border-color: $pgbg;
8011: text-align: center;
8012: }
1.795 www 8013:
1.396 albertel 8014: table.LC_parm_overview_restrictions th {
8015: background: $tabbg;
8016: border-width: 1px 4px 1px 4px;
8017: border-style: solid;
8018: border-color: $pgbg;
8019: }
1.795 www 8020:
1.1459 raeburn 8021: h1.LC_helpmenu {
8022: display: inline;
8023: font-size: 100%;
8024: font-weight: normal;
8025: line-height: 1em;
8026: margin: 0;
8027: padding: 0;
8028: border: 0;
1.398 albertel 8029: }
1.795 www 8030:
1.1456 raeburn 8031: .LC_helpdesk_headbox {
8032: border: 2px groove threedface;
8033: padding: 1em;
8034: }
8035:
8036: h1.LC_helpdesk_legend {
8037: float: left;
8038: margin: -1.7em 0 0;
8039: padding: 0 .5em;
1.397 albertel 8040: background: $pgbg;
1.1456 raeburn 8041: font-size: 1em;
8042: font-weight: bold;
8043: }
8044:
8045: h1.LC_helpdesk_title {
8046: display: inline;
8047: font-size: 1em;
8048: line-height: 2.5em;
8049: margin: 0;
1.803 bisitz 8050: padding: 0;
1.1456 raeburn 8051: vertical-align: bottom;
1.397 albertel 8052: }
1.795 www 8053:
1.1456 raeburn 8054: .LC_helpdesk_links {
8055: border: 1px solid black;
8056: padding: 3px;
1.397 albertel 8057: background: $tabbg;
1.399 albertel 8058: text-align: center;
8059: font-weight: bold;
1.1456 raeburn 8060: display: inline;
8061: margin-right: -6px;
8062: }
8063:
8064: .LC_helpdesk_img,
8065: .LC_helpdesk_text {
8066: padding: 0;
8067: margin: 0;
8068: border: 0;
8069: display: inline;
1.397 albertel 8070: }
1.396 albertel 8071:
1.1456 raeburn 8072: .LC_helpdesk_img a:link,
8073: .LC_helpdesk_img a:visited,
8074: .LC_helpdesk_img a:active,
8075: .LC_helpdesk_text a:link,
8076: .LC_helpdesk_text a:visited,
8077: .LC_helpdesk_text a:active {
1.397 albertel 8078: text-decoration: none;
8079: color: $font;
8080: }
1.795 www 8081:
1.1456 raeburn 8082: div.LC_helpdesk_text a:hover {
1.397 albertel 8083: text-decoration: underline;
8084: color: $vlink;
8085: }
1.396 albertel 8086:
1.417 albertel 8087: .LC_chrt_popup_exists {
8088: border: 1px solid #339933;
8089: margin: -1px;
8090: }
1.795 www 8091:
1.417 albertel 8092: .LC_chrt_popup_up {
8093: border: 1px solid yellow;
8094: margin: -1px;
8095: }
1.795 www 8096:
1.417 albertel 8097: .LC_chrt_popup {
8098: border: 1px solid #8888FF;
8099: background: #CCCCFF;
8100: }
1.795 www 8101:
1.421 albertel 8102: table.LC_pick_box {
8103: border-collapse: separate;
8104: background: white;
8105: border: 1px solid black;
8106: border-spacing: 1px;
8107: }
1.795 www 8108:
1.1454 raeburn 8109: table.LC_pick_box th.LC_pick_box_title {
1.850 bisitz 8110: background: $sidebg;
1.421 albertel 8111: font-weight: bold;
1.900 bisitz 8112: text-align: left;
1.740 bisitz 8113: vertical-align: top;
1.421 albertel 8114: width: 184px;
8115: padding: 8px;
8116: }
1.795 www 8117:
1.579 raeburn 8118: table.LC_pick_box td.LC_pick_box_value {
8119: text-align: left;
8120: padding: 8px;
8121: }
1.795 www 8122:
1.579 raeburn 8123: table.LC_pick_box td.LC_pick_box_select {
8124: text-align: left;
8125: padding: 8px;
8126: }
1.795 www 8127:
1.424 albertel 8128: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 8129: padding: 0;
1.421 albertel 8130: height: 1px;
8131: background: black;
8132: }
1.795 www 8133:
1.421 albertel 8134: table.LC_pick_box td.LC_pick_box_submit {
8135: text-align: right;
8136: }
1.795 www 8137:
1.579 raeburn 8138: table.LC_pick_box td.LC_evenrow_value {
8139: text-align: left;
8140: padding: 8px;
8141: background-color: $data_table_light;
8142: }
1.795 www 8143:
1.579 raeburn 8144: table.LC_pick_box td.LC_oddrow_value {
8145: text-align: left;
8146: padding: 8px;
8147: background-color: $data_table_light;
8148: }
1.795 www 8149:
1.579 raeburn 8150: span.LC_helpform_receipt_cat {
8151: font-weight: bold;
8152: }
1.795 www 8153:
1.424 albertel 8154: table.LC_group_priv_box {
8155: background: white;
8156: border: 1px solid black;
8157: border-spacing: 1px;
8158: }
1.795 www 8159:
1.424 albertel 8160: table.LC_group_priv_box td.LC_pick_box_title {
8161: background: $tabbg;
8162: font-weight: bold;
8163: text-align: right;
8164: width: 184px;
8165: }
1.795 www 8166:
1.424 albertel 8167: table.LC_group_priv_box td.LC_groups_fixed {
8168: background: $data_table_light;
8169: text-align: center;
8170: }
1.795 www 8171:
1.424 albertel 8172: table.LC_group_priv_box td.LC_groups_optional {
8173: background: $data_table_dark;
8174: text-align: center;
8175: }
1.795 www 8176:
1.424 albertel 8177: table.LC_group_priv_box td.LC_groups_functionality {
8178: background: $data_table_darker;
8179: text-align: center;
8180: font-weight: bold;
8181: }
1.795 www 8182:
1.424 albertel 8183: table.LC_group_priv td {
8184: text-align: left;
1.803 bisitz 8185: padding: 0;
1.424 albertel 8186: }
8187:
8188: .LC_navbuttons {
8189: margin: 2ex 0ex 2ex 0ex;
8190: }
1.795 www 8191:
1.423 albertel 8192: .LC_topic_bar {
8193: font-weight: bold;
8194: background: $tabbg;
1.918 wenzelju 8195: margin: 1em 0em 1em 2em;
1.805 bisitz 8196: padding: 3px;
1.918 wenzelju 8197: font-size: 1.2em;
1.423 albertel 8198: }
1.795 www 8199:
1.423 albertel 8200: .LC_topic_bar span {
1.918 wenzelju 8201: left: 0.5em;
8202: position: absolute;
1.423 albertel 8203: vertical-align: middle;
1.918 wenzelju 8204: font-size: 1.2em;
1.423 albertel 8205: }
1.795 www 8206:
1.423 albertel 8207: table.LC_course_group_status {
8208: margin: 20px;
8209: }
1.795 www 8210:
1.423 albertel 8211: table.LC_status_selector td {
8212: vertical-align: top;
8213: text-align: center;
1.424 albertel 8214: padding: 4px;
8215: }
1.795 www 8216:
1.599 albertel 8217: div.LC_feedback_link {
1.616 albertel 8218: clear: both;
1.829 kalberla 8219: background: $sidebg;
1.779 bisitz 8220: width: 100%;
1.829 kalberla 8221: padding-bottom: 10px;
8222: border: 1px $tabbg solid;
1.833 kalberla 8223: height: 22px;
8224: line-height: 22px;
8225: padding-top: 5px;
8226: }
8227:
8228: div.LC_feedback_link img {
8229: height: 22px;
1.867 kalberla 8230: vertical-align:middle;
1.829 kalberla 8231: }
8232:
1.911 bisitz 8233: div.LC_feedback_link a {
1.829 kalberla 8234: text-decoration: none;
1.489 raeburn 8235: }
1.795 www 8236:
1.867 kalberla 8237: div.LC_comblock {
1.911 bisitz 8238: display:inline;
1.867 kalberla 8239: color:$font;
8240: font-size:90%;
8241: }
8242:
8243: div.LC_feedback_link div.LC_comblock {
8244: padding-left:5px;
8245: }
8246:
8247: div.LC_feedback_link div.LC_comblock a {
8248: color:$font;
8249: }
8250:
1.489 raeburn 8251: span.LC_feedback_link {
1.858 bisitz 8252: /* background: $feedback_link_bg; */
1.599 albertel 8253: font-size: larger;
8254: }
1.795 www 8255:
1.599 albertel 8256: span.LC_message_link {
1.858 bisitz 8257: /* background: $feedback_link_bg; */
1.599 albertel 8258: font-size: larger;
8259: position: absolute;
8260: right: 1em;
1.489 raeburn 8261: }
1.421 albertel 8262:
1.515 albertel 8263: table.LC_prior_tries {
1.524 albertel 8264: border: 1px solid #000000;
8265: border-collapse: separate;
8266: border-spacing: 1px;
1.515 albertel 8267: }
1.523 albertel 8268:
1.515 albertel 8269: table.LC_prior_tries td {
1.524 albertel 8270: padding: 2px;
1.515 albertel 8271: }
1.523 albertel 8272:
8273: .LC_answer_correct {
1.795 www 8274: background: lightgreen;
8275: color: darkgreen;
8276: padding: 6px;
1.523 albertel 8277: }
1.795 www 8278:
1.523 albertel 8279: .LC_answer_charged_try {
1.797 www 8280: background: #FFAAAA;
1.795 www 8281: color: darkred;
8282: padding: 6px;
1.523 albertel 8283: }
1.795 www 8284:
1.779 bisitz 8285: .LC_answer_not_charged_try,
1.523 albertel 8286: .LC_answer_no_grade,
8287: .LC_answer_late {
1.795 www 8288: background: lightyellow;
1.523 albertel 8289: color: black;
1.795 www 8290: padding: 6px;
1.523 albertel 8291: }
1.795 www 8292:
1.523 albertel 8293: .LC_answer_previous {
1.795 www 8294: background: lightblue;
8295: color: darkblue;
8296: padding: 6px;
1.523 albertel 8297: }
1.795 www 8298:
1.779 bisitz 8299: .LC_answer_no_message {
1.777 tempelho 8300: background: #FFFFFF;
8301: color: black;
1.795 www 8302: padding: 6px;
1.779 bisitz 8303: }
1.795 www 8304:
1.1334 raeburn 8305: .LC_answer_unknown,
8306: .LC_answer_warning {
1.779 bisitz 8307: background: orange;
8308: color: black;
1.795 www 8309: padding: 6px;
1.777 tempelho 8310: }
1.795 www 8311:
1.1467 raeburn 8312: span.LC_prob_status {
8313: margin: 5px 0 0 0;
8314: padding: 0 5px 0 0;
8315: vertical-align: middle;
8316: }
8317:
8318: div.LC_prob_status_outer {
8319: display: inline-block;
8320: margin: -5px 0 0 0;
8321: padding: 0;
8322: }
8323:
8324: div.LC_prob_status_inner {
8325: display: inline-block;
8326: margin: 0 5px 0 0;
8327: padding: 5px;
1.1446 raeburn 8328: }
8329:
1.1468 raeburn 8330: caption.LC_filesub_status {
8331: text-align: left;
8332: font-weight: bold;
8333: }
8334:
1.1448 raeburn 8335: .LC_mail_actions {
8336: float: left;
8337: padding: 0;
8338: margin: 6px;
8339: }
8340:
8341: .LC_vertical_line {
8342: width: 1px;
8343: background-color: black;
8344: height: 4em;
8345: float: left;
8346: margin: 0;
8347: padding: 0;
8348: }
8349:
1.529 albertel 8350: span.LC_prior_numerical,
8351: span.LC_prior_string,
8352: span.LC_prior_custom,
8353: span.LC_prior_reaction,
8354: span.LC_prior_math {
1.925 bisitz 8355: font-family: $mono;
1.523 albertel 8356: white-space: pre;
8357: }
8358:
1.525 albertel 8359: span.LC_prior_string {
1.925 bisitz 8360: font-family: $mono;
1.525 albertel 8361: white-space: pre;
8362: }
8363:
1.523 albertel 8364: table.LC_prior_option {
8365: width: 100%;
8366: border-collapse: collapse;
8367: }
1.795 www 8368:
1.911 bisitz 8369: table.LC_prior_rank,
1.795 www 8370: table.LC_prior_match {
1.528 albertel 8371: border-collapse: collapse;
8372: }
1.795 www 8373:
1.528 albertel 8374: table.LC_prior_option tr td,
8375: table.LC_prior_rank tr td,
8376: table.LC_prior_match tr td {
1.524 albertel 8377: border: 1px solid #000000;
1.515 albertel 8378: }
8379:
1.855 bisitz 8380: .LC_nobreak {
1.544 albertel 8381: white-space: nowrap;
1.519 raeburn 8382: }
8383:
1.576 raeburn 8384: span.LC_cusr_emph {
8385: font-style: italic;
8386: }
8387:
1.633 raeburn 8388: span.LC_cusr_subheading {
8389: font-weight: normal;
8390: font-size: 85%;
8391: }
8392:
1.861 bisitz 8393: div.LC_docs_entry_move {
1.859 bisitz 8394: border: 1px solid #BBBBBB;
1.545 albertel 8395: background: #DDDDDD;
1.861 bisitz 8396: width: 22px;
1.859 bisitz 8397: padding: 1px;
8398: margin: 0;
1.545 albertel 8399: }
8400:
1.861 bisitz 8401: table.LC_data_table tr > td.LC_docs_entry_commands,
8402: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 8403: font-size: x-small;
8404: }
1.795 www 8405:
1.861 bisitz 8406: .LC_docs_entry_parameter {
8407: white-space: nowrap;
8408: }
8409:
1.544 albertel 8410: .LC_docs_copy {
1.545 albertel 8411: color: #000099;
1.544 albertel 8412: }
1.795 www 8413:
1.544 albertel 8414: .LC_docs_cut {
1.545 albertel 8415: color: #550044;
1.544 albertel 8416: }
1.795 www 8417:
1.544 albertel 8418: .LC_docs_rename {
1.545 albertel 8419: color: #009900;
1.544 albertel 8420: }
1.795 www 8421:
1.544 albertel 8422: .LC_docs_remove {
1.545 albertel 8423: color: #990000;
8424: }
8425:
1.1284 raeburn 8426: .LC_docs_alias {
8427: color: #440055;
8428: }
8429:
1.1286 raeburn 8430: .LC_domprefs_email,
1.1284 raeburn 8431: .LC_docs_alias_name,
1.547 albertel 8432: .LC_docs_reinit_warn,
8433: .LC_docs_ext_edit {
8434: font-size: x-small;
8435: }
8436:
1.545 albertel 8437: table.LC_docs_adddocs td,
8438: table.LC_docs_adddocs th {
8439: border: 1px solid #BBBBBB;
8440: padding: 4px;
8441: background: #DDDDDD;
1.543 albertel 8442: }
8443:
1.584 albertel 8444: table.LC_sty_begin {
8445: background: #BBFFBB;
8446: }
1.795 www 8447:
1.584 albertel 8448: table.LC_sty_end {
8449: background: #FFBBBB;
8450: }
8451:
1.589 raeburn 8452: table.LC_double_column {
1.803 bisitz 8453: border-width: 0;
1.589 raeburn 8454: border-collapse: collapse;
8455: width: 100%;
8456: padding: 2px;
8457: }
8458:
8459: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 8460: top: 2px;
1.589 raeburn 8461: left: 2px;
8462: width: 47%;
8463: vertical-align: top;
8464: }
8465:
8466: table.LC_double_column tr td.LC_right_col {
8467: top: 2px;
1.779 bisitz 8468: right: 2px;
1.589 raeburn 8469: width: 47%;
8470: vertical-align: top;
8471: }
8472:
1.591 raeburn 8473: div.LC_left_float {
8474: float: left;
8475: padding-right: 5%;
1.597 albertel 8476: padding-bottom: 4px;
1.591 raeburn 8477: }
8478:
8479: div.LC_clear_float_header {
1.597 albertel 8480: padding-bottom: 2px;
1.591 raeburn 8481: }
8482:
8483: div.LC_clear_float_footer {
1.597 albertel 8484: padding-top: 10px;
1.591 raeburn 8485: clear: both;
8486: }
8487:
1.597 albertel 8488: div.LC_grade_show_user {
1.941 bisitz 8489: /* border-left: 5px solid $sidebg; */
8490: border-top: 5px solid #000000;
8491: margin: 50px 0 0 0;
1.936 bisitz 8492: padding: 15px 0 5px 10px;
1.597 albertel 8493: }
1.795 www 8494:
1.936 bisitz 8495: div.LC_grade_show_user_odd_row {
1.941 bisitz 8496: /* border-left: 5px solid #000000; */
8497: }
8498:
8499: div.LC_grade_show_user div.LC_Box {
8500: margin-right: 50px;
1.597 albertel 8501: }
8502:
1.1461 raeburn 8503: div.LC_grade_show_user div.LC_Box table tr th {
8504: font-weight: normal;
8505: }
8506:
1.597 albertel 8507: div.LC_grade_submissions,
8508: div.LC_grade_message_center,
1.936 bisitz 8509: div.LC_grade_info_links {
1.597 albertel 8510: margin: 5px;
8511: width: 99%;
8512: background: #FFFFFF;
8513: }
1.795 www 8514:
1.597 albertel 8515: div.LC_grade_submissions_header,
1.936 bisitz 8516: div.LC_grade_message_center_header {
1.705 tempelho 8517: font-weight: bold;
8518: font-size: large;
1.597 albertel 8519: }
1.795 www 8520:
1.597 albertel 8521: div.LC_grade_submissions_body,
1.936 bisitz 8522: div.LC_grade_message_center_body {
1.597 albertel 8523: border: 1px solid black;
8524: width: 99%;
8525: background: #FFFFFF;
8526: }
1.795 www 8527:
1.613 albertel 8528: table.LC_scantron_action {
8529: width: 100%;
8530: }
1.795 www 8531:
1.613 albertel 8532: table.LC_scantron_action tr th {
1.698 harmsja 8533: font-weight:bold;
8534: font-style:normal;
1.613 albertel 8535: }
1.795 www 8536:
1.1461 raeburn 8537: div.LC_edit_problem_daxe_header {
8538: padding: 3px;
8539: background: $tabbg;
8540: z-index: 100;
8541: }
8542:
1.779 bisitz 8543: .LC_edit_problem_header,
1.614 albertel 8544: div.LC_edit_problem_footer {
1.705 tempelho 8545: font-weight: normal;
8546: font-size: medium;
1.602 albertel 8547: margin: 2px;
1.1060 bisitz 8548: background-color: $sidebg;
1.600 albertel 8549: }
1.795 www 8550:
1.600 albertel 8551: div.LC_edit_problem_header,
1.602 albertel 8552: div.LC_edit_problem_header div,
1.614 albertel 8553: div.LC_edit_problem_footer,
8554: div.LC_edit_problem_footer div,
1.602 albertel 8555: div.LC_edit_problem_editxml_header,
8556: div.LC_edit_problem_editxml_header div {
1.1205 golterma 8557: z-index: 100;
1.600 albertel 8558: }
1.795 www 8559:
1.600 albertel 8560: div.LC_edit_problem_header_title {
1.705 tempelho 8561: font-weight: bold;
8562: font-size: larger;
1.602 albertel 8563: background: $tabbg;
8564: padding: 3px;
1.1060 bisitz 8565: margin: 0 0 5px 0;
1.602 albertel 8566: }
1.795 www 8567:
1.602 albertel 8568: table.LC_edit_problem_header_title {
8569: width: 100%;
1.600 albertel 8570: background: $tabbg;
1.602 albertel 8571: }
8572:
1.1205 golterma 8573: div.LC_edit_actionbar {
8574: background-color: $sidebg;
1.1218 droeschl 8575: margin: 0;
8576: padding: 0;
8577: line-height: 200%;
1.602 albertel 8578: }
1.795 www 8579:
1.1218 droeschl 8580: div.LC_edit_actionbar div{
8581: padding: 0;
8582: margin: 0;
8583: display: inline-block;
1.600 albertel 8584: }
1.795 www 8585:
1.1124 bisitz 8586: .LC_edit_opt {
8587: padding-left: 1em;
8588: white-space: nowrap;
8589: }
8590:
1.1152 golterma 8591: .LC_edit_problem_latexhelper{
8592: text-align: right;
8593: }
8594:
8595: #LC_edit_problem_colorful div{
8596: margin-left: 40px;
8597: }
8598:
1.1205 golterma 8599: #LC_edit_problem_codemirror div{
8600: margin-left: 0px;
8601: }
8602:
1.911 bisitz 8603: img.stift {
1.803 bisitz 8604: border-width: 0;
8605: vertical-align: middle;
1.677 riegler 8606: }
1.680 riegler 8607:
1.1460 raeburn 8608: div.LC_mainmenu {
8609: margin: 3px 2px 2px 1px;
8610: float: left;
1.777 tempelho 8611: }
1.795 www 8612:
1.716 raeburn 8613: div.LC_createcourse {
1.911 bisitz 8614: margin: 10px 10px 10px 10px;
1.716 raeburn 8615: }
8616:
1.917 raeburn 8617: .LC_dccid {
1.1130 raeburn 8618: float: right;
1.917 raeburn 8619: margin: 0.2em 0 0 0;
8620: padding: 0;
8621: font-size: 90%;
8622: display:none;
8623: }
8624:
1.897 wenzelju 8625: ol.LC_primary_menu a:hover,
1.721 harmsja 8626: ol#LC_MenuBreadcrumbs a:hover,
8627: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 8628: ul#LC_secondary_menu a:hover,
1.721 harmsja 8629: .LC_FormSectionClearButton input:hover
1.795 www 8630: ul.LC_TabContent li:hover a {
1.952 onken 8631: color:$button_hover;
1.911 bisitz 8632: text-decoration:none;
1.693 droeschl 8633: }
8634:
1.779 bisitz 8635: h1 {
1.911 bisitz 8636: padding: 0;
8637: line-height:130%;
1.693 droeschl 8638: }
1.698 harmsja 8639:
1.911 bisitz 8640: h2,
8641: h3,
8642: h4,
8643: h5,
8644: h6 {
8645: margin: 5px 0 5px 0;
8646: padding: 0;
8647: line-height:130%;
1.693 droeschl 8648: }
1.795 www 8649:
8650: .LC_hcell {
1.911 bisitz 8651: padding:3px 15px 3px 15px;
8652: margin: 0;
8653: background-color:$tabbg;
8654: color:$fontmenu;
8655: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 8656: }
1.795 www 8657:
1.840 bisitz 8658: .LC_Box > .LC_hcell {
1.911 bisitz 8659: margin: 0 -10px 10px -10px;
1.835 bisitz 8660: }
8661:
1.721 harmsja 8662: .LC_noBorder {
1.911 bisitz 8663: border: 0;
1.698 harmsja 8664: }
1.693 droeschl 8665:
1.721 harmsja 8666: .LC_FormSectionClearButton input {
1.911 bisitz 8667: background-color:transparent;
8668: border: none;
8669: cursor:pointer;
8670: text-decoration:underline;
1.693 droeschl 8671: }
1.763 bisitz 8672:
8673: .LC_help_open_topic {
1.911 bisitz 8674: color: #FFFFFF;
8675: background-color: #EEEEFF;
8676: margin: 1px;
8677: padding: 4px;
8678: border: 1px solid #000033;
8679: white-space: nowrap;
8680: /* vertical-align: middle; */
1.759 neumanie 8681: }
1.693 droeschl 8682:
1.911 bisitz 8683: dl,
8684: ul,
8685: div,
8686: fieldset {
8687: margin: 10px 10px 10px 0;
8688: /* overflow: hidden; */
1.693 droeschl 8689: }
1.795 www 8690:
1.1404 raeburn 8691: fieldset#LC_selectuser {
1.1460 raeburn 8692: margin: -1px 0 0 0;
8693: padding: 0;
8694: border: 0;
1.1404 raeburn 8695: }
8696:
1.1211 raeburn 8697: article.geogebraweb div {
8698: margin: 0;
8699: }
8700:
1.838 bisitz 8701: fieldset > legend {
1.911 bisitz 8702: font-weight: bold;
8703: padding: 0 5px 0 5px;
1.838 bisitz 8704: }
8705:
1.813 bisitz 8706: #LC_nav_bar {
1.911 bisitz 8707: float: left;
1.995 raeburn 8708: background-color: $pgbg_or_bgcolor;
1.966 bisitz 8709: margin: 0 0 2px 0;
1.807 droeschl 8710: }
8711:
1.916 droeschl 8712: #LC_realm {
8713: margin: 0.2em 0 0 0;
8714: padding: 0;
8715: font-weight: bold;
8716: text-align: center;
1.995 raeburn 8717: background-color: $pgbg_or_bgcolor;
1.916 droeschl 8718: }
8719:
1.911 bisitz 8720: #LC_nav_bar em {
8721: font-weight: bold;
8722: font-style: normal;
1.807 droeschl 8723: }
8724:
1.897 wenzelju 8725: ol.LC_primary_menu {
1.934 droeschl 8726: margin: 0;
1.1076 raeburn 8727: padding: 0;
1.807 droeschl 8728: }
8729:
1.852 droeschl 8730: ol#LC_PathBreadcrumbs {
1.911 bisitz 8731: margin: 0;
1.693 droeschl 8732: }
8733:
1.897 wenzelju 8734: ol.LC_primary_menu li {
1.1076 raeburn 8735: color: RGB(80, 80, 80);
8736: vertical-align: middle;
8737: text-align: left;
8738: list-style: none;
1.1205 golterma 8739: position: relative;
1.1076 raeburn 8740: float: left;
1.1205 golterma 8741: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
8742: line-height: 1.5em;
1.1076 raeburn 8743: }
8744:
1.1205 golterma 8745: ol.LC_primary_menu li a,
8746: ol.LC_primary_menu li p {
1.1076 raeburn 8747: display: block;
8748: margin: 0;
8749: padding: 0 5px 0 10px;
8750: text-decoration: none;
8751: }
8752:
1.1205 golterma 8753: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
8754: display: inline-block;
8755: width: 95%;
8756: text-align: left;
8757: }
8758:
8759: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
8760: display: inline-block;
8761: width: 5%;
8762: float: right;
8763: text-align: right;
8764: font-size: 70%;
8765: }
8766:
8767: ol.LC_primary_menu ul {
1.1076 raeburn 8768: display: none;
1.1205 golterma 8769: width: 15em;
1.1076 raeburn 8770: background-color: $data_table_light;
1.1205 golterma 8771: position: absolute;
8772: top: 100%;
1.1076 raeburn 8773: }
8774:
1.1205 golterma 8775: ol.LC_primary_menu ul ul {
8776: left: 100%;
8777: top: 0;
8778: }
8779:
8780: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 8781: display: block;
8782: position: absolute;
8783: margin: 0;
8784: padding: 0;
1.1078 raeburn 8785: z-index: 2;
1.1076 raeburn 8786: }
8787:
8788: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 8789: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 8790: font-size: 90%;
1.911 bisitz 8791: vertical-align: top;
1.1076 raeburn 8792: float: none;
1.1079 raeburn 8793: border-left: 1px solid black;
8794: border-right: 1px solid black;
1.1205 golterma 8795: /* A dark bottom border to visualize different menu options;
8796: overwritten in the create_submenu routine for the last border-bottom of the menu */
8797: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 8798: }
8799:
1.1205 golterma 8800: ol.LC_primary_menu li li p:hover {
8801: color:$button_hover;
8802: text-decoration:none;
8803: background-color:$data_table_dark;
1.1076 raeburn 8804: }
8805:
8806: ol.LC_primary_menu li li a:hover {
8807: color:$button_hover;
8808: background-color:$data_table_dark;
1.693 droeschl 8809: }
8810:
1.1205 golterma 8811: /* Font-size equal to the size of the predecessors*/
8812: ol.LC_primary_menu li:hover li li {
8813: font-size: 100%;
8814: }
8815:
1.897 wenzelju 8816: ol.LC_primary_menu li img {
1.911 bisitz 8817: vertical-align: bottom;
1.934 droeschl 8818: height: 1.1em;
1.1077 raeburn 8819: margin: 0.2em 0 0 0;
1.693 droeschl 8820: }
8821:
1.897 wenzelju 8822: ol.LC_primary_menu a {
1.911 bisitz 8823: color: RGB(80, 80, 80);
8824: text-decoration: none;
1.693 droeschl 8825: }
1.795 www 8826:
1.949 droeschl 8827: ol.LC_primary_menu a.LC_new_message {
8828: font-weight:bold;
8829: color: darkred;
8830: }
8831:
1.975 raeburn 8832: ol.LC_docs_parameters {
8833: margin-left: 0;
8834: padding: 0;
8835: list-style: none;
8836: }
8837:
8838: ol.LC_docs_parameters li {
8839: margin: 0;
8840: padding-right: 20px;
8841: display: inline;
8842: }
8843:
1.976 raeburn 8844: ol.LC_docs_parameters li:before {
8845: content: "\\002022 \\0020";
8846: }
8847:
8848: li.LC_docs_parameters_title {
8849: font-weight: bold;
8850: }
8851:
8852: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
8853: content: "";
8854: }
8855:
1.897 wenzelju 8856: ul#LC_secondary_menu {
1.1107 raeburn 8857: clear: right;
1.911 bisitz 8858: color: $fontmenu;
8859: background: $tabbg;
8860: list-style: none;
8861: padding: 0;
8862: margin: 0;
8863: width: 100%;
1.995 raeburn 8864: text-align: left;
1.1107 raeburn 8865: float: left;
1.808 droeschl 8866: }
8867:
1.897 wenzelju 8868: ul#LC_secondary_menu li {
1.911 bisitz 8869: font-weight: bold;
8870: line-height: 1.8em;
1.1107 raeburn 8871: border-right: 1px solid black;
8872: float: left;
8873: }
8874:
8875: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
8876: background-color: $data_table_light;
8877: }
8878:
8879: ul#LC_secondary_menu li a {
1.911 bisitz 8880: padding: 0 0.8em;
1.1107 raeburn 8881: }
8882:
8883: ul#LC_secondary_menu li ul {
8884: display: none;
8885: }
8886:
8887: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8888: display: block;
8889: position: absolute;
8890: margin: 0;
8891: padding: 0;
8892: list-style:none;
8893: float: none;
8894: background-color: $data_table_light;
8895: z-index: 2;
8896: margin-left: -1px;
8897: }
8898:
8899: ul#LC_secondary_menu li ul li {
8900: font-size: 90%;
8901: vertical-align: top;
8902: border-left: 1px solid black;
1.911 bisitz 8903: border-right: 1px solid black;
1.1119 raeburn 8904: background-color: $data_table_light;
1.1107 raeburn 8905: list-style:none;
8906: float: none;
8907: }
8908:
8909: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8910: background-color: $data_table_dark;
1.807 droeschl 8911: }
8912:
1.847 tempelho 8913: ul.LC_TabContent {
1.911 bisitz 8914: display:block;
8915: background: $sidebg;
8916: border-bottom: solid 1px $lg_border_color;
8917: list-style:none;
1.1020 raeburn 8918: margin: -1px -10px 0 -10px;
1.911 bisitz 8919: padding: 0;
1.693 droeschl 8920: }
8921:
1.795 www 8922: ul.LC_TabContent li,
8923: ul.LC_TabContentBigger li {
1.911 bisitz 8924: float:left;
1.741 harmsja 8925: }
1.795 www 8926:
1.897 wenzelju 8927: ul#LC_secondary_menu li a {
1.911 bisitz 8928: color: $fontmenu;
8929: text-decoration: none;
1.693 droeschl 8930: }
1.795 www 8931:
1.721 harmsja 8932: ul.LC_TabContent {
1.952 onken 8933: min-height:20px;
1.721 harmsja 8934: }
1.795 www 8935:
8936: ul.LC_TabContent li {
1.911 bisitz 8937: vertical-align:middle;
1.959 onken 8938: padding: 0 16px 0 10px;
1.911 bisitz 8939: background-color:$tabbg;
8940: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8941: border-left: solid 1px $font;
1.721 harmsja 8942: }
1.795 www 8943:
1.847 tempelho 8944: ul.LC_TabContent .right {
1.911 bisitz 8945: float:right;
1.847 tempelho 8946: }
8947:
1.911 bisitz 8948: ul.LC_TabContent li a,
8949: ul.LC_TabContent li {
8950: color:rgb(47,47,47);
8951: text-decoration:none;
8952: font-size:95%;
8953: font-weight:bold;
1.952 onken 8954: min-height:20px;
8955: }
8956:
1.959 onken 8957: ul.LC_TabContent li a:hover,
8958: ul.LC_TabContent li a:focus {
1.952 onken 8959: color: $button_hover;
1.959 onken 8960: background:none;
8961: outline:none;
1.952 onken 8962: }
8963:
8964: ul.LC_TabContent li:hover {
8965: color: $button_hover;
8966: cursor:pointer;
1.721 harmsja 8967: }
1.795 www 8968:
1.911 bisitz 8969: ul.LC_TabContent li.active {
1.952 onken 8970: color: $font;
1.911 bisitz 8971: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8972: border-bottom:solid 1px #FFFFFF;
8973: cursor: default;
1.744 ehlerst 8974: }
1.795 www 8975:
1.959 onken 8976: ul.LC_TabContent li.active a {
8977: color:$font;
8978: background:#FFFFFF;
8979: outline: none;
8980: }
1.1047 raeburn 8981:
8982: ul.LC_TabContent li.goback {
8983: float: left;
8984: border-left: none;
8985: }
8986:
1.870 tempelho 8987: #maincoursedoc {
1.911 bisitz 8988: clear:both;
1.870 tempelho 8989: }
8990:
8991: ul.LC_TabContentBigger {
1.911 bisitz 8992: display:block;
8993: list-style:none;
8994: padding: 0;
1.870 tempelho 8995: }
8996:
1.795 www 8997: ul.LC_TabContentBigger li {
1.911 bisitz 8998: vertical-align:bottom;
8999: height: 30px;
9000: font-size:110%;
9001: font-weight:bold;
9002: color: #737373;
1.841 tempelho 9003: }
9004:
1.957 onken 9005: ul.LC_TabContentBigger li.active {
9006: position: relative;
9007: top: 1px;
9008: }
9009:
1.870 tempelho 9010: ul.LC_TabContentBigger li a {
1.911 bisitz 9011: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
9012: height: 30px;
9013: line-height: 30px;
9014: text-align: center;
9015: display: block;
9016: text-decoration: none;
1.958 onken 9017: outline: none;
1.741 harmsja 9018: }
1.795 www 9019:
1.870 tempelho 9020: ul.LC_TabContentBigger li.active a {
1.911 bisitz 9021: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
9022: color:$font;
1.744 ehlerst 9023: }
1.795 www 9024:
1.870 tempelho 9025: ul.LC_TabContentBigger li b {
1.911 bisitz 9026: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
9027: display: block;
9028: float: left;
9029: padding: 0 30px;
1.957 onken 9030: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 9031: }
9032:
1.956 onken 9033: ul.LC_TabContentBigger li:hover b {
9034: color:$button_hover;
9035: }
9036:
1.870 tempelho 9037: ul.LC_TabContentBigger li.active b {
1.911 bisitz 9038: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
9039: color:$font;
1.957 onken 9040: border: 0;
1.741 harmsja 9041: }
1.693 droeschl 9042:
1.870 tempelho 9043:
1.862 bisitz 9044: ul.LC_CourseBreadcrumbs {
9045: background: $sidebg;
1.1020 raeburn 9046: height: 2em;
1.862 bisitz 9047: padding-left: 10px;
1.1020 raeburn 9048: margin: 0;
1.862 bisitz 9049: list-style-position: inside;
9050: }
9051:
1.911 bisitz 9052: ol#LC_MenuBreadcrumbs,
1.862 bisitz 9053: ol#LC_PathBreadcrumbs {
1.911 bisitz 9054: padding-left: 10px;
9055: margin: 0;
1.933 droeschl 9056: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 9057: }
9058:
1.911 bisitz 9059: ol#LC_MenuBreadcrumbs li,
9060: ol#LC_PathBreadcrumbs li,
1.862 bisitz 9061: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 9062: display: inline;
1.933 droeschl 9063: white-space: normal;
1.693 droeschl 9064: }
9065:
1.823 bisitz 9066: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 9067: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 9068: text-decoration: none;
9069: font-size:90%;
1.693 droeschl 9070: }
1.795 www 9071:
1.969 droeschl 9072: ol#LC_MenuBreadcrumbs h1 {
9073: display: inline;
9074: font-size: 90%;
9075: line-height: 2.5em;
9076: margin: 0;
9077: padding: 0;
9078: }
9079:
1.795 www 9080: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 9081: text-decoration:none;
9082: font-size:100%;
9083: font-weight:bold;
1.693 droeschl 9084: }
1.795 www 9085:
1.840 bisitz 9086: .LC_Box {
1.911 bisitz 9087: border: solid 1px $lg_border_color;
9088: padding: 0 10px 10px 10px;
1.746 neumanie 9089: }
1.795 www 9090:
1.1020 raeburn 9091: .LC_DocsBox {
9092: border: solid 1px $lg_border_color;
9093: padding: 0 0 10px 10px;
9094: }
9095:
1.795 www 9096: .LC_AboutMe_Image {
1.911 bisitz 9097: float:left;
9098: margin-right:10px;
1.747 neumanie 9099: }
1.795 www 9100:
9101: .LC_Clear_AboutMe_Image {
1.911 bisitz 9102: clear:left;
1.747 neumanie 9103: }
1.795 www 9104:
1.721 harmsja 9105: dl.LC_ListStyleClean dt {
1.911 bisitz 9106: padding-right: 5px;
9107: display: table-header-group;
1.693 droeschl 9108: }
9109:
1.721 harmsja 9110: dl.LC_ListStyleClean dd {
1.911 bisitz 9111: display: table-row;
1.693 droeschl 9112: }
9113:
1.721 harmsja 9114: .LC_ListStyleClean,
9115: .LC_ListStyleSimple,
9116: .LC_ListStyleNormal,
1.795 www 9117: .LC_ListStyleSpecial {
1.911 bisitz 9118: /* display:block; */
9119: list-style-position: inside;
9120: list-style-type: none;
9121: overflow: hidden;
9122: padding: 0;
1.693 droeschl 9123: }
9124:
1.721 harmsja 9125: .LC_ListStyleSimple li,
9126: .LC_ListStyleSimple dd,
9127: .LC_ListStyleNormal li,
9128: .LC_ListStyleNormal dd,
9129: .LC_ListStyleSpecial li,
1.795 www 9130: .LC_ListStyleSpecial dd {
1.911 bisitz 9131: margin: 0;
9132: padding: 5px 5px 5px 10px;
9133: clear: both;
1.693 droeschl 9134: }
9135:
1.721 harmsja 9136: .LC_ListStyleClean li,
9137: .LC_ListStyleClean dd {
1.911 bisitz 9138: padding-top: 0;
9139: padding-bottom: 0;
1.693 droeschl 9140: }
9141:
1.721 harmsja 9142: .LC_ListStyleSimple dd,
1.795 www 9143: .LC_ListStyleSimple li {
1.911 bisitz 9144: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 9145: }
9146:
1.721 harmsja 9147: .LC_ListStyleSpecial li,
9148: .LC_ListStyleSpecial dd {
1.911 bisitz 9149: list-style-type: none;
9150: background-color: RGB(220, 220, 220);
9151: margin-bottom: 4px;
1.693 droeschl 9152: }
9153:
1.721 harmsja 9154: table.LC_SimpleTable {
1.911 bisitz 9155: margin:5px;
9156: border:solid 1px $lg_border_color;
1.795 www 9157: }
1.693 droeschl 9158:
1.721 harmsja 9159: table.LC_SimpleTable tr {
1.911 bisitz 9160: padding: 0;
9161: border:solid 1px $lg_border_color;
1.693 droeschl 9162: }
1.795 www 9163:
9164: table.LC_SimpleTable thead {
1.911 bisitz 9165: background:rgb(220,220,220);
1.693 droeschl 9166: }
9167:
1.721 harmsja 9168: div.LC_columnSection {
1.911 bisitz 9169: display: block;
9170: clear: both;
9171: overflow: hidden;
9172: margin: 0;
1.693 droeschl 9173: }
9174:
1.721 harmsja 9175: div.LC_columnSection>* {
1.911 bisitz 9176: float: left;
9177: margin: 10px 20px 10px 0;
9178: overflow:hidden;
1.693 droeschl 9179: }
1.721 harmsja 9180:
1.795 www 9181: table em {
1.911 bisitz 9182: font-weight: bold;
9183: font-style: normal;
1.748 schulted 9184: }
1.795 www 9185:
1.779 bisitz 9186: table.LC_tableBrowseRes,
1.795 www 9187: table.LC_tableOfContent {
1.911 bisitz 9188: border:none;
9189: border-spacing: 1px;
9190: padding: 3px;
9191: background-color: #FFFFFF;
9192: font-size: 90%;
1.753 droeschl 9193: }
1.789 droeschl 9194:
1.911 bisitz 9195: table.LC_tableOfContent {
9196: border-collapse: collapse;
1.789 droeschl 9197: }
9198:
1.771 droeschl 9199: table.LC_tableBrowseRes a,
1.768 schulted 9200: table.LC_tableOfContent a {
1.911 bisitz 9201: background-color: transparent;
9202: text-decoration: none;
1.753 droeschl 9203: }
9204:
1.795 www 9205: table.LC_tableOfContent img {
1.911 bisitz 9206: border: none;
9207: height: 1.3em;
9208: vertical-align: text-bottom;
9209: margin-right: 0.3em;
1.753 droeschl 9210: }
1.757 schulted 9211:
1.795 www 9212: a#LC_content_toolbar_firsthomework {
1.911 bisitz 9213: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 9214: }
9215:
1.795 www 9216: a#LC_content_toolbar_everything {
1.911 bisitz 9217: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 9218: }
9219:
1.795 www 9220: a#LC_content_toolbar_uncompleted {
1.911 bisitz 9221: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 9222: }
9223:
1.795 www 9224: #LC_content_toolbar_clearbubbles {
1.911 bisitz 9225: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 9226: }
9227:
1.795 www 9228: a#LC_content_toolbar_changefolder {
1.911 bisitz 9229: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 9230: }
9231:
1.795 www 9232: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 9233: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 9234: }
9235:
1.1043 raeburn 9236: a#LC_content_toolbar_edittoplevel {
9237: background-image:url(/res/adm/pages/edittoplevel.gif);
9238: }
9239:
1.1384 raeburn 9240: a#LC_content_toolbar_printout {
9241: background-image:url(/res/adm/pages/printout.gif);
9242: }
9243:
1.795 www 9244: ul#LC_toolbar li a:hover {
1.911 bisitz 9245: background-position: bottom center;
1.757 schulted 9246: }
9247:
1.795 www 9248: ul#LC_toolbar {
1.911 bisitz 9249: padding: 0;
9250: margin: 2px;
9251: list-style:none;
1.1449 raeburn 9252: display:inline;
1.911 bisitz 9253: background-color:white;
1.1082 raeburn 9254: overflow: auto;
1.757 schulted 9255: }
9256:
1.795 www 9257: ul#LC_toolbar li {
1.911 bisitz 9258: border:1px solid white;
9259: padding: 0;
9260: margin: 0;
9261: float: left;
9262: display:inline;
9263: vertical-align:middle;
1.1082 raeburn 9264: white-space: nowrap;
1.911 bisitz 9265: }
1.757 schulted 9266:
1.783 amueller 9267:
1.795 www 9268: a.LC_toolbarItem {
1.911 bisitz 9269: display:block;
9270: padding: 0;
9271: margin: 0;
9272: height: 32px;
9273: width: 32px;
9274: color:white;
9275: border: none;
9276: background-repeat:no-repeat;
9277: background-color:transparent;
1.757 schulted 9278: }
9279:
1.1449 raeburn 9280: .LC_navtools {
9281: display: inline-block;
9282: padding: 0;
9283: margin: 2px;
9284: vertical-align: middle;
9285: }
9286:
1.915 droeschl 9287: ul.LC_funclist {
9288: margin: 0;
9289: padding: 0.5em 1em 0.5em 0;
9290: }
9291:
1.933 droeschl 9292: ul.LC_funclist > li:first-child {
9293: font-weight:bold;
9294: margin-left:0.8em;
9295: }
9296:
1.915 droeschl 9297: ul.LC_funclist + ul.LC_funclist {
9298: /*
9299: left border as a seperator if we have more than
9300: one list
9301: */
9302: border-left: 1px solid $sidebg;
9303: /*
9304: this hides the left border behind the border of the
9305: outer box if element is wrapped to the next 'line'
9306: */
9307: margin-left: -1px;
9308: }
9309:
1.843 bisitz 9310: ul.LC_funclist li {
1.915 droeschl 9311: display: inline;
1.782 bisitz 9312: white-space: nowrap;
1.915 droeschl 9313: margin: 0 0 0 25px;
9314: line-height: 150%;
1.782 bisitz 9315: }
9316:
1.974 wenzelju 9317: .LC_hidden {
9318: display: none;
9319: }
9320:
1.1030 www 9321: .LCmodal-overlay {
9322: position:fixed;
9323: top:0;
9324: right:0;
9325: bottom:0;
9326: left:0;
9327: height:100%;
9328: width:100%;
9329: margin:0;
9330: padding:0;
9331: background:#999;
9332: opacity:.75;
9333: filter: alpha(opacity=75);
9334: -moz-opacity: 0.75;
9335: z-index:101;
9336: }
9337:
9338: * html .LCmodal-overlay {
9339: position: absolute;
9340: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
9341: }
9342:
9343: .LCmodal-window {
9344: position:fixed;
9345: top:50%;
9346: left:50%;
9347: margin:0;
9348: padding:0;
9349: z-index:102;
9350: }
9351:
9352: * html .LCmodal-window {
9353: position:absolute;
9354: }
9355:
9356: .LCclose-window {
9357: position:absolute;
9358: width:32px;
9359: height:32px;
9360: right:8px;
9361: top:8px;
9362: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
9363: text-indent:-99999px;
9364: overflow:hidden;
9365: cursor:pointer;
9366: }
9367:
1.1369 raeburn 9368: .LCisDisabled {
9369: cursor: not-allowed;
9370: opacity: 0.5;
9371: }
9372:
9373: a[aria-disabled="true"] {
9374: color: currentColor;
9375: display: inline-block; /* For IE11/ MS Edge bug */
9376: pointer-events: none;
9377: text-decoration: none;
9378: }
9379:
1.1335 raeburn 9380: pre.LC_wordwrap {
9381: white-space: pre-wrap;
9382: white-space: -moz-pre-wrap;
9383: white-space: -pre-wrap;
9384: white-space: -o-pre-wrap;
9385: word-wrap: break-word;
9386: }
9387:
1.1100 raeburn 9388: /*
1.1231 damieng 9389: styles used for response display
9390: */
1.1464 raeburn 9391: div.LC_radiofoil, div.LC_rankfoil, div.LC_optionfoil, div.LC_matchfoil, div.LC_login_links {
1.1231 damieng 9392: margin: .5em 0em .5em 0em;
9393: }
9394: table.LC_itemgroup {
9395: margin-top: 1em;
9396: }
9397:
1.1462 raeburn 9398: table.LC_itemgroup tr th {
9399: font-weight: normal;
9400: }
9401:
9402: fieldset.LC_webbubbles {
9403: margin: 2px 0 0 0;
9404: padding: 0;
9405: border: 0;
9406: }
9407:
9408: ul.LC_webbubbles {
9409: list-style: none;
9410: padding: 0;
9411: margin: 0;
9412: text-align: left;
9413: float: left;
9414: }
9415:
9416: ul.LC_webbubbles li {
9417: line-height: 1.8em;
9418: border: 1px solid black;
9419: padding: 0 2px 0 5px;
9420: margin: 0 0 0 -1px;
9421: float: left;
9422: }
9423:
1.1231 damieng 9424: /*
1.1100 raeburn 9425: styles used by TTH when "Default set of options to pass to tth/m
9426: when converting TeX" in course settings has been set
9427:
9428: option passed: -t
9429:
9430: */
9431:
9432: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
9433: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
9434: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
9435: td div.norm {line-height:normal;}
9436:
9437: /*
9438: option passed -y3
9439: */
9440:
9441: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
9442: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
9443: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
9444:
1.1230 damieng 9445: /*
9446: sections with roles, for content only
9447: */
9448: section[class^="role-"] {
9449: padding-left: 10px;
9450: padding-right: 5px;
9451: margin-top: 8px;
9452: margin-bottom: 8px;
9453: border: 1px solid #2A4;
9454: border-radius: 5px;
9455: box-shadow: 0px 1px 1px #BBB;
9456: }
9457: section[class^="role-"]>h1 {
9458: position: relative;
9459: margin: 0px;
9460: padding-top: 10px;
9461: padding-left: 40px;
9462: }
9463: section[class^="role-"]>h1:before {
9464: position: absolute;
9465: left: -5px;
9466: top: 5px;
9467: }
9468: section.role-activity>h1:before {
9469: content:url('/adm/daxe/images/section_icons/activity.png');
9470: }
9471: section.role-advice>h1:before {
9472: content:url('/adm/daxe/images/section_icons/advice.png');
9473: }
9474: section.role-bibliography>h1:before {
9475: content:url('/adm/daxe/images/section_icons/bibliography.png');
9476: }
9477: section.role-citation>h1:before {
9478: content:url('/adm/daxe/images/section_icons/citation.png');
9479: }
9480: section.role-conclusion>h1:before {
9481: content:url('/adm/daxe/images/section_icons/conclusion.png');
9482: }
9483: section.role-definition>h1:before {
9484: content:url('/adm/daxe/images/section_icons/definition.png');
9485: }
9486: section.role-demonstration>h1:before {
9487: content:url('/adm/daxe/images/section_icons/demonstration.png');
9488: }
9489: section.role-example>h1:before {
9490: content:url('/adm/daxe/images/section_icons/example.png');
9491: }
9492: section.role-explanation>h1:before {
9493: content:url('/adm/daxe/images/section_icons/explanation.png');
9494: }
9495: section.role-introduction>h1:before {
9496: content:url('/adm/daxe/images/section_icons/introduction.png');
9497: }
9498: section.role-method>h1:before {
9499: content:url('/adm/daxe/images/section_icons/method.png');
9500: }
9501: section.role-more_information>h1:before {
9502: content:url('/adm/daxe/images/section_icons/more_information.png');
9503: }
9504: section.role-objectives>h1:before {
9505: content:url('/adm/daxe/images/section_icons/objectives.png');
9506: }
9507: section.role-prerequisites>h1:before {
9508: content:url('/adm/daxe/images/section_icons/prerequisites.png');
9509: }
9510: section.role-remark>h1:before {
9511: content:url('/adm/daxe/images/section_icons/remark.png');
9512: }
9513: section.role-reminder>h1:before {
9514: content:url('/adm/daxe/images/section_icons/reminder.png');
9515: }
9516: section.role-summary>h1:before {
9517: content:url('/adm/daxe/images/section_icons/summary.png');
9518: }
9519: section.role-syntax>h1:before {
9520: content:url('/adm/daxe/images/section_icons/syntax.png');
9521: }
9522: section.role-warning>h1:before {
9523: content:url('/adm/daxe/images/section_icons/warning.png');
9524: }
9525:
1.1269 raeburn 9526: #LC_minitab_header {
9527: float:left;
9528: width:100%;
9529: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
9530: font-size:93%;
9531: line-height:normal;
9532: margin: 0.5em 0 0.5em 0;
9533: }
9534: #LC_minitab_header ul {
9535: margin:0;
9536: padding:10px 10px 0;
9537: list-style:none;
9538: }
9539: #LC_minitab_header li {
9540: float:left;
9541: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
9542: margin:0;
9543: padding:0 0 0 9px;
9544: }
9545: #LC_minitab_header a {
9546: display:block;
9547: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
9548: padding:5px 15px 4px 6px;
9549: }
9550: #LC_minitab_header #LC_current_minitab {
9551: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
9552: }
9553: #LC_minitab_header #LC_current_minitab a {
9554: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
9555: padding-bottom:5px;
9556: }
9557:
9558:
1.343 albertel 9559: END
9560: }
9561:
1.306 albertel 9562: =pod
9563:
9564: =item * &headtag()
9565:
9566: Returns a uniform footer for LON-CAPA web pages.
9567:
1.307 albertel 9568: Inputs: $title - optional title for the head
9569: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 9570: $args - optional arguments
1.319 albertel 9571: force_register - if is true call registerurl so the remote is
9572: informed
1.415 albertel 9573: redirect -> array ref of
9574: 1- seconds before redirect occurs
9575: 2- url to redirect to
9576: 3- whether the side effect should occur
1.315 albertel 9577: (side effect of setting
9578: $env{'internal.head.redirect'} to the url
1.1386 raeburn 9579: redirected to)
9580: 4- whether the redirect target should be
9581: the opener of the current (pop-up)
9582: window (side effect of setting
9583: $env{'internal.head.to_opener'} to
9584: 1, if true.
1.1388 raeburn 9585: 5- whether encrypt check should be skipped
1.352 albertel 9586: domain -> force to color decorate a page for a specific
9587: domain
9588: function -> force usage of a specific rolish color scheme
9589: bgcolor -> override the default page bgcolor
1.460 albertel 9590: no_auto_mt_title
9591: -> prevent &mt()ing the title arg
1.464 albertel 9592:
1.306 albertel 9593: =cut
9594:
9595: sub headtag {
1.313 albertel 9596: my ($title,$head_extra,$args) = @_;
1.306 albertel 9597:
1.363 albertel 9598: my $function = $args->{'function'} || &get_users_function();
9599: my $domain = $args->{'domain'} || &determinedomain();
9600: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 9601: my $httphost = $args->{'use_absolute'};
1.418 albertel 9602: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 9603: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 9604: #time(),
1.418 albertel 9605: $env{'environment.color.timestamp'},
1.363 albertel 9606: $function,$domain,$bgcolor);
9607:
1.369 www 9608: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 9609:
1.308 albertel 9610: my $result =
9611: '<head>'.
1.1160 raeburn 9612: &font_settings($args);
1.319 albertel 9613:
1.1188 raeburn 9614: my $inhibitprint;
9615: if ($args->{'print_suppress'}) {
9616: $inhibitprint = &print_suppression();
9617: }
1.1064 raeburn 9618:
1.1439 raeburn 9619: if (!$args->{'frameset'} && !$args->{'switchserver'}) {
1.461 albertel 9620: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
9621: }
1.962 droeschl 9622: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
9623: $result .= Apache::lonxml::display_title();
1.319 albertel 9624: }
1.436 albertel 9625: if (!$args->{'no_nav_bar'}
9626: && !$args->{'only_body'}
1.1438 raeburn 9627: && !$args->{'frameset'}
9628: && !$args->{'switchserver'}) {
1.1154 raeburn 9629: $result .= &help_menu_js($httphost);
1.1032 www 9630: $result.=&modal_window();
1.1038 www 9631: $result.=&togglebox_script();
1.1034 www 9632: $result.=&wishlist_window();
1.1041 www 9633: $result.=&LCprogressbarUpdate_script();
1.1034 www 9634: } else {
9635: if ($args->{'add_modal'}) {
9636: $result.=&modal_window();
9637: }
9638: if ($args->{'add_wishlist'}) {
9639: $result.=&wishlist_window();
9640: }
1.1038 www 9641: if ($args->{'add_togglebox'}) {
9642: $result.=&togglebox_script();
9643: }
1.1041 www 9644: if ($args->{'add_progressbar'}) {
9645: $result.=&LCprogressbarUpdate_script();
9646: }
1.436 albertel 9647: }
1.314 albertel 9648: if (ref($args->{'redirect'})) {
1.1388 raeburn 9649: my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
9650: if (!$skip_enc_check) {
9651: $url = &Apache::lonenc::check_encrypt($url);
9652: }
1.414 albertel 9653: if (!$inhibit_continue) {
9654: $env{'internal.head.redirect'} = $url;
9655: }
1.1386 raeburn 9656: $result.=<<"ADDMETA";
1.313 albertel 9657: <meta http-equiv="pragma" content="no-cache" />
1.1386 raeburn 9658: ADDMETA
9659: if ($to_opener) {
9660: $env{'internal.head.to_opener'} = 1;
9661: my $dest = &js_escape($url);
9662: my $timeout = int($time * 1000);
9663: $result .=<<"ENDJS";
9664: <script type="text/javascript">
9665: // <![CDATA[
9666: function LC_To_Opener() {
9667: var dest = '$dest';
9668: if (dest != '') {
9669: if (window.opener != null && !window.opener.closed) {
9670: window.opener.location.href=dest;
9671: window.close();
9672: } else {
9673: window.location.href=dest;
9674: }
9675: }
9676: }
9677: \$(document).ready(function () {
9678: setTimeout('LC_To_Opener()',$timeout);
9679: });
9680: // ]]>
9681: </script>
9682: ENDJS
9683: } else {
9684: $result.=<<"ADDMETA";
1.344 albertel 9685: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 9686: ADDMETA
1.1386 raeburn 9687: }
1.1210 raeburn 9688: } else {
9689: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
9690: my $requrl = $env{'request.uri'};
9691: if ($requrl eq '') {
9692: $requrl = $ENV{'REQUEST_URI'};
9693: $requrl =~ s/\?.+$//;
9694: }
9695: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
9696: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
9697: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
9698: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
9699: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
9700: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 9701: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 9702: my ($offload,$offloadoth);
1.1210 raeburn 9703: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
9704: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 9705: $offload = 1;
1.1353 raeburn 9706: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9707: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9708: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9709: $offloadoth = 1;
9710: $dom_in_use = $env{'user.domain'};
9711: }
9712: }
1.1340 raeburn 9713: }
9714: }
9715: unless ($offload) {
9716: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
9717: if ($domdefs{'offloadoth'}{$lonhost}) {
9718: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9719: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9720: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9721: $offload = 1;
1.1352 raeburn 9722: $offloadoth = 1;
1.1340 raeburn 9723: $dom_in_use = $env{'user.domain'};
9724: }
1.1210 raeburn 9725: }
1.1340 raeburn 9726: }
9727: }
9728: }
9729: if ($offload) {
1.1358 raeburn 9730: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1352 raeburn 9731: if (($newserver eq '') && ($offloadoth)) {
9732: my @domains = &Apache::lonnet::current_machine_domains();
9733: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
9734: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
9735: }
9736: }
1.1340 raeburn 9737: if (($newserver) && ($newserver ne $lonhost)) {
9738: my $numsec = 5;
9739: my $timeout = $numsec * 1000;
9740: my ($newurl,$locknum,%locks,$msg);
9741: if ($env{'request.role.adv'}) {
9742: ($locknum,%locks) = &Apache::lonnet::get_locks();
9743: }
9744: my $disable_submit = 0;
9745: if ($requrl =~ /$LONCAPA::assess_re/) {
9746: $disable_submit = 1;
9747: }
9748: if ($locknum) {
9749: my @lockinfo = sort(values(%locks));
1.1354 raeburn 9750: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 9751: join(", ",sort(values(%locks)))."\n";
9752: if (&show_course()) {
9753: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
9754: } else {
9755: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 9756: }
1.1340 raeburn 9757: } else {
9758: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
9759: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
9760: }
9761: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
9762: $newurl = '/adm/switchserver?otherserver='.$newserver;
9763: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
9764: $newurl .= '&role='.$env{'request.role'};
9765: }
9766: if ($env{'request.symb'}) {
9767: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
9768: if ($shownsymb =~ m{^/enc/}) {
9769: my $reqdmajor = 2;
9770: my $reqdminor = 11;
9771: my $reqdsubminor = 3;
9772: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
9773: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
9774: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
9775: if (($major eq '' && $minor eq '') ||
9776: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
9777: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
9778: ($reqdsubminor > $subminor))))) {
9779: undef($shownsymb);
9780: }
1.1210 raeburn 9781: }
1.1340 raeburn 9782: if ($shownsymb) {
9783: &js_escape(\$shownsymb);
9784: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 9785: }
1.1340 raeburn 9786: } else {
9787: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
9788: &js_escape(\$shownurl);
9789: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 9790: }
1.1340 raeburn 9791: }
9792: &js_escape(\$msg);
9793: $result.=<<OFFLOAD
1.1210 raeburn 9794: <meta http-equiv="pragma" content="no-cache" />
9795: <script type="text/javascript">
1.1215 raeburn 9796: // <![CDATA[
1.1210 raeburn 9797: function LC_Offload_Now() {
9798: var dest = "$newurl";
9799: if (dest != '') {
9800: window.location.href="$newurl";
9801: }
9802: }
1.1214 raeburn 9803: \$(document).ready(function () {
9804: window.alert('$msg');
9805: if ($disable_submit) {
1.1210 raeburn 9806: \$(".LC_hwk_submit").prop("disabled", true);
9807: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 9808: }
9809: setTimeout('LC_Offload_Now()', $timeout);
9810: });
1.1215 raeburn 9811: // ]]>
1.1210 raeburn 9812: </script>
9813: OFFLOAD
9814: }
9815: }
9816: }
9817: }
9818: }
1.313 albertel 9819: }
1.306 albertel 9820: if (!defined($title)) {
9821: $title = 'The LearningOnline Network with CAPA';
9822: }
1.460 albertel 9823: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1432 raeburn 9824: if ($title =~ /^LON-CAPA\s+/) {
9825: $result .= '<title> '.$title.'</title>';
9826: } else {
9827: $result .= '<title> LON-CAPA '.$title.'</title>';
9828: }
9829: $result .= "\n".'<link rel="stylesheet" type="text/css" href="'.$url.'"';
1.1168 raeburn 9830: if (!$args->{'frameset'}) {
9831: $result .= ' /';
9832: }
9833: $result .= '>'
1.1064 raeburn 9834: .$inhibitprint
1.414 albertel 9835: .$head_extra;
1.1242 raeburn 9836: my $clientmobile;
9837: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
9838: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
9839: } else {
9840: $clientmobile = $env{'browser.mobile'};
9841: }
9842: if ($clientmobile) {
1.1137 raeburn 9843: $result .= '
1.1435 raeburn 9844: <meta name="viewport" content="width=device-width, initial-scale=1.0">
1.1137 raeburn 9845: <meta name="apple-mobile-web-app-capable" content="yes" />';
9846: }
1.1455 raeburn 9847: $result .= '<meta name="google" content="notranslate"';
9848: if (!$args->{'frameset'}) {
9849: $result .= ' /';
9850: }
9851: $result .= '>'."\n";
1.962 droeschl 9852: return $result.'</head>';
1.306 albertel 9853: }
9854:
9855: =pod
9856:
1.340 albertel 9857: =item * &font_settings()
9858:
9859: Returns neccessary <meta> to set the proper encoding
9860:
1.1160 raeburn 9861: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 9862:
9863: =cut
9864:
9865: sub font_settings {
1.1160 raeburn 9866: my ($args) = @_;
1.340 albertel 9867: my $headerstring='';
1.1160 raeburn 9868: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
9869: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 9870: $headerstring.=
9871: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
9872: if (!$args->{'frameset'}) {
9873: $headerstring.= ' /';
9874: }
9875: $headerstring .= '>'."\n";
1.340 albertel 9876: }
9877: return $headerstring;
9878: }
9879:
1.341 albertel 9880: =pod
9881:
1.1064 raeburn 9882: =item * &print_suppression()
9883:
9884: In course context returns css which causes the body to be blank when media="print",
9885: if printout generation is unavailable for the current resource.
9886:
9887: This could be because:
9888:
9889: (a) printstartdate is in the future
9890:
9891: (b) printenddate is in the past
9892:
9893: (c) there is an active exam block with "printout"
9894: functionality blocked
9895:
9896: Users with pav, pfo or evb privileges are exempt.
9897:
9898: Inputs: none
9899:
9900: =cut
9901:
9902:
9903: sub print_suppression {
9904: my $noprint;
9905: if ($env{'request.course.id'}) {
9906: my $scope = $env{'request.course.id'};
9907: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9908: (&Apache::lonnet::allowed('pfo',$scope))) {
9909: return;
9910: }
9911: if ($env{'request.course.sec'} ne '') {
9912: $scope .= "/$env{'request.course.sec'}";
9913: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9914: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 9915: return;
1.1064 raeburn 9916: }
9917: }
9918: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9919: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 9920: my $clientip = &Apache::lonnet::get_requestor_ip();
9921: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 9922: if ($blocked) {
9923: my $checkrole = "cm./$cdom/$cnum";
9924: if ($env{'request.course.sec'} ne '') {
9925: $checkrole .= "/$env{'request.course.sec'}";
9926: }
9927: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
9928: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
9929: $noprint = 1;
9930: }
9931: }
9932: unless ($noprint) {
9933: my $symb = &Apache::lonnet::symbread();
9934: if ($symb ne '') {
9935: my $navmap = Apache::lonnavmaps::navmap->new();
9936: if (ref($navmap)) {
9937: my $res = $navmap->getBySymb($symb);
9938: if (ref($res)) {
9939: if (!$res->resprintable()) {
9940: $noprint = 1;
9941: }
9942: }
9943: }
9944: }
9945: }
9946: if ($noprint) {
9947: return <<"ENDSTYLE";
9948: <style type="text/css" media="print">
9949: body { display:none }
9950: </style>
9951: ENDSTYLE
9952: }
9953: }
9954: return;
9955: }
9956:
9957: =pod
9958:
1.341 albertel 9959: =item * &xml_begin()
9960:
9961: Returns the needed doctype and <html>
9962:
9963: Inputs: none
9964:
9965: =cut
9966:
9967: sub xml_begin {
1.1168 raeburn 9968: my ($is_frameset) = @_;
1.341 albertel 9969: my $output='';
9970:
9971: if ($env{'browser.mathml'}) {
9972: $output='<?xml version="1.0"?>'
9973: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9974: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9975:
9976: # .'<!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">] >'
9977: .'<!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">'
9978: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9979: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 9980: } elsif ($is_frameset) {
9981: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
1.1459 raeburn 9982: '<html lang="en">'."\n";
1.341 albertel 9983: } else {
1.1168 raeburn 9984: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9985: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9986: }
9987: return $output;
9988: }
1.340 albertel 9989:
9990: =pod
9991:
1.306 albertel 9992: =item * &start_page()
9993:
9994: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9995:
1.648 raeburn 9996: Inputs:
9997:
9998: =over 4
9999:
10000: $title - optional title for the page
10001:
10002: $head_extra - optional extra HTML to incude inside the <head>
10003:
10004: $args - additional optional args supported are:
10005:
10006: =over 8
10007:
10008: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 10009: arg on
1.814 bisitz 10010: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 10011: add_entries -> additional attributes to add to the <body>
10012: domain -> force to color decorate a page for a
1.317 albertel 10013: specific domain
1.648 raeburn 10014: function -> force usage of a specific rolish color
1.317 albertel 10015: scheme
1.648 raeburn 10016: redirect -> see &headtag()
10017: bgcolor -> override the default page bg color
10018: js_ready -> return a string ready for being used in
1.317 albertel 10019: a javascript writeln
1.648 raeburn 10020: html_encode -> return a string ready for being used in
1.320 albertel 10021: a html attribute
1.648 raeburn 10022: force_register -> if is true will turn on the &bodytag()
1.317 albertel 10023: $forcereg arg
1.648 raeburn 10024: frameset -> if true will start with a <frameset>
1.330 albertel 10025: rather than <body>
1.648 raeburn 10026: skip_phases -> hash ref of
1.338 albertel 10027: head -> skip the <html><head> generation
10028: body -> skip all <body> generation
1.648 raeburn 10029: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 10030: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 10031: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1437 raeburn 10032: bread_crumbs_style -> breadcrumbs are contained within <div id="LC_breadcrumbs">,
10033: and &standard_css() contains CSS for #LC_breadcrumbs, if you want
10034: to override those values, or add to them, specify the value to
10035: include in the style attribute to include in the div tag by using
10036: bread_crumbs_style (e.g., overflow: visible)
1.1272 raeburn 10037: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
10038: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 10039: group -> includes the current group, if page is for a
1.1274 raeburn 10040: specific group
10041: use_absolute -> for request for external resource or syllabus, this
10042: will contain https://<hostname> if server uses
10043: https (as per hosts.tab), but request is for http
10044: hostname -> hostname, originally from $r->hostname(), (optional).
1.1369 raeburn 10045: links_disabled -> Links in primary and secondary menus are disabled
10046: (Can enable them once page has loaded - see lonroles.pm
10047: for an example).
1.1380 raeburn 10048: links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 10049:
1.648 raeburn 10050: =back
1.460 albertel 10051:
1.648 raeburn 10052: =back
1.562 albertel 10053:
1.306 albertel 10054: =cut
10055:
10056: sub start_page {
1.309 albertel 10057: my ($title,$head_extra,$args) = @_;
1.318 albertel 10058: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 10059:
1.315 albertel 10060: $env{'internal.start_page'}++;
1.1359 raeburn 10061: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 10062:
1.338 albertel 10063: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 10064: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 10065: }
1.1316 raeburn 10066:
10067: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 10068: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
10069: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
10070: $args->{'no_primary_menu'} = 1;
10071: }
10072: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
10073: $args->{'no_inline_menu'} = 1;
10074: }
10075: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
10076: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
10077: }
10078: } else {
10079: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10080: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
10081: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
10082: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
10083: $args->{'no_primary_menu'} = 1;
10084: }
10085: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
10086: $args->{'no_inline_menu'} = 1;
10087: }
10088: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
10089: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
10090: }
10091: }
10092: }
1.1316 raeburn 10093: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
10094: $env{'course.'.$env{'request.course.id'}.'.domain'},
10095: $env{'course.'.$env{'request.course.id'}.'.num'});
1.1359 raeburn 10096: } elsif ($env{'request.course.id'}) {
10097: my $expiretime=600;
10098: if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
10099: &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
10100: }
10101: my ($deeplinkmenu,$menuref);
10102: ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
10103: if ($menucoll) {
10104: if (ref($menuref) eq 'HASH') {
10105: %menu = %{$menuref};
10106: }
10107: if ($menu{'top'} eq 'n') {
10108: $args->{'no_primary_menu'} = 1;
10109: }
10110: if ($menu{'inline'} eq 'n') {
10111: unless (&Apache::lonnet::allowed('opa')) {
10112: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10113: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
10114: my $crstype = &course_type();
10115: my $now = time;
10116: my $ccrole;
10117: if ($crstype eq 'Community') {
10118: $ccrole = 'co';
10119: } else {
10120: $ccrole = 'cc';
10121: }
10122: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
10123: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
10124: if ((($start) && ($start<0)) ||
10125: (($end) && ($end<$now)) ||
10126: (($start) && ($now<$start))) {
10127: $args->{'no_inline_menu'} = 1;
10128: }
10129: } else {
10130: $args->{'no_inline_menu'} = 1;
10131: }
10132: }
10133: }
10134: }
1.1316 raeburn 10135: }
1.1359 raeburn 10136:
1.1385 raeburn 10137: my $showncrumbs;
1.338 albertel 10138: if (! exists($args->{'skip_phases'}{'body'}) ) {
10139: if ($args->{'frameset'}) {
10140: my $attr_string = &make_attr_string($args->{'force_register'},
10141: $args->{'add_entries'});
10142: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 10143: } else {
10144: $result .=
10145: &bodytag($title,
10146: $args->{'function'}, $args->{'add_entries'},
10147: $args->{'only_body'}, $args->{'domain'},
10148: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 10149: $args->{'bgcolor'}, $args,
1.1385 raeburn 10150: \@advtools,$ltiscope,$ltiuri,\%ltimenu,$menucoll,
10151: \%menu,\$showncrumbs);
1.831 bisitz 10152: }
1.330 albertel 10153: }
1.338 albertel 10154:
1.315 albertel 10155: if ($args->{'js_ready'}) {
1.713 kaisler 10156: $result = &js_ready($result);
1.315 albertel 10157: }
1.320 albertel 10158: if ($args->{'html_encode'}) {
1.713 kaisler 10159: $result = &html_encode($result);
10160: }
10161:
1.813 bisitz 10162: # Preparation for new and consistent functionlist at top of screen
10163: # if ($args->{'functionlist'}) {
10164: # $result .= &build_functionlist();
10165: #}
10166:
1.964 droeschl 10167: # Don't add anything more if only_body wanted or in const space
10168: return $result if $args->{'only_body'}
10169: || $env{'request.state'} eq 'construct';
1.813 bisitz 10170:
10171: #Breadcrumbs
1.758 kaisler 10172: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1385 raeburn 10173: unless ($showncrumbs) {
1.758 kaisler 10174: &Apache::lonhtmlcommon::clear_breadcrumbs();
10175: #if any br links exists, add them to the breadcrumbs
10176: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
10177: foreach my $crumb (@{$args->{'bread_crumbs'}}){
10178: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
10179: }
10180: }
1.1096 raeburn 10181: # if @advtools array contains items add then to the breadcrumbs
10182: if (@advtools > 0) {
10183: &Apache::lonmenu::advtools_crumbs(@advtools);
10184: }
1.1272 raeburn 10185: my $menulink;
10186: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
10187: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 10188: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 10189: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
10190: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
10191: (!$env{'request.role.adv'}))) {
10192: $menulink = 0;
10193: } else {
10194: undef($menulink);
10195: }
1.1385 raeburn 10196: my $linkprotout;
10197: if ($env{'request.deeplink.login'}) {
10198: my $linkprotout = &Apache::lonmenu::linkprot_exit();
10199: if ($linkprotout) {
10200: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
10201: }
10202: }
1.758 kaisler 10203: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
10204: if(exists($args->{'bread_crumbs_component'})){
1.1437 raeburn 10205: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},
10206: '',$menulink,'',
10207: $args->{'bread_crumbs_style'});
1.1237 raeburn 10208: } else {
1.1437 raeburn 10209: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink,'',
10210: $args->{'bread_crumbs_style'});
1.758 kaisler 10211: }
1.1385 raeburn 10212: }
1.320 albertel 10213: }
1.315 albertel 10214: return $result;
1.306 albertel 10215: }
10216:
10217: sub end_page {
1.315 albertel 10218: my ($args) = @_;
10219: $env{'internal.end_page'}++;
1.330 albertel 10220: my $result;
1.335 albertel 10221: if ($args->{'discussion'}) {
10222: my ($target,$parser);
10223: if (ref($args->{'discussion'})) {
10224: ($target,$parser) =($args->{'discussion'}{'target'},
10225: $args->{'discussion'}{'parser'});
10226: }
10227: $result .= &Apache::lonxml::xmlend($target,$parser);
10228: }
1.330 albertel 10229: if ($args->{'frameset'}) {
10230: $result .= '</frameset>';
10231: } else {
1.635 raeburn 10232: $result .= &endbodytag($args);
1.330 albertel 10233: }
1.1080 raeburn 10234: unless ($args->{'notbody'}) {
10235: $result .= "\n</html>";
10236: }
1.330 albertel 10237:
1.315 albertel 10238: if ($args->{'js_ready'}) {
1.317 albertel 10239: $result = &js_ready($result);
1.315 albertel 10240: }
1.335 albertel 10241:
1.320 albertel 10242: if ($args->{'html_encode'}) {
10243: $result = &html_encode($result);
10244: }
1.335 albertel 10245:
1.315 albertel 10246: return $result;
10247: }
10248:
1.1359 raeburn 10249: sub menucoll_in_effect {
10250: my ($menucoll,$deeplinkmenu,%menu);
10251: if ($env{'request.course.id'}) {
10252: $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
1.1362 raeburn 10253: if ($env{'request.deeplink.login'}) {
1.1370 raeburn 10254: my ($deeplink_symb,$deeplink,$check_login_symb);
1.1362 raeburn 10255: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
10256: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10257: if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
10258: if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
10259: my $navmap = Apache::lonnavmaps::navmap->new();
10260: if (ref($navmap)) {
10261: $deeplink = $navmap->get_mapparam(undef,
10262: &Apache::lonnet::declutter($env{'request.noversionuri'}),
10263: '0.deeplink');
1.1370 raeburn 10264: } else {
10265: $check_login_symb = 1;
1.1362 raeburn 10266: }
10267: } else {
1.1370 raeburn 10268: my $symb = &Apache::lonnet::symbread();
10269: if ($symb) {
10270: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
10271: } else {
10272: $check_login_symb = 1;
10273: }
1.1362 raeburn 10274: }
10275: } else {
1.1370 raeburn 10276: $check_login_symb = 1;
10277: }
10278: if ($check_login_symb) {
1.1362 raeburn 10279: $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
10280: if ($deeplink_symb =~ /\.(page|sequence)$/) {
10281: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
10282: my $navmap = Apache::lonnavmaps::navmap->new();
10283: if (ref($navmap)) {
10284: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
10285: }
10286: } else {
10287: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
10288: }
10289: }
1.1359 raeburn 10290: if ($deeplink ne '') {
1.1378 raeburn 10291: my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
1.1359 raeburn 10292: if ($display =~ /^\d+$/) {
10293: $deeplinkmenu = 1;
10294: $menucoll = $display;
10295: }
10296: }
10297: }
10298: if ($menucoll) {
10299: %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
10300: }
10301: }
10302: return ($menucoll,$deeplinkmenu,\%menu);
10303: }
10304:
1.1362 raeburn 10305: sub deeplink_login_symb {
10306: my ($cnum,$cdom) = @_;
10307: my $login_symb;
10308: if ($env{'request.deeplink.login'}) {
1.1364 raeburn 10309: $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
10310: }
10311: return $login_symb;
10312: }
10313:
10314: sub symb_from_tinyurl {
10315: my ($url,$cnum,$cdom) = @_;
10316: if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
10317: my $key = $1;
10318: my ($tinyurl,$login);
10319: my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
10320: if (defined($cached)) {
10321: $tinyurl = $result;
10322: } else {
10323: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
10324: my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
10325: if ($currtiny{$key} ne '') {
10326: $tinyurl = $currtiny{$key};
10327: &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
1.1362 raeburn 10328: }
1.1364 raeburn 10329: }
10330: if ($tinyurl ne '') {
10331: my ($cnumreq,$symb) = split(/\&/,$tinyurl);
10332: if (wantarray) {
10333: return ($cnumreq,$symb);
10334: } elsif ($cnumreq eq $cnum) {
10335: return $symb;
1.1362 raeburn 10336: }
10337: }
10338: }
1.1364 raeburn 10339: if (wantarray) {
10340: return ();
10341: } else {
10342: return;
10343: }
1.1362 raeburn 10344: }
10345:
1.1405 raeburn 10346: sub usable_exttools {
10347: my %tooltypes;
10348: if ($env{'request.course.id'}) {
10349: if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) {
10350: if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') {
10351: %tooltypes = (
10352: crs => 1,
10353: dom => 1,
10354: );
10355: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') {
10356: $tooltypes{'crs'} = 1;
10357: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') {
10358: $tooltypes{'dom'} = 1;
10359: }
10360: } else {
10361: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10362: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
10363: my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'});
10364: if ($crstype eq '') {
10365: $crstype = 'course';
10366: }
10367: if ($crstype eq 'course') {
10368: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) {
10369: $crstype = 'official';
10370: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
10371: $crstype = 'textbook';
10372: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) {
10373: $crstype = 'lti';
10374: } else {
10375: $crstype = 'unofficial';
10376: }
10377: }
10378: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
10379: if ($domdefaults{$crstype.'domexttool'}) {
10380: $tooltypes{'dom'} = 1;
10381: }
10382: if ($domdefaults{$crstype.'exttool'}) {
10383: $tooltypes{'crs'} = 1;
10384: }
10385: }
10386: }
10387: return %tooltypes;
10388: }
10389:
1.1034 www 10390: sub wishlist_window {
10391: return(<<'ENDWISHLIST');
1.1046 raeburn 10392: <script type="text/javascript">
1.1034 www 10393: // <![CDATA[
10394: // <!-- BEGIN LON-CAPA Internal
10395: function set_wishlistlink(title, path) {
10396: if (!title) {
10397: title = document.title;
10398: title = title.replace(/^LON-CAPA /,'');
10399: }
1.1175 raeburn 10400: title = encodeURIComponent(title);
1.1203 raeburn 10401: title = title.replace("'","\\\'");
1.1034 www 10402: if (!path) {
10403: path = location.pathname;
10404: }
1.1175 raeburn 10405: path = encodeURIComponent(path);
1.1203 raeburn 10406: path = path.replace("'","\\\'");
1.1034 www 10407: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
10408: 'wishlistNewLink','width=560,height=350,scrollbars=0');
10409: }
10410: // END LON-CAPA Internal -->
10411: // ]]>
10412: </script>
10413: ENDWISHLIST
10414: }
10415:
1.1030 www 10416: sub modal_window {
10417: return(<<'ENDMODAL');
1.1046 raeburn 10418: <script type="text/javascript">
1.1030 www 10419: // <![CDATA[
10420: // <!-- BEGIN LON-CAPA Internal
10421: var modalWindow = {
10422: parent:"body",
10423: windowId:null,
10424: content:null,
10425: width:null,
10426: height:null,
10427: close:function()
10428: {
10429: $(".LCmodal-window").remove();
10430: $(".LCmodal-overlay").remove();
10431: },
10432: open:function()
10433: {
10434: var modal = "";
10435: modal += "<div class=\"LCmodal-overlay\"></div>";
10436: 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;\">";
10437: modal += this.content;
10438: modal += "</div>";
10439:
10440: $(this.parent).append(modal);
10441:
10442: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
10443: $(".LCclose-window").click(function(){modalWindow.close();});
10444: $(".LCmodal-overlay").click(function(){modalWindow.close();});
10445: }
10446: };
1.1140 raeburn 10447: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 10448: {
1.1266 raeburn 10449: source = source.replace(/'/g,"'");
1.1030 www 10450: modalWindow.windowId = "myModal";
10451: modalWindow.width = width;
10452: modalWindow.height = height;
1.1196 raeburn 10453: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 10454: modalWindow.open();
1.1208 raeburn 10455: };
1.1030 www 10456: // END LON-CAPA Internal -->
10457: // ]]>
10458: </script>
10459: ENDMODAL
10460: }
10461:
10462: sub modal_link {
1.1140 raeburn 10463: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 10464: unless ($width) { $width=480; }
10465: unless ($height) { $height=400; }
1.1031 www 10466: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 10467: unless ($transparency) { $transparency='true'; }
10468:
1.1074 raeburn 10469: my $target_attr;
10470: if (defined($target)) {
10471: $target_attr = 'target="'.$target.'"';
10472: }
10473: return <<"ENDLINK";
1.1336 raeburn 10474: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 10475: ENDLINK
1.1030 www 10476: }
10477:
1.1032 www 10478: sub modal_adhoc_script {
1.1365 raeburn 10479: my ($funcname,$width,$height,$content,$possmathjax)=@_;
10480: my $mathjax;
10481: if ($possmathjax) {
10482: $mathjax = <<'ENDJAX';
10483: if (typeof MathJax == 'object') {
10484: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
10485: }
10486: ENDJAX
10487: }
1.1032 www 10488: return (<<ENDADHOC);
1.1046 raeburn 10489: <script type="text/javascript">
1.1032 www 10490: // <![CDATA[
10491: var $funcname = function()
10492: {
10493: modalWindow.windowId = "myModal";
10494: modalWindow.width = $width;
10495: modalWindow.height = $height;
10496: modalWindow.content = '$content';
10497: modalWindow.open();
1.1365 raeburn 10498: $mathjax
1.1032 www 10499: };
10500: // ]]>
10501: </script>
10502: ENDADHOC
10503: }
10504:
1.1041 www 10505: sub modal_adhoc_inner {
1.1365 raeburn 10506: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 10507: my $innerwidth=$width-20;
10508: $content=&js_ready(
1.1140 raeburn 10509: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
10510: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
10511: $content.
1.1041 www 10512: &end_scrollbox().
1.1140 raeburn 10513: &end_page()
1.1041 www 10514: );
1.1365 raeburn 10515: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 10516: }
10517:
10518: sub modal_adhoc_window {
1.1365 raeburn 10519: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
10520: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 10521: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
10522: }
10523:
10524: sub modal_adhoc_launch {
10525: my ($funcname,$width,$height,$content)=@_;
10526: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
10527: <script type="text/javascript">
10528: // <![CDATA[
10529: $funcname();
10530: // ]]>
10531: </script>
10532: ENDLAUNCH
10533: }
10534:
10535: sub modal_adhoc_close {
10536: return (<<ENDCLOSE);
10537: <script type="text/javascript">
10538: // <![CDATA[
10539: modalWindow.close();
10540: // ]]>
10541: </script>
10542: ENDCLOSE
10543: }
10544:
1.1038 www 10545: sub togglebox_script {
10546: return(<<ENDTOGGLE);
10547: <script type="text/javascript">
10548: // <![CDATA[
10549: function LCtoggleDisplay(id,hidetext,showtext) {
10550: link = document.getElementById(id + "link").childNodes[0];
10551: with (document.getElementById(id).style) {
10552: if (display == "none" ) {
10553: display = "inline";
10554: link.nodeValue = hidetext;
10555: } else {
10556: display = "none";
10557: link.nodeValue = showtext;
10558: }
10559: }
10560: }
10561: // ]]>
10562: </script>
10563: ENDTOGGLE
10564: }
10565:
1.1039 www 10566: sub start_togglebox {
10567: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
10568: unless ($heading) { $heading=''; } else { $heading.=' '; }
10569: unless ($showtext) { $showtext=&mt('show'); }
10570: unless ($hidetext) { $hidetext=&mt('hide'); }
10571: unless ($headerbg) { $headerbg='#FFFFFF'; }
10572: return &start_data_table().
10573: &start_data_table_header_row().
10574: '<td bgcolor="'.$headerbg.'">'.$heading.
10575: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
10576: $showtext.'\')">'.$showtext.'</a>]</td>'.
10577: &end_data_table_header_row().
10578: '<tr id="'.$id.'" style="display:none""><td>';
10579: }
10580:
10581: sub end_togglebox {
10582: return '</td></tr>'.&end_data_table();
10583: }
10584:
1.1041 www 10585: sub LCprogressbar_script {
1.1302 raeburn 10586: my ($id,$number_to_do)=@_;
10587: if ($number_to_do) {
10588: return(<<ENDPROGRESS);
1.1041 www 10589: <script type="text/javascript">
10590: // <![CDATA[
1.1045 www 10591: \$('#progressbar$id').progressbar({
1.1041 www 10592: value: 0,
10593: change: function(event, ui) {
10594: var newVal = \$(this).progressbar('option', 'value');
10595: \$('.pblabel', this).text(LCprogressTxt);
10596: }
10597: });
10598: // ]]>
10599: </script>
10600: ENDPROGRESS
1.1302 raeburn 10601: } else {
10602: return(<<ENDPROGRESS);
10603: <script type="text/javascript">
10604: // <![CDATA[
10605: \$('#progressbar$id').progressbar({
10606: value: false,
10607: create: function(event, ui) {
10608: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
10609: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
10610: }
10611: });
10612: // ]]>
10613: </script>
10614: ENDPROGRESS
10615: }
1.1041 www 10616: }
10617:
10618: sub LCprogressbarUpdate_script {
10619: return(<<ENDPROGRESSUPDATE);
10620: <style type="text/css">
10621: .ui-progressbar { position:relative; }
1.1302 raeburn 10622: .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 10623: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
10624: </style>
10625: <script type="text/javascript">
10626: // <![CDATA[
1.1045 www 10627: var LCprogressTxt='---';
10628:
1.1302 raeburn 10629: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 10630: LCprogressTxt=progresstext;
1.1302 raeburn 10631: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
10632: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
10633: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 10634: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
10635: } else {
10636: \$('#progressbar'+id).progressbar('value',percent);
10637: }
1.1041 www 10638: }
10639: // ]]>
10640: </script>
10641: ENDPROGRESSUPDATE
10642: }
10643:
1.1042 www 10644: my $LClastpercent;
1.1045 www 10645: my $LCidcnt;
10646: my $LCcurrentid;
1.1042 www 10647:
1.1041 www 10648: sub LCprogressbar {
1.1302 raeburn 10649: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 10650: $LClastpercent=0;
1.1045 www 10651: $LCidcnt++;
10652: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 10653: my ($starting,$content);
10654: if ($number_to_do) {
10655: $starting=&mt('Starting');
10656: $content=(<<ENDPROGBAR);
10657: $preamble
1.1045 www 10658: <div id="progressbar$LCcurrentid">
1.1041 www 10659: <span class="pblabel">$starting</span>
10660: </div>
10661: ENDPROGBAR
1.1302 raeburn 10662: } else {
10663: $starting=&mt('Loading...');
10664: $LClastpercent='false';
10665: $content=(<<ENDPROGBAR);
10666: $preamble
10667: <div id="progressbar$LCcurrentid">
10668: <div class="progress-label">$starting</div>
10669: </div>
10670: ENDPROGBAR
10671: }
10672: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 10673: }
10674:
10675: sub LCprogressbarUpdate {
1.1302 raeburn 10676: my ($r,$val,$text,$number_to_do)=@_;
10677: if ($number_to_do) {
10678: unless ($val) {
10679: if ($LClastpercent) {
10680: $val=$LClastpercent;
10681: } else {
10682: $val=0;
10683: }
10684: }
10685: if ($val<0) { $val=0; }
10686: if ($val>100) { $val=0; }
10687: $LClastpercent=$val;
10688: unless ($text) { $text=$val.'%'; }
10689: } else {
10690: $val = 'false';
1.1042 www 10691: }
1.1041 www 10692: $text=&js_ready($text);
1.1044 www 10693: &r_print($r,<<ENDUPDATE);
1.1041 www 10694: <script type="text/javascript">
10695: // <![CDATA[
1.1302 raeburn 10696: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 10697: // ]]>
10698: </script>
10699: ENDUPDATE
1.1035 www 10700: }
10701:
1.1042 www 10702: sub LCprogressbarClose {
10703: my ($r)=@_;
10704: $LClastpercent=0;
1.1044 www 10705: &r_print($r,<<ENDCLOSE);
1.1042 www 10706: <script type="text/javascript">
10707: // <![CDATA[
1.1045 www 10708: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 10709: // ]]>
10710: </script>
10711: ENDCLOSE
1.1044 www 10712: }
10713:
10714: sub r_print {
10715: my ($r,$to_print)=@_;
10716: if ($r) {
10717: $r->print($to_print);
10718: $r->rflush();
10719: } else {
10720: print($to_print);
10721: }
1.1042 www 10722: }
10723:
1.320 albertel 10724: sub html_encode {
10725: my ($result) = @_;
10726:
1.322 albertel 10727: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 10728:
10729: return $result;
10730: }
1.1044 www 10731:
1.317 albertel 10732: sub js_ready {
10733: my ($result) = @_;
10734:
1.323 albertel 10735: $result =~ s/[\n\r]/ /xmsg;
10736: $result =~ s/\\/\\\\/xmsg;
10737: $result =~ s/'/\\'/xmsg;
1.372 albertel 10738: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 10739:
10740: return $result;
10741: }
10742:
1.315 albertel 10743: sub validate_page {
10744: if ( exists($env{'internal.start_page'})
1.316 albertel 10745: && $env{'internal.start_page'} > 1) {
10746: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 10747: $env{'internal.start_page'}.' '.
1.316 albertel 10748: $ENV{'request.filename'});
1.315 albertel 10749: }
10750: if ( exists($env{'internal.end_page'})
1.316 albertel 10751: && $env{'internal.end_page'} > 1) {
10752: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 10753: $env{'internal.end_page'}.' '.
1.316 albertel 10754: $env{'request.filename'});
1.315 albertel 10755: }
10756: if ( exists($env{'internal.start_page'})
10757: && ! exists($env{'internal.end_page'})) {
1.316 albertel 10758: &Apache::lonnet::logthis('start_page called without end_page '.
10759: $env{'request.filename'});
1.315 albertel 10760: }
10761: if ( ! exists($env{'internal.start_page'})
10762: && exists($env{'internal.end_page'})) {
1.316 albertel 10763: &Apache::lonnet::logthis('end_page called without start_page'.
10764: $env{'request.filename'});
1.315 albertel 10765: }
1.306 albertel 10766: }
1.315 albertel 10767:
1.996 www 10768:
10769: sub start_scrollbox {
1.1140 raeburn 10770: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 10771: unless ($outerwidth) { $outerwidth='520px'; }
10772: unless ($width) { $width='500px'; }
10773: unless ($height) { $height='200px'; }
1.1075 raeburn 10774: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 10775: if ($id ne '') {
1.1140 raeburn 10776: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 10777: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 10778: }
1.1075 raeburn 10779: if ($bgcolor ne '') {
10780: $tdcol = "background-color: $bgcolor;";
10781: }
1.1137 raeburn 10782: my $nicescroll_js;
10783: if ($env{'browser.mobile'}) {
1.1140 raeburn 10784: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
10785: }
10786: return <<"END";
10787: $nicescroll_js
10788:
10789: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
10790: <div style="overflow:auto; width:$width; height:$height;"$div_id>
10791: END
10792: }
10793:
10794: sub end_scrollbox {
10795: return '</div></td></tr></table>';
10796: }
10797:
10798: sub nicescroll_javascript {
10799: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
10800: my %options;
10801: if (ref($cursor) eq 'HASH') {
10802: %options = %{$cursor};
10803: }
10804: unless ($options{'railalign'} =~ /^left|right$/) {
10805: $options{'railalign'} = 'left';
10806: }
10807: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10808: my $function = &get_users_function();
10809: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 10810: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 10811: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 10812: }
1.1140 raeburn 10813: }
10814: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
10815: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 10816: $options{'cursoropacity'}='1.0';
10817: }
1.1140 raeburn 10818: } else {
10819: $options{'cursoropacity'}='1.0';
10820: }
10821: if ($options{'cursorfixedheight'} eq 'none') {
10822: delete($options{'cursorfixedheight'});
10823: } else {
10824: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
10825: }
10826: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
10827: delete($options{'railoffset'});
10828: }
10829: my @niceoptions;
10830: while (my($key,$value) = each(%options)) {
10831: if ($value =~ /^\{.+\}$/) {
10832: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 10833: } else {
1.1140 raeburn 10834: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 10835: }
1.1140 raeburn 10836: }
10837: my $nicescroll_js = '
1.1137 raeburn 10838: $(document).ready(
1.1140 raeburn 10839: function() {
10840: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
10841: }
1.1137 raeburn 10842: );
10843: ';
1.1140 raeburn 10844: if ($framecheck) {
10845: $nicescroll_js .= '
10846: function expand_div(caller) {
10847: if (top === self) {
10848: document.getElementById("'.$id.'").style.width = "auto";
10849: document.getElementById("'.$id.'").style.height = "auto";
10850: } else {
10851: try {
10852: if (parent.frames) {
10853: if (parent.frames.length > 1) {
10854: var framesrc = parent.frames[1].location.href;
10855: var currsrc = framesrc.replace(/\#.*$/,"");
10856: if ((caller == "search") || (currsrc == "'.$location.'")) {
10857: document.getElementById("'.$id.'").style.width = "auto";
10858: document.getElementById("'.$id.'").style.height = "auto";
10859: }
10860: }
10861: }
10862: } catch (e) {
10863: return;
10864: }
1.1137 raeburn 10865: }
1.1140 raeburn 10866: return;
1.996 www 10867: }
1.1140 raeburn 10868: ';
10869: }
10870: if ($needjsready) {
10871: $nicescroll_js = '
10872: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
10873: } else {
10874: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
10875: }
10876: return $nicescroll_js;
1.996 www 10877: }
10878:
1.318 albertel 10879: sub simple_error_page {
1.1150 bisitz 10880: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 10881: my %displayargs;
1.1151 raeburn 10882: if (ref($args) eq 'HASH') {
10883: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 10884: if ($args->{'only_body'}) {
10885: $displayargs{'only_body'} = 1;
10886: }
10887: if ($args->{'no_nav_bar'}) {
10888: $displayargs{'no_nav_bar'} = 1;
10889: }
1.1151 raeburn 10890: } else {
10891: $msg = &mt($msg);
10892: }
1.1150 bisitz 10893:
1.318 albertel 10894: my $page =
1.1459 raeburn 10895: &Apache::loncommon::start_page($title,'',\%displayargs)."\n".
1.1460 raeburn 10896: '<div class="LC_landmark" style="clear:both" role="main">'.
1.1150 bisitz 10897: '<p class="LC_error">'.$msg.'</p>'.
1.1459 raeburn 10898: '</div>'.
1.318 albertel 10899: &Apache::loncommon::end_page();
10900: if (ref($r)) {
10901: $r->print($page);
1.327 albertel 10902: return;
1.318 albertel 10903: }
10904: return $page;
10905: }
1.347 albertel 10906:
10907: {
1.610 albertel 10908: my @row_count;
1.961 onken 10909:
10910: sub start_data_table_count {
10911: unshift(@row_count, 0);
10912: return;
10913: }
10914:
10915: sub end_data_table_count {
10916: shift(@row_count);
10917: return;
10918: }
10919:
1.1466 raeburn 10920: sub set_data_table_count {
10921: my ($count) = @_;
10922: unshift(@row_count,$count);
10923: }
10924:
1.347 albertel 10925: sub start_data_table {
1.1018 raeburn 10926: my ($add_class,$id) = @_;
1.422 albertel 10927: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 10928: my $table_id;
10929: if (defined($id)) {
10930: $table_id = ' id="'.$id.'"';
10931: }
1.961 onken 10932: &start_data_table_count();
1.1018 raeburn 10933: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 10934: }
10935:
10936: sub end_data_table {
1.961 onken 10937: &end_data_table_count();
1.389 albertel 10938: return '</table>'."\n";;
1.347 albertel 10939: }
10940:
10941: sub start_data_table_row {
1.974 wenzelju 10942: my ($add_class, $id) = @_;
1.610 albertel 10943: $row_count[0]++;
10944: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 10945: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 10946: $id = (' id="'.$id.'"') unless ($id eq '');
10947: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 10948: }
1.471 banghart 10949:
10950: sub continue_data_table_row {
1.974 wenzelju 10951: my ($add_class, $id) = @_;
1.610 albertel 10952: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 10953: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10954: $id = (' id="'.$id.'"') unless ($id eq '');
10955: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 10956: }
1.347 albertel 10957:
10958: sub end_data_table_row {
1.389 albertel 10959: return '</tr>'."\n";;
1.347 albertel 10960: }
1.367 www 10961:
1.421 albertel 10962: sub start_data_table_empty_row {
1.707 bisitz 10963: # $row_count[0]++;
1.421 albertel 10964: return '<tr class="LC_empty_row" >'."\n";;
10965: }
10966:
10967: sub end_data_table_empty_row {
10968: return '</tr>'."\n";;
10969: }
10970:
1.367 www 10971: sub start_data_table_header_row {
1.1465 raeburn 10972: my ($add_class,$id) = @_;
10973: my $css_class = 'LC_header_row';
10974: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10975: $id = (' id="'.$id.'"') unless ($id eq '');
10976: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.367 www 10977: }
10978:
10979: sub end_data_table_header_row {
1.389 albertel 10980: return '</tr>'."\n";;
1.367 www 10981: }
1.890 droeschl 10982:
10983: sub data_table_caption {
1.1468 raeburn 10984: my ($caption,$css_class) = @_;
10985: return "<caption class=\"LC_caption $css_class\">$caption</caption>";
1.890 droeschl 10986: }
1.347 albertel 10987: }
10988:
1.548 albertel 10989: =pod
10990:
10991: =item * &inhibit_menu_check($arg)
10992:
10993: Checks for a inhibitmenu state and generates output to preserve it
10994:
10995: Inputs: $arg - can be any of
10996: - undef - in which case the return value is a string
10997: to add into arguments list of a uri
10998: - 'input' - in which case the return value is a HTML
10999: <form> <input> field of type hidden to
11000: preserve the value
11001: - a url - in which case the return value is the url with
11002: the neccesary cgi args added to preserve the
11003: inhibitmenu state
11004: - a ref to a url - no return value, but the string is
11005: updated to include the neccessary cgi
11006: args to preserve the inhibitmenu state
11007:
11008: =cut
11009:
11010: sub inhibit_menu_check {
11011: my ($arg) = @_;
11012: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
11013: if ($arg eq 'input') {
11014: if ($env{'form.inhibitmenu'}) {
11015: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
11016: } else {
11017: return
11018: }
11019: }
11020: if ($env{'form.inhibitmenu'}) {
11021: if (ref($arg)) {
11022: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
11023: } elsif ($arg eq '') {
11024: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
11025: } else {
11026: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
11027: }
11028: }
11029: if (!ref($arg)) {
11030: return $arg;
11031: }
11032: }
11033:
1.251 albertel 11034: ###############################################
1.182 matthew 11035:
11036: =pod
11037:
1.549 albertel 11038: =back
11039:
11040: =head1 User Information Routines
11041:
11042: =over 4
11043:
1.405 albertel 11044: =item * &get_users_function()
1.182 matthew 11045:
11046: Used by &bodytag to determine the current users primary role.
11047: Returns either 'student','coordinator','admin', or 'author'.
11048:
11049: =cut
11050:
11051: ###############################################
11052: sub get_users_function {
1.815 tempelho 11053: my $function = 'norole';
1.818 tempelho 11054: if ($env{'request.role'}=~/^(st)/) {
11055: $function='student';
11056: }
1.907 raeburn 11057: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 11058: $function='coordinator';
11059: }
1.258 albertel 11060: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 11061: $function='admin';
11062: }
1.826 bisitz 11063: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 11064: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 11065: $function='author';
11066: }
11067: return $function;
1.54 www 11068: }
1.99 www 11069:
11070: ###############################################
11071:
1.233 raeburn 11072: =pod
11073:
1.821 raeburn 11074: =item * &show_course()
11075:
11076: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
11077: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
11078:
11079: Inputs:
11080: None
11081:
11082: Outputs:
11083: Scalar: 1 if 'Course' to be used, 0 otherwise.
11084:
11085: =cut
11086:
11087: ###############################################
11088: sub show_course {
1.1408 raeburn 11089: my ($udom,$uname) = @_;
11090: if (($udom ne '') && ($uname ne '')) {
11091: if (($udom ne $env{'user.domain'}) || ($uname ne $env{'user.name'})) {
1.1410 raeburn 11092: if (&Apache::lonnet::is_advanced_user($udom,$uname)) {
1.1408 raeburn 11093: return 0;
11094: } else {
11095: return 1;
11096: }
11097: }
11098: }
1.821 raeburn 11099: my $course = !$env{'user.adv'};
11100: if (!$env{'user.adv'}) {
11101: foreach my $env (keys(%env)) {
11102: next if ($env !~ m/^user\.priv\./);
11103: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
11104: $course = 0;
11105: last;
11106: }
11107: }
11108: }
11109: return $course;
11110: }
11111:
11112: ###############################################
11113:
11114: =pod
11115:
1.542 raeburn 11116: =item * &check_user_status()
1.274 raeburn 11117:
11118: Determines current status of supplied role for a
11119: specific user. Roles can be active, previous or future.
11120:
11121: Inputs:
11122: user's domain, user's username, course's domain,
1.375 raeburn 11123: course's number, optional section ID.
1.274 raeburn 11124:
11125: Outputs:
11126: role status: active, previous or future.
11127:
11128: =cut
11129:
11130: sub check_user_status {
1.412 raeburn 11131: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 11132: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 11133: my @uroles = keys(%userinfo);
1.274 raeburn 11134: my $srchstr;
11135: my $active_chk = 'none';
1.412 raeburn 11136: my $now = time;
1.274 raeburn 11137: if (@uroles > 0) {
1.908 raeburn 11138: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 11139: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
11140: } else {
1.412 raeburn 11141: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
11142: }
11143: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 11144: my $role_end = 0;
11145: my $role_start = 0;
11146: $active_chk = 'active';
1.412 raeburn 11147: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
11148: $role_end = $1;
11149: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
11150: $role_start = $1;
1.274 raeburn 11151: }
11152: }
11153: if ($role_start > 0) {
1.412 raeburn 11154: if ($now < $role_start) {
1.274 raeburn 11155: $active_chk = 'future';
11156: }
11157: }
11158: if ($role_end > 0) {
1.412 raeburn 11159: if ($now > $role_end) {
1.274 raeburn 11160: $active_chk = 'previous';
11161: }
11162: }
11163: }
11164: }
11165: return $active_chk;
11166: }
11167:
11168: ###############################################
11169:
11170: =pod
11171:
1.405 albertel 11172: =item * &get_sections()
1.233 raeburn 11173:
11174: Determines all the sections for a course including
11175: sections with students and sections containing other roles.
1.419 raeburn 11176: Incoming parameters:
11177:
11178: 1. domain
11179: 2. course number
11180: 3. reference to array containing roles for which sections should
11181: be gathered (optional).
11182: 4. reference to array containing status types for which sections
11183: should be gathered (optional).
11184:
11185: If the third argument is undefined, sections are gathered for any role.
11186: If the fourth argument is undefined, sections are gathered for any status.
11187: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 11188:
1.374 raeburn 11189: Returns section hash (keys are section IDs, values are
11190: number of users in each section), subject to the
1.419 raeburn 11191: optional roles filter, optional status filter
1.233 raeburn 11192:
11193: =cut
11194:
11195: ###############################################
11196: sub get_sections {
1.419 raeburn 11197: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 11198: if (!defined($cdom) || !defined($cnum)) {
11199: my $cid = $env{'request.course.id'};
11200:
11201: return if (!defined($cid));
11202:
11203: $cdom = $env{'course.'.$cid.'.domain'};
11204: $cnum = $env{'course.'.$cid.'.num'};
11205: }
11206:
11207: my %sectioncount;
1.419 raeburn 11208: my $now = time;
1.240 albertel 11209:
1.1118 raeburn 11210: my $check_students = 1;
11211: my $only_students = 0;
11212: if (ref($possible_roles) eq 'ARRAY') {
11213: if (grep(/^st$/,@{$possible_roles})) {
11214: if (@{$possible_roles} == 1) {
11215: $only_students = 1;
11216: }
11217: } else {
11218: $check_students = 0;
11219: }
11220: }
11221:
11222: if ($check_students) {
1.276 albertel 11223: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 11224: my $sec_index = &Apache::loncoursedata::CL_SECTION();
11225: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 11226: my $start_index = &Apache::loncoursedata::CL_START();
11227: my $end_index = &Apache::loncoursedata::CL_END();
11228: my $status;
1.366 albertel 11229: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 11230: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
11231: $data->[$status_index],
11232: $data->[$start_index],
11233: $data->[$end_index]);
11234: if ($stu_status eq 'Active') {
11235: $status = 'active';
11236: } elsif ($end < $now) {
11237: $status = 'previous';
11238: } elsif ($start > $now) {
11239: $status = 'future';
11240: }
11241: if ($section ne '-1' && $section !~ /^\s*$/) {
11242: if ((!defined($possible_status)) || (($status ne '') &&
11243: (grep/^\Q$status\E$/,@{$possible_status}))) {
11244: $sectioncount{$section}++;
11245: }
1.240 albertel 11246: }
11247: }
11248: }
1.1118 raeburn 11249: if ($only_students) {
11250: return %sectioncount;
11251: }
1.240 albertel 11252: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11253: foreach my $user (sort(keys(%courseroles))) {
11254: if ($user !~ /^(\w{2})/) { next; }
11255: my ($role) = ($user =~ /^(\w{2})/);
11256: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 11257: my ($section,$status);
1.240 albertel 11258: if ($role eq 'cr' &&
11259: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
11260: $section=$1;
11261: }
11262: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
11263: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 11264: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
11265: if ($end == -1 && $start == -1) {
11266: next; #deleted role
11267: }
11268: if (!defined($possible_status)) {
11269: $sectioncount{$section}++;
11270: } else {
11271: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
11272: $status = 'active';
11273: } elsif ($end < $now) {
11274: $status = 'future';
11275: } elsif ($start > $now) {
11276: $status = 'previous';
11277: }
11278: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
11279: $sectioncount{$section}++;
11280: }
11281: }
1.233 raeburn 11282: }
1.366 albertel 11283: return %sectioncount;
1.233 raeburn 11284: }
11285:
1.274 raeburn 11286: ###############################################
1.294 raeburn 11287:
11288: =pod
1.405 albertel 11289:
11290: =item * &get_course_users()
11291:
1.275 raeburn 11292: Retrieves usernames:domains for users in the specified course
11293: with specific role(s), and access status.
11294:
11295: Incoming parameters:
1.277 albertel 11296: 1. course domain
11297: 2. course number
11298: 3. access status: users must have - either active,
1.275 raeburn 11299: previous, future, or all.
1.277 albertel 11300: 4. reference to array of permissible roles
1.288 raeburn 11301: 5. reference to array of section restrictions (optional)
11302: 6. reference to results object (hash of hashes).
11303: 7. reference to optional userdata hash
1.609 raeburn 11304: 8. reference to optional statushash
1.630 raeburn 11305: 9. flag if privileged users (except those set to unhide in
11306: course settings) should be excluded
1.609 raeburn 11307: Keys of top level results hash are roles.
1.275 raeburn 11308: Keys of inner hashes are username:domain, with
11309: values set to access type.
1.288 raeburn 11310: Optional userdata hash returns an array with arguments in the
11311: same order as loncoursedata::get_classlist() for student data.
11312:
1.609 raeburn 11313: Optional statushash returns
11314:
1.288 raeburn 11315: Entries for end, start, section and status are blank because
11316: of the possibility of multiple values for non-student roles.
11317:
1.275 raeburn 11318: =cut
1.405 albertel 11319:
1.275 raeburn 11320: ###############################################
1.405 albertel 11321:
1.275 raeburn 11322: sub get_course_users {
1.630 raeburn 11323: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 11324: my %idx = ();
1.419 raeburn 11325: my %seclists;
1.288 raeburn 11326:
11327: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
11328: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
11329: $idx{end} = &Apache::loncoursedata::CL_END();
11330: $idx{start} = &Apache::loncoursedata::CL_START();
11331: $idx{id} = &Apache::loncoursedata::CL_ID();
11332: $idx{section} = &Apache::loncoursedata::CL_SECTION();
11333: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
11334: $idx{status} = &Apache::loncoursedata::CL_STATUS();
11335:
1.290 albertel 11336: if (grep(/^st$/,@{$roles})) {
1.276 albertel 11337: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 11338: my $now = time;
1.277 albertel 11339: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 11340: my $match = 0;
1.412 raeburn 11341: my $secmatch = 0;
1.419 raeburn 11342: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 11343: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 11344: if ($section eq '') {
11345: $section = 'none';
11346: }
1.291 albertel 11347: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 11348: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 11349: $secmatch = 1;
11350: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 11351: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 11352: $secmatch = 1;
11353: }
11354: } else {
1.419 raeburn 11355: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 11356: $secmatch = 1;
11357: }
1.290 albertel 11358: }
1.412 raeburn 11359: if (!$secmatch) {
11360: next;
11361: }
1.419 raeburn 11362: }
1.275 raeburn 11363: if (defined($$types{'active'})) {
1.288 raeburn 11364: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 11365: push(@{$$users{st}{$student}},'active');
1.288 raeburn 11366: $match = 1;
1.275 raeburn 11367: }
11368: }
11369: if (defined($$types{'previous'})) {
1.609 raeburn 11370: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 11371: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 11372: $match = 1;
1.275 raeburn 11373: }
11374: }
11375: if (defined($$types{'future'})) {
1.609 raeburn 11376: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 11377: push(@{$$users{st}{$student}},'future');
1.288 raeburn 11378: $match = 1;
1.275 raeburn 11379: }
11380: }
1.609 raeburn 11381: if ($match) {
11382: push(@{$seclists{$student}},$section);
11383: if (ref($userdata) eq 'HASH') {
11384: $$userdata{$student} = $$classlist{$student};
11385: }
11386: if (ref($statushash) eq 'HASH') {
11387: $statushash->{$student}{'st'}{$section} = $status;
11388: }
1.288 raeburn 11389: }
1.275 raeburn 11390: }
11391: }
1.412 raeburn 11392: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 11393: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11394: my $now = time;
1.609 raeburn 11395: my %displaystatus = ( previous => 'Expired',
11396: active => 'Active',
11397: future => 'Future',
11398: );
1.1121 raeburn 11399: my (%nothide,@possdoms);
1.630 raeburn 11400: if ($hidepriv) {
11401: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
11402: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
11403: if ($user !~ /:/) {
11404: $nothide{join(':',split(/[\@]/,$user))}=1;
11405: } else {
11406: $nothide{$user} = 1;
11407: }
11408: }
1.1121 raeburn 11409: my @possdoms = ($cdom);
11410: if ($coursehash{'checkforpriv'}) {
11411: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
11412: }
1.630 raeburn 11413: }
1.439 raeburn 11414: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 11415: my $match = 0;
1.412 raeburn 11416: my $secmatch = 0;
1.439 raeburn 11417: my $status;
1.412 raeburn 11418: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 11419: $user =~ s/:$//;
1.439 raeburn 11420: my ($end,$start) = split(/:/,$coursepersonnel{$person});
11421: if ($end == -1 || $start == -1) {
11422: next;
11423: }
11424: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
11425: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 11426: my ($uname,$udom) = split(/:/,$user);
11427: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 11428: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 11429: $secmatch = 1;
11430: } elsif ($usec eq '') {
1.420 albertel 11431: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 11432: $secmatch = 1;
11433: }
11434: } else {
11435: if (grep(/^\Q$usec\E$/,@{$sections})) {
11436: $secmatch = 1;
11437: }
11438: }
11439: if (!$secmatch) {
11440: next;
11441: }
1.288 raeburn 11442: }
1.419 raeburn 11443: if ($usec eq '') {
11444: $usec = 'none';
11445: }
1.275 raeburn 11446: if ($uname ne '' && $udom ne '') {
1.630 raeburn 11447: if ($hidepriv) {
1.1121 raeburn 11448: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 11449: (!$nothide{$uname.':'.$udom})) {
11450: next;
11451: }
11452: }
1.503 raeburn 11453: if ($end > 0 && $end < $now) {
1.439 raeburn 11454: $status = 'previous';
11455: } elsif ($start > $now) {
11456: $status = 'future';
11457: } else {
11458: $status = 'active';
11459: }
1.277 albertel 11460: foreach my $type (keys(%{$types})) {
1.275 raeburn 11461: if ($status eq $type) {
1.420 albertel 11462: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 11463: push(@{$$users{$role}{$user}},$type);
11464: }
1.288 raeburn 11465: $match = 1;
11466: }
11467: }
1.419 raeburn 11468: if (($match) && (ref($userdata) eq 'HASH')) {
11469: if (!exists($$userdata{$uname.':'.$udom})) {
11470: &get_user_info($udom,$uname,\%idx,$userdata);
11471: }
1.420 albertel 11472: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 11473: push(@{$seclists{$uname.':'.$udom}},$usec);
11474: }
1.609 raeburn 11475: if (ref($statushash) eq 'HASH') {
11476: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
11477: }
1.275 raeburn 11478: }
11479: }
11480: }
11481: }
1.290 albertel 11482: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 11483: if ((defined($cdom)) && (defined($cnum))) {
11484: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
11485: if ( defined($csettings{'internal.courseowner'}) ) {
11486: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 11487: next if ($owner eq '');
11488: my ($ownername,$ownerdom);
11489: if ($owner =~ /^([^:]+):([^:]+)$/) {
11490: $ownername = $1;
11491: $ownerdom = $2;
11492: } else {
11493: $ownername = $owner;
11494: $ownerdom = $cdom;
11495: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 11496: }
11497: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 11498: if (defined($userdata) &&
1.609 raeburn 11499: !exists($$userdata{$owner})) {
11500: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
11501: if (!grep(/^none$/,@{$seclists{$owner}})) {
11502: push(@{$seclists{$owner}},'none');
11503: }
11504: if (ref($statushash) eq 'HASH') {
11505: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 11506: }
1.290 albertel 11507: }
1.279 raeburn 11508: }
11509: }
11510: }
1.419 raeburn 11511: foreach my $user (keys(%seclists)) {
11512: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
11513: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
11514: }
1.275 raeburn 11515: }
11516: return;
11517: }
11518:
1.288 raeburn 11519: sub get_user_info {
11520: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 11521: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
11522: &plainname($uname,$udom,'lastname');
1.291 albertel 11523: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 11524: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 11525: my %idhash = &Apache::lonnet::idrget($udom,($uname));
11526: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 11527: return;
11528: }
1.275 raeburn 11529:
1.472 raeburn 11530: ###############################################
11531:
11532: =pod
11533:
11534: =item * &get_user_quota()
11535:
1.1134 raeburn 11536: Retrieves quota assigned for storage of user files.
11537: Default is to report quota for portfolio files.
1.472 raeburn 11538:
11539: Incoming parameters:
11540: 1. user's username
11541: 2. user's domain
1.1134 raeburn 11542: 3. quota name - portfolio, author, or course
1.1136 raeburn 11543: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 11544: 4. crstype - official, unofficial, textbook, placement or community,
11545: if quota name is course
1.472 raeburn 11546:
11547: Returns:
1.1163 raeburn 11548: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 11549: 2. (Optional) Type of setting: custom or default
11550: (individually assigned or default for user's
11551: institutional status).
11552: 3. (Optional) - User's institutional status (e.g., faculty, staff
11553: or student - types as defined in localenroll::inst_usertypes
11554: for user's domain, which determines default quota for user.
11555: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 11556:
11557: If a value has been stored in the user's environment,
1.536 raeburn 11558: it will return that, otherwise it returns the maximal default
1.1134 raeburn 11559: defined for the user's institutional status(es) in the domain.
1.472 raeburn 11560:
11561: =cut
11562:
11563: ###############################################
11564:
11565:
11566: sub get_user_quota {
1.1136 raeburn 11567: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 11568: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 11569: if (!defined($udom)) {
11570: $udom = $env{'user.domain'};
11571: }
11572: if (!defined($uname)) {
11573: $uname = $env{'user.name'};
11574: }
11575: if (($udom eq '' || $uname eq '') ||
11576: ($udom eq 'public') && ($uname eq 'public')) {
11577: $quota = 0;
1.536 raeburn 11578: $quotatype = 'default';
11579: $defquota = 0;
1.472 raeburn 11580: } else {
1.536 raeburn 11581: my $inststatus;
1.1134 raeburn 11582: if ($quotaname eq 'course') {
11583: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
11584: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
11585: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
11586: } else {
11587: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
11588: $quota = $cenv{'internal.uploadquota'};
11589: }
1.536 raeburn 11590: } else {
1.1134 raeburn 11591: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
11592: if ($quotaname eq 'author') {
11593: $quota = $env{'environment.authorquota'};
11594: } else {
11595: $quota = $env{'environment.portfolioquota'};
11596: }
11597: $inststatus = $env{'environment.inststatus'};
11598: } else {
11599: my %userenv =
11600: &Apache::lonnet::get('environment',['portfolioquota',
11601: 'authorquota','inststatus'],$udom,$uname);
11602: my ($tmp) = keys(%userenv);
11603: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
11604: if ($quotaname eq 'author') {
11605: $quota = $userenv{'authorquota'};
11606: } else {
11607: $quota = $userenv{'portfolioquota'};
11608: }
11609: $inststatus = $userenv{'inststatus'};
11610: } else {
11611: undef(%userenv);
11612: }
11613: }
11614: }
11615: if ($quota eq '' || wantarray) {
11616: if ($quotaname eq 'course') {
11617: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 11618: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 11619: ($crstype eq 'community') || ($crstype eq 'textbook') ||
11620: ($crstype eq 'placement')) {
1.1136 raeburn 11621: $defquota = $domdefs{$crstype.'quota'};
11622: }
11623: if ($defquota eq '') {
11624: $defquota = 500;
11625: }
1.1134 raeburn 11626: } else {
11627: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
11628: }
11629: if ($quota eq '') {
11630: $quota = $defquota;
11631: $quotatype = 'default';
11632: } else {
11633: $quotatype = 'custom';
11634: }
1.472 raeburn 11635: }
11636: }
1.536 raeburn 11637: if (wantarray) {
11638: return ($quota,$quotatype,$settingstatus,$defquota);
11639: } else {
11640: return $quota;
11641: }
1.472 raeburn 11642: }
11643:
11644: ###############################################
11645:
11646: =pod
11647:
11648: =item * &default_quota()
11649:
1.536 raeburn 11650: Retrieves default quota assigned for storage of user portfolio files,
11651: given an (optional) user's institutional status.
1.472 raeburn 11652:
11653: Incoming parameters:
1.1142 raeburn 11654:
1.472 raeburn 11655: 1. domain
1.536 raeburn 11656: 2. (Optional) institutional status(es). This is a : separated list of
11657: status types (e.g., faculty, staff, student etc.)
11658: which apply to the user for whom the default is being retrieved.
11659: If the institutional status string in undefined, the domain
1.1134 raeburn 11660: default quota will be returned.
11661: 3. quota name - portfolio, author, or course
11662: (if no quota name provided, defaults to portfolio).
1.472 raeburn 11663:
11664: Returns:
1.1142 raeburn 11665:
1.1163 raeburn 11666: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 11667: 2. (Optional) institutional type which determined the value of the
11668: default quota.
1.472 raeburn 11669:
11670: If a value has been stored in the domain's configuration db,
11671: it will return that, otherwise it returns 20 (for backwards
11672: compatibility with domains which have not set up a configuration
1.1163 raeburn 11673: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 11674:
1.536 raeburn 11675: If the user's status includes multiple types (e.g., staff and student),
11676: the largest default quota which applies to the user determines the
11677: default quota returned.
11678:
1.472 raeburn 11679: =cut
11680:
11681: ###############################################
11682:
11683:
11684: sub default_quota {
1.1134 raeburn 11685: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 11686: my ($defquota,$settingstatus);
11687: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 11688: ['quotas'],$udom);
1.1134 raeburn 11689: my $key = 'defaultquota';
11690: if ($quotaname eq 'author') {
11691: $key = 'authorquota';
11692: }
1.622 raeburn 11693: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 11694: if ($inststatus ne '') {
1.765 raeburn 11695: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 11696: foreach my $item (@statuses) {
1.1134 raeburn 11697: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11698: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 11699: if ($defquota eq '') {
1.1134 raeburn 11700: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11701: $settingstatus = $item;
1.1134 raeburn 11702: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
11703: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11704: $settingstatus = $item;
11705: }
11706: }
1.1134 raeburn 11707: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11708: if ($quotahash{'quotas'}{$item} ne '') {
11709: if ($defquota eq '') {
11710: $defquota = $quotahash{'quotas'}{$item};
11711: $settingstatus = $item;
11712: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
11713: $defquota = $quotahash{'quotas'}{$item};
11714: $settingstatus = $item;
11715: }
1.536 raeburn 11716: }
11717: }
11718: }
11719: }
11720: if ($defquota eq '') {
1.1134 raeburn 11721: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11722: $defquota = $quotahash{'quotas'}{$key}{'default'};
11723: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11724: $defquota = $quotahash{'quotas'}{'default'};
11725: }
1.536 raeburn 11726: $settingstatus = 'default';
1.1139 raeburn 11727: if ($defquota eq '') {
11728: if ($quotaname eq 'author') {
11729: $defquota = 500;
11730: }
11731: }
1.536 raeburn 11732: }
11733: } else {
11734: $settingstatus = 'default';
1.1134 raeburn 11735: if ($quotaname eq 'author') {
11736: $defquota = 500;
11737: } else {
11738: $defquota = 20;
11739: }
1.536 raeburn 11740: }
11741: if (wantarray) {
11742: return ($defquota,$settingstatus);
1.472 raeburn 11743: } else {
1.536 raeburn 11744: return $defquota;
1.472 raeburn 11745: }
11746: }
11747:
1.1135 raeburn 11748: ###############################################
11749:
11750: =pod
11751:
1.1136 raeburn 11752: =item * &excess_filesize_warning()
1.1135 raeburn 11753:
11754: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 11755: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 11756: space to be exceeded.
1.1136 raeburn 11757:
11758: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 11759: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 11760:
1.1165 raeburn 11761: Inputs: 7
1.1136 raeburn 11762: 1. username or coursenum
1.1135 raeburn 11763: 2. domain
1.1136 raeburn 11764: 3. context ('author' or 'course')
1.1135 raeburn 11765: 4. filename of file for which action is being requested
11766: 5. filesize (kB) of file
11767: 6. action being taken: copy or upload.
1.1237 raeburn 11768: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 11769:
11770: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 11771: otherwise return null.
11772:
11773: =back
1.1135 raeburn 11774:
11775: =cut
11776:
1.1136 raeburn 11777: sub excess_filesize_warning {
1.1165 raeburn 11778: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 11779: my $current_disk_usage = 0;
1.1165 raeburn 11780: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 11781: if ($context eq 'author') {
11782: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
11783: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
11784: } else {
11785: foreach my $subdir ('docs','supplemental') {
11786: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
11787: }
11788: }
1.1135 raeburn 11789: $disk_quota = int($disk_quota * 1000);
11790: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 11791: return '<p class="LC_warning">'.
1.1135 raeburn 11792: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 11793: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
11794: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 11795: $disk_quota,$current_disk_usage).
11796: '</p>';
11797: }
11798: return;
11799: }
11800:
11801: ###############################################
11802:
11803:
1.1136 raeburn 11804:
11805:
1.384 raeburn 11806: sub get_secgrprole_info {
11807: my ($cdom,$cnum,$needroles,$type) = @_;
11808: my %sections_count = &get_sections($cdom,$cnum);
11809: my @sections = (sort {$a <=> $b} keys(%sections_count));
11810: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
11811: my @groups = sort(keys(%curr_groups));
11812: my $allroles = [];
11813: my $rolehash;
11814: my $accesshash = {
11815: active => 'Currently has access',
11816: future => 'Will have future access',
11817: previous => 'Previously had access',
11818: };
11819: if ($needroles) {
11820: $rolehash = {'all' => 'all'};
1.385 albertel 11821: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11822: if (&Apache::lonnet::error(%user_roles)) {
11823: undef(%user_roles);
11824: }
11825: foreach my $item (keys(%user_roles)) {
1.384 raeburn 11826: my ($role)=split(/\:/,$item,2);
11827: if ($role eq 'cr') { next; }
11828: if ($role =~ /^cr/) {
11829: $$rolehash{$role} = (split('/',$role))[3];
11830: } else {
11831: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
11832: }
11833: }
11834: foreach my $key (sort(keys(%{$rolehash}))) {
11835: push(@{$allroles},$key);
11836: }
11837: push (@{$allroles},'st');
11838: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
11839: }
11840: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
11841: }
11842:
1.555 raeburn 11843: sub user_picker {
1.1279 raeburn 11844: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 11845: my $currdom = $dom;
1.1253 raeburn 11846: my @alldoms = &Apache::lonnet::all_domains();
11847: if (@alldoms == 1) {
11848: my %domsrch = &Apache::lonnet::get_dom('configuration',
11849: ['directorysrch'],$alldoms[0]);
11850: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
11851: my $showdom = $domdesc;
11852: if ($showdom eq '') {
11853: $showdom = $dom;
11854: }
11855: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
11856: if ((!$domsrch{'directorysrch'}{'available'}) &&
11857: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
11858: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
11859: }
11860: }
11861: }
1.555 raeburn 11862: my %curr_selected = (
11863: srchin => 'dom',
1.580 raeburn 11864: srchby => 'lastname',
1.555 raeburn 11865: );
11866: my $srchterm;
1.625 raeburn 11867: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 11868: if ($srch->{'srchby'} ne '') {
11869: $curr_selected{'srchby'} = $srch->{'srchby'};
11870: }
11871: if ($srch->{'srchin'} ne '') {
11872: $curr_selected{'srchin'} = $srch->{'srchin'};
11873: }
11874: if ($srch->{'srchtype'} ne '') {
11875: $curr_selected{'srchtype'} = $srch->{'srchtype'};
11876: }
11877: if ($srch->{'srchdomain'} ne '') {
11878: $currdom = $srch->{'srchdomain'};
11879: }
11880: $srchterm = $srch->{'srchterm'};
11881: }
1.1222 damieng 11882: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 11883: 'usr' => 'Search criteria',
1.563 raeburn 11884: 'doma' => 'Domain/institution to search',
1.558 albertel 11885: 'uname' => 'username',
11886: 'lastname' => 'last name',
1.555 raeburn 11887: 'lastfirst' => 'last name, first name',
1.558 albertel 11888: 'crs' => 'in this course',
1.576 raeburn 11889: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 11890: 'alc' => 'all LON-CAPA',
1.573 raeburn 11891: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 11892: 'exact' => 'is',
11893: 'contains' => 'contains',
1.569 raeburn 11894: 'begins' => 'begins with',
1.1222 damieng 11895: );
11896: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 11897: 'youm' => "You must include some text to search for.",
11898: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
11899: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
11900: 'yomc' => "You must choose a domain when using an institutional directory search.",
11901: 'ymcd' => "You must choose a domain when using a domain search.",
11902: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
11903: 'whse' => "When searching by last,first you must include at least one character in the first name.",
11904: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 11905: );
1.1222 damieng 11906: &html_escape(\%html_lt);
11907: &js_escape(\%js_lt);
1.1255 raeburn 11908: my $domform;
1.1277 raeburn 11909: my $allow_blank = 1;
1.1255 raeburn 11910: if ($fixeddom) {
1.1277 raeburn 11911: $allow_blank = 0;
11912: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 11913: } else {
1.1287 raeburn 11914: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 11915: my ($trusted,$untrusted);
1.1287 raeburn 11916: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 11917: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 11918: } elsif ($context eq 'author') {
1.1288 raeburn 11919: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 11920: } elsif ($context eq 'domain') {
1.1288 raeburn 11921: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 11922: }
1.1288 raeburn 11923: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 11924: }
1.563 raeburn 11925: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 11926:
11927: my @srchins = ('crs','dom','alc','instd');
11928:
11929: foreach my $option (@srchins) {
11930: # FIXME 'alc' option unavailable until
11931: # loncreateuser::print_user_query_page()
11932: # has been completed.
11933: next if ($option eq 'alc');
1.880 raeburn 11934: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 11935: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 11936: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 11937: if ($curr_selected{'srchin'} eq $option) {
11938: $srchinsel .= '
1.1222 damieng 11939: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 11940: } else {
11941: $srchinsel .= '
1.1222 damieng 11942: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 11943: }
1.555 raeburn 11944: }
1.563 raeburn 11945: $srchinsel .= "\n </select>\n";
1.555 raeburn 11946:
11947: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 11948: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 11949: if ($curr_selected{'srchby'} eq $option) {
11950: $srchbysel .= '
1.1222 damieng 11951: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11952: } else {
11953: $srchbysel .= '
1.1222 damieng 11954: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11955: }
11956: }
11957: $srchbysel .= "\n </select>\n";
11958:
11959: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 11960: foreach my $option ('begins','contains','exact') {
1.555 raeburn 11961: if ($curr_selected{'srchtype'} eq $option) {
11962: $srchtypesel .= '
1.1222 damieng 11963: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11964: } else {
11965: $srchtypesel .= '
1.1222 damieng 11966: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11967: }
11968: }
11969: $srchtypesel .= "\n </select>\n";
11970:
1.558 albertel 11971: my ($newuserscript,$new_user_create);
1.994 raeburn 11972: my $context_dom = $env{'request.role.domain'};
11973: if ($context eq 'requestcrs') {
11974: if ($env{'form.coursedom'} ne '') {
11975: $context_dom = $env{'form.coursedom'};
11976: }
11977: }
1.556 raeburn 11978: if ($forcenewuser) {
1.576 raeburn 11979: if (ref($srch) eq 'HASH') {
1.994 raeburn 11980: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 11981: if ($cancreate) {
11982: $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>';
11983: } else {
1.799 bisitz 11984: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 11985: my %usertypetext = (
11986: official => 'institutional',
11987: unofficial => 'non-institutional',
11988: );
1.799 bisitz 11989: $new_user_create = '<p class="LC_warning">'
11990: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
11991: .' '
11992: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
11993: ,'<a href="'.$helplink.'">','</a>')
11994: .'</p><br />';
1.627 raeburn 11995: }
1.576 raeburn 11996: }
11997: }
11998:
1.556 raeburn 11999: $newuserscript = <<"ENDSCRIPT";
12000:
1.570 raeburn 12001: function setSearch(createnew,callingForm) {
1.556 raeburn 12002: if (createnew == 1) {
1.570 raeburn 12003: for (var i=0; i<callingForm.srchby.length; i++) {
12004: if (callingForm.srchby.options[i].value == 'uname') {
12005: callingForm.srchby.selectedIndex = i;
1.556 raeburn 12006: }
12007: }
1.570 raeburn 12008: for (var i=0; i<callingForm.srchin.length; i++) {
12009: if ( callingForm.srchin.options[i].value == 'dom') {
12010: callingForm.srchin.selectedIndex = i;
1.556 raeburn 12011: }
12012: }
1.570 raeburn 12013: for (var i=0; i<callingForm.srchtype.length; i++) {
12014: if (callingForm.srchtype.options[i].value == 'exact') {
12015: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 12016: }
12017: }
1.570 raeburn 12018: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 12019: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 12020: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 12021: }
12022: }
12023: }
12024: }
12025: ENDSCRIPT
1.558 albertel 12026:
1.556 raeburn 12027: }
12028:
1.555 raeburn 12029: my $output = <<"END_BLOCK";
1.556 raeburn 12030: <script type="text/javascript">
1.824 bisitz 12031: // <![CDATA[
1.570 raeburn 12032: function validateEntry(callingForm) {
1.558 albertel 12033:
1.556 raeburn 12034: var checkok = 1;
1.558 albertel 12035: var srchin;
1.570 raeburn 12036: for (var i=0; i<callingForm.srchin.length; i++) {
12037: if ( callingForm.srchin[i].checked ) {
12038: srchin = callingForm.srchin[i].value;
1.558 albertel 12039: }
12040: }
12041:
1.570 raeburn 12042: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
12043: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
12044: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
12045: var srchterm = callingForm.srchterm.value;
12046: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 12047: var msg = "";
12048:
12049: if (srchterm == "") {
12050: checkok = 0;
1.1222 damieng 12051: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 12052: }
12053:
1.569 raeburn 12054: if (srchtype== 'begins') {
12055: if (srchterm.length < 2) {
12056: checkok = 0;
1.1222 damieng 12057: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 12058: }
12059: }
12060:
1.556 raeburn 12061: if (srchtype== 'contains') {
12062: if (srchterm.length < 3) {
12063: checkok = 0;
1.1222 damieng 12064: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 12065: }
12066: }
12067: if (srchin == 'instd') {
12068: if (srchdomain == '') {
12069: checkok = 0;
1.1222 damieng 12070: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 12071: }
12072: }
12073: if (srchin == 'dom') {
12074: if (srchdomain == '') {
12075: checkok = 0;
1.1222 damieng 12076: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 12077: }
12078: }
12079: if (srchby == 'lastfirst') {
12080: if (srchterm.indexOf(",") == -1) {
12081: checkok = 0;
1.1222 damieng 12082: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 12083: }
12084: if (srchterm.indexOf(",") == srchterm.length -1) {
12085: checkok = 0;
1.1222 damieng 12086: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 12087: }
12088: }
12089: if (checkok == 0) {
1.1222 damieng 12090: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 12091: return;
12092: }
12093: if (checkok == 1) {
1.570 raeburn 12094: callingForm.submit();
1.556 raeburn 12095: }
12096: }
12097:
12098: $newuserscript
12099:
1.824 bisitz 12100: // ]]>
1.556 raeburn 12101: </script>
1.558 albertel 12102:
12103: $new_user_create
12104:
1.555 raeburn 12105: END_BLOCK
1.558 albertel 12106:
1.876 raeburn 12107: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 12108: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 12109: $domform.
12110: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 12111: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 12112: $srchbysel.
12113: $srchtypesel.
12114: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
12115: $srchinsel.
12116: &Apache::lonhtmlcommon::row_closure(1).
12117: &Apache::lonhtmlcommon::end_pick_box().
12118: '<br />';
1.1253 raeburn 12119: return ($output,1);
1.555 raeburn 12120: }
12121:
1.612 raeburn 12122: sub user_rule_check {
1.615 raeburn 12123: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 12124: my ($response,%inst_response);
1.612 raeburn 12125: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 12126: if (keys(%{$usershash}) > 1) {
12127: my (%by_username,%by_id,%userdoms);
12128: my $checkid;
12129: if (ref($checks) eq 'HASH') {
12130: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
12131: $checkid = 1;
12132: }
12133: }
12134: foreach my $user (keys(%{$usershash})) {
12135: my ($uname,$udom) = split(/:/,$user);
12136: if ($checkid) {
12137: if (ref($usershash->{$user}) eq 'HASH') {
12138: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 12139: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 12140: $userdoms{$udom} = 1;
1.1227 raeburn 12141: if (ref($inst_results) eq 'HASH') {
12142: $inst_results->{$uname.':'.$udom} = {};
12143: }
1.1226 raeburn 12144: }
12145: }
12146: } else {
12147: $by_username{$udom}{$uname} = 1;
12148: $userdoms{$udom} = 1;
1.1227 raeburn 12149: if (ref($inst_results) eq 'HASH') {
12150: $inst_results->{$uname.':'.$udom} = {};
12151: }
1.1226 raeburn 12152: }
12153: }
12154: foreach my $udom (keys(%userdoms)) {
12155: if (!$got_rules->{$udom}) {
12156: my %domconfig = &Apache::lonnet::get_dom('configuration',
12157: ['usercreation'],$udom);
12158: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12159: foreach my $item ('username','id') {
12160: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 12161: $$curr_rules{$udom}{$item} =
12162: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 12163: }
12164: }
12165: }
12166: $got_rules->{$udom} = 1;
12167: }
1.612 raeburn 12168: }
1.1226 raeburn 12169: if ($checkid) {
12170: foreach my $udom (keys(%by_id)) {
12171: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
12172: if ($outcome eq 'ok') {
1.1227 raeburn 12173: foreach my $id (keys(%{$by_id{$udom}})) {
12174: my $uname = $by_id{$udom}{$id};
12175: $inst_response{$uname.':'.$udom} = $outcome;
12176: }
1.1226 raeburn 12177: if (ref($results) eq 'HASH') {
12178: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 12179: if (exists($inst_response{$uname.':'.$udom})) {
12180: $inst_response{$uname.':'.$udom} = $outcome;
12181: $inst_results->{$uname.':'.$udom} = $results->{$uname};
12182: }
1.1226 raeburn 12183: }
12184: }
12185: }
1.612 raeburn 12186: }
1.615 raeburn 12187: } else {
1.1226 raeburn 12188: foreach my $udom (keys(%by_username)) {
12189: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
12190: if ($outcome eq 'ok') {
1.1227 raeburn 12191: foreach my $uname (keys(%{$by_username{$udom}})) {
12192: $inst_response{$uname.':'.$udom} = $outcome;
12193: }
1.1226 raeburn 12194: if (ref($results) eq 'HASH') {
12195: foreach my $uname (keys(%{$results})) {
12196: $inst_results->{$uname.':'.$udom} = $results->{$uname};
12197: }
12198: }
12199: }
12200: }
1.612 raeburn 12201: }
1.1226 raeburn 12202: } elsif (keys(%{$usershash}) == 1) {
12203: my $user = (keys(%{$usershash}))[0];
12204: my ($uname,$udom) = split(/:/,$user);
12205: if (($udom ne '') && ($uname ne '')) {
12206: if (ref($usershash->{$user}) eq 'HASH') {
12207: if (ref($checks) eq 'HASH') {
12208: if (defined($checks->{'username'})) {
12209: ($inst_response{$user},%{$inst_results->{$user}}) =
12210: &Apache::lonnet::get_instuser($udom,$uname);
12211: } elsif (defined($checks->{'id'})) {
12212: if ($usershash->{$user}->{'id'} ne '') {
12213: ($inst_response{$user},%{$inst_results->{$user}}) =
12214: &Apache::lonnet::get_instuser($udom,undef,
12215: $usershash->{$user}->{'id'});
12216: } else {
12217: ($inst_response{$user},%{$inst_results->{$user}}) =
12218: &Apache::lonnet::get_instuser($udom,$uname);
12219: }
1.585 raeburn 12220: }
1.1226 raeburn 12221: } else {
12222: ($inst_response{$user},%{$inst_results->{$user}}) =
12223: &Apache::lonnet::get_instuser($udom,$uname);
12224: return;
12225: }
12226: if (!$got_rules->{$udom}) {
12227: my %domconfig = &Apache::lonnet::get_dom('configuration',
12228: ['usercreation'],$udom);
12229: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12230: foreach my $item ('username','id') {
12231: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
12232: $$curr_rules{$udom}{$item} =
12233: $domconfig{'usercreation'}{$item.'_rule'};
12234: }
12235: }
12236: }
12237: $got_rules->{$udom} = 1;
1.585 raeburn 12238: }
12239: }
1.1226 raeburn 12240: } else {
12241: return;
12242: }
12243: } else {
12244: return;
12245: }
12246: foreach my $user (keys(%{$usershash})) {
12247: my ($uname,$udom) = split(/:/,$user);
12248: next if (($udom eq '') || ($uname eq ''));
12249: my $id;
1.1227 raeburn 12250: if (ref($inst_results) eq 'HASH') {
12251: if (ref($inst_results->{$user}) eq 'HASH') {
12252: $id = $inst_results->{$user}->{'id'};
12253: }
12254: }
12255: if ($id eq '') {
12256: if (ref($usershash->{$user})) {
12257: $id = $usershash->{$user}->{'id'};
12258: }
1.585 raeburn 12259: }
1.612 raeburn 12260: foreach my $item (keys(%{$checks})) {
12261: if (ref($$curr_rules{$udom}) eq 'HASH') {
12262: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
12263: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 12264: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
12265: $$curr_rules{$udom}{$item});
1.612 raeburn 12266: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
12267: if ($rule_check{$rule}) {
12268: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 12269: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 12270: if (ref($inst_results) eq 'HASH') {
12271: if (ref($inst_results->{$user}) eq 'HASH') {
12272: if (keys(%{$inst_results->{$user}}) == 0) {
12273: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 12274: } elsif ($item eq 'id') {
12275: if ($inst_results->{$user}->{'id'} eq '') {
12276: $$alerts{$item}{$udom}{$uname} = 1;
12277: }
1.615 raeburn 12278: }
1.612 raeburn 12279: }
12280: }
1.615 raeburn 12281: }
12282: last;
1.585 raeburn 12283: }
12284: }
12285: }
12286: }
12287: }
12288: }
12289: }
12290: }
1.612 raeburn 12291: return;
12292: }
12293:
12294: sub user_rule_formats {
12295: my ($domain,$domdesc,$curr_rules,$check) = @_;
12296: my %text = (
12297: 'username' => 'Usernames',
12298: 'id' => 'IDs',
12299: );
12300: my $output;
12301: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
12302: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
12303: if (@{$ruleorder} > 0) {
1.1102 raeburn 12304: $output = '<br />'.
12305: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
12306: '<span class="LC_cusr_emph">','</span>',$domdesc).
12307: ' <ul>';
1.612 raeburn 12308: foreach my $rule (@{$ruleorder}) {
12309: if (ref($curr_rules) eq 'ARRAY') {
12310: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
12311: if (ref($rules->{$rule}) eq 'HASH') {
12312: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
12313: $rules->{$rule}{'desc'}.'</li>';
12314: }
12315: }
12316: }
12317: }
12318: $output .= '</ul>';
12319: }
12320: }
12321: return $output;
12322: }
12323:
12324: sub instrule_disallow_msg {
1.615 raeburn 12325: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 12326: my $response;
12327: my %text = (
12328: item => 'username',
12329: items => 'usernames',
12330: match => 'matches',
12331: do => 'does',
12332: action => 'a username',
12333: one => 'one',
12334: );
12335: if ($count > 1) {
12336: $text{'item'} = 'usernames';
12337: $text{'match'} ='match';
12338: $text{'do'} = 'do';
12339: $text{'action'} = 'usernames',
12340: $text{'one'} = 'ones';
12341: }
12342: if ($checkitem eq 'id') {
12343: $text{'items'} = 'IDs';
12344: $text{'item'} = 'ID';
12345: $text{'action'} = 'an ID';
1.615 raeburn 12346: if ($count > 1) {
12347: $text{'item'} = 'IDs';
12348: $text{'action'} = 'IDs';
12349: }
1.612 raeburn 12350: }
1.674 bisitz 12351: $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 12352: if ($mode eq 'upload') {
12353: if ($checkitem eq 'username') {
12354: $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'}.");
12355: } elsif ($checkitem eq 'id') {
1.674 bisitz 12356: $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 12357: }
1.669 raeburn 12358: } elsif ($mode eq 'selfcreate') {
12359: if ($checkitem eq 'id') {
12360: $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.");
12361: }
1.615 raeburn 12362: } else {
12363: if ($checkitem eq 'username') {
12364: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
12365: } elsif ($checkitem eq 'id') {
12366: $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.");
12367: }
1.612 raeburn 12368: }
12369: return $response;
1.585 raeburn 12370: }
12371:
1.624 raeburn 12372: sub personal_data_fieldtitles {
12373: my %fieldtitles = &Apache::lonlocal::texthash (
12374: id => 'Student/Employee ID',
12375: permanentemail => 'E-mail address',
12376: lastname => 'Last Name',
12377: firstname => 'First Name',
12378: middlename => 'Middle Name',
12379: generation => 'Generation',
12380: gen => 'Generation',
1.765 raeburn 12381: inststatus => 'Affiliation',
1.624 raeburn 12382: );
12383: return %fieldtitles;
12384: }
12385:
1.642 raeburn 12386: sub sorted_inst_types {
12387: my ($dom) = @_;
1.1185 raeburn 12388: my ($usertypes,$order);
12389: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12390: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
12391: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
12392: $order = $domdefaults{'inststatus'}{'inststatusorder'};
12393: } else {
12394: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
12395: }
1.642 raeburn 12396: my $othertitle = &mt('All users');
12397: if ($env{'request.course.id'}) {
1.668 raeburn 12398: $othertitle = &mt('Any users');
1.642 raeburn 12399: }
12400: my @types;
12401: if (ref($order) eq 'ARRAY') {
12402: @types = @{$order};
12403: }
12404: if (@types == 0) {
12405: if (ref($usertypes) eq 'HASH') {
12406: @types = sort(keys(%{$usertypes}));
12407: }
12408: }
12409: if (keys(%{$usertypes}) > 0) {
12410: $othertitle = &mt('Other users');
12411: }
12412: return ($othertitle,$usertypes,\@types);
12413: }
12414:
1.645 raeburn 12415: sub get_institutional_codes {
1.1361 raeburn 12416: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 12417: # Get complete list of course sections to update
12418: my @currsections = ();
12419: my @currxlists = ();
1.1361 raeburn 12420: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 12421: my $coursecode = $$settings{'internal.coursecode'};
1.1361 raeburn 12422: my $crskey = $crs.':'.$coursecode;
12423: @{$unclutteredsec{$crskey}} = ();
12424: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 12425:
12426: if ($$settings{'internal.sectionnums'} ne '') {
12427: @currsections = split(/,/,$$settings{'internal.sectionnums'});
12428: }
12429:
12430: if ($$settings{'internal.crosslistings'} ne '') {
12431: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
12432: }
12433:
12434: if (@currxlists > 0) {
1.1361 raeburn 12435: foreach my $xl (@currxlists) {
12436: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 12437: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 12438: push(@{$allcourses},$1);
1.645 raeburn 12439: $$LC_code{$1} = $2;
12440: }
12441: }
12442: }
12443: }
1.1361 raeburn 12444:
1.645 raeburn 12445: if (@currsections > 0) {
1.1361 raeburn 12446: foreach my $sec (@currsections) {
12447: if ($sec =~ m/^(\w+):(\w*)$/ ) {
12448: my $instsec = $1;
1.645 raeburn 12449: my $lc_sec = $2;
1.1361 raeburn 12450: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
12451: push(@{$unclutteredsec{$crskey}},$instsec);
12452: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
12453: }
12454: }
12455: }
12456: }
12457:
12458: if (@{$unclutteredsec{$crskey}} > 0) {
12459: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
12460: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
12461: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
12462: my $sec = $coursecode.$formattedsec{$crskey}[$i];
12463: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1263 raeburn 12464: push(@{$allcourses},$sec);
1.1361 raeburn 12465: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 12466: }
12467: }
12468: }
12469: }
12470: return;
12471: }
12472:
1.971 raeburn 12473: sub get_standard_codeitems {
12474: return ('Year','Semester','Department','Number','Section');
12475: }
12476:
1.112 bowersj2 12477: =pod
12478:
1.780 raeburn 12479: =head1 Slot Helpers
12480:
12481: =over 4
12482:
12483: =item * sorted_slots()
12484:
1.1040 raeburn 12485: Sorts an array of slot names in order of an optional sort key,
12486: default sort is by slot start time (earliest first).
1.780 raeburn 12487:
12488: Inputs:
12489:
12490: =over 4
12491:
12492: slotsarr - Reference to array of unsorted slot names.
12493:
12494: slots - Reference to hash of hash, where outer hash keys are slot names.
12495:
1.1040 raeburn 12496: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
12497:
1.549 albertel 12498: =back
12499:
1.780 raeburn 12500: Returns:
12501:
12502: =over 4
12503:
1.1040 raeburn 12504: sorted - An array of slot names sorted by a specified sort key
12505: (default sort key is start time of the slot).
1.780 raeburn 12506:
12507: =back
12508:
12509: =cut
12510:
12511:
12512: sub sorted_slots {
1.1040 raeburn 12513: my ($slotsarr,$slots,$sortkey) = @_;
12514: if ($sortkey eq '') {
12515: $sortkey = 'starttime';
12516: }
1.780 raeburn 12517: my @sorted;
12518: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
12519: @sorted =
12520: sort {
12521: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 12522: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 12523: }
12524: if (ref($slots->{$a})) { return -1;}
12525: if (ref($slots->{$b})) { return 1;}
12526: return 0;
12527: } @{$slotsarr};
12528: }
12529: return @sorted;
12530: }
12531:
1.1040 raeburn 12532: =pod
12533:
12534: =item * get_future_slots()
12535:
12536: Inputs:
12537:
12538: =over 4
12539:
12540: cnum - course number
12541:
12542: cdom - course domain
12543:
12544: now - current UNIX time
12545:
12546: symb - optional symb
12547:
12548: =back
12549:
12550: Returns:
12551:
12552: =over 4
12553:
12554: sorted_reservable - ref to array of student_schedulable slots currently
12555: reservable, ordered by end date of reservation period.
12556:
12557: reservable_now - ref to hash of student_schedulable slots currently
12558: reservable.
12559:
12560: Keys in inner hash are:
12561: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 12562: (b) endreserve: end date of reservation period.
12563: (c) uniqueperiod: start,end dates when slot is to be uniquely
12564: selected.
1.1040 raeburn 12565:
12566: sorted_future - ref to array of student_schedulable slots reservable in
12567: the future, ordered by start date of reservation period.
12568:
12569: future_reservable - ref to hash of student_schedulable slots reservable
12570: in the future.
12571:
12572: Keys in inner hash are:
12573: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 12574: (b) startreserve: start date of reservation period.
12575: (c) uniqueperiod: start,end dates when slot is to be uniquely
12576: selected.
1.1040 raeburn 12577:
12578: =back
12579:
12580: =cut
12581:
12582: sub get_future_slots {
12583: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 12584: my $map;
12585: if ($symb) {
12586: ($map) = &Apache::lonnet::decode_symb($symb);
12587: }
1.1040 raeburn 12588: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
12589: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
12590: foreach my $slot (keys(%slots)) {
12591: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
12592: if ($symb) {
1.1229 raeburn 12593: if ($slots{$slot}->{'symb'} ne '') {
12594: my $canuse;
12595: my %oksymbs;
12596: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
12597: map { $oksymbs{$_} = 1; } @slotsymbs;
12598: if ($oksymbs{$symb}) {
12599: $canuse = 1;
12600: } else {
12601: foreach my $item (@slotsymbs) {
12602: if ($item =~ /\.(page|sequence)$/) {
12603: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
12604: if (($map ne '') && ($map eq $sloturl)) {
12605: $canuse = 1;
12606: last;
12607: }
12608: }
12609: }
12610: }
12611: next unless ($canuse);
12612: }
1.1040 raeburn 12613: }
12614: if (($slots{$slot}->{'starttime'} > $now) &&
12615: ($slots{$slot}->{'endtime'} > $now)) {
12616: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
12617: my $userallowed = 0;
12618: if ($slots{$slot}->{'allowedsections'}) {
12619: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
12620: if (!defined($env{'request.role.sec'})
12621: && grep(/^No section assigned$/,@allowed_sec)) {
12622: $userallowed=1;
12623: } else {
12624: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
12625: $userallowed=1;
12626: }
12627: }
12628: unless ($userallowed) {
12629: if (defined($env{'request.course.groups'})) {
12630: my @groups = split(/:/,$env{'request.course.groups'});
12631: foreach my $group (@groups) {
12632: if (grep(/^\Q$group\E$/,@allowed_sec)) {
12633: $userallowed=1;
12634: last;
12635: }
12636: }
12637: }
12638: }
12639: }
12640: if ($slots{$slot}->{'allowedusers'}) {
12641: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
12642: my $user = $env{'user.name'}.':'.$env{'user.domain'};
12643: if (grep(/^\Q$user\E$/,@allowed_users)) {
12644: $userallowed = 1;
12645: }
12646: }
12647: next unless($userallowed);
12648: }
12649: my $startreserve = $slots{$slot}->{'startreserve'};
12650: my $endreserve = $slots{$slot}->{'endreserve'};
12651: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 12652: my $uniqueperiod;
12653: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
12654: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
12655: }
1.1040 raeburn 12656: if (($startreserve < $now) &&
12657: (!$endreserve || $endreserve > $now)) {
12658: my $lastres = $endreserve;
12659: if (!$lastres) {
12660: $lastres = $slots{$slot}->{'starttime'};
12661: }
12662: $reservable_now{$slot} = {
12663: symb => $symb,
1.1250 raeburn 12664: endreserve => $lastres,
12665: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12666: };
12667: } elsif (($startreserve > $now) &&
12668: (!$endreserve || $endreserve > $startreserve)) {
12669: $future_reservable{$slot} = {
12670: symb => $symb,
1.1250 raeburn 12671: startreserve => $startreserve,
12672: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12673: };
12674: }
12675: }
12676: }
12677: my @unsorted_reservable = keys(%reservable_now);
12678: if (@unsorted_reservable > 0) {
12679: @sorted_reservable =
12680: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
12681: }
12682: my @unsorted_future = keys(%future_reservable);
12683: if (@unsorted_future > 0) {
12684: @sorted_future =
12685: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
12686: }
12687: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
12688: }
1.780 raeburn 12689:
12690: =pod
12691:
1.1057 foxr 12692: =back
12693:
1.549 albertel 12694: =head1 HTTP Helpers
12695:
12696: =over 4
12697:
1.648 raeburn 12698: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 12699:
1.258 albertel 12700: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 12701: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 12702: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 12703:
12704: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
12705: $possible_names is an ref to an array of form element names. As an example:
12706: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 12707: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 12708:
12709: =cut
1.1 albertel 12710:
1.6 albertel 12711: sub get_unprocessed_cgi {
1.25 albertel 12712: my ($query,$possible_names)= @_;
1.26 matthew 12713: # $Apache::lonxml::debug=1;
1.356 albertel 12714: foreach my $pair (split(/&/,$query)) {
12715: my ($name, $value) = split(/=/,$pair);
1.369 www 12716: $name = &unescape($name);
1.25 albertel 12717: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
12718: $value =~ tr/+/ /;
12719: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 12720: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 12721: }
1.16 harris41 12722: }
1.6 albertel 12723: }
12724:
1.112 bowersj2 12725: =pod
12726:
1.648 raeburn 12727: =item * &cacheheader()
1.112 bowersj2 12728:
12729: returns cache-controlling header code
12730:
12731: =cut
12732:
1.7 albertel 12733: sub cacheheader {
1.258 albertel 12734: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 12735: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
12736: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 12737: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
12738: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 12739: return $output;
1.7 albertel 12740: }
12741:
1.112 bowersj2 12742: =pod
12743:
1.648 raeburn 12744: =item * &no_cache($r)
1.112 bowersj2 12745:
12746: specifies header code to not have cache
12747:
12748: =cut
12749:
1.9 albertel 12750: sub no_cache {
1.216 albertel 12751: my ($r) = @_;
12752: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 12753: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 12754: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
12755: $r->no_cache(1);
12756: $r->header_out("Expires" => $date);
12757: $r->header_out("Pragma" => "no-cache");
1.123 www 12758: }
12759:
12760: sub content_type {
1.181 albertel 12761: my ($r,$type,$charset) = @_;
1.299 foxr 12762: if ($r) {
12763: # Note that printout.pl calls this with undef for $r.
12764: &no_cache($r);
12765: }
1.258 albertel 12766: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 12767: unless ($charset) {
12768: $charset=&Apache::lonlocal::current_encoding;
12769: }
12770: if ($charset) { $type.='; charset='.$charset; }
12771: if ($r) {
12772: $r->content_type($type);
12773: } else {
12774: print("Content-type: $type\n\n");
12775: }
1.9 albertel 12776: }
1.25 albertel 12777:
1.112 bowersj2 12778: =pod
12779:
1.648 raeburn 12780: =item * &add_to_env($name,$value)
1.112 bowersj2 12781:
1.258 albertel 12782: adds $name to the %env hash with value
1.112 bowersj2 12783: $value, if $name already exists, the entry is converted to an array
12784: reference and $value is added to the array.
12785:
12786: =cut
12787:
1.25 albertel 12788: sub add_to_env {
12789: my ($name,$value)=@_;
1.258 albertel 12790: if (defined($env{$name})) {
12791: if (ref($env{$name})) {
1.25 albertel 12792: #already have multiple values
1.258 albertel 12793: push(@{ $env{$name} },$value);
1.25 albertel 12794: } else {
12795: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 12796: my $first=$env{$name};
12797: undef($env{$name});
12798: push(@{ $env{$name} },$first,$value);
1.25 albertel 12799: }
12800: } else {
1.258 albertel 12801: $env{$name}=$value;
1.25 albertel 12802: }
1.31 albertel 12803: }
1.149 albertel 12804:
12805: =pod
12806:
1.648 raeburn 12807: =item * &get_env_multiple($name)
1.149 albertel 12808:
1.258 albertel 12809: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 12810: values may be defined and end up as an array ref.
12811:
12812: returns an array of values
12813:
12814: =cut
12815:
12816: sub get_env_multiple {
12817: my ($name) = @_;
12818: my @values;
1.258 albertel 12819: if (defined($env{$name})) {
1.149 albertel 12820: # exists is it an array
1.258 albertel 12821: if (ref($env{$name})) {
12822: @values=@{ $env{$name} };
1.149 albertel 12823: } else {
1.258 albertel 12824: $values[0]=$env{$name};
1.149 albertel 12825: }
12826: }
12827: return(@values);
12828: }
12829:
1.1249 damieng 12830: # Looks at given dependencies, and returns something depending on the context.
12831: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
12832: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
12833: # For all other contexts, returns ($output, $counter, $numpathchg).
12834: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
12835: # $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.
12836: # $numpathchg: integer with the number of cleaned up dependency paths.
12837: # \%existing: hash reference clean path -> 1 only for existing dependencies.
12838: # \%mapping: hash reference clean path -> original path for all dependencies.
12839: # @param {string} actionurl - The path to the handler, indicative of the context.
12840: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
12841: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
12842: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
12843: # @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)
12844: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 12845: sub ask_for_embedded_content {
1.1249 damieng 12846: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 12847: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 12848: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 12849: %currsubfile,%unused,$rem);
1.1071 raeburn 12850: my $counter = 0;
12851: my $numnew = 0;
1.987 raeburn 12852: my $numremref = 0;
12853: my $numinvalid = 0;
12854: my $numpathchg = 0;
12855: my $numexisting = 0;
1.1071 raeburn 12856: my $numunused = 0;
12857: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 12858: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 12859: my $heading = &mt('Upload embedded files');
12860: my $buttontext = &mt('Upload');
12861:
1.1249 damieng 12862: # fills these variables based on the context:
12863: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
12864: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 12865: if ($env{'request.course.id'}) {
1.1123 raeburn 12866: if ($actionurl eq '/adm/dependencies') {
12867: $navmap = Apache::lonnavmaps::navmap->new();
12868: }
12869: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12870: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 12871: }
1.1123 raeburn 12872: if (($actionurl eq '/adm/portfolio') ||
12873: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 12874: my $current_path='/';
12875: if ($env{'form.currentpath'}) {
12876: $current_path = $env{'form.currentpath'};
12877: }
12878: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 12879: $udom = $cdom;
12880: $uname = $cnum;
1.984 raeburn 12881: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
12882: } else {
12883: $udom = $env{'user.domain'};
12884: $uname = $env{'user.name'};
12885: $url = '/userfiles/portfolio';
12886: }
1.987 raeburn 12887: $toplevel = $url.'/';
1.984 raeburn 12888: $url .= $current_path;
12889: $getpropath = 1;
1.987 raeburn 12890: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12891: ($actionurl eq '/adm/imsimport')) {
1.1022 www 12892: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 12893: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 12894: $toplevel = $url;
1.984 raeburn 12895: if ($rest ne '') {
1.987 raeburn 12896: $url .= $rest;
12897: }
12898: } elsif ($actionurl eq '/adm/coursedocs') {
12899: if (ref($args) eq 'HASH') {
1.1071 raeburn 12900: $url = $args->{'docs_url'};
12901: $toplevel = $url;
1.1084 raeburn 12902: if ($args->{'context'} eq 'paste') {
12903: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
12904: ($path) =
12905: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12906: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12907: $fileloc =~ s{^/}{};
12908: }
1.1071 raeburn 12909: }
1.1084 raeburn 12910: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 12911: if ($env{'request.course.id'} ne '') {
12912: if (ref($args) eq 'HASH') {
12913: $url = $args->{'docs_url'};
12914: $title = $args->{'docs_title'};
1.1126 raeburn 12915: $toplevel = $url;
12916: unless ($toplevel =~ m{^/}) {
12917: $toplevel = "/$url";
12918: }
1.1085 raeburn 12919: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 12920: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
12921: $path = $1;
12922: } else {
12923: ($path) =
12924: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12925: }
1.1195 raeburn 12926: if ($toplevel=~/^\/*(uploaded|editupload)/) {
12927: $fileloc = $toplevel;
12928: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
12929: my ($udom,$uname,$fname) =
12930: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
12931: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
12932: } else {
12933: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12934: }
1.1071 raeburn 12935: $fileloc =~ s{^/}{};
12936: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
12937: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
12938: }
1.987 raeburn 12939: }
1.1123 raeburn 12940: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12941: $udom = $cdom;
12942: $uname = $cnum;
12943: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
12944: $toplevel = $url;
12945: $path = $url;
12946: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
12947: $fileloc =~ s{^/}{};
1.987 raeburn 12948: }
1.1249 damieng 12949:
12950: # parses the dependency paths to get some info
12951: # fills $newfiles, $mapping, $subdependencies, $dependencies
12952: # $newfiles: hash URL -> 1 for new files or external URLs
12953: # (will be completed later)
12954: # $mapping:
12955: # for external URLs: external URL -> external URL
12956: # for relative paths: clean path -> original path
12957: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
12958: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 12959: foreach my $file (keys(%{$allfiles})) {
12960: my $embed_file;
12961: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
12962: $embed_file = $1;
12963: } else {
12964: $embed_file = $file;
12965: }
1.1158 raeburn 12966: my ($absolutepath,$cleaned_file);
12967: if ($embed_file =~ m{^\w+://}) {
12968: $cleaned_file = $embed_file;
1.1147 raeburn 12969: $newfiles{$cleaned_file} = 1;
12970: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12971: } else {
1.1158 raeburn 12972: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 12973: if ($embed_file =~ m{^/}) {
12974: $absolutepath = $embed_file;
12975: }
1.1147 raeburn 12976: if ($cleaned_file =~ m{/}) {
12977: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 12978: $path = &check_for_traversal($path,$url,$toplevel);
12979: my $item = $fname;
12980: if ($path ne '') {
12981: $item = $path.'/'.$fname;
12982: $subdependencies{$path}{$fname} = 1;
12983: } else {
12984: $dependencies{$item} = 1;
12985: }
12986: if ($absolutepath) {
12987: $mapping{$item} = $absolutepath;
12988: } else {
12989: $mapping{$item} = $embed_file;
12990: }
12991: } else {
12992: $dependencies{$embed_file} = 1;
12993: if ($absolutepath) {
1.1147 raeburn 12994: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 12995: } else {
1.1147 raeburn 12996: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12997: }
12998: }
1.984 raeburn 12999: }
13000: }
1.1249 damieng 13001:
13002: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
13003: # and lists
13004: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
13005: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
13006: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
13007: # the path had to be cleaned up
13008: # $existing: hash clean path -> 1 if the file exists
13009: # $numexisting: number of keys in $existing
13010: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
13011: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
13012: # dependency subdirectories that are
13013: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 13014: my $dirptr = 16384;
1.984 raeburn 13015: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 13016: $currsubfile{$path} = {};
1.1123 raeburn 13017: if (($actionurl eq '/adm/portfolio') ||
13018: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 13019: my ($sublistref,$listerror) =
13020: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
13021: if (ref($sublistref) eq 'ARRAY') {
13022: foreach my $line (@{$sublistref}) {
13023: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 13024: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 13025: }
1.984 raeburn 13026: }
1.987 raeburn 13027: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 13028: if (opendir(my $dir,$url.'/'.$path)) {
13029: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 13030: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
13031: }
1.1084 raeburn 13032: } elsif (($actionurl eq '/adm/dependencies') ||
13033: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 13034: ($args->{'context'} eq 'paste')) ||
13035: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 13036: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 13037: my $dir;
13038: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
13039: $dir = $fileloc;
13040: } else {
13041: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
13042: }
1.1071 raeburn 13043: if ($dir ne '') {
13044: my ($sublistref,$listerror) =
13045: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
13046: if (ref($sublistref) eq 'ARRAY') {
13047: foreach my $line (@{$sublistref}) {
13048: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
13049: undef,$mtime)=split(/\&/,$line,12);
13050: unless (($testdir&$dirptr) ||
13051: ($file_name =~ /^\.\.?$/)) {
13052: $currsubfile{$path}{$file_name} = [$size,$mtime];
13053: }
13054: }
13055: }
13056: }
1.984 raeburn 13057: }
13058: }
13059: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 13060: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 13061: my $item = $path.'/'.$file;
13062: unless ($mapping{$item} eq $item) {
13063: $pathchanges{$item} = 1;
13064: }
13065: $existing{$item} = 1;
13066: $numexisting ++;
13067: } else {
13068: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 13069: }
13070: }
1.1071 raeburn 13071: if ($actionurl eq '/adm/dependencies') {
13072: foreach my $path (keys(%currsubfile)) {
13073: if (ref($currsubfile{$path}) eq 'HASH') {
13074: foreach my $file (keys(%{$currsubfile{$path}})) {
13075: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 13076: next if (($rem ne '') &&
13077: (($env{"httpref.$rem"."$path/$file"} ne '') ||
13078: (ref($navmap) &&
13079: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
13080: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
13081: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 13082: $unused{$path.'/'.$file} = 1;
13083: }
13084: }
13085: }
13086: }
13087: }
1.984 raeburn 13088: }
1.1249 damieng 13089:
13090: # fills $currfile, hash file name -> 1 or [$size,$mtime]
13091: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 13092: my %currfile;
1.1123 raeburn 13093: if (($actionurl eq '/adm/portfolio') ||
13094: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 13095: my ($dirlistref,$listerror) =
13096: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
13097: if (ref($dirlistref) eq 'ARRAY') {
13098: foreach my $line (@{$dirlistref}) {
13099: my ($file_name,$rest) = split(/\&/,$line,2);
13100: $currfile{$file_name} = 1;
13101: }
1.984 raeburn 13102: }
1.987 raeburn 13103: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 13104: if (opendir(my $dir,$url)) {
1.987 raeburn 13105: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 13106: map {$currfile{$_} = 1;} @dir_list;
13107: }
1.1084 raeburn 13108: } elsif (($actionurl eq '/adm/dependencies') ||
13109: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 13110: ($args->{'context'} eq 'paste')) ||
13111: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 13112: if ($env{'request.course.id'} ne '') {
13113: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
13114: if ($dir ne '') {
13115: my ($dirlistref,$listerror) =
13116: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
13117: if (ref($dirlistref) eq 'ARRAY') {
13118: foreach my $line (@{$dirlistref}) {
13119: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
13120: $size,undef,$mtime)=split(/\&/,$line,12);
13121: unless (($testdir&$dirptr) ||
13122: ($file_name =~ /^\.\.?$/)) {
13123: $currfile{$file_name} = [$size,$mtime];
13124: }
13125: }
13126: }
13127: }
13128: }
1.984 raeburn 13129: }
1.1249 damieng 13130: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
13131: # are not in subdirectories, using $currfile
1.984 raeburn 13132: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 13133: if (exists($currfile{$file})) {
1.987 raeburn 13134: unless ($mapping{$file} eq $file) {
13135: $pathchanges{$file} = 1;
13136: }
13137: $existing{$file} = 1;
13138: $numexisting ++;
13139: } else {
1.984 raeburn 13140: $newfiles{$file} = 1;
13141: }
13142: }
1.1071 raeburn 13143: foreach my $file (keys(%currfile)) {
13144: unless (($file eq $filename) ||
13145: ($file eq $filename.'.bak') ||
13146: ($dependencies{$file})) {
1.1085 raeburn 13147: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 13148: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
13149: next if (($rem ne '') &&
13150: (($env{"httpref.$rem".$file} ne '') ||
13151: (ref($navmap) &&
13152: (($navmap->getResourceByUrl($rem.$file) ne '') ||
13153: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
13154: ($navmap->getResourceByUrl($rem.$1)))))));
13155: }
1.1085 raeburn 13156: }
1.1071 raeburn 13157: $unused{$file} = 1;
13158: }
13159: }
1.1249 damieng 13160:
13161: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 13162: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
13163: ($args->{'context'} eq 'paste')) {
13164: $counter = scalar(keys(%existing));
13165: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 13166: return ($output,$counter,$numpathchg,\%existing);
13167: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
13168: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
13169: $counter = scalar(keys(%existing));
13170: $numpathchg = scalar(keys(%pathchanges));
13171: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 13172: }
1.1249 damieng 13173:
13174: # returns HTML otherwise, with dependency results and to ask for more uploads
13175:
13176: # $upload_output: missing dependencies (with upload form)
13177: # $modify_output: uploaded dependencies (in use)
13178: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 13179: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 13180: if ($actionurl eq '/adm/dependencies') {
13181: next if ($embed_file =~ m{^\w+://});
13182: }
1.660 raeburn 13183: $upload_output .= &start_data_table_row().
1.1123 raeburn 13184: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 13185: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 13186: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 13187: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
13188: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 13189: }
1.1123 raeburn 13190: $upload_output .= '</td>';
1.1071 raeburn 13191: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 13192: $upload_output.='<td align="right">'.
13193: '<span class="LC_info LC_fontsize_medium">'.
13194: &mt("URL points to web address").'</span>';
1.987 raeburn 13195: $numremref++;
1.660 raeburn 13196: } elsif ($args->{'error_on_invalid_names'}
13197: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 13198: $upload_output.='<td align="right"><span class="LC_warning">'.
13199: &mt('Invalid characters').'</span>';
1.987 raeburn 13200: $numinvalid++;
1.660 raeburn 13201: } else {
1.1123 raeburn 13202: $upload_output .= '<td>'.
13203: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 13204: $embed_file,\%mapping,
1.1071 raeburn 13205: $allfiles,$codebase,'upload');
13206: $counter ++;
13207: $numnew ++;
1.987 raeburn 13208: }
13209: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
13210: }
13211: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 13212: if ($actionurl eq '/adm/dependencies') {
13213: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
13214: $modify_output .= &start_data_table_row().
13215: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
13216: '<img src="'.&icon($embed_file).'" border="0" />'.
13217: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
13218: '<td>'.$size.'</td>'.
13219: '<td>'.$mtime.'</td>'.
13220: '<td><label><input type="checkbox" name="mod_upload_dep" '.
13221: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
13222: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
13223: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
13224: &embedded_file_element('upload_embedded',$counter,
13225: $embed_file,\%mapping,
13226: $allfiles,$codebase,'modify').
13227: '</div></td>'.
13228: &end_data_table_row()."\n";
13229: $counter ++;
13230: } else {
13231: $upload_output .= &start_data_table_row().
1.1123 raeburn 13232: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
13233: '<span class="LC_filename">'.$embed_file.'</span></td>'.
13234: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 13235: &Apache::loncommon::end_data_table_row()."\n";
13236: }
13237: }
13238: my $delidx = $counter;
13239: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
13240: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
13241: $delete_output .= &start_data_table_row().
13242: '<td><img src="'.&icon($oldfile).'" />'.
13243: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
13244: '<td>'.$size.'</td>'.
13245: '<td>'.$mtime.'</td>'.
13246: '<td><label><input type="checkbox" name="del_upload_dep" '.
13247: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
13248: &embedded_file_element('upload_embedded',$delidx,
13249: $oldfile,\%mapping,$allfiles,
13250: $codebase,'delete').'</td>'.
13251: &end_data_table_row()."\n";
13252: $numunused ++;
13253: $delidx ++;
1.987 raeburn 13254: }
13255: if ($upload_output) {
13256: $upload_output = &start_data_table().
13257: $upload_output.
13258: &end_data_table()."\n";
13259: }
1.1071 raeburn 13260: if ($modify_output) {
13261: $modify_output = &start_data_table().
13262: &start_data_table_header_row().
13263: '<th>'.&mt('File').'</th>'.
13264: '<th>'.&mt('Size (KB)').'</th>'.
13265: '<th>'.&mt('Modified').'</th>'.
13266: '<th>'.&mt('Upload replacement?').'</th>'.
13267: &end_data_table_header_row().
13268: $modify_output.
13269: &end_data_table()."\n";
13270: }
13271: if ($delete_output) {
13272: $delete_output = &start_data_table().
13273: &start_data_table_header_row().
13274: '<th>'.&mt('File').'</th>'.
13275: '<th>'.&mt('Size (KB)').'</th>'.
13276: '<th>'.&mt('Modified').'</th>'.
13277: '<th>'.&mt('Delete?').'</th>'.
13278: &end_data_table_header_row().
13279: $delete_output.
13280: &end_data_table()."\n";
13281: }
1.987 raeburn 13282: my $applies = 0;
13283: if ($numremref) {
13284: $applies ++;
13285: }
13286: if ($numinvalid) {
13287: $applies ++;
13288: }
13289: if ($numexisting) {
13290: $applies ++;
13291: }
1.1071 raeburn 13292: if ($counter || $numunused) {
1.987 raeburn 13293: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
13294: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 13295: $state.'<h3>'.$heading.'</h3>';
13296: if ($actionurl eq '/adm/dependencies') {
13297: if ($numnew) {
13298: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
13299: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
13300: $upload_output.'<br />'."\n";
13301: }
13302: if ($numexisting) {
13303: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
13304: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
13305: $modify_output.'<br />'."\n";
13306: $buttontext = &mt('Save changes');
13307: }
13308: if ($numunused) {
13309: $output .= '<h4>'.&mt('Unused files').'</h4>'.
13310: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
13311: $delete_output.'<br />'."\n";
13312: $buttontext = &mt('Save changes');
13313: }
13314: } else {
13315: $output .= $upload_output.'<br />'."\n";
13316: }
13317: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
13318: $counter.'" />'."\n";
13319: if ($actionurl eq '/adm/dependencies') {
13320: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
13321: $numnew.'" />'."\n";
13322: } elsif ($actionurl eq '') {
1.987 raeburn 13323: $output .= '<input type="hidden" name="phase" value="three" />';
13324: }
13325: } elsif ($applies) {
13326: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
13327: if ($applies > 1) {
13328: $output .=
1.1123 raeburn 13329: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 13330: if ($numremref) {
13331: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
13332: }
13333: if ($numinvalid) {
13334: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
13335: }
13336: if ($numexisting) {
13337: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
13338: }
13339: $output .= '</ul><br />';
13340: } elsif ($numremref) {
13341: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
13342: } elsif ($numinvalid) {
13343: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
13344: } elsif ($numexisting) {
13345: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
13346: }
13347: $output .= $upload_output.'<br />';
13348: }
13349: my ($pathchange_output,$chgcount);
1.1071 raeburn 13350: $chgcount = $counter;
1.987 raeburn 13351: if (keys(%pathchanges) > 0) {
13352: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 13353: if ($counter) {
1.987 raeburn 13354: $output .= &embedded_file_element('pathchange',$chgcount,
13355: $embed_file,\%mapping,
1.1071 raeburn 13356: $allfiles,$codebase,'change');
1.987 raeburn 13357: } else {
13358: $pathchange_output .=
13359: &start_data_table_row().
13360: '<td><input type ="checkbox" name="namechange" value="'.
13361: $chgcount.'" checked="checked" /></td>'.
13362: '<td>'.$mapping{$embed_file}.'</td>'.
13363: '<td>'.$embed_file.
13364: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 13365: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 13366: '</td>'.&end_data_table_row();
1.660 raeburn 13367: }
1.987 raeburn 13368: $numpathchg ++;
13369: $chgcount ++;
1.660 raeburn 13370: }
13371: }
1.1127 raeburn 13372: if (($counter) || ($numunused)) {
1.987 raeburn 13373: if ($numpathchg) {
13374: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
13375: $numpathchg.'" />'."\n";
13376: }
13377: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
13378: ($actionurl eq '/adm/imsimport')) {
13379: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
13380: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
13381: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 13382: } elsif ($actionurl eq '/adm/dependencies') {
13383: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 13384: }
1.1123 raeburn 13385: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 13386: } elsif ($numpathchg) {
13387: my %pathchange = ();
13388: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
13389: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
13390: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 13391: }
1.987 raeburn 13392: }
1.1071 raeburn 13393: return ($output,$counter,$numpathchg);
1.987 raeburn 13394: }
13395:
1.1147 raeburn 13396: =pod
13397:
13398: =item * clean_path($name)
13399:
13400: Performs clean-up of directories, subdirectories and filename in an
13401: embedded object, referenced in an HTML file which is being uploaded
13402: to a course or portfolio, where
13403: "Upload embedded images/multimedia files if HTML file" checkbox was
13404: checked.
13405:
13406: Clean-up is similar to replacements in lonnet::clean_filename()
13407: except each / between sub-directory and next level is preserved.
13408:
13409: =cut
13410:
13411: sub clean_path {
13412: my ($embed_file) = @_;
13413: $embed_file =~s{^/+}{};
13414: my @contents;
13415: if ($embed_file =~ m{/}) {
13416: @contents = split(/\//,$embed_file);
13417: } else {
13418: @contents = ($embed_file);
13419: }
13420: my $lastidx = scalar(@contents)-1;
13421: for (my $i=0; $i<=$lastidx; $i++) {
13422: $contents[$i]=~s{\\}{/}g;
13423: $contents[$i]=~s/\s+/\_/g;
13424: $contents[$i]=~s{[^/\w\.\-]}{}g;
13425: if ($i == $lastidx) {
13426: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
13427: }
13428: }
13429: if ($lastidx > 0) {
13430: return join('/',@contents);
13431: } else {
13432: return $contents[0];
13433: }
13434: }
13435:
1.987 raeburn 13436: sub embedded_file_element {
1.1071 raeburn 13437: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 13438: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
13439: (ref($codebase) eq 'HASH'));
13440: my $output;
1.1071 raeburn 13441: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 13442: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
13443: }
13444: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
13445: &escape($embed_file).'" />';
13446: unless (($context eq 'upload_embedded') &&
13447: ($mapping->{$embed_file} eq $embed_file)) {
13448: $output .='
13449: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
13450: }
13451: my $attrib;
13452: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
13453: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
13454: }
13455: $output .=
13456: "\n\t\t".
13457: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
13458: $attrib.'" />';
13459: if (exists($codebase->{$mapping->{$embed_file}})) {
13460: $output .=
13461: "\n\t\t".
13462: '<input name="codebase_'.$num.'" type="hidden" value="'.
13463: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 13464: }
1.987 raeburn 13465: return $output;
1.660 raeburn 13466: }
13467:
1.1071 raeburn 13468: sub get_dependency_details {
13469: my ($currfile,$currsubfile,$embed_file) = @_;
13470: my ($size,$mtime,$showsize,$showmtime);
13471: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
13472: if ($embed_file =~ m{/}) {
13473: my ($path,$fname) = split(/\//,$embed_file);
13474: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
13475: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
13476: }
13477: } else {
13478: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
13479: ($size,$mtime) = @{$currfile->{$embed_file}};
13480: }
13481: }
13482: $showsize = $size/1024.0;
13483: $showsize = sprintf("%.1f",$showsize);
13484: if ($mtime > 0) {
13485: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
13486: }
13487: }
13488: return ($showsize,$showmtime);
13489: }
13490:
13491: sub ask_embedded_js {
13492: return <<"END";
13493: <script type="text/javascript"">
13494: // <![CDATA[
13495: function toggleBrowse(counter) {
13496: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
13497: var fileid = document.getElementById('embedded_item_'+counter);
13498: var uploaddivid = document.getElementById('moduploaddep_'+counter);
13499: if (chkboxid.checked == true) {
13500: uploaddivid.style.display='block';
13501: } else {
13502: uploaddivid.style.display='none';
13503: fileid.value = '';
13504: }
13505: }
13506: // ]]>
13507: </script>
13508:
13509: END
13510: }
13511:
1.661 raeburn 13512: sub upload_embedded {
13513: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 13514: $current_disk_usage,$hiddenstate,$actionurl) = @_;
13515: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 13516: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
13517: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
13518: my $orig_uploaded_filename =
13519: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 13520: foreach my $type ('orig','ref','attrib','codebase') {
13521: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
13522: $env{'form.embedded_'.$type.'_'.$i} =
13523: &unescape($env{'form.embedded_'.$type.'_'.$i});
13524: }
13525: }
1.661 raeburn 13526: my ($path,$fname) =
13527: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
13528: # no path, whole string is fname
13529: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
13530: $fname = &Apache::lonnet::clean_filename($fname);
13531: # See if there is anything left
13532: next if ($fname eq '');
13533:
13534: # Check if file already exists as a file or directory.
13535: my ($state,$msg);
13536: if ($context eq 'portfolio') {
13537: my $port_path = $dirpath;
13538: if ($group ne '') {
13539: $port_path = "groups/$group/$port_path";
13540: }
1.987 raeburn 13541: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
13542: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 13543: $dir_root,$port_path,$disk_quota,
13544: $current_disk_usage,$uname,$udom);
13545: if ($state eq 'will_exceed_quota'
1.984 raeburn 13546: || $state eq 'file_locked') {
1.661 raeburn 13547: $output .= $msg;
13548: next;
13549: }
13550: } elsif (($context eq 'author') || ($context eq 'testbank')) {
13551: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
13552: if ($state eq 'exists') {
13553: $output .= $msg;
13554: next;
13555: }
13556: }
13557: # Check if extension is valid
13558: if (($fname =~ /\.(\w+)$/) &&
13559: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 13560: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
13561: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 13562: next;
13563: } elsif (($fname =~ /\.(\w+)$/) &&
13564: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 13565: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 13566: next;
13567: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 13568: $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 13569: next;
13570: }
13571: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 13572: my $subdir = $path;
13573: $subdir =~ s{/+$}{};
1.661 raeburn 13574: if ($context eq 'portfolio') {
1.984 raeburn 13575: my $result;
13576: if ($state eq 'existingfile') {
13577: $result=
13578: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 13579: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 13580: } else {
1.984 raeburn 13581: $result=
13582: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 13583: $dirpath.
1.1123 raeburn 13584: $env{'form.currentpath'}.$subdir);
1.984 raeburn 13585: if ($result !~ m|^/uploaded/|) {
13586: $output .= '<span class="LC_error">'
13587: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
13588: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
13589: .'</span><br />';
13590: next;
13591: } else {
1.987 raeburn 13592: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13593: $path.$fname.'</span>').'<br />';
1.984 raeburn 13594: }
1.661 raeburn 13595: }
1.1123 raeburn 13596: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 13597: my $extendedsubdir = $dirpath.'/'.$subdir;
13598: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 13599: my $result =
1.1126 raeburn 13600: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 13601: if ($result !~ m|^/uploaded/|) {
13602: $output .= '<span class="LC_error">'
13603: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
13604: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
13605: .'</span><br />';
13606: next;
13607: } else {
13608: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13609: $path.$fname.'</span>').'<br />';
1.1125 raeburn 13610: if ($context eq 'syllabus') {
13611: &Apache::lonnet::make_public_indefinitely($result);
13612: }
1.987 raeburn 13613: }
1.661 raeburn 13614: } else {
13615: # Save the file
13616: my $target = $env{'form.embedded_item_'.$i};
13617: my $fullpath = $dir_root.$dirpath.'/'.$path;
13618: my $dest = $fullpath.$fname;
13619: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 13620: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 13621: my $count;
13622: my $filepath = $dir_root;
1.1027 raeburn 13623: foreach my $subdir (@parts) {
13624: $filepath .= "/$subdir";
13625: if (!-e $filepath) {
1.661 raeburn 13626: mkdir($filepath,0770);
13627: }
13628: }
13629: my $fh;
13630: if (!open($fh,'>'.$dest)) {
13631: &Apache::lonnet::logthis('Failed to create '.$dest);
13632: $output .= '<span class="LC_error">'.
1.1071 raeburn 13633: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
13634: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 13635: '</span><br />';
13636: } else {
13637: if (!print $fh $env{'form.embedded_item_'.$i}) {
13638: &Apache::lonnet::logthis('Failed to write to '.$dest);
13639: $output .= '<span class="LC_error">'.
1.1071 raeburn 13640: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
13641: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 13642: '</span><br />';
13643: } else {
1.987 raeburn 13644: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13645: $url.'</span>').'<br />';
13646: unless ($context eq 'testbank') {
13647: $footer .= &mt('View embedded file: [_1]',
13648: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
13649: }
13650: }
13651: close($fh);
13652: }
13653: }
13654: if ($env{'form.embedded_ref_'.$i}) {
13655: $pathchange{$i} = 1;
13656: }
13657: }
13658: if ($output) {
13659: $output = '<p>'.$output.'</p>';
13660: }
13661: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
13662: $returnflag = 'ok';
1.1071 raeburn 13663: my $numpathchgs = scalar(keys(%pathchange));
13664: if ($numpathchgs > 0) {
1.987 raeburn 13665: if ($context eq 'portfolio') {
13666: $output .= '<p>'.&mt('or').'</p>';
13667: } elsif ($context eq 'testbank') {
1.1071 raeburn 13668: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
13669: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 13670: $returnflag = 'modify_orightml';
13671: }
13672: }
1.1071 raeburn 13673: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 13674: }
13675:
13676: sub modify_html_form {
13677: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
13678: my $end = 0;
13679: my $modifyform;
13680: if ($context eq 'upload_embedded') {
13681: return unless (ref($pathchange) eq 'HASH');
13682: if ($env{'form.number_embedded_items'}) {
13683: $end += $env{'form.number_embedded_items'};
13684: }
13685: if ($env{'form.number_pathchange_items'}) {
13686: $end += $env{'form.number_pathchange_items'};
13687: }
13688: if ($end) {
13689: for (my $i=0; $i<$end; $i++) {
13690: if ($i < $env{'form.number_embedded_items'}) {
13691: next unless($pathchange->{$i});
13692: }
13693: $modifyform .=
13694: &start_data_table_row().
13695: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
13696: 'checked="checked" /></td>'.
13697: '<td>'.$env{'form.embedded_ref_'.$i}.
13698: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
13699: &escape($env{'form.embedded_ref_'.$i}).'" />'.
13700: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
13701: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
13702: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
13703: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
13704: '<td>'.$env{'form.embedded_orig_'.$i}.
13705: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
13706: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
13707: &end_data_table_row();
1.1071 raeburn 13708: }
1.987 raeburn 13709: }
13710: } else {
13711: $modifyform = $pathchgtable;
13712: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
13713: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
13714: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
13715: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
13716: }
13717: }
13718: if ($modifyform) {
1.1071 raeburn 13719: if ($actionurl eq '/adm/dependencies') {
13720: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
13721: }
1.987 raeburn 13722: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
13723: '<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".
13724: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
13725: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
13726: '</ol></p>'."\n".'<p>'.
13727: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
13728: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
13729: &start_data_table()."\n".
13730: &start_data_table_header_row().
13731: '<th>'.&mt('Change?').'</th>'.
13732: '<th>'.&mt('Current reference').'</th>'.
13733: '<th>'.&mt('Required reference').'</th>'.
13734: &end_data_table_header_row()."\n".
13735: $modifyform.
13736: &end_data_table().'<br />'."\n".$hiddenstate.
13737: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
13738: '</form>'."\n";
13739: }
13740: return;
13741: }
13742:
13743: sub modify_html_refs {
1.1123 raeburn 13744: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 13745: my $container;
13746: if ($context eq 'portfolio') {
13747: $container = $env{'form.container'};
13748: } elsif ($context eq 'coursedoc') {
13749: $container = $env{'form.primaryurl'};
1.1071 raeburn 13750: } elsif ($context eq 'manage_dependencies') {
13751: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
13752: $container = "/$container";
1.1123 raeburn 13753: } elsif ($context eq 'syllabus') {
13754: $container = $url;
1.987 raeburn 13755: } else {
1.1027 raeburn 13756: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 13757: }
13758: my (%allfiles,%codebase,$output,$content);
13759: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 13760: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 13761: if (wantarray) {
13762: return ('',0,0);
13763: } else {
13764: return;
13765: }
13766: }
13767: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13768: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 13769: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
13770: if (wantarray) {
13771: return ('',0,0);
13772: } else {
13773: return;
13774: }
13775: }
1.987 raeburn 13776: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 13777: if ($content eq '-1') {
13778: if (wantarray) {
13779: return ('',0,0);
13780: } else {
13781: return;
13782: }
13783: }
1.987 raeburn 13784: } else {
1.1071 raeburn 13785: unless ($container =~ /^\Q$dir_root\E/) {
13786: if (wantarray) {
13787: return ('',0,0);
13788: } else {
13789: return;
13790: }
13791: }
1.1317 raeburn 13792: if (open(my $fh,'<',$container)) {
1.987 raeburn 13793: $content = join('', <$fh>);
13794: close($fh);
13795: } else {
1.1071 raeburn 13796: if (wantarray) {
13797: return ('',0,0);
13798: } else {
13799: return;
13800: }
1.987 raeburn 13801: }
13802: }
13803: my ($count,$codebasecount) = (0,0);
13804: my $mm = new File::MMagic;
13805: my $mime_type = $mm->checktype_contents($content);
13806: if ($mime_type eq 'text/html') {
13807: my $parse_result =
13808: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
13809: \%codebase,\$content);
13810: if ($parse_result eq 'ok') {
13811: foreach my $i (@changes) {
13812: my $orig = &unescape($env{'form.embedded_orig_'.$i});
13813: my $ref = &unescape($env{'form.embedded_ref_'.$i});
13814: if ($allfiles{$ref}) {
13815: my $newname = $orig;
13816: my ($attrib_regexp,$codebase);
1.1006 raeburn 13817: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 13818: if ($attrib_regexp =~ /:/) {
13819: $attrib_regexp =~ s/\:/|/g;
13820: }
13821: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13822: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13823: $count += $numchg;
1.1123 raeburn 13824: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 13825: delete($allfiles{$ref});
1.987 raeburn 13826: }
13827: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 13828: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 13829: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
13830: $codebasecount ++;
13831: }
13832: }
13833: }
1.1123 raeburn 13834: my $skiprewrites;
1.987 raeburn 13835: if ($count || $codebasecount) {
13836: my $saveresult;
1.1071 raeburn 13837: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13838: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 13839: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13840: if ($url eq $container) {
13841: my ($fname) = ($container =~ m{/([^/]+)$});
13842: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13843: $count,'<span class="LC_filename">'.
1.1071 raeburn 13844: $fname.'</span>').'</p>';
1.987 raeburn 13845: } else {
13846: $output = '<p class="LC_error">'.
13847: &mt('Error: update failed for: [_1].',
13848: '<span class="LC_filename">'.
13849: $container.'</span>').'</p>';
13850: }
1.1123 raeburn 13851: if ($context eq 'syllabus') {
13852: unless ($saveresult eq 'ok') {
13853: $skiprewrites = 1;
13854: }
13855: }
1.987 raeburn 13856: } else {
1.1317 raeburn 13857: if (open(my $fh,'>',$container)) {
1.987 raeburn 13858: print $fh $content;
13859: close($fh);
13860: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13861: $count,'<span class="LC_filename">'.
13862: $container.'</span>').'</p>';
1.661 raeburn 13863: } else {
1.987 raeburn 13864: $output = '<p class="LC_error">'.
13865: &mt('Error: could not update [_1].',
13866: '<span class="LC_filename">'.
13867: $container.'</span>').'</p>';
1.661 raeburn 13868: }
13869: }
13870: }
1.1123 raeburn 13871: if (($context eq 'syllabus') && (!$skiprewrites)) {
13872: my ($actionurl,$state);
13873: $actionurl = "/public/$udom/$uname/syllabus";
13874: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
13875: &ask_for_embedded_content($actionurl,$state,\%allfiles,
13876: \%codebase,
13877: {'context' => 'rewrites',
13878: 'ignore_remote_references' => 1,});
13879: if (ref($mapping) eq 'HASH') {
13880: my $rewrites = 0;
13881: foreach my $key (keys(%{$mapping})) {
13882: next if ($key =~ m{^https?://});
13883: my $ref = $mapping->{$key};
13884: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
13885: my $attrib;
13886: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
13887: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
13888: }
13889: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13890: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13891: $rewrites += $numchg;
13892: }
13893: }
13894: if ($rewrites) {
13895: my $saveresult;
13896: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13897: if ($url eq $container) {
13898: my ($fname) = ($container =~ m{/([^/]+)$});
13899: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
13900: $count,'<span class="LC_filename">'.
13901: $fname.'</span>').'</p>';
13902: } else {
13903: $output .= '<p class="LC_error">'.
13904: &mt('Error: could not update links in [_1].',
13905: '<span class="LC_filename">'.
13906: $container.'</span>').'</p>';
13907:
13908: }
13909: }
13910: }
13911: }
1.987 raeburn 13912: } else {
13913: &logthis('Failed to parse '.$container.
13914: ' to modify references: '.$parse_result);
1.661 raeburn 13915: }
13916: }
1.1071 raeburn 13917: if (wantarray) {
13918: return ($output,$count,$codebasecount);
13919: } else {
13920: return $output;
13921: }
1.661 raeburn 13922: }
13923:
13924: sub check_for_existing {
13925: my ($path,$fname,$element) = @_;
13926: my ($state,$msg);
13927: if (-d $path.'/'.$fname) {
13928: $state = 'exists';
13929: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13930: } elsif (-e $path.'/'.$fname) {
13931: $state = 'exists';
13932: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13933: }
13934: if ($state eq 'exists') {
13935: $msg = '<span class="LC_error">'.$msg.'</span><br />';
13936: }
13937: return ($state,$msg);
13938: }
13939:
13940: sub check_for_upload {
13941: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
13942: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 13943: my $filesize = length($env{'form.'.$element});
13944: if (!$filesize) {
13945: my $msg = '<span class="LC_error">'.
13946: &mt('Unable to upload [_1]. (size = [_2] bytes)',
13947: '<span class="LC_filename">'.$fname.'</span>',
13948: $filesize).'<br />'.
1.1007 raeburn 13949: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 13950: '</span>';
13951: return ('zero_bytes',$msg);
13952: }
13953: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 13954: my $getpropath = 1;
1.1021 raeburn 13955: my ($dirlistref,$listerror) =
13956: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 13957: my $found_file = 0;
13958: my $locked_file = 0;
1.991 raeburn 13959: my @lockers;
13960: my $navmap;
13961: if ($env{'request.course.id'}) {
13962: $navmap = Apache::lonnavmaps::navmap->new();
13963: }
1.1021 raeburn 13964: if (ref($dirlistref) eq 'ARRAY') {
13965: foreach my $line (@{$dirlistref}) {
13966: my ($file_name,$rest)=split(/\&/,$line,2);
13967: if ($file_name eq $fname){
13968: $file_name = $path.$file_name;
13969: if ($group ne '') {
13970: $file_name = $group.$file_name;
13971: }
13972: $found_file = 1;
13973: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
13974: foreach my $lock (@lockers) {
13975: if (ref($lock) eq 'ARRAY') {
13976: my ($symb,$crsid) = @{$lock};
13977: if ($crsid eq $env{'request.course.id'}) {
13978: if (ref($navmap)) {
13979: my $res = $navmap->getBySymb($symb);
13980: foreach my $part (@{$res->parts()}) {
13981: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
13982: unless (($slot_status == $res->RESERVED) ||
13983: ($slot_status == $res->RESERVED_LOCATION)) {
13984: $locked_file = 1;
13985: }
1.991 raeburn 13986: }
1.1021 raeburn 13987: } else {
13988: $locked_file = 1;
1.991 raeburn 13989: }
13990: } else {
13991: $locked_file = 1;
13992: }
13993: }
1.1021 raeburn 13994: }
13995: } else {
13996: my @info = split(/\&/,$rest);
13997: my $currsize = $info[6]/1000;
13998: if ($currsize < $filesize) {
13999: my $extra = $filesize - $currsize;
14000: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 14001: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 14002: &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 14003: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
14004: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
14005: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 14006: return ('will_exceed_quota',$msg);
14007: }
1.984 raeburn 14008: }
14009: }
1.661 raeburn 14010: }
14011: }
14012: }
14013: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 14014: my $msg = '<p class="LC_warning">'.
14015: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 14016: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 14017: return ('will_exceed_quota',$msg);
14018: } elsif ($found_file) {
14019: if ($locked_file) {
1.1179 bisitz 14020: my $msg = '<p class="LC_warning">';
1.661 raeburn 14021: $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 14022: $msg .= '</p>';
1.661 raeburn 14023: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
14024: return ('file_locked',$msg);
14025: } else {
1.1179 bisitz 14026: my $msg = '<p class="LC_error">';
1.984 raeburn 14027: $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 14028: $msg .= '</p>';
1.984 raeburn 14029: return ('existingfile',$msg);
1.661 raeburn 14030: }
14031: }
14032: }
14033:
1.987 raeburn 14034: sub check_for_traversal {
14035: my ($path,$url,$toplevel) = @_;
14036: my @parts=split(/\//,$path);
14037: my $cleanpath;
14038: my $fullpath = $url;
14039: for (my $i=0;$i<@parts;$i++) {
14040: next if ($parts[$i] eq '.');
14041: if ($parts[$i] eq '..') {
14042: $fullpath =~ s{([^/]+/)$}{};
14043: } else {
14044: $fullpath .= $parts[$i].'/';
14045: }
14046: }
14047: if ($fullpath =~ /^\Q$url\E(.*)$/) {
14048: $cleanpath = $1;
14049: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
14050: my $curr_toprel = $1;
14051: my @parts = split(/\//,$curr_toprel);
14052: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
14053: my @urlparts = split(/\//,$url_toprel);
14054: my $doubledots;
14055: my $startdiff = -1;
14056: for (my $i=0; $i<@urlparts; $i++) {
14057: if ($startdiff == -1) {
14058: unless ($urlparts[$i] eq $parts[$i]) {
14059: $startdiff = $i;
14060: $doubledots .= '../';
14061: }
14062: } else {
14063: $doubledots .= '../';
14064: }
14065: }
14066: if ($startdiff > -1) {
14067: $cleanpath = $doubledots;
14068: for (my $i=$startdiff; $i<@parts; $i++) {
14069: $cleanpath .= $parts[$i].'/';
14070: }
14071: }
14072: }
14073: $cleanpath =~ s{(/)$}{};
14074: return $cleanpath;
14075: }
1.31 albertel 14076:
1.1053 raeburn 14077: sub is_archive_file {
14078: my ($mimetype) = @_;
14079: if (($mimetype eq 'application/octet-stream') ||
14080: ($mimetype eq 'application/x-stuffit') ||
14081: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
14082: return 1;
14083: }
14084: return;
14085: }
14086:
14087: sub decompress_form {
1.1065 raeburn 14088: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 14089: my %lt = &Apache::lonlocal::texthash (
14090: this => 'This file is an archive file.',
1.1067 raeburn 14091: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 14092: itsc => 'Its contents are as follows:',
1.1053 raeburn 14093: youm => 'You may wish to extract its contents.',
14094: extr => 'Extract contents',
1.1067 raeburn 14095: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
14096: proa => 'Process automatically?',
1.1053 raeburn 14097: yes => 'Yes',
14098: no => 'No',
1.1067 raeburn 14099: fold => 'Title for folder containing movie',
14100: movi => 'Title for page containing embedded movie',
1.1053 raeburn 14101: );
1.1065 raeburn 14102: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 14103: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 14104: my $info = &list_archive_contents($fileloc,\@paths);
14105: if (@paths) {
14106: foreach my $path (@paths) {
14107: $path =~ s{^/}{};
1.1067 raeburn 14108: if ($path =~ m{^([^/]+)/$}) {
14109: $topdir = $1;
14110: }
1.1065 raeburn 14111: if ($path =~ m{^([^/]+)/}) {
14112: $toplevel{$1} = $path;
14113: } else {
14114: $toplevel{$path} = $path;
14115: }
14116: }
14117: }
1.1067 raeburn 14118: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 14119: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 14120: "$topdir/media/",
14121: "$topdir/media/$topdir.mp4",
14122: "$topdir/media/FirstFrame.png",
14123: "$topdir/media/player.swf",
14124: "$topdir/media/swfobject.js",
14125: "$topdir/media/expressInstall.swf");
1.1197 raeburn 14126: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 14127: "$topdir/$topdir.mp4",
14128: "$topdir/$topdir\_config.xml",
14129: "$topdir/$topdir\_controller.swf",
14130: "$topdir/$topdir\_embed.css",
14131: "$topdir/$topdir\_First_Frame.png",
14132: "$topdir/$topdir\_player.html",
14133: "$topdir/$topdir\_Thumbnails.png",
14134: "$topdir/playerProductInstall.swf",
14135: "$topdir/scripts/",
14136: "$topdir/scripts/config_xml.js",
14137: "$topdir/scripts/handlebars.js",
14138: "$topdir/scripts/jquery-1.7.1.min.js",
14139: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
14140: "$topdir/scripts/modernizr.js",
14141: "$topdir/scripts/player-min.js",
14142: "$topdir/scripts/swfobject.js",
14143: "$topdir/skins/",
14144: "$topdir/skins/configuration_express.xml",
14145: "$topdir/skins/express_show/",
14146: "$topdir/skins/express_show/player-min.css",
14147: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 14148: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
14149: "$topdir/$topdir.mp4",
14150: "$topdir/$topdir\_config.xml",
14151: "$topdir/$topdir\_controller.swf",
14152: "$topdir/$topdir\_embed.css",
14153: "$topdir/$topdir\_First_Frame.png",
14154: "$topdir/$topdir\_player.html",
14155: "$topdir/$topdir\_Thumbnails.png",
14156: "$topdir/playerProductInstall.swf",
14157: "$topdir/scripts/",
14158: "$topdir/scripts/config_xml.js",
14159: "$topdir/scripts/techsmith-smart-player.min.js",
14160: "$topdir/skins/",
14161: "$topdir/skins/configuration_express.xml",
14162: "$topdir/skins/express_show/",
14163: "$topdir/skins/express_show/spritesheet.min.css",
14164: "$topdir/skins/express_show/spritesheet.png",
14165: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 14166: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 14167: if (@diffs == 0) {
1.1164 raeburn 14168: $is_camtasia = 6;
14169: } else {
1.1197 raeburn 14170: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 14171: if (@diffs == 0) {
14172: $is_camtasia = 8;
1.1197 raeburn 14173: } else {
14174: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
14175: if (@diffs == 0) {
14176: $is_camtasia = 8;
14177: }
1.1164 raeburn 14178: }
1.1067 raeburn 14179: }
14180: }
14181: my $output;
14182: if ($is_camtasia) {
14183: $output = <<"ENDCAM";
14184: <script type="text/javascript" language="Javascript">
14185: // <![CDATA[
14186:
14187: function camtasiaToggle() {
14188: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
14189: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 14190: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 14191: document.getElementById('camtasia_titles').style.display='block';
14192: } else {
14193: document.getElementById('camtasia_titles').style.display='none';
14194: }
14195: }
14196: }
14197: return;
14198: }
14199:
14200: // ]]>
14201: </script>
14202: <p>$lt{'camt'}</p>
14203: ENDCAM
1.1065 raeburn 14204: } else {
1.1067 raeburn 14205: $output = '<p>'.$lt{'this'};
14206: if ($info eq '') {
14207: $output .= ' '.$lt{'youm'}.'</p>'."\n";
14208: } else {
14209: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
14210: '<div><pre>'.$info.'</pre></div>';
14211: }
1.1065 raeburn 14212: }
1.1067 raeburn 14213: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 14214: my $duplicates;
14215: my $num = 0;
14216: if (ref($dirlist) eq 'ARRAY') {
14217: foreach my $item (@{$dirlist}) {
14218: if (ref($item) eq 'ARRAY') {
14219: if (exists($toplevel{$item->[0]})) {
14220: $duplicates .=
14221: &start_data_table_row().
14222: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
14223: 'value="0" checked="checked" />'.&mt('No').'</label>'.
14224: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
14225: 'value="1" />'.&mt('Yes').'</label>'.
14226: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
14227: '<td>'.$item->[0].'</td>';
14228: if ($item->[2]) {
14229: $duplicates .= '<td>'.&mt('Directory').'</td>';
14230: } else {
14231: $duplicates .= '<td>'.&mt('File').'</td>';
14232: }
14233: $duplicates .= '<td>'.$item->[3].'</td>'.
14234: '<td>'.
14235: &Apache::lonlocal::locallocaltime($item->[4]).
14236: '</td>'.
14237: &end_data_table_row();
14238: $num ++;
14239: }
14240: }
14241: }
14242: }
14243: my $itemcount;
14244: if (@paths > 0) {
14245: $itemcount = scalar(@paths);
14246: } else {
14247: $itemcount = 1;
14248: }
1.1067 raeburn 14249: if ($is_camtasia) {
14250: $output .= $lt{'auto'}.'<br />'.
14251: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 14252: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 14253: $lt{'yes'}.'</label> <label>'.
14254: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
14255: $lt{'no'}.'</label></span><br />'.
14256: '<div id="camtasia_titles" style="display:block">'.
14257: &Apache::lonhtmlcommon::start_pick_box().
14258: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
14259: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
14260: &Apache::lonhtmlcommon::row_closure().
14261: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
14262: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
14263: &Apache::lonhtmlcommon::row_closure(1).
14264: &Apache::lonhtmlcommon::end_pick_box().
14265: '</div>';
14266: }
1.1065 raeburn 14267: $output .=
14268: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 14269: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
14270: "\n";
1.1065 raeburn 14271: if ($duplicates ne '') {
14272: $output .= '<p><span class="LC_warning">'.
14273: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
14274: &start_data_table().
14275: &start_data_table_header_row().
14276: '<th>'.&mt('Overwrite?').'</th>'.
14277: '<th>'.&mt('Name').'</th>'.
14278: '<th>'.&mt('Type').'</th>'.
14279: '<th>'.&mt('Size').'</th>'.
14280: '<th>'.&mt('Last modified').'</th>'.
14281: &end_data_table_header_row().
14282: $duplicates.
14283: &end_data_table().
14284: '</p>';
14285: }
1.1067 raeburn 14286: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 14287: if (ref($hiddenelements) eq 'HASH') {
14288: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
14289: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
14290: }
14291: }
14292: $output .= <<"END";
1.1067 raeburn 14293: <br />
1.1053 raeburn 14294: <input type="submit" name="decompress" value="$lt{'extr'}" />
14295: </form>
14296: $noextract
14297: END
14298: return $output;
14299: }
14300:
1.1065 raeburn 14301: sub decompression_utility {
14302: my ($program) = @_;
14303: my @utilities = ('tar','gunzip','bunzip2','unzip');
14304: my $location;
14305: if (grep(/^\Q$program\E$/,@utilities)) {
14306: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
14307: '/usr/sbin/') {
14308: if (-x $dir.$program) {
14309: $location = $dir.$program;
14310: last;
14311: }
14312: }
14313: }
14314: return $location;
14315: }
14316:
14317: sub list_archive_contents {
14318: my ($file,$pathsref) = @_;
14319: my (@cmd,$output);
14320: my $needsregexp;
14321: if ($file =~ /\.zip$/) {
14322: @cmd = (&decompression_utility('unzip'),"-l");
14323: $needsregexp = 1;
14324: } elsif (($file =~ m/\.tar\.gz$/) ||
14325: ($file =~ /\.tgz$/)) {
14326: @cmd = (&decompression_utility('tar'),"-ztf");
14327: } elsif ($file =~ /\.tar\.bz2$/) {
14328: @cmd = (&decompression_utility('tar'),"-jtf");
14329: } elsif ($file =~ m|\.tar$|) {
14330: @cmd = (&decompression_utility('tar'),"-tf");
14331: }
14332: if (@cmd) {
14333: undef($!);
14334: undef($@);
14335: if (open(my $fh,"-|", @cmd, $file)) {
14336: while (my $line = <$fh>) {
14337: $output .= $line;
14338: chomp($line);
14339: my $item;
14340: if ($needsregexp) {
14341: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
14342: } else {
14343: $item = $line;
14344: }
14345: if ($item ne '') {
14346: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
14347: push(@{$pathsref},$item);
14348: }
14349: }
14350: }
14351: close($fh);
14352: }
14353: }
14354: return $output;
14355: }
14356:
1.1053 raeburn 14357: sub decompress_uploaded_file {
14358: my ($file,$dir) = @_;
14359: &Apache::lonnet::appenv({'cgi.file' => $file});
14360: &Apache::lonnet::appenv({'cgi.dir' => $dir});
14361: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
14362: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
14363: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
14364: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
14365: my $decompressed = $env{'cgi.decompressed'};
14366: &Apache::lonnet::delenv('cgi.file');
14367: &Apache::lonnet::delenv('cgi.dir');
14368: &Apache::lonnet::delenv('cgi.decompressed');
14369: return ($decompressed,$result);
14370: }
14371:
1.1055 raeburn 14372: sub process_decompression {
14373: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 14374: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
14375: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14376: &mt('Unexpected file path.').'</p>'."\n";
14377: }
14378: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
14379: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14380: &mt('Unexpected course context.').'</p>'."\n";
14381: }
1.1293 raeburn 14382: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 14383: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14384: &mt('Filename contained unexpected characters.').'</p>'."\n";
14385: }
1.1055 raeburn 14386: my ($dir,$error,$warning,$output);
1.1180 raeburn 14387: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 14388: $error = &mt('Filename not a supported archive file type.').
14389: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 14390: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
14391: } else {
14392: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14393: if ($docuhome eq 'no_host') {
14394: $error = &mt('Could not determine home server for course.');
14395: } else {
14396: my @ids=&Apache::lonnet::current_machine_ids();
14397: my $currdir = "$dir_root/$destination";
14398: if (grep(/^\Q$docuhome\E$/,@ids)) {
14399: $dir = &LONCAPA::propath($docudom,$docuname).
14400: "$dir_root/$destination";
14401: } else {
14402: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
14403: "$dir_root/$docudom/$docuname/$destination";
14404: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
14405: $error = &mt('Archive file not found.');
14406: }
14407: }
1.1065 raeburn 14408: my (@to_overwrite,@to_skip);
14409: if ($env{'form.archive_overwrite_total'} > 0) {
14410: my $total = $env{'form.archive_overwrite_total'};
14411: for (my $i=0; $i<$total; $i++) {
14412: if ($env{'form.archive_overwrite_'.$i} == 1) {
14413: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
14414: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
14415: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
14416: }
14417: }
14418: }
14419: my $numskip = scalar(@to_skip);
1.1292 raeburn 14420: my $numoverwrite = scalar(@to_overwrite);
14421: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 14422: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
14423: } elsif ($dir eq '') {
1.1055 raeburn 14424: $error = &mt('Directory containing archive file unavailable.');
14425: } elsif (!$error) {
1.1065 raeburn 14426: my ($decompressed,$display);
1.1292 raeburn 14427: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 14428: my $tempdir = time.'_'.$$.int(rand(10000));
14429: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 14430: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
14431: ($decompressed,$display) =
14432: &decompress_uploaded_file($file,"$dir/$tempdir");
14433: foreach my $item (@to_skip) {
14434: if (($item ne '') && ($item !~ /\.\./)) {
14435: if (-f "$dir/$tempdir/$item") {
14436: unlink("$dir/$tempdir/$item");
14437: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 14438: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 14439: }
14440: }
14441: }
14442: foreach my $item (@to_overwrite) {
14443: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
14444: if (($item ne '') && ($item !~ /\.\./)) {
14445: if (-f "$dir/$item") {
14446: unlink("$dir/$item");
14447: } elsif (-d "$dir/$item") {
1.1300 raeburn 14448: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 14449: }
14450: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
14451: }
1.1065 raeburn 14452: }
14453: }
1.1292 raeburn 14454: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 14455: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 14456: }
1.1065 raeburn 14457: }
14458: } else {
14459: ($decompressed,$display) =
14460: &decompress_uploaded_file($file,$dir);
14461: }
1.1055 raeburn 14462: if ($decompressed eq 'ok') {
1.1065 raeburn 14463: $output = '<p class="LC_info">'.
14464: &mt('Files extracted successfully from archive.').
14465: '</p>'."\n";
1.1055 raeburn 14466: my ($warning,$result,@contents);
14467: my ($newdirlistref,$newlisterror) =
14468: &Apache::lonnet::dirlist($currdir,$docudom,
14469: $docuname,1);
14470: my (%is_dir,%changes,@newitems);
14471: my $dirptr = 16384;
1.1065 raeburn 14472: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 14473: foreach my $dir_line (@{$newdirlistref}) {
14474: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 14475: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 14476: push(@newitems,$item);
14477: if ($dirptr&$testdir) {
14478: $is_dir{$item} = 1;
14479: }
14480: $changes{$item} = 1;
14481: }
14482: }
14483: }
14484: if (keys(%changes) > 0) {
14485: foreach my $item (sort(@newitems)) {
14486: if ($changes{$item}) {
14487: push(@contents,$item);
14488: }
14489: }
14490: }
14491: if (@contents > 0) {
1.1067 raeburn 14492: my $wantform;
14493: unless ($env{'form.autoextract_camtasia'}) {
14494: $wantform = 1;
14495: }
1.1056 raeburn 14496: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 14497: my ($count,$datatable) = &get_extracted($docudom,$docuname,
14498: $currdir,\%is_dir,
14499: \%children,\%parent,
1.1056 raeburn 14500: \@contents,\%dirorder,
14501: \%titles,$wantform);
1.1055 raeburn 14502: if ($datatable ne '') {
14503: $output .= &archive_options_form('decompressed',$datatable,
14504: $count,$hiddenelem);
1.1065 raeburn 14505: my $startcount = 6;
1.1055 raeburn 14506: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 14507: \%titles,\%children);
1.1055 raeburn 14508: }
1.1067 raeburn 14509: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 14510: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 14511: my %displayed;
14512: my $total = 1;
14513: $env{'form.archive_directory'} = [];
14514: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
14515: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
14516: $path =~ s{/$}{};
14517: my $item;
14518: if ($path ne '') {
14519: $item = "$path/$titles{$i}";
14520: } else {
14521: $item = $titles{$i};
14522: }
14523: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
14524: if ($item eq $contents[0]) {
14525: push(@{$env{'form.archive_directory'}},$i);
14526: $env{'form.archive_'.$i} = 'display';
14527: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
14528: $displayed{'folder'} = $i;
1.1164 raeburn 14529: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
14530: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 14531: $env{'form.archive_'.$i} = 'display';
14532: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
14533: $displayed{'web'} = $i;
14534: } else {
1.1164 raeburn 14535: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
14536: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
14537: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 14538: push(@{$env{'form.archive_directory'}},$i);
14539: }
14540: $env{'form.archive_'.$i} = 'dependency';
14541: }
14542: $total ++;
14543: }
14544: for (my $i=1; $i<$total; $i++) {
14545: next if ($i == $displayed{'web'});
14546: next if ($i == $displayed{'folder'});
14547: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
14548: }
14549: $env{'form.phase'} = 'decompress_cleanup';
14550: $env{'form.archivedelete'} = 1;
14551: $env{'form.archive_count'} = $total-1;
14552: $output .=
14553: &process_extracted_files('coursedocs',$docudom,
14554: $docuname,$destination,
14555: $dir_root,$hiddenelem);
14556: }
1.1055 raeburn 14557: } else {
14558: $warning = &mt('No new items extracted from archive file.');
14559: }
14560: } else {
14561: $output = $display;
14562: $error = &mt('An error occurred during extraction from the archive file.');
14563: }
14564: }
14565: }
14566: }
14567: if ($error) {
14568: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14569: $error.'</p>'."\n";
14570: }
14571: if ($warning) {
14572: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14573: }
14574: return $output;
14575: }
14576:
14577: sub get_extracted {
1.1056 raeburn 14578: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
14579: $titles,$wantform) = @_;
1.1055 raeburn 14580: my $count = 0;
14581: my $depth = 0;
14582: my $datatable;
1.1056 raeburn 14583: my @hierarchy;
1.1055 raeburn 14584: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 14585: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
14586: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 14587: foreach my $item (@{$contents}) {
14588: $count ++;
1.1056 raeburn 14589: @{$dirorder->{$count}} = @hierarchy;
14590: $titles->{$count} = $item;
1.1055 raeburn 14591: &archive_hierarchy($depth,$count,$parent,$children);
14592: if ($wantform) {
14593: $datatable .= &archive_row($is_dir->{$item},$item,
14594: $currdir,$depth,$count);
14595: }
14596: if ($is_dir->{$item}) {
14597: $depth ++;
1.1056 raeburn 14598: push(@hierarchy,$count);
14599: $parent->{$depth} = $count;
1.1055 raeburn 14600: $datatable .=
14601: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 14602: \$depth,\$count,\@hierarchy,$dirorder,
14603: $children,$parent,$titles,$wantform);
1.1055 raeburn 14604: $depth --;
1.1056 raeburn 14605: pop(@hierarchy);
1.1055 raeburn 14606: }
14607: }
14608: return ($count,$datatable);
14609: }
14610:
14611: sub recurse_extracted_archive {
1.1056 raeburn 14612: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
14613: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 14614: my $result='';
1.1056 raeburn 14615: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
14616: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
14617: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 14618: return $result;
14619: }
14620: my $dirptr = 16384;
14621: my ($newdirlistref,$newlisterror) =
14622: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
14623: if (ref($newdirlistref) eq 'ARRAY') {
14624: foreach my $dir_line (@{$newdirlistref}) {
14625: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
14626: unless ($item =~ /^\.+$/) {
14627: $$count ++;
1.1056 raeburn 14628: @{$dirorder->{$$count}} = @{$hierarchy};
14629: $titles->{$$count} = $item;
1.1055 raeburn 14630: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 14631:
1.1055 raeburn 14632: my $is_dir;
14633: if ($dirptr&$testdir) {
14634: $is_dir = 1;
14635: }
14636: if ($wantform) {
14637: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
14638: }
14639: if ($is_dir) {
14640: $$depth ++;
1.1056 raeburn 14641: push(@{$hierarchy},$$count);
14642: $parent->{$$depth} = $$count;
1.1055 raeburn 14643: $result .=
14644: &recurse_extracted_archive("$currdir/$item",$docudom,
14645: $docuname,$depth,$count,
1.1056 raeburn 14646: $hierarchy,$dirorder,$children,
14647: $parent,$titles,$wantform);
1.1055 raeburn 14648: $$depth --;
1.1056 raeburn 14649: pop(@{$hierarchy});
1.1055 raeburn 14650: }
14651: }
14652: }
14653: }
14654: return $result;
14655: }
14656:
14657: sub archive_hierarchy {
14658: my ($depth,$count,$parent,$children) =@_;
14659: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
14660: if (exists($parent->{$depth})) {
14661: $children->{$parent->{$depth}} .= $count.':';
14662: }
14663: }
14664: return;
14665: }
14666:
14667: sub archive_row {
14668: my ($is_dir,$item,$currdir,$depth,$count) = @_;
14669: my ($name) = ($item =~ m{([^/]+)$});
14670: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 14671: 'display' => 'Add as file',
1.1055 raeburn 14672: 'dependency' => 'Include as dependency',
14673: 'discard' => 'Discard',
14674: );
14675: if ($is_dir) {
1.1059 raeburn 14676: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 14677: }
1.1056 raeburn 14678: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
14679: my $offset = 0;
1.1055 raeburn 14680: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 14681: $offset ++;
1.1065 raeburn 14682: if ($action ne 'display') {
14683: $offset ++;
14684: }
1.1055 raeburn 14685: $output .= '<td><span class="LC_nobreak">'.
14686: '<label><input type="radio" name="archive_'.$count.
14687: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
14688: my $text = $choices{$action};
14689: if ($is_dir) {
14690: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
14691: if ($action eq 'display') {
1.1059 raeburn 14692: $text = &mt('Add as folder');
1.1055 raeburn 14693: }
1.1056 raeburn 14694: } else {
14695: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
14696:
14697: }
14698: $output .= ' /> '.$choices{$action}.'</label></span>';
14699: if ($action eq 'dependency') {
14700: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
14701: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
14702: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
14703: '<option value=""></option>'."\n".
14704: '</select>'."\n".
14705: '</div>';
1.1059 raeburn 14706: } elsif ($action eq 'display') {
14707: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
14708: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
14709: '</div>';
1.1055 raeburn 14710: }
1.1056 raeburn 14711: $output .= '</td>';
1.1055 raeburn 14712: }
14713: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
14714: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
14715: for (my $i=0; $i<$depth; $i++) {
14716: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
14717: }
14718: if ($is_dir) {
14719: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
14720: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
14721: } else {
14722: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
14723: }
14724: $output .= ' '.$name.'</td>'."\n".
14725: &end_data_table_row();
14726: return $output;
14727: }
14728:
14729: sub archive_options_form {
1.1065 raeburn 14730: my ($form,$display,$count,$hiddenelem) = @_;
14731: my %lt = &Apache::lonlocal::texthash(
14732: perm => 'Permanently remove archive file?',
14733: hows => 'How should each extracted item be incorporated in the course?',
14734: cont => 'Content actions for all',
14735: addf => 'Add as folder/file',
14736: incd => 'Include as dependency for a displayed file',
14737: disc => 'Discard',
14738: no => 'No',
14739: yes => 'Yes',
14740: save => 'Save',
14741: );
14742: my $output = <<"END";
14743: <form name="$form" method="post" action="">
14744: <p><span class="LC_nobreak">$lt{'perm'}
14745: <label>
14746: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
14747: </label>
14748:
14749: <label>
14750: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
14751: </span>
14752: </p>
14753: <input type="hidden" name="phase" value="decompress_cleanup" />
14754: <br />$lt{'hows'}
14755: <div class="LC_columnSection">
14756: <fieldset>
14757: <legend>$lt{'cont'}</legend>
14758: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
14759: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
14760: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
14761: </fieldset>
14762: </div>
14763: END
14764: return $output.
1.1055 raeburn 14765: &start_data_table()."\n".
1.1065 raeburn 14766: $display."\n".
1.1055 raeburn 14767: &end_data_table()."\n".
14768: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
14769: $hiddenelem.
1.1065 raeburn 14770: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 14771: '</form>';
14772: }
14773:
14774: sub archive_javascript {
1.1056 raeburn 14775: my ($startcount,$numitems,$titles,$children) = @_;
14776: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 14777: my $maintitle = $env{'form.comment'};
1.1055 raeburn 14778: my $scripttag = <<START;
14779: <script type="text/javascript">
14780: // <![CDATA[
14781:
14782: function checkAll(form,prefix) {
14783: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
14784: for (var i=0; i < form.elements.length; i++) {
14785: var id = form.elements[i].id;
14786: if ((id != '') && (id != undefined)) {
14787: if (idstr.test(id)) {
14788: if (form.elements[i].type == 'radio') {
14789: form.elements[i].checked = true;
1.1056 raeburn 14790: var nostart = i-$startcount;
1.1059 raeburn 14791: var offset = nostart%7;
14792: var count = (nostart-offset)/7;
1.1056 raeburn 14793: dependencyCheck(form,count,offset);
1.1055 raeburn 14794: }
14795: }
14796: }
14797: }
14798: }
14799:
14800: function propagateCheck(form,count) {
14801: if (count > 0) {
1.1059 raeburn 14802: var startelement = $startcount + ((count-1) * 7);
14803: for (var j=1; j<6; j++) {
14804: if ((j != 2) && (j != 4)) {
1.1056 raeburn 14805: var item = startelement + j;
14806: if (form.elements[item].type == 'radio') {
14807: if (form.elements[item].checked) {
14808: containerCheck(form,count,j);
14809: break;
14810: }
1.1055 raeburn 14811: }
14812: }
14813: }
14814: }
14815: }
14816:
14817: numitems = $numitems
1.1056 raeburn 14818: var titles = new Array(numitems);
14819: var parents = new Array(numitems);
1.1055 raeburn 14820: for (var i=0; i<numitems; i++) {
1.1056 raeburn 14821: parents[i] = new Array;
1.1055 raeburn 14822: }
1.1059 raeburn 14823: var maintitle = '$maintitle';
1.1055 raeburn 14824:
14825: START
14826:
1.1056 raeburn 14827: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
14828: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 14829: for (my $i=0; $i<@contents; $i ++) {
14830: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
14831: }
14832: }
14833:
1.1056 raeburn 14834: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
14835: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
14836: }
14837:
1.1055 raeburn 14838: $scripttag .= <<END;
14839:
14840: function containerCheck(form,count,offset) {
14841: if (count > 0) {
1.1056 raeburn 14842: dependencyCheck(form,count,offset);
1.1059 raeburn 14843: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 14844: form.elements[item].checked = true;
14845: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
14846: if (parents[count].length > 0) {
14847: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 14848: containerCheck(form,parents[count][j],offset);
14849: }
14850: }
14851: }
14852: }
14853: }
14854:
14855: function dependencyCheck(form,count,offset) {
14856: if (count > 0) {
1.1059 raeburn 14857: var chosen = (offset+$startcount)+7*(count-1);
14858: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 14859: var currtype = form.elements[depitem].type;
14860: if (form.elements[chosen].value == 'dependency') {
14861: document.getElementById('arc_depon_'+count).style.display='block';
14862: form.elements[depitem].options.length = 0;
14863: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 14864: for (var i=1; i<=numitems; i++) {
14865: if (i == count) {
14866: continue;
14867: }
1.1059 raeburn 14868: var startelement = $startcount + (i-1) * 7;
14869: for (var j=1; j<6; j++) {
14870: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 14871: var item = startelement + j;
14872: if (form.elements[item].type == 'radio') {
14873: if (form.elements[item].checked) {
14874: if (form.elements[item].value == 'display') {
14875: var n = form.elements[depitem].options.length;
14876: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
14877: }
14878: }
14879: }
14880: }
14881: }
14882: }
14883: } else {
14884: document.getElementById('arc_depon_'+count).style.display='none';
14885: form.elements[depitem].options.length = 0;
14886: form.elements[depitem].options[0] = new Option('Select','',true,true);
14887: }
1.1059 raeburn 14888: titleCheck(form,count,offset);
1.1056 raeburn 14889: }
14890: }
14891:
14892: function propagateSelect(form,count,offset) {
14893: if (count > 0) {
1.1065 raeburn 14894: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 14895: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
14896: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14897: if (parents[count].length > 0) {
14898: for (var j=0; j<parents[count].length; j++) {
14899: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 14900: }
14901: }
14902: }
14903: }
14904: }
1.1056 raeburn 14905:
14906: function containerSelect(form,count,offset,picked) {
14907: if (count > 0) {
1.1065 raeburn 14908: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 14909: if (form.elements[item].type == 'radio') {
14910: if (form.elements[item].value == 'dependency') {
14911: if (form.elements[item+1].type == 'select-one') {
14912: for (var i=0; i<form.elements[item+1].options.length; i++) {
14913: if (form.elements[item+1].options[i].value == picked) {
14914: form.elements[item+1].selectedIndex = i;
14915: break;
14916: }
14917: }
14918: }
14919: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14920: if (parents[count].length > 0) {
14921: for (var j=0; j<parents[count].length; j++) {
14922: containerSelect(form,parents[count][j],offset,picked);
14923: }
14924: }
14925: }
14926: }
14927: }
14928: }
14929: }
14930:
1.1059 raeburn 14931: function titleCheck(form,count,offset) {
14932: if (count > 0) {
14933: var chosen = (offset+$startcount)+7*(count-1);
14934: var depitem = $startcount + ((count-1) * 7) + 2;
14935: var currtype = form.elements[depitem].type;
14936: if (form.elements[chosen].value == 'display') {
14937: document.getElementById('arc_title_'+count).style.display='block';
14938: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
14939: document.getElementById('archive_title_'+count).value=maintitle;
14940: }
14941: } else {
14942: document.getElementById('arc_title_'+count).style.display='none';
14943: if (currtype == 'text') {
14944: document.getElementById('archive_title_'+count).value='';
14945: }
14946: }
14947: }
14948: return;
14949: }
14950:
1.1055 raeburn 14951: // ]]>
14952: </script>
14953: END
14954: return $scripttag;
14955: }
14956:
14957: sub process_extracted_files {
1.1067 raeburn 14958: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 14959: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 14960: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 14961: my @ids=&Apache::lonnet::current_machine_ids();
14962: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 14963: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 14964: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14965: if (grep(/^\Q$docuhome\E$/,@ids)) {
14966: $prefix = &LONCAPA::propath($docudom,$docuname);
14967: $pathtocheck = "$dir_root/$destination";
14968: $dir = $dir_root;
14969: $ishome = 1;
14970: } else {
14971: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
14972: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 14973: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 14974: }
14975: my $currdir = "$dir_root/$destination";
14976: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
14977: if ($env{'form.folderpath'}) {
14978: my @items = split('&',$env{'form.folderpath'});
14979: $folders{'0'} = $items[-2];
1.1099 raeburn 14980: if ($env{'form.folderpath'} =~ /\:1$/) {
14981: $containers{'0'}='page';
14982: } else {
14983: $containers{'0'}='sequence';
14984: }
1.1055 raeburn 14985: }
14986: my @archdirs = &get_env_multiple('form.archive_directory');
14987: if ($numitems) {
14988: for (my $i=1; $i<=$numitems; $i++) {
14989: my $path = $env{'form.archive_content_'.$i};
14990: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
14991: my $item = $1;
14992: $toplevelitems{$item} = $i;
14993: if (grep(/^\Q$i\E$/,@archdirs)) {
14994: $is_dir{$item} = 1;
14995: }
14996: }
14997: }
14998: }
1.1067 raeburn 14999: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 15000: if (keys(%toplevelitems) > 0) {
15001: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 15002: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
15003: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 15004: }
1.1066 raeburn 15005: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 15006: if ($numitems) {
15007: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 15008: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 15009: my $path = $env{'form.archive_content_'.$i};
15010: if ($path =~ /^\Q$pathtocheck\E/) {
15011: if ($env{'form.archive_'.$i} eq 'discard') {
15012: if ($prefix ne '' && $path ne '') {
15013: if (-e $prefix.$path) {
1.1066 raeburn 15014: if ((@archdirs > 0) &&
15015: (grep(/^\Q$i\E$/,@archdirs))) {
15016: $todeletedir{$prefix.$path} = 1;
15017: } else {
15018: $todelete{$prefix.$path} = 1;
15019: }
1.1055 raeburn 15020: }
15021: }
15022: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 15023: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 15024: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 15025: $docstitle = $env{'form.archive_title_'.$i};
15026: if ($docstitle eq '') {
15027: $docstitle = $title;
15028: }
1.1055 raeburn 15029: $outer = 0;
1.1056 raeburn 15030: if (ref($dirorder{$i}) eq 'ARRAY') {
15031: if (@{$dirorder{$i}} > 0) {
15032: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 15033: if ($env{'form.archive_'.$item} eq 'display') {
15034: $outer = $item;
15035: last;
15036: }
15037: }
15038: }
15039: }
15040: my ($errtext,$fatal) =
15041: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
15042: '/'.$folders{$outer}.'.'.
15043: $containers{$outer});
15044: next if ($fatal);
15045: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
15046: if ($context eq 'coursedocs') {
1.1056 raeburn 15047: $mapinner{$i} = time;
1.1055 raeburn 15048: $folders{$i} = 'default_'.$mapinner{$i};
15049: $containers{$i} = 'sequence';
15050: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
15051: $folders{$i}.'.'.$containers{$i};
15052: my $newidx = &LONCAPA::map::getresidx();
15053: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 15054: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 15055: push(@LONCAPA::map::order,$newidx);
15056: my ($outtext,$errtext) =
15057: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
15058: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 15059: '.'.$containers{$outer},1,1);
1.1056 raeburn 15060: $newseqid{$i} = $newidx;
1.1067 raeburn 15061: unless ($errtext) {
1.1294 raeburn 15062: $result .= '<li>'.&mt('Folder: [_1] added to course',
15063: &HTML::Entities::encode($docstitle,'<>&"')).
15064: '</li>'."\n";
1.1067 raeburn 15065: }
1.1055 raeburn 15066: }
15067: } else {
15068: if ($context eq 'coursedocs') {
15069: my $newidx=&LONCAPA::map::getresidx();
15070: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
15071: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
15072: $title;
1.1392 raeburn 15073: if (($outer !~ /\D/) &&
15074: (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
15075: ($newidx !~ /\D/)) {
1.1294 raeburn 15076: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
15077: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
15078: }
15079: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
15080: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
15081: }
15082: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
15083: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
15084: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
15085: unless ($ishome) {
15086: my $fetch = "$newdest{$i}/$title";
15087: $fetch =~ s/^\Q$prefix$dir\E//;
15088: $prompttofetch{$fetch} = 1;
15089: }
1.1292 raeburn 15090: }
1.1067 raeburn 15091: }
1.1294 raeburn 15092: $LONCAPA::map::resources[$newidx]=
15093: $docstitle.':'.$url.':false:normal:res';
15094: push(@LONCAPA::map::order, $newidx);
15095: my ($outtext,$errtext)=
15096: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
15097: $docuname.'/'.$folders{$outer}.
15098: '.'.$containers{$outer},1,1);
15099: unless ($errtext) {
15100: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
15101: $result .= '<li>'.&mt('File: [_1] added to course',
15102: &HTML::Entities::encode($docstitle,'<>&"')).
15103: '</li>'."\n";
15104: }
1.1067 raeburn 15105: }
1.1294 raeburn 15106: } else {
15107: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
15108: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 15109: }
1.1055 raeburn 15110: }
15111: }
1.1086 raeburn 15112: }
15113: } else {
1.1294 raeburn 15114: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
15115: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 15116: }
15117: }
15118: for (my $i=1; $i<=$numitems; $i++) {
15119: next unless ($env{'form.archive_'.$i} eq 'dependency');
15120: my $path = $env{'form.archive_content_'.$i};
15121: if ($path =~ /^\Q$pathtocheck\E/) {
15122: my ($title) = ($path =~ m{/([^/]+)$});
15123: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
15124: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
15125: if (ref($dirorder{$i}) eq 'ARRAY') {
15126: my ($itemidx,$fullpath,$relpath);
15127: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
15128: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 15129: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 15130: if ($dirorder{$i}->[$j] eq $container) {
15131: $itemidx = $j;
1.1056 raeburn 15132: }
15133: }
1.1086 raeburn 15134: }
15135: if ($itemidx eq '') {
15136: $itemidx = 0;
15137: }
15138: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
15139: if ($mapinner{$referrer{$i}}) {
15140: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
15141: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
15142: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
15143: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
15144: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
15145: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
15146: if (!-e $fullpath) {
15147: mkdir($fullpath,0755);
1.1056 raeburn 15148: }
15149: }
1.1086 raeburn 15150: } else {
15151: last;
1.1056 raeburn 15152: }
1.1086 raeburn 15153: }
15154: }
15155: } elsif ($newdest{$referrer{$i}}) {
15156: $fullpath = $newdest{$referrer{$i}};
15157: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
15158: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
15159: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
15160: last;
15161: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
15162: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
15163: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
15164: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
15165: if (!-e $fullpath) {
15166: mkdir($fullpath,0755);
1.1056 raeburn 15167: }
15168: }
1.1086 raeburn 15169: } else {
15170: last;
1.1056 raeburn 15171: }
1.1055 raeburn 15172: }
15173: }
1.1086 raeburn 15174: if ($fullpath ne '') {
15175: if (-e "$prefix$path") {
1.1292 raeburn 15176: unless (rename("$prefix$path","$fullpath/$title")) {
15177: $warning .= &mt('Failed to rename dependency').'<br />';
15178: }
1.1086 raeburn 15179: }
15180: if (-e "$fullpath/$title") {
15181: my $showpath;
15182: if ($relpath ne '') {
15183: $showpath = "$relpath/$title";
15184: } else {
15185: $showpath = "/$title";
15186: }
1.1294 raeburn 15187: $result .= '<li>'.&mt('[_1] included as a dependency',
15188: &HTML::Entities::encode($showpath,'<>&"')).
15189: '</li>'."\n";
1.1292 raeburn 15190: unless ($ishome) {
15191: my $fetch = "$fullpath/$title";
15192: $fetch =~ s/^\Q$prefix$dir\E//;
15193: $prompttofetch{$fetch} = 1;
15194: }
1.1086 raeburn 15195: }
15196: }
1.1055 raeburn 15197: }
1.1086 raeburn 15198: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
15199: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 15200: &HTML::Entities::encode($path,'<>&"'),
15201: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
15202: '<br />';
1.1055 raeburn 15203: }
15204: } else {
1.1294 raeburn 15205: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 15206: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 15207: }
15208: }
15209: if (keys(%todelete)) {
15210: foreach my $key (keys(%todelete)) {
15211: unlink($key);
1.1066 raeburn 15212: }
15213: }
15214: if (keys(%todeletedir)) {
15215: foreach my $key (keys(%todeletedir)) {
15216: rmdir($key);
15217: }
15218: }
15219: foreach my $dir (sort(keys(%is_dir))) {
15220: if (($pathtocheck ne '') && ($dir ne '')) {
15221: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 15222: }
15223: }
1.1067 raeburn 15224: if ($result ne '') {
15225: $output .= '<ul>'."\n".
15226: $result."\n".
15227: '</ul>';
15228: }
15229: unless ($ishome) {
15230: my $replicationfail;
15231: foreach my $item (keys(%prompttofetch)) {
15232: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
15233: unless ($fetchresult eq 'ok') {
15234: $replicationfail .= '<li>'.$item.'</li>'."\n";
15235: }
15236: }
15237: if ($replicationfail) {
15238: $output .= '<p class="LC_error">'.
15239: &mt('Course home server failed to retrieve:').'<ul>'.
15240: $replicationfail.
15241: '</ul></p>';
15242: }
15243: }
1.1055 raeburn 15244: } else {
15245: $warning = &mt('No items found in archive.');
15246: }
15247: if ($error) {
15248: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
15249: $error.'</p>'."\n";
15250: }
15251: if ($warning) {
15252: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
15253: }
15254: return $output;
15255: }
15256:
1.1066 raeburn 15257: sub cleanup_empty_dirs {
15258: my ($path) = @_;
15259: if (($path ne '') && (-d $path)) {
15260: if (opendir(my $dirh,$path)) {
15261: my @dircontents = grep(!/^\./,readdir($dirh));
15262: my $numitems = 0;
15263: foreach my $item (@dircontents) {
15264: if (-d "$path/$item") {
1.1111 raeburn 15265: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 15266: if (-e "$path/$item") {
15267: $numitems ++;
15268: }
15269: } else {
15270: $numitems ++;
15271: }
15272: }
15273: if ($numitems == 0) {
15274: rmdir($path);
15275: }
15276: closedir($dirh);
15277: }
15278: }
15279: return;
15280: }
15281:
1.41 ng 15282: =pod
1.45 matthew 15283:
1.1162 raeburn 15284: =item * &get_folder_hierarchy()
1.1068 raeburn 15285:
15286: Provides hierarchy of names of folders/sub-folders containing the current
15287: item,
15288:
15289: Inputs: 3
15290: - $navmap - navmaps object
15291:
15292: - $map - url for map (either the trigger itself, or map containing
15293: the resource, which is the trigger).
15294:
15295: - $showitem - 1 => show title for map itself; 0 => do not show.
15296:
15297: Outputs: 1 @pathitems - array of folder/subfolder names.
15298:
15299: =cut
15300:
15301: sub get_folder_hierarchy {
15302: my ($navmap,$map,$showitem) = @_;
15303: my @pathitems;
15304: if (ref($navmap)) {
15305: my $mapres = $navmap->getResourceByUrl($map);
15306: if (ref($mapres)) {
15307: my $pcslist = $mapres->map_hierarchy();
15308: if ($pcslist ne '') {
15309: my @pcs = split(/,/,$pcslist);
15310: foreach my $pc (@pcs) {
15311: if ($pc == 1) {
1.1129 raeburn 15312: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 15313: } else {
15314: my $res = $navmap->getByMapPc($pc);
15315: if (ref($res)) {
15316: my $title = $res->compTitle();
15317: $title =~ s/\W+/_/g;
15318: if ($title ne '') {
15319: push(@pathitems,$title);
15320: }
15321: }
15322: }
15323: }
15324: }
1.1071 raeburn 15325: if ($showitem) {
15326: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 15327: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 15328: } else {
15329: my $maptitle = $mapres->compTitle();
15330: $maptitle =~ s/\W+/_/g;
15331: if ($maptitle ne '') {
15332: push(@pathitems,$maptitle);
15333: }
1.1068 raeburn 15334: }
15335: }
15336: }
15337: }
15338: return @pathitems;
15339: }
15340:
15341: =pod
15342:
1.1015 raeburn 15343: =item * &get_turnedin_filepath()
15344:
15345: Determines path in a user's portfolio file for storage of files uploaded
15346: to a specific essayresponse or dropbox item.
15347:
15348: Inputs: 3 required + 1 optional.
15349: $symb is symb for resource, $uname and $udom are for current user (required).
15350: $caller is optional (can be "submission", if routine is called when storing
15351: an upoaded file when "Submit Answer" button was pressed).
15352:
15353: Returns array containing $path and $multiresp.
15354: $path is path in portfolio. $multiresp is 1 if this resource contains more
15355: than one file upload item. Callers of routine should append partid as a
15356: subdirectory to $path in cases where $multiresp is 1.
15357:
15358: Called by: homework/essayresponse.pm and homework/structuretags.pm
15359:
15360: =cut
15361:
15362: sub get_turnedin_filepath {
15363: my ($symb,$uname,$udom,$caller) = @_;
15364: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
15365: my $turnindir;
15366: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
15367: $turnindir = $userhash{'turnindir'};
15368: my ($path,$multiresp);
15369: if ($turnindir eq '') {
15370: if ($caller eq 'submission') {
15371: $turnindir = &mt('turned in');
15372: $turnindir =~ s/\W+/_/g;
15373: my %newhash = (
15374: 'turnindir' => $turnindir,
15375: );
15376: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
15377: }
15378: }
15379: if ($turnindir ne '') {
15380: $path = '/'.$turnindir.'/';
15381: my ($multipart,$turnin,@pathitems);
15382: my $navmap = Apache::lonnavmaps::navmap->new();
15383: if (defined($navmap)) {
15384: my $mapres = $navmap->getResourceByUrl($map);
15385: if (ref($mapres)) {
15386: my $pcslist = $mapres->map_hierarchy();
15387: if ($pcslist ne '') {
15388: foreach my $pc (split(/,/,$pcslist)) {
15389: my $res = $navmap->getByMapPc($pc);
15390: if (ref($res)) {
15391: my $title = $res->compTitle();
15392: $title =~ s/\W+/_/g;
15393: if ($title ne '') {
1.1149 raeburn 15394: if (($pc > 1) && (length($title) > 12)) {
15395: $title = substr($title,0,12);
15396: }
1.1015 raeburn 15397: push(@pathitems,$title);
15398: }
15399: }
15400: }
15401: }
15402: my $maptitle = $mapres->compTitle();
15403: $maptitle =~ s/\W+/_/g;
15404: if ($maptitle ne '') {
1.1149 raeburn 15405: if (length($maptitle) > 12) {
15406: $maptitle = substr($maptitle,0,12);
15407: }
1.1015 raeburn 15408: push(@pathitems,$maptitle);
15409: }
15410: unless ($env{'request.state'} eq 'construct') {
15411: my $res = $navmap->getBySymb($symb);
15412: if (ref($res)) {
15413: my $partlist = $res->parts();
15414: my $totaluploads = 0;
15415: if (ref($partlist) eq 'ARRAY') {
15416: foreach my $part (@{$partlist}) {
15417: my @types = $res->responseType($part);
15418: my @ids = $res->responseIds($part);
15419: for (my $i=0; $i < scalar(@ids); $i++) {
15420: if ($types[$i] eq 'essay') {
15421: my $partid = $part.'_'.$ids[$i];
15422: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
15423: $totaluploads ++;
15424: }
15425: }
15426: }
15427: }
15428: if ($totaluploads > 1) {
15429: $multiresp = 1;
15430: }
15431: }
15432: }
15433: }
15434: } else {
15435: return;
15436: }
15437: } else {
15438: return;
15439: }
15440: my $restitle=&Apache::lonnet::gettitle($symb);
15441: $restitle =~ s/\W+/_/g;
15442: if ($restitle eq '') {
15443: $restitle = ($resurl =~ m{/[^/]+$});
15444: if ($restitle eq '') {
15445: $restitle = time;
15446: }
15447: }
1.1149 raeburn 15448: if (length($restitle) > 12) {
15449: $restitle = substr($restitle,0,12);
15450: }
1.1015 raeburn 15451: push(@pathitems,$restitle);
15452: $path .= join('/',@pathitems);
15453: }
15454: return ($path,$multiresp);
15455: }
15456:
15457: =pod
15458:
1.464 albertel 15459: =back
1.41 ng 15460:
1.112 bowersj2 15461: =head1 CSV Upload/Handling functions
1.38 albertel 15462:
1.41 ng 15463: =over 4
15464:
1.648 raeburn 15465: =item * &upfile_store($r)
1.41 ng 15466:
15467: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 15468: needs $env{'form.upfile'}
1.41 ng 15469: returns $datatoken to be put into hidden field
15470:
15471: =cut
1.31 albertel 15472:
15473: sub upfile_store {
15474: my $r=shift;
1.258 albertel 15475: $env{'form.upfile'}=~s/\r/\n/gs;
15476: $env{'form.upfile'}=~s/\f/\n/gs;
15477: $env{'form.upfile'}=~s/\n+/\n/gs;
15478: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 15479:
1.1299 raeburn 15480: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
15481: '_enroll_'.$env{'request.course.id'}.'_'.
15482: time.'_'.$$);
15483: return if ($datatoken eq '');
15484:
1.31 albertel 15485: {
1.158 raeburn 15486: my $datafile = $r->dir_config('lonDaemons').
15487: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 15488: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 15489: print $fh $env{'form.upfile'};
1.158 raeburn 15490: close($fh);
15491: }
1.31 albertel 15492: }
15493: return $datatoken;
15494: }
15495:
1.56 matthew 15496: =pod
15497:
1.1290 raeburn 15498: =item * &load_tmp_file($r,$datatoken)
1.41 ng 15499:
15500: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 15501: $datatoken is the name to assign to the temporary file.
1.258 albertel 15502: sets $env{'form.upfile'} to the contents of the file
1.41 ng 15503:
15504: =cut
1.31 albertel 15505:
15506: sub load_tmp_file {
1.1290 raeburn 15507: my ($r,$datatoken) = @_;
15508: return if ($datatoken eq '');
1.31 albertel 15509: my @studentdata=();
15510: {
1.158 raeburn 15511: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 15512: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 15513: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 15514: @studentdata=<$fh>;
15515: close($fh);
15516: }
1.31 albertel 15517: }
1.258 albertel 15518: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 15519: }
15520:
1.1290 raeburn 15521: sub valid_datatoken {
15522: my ($datatoken) = @_;
1.1325 raeburn 15523: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 15524: return $datatoken;
15525: }
15526: return;
15527: }
15528:
1.56 matthew 15529: =pod
15530:
1.648 raeburn 15531: =item * &upfile_record_sep()
1.41 ng 15532:
15533: Separate uploaded file into records
15534: returns array of records,
1.258 albertel 15535: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 15536:
15537: =cut
1.31 albertel 15538:
15539: sub upfile_record_sep {
1.258 albertel 15540: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 15541: } else {
1.248 albertel 15542: my @records;
1.258 albertel 15543: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 15544: if ($line=~/^\s*$/) { next; }
15545: push(@records,$line);
15546: }
15547: return @records;
1.31 albertel 15548: }
15549: }
15550:
1.56 matthew 15551: =pod
15552:
1.648 raeburn 15553: =item * &record_sep($record)
1.41 ng 15554:
1.258 albertel 15555: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 15556:
15557: =cut
15558:
1.263 www 15559: sub takeleft {
15560: my $index=shift;
15561: return substr('0000'.$index,-4,4);
15562: }
15563:
1.31 albertel 15564: sub record_sep {
15565: my $record=shift;
15566: my %components=();
1.258 albertel 15567: if ($env{'form.upfiletype'} eq 'xml') {
15568: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 15569: my $i=0;
1.356 albertel 15570: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 15571: $field=~s/^(\"|\')//;
15572: $field=~s/(\"|\')$//;
1.263 www 15573: $components{&takeleft($i)}=$field;
1.31 albertel 15574: $i++;
15575: }
1.258 albertel 15576: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 15577: my $i=0;
1.356 albertel 15578: foreach my $field (split(/\t/,$record)) {
1.31 albertel 15579: $field=~s/^(\"|\')//;
15580: $field=~s/(\"|\')$//;
1.263 www 15581: $components{&takeleft($i)}=$field;
1.31 albertel 15582: $i++;
15583: }
15584: } else {
1.561 www 15585: my $separator=',';
1.480 banghart 15586: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 15587: $separator=';';
1.480 banghart 15588: }
1.31 albertel 15589: my $i=0;
1.561 www 15590: # the character we are looking for to indicate the end of a quote or a record
15591: my $looking_for=$separator;
15592: # do not add the characters to the fields
15593: my $ignore=0;
15594: # we just encountered a separator (or the beginning of the record)
15595: my $just_found_separator=1;
15596: # store the field we are working on here
15597: my $field='';
15598: # work our way through all characters in record
15599: foreach my $character ($record=~/(.)/g) {
15600: if ($character eq $looking_for) {
15601: if ($character ne $separator) {
15602: # Found the end of a quote, again looking for separator
15603: $looking_for=$separator;
15604: $ignore=1;
15605: } else {
15606: # Found a separator, store away what we got
15607: $components{&takeleft($i)}=$field;
15608: $i++;
15609: $just_found_separator=1;
15610: $ignore=0;
15611: $field='';
15612: }
15613: next;
15614: }
15615: # single or double quotation marks after a separator indicate beginning of a quote
15616: # we are now looking for the end of the quote and need to ignore separators
15617: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
15618: $looking_for=$character;
15619: next;
15620: }
15621: # ignore would be true after we reached the end of a quote
15622: if ($ignore) { next; }
15623: if (($just_found_separator) && ($character=~/\s/)) { next; }
15624: $field.=$character;
15625: $just_found_separator=0;
1.31 albertel 15626: }
1.561 www 15627: # catch the very last entry, since we never encountered the separator
15628: $components{&takeleft($i)}=$field;
1.31 albertel 15629: }
15630: return %components;
15631: }
15632:
1.144 matthew 15633: ######################################################
15634: ######################################################
15635:
1.56 matthew 15636: =pod
15637:
1.648 raeburn 15638: =item * &upfile_select_html()
1.41 ng 15639:
1.144 matthew 15640: Return HTML code to select a file from the users machine and specify
15641: the file type.
1.41 ng 15642:
15643: =cut
15644:
1.144 matthew 15645: ######################################################
15646: ######################################################
1.31 albertel 15647: sub upfile_select_html {
1.144 matthew 15648: my %Types = (
15649: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 15650: semisv => &mt('Semicolon separated values'),
1.144 matthew 15651: space => &mt('Space separated'),
15652: tab => &mt('Tabulator separated'),
15653: # xml => &mt('HTML/XML'),
15654: );
15655: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 15656: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 15657: foreach my $type (sort(keys(%Types))) {
15658: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
15659: }
15660: $Str .= "</select>\n";
15661: return $Str;
1.31 albertel 15662: }
15663:
1.301 albertel 15664: sub get_samples {
15665: my ($records,$toget) = @_;
15666: my @samples=({});
15667: my $got=0;
15668: foreach my $rec (@$records) {
15669: my %temp = &record_sep($rec);
15670: if (! grep(/\S/, values(%temp))) { next; }
15671: if (%temp) {
15672: $samples[$got]=\%temp;
15673: $got++;
15674: if ($got == $toget) { last; }
15675: }
15676: }
15677: return \@samples;
15678: }
15679:
1.144 matthew 15680: ######################################################
15681: ######################################################
15682:
1.56 matthew 15683: =pod
15684:
1.648 raeburn 15685: =item * &csv_print_samples($r,$records)
1.41 ng 15686:
15687: Prints a table of sample values from each column uploaded $r is an
15688: Apache Request ref, $records is an arrayref from
15689: &Apache::loncommon::upfile_record_sep
15690:
15691: =cut
15692:
1.144 matthew 15693: ######################################################
15694: ######################################################
1.31 albertel 15695: sub csv_print_samples {
15696: my ($r,$records) = @_;
1.662 bisitz 15697: my $samples = &get_samples($records,5);
1.301 albertel 15698:
1.594 raeburn 15699: $r->print(&mt('Samples').'<br />'.&start_data_table().
15700: &start_data_table_header_row());
1.356 albertel 15701: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 15702: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 15703: $r->print(&end_data_table_header_row());
1.301 albertel 15704: foreach my $hash (@$samples) {
1.594 raeburn 15705: $r->print(&start_data_table_row());
1.356 albertel 15706: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 15707: $r->print('<td>');
1.356 albertel 15708: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 15709: $r->print('</td>');
15710: }
1.594 raeburn 15711: $r->print(&end_data_table_row());
1.31 albertel 15712: }
1.594 raeburn 15713: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 15714: }
15715:
1.144 matthew 15716: ######################################################
15717: ######################################################
15718:
1.56 matthew 15719: =pod
15720:
1.648 raeburn 15721: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 15722:
15723: Prints a table to create associations between values and table columns.
1.144 matthew 15724:
1.41 ng 15725: $r is an Apache Request ref,
15726: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 15727: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 15728:
15729: =cut
15730:
1.144 matthew 15731: ######################################################
15732: ######################################################
1.31 albertel 15733: sub csv_print_select_table {
15734: my ($r,$records,$d) = @_;
1.301 albertel 15735: my $i=0;
15736: my $samples = &get_samples($records,1);
1.144 matthew 15737: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 15738: &start_data_table().&start_data_table_header_row().
1.144 matthew 15739: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 15740: '<th>'.&mt('Column').'</th>'.
15741: &end_data_table_header_row()."\n");
1.356 albertel 15742: foreach my $array_ref (@$d) {
15743: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 15744: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 15745:
1.875 bisitz 15746: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 15747: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 15748: $r->print('<option value="none"></option>');
1.356 albertel 15749: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
15750: $r->print('<option value="'.$sample.'"'.
15751: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 15752: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 15753: }
1.594 raeburn 15754: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 15755: $i++;
15756: }
1.594 raeburn 15757: $r->print(&end_data_table());
1.31 albertel 15758: $i--;
15759: return $i;
15760: }
1.56 matthew 15761:
1.144 matthew 15762: ######################################################
15763: ######################################################
15764:
1.56 matthew 15765: =pod
1.31 albertel 15766:
1.648 raeburn 15767: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 15768:
15769: Prints a table of sample values from the upload and can make associate samples to internal names.
15770:
15771: $r is an Apache Request ref,
15772: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
15773: $d is an array of 2 element arrays (internal name, displayed name)
15774:
15775: =cut
15776:
1.144 matthew 15777: ######################################################
15778: ######################################################
1.31 albertel 15779: sub csv_samples_select_table {
15780: my ($r,$records,$d) = @_;
15781: my $i=0;
1.144 matthew 15782: #
1.662 bisitz 15783: my $max_samples = 5;
15784: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 15785: $r->print(&start_data_table().
15786: &start_data_table_header_row().'<th>'.
15787: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
15788: &end_data_table_header_row());
1.301 albertel 15789:
15790: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 15791: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 15792: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 15793: foreach my $option (@$d) {
15794: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 15795: $r->print('<option value="'.$value.'"'.
1.253 albertel 15796: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 15797: $display.'</option>');
1.31 albertel 15798: }
15799: $r->print('</select></td><td>');
1.662 bisitz 15800: foreach my $line (0..($max_samples-1)) {
1.301 albertel 15801: if (defined($samples->[$line]{$key})) {
15802: $r->print($samples->[$line]{$key}."<br />\n");
15803: }
15804: }
1.594 raeburn 15805: $r->print('</td>'.&end_data_table_row());
1.31 albertel 15806: $i++;
15807: }
1.594 raeburn 15808: $r->print(&end_data_table());
1.31 albertel 15809: $i--;
15810: return($i);
1.115 matthew 15811: }
15812:
1.144 matthew 15813: ######################################################
15814: ######################################################
15815:
1.115 matthew 15816: =pod
15817:
1.648 raeburn 15818: =item * &clean_excel_name($name)
1.115 matthew 15819:
15820: Returns a replacement for $name which does not contain any illegal characters.
15821:
15822: =cut
15823:
1.144 matthew 15824: ######################################################
15825: ######################################################
1.115 matthew 15826: sub clean_excel_name {
15827: my ($name) = @_;
15828: $name =~ s/[:\*\?\/\\]//g;
15829: if (length($name) > 31) {
15830: $name = substr($name,0,31);
15831: }
15832: return $name;
1.25 albertel 15833: }
1.84 albertel 15834:
1.85 albertel 15835: =pod
15836:
1.648 raeburn 15837: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 15838:
15839: Returns either 1 or undef
15840:
15841: 1 if the part is to be hidden, undef if it is to be shown
15842:
15843: Arguments are:
15844:
15845: $id the id of the part to be checked
15846: $symb, optional the symb of the resource to check
15847: $udom, optional the domain of the user to check for
15848: $uname, optional the username of the user to check for
15849:
15850: =cut
1.84 albertel 15851:
15852: sub check_if_partid_hidden {
15853: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 15854: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 15855: $symb,$udom,$uname);
1.141 albertel 15856: my $truth=1;
15857: #if the string starts with !, then the list is the list to show not hide
15858: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 15859: my @hiddenlist=split(/,/,$hiddenparts);
15860: foreach my $checkid (@hiddenlist) {
1.141 albertel 15861: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 15862: }
1.141 albertel 15863: return !$truth;
1.84 albertel 15864: }
1.127 matthew 15865:
1.138 matthew 15866:
15867: ############################################################
15868: ############################################################
15869:
15870: =pod
15871:
1.157 matthew 15872: =back
15873:
1.138 matthew 15874: =head1 cgi-bin script and graphing routines
15875:
1.157 matthew 15876: =over 4
15877:
1.648 raeburn 15878: =item * &get_cgi_id()
1.138 matthew 15879:
15880: Inputs: none
15881:
15882: Returns an id which can be used to pass environment variables
15883: to various cgi-bin scripts. These environment variables will
15884: be removed from the users environment after a given time by
15885: the routine &Apache::lonnet::transfer_profile_to_env.
15886:
15887: =cut
15888:
15889: ############################################################
15890: ############################################################
1.152 albertel 15891: my $uniq=0;
1.136 matthew 15892: sub get_cgi_id {
1.154 albertel 15893: $uniq=($uniq+1)%100000;
1.280 albertel 15894: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 15895: }
15896:
1.127 matthew 15897: ############################################################
15898: ############################################################
15899:
15900: =pod
15901:
1.648 raeburn 15902: =item * &DrawBarGraph()
1.127 matthew 15903:
1.138 matthew 15904: Facilitates the plotting of data in a (stacked) bar graph.
15905: Puts plot definition data into the users environment in order for
15906: graph.png to plot it. Returns an <img> tag for the plot.
15907: The bars on the plot are labeled '1','2',...,'n'.
15908:
15909: Inputs:
15910:
15911: =over 4
15912:
15913: =item $Title: string, the title of the plot
15914:
15915: =item $xlabel: string, text describing the X-axis of the plot
15916:
15917: =item $ylabel: string, text describing the Y-axis of the plot
15918:
15919: =item $Max: scalar, the maximum Y value to use in the plot
15920: If $Max is < any data point, the graph will not be rendered.
15921:
1.140 matthew 15922: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 15923: they are plotted. If undefined, default values will be used.
15924:
1.178 matthew 15925: =item $labels: array ref holding the labels to use on the x-axis for the bars.
15926:
1.138 matthew 15927: =item @Values: An array of array references. Each array reference holds data
15928: to be plotted in a stacked bar chart.
15929:
1.239 matthew 15930: =item If the final element of @Values is a hash reference the key/value
15931: pairs will be added to the graph definition.
15932:
1.138 matthew 15933: =back
15934:
15935: Returns:
15936:
15937: An <img> tag which references graph.png and the appropriate identifying
15938: information for the plot.
15939:
1.127 matthew 15940: =cut
15941:
15942: ############################################################
15943: ############################################################
1.134 matthew 15944: sub DrawBarGraph {
1.178 matthew 15945: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 15946: #
15947: if (! defined($colors)) {
15948: $colors = ['#33ff00',
15949: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
15950: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
15951: ];
15952: }
1.228 matthew 15953: my $extra_settings = {};
15954: if (ref($Values[-1]) eq 'HASH') {
15955: $extra_settings = pop(@Values);
15956: }
1.127 matthew 15957: #
1.136 matthew 15958: my $identifier = &get_cgi_id();
15959: my $id = 'cgi.'.$identifier;
1.129 matthew 15960: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 15961: return '';
15962: }
1.225 matthew 15963: #
15964: my @Labels;
15965: if (defined($labels)) {
15966: @Labels = @$labels;
15967: } else {
15968: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 15969: push(@Labels,$i+1);
1.225 matthew 15970: }
15971: }
15972: #
1.129 matthew 15973: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 15974: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 15975: my %ValuesHash;
15976: my $NumSets=1;
15977: foreach my $array (@Values) {
15978: next if (! ref($array));
1.136 matthew 15979: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 15980: join(',',@$array);
1.129 matthew 15981: }
1.127 matthew 15982: #
1.136 matthew 15983: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 15984: if ($NumBars < 3) {
15985: $width = 120+$NumBars*32;
1.220 matthew 15986: $xskip = 1;
1.225 matthew 15987: $bar_width = 30;
15988: } elsif ($NumBars < 5) {
15989: $width = 120+$NumBars*20;
15990: $xskip = 1;
15991: $bar_width = 20;
1.220 matthew 15992: } elsif ($NumBars < 10) {
1.136 matthew 15993: $width = 120+$NumBars*15;
15994: $xskip = 1;
15995: $bar_width = 15;
15996: } elsif ($NumBars <= 25) {
15997: $width = 120+$NumBars*11;
15998: $xskip = 5;
15999: $bar_width = 8;
16000: } elsif ($NumBars <= 50) {
16001: $width = 120+$NumBars*8;
16002: $xskip = 5;
16003: $bar_width = 4;
16004: } else {
16005: $width = 120+$NumBars*8;
16006: $xskip = 5;
16007: $bar_width = 4;
16008: }
16009: #
1.137 matthew 16010: $Max = 1 if ($Max < 1);
16011: if ( int($Max) < $Max ) {
16012: $Max++;
16013: $Max = int($Max);
16014: }
1.127 matthew 16015: $Title = '' if (! defined($Title));
16016: $xlabel = '' if (! defined($xlabel));
16017: $ylabel = '' if (! defined($ylabel));
1.369 www 16018: $ValuesHash{$id.'.title'} = &escape($Title);
16019: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
16020: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 16021: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 16022: $ValuesHash{$id.'.NumBars'} = $NumBars;
16023: $ValuesHash{$id.'.NumSets'} = $NumSets;
16024: $ValuesHash{$id.'.PlotType'} = 'bar';
16025: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
16026: $ValuesHash{$id.'.height'} = $height;
16027: $ValuesHash{$id.'.width'} = $width;
16028: $ValuesHash{$id.'.xskip'} = $xskip;
16029: $ValuesHash{$id.'.bar_width'} = $bar_width;
16030: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 16031: #
1.228 matthew 16032: # Deal with other parameters
16033: while (my ($key,$value) = each(%$extra_settings)) {
16034: $ValuesHash{$id.'.'.$key} = $value;
16035: }
16036: #
1.646 raeburn 16037: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 16038: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
16039: }
16040:
16041: ############################################################
16042: ############################################################
16043:
16044: =pod
16045:
1.648 raeburn 16046: =item * &DrawXYGraph()
1.137 matthew 16047:
1.138 matthew 16048: Facilitates the plotting of data in an XY graph.
16049: Puts plot definition data into the users environment in order for
16050: graph.png to plot it. Returns an <img> tag for the plot.
16051:
16052: Inputs:
16053:
16054: =over 4
16055:
16056: =item $Title: string, the title of the plot
16057:
16058: =item $xlabel: string, text describing the X-axis of the plot
16059:
16060: =item $ylabel: string, text describing the Y-axis of the plot
16061:
16062: =item $Max: scalar, the maximum Y value to use in the plot
16063: If $Max is < any data point, the graph will not be rendered.
16064:
16065: =item $colors: Array ref containing the hex color codes for the data to be
16066: plotted in. If undefined, default values will be used.
16067:
16068: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
16069:
16070: =item $Ydata: Array ref containing Array refs.
1.185 www 16071: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 16072:
16073: =item %Values: hash indicating or overriding any default values which are
16074: passed to graph.png.
16075: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
16076:
16077: =back
16078:
16079: Returns:
16080:
16081: An <img> tag which references graph.png and the appropriate identifying
16082: information for the plot.
16083:
1.137 matthew 16084: =cut
16085:
16086: ############################################################
16087: ############################################################
16088: sub DrawXYGraph {
16089: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
16090: #
16091: # Create the identifier for the graph
16092: my $identifier = &get_cgi_id();
16093: my $id = 'cgi.'.$identifier;
16094: #
16095: $Title = '' if (! defined($Title));
16096: $xlabel = '' if (! defined($xlabel));
16097: $ylabel = '' if (! defined($ylabel));
16098: my %ValuesHash =
16099: (
1.369 www 16100: $id.'.title' => &escape($Title),
16101: $id.'.xlabel' => &escape($xlabel),
16102: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 16103: $id.'.y_max_value'=> $Max,
16104: $id.'.labels' => join(',',@$Xlabels),
16105: $id.'.PlotType' => 'XY',
16106: );
16107: #
16108: if (defined($colors) && ref($colors) eq 'ARRAY') {
16109: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
16110: }
16111: #
16112: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
16113: return '';
16114: }
16115: my $NumSets=1;
1.138 matthew 16116: foreach my $array (@{$Ydata}){
1.137 matthew 16117: next if (! ref($array));
16118: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
16119: }
1.138 matthew 16120: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 16121: #
16122: # Deal with other parameters
16123: while (my ($key,$value) = each(%Values)) {
16124: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 16125: }
16126: #
1.646 raeburn 16127: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 16128: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
16129: }
16130:
16131: ############################################################
16132: ############################################################
16133:
16134: =pod
16135:
1.648 raeburn 16136: =item * &DrawXYYGraph()
1.138 matthew 16137:
16138: Facilitates the plotting of data in an XY graph with two Y axes.
16139: Puts plot definition data into the users environment in order for
16140: graph.png to plot it. Returns an <img> tag for the plot.
16141:
16142: Inputs:
16143:
16144: =over 4
16145:
16146: =item $Title: string, the title of the plot
16147:
16148: =item $xlabel: string, text describing the X-axis of the plot
16149:
16150: =item $ylabel: string, text describing the Y-axis of the plot
16151:
16152: =item $colors: Array ref containing the hex color codes for the data to be
16153: plotted in. If undefined, default values will be used.
16154:
16155: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
16156:
16157: =item $Ydata1: The first data set
16158:
16159: =item $Min1: The minimum value of the left Y-axis
16160:
16161: =item $Max1: The maximum value of the left Y-axis
16162:
16163: =item $Ydata2: The second data set
16164:
16165: =item $Min2: The minimum value of the right Y-axis
16166:
16167: =item $Max2: The maximum value of the left Y-axis
16168:
16169: =item %Values: hash indicating or overriding any default values which are
16170: passed to graph.png.
16171: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
16172:
16173: =back
16174:
16175: Returns:
16176:
16177: An <img> tag which references graph.png and the appropriate identifying
16178: information for the plot.
1.136 matthew 16179:
16180: =cut
16181:
16182: ############################################################
16183: ############################################################
1.137 matthew 16184: sub DrawXYYGraph {
16185: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
16186: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 16187: #
16188: # Create the identifier for the graph
16189: my $identifier = &get_cgi_id();
16190: my $id = 'cgi.'.$identifier;
16191: #
16192: $Title = '' if (! defined($Title));
16193: $xlabel = '' if (! defined($xlabel));
16194: $ylabel = '' if (! defined($ylabel));
16195: my %ValuesHash =
16196: (
1.369 www 16197: $id.'.title' => &escape($Title),
16198: $id.'.xlabel' => &escape($xlabel),
16199: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 16200: $id.'.labels' => join(',',@$Xlabels),
16201: $id.'.PlotType' => 'XY',
16202: $id.'.NumSets' => 2,
1.137 matthew 16203: $id.'.two_axes' => 1,
16204: $id.'.y1_max_value' => $Max1,
16205: $id.'.y1_min_value' => $Min1,
16206: $id.'.y2_max_value' => $Max2,
16207: $id.'.y2_min_value' => $Min2,
1.136 matthew 16208: );
16209: #
1.137 matthew 16210: if (defined($colors) && ref($colors) eq 'ARRAY') {
16211: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
16212: }
16213: #
16214: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
16215: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 16216: return '';
16217: }
16218: my $NumSets=1;
1.137 matthew 16219: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 16220: next if (! ref($array));
16221: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 16222: }
16223: #
16224: # Deal with other parameters
16225: while (my ($key,$value) = each(%Values)) {
16226: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 16227: }
16228: #
1.646 raeburn 16229: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 16230: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 16231: }
16232:
16233: ############################################################
16234: ############################################################
16235:
16236: =pod
16237:
1.157 matthew 16238: =back
16239:
1.139 matthew 16240: =head1 Statistics helper routines?
16241:
16242: Bad place for them but what the hell.
16243:
1.157 matthew 16244: =over 4
16245:
1.648 raeburn 16246: =item * &chartlink()
1.139 matthew 16247:
16248: Returns a link to the chart for a specific student.
16249:
16250: Inputs:
16251:
16252: =over 4
16253:
16254: =item $linktext: The text of the link
16255:
16256: =item $sname: The students username
16257:
16258: =item $sdomain: The students domain
16259:
16260: =back
16261:
1.157 matthew 16262: =back
16263:
1.139 matthew 16264: =cut
16265:
16266: ############################################################
16267: ############################################################
16268: sub chartlink {
16269: my ($linktext, $sname, $sdomain) = @_;
16270: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 16271: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 16272: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 16273: '">'.$linktext.'</a>';
1.153 matthew 16274: }
16275:
16276: #######################################################
16277: #######################################################
16278:
16279: =pod
16280:
16281: =head1 Course Environment Routines
1.157 matthew 16282:
16283: =over 4
1.153 matthew 16284:
1.648 raeburn 16285: =item * &restore_course_settings()
1.153 matthew 16286:
1.648 raeburn 16287: =item * &store_course_settings()
1.153 matthew 16288:
16289: Restores/Store indicated form parameters from the course environment.
16290: Will not overwrite existing values of the form parameters.
16291:
16292: Inputs:
16293: a scalar describing the data (e.g. 'chart', 'problem_analysis')
16294:
16295: a hash ref describing the data to be stored. For example:
16296:
16297: %Save_Parameters = ('Status' => 'scalar',
16298: 'chartoutputmode' => 'scalar',
16299: 'chartoutputdata' => 'scalar',
16300: 'Section' => 'array',
1.373 raeburn 16301: 'Group' => 'array',
1.153 matthew 16302: 'StudentData' => 'array',
16303: 'Maps' => 'array');
16304:
16305: Returns: both routines return nothing
16306:
1.631 raeburn 16307: =back
16308:
1.153 matthew 16309: =cut
16310:
16311: #######################################################
16312: #######################################################
16313: sub store_course_settings {
1.496 albertel 16314: return &store_settings($env{'request.course.id'},@_);
16315: }
16316:
16317: sub store_settings {
1.153 matthew 16318: # save to the environment
16319: # appenv the same items, just to be safe
1.300 albertel 16320: my $udom = $env{'user.domain'};
16321: my $uname = $env{'user.name'};
1.496 albertel 16322: my ($context,$prefix,$Settings) = @_;
1.153 matthew 16323: my %SaveHash;
16324: my %AppHash;
16325: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 16326: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 16327: my $envname = 'environment.'.$basename;
1.258 albertel 16328: if (exists($env{'form.'.$setting})) {
1.153 matthew 16329: # Save this value away
16330: if ($type eq 'scalar' &&
1.258 albertel 16331: (! exists($env{$envname}) ||
16332: $env{$envname} ne $env{'form.'.$setting})) {
16333: $SaveHash{$basename} = $env{'form.'.$setting};
16334: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 16335: } elsif ($type eq 'array') {
16336: my $stored_form;
1.258 albertel 16337: if (ref($env{'form.'.$setting})) {
1.153 matthew 16338: $stored_form = join(',',
16339: map {
1.369 www 16340: &escape($_);
1.258 albertel 16341: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 16342: } else {
16343: $stored_form =
1.369 www 16344: &escape($env{'form.'.$setting});
1.153 matthew 16345: }
16346: # Determine if the array contents are the same.
1.258 albertel 16347: if ($stored_form ne $env{$envname}) {
1.153 matthew 16348: $SaveHash{$basename} = $stored_form;
16349: $AppHash{$envname} = $stored_form;
16350: }
16351: }
16352: }
16353: }
16354: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 16355: $udom,$uname);
1.153 matthew 16356: if ($put_result !~ /^(ok|delayed)/) {
16357: &Apache::lonnet::logthis('unable to save form parameters, '.
16358: 'got error:'.$put_result);
16359: }
16360: # Make sure these settings stick around in this session, too
1.646 raeburn 16361: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 16362: return;
16363: }
16364:
16365: sub restore_course_settings {
1.499 albertel 16366: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 16367: }
16368:
16369: sub restore_settings {
16370: my ($context,$prefix,$Settings) = @_;
1.153 matthew 16371: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 16372: next if (exists($env{'form.'.$setting}));
1.496 albertel 16373: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 16374: '.'.$setting;
1.258 albertel 16375: if (exists($env{$envname})) {
1.153 matthew 16376: if ($type eq 'scalar') {
1.258 albertel 16377: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 16378: } elsif ($type eq 'array') {
1.258 albertel 16379: $env{'form.'.$setting} = [
1.153 matthew 16380: map {
1.369 www 16381: &unescape($_);
1.258 albertel 16382: } split(',',$env{$envname})
1.153 matthew 16383: ];
16384: }
16385: }
16386: }
1.127 matthew 16387: }
16388:
1.618 raeburn 16389: #######################################################
16390: #######################################################
16391:
16392: =pod
16393:
16394: =head1 Domain E-mail Routines
16395:
16396: =over 4
16397:
1.648 raeburn 16398: =item * &build_recipient_list()
1.618 raeburn 16399:
1.1144 raeburn 16400: Build recipient lists for following types of e-mail:
1.766 raeburn 16401: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 16402: (d) Help requests, (e) Course requests needing approval, (f) loncapa
16403: module change checking, student/employee ID conflict checks, as
16404: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
16405: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 16406:
16407: Inputs:
1.619 raeburn 16408: defmail (scalar - email address of default recipient),
1.1144 raeburn 16409: mailing type (scalar: errormail, packagesmail, helpdeskmail,
16410: requestsmail, updatesmail, or idconflictsmail).
16411:
1.619 raeburn 16412: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 16413:
1.619 raeburn 16414: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 16415: i.e., predates configuration by DC via domainprefs.pm
16416:
16417: $requname username of requester (if mailing type is helpdeskmail)
16418:
16419: $requdom domain of requester (if mailing type is helpdeskmail)
16420:
16421: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
16422:
1.618 raeburn 16423:
1.655 raeburn 16424: Returns: comma separated list of addresses to which to send e-mail.
16425:
16426: =back
1.618 raeburn 16427:
16428: =cut
16429:
16430: ############################################################
16431: ############################################################
16432: sub build_recipient_list {
1.1297 raeburn 16433: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 16434: my @recipients;
1.1270 raeburn 16435: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 16436: my %domconfig =
1.1270 raeburn 16437: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 16438: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 16439: if (exists($domconfig{'contacts'}{$mailing})) {
16440: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
16441: my @contacts = ('adminemail','supportemail');
16442: foreach my $item (@contacts) {
16443: if ($domconfig{'contacts'}{$mailing}{$item}) {
16444: my $addr = $domconfig{'contacts'}{$item};
16445: if (!grep(/^\Q$addr\E$/,@recipients)) {
16446: push(@recipients,$addr);
16447: }
1.619 raeburn 16448: }
1.1270 raeburn 16449: }
16450: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
16451: if ($mailing eq 'helpdeskmail') {
16452: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
16453: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
16454: my @ok_bccs;
16455: foreach my $bcc (@bccs) {
16456: $bcc =~ s/^\s+//g;
16457: $bcc =~ s/\s+$//g;
16458: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16459: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16460: push(@ok_bccs,$bcc);
16461: }
16462: }
16463: }
16464: if (@ok_bccs > 0) {
16465: $allbcc = join(', ',@ok_bccs);
16466: }
16467: }
16468: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 16469: }
16470: }
1.766 raeburn 16471: } elsif ($origmail ne '') {
1.1270 raeburn 16472: $lastresort = $origmail;
1.618 raeburn 16473: }
1.1297 raeburn 16474: if ($mailing eq 'helpdeskmail') {
16475: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
16476: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
16477: my ($inststatus,$inststatus_checked);
16478: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
16479: ($env{'user.domain'} ne 'public')) {
16480: $inststatus_checked = 1;
16481: $inststatus = $env{'environment.inststatus'};
16482: }
16483: unless ($inststatus_checked) {
16484: if (($requname ne '') && ($requdom ne '')) {
16485: if (($requname =~ /^$match_username$/) &&
16486: ($requdom =~ /^$match_domain$/) &&
16487: (&Apache::lonnet::domain($requdom))) {
16488: my $requhome = &Apache::lonnet::homeserver($requname,
16489: $requdom);
16490: unless ($requhome eq 'no_host') {
16491: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
16492: $inststatus = $userenv{'inststatus'};
16493: $inststatus_checked = 1;
16494: }
16495: }
16496: }
16497: }
16498: unless ($inststatus_checked) {
16499: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
16500: my %srch = (srchby => 'email',
16501: srchdomain => $defdom,
16502: srchterm => $reqemail,
16503: srchtype => 'exact');
16504: my %srch_results = &Apache::lonnet::usersearch(\%srch);
16505: foreach my $uname (keys(%srch_results)) {
16506: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
16507: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
16508: $inststatus_checked = 1;
16509: last;
16510: }
16511: }
16512: unless ($inststatus_checked) {
16513: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
16514: if ($dirsrchres eq 'ok') {
16515: foreach my $uname (keys(%srch_results)) {
16516: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
16517: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
16518: $inststatus_checked = 1;
16519: last;
16520: }
16521: }
16522: }
16523: }
16524: }
16525: }
16526: if ($inststatus ne '') {
16527: foreach my $status (split(/\:/,$inststatus)) {
16528: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
16529: my @contacts = ('adminemail','supportemail');
16530: foreach my $item (@contacts) {
16531: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
16532: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
16533: if (!grep(/^\Q$addr\E$/,@recipients)) {
16534: push(@recipients,$addr);
16535: }
16536: }
16537: }
16538: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
16539: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
16540: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
16541: my @ok_bccs;
16542: foreach my $bcc (@bccs) {
16543: $bcc =~ s/^\s+//g;
16544: $bcc =~ s/\s+$//g;
16545: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16546: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16547: push(@ok_bccs,$bcc);
16548: }
16549: }
16550: }
16551: if (@ok_bccs > 0) {
16552: $allbcc = join(', ',@ok_bccs);
16553: }
16554: }
16555: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
16556: last;
16557: }
16558: }
16559: }
16560: }
16561: }
1.619 raeburn 16562: } elsif ($origmail ne '') {
1.1270 raeburn 16563: $lastresort = $origmail;
16564: }
1.1297 raeburn 16565: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 16566: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
16567: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
16568: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
16569: my %what = (
16570: perlvar => 1,
16571: );
16572: my $primary = &Apache::lonnet::domain($defdom,'primary');
16573: if ($primary) {
16574: my $gotaddr;
16575: my ($result,$returnhash) =
16576: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
16577: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
16578: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
16579: $lastresort = $returnhash->{'lonSupportEMail'};
16580: $gotaddr = 1;
16581: }
16582: }
16583: unless ($gotaddr) {
16584: my $uintdom = &Apache::lonnet::internet_dom($primary);
16585: my $intdom = &Apache::lonnet::internet_dom($lonhost);
16586: unless ($uintdom eq $intdom) {
16587: my %domconfig =
16588: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
16589: if (ref($domconfig{'contacts'}) eq 'HASH') {
16590: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
16591: my @contacts = ('adminemail','supportemail');
16592: foreach my $item (@contacts) {
16593: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
16594: my $addr = $domconfig{'contacts'}{$item};
16595: if (!grep(/^\Q$addr\E$/,@recipients)) {
16596: push(@recipients,$addr);
16597: }
16598: }
16599: }
16600: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
16601: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
16602: }
16603: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
16604: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
16605: my @ok_bccs;
16606: foreach my $bcc (@bccs) {
16607: $bcc =~ s/^\s+//g;
16608: $bcc =~ s/\s+$//g;
16609: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16610: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16611: push(@ok_bccs,$bcc);
16612: }
16613: }
16614: }
16615: if (@ok_bccs > 0) {
16616: $allbcc = join(', ',@ok_bccs);
16617: }
16618: }
16619: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
16620: }
16621: }
16622: }
16623: }
16624: }
16625: }
1.618 raeburn 16626: }
1.688 raeburn 16627: if (defined($defmail)) {
16628: if ($defmail ne '') {
16629: push(@recipients,$defmail);
16630: }
1.618 raeburn 16631: }
16632: if ($otheremails) {
1.619 raeburn 16633: my @others;
16634: if ($otheremails =~ /,/) {
16635: @others = split(/,/,$otheremails);
1.618 raeburn 16636: } else {
1.619 raeburn 16637: push(@others,$otheremails);
16638: }
16639: foreach my $addr (@others) {
16640: if (!grep(/^\Q$addr\E$/,@recipients)) {
16641: push(@recipients,$addr);
16642: }
1.618 raeburn 16643: }
16644: }
1.1298 raeburn 16645: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 16646: if ((!@recipients) && ($lastresort ne '')) {
16647: push(@recipients,$lastresort);
16648: }
16649: } elsif ($lastresort ne '') {
16650: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
16651: push(@recipients,$lastresort);
16652: }
16653: }
1.1271 raeburn 16654: my $recipientlist = join(',',@recipients);
1.1270 raeburn 16655: if (wantarray) {
16656: return ($recipientlist,$allbcc,$addtext);
16657: } else {
16658: return $recipientlist;
16659: }
1.618 raeburn 16660: }
16661:
1.127 matthew 16662: ############################################################
16663: ############################################################
1.154 albertel 16664:
1.655 raeburn 16665: =pod
16666:
1.1224 musolffc 16667: =over 4
16668:
1.1223 musolffc 16669: =item * &mime_email()
16670:
16671: Sends an email with a possible attachment
16672:
16673: Inputs:
16674:
16675: =over 4
16676:
16677: from - Sender's email address
16678:
1.1343 raeburn 16679: replyto - Reply-To email address
16680:
1.1223 musolffc 16681: to - Email address of recipient
16682:
16683: subject - Subject of email
16684:
16685: body - Body of email
16686:
16687: cc_string - Carbon copy email address
16688:
16689: bcc - Blind carbon copy email address
16690:
16691: attachment_path - Path of file to be attached
16692:
16693: file_name - Name of file to be attached
16694:
16695: attachment_text - The body of an attachment of type "TEXT"
16696:
16697: =back
16698:
16699: =back
16700:
16701: =cut
16702:
16703: ############################################################
16704: ############################################################
16705:
16706: sub mime_email {
1.1343 raeburn 16707: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
16708: $file_name,$attachment_text) = @_;
16709:
1.1223 musolffc 16710: my $msg = MIME::Lite->new(
16711: From => $from,
16712: To => $to,
16713: Subject => $subject,
16714: Type =>'TEXT',
16715: Data => $body,
16716: );
1.1343 raeburn 16717: if ($replyto ne '') {
16718: $msg->add("Reply-To" => $replyto);
16719: }
1.1223 musolffc 16720: if ($cc_string ne '') {
16721: $msg->add("Cc" => $cc_string);
16722: }
16723: if ($bcc ne '') {
16724: $msg->add("Bcc" => $bcc);
16725: }
16726: $msg->attr("content-type" => "text/plain");
16727: $msg->attr("content-type.charset" => "UTF-8");
16728: # Attach file if given
16729: if ($attachment_path) {
16730: unless ($file_name) {
16731: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
16732: }
16733: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
16734: $msg->attach(Type => $type,
16735: Path => $attachment_path,
16736: Filename => $file_name
16737: );
16738: # Otherwise attach text if given
16739: } elsif ($attachment_text) {
16740: $msg->attach(Type => 'TEXT',
16741: Data => $attachment_text);
16742: }
16743: # Send it
16744: $msg->send('sendmail');
16745: }
16746:
16747: ############################################################
16748: ############################################################
16749:
16750: =pod
16751:
1.655 raeburn 16752: =head1 Course Catalog Routines
16753:
16754: =over 4
16755:
16756: =item * &gather_categories()
16757:
16758: Converts category definitions - keys of categories hash stored in
16759: coursecategories in configuration.db on the primary library server in a
16760: domain - to an array. Also generates javascript and idx hash used to
16761: generate Domain Coordinator interface for editing Course Categories.
16762:
16763: Inputs:
1.663 raeburn 16764:
1.655 raeburn 16765: categories (reference to hash of category definitions).
1.663 raeburn 16766:
1.655 raeburn 16767: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16768: categories and subcategories).
1.663 raeburn 16769:
1.655 raeburn 16770: idx (reference to hash of counters used in Domain Coordinator interface for
16771: editing Course Categories).
1.663 raeburn 16772:
1.655 raeburn 16773: jsarray (reference to array of categories used to create Javascript arrays for
16774: Domain Coordinator interface for editing Course Categories).
16775:
16776: Returns: nothing
16777:
16778: Side effects: populates cats, idx and jsarray.
16779:
16780: =cut
16781:
16782: sub gather_categories {
16783: my ($categories,$cats,$idx,$jsarray) = @_;
16784: my %counters;
16785: my $num = 0;
16786: foreach my $item (keys(%{$categories})) {
16787: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16788: if ($container eq '' && $depth == 0) {
16789: $cats->[$depth][$categories->{$item}] = $cat;
16790: } else {
16791: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
16792: }
16793: my ($escitem,$tail) = split(/:/,$item,2);
16794: if ($counters{$tail} eq '') {
16795: $counters{$tail} = $num;
16796: $num ++;
16797: }
16798: if (ref($idx) eq 'HASH') {
16799: $idx->{$item} = $counters{$tail};
16800: }
16801: if (ref($jsarray) eq 'ARRAY') {
16802: push(@{$jsarray->[$counters{$tail}]},$item);
16803: }
16804: }
16805: return;
16806: }
16807:
16808: =pod
16809:
16810: =item * &extract_categories()
16811:
16812: Used to generate breadcrumb trails for course categories.
16813:
16814: Inputs:
1.663 raeburn 16815:
1.655 raeburn 16816: categories (reference to hash of category definitions).
1.663 raeburn 16817:
1.655 raeburn 16818: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16819: categories and subcategories).
1.663 raeburn 16820:
1.655 raeburn 16821: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 16822:
1.655 raeburn 16823: allitems (reference to hash - key is category key
16824: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16825:
1.655 raeburn 16826: idx (reference to hash of counters used in Domain Coordinator interface for
16827: editing Course Categories).
1.663 raeburn 16828:
1.655 raeburn 16829: jsarray (reference to array of categories used to create Javascript arrays for
16830: Domain Coordinator interface for editing Course Categories).
16831:
1.665 raeburn 16832: subcats (reference to hash of arrays containing all subcategories within each
16833: category, -recursive)
16834:
1.1321 raeburn 16835: maxd (reference to hash used to hold max depth for all top-level categories).
16836:
1.655 raeburn 16837: Returns: nothing
16838:
16839: Side effects: populates trails and allitems hash references.
16840:
16841: =cut
16842:
16843: sub extract_categories {
1.1321 raeburn 16844: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 16845: if (ref($categories) eq 'HASH') {
16846: &gather_categories($categories,$cats,$idx,$jsarray);
16847: if (ref($cats->[0]) eq 'ARRAY') {
16848: for (my $i=0; $i<@{$cats->[0]}; $i++) {
16849: my $name = $cats->[0][$i];
16850: my $item = &escape($name).'::0';
16851: my $trailstr;
16852: if ($name eq 'instcode') {
16853: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 16854: } elsif ($name eq 'communities') {
16855: $trailstr = &mt('Communities');
1.1239 raeburn 16856: } elsif ($name eq 'placement') {
16857: $trailstr = &mt('Placement Tests');
1.655 raeburn 16858: } else {
16859: $trailstr = $name;
16860: }
16861: if ($allitems->{$item} eq '') {
16862: push(@{$trails},$trailstr);
16863: $allitems->{$item} = scalar(@{$trails})-1;
16864: }
16865: my @parents = ($name);
16866: if (ref($cats->[1]{$name}) eq 'ARRAY') {
16867: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
16868: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 16869: if (ref($subcats) eq 'HASH') {
16870: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
16871: }
1.1321 raeburn 16872: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 16873: }
16874: } else {
16875: if (ref($subcats) eq 'HASH') {
16876: $subcats->{$item} = [];
1.655 raeburn 16877: }
1.1321 raeburn 16878: if (ref($maxd) eq 'HASH') {
16879: $maxd->{$name} = 1;
16880: }
1.655 raeburn 16881: }
16882: }
16883: }
16884: }
16885: return;
16886: }
16887:
16888: =pod
16889:
1.1162 raeburn 16890: =item * &recurse_categories()
1.655 raeburn 16891:
16892: Recursively used to generate breadcrumb trails for course categories.
16893:
16894: Inputs:
1.663 raeburn 16895:
1.655 raeburn 16896: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16897: categories and subcategories).
1.663 raeburn 16898:
1.655 raeburn 16899: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 16900:
16901: category (current course category, for which breadcrumb trail is being generated).
16902:
16903: trails (reference to array of breadcrumb trails for each category).
16904:
1.655 raeburn 16905: allitems (reference to hash - key is category key
16906: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16907:
1.655 raeburn 16908: parents (array containing containers directories for current category,
16909: back to top level).
16910:
16911: Returns: nothing
16912:
16913: Side effects: populates trails and allitems hash references
16914:
16915: =cut
16916:
16917: sub recurse_categories {
1.1321 raeburn 16918: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 16919: my $shallower = $depth - 1;
16920: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
16921: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
16922: my $name = $cats->[$depth]{$category}[$k];
16923: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16924: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16925: if ($allitems->{$item} eq '') {
16926: push(@{$trails},$trailstr);
16927: $allitems->{$item} = scalar(@{$trails})-1;
16928: }
16929: my $deeper = $depth+1;
16930: push(@{$parents},$category);
1.665 raeburn 16931: if (ref($subcats) eq 'HASH') {
16932: my $subcat = &escape($name).':'.$category.':'.$depth;
16933: for (my $j=@{$parents}; $j>=0; $j--) {
16934: my $higher;
16935: if ($j > 0) {
16936: $higher = &escape($parents->[$j]).':'.
16937: &escape($parents->[$j-1]).':'.$j;
16938: } else {
16939: $higher = &escape($parents->[$j]).'::'.$j;
16940: }
16941: push(@{$subcats->{$higher}},$subcat);
16942: }
16943: }
16944: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 16945: $subcats,$maxd);
1.655 raeburn 16946: pop(@{$parents});
16947: }
16948: } else {
16949: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16950: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16951: if ($allitems->{$item} eq '') {
16952: push(@{$trails},$trailstr);
16953: $allitems->{$item} = scalar(@{$trails})-1;
16954: }
1.1321 raeburn 16955: if (ref($maxd) eq 'HASH') {
16956: if ($depth > $maxd->{$parents->[0]}) {
16957: $maxd->{$parents->[0]} = $depth;
16958: }
16959: }
1.655 raeburn 16960: }
16961: return;
16962: }
16963:
1.663 raeburn 16964: =pod
16965:
1.1162 raeburn 16966: =item * &assign_categories_table()
1.663 raeburn 16967:
16968: Create a datatable for display of hierarchical categories in a domain,
16969: with checkboxes to allow a course to be categorized.
16970:
16971: Inputs:
16972:
16973: cathash - reference to hash of categories defined for the domain (from
16974: configuration.db)
16975:
16976: currcat - scalar with an & separated list of categories assigned to a course.
16977:
1.919 raeburn 16978: type - scalar contains course type (Course or Community).
16979:
1.1260 raeburn 16980: disabled - scalar (optional) contains disabled="disabled" if input elements are
16981: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16982:
1.663 raeburn 16983: Returns: $output (markup to be displayed)
16984:
16985: =cut
16986:
16987: sub assign_categories_table {
1.1259 raeburn 16988: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 16989: my $output;
16990: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 16991: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
16992: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 16993: $maxdepth = scalar(@cats);
16994: if (@cats > 0) {
16995: my $itemcount = 0;
16996: if (ref($cats[0]) eq 'ARRAY') {
16997: my @currcategories;
16998: if ($currcat ne '') {
16999: @currcategories = split('&',$currcat);
17000: }
1.919 raeburn 17001: my $table;
1.663 raeburn 17002: for (my $i=0; $i<@{$cats[0]}; $i++) {
17003: my $parent = $cats[0][$i];
1.919 raeburn 17004: next if ($parent eq 'instcode');
17005: if ($type eq 'Community') {
17006: next unless ($parent eq 'communities');
1.1239 raeburn 17007: } elsif ($type eq 'Placement') {
17008: next unless ($parent eq 'placement');
1.919 raeburn 17009: } else {
1.1239 raeburn 17010: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 17011: }
1.663 raeburn 17012: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
17013: my $item = &escape($parent).'::0';
17014: my $checked = '';
17015: if (@currcategories > 0) {
17016: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 17017: $checked = ' checked="checked"';
1.663 raeburn 17018: }
17019: }
1.919 raeburn 17020: my $parent_title = $parent;
17021: if ($parent eq 'communities') {
17022: $parent_title = &mt('Communities');
1.1239 raeburn 17023: } elsif ($parent eq 'placement') {
17024: $parent_title = &mt('Placement Tests');
1.919 raeburn 17025: }
17026: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
17027: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 17028: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 17029: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 17030: my $depth = 1;
17031: push(@path,$parent);
1.1259 raeburn 17032: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 17033: pop(@path);
1.919 raeburn 17034: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 17035: $itemcount ++;
17036: }
1.919 raeburn 17037: if ($itemcount) {
17038: $output = &Apache::loncommon::start_data_table().
17039: $table.
17040: &Apache::loncommon::end_data_table();
17041: }
1.663 raeburn 17042: }
17043: }
17044: }
17045: return $output;
17046: }
17047:
17048: =pod
17049:
1.1162 raeburn 17050: =item * &assign_category_rows()
1.663 raeburn 17051:
17052: Create a datatable row for display of nested categories in a domain,
17053: with checkboxes to allow a course to be categorized,called recursively.
17054:
17055: Inputs:
17056:
17057: itemcount - track row number for alternating colors
17058:
17059: cats - reference to array of arrays/hashes which encapsulates hierarchy of
17060: categories and subcategories.
17061:
17062: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
17063:
17064: parent - parent of current category item
17065:
17066: path - Array containing all categories back up through the hierarchy from the
17067: current category to the top level.
17068:
17069: currcategories - reference to array of current categories assigned to the course
17070:
1.1260 raeburn 17071: disabled - scalar (optional) contains disabled="disabled" if input elements are
17072: to be readonly (e.g., Domain Helpdesk role viewing course settings).
17073:
1.663 raeburn 17074: Returns: $output (markup to be displayed).
17075:
17076: =cut
17077:
17078: sub assign_category_rows {
1.1259 raeburn 17079: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 17080: my ($text,$name,$item,$chgstr);
17081: if (ref($cats) eq 'ARRAY') {
17082: my $maxdepth = scalar(@{$cats});
17083: if (ref($cats->[$depth]) eq 'HASH') {
17084: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
17085: my $numchildren = @{$cats->[$depth]{$parent}};
17086: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 17087: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 17088: for (my $j=0; $j<$numchildren; $j++) {
17089: $name = $cats->[$depth]{$parent}[$j];
17090: $item = &escape($name).':'.&escape($parent).':'.$depth;
17091: my $deeper = $depth+1;
17092: my $checked = '';
17093: if (ref($currcategories) eq 'ARRAY') {
17094: if (@{$currcategories} > 0) {
17095: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 17096: $checked = ' checked="checked"';
1.663 raeburn 17097: }
17098: }
17099: }
1.664 raeburn 17100: $text .= '<tr><td><span class="LC_nobreak"><label>'.
17101: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 17102: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 17103: '<input type="hidden" name="catname" value="'.$name.'" />'.
17104: '</td><td>';
1.663 raeburn 17105: if (ref($path) eq 'ARRAY') {
17106: push(@{$path},$name);
1.1259 raeburn 17107: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 17108: pop(@{$path});
17109: }
17110: $text .= '</td></tr>';
17111: }
17112: $text .= '</table></td>';
17113: }
17114: }
17115: }
17116: return $text;
17117: }
17118:
1.1181 raeburn 17119: =pod
17120:
17121: =back
17122:
17123: =cut
17124:
1.655 raeburn 17125: ############################################################
17126: ############################################################
17127:
17128:
1.443 albertel 17129: sub commit_customrole {
1.1408 raeburn 17130: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context,$othdomby,$requester) = @_;
1.1399 raeburn 17131: my $result = &Apache::lonnet::assigncustomrole(
1.1408 raeburn 17132: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,
17133: $context,$othdomby,$requester);
1.630 raeburn 17134: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 17135: ($start?', '.&mt('starting').' '.localtime($start):'').
1.1399 raeburn 17136: ($end?', ending '.localtime($end):'').': <b>'.$result.'</b><br />';
17137: if (wantarray) {
17138: return ($output,$result);
17139: } else {
17140: return $output;
17141: }
1.443 albertel 17142: }
17143:
17144: sub commit_standardrole {
1.1408 raeburn 17145: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits,
17146: $othdomby,$requester) = @_;
1.1399 raeburn 17147: my ($output,$logmsg,$linefeed,$result);
1.541 raeburn 17148: if ($context eq 'auto') {
17149: $linefeed = "\n";
17150: } else {
17151: $linefeed = "<br />\n";
17152: }
1.443 albertel 17153: if ($three eq 'st') {
1.1399 raeburn 17154: $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1408 raeburn 17155: $one,$two,$sec,$context,$credits,$othdomby,
17156: $requester);
1.541 raeburn 17157: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 17158: ($result eq 'unknown_course') || ($result eq 'refused')) {
17159: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 17160: } else {
1.541 raeburn 17161: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 17162: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 17163: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
17164: if ($context eq 'auto') {
17165: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
17166: } else {
17167: $output .= '<b>'.$result.'</b>'.$linefeed.
17168: &mt('Add to classlist').': <b>ok</b>';
17169: }
17170: $output .= $linefeed;
1.443 albertel 17171: }
17172: } else {
17173: $output = &mt('Assigning').' '.$three.' in '.$url.
17174: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 17175: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.1408 raeburn 17176: $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,
17177: '','',$context,$othdomby,$requester);
1.541 raeburn 17178: if ($context eq 'auto') {
17179: $output .= $result.$linefeed;
17180: } else {
17181: $output .= '<b>'.$result.'</b>'.$linefeed;
17182: }
1.443 albertel 17183: }
1.1399 raeburn 17184: if (wantarray) {
17185: return ($output,$result);
17186: } else {
17187: return $output;
17188: }
1.443 albertel 17189: }
17190:
17191: sub commit_studentrole {
1.1116 raeburn 17192: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
1.1408 raeburn 17193: $credits,$othdomby,$requester) = @_;
1.626 raeburn 17194: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 17195: if ($context eq 'auto') {
17196: $linefeed = "\n";
17197: } else {
17198: $linefeed = '<br />'."\n";
17199: }
1.443 albertel 17200: if (defined($one) && defined($two)) {
17201: my $cid=$one.'_'.$two;
17202: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
17203: my $secchange = 0;
17204: my $expire_role_result;
17205: my $modify_section_result;
1.628 raeburn 17206: if ($oldsec ne '-1') {
17207: if ($oldsec ne $sec) {
1.443 albertel 17208: $secchange = 1;
1.628 raeburn 17209: my $now = time;
1.443 albertel 17210: my $uurl='/'.$cid;
17211: $uurl=~s/\_/\//g;
17212: if ($oldsec) {
17213: $uurl.='/'.$oldsec;
17214: }
1.626 raeburn 17215: $oldsecurl = $uurl;
1.628 raeburn 17216: $expire_role_result =
1.1408 raeburn 17217: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,
17218: '','','',$context,$othdomby,$requester);
17219: if ($env{'request.course.sec'} ne '') {
1.628 raeburn 17220: if ($expire_role_result eq 'refused') {
17221: my @roles = ('st');
17222: my @statuses = ('previous');
17223: my @roledoms = ($one);
17224: my $withsec = 1;
17225: my %roleshash =
17226: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
17227: \@statuses,\@roles,\@roledoms,$withsec);
17228: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
17229: my ($oldstart,$oldend) =
17230: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
17231: if ($oldend > 0 && $oldend <= $now) {
17232: $expire_role_result = 'ok';
17233: }
17234: }
17235: }
17236: }
1.443 albertel 17237: $result = $expire_role_result;
17238: }
17239: }
17240: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 17241: $modify_section_result =
17242: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
17243: undef,undef,undef,$sec,
17244: $end,$start,'','',$cid,
1.1408 raeburn 17245: '',$context,$credits,'',
17246: $othdomby,$requester);
1.443 albertel 17247: if ($modify_section_result =~ /^ok/) {
17248: if ($secchange == 1) {
1.628 raeburn 17249: if ($sec eq '') {
17250: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
17251: } else {
17252: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
17253: }
1.443 albertel 17254: } elsif ($oldsec eq '-1') {
1.628 raeburn 17255: if ($sec eq '') {
17256: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
17257: } else {
17258: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
17259: }
1.443 albertel 17260: } else {
1.628 raeburn 17261: if ($sec eq '') {
17262: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
17263: } else {
17264: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
17265: }
1.443 albertel 17266: }
17267: } else {
1.1115 raeburn 17268: if ($secchange) {
1.628 raeburn 17269: $$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;
17270: } else {
17271: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
17272: }
1.443 albertel 17273: }
17274: $result = $modify_section_result;
17275: } elsif ($secchange == 1) {
1.628 raeburn 17276: if ($oldsec eq '') {
1.1103 raeburn 17277: $$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 17278: } else {
17279: $$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;
17280: }
1.626 raeburn 17281: if ($expire_role_result eq 'refused') {
17282: my $newsecurl = '/'.$cid;
17283: $newsecurl =~ s/\_/\//g;
17284: if ($sec ne '') {
17285: $newsecurl.='/'.$sec;
17286: }
17287: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
17288: if ($sec eq '') {
17289: $$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;
17290: } else {
17291: $$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;
17292: }
17293: }
17294: }
1.443 albertel 17295: }
17296: } else {
1.626 raeburn 17297: $$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 17298: $result = "error: incomplete course id\n";
17299: }
17300: return $result;
17301: }
17302:
1.1108 raeburn 17303: sub show_role_extent {
17304: my ($scope,$context,$role) = @_;
17305: $scope =~ s{^/}{};
17306: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
17307: push(@courseroles,'co');
17308: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
17309: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
17310: $scope =~ s{/}{_};
17311: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
17312: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
17313: my ($audom,$auname) = split(/\//,$scope);
17314: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
17315: &Apache::loncommon::plainname($auname,$audom).'</span>');
17316: } else {
17317: $scope =~ s{/$}{};
17318: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
17319: &Apache::lonnet::domain($scope,'description').'</span>');
17320: }
17321: }
17322:
1.443 albertel 17323: ############################################################
17324: ############################################################
17325:
1.566 albertel 17326: sub check_clone {
1.578 raeburn 17327: my ($args,$linefeed) = @_;
1.566 albertel 17328: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
17329: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
17330: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 17331: my $clonetitle;
17332: my @clonemsg;
1.566 albertel 17333: my $can_clone = 0;
1.944 raeburn 17334: my $lctype = lc($args->{'crstype'});
1.908 raeburn 17335: if ($lctype ne 'community') {
17336: $lctype = 'course';
17337: }
1.566 albertel 17338: if ($clonehome eq 'no_host') {
1.944 raeburn 17339: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 17340: push(@clonemsg,({
17341: mt => 'No new community created.',
17342: args => [],
17343: },
17344: {
17345: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
17346: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
17347: }));
1.908 raeburn 17348: } else {
1.1344 raeburn 17349: push(@clonemsg,({
17350: mt => 'No new course created.',
17351: args => [],
17352: },
17353: {
17354: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
17355: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
17356: }));
17357: }
1.566 albertel 17358: } else {
17359: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 17360: $clonetitle = $clonedesc{'description'};
1.944 raeburn 17361: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 17362: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 17363: push(@clonemsg,({
17364: mt => 'No new community created.',
17365: args => [],
17366: },
17367: {
17368: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
17369: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
17370: }));
17371: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 17372: }
17373: }
1.1262 raeburn 17374: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 17375: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 17376: $can_clone = 1;
17377: } else {
1.1221 raeburn 17378: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 17379: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 17380: if ($clonehash{'cloners'} eq '') {
17381: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
17382: if ($domdefs{'canclone'}) {
17383: unless ($domdefs{'canclone'} eq 'none') {
17384: if ($domdefs{'canclone'} eq 'domain') {
17385: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
17386: $can_clone = 1;
17387: }
17388: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
17389: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
17390: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
17391: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
17392: $can_clone = 1;
17393: }
17394: }
17395: }
17396: }
1.578 raeburn 17397: } else {
1.1221 raeburn 17398: my @cloners = split(/,/,$clonehash{'cloners'});
17399: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 17400: $can_clone = 1;
1.1221 raeburn 17401: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 17402: $can_clone = 1;
1.1225 raeburn 17403: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
17404: $can_clone = 1;
1.1221 raeburn 17405: }
17406: unless ($can_clone) {
1.1225 raeburn 17407: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
17408: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 17409: my (%gotdomdefaults,%gotcodedefaults);
17410: foreach my $cloner (@cloners) {
17411: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
17412: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
17413: my (%codedefaults,@code_order);
17414: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
17415: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
17416: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
17417: }
17418: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
17419: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
17420: }
17421: } else {
17422: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
17423: \%codedefaults,
17424: \@code_order);
17425: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
17426: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
17427: }
17428: if (@code_order > 0) {
17429: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
17430: $cloner,$clonehash{'internal.coursecode'},
17431: $args->{'crscode'})) {
17432: $can_clone = 1;
17433: last;
17434: }
17435: }
17436: }
17437: }
17438: }
1.1225 raeburn 17439: }
17440: }
17441: unless ($can_clone) {
17442: my $ccrole = 'cc';
17443: if ($args->{'crstype'} eq 'Community') {
17444: $ccrole = 'co';
17445: }
17446: my %roleshash =
17447: &Apache::lonnet::get_my_roles($args->{'ccuname'},
17448: $args->{'ccdomain'},
17449: 'userroles',['active'],[$ccrole],
17450: [$args->{'clonedomain'}]);
17451: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
17452: $can_clone = 1;
17453: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
17454: $args->{'ccuname'},$args->{'ccdomain'})) {
17455: $can_clone = 1;
1.1221 raeburn 17456: }
17457: }
17458: unless ($can_clone) {
17459: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 17460: push(@clonemsg,({
17461: mt => 'No new community created.',
17462: args => [],
17463: },
17464: {
17465: 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]).',
17466: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
17467: }));
1.942 raeburn 17468: } else {
1.1344 raeburn 17469: push(@clonemsg,({
17470: mt => 'No new course created.',
17471: args => [],
17472: },
17473: {
17474: 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]).',
17475: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
17476: }));
1.1221 raeburn 17477: }
1.566 albertel 17478: }
1.578 raeburn 17479: }
1.566 albertel 17480: }
1.1344 raeburn 17481: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 17482: }
17483:
1.444 albertel 17484: sub construct_course {
1.1262 raeburn 17485: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 17486: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
17487: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 17488: my $linefeed = '<br />'."\n";
17489: if ($context eq 'auto') {
17490: $linefeed = "\n";
17491: }
1.566 albertel 17492:
17493: #
17494: # Are we cloning?
17495: #
1.1344 raeburn 17496: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 17497: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 17498: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 17499: if (!$can_clone) {
1.1344 raeburn 17500: return (0,$outcome,$clonemsgref);
1.566 albertel 17501: }
17502: }
17503:
1.444 albertel 17504: #
17505: # Open course
17506: #
1.1239 raeburn 17507: my $showncrstype;
17508: if ($args->{'crstype'} eq 'Placement') {
17509: $showncrstype = 'placement test';
17510: } else {
17511: $showncrstype = lc($args->{'crstype'});
17512: }
1.444 albertel 17513: my %cenv=();
17514: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
17515: $args->{'cdescr'},
17516: $args->{'curl'},
17517: $args->{'course_home'},
17518: $args->{'nonstandard'},
17519: $args->{'crscode'},
17520: $args->{'ccuname'}.':'.
17521: $args->{'ccdomain'},
1.882 raeburn 17522: $args->{'crstype'},
1.1344 raeburn 17523: $cnum,$context,$category,
17524: $callercontext);
1.444 albertel 17525:
17526: # Note: The testing routines depend on this being output; see
17527: # Utils::Course. This needs to at least be output as a comment
17528: # if anyone ever decides to not show this, and Utils::Course::new
17529: # will need to be suitably modified.
1.1344 raeburn 17530: if (($callercontext eq 'auto') && ($user_lh ne '')) {
17531: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
17532: } else {
17533: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
17534: }
1.943 raeburn 17535: if ($$courseid =~ /^error:/) {
1.1344 raeburn 17536: return (0,$outcome,$clonemsgref);
1.943 raeburn 17537: }
17538:
1.444 albertel 17539: #
17540: # Check if created correctly
17541: #
1.479 albertel 17542: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 17543: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 17544: if ($crsuhome eq 'no_host') {
1.1344 raeburn 17545: if (($callercontext eq 'auto') && ($user_lh ne '')) {
17546: $outcome .= &mt_user($user_lh,
17547: 'Course creation failed, unrecognized course home server.');
17548: } else {
17549: $outcome .= &mt('Course creation failed, unrecognized course home server.');
17550: }
17551: $outcome .= $linefeed;
17552: return (0,$outcome,$clonemsgref);
1.943 raeburn 17553: }
1.541 raeburn 17554: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 17555:
1.444 albertel 17556: #
1.566 albertel 17557: # Do the cloning
17558: #
1.1344 raeburn 17559: my @clonemsg;
1.566 albertel 17560: if ($can_clone && $cloneid) {
1.1344 raeburn 17561: push(@clonemsg,
17562: {
17563: mt => 'Created [_1] by cloning from [_2]',
17564: args => [$showncrstype,$clonetitle],
17565: });
1.566 albertel 17566: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 17567: # Copy all files
1.1344 raeburn 17568: my @info =
17569: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
17570: $args->{'dateshift'},$args->{'crscode'},
17571: $args->{'ccuname'}.':'.$args->{'ccdomain'},
17572: $args->{'tinyurls'});
17573: if (@info) {
17574: push(@clonemsg,@info);
17575: }
1.444 albertel 17576: # Restore URL
1.566 albertel 17577: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 17578: # Restore title
1.566 albertel 17579: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 17580: # Restore creation date, creator and creation context.
17581: $cenv{'internal.created'}=$oldcenv{'internal.created'};
17582: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
17583: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 17584: # Mark as cloned
1.566 albertel 17585: $cenv{'clonedfrom'}=$cloneid;
1.638 www 17586: # Need to clone grading mode
17587: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
17588: $cenv{'grading'}=$newenv{'grading'};
17589: # Do not clone these environment entries
17590: &Apache::lonnet::del('environment',
17591: ['default_enrollment_start_date',
17592: 'default_enrollment_end_date',
17593: 'question.email',
17594: 'policy.email',
17595: 'comment.email',
17596: 'pch.users.denied',
1.725 raeburn 17597: 'plc.users.denied',
17598: 'hidefromcat',
1.1121 raeburn 17599: 'checkforpriv',
1.1355 raeburn 17600: 'categories'],
1.638 www 17601: $$crsudom,$$crsunum);
1.1170 raeburn 17602: if ($args->{'textbook'}) {
17603: $cenv{'internal.textbook'} = $args->{'textbook'};
17604: }
1.444 albertel 17605: }
1.566 albertel 17606:
1.444 albertel 17607: #
17608: # Set environment (will override cloned, if existing)
17609: #
17610: my @sections = ();
17611: my @xlists = ();
17612: if ($args->{'crstype'}) {
17613: $cenv{'type'}=$args->{'crstype'};
17614: }
1.1371 raeburn 17615: if ($args->{'lti'}) {
17616: $cenv{'internal.lti'}=$args->{'lti'};
17617: }
1.444 albertel 17618: if ($args->{'crsid'}) {
17619: $cenv{'courseid'}=$args->{'crsid'};
17620: }
17621: if ($args->{'crscode'}) {
17622: $cenv{'internal.coursecode'}=$args->{'crscode'};
17623: }
17624: if ($args->{'crsquota'} ne '') {
17625: $cenv{'internal.coursequota'}=$args->{'crsquota'};
17626: } else {
17627: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
17628: }
17629: if ($args->{'ccuname'}) {
17630: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
17631: ':'.$args->{'ccdomain'};
17632: } else {
17633: $cenv{'internal.courseowner'} = $args->{'curruser'};
17634: }
1.1116 raeburn 17635: if ($args->{'defaultcredits'}) {
17636: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
17637: }
1.444 albertel 17638: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.1412 raeburn 17639: my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.
1.444 albertel 17640: if ($args->{'crssections'}) {
17641: $cenv{'internal.sectionnums'} = '';
17642: if ($args->{'crssections'} =~ m/,/) {
17643: @sections = split/,/,$args->{'crssections'};
17644: } else {
17645: $sections[0] = $args->{'crssections'};
17646: }
17647: if (@sections > 0) {
17648: foreach my $item (@sections) {
17649: my ($sec,$gp) = split/:/,$item;
17650: my $class = $args->{'crscode'}.$sec;
17651: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
17652: $cenv{'internal.sectionnums'} .= $item.',';
1.1412 raeburn 17653: if ($addcheck eq 'ok') {
17654: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
17655: push(@oklcsecs,$gp);
17656: }
17657: } else {
1.1263 raeburn 17658: push(@badclasses,$class);
1.444 albertel 17659: }
17660: }
17661: $cenv{'internal.sectionnums'} =~ s/,$//;
17662: }
17663: }
17664: # do not hide course coordinator from staff listing,
17665: # even if privileged
17666: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 17667: # add course coordinator's domain to domains to check for privileged users
17668: # if different to course domain
17669: if ($$crsudom ne $args->{'ccdomain'}) {
17670: $cenv{'checkforpriv'} = $args->{'ccdomain'};
17671: }
1.444 albertel 17672: # add crosslistings
17673: if ($args->{'crsxlist'}) {
17674: $cenv{'internal.crosslistings'}='';
17675: if ($args->{'crsxlist'} =~ m/,/) {
17676: @xlists = split/,/,$args->{'crsxlist'};
17677: } else {
17678: $xlists[0] = $args->{'crsxlist'};
17679: }
17680: if (@xlists > 0) {
17681: foreach my $item (@xlists) {
17682: my ($xl,$gp) = split/:/,$item;
17683: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
17684: $cenv{'internal.crosslistings'} .= $item.',';
1.1412 raeburn 17685: if ($addcheck eq 'ok') {
17686: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
17687: push(@oklcsecs,$gp);
17688: }
17689: } else {
1.1263 raeburn 17690: push(@badclasses,$xl);
1.444 albertel 17691: }
17692: }
17693: $cenv{'internal.crosslistings'} =~ s/,$//;
17694: }
17695: }
17696: if ($args->{'autoadds'}) {
17697: $cenv{'internal.autoadds'}=$args->{'autoadds'};
17698: }
17699: if ($args->{'autodrops'}) {
17700: $cenv{'internal.autodrops'}=$args->{'autodrops'};
17701: }
17702: # check for notification of enrollment changes
17703: my @notified = ();
17704: if ($args->{'notify_owner'}) {
17705: if ($args->{'ccuname'} ne '') {
17706: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
17707: }
17708: }
17709: if ($args->{'notify_dc'}) {
17710: if ($uname ne '') {
1.630 raeburn 17711: push(@notified,$uname.':'.$udom);
1.444 albertel 17712: }
17713: }
17714: if (@notified > 0) {
17715: my $notifylist;
17716: if (@notified > 1) {
17717: $notifylist = join(',',@notified);
17718: } else {
17719: $notifylist = $notified[0];
17720: }
17721: $cenv{'internal.notifylist'} = $notifylist;
17722: }
17723: if (@badclasses > 0) {
17724: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 17725: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
17726: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
17727: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 17728: );
1.1264 raeburn 17729: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
17730: &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 17731: if ($context eq 'auto') {
17732: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 17733: } else {
1.566 albertel 17734: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 17735: }
17736: foreach my $item (@badclasses) {
1.541 raeburn 17737: if ($context eq 'auto') {
1.1261 raeburn 17738: $outcome .= " - $item\n";
1.541 raeburn 17739: } else {
1.1261 raeburn 17740: $outcome .= "<li>$item</li>\n";
1.541 raeburn 17741: }
1.1261 raeburn 17742: }
17743: if ($context eq 'auto') {
17744: $outcome .= $linefeed;
17745: } else {
17746: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 17747: }
1.444 albertel 17748: }
17749: if ($args->{'no_end_date'}) {
17750: $args->{'endaccess'} = 0;
17751: }
1.1412 raeburn 17752: # If an official course with institutional sections is created by cloning
17753: # an existing course, section-specific hiding of course totals in student's
17754: # view of grades as copied from cloned course, will be checked for valid
17755: # sections.
17756: if (($can_clone && $cloneid) &&
17757: ($cenv{'internal.coursecode'} ne '') &&
17758: ($cenv{'grading'} eq 'standard') &&
17759: ($cenv{'hidetotals'} ne '') &&
17760: ($cenv{'hidetotals'} ne 'all')) {
17761: my @hidesecs;
17762: my $deletehidetotals;
17763: if (@oklcsecs) {
17764: foreach my $sec (split(/,/,$cenv{'hidetotals'})) {
17765: if (grep(/^\Q$sec$/,@oklcsecs)) {
17766: push(@hidesecs,$sec);
17767: }
17768: }
17769: if (@hidesecs) {
17770: $cenv{'hidetotals'} = join(',',@hidesecs);
17771: } else {
17772: $deletehidetotals = 1;
17773: }
17774: } else {
17775: $deletehidetotals = 1;
17776: }
17777: if ($deletehidetotals) {
17778: delete($cenv{'hidetotals'});
17779: &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);
17780: }
17781: }
1.444 albertel 17782: $cenv{'internal.autostart'}=$args->{'enrollstart'};
17783: $cenv{'internal.autoend'}=$args->{'enrollend'};
17784: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
17785: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
17786: if ($args->{'showphotos'}) {
17787: $cenv{'internal.showphotos'}=$args->{'showphotos'};
17788: }
17789: $cenv{'internal.authtype'} = $args->{'authtype'};
17790: $cenv{'internal.autharg'} = $args->{'autharg'};
17791: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
17792: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 17793: 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');
17794: if ($context eq 'auto') {
17795: $outcome .= $krb_msg;
17796: } else {
1.566 albertel 17797: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 17798: }
17799: $outcome .= $linefeed;
1.444 albertel 17800: }
17801: }
17802: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
17803: if ($args->{'setpolicy'}) {
17804: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17805: }
17806: if ($args->{'setcontent'}) {
17807: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17808: }
1.1251 raeburn 17809: if ($args->{'setcomment'}) {
17810: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17811: }
1.444 albertel 17812: }
17813: if ($args->{'reshome'}) {
17814: $cenv{'reshome'}=$args->{'reshome'}.'/';
17815: $cenv{'reshome'}=~s/\/+$/\//;
17816: }
17817: #
17818: # course has keyed access
17819: #
17820: if ($args->{'setkeys'}) {
17821: $cenv{'keyaccess'}='yes';
17822: }
17823: # if specified, key authority is not course, but user
17824: # only active if keyaccess is yes
17825: if ($args->{'keyauth'}) {
1.487 albertel 17826: my ($user,$domain) = split(':',$args->{'keyauth'});
17827: $user = &LONCAPA::clean_username($user);
17828: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 17829: if ($user ne '' && $domain ne '') {
1.487 albertel 17830: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 17831: }
17832: }
17833:
1.1166 raeburn 17834: #
1.1167 raeburn 17835: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 17836: #
17837: if ($args->{'uniquecode'}) {
17838: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
17839: if ($code) {
17840: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 17841: my %crsinfo =
17842: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
17843: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
17844: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
17845: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
17846: }
1.1166 raeburn 17847: if (ref($coderef)) {
17848: $$coderef = $code;
17849: }
17850: }
17851: }
17852:
1.444 albertel 17853: if ($args->{'disresdis'}) {
17854: $cenv{'pch.roles.denied'}='st';
17855: }
17856: if ($args->{'disablechat'}) {
17857: $cenv{'plc.roles.denied'}='st';
17858: }
17859:
17860: # Record we've not yet viewed the Course Initialization Helper for this
17861: # course
17862: $cenv{'course.helper.not.run'} = 1;
17863: #
17864: # Use new Randomseed
17865: #
17866: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
17867: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
17868: #
17869: # The encryption code and receipt prefix for this course
17870: #
17871: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
17872: $cenv{'internal.encpref'}=100+int(9*rand(99));
17873: #
17874: # By default, use standard grading
17875: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
17876:
1.541 raeburn 17877: $outcome .= $linefeed.&mt('Setting environment').': '.
17878: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17879: #
17880: # Open all assignments
17881: #
17882: if ($args->{'openall'}) {
1.1341 raeburn 17883: my $opendate = time;
17884: if ($args->{'openallfrom'} =~ /^\d+$/) {
17885: $opendate = $args->{'openallfrom'};
17886: }
1.444 albertel 17887: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 17888: my %storecontent = ($storeunder => $opendate,
1.444 albertel 17889: $storeunder.'.type' => 'date_start');
1.1341 raeburn 17890: $outcome .= &mt('All assignments open starting [_1]',
17891: &Apache::lonlocal::locallocaltime($opendate)).': '.
17892: &Apache::lonnet::cput
17893: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17894: }
17895: #
17896: # Set first page
17897: #
17898: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
17899: || ($cloneid)) {
17900: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 17901:
17902: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
17903: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
17904:
1.444 albertel 17905: $outcome .= ($fatal?$errtext:'read ok').' - ';
17906: my $title; my $url;
17907: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 17908: $title=&mt('Syllabus');
1.444 albertel 17909: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
17910: } else {
1.963 raeburn 17911: $title=&mt('Table of Contents');
1.444 albertel 17912: $url='/adm/navmaps';
17913: }
1.445 albertel 17914:
17915: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
17916: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
17917:
17918: if ($errtext) { $fatal=2; }
1.541 raeburn 17919: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 17920: }
1.566 albertel 17921:
1.1237 raeburn 17922: #
17923: # Set params for Placement Tests
17924: #
1.1239 raeburn 17925: if ($args->{'crstype'} eq 'Placement') {
17926: my %storecontent;
17927: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
17928: my %defaults = (
17929: buttonshide => { value => 'yes',
17930: type => 'string_yesno',},
17931: type => { value => 'randomizetry',
17932: type => 'string_questiontype',},
17933: maxtries => { value => 1,
17934: type => 'int_pos',},
17935: problemstatus => { value => 'no',
17936: type => 'string_problemstatus',},
17937: );
17938: foreach my $key (keys(%defaults)) {
17939: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
17940: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
17941: }
1.1237 raeburn 17942: &Apache::lonnet::cput
17943: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
17944: }
17945:
1.1344 raeburn 17946: return (1,$outcome,\@clonemsg);
1.444 albertel 17947: }
17948:
1.1166 raeburn 17949: sub make_unique_code {
17950: my ($cdom,$cnum) = @_;
17951: # get lock on uniquecodes db
17952: my $lockhash = {
17953: $cnum."\0".'uniquecodes' => $env{'user.name'}.
17954: ':'.$env{'user.domain'},
17955: };
17956: my $tries = 0;
17957: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17958: my ($code,$error);
17959:
17960: while (($gotlock ne 'ok') && ($tries<3)) {
17961: $tries ++;
17962: sleep 1;
17963: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17964: }
17965: if ($gotlock eq 'ok') {
17966: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
17967: my $gotcode;
17968: my $attempts = 0;
17969: while ((!$gotcode) && ($attempts < 100)) {
17970: $code = &generate_code();
17971: if (!exists($currcodes{$code})) {
17972: $gotcode = 1;
17973: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
17974: $error = 'nostore';
17975: }
17976: }
17977: $attempts ++;
17978: }
17979: my @del_lock = ($cnum."\0".'uniquecodes');
17980: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
17981: } else {
17982: $error = 'nolock';
17983: }
17984: return ($code,$error);
17985: }
17986:
17987: sub generate_code {
17988: my $code;
17989: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
17990: for (my $i=0; $i<6; $i++) {
17991: my $lettnum = int (rand 2);
17992: my $item = '';
17993: if ($lettnum) {
17994: $item = $letts[int( rand(18) )];
17995: } else {
17996: $item = 1+int( rand(8) );
17997: }
17998: $code .= $item;
17999: }
18000: return $code;
18001: }
18002:
1.444 albertel 18003: ############################################################
18004: ############################################################
18005:
1.1237 raeburn 18006: # Community, Course and Placement Test
1.378 raeburn 18007: sub course_type {
18008: my ($cid) = @_;
18009: if (!defined($cid)) {
18010: $cid = $env{'request.course.id'};
18011: }
1.404 albertel 18012: if (defined($env{'course.'.$cid.'.type'})) {
18013: return $env{'course.'.$cid.'.type'};
1.378 raeburn 18014: } else {
18015: return 'Course';
1.377 raeburn 18016: }
18017: }
1.156 albertel 18018:
1.406 raeburn 18019: sub group_term {
18020: my $crstype = &course_type();
18021: my %names = (
18022: 'Course' => 'group',
1.865 raeburn 18023: 'Community' => 'group',
1.1237 raeburn 18024: 'Placement' => 'group',
1.406 raeburn 18025: );
18026: return $names{$crstype};
18027: }
18028:
1.902 raeburn 18029: sub course_types {
1.1310 raeburn 18030: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 18031: my %typename = (
18032: official => 'Official course',
18033: unofficial => 'Unofficial course',
18034: community => 'Community',
1.1165 raeburn 18035: textbook => 'Textbook course',
1.1237 raeburn 18036: placement => 'Placement test',
1.1310 raeburn 18037: lti => 'LTI provider',
1.902 raeburn 18038: );
18039: return (\@types,\%typename);
18040: }
18041:
1.156 albertel 18042: sub icon {
18043: my ($file)=@_;
1.505 albertel 18044: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 18045: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 18046: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 18047: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
18048: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
18049: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
18050: $curfext.".gif") {
18051: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
18052: $curfext.".gif";
18053: }
18054: }
1.249 albertel 18055: return &lonhttpdurl($iconname);
1.154 albertel 18056: }
1.84 albertel 18057:
1.575 albertel 18058: sub lonhttpdurl {
1.692 www 18059: #
18060: # Had been used for "small fry" static images on separate port 8080.
18061: # Modify here if lightweight http functionality desired again.
18062: # Currently eliminated due to increasing firewall issues.
18063: #
1.575 albertel 18064: my ($url)=@_;
1.692 www 18065: return $url;
1.215 albertel 18066: }
18067:
1.213 albertel 18068: sub connection_aborted {
18069: my ($r)=@_;
18070: $r->print(" ");$r->rflush();
18071: my $c = $r->connection;
18072: return $c->aborted();
18073: }
18074:
1.221 foxr 18075: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 18076: # strings as 'strings'.
18077: sub escape_single {
1.221 foxr 18078: my ($input) = @_;
1.223 albertel 18079: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 18080: $input =~ s/\'/\\\'/g; # Esacpe the 's....
18081: return $input;
18082: }
1.223 albertel 18083:
1.222 foxr 18084: # Same as escape_single, but escape's "'s This
18085: # can be used for "strings"
18086: sub escape_double {
18087: my ($input) = @_;
18088: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
18089: $input =~ s/\"/\\\"/g; # Esacpe the "s....
18090: return $input;
18091: }
1.223 albertel 18092:
1.222 foxr 18093: # Escapes the last element of a full URL.
18094: sub escape_url {
18095: my ($url) = @_;
1.238 raeburn 18096: my @urlslices = split(/\//, $url,-1);
1.369 www 18097: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 18098: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 18099: }
1.462 albertel 18100:
1.820 raeburn 18101: sub compare_arrays {
18102: my ($arrayref1,$arrayref2) = @_;
18103: my (@difference,%count);
18104: @difference = ();
18105: %count = ();
18106: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
18107: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
18108: foreach my $element (keys(%count)) {
18109: if ($count{$element} == 1) {
18110: push(@difference,$element);
18111: }
18112: }
18113: }
18114: return @difference;
18115: }
18116:
1.1322 raeburn 18117: sub lon_status_items {
18118: my %defaults = (
18119: E => 100,
18120: W => 4,
18121: N => 1,
1.1324 raeburn 18122: U => 5,
1.1322 raeburn 18123: threshold => 200,
18124: sysmail => 2500,
18125: );
18126: my %names = (
18127: E => 'Errors',
18128: W => 'Warnings',
18129: N => 'Notices',
1.1324 raeburn 18130: U => 'Unsent',
1.1322 raeburn 18131: );
18132: return (\%defaults,\%names);
18133: }
18134:
1.817 bisitz 18135: # -------------------------------------------------------- Initialize user login
1.462 albertel 18136: sub init_user_environment {
1.463 albertel 18137: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 18138: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
18139:
18140: my $public=($username eq 'public' && $domain eq 'public');
18141:
1.1415 raeburn 18142: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv,
18143: $coauthorenv);
1.462 albertel 18144: my $now=time;
18145:
18146: if ($public) {
18147: my $max_public=100;
18148: my $oldest;
18149: my $oldest_time=0;
18150: for(my $next=1;$next<=$max_public;$next++) {
18151: if (-e $lonids."/publicuser_$next.id") {
18152: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
18153: if ($mtime<$oldest_time || !$oldest_time) {
18154: $oldest_time=$mtime;
18155: $oldest=$next;
18156: }
18157: } else {
18158: $cookie="publicuser_$next";
18159: last;
18160: }
18161: }
18162: if (!$cookie) { $cookie="publicuser_$oldest"; }
18163: } else {
1.1275 raeburn 18164: # See if old ID present, if so, remove if this isn't a robot,
18165: # killing any existing non-robot sessions
1.463 albertel 18166: if (!$args->{'robot'}) {
18167: opendir(DIR,$lonids);
18168: while ($filename=readdir(DIR)) {
18169: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 18170: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
18171: &GDBM_READER(),0640)) {
1.1295 raeburn 18172: my $linkedfile;
1.1320 raeburn 18173: if (exists($oldenv{'user.linkedenv'})) {
18174: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 18175: }
1.1320 raeburn 18176: untie(%oldenv);
18177: if (unlink("$lonids/$filename")) {
18178: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
18179: if (-l "$lonids/$linkedfile.id") {
18180: unlink("$lonids/$linkedfile.id");
18181: }
1.1295 raeburn 18182: }
18183: }
18184: } else {
18185: unlink($lonids.'/'.$filename);
18186: }
1.463 albertel 18187: }
1.462 albertel 18188: }
1.463 albertel 18189: closedir(DIR);
1.1204 raeburn 18190: # If there is a undeleted lockfile for the user's paste buffer remove it.
18191: my $namespace = 'nohist_courseeditor';
18192: my $lockingkey = 'paste'."\0".'locked_num';
18193: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
18194: $domain,$username);
18195: if (exists($lockhash{$lockingkey})) {
18196: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
18197: unless ($delresult eq 'ok') {
18198: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
18199: }
18200: }
1.462 albertel 18201: }
18202: # Give them a new cookie
1.463 albertel 18203: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 18204: : $now.$$.int(rand(10000)));
1.463 albertel 18205: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 18206:
18207: # Initialize roles
18208:
1.1414 raeburn 18209: ($userroles,$firstaccenv,$timerintenv,$coauthorenv) =
1.1062 raeburn 18210: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 18211: }
18212: # ------------------------------------ Check browser type and MathML capability
18213:
1.1194 raeburn 18214: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
18215: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 18216:
18217: # ------------------------------------------------------------- Get environment
18218:
18219: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
18220: my ($tmp) = keys(%userenv);
1.1275 raeburn 18221: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 18222: undef(%userenv);
18223: }
18224: if (($userenv{'interface'}) && (!$form->{'interface'})) {
18225: $form->{'interface'}=$userenv{'interface'};
18226: }
18227: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
18228:
18229: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 18230: foreach my $option ('interface','localpath','localres') {
18231: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 18232: }
18233: # --------------------------------------------------------- Write first profile
18234:
18235: {
1.1350 raeburn 18236: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 18237: my %initial_env =
18238: ("user.name" => $username,
18239: "user.domain" => $domain,
18240: "user.home" => $authhost,
18241: "browser.type" => $clientbrowser,
18242: "browser.version" => $clientversion,
18243: "browser.mathml" => $clientmathml,
18244: "browser.unicode" => $clientunicode,
18245: "browser.os" => $clientos,
1.1137 raeburn 18246: "browser.mobile" => $clientmobile,
1.1141 raeburn 18247: "browser.info" => $clientinfo,
1.1194 raeburn 18248: "browser.osversion" => $clientosversion,
1.462 albertel 18249: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
18250: "request.course.fn" => '',
18251: "request.course.uri" => '',
18252: "request.course.sec" => '',
18253: "request.role" => 'cm',
18254: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 18255: "request.host" => $ip,);
1.462 albertel 18256:
18257: if ($form->{'localpath'}) {
18258: $initial_env{"browser.localpath"} = $form->{'localpath'};
18259: $initial_env{"browser.localres"} = $form->{'localres'};
18260: }
18261:
18262: if ($form->{'interface'}) {
18263: $form->{'interface'}=~s/\W//gs;
18264: $initial_env{"browser.interface"} = $form->{'interface'};
18265: $env{'browser.interface'}=$form->{'interface'};
18266: }
18267:
1.1157 raeburn 18268: if ($form->{'iptoken'}) {
18269: my $lonhost = $r->dir_config('lonHostID');
18270: $initial_env{"user.noloadbalance"} = $lonhost;
18271: $env{'user.noloadbalance'} = $lonhost;
18272: }
18273:
1.1268 raeburn 18274: if ($form->{'noloadbalance'}) {
18275: my @hosts = &Apache::lonnet::current_machine_ids();
18276: my $hosthere = $form->{'noloadbalance'};
18277: if (grep(/^\Q$hosthere\E$/,@hosts)) {
18278: $initial_env{"user.noloadbalance"} = $hosthere;
18279: $env{'user.noloadbalance'} = $hosthere;
18280: }
18281: }
18282:
1.1016 raeburn 18283: unless ($domain eq 'public') {
1.1273 raeburn 18284: my %is_adv = ( is_adv => $env{'user.adv'} );
18285: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
18286:
1.1414 raeburn 18287: foreach my $tool ('aboutme','blog','webdav','portfolio','portaccess','timezone') {
18288: $userenv{'availabletools.'.$tool} =
1.1273 raeburn 18289: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
18290: undef,\%userenv,\%domdef,\%is_adv);
18291: }
1.980 raeburn 18292:
1.1311 raeburn 18293: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 18294: $userenv{'canrequest.'.$crstype} =
18295: &Apache::lonnet::usertools_access($username,$domain,$crstype,
18296: 'reload','requestcourses',
18297: \%userenv,\%domdef,\%is_adv);
18298: }
1.724 raeburn 18299:
1.1418 raeburn 18300: if ((ref($userroles) eq 'HASH') && ($userroles->{'user.author'}) &&
18301: (exists($userroles->{"user.role.au./$domain/"}))) {
18302: if ($userenv{'authoreditors'}) {
18303: $userenv{'editors'} = $userenv{'authoreditors'};
18304: } elsif ($domdef{'editors'} ne '') {
18305: $userenv{'editors'} = $domdef{'editors'};
18306: } else {
18307: $userenv{'editors'} = 'edit,xml';
18308: }
1.1431 raeburn 18309: if ($userenv{'authorarchive'}) {
18310: $userenv{'canarchive'} = 1;
18311: } elsif (($userenv{'authorarchive'} eq '') &&
18312: ($domdef{'archive'})) {
18313: $userenv{'canarchive'} = 1;
18314: }
1.1418 raeburn 18315: }
18316:
1.1273 raeburn 18317: $userenv{'canrequest.author'} =
18318: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
18319: 'reload','requestauthor',
1.980 raeburn 18320: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 18321: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
18322: $domain,$username);
18323: my $reqstatus = $reqauthor{'author_status'};
18324: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
18325: if (ref($reqauthor{'author'}) eq 'HASH') {
18326: $userenv{'requestauthorqueued'} = $reqstatus.':'.
18327: $reqauthor{'author'}{'timestamp'};
18328: }
1.1092 raeburn 18329: }
1.1287 raeburn 18330: my ($types,$typename) = &course_types();
18331: if (ref($types) eq 'ARRAY') {
18332: my @options = ('approval','validate','autolimit');
18333: my $optregex = join('|',@options);
18334: my (%willtrust,%trustchecked);
18335: foreach my $type (@{$types}) {
18336: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
18337: if ($dom_str ne '') {
18338: my $updatedstr = '';
18339: my @possdomains = split(',',$dom_str);
18340: foreach my $entry (@possdomains) {
18341: my ($extdom,$extopt) = split(':',$entry);
18342: unless ($trustchecked{$extdom}) {
18343: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
18344: $trustchecked{$extdom} = 1;
18345: }
18346: if ($willtrust{$extdom}) {
18347: $updatedstr .= $entry.',';
18348: }
18349: }
18350: $updatedstr =~ s/,$//;
18351: if ($updatedstr) {
18352: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
18353: } else {
18354: delete($userenv{'reqcrsotherdom.'.$type});
18355: }
18356: }
18357: }
18358: }
1.1092 raeburn 18359: }
1.462 albertel 18360: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 18361:
1.462 albertel 18362: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
18363: &GDBM_WRCREAT(),0640)) {
18364: &_add_to_env(\%disk_env,\%initial_env);
18365: &_add_to_env(\%disk_env,\%userenv,'environment.');
18366: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 18367: if (ref($firstaccenv) eq 'HASH') {
18368: &_add_to_env(\%disk_env,$firstaccenv);
18369: }
18370: if (ref($timerintenv) eq 'HASH') {
18371: &_add_to_env(\%disk_env,$timerintenv);
18372: }
1.1414 raeburn 18373: if (ref($coauthorenv) eq 'HASH') {
18374: if (keys(%{$coauthorenv})) {
18375: &_add_to_env(\%disk_env,$coauthorenv);
18376: }
18377: }
1.463 albertel 18378: if (ref($args->{'extra_env'})) {
18379: &_add_to_env(\%disk_env,$args->{'extra_env'});
18380: }
1.462 albertel 18381: untie(%disk_env);
18382: } else {
1.705 tempelho 18383: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
18384: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 18385: return 'error: '.$!;
18386: }
18387: }
18388: $env{'request.role'}='cm';
18389: $env{'request.role.adv'}=$env{'user.adv'};
18390: $env{'browser.type'}=$clientbrowser;
18391:
18392: return $cookie;
18393:
18394: }
18395:
18396: sub _add_to_env {
18397: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 18398: if (ref($env_data) eq 'HASH') {
18399: while (my ($key,$value) = each(%$env_data)) {
18400: $idf->{$prefix.$key} = $value;
18401: $env{$prefix.$key} = $value;
18402: }
1.462 albertel 18403: }
18404: }
18405:
1.685 tempelho 18406: # --- Get the symbolic name of a problem and the url
18407: sub get_symb {
18408: my ($request,$silent) = @_;
1.726 raeburn 18409: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 18410: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
18411: if ($symb eq '') {
18412: if (!$silent) {
1.1071 raeburn 18413: if (ref($request)) {
18414: $request->print("Unable to handle ambiguous references:$url:.");
18415: }
1.685 tempelho 18416: return ();
18417: }
18418: }
18419: &Apache::lonenc::check_decrypt(\$symb);
18420: return ($symb);
18421: }
18422:
18423: # --------------------------------------------------------------Get annotation
18424:
18425: sub get_annotation {
18426: my ($symb,$enc) = @_;
18427:
18428: my $key = $symb;
18429: if (!$enc) {
18430: $key =
18431: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
18432: }
18433: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
18434: return $annotation{$key};
18435: }
18436:
18437: sub clean_symb {
1.731 raeburn 18438: my ($symb,$delete_enc) = @_;
1.685 tempelho 18439:
18440: &Apache::lonenc::check_decrypt(\$symb);
18441: my $enc = $env{'request.enc'};
1.731 raeburn 18442: if ($delete_enc) {
1.730 raeburn 18443: delete($env{'request.enc'});
18444: }
1.685 tempelho 18445:
18446: return ($symb,$enc);
18447: }
1.462 albertel 18448:
1.1181 raeburn 18449: ############################################################
18450: ############################################################
18451:
18452: =pod
18453:
18454: =head1 Routines for building display used to search for courses
18455:
18456:
18457: =over 4
18458:
18459: =item * &build_filters()
18460:
18461: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 18462: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
18463: and quotacheck.pl
18464:
1.1181 raeburn 18465:
18466: Inputs:
18467:
18468: filterlist - anonymous array of fields to include as potential filters
18469:
18470: crstype - course type
18471:
18472: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
18473: to pop-open a course selector (will contain "extra element").
18474:
18475: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
18476:
18477: filter - anonymous hash of criteria and their values
18478:
18479: action - form action
18480:
18481: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
18482:
1.1182 raeburn 18483: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 18484:
18485: cloneruname - username of owner of new course who wants to clone
18486:
18487: clonerudom - domain of owner of new course who wants to clone
18488:
18489: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
18490:
18491: codetitlesref - reference to array of titles of components in institutional codes (official courses)
18492:
18493: codedom - domain
18494:
18495: formname - value of form element named "form".
18496:
18497: fixeddom - domain, if fixed.
18498:
18499: prevphase - value to assign to form element named "phase" when going back to the previous screen
18500:
18501: cnameelement - name of form element in form on opener page which will receive title of selected course
18502:
18503: cnumelement - name of form element in form on opener page which will receive courseID of selected course
18504:
18505: cdomelement - name of form element in form on opener page which will receive domain of selected course
18506:
18507: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
18508:
18509: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
18510:
18511: clonewarning - warning message about missing information for intended course owner when DC creates a course
18512:
1.1182 raeburn 18513:
1.1181 raeburn 18514: Returns: $output - HTML for display of search criteria, and hidden form elements.
18515:
1.1182 raeburn 18516:
1.1181 raeburn 18517: Side Effects: None
18518:
18519: =cut
18520:
18521: # ---------------------------------------------- search for courses based on last activity etc.
18522:
18523: sub build_filters {
18524: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
18525: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
18526: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
18527: $cnameelement,$cnumelement,$cdomelement,$setroles,
18528: $clonetext,$clonewarning) = @_;
1.1182 raeburn 18529: my ($list,$jscript);
1.1181 raeburn 18530: my $onchange = 'javascript:updateFilters(this)';
18531: my ($domainselectform,$sincefilterform,$createdfilterform,
18532: $ownerdomselectform,$persondomselectform,$instcodeform,
18533: $typeselectform,$instcodetitle);
18534: if ($formname eq '') {
18535: $formname = $caller;
18536: }
18537: foreach my $item (@{$filterlist}) {
18538: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
18539: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
18540: if ($item eq 'domainfilter') {
18541: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
18542: } elsif ($item eq 'coursefilter') {
18543: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
18544: } elsif ($item eq 'ownerfilter') {
18545: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
18546: } elsif ($item eq 'ownerdomfilter') {
18547: $filter->{'ownerdomfilter'} =
18548: &LONCAPA::clean_domain($filter->{$item});
18549: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
18550: 'ownerdomfilter',1);
18551: } elsif ($item eq 'personfilter') {
18552: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
18553: } elsif ($item eq 'persondomfilter') {
18554: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
18555: 'persondomfilter',1);
18556: } else {
18557: $filter->{$item} =~ s/\W//g;
18558: }
18559: if (!$filter->{$item}) {
18560: $filter->{$item} = '';
18561: }
18562: }
18563: if ($item eq 'domainfilter') {
18564: my $allow_blank = 1;
18565: if ($formname eq 'portform') {
18566: $allow_blank=0;
18567: } elsif ($formname eq 'studentform') {
18568: $allow_blank=0;
18569: }
18570: if ($fixeddom) {
18571: $domainselectform = '<input type="hidden" name="domainfilter"'.
18572: ' value="'.$codedom.'" />'.
18573: &Apache::lonnet::domain($codedom,'description');
18574: } else {
18575: $domainselectform = &select_dom_form($filter->{$item},
18576: 'domainfilter',
18577: $allow_blank,'',$onchange);
18578: }
18579: } else {
18580: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
18581: }
18582: }
18583:
18584: # last course activity filter and selection
18585: $sincefilterform = &timebased_select_form('sincefilter',$filter);
18586:
18587: # course created filter and selection
18588: if (exists($filter->{'createdfilter'})) {
18589: $createdfilterform = &timebased_select_form('createdfilter',$filter);
18590: }
18591:
1.1239 raeburn 18592: my $prefix = $crstype;
18593: if ($crstype eq 'Placement') {
18594: $prefix = 'Placement Test'
18595: }
1.1181 raeburn 18596: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 18597: 'cac' => "$prefix Activity",
18598: 'ccr' => "$prefix Created",
18599: 'cde' => "$prefix Title",
18600: 'cdo' => "$prefix Domain",
1.1181 raeburn 18601: 'ins' => 'Institutional Code',
18602: 'inc' => 'Institutional Categorization',
1.1239 raeburn 18603: 'cow' => "$prefix Owner/Co-owner",
18604: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 18605: 'cog' => 'Type',
18606: );
18607:
18608: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
18609: my $typeval = 'Course';
18610: if ($crstype eq 'Community') {
18611: $typeval = 'Community';
1.1239 raeburn 18612: } elsif ($crstype eq 'Placement') {
18613: $typeval = 'Placement';
1.1181 raeburn 18614: }
18615: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
18616: } else {
18617: $typeselectform = '<select name="type" size="1"';
18618: if ($onchange) {
18619: $typeselectform .= ' onchange="'.$onchange.'"';
18620: }
18621: $typeselectform .= '>'."\n";
1.1237 raeburn 18622: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 18623: my $shown;
18624: if ($posstype eq 'Placement') {
18625: $shown = &mt('Placement Test');
18626: } else {
18627: $shown = &mt($posstype);
18628: }
1.1181 raeburn 18629: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 18630: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 18631: }
18632: $typeselectform.="</select>";
18633: }
18634:
18635: my ($cloneableonlyform,$cloneabletitle);
18636: if (exists($filter->{'cloneableonly'})) {
18637: my $cloneableon = '';
18638: my $cloneableoff = ' checked="checked"';
18639: if ($filter->{'cloneableonly'}) {
18640: $cloneableon = $cloneableoff;
18641: $cloneableoff = '';
18642: }
18643: $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>';
18644: if ($formname eq 'ccrs') {
1.1187 bisitz 18645: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 18646: } else {
18647: $cloneabletitle = &mt('Cloneable by you');
18648: }
18649: }
18650: my $officialjs;
18651: if ($crstype eq 'Course') {
18652: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 18653: # if (($fixeddom) || ($formname eq 'requestcrs') ||
18654: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
18655: if ($codedom) {
1.1181 raeburn 18656: $officialjs = 1;
18657: ($instcodeform,$jscript,$$numtitlesref) =
18658: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
18659: $officialjs,$codetitlesref);
18660: if ($jscript) {
1.1182 raeburn 18661: $jscript = '<script type="text/javascript">'."\n".
18662: '// <![CDATA['."\n".
18663: $jscript."\n".
18664: '// ]]>'."\n".
18665: '</script>'."\n";
1.1181 raeburn 18666: }
18667: }
18668: if ($instcodeform eq '') {
18669: $instcodeform =
18670: '<input type="text" name="instcodefilter" size="10" value="'.
18671: $list->{'instcodefilter'}.'" />';
18672: $instcodetitle = $lt{'ins'};
18673: } else {
18674: $instcodetitle = $lt{'inc'};
18675: }
18676: if ($fixeddom) {
18677: $instcodetitle .= '<br />('.$codedom.')';
18678: }
18679: }
18680: }
18681: my $output = qq|
18682: <form method="post" name="filterpicker" action="$action">
18683: <input type="hidden" name="form" value="$formname" />
18684: |;
18685: if ($formname eq 'modifycourse') {
18686: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
18687: '<input type="hidden" name="prevphase" value="'.
18688: $prevphase.'" />'."\n";
1.1198 musolffc 18689: } elsif ($formname eq 'quotacheck') {
18690: $output .= qq|
18691: <input type="hidden" name="sortby" value="" />
18692: <input type="hidden" name="sortorder" value="" />
18693: |;
18694: } else {
1.1181 raeburn 18695: my $name_input;
18696: if ($cnameelement ne '') {
18697: $name_input = '<input type="hidden" name="cnameelement" value="'.
18698: $cnameelement.'" />';
18699: }
18700: $output .= qq|
1.1182 raeburn 18701: <input type="hidden" name="cnumelement" value="$cnumelement" />
18702: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 18703: $name_input
18704: $roleelement
18705: $multelement
18706: $typeelement
18707: |;
18708: if ($formname eq 'portform') {
18709: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
18710: }
18711: }
18712: if ($fixeddom) {
18713: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
18714: }
18715: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
18716: if ($sincefilterform) {
18717: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
18718: .$sincefilterform
18719: .&Apache::lonhtmlcommon::row_closure();
18720: }
18721: if ($createdfilterform) {
18722: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
18723: .$createdfilterform
18724: .&Apache::lonhtmlcommon::row_closure();
18725: }
18726: if ($domainselectform) {
18727: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
18728: .$domainselectform
18729: .&Apache::lonhtmlcommon::row_closure();
18730: }
18731: if ($typeselectform) {
18732: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
18733: $output .= $typeselectform;
18734: } else {
18735: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
18736: .$typeselectform
18737: .&Apache::lonhtmlcommon::row_closure();
18738: }
18739: }
18740: if ($instcodeform) {
18741: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
18742: .$instcodeform
18743: .&Apache::lonhtmlcommon::row_closure();
18744: }
18745: if (exists($filter->{'ownerfilter'})) {
18746: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
18747: '<table><tr><td>'.&mt('Username').'<br />'.
18748: '<input type="text" name="ownerfilter" size="20" value="'.
18749: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18750: $ownerdomselectform.'</td></tr></table>'.
18751: &Apache::lonhtmlcommon::row_closure();
18752: }
18753: if (exists($filter->{'personfilter'})) {
18754: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
18755: '<table><tr><td>'.&mt('Username').'<br />'.
18756: '<input type="text" name="personfilter" size="20" value="'.
18757: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18758: $persondomselectform.'</td></tr></table>'.
18759: &Apache::lonhtmlcommon::row_closure();
18760: }
18761: if (exists($filter->{'coursefilter'})) {
18762: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
18763: .'<input type="text" name="coursefilter" size="25" value="'
18764: .$list->{'coursefilter'}.'" />'
18765: .&Apache::lonhtmlcommon::row_closure();
18766: }
18767: if ($cloneableonlyform) {
18768: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
18769: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
18770: }
18771: if (exists($filter->{'descriptfilter'})) {
18772: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
18773: .'<input type="text" name="descriptfilter" size="40" value="'
18774: .$list->{'descriptfilter'}.'" />'
18775: .&Apache::lonhtmlcommon::row_closure(1);
18776: }
18777: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
18778: '<input type="hidden" name="updater" value="" />'."\n".
18779: '<input type="submit" name="gosearch" value="'.
18780: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
18781: return $jscript.$clonewarning.$output;
18782: }
18783:
18784: =pod
18785:
18786: =item * &timebased_select_form()
18787:
1.1182 raeburn 18788: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 18789: filter e.g., Course Activity, Course Created, when searching for courses
18790: or communities
18791:
18792: Inputs:
18793:
18794: item - name of form element (sincefilter or createdfilter)
18795:
18796: filter - anonymous hash of criteria and their values
18797:
18798: Returns: HTML for a select box contained a blank, then six time selections,
18799: with value set in incoming form variables currently selected.
18800:
18801: Side Effects: None
18802:
18803: =cut
18804:
18805: sub timebased_select_form {
18806: my ($item,$filter) = @_;
18807: if (ref($filter) eq 'HASH') {
18808: $filter->{$item} =~ s/[^\d-]//g;
18809: if (!$filter->{$item}) { $filter->{$item}=-1; }
18810: return &select_form(
18811: $filter->{$item},
18812: $item,
18813: { '-1' => '',
18814: '86400' => &mt('today'),
18815: '604800' => &mt('last week'),
18816: '2592000' => &mt('last month'),
18817: '7776000' => &mt('last three months'),
18818: '15552000' => &mt('last six months'),
18819: '31104000' => &mt('last year'),
18820: 'select_form_order' =>
18821: ['-1','86400','604800','2592000','7776000',
18822: '15552000','31104000']});
18823: }
18824: }
18825:
18826: =pod
18827:
18828: =item * &js_changer()
18829:
18830: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 18831: when course type or domain is changed, and also to hide 'Searching ...' on
18832: page load completion for page showing search result.
1.1181 raeburn 18833:
18834: Inputs: None
18835:
1.1183 raeburn 18836: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 18837:
18838: Side Effects: None
18839:
18840: =cut
18841:
18842: sub js_changer {
18843: return <<ENDJS;
18844: <script type="text/javascript">
18845: // <![CDATA[
18846: function updateFilters(caller) {
18847: if (typeof(caller) != "undefined") {
18848: document.filterpicker.updater.value = caller.name;
18849: }
18850: document.filterpicker.submit();
18851: }
1.1183 raeburn 18852:
18853: function hideSearching() {
18854: if (document.getElementById('searching')) {
18855: document.getElementById('searching').style.display = 'none';
18856: }
18857: return;
18858: }
18859:
1.1181 raeburn 18860: // ]]>
18861: </script>
18862:
18863: ENDJS
18864: }
18865:
18866: =pod
18867:
1.1182 raeburn 18868: =item * &search_courses()
18869:
18870: Process selected filters form course search form and pass to lonnet::courseiddump
18871: to retrieve a hash for which keys are courseIDs which match the selected filters.
18872:
18873: Inputs:
18874:
18875: dom - domain being searched
18876:
18877: type - course type ('Course' or 'Community' or '.' if any).
18878:
18879: filter - anonymous hash of criteria and their values
18880:
18881: numtitles - for institutional codes - number of categories
18882:
18883: cloneruname - optional username of new course owner
18884:
18885: clonerudom - optional domain of new course owner
18886:
1.1221 raeburn 18887: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 18888: (used when DC is using course creation form)
18889:
18890: codetitles - reference to array of titles of components in institutional codes (official courses).
18891:
1.1221 raeburn 18892: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
18893: (and so can clone automatically)
18894:
18895: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
18896:
18897: reqinstcode - institutional code of new course, where search_courses is used to identify potential
18898: courses to clone
1.1182 raeburn 18899:
18900: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
18901:
18902:
18903: Side Effects: None
18904:
18905: =cut
18906:
18907:
18908: sub search_courses {
1.1221 raeburn 18909: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
18910: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 18911: my (%courses,%showcourses,$cloner);
18912: if (($filter->{'ownerfilter'} ne '') ||
18913: ($filter->{'ownerdomfilter'} ne '')) {
18914: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
18915: $filter->{'ownerdomfilter'};
18916: }
18917: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
18918: if (!$filter->{$item}) {
18919: $filter->{$item}='.';
18920: }
18921: }
18922: my $now = time;
18923: my $timefilter =
18924: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
18925: my ($createdbefore,$createdafter);
18926: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
18927: $createdbefore = $now;
18928: $createdafter = $now-$filter->{'createdfilter'};
18929: }
18930: my ($instcodefilter,$regexpok);
18931: if ($numtitles) {
18932: if ($env{'form.official'} eq 'on') {
18933: $instcodefilter =
18934: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18935: $regexpok = 1;
18936: } elsif ($env{'form.official'} eq 'off') {
18937: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18938: unless ($instcodefilter eq '') {
18939: $regexpok = -1;
18940: }
18941: }
18942: } else {
18943: $instcodefilter = $filter->{'instcodefilter'};
18944: }
18945: if ($instcodefilter eq '') { $instcodefilter = '.'; }
18946: if ($type eq '') { $type = '.'; }
18947:
18948: if (($clonerudom ne '') && ($cloneruname ne '')) {
18949: $cloner = $cloneruname.':'.$clonerudom;
18950: }
18951: %courses = &Apache::lonnet::courseiddump($dom,
18952: $filter->{'descriptfilter'},
18953: $timefilter,
18954: $instcodefilter,
18955: $filter->{'combownerfilter'},
18956: $filter->{'coursefilter'},
18957: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 18958: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 18959: $filter->{'cloneableonly'},
18960: $createdbefore,$createdafter,undef,
1.1221 raeburn 18961: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 18962: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
18963: my $ccrole;
18964: if ($type eq 'Community') {
18965: $ccrole = 'co';
18966: } else {
18967: $ccrole = 'cc';
18968: }
18969: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
18970: $filter->{'persondomfilter'},
18971: 'userroles',undef,
18972: [$ccrole,'in','ad','ep','ta','cr'],
18973: $dom);
18974: foreach my $role (keys(%rolehash)) {
18975: my ($cnum,$cdom,$courserole) = split(':',$role);
18976: my $cid = $cdom.'_'.$cnum;
18977: if (exists($courses{$cid})) {
18978: if (ref($courses{$cid}) eq 'HASH') {
18979: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
18980: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 18981: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 18982: }
18983: } else {
18984: $courses{$cid}{roles} = [$courserole];
18985: }
18986: $showcourses{$cid} = $courses{$cid};
18987: }
18988: }
18989: }
18990: %courses = %showcourses;
18991: }
18992: return %courses;
18993: }
18994:
18995: =pod
18996:
1.1181 raeburn 18997: =back
18998:
1.1207 raeburn 18999: =head1 Routines for version requirements for current course.
19000:
19001: =over 4
19002:
19003: =item * &check_release_required()
19004:
19005: Compares required LON-CAPA version with version on server, and
19006: if required version is newer looks for a server with the required version.
19007:
19008: Looks first at servers in user's owen domain; if none suitable, looks at
19009: servers in course's domain are permitted to host sessions for user's domain.
19010:
19011: Inputs:
19012:
19013: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
19014:
19015: $courseid - Course ID of current course
19016:
19017: $rolecode - User's current role in course (for switchserver query string).
19018:
19019: $required - LON-CAPA version needed by course (format: Major.Minor).
19020:
19021:
19022: Returns:
19023:
19024: $switchserver - query string tp append to /adm/switchserver call (if
19025: current server's LON-CAPA version is too old.
19026:
19027: $warning - Message is displayed if no suitable server could be found.
19028:
19029: =cut
19030:
19031: sub check_release_required {
19032: my ($loncaparev,$courseid,$rolecode,$required) = @_;
19033: my ($switchserver,$warning);
19034: if ($required ne '') {
19035: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
19036: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
19037: if ($reqdmajor ne '' && $reqdminor ne '') {
19038: my $otherserver;
19039: if (($major eq '' && $minor eq '') ||
19040: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
19041: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
19042: my $switchlcrev =
19043: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
19044: $userdomserver);
19045: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
19046: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
19047: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
19048: my $cdom = $env{'course.'.$courseid.'.domain'};
19049: if ($cdom ne $env{'user.domain'}) {
19050: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
19051: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
19052: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
19053: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
19054: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
19055: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
19056: my $canhost =
19057: &Apache::lonnet::can_host_session($env{'user.domain'},
19058: $coursedomserver,
19059: $remoterev,
19060: $udomdefaults{'remotesessions'},
19061: $defdomdefaults{'hostedsessions'});
19062:
19063: if ($canhost) {
19064: $otherserver = $coursedomserver;
19065: } else {
19066: $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.");
19067: }
19068: } else {
19069: $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).");
19070: }
19071: } else {
19072: $otherserver = $userdomserver;
19073: }
19074: }
19075: if ($otherserver ne '') {
19076: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
19077: }
19078: }
19079: }
19080: return ($switchserver,$warning);
19081: }
19082:
19083: =pod
19084:
19085: =item * &check_release_result()
19086:
19087: Inputs:
19088:
19089: $switchwarning - Warning message if no suitable server found to host session.
19090:
19091: $switchserver - query string to append to /adm/switchserver containing lonHostID
19092: and current role.
19093:
19094: Returns: HTML to display with information about requirement to switch server.
19095: Either displaying warning with link to Roles/Courses screen or
19096: display link to switchserver.
19097:
1.1181 raeburn 19098: =cut
19099:
1.1207 raeburn 19100: sub check_release_result {
19101: my ($switchwarning,$switchserver) = @_;
19102: my $output = &start_page('Selected course unavailable on this server').
1.1463 raeburn 19103: '<div class="LC_landmark" role="main"><p class="LC_warning">';
1.1207 raeburn 19104: if ($switchwarning) {
19105: $output .= $switchwarning.'<br /><a href="/adm/roles">';
19106: if (&show_course()) {
19107: $output .= &mt('Display courses');
19108: } else {
19109: $output .= &mt('Display roles');
19110: }
19111: $output .= '</a>';
19112: } elsif ($switchserver) {
19113: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
19114: '<br />'.
19115: '<a href="/adm/switchserver?'.$switchserver.'">'.
19116: &mt('Switch Server').
19117: '</a>';
19118: }
1.1463 raeburn 19119: $output .= '</p></div>'.&end_page();
1.1207 raeburn 19120: return $output;
19121: }
19122:
19123: =pod
19124:
19125: =item * &needs_coursereinit()
19126:
19127: Determine if course contents stored for user's session needs to be
19128: refreshed, because content has changed since "Big Hash" last tied.
19129:
19130: Check for change is made if time last checked is more than 10 minutes ago
19131: (by default).
19132:
19133: Inputs:
19134:
19135: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
19136:
19137: $interval (optional) - Time which may elapse (in s) between last check for content
19138: change in current course. (default: 600 s).
19139:
19140: Returns: an array; first element is:
19141:
19142: =over 4
19143:
19144: 'switch' - if content updates mean user's session
19145: needs to be switched to a server running a newer LON-CAPA version
19146:
19147: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
19148: on current server hosting user's session
19149:
19150: '' - if no action required.
19151:
19152: =back
19153:
19154: If first item element is 'switch':
19155:
19156: second item is $switchwarning - Warning message if no suitable server found to host session.
19157:
19158: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
19159: and current role.
19160:
19161: otherwise: no other elements returned.
19162:
19163: =back
19164:
19165: =cut
19166:
19167: sub needs_coursereinit {
19168: my ($loncaparev,$interval) = @_;
19169: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
19170: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
19171: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
19172: my $now = time;
19173: if ($interval eq '') {
19174: $interval = 600;
19175: }
19176: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 19177: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1372 raeburn 19178: my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 19179: if ($blocked) {
19180: return ();
19181: }
1.1391 raeburn 19182: my $update;
19183: my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
19184: my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);
19185: if ($lastmainchange > $env{'request.course.tied'}) {
19186: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
19187: if ($needswitch) {
19188: return ('switch',$switchwarning,$switchserver);
19189: }
19190: $update = 'main';
19191: }
19192: if ($lastsuppchange > $env{'request.course.suppupdated'}) {
19193: if ($update) {
19194: $update = 'both';
19195: } else {
19196: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
19197: if ($needswitch) {
19198: return ('switch',$switchwarning,$switchserver);
19199: } else {
19200: $update = 'supp';
1.1207 raeburn 19201: }
19202: }
1.1391 raeburn 19203: }
1.1453 raeburn 19204: return ($update);
1.1391 raeburn 19205: }
19206: return ();
19207: }
19208:
19209: sub switch_for_update {
19210: my ($loncaparev,$cdom,$cnum) = @_;
19211: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
19212: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
19213: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
19214: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
19215: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
19216: $curr_reqd_hash{'internal.releaserequired'}});
19217: my ($switchserver,$switchwarning) =
19218: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
19219: $curr_reqd_hash{'internal.releaserequired'});
19220: if ($switchwarning ne '' || $switchserver ne '') {
19221: return ('switch',$switchwarning,$switchserver);
19222: }
1.1207 raeburn 19223: }
19224: }
19225: return ();
19226: }
1.1181 raeburn 19227:
1.1083 raeburn 19228: sub update_content_constraints {
1.1395 raeburn 19229: my ($cdom,$cnum,$chome,$cid) = @_;
1.1083 raeburn 19230: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
19231: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 19232: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 19233: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 19234: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 19235: if ($item eq 'resourcetag') {
19236: if ($name eq 'responsetype') {
19237: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
19238: }
1.1307 raeburn 19239: } elsif ($item eq 'course') {
19240: if ($name eq 'courserestype') {
19241: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
19242: }
1.1083 raeburn 19243: }
19244: }
19245: my $navmap = Apache::lonnavmaps::navmap->new();
19246: if (defined($navmap)) {
1.1307 raeburn 19247: my (%allresponses,%allcrsrestypes);
19248: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
19249: if ($res->is_tool()) {
19250: if ($allcrsrestypes{'exttool'}) {
19251: $allcrsrestypes{'exttool'} ++;
19252: } else {
19253: $allcrsrestypes{'exttool'} = 1;
19254: }
19255: next;
19256: }
1.1083 raeburn 19257: my %responses = $res->responseTypes();
19258: foreach my $key (keys(%responses)) {
19259: next unless(exists($checkresponsetypes{$key}));
19260: $allresponses{$key} += $responses{$key};
19261: }
19262: }
19263: foreach my $key (keys(%allresponses)) {
19264: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
19265: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
19266: ($reqdmajor,$reqdminor) = ($major,$minor);
19267: }
19268: }
1.1307 raeburn 19269: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 19270: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 19271: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
19272: ($reqdmajor,$reqdminor) = ($major,$minor);
19273: }
19274: }
1.1083 raeburn 19275: undef($navmap);
19276: }
1.1391 raeburn 19277: if (&Apache::lonnet::count_supptools($cnum,$cdom,1)) {
1.1308 raeburn 19278: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
19279: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
19280: ($reqdmajor,$reqdminor) = ($major,$minor);
19281: }
19282: }
1.1083 raeburn 19283: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
19284: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
19285: }
19286: return;
19287: }
19288:
1.1110 raeburn 19289: sub allmaps_incourse {
19290: my ($cdom,$cnum,$chome,$cid) = @_;
19291: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
19292: $cid = $env{'request.course.id'};
19293: $cdom = $env{'course.'.$cid.'.domain'};
19294: $cnum = $env{'course.'.$cid.'.num'};
19295: $chome = $env{'course.'.$cid.'.home'};
19296: }
19297: my %allmaps = ();
19298: my $lastchange =
19299: &Apache::lonnet::get_coursechange($cdom,$cnum);
19300: if ($lastchange > $env{'request.course.tied'}) {
19301: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
19302: unless ($ferr) {
1.1395 raeburn 19303: &update_content_constraints($cdom,$cnum,$chome,$cid);
1.1110 raeburn 19304: }
19305: }
19306: my $navmap = Apache::lonnavmaps::navmap->new();
19307: if (defined($navmap)) {
19308: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
19309: $allmaps{$res->src()} = 1;
19310: }
19311: }
19312: return \%allmaps;
19313: }
19314:
1.1083 raeburn 19315: sub parse_supplemental_title {
19316: my ($title) = @_;
19317:
19318: my ($foldertitle,$renametitle);
19319: if ($title =~ /&&&/) {
19320: $title = &HTML::Entites::decode($title);
19321: }
19322: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
19323: $renametitle=$4;
19324: my ($time,$uname,$udom) = ($1,$2,$3);
19325: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
19326: my $name = &plainname($uname,$udom);
19327: $name = &HTML::Entities::encode($name,'"<>&\'');
19328: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.1401 raeburn 19329: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
1.1402 raeburn 19330: if ($foldertitle ne '') {
1.1401 raeburn 19331: $title .= ': <br />'.$foldertitle;
19332: }
1.1083 raeburn 19333: }
19334: if (wantarray) {
19335: return ($title,$foldertitle,$renametitle);
19336: }
19337: return $title;
19338: }
19339:
1.1395 raeburn 19340: sub get_supplemental {
19341: my ($cnum,$cdom,$ignorecache,$possdel)=@_;
19342: my $hashid=$cnum.':'.$cdom;
19343: my ($supplemental,$cached,$set_httprefs);
19344: unless ($ignorecache) {
19345: ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);
19346: }
19347: unless (defined($cached)) {
19348: my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
19349: unless ($chome eq 'no_host') {
19350: my @order = @LONCAPA::map::order;
19351: my @resources = @LONCAPA::map::resources;
19352: my @resparms = @LONCAPA::map::resparms;
19353: my @zombies = @LONCAPA::map::zombies;
19354: my ($errors,%ids,%hidden);
19355: $errors =
19356: &recurse_supplemental($cnum,$cdom,'supplemental.sequence',
19357: $errors,$possdel,\%ids,\%hidden);
19358: @LONCAPA::map::order = @order;
19359: @LONCAPA::map::resources = @resources;
19360: @LONCAPA::map::resparms = @resparms;
19361: @LONCAPA::map::zombies = @zombies;
19362: $set_httprefs = 1;
19363: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
19364: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
19365: }
19366: $supplemental = {
19367: ids => \%ids,
19368: hidden => \%hidden,
19369: };
19370: &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);
19371: }
19372: }
19373: return ($supplemental,$set_httprefs);
19374: }
19375:
1.1143 raeburn 19376: sub recurse_supplemental {
1.1391 raeburn 19377: my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;
19378: if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {
19379: my $mapnum;
19380: if ($suppmap eq 'supplemental.sequence') {
19381: $mapnum = 0;
19382: } else {
19383: ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);
19384: }
1.1143 raeburn 19385: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
19386: if ($fatal) {
19387: $errors ++;
19388: } else {
1.1389 raeburn 19389: my @order = @LONCAPA::map::order;
19390: if (@order > 0) {
19391: my @resources = @LONCAPA::map::resources;
1.1391 raeburn 19392: my @resparms = @LONCAPA::map::resparms;
1.1389 raeburn 19393: foreach my $idx (@order) {
19394: my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1143 raeburn 19395: if (($src ne '') && ($status eq 'res')) {
1.1391 raeburn 19396: my $id = $mapnum.':'.$idx;
19397: push(@{$suppids->{$src}},$id);
19398: if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {
19399: $hiddensupp->{$id} = 1;
19400: }
1.1146 raeburn 19401: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1391 raeburn 19402: $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,
19403: $hiddensupp,$hiddensupp->{$id});
1.1143 raeburn 19404: } else {
1.1391 raeburn 19405: my $allowed;
19406: if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {
19407: $allowed = 1;
19408: } elsif ($possdel) {
19409: foreach my $item (@{$suppids->{$src}}) {
19410: next if ($item eq $id);
19411: unless ($hiddensupp->{$item}) {
19412: $allowed = 1;
19413: last;
19414: }
19415: }
19416: if ((!$allowed) && (exists($env{'httpref.'.$src}))) {
19417: &Apache::lonnet::delenv('httpref.'.$src);
19418: }
19419: }
19420: if ($allowed && (!exists($env{'httpref.'.$src}))) {
19421: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
1.1308 raeburn 19422: }
1.1143 raeburn 19423: }
19424: }
19425: }
19426: }
19427: }
19428: }
1.1391 raeburn 19429: return $errors;
19430: }
19431:
19432: sub set_supp_httprefs {
19433: my ($cnum,$cdom,$supplemental,$possdel) = @_;
19434: if (ref($supplemental) eq 'HASH') {
19435: if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {
19436: foreach my $src (keys(%{$supplemental->{'ids'}})) {
19437: next if ($src =~ /\.sequence$/);
19438: if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {
19439: my $allowed;
19440: if ($env{'request.role.adv'}) {
19441: $allowed = 1;
19442: } else {
19443: foreach my $id (@{$supplemental->{'ids'}->{$src}}) {
19444: unless ($supplemental->{'hidden'}->{$id}) {
19445: $allowed = 1;
19446: last;
19447: }
19448: }
19449: }
19450: if (exists($env{'httpref.'.$src})) {
19451: if ($possdel) {
19452: unless ($allowed) {
19453: &Apache::lonnet::delenv('httpref.'.$src);
19454: }
19455: }
19456: } elsif ($allowed) {
19457: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
19458: }
19459: }
19460: }
19461: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
19462: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
19463: }
19464: }
19465: }
19466: }
19467:
19468: sub get_supp_parameter {
19469: my ($resparm,$name)=@_;
19470: return if ($resparm eq '');
19471: my $value=undef;
19472: my $ptype=undef;
19473: foreach (split('&&&',$resparm)) {
19474: my ($thistype,$thisname,$thisvalue)=split('___',$_);
19475: if ($thisname eq $name) {
19476: $value=$thisvalue;
19477: $ptype=$thistype;
19478: }
19479: }
19480: return $value;
1.1143 raeburn 19481: }
19482:
1.1101 raeburn 19483: sub symb_to_docspath {
1.1267 raeburn 19484: my ($symb,$navmapref) = @_;
19485: return unless ($symb && ref($navmapref));
1.1101 raeburn 19486: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
19487: if ($resurl=~/\.(sequence|page)$/) {
19488: $mapurl=$resurl;
19489: } elsif ($resurl eq 'adm/navmaps') {
19490: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
19491: }
19492: my $mapresobj;
1.1267 raeburn 19493: unless (ref($$navmapref)) {
19494: $$navmapref = Apache::lonnavmaps::navmap->new();
19495: }
19496: if (ref($$navmapref)) {
19497: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 19498: }
19499: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
19500: my $type=$2;
19501: my $path;
19502: if (ref($mapresobj)) {
19503: my $pcslist = $mapresobj->map_hierarchy();
19504: if ($pcslist ne '') {
19505: foreach my $pc (split(/,/,$pcslist)) {
19506: next if ($pc <= 1);
1.1267 raeburn 19507: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 19508: if (ref($res)) {
19509: my $thisurl = $res->src();
19510: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
19511: my $thistitle = $res->title();
19512: $path .= '&'.
19513: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 19514: &escape($thistitle).
1.1101 raeburn 19515: ':'.$res->randompick().
19516: ':'.$res->randomout().
19517: ':'.$res->encrypted().
19518: ':'.$res->randomorder().
19519: ':'.$res->is_page();
19520: }
19521: }
19522: }
19523: $path =~ s/^\&//;
19524: my $maptitle = $mapresobj->title();
19525: if ($mapurl eq 'default') {
1.1129 raeburn 19526: $maptitle = 'Main Content';
1.1101 raeburn 19527: }
19528: $path .= (($path ne '')? '&' : '').
19529: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 19530: &escape($maptitle).
1.1101 raeburn 19531: ':'.$mapresobj->randompick().
19532: ':'.$mapresobj->randomout().
19533: ':'.$mapresobj->encrypted().
19534: ':'.$mapresobj->randomorder().
19535: ':'.$mapresobj->is_page();
19536: } else {
19537: my $maptitle = &Apache::lonnet::gettitle($mapurl);
19538: my $ispage = (($type eq 'page')? 1 : '');
19539: if ($mapurl eq 'default') {
1.1129 raeburn 19540: $maptitle = 'Main Content';
1.1101 raeburn 19541: }
19542: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 19543: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 19544: }
19545: unless ($mapurl eq 'default') {
19546: $path = 'default&'.
1.1146 raeburn 19547: &escape('Main Content').
1.1101 raeburn 19548: ':::::&'.$path;
19549: }
19550: return $path;
19551: }
19552:
1.1393 raeburn 19553: sub validate_folderpath {
19554: my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;
19555: if ($env{'form.folderpath'} ne '') {
19556: my @items = split(/\&/,$env{'form.folderpath'});
1.1394 raeburn 19557: my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);
1.1393 raeburn 19558: for (my $i=0; $i<@items; $i++) {
19559: my $odd = $i%2;
19560: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
19561: $badpath = 1;
1.1394 raeburn 19562: } elsif ($odd && $supplementalflag) {
1.1393 raeburn 19563: my $idx = $i-1;
1.1394 raeburn 19564: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
19565: my $esc_name = $1;
19566: if ((!$allowed) || ($items[$idx] eq 'supplemental')) {
19567: $supppath .= '&'.$esc_name;
19568: $changed = 1;
19569: } else {
19570: $supppath .= '&'.$items[$i];
19571: }
19572: } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {
19573: $changed = 1;
1.1393 raeburn 19574: my $is_hidden;
19575: unless ($got_supp) {
1.1395 raeburn 19576: my ($supplemental) = &get_supplemental($coursenum,$coursedom);
1.1393 raeburn 19577: if (ref($supplemental) eq 'HASH') {
19578: if (ref($supplemental->{'hidden'}) eq 'HASH') {
19579: %supphidden = %{$supplemental->{'hidden'}};
19580: }
19581: if (ref($supplemental->{'ids'}) eq 'HASH') {
19582: %suppids = %{$supplemental->{'ids'}};
19583: }
19584: }
19585: $got_supp = 1;
19586: }
19587: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
19588: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
19589: if ($supphidden{$mapid}) {
19590: $is_hidden = 1;
19591: }
19592: }
1.1394 raeburn 19593: $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';
19594: } else {
19595: $supppath .= '&'.$items[$i];
1.1393 raeburn 19596: }
19597: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
19598: $badpath = 1;
1.1394 raeburn 19599: } elsif ($supplementalflag) {
1.1393 raeburn 19600: $supppath .= '&'.$items[$i];
19601: }
19602: last if ($badpath);
19603: }
19604: if ($badpath) {
19605: delete($env{'form.folderpath'});
1.1394 raeburn 19606: } elsif ($changed && $supplementalflag) {
1.1393 raeburn 19607: $supppath =~ s/^\&//;
19608: $env{'form.folderpath'} = $supppath;
19609: }
19610: }
19611: return;
19612: }
19613:
1.1094 raeburn 19614: sub captcha_display {
1.1327 raeburn 19615: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 19616: my ($output,$error);
1.1234 raeburn 19617: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 19618: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 19619: if ($captcha eq 'original') {
1.1094 raeburn 19620: $output = &create_captcha();
19621: unless ($output) {
1.1172 raeburn 19622: $error = 'captcha';
1.1094 raeburn 19623: }
19624: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 19625: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 19626: unless ($output) {
1.1172 raeburn 19627: $error = 'recaptcha';
1.1094 raeburn 19628: }
19629: }
1.1234 raeburn 19630: return ($output,$error,$captcha,$version);
1.1094 raeburn 19631: }
19632:
19633: sub captcha_response {
1.1327 raeburn 19634: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 19635: my ($captcha_chk,$captcha_error);
1.1327 raeburn 19636: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 19637: if ($captcha eq 'original') {
1.1094 raeburn 19638: ($captcha_chk,$captcha_error) = &check_captcha();
19639: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 19640: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 19641: } else {
19642: $captcha_chk = 1;
19643: }
19644: return ($captcha_chk,$captcha_error);
19645: }
19646:
19647: sub get_captcha_config {
1.1327 raeburn 19648: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 19649: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 19650: my $hostname = &Apache::lonnet::hostname($lonhost);
19651: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
19652: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 19653: if ($context eq 'usercreation') {
19654: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
19655: if (ref($domconfig{$context}) eq 'HASH') {
19656: $hashtocheck = $domconfig{$context}{'cancreate'};
19657: if (ref($hashtocheck) eq 'HASH') {
19658: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
19659: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
19660: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
19661: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
19662: }
19663: if ($privkey && $pubkey) {
19664: $captcha = 'recaptcha';
1.1234 raeburn 19665: $version = $hashtocheck->{'recaptchaversion'};
19666: if ($version ne '2') {
19667: $version = 1;
19668: }
1.1095 raeburn 19669: } else {
19670: $captcha = 'original';
19671: }
19672: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
19673: $captcha = 'original';
19674: }
1.1094 raeburn 19675: }
1.1095 raeburn 19676: } else {
19677: $captcha = 'captcha';
19678: }
19679: } elsif ($context eq 'login') {
19680: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
19681: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
19682: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
19683: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 19684: if ($privkey && $pubkey) {
19685: $captcha = 'recaptcha';
1.1234 raeburn 19686: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
19687: if ($version ne '2') {
19688: $version = 1;
19689: }
1.1095 raeburn 19690: } else {
19691: $captcha = 'original';
1.1094 raeburn 19692: }
1.1095 raeburn 19693: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
19694: $captcha = 'original';
1.1094 raeburn 19695: }
1.1327 raeburn 19696: } elsif ($context eq 'passwords') {
19697: if ($dom_in_effect) {
19698: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
19699: if ($passwdconf{'captcha'} eq 'recaptcha') {
19700: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
19701: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
19702: $privkey = $passwdconf{'recaptchakeys'}{'private'};
19703: }
19704: if ($privkey && $pubkey) {
19705: $captcha = 'recaptcha';
19706: $version = $passwdconf{'recaptchaversion'};
19707: if ($version ne '2') {
19708: $version = 1;
19709: }
19710: } else {
19711: $captcha = 'original';
19712: }
19713: } elsif ($passwdconf{'captcha'} ne 'notused') {
19714: $captcha = 'original';
19715: }
19716: }
19717: }
1.1234 raeburn 19718: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 19719: }
19720:
19721: sub create_captcha {
19722: my %captcha_params = &captcha_settings();
19723: my ($output,$maxtries,$tries) = ('',10,0);
19724: while ($tries < $maxtries) {
19725: $tries ++;
19726: my $captcha = Authen::Captcha->new (
19727: output_folder => $captcha_params{'output_dir'},
19728: data_folder => $captcha_params{'db_dir'},
19729: );
19730: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
19731:
19732: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
19733: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1367 raeburn 19734: '<span class="LC_nobreak">'.
1.1453 raeburn 19735: '<label>'.&mt('Type in the letters/numbers shown below').' '.
1.1463 raeburn 19736: '<input type="text" size="5" name="code" value="" autocomplete="new-password" aria-required="true" />'.
1.1453 raeburn 19737: '</label></span><br />'.
1.1176 raeburn 19738: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 19739: last;
19740: }
19741: }
1.1323 raeburn 19742: if ($output eq '') {
19743: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
19744: }
1.1094 raeburn 19745: return $output;
19746: }
19747:
19748: sub captcha_settings {
19749: my %captcha_params = (
19750: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
19751: www_output_dir => "/captchaspool",
19752: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
19753: numchars => '5',
19754: );
19755: return %captcha_params;
19756: }
19757:
19758: sub check_captcha {
19759: my ($captcha_chk,$captcha_error);
19760: my $code = $env{'form.code'};
19761: my $md5sum = $env{'form.crypt'};
19762: my %captcha_params = &captcha_settings();
19763: my $captcha = Authen::Captcha->new(
19764: output_folder => $captcha_params{'output_dir'},
19765: data_folder => $captcha_params{'db_dir'},
19766: );
1.1109 raeburn 19767: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 19768: my %captcha_hash = (
19769: 0 => 'Code not checked (file error)',
19770: -1 => 'Failed: code expired',
19771: -2 => 'Failed: invalid code (not in database)',
19772: -3 => 'Failed: invalid code (code does not match crypt)',
19773: );
19774: if ($captcha_chk != 1) {
19775: $captcha_error = $captcha_hash{$captcha_chk}
19776: }
19777: return ($captcha_chk,$captcha_error);
19778: }
19779:
19780: sub create_recaptcha {
1.1234 raeburn 19781: my ($pubkey,$version) = @_;
19782: if ($version >= 2) {
1.1367 raeburn 19783: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
19784: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1234 raeburn 19785: } else {
19786: my $use_ssl;
19787: if ($ENV{'SERVER_PORT'} == 443) {
19788: $use_ssl = 1;
19789: }
19790: my $captcha = Captcha::reCAPTCHA->new;
19791: return $captcha->get_options_setter({theme => 'white'})."\n".
19792: $captcha->get_html($pubkey,undef,$use_ssl).
19793: &mt('If the text is hard to read, [_1] will replace them.',
19794: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
19795: '<br /><br />';
19796: }
1.1094 raeburn 19797: }
19798:
19799: sub check_recaptcha {
1.1234 raeburn 19800: my ($privkey,$version) = @_;
1.1094 raeburn 19801: my $captcha_chk;
1.1350 raeburn 19802: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 19803: if ($version >= 2) {
19804: my %info = (
19805: secret => $privkey,
19806: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 19807: remoteip => $ip,
1.1234 raeburn 19808: );
1.1280 raeburn 19809: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
19810: $request->content(join('&',map {
19811: my $name = escape($_);
19812: "$name=" . ( ref($info{$_}) eq 'ARRAY'
19813: ? join("&$name=", map {escape($_) } @{$info{$_}})
19814: : &escape($info{$_}) );
19815: } keys(%info)));
19816: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 19817: if ($response->is_success) {
19818: my $data = JSON::DWIW->from_json($response->decoded_content);
19819: if (ref($data) eq 'HASH') {
19820: if ($data->{'success'}) {
19821: $captcha_chk = 1;
19822: }
19823: }
19824: }
19825: } else {
19826: my $captcha = Captcha::reCAPTCHA->new;
19827: my $captcha_result =
19828: $captcha->check_answer(
19829: $privkey,
1.1350 raeburn 19830: $ip,
1.1234 raeburn 19831: $env{'form.recaptcha_challenge_field'},
19832: $env{'form.recaptcha_response_field'},
19833: );
19834: if ($captcha_result->{is_valid}) {
19835: $captcha_chk = 1;
19836: }
1.1094 raeburn 19837: }
19838: return $captcha_chk;
19839: }
19840:
1.1174 raeburn 19841: sub emailusername_info {
1.1244 raeburn 19842: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 19843: my %titles = &Apache::lonlocal::texthash (
19844: lastname => 'Last Name',
19845: firstname => 'First Name',
19846: institution => 'School/college/university',
19847: location => "School's city, state/province, country",
19848: web => "School's web address",
19849: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 19850: id => 'Student/Employee ID',
1.1174 raeburn 19851: );
19852: return (\@fields,\%titles);
19853: }
19854:
1.1161 raeburn 19855: sub cleanup_html {
19856: my ($incoming) = @_;
19857: my $outgoing;
19858: if ($incoming ne '') {
19859: $outgoing = $incoming;
19860: $outgoing =~ s/;/;/g;
19861: $outgoing =~ s/\#/#/g;
19862: $outgoing =~ s/\&/&/g;
19863: $outgoing =~ s/</</g;
19864: $outgoing =~ s/>/>/g;
19865: $outgoing =~ s/\(/(/g;
19866: $outgoing =~ s/\)/)/g;
19867: $outgoing =~ s/"/"/g;
19868: $outgoing =~ s/'/'/g;
19869: $outgoing =~ s/\$/$/g;
19870: $outgoing =~ s{/}{/}g;
19871: $outgoing =~ s/=/=/g;
19872: $outgoing =~ s/\\/\/g
19873: }
19874: return $outgoing;
19875: }
19876:
1.1190 musolffc 19877: # Checks for critical messages and returns a redirect url if one exists.
19878: # $interval indicates how often to check for messages.
1.1282 raeburn 19879: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 19880: sub critical_redirect {
1.1282 raeburn 19881: my ($interval,$context) = @_;
1.1356 raeburn 19882: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
19883: return ();
19884: }
1.1190 musolffc 19885: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 19886: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
19887: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
19888: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 19889: my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 19890: if ($blocked) {
19891: my $checkrole = "cm./$cdom/$cnum";
19892: if ($env{'request.course.sec'} ne '') {
19893: $checkrole .= "/$env{'request.course.sec'}";
19894: }
19895: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
19896: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
19897: return;
19898: }
19899: }
19900: }
1.1190 musolffc 19901: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
19902: $env{'user.name'});
19903: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 19904: my $redirecturl;
1.1190 musolffc 19905: if ($what[0]) {
1.1356 raeburn 19906: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1190 musolffc 19907: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 19908: my $url=&Apache::lonnet::absolute_url().$redirecturl;
19909: return (1, $url);
1.1190 musolffc 19910: }
1.1191 raeburn 19911: }
19912: }
19913: return ();
1.1190 musolffc 19914: }
19915:
1.1174 raeburn 19916: # Use:
19917: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
19918: #
19919: ##################################################
19920: # password associated functions #
19921: ##################################################
19922: sub des_keys {
19923: # Make a new key for DES encryption.
19924: # Each key has two parts which are returned separately.
19925: # Please note: Each key must be passed through the &hex function
19926: # before it is output to the web browser. The hex versions cannot
19927: # be used to decrypt.
19928: my @hexstr=('0','1','2','3','4','5','6','7',
19929: '8','9','a','b','c','d','e','f');
19930: my $lkey='';
19931: for (0..7) {
19932: $lkey.=$hexstr[rand(15)];
19933: }
19934: my $ukey='';
19935: for (0..7) {
19936: $ukey.=$hexstr[rand(15)];
19937: }
19938: return ($lkey,$ukey);
19939: }
19940:
19941: sub des_decrypt {
19942: my ($key,$cyphertext) = @_;
19943: my $keybin=pack("H16",$key);
19944: my $cypher;
19945: if ($Crypt::DES::VERSION>=2.03) {
19946: $cypher=new Crypt::DES $keybin;
19947: } else {
19948: $cypher=new DES $keybin;
19949: }
1.1233 raeburn 19950: my $plaintext='';
19951: my $cypherlength = length($cyphertext);
19952: my $numchunks = int($cypherlength/32);
19953: for (my $j=0; $j<$numchunks; $j++) {
19954: my $start = $j*32;
19955: my $cypherblock = substr($cyphertext,$start,32);
19956: my $chunk =
19957: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
19958: $chunk .=
19959: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
19960: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
19961: $plaintext .= $chunk;
19962: }
1.1174 raeburn 19963: return $plaintext;
19964: }
19965:
1.1344 raeburn 19966: sub get_requested_shorturls {
1.1309 raeburn 19967: my ($cdom,$cnum,$navmap) = @_;
19968: return unless (ref($navmap));
1.1344 raeburn 19969: my ($numnew,$errors);
1.1309 raeburn 19970: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
19971: if (@toshorten) {
19972: my (%maps,%resources,%titles);
19973: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
19974: 'shorturls',$cdom,$cnum);
19975: if (keys(%resources)) {
1.1344 raeburn 19976: my %tocreate;
1.1309 raeburn 19977: foreach my $item (sort {$a <=> $b} (@toshorten)) {
19978: my $symb = $resources{$item};
19979: if ($symb) {
19980: $tocreate{$cnum.'&'.$symb} = 1;
19981: }
19982: }
1.1344 raeburn 19983: if (keys(%tocreate)) {
19984: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
19985: \%tocreate);
19986: }
1.1309 raeburn 19987: }
1.1344 raeburn 19988: }
19989: return ($numnew,$errors);
19990: }
19991:
19992: sub make_short_symbs {
19993: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
19994: my ($numnew,@errors);
19995: if (ref($tocreateref) eq 'HASH') {
19996: my %tocreate = %{$tocreateref};
1.1309 raeburn 19997: if (keys(%tocreate)) {
19998: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
19999: my $su = Short::URL->new(no_vowels => 1);
20000: my $init = '';
20001: my (%newunique,%addcourse,%courseonly,%failed);
20002: # get lock on tiny db
20003: my $now = time;
1.1344 raeburn 20004: if ($lockuser eq '') {
20005: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
20006: }
1.1309 raeburn 20007: my $lockhash = {
1.1344 raeburn 20008: "lock\0$now" => $lockuser,
1.1309 raeburn 20009: };
20010: my $tries = 0;
20011: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
20012: my ($code,$error);
20013: while (($gotlock ne 'ok') && ($tries<3)) {
20014: $tries ++;
20015: sleep 1;
1.1319 raeburn 20016: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 20017: }
20018: if ($gotlock eq 'ok') {
20019: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
20020: \%addcourse,\%courseonly,\%failed);
20021: if (keys(%failed)) {
20022: my $numfailed = scalar(keys(%failed));
20023: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
20024: }
20025: if (keys(%newunique)) {
20026: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
20027: if ($putres eq 'ok') {
20028: $numnew = scalar(keys(%newunique));
20029: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
20030: unless ($newputres eq 'ok') {
20031: push(@errors,&mt('error: could not store course look-up of short URLs'));
20032: }
20033: } else {
20034: push(@errors,&mt('error: could not store unique six character URLs'));
20035: }
20036: }
20037: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
20038: unless ($dellockres eq 'ok') {
20039: push(@errors,&mt('error: could not release lockfile'));
20040: }
20041: } else {
20042: push(@errors,&mt('error: could not obtain lockfile'));
20043: }
20044: if (keys(%courseonly)) {
20045: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
20046: if ($result ne 'ok') {
20047: push(@errors,&mt('error: could not update course look-up of short URLs'));
20048: }
20049: }
20050: }
20051: }
20052: return ($numnew,\@errors);
20053: }
20054:
20055: sub shorten_symbs {
20056: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
20057: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
20058: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
20059: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
20060: my (%possibles,%collisions);
20061: foreach my $key (keys(%{$tocreate})) {
20062: my $num = String::CRC32::crc32($key);
20063: my $tiny = $su->encode($num,$init);
20064: if ($tiny) {
20065: $possibles{$tiny} = $key;
20066: }
20067: }
20068: if (!$init) {
20069: $init = 1;
20070: } else {
20071: $init ++;
20072: }
20073: if (keys(%possibles)) {
20074: my @posstiny = keys(%possibles);
20075: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
20076: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
20077: if (keys(%currtiny)) {
20078: foreach my $key (keys(%currtiny)) {
20079: next if ($currtiny{$key} eq '');
20080: if ($currtiny{$key} eq $possibles{$key}) {
20081: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
20082: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
20083: $courseonly->{$tsymb} = $key;
20084: }
20085: } else {
20086: $collisions{$possibles{$key}} = 1;
20087: }
20088: delete($possibles{$key});
20089: }
20090: }
20091: foreach my $key (keys(%possibles)) {
20092: $newunique->{$key} = $possibles{$key};
20093: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
20094: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
20095: $addcourse->{$tsymb} = $key;
20096: }
20097: }
20098: }
20099: if (keys(%collisions)) {
20100: if ($init <5) {
20101: if (!$init) {
20102: $init = 1;
20103: } else {
20104: $init ++;
20105: }
20106: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
20107: $newunique,$addcourse,$courseonly,$failed);
20108: } else {
20109: foreach my $key (keys(%collisions)) {
20110: $failed->{$key} = 1;
20111: }
20112: }
20113: }
20114: return $init;
20115: }
20116:
1.1328 raeburn 20117: sub is_nonframeable {
1.1329 raeburn 20118: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
20119: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 20120: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 20121:
20122: $remprotocol = lc($remprotocol);
20123: $remhost = lc($remhost);
20124: my $remport = 80;
20125: if ($remprotocol eq 'https') {
20126: $remport = 443;
20127: }
1.1330 raeburn 20128: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 20129: if ($cached) {
20130: unless ($nocache) {
20131: if ($result) {
20132: return 1;
20133: } else {
20134: return 0;
20135: }
20136: }
20137: }
1.1328 raeburn 20138: my $uselink;
20139: my $request = new HTTP::Request('HEAD',$url);
20140: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
20141: if ($response->is_success()) {
20142: my $secpolicy = lc($response->header('content-security-policy'));
20143: my $xframeop = lc($response->header('x-frame-options'));
20144: $secpolicy =~ s/^\s+|\s+$//g;
20145: $xframeop =~ s/^\s+|\s+$//g;
20146: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 20147: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 20148: my ($origin,$protocol,$port);
20149: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
20150: $port = $ENV{'SERVER_PORT'};
20151: } else {
20152: $port = 80;
20153: }
20154: if ($absolute eq '') {
20155: $protocol = 'http:';
20156: if ($port == 443) {
20157: $protocol = 'https:';
20158: }
20159: $origin = $protocol.'//'.lc($hostname);
20160: } else {
20161: $origin = lc($absolute);
20162: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
20163: }
20164: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
20165: my $framepolicy = $1;
20166: $framepolicy =~ s/^\s+|\s+$//g;
20167: my @policies = split(/\s+/,$framepolicy);
20168: if (@policies) {
20169: if (grep(/^\Q'none'\E$/,@policies)) {
20170: $uselink = 1;
20171: } else {
20172: $uselink = 1;
20173: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
20174: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
20175: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
20176: undef($uselink);
20177: }
20178: if ($uselink) {
20179: if (grep(/^\Q'self'\E$/,@policies)) {
20180: if (($origin ne '') && ($remotehost eq $origin)) {
20181: undef($uselink);
20182: }
20183: }
20184: }
20185: if ($uselink) {
20186: my @possok;
20187: if ($ip ne '') {
20188: push(@possok,$ip);
20189: }
20190: my $hoststr = '';
20191: foreach my $part (reverse(split(/\./,$hostname))) {
20192: if ($hoststr eq '') {
20193: $hoststr = $part;
20194: } else {
20195: $hoststr = "$part.$hoststr";
20196: }
20197: if ($hoststr eq $hostname) {
20198: push(@possok,$hostname);
20199: } else {
20200: push(@possok,"*.$hoststr");
20201: }
20202: }
20203: if (@possok) {
20204: foreach my $poss (@possok) {
20205: last if (!$uselink);
20206: foreach my $policy (@policies) {
20207: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
20208: undef($uselink);
20209: last;
20210: }
20211: }
20212: }
20213: }
20214: }
20215: }
20216: }
20217: } elsif ($xframeop ne '') {
20218: $uselink = 1;
20219: my @policies = split(/\s*,\s*/,$xframeop);
20220: if (@policies) {
20221: unless (grep(/^deny$/,@policies)) {
20222: if ($origin ne '') {
20223: if (grep(/^sameorigin$/,@policies)) {
20224: if ($remotehost eq $origin) {
20225: undef($uselink);
20226: }
20227: }
20228: if ($uselink) {
20229: foreach my $policy (@policies) {
20230: if ($policy =~ /^allow-from\s*(.+)$/) {
20231: my $allowfrom = $1;
20232: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
20233: undef($uselink);
20234: last;
20235: }
20236: }
20237: }
20238: }
20239: }
20240: }
20241: }
20242: }
20243: }
20244: }
1.1329 raeburn 20245: if ($nocache) {
20246: if ($cached) {
20247: my $devalidate;
20248: if ($uselink && !$result) {
20249: $devalidate = 1;
20250: } elsif (!$uselink && $result) {
20251: $devalidate = 1;
20252: }
20253: if ($devalidate) {
20254: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
20255: }
20256: }
20257: } else {
20258: if ($uselink) {
20259: $result = 1;
20260: } else {
20261: $result = 0;
20262: }
20263: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
20264: }
1.1328 raeburn 20265: return $uselink;
20266: }
20267:
1.1359 raeburn 20268: sub page_menu {
20269: my ($menucolls,$menunum) = @_;
20270: my %menu;
20271: foreach my $item (split(/;/,$menucolls)) {
20272: my ($num,$value) = split(/\%/,$item);
20273: if ($num eq $menunum) {
20274: my @entries = split(/\&/,$value);
20275: foreach my $entry (@entries) {
20276: my ($name,$fields) = split(/=/,$entry);
1.1368 raeburn 20277: if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
1.1359 raeburn 20278: $menu{$name} = $fields;
20279: } else {
20280: my @shown;
20281: if ($fields =~ /,/) {
20282: @shown = split(/,/,$fields);
20283: } else {
20284: @shown = ($fields);
20285: }
20286: if (@shown) {
20287: foreach my $field (@shown) {
20288: next if ($field eq '');
20289: $menu{$field} = 1;
20290: }
20291: }
20292: }
20293: }
20294: }
20295: }
20296: return %menu;
20297: }
20298:
1.112 bowersj2 20299: 1;
20300: __END__;
1.41 ng 20301:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>