Annotation of loncom/interface/loncommon.pm, revision 1.1418
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1418 ! raeburn 4: # $Id: loncommon.pm,v 1.1417 2023/11/11 23:09:23 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.1383 raeburn 64: use Apache::lonnavmaps();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1409 raeburn 74: use LONCAPA::ltiutils;
1.1280 raeburn 75: use LONCAPA::LWPReq;
1.1395 raeburn 76: use LONCAPA::map();
1.1328 raeburn 77: use HTTP::Request;
1.657 raeburn 78: use DateTime::TimeZone;
1.1241 raeburn 79: use DateTime::Locale;
1.1220 raeburn 80: use Encode();
1.1091 foxr 81: use Text::Aspell;
1.1094 raeburn 82: use Authen::Captcha;
83: use Captcha::reCAPTCHA;
1.1234 raeburn 84: use JSON::DWIW;
1.1174 raeburn 85: use Crypt::DES;
86: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 87: use MIME::Lite;
88: use MIME::Types;
1.1292 raeburn 89: use File::Copy();
1.1300 raeburn 90: use File::Path();
1.1309 raeburn 91: use String::CRC32();
92: use Short::URL();
1.117 www 93:
1.517 raeburn 94: # ---------------------------------------------- Designs
95: use vars qw(%defaultdesign);
96:
1.22 www 97: my $readit;
98:
1.517 raeburn 99:
1.157 matthew 100: ##
101: ## Global Variables
102: ##
1.46 matthew 103:
1.643 foxr 104:
105: # ----------------------------------------------- SSI with retries:
106: #
107:
108: =pod
109:
1.648 raeburn 110: =head1 Server Side include with retries:
1.643 foxr 111:
112: =over 4
113:
1.648 raeburn 114: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 115:
116: Performs an ssi with some number of retries. Retries continue either
117: until the result is ok or until the retry count supplied by the
118: caller is exhausted.
119:
120: Inputs:
1.648 raeburn 121:
122: =over 4
123:
1.643 foxr 124: resource - Identifies the resource to insert.
1.648 raeburn 125:
1.643 foxr 126: retries - Count of the number of retries allowed.
1.648 raeburn 127:
1.643 foxr 128: form - Hash that identifies the rendering options.
129:
1.648 raeburn 130: =back
131:
132: Returns:
133:
134: =over 4
135:
1.643 foxr 136: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 137:
1.643 foxr 138: response - The response from the last attempt (which may or may not have been successful.
139:
1.648 raeburn 140: =back
141:
142: =back
143:
1.643 foxr 144: =cut
145:
146: sub ssi_with_retries {
147: my ($resource, $retries, %form) = @_;
148:
149:
150: my $ok = 0; # True if we got a good response.
151: my $content;
152: my $response;
153:
154: # Try to get the ssi done. within the retries count:
155:
156: do {
157: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
158: $ok = $response->is_success;
1.650 www 159: if (!$ok) {
160: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
161: }
1.643 foxr 162: $retries--;
163: } while (!$ok && ($retries > 0));
164:
165: if (!$ok) {
166: $content = ''; # On error return an empty content.
167: }
168: return ($content, $response);
169:
170: }
171:
172:
173:
1.20 www 174: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 175: my %language;
1.124 www 176: my %supported_language;
1.1088 foxr 177: my %supported_codes;
1.1048 foxr 178: my %latex_language; # For choosing hyphenation in <transl..>
179: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 180: my %cprtag;
1.192 taceyjo1 181: my %scprtag;
1.351 www 182: my %fe; my %fd; my %fm;
1.41 ng 183: my %category_extensions;
1.12 harris41 184:
1.46 matthew 185: # ---------------------------------------------- Thesaurus variables
1.144 matthew 186: #
187: # %Keywords:
188: # A hash used by &keyword to determine if a word is considered a keyword.
189: # $thesaurus_db_file
190: # Scalar containing the full path to the thesaurus database.
1.46 matthew 191:
192: my %Keywords;
193: my $thesaurus_db_file;
194:
1.144 matthew 195: #
196: # Initialize values from language.tab, copyright.tab, filetypes.tab,
197: # thesaurus.tab, and filecategories.tab.
198: #
1.18 www 199: BEGIN {
1.46 matthew 200: # Variable initialization
201: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
202: #
1.22 www 203: unless ($readit) {
1.12 harris41 204: # ------------------------------------------------------------------- languages
205: {
1.158 raeburn 206: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
207: '/language.tab';
1.1317 raeburn 208: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 209: while (my $line = <$fh>) {
210: next if ($line=~/^\#/);
211: chomp($line);
1.1088 foxr 212: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 213: $language{$key}=$val.' - '.$enc;
214: if ($sup) {
215: $supported_language{$key}=$sup;
1.1088 foxr 216: $supported_codes{$key} = $code;
1.158 raeburn 217: }
1.1048 foxr 218: if ($latex) {
219: $latex_language_bykey{$key} = $latex;
1.1088 foxr 220: $latex_language{$code} = $latex;
1.1048 foxr 221: }
1.158 raeburn 222: }
223: close($fh);
224: }
1.12 harris41 225: }
226: # ------------------------------------------------------------------ copyrights
227: {
1.158 raeburn 228: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
229: '/copyright.tab';
1.1317 raeburn 230: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 231: while (my $line = <$fh>) {
232: next if ($line=~/^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 235: $cprtag{$key}=$val;
236: }
237: close($fh);
238: }
1.12 harris41 239: }
1.351 www 240: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 241: {
242: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
243: '/source_copyright.tab';
1.1317 raeburn 244: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 249: $scprtag{$key}=$val;
250: }
251: close($fh);
252: }
253: }
1.63 www 254:
1.517 raeburn 255: # -------------------------------------------------------------- default domain designs
1.63 www 256: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 257: my $designfile = $designdir.'/default.tab';
1.1317 raeburn 258: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 259: while (my $line = <$fh>) {
260: next if ($line =~ /^\#/);
261: chomp($line);
262: my ($key,$val)=(split(/\=/,$line));
263: if ($val) { $defaultdesign{$key}=$val; }
264: }
265: close($fh);
1.63 www 266: }
267:
1.15 harris41 268: # ------------------------------------------------------------- file categories
269: {
1.158 raeburn 270: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
271: '/filecategories.tab';
1.1317 raeburn 272: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 273: while (my $line = <$fh>) {
274: next if ($line =~ /^\#/);
275: chomp($line);
276: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 277: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 278: }
279: close($fh);
280: }
281:
1.15 harris41 282: }
1.12 harris41 283: # ------------------------------------------------------------------ file types
284: {
1.158 raeburn 285: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
286: '/filetypes.tab';
1.1317 raeburn 287: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 288: while (my $line = <$fh>) {
289: next if ($line =~ /^\#/);
290: chomp($line);
291: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 292: if ($descr ne '') {
293: $fe{$ending}=lc($emb);
294: $fd{$ending}=$descr;
1.351 www 295: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 296: }
297: }
298: close($fh);
299: }
1.12 harris41 300: }
1.22 www 301: &Apache::lonnet::logthis(
1.705 tempelho 302: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 303: $readit=1;
1.46 matthew 304: } # end of unless($readit)
1.32 matthew 305:
306: }
1.112 bowersj2 307:
1.42 matthew 308: ###############################################################
309: ## HTML and Javascript Helper Functions ##
310: ###############################################################
311:
312: =pod
313:
1.112 bowersj2 314: =head1 HTML and Javascript Functions
1.42 matthew 315:
1.112 bowersj2 316: =over 4
317:
1.648 raeburn 318: =item * &browser_and_searcher_javascript()
1.112 bowersj2 319:
320: X<browsing, javascript>X<searching, javascript>Returns a string
321: containing javascript with two functions, C<openbrowser> and
322: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
323: tags.
1.42 matthew 324:
1.648 raeburn 325: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 326:
327: inputs: formname, elementname, only, omit
328:
329: formname and elementname indicate the name of the html form and name of
330: the element that the results of the browsing selection are to be placed in.
331:
332: Specifying 'only' will restrict the browser to displaying only files
1.185 www 333: with the given extension. Can be a comma separated list.
1.42 matthew 334:
335: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 336: with the given extension. Can be a comma separated list.
1.42 matthew 337:
1.648 raeburn 338: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 339:
340: Inputs: formname, elementname
341:
342: formname and elementname specify the name of the html form and the name
343: of the element the selection from the search results will be placed in.
1.542 raeburn 344:
1.42 matthew 345: =cut
346:
347: sub browser_and_searcher_javascript {
1.199 albertel 348: my ($mode)=@_;
349: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 350: my $resurl=&escape_single(&lastresurl());
1.42 matthew 351: return <<END;
1.219 albertel 352: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 353: var editbrowser = null;
1.135 albertel 354: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 355: var url = '$resurl/?';
1.42 matthew 356: if (editbrowser == null) {
357: url += 'launch=1&';
358: }
359: url += 'catalogmode=interactive&';
1.199 albertel 360: url += 'mode=$mode&';
1.611 albertel 361: url += 'inhibitmenu=yes&';
1.42 matthew 362: url += 'form=' + formname + '&';
363: if (only != null) {
364: url += 'only=' + only + '&';
1.217 albertel 365: } else {
366: url += 'only=&';
367: }
1.42 matthew 368: if (omit != null) {
369: url += 'omit=' + omit + '&';
1.217 albertel 370: } else {
371: url += 'omit=&';
372: }
1.135 albertel 373: if (titleelement != null) {
374: url += 'titleelement=' + titleelement + '&';
1.217 albertel 375: } else {
376: url += 'titleelement=&';
377: }
1.42 matthew 378: url += 'element=' + elementname + '';
379: var title = 'Browser';
1.435 albertel 380: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 381: options += ',width=700,height=600';
382: editbrowser = open(url,title,options,'1');
383: editbrowser.focus();
384: }
385: var editsearcher;
1.135 albertel 386: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 387: var url = '/adm/searchcat?';
388: if (editsearcher == null) {
389: url += 'launch=1&';
390: }
391: url += 'catalogmode=interactive&';
1.199 albertel 392: url += 'mode=$mode&';
1.42 matthew 393: url += 'form=' + formname + '&';
1.135 albertel 394: if (titleelement != null) {
395: url += 'titleelement=' + titleelement + '&';
1.217 albertel 396: } else {
397: url += 'titleelement=&';
398: }
1.42 matthew 399: url += 'element=' + elementname + '';
400: var title = 'Search';
1.435 albertel 401: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 402: options += ',width=700,height=600';
403: editsearcher = open(url,title,options,'1');
404: editsearcher.focus();
405: }
1.219 albertel 406: // END LON-CAPA Internal -->
1.42 matthew 407: END
1.170 www 408: }
409:
410: sub lastresurl {
1.258 albertel 411: if ($env{'environment.lastresurl'}) {
412: return $env{'environment.lastresurl'}
1.170 www 413: } else {
414: return '/res';
415: }
416: }
417:
418: sub storeresurl {
419: my $resurl=&Apache::lonnet::clutter(shift);
420: unless ($resurl=~/^\/res/) { return 0; }
421: $resurl=~s/\/$//;
422: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 423: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 424: return 1;
1.42 matthew 425: }
426:
1.74 www 427: sub studentbrowser_javascript {
1.111 www 428: unless (
1.258 albertel 429: (($env{'request.course.id'}) &&
1.302 albertel 430: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
431: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
432: '/'.$env{'request.course.sec'})
433: ))
1.258 albertel 434: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 435: ) { return ''; }
1.74 www 436: return (<<'ENDSTDBRW');
1.776 bisitz 437: <script type="text/javascript" language="Javascript">
1.824 bisitz 438: // <![CDATA[
1.74 www 439: var stdeditbrowser;
1.1413 raeburn 440: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv,uident) {
1.74 www 441: var url = '/adm/pickstudent?';
442: var filter;
1.558 albertel 443: if (!ignorefilter) {
444: eval('filter=document.'+formname+'.'+uname+'.value;');
445: }
1.74 www 446: if (filter != null) {
447: if (filter != '') {
448: url += 'filter='+filter+'&';
449: }
450: }
451: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 452: '&udomelement='+udom+
453: '&clicker='+clicker;
1.111 www 454: if (roleflag) { url+="&roles=1"; }
1.1337 raeburn 455: if (courseadv == 'condition') {
456: if (document.getElementById('courseadv')) {
457: courseadv = document.getElementById('courseadv').value;
458: }
459: }
460: if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.1413 raeburn 461: if (uident !== '') { url+="&identelement="+uident; }
1.102 www 462: var title = 'Student_Browser';
1.74 www 463: var options = 'scrollbars=1,resizable=1,menubar=0';
464: options += ',width=700,height=600';
465: stdeditbrowser = open(url,title,options,'1');
466: stdeditbrowser.focus();
467: }
1.824 bisitz 468: // ]]>
1.74 www 469: </script>
470: ENDSTDBRW
471: }
1.42 matthew 472:
1.1003 www 473: sub resourcebrowser_javascript {
474: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 475: return (<<'ENDRESBRW');
1.1003 www 476: <script type="text/javascript" language="Javascript">
477: // <![CDATA[
478: var reseditbrowser;
1.1004 www 479: function openresbrowser(formname,reslink) {
1.1005 www 480: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 481: var title = 'Resource_Browser';
482: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 483: options += ',width=700,height=500';
1.1004 www 484: reseditbrowser = open(url,title,options,'1');
485: reseditbrowser.focus();
1.1003 www 486: }
487: // ]]>
488: </script>
1.1004 www 489: ENDRESBRW
1.1003 www 490: }
491:
1.74 www 492: sub selectstudent_link {
1.1413 raeburn 493: my ($form,$unameele,$udomele,$courseadv,$clickerid,$identelem)=@_;
1.999 www 494: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
495: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
496: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 497: if ($env{'request.course.id'}) {
1.302 albertel 498: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
499: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
500: '/'.$env{'request.course.sec'})) {
1.111 www 501: return '';
502: }
1.999 www 503: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1337 raeburn 504: if ($courseadv eq 'only') {
505: $callargs .= ",'',1,'$courseadv'";
506: } elsif ($courseadv eq 'none') {
507: $callargs .= ",'','','$courseadv'";
508: } elsif ($courseadv eq 'condition') {
509: $callargs .= ",'','','$courseadv'";
1.1413 raeburn 510: } elsif ($identelem ne '') {
511: $callargs .= ",'','',''";
512: }
513: if ($identelem ne '') {
514: $callargs .= ",'".&Apache::lonhtmlcommon::entity_encode($identelem)."'";
1.793 raeburn 515: }
516: return '<span class="LC_nobreak">'.
517: '<a href="javascript:openstdbrowser('.$callargs.');">'.
518: &mt('Select User').'</a></span>';
1.74 www 519: }
1.258 albertel 520: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 521: $callargs .= ",'',1";
1.793 raeburn 522: return '<span class="LC_nobreak">'.
523: '<a href="javascript:openstdbrowser('.$callargs.');">'.
524: &mt('Select User').'</a></span>';
1.111 www 525: }
526: return '';
1.91 www 527: }
528:
1.1004 www 529: sub selectresource_link {
530: my ($form,$reslink,$arg)=@_;
531:
532: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
533: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
534: unless ($env{'request.course.id'}) { return $arg; }
535: return '<span class="LC_nobreak">'.
536: '<a href="javascript:openresbrowser('.$callargs.');">'.
537: $arg.'</a></span>';
538: }
539:
540:
541:
1.653 raeburn 542: sub authorbrowser_javascript {
543: return <<"ENDAUTHORBRW";
1.776 bisitz 544: <script type="text/javascript" language="JavaScript">
1.824 bisitz 545: // <![CDATA[
1.653 raeburn 546: var stdeditbrowser;
547:
548: function openauthorbrowser(formname,udom) {
549: var url = '/adm/pickauthor?';
550: url += 'form='+formname+'&roledom='+udom;
551: var title = 'Author_Browser';
552: var options = 'scrollbars=1,resizable=1,menubar=0';
553: options += ',width=700,height=600';
554: stdeditbrowser = open(url,title,options,'1');
555: stdeditbrowser.focus();
556: }
557:
1.824 bisitz 558: // ]]>
1.653 raeburn 559: </script>
560: ENDAUTHORBRW
561: }
562:
1.91 www 563: sub coursebrowser_javascript {
1.1116 raeburn 564: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 565: $credits_element,$instcode) = @_;
1.932 raeburn 566: my $wintitle = 'Course_Browser';
1.931 raeburn 567: if ($crstype eq 'Community') {
1.932 raeburn 568: $wintitle = 'Community_Browser';
1.909 raeburn 569: }
1.876 raeburn 570: my $id_functions = &javascript_index_functions();
571: my $output = '
1.776 bisitz 572: <script type="text/javascript" language="JavaScript">
1.824 bisitz 573: // <![CDATA[
1.468 raeburn 574: var stdeditbrowser;'."\n";
1.876 raeburn 575:
576: $output .= <<"ENDSTDBRW";
1.909 raeburn 577: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 578: var url = '/adm/pickcourse?';
1.895 raeburn 579: var formid = getFormIdByName(formname);
1.876 raeburn 580: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 581: if (domainfilter != null) {
582: if (domainfilter != '') {
583: url += 'domainfilter='+domainfilter+'&';
584: }
585: }
1.91 www 586: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 587: '&cdomelement='+udom+
588: '&cnameelement='+desc;
1.468 raeburn 589: if (extra_element !=null && extra_element != '') {
1.594 raeburn 590: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 591: url += '&roleelement='+extra_element;
592: if (domainfilter == null || domainfilter == '') {
593: url += '&domainfilter='+extra_element;
594: }
1.234 raeburn 595: }
1.468 raeburn 596: else {
597: if (formname == 'portform') {
598: url += '&setroles='+extra_element;
1.800 raeburn 599: } else {
600: if (formname == 'rules') {
601: url += '&fixeddom='+extra_element;
602: }
1.468 raeburn 603: }
604: }
1.230 raeburn 605: }
1.909 raeburn 606: if (type != null && type != '') {
607: url += '&type='+type;
608: }
609: if (type_elem != null && type_elem != '') {
610: url += '&typeelement='+type_elem;
611: }
1.872 raeburn 612: if (formname == 'ccrs') {
613: var ownername = document.forms[formid].ccuname.value;
614: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 615: url += '&cloner='+ownername+':'+ownerdom;
616: if (type == 'Course') {
617: url += '&crscode='+document.forms[formid].crscode.value;
618: }
1.1221 raeburn 619: }
620: if (formname == 'requestcrs') {
621: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 622: }
1.293 raeburn 623: if (multflag !=null && multflag != '') {
624: url += '&multiple='+multflag;
625: }
1.909 raeburn 626: var title = '$wintitle';
1.91 www 627: var options = 'scrollbars=1,resizable=1,menubar=0';
628: options += ',width=700,height=600';
629: stdeditbrowser = open(url,title,options,'1');
630: stdeditbrowser.focus();
631: }
1.876 raeburn 632: $id_functions
633: ENDSTDBRW
1.1116 raeburn 634: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
635: $output .= &setsec_javascript($sec_element,$formname,$role_element,
636: $credits_element);
1.876 raeburn 637: }
638: $output .= '
639: // ]]>
640: </script>';
641: return $output;
642: }
643:
644: sub javascript_index_functions {
645: return <<"ENDJS";
646:
647: function getFormIdByName(formname) {
648: for (var i=0;i<document.forms.length;i++) {
649: if (document.forms[i].name == formname) {
650: return i;
651: }
652: }
653: return -1;
654: }
655:
656: function getIndexByName(formid,item) {
657: for (var i=0;i<document.forms[formid].elements.length;i++) {
658: if (document.forms[formid].elements[i].name == item) {
659: return i;
660: }
661: }
662: return -1;
663: }
1.468 raeburn 664:
1.876 raeburn 665: function getDomainFromSelectbox(formname,udom) {
666: var userdom;
667: var formid = getFormIdByName(formname);
668: if (formid > -1) {
669: var domid = getIndexByName(formid,udom);
670: if (domid > -1) {
671: if (document.forms[formid].elements[domid].type == 'select-one') {
672: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
673: }
674: if (document.forms[formid].elements[domid].type == 'hidden') {
675: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 676: }
677: }
678: }
1.876 raeburn 679: return userdom;
680: }
681:
682: ENDJS
1.468 raeburn 683:
1.876 raeburn 684: }
685:
1.1017 raeburn 686: sub javascript_array_indexof {
1.1018 raeburn 687: return <<ENDJS;
1.1017 raeburn 688: <script type="text/javascript" language="JavaScript">
689: // <![CDATA[
690:
691: if (!Array.prototype.indexOf) {
692: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
693: "use strict";
694: if (this === void 0 || this === null) {
695: throw new TypeError();
696: }
697: var t = Object(this);
698: var len = t.length >>> 0;
699: if (len === 0) {
700: return -1;
701: }
702: var n = 0;
703: if (arguments.length > 0) {
704: n = Number(arguments[1]);
1.1088 foxr 705: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 706: n = 0;
707: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
708: n = (n > 0 || -1) * Math.floor(Math.abs(n));
709: }
710: }
711: if (n >= len) {
712: return -1;
713: }
714: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
715: for (; k < len; k++) {
716: if (k in t && t[k] === searchElement) {
717: return k;
718: }
719: }
720: return -1;
721: }
722: }
723:
724: // ]]>
725: </script>
726:
727: ENDJS
728:
729: }
730:
1.876 raeburn 731: sub userbrowser_javascript {
732: my $id_functions = &javascript_index_functions();
733: return <<"ENDUSERBRW";
734:
1.888 raeburn 735: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 736: var url = '/adm/pickuser?';
737: var userdom = getDomainFromSelectbox(formname,udom);
738: if (userdom != null) {
739: if (userdom != '') {
740: url += 'srchdom='+userdom+'&';
741: }
742: }
743: url += 'form=' + formname + '&unameelement='+uname+
744: '&udomelement='+udom+
745: '&ulastelement='+ulast+
746: '&ufirstelement='+ufirst+
747: '&uemailelement='+uemail+
1.881 raeburn 748: '&hideudomelement='+hideudom+
749: '&coursedom='+crsdom;
1.888 raeburn 750: if ((caller != null) && (caller != undefined)) {
751: url += '&caller='+caller;
752: }
1.876 raeburn 753: var title = 'User_Browser';
754: var options = 'scrollbars=1,resizable=1,menubar=0';
755: options += ',width=700,height=600';
756: var stdeditbrowser = open(url,title,options,'1');
757: stdeditbrowser.focus();
758: }
759:
1.888 raeburn 760: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 761: var formid = getFormIdByName(formname);
762: if (formid > -1) {
1.888 raeburn 763: var unameid = getIndexByName(formid,uname);
1.876 raeburn 764: var domid = getIndexByName(formid,udom);
765: var hidedomid = getIndexByName(formid,origdom);
766: if (hidedomid > -1) {
767: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 768: var unameval = document.forms[formid].elements[unameid].value;
769: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
770: if (domid > -1) {
771: var slct = document.forms[formid].elements[domid];
772: if (slct.type == 'select-one') {
773: var i;
774: for (i=0;i<slct.length;i++) {
775: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
776: }
777: }
778: if (slct.type == 'hidden') {
779: slct.value = fixeddom;
1.876 raeburn 780: }
781: }
1.468 raeburn 782: }
783: }
784: }
1.876 raeburn 785: return;
786: }
787:
788: $id_functions
789: ENDUSERBRW
1.468 raeburn 790: }
791:
792: sub setsec_javascript {
1.1116 raeburn 793: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 794: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
795: $communityrolestr);
796: if ($role_element ne '') {
797: my @allroles = ('st','ta','ep','in','ad');
798: foreach my $crstype ('Course','Community') {
799: if ($crstype eq 'Community') {
800: foreach my $role (@allroles) {
801: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
802: }
803: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
804: } else {
805: foreach my $role (@allroles) {
806: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
807: }
808: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
809: }
810: }
811: $rolestr = '"'.join('","',@allroles).'"';
812: $courserolestr = '"'.join('","',@courserolenames).'"';
813: $communityrolestr = '"'.join('","',@communityrolenames).'"';
814: }
1.468 raeburn 815: my $setsections = qq|
816: function setSect(sectionlist) {
1.629 raeburn 817: var sectionsArray = new Array();
818: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
819: sectionsArray = sectionlist.split(",");
820: }
1.468 raeburn 821: var numSections = sectionsArray.length;
822: document.$formname.$sec_element.length = 0;
823: if (numSections == 0) {
824: document.$formname.$sec_element.multiple=false;
825: document.$formname.$sec_element.size=1;
826: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
827: } else {
828: if (numSections == 1) {
829: document.$formname.$sec_element.multiple=false;
830: document.$formname.$sec_element.size=1;
831: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
832: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
833: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
834: } else {
835: for (var i=0; i<numSections; i++) {
836: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
837: }
838: document.$formname.$sec_element.multiple=true
839: if (numSections < 3) {
840: document.$formname.$sec_element.size=numSections;
841: } else {
842: document.$formname.$sec_element.size=3;
843: }
844: document.$formname.$sec_element.options[0].selected = false
845: }
846: }
1.91 www 847: }
1.905 raeburn 848:
849: function setRole(crstype) {
1.468 raeburn 850: |;
1.905 raeburn 851: if ($role_element eq '') {
852: $setsections .= ' return;
853: }
854: ';
855: } else {
856: $setsections .= qq|
857: var elementLength = document.$formname.$role_element.length;
858: var allroles = Array($rolestr);
859: var courserolenames = Array($courserolestr);
860: var communityrolenames = Array($communityrolestr);
861: if (elementLength != undefined) {
862: if (document.$formname.$role_element.options[5].value == 'cc') {
863: if (crstype == 'Course') {
864: return;
865: } else {
866: allroles[5] = 'co';
867: for (var i=0; i<6; i++) {
868: document.$formname.$role_element.options[i].value = allroles[i];
869: document.$formname.$role_element.options[i].text = communityrolenames[i];
870: }
871: }
872: } else {
873: if (crstype == 'Community') {
874: return;
875: } else {
876: allroles[5] = 'cc';
877: for (var i=0; i<6; i++) {
878: document.$formname.$role_element.options[i].value = allroles[i];
879: document.$formname.$role_element.options[i].text = courserolenames[i];
880: }
881: }
882: }
883: }
884: return;
885: }
886: |;
887: }
1.1116 raeburn 888: if ($credits_element) {
889: $setsections .= qq|
890: function setCredits(defaultcredits) {
891: document.$formname.$credits_element.value = defaultcredits;
892: return;
893: }
894: |;
895: }
1.468 raeburn 896: return $setsections;
897: }
898:
1.91 www 899: sub selectcourse_link {
1.909 raeburn 900: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
901: $typeelement) = @_;
902: my $type = $selecttype;
1.871 raeburn 903: my $linktext = &mt('Select Course');
904: if ($selecttype eq 'Community') {
1.909 raeburn 905: $linktext = &mt('Select Community');
1.1239 raeburn 906: } elsif ($selecttype eq 'Placement') {
907: $linktext = &mt('Select Placement Test');
1.906 raeburn 908: } elsif ($selecttype eq 'Course/Community') {
909: $linktext = &mt('Select Course/Community');
1.909 raeburn 910: $type = '';
1.1019 raeburn 911: } elsif ($selecttype eq 'Select') {
912: $linktext = &mt('Select');
913: $type = '';
1.871 raeburn 914: }
1.787 bisitz 915: return '<span class="LC_nobreak">'
916: ."<a href='"
917: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
918: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 919: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 920: ."'>".$linktext.'</a>'
1.787 bisitz 921: .'</span>';
1.74 www 922: }
1.42 matthew 923:
1.653 raeburn 924: sub selectauthor_link {
925: my ($form,$udom)=@_;
926: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
927: &mt('Select Author').'</a>';
928: }
929:
1.876 raeburn 930: sub selectuser_link {
1.881 raeburn 931: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 932: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 933: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 934: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 935: ');">'.$linktext.'</a>';
1.876 raeburn 936: }
937:
1.273 raeburn 938: sub check_uncheck_jscript {
939: my $jscript = <<"ENDSCRT";
940: function checkAll(field) {
941: if (field.length > 0) {
942: for (i = 0; i < field.length; i++) {
1.1093 raeburn 943: if (!field[i].disabled) {
944: field[i].checked = true;
945: }
1.273 raeburn 946: }
947: } else {
1.1093 raeburn 948: if (!field.disabled) {
949: field.checked = true;
950: }
1.273 raeburn 951: }
952: }
953:
954: function uncheckAll(field) {
955: if (field.length > 0) {
956: for (i = 0; i < field.length; i++) {
957: field[i].checked = false ;
1.543 albertel 958: }
959: } else {
1.273 raeburn 960: field.checked = false ;
961: }
962: }
963: ENDSCRT
964: return $jscript;
965: }
966:
1.656 www 967: sub select_timezone {
1.1387 raeburn 968: my ($name,$selected,$onchange,$includeempty,$id,$disabled)=@_;
969: my $output='<select name="'.$name.'" '.$id.$onchange.$disabled.'>'."\n";
1.659 raeburn 970: if ($includeempty) {
971: $output .= '<option value=""';
972: if (($selected eq '') || ($selected eq 'local')) {
973: $output .= ' selected="selected" ';
974: }
975: $output .= '> </option>';
976: }
1.657 raeburn 977: my @timezones = DateTime::TimeZone->all_names;
978: foreach my $tzone (@timezones) {
979: $output.= '<option value="'.$tzone.'"';
980: if ($tzone eq $selected) {
981: $output.=' selected="selected"';
982: }
983: $output.=">$tzone</option>\n";
1.656 www 984: }
985: $output.="</select>";
986: return $output;
987: }
1.273 raeburn 988:
1.687 raeburn 989: sub select_datelocale {
1.1256 raeburn 990: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
991: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 992: if ($includeempty) {
993: $output .= '<option value=""';
994: if ($selected eq '') {
995: $output .= ' selected="selected" ';
996: }
997: $output .= '> </option>';
998: }
1.1241 raeburn 999: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 1000: my (@possibles,%locale_names);
1.1241 raeburn 1001: my @locales = DateTime::Locale->ids();
1002: foreach my $id (@locales) {
1003: if ($id ne '') {
1004: my ($en_terr,$native_terr);
1005: my $loc = DateTime::Locale->load($id);
1006: if (ref($loc)) {
1007: $en_terr = $loc->name();
1008: $native_terr = $loc->native_name();
1.687 raeburn 1009: if (grep(/^en$/,@languages) || !@languages) {
1010: if ($en_terr ne '') {
1011: $locale_names{$id} = '('.$en_terr.')';
1012: } elsif ($native_terr ne '') {
1013: $locale_names{$id} = $native_terr;
1014: }
1015: } else {
1016: if ($native_terr ne '') {
1017: $locale_names{$id} = $native_terr.' ';
1018: } elsif ($en_terr ne '') {
1019: $locale_names{$id} = '('.$en_terr.')';
1020: }
1021: }
1.1220 raeburn 1022: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1023: push(@possibles,$id);
1024: }
1.687 raeburn 1025: }
1026: }
1027: foreach my $item (sort(@possibles)) {
1028: $output.= '<option value="'.$item.'"';
1029: if ($item eq $selected) {
1030: $output.=' selected="selected"';
1031: }
1032: $output.=">$item";
1033: if ($locale_names{$item} ne '') {
1.1220 raeburn 1034: $output.=' '.$locale_names{$item};
1.687 raeburn 1035: }
1036: $output.="</option>\n";
1037: }
1038: $output.="</select>";
1039: return $output;
1040: }
1041:
1.792 raeburn 1042: sub select_language {
1.1256 raeburn 1043: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1044: my %langchoices;
1045: if ($includeempty) {
1.1117 raeburn 1046: %langchoices = ('' => 'No language preference');
1.792 raeburn 1047: }
1048: foreach my $id (&languageids()) {
1049: my $code = &supportedlanguagecode($id);
1050: if ($code) {
1051: $langchoices{$code} = &plainlanguagedescription($id);
1052: }
1053: }
1.1117 raeburn 1054: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1055: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1056: }
1057:
1.42 matthew 1058: =pod
1.36 matthew 1059:
1.1088 foxr 1060:
1061: =item * &list_languages()
1062:
1063: Returns an array reference that is suitable for use in language prompters.
1064: Each array element is itself a two element array. The first element
1065: is the language code. The second element a descsriptiuon of the
1066: language itself. This is suitable for use in e.g.
1067: &Apache::edit::select_arg (once dereferenced that is).
1068:
1069: =cut
1070:
1071: sub list_languages {
1072: my @lang_choices;
1073:
1074: foreach my $id (&languageids()) {
1075: my $code = &supportedlanguagecode($id);
1076: if ($code) {
1077: my $selector = $supported_codes{$id};
1078: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1079: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1080: }
1081: }
1082: return \@lang_choices;
1083: }
1084:
1085: =pod
1086:
1.648 raeburn 1087: =item * &linked_select_forms(...)
1.36 matthew 1088:
1089: linked_select_forms returns a string containing a <script></script> block
1090: and html for two <select> menus. The select menus will be linked in that
1091: changing the value of the first menu will result in new values being placed
1092: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1093: order unless a defined order is provided.
1.36 matthew 1094:
1095: linked_select_forms takes the following ordered inputs:
1096:
1097: =over 4
1098:
1.112 bowersj2 1099: =item * $formname, the name of the <form> tag
1.36 matthew 1100:
1.112 bowersj2 1101: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1102:
1.112 bowersj2 1103: =item * $firstdefault, the default value for the first menu
1.36 matthew 1104:
1.112 bowersj2 1105: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1106:
1.112 bowersj2 1107: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1108:
1.112 bowersj2 1109: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1110:
1.609 raeburn 1111: =item * $menuorder, the order of values in the first menu
1112:
1.1115 raeburn 1113: =item * $onchangefirst, additional javascript call to execute for an onchange
1114: event for the first <select> tag
1115:
1116: =item * $onchangesecond, additional javascript call to execute for an onchange
1117: event for the second <select> tag
1118:
1.1245 raeburn 1119: =item * $suffix, to differentiate separate uses of select2data javascript
1120: objects in a page.
1121:
1.41 ng 1122: =back
1123:
1.36 matthew 1124: Below is an example of such a hash. Only the 'text', 'default', and
1125: 'select2' keys must appear as stated. keys(%menu) are the possible
1126: values for the first select menu. The text that coincides with the
1.41 ng 1127: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1128: and text for the second menu are given in the hash pointed to by
1129: $menu{$choice1}->{'select2'}.
1130:
1.112 bowersj2 1131: my %menu = ( A1 => { text =>"Choice A1" ,
1132: default => "B3",
1133: select2 => {
1134: B1 => "Choice B1",
1135: B2 => "Choice B2",
1136: B3 => "Choice B3",
1137: B4 => "Choice B4"
1.609 raeburn 1138: },
1139: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1140: },
1141: A2 => { text =>"Choice A2" ,
1142: default => "C2",
1143: select2 => {
1144: C1 => "Choice C1",
1145: C2 => "Choice C2",
1146: C3 => "Choice C3"
1.609 raeburn 1147: },
1148: order => ['C2','C1','C3'],
1.112 bowersj2 1149: },
1150: A3 => { text =>"Choice A3" ,
1151: default => "D6",
1152: select2 => {
1153: D1 => "Choice D1",
1154: D2 => "Choice D2",
1155: D3 => "Choice D3",
1156: D4 => "Choice D4",
1157: D5 => "Choice D5",
1158: D6 => "Choice D6",
1159: D7 => "Choice D7"
1.609 raeburn 1160: },
1161: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1162: }
1163: );
1.36 matthew 1164:
1165: =cut
1166:
1167: sub linked_select_forms {
1168: my ($formname,
1169: $middletext,
1170: $firstdefault,
1171: $firstselectname,
1172: $secondselectname,
1.609 raeburn 1173: $hashref,
1174: $menuorder,
1.1115 raeburn 1175: $onchangefirst,
1.1245 raeburn 1176: $onchangesecond,
1177: $suffix
1.36 matthew 1178: ) = @_;
1179: my $second = "document.$formname.$secondselectname";
1180: my $first = "document.$formname.$firstselectname";
1181: # output the javascript to do the changing
1182: my $result = '';
1.776 bisitz 1183: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1184: $result.="// <![CDATA[\n";
1.1245 raeburn 1185: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1186: $" = '","';
1187: my $debug = '';
1188: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1189: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1190: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1191: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1192: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1193: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1194: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1195: @s2values = @{$hashref->{$s1}->{'order'}};
1196: }
1.36 matthew 1197: $result.="\"@s2values\");\n";
1.1245 raeburn 1198: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1199: my @s2texts;
1200: foreach my $value (@s2values) {
1.1263 raeburn 1201: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1202: }
1203: $result.="\"@s2texts\");\n";
1204: }
1205: $"=' ';
1206: $result.= <<"END";
1207:
1.1245 raeburn 1208: function select1${suffix}_changed() {
1.36 matthew 1209: // Determine new choice
1.1245 raeburn 1210: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1211: // update select2
1.1245 raeburn 1212: var values = select2data${suffix}[newvalue].values;
1213: var texts = select2data${suffix}[newvalue].texts;
1214: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1215: var i;
1216: // out with the old
1.1245 raeburn 1217: $second.options.length = 0;
1218: // in with the new
1.36 matthew 1219: for (i=0;i<values.length; i++) {
1220: $second.options[i] = new Option(values[i]);
1.143 matthew 1221: $second.options[i].value = values[i];
1.36 matthew 1222: $second.options[i].text = texts[i];
1223: if (values[i] == select2def) {
1224: $second.options[i].selected = true;
1225: }
1226: }
1227: }
1.824 bisitz 1228: // ]]>
1.36 matthew 1229: </script>
1230: END
1231: # output the initial values for the selection lists
1.1245 raeburn 1232: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1233: my @order = sort(keys(%{$hashref}));
1234: if (ref($menuorder) eq 'ARRAY') {
1235: @order = @{$menuorder};
1236: }
1237: foreach my $value (@order) {
1.36 matthew 1238: $result.=" <option value=\"$value\" ";
1.253 albertel 1239: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1240: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1241: }
1242: $result .= "</select>\n";
1.1400 raeburn 1243: my %select2;
1244: if (ref($hashref->{$firstdefault}) eq 'HASH') {
1245: if (ref($hashref->{$firstdefault}->{'select2'}) eq 'HASH') {
1246: %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1247: }
1248: }
1.36 matthew 1249: $result .= $middletext;
1.1115 raeburn 1250: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1251: if ($onchangesecond) {
1252: $result .= ' onchange="'.$onchangesecond.'"';
1253: }
1254: $result .= ">\n";
1.36 matthew 1255: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1256:
1257: my @secondorder = sort(keys(%select2));
1258: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1259: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1260: }
1261: foreach my $value (@secondorder) {
1.36 matthew 1262: $result.=" <option value=\"$value\" ";
1.253 albertel 1263: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1264: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1265: }
1266: $result .= "</select>\n";
1267: # return $debug;
1268: return $result;
1269: } # end of sub linked_select_forms {
1270:
1.45 matthew 1271: =pod
1.44 bowersj2 1272:
1.1381 raeburn 1273: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid,$links_target)
1.44 bowersj2 1274:
1.112 bowersj2 1275: Returns a string corresponding to an HTML link to the given help
1276: $topic, where $topic corresponds to the name of a .tex file in
1277: /home/httpd/html/adm/help/tex, with underscores replaced by
1278: spaces.
1279:
1280: $text will optionally be linked to the same topic, allowing you to
1281: link text in addition to the graphic. If you do not want to link
1282: text, but wish to specify one of the later parameters, pass an
1283: empty string.
1284:
1285: $stayOnPage is a value that will be interpreted as a boolean. If true,
1286: the link will not open a new window. If false, the link will open
1287: a new window using Javascript. (Default is false.)
1288:
1289: $width and $height are optional numerical parameters that will
1290: override the width and height of the popped up window, which may
1.973 raeburn 1291: be useful for certain help topics with big pictures included.
1292:
1293: $imgid is the id of the img tag used for the help icon. This may be
1294: used in a javascript call to switch the image src. See
1295: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1296:
1.1381 raeburn 1297: $links_target will optionally be set to a target (_top, _parent or _self).
1298:
1.44 bowersj2 1299: =cut
1300:
1301: sub help_open_topic {
1.1381 raeburn 1302: my ($topic, $text, $stayOnPage, $width, $height, $imgid, $links_target) = @_;
1.48 bowersj2 1303: $text = "" if (not defined $text);
1.44 bowersj2 1304: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1305: $width = 500 if (not defined $width);
1.44 bowersj2 1306: $height = 400 if (not defined $height);
1307: my $filename = $topic;
1308: $filename =~ s/ /_/g;
1309:
1.48 bowersj2 1310: my $template = "";
1311: my $link;
1.572 banghart 1312:
1.159 www 1313: $topic=~s/\W/\_/g;
1.44 bowersj2 1314:
1.572 banghart 1315: if (!$stayOnPage) {
1.1033 www 1316: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1317: } elsif ($stayOnPage eq 'popup') {
1318: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1319: } else {
1.48 bowersj2 1320: $link = "/adm/help/${filename}.hlp";
1321: }
1322:
1323: # Add the text
1.1314 raeburn 1324: my $target = ' target="_top"';
1.1381 raeburn 1325: if ($links_target) {
1326: $target = ' target="'.$links_target.'"';
1327: } elsif ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1328: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1329: $target = '';
1.1378 raeburn 1330: }
1.1380 raeburn 1331: if ($text ne "") {
1.763 bisitz 1332: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1333: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1334: .$text.'</a>';
1.48 bowersj2 1335: }
1336:
1.763 bisitz 1337: # (Always) Add the graphic
1.179 matthew 1338: my $title = &mt('Online Help');
1.667 raeburn 1339: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1340: if ($imgid ne '') {
1341: $imgid = ' id="'.$imgid.'"';
1342: }
1.1314 raeburn 1343: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1344: .'<img src="'.$helpicon.'" border="0"'
1345: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1346: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1347: .' /></a>';
1348: if ($text ne "") {
1349: $template.='</span>';
1350: }
1.44 bowersj2 1351: return $template;
1352:
1.106 bowersj2 1353: }
1354:
1355: # This is a quicky function for Latex cheatsheet editing, since it
1356: # appears in at least four places
1357: sub helpLatexCheatsheet {
1.1037 www 1358: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1359: my $out;
1.106 bowersj2 1360: my $addOther = '';
1.732 raeburn 1361: if ($topic) {
1.1037 www 1362: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1363: }
1364: $out = '<span>' # Start cheatsheet
1365: .$addOther
1366: .'<span>'
1.1037 www 1367: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1368: .'</span> <span>'
1.1037 www 1369: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1370: .'</span>';
1.732 raeburn 1371: unless ($not_author) {
1.1186 kruse 1372: $out .= '<span>'
1373: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1374: .'</span> <span>'
1375: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1376: .'</span>';
1.732 raeburn 1377: }
1.763 bisitz 1378: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1379: return $out;
1.172 www 1380: }
1381:
1.430 albertel 1382: sub general_help {
1383: my $helptopic='Student_Intro';
1384: if ($env{'request.role'}=~/^(ca|au)/) {
1385: $helptopic='Authoring_Intro';
1.907 raeburn 1386: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1387: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1388: } elsif ($env{'request.role'}=~/^dc/) {
1389: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1390: }
1391: return $helptopic;
1392: }
1393:
1394: sub update_help_link {
1395: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1396: my $origurl = $ENV{'REQUEST_URI'};
1397: $origurl=~s|^/~|/priv/|;
1398: my $timestamp = time;
1399: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1400: $$datum = &escape($$datum);
1401: }
1402:
1403: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1404: my $output .= <<"ENDOUTPUT";
1405: <script type="text/javascript">
1.824 bisitz 1406: // <![CDATA[
1.430 albertel 1407: banner_link = '$banner_link';
1.824 bisitz 1408: // ]]>
1.430 albertel 1409: </script>
1410: ENDOUTPUT
1411: return $output;
1412: }
1413:
1414: # now just updates the help link and generates a blue icon
1.193 raeburn 1415: sub help_open_menu {
1.1381 raeburn 1416: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text,$links_target)
1.552 banghart 1417: = @_;
1.949 droeschl 1418: $stayOnPage = 1;
1.430 albertel 1419: my $output;
1420: if ($component_help) {
1421: if (!$text) {
1422: $output=&help_open_topic($component_help,undef,$stayOnPage,
1.1381 raeburn 1423: $width,$height,'',$links_target);
1.430 albertel 1424: } else {
1425: my $help_text;
1426: $help_text=&unescape($topic);
1427: $output='<table><tr><td>'.
1428: &help_open_topic($component_help,$help_text,$stayOnPage,
1.1381 raeburn 1429: $width,$height,'',$links_target).'</td></tr></table>';
1.430 albertel 1430: }
1431: }
1432: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1433: return $output.$banner_link;
1434: }
1435:
1436: sub top_nav_help {
1.1369 raeburn 1437: my ($text,$linkattr) = @_;
1.436 albertel 1438: $text = &mt($text);
1.949 droeschl 1439: my $stay_on_page = 1;
1440:
1.1168 raeburn 1441: my ($link,$banner_link);
1442: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1443: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1444: : "javascript:helpMenu('open')";
1445: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1446: }
1.201 raeburn 1447: my $title = &mt('Get help');
1.1168 raeburn 1448: if ($link) {
1449: return <<"END";
1.436 albertel 1450: $banner_link
1.1369 raeburn 1451: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1452: END
1.1168 raeburn 1453: } else {
1454: return ' '.$text.' ';
1455: }
1.436 albertel 1456: }
1457:
1458: sub help_menu_js {
1.1154 raeburn 1459: my ($httphost) = @_;
1.949 droeschl 1460: my $stayOnPage = 1;
1.436 albertel 1461: my $width = 620;
1462: my $height = 600;
1.430 albertel 1463: my $helptopic=&general_help();
1.1154 raeburn 1464: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1465: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1466: my $start_page =
1467: &Apache::loncommon::start_page('Help Menu', undef,
1468: {'frameset' => 1,
1469: 'js_ready' => 1,
1.1154 raeburn 1470: 'use_absolute' => $httphost,
1.331 albertel 1471: 'add_entries' => {
1.1168 raeburn 1472: 'border' => '0',
1.579 raeburn 1473: 'rows' => "110,*",},});
1.331 albertel 1474: my $end_page =
1475: &Apache::loncommon::end_page({'frameset' => 1,
1476: 'js_ready' => 1,});
1477:
1.436 albertel 1478: my $template .= <<"ENDTEMPLATE";
1479: <script type="text/javascript">
1.877 bisitz 1480: // <![CDATA[
1.253 albertel 1481: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1482: var banner_link = '';
1.243 raeburn 1483: function helpMenu(target) {
1484: var caller = this;
1485: if (target == 'open') {
1486: var newWindow = null;
1487: try {
1.262 albertel 1488: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1489: }
1490: catch(error) {
1491: writeHelp(caller);
1492: return;
1493: }
1494: if (newWindow) {
1495: caller = newWindow;
1496: }
1.193 raeburn 1497: }
1.243 raeburn 1498: writeHelp(caller);
1499: return;
1500: }
1501: function writeHelp(caller) {
1.1168 raeburn 1502: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1503: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1504: caller.document.close();
1505: caller.focus();
1.193 raeburn 1506: }
1.877 bisitz 1507: // END LON-CAPA Internal -->
1.253 albertel 1508: // ]]>
1.436 albertel 1509: </script>
1.193 raeburn 1510: ENDTEMPLATE
1511: return $template;
1512: }
1513:
1.172 www 1514: sub help_open_bug {
1515: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1516: unless ($env{'user.adv'}) { return ''; }
1.172 www 1517: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1518: $text = "" if (not defined $text);
1519: $stayOnPage=1;
1.184 albertel 1520: $width = 600 if (not defined $width);
1521: $height = 600 if (not defined $height);
1.172 www 1522:
1523: $topic=~s/\W+/\+/g;
1524: my $link='';
1525: my $template='';
1.379 albertel 1526: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1527: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1528: if (!$stayOnPage)
1529: {
1530: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1531: }
1532: else
1533: {
1534: $link = $url;
1535: }
1.1314 raeburn 1536:
1.1382 raeburn 1537: my $target = '_top';
1538: if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1539: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1540: $target = '_blank';
1.1378 raeburn 1541: }
1.1382 raeburn 1542:
1.172 www 1543: # Add the text
1544: if ($text ne "")
1545: {
1546: $template .=
1547: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1382 raeburn 1548: "<td bgcolor='#FF5555'><a target=\"$target\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1549: }
1550:
1551: # Add the graphic
1.179 matthew 1552: my $title = &mt('Report a Bug');
1.215 albertel 1553: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1554: $template .= <<"ENDTEMPLATE";
1.1382 raeburn 1555: <a target="$target" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1556: ENDTEMPLATE
1557: if ($text ne '') { $template.='</td></tr></table>' };
1558: return $template;
1559:
1560: }
1561:
1562: sub help_open_faq {
1563: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1564: unless ($env{'user.adv'}) { return ''; }
1.172 www 1565: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1566: $text = "" if (not defined $text);
1567: $stayOnPage=1;
1568: $width = 350 if (not defined $width);
1569: $height = 400 if (not defined $height);
1570:
1571: $topic=~s/\W+/\+/g;
1572: my $link='';
1573: my $template='';
1574: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1575: if (!$stayOnPage)
1576: {
1577: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1578: }
1579: else
1580: {
1581: $link = $url;
1582: }
1583:
1584: # Add the text
1585: if ($text ne "")
1586: {
1587: $template .=
1.173 www 1588: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1589: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1590: }
1591:
1592: # Add the graphic
1.179 matthew 1593: my $title = &mt('View the FAQ');
1.215 albertel 1594: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1595: $template .= <<"ENDTEMPLATE";
1.436 albertel 1596: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1597: ENDTEMPLATE
1598: if ($text ne '') { $template.='</td></tr></table>' };
1599: return $template;
1600:
1.44 bowersj2 1601: }
1.37 matthew 1602:
1.180 matthew 1603: ###############################################################
1604: ###############################################################
1605:
1.45 matthew 1606: =pod
1607:
1.648 raeburn 1608: =item * &change_content_javascript():
1.256 matthew 1609:
1610: This and the next function allow you to create small sections of an
1611: otherwise static HTML page that you can update on the fly with
1612: Javascript, even in Netscape 4.
1613:
1614: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1615: must be written to the HTML page once. It will prove the Javascript
1616: function "change(name, content)". Calling the change function with the
1617: name of the section
1618: you want to update, matching the name passed to C<changable_area>, and
1619: the new content you want to put in there, will put the content into
1620: that area.
1621:
1622: B<Note>: Netscape 4 only reserves enough space for the changable area
1623: to contain room for the original contents. You need to "make space"
1624: for whatever changes you wish to make, and be B<sure> to check your
1625: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1626: it's adequate for updating a one-line status display, but little more.
1627: This script will set the space to 100% width, so you only need to
1628: worry about height in Netscape 4.
1629:
1630: Modern browsers are much less limiting, and if you can commit to the
1631: user not using Netscape 4, this feature may be used freely with
1632: pretty much any HTML.
1633:
1634: =cut
1635:
1636: sub change_content_javascript {
1637: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1638: if ($env{'browser.type'} eq 'netscape' &&
1639: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1640: return (<<NETSCAPE4);
1641: function change(name, content) {
1642: doc = document.layers[name+"___escape"].layers[0].document;
1643: doc.open();
1644: doc.write(content);
1645: doc.close();
1646: }
1647: NETSCAPE4
1648: } else {
1649: # Otherwise, we need to use semi-standards-compliant code
1650: # (technically, "innerHTML" isn't standard but the equivalent
1651: # is really scary, and every useful browser supports it
1652: return (<<DOMBASED);
1653: function change(name, content) {
1654: element = document.getElementById(name);
1655: element.innerHTML = content;
1656: }
1657: DOMBASED
1658: }
1659: }
1660:
1661: =pod
1662:
1.648 raeburn 1663: =item * &changable_area($name,$origContent):
1.256 matthew 1664:
1665: This provides a "changable area" that can be modified on the fly via
1666: the Javascript code provided in C<change_content_javascript>. $name is
1667: the name you will use to reference the area later; do not repeat the
1668: same name on a given HTML page more then once. $origContent is what
1669: the area will originally contain, which can be left blank.
1670:
1671: =cut
1672:
1673: sub changable_area {
1674: my ($name, $origContent) = @_;
1675:
1.258 albertel 1676: if ($env{'browser.type'} eq 'netscape' &&
1677: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1678: # If this is netscape 4, we need to use the Layer tag
1679: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1680: } else {
1681: return "<span id='$name'>$origContent</span>";
1682: }
1683: }
1684:
1685: =pod
1686:
1.648 raeburn 1687: =item * &viewport_geometry_js
1.590 raeburn 1688:
1689: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1690:
1691: =cut
1692:
1693:
1694: sub viewport_geometry_js {
1695: return <<"GEOMETRY";
1696: var Geometry = {};
1697: function init_geometry() {
1698: if (Geometry.init) { return };
1699: Geometry.init=1;
1700: if (window.innerHeight) {
1701: Geometry.getViewportHeight = function() { return window.innerHeight; };
1702: Geometry.getViewportWidth = function() { return window.innerWidth; };
1703: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1704: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1705: }
1706: else if (document.documentElement && document.documentElement.clientHeight) {
1707: Geometry.getViewportHeight =
1708: function() { return document.documentElement.clientHeight; };
1709: Geometry.getViewportWidth =
1710: function() { return document.documentElement.clientWidth; };
1711:
1712: Geometry.getHorizontalScroll =
1713: function() { return document.documentElement.scrollLeft; };
1714: Geometry.getVerticalScroll =
1715: function() { return document.documentElement.scrollTop; };
1716: }
1717: else if (document.body.clientHeight) {
1718: Geometry.getViewportHeight =
1719: function() { return document.body.clientHeight; };
1720: Geometry.getViewportWidth =
1721: function() { return document.body.clientWidth; };
1722: Geometry.getHorizontalScroll =
1723: function() { return document.body.scrollLeft; };
1724: Geometry.getVerticalScroll =
1725: function() { return document.body.scrollTop; };
1726: }
1727: }
1728:
1729: GEOMETRY
1730: }
1731:
1732: =pod
1733:
1.648 raeburn 1734: =item * &viewport_size_js()
1.590 raeburn 1735:
1736: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1737:
1738: =cut
1739:
1740: sub viewport_size_js {
1741: my $geometry = &viewport_geometry_js();
1742: return <<"DIMS";
1743:
1744: $geometry
1745:
1746: function getViewportDims(width,height) {
1747: init_geometry();
1748: width.value = Geometry.getViewportWidth();
1749: height.value = Geometry.getViewportHeight();
1750: return;
1751: }
1752:
1753: DIMS
1754: }
1755:
1756: =pod
1757:
1.648 raeburn 1758: =item * &resize_textarea_js()
1.565 albertel 1759:
1760: emits the needed javascript to resize a textarea to be as big as possible
1761:
1762: creates a function resize_textrea that takes two IDs first should be
1763: the id of the element to resize, second should be the id of a div that
1764: surrounds everything that comes after the textarea, this routine needs
1765: to be attached to the <body> for the onload and onresize events.
1766:
1.648 raeburn 1767: =back
1.565 albertel 1768:
1769: =cut
1770:
1771: sub resize_textarea_js {
1.590 raeburn 1772: my $geometry = &viewport_geometry_js();
1.565 albertel 1773: return <<"RESIZE";
1774: <script type="text/javascript">
1.824 bisitz 1775: // <![CDATA[
1.590 raeburn 1776: $geometry
1.565 albertel 1777:
1.588 albertel 1778: function getX(element) {
1779: var x = 0;
1780: while (element) {
1781: x += element.offsetLeft;
1782: element = element.offsetParent;
1783: }
1784: return x;
1785: }
1786: function getY(element) {
1787: var y = 0;
1788: while (element) {
1789: y += element.offsetTop;
1790: element = element.offsetParent;
1791: }
1792: return y;
1793: }
1794:
1795:
1.565 albertel 1796: function resize_textarea(textarea_id,bottom_id) {
1797: init_geometry();
1798: var textarea = document.getElementById(textarea_id);
1799: //alert(textarea);
1800:
1.588 albertel 1801: var textarea_top = getY(textarea);
1.565 albertel 1802: var textarea_height = textarea.offsetHeight;
1803: var bottom = document.getElementById(bottom_id);
1.588 albertel 1804: var bottom_top = getY(bottom);
1.565 albertel 1805: var bottom_height = bottom.offsetHeight;
1806: var window_height = Geometry.getViewportHeight();
1.588 albertel 1807: var fudge = 23;
1.565 albertel 1808: var new_height = window_height-fudge-textarea_top-bottom_height;
1809: if (new_height < 300) {
1810: new_height = 300;
1811: }
1812: textarea.style.height=new_height+'px';
1813: }
1.824 bisitz 1814: // ]]>
1.565 albertel 1815: </script>
1816: RESIZE
1817:
1818: }
1819:
1.1205 golterma 1820: sub colorfuleditor_js {
1.1248 raeburn 1821: my $browse_or_search;
1822: my $respath;
1823: my ($cnum,$cdom) = &crsauthor_url();
1824: if ($cnum) {
1825: $respath = "/res/$cdom/$cnum/";
1826: my %js_lt = &Apache::lonlocal::texthash(
1827: sunm => 'Sub-directory name',
1828: save => 'Save page to make this permanent',
1829: );
1830: &js_escape(\%js_lt);
1.1400 raeburn 1831: my $showfile_js = &show_crsfiles_js();
1.1248 raeburn 1832: $browse_or_search = <<"END";
1833:
1.1400 raeburn 1834: $showfile_js
1835:
1.1248 raeburn 1836: function toggleChooser(form,element,titleid,only,search) {
1837: var disp = 'none';
1838: if (document.getElementById('chooser_'+element)) {
1839: var curr = document.getElementById('chooser_'+element).style.display;
1840: if (curr == 'none') {
1841: disp='inline';
1842: if (form.elements['chooser_'+element].length) {
1843: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1844: form.elements['chooser_'+element][i].checked = false;
1845: }
1846: }
1847: toggleResImport(form,element);
1848: }
1849: document.getElementById('chooser_'+element).style.display = disp;
1.1400 raeburn 1850: var dirsel = '';
1851: var filesel = '';
1852: if (document.getElementById('chooser_'+element+'_crsres')) {
1853: var currcrsres = document.getElementById('chooser_'+element+'_crsres').style.display;
1854: if (currcrsres == 'none') {
1855: dirsel = 'coursepath_'+element;
1856: var filesel = 'coursefile_'+element;
1857: var include;
1858: if (document.getElementById('crsres_include_'+element)) {
1859: include = document.getElementById('crsres_include_'+element).value;
1860: }
1.1402 raeburn 1861: populateCrsSelects(form,dirsel,filesel,1,include,1,0,1,1,0);
1.1400 raeburn 1862: }
1863: }
1864: if (document.getElementById('chooser_'+element+'_upload')) {
1865: var currcrsupload = document.getElementById('chooser_'+element+'_upload').style.display;
1866: if (currcrsupload == 'none') {
1867: dirsel = 'crsauthorpath_'+element;
1868: filesel = '';
1.1402 raeburn 1869: populateCrsSelects(form,dirsel,filesel,0,'',1,0,1,0,1);
1.1400 raeburn 1870: }
1871: }
1.1248 raeburn 1872: }
1873: }
1874:
1.1400 raeburn 1875: function toggleCrsFile(form,element) {
1.1248 raeburn 1876: if (document.getElementById('chooser_'+element+'_crsres')) {
1877: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1878: if (curr == 'none') {
1.1400 raeburn 1879: if (document.getElementById('coursepath_'+element)) {
1880: var numdirs;
1881: if (document.getElementById('coursepath_'+element).length) {
1882: numdirs = document.getElementById('coursepath_'+element).length;
1883: }
1.1402 raeburn 1884: if ((document.getElementById('hascrsres_'+element)) &&
1885: (document.getElementById('nocrsres_'+element))) {
1886: if (numdirs) {
1887: document.getElementById('hascrsres_'+element).style.display='inline-block';
1888: document.getElementById('nocrsres_'+element).style.display='none';
1889: } else {
1890: document.getElementById('hascrsres_'+element).style.display='none';
1891: document.getElementById('nocrsres_'+element).style.display='inline-block';
1892: }
1893: }
1.1248 raeburn 1894: form.elements['coursepath_'+element].selectedIndex = 0;
1895: if (numdirs > 1) {
1.1400 raeburn 1896: var selelem = form.elements['coursefile_'+element];
1897: var i, len = selelem.options.length -1;
1898: if (len >=0) {
1899: for (i = len; i >= 0; i--) {
1900: selelem.remove(i);
1901: }
1902: selelem.options[0] = new Option('','');
1903: }
1.1248 raeburn 1904: }
1905: }
1.1400 raeburn 1906: }
1.1248 raeburn 1907: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1908: }
1909: if (document.getElementById('chooser_'+element+'_upload')) {
1910: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1911: if (document.getElementById('uploadcrsres_'+element)) {
1912: document.getElementById('uploadcrsres_'+element).value = '';
1913: }
1914: }
1915: return;
1916: }
1917:
1.1400 raeburn 1918: function toggleCrsUpload(form,element) {
1.1248 raeburn 1919: if (document.getElementById('chooser_'+element+'_crsres')) {
1920: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1921: }
1922: if (document.getElementById('chooser_'+element+'_upload')) {
1923: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1924: if (curr == 'none') {
1.1400 raeburn 1925: form.elements['newsubdir_'+element][0].checked = true;
1926: toggleNewsubdir(form,element);
1927: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1928: if (document.getElementById('uploadcrsres_'+element)) {
1929: document.getElementById('uploadcrsres_'+element).value = '';
1.1248 raeburn 1930: }
1931: }
1932: }
1933: return;
1934: }
1935:
1936: function toggleResImport(form,element) {
1937: var choices = new Array('crsres','upload');
1938: for (var i=0; i<choices.length; i++) {
1939: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1940: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1941: }
1942: }
1943: }
1944:
1945: function toggleNewsubdir(form,element) {
1946: var newsub = form.elements['newsubdir_'+element];
1947: if (newsub) {
1948: if (newsub.length) {
1949: for (var j=0; j<newsub.length; j++) {
1950: if (newsub[j].checked) {
1951: if (document.getElementById('newsubdirname_'+element)) {
1952: if (newsub[j].value == '1') {
1953: document.getElementById('newsubdirname_'+element).type = "text";
1954: if (document.getElementById('newsubdir_'+element)) {
1955: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1956: }
1957: } else {
1958: document.getElementById('newsubdirname_'+element).type = "hidden";
1959: document.getElementById('newsubdirname_'+element).value = "";
1960: document.getElementById('newsubdir_'+element).innerHTML = "";
1961: }
1962: }
1963: break;
1964: }
1965: }
1966: }
1967: }
1968: }
1969:
1970: function updateCrsFile(form,element) {
1971: var directory = form.elements['coursepath_'+element];
1972: var filename = form.elements['coursefile_'+element];
1973: var path = directory.options[directory.selectedIndex].value;
1974: var file = filename.options[filename.selectedIndex].value;
1.1400 raeburn 1975: if (file != '') {
1976: form.elements[element].value = '$respath';
1977: if (path == '/') {
1978: form.elements[element].value += file;
1979: } else {
1980: form.elements[element].value += path+'/'+file;
1981: }
1982: unClean();
1983: if (document.getElementById('previewimg_'+element)) {
1984: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1985: var newsrc = document.getElementById('previewimg_'+element).src;
1986: }
1987: if (document.getElementById('showimg_'+element)) {
1988: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1989: }
1.1248 raeburn 1990: }
1991: toggleChooser(form,element);
1992: return;
1993: }
1994:
1995: function uploadDone(suffix,name) {
1996: if (name) {
1997: document.forms["lonhomework"].elements[suffix].value = name;
1998: unClean();
1999: toggleChooser(document.forms["lonhomework"],suffix);
2000: }
2001: }
2002:
2003: \$(document).ready(function(){
2004:
2005: \$(document).delegate('form :submit', 'click', function( event ) {
2006: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
2007: var buttonId = this.id;
2008: var suffix = buttonId.toString();
2009: suffix = suffix.replace(/^crsupload_/,'');
2010: event.preventDefault();
2011: document.lonhomework.target = 'crsupload_target_'+suffix;
2012: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
2013: \$(this.form).submit();
2014: document.lonhomework.target = '';
2015: if (document.getElementById('crsuploadto_'+suffix)) {
2016: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
2017: }
2018: return false;
2019: }
2020: });
2021: });
2022: END
2023: }
1.1205 golterma 2024: return <<"COLORFULEDIT"
2025: <script type="text/javascript">
2026: // <![CDATA[>
2027: function fold_box(curDepth, lastresource){
2028:
2029: // we need a list because there can be several blocks you need to fold in one tag
2030: var block = document.getElementsByName('foldblock_'+curDepth);
2031: // but there is only one folding button per tag
2032: var foldbutton = document.getElementById('folding_btn_'+curDepth);
2033:
2034: if(block.item(0).style.display == 'none'){
2035:
2036: foldbutton.value = '@{[&mt("Hide")]}';
2037: for (i = 0; i < block.length; i++){
2038: block.item(i).style.display = '';
2039: }
2040: }else{
2041:
2042: foldbutton.value = '@{[&mt("Show")]}';
2043: for (i = 0; i < block.length; i++){
2044: // block.item(i).style.visibility = 'collapse';
2045: block.item(i).style.display = 'none';
2046: }
2047: };
2048: saveState(lastresource);
2049: }
2050:
2051: function saveState (lastresource) {
2052:
2053: var tag_list = getTagList();
2054: if(tag_list != null){
2055: var timestamp = new Date().getTime();
2056: var key = lastresource;
2057:
2058: // the value pattern is: 'time;key1,value1;key2,value2; ... '
2059: // starting with timestamp
2060: var value = timestamp+';';
2061:
2062: // building the list of key-value pairs
2063: for(var i = 0; i < tag_list.length; i++){
2064: value += tag_list[i]+',';
2065: value += document.getElementsByName(tag_list[i])[0].style.display+';';
2066: }
2067:
2068: // only iterate whole storage if nothing to override
2069: if(localStorage.getItem(key) == null){
2070:
2071: // prevent storage from growing large
2072: if(localStorage.length > 50){
2073: var regex_getTimestamp = /^(?:\d)+;/;
2074: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2075: var oldest_key;
2076:
2077: for(var i = 1; i < localStorage.length; i++){
2078: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2079: oldest_key = localStorage.key(i);
2080: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2081: }
2082: }
2083: localStorage.removeItem(oldest_key);
2084: }
2085: }
2086: localStorage.setItem(key,value);
2087: }
2088: }
2089:
2090: // restore folding status of blocks (on page load)
2091: function restoreState (lastresource) {
2092: if(localStorage.getItem(lastresource) != null){
2093: var key = lastresource;
2094: var value = localStorage.getItem(key);
2095: var regex_delTimestamp = /^\d+;/;
2096:
2097: value.replace(regex_delTimestamp, '');
2098:
2099: var valueArr = value.split(';');
2100: var pairs;
2101: var elements;
2102: for (var i = 0; i < valueArr.length; i++){
2103: pairs = valueArr[i].split(',');
2104: elements = document.getElementsByName(pairs[0]);
2105:
2106: for (var j = 0; j < elements.length; j++){
2107: elements[j].style.display = pairs[1];
2108: if (pairs[1] == "none"){
2109: var regex_id = /([_\\d]+)\$/;
2110: regex_id.exec(pairs[0]);
2111: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2112: }
2113: }
2114: }
2115: }
2116: }
2117:
2118: function getTagList () {
2119:
2120: var stringToSearch = document.lonhomework.innerHTML;
2121:
2122: var ret = new Array();
2123: var regex_findBlock = /(foldblock_.*?)"/g;
2124: var tag_list = stringToSearch.match(regex_findBlock);
2125:
2126: if(tag_list != null){
2127: for(var i = 0; i < tag_list.length; i++){
2128: ret.push(tag_list[i].replace(/"/, ''));
2129: }
2130: }
2131: return ret;
2132: }
2133:
2134: function saveScrollPosition (resource) {
2135: var tag_list = getTagList();
2136:
2137: // we dont always want to jump to the first block
2138: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2139: if(\$(window).scrollTop() > 170){
2140: if(tag_list != null){
2141: var result;
2142: for(var i = 0; i < tag_list.length; i++){
2143: if(isElementInViewport(tag_list[i])){
2144: result += tag_list[i]+';';
2145: }
2146: }
2147: sessionStorage.setItem('anchor_'+resource, result);
2148: }
2149: } else {
2150: // we dont need to save zero, just delete the item to leave everything tidy
2151: sessionStorage.removeItem('anchor_'+resource);
2152: }
2153: }
2154:
2155: function restoreScrollPosition(resource){
2156:
2157: var elem = sessionStorage.getItem('anchor_'+resource);
2158: if(elem != null){
2159: var tag_list = elem.split(';');
2160: var elem_list;
2161:
2162: for(var i = 0; i < tag_list.length; i++){
2163: elem_list = document.getElementsByName(tag_list[i]);
2164:
2165: if(elem_list.length > 0){
2166: elem = elem_list[0];
2167: break;
2168: }
2169: }
2170: elem.scrollIntoView();
2171: }
2172: }
2173:
2174: function isElementInViewport(el) {
2175:
2176: // change to last element instead of first
2177: var elem = document.getElementsByName(el);
2178: var rect = elem[0].getBoundingClientRect();
2179:
2180: return (
2181: rect.top >= 0 &&
2182: rect.left >= 0 &&
2183: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2184: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2185: );
2186: }
2187:
2188: function autosize(depth){
2189: var cmInst = window['cm'+depth];
2190: var fitsizeButton = document.getElementById('fitsize'+depth);
2191:
2192: // is fixed size, switching to dynamic
2193: if (sessionStorage.getItem("autosized_"+depth) == null) {
2194: cmInst.setSize("","auto");
2195: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2196: sessionStorage.setItem("autosized_"+depth, "yes");
2197:
2198: // is dynamic size, switching to fixed
2199: } else {
2200: cmInst.setSize("","300px");
2201: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2202: sessionStorage.removeItem("autosized_"+depth);
2203: }
2204: }
2205:
1.1248 raeburn 2206: $browse_or_search
1.1205 golterma 2207:
2208: // ]]>
2209: </script>
2210: COLORFULEDIT
2211: }
2212:
2213: sub xmleditor_js {
2214: return <<XMLEDIT
2215: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2216: <script type="text/javascript">
2217: // <![CDATA[>
2218:
2219: function saveScrollPosition (resource) {
2220:
2221: var scrollPos = \$(window).scrollTop();
2222: sessionStorage.setItem(resource,scrollPos);
2223: }
2224:
2225: function restoreScrollPosition(resource){
2226:
2227: var scrollPos = sessionStorage.getItem(resource);
2228: \$(window).scrollTop(scrollPos);
2229: }
2230:
2231: // unless internet explorer
2232: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2233:
2234: \$(document).ready(function() {
2235: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2236: });
2237: }
2238:
2239: // inserts text at cursor position into codemirror (xml editor only)
2240: function insertText(text){
2241: cm.focus();
2242: var curPos = cm.getCursor();
2243: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2244: }
2245: // ]]>
2246: </script>
2247: XMLEDIT
2248: }
2249:
2250: sub insert_folding_button {
2251: my $curDepth = $Apache::lonxml::curdepth;
2252: my $lastresource = $env{'request.ambiguous'};
2253:
2254: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2255: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2256: }
2257:
1.1248 raeburn 2258: sub crsauthor_url {
2259: my ($url) = @_;
2260: if ($url eq '') {
2261: $url = $ENV{'REQUEST_URI'};
2262: }
2263: my ($cnum,$cdom);
2264: if ($env{'request.course.id'}) {
2265: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2266: if ($audom ne '' && $auname ne '') {
2267: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2268: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2269: $cnum = $auname;
2270: $cdom = $audom;
2271: }
2272: }
2273: }
2274: return ($cnum,$cdom);
2275: }
2276:
2277: sub import_crsauthor_form {
1.1400 raeburn 2278: my ($firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2279: return (0) unless ($env{'request.course.id'});
2280: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2281: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2282: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2283: return (0) unless (($cnum ne '') && ($cdom ne ''));
2284: my @ids=&Apache::lonnet::current_machine_ids();
1.1400 raeburn 2285: my ($output,$is_home,$toppath,%subdirs,%files,%selimport_menus,$include,$exclude);
1.1402 raeburn 2286:
1.1248 raeburn 2287: if (grep(/^\Q$crshome\E$/,@ids)) {
2288: $is_home = 1;
2289: }
1.1400 raeburn 2290: $toppath = "/priv/$cdom/$cnum";
2291: my $nonemptydir = 1;
2292: my $js_only;
2293: if ($only) {
2294: map { $include->{$_} = 1; } split(/\s*,\s*/,$only);
2295: $js_only = join(',',map { &js_escape($_); } sort(keys(%{$include})));
2296: }
2297: $exclude = &Apache::lonnet::priv_exclude();
1.1402 raeburn 2298: &Apache::lonnet::recursedirs($is_home,1,$include,$exclude,1,0,$toppath,'',\%subdirs,\%files);
1.1400 raeburn 2299: my $numdirs = scalar(keys(%files));
1.1248 raeburn 2300: my %lt = &Apache::lonlocal::texthash (
2301: fnam => 'Filename',
2302: dire => 'Directory',
1.1400 raeburn 2303: se => 'Select',
1.1248 raeburn 2304: );
1.1402 raeburn 2305: $output = $lt{'dire'}.': '.
1.1400 raeburn 2306: '<select id="'.$firstselectname.'" name="'.$firstselectname.'" '.
1.1402 raeburn 2307: 'onchange="populateCrsSelects(this.form,'."'$firstselectname','$secondselectname',1,'$js_only',0,1,0,0,0".');">'.
1.1400 raeburn 2308: '<option value="" selected="selected">'.$lt{'se'}.'</option>';
1.1402 raeburn 2309: if ($files{'/'}) {
2310: $output .= '<option value="/">/</option>'."\n";
2311: }
1.1400 raeburn 2312: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
1.1402 raeburn 2313: next if ($key eq '/');
1.1400 raeburn 2314: $output .= '<option value="'.$key.'">'.$key.'</option>'."\n";
2315: }
2316: $output .= '</select><br />'."\n".
1.1402 raeburn 2317: $lt{'fnam'}.': <select id="'.$secondselectname.'" name="'.$secondselectname.'">'."\n".
1.1400 raeburn 2318: '<option value="" selected="selected"></option>'."\n".
1.1402 raeburn 2319: '</select>'."\n".
2320: '<input type="hidden" id="crsres_include_'.$suffix.'" value="'.$only.'" />';
1.1400 raeburn 2321: return ($numdirs,$output);
2322: }
2323:
2324: sub show_crsfiles_js {
2325: my $excluderef = &Apache::lonnet::priv_exclude();
2326: my $se = &js_escape(&mt('Select'));
2327: my $exclude;
2328: if (ref($excluderef) eq 'HASH') {
2329: $exclude = join(',', map { &js_escape($_); } sort(keys(%{$excluderef})));
2330: }
2331: my $js = <<"END";
2332:
2333:
1.1402 raeburn 2334: function populateCrsSelects (form,dirsel,filesel,exc,include,setdir,setfile,recurse,nonemptydir,addtopdir) {
1.1400 raeburn 2335: var relpath = '';
2336: if ((setfile) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2337: var currdir = form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value;
2338: if (currdir == '') {
2339: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2340: selelem = form.elements[filesel];
2341: var j, numfiles = selelem.options.length -1;
2342: if (numfiles >=0) {
2343: for (j = numfiles; j >= 0; j--) {
2344: selelem.remove(j);
2345: }
2346: }
2347: if (selelem.options.length == 0) {
2348: selelem.options[selelem.options.length] = new Option('','');
2349: selelem.selectedIndex = 0;
1.1248 raeburn 2350: }
2351: }
1.1400 raeburn 2352: return;
2353: } else {
2354: relpath = encodeURIComponent(form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value);
1.1248 raeburn 2355: }
2356: }
1.1400 raeburn 2357: var http = new XMLHttpRequest();
2358: var url = "/adm/courseauthor";
2359: var crsrole = "$env{'request.role'}";
2360: var exclude = '';
2361: if (exc) {
2362: exclude = '$exclude';
2363: }
1.1402 raeburn 2364: var params = "role=course&files=1&rec="+recurse+"&nonempty="+nonemptydir+"&exc="+exclude+"&inc="+include+"&addtop="+addtopdir+"&path="+relpath;
1.1400 raeburn 2365: http.open("POST", url, true);
2366: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
2367: http.onreadystatechange = function() {
2368: if (http.readyState == 4 && http.status == 200) {
2369: var data = JSON.parse(http.responseText);
2370: var selelem;
2371: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2372: if (Array.isArray(data.dirs)) {
2373: selelem = form.elements[dirsel];
2374: var i, numdirs = selelem.options.length -1;
2375: if (numdirs >=0) {
2376: for (i = numdirs; i >= 0; i--) {
2377: selelem.remove(i);
2378: }
2379: }
2380: var len = data.dirs.length;
2381: if (len) {
1.1402 raeburn 2382: selelem.options[selelem.options.length] = new Option('$se','');
1.1400 raeburn 2383: var j;
2384: for (j = 0; j < len; j++) {
2385: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
2386: }
2387: selelem.selectedIndex = 0;
2388: }
2389: if (!setfile) {
2390: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2391: selelem = form.elements[filesel];
2392: var j, numfiles = selelem.options.length -1;
2393: if (numfiles >=0) {
2394: for (j = numfiles; j >= 0; j--) {
2395: selelem.remove(j);
2396: }
2397: }
2398: if (selelem.options.length == 0) {
2399: selelem.options[selelem.options.length] = new Option('','');
2400: selelem.selectedIndex = 0;
2401: }
2402: }
2403: }
2404: }
2405: }
2406: if ((setfile) && (filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2407: selelem = form.elements[filesel];
2408: var i, numfiles = selelem.options.length -1;
2409: if (numfiles >=0) {
2410: for (i = numfiles; i >= 0; i--) {
2411: selelem.remove(i);
2412: }
2413: }
2414: var x;
2415: for (x in data.files) {
2416: if (Array.isArray(data.files[x])) {
2417: if (data.files[x].length > 1) {
2418: selelem.options[selelem.options.length] = new Option('$se','');
2419: }
2420: var len = data.files[x].length;
2421: if (len) {
2422: var k;
2423: for (k = 0; k < len; k++) {
2424: selelem.options[selelem.options.length] = new Option(data.files[x][k],data.files[x][k]);
2425: }
2426: selelem.selectedIndex = 0;
2427: }
2428: }
2429: }
2430: if (selelem.options.length == 0) {
2431: selelem.options[selelem.options.length] = new Option('','');
2432: selelem.selectedIndex = 0;
2433: }
1.1248 raeburn 2434: }
2435: }
2436: }
1.1400 raeburn 2437: http.send(params);
1.1248 raeburn 2438: }
1.1400 raeburn 2439: END
1.1248 raeburn 2440: }
2441:
1.565 albertel 2442: =pod
2443:
1.256 matthew 2444: =head1 Excel and CSV file utility routines
2445:
2446: =cut
2447:
2448: ###############################################################
2449: ###############################################################
2450:
2451: =pod
2452:
1.1162 raeburn 2453: =over 4
2454:
1.648 raeburn 2455: =item * &csv_translate($text)
1.37 matthew 2456:
1.185 www 2457: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2458: format.
2459:
2460: =cut
2461:
1.180 matthew 2462: ###############################################################
2463: ###############################################################
1.37 matthew 2464: sub csv_translate {
2465: my $text = shift;
2466: $text =~ s/\"/\"\"/g;
1.209 albertel 2467: $text =~ s/\n/ /g;
1.37 matthew 2468: return $text;
2469: }
1.180 matthew 2470:
2471: ###############################################################
2472: ###############################################################
2473:
2474: =pod
2475:
1.648 raeburn 2476: =item * &define_excel_formats()
1.180 matthew 2477:
2478: Define some commonly used Excel cell formats.
2479:
2480: Currently supported formats:
2481:
2482: =over 4
2483:
2484: =item header
2485:
2486: =item bold
2487:
2488: =item h1
2489:
2490: =item h2
2491:
2492: =item h3
2493:
1.256 matthew 2494: =item h4
2495:
2496: =item i
2497:
1.180 matthew 2498: =item date
2499:
2500: =back
2501:
2502: Inputs: $workbook
2503:
2504: Returns: $format, a hash reference.
2505:
1.1057 foxr 2506:
1.180 matthew 2507: =cut
2508:
2509: ###############################################################
2510: ###############################################################
2511: sub define_excel_formats {
2512: my ($workbook) = @_;
2513: my $format;
2514: $format->{'header'} = $workbook->add_format(bold => 1,
2515: bottom => 1,
2516: align => 'center');
2517: $format->{'bold'} = $workbook->add_format(bold=>1);
2518: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2519: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2520: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2521: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2522: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2523: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2524: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2525: return $format;
2526: }
2527:
2528: ###############################################################
2529: ###############################################################
1.113 bowersj2 2530:
2531: =pod
2532:
1.648 raeburn 2533: =item * &create_workbook()
1.255 matthew 2534:
2535: Create an Excel worksheet. If it fails, output message on the
2536: request object and return undefs.
2537:
2538: Inputs: Apache request object
2539:
2540: Returns (undef) on failure,
2541: Excel worksheet object, scalar with filename, and formats
2542: from &Apache::loncommon::define_excel_formats on success
2543:
2544: =cut
2545:
2546: ###############################################################
2547: ###############################################################
2548: sub create_workbook {
2549: my ($r) = @_;
2550: #
2551: # Create the excel spreadsheet
2552: my $filename = '/prtspool/'.
1.258 albertel 2553: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2554: time.'_'.rand(1000000000).'.xls';
2555: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2556: if (! defined($workbook)) {
2557: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2558: $r->print(
2559: '<p class="LC_error">'
2560: .&mt('Problems occurred in creating the new Excel file.')
2561: .' '.&mt('This error has been logged.')
2562: .' '.&mt('Please alert your LON-CAPA administrator.')
2563: .'</p>'
2564: );
1.255 matthew 2565: return (undef);
2566: }
2567: #
1.1014 foxr 2568: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2569: #
2570: my $format = &Apache::loncommon::define_excel_formats($workbook);
2571: return ($workbook,$filename,$format);
2572: }
2573:
2574: ###############################################################
2575: ###############################################################
2576:
2577: =pod
2578:
1.648 raeburn 2579: =item * &create_text_file()
1.113 bowersj2 2580:
1.542 raeburn 2581: Create a file to write to and eventually make available to the user.
1.256 matthew 2582: If file creation fails, outputs an error message on the request object and
2583: return undefs.
1.113 bowersj2 2584:
1.256 matthew 2585: Inputs: Apache request object, and file suffix
1.113 bowersj2 2586:
1.256 matthew 2587: Returns (undef) on failure,
2588: Filehandle and filename on success.
1.113 bowersj2 2589:
2590: =cut
2591:
1.256 matthew 2592: ###############################################################
2593: ###############################################################
2594: sub create_text_file {
2595: my ($r,$suffix) = @_;
2596: if (! defined($suffix)) { $suffix = 'txt'; };
2597: my $fh;
2598: my $filename = '/prtspool/'.
1.258 albertel 2599: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2600: time.'_'.rand(1000000000).'.'.$suffix;
2601: $fh = Apache::File->new('>/home/httpd'.$filename);
2602: if (! defined($fh)) {
2603: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2604: $r->print(
2605: '<p class="LC_error">'
2606: .&mt('Problems occurred in creating the output file.')
2607: .' '.&mt('This error has been logged.')
2608: .' '.&mt('Please alert your LON-CAPA administrator.')
2609: .'</p>'
2610: );
1.113 bowersj2 2611: }
1.256 matthew 2612: return ($fh,$filename)
1.113 bowersj2 2613: }
2614:
2615:
1.256 matthew 2616: =pod
1.113 bowersj2 2617:
2618: =back
2619:
2620: =cut
1.37 matthew 2621:
2622: ###############################################################
1.33 matthew 2623: ## Home server <option> list generating code ##
2624: ###############################################################
1.35 matthew 2625:
1.169 www 2626: # ------------------------------------------
2627:
2628: sub domain_select {
1.1289 raeburn 2629: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2630: my @possdoms;
2631: if (ref($incdoms) eq 'ARRAY') {
2632: @possdoms = @{$incdoms};
2633: } else {
2634: @possdoms = &Apache::lonnet::all_domains();
2635: }
2636:
1.169 www 2637: my %domains=map {
1.514 albertel 2638: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2639: } @possdoms;
2640:
2641: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2642: foreach my $dom (@{$excdoms}) {
2643: delete($domains{$dom});
2644: }
2645: }
2646:
1.169 www 2647: if ($multiple) {
2648: $domains{''}=&mt('Any domain');
1.550 albertel 2649: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2650: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2651: } else {
1.550 albertel 2652: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2653: return &select_form($name,$value,\%domains);
1.169 www 2654: }
2655: }
2656:
1.282 albertel 2657: #-------------------------------------------
2658:
2659: =pod
2660:
1.519 raeburn 2661: =head1 Routines for form select boxes
2662:
2663: =over 4
2664:
1.648 raeburn 2665: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2666:
2667: Returns a string containing a <select> element int multiple mode
2668:
2669:
2670: Args:
2671: $name - name of the <select> element
1.506 raeburn 2672: $value - scalar or array ref of values that should already be selected
1.282 albertel 2673: $size - number of rows long the select element is
1.283 albertel 2674: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2675: (shown text should already have been &mt())
1.506 raeburn 2676: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2677:
1.282 albertel 2678: =cut
2679:
2680: #-------------------------------------------
1.169 www 2681: sub multiple_select_form {
1.284 albertel 2682: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2683: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2684: my $output='';
1.191 matthew 2685: if (! defined($size)) {
2686: $size = 4;
1.283 albertel 2687: if (scalar(keys(%$hash))<4) {
2688: $size = scalar(keys(%$hash));
1.191 matthew 2689: }
2690: }
1.734 bisitz 2691: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2692: my @order;
1.506 raeburn 2693: if (ref($order) eq 'ARRAY') {
2694: @order = @{$order};
2695: } else {
2696: @order = sort(keys(%$hash));
1.501 banghart 2697: }
2698: if (exists($$hash{'select_form_order'})) {
2699: @order = @{$$hash{'select_form_order'}};
2700: }
2701:
1.284 albertel 2702: foreach my $key (@order) {
1.356 albertel 2703: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2704: $output.='selected="selected" ' if ($selected{$key});
2705: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2706: }
2707: $output.="</select>\n";
2708: return $output;
2709: }
2710:
1.88 www 2711: #-------------------------------------------
2712:
2713: =pod
2714:
1.1254 raeburn 2715: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2716:
2717: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2718: allow a user to select options from a ref to a hash containing:
2719: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2720: a javascript onchange item, e.g., onchange="this.form.submit();".
2721: An optional arg -- $readonly -- if true will cause the select form
2722: to be disabled, e.g., for the case where an instructor has a section-
2723: specific role, and is viewing/modifying parameters.
1.970 raeburn 2724:
1.88 www 2725: See lonrights.pm for an example invocation and use.
2726:
2727: =cut
2728:
2729: #-------------------------------------------
2730: sub select_form {
1.1228 raeburn 2731: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2732: return unless (ref($hashref) eq 'HASH');
2733: if ($onchange) {
2734: $onchange = ' onchange="'.$onchange.'"';
2735: }
1.1228 raeburn 2736: my $disabled;
2737: if ($readonly) {
2738: $disabled = ' disabled="disabled"';
2739: }
2740: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2741: my @keys;
1.970 raeburn 2742: if (exists($hashref->{'select_form_order'})) {
2743: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2744: } else {
1.970 raeburn 2745: @keys=sort(keys(%{$hashref}));
1.128 albertel 2746: }
1.356 albertel 2747: foreach my $key (@keys) {
2748: $selectform.=
2749: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2750: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2751: ">".$hashref->{$key}."</option>\n";
1.88 www 2752: }
2753: $selectform.="</select>";
2754: return $selectform;
2755: }
2756:
1.475 www 2757: # For display filters
2758:
2759: sub display_filter {
1.1074 raeburn 2760: my ($context) = @_;
1.475 www 2761: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2762: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2763: my $phraseinput = 'hidden';
2764: my $includeinput = 'hidden';
2765: my ($checked,$includetypestext);
2766: if ($env{'form.displayfilter'} eq 'containing') {
2767: $phraseinput = 'text';
2768: if ($context eq 'parmslog') {
2769: $includeinput = 'checkbox';
2770: if ($env{'form.includetypes'}) {
2771: $checked = ' checked="checked"';
2772: }
2773: $includetypestext = &mt('Include parameter types');
2774: }
2775: } else {
2776: $includetypestext = ' ';
2777: }
2778: my ($additional,$secondid,$thirdid);
2779: if ($context eq 'parmslog') {
2780: $additional =
2781: '<label><input type="'.$includeinput.'" name="includetypes"'.
2782: $checked.' name="includetypes" value="1" id="includetypes" />'.
2783: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2784: '</label>';
2785: $secondid = 'includetypes';
2786: $thirdid = 'includetypestext';
2787: }
2788: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2789: '$secondid','$thirdid')";
2790: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.1403 raeburn 2791: &Apache::lonmeta::selectbox('show',$env{'form.show'},'',undef,
1.475 www 2792: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2793: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2794: &mt('Filter: [_1]',
1.477 www 2795: &select_form($env{'form.displayfilter'},
2796: 'displayfilter',
1.970 raeburn 2797: {'currentfolder' => 'Current folder/page',
1.477 www 2798: 'containing' => 'Containing phrase',
1.1074 raeburn 2799: 'none' => 'None'},$onchange)).' '.
2800: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2801: &HTML::Entities::encode($env{'form.containingphrase'}).
2802: '" />'.$additional;
2803: }
2804:
2805: sub display_filter_js {
2806: my $includetext = &mt('Include parameter types');
2807: return <<"ENDJS";
2808:
2809: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2810: var firstType = 'hidden';
2811: if (setter.options[setter.selectedIndex].value == 'containing') {
2812: firstType = 'text';
2813: }
2814: firstObject = document.getElementById(firstid);
2815: if (typeof(firstObject) == 'object') {
2816: if (firstObject.type != firstType) {
2817: changeInputType(firstObject,firstType);
2818: }
2819: }
2820: if (context == 'parmslog') {
2821: var secondType = 'hidden';
2822: if (firstType == 'text') {
2823: secondType = 'checkbox';
2824: }
2825: secondObject = document.getElementById(secondid);
2826: if (typeof(secondObject) == 'object') {
2827: if (secondObject.type != secondType) {
2828: changeInputType(secondObject,secondType);
2829: }
2830: }
2831: var textItem = document.getElementById(thirdid);
2832: var currtext = textItem.innerHTML;
2833: var newtext;
2834: if (firstType == 'text') {
2835: newtext = '$includetext';
2836: } else {
2837: newtext = ' ';
2838: }
2839: if (currtext != newtext) {
2840: textItem.innerHTML = newtext;
2841: }
2842: }
2843: return;
2844: }
2845:
2846: function changeInputType(oldObject,newType) {
2847: var newObject = document.createElement('input');
2848: newObject.type = newType;
2849: if (oldObject.size) {
2850: newObject.size = oldObject.size;
2851: }
2852: if (oldObject.value) {
2853: newObject.value = oldObject.value;
2854: }
2855: if (oldObject.name) {
2856: newObject.name = oldObject.name;
2857: }
2858: if (oldObject.id) {
2859: newObject.id = oldObject.id;
2860: }
2861: oldObject.parentNode.replaceChild(newObject,oldObject);
2862: return;
2863: }
2864:
2865: ENDJS
1.475 www 2866: }
2867:
1.167 www 2868: sub gradeleveldescription {
2869: my $gradelevel=shift;
2870: my %gradelevels=(0 => 'Not specified',
2871: 1 => 'Grade 1',
2872: 2 => 'Grade 2',
2873: 3 => 'Grade 3',
2874: 4 => 'Grade 4',
2875: 5 => 'Grade 5',
2876: 6 => 'Grade 6',
2877: 7 => 'Grade 7',
2878: 8 => 'Grade 8',
2879: 9 => 'Grade 9',
2880: 10 => 'Grade 10',
2881: 11 => 'Grade 11',
2882: 12 => 'Grade 12',
2883: 13 => 'Grade 13',
2884: 14 => '100 Level',
2885: 15 => '200 Level',
2886: 16 => '300 Level',
2887: 17 => '400 Level',
2888: 18 => 'Graduate Level');
2889: return &mt($gradelevels{$gradelevel});
2890: }
2891:
1.163 www 2892: sub select_level_form {
2893: my ($deflevel,$name)=@_;
2894: unless ($deflevel) { $deflevel=0; }
1.167 www 2895: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2896: for (my $i=0; $i<=18; $i++) {
2897: $selectform.="<option value=\"$i\" ".
1.253 albertel 2898: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2899: ">".&gradeleveldescription($i)."</option>\n";
2900: }
2901: $selectform.="</select>";
2902: return $selectform;
1.163 www 2903: }
1.167 www 2904:
1.35 matthew 2905: #-------------------------------------------
2906:
1.45 matthew 2907: =pod
2908:
1.1256 raeburn 2909: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2910:
2911: Returns a string containing a <select name='$name' size='1'> form to
2912: allow a user to select the domain to preform an operation in.
2913: See loncreateuser.pm for an example invocation and use.
2914:
1.90 www 2915: If the $includeempty flag is set, it also includes an empty choice ("no domain
2916: selected");
2917:
1.743 raeburn 2918: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2919:
1.910 raeburn 2920: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
2921:
1.1121 raeburn 2922: The optional $incdoms is a reference to an array of domains which will be the only available options.
2923:
2924: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2925:
1.1256 raeburn 2926: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2927:
1.35 matthew 2928: =cut
2929:
2930: #-------------------------------------------
1.34 matthew 2931: sub select_dom_form {
1.1256 raeburn 2932: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2933: if ($onchange) {
1.874 raeburn 2934: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2935: }
1.1256 raeburn 2936: if ($disabled) {
2937: $disabled = ' disabled="disabled"';
2938: }
1.1121 raeburn 2939: my (@domains,%exclude);
1.910 raeburn 2940: if (ref($incdoms) eq 'ARRAY') {
2941: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2942: } else {
2943: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2944: }
1.90 www 2945: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2946: if (ref($excdoms) eq 'ARRAY') {
2947: map { $exclude{$_} = 1; } @{$excdoms};
2948: }
1.1256 raeburn 2949: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2950: foreach my $dom (@domains) {
1.1121 raeburn 2951: next if ($exclude{$dom});
1.356 albertel 2952: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2953: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2954: if ($showdomdesc) {
2955: if ($dom ne '') {
2956: my $domdesc = &Apache::lonnet::domain($dom,'description');
2957: if ($domdesc ne '') {
2958: $selectdomain .= ' ('.$domdesc.')';
2959: }
2960: }
2961: }
2962: $selectdomain .= "</option>\n";
1.34 matthew 2963: }
2964: $selectdomain.="</select>";
2965: return $selectdomain;
2966: }
2967:
1.35 matthew 2968: #-------------------------------------------
2969:
1.45 matthew 2970: =pod
2971:
1.648 raeburn 2972: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2973:
1.586 raeburn 2974: input: 4 arguments (two required, two optional) -
2975: $domain - domain of new user
2976: $name - name of form element
2977: $default - Value of 'default' causes a default item to be first
2978: option, and selected by default.
2979: $hide - Value of 'hide' causes hiding of the name of the server,
2980: if 1 server found, or default, if 0 found.
1.594 raeburn 2981: output: returns 2 items:
1.586 raeburn 2982: (a) form element which contains either:
2983: (i) <select name="$name">
2984: <option value="$hostid1">$hostid $servers{$hostid}</option>
2985: <option value="$hostid2">$hostid $servers{$hostid}</option>
2986: </select>
2987: form item if there are multiple library servers in $domain, or
2988: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2989: if there is only one library server in $domain.
2990:
2991: (b) number of library servers found.
2992:
2993: See loncreateuser.pm for example of use.
1.35 matthew 2994:
2995: =cut
2996:
2997: #-------------------------------------------
1.586 raeburn 2998: sub home_server_form_item {
2999: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 3000: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 3001: my $result;
3002: my $numlib = keys(%servers);
3003: if ($numlib > 1) {
3004: $result .= '<select name="'.$name.'" />'."\n";
3005: if ($default) {
1.804 bisitz 3006: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 3007: '</option>'."\n";
3008: }
3009: foreach my $hostid (sort(keys(%servers))) {
3010: $result.= '<option value="'.$hostid.'">'.
3011: $hostid.' '.$servers{$hostid}."</option>\n";
3012: }
3013: $result .= '</select>'."\n";
3014: } elsif ($numlib == 1) {
3015: my $hostid;
3016: foreach my $item (keys(%servers)) {
3017: $hostid = $item;
3018: }
3019: $result .= '<input type="hidden" name="'.$name.'" value="'.
3020: $hostid.'" />';
3021: if (!$hide) {
3022: $result .= $hostid.' '.$servers{$hostid};
3023: }
3024: $result .= "\n";
3025: } elsif ($default) {
3026: $result .= '<input type="hidden" name="'.$name.
3027: '" value="default" />';
3028: if (!$hide) {
3029: $result .= &mt('default');
3030: }
3031: $result .= "\n";
1.33 matthew 3032: }
1.586 raeburn 3033: return ($result,$numlib);
1.33 matthew 3034: }
1.112 bowersj2 3035:
3036: =pod
3037:
1.534 albertel 3038: =back
3039:
1.112 bowersj2 3040: =cut
1.87 matthew 3041:
3042: ###############################################################
1.112 bowersj2 3043: ## Decoding User Agent ##
1.87 matthew 3044: ###############################################################
3045:
3046: =pod
3047:
1.112 bowersj2 3048: =head1 Decoding the User Agent
3049:
3050: =over 4
3051:
3052: =item * &decode_user_agent()
1.87 matthew 3053:
3054: Inputs: $r
3055:
3056: Outputs:
3057:
3058: =over 4
3059:
1.112 bowersj2 3060: =item * $httpbrowser
1.87 matthew 3061:
1.112 bowersj2 3062: =item * $clientbrowser
1.87 matthew 3063:
1.112 bowersj2 3064: =item * $clientversion
1.87 matthew 3065:
1.112 bowersj2 3066: =item * $clientmathml
1.87 matthew 3067:
1.112 bowersj2 3068: =item * $clientunicode
1.87 matthew 3069:
1.112 bowersj2 3070: =item * $clientos
1.87 matthew 3071:
1.1137 raeburn 3072: =item * $clientmobile
3073:
1.1141 raeburn 3074: =item * $clientinfo
3075:
1.1194 raeburn 3076: =item * $clientosversion
3077:
1.87 matthew 3078: =back
3079:
1.157 matthew 3080: =back
3081:
1.87 matthew 3082: =cut
3083:
3084: ###############################################################
3085: ###############################################################
3086: sub decode_user_agent {
1.247 albertel 3087: my ($r)=@_;
1.87 matthew 3088: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
3089: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
3090: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 3091: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 3092: my $clientbrowser='unknown';
3093: my $clientversion='0';
3094: my $clientmathml='';
3095: my $clientunicode='0';
1.1137 raeburn 3096: my $clientmobile=0;
1.1194 raeburn 3097: my $clientosversion='';
1.87 matthew 3098: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 3099: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 3100: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
3101: $clientbrowser=$bname;
3102: $httpbrowser=~/$vreg/i;
3103: $clientversion=$1;
3104: $clientmathml=($clientversion>=$minv);
3105: $clientunicode=($clientversion>=$univ);
3106: }
3107: }
3108: my $clientos='unknown';
1.1141 raeburn 3109: my $clientinfo;
1.87 matthew 3110: if (($httpbrowser=~/linux/i) ||
3111: ($httpbrowser=~/unix/i) ||
3112: ($httpbrowser=~/ux/i) ||
3113: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
3114: if (($httpbrowser=~/vax/i) ||
3115: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
3116: if ($httpbrowser=~/next/i) { $clientos='next'; }
3117: if (($httpbrowser=~/mac/i) ||
3118: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 3119: if ($httpbrowser=~/win/i) {
3120: $clientos='win';
3121: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
3122: $clientosversion = $1;
3123: }
3124: }
1.87 matthew 3125: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 3126: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
3127: $clientmobile=lc($1);
3128: }
1.1141 raeburn 3129: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
3130: $clientinfo = 'firefox-'.$1;
3131: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3132: $clientinfo = 'chromeframe-'.$1;
3133: }
1.87 matthew 3134: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3135: $clientunicode,$clientos,$clientmobile,$clientinfo,
3136: $clientosversion);
1.87 matthew 3137: }
3138:
1.32 matthew 3139: ###############################################################
3140: ## Authentication changing form generation subroutines ##
3141: ###############################################################
3142: ##
3143: ## All of the authform_xxxxxxx subroutines take their inputs in a
3144: ## hash, and have reasonable default values.
3145: ##
3146: ## formname = the name given in the <form> tag.
1.35 matthew 3147: #-------------------------------------------
3148:
1.45 matthew 3149: =pod
3150:
1.112 bowersj2 3151: =head1 Authentication Routines
3152:
3153: =over 4
3154:
1.648 raeburn 3155: =item * &authform_xxxxxx()
1.35 matthew 3156:
3157: The authform_xxxxxx subroutines provide javascript and html forms which
3158: handle some of the conveniences required for authentication forms.
3159: This is not an optimal method, but it works.
3160:
3161: =over 4
3162:
1.112 bowersj2 3163: =item * authform_header
1.35 matthew 3164:
1.112 bowersj2 3165: =item * authform_authorwarning
1.35 matthew 3166:
1.112 bowersj2 3167: =item * authform_nochange
1.35 matthew 3168:
1.112 bowersj2 3169: =item * authform_kerberos
1.35 matthew 3170:
1.112 bowersj2 3171: =item * authform_internal
1.35 matthew 3172:
1.112 bowersj2 3173: =item * authform_filesystem
1.35 matthew 3174:
1.1310 raeburn 3175: =item * authform_lti
3176:
1.35 matthew 3177: =back
3178:
1.648 raeburn 3179: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3180:
1.35 matthew 3181: =cut
3182:
3183: #-------------------------------------------
1.32 matthew 3184: sub authform_header{
3185: my %in = (
3186: formname => 'cu',
1.80 albertel 3187: kerb_def_dom => '',
1.32 matthew 3188: @_,
3189: );
3190: $in{'formname'} = 'document.' . $in{'formname'};
3191: my $result='';
1.80 albertel 3192:
3193: #---------------------------------------------- Code for upper case translation
3194: my $Javascript_toUpperCase;
3195: unless ($in{kerb_def_dom}) {
3196: $Javascript_toUpperCase =<<"END";
3197: switch (choice) {
3198: case 'krb': currentform.elements[choicearg].value =
3199: currentform.elements[choicearg].value.toUpperCase();
3200: break;
3201: default:
3202: }
3203: END
3204: } else {
3205: $Javascript_toUpperCase = "";
3206: }
3207:
1.165 raeburn 3208: my $radioval = "'nochange'";
1.591 raeburn 3209: if (defined($in{'curr_authtype'})) {
3210: if ($in{'curr_authtype'} ne '') {
3211: $radioval = "'".$in{'curr_authtype'}."arg'";
3212: }
1.174 matthew 3213: }
1.165 raeburn 3214: my $argfield = 'null';
1.591 raeburn 3215: if (defined($in{'mode'})) {
1.165 raeburn 3216: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3217: if (defined($in{'curr_autharg'})) {
3218: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3219: $argfield = "'$in{'curr_autharg'}'";
3220: }
3221: }
3222: }
3223: }
3224:
1.32 matthew 3225: $result.=<<"END";
3226: var current = new Object();
1.165 raeburn 3227: current.radiovalue = $radioval;
3228: current.argfield = $argfield;
1.32 matthew 3229:
3230: function changed_radio(choice,currentform) {
3231: var choicearg = choice + 'arg';
3232: // If a radio button in changed, we need to change the argfield
3233: if (current.radiovalue != choice) {
3234: current.radiovalue = choice;
3235: if (current.argfield != null) {
3236: currentform.elements[current.argfield].value = '';
3237: }
3238: if (choice == 'nochange') {
3239: current.argfield = null;
3240: } else {
3241: current.argfield = choicearg;
3242: switch(choice) {
3243: case 'krb':
3244: currentform.elements[current.argfield].value =
3245: "$in{'kerb_def_dom'}";
3246: break;
3247: default:
3248: break;
3249: }
3250: }
3251: }
3252: return;
3253: }
1.22 www 3254:
1.32 matthew 3255: function changed_text(choice,currentform) {
3256: var choicearg = choice + 'arg';
3257: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3258: $Javascript_toUpperCase
1.32 matthew 3259: // clear old field
3260: if ((current.argfield != choicearg) && (current.argfield != null)) {
3261: currentform.elements[current.argfield].value = '';
3262: }
3263: current.argfield = choicearg;
3264: }
3265: set_auth_radio_buttons(choice,currentform);
3266: return;
1.20 www 3267: }
1.32 matthew 3268:
3269: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3270: var numauthchoices = currentform.login.length;
3271: if (typeof numauthchoices == "undefined") {
3272: return;
3273: }
1.32 matthew 3274: var i=0;
1.986 raeburn 3275: while (i < numauthchoices) {
1.32 matthew 3276: if (currentform.login[i].value == newvalue) { break; }
3277: i++;
3278: }
1.986 raeburn 3279: if (i == numauthchoices) {
1.32 matthew 3280: return;
3281: }
3282: current.radiovalue = newvalue;
3283: currentform.login[i].checked = true;
3284: return;
3285: }
3286: END
3287: return $result;
3288: }
3289:
1.1106 raeburn 3290: sub authform_authorwarning {
1.32 matthew 3291: my $result='';
1.144 matthew 3292: $result='<i>'.
3293: &mt('As a general rule, only authors or co-authors should be '.
3294: 'filesystem authenticated '.
3295: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3296: return $result;
3297: }
3298:
1.1106 raeburn 3299: sub authform_nochange {
1.32 matthew 3300: my %in = (
3301: formname => 'document.cu',
3302: kerb_def_dom => 'MSU.EDU',
3303: @_,
3304: );
1.1106 raeburn 3305: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3306: my $result;
1.1104 raeburn 3307: if (!$authnum) {
1.1105 raeburn 3308: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3309: } else {
3310: $result = '<label>'.&mt('[_1] Do not change login data',
3311: '<input type="radio" name="login" value="nochange" '.
3312: 'checked="checked" onclick="'.
1.281 albertel 3313: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3314: '</label>';
1.586 raeburn 3315: }
1.32 matthew 3316: return $result;
3317: }
3318:
1.591 raeburn 3319: sub authform_kerberos {
1.32 matthew 3320: my %in = (
3321: formname => 'document.cu',
3322: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3323: kerb_def_auth => 'krb4',
1.32 matthew 3324: @_,
3325: );
1.586 raeburn 3326: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3327: $autharg,$jscall,$disabled);
1.1106 raeburn 3328: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3329: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3330: $check5 = ' checked="checked"';
1.80 albertel 3331: } else {
1.772 bisitz 3332: $check4 = ' checked="checked"';
1.80 albertel 3333: }
1.1259 raeburn 3334: if ($in{'readonly'}) {
3335: $disabled = ' disabled="disabled"';
3336: }
1.165 raeburn 3337: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3338: if (defined($in{'curr_authtype'})) {
3339: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3340: $krbcheck = ' checked="checked"';
1.623 raeburn 3341: if (defined($in{'mode'})) {
3342: if ($in{'mode'} eq 'modifyuser') {
3343: $krbcheck = '';
3344: }
3345: }
1.591 raeburn 3346: if (defined($in{'curr_kerb_ver'})) {
3347: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3348: $check5 = ' checked="checked"';
1.591 raeburn 3349: $check4 = '';
3350: } else {
1.772 bisitz 3351: $check4 = ' checked="checked"';
1.591 raeburn 3352: $check5 = '';
3353: }
1.586 raeburn 3354: }
1.591 raeburn 3355: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3356: $krbarg = $in{'curr_autharg'};
3357: }
1.586 raeburn 3358: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3359: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3360: $result =
3361: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3362: $in{'curr_autharg'},$krbver);
3363: } else {
3364: $result =
3365: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3366: }
3367: return $result;
3368: }
3369: }
3370: } else {
3371: if ($authnum == 1) {
1.784 bisitz 3372: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3373: }
3374: }
1.586 raeburn 3375: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3376: return;
1.587 raeburn 3377: } elsif ($authtype eq '') {
1.591 raeburn 3378: if (defined($in{'mode'})) {
1.587 raeburn 3379: if ($in{'mode'} eq 'modifycourse') {
3380: if ($authnum == 1) {
1.1259 raeburn 3381: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3382: }
3383: }
3384: }
1.586 raeburn 3385: }
3386: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3387: if ($authtype eq '') {
3388: $authtype = '<input type="radio" name="login" value="krb" '.
3389: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3390: $krbcheck.$disabled.' />';
1.586 raeburn 3391: }
3392: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3393: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3394: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3395: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3396: $in{'curr_authtype'} eq 'krb4')) {
3397: $result .= &mt
1.144 matthew 3398: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3399: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3400: '<label>'.$authtype,
1.281 albertel 3401: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3402: 'value="'.$krbarg.'" '.
1.1259 raeburn 3403: 'onchange="'.$jscall.'"'.$disabled.' />',
3404: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3405: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3406: '</label>');
1.586 raeburn 3407: } elsif ($can_assign{'krb4'}) {
3408: $result .= &mt
3409: ('[_1] Kerberos authenticated with domain [_2] '.
3410: '[_3] Version 4 [_4]',
3411: '<label>'.$authtype,
3412: '</label><input type="text" size="10" name="krbarg" '.
3413: 'value="'.$krbarg.'" '.
1.1259 raeburn 3414: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3415: '<label><input type="hidden" name="krbver" value="4" />',
3416: '</label>');
3417: } elsif ($can_assign{'krb5'}) {
3418: $result .= &mt
3419: ('[_1] Kerberos authenticated with domain [_2] '.
3420: '[_3] Version 5 [_4]',
3421: '<label>'.$authtype,
3422: '</label><input type="text" size="10" name="krbarg" '.
3423: 'value="'.$krbarg.'" '.
1.1259 raeburn 3424: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3425: '<label><input type="hidden" name="krbver" value="5" />',
3426: '</label>');
3427: }
1.32 matthew 3428: return $result;
3429: }
3430:
1.1106 raeburn 3431: sub authform_internal {
1.586 raeburn 3432: my %in = (
1.32 matthew 3433: formname => 'document.cu',
3434: kerb_def_dom => 'MSU.EDU',
3435: @_,
3436: );
1.1259 raeburn 3437: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3438: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3439: if ($in{'readonly'}) {
3440: $disabled = ' disabled="disabled"';
3441: }
1.591 raeburn 3442: if (defined($in{'curr_authtype'})) {
3443: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3444: if ($can_assign{'int'}) {
1.772 bisitz 3445: $intcheck = 'checked="checked" ';
1.623 raeburn 3446: if (defined($in{'mode'})) {
3447: if ($in{'mode'} eq 'modifyuser') {
3448: $intcheck = '';
3449: }
3450: }
1.591 raeburn 3451: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3452: $intarg = $in{'curr_autharg'};
3453: }
3454: } else {
3455: $result = &mt('Currently internally authenticated.');
3456: return $result;
1.165 raeburn 3457: }
3458: }
1.586 raeburn 3459: } else {
3460: if ($authnum == 1) {
1.784 bisitz 3461: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3462: }
3463: }
3464: if (!$can_assign{'int'}) {
3465: return;
1.587 raeburn 3466: } elsif ($authtype eq '') {
1.591 raeburn 3467: if (defined($in{'mode'})) {
1.587 raeburn 3468: if ($in{'mode'} eq 'modifycourse') {
3469: if ($authnum == 1) {
1.1259 raeburn 3470: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3471: }
3472: }
3473: }
1.165 raeburn 3474: }
1.586 raeburn 3475: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3476: if ($authtype eq '') {
3477: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3478: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3479: }
1.605 bisitz 3480: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3481: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3482: $result = &mt
1.144 matthew 3483: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3484: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3485: $result.='<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>';
1.32 matthew 3486: return $result;
3487: }
3488:
1.1104 raeburn 3489: sub authform_local {
1.32 matthew 3490: my %in = (
3491: formname => 'document.cu',
3492: kerb_def_dom => 'MSU.EDU',
3493: @_,
3494: );
1.1259 raeburn 3495: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3496: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3497: if ($in{'readonly'}) {
3498: $disabled = ' disabled="disabled"';
3499: }
1.591 raeburn 3500: if (defined($in{'curr_authtype'})) {
3501: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3502: if ($can_assign{'loc'}) {
1.772 bisitz 3503: $loccheck = 'checked="checked" ';
1.623 raeburn 3504: if (defined($in{'mode'})) {
3505: if ($in{'mode'} eq 'modifyuser') {
3506: $loccheck = '';
3507: }
3508: }
1.591 raeburn 3509: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3510: $locarg = $in{'curr_autharg'};
3511: }
3512: } else {
3513: $result = &mt('Currently using local (institutional) authentication.');
3514: return $result;
1.165 raeburn 3515: }
3516: }
1.586 raeburn 3517: } else {
3518: if ($authnum == 1) {
1.784 bisitz 3519: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3520: }
3521: }
3522: if (!$can_assign{'loc'}) {
3523: return;
1.587 raeburn 3524: } elsif ($authtype eq '') {
1.591 raeburn 3525: if (defined($in{'mode'})) {
1.587 raeburn 3526: if ($in{'mode'} eq 'modifycourse') {
3527: if ($authnum == 1) {
1.1259 raeburn 3528: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3529: }
3530: }
3531: }
1.165 raeburn 3532: }
1.586 raeburn 3533: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3534: if ($authtype eq '') {
3535: $authtype = '<input type="radio" name="login" value="loc" '.
3536: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3537: $jscall.'"'.$disabled.' />';
1.586 raeburn 3538: }
3539: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3540: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3541: $result = &mt('[_1] Local Authentication with argument [_2]',
3542: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3543: return $result;
3544: }
3545:
1.1106 raeburn 3546: sub authform_filesystem {
1.32 matthew 3547: my %in = (
3548: formname => 'document.cu',
3549: kerb_def_dom => 'MSU.EDU',
3550: @_,
3551: );
1.1259 raeburn 3552: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3553: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3554: if ($in{'readonly'}) {
3555: $disabled = ' disabled="disabled"';
3556: }
1.591 raeburn 3557: if (defined($in{'curr_authtype'})) {
3558: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3559: if ($can_assign{'fsys'}) {
1.772 bisitz 3560: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3561: if (defined($in{'mode'})) {
3562: if ($in{'mode'} eq 'modifyuser') {
3563: $fsyscheck = '';
3564: }
3565: }
1.586 raeburn 3566: } else {
3567: $result = &mt('Currently Filesystem Authenticated.');
3568: return $result;
1.1259 raeburn 3569: }
1.586 raeburn 3570: }
3571: } else {
3572: if ($authnum == 1) {
1.784 bisitz 3573: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3574: }
3575: }
3576: if (!$can_assign{'fsys'}) {
3577: return;
1.587 raeburn 3578: } elsif ($authtype eq '') {
1.591 raeburn 3579: if (defined($in{'mode'})) {
1.587 raeburn 3580: if ($in{'mode'} eq 'modifycourse') {
3581: if ($authnum == 1) {
1.1259 raeburn 3582: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3583: }
3584: }
3585: }
1.586 raeburn 3586: }
3587: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3588: if ($authtype eq '') {
3589: $authtype = '<input type="radio" name="login" value="fsys" '.
3590: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3591: $jscall.'"'.$disabled.' />';
1.586 raeburn 3592: }
1.1310 raeburn 3593: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3594: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3595: $result = &mt
1.144 matthew 3596: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3597: '<label>'.$authtype,'</label>'.$autharg);
3598: return $result;
3599: }
3600:
3601: sub authform_lti {
3602: my %in = (
3603: formname => 'document.cu',
3604: kerb_def_dom => 'MSU.EDU',
3605: @_,
3606: );
3607: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3608: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3609: if ($in{'readonly'}) {
3610: $disabled = ' disabled="disabled"';
3611: }
3612: if (defined($in{'curr_authtype'})) {
3613: if ($in{'curr_authtype'} eq 'lti') {
3614: if ($can_assign{'lti'}) {
3615: $lticheck = 'checked="checked" ';
3616: if (defined($in{'mode'})) {
3617: if ($in{'mode'} eq 'modifyuser') {
3618: $lticheck = '';
3619: }
3620: }
3621: } else {
3622: $result = &mt('Currently LTI Authenticated.');
3623: return $result;
3624: }
3625: }
3626: } else {
3627: if ($authnum == 1) {
3628: $authtype = '<input type="hidden" name="login" value="lti" />';
3629: }
3630: }
3631: if (!$can_assign{'lti'}) {
3632: return;
3633: } elsif ($authtype eq '') {
3634: if (defined($in{'mode'})) {
3635: if ($in{'mode'} eq 'modifycourse') {
3636: if ($authnum == 1) {
3637: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3638: }
3639: }
3640: }
3641: }
3642: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3643: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3644: $authtype = '<input type="radio" name="login" value="lti" '.
3645: $lticheck.' onchange="'.$jscall.'" onclick="'.
3646: $jscall.'"'.$disabled.' />';
3647: }
3648: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3649: if ($authtype) {
3650: $result = &mt('[_1] LTI Authenticated',
3651: '<label>'.$authtype.'</label>'.$autharg);
3652: } else {
3653: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3654: $autharg;
3655: }
1.32 matthew 3656: return $result;
3657: }
3658:
1.586 raeburn 3659: sub get_assignable_auth {
3660: my ($dom) = @_;
3661: if ($dom eq '') {
3662: $dom = $env{'request.role.domain'};
3663: }
3664: my %can_assign = (
3665: krb4 => 1,
3666: krb5 => 1,
3667: int => 1,
3668: loc => 1,
1.1310 raeburn 3669: lti => 1,
1.586 raeburn 3670: );
3671: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3672: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3673: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3674: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3675: my $context;
3676: if ($env{'request.role'} =~ /^au/) {
3677: $context = 'author';
1.1259 raeburn 3678: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3679: $context = 'domain';
3680: } elsif ($env{'request.course.id'}) {
3681: $context = 'course';
3682: }
3683: if ($context) {
3684: if (ref($authhash->{$context}) eq 'HASH') {
3685: %can_assign = %{$authhash->{$context}};
3686: }
3687: }
3688: }
3689: }
3690: my $authnum = 0;
3691: foreach my $key (keys(%can_assign)) {
3692: if ($can_assign{$key}) {
3693: $authnum ++;
3694: }
3695: }
3696: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3697: $authnum --;
3698: }
3699: return ($authnum,%can_assign);
3700: }
3701:
1.1331 raeburn 3702: sub check_passwd_rules {
3703: my ($domain,$plainpass) = @_;
3704: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3705: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3706: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3707: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3708: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3709: if ($passwdconf{'min'} > $min) {
3710: $min = $passwdconf{'min'};
3711: }
1.1331 raeburn 3712: }
3713: if ($passwdconf{'max'} =~ /^\d+$/) {
3714: $max = $passwdconf{'max'};
3715: }
3716: @chars = @{$passwdconf{'chars'}};
3717: }
3718: if (($min) && (length($plainpass) < $min)) {
3719: push(@brokerule,'min');
3720: }
3721: if (($max) && (length($plainpass) > $max)) {
3722: push(@brokerule,'max');
3723: }
3724: if (@chars) {
3725: my %rules;
3726: map { $rules{$_} = 1; } @chars;
3727: if ($rules{'uc'}) {
3728: unless ($plainpass =~ /[A-Z]/) {
3729: push(@brokerule,'uc');
3730: }
3731: }
3732: if ($rules{'lc'}) {
1.1332 raeburn 3733: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3734: push(@brokerule,'lc');
3735: }
3736: }
3737: if ($rules{'num'}) {
3738: unless ($plainpass =~ /\d/) {
3739: push(@brokerule,'num');
3740: }
3741: }
3742: if ($rules{'spec'}) {
3743: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3744: push(@brokerule,'spec');
3745: }
3746: }
3747: }
3748: if (@brokerule) {
3749: my %rulenames = &Apache::lonlocal::texthash(
3750: uc => 'At least one upper case letter',
3751: lc => 'At least one lower case letter',
3752: num => 'At least one number',
3753: spec => 'At least one non-alphanumeric',
3754: );
3755: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3756: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3757: $rulenames{'num'} .= ': 0123456789';
3758: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3759: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3760: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3761: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1336 raeburn 3762: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1331 raeburn 3763: if (grep(/^$rule$/,@brokerule)) {
3764: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3765: }
3766: }
3767: $warning .= '</ul>';
3768: }
1.1332 raeburn 3769: if (wantarray) {
3770: return @brokerule;
3771: }
1.1331 raeburn 3772: return $warning;
3773: }
3774:
1.1376 raeburn 3775: sub passwd_validation_js {
1.1377 raeburn 3776: my ($currpasswdval,$domain,$context,$id) = @_;
3777: my (%passwdconf,$alertmsg);
3778: if ($context eq 'linkprot') {
3779: my %domconfig = &Apache::lonnet::get_dom('configuration',['ltisec'],$domain);
3780: if (ref($domconfig{'ltisec'}) eq 'HASH') {
3781: if (ref($domconfig{'ltisec'}{'rules'}) eq 'HASH') {
3782: %passwdconf = %{$domconfig{'ltisec'}{'rules'}};
3783: }
3784: }
3785: if ($id eq 'add') {
3786: $alertmsg = &mt('Secret for added launcher did not satisfy requirement(s):').'\n\n';
3787: } elsif ($id =~ /^\d+$/) {
3788: my $pos = $id+1;
3789: $alertmsg = &mt('Secret for launcher [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3790: } else {
3791: $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3792: }
3793: } else {
3794: %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3795: $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
3796: }
1.1376 raeburn 3797: my ($min,$max,@chars,$numrules,$intargjs,%alert);
3798: $numrules = 0;
3799: $min = $Apache::lonnet::passwdmin;
3800: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3801: if ($passwdconf{'min'} =~ /^\d+$/) {
3802: if ($passwdconf{'min'} > $min) {
3803: $min = $passwdconf{'min'};
3804: }
3805: }
3806: if ($passwdconf{'max'} =~ /^\d+$/) {
3807: $max = $passwdconf{'max'};
3808: $numrules ++;
3809: }
3810: @chars = @{$passwdconf{'chars'}};
3811: if (@chars) {
3812: $numrules ++;
3813: }
3814: }
3815: if ($min > 0) {
3816: $numrules ++;
3817: }
3818: if (($min > 0) || ($max ne '') || (@chars > 0)) {
3819: if ($min) {
3820: $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
3821: }
3822: if ($max) {
3823: $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
3824: }
3825: my (@charalerts,@charrules);
3826: if (@chars) {
3827: if (grep(/^uc$/,@chars)) {
3828: push(@charalerts,&mt('contain at least one upper case letter'));
3829: push(@charrules,'uc');
3830: }
3831: if (grep(/^lc$/,@chars)) {
3832: push(@charalerts,&mt('contain at least one lower case letter'));
3833: push(@charrules,'lc');
3834: }
3835: if (grep(/^num$/,@chars)) {
3836: push(@charalerts,&mt('contain at least one number'));
3837: push(@charrules,'num');
3838: }
3839: if (grep(/^spec$/,@chars)) {
3840: push(@charalerts,&mt('contain at least one non-alphanumeric'));
3841: push(@charrules,'spec');
3842: }
3843: }
3844: $intargjs = qq| var rulesmsg = '';\n|.
3845: qq| var currpwval = $currpasswdval;\n|;
3846: if ($min) {
3847: $intargjs .= qq|
3848: if (currpwval.length < $min) {
3849: rulesmsg += ' - $alert{min}';
3850: }
3851: |;
3852: }
3853: if ($max) {
3854: $intargjs .= qq|
3855: if (currpwval.length > $max) {
3856: rulesmsg += ' - $alert{max}';
3857: }
3858: |;
3859: }
3860: if (@chars > 0) {
3861: my $charrulestr = '"'.join('","',@charrules).'"';
3862: my $charalertstr = '"'.join('","',@charalerts).'"';
3863: $intargjs .= qq| var brokerules = new Array();\n|.
3864: qq| var charrules = new Array($charrulestr);\n|.
3865: qq| var charalerts = new Array($charalertstr);\n|;
3866: my %rules;
3867: map { $rules{$_} = 1; } @chars;
3868: if ($rules{'uc'}) {
3869: $intargjs .= qq|
3870: var ucRegExp = /[A-Z]/;
3871: if (!ucRegExp.test(currpwval)) {
3872: brokerules.push('uc');
3873: }
3874: |;
3875: }
3876: if ($rules{'lc'}) {
3877: $intargjs .= qq|
3878: var lcRegExp = /[a-z]/;
3879: if (!lcRegExp.test(currpwval)) {
3880: brokerules.push('lc');
3881: }
3882: |;
3883: }
3884: if ($rules{'num'}) {
3885: $intargjs .= qq|
3886: var numRegExp = /[0-9]/;
3887: if (!numRegExp.test(currpwval)) {
3888: brokerules.push('num');
3889: }
3890: |;
3891: }
3892: if ($rules{'spec'}) {
3893: $intargjs .= q|
3894: var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
3895: if (!specRegExp.test(currpwval)) {
3896: brokerules.push('spec');
3897: }
3898: |;
3899: }
3900: $intargjs .= qq|
3901: if (brokerules.length > 0) {
3902: for (var i=0; i<brokerules.length; i++) {
3903: for (var j=0; j<charrules.length; j++) {
3904: if (brokerules[i] == charrules[j]) {
3905: rulesmsg += ' - '+charalerts[j]+'\\n';
3906: break;
3907: }
3908: }
3909: }
3910: }
3911: |;
3912: }
3913: $intargjs .= qq|
3914: if (rulesmsg != '') {
3915: rulesmsg = '$alertmsg'+rulesmsg;
3916: alert(rulesmsg);
3917: return false;
3918: }
3919: |;
3920: }
3921: return ($numrules,$intargjs);
3922: }
3923:
1.80 albertel 3924: ###############################################################
3925: ## Get Kerberos Defaults for Domain ##
3926: ###############################################################
3927: ##
3928: ## Returns default kerberos version and an associated argument
3929: ## as listed in file domain.tab. If not listed, provides
3930: ## appropriate default domain and kerberos version.
3931: ##
3932: #-------------------------------------------
3933:
3934: =pod
3935:
1.648 raeburn 3936: =item * &get_kerberos_defaults()
1.80 albertel 3937:
3938: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3939: version and domain. If not found, it defaults to version 4 and the
3940: domain of the server.
1.80 albertel 3941:
1.648 raeburn 3942: =over 4
3943:
1.80 albertel 3944: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3945:
1.648 raeburn 3946: =back
3947:
3948: =back
3949:
1.80 albertel 3950: =cut
3951:
3952: #-------------------------------------------
3953: sub get_kerberos_defaults {
3954: my $domain=shift;
1.641 raeburn 3955: my ($krbdef,$krbdefdom);
3956: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3957: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3958: $krbdef = $domdefaults{'auth_def'};
3959: $krbdefdom = $domdefaults{'auth_arg_def'};
3960: } else {
1.80 albertel 3961: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3962: my $krbdefdom=$1;
3963: $krbdefdom=~tr/a-z/A-Z/;
3964: $krbdef = "krb4";
3965: }
3966: return ($krbdef,$krbdefdom);
3967: }
1.112 bowersj2 3968:
1.32 matthew 3969:
1.46 matthew 3970: ###############################################################
3971: ## Thesaurus Functions ##
3972: ###############################################################
1.20 www 3973:
1.46 matthew 3974: =pod
1.20 www 3975:
1.112 bowersj2 3976: =head1 Thesaurus Functions
3977:
3978: =over 4
3979:
1.648 raeburn 3980: =item * &initialize_keywords()
1.46 matthew 3981:
3982: Initializes the package variable %Keywords if it is empty. Uses the
3983: package variable $thesaurus_db_file.
3984:
3985: =cut
3986:
3987: ###################################################
3988:
3989: sub initialize_keywords {
3990: return 1 if (scalar keys(%Keywords));
3991: # If we are here, %Keywords is empty, so fill it up
3992: # Make sure the file we need exists...
3993: if (! -e $thesaurus_db_file) {
3994: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3995: " failed because it does not exist");
3996: return 0;
3997: }
3998: # Set up the hash as a database
3999: my %thesaurus_db;
4000: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 4001: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 4002: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
4003: $thesaurus_db_file);
4004: return 0;
4005: }
4006: # Get the average number of appearances of a word.
4007: my $avecount = $thesaurus_db{'average.count'};
4008: # Put keywords (those that appear > average) into %Keywords
4009: while (my ($word,$data)=each (%thesaurus_db)) {
4010: my ($count,undef) = split /:/,$data;
4011: $Keywords{$word}++ if ($count > $avecount);
4012: }
4013: untie %thesaurus_db;
4014: # Remove special values from %Keywords.
1.356 albertel 4015: foreach my $value ('total.count','average.count') {
4016: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 4017: }
1.46 matthew 4018: return 1;
4019: }
4020:
4021: ###################################################
4022:
4023: =pod
4024:
1.648 raeburn 4025: =item * &keyword($word)
1.46 matthew 4026:
4027: Returns true if $word is a keyword. A keyword is a word that appears more
4028: than the average number of times in the thesaurus database. Calls
4029: &initialize_keywords
4030:
4031: =cut
4032:
4033: ###################################################
1.20 www 4034:
4035: sub keyword {
1.46 matthew 4036: return if (!&initialize_keywords());
4037: my $word=lc(shift());
4038: $word=~s/\W//g;
4039: return exists($Keywords{$word});
1.20 www 4040: }
1.46 matthew 4041:
4042: ###############################################################
4043:
4044: =pod
1.20 www 4045:
1.648 raeburn 4046: =item * &get_related_words()
1.46 matthew 4047:
1.160 matthew 4048: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 4049: an array of words. If the keyword is not in the thesaurus, an empty array
4050: will be returned. The order of the words returned is determined by the
4051: database which holds them.
4052:
4053: Uses global $thesaurus_db_file.
4054:
1.1057 foxr 4055:
1.46 matthew 4056: =cut
4057:
4058: ###############################################################
4059: sub get_related_words {
4060: my $keyword = shift;
4061: my %thesaurus_db;
4062: if (! -e $thesaurus_db_file) {
4063: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
4064: "failed because the file does not exist");
4065: return ();
4066: }
4067: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 4068: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 4069: return ();
4070: }
4071: my @Words=();
1.429 www 4072: my $count=0;
1.46 matthew 4073: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 4074: # The first element is the number of times
4075: # the word appears. We do not need it now.
1.429 www 4076: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
4077: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
4078: my $threshold=$mostfrequentcount/10;
4079: foreach my $possibleword (@RelatedWords) {
4080: my ($word,$wordcount)=split(/\,/,$possibleword);
4081: if ($wordcount>$threshold) {
4082: push(@Words,$word);
4083: $count++;
4084: if ($count>10) { last; }
4085: }
1.20 www 4086: }
4087: }
1.46 matthew 4088: untie %thesaurus_db;
4089: return @Words;
1.14 harris41 4090: }
1.1090 foxr 4091: ###############################################################
4092: #
4093: # Spell checking
4094: #
4095:
4096: =pod
4097:
1.1142 raeburn 4098: =back
4099:
1.1090 foxr 4100: =head1 Spell checking
4101:
4102: =over 4
4103:
4104: =item * &check_spelling($wordlist $language)
4105:
4106: Takes a string containing words and feeds it to an external
4107: spellcheck program via a pipeline. Returns a string containing
4108: them mis-spelled words.
4109:
4110: Parameters:
4111:
4112: =over 4
4113:
4114: =item - $wordlist
4115:
4116: String that will be fed into the spellcheck program.
4117:
4118: =item - $language
4119:
4120: Language string that specifies the language for which the spell
4121: check will be performed.
4122:
4123: =back
4124:
4125: =back
4126:
4127: Note: This sub assumes that aspell is installed.
4128:
4129:
4130: =cut
4131:
1.46 matthew 4132:
1.1090 foxr 4133: sub check_spelling {
4134: my ($wordlist, $language) = @_;
1.1091 foxr 4135: my @misspellings;
4136:
4137: # Generate the speller and set the langauge.
4138: # if explicitly selected:
1.1090 foxr 4139:
1.1091 foxr 4140: my $speller = Text::Aspell->new;
1.1090 foxr 4141: if ($language) {
1.1091 foxr 4142: $speller->set_option('lang', $language);
1.1090 foxr 4143: }
4144:
1.1091 foxr 4145: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 4146:
1.1091 foxr 4147: my @words = split(/\s+/, $wordlist);
1.1090 foxr 4148:
1.1091 foxr 4149: foreach my $word (@words) {
4150: if(! $speller->check($word)) {
4151: push(@misspellings, $word);
1.1090 foxr 4152: }
4153: }
1.1091 foxr 4154: return join(' ', @misspellings);
4155:
1.1090 foxr 4156: }
4157:
1.61 www 4158: # -------------------------------------------------------------- Plaintext name
1.81 albertel 4159: =pod
4160:
1.112 bowersj2 4161: =head1 User Name Functions
4162:
4163: =over 4
4164:
1.648 raeburn 4165: =item * &plainname($uname,$udom,$first)
1.81 albertel 4166:
1.112 bowersj2 4167: Takes a users logon name and returns it as a string in
1.226 albertel 4168: "first middle last generation" form
4169: if $first is set to 'lastname' then it returns it as
4170: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 4171:
4172: =cut
1.61 www 4173:
1.295 www 4174:
1.81 albertel 4175: ###############################################################
1.61 www 4176: sub plainname {
1.226 albertel 4177: my ($uname,$udom,$first)=@_;
1.537 albertel 4178: return if (!defined($uname) || !defined($udom));
1.295 www 4179: my %names=&getnames($uname,$udom);
1.226 albertel 4180: my $name=&Apache::lonnet::format_name($names{'firstname'},
4181: $names{'middlename'},
4182: $names{'lastname'},
4183: $names{'generation'},$first);
4184: $name=~s/^\s+//;
1.62 www 4185: $name=~s/\s+$//;
4186: $name=~s/\s+/ /g;
1.353 albertel 4187: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 4188: return $name;
1.61 www 4189: }
1.66 www 4190:
4191: # -------------------------------------------------------------------- Nickname
1.81 albertel 4192: =pod
4193:
1.648 raeburn 4194: =item * &nickname($uname,$udom)
1.81 albertel 4195:
4196: Gets a users name and returns it as a string as
4197:
4198: ""nickname""
1.66 www 4199:
1.81 albertel 4200: if the user has a nickname or
4201:
4202: "first middle last generation"
4203:
4204: if the user does not
4205:
4206: =cut
1.66 www 4207:
4208: sub nickname {
4209: my ($uname,$udom)=@_;
1.537 albertel 4210: return if (!defined($uname) || !defined($udom));
1.295 www 4211: my %names=&getnames($uname,$udom);
1.68 albertel 4212: my $name=$names{'nickname'};
1.66 www 4213: if ($name) {
4214: $name='"'.$name.'"';
4215: } else {
4216: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
4217: $names{'lastname'}.' '.$names{'generation'};
4218: $name=~s/\s+$//;
4219: $name=~s/\s+/ /g;
4220: }
4221: return $name;
4222: }
4223:
1.295 www 4224: sub getnames {
4225: my ($uname,$udom)=@_;
1.537 albertel 4226: return if (!defined($uname) || !defined($udom));
1.433 albertel 4227: if ($udom eq 'public' && $uname eq 'public') {
4228: return ('lastname' => &mt('Public'));
4229: }
1.295 www 4230: my $id=$uname.':'.$udom;
4231: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
4232: if ($cached) {
4233: return %{$names};
4234: } else {
4235: my %loadnames=&Apache::lonnet::get('environment',
4236: ['firstname','middlename','lastname','generation','nickname'],
4237: $udom,$uname);
4238: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
4239: return %loadnames;
4240: }
4241: }
1.61 www 4242:
1.542 raeburn 4243: # -------------------------------------------------------------------- getemails
1.648 raeburn 4244:
1.542 raeburn 4245: =pod
4246:
1.648 raeburn 4247: =item * &getemails($uname,$udom)
1.542 raeburn 4248:
4249: Gets a user's email information and returns it as a hash with keys:
4250: notification, critnotification, permanentemail
4251:
4252: For notification and critnotification, values are comma-separated lists
1.648 raeburn 4253: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 4254:
1.648 raeburn 4255:
1.542 raeburn 4256: =cut
4257:
1.648 raeburn 4258:
1.466 albertel 4259: sub getemails {
4260: my ($uname,$udom)=@_;
4261: if ($udom eq 'public' && $uname eq 'public') {
4262: return;
4263: }
1.467 www 4264: if (!$udom) { $udom=$env{'user.domain'}; }
4265: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 4266: my $id=$uname.':'.$udom;
4267: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
4268: if ($cached) {
4269: return %{$names};
4270: } else {
4271: my %loadnames=&Apache::lonnet::get('environment',
4272: ['notification','critnotification',
4273: 'permanentemail'],
4274: $udom,$uname);
4275: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
4276: return %loadnames;
4277: }
4278: }
4279:
1.551 albertel 4280: sub flush_email_cache {
4281: my ($uname,$udom)=@_;
4282: if (!$udom) { $udom =$env{'user.domain'}; }
4283: if (!$uname) { $uname=$env{'user.name'}; }
4284: return if ($udom eq 'public' && $uname eq 'public');
4285: my $id=$uname.':'.$udom;
4286: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4287: }
4288:
1.728 raeburn 4289: # -------------------------------------------------------------------- getlangs
4290:
4291: =pod
4292:
4293: =item * &getlangs($uname,$udom)
4294:
4295: Gets a user's language preference and returns it as a hash with key:
4296: language.
4297:
4298: =cut
4299:
4300:
4301: sub getlangs {
4302: my ($uname,$udom) = @_;
4303: if (!$udom) { $udom =$env{'user.domain'}; }
4304: if (!$uname) { $uname=$env{'user.name'}; }
4305: my $id=$uname.':'.$udom;
4306: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4307: if ($cached) {
4308: return %{$langs};
4309: } else {
4310: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4311: $udom,$uname);
4312: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4313: return %loadlangs;
4314: }
4315: }
4316:
4317: sub flush_langs_cache {
4318: my ($uname,$udom)=@_;
4319: if (!$udom) { $udom =$env{'user.domain'}; }
4320: if (!$uname) { $uname=$env{'user.name'}; }
4321: return if ($udom eq 'public' && $uname eq 'public');
4322: my $id=$uname.':'.$udom;
4323: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4324: }
4325:
1.61 www 4326: # ------------------------------------------------------------------ Screenname
1.81 albertel 4327:
4328: =pod
4329:
1.648 raeburn 4330: =item * &screenname($uname,$udom)
1.81 albertel 4331:
4332: Gets a users screenname and returns it as a string
4333:
4334: =cut
1.61 www 4335:
4336: sub screenname {
4337: my ($uname,$udom)=@_;
1.258 albertel 4338: if ($uname eq $env{'user.name'} &&
4339: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4340: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4341: return $names{'screenname'};
1.62 www 4342: }
4343:
1.212 albertel 4344:
1.802 bisitz 4345: # ------------------------------------------------------------- Confirm Wrapper
4346: =pod
4347:
1.1142 raeburn 4348: =item * &confirmwrapper($message)
1.802 bisitz 4349:
4350: Wrap messages about completion of operation in box
4351:
4352: =cut
4353:
4354: sub confirmwrapper {
4355: my ($message)=@_;
4356: if ($message) {
4357: return "\n".'<div class="LC_confirm_box">'."\n"
4358: .$message."\n"
4359: .'</div>'."\n";
4360: } else {
4361: return $message;
4362: }
4363: }
4364:
1.62 www 4365: # ------------------------------------------------------------- Message Wrapper
4366:
4367: sub messagewrapper {
1.369 www 4368: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4369: return
1.441 albertel 4370: '<a href="/adm/email?compose=individual&'.
4371: 'recname='.$username.'&recdom='.$domain.
4372: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4373: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4374: }
1.802 bisitz 4375:
1.74 www 4376: # --------------------------------------------------------------- Notes Wrapper
4377:
4378: sub noteswrapper {
4379: my ($link,$un,$do)=@_;
4380: return
1.896 amueller 4381: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4382: }
1.802 bisitz 4383:
1.62 www 4384: # ------------------------------------------------------------- Aboutme Wrapper
4385:
4386: sub aboutmewrapper {
1.1070 raeburn 4387: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4388: if (!defined($username) && !defined($domain)) {
4389: return;
4390: }
1.1096 raeburn 4391: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4392: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4393: }
4394:
4395: # ------------------------------------------------------------ Syllabus Wrapper
4396:
4397: sub syllabuswrapper {
1.707 bisitz 4398: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4399: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4400: }
1.14 harris41 4401:
1.1397 raeburn 4402: # -----------------------------------------------------------------------------
4403:
1.1396 raeburn 4404: sub aboutme_on {
4405: my ($uname,$udom)=@_;
4406: unless ($uname) { $uname=$env{'user.name'}; }
4407: unless ($udom) { $udom=$env{'user.domain'}; }
4408: return if ($udom eq 'public' && $uname eq 'public');
4409: my $hashkey=$uname.':'.$udom;
4410: my ($aboutme,$cached)=&Apache::lonnet::is_cached_new('aboutme',$hashkey);
4411: if ($cached) {
4412: return $aboutme;
4413: }
4414: $aboutme = &Apache::lonnet::usertools_access($uname,$udom,'aboutme');
4415: &Apache::lonnet::do_cache_new('aboutme',$hashkey,$aboutme,3600);
4416: return $aboutme;
4417: }
4418:
4419: sub devalidate_aboutme_cache {
4420: my ($uname,$udom)=@_;
4421: if (!$udom) { $udom =$env{'user.domain'}; }
4422: if (!$uname) { $uname=$env{'user.name'}; }
4423: return if ($udom eq 'public' && $uname eq 'public');
4424: my $id=$uname.':'.$udom;
4425: &Apache::lonnet::devalidate_cache_new('aboutme',$id);
4426: }
4427:
1.208 matthew 4428: sub track_student_link {
1.887 raeburn 4429: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4430: my $link ="/adm/trackstudent?";
1.208 matthew 4431: my $title = 'View recent activity';
4432: if (defined($sname) && $sname !~ /^\s*$/ &&
4433: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4434: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4435: $title .= ' of this student';
1.268 albertel 4436: }
1.208 matthew 4437: if (defined($target) && $target !~ /^\s*$/) {
4438: $target = qq{target="$target"};
4439: } else {
4440: $target = '';
4441: }
1.268 albertel 4442: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4443: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4444: $title = &mt($title);
4445: $linktext = &mt($linktext);
1.448 albertel 4446: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4447: &help_open_topic('View_recent_activity');
1.208 matthew 4448: }
4449:
1.781 raeburn 4450: sub slot_reservations_link {
4451: my ($linktext,$sname,$sdom,$target) = @_;
4452: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4453: my $title = 'View slot reservation history';
4454: if (defined($sname) && $sname !~ /^\s*$/ &&
4455: defined($sdom) && $sdom !~ /^\s*$/) {
4456: $link .= "&uname=$sname&udom=$sdom";
4457: $title .= ' of this student';
4458: }
4459: if (defined($target) && $target !~ /^\s*$/) {
4460: $target = qq{target="$target"};
4461: } else {
4462: $target = '';
4463: }
4464: $title = &mt($title);
4465: $linktext = &mt($linktext);
4466: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4467: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4468:
4469: }
4470:
1.508 www 4471: # ===================================================== Display a student photo
4472:
4473:
1.509 albertel 4474: sub student_image_tag {
1.508 www 4475: my ($domain,$user)=@_;
4476: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4477: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4478: return '<img src="'.$imgsrc.'" align="right" />';
4479: } else {
4480: return '';
4481: }
4482: }
4483:
1.112 bowersj2 4484: =pod
4485:
4486: =back
4487:
4488: =head1 Access .tab File Data
4489:
4490: =over 4
4491:
1.648 raeburn 4492: =item * &languageids()
1.112 bowersj2 4493:
4494: returns list of all language ids
4495:
4496: =cut
4497:
1.14 harris41 4498: sub languageids {
1.16 harris41 4499: return sort(keys(%language));
1.14 harris41 4500: }
4501:
1.112 bowersj2 4502: =pod
4503:
1.648 raeburn 4504: =item * &languagedescription()
1.112 bowersj2 4505:
4506: returns description of a specified language id
4507:
4508: =cut
4509:
1.14 harris41 4510: sub languagedescription {
1.125 www 4511: my $code=shift;
4512: return ($supported_language{$code}?'* ':'').
4513: $language{$code}.
1.126 www 4514: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4515: }
4516:
1.1048 foxr 4517: =pod
4518:
4519: =item * &plainlanguagedescription
4520:
4521: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4522: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4523:
4524: =cut
4525:
1.145 www 4526: sub plainlanguagedescription {
4527: my $code=shift;
4528: return $language{$code};
4529: }
4530:
1.1048 foxr 4531: =pod
4532:
4533: =item * &supportedlanguagecode
4534:
4535: Returns the supported language code (e.g. sptutf maps to pt) given a language
4536: code.
4537:
4538: =cut
4539:
1.145 www 4540: sub supportedlanguagecode {
4541: my $code=shift;
4542: return $supported_language{$code};
1.97 www 4543: }
4544:
1.112 bowersj2 4545: =pod
4546:
1.1048 foxr 4547: =item * &latexlanguage()
4548:
4549: Given a language key code returns the correspondnig language to use
4550: to select the correct hyphenation on LaTeX printouts. This is undef if there
4551: is no supported hyphenation for the language code.
4552:
4553: =cut
4554:
4555: sub latexlanguage {
4556: my $code = shift;
4557: return $latex_language{$code};
4558: }
4559:
4560: =pod
4561:
4562: =item * &latexhyphenation()
4563:
4564: Same as above but what's supplied is the language as it might be stored
4565: in the metadata.
4566:
4567: =cut
4568:
4569: sub latexhyphenation {
4570: my $key = shift;
4571: return $latex_language_bykey{$key};
4572: }
4573:
4574: =pod
4575:
1.648 raeburn 4576: =item * ©rightids()
1.112 bowersj2 4577:
4578: returns list of all copyrights
4579:
4580: =cut
4581:
4582: sub copyrightids {
4583: return sort(keys(%cprtag));
4584: }
4585:
4586: =pod
4587:
1.648 raeburn 4588: =item * ©rightdescription()
1.112 bowersj2 4589:
4590: returns description of a specified copyright id
4591:
4592: =cut
4593:
4594: sub copyrightdescription {
1.166 www 4595: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4596: }
1.197 matthew 4597:
4598: =pod
4599:
1.648 raeburn 4600: =item * &source_copyrightids()
1.192 taceyjo1 4601:
4602: returns list of all source copyrights
4603:
4604: =cut
4605:
4606: sub source_copyrightids {
4607: return sort(keys(%scprtag));
4608: }
4609:
4610: =pod
4611:
1.648 raeburn 4612: =item * &source_copyrightdescription()
1.192 taceyjo1 4613:
4614: returns description of a specified source copyright id
4615:
4616: =cut
4617:
4618: sub source_copyrightdescription {
4619: return &mt($scprtag{shift(@_)});
4620: }
1.112 bowersj2 4621:
4622: =pod
4623:
1.648 raeburn 4624: =item * &filecategories()
1.112 bowersj2 4625:
4626: returns list of all file categories
4627:
4628: =cut
4629:
4630: sub filecategories {
4631: return sort(keys(%category_extensions));
4632: }
4633:
4634: =pod
4635:
1.648 raeburn 4636: =item * &filecategorytypes()
1.112 bowersj2 4637:
4638: returns list of file types belonging to a given file
4639: category
4640:
4641: =cut
4642:
4643: sub filecategorytypes {
1.356 albertel 4644: my ($cat) = @_;
1.1248 raeburn 4645: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4646: return @{$category_extensions{lc($cat)}};
4647: } else {
4648: return ();
4649: }
1.112 bowersj2 4650: }
4651:
4652: =pod
4653:
1.648 raeburn 4654: =item * &fileembstyle()
1.112 bowersj2 4655:
4656: returns embedding style for a specified file type
4657:
4658: =cut
4659:
4660: sub fileembstyle {
4661: return $fe{lc(shift(@_))};
1.169 www 4662: }
4663:
1.351 www 4664: sub filemimetype {
4665: return $fm{lc(shift(@_))};
4666: }
4667:
1.169 www 4668:
4669: sub filecategoryselect {
4670: my ($name,$value)=@_;
1.189 matthew 4671: return &select_form($value,$name,
1.970 raeburn 4672: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4673: }
4674:
4675: =pod
4676:
1.648 raeburn 4677: =item * &filedescription()
1.112 bowersj2 4678:
4679: returns description for a specified file type
4680:
4681: =cut
4682:
4683: sub filedescription {
1.188 matthew 4684: my $file_description = $fd{lc(shift())};
4685: $file_description =~ s:([\[\]]):~$1:g;
4686: return &mt($file_description);
1.112 bowersj2 4687: }
4688:
4689: =pod
4690:
1.648 raeburn 4691: =item * &filedescriptionex()
1.112 bowersj2 4692:
4693: returns description for a specified file type with
4694: extra formatting
4695:
4696: =cut
4697:
4698: sub filedescriptionex {
4699: my $ex=shift;
1.188 matthew 4700: my $file_description = $fd{lc($ex)};
4701: $file_description =~ s:([\[\]]):~$1:g;
4702: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4703: }
4704:
4705: # End of .tab access
4706: =pod
4707:
4708: =back
4709:
4710: =cut
4711:
4712: # ------------------------------------------------------------------ File Types
4713: sub fileextensions {
4714: return sort(keys(%fe));
4715: }
4716:
1.97 www 4717: # ----------------------------------------------------------- Display Languages
4718: # returns a hash with all desired display languages
4719: #
4720:
4721: sub display_languages {
4722: my %languages=();
1.695 raeburn 4723: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4724: $languages{$lang}=1;
1.97 www 4725: }
4726: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4727: if ($env{'form.displaylanguage'}) {
1.356 albertel 4728: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4729: $languages{$lang}=1;
1.97 www 4730: }
4731: }
4732: return %languages;
1.14 harris41 4733: }
4734:
1.582 albertel 4735: sub languages {
4736: my ($possible_langs) = @_;
1.695 raeburn 4737: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4738: if (!ref($possible_langs)) {
4739: if( wantarray ) {
4740: return @preferred_langs;
4741: } else {
4742: return $preferred_langs[0];
4743: }
4744: }
4745: my %possibilities = map { $_ => 1 } (@$possible_langs);
4746: my @preferred_possibilities;
4747: foreach my $preferred_lang (@preferred_langs) {
4748: if (exists($possibilities{$preferred_lang})) {
4749: push(@preferred_possibilities, $preferred_lang);
4750: }
4751: }
4752: if( wantarray ) {
4753: return @preferred_possibilities;
4754: }
4755: return $preferred_possibilities[0];
4756: }
4757:
1.742 raeburn 4758: sub user_lang {
4759: my ($touname,$toudom,$fromcid) = @_;
4760: my @userlangs;
4761: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4762: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4763: $env{'course.'.$fromcid.'.languages'}));
4764: } else {
4765: my %langhash = &getlangs($touname,$toudom);
4766: if ($langhash{'languages'} ne '') {
4767: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4768: } else {
4769: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4770: if ($domdefs{'lang_def'} ne '') {
4771: @userlangs = ($domdefs{'lang_def'});
4772: }
4773: }
4774: }
4775: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4776: my $user_lh = Apache::localize->get_handle(@languages);
4777: return $user_lh;
4778: }
4779:
4780:
1.112 bowersj2 4781: ###############################################################
4782: ## Student Answer Attempts ##
4783: ###############################################################
4784:
4785: =pod
4786:
4787: =head1 Alternate Problem Views
4788:
4789: =over 4
4790:
1.648 raeburn 4791: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4792: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4793:
4794: Return string with previous attempt on problem. Arguments:
4795:
4796: =over 4
4797:
4798: =item * $symb: Problem, including path
4799:
4800: =item * $username: username of the desired student
4801:
4802: =item * $domain: domain of the desired student
1.14 harris41 4803:
1.112 bowersj2 4804: =item * $course: Course ID
1.14 harris41 4805:
1.112 bowersj2 4806: =item * $getattempt: Leave blank for all attempts, otherwise put
4807: something
1.14 harris41 4808:
1.112 bowersj2 4809: =item * $regexp: if string matches this regexp, the string will be
4810: sent to $gradesub
1.14 harris41 4811:
1.112 bowersj2 4812: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4813:
1.1199 raeburn 4814: =item * $usec: section of the desired student
4815:
4816: =item * $identifier: counter for student (multiple students one problem) or
4817: problem (one student; whole sequence).
4818:
1.112 bowersj2 4819: =back
1.14 harris41 4820:
1.112 bowersj2 4821: The output string is a table containing all desired attempts, if any.
1.16 harris41 4822:
1.112 bowersj2 4823: =cut
1.1 albertel 4824:
4825: sub get_previous_attempt {
1.1199 raeburn 4826: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4827: my $prevattempts='';
1.43 ng 4828: no strict 'refs';
1.1 albertel 4829: if ($symb) {
1.3 albertel 4830: my (%returnhash)=
4831: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4832: if ($returnhash{'version'}) {
4833: my %lasthash=();
4834: my $version;
4835: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4836: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4837: if ($key =~ /\.rawrndseed$/) {
4838: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4839: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4840: } else {
4841: $lasthash{$key}=$returnhash{$version.':'.$key};
4842: }
1.19 harris41 4843: }
1.1 albertel 4844: }
1.596 albertel 4845: $prevattempts=&start_data_table().&start_data_table_header_row();
4846: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4847: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4848: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4849: foreach my $key (sort(keys(%lasthash))) {
4850: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4851: if ($#parts > 0) {
1.31 albertel 4852: my $data=$parts[-1];
1.989 raeburn 4853: next if ($data eq 'foilorder');
1.31 albertel 4854: pop(@parts);
1.1010 www 4855: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4856: if ($data eq 'type') {
4857: unless ($showsurv) {
4858: my $id = join(',',@parts);
4859: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4860: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4861: $lasthidden{$ign.'.'.$id} = 1;
4862: }
1.945 raeburn 4863: }
1.1199 raeburn 4864: if ($identifier ne '') {
4865: my $id = join(',',@parts);
4866: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4867: $domain,$username,$usec,undef,$course) =~ /^no/) {
4868: $hidestatus{$ign.'.'.$id} = 1;
4869: }
4870: }
4871: } elsif ($data eq 'regrader') {
4872: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4873: my $id = join(',',@parts);
4874: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4875: }
1.1010 www 4876: }
1.31 albertel 4877: } else {
1.41 ng 4878: if ($#parts == 0) {
4879: $prevattempts.='<th>'.$parts[0].'</th>';
4880: } else {
4881: $prevattempts.='<th>'.$ign.'</th>';
4882: }
1.31 albertel 4883: }
1.16 harris41 4884: }
1.596 albertel 4885: $prevattempts.=&end_data_table_header_row();
1.40 ng 4886: if ($getattempt eq '') {
1.1199 raeburn 4887: my (%solved,%resets,%probstatus);
1.1200 raeburn 4888: if (($identifier ne '') && (keys(%regraded) > 0)) {
4889: for ($version=1;$version<=$returnhash{'version'};$version++) {
4890: foreach my $id (keys(%regraded)) {
4891: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4892: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4893: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4894: push(@{$resets{$id}},$version);
1.1199 raeburn 4895: }
4896: }
4897: }
1.1200 raeburn 4898: }
4899: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4900: my (@hidden,@unsolved);
1.945 raeburn 4901: if (%typeparts) {
4902: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4903: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4904: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4905: push(@hidden,$id);
1.1199 raeburn 4906: } elsif ($identifier ne '') {
4907: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4908: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4909: ($hidestatus{$id})) {
1.1200 raeburn 4910: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4911: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4912: push(@{$solved{$id}},$version);
4913: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4914: (ref($solved{$id}) eq 'ARRAY')) {
4915: my $skip;
4916: if (ref($resets{$id}) eq 'ARRAY') {
4917: foreach my $reset (@{$resets{$id}}) {
4918: if ($reset > $solved{$id}[-1]) {
4919: $skip=1;
4920: last;
4921: }
4922: }
4923: }
4924: unless ($skip) {
4925: my ($ign,$partslist) = split(/\./,$id,2);
4926: push(@unsolved,$partslist);
4927: }
4928: }
4929: }
1.945 raeburn 4930: }
4931: }
4932: }
4933: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4934: '<td>'.&mt('Transaction [_1]',$version);
4935: if (@unsolved) {
4936: $prevattempts .= '<span class="LC_nobreak"><label>'.
4937: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4938: &mt('Hide').'</label></span>';
4939: }
4940: $prevattempts .= '</td>';
1.945 raeburn 4941: if (@hidden) {
4942: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4943: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4944: my $hide;
4945: foreach my $id (@hidden) {
4946: if ($key =~ /^\Q$id\E/) {
4947: $hide = 1;
4948: last;
4949: }
4950: }
4951: if ($hide) {
4952: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4953: if (($data eq 'award') || ($data eq 'awarddetail')) {
4954: my $value = &format_previous_attempt_value($key,
4955: $returnhash{$version.':'.$key});
1.1173 kruse 4956: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4957: } else {
4958: $prevattempts.='<td> </td>';
4959: }
4960: } else {
4961: if ($key =~ /\./) {
1.1212 raeburn 4962: my $value = $returnhash{$version.':'.$key};
4963: if ($key =~ /\.rndseed$/) {
4964: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4965: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4966: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4967: }
4968: }
4969: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4970: ' </td>';
1.945 raeburn 4971: } else {
4972: $prevattempts.='<td> </td>';
4973: }
4974: }
4975: }
4976: } else {
4977: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4978: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4979: my $value = $returnhash{$version.':'.$key};
4980: if ($key =~ /\.rndseed$/) {
4981: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4982: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4983: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4984: }
4985: }
4986: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4987: ' </td>';
1.945 raeburn 4988: }
4989: }
4990: $prevattempts.=&end_data_table_row();
1.40 ng 4991: }
1.1 albertel 4992: }
1.945 raeburn 4993: my @currhidden = keys(%lasthidden);
1.596 albertel 4994: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4995: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4996: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4997: if (%typeparts) {
4998: my $hidden;
4999: foreach my $id (@currhidden) {
5000: if ($key =~ /^\Q$id\E/) {
5001: $hidden = 1;
5002: last;
5003: }
5004: }
5005: if ($hidden) {
5006: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
5007: if (($data eq 'award') || ($data eq 'awarddetail')) {
5008: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5009: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5010: $value = &$gradesub($value);
5011: }
1.1173 kruse 5012: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 5013: } else {
5014: $prevattempts.='<td> </td>';
5015: }
5016: } else {
5017: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5018: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5019: $value = &$gradesub($value);
5020: }
1.1173 kruse 5021: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5022: }
5023: } else {
5024: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5025: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5026: $value = &$gradesub($value);
5027: }
1.1173 kruse 5028: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5029: }
1.16 harris41 5030: }
1.596 albertel 5031: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 5032: } else {
1.1305 raeburn 5033: my $msg;
5034: if ($symb =~ /ext\.tool$/) {
5035: $msg = &mt('No grade passed back.');
5036: } else {
5037: $msg = &mt('Nothing submitted - no attempts.');
5038: }
1.596 albertel 5039: $prevattempts=
5040: &start_data_table().&start_data_table_row().
1.1305 raeburn 5041: '<td>'.$msg.'</td>'.
1.596 albertel 5042: &end_data_table_row().&end_data_table();
1.1 albertel 5043: }
5044: } else {
1.596 albertel 5045: $prevattempts=
5046: &start_data_table().&start_data_table_row().
5047: '<td>'.&mt('No data.').'</td>'.
5048: &end_data_table_row().&end_data_table();
1.1 albertel 5049: }
1.10 albertel 5050: }
5051:
1.581 albertel 5052: sub format_previous_attempt_value {
5053: my ($key,$value) = @_;
1.1011 www 5054: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 5055: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 5056: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 5057: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 5058: } elsif ($key =~ /answerstring$/) {
5059: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 5060: my @answer = %answers;
5061: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 5062: my @anskeys = sort(keys(%answers));
5063: if (@anskeys == 1) {
5064: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 5065: if ($answer =~ m{\0}) {
5066: $answer =~ s{\0}{,}g;
1.988 raeburn 5067: }
5068: my $tag_internal_answer_name = 'INTERNAL';
5069: if ($anskeys[0] eq $tag_internal_answer_name) {
5070: $value = $answer;
5071: } else {
5072: $value = $anskeys[0].'='.$answer;
5073: }
5074: } else {
5075: foreach my $ans (@anskeys) {
5076: my $answer = $answers{$ans};
1.1001 raeburn 5077: if ($answer =~ m{\0}) {
5078: $answer =~ s{\0}{,}g;
1.988 raeburn 5079: }
5080: $value .= $ans.'='.$answer.'<br />';;
5081: }
5082: }
1.581 albertel 5083: } else {
1.1173 kruse 5084: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 5085: }
5086: return $value;
5087: }
5088:
5089:
1.107 albertel 5090: sub relative_to_absolute {
5091: my ($url,$output)=@_;
5092: my $parser=HTML::TokeParser->new(\$output);
5093: my $token;
5094: my $thisdir=$url;
5095: my @rlinks=();
5096: while ($token=$parser->get_token) {
5097: if ($token->[0] eq 'S') {
5098: if ($token->[1] eq 'a') {
5099: if ($token->[2]->{'href'}) {
5100: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
5101: }
5102: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
5103: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
5104: } elsif ($token->[1] eq 'base') {
5105: $thisdir=$token->[2]->{'href'};
5106: }
5107: }
5108: }
5109: $thisdir=~s-/[^/]*$--;
1.356 albertel 5110: foreach my $link (@rlinks) {
1.726 raeburn 5111: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 5112: ($link=~/^\//) ||
5113: ($link=~/^javascript:/i) ||
5114: ($link=~/^mailto:/i) ||
5115: ($link=~/^\#/)) {
5116: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
5117: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 5118: }
5119: }
5120: # -------------------------------------------------- Deal with Applet codebases
5121: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
5122: return $output;
5123: }
5124:
1.112 bowersj2 5125: =pod
5126:
1.648 raeburn 5127: =item * &get_student_view()
1.112 bowersj2 5128:
5129: show a snapshot of what student was looking at
5130:
5131: =cut
5132:
1.10 albertel 5133: sub get_student_view {
1.186 albertel 5134: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 5135: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5136: my (%form);
1.10 albertel 5137: my @elements=('symb','courseid','domain','username');
5138: foreach my $element (@elements) {
1.186 albertel 5139: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5140: }
1.186 albertel 5141: if (defined($moreenv)) {
5142: %form=(%form,%{$moreenv});
5143: }
1.236 albertel 5144: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 5145: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 5146: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
5147: $feedurl =~ s{^/adm/wrapper}{};
5148: }
1.650 www 5149: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 5150: $userview=~s/\<body[^\>]*\>//gi;
5151: $userview=~s/\<\/body\>//gi;
5152: $userview=~s/\<html\>//gi;
5153: $userview=~s/\<\/html\>//gi;
5154: $userview=~s/\<head\>//gi;
5155: $userview=~s/\<\/head\>//gi;
5156: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 5157: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 5158: if (wantarray) {
5159: return ($userview,$response);
5160: } else {
5161: return $userview;
5162: }
5163: }
5164:
5165: sub get_student_view_with_retries {
5166: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
5167:
5168: my $ok = 0; # True if we got a good response.
5169: my $content;
5170: my $response;
5171:
5172: # Try to get the student_view done. within the retries count:
5173:
5174: do {
5175: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
5176: $ok = $response->is_success;
5177: if (!$ok) {
5178: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
5179: }
5180: $retries--;
5181: } while (!$ok && ($retries > 0));
5182:
5183: if (!$ok) {
5184: $content = ''; # On error return an empty content.
5185: }
1.651 www 5186: if (wantarray) {
5187: return ($content, $response);
5188: } else {
5189: return $content;
5190: }
1.11 albertel 5191: }
5192:
1.1349 raeburn 5193: sub css_links {
5194: my ($currsymb,$level) = @_;
5195: my ($links,@symbs,%cssrefs,%httpref);
5196: if ($level eq 'map') {
5197: my $navmap = Apache::lonnavmaps::navmap->new();
5198: if (ref($navmap)) {
5199: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
5200: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
5201: foreach my $res (@resources) {
5202: if (ref($res) && $res->symb()) {
5203: push(@symbs,$res->symb());
5204: }
5205: }
5206: }
5207: } else {
5208: @symbs = ($currsymb);
5209: }
5210: foreach my $symb (@symbs) {
5211: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
5212: if ($css_href =~ /\S/) {
5213: unless ($css_href =~ m{https?://}) {
5214: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
5215: my $proburl = &Apache::lonnet::clutter($url);
5216: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
5217: unless ($css_href =~ m{^/}) {
5218: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
5219: }
5220: if ($css_href =~ m{^/(res|uploaded)/}) {
5221: unless (($httpref{'httpref.'.$css_href}) ||
5222: (&Apache::lonnet::is_on_map($css_href))) {
5223: my $thisurl = $proburl;
5224: if ($env{'httpref.'.$proburl}) {
5225: $thisurl = $env{'httpref.'.$proburl};
5226: }
5227: $httpref{'httpref.'.$css_href} = $thisurl;
5228: }
5229: }
5230: }
5231: $cssrefs{$css_href} = 1;
5232: }
5233: }
5234: if (keys(%httpref)) {
5235: &Apache::lonnet::appenv(\%httpref);
5236: }
5237: if (keys(%cssrefs)) {
5238: foreach my $css_href (keys(%cssrefs)) {
5239: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
5240: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
5241: }
5242: }
5243: return $links;
5244: }
5245:
1.112 bowersj2 5246: =pod
5247:
1.648 raeburn 5248: =item * &get_student_answers()
1.112 bowersj2 5249:
5250: show a snapshot of how student was answering problem
5251:
5252: =cut
5253:
1.11 albertel 5254: sub get_student_answers {
1.100 sakharuk 5255: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 5256: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5257: my (%moreenv);
1.11 albertel 5258: my @elements=('symb','courseid','domain','username');
5259: foreach my $element (@elements) {
1.186 albertel 5260: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5261: }
1.186 albertel 5262: $moreenv{'grade_target'}='answer';
5263: %moreenv=(%form,%moreenv);
1.497 raeburn 5264: $feedurl = &Apache::lonnet::clutter($feedurl);
5265: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 5266: return $userview;
1.1 albertel 5267: }
1.116 albertel 5268:
5269: =pod
5270:
5271: =item * &submlink()
5272:
1.242 albertel 5273: Inputs: $text $uname $udom $symb $target
1.116 albertel 5274:
5275: Returns: A link to grades.pm such as to see the SUBM view of a student
5276:
5277: =cut
5278:
5279: ###############################################
5280: sub submlink {
1.242 albertel 5281: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 5282: if (!($uname && $udom)) {
5283: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5284: &Apache::lonnet::whichuser($symb);
1.116 albertel 5285: if (!$symb) { $symb=$cursymb; }
5286: }
1.254 matthew 5287: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5288: $symb=&escape($symb);
1.960 bisitz 5289: if ($target) { $target=" target=\"$target\""; }
5290: return
5291: '<a href="/adm/grades?command=submission'.
5292: '&symb='.$symb.
5293: '&student='.$uname.
5294: '&userdom='.$udom.'"'.
5295: $target.'>'.$text.'</a>';
1.242 albertel 5296: }
5297: ##############################################
5298:
5299: =pod
5300:
5301: =item * &pgrdlink()
5302:
5303: Inputs: $text $uname $udom $symb $target
5304:
5305: Returns: A link to grades.pm such as to see the PGRD view of a student
5306:
5307: =cut
5308:
5309: ###############################################
5310: sub pgrdlink {
5311: my $link=&submlink(@_);
5312: $link=~s/(&command=submission)/$1&showgrading=yes/;
5313: return $link;
5314: }
5315: ##############################################
5316:
5317: =pod
5318:
5319: =item * &pprmlink()
5320:
5321: Inputs: $text $uname $udom $symb $target
5322:
5323: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 5324: student and a specific resource
1.242 albertel 5325:
5326: =cut
5327:
5328: ###############################################
5329: sub pprmlink {
5330: my ($text,$uname,$udom,$symb,$target)=@_;
5331: if (!($uname && $udom)) {
5332: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5333: &Apache::lonnet::whichuser($symb);
1.242 albertel 5334: if (!$symb) { $symb=$cursymb; }
5335: }
1.254 matthew 5336: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5337: $symb=&escape($symb);
1.242 albertel 5338: if ($target) { $target="target=\"$target\""; }
1.595 albertel 5339: return '<a href="/adm/parmset?command=set&'.
5340: 'symb='.$symb.'&uname='.$uname.
5341: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 5342: }
5343: ##############################################
1.37 matthew 5344:
1.112 bowersj2 5345: =pod
5346:
5347: =back
5348:
5349: =cut
5350:
1.37 matthew 5351: ###############################################
1.51 www 5352:
5353:
5354: sub timehash {
1.687 raeburn 5355: my ($thistime) = @_;
5356: my $timezone = &Apache::lonlocal::gettimezone();
5357: my $dt = DateTime->from_epoch(epoch => $thistime)
5358: ->set_time_zone($timezone);
5359: my $wday = $dt->day_of_week();
5360: if ($wday == 7) { $wday = 0; }
5361: return ( 'second' => $dt->second(),
5362: 'minute' => $dt->minute(),
5363: 'hour' => $dt->hour(),
5364: 'day' => $dt->day_of_month(),
5365: 'month' => $dt->month(),
5366: 'year' => $dt->year(),
5367: 'weekday' => $wday,
5368: 'dayyear' => $dt->day_of_year(),
5369: 'dlsav' => $dt->is_dst() );
1.51 www 5370: }
5371:
1.370 www 5372: sub utc_string {
5373: my ($date)=@_;
1.371 www 5374: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5375: }
5376:
1.51 www 5377: sub maketime {
5378: my %th=@_;
1.687 raeburn 5379: my ($epoch_time,$timezone,$dt);
5380: $timezone = &Apache::lonlocal::gettimezone();
5381: eval {
5382: $dt = DateTime->new( year => $th{'year'},
5383: month => $th{'month'},
5384: day => $th{'day'},
5385: hour => $th{'hour'},
5386: minute => $th{'minute'},
5387: second => $th{'second'},
5388: time_zone => $timezone,
5389: );
5390: };
5391: if (!$@) {
5392: $epoch_time = $dt->epoch;
5393: if ($epoch_time) {
5394: return $epoch_time;
5395: }
5396: }
1.51 www 5397: return POSIX::mktime(
5398: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5399: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5400: }
5401:
5402: #########################################
1.51 www 5403:
5404: sub findallcourses {
1.482 raeburn 5405: my ($roles,$uname,$udom) = @_;
1.355 albertel 5406: my %roles;
5407: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5408: my %courses;
1.51 www 5409: my $now=time;
1.482 raeburn 5410: if (!defined($uname)) {
5411: $uname = $env{'user.name'};
5412: }
5413: if (!defined($udom)) {
5414: $udom = $env{'user.domain'};
5415: }
5416: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5417: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5418: if (!%roles) {
5419: %roles = (
5420: cc => 1,
1.907 raeburn 5421: co => 1,
1.482 raeburn 5422: in => 1,
5423: ep => 1,
5424: ta => 1,
5425: cr => 1,
5426: st => 1,
5427: );
5428: }
5429: foreach my $entry (keys(%roleshash)) {
5430: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5431: if ($trole =~ /^cr/) {
5432: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5433: } else {
5434: next if (!exists($roles{$trole}));
5435: }
5436: if ($tend) {
5437: next if ($tend < $now);
5438: }
5439: if ($tstart) {
5440: next if ($tstart > $now);
5441: }
1.1058 raeburn 5442: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5443: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5444: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5445: if ($secpart eq '') {
5446: ($cnum,$role) = split(/_/,$cnumpart);
5447: $sec = 'none';
1.1058 raeburn 5448: $value .= $cnum.'/';
1.482 raeburn 5449: } else {
5450: $cnum = $cnumpart;
5451: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5452: $value .= $cnum.'/'.$sec;
5453: }
5454: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5455: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5456: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5457: }
5458: } else {
5459: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5460: }
1.482 raeburn 5461: }
5462: } else {
5463: foreach my $key (keys(%env)) {
1.483 albertel 5464: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5465: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5466: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5467: next if ($role eq 'ca' || $role eq 'aa');
5468: next if (%roles && !exists($roles{$role}));
5469: my ($starttime,$endtime)=split(/\./,$env{$key});
5470: my $active=1;
5471: if ($starttime) {
5472: if ($now<$starttime) { $active=0; }
5473: }
5474: if ($endtime) {
5475: if ($now>$endtime) { $active=0; }
5476: }
5477: if ($active) {
1.1058 raeburn 5478: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5479: if ($sec eq '') {
5480: $sec = 'none';
1.1058 raeburn 5481: } else {
5482: $value .= $sec;
5483: }
5484: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5485: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5486: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5487: }
5488: } else {
5489: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5490: }
1.474 raeburn 5491: }
5492: }
1.51 www 5493: }
5494: }
1.474 raeburn 5495: return %courses;
1.51 www 5496: }
1.37 matthew 5497:
1.54 www 5498: ###############################################
1.474 raeburn 5499:
5500: sub blockcheck {
1.1372 raeburn 5501: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
5502: unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
5503: my ($has_evb,$check_ipaccess);
5504: my $dom = $env{'user.domain'};
5505: if ($env{'request.course.id'}) {
5506: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5507: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5508: my $checkrole = "cm./$cdom/$cnum";
5509: my $sec = $env{'request.course.sec'};
5510: if ($sec ne '') {
5511: $checkrole .= "/$sec";
5512: }
5513: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
5514: ($env{'request.role'} !~ /^st/)) {
5515: $has_evb = 1;
5516: }
5517: unless ($has_evb) {
5518: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
5519: ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
5520: if ($udom eq $cdom) {
5521: $check_ipaccess = 1;
5522: }
5523: }
5524: }
1.1375 raeburn 5525: } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
5526: ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
5527: my $checkrole;
5528: if ($env{'request.role.domain'} eq '') {
5529: $checkrole = "cm./$env{'user.domain'}/";
5530: } else {
5531: $checkrole = "cm./$env{'request.role.domain'}/";
5532: }
5533: if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
5534: $has_evb = 1;
5535: }
1.1372 raeburn 5536: }
5537: unless ($has_evb || $check_ipaccess) {
5538: my @machinedoms = &Apache::lonnet::current_machine_domains();
5539: if (($dom eq 'public') && ($activity eq 'port')) {
5540: $dom = $udom;
5541: }
5542: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5543: $check_ipaccess = 1;
5544: } else {
5545: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5546: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5547: my $prim = &Apache::lonnet::domain($dom,'primary');
5548: my $intdom = &Apache::lonnet::internet_dom($prim);
5549: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5550: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5551: $check_ipaccess = 1;
5552: }
5553: }
5554: }
5555: }
5556: if ($check_ipaccess) {
5557: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5558: unless (defined($cached)) {
5559: my %domconfig =
5560: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5561: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5562: }
5563: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5564: foreach my $id (keys(%{$ipaccessref})) {
5565: if (ref($ipaccessref->{$id}) eq 'HASH') {
5566: my $range = $ipaccessref->{$id}->{'ip'};
5567: if ($range) {
5568: if (&Apache::lonnet::ip_match($clientip,$range)) {
5569: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5570: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5571: return ('','','',$id,$dom);
5572: last;
5573: }
5574: }
5575: }
5576: }
5577: }
5578: }
5579: }
5580: }
1.1373 raeburn 5581: if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5582: return ();
5583: }
1.1372 raeburn 5584: }
1.1189 raeburn 5585: if (defined($udom) && defined($uname)) {
5586: # If uname and udom are for a course, check for blocks in the course.
5587: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5588: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5589: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 5590: return ($startblock,$endblock,$triggerblock);
5591: }
5592: } else {
1.490 raeburn 5593: $udom = $env{'user.domain'};
5594: $uname = $env{'user.name'};
5595: }
5596:
1.502 raeburn 5597: my $startblock = 0;
5598: my $endblock = 0;
1.1062 raeburn 5599: my $triggerblock = '';
1.1373 raeburn 5600: my %live_courses;
5601: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5602: %live_courses = &findallcourses(undef,$uname,$udom);
5603: }
1.474 raeburn 5604:
1.490 raeburn 5605: # If uname is for a user, and activity is course-specific, i.e.,
5606: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5607:
1.490 raeburn 5608: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5609: $activity eq 'groups' || $activity eq 'printout' ||
1.1346 raeburn 5610: $activity eq 'search' || $activity eq 'reinit' ||
5611: $activity eq 'alert') &&
1.1189 raeburn 5612: ($env{'request.course.id'})) {
1.490 raeburn 5613: foreach my $key (keys(%live_courses)) {
5614: if ($key ne $env{'request.course.id'}) {
5615: delete($live_courses{$key});
5616: }
5617: }
5618: }
5619:
5620: my $otheruser = 0;
5621: my %own_courses;
5622: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5623: # Resource belongs to user other than current user.
5624: $otheruser = 1;
5625: # Gather courses for current user
5626: %own_courses =
5627: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5628: }
5629:
5630: # Gather active course roles - course coordinator, instructor,
5631: # exam proctor, ta, student, or custom role.
1.474 raeburn 5632:
5633: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5634: my ($cdom,$cnum);
5635: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5636: $cdom = $env{'course.'.$course.'.domain'};
5637: $cnum = $env{'course.'.$course.'.num'};
5638: } else {
1.490 raeburn 5639: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5640: }
5641: my $no_ownblock = 0;
5642: my $no_userblock = 0;
1.533 raeburn 5643: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5644: # Check if current user has 'evb' priv for this
5645: if (defined($own_courses{$course})) {
5646: foreach my $sec (keys(%{$own_courses{$course}})) {
5647: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5648: if ($sec ne 'none') {
5649: $checkrole .= '/'.$sec;
5650: }
5651: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5652: $no_ownblock = 1;
5653: last;
5654: }
5655: }
5656: }
5657: # if they have 'evb' priv and are currently not playing student
5658: next if (($no_ownblock) &&
5659: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5660: }
1.474 raeburn 5661: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5662: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5663: if ($sec ne 'none') {
1.482 raeburn 5664: $checkrole .= '/'.$sec;
1.474 raeburn 5665: }
1.490 raeburn 5666: if ($otheruser) {
5667: # Resource belongs to user other than current user.
5668: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5669: my (%allroles,%userroles);
5670: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5671: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5672: my ($trole,$tdom,$tnum,$tsec);
5673: if ($entry =~ /^cr/) {
5674: ($trole,$tdom,$tnum,$tsec) =
5675: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5676: } else {
5677: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5678: }
5679: my ($spec,$area,$trest);
5680: $area = '/'.$tdom.'/'.$tnum;
5681: $trest = $tnum;
5682: if ($tsec ne '') {
5683: $area .= '/'.$tsec;
5684: $trest .= '/'.$tsec;
5685: }
5686: $spec = $trole.'.'.$area;
5687: if ($trole =~ /^cr/) {
5688: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5689: $tdom,$spec,$trest,$area);
5690: } else {
5691: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5692: $tdom,$spec,$trest,$area);
5693: }
5694: }
1.1276 raeburn 5695: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5696: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5697: if ($1) {
5698: $no_userblock = 1;
5699: last;
5700: }
1.486 raeburn 5701: }
5702: }
1.490 raeburn 5703: } else {
5704: # Resource belongs to current user
5705: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5706: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5707: $no_ownblock = 1;
5708: last;
5709: }
1.474 raeburn 5710: }
5711: }
5712: # if they have the evb priv and are currently not playing student
1.482 raeburn 5713: next if (($no_ownblock) &&
1.491 albertel 5714: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5715: next if ($no_userblock);
1.474 raeburn 5716:
1.1303 raeburn 5717: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5718: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5719:
1.1062 raeburn 5720: my ($start,$end,$trigger) =
1.1347 raeburn 5721: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5722: if (($start != 0) &&
5723: (($startblock == 0) || ($startblock > $start))) {
5724: $startblock = $start;
1.1062 raeburn 5725: if ($trigger ne '') {
5726: $triggerblock = $trigger;
5727: }
1.502 raeburn 5728: }
5729: if (($end != 0) &&
5730: (($endblock == 0) || ($endblock < $end))) {
5731: $endblock = $end;
1.1062 raeburn 5732: if ($trigger ne '') {
5733: $triggerblock = $trigger;
5734: }
1.502 raeburn 5735: }
1.490 raeburn 5736: }
1.1062 raeburn 5737: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5738: }
5739:
5740: sub get_blocks {
1.1347 raeburn 5741: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5742: my $startblock = 0;
5743: my $endblock = 0;
1.1062 raeburn 5744: my $triggerblock = '';
1.490 raeburn 5745: my $course = $cdom.'_'.$cnum;
5746: $setters->{$course} = {};
5747: $setters->{$course}{'staff'} = [];
5748: $setters->{$course}{'times'} = [];
1.1062 raeburn 5749: $setters->{$course}{'triggers'} = [];
5750: my (@blockers,%triggered);
5751: my $now = time;
5752: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5753: if ($activity eq 'docs') {
1.1348 raeburn 5754: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5755: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5756: $blocked = 1;
5757: $nosymbcache = 1;
1.1348 raeburn 5758: $noenccheck = 1;
1.1347 raeburn 5759: }
1.1348 raeburn 5760: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5761: foreach my $block (@blockers) {
5762: if ($block =~ /^firstaccess____(.+)$/) {
5763: my $item = $1;
5764: my $type = 'map';
5765: my $timersymb = $item;
5766: if ($item eq 'course') {
5767: $type = 'course';
5768: } elsif ($item =~ /___\d+___/) {
5769: $type = 'resource';
5770: } else {
5771: $timersymb = &Apache::lonnet::symbread($item);
5772: }
5773: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5774: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5775: $triggered{$block} = {
5776: start => $start,
5777: end => $end,
5778: type => $type,
5779: };
5780: }
5781: }
5782: } else {
5783: foreach my $block (keys(%commblocks)) {
5784: if ($block =~ m/^(\d+)____(\d+)$/) {
5785: my ($start,$end) = ($1,$2);
5786: if ($start <= time && $end >= time) {
5787: if (ref($commblocks{$block}) eq 'HASH') {
5788: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5789: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5790: unless(grep(/^\Q$block\E$/,@blockers)) {
5791: push(@blockers,$block);
5792: }
5793: }
5794: }
5795: }
5796: }
5797: } elsif ($block =~ /^firstaccess____(.+)$/) {
5798: my $item = $1;
5799: my $timersymb = $item;
5800: my $type = 'map';
5801: if ($item eq 'course') {
5802: $type = 'course';
5803: } elsif ($item =~ /___\d+___/) {
5804: $type = 'resource';
5805: } else {
5806: $timersymb = &Apache::lonnet::symbread($item);
5807: }
5808: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5809: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5810: if ($start && $end) {
5811: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5812: if (ref($commblocks{$block}) eq 'HASH') {
5813: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5814: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5815: unless(grep(/^\Q$block\E$/,@blockers)) {
5816: push(@blockers,$block);
5817: $triggered{$block} = {
5818: start => $start,
5819: end => $end,
5820: type => $type,
5821: };
5822: }
5823: }
5824: }
1.1062 raeburn 5825: }
5826: }
1.490 raeburn 5827: }
1.1062 raeburn 5828: }
5829: }
5830: }
5831: foreach my $blocker (@blockers) {
5832: my ($staff_name,$staff_dom,$title,$blocks) =
5833: &parse_block_record($commblocks{$blocker});
5834: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5835: my ($start,$end,$triggertype);
5836: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5837: ($start,$end) = ($1,$2);
5838: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5839: $start = $triggered{$blocker}{'start'};
5840: $end = $triggered{$blocker}{'end'};
5841: $triggertype = $triggered{$blocker}{'type'};
5842: }
5843: if ($start) {
5844: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5845: if ($triggertype) {
5846: push(@{$$setters{$course}{'triggers'}},$triggertype);
5847: } else {
5848: push(@{$$setters{$course}{'triggers'}},0);
5849: }
5850: if ( ($startblock == 0) || ($startblock > $start) ) {
5851: $startblock = $start;
5852: if ($triggertype) {
5853: $triggerblock = $blocker;
1.474 raeburn 5854: }
5855: }
1.1062 raeburn 5856: if ( ($endblock == 0) || ($endblock < $end) ) {
5857: $endblock = $end;
5858: if ($triggertype) {
5859: $triggerblock = $blocker;
5860: }
5861: }
1.474 raeburn 5862: }
5863: }
1.1062 raeburn 5864: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5865: }
5866:
5867: sub parse_block_record {
5868: my ($record) = @_;
5869: my ($setuname,$setudom,$title,$blocks);
5870: if (ref($record) eq 'HASH') {
5871: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5872: $title = &unescape($record->{'event'});
5873: $blocks = $record->{'blocks'};
5874: } else {
5875: my @data = split(/:/,$record,3);
5876: if (scalar(@data) eq 2) {
5877: $title = $data[1];
5878: ($setuname,$setudom) = split(/@/,$data[0]);
5879: } else {
5880: ($setuname,$setudom,$title) = @data;
5881: }
5882: $blocks = { 'com' => 'on' };
5883: }
5884: return ($setuname,$setudom,$title,$blocks);
5885: }
5886:
1.854 kalberla 5887: sub blocking_status {
1.1372 raeburn 5888: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5889: my %setters;
1.890 droeschl 5890:
1.1061 raeburn 5891: # check for active blocking
1.1372 raeburn 5892: if ($clientip eq '') {
5893: $clientip = &Apache::lonnet::get_requestor_ip();
5894: }
5895: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5896: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5897: my $blocked = 0;
1.1372 raeburn 5898: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5899: $blocked = 1;
5900: }
1.890 droeschl 5901:
1.1061 raeburn 5902: # caller just wants to know whether a block is active
5903: if (!wantarray) { return $blocked; }
5904:
5905: # build a link to a popup window containing the details
5906: my $querystring = "?activity=$activity";
1.1351 raeburn 5907: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5908: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1232 raeburn 5909: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5910: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5911: } elsif ($activity eq 'docs') {
1.1347 raeburn 5912: my $showurl = &Apache::lonenc::check_encrypt($url);
5913: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5914: if ($symb) {
5915: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5916: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5917: }
1.1062 raeburn 5918: }
1.1061 raeburn 5919:
5920: my $output .= <<'END_MYBLOCK';
5921: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5922: var options = "width=" + w + ",height=" + h + ",";
5923: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5924: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5925: var newWin = window.open(url, wdwName, options);
5926: newWin.focus();
5927: }
1.890 droeschl 5928: END_MYBLOCK
1.854 kalberla 5929:
1.1061 raeburn 5930: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5931:
1.1061 raeburn 5932: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5933: my $text = &mt('Communication Blocked');
1.1217 raeburn 5934: my $class = 'LC_comblock';
1.1062 raeburn 5935: if ($activity eq 'docs') {
5936: $text = &mt('Content Access Blocked');
1.1217 raeburn 5937: $class = '';
1.1063 raeburn 5938: } elsif ($activity eq 'printout') {
5939: $text = &mt('Printing Blocked');
1.1232 raeburn 5940: } elsif ($activity eq 'passwd') {
5941: $text = &mt('Password Changing Blocked');
1.1345 raeburn 5942: } elsif ($activity eq 'grades') {
5943: $text = &mt('Gradebook Blocked');
1.1346 raeburn 5944: } elsif ($activity eq 'search') {
5945: $text = &mt('Search Blocked');
1.1282 raeburn 5946: } elsif ($activity eq 'alert') {
5947: $text = &mt('Checking Critical Messages Blocked');
5948: } elsif ($activity eq 'reinit') {
5949: $text = &mt('Checking Course Update Blocked');
1.1351 raeburn 5950: } elsif ($activity eq 'about') {
5951: $text = &mt('Access to User Information Pages Blocked');
1.1373 raeburn 5952: } elsif ($activity eq 'wishlist') {
5953: $text = &mt('Access to Stored Links Blocked');
5954: } elsif ($activity eq 'annotate') {
5955: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 5956: }
1.1061 raeburn 5957: $output .= <<"END_BLOCK";
1.1217 raeburn 5958: <div class='$class'>
1.869 kalberla 5959: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5960: title='$text'>
5961: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5962: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5963: title='$text'>$text</a>
1.867 kalberla 5964: </div>
5965:
5966: END_BLOCK
1.474 raeburn 5967:
1.1061 raeburn 5968: return ($blocked, $output);
1.854 kalberla 5969: }
1.490 raeburn 5970:
1.60 matthew 5971: ###############################################
5972:
1.682 raeburn 5973: sub check_ip_acc {
1.1201 raeburn 5974: my ($acc,$clientip)=@_;
1.682 raeburn 5975: &Apache::lonxml::debug("acc is $acc");
5976: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5977: return 1;
5978: }
1.1339 raeburn 5979: my ($ip,$allowed);
5980: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5981: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5982: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5983: } else {
1.1350 raeburn 5984: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5985: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1339 raeburn 5986: }
1.682 raeburn 5987:
5988: my $name;
1.1219 raeburn 5989: my %access = (
5990: allowfrom => 1,
5991: denyfrom => 0,
5992: );
5993: my @allows;
5994: my @denies;
5995: foreach my $item (split(',',$acc)) {
5996: $item =~ s/^\s*//;
5997: $item =~ s/\s*$//;
5998: my $pattern;
5999: if ($item =~ /^\!(.+)$/) {
6000: push(@denies,$1);
6001: } else {
6002: push(@allows,$item);
6003: }
6004: }
6005: my $numdenies = scalar(@denies);
6006: my $numallows = scalar(@allows);
6007: my $count = 0;
6008: foreach my $pattern (@denies,@allows) {
6009: $count ++;
6010: my $acctype = 'allowfrom';
6011: if ($count <= $numdenies) {
6012: $acctype = 'denyfrom';
6013: }
1.682 raeburn 6014: if ($pattern =~ /\*$/) {
6015: #35.8.*
6016: $pattern=~s/\*//;
1.1219 raeburn 6017: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6018: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
6019: #35.8.3.[34-56]
6020: my $low=$2;
6021: my $high=$3;
6022: $pattern=$1;
6023: if ($ip =~ /^\Q$pattern\E/) {
6024: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 6025: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 6026: }
6027: } elsif ($pattern =~ /^\*/) {
6028: #*.msu.edu
6029: $pattern=~s/\*//;
6030: if (!defined($name)) {
6031: use Socket;
6032: my $netaddr=inet_aton($ip);
6033: ($name)=gethostbyaddr($netaddr,AF_INET);
6034: }
1.1219 raeburn 6035: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 6036: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
6037: #127.0.0.1
1.1219 raeburn 6038: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6039: } else {
6040: #some.name.com
6041: if (!defined($name)) {
6042: use Socket;
6043: my $netaddr=inet_aton($ip);
6044: ($name)=gethostbyaddr($netaddr,AF_INET);
6045: }
1.1219 raeburn 6046: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
6047: }
6048: if ($allowed =~ /^(0|1)$/) { last; }
6049: }
6050: if ($allowed eq '') {
6051: if ($numdenies && !$numallows) {
6052: $allowed = 1;
6053: } else {
6054: $allowed = 0;
1.682 raeburn 6055: }
6056: }
6057: return $allowed;
6058: }
6059:
6060: ###############################################
6061:
1.60 matthew 6062: =pod
6063:
1.112 bowersj2 6064: =head1 Domain Template Functions
6065:
6066: =over 4
6067:
6068: =item * &determinedomain()
1.60 matthew 6069:
6070: Inputs: $domain (usually will be undef)
6071:
1.63 www 6072: Returns: Determines which domain should be used for designs
1.60 matthew 6073:
6074: =cut
1.54 www 6075:
1.60 matthew 6076: ###############################################
1.63 www 6077: sub determinedomain {
6078: my $domain=shift;
1.531 albertel 6079: if (! $domain) {
1.60 matthew 6080: # Determine domain if we have not been given one
1.893 raeburn 6081: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 6082: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
6083: if ($env{'request.role.domain'}) {
6084: $domain=$env{'request.role.domain'};
1.60 matthew 6085: }
6086: }
1.63 www 6087: return $domain;
6088: }
6089: ###############################################
1.517 raeburn 6090:
1.518 albertel 6091: sub devalidate_domconfig_cache {
6092: my ($udom)=@_;
6093: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
6094: }
6095:
6096: # ---------------------- Get domain configuration for a domain
6097: sub get_domainconf {
6098: my ($udom) = @_;
6099: my $cachetime=1800;
6100: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
6101: if (defined($cached)) { return %{$result}; }
6102:
6103: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 6104: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 6105: my (%designhash,%legacy);
1.518 albertel 6106: if (keys(%domconfig) > 0) {
6107: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 6108: if (keys(%{$domconfig{'login'}})) {
6109: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 6110: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 6111: if (($key eq 'loginvia') || ($key eq 'headtag')) {
6112: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6113: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
6114: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
6115: if ($key eq 'loginvia') {
6116: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
6117: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
6118: $designhash{$udom.'.login.loginvia'} = $server;
6119: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
6120:
6121: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
6122: } else {
6123: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
6124: }
1.948 raeburn 6125: }
1.1208 raeburn 6126: } elsif ($key eq 'headtag') {
6127: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
6128: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 6129: }
1.946 raeburn 6130: }
1.1208 raeburn 6131: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
6132: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
6133: }
1.946 raeburn 6134: }
6135: }
6136: }
1.1366 raeburn 6137: } elsif ($key eq 'saml') {
6138: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6139: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
6140: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
6141: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
1.1386 raeburn 6142: foreach my $item ('text','img','alt','url','title','window','notsso') {
1.1366 raeburn 6143: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
6144: }
6145: }
6146: }
6147: }
1.946 raeburn 6148: } else {
6149: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
6150: $designhash{$udom.'.login.'.$key.'_'.$img} =
6151: $domconfig{'login'}{$key}{$img};
6152: }
1.699 raeburn 6153: }
6154: } else {
6155: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
6156: }
1.632 raeburn 6157: }
6158: } else {
6159: $legacy{'login'} = 1;
1.518 albertel 6160: }
1.632 raeburn 6161: } else {
6162: $legacy{'login'} = 1;
1.518 albertel 6163: }
6164: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 6165: if (keys(%{$domconfig{'rolecolors'}})) {
6166: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
6167: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
6168: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
6169: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
6170: }
1.518 albertel 6171: }
6172: }
1.632 raeburn 6173: } else {
6174: $legacy{'rolecolors'} = 1;
1.518 albertel 6175: }
1.632 raeburn 6176: } else {
6177: $legacy{'rolecolors'} = 1;
1.518 albertel 6178: }
1.948 raeburn 6179: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6180: if ($domconfig{'autoenroll'}{'co-owners'}) {
6181: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
6182: }
6183: }
1.632 raeburn 6184: if (keys(%legacy) > 0) {
6185: my %legacyhash = &get_legacy_domconf($udom);
6186: foreach my $item (keys(%legacyhash)) {
6187: if ($item =~ /^\Q$udom\E\.login/) {
6188: if ($legacy{'login'}) {
6189: $designhash{$item} = $legacyhash{$item};
6190: }
6191: } else {
6192: if ($legacy{'rolecolors'}) {
6193: $designhash{$item} = $legacyhash{$item};
6194: }
1.518 albertel 6195: }
6196: }
6197: }
1.632 raeburn 6198: } else {
6199: %designhash = &get_legacy_domconf($udom);
1.518 albertel 6200: }
6201: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
6202: $cachetime);
6203: return %designhash;
6204: }
6205:
1.632 raeburn 6206: sub get_legacy_domconf {
6207: my ($udom) = @_;
6208: my %legacyhash;
6209: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
6210: my $designfile = $designdir.'/'.$udom.'.tab';
6211: if (-e $designfile) {
1.1317 raeburn 6212: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 6213: while (my $line = <$fh>) {
6214: next if ($line =~ /^\#/);
6215: chomp($line);
6216: my ($key,$val)=(split(/\=/,$line));
6217: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
6218: }
6219: close($fh);
6220: }
6221: }
1.1026 raeburn 6222: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 6223: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
6224: }
6225: return %legacyhash;
6226: }
6227:
1.63 www 6228: =pod
6229:
1.112 bowersj2 6230: =item * &domainlogo()
1.63 www 6231:
6232: Inputs: $domain (usually will be undef)
6233:
6234: Returns: A link to a domain logo, if the domain logo exists.
6235: If the domain logo does not exist, a description of the domain.
6236:
6237: =cut
1.112 bowersj2 6238:
1.63 www 6239: ###############################################
6240: sub domainlogo {
1.517 raeburn 6241: my $domain = &determinedomain(shift);
1.518 albertel 6242: my %designhash = &get_domainconf($domain);
1.517 raeburn 6243: # See if there is a logo
6244: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 6245: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 6246: if ($imgsrc =~ m{^/(adm|res)/}) {
6247: if ($imgsrc =~ m{^/res/}) {
6248: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
6249: &Apache::lonnet::repcopy($local_name);
6250: }
6251: $imgsrc = &lonhttpdurl($imgsrc);
1.1374 raeburn 6252: }
6253: my $alttext = $domain;
6254: if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
6255: $alttext = $designhash{$domain.'.login.alttext_domlogo'};
6256: }
6257: return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 6258: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
6259: return &Apache::lonnet::domain($domain,'description');
1.59 www 6260: } else {
1.60 matthew 6261: return '';
1.59 www 6262: }
6263: }
1.63 www 6264: ##############################################
6265:
6266: =pod
6267:
1.112 bowersj2 6268: =item * &designparm()
1.63 www 6269:
6270: Inputs: $which parameter; $domain (usually will be undef)
6271:
6272: Returns: value of designparamter $which
6273:
6274: =cut
1.112 bowersj2 6275:
1.397 albertel 6276:
1.400 albertel 6277: ##############################################
1.397 albertel 6278: sub designparm {
6279: my ($which,$domain)=@_;
6280: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 6281: return $env{'environment.color.'.$which};
1.96 www 6282: }
1.63 www 6283: $domain=&determinedomain($domain);
1.1016 raeburn 6284: my %domdesign;
6285: unless ($domain eq 'public') {
6286: %domdesign = &get_domainconf($domain);
6287: }
1.520 raeburn 6288: my $output;
1.517 raeburn 6289: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 6290: $output = $domdesign{$domain.'.'.$which};
1.63 www 6291: } else {
1.520 raeburn 6292: $output = $defaultdesign{$which};
6293: }
6294: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 6295: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 6296: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 6297: if ($output =~ m{^/res/}) {
6298: my $local_name = &Apache::lonnet::filelocation('',$output);
6299: &Apache::lonnet::repcopy($local_name);
6300: }
1.520 raeburn 6301: $output = &lonhttpdurl($output);
6302: }
1.63 www 6303: }
1.520 raeburn 6304: return $output;
1.63 www 6305: }
1.59 www 6306:
1.822 bisitz 6307: ##############################################
6308: =pod
6309:
1.832 bisitz 6310: =item * &authorspace()
6311:
1.1028 raeburn 6312: Inputs: $url (usually will be undef).
1.832 bisitz 6313:
1.1132 raeburn 6314: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 6315: directory being viewed (or for which action is being taken).
6316: If $url is provided, and begins /priv/<domain>/<uname>
6317: the path will be that portion of the $context argument.
6318: Otherwise the path will be for the author space of the current
6319: user when the current role is author, or for that of the
6320: co-author/assistant co-author space when the current role
6321: is co-author or assistant co-author.
1.832 bisitz 6322:
6323: =cut
6324:
6325: sub authorspace {
1.1028 raeburn 6326: my ($url) = @_;
6327: if ($url ne '') {
6328: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
6329: return $1;
6330: }
6331: }
1.832 bisitz 6332: my $caname = '';
1.1024 www 6333: my $cadom = '';
1.1028 raeburn 6334: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 6335: ($cadom,$caname) =
1.832 bisitz 6336: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 6337: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 6338: $caname = $env{'user.name'};
1.1024 www 6339: $cadom = $env{'user.domain'};
1.832 bisitz 6340: }
1.1028 raeburn 6341: if (($caname ne '') && ($cadom ne '')) {
6342: return "/priv/$cadom/$caname/";
6343: }
6344: return;
1.832 bisitz 6345: }
6346:
6347: ##############################################
6348: =pod
6349:
1.822 bisitz 6350: =item * &head_subbox()
6351:
6352: Inputs: $content (contains HTML code with page functions, etc.)
6353:
6354: Returns: HTML div with $content
6355: To be included in page header
6356:
6357: =cut
6358:
6359: sub head_subbox {
6360: my ($content)=@_;
6361: my $output =
1.993 raeburn 6362: '<div class="LC_head_subbox">'
1.822 bisitz 6363: .$content
6364: .'</div>'
6365: }
6366:
6367: ##############################################
6368: =pod
6369:
6370: =item * &CSTR_pageheader()
6371:
1.1026 raeburn 6372: Input: (optional) filename from which breadcrumb trail is built.
6373: In most cases no input as needed, as $env{'request.filename'}
6374: is appropriate for use in building the breadcrumb trail.
1.1379 raeburn 6375: frameset flag
6376: If page header is being requested for use in a frameset, then
6377: the second (option) argument -- frameset will be true, and
6378: the target attribute set for links should be target="_parent".
1.1407 raeburn 6379: If $title is supplied as the thitd arg, that will be used to
6380: the left of the breadcrumbs tail for the current path.
1.822 bisitz 6381:
6382: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 6383: To be included on Authoring Space pages
1.822 bisitz 6384:
6385: =cut
6386:
6387: sub CSTR_pageheader {
1.1407 raeburn 6388: my ($trailfile,$frameset,$title) = @_;
1.1026 raeburn 6389: if ($trailfile eq '') {
6390: $trailfile = $env{'request.filename'};
6391: }
6392:
6393: # this is for resources; directories have customtitle, and crumbs
6394: # and select recent are created in lonpubdir.pm
6395:
6396: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 6397: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 6398: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 6399: my $formaction = "/priv/$udom/$uname/$thisdisfn";
6400: $formaction =~ s{/+}{/}g;
1.822 bisitz 6401:
6402: my $parentpath = '';
6403: my $lastitem = '';
6404: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
6405: $parentpath = $1;
6406: $lastitem = $2;
6407: } else {
6408: $lastitem = $thisdisfn;
6409: }
1.921 bisitz 6410:
1.1406 raeburn 6411: my $crsauthor;
1.1246 raeburn 6412: if (($env{'request.course.id'}) &&
6413: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 6414: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 6415: $crsauthor = 1;
1.1406 raeburn 6416: if ($title eq '') {
6417: $title = &mt('Course Authoring Space');
6418: }
6419: } elsif ($title eq '') {
1.1246 raeburn 6420: $title = &mt('Authoring Space');
6421: }
6422:
1.1379 raeburn 6423: my ($target,$crumbtarget) = (' target="_top"','_top');
6424: if ($frameset) {
6425: $target = ' target="_parent"';
6426: $crumbtarget = '_parent';
6427: } elsif (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 6428: $target = '';
6429: $crumbtarget = '';
1.1379 raeburn 6430: } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {
1.1378 raeburn 6431: $target = ' target="'.$env{'request.deeplink.target'}.'"';
6432: $crumbtarget = $env{'request.deeplink.target'};
6433: }
1.1313 raeburn 6434:
1.921 bisitz 6435: my $output =
1.1407 raeburn 6436: '<div>'
1.822 bisitz 6437: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 6438: .'<b>'.$title.'</b> '
1.1314 raeburn 6439: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6440: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6441:
6442: if ($lastitem) {
6443: $output .=
6444: '<span class="LC_filename">'
6445: .$lastitem
6446: .'</span>';
6447: }
1.1245 raeburn 6448:
1.1246 raeburn 6449: if ($crsauthor) {
1.1379 raeburn 6450: $output .= '</form>'.&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6451: } else {
6452: $output .=
6453: '<br />'
1.1314 raeburn 6454: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 6455: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6456: .'</form>'
1.1379 raeburn 6457: .&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6458: }
1.1407 raeburn 6459: $output .= '</div>';
1.921 bisitz 6460:
6461: return $output;
1.822 bisitz 6462: }
6463:
1.1416 raeburn 6464: sub nocodemirror {
6465: my $nocodem = $env{'environment.nocodemirror'};
6466: unless ($nocodem) {
6467: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
6468: if ($domdefs{'nocodemirror'}) {
6469: $nocodem = 'yes';
6470: }
6471: }
1.1417 raeburn 6472: if ($nocodem eq 'yes') {
6473: return 1;
6474: }
6475: return;
1.1416 raeburn 6476: }
6477:
1.1418 ! raeburn 6478: sub permitted_editors {
! 6479: my ($is_author,$is_coauthor,$auname,$audom,%editors);
! 6480: if ($env{'request.role'} =~ m{^au\./}) {
! 6481: $is_author = 1;
! 6482: } elsif ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)}) {
! 6483: ($audom,$auname) = ($1,$2);
! 6484: if (($audom ne '') && ($auname ne '')) {
! 6485: if (($env{'user.domain'} eq $audom) &&
! 6486: ($env{'user.name'} eq $auname)) {
! 6487: $is_author = 1;
! 6488: } else {
! 6489: $is_coauthor = 1;
! 6490: }
! 6491: }
! 6492: } elsif ($env{'request.course.id'}) {
! 6493: if ($env{'request.editurl'} =~ m{^/priv/($match_domain)/($match_username)/}) {
! 6494: ($audom,$auname) = ($1,$2);
! 6495: } elsif ($env{'request.uri'} =~ m{^/priv/($match_domain)/($match_username)/}) {
! 6496: ($audom,$auname) = ($1,$2);
! 6497: }
! 6498: if (($audom ne '') && ($auname ne '')) {
! 6499: if (($env{'user.domain'} eq $audom) &&
! 6500: ($env{'user.name'} eq $auname)) {
! 6501: $is_author = 1;
! 6502: } else {
! 6503: $is_coauthor = 1;
! 6504: }
! 6505: }
! 6506: }
! 6507: if ($is_author) {
! 6508: if (exists($env{'environment.editors'})) {
! 6509: map { $editors{$_} = 1; } split(/,/,$env{'environment.editors'});
! 6510: } else {
! 6511: %editors = ( edit => 1,
! 6512: xml => 1,
! 6513: );
! 6514: }
! 6515: } elsif ($is_coauthor) {
! 6516: if (exists($env{"environment.internal.editors./$audom/$auname"})) {
! 6517: map { $editors{$_} = 1; } split(/,/,$env{"environment.internal.editors./$audom/$auname"});
! 6518: } else {
! 6519: %editors = ( edit => 1,
! 6520: xml => 1,
! 6521: );
! 6522: }
! 6523: } else {
! 6524: %editors = ( edit => 1,
! 6525: xml => 1,
! 6526: );
! 6527: }
! 6528: return %editors;
! 6529: }
! 6530:
1.60 matthew 6531: ###############################################
6532: ###############################################
6533:
6534: =pod
6535:
1.112 bowersj2 6536: =back
6537:
1.549 albertel 6538: =head1 HTML Helpers
1.112 bowersj2 6539:
6540: =over 4
6541:
6542: =item * &bodytag()
1.60 matthew 6543:
6544: Returns a uniform header for LON-CAPA web pages.
6545:
6546: Inputs:
6547:
1.112 bowersj2 6548: =over 4
6549:
6550: =item * $title, A title to be displayed on the page.
6551:
6552: =item * $function, the current role (can be undef).
6553:
6554: =item * $addentries, extra parameters for the <body> tag.
6555:
6556: =item * $bodyonly, if defined, only return the <body> tag.
6557:
6558: =item * $domain, if defined, force a given domain.
6559:
6560: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6561: text interface only)
1.60 matthew 6562:
1.814 bisitz 6563: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6564: navigational links
1.317 albertel 6565:
1.338 albertel 6566: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6567:
1.460 albertel 6568: =item * $args, optional argument valid values are
6569: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6570: use_absolute -> for external resource or syllabus, this will
6571: contain https://<hostname> if server uses
6572: https (as per hosts.tab), but request is for http
6573: hostname -> hostname, from $r->hostname().
1.460 albertel 6574:
1.1096 raeburn 6575: =item * $advtoolsref, optional argument, ref to an array containing
6576: inlineremote items to be added in "Functions" menu below
6577: breadcrumbs.
6578:
1.1316 raeburn 6579: =item * $ltiscope, optional argument, will be one of: resource, map or
6580: course, if LON-CAPA is in LTI Provider context. Value is
6581: the scope of use, i.e., launch was for access to a single, a map
6582: or the entire course.
6583:
6584: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6585: context, this will contain the URL for the landing item in
6586: the course, after launch from an LTI Consumer
6587:
1.1318 raeburn 6588: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6589: context, this will contain a reference to hash of items
6590: to be included in the page header and/or inline menu.
6591:
1.1385 raeburn 6592: =item * $menucoll, optional argument, if specific menu collection is in
6593: effect, either set as the default for the course, or set for
6594: the deeplink paramater for $env{'request.deeplink.login'}
6595: then $menucoll will be the number of that collection.
6596:
6597: =item * $menuref, optional argument, reference to a hash, containing the
6598: menu options included for the menu in effect, based on the
6599: configuration for the numbered menu collection in use.
6600:
6601: =item * $showncrumbsref, reference to a scalar. Calls to lonmenu::innerregister
6602: within &bodytag() can result in calls to lonhtmlcommon::breadcrumbs(),
6603: if so, $showncrumbsref is set there to 1, and will propagate back
6604: via &bodytag() to &start_page(), to prevent lonhtmlcommon::breadcrumbs()
6605: being called a second time.
6606:
1.112 bowersj2 6607: =back
6608:
1.60 matthew 6609: Returns: A uniform header for LON-CAPA web pages.
6610: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6611: If $bodyonly is undef or zero, an html string containing a <body> tag and
6612: other decorations will be returned.
6613:
6614: =cut
6615:
1.54 www 6616: sub bodytag {
1.831 bisitz 6617: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1359 raeburn 6618: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,
1.1385 raeburn 6619: $ltimenu,$menucoll,$menuref,$showncrumbsref)=@_;
1.339 albertel 6620:
1.954 raeburn 6621: my $public;
6622: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6623: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6624: $public = 1;
6625: }
1.460 albertel 6626: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6627: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6628: my $hostname = $args->{'hostname'};
1.339 albertel 6629:
1.183 matthew 6630: $function = &get_users_function() if (!$function);
1.339 albertel 6631: my $img = &designparm($function.'.img',$domain);
6632: my $font = &designparm($function.'.font',$domain);
6633: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6634:
1.803 bisitz 6635: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6636: 'bgcolor' => $pgbg,
1.339 albertel 6637: 'text' => $font,
6638: 'alink' => &designparm($function.'.alink',$domain),
6639: 'vlink' => &designparm($function.'.vlink',$domain),
6640: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6641: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6642:
1.63 www 6643: # role and realm
1.1178 raeburn 6644: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6645: if ($realm) {
6646: $realm = '/'.$realm;
6647: }
1.1357 raeburn 6648: if ($role eq 'ca') {
1.479 albertel 6649: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6650: $realm = &plainname($rname,$rdom);
1.378 raeburn 6651: }
1.55 www 6652: # realm
1.1357 raeburn 6653: my ($cid,$sec);
1.258 albertel 6654: if ($env{'request.course.id'}) {
1.1357 raeburn 6655: $cid = $env{'request.course.id'};
6656: if ($env{'request.course.sec'}) {
6657: $sec = $env{'request.course.sec'};
6658: }
6659: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6660: if (&Apache::lonnet::is_course($1,$2)) {
6661: $cid = $1.'_'.$2;
6662: $sec = $3;
6663: }
6664: }
6665: if ($cid) {
1.378 raeburn 6666: if ($env{'request.role'} !~ /^cr/) {
6667: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6668: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6669: if ($env{'request.role.desc'}) {
6670: $role = $env{'request.role.desc'};
6671: } else {
6672: $role = &mt('Helpdesk[_1]',' '.$2);
6673: }
1.1257 raeburn 6674: } else {
6675: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6676: }
1.1357 raeburn 6677: if ($sec) {
6678: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6679: }
1.1357 raeburn 6680: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6681: } else {
6682: $role = &Apache::lonnet::plaintext($role);
1.54 www 6683: }
1.433 albertel 6684:
1.359 albertel 6685: if (!$realm) { $realm=' '; }
1.330 albertel 6686:
1.438 albertel 6687: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6688:
1.101 www 6689: # construct main body tag
1.359 albertel 6690: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6691: &Apache::lontexconvert::init_math_support();
1.252 albertel 6692:
1.1131 raeburn 6693: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6694:
1.1130 raeburn 6695: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6696: return $bodytag;
1.1130 raeburn 6697: }
1.359 albertel 6698:
1.954 raeburn 6699: if ($public) {
1.433 albertel 6700: undef($role);
6701: }
1.1318 raeburn 6702:
1.1359 raeburn 6703: my $showcrstitle = 1;
1.1357 raeburn 6704: if (($cid) && ($env{'request.lti.login'})) {
1.1318 raeburn 6705: if (ref($ltimenu) eq 'HASH') {
6706: unless ($ltimenu->{'role'}) {
6707: undef($role);
6708: }
6709: unless ($ltimenu->{'coursetitle'}) {
6710: $realm=' ';
1.1359 raeburn 6711: $showcrstitle = 0;
6712: }
6713: }
6714: } elsif (($cid) && ($menucoll)) {
6715: if (ref($menuref) eq 'HASH') {
6716: unless ($menuref->{'role'}) {
6717: undef($role);
6718: }
6719: unless ($menuref->{'crs'}) {
6720: $realm=' ';
6721: $showcrstitle = 0;
1.1318 raeburn 6722: }
6723: }
6724: }
6725:
1.762 bisitz 6726: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6727: #
6728: # Extra info if you are the DC
6729: my $dc_info = '';
1.1359 raeburn 6730: if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1357 raeburn 6731: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6732: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6733: $dc_info =~ s/\s+$//;
1.359 albertel 6734: }
6735:
1.1237 raeburn 6736: my $crstype;
1.1357 raeburn 6737: if ($cid) {
6738: $crstype = $env{'course.'.$cid.'.type'};
1.1237 raeburn 6739: } elsif ($args->{'crstype'}) {
6740: $crstype = $args->{'crstype'};
6741: }
6742: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6743: undef($role);
6744: } else {
1.1242 raeburn 6745: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6746: }
1.853 droeschl 6747:
1.903 droeschl 6748: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6749:
6750: # if ($env{'request.state'} eq 'construct') {
6751: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6752: # }
6753:
1.1130 raeburn 6754: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6755: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6756:
1.1318 raeburn 6757: unless ($args->{'no_primary_menu'}) {
1.1369 raeburn 6758: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
1.1380 raeburn 6759: $args->{'links_disabled'},
6760: $args->{'links_target'});
1.359 albertel 6761:
1.1318 raeburn 6762: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6763: if ($dc_info) {
6764: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6765: }
6766: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6767: <em>$realm</em> $dc_info</div>|;
6768: return $bodytag;
6769: }
1.894 droeschl 6770:
1.1318 raeburn 6771: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6772: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6773: }
1.916 droeschl 6774:
1.1318 raeburn 6775: $bodytag .= $right;
1.852 droeschl 6776:
1.1318 raeburn 6777: if ($dc_info) {
6778: $dc_info = &dc_courseid_toggle($dc_info);
6779: }
6780: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6781: }
1.916 droeschl 6782:
1.1169 raeburn 6783: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6784: if ($args->{'no_secondary_menu'}) {
6785: return $bodytag;
6786: }
1.1169 raeburn 6787: #don't show menus for public users
1.954 raeburn 6788: if (!$public){
1.1318 raeburn 6789: unless ($args->{'no_inline_menu'}) {
6790: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
1.1359 raeburn 6791: $args->{'no_primary_menu'},
1.1369 raeburn 6792: $menucoll,$menuref,
1.1380 raeburn 6793: $args->{'links_disabled'},
6794: $args->{'links_target'});
1.1318 raeburn 6795: }
1.903 droeschl 6796: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6797: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6798: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6799: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1385 raeburn 6800: $args->{'bread_crumbs'},'','',$hostname,
6801: $ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 6802: } elsif ($forcereg) {
6803: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1385 raeburn 6804: $args->{'group'},$args->{'hide_buttons'},
6805: $hostname,$ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 6806: } else {
6807: $bodytag .=
6808: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6809: $forcereg,$args->{'group'},
6810: $args->{'bread_crumbs'},
1.1274 raeburn 6811: $advtoolsref,'',$hostname);
1.920 raeburn 6812: }
1.903 droeschl 6813: }else{
6814: # this is to seperate menu from content when there's no secondary
6815: # menu. Especially needed for public accessible ressources.
6816: $bodytag .= '<hr style="clear:both" />';
6817: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6818: }
1.903 droeschl 6819:
1.235 raeburn 6820: return $bodytag;
1.182 matthew 6821: }
6822:
1.917 raeburn 6823: sub dc_courseid_toggle {
6824: my ($dc_info) = @_;
1.980 raeburn 6825: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6826: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6827: &mt('(More ...)').'</a></span>'.
6828: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6829: }
6830:
1.330 albertel 6831: sub make_attr_string {
6832: my ($register,$attr_ref) = @_;
6833:
6834: if ($attr_ref && !ref($attr_ref)) {
6835: die("addentries Must be a hash ref ".
6836: join(':',caller(1))." ".
6837: join(':',caller(0))." ");
6838: }
6839:
6840: if ($register) {
1.339 albertel 6841: my ($on_load,$on_unload);
6842: foreach my $key (keys(%{$attr_ref})) {
6843: if (lc($key) eq 'onload') {
6844: $on_load.=$attr_ref->{$key}.';';
6845: delete($attr_ref->{$key});
6846:
6847: } elsif (lc($key) eq 'onunload') {
6848: $on_unload.=$attr_ref->{$key}.';';
6849: delete($attr_ref->{$key});
6850: }
6851: }
1.953 droeschl 6852: $attr_ref->{'onload'} = $on_load;
6853: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6854: }
1.339 albertel 6855:
1.330 albertel 6856: my $attr_string;
1.1159 raeburn 6857: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6858: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6859: }
6860: return $attr_string;
6861: }
6862:
6863:
1.182 matthew 6864: ###############################################
1.251 albertel 6865: ###############################################
6866:
6867: =pod
6868:
6869: =item * &endbodytag()
6870:
6871: Returns a uniform footer for LON-CAPA web pages.
6872:
1.635 raeburn 6873: Inputs: 1 - optional reference to an args hash
6874: If in the hash, key for noredirectlink has a value which evaluates to true,
6875: a 'Continue' link is not displayed if the page contains an
6876: internal redirect in the <head></head> section,
6877: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6878:
6879: =cut
6880:
6881: sub endbodytag {
1.635 raeburn 6882: my ($args) = @_;
1.1080 raeburn 6883: my $endbodytag;
6884: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6885: $endbodytag='</body>';
6886: }
1.315 albertel 6887: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6888: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
1.1386 raeburn 6889: my ($endbodyjs,$idattr);
6890: if ($env{'internal.head.to_opener'}) {
6891: my $linkid = 'LC_continue_link';
6892: $idattr = ' id="'.$linkid.'"';
6893: my $redirect_for_js = &js_escape($env{'internal.head.redirect'});
6894: $endbodyjs=<<ENDJS;
6895: <script type="text/javascript">
6896: // <![CDATA[
6897: function ebFunction(evt) {
6898: evt.preventDefault();
6899: var dest = '$redirect_for_js';
6900: if (window.opener != null && !window.opener.closed) {
6901: window.opener.location.href=dest;
6902: window.close();
6903: } else {
6904: window.location.href=dest;
6905: }
6906: return false;
6907: }
6908:
6909: \$(document).ready(function () {
6910: if (document.getElementById('$linkid')) {
6911: var clickelem = document.getElementById('$linkid');
6912: clickelem.addEventListener('click',ebFunction,false);
6913: }
6914: });
6915: // ]]>
6916: </script>
6917: ENDJS
6918: }
1.635 raeburn 6919: $endbodytag=
1.1386 raeburn 6920: "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".
1.635 raeburn 6921: &mt('Continue').'</a>'.
6922: $endbodytag;
6923: }
1.315 albertel 6924: }
1.1411 raeburn 6925: if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
6926: $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
6927: }
1.251 albertel 6928: return $endbodytag;
6929: }
6930:
1.352 albertel 6931: =pod
6932:
6933: =item * &standard_css()
6934:
6935: Returns a style sheet
6936:
6937: Inputs: (all optional)
6938: domain -> force to color decorate a page for a specific
6939: domain
6940: function -> force usage of a specific rolish color scheme
6941: bgcolor -> override the default page bgcolor
6942:
6943: =cut
6944:
1.343 albertel 6945: sub standard_css {
1.345 albertel 6946: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6947: $function = &get_users_function() if (!$function);
6948: my $img = &designparm($function.'.img', $domain);
6949: my $tabbg = &designparm($function.'.tabbg', $domain);
6950: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6951: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6952: #second colour for later usage
1.345 albertel 6953: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6954: my $pgbg_or_bgcolor =
6955: $bgcolor ||
1.352 albertel 6956: &designparm($function.'.pgbg', $domain);
1.382 albertel 6957: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6958: my $alink = &designparm($function.'.alink', $domain);
6959: my $vlink = &designparm($function.'.vlink', $domain);
6960: my $link = &designparm($function.'.link', $domain);
6961:
1.602 albertel 6962: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6963: my $mono = 'monospace';
1.850 bisitz 6964: my $data_table_head = $sidebg;
6965: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6966: my $data_table_dark = '#E0E0E0';
1.470 banghart 6967: my $data_table_darker = '#CCCCCC';
1.349 albertel 6968: my $data_table_highlight = '#FFFF00';
1.352 albertel 6969: my $mail_new = '#FFBB77';
6970: my $mail_new_hover = '#DD9955';
6971: my $mail_read = '#BBBB77';
6972: my $mail_read_hover = '#999944';
6973: my $mail_replied = '#AAAA88';
6974: my $mail_replied_hover = '#888855';
6975: my $mail_other = '#99BBBB';
6976: my $mail_other_hover = '#669999';
1.391 albertel 6977: my $table_header = '#DDDDDD';
1.489 raeburn 6978: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6979: my $lg_border_color = '#C8C8C8';
1.952 onken 6980: my $button_hover = '#BF2317';
1.392 albertel 6981:
1.608 albertel 6982: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6983: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6984: : '0 3px 0 4px';
1.448 albertel 6985:
1.523 albertel 6986:
1.343 albertel 6987: return <<END;
1.947 droeschl 6988:
6989: /* needed for iframe to allow 100% height in FF */
6990: body, html {
6991: margin: 0;
6992: padding: 0 0.5%;
6993: height: 99%; /* to avoid scrollbars */
6994: }
6995:
1.795 www 6996: body {
1.911 bisitz 6997: font-family: $sans;
6998: line-height:130%;
6999: font-size:0.83em;
7000: color:$font;
1.795 www 7001: }
7002:
1.959 onken 7003: a:focus,
7004: a:focus img {
1.795 www 7005: color: red;
7006: }
1.698 harmsja 7007:
1.911 bisitz 7008: form, .inline {
7009: display: inline;
1.795 www 7010: }
1.721 harmsja 7011:
1.795 www 7012: .LC_right {
1.911 bisitz 7013: text-align:right;
1.795 www 7014: }
7015:
7016: .LC_middle {
1.911 bisitz 7017: vertical-align:middle;
1.795 www 7018: }
1.721 harmsja 7019:
1.1130 raeburn 7020: .LC_floatleft {
7021: float: left;
7022: }
7023:
7024: .LC_floatright {
7025: float: right;
7026: }
7027:
1.911 bisitz 7028: .LC_400Box {
7029: width:400px;
7030: }
1.721 harmsja 7031:
1.947 droeschl 7032: .LC_iframecontainer {
7033: width: 98%;
7034: margin: 0;
7035: position: fixed;
7036: top: 8.5em;
7037: bottom: 0;
7038: }
7039:
7040: .LC_iframecontainer iframe{
7041: border: none;
7042: width: 100%;
7043: height: 100%;
7044: }
7045:
1.778 bisitz 7046: .LC_filename {
7047: font-family: $mono;
7048: white-space:pre;
1.921 bisitz 7049: font-size: 120%;
1.778 bisitz 7050: }
7051:
7052: .LC_fileicon {
7053: border: none;
7054: height: 1.3em;
7055: vertical-align: text-bottom;
7056: margin-right: 0.3em;
7057: text-decoration:none;
7058: }
7059:
1.1008 www 7060: .LC_setting {
7061: text-decoration:underline;
7062: }
7063:
1.350 albertel 7064: .LC_error {
7065: color: red;
7066: }
1.795 www 7067:
1.1097 bisitz 7068: .LC_warning {
7069: color: darkorange;
7070: }
7071:
1.457 albertel 7072: .LC_diff_removed {
1.733 bisitz 7073: color: red;
1.394 albertel 7074: }
1.532 albertel 7075:
7076: .LC_info,
1.457 albertel 7077: .LC_success,
7078: .LC_diff_added {
1.350 albertel 7079: color: green;
7080: }
1.795 www 7081:
1.802 bisitz 7082: div.LC_confirm_box {
7083: background-color: #FAFAFA;
7084: border: 1px solid $lg_border_color;
7085: margin-right: 0;
7086: padding: 5px;
7087: }
7088:
7089: div.LC_confirm_box .LC_error img,
7090: div.LC_confirm_box .LC_success img {
7091: vertical-align: middle;
7092: }
7093:
1.1242 raeburn 7094: .LC_maxwidth {
7095: max-width: 100%;
7096: height: auto;
7097: }
7098:
1.1243 raeburn 7099: .LC_textsize_mobile {
7100: \@media only screen and (max-device-width: 480px) {
7101: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
7102: }
7103: }
7104:
1.440 albertel 7105: .LC_icon {
1.771 droeschl 7106: border: none;
1.790 droeschl 7107: vertical-align: middle;
1.771 droeschl 7108: }
7109:
1.543 albertel 7110: .LC_docs_spacer {
7111: width: 25px;
7112: height: 1px;
1.771 droeschl 7113: border: none;
1.543 albertel 7114: }
1.346 albertel 7115:
1.532 albertel 7116: .LC_internal_info {
1.735 bisitz 7117: color: #999999;
1.532 albertel 7118: }
7119:
1.794 www 7120: .LC_discussion {
1.1050 www 7121: background: $data_table_dark;
1.911 bisitz 7122: border: 1px solid black;
7123: margin: 2px;
1.794 www 7124: }
7125:
7126: .LC_disc_action_left {
1.1050 www 7127: background: $sidebg;
1.911 bisitz 7128: text-align: left;
1.1050 www 7129: padding: 4px;
7130: margin: 2px;
1.794 www 7131: }
7132:
7133: .LC_disc_action_right {
1.1050 www 7134: background: $sidebg;
1.911 bisitz 7135: text-align: right;
1.1050 www 7136: padding: 4px;
7137: margin: 2px;
1.794 www 7138: }
7139:
7140: .LC_disc_new_item {
1.911 bisitz 7141: background: white;
7142: border: 2px solid red;
1.1050 www 7143: margin: 4px;
7144: padding: 4px;
1.794 www 7145: }
7146:
7147: .LC_disc_old_item {
1.911 bisitz 7148: background: white;
1.1050 www 7149: margin: 4px;
7150: padding: 4px;
1.794 www 7151: }
7152:
1.458 albertel 7153: table.LC_pastsubmission {
7154: border: 1px solid black;
7155: margin: 2px;
7156: }
7157:
1.924 bisitz 7158: table#LC_menubuttons {
1.345 albertel 7159: width: 100%;
7160: background: $pgbg;
1.392 albertel 7161: border: 2px;
1.402 albertel 7162: border-collapse: separate;
1.803 bisitz 7163: padding: 0;
1.345 albertel 7164: }
1.392 albertel 7165:
1.801 tempelho 7166: table#LC_title_bar a {
7167: color: $fontmenu;
7168: }
1.836 bisitz 7169:
1.807 droeschl 7170: table#LC_title_bar {
1.819 tempelho 7171: clear: both;
1.836 bisitz 7172: display: none;
1.807 droeschl 7173: }
7174:
1.795 www 7175: table#LC_title_bar,
1.933 droeschl 7176: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 7177: table#LC_title_bar.LC_with_remote {
1.359 albertel 7178: width: 100%;
1.392 albertel 7179: border-color: $pgbg;
7180: border-style: solid;
7181: border-width: $border;
1.379 albertel 7182: background: $pgbg;
1.801 tempelho 7183: color: $fontmenu;
1.392 albertel 7184: border-collapse: collapse;
1.803 bisitz 7185: padding: 0;
1.819 tempelho 7186: margin: 0;
1.359 albertel 7187: }
1.795 www 7188:
1.933 droeschl 7189: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 7190: margin: 0;
7191: padding: 0;
1.933 droeschl 7192: position: relative;
7193: list-style: none;
1.913 droeschl 7194: }
1.933 droeschl 7195: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 7196: display: inline;
7197: }
1.933 droeschl 7198:
7199: .LC_breadcrumb_tools_navigation {
1.913 droeschl 7200: padding: 0;
1.933 droeschl 7201: margin: 0;
7202: float: left;
1.913 droeschl 7203: }
1.933 droeschl 7204: .LC_breadcrumb_tools_tools {
7205: padding: 0;
7206: margin: 0;
1.913 droeschl 7207: float: right;
7208: }
7209:
1.1240 raeburn 7210: .LC_placement_prog {
7211: padding-right: 20px;
7212: font-weight: bold;
7213: font-size: 90%;
7214: }
7215:
1.359 albertel 7216: table#LC_title_bar td {
7217: background: $tabbg;
7218: }
1.795 www 7219:
1.911 bisitz 7220: table#LC_menubuttons img {
1.803 bisitz 7221: border: none;
1.346 albertel 7222: }
1.795 www 7223:
1.842 droeschl 7224: .LC_breadcrumbs_component {
1.911 bisitz 7225: float: right;
7226: margin: 0 1em;
1.357 albertel 7227: }
1.842 droeschl 7228: .LC_breadcrumbs_component img {
1.911 bisitz 7229: vertical-align: middle;
1.777 tempelho 7230: }
1.795 www 7231:
1.1243 raeburn 7232: .LC_breadcrumbs_hoverable {
7233: background: $sidebg;
7234: }
7235:
1.383 albertel 7236: td.LC_table_cell_checkbox {
7237: text-align: center;
7238: }
1.795 www 7239:
7240: .LC_fontsize_small {
1.911 bisitz 7241: font-size: 70%;
1.705 tempelho 7242: }
7243:
1.844 bisitz 7244: #LC_breadcrumbs {
1.911 bisitz 7245: clear:both;
7246: background: $sidebg;
7247: border-bottom: 1px solid $lg_border_color;
7248: line-height: 2.5em;
1.933 droeschl 7249: overflow: hidden;
1.911 bisitz 7250: margin: 0;
7251: padding: 0;
1.995 raeburn 7252: text-align: left;
1.819 tempelho 7253: }
1.862 bisitz 7254:
1.1098 bisitz 7255: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 7256: clear:both;
7257: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 7258: border: 1px solid $sidebg;
1.1098 bisitz 7259: margin: 0 0 10px 0;
1.966 bisitz 7260: padding: 3px;
1.995 raeburn 7261: text-align: left;
1.822 bisitz 7262: }
7263:
1.795 www 7264: .LC_fontsize_medium {
1.911 bisitz 7265: font-size: 85%;
1.705 tempelho 7266: }
7267:
1.795 www 7268: .LC_fontsize_large {
1.911 bisitz 7269: font-size: 120%;
1.705 tempelho 7270: }
7271:
1.346 albertel 7272: .LC_menubuttons_inline_text {
7273: color: $font;
1.698 harmsja 7274: font-size: 90%;
1.701 harmsja 7275: padding-left:3px;
1.346 albertel 7276: }
7277:
1.934 droeschl 7278: .LC_menubuttons_inline_text img{
7279: vertical-align: middle;
7280: }
7281:
1.1051 www 7282: li.LC_menubuttons_inline_text img {
1.951 onken 7283: cursor:pointer;
1.1002 droeschl 7284: text-decoration: none;
1.951 onken 7285: }
7286:
1.526 www 7287: .LC_menubuttons_link {
7288: text-decoration: none;
7289: }
1.795 www 7290:
1.522 albertel 7291: .LC_menubuttons_category {
1.521 www 7292: color: $font;
1.526 www 7293: background: $pgbg;
1.521 www 7294: font-size: larger;
7295: font-weight: bold;
7296: }
7297:
1.346 albertel 7298: td.LC_menubuttons_text {
1.911 bisitz 7299: color: $font;
1.346 albertel 7300: }
1.706 harmsja 7301:
1.346 albertel 7302: .LC_current_location {
7303: background: $tabbg;
7304: }
1.795 www 7305:
1.1286 raeburn 7306: td.LC_zero_height {
7307: line-height: 0;
7308: cellpadding: 0;
7309: }
7310:
1.938 bisitz 7311: table.LC_data_table {
1.347 albertel 7312: border: 1px solid #000000;
1.402 albertel 7313: border-collapse: separate;
1.426 albertel 7314: border-spacing: 1px;
1.610 albertel 7315: background: $pgbg;
1.347 albertel 7316: }
1.795 www 7317:
1.422 albertel 7318: .LC_data_table_dense {
7319: font-size: small;
7320: }
1.795 www 7321:
1.507 raeburn 7322: table.LC_nested_outer {
7323: border: 1px solid #000000;
1.589 raeburn 7324: border-collapse: collapse;
1.803 bisitz 7325: border-spacing: 0;
1.507 raeburn 7326: width: 100%;
7327: }
1.795 www 7328:
1.879 raeburn 7329: table.LC_innerpickbox,
1.507 raeburn 7330: table.LC_nested {
1.803 bisitz 7331: border: none;
1.589 raeburn 7332: border-collapse: collapse;
1.803 bisitz 7333: border-spacing: 0;
1.507 raeburn 7334: width: 100%;
7335: }
1.795 www 7336:
1.911 bisitz 7337: table.LC_data_table tr th,
7338: table.LC_calendar tr th,
1.879 raeburn 7339: table.LC_prior_tries tr th,
7340: table.LC_innerpickbox tr th {
1.349 albertel 7341: font-weight: bold;
7342: background-color: $data_table_head;
1.801 tempelho 7343: color:$fontmenu;
1.701 harmsja 7344: font-size:90%;
1.347 albertel 7345: }
1.795 www 7346:
1.879 raeburn 7347: table.LC_innerpickbox tr th,
7348: table.LC_innerpickbox tr td {
7349: vertical-align: top;
7350: }
7351:
1.711 raeburn 7352: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 7353: background-color: #CCCCCC;
1.711 raeburn 7354: font-weight: bold;
7355: text-align: left;
7356: }
1.795 www 7357:
1.912 bisitz 7358: table.LC_data_table tr.LC_odd_row > td {
7359: background-color: $data_table_light;
7360: padding: 2px;
7361: vertical-align: top;
7362: }
7363:
1.809 bisitz 7364: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 7365: background-color: $data_table_light;
1.912 bisitz 7366: vertical-align: top;
7367: }
7368:
7369: table.LC_data_table tr.LC_even_row > td {
7370: background-color: $data_table_dark;
1.425 albertel 7371: padding: 2px;
1.900 bisitz 7372: vertical-align: top;
1.347 albertel 7373: }
1.795 www 7374:
1.809 bisitz 7375: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 7376: background-color: $data_table_dark;
1.900 bisitz 7377: vertical-align: top;
1.347 albertel 7378: }
1.795 www 7379:
1.425 albertel 7380: table.LC_data_table tr.LC_data_table_highlight td {
7381: background-color: $data_table_darker;
7382: }
1.795 www 7383:
1.639 raeburn 7384: table.LC_data_table tr td.LC_leftcol_header {
7385: background-color: $data_table_head;
7386: font-weight: bold;
7387: }
1.795 www 7388:
1.451 albertel 7389: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 7390: table.LC_nested tr.LC_empty_row td {
1.421 albertel 7391: font-weight: bold;
7392: font-style: italic;
7393: text-align: center;
7394: padding: 8px;
1.347 albertel 7395: }
1.795 www 7396:
1.1114 raeburn 7397: table.LC_data_table tr.LC_empty_row td,
7398: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 7399: background-color: $sidebg;
7400: }
7401:
7402: table.LC_nested tr.LC_empty_row td {
7403: background-color: #FFFFFF;
7404: }
7405:
1.890 droeschl 7406: table.LC_caption {
7407: }
7408:
1.507 raeburn 7409: table.LC_nested tr.LC_empty_row td {
1.465 albertel 7410: padding: 4ex
7411: }
1.795 www 7412:
1.507 raeburn 7413: table.LC_nested_outer tr th {
7414: font-weight: bold;
1.801 tempelho 7415: color:$fontmenu;
1.507 raeburn 7416: background-color: $data_table_head;
1.701 harmsja 7417: font-size: small;
1.507 raeburn 7418: border-bottom: 1px solid #000000;
7419: }
1.795 www 7420:
1.507 raeburn 7421: table.LC_nested_outer tr td.LC_subheader {
7422: background-color: $data_table_head;
7423: font-weight: bold;
7424: font-size: small;
7425: border-bottom: 1px solid #000000;
7426: text-align: right;
1.451 albertel 7427: }
1.795 www 7428:
1.507 raeburn 7429: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7430: background-color: #CCCCCC;
1.451 albertel 7431: font-weight: bold;
7432: font-size: small;
1.507 raeburn 7433: text-align: center;
7434: }
1.795 www 7435:
1.589 raeburn 7436: table.LC_nested tr.LC_info_row td.LC_left_item,
7437: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7438: text-align: left;
1.451 albertel 7439: }
1.795 www 7440:
1.507 raeburn 7441: table.LC_nested td {
1.735 bisitz 7442: background-color: #FFFFFF;
1.451 albertel 7443: font-size: small;
1.507 raeburn 7444: }
1.795 www 7445:
1.507 raeburn 7446: table.LC_nested_outer tr th.LC_right_item,
7447: table.LC_nested tr.LC_info_row td.LC_right_item,
7448: table.LC_nested tr.LC_odd_row td.LC_right_item,
7449: table.LC_nested tr td.LC_right_item {
1.451 albertel 7450: text-align: right;
7451: }
7452:
1.507 raeburn 7453: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7454: background-color: #EEEEEE;
1.451 albertel 7455: }
7456:
1.473 raeburn 7457: table.LC_createuser {
7458: }
7459:
7460: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7461: font-size: small;
1.473 raeburn 7462: }
7463:
7464: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7465: background-color: #CCCCCC;
1.473 raeburn 7466: font-weight: bold;
7467: text-align: center;
7468: }
7469:
1.349 albertel 7470: table.LC_calendar {
7471: border: 1px solid #000000;
7472: border-collapse: collapse;
1.917 raeburn 7473: width: 98%;
1.349 albertel 7474: }
1.795 www 7475:
1.349 albertel 7476: table.LC_calendar_pickdate {
7477: font-size: xx-small;
7478: }
1.795 www 7479:
1.349 albertel 7480: table.LC_calendar tr td {
7481: border: 1px solid #000000;
7482: vertical-align: top;
1.917 raeburn 7483: width: 14%;
1.349 albertel 7484: }
1.795 www 7485:
1.349 albertel 7486: table.LC_calendar tr td.LC_calendar_day_empty {
7487: background-color: $data_table_dark;
7488: }
1.795 www 7489:
1.779 bisitz 7490: table.LC_calendar tr td.LC_calendar_day_current {
7491: background-color: $data_table_highlight;
1.777 tempelho 7492: }
1.795 www 7493:
1.938 bisitz 7494: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7495: background-color: $mail_new;
7496: }
1.795 www 7497:
1.938 bisitz 7498: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7499: background-color: $mail_new_hover;
7500: }
1.795 www 7501:
1.938 bisitz 7502: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7503: background-color: $mail_read;
7504: }
1.795 www 7505:
1.938 bisitz 7506: /*
7507: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7508: background-color: $mail_read_hover;
7509: }
1.938 bisitz 7510: */
1.795 www 7511:
1.938 bisitz 7512: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7513: background-color: $mail_replied;
7514: }
1.795 www 7515:
1.938 bisitz 7516: /*
7517: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7518: background-color: $mail_replied_hover;
7519: }
1.938 bisitz 7520: */
1.795 www 7521:
1.938 bisitz 7522: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7523: background-color: $mail_other;
7524: }
1.795 www 7525:
1.938 bisitz 7526: /*
7527: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7528: background-color: $mail_other_hover;
7529: }
1.938 bisitz 7530: */
1.494 raeburn 7531:
1.777 tempelho 7532: table.LC_data_table tr > td.LC_browser_file,
7533: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7534: background: #AAEE77;
1.389 albertel 7535: }
1.795 www 7536:
1.777 tempelho 7537: table.LC_data_table tr > td.LC_browser_file_locked,
7538: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7539: background: #FFAA99;
1.387 albertel 7540: }
1.795 www 7541:
1.777 tempelho 7542: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7543: background: #888888;
1.779 bisitz 7544: }
1.795 www 7545:
1.777 tempelho 7546: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7547: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7548: background: #F8F866;
1.777 tempelho 7549: }
1.795 www 7550:
1.696 bisitz 7551: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7552: background: #E0E8FF;
1.387 albertel 7553: }
1.696 bisitz 7554:
1.707 bisitz 7555: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7556: /* background: #77FF77; */
1.707 bisitz 7557: }
1.795 www 7558:
1.707 bisitz 7559: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7560: border-right: 8px solid #FFFF77;
1.707 bisitz 7561: }
1.795 www 7562:
1.707 bisitz 7563: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7564: border-right: 8px solid #FFAA77;
1.707 bisitz 7565: }
1.795 www 7566:
1.707 bisitz 7567: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7568: border-right: 8px solid #FF7777;
1.707 bisitz 7569: }
1.795 www 7570:
1.707 bisitz 7571: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7572: border-right: 8px solid #AAFF77;
1.707 bisitz 7573: }
1.795 www 7574:
1.707 bisitz 7575: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7576: border-right: 8px solid #11CC55;
1.707 bisitz 7577: }
7578:
1.388 albertel 7579: span.LC_current_location {
1.701 harmsja 7580: font-size:larger;
1.388 albertel 7581: background: $pgbg;
7582: }
1.387 albertel 7583:
1.1029 www 7584: span.LC_current_nav_location {
7585: font-weight:bold;
7586: background: $sidebg;
7587: }
7588:
1.395 albertel 7589: span.LC_parm_menu_item {
7590: font-size: larger;
7591: }
1.795 www 7592:
1.395 albertel 7593: span.LC_parm_scope_all {
7594: color: red;
7595: }
1.795 www 7596:
1.395 albertel 7597: span.LC_parm_scope_folder {
7598: color: green;
7599: }
1.795 www 7600:
1.395 albertel 7601: span.LC_parm_scope_resource {
7602: color: orange;
7603: }
1.795 www 7604:
1.395 albertel 7605: span.LC_parm_part {
7606: color: blue;
7607: }
1.795 www 7608:
1.911 bisitz 7609: span.LC_parm_folder,
7610: span.LC_parm_symb {
1.395 albertel 7611: font-size: x-small;
7612: font-family: $mono;
7613: color: #AAAAAA;
7614: }
7615:
1.977 bisitz 7616: ul.LC_parm_parmlist li {
7617: display: inline-block;
7618: padding: 0.3em 0.8em;
7619: vertical-align: top;
7620: width: 150px;
7621: border-top:1px solid $lg_border_color;
7622: }
7623:
1.795 www 7624: td.LC_parm_overview_level_menu,
7625: td.LC_parm_overview_map_menu,
7626: td.LC_parm_overview_parm_selectors,
7627: td.LC_parm_overview_restrictions {
1.396 albertel 7628: border: 1px solid black;
7629: border-collapse: collapse;
7630: }
1.795 www 7631:
1.1285 raeburn 7632: span.LC_parm_recursive,
7633: td.LC_parm_recursive {
7634: font-weight: bold;
7635: font-size: smaller;
7636: }
7637:
1.396 albertel 7638: table.LC_parm_overview_restrictions td {
7639: border-width: 1px 4px 1px 4px;
7640: border-style: solid;
7641: border-color: $pgbg;
7642: text-align: center;
7643: }
1.795 www 7644:
1.396 albertel 7645: table.LC_parm_overview_restrictions th {
7646: background: $tabbg;
7647: border-width: 1px 4px 1px 4px;
7648: border-style: solid;
7649: border-color: $pgbg;
7650: }
1.795 www 7651:
1.398 albertel 7652: table#LC_helpmenu {
1.803 bisitz 7653: border: none;
1.398 albertel 7654: height: 55px;
1.803 bisitz 7655: border-spacing: 0;
1.398 albertel 7656: }
7657:
7658: table#LC_helpmenu fieldset legend {
7659: font-size: larger;
7660: }
1.795 www 7661:
1.397 albertel 7662: table#LC_helpmenu_links {
7663: width: 100%;
7664: border: 1px solid black;
7665: background: $pgbg;
1.803 bisitz 7666: padding: 0;
1.397 albertel 7667: border-spacing: 1px;
7668: }
1.795 www 7669:
1.397 albertel 7670: table#LC_helpmenu_links tr td {
7671: padding: 1px;
7672: background: $tabbg;
1.399 albertel 7673: text-align: center;
7674: font-weight: bold;
1.397 albertel 7675: }
1.396 albertel 7676:
1.795 www 7677: table#LC_helpmenu_links a:link,
7678: table#LC_helpmenu_links a:visited,
1.397 albertel 7679: table#LC_helpmenu_links a:active {
7680: text-decoration: none;
7681: color: $font;
7682: }
1.795 www 7683:
1.397 albertel 7684: table#LC_helpmenu_links a:hover {
7685: text-decoration: underline;
7686: color: $vlink;
7687: }
1.396 albertel 7688:
1.417 albertel 7689: .LC_chrt_popup_exists {
7690: border: 1px solid #339933;
7691: margin: -1px;
7692: }
1.795 www 7693:
1.417 albertel 7694: .LC_chrt_popup_up {
7695: border: 1px solid yellow;
7696: margin: -1px;
7697: }
1.795 www 7698:
1.417 albertel 7699: .LC_chrt_popup {
7700: border: 1px solid #8888FF;
7701: background: #CCCCFF;
7702: }
1.795 www 7703:
1.421 albertel 7704: table.LC_pick_box {
7705: border-collapse: separate;
7706: background: white;
7707: border: 1px solid black;
7708: border-spacing: 1px;
7709: }
1.795 www 7710:
1.421 albertel 7711: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7712: background: $sidebg;
1.421 albertel 7713: font-weight: bold;
1.900 bisitz 7714: text-align: left;
1.740 bisitz 7715: vertical-align: top;
1.421 albertel 7716: width: 184px;
7717: padding: 8px;
7718: }
1.795 www 7719:
1.579 raeburn 7720: table.LC_pick_box td.LC_pick_box_value {
7721: text-align: left;
7722: padding: 8px;
7723: }
1.795 www 7724:
1.579 raeburn 7725: table.LC_pick_box td.LC_pick_box_select {
7726: text-align: left;
7727: padding: 8px;
7728: }
1.795 www 7729:
1.424 albertel 7730: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7731: padding: 0;
1.421 albertel 7732: height: 1px;
7733: background: black;
7734: }
1.795 www 7735:
1.421 albertel 7736: table.LC_pick_box td.LC_pick_box_submit {
7737: text-align: right;
7738: }
1.795 www 7739:
1.579 raeburn 7740: table.LC_pick_box td.LC_evenrow_value {
7741: text-align: left;
7742: padding: 8px;
7743: background-color: $data_table_light;
7744: }
1.795 www 7745:
1.579 raeburn 7746: table.LC_pick_box td.LC_oddrow_value {
7747: text-align: left;
7748: padding: 8px;
7749: background-color: $data_table_light;
7750: }
1.795 www 7751:
1.579 raeburn 7752: span.LC_helpform_receipt_cat {
7753: font-weight: bold;
7754: }
1.795 www 7755:
1.424 albertel 7756: table.LC_group_priv_box {
7757: background: white;
7758: border: 1px solid black;
7759: border-spacing: 1px;
7760: }
1.795 www 7761:
1.424 albertel 7762: table.LC_group_priv_box td.LC_pick_box_title {
7763: background: $tabbg;
7764: font-weight: bold;
7765: text-align: right;
7766: width: 184px;
7767: }
1.795 www 7768:
1.424 albertel 7769: table.LC_group_priv_box td.LC_groups_fixed {
7770: background: $data_table_light;
7771: text-align: center;
7772: }
1.795 www 7773:
1.424 albertel 7774: table.LC_group_priv_box td.LC_groups_optional {
7775: background: $data_table_dark;
7776: text-align: center;
7777: }
1.795 www 7778:
1.424 albertel 7779: table.LC_group_priv_box td.LC_groups_functionality {
7780: background: $data_table_darker;
7781: text-align: center;
7782: font-weight: bold;
7783: }
1.795 www 7784:
1.424 albertel 7785: table.LC_group_priv td {
7786: text-align: left;
1.803 bisitz 7787: padding: 0;
1.424 albertel 7788: }
7789:
7790: .LC_navbuttons {
7791: margin: 2ex 0ex 2ex 0ex;
7792: }
1.795 www 7793:
1.423 albertel 7794: .LC_topic_bar {
7795: font-weight: bold;
7796: background: $tabbg;
1.918 wenzelju 7797: margin: 1em 0em 1em 2em;
1.805 bisitz 7798: padding: 3px;
1.918 wenzelju 7799: font-size: 1.2em;
1.423 albertel 7800: }
1.795 www 7801:
1.423 albertel 7802: .LC_topic_bar span {
1.918 wenzelju 7803: left: 0.5em;
7804: position: absolute;
1.423 albertel 7805: vertical-align: middle;
1.918 wenzelju 7806: font-size: 1.2em;
1.423 albertel 7807: }
1.795 www 7808:
1.423 albertel 7809: table.LC_course_group_status {
7810: margin: 20px;
7811: }
1.795 www 7812:
1.423 albertel 7813: table.LC_status_selector td {
7814: vertical-align: top;
7815: text-align: center;
1.424 albertel 7816: padding: 4px;
7817: }
1.795 www 7818:
1.599 albertel 7819: div.LC_feedback_link {
1.616 albertel 7820: clear: both;
1.829 kalberla 7821: background: $sidebg;
1.779 bisitz 7822: width: 100%;
1.829 kalberla 7823: padding-bottom: 10px;
7824: border: 1px $tabbg solid;
1.833 kalberla 7825: height: 22px;
7826: line-height: 22px;
7827: padding-top: 5px;
7828: }
7829:
7830: div.LC_feedback_link img {
7831: height: 22px;
1.867 kalberla 7832: vertical-align:middle;
1.829 kalberla 7833: }
7834:
1.911 bisitz 7835: div.LC_feedback_link a {
1.829 kalberla 7836: text-decoration: none;
1.489 raeburn 7837: }
1.795 www 7838:
1.867 kalberla 7839: div.LC_comblock {
1.911 bisitz 7840: display:inline;
1.867 kalberla 7841: color:$font;
7842: font-size:90%;
7843: }
7844:
7845: div.LC_feedback_link div.LC_comblock {
7846: padding-left:5px;
7847: }
7848:
7849: div.LC_feedback_link div.LC_comblock a {
7850: color:$font;
7851: }
7852:
1.489 raeburn 7853: span.LC_feedback_link {
1.858 bisitz 7854: /* background: $feedback_link_bg; */
1.599 albertel 7855: font-size: larger;
7856: }
1.795 www 7857:
1.599 albertel 7858: span.LC_message_link {
1.858 bisitz 7859: /* background: $feedback_link_bg; */
1.599 albertel 7860: font-size: larger;
7861: position: absolute;
7862: right: 1em;
1.489 raeburn 7863: }
1.421 albertel 7864:
1.515 albertel 7865: table.LC_prior_tries {
1.524 albertel 7866: border: 1px solid #000000;
7867: border-collapse: separate;
7868: border-spacing: 1px;
1.515 albertel 7869: }
1.523 albertel 7870:
1.515 albertel 7871: table.LC_prior_tries td {
1.524 albertel 7872: padding: 2px;
1.515 albertel 7873: }
1.523 albertel 7874:
7875: .LC_answer_correct {
1.795 www 7876: background: lightgreen;
7877: color: darkgreen;
7878: padding: 6px;
1.523 albertel 7879: }
1.795 www 7880:
1.523 albertel 7881: .LC_answer_charged_try {
1.797 www 7882: background: #FFAAAA;
1.795 www 7883: color: darkred;
7884: padding: 6px;
1.523 albertel 7885: }
1.795 www 7886:
1.779 bisitz 7887: .LC_answer_not_charged_try,
1.523 albertel 7888: .LC_answer_no_grade,
7889: .LC_answer_late {
1.795 www 7890: background: lightyellow;
1.523 albertel 7891: color: black;
1.795 www 7892: padding: 6px;
1.523 albertel 7893: }
1.795 www 7894:
1.523 albertel 7895: .LC_answer_previous {
1.795 www 7896: background: lightblue;
7897: color: darkblue;
7898: padding: 6px;
1.523 albertel 7899: }
1.795 www 7900:
1.779 bisitz 7901: .LC_answer_no_message {
1.777 tempelho 7902: background: #FFFFFF;
7903: color: black;
1.795 www 7904: padding: 6px;
1.779 bisitz 7905: }
1.795 www 7906:
1.1334 raeburn 7907: .LC_answer_unknown,
7908: .LC_answer_warning {
1.779 bisitz 7909: background: orange;
7910: color: black;
1.795 www 7911: padding: 6px;
1.777 tempelho 7912: }
1.795 www 7913:
1.529 albertel 7914: span.LC_prior_numerical,
7915: span.LC_prior_string,
7916: span.LC_prior_custom,
7917: span.LC_prior_reaction,
7918: span.LC_prior_math {
1.925 bisitz 7919: font-family: $mono;
1.523 albertel 7920: white-space: pre;
7921: }
7922:
1.525 albertel 7923: span.LC_prior_string {
1.925 bisitz 7924: font-family: $mono;
1.525 albertel 7925: white-space: pre;
7926: }
7927:
1.523 albertel 7928: table.LC_prior_option {
7929: width: 100%;
7930: border-collapse: collapse;
7931: }
1.795 www 7932:
1.911 bisitz 7933: table.LC_prior_rank,
1.795 www 7934: table.LC_prior_match {
1.528 albertel 7935: border-collapse: collapse;
7936: }
1.795 www 7937:
1.528 albertel 7938: table.LC_prior_option tr td,
7939: table.LC_prior_rank tr td,
7940: table.LC_prior_match tr td {
1.524 albertel 7941: border: 1px solid #000000;
1.515 albertel 7942: }
7943:
1.855 bisitz 7944: .LC_nobreak {
1.544 albertel 7945: white-space: nowrap;
1.519 raeburn 7946: }
7947:
1.576 raeburn 7948: span.LC_cusr_emph {
7949: font-style: italic;
7950: }
7951:
1.633 raeburn 7952: span.LC_cusr_subheading {
7953: font-weight: normal;
7954: font-size: 85%;
7955: }
7956:
1.861 bisitz 7957: div.LC_docs_entry_move {
1.859 bisitz 7958: border: 1px solid #BBBBBB;
1.545 albertel 7959: background: #DDDDDD;
1.861 bisitz 7960: width: 22px;
1.859 bisitz 7961: padding: 1px;
7962: margin: 0;
1.545 albertel 7963: }
7964:
1.861 bisitz 7965: table.LC_data_table tr > td.LC_docs_entry_commands,
7966: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7967: font-size: x-small;
7968: }
1.795 www 7969:
1.861 bisitz 7970: .LC_docs_entry_parameter {
7971: white-space: nowrap;
7972: }
7973:
1.544 albertel 7974: .LC_docs_copy {
1.545 albertel 7975: color: #000099;
1.544 albertel 7976: }
1.795 www 7977:
1.544 albertel 7978: .LC_docs_cut {
1.545 albertel 7979: color: #550044;
1.544 albertel 7980: }
1.795 www 7981:
1.544 albertel 7982: .LC_docs_rename {
1.545 albertel 7983: color: #009900;
1.544 albertel 7984: }
1.795 www 7985:
1.544 albertel 7986: .LC_docs_remove {
1.545 albertel 7987: color: #990000;
7988: }
7989:
1.1284 raeburn 7990: .LC_docs_alias {
7991: color: #440055;
7992: }
7993:
1.1286 raeburn 7994: .LC_domprefs_email,
1.1284 raeburn 7995: .LC_docs_alias_name,
1.547 albertel 7996: .LC_docs_reinit_warn,
7997: .LC_docs_ext_edit {
7998: font-size: x-small;
7999: }
8000:
1.545 albertel 8001: table.LC_docs_adddocs td,
8002: table.LC_docs_adddocs th {
8003: border: 1px solid #BBBBBB;
8004: padding: 4px;
8005: background: #DDDDDD;
1.543 albertel 8006: }
8007:
1.584 albertel 8008: table.LC_sty_begin {
8009: background: #BBFFBB;
8010: }
1.795 www 8011:
1.584 albertel 8012: table.LC_sty_end {
8013: background: #FFBBBB;
8014: }
8015:
1.589 raeburn 8016: table.LC_double_column {
1.803 bisitz 8017: border-width: 0;
1.589 raeburn 8018: border-collapse: collapse;
8019: width: 100%;
8020: padding: 2px;
8021: }
8022:
8023: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 8024: top: 2px;
1.589 raeburn 8025: left: 2px;
8026: width: 47%;
8027: vertical-align: top;
8028: }
8029:
8030: table.LC_double_column tr td.LC_right_col {
8031: top: 2px;
1.779 bisitz 8032: right: 2px;
1.589 raeburn 8033: width: 47%;
8034: vertical-align: top;
8035: }
8036:
1.591 raeburn 8037: div.LC_left_float {
8038: float: left;
8039: padding-right: 5%;
1.597 albertel 8040: padding-bottom: 4px;
1.591 raeburn 8041: }
8042:
8043: div.LC_clear_float_header {
1.597 albertel 8044: padding-bottom: 2px;
1.591 raeburn 8045: }
8046:
8047: div.LC_clear_float_footer {
1.597 albertel 8048: padding-top: 10px;
1.591 raeburn 8049: clear: both;
8050: }
8051:
1.597 albertel 8052: div.LC_grade_show_user {
1.941 bisitz 8053: /* border-left: 5px solid $sidebg; */
8054: border-top: 5px solid #000000;
8055: margin: 50px 0 0 0;
1.936 bisitz 8056: padding: 15px 0 5px 10px;
1.597 albertel 8057: }
1.795 www 8058:
1.936 bisitz 8059: div.LC_grade_show_user_odd_row {
1.941 bisitz 8060: /* border-left: 5px solid #000000; */
8061: }
8062:
8063: div.LC_grade_show_user div.LC_Box {
8064: margin-right: 50px;
1.597 albertel 8065: }
8066:
8067: div.LC_grade_submissions,
8068: div.LC_grade_message_center,
1.936 bisitz 8069: div.LC_grade_info_links {
1.597 albertel 8070: margin: 5px;
8071: width: 99%;
8072: background: #FFFFFF;
8073: }
1.795 www 8074:
1.597 albertel 8075: div.LC_grade_submissions_header,
1.936 bisitz 8076: div.LC_grade_message_center_header {
1.705 tempelho 8077: font-weight: bold;
8078: font-size: large;
1.597 albertel 8079: }
1.795 www 8080:
1.597 albertel 8081: div.LC_grade_submissions_body,
1.936 bisitz 8082: div.LC_grade_message_center_body {
1.597 albertel 8083: border: 1px solid black;
8084: width: 99%;
8085: background: #FFFFFF;
8086: }
1.795 www 8087:
1.613 albertel 8088: table.LC_scantron_action {
8089: width: 100%;
8090: }
1.795 www 8091:
1.613 albertel 8092: table.LC_scantron_action tr th {
1.698 harmsja 8093: font-weight:bold;
8094: font-style:normal;
1.613 albertel 8095: }
1.795 www 8096:
1.779 bisitz 8097: .LC_edit_problem_header,
1.614 albertel 8098: div.LC_edit_problem_footer {
1.705 tempelho 8099: font-weight: normal;
8100: font-size: medium;
1.602 albertel 8101: margin: 2px;
1.1060 bisitz 8102: background-color: $sidebg;
1.600 albertel 8103: }
1.795 www 8104:
1.600 albertel 8105: div.LC_edit_problem_header,
1.602 albertel 8106: div.LC_edit_problem_header div,
1.614 albertel 8107: div.LC_edit_problem_footer,
8108: div.LC_edit_problem_footer div,
1.602 albertel 8109: div.LC_edit_problem_editxml_header,
8110: div.LC_edit_problem_editxml_header div {
1.1205 golterma 8111: z-index: 100;
1.600 albertel 8112: }
1.795 www 8113:
1.600 albertel 8114: div.LC_edit_problem_header_title {
1.705 tempelho 8115: font-weight: bold;
8116: font-size: larger;
1.602 albertel 8117: background: $tabbg;
8118: padding: 3px;
1.1060 bisitz 8119: margin: 0 0 5px 0;
1.602 albertel 8120: }
1.795 www 8121:
1.602 albertel 8122: table.LC_edit_problem_header_title {
8123: width: 100%;
1.600 albertel 8124: background: $tabbg;
1.602 albertel 8125: }
8126:
1.1205 golterma 8127: div.LC_edit_actionbar {
8128: background-color: $sidebg;
1.1218 droeschl 8129: margin: 0;
8130: padding: 0;
8131: line-height: 200%;
1.602 albertel 8132: }
1.795 www 8133:
1.1218 droeschl 8134: div.LC_edit_actionbar div{
8135: padding: 0;
8136: margin: 0;
8137: display: inline-block;
1.600 albertel 8138: }
1.795 www 8139:
1.1124 bisitz 8140: .LC_edit_opt {
8141: padding-left: 1em;
8142: white-space: nowrap;
8143: }
8144:
1.1152 golterma 8145: .LC_edit_problem_latexhelper{
8146: text-align: right;
8147: }
8148:
8149: #LC_edit_problem_colorful div{
8150: margin-left: 40px;
8151: }
8152:
1.1205 golterma 8153: #LC_edit_problem_codemirror div{
8154: margin-left: 0px;
8155: }
8156:
1.911 bisitz 8157: img.stift {
1.803 bisitz 8158: border-width: 0;
8159: vertical-align: middle;
1.677 riegler 8160: }
1.680 riegler 8161:
1.923 bisitz 8162: table td.LC_mainmenu_col_fieldset {
1.680 riegler 8163: vertical-align: top;
1.777 tempelho 8164: }
1.795 www 8165:
1.716 raeburn 8166: div.LC_createcourse {
1.911 bisitz 8167: margin: 10px 10px 10px 10px;
1.716 raeburn 8168: }
8169:
1.917 raeburn 8170: .LC_dccid {
1.1130 raeburn 8171: float: right;
1.917 raeburn 8172: margin: 0.2em 0 0 0;
8173: padding: 0;
8174: font-size: 90%;
8175: display:none;
8176: }
8177:
1.897 wenzelju 8178: ol.LC_primary_menu a:hover,
1.721 harmsja 8179: ol#LC_MenuBreadcrumbs a:hover,
8180: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 8181: ul#LC_secondary_menu a:hover,
1.721 harmsja 8182: .LC_FormSectionClearButton input:hover
1.795 www 8183: ul.LC_TabContent li:hover a {
1.952 onken 8184: color:$button_hover;
1.911 bisitz 8185: text-decoration:none;
1.693 droeschl 8186: }
8187:
1.779 bisitz 8188: h1 {
1.911 bisitz 8189: padding: 0;
8190: line-height:130%;
1.693 droeschl 8191: }
1.698 harmsja 8192:
1.911 bisitz 8193: h2,
8194: h3,
8195: h4,
8196: h5,
8197: h6 {
8198: margin: 5px 0 5px 0;
8199: padding: 0;
8200: line-height:130%;
1.693 droeschl 8201: }
1.795 www 8202:
8203: .LC_hcell {
1.911 bisitz 8204: padding:3px 15px 3px 15px;
8205: margin: 0;
8206: background-color:$tabbg;
8207: color:$fontmenu;
8208: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 8209: }
1.795 www 8210:
1.840 bisitz 8211: .LC_Box > .LC_hcell {
1.911 bisitz 8212: margin: 0 -10px 10px -10px;
1.835 bisitz 8213: }
8214:
1.721 harmsja 8215: .LC_noBorder {
1.911 bisitz 8216: border: 0;
1.698 harmsja 8217: }
1.693 droeschl 8218:
1.721 harmsja 8219: .LC_FormSectionClearButton input {
1.911 bisitz 8220: background-color:transparent;
8221: border: none;
8222: cursor:pointer;
8223: text-decoration:underline;
1.693 droeschl 8224: }
1.763 bisitz 8225:
8226: .LC_help_open_topic {
1.911 bisitz 8227: color: #FFFFFF;
8228: background-color: #EEEEFF;
8229: margin: 1px;
8230: padding: 4px;
8231: border: 1px solid #000033;
8232: white-space: nowrap;
8233: /* vertical-align: middle; */
1.759 neumanie 8234: }
1.693 droeschl 8235:
1.911 bisitz 8236: dl,
8237: ul,
8238: div,
8239: fieldset {
8240: margin: 10px 10px 10px 0;
8241: /* overflow: hidden; */
1.693 droeschl 8242: }
1.795 www 8243:
1.1404 raeburn 8244: fieldset#LC_selectuser {
8245: margin: 0;
8246: padding: 0;
8247: }
8248:
1.1211 raeburn 8249: article.geogebraweb div {
8250: margin: 0;
8251: }
8252:
1.838 bisitz 8253: fieldset > legend {
1.911 bisitz 8254: font-weight: bold;
8255: padding: 0 5px 0 5px;
1.838 bisitz 8256: }
8257:
1.813 bisitz 8258: #LC_nav_bar {
1.911 bisitz 8259: float: left;
1.995 raeburn 8260: background-color: $pgbg_or_bgcolor;
1.966 bisitz 8261: margin: 0 0 2px 0;
1.807 droeschl 8262: }
8263:
1.916 droeschl 8264: #LC_realm {
8265: margin: 0.2em 0 0 0;
8266: padding: 0;
8267: font-weight: bold;
8268: text-align: center;
1.995 raeburn 8269: background-color: $pgbg_or_bgcolor;
1.916 droeschl 8270: }
8271:
1.911 bisitz 8272: #LC_nav_bar em {
8273: font-weight: bold;
8274: font-style: normal;
1.807 droeschl 8275: }
8276:
1.897 wenzelju 8277: ol.LC_primary_menu {
1.934 droeschl 8278: margin: 0;
1.1076 raeburn 8279: padding: 0;
1.807 droeschl 8280: }
8281:
1.852 droeschl 8282: ol#LC_PathBreadcrumbs {
1.911 bisitz 8283: margin: 0;
1.693 droeschl 8284: }
8285:
1.897 wenzelju 8286: ol.LC_primary_menu li {
1.1076 raeburn 8287: color: RGB(80, 80, 80);
8288: vertical-align: middle;
8289: text-align: left;
8290: list-style: none;
1.1205 golterma 8291: position: relative;
1.1076 raeburn 8292: float: left;
1.1205 golterma 8293: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
8294: line-height: 1.5em;
1.1076 raeburn 8295: }
8296:
1.1205 golterma 8297: ol.LC_primary_menu li a,
8298: ol.LC_primary_menu li p {
1.1076 raeburn 8299: display: block;
8300: margin: 0;
8301: padding: 0 5px 0 10px;
8302: text-decoration: none;
8303: }
8304:
1.1205 golterma 8305: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
8306: display: inline-block;
8307: width: 95%;
8308: text-align: left;
8309: }
8310:
8311: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
8312: display: inline-block;
8313: width: 5%;
8314: float: right;
8315: text-align: right;
8316: font-size: 70%;
8317: }
8318:
8319: ol.LC_primary_menu ul {
1.1076 raeburn 8320: display: none;
1.1205 golterma 8321: width: 15em;
1.1076 raeburn 8322: background-color: $data_table_light;
1.1205 golterma 8323: position: absolute;
8324: top: 100%;
1.1076 raeburn 8325: }
8326:
1.1205 golterma 8327: ol.LC_primary_menu ul ul {
8328: left: 100%;
8329: top: 0;
8330: }
8331:
8332: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 8333: display: block;
8334: position: absolute;
8335: margin: 0;
8336: padding: 0;
1.1078 raeburn 8337: z-index: 2;
1.1076 raeburn 8338: }
8339:
8340: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 8341: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 8342: font-size: 90%;
1.911 bisitz 8343: vertical-align: top;
1.1076 raeburn 8344: float: none;
1.1079 raeburn 8345: border-left: 1px solid black;
8346: border-right: 1px solid black;
1.1205 golterma 8347: /* A dark bottom border to visualize different menu options;
8348: overwritten in the create_submenu routine for the last border-bottom of the menu */
8349: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 8350: }
8351:
1.1205 golterma 8352: ol.LC_primary_menu li li p:hover {
8353: color:$button_hover;
8354: text-decoration:none;
8355: background-color:$data_table_dark;
1.1076 raeburn 8356: }
8357:
8358: ol.LC_primary_menu li li a:hover {
8359: color:$button_hover;
8360: background-color:$data_table_dark;
1.693 droeschl 8361: }
8362:
1.1205 golterma 8363: /* Font-size equal to the size of the predecessors*/
8364: ol.LC_primary_menu li:hover li li {
8365: font-size: 100%;
8366: }
8367:
1.897 wenzelju 8368: ol.LC_primary_menu li img {
1.911 bisitz 8369: vertical-align: bottom;
1.934 droeschl 8370: height: 1.1em;
1.1077 raeburn 8371: margin: 0.2em 0 0 0;
1.693 droeschl 8372: }
8373:
1.897 wenzelju 8374: ol.LC_primary_menu a {
1.911 bisitz 8375: color: RGB(80, 80, 80);
8376: text-decoration: none;
1.693 droeschl 8377: }
1.795 www 8378:
1.949 droeschl 8379: ol.LC_primary_menu a.LC_new_message {
8380: font-weight:bold;
8381: color: darkred;
8382: }
8383:
1.975 raeburn 8384: ol.LC_docs_parameters {
8385: margin-left: 0;
8386: padding: 0;
8387: list-style: none;
8388: }
8389:
8390: ol.LC_docs_parameters li {
8391: margin: 0;
8392: padding-right: 20px;
8393: display: inline;
8394: }
8395:
1.976 raeburn 8396: ol.LC_docs_parameters li:before {
8397: content: "\\002022 \\0020";
8398: }
8399:
8400: li.LC_docs_parameters_title {
8401: font-weight: bold;
8402: }
8403:
8404: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
8405: content: "";
8406: }
8407:
1.897 wenzelju 8408: ul#LC_secondary_menu {
1.1107 raeburn 8409: clear: right;
1.911 bisitz 8410: color: $fontmenu;
8411: background: $tabbg;
8412: list-style: none;
8413: padding: 0;
8414: margin: 0;
8415: width: 100%;
1.995 raeburn 8416: text-align: left;
1.1107 raeburn 8417: float: left;
1.808 droeschl 8418: }
8419:
1.897 wenzelju 8420: ul#LC_secondary_menu li {
1.911 bisitz 8421: font-weight: bold;
8422: line-height: 1.8em;
1.1107 raeburn 8423: border-right: 1px solid black;
8424: float: left;
8425: }
8426:
8427: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
8428: background-color: $data_table_light;
8429: }
8430:
8431: ul#LC_secondary_menu li a {
1.911 bisitz 8432: padding: 0 0.8em;
1.1107 raeburn 8433: }
8434:
8435: ul#LC_secondary_menu li ul {
8436: display: none;
8437: }
8438:
8439: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8440: display: block;
8441: position: absolute;
8442: margin: 0;
8443: padding: 0;
8444: list-style:none;
8445: float: none;
8446: background-color: $data_table_light;
8447: z-index: 2;
8448: margin-left: -1px;
8449: }
8450:
8451: ul#LC_secondary_menu li ul li {
8452: font-size: 90%;
8453: vertical-align: top;
8454: border-left: 1px solid black;
1.911 bisitz 8455: border-right: 1px solid black;
1.1119 raeburn 8456: background-color: $data_table_light;
1.1107 raeburn 8457: list-style:none;
8458: float: none;
8459: }
8460:
8461: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8462: background-color: $data_table_dark;
1.807 droeschl 8463: }
8464:
1.847 tempelho 8465: ul.LC_TabContent {
1.911 bisitz 8466: display:block;
8467: background: $sidebg;
8468: border-bottom: solid 1px $lg_border_color;
8469: list-style:none;
1.1020 raeburn 8470: margin: -1px -10px 0 -10px;
1.911 bisitz 8471: padding: 0;
1.693 droeschl 8472: }
8473:
1.795 www 8474: ul.LC_TabContent li,
8475: ul.LC_TabContentBigger li {
1.911 bisitz 8476: float:left;
1.741 harmsja 8477: }
1.795 www 8478:
1.897 wenzelju 8479: ul#LC_secondary_menu li a {
1.911 bisitz 8480: color: $fontmenu;
8481: text-decoration: none;
1.693 droeschl 8482: }
1.795 www 8483:
1.721 harmsja 8484: ul.LC_TabContent {
1.952 onken 8485: min-height:20px;
1.721 harmsja 8486: }
1.795 www 8487:
8488: ul.LC_TabContent li {
1.911 bisitz 8489: vertical-align:middle;
1.959 onken 8490: padding: 0 16px 0 10px;
1.911 bisitz 8491: background-color:$tabbg;
8492: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8493: border-left: solid 1px $font;
1.721 harmsja 8494: }
1.795 www 8495:
1.847 tempelho 8496: ul.LC_TabContent .right {
1.911 bisitz 8497: float:right;
1.847 tempelho 8498: }
8499:
1.911 bisitz 8500: ul.LC_TabContent li a,
8501: ul.LC_TabContent li {
8502: color:rgb(47,47,47);
8503: text-decoration:none;
8504: font-size:95%;
8505: font-weight:bold;
1.952 onken 8506: min-height:20px;
8507: }
8508:
1.959 onken 8509: ul.LC_TabContent li a:hover,
8510: ul.LC_TabContent li a:focus {
1.952 onken 8511: color: $button_hover;
1.959 onken 8512: background:none;
8513: outline:none;
1.952 onken 8514: }
8515:
8516: ul.LC_TabContent li:hover {
8517: color: $button_hover;
8518: cursor:pointer;
1.721 harmsja 8519: }
1.795 www 8520:
1.911 bisitz 8521: ul.LC_TabContent li.active {
1.952 onken 8522: color: $font;
1.911 bisitz 8523: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8524: border-bottom:solid 1px #FFFFFF;
8525: cursor: default;
1.744 ehlerst 8526: }
1.795 www 8527:
1.959 onken 8528: ul.LC_TabContent li.active a {
8529: color:$font;
8530: background:#FFFFFF;
8531: outline: none;
8532: }
1.1047 raeburn 8533:
8534: ul.LC_TabContent li.goback {
8535: float: left;
8536: border-left: none;
8537: }
8538:
1.870 tempelho 8539: #maincoursedoc {
1.911 bisitz 8540: clear:both;
1.870 tempelho 8541: }
8542:
8543: ul.LC_TabContentBigger {
1.911 bisitz 8544: display:block;
8545: list-style:none;
8546: padding: 0;
1.870 tempelho 8547: }
8548:
1.795 www 8549: ul.LC_TabContentBigger li {
1.911 bisitz 8550: vertical-align:bottom;
8551: height: 30px;
8552: font-size:110%;
8553: font-weight:bold;
8554: color: #737373;
1.841 tempelho 8555: }
8556:
1.957 onken 8557: ul.LC_TabContentBigger li.active {
8558: position: relative;
8559: top: 1px;
8560: }
8561:
1.870 tempelho 8562: ul.LC_TabContentBigger li a {
1.911 bisitz 8563: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8564: height: 30px;
8565: line-height: 30px;
8566: text-align: center;
8567: display: block;
8568: text-decoration: none;
1.958 onken 8569: outline: none;
1.741 harmsja 8570: }
1.795 www 8571:
1.870 tempelho 8572: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8573: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8574: color:$font;
1.744 ehlerst 8575: }
1.795 www 8576:
1.870 tempelho 8577: ul.LC_TabContentBigger li b {
1.911 bisitz 8578: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8579: display: block;
8580: float: left;
8581: padding: 0 30px;
1.957 onken 8582: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8583: }
8584:
1.956 onken 8585: ul.LC_TabContentBigger li:hover b {
8586: color:$button_hover;
8587: }
8588:
1.870 tempelho 8589: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8590: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8591: color:$font;
1.957 onken 8592: border: 0;
1.741 harmsja 8593: }
1.693 droeschl 8594:
1.870 tempelho 8595:
1.862 bisitz 8596: ul.LC_CourseBreadcrumbs {
8597: background: $sidebg;
1.1020 raeburn 8598: height: 2em;
1.862 bisitz 8599: padding-left: 10px;
1.1020 raeburn 8600: margin: 0;
1.862 bisitz 8601: list-style-position: inside;
8602: }
8603:
1.911 bisitz 8604: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8605: ol#LC_PathBreadcrumbs {
1.911 bisitz 8606: padding-left: 10px;
8607: margin: 0;
1.933 droeschl 8608: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8609: }
8610:
1.911 bisitz 8611: ol#LC_MenuBreadcrumbs li,
8612: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8613: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8614: display: inline;
1.933 droeschl 8615: white-space: normal;
1.693 droeschl 8616: }
8617:
1.823 bisitz 8618: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8619: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8620: text-decoration: none;
8621: font-size:90%;
1.693 droeschl 8622: }
1.795 www 8623:
1.969 droeschl 8624: ol#LC_MenuBreadcrumbs h1 {
8625: display: inline;
8626: font-size: 90%;
8627: line-height: 2.5em;
8628: margin: 0;
8629: padding: 0;
8630: }
8631:
1.795 www 8632: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8633: text-decoration:none;
8634: font-size:100%;
8635: font-weight:bold;
1.693 droeschl 8636: }
1.795 www 8637:
1.840 bisitz 8638: .LC_Box {
1.911 bisitz 8639: border: solid 1px $lg_border_color;
8640: padding: 0 10px 10px 10px;
1.746 neumanie 8641: }
1.795 www 8642:
1.1020 raeburn 8643: .LC_DocsBox {
8644: border: solid 1px $lg_border_color;
8645: padding: 0 0 10px 10px;
8646: }
8647:
1.795 www 8648: .LC_AboutMe_Image {
1.911 bisitz 8649: float:left;
8650: margin-right:10px;
1.747 neumanie 8651: }
1.795 www 8652:
8653: .LC_Clear_AboutMe_Image {
1.911 bisitz 8654: clear:left;
1.747 neumanie 8655: }
1.795 www 8656:
1.721 harmsja 8657: dl.LC_ListStyleClean dt {
1.911 bisitz 8658: padding-right: 5px;
8659: display: table-header-group;
1.693 droeschl 8660: }
8661:
1.721 harmsja 8662: dl.LC_ListStyleClean dd {
1.911 bisitz 8663: display: table-row;
1.693 droeschl 8664: }
8665:
1.721 harmsja 8666: .LC_ListStyleClean,
8667: .LC_ListStyleSimple,
8668: .LC_ListStyleNormal,
1.795 www 8669: .LC_ListStyleSpecial {
1.911 bisitz 8670: /* display:block; */
8671: list-style-position: inside;
8672: list-style-type: none;
8673: overflow: hidden;
8674: padding: 0;
1.693 droeschl 8675: }
8676:
1.721 harmsja 8677: .LC_ListStyleSimple li,
8678: .LC_ListStyleSimple dd,
8679: .LC_ListStyleNormal li,
8680: .LC_ListStyleNormal dd,
8681: .LC_ListStyleSpecial li,
1.795 www 8682: .LC_ListStyleSpecial dd {
1.911 bisitz 8683: margin: 0;
8684: padding: 5px 5px 5px 10px;
8685: clear: both;
1.693 droeschl 8686: }
8687:
1.721 harmsja 8688: .LC_ListStyleClean li,
8689: .LC_ListStyleClean dd {
1.911 bisitz 8690: padding-top: 0;
8691: padding-bottom: 0;
1.693 droeschl 8692: }
8693:
1.721 harmsja 8694: .LC_ListStyleSimple dd,
1.795 www 8695: .LC_ListStyleSimple li {
1.911 bisitz 8696: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8697: }
8698:
1.721 harmsja 8699: .LC_ListStyleSpecial li,
8700: .LC_ListStyleSpecial dd {
1.911 bisitz 8701: list-style-type: none;
8702: background-color: RGB(220, 220, 220);
8703: margin-bottom: 4px;
1.693 droeschl 8704: }
8705:
1.721 harmsja 8706: table.LC_SimpleTable {
1.911 bisitz 8707: margin:5px;
8708: border:solid 1px $lg_border_color;
1.795 www 8709: }
1.693 droeschl 8710:
1.721 harmsja 8711: table.LC_SimpleTable tr {
1.911 bisitz 8712: padding: 0;
8713: border:solid 1px $lg_border_color;
1.693 droeschl 8714: }
1.795 www 8715:
8716: table.LC_SimpleTable thead {
1.911 bisitz 8717: background:rgb(220,220,220);
1.693 droeschl 8718: }
8719:
1.721 harmsja 8720: div.LC_columnSection {
1.911 bisitz 8721: display: block;
8722: clear: both;
8723: overflow: hidden;
8724: margin: 0;
1.693 droeschl 8725: }
8726:
1.721 harmsja 8727: div.LC_columnSection>* {
1.911 bisitz 8728: float: left;
8729: margin: 10px 20px 10px 0;
8730: overflow:hidden;
1.693 droeschl 8731: }
1.721 harmsja 8732:
1.795 www 8733: table em {
1.911 bisitz 8734: font-weight: bold;
8735: font-style: normal;
1.748 schulted 8736: }
1.795 www 8737:
1.779 bisitz 8738: table.LC_tableBrowseRes,
1.795 www 8739: table.LC_tableOfContent {
1.911 bisitz 8740: border:none;
8741: border-spacing: 1px;
8742: padding: 3px;
8743: background-color: #FFFFFF;
8744: font-size: 90%;
1.753 droeschl 8745: }
1.789 droeschl 8746:
1.911 bisitz 8747: table.LC_tableOfContent {
8748: border-collapse: collapse;
1.789 droeschl 8749: }
8750:
1.771 droeschl 8751: table.LC_tableBrowseRes a,
1.768 schulted 8752: table.LC_tableOfContent a {
1.911 bisitz 8753: background-color: transparent;
8754: text-decoration: none;
1.753 droeschl 8755: }
8756:
1.795 www 8757: table.LC_tableOfContent img {
1.911 bisitz 8758: border: none;
8759: height: 1.3em;
8760: vertical-align: text-bottom;
8761: margin-right: 0.3em;
1.753 droeschl 8762: }
1.757 schulted 8763:
1.795 www 8764: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8765: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8766: }
8767:
1.795 www 8768: a#LC_content_toolbar_everything {
1.911 bisitz 8769: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8770: }
8771:
1.795 www 8772: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8773: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8774: }
8775:
1.795 www 8776: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8777: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8778: }
8779:
1.795 www 8780: a#LC_content_toolbar_changefolder {
1.911 bisitz 8781: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8782: }
8783:
1.795 www 8784: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8785: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8786: }
8787:
1.1043 raeburn 8788: a#LC_content_toolbar_edittoplevel {
8789: background-image:url(/res/adm/pages/edittoplevel.gif);
8790: }
8791:
1.1384 raeburn 8792: a#LC_content_toolbar_printout {
8793: background-image:url(/res/adm/pages/printout.gif);
8794: }
8795:
1.795 www 8796: ul#LC_toolbar li a:hover {
1.911 bisitz 8797: background-position: bottom center;
1.757 schulted 8798: }
8799:
1.795 www 8800: ul#LC_toolbar {
1.911 bisitz 8801: padding: 0;
8802: margin: 2px;
8803: list-style:none;
8804: position:relative;
8805: background-color:white;
1.1082 raeburn 8806: overflow: auto;
1.757 schulted 8807: }
8808:
1.795 www 8809: ul#LC_toolbar li {
1.911 bisitz 8810: border:1px solid white;
8811: padding: 0;
8812: margin: 0;
8813: float: left;
8814: display:inline;
8815: vertical-align:middle;
1.1082 raeburn 8816: white-space: nowrap;
1.911 bisitz 8817: }
1.757 schulted 8818:
1.783 amueller 8819:
1.795 www 8820: a.LC_toolbarItem {
1.911 bisitz 8821: display:block;
8822: padding: 0;
8823: margin: 0;
8824: height: 32px;
8825: width: 32px;
8826: color:white;
8827: border: none;
8828: background-repeat:no-repeat;
8829: background-color:transparent;
1.757 schulted 8830: }
8831:
1.915 droeschl 8832: ul.LC_funclist {
8833: margin: 0;
8834: padding: 0.5em 1em 0.5em 0;
8835: }
8836:
1.933 droeschl 8837: ul.LC_funclist > li:first-child {
8838: font-weight:bold;
8839: margin-left:0.8em;
8840: }
8841:
1.915 droeschl 8842: ul.LC_funclist + ul.LC_funclist {
8843: /*
8844: left border as a seperator if we have more than
8845: one list
8846: */
8847: border-left: 1px solid $sidebg;
8848: /*
8849: this hides the left border behind the border of the
8850: outer box if element is wrapped to the next 'line'
8851: */
8852: margin-left: -1px;
8853: }
8854:
1.843 bisitz 8855: ul.LC_funclist li {
1.915 droeschl 8856: display: inline;
1.782 bisitz 8857: white-space: nowrap;
1.915 droeschl 8858: margin: 0 0 0 25px;
8859: line-height: 150%;
1.782 bisitz 8860: }
8861:
1.974 wenzelju 8862: .LC_hidden {
8863: display: none;
8864: }
8865:
1.1030 www 8866: .LCmodal-overlay {
8867: position:fixed;
8868: top:0;
8869: right:0;
8870: bottom:0;
8871: left:0;
8872: height:100%;
8873: width:100%;
8874: margin:0;
8875: padding:0;
8876: background:#999;
8877: opacity:.75;
8878: filter: alpha(opacity=75);
8879: -moz-opacity: 0.75;
8880: z-index:101;
8881: }
8882:
8883: * html .LCmodal-overlay {
8884: position: absolute;
8885: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8886: }
8887:
8888: .LCmodal-window {
8889: position:fixed;
8890: top:50%;
8891: left:50%;
8892: margin:0;
8893: padding:0;
8894: z-index:102;
8895: }
8896:
8897: * html .LCmodal-window {
8898: position:absolute;
8899: }
8900:
8901: .LCclose-window {
8902: position:absolute;
8903: width:32px;
8904: height:32px;
8905: right:8px;
8906: top:8px;
8907: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8908: text-indent:-99999px;
8909: overflow:hidden;
8910: cursor:pointer;
8911: }
8912:
1.1369 raeburn 8913: .LCisDisabled {
8914: cursor: not-allowed;
8915: opacity: 0.5;
8916: }
8917:
8918: a[aria-disabled="true"] {
8919: color: currentColor;
8920: display: inline-block; /* For IE11/ MS Edge bug */
8921: pointer-events: none;
8922: text-decoration: none;
8923: }
8924:
1.1335 raeburn 8925: pre.LC_wordwrap {
8926: white-space: pre-wrap;
8927: white-space: -moz-pre-wrap;
8928: white-space: -pre-wrap;
8929: white-space: -o-pre-wrap;
8930: word-wrap: break-word;
8931: }
8932:
1.1100 raeburn 8933: /*
1.1231 damieng 8934: styles used for response display
8935: */
8936: div.LC_radiofoil, div.LC_rankfoil {
8937: margin: .5em 0em .5em 0em;
8938: }
8939: table.LC_itemgroup {
8940: margin-top: 1em;
8941: }
8942:
8943: /*
1.1100 raeburn 8944: styles used by TTH when "Default set of options to pass to tth/m
8945: when converting TeX" in course settings has been set
8946:
8947: option passed: -t
8948:
8949: */
8950:
8951: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8952: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8953: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8954: td div.norm {line-height:normal;}
8955:
8956: /*
8957: option passed -y3
8958: */
8959:
8960: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8961: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8962: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8963:
1.1230 damieng 8964: /*
8965: sections with roles, for content only
8966: */
8967: section[class^="role-"] {
8968: padding-left: 10px;
8969: padding-right: 5px;
8970: margin-top: 8px;
8971: margin-bottom: 8px;
8972: border: 1px solid #2A4;
8973: border-radius: 5px;
8974: box-shadow: 0px 1px 1px #BBB;
8975: }
8976: section[class^="role-"]>h1 {
8977: position: relative;
8978: margin: 0px;
8979: padding-top: 10px;
8980: padding-left: 40px;
8981: }
8982: section[class^="role-"]>h1:before {
8983: position: absolute;
8984: left: -5px;
8985: top: 5px;
8986: }
8987: section.role-activity>h1:before {
8988: content:url('/adm/daxe/images/section_icons/activity.png');
8989: }
8990: section.role-advice>h1:before {
8991: content:url('/adm/daxe/images/section_icons/advice.png');
8992: }
8993: section.role-bibliography>h1:before {
8994: content:url('/adm/daxe/images/section_icons/bibliography.png');
8995: }
8996: section.role-citation>h1:before {
8997: content:url('/adm/daxe/images/section_icons/citation.png');
8998: }
8999: section.role-conclusion>h1:before {
9000: content:url('/adm/daxe/images/section_icons/conclusion.png');
9001: }
9002: section.role-definition>h1:before {
9003: content:url('/adm/daxe/images/section_icons/definition.png');
9004: }
9005: section.role-demonstration>h1:before {
9006: content:url('/adm/daxe/images/section_icons/demonstration.png');
9007: }
9008: section.role-example>h1:before {
9009: content:url('/adm/daxe/images/section_icons/example.png');
9010: }
9011: section.role-explanation>h1:before {
9012: content:url('/adm/daxe/images/section_icons/explanation.png');
9013: }
9014: section.role-introduction>h1:before {
9015: content:url('/adm/daxe/images/section_icons/introduction.png');
9016: }
9017: section.role-method>h1:before {
9018: content:url('/adm/daxe/images/section_icons/method.png');
9019: }
9020: section.role-more_information>h1:before {
9021: content:url('/adm/daxe/images/section_icons/more_information.png');
9022: }
9023: section.role-objectives>h1:before {
9024: content:url('/adm/daxe/images/section_icons/objectives.png');
9025: }
9026: section.role-prerequisites>h1:before {
9027: content:url('/adm/daxe/images/section_icons/prerequisites.png');
9028: }
9029: section.role-remark>h1:before {
9030: content:url('/adm/daxe/images/section_icons/remark.png');
9031: }
9032: section.role-reminder>h1:before {
9033: content:url('/adm/daxe/images/section_icons/reminder.png');
9034: }
9035: section.role-summary>h1:before {
9036: content:url('/adm/daxe/images/section_icons/summary.png');
9037: }
9038: section.role-syntax>h1:before {
9039: content:url('/adm/daxe/images/section_icons/syntax.png');
9040: }
9041: section.role-warning>h1:before {
9042: content:url('/adm/daxe/images/section_icons/warning.png');
9043: }
9044:
1.1269 raeburn 9045: #LC_minitab_header {
9046: float:left;
9047: width:100%;
9048: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
9049: font-size:93%;
9050: line-height:normal;
9051: margin: 0.5em 0 0.5em 0;
9052: }
9053: #LC_minitab_header ul {
9054: margin:0;
9055: padding:10px 10px 0;
9056: list-style:none;
9057: }
9058: #LC_minitab_header li {
9059: float:left;
9060: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
9061: margin:0;
9062: padding:0 0 0 9px;
9063: }
9064: #LC_minitab_header a {
9065: display:block;
9066: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
9067: padding:5px 15px 4px 6px;
9068: }
9069: #LC_minitab_header #LC_current_minitab {
9070: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
9071: }
9072: #LC_minitab_header #LC_current_minitab a {
9073: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
9074: padding-bottom:5px;
9075: }
9076:
9077:
1.343 albertel 9078: END
9079: }
9080:
1.306 albertel 9081: =pod
9082:
9083: =item * &headtag()
9084:
9085: Returns a uniform footer for LON-CAPA web pages.
9086:
1.307 albertel 9087: Inputs: $title - optional title for the head
9088: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 9089: $args - optional arguments
1.319 albertel 9090: force_register - if is true call registerurl so the remote is
9091: informed
1.415 albertel 9092: redirect -> array ref of
9093: 1- seconds before redirect occurs
9094: 2- url to redirect to
9095: 3- whether the side effect should occur
1.315 albertel 9096: (side effect of setting
9097: $env{'internal.head.redirect'} to the url
1.1386 raeburn 9098: redirected to)
9099: 4- whether the redirect target should be
9100: the opener of the current (pop-up)
9101: window (side effect of setting
9102: $env{'internal.head.to_opener'} to
9103: 1, if true.
1.1388 raeburn 9104: 5- whether encrypt check should be skipped
1.352 albertel 9105: domain -> force to color decorate a page for a specific
9106: domain
9107: function -> force usage of a specific rolish color scheme
9108: bgcolor -> override the default page bgcolor
1.460 albertel 9109: no_auto_mt_title
9110: -> prevent &mt()ing the title arg
1.464 albertel 9111:
1.306 albertel 9112: =cut
9113:
9114: sub headtag {
1.313 albertel 9115: my ($title,$head_extra,$args) = @_;
1.306 albertel 9116:
1.363 albertel 9117: my $function = $args->{'function'} || &get_users_function();
9118: my $domain = $args->{'domain'} || &determinedomain();
9119: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 9120: my $httphost = $args->{'use_absolute'};
1.418 albertel 9121: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 9122: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 9123: #time(),
1.418 albertel 9124: $env{'environment.color.timestamp'},
1.363 albertel 9125: $function,$domain,$bgcolor);
9126:
1.369 www 9127: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 9128:
1.308 albertel 9129: my $result =
9130: '<head>'.
1.1160 raeburn 9131: &font_settings($args);
1.319 albertel 9132:
1.1188 raeburn 9133: my $inhibitprint;
9134: if ($args->{'print_suppress'}) {
9135: $inhibitprint = &print_suppression();
9136: }
1.1064 raeburn 9137:
1.461 albertel 9138: if (!$args->{'frameset'}) {
9139: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
9140: }
1.962 droeschl 9141: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
9142: $result .= Apache::lonxml::display_title();
1.319 albertel 9143: }
1.436 albertel 9144: if (!$args->{'no_nav_bar'}
9145: && !$args->{'only_body'}
9146: && !$args->{'frameset'}) {
1.1154 raeburn 9147: $result .= &help_menu_js($httphost);
1.1032 www 9148: $result.=&modal_window();
1.1038 www 9149: $result.=&togglebox_script();
1.1034 www 9150: $result.=&wishlist_window();
1.1041 www 9151: $result.=&LCprogressbarUpdate_script();
1.1034 www 9152: } else {
9153: if ($args->{'add_modal'}) {
9154: $result.=&modal_window();
9155: }
9156: if ($args->{'add_wishlist'}) {
9157: $result.=&wishlist_window();
9158: }
1.1038 www 9159: if ($args->{'add_togglebox'}) {
9160: $result.=&togglebox_script();
9161: }
1.1041 www 9162: if ($args->{'add_progressbar'}) {
9163: $result.=&LCprogressbarUpdate_script();
9164: }
1.436 albertel 9165: }
1.314 albertel 9166: if (ref($args->{'redirect'})) {
1.1388 raeburn 9167: my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
9168: if (!$skip_enc_check) {
9169: $url = &Apache::lonenc::check_encrypt($url);
9170: }
1.414 albertel 9171: if (!$inhibit_continue) {
9172: $env{'internal.head.redirect'} = $url;
9173: }
1.1386 raeburn 9174: $result.=<<"ADDMETA";
1.313 albertel 9175: <meta http-equiv="pragma" content="no-cache" />
1.1386 raeburn 9176: ADDMETA
9177: if ($to_opener) {
9178: $env{'internal.head.to_opener'} = 1;
9179: my $dest = &js_escape($url);
9180: my $timeout = int($time * 1000);
9181: $result .=<<"ENDJS";
9182: <script type="text/javascript">
9183: // <![CDATA[
9184: function LC_To_Opener() {
9185: var dest = '$dest';
9186: if (dest != '') {
9187: if (window.opener != null && !window.opener.closed) {
9188: window.opener.location.href=dest;
9189: window.close();
9190: } else {
9191: window.location.href=dest;
9192: }
9193: }
9194: }
9195: \$(document).ready(function () {
9196: setTimeout('LC_To_Opener()',$timeout);
9197: });
9198: // ]]>
9199: </script>
9200: ENDJS
9201: } else {
9202: $result.=<<"ADDMETA";
1.344 albertel 9203: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 9204: ADDMETA
1.1386 raeburn 9205: }
1.1210 raeburn 9206: } else {
9207: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
9208: my $requrl = $env{'request.uri'};
9209: if ($requrl eq '') {
9210: $requrl = $ENV{'REQUEST_URI'};
9211: $requrl =~ s/\?.+$//;
9212: }
9213: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
9214: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
9215: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
9216: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
9217: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
9218: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 9219: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 9220: my ($offload,$offloadoth);
1.1210 raeburn 9221: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
9222: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 9223: $offload = 1;
1.1353 raeburn 9224: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9225: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9226: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9227: $offloadoth = 1;
9228: $dom_in_use = $env{'user.domain'};
9229: }
9230: }
1.1340 raeburn 9231: }
9232: }
9233: unless ($offload) {
9234: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
9235: if ($domdefs{'offloadoth'}{$lonhost}) {
9236: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9237: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9238: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9239: $offload = 1;
1.1352 raeburn 9240: $offloadoth = 1;
1.1340 raeburn 9241: $dom_in_use = $env{'user.domain'};
9242: }
1.1210 raeburn 9243: }
1.1340 raeburn 9244: }
9245: }
9246: }
9247: if ($offload) {
1.1358 raeburn 9248: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1352 raeburn 9249: if (($newserver eq '') && ($offloadoth)) {
9250: my @domains = &Apache::lonnet::current_machine_domains();
9251: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
9252: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
9253: }
9254: }
1.1340 raeburn 9255: if (($newserver) && ($newserver ne $lonhost)) {
9256: my $numsec = 5;
9257: my $timeout = $numsec * 1000;
9258: my ($newurl,$locknum,%locks,$msg);
9259: if ($env{'request.role.adv'}) {
9260: ($locknum,%locks) = &Apache::lonnet::get_locks();
9261: }
9262: my $disable_submit = 0;
9263: if ($requrl =~ /$LONCAPA::assess_re/) {
9264: $disable_submit = 1;
9265: }
9266: if ($locknum) {
9267: my @lockinfo = sort(values(%locks));
1.1354 raeburn 9268: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 9269: join(", ",sort(values(%locks)))."\n";
9270: if (&show_course()) {
9271: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
9272: } else {
9273: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 9274: }
1.1340 raeburn 9275: } else {
9276: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
9277: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
9278: }
9279: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
9280: $newurl = '/adm/switchserver?otherserver='.$newserver;
9281: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
9282: $newurl .= '&role='.$env{'request.role'};
9283: }
9284: if ($env{'request.symb'}) {
9285: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
9286: if ($shownsymb =~ m{^/enc/}) {
9287: my $reqdmajor = 2;
9288: my $reqdminor = 11;
9289: my $reqdsubminor = 3;
9290: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
9291: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
9292: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
9293: if (($major eq '' && $minor eq '') ||
9294: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
9295: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
9296: ($reqdsubminor > $subminor))))) {
9297: undef($shownsymb);
9298: }
1.1210 raeburn 9299: }
1.1340 raeburn 9300: if ($shownsymb) {
9301: &js_escape(\$shownsymb);
9302: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 9303: }
1.1340 raeburn 9304: } else {
9305: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
9306: &js_escape(\$shownurl);
9307: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 9308: }
1.1340 raeburn 9309: }
9310: &js_escape(\$msg);
9311: $result.=<<OFFLOAD
1.1210 raeburn 9312: <meta http-equiv="pragma" content="no-cache" />
9313: <script type="text/javascript">
1.1215 raeburn 9314: // <![CDATA[
1.1210 raeburn 9315: function LC_Offload_Now() {
9316: var dest = "$newurl";
9317: if (dest != '') {
9318: window.location.href="$newurl";
9319: }
9320: }
1.1214 raeburn 9321: \$(document).ready(function () {
9322: window.alert('$msg');
9323: if ($disable_submit) {
1.1210 raeburn 9324: \$(".LC_hwk_submit").prop("disabled", true);
9325: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 9326: }
9327: setTimeout('LC_Offload_Now()', $timeout);
9328: });
1.1215 raeburn 9329: // ]]>
1.1210 raeburn 9330: </script>
9331: OFFLOAD
9332: }
9333: }
9334: }
9335: }
9336: }
1.313 albertel 9337: }
1.306 albertel 9338: if (!defined($title)) {
9339: $title = 'The LearningOnline Network with CAPA';
9340: }
1.460 albertel 9341: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
9342: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 9343: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
9344: if (!$args->{'frameset'}) {
9345: $result .= ' /';
9346: }
9347: $result .= '>'
1.1064 raeburn 9348: .$inhibitprint
1.414 albertel 9349: .$head_extra;
1.1242 raeburn 9350: my $clientmobile;
9351: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
9352: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
9353: } else {
9354: $clientmobile = $env{'browser.mobile'};
9355: }
9356: if ($clientmobile) {
1.1137 raeburn 9357: $result .= '
9358: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
9359: <meta name="apple-mobile-web-app-capable" content="yes" />';
9360: }
1.1278 raeburn 9361: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 9362: return $result.'</head>';
1.306 albertel 9363: }
9364:
9365: =pod
9366:
1.340 albertel 9367: =item * &font_settings()
9368:
9369: Returns neccessary <meta> to set the proper encoding
9370:
1.1160 raeburn 9371: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 9372:
9373: =cut
9374:
9375: sub font_settings {
1.1160 raeburn 9376: my ($args) = @_;
1.340 albertel 9377: my $headerstring='';
1.1160 raeburn 9378: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
9379: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 9380: $headerstring.=
9381: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
9382: if (!$args->{'frameset'}) {
9383: $headerstring.= ' /';
9384: }
9385: $headerstring .= '>'."\n";
1.340 albertel 9386: }
9387: return $headerstring;
9388: }
9389:
1.341 albertel 9390: =pod
9391:
1.1064 raeburn 9392: =item * &print_suppression()
9393:
9394: In course context returns css which causes the body to be blank when media="print",
9395: if printout generation is unavailable for the current resource.
9396:
9397: This could be because:
9398:
9399: (a) printstartdate is in the future
9400:
9401: (b) printenddate is in the past
9402:
9403: (c) there is an active exam block with "printout"
9404: functionality blocked
9405:
9406: Users with pav, pfo or evb privileges are exempt.
9407:
9408: Inputs: none
9409:
9410: =cut
9411:
9412:
9413: sub print_suppression {
9414: my $noprint;
9415: if ($env{'request.course.id'}) {
9416: my $scope = $env{'request.course.id'};
9417: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9418: (&Apache::lonnet::allowed('pfo',$scope))) {
9419: return;
9420: }
9421: if ($env{'request.course.sec'} ne '') {
9422: $scope .= "/$env{'request.course.sec'}";
9423: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9424: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 9425: return;
1.1064 raeburn 9426: }
9427: }
9428: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9429: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 9430: my $clientip = &Apache::lonnet::get_requestor_ip();
9431: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 9432: if ($blocked) {
9433: my $checkrole = "cm./$cdom/$cnum";
9434: if ($env{'request.course.sec'} ne '') {
9435: $checkrole .= "/$env{'request.course.sec'}";
9436: }
9437: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
9438: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
9439: $noprint = 1;
9440: }
9441: }
9442: unless ($noprint) {
9443: my $symb = &Apache::lonnet::symbread();
9444: if ($symb ne '') {
9445: my $navmap = Apache::lonnavmaps::navmap->new();
9446: if (ref($navmap)) {
9447: my $res = $navmap->getBySymb($symb);
9448: if (ref($res)) {
9449: if (!$res->resprintable()) {
9450: $noprint = 1;
9451: }
9452: }
9453: }
9454: }
9455: }
9456: if ($noprint) {
9457: return <<"ENDSTYLE";
9458: <style type="text/css" media="print">
9459: body { display:none }
9460: </style>
9461: ENDSTYLE
9462: }
9463: }
9464: return;
9465: }
9466:
9467: =pod
9468:
1.341 albertel 9469: =item * &xml_begin()
9470:
9471: Returns the needed doctype and <html>
9472:
9473: Inputs: none
9474:
9475: =cut
9476:
9477: sub xml_begin {
1.1168 raeburn 9478: my ($is_frameset) = @_;
1.341 albertel 9479: my $output='';
9480:
9481: if ($env{'browser.mathml'}) {
9482: $output='<?xml version="1.0"?>'
9483: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9484: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9485:
9486: # .'<!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">] >'
9487: .'<!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">'
9488: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9489: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 9490: } elsif ($is_frameset) {
9491: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
9492: '<html>'."\n";
1.341 albertel 9493: } else {
1.1168 raeburn 9494: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9495: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9496: }
9497: return $output;
9498: }
1.340 albertel 9499:
9500: =pod
9501:
1.306 albertel 9502: =item * &start_page()
9503:
9504: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9505:
1.648 raeburn 9506: Inputs:
9507:
9508: =over 4
9509:
9510: $title - optional title for the page
9511:
9512: $head_extra - optional extra HTML to incude inside the <head>
9513:
9514: $args - additional optional args supported are:
9515:
9516: =over 8
9517:
9518: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 9519: arg on
1.814 bisitz 9520: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 9521: add_entries -> additional attributes to add to the <body>
9522: domain -> force to color decorate a page for a
1.317 albertel 9523: specific domain
1.648 raeburn 9524: function -> force usage of a specific rolish color
1.317 albertel 9525: scheme
1.648 raeburn 9526: redirect -> see &headtag()
9527: bgcolor -> override the default page bg color
9528: js_ready -> return a string ready for being used in
1.317 albertel 9529: a javascript writeln
1.648 raeburn 9530: html_encode -> return a string ready for being used in
1.320 albertel 9531: a html attribute
1.648 raeburn 9532: force_register -> if is true will turn on the &bodytag()
1.317 albertel 9533: $forcereg arg
1.648 raeburn 9534: frameset -> if true will start with a <frameset>
1.330 albertel 9535: rather than <body>
1.648 raeburn 9536: skip_phases -> hash ref of
1.338 albertel 9537: head -> skip the <html><head> generation
9538: body -> skip all <body> generation
1.648 raeburn 9539: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 9540: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 9541: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 9542: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
9543: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 9544: group -> includes the current group, if page is for a
1.1274 raeburn 9545: specific group
9546: use_absolute -> for request for external resource or syllabus, this
9547: will contain https://<hostname> if server uses
9548: https (as per hosts.tab), but request is for http
9549: hostname -> hostname, originally from $r->hostname(), (optional).
1.1369 raeburn 9550: links_disabled -> Links in primary and secondary menus are disabled
9551: (Can enable them once page has loaded - see lonroles.pm
9552: for an example).
1.1380 raeburn 9553: links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 9554:
1.648 raeburn 9555: =back
1.460 albertel 9556:
1.648 raeburn 9557: =back
1.562 albertel 9558:
1.306 albertel 9559: =cut
9560:
9561: sub start_page {
1.309 albertel 9562: my ($title,$head_extra,$args) = @_;
1.318 albertel 9563: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 9564:
1.315 albertel 9565: $env{'internal.start_page'}++;
1.1359 raeburn 9566: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 9567:
1.338 albertel 9568: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 9569: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 9570: }
1.1316 raeburn 9571:
9572: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 9573: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
9574: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
9575: $args->{'no_primary_menu'} = 1;
9576: }
9577: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
9578: $args->{'no_inline_menu'} = 1;
9579: }
9580: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
9581: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
9582: }
9583: } else {
9584: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9585: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
9586: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
9587: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
9588: $args->{'no_primary_menu'} = 1;
9589: }
9590: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
9591: $args->{'no_inline_menu'} = 1;
9592: }
9593: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
9594: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
9595: }
9596: }
9597: }
1.1316 raeburn 9598: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
9599: $env{'course.'.$env{'request.course.id'}.'.domain'},
9600: $env{'course.'.$env{'request.course.id'}.'.num'});
1.1359 raeburn 9601: } elsif ($env{'request.course.id'}) {
9602: my $expiretime=600;
9603: if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
9604: &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
9605: }
9606: my ($deeplinkmenu,$menuref);
9607: ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
9608: if ($menucoll) {
9609: if (ref($menuref) eq 'HASH') {
9610: %menu = %{$menuref};
9611: }
9612: if ($menu{'top'} eq 'n') {
9613: $args->{'no_primary_menu'} = 1;
9614: }
9615: if ($menu{'inline'} eq 'n') {
9616: unless (&Apache::lonnet::allowed('opa')) {
9617: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9618: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9619: my $crstype = &course_type();
9620: my $now = time;
9621: my $ccrole;
9622: if ($crstype eq 'Community') {
9623: $ccrole = 'co';
9624: } else {
9625: $ccrole = 'cc';
9626: }
9627: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
9628: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
9629: if ((($start) && ($start<0)) ||
9630: (($end) && ($end<$now)) ||
9631: (($start) && ($now<$start))) {
9632: $args->{'no_inline_menu'} = 1;
9633: }
9634: } else {
9635: $args->{'no_inline_menu'} = 1;
9636: }
9637: }
9638: }
9639: }
1.1316 raeburn 9640: }
1.1359 raeburn 9641:
1.1385 raeburn 9642: my $showncrumbs;
1.338 albertel 9643: if (! exists($args->{'skip_phases'}{'body'}) ) {
9644: if ($args->{'frameset'}) {
9645: my $attr_string = &make_attr_string($args->{'force_register'},
9646: $args->{'add_entries'});
9647: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9648: } else {
9649: $result .=
9650: &bodytag($title,
9651: $args->{'function'}, $args->{'add_entries'},
9652: $args->{'only_body'}, $args->{'domain'},
9653: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 9654: $args->{'bgcolor'}, $args,
1.1385 raeburn 9655: \@advtools,$ltiscope,$ltiuri,\%ltimenu,$menucoll,
9656: \%menu,\$showncrumbs);
1.831 bisitz 9657: }
1.330 albertel 9658: }
1.338 albertel 9659:
1.315 albertel 9660: if ($args->{'js_ready'}) {
1.713 kaisler 9661: $result = &js_ready($result);
1.315 albertel 9662: }
1.320 albertel 9663: if ($args->{'html_encode'}) {
1.713 kaisler 9664: $result = &html_encode($result);
9665: }
9666:
1.813 bisitz 9667: # Preparation for new and consistent functionlist at top of screen
9668: # if ($args->{'functionlist'}) {
9669: # $result .= &build_functionlist();
9670: #}
9671:
1.964 droeschl 9672: # Don't add anything more if only_body wanted or in const space
9673: return $result if $args->{'only_body'}
9674: || $env{'request.state'} eq 'construct';
1.813 bisitz 9675:
9676: #Breadcrumbs
1.758 kaisler 9677: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1385 raeburn 9678: unless ($showncrumbs) {
1.758 kaisler 9679: &Apache::lonhtmlcommon::clear_breadcrumbs();
9680: #if any br links exists, add them to the breadcrumbs
9681: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9682: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9683: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9684: }
9685: }
1.1096 raeburn 9686: # if @advtools array contains items add then to the breadcrumbs
9687: if (@advtools > 0) {
9688: &Apache::lonmenu::advtools_crumbs(@advtools);
9689: }
1.1272 raeburn 9690: my $menulink;
9691: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
9692: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 9693: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 9694: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
9695: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
9696: (!$env{'request.role.adv'}))) {
9697: $menulink = 0;
9698: } else {
9699: undef($menulink);
9700: }
1.1385 raeburn 9701: my $linkprotout;
9702: if ($env{'request.deeplink.login'}) {
9703: my $linkprotout = &Apache::lonmenu::linkprot_exit();
9704: if ($linkprotout) {
9705: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
9706: }
9707: }
1.758 kaisler 9708: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9709: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 9710: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 9711: } else {
1.1272 raeburn 9712: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9713: }
1.1385 raeburn 9714: }
1.320 albertel 9715: }
1.315 albertel 9716: return $result;
1.306 albertel 9717: }
9718:
9719: sub end_page {
1.315 albertel 9720: my ($args) = @_;
9721: $env{'internal.end_page'}++;
1.330 albertel 9722: my $result;
1.335 albertel 9723: if ($args->{'discussion'}) {
9724: my ($target,$parser);
9725: if (ref($args->{'discussion'})) {
9726: ($target,$parser) =($args->{'discussion'}{'target'},
9727: $args->{'discussion'}{'parser'});
9728: }
9729: $result .= &Apache::lonxml::xmlend($target,$parser);
9730: }
1.330 albertel 9731: if ($args->{'frameset'}) {
9732: $result .= '</frameset>';
9733: } else {
1.635 raeburn 9734: $result .= &endbodytag($args);
1.330 albertel 9735: }
1.1080 raeburn 9736: unless ($args->{'notbody'}) {
9737: $result .= "\n</html>";
9738: }
1.330 albertel 9739:
1.315 albertel 9740: if ($args->{'js_ready'}) {
1.317 albertel 9741: $result = &js_ready($result);
1.315 albertel 9742: }
1.335 albertel 9743:
1.320 albertel 9744: if ($args->{'html_encode'}) {
9745: $result = &html_encode($result);
9746: }
1.335 albertel 9747:
1.315 albertel 9748: return $result;
9749: }
9750:
1.1359 raeburn 9751: sub menucoll_in_effect {
9752: my ($menucoll,$deeplinkmenu,%menu);
9753: if ($env{'request.course.id'}) {
9754: $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
1.1362 raeburn 9755: if ($env{'request.deeplink.login'}) {
1.1370 raeburn 9756: my ($deeplink_symb,$deeplink,$check_login_symb);
1.1362 raeburn 9757: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9758: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9759: if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9760: if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9761: my $navmap = Apache::lonnavmaps::navmap->new();
9762: if (ref($navmap)) {
9763: $deeplink = $navmap->get_mapparam(undef,
9764: &Apache::lonnet::declutter($env{'request.noversionuri'}),
9765: '0.deeplink');
1.1370 raeburn 9766: } else {
9767: $check_login_symb = 1;
1.1362 raeburn 9768: }
9769: } else {
1.1370 raeburn 9770: my $symb = &Apache::lonnet::symbread();
9771: if ($symb) {
9772: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9773: } else {
9774: $check_login_symb = 1;
9775: }
1.1362 raeburn 9776: }
9777: } else {
1.1370 raeburn 9778: $check_login_symb = 1;
9779: }
9780: if ($check_login_symb) {
1.1362 raeburn 9781: $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9782: if ($deeplink_symb =~ /\.(page|sequence)$/) {
9783: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9784: my $navmap = Apache::lonnavmaps::navmap->new();
9785: if (ref($navmap)) {
9786: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9787: }
9788: } else {
9789: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9790: }
9791: }
1.1359 raeburn 9792: if ($deeplink ne '') {
1.1378 raeburn 9793: my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
1.1359 raeburn 9794: if ($display =~ /^\d+$/) {
9795: $deeplinkmenu = 1;
9796: $menucoll = $display;
9797: }
9798: }
9799: }
9800: if ($menucoll) {
9801: %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9802: }
9803: }
9804: return ($menucoll,$deeplinkmenu,\%menu);
9805: }
9806:
1.1362 raeburn 9807: sub deeplink_login_symb {
9808: my ($cnum,$cdom) = @_;
9809: my $login_symb;
9810: if ($env{'request.deeplink.login'}) {
1.1364 raeburn 9811: $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9812: }
9813: return $login_symb;
9814: }
9815:
9816: sub symb_from_tinyurl {
9817: my ($url,$cnum,$cdom) = @_;
9818: if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9819: my $key = $1;
9820: my ($tinyurl,$login);
9821: my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9822: if (defined($cached)) {
9823: $tinyurl = $result;
9824: } else {
9825: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9826: my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9827: if ($currtiny{$key} ne '') {
9828: $tinyurl = $currtiny{$key};
9829: &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
1.1362 raeburn 9830: }
1.1364 raeburn 9831: }
9832: if ($tinyurl ne '') {
9833: my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9834: if (wantarray) {
9835: return ($cnumreq,$symb);
9836: } elsif ($cnumreq eq $cnum) {
9837: return $symb;
1.1362 raeburn 9838: }
9839: }
9840: }
1.1364 raeburn 9841: if (wantarray) {
9842: return ();
9843: } else {
9844: return;
9845: }
1.1362 raeburn 9846: }
9847:
1.1405 raeburn 9848: sub usable_exttools {
9849: my %tooltypes;
9850: if ($env{'request.course.id'}) {
9851: if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) {
9852: if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') {
9853: %tooltypes = (
9854: crs => 1,
9855: dom => 1,
9856: );
9857: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') {
9858: $tooltypes{'crs'} = 1;
9859: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') {
9860: $tooltypes{'dom'} = 1;
9861: }
9862: } else {
9863: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9864: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9865: my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'});
9866: if ($crstype eq '') {
9867: $crstype = 'course';
9868: }
9869: if ($crstype eq 'course') {
9870: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) {
9871: $crstype = 'official';
9872: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
9873: $crstype = 'textbook';
9874: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) {
9875: $crstype = 'lti';
9876: } else {
9877: $crstype = 'unofficial';
9878: }
9879: }
9880: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
9881: if ($domdefaults{$crstype.'domexttool'}) {
9882: $tooltypes{'dom'} = 1;
9883: }
9884: if ($domdefaults{$crstype.'exttool'}) {
9885: $tooltypes{'crs'} = 1;
9886: }
9887: }
9888: }
9889: return %tooltypes;
9890: }
9891:
1.1034 www 9892: sub wishlist_window {
9893: return(<<'ENDWISHLIST');
1.1046 raeburn 9894: <script type="text/javascript">
1.1034 www 9895: // <![CDATA[
9896: // <!-- BEGIN LON-CAPA Internal
9897: function set_wishlistlink(title, path) {
9898: if (!title) {
9899: title = document.title;
9900: title = title.replace(/^LON-CAPA /,'');
9901: }
1.1175 raeburn 9902: title = encodeURIComponent(title);
1.1203 raeburn 9903: title = title.replace("'","\\\'");
1.1034 www 9904: if (!path) {
9905: path = location.pathname;
9906: }
1.1175 raeburn 9907: path = encodeURIComponent(path);
1.1203 raeburn 9908: path = path.replace("'","\\\'");
1.1034 www 9909: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9910: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9911: }
9912: // END LON-CAPA Internal -->
9913: // ]]>
9914: </script>
9915: ENDWISHLIST
9916: }
9917:
1.1030 www 9918: sub modal_window {
9919: return(<<'ENDMODAL');
1.1046 raeburn 9920: <script type="text/javascript">
1.1030 www 9921: // <![CDATA[
9922: // <!-- BEGIN LON-CAPA Internal
9923: var modalWindow = {
9924: parent:"body",
9925: windowId:null,
9926: content:null,
9927: width:null,
9928: height:null,
9929: close:function()
9930: {
9931: $(".LCmodal-window").remove();
9932: $(".LCmodal-overlay").remove();
9933: },
9934: open:function()
9935: {
9936: var modal = "";
9937: modal += "<div class=\"LCmodal-overlay\"></div>";
9938: 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;\">";
9939: modal += this.content;
9940: modal += "</div>";
9941:
9942: $(this.parent).append(modal);
9943:
9944: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9945: $(".LCclose-window").click(function(){modalWindow.close();});
9946: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9947: }
9948: };
1.1140 raeburn 9949: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9950: {
1.1266 raeburn 9951: source = source.replace(/'/g,"'");
1.1030 www 9952: modalWindow.windowId = "myModal";
9953: modalWindow.width = width;
9954: modalWindow.height = height;
1.1196 raeburn 9955: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9956: modalWindow.open();
1.1208 raeburn 9957: };
1.1030 www 9958: // END LON-CAPA Internal -->
9959: // ]]>
9960: </script>
9961: ENDMODAL
9962: }
9963:
9964: sub modal_link {
1.1140 raeburn 9965: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9966: unless ($width) { $width=480; }
9967: unless ($height) { $height=400; }
1.1031 www 9968: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9969: unless ($transparency) { $transparency='true'; }
9970:
1.1074 raeburn 9971: my $target_attr;
9972: if (defined($target)) {
9973: $target_attr = 'target="'.$target.'"';
9974: }
9975: return <<"ENDLINK";
1.1336 raeburn 9976: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9977: ENDLINK
1.1030 www 9978: }
9979:
1.1032 www 9980: sub modal_adhoc_script {
1.1365 raeburn 9981: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9982: my $mathjax;
9983: if ($possmathjax) {
9984: $mathjax = <<'ENDJAX';
9985: if (typeof MathJax == 'object') {
9986: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9987: }
9988: ENDJAX
9989: }
1.1032 www 9990: return (<<ENDADHOC);
1.1046 raeburn 9991: <script type="text/javascript">
1.1032 www 9992: // <![CDATA[
9993: var $funcname = function()
9994: {
9995: modalWindow.windowId = "myModal";
9996: modalWindow.width = $width;
9997: modalWindow.height = $height;
9998: modalWindow.content = '$content';
9999: modalWindow.open();
1.1365 raeburn 10000: $mathjax
1.1032 www 10001: };
10002: // ]]>
10003: </script>
10004: ENDADHOC
10005: }
10006:
1.1041 www 10007: sub modal_adhoc_inner {
1.1365 raeburn 10008: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 10009: my $innerwidth=$width-20;
10010: $content=&js_ready(
1.1140 raeburn 10011: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
10012: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
10013: $content.
1.1041 www 10014: &end_scrollbox().
1.1140 raeburn 10015: &end_page()
1.1041 www 10016: );
1.1365 raeburn 10017: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 10018: }
10019:
10020: sub modal_adhoc_window {
1.1365 raeburn 10021: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
10022: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 10023: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
10024: }
10025:
10026: sub modal_adhoc_launch {
10027: my ($funcname,$width,$height,$content)=@_;
10028: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
10029: <script type="text/javascript">
10030: // <![CDATA[
10031: $funcname();
10032: // ]]>
10033: </script>
10034: ENDLAUNCH
10035: }
10036:
10037: sub modal_adhoc_close {
10038: return (<<ENDCLOSE);
10039: <script type="text/javascript">
10040: // <![CDATA[
10041: modalWindow.close();
10042: // ]]>
10043: </script>
10044: ENDCLOSE
10045: }
10046:
1.1038 www 10047: sub togglebox_script {
10048: return(<<ENDTOGGLE);
10049: <script type="text/javascript">
10050: // <![CDATA[
10051: function LCtoggleDisplay(id,hidetext,showtext) {
10052: link = document.getElementById(id + "link").childNodes[0];
10053: with (document.getElementById(id).style) {
10054: if (display == "none" ) {
10055: display = "inline";
10056: link.nodeValue = hidetext;
10057: } else {
10058: display = "none";
10059: link.nodeValue = showtext;
10060: }
10061: }
10062: }
10063: // ]]>
10064: </script>
10065: ENDTOGGLE
10066: }
10067:
1.1039 www 10068: sub start_togglebox {
10069: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
10070: unless ($heading) { $heading=''; } else { $heading.=' '; }
10071: unless ($showtext) { $showtext=&mt('show'); }
10072: unless ($hidetext) { $hidetext=&mt('hide'); }
10073: unless ($headerbg) { $headerbg='#FFFFFF'; }
10074: return &start_data_table().
10075: &start_data_table_header_row().
10076: '<td bgcolor="'.$headerbg.'">'.$heading.
10077: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
10078: $showtext.'\')">'.$showtext.'</a>]</td>'.
10079: &end_data_table_header_row().
10080: '<tr id="'.$id.'" style="display:none""><td>';
10081: }
10082:
10083: sub end_togglebox {
10084: return '</td></tr>'.&end_data_table();
10085: }
10086:
1.1041 www 10087: sub LCprogressbar_script {
1.1302 raeburn 10088: my ($id,$number_to_do)=@_;
10089: if ($number_to_do) {
10090: return(<<ENDPROGRESS);
1.1041 www 10091: <script type="text/javascript">
10092: // <![CDATA[
1.1045 www 10093: \$('#progressbar$id').progressbar({
1.1041 www 10094: value: 0,
10095: change: function(event, ui) {
10096: var newVal = \$(this).progressbar('option', 'value');
10097: \$('.pblabel', this).text(LCprogressTxt);
10098: }
10099: });
10100: // ]]>
10101: </script>
10102: ENDPROGRESS
1.1302 raeburn 10103: } else {
10104: return(<<ENDPROGRESS);
10105: <script type="text/javascript">
10106: // <![CDATA[
10107: \$('#progressbar$id').progressbar({
10108: value: false,
10109: create: function(event, ui) {
10110: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
10111: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
10112: }
10113: });
10114: // ]]>
10115: </script>
10116: ENDPROGRESS
10117: }
1.1041 www 10118: }
10119:
10120: sub LCprogressbarUpdate_script {
10121: return(<<ENDPROGRESSUPDATE);
10122: <style type="text/css">
10123: .ui-progressbar { position:relative; }
1.1302 raeburn 10124: .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 10125: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
10126: </style>
10127: <script type="text/javascript">
10128: // <![CDATA[
1.1045 www 10129: var LCprogressTxt='---';
10130:
1.1302 raeburn 10131: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 10132: LCprogressTxt=progresstext;
1.1302 raeburn 10133: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
10134: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
10135: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 10136: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
10137: } else {
10138: \$('#progressbar'+id).progressbar('value',percent);
10139: }
1.1041 www 10140: }
10141: // ]]>
10142: </script>
10143: ENDPROGRESSUPDATE
10144: }
10145:
1.1042 www 10146: my $LClastpercent;
1.1045 www 10147: my $LCidcnt;
10148: my $LCcurrentid;
1.1042 www 10149:
1.1041 www 10150: sub LCprogressbar {
1.1302 raeburn 10151: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 10152: $LClastpercent=0;
1.1045 www 10153: $LCidcnt++;
10154: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 10155: my ($starting,$content);
10156: if ($number_to_do) {
10157: $starting=&mt('Starting');
10158: $content=(<<ENDPROGBAR);
10159: $preamble
1.1045 www 10160: <div id="progressbar$LCcurrentid">
1.1041 www 10161: <span class="pblabel">$starting</span>
10162: </div>
10163: ENDPROGBAR
1.1302 raeburn 10164: } else {
10165: $starting=&mt('Loading...');
10166: $LClastpercent='false';
10167: $content=(<<ENDPROGBAR);
10168: $preamble
10169: <div id="progressbar$LCcurrentid">
10170: <div class="progress-label">$starting</div>
10171: </div>
10172: ENDPROGBAR
10173: }
10174: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 10175: }
10176:
10177: sub LCprogressbarUpdate {
1.1302 raeburn 10178: my ($r,$val,$text,$number_to_do)=@_;
10179: if ($number_to_do) {
10180: unless ($val) {
10181: if ($LClastpercent) {
10182: $val=$LClastpercent;
10183: } else {
10184: $val=0;
10185: }
10186: }
10187: if ($val<0) { $val=0; }
10188: if ($val>100) { $val=0; }
10189: $LClastpercent=$val;
10190: unless ($text) { $text=$val.'%'; }
10191: } else {
10192: $val = 'false';
1.1042 www 10193: }
1.1041 www 10194: $text=&js_ready($text);
1.1044 www 10195: &r_print($r,<<ENDUPDATE);
1.1041 www 10196: <script type="text/javascript">
10197: // <![CDATA[
1.1302 raeburn 10198: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 10199: // ]]>
10200: </script>
10201: ENDUPDATE
1.1035 www 10202: }
10203:
1.1042 www 10204: sub LCprogressbarClose {
10205: my ($r)=@_;
10206: $LClastpercent=0;
1.1044 www 10207: &r_print($r,<<ENDCLOSE);
1.1042 www 10208: <script type="text/javascript">
10209: // <![CDATA[
1.1045 www 10210: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 10211: // ]]>
10212: </script>
10213: ENDCLOSE
1.1044 www 10214: }
10215:
10216: sub r_print {
10217: my ($r,$to_print)=@_;
10218: if ($r) {
10219: $r->print($to_print);
10220: $r->rflush();
10221: } else {
10222: print($to_print);
10223: }
1.1042 www 10224: }
10225:
1.320 albertel 10226: sub html_encode {
10227: my ($result) = @_;
10228:
1.322 albertel 10229: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 10230:
10231: return $result;
10232: }
1.1044 www 10233:
1.317 albertel 10234: sub js_ready {
10235: my ($result) = @_;
10236:
1.323 albertel 10237: $result =~ s/[\n\r]/ /xmsg;
10238: $result =~ s/\\/\\\\/xmsg;
10239: $result =~ s/'/\\'/xmsg;
1.372 albertel 10240: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 10241:
10242: return $result;
10243: }
10244:
1.315 albertel 10245: sub validate_page {
10246: if ( exists($env{'internal.start_page'})
1.316 albertel 10247: && $env{'internal.start_page'} > 1) {
10248: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 10249: $env{'internal.start_page'}.' '.
1.316 albertel 10250: $ENV{'request.filename'});
1.315 albertel 10251: }
10252: if ( exists($env{'internal.end_page'})
1.316 albertel 10253: && $env{'internal.end_page'} > 1) {
10254: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 10255: $env{'internal.end_page'}.' '.
1.316 albertel 10256: $env{'request.filename'});
1.315 albertel 10257: }
10258: if ( exists($env{'internal.start_page'})
10259: && ! exists($env{'internal.end_page'})) {
1.316 albertel 10260: &Apache::lonnet::logthis('start_page called without end_page '.
10261: $env{'request.filename'});
1.315 albertel 10262: }
10263: if ( ! exists($env{'internal.start_page'})
10264: && exists($env{'internal.end_page'})) {
1.316 albertel 10265: &Apache::lonnet::logthis('end_page called without start_page'.
10266: $env{'request.filename'});
1.315 albertel 10267: }
1.306 albertel 10268: }
1.315 albertel 10269:
1.996 www 10270:
10271: sub start_scrollbox {
1.1140 raeburn 10272: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 10273: unless ($outerwidth) { $outerwidth='520px'; }
10274: unless ($width) { $width='500px'; }
10275: unless ($height) { $height='200px'; }
1.1075 raeburn 10276: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 10277: if ($id ne '') {
1.1140 raeburn 10278: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 10279: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 10280: }
1.1075 raeburn 10281: if ($bgcolor ne '') {
10282: $tdcol = "background-color: $bgcolor;";
10283: }
1.1137 raeburn 10284: my $nicescroll_js;
10285: if ($env{'browser.mobile'}) {
1.1140 raeburn 10286: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
10287: }
10288: return <<"END";
10289: $nicescroll_js
10290:
10291: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
10292: <div style="overflow:auto; width:$width; height:$height;"$div_id>
10293: END
10294: }
10295:
10296: sub end_scrollbox {
10297: return '</div></td></tr></table>';
10298: }
10299:
10300: sub nicescroll_javascript {
10301: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
10302: my %options;
10303: if (ref($cursor) eq 'HASH') {
10304: %options = %{$cursor};
10305: }
10306: unless ($options{'railalign'} =~ /^left|right$/) {
10307: $options{'railalign'} = 'left';
10308: }
10309: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10310: my $function = &get_users_function();
10311: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 10312: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 10313: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 10314: }
1.1140 raeburn 10315: }
10316: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
10317: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 10318: $options{'cursoropacity'}='1.0';
10319: }
1.1140 raeburn 10320: } else {
10321: $options{'cursoropacity'}='1.0';
10322: }
10323: if ($options{'cursorfixedheight'} eq 'none') {
10324: delete($options{'cursorfixedheight'});
10325: } else {
10326: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
10327: }
10328: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
10329: delete($options{'railoffset'});
10330: }
10331: my @niceoptions;
10332: while (my($key,$value) = each(%options)) {
10333: if ($value =~ /^\{.+\}$/) {
10334: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 10335: } else {
1.1140 raeburn 10336: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 10337: }
1.1140 raeburn 10338: }
10339: my $nicescroll_js = '
1.1137 raeburn 10340: $(document).ready(
1.1140 raeburn 10341: function() {
10342: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
10343: }
1.1137 raeburn 10344: );
10345: ';
1.1140 raeburn 10346: if ($framecheck) {
10347: $nicescroll_js .= '
10348: function expand_div(caller) {
10349: if (top === self) {
10350: document.getElementById("'.$id.'").style.width = "auto";
10351: document.getElementById("'.$id.'").style.height = "auto";
10352: } else {
10353: try {
10354: if (parent.frames) {
10355: if (parent.frames.length > 1) {
10356: var framesrc = parent.frames[1].location.href;
10357: var currsrc = framesrc.replace(/\#.*$/,"");
10358: if ((caller == "search") || (currsrc == "'.$location.'")) {
10359: document.getElementById("'.$id.'").style.width = "auto";
10360: document.getElementById("'.$id.'").style.height = "auto";
10361: }
10362: }
10363: }
10364: } catch (e) {
10365: return;
10366: }
1.1137 raeburn 10367: }
1.1140 raeburn 10368: return;
1.996 www 10369: }
1.1140 raeburn 10370: ';
10371: }
10372: if ($needjsready) {
10373: $nicescroll_js = '
10374: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
10375: } else {
10376: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
10377: }
10378: return $nicescroll_js;
1.996 www 10379: }
10380:
1.318 albertel 10381: sub simple_error_page {
1.1150 bisitz 10382: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 10383: my %displayargs;
1.1151 raeburn 10384: if (ref($args) eq 'HASH') {
10385: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 10386: if ($args->{'only_body'}) {
10387: $displayargs{'only_body'} = 1;
10388: }
10389: if ($args->{'no_nav_bar'}) {
10390: $displayargs{'no_nav_bar'} = 1;
10391: }
1.1151 raeburn 10392: } else {
10393: $msg = &mt($msg);
10394: }
1.1150 bisitz 10395:
1.318 albertel 10396: my $page =
1.1304 raeburn 10397: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 10398: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 10399: &Apache::loncommon::end_page();
10400: if (ref($r)) {
10401: $r->print($page);
1.327 albertel 10402: return;
1.318 albertel 10403: }
10404: return $page;
10405: }
1.347 albertel 10406:
10407: {
1.610 albertel 10408: my @row_count;
1.961 onken 10409:
10410: sub start_data_table_count {
10411: unshift(@row_count, 0);
10412: return;
10413: }
10414:
10415: sub end_data_table_count {
10416: shift(@row_count);
10417: return;
10418: }
10419:
1.347 albertel 10420: sub start_data_table {
1.1018 raeburn 10421: my ($add_class,$id) = @_;
1.422 albertel 10422: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 10423: my $table_id;
10424: if (defined($id)) {
10425: $table_id = ' id="'.$id.'"';
10426: }
1.961 onken 10427: &start_data_table_count();
1.1018 raeburn 10428: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 10429: }
10430:
10431: sub end_data_table {
1.961 onken 10432: &end_data_table_count();
1.389 albertel 10433: return '</table>'."\n";;
1.347 albertel 10434: }
10435:
10436: sub start_data_table_row {
1.974 wenzelju 10437: my ($add_class, $id) = @_;
1.610 albertel 10438: $row_count[0]++;
10439: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 10440: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 10441: $id = (' id="'.$id.'"') unless ($id eq '');
10442: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 10443: }
1.471 banghart 10444:
10445: sub continue_data_table_row {
1.974 wenzelju 10446: my ($add_class, $id) = @_;
1.610 albertel 10447: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 10448: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10449: $id = (' id="'.$id.'"') unless ($id eq '');
10450: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 10451: }
1.347 albertel 10452:
10453: sub end_data_table_row {
1.389 albertel 10454: return '</tr>'."\n";;
1.347 albertel 10455: }
1.367 www 10456:
1.421 albertel 10457: sub start_data_table_empty_row {
1.707 bisitz 10458: # $row_count[0]++;
1.421 albertel 10459: return '<tr class="LC_empty_row" >'."\n";;
10460: }
10461:
10462: sub end_data_table_empty_row {
10463: return '</tr>'."\n";;
10464: }
10465:
1.367 www 10466: sub start_data_table_header_row {
1.389 albertel 10467: return '<tr class="LC_header_row">'."\n";;
1.367 www 10468: }
10469:
10470: sub end_data_table_header_row {
1.389 albertel 10471: return '</tr>'."\n";;
1.367 www 10472: }
1.890 droeschl 10473:
10474: sub data_table_caption {
10475: my $caption = shift;
10476: return "<caption class=\"LC_caption\">$caption</caption>";
10477: }
1.347 albertel 10478: }
10479:
1.548 albertel 10480: =pod
10481:
10482: =item * &inhibit_menu_check($arg)
10483:
10484: Checks for a inhibitmenu state and generates output to preserve it
10485:
10486: Inputs: $arg - can be any of
10487: - undef - in which case the return value is a string
10488: to add into arguments list of a uri
10489: - 'input' - in which case the return value is a HTML
10490: <form> <input> field of type hidden to
10491: preserve the value
10492: - a url - in which case the return value is the url with
10493: the neccesary cgi args added to preserve the
10494: inhibitmenu state
10495: - a ref to a url - no return value, but the string is
10496: updated to include the neccessary cgi
10497: args to preserve the inhibitmenu state
10498:
10499: =cut
10500:
10501: sub inhibit_menu_check {
10502: my ($arg) = @_;
10503: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
10504: if ($arg eq 'input') {
10505: if ($env{'form.inhibitmenu'}) {
10506: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
10507: } else {
10508: return
10509: }
10510: }
10511: if ($env{'form.inhibitmenu'}) {
10512: if (ref($arg)) {
10513: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10514: } elsif ($arg eq '') {
10515: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
10516: } else {
10517: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10518: }
10519: }
10520: if (!ref($arg)) {
10521: return $arg;
10522: }
10523: }
10524:
1.251 albertel 10525: ###############################################
1.182 matthew 10526:
10527: =pod
10528:
1.549 albertel 10529: =back
10530:
10531: =head1 User Information Routines
10532:
10533: =over 4
10534:
1.405 albertel 10535: =item * &get_users_function()
1.182 matthew 10536:
10537: Used by &bodytag to determine the current users primary role.
10538: Returns either 'student','coordinator','admin', or 'author'.
10539:
10540: =cut
10541:
10542: ###############################################
10543: sub get_users_function {
1.815 tempelho 10544: my $function = 'norole';
1.818 tempelho 10545: if ($env{'request.role'}=~/^(st)/) {
10546: $function='student';
10547: }
1.907 raeburn 10548: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 10549: $function='coordinator';
10550: }
1.258 albertel 10551: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 10552: $function='admin';
10553: }
1.826 bisitz 10554: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 10555: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 10556: $function='author';
10557: }
10558: return $function;
1.54 www 10559: }
1.99 www 10560:
10561: ###############################################
10562:
1.233 raeburn 10563: =pod
10564:
1.821 raeburn 10565: =item * &show_course()
10566:
10567: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
10568: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
10569:
10570: Inputs:
10571: None
10572:
10573: Outputs:
10574: Scalar: 1 if 'Course' to be used, 0 otherwise.
10575:
10576: =cut
10577:
10578: ###############################################
10579: sub show_course {
1.1408 raeburn 10580: my ($udom,$uname) = @_;
10581: if (($udom ne '') && ($uname ne '')) {
10582: if (($udom ne $env{'user.domain'}) || ($uname ne $env{'user.name'})) {
1.1410 raeburn 10583: if (&Apache::lonnet::is_advanced_user($udom,$uname)) {
1.1408 raeburn 10584: return 0;
10585: } else {
10586: return 1;
10587: }
10588: }
10589: }
1.821 raeburn 10590: my $course = !$env{'user.adv'};
10591: if (!$env{'user.adv'}) {
10592: foreach my $env (keys(%env)) {
10593: next if ($env !~ m/^user\.priv\./);
10594: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
10595: $course = 0;
10596: last;
10597: }
10598: }
10599: }
10600: return $course;
10601: }
10602:
10603: ###############################################
10604:
10605: =pod
10606:
1.542 raeburn 10607: =item * &check_user_status()
1.274 raeburn 10608:
10609: Determines current status of supplied role for a
10610: specific user. Roles can be active, previous or future.
10611:
10612: Inputs:
10613: user's domain, user's username, course's domain,
1.375 raeburn 10614: course's number, optional section ID.
1.274 raeburn 10615:
10616: Outputs:
10617: role status: active, previous or future.
10618:
10619: =cut
10620:
10621: sub check_user_status {
1.412 raeburn 10622: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 10623: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 10624: my @uroles = keys(%userinfo);
1.274 raeburn 10625: my $srchstr;
10626: my $active_chk = 'none';
1.412 raeburn 10627: my $now = time;
1.274 raeburn 10628: if (@uroles > 0) {
1.908 raeburn 10629: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 10630: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
10631: } else {
1.412 raeburn 10632: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
10633: }
10634: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 10635: my $role_end = 0;
10636: my $role_start = 0;
10637: $active_chk = 'active';
1.412 raeburn 10638: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
10639: $role_end = $1;
10640: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
10641: $role_start = $1;
1.274 raeburn 10642: }
10643: }
10644: if ($role_start > 0) {
1.412 raeburn 10645: if ($now < $role_start) {
1.274 raeburn 10646: $active_chk = 'future';
10647: }
10648: }
10649: if ($role_end > 0) {
1.412 raeburn 10650: if ($now > $role_end) {
1.274 raeburn 10651: $active_chk = 'previous';
10652: }
10653: }
10654: }
10655: }
10656: return $active_chk;
10657: }
10658:
10659: ###############################################
10660:
10661: =pod
10662:
1.405 albertel 10663: =item * &get_sections()
1.233 raeburn 10664:
10665: Determines all the sections for a course including
10666: sections with students and sections containing other roles.
1.419 raeburn 10667: Incoming parameters:
10668:
10669: 1. domain
10670: 2. course number
10671: 3. reference to array containing roles for which sections should
10672: be gathered (optional).
10673: 4. reference to array containing status types for which sections
10674: should be gathered (optional).
10675:
10676: If the third argument is undefined, sections are gathered for any role.
10677: If the fourth argument is undefined, sections are gathered for any status.
10678: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10679:
1.374 raeburn 10680: Returns section hash (keys are section IDs, values are
10681: number of users in each section), subject to the
1.419 raeburn 10682: optional roles filter, optional status filter
1.233 raeburn 10683:
10684: =cut
10685:
10686: ###############################################
10687: sub get_sections {
1.419 raeburn 10688: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10689: if (!defined($cdom) || !defined($cnum)) {
10690: my $cid = $env{'request.course.id'};
10691:
10692: return if (!defined($cid));
10693:
10694: $cdom = $env{'course.'.$cid.'.domain'};
10695: $cnum = $env{'course.'.$cid.'.num'};
10696: }
10697:
10698: my %sectioncount;
1.419 raeburn 10699: my $now = time;
1.240 albertel 10700:
1.1118 raeburn 10701: my $check_students = 1;
10702: my $only_students = 0;
10703: if (ref($possible_roles) eq 'ARRAY') {
10704: if (grep(/^st$/,@{$possible_roles})) {
10705: if (@{$possible_roles} == 1) {
10706: $only_students = 1;
10707: }
10708: } else {
10709: $check_students = 0;
10710: }
10711: }
10712:
10713: if ($check_students) {
1.276 albertel 10714: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10715: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10716: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10717: my $start_index = &Apache::loncoursedata::CL_START();
10718: my $end_index = &Apache::loncoursedata::CL_END();
10719: my $status;
1.366 albertel 10720: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10721: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10722: $data->[$status_index],
10723: $data->[$start_index],
10724: $data->[$end_index]);
10725: if ($stu_status eq 'Active') {
10726: $status = 'active';
10727: } elsif ($end < $now) {
10728: $status = 'previous';
10729: } elsif ($start > $now) {
10730: $status = 'future';
10731: }
10732: if ($section ne '-1' && $section !~ /^\s*$/) {
10733: if ((!defined($possible_status)) || (($status ne '') &&
10734: (grep/^\Q$status\E$/,@{$possible_status}))) {
10735: $sectioncount{$section}++;
10736: }
1.240 albertel 10737: }
10738: }
10739: }
1.1118 raeburn 10740: if ($only_students) {
10741: return %sectioncount;
10742: }
1.240 albertel 10743: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10744: foreach my $user (sort(keys(%courseroles))) {
10745: if ($user !~ /^(\w{2})/) { next; }
10746: my ($role) = ($user =~ /^(\w{2})/);
10747: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10748: my ($section,$status);
1.240 albertel 10749: if ($role eq 'cr' &&
10750: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10751: $section=$1;
10752: }
10753: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10754: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10755: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10756: if ($end == -1 && $start == -1) {
10757: next; #deleted role
10758: }
10759: if (!defined($possible_status)) {
10760: $sectioncount{$section}++;
10761: } else {
10762: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10763: $status = 'active';
10764: } elsif ($end < $now) {
10765: $status = 'future';
10766: } elsif ($start > $now) {
10767: $status = 'previous';
10768: }
10769: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10770: $sectioncount{$section}++;
10771: }
10772: }
1.233 raeburn 10773: }
1.366 albertel 10774: return %sectioncount;
1.233 raeburn 10775: }
10776:
1.274 raeburn 10777: ###############################################
1.294 raeburn 10778:
10779: =pod
1.405 albertel 10780:
10781: =item * &get_course_users()
10782:
1.275 raeburn 10783: Retrieves usernames:domains for users in the specified course
10784: with specific role(s), and access status.
10785:
10786: Incoming parameters:
1.277 albertel 10787: 1. course domain
10788: 2. course number
10789: 3. access status: users must have - either active,
1.275 raeburn 10790: previous, future, or all.
1.277 albertel 10791: 4. reference to array of permissible roles
1.288 raeburn 10792: 5. reference to array of section restrictions (optional)
10793: 6. reference to results object (hash of hashes).
10794: 7. reference to optional userdata hash
1.609 raeburn 10795: 8. reference to optional statushash
1.630 raeburn 10796: 9. flag if privileged users (except those set to unhide in
10797: course settings) should be excluded
1.609 raeburn 10798: Keys of top level results hash are roles.
1.275 raeburn 10799: Keys of inner hashes are username:domain, with
10800: values set to access type.
1.288 raeburn 10801: Optional userdata hash returns an array with arguments in the
10802: same order as loncoursedata::get_classlist() for student data.
10803:
1.609 raeburn 10804: Optional statushash returns
10805:
1.288 raeburn 10806: Entries for end, start, section and status are blank because
10807: of the possibility of multiple values for non-student roles.
10808:
1.275 raeburn 10809: =cut
1.405 albertel 10810:
1.275 raeburn 10811: ###############################################
1.405 albertel 10812:
1.275 raeburn 10813: sub get_course_users {
1.630 raeburn 10814: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10815: my %idx = ();
1.419 raeburn 10816: my %seclists;
1.288 raeburn 10817:
10818: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10819: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10820: $idx{end} = &Apache::loncoursedata::CL_END();
10821: $idx{start} = &Apache::loncoursedata::CL_START();
10822: $idx{id} = &Apache::loncoursedata::CL_ID();
10823: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10824: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10825: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10826:
1.290 albertel 10827: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10828: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10829: my $now = time;
1.277 albertel 10830: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10831: my $match = 0;
1.412 raeburn 10832: my $secmatch = 0;
1.419 raeburn 10833: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10834: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10835: if ($section eq '') {
10836: $section = 'none';
10837: }
1.291 albertel 10838: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10839: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10840: $secmatch = 1;
10841: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10842: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10843: $secmatch = 1;
10844: }
10845: } else {
1.419 raeburn 10846: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10847: $secmatch = 1;
10848: }
1.290 albertel 10849: }
1.412 raeburn 10850: if (!$secmatch) {
10851: next;
10852: }
1.419 raeburn 10853: }
1.275 raeburn 10854: if (defined($$types{'active'})) {
1.288 raeburn 10855: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10856: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10857: $match = 1;
1.275 raeburn 10858: }
10859: }
10860: if (defined($$types{'previous'})) {
1.609 raeburn 10861: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10862: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10863: $match = 1;
1.275 raeburn 10864: }
10865: }
10866: if (defined($$types{'future'})) {
1.609 raeburn 10867: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10868: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10869: $match = 1;
1.275 raeburn 10870: }
10871: }
1.609 raeburn 10872: if ($match) {
10873: push(@{$seclists{$student}},$section);
10874: if (ref($userdata) eq 'HASH') {
10875: $$userdata{$student} = $$classlist{$student};
10876: }
10877: if (ref($statushash) eq 'HASH') {
10878: $statushash->{$student}{'st'}{$section} = $status;
10879: }
1.288 raeburn 10880: }
1.275 raeburn 10881: }
10882: }
1.412 raeburn 10883: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10884: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10885: my $now = time;
1.609 raeburn 10886: my %displaystatus = ( previous => 'Expired',
10887: active => 'Active',
10888: future => 'Future',
10889: );
1.1121 raeburn 10890: my (%nothide,@possdoms);
1.630 raeburn 10891: if ($hidepriv) {
10892: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10893: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10894: if ($user !~ /:/) {
10895: $nothide{join(':',split(/[\@]/,$user))}=1;
10896: } else {
10897: $nothide{$user} = 1;
10898: }
10899: }
1.1121 raeburn 10900: my @possdoms = ($cdom);
10901: if ($coursehash{'checkforpriv'}) {
10902: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10903: }
1.630 raeburn 10904: }
1.439 raeburn 10905: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10906: my $match = 0;
1.412 raeburn 10907: my $secmatch = 0;
1.439 raeburn 10908: my $status;
1.412 raeburn 10909: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10910: $user =~ s/:$//;
1.439 raeburn 10911: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10912: if ($end == -1 || $start == -1) {
10913: next;
10914: }
10915: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10916: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10917: my ($uname,$udom) = split(/:/,$user);
10918: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10919: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10920: $secmatch = 1;
10921: } elsif ($usec eq '') {
1.420 albertel 10922: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10923: $secmatch = 1;
10924: }
10925: } else {
10926: if (grep(/^\Q$usec\E$/,@{$sections})) {
10927: $secmatch = 1;
10928: }
10929: }
10930: if (!$secmatch) {
10931: next;
10932: }
1.288 raeburn 10933: }
1.419 raeburn 10934: if ($usec eq '') {
10935: $usec = 'none';
10936: }
1.275 raeburn 10937: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10938: if ($hidepriv) {
1.1121 raeburn 10939: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10940: (!$nothide{$uname.':'.$udom})) {
10941: next;
10942: }
10943: }
1.503 raeburn 10944: if ($end > 0 && $end < $now) {
1.439 raeburn 10945: $status = 'previous';
10946: } elsif ($start > $now) {
10947: $status = 'future';
10948: } else {
10949: $status = 'active';
10950: }
1.277 albertel 10951: foreach my $type (keys(%{$types})) {
1.275 raeburn 10952: if ($status eq $type) {
1.420 albertel 10953: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10954: push(@{$$users{$role}{$user}},$type);
10955: }
1.288 raeburn 10956: $match = 1;
10957: }
10958: }
1.419 raeburn 10959: if (($match) && (ref($userdata) eq 'HASH')) {
10960: if (!exists($$userdata{$uname.':'.$udom})) {
10961: &get_user_info($udom,$uname,\%idx,$userdata);
10962: }
1.420 albertel 10963: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10964: push(@{$seclists{$uname.':'.$udom}},$usec);
10965: }
1.609 raeburn 10966: if (ref($statushash) eq 'HASH') {
10967: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10968: }
1.275 raeburn 10969: }
10970: }
10971: }
10972: }
1.290 albertel 10973: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10974: if ((defined($cdom)) && (defined($cnum))) {
10975: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10976: if ( defined($csettings{'internal.courseowner'}) ) {
10977: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10978: next if ($owner eq '');
10979: my ($ownername,$ownerdom);
10980: if ($owner =~ /^([^:]+):([^:]+)$/) {
10981: $ownername = $1;
10982: $ownerdom = $2;
10983: } else {
10984: $ownername = $owner;
10985: $ownerdom = $cdom;
10986: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10987: }
10988: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10989: if (defined($userdata) &&
1.609 raeburn 10990: !exists($$userdata{$owner})) {
10991: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10992: if (!grep(/^none$/,@{$seclists{$owner}})) {
10993: push(@{$seclists{$owner}},'none');
10994: }
10995: if (ref($statushash) eq 'HASH') {
10996: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10997: }
1.290 albertel 10998: }
1.279 raeburn 10999: }
11000: }
11001: }
1.419 raeburn 11002: foreach my $user (keys(%seclists)) {
11003: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
11004: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
11005: }
1.275 raeburn 11006: }
11007: return;
11008: }
11009:
1.288 raeburn 11010: sub get_user_info {
11011: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 11012: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
11013: &plainname($uname,$udom,'lastname');
1.291 albertel 11014: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 11015: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 11016: my %idhash = &Apache::lonnet::idrget($udom,($uname));
11017: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 11018: return;
11019: }
1.275 raeburn 11020:
1.472 raeburn 11021: ###############################################
11022:
11023: =pod
11024:
11025: =item * &get_user_quota()
11026:
1.1134 raeburn 11027: Retrieves quota assigned for storage of user files.
11028: Default is to report quota for portfolio files.
1.472 raeburn 11029:
11030: Incoming parameters:
11031: 1. user's username
11032: 2. user's domain
1.1134 raeburn 11033: 3. quota name - portfolio, author, or course
1.1136 raeburn 11034: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 11035: 4. crstype - official, unofficial, textbook, placement or community,
11036: if quota name is course
1.472 raeburn 11037:
11038: Returns:
1.1163 raeburn 11039: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 11040: 2. (Optional) Type of setting: custom or default
11041: (individually assigned or default for user's
11042: institutional status).
11043: 3. (Optional) - User's institutional status (e.g., faculty, staff
11044: or student - types as defined in localenroll::inst_usertypes
11045: for user's domain, which determines default quota for user.
11046: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 11047:
11048: If a value has been stored in the user's environment,
1.536 raeburn 11049: it will return that, otherwise it returns the maximal default
1.1134 raeburn 11050: defined for the user's institutional status(es) in the domain.
1.472 raeburn 11051:
11052: =cut
11053:
11054: ###############################################
11055:
11056:
11057: sub get_user_quota {
1.1136 raeburn 11058: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 11059: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 11060: if (!defined($udom)) {
11061: $udom = $env{'user.domain'};
11062: }
11063: if (!defined($uname)) {
11064: $uname = $env{'user.name'};
11065: }
11066: if (($udom eq '' || $uname eq '') ||
11067: ($udom eq 'public') && ($uname eq 'public')) {
11068: $quota = 0;
1.536 raeburn 11069: $quotatype = 'default';
11070: $defquota = 0;
1.472 raeburn 11071: } else {
1.536 raeburn 11072: my $inststatus;
1.1134 raeburn 11073: if ($quotaname eq 'course') {
11074: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
11075: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
11076: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
11077: } else {
11078: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
11079: $quota = $cenv{'internal.uploadquota'};
11080: }
1.536 raeburn 11081: } else {
1.1134 raeburn 11082: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
11083: if ($quotaname eq 'author') {
11084: $quota = $env{'environment.authorquota'};
11085: } else {
11086: $quota = $env{'environment.portfolioquota'};
11087: }
11088: $inststatus = $env{'environment.inststatus'};
11089: } else {
11090: my %userenv =
11091: &Apache::lonnet::get('environment',['portfolioquota',
11092: 'authorquota','inststatus'],$udom,$uname);
11093: my ($tmp) = keys(%userenv);
11094: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
11095: if ($quotaname eq 'author') {
11096: $quota = $userenv{'authorquota'};
11097: } else {
11098: $quota = $userenv{'portfolioquota'};
11099: }
11100: $inststatus = $userenv{'inststatus'};
11101: } else {
11102: undef(%userenv);
11103: }
11104: }
11105: }
11106: if ($quota eq '' || wantarray) {
11107: if ($quotaname eq 'course') {
11108: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 11109: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 11110: ($crstype eq 'community') || ($crstype eq 'textbook') ||
11111: ($crstype eq 'placement')) {
1.1136 raeburn 11112: $defquota = $domdefs{$crstype.'quota'};
11113: }
11114: if ($defquota eq '') {
11115: $defquota = 500;
11116: }
1.1134 raeburn 11117: } else {
11118: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
11119: }
11120: if ($quota eq '') {
11121: $quota = $defquota;
11122: $quotatype = 'default';
11123: } else {
11124: $quotatype = 'custom';
11125: }
1.472 raeburn 11126: }
11127: }
1.536 raeburn 11128: if (wantarray) {
11129: return ($quota,$quotatype,$settingstatus,$defquota);
11130: } else {
11131: return $quota;
11132: }
1.472 raeburn 11133: }
11134:
11135: ###############################################
11136:
11137: =pod
11138:
11139: =item * &default_quota()
11140:
1.536 raeburn 11141: Retrieves default quota assigned for storage of user portfolio files,
11142: given an (optional) user's institutional status.
1.472 raeburn 11143:
11144: Incoming parameters:
1.1142 raeburn 11145:
1.472 raeburn 11146: 1. domain
1.536 raeburn 11147: 2. (Optional) institutional status(es). This is a : separated list of
11148: status types (e.g., faculty, staff, student etc.)
11149: which apply to the user for whom the default is being retrieved.
11150: If the institutional status string in undefined, the domain
1.1134 raeburn 11151: default quota will be returned.
11152: 3. quota name - portfolio, author, or course
11153: (if no quota name provided, defaults to portfolio).
1.472 raeburn 11154:
11155: Returns:
1.1142 raeburn 11156:
1.1163 raeburn 11157: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 11158: 2. (Optional) institutional type which determined the value of the
11159: default quota.
1.472 raeburn 11160:
11161: If a value has been stored in the domain's configuration db,
11162: it will return that, otherwise it returns 20 (for backwards
11163: compatibility with domains which have not set up a configuration
1.1163 raeburn 11164: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 11165:
1.536 raeburn 11166: If the user's status includes multiple types (e.g., staff and student),
11167: the largest default quota which applies to the user determines the
11168: default quota returned.
11169:
1.472 raeburn 11170: =cut
11171:
11172: ###############################################
11173:
11174:
11175: sub default_quota {
1.1134 raeburn 11176: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 11177: my ($defquota,$settingstatus);
11178: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 11179: ['quotas'],$udom);
1.1134 raeburn 11180: my $key = 'defaultquota';
11181: if ($quotaname eq 'author') {
11182: $key = 'authorquota';
11183: }
1.622 raeburn 11184: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 11185: if ($inststatus ne '') {
1.765 raeburn 11186: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 11187: foreach my $item (@statuses) {
1.1134 raeburn 11188: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11189: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 11190: if ($defquota eq '') {
1.1134 raeburn 11191: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11192: $settingstatus = $item;
1.1134 raeburn 11193: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
11194: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11195: $settingstatus = $item;
11196: }
11197: }
1.1134 raeburn 11198: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11199: if ($quotahash{'quotas'}{$item} ne '') {
11200: if ($defquota eq '') {
11201: $defquota = $quotahash{'quotas'}{$item};
11202: $settingstatus = $item;
11203: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
11204: $defquota = $quotahash{'quotas'}{$item};
11205: $settingstatus = $item;
11206: }
1.536 raeburn 11207: }
11208: }
11209: }
11210: }
11211: if ($defquota eq '') {
1.1134 raeburn 11212: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11213: $defquota = $quotahash{'quotas'}{$key}{'default'};
11214: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11215: $defquota = $quotahash{'quotas'}{'default'};
11216: }
1.536 raeburn 11217: $settingstatus = 'default';
1.1139 raeburn 11218: if ($defquota eq '') {
11219: if ($quotaname eq 'author') {
11220: $defquota = 500;
11221: }
11222: }
1.536 raeburn 11223: }
11224: } else {
11225: $settingstatus = 'default';
1.1134 raeburn 11226: if ($quotaname eq 'author') {
11227: $defquota = 500;
11228: } else {
11229: $defquota = 20;
11230: }
1.536 raeburn 11231: }
11232: if (wantarray) {
11233: return ($defquota,$settingstatus);
1.472 raeburn 11234: } else {
1.536 raeburn 11235: return $defquota;
1.472 raeburn 11236: }
11237: }
11238:
1.1135 raeburn 11239: ###############################################
11240:
11241: =pod
11242:
1.1136 raeburn 11243: =item * &excess_filesize_warning()
1.1135 raeburn 11244:
11245: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 11246: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 11247: space to be exceeded.
1.1136 raeburn 11248:
11249: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 11250: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 11251:
1.1165 raeburn 11252: Inputs: 7
1.1136 raeburn 11253: 1. username or coursenum
1.1135 raeburn 11254: 2. domain
1.1136 raeburn 11255: 3. context ('author' or 'course')
1.1135 raeburn 11256: 4. filename of file for which action is being requested
11257: 5. filesize (kB) of file
11258: 6. action being taken: copy or upload.
1.1237 raeburn 11259: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 11260:
11261: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 11262: otherwise return null.
11263:
11264: =back
1.1135 raeburn 11265:
11266: =cut
11267:
1.1136 raeburn 11268: sub excess_filesize_warning {
1.1165 raeburn 11269: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 11270: my $current_disk_usage = 0;
1.1165 raeburn 11271: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 11272: if ($context eq 'author') {
11273: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
11274: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
11275: } else {
11276: foreach my $subdir ('docs','supplemental') {
11277: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
11278: }
11279: }
1.1135 raeburn 11280: $disk_quota = int($disk_quota * 1000);
11281: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 11282: return '<p class="LC_warning">'.
1.1135 raeburn 11283: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 11284: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
11285: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 11286: $disk_quota,$current_disk_usage).
11287: '</p>';
11288: }
11289: return;
11290: }
11291:
11292: ###############################################
11293:
11294:
1.1136 raeburn 11295:
11296:
1.384 raeburn 11297: sub get_secgrprole_info {
11298: my ($cdom,$cnum,$needroles,$type) = @_;
11299: my %sections_count = &get_sections($cdom,$cnum);
11300: my @sections = (sort {$a <=> $b} keys(%sections_count));
11301: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
11302: my @groups = sort(keys(%curr_groups));
11303: my $allroles = [];
11304: my $rolehash;
11305: my $accesshash = {
11306: active => 'Currently has access',
11307: future => 'Will have future access',
11308: previous => 'Previously had access',
11309: };
11310: if ($needroles) {
11311: $rolehash = {'all' => 'all'};
1.385 albertel 11312: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11313: if (&Apache::lonnet::error(%user_roles)) {
11314: undef(%user_roles);
11315: }
11316: foreach my $item (keys(%user_roles)) {
1.384 raeburn 11317: my ($role)=split(/\:/,$item,2);
11318: if ($role eq 'cr') { next; }
11319: if ($role =~ /^cr/) {
11320: $$rolehash{$role} = (split('/',$role))[3];
11321: } else {
11322: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
11323: }
11324: }
11325: foreach my $key (sort(keys(%{$rolehash}))) {
11326: push(@{$allroles},$key);
11327: }
11328: push (@{$allroles},'st');
11329: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
11330: }
11331: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
11332: }
11333:
1.555 raeburn 11334: sub user_picker {
1.1279 raeburn 11335: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 11336: my $currdom = $dom;
1.1253 raeburn 11337: my @alldoms = &Apache::lonnet::all_domains();
11338: if (@alldoms == 1) {
11339: my %domsrch = &Apache::lonnet::get_dom('configuration',
11340: ['directorysrch'],$alldoms[0]);
11341: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
11342: my $showdom = $domdesc;
11343: if ($showdom eq '') {
11344: $showdom = $dom;
11345: }
11346: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
11347: if ((!$domsrch{'directorysrch'}{'available'}) &&
11348: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
11349: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
11350: }
11351: }
11352: }
1.555 raeburn 11353: my %curr_selected = (
11354: srchin => 'dom',
1.580 raeburn 11355: srchby => 'lastname',
1.555 raeburn 11356: );
11357: my $srchterm;
1.625 raeburn 11358: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 11359: if ($srch->{'srchby'} ne '') {
11360: $curr_selected{'srchby'} = $srch->{'srchby'};
11361: }
11362: if ($srch->{'srchin'} ne '') {
11363: $curr_selected{'srchin'} = $srch->{'srchin'};
11364: }
11365: if ($srch->{'srchtype'} ne '') {
11366: $curr_selected{'srchtype'} = $srch->{'srchtype'};
11367: }
11368: if ($srch->{'srchdomain'} ne '') {
11369: $currdom = $srch->{'srchdomain'};
11370: }
11371: $srchterm = $srch->{'srchterm'};
11372: }
1.1222 damieng 11373: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 11374: 'usr' => 'Search criteria',
1.563 raeburn 11375: 'doma' => 'Domain/institution to search',
1.558 albertel 11376: 'uname' => 'username',
11377: 'lastname' => 'last name',
1.555 raeburn 11378: 'lastfirst' => 'last name, first name',
1.558 albertel 11379: 'crs' => 'in this course',
1.576 raeburn 11380: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 11381: 'alc' => 'all LON-CAPA',
1.573 raeburn 11382: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 11383: 'exact' => 'is',
11384: 'contains' => 'contains',
1.569 raeburn 11385: 'begins' => 'begins with',
1.1222 damieng 11386: );
11387: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 11388: 'youm' => "You must include some text to search for.",
11389: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
11390: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
11391: 'yomc' => "You must choose a domain when using an institutional directory search.",
11392: 'ymcd' => "You must choose a domain when using a domain search.",
11393: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
11394: 'whse' => "When searching by last,first you must include at least one character in the first name.",
11395: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 11396: );
1.1222 damieng 11397: &html_escape(\%html_lt);
11398: &js_escape(\%js_lt);
1.1255 raeburn 11399: my $domform;
1.1277 raeburn 11400: my $allow_blank = 1;
1.1255 raeburn 11401: if ($fixeddom) {
1.1277 raeburn 11402: $allow_blank = 0;
11403: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 11404: } else {
1.1287 raeburn 11405: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 11406: my ($trusted,$untrusted);
1.1287 raeburn 11407: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 11408: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 11409: } elsif ($context eq 'author') {
1.1288 raeburn 11410: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 11411: } elsif ($context eq 'domain') {
1.1288 raeburn 11412: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 11413: }
1.1288 raeburn 11414: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 11415: }
1.563 raeburn 11416: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 11417:
11418: my @srchins = ('crs','dom','alc','instd');
11419:
11420: foreach my $option (@srchins) {
11421: # FIXME 'alc' option unavailable until
11422: # loncreateuser::print_user_query_page()
11423: # has been completed.
11424: next if ($option eq 'alc');
1.880 raeburn 11425: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 11426: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 11427: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 11428: if ($curr_selected{'srchin'} eq $option) {
11429: $srchinsel .= '
1.1222 damieng 11430: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 11431: } else {
11432: $srchinsel .= '
1.1222 damieng 11433: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 11434: }
1.555 raeburn 11435: }
1.563 raeburn 11436: $srchinsel .= "\n </select>\n";
1.555 raeburn 11437:
11438: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 11439: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 11440: if ($curr_selected{'srchby'} eq $option) {
11441: $srchbysel .= '
1.1222 damieng 11442: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11443: } else {
11444: $srchbysel .= '
1.1222 damieng 11445: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11446: }
11447: }
11448: $srchbysel .= "\n </select>\n";
11449:
11450: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 11451: foreach my $option ('begins','contains','exact') {
1.555 raeburn 11452: if ($curr_selected{'srchtype'} eq $option) {
11453: $srchtypesel .= '
1.1222 damieng 11454: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11455: } else {
11456: $srchtypesel .= '
1.1222 damieng 11457: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11458: }
11459: }
11460: $srchtypesel .= "\n </select>\n";
11461:
1.558 albertel 11462: my ($newuserscript,$new_user_create);
1.994 raeburn 11463: my $context_dom = $env{'request.role.domain'};
11464: if ($context eq 'requestcrs') {
11465: if ($env{'form.coursedom'} ne '') {
11466: $context_dom = $env{'form.coursedom'};
11467: }
11468: }
1.556 raeburn 11469: if ($forcenewuser) {
1.576 raeburn 11470: if (ref($srch) eq 'HASH') {
1.994 raeburn 11471: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 11472: if ($cancreate) {
11473: $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>';
11474: } else {
1.799 bisitz 11475: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 11476: my %usertypetext = (
11477: official => 'institutional',
11478: unofficial => 'non-institutional',
11479: );
1.799 bisitz 11480: $new_user_create = '<p class="LC_warning">'
11481: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
11482: .' '
11483: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
11484: ,'<a href="'.$helplink.'">','</a>')
11485: .'</p><br />';
1.627 raeburn 11486: }
1.576 raeburn 11487: }
11488: }
11489:
1.556 raeburn 11490: $newuserscript = <<"ENDSCRIPT";
11491:
1.570 raeburn 11492: function setSearch(createnew,callingForm) {
1.556 raeburn 11493: if (createnew == 1) {
1.570 raeburn 11494: for (var i=0; i<callingForm.srchby.length; i++) {
11495: if (callingForm.srchby.options[i].value == 'uname') {
11496: callingForm.srchby.selectedIndex = i;
1.556 raeburn 11497: }
11498: }
1.570 raeburn 11499: for (var i=0; i<callingForm.srchin.length; i++) {
11500: if ( callingForm.srchin.options[i].value == 'dom') {
11501: callingForm.srchin.selectedIndex = i;
1.556 raeburn 11502: }
11503: }
1.570 raeburn 11504: for (var i=0; i<callingForm.srchtype.length; i++) {
11505: if (callingForm.srchtype.options[i].value == 'exact') {
11506: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 11507: }
11508: }
1.570 raeburn 11509: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 11510: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 11511: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 11512: }
11513: }
11514: }
11515: }
11516: ENDSCRIPT
1.558 albertel 11517:
1.556 raeburn 11518: }
11519:
1.555 raeburn 11520: my $output = <<"END_BLOCK";
1.556 raeburn 11521: <script type="text/javascript">
1.824 bisitz 11522: // <![CDATA[
1.570 raeburn 11523: function validateEntry(callingForm) {
1.558 albertel 11524:
1.556 raeburn 11525: var checkok = 1;
1.558 albertel 11526: var srchin;
1.570 raeburn 11527: for (var i=0; i<callingForm.srchin.length; i++) {
11528: if ( callingForm.srchin[i].checked ) {
11529: srchin = callingForm.srchin[i].value;
1.558 albertel 11530: }
11531: }
11532:
1.570 raeburn 11533: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
11534: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
11535: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
11536: var srchterm = callingForm.srchterm.value;
11537: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 11538: var msg = "";
11539:
11540: if (srchterm == "") {
11541: checkok = 0;
1.1222 damieng 11542: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 11543: }
11544:
1.569 raeburn 11545: if (srchtype== 'begins') {
11546: if (srchterm.length < 2) {
11547: checkok = 0;
1.1222 damieng 11548: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 11549: }
11550: }
11551:
1.556 raeburn 11552: if (srchtype== 'contains') {
11553: if (srchterm.length < 3) {
11554: checkok = 0;
1.1222 damieng 11555: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 11556: }
11557: }
11558: if (srchin == 'instd') {
11559: if (srchdomain == '') {
11560: checkok = 0;
1.1222 damieng 11561: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 11562: }
11563: }
11564: if (srchin == 'dom') {
11565: if (srchdomain == '') {
11566: checkok = 0;
1.1222 damieng 11567: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 11568: }
11569: }
11570: if (srchby == 'lastfirst') {
11571: if (srchterm.indexOf(",") == -1) {
11572: checkok = 0;
1.1222 damieng 11573: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 11574: }
11575: if (srchterm.indexOf(",") == srchterm.length -1) {
11576: checkok = 0;
1.1222 damieng 11577: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 11578: }
11579: }
11580: if (checkok == 0) {
1.1222 damieng 11581: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 11582: return;
11583: }
11584: if (checkok == 1) {
1.570 raeburn 11585: callingForm.submit();
1.556 raeburn 11586: }
11587: }
11588:
11589: $newuserscript
11590:
1.824 bisitz 11591: // ]]>
1.556 raeburn 11592: </script>
1.558 albertel 11593:
11594: $new_user_create
11595:
1.555 raeburn 11596: END_BLOCK
1.558 albertel 11597:
1.876 raeburn 11598: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 11599: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 11600: $domform.
11601: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 11602: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 11603: $srchbysel.
11604: $srchtypesel.
11605: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
11606: $srchinsel.
11607: &Apache::lonhtmlcommon::row_closure(1).
11608: &Apache::lonhtmlcommon::end_pick_box().
11609: '<br />';
1.1253 raeburn 11610: return ($output,1);
1.555 raeburn 11611: }
11612:
1.612 raeburn 11613: sub user_rule_check {
1.615 raeburn 11614: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 11615: my ($response,%inst_response);
1.612 raeburn 11616: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 11617: if (keys(%{$usershash}) > 1) {
11618: my (%by_username,%by_id,%userdoms);
11619: my $checkid;
11620: if (ref($checks) eq 'HASH') {
11621: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
11622: $checkid = 1;
11623: }
11624: }
11625: foreach my $user (keys(%{$usershash})) {
11626: my ($uname,$udom) = split(/:/,$user);
11627: if ($checkid) {
11628: if (ref($usershash->{$user}) eq 'HASH') {
11629: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 11630: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 11631: $userdoms{$udom} = 1;
1.1227 raeburn 11632: if (ref($inst_results) eq 'HASH') {
11633: $inst_results->{$uname.':'.$udom} = {};
11634: }
1.1226 raeburn 11635: }
11636: }
11637: } else {
11638: $by_username{$udom}{$uname} = 1;
11639: $userdoms{$udom} = 1;
1.1227 raeburn 11640: if (ref($inst_results) eq 'HASH') {
11641: $inst_results->{$uname.':'.$udom} = {};
11642: }
1.1226 raeburn 11643: }
11644: }
11645: foreach my $udom (keys(%userdoms)) {
11646: if (!$got_rules->{$udom}) {
11647: my %domconfig = &Apache::lonnet::get_dom('configuration',
11648: ['usercreation'],$udom);
11649: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11650: foreach my $item ('username','id') {
11651: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 11652: $$curr_rules{$udom}{$item} =
11653: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 11654: }
11655: }
11656: }
11657: $got_rules->{$udom} = 1;
11658: }
1.612 raeburn 11659: }
1.1226 raeburn 11660: if ($checkid) {
11661: foreach my $udom (keys(%by_id)) {
11662: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11663: if ($outcome eq 'ok') {
1.1227 raeburn 11664: foreach my $id (keys(%{$by_id{$udom}})) {
11665: my $uname = $by_id{$udom}{$id};
11666: $inst_response{$uname.':'.$udom} = $outcome;
11667: }
1.1226 raeburn 11668: if (ref($results) eq 'HASH') {
11669: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 11670: if (exists($inst_response{$uname.':'.$udom})) {
11671: $inst_response{$uname.':'.$udom} = $outcome;
11672: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11673: }
1.1226 raeburn 11674: }
11675: }
11676: }
1.612 raeburn 11677: }
1.615 raeburn 11678: } else {
1.1226 raeburn 11679: foreach my $udom (keys(%by_username)) {
11680: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11681: if ($outcome eq 'ok') {
1.1227 raeburn 11682: foreach my $uname (keys(%{$by_username{$udom}})) {
11683: $inst_response{$uname.':'.$udom} = $outcome;
11684: }
1.1226 raeburn 11685: if (ref($results) eq 'HASH') {
11686: foreach my $uname (keys(%{$results})) {
11687: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11688: }
11689: }
11690: }
11691: }
1.612 raeburn 11692: }
1.1226 raeburn 11693: } elsif (keys(%{$usershash}) == 1) {
11694: my $user = (keys(%{$usershash}))[0];
11695: my ($uname,$udom) = split(/:/,$user);
11696: if (($udom ne '') && ($uname ne '')) {
11697: if (ref($usershash->{$user}) eq 'HASH') {
11698: if (ref($checks) eq 'HASH') {
11699: if (defined($checks->{'username'})) {
11700: ($inst_response{$user},%{$inst_results->{$user}}) =
11701: &Apache::lonnet::get_instuser($udom,$uname);
11702: } elsif (defined($checks->{'id'})) {
11703: if ($usershash->{$user}->{'id'} ne '') {
11704: ($inst_response{$user},%{$inst_results->{$user}}) =
11705: &Apache::lonnet::get_instuser($udom,undef,
11706: $usershash->{$user}->{'id'});
11707: } else {
11708: ($inst_response{$user},%{$inst_results->{$user}}) =
11709: &Apache::lonnet::get_instuser($udom,$uname);
11710: }
1.585 raeburn 11711: }
1.1226 raeburn 11712: } else {
11713: ($inst_response{$user},%{$inst_results->{$user}}) =
11714: &Apache::lonnet::get_instuser($udom,$uname);
11715: return;
11716: }
11717: if (!$got_rules->{$udom}) {
11718: my %domconfig = &Apache::lonnet::get_dom('configuration',
11719: ['usercreation'],$udom);
11720: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11721: foreach my $item ('username','id') {
11722: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11723: $$curr_rules{$udom}{$item} =
11724: $domconfig{'usercreation'}{$item.'_rule'};
11725: }
11726: }
11727: }
11728: $got_rules->{$udom} = 1;
1.585 raeburn 11729: }
11730: }
1.1226 raeburn 11731: } else {
11732: return;
11733: }
11734: } else {
11735: return;
11736: }
11737: foreach my $user (keys(%{$usershash})) {
11738: my ($uname,$udom) = split(/:/,$user);
11739: next if (($udom eq '') || ($uname eq ''));
11740: my $id;
1.1227 raeburn 11741: if (ref($inst_results) eq 'HASH') {
11742: if (ref($inst_results->{$user}) eq 'HASH') {
11743: $id = $inst_results->{$user}->{'id'};
11744: }
11745: }
11746: if ($id eq '') {
11747: if (ref($usershash->{$user})) {
11748: $id = $usershash->{$user}->{'id'};
11749: }
1.585 raeburn 11750: }
1.612 raeburn 11751: foreach my $item (keys(%{$checks})) {
11752: if (ref($$curr_rules{$udom}) eq 'HASH') {
11753: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11754: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 11755: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11756: $$curr_rules{$udom}{$item});
1.612 raeburn 11757: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11758: if ($rule_check{$rule}) {
11759: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 11760: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11761: if (ref($inst_results) eq 'HASH') {
11762: if (ref($inst_results->{$user}) eq 'HASH') {
11763: if (keys(%{$inst_results->{$user}}) == 0) {
11764: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 11765: } elsif ($item eq 'id') {
11766: if ($inst_results->{$user}->{'id'} eq '') {
11767: $$alerts{$item}{$udom}{$uname} = 1;
11768: }
1.615 raeburn 11769: }
1.612 raeburn 11770: }
11771: }
1.615 raeburn 11772: }
11773: last;
1.585 raeburn 11774: }
11775: }
11776: }
11777: }
11778: }
11779: }
11780: }
11781: }
1.612 raeburn 11782: return;
11783: }
11784:
11785: sub user_rule_formats {
11786: my ($domain,$domdesc,$curr_rules,$check) = @_;
11787: my %text = (
11788: 'username' => 'Usernames',
11789: 'id' => 'IDs',
11790: );
11791: my $output;
11792: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11793: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11794: if (@{$ruleorder} > 0) {
1.1102 raeburn 11795: $output = '<br />'.
11796: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11797: '<span class="LC_cusr_emph">','</span>',$domdesc).
11798: ' <ul>';
1.612 raeburn 11799: foreach my $rule (@{$ruleorder}) {
11800: if (ref($curr_rules) eq 'ARRAY') {
11801: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11802: if (ref($rules->{$rule}) eq 'HASH') {
11803: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11804: $rules->{$rule}{'desc'}.'</li>';
11805: }
11806: }
11807: }
11808: }
11809: $output .= '</ul>';
11810: }
11811: }
11812: return $output;
11813: }
11814:
11815: sub instrule_disallow_msg {
1.615 raeburn 11816: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11817: my $response;
11818: my %text = (
11819: item => 'username',
11820: items => 'usernames',
11821: match => 'matches',
11822: do => 'does',
11823: action => 'a username',
11824: one => 'one',
11825: );
11826: if ($count > 1) {
11827: $text{'item'} = 'usernames';
11828: $text{'match'} ='match';
11829: $text{'do'} = 'do';
11830: $text{'action'} = 'usernames',
11831: $text{'one'} = 'ones';
11832: }
11833: if ($checkitem eq 'id') {
11834: $text{'items'} = 'IDs';
11835: $text{'item'} = 'ID';
11836: $text{'action'} = 'an ID';
1.615 raeburn 11837: if ($count > 1) {
11838: $text{'item'} = 'IDs';
11839: $text{'action'} = 'IDs';
11840: }
1.612 raeburn 11841: }
1.674 bisitz 11842: $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 11843: if ($mode eq 'upload') {
11844: if ($checkitem eq 'username') {
11845: $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'}.");
11846: } elsif ($checkitem eq 'id') {
1.674 bisitz 11847: $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 11848: }
1.669 raeburn 11849: } elsif ($mode eq 'selfcreate') {
11850: if ($checkitem eq 'id') {
11851: $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.");
11852: }
1.615 raeburn 11853: } else {
11854: if ($checkitem eq 'username') {
11855: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11856: } elsif ($checkitem eq 'id') {
11857: $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.");
11858: }
1.612 raeburn 11859: }
11860: return $response;
1.585 raeburn 11861: }
11862:
1.624 raeburn 11863: sub personal_data_fieldtitles {
11864: my %fieldtitles = &Apache::lonlocal::texthash (
11865: id => 'Student/Employee ID',
11866: permanentemail => 'E-mail address',
11867: lastname => 'Last Name',
11868: firstname => 'First Name',
11869: middlename => 'Middle Name',
11870: generation => 'Generation',
11871: gen => 'Generation',
1.765 raeburn 11872: inststatus => 'Affiliation',
1.624 raeburn 11873: );
11874: return %fieldtitles;
11875: }
11876:
1.642 raeburn 11877: sub sorted_inst_types {
11878: my ($dom) = @_;
1.1185 raeburn 11879: my ($usertypes,$order);
11880: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11881: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11882: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11883: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11884: } else {
11885: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11886: }
1.642 raeburn 11887: my $othertitle = &mt('All users');
11888: if ($env{'request.course.id'}) {
1.668 raeburn 11889: $othertitle = &mt('Any users');
1.642 raeburn 11890: }
11891: my @types;
11892: if (ref($order) eq 'ARRAY') {
11893: @types = @{$order};
11894: }
11895: if (@types == 0) {
11896: if (ref($usertypes) eq 'HASH') {
11897: @types = sort(keys(%{$usertypes}));
11898: }
11899: }
11900: if (keys(%{$usertypes}) > 0) {
11901: $othertitle = &mt('Other users');
11902: }
11903: return ($othertitle,$usertypes,\@types);
11904: }
11905:
1.645 raeburn 11906: sub get_institutional_codes {
1.1361 raeburn 11907: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11908: # Get complete list of course sections to update
11909: my @currsections = ();
11910: my @currxlists = ();
1.1361 raeburn 11911: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11912: my $coursecode = $$settings{'internal.coursecode'};
1.1361 raeburn 11913: my $crskey = $crs.':'.$coursecode;
11914: @{$unclutteredsec{$crskey}} = ();
11915: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11916:
11917: if ($$settings{'internal.sectionnums'} ne '') {
11918: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11919: }
11920:
11921: if ($$settings{'internal.crosslistings'} ne '') {
11922: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11923: }
11924:
11925: if (@currxlists > 0) {
1.1361 raeburn 11926: foreach my $xl (@currxlists) {
11927: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11928: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 11929: push(@{$allcourses},$1);
1.645 raeburn 11930: $$LC_code{$1} = $2;
11931: }
11932: }
11933: }
11934: }
1.1361 raeburn 11935:
1.645 raeburn 11936: if (@currsections > 0) {
1.1361 raeburn 11937: foreach my $sec (@currsections) {
11938: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11939: my $instsec = $1;
1.645 raeburn 11940: my $lc_sec = $2;
1.1361 raeburn 11941: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11942: push(@{$unclutteredsec{$crskey}},$instsec);
11943: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11944: }
11945: }
11946: }
11947: }
11948:
11949: if (@{$unclutteredsec{$crskey}} > 0) {
11950: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11951: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11952: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11953: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11954: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1263 raeburn 11955: push(@{$allcourses},$sec);
1.1361 raeburn 11956: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11957: }
11958: }
11959: }
11960: }
11961: return;
11962: }
11963:
1.971 raeburn 11964: sub get_standard_codeitems {
11965: return ('Year','Semester','Department','Number','Section');
11966: }
11967:
1.112 bowersj2 11968: =pod
11969:
1.780 raeburn 11970: =head1 Slot Helpers
11971:
11972: =over 4
11973:
11974: =item * sorted_slots()
11975:
1.1040 raeburn 11976: Sorts an array of slot names in order of an optional sort key,
11977: default sort is by slot start time (earliest first).
1.780 raeburn 11978:
11979: Inputs:
11980:
11981: =over 4
11982:
11983: slotsarr - Reference to array of unsorted slot names.
11984:
11985: slots - Reference to hash of hash, where outer hash keys are slot names.
11986:
1.1040 raeburn 11987: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11988:
1.549 albertel 11989: =back
11990:
1.780 raeburn 11991: Returns:
11992:
11993: =over 4
11994:
1.1040 raeburn 11995: sorted - An array of slot names sorted by a specified sort key
11996: (default sort key is start time of the slot).
1.780 raeburn 11997:
11998: =back
11999:
12000: =cut
12001:
12002:
12003: sub sorted_slots {
1.1040 raeburn 12004: my ($slotsarr,$slots,$sortkey) = @_;
12005: if ($sortkey eq '') {
12006: $sortkey = 'starttime';
12007: }
1.780 raeburn 12008: my @sorted;
12009: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
12010: @sorted =
12011: sort {
12012: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 12013: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 12014: }
12015: if (ref($slots->{$a})) { return -1;}
12016: if (ref($slots->{$b})) { return 1;}
12017: return 0;
12018: } @{$slotsarr};
12019: }
12020: return @sorted;
12021: }
12022:
1.1040 raeburn 12023: =pod
12024:
12025: =item * get_future_slots()
12026:
12027: Inputs:
12028:
12029: =over 4
12030:
12031: cnum - course number
12032:
12033: cdom - course domain
12034:
12035: now - current UNIX time
12036:
12037: symb - optional symb
12038:
12039: =back
12040:
12041: Returns:
12042:
12043: =over 4
12044:
12045: sorted_reservable - ref to array of student_schedulable slots currently
12046: reservable, ordered by end date of reservation period.
12047:
12048: reservable_now - ref to hash of student_schedulable slots currently
12049: reservable.
12050:
12051: Keys in inner hash are:
12052: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 12053: (b) endreserve: end date of reservation period.
12054: (c) uniqueperiod: start,end dates when slot is to be uniquely
12055: selected.
1.1040 raeburn 12056:
12057: sorted_future - ref to array of student_schedulable slots reservable in
12058: the future, ordered by start date of reservation period.
12059:
12060: future_reservable - ref to hash of student_schedulable slots reservable
12061: in the future.
12062:
12063: Keys in inner hash are:
12064: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 12065: (b) startreserve: start date of reservation period.
12066: (c) uniqueperiod: start,end dates when slot is to be uniquely
12067: selected.
1.1040 raeburn 12068:
12069: =back
12070:
12071: =cut
12072:
12073: sub get_future_slots {
12074: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 12075: my $map;
12076: if ($symb) {
12077: ($map) = &Apache::lonnet::decode_symb($symb);
12078: }
1.1040 raeburn 12079: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
12080: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
12081: foreach my $slot (keys(%slots)) {
12082: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
12083: if ($symb) {
1.1229 raeburn 12084: if ($slots{$slot}->{'symb'} ne '') {
12085: my $canuse;
12086: my %oksymbs;
12087: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
12088: map { $oksymbs{$_} = 1; } @slotsymbs;
12089: if ($oksymbs{$symb}) {
12090: $canuse = 1;
12091: } else {
12092: foreach my $item (@slotsymbs) {
12093: if ($item =~ /\.(page|sequence)$/) {
12094: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
12095: if (($map ne '') && ($map eq $sloturl)) {
12096: $canuse = 1;
12097: last;
12098: }
12099: }
12100: }
12101: }
12102: next unless ($canuse);
12103: }
1.1040 raeburn 12104: }
12105: if (($slots{$slot}->{'starttime'} > $now) &&
12106: ($slots{$slot}->{'endtime'} > $now)) {
12107: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
12108: my $userallowed = 0;
12109: if ($slots{$slot}->{'allowedsections'}) {
12110: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
12111: if (!defined($env{'request.role.sec'})
12112: && grep(/^No section assigned$/,@allowed_sec)) {
12113: $userallowed=1;
12114: } else {
12115: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
12116: $userallowed=1;
12117: }
12118: }
12119: unless ($userallowed) {
12120: if (defined($env{'request.course.groups'})) {
12121: my @groups = split(/:/,$env{'request.course.groups'});
12122: foreach my $group (@groups) {
12123: if (grep(/^\Q$group\E$/,@allowed_sec)) {
12124: $userallowed=1;
12125: last;
12126: }
12127: }
12128: }
12129: }
12130: }
12131: if ($slots{$slot}->{'allowedusers'}) {
12132: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
12133: my $user = $env{'user.name'}.':'.$env{'user.domain'};
12134: if (grep(/^\Q$user\E$/,@allowed_users)) {
12135: $userallowed = 1;
12136: }
12137: }
12138: next unless($userallowed);
12139: }
12140: my $startreserve = $slots{$slot}->{'startreserve'};
12141: my $endreserve = $slots{$slot}->{'endreserve'};
12142: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 12143: my $uniqueperiod;
12144: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
12145: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
12146: }
1.1040 raeburn 12147: if (($startreserve < $now) &&
12148: (!$endreserve || $endreserve > $now)) {
12149: my $lastres = $endreserve;
12150: if (!$lastres) {
12151: $lastres = $slots{$slot}->{'starttime'};
12152: }
12153: $reservable_now{$slot} = {
12154: symb => $symb,
1.1250 raeburn 12155: endreserve => $lastres,
12156: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12157: };
12158: } elsif (($startreserve > $now) &&
12159: (!$endreserve || $endreserve > $startreserve)) {
12160: $future_reservable{$slot} = {
12161: symb => $symb,
1.1250 raeburn 12162: startreserve => $startreserve,
12163: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12164: };
12165: }
12166: }
12167: }
12168: my @unsorted_reservable = keys(%reservable_now);
12169: if (@unsorted_reservable > 0) {
12170: @sorted_reservable =
12171: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
12172: }
12173: my @unsorted_future = keys(%future_reservable);
12174: if (@unsorted_future > 0) {
12175: @sorted_future =
12176: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
12177: }
12178: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
12179: }
1.780 raeburn 12180:
12181: =pod
12182:
1.1057 foxr 12183: =back
12184:
1.549 albertel 12185: =head1 HTTP Helpers
12186:
12187: =over 4
12188:
1.648 raeburn 12189: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 12190:
1.258 albertel 12191: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 12192: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 12193: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 12194:
12195: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
12196: $possible_names is an ref to an array of form element names. As an example:
12197: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 12198: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 12199:
12200: =cut
1.1 albertel 12201:
1.6 albertel 12202: sub get_unprocessed_cgi {
1.25 albertel 12203: my ($query,$possible_names)= @_;
1.26 matthew 12204: # $Apache::lonxml::debug=1;
1.356 albertel 12205: foreach my $pair (split(/&/,$query)) {
12206: my ($name, $value) = split(/=/,$pair);
1.369 www 12207: $name = &unescape($name);
1.25 albertel 12208: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
12209: $value =~ tr/+/ /;
12210: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 12211: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 12212: }
1.16 harris41 12213: }
1.6 albertel 12214: }
12215:
1.112 bowersj2 12216: =pod
12217:
1.648 raeburn 12218: =item * &cacheheader()
1.112 bowersj2 12219:
12220: returns cache-controlling header code
12221:
12222: =cut
12223:
1.7 albertel 12224: sub cacheheader {
1.258 albertel 12225: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 12226: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
12227: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 12228: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
12229: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 12230: return $output;
1.7 albertel 12231: }
12232:
1.112 bowersj2 12233: =pod
12234:
1.648 raeburn 12235: =item * &no_cache($r)
1.112 bowersj2 12236:
12237: specifies header code to not have cache
12238:
12239: =cut
12240:
1.9 albertel 12241: sub no_cache {
1.216 albertel 12242: my ($r) = @_;
12243: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 12244: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 12245: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
12246: $r->no_cache(1);
12247: $r->header_out("Expires" => $date);
12248: $r->header_out("Pragma" => "no-cache");
1.123 www 12249: }
12250:
12251: sub content_type {
1.181 albertel 12252: my ($r,$type,$charset) = @_;
1.299 foxr 12253: if ($r) {
12254: # Note that printout.pl calls this with undef for $r.
12255: &no_cache($r);
12256: }
1.258 albertel 12257: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 12258: unless ($charset) {
12259: $charset=&Apache::lonlocal::current_encoding;
12260: }
12261: if ($charset) { $type.='; charset='.$charset; }
12262: if ($r) {
12263: $r->content_type($type);
12264: } else {
12265: print("Content-type: $type\n\n");
12266: }
1.9 albertel 12267: }
1.25 albertel 12268:
1.112 bowersj2 12269: =pod
12270:
1.648 raeburn 12271: =item * &add_to_env($name,$value)
1.112 bowersj2 12272:
1.258 albertel 12273: adds $name to the %env hash with value
1.112 bowersj2 12274: $value, if $name already exists, the entry is converted to an array
12275: reference and $value is added to the array.
12276:
12277: =cut
12278:
1.25 albertel 12279: sub add_to_env {
12280: my ($name,$value)=@_;
1.258 albertel 12281: if (defined($env{$name})) {
12282: if (ref($env{$name})) {
1.25 albertel 12283: #already have multiple values
1.258 albertel 12284: push(@{ $env{$name} },$value);
1.25 albertel 12285: } else {
12286: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 12287: my $first=$env{$name};
12288: undef($env{$name});
12289: push(@{ $env{$name} },$first,$value);
1.25 albertel 12290: }
12291: } else {
1.258 albertel 12292: $env{$name}=$value;
1.25 albertel 12293: }
1.31 albertel 12294: }
1.149 albertel 12295:
12296: =pod
12297:
1.648 raeburn 12298: =item * &get_env_multiple($name)
1.149 albertel 12299:
1.258 albertel 12300: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 12301: values may be defined and end up as an array ref.
12302:
12303: returns an array of values
12304:
12305: =cut
12306:
12307: sub get_env_multiple {
12308: my ($name) = @_;
12309: my @values;
1.258 albertel 12310: if (defined($env{$name})) {
1.149 albertel 12311: # exists is it an array
1.258 albertel 12312: if (ref($env{$name})) {
12313: @values=@{ $env{$name} };
1.149 albertel 12314: } else {
1.258 albertel 12315: $values[0]=$env{$name};
1.149 albertel 12316: }
12317: }
12318: return(@values);
12319: }
12320:
1.1249 damieng 12321: # Looks at given dependencies, and returns something depending on the context.
12322: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
12323: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
12324: # For all other contexts, returns ($output, $counter, $numpathchg).
12325: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
12326: # $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.
12327: # $numpathchg: integer with the number of cleaned up dependency paths.
12328: # \%existing: hash reference clean path -> 1 only for existing dependencies.
12329: # \%mapping: hash reference clean path -> original path for all dependencies.
12330: # @param {string} actionurl - The path to the handler, indicative of the context.
12331: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
12332: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
12333: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
12334: # @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)
12335: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 12336: sub ask_for_embedded_content {
1.1249 damieng 12337: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 12338: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 12339: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 12340: %currsubfile,%unused,$rem);
1.1071 raeburn 12341: my $counter = 0;
12342: my $numnew = 0;
1.987 raeburn 12343: my $numremref = 0;
12344: my $numinvalid = 0;
12345: my $numpathchg = 0;
12346: my $numexisting = 0;
1.1071 raeburn 12347: my $numunused = 0;
12348: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 12349: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 12350: my $heading = &mt('Upload embedded files');
12351: my $buttontext = &mt('Upload');
12352:
1.1249 damieng 12353: # fills these variables based on the context:
12354: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
12355: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 12356: if ($env{'request.course.id'}) {
1.1123 raeburn 12357: if ($actionurl eq '/adm/dependencies') {
12358: $navmap = Apache::lonnavmaps::navmap->new();
12359: }
12360: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12361: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 12362: }
1.1123 raeburn 12363: if (($actionurl eq '/adm/portfolio') ||
12364: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 12365: my $current_path='/';
12366: if ($env{'form.currentpath'}) {
12367: $current_path = $env{'form.currentpath'};
12368: }
12369: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 12370: $udom = $cdom;
12371: $uname = $cnum;
1.984 raeburn 12372: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
12373: } else {
12374: $udom = $env{'user.domain'};
12375: $uname = $env{'user.name'};
12376: $url = '/userfiles/portfolio';
12377: }
1.987 raeburn 12378: $toplevel = $url.'/';
1.984 raeburn 12379: $url .= $current_path;
12380: $getpropath = 1;
1.987 raeburn 12381: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12382: ($actionurl eq '/adm/imsimport')) {
1.1022 www 12383: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 12384: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 12385: $toplevel = $url;
1.984 raeburn 12386: if ($rest ne '') {
1.987 raeburn 12387: $url .= $rest;
12388: }
12389: } elsif ($actionurl eq '/adm/coursedocs') {
12390: if (ref($args) eq 'HASH') {
1.1071 raeburn 12391: $url = $args->{'docs_url'};
12392: $toplevel = $url;
1.1084 raeburn 12393: if ($args->{'context'} eq 'paste') {
12394: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
12395: ($path) =
12396: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12397: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12398: $fileloc =~ s{^/}{};
12399: }
1.1071 raeburn 12400: }
1.1084 raeburn 12401: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 12402: if ($env{'request.course.id'} ne '') {
12403: if (ref($args) eq 'HASH') {
12404: $url = $args->{'docs_url'};
12405: $title = $args->{'docs_title'};
1.1126 raeburn 12406: $toplevel = $url;
12407: unless ($toplevel =~ m{^/}) {
12408: $toplevel = "/$url";
12409: }
1.1085 raeburn 12410: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 12411: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
12412: $path = $1;
12413: } else {
12414: ($path) =
12415: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12416: }
1.1195 raeburn 12417: if ($toplevel=~/^\/*(uploaded|editupload)/) {
12418: $fileloc = $toplevel;
12419: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
12420: my ($udom,$uname,$fname) =
12421: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
12422: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
12423: } else {
12424: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12425: }
1.1071 raeburn 12426: $fileloc =~ s{^/}{};
12427: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
12428: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
12429: }
1.987 raeburn 12430: }
1.1123 raeburn 12431: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12432: $udom = $cdom;
12433: $uname = $cnum;
12434: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
12435: $toplevel = $url;
12436: $path = $url;
12437: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
12438: $fileloc =~ s{^/}{};
1.987 raeburn 12439: }
1.1249 damieng 12440:
12441: # parses the dependency paths to get some info
12442: # fills $newfiles, $mapping, $subdependencies, $dependencies
12443: # $newfiles: hash URL -> 1 for new files or external URLs
12444: # (will be completed later)
12445: # $mapping:
12446: # for external URLs: external URL -> external URL
12447: # for relative paths: clean path -> original path
12448: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
12449: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 12450: foreach my $file (keys(%{$allfiles})) {
12451: my $embed_file;
12452: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
12453: $embed_file = $1;
12454: } else {
12455: $embed_file = $file;
12456: }
1.1158 raeburn 12457: my ($absolutepath,$cleaned_file);
12458: if ($embed_file =~ m{^\w+://}) {
12459: $cleaned_file = $embed_file;
1.1147 raeburn 12460: $newfiles{$cleaned_file} = 1;
12461: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12462: } else {
1.1158 raeburn 12463: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 12464: if ($embed_file =~ m{^/}) {
12465: $absolutepath = $embed_file;
12466: }
1.1147 raeburn 12467: if ($cleaned_file =~ m{/}) {
12468: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 12469: $path = &check_for_traversal($path,$url,$toplevel);
12470: my $item = $fname;
12471: if ($path ne '') {
12472: $item = $path.'/'.$fname;
12473: $subdependencies{$path}{$fname} = 1;
12474: } else {
12475: $dependencies{$item} = 1;
12476: }
12477: if ($absolutepath) {
12478: $mapping{$item} = $absolutepath;
12479: } else {
12480: $mapping{$item} = $embed_file;
12481: }
12482: } else {
12483: $dependencies{$embed_file} = 1;
12484: if ($absolutepath) {
1.1147 raeburn 12485: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 12486: } else {
1.1147 raeburn 12487: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12488: }
12489: }
1.984 raeburn 12490: }
12491: }
1.1249 damieng 12492:
12493: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
12494: # and lists
12495: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
12496: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
12497: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
12498: # the path had to be cleaned up
12499: # $existing: hash clean path -> 1 if the file exists
12500: # $numexisting: number of keys in $existing
12501: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
12502: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
12503: # dependency subdirectories that are
12504: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 12505: my $dirptr = 16384;
1.984 raeburn 12506: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 12507: $currsubfile{$path} = {};
1.1123 raeburn 12508: if (($actionurl eq '/adm/portfolio') ||
12509: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12510: my ($sublistref,$listerror) =
12511: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
12512: if (ref($sublistref) eq 'ARRAY') {
12513: foreach my $line (@{$sublistref}) {
12514: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 12515: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 12516: }
1.984 raeburn 12517: }
1.987 raeburn 12518: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12519: if (opendir(my $dir,$url.'/'.$path)) {
12520: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 12521: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
12522: }
1.1084 raeburn 12523: } elsif (($actionurl eq '/adm/dependencies') ||
12524: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12525: ($args->{'context'} eq 'paste')) ||
12526: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12527: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 12528: my $dir;
12529: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12530: $dir = $fileloc;
12531: } else {
12532: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12533: }
1.1071 raeburn 12534: if ($dir ne '') {
12535: my ($sublistref,$listerror) =
12536: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
12537: if (ref($sublistref) eq 'ARRAY') {
12538: foreach my $line (@{$sublistref}) {
12539: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
12540: undef,$mtime)=split(/\&/,$line,12);
12541: unless (($testdir&$dirptr) ||
12542: ($file_name =~ /^\.\.?$/)) {
12543: $currsubfile{$path}{$file_name} = [$size,$mtime];
12544: }
12545: }
12546: }
12547: }
1.984 raeburn 12548: }
12549: }
12550: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 12551: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 12552: my $item = $path.'/'.$file;
12553: unless ($mapping{$item} eq $item) {
12554: $pathchanges{$item} = 1;
12555: }
12556: $existing{$item} = 1;
12557: $numexisting ++;
12558: } else {
12559: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 12560: }
12561: }
1.1071 raeburn 12562: if ($actionurl eq '/adm/dependencies') {
12563: foreach my $path (keys(%currsubfile)) {
12564: if (ref($currsubfile{$path}) eq 'HASH') {
12565: foreach my $file (keys(%{$currsubfile{$path}})) {
12566: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 12567: next if (($rem ne '') &&
12568: (($env{"httpref.$rem"."$path/$file"} ne '') ||
12569: (ref($navmap) &&
12570: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
12571: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12572: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 12573: $unused{$path.'/'.$file} = 1;
12574: }
12575: }
12576: }
12577: }
12578: }
1.984 raeburn 12579: }
1.1249 damieng 12580:
12581: # fills $currfile, hash file name -> 1 or [$size,$mtime]
12582: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 12583: my %currfile;
1.1123 raeburn 12584: if (($actionurl eq '/adm/portfolio') ||
12585: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12586: my ($dirlistref,$listerror) =
12587: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
12588: if (ref($dirlistref) eq 'ARRAY') {
12589: foreach my $line (@{$dirlistref}) {
12590: my ($file_name,$rest) = split(/\&/,$line,2);
12591: $currfile{$file_name} = 1;
12592: }
1.984 raeburn 12593: }
1.987 raeburn 12594: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12595: if (opendir(my $dir,$url)) {
1.987 raeburn 12596: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 12597: map {$currfile{$_} = 1;} @dir_list;
12598: }
1.1084 raeburn 12599: } elsif (($actionurl eq '/adm/dependencies') ||
12600: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12601: ($args->{'context'} eq 'paste')) ||
12602: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12603: if ($env{'request.course.id'} ne '') {
12604: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12605: if ($dir ne '') {
12606: my ($dirlistref,$listerror) =
12607: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
12608: if (ref($dirlistref) eq 'ARRAY') {
12609: foreach my $line (@{$dirlistref}) {
12610: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
12611: $size,undef,$mtime)=split(/\&/,$line,12);
12612: unless (($testdir&$dirptr) ||
12613: ($file_name =~ /^\.\.?$/)) {
12614: $currfile{$file_name} = [$size,$mtime];
12615: }
12616: }
12617: }
12618: }
12619: }
1.984 raeburn 12620: }
1.1249 damieng 12621: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
12622: # are not in subdirectories, using $currfile
1.984 raeburn 12623: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 12624: if (exists($currfile{$file})) {
1.987 raeburn 12625: unless ($mapping{$file} eq $file) {
12626: $pathchanges{$file} = 1;
12627: }
12628: $existing{$file} = 1;
12629: $numexisting ++;
12630: } else {
1.984 raeburn 12631: $newfiles{$file} = 1;
12632: }
12633: }
1.1071 raeburn 12634: foreach my $file (keys(%currfile)) {
12635: unless (($file eq $filename) ||
12636: ($file eq $filename.'.bak') ||
12637: ($dependencies{$file})) {
1.1085 raeburn 12638: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 12639: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
12640: next if (($rem ne '') &&
12641: (($env{"httpref.$rem".$file} ne '') ||
12642: (ref($navmap) &&
12643: (($navmap->getResourceByUrl($rem.$file) ne '') ||
12644: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12645: ($navmap->getResourceByUrl($rem.$1)))))));
12646: }
1.1085 raeburn 12647: }
1.1071 raeburn 12648: $unused{$file} = 1;
12649: }
12650: }
1.1249 damieng 12651:
12652: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 12653: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
12654: ($args->{'context'} eq 'paste')) {
12655: $counter = scalar(keys(%existing));
12656: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 12657: return ($output,$counter,$numpathchg,\%existing);
12658: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
12659: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
12660: $counter = scalar(keys(%existing));
12661: $numpathchg = scalar(keys(%pathchanges));
12662: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 12663: }
1.1249 damieng 12664:
12665: # returns HTML otherwise, with dependency results and to ask for more uploads
12666:
12667: # $upload_output: missing dependencies (with upload form)
12668: # $modify_output: uploaded dependencies (in use)
12669: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 12670: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 12671: if ($actionurl eq '/adm/dependencies') {
12672: next if ($embed_file =~ m{^\w+://});
12673: }
1.660 raeburn 12674: $upload_output .= &start_data_table_row().
1.1123 raeburn 12675: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 12676: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 12677: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 12678: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
12679: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 12680: }
1.1123 raeburn 12681: $upload_output .= '</td>';
1.1071 raeburn 12682: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 12683: $upload_output.='<td align="right">'.
12684: '<span class="LC_info LC_fontsize_medium">'.
12685: &mt("URL points to web address").'</span>';
1.987 raeburn 12686: $numremref++;
1.660 raeburn 12687: } elsif ($args->{'error_on_invalid_names'}
12688: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 12689: $upload_output.='<td align="right"><span class="LC_warning">'.
12690: &mt('Invalid characters').'</span>';
1.987 raeburn 12691: $numinvalid++;
1.660 raeburn 12692: } else {
1.1123 raeburn 12693: $upload_output .= '<td>'.
12694: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 12695: $embed_file,\%mapping,
1.1071 raeburn 12696: $allfiles,$codebase,'upload');
12697: $counter ++;
12698: $numnew ++;
1.987 raeburn 12699: }
12700: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
12701: }
12702: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 12703: if ($actionurl eq '/adm/dependencies') {
12704: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
12705: $modify_output .= &start_data_table_row().
12706: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
12707: '<img src="'.&icon($embed_file).'" border="0" />'.
12708: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
12709: '<td>'.$size.'</td>'.
12710: '<td>'.$mtime.'</td>'.
12711: '<td><label><input type="checkbox" name="mod_upload_dep" '.
12712: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
12713: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
12714: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
12715: &embedded_file_element('upload_embedded',$counter,
12716: $embed_file,\%mapping,
12717: $allfiles,$codebase,'modify').
12718: '</div></td>'.
12719: &end_data_table_row()."\n";
12720: $counter ++;
12721: } else {
12722: $upload_output .= &start_data_table_row().
1.1123 raeburn 12723: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
12724: '<span class="LC_filename">'.$embed_file.'</span></td>'.
12725: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 12726: &Apache::loncommon::end_data_table_row()."\n";
12727: }
12728: }
12729: my $delidx = $counter;
12730: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
12731: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
12732: $delete_output .= &start_data_table_row().
12733: '<td><img src="'.&icon($oldfile).'" />'.
12734: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
12735: '<td>'.$size.'</td>'.
12736: '<td>'.$mtime.'</td>'.
12737: '<td><label><input type="checkbox" name="del_upload_dep" '.
12738: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12739: &embedded_file_element('upload_embedded',$delidx,
12740: $oldfile,\%mapping,$allfiles,
12741: $codebase,'delete').'</td>'.
12742: &end_data_table_row()."\n";
12743: $numunused ++;
12744: $delidx ++;
1.987 raeburn 12745: }
12746: if ($upload_output) {
12747: $upload_output = &start_data_table().
12748: $upload_output.
12749: &end_data_table()."\n";
12750: }
1.1071 raeburn 12751: if ($modify_output) {
12752: $modify_output = &start_data_table().
12753: &start_data_table_header_row().
12754: '<th>'.&mt('File').'</th>'.
12755: '<th>'.&mt('Size (KB)').'</th>'.
12756: '<th>'.&mt('Modified').'</th>'.
12757: '<th>'.&mt('Upload replacement?').'</th>'.
12758: &end_data_table_header_row().
12759: $modify_output.
12760: &end_data_table()."\n";
12761: }
12762: if ($delete_output) {
12763: $delete_output = &start_data_table().
12764: &start_data_table_header_row().
12765: '<th>'.&mt('File').'</th>'.
12766: '<th>'.&mt('Size (KB)').'</th>'.
12767: '<th>'.&mt('Modified').'</th>'.
12768: '<th>'.&mt('Delete?').'</th>'.
12769: &end_data_table_header_row().
12770: $delete_output.
12771: &end_data_table()."\n";
12772: }
1.987 raeburn 12773: my $applies = 0;
12774: if ($numremref) {
12775: $applies ++;
12776: }
12777: if ($numinvalid) {
12778: $applies ++;
12779: }
12780: if ($numexisting) {
12781: $applies ++;
12782: }
1.1071 raeburn 12783: if ($counter || $numunused) {
1.987 raeburn 12784: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12785: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12786: $state.'<h3>'.$heading.'</h3>';
12787: if ($actionurl eq '/adm/dependencies') {
12788: if ($numnew) {
12789: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12790: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12791: $upload_output.'<br />'."\n";
12792: }
12793: if ($numexisting) {
12794: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12795: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12796: $modify_output.'<br />'."\n";
12797: $buttontext = &mt('Save changes');
12798: }
12799: if ($numunused) {
12800: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12801: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12802: $delete_output.'<br />'."\n";
12803: $buttontext = &mt('Save changes');
12804: }
12805: } else {
12806: $output .= $upload_output.'<br />'."\n";
12807: }
12808: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12809: $counter.'" />'."\n";
12810: if ($actionurl eq '/adm/dependencies') {
12811: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12812: $numnew.'" />'."\n";
12813: } elsif ($actionurl eq '') {
1.987 raeburn 12814: $output .= '<input type="hidden" name="phase" value="three" />';
12815: }
12816: } elsif ($applies) {
12817: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12818: if ($applies > 1) {
12819: $output .=
1.1123 raeburn 12820: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12821: if ($numremref) {
12822: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12823: }
12824: if ($numinvalid) {
12825: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12826: }
12827: if ($numexisting) {
12828: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12829: }
12830: $output .= '</ul><br />';
12831: } elsif ($numremref) {
12832: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12833: } elsif ($numinvalid) {
12834: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12835: } elsif ($numexisting) {
12836: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12837: }
12838: $output .= $upload_output.'<br />';
12839: }
12840: my ($pathchange_output,$chgcount);
1.1071 raeburn 12841: $chgcount = $counter;
1.987 raeburn 12842: if (keys(%pathchanges) > 0) {
12843: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12844: if ($counter) {
1.987 raeburn 12845: $output .= &embedded_file_element('pathchange',$chgcount,
12846: $embed_file,\%mapping,
1.1071 raeburn 12847: $allfiles,$codebase,'change');
1.987 raeburn 12848: } else {
12849: $pathchange_output .=
12850: &start_data_table_row().
12851: '<td><input type ="checkbox" name="namechange" value="'.
12852: $chgcount.'" checked="checked" /></td>'.
12853: '<td>'.$mapping{$embed_file}.'</td>'.
12854: '<td>'.$embed_file.
12855: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12856: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12857: '</td>'.&end_data_table_row();
1.660 raeburn 12858: }
1.987 raeburn 12859: $numpathchg ++;
12860: $chgcount ++;
1.660 raeburn 12861: }
12862: }
1.1127 raeburn 12863: if (($counter) || ($numunused)) {
1.987 raeburn 12864: if ($numpathchg) {
12865: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12866: $numpathchg.'" />'."\n";
12867: }
12868: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12869: ($actionurl eq '/adm/imsimport')) {
12870: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12871: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12872: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12873: } elsif ($actionurl eq '/adm/dependencies') {
12874: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12875: }
1.1123 raeburn 12876: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12877: } elsif ($numpathchg) {
12878: my %pathchange = ();
12879: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12880: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12881: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 12882: }
1.987 raeburn 12883: }
1.1071 raeburn 12884: return ($output,$counter,$numpathchg);
1.987 raeburn 12885: }
12886:
1.1147 raeburn 12887: =pod
12888:
12889: =item * clean_path($name)
12890:
12891: Performs clean-up of directories, subdirectories and filename in an
12892: embedded object, referenced in an HTML file which is being uploaded
12893: to a course or portfolio, where
12894: "Upload embedded images/multimedia files if HTML file" checkbox was
12895: checked.
12896:
12897: Clean-up is similar to replacements in lonnet::clean_filename()
12898: except each / between sub-directory and next level is preserved.
12899:
12900: =cut
12901:
12902: sub clean_path {
12903: my ($embed_file) = @_;
12904: $embed_file =~s{^/+}{};
12905: my @contents;
12906: if ($embed_file =~ m{/}) {
12907: @contents = split(/\//,$embed_file);
12908: } else {
12909: @contents = ($embed_file);
12910: }
12911: my $lastidx = scalar(@contents)-1;
12912: for (my $i=0; $i<=$lastidx; $i++) {
12913: $contents[$i]=~s{\\}{/}g;
12914: $contents[$i]=~s/\s+/\_/g;
12915: $contents[$i]=~s{[^/\w\.\-]}{}g;
12916: if ($i == $lastidx) {
12917: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12918: }
12919: }
12920: if ($lastidx > 0) {
12921: return join('/',@contents);
12922: } else {
12923: return $contents[0];
12924: }
12925: }
12926:
1.987 raeburn 12927: sub embedded_file_element {
1.1071 raeburn 12928: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12929: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12930: (ref($codebase) eq 'HASH'));
12931: my $output;
1.1071 raeburn 12932: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12933: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12934: }
12935: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12936: &escape($embed_file).'" />';
12937: unless (($context eq 'upload_embedded') &&
12938: ($mapping->{$embed_file} eq $embed_file)) {
12939: $output .='
12940: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12941: }
12942: my $attrib;
12943: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12944: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12945: }
12946: $output .=
12947: "\n\t\t".
12948: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12949: $attrib.'" />';
12950: if (exists($codebase->{$mapping->{$embed_file}})) {
12951: $output .=
12952: "\n\t\t".
12953: '<input name="codebase_'.$num.'" type="hidden" value="'.
12954: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12955: }
1.987 raeburn 12956: return $output;
1.660 raeburn 12957: }
12958:
1.1071 raeburn 12959: sub get_dependency_details {
12960: my ($currfile,$currsubfile,$embed_file) = @_;
12961: my ($size,$mtime,$showsize,$showmtime);
12962: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12963: if ($embed_file =~ m{/}) {
12964: my ($path,$fname) = split(/\//,$embed_file);
12965: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12966: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12967: }
12968: } else {
12969: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12970: ($size,$mtime) = @{$currfile->{$embed_file}};
12971: }
12972: }
12973: $showsize = $size/1024.0;
12974: $showsize = sprintf("%.1f",$showsize);
12975: if ($mtime > 0) {
12976: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12977: }
12978: }
12979: return ($showsize,$showmtime);
12980: }
12981:
12982: sub ask_embedded_js {
12983: return <<"END";
12984: <script type="text/javascript"">
12985: // <![CDATA[
12986: function toggleBrowse(counter) {
12987: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12988: var fileid = document.getElementById('embedded_item_'+counter);
12989: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12990: if (chkboxid.checked == true) {
12991: uploaddivid.style.display='block';
12992: } else {
12993: uploaddivid.style.display='none';
12994: fileid.value = '';
12995: }
12996: }
12997: // ]]>
12998: </script>
12999:
13000: END
13001: }
13002:
1.661 raeburn 13003: sub upload_embedded {
13004: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 13005: $current_disk_usage,$hiddenstate,$actionurl) = @_;
13006: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 13007: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
13008: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
13009: my $orig_uploaded_filename =
13010: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 13011: foreach my $type ('orig','ref','attrib','codebase') {
13012: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
13013: $env{'form.embedded_'.$type.'_'.$i} =
13014: &unescape($env{'form.embedded_'.$type.'_'.$i});
13015: }
13016: }
1.661 raeburn 13017: my ($path,$fname) =
13018: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
13019: # no path, whole string is fname
13020: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
13021: $fname = &Apache::lonnet::clean_filename($fname);
13022: # See if there is anything left
13023: next if ($fname eq '');
13024:
13025: # Check if file already exists as a file or directory.
13026: my ($state,$msg);
13027: if ($context eq 'portfolio') {
13028: my $port_path = $dirpath;
13029: if ($group ne '') {
13030: $port_path = "groups/$group/$port_path";
13031: }
1.987 raeburn 13032: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
13033: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 13034: $dir_root,$port_path,$disk_quota,
13035: $current_disk_usage,$uname,$udom);
13036: if ($state eq 'will_exceed_quota'
1.984 raeburn 13037: || $state eq 'file_locked') {
1.661 raeburn 13038: $output .= $msg;
13039: next;
13040: }
13041: } elsif (($context eq 'author') || ($context eq 'testbank')) {
13042: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
13043: if ($state eq 'exists') {
13044: $output .= $msg;
13045: next;
13046: }
13047: }
13048: # Check if extension is valid
13049: if (($fname =~ /\.(\w+)$/) &&
13050: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 13051: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
13052: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 13053: next;
13054: } elsif (($fname =~ /\.(\w+)$/) &&
13055: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 13056: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 13057: next;
13058: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 13059: $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 13060: next;
13061: }
13062: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 13063: my $subdir = $path;
13064: $subdir =~ s{/+$}{};
1.661 raeburn 13065: if ($context eq 'portfolio') {
1.984 raeburn 13066: my $result;
13067: if ($state eq 'existingfile') {
13068: $result=
13069: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 13070: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 13071: } else {
1.984 raeburn 13072: $result=
13073: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 13074: $dirpath.
1.1123 raeburn 13075: $env{'form.currentpath'}.$subdir);
1.984 raeburn 13076: if ($result !~ m|^/uploaded/|) {
13077: $output .= '<span class="LC_error">'
13078: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
13079: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
13080: .'</span><br />';
13081: next;
13082: } else {
1.987 raeburn 13083: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13084: $path.$fname.'</span>').'<br />';
1.984 raeburn 13085: }
1.661 raeburn 13086: }
1.1123 raeburn 13087: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 13088: my $extendedsubdir = $dirpath.'/'.$subdir;
13089: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 13090: my $result =
1.1126 raeburn 13091: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 13092: if ($result !~ m|^/uploaded/|) {
13093: $output .= '<span class="LC_error">'
13094: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
13095: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
13096: .'</span><br />';
13097: next;
13098: } else {
13099: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13100: $path.$fname.'</span>').'<br />';
1.1125 raeburn 13101: if ($context eq 'syllabus') {
13102: &Apache::lonnet::make_public_indefinitely($result);
13103: }
1.987 raeburn 13104: }
1.661 raeburn 13105: } else {
13106: # Save the file
13107: my $target = $env{'form.embedded_item_'.$i};
13108: my $fullpath = $dir_root.$dirpath.'/'.$path;
13109: my $dest = $fullpath.$fname;
13110: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 13111: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 13112: my $count;
13113: my $filepath = $dir_root;
1.1027 raeburn 13114: foreach my $subdir (@parts) {
13115: $filepath .= "/$subdir";
13116: if (!-e $filepath) {
1.661 raeburn 13117: mkdir($filepath,0770);
13118: }
13119: }
13120: my $fh;
13121: if (!open($fh,'>'.$dest)) {
13122: &Apache::lonnet::logthis('Failed to create '.$dest);
13123: $output .= '<span class="LC_error">'.
1.1071 raeburn 13124: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
13125: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 13126: '</span><br />';
13127: } else {
13128: if (!print $fh $env{'form.embedded_item_'.$i}) {
13129: &Apache::lonnet::logthis('Failed to write to '.$dest);
13130: $output .= '<span class="LC_error">'.
1.1071 raeburn 13131: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
13132: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 13133: '</span><br />';
13134: } else {
1.987 raeburn 13135: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13136: $url.'</span>').'<br />';
13137: unless ($context eq 'testbank') {
13138: $footer .= &mt('View embedded file: [_1]',
13139: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
13140: }
13141: }
13142: close($fh);
13143: }
13144: }
13145: if ($env{'form.embedded_ref_'.$i}) {
13146: $pathchange{$i} = 1;
13147: }
13148: }
13149: if ($output) {
13150: $output = '<p>'.$output.'</p>';
13151: }
13152: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
13153: $returnflag = 'ok';
1.1071 raeburn 13154: my $numpathchgs = scalar(keys(%pathchange));
13155: if ($numpathchgs > 0) {
1.987 raeburn 13156: if ($context eq 'portfolio') {
13157: $output .= '<p>'.&mt('or').'</p>';
13158: } elsif ($context eq 'testbank') {
1.1071 raeburn 13159: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
13160: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 13161: $returnflag = 'modify_orightml';
13162: }
13163: }
1.1071 raeburn 13164: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 13165: }
13166:
13167: sub modify_html_form {
13168: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
13169: my $end = 0;
13170: my $modifyform;
13171: if ($context eq 'upload_embedded') {
13172: return unless (ref($pathchange) eq 'HASH');
13173: if ($env{'form.number_embedded_items'}) {
13174: $end += $env{'form.number_embedded_items'};
13175: }
13176: if ($env{'form.number_pathchange_items'}) {
13177: $end += $env{'form.number_pathchange_items'};
13178: }
13179: if ($end) {
13180: for (my $i=0; $i<$end; $i++) {
13181: if ($i < $env{'form.number_embedded_items'}) {
13182: next unless($pathchange->{$i});
13183: }
13184: $modifyform .=
13185: &start_data_table_row().
13186: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
13187: 'checked="checked" /></td>'.
13188: '<td>'.$env{'form.embedded_ref_'.$i}.
13189: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
13190: &escape($env{'form.embedded_ref_'.$i}).'" />'.
13191: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
13192: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
13193: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
13194: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
13195: '<td>'.$env{'form.embedded_orig_'.$i}.
13196: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
13197: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
13198: &end_data_table_row();
1.1071 raeburn 13199: }
1.987 raeburn 13200: }
13201: } else {
13202: $modifyform = $pathchgtable;
13203: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
13204: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
13205: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
13206: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
13207: }
13208: }
13209: if ($modifyform) {
1.1071 raeburn 13210: if ($actionurl eq '/adm/dependencies') {
13211: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
13212: }
1.987 raeburn 13213: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
13214: '<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".
13215: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
13216: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
13217: '</ol></p>'."\n".'<p>'.
13218: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
13219: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
13220: &start_data_table()."\n".
13221: &start_data_table_header_row().
13222: '<th>'.&mt('Change?').'</th>'.
13223: '<th>'.&mt('Current reference').'</th>'.
13224: '<th>'.&mt('Required reference').'</th>'.
13225: &end_data_table_header_row()."\n".
13226: $modifyform.
13227: &end_data_table().'<br />'."\n".$hiddenstate.
13228: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
13229: '</form>'."\n";
13230: }
13231: return;
13232: }
13233:
13234: sub modify_html_refs {
1.1123 raeburn 13235: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 13236: my $container;
13237: if ($context eq 'portfolio') {
13238: $container = $env{'form.container'};
13239: } elsif ($context eq 'coursedoc') {
13240: $container = $env{'form.primaryurl'};
1.1071 raeburn 13241: } elsif ($context eq 'manage_dependencies') {
13242: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
13243: $container = "/$container";
1.1123 raeburn 13244: } elsif ($context eq 'syllabus') {
13245: $container = $url;
1.987 raeburn 13246: } else {
1.1027 raeburn 13247: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 13248: }
13249: my (%allfiles,%codebase,$output,$content);
13250: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 13251: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 13252: if (wantarray) {
13253: return ('',0,0);
13254: } else {
13255: return;
13256: }
13257: }
13258: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13259: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 13260: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
13261: if (wantarray) {
13262: return ('',0,0);
13263: } else {
13264: return;
13265: }
13266: }
1.987 raeburn 13267: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 13268: if ($content eq '-1') {
13269: if (wantarray) {
13270: return ('',0,0);
13271: } else {
13272: return;
13273: }
13274: }
1.987 raeburn 13275: } else {
1.1071 raeburn 13276: unless ($container =~ /^\Q$dir_root\E/) {
13277: if (wantarray) {
13278: return ('',0,0);
13279: } else {
13280: return;
13281: }
13282: }
1.1317 raeburn 13283: if (open(my $fh,'<',$container)) {
1.987 raeburn 13284: $content = join('', <$fh>);
13285: close($fh);
13286: } else {
1.1071 raeburn 13287: if (wantarray) {
13288: return ('',0,0);
13289: } else {
13290: return;
13291: }
1.987 raeburn 13292: }
13293: }
13294: my ($count,$codebasecount) = (0,0);
13295: my $mm = new File::MMagic;
13296: my $mime_type = $mm->checktype_contents($content);
13297: if ($mime_type eq 'text/html') {
13298: my $parse_result =
13299: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
13300: \%codebase,\$content);
13301: if ($parse_result eq 'ok') {
13302: foreach my $i (@changes) {
13303: my $orig = &unescape($env{'form.embedded_orig_'.$i});
13304: my $ref = &unescape($env{'form.embedded_ref_'.$i});
13305: if ($allfiles{$ref}) {
13306: my $newname = $orig;
13307: my ($attrib_regexp,$codebase);
1.1006 raeburn 13308: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 13309: if ($attrib_regexp =~ /:/) {
13310: $attrib_regexp =~ s/\:/|/g;
13311: }
13312: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13313: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13314: $count += $numchg;
1.1123 raeburn 13315: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 13316: delete($allfiles{$ref});
1.987 raeburn 13317: }
13318: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 13319: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 13320: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
13321: $codebasecount ++;
13322: }
13323: }
13324: }
1.1123 raeburn 13325: my $skiprewrites;
1.987 raeburn 13326: if ($count || $codebasecount) {
13327: my $saveresult;
1.1071 raeburn 13328: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13329: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 13330: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13331: if ($url eq $container) {
13332: my ($fname) = ($container =~ m{/([^/]+)$});
13333: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13334: $count,'<span class="LC_filename">'.
1.1071 raeburn 13335: $fname.'</span>').'</p>';
1.987 raeburn 13336: } else {
13337: $output = '<p class="LC_error">'.
13338: &mt('Error: update failed for: [_1].',
13339: '<span class="LC_filename">'.
13340: $container.'</span>').'</p>';
13341: }
1.1123 raeburn 13342: if ($context eq 'syllabus') {
13343: unless ($saveresult eq 'ok') {
13344: $skiprewrites = 1;
13345: }
13346: }
1.987 raeburn 13347: } else {
1.1317 raeburn 13348: if (open(my $fh,'>',$container)) {
1.987 raeburn 13349: print $fh $content;
13350: close($fh);
13351: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13352: $count,'<span class="LC_filename">'.
13353: $container.'</span>').'</p>';
1.661 raeburn 13354: } else {
1.987 raeburn 13355: $output = '<p class="LC_error">'.
13356: &mt('Error: could not update [_1].',
13357: '<span class="LC_filename">'.
13358: $container.'</span>').'</p>';
1.661 raeburn 13359: }
13360: }
13361: }
1.1123 raeburn 13362: if (($context eq 'syllabus') && (!$skiprewrites)) {
13363: my ($actionurl,$state);
13364: $actionurl = "/public/$udom/$uname/syllabus";
13365: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
13366: &ask_for_embedded_content($actionurl,$state,\%allfiles,
13367: \%codebase,
13368: {'context' => 'rewrites',
13369: 'ignore_remote_references' => 1,});
13370: if (ref($mapping) eq 'HASH') {
13371: my $rewrites = 0;
13372: foreach my $key (keys(%{$mapping})) {
13373: next if ($key =~ m{^https?://});
13374: my $ref = $mapping->{$key};
13375: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
13376: my $attrib;
13377: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
13378: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
13379: }
13380: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13381: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13382: $rewrites += $numchg;
13383: }
13384: }
13385: if ($rewrites) {
13386: my $saveresult;
13387: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13388: if ($url eq $container) {
13389: my ($fname) = ($container =~ m{/([^/]+)$});
13390: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
13391: $count,'<span class="LC_filename">'.
13392: $fname.'</span>').'</p>';
13393: } else {
13394: $output .= '<p class="LC_error">'.
13395: &mt('Error: could not update links in [_1].',
13396: '<span class="LC_filename">'.
13397: $container.'</span>').'</p>';
13398:
13399: }
13400: }
13401: }
13402: }
1.987 raeburn 13403: } else {
13404: &logthis('Failed to parse '.$container.
13405: ' to modify references: '.$parse_result);
1.661 raeburn 13406: }
13407: }
1.1071 raeburn 13408: if (wantarray) {
13409: return ($output,$count,$codebasecount);
13410: } else {
13411: return $output;
13412: }
1.661 raeburn 13413: }
13414:
13415: sub check_for_existing {
13416: my ($path,$fname,$element) = @_;
13417: my ($state,$msg);
13418: if (-d $path.'/'.$fname) {
13419: $state = 'exists';
13420: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13421: } elsif (-e $path.'/'.$fname) {
13422: $state = 'exists';
13423: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13424: }
13425: if ($state eq 'exists') {
13426: $msg = '<span class="LC_error">'.$msg.'</span><br />';
13427: }
13428: return ($state,$msg);
13429: }
13430:
13431: sub check_for_upload {
13432: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
13433: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 13434: my $filesize = length($env{'form.'.$element});
13435: if (!$filesize) {
13436: my $msg = '<span class="LC_error">'.
13437: &mt('Unable to upload [_1]. (size = [_2] bytes)',
13438: '<span class="LC_filename">'.$fname.'</span>',
13439: $filesize).'<br />'.
1.1007 raeburn 13440: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 13441: '</span>';
13442: return ('zero_bytes',$msg);
13443: }
13444: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 13445: my $getpropath = 1;
1.1021 raeburn 13446: my ($dirlistref,$listerror) =
13447: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 13448: my $found_file = 0;
13449: my $locked_file = 0;
1.991 raeburn 13450: my @lockers;
13451: my $navmap;
13452: if ($env{'request.course.id'}) {
13453: $navmap = Apache::lonnavmaps::navmap->new();
13454: }
1.1021 raeburn 13455: if (ref($dirlistref) eq 'ARRAY') {
13456: foreach my $line (@{$dirlistref}) {
13457: my ($file_name,$rest)=split(/\&/,$line,2);
13458: if ($file_name eq $fname){
13459: $file_name = $path.$file_name;
13460: if ($group ne '') {
13461: $file_name = $group.$file_name;
13462: }
13463: $found_file = 1;
13464: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
13465: foreach my $lock (@lockers) {
13466: if (ref($lock) eq 'ARRAY') {
13467: my ($symb,$crsid) = @{$lock};
13468: if ($crsid eq $env{'request.course.id'}) {
13469: if (ref($navmap)) {
13470: my $res = $navmap->getBySymb($symb);
13471: foreach my $part (@{$res->parts()}) {
13472: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
13473: unless (($slot_status == $res->RESERVED) ||
13474: ($slot_status == $res->RESERVED_LOCATION)) {
13475: $locked_file = 1;
13476: }
1.991 raeburn 13477: }
1.1021 raeburn 13478: } else {
13479: $locked_file = 1;
1.991 raeburn 13480: }
13481: } else {
13482: $locked_file = 1;
13483: }
13484: }
1.1021 raeburn 13485: }
13486: } else {
13487: my @info = split(/\&/,$rest);
13488: my $currsize = $info[6]/1000;
13489: if ($currsize < $filesize) {
13490: my $extra = $filesize - $currsize;
13491: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 13492: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 13493: &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 13494: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
13495: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
13496: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 13497: return ('will_exceed_quota',$msg);
13498: }
1.984 raeburn 13499: }
13500: }
1.661 raeburn 13501: }
13502: }
13503: }
13504: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 13505: my $msg = '<p class="LC_warning">'.
13506: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 13507: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 13508: return ('will_exceed_quota',$msg);
13509: } elsif ($found_file) {
13510: if ($locked_file) {
1.1179 bisitz 13511: my $msg = '<p class="LC_warning">';
1.661 raeburn 13512: $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 13513: $msg .= '</p>';
1.661 raeburn 13514: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
13515: return ('file_locked',$msg);
13516: } else {
1.1179 bisitz 13517: my $msg = '<p class="LC_error">';
1.984 raeburn 13518: $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 13519: $msg .= '</p>';
1.984 raeburn 13520: return ('existingfile',$msg);
1.661 raeburn 13521: }
13522: }
13523: }
13524:
1.987 raeburn 13525: sub check_for_traversal {
13526: my ($path,$url,$toplevel) = @_;
13527: my @parts=split(/\//,$path);
13528: my $cleanpath;
13529: my $fullpath = $url;
13530: for (my $i=0;$i<@parts;$i++) {
13531: next if ($parts[$i] eq '.');
13532: if ($parts[$i] eq '..') {
13533: $fullpath =~ s{([^/]+/)$}{};
13534: } else {
13535: $fullpath .= $parts[$i].'/';
13536: }
13537: }
13538: if ($fullpath =~ /^\Q$url\E(.*)$/) {
13539: $cleanpath = $1;
13540: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
13541: my $curr_toprel = $1;
13542: my @parts = split(/\//,$curr_toprel);
13543: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
13544: my @urlparts = split(/\//,$url_toprel);
13545: my $doubledots;
13546: my $startdiff = -1;
13547: for (my $i=0; $i<@urlparts; $i++) {
13548: if ($startdiff == -1) {
13549: unless ($urlparts[$i] eq $parts[$i]) {
13550: $startdiff = $i;
13551: $doubledots .= '../';
13552: }
13553: } else {
13554: $doubledots .= '../';
13555: }
13556: }
13557: if ($startdiff > -1) {
13558: $cleanpath = $doubledots;
13559: for (my $i=$startdiff; $i<@parts; $i++) {
13560: $cleanpath .= $parts[$i].'/';
13561: }
13562: }
13563: }
13564: $cleanpath =~ s{(/)$}{};
13565: return $cleanpath;
13566: }
1.31 albertel 13567:
1.1053 raeburn 13568: sub is_archive_file {
13569: my ($mimetype) = @_;
13570: if (($mimetype eq 'application/octet-stream') ||
13571: ($mimetype eq 'application/x-stuffit') ||
13572: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
13573: return 1;
13574: }
13575: return;
13576: }
13577:
13578: sub decompress_form {
1.1065 raeburn 13579: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 13580: my %lt = &Apache::lonlocal::texthash (
13581: this => 'This file is an archive file.',
1.1067 raeburn 13582: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 13583: itsc => 'Its contents are as follows:',
1.1053 raeburn 13584: youm => 'You may wish to extract its contents.',
13585: extr => 'Extract contents',
1.1067 raeburn 13586: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
13587: proa => 'Process automatically?',
1.1053 raeburn 13588: yes => 'Yes',
13589: no => 'No',
1.1067 raeburn 13590: fold => 'Title for folder containing movie',
13591: movi => 'Title for page containing embedded movie',
1.1053 raeburn 13592: );
1.1065 raeburn 13593: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 13594: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 13595: my $info = &list_archive_contents($fileloc,\@paths);
13596: if (@paths) {
13597: foreach my $path (@paths) {
13598: $path =~ s{^/}{};
1.1067 raeburn 13599: if ($path =~ m{^([^/]+)/$}) {
13600: $topdir = $1;
13601: }
1.1065 raeburn 13602: if ($path =~ m{^([^/]+)/}) {
13603: $toplevel{$1} = $path;
13604: } else {
13605: $toplevel{$path} = $path;
13606: }
13607: }
13608: }
1.1067 raeburn 13609: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 13610: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 13611: "$topdir/media/",
13612: "$topdir/media/$topdir.mp4",
13613: "$topdir/media/FirstFrame.png",
13614: "$topdir/media/player.swf",
13615: "$topdir/media/swfobject.js",
13616: "$topdir/media/expressInstall.swf");
1.1197 raeburn 13617: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 13618: "$topdir/$topdir.mp4",
13619: "$topdir/$topdir\_config.xml",
13620: "$topdir/$topdir\_controller.swf",
13621: "$topdir/$topdir\_embed.css",
13622: "$topdir/$topdir\_First_Frame.png",
13623: "$topdir/$topdir\_player.html",
13624: "$topdir/$topdir\_Thumbnails.png",
13625: "$topdir/playerProductInstall.swf",
13626: "$topdir/scripts/",
13627: "$topdir/scripts/config_xml.js",
13628: "$topdir/scripts/handlebars.js",
13629: "$topdir/scripts/jquery-1.7.1.min.js",
13630: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
13631: "$topdir/scripts/modernizr.js",
13632: "$topdir/scripts/player-min.js",
13633: "$topdir/scripts/swfobject.js",
13634: "$topdir/skins/",
13635: "$topdir/skins/configuration_express.xml",
13636: "$topdir/skins/express_show/",
13637: "$topdir/skins/express_show/player-min.css",
13638: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 13639: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
13640: "$topdir/$topdir.mp4",
13641: "$topdir/$topdir\_config.xml",
13642: "$topdir/$topdir\_controller.swf",
13643: "$topdir/$topdir\_embed.css",
13644: "$topdir/$topdir\_First_Frame.png",
13645: "$topdir/$topdir\_player.html",
13646: "$topdir/$topdir\_Thumbnails.png",
13647: "$topdir/playerProductInstall.swf",
13648: "$topdir/scripts/",
13649: "$topdir/scripts/config_xml.js",
13650: "$topdir/scripts/techsmith-smart-player.min.js",
13651: "$topdir/skins/",
13652: "$topdir/skins/configuration_express.xml",
13653: "$topdir/skins/express_show/",
13654: "$topdir/skins/express_show/spritesheet.min.css",
13655: "$topdir/skins/express_show/spritesheet.png",
13656: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 13657: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 13658: if (@diffs == 0) {
1.1164 raeburn 13659: $is_camtasia = 6;
13660: } else {
1.1197 raeburn 13661: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 13662: if (@diffs == 0) {
13663: $is_camtasia = 8;
1.1197 raeburn 13664: } else {
13665: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
13666: if (@diffs == 0) {
13667: $is_camtasia = 8;
13668: }
1.1164 raeburn 13669: }
1.1067 raeburn 13670: }
13671: }
13672: my $output;
13673: if ($is_camtasia) {
13674: $output = <<"ENDCAM";
13675: <script type="text/javascript" language="Javascript">
13676: // <![CDATA[
13677:
13678: function camtasiaToggle() {
13679: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
13680: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 13681: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 13682: document.getElementById('camtasia_titles').style.display='block';
13683: } else {
13684: document.getElementById('camtasia_titles').style.display='none';
13685: }
13686: }
13687: }
13688: return;
13689: }
13690:
13691: // ]]>
13692: </script>
13693: <p>$lt{'camt'}</p>
13694: ENDCAM
1.1065 raeburn 13695: } else {
1.1067 raeburn 13696: $output = '<p>'.$lt{'this'};
13697: if ($info eq '') {
13698: $output .= ' '.$lt{'youm'}.'</p>'."\n";
13699: } else {
13700: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
13701: '<div><pre>'.$info.'</pre></div>';
13702: }
1.1065 raeburn 13703: }
1.1067 raeburn 13704: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 13705: my $duplicates;
13706: my $num = 0;
13707: if (ref($dirlist) eq 'ARRAY') {
13708: foreach my $item (@{$dirlist}) {
13709: if (ref($item) eq 'ARRAY') {
13710: if (exists($toplevel{$item->[0]})) {
13711: $duplicates .=
13712: &start_data_table_row().
13713: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
13714: 'value="0" checked="checked" />'.&mt('No').'</label>'.
13715: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
13716: 'value="1" />'.&mt('Yes').'</label>'.
13717: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
13718: '<td>'.$item->[0].'</td>';
13719: if ($item->[2]) {
13720: $duplicates .= '<td>'.&mt('Directory').'</td>';
13721: } else {
13722: $duplicates .= '<td>'.&mt('File').'</td>';
13723: }
13724: $duplicates .= '<td>'.$item->[3].'</td>'.
13725: '<td>'.
13726: &Apache::lonlocal::locallocaltime($item->[4]).
13727: '</td>'.
13728: &end_data_table_row();
13729: $num ++;
13730: }
13731: }
13732: }
13733: }
13734: my $itemcount;
13735: if (@paths > 0) {
13736: $itemcount = scalar(@paths);
13737: } else {
13738: $itemcount = 1;
13739: }
1.1067 raeburn 13740: if ($is_camtasia) {
13741: $output .= $lt{'auto'}.'<br />'.
13742: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 13743: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13744: $lt{'yes'}.'</label> <label>'.
13745: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13746: $lt{'no'}.'</label></span><br />'.
13747: '<div id="camtasia_titles" style="display:block">'.
13748: &Apache::lonhtmlcommon::start_pick_box().
13749: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13750: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13751: &Apache::lonhtmlcommon::row_closure().
13752: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13753: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13754: &Apache::lonhtmlcommon::row_closure(1).
13755: &Apache::lonhtmlcommon::end_pick_box().
13756: '</div>';
13757: }
1.1065 raeburn 13758: $output .=
13759: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13760: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13761: "\n";
1.1065 raeburn 13762: if ($duplicates ne '') {
13763: $output .= '<p><span class="LC_warning">'.
13764: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13765: &start_data_table().
13766: &start_data_table_header_row().
13767: '<th>'.&mt('Overwrite?').'</th>'.
13768: '<th>'.&mt('Name').'</th>'.
13769: '<th>'.&mt('Type').'</th>'.
13770: '<th>'.&mt('Size').'</th>'.
13771: '<th>'.&mt('Last modified').'</th>'.
13772: &end_data_table_header_row().
13773: $duplicates.
13774: &end_data_table().
13775: '</p>';
13776: }
1.1067 raeburn 13777: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13778: if (ref($hiddenelements) eq 'HASH') {
13779: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13780: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13781: }
13782: }
13783: $output .= <<"END";
1.1067 raeburn 13784: <br />
1.1053 raeburn 13785: <input type="submit" name="decompress" value="$lt{'extr'}" />
13786: </form>
13787: $noextract
13788: END
13789: return $output;
13790: }
13791:
1.1065 raeburn 13792: sub decompression_utility {
13793: my ($program) = @_;
13794: my @utilities = ('tar','gunzip','bunzip2','unzip');
13795: my $location;
13796: if (grep(/^\Q$program\E$/,@utilities)) {
13797: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13798: '/usr/sbin/') {
13799: if (-x $dir.$program) {
13800: $location = $dir.$program;
13801: last;
13802: }
13803: }
13804: }
13805: return $location;
13806: }
13807:
13808: sub list_archive_contents {
13809: my ($file,$pathsref) = @_;
13810: my (@cmd,$output);
13811: my $needsregexp;
13812: if ($file =~ /\.zip$/) {
13813: @cmd = (&decompression_utility('unzip'),"-l");
13814: $needsregexp = 1;
13815: } elsif (($file =~ m/\.tar\.gz$/) ||
13816: ($file =~ /\.tgz$/)) {
13817: @cmd = (&decompression_utility('tar'),"-ztf");
13818: } elsif ($file =~ /\.tar\.bz2$/) {
13819: @cmd = (&decompression_utility('tar'),"-jtf");
13820: } elsif ($file =~ m|\.tar$|) {
13821: @cmd = (&decompression_utility('tar'),"-tf");
13822: }
13823: if (@cmd) {
13824: undef($!);
13825: undef($@);
13826: if (open(my $fh,"-|", @cmd, $file)) {
13827: while (my $line = <$fh>) {
13828: $output .= $line;
13829: chomp($line);
13830: my $item;
13831: if ($needsregexp) {
13832: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13833: } else {
13834: $item = $line;
13835: }
13836: if ($item ne '') {
13837: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13838: push(@{$pathsref},$item);
13839: }
13840: }
13841: }
13842: close($fh);
13843: }
13844: }
13845: return $output;
13846: }
13847:
1.1053 raeburn 13848: sub decompress_uploaded_file {
13849: my ($file,$dir) = @_;
13850: &Apache::lonnet::appenv({'cgi.file' => $file});
13851: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13852: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13853: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13854: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13855: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13856: my $decompressed = $env{'cgi.decompressed'};
13857: &Apache::lonnet::delenv('cgi.file');
13858: &Apache::lonnet::delenv('cgi.dir');
13859: &Apache::lonnet::delenv('cgi.decompressed');
13860: return ($decompressed,$result);
13861: }
13862:
1.1055 raeburn 13863: sub process_decompression {
13864: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 13865: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13866: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13867: &mt('Unexpected file path.').'</p>'."\n";
13868: }
13869: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13870: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13871: &mt('Unexpected course context.').'</p>'."\n";
13872: }
1.1293 raeburn 13873: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 13874: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13875: &mt('Filename contained unexpected characters.').'</p>'."\n";
13876: }
1.1055 raeburn 13877: my ($dir,$error,$warning,$output);
1.1180 raeburn 13878: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 13879: $error = &mt('Filename not a supported archive file type.').
13880: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13881: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13882: } else {
13883: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13884: if ($docuhome eq 'no_host') {
13885: $error = &mt('Could not determine home server for course.');
13886: } else {
13887: my @ids=&Apache::lonnet::current_machine_ids();
13888: my $currdir = "$dir_root/$destination";
13889: if (grep(/^\Q$docuhome\E$/,@ids)) {
13890: $dir = &LONCAPA::propath($docudom,$docuname).
13891: "$dir_root/$destination";
13892: } else {
13893: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13894: "$dir_root/$docudom/$docuname/$destination";
13895: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13896: $error = &mt('Archive file not found.');
13897: }
13898: }
1.1065 raeburn 13899: my (@to_overwrite,@to_skip);
13900: if ($env{'form.archive_overwrite_total'} > 0) {
13901: my $total = $env{'form.archive_overwrite_total'};
13902: for (my $i=0; $i<$total; $i++) {
13903: if ($env{'form.archive_overwrite_'.$i} == 1) {
13904: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13905: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13906: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13907: }
13908: }
13909: }
13910: my $numskip = scalar(@to_skip);
1.1292 raeburn 13911: my $numoverwrite = scalar(@to_overwrite);
13912: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13913: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13914: } elsif ($dir eq '') {
1.1055 raeburn 13915: $error = &mt('Directory containing archive file unavailable.');
13916: } elsif (!$error) {
1.1065 raeburn 13917: my ($decompressed,$display);
1.1292 raeburn 13918: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13919: my $tempdir = time.'_'.$$.int(rand(10000));
13920: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 13921: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13922: ($decompressed,$display) =
13923: &decompress_uploaded_file($file,"$dir/$tempdir");
13924: foreach my $item (@to_skip) {
13925: if (($item ne '') && ($item !~ /\.\./)) {
13926: if (-f "$dir/$tempdir/$item") {
13927: unlink("$dir/$tempdir/$item");
13928: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 13929: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 13930: }
13931: }
13932: }
13933: foreach my $item (@to_overwrite) {
13934: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13935: if (($item ne '') && ($item !~ /\.\./)) {
13936: if (-f "$dir/$item") {
13937: unlink("$dir/$item");
13938: } elsif (-d "$dir/$item") {
1.1300 raeburn 13939: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 13940: }
13941: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13942: }
1.1065 raeburn 13943: }
13944: }
1.1292 raeburn 13945: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 13946: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 13947: }
1.1065 raeburn 13948: }
13949: } else {
13950: ($decompressed,$display) =
13951: &decompress_uploaded_file($file,$dir);
13952: }
1.1055 raeburn 13953: if ($decompressed eq 'ok') {
1.1065 raeburn 13954: $output = '<p class="LC_info">'.
13955: &mt('Files extracted successfully from archive.').
13956: '</p>'."\n";
1.1055 raeburn 13957: my ($warning,$result,@contents);
13958: my ($newdirlistref,$newlisterror) =
13959: &Apache::lonnet::dirlist($currdir,$docudom,
13960: $docuname,1);
13961: my (%is_dir,%changes,@newitems);
13962: my $dirptr = 16384;
1.1065 raeburn 13963: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13964: foreach my $dir_line (@{$newdirlistref}) {
13965: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 13966: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13967: push(@newitems,$item);
13968: if ($dirptr&$testdir) {
13969: $is_dir{$item} = 1;
13970: }
13971: $changes{$item} = 1;
13972: }
13973: }
13974: }
13975: if (keys(%changes) > 0) {
13976: foreach my $item (sort(@newitems)) {
13977: if ($changes{$item}) {
13978: push(@contents,$item);
13979: }
13980: }
13981: }
13982: if (@contents > 0) {
1.1067 raeburn 13983: my $wantform;
13984: unless ($env{'form.autoextract_camtasia'}) {
13985: $wantform = 1;
13986: }
1.1056 raeburn 13987: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13988: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13989: $currdir,\%is_dir,
13990: \%children,\%parent,
1.1056 raeburn 13991: \@contents,\%dirorder,
13992: \%titles,$wantform);
1.1055 raeburn 13993: if ($datatable ne '') {
13994: $output .= &archive_options_form('decompressed',$datatable,
13995: $count,$hiddenelem);
1.1065 raeburn 13996: my $startcount = 6;
1.1055 raeburn 13997: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13998: \%titles,\%children);
1.1055 raeburn 13999: }
1.1067 raeburn 14000: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 14001: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 14002: my %displayed;
14003: my $total = 1;
14004: $env{'form.archive_directory'} = [];
14005: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
14006: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
14007: $path =~ s{/$}{};
14008: my $item;
14009: if ($path ne '') {
14010: $item = "$path/$titles{$i}";
14011: } else {
14012: $item = $titles{$i};
14013: }
14014: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
14015: if ($item eq $contents[0]) {
14016: push(@{$env{'form.archive_directory'}},$i);
14017: $env{'form.archive_'.$i} = 'display';
14018: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
14019: $displayed{'folder'} = $i;
1.1164 raeburn 14020: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
14021: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 14022: $env{'form.archive_'.$i} = 'display';
14023: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
14024: $displayed{'web'} = $i;
14025: } else {
1.1164 raeburn 14026: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
14027: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
14028: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 14029: push(@{$env{'form.archive_directory'}},$i);
14030: }
14031: $env{'form.archive_'.$i} = 'dependency';
14032: }
14033: $total ++;
14034: }
14035: for (my $i=1; $i<$total; $i++) {
14036: next if ($i == $displayed{'web'});
14037: next if ($i == $displayed{'folder'});
14038: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
14039: }
14040: $env{'form.phase'} = 'decompress_cleanup';
14041: $env{'form.archivedelete'} = 1;
14042: $env{'form.archive_count'} = $total-1;
14043: $output .=
14044: &process_extracted_files('coursedocs',$docudom,
14045: $docuname,$destination,
14046: $dir_root,$hiddenelem);
14047: }
1.1055 raeburn 14048: } else {
14049: $warning = &mt('No new items extracted from archive file.');
14050: }
14051: } else {
14052: $output = $display;
14053: $error = &mt('An error occurred during extraction from the archive file.');
14054: }
14055: }
14056: }
14057: }
14058: if ($error) {
14059: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14060: $error.'</p>'."\n";
14061: }
14062: if ($warning) {
14063: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14064: }
14065: return $output;
14066: }
14067:
14068: sub get_extracted {
1.1056 raeburn 14069: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
14070: $titles,$wantform) = @_;
1.1055 raeburn 14071: my $count = 0;
14072: my $depth = 0;
14073: my $datatable;
1.1056 raeburn 14074: my @hierarchy;
1.1055 raeburn 14075: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 14076: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
14077: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 14078: foreach my $item (@{$contents}) {
14079: $count ++;
1.1056 raeburn 14080: @{$dirorder->{$count}} = @hierarchy;
14081: $titles->{$count} = $item;
1.1055 raeburn 14082: &archive_hierarchy($depth,$count,$parent,$children);
14083: if ($wantform) {
14084: $datatable .= &archive_row($is_dir->{$item},$item,
14085: $currdir,$depth,$count);
14086: }
14087: if ($is_dir->{$item}) {
14088: $depth ++;
1.1056 raeburn 14089: push(@hierarchy,$count);
14090: $parent->{$depth} = $count;
1.1055 raeburn 14091: $datatable .=
14092: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 14093: \$depth,\$count,\@hierarchy,$dirorder,
14094: $children,$parent,$titles,$wantform);
1.1055 raeburn 14095: $depth --;
1.1056 raeburn 14096: pop(@hierarchy);
1.1055 raeburn 14097: }
14098: }
14099: return ($count,$datatable);
14100: }
14101:
14102: sub recurse_extracted_archive {
1.1056 raeburn 14103: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
14104: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 14105: my $result='';
1.1056 raeburn 14106: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
14107: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
14108: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 14109: return $result;
14110: }
14111: my $dirptr = 16384;
14112: my ($newdirlistref,$newlisterror) =
14113: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
14114: if (ref($newdirlistref) eq 'ARRAY') {
14115: foreach my $dir_line (@{$newdirlistref}) {
14116: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
14117: unless ($item =~ /^\.+$/) {
14118: $$count ++;
1.1056 raeburn 14119: @{$dirorder->{$$count}} = @{$hierarchy};
14120: $titles->{$$count} = $item;
1.1055 raeburn 14121: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 14122:
1.1055 raeburn 14123: my $is_dir;
14124: if ($dirptr&$testdir) {
14125: $is_dir = 1;
14126: }
14127: if ($wantform) {
14128: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
14129: }
14130: if ($is_dir) {
14131: $$depth ++;
1.1056 raeburn 14132: push(@{$hierarchy},$$count);
14133: $parent->{$$depth} = $$count;
1.1055 raeburn 14134: $result .=
14135: &recurse_extracted_archive("$currdir/$item",$docudom,
14136: $docuname,$depth,$count,
1.1056 raeburn 14137: $hierarchy,$dirorder,$children,
14138: $parent,$titles,$wantform);
1.1055 raeburn 14139: $$depth --;
1.1056 raeburn 14140: pop(@{$hierarchy});
1.1055 raeburn 14141: }
14142: }
14143: }
14144: }
14145: return $result;
14146: }
14147:
14148: sub archive_hierarchy {
14149: my ($depth,$count,$parent,$children) =@_;
14150: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
14151: if (exists($parent->{$depth})) {
14152: $children->{$parent->{$depth}} .= $count.':';
14153: }
14154: }
14155: return;
14156: }
14157:
14158: sub archive_row {
14159: my ($is_dir,$item,$currdir,$depth,$count) = @_;
14160: my ($name) = ($item =~ m{([^/]+)$});
14161: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 14162: 'display' => 'Add as file',
1.1055 raeburn 14163: 'dependency' => 'Include as dependency',
14164: 'discard' => 'Discard',
14165: );
14166: if ($is_dir) {
1.1059 raeburn 14167: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 14168: }
1.1056 raeburn 14169: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
14170: my $offset = 0;
1.1055 raeburn 14171: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 14172: $offset ++;
1.1065 raeburn 14173: if ($action ne 'display') {
14174: $offset ++;
14175: }
1.1055 raeburn 14176: $output .= '<td><span class="LC_nobreak">'.
14177: '<label><input type="radio" name="archive_'.$count.
14178: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
14179: my $text = $choices{$action};
14180: if ($is_dir) {
14181: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
14182: if ($action eq 'display') {
1.1059 raeburn 14183: $text = &mt('Add as folder');
1.1055 raeburn 14184: }
1.1056 raeburn 14185: } else {
14186: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
14187:
14188: }
14189: $output .= ' /> '.$choices{$action}.'</label></span>';
14190: if ($action eq 'dependency') {
14191: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
14192: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
14193: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
14194: '<option value=""></option>'."\n".
14195: '</select>'."\n".
14196: '</div>';
1.1059 raeburn 14197: } elsif ($action eq 'display') {
14198: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
14199: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
14200: '</div>';
1.1055 raeburn 14201: }
1.1056 raeburn 14202: $output .= '</td>';
1.1055 raeburn 14203: }
14204: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
14205: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
14206: for (my $i=0; $i<$depth; $i++) {
14207: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
14208: }
14209: if ($is_dir) {
14210: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
14211: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
14212: } else {
14213: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
14214: }
14215: $output .= ' '.$name.'</td>'."\n".
14216: &end_data_table_row();
14217: return $output;
14218: }
14219:
14220: sub archive_options_form {
1.1065 raeburn 14221: my ($form,$display,$count,$hiddenelem) = @_;
14222: my %lt = &Apache::lonlocal::texthash(
14223: perm => 'Permanently remove archive file?',
14224: hows => 'How should each extracted item be incorporated in the course?',
14225: cont => 'Content actions for all',
14226: addf => 'Add as folder/file',
14227: incd => 'Include as dependency for a displayed file',
14228: disc => 'Discard',
14229: no => 'No',
14230: yes => 'Yes',
14231: save => 'Save',
14232: );
14233: my $output = <<"END";
14234: <form name="$form" method="post" action="">
14235: <p><span class="LC_nobreak">$lt{'perm'}
14236: <label>
14237: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
14238: </label>
14239:
14240: <label>
14241: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
14242: </span>
14243: </p>
14244: <input type="hidden" name="phase" value="decompress_cleanup" />
14245: <br />$lt{'hows'}
14246: <div class="LC_columnSection">
14247: <fieldset>
14248: <legend>$lt{'cont'}</legend>
14249: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
14250: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
14251: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
14252: </fieldset>
14253: </div>
14254: END
14255: return $output.
1.1055 raeburn 14256: &start_data_table()."\n".
1.1065 raeburn 14257: $display."\n".
1.1055 raeburn 14258: &end_data_table()."\n".
14259: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
14260: $hiddenelem.
1.1065 raeburn 14261: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 14262: '</form>';
14263: }
14264:
14265: sub archive_javascript {
1.1056 raeburn 14266: my ($startcount,$numitems,$titles,$children) = @_;
14267: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 14268: my $maintitle = $env{'form.comment'};
1.1055 raeburn 14269: my $scripttag = <<START;
14270: <script type="text/javascript">
14271: // <![CDATA[
14272:
14273: function checkAll(form,prefix) {
14274: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
14275: for (var i=0; i < form.elements.length; i++) {
14276: var id = form.elements[i].id;
14277: if ((id != '') && (id != undefined)) {
14278: if (idstr.test(id)) {
14279: if (form.elements[i].type == 'radio') {
14280: form.elements[i].checked = true;
1.1056 raeburn 14281: var nostart = i-$startcount;
1.1059 raeburn 14282: var offset = nostart%7;
14283: var count = (nostart-offset)/7;
1.1056 raeburn 14284: dependencyCheck(form,count,offset);
1.1055 raeburn 14285: }
14286: }
14287: }
14288: }
14289: }
14290:
14291: function propagateCheck(form,count) {
14292: if (count > 0) {
1.1059 raeburn 14293: var startelement = $startcount + ((count-1) * 7);
14294: for (var j=1; j<6; j++) {
14295: if ((j != 2) && (j != 4)) {
1.1056 raeburn 14296: var item = startelement + j;
14297: if (form.elements[item].type == 'radio') {
14298: if (form.elements[item].checked) {
14299: containerCheck(form,count,j);
14300: break;
14301: }
1.1055 raeburn 14302: }
14303: }
14304: }
14305: }
14306: }
14307:
14308: numitems = $numitems
1.1056 raeburn 14309: var titles = new Array(numitems);
14310: var parents = new Array(numitems);
1.1055 raeburn 14311: for (var i=0; i<numitems; i++) {
1.1056 raeburn 14312: parents[i] = new Array;
1.1055 raeburn 14313: }
1.1059 raeburn 14314: var maintitle = '$maintitle';
1.1055 raeburn 14315:
14316: START
14317:
1.1056 raeburn 14318: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
14319: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 14320: for (my $i=0; $i<@contents; $i ++) {
14321: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
14322: }
14323: }
14324:
1.1056 raeburn 14325: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
14326: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
14327: }
14328:
1.1055 raeburn 14329: $scripttag .= <<END;
14330:
14331: function containerCheck(form,count,offset) {
14332: if (count > 0) {
1.1056 raeburn 14333: dependencyCheck(form,count,offset);
1.1059 raeburn 14334: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 14335: form.elements[item].checked = true;
14336: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
14337: if (parents[count].length > 0) {
14338: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 14339: containerCheck(form,parents[count][j],offset);
14340: }
14341: }
14342: }
14343: }
14344: }
14345:
14346: function dependencyCheck(form,count,offset) {
14347: if (count > 0) {
1.1059 raeburn 14348: var chosen = (offset+$startcount)+7*(count-1);
14349: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 14350: var currtype = form.elements[depitem].type;
14351: if (form.elements[chosen].value == 'dependency') {
14352: document.getElementById('arc_depon_'+count).style.display='block';
14353: form.elements[depitem].options.length = 0;
14354: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 14355: for (var i=1; i<=numitems; i++) {
14356: if (i == count) {
14357: continue;
14358: }
1.1059 raeburn 14359: var startelement = $startcount + (i-1) * 7;
14360: for (var j=1; j<6; j++) {
14361: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 14362: var item = startelement + j;
14363: if (form.elements[item].type == 'radio') {
14364: if (form.elements[item].checked) {
14365: if (form.elements[item].value == 'display') {
14366: var n = form.elements[depitem].options.length;
14367: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
14368: }
14369: }
14370: }
14371: }
14372: }
14373: }
14374: } else {
14375: document.getElementById('arc_depon_'+count).style.display='none';
14376: form.elements[depitem].options.length = 0;
14377: form.elements[depitem].options[0] = new Option('Select','',true,true);
14378: }
1.1059 raeburn 14379: titleCheck(form,count,offset);
1.1056 raeburn 14380: }
14381: }
14382:
14383: function propagateSelect(form,count,offset) {
14384: if (count > 0) {
1.1065 raeburn 14385: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 14386: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
14387: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14388: if (parents[count].length > 0) {
14389: for (var j=0; j<parents[count].length; j++) {
14390: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 14391: }
14392: }
14393: }
14394: }
14395: }
1.1056 raeburn 14396:
14397: function containerSelect(form,count,offset,picked) {
14398: if (count > 0) {
1.1065 raeburn 14399: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 14400: if (form.elements[item].type == 'radio') {
14401: if (form.elements[item].value == 'dependency') {
14402: if (form.elements[item+1].type == 'select-one') {
14403: for (var i=0; i<form.elements[item+1].options.length; i++) {
14404: if (form.elements[item+1].options[i].value == picked) {
14405: form.elements[item+1].selectedIndex = i;
14406: break;
14407: }
14408: }
14409: }
14410: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14411: if (parents[count].length > 0) {
14412: for (var j=0; j<parents[count].length; j++) {
14413: containerSelect(form,parents[count][j],offset,picked);
14414: }
14415: }
14416: }
14417: }
14418: }
14419: }
14420: }
14421:
1.1059 raeburn 14422: function titleCheck(form,count,offset) {
14423: if (count > 0) {
14424: var chosen = (offset+$startcount)+7*(count-1);
14425: var depitem = $startcount + ((count-1) * 7) + 2;
14426: var currtype = form.elements[depitem].type;
14427: if (form.elements[chosen].value == 'display') {
14428: document.getElementById('arc_title_'+count).style.display='block';
14429: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
14430: document.getElementById('archive_title_'+count).value=maintitle;
14431: }
14432: } else {
14433: document.getElementById('arc_title_'+count).style.display='none';
14434: if (currtype == 'text') {
14435: document.getElementById('archive_title_'+count).value='';
14436: }
14437: }
14438: }
14439: return;
14440: }
14441:
1.1055 raeburn 14442: // ]]>
14443: </script>
14444: END
14445: return $scripttag;
14446: }
14447:
14448: sub process_extracted_files {
1.1067 raeburn 14449: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 14450: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 14451: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 14452: my @ids=&Apache::lonnet::current_machine_ids();
14453: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 14454: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 14455: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14456: if (grep(/^\Q$docuhome\E$/,@ids)) {
14457: $prefix = &LONCAPA::propath($docudom,$docuname);
14458: $pathtocheck = "$dir_root/$destination";
14459: $dir = $dir_root;
14460: $ishome = 1;
14461: } else {
14462: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
14463: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 14464: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 14465: }
14466: my $currdir = "$dir_root/$destination";
14467: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
14468: if ($env{'form.folderpath'}) {
14469: my @items = split('&',$env{'form.folderpath'});
14470: $folders{'0'} = $items[-2];
1.1099 raeburn 14471: if ($env{'form.folderpath'} =~ /\:1$/) {
14472: $containers{'0'}='page';
14473: } else {
14474: $containers{'0'}='sequence';
14475: }
1.1055 raeburn 14476: }
14477: my @archdirs = &get_env_multiple('form.archive_directory');
14478: if ($numitems) {
14479: for (my $i=1; $i<=$numitems; $i++) {
14480: my $path = $env{'form.archive_content_'.$i};
14481: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
14482: my $item = $1;
14483: $toplevelitems{$item} = $i;
14484: if (grep(/^\Q$i\E$/,@archdirs)) {
14485: $is_dir{$item} = 1;
14486: }
14487: }
14488: }
14489: }
1.1067 raeburn 14490: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 14491: if (keys(%toplevelitems) > 0) {
14492: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 14493: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
14494: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 14495: }
1.1066 raeburn 14496: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 14497: if ($numitems) {
14498: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 14499: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 14500: my $path = $env{'form.archive_content_'.$i};
14501: if ($path =~ /^\Q$pathtocheck\E/) {
14502: if ($env{'form.archive_'.$i} eq 'discard') {
14503: if ($prefix ne '' && $path ne '') {
14504: if (-e $prefix.$path) {
1.1066 raeburn 14505: if ((@archdirs > 0) &&
14506: (grep(/^\Q$i\E$/,@archdirs))) {
14507: $todeletedir{$prefix.$path} = 1;
14508: } else {
14509: $todelete{$prefix.$path} = 1;
14510: }
1.1055 raeburn 14511: }
14512: }
14513: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 14514: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 14515: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 14516: $docstitle = $env{'form.archive_title_'.$i};
14517: if ($docstitle eq '') {
14518: $docstitle = $title;
14519: }
1.1055 raeburn 14520: $outer = 0;
1.1056 raeburn 14521: if (ref($dirorder{$i}) eq 'ARRAY') {
14522: if (@{$dirorder{$i}} > 0) {
14523: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 14524: if ($env{'form.archive_'.$item} eq 'display') {
14525: $outer = $item;
14526: last;
14527: }
14528: }
14529: }
14530: }
14531: my ($errtext,$fatal) =
14532: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
14533: '/'.$folders{$outer}.'.'.
14534: $containers{$outer});
14535: next if ($fatal);
14536: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
14537: if ($context eq 'coursedocs') {
1.1056 raeburn 14538: $mapinner{$i} = time;
1.1055 raeburn 14539: $folders{$i} = 'default_'.$mapinner{$i};
14540: $containers{$i} = 'sequence';
14541: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14542: $folders{$i}.'.'.$containers{$i};
14543: my $newidx = &LONCAPA::map::getresidx();
14544: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 14545: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 14546: push(@LONCAPA::map::order,$newidx);
14547: my ($outtext,$errtext) =
14548: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14549: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 14550: '.'.$containers{$outer},1,1);
1.1056 raeburn 14551: $newseqid{$i} = $newidx;
1.1067 raeburn 14552: unless ($errtext) {
1.1294 raeburn 14553: $result .= '<li>'.&mt('Folder: [_1] added to course',
14554: &HTML::Entities::encode($docstitle,'<>&"')).
14555: '</li>'."\n";
1.1067 raeburn 14556: }
1.1055 raeburn 14557: }
14558: } else {
14559: if ($context eq 'coursedocs') {
14560: my $newidx=&LONCAPA::map::getresidx();
14561: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14562: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
14563: $title;
1.1392 raeburn 14564: if (($outer !~ /\D/) &&
14565: (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
14566: ($newidx !~ /\D/)) {
1.1294 raeburn 14567: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
14568: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
14569: }
14570: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14571: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
14572: }
14573: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14574: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
14575: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
14576: unless ($ishome) {
14577: my $fetch = "$newdest{$i}/$title";
14578: $fetch =~ s/^\Q$prefix$dir\E//;
14579: $prompttofetch{$fetch} = 1;
14580: }
1.1292 raeburn 14581: }
1.1067 raeburn 14582: }
1.1294 raeburn 14583: $LONCAPA::map::resources[$newidx]=
14584: $docstitle.':'.$url.':false:normal:res';
14585: push(@LONCAPA::map::order, $newidx);
14586: my ($outtext,$errtext)=
14587: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14588: $docuname.'/'.$folders{$outer}.
14589: '.'.$containers{$outer},1,1);
14590: unless ($errtext) {
14591: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
14592: $result .= '<li>'.&mt('File: [_1] added to course',
14593: &HTML::Entities::encode($docstitle,'<>&"')).
14594: '</li>'."\n";
14595: }
1.1067 raeburn 14596: }
1.1294 raeburn 14597: } else {
14598: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14599: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 14600: }
1.1055 raeburn 14601: }
14602: }
1.1086 raeburn 14603: }
14604: } else {
1.1294 raeburn 14605: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14606: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 14607: }
14608: }
14609: for (my $i=1; $i<=$numitems; $i++) {
14610: next unless ($env{'form.archive_'.$i} eq 'dependency');
14611: my $path = $env{'form.archive_content_'.$i};
14612: if ($path =~ /^\Q$pathtocheck\E/) {
14613: my ($title) = ($path =~ m{/([^/]+)$});
14614: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
14615: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
14616: if (ref($dirorder{$i}) eq 'ARRAY') {
14617: my ($itemidx,$fullpath,$relpath);
14618: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
14619: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 14620: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 14621: if ($dirorder{$i}->[$j] eq $container) {
14622: $itemidx = $j;
1.1056 raeburn 14623: }
14624: }
1.1086 raeburn 14625: }
14626: if ($itemidx eq '') {
14627: $itemidx = 0;
14628: }
14629: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
14630: if ($mapinner{$referrer{$i}}) {
14631: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
14632: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14633: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14634: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14635: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14636: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14637: if (!-e $fullpath) {
14638: mkdir($fullpath,0755);
1.1056 raeburn 14639: }
14640: }
1.1086 raeburn 14641: } else {
14642: last;
1.1056 raeburn 14643: }
1.1086 raeburn 14644: }
14645: }
14646: } elsif ($newdest{$referrer{$i}}) {
14647: $fullpath = $newdest{$referrer{$i}};
14648: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14649: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
14650: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
14651: last;
14652: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14653: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14654: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14655: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14656: if (!-e $fullpath) {
14657: mkdir($fullpath,0755);
1.1056 raeburn 14658: }
14659: }
1.1086 raeburn 14660: } else {
14661: last;
1.1056 raeburn 14662: }
1.1055 raeburn 14663: }
14664: }
1.1086 raeburn 14665: if ($fullpath ne '') {
14666: if (-e "$prefix$path") {
1.1292 raeburn 14667: unless (rename("$prefix$path","$fullpath/$title")) {
14668: $warning .= &mt('Failed to rename dependency').'<br />';
14669: }
1.1086 raeburn 14670: }
14671: if (-e "$fullpath/$title") {
14672: my $showpath;
14673: if ($relpath ne '') {
14674: $showpath = "$relpath/$title";
14675: } else {
14676: $showpath = "/$title";
14677: }
1.1294 raeburn 14678: $result .= '<li>'.&mt('[_1] included as a dependency',
14679: &HTML::Entities::encode($showpath,'<>&"')).
14680: '</li>'."\n";
1.1292 raeburn 14681: unless ($ishome) {
14682: my $fetch = "$fullpath/$title";
14683: $fetch =~ s/^\Q$prefix$dir\E//;
14684: $prompttofetch{$fetch} = 1;
14685: }
1.1086 raeburn 14686: }
14687: }
1.1055 raeburn 14688: }
1.1086 raeburn 14689: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
14690: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 14691: &HTML::Entities::encode($path,'<>&"'),
14692: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
14693: '<br />';
1.1055 raeburn 14694: }
14695: } else {
1.1294 raeburn 14696: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 14697: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 14698: }
14699: }
14700: if (keys(%todelete)) {
14701: foreach my $key (keys(%todelete)) {
14702: unlink($key);
1.1066 raeburn 14703: }
14704: }
14705: if (keys(%todeletedir)) {
14706: foreach my $key (keys(%todeletedir)) {
14707: rmdir($key);
14708: }
14709: }
14710: foreach my $dir (sort(keys(%is_dir))) {
14711: if (($pathtocheck ne '') && ($dir ne '')) {
14712: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 14713: }
14714: }
1.1067 raeburn 14715: if ($result ne '') {
14716: $output .= '<ul>'."\n".
14717: $result."\n".
14718: '</ul>';
14719: }
14720: unless ($ishome) {
14721: my $replicationfail;
14722: foreach my $item (keys(%prompttofetch)) {
14723: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
14724: unless ($fetchresult eq 'ok') {
14725: $replicationfail .= '<li>'.$item.'</li>'."\n";
14726: }
14727: }
14728: if ($replicationfail) {
14729: $output .= '<p class="LC_error">'.
14730: &mt('Course home server failed to retrieve:').'<ul>'.
14731: $replicationfail.
14732: '</ul></p>';
14733: }
14734: }
1.1055 raeburn 14735: } else {
14736: $warning = &mt('No items found in archive.');
14737: }
14738: if ($error) {
14739: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14740: $error.'</p>'."\n";
14741: }
14742: if ($warning) {
14743: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14744: }
14745: return $output;
14746: }
14747:
1.1066 raeburn 14748: sub cleanup_empty_dirs {
14749: my ($path) = @_;
14750: if (($path ne '') && (-d $path)) {
14751: if (opendir(my $dirh,$path)) {
14752: my @dircontents = grep(!/^\./,readdir($dirh));
14753: my $numitems = 0;
14754: foreach my $item (@dircontents) {
14755: if (-d "$path/$item") {
1.1111 raeburn 14756: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14757: if (-e "$path/$item") {
14758: $numitems ++;
14759: }
14760: } else {
14761: $numitems ++;
14762: }
14763: }
14764: if ($numitems == 0) {
14765: rmdir($path);
14766: }
14767: closedir($dirh);
14768: }
14769: }
14770: return;
14771: }
14772:
1.41 ng 14773: =pod
1.45 matthew 14774:
1.1162 raeburn 14775: =item * &get_folder_hierarchy()
1.1068 raeburn 14776:
14777: Provides hierarchy of names of folders/sub-folders containing the current
14778: item,
14779:
14780: Inputs: 3
14781: - $navmap - navmaps object
14782:
14783: - $map - url for map (either the trigger itself, or map containing
14784: the resource, which is the trigger).
14785:
14786: - $showitem - 1 => show title for map itself; 0 => do not show.
14787:
14788: Outputs: 1 @pathitems - array of folder/subfolder names.
14789:
14790: =cut
14791:
14792: sub get_folder_hierarchy {
14793: my ($navmap,$map,$showitem) = @_;
14794: my @pathitems;
14795: if (ref($navmap)) {
14796: my $mapres = $navmap->getResourceByUrl($map);
14797: if (ref($mapres)) {
14798: my $pcslist = $mapres->map_hierarchy();
14799: if ($pcslist ne '') {
14800: my @pcs = split(/,/,$pcslist);
14801: foreach my $pc (@pcs) {
14802: if ($pc == 1) {
1.1129 raeburn 14803: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14804: } else {
14805: my $res = $navmap->getByMapPc($pc);
14806: if (ref($res)) {
14807: my $title = $res->compTitle();
14808: $title =~ s/\W+/_/g;
14809: if ($title ne '') {
14810: push(@pathitems,$title);
14811: }
14812: }
14813: }
14814: }
14815: }
1.1071 raeburn 14816: if ($showitem) {
14817: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 14818: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14819: } else {
14820: my $maptitle = $mapres->compTitle();
14821: $maptitle =~ s/\W+/_/g;
14822: if ($maptitle ne '') {
14823: push(@pathitems,$maptitle);
14824: }
1.1068 raeburn 14825: }
14826: }
14827: }
14828: }
14829: return @pathitems;
14830: }
14831:
14832: =pod
14833:
1.1015 raeburn 14834: =item * &get_turnedin_filepath()
14835:
14836: Determines path in a user's portfolio file for storage of files uploaded
14837: to a specific essayresponse or dropbox item.
14838:
14839: Inputs: 3 required + 1 optional.
14840: $symb is symb for resource, $uname and $udom are for current user (required).
14841: $caller is optional (can be "submission", if routine is called when storing
14842: an upoaded file when "Submit Answer" button was pressed).
14843:
14844: Returns array containing $path and $multiresp.
14845: $path is path in portfolio. $multiresp is 1 if this resource contains more
14846: than one file upload item. Callers of routine should append partid as a
14847: subdirectory to $path in cases where $multiresp is 1.
14848:
14849: Called by: homework/essayresponse.pm and homework/structuretags.pm
14850:
14851: =cut
14852:
14853: sub get_turnedin_filepath {
14854: my ($symb,$uname,$udom,$caller) = @_;
14855: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14856: my $turnindir;
14857: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14858: $turnindir = $userhash{'turnindir'};
14859: my ($path,$multiresp);
14860: if ($turnindir eq '') {
14861: if ($caller eq 'submission') {
14862: $turnindir = &mt('turned in');
14863: $turnindir =~ s/\W+/_/g;
14864: my %newhash = (
14865: 'turnindir' => $turnindir,
14866: );
14867: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14868: }
14869: }
14870: if ($turnindir ne '') {
14871: $path = '/'.$turnindir.'/';
14872: my ($multipart,$turnin,@pathitems);
14873: my $navmap = Apache::lonnavmaps::navmap->new();
14874: if (defined($navmap)) {
14875: my $mapres = $navmap->getResourceByUrl($map);
14876: if (ref($mapres)) {
14877: my $pcslist = $mapres->map_hierarchy();
14878: if ($pcslist ne '') {
14879: foreach my $pc (split(/,/,$pcslist)) {
14880: my $res = $navmap->getByMapPc($pc);
14881: if (ref($res)) {
14882: my $title = $res->compTitle();
14883: $title =~ s/\W+/_/g;
14884: if ($title ne '') {
1.1149 raeburn 14885: if (($pc > 1) && (length($title) > 12)) {
14886: $title = substr($title,0,12);
14887: }
1.1015 raeburn 14888: push(@pathitems,$title);
14889: }
14890: }
14891: }
14892: }
14893: my $maptitle = $mapres->compTitle();
14894: $maptitle =~ s/\W+/_/g;
14895: if ($maptitle ne '') {
1.1149 raeburn 14896: if (length($maptitle) > 12) {
14897: $maptitle = substr($maptitle,0,12);
14898: }
1.1015 raeburn 14899: push(@pathitems,$maptitle);
14900: }
14901: unless ($env{'request.state'} eq 'construct') {
14902: my $res = $navmap->getBySymb($symb);
14903: if (ref($res)) {
14904: my $partlist = $res->parts();
14905: my $totaluploads = 0;
14906: if (ref($partlist) eq 'ARRAY') {
14907: foreach my $part (@{$partlist}) {
14908: my @types = $res->responseType($part);
14909: my @ids = $res->responseIds($part);
14910: for (my $i=0; $i < scalar(@ids); $i++) {
14911: if ($types[$i] eq 'essay') {
14912: my $partid = $part.'_'.$ids[$i];
14913: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14914: $totaluploads ++;
14915: }
14916: }
14917: }
14918: }
14919: if ($totaluploads > 1) {
14920: $multiresp = 1;
14921: }
14922: }
14923: }
14924: }
14925: } else {
14926: return;
14927: }
14928: } else {
14929: return;
14930: }
14931: my $restitle=&Apache::lonnet::gettitle($symb);
14932: $restitle =~ s/\W+/_/g;
14933: if ($restitle eq '') {
14934: $restitle = ($resurl =~ m{/[^/]+$});
14935: if ($restitle eq '') {
14936: $restitle = time;
14937: }
14938: }
1.1149 raeburn 14939: if (length($restitle) > 12) {
14940: $restitle = substr($restitle,0,12);
14941: }
1.1015 raeburn 14942: push(@pathitems,$restitle);
14943: $path .= join('/',@pathitems);
14944: }
14945: return ($path,$multiresp);
14946: }
14947:
14948: =pod
14949:
1.464 albertel 14950: =back
1.41 ng 14951:
1.112 bowersj2 14952: =head1 CSV Upload/Handling functions
1.38 albertel 14953:
1.41 ng 14954: =over 4
14955:
1.648 raeburn 14956: =item * &upfile_store($r)
1.41 ng 14957:
14958: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14959: needs $env{'form.upfile'}
1.41 ng 14960: returns $datatoken to be put into hidden field
14961:
14962: =cut
1.31 albertel 14963:
14964: sub upfile_store {
14965: my $r=shift;
1.258 albertel 14966: $env{'form.upfile'}=~s/\r/\n/gs;
14967: $env{'form.upfile'}=~s/\f/\n/gs;
14968: $env{'form.upfile'}=~s/\n+/\n/gs;
14969: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14970:
1.1299 raeburn 14971: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14972: '_enroll_'.$env{'request.course.id'}.'_'.
14973: time.'_'.$$);
14974: return if ($datatoken eq '');
14975:
1.31 albertel 14976: {
1.158 raeburn 14977: my $datafile = $r->dir_config('lonDaemons').
14978: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14979: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14980: print $fh $env{'form.upfile'};
1.158 raeburn 14981: close($fh);
14982: }
1.31 albertel 14983: }
14984: return $datatoken;
14985: }
14986:
1.56 matthew 14987: =pod
14988:
1.1290 raeburn 14989: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14990:
14991: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14992: $datatoken is the name to assign to the temporary file.
1.258 albertel 14993: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14994:
14995: =cut
1.31 albertel 14996:
14997: sub load_tmp_file {
1.1290 raeburn 14998: my ($r,$datatoken) = @_;
14999: return if ($datatoken eq '');
1.31 albertel 15000: my @studentdata=();
15001: {
1.158 raeburn 15002: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 15003: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 15004: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 15005: @studentdata=<$fh>;
15006: close($fh);
15007: }
1.31 albertel 15008: }
1.258 albertel 15009: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 15010: }
15011:
1.1290 raeburn 15012: sub valid_datatoken {
15013: my ($datatoken) = @_;
1.1325 raeburn 15014: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 15015: return $datatoken;
15016: }
15017: return;
15018: }
15019:
1.56 matthew 15020: =pod
15021:
1.648 raeburn 15022: =item * &upfile_record_sep()
1.41 ng 15023:
15024: Separate uploaded file into records
15025: returns array of records,
1.258 albertel 15026: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 15027:
15028: =cut
1.31 albertel 15029:
15030: sub upfile_record_sep {
1.258 albertel 15031: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 15032: } else {
1.248 albertel 15033: my @records;
1.258 albertel 15034: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 15035: if ($line=~/^\s*$/) { next; }
15036: push(@records,$line);
15037: }
15038: return @records;
1.31 albertel 15039: }
15040: }
15041:
1.56 matthew 15042: =pod
15043:
1.648 raeburn 15044: =item * &record_sep($record)
1.41 ng 15045:
1.258 albertel 15046: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 15047:
15048: =cut
15049:
1.263 www 15050: sub takeleft {
15051: my $index=shift;
15052: return substr('0000'.$index,-4,4);
15053: }
15054:
1.31 albertel 15055: sub record_sep {
15056: my $record=shift;
15057: my %components=();
1.258 albertel 15058: if ($env{'form.upfiletype'} eq 'xml') {
15059: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 15060: my $i=0;
1.356 albertel 15061: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 15062: $field=~s/^(\"|\')//;
15063: $field=~s/(\"|\')$//;
1.263 www 15064: $components{&takeleft($i)}=$field;
1.31 albertel 15065: $i++;
15066: }
1.258 albertel 15067: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 15068: my $i=0;
1.356 albertel 15069: foreach my $field (split(/\t/,$record)) {
1.31 albertel 15070: $field=~s/^(\"|\')//;
15071: $field=~s/(\"|\')$//;
1.263 www 15072: $components{&takeleft($i)}=$field;
1.31 albertel 15073: $i++;
15074: }
15075: } else {
1.561 www 15076: my $separator=',';
1.480 banghart 15077: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 15078: $separator=';';
1.480 banghart 15079: }
1.31 albertel 15080: my $i=0;
1.561 www 15081: # the character we are looking for to indicate the end of a quote or a record
15082: my $looking_for=$separator;
15083: # do not add the characters to the fields
15084: my $ignore=0;
15085: # we just encountered a separator (or the beginning of the record)
15086: my $just_found_separator=1;
15087: # store the field we are working on here
15088: my $field='';
15089: # work our way through all characters in record
15090: foreach my $character ($record=~/(.)/g) {
15091: if ($character eq $looking_for) {
15092: if ($character ne $separator) {
15093: # Found the end of a quote, again looking for separator
15094: $looking_for=$separator;
15095: $ignore=1;
15096: } else {
15097: # Found a separator, store away what we got
15098: $components{&takeleft($i)}=$field;
15099: $i++;
15100: $just_found_separator=1;
15101: $ignore=0;
15102: $field='';
15103: }
15104: next;
15105: }
15106: # single or double quotation marks after a separator indicate beginning of a quote
15107: # we are now looking for the end of the quote and need to ignore separators
15108: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
15109: $looking_for=$character;
15110: next;
15111: }
15112: # ignore would be true after we reached the end of a quote
15113: if ($ignore) { next; }
15114: if (($just_found_separator) && ($character=~/\s/)) { next; }
15115: $field.=$character;
15116: $just_found_separator=0;
1.31 albertel 15117: }
1.561 www 15118: # catch the very last entry, since we never encountered the separator
15119: $components{&takeleft($i)}=$field;
1.31 albertel 15120: }
15121: return %components;
15122: }
15123:
1.144 matthew 15124: ######################################################
15125: ######################################################
15126:
1.56 matthew 15127: =pod
15128:
1.648 raeburn 15129: =item * &upfile_select_html()
1.41 ng 15130:
1.144 matthew 15131: Return HTML code to select a file from the users machine and specify
15132: the file type.
1.41 ng 15133:
15134: =cut
15135:
1.144 matthew 15136: ######################################################
15137: ######################################################
1.31 albertel 15138: sub upfile_select_html {
1.144 matthew 15139: my %Types = (
15140: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 15141: semisv => &mt('Semicolon separated values'),
1.144 matthew 15142: space => &mt('Space separated'),
15143: tab => &mt('Tabulator separated'),
15144: # xml => &mt('HTML/XML'),
15145: );
15146: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 15147: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 15148: foreach my $type (sort(keys(%Types))) {
15149: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
15150: }
15151: $Str .= "</select>\n";
15152: return $Str;
1.31 albertel 15153: }
15154:
1.301 albertel 15155: sub get_samples {
15156: my ($records,$toget) = @_;
15157: my @samples=({});
15158: my $got=0;
15159: foreach my $rec (@$records) {
15160: my %temp = &record_sep($rec);
15161: if (! grep(/\S/, values(%temp))) { next; }
15162: if (%temp) {
15163: $samples[$got]=\%temp;
15164: $got++;
15165: if ($got == $toget) { last; }
15166: }
15167: }
15168: return \@samples;
15169: }
15170:
1.144 matthew 15171: ######################################################
15172: ######################################################
15173:
1.56 matthew 15174: =pod
15175:
1.648 raeburn 15176: =item * &csv_print_samples($r,$records)
1.41 ng 15177:
15178: Prints a table of sample values from each column uploaded $r is an
15179: Apache Request ref, $records is an arrayref from
15180: &Apache::loncommon::upfile_record_sep
15181:
15182: =cut
15183:
1.144 matthew 15184: ######################################################
15185: ######################################################
1.31 albertel 15186: sub csv_print_samples {
15187: my ($r,$records) = @_;
1.662 bisitz 15188: my $samples = &get_samples($records,5);
1.301 albertel 15189:
1.594 raeburn 15190: $r->print(&mt('Samples').'<br />'.&start_data_table().
15191: &start_data_table_header_row());
1.356 albertel 15192: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 15193: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 15194: $r->print(&end_data_table_header_row());
1.301 albertel 15195: foreach my $hash (@$samples) {
1.594 raeburn 15196: $r->print(&start_data_table_row());
1.356 albertel 15197: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 15198: $r->print('<td>');
1.356 albertel 15199: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 15200: $r->print('</td>');
15201: }
1.594 raeburn 15202: $r->print(&end_data_table_row());
1.31 albertel 15203: }
1.594 raeburn 15204: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 15205: }
15206:
1.144 matthew 15207: ######################################################
15208: ######################################################
15209:
1.56 matthew 15210: =pod
15211:
1.648 raeburn 15212: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 15213:
15214: Prints a table to create associations between values and table columns.
1.144 matthew 15215:
1.41 ng 15216: $r is an Apache Request ref,
15217: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 15218: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 15219:
15220: =cut
15221:
1.144 matthew 15222: ######################################################
15223: ######################################################
1.31 albertel 15224: sub csv_print_select_table {
15225: my ($r,$records,$d) = @_;
1.301 albertel 15226: my $i=0;
15227: my $samples = &get_samples($records,1);
1.144 matthew 15228: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 15229: &start_data_table().&start_data_table_header_row().
1.144 matthew 15230: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 15231: '<th>'.&mt('Column').'</th>'.
15232: &end_data_table_header_row()."\n");
1.356 albertel 15233: foreach my $array_ref (@$d) {
15234: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 15235: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 15236:
1.875 bisitz 15237: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 15238: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 15239: $r->print('<option value="none"></option>');
1.356 albertel 15240: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
15241: $r->print('<option value="'.$sample.'"'.
15242: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 15243: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 15244: }
1.594 raeburn 15245: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 15246: $i++;
15247: }
1.594 raeburn 15248: $r->print(&end_data_table());
1.31 albertel 15249: $i--;
15250: return $i;
15251: }
1.56 matthew 15252:
1.144 matthew 15253: ######################################################
15254: ######################################################
15255:
1.56 matthew 15256: =pod
1.31 albertel 15257:
1.648 raeburn 15258: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 15259:
15260: Prints a table of sample values from the upload and can make associate samples to internal names.
15261:
15262: $r is an Apache Request ref,
15263: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
15264: $d is an array of 2 element arrays (internal name, displayed name)
15265:
15266: =cut
15267:
1.144 matthew 15268: ######################################################
15269: ######################################################
1.31 albertel 15270: sub csv_samples_select_table {
15271: my ($r,$records,$d) = @_;
15272: my $i=0;
1.144 matthew 15273: #
1.662 bisitz 15274: my $max_samples = 5;
15275: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 15276: $r->print(&start_data_table().
15277: &start_data_table_header_row().'<th>'.
15278: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
15279: &end_data_table_header_row());
1.301 albertel 15280:
15281: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 15282: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 15283: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 15284: foreach my $option (@$d) {
15285: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 15286: $r->print('<option value="'.$value.'"'.
1.253 albertel 15287: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 15288: $display.'</option>');
1.31 albertel 15289: }
15290: $r->print('</select></td><td>');
1.662 bisitz 15291: foreach my $line (0..($max_samples-1)) {
1.301 albertel 15292: if (defined($samples->[$line]{$key})) {
15293: $r->print($samples->[$line]{$key}."<br />\n");
15294: }
15295: }
1.594 raeburn 15296: $r->print('</td>'.&end_data_table_row());
1.31 albertel 15297: $i++;
15298: }
1.594 raeburn 15299: $r->print(&end_data_table());
1.31 albertel 15300: $i--;
15301: return($i);
1.115 matthew 15302: }
15303:
1.144 matthew 15304: ######################################################
15305: ######################################################
15306:
1.115 matthew 15307: =pod
15308:
1.648 raeburn 15309: =item * &clean_excel_name($name)
1.115 matthew 15310:
15311: Returns a replacement for $name which does not contain any illegal characters.
15312:
15313: =cut
15314:
1.144 matthew 15315: ######################################################
15316: ######################################################
1.115 matthew 15317: sub clean_excel_name {
15318: my ($name) = @_;
15319: $name =~ s/[:\*\?\/\\]//g;
15320: if (length($name) > 31) {
15321: $name = substr($name,0,31);
15322: }
15323: return $name;
1.25 albertel 15324: }
1.84 albertel 15325:
1.85 albertel 15326: =pod
15327:
1.648 raeburn 15328: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 15329:
15330: Returns either 1 or undef
15331:
15332: 1 if the part is to be hidden, undef if it is to be shown
15333:
15334: Arguments are:
15335:
15336: $id the id of the part to be checked
15337: $symb, optional the symb of the resource to check
15338: $udom, optional the domain of the user to check for
15339: $uname, optional the username of the user to check for
15340:
15341: =cut
1.84 albertel 15342:
15343: sub check_if_partid_hidden {
15344: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 15345: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 15346: $symb,$udom,$uname);
1.141 albertel 15347: my $truth=1;
15348: #if the string starts with !, then the list is the list to show not hide
15349: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 15350: my @hiddenlist=split(/,/,$hiddenparts);
15351: foreach my $checkid (@hiddenlist) {
1.141 albertel 15352: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 15353: }
1.141 albertel 15354: return !$truth;
1.84 albertel 15355: }
1.127 matthew 15356:
1.138 matthew 15357:
15358: ############################################################
15359: ############################################################
15360:
15361: =pod
15362:
1.157 matthew 15363: =back
15364:
1.138 matthew 15365: =head1 cgi-bin script and graphing routines
15366:
1.157 matthew 15367: =over 4
15368:
1.648 raeburn 15369: =item * &get_cgi_id()
1.138 matthew 15370:
15371: Inputs: none
15372:
15373: Returns an id which can be used to pass environment variables
15374: to various cgi-bin scripts. These environment variables will
15375: be removed from the users environment after a given time by
15376: the routine &Apache::lonnet::transfer_profile_to_env.
15377:
15378: =cut
15379:
15380: ############################################################
15381: ############################################################
1.152 albertel 15382: my $uniq=0;
1.136 matthew 15383: sub get_cgi_id {
1.154 albertel 15384: $uniq=($uniq+1)%100000;
1.280 albertel 15385: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 15386: }
15387:
1.127 matthew 15388: ############################################################
15389: ############################################################
15390:
15391: =pod
15392:
1.648 raeburn 15393: =item * &DrawBarGraph()
1.127 matthew 15394:
1.138 matthew 15395: Facilitates the plotting of data in a (stacked) bar graph.
15396: Puts plot definition data into the users environment in order for
15397: graph.png to plot it. Returns an <img> tag for the plot.
15398: The bars on the plot are labeled '1','2',...,'n'.
15399:
15400: Inputs:
15401:
15402: =over 4
15403:
15404: =item $Title: string, the title of the plot
15405:
15406: =item $xlabel: string, text describing the X-axis of the plot
15407:
15408: =item $ylabel: string, text describing the Y-axis of the plot
15409:
15410: =item $Max: scalar, the maximum Y value to use in the plot
15411: If $Max is < any data point, the graph will not be rendered.
15412:
1.140 matthew 15413: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 15414: they are plotted. If undefined, default values will be used.
15415:
1.178 matthew 15416: =item $labels: array ref holding the labels to use on the x-axis for the bars.
15417:
1.138 matthew 15418: =item @Values: An array of array references. Each array reference holds data
15419: to be plotted in a stacked bar chart.
15420:
1.239 matthew 15421: =item If the final element of @Values is a hash reference the key/value
15422: pairs will be added to the graph definition.
15423:
1.138 matthew 15424: =back
15425:
15426: Returns:
15427:
15428: An <img> tag which references graph.png and the appropriate identifying
15429: information for the plot.
15430:
1.127 matthew 15431: =cut
15432:
15433: ############################################################
15434: ############################################################
1.134 matthew 15435: sub DrawBarGraph {
1.178 matthew 15436: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 15437: #
15438: if (! defined($colors)) {
15439: $colors = ['#33ff00',
15440: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
15441: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
15442: ];
15443: }
1.228 matthew 15444: my $extra_settings = {};
15445: if (ref($Values[-1]) eq 'HASH') {
15446: $extra_settings = pop(@Values);
15447: }
1.127 matthew 15448: #
1.136 matthew 15449: my $identifier = &get_cgi_id();
15450: my $id = 'cgi.'.$identifier;
1.129 matthew 15451: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 15452: return '';
15453: }
1.225 matthew 15454: #
15455: my @Labels;
15456: if (defined($labels)) {
15457: @Labels = @$labels;
15458: } else {
15459: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 15460: push(@Labels,$i+1);
1.225 matthew 15461: }
15462: }
15463: #
1.129 matthew 15464: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 15465: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 15466: my %ValuesHash;
15467: my $NumSets=1;
15468: foreach my $array (@Values) {
15469: next if (! ref($array));
1.136 matthew 15470: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 15471: join(',',@$array);
1.129 matthew 15472: }
1.127 matthew 15473: #
1.136 matthew 15474: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 15475: if ($NumBars < 3) {
15476: $width = 120+$NumBars*32;
1.220 matthew 15477: $xskip = 1;
1.225 matthew 15478: $bar_width = 30;
15479: } elsif ($NumBars < 5) {
15480: $width = 120+$NumBars*20;
15481: $xskip = 1;
15482: $bar_width = 20;
1.220 matthew 15483: } elsif ($NumBars < 10) {
1.136 matthew 15484: $width = 120+$NumBars*15;
15485: $xskip = 1;
15486: $bar_width = 15;
15487: } elsif ($NumBars <= 25) {
15488: $width = 120+$NumBars*11;
15489: $xskip = 5;
15490: $bar_width = 8;
15491: } elsif ($NumBars <= 50) {
15492: $width = 120+$NumBars*8;
15493: $xskip = 5;
15494: $bar_width = 4;
15495: } else {
15496: $width = 120+$NumBars*8;
15497: $xskip = 5;
15498: $bar_width = 4;
15499: }
15500: #
1.137 matthew 15501: $Max = 1 if ($Max < 1);
15502: if ( int($Max) < $Max ) {
15503: $Max++;
15504: $Max = int($Max);
15505: }
1.127 matthew 15506: $Title = '' if (! defined($Title));
15507: $xlabel = '' if (! defined($xlabel));
15508: $ylabel = '' if (! defined($ylabel));
1.369 www 15509: $ValuesHash{$id.'.title'} = &escape($Title);
15510: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
15511: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 15512: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 15513: $ValuesHash{$id.'.NumBars'} = $NumBars;
15514: $ValuesHash{$id.'.NumSets'} = $NumSets;
15515: $ValuesHash{$id.'.PlotType'} = 'bar';
15516: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15517: $ValuesHash{$id.'.height'} = $height;
15518: $ValuesHash{$id.'.width'} = $width;
15519: $ValuesHash{$id.'.xskip'} = $xskip;
15520: $ValuesHash{$id.'.bar_width'} = $bar_width;
15521: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 15522: #
1.228 matthew 15523: # Deal with other parameters
15524: while (my ($key,$value) = each(%$extra_settings)) {
15525: $ValuesHash{$id.'.'.$key} = $value;
15526: }
15527: #
1.646 raeburn 15528: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 15529: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15530: }
15531:
15532: ############################################################
15533: ############################################################
15534:
15535: =pod
15536:
1.648 raeburn 15537: =item * &DrawXYGraph()
1.137 matthew 15538:
1.138 matthew 15539: Facilitates the plotting of data in an XY graph.
15540: Puts plot definition data into the users environment in order for
15541: graph.png to plot it. Returns an <img> tag for the plot.
15542:
15543: Inputs:
15544:
15545: =over 4
15546:
15547: =item $Title: string, the title of the plot
15548:
15549: =item $xlabel: string, text describing the X-axis of the plot
15550:
15551: =item $ylabel: string, text describing the Y-axis of the plot
15552:
15553: =item $Max: scalar, the maximum Y value to use in the plot
15554: If $Max is < any data point, the graph will not be rendered.
15555:
15556: =item $colors: Array ref containing the hex color codes for the data to be
15557: plotted in. If undefined, default values will be used.
15558:
15559: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15560:
15561: =item $Ydata: Array ref containing Array refs.
1.185 www 15562: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 15563:
15564: =item %Values: hash indicating or overriding any default values which are
15565: passed to graph.png.
15566: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15567:
15568: =back
15569:
15570: Returns:
15571:
15572: An <img> tag which references graph.png and the appropriate identifying
15573: information for the plot.
15574:
1.137 matthew 15575: =cut
15576:
15577: ############################################################
15578: ############################################################
15579: sub DrawXYGraph {
15580: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
15581: #
15582: # Create the identifier for the graph
15583: my $identifier = &get_cgi_id();
15584: my $id = 'cgi.'.$identifier;
15585: #
15586: $Title = '' if (! defined($Title));
15587: $xlabel = '' if (! defined($xlabel));
15588: $ylabel = '' if (! defined($ylabel));
15589: my %ValuesHash =
15590: (
1.369 www 15591: $id.'.title' => &escape($Title),
15592: $id.'.xlabel' => &escape($xlabel),
15593: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 15594: $id.'.y_max_value'=> $Max,
15595: $id.'.labels' => join(',',@$Xlabels),
15596: $id.'.PlotType' => 'XY',
15597: );
15598: #
15599: if (defined($colors) && ref($colors) eq 'ARRAY') {
15600: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15601: }
15602: #
15603: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
15604: return '';
15605: }
15606: my $NumSets=1;
1.138 matthew 15607: foreach my $array (@{$Ydata}){
1.137 matthew 15608: next if (! ref($array));
15609: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
15610: }
1.138 matthew 15611: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 15612: #
15613: # Deal with other parameters
15614: while (my ($key,$value) = each(%Values)) {
15615: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 15616: }
15617: #
1.646 raeburn 15618: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 15619: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15620: }
15621:
15622: ############################################################
15623: ############################################################
15624:
15625: =pod
15626:
1.648 raeburn 15627: =item * &DrawXYYGraph()
1.138 matthew 15628:
15629: Facilitates the plotting of data in an XY graph with two Y axes.
15630: Puts plot definition data into the users environment in order for
15631: graph.png to plot it. Returns an <img> tag for the plot.
15632:
15633: Inputs:
15634:
15635: =over 4
15636:
15637: =item $Title: string, the title of the plot
15638:
15639: =item $xlabel: string, text describing the X-axis of the plot
15640:
15641: =item $ylabel: string, text describing the Y-axis of the plot
15642:
15643: =item $colors: Array ref containing the hex color codes for the data to be
15644: plotted in. If undefined, default values will be used.
15645:
15646: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15647:
15648: =item $Ydata1: The first data set
15649:
15650: =item $Min1: The minimum value of the left Y-axis
15651:
15652: =item $Max1: The maximum value of the left Y-axis
15653:
15654: =item $Ydata2: The second data set
15655:
15656: =item $Min2: The minimum value of the right Y-axis
15657:
15658: =item $Max2: The maximum value of the left Y-axis
15659:
15660: =item %Values: hash indicating or overriding any default values which are
15661: passed to graph.png.
15662: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15663:
15664: =back
15665:
15666: Returns:
15667:
15668: An <img> tag which references graph.png and the appropriate identifying
15669: information for the plot.
1.136 matthew 15670:
15671: =cut
15672:
15673: ############################################################
15674: ############################################################
1.137 matthew 15675: sub DrawXYYGraph {
15676: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
15677: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 15678: #
15679: # Create the identifier for the graph
15680: my $identifier = &get_cgi_id();
15681: my $id = 'cgi.'.$identifier;
15682: #
15683: $Title = '' if (! defined($Title));
15684: $xlabel = '' if (! defined($xlabel));
15685: $ylabel = '' if (! defined($ylabel));
15686: my %ValuesHash =
15687: (
1.369 www 15688: $id.'.title' => &escape($Title),
15689: $id.'.xlabel' => &escape($xlabel),
15690: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 15691: $id.'.labels' => join(',',@$Xlabels),
15692: $id.'.PlotType' => 'XY',
15693: $id.'.NumSets' => 2,
1.137 matthew 15694: $id.'.two_axes' => 1,
15695: $id.'.y1_max_value' => $Max1,
15696: $id.'.y1_min_value' => $Min1,
15697: $id.'.y2_max_value' => $Max2,
15698: $id.'.y2_min_value' => $Min2,
1.136 matthew 15699: );
15700: #
1.137 matthew 15701: if (defined($colors) && ref($colors) eq 'ARRAY') {
15702: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15703: }
15704: #
15705: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
15706: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 15707: return '';
15708: }
15709: my $NumSets=1;
1.137 matthew 15710: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 15711: next if (! ref($array));
15712: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 15713: }
15714: #
15715: # Deal with other parameters
15716: while (my ($key,$value) = each(%Values)) {
15717: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 15718: }
15719: #
1.646 raeburn 15720: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 15721: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 15722: }
15723:
15724: ############################################################
15725: ############################################################
15726:
15727: =pod
15728:
1.157 matthew 15729: =back
15730:
1.139 matthew 15731: =head1 Statistics helper routines?
15732:
15733: Bad place for them but what the hell.
15734:
1.157 matthew 15735: =over 4
15736:
1.648 raeburn 15737: =item * &chartlink()
1.139 matthew 15738:
15739: Returns a link to the chart for a specific student.
15740:
15741: Inputs:
15742:
15743: =over 4
15744:
15745: =item $linktext: The text of the link
15746:
15747: =item $sname: The students username
15748:
15749: =item $sdomain: The students domain
15750:
15751: =back
15752:
1.157 matthew 15753: =back
15754:
1.139 matthew 15755: =cut
15756:
15757: ############################################################
15758: ############################################################
15759: sub chartlink {
15760: my ($linktext, $sname, $sdomain) = @_;
15761: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15762: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15763: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15764: '">'.$linktext.'</a>';
1.153 matthew 15765: }
15766:
15767: #######################################################
15768: #######################################################
15769:
15770: =pod
15771:
15772: =head1 Course Environment Routines
1.157 matthew 15773:
15774: =over 4
1.153 matthew 15775:
1.648 raeburn 15776: =item * &restore_course_settings()
1.153 matthew 15777:
1.648 raeburn 15778: =item * &store_course_settings()
1.153 matthew 15779:
15780: Restores/Store indicated form parameters from the course environment.
15781: Will not overwrite existing values of the form parameters.
15782:
15783: Inputs:
15784: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15785:
15786: a hash ref describing the data to be stored. For example:
15787:
15788: %Save_Parameters = ('Status' => 'scalar',
15789: 'chartoutputmode' => 'scalar',
15790: 'chartoutputdata' => 'scalar',
15791: 'Section' => 'array',
1.373 raeburn 15792: 'Group' => 'array',
1.153 matthew 15793: 'StudentData' => 'array',
15794: 'Maps' => 'array');
15795:
15796: Returns: both routines return nothing
15797:
1.631 raeburn 15798: =back
15799:
1.153 matthew 15800: =cut
15801:
15802: #######################################################
15803: #######################################################
15804: sub store_course_settings {
1.496 albertel 15805: return &store_settings($env{'request.course.id'},@_);
15806: }
15807:
15808: sub store_settings {
1.153 matthew 15809: # save to the environment
15810: # appenv the same items, just to be safe
1.300 albertel 15811: my $udom = $env{'user.domain'};
15812: my $uname = $env{'user.name'};
1.496 albertel 15813: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15814: my %SaveHash;
15815: my %AppHash;
15816: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15817: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15818: my $envname = 'environment.'.$basename;
1.258 albertel 15819: if (exists($env{'form.'.$setting})) {
1.153 matthew 15820: # Save this value away
15821: if ($type eq 'scalar' &&
1.258 albertel 15822: (! exists($env{$envname}) ||
15823: $env{$envname} ne $env{'form.'.$setting})) {
15824: $SaveHash{$basename} = $env{'form.'.$setting};
15825: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15826: } elsif ($type eq 'array') {
15827: my $stored_form;
1.258 albertel 15828: if (ref($env{'form.'.$setting})) {
1.153 matthew 15829: $stored_form = join(',',
15830: map {
1.369 www 15831: &escape($_);
1.258 albertel 15832: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15833: } else {
15834: $stored_form =
1.369 www 15835: &escape($env{'form.'.$setting});
1.153 matthew 15836: }
15837: # Determine if the array contents are the same.
1.258 albertel 15838: if ($stored_form ne $env{$envname}) {
1.153 matthew 15839: $SaveHash{$basename} = $stored_form;
15840: $AppHash{$envname} = $stored_form;
15841: }
15842: }
15843: }
15844: }
15845: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15846: $udom,$uname);
1.153 matthew 15847: if ($put_result !~ /^(ok|delayed)/) {
15848: &Apache::lonnet::logthis('unable to save form parameters, '.
15849: 'got error:'.$put_result);
15850: }
15851: # Make sure these settings stick around in this session, too
1.646 raeburn 15852: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15853: return;
15854: }
15855:
15856: sub restore_course_settings {
1.499 albertel 15857: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15858: }
15859:
15860: sub restore_settings {
15861: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15862: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15863: next if (exists($env{'form.'.$setting}));
1.496 albertel 15864: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15865: '.'.$setting;
1.258 albertel 15866: if (exists($env{$envname})) {
1.153 matthew 15867: if ($type eq 'scalar') {
1.258 albertel 15868: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15869: } elsif ($type eq 'array') {
1.258 albertel 15870: $env{'form.'.$setting} = [
1.153 matthew 15871: map {
1.369 www 15872: &unescape($_);
1.258 albertel 15873: } split(',',$env{$envname})
1.153 matthew 15874: ];
15875: }
15876: }
15877: }
1.127 matthew 15878: }
15879:
1.618 raeburn 15880: #######################################################
15881: #######################################################
15882:
15883: =pod
15884:
15885: =head1 Domain E-mail Routines
15886:
15887: =over 4
15888:
1.648 raeburn 15889: =item * &build_recipient_list()
1.618 raeburn 15890:
1.1144 raeburn 15891: Build recipient lists for following types of e-mail:
1.766 raeburn 15892: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 15893: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15894: module change checking, student/employee ID conflict checks, as
15895: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15896: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15897:
15898: Inputs:
1.619 raeburn 15899: defmail (scalar - email address of default recipient),
1.1144 raeburn 15900: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15901: requestsmail, updatesmail, or idconflictsmail).
15902:
1.619 raeburn 15903: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 15904:
1.619 raeburn 15905: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 15906: i.e., predates configuration by DC via domainprefs.pm
15907:
15908: $requname username of requester (if mailing type is helpdeskmail)
15909:
15910: $requdom domain of requester (if mailing type is helpdeskmail)
15911:
15912: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15913:
1.618 raeburn 15914:
1.655 raeburn 15915: Returns: comma separated list of addresses to which to send e-mail.
15916:
15917: =back
1.618 raeburn 15918:
15919: =cut
15920:
15921: ############################################################
15922: ############################################################
15923: sub build_recipient_list {
1.1297 raeburn 15924: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15925: my @recipients;
1.1270 raeburn 15926: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15927: my %domconfig =
1.1270 raeburn 15928: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15929: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15930: if (exists($domconfig{'contacts'}{$mailing})) {
15931: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15932: my @contacts = ('adminemail','supportemail');
15933: foreach my $item (@contacts) {
15934: if ($domconfig{'contacts'}{$mailing}{$item}) {
15935: my $addr = $domconfig{'contacts'}{$item};
15936: if (!grep(/^\Q$addr\E$/,@recipients)) {
15937: push(@recipients,$addr);
15938: }
1.619 raeburn 15939: }
1.1270 raeburn 15940: }
15941: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15942: if ($mailing eq 'helpdeskmail') {
15943: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15944: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15945: my @ok_bccs;
15946: foreach my $bcc (@bccs) {
15947: $bcc =~ s/^\s+//g;
15948: $bcc =~ s/\s+$//g;
15949: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15950: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15951: push(@ok_bccs,$bcc);
15952: }
15953: }
15954: }
15955: if (@ok_bccs > 0) {
15956: $allbcc = join(', ',@ok_bccs);
15957: }
15958: }
15959: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15960: }
15961: }
1.766 raeburn 15962: } elsif ($origmail ne '') {
1.1270 raeburn 15963: $lastresort = $origmail;
1.618 raeburn 15964: }
1.1297 raeburn 15965: if ($mailing eq 'helpdeskmail') {
15966: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15967: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15968: my ($inststatus,$inststatus_checked);
15969: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15970: ($env{'user.domain'} ne 'public')) {
15971: $inststatus_checked = 1;
15972: $inststatus = $env{'environment.inststatus'};
15973: }
15974: unless ($inststatus_checked) {
15975: if (($requname ne '') && ($requdom ne '')) {
15976: if (($requname =~ /^$match_username$/) &&
15977: ($requdom =~ /^$match_domain$/) &&
15978: (&Apache::lonnet::domain($requdom))) {
15979: my $requhome = &Apache::lonnet::homeserver($requname,
15980: $requdom);
15981: unless ($requhome eq 'no_host') {
15982: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15983: $inststatus = $userenv{'inststatus'};
15984: $inststatus_checked = 1;
15985: }
15986: }
15987: }
15988: }
15989: unless ($inststatus_checked) {
15990: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15991: my %srch = (srchby => 'email',
15992: srchdomain => $defdom,
15993: srchterm => $reqemail,
15994: srchtype => 'exact');
15995: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15996: foreach my $uname (keys(%srch_results)) {
15997: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15998: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15999: $inststatus_checked = 1;
16000: last;
16001: }
16002: }
16003: unless ($inststatus_checked) {
16004: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
16005: if ($dirsrchres eq 'ok') {
16006: foreach my $uname (keys(%srch_results)) {
16007: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
16008: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
16009: $inststatus_checked = 1;
16010: last;
16011: }
16012: }
16013: }
16014: }
16015: }
16016: }
16017: if ($inststatus ne '') {
16018: foreach my $status (split(/\:/,$inststatus)) {
16019: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
16020: my @contacts = ('adminemail','supportemail');
16021: foreach my $item (@contacts) {
16022: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
16023: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
16024: if (!grep(/^\Q$addr\E$/,@recipients)) {
16025: push(@recipients,$addr);
16026: }
16027: }
16028: }
16029: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
16030: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
16031: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
16032: my @ok_bccs;
16033: foreach my $bcc (@bccs) {
16034: $bcc =~ s/^\s+//g;
16035: $bcc =~ s/\s+$//g;
16036: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16037: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16038: push(@ok_bccs,$bcc);
16039: }
16040: }
16041: }
16042: if (@ok_bccs > 0) {
16043: $allbcc = join(', ',@ok_bccs);
16044: }
16045: }
16046: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
16047: last;
16048: }
16049: }
16050: }
16051: }
16052: }
1.619 raeburn 16053: } elsif ($origmail ne '') {
1.1270 raeburn 16054: $lastresort = $origmail;
16055: }
1.1297 raeburn 16056: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 16057: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
16058: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
16059: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
16060: my %what = (
16061: perlvar => 1,
16062: );
16063: my $primary = &Apache::lonnet::domain($defdom,'primary');
16064: if ($primary) {
16065: my $gotaddr;
16066: my ($result,$returnhash) =
16067: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
16068: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
16069: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
16070: $lastresort = $returnhash->{'lonSupportEMail'};
16071: $gotaddr = 1;
16072: }
16073: }
16074: unless ($gotaddr) {
16075: my $uintdom = &Apache::lonnet::internet_dom($primary);
16076: my $intdom = &Apache::lonnet::internet_dom($lonhost);
16077: unless ($uintdom eq $intdom) {
16078: my %domconfig =
16079: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
16080: if (ref($domconfig{'contacts'}) eq 'HASH') {
16081: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
16082: my @contacts = ('adminemail','supportemail');
16083: foreach my $item (@contacts) {
16084: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
16085: my $addr = $domconfig{'contacts'}{$item};
16086: if (!grep(/^\Q$addr\E$/,@recipients)) {
16087: push(@recipients,$addr);
16088: }
16089: }
16090: }
16091: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
16092: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
16093: }
16094: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
16095: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
16096: my @ok_bccs;
16097: foreach my $bcc (@bccs) {
16098: $bcc =~ s/^\s+//g;
16099: $bcc =~ s/\s+$//g;
16100: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16101: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16102: push(@ok_bccs,$bcc);
16103: }
16104: }
16105: }
16106: if (@ok_bccs > 0) {
16107: $allbcc = join(', ',@ok_bccs);
16108: }
16109: }
16110: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
16111: }
16112: }
16113: }
16114: }
16115: }
16116: }
1.618 raeburn 16117: }
1.688 raeburn 16118: if (defined($defmail)) {
16119: if ($defmail ne '') {
16120: push(@recipients,$defmail);
16121: }
1.618 raeburn 16122: }
16123: if ($otheremails) {
1.619 raeburn 16124: my @others;
16125: if ($otheremails =~ /,/) {
16126: @others = split(/,/,$otheremails);
1.618 raeburn 16127: } else {
1.619 raeburn 16128: push(@others,$otheremails);
16129: }
16130: foreach my $addr (@others) {
16131: if (!grep(/^\Q$addr\E$/,@recipients)) {
16132: push(@recipients,$addr);
16133: }
1.618 raeburn 16134: }
16135: }
1.1298 raeburn 16136: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 16137: if ((!@recipients) && ($lastresort ne '')) {
16138: push(@recipients,$lastresort);
16139: }
16140: } elsif ($lastresort ne '') {
16141: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
16142: push(@recipients,$lastresort);
16143: }
16144: }
1.1271 raeburn 16145: my $recipientlist = join(',',@recipients);
1.1270 raeburn 16146: if (wantarray) {
16147: return ($recipientlist,$allbcc,$addtext);
16148: } else {
16149: return $recipientlist;
16150: }
1.618 raeburn 16151: }
16152:
1.127 matthew 16153: ############################################################
16154: ############################################################
1.154 albertel 16155:
1.655 raeburn 16156: =pod
16157:
1.1224 musolffc 16158: =over 4
16159:
1.1223 musolffc 16160: =item * &mime_email()
16161:
16162: Sends an email with a possible attachment
16163:
16164: Inputs:
16165:
16166: =over 4
16167:
16168: from - Sender's email address
16169:
1.1343 raeburn 16170: replyto - Reply-To email address
16171:
1.1223 musolffc 16172: to - Email address of recipient
16173:
16174: subject - Subject of email
16175:
16176: body - Body of email
16177:
16178: cc_string - Carbon copy email address
16179:
16180: bcc - Blind carbon copy email address
16181:
16182: attachment_path - Path of file to be attached
16183:
16184: file_name - Name of file to be attached
16185:
16186: attachment_text - The body of an attachment of type "TEXT"
16187:
16188: =back
16189:
16190: =back
16191:
16192: =cut
16193:
16194: ############################################################
16195: ############################################################
16196:
16197: sub mime_email {
1.1343 raeburn 16198: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
16199: $file_name,$attachment_text) = @_;
16200:
1.1223 musolffc 16201: my $msg = MIME::Lite->new(
16202: From => $from,
16203: To => $to,
16204: Subject => $subject,
16205: Type =>'TEXT',
16206: Data => $body,
16207: );
1.1343 raeburn 16208: if ($replyto ne '') {
16209: $msg->add("Reply-To" => $replyto);
16210: }
1.1223 musolffc 16211: if ($cc_string ne '') {
16212: $msg->add("Cc" => $cc_string);
16213: }
16214: if ($bcc ne '') {
16215: $msg->add("Bcc" => $bcc);
16216: }
16217: $msg->attr("content-type" => "text/plain");
16218: $msg->attr("content-type.charset" => "UTF-8");
16219: # Attach file if given
16220: if ($attachment_path) {
16221: unless ($file_name) {
16222: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
16223: }
16224: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
16225: $msg->attach(Type => $type,
16226: Path => $attachment_path,
16227: Filename => $file_name
16228: );
16229: # Otherwise attach text if given
16230: } elsif ($attachment_text) {
16231: $msg->attach(Type => 'TEXT',
16232: Data => $attachment_text);
16233: }
16234: # Send it
16235: $msg->send('sendmail');
16236: }
16237:
16238: ############################################################
16239: ############################################################
16240:
16241: =pod
16242:
1.655 raeburn 16243: =head1 Course Catalog Routines
16244:
16245: =over 4
16246:
16247: =item * &gather_categories()
16248:
16249: Converts category definitions - keys of categories hash stored in
16250: coursecategories in configuration.db on the primary library server in a
16251: domain - to an array. Also generates javascript and idx hash used to
16252: generate Domain Coordinator interface for editing Course Categories.
16253:
16254: Inputs:
1.663 raeburn 16255:
1.655 raeburn 16256: categories (reference to hash of category definitions).
1.663 raeburn 16257:
1.655 raeburn 16258: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16259: categories and subcategories).
1.663 raeburn 16260:
1.655 raeburn 16261: idx (reference to hash of counters used in Domain Coordinator interface for
16262: editing Course Categories).
1.663 raeburn 16263:
1.655 raeburn 16264: jsarray (reference to array of categories used to create Javascript arrays for
16265: Domain Coordinator interface for editing Course Categories).
16266:
16267: Returns: nothing
16268:
16269: Side effects: populates cats, idx and jsarray.
16270:
16271: =cut
16272:
16273: sub gather_categories {
16274: my ($categories,$cats,$idx,$jsarray) = @_;
16275: my %counters;
16276: my $num = 0;
16277: foreach my $item (keys(%{$categories})) {
16278: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16279: if ($container eq '' && $depth == 0) {
16280: $cats->[$depth][$categories->{$item}] = $cat;
16281: } else {
16282: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
16283: }
16284: my ($escitem,$tail) = split(/:/,$item,2);
16285: if ($counters{$tail} eq '') {
16286: $counters{$tail} = $num;
16287: $num ++;
16288: }
16289: if (ref($idx) eq 'HASH') {
16290: $idx->{$item} = $counters{$tail};
16291: }
16292: if (ref($jsarray) eq 'ARRAY') {
16293: push(@{$jsarray->[$counters{$tail}]},$item);
16294: }
16295: }
16296: return;
16297: }
16298:
16299: =pod
16300:
16301: =item * &extract_categories()
16302:
16303: Used to generate breadcrumb trails for course categories.
16304:
16305: Inputs:
1.663 raeburn 16306:
1.655 raeburn 16307: categories (reference to hash of category definitions).
1.663 raeburn 16308:
1.655 raeburn 16309: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16310: categories and subcategories).
1.663 raeburn 16311:
1.655 raeburn 16312: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 16313:
1.655 raeburn 16314: allitems (reference to hash - key is category key
16315: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16316:
1.655 raeburn 16317: idx (reference to hash of counters used in Domain Coordinator interface for
16318: editing Course Categories).
1.663 raeburn 16319:
1.655 raeburn 16320: jsarray (reference to array of categories used to create Javascript arrays for
16321: Domain Coordinator interface for editing Course Categories).
16322:
1.665 raeburn 16323: subcats (reference to hash of arrays containing all subcategories within each
16324: category, -recursive)
16325:
1.1321 raeburn 16326: maxd (reference to hash used to hold max depth for all top-level categories).
16327:
1.655 raeburn 16328: Returns: nothing
16329:
16330: Side effects: populates trails and allitems hash references.
16331:
16332: =cut
16333:
16334: sub extract_categories {
1.1321 raeburn 16335: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 16336: if (ref($categories) eq 'HASH') {
16337: &gather_categories($categories,$cats,$idx,$jsarray);
16338: if (ref($cats->[0]) eq 'ARRAY') {
16339: for (my $i=0; $i<@{$cats->[0]}; $i++) {
16340: my $name = $cats->[0][$i];
16341: my $item = &escape($name).'::0';
16342: my $trailstr;
16343: if ($name eq 'instcode') {
16344: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 16345: } elsif ($name eq 'communities') {
16346: $trailstr = &mt('Communities');
1.1239 raeburn 16347: } elsif ($name eq 'placement') {
16348: $trailstr = &mt('Placement Tests');
1.655 raeburn 16349: } else {
16350: $trailstr = $name;
16351: }
16352: if ($allitems->{$item} eq '') {
16353: push(@{$trails},$trailstr);
16354: $allitems->{$item} = scalar(@{$trails})-1;
16355: }
16356: my @parents = ($name);
16357: if (ref($cats->[1]{$name}) eq 'ARRAY') {
16358: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
16359: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 16360: if (ref($subcats) eq 'HASH') {
16361: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
16362: }
1.1321 raeburn 16363: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 16364: }
16365: } else {
16366: if (ref($subcats) eq 'HASH') {
16367: $subcats->{$item} = [];
1.655 raeburn 16368: }
1.1321 raeburn 16369: if (ref($maxd) eq 'HASH') {
16370: $maxd->{$name} = 1;
16371: }
1.655 raeburn 16372: }
16373: }
16374: }
16375: }
16376: return;
16377: }
16378:
16379: =pod
16380:
1.1162 raeburn 16381: =item * &recurse_categories()
1.655 raeburn 16382:
16383: Recursively used to generate breadcrumb trails for course categories.
16384:
16385: Inputs:
1.663 raeburn 16386:
1.655 raeburn 16387: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16388: categories and subcategories).
1.663 raeburn 16389:
1.655 raeburn 16390: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 16391:
16392: category (current course category, for which breadcrumb trail is being generated).
16393:
16394: trails (reference to array of breadcrumb trails for each category).
16395:
1.655 raeburn 16396: allitems (reference to hash - key is category key
16397: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16398:
1.655 raeburn 16399: parents (array containing containers directories for current category,
16400: back to top level).
16401:
16402: Returns: nothing
16403:
16404: Side effects: populates trails and allitems hash references
16405:
16406: =cut
16407:
16408: sub recurse_categories {
1.1321 raeburn 16409: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 16410: my $shallower = $depth - 1;
16411: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
16412: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
16413: my $name = $cats->[$depth]{$category}[$k];
16414: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16415: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16416: if ($allitems->{$item} eq '') {
16417: push(@{$trails},$trailstr);
16418: $allitems->{$item} = scalar(@{$trails})-1;
16419: }
16420: my $deeper = $depth+1;
16421: push(@{$parents},$category);
1.665 raeburn 16422: if (ref($subcats) eq 'HASH') {
16423: my $subcat = &escape($name).':'.$category.':'.$depth;
16424: for (my $j=@{$parents}; $j>=0; $j--) {
16425: my $higher;
16426: if ($j > 0) {
16427: $higher = &escape($parents->[$j]).':'.
16428: &escape($parents->[$j-1]).':'.$j;
16429: } else {
16430: $higher = &escape($parents->[$j]).'::'.$j;
16431: }
16432: push(@{$subcats->{$higher}},$subcat);
16433: }
16434: }
16435: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 16436: $subcats,$maxd);
1.655 raeburn 16437: pop(@{$parents});
16438: }
16439: } else {
16440: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16441: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16442: if ($allitems->{$item} eq '') {
16443: push(@{$trails},$trailstr);
16444: $allitems->{$item} = scalar(@{$trails})-1;
16445: }
1.1321 raeburn 16446: if (ref($maxd) eq 'HASH') {
16447: if ($depth > $maxd->{$parents->[0]}) {
16448: $maxd->{$parents->[0]} = $depth;
16449: }
16450: }
1.655 raeburn 16451: }
16452: return;
16453: }
16454:
1.663 raeburn 16455: =pod
16456:
1.1162 raeburn 16457: =item * &assign_categories_table()
1.663 raeburn 16458:
16459: Create a datatable for display of hierarchical categories in a domain,
16460: with checkboxes to allow a course to be categorized.
16461:
16462: Inputs:
16463:
16464: cathash - reference to hash of categories defined for the domain (from
16465: configuration.db)
16466:
16467: currcat - scalar with an & separated list of categories assigned to a course.
16468:
1.919 raeburn 16469: type - scalar contains course type (Course or Community).
16470:
1.1260 raeburn 16471: disabled - scalar (optional) contains disabled="disabled" if input elements are
16472: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16473:
1.663 raeburn 16474: Returns: $output (markup to be displayed)
16475:
16476: =cut
16477:
16478: sub assign_categories_table {
1.1259 raeburn 16479: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 16480: my $output;
16481: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 16482: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
16483: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 16484: $maxdepth = scalar(@cats);
16485: if (@cats > 0) {
16486: my $itemcount = 0;
16487: if (ref($cats[0]) eq 'ARRAY') {
16488: my @currcategories;
16489: if ($currcat ne '') {
16490: @currcategories = split('&',$currcat);
16491: }
1.919 raeburn 16492: my $table;
1.663 raeburn 16493: for (my $i=0; $i<@{$cats[0]}; $i++) {
16494: my $parent = $cats[0][$i];
1.919 raeburn 16495: next if ($parent eq 'instcode');
16496: if ($type eq 'Community') {
16497: next unless ($parent eq 'communities');
1.1239 raeburn 16498: } elsif ($type eq 'Placement') {
16499: next unless ($parent eq 'placement');
1.919 raeburn 16500: } else {
1.1239 raeburn 16501: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 16502: }
1.663 raeburn 16503: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
16504: my $item = &escape($parent).'::0';
16505: my $checked = '';
16506: if (@currcategories > 0) {
16507: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 16508: $checked = ' checked="checked"';
1.663 raeburn 16509: }
16510: }
1.919 raeburn 16511: my $parent_title = $parent;
16512: if ($parent eq 'communities') {
16513: $parent_title = &mt('Communities');
1.1239 raeburn 16514: } elsif ($parent eq 'placement') {
16515: $parent_title = &mt('Placement Tests');
1.919 raeburn 16516: }
16517: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
16518: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16519: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 16520: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 16521: my $depth = 1;
16522: push(@path,$parent);
1.1259 raeburn 16523: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 16524: pop(@path);
1.919 raeburn 16525: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 16526: $itemcount ++;
16527: }
1.919 raeburn 16528: if ($itemcount) {
16529: $output = &Apache::loncommon::start_data_table().
16530: $table.
16531: &Apache::loncommon::end_data_table();
16532: }
1.663 raeburn 16533: }
16534: }
16535: }
16536: return $output;
16537: }
16538:
16539: =pod
16540:
1.1162 raeburn 16541: =item * &assign_category_rows()
1.663 raeburn 16542:
16543: Create a datatable row for display of nested categories in a domain,
16544: with checkboxes to allow a course to be categorized,called recursively.
16545:
16546: Inputs:
16547:
16548: itemcount - track row number for alternating colors
16549:
16550: cats - reference to array of arrays/hashes which encapsulates hierarchy of
16551: categories and subcategories.
16552:
16553: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
16554:
16555: parent - parent of current category item
16556:
16557: path - Array containing all categories back up through the hierarchy from the
16558: current category to the top level.
16559:
16560: currcategories - reference to array of current categories assigned to the course
16561:
1.1260 raeburn 16562: disabled - scalar (optional) contains disabled="disabled" if input elements are
16563: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16564:
1.663 raeburn 16565: Returns: $output (markup to be displayed).
16566:
16567: =cut
16568:
16569: sub assign_category_rows {
1.1259 raeburn 16570: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 16571: my ($text,$name,$item,$chgstr);
16572: if (ref($cats) eq 'ARRAY') {
16573: my $maxdepth = scalar(@{$cats});
16574: if (ref($cats->[$depth]) eq 'HASH') {
16575: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
16576: my $numchildren = @{$cats->[$depth]{$parent}};
16577: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 16578: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 16579: for (my $j=0; $j<$numchildren; $j++) {
16580: $name = $cats->[$depth]{$parent}[$j];
16581: $item = &escape($name).':'.&escape($parent).':'.$depth;
16582: my $deeper = $depth+1;
16583: my $checked = '';
16584: if (ref($currcategories) eq 'ARRAY') {
16585: if (@{$currcategories} > 0) {
16586: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 16587: $checked = ' checked="checked"';
1.663 raeburn 16588: }
16589: }
16590: }
1.664 raeburn 16591: $text .= '<tr><td><span class="LC_nobreak"><label>'.
16592: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16593: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 16594: '<input type="hidden" name="catname" value="'.$name.'" />'.
16595: '</td><td>';
1.663 raeburn 16596: if (ref($path) eq 'ARRAY') {
16597: push(@{$path},$name);
1.1259 raeburn 16598: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 16599: pop(@{$path});
16600: }
16601: $text .= '</td></tr>';
16602: }
16603: $text .= '</table></td>';
16604: }
16605: }
16606: }
16607: return $text;
16608: }
16609:
1.1181 raeburn 16610: =pod
16611:
16612: =back
16613:
16614: =cut
16615:
1.655 raeburn 16616: ############################################################
16617: ############################################################
16618:
16619:
1.443 albertel 16620: sub commit_customrole {
1.1408 raeburn 16621: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context,$othdomby,$requester) = @_;
1.1399 raeburn 16622: my $result = &Apache::lonnet::assigncustomrole(
1.1408 raeburn 16623: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,
16624: $context,$othdomby,$requester);
1.630 raeburn 16625: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 16626: ($start?', '.&mt('starting').' '.localtime($start):'').
1.1399 raeburn 16627: ($end?', ending '.localtime($end):'').': <b>'.$result.'</b><br />';
16628: if (wantarray) {
16629: return ($output,$result);
16630: } else {
16631: return $output;
16632: }
1.443 albertel 16633: }
16634:
16635: sub commit_standardrole {
1.1408 raeburn 16636: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits,
16637: $othdomby,$requester) = @_;
1.1399 raeburn 16638: my ($output,$logmsg,$linefeed,$result);
1.541 raeburn 16639: if ($context eq 'auto') {
16640: $linefeed = "\n";
16641: } else {
16642: $linefeed = "<br />\n";
16643: }
1.443 albertel 16644: if ($three eq 'st') {
1.1399 raeburn 16645: $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1408 raeburn 16646: $one,$two,$sec,$context,$credits,$othdomby,
16647: $requester);
1.541 raeburn 16648: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 16649: ($result eq 'unknown_course') || ($result eq 'refused')) {
16650: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 16651: } else {
1.541 raeburn 16652: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 16653: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16654: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
16655: if ($context eq 'auto') {
16656: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
16657: } else {
16658: $output .= '<b>'.$result.'</b>'.$linefeed.
16659: &mt('Add to classlist').': <b>ok</b>';
16660: }
16661: $output .= $linefeed;
1.443 albertel 16662: }
16663: } else {
16664: $output = &mt('Assigning').' '.$three.' in '.$url.
16665: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16666: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.1408 raeburn 16667: $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,
16668: '','',$context,$othdomby,$requester);
1.541 raeburn 16669: if ($context eq 'auto') {
16670: $output .= $result.$linefeed;
16671: } else {
16672: $output .= '<b>'.$result.'</b>'.$linefeed;
16673: }
1.443 albertel 16674: }
1.1399 raeburn 16675: if (wantarray) {
16676: return ($output,$result);
16677: } else {
16678: return $output;
16679: }
1.443 albertel 16680: }
16681:
16682: sub commit_studentrole {
1.1116 raeburn 16683: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
1.1408 raeburn 16684: $credits,$othdomby,$requester) = @_;
1.626 raeburn 16685: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 16686: if ($context eq 'auto') {
16687: $linefeed = "\n";
16688: } else {
16689: $linefeed = '<br />'."\n";
16690: }
1.443 albertel 16691: if (defined($one) && defined($two)) {
16692: my $cid=$one.'_'.$two;
16693: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
16694: my $secchange = 0;
16695: my $expire_role_result;
16696: my $modify_section_result;
1.628 raeburn 16697: if ($oldsec ne '-1') {
16698: if ($oldsec ne $sec) {
1.443 albertel 16699: $secchange = 1;
1.628 raeburn 16700: my $now = time;
1.443 albertel 16701: my $uurl='/'.$cid;
16702: $uurl=~s/\_/\//g;
16703: if ($oldsec) {
16704: $uurl.='/'.$oldsec;
16705: }
1.626 raeburn 16706: $oldsecurl = $uurl;
1.628 raeburn 16707: $expire_role_result =
1.1408 raeburn 16708: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,
16709: '','','',$context,$othdomby,$requester);
16710: if ($env{'request.course.sec'} ne '') {
1.628 raeburn 16711: if ($expire_role_result eq 'refused') {
16712: my @roles = ('st');
16713: my @statuses = ('previous');
16714: my @roledoms = ($one);
16715: my $withsec = 1;
16716: my %roleshash =
16717: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
16718: \@statuses,\@roles,\@roledoms,$withsec);
16719: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
16720: my ($oldstart,$oldend) =
16721: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
16722: if ($oldend > 0 && $oldend <= $now) {
16723: $expire_role_result = 'ok';
16724: }
16725: }
16726: }
16727: }
1.443 albertel 16728: $result = $expire_role_result;
16729: }
16730: }
16731: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 16732: $modify_section_result =
16733: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
16734: undef,undef,undef,$sec,
16735: $end,$start,'','',$cid,
1.1408 raeburn 16736: '',$context,$credits,'',
16737: $othdomby,$requester);
1.443 albertel 16738: if ($modify_section_result =~ /^ok/) {
16739: if ($secchange == 1) {
1.628 raeburn 16740: if ($sec eq '') {
16741: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
16742: } else {
16743: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
16744: }
1.443 albertel 16745: } elsif ($oldsec eq '-1') {
1.628 raeburn 16746: if ($sec eq '') {
16747: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
16748: } else {
16749: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16750: }
1.443 albertel 16751: } else {
1.628 raeburn 16752: if ($sec eq '') {
16753: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
16754: } else {
16755: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16756: }
1.443 albertel 16757: }
16758: } else {
1.1115 raeburn 16759: if ($secchange) {
1.628 raeburn 16760: $$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;
16761: } else {
16762: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
16763: }
1.443 albertel 16764: }
16765: $result = $modify_section_result;
16766: } elsif ($secchange == 1) {
1.628 raeburn 16767: if ($oldsec eq '') {
1.1103 raeburn 16768: $$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 16769: } else {
16770: $$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;
16771: }
1.626 raeburn 16772: if ($expire_role_result eq 'refused') {
16773: my $newsecurl = '/'.$cid;
16774: $newsecurl =~ s/\_/\//g;
16775: if ($sec ne '') {
16776: $newsecurl.='/'.$sec;
16777: }
16778: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
16779: if ($sec eq '') {
16780: $$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;
16781: } else {
16782: $$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;
16783: }
16784: }
16785: }
1.443 albertel 16786: }
16787: } else {
1.626 raeburn 16788: $$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 16789: $result = "error: incomplete course id\n";
16790: }
16791: return $result;
16792: }
16793:
1.1108 raeburn 16794: sub show_role_extent {
16795: my ($scope,$context,$role) = @_;
16796: $scope =~ s{^/}{};
16797: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
16798: push(@courseroles,'co');
16799: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
16800: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
16801: $scope =~ s{/}{_};
16802: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
16803: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
16804: my ($audom,$auname) = split(/\//,$scope);
16805: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
16806: &Apache::loncommon::plainname($auname,$audom).'</span>');
16807: } else {
16808: $scope =~ s{/$}{};
16809: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
16810: &Apache::lonnet::domain($scope,'description').'</span>');
16811: }
16812: }
16813:
1.443 albertel 16814: ############################################################
16815: ############################################################
16816:
1.566 albertel 16817: sub check_clone {
1.578 raeburn 16818: my ($args,$linefeed) = @_;
1.566 albertel 16819: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
16820: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
16821: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 16822: my $clonetitle;
16823: my @clonemsg;
1.566 albertel 16824: my $can_clone = 0;
1.944 raeburn 16825: my $lctype = lc($args->{'crstype'});
1.908 raeburn 16826: if ($lctype ne 'community') {
16827: $lctype = 'course';
16828: }
1.566 albertel 16829: if ($clonehome eq 'no_host') {
1.944 raeburn 16830: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16831: push(@clonemsg,({
16832: mt => 'No new community created.',
16833: args => [],
16834: },
16835: {
16836: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16837: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16838: }));
1.908 raeburn 16839: } else {
1.1344 raeburn 16840: push(@clonemsg,({
16841: mt => 'No new course created.',
16842: args => [],
16843: },
16844: {
16845: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16846: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16847: }));
16848: }
1.566 albertel 16849: } else {
16850: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 16851: $clonetitle = $clonedesc{'description'};
1.944 raeburn 16852: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16853: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 16854: push(@clonemsg,({
16855: mt => 'No new community created.',
16856: args => [],
16857: },
16858: {
16859: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16860: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16861: }));
16862: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16863: }
16864: }
1.1262 raeburn 16865: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16866: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16867: $can_clone = 1;
16868: } else {
1.1221 raeburn 16869: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16870: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 16871: if ($clonehash{'cloners'} eq '') {
16872: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16873: if ($domdefs{'canclone'}) {
16874: unless ($domdefs{'canclone'} eq 'none') {
16875: if ($domdefs{'canclone'} eq 'domain') {
16876: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16877: $can_clone = 1;
16878: }
16879: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16880: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16881: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16882: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16883: $can_clone = 1;
16884: }
16885: }
16886: }
16887: }
1.578 raeburn 16888: } else {
1.1221 raeburn 16889: my @cloners = split(/,/,$clonehash{'cloners'});
16890: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16891: $can_clone = 1;
1.1221 raeburn 16892: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16893: $can_clone = 1;
1.1225 raeburn 16894: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16895: $can_clone = 1;
1.1221 raeburn 16896: }
16897: unless ($can_clone) {
1.1225 raeburn 16898: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16899: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 16900: my (%gotdomdefaults,%gotcodedefaults);
16901: foreach my $cloner (@cloners) {
16902: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16903: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16904: my (%codedefaults,@code_order);
16905: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16906: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16907: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16908: }
16909: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16910: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16911: }
16912: } else {
16913: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16914: \%codedefaults,
16915: \@code_order);
16916: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16917: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16918: }
16919: if (@code_order > 0) {
16920: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16921: $cloner,$clonehash{'internal.coursecode'},
16922: $args->{'crscode'})) {
16923: $can_clone = 1;
16924: last;
16925: }
16926: }
16927: }
16928: }
16929: }
1.1225 raeburn 16930: }
16931: }
16932: unless ($can_clone) {
16933: my $ccrole = 'cc';
16934: if ($args->{'crstype'} eq 'Community') {
16935: $ccrole = 'co';
16936: }
16937: my %roleshash =
16938: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16939: $args->{'ccdomain'},
16940: 'userroles',['active'],[$ccrole],
16941: [$args->{'clonedomain'}]);
16942: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16943: $can_clone = 1;
16944: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16945: $args->{'ccuname'},$args->{'ccdomain'})) {
16946: $can_clone = 1;
1.1221 raeburn 16947: }
16948: }
16949: unless ($can_clone) {
16950: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16951: push(@clonemsg,({
16952: mt => 'No new community created.',
16953: args => [],
16954: },
16955: {
16956: 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]).',
16957: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16958: }));
1.942 raeburn 16959: } else {
1.1344 raeburn 16960: push(@clonemsg,({
16961: mt => 'No new course created.',
16962: args => [],
16963: },
16964: {
16965: 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]).',
16966: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16967: }));
1.1221 raeburn 16968: }
1.566 albertel 16969: }
1.578 raeburn 16970: }
1.566 albertel 16971: }
1.1344 raeburn 16972: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16973: }
16974:
1.444 albertel 16975: sub construct_course {
1.1262 raeburn 16976: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 16977: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16978: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16979: my $linefeed = '<br />'."\n";
16980: if ($context eq 'auto') {
16981: $linefeed = "\n";
16982: }
1.566 albertel 16983:
16984: #
16985: # Are we cloning?
16986: #
1.1344 raeburn 16987: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16988: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 16989: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16990: if (!$can_clone) {
1.1344 raeburn 16991: return (0,$outcome,$clonemsgref);
1.566 albertel 16992: }
16993: }
16994:
1.444 albertel 16995: #
16996: # Open course
16997: #
1.1239 raeburn 16998: my $showncrstype;
16999: if ($args->{'crstype'} eq 'Placement') {
17000: $showncrstype = 'placement test';
17001: } else {
17002: $showncrstype = lc($args->{'crstype'});
17003: }
1.444 albertel 17004: my %cenv=();
17005: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
17006: $args->{'cdescr'},
17007: $args->{'curl'},
17008: $args->{'course_home'},
17009: $args->{'nonstandard'},
17010: $args->{'crscode'},
17011: $args->{'ccuname'}.':'.
17012: $args->{'ccdomain'},
1.882 raeburn 17013: $args->{'crstype'},
1.1344 raeburn 17014: $cnum,$context,$category,
17015: $callercontext);
1.444 albertel 17016:
17017: # Note: The testing routines depend on this being output; see
17018: # Utils::Course. This needs to at least be output as a comment
17019: # if anyone ever decides to not show this, and Utils::Course::new
17020: # will need to be suitably modified.
1.1344 raeburn 17021: if (($callercontext eq 'auto') && ($user_lh ne '')) {
17022: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
17023: } else {
17024: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
17025: }
1.943 raeburn 17026: if ($$courseid =~ /^error:/) {
1.1344 raeburn 17027: return (0,$outcome,$clonemsgref);
1.943 raeburn 17028: }
17029:
1.444 albertel 17030: #
17031: # Check if created correctly
17032: #
1.479 albertel 17033: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 17034: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 17035: if ($crsuhome eq 'no_host') {
1.1344 raeburn 17036: if (($callercontext eq 'auto') && ($user_lh ne '')) {
17037: $outcome .= &mt_user($user_lh,
17038: 'Course creation failed, unrecognized course home server.');
17039: } else {
17040: $outcome .= &mt('Course creation failed, unrecognized course home server.');
17041: }
17042: $outcome .= $linefeed;
17043: return (0,$outcome,$clonemsgref);
1.943 raeburn 17044: }
1.541 raeburn 17045: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 17046:
1.444 albertel 17047: #
1.566 albertel 17048: # Do the cloning
17049: #
1.1344 raeburn 17050: my @clonemsg;
1.566 albertel 17051: if ($can_clone && $cloneid) {
1.1344 raeburn 17052: push(@clonemsg,
17053: {
17054: mt => 'Created [_1] by cloning from [_2]',
17055: args => [$showncrstype,$clonetitle],
17056: });
1.566 albertel 17057: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 17058: # Copy all files
1.1344 raeburn 17059: my @info =
17060: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
17061: $args->{'dateshift'},$args->{'crscode'},
17062: $args->{'ccuname'}.':'.$args->{'ccdomain'},
17063: $args->{'tinyurls'});
17064: if (@info) {
17065: push(@clonemsg,@info);
17066: }
1.444 albertel 17067: # Restore URL
1.566 albertel 17068: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 17069: # Restore title
1.566 albertel 17070: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 17071: # Restore creation date, creator and creation context.
17072: $cenv{'internal.created'}=$oldcenv{'internal.created'};
17073: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
17074: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 17075: # Mark as cloned
1.566 albertel 17076: $cenv{'clonedfrom'}=$cloneid;
1.638 www 17077: # Need to clone grading mode
17078: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
17079: $cenv{'grading'}=$newenv{'grading'};
17080: # Do not clone these environment entries
17081: &Apache::lonnet::del('environment',
17082: ['default_enrollment_start_date',
17083: 'default_enrollment_end_date',
17084: 'question.email',
17085: 'policy.email',
17086: 'comment.email',
17087: 'pch.users.denied',
1.725 raeburn 17088: 'plc.users.denied',
17089: 'hidefromcat',
1.1121 raeburn 17090: 'checkforpriv',
1.1355 raeburn 17091: 'categories'],
1.638 www 17092: $$crsudom,$$crsunum);
1.1170 raeburn 17093: if ($args->{'textbook'}) {
17094: $cenv{'internal.textbook'} = $args->{'textbook'};
17095: }
1.444 albertel 17096: }
1.566 albertel 17097:
1.444 albertel 17098: #
17099: # Set environment (will override cloned, if existing)
17100: #
17101: my @sections = ();
17102: my @xlists = ();
17103: if ($args->{'crstype'}) {
17104: $cenv{'type'}=$args->{'crstype'};
17105: }
1.1371 raeburn 17106: if ($args->{'lti'}) {
17107: $cenv{'internal.lti'}=$args->{'lti'};
17108: }
1.444 albertel 17109: if ($args->{'crsid'}) {
17110: $cenv{'courseid'}=$args->{'crsid'};
17111: }
17112: if ($args->{'crscode'}) {
17113: $cenv{'internal.coursecode'}=$args->{'crscode'};
17114: }
17115: if ($args->{'crsquota'} ne '') {
17116: $cenv{'internal.coursequota'}=$args->{'crsquota'};
17117: } else {
17118: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
17119: }
17120: if ($args->{'ccuname'}) {
17121: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
17122: ':'.$args->{'ccdomain'};
17123: } else {
17124: $cenv{'internal.courseowner'} = $args->{'curruser'};
17125: }
1.1116 raeburn 17126: if ($args->{'defaultcredits'}) {
17127: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
17128: }
1.444 albertel 17129: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.1412 raeburn 17130: my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.
1.444 albertel 17131: if ($args->{'crssections'}) {
17132: $cenv{'internal.sectionnums'} = '';
17133: if ($args->{'crssections'} =~ m/,/) {
17134: @sections = split/,/,$args->{'crssections'};
17135: } else {
17136: $sections[0] = $args->{'crssections'};
17137: }
17138: if (@sections > 0) {
17139: foreach my $item (@sections) {
17140: my ($sec,$gp) = split/:/,$item;
17141: my $class = $args->{'crscode'}.$sec;
17142: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
17143: $cenv{'internal.sectionnums'} .= $item.',';
1.1412 raeburn 17144: if ($addcheck eq 'ok') {
17145: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
17146: push(@oklcsecs,$gp);
17147: }
17148: } else {
1.1263 raeburn 17149: push(@badclasses,$class);
1.444 albertel 17150: }
17151: }
17152: $cenv{'internal.sectionnums'} =~ s/,$//;
17153: }
17154: }
17155: # do not hide course coordinator from staff listing,
17156: # even if privileged
17157: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 17158: # add course coordinator's domain to domains to check for privileged users
17159: # if different to course domain
17160: if ($$crsudom ne $args->{'ccdomain'}) {
17161: $cenv{'checkforpriv'} = $args->{'ccdomain'};
17162: }
1.444 albertel 17163: # add crosslistings
17164: if ($args->{'crsxlist'}) {
17165: $cenv{'internal.crosslistings'}='';
17166: if ($args->{'crsxlist'} =~ m/,/) {
17167: @xlists = split/,/,$args->{'crsxlist'};
17168: } else {
17169: $xlists[0] = $args->{'crsxlist'};
17170: }
17171: if (@xlists > 0) {
17172: foreach my $item (@xlists) {
17173: my ($xl,$gp) = split/:/,$item;
17174: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
17175: $cenv{'internal.crosslistings'} .= $item.',';
1.1412 raeburn 17176: if ($addcheck eq 'ok') {
17177: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
17178: push(@oklcsecs,$gp);
17179: }
17180: } else {
1.1263 raeburn 17181: push(@badclasses,$xl);
1.444 albertel 17182: }
17183: }
17184: $cenv{'internal.crosslistings'} =~ s/,$//;
17185: }
17186: }
17187: if ($args->{'autoadds'}) {
17188: $cenv{'internal.autoadds'}=$args->{'autoadds'};
17189: }
17190: if ($args->{'autodrops'}) {
17191: $cenv{'internal.autodrops'}=$args->{'autodrops'};
17192: }
17193: # check for notification of enrollment changes
17194: my @notified = ();
17195: if ($args->{'notify_owner'}) {
17196: if ($args->{'ccuname'} ne '') {
17197: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
17198: }
17199: }
17200: if ($args->{'notify_dc'}) {
17201: if ($uname ne '') {
1.630 raeburn 17202: push(@notified,$uname.':'.$udom);
1.444 albertel 17203: }
17204: }
17205: if (@notified > 0) {
17206: my $notifylist;
17207: if (@notified > 1) {
17208: $notifylist = join(',',@notified);
17209: } else {
17210: $notifylist = $notified[0];
17211: }
17212: $cenv{'internal.notifylist'} = $notifylist;
17213: }
17214: if (@badclasses > 0) {
17215: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 17216: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
17217: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
17218: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 17219: );
1.1264 raeburn 17220: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
17221: &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 17222: if ($context eq 'auto') {
17223: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 17224: } else {
1.566 albertel 17225: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 17226: }
17227: foreach my $item (@badclasses) {
1.541 raeburn 17228: if ($context eq 'auto') {
1.1261 raeburn 17229: $outcome .= " - $item\n";
1.541 raeburn 17230: } else {
1.1261 raeburn 17231: $outcome .= "<li>$item</li>\n";
1.541 raeburn 17232: }
1.1261 raeburn 17233: }
17234: if ($context eq 'auto') {
17235: $outcome .= $linefeed;
17236: } else {
17237: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 17238: }
1.444 albertel 17239: }
17240: if ($args->{'no_end_date'}) {
17241: $args->{'endaccess'} = 0;
17242: }
1.1412 raeburn 17243: # If an official course with institutional sections is created by cloning
17244: # an existing course, section-specific hiding of course totals in student's
17245: # view of grades as copied from cloned course, will be checked for valid
17246: # sections.
17247: if (($can_clone && $cloneid) &&
17248: ($cenv{'internal.coursecode'} ne '') &&
17249: ($cenv{'grading'} eq 'standard') &&
17250: ($cenv{'hidetotals'} ne '') &&
17251: ($cenv{'hidetotals'} ne 'all')) {
17252: my @hidesecs;
17253: my $deletehidetotals;
17254: if (@oklcsecs) {
17255: foreach my $sec (split(/,/,$cenv{'hidetotals'})) {
17256: if (grep(/^\Q$sec$/,@oklcsecs)) {
17257: push(@hidesecs,$sec);
17258: }
17259: }
17260: if (@hidesecs) {
17261: $cenv{'hidetotals'} = join(',',@hidesecs);
17262: } else {
17263: $deletehidetotals = 1;
17264: }
17265: } else {
17266: $deletehidetotals = 1;
17267: }
17268: if ($deletehidetotals) {
17269: delete($cenv{'hidetotals'});
17270: &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);
17271: }
17272: }
1.444 albertel 17273: $cenv{'internal.autostart'}=$args->{'enrollstart'};
17274: $cenv{'internal.autoend'}=$args->{'enrollend'};
17275: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
17276: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
17277: if ($args->{'showphotos'}) {
17278: $cenv{'internal.showphotos'}=$args->{'showphotos'};
17279: }
17280: $cenv{'internal.authtype'} = $args->{'authtype'};
17281: $cenv{'internal.autharg'} = $args->{'autharg'};
17282: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
17283: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 17284: 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');
17285: if ($context eq 'auto') {
17286: $outcome .= $krb_msg;
17287: } else {
1.566 albertel 17288: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 17289: }
17290: $outcome .= $linefeed;
1.444 albertel 17291: }
17292: }
17293: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
17294: if ($args->{'setpolicy'}) {
17295: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17296: }
17297: if ($args->{'setcontent'}) {
17298: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17299: }
1.1251 raeburn 17300: if ($args->{'setcomment'}) {
17301: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17302: }
1.444 albertel 17303: }
17304: if ($args->{'reshome'}) {
17305: $cenv{'reshome'}=$args->{'reshome'}.'/';
17306: $cenv{'reshome'}=~s/\/+$/\//;
17307: }
17308: #
17309: # course has keyed access
17310: #
17311: if ($args->{'setkeys'}) {
17312: $cenv{'keyaccess'}='yes';
17313: }
17314: # if specified, key authority is not course, but user
17315: # only active if keyaccess is yes
17316: if ($args->{'keyauth'}) {
1.487 albertel 17317: my ($user,$domain) = split(':',$args->{'keyauth'});
17318: $user = &LONCAPA::clean_username($user);
17319: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 17320: if ($user ne '' && $domain ne '') {
1.487 albertel 17321: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 17322: }
17323: }
17324:
1.1166 raeburn 17325: #
1.1167 raeburn 17326: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 17327: #
17328: if ($args->{'uniquecode'}) {
17329: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
17330: if ($code) {
17331: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 17332: my %crsinfo =
17333: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
17334: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
17335: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
17336: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
17337: }
1.1166 raeburn 17338: if (ref($coderef)) {
17339: $$coderef = $code;
17340: }
17341: }
17342: }
17343:
1.444 albertel 17344: if ($args->{'disresdis'}) {
17345: $cenv{'pch.roles.denied'}='st';
17346: }
17347: if ($args->{'disablechat'}) {
17348: $cenv{'plc.roles.denied'}='st';
17349: }
17350:
17351: # Record we've not yet viewed the Course Initialization Helper for this
17352: # course
17353: $cenv{'course.helper.not.run'} = 1;
17354: #
17355: # Use new Randomseed
17356: #
17357: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
17358: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
17359: #
17360: # The encryption code and receipt prefix for this course
17361: #
17362: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
17363: $cenv{'internal.encpref'}=100+int(9*rand(99));
17364: #
17365: # By default, use standard grading
17366: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
17367:
1.541 raeburn 17368: $outcome .= $linefeed.&mt('Setting environment').': '.
17369: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17370: #
17371: # Open all assignments
17372: #
17373: if ($args->{'openall'}) {
1.1341 raeburn 17374: my $opendate = time;
17375: if ($args->{'openallfrom'} =~ /^\d+$/) {
17376: $opendate = $args->{'openallfrom'};
17377: }
1.444 albertel 17378: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 17379: my %storecontent = ($storeunder => $opendate,
1.444 albertel 17380: $storeunder.'.type' => 'date_start');
1.1341 raeburn 17381: $outcome .= &mt('All assignments open starting [_1]',
17382: &Apache::lonlocal::locallocaltime($opendate)).': '.
17383: &Apache::lonnet::cput
17384: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17385: }
17386: #
17387: # Set first page
17388: #
17389: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
17390: || ($cloneid)) {
17391: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 17392:
17393: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
17394: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
17395:
1.444 albertel 17396: $outcome .= ($fatal?$errtext:'read ok').' - ';
17397: my $title; my $url;
17398: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 17399: $title=&mt('Syllabus');
1.444 albertel 17400: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
17401: } else {
1.963 raeburn 17402: $title=&mt('Table of Contents');
1.444 albertel 17403: $url='/adm/navmaps';
17404: }
1.445 albertel 17405:
17406: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
17407: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
17408:
17409: if ($errtext) { $fatal=2; }
1.541 raeburn 17410: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 17411: }
1.566 albertel 17412:
1.1237 raeburn 17413: #
17414: # Set params for Placement Tests
17415: #
1.1239 raeburn 17416: if ($args->{'crstype'} eq 'Placement') {
17417: my %storecontent;
17418: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
17419: my %defaults = (
17420: buttonshide => { value => 'yes',
17421: type => 'string_yesno',},
17422: type => { value => 'randomizetry',
17423: type => 'string_questiontype',},
17424: maxtries => { value => 1,
17425: type => 'int_pos',},
17426: problemstatus => { value => 'no',
17427: type => 'string_problemstatus',},
17428: );
17429: foreach my $key (keys(%defaults)) {
17430: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
17431: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
17432: }
1.1237 raeburn 17433: &Apache::lonnet::cput
17434: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
17435: }
17436:
1.1344 raeburn 17437: return (1,$outcome,\@clonemsg);
1.444 albertel 17438: }
17439:
1.1166 raeburn 17440: sub make_unique_code {
17441: my ($cdom,$cnum) = @_;
17442: # get lock on uniquecodes db
17443: my $lockhash = {
17444: $cnum."\0".'uniquecodes' => $env{'user.name'}.
17445: ':'.$env{'user.domain'},
17446: };
17447: my $tries = 0;
17448: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17449: my ($code,$error);
17450:
17451: while (($gotlock ne 'ok') && ($tries<3)) {
17452: $tries ++;
17453: sleep 1;
17454: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17455: }
17456: if ($gotlock eq 'ok') {
17457: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
17458: my $gotcode;
17459: my $attempts = 0;
17460: while ((!$gotcode) && ($attempts < 100)) {
17461: $code = &generate_code();
17462: if (!exists($currcodes{$code})) {
17463: $gotcode = 1;
17464: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
17465: $error = 'nostore';
17466: }
17467: }
17468: $attempts ++;
17469: }
17470: my @del_lock = ($cnum."\0".'uniquecodes');
17471: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
17472: } else {
17473: $error = 'nolock';
17474: }
17475: return ($code,$error);
17476: }
17477:
17478: sub generate_code {
17479: my $code;
17480: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
17481: for (my $i=0; $i<6; $i++) {
17482: my $lettnum = int (rand 2);
17483: my $item = '';
17484: if ($lettnum) {
17485: $item = $letts[int( rand(18) )];
17486: } else {
17487: $item = 1+int( rand(8) );
17488: }
17489: $code .= $item;
17490: }
17491: return $code;
17492: }
17493:
1.444 albertel 17494: ############################################################
17495: ############################################################
17496:
1.1237 raeburn 17497: # Community, Course and Placement Test
1.378 raeburn 17498: sub course_type {
17499: my ($cid) = @_;
17500: if (!defined($cid)) {
17501: $cid = $env{'request.course.id'};
17502: }
1.404 albertel 17503: if (defined($env{'course.'.$cid.'.type'})) {
17504: return $env{'course.'.$cid.'.type'};
1.378 raeburn 17505: } else {
17506: return 'Course';
1.377 raeburn 17507: }
17508: }
1.156 albertel 17509:
1.406 raeburn 17510: sub group_term {
17511: my $crstype = &course_type();
17512: my %names = (
17513: 'Course' => 'group',
1.865 raeburn 17514: 'Community' => 'group',
1.1237 raeburn 17515: 'Placement' => 'group',
1.406 raeburn 17516: );
17517: return $names{$crstype};
17518: }
17519:
1.902 raeburn 17520: sub course_types {
1.1310 raeburn 17521: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 17522: my %typename = (
17523: official => 'Official course',
17524: unofficial => 'Unofficial course',
17525: community => 'Community',
1.1165 raeburn 17526: textbook => 'Textbook course',
1.1237 raeburn 17527: placement => 'Placement test',
1.1310 raeburn 17528: lti => 'LTI provider',
1.902 raeburn 17529: );
17530: return (\@types,\%typename);
17531: }
17532:
1.156 albertel 17533: sub icon {
17534: my ($file)=@_;
1.505 albertel 17535: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 17536: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 17537: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 17538: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
17539: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
17540: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17541: $curfext.".gif") {
17542: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17543: $curfext.".gif";
17544: }
17545: }
1.249 albertel 17546: return &lonhttpdurl($iconname);
1.154 albertel 17547: }
1.84 albertel 17548:
1.575 albertel 17549: sub lonhttpdurl {
1.692 www 17550: #
17551: # Had been used for "small fry" static images on separate port 8080.
17552: # Modify here if lightweight http functionality desired again.
17553: # Currently eliminated due to increasing firewall issues.
17554: #
1.575 albertel 17555: my ($url)=@_;
1.692 www 17556: return $url;
1.215 albertel 17557: }
17558:
1.213 albertel 17559: sub connection_aborted {
17560: my ($r)=@_;
17561: $r->print(" ");$r->rflush();
17562: my $c = $r->connection;
17563: return $c->aborted();
17564: }
17565:
1.221 foxr 17566: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 17567: # strings as 'strings'.
17568: sub escape_single {
1.221 foxr 17569: my ($input) = @_;
1.223 albertel 17570: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 17571: $input =~ s/\'/\\\'/g; # Esacpe the 's....
17572: return $input;
17573: }
1.223 albertel 17574:
1.222 foxr 17575: # Same as escape_single, but escape's "'s This
17576: # can be used for "strings"
17577: sub escape_double {
17578: my ($input) = @_;
17579: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
17580: $input =~ s/\"/\\\"/g; # Esacpe the "s....
17581: return $input;
17582: }
1.223 albertel 17583:
1.222 foxr 17584: # Escapes the last element of a full URL.
17585: sub escape_url {
17586: my ($url) = @_;
1.238 raeburn 17587: my @urlslices = split(/\//, $url,-1);
1.369 www 17588: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 17589: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 17590: }
1.462 albertel 17591:
1.820 raeburn 17592: sub compare_arrays {
17593: my ($arrayref1,$arrayref2) = @_;
17594: my (@difference,%count);
17595: @difference = ();
17596: %count = ();
17597: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
17598: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
17599: foreach my $element (keys(%count)) {
17600: if ($count{$element} == 1) {
17601: push(@difference,$element);
17602: }
17603: }
17604: }
17605: return @difference;
17606: }
17607:
1.1322 raeburn 17608: sub lon_status_items {
17609: my %defaults = (
17610: E => 100,
17611: W => 4,
17612: N => 1,
1.1324 raeburn 17613: U => 5,
1.1322 raeburn 17614: threshold => 200,
17615: sysmail => 2500,
17616: );
17617: my %names = (
17618: E => 'Errors',
17619: W => 'Warnings',
17620: N => 'Notices',
1.1324 raeburn 17621: U => 'Unsent',
1.1322 raeburn 17622: );
17623: return (\%defaults,\%names);
17624: }
17625:
1.817 bisitz 17626: # -------------------------------------------------------- Initialize user login
1.462 albertel 17627: sub init_user_environment {
1.463 albertel 17628: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 17629: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
17630:
17631: my $public=($username eq 'public' && $domain eq 'public');
17632:
1.1415 raeburn 17633: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv,
17634: $coauthorenv);
1.462 albertel 17635: my $now=time;
17636:
17637: if ($public) {
17638: my $max_public=100;
17639: my $oldest;
17640: my $oldest_time=0;
17641: for(my $next=1;$next<=$max_public;$next++) {
17642: if (-e $lonids."/publicuser_$next.id") {
17643: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
17644: if ($mtime<$oldest_time || !$oldest_time) {
17645: $oldest_time=$mtime;
17646: $oldest=$next;
17647: }
17648: } else {
17649: $cookie="publicuser_$next";
17650: last;
17651: }
17652: }
17653: if (!$cookie) { $cookie="publicuser_$oldest"; }
17654: } else {
1.1275 raeburn 17655: # See if old ID present, if so, remove if this isn't a robot,
17656: # killing any existing non-robot sessions
1.463 albertel 17657: if (!$args->{'robot'}) {
17658: opendir(DIR,$lonids);
17659: while ($filename=readdir(DIR)) {
17660: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 17661: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
17662: &GDBM_READER(),0640)) {
1.1295 raeburn 17663: my $linkedfile;
1.1320 raeburn 17664: if (exists($oldenv{'user.linkedenv'})) {
17665: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 17666: }
1.1320 raeburn 17667: untie(%oldenv);
17668: if (unlink("$lonids/$filename")) {
17669: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
17670: if (-l "$lonids/$linkedfile.id") {
17671: unlink("$lonids/$linkedfile.id");
17672: }
1.1295 raeburn 17673: }
17674: }
17675: } else {
17676: unlink($lonids.'/'.$filename);
17677: }
1.463 albertel 17678: }
1.462 albertel 17679: }
1.463 albertel 17680: closedir(DIR);
1.1204 raeburn 17681: # If there is a undeleted lockfile for the user's paste buffer remove it.
17682: my $namespace = 'nohist_courseeditor';
17683: my $lockingkey = 'paste'."\0".'locked_num';
17684: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
17685: $domain,$username);
17686: if (exists($lockhash{$lockingkey})) {
17687: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
17688: unless ($delresult eq 'ok') {
17689: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
17690: }
17691: }
1.462 albertel 17692: }
17693: # Give them a new cookie
1.463 albertel 17694: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 17695: : $now.$$.int(rand(10000)));
1.463 albertel 17696: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 17697:
17698: # Initialize roles
17699:
1.1414 raeburn 17700: ($userroles,$firstaccenv,$timerintenv,$coauthorenv) =
1.1062 raeburn 17701: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 17702: }
17703: # ------------------------------------ Check browser type and MathML capability
17704:
1.1194 raeburn 17705: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
17706: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 17707:
17708: # ------------------------------------------------------------- Get environment
17709:
17710: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
17711: my ($tmp) = keys(%userenv);
1.1275 raeburn 17712: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 17713: undef(%userenv);
17714: }
17715: if (($userenv{'interface'}) && (!$form->{'interface'})) {
17716: $form->{'interface'}=$userenv{'interface'};
17717: }
17718: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
17719:
17720: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 17721: foreach my $option ('interface','localpath','localres') {
17722: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 17723: }
17724: # --------------------------------------------------------- Write first profile
17725:
17726: {
1.1350 raeburn 17727: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 17728: my %initial_env =
17729: ("user.name" => $username,
17730: "user.domain" => $domain,
17731: "user.home" => $authhost,
17732: "browser.type" => $clientbrowser,
17733: "browser.version" => $clientversion,
17734: "browser.mathml" => $clientmathml,
17735: "browser.unicode" => $clientunicode,
17736: "browser.os" => $clientos,
1.1137 raeburn 17737: "browser.mobile" => $clientmobile,
1.1141 raeburn 17738: "browser.info" => $clientinfo,
1.1194 raeburn 17739: "browser.osversion" => $clientosversion,
1.462 albertel 17740: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
17741: "request.course.fn" => '',
17742: "request.course.uri" => '',
17743: "request.course.sec" => '',
17744: "request.role" => 'cm',
17745: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 17746: "request.host" => $ip,);
1.462 albertel 17747:
17748: if ($form->{'localpath'}) {
17749: $initial_env{"browser.localpath"} = $form->{'localpath'};
17750: $initial_env{"browser.localres"} = $form->{'localres'};
17751: }
17752:
17753: if ($form->{'interface'}) {
17754: $form->{'interface'}=~s/\W//gs;
17755: $initial_env{"browser.interface"} = $form->{'interface'};
17756: $env{'browser.interface'}=$form->{'interface'};
17757: }
17758:
1.1157 raeburn 17759: if ($form->{'iptoken'}) {
17760: my $lonhost = $r->dir_config('lonHostID');
17761: $initial_env{"user.noloadbalance"} = $lonhost;
17762: $env{'user.noloadbalance'} = $lonhost;
17763: }
17764:
1.1268 raeburn 17765: if ($form->{'noloadbalance'}) {
17766: my @hosts = &Apache::lonnet::current_machine_ids();
17767: my $hosthere = $form->{'noloadbalance'};
17768: if (grep(/^\Q$hosthere\E$/,@hosts)) {
17769: $initial_env{"user.noloadbalance"} = $hosthere;
17770: $env{'user.noloadbalance'} = $hosthere;
17771: }
17772: }
17773:
1.1016 raeburn 17774: unless ($domain eq 'public') {
1.1273 raeburn 17775: my %is_adv = ( is_adv => $env{'user.adv'} );
17776: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
17777:
1.1414 raeburn 17778: foreach my $tool ('aboutme','blog','webdav','portfolio','portaccess','timezone') {
17779: $userenv{'availabletools.'.$tool} =
1.1273 raeburn 17780: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
17781: undef,\%userenv,\%domdef,\%is_adv);
17782: }
1.980 raeburn 17783:
1.1311 raeburn 17784: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 17785: $userenv{'canrequest.'.$crstype} =
17786: &Apache::lonnet::usertools_access($username,$domain,$crstype,
17787: 'reload','requestcourses',
17788: \%userenv,\%domdef,\%is_adv);
17789: }
1.724 raeburn 17790:
1.1418 ! raeburn 17791: if ((ref($userroles) eq 'HASH') && ($userroles->{'user.author'}) &&
! 17792: (exists($userroles->{"user.role.au./$domain/"}))) {
! 17793: if ($userenv{'authoreditors'}) {
! 17794: $userenv{'editors'} = $userenv{'authoreditors'};
! 17795: } elsif ($domdef{'editors'} ne '') {
! 17796: $userenv{'editors'} = $domdef{'editors'};
! 17797: } else {
! 17798: $userenv{'editors'} = 'edit,xml';
! 17799: }
! 17800: }
! 17801:
1.1273 raeburn 17802: $userenv{'canrequest.author'} =
17803: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
17804: 'reload','requestauthor',
1.980 raeburn 17805: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 17806: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
17807: $domain,$username);
17808: my $reqstatus = $reqauthor{'author_status'};
17809: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
17810: if (ref($reqauthor{'author'}) eq 'HASH') {
17811: $userenv{'requestauthorqueued'} = $reqstatus.':'.
17812: $reqauthor{'author'}{'timestamp'};
17813: }
1.1092 raeburn 17814: }
1.1287 raeburn 17815: my ($types,$typename) = &course_types();
17816: if (ref($types) eq 'ARRAY') {
17817: my @options = ('approval','validate','autolimit');
17818: my $optregex = join('|',@options);
17819: my (%willtrust,%trustchecked);
17820: foreach my $type (@{$types}) {
17821: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
17822: if ($dom_str ne '') {
17823: my $updatedstr = '';
17824: my @possdomains = split(',',$dom_str);
17825: foreach my $entry (@possdomains) {
17826: my ($extdom,$extopt) = split(':',$entry);
17827: unless ($trustchecked{$extdom}) {
17828: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
17829: $trustchecked{$extdom} = 1;
17830: }
17831: if ($willtrust{$extdom}) {
17832: $updatedstr .= $entry.',';
17833: }
17834: }
17835: $updatedstr =~ s/,$//;
17836: if ($updatedstr) {
17837: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
17838: } else {
17839: delete($userenv{'reqcrsotherdom.'.$type});
17840: }
17841: }
17842: }
17843: }
1.1092 raeburn 17844: }
1.462 albertel 17845: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 17846:
1.462 albertel 17847: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
17848: &GDBM_WRCREAT(),0640)) {
17849: &_add_to_env(\%disk_env,\%initial_env);
17850: &_add_to_env(\%disk_env,\%userenv,'environment.');
17851: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 17852: if (ref($firstaccenv) eq 'HASH') {
17853: &_add_to_env(\%disk_env,$firstaccenv);
17854: }
17855: if (ref($timerintenv) eq 'HASH') {
17856: &_add_to_env(\%disk_env,$timerintenv);
17857: }
1.1414 raeburn 17858: if (ref($coauthorenv) eq 'HASH') {
17859: if (keys(%{$coauthorenv})) {
17860: &_add_to_env(\%disk_env,$coauthorenv);
17861: }
17862: }
1.463 albertel 17863: if (ref($args->{'extra_env'})) {
17864: &_add_to_env(\%disk_env,$args->{'extra_env'});
17865: }
1.462 albertel 17866: untie(%disk_env);
17867: } else {
1.705 tempelho 17868: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
17869: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 17870: return 'error: '.$!;
17871: }
17872: }
17873: $env{'request.role'}='cm';
17874: $env{'request.role.adv'}=$env{'user.adv'};
17875: $env{'browser.type'}=$clientbrowser;
17876:
17877: return $cookie;
17878:
17879: }
17880:
17881: sub _add_to_env {
17882: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 17883: if (ref($env_data) eq 'HASH') {
17884: while (my ($key,$value) = each(%$env_data)) {
17885: $idf->{$prefix.$key} = $value;
17886: $env{$prefix.$key} = $value;
17887: }
1.462 albertel 17888: }
17889: }
17890:
1.685 tempelho 17891: # --- Get the symbolic name of a problem and the url
17892: sub get_symb {
17893: my ($request,$silent) = @_;
1.726 raeburn 17894: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 17895: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
17896: if ($symb eq '') {
17897: if (!$silent) {
1.1071 raeburn 17898: if (ref($request)) {
17899: $request->print("Unable to handle ambiguous references:$url:.");
17900: }
1.685 tempelho 17901: return ();
17902: }
17903: }
17904: &Apache::lonenc::check_decrypt(\$symb);
17905: return ($symb);
17906: }
17907:
17908: # --------------------------------------------------------------Get annotation
17909:
17910: sub get_annotation {
17911: my ($symb,$enc) = @_;
17912:
17913: my $key = $symb;
17914: if (!$enc) {
17915: $key =
17916: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
17917: }
17918: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
17919: return $annotation{$key};
17920: }
17921:
17922: sub clean_symb {
1.731 raeburn 17923: my ($symb,$delete_enc) = @_;
1.685 tempelho 17924:
17925: &Apache::lonenc::check_decrypt(\$symb);
17926: my $enc = $env{'request.enc'};
1.731 raeburn 17927: if ($delete_enc) {
1.730 raeburn 17928: delete($env{'request.enc'});
17929: }
1.685 tempelho 17930:
17931: return ($symb,$enc);
17932: }
1.462 albertel 17933:
1.1181 raeburn 17934: ############################################################
17935: ############################################################
17936:
17937: =pod
17938:
17939: =head1 Routines for building display used to search for courses
17940:
17941:
17942: =over 4
17943:
17944: =item * &build_filters()
17945:
17946: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 17947: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17948: and quotacheck.pl
17949:
1.1181 raeburn 17950:
17951: Inputs:
17952:
17953: filterlist - anonymous array of fields to include as potential filters
17954:
17955: crstype - course type
17956:
17957: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17958: to pop-open a course selector (will contain "extra element").
17959:
17960: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17961:
17962: filter - anonymous hash of criteria and their values
17963:
17964: action - form action
17965:
17966: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17967:
1.1182 raeburn 17968: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 17969:
17970: cloneruname - username of owner of new course who wants to clone
17971:
17972: clonerudom - domain of owner of new course who wants to clone
17973:
17974: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17975:
17976: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17977:
17978: codedom - domain
17979:
17980: formname - value of form element named "form".
17981:
17982: fixeddom - domain, if fixed.
17983:
17984: prevphase - value to assign to form element named "phase" when going back to the previous screen
17985:
17986: cnameelement - name of form element in form on opener page which will receive title of selected course
17987:
17988: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17989:
17990: cdomelement - name of form element in form on opener page which will receive domain of selected course
17991:
17992: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17993:
17994: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17995:
17996: clonewarning - warning message about missing information for intended course owner when DC creates a course
17997:
1.1182 raeburn 17998:
1.1181 raeburn 17999: Returns: $output - HTML for display of search criteria, and hidden form elements.
18000:
1.1182 raeburn 18001:
1.1181 raeburn 18002: Side Effects: None
18003:
18004: =cut
18005:
18006: # ---------------------------------------------- search for courses based on last activity etc.
18007:
18008: sub build_filters {
18009: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
18010: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
18011: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
18012: $cnameelement,$cnumelement,$cdomelement,$setroles,
18013: $clonetext,$clonewarning) = @_;
1.1182 raeburn 18014: my ($list,$jscript);
1.1181 raeburn 18015: my $onchange = 'javascript:updateFilters(this)';
18016: my ($domainselectform,$sincefilterform,$createdfilterform,
18017: $ownerdomselectform,$persondomselectform,$instcodeform,
18018: $typeselectform,$instcodetitle);
18019: if ($formname eq '') {
18020: $formname = $caller;
18021: }
18022: foreach my $item (@{$filterlist}) {
18023: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
18024: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
18025: if ($item eq 'domainfilter') {
18026: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
18027: } elsif ($item eq 'coursefilter') {
18028: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
18029: } elsif ($item eq 'ownerfilter') {
18030: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
18031: } elsif ($item eq 'ownerdomfilter') {
18032: $filter->{'ownerdomfilter'} =
18033: &LONCAPA::clean_domain($filter->{$item});
18034: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
18035: 'ownerdomfilter',1);
18036: } elsif ($item eq 'personfilter') {
18037: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
18038: } elsif ($item eq 'persondomfilter') {
18039: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
18040: 'persondomfilter',1);
18041: } else {
18042: $filter->{$item} =~ s/\W//g;
18043: }
18044: if (!$filter->{$item}) {
18045: $filter->{$item} = '';
18046: }
18047: }
18048: if ($item eq 'domainfilter') {
18049: my $allow_blank = 1;
18050: if ($formname eq 'portform') {
18051: $allow_blank=0;
18052: } elsif ($formname eq 'studentform') {
18053: $allow_blank=0;
18054: }
18055: if ($fixeddom) {
18056: $domainselectform = '<input type="hidden" name="domainfilter"'.
18057: ' value="'.$codedom.'" />'.
18058: &Apache::lonnet::domain($codedom,'description');
18059: } else {
18060: $domainselectform = &select_dom_form($filter->{$item},
18061: 'domainfilter',
18062: $allow_blank,'',$onchange);
18063: }
18064: } else {
18065: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
18066: }
18067: }
18068:
18069: # last course activity filter and selection
18070: $sincefilterform = &timebased_select_form('sincefilter',$filter);
18071:
18072: # course created filter and selection
18073: if (exists($filter->{'createdfilter'})) {
18074: $createdfilterform = &timebased_select_form('createdfilter',$filter);
18075: }
18076:
1.1239 raeburn 18077: my $prefix = $crstype;
18078: if ($crstype eq 'Placement') {
18079: $prefix = 'Placement Test'
18080: }
1.1181 raeburn 18081: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 18082: 'cac' => "$prefix Activity",
18083: 'ccr' => "$prefix Created",
18084: 'cde' => "$prefix Title",
18085: 'cdo' => "$prefix Domain",
1.1181 raeburn 18086: 'ins' => 'Institutional Code',
18087: 'inc' => 'Institutional Categorization',
1.1239 raeburn 18088: 'cow' => "$prefix Owner/Co-owner",
18089: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 18090: 'cog' => 'Type',
18091: );
18092:
18093: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
18094: my $typeval = 'Course';
18095: if ($crstype eq 'Community') {
18096: $typeval = 'Community';
1.1239 raeburn 18097: } elsif ($crstype eq 'Placement') {
18098: $typeval = 'Placement';
1.1181 raeburn 18099: }
18100: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
18101: } else {
18102: $typeselectform = '<select name="type" size="1"';
18103: if ($onchange) {
18104: $typeselectform .= ' onchange="'.$onchange.'"';
18105: }
18106: $typeselectform .= '>'."\n";
1.1237 raeburn 18107: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 18108: my $shown;
18109: if ($posstype eq 'Placement') {
18110: $shown = &mt('Placement Test');
18111: } else {
18112: $shown = &mt($posstype);
18113: }
1.1181 raeburn 18114: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 18115: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 18116: }
18117: $typeselectform.="</select>";
18118: }
18119:
18120: my ($cloneableonlyform,$cloneabletitle);
18121: if (exists($filter->{'cloneableonly'})) {
18122: my $cloneableon = '';
18123: my $cloneableoff = ' checked="checked"';
18124: if ($filter->{'cloneableonly'}) {
18125: $cloneableon = $cloneableoff;
18126: $cloneableoff = '';
18127: }
18128: $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>';
18129: if ($formname eq 'ccrs') {
1.1187 bisitz 18130: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 18131: } else {
18132: $cloneabletitle = &mt('Cloneable by you');
18133: }
18134: }
18135: my $officialjs;
18136: if ($crstype eq 'Course') {
18137: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 18138: # if (($fixeddom) || ($formname eq 'requestcrs') ||
18139: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
18140: if ($codedom) {
1.1181 raeburn 18141: $officialjs = 1;
18142: ($instcodeform,$jscript,$$numtitlesref) =
18143: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
18144: $officialjs,$codetitlesref);
18145: if ($jscript) {
1.1182 raeburn 18146: $jscript = '<script type="text/javascript">'."\n".
18147: '// <![CDATA['."\n".
18148: $jscript."\n".
18149: '// ]]>'."\n".
18150: '</script>'."\n";
1.1181 raeburn 18151: }
18152: }
18153: if ($instcodeform eq '') {
18154: $instcodeform =
18155: '<input type="text" name="instcodefilter" size="10" value="'.
18156: $list->{'instcodefilter'}.'" />';
18157: $instcodetitle = $lt{'ins'};
18158: } else {
18159: $instcodetitle = $lt{'inc'};
18160: }
18161: if ($fixeddom) {
18162: $instcodetitle .= '<br />('.$codedom.')';
18163: }
18164: }
18165: }
18166: my $output = qq|
18167: <form method="post" name="filterpicker" action="$action">
18168: <input type="hidden" name="form" value="$formname" />
18169: |;
18170: if ($formname eq 'modifycourse') {
18171: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
18172: '<input type="hidden" name="prevphase" value="'.
18173: $prevphase.'" />'."\n";
1.1198 musolffc 18174: } elsif ($formname eq 'quotacheck') {
18175: $output .= qq|
18176: <input type="hidden" name="sortby" value="" />
18177: <input type="hidden" name="sortorder" value="" />
18178: |;
18179: } else {
1.1181 raeburn 18180: my $name_input;
18181: if ($cnameelement ne '') {
18182: $name_input = '<input type="hidden" name="cnameelement" value="'.
18183: $cnameelement.'" />';
18184: }
18185: $output .= qq|
1.1182 raeburn 18186: <input type="hidden" name="cnumelement" value="$cnumelement" />
18187: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 18188: $name_input
18189: $roleelement
18190: $multelement
18191: $typeelement
18192: |;
18193: if ($formname eq 'portform') {
18194: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
18195: }
18196: }
18197: if ($fixeddom) {
18198: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
18199: }
18200: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
18201: if ($sincefilterform) {
18202: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
18203: .$sincefilterform
18204: .&Apache::lonhtmlcommon::row_closure();
18205: }
18206: if ($createdfilterform) {
18207: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
18208: .$createdfilterform
18209: .&Apache::lonhtmlcommon::row_closure();
18210: }
18211: if ($domainselectform) {
18212: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
18213: .$domainselectform
18214: .&Apache::lonhtmlcommon::row_closure();
18215: }
18216: if ($typeselectform) {
18217: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
18218: $output .= $typeselectform;
18219: } else {
18220: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
18221: .$typeselectform
18222: .&Apache::lonhtmlcommon::row_closure();
18223: }
18224: }
18225: if ($instcodeform) {
18226: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
18227: .$instcodeform
18228: .&Apache::lonhtmlcommon::row_closure();
18229: }
18230: if (exists($filter->{'ownerfilter'})) {
18231: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
18232: '<table><tr><td>'.&mt('Username').'<br />'.
18233: '<input type="text" name="ownerfilter" size="20" value="'.
18234: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18235: $ownerdomselectform.'</td></tr></table>'.
18236: &Apache::lonhtmlcommon::row_closure();
18237: }
18238: if (exists($filter->{'personfilter'})) {
18239: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
18240: '<table><tr><td>'.&mt('Username').'<br />'.
18241: '<input type="text" name="personfilter" size="20" value="'.
18242: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18243: $persondomselectform.'</td></tr></table>'.
18244: &Apache::lonhtmlcommon::row_closure();
18245: }
18246: if (exists($filter->{'coursefilter'})) {
18247: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
18248: .'<input type="text" name="coursefilter" size="25" value="'
18249: .$list->{'coursefilter'}.'" />'
18250: .&Apache::lonhtmlcommon::row_closure();
18251: }
18252: if ($cloneableonlyform) {
18253: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
18254: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
18255: }
18256: if (exists($filter->{'descriptfilter'})) {
18257: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
18258: .'<input type="text" name="descriptfilter" size="40" value="'
18259: .$list->{'descriptfilter'}.'" />'
18260: .&Apache::lonhtmlcommon::row_closure(1);
18261: }
18262: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
18263: '<input type="hidden" name="updater" value="" />'."\n".
18264: '<input type="submit" name="gosearch" value="'.
18265: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
18266: return $jscript.$clonewarning.$output;
18267: }
18268:
18269: =pod
18270:
18271: =item * &timebased_select_form()
18272:
1.1182 raeburn 18273: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 18274: filter e.g., Course Activity, Course Created, when searching for courses
18275: or communities
18276:
18277: Inputs:
18278:
18279: item - name of form element (sincefilter or createdfilter)
18280:
18281: filter - anonymous hash of criteria and their values
18282:
18283: Returns: HTML for a select box contained a blank, then six time selections,
18284: with value set in incoming form variables currently selected.
18285:
18286: Side Effects: None
18287:
18288: =cut
18289:
18290: sub timebased_select_form {
18291: my ($item,$filter) = @_;
18292: if (ref($filter) eq 'HASH') {
18293: $filter->{$item} =~ s/[^\d-]//g;
18294: if (!$filter->{$item}) { $filter->{$item}=-1; }
18295: return &select_form(
18296: $filter->{$item},
18297: $item,
18298: { '-1' => '',
18299: '86400' => &mt('today'),
18300: '604800' => &mt('last week'),
18301: '2592000' => &mt('last month'),
18302: '7776000' => &mt('last three months'),
18303: '15552000' => &mt('last six months'),
18304: '31104000' => &mt('last year'),
18305: 'select_form_order' =>
18306: ['-1','86400','604800','2592000','7776000',
18307: '15552000','31104000']});
18308: }
18309: }
18310:
18311: =pod
18312:
18313: =item * &js_changer()
18314:
18315: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 18316: when course type or domain is changed, and also to hide 'Searching ...' on
18317: page load completion for page showing search result.
1.1181 raeburn 18318:
18319: Inputs: None
18320:
1.1183 raeburn 18321: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 18322:
18323: Side Effects: None
18324:
18325: =cut
18326:
18327: sub js_changer {
18328: return <<ENDJS;
18329: <script type="text/javascript">
18330: // <![CDATA[
18331: function updateFilters(caller) {
18332: if (typeof(caller) != "undefined") {
18333: document.filterpicker.updater.value = caller.name;
18334: }
18335: document.filterpicker.submit();
18336: }
1.1183 raeburn 18337:
18338: function hideSearching() {
18339: if (document.getElementById('searching')) {
18340: document.getElementById('searching').style.display = 'none';
18341: }
18342: return;
18343: }
18344:
1.1181 raeburn 18345: // ]]>
18346: </script>
18347:
18348: ENDJS
18349: }
18350:
18351: =pod
18352:
1.1182 raeburn 18353: =item * &search_courses()
18354:
18355: Process selected filters form course search form and pass to lonnet::courseiddump
18356: to retrieve a hash for which keys are courseIDs which match the selected filters.
18357:
18358: Inputs:
18359:
18360: dom - domain being searched
18361:
18362: type - course type ('Course' or 'Community' or '.' if any).
18363:
18364: filter - anonymous hash of criteria and their values
18365:
18366: numtitles - for institutional codes - number of categories
18367:
18368: cloneruname - optional username of new course owner
18369:
18370: clonerudom - optional domain of new course owner
18371:
1.1221 raeburn 18372: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 18373: (used when DC is using course creation form)
18374:
18375: codetitles - reference to array of titles of components in institutional codes (official courses).
18376:
1.1221 raeburn 18377: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
18378: (and so can clone automatically)
18379:
18380: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
18381:
18382: reqinstcode - institutional code of new course, where search_courses is used to identify potential
18383: courses to clone
1.1182 raeburn 18384:
18385: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
18386:
18387:
18388: Side Effects: None
18389:
18390: =cut
18391:
18392:
18393: sub search_courses {
1.1221 raeburn 18394: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
18395: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 18396: my (%courses,%showcourses,$cloner);
18397: if (($filter->{'ownerfilter'} ne '') ||
18398: ($filter->{'ownerdomfilter'} ne '')) {
18399: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
18400: $filter->{'ownerdomfilter'};
18401: }
18402: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
18403: if (!$filter->{$item}) {
18404: $filter->{$item}='.';
18405: }
18406: }
18407: my $now = time;
18408: my $timefilter =
18409: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
18410: my ($createdbefore,$createdafter);
18411: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
18412: $createdbefore = $now;
18413: $createdafter = $now-$filter->{'createdfilter'};
18414: }
18415: my ($instcodefilter,$regexpok);
18416: if ($numtitles) {
18417: if ($env{'form.official'} eq 'on') {
18418: $instcodefilter =
18419: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18420: $regexpok = 1;
18421: } elsif ($env{'form.official'} eq 'off') {
18422: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18423: unless ($instcodefilter eq '') {
18424: $regexpok = -1;
18425: }
18426: }
18427: } else {
18428: $instcodefilter = $filter->{'instcodefilter'};
18429: }
18430: if ($instcodefilter eq '') { $instcodefilter = '.'; }
18431: if ($type eq '') { $type = '.'; }
18432:
18433: if (($clonerudom ne '') && ($cloneruname ne '')) {
18434: $cloner = $cloneruname.':'.$clonerudom;
18435: }
18436: %courses = &Apache::lonnet::courseiddump($dom,
18437: $filter->{'descriptfilter'},
18438: $timefilter,
18439: $instcodefilter,
18440: $filter->{'combownerfilter'},
18441: $filter->{'coursefilter'},
18442: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 18443: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 18444: $filter->{'cloneableonly'},
18445: $createdbefore,$createdafter,undef,
1.1221 raeburn 18446: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 18447: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
18448: my $ccrole;
18449: if ($type eq 'Community') {
18450: $ccrole = 'co';
18451: } else {
18452: $ccrole = 'cc';
18453: }
18454: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
18455: $filter->{'persondomfilter'},
18456: 'userroles',undef,
18457: [$ccrole,'in','ad','ep','ta','cr'],
18458: $dom);
18459: foreach my $role (keys(%rolehash)) {
18460: my ($cnum,$cdom,$courserole) = split(':',$role);
18461: my $cid = $cdom.'_'.$cnum;
18462: if (exists($courses{$cid})) {
18463: if (ref($courses{$cid}) eq 'HASH') {
18464: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
18465: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 18466: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 18467: }
18468: } else {
18469: $courses{$cid}{roles} = [$courserole];
18470: }
18471: $showcourses{$cid} = $courses{$cid};
18472: }
18473: }
18474: }
18475: %courses = %showcourses;
18476: }
18477: return %courses;
18478: }
18479:
18480: =pod
18481:
1.1181 raeburn 18482: =back
18483:
1.1207 raeburn 18484: =head1 Routines for version requirements for current course.
18485:
18486: =over 4
18487:
18488: =item * &check_release_required()
18489:
18490: Compares required LON-CAPA version with version on server, and
18491: if required version is newer looks for a server with the required version.
18492:
18493: Looks first at servers in user's owen domain; if none suitable, looks at
18494: servers in course's domain are permitted to host sessions for user's domain.
18495:
18496: Inputs:
18497:
18498: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18499:
18500: $courseid - Course ID of current course
18501:
18502: $rolecode - User's current role in course (for switchserver query string).
18503:
18504: $required - LON-CAPA version needed by course (format: Major.Minor).
18505:
18506:
18507: Returns:
18508:
18509: $switchserver - query string tp append to /adm/switchserver call (if
18510: current server's LON-CAPA version is too old.
18511:
18512: $warning - Message is displayed if no suitable server could be found.
18513:
18514: =cut
18515:
18516: sub check_release_required {
18517: my ($loncaparev,$courseid,$rolecode,$required) = @_;
18518: my ($switchserver,$warning);
18519: if ($required ne '') {
18520: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
18521: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18522: if ($reqdmajor ne '' && $reqdminor ne '') {
18523: my $otherserver;
18524: if (($major eq '' && $minor eq '') ||
18525: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
18526: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
18527: my $switchlcrev =
18528: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
18529: $userdomserver);
18530: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18531: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
18532: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
18533: my $cdom = $env{'course.'.$courseid.'.domain'};
18534: if ($cdom ne $env{'user.domain'}) {
18535: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
18536: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
18537: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18538: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
18539: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
18540: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
18541: my $canhost =
18542: &Apache::lonnet::can_host_session($env{'user.domain'},
18543: $coursedomserver,
18544: $remoterev,
18545: $udomdefaults{'remotesessions'},
18546: $defdomdefaults{'hostedsessions'});
18547:
18548: if ($canhost) {
18549: $otherserver = $coursedomserver;
18550: } else {
18551: $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.");
18552: }
18553: } else {
18554: $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).");
18555: }
18556: } else {
18557: $otherserver = $userdomserver;
18558: }
18559: }
18560: if ($otherserver ne '') {
18561: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
18562: }
18563: }
18564: }
18565: return ($switchserver,$warning);
18566: }
18567:
18568: =pod
18569:
18570: =item * &check_release_result()
18571:
18572: Inputs:
18573:
18574: $switchwarning - Warning message if no suitable server found to host session.
18575:
18576: $switchserver - query string to append to /adm/switchserver containing lonHostID
18577: and current role.
18578:
18579: Returns: HTML to display with information about requirement to switch server.
18580: Either displaying warning with link to Roles/Courses screen or
18581: display link to switchserver.
18582:
1.1181 raeburn 18583: =cut
18584:
1.1207 raeburn 18585: sub check_release_result {
18586: my ($switchwarning,$switchserver) = @_;
18587: my $output = &start_page('Selected course unavailable on this server').
18588: '<p class="LC_warning">';
18589: if ($switchwarning) {
18590: $output .= $switchwarning.'<br /><a href="/adm/roles">';
18591: if (&show_course()) {
18592: $output .= &mt('Display courses');
18593: } else {
18594: $output .= &mt('Display roles');
18595: }
18596: $output .= '</a>';
18597: } elsif ($switchserver) {
18598: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
18599: '<br />'.
18600: '<a href="/adm/switchserver?'.$switchserver.'">'.
18601: &mt('Switch Server').
18602: '</a>';
18603: }
18604: $output .= '</p>'.&end_page();
18605: return $output;
18606: }
18607:
18608: =pod
18609:
18610: =item * &needs_coursereinit()
18611:
18612: Determine if course contents stored for user's session needs to be
18613: refreshed, because content has changed since "Big Hash" last tied.
18614:
18615: Check for change is made if time last checked is more than 10 minutes ago
18616: (by default).
18617:
18618: Inputs:
18619:
18620: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18621:
18622: $interval (optional) - Time which may elapse (in s) between last check for content
18623: change in current course. (default: 600 s).
18624:
18625: Returns: an array; first element is:
18626:
18627: =over 4
18628:
18629: 'switch' - if content updates mean user's session
18630: needs to be switched to a server running a newer LON-CAPA version
18631:
18632: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
18633: on current server hosting user's session
18634:
18635: '' - if no action required.
18636:
18637: =back
18638:
18639: If first item element is 'switch':
18640:
18641: second item is $switchwarning - Warning message if no suitable server found to host session.
18642:
18643: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
18644: and current role.
18645:
18646: otherwise: no other elements returned.
18647:
18648: =back
18649:
18650: =cut
18651:
18652: sub needs_coursereinit {
18653: my ($loncaparev,$interval) = @_;
18654: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
18655: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18656: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18657: my $now = time;
18658: if ($interval eq '') {
18659: $interval = 600;
18660: }
18661: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 18662: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1372 raeburn 18663: my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 18664: if ($blocked) {
18665: return ();
18666: }
1.1391 raeburn 18667: my $update;
18668: my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
18669: my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);
18670: if ($lastmainchange > $env{'request.course.tied'}) {
18671: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18672: if ($needswitch) {
18673: return ('switch',$switchwarning,$switchserver);
18674: }
18675: $update = 'main';
18676: }
18677: if ($lastsuppchange > $env{'request.course.suppupdated'}) {
18678: if ($update) {
18679: $update = 'both';
18680: } else {
18681: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18682: if ($needswitch) {
18683: return ('switch',$switchwarning,$switchserver);
18684: } else {
18685: $update = 'supp';
1.1207 raeburn 18686: }
18687: }
1.1391 raeburn 18688: return ($update);
18689: }
18690: }
18691: return ();
18692: }
18693:
18694: sub switch_for_update {
18695: my ($loncaparev,$cdom,$cnum) = @_;
18696: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18697: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
18698: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
18699: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
18700: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
18701: $curr_reqd_hash{'internal.releaserequired'}});
18702: my ($switchserver,$switchwarning) =
18703: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
18704: $curr_reqd_hash{'internal.releaserequired'});
18705: if ($switchwarning ne '' || $switchserver ne '') {
18706: return ('switch',$switchwarning,$switchserver);
18707: }
1.1207 raeburn 18708: }
18709: }
18710: return ();
18711: }
1.1181 raeburn 18712:
1.1083 raeburn 18713: sub update_content_constraints {
1.1395 raeburn 18714: my ($cdom,$cnum,$chome,$cid) = @_;
1.1083 raeburn 18715: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18716: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 18717: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 18718: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 18719: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 18720: if ($item eq 'resourcetag') {
18721: if ($name eq 'responsetype') {
18722: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
18723: }
1.1307 raeburn 18724: } elsif ($item eq 'course') {
18725: if ($name eq 'courserestype') {
18726: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
18727: }
1.1083 raeburn 18728: }
18729: }
18730: my $navmap = Apache::lonnavmaps::navmap->new();
18731: if (defined($navmap)) {
1.1307 raeburn 18732: my (%allresponses,%allcrsrestypes);
18733: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
18734: if ($res->is_tool()) {
18735: if ($allcrsrestypes{'exttool'}) {
18736: $allcrsrestypes{'exttool'} ++;
18737: } else {
18738: $allcrsrestypes{'exttool'} = 1;
18739: }
18740: next;
18741: }
1.1083 raeburn 18742: my %responses = $res->responseTypes();
18743: foreach my $key (keys(%responses)) {
18744: next unless(exists($checkresponsetypes{$key}));
18745: $allresponses{$key} += $responses{$key};
18746: }
18747: }
18748: foreach my $key (keys(%allresponses)) {
18749: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
18750: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18751: ($reqdmajor,$reqdminor) = ($major,$minor);
18752: }
18753: }
1.1307 raeburn 18754: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 18755: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 18756: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18757: ($reqdmajor,$reqdminor) = ($major,$minor);
18758: }
18759: }
1.1083 raeburn 18760: undef($navmap);
18761: }
1.1391 raeburn 18762: if (&Apache::lonnet::count_supptools($cnum,$cdom,1)) {
1.1308 raeburn 18763: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
18764: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18765: ($reqdmajor,$reqdminor) = ($major,$minor);
18766: }
18767: }
1.1083 raeburn 18768: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
18769: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
18770: }
18771: return;
18772: }
18773:
1.1110 raeburn 18774: sub allmaps_incourse {
18775: my ($cdom,$cnum,$chome,$cid) = @_;
18776: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
18777: $cid = $env{'request.course.id'};
18778: $cdom = $env{'course.'.$cid.'.domain'};
18779: $cnum = $env{'course.'.$cid.'.num'};
18780: $chome = $env{'course.'.$cid.'.home'};
18781: }
18782: my %allmaps = ();
18783: my $lastchange =
18784: &Apache::lonnet::get_coursechange($cdom,$cnum);
18785: if ($lastchange > $env{'request.course.tied'}) {
18786: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
18787: unless ($ferr) {
1.1395 raeburn 18788: &update_content_constraints($cdom,$cnum,$chome,$cid);
1.1110 raeburn 18789: }
18790: }
18791: my $navmap = Apache::lonnavmaps::navmap->new();
18792: if (defined($navmap)) {
18793: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
18794: $allmaps{$res->src()} = 1;
18795: }
18796: }
18797: return \%allmaps;
18798: }
18799:
1.1083 raeburn 18800: sub parse_supplemental_title {
18801: my ($title) = @_;
18802:
18803: my ($foldertitle,$renametitle);
18804: if ($title =~ /&&&/) {
18805: $title = &HTML::Entites::decode($title);
18806: }
18807: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
18808: $renametitle=$4;
18809: my ($time,$uname,$udom) = ($1,$2,$3);
18810: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
18811: my $name = &plainname($uname,$udom);
18812: $name = &HTML::Entities::encode($name,'"<>&\'');
18813: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.1401 raeburn 18814: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
1.1402 raeburn 18815: if ($foldertitle ne '') {
1.1401 raeburn 18816: $title .= ': <br />'.$foldertitle;
18817: }
1.1083 raeburn 18818: }
18819: if (wantarray) {
18820: return ($title,$foldertitle,$renametitle);
18821: }
18822: return $title;
18823: }
18824:
1.1395 raeburn 18825: sub get_supplemental {
18826: my ($cnum,$cdom,$ignorecache,$possdel)=@_;
18827: my $hashid=$cnum.':'.$cdom;
18828: my ($supplemental,$cached,$set_httprefs);
18829: unless ($ignorecache) {
18830: ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);
18831: }
18832: unless (defined($cached)) {
18833: my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
18834: unless ($chome eq 'no_host') {
18835: my @order = @LONCAPA::map::order;
18836: my @resources = @LONCAPA::map::resources;
18837: my @resparms = @LONCAPA::map::resparms;
18838: my @zombies = @LONCAPA::map::zombies;
18839: my ($errors,%ids,%hidden);
18840: $errors =
18841: &recurse_supplemental($cnum,$cdom,'supplemental.sequence',
18842: $errors,$possdel,\%ids,\%hidden);
18843: @LONCAPA::map::order = @order;
18844: @LONCAPA::map::resources = @resources;
18845: @LONCAPA::map::resparms = @resparms;
18846: @LONCAPA::map::zombies = @zombies;
18847: $set_httprefs = 1;
18848: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18849: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18850: }
18851: $supplemental = {
18852: ids => \%ids,
18853: hidden => \%hidden,
18854: };
18855: &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);
18856: }
18857: }
18858: return ($supplemental,$set_httprefs);
18859: }
18860:
1.1143 raeburn 18861: sub recurse_supplemental {
1.1391 raeburn 18862: my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;
18863: if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {
18864: my $mapnum;
18865: if ($suppmap eq 'supplemental.sequence') {
18866: $mapnum = 0;
18867: } else {
18868: ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);
18869: }
1.1143 raeburn 18870: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
18871: if ($fatal) {
18872: $errors ++;
18873: } else {
1.1389 raeburn 18874: my @order = @LONCAPA::map::order;
18875: if (@order > 0) {
18876: my @resources = @LONCAPA::map::resources;
1.1391 raeburn 18877: my @resparms = @LONCAPA::map::resparms;
1.1389 raeburn 18878: foreach my $idx (@order) {
18879: my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1143 raeburn 18880: if (($src ne '') && ($status eq 'res')) {
1.1391 raeburn 18881: my $id = $mapnum.':'.$idx;
18882: push(@{$suppids->{$src}},$id);
18883: if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {
18884: $hiddensupp->{$id} = 1;
18885: }
1.1146 raeburn 18886: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1391 raeburn 18887: $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,
18888: $hiddensupp,$hiddensupp->{$id});
1.1143 raeburn 18889: } else {
1.1391 raeburn 18890: my $allowed;
18891: if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {
18892: $allowed = 1;
18893: } elsif ($possdel) {
18894: foreach my $item (@{$suppids->{$src}}) {
18895: next if ($item eq $id);
18896: unless ($hiddensupp->{$item}) {
18897: $allowed = 1;
18898: last;
18899: }
18900: }
18901: if ((!$allowed) && (exists($env{'httpref.'.$src}))) {
18902: &Apache::lonnet::delenv('httpref.'.$src);
18903: }
18904: }
18905: if ($allowed && (!exists($env{'httpref.'.$src}))) {
18906: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
1.1308 raeburn 18907: }
1.1143 raeburn 18908: }
18909: }
18910: }
18911: }
18912: }
18913: }
1.1391 raeburn 18914: return $errors;
18915: }
18916:
18917: sub set_supp_httprefs {
18918: my ($cnum,$cdom,$supplemental,$possdel) = @_;
18919: if (ref($supplemental) eq 'HASH') {
18920: if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {
18921: foreach my $src (keys(%{$supplemental->{'ids'}})) {
18922: next if ($src =~ /\.sequence$/);
18923: if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {
18924: my $allowed;
18925: if ($env{'request.role.adv'}) {
18926: $allowed = 1;
18927: } else {
18928: foreach my $id (@{$supplemental->{'ids'}->{$src}}) {
18929: unless ($supplemental->{'hidden'}->{$id}) {
18930: $allowed = 1;
18931: last;
18932: }
18933: }
18934: }
18935: if (exists($env{'httpref.'.$src})) {
18936: if ($possdel) {
18937: unless ($allowed) {
18938: &Apache::lonnet::delenv('httpref.'.$src);
18939: }
18940: }
18941: } elsif ($allowed) {
18942: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
18943: }
18944: }
18945: }
18946: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18947: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18948: }
18949: }
18950: }
18951: }
18952:
18953: sub get_supp_parameter {
18954: my ($resparm,$name)=@_;
18955: return if ($resparm eq '');
18956: my $value=undef;
18957: my $ptype=undef;
18958: foreach (split('&&&',$resparm)) {
18959: my ($thistype,$thisname,$thisvalue)=split('___',$_);
18960: if ($thisname eq $name) {
18961: $value=$thisvalue;
18962: $ptype=$thistype;
18963: }
18964: }
18965: return $value;
1.1143 raeburn 18966: }
18967:
1.1101 raeburn 18968: sub symb_to_docspath {
1.1267 raeburn 18969: my ($symb,$navmapref) = @_;
18970: return unless ($symb && ref($navmapref));
1.1101 raeburn 18971: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
18972: if ($resurl=~/\.(sequence|page)$/) {
18973: $mapurl=$resurl;
18974: } elsif ($resurl eq 'adm/navmaps') {
18975: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
18976: }
18977: my $mapresobj;
1.1267 raeburn 18978: unless (ref($$navmapref)) {
18979: $$navmapref = Apache::lonnavmaps::navmap->new();
18980: }
18981: if (ref($$navmapref)) {
18982: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 18983: }
18984: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
18985: my $type=$2;
18986: my $path;
18987: if (ref($mapresobj)) {
18988: my $pcslist = $mapresobj->map_hierarchy();
18989: if ($pcslist ne '') {
18990: foreach my $pc (split(/,/,$pcslist)) {
18991: next if ($pc <= 1);
1.1267 raeburn 18992: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 18993: if (ref($res)) {
18994: my $thisurl = $res->src();
18995: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18996: my $thistitle = $res->title();
18997: $path .= '&'.
18998: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 18999: &escape($thistitle).
1.1101 raeburn 19000: ':'.$res->randompick().
19001: ':'.$res->randomout().
19002: ':'.$res->encrypted().
19003: ':'.$res->randomorder().
19004: ':'.$res->is_page();
19005: }
19006: }
19007: }
19008: $path =~ s/^\&//;
19009: my $maptitle = $mapresobj->title();
19010: if ($mapurl eq 'default') {
1.1129 raeburn 19011: $maptitle = 'Main Content';
1.1101 raeburn 19012: }
19013: $path .= (($path ne '')? '&' : '').
19014: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 19015: &escape($maptitle).
1.1101 raeburn 19016: ':'.$mapresobj->randompick().
19017: ':'.$mapresobj->randomout().
19018: ':'.$mapresobj->encrypted().
19019: ':'.$mapresobj->randomorder().
19020: ':'.$mapresobj->is_page();
19021: } else {
19022: my $maptitle = &Apache::lonnet::gettitle($mapurl);
19023: my $ispage = (($type eq 'page')? 1 : '');
19024: if ($mapurl eq 'default') {
1.1129 raeburn 19025: $maptitle = 'Main Content';
1.1101 raeburn 19026: }
19027: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 19028: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 19029: }
19030: unless ($mapurl eq 'default') {
19031: $path = 'default&'.
1.1146 raeburn 19032: &escape('Main Content').
1.1101 raeburn 19033: ':::::&'.$path;
19034: }
19035: return $path;
19036: }
19037:
1.1393 raeburn 19038: sub validate_folderpath {
19039: my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;
19040: if ($env{'form.folderpath'} ne '') {
19041: my @items = split(/\&/,$env{'form.folderpath'});
1.1394 raeburn 19042: my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);
1.1393 raeburn 19043: for (my $i=0; $i<@items; $i++) {
19044: my $odd = $i%2;
19045: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
19046: $badpath = 1;
1.1394 raeburn 19047: } elsif ($odd && $supplementalflag) {
1.1393 raeburn 19048: my $idx = $i-1;
1.1394 raeburn 19049: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
19050: my $esc_name = $1;
19051: if ((!$allowed) || ($items[$idx] eq 'supplemental')) {
19052: $supppath .= '&'.$esc_name;
19053: $changed = 1;
19054: } else {
19055: $supppath .= '&'.$items[$i];
19056: }
19057: } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {
19058: $changed = 1;
1.1393 raeburn 19059: my $is_hidden;
19060: unless ($got_supp) {
1.1395 raeburn 19061: my ($supplemental) = &get_supplemental($coursenum,$coursedom);
1.1393 raeburn 19062: if (ref($supplemental) eq 'HASH') {
19063: if (ref($supplemental->{'hidden'}) eq 'HASH') {
19064: %supphidden = %{$supplemental->{'hidden'}};
19065: }
19066: if (ref($supplemental->{'ids'}) eq 'HASH') {
19067: %suppids = %{$supplemental->{'ids'}};
19068: }
19069: }
19070: $got_supp = 1;
19071: }
19072: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
19073: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
19074: if ($supphidden{$mapid}) {
19075: $is_hidden = 1;
19076: }
19077: }
1.1394 raeburn 19078: $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';
19079: } else {
19080: $supppath .= '&'.$items[$i];
1.1393 raeburn 19081: }
19082: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
19083: $badpath = 1;
1.1394 raeburn 19084: } elsif ($supplementalflag) {
1.1393 raeburn 19085: $supppath .= '&'.$items[$i];
19086: }
19087: last if ($badpath);
19088: }
19089: if ($badpath) {
19090: delete($env{'form.folderpath'});
1.1394 raeburn 19091: } elsif ($changed && $supplementalflag) {
1.1393 raeburn 19092: $supppath =~ s/^\&//;
19093: $env{'form.folderpath'} = $supppath;
19094: }
19095: }
19096: return;
19097: }
19098:
1.1094 raeburn 19099: sub captcha_display {
1.1327 raeburn 19100: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 19101: my ($output,$error);
1.1234 raeburn 19102: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 19103: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 19104: if ($captcha eq 'original') {
1.1094 raeburn 19105: $output = &create_captcha();
19106: unless ($output) {
1.1172 raeburn 19107: $error = 'captcha';
1.1094 raeburn 19108: }
19109: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 19110: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 19111: unless ($output) {
1.1172 raeburn 19112: $error = 'recaptcha';
1.1094 raeburn 19113: }
19114: }
1.1234 raeburn 19115: return ($output,$error,$captcha,$version);
1.1094 raeburn 19116: }
19117:
19118: sub captcha_response {
1.1327 raeburn 19119: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 19120: my ($captcha_chk,$captcha_error);
1.1327 raeburn 19121: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 19122: if ($captcha eq 'original') {
1.1094 raeburn 19123: ($captcha_chk,$captcha_error) = &check_captcha();
19124: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 19125: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 19126: } else {
19127: $captcha_chk = 1;
19128: }
19129: return ($captcha_chk,$captcha_error);
19130: }
19131:
19132: sub get_captcha_config {
1.1327 raeburn 19133: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 19134: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 19135: my $hostname = &Apache::lonnet::hostname($lonhost);
19136: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
19137: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 19138: if ($context eq 'usercreation') {
19139: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
19140: if (ref($domconfig{$context}) eq 'HASH') {
19141: $hashtocheck = $domconfig{$context}{'cancreate'};
19142: if (ref($hashtocheck) eq 'HASH') {
19143: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
19144: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
19145: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
19146: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
19147: }
19148: if ($privkey && $pubkey) {
19149: $captcha = 'recaptcha';
1.1234 raeburn 19150: $version = $hashtocheck->{'recaptchaversion'};
19151: if ($version ne '2') {
19152: $version = 1;
19153: }
1.1095 raeburn 19154: } else {
19155: $captcha = 'original';
19156: }
19157: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
19158: $captcha = 'original';
19159: }
1.1094 raeburn 19160: }
1.1095 raeburn 19161: } else {
19162: $captcha = 'captcha';
19163: }
19164: } elsif ($context eq 'login') {
19165: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
19166: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
19167: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
19168: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 19169: if ($privkey && $pubkey) {
19170: $captcha = 'recaptcha';
1.1234 raeburn 19171: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
19172: if ($version ne '2') {
19173: $version = 1;
19174: }
1.1095 raeburn 19175: } else {
19176: $captcha = 'original';
1.1094 raeburn 19177: }
1.1095 raeburn 19178: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
19179: $captcha = 'original';
1.1094 raeburn 19180: }
1.1327 raeburn 19181: } elsif ($context eq 'passwords') {
19182: if ($dom_in_effect) {
19183: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
19184: if ($passwdconf{'captcha'} eq 'recaptcha') {
19185: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
19186: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
19187: $privkey = $passwdconf{'recaptchakeys'}{'private'};
19188: }
19189: if ($privkey && $pubkey) {
19190: $captcha = 'recaptcha';
19191: $version = $passwdconf{'recaptchaversion'};
19192: if ($version ne '2') {
19193: $version = 1;
19194: }
19195: } else {
19196: $captcha = 'original';
19197: }
19198: } elsif ($passwdconf{'captcha'} ne 'notused') {
19199: $captcha = 'original';
19200: }
19201: }
19202: }
1.1234 raeburn 19203: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 19204: }
19205:
19206: sub create_captcha {
19207: my %captcha_params = &captcha_settings();
19208: my ($output,$maxtries,$tries) = ('',10,0);
19209: while ($tries < $maxtries) {
19210: $tries ++;
19211: my $captcha = Authen::Captcha->new (
19212: output_folder => $captcha_params{'output_dir'},
19213: data_folder => $captcha_params{'db_dir'},
19214: );
19215: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
19216:
19217: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
19218: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1367 raeburn 19219: '<span class="LC_nobreak">'.
1.1094 raeburn 19220: &mt('Type in the letters/numbers shown below').' '.
1.1390 raeburn 19221: '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1367 raeburn 19222: '</span><br />'.
1.1176 raeburn 19223: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 19224: last;
19225: }
19226: }
1.1323 raeburn 19227: if ($output eq '') {
19228: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
19229: }
1.1094 raeburn 19230: return $output;
19231: }
19232:
19233: sub captcha_settings {
19234: my %captcha_params = (
19235: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
19236: www_output_dir => "/captchaspool",
19237: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
19238: numchars => '5',
19239: );
19240: return %captcha_params;
19241: }
19242:
19243: sub check_captcha {
19244: my ($captcha_chk,$captcha_error);
19245: my $code = $env{'form.code'};
19246: my $md5sum = $env{'form.crypt'};
19247: my %captcha_params = &captcha_settings();
19248: my $captcha = Authen::Captcha->new(
19249: output_folder => $captcha_params{'output_dir'},
19250: data_folder => $captcha_params{'db_dir'},
19251: );
1.1109 raeburn 19252: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 19253: my %captcha_hash = (
19254: 0 => 'Code not checked (file error)',
19255: -1 => 'Failed: code expired',
19256: -2 => 'Failed: invalid code (not in database)',
19257: -3 => 'Failed: invalid code (code does not match crypt)',
19258: );
19259: if ($captcha_chk != 1) {
19260: $captcha_error = $captcha_hash{$captcha_chk}
19261: }
19262: return ($captcha_chk,$captcha_error);
19263: }
19264:
19265: sub create_recaptcha {
1.1234 raeburn 19266: my ($pubkey,$version) = @_;
19267: if ($version >= 2) {
1.1367 raeburn 19268: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
19269: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1234 raeburn 19270: } else {
19271: my $use_ssl;
19272: if ($ENV{'SERVER_PORT'} == 443) {
19273: $use_ssl = 1;
19274: }
19275: my $captcha = Captcha::reCAPTCHA->new;
19276: return $captcha->get_options_setter({theme => 'white'})."\n".
19277: $captcha->get_html($pubkey,undef,$use_ssl).
19278: &mt('If the text is hard to read, [_1] will replace them.',
19279: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
19280: '<br /><br />';
19281: }
1.1094 raeburn 19282: }
19283:
19284: sub check_recaptcha {
1.1234 raeburn 19285: my ($privkey,$version) = @_;
1.1094 raeburn 19286: my $captcha_chk;
1.1350 raeburn 19287: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 19288: if ($version >= 2) {
19289: my %info = (
19290: secret => $privkey,
19291: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 19292: remoteip => $ip,
1.1234 raeburn 19293: );
1.1280 raeburn 19294: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
19295: $request->content(join('&',map {
19296: my $name = escape($_);
19297: "$name=" . ( ref($info{$_}) eq 'ARRAY'
19298: ? join("&$name=", map {escape($_) } @{$info{$_}})
19299: : &escape($info{$_}) );
19300: } keys(%info)));
19301: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 19302: if ($response->is_success) {
19303: my $data = JSON::DWIW->from_json($response->decoded_content);
19304: if (ref($data) eq 'HASH') {
19305: if ($data->{'success'}) {
19306: $captcha_chk = 1;
19307: }
19308: }
19309: }
19310: } else {
19311: my $captcha = Captcha::reCAPTCHA->new;
19312: my $captcha_result =
19313: $captcha->check_answer(
19314: $privkey,
1.1350 raeburn 19315: $ip,
1.1234 raeburn 19316: $env{'form.recaptcha_challenge_field'},
19317: $env{'form.recaptcha_response_field'},
19318: );
19319: if ($captcha_result->{is_valid}) {
19320: $captcha_chk = 1;
19321: }
1.1094 raeburn 19322: }
19323: return $captcha_chk;
19324: }
19325:
1.1174 raeburn 19326: sub emailusername_info {
1.1244 raeburn 19327: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 19328: my %titles = &Apache::lonlocal::texthash (
19329: lastname => 'Last Name',
19330: firstname => 'First Name',
19331: institution => 'School/college/university',
19332: location => "School's city, state/province, country",
19333: web => "School's web address",
19334: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 19335: id => 'Student/Employee ID',
1.1174 raeburn 19336: );
19337: return (\@fields,\%titles);
19338: }
19339:
1.1161 raeburn 19340: sub cleanup_html {
19341: my ($incoming) = @_;
19342: my $outgoing;
19343: if ($incoming ne '') {
19344: $outgoing = $incoming;
19345: $outgoing =~ s/;/;/g;
19346: $outgoing =~ s/\#/#/g;
19347: $outgoing =~ s/\&/&/g;
19348: $outgoing =~ s/</</g;
19349: $outgoing =~ s/>/>/g;
19350: $outgoing =~ s/\(/(/g;
19351: $outgoing =~ s/\)/)/g;
19352: $outgoing =~ s/"/"/g;
19353: $outgoing =~ s/'/'/g;
19354: $outgoing =~ s/\$/$/g;
19355: $outgoing =~ s{/}{/}g;
19356: $outgoing =~ s/=/=/g;
19357: $outgoing =~ s/\\/\/g
19358: }
19359: return $outgoing;
19360: }
19361:
1.1190 musolffc 19362: # Checks for critical messages and returns a redirect url if one exists.
19363: # $interval indicates how often to check for messages.
1.1282 raeburn 19364: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 19365: sub critical_redirect {
1.1282 raeburn 19366: my ($interval,$context) = @_;
1.1356 raeburn 19367: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
19368: return ();
19369: }
1.1190 musolffc 19370: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 19371: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
19372: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
19373: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 19374: my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 19375: if ($blocked) {
19376: my $checkrole = "cm./$cdom/$cnum";
19377: if ($env{'request.course.sec'} ne '') {
19378: $checkrole .= "/$env{'request.course.sec'}";
19379: }
19380: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
19381: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
19382: return;
19383: }
19384: }
19385: }
1.1190 musolffc 19386: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
19387: $env{'user.name'});
19388: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 19389: my $redirecturl;
1.1190 musolffc 19390: if ($what[0]) {
1.1356 raeburn 19391: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1190 musolffc 19392: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 19393: my $url=&Apache::lonnet::absolute_url().$redirecturl;
19394: return (1, $url);
1.1190 musolffc 19395: }
1.1191 raeburn 19396: }
19397: }
19398: return ();
1.1190 musolffc 19399: }
19400:
1.1174 raeburn 19401: # Use:
19402: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
19403: #
19404: ##################################################
19405: # password associated functions #
19406: ##################################################
19407: sub des_keys {
19408: # Make a new key for DES encryption.
19409: # Each key has two parts which are returned separately.
19410: # Please note: Each key must be passed through the &hex function
19411: # before it is output to the web browser. The hex versions cannot
19412: # be used to decrypt.
19413: my @hexstr=('0','1','2','3','4','5','6','7',
19414: '8','9','a','b','c','d','e','f');
19415: my $lkey='';
19416: for (0..7) {
19417: $lkey.=$hexstr[rand(15)];
19418: }
19419: my $ukey='';
19420: for (0..7) {
19421: $ukey.=$hexstr[rand(15)];
19422: }
19423: return ($lkey,$ukey);
19424: }
19425:
19426: sub des_decrypt {
19427: my ($key,$cyphertext) = @_;
19428: my $keybin=pack("H16",$key);
19429: my $cypher;
19430: if ($Crypt::DES::VERSION>=2.03) {
19431: $cypher=new Crypt::DES $keybin;
19432: } else {
19433: $cypher=new DES $keybin;
19434: }
1.1233 raeburn 19435: my $plaintext='';
19436: my $cypherlength = length($cyphertext);
19437: my $numchunks = int($cypherlength/32);
19438: for (my $j=0; $j<$numchunks; $j++) {
19439: my $start = $j*32;
19440: my $cypherblock = substr($cyphertext,$start,32);
19441: my $chunk =
19442: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
19443: $chunk .=
19444: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
19445: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
19446: $plaintext .= $chunk;
19447: }
1.1174 raeburn 19448: return $plaintext;
19449: }
19450:
1.1344 raeburn 19451: sub get_requested_shorturls {
1.1309 raeburn 19452: my ($cdom,$cnum,$navmap) = @_;
19453: return unless (ref($navmap));
1.1344 raeburn 19454: my ($numnew,$errors);
1.1309 raeburn 19455: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
19456: if (@toshorten) {
19457: my (%maps,%resources,%titles);
19458: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
19459: 'shorturls',$cdom,$cnum);
19460: if (keys(%resources)) {
1.1344 raeburn 19461: my %tocreate;
1.1309 raeburn 19462: foreach my $item (sort {$a <=> $b} (@toshorten)) {
19463: my $symb = $resources{$item};
19464: if ($symb) {
19465: $tocreate{$cnum.'&'.$symb} = 1;
19466: }
19467: }
1.1344 raeburn 19468: if (keys(%tocreate)) {
19469: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
19470: \%tocreate);
19471: }
1.1309 raeburn 19472: }
1.1344 raeburn 19473: }
19474: return ($numnew,$errors);
19475: }
19476:
19477: sub make_short_symbs {
19478: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
19479: my ($numnew,@errors);
19480: if (ref($tocreateref) eq 'HASH') {
19481: my %tocreate = %{$tocreateref};
1.1309 raeburn 19482: if (keys(%tocreate)) {
19483: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
19484: my $su = Short::URL->new(no_vowels => 1);
19485: my $init = '';
19486: my (%newunique,%addcourse,%courseonly,%failed);
19487: # get lock on tiny db
19488: my $now = time;
1.1344 raeburn 19489: if ($lockuser eq '') {
19490: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
19491: }
1.1309 raeburn 19492: my $lockhash = {
1.1344 raeburn 19493: "lock\0$now" => $lockuser,
1.1309 raeburn 19494: };
19495: my $tries = 0;
19496: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
19497: my ($code,$error);
19498: while (($gotlock ne 'ok') && ($tries<3)) {
19499: $tries ++;
19500: sleep 1;
1.1319 raeburn 19501: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 19502: }
19503: if ($gotlock eq 'ok') {
19504: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
19505: \%addcourse,\%courseonly,\%failed);
19506: if (keys(%failed)) {
19507: my $numfailed = scalar(keys(%failed));
19508: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
19509: }
19510: if (keys(%newunique)) {
19511: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
19512: if ($putres eq 'ok') {
19513: $numnew = scalar(keys(%newunique));
19514: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
19515: unless ($newputres eq 'ok') {
19516: push(@errors,&mt('error: could not store course look-up of short URLs'));
19517: }
19518: } else {
19519: push(@errors,&mt('error: could not store unique six character URLs'));
19520: }
19521: }
19522: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
19523: unless ($dellockres eq 'ok') {
19524: push(@errors,&mt('error: could not release lockfile'));
19525: }
19526: } else {
19527: push(@errors,&mt('error: could not obtain lockfile'));
19528: }
19529: if (keys(%courseonly)) {
19530: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
19531: if ($result ne 'ok') {
19532: push(@errors,&mt('error: could not update course look-up of short URLs'));
19533: }
19534: }
19535: }
19536: }
19537: return ($numnew,\@errors);
19538: }
19539:
19540: sub shorten_symbs {
19541: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
19542: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
19543: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
19544: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
19545: my (%possibles,%collisions);
19546: foreach my $key (keys(%{$tocreate})) {
19547: my $num = String::CRC32::crc32($key);
19548: my $tiny = $su->encode($num,$init);
19549: if ($tiny) {
19550: $possibles{$tiny} = $key;
19551: }
19552: }
19553: if (!$init) {
19554: $init = 1;
19555: } else {
19556: $init ++;
19557: }
19558: if (keys(%possibles)) {
19559: my @posstiny = keys(%possibles);
19560: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
19561: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
19562: if (keys(%currtiny)) {
19563: foreach my $key (keys(%currtiny)) {
19564: next if ($currtiny{$key} eq '');
19565: if ($currtiny{$key} eq $possibles{$key}) {
19566: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
19567: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19568: $courseonly->{$tsymb} = $key;
19569: }
19570: } else {
19571: $collisions{$possibles{$key}} = 1;
19572: }
19573: delete($possibles{$key});
19574: }
19575: }
19576: foreach my $key (keys(%possibles)) {
19577: $newunique->{$key} = $possibles{$key};
19578: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
19579: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19580: $addcourse->{$tsymb} = $key;
19581: }
19582: }
19583: }
19584: if (keys(%collisions)) {
19585: if ($init <5) {
19586: if (!$init) {
19587: $init = 1;
19588: } else {
19589: $init ++;
19590: }
19591: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
19592: $newunique,$addcourse,$courseonly,$failed);
19593: } else {
19594: foreach my $key (keys(%collisions)) {
19595: $failed->{$key} = 1;
19596: }
19597: }
19598: }
19599: return $init;
19600: }
19601:
1.1328 raeburn 19602: sub is_nonframeable {
1.1329 raeburn 19603: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
19604: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 19605: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 19606:
19607: $remprotocol = lc($remprotocol);
19608: $remhost = lc($remhost);
19609: my $remport = 80;
19610: if ($remprotocol eq 'https') {
19611: $remport = 443;
19612: }
1.1330 raeburn 19613: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 19614: if ($cached) {
19615: unless ($nocache) {
19616: if ($result) {
19617: return 1;
19618: } else {
19619: return 0;
19620: }
19621: }
19622: }
1.1328 raeburn 19623: my $uselink;
19624: my $request = new HTTP::Request('HEAD',$url);
19625: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
19626: if ($response->is_success()) {
19627: my $secpolicy = lc($response->header('content-security-policy'));
19628: my $xframeop = lc($response->header('x-frame-options'));
19629: $secpolicy =~ s/^\s+|\s+$//g;
19630: $xframeop =~ s/^\s+|\s+$//g;
19631: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 19632: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 19633: my ($origin,$protocol,$port);
19634: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
19635: $port = $ENV{'SERVER_PORT'};
19636: } else {
19637: $port = 80;
19638: }
19639: if ($absolute eq '') {
19640: $protocol = 'http:';
19641: if ($port == 443) {
19642: $protocol = 'https:';
19643: }
19644: $origin = $protocol.'//'.lc($hostname);
19645: } else {
19646: $origin = lc($absolute);
19647: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
19648: }
19649: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
19650: my $framepolicy = $1;
19651: $framepolicy =~ s/^\s+|\s+$//g;
19652: my @policies = split(/\s+/,$framepolicy);
19653: if (@policies) {
19654: if (grep(/^\Q'none'\E$/,@policies)) {
19655: $uselink = 1;
19656: } else {
19657: $uselink = 1;
19658: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
19659: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
19660: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
19661: undef($uselink);
19662: }
19663: if ($uselink) {
19664: if (grep(/^\Q'self'\E$/,@policies)) {
19665: if (($origin ne '') && ($remotehost eq $origin)) {
19666: undef($uselink);
19667: }
19668: }
19669: }
19670: if ($uselink) {
19671: my @possok;
19672: if ($ip ne '') {
19673: push(@possok,$ip);
19674: }
19675: my $hoststr = '';
19676: foreach my $part (reverse(split(/\./,$hostname))) {
19677: if ($hoststr eq '') {
19678: $hoststr = $part;
19679: } else {
19680: $hoststr = "$part.$hoststr";
19681: }
19682: if ($hoststr eq $hostname) {
19683: push(@possok,$hostname);
19684: } else {
19685: push(@possok,"*.$hoststr");
19686: }
19687: }
19688: if (@possok) {
19689: foreach my $poss (@possok) {
19690: last if (!$uselink);
19691: foreach my $policy (@policies) {
19692: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
19693: undef($uselink);
19694: last;
19695: }
19696: }
19697: }
19698: }
19699: }
19700: }
19701: }
19702: } elsif ($xframeop ne '') {
19703: $uselink = 1;
19704: my @policies = split(/\s*,\s*/,$xframeop);
19705: if (@policies) {
19706: unless (grep(/^deny$/,@policies)) {
19707: if ($origin ne '') {
19708: if (grep(/^sameorigin$/,@policies)) {
19709: if ($remotehost eq $origin) {
19710: undef($uselink);
19711: }
19712: }
19713: if ($uselink) {
19714: foreach my $policy (@policies) {
19715: if ($policy =~ /^allow-from\s*(.+)$/) {
19716: my $allowfrom = $1;
19717: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
19718: undef($uselink);
19719: last;
19720: }
19721: }
19722: }
19723: }
19724: }
19725: }
19726: }
19727: }
19728: }
19729: }
1.1329 raeburn 19730: if ($nocache) {
19731: if ($cached) {
19732: my $devalidate;
19733: if ($uselink && !$result) {
19734: $devalidate = 1;
19735: } elsif (!$uselink && $result) {
19736: $devalidate = 1;
19737: }
19738: if ($devalidate) {
19739: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
19740: }
19741: }
19742: } else {
19743: if ($uselink) {
19744: $result = 1;
19745: } else {
19746: $result = 0;
19747: }
19748: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
19749: }
1.1328 raeburn 19750: return $uselink;
19751: }
19752:
1.1359 raeburn 19753: sub page_menu {
19754: my ($menucolls,$menunum) = @_;
19755: my %menu;
19756: foreach my $item (split(/;/,$menucolls)) {
19757: my ($num,$value) = split(/\%/,$item);
19758: if ($num eq $menunum) {
19759: my @entries = split(/\&/,$value);
19760: foreach my $entry (@entries) {
19761: my ($name,$fields) = split(/=/,$entry);
1.1368 raeburn 19762: if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
1.1359 raeburn 19763: $menu{$name} = $fields;
19764: } else {
19765: my @shown;
19766: if ($fields =~ /,/) {
19767: @shown = split(/,/,$fields);
19768: } else {
19769: @shown = ($fields);
19770: }
19771: if (@shown) {
19772: foreach my $field (@shown) {
19773: next if ($field eq '');
19774: $menu{$field} = 1;
19775: }
19776: }
19777: }
19778: }
19779: }
19780: }
19781: return %menu;
19782: }
19783:
1.112 bowersj2 19784: 1;
19785: __END__;
1.41 ng 19786:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>