Annotation of loncom/interface/loncommon.pm, revision 1.1401
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1401 ! raeburn 4: # $Id: loncommon.pm,v 1.1400 2022/12/31 14:08:58 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.1280 raeburn 74: use LONCAPA::LWPReq;
1.1395 raeburn 75: use LONCAPA::map();
1.1328 raeburn 76: use HTTP::Request;
1.657 raeburn 77: use DateTime::TimeZone;
1.1241 raeburn 78: use DateTime::Locale;
1.1220 raeburn 79: use Encode();
1.1091 foxr 80: use Text::Aspell;
1.1094 raeburn 81: use Authen::Captcha;
82: use Captcha::reCAPTCHA;
1.1234 raeburn 83: use JSON::DWIW;
1.1174 raeburn 84: use Crypt::DES;
85: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 86: use MIME::Lite;
87: use MIME::Types;
1.1292 raeburn 88: use File::Copy();
1.1300 raeburn 89: use File::Path();
1.1309 raeburn 90: use String::CRC32();
91: use Short::URL();
1.117 www 92:
1.517 raeburn 93: # ---------------------------------------------- Designs
94: use vars qw(%defaultdesign);
95:
1.22 www 96: my $readit;
97:
1.517 raeburn 98:
1.157 matthew 99: ##
100: ## Global Variables
101: ##
1.46 matthew 102:
1.643 foxr 103:
104: # ----------------------------------------------- SSI with retries:
105: #
106:
107: =pod
108:
1.648 raeburn 109: =head1 Server Side include with retries:
1.643 foxr 110:
111: =over 4
112:
1.648 raeburn 113: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 114:
115: Performs an ssi with some number of retries. Retries continue either
116: until the result is ok or until the retry count supplied by the
117: caller is exhausted.
118:
119: Inputs:
1.648 raeburn 120:
121: =over 4
122:
1.643 foxr 123: resource - Identifies the resource to insert.
1.648 raeburn 124:
1.643 foxr 125: retries - Count of the number of retries allowed.
1.648 raeburn 126:
1.643 foxr 127: form - Hash that identifies the rendering options.
128:
1.648 raeburn 129: =back
130:
131: Returns:
132:
133: =over 4
134:
1.643 foxr 135: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 136:
1.643 foxr 137: response - The response from the last attempt (which may or may not have been successful.
138:
1.648 raeburn 139: =back
140:
141: =back
142:
1.643 foxr 143: =cut
144:
145: sub ssi_with_retries {
146: my ($resource, $retries, %form) = @_;
147:
148:
149: my $ok = 0; # True if we got a good response.
150: my $content;
151: my $response;
152:
153: # Try to get the ssi done. within the retries count:
154:
155: do {
156: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
157: $ok = $response->is_success;
1.650 www 158: if (!$ok) {
159: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
160: }
1.643 foxr 161: $retries--;
162: } while (!$ok && ($retries > 0));
163:
164: if (!$ok) {
165: $content = ''; # On error return an empty content.
166: }
167: return ($content, $response);
168:
169: }
170:
171:
172:
1.20 www 173: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 174: my %language;
1.124 www 175: my %supported_language;
1.1088 foxr 176: my %supported_codes;
1.1048 foxr 177: my %latex_language; # For choosing hyphenation in <transl..>
178: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 179: my %cprtag;
1.192 taceyjo1 180: my %scprtag;
1.351 www 181: my %fe; my %fd; my %fm;
1.41 ng 182: my %category_extensions;
1.12 harris41 183:
1.46 matthew 184: # ---------------------------------------------- Thesaurus variables
1.144 matthew 185: #
186: # %Keywords:
187: # A hash used by &keyword to determine if a word is considered a keyword.
188: # $thesaurus_db_file
189: # Scalar containing the full path to the thesaurus database.
1.46 matthew 190:
191: my %Keywords;
192: my $thesaurus_db_file;
193:
1.144 matthew 194: #
195: # Initialize values from language.tab, copyright.tab, filetypes.tab,
196: # thesaurus.tab, and filecategories.tab.
197: #
1.18 www 198: BEGIN {
1.46 matthew 199: # Variable initialization
200: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
201: #
1.22 www 202: unless ($readit) {
1.12 harris41 203: # ------------------------------------------------------------------- languages
204: {
1.158 raeburn 205: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
206: '/language.tab';
1.1317 raeburn 207: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 208: while (my $line = <$fh>) {
209: next if ($line=~/^\#/);
210: chomp($line);
1.1088 foxr 211: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 212: $language{$key}=$val.' - '.$enc;
213: if ($sup) {
214: $supported_language{$key}=$sup;
1.1088 foxr 215: $supported_codes{$key} = $code;
1.158 raeburn 216: }
1.1048 foxr 217: if ($latex) {
218: $latex_language_bykey{$key} = $latex;
1.1088 foxr 219: $latex_language{$code} = $latex;
1.1048 foxr 220: }
1.158 raeburn 221: }
222: close($fh);
223: }
1.12 harris41 224: }
225: # ------------------------------------------------------------------ copyrights
226: {
1.158 raeburn 227: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
228: '/copyright.tab';
1.1317 raeburn 229: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 230: while (my $line = <$fh>) {
231: next if ($line=~/^\#/);
232: chomp($line);
233: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 234: $cprtag{$key}=$val;
235: }
236: close($fh);
237: }
1.12 harris41 238: }
1.351 www 239: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 240: {
241: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
242: '/source_copyright.tab';
1.1317 raeburn 243: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 244: while (my $line = <$fh>) {
245: next if ($line =~ /^\#/);
246: chomp($line);
247: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 248: $scprtag{$key}=$val;
249: }
250: close($fh);
251: }
252: }
1.63 www 253:
1.517 raeburn 254: # -------------------------------------------------------------- default domain designs
1.63 www 255: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 256: my $designfile = $designdir.'/default.tab';
1.1317 raeburn 257: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 258: while (my $line = <$fh>) {
259: next if ($line =~ /^\#/);
260: chomp($line);
261: my ($key,$val)=(split(/\=/,$line));
262: if ($val) { $defaultdesign{$key}=$val; }
263: }
264: close($fh);
1.63 www 265: }
266:
1.15 harris41 267: # ------------------------------------------------------------- file categories
268: {
1.158 raeburn 269: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
270: '/filecategories.tab';
1.1317 raeburn 271: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 272: while (my $line = <$fh>) {
273: next if ($line =~ /^\#/);
274: chomp($line);
275: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 276: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 277: }
278: close($fh);
279: }
280:
1.15 harris41 281: }
1.12 harris41 282: # ------------------------------------------------------------------ file types
283: {
1.158 raeburn 284: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
285: '/filetypes.tab';
1.1317 raeburn 286: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 287: while (my $line = <$fh>) {
288: next if ($line =~ /^\#/);
289: chomp($line);
290: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 291: if ($descr ne '') {
292: $fe{$ending}=lc($emb);
293: $fd{$ending}=$descr;
1.351 www 294: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 295: }
296: }
297: close($fh);
298: }
1.12 harris41 299: }
1.22 www 300: &Apache::lonnet::logthis(
1.705 tempelho 301: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 302: $readit=1;
1.46 matthew 303: } # end of unless($readit)
1.32 matthew 304:
305: }
1.112 bowersj2 306:
1.42 matthew 307: ###############################################################
308: ## HTML and Javascript Helper Functions ##
309: ###############################################################
310:
311: =pod
312:
1.112 bowersj2 313: =head1 HTML and Javascript Functions
1.42 matthew 314:
1.112 bowersj2 315: =over 4
316:
1.648 raeburn 317: =item * &browser_and_searcher_javascript()
1.112 bowersj2 318:
319: X<browsing, javascript>X<searching, javascript>Returns a string
320: containing javascript with two functions, C<openbrowser> and
321: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
322: tags.
1.42 matthew 323:
1.648 raeburn 324: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 325:
326: inputs: formname, elementname, only, omit
327:
328: formname and elementname indicate the name of the html form and name of
329: the element that the results of the browsing selection are to be placed in.
330:
331: Specifying 'only' will restrict the browser to displaying only files
1.185 www 332: with the given extension. Can be a comma separated list.
1.42 matthew 333:
334: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 335: with the given extension. Can be a comma separated list.
1.42 matthew 336:
1.648 raeburn 337: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 338:
339: Inputs: formname, elementname
340:
341: formname and elementname specify the name of the html form and the name
342: of the element the selection from the search results will be placed in.
1.542 raeburn 343:
1.42 matthew 344: =cut
345:
346: sub browser_and_searcher_javascript {
1.199 albertel 347: my ($mode)=@_;
348: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 349: my $resurl=&escape_single(&lastresurl());
1.42 matthew 350: return <<END;
1.219 albertel 351: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 352: var editbrowser = null;
1.135 albertel 353: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 354: var url = '$resurl/?';
1.42 matthew 355: if (editbrowser == null) {
356: url += 'launch=1&';
357: }
358: url += 'catalogmode=interactive&';
1.199 albertel 359: url += 'mode=$mode&';
1.611 albertel 360: url += 'inhibitmenu=yes&';
1.42 matthew 361: url += 'form=' + formname + '&';
362: if (only != null) {
363: url += 'only=' + only + '&';
1.217 albertel 364: } else {
365: url += 'only=&';
366: }
1.42 matthew 367: if (omit != null) {
368: url += 'omit=' + omit + '&';
1.217 albertel 369: } else {
370: url += 'omit=&';
371: }
1.135 albertel 372: if (titleelement != null) {
373: url += 'titleelement=' + titleelement + '&';
1.217 albertel 374: } else {
375: url += 'titleelement=&';
376: }
1.42 matthew 377: url += 'element=' + elementname + '';
378: var title = 'Browser';
1.435 albertel 379: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 380: options += ',width=700,height=600';
381: editbrowser = open(url,title,options,'1');
382: editbrowser.focus();
383: }
384: var editsearcher;
1.135 albertel 385: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 386: var url = '/adm/searchcat?';
387: if (editsearcher == null) {
388: url += 'launch=1&';
389: }
390: url += 'catalogmode=interactive&';
1.199 albertel 391: url += 'mode=$mode&';
1.42 matthew 392: url += 'form=' + formname + '&';
1.135 albertel 393: if (titleelement != null) {
394: url += 'titleelement=' + titleelement + '&';
1.217 albertel 395: } else {
396: url += 'titleelement=&';
397: }
1.42 matthew 398: url += 'element=' + elementname + '';
399: var title = 'Search';
1.435 albertel 400: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 401: options += ',width=700,height=600';
402: editsearcher = open(url,title,options,'1');
403: editsearcher.focus();
404: }
1.219 albertel 405: // END LON-CAPA Internal -->
1.42 matthew 406: END
1.170 www 407: }
408:
409: sub lastresurl {
1.258 albertel 410: if ($env{'environment.lastresurl'}) {
411: return $env{'environment.lastresurl'}
1.170 www 412: } else {
413: return '/res';
414: }
415: }
416:
417: sub storeresurl {
418: my $resurl=&Apache::lonnet::clutter(shift);
419: unless ($resurl=~/^\/res/) { return 0; }
420: $resurl=~s/\/$//;
421: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 422: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 423: return 1;
1.42 matthew 424: }
425:
1.74 www 426: sub studentbrowser_javascript {
1.111 www 427: unless (
1.258 albertel 428: (($env{'request.course.id'}) &&
1.302 albertel 429: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
430: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
431: '/'.$env{'request.course.sec'})
432: ))
1.258 albertel 433: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 434: ) { return ''; }
1.74 www 435: return (<<'ENDSTDBRW');
1.776 bisitz 436: <script type="text/javascript" language="Javascript">
1.824 bisitz 437: // <![CDATA[
1.74 www 438: var stdeditbrowser;
1.1337 raeburn 439: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv) {
1.74 www 440: var url = '/adm/pickstudent?';
441: var filter;
1.558 albertel 442: if (!ignorefilter) {
443: eval('filter=document.'+formname+'.'+uname+'.value;');
444: }
1.74 www 445: if (filter != null) {
446: if (filter != '') {
447: url += 'filter='+filter+'&';
448: }
449: }
450: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 451: '&udomelement='+udom+
452: '&clicker='+clicker;
1.111 www 453: if (roleflag) { url+="&roles=1"; }
1.1337 raeburn 454: if (courseadv == 'condition') {
455: if (document.getElementById('courseadv')) {
456: courseadv = document.getElementById('courseadv').value;
457: }
458: }
459: if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.102 www 460: var title = 'Student_Browser';
1.74 www 461: var options = 'scrollbars=1,resizable=1,menubar=0';
462: options += ',width=700,height=600';
463: stdeditbrowser = open(url,title,options,'1');
464: stdeditbrowser.focus();
465: }
1.824 bisitz 466: // ]]>
1.74 www 467: </script>
468: ENDSTDBRW
469: }
1.42 matthew 470:
1.1003 www 471: sub resourcebrowser_javascript {
472: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 473: return (<<'ENDRESBRW');
1.1003 www 474: <script type="text/javascript" language="Javascript">
475: // <![CDATA[
476: var reseditbrowser;
1.1004 www 477: function openresbrowser(formname,reslink) {
1.1005 www 478: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 479: var title = 'Resource_Browser';
480: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 481: options += ',width=700,height=500';
1.1004 www 482: reseditbrowser = open(url,title,options,'1');
483: reseditbrowser.focus();
1.1003 www 484: }
485: // ]]>
486: </script>
1.1004 www 487: ENDRESBRW
1.1003 www 488: }
489:
1.74 www 490: sub selectstudent_link {
1.1337 raeburn 491: my ($form,$unameele,$udomele,$courseadv,$clickerid)=@_;
1.999 www 492: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
493: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
494: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 495: if ($env{'request.course.id'}) {
1.302 albertel 496: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
497: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
498: '/'.$env{'request.course.sec'})) {
1.111 www 499: return '';
500: }
1.999 www 501: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1337 raeburn 502: if ($courseadv eq 'only') {
503: $callargs .= ",'',1,'$courseadv'";
504: } elsif ($courseadv eq 'none') {
505: $callargs .= ",'','','$courseadv'";
506: } elsif ($courseadv eq 'condition') {
507: $callargs .= ",'','','$courseadv'";
1.793 raeburn 508: }
509: return '<span class="LC_nobreak">'.
510: '<a href="javascript:openstdbrowser('.$callargs.');">'.
511: &mt('Select User').'</a></span>';
1.74 www 512: }
1.258 albertel 513: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 514: $callargs .= ",'',1";
1.793 raeburn 515: return '<span class="LC_nobreak">'.
516: '<a href="javascript:openstdbrowser('.$callargs.');">'.
517: &mt('Select User').'</a></span>';
1.111 www 518: }
519: return '';
1.91 www 520: }
521:
1.1004 www 522: sub selectresource_link {
523: my ($form,$reslink,$arg)=@_;
524:
525: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
526: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
527: unless ($env{'request.course.id'}) { return $arg; }
528: return '<span class="LC_nobreak">'.
529: '<a href="javascript:openresbrowser('.$callargs.');">'.
530: $arg.'</a></span>';
531: }
532:
533:
534:
1.653 raeburn 535: sub authorbrowser_javascript {
536: return <<"ENDAUTHORBRW";
1.776 bisitz 537: <script type="text/javascript" language="JavaScript">
1.824 bisitz 538: // <![CDATA[
1.653 raeburn 539: var stdeditbrowser;
540:
541: function openauthorbrowser(formname,udom) {
542: var url = '/adm/pickauthor?';
543: url += 'form='+formname+'&roledom='+udom;
544: var title = 'Author_Browser';
545: var options = 'scrollbars=1,resizable=1,menubar=0';
546: options += ',width=700,height=600';
547: stdeditbrowser = open(url,title,options,'1');
548: stdeditbrowser.focus();
549: }
550:
1.824 bisitz 551: // ]]>
1.653 raeburn 552: </script>
553: ENDAUTHORBRW
554: }
555:
1.91 www 556: sub coursebrowser_javascript {
1.1116 raeburn 557: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 558: $credits_element,$instcode) = @_;
1.932 raeburn 559: my $wintitle = 'Course_Browser';
1.931 raeburn 560: if ($crstype eq 'Community') {
1.932 raeburn 561: $wintitle = 'Community_Browser';
1.909 raeburn 562: }
1.876 raeburn 563: my $id_functions = &javascript_index_functions();
564: my $output = '
1.776 bisitz 565: <script type="text/javascript" language="JavaScript">
1.824 bisitz 566: // <![CDATA[
1.468 raeburn 567: var stdeditbrowser;'."\n";
1.876 raeburn 568:
569: $output .= <<"ENDSTDBRW";
1.909 raeburn 570: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 571: var url = '/adm/pickcourse?';
1.895 raeburn 572: var formid = getFormIdByName(formname);
1.876 raeburn 573: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 574: if (domainfilter != null) {
575: if (domainfilter != '') {
576: url += 'domainfilter='+domainfilter+'&';
577: }
578: }
1.91 www 579: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 580: '&cdomelement='+udom+
581: '&cnameelement='+desc;
1.468 raeburn 582: if (extra_element !=null && extra_element != '') {
1.594 raeburn 583: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 584: url += '&roleelement='+extra_element;
585: if (domainfilter == null || domainfilter == '') {
586: url += '&domainfilter='+extra_element;
587: }
1.234 raeburn 588: }
1.468 raeburn 589: else {
590: if (formname == 'portform') {
591: url += '&setroles='+extra_element;
1.800 raeburn 592: } else {
593: if (formname == 'rules') {
594: url += '&fixeddom='+extra_element;
595: }
1.468 raeburn 596: }
597: }
1.230 raeburn 598: }
1.909 raeburn 599: if (type != null && type != '') {
600: url += '&type='+type;
601: }
602: if (type_elem != null && type_elem != '') {
603: url += '&typeelement='+type_elem;
604: }
1.872 raeburn 605: if (formname == 'ccrs') {
606: var ownername = document.forms[formid].ccuname.value;
607: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 608: url += '&cloner='+ownername+':'+ownerdom;
609: if (type == 'Course') {
610: url += '&crscode='+document.forms[formid].crscode.value;
611: }
1.1221 raeburn 612: }
613: if (formname == 'requestcrs') {
614: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 615: }
1.293 raeburn 616: if (multflag !=null && multflag != '') {
617: url += '&multiple='+multflag;
618: }
1.909 raeburn 619: var title = '$wintitle';
1.91 www 620: var options = 'scrollbars=1,resizable=1,menubar=0';
621: options += ',width=700,height=600';
622: stdeditbrowser = open(url,title,options,'1');
623: stdeditbrowser.focus();
624: }
1.876 raeburn 625: $id_functions
626: ENDSTDBRW
1.1116 raeburn 627: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
628: $output .= &setsec_javascript($sec_element,$formname,$role_element,
629: $credits_element);
1.876 raeburn 630: }
631: $output .= '
632: // ]]>
633: </script>';
634: return $output;
635: }
636:
637: sub javascript_index_functions {
638: return <<"ENDJS";
639:
640: function getFormIdByName(formname) {
641: for (var i=0;i<document.forms.length;i++) {
642: if (document.forms[i].name == formname) {
643: return i;
644: }
645: }
646: return -1;
647: }
648:
649: function getIndexByName(formid,item) {
650: for (var i=0;i<document.forms[formid].elements.length;i++) {
651: if (document.forms[formid].elements[i].name == item) {
652: return i;
653: }
654: }
655: return -1;
656: }
1.468 raeburn 657:
1.876 raeburn 658: function getDomainFromSelectbox(formname,udom) {
659: var userdom;
660: var formid = getFormIdByName(formname);
661: if (formid > -1) {
662: var domid = getIndexByName(formid,udom);
663: if (domid > -1) {
664: if (document.forms[formid].elements[domid].type == 'select-one') {
665: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
666: }
667: if (document.forms[formid].elements[domid].type == 'hidden') {
668: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 669: }
670: }
671: }
1.876 raeburn 672: return userdom;
673: }
674:
675: ENDJS
1.468 raeburn 676:
1.876 raeburn 677: }
678:
1.1017 raeburn 679: sub javascript_array_indexof {
1.1018 raeburn 680: return <<ENDJS;
1.1017 raeburn 681: <script type="text/javascript" language="JavaScript">
682: // <![CDATA[
683:
684: if (!Array.prototype.indexOf) {
685: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
686: "use strict";
687: if (this === void 0 || this === null) {
688: throw new TypeError();
689: }
690: var t = Object(this);
691: var len = t.length >>> 0;
692: if (len === 0) {
693: return -1;
694: }
695: var n = 0;
696: if (arguments.length > 0) {
697: n = Number(arguments[1]);
1.1088 foxr 698: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 699: n = 0;
700: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
701: n = (n > 0 || -1) * Math.floor(Math.abs(n));
702: }
703: }
704: if (n >= len) {
705: return -1;
706: }
707: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
708: for (; k < len; k++) {
709: if (k in t && t[k] === searchElement) {
710: return k;
711: }
712: }
713: return -1;
714: }
715: }
716:
717: // ]]>
718: </script>
719:
720: ENDJS
721:
722: }
723:
1.876 raeburn 724: sub userbrowser_javascript {
725: my $id_functions = &javascript_index_functions();
726: return <<"ENDUSERBRW";
727:
1.888 raeburn 728: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 729: var url = '/adm/pickuser?';
730: var userdom = getDomainFromSelectbox(formname,udom);
731: if (userdom != null) {
732: if (userdom != '') {
733: url += 'srchdom='+userdom+'&';
734: }
735: }
736: url += 'form=' + formname + '&unameelement='+uname+
737: '&udomelement='+udom+
738: '&ulastelement='+ulast+
739: '&ufirstelement='+ufirst+
740: '&uemailelement='+uemail+
1.881 raeburn 741: '&hideudomelement='+hideudom+
742: '&coursedom='+crsdom;
1.888 raeburn 743: if ((caller != null) && (caller != undefined)) {
744: url += '&caller='+caller;
745: }
1.876 raeburn 746: var title = 'User_Browser';
747: var options = 'scrollbars=1,resizable=1,menubar=0';
748: options += ',width=700,height=600';
749: var stdeditbrowser = open(url,title,options,'1');
750: stdeditbrowser.focus();
751: }
752:
1.888 raeburn 753: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 754: var formid = getFormIdByName(formname);
755: if (formid > -1) {
1.888 raeburn 756: var unameid = getIndexByName(formid,uname);
1.876 raeburn 757: var domid = getIndexByName(formid,udom);
758: var hidedomid = getIndexByName(formid,origdom);
759: if (hidedomid > -1) {
760: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 761: var unameval = document.forms[formid].elements[unameid].value;
762: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
763: if (domid > -1) {
764: var slct = document.forms[formid].elements[domid];
765: if (slct.type == 'select-one') {
766: var i;
767: for (i=0;i<slct.length;i++) {
768: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
769: }
770: }
771: if (slct.type == 'hidden') {
772: slct.value = fixeddom;
1.876 raeburn 773: }
774: }
1.468 raeburn 775: }
776: }
777: }
1.876 raeburn 778: return;
779: }
780:
781: $id_functions
782: ENDUSERBRW
1.468 raeburn 783: }
784:
785: sub setsec_javascript {
1.1116 raeburn 786: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 787: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
788: $communityrolestr);
789: if ($role_element ne '') {
790: my @allroles = ('st','ta','ep','in','ad');
791: foreach my $crstype ('Course','Community') {
792: if ($crstype eq 'Community') {
793: foreach my $role (@allroles) {
794: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
795: }
796: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
797: } else {
798: foreach my $role (@allroles) {
799: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
800: }
801: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
802: }
803: }
804: $rolestr = '"'.join('","',@allroles).'"';
805: $courserolestr = '"'.join('","',@courserolenames).'"';
806: $communityrolestr = '"'.join('","',@communityrolenames).'"';
807: }
1.468 raeburn 808: my $setsections = qq|
809: function setSect(sectionlist) {
1.629 raeburn 810: var sectionsArray = new Array();
811: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
812: sectionsArray = sectionlist.split(",");
813: }
1.468 raeburn 814: var numSections = sectionsArray.length;
815: document.$formname.$sec_element.length = 0;
816: if (numSections == 0) {
817: document.$formname.$sec_element.multiple=false;
818: document.$formname.$sec_element.size=1;
819: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
820: } else {
821: if (numSections == 1) {
822: document.$formname.$sec_element.multiple=false;
823: document.$formname.$sec_element.size=1;
824: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
825: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
826: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
827: } else {
828: for (var i=0; i<numSections; i++) {
829: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
830: }
831: document.$formname.$sec_element.multiple=true
832: if (numSections < 3) {
833: document.$formname.$sec_element.size=numSections;
834: } else {
835: document.$formname.$sec_element.size=3;
836: }
837: document.$formname.$sec_element.options[0].selected = false
838: }
839: }
1.91 www 840: }
1.905 raeburn 841:
842: function setRole(crstype) {
1.468 raeburn 843: |;
1.905 raeburn 844: if ($role_element eq '') {
845: $setsections .= ' return;
846: }
847: ';
848: } else {
849: $setsections .= qq|
850: var elementLength = document.$formname.$role_element.length;
851: var allroles = Array($rolestr);
852: var courserolenames = Array($courserolestr);
853: var communityrolenames = Array($communityrolestr);
854: if (elementLength != undefined) {
855: if (document.$formname.$role_element.options[5].value == 'cc') {
856: if (crstype == 'Course') {
857: return;
858: } else {
859: allroles[5] = 'co';
860: for (var i=0; i<6; i++) {
861: document.$formname.$role_element.options[i].value = allroles[i];
862: document.$formname.$role_element.options[i].text = communityrolenames[i];
863: }
864: }
865: } else {
866: if (crstype == 'Community') {
867: return;
868: } else {
869: allroles[5] = 'cc';
870: for (var i=0; i<6; i++) {
871: document.$formname.$role_element.options[i].value = allroles[i];
872: document.$formname.$role_element.options[i].text = courserolenames[i];
873: }
874: }
875: }
876: }
877: return;
878: }
879: |;
880: }
1.1116 raeburn 881: if ($credits_element) {
882: $setsections .= qq|
883: function setCredits(defaultcredits) {
884: document.$formname.$credits_element.value = defaultcredits;
885: return;
886: }
887: |;
888: }
1.468 raeburn 889: return $setsections;
890: }
891:
1.91 www 892: sub selectcourse_link {
1.909 raeburn 893: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
894: $typeelement) = @_;
895: my $type = $selecttype;
1.871 raeburn 896: my $linktext = &mt('Select Course');
897: if ($selecttype eq 'Community') {
1.909 raeburn 898: $linktext = &mt('Select Community');
1.1239 raeburn 899: } elsif ($selecttype eq 'Placement') {
900: $linktext = &mt('Select Placement Test');
1.906 raeburn 901: } elsif ($selecttype eq 'Course/Community') {
902: $linktext = &mt('Select Course/Community');
1.909 raeburn 903: $type = '';
1.1019 raeburn 904: } elsif ($selecttype eq 'Select') {
905: $linktext = &mt('Select');
906: $type = '';
1.871 raeburn 907: }
1.787 bisitz 908: return '<span class="LC_nobreak">'
909: ."<a href='"
910: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
911: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 912: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 913: ."'>".$linktext.'</a>'
1.787 bisitz 914: .'</span>';
1.74 www 915: }
1.42 matthew 916:
1.653 raeburn 917: sub selectauthor_link {
918: my ($form,$udom)=@_;
919: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
920: &mt('Select Author').'</a>';
921: }
922:
1.876 raeburn 923: sub selectuser_link {
1.881 raeburn 924: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 925: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 926: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 927: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 928: ');">'.$linktext.'</a>';
1.876 raeburn 929: }
930:
1.273 raeburn 931: sub check_uncheck_jscript {
932: my $jscript = <<"ENDSCRT";
933: function checkAll(field) {
934: if (field.length > 0) {
935: for (i = 0; i < field.length; i++) {
1.1093 raeburn 936: if (!field[i].disabled) {
937: field[i].checked = true;
938: }
1.273 raeburn 939: }
940: } else {
1.1093 raeburn 941: if (!field.disabled) {
942: field.checked = true;
943: }
1.273 raeburn 944: }
945: }
946:
947: function uncheckAll(field) {
948: if (field.length > 0) {
949: for (i = 0; i < field.length; i++) {
950: field[i].checked = false ;
1.543 albertel 951: }
952: } else {
1.273 raeburn 953: field.checked = false ;
954: }
955: }
956: ENDSCRT
957: return $jscript;
958: }
959:
1.656 www 960: sub select_timezone {
1.1387 raeburn 961: my ($name,$selected,$onchange,$includeempty,$id,$disabled)=@_;
962: my $output='<select name="'.$name.'" '.$id.$onchange.$disabled.'>'."\n";
1.659 raeburn 963: if ($includeempty) {
964: $output .= '<option value=""';
965: if (($selected eq '') || ($selected eq 'local')) {
966: $output .= ' selected="selected" ';
967: }
968: $output .= '> </option>';
969: }
1.657 raeburn 970: my @timezones = DateTime::TimeZone->all_names;
971: foreach my $tzone (@timezones) {
972: $output.= '<option value="'.$tzone.'"';
973: if ($tzone eq $selected) {
974: $output.=' selected="selected"';
975: }
976: $output.=">$tzone</option>\n";
1.656 www 977: }
978: $output.="</select>";
979: return $output;
980: }
1.273 raeburn 981:
1.687 raeburn 982: sub select_datelocale {
1.1256 raeburn 983: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
984: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 985: if ($includeempty) {
986: $output .= '<option value=""';
987: if ($selected eq '') {
988: $output .= ' selected="selected" ';
989: }
990: $output .= '> </option>';
991: }
1.1241 raeburn 992: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 993: my (@possibles,%locale_names);
1.1241 raeburn 994: my @locales = DateTime::Locale->ids();
995: foreach my $id (@locales) {
996: if ($id ne '') {
997: my ($en_terr,$native_terr);
998: my $loc = DateTime::Locale->load($id);
999: if (ref($loc)) {
1000: $en_terr = $loc->name();
1001: $native_terr = $loc->native_name();
1.687 raeburn 1002: if (grep(/^en$/,@languages) || !@languages) {
1003: if ($en_terr ne '') {
1004: $locale_names{$id} = '('.$en_terr.')';
1005: } elsif ($native_terr ne '') {
1006: $locale_names{$id} = $native_terr;
1007: }
1008: } else {
1009: if ($native_terr ne '') {
1010: $locale_names{$id} = $native_terr.' ';
1011: } elsif ($en_terr ne '') {
1012: $locale_names{$id} = '('.$en_terr.')';
1013: }
1014: }
1.1220 raeburn 1015: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1016: push(@possibles,$id);
1017: }
1.687 raeburn 1018: }
1019: }
1020: foreach my $item (sort(@possibles)) {
1021: $output.= '<option value="'.$item.'"';
1022: if ($item eq $selected) {
1023: $output.=' selected="selected"';
1024: }
1025: $output.=">$item";
1026: if ($locale_names{$item} ne '') {
1.1220 raeburn 1027: $output.=' '.$locale_names{$item};
1.687 raeburn 1028: }
1029: $output.="</option>\n";
1030: }
1031: $output.="</select>";
1032: return $output;
1033: }
1034:
1.792 raeburn 1035: sub select_language {
1.1256 raeburn 1036: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1037: my %langchoices;
1038: if ($includeempty) {
1.1117 raeburn 1039: %langchoices = ('' => 'No language preference');
1.792 raeburn 1040: }
1041: foreach my $id (&languageids()) {
1042: my $code = &supportedlanguagecode($id);
1043: if ($code) {
1044: $langchoices{$code} = &plainlanguagedescription($id);
1045: }
1046: }
1.1117 raeburn 1047: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1048: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1049: }
1050:
1.42 matthew 1051: =pod
1.36 matthew 1052:
1.1088 foxr 1053:
1054: =item * &list_languages()
1055:
1056: Returns an array reference that is suitable for use in language prompters.
1057: Each array element is itself a two element array. The first element
1058: is the language code. The second element a descsriptiuon of the
1059: language itself. This is suitable for use in e.g.
1060: &Apache::edit::select_arg (once dereferenced that is).
1061:
1062: =cut
1063:
1064: sub list_languages {
1065: my @lang_choices;
1066:
1067: foreach my $id (&languageids()) {
1068: my $code = &supportedlanguagecode($id);
1069: if ($code) {
1070: my $selector = $supported_codes{$id};
1071: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1072: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1073: }
1074: }
1075: return \@lang_choices;
1076: }
1077:
1078: =pod
1079:
1.648 raeburn 1080: =item * &linked_select_forms(...)
1.36 matthew 1081:
1082: linked_select_forms returns a string containing a <script></script> block
1083: and html for two <select> menus. The select menus will be linked in that
1084: changing the value of the first menu will result in new values being placed
1085: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1086: order unless a defined order is provided.
1.36 matthew 1087:
1088: linked_select_forms takes the following ordered inputs:
1089:
1090: =over 4
1091:
1.112 bowersj2 1092: =item * $formname, the name of the <form> tag
1.36 matthew 1093:
1.112 bowersj2 1094: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1095:
1.112 bowersj2 1096: =item * $firstdefault, the default value for the first menu
1.36 matthew 1097:
1.112 bowersj2 1098: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1099:
1.112 bowersj2 1100: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1101:
1.112 bowersj2 1102: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1103:
1.609 raeburn 1104: =item * $menuorder, the order of values in the first menu
1105:
1.1115 raeburn 1106: =item * $onchangefirst, additional javascript call to execute for an onchange
1107: event for the first <select> tag
1108:
1109: =item * $onchangesecond, additional javascript call to execute for an onchange
1110: event for the second <select> tag
1111:
1.1245 raeburn 1112: =item * $suffix, to differentiate separate uses of select2data javascript
1113: objects in a page.
1114:
1.41 ng 1115: =back
1116:
1.36 matthew 1117: Below is an example of such a hash. Only the 'text', 'default', and
1118: 'select2' keys must appear as stated. keys(%menu) are the possible
1119: values for the first select menu. The text that coincides with the
1.41 ng 1120: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1121: and text for the second menu are given in the hash pointed to by
1122: $menu{$choice1}->{'select2'}.
1123:
1.112 bowersj2 1124: my %menu = ( A1 => { text =>"Choice A1" ,
1125: default => "B3",
1126: select2 => {
1127: B1 => "Choice B1",
1128: B2 => "Choice B2",
1129: B3 => "Choice B3",
1130: B4 => "Choice B4"
1.609 raeburn 1131: },
1132: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1133: },
1134: A2 => { text =>"Choice A2" ,
1135: default => "C2",
1136: select2 => {
1137: C1 => "Choice C1",
1138: C2 => "Choice C2",
1139: C3 => "Choice C3"
1.609 raeburn 1140: },
1141: order => ['C2','C1','C3'],
1.112 bowersj2 1142: },
1143: A3 => { text =>"Choice A3" ,
1144: default => "D6",
1145: select2 => {
1146: D1 => "Choice D1",
1147: D2 => "Choice D2",
1148: D3 => "Choice D3",
1149: D4 => "Choice D4",
1150: D5 => "Choice D5",
1151: D6 => "Choice D6",
1152: D7 => "Choice D7"
1.609 raeburn 1153: },
1154: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1155: }
1156: );
1.36 matthew 1157:
1158: =cut
1159:
1160: sub linked_select_forms {
1161: my ($formname,
1162: $middletext,
1163: $firstdefault,
1164: $firstselectname,
1165: $secondselectname,
1.609 raeburn 1166: $hashref,
1167: $menuorder,
1.1115 raeburn 1168: $onchangefirst,
1.1245 raeburn 1169: $onchangesecond,
1170: $suffix
1.36 matthew 1171: ) = @_;
1172: my $second = "document.$formname.$secondselectname";
1173: my $first = "document.$formname.$firstselectname";
1174: # output the javascript to do the changing
1175: my $result = '';
1.776 bisitz 1176: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1177: $result.="// <![CDATA[\n";
1.1245 raeburn 1178: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1179: $" = '","';
1180: my $debug = '';
1181: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1182: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1183: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1184: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1185: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1186: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1187: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1188: @s2values = @{$hashref->{$s1}->{'order'}};
1189: }
1.36 matthew 1190: $result.="\"@s2values\");\n";
1.1245 raeburn 1191: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1192: my @s2texts;
1193: foreach my $value (@s2values) {
1.1263 raeburn 1194: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1195: }
1196: $result.="\"@s2texts\");\n";
1197: }
1198: $"=' ';
1199: $result.= <<"END";
1200:
1.1245 raeburn 1201: function select1${suffix}_changed() {
1.36 matthew 1202: // Determine new choice
1.1245 raeburn 1203: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1204: // update select2
1.1245 raeburn 1205: var values = select2data${suffix}[newvalue].values;
1206: var texts = select2data${suffix}[newvalue].texts;
1207: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1208: var i;
1209: // out with the old
1.1245 raeburn 1210: $second.options.length = 0;
1211: // in with the new
1.36 matthew 1212: for (i=0;i<values.length; i++) {
1213: $second.options[i] = new Option(values[i]);
1.143 matthew 1214: $second.options[i].value = values[i];
1.36 matthew 1215: $second.options[i].text = texts[i];
1216: if (values[i] == select2def) {
1217: $second.options[i].selected = true;
1218: }
1219: }
1220: }
1.824 bisitz 1221: // ]]>
1.36 matthew 1222: </script>
1223: END
1224: # output the initial values for the selection lists
1.1245 raeburn 1225: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1226: my @order = sort(keys(%{$hashref}));
1227: if (ref($menuorder) eq 'ARRAY') {
1228: @order = @{$menuorder};
1229: }
1230: foreach my $value (@order) {
1.36 matthew 1231: $result.=" <option value=\"$value\" ";
1.253 albertel 1232: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1233: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1234: }
1235: $result .= "</select>\n";
1.1400 raeburn 1236: my %select2;
1237: if (ref($hashref->{$firstdefault}) eq 'HASH') {
1238: if (ref($hashref->{$firstdefault}->{'select2'}) eq 'HASH') {
1239: %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1240: }
1241: }
1.36 matthew 1242: $result .= $middletext;
1.1115 raeburn 1243: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1244: if ($onchangesecond) {
1245: $result .= ' onchange="'.$onchangesecond.'"';
1246: }
1247: $result .= ">\n";
1.36 matthew 1248: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1249:
1250: my @secondorder = sort(keys(%select2));
1251: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1252: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1253: }
1254: foreach my $value (@secondorder) {
1.36 matthew 1255: $result.=" <option value=\"$value\" ";
1.253 albertel 1256: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1257: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1258: }
1259: $result .= "</select>\n";
1260: # return $debug;
1261: return $result;
1262: } # end of sub linked_select_forms {
1263:
1.45 matthew 1264: =pod
1.44 bowersj2 1265:
1.1381 raeburn 1266: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid,$links_target)
1.44 bowersj2 1267:
1.112 bowersj2 1268: Returns a string corresponding to an HTML link to the given help
1269: $topic, where $topic corresponds to the name of a .tex file in
1270: /home/httpd/html/adm/help/tex, with underscores replaced by
1271: spaces.
1272:
1273: $text will optionally be linked to the same topic, allowing you to
1274: link text in addition to the graphic. If you do not want to link
1275: text, but wish to specify one of the later parameters, pass an
1276: empty string.
1277:
1278: $stayOnPage is a value that will be interpreted as a boolean. If true,
1279: the link will not open a new window. If false, the link will open
1280: a new window using Javascript. (Default is false.)
1281:
1282: $width and $height are optional numerical parameters that will
1283: override the width and height of the popped up window, which may
1.973 raeburn 1284: be useful for certain help topics with big pictures included.
1285:
1286: $imgid is the id of the img tag used for the help icon. This may be
1287: used in a javascript call to switch the image src. See
1288: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1289:
1.1381 raeburn 1290: $links_target will optionally be set to a target (_top, _parent or _self).
1291:
1.44 bowersj2 1292: =cut
1293:
1294: sub help_open_topic {
1.1381 raeburn 1295: my ($topic, $text, $stayOnPage, $width, $height, $imgid, $links_target) = @_;
1.48 bowersj2 1296: $text = "" if (not defined $text);
1.44 bowersj2 1297: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1298: $width = 500 if (not defined $width);
1.44 bowersj2 1299: $height = 400 if (not defined $height);
1300: my $filename = $topic;
1301: $filename =~ s/ /_/g;
1302:
1.48 bowersj2 1303: my $template = "";
1304: my $link;
1.572 banghart 1305:
1.159 www 1306: $topic=~s/\W/\_/g;
1.44 bowersj2 1307:
1.572 banghart 1308: if (!$stayOnPage) {
1.1033 www 1309: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1310: } elsif ($stayOnPage eq 'popup') {
1311: $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 1312: } else {
1.48 bowersj2 1313: $link = "/adm/help/${filename}.hlp";
1314: }
1315:
1316: # Add the text
1.1314 raeburn 1317: my $target = ' target="_top"';
1.1381 raeburn 1318: if ($links_target) {
1319: $target = ' target="'.$links_target.'"';
1320: } elsif ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1321: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1322: $target = '';
1.1378 raeburn 1323: }
1.1380 raeburn 1324: if ($text ne "") {
1.763 bisitz 1325: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1326: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1327: .$text.'</a>';
1.48 bowersj2 1328: }
1329:
1.763 bisitz 1330: # (Always) Add the graphic
1.179 matthew 1331: my $title = &mt('Online Help');
1.667 raeburn 1332: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1333: if ($imgid ne '') {
1334: $imgid = ' id="'.$imgid.'"';
1335: }
1.1314 raeburn 1336: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1337: .'<img src="'.$helpicon.'" border="0"'
1338: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1339: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1340: .' /></a>';
1341: if ($text ne "") {
1342: $template.='</span>';
1343: }
1.44 bowersj2 1344: return $template;
1345:
1.106 bowersj2 1346: }
1347:
1348: # This is a quicky function for Latex cheatsheet editing, since it
1349: # appears in at least four places
1350: sub helpLatexCheatsheet {
1.1037 www 1351: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1352: my $out;
1.106 bowersj2 1353: my $addOther = '';
1.732 raeburn 1354: if ($topic) {
1.1037 www 1355: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1356: }
1357: $out = '<span>' # Start cheatsheet
1358: .$addOther
1359: .'<span>'
1.1037 www 1360: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1361: .'</span> <span>'
1.1037 www 1362: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1363: .'</span>';
1.732 raeburn 1364: unless ($not_author) {
1.1186 kruse 1365: $out .= '<span>'
1366: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1367: .'</span> <span>'
1368: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1369: .'</span>';
1.732 raeburn 1370: }
1.763 bisitz 1371: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1372: return $out;
1.172 www 1373: }
1374:
1.430 albertel 1375: sub general_help {
1376: my $helptopic='Student_Intro';
1377: if ($env{'request.role'}=~/^(ca|au)/) {
1378: $helptopic='Authoring_Intro';
1.907 raeburn 1379: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1380: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1381: } elsif ($env{'request.role'}=~/^dc/) {
1382: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1383: }
1384: return $helptopic;
1385: }
1386:
1387: sub update_help_link {
1388: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1389: my $origurl = $ENV{'REQUEST_URI'};
1390: $origurl=~s|^/~|/priv/|;
1391: my $timestamp = time;
1392: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1393: $$datum = &escape($$datum);
1394: }
1395:
1396: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1397: my $output .= <<"ENDOUTPUT";
1398: <script type="text/javascript">
1.824 bisitz 1399: // <![CDATA[
1.430 albertel 1400: banner_link = '$banner_link';
1.824 bisitz 1401: // ]]>
1.430 albertel 1402: </script>
1403: ENDOUTPUT
1404: return $output;
1405: }
1406:
1407: # now just updates the help link and generates a blue icon
1.193 raeburn 1408: sub help_open_menu {
1.1381 raeburn 1409: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text,$links_target)
1.552 banghart 1410: = @_;
1.949 droeschl 1411: $stayOnPage = 1;
1.430 albertel 1412: my $output;
1413: if ($component_help) {
1414: if (!$text) {
1415: $output=&help_open_topic($component_help,undef,$stayOnPage,
1.1381 raeburn 1416: $width,$height,'',$links_target);
1.430 albertel 1417: } else {
1418: my $help_text;
1419: $help_text=&unescape($topic);
1420: $output='<table><tr><td>'.
1421: &help_open_topic($component_help,$help_text,$stayOnPage,
1.1381 raeburn 1422: $width,$height,'',$links_target).'</td></tr></table>';
1.430 albertel 1423: }
1424: }
1425: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1426: return $output.$banner_link;
1427: }
1428:
1429: sub top_nav_help {
1.1369 raeburn 1430: my ($text,$linkattr) = @_;
1.436 albertel 1431: $text = &mt($text);
1.949 droeschl 1432: my $stay_on_page = 1;
1433:
1.1168 raeburn 1434: my ($link,$banner_link);
1435: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1436: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1437: : "javascript:helpMenu('open')";
1438: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1439: }
1.201 raeburn 1440: my $title = &mt('Get help');
1.1168 raeburn 1441: if ($link) {
1442: return <<"END";
1.436 albertel 1443: $banner_link
1.1369 raeburn 1444: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1445: END
1.1168 raeburn 1446: } else {
1447: return ' '.$text.' ';
1448: }
1.436 albertel 1449: }
1450:
1451: sub help_menu_js {
1.1154 raeburn 1452: my ($httphost) = @_;
1.949 droeschl 1453: my $stayOnPage = 1;
1.436 albertel 1454: my $width = 620;
1455: my $height = 600;
1.430 albertel 1456: my $helptopic=&general_help();
1.1154 raeburn 1457: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1458: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1459: my $start_page =
1460: &Apache::loncommon::start_page('Help Menu', undef,
1461: {'frameset' => 1,
1462: 'js_ready' => 1,
1.1154 raeburn 1463: 'use_absolute' => $httphost,
1.331 albertel 1464: 'add_entries' => {
1.1168 raeburn 1465: 'border' => '0',
1.579 raeburn 1466: 'rows' => "110,*",},});
1.331 albertel 1467: my $end_page =
1468: &Apache::loncommon::end_page({'frameset' => 1,
1469: 'js_ready' => 1,});
1470:
1.436 albertel 1471: my $template .= <<"ENDTEMPLATE";
1472: <script type="text/javascript">
1.877 bisitz 1473: // <![CDATA[
1.253 albertel 1474: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1475: var banner_link = '';
1.243 raeburn 1476: function helpMenu(target) {
1477: var caller = this;
1478: if (target == 'open') {
1479: var newWindow = null;
1480: try {
1.262 albertel 1481: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1482: }
1483: catch(error) {
1484: writeHelp(caller);
1485: return;
1486: }
1487: if (newWindow) {
1488: caller = newWindow;
1489: }
1.193 raeburn 1490: }
1.243 raeburn 1491: writeHelp(caller);
1492: return;
1493: }
1494: function writeHelp(caller) {
1.1168 raeburn 1495: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1496: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1497: caller.document.close();
1498: caller.focus();
1.193 raeburn 1499: }
1.877 bisitz 1500: // END LON-CAPA Internal -->
1.253 albertel 1501: // ]]>
1.436 albertel 1502: </script>
1.193 raeburn 1503: ENDTEMPLATE
1504: return $template;
1505: }
1506:
1.172 www 1507: sub help_open_bug {
1508: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1509: unless ($env{'user.adv'}) { return ''; }
1.172 www 1510: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1511: $text = "" if (not defined $text);
1512: $stayOnPage=1;
1.184 albertel 1513: $width = 600 if (not defined $width);
1514: $height = 600 if (not defined $height);
1.172 www 1515:
1516: $topic=~s/\W+/\+/g;
1517: my $link='';
1518: my $template='';
1.379 albertel 1519: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1520: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1521: if (!$stayOnPage)
1522: {
1523: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1524: }
1525: else
1526: {
1527: $link = $url;
1528: }
1.1314 raeburn 1529:
1.1382 raeburn 1530: my $target = '_top';
1531: if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
1532: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
1533: $target = '_blank';
1.1378 raeburn 1534: }
1.1382 raeburn 1535:
1.172 www 1536: # Add the text
1537: if ($text ne "")
1538: {
1539: $template .=
1540: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1382 raeburn 1541: "<td bgcolor='#FF5555'><a target=\"$target\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1542: }
1543:
1544: # Add the graphic
1.179 matthew 1545: my $title = &mt('Report a Bug');
1.215 albertel 1546: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1547: $template .= <<"ENDTEMPLATE";
1.1382 raeburn 1548: <a target="$target" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1549: ENDTEMPLATE
1550: if ($text ne '') { $template.='</td></tr></table>' };
1551: return $template;
1552:
1553: }
1554:
1555: sub help_open_faq {
1556: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1557: unless ($env{'user.adv'}) { return ''; }
1.172 www 1558: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1559: $text = "" if (not defined $text);
1560: $stayOnPage=1;
1561: $width = 350 if (not defined $width);
1562: $height = 400 if (not defined $height);
1563:
1564: $topic=~s/\W+/\+/g;
1565: my $link='';
1566: my $template='';
1567: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1568: if (!$stayOnPage)
1569: {
1570: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1571: }
1572: else
1573: {
1574: $link = $url;
1575: }
1576:
1577: # Add the text
1578: if ($text ne "")
1579: {
1580: $template .=
1.173 www 1581: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1582: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1583: }
1584:
1585: # Add the graphic
1.179 matthew 1586: my $title = &mt('View the FAQ');
1.215 albertel 1587: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1588: $template .= <<"ENDTEMPLATE";
1.436 albertel 1589: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1590: ENDTEMPLATE
1591: if ($text ne '') { $template.='</td></tr></table>' };
1592: return $template;
1593:
1.44 bowersj2 1594: }
1.37 matthew 1595:
1.180 matthew 1596: ###############################################################
1597: ###############################################################
1598:
1.45 matthew 1599: =pod
1600:
1.648 raeburn 1601: =item * &change_content_javascript():
1.256 matthew 1602:
1603: This and the next function allow you to create small sections of an
1604: otherwise static HTML page that you can update on the fly with
1605: Javascript, even in Netscape 4.
1606:
1607: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1608: must be written to the HTML page once. It will prove the Javascript
1609: function "change(name, content)". Calling the change function with the
1610: name of the section
1611: you want to update, matching the name passed to C<changable_area>, and
1612: the new content you want to put in there, will put the content into
1613: that area.
1614:
1615: B<Note>: Netscape 4 only reserves enough space for the changable area
1616: to contain room for the original contents. You need to "make space"
1617: for whatever changes you wish to make, and be B<sure> to check your
1618: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1619: it's adequate for updating a one-line status display, but little more.
1620: This script will set the space to 100% width, so you only need to
1621: worry about height in Netscape 4.
1622:
1623: Modern browsers are much less limiting, and if you can commit to the
1624: user not using Netscape 4, this feature may be used freely with
1625: pretty much any HTML.
1626:
1627: =cut
1628:
1629: sub change_content_javascript {
1630: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1631: if ($env{'browser.type'} eq 'netscape' &&
1632: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1633: return (<<NETSCAPE4);
1634: function change(name, content) {
1635: doc = document.layers[name+"___escape"].layers[0].document;
1636: doc.open();
1637: doc.write(content);
1638: doc.close();
1639: }
1640: NETSCAPE4
1641: } else {
1642: # Otherwise, we need to use semi-standards-compliant code
1643: # (technically, "innerHTML" isn't standard but the equivalent
1644: # is really scary, and every useful browser supports it
1645: return (<<DOMBASED);
1646: function change(name, content) {
1647: element = document.getElementById(name);
1648: element.innerHTML = content;
1649: }
1650: DOMBASED
1651: }
1652: }
1653:
1654: =pod
1655:
1.648 raeburn 1656: =item * &changable_area($name,$origContent):
1.256 matthew 1657:
1658: This provides a "changable area" that can be modified on the fly via
1659: the Javascript code provided in C<change_content_javascript>. $name is
1660: the name you will use to reference the area later; do not repeat the
1661: same name on a given HTML page more then once. $origContent is what
1662: the area will originally contain, which can be left blank.
1663:
1664: =cut
1665:
1666: sub changable_area {
1667: my ($name, $origContent) = @_;
1668:
1.258 albertel 1669: if ($env{'browser.type'} eq 'netscape' &&
1670: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1671: # If this is netscape 4, we need to use the Layer tag
1672: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1673: } else {
1674: return "<span id='$name'>$origContent</span>";
1675: }
1676: }
1677:
1678: =pod
1679:
1.648 raeburn 1680: =item * &viewport_geometry_js
1.590 raeburn 1681:
1682: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1683:
1684: =cut
1685:
1686:
1687: sub viewport_geometry_js {
1688: return <<"GEOMETRY";
1689: var Geometry = {};
1690: function init_geometry() {
1691: if (Geometry.init) { return };
1692: Geometry.init=1;
1693: if (window.innerHeight) {
1694: Geometry.getViewportHeight = function() { return window.innerHeight; };
1695: Geometry.getViewportWidth = function() { return window.innerWidth; };
1696: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1697: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1698: }
1699: else if (document.documentElement && document.documentElement.clientHeight) {
1700: Geometry.getViewportHeight =
1701: function() { return document.documentElement.clientHeight; };
1702: Geometry.getViewportWidth =
1703: function() { return document.documentElement.clientWidth; };
1704:
1705: Geometry.getHorizontalScroll =
1706: function() { return document.documentElement.scrollLeft; };
1707: Geometry.getVerticalScroll =
1708: function() { return document.documentElement.scrollTop; };
1709: }
1710: else if (document.body.clientHeight) {
1711: Geometry.getViewportHeight =
1712: function() { return document.body.clientHeight; };
1713: Geometry.getViewportWidth =
1714: function() { return document.body.clientWidth; };
1715: Geometry.getHorizontalScroll =
1716: function() { return document.body.scrollLeft; };
1717: Geometry.getVerticalScroll =
1718: function() { return document.body.scrollTop; };
1719: }
1720: }
1721:
1722: GEOMETRY
1723: }
1724:
1725: =pod
1726:
1.648 raeburn 1727: =item * &viewport_size_js()
1.590 raeburn 1728:
1729: 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.
1730:
1731: =cut
1732:
1733: sub viewport_size_js {
1734: my $geometry = &viewport_geometry_js();
1735: return <<"DIMS";
1736:
1737: $geometry
1738:
1739: function getViewportDims(width,height) {
1740: init_geometry();
1741: width.value = Geometry.getViewportWidth();
1742: height.value = Geometry.getViewportHeight();
1743: return;
1744: }
1745:
1746: DIMS
1747: }
1748:
1749: =pod
1750:
1.648 raeburn 1751: =item * &resize_textarea_js()
1.565 albertel 1752:
1753: emits the needed javascript to resize a textarea to be as big as possible
1754:
1755: creates a function resize_textrea that takes two IDs first should be
1756: the id of the element to resize, second should be the id of a div that
1757: surrounds everything that comes after the textarea, this routine needs
1758: to be attached to the <body> for the onload and onresize events.
1759:
1.648 raeburn 1760: =back
1.565 albertel 1761:
1762: =cut
1763:
1764: sub resize_textarea_js {
1.590 raeburn 1765: my $geometry = &viewport_geometry_js();
1.565 albertel 1766: return <<"RESIZE";
1767: <script type="text/javascript">
1.824 bisitz 1768: // <![CDATA[
1.590 raeburn 1769: $geometry
1.565 albertel 1770:
1.588 albertel 1771: function getX(element) {
1772: var x = 0;
1773: while (element) {
1774: x += element.offsetLeft;
1775: element = element.offsetParent;
1776: }
1777: return x;
1778: }
1779: function getY(element) {
1780: var y = 0;
1781: while (element) {
1782: y += element.offsetTop;
1783: element = element.offsetParent;
1784: }
1785: return y;
1786: }
1787:
1788:
1.565 albertel 1789: function resize_textarea(textarea_id,bottom_id) {
1790: init_geometry();
1791: var textarea = document.getElementById(textarea_id);
1792: //alert(textarea);
1793:
1.588 albertel 1794: var textarea_top = getY(textarea);
1.565 albertel 1795: var textarea_height = textarea.offsetHeight;
1796: var bottom = document.getElementById(bottom_id);
1.588 albertel 1797: var bottom_top = getY(bottom);
1.565 albertel 1798: var bottom_height = bottom.offsetHeight;
1799: var window_height = Geometry.getViewportHeight();
1.588 albertel 1800: var fudge = 23;
1.565 albertel 1801: var new_height = window_height-fudge-textarea_top-bottom_height;
1802: if (new_height < 300) {
1803: new_height = 300;
1804: }
1805: textarea.style.height=new_height+'px';
1806: }
1.824 bisitz 1807: // ]]>
1.565 albertel 1808: </script>
1809: RESIZE
1810:
1811: }
1812:
1.1205 golterma 1813: sub colorfuleditor_js {
1.1248 raeburn 1814: my $browse_or_search;
1815: my $respath;
1816: my ($cnum,$cdom) = &crsauthor_url();
1817: if ($cnum) {
1818: $respath = "/res/$cdom/$cnum/";
1819: my %js_lt = &Apache::lonlocal::texthash(
1820: sunm => 'Sub-directory name',
1821: save => 'Save page to make this permanent',
1822: );
1823: &js_escape(\%js_lt);
1.1400 raeburn 1824: my $showfile_js = &show_crsfiles_js();
1.1248 raeburn 1825: $browse_or_search = <<"END";
1826:
1.1400 raeburn 1827: $showfile_js
1828:
1.1248 raeburn 1829: function toggleChooser(form,element,titleid,only,search) {
1830: var disp = 'none';
1831: if (document.getElementById('chooser_'+element)) {
1832: var curr = document.getElementById('chooser_'+element).style.display;
1833: if (curr == 'none') {
1834: disp='inline';
1835: if (form.elements['chooser_'+element].length) {
1836: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1837: form.elements['chooser_'+element][i].checked = false;
1838: }
1839: }
1840: toggleResImport(form,element);
1841: }
1842: document.getElementById('chooser_'+element).style.display = disp;
1.1400 raeburn 1843: var dirsel = '';
1844: var filesel = '';
1845: if (document.getElementById('chooser_'+element+'_crsres')) {
1846: var currcrsres = document.getElementById('chooser_'+element+'_crsres').style.display;
1847: if (currcrsres == 'none') {
1848: dirsel = 'coursepath_'+element;
1849: var filesel = 'coursefile_'+element;
1850: var include;
1851: if (document.getElementById('crsres_include_'+element)) {
1852: include = document.getElementById('crsres_include_'+element).value;
1853: }
1854: populateCrsSelects(form,dirsel,filesel,1,include,1,0,1,1);
1855: }
1856: }
1857: if (document.getElementById('chooser_'+element+'_upload')) {
1858: var currcrsupload = document.getElementById('chooser_'+element+'_upload').style.display;
1859: if (currcrsupload == 'none') {
1860: dirsel = 'crsauthorpath_'+element;
1861: filesel = '';
1862: populateCrsSelects(form,dirsel,filesel,0,'',1,0,1,0);
1863: }
1864: }
1.1248 raeburn 1865: }
1866: }
1867:
1.1400 raeburn 1868: function toggleCrsFile(form,element) {
1.1248 raeburn 1869: if (document.getElementById('chooser_'+element+'_crsres')) {
1870: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1871: if (curr == 'none') {
1.1400 raeburn 1872: if (document.getElementById('coursepath_'+element)) {
1873: var numdirs;
1874: if (document.getElementById('coursepath_'+element).length) {
1875: numdirs = document.getElementById('coursepath_'+element).length;
1876: }
1.1248 raeburn 1877: form.elements['coursepath_'+element].selectedIndex = 0;
1878: if (numdirs > 1) {
1.1400 raeburn 1879: var selelem = form.elements['coursefile_'+element];
1880: var i, len = selelem.options.length -1;
1881: if (len >=0) {
1882: for (i = len; i >= 0; i--) {
1883: selelem.remove(i);
1884: }
1885: selelem.options[0] = new Option('','');
1886: }
1.1248 raeburn 1887: }
1888: }
1.1400 raeburn 1889: }
1.1248 raeburn 1890: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1891: }
1892: if (document.getElementById('chooser_'+element+'_upload')) {
1893: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1894: if (document.getElementById('uploadcrsres_'+element)) {
1895: document.getElementById('uploadcrsres_'+element).value = '';
1896: }
1897: }
1898: return;
1899: }
1900:
1.1400 raeburn 1901: function toggleCrsUpload(form,element) {
1.1248 raeburn 1902: if (document.getElementById('chooser_'+element+'_crsres')) {
1903: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1904: }
1905: if (document.getElementById('chooser_'+element+'_upload')) {
1906: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1907: if (curr == 'none') {
1.1400 raeburn 1908: form.elements['newsubdir_'+element][0].checked = true;
1909: toggleNewsubdir(form,element);
1910: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1911: if (document.getElementById('uploadcrsres_'+element)) {
1912: document.getElementById('uploadcrsres_'+element).value = '';
1.1248 raeburn 1913: }
1914: }
1915: }
1916: return;
1917: }
1918:
1919: function toggleResImport(form,element) {
1920: var choices = new Array('crsres','upload');
1921: for (var i=0; i<choices.length; i++) {
1922: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1923: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1924: }
1925: }
1926: }
1927:
1928: function toggleNewsubdir(form,element) {
1929: var newsub = form.elements['newsubdir_'+element];
1930: if (newsub) {
1931: if (newsub.length) {
1932: for (var j=0; j<newsub.length; j++) {
1933: if (newsub[j].checked) {
1934: if (document.getElementById('newsubdirname_'+element)) {
1935: if (newsub[j].value == '1') {
1936: document.getElementById('newsubdirname_'+element).type = "text";
1937: if (document.getElementById('newsubdir_'+element)) {
1938: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1939: }
1940: } else {
1941: document.getElementById('newsubdirname_'+element).type = "hidden";
1942: document.getElementById('newsubdirname_'+element).value = "";
1943: document.getElementById('newsubdir_'+element).innerHTML = "";
1944: }
1945: }
1946: break;
1947: }
1948: }
1949: }
1950: }
1951: }
1952:
1953: function updateCrsFile(form,element) {
1954: var directory = form.elements['coursepath_'+element];
1955: var filename = form.elements['coursefile_'+element];
1956: var path = directory.options[directory.selectedIndex].value;
1957: var file = filename.options[filename.selectedIndex].value;
1.1400 raeburn 1958: if (file != '') {
1959: form.elements[element].value = '$respath';
1960: if (path == '/') {
1961: form.elements[element].value += file;
1962: } else {
1963: form.elements[element].value += path+'/'+file;
1964: }
1965: unClean();
1966: if (document.getElementById('previewimg_'+element)) {
1967: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1968: var newsrc = document.getElementById('previewimg_'+element).src;
1969: }
1970: if (document.getElementById('showimg_'+element)) {
1971: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1972: }
1.1248 raeburn 1973: }
1974: toggleChooser(form,element);
1975: return;
1976: }
1977:
1978: function uploadDone(suffix,name) {
1979: if (name) {
1980: document.forms["lonhomework"].elements[suffix].value = name;
1981: unClean();
1982: toggleChooser(document.forms["lonhomework"],suffix);
1983: }
1984: }
1985:
1986: \$(document).ready(function(){
1987:
1988: \$(document).delegate('form :submit', 'click', function( event ) {
1989: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1990: var buttonId = this.id;
1991: var suffix = buttonId.toString();
1992: suffix = suffix.replace(/^crsupload_/,'');
1993: event.preventDefault();
1994: document.lonhomework.target = 'crsupload_target_'+suffix;
1995: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1996: \$(this.form).submit();
1997: document.lonhomework.target = '';
1998: if (document.getElementById('crsuploadto_'+suffix)) {
1999: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
2000: }
2001: return false;
2002: }
2003: });
2004: });
2005: END
2006: }
1.1205 golterma 2007: return <<"COLORFULEDIT"
2008: <script type="text/javascript">
2009: // <![CDATA[>
2010: function fold_box(curDepth, lastresource){
2011:
2012: // we need a list because there can be several blocks you need to fold in one tag
2013: var block = document.getElementsByName('foldblock_'+curDepth);
2014: // but there is only one folding button per tag
2015: var foldbutton = document.getElementById('folding_btn_'+curDepth);
2016:
2017: if(block.item(0).style.display == 'none'){
2018:
2019: foldbutton.value = '@{[&mt("Hide")]}';
2020: for (i = 0; i < block.length; i++){
2021: block.item(i).style.display = '';
2022: }
2023: }else{
2024:
2025: foldbutton.value = '@{[&mt("Show")]}';
2026: for (i = 0; i < block.length; i++){
2027: // block.item(i).style.visibility = 'collapse';
2028: block.item(i).style.display = 'none';
2029: }
2030: };
2031: saveState(lastresource);
2032: }
2033:
2034: function saveState (lastresource) {
2035:
2036: var tag_list = getTagList();
2037: if(tag_list != null){
2038: var timestamp = new Date().getTime();
2039: var key = lastresource;
2040:
2041: // the value pattern is: 'time;key1,value1;key2,value2; ... '
2042: // starting with timestamp
2043: var value = timestamp+';';
2044:
2045: // building the list of key-value pairs
2046: for(var i = 0; i < tag_list.length; i++){
2047: value += tag_list[i]+',';
2048: value += document.getElementsByName(tag_list[i])[0].style.display+';';
2049: }
2050:
2051: // only iterate whole storage if nothing to override
2052: if(localStorage.getItem(key) == null){
2053:
2054: // prevent storage from growing large
2055: if(localStorage.length > 50){
2056: var regex_getTimestamp = /^(?:\d)+;/;
2057: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2058: var oldest_key;
2059:
2060: for(var i = 1; i < localStorage.length; i++){
2061: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2062: oldest_key = localStorage.key(i);
2063: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2064: }
2065: }
2066: localStorage.removeItem(oldest_key);
2067: }
2068: }
2069: localStorage.setItem(key,value);
2070: }
2071: }
2072:
2073: // restore folding status of blocks (on page load)
2074: function restoreState (lastresource) {
2075: if(localStorage.getItem(lastresource) != null){
2076: var key = lastresource;
2077: var value = localStorage.getItem(key);
2078: var regex_delTimestamp = /^\d+;/;
2079:
2080: value.replace(regex_delTimestamp, '');
2081:
2082: var valueArr = value.split(';');
2083: var pairs;
2084: var elements;
2085: for (var i = 0; i < valueArr.length; i++){
2086: pairs = valueArr[i].split(',');
2087: elements = document.getElementsByName(pairs[0]);
2088:
2089: for (var j = 0; j < elements.length; j++){
2090: elements[j].style.display = pairs[1];
2091: if (pairs[1] == "none"){
2092: var regex_id = /([_\\d]+)\$/;
2093: regex_id.exec(pairs[0]);
2094: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2095: }
2096: }
2097: }
2098: }
2099: }
2100:
2101: function getTagList () {
2102:
2103: var stringToSearch = document.lonhomework.innerHTML;
2104:
2105: var ret = new Array();
2106: var regex_findBlock = /(foldblock_.*?)"/g;
2107: var tag_list = stringToSearch.match(regex_findBlock);
2108:
2109: if(tag_list != null){
2110: for(var i = 0; i < tag_list.length; i++){
2111: ret.push(tag_list[i].replace(/"/, ''));
2112: }
2113: }
2114: return ret;
2115: }
2116:
2117: function saveScrollPosition (resource) {
2118: var tag_list = getTagList();
2119:
2120: // we dont always want to jump to the first block
2121: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2122: if(\$(window).scrollTop() > 170){
2123: if(tag_list != null){
2124: var result;
2125: for(var i = 0; i < tag_list.length; i++){
2126: if(isElementInViewport(tag_list[i])){
2127: result += tag_list[i]+';';
2128: }
2129: }
2130: sessionStorage.setItem('anchor_'+resource, result);
2131: }
2132: } else {
2133: // we dont need to save zero, just delete the item to leave everything tidy
2134: sessionStorage.removeItem('anchor_'+resource);
2135: }
2136: }
2137:
2138: function restoreScrollPosition(resource){
2139:
2140: var elem = sessionStorage.getItem('anchor_'+resource);
2141: if(elem != null){
2142: var tag_list = elem.split(';');
2143: var elem_list;
2144:
2145: for(var i = 0; i < tag_list.length; i++){
2146: elem_list = document.getElementsByName(tag_list[i]);
2147:
2148: if(elem_list.length > 0){
2149: elem = elem_list[0];
2150: break;
2151: }
2152: }
2153: elem.scrollIntoView();
2154: }
2155: }
2156:
2157: function isElementInViewport(el) {
2158:
2159: // change to last element instead of first
2160: var elem = document.getElementsByName(el);
2161: var rect = elem[0].getBoundingClientRect();
2162:
2163: return (
2164: rect.top >= 0 &&
2165: rect.left >= 0 &&
2166: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2167: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2168: );
2169: }
2170:
2171: function autosize(depth){
2172: var cmInst = window['cm'+depth];
2173: var fitsizeButton = document.getElementById('fitsize'+depth);
2174:
2175: // is fixed size, switching to dynamic
2176: if (sessionStorage.getItem("autosized_"+depth) == null) {
2177: cmInst.setSize("","auto");
2178: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2179: sessionStorage.setItem("autosized_"+depth, "yes");
2180:
2181: // is dynamic size, switching to fixed
2182: } else {
2183: cmInst.setSize("","300px");
2184: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2185: sessionStorage.removeItem("autosized_"+depth);
2186: }
2187: }
2188:
1.1248 raeburn 2189: $browse_or_search
1.1205 golterma 2190:
2191: // ]]>
2192: </script>
2193: COLORFULEDIT
2194: }
2195:
2196: sub xmleditor_js {
2197: return <<XMLEDIT
2198: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2199: <script type="text/javascript">
2200: // <![CDATA[>
2201:
2202: function saveScrollPosition (resource) {
2203:
2204: var scrollPos = \$(window).scrollTop();
2205: sessionStorage.setItem(resource,scrollPos);
2206: }
2207:
2208: function restoreScrollPosition(resource){
2209:
2210: var scrollPos = sessionStorage.getItem(resource);
2211: \$(window).scrollTop(scrollPos);
2212: }
2213:
2214: // unless internet explorer
2215: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2216:
2217: \$(document).ready(function() {
2218: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2219: });
2220: }
2221:
2222: // inserts text at cursor position into codemirror (xml editor only)
2223: function insertText(text){
2224: cm.focus();
2225: var curPos = cm.getCursor();
2226: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2227: }
2228: // ]]>
2229: </script>
2230: XMLEDIT
2231: }
2232:
2233: sub insert_folding_button {
2234: my $curDepth = $Apache::lonxml::curdepth;
2235: my $lastresource = $env{'request.ambiguous'};
2236:
2237: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2238: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2239: }
2240:
1.1248 raeburn 2241: sub crsauthor_url {
2242: my ($url) = @_;
2243: if ($url eq '') {
2244: $url = $ENV{'REQUEST_URI'};
2245: }
2246: my ($cnum,$cdom);
2247: if ($env{'request.course.id'}) {
2248: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2249: if ($audom ne '' && $auname ne '') {
2250: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2251: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2252: $cnum = $auname;
2253: $cdom = $audom;
2254: }
2255: }
2256: }
2257: return ($cnum,$cdom);
2258: }
2259:
2260: sub import_crsauthor_form {
1.1400 raeburn 2261: my ($firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2262: return (0) unless ($env{'request.course.id'});
2263: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2264: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2265: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2266: return (0) unless (($cnum ne '') && ($cdom ne ''));
2267: my @ids=&Apache::lonnet::current_machine_ids();
1.1400 raeburn 2268: my ($output,$is_home,$toppath,%subdirs,%files,%selimport_menus,$include,$exclude);
1.1248 raeburn 2269:
2270: if (grep(/^\Q$crshome\E$/,@ids)) {
2271: $is_home = 1;
2272: }
1.1400 raeburn 2273: $toppath = "/priv/$cdom/$cnum";
2274: my $nonemptydir = 1;
2275: my $js_only;
2276: if ($only) {
2277: map { $include->{$_} = 1; } split(/\s*,\s*/,$only);
2278: $js_only = join(',',map { &js_escape($_); } sort(keys(%{$include})));
2279: }
2280: $exclude = &Apache::lonnet::priv_exclude();
2281: &Apache::lonnet::recursedirs($is_home,1,$include,$exclude,1,$toppath,'',\%subdirs,\%files);
2282: my $numdirs = scalar(keys(%files));
1.1248 raeburn 2283: my %lt = &Apache::lonlocal::texthash (
2284: fnam => 'Filename',
2285: dire => 'Directory',
1.1400 raeburn 2286: se => 'Select',
1.1248 raeburn 2287: );
1.1400 raeburn 2288: $output = $lt{'dire'}.
2289: '<select id="'.$firstselectname.'" name="'.$firstselectname.'" '.
2290: 'onchange="populateCrsSelects(this.form,'."'$firstselectname','$secondselectname',1,'$js_only',0,1,0,0".');">'.
2291: '<option value="" selected="selected">'.$lt{'se'}.'</option>';
2292: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2293: $output .= '<option value="'.$key.'">'.$key.'</option>'."\n";
2294: }
2295: $output .= '</select><br />'."\n".
2296: $lt{'fnam'}.'<select id="'.$secondselectname.'" name="'.$secondselectname.'">'."\n".
2297: '<option value="" selected="selected"></option>'."\n".
2298: '</select>'."\n";
2299: $output .= '<input type="hidden" id="crsres_include_'.$suffix.'" value="'.$only.'" />';
2300: return ($numdirs,$output);
2301: }
2302:
2303: sub show_crsfiles_js {
2304: my $excluderef = &Apache::lonnet::priv_exclude();
2305: my $se = &js_escape(&mt('Select'));
2306: my $exclude;
2307: if (ref($excluderef) eq 'HASH') {
2308: $exclude = join(',', map { &js_escape($_); } sort(keys(%{$excluderef})));
2309: }
2310: my $js = <<"END";
2311:
2312:
2313: function populateCrsSelects (form,dirsel,filesel,exc,include,setdir,setfile,recurse,nonemptydir) {
2314: var relpath = '';
2315: if ((setfile) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2316: var currdir = form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value;
2317: if (currdir == '') {
2318: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2319: selelem = form.elements[filesel];
2320: var j, numfiles = selelem.options.length -1;
2321: if (numfiles >=0) {
2322: for (j = numfiles; j >= 0; j--) {
2323: selelem.remove(j);
2324: }
2325: }
2326: if (selelem.options.length == 0) {
2327: selelem.options[selelem.options.length] = new Option('','');
2328: selelem.selectedIndex = 0;
1.1248 raeburn 2329: }
2330: }
1.1400 raeburn 2331: return;
2332: } else {
2333: relpath = encodeURIComponent(form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value);
1.1248 raeburn 2334: }
2335: }
1.1400 raeburn 2336: var http = new XMLHttpRequest();
2337: var url = "/adm/courseauthor";
2338: var crsrole = "$env{'request.role'}";
2339: var exclude = '';
2340: if (exc) {
2341: exclude = '$exclude';
2342: }
2343: var params = "role=course&files=1&rec="+recurse+"&nonempty="+nonemptydir+"&exc="+exclude+"&inc="+include+"&path="+relpath;
2344: http.open("POST", url, true);
2345: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
2346: http.onreadystatechange = function() {
2347: if (http.readyState == 4 && http.status == 200) {
2348: var data = JSON.parse(http.responseText);
2349: var selelem;
2350: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2351: if (Array.isArray(data.dirs)) {
2352: selelem = form.elements[dirsel];
2353: var i, numdirs = selelem.options.length -1;
2354: if (numdirs >=0) {
2355: for (i = numdirs; i >= 0; i--) {
2356: selelem.remove(i);
2357: }
2358: }
2359: var len = data.dirs.length;
2360: if (len) {
2361: if (len > 1) {
2362: selelem.options[selelem.options.length] = new Option('$se','');
2363: }
2364: }
2365: if (len) {
2366: var j;
2367: for (j = 0; j < len; j++) {
2368: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
2369: }
2370: selelem.selectedIndex = 0;
2371: }
2372: if (!setfile) {
2373: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2374: selelem = form.elements[filesel];
2375: var j, numfiles = selelem.options.length -1;
2376: if (numfiles >=0) {
2377: for (j = numfiles; j >= 0; j--) {
2378: selelem.remove(j);
2379: }
2380: }
2381: if (selelem.options.length == 0) {
2382: selelem.options[selelem.options.length] = new Option('','');
2383: selelem.selectedIndex = 0;
2384: }
2385: }
2386: }
2387: }
2388: }
2389: if ((setfile) && (filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2390: selelem = form.elements[filesel];
2391: var i, numfiles = selelem.options.length -1;
2392: if (numfiles >=0) {
2393: for (i = numfiles; i >= 0; i--) {
2394: selelem.remove(i);
2395: }
2396: }
2397: var x;
2398: for (x in data.files) {
2399: if (Array.isArray(data.files[x])) {
2400: if (data.files[x].length > 1) {
2401: selelem.options[selelem.options.length] = new Option('$se','');
2402: }
2403: var len = data.files[x].length;
2404: if (len) {
2405: var k;
2406: for (k = 0; k < len; k++) {
2407: selelem.options[selelem.options.length] = new Option(data.files[x][k],data.files[x][k]);
2408: }
2409: selelem.selectedIndex = 0;
2410: }
2411: }
2412: }
2413: if (selelem.options.length == 0) {
2414: selelem.options[selelem.options.length] = new Option('','');
2415: selelem.selectedIndex = 0;
2416: }
1.1248 raeburn 2417: }
2418: }
2419: }
1.1400 raeburn 2420: http.send(params);
1.1248 raeburn 2421: }
1.1400 raeburn 2422: END
1.1248 raeburn 2423: }
2424:
1.565 albertel 2425: =pod
2426:
1.256 matthew 2427: =head1 Excel and CSV file utility routines
2428:
2429: =cut
2430:
2431: ###############################################################
2432: ###############################################################
2433:
2434: =pod
2435:
1.1162 raeburn 2436: =over 4
2437:
1.648 raeburn 2438: =item * &csv_translate($text)
1.37 matthew 2439:
1.185 www 2440: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2441: format.
2442:
2443: =cut
2444:
1.180 matthew 2445: ###############################################################
2446: ###############################################################
1.37 matthew 2447: sub csv_translate {
2448: my $text = shift;
2449: $text =~ s/\"/\"\"/g;
1.209 albertel 2450: $text =~ s/\n/ /g;
1.37 matthew 2451: return $text;
2452: }
1.180 matthew 2453:
2454: ###############################################################
2455: ###############################################################
2456:
2457: =pod
2458:
1.648 raeburn 2459: =item * &define_excel_formats()
1.180 matthew 2460:
2461: Define some commonly used Excel cell formats.
2462:
2463: Currently supported formats:
2464:
2465: =over 4
2466:
2467: =item header
2468:
2469: =item bold
2470:
2471: =item h1
2472:
2473: =item h2
2474:
2475: =item h3
2476:
1.256 matthew 2477: =item h4
2478:
2479: =item i
2480:
1.180 matthew 2481: =item date
2482:
2483: =back
2484:
2485: Inputs: $workbook
2486:
2487: Returns: $format, a hash reference.
2488:
1.1057 foxr 2489:
1.180 matthew 2490: =cut
2491:
2492: ###############################################################
2493: ###############################################################
2494: sub define_excel_formats {
2495: my ($workbook) = @_;
2496: my $format;
2497: $format->{'header'} = $workbook->add_format(bold => 1,
2498: bottom => 1,
2499: align => 'center');
2500: $format->{'bold'} = $workbook->add_format(bold=>1);
2501: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2502: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2503: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2504: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2505: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2506: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2507: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2508: return $format;
2509: }
2510:
2511: ###############################################################
2512: ###############################################################
1.113 bowersj2 2513:
2514: =pod
2515:
1.648 raeburn 2516: =item * &create_workbook()
1.255 matthew 2517:
2518: Create an Excel worksheet. If it fails, output message on the
2519: request object and return undefs.
2520:
2521: Inputs: Apache request object
2522:
2523: Returns (undef) on failure,
2524: Excel worksheet object, scalar with filename, and formats
2525: from &Apache::loncommon::define_excel_formats on success
2526:
2527: =cut
2528:
2529: ###############################################################
2530: ###############################################################
2531: sub create_workbook {
2532: my ($r) = @_;
2533: #
2534: # Create the excel spreadsheet
2535: my $filename = '/prtspool/'.
1.258 albertel 2536: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2537: time.'_'.rand(1000000000).'.xls';
2538: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2539: if (! defined($workbook)) {
2540: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2541: $r->print(
2542: '<p class="LC_error">'
2543: .&mt('Problems occurred in creating the new Excel file.')
2544: .' '.&mt('This error has been logged.')
2545: .' '.&mt('Please alert your LON-CAPA administrator.')
2546: .'</p>'
2547: );
1.255 matthew 2548: return (undef);
2549: }
2550: #
1.1014 foxr 2551: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2552: #
2553: my $format = &Apache::loncommon::define_excel_formats($workbook);
2554: return ($workbook,$filename,$format);
2555: }
2556:
2557: ###############################################################
2558: ###############################################################
2559:
2560: =pod
2561:
1.648 raeburn 2562: =item * &create_text_file()
1.113 bowersj2 2563:
1.542 raeburn 2564: Create a file to write to and eventually make available to the user.
1.256 matthew 2565: If file creation fails, outputs an error message on the request object and
2566: return undefs.
1.113 bowersj2 2567:
1.256 matthew 2568: Inputs: Apache request object, and file suffix
1.113 bowersj2 2569:
1.256 matthew 2570: Returns (undef) on failure,
2571: Filehandle and filename on success.
1.113 bowersj2 2572:
2573: =cut
2574:
1.256 matthew 2575: ###############################################################
2576: ###############################################################
2577: sub create_text_file {
2578: my ($r,$suffix) = @_;
2579: if (! defined($suffix)) { $suffix = 'txt'; };
2580: my $fh;
2581: my $filename = '/prtspool/'.
1.258 albertel 2582: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2583: time.'_'.rand(1000000000).'.'.$suffix;
2584: $fh = Apache::File->new('>/home/httpd'.$filename);
2585: if (! defined($fh)) {
2586: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2587: $r->print(
2588: '<p class="LC_error">'
2589: .&mt('Problems occurred in creating the output file.')
2590: .' '.&mt('This error has been logged.')
2591: .' '.&mt('Please alert your LON-CAPA administrator.')
2592: .'</p>'
2593: );
1.113 bowersj2 2594: }
1.256 matthew 2595: return ($fh,$filename)
1.113 bowersj2 2596: }
2597:
2598:
1.256 matthew 2599: =pod
1.113 bowersj2 2600:
2601: =back
2602:
2603: =cut
1.37 matthew 2604:
2605: ###############################################################
1.33 matthew 2606: ## Home server <option> list generating code ##
2607: ###############################################################
1.35 matthew 2608:
1.169 www 2609: # ------------------------------------------
2610:
2611: sub domain_select {
1.1289 raeburn 2612: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2613: my @possdoms;
2614: if (ref($incdoms) eq 'ARRAY') {
2615: @possdoms = @{$incdoms};
2616: } else {
2617: @possdoms = &Apache::lonnet::all_domains();
2618: }
2619:
1.169 www 2620: my %domains=map {
1.514 albertel 2621: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2622: } @possdoms;
2623:
2624: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2625: foreach my $dom (@{$excdoms}) {
2626: delete($domains{$dom});
2627: }
2628: }
2629:
1.169 www 2630: if ($multiple) {
2631: $domains{''}=&mt('Any domain');
1.550 albertel 2632: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2633: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2634: } else {
1.550 albertel 2635: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2636: return &select_form($name,$value,\%domains);
1.169 www 2637: }
2638: }
2639:
1.282 albertel 2640: #-------------------------------------------
2641:
2642: =pod
2643:
1.519 raeburn 2644: =head1 Routines for form select boxes
2645:
2646: =over 4
2647:
1.648 raeburn 2648: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2649:
2650: Returns a string containing a <select> element int multiple mode
2651:
2652:
2653: Args:
2654: $name - name of the <select> element
1.506 raeburn 2655: $value - scalar or array ref of values that should already be selected
1.282 albertel 2656: $size - number of rows long the select element is
1.283 albertel 2657: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2658: (shown text should already have been &mt())
1.506 raeburn 2659: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2660:
1.282 albertel 2661: =cut
2662:
2663: #-------------------------------------------
1.169 www 2664: sub multiple_select_form {
1.284 albertel 2665: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2666: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2667: my $output='';
1.191 matthew 2668: if (! defined($size)) {
2669: $size = 4;
1.283 albertel 2670: if (scalar(keys(%$hash))<4) {
2671: $size = scalar(keys(%$hash));
1.191 matthew 2672: }
2673: }
1.734 bisitz 2674: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2675: my @order;
1.506 raeburn 2676: if (ref($order) eq 'ARRAY') {
2677: @order = @{$order};
2678: } else {
2679: @order = sort(keys(%$hash));
1.501 banghart 2680: }
2681: if (exists($$hash{'select_form_order'})) {
2682: @order = @{$$hash{'select_form_order'}};
2683: }
2684:
1.284 albertel 2685: foreach my $key (@order) {
1.356 albertel 2686: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2687: $output.='selected="selected" ' if ($selected{$key});
2688: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2689: }
2690: $output.="</select>\n";
2691: return $output;
2692: }
2693:
1.88 www 2694: #-------------------------------------------
2695:
2696: =pod
2697:
1.1254 raeburn 2698: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2699:
2700: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2701: allow a user to select options from a ref to a hash containing:
2702: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2703: a javascript onchange item, e.g., onchange="this.form.submit();".
2704: An optional arg -- $readonly -- if true will cause the select form
2705: to be disabled, e.g., for the case where an instructor has a section-
2706: specific role, and is viewing/modifying parameters.
1.970 raeburn 2707:
1.88 www 2708: See lonrights.pm for an example invocation and use.
2709:
2710: =cut
2711:
2712: #-------------------------------------------
2713: sub select_form {
1.1228 raeburn 2714: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2715: return unless (ref($hashref) eq 'HASH');
2716: if ($onchange) {
2717: $onchange = ' onchange="'.$onchange.'"';
2718: }
1.1228 raeburn 2719: my $disabled;
2720: if ($readonly) {
2721: $disabled = ' disabled="disabled"';
2722: }
2723: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2724: my @keys;
1.970 raeburn 2725: if (exists($hashref->{'select_form_order'})) {
2726: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2727: } else {
1.970 raeburn 2728: @keys=sort(keys(%{$hashref}));
1.128 albertel 2729: }
1.356 albertel 2730: foreach my $key (@keys) {
2731: $selectform.=
2732: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2733: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2734: ">".$hashref->{$key}."</option>\n";
1.88 www 2735: }
2736: $selectform.="</select>";
2737: return $selectform;
2738: }
2739:
1.475 www 2740: # For display filters
2741:
2742: sub display_filter {
1.1074 raeburn 2743: my ($context) = @_;
1.475 www 2744: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2745: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2746: my $phraseinput = 'hidden';
2747: my $includeinput = 'hidden';
2748: my ($checked,$includetypestext);
2749: if ($env{'form.displayfilter'} eq 'containing') {
2750: $phraseinput = 'text';
2751: if ($context eq 'parmslog') {
2752: $includeinput = 'checkbox';
2753: if ($env{'form.includetypes'}) {
2754: $checked = ' checked="checked"';
2755: }
2756: $includetypestext = &mt('Include parameter types');
2757: }
2758: } else {
2759: $includetypestext = ' ';
2760: }
2761: my ($additional,$secondid,$thirdid);
2762: if ($context eq 'parmslog') {
2763: $additional =
2764: '<label><input type="'.$includeinput.'" name="includetypes"'.
2765: $checked.' name="includetypes" value="1" id="includetypes" />'.
2766: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2767: '</label>';
2768: $secondid = 'includetypes';
2769: $thirdid = 'includetypestext';
2770: }
2771: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2772: '$secondid','$thirdid')";
2773: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2774: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2775: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2776: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2777: &mt('Filter: [_1]',
1.477 www 2778: &select_form($env{'form.displayfilter'},
2779: 'displayfilter',
1.970 raeburn 2780: {'currentfolder' => 'Current folder/page',
1.477 www 2781: 'containing' => 'Containing phrase',
1.1074 raeburn 2782: 'none' => 'None'},$onchange)).' '.
2783: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2784: &HTML::Entities::encode($env{'form.containingphrase'}).
2785: '" />'.$additional;
2786: }
2787:
2788: sub display_filter_js {
2789: my $includetext = &mt('Include parameter types');
2790: return <<"ENDJS";
2791:
2792: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2793: var firstType = 'hidden';
2794: if (setter.options[setter.selectedIndex].value == 'containing') {
2795: firstType = 'text';
2796: }
2797: firstObject = document.getElementById(firstid);
2798: if (typeof(firstObject) == 'object') {
2799: if (firstObject.type != firstType) {
2800: changeInputType(firstObject,firstType);
2801: }
2802: }
2803: if (context == 'parmslog') {
2804: var secondType = 'hidden';
2805: if (firstType == 'text') {
2806: secondType = 'checkbox';
2807: }
2808: secondObject = document.getElementById(secondid);
2809: if (typeof(secondObject) == 'object') {
2810: if (secondObject.type != secondType) {
2811: changeInputType(secondObject,secondType);
2812: }
2813: }
2814: var textItem = document.getElementById(thirdid);
2815: var currtext = textItem.innerHTML;
2816: var newtext;
2817: if (firstType == 'text') {
2818: newtext = '$includetext';
2819: } else {
2820: newtext = ' ';
2821: }
2822: if (currtext != newtext) {
2823: textItem.innerHTML = newtext;
2824: }
2825: }
2826: return;
2827: }
2828:
2829: function changeInputType(oldObject,newType) {
2830: var newObject = document.createElement('input');
2831: newObject.type = newType;
2832: if (oldObject.size) {
2833: newObject.size = oldObject.size;
2834: }
2835: if (oldObject.value) {
2836: newObject.value = oldObject.value;
2837: }
2838: if (oldObject.name) {
2839: newObject.name = oldObject.name;
2840: }
2841: if (oldObject.id) {
2842: newObject.id = oldObject.id;
2843: }
2844: oldObject.parentNode.replaceChild(newObject,oldObject);
2845: return;
2846: }
2847:
2848: ENDJS
1.475 www 2849: }
2850:
1.167 www 2851: sub gradeleveldescription {
2852: my $gradelevel=shift;
2853: my %gradelevels=(0 => 'Not specified',
2854: 1 => 'Grade 1',
2855: 2 => 'Grade 2',
2856: 3 => 'Grade 3',
2857: 4 => 'Grade 4',
2858: 5 => 'Grade 5',
2859: 6 => 'Grade 6',
2860: 7 => 'Grade 7',
2861: 8 => 'Grade 8',
2862: 9 => 'Grade 9',
2863: 10 => 'Grade 10',
2864: 11 => 'Grade 11',
2865: 12 => 'Grade 12',
2866: 13 => 'Grade 13',
2867: 14 => '100 Level',
2868: 15 => '200 Level',
2869: 16 => '300 Level',
2870: 17 => '400 Level',
2871: 18 => 'Graduate Level');
2872: return &mt($gradelevels{$gradelevel});
2873: }
2874:
1.163 www 2875: sub select_level_form {
2876: my ($deflevel,$name)=@_;
2877: unless ($deflevel) { $deflevel=0; }
1.167 www 2878: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2879: for (my $i=0; $i<=18; $i++) {
2880: $selectform.="<option value=\"$i\" ".
1.253 albertel 2881: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2882: ">".&gradeleveldescription($i)."</option>\n";
2883: }
2884: $selectform.="</select>";
2885: return $selectform;
1.163 www 2886: }
1.167 www 2887:
1.35 matthew 2888: #-------------------------------------------
2889:
1.45 matthew 2890: =pod
2891:
1.1256 raeburn 2892: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2893:
2894: Returns a string containing a <select name='$name' size='1'> form to
2895: allow a user to select the domain to preform an operation in.
2896: See loncreateuser.pm for an example invocation and use.
2897:
1.90 www 2898: If the $includeempty flag is set, it also includes an empty choice ("no domain
2899: selected");
2900:
1.743 raeburn 2901: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2902:
1.910 raeburn 2903: 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.
2904:
1.1121 raeburn 2905: The optional $incdoms is a reference to an array of domains which will be the only available options.
2906:
2907: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2908:
1.1256 raeburn 2909: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2910:
1.35 matthew 2911: =cut
2912:
2913: #-------------------------------------------
1.34 matthew 2914: sub select_dom_form {
1.1256 raeburn 2915: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2916: if ($onchange) {
1.874 raeburn 2917: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2918: }
1.1256 raeburn 2919: if ($disabled) {
2920: $disabled = ' disabled="disabled"';
2921: }
1.1121 raeburn 2922: my (@domains,%exclude);
1.910 raeburn 2923: if (ref($incdoms) eq 'ARRAY') {
2924: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2925: } else {
2926: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2927: }
1.90 www 2928: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2929: if (ref($excdoms) eq 'ARRAY') {
2930: map { $exclude{$_} = 1; } @{$excdoms};
2931: }
1.1256 raeburn 2932: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2933: foreach my $dom (@domains) {
1.1121 raeburn 2934: next if ($exclude{$dom});
1.356 albertel 2935: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2936: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2937: if ($showdomdesc) {
2938: if ($dom ne '') {
2939: my $domdesc = &Apache::lonnet::domain($dom,'description');
2940: if ($domdesc ne '') {
2941: $selectdomain .= ' ('.$domdesc.')';
2942: }
2943: }
2944: }
2945: $selectdomain .= "</option>\n";
1.34 matthew 2946: }
2947: $selectdomain.="</select>";
2948: return $selectdomain;
2949: }
2950:
1.35 matthew 2951: #-------------------------------------------
2952:
1.45 matthew 2953: =pod
2954:
1.648 raeburn 2955: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2956:
1.586 raeburn 2957: input: 4 arguments (two required, two optional) -
2958: $domain - domain of new user
2959: $name - name of form element
2960: $default - Value of 'default' causes a default item to be first
2961: option, and selected by default.
2962: $hide - Value of 'hide' causes hiding of the name of the server,
2963: if 1 server found, or default, if 0 found.
1.594 raeburn 2964: output: returns 2 items:
1.586 raeburn 2965: (a) form element which contains either:
2966: (i) <select name="$name">
2967: <option value="$hostid1">$hostid $servers{$hostid}</option>
2968: <option value="$hostid2">$hostid $servers{$hostid}</option>
2969: </select>
2970: form item if there are multiple library servers in $domain, or
2971: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2972: if there is only one library server in $domain.
2973:
2974: (b) number of library servers found.
2975:
2976: See loncreateuser.pm for example of use.
1.35 matthew 2977:
2978: =cut
2979:
2980: #-------------------------------------------
1.586 raeburn 2981: sub home_server_form_item {
2982: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2983: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2984: my $result;
2985: my $numlib = keys(%servers);
2986: if ($numlib > 1) {
2987: $result .= '<select name="'.$name.'" />'."\n";
2988: if ($default) {
1.804 bisitz 2989: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2990: '</option>'."\n";
2991: }
2992: foreach my $hostid (sort(keys(%servers))) {
2993: $result.= '<option value="'.$hostid.'">'.
2994: $hostid.' '.$servers{$hostid}."</option>\n";
2995: }
2996: $result .= '</select>'."\n";
2997: } elsif ($numlib == 1) {
2998: my $hostid;
2999: foreach my $item (keys(%servers)) {
3000: $hostid = $item;
3001: }
3002: $result .= '<input type="hidden" name="'.$name.'" value="'.
3003: $hostid.'" />';
3004: if (!$hide) {
3005: $result .= $hostid.' '.$servers{$hostid};
3006: }
3007: $result .= "\n";
3008: } elsif ($default) {
3009: $result .= '<input type="hidden" name="'.$name.
3010: '" value="default" />';
3011: if (!$hide) {
3012: $result .= &mt('default');
3013: }
3014: $result .= "\n";
1.33 matthew 3015: }
1.586 raeburn 3016: return ($result,$numlib);
1.33 matthew 3017: }
1.112 bowersj2 3018:
3019: =pod
3020:
1.534 albertel 3021: =back
3022:
1.112 bowersj2 3023: =cut
1.87 matthew 3024:
3025: ###############################################################
1.112 bowersj2 3026: ## Decoding User Agent ##
1.87 matthew 3027: ###############################################################
3028:
3029: =pod
3030:
1.112 bowersj2 3031: =head1 Decoding the User Agent
3032:
3033: =over 4
3034:
3035: =item * &decode_user_agent()
1.87 matthew 3036:
3037: Inputs: $r
3038:
3039: Outputs:
3040:
3041: =over 4
3042:
1.112 bowersj2 3043: =item * $httpbrowser
1.87 matthew 3044:
1.112 bowersj2 3045: =item * $clientbrowser
1.87 matthew 3046:
1.112 bowersj2 3047: =item * $clientversion
1.87 matthew 3048:
1.112 bowersj2 3049: =item * $clientmathml
1.87 matthew 3050:
1.112 bowersj2 3051: =item * $clientunicode
1.87 matthew 3052:
1.112 bowersj2 3053: =item * $clientos
1.87 matthew 3054:
1.1137 raeburn 3055: =item * $clientmobile
3056:
1.1141 raeburn 3057: =item * $clientinfo
3058:
1.1194 raeburn 3059: =item * $clientosversion
3060:
1.87 matthew 3061: =back
3062:
1.157 matthew 3063: =back
3064:
1.87 matthew 3065: =cut
3066:
3067: ###############################################################
3068: ###############################################################
3069: sub decode_user_agent {
1.247 albertel 3070: my ($r)=@_;
1.87 matthew 3071: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
3072: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
3073: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 3074: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 3075: my $clientbrowser='unknown';
3076: my $clientversion='0';
3077: my $clientmathml='';
3078: my $clientunicode='0';
1.1137 raeburn 3079: my $clientmobile=0;
1.1194 raeburn 3080: my $clientosversion='';
1.87 matthew 3081: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 3082: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 3083: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
3084: $clientbrowser=$bname;
3085: $httpbrowser=~/$vreg/i;
3086: $clientversion=$1;
3087: $clientmathml=($clientversion>=$minv);
3088: $clientunicode=($clientversion>=$univ);
3089: }
3090: }
3091: my $clientos='unknown';
1.1141 raeburn 3092: my $clientinfo;
1.87 matthew 3093: if (($httpbrowser=~/linux/i) ||
3094: ($httpbrowser=~/unix/i) ||
3095: ($httpbrowser=~/ux/i) ||
3096: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
3097: if (($httpbrowser=~/vax/i) ||
3098: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
3099: if ($httpbrowser=~/next/i) { $clientos='next'; }
3100: if (($httpbrowser=~/mac/i) ||
3101: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 3102: if ($httpbrowser=~/win/i) {
3103: $clientos='win';
3104: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
3105: $clientosversion = $1;
3106: }
3107: }
1.87 matthew 3108: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 3109: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
3110: $clientmobile=lc($1);
3111: }
1.1141 raeburn 3112: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
3113: $clientinfo = 'firefox-'.$1;
3114: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3115: $clientinfo = 'chromeframe-'.$1;
3116: }
1.87 matthew 3117: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3118: $clientunicode,$clientos,$clientmobile,$clientinfo,
3119: $clientosversion);
1.87 matthew 3120: }
3121:
1.32 matthew 3122: ###############################################################
3123: ## Authentication changing form generation subroutines ##
3124: ###############################################################
3125: ##
3126: ## All of the authform_xxxxxxx subroutines take their inputs in a
3127: ## hash, and have reasonable default values.
3128: ##
3129: ## formname = the name given in the <form> tag.
1.35 matthew 3130: #-------------------------------------------
3131:
1.45 matthew 3132: =pod
3133:
1.112 bowersj2 3134: =head1 Authentication Routines
3135:
3136: =over 4
3137:
1.648 raeburn 3138: =item * &authform_xxxxxx()
1.35 matthew 3139:
3140: The authform_xxxxxx subroutines provide javascript and html forms which
3141: handle some of the conveniences required for authentication forms.
3142: This is not an optimal method, but it works.
3143:
3144: =over 4
3145:
1.112 bowersj2 3146: =item * authform_header
1.35 matthew 3147:
1.112 bowersj2 3148: =item * authform_authorwarning
1.35 matthew 3149:
1.112 bowersj2 3150: =item * authform_nochange
1.35 matthew 3151:
1.112 bowersj2 3152: =item * authform_kerberos
1.35 matthew 3153:
1.112 bowersj2 3154: =item * authform_internal
1.35 matthew 3155:
1.112 bowersj2 3156: =item * authform_filesystem
1.35 matthew 3157:
1.1310 raeburn 3158: =item * authform_lti
3159:
1.35 matthew 3160: =back
3161:
1.648 raeburn 3162: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3163:
1.35 matthew 3164: =cut
3165:
3166: #-------------------------------------------
1.32 matthew 3167: sub authform_header{
3168: my %in = (
3169: formname => 'cu',
1.80 albertel 3170: kerb_def_dom => '',
1.32 matthew 3171: @_,
3172: );
3173: $in{'formname'} = 'document.' . $in{'formname'};
3174: my $result='';
1.80 albertel 3175:
3176: #---------------------------------------------- Code for upper case translation
3177: my $Javascript_toUpperCase;
3178: unless ($in{kerb_def_dom}) {
3179: $Javascript_toUpperCase =<<"END";
3180: switch (choice) {
3181: case 'krb': currentform.elements[choicearg].value =
3182: currentform.elements[choicearg].value.toUpperCase();
3183: break;
3184: default:
3185: }
3186: END
3187: } else {
3188: $Javascript_toUpperCase = "";
3189: }
3190:
1.165 raeburn 3191: my $radioval = "'nochange'";
1.591 raeburn 3192: if (defined($in{'curr_authtype'})) {
3193: if ($in{'curr_authtype'} ne '') {
3194: $radioval = "'".$in{'curr_authtype'}."arg'";
3195: }
1.174 matthew 3196: }
1.165 raeburn 3197: my $argfield = 'null';
1.591 raeburn 3198: if (defined($in{'mode'})) {
1.165 raeburn 3199: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3200: if (defined($in{'curr_autharg'})) {
3201: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3202: $argfield = "'$in{'curr_autharg'}'";
3203: }
3204: }
3205: }
3206: }
3207:
1.32 matthew 3208: $result.=<<"END";
3209: var current = new Object();
1.165 raeburn 3210: current.radiovalue = $radioval;
3211: current.argfield = $argfield;
1.32 matthew 3212:
3213: function changed_radio(choice,currentform) {
3214: var choicearg = choice + 'arg';
3215: // If a radio button in changed, we need to change the argfield
3216: if (current.radiovalue != choice) {
3217: current.radiovalue = choice;
3218: if (current.argfield != null) {
3219: currentform.elements[current.argfield].value = '';
3220: }
3221: if (choice == 'nochange') {
3222: current.argfield = null;
3223: } else {
3224: current.argfield = choicearg;
3225: switch(choice) {
3226: case 'krb':
3227: currentform.elements[current.argfield].value =
3228: "$in{'kerb_def_dom'}";
3229: break;
3230: default:
3231: break;
3232: }
3233: }
3234: }
3235: return;
3236: }
1.22 www 3237:
1.32 matthew 3238: function changed_text(choice,currentform) {
3239: var choicearg = choice + 'arg';
3240: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3241: $Javascript_toUpperCase
1.32 matthew 3242: // clear old field
3243: if ((current.argfield != choicearg) && (current.argfield != null)) {
3244: currentform.elements[current.argfield].value = '';
3245: }
3246: current.argfield = choicearg;
3247: }
3248: set_auth_radio_buttons(choice,currentform);
3249: return;
1.20 www 3250: }
1.32 matthew 3251:
3252: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3253: var numauthchoices = currentform.login.length;
3254: if (typeof numauthchoices == "undefined") {
3255: return;
3256: }
1.32 matthew 3257: var i=0;
1.986 raeburn 3258: while (i < numauthchoices) {
1.32 matthew 3259: if (currentform.login[i].value == newvalue) { break; }
3260: i++;
3261: }
1.986 raeburn 3262: if (i == numauthchoices) {
1.32 matthew 3263: return;
3264: }
3265: current.radiovalue = newvalue;
3266: currentform.login[i].checked = true;
3267: return;
3268: }
3269: END
3270: return $result;
3271: }
3272:
1.1106 raeburn 3273: sub authform_authorwarning {
1.32 matthew 3274: my $result='';
1.144 matthew 3275: $result='<i>'.
3276: &mt('As a general rule, only authors or co-authors should be '.
3277: 'filesystem authenticated '.
3278: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3279: return $result;
3280: }
3281:
1.1106 raeburn 3282: sub authform_nochange {
1.32 matthew 3283: my %in = (
3284: formname => 'document.cu',
3285: kerb_def_dom => 'MSU.EDU',
3286: @_,
3287: );
1.1106 raeburn 3288: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3289: my $result;
1.1104 raeburn 3290: if (!$authnum) {
1.1105 raeburn 3291: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3292: } else {
3293: $result = '<label>'.&mt('[_1] Do not change login data',
3294: '<input type="radio" name="login" value="nochange" '.
3295: 'checked="checked" onclick="'.
1.281 albertel 3296: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3297: '</label>';
1.586 raeburn 3298: }
1.32 matthew 3299: return $result;
3300: }
3301:
1.591 raeburn 3302: sub authform_kerberos {
1.32 matthew 3303: my %in = (
3304: formname => 'document.cu',
3305: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3306: kerb_def_auth => 'krb4',
1.32 matthew 3307: @_,
3308: );
1.586 raeburn 3309: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3310: $autharg,$jscall,$disabled);
1.1106 raeburn 3311: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3312: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3313: $check5 = ' checked="checked"';
1.80 albertel 3314: } else {
1.772 bisitz 3315: $check4 = ' checked="checked"';
1.80 albertel 3316: }
1.1259 raeburn 3317: if ($in{'readonly'}) {
3318: $disabled = ' disabled="disabled"';
3319: }
1.165 raeburn 3320: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3321: if (defined($in{'curr_authtype'})) {
3322: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3323: $krbcheck = ' checked="checked"';
1.623 raeburn 3324: if (defined($in{'mode'})) {
3325: if ($in{'mode'} eq 'modifyuser') {
3326: $krbcheck = '';
3327: }
3328: }
1.591 raeburn 3329: if (defined($in{'curr_kerb_ver'})) {
3330: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3331: $check5 = ' checked="checked"';
1.591 raeburn 3332: $check4 = '';
3333: } else {
1.772 bisitz 3334: $check4 = ' checked="checked"';
1.591 raeburn 3335: $check5 = '';
3336: }
1.586 raeburn 3337: }
1.591 raeburn 3338: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3339: $krbarg = $in{'curr_autharg'};
3340: }
1.586 raeburn 3341: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3342: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3343: $result =
3344: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3345: $in{'curr_autharg'},$krbver);
3346: } else {
3347: $result =
3348: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3349: }
3350: return $result;
3351: }
3352: }
3353: } else {
3354: if ($authnum == 1) {
1.784 bisitz 3355: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3356: }
3357: }
1.586 raeburn 3358: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3359: return;
1.587 raeburn 3360: } elsif ($authtype eq '') {
1.591 raeburn 3361: if (defined($in{'mode'})) {
1.587 raeburn 3362: if ($in{'mode'} eq 'modifycourse') {
3363: if ($authnum == 1) {
1.1259 raeburn 3364: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3365: }
3366: }
3367: }
1.586 raeburn 3368: }
3369: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3370: if ($authtype eq '') {
3371: $authtype = '<input type="radio" name="login" value="krb" '.
3372: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3373: $krbcheck.$disabled.' />';
1.586 raeburn 3374: }
3375: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3376: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3377: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3378: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3379: $in{'curr_authtype'} eq 'krb4')) {
3380: $result .= &mt
1.144 matthew 3381: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3382: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3383: '<label>'.$authtype,
1.281 albertel 3384: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3385: 'value="'.$krbarg.'" '.
1.1259 raeburn 3386: 'onchange="'.$jscall.'"'.$disabled.' />',
3387: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3388: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3389: '</label>');
1.586 raeburn 3390: } elsif ($can_assign{'krb4'}) {
3391: $result .= &mt
3392: ('[_1] Kerberos authenticated with domain [_2] '.
3393: '[_3] Version 4 [_4]',
3394: '<label>'.$authtype,
3395: '</label><input type="text" size="10" name="krbarg" '.
3396: 'value="'.$krbarg.'" '.
1.1259 raeburn 3397: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3398: '<label><input type="hidden" name="krbver" value="4" />',
3399: '</label>');
3400: } elsif ($can_assign{'krb5'}) {
3401: $result .= &mt
3402: ('[_1] Kerberos authenticated with domain [_2] '.
3403: '[_3] Version 5 [_4]',
3404: '<label>'.$authtype,
3405: '</label><input type="text" size="10" name="krbarg" '.
3406: 'value="'.$krbarg.'" '.
1.1259 raeburn 3407: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3408: '<label><input type="hidden" name="krbver" value="5" />',
3409: '</label>');
3410: }
1.32 matthew 3411: return $result;
3412: }
3413:
1.1106 raeburn 3414: sub authform_internal {
1.586 raeburn 3415: my %in = (
1.32 matthew 3416: formname => 'document.cu',
3417: kerb_def_dom => 'MSU.EDU',
3418: @_,
3419: );
1.1259 raeburn 3420: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3421: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3422: if ($in{'readonly'}) {
3423: $disabled = ' disabled="disabled"';
3424: }
1.591 raeburn 3425: if (defined($in{'curr_authtype'})) {
3426: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3427: if ($can_assign{'int'}) {
1.772 bisitz 3428: $intcheck = 'checked="checked" ';
1.623 raeburn 3429: if (defined($in{'mode'})) {
3430: if ($in{'mode'} eq 'modifyuser') {
3431: $intcheck = '';
3432: }
3433: }
1.591 raeburn 3434: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3435: $intarg = $in{'curr_autharg'};
3436: }
3437: } else {
3438: $result = &mt('Currently internally authenticated.');
3439: return $result;
1.165 raeburn 3440: }
3441: }
1.586 raeburn 3442: } else {
3443: if ($authnum == 1) {
1.784 bisitz 3444: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3445: }
3446: }
3447: if (!$can_assign{'int'}) {
3448: return;
1.587 raeburn 3449: } elsif ($authtype eq '') {
1.591 raeburn 3450: if (defined($in{'mode'})) {
1.587 raeburn 3451: if ($in{'mode'} eq 'modifycourse') {
3452: if ($authnum == 1) {
1.1259 raeburn 3453: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3454: }
3455: }
3456: }
1.165 raeburn 3457: }
1.586 raeburn 3458: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3459: if ($authtype eq '') {
3460: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3461: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3462: }
1.605 bisitz 3463: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3464: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3465: $result = &mt
1.144 matthew 3466: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3467: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3468: $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 3469: return $result;
3470: }
3471:
1.1104 raeburn 3472: sub authform_local {
1.32 matthew 3473: my %in = (
3474: formname => 'document.cu',
3475: kerb_def_dom => 'MSU.EDU',
3476: @_,
3477: );
1.1259 raeburn 3478: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3479: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3480: if ($in{'readonly'}) {
3481: $disabled = ' disabled="disabled"';
3482: }
1.591 raeburn 3483: if (defined($in{'curr_authtype'})) {
3484: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3485: if ($can_assign{'loc'}) {
1.772 bisitz 3486: $loccheck = 'checked="checked" ';
1.623 raeburn 3487: if (defined($in{'mode'})) {
3488: if ($in{'mode'} eq 'modifyuser') {
3489: $loccheck = '';
3490: }
3491: }
1.591 raeburn 3492: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3493: $locarg = $in{'curr_autharg'};
3494: }
3495: } else {
3496: $result = &mt('Currently using local (institutional) authentication.');
3497: return $result;
1.165 raeburn 3498: }
3499: }
1.586 raeburn 3500: } else {
3501: if ($authnum == 1) {
1.784 bisitz 3502: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3503: }
3504: }
3505: if (!$can_assign{'loc'}) {
3506: return;
1.587 raeburn 3507: } elsif ($authtype eq '') {
1.591 raeburn 3508: if (defined($in{'mode'})) {
1.587 raeburn 3509: if ($in{'mode'} eq 'modifycourse') {
3510: if ($authnum == 1) {
1.1259 raeburn 3511: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3512: }
3513: }
3514: }
1.165 raeburn 3515: }
1.586 raeburn 3516: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3517: if ($authtype eq '') {
3518: $authtype = '<input type="radio" name="login" value="loc" '.
3519: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3520: $jscall.'"'.$disabled.' />';
1.586 raeburn 3521: }
3522: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3523: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3524: $result = &mt('[_1] Local Authentication with argument [_2]',
3525: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3526: return $result;
3527: }
3528:
1.1106 raeburn 3529: sub authform_filesystem {
1.32 matthew 3530: my %in = (
3531: formname => 'document.cu',
3532: kerb_def_dom => 'MSU.EDU',
3533: @_,
3534: );
1.1259 raeburn 3535: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3536: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3537: if ($in{'readonly'}) {
3538: $disabled = ' disabled="disabled"';
3539: }
1.591 raeburn 3540: if (defined($in{'curr_authtype'})) {
3541: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3542: if ($can_assign{'fsys'}) {
1.772 bisitz 3543: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3544: if (defined($in{'mode'})) {
3545: if ($in{'mode'} eq 'modifyuser') {
3546: $fsyscheck = '';
3547: }
3548: }
1.586 raeburn 3549: } else {
3550: $result = &mt('Currently Filesystem Authenticated.');
3551: return $result;
1.1259 raeburn 3552: }
1.586 raeburn 3553: }
3554: } else {
3555: if ($authnum == 1) {
1.784 bisitz 3556: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3557: }
3558: }
3559: if (!$can_assign{'fsys'}) {
3560: return;
1.587 raeburn 3561: } elsif ($authtype eq '') {
1.591 raeburn 3562: if (defined($in{'mode'})) {
1.587 raeburn 3563: if ($in{'mode'} eq 'modifycourse') {
3564: if ($authnum == 1) {
1.1259 raeburn 3565: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3566: }
3567: }
3568: }
1.586 raeburn 3569: }
3570: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3571: if ($authtype eq '') {
3572: $authtype = '<input type="radio" name="login" value="fsys" '.
3573: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3574: $jscall.'"'.$disabled.' />';
1.586 raeburn 3575: }
1.1310 raeburn 3576: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3577: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3578: $result = &mt
1.144 matthew 3579: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3580: '<label>'.$authtype,'</label>'.$autharg);
3581: return $result;
3582: }
3583:
3584: sub authform_lti {
3585: my %in = (
3586: formname => 'document.cu',
3587: kerb_def_dom => 'MSU.EDU',
3588: @_,
3589: );
3590: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3591: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3592: if ($in{'readonly'}) {
3593: $disabled = ' disabled="disabled"';
3594: }
3595: if (defined($in{'curr_authtype'})) {
3596: if ($in{'curr_authtype'} eq 'lti') {
3597: if ($can_assign{'lti'}) {
3598: $lticheck = 'checked="checked" ';
3599: if (defined($in{'mode'})) {
3600: if ($in{'mode'} eq 'modifyuser') {
3601: $lticheck = '';
3602: }
3603: }
3604: } else {
3605: $result = &mt('Currently LTI Authenticated.');
3606: return $result;
3607: }
3608: }
3609: } else {
3610: if ($authnum == 1) {
3611: $authtype = '<input type="hidden" name="login" value="lti" />';
3612: }
3613: }
3614: if (!$can_assign{'lti'}) {
3615: return;
3616: } elsif ($authtype eq '') {
3617: if (defined($in{'mode'})) {
3618: if ($in{'mode'} eq 'modifycourse') {
3619: if ($authnum == 1) {
3620: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3621: }
3622: }
3623: }
3624: }
3625: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3626: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3627: $authtype = '<input type="radio" name="login" value="lti" '.
3628: $lticheck.' onchange="'.$jscall.'" onclick="'.
3629: $jscall.'"'.$disabled.' />';
3630: }
3631: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3632: if ($authtype) {
3633: $result = &mt('[_1] LTI Authenticated',
3634: '<label>'.$authtype.'</label>'.$autharg);
3635: } else {
3636: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3637: $autharg;
3638: }
1.32 matthew 3639: return $result;
3640: }
3641:
1.586 raeburn 3642: sub get_assignable_auth {
3643: my ($dom) = @_;
3644: if ($dom eq '') {
3645: $dom = $env{'request.role.domain'};
3646: }
3647: my %can_assign = (
3648: krb4 => 1,
3649: krb5 => 1,
3650: int => 1,
3651: loc => 1,
1.1310 raeburn 3652: lti => 1,
1.586 raeburn 3653: );
3654: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3655: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3656: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3657: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3658: my $context;
3659: if ($env{'request.role'} =~ /^au/) {
3660: $context = 'author';
1.1259 raeburn 3661: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3662: $context = 'domain';
3663: } elsif ($env{'request.course.id'}) {
3664: $context = 'course';
3665: }
3666: if ($context) {
3667: if (ref($authhash->{$context}) eq 'HASH') {
3668: %can_assign = %{$authhash->{$context}};
3669: }
3670: }
3671: }
3672: }
3673: my $authnum = 0;
3674: foreach my $key (keys(%can_assign)) {
3675: if ($can_assign{$key}) {
3676: $authnum ++;
3677: }
3678: }
3679: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3680: $authnum --;
3681: }
3682: return ($authnum,%can_assign);
3683: }
3684:
1.1331 raeburn 3685: sub check_passwd_rules {
3686: my ($domain,$plainpass) = @_;
3687: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3688: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3689: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3690: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3691: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3692: if ($passwdconf{'min'} > $min) {
3693: $min = $passwdconf{'min'};
3694: }
1.1331 raeburn 3695: }
3696: if ($passwdconf{'max'} =~ /^\d+$/) {
3697: $max = $passwdconf{'max'};
3698: }
3699: @chars = @{$passwdconf{'chars'}};
3700: }
3701: if (($min) && (length($plainpass) < $min)) {
3702: push(@brokerule,'min');
3703: }
3704: if (($max) && (length($plainpass) > $max)) {
3705: push(@brokerule,'max');
3706: }
3707: if (@chars) {
3708: my %rules;
3709: map { $rules{$_} = 1; } @chars;
3710: if ($rules{'uc'}) {
3711: unless ($plainpass =~ /[A-Z]/) {
3712: push(@brokerule,'uc');
3713: }
3714: }
3715: if ($rules{'lc'}) {
1.1332 raeburn 3716: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3717: push(@brokerule,'lc');
3718: }
3719: }
3720: if ($rules{'num'}) {
3721: unless ($plainpass =~ /\d/) {
3722: push(@brokerule,'num');
3723: }
3724: }
3725: if ($rules{'spec'}) {
3726: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3727: push(@brokerule,'spec');
3728: }
3729: }
3730: }
3731: if (@brokerule) {
3732: my %rulenames = &Apache::lonlocal::texthash(
3733: uc => 'At least one upper case letter',
3734: lc => 'At least one lower case letter',
3735: num => 'At least one number',
3736: spec => 'At least one non-alphanumeric',
3737: );
3738: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3739: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3740: $rulenames{'num'} .= ': 0123456789';
3741: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3742: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3743: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3744: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1336 raeburn 3745: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1331 raeburn 3746: if (grep(/^$rule$/,@brokerule)) {
3747: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3748: }
3749: }
3750: $warning .= '</ul>';
3751: }
1.1332 raeburn 3752: if (wantarray) {
3753: return @brokerule;
3754: }
1.1331 raeburn 3755: return $warning;
3756: }
3757:
1.1376 raeburn 3758: sub passwd_validation_js {
1.1377 raeburn 3759: my ($currpasswdval,$domain,$context,$id) = @_;
3760: my (%passwdconf,$alertmsg);
3761: if ($context eq 'linkprot') {
3762: my %domconfig = &Apache::lonnet::get_dom('configuration',['ltisec'],$domain);
3763: if (ref($domconfig{'ltisec'}) eq 'HASH') {
3764: if (ref($domconfig{'ltisec'}{'rules'}) eq 'HASH') {
3765: %passwdconf = %{$domconfig{'ltisec'}{'rules'}};
3766: }
3767: }
3768: if ($id eq 'add') {
3769: $alertmsg = &mt('Secret for added launcher did not satisfy requirement(s):').'\n\n';
3770: } elsif ($id =~ /^\d+$/) {
3771: my $pos = $id+1;
3772: $alertmsg = &mt('Secret for launcher [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3773: } else {
3774: $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3775: }
3776: } else {
3777: %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3778: $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
3779: }
1.1376 raeburn 3780: my ($min,$max,@chars,$numrules,$intargjs,%alert);
3781: $numrules = 0;
3782: $min = $Apache::lonnet::passwdmin;
3783: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3784: if ($passwdconf{'min'} =~ /^\d+$/) {
3785: if ($passwdconf{'min'} > $min) {
3786: $min = $passwdconf{'min'};
3787: }
3788: }
3789: if ($passwdconf{'max'} =~ /^\d+$/) {
3790: $max = $passwdconf{'max'};
3791: $numrules ++;
3792: }
3793: @chars = @{$passwdconf{'chars'}};
3794: if (@chars) {
3795: $numrules ++;
3796: }
3797: }
3798: if ($min > 0) {
3799: $numrules ++;
3800: }
3801: if (($min > 0) || ($max ne '') || (@chars > 0)) {
3802: if ($min) {
3803: $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
3804: }
3805: if ($max) {
3806: $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
3807: }
3808: my (@charalerts,@charrules);
3809: if (@chars) {
3810: if (grep(/^uc$/,@chars)) {
3811: push(@charalerts,&mt('contain at least one upper case letter'));
3812: push(@charrules,'uc');
3813: }
3814: if (grep(/^lc$/,@chars)) {
3815: push(@charalerts,&mt('contain at least one lower case letter'));
3816: push(@charrules,'lc');
3817: }
3818: if (grep(/^num$/,@chars)) {
3819: push(@charalerts,&mt('contain at least one number'));
3820: push(@charrules,'num');
3821: }
3822: if (grep(/^spec$/,@chars)) {
3823: push(@charalerts,&mt('contain at least one non-alphanumeric'));
3824: push(@charrules,'spec');
3825: }
3826: }
3827: $intargjs = qq| var rulesmsg = '';\n|.
3828: qq| var currpwval = $currpasswdval;\n|;
3829: if ($min) {
3830: $intargjs .= qq|
3831: if (currpwval.length < $min) {
3832: rulesmsg += ' - $alert{min}';
3833: }
3834: |;
3835: }
3836: if ($max) {
3837: $intargjs .= qq|
3838: if (currpwval.length > $max) {
3839: rulesmsg += ' - $alert{max}';
3840: }
3841: |;
3842: }
3843: if (@chars > 0) {
3844: my $charrulestr = '"'.join('","',@charrules).'"';
3845: my $charalertstr = '"'.join('","',@charalerts).'"';
3846: $intargjs .= qq| var brokerules = new Array();\n|.
3847: qq| var charrules = new Array($charrulestr);\n|.
3848: qq| var charalerts = new Array($charalertstr);\n|;
3849: my %rules;
3850: map { $rules{$_} = 1; } @chars;
3851: if ($rules{'uc'}) {
3852: $intargjs .= qq|
3853: var ucRegExp = /[A-Z]/;
3854: if (!ucRegExp.test(currpwval)) {
3855: brokerules.push('uc');
3856: }
3857: |;
3858: }
3859: if ($rules{'lc'}) {
3860: $intargjs .= qq|
3861: var lcRegExp = /[a-z]/;
3862: if (!lcRegExp.test(currpwval)) {
3863: brokerules.push('lc');
3864: }
3865: |;
3866: }
3867: if ($rules{'num'}) {
3868: $intargjs .= qq|
3869: var numRegExp = /[0-9]/;
3870: if (!numRegExp.test(currpwval)) {
3871: brokerules.push('num');
3872: }
3873: |;
3874: }
3875: if ($rules{'spec'}) {
3876: $intargjs .= q|
3877: var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
3878: if (!specRegExp.test(currpwval)) {
3879: brokerules.push('spec');
3880: }
3881: |;
3882: }
3883: $intargjs .= qq|
3884: if (brokerules.length > 0) {
3885: for (var i=0; i<brokerules.length; i++) {
3886: for (var j=0; j<charrules.length; j++) {
3887: if (brokerules[i] == charrules[j]) {
3888: rulesmsg += ' - '+charalerts[j]+'\\n';
3889: break;
3890: }
3891: }
3892: }
3893: }
3894: |;
3895: }
3896: $intargjs .= qq|
3897: if (rulesmsg != '') {
3898: rulesmsg = '$alertmsg'+rulesmsg;
3899: alert(rulesmsg);
3900: return false;
3901: }
3902: |;
3903: }
3904: return ($numrules,$intargjs);
3905: }
3906:
1.80 albertel 3907: ###############################################################
3908: ## Get Kerberos Defaults for Domain ##
3909: ###############################################################
3910: ##
3911: ## Returns default kerberos version and an associated argument
3912: ## as listed in file domain.tab. If not listed, provides
3913: ## appropriate default domain and kerberos version.
3914: ##
3915: #-------------------------------------------
3916:
3917: =pod
3918:
1.648 raeburn 3919: =item * &get_kerberos_defaults()
1.80 albertel 3920:
3921: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3922: version and domain. If not found, it defaults to version 4 and the
3923: domain of the server.
1.80 albertel 3924:
1.648 raeburn 3925: =over 4
3926:
1.80 albertel 3927: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3928:
1.648 raeburn 3929: =back
3930:
3931: =back
3932:
1.80 albertel 3933: =cut
3934:
3935: #-------------------------------------------
3936: sub get_kerberos_defaults {
3937: my $domain=shift;
1.641 raeburn 3938: my ($krbdef,$krbdefdom);
3939: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3940: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3941: $krbdef = $domdefaults{'auth_def'};
3942: $krbdefdom = $domdefaults{'auth_arg_def'};
3943: } else {
1.80 albertel 3944: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3945: my $krbdefdom=$1;
3946: $krbdefdom=~tr/a-z/A-Z/;
3947: $krbdef = "krb4";
3948: }
3949: return ($krbdef,$krbdefdom);
3950: }
1.112 bowersj2 3951:
1.32 matthew 3952:
1.46 matthew 3953: ###############################################################
3954: ## Thesaurus Functions ##
3955: ###############################################################
1.20 www 3956:
1.46 matthew 3957: =pod
1.20 www 3958:
1.112 bowersj2 3959: =head1 Thesaurus Functions
3960:
3961: =over 4
3962:
1.648 raeburn 3963: =item * &initialize_keywords()
1.46 matthew 3964:
3965: Initializes the package variable %Keywords if it is empty. Uses the
3966: package variable $thesaurus_db_file.
3967:
3968: =cut
3969:
3970: ###################################################
3971:
3972: sub initialize_keywords {
3973: return 1 if (scalar keys(%Keywords));
3974: # If we are here, %Keywords is empty, so fill it up
3975: # Make sure the file we need exists...
3976: if (! -e $thesaurus_db_file) {
3977: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3978: " failed because it does not exist");
3979: return 0;
3980: }
3981: # Set up the hash as a database
3982: my %thesaurus_db;
3983: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3984: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3985: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3986: $thesaurus_db_file);
3987: return 0;
3988: }
3989: # Get the average number of appearances of a word.
3990: my $avecount = $thesaurus_db{'average.count'};
3991: # Put keywords (those that appear > average) into %Keywords
3992: while (my ($word,$data)=each (%thesaurus_db)) {
3993: my ($count,undef) = split /:/,$data;
3994: $Keywords{$word}++ if ($count > $avecount);
3995: }
3996: untie %thesaurus_db;
3997: # Remove special values from %Keywords.
1.356 albertel 3998: foreach my $value ('total.count','average.count') {
3999: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 4000: }
1.46 matthew 4001: return 1;
4002: }
4003:
4004: ###################################################
4005:
4006: =pod
4007:
1.648 raeburn 4008: =item * &keyword($word)
1.46 matthew 4009:
4010: Returns true if $word is a keyword. A keyword is a word that appears more
4011: than the average number of times in the thesaurus database. Calls
4012: &initialize_keywords
4013:
4014: =cut
4015:
4016: ###################################################
1.20 www 4017:
4018: sub keyword {
1.46 matthew 4019: return if (!&initialize_keywords());
4020: my $word=lc(shift());
4021: $word=~s/\W//g;
4022: return exists($Keywords{$word});
1.20 www 4023: }
1.46 matthew 4024:
4025: ###############################################################
4026:
4027: =pod
1.20 www 4028:
1.648 raeburn 4029: =item * &get_related_words()
1.46 matthew 4030:
1.160 matthew 4031: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 4032: an array of words. If the keyword is not in the thesaurus, an empty array
4033: will be returned. The order of the words returned is determined by the
4034: database which holds them.
4035:
4036: Uses global $thesaurus_db_file.
4037:
1.1057 foxr 4038:
1.46 matthew 4039: =cut
4040:
4041: ###############################################################
4042: sub get_related_words {
4043: my $keyword = shift;
4044: my %thesaurus_db;
4045: if (! -e $thesaurus_db_file) {
4046: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
4047: "failed because the file does not exist");
4048: return ();
4049: }
4050: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 4051: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 4052: return ();
4053: }
4054: my @Words=();
1.429 www 4055: my $count=0;
1.46 matthew 4056: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 4057: # The first element is the number of times
4058: # the word appears. We do not need it now.
1.429 www 4059: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
4060: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
4061: my $threshold=$mostfrequentcount/10;
4062: foreach my $possibleword (@RelatedWords) {
4063: my ($word,$wordcount)=split(/\,/,$possibleword);
4064: if ($wordcount>$threshold) {
4065: push(@Words,$word);
4066: $count++;
4067: if ($count>10) { last; }
4068: }
1.20 www 4069: }
4070: }
1.46 matthew 4071: untie %thesaurus_db;
4072: return @Words;
1.14 harris41 4073: }
1.1090 foxr 4074: ###############################################################
4075: #
4076: # Spell checking
4077: #
4078:
4079: =pod
4080:
1.1142 raeburn 4081: =back
4082:
1.1090 foxr 4083: =head1 Spell checking
4084:
4085: =over 4
4086:
4087: =item * &check_spelling($wordlist $language)
4088:
4089: Takes a string containing words and feeds it to an external
4090: spellcheck program via a pipeline. Returns a string containing
4091: them mis-spelled words.
4092:
4093: Parameters:
4094:
4095: =over 4
4096:
4097: =item - $wordlist
4098:
4099: String that will be fed into the spellcheck program.
4100:
4101: =item - $language
4102:
4103: Language string that specifies the language for which the spell
4104: check will be performed.
4105:
4106: =back
4107:
4108: =back
4109:
4110: Note: This sub assumes that aspell is installed.
4111:
4112:
4113: =cut
4114:
1.46 matthew 4115:
1.1090 foxr 4116: sub check_spelling {
4117: my ($wordlist, $language) = @_;
1.1091 foxr 4118: my @misspellings;
4119:
4120: # Generate the speller and set the langauge.
4121: # if explicitly selected:
1.1090 foxr 4122:
1.1091 foxr 4123: my $speller = Text::Aspell->new;
1.1090 foxr 4124: if ($language) {
1.1091 foxr 4125: $speller->set_option('lang', $language);
1.1090 foxr 4126: }
4127:
1.1091 foxr 4128: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 4129:
1.1091 foxr 4130: my @words = split(/\s+/, $wordlist);
1.1090 foxr 4131:
1.1091 foxr 4132: foreach my $word (@words) {
4133: if(! $speller->check($word)) {
4134: push(@misspellings, $word);
1.1090 foxr 4135: }
4136: }
1.1091 foxr 4137: return join(' ', @misspellings);
4138:
1.1090 foxr 4139: }
4140:
1.61 www 4141: # -------------------------------------------------------------- Plaintext name
1.81 albertel 4142: =pod
4143:
1.112 bowersj2 4144: =head1 User Name Functions
4145:
4146: =over 4
4147:
1.648 raeburn 4148: =item * &plainname($uname,$udom,$first)
1.81 albertel 4149:
1.112 bowersj2 4150: Takes a users logon name and returns it as a string in
1.226 albertel 4151: "first middle last generation" form
4152: if $first is set to 'lastname' then it returns it as
4153: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 4154:
4155: =cut
1.61 www 4156:
1.295 www 4157:
1.81 albertel 4158: ###############################################################
1.61 www 4159: sub plainname {
1.226 albertel 4160: my ($uname,$udom,$first)=@_;
1.537 albertel 4161: return if (!defined($uname) || !defined($udom));
1.295 www 4162: my %names=&getnames($uname,$udom);
1.226 albertel 4163: my $name=&Apache::lonnet::format_name($names{'firstname'},
4164: $names{'middlename'},
4165: $names{'lastname'},
4166: $names{'generation'},$first);
4167: $name=~s/^\s+//;
1.62 www 4168: $name=~s/\s+$//;
4169: $name=~s/\s+/ /g;
1.353 albertel 4170: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 4171: return $name;
1.61 www 4172: }
1.66 www 4173:
4174: # -------------------------------------------------------------------- Nickname
1.81 albertel 4175: =pod
4176:
1.648 raeburn 4177: =item * &nickname($uname,$udom)
1.81 albertel 4178:
4179: Gets a users name and returns it as a string as
4180:
4181: ""nickname""
1.66 www 4182:
1.81 albertel 4183: if the user has a nickname or
4184:
4185: "first middle last generation"
4186:
4187: if the user does not
4188:
4189: =cut
1.66 www 4190:
4191: sub nickname {
4192: my ($uname,$udom)=@_;
1.537 albertel 4193: return if (!defined($uname) || !defined($udom));
1.295 www 4194: my %names=&getnames($uname,$udom);
1.68 albertel 4195: my $name=$names{'nickname'};
1.66 www 4196: if ($name) {
4197: $name='"'.$name.'"';
4198: } else {
4199: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
4200: $names{'lastname'}.' '.$names{'generation'};
4201: $name=~s/\s+$//;
4202: $name=~s/\s+/ /g;
4203: }
4204: return $name;
4205: }
4206:
1.295 www 4207: sub getnames {
4208: my ($uname,$udom)=@_;
1.537 albertel 4209: return if (!defined($uname) || !defined($udom));
1.433 albertel 4210: if ($udom eq 'public' && $uname eq 'public') {
4211: return ('lastname' => &mt('Public'));
4212: }
1.295 www 4213: my $id=$uname.':'.$udom;
4214: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
4215: if ($cached) {
4216: return %{$names};
4217: } else {
4218: my %loadnames=&Apache::lonnet::get('environment',
4219: ['firstname','middlename','lastname','generation','nickname'],
4220: $udom,$uname);
4221: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
4222: return %loadnames;
4223: }
4224: }
1.61 www 4225:
1.542 raeburn 4226: # -------------------------------------------------------------------- getemails
1.648 raeburn 4227:
1.542 raeburn 4228: =pod
4229:
1.648 raeburn 4230: =item * &getemails($uname,$udom)
1.542 raeburn 4231:
4232: Gets a user's email information and returns it as a hash with keys:
4233: notification, critnotification, permanentemail
4234:
4235: For notification and critnotification, values are comma-separated lists
1.648 raeburn 4236: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 4237:
1.648 raeburn 4238:
1.542 raeburn 4239: =cut
4240:
1.648 raeburn 4241:
1.466 albertel 4242: sub getemails {
4243: my ($uname,$udom)=@_;
4244: if ($udom eq 'public' && $uname eq 'public') {
4245: return;
4246: }
1.467 www 4247: if (!$udom) { $udom=$env{'user.domain'}; }
4248: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 4249: my $id=$uname.':'.$udom;
4250: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
4251: if ($cached) {
4252: return %{$names};
4253: } else {
4254: my %loadnames=&Apache::lonnet::get('environment',
4255: ['notification','critnotification',
4256: 'permanentemail'],
4257: $udom,$uname);
4258: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
4259: return %loadnames;
4260: }
4261: }
4262:
1.551 albertel 4263: sub flush_email_cache {
4264: my ($uname,$udom)=@_;
4265: if (!$udom) { $udom =$env{'user.domain'}; }
4266: if (!$uname) { $uname=$env{'user.name'}; }
4267: return if ($udom eq 'public' && $uname eq 'public');
4268: my $id=$uname.':'.$udom;
4269: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4270: }
4271:
1.728 raeburn 4272: # -------------------------------------------------------------------- getlangs
4273:
4274: =pod
4275:
4276: =item * &getlangs($uname,$udom)
4277:
4278: Gets a user's language preference and returns it as a hash with key:
4279: language.
4280:
4281: =cut
4282:
4283:
4284: sub getlangs {
4285: my ($uname,$udom) = @_;
4286: if (!$udom) { $udom =$env{'user.domain'}; }
4287: if (!$uname) { $uname=$env{'user.name'}; }
4288: my $id=$uname.':'.$udom;
4289: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4290: if ($cached) {
4291: return %{$langs};
4292: } else {
4293: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4294: $udom,$uname);
4295: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4296: return %loadlangs;
4297: }
4298: }
4299:
4300: sub flush_langs_cache {
4301: my ($uname,$udom)=@_;
4302: if (!$udom) { $udom =$env{'user.domain'}; }
4303: if (!$uname) { $uname=$env{'user.name'}; }
4304: return if ($udom eq 'public' && $uname eq 'public');
4305: my $id=$uname.':'.$udom;
4306: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4307: }
4308:
1.61 www 4309: # ------------------------------------------------------------------ Screenname
1.81 albertel 4310:
4311: =pod
4312:
1.648 raeburn 4313: =item * &screenname($uname,$udom)
1.81 albertel 4314:
4315: Gets a users screenname and returns it as a string
4316:
4317: =cut
1.61 www 4318:
4319: sub screenname {
4320: my ($uname,$udom)=@_;
1.258 albertel 4321: if ($uname eq $env{'user.name'} &&
4322: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4323: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4324: return $names{'screenname'};
1.62 www 4325: }
4326:
1.212 albertel 4327:
1.802 bisitz 4328: # ------------------------------------------------------------- Confirm Wrapper
4329: =pod
4330:
1.1142 raeburn 4331: =item * &confirmwrapper($message)
1.802 bisitz 4332:
4333: Wrap messages about completion of operation in box
4334:
4335: =cut
4336:
4337: sub confirmwrapper {
4338: my ($message)=@_;
4339: if ($message) {
4340: return "\n".'<div class="LC_confirm_box">'."\n"
4341: .$message."\n"
4342: .'</div>'."\n";
4343: } else {
4344: return $message;
4345: }
4346: }
4347:
1.62 www 4348: # ------------------------------------------------------------- Message Wrapper
4349:
4350: sub messagewrapper {
1.369 www 4351: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4352: return
1.441 albertel 4353: '<a href="/adm/email?compose=individual&'.
4354: 'recname='.$username.'&recdom='.$domain.
4355: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4356: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4357: }
1.802 bisitz 4358:
1.74 www 4359: # --------------------------------------------------------------- Notes Wrapper
4360:
4361: sub noteswrapper {
4362: my ($link,$un,$do)=@_;
4363: return
1.896 amueller 4364: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4365: }
1.802 bisitz 4366:
1.62 www 4367: # ------------------------------------------------------------- Aboutme Wrapper
4368:
4369: sub aboutmewrapper {
1.1070 raeburn 4370: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4371: if (!defined($username) && !defined($domain)) {
4372: return;
4373: }
1.1096 raeburn 4374: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4375: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4376: }
4377:
4378: # ------------------------------------------------------------ Syllabus Wrapper
4379:
4380: sub syllabuswrapper {
1.707 bisitz 4381: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4382: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4383: }
1.14 harris41 4384:
1.1397 raeburn 4385: # -----------------------------------------------------------------------------
4386:
1.1396 raeburn 4387: sub aboutme_on {
4388: my ($uname,$udom)=@_;
4389: unless ($uname) { $uname=$env{'user.name'}; }
4390: unless ($udom) { $udom=$env{'user.domain'}; }
4391: return if ($udom eq 'public' && $uname eq 'public');
4392: my $hashkey=$uname.':'.$udom;
4393: my ($aboutme,$cached)=&Apache::lonnet::is_cached_new('aboutme',$hashkey);
4394: if ($cached) {
4395: return $aboutme;
4396: }
4397: $aboutme = &Apache::lonnet::usertools_access($uname,$udom,'aboutme');
4398: &Apache::lonnet::do_cache_new('aboutme',$hashkey,$aboutme,3600);
4399: return $aboutme;
4400: }
4401:
4402: sub devalidate_aboutme_cache {
4403: my ($uname,$udom)=@_;
4404: if (!$udom) { $udom =$env{'user.domain'}; }
4405: if (!$uname) { $uname=$env{'user.name'}; }
4406: return if ($udom eq 'public' && $uname eq 'public');
4407: my $id=$uname.':'.$udom;
4408: &Apache::lonnet::devalidate_cache_new('aboutme',$id);
4409: }
4410:
1.208 matthew 4411: sub track_student_link {
1.887 raeburn 4412: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4413: my $link ="/adm/trackstudent?";
1.208 matthew 4414: my $title = 'View recent activity';
4415: if (defined($sname) && $sname !~ /^\s*$/ &&
4416: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4417: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4418: $title .= ' of this student';
1.268 albertel 4419: }
1.208 matthew 4420: if (defined($target) && $target !~ /^\s*$/) {
4421: $target = qq{target="$target"};
4422: } else {
4423: $target = '';
4424: }
1.268 albertel 4425: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4426: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4427: $title = &mt($title);
4428: $linktext = &mt($linktext);
1.448 albertel 4429: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4430: &help_open_topic('View_recent_activity');
1.208 matthew 4431: }
4432:
1.781 raeburn 4433: sub slot_reservations_link {
4434: my ($linktext,$sname,$sdom,$target) = @_;
4435: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4436: my $title = 'View slot reservation history';
4437: if (defined($sname) && $sname !~ /^\s*$/ &&
4438: defined($sdom) && $sdom !~ /^\s*$/) {
4439: $link .= "&uname=$sname&udom=$sdom";
4440: $title .= ' of this student';
4441: }
4442: if (defined($target) && $target !~ /^\s*$/) {
4443: $target = qq{target="$target"};
4444: } else {
4445: $target = '';
4446: }
4447: $title = &mt($title);
4448: $linktext = &mt($linktext);
4449: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4450: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4451:
4452: }
4453:
1.508 www 4454: # ===================================================== Display a student photo
4455:
4456:
1.509 albertel 4457: sub student_image_tag {
1.508 www 4458: my ($domain,$user)=@_;
4459: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4460: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4461: return '<img src="'.$imgsrc.'" align="right" />';
4462: } else {
4463: return '';
4464: }
4465: }
4466:
1.112 bowersj2 4467: =pod
4468:
4469: =back
4470:
4471: =head1 Access .tab File Data
4472:
4473: =over 4
4474:
1.648 raeburn 4475: =item * &languageids()
1.112 bowersj2 4476:
4477: returns list of all language ids
4478:
4479: =cut
4480:
1.14 harris41 4481: sub languageids {
1.16 harris41 4482: return sort(keys(%language));
1.14 harris41 4483: }
4484:
1.112 bowersj2 4485: =pod
4486:
1.648 raeburn 4487: =item * &languagedescription()
1.112 bowersj2 4488:
4489: returns description of a specified language id
4490:
4491: =cut
4492:
1.14 harris41 4493: sub languagedescription {
1.125 www 4494: my $code=shift;
4495: return ($supported_language{$code}?'* ':'').
4496: $language{$code}.
1.126 www 4497: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4498: }
4499:
1.1048 foxr 4500: =pod
4501:
4502: =item * &plainlanguagedescription
4503:
4504: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4505: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4506:
4507: =cut
4508:
1.145 www 4509: sub plainlanguagedescription {
4510: my $code=shift;
4511: return $language{$code};
4512: }
4513:
1.1048 foxr 4514: =pod
4515:
4516: =item * &supportedlanguagecode
4517:
4518: Returns the supported language code (e.g. sptutf maps to pt) given a language
4519: code.
4520:
4521: =cut
4522:
1.145 www 4523: sub supportedlanguagecode {
4524: my $code=shift;
4525: return $supported_language{$code};
1.97 www 4526: }
4527:
1.112 bowersj2 4528: =pod
4529:
1.1048 foxr 4530: =item * &latexlanguage()
4531:
4532: Given a language key code returns the correspondnig language to use
4533: to select the correct hyphenation on LaTeX printouts. This is undef if there
4534: is no supported hyphenation for the language code.
4535:
4536: =cut
4537:
4538: sub latexlanguage {
4539: my $code = shift;
4540: return $latex_language{$code};
4541: }
4542:
4543: =pod
4544:
4545: =item * &latexhyphenation()
4546:
4547: Same as above but what's supplied is the language as it might be stored
4548: in the metadata.
4549:
4550: =cut
4551:
4552: sub latexhyphenation {
4553: my $key = shift;
4554: return $latex_language_bykey{$key};
4555: }
4556:
4557: =pod
4558:
1.648 raeburn 4559: =item * ©rightids()
1.112 bowersj2 4560:
4561: returns list of all copyrights
4562:
4563: =cut
4564:
4565: sub copyrightids {
4566: return sort(keys(%cprtag));
4567: }
4568:
4569: =pod
4570:
1.648 raeburn 4571: =item * ©rightdescription()
1.112 bowersj2 4572:
4573: returns description of a specified copyright id
4574:
4575: =cut
4576:
4577: sub copyrightdescription {
1.166 www 4578: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4579: }
1.197 matthew 4580:
4581: =pod
4582:
1.648 raeburn 4583: =item * &source_copyrightids()
1.192 taceyjo1 4584:
4585: returns list of all source copyrights
4586:
4587: =cut
4588:
4589: sub source_copyrightids {
4590: return sort(keys(%scprtag));
4591: }
4592:
4593: =pod
4594:
1.648 raeburn 4595: =item * &source_copyrightdescription()
1.192 taceyjo1 4596:
4597: returns description of a specified source copyright id
4598:
4599: =cut
4600:
4601: sub source_copyrightdescription {
4602: return &mt($scprtag{shift(@_)});
4603: }
1.112 bowersj2 4604:
4605: =pod
4606:
1.648 raeburn 4607: =item * &filecategories()
1.112 bowersj2 4608:
4609: returns list of all file categories
4610:
4611: =cut
4612:
4613: sub filecategories {
4614: return sort(keys(%category_extensions));
4615: }
4616:
4617: =pod
4618:
1.648 raeburn 4619: =item * &filecategorytypes()
1.112 bowersj2 4620:
4621: returns list of file types belonging to a given file
4622: category
4623:
4624: =cut
4625:
4626: sub filecategorytypes {
1.356 albertel 4627: my ($cat) = @_;
1.1248 raeburn 4628: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4629: return @{$category_extensions{lc($cat)}};
4630: } else {
4631: return ();
4632: }
1.112 bowersj2 4633: }
4634:
4635: =pod
4636:
1.648 raeburn 4637: =item * &fileembstyle()
1.112 bowersj2 4638:
4639: returns embedding style for a specified file type
4640:
4641: =cut
4642:
4643: sub fileembstyle {
4644: return $fe{lc(shift(@_))};
1.169 www 4645: }
4646:
1.351 www 4647: sub filemimetype {
4648: return $fm{lc(shift(@_))};
4649: }
4650:
1.169 www 4651:
4652: sub filecategoryselect {
4653: my ($name,$value)=@_;
1.189 matthew 4654: return &select_form($value,$name,
1.970 raeburn 4655: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4656: }
4657:
4658: =pod
4659:
1.648 raeburn 4660: =item * &filedescription()
1.112 bowersj2 4661:
4662: returns description for a specified file type
4663:
4664: =cut
4665:
4666: sub filedescription {
1.188 matthew 4667: my $file_description = $fd{lc(shift())};
4668: $file_description =~ s:([\[\]]):~$1:g;
4669: return &mt($file_description);
1.112 bowersj2 4670: }
4671:
4672: =pod
4673:
1.648 raeburn 4674: =item * &filedescriptionex()
1.112 bowersj2 4675:
4676: returns description for a specified file type with
4677: extra formatting
4678:
4679: =cut
4680:
4681: sub filedescriptionex {
4682: my $ex=shift;
1.188 matthew 4683: my $file_description = $fd{lc($ex)};
4684: $file_description =~ s:([\[\]]):~$1:g;
4685: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4686: }
4687:
4688: # End of .tab access
4689: =pod
4690:
4691: =back
4692:
4693: =cut
4694:
4695: # ------------------------------------------------------------------ File Types
4696: sub fileextensions {
4697: return sort(keys(%fe));
4698: }
4699:
1.97 www 4700: # ----------------------------------------------------------- Display Languages
4701: # returns a hash with all desired display languages
4702: #
4703:
4704: sub display_languages {
4705: my %languages=();
1.695 raeburn 4706: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4707: $languages{$lang}=1;
1.97 www 4708: }
4709: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4710: if ($env{'form.displaylanguage'}) {
1.356 albertel 4711: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4712: $languages{$lang}=1;
1.97 www 4713: }
4714: }
4715: return %languages;
1.14 harris41 4716: }
4717:
1.582 albertel 4718: sub languages {
4719: my ($possible_langs) = @_;
1.695 raeburn 4720: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4721: if (!ref($possible_langs)) {
4722: if( wantarray ) {
4723: return @preferred_langs;
4724: } else {
4725: return $preferred_langs[0];
4726: }
4727: }
4728: my %possibilities = map { $_ => 1 } (@$possible_langs);
4729: my @preferred_possibilities;
4730: foreach my $preferred_lang (@preferred_langs) {
4731: if (exists($possibilities{$preferred_lang})) {
4732: push(@preferred_possibilities, $preferred_lang);
4733: }
4734: }
4735: if( wantarray ) {
4736: return @preferred_possibilities;
4737: }
4738: return $preferred_possibilities[0];
4739: }
4740:
1.742 raeburn 4741: sub user_lang {
4742: my ($touname,$toudom,$fromcid) = @_;
4743: my @userlangs;
4744: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4745: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4746: $env{'course.'.$fromcid.'.languages'}));
4747: } else {
4748: my %langhash = &getlangs($touname,$toudom);
4749: if ($langhash{'languages'} ne '') {
4750: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4751: } else {
4752: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4753: if ($domdefs{'lang_def'} ne '') {
4754: @userlangs = ($domdefs{'lang_def'});
4755: }
4756: }
4757: }
4758: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4759: my $user_lh = Apache::localize->get_handle(@languages);
4760: return $user_lh;
4761: }
4762:
4763:
1.112 bowersj2 4764: ###############################################################
4765: ## Student Answer Attempts ##
4766: ###############################################################
4767:
4768: =pod
4769:
4770: =head1 Alternate Problem Views
4771:
4772: =over 4
4773:
1.648 raeburn 4774: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4775: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4776:
4777: Return string with previous attempt on problem. Arguments:
4778:
4779: =over 4
4780:
4781: =item * $symb: Problem, including path
4782:
4783: =item * $username: username of the desired student
4784:
4785: =item * $domain: domain of the desired student
1.14 harris41 4786:
1.112 bowersj2 4787: =item * $course: Course ID
1.14 harris41 4788:
1.112 bowersj2 4789: =item * $getattempt: Leave blank for all attempts, otherwise put
4790: something
1.14 harris41 4791:
1.112 bowersj2 4792: =item * $regexp: if string matches this regexp, the string will be
4793: sent to $gradesub
1.14 harris41 4794:
1.112 bowersj2 4795: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4796:
1.1199 raeburn 4797: =item * $usec: section of the desired student
4798:
4799: =item * $identifier: counter for student (multiple students one problem) or
4800: problem (one student; whole sequence).
4801:
1.112 bowersj2 4802: =back
1.14 harris41 4803:
1.112 bowersj2 4804: The output string is a table containing all desired attempts, if any.
1.16 harris41 4805:
1.112 bowersj2 4806: =cut
1.1 albertel 4807:
4808: sub get_previous_attempt {
1.1199 raeburn 4809: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4810: my $prevattempts='';
1.43 ng 4811: no strict 'refs';
1.1 albertel 4812: if ($symb) {
1.3 albertel 4813: my (%returnhash)=
4814: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4815: if ($returnhash{'version'}) {
4816: my %lasthash=();
4817: my $version;
4818: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4819: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4820: if ($key =~ /\.rawrndseed$/) {
4821: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4822: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4823: } else {
4824: $lasthash{$key}=$returnhash{$version.':'.$key};
4825: }
1.19 harris41 4826: }
1.1 albertel 4827: }
1.596 albertel 4828: $prevattempts=&start_data_table().&start_data_table_header_row();
4829: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4830: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4831: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4832: foreach my $key (sort(keys(%lasthash))) {
4833: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4834: if ($#parts > 0) {
1.31 albertel 4835: my $data=$parts[-1];
1.989 raeburn 4836: next if ($data eq 'foilorder');
1.31 albertel 4837: pop(@parts);
1.1010 www 4838: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4839: if ($data eq 'type') {
4840: unless ($showsurv) {
4841: my $id = join(',',@parts);
4842: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4843: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4844: $lasthidden{$ign.'.'.$id} = 1;
4845: }
1.945 raeburn 4846: }
1.1199 raeburn 4847: if ($identifier ne '') {
4848: my $id = join(',',@parts);
4849: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4850: $domain,$username,$usec,undef,$course) =~ /^no/) {
4851: $hidestatus{$ign.'.'.$id} = 1;
4852: }
4853: }
4854: } elsif ($data eq 'regrader') {
4855: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4856: my $id = join(',',@parts);
4857: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4858: }
1.1010 www 4859: }
1.31 albertel 4860: } else {
1.41 ng 4861: if ($#parts == 0) {
4862: $prevattempts.='<th>'.$parts[0].'</th>';
4863: } else {
4864: $prevattempts.='<th>'.$ign.'</th>';
4865: }
1.31 albertel 4866: }
1.16 harris41 4867: }
1.596 albertel 4868: $prevattempts.=&end_data_table_header_row();
1.40 ng 4869: if ($getattempt eq '') {
1.1199 raeburn 4870: my (%solved,%resets,%probstatus);
1.1200 raeburn 4871: if (($identifier ne '') && (keys(%regraded) > 0)) {
4872: for ($version=1;$version<=$returnhash{'version'};$version++) {
4873: foreach my $id (keys(%regraded)) {
4874: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4875: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4876: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4877: push(@{$resets{$id}},$version);
1.1199 raeburn 4878: }
4879: }
4880: }
1.1200 raeburn 4881: }
4882: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4883: my (@hidden,@unsolved);
1.945 raeburn 4884: if (%typeparts) {
4885: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4886: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4887: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4888: push(@hidden,$id);
1.1199 raeburn 4889: } elsif ($identifier ne '') {
4890: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4891: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4892: ($hidestatus{$id})) {
1.1200 raeburn 4893: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4894: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4895: push(@{$solved{$id}},$version);
4896: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4897: (ref($solved{$id}) eq 'ARRAY')) {
4898: my $skip;
4899: if (ref($resets{$id}) eq 'ARRAY') {
4900: foreach my $reset (@{$resets{$id}}) {
4901: if ($reset > $solved{$id}[-1]) {
4902: $skip=1;
4903: last;
4904: }
4905: }
4906: }
4907: unless ($skip) {
4908: my ($ign,$partslist) = split(/\./,$id,2);
4909: push(@unsolved,$partslist);
4910: }
4911: }
4912: }
1.945 raeburn 4913: }
4914: }
4915: }
4916: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4917: '<td>'.&mt('Transaction [_1]',$version);
4918: if (@unsolved) {
4919: $prevattempts .= '<span class="LC_nobreak"><label>'.
4920: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4921: &mt('Hide').'</label></span>';
4922: }
4923: $prevattempts .= '</td>';
1.945 raeburn 4924: if (@hidden) {
4925: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4926: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4927: my $hide;
4928: foreach my $id (@hidden) {
4929: if ($key =~ /^\Q$id\E/) {
4930: $hide = 1;
4931: last;
4932: }
4933: }
4934: if ($hide) {
4935: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4936: if (($data eq 'award') || ($data eq 'awarddetail')) {
4937: my $value = &format_previous_attempt_value($key,
4938: $returnhash{$version.':'.$key});
1.1173 kruse 4939: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4940: } else {
4941: $prevattempts.='<td> </td>';
4942: }
4943: } else {
4944: if ($key =~ /\./) {
1.1212 raeburn 4945: my $value = $returnhash{$version.':'.$key};
4946: if ($key =~ /\.rndseed$/) {
4947: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4948: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4949: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4950: }
4951: }
4952: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4953: ' </td>';
1.945 raeburn 4954: } else {
4955: $prevattempts.='<td> </td>';
4956: }
4957: }
4958: }
4959: } else {
4960: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4961: next if ($key =~ /\.foilorder$/);
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: }
4972: }
4973: $prevattempts.=&end_data_table_row();
1.40 ng 4974: }
1.1 albertel 4975: }
1.945 raeburn 4976: my @currhidden = keys(%lasthidden);
1.596 albertel 4977: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4978: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4979: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4980: if (%typeparts) {
4981: my $hidden;
4982: foreach my $id (@currhidden) {
4983: if ($key =~ /^\Q$id\E/) {
4984: $hidden = 1;
4985: last;
4986: }
4987: }
4988: if ($hidden) {
4989: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4990: if (($data eq 'award') || ($data eq 'awarddetail')) {
4991: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4992: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4993: $value = &$gradesub($value);
4994: }
1.1173 kruse 4995: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4996: } else {
4997: $prevattempts.='<td> </td>';
4998: }
4999: } else {
5000: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5001: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5002: $value = &$gradesub($value);
5003: }
1.1173 kruse 5004: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5005: }
5006: } else {
5007: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5008: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5009: $value = &$gradesub($value);
5010: }
1.1173 kruse 5011: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5012: }
1.16 harris41 5013: }
1.596 albertel 5014: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 5015: } else {
1.1305 raeburn 5016: my $msg;
5017: if ($symb =~ /ext\.tool$/) {
5018: $msg = &mt('No grade passed back.');
5019: } else {
5020: $msg = &mt('Nothing submitted - no attempts.');
5021: }
1.596 albertel 5022: $prevattempts=
5023: &start_data_table().&start_data_table_row().
1.1305 raeburn 5024: '<td>'.$msg.'</td>'.
1.596 albertel 5025: &end_data_table_row().&end_data_table();
1.1 albertel 5026: }
5027: } else {
1.596 albertel 5028: $prevattempts=
5029: &start_data_table().&start_data_table_row().
5030: '<td>'.&mt('No data.').'</td>'.
5031: &end_data_table_row().&end_data_table();
1.1 albertel 5032: }
1.10 albertel 5033: }
5034:
1.581 albertel 5035: sub format_previous_attempt_value {
5036: my ($key,$value) = @_;
1.1011 www 5037: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 5038: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 5039: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 5040: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 5041: } elsif ($key =~ /answerstring$/) {
5042: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 5043: my @answer = %answers;
5044: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 5045: my @anskeys = sort(keys(%answers));
5046: if (@anskeys == 1) {
5047: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 5048: if ($answer =~ m{\0}) {
5049: $answer =~ s{\0}{,}g;
1.988 raeburn 5050: }
5051: my $tag_internal_answer_name = 'INTERNAL';
5052: if ($anskeys[0] eq $tag_internal_answer_name) {
5053: $value = $answer;
5054: } else {
5055: $value = $anskeys[0].'='.$answer;
5056: }
5057: } else {
5058: foreach my $ans (@anskeys) {
5059: my $answer = $answers{$ans};
1.1001 raeburn 5060: if ($answer =~ m{\0}) {
5061: $answer =~ s{\0}{,}g;
1.988 raeburn 5062: }
5063: $value .= $ans.'='.$answer.'<br />';;
5064: }
5065: }
1.581 albertel 5066: } else {
1.1173 kruse 5067: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 5068: }
5069: return $value;
5070: }
5071:
5072:
1.107 albertel 5073: sub relative_to_absolute {
5074: my ($url,$output)=@_;
5075: my $parser=HTML::TokeParser->new(\$output);
5076: my $token;
5077: my $thisdir=$url;
5078: my @rlinks=();
5079: while ($token=$parser->get_token) {
5080: if ($token->[0] eq 'S') {
5081: if ($token->[1] eq 'a') {
5082: if ($token->[2]->{'href'}) {
5083: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
5084: }
5085: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
5086: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
5087: } elsif ($token->[1] eq 'base') {
5088: $thisdir=$token->[2]->{'href'};
5089: }
5090: }
5091: }
5092: $thisdir=~s-/[^/]*$--;
1.356 albertel 5093: foreach my $link (@rlinks) {
1.726 raeburn 5094: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 5095: ($link=~/^\//) ||
5096: ($link=~/^javascript:/i) ||
5097: ($link=~/^mailto:/i) ||
5098: ($link=~/^\#/)) {
5099: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
5100: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 5101: }
5102: }
5103: # -------------------------------------------------- Deal with Applet codebases
5104: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
5105: return $output;
5106: }
5107:
1.112 bowersj2 5108: =pod
5109:
1.648 raeburn 5110: =item * &get_student_view()
1.112 bowersj2 5111:
5112: show a snapshot of what student was looking at
5113:
5114: =cut
5115:
1.10 albertel 5116: sub get_student_view {
1.186 albertel 5117: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 5118: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5119: my (%form);
1.10 albertel 5120: my @elements=('symb','courseid','domain','username');
5121: foreach my $element (@elements) {
1.186 albertel 5122: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5123: }
1.186 albertel 5124: if (defined($moreenv)) {
5125: %form=(%form,%{$moreenv});
5126: }
1.236 albertel 5127: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 5128: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 5129: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
5130: $feedurl =~ s{^/adm/wrapper}{};
5131: }
1.650 www 5132: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 5133: $userview=~s/\<body[^\>]*\>//gi;
5134: $userview=~s/\<\/body\>//gi;
5135: $userview=~s/\<html\>//gi;
5136: $userview=~s/\<\/html\>//gi;
5137: $userview=~s/\<head\>//gi;
5138: $userview=~s/\<\/head\>//gi;
5139: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 5140: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 5141: if (wantarray) {
5142: return ($userview,$response);
5143: } else {
5144: return $userview;
5145: }
5146: }
5147:
5148: sub get_student_view_with_retries {
5149: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
5150:
5151: my $ok = 0; # True if we got a good response.
5152: my $content;
5153: my $response;
5154:
5155: # Try to get the student_view done. within the retries count:
5156:
5157: do {
5158: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
5159: $ok = $response->is_success;
5160: if (!$ok) {
5161: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
5162: }
5163: $retries--;
5164: } while (!$ok && ($retries > 0));
5165:
5166: if (!$ok) {
5167: $content = ''; # On error return an empty content.
5168: }
1.651 www 5169: if (wantarray) {
5170: return ($content, $response);
5171: } else {
5172: return $content;
5173: }
1.11 albertel 5174: }
5175:
1.1349 raeburn 5176: sub css_links {
5177: my ($currsymb,$level) = @_;
5178: my ($links,@symbs,%cssrefs,%httpref);
5179: if ($level eq 'map') {
5180: my $navmap = Apache::lonnavmaps::navmap->new();
5181: if (ref($navmap)) {
5182: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
5183: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
5184: foreach my $res (@resources) {
5185: if (ref($res) && $res->symb()) {
5186: push(@symbs,$res->symb());
5187: }
5188: }
5189: }
5190: } else {
5191: @symbs = ($currsymb);
5192: }
5193: foreach my $symb (@symbs) {
5194: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
5195: if ($css_href =~ /\S/) {
5196: unless ($css_href =~ m{https?://}) {
5197: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
5198: my $proburl = &Apache::lonnet::clutter($url);
5199: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
5200: unless ($css_href =~ m{^/}) {
5201: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
5202: }
5203: if ($css_href =~ m{^/(res|uploaded)/}) {
5204: unless (($httpref{'httpref.'.$css_href}) ||
5205: (&Apache::lonnet::is_on_map($css_href))) {
5206: my $thisurl = $proburl;
5207: if ($env{'httpref.'.$proburl}) {
5208: $thisurl = $env{'httpref.'.$proburl};
5209: }
5210: $httpref{'httpref.'.$css_href} = $thisurl;
5211: }
5212: }
5213: }
5214: $cssrefs{$css_href} = 1;
5215: }
5216: }
5217: if (keys(%httpref)) {
5218: &Apache::lonnet::appenv(\%httpref);
5219: }
5220: if (keys(%cssrefs)) {
5221: foreach my $css_href (keys(%cssrefs)) {
5222: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
5223: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
5224: }
5225: }
5226: return $links;
5227: }
5228:
1.112 bowersj2 5229: =pod
5230:
1.648 raeburn 5231: =item * &get_student_answers()
1.112 bowersj2 5232:
5233: show a snapshot of how student was answering problem
5234:
5235: =cut
5236:
1.11 albertel 5237: sub get_student_answers {
1.100 sakharuk 5238: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 5239: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5240: my (%moreenv);
1.11 albertel 5241: my @elements=('symb','courseid','domain','username');
5242: foreach my $element (@elements) {
1.186 albertel 5243: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5244: }
1.186 albertel 5245: $moreenv{'grade_target'}='answer';
5246: %moreenv=(%form,%moreenv);
1.497 raeburn 5247: $feedurl = &Apache::lonnet::clutter($feedurl);
5248: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 5249: return $userview;
1.1 albertel 5250: }
1.116 albertel 5251:
5252: =pod
5253:
5254: =item * &submlink()
5255:
1.242 albertel 5256: Inputs: $text $uname $udom $symb $target
1.116 albertel 5257:
5258: Returns: A link to grades.pm such as to see the SUBM view of a student
5259:
5260: =cut
5261:
5262: ###############################################
5263: sub submlink {
1.242 albertel 5264: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 5265: if (!($uname && $udom)) {
5266: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5267: &Apache::lonnet::whichuser($symb);
1.116 albertel 5268: if (!$symb) { $symb=$cursymb; }
5269: }
1.254 matthew 5270: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5271: $symb=&escape($symb);
1.960 bisitz 5272: if ($target) { $target=" target=\"$target\""; }
5273: return
5274: '<a href="/adm/grades?command=submission'.
5275: '&symb='.$symb.
5276: '&student='.$uname.
5277: '&userdom='.$udom.'"'.
5278: $target.'>'.$text.'</a>';
1.242 albertel 5279: }
5280: ##############################################
5281:
5282: =pod
5283:
5284: =item * &pgrdlink()
5285:
5286: Inputs: $text $uname $udom $symb $target
5287:
5288: Returns: A link to grades.pm such as to see the PGRD view of a student
5289:
5290: =cut
5291:
5292: ###############################################
5293: sub pgrdlink {
5294: my $link=&submlink(@_);
5295: $link=~s/(&command=submission)/$1&showgrading=yes/;
5296: return $link;
5297: }
5298: ##############################################
5299:
5300: =pod
5301:
5302: =item * &pprmlink()
5303:
5304: Inputs: $text $uname $udom $symb $target
5305:
5306: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 5307: student and a specific resource
1.242 albertel 5308:
5309: =cut
5310:
5311: ###############################################
5312: sub pprmlink {
5313: my ($text,$uname,$udom,$symb,$target)=@_;
5314: if (!($uname && $udom)) {
5315: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5316: &Apache::lonnet::whichuser($symb);
1.242 albertel 5317: if (!$symb) { $symb=$cursymb; }
5318: }
1.254 matthew 5319: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5320: $symb=&escape($symb);
1.242 albertel 5321: if ($target) { $target="target=\"$target\""; }
1.595 albertel 5322: return '<a href="/adm/parmset?command=set&'.
5323: 'symb='.$symb.'&uname='.$uname.
5324: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 5325: }
5326: ##############################################
1.37 matthew 5327:
1.112 bowersj2 5328: =pod
5329:
5330: =back
5331:
5332: =cut
5333:
1.37 matthew 5334: ###############################################
1.51 www 5335:
5336:
5337: sub timehash {
1.687 raeburn 5338: my ($thistime) = @_;
5339: my $timezone = &Apache::lonlocal::gettimezone();
5340: my $dt = DateTime->from_epoch(epoch => $thistime)
5341: ->set_time_zone($timezone);
5342: my $wday = $dt->day_of_week();
5343: if ($wday == 7) { $wday = 0; }
5344: return ( 'second' => $dt->second(),
5345: 'minute' => $dt->minute(),
5346: 'hour' => $dt->hour(),
5347: 'day' => $dt->day_of_month(),
5348: 'month' => $dt->month(),
5349: 'year' => $dt->year(),
5350: 'weekday' => $wday,
5351: 'dayyear' => $dt->day_of_year(),
5352: 'dlsav' => $dt->is_dst() );
1.51 www 5353: }
5354:
1.370 www 5355: sub utc_string {
5356: my ($date)=@_;
1.371 www 5357: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5358: }
5359:
1.51 www 5360: sub maketime {
5361: my %th=@_;
1.687 raeburn 5362: my ($epoch_time,$timezone,$dt);
5363: $timezone = &Apache::lonlocal::gettimezone();
5364: eval {
5365: $dt = DateTime->new( year => $th{'year'},
5366: month => $th{'month'},
5367: day => $th{'day'},
5368: hour => $th{'hour'},
5369: minute => $th{'minute'},
5370: second => $th{'second'},
5371: time_zone => $timezone,
5372: );
5373: };
5374: if (!$@) {
5375: $epoch_time = $dt->epoch;
5376: if ($epoch_time) {
5377: return $epoch_time;
5378: }
5379: }
1.51 www 5380: return POSIX::mktime(
5381: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5382: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5383: }
5384:
5385: #########################################
1.51 www 5386:
5387: sub findallcourses {
1.482 raeburn 5388: my ($roles,$uname,$udom) = @_;
1.355 albertel 5389: my %roles;
5390: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5391: my %courses;
1.51 www 5392: my $now=time;
1.482 raeburn 5393: if (!defined($uname)) {
5394: $uname = $env{'user.name'};
5395: }
5396: if (!defined($udom)) {
5397: $udom = $env{'user.domain'};
5398: }
5399: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5400: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5401: if (!%roles) {
5402: %roles = (
5403: cc => 1,
1.907 raeburn 5404: co => 1,
1.482 raeburn 5405: in => 1,
5406: ep => 1,
5407: ta => 1,
5408: cr => 1,
5409: st => 1,
5410: );
5411: }
5412: foreach my $entry (keys(%roleshash)) {
5413: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5414: if ($trole =~ /^cr/) {
5415: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5416: } else {
5417: next if (!exists($roles{$trole}));
5418: }
5419: if ($tend) {
5420: next if ($tend < $now);
5421: }
5422: if ($tstart) {
5423: next if ($tstart > $now);
5424: }
1.1058 raeburn 5425: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5426: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5427: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5428: if ($secpart eq '') {
5429: ($cnum,$role) = split(/_/,$cnumpart);
5430: $sec = 'none';
1.1058 raeburn 5431: $value .= $cnum.'/';
1.482 raeburn 5432: } else {
5433: $cnum = $cnumpart;
5434: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5435: $value .= $cnum.'/'.$sec;
5436: }
5437: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5438: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5439: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5440: }
5441: } else {
5442: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5443: }
1.482 raeburn 5444: }
5445: } else {
5446: foreach my $key (keys(%env)) {
1.483 albertel 5447: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5448: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5449: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5450: next if ($role eq 'ca' || $role eq 'aa');
5451: next if (%roles && !exists($roles{$role}));
5452: my ($starttime,$endtime)=split(/\./,$env{$key});
5453: my $active=1;
5454: if ($starttime) {
5455: if ($now<$starttime) { $active=0; }
5456: }
5457: if ($endtime) {
5458: if ($now>$endtime) { $active=0; }
5459: }
5460: if ($active) {
1.1058 raeburn 5461: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5462: if ($sec eq '') {
5463: $sec = 'none';
1.1058 raeburn 5464: } else {
5465: $value .= $sec;
5466: }
5467: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5468: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5469: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5470: }
5471: } else {
5472: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5473: }
1.474 raeburn 5474: }
5475: }
1.51 www 5476: }
5477: }
1.474 raeburn 5478: return %courses;
1.51 www 5479: }
1.37 matthew 5480:
1.54 www 5481: ###############################################
1.474 raeburn 5482:
5483: sub blockcheck {
1.1372 raeburn 5484: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
5485: unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
5486: my ($has_evb,$check_ipaccess);
5487: my $dom = $env{'user.domain'};
5488: if ($env{'request.course.id'}) {
5489: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5490: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5491: my $checkrole = "cm./$cdom/$cnum";
5492: my $sec = $env{'request.course.sec'};
5493: if ($sec ne '') {
5494: $checkrole .= "/$sec";
5495: }
5496: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
5497: ($env{'request.role'} !~ /^st/)) {
5498: $has_evb = 1;
5499: }
5500: unless ($has_evb) {
5501: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
5502: ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
5503: if ($udom eq $cdom) {
5504: $check_ipaccess = 1;
5505: }
5506: }
5507: }
1.1375 raeburn 5508: } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
5509: ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
5510: my $checkrole;
5511: if ($env{'request.role.domain'} eq '') {
5512: $checkrole = "cm./$env{'user.domain'}/";
5513: } else {
5514: $checkrole = "cm./$env{'request.role.domain'}/";
5515: }
5516: if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
5517: $has_evb = 1;
5518: }
1.1372 raeburn 5519: }
5520: unless ($has_evb || $check_ipaccess) {
5521: my @machinedoms = &Apache::lonnet::current_machine_domains();
5522: if (($dom eq 'public') && ($activity eq 'port')) {
5523: $dom = $udom;
5524: }
5525: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5526: $check_ipaccess = 1;
5527: } else {
5528: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5529: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5530: my $prim = &Apache::lonnet::domain($dom,'primary');
5531: my $intdom = &Apache::lonnet::internet_dom($prim);
5532: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5533: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5534: $check_ipaccess = 1;
5535: }
5536: }
5537: }
5538: }
5539: if ($check_ipaccess) {
5540: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5541: unless (defined($cached)) {
5542: my %domconfig =
5543: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5544: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5545: }
5546: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5547: foreach my $id (keys(%{$ipaccessref})) {
5548: if (ref($ipaccessref->{$id}) eq 'HASH') {
5549: my $range = $ipaccessref->{$id}->{'ip'};
5550: if ($range) {
5551: if (&Apache::lonnet::ip_match($clientip,$range)) {
5552: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5553: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5554: return ('','','',$id,$dom);
5555: last;
5556: }
5557: }
5558: }
5559: }
5560: }
5561: }
5562: }
5563: }
1.1373 raeburn 5564: if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5565: return ();
5566: }
1.1372 raeburn 5567: }
1.1189 raeburn 5568: if (defined($udom) && defined($uname)) {
5569: # If uname and udom are for a course, check for blocks in the course.
5570: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5571: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5572: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 5573: return ($startblock,$endblock,$triggerblock);
5574: }
5575: } else {
1.490 raeburn 5576: $udom = $env{'user.domain'};
5577: $uname = $env{'user.name'};
5578: }
5579:
1.502 raeburn 5580: my $startblock = 0;
5581: my $endblock = 0;
1.1062 raeburn 5582: my $triggerblock = '';
1.1373 raeburn 5583: my %live_courses;
5584: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5585: %live_courses = &findallcourses(undef,$uname,$udom);
5586: }
1.474 raeburn 5587:
1.490 raeburn 5588: # If uname is for a user, and activity is course-specific, i.e.,
5589: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5590:
1.490 raeburn 5591: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5592: $activity eq 'groups' || $activity eq 'printout' ||
1.1346 raeburn 5593: $activity eq 'search' || $activity eq 'reinit' ||
5594: $activity eq 'alert') &&
1.1189 raeburn 5595: ($env{'request.course.id'})) {
1.490 raeburn 5596: foreach my $key (keys(%live_courses)) {
5597: if ($key ne $env{'request.course.id'}) {
5598: delete($live_courses{$key});
5599: }
5600: }
5601: }
5602:
5603: my $otheruser = 0;
5604: my %own_courses;
5605: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5606: # Resource belongs to user other than current user.
5607: $otheruser = 1;
5608: # Gather courses for current user
5609: %own_courses =
5610: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5611: }
5612:
5613: # Gather active course roles - course coordinator, instructor,
5614: # exam proctor, ta, student, or custom role.
1.474 raeburn 5615:
5616: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5617: my ($cdom,$cnum);
5618: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5619: $cdom = $env{'course.'.$course.'.domain'};
5620: $cnum = $env{'course.'.$course.'.num'};
5621: } else {
1.490 raeburn 5622: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5623: }
5624: my $no_ownblock = 0;
5625: my $no_userblock = 0;
1.533 raeburn 5626: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5627: # Check if current user has 'evb' priv for this
5628: if (defined($own_courses{$course})) {
5629: foreach my $sec (keys(%{$own_courses{$course}})) {
5630: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5631: if ($sec ne 'none') {
5632: $checkrole .= '/'.$sec;
5633: }
5634: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5635: $no_ownblock = 1;
5636: last;
5637: }
5638: }
5639: }
5640: # if they have 'evb' priv and are currently not playing student
5641: next if (($no_ownblock) &&
5642: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5643: }
1.474 raeburn 5644: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5645: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5646: if ($sec ne 'none') {
1.482 raeburn 5647: $checkrole .= '/'.$sec;
1.474 raeburn 5648: }
1.490 raeburn 5649: if ($otheruser) {
5650: # Resource belongs to user other than current user.
5651: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5652: my (%allroles,%userroles);
5653: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5654: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5655: my ($trole,$tdom,$tnum,$tsec);
5656: if ($entry =~ /^cr/) {
5657: ($trole,$tdom,$tnum,$tsec) =
5658: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5659: } else {
5660: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5661: }
5662: my ($spec,$area,$trest);
5663: $area = '/'.$tdom.'/'.$tnum;
5664: $trest = $tnum;
5665: if ($tsec ne '') {
5666: $area .= '/'.$tsec;
5667: $trest .= '/'.$tsec;
5668: }
5669: $spec = $trole.'.'.$area;
5670: if ($trole =~ /^cr/) {
5671: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5672: $tdom,$spec,$trest,$area);
5673: } else {
5674: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5675: $tdom,$spec,$trest,$area);
5676: }
5677: }
1.1276 raeburn 5678: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5679: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5680: if ($1) {
5681: $no_userblock = 1;
5682: last;
5683: }
1.486 raeburn 5684: }
5685: }
1.490 raeburn 5686: } else {
5687: # Resource belongs to current user
5688: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5689: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5690: $no_ownblock = 1;
5691: last;
5692: }
1.474 raeburn 5693: }
5694: }
5695: # if they have the evb priv and are currently not playing student
1.482 raeburn 5696: next if (($no_ownblock) &&
1.491 albertel 5697: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5698: next if ($no_userblock);
1.474 raeburn 5699:
1.1303 raeburn 5700: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5701: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5702:
1.1062 raeburn 5703: my ($start,$end,$trigger) =
1.1347 raeburn 5704: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5705: if (($start != 0) &&
5706: (($startblock == 0) || ($startblock > $start))) {
5707: $startblock = $start;
1.1062 raeburn 5708: if ($trigger ne '') {
5709: $triggerblock = $trigger;
5710: }
1.502 raeburn 5711: }
5712: if (($end != 0) &&
5713: (($endblock == 0) || ($endblock < $end))) {
5714: $endblock = $end;
1.1062 raeburn 5715: if ($trigger ne '') {
5716: $triggerblock = $trigger;
5717: }
1.502 raeburn 5718: }
1.490 raeburn 5719: }
1.1062 raeburn 5720: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5721: }
5722:
5723: sub get_blocks {
1.1347 raeburn 5724: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5725: my $startblock = 0;
5726: my $endblock = 0;
1.1062 raeburn 5727: my $triggerblock = '';
1.490 raeburn 5728: my $course = $cdom.'_'.$cnum;
5729: $setters->{$course} = {};
5730: $setters->{$course}{'staff'} = [];
5731: $setters->{$course}{'times'} = [];
1.1062 raeburn 5732: $setters->{$course}{'triggers'} = [];
5733: my (@blockers,%triggered);
5734: my $now = time;
5735: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5736: if ($activity eq 'docs') {
1.1348 raeburn 5737: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5738: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5739: $blocked = 1;
5740: $nosymbcache = 1;
1.1348 raeburn 5741: $noenccheck = 1;
1.1347 raeburn 5742: }
1.1348 raeburn 5743: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5744: foreach my $block (@blockers) {
5745: if ($block =~ /^firstaccess____(.+)$/) {
5746: my $item = $1;
5747: my $type = 'map';
5748: my $timersymb = $item;
5749: if ($item eq 'course') {
5750: $type = 'course';
5751: } elsif ($item =~ /___\d+___/) {
5752: $type = 'resource';
5753: } else {
5754: $timersymb = &Apache::lonnet::symbread($item);
5755: }
5756: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5757: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5758: $triggered{$block} = {
5759: start => $start,
5760: end => $end,
5761: type => $type,
5762: };
5763: }
5764: }
5765: } else {
5766: foreach my $block (keys(%commblocks)) {
5767: if ($block =~ m/^(\d+)____(\d+)$/) {
5768: my ($start,$end) = ($1,$2);
5769: if ($start <= time && $end >= time) {
5770: if (ref($commblocks{$block}) eq 'HASH') {
5771: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5772: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5773: unless(grep(/^\Q$block\E$/,@blockers)) {
5774: push(@blockers,$block);
5775: }
5776: }
5777: }
5778: }
5779: }
5780: } elsif ($block =~ /^firstaccess____(.+)$/) {
5781: my $item = $1;
5782: my $timersymb = $item;
5783: my $type = 'map';
5784: if ($item eq 'course') {
5785: $type = 'course';
5786: } elsif ($item =~ /___\d+___/) {
5787: $type = 'resource';
5788: } else {
5789: $timersymb = &Apache::lonnet::symbread($item);
5790: }
5791: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5792: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5793: if ($start && $end) {
5794: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5795: if (ref($commblocks{$block}) eq 'HASH') {
5796: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5797: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5798: unless(grep(/^\Q$block\E$/,@blockers)) {
5799: push(@blockers,$block);
5800: $triggered{$block} = {
5801: start => $start,
5802: end => $end,
5803: type => $type,
5804: };
5805: }
5806: }
5807: }
1.1062 raeburn 5808: }
5809: }
1.490 raeburn 5810: }
1.1062 raeburn 5811: }
5812: }
5813: }
5814: foreach my $blocker (@blockers) {
5815: my ($staff_name,$staff_dom,$title,$blocks) =
5816: &parse_block_record($commblocks{$blocker});
5817: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5818: my ($start,$end,$triggertype);
5819: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5820: ($start,$end) = ($1,$2);
5821: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5822: $start = $triggered{$blocker}{'start'};
5823: $end = $triggered{$blocker}{'end'};
5824: $triggertype = $triggered{$blocker}{'type'};
5825: }
5826: if ($start) {
5827: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5828: if ($triggertype) {
5829: push(@{$$setters{$course}{'triggers'}},$triggertype);
5830: } else {
5831: push(@{$$setters{$course}{'triggers'}},0);
5832: }
5833: if ( ($startblock == 0) || ($startblock > $start) ) {
5834: $startblock = $start;
5835: if ($triggertype) {
5836: $triggerblock = $blocker;
1.474 raeburn 5837: }
5838: }
1.1062 raeburn 5839: if ( ($endblock == 0) || ($endblock < $end) ) {
5840: $endblock = $end;
5841: if ($triggertype) {
5842: $triggerblock = $blocker;
5843: }
5844: }
1.474 raeburn 5845: }
5846: }
1.1062 raeburn 5847: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5848: }
5849:
5850: sub parse_block_record {
5851: my ($record) = @_;
5852: my ($setuname,$setudom,$title,$blocks);
5853: if (ref($record) eq 'HASH') {
5854: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5855: $title = &unescape($record->{'event'});
5856: $blocks = $record->{'blocks'};
5857: } else {
5858: my @data = split(/:/,$record,3);
5859: if (scalar(@data) eq 2) {
5860: $title = $data[1];
5861: ($setuname,$setudom) = split(/@/,$data[0]);
5862: } else {
5863: ($setuname,$setudom,$title) = @data;
5864: }
5865: $blocks = { 'com' => 'on' };
5866: }
5867: return ($setuname,$setudom,$title,$blocks);
5868: }
5869:
1.854 kalberla 5870: sub blocking_status {
1.1372 raeburn 5871: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5872: my %setters;
1.890 droeschl 5873:
1.1061 raeburn 5874: # check for active blocking
1.1372 raeburn 5875: if ($clientip eq '') {
5876: $clientip = &Apache::lonnet::get_requestor_ip();
5877: }
5878: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5879: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5880: my $blocked = 0;
1.1372 raeburn 5881: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5882: $blocked = 1;
5883: }
1.890 droeschl 5884:
1.1061 raeburn 5885: # caller just wants to know whether a block is active
5886: if (!wantarray) { return $blocked; }
5887:
5888: # build a link to a popup window containing the details
5889: my $querystring = "?activity=$activity";
1.1351 raeburn 5890: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5891: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1232 raeburn 5892: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5893: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5894: } elsif ($activity eq 'docs') {
1.1347 raeburn 5895: my $showurl = &Apache::lonenc::check_encrypt($url);
5896: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5897: if ($symb) {
5898: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5899: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5900: }
1.1062 raeburn 5901: }
1.1061 raeburn 5902:
5903: my $output .= <<'END_MYBLOCK';
5904: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5905: var options = "width=" + w + ",height=" + h + ",";
5906: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5907: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5908: var newWin = window.open(url, wdwName, options);
5909: newWin.focus();
5910: }
1.890 droeschl 5911: END_MYBLOCK
1.854 kalberla 5912:
1.1061 raeburn 5913: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5914:
1.1061 raeburn 5915: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5916: my $text = &mt('Communication Blocked');
1.1217 raeburn 5917: my $class = 'LC_comblock';
1.1062 raeburn 5918: if ($activity eq 'docs') {
5919: $text = &mt('Content Access Blocked');
1.1217 raeburn 5920: $class = '';
1.1063 raeburn 5921: } elsif ($activity eq 'printout') {
5922: $text = &mt('Printing Blocked');
1.1232 raeburn 5923: } elsif ($activity eq 'passwd') {
5924: $text = &mt('Password Changing Blocked');
1.1345 raeburn 5925: } elsif ($activity eq 'grades') {
5926: $text = &mt('Gradebook Blocked');
1.1346 raeburn 5927: } elsif ($activity eq 'search') {
5928: $text = &mt('Search Blocked');
1.1282 raeburn 5929: } elsif ($activity eq 'alert') {
5930: $text = &mt('Checking Critical Messages Blocked');
5931: } elsif ($activity eq 'reinit') {
5932: $text = &mt('Checking Course Update Blocked');
1.1351 raeburn 5933: } elsif ($activity eq 'about') {
5934: $text = &mt('Access to User Information Pages Blocked');
1.1373 raeburn 5935: } elsif ($activity eq 'wishlist') {
5936: $text = &mt('Access to Stored Links Blocked');
5937: } elsif ($activity eq 'annotate') {
5938: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 5939: }
1.1061 raeburn 5940: $output .= <<"END_BLOCK";
1.1217 raeburn 5941: <div class='$class'>
1.869 kalberla 5942: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5943: title='$text'>
5944: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5945: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5946: title='$text'>$text</a>
1.867 kalberla 5947: </div>
5948:
5949: END_BLOCK
1.474 raeburn 5950:
1.1061 raeburn 5951: return ($blocked, $output);
1.854 kalberla 5952: }
1.490 raeburn 5953:
1.60 matthew 5954: ###############################################
5955:
1.682 raeburn 5956: sub check_ip_acc {
1.1201 raeburn 5957: my ($acc,$clientip)=@_;
1.682 raeburn 5958: &Apache::lonxml::debug("acc is $acc");
5959: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5960: return 1;
5961: }
1.1339 raeburn 5962: my ($ip,$allowed);
5963: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5964: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5965: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5966: } else {
1.1350 raeburn 5967: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5968: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1339 raeburn 5969: }
1.682 raeburn 5970:
5971: my $name;
1.1219 raeburn 5972: my %access = (
5973: allowfrom => 1,
5974: denyfrom => 0,
5975: );
5976: my @allows;
5977: my @denies;
5978: foreach my $item (split(',',$acc)) {
5979: $item =~ s/^\s*//;
5980: $item =~ s/\s*$//;
5981: my $pattern;
5982: if ($item =~ /^\!(.+)$/) {
5983: push(@denies,$1);
5984: } else {
5985: push(@allows,$item);
5986: }
5987: }
5988: my $numdenies = scalar(@denies);
5989: my $numallows = scalar(@allows);
5990: my $count = 0;
5991: foreach my $pattern (@denies,@allows) {
5992: $count ++;
5993: my $acctype = 'allowfrom';
5994: if ($count <= $numdenies) {
5995: $acctype = 'denyfrom';
5996: }
1.682 raeburn 5997: if ($pattern =~ /\*$/) {
5998: #35.8.*
5999: $pattern=~s/\*//;
1.1219 raeburn 6000: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6001: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
6002: #35.8.3.[34-56]
6003: my $low=$2;
6004: my $high=$3;
6005: $pattern=$1;
6006: if ($ip =~ /^\Q$pattern\E/) {
6007: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 6008: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 6009: }
6010: } elsif ($pattern =~ /^\*/) {
6011: #*.msu.edu
6012: $pattern=~s/\*//;
6013: if (!defined($name)) {
6014: use Socket;
6015: my $netaddr=inet_aton($ip);
6016: ($name)=gethostbyaddr($netaddr,AF_INET);
6017: }
1.1219 raeburn 6018: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 6019: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
6020: #127.0.0.1
1.1219 raeburn 6021: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6022: } else {
6023: #some.name.com
6024: if (!defined($name)) {
6025: use Socket;
6026: my $netaddr=inet_aton($ip);
6027: ($name)=gethostbyaddr($netaddr,AF_INET);
6028: }
1.1219 raeburn 6029: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
6030: }
6031: if ($allowed =~ /^(0|1)$/) { last; }
6032: }
6033: if ($allowed eq '') {
6034: if ($numdenies && !$numallows) {
6035: $allowed = 1;
6036: } else {
6037: $allowed = 0;
1.682 raeburn 6038: }
6039: }
6040: return $allowed;
6041: }
6042:
6043: ###############################################
6044:
1.60 matthew 6045: =pod
6046:
1.112 bowersj2 6047: =head1 Domain Template Functions
6048:
6049: =over 4
6050:
6051: =item * &determinedomain()
1.60 matthew 6052:
6053: Inputs: $domain (usually will be undef)
6054:
1.63 www 6055: Returns: Determines which domain should be used for designs
1.60 matthew 6056:
6057: =cut
1.54 www 6058:
1.60 matthew 6059: ###############################################
1.63 www 6060: sub determinedomain {
6061: my $domain=shift;
1.531 albertel 6062: if (! $domain) {
1.60 matthew 6063: # Determine domain if we have not been given one
1.893 raeburn 6064: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 6065: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
6066: if ($env{'request.role.domain'}) {
6067: $domain=$env{'request.role.domain'};
1.60 matthew 6068: }
6069: }
1.63 www 6070: return $domain;
6071: }
6072: ###############################################
1.517 raeburn 6073:
1.518 albertel 6074: sub devalidate_domconfig_cache {
6075: my ($udom)=@_;
6076: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
6077: }
6078:
6079: # ---------------------- Get domain configuration for a domain
6080: sub get_domainconf {
6081: my ($udom) = @_;
6082: my $cachetime=1800;
6083: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
6084: if (defined($cached)) { return %{$result}; }
6085:
6086: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 6087: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 6088: my (%designhash,%legacy);
1.518 albertel 6089: if (keys(%domconfig) > 0) {
6090: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 6091: if (keys(%{$domconfig{'login'}})) {
6092: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 6093: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 6094: if (($key eq 'loginvia') || ($key eq 'headtag')) {
6095: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6096: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
6097: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
6098: if ($key eq 'loginvia') {
6099: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
6100: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
6101: $designhash{$udom.'.login.loginvia'} = $server;
6102: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
6103:
6104: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
6105: } else {
6106: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
6107: }
1.948 raeburn 6108: }
1.1208 raeburn 6109: } elsif ($key eq 'headtag') {
6110: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
6111: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 6112: }
1.946 raeburn 6113: }
1.1208 raeburn 6114: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
6115: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
6116: }
1.946 raeburn 6117: }
6118: }
6119: }
1.1366 raeburn 6120: } elsif ($key eq 'saml') {
6121: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6122: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
6123: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
6124: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
1.1386 raeburn 6125: foreach my $item ('text','img','alt','url','title','window','notsso') {
1.1366 raeburn 6126: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
6127: }
6128: }
6129: }
6130: }
1.946 raeburn 6131: } else {
6132: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
6133: $designhash{$udom.'.login.'.$key.'_'.$img} =
6134: $domconfig{'login'}{$key}{$img};
6135: }
1.699 raeburn 6136: }
6137: } else {
6138: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
6139: }
1.632 raeburn 6140: }
6141: } else {
6142: $legacy{'login'} = 1;
1.518 albertel 6143: }
1.632 raeburn 6144: } else {
6145: $legacy{'login'} = 1;
1.518 albertel 6146: }
6147: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 6148: if (keys(%{$domconfig{'rolecolors'}})) {
6149: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
6150: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
6151: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
6152: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
6153: }
1.518 albertel 6154: }
6155: }
1.632 raeburn 6156: } else {
6157: $legacy{'rolecolors'} = 1;
1.518 albertel 6158: }
1.632 raeburn 6159: } else {
6160: $legacy{'rolecolors'} = 1;
1.518 albertel 6161: }
1.948 raeburn 6162: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6163: if ($domconfig{'autoenroll'}{'co-owners'}) {
6164: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
6165: }
6166: }
1.632 raeburn 6167: if (keys(%legacy) > 0) {
6168: my %legacyhash = &get_legacy_domconf($udom);
6169: foreach my $item (keys(%legacyhash)) {
6170: if ($item =~ /^\Q$udom\E\.login/) {
6171: if ($legacy{'login'}) {
6172: $designhash{$item} = $legacyhash{$item};
6173: }
6174: } else {
6175: if ($legacy{'rolecolors'}) {
6176: $designhash{$item} = $legacyhash{$item};
6177: }
1.518 albertel 6178: }
6179: }
6180: }
1.632 raeburn 6181: } else {
6182: %designhash = &get_legacy_domconf($udom);
1.518 albertel 6183: }
6184: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
6185: $cachetime);
6186: return %designhash;
6187: }
6188:
1.632 raeburn 6189: sub get_legacy_domconf {
6190: my ($udom) = @_;
6191: my %legacyhash;
6192: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
6193: my $designfile = $designdir.'/'.$udom.'.tab';
6194: if (-e $designfile) {
1.1317 raeburn 6195: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 6196: while (my $line = <$fh>) {
6197: next if ($line =~ /^\#/);
6198: chomp($line);
6199: my ($key,$val)=(split(/\=/,$line));
6200: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
6201: }
6202: close($fh);
6203: }
6204: }
1.1026 raeburn 6205: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 6206: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
6207: }
6208: return %legacyhash;
6209: }
6210:
1.63 www 6211: =pod
6212:
1.112 bowersj2 6213: =item * &domainlogo()
1.63 www 6214:
6215: Inputs: $domain (usually will be undef)
6216:
6217: Returns: A link to a domain logo, if the domain logo exists.
6218: If the domain logo does not exist, a description of the domain.
6219:
6220: =cut
1.112 bowersj2 6221:
1.63 www 6222: ###############################################
6223: sub domainlogo {
1.517 raeburn 6224: my $domain = &determinedomain(shift);
1.518 albertel 6225: my %designhash = &get_domainconf($domain);
1.517 raeburn 6226: # See if there is a logo
6227: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 6228: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 6229: if ($imgsrc =~ m{^/(adm|res)/}) {
6230: if ($imgsrc =~ m{^/res/}) {
6231: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
6232: &Apache::lonnet::repcopy($local_name);
6233: }
6234: $imgsrc = &lonhttpdurl($imgsrc);
1.1374 raeburn 6235: }
6236: my $alttext = $domain;
6237: if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
6238: $alttext = $designhash{$domain.'.login.alttext_domlogo'};
6239: }
6240: return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 6241: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
6242: return &Apache::lonnet::domain($domain,'description');
1.59 www 6243: } else {
1.60 matthew 6244: return '';
1.59 www 6245: }
6246: }
1.63 www 6247: ##############################################
6248:
6249: =pod
6250:
1.112 bowersj2 6251: =item * &designparm()
1.63 www 6252:
6253: Inputs: $which parameter; $domain (usually will be undef)
6254:
6255: Returns: value of designparamter $which
6256:
6257: =cut
1.112 bowersj2 6258:
1.397 albertel 6259:
1.400 albertel 6260: ##############################################
1.397 albertel 6261: sub designparm {
6262: my ($which,$domain)=@_;
6263: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 6264: return $env{'environment.color.'.$which};
1.96 www 6265: }
1.63 www 6266: $domain=&determinedomain($domain);
1.1016 raeburn 6267: my %domdesign;
6268: unless ($domain eq 'public') {
6269: %domdesign = &get_domainconf($domain);
6270: }
1.520 raeburn 6271: my $output;
1.517 raeburn 6272: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 6273: $output = $domdesign{$domain.'.'.$which};
1.63 www 6274: } else {
1.520 raeburn 6275: $output = $defaultdesign{$which};
6276: }
6277: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 6278: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 6279: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 6280: if ($output =~ m{^/res/}) {
6281: my $local_name = &Apache::lonnet::filelocation('',$output);
6282: &Apache::lonnet::repcopy($local_name);
6283: }
1.520 raeburn 6284: $output = &lonhttpdurl($output);
6285: }
1.63 www 6286: }
1.520 raeburn 6287: return $output;
1.63 www 6288: }
1.59 www 6289:
1.822 bisitz 6290: ##############################################
6291: =pod
6292:
1.832 bisitz 6293: =item * &authorspace()
6294:
1.1028 raeburn 6295: Inputs: $url (usually will be undef).
1.832 bisitz 6296:
1.1132 raeburn 6297: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 6298: directory being viewed (or for which action is being taken).
6299: If $url is provided, and begins /priv/<domain>/<uname>
6300: the path will be that portion of the $context argument.
6301: Otherwise the path will be for the author space of the current
6302: user when the current role is author, or for that of the
6303: co-author/assistant co-author space when the current role
6304: is co-author or assistant co-author.
1.832 bisitz 6305:
6306: =cut
6307:
6308: sub authorspace {
1.1028 raeburn 6309: my ($url) = @_;
6310: if ($url ne '') {
6311: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
6312: return $1;
6313: }
6314: }
1.832 bisitz 6315: my $caname = '';
1.1024 www 6316: my $cadom = '';
1.1028 raeburn 6317: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 6318: ($cadom,$caname) =
1.832 bisitz 6319: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 6320: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 6321: $caname = $env{'user.name'};
1.1024 www 6322: $cadom = $env{'user.domain'};
1.832 bisitz 6323: }
1.1028 raeburn 6324: if (($caname ne '') && ($cadom ne '')) {
6325: return "/priv/$cadom/$caname/";
6326: }
6327: return;
1.832 bisitz 6328: }
6329:
6330: ##############################################
6331: =pod
6332:
1.822 bisitz 6333: =item * &head_subbox()
6334:
6335: Inputs: $content (contains HTML code with page functions, etc.)
6336:
6337: Returns: HTML div with $content
6338: To be included in page header
6339:
6340: =cut
6341:
6342: sub head_subbox {
6343: my ($content)=@_;
6344: my $output =
1.993 raeburn 6345: '<div class="LC_head_subbox">'
1.822 bisitz 6346: .$content
6347: .'</div>'
6348: }
6349:
6350: ##############################################
6351: =pod
6352:
6353: =item * &CSTR_pageheader()
6354:
1.1026 raeburn 6355: Input: (optional) filename from which breadcrumb trail is built.
6356: In most cases no input as needed, as $env{'request.filename'}
6357: is appropriate for use in building the breadcrumb trail.
1.1379 raeburn 6358: frameset flag
6359: If page header is being requested for use in a frameset, then
6360: the second (option) argument -- frameset will be true, and
6361: the target attribute set for links should be target="_parent".
1.822 bisitz 6362:
6363: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 6364: To be included on Authoring Space pages
1.822 bisitz 6365:
6366: =cut
6367:
6368: sub CSTR_pageheader {
1.1379 raeburn 6369: my ($trailfile,$frameset) = @_;
1.1026 raeburn 6370: if ($trailfile eq '') {
6371: $trailfile = $env{'request.filename'};
6372: }
6373:
6374: # this is for resources; directories have customtitle, and crumbs
6375: # and select recent are created in lonpubdir.pm
6376:
6377: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 6378: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 6379: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 6380: my $formaction = "/priv/$udom/$uname/$thisdisfn";
6381: $formaction =~ s{/+}{/}g;
1.822 bisitz 6382:
6383: my $parentpath = '';
6384: my $lastitem = '';
6385: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
6386: $parentpath = $1;
6387: $lastitem = $2;
6388: } else {
6389: $lastitem = $thisdisfn;
6390: }
1.921 bisitz 6391:
1.1246 raeburn 6392: my ($crsauthor,$title);
6393: if (($env{'request.course.id'}) &&
6394: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 6395: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 6396: $crsauthor = 1;
6397: $title = &mt('Course Authoring Space');
6398: } else {
6399: $title = &mt('Authoring Space');
6400: }
6401:
1.1379 raeburn 6402: my ($target,$crumbtarget) = (' target="_top"','_top');
6403: if ($frameset) {
6404: $target = ' target="_parent"';
6405: $crumbtarget = '_parent';
6406: } elsif (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 6407: $target = '';
6408: $crumbtarget = '';
1.1379 raeburn 6409: } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {
1.1378 raeburn 6410: $target = ' target="'.$env{'request.deeplink.target'}.'"';
6411: $crumbtarget = $env{'request.deeplink.target'};
6412: }
1.1313 raeburn 6413:
1.921 bisitz 6414: my $output =
1.822 bisitz 6415: '<div>'
6416: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 6417: .'<b>'.$title.'</b> '
1.1314 raeburn 6418: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6419: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6420:
6421: if ($lastitem) {
6422: $output .=
6423: '<span class="LC_filename">'
6424: .$lastitem
6425: .'</span>';
6426: }
1.1245 raeburn 6427:
1.1246 raeburn 6428: if ($crsauthor) {
1.1379 raeburn 6429: $output .= '</form>'.&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6430: } else {
6431: $output .=
6432: '<br />'
1.1314 raeburn 6433: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 6434: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6435: .'</form>'
1.1379 raeburn 6436: .&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6437: }
6438: $output .= '</div>';
1.921 bisitz 6439:
6440: return $output;
1.822 bisitz 6441: }
6442:
1.60 matthew 6443: ###############################################
6444: ###############################################
6445:
6446: =pod
6447:
1.112 bowersj2 6448: =back
6449:
1.549 albertel 6450: =head1 HTML Helpers
1.112 bowersj2 6451:
6452: =over 4
6453:
6454: =item * &bodytag()
1.60 matthew 6455:
6456: Returns a uniform header for LON-CAPA web pages.
6457:
6458: Inputs:
6459:
1.112 bowersj2 6460: =over 4
6461:
6462: =item * $title, A title to be displayed on the page.
6463:
6464: =item * $function, the current role (can be undef).
6465:
6466: =item * $addentries, extra parameters for the <body> tag.
6467:
6468: =item * $bodyonly, if defined, only return the <body> tag.
6469:
6470: =item * $domain, if defined, force a given domain.
6471:
6472: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6473: text interface only)
1.60 matthew 6474:
1.814 bisitz 6475: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6476: navigational links
1.317 albertel 6477:
1.338 albertel 6478: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6479:
1.460 albertel 6480: =item * $args, optional argument valid values are
6481: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6482: use_absolute -> for external resource or syllabus, this will
6483: contain https://<hostname> if server uses
6484: https (as per hosts.tab), but request is for http
6485: hostname -> hostname, from $r->hostname().
1.460 albertel 6486:
1.1096 raeburn 6487: =item * $advtoolsref, optional argument, ref to an array containing
6488: inlineremote items to be added in "Functions" menu below
6489: breadcrumbs.
6490:
1.1316 raeburn 6491: =item * $ltiscope, optional argument, will be one of: resource, map or
6492: course, if LON-CAPA is in LTI Provider context. Value is
6493: the scope of use, i.e., launch was for access to a single, a map
6494: or the entire course.
6495:
6496: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6497: context, this will contain the URL for the landing item in
6498: the course, after launch from an LTI Consumer
6499:
1.1318 raeburn 6500: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6501: context, this will contain a reference to hash of items
6502: to be included in the page header and/or inline menu.
6503:
1.1385 raeburn 6504: =item * $menucoll, optional argument, if specific menu collection is in
6505: effect, either set as the default for the course, or set for
6506: the deeplink paramater for $env{'request.deeplink.login'}
6507: then $menucoll will be the number of that collection.
6508:
6509: =item * $menuref, optional argument, reference to a hash, containing the
6510: menu options included for the menu in effect, based on the
6511: configuration for the numbered menu collection in use.
6512:
6513: =item * $showncrumbsref, reference to a scalar. Calls to lonmenu::innerregister
6514: within &bodytag() can result in calls to lonhtmlcommon::breadcrumbs(),
6515: if so, $showncrumbsref is set there to 1, and will propagate back
6516: via &bodytag() to &start_page(), to prevent lonhtmlcommon::breadcrumbs()
6517: being called a second time.
6518:
1.112 bowersj2 6519: =back
6520:
1.60 matthew 6521: Returns: A uniform header for LON-CAPA web pages.
6522: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6523: If $bodyonly is undef or zero, an html string containing a <body> tag and
6524: other decorations will be returned.
6525:
6526: =cut
6527:
1.54 www 6528: sub bodytag {
1.831 bisitz 6529: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1359 raeburn 6530: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,
1.1385 raeburn 6531: $ltimenu,$menucoll,$menuref,$showncrumbsref)=@_;
1.339 albertel 6532:
1.954 raeburn 6533: my $public;
6534: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6535: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6536: $public = 1;
6537: }
1.460 albertel 6538: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6539: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6540: my $hostname = $args->{'hostname'};
1.339 albertel 6541:
1.183 matthew 6542: $function = &get_users_function() if (!$function);
1.339 albertel 6543: my $img = &designparm($function.'.img',$domain);
6544: my $font = &designparm($function.'.font',$domain);
6545: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6546:
1.803 bisitz 6547: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6548: 'bgcolor' => $pgbg,
1.339 albertel 6549: 'text' => $font,
6550: 'alink' => &designparm($function.'.alink',$domain),
6551: 'vlink' => &designparm($function.'.vlink',$domain),
6552: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6553: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6554:
1.63 www 6555: # role and realm
1.1178 raeburn 6556: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6557: if ($realm) {
6558: $realm = '/'.$realm;
6559: }
1.1357 raeburn 6560: if ($role eq 'ca') {
1.479 albertel 6561: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6562: $realm = &plainname($rname,$rdom);
1.378 raeburn 6563: }
1.55 www 6564: # realm
1.1357 raeburn 6565: my ($cid,$sec);
1.258 albertel 6566: if ($env{'request.course.id'}) {
1.1357 raeburn 6567: $cid = $env{'request.course.id'};
6568: if ($env{'request.course.sec'}) {
6569: $sec = $env{'request.course.sec'};
6570: }
6571: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6572: if (&Apache::lonnet::is_course($1,$2)) {
6573: $cid = $1.'_'.$2;
6574: $sec = $3;
6575: }
6576: }
6577: if ($cid) {
1.378 raeburn 6578: if ($env{'request.role'} !~ /^cr/) {
6579: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6580: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6581: if ($env{'request.role.desc'}) {
6582: $role = $env{'request.role.desc'};
6583: } else {
6584: $role = &mt('Helpdesk[_1]',' '.$2);
6585: }
1.1257 raeburn 6586: } else {
6587: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6588: }
1.1357 raeburn 6589: if ($sec) {
6590: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6591: }
1.1357 raeburn 6592: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6593: } else {
6594: $role = &Apache::lonnet::plaintext($role);
1.54 www 6595: }
1.433 albertel 6596:
1.359 albertel 6597: if (!$realm) { $realm=' '; }
1.330 albertel 6598:
1.438 albertel 6599: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6600:
1.101 www 6601: # construct main body tag
1.359 albertel 6602: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6603: &Apache::lontexconvert::init_math_support();
1.252 albertel 6604:
1.1131 raeburn 6605: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6606:
1.1130 raeburn 6607: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6608: return $bodytag;
1.1130 raeburn 6609: }
1.359 albertel 6610:
1.954 raeburn 6611: if ($public) {
1.433 albertel 6612: undef($role);
6613: }
1.1318 raeburn 6614:
1.1359 raeburn 6615: my $showcrstitle = 1;
1.1357 raeburn 6616: if (($cid) && ($env{'request.lti.login'})) {
1.1318 raeburn 6617: if (ref($ltimenu) eq 'HASH') {
6618: unless ($ltimenu->{'role'}) {
6619: undef($role);
6620: }
6621: unless ($ltimenu->{'coursetitle'}) {
6622: $realm=' ';
1.1359 raeburn 6623: $showcrstitle = 0;
6624: }
6625: }
6626: } elsif (($cid) && ($menucoll)) {
6627: if (ref($menuref) eq 'HASH') {
6628: unless ($menuref->{'role'}) {
6629: undef($role);
6630: }
6631: unless ($menuref->{'crs'}) {
6632: $realm=' ';
6633: $showcrstitle = 0;
1.1318 raeburn 6634: }
6635: }
6636: }
6637:
1.762 bisitz 6638: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6639: #
6640: # Extra info if you are the DC
6641: my $dc_info = '';
1.1359 raeburn 6642: if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1357 raeburn 6643: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6644: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6645: $dc_info =~ s/\s+$//;
1.359 albertel 6646: }
6647:
1.1237 raeburn 6648: my $crstype;
1.1357 raeburn 6649: if ($cid) {
6650: $crstype = $env{'course.'.$cid.'.type'};
1.1237 raeburn 6651: } elsif ($args->{'crstype'}) {
6652: $crstype = $args->{'crstype'};
6653: }
6654: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6655: undef($role);
6656: } else {
1.1242 raeburn 6657: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6658: }
1.853 droeschl 6659:
1.903 droeschl 6660: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6661:
6662: # if ($env{'request.state'} eq 'construct') {
6663: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6664: # }
6665:
1.1130 raeburn 6666: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6667: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6668:
1.1318 raeburn 6669: unless ($args->{'no_primary_menu'}) {
1.1369 raeburn 6670: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
1.1380 raeburn 6671: $args->{'links_disabled'},
6672: $args->{'links_target'});
1.359 albertel 6673:
1.1318 raeburn 6674: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6675: if ($dc_info) {
6676: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6677: }
6678: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6679: <em>$realm</em> $dc_info</div>|;
6680: return $bodytag;
6681: }
1.894 droeschl 6682:
1.1318 raeburn 6683: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6684: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6685: }
1.916 droeschl 6686:
1.1318 raeburn 6687: $bodytag .= $right;
1.852 droeschl 6688:
1.1318 raeburn 6689: if ($dc_info) {
6690: $dc_info = &dc_courseid_toggle($dc_info);
6691: }
6692: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6693: }
1.916 droeschl 6694:
1.1169 raeburn 6695: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6696: if ($args->{'no_secondary_menu'}) {
6697: return $bodytag;
6698: }
1.1169 raeburn 6699: #don't show menus for public users
1.954 raeburn 6700: if (!$public){
1.1318 raeburn 6701: unless ($args->{'no_inline_menu'}) {
6702: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
1.1359 raeburn 6703: $args->{'no_primary_menu'},
1.1369 raeburn 6704: $menucoll,$menuref,
1.1380 raeburn 6705: $args->{'links_disabled'},
6706: $args->{'links_target'});
1.1318 raeburn 6707: }
1.903 droeschl 6708: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6709: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6710: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6711: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1385 raeburn 6712: $args->{'bread_crumbs'},'','',$hostname,
6713: $ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 6714: } elsif ($forcereg) {
6715: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1385 raeburn 6716: $args->{'group'},$args->{'hide_buttons'},
6717: $hostname,$ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 6718: } else {
6719: $bodytag .=
6720: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6721: $forcereg,$args->{'group'},
6722: $args->{'bread_crumbs'},
1.1274 raeburn 6723: $advtoolsref,'',$hostname);
1.920 raeburn 6724: }
1.903 droeschl 6725: }else{
6726: # this is to seperate menu from content when there's no secondary
6727: # menu. Especially needed for public accessible ressources.
6728: $bodytag .= '<hr style="clear:both" />';
6729: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6730: }
1.903 droeschl 6731:
1.235 raeburn 6732: return $bodytag;
1.182 matthew 6733: }
6734:
1.917 raeburn 6735: sub dc_courseid_toggle {
6736: my ($dc_info) = @_;
1.980 raeburn 6737: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6738: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6739: &mt('(More ...)').'</a></span>'.
6740: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6741: }
6742:
1.330 albertel 6743: sub make_attr_string {
6744: my ($register,$attr_ref) = @_;
6745:
6746: if ($attr_ref && !ref($attr_ref)) {
6747: die("addentries Must be a hash ref ".
6748: join(':',caller(1))." ".
6749: join(':',caller(0))." ");
6750: }
6751:
6752: if ($register) {
1.339 albertel 6753: my ($on_load,$on_unload);
6754: foreach my $key (keys(%{$attr_ref})) {
6755: if (lc($key) eq 'onload') {
6756: $on_load.=$attr_ref->{$key}.';';
6757: delete($attr_ref->{$key});
6758:
6759: } elsif (lc($key) eq 'onunload') {
6760: $on_unload.=$attr_ref->{$key}.';';
6761: delete($attr_ref->{$key});
6762: }
6763: }
1.953 droeschl 6764: $attr_ref->{'onload'} = $on_load;
6765: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6766: }
1.339 albertel 6767:
1.330 albertel 6768: my $attr_string;
1.1159 raeburn 6769: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6770: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6771: }
6772: return $attr_string;
6773: }
6774:
6775:
1.182 matthew 6776: ###############################################
1.251 albertel 6777: ###############################################
6778:
6779: =pod
6780:
6781: =item * &endbodytag()
6782:
6783: Returns a uniform footer for LON-CAPA web pages.
6784:
1.635 raeburn 6785: Inputs: 1 - optional reference to an args hash
6786: If in the hash, key for noredirectlink has a value which evaluates to true,
6787: a 'Continue' link is not displayed if the page contains an
6788: internal redirect in the <head></head> section,
6789: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6790:
6791: =cut
6792:
6793: sub endbodytag {
1.635 raeburn 6794: my ($args) = @_;
1.1080 raeburn 6795: my $endbodytag;
6796: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6797: $endbodytag='</body>';
6798: }
1.315 albertel 6799: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6800: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
1.1386 raeburn 6801: my ($endbodyjs,$idattr);
6802: if ($env{'internal.head.to_opener'}) {
6803: my $linkid = 'LC_continue_link';
6804: $idattr = ' id="'.$linkid.'"';
6805: my $redirect_for_js = &js_escape($env{'internal.head.redirect'});
6806: $endbodyjs=<<ENDJS;
6807: <script type="text/javascript">
6808: // <![CDATA[
6809: function ebFunction(evt) {
6810: evt.preventDefault();
6811: var dest = '$redirect_for_js';
6812: if (window.opener != null && !window.opener.closed) {
6813: window.opener.location.href=dest;
6814: window.close();
6815: } else {
6816: window.location.href=dest;
6817: }
6818: return false;
6819: }
6820:
6821: \$(document).ready(function () {
6822: if (document.getElementById('$linkid')) {
6823: var clickelem = document.getElementById('$linkid');
6824: clickelem.addEventListener('click',ebFunction,false);
6825: }
6826: });
6827: // ]]>
6828: </script>
6829: ENDJS
6830: }
1.635 raeburn 6831: $endbodytag=
1.1386 raeburn 6832: "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".
1.635 raeburn 6833: &mt('Continue').'</a>'.
6834: $endbodytag;
6835: }
1.315 albertel 6836: }
1.251 albertel 6837: return $endbodytag;
6838: }
6839:
1.352 albertel 6840: =pod
6841:
6842: =item * &standard_css()
6843:
6844: Returns a style sheet
6845:
6846: Inputs: (all optional)
6847: domain -> force to color decorate a page for a specific
6848: domain
6849: function -> force usage of a specific rolish color scheme
6850: bgcolor -> override the default page bgcolor
6851:
6852: =cut
6853:
1.343 albertel 6854: sub standard_css {
1.345 albertel 6855: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6856: $function = &get_users_function() if (!$function);
6857: my $img = &designparm($function.'.img', $domain);
6858: my $tabbg = &designparm($function.'.tabbg', $domain);
6859: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6860: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6861: #second colour for later usage
1.345 albertel 6862: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6863: my $pgbg_or_bgcolor =
6864: $bgcolor ||
1.352 albertel 6865: &designparm($function.'.pgbg', $domain);
1.382 albertel 6866: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6867: my $alink = &designparm($function.'.alink', $domain);
6868: my $vlink = &designparm($function.'.vlink', $domain);
6869: my $link = &designparm($function.'.link', $domain);
6870:
1.602 albertel 6871: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6872: my $mono = 'monospace';
1.850 bisitz 6873: my $data_table_head = $sidebg;
6874: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6875: my $data_table_dark = '#E0E0E0';
1.470 banghart 6876: my $data_table_darker = '#CCCCCC';
1.349 albertel 6877: my $data_table_highlight = '#FFFF00';
1.352 albertel 6878: my $mail_new = '#FFBB77';
6879: my $mail_new_hover = '#DD9955';
6880: my $mail_read = '#BBBB77';
6881: my $mail_read_hover = '#999944';
6882: my $mail_replied = '#AAAA88';
6883: my $mail_replied_hover = '#888855';
6884: my $mail_other = '#99BBBB';
6885: my $mail_other_hover = '#669999';
1.391 albertel 6886: my $table_header = '#DDDDDD';
1.489 raeburn 6887: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6888: my $lg_border_color = '#C8C8C8';
1.952 onken 6889: my $button_hover = '#BF2317';
1.392 albertel 6890:
1.608 albertel 6891: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6892: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6893: : '0 3px 0 4px';
1.448 albertel 6894:
1.523 albertel 6895:
1.343 albertel 6896: return <<END;
1.947 droeschl 6897:
6898: /* needed for iframe to allow 100% height in FF */
6899: body, html {
6900: margin: 0;
6901: padding: 0 0.5%;
6902: height: 99%; /* to avoid scrollbars */
6903: }
6904:
1.795 www 6905: body {
1.911 bisitz 6906: font-family: $sans;
6907: line-height:130%;
6908: font-size:0.83em;
6909: color:$font;
1.795 www 6910: }
6911:
1.959 onken 6912: a:focus,
6913: a:focus img {
1.795 www 6914: color: red;
6915: }
1.698 harmsja 6916:
1.911 bisitz 6917: form, .inline {
6918: display: inline;
1.795 www 6919: }
1.721 harmsja 6920:
1.795 www 6921: .LC_right {
1.911 bisitz 6922: text-align:right;
1.795 www 6923: }
6924:
6925: .LC_middle {
1.911 bisitz 6926: vertical-align:middle;
1.795 www 6927: }
1.721 harmsja 6928:
1.1130 raeburn 6929: .LC_floatleft {
6930: float: left;
6931: }
6932:
6933: .LC_floatright {
6934: float: right;
6935: }
6936:
1.911 bisitz 6937: .LC_400Box {
6938: width:400px;
6939: }
1.721 harmsja 6940:
1.947 droeschl 6941: .LC_iframecontainer {
6942: width: 98%;
6943: margin: 0;
6944: position: fixed;
6945: top: 8.5em;
6946: bottom: 0;
6947: }
6948:
6949: .LC_iframecontainer iframe{
6950: border: none;
6951: width: 100%;
6952: height: 100%;
6953: }
6954:
1.778 bisitz 6955: .LC_filename {
6956: font-family: $mono;
6957: white-space:pre;
1.921 bisitz 6958: font-size: 120%;
1.778 bisitz 6959: }
6960:
6961: .LC_fileicon {
6962: border: none;
6963: height: 1.3em;
6964: vertical-align: text-bottom;
6965: margin-right: 0.3em;
6966: text-decoration:none;
6967: }
6968:
1.1008 www 6969: .LC_setting {
6970: text-decoration:underline;
6971: }
6972:
1.350 albertel 6973: .LC_error {
6974: color: red;
6975: }
1.795 www 6976:
1.1097 bisitz 6977: .LC_warning {
6978: color: darkorange;
6979: }
6980:
1.457 albertel 6981: .LC_diff_removed {
1.733 bisitz 6982: color: red;
1.394 albertel 6983: }
1.532 albertel 6984:
6985: .LC_info,
1.457 albertel 6986: .LC_success,
6987: .LC_diff_added {
1.350 albertel 6988: color: green;
6989: }
1.795 www 6990:
1.802 bisitz 6991: div.LC_confirm_box {
6992: background-color: #FAFAFA;
6993: border: 1px solid $lg_border_color;
6994: margin-right: 0;
6995: padding: 5px;
6996: }
6997:
6998: div.LC_confirm_box .LC_error img,
6999: div.LC_confirm_box .LC_success img {
7000: vertical-align: middle;
7001: }
7002:
1.1242 raeburn 7003: .LC_maxwidth {
7004: max-width: 100%;
7005: height: auto;
7006: }
7007:
1.1243 raeburn 7008: .LC_textsize_mobile {
7009: \@media only screen and (max-device-width: 480px) {
7010: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
7011: }
7012: }
7013:
1.440 albertel 7014: .LC_icon {
1.771 droeschl 7015: border: none;
1.790 droeschl 7016: vertical-align: middle;
1.771 droeschl 7017: }
7018:
1.543 albertel 7019: .LC_docs_spacer {
7020: width: 25px;
7021: height: 1px;
1.771 droeschl 7022: border: none;
1.543 albertel 7023: }
1.346 albertel 7024:
1.532 albertel 7025: .LC_internal_info {
1.735 bisitz 7026: color: #999999;
1.532 albertel 7027: }
7028:
1.794 www 7029: .LC_discussion {
1.1050 www 7030: background: $data_table_dark;
1.911 bisitz 7031: border: 1px solid black;
7032: margin: 2px;
1.794 www 7033: }
7034:
7035: .LC_disc_action_left {
1.1050 www 7036: background: $sidebg;
1.911 bisitz 7037: text-align: left;
1.1050 www 7038: padding: 4px;
7039: margin: 2px;
1.794 www 7040: }
7041:
7042: .LC_disc_action_right {
1.1050 www 7043: background: $sidebg;
1.911 bisitz 7044: text-align: right;
1.1050 www 7045: padding: 4px;
7046: margin: 2px;
1.794 www 7047: }
7048:
7049: .LC_disc_new_item {
1.911 bisitz 7050: background: white;
7051: border: 2px solid red;
1.1050 www 7052: margin: 4px;
7053: padding: 4px;
1.794 www 7054: }
7055:
7056: .LC_disc_old_item {
1.911 bisitz 7057: background: white;
1.1050 www 7058: margin: 4px;
7059: padding: 4px;
1.794 www 7060: }
7061:
1.458 albertel 7062: table.LC_pastsubmission {
7063: border: 1px solid black;
7064: margin: 2px;
7065: }
7066:
1.924 bisitz 7067: table#LC_menubuttons {
1.345 albertel 7068: width: 100%;
7069: background: $pgbg;
1.392 albertel 7070: border: 2px;
1.402 albertel 7071: border-collapse: separate;
1.803 bisitz 7072: padding: 0;
1.345 albertel 7073: }
1.392 albertel 7074:
1.801 tempelho 7075: table#LC_title_bar a {
7076: color: $fontmenu;
7077: }
1.836 bisitz 7078:
1.807 droeschl 7079: table#LC_title_bar {
1.819 tempelho 7080: clear: both;
1.836 bisitz 7081: display: none;
1.807 droeschl 7082: }
7083:
1.795 www 7084: table#LC_title_bar,
1.933 droeschl 7085: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 7086: table#LC_title_bar.LC_with_remote {
1.359 albertel 7087: width: 100%;
1.392 albertel 7088: border-color: $pgbg;
7089: border-style: solid;
7090: border-width: $border;
1.379 albertel 7091: background: $pgbg;
1.801 tempelho 7092: color: $fontmenu;
1.392 albertel 7093: border-collapse: collapse;
1.803 bisitz 7094: padding: 0;
1.819 tempelho 7095: margin: 0;
1.359 albertel 7096: }
1.795 www 7097:
1.933 droeschl 7098: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 7099: margin: 0;
7100: padding: 0;
1.933 droeschl 7101: position: relative;
7102: list-style: none;
1.913 droeschl 7103: }
1.933 droeschl 7104: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 7105: display: inline;
7106: }
1.933 droeschl 7107:
7108: .LC_breadcrumb_tools_navigation {
1.913 droeschl 7109: padding: 0;
1.933 droeschl 7110: margin: 0;
7111: float: left;
1.913 droeschl 7112: }
1.933 droeschl 7113: .LC_breadcrumb_tools_tools {
7114: padding: 0;
7115: margin: 0;
1.913 droeschl 7116: float: right;
7117: }
7118:
1.1240 raeburn 7119: .LC_placement_prog {
7120: padding-right: 20px;
7121: font-weight: bold;
7122: font-size: 90%;
7123: }
7124:
1.359 albertel 7125: table#LC_title_bar td {
7126: background: $tabbg;
7127: }
1.795 www 7128:
1.911 bisitz 7129: table#LC_menubuttons img {
1.803 bisitz 7130: border: none;
1.346 albertel 7131: }
1.795 www 7132:
1.842 droeschl 7133: .LC_breadcrumbs_component {
1.911 bisitz 7134: float: right;
7135: margin: 0 1em;
1.357 albertel 7136: }
1.842 droeschl 7137: .LC_breadcrumbs_component img {
1.911 bisitz 7138: vertical-align: middle;
1.777 tempelho 7139: }
1.795 www 7140:
1.1243 raeburn 7141: .LC_breadcrumbs_hoverable {
7142: background: $sidebg;
7143: }
7144:
1.383 albertel 7145: td.LC_table_cell_checkbox {
7146: text-align: center;
7147: }
1.795 www 7148:
7149: .LC_fontsize_small {
1.911 bisitz 7150: font-size: 70%;
1.705 tempelho 7151: }
7152:
1.844 bisitz 7153: #LC_breadcrumbs {
1.911 bisitz 7154: clear:both;
7155: background: $sidebg;
7156: border-bottom: 1px solid $lg_border_color;
7157: line-height: 2.5em;
1.933 droeschl 7158: overflow: hidden;
1.911 bisitz 7159: margin: 0;
7160: padding: 0;
1.995 raeburn 7161: text-align: left;
1.819 tempelho 7162: }
1.862 bisitz 7163:
1.1098 bisitz 7164: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 7165: clear:both;
7166: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 7167: border: 1px solid $sidebg;
1.1098 bisitz 7168: margin: 0 0 10px 0;
1.966 bisitz 7169: padding: 3px;
1.995 raeburn 7170: text-align: left;
1.822 bisitz 7171: }
7172:
1.795 www 7173: .LC_fontsize_medium {
1.911 bisitz 7174: font-size: 85%;
1.705 tempelho 7175: }
7176:
1.795 www 7177: .LC_fontsize_large {
1.911 bisitz 7178: font-size: 120%;
1.705 tempelho 7179: }
7180:
1.346 albertel 7181: .LC_menubuttons_inline_text {
7182: color: $font;
1.698 harmsja 7183: font-size: 90%;
1.701 harmsja 7184: padding-left:3px;
1.346 albertel 7185: }
7186:
1.934 droeschl 7187: .LC_menubuttons_inline_text img{
7188: vertical-align: middle;
7189: }
7190:
1.1051 www 7191: li.LC_menubuttons_inline_text img {
1.951 onken 7192: cursor:pointer;
1.1002 droeschl 7193: text-decoration: none;
1.951 onken 7194: }
7195:
1.526 www 7196: .LC_menubuttons_link {
7197: text-decoration: none;
7198: }
1.795 www 7199:
1.522 albertel 7200: .LC_menubuttons_category {
1.521 www 7201: color: $font;
1.526 www 7202: background: $pgbg;
1.521 www 7203: font-size: larger;
7204: font-weight: bold;
7205: }
7206:
1.346 albertel 7207: td.LC_menubuttons_text {
1.911 bisitz 7208: color: $font;
1.346 albertel 7209: }
1.706 harmsja 7210:
1.346 albertel 7211: .LC_current_location {
7212: background: $tabbg;
7213: }
1.795 www 7214:
1.1286 raeburn 7215: td.LC_zero_height {
7216: line-height: 0;
7217: cellpadding: 0;
7218: }
7219:
1.938 bisitz 7220: table.LC_data_table {
1.347 albertel 7221: border: 1px solid #000000;
1.402 albertel 7222: border-collapse: separate;
1.426 albertel 7223: border-spacing: 1px;
1.610 albertel 7224: background: $pgbg;
1.347 albertel 7225: }
1.795 www 7226:
1.422 albertel 7227: .LC_data_table_dense {
7228: font-size: small;
7229: }
1.795 www 7230:
1.507 raeburn 7231: table.LC_nested_outer {
7232: border: 1px solid #000000;
1.589 raeburn 7233: border-collapse: collapse;
1.803 bisitz 7234: border-spacing: 0;
1.507 raeburn 7235: width: 100%;
7236: }
1.795 www 7237:
1.879 raeburn 7238: table.LC_innerpickbox,
1.507 raeburn 7239: table.LC_nested {
1.803 bisitz 7240: border: none;
1.589 raeburn 7241: border-collapse: collapse;
1.803 bisitz 7242: border-spacing: 0;
1.507 raeburn 7243: width: 100%;
7244: }
1.795 www 7245:
1.911 bisitz 7246: table.LC_data_table tr th,
7247: table.LC_calendar tr th,
1.879 raeburn 7248: table.LC_prior_tries tr th,
7249: table.LC_innerpickbox tr th {
1.349 albertel 7250: font-weight: bold;
7251: background-color: $data_table_head;
1.801 tempelho 7252: color:$fontmenu;
1.701 harmsja 7253: font-size:90%;
1.347 albertel 7254: }
1.795 www 7255:
1.879 raeburn 7256: table.LC_innerpickbox tr th,
7257: table.LC_innerpickbox tr td {
7258: vertical-align: top;
7259: }
7260:
1.711 raeburn 7261: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 7262: background-color: #CCCCCC;
1.711 raeburn 7263: font-weight: bold;
7264: text-align: left;
7265: }
1.795 www 7266:
1.912 bisitz 7267: table.LC_data_table tr.LC_odd_row > td {
7268: background-color: $data_table_light;
7269: padding: 2px;
7270: vertical-align: top;
7271: }
7272:
1.809 bisitz 7273: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 7274: background-color: $data_table_light;
1.912 bisitz 7275: vertical-align: top;
7276: }
7277:
7278: table.LC_data_table tr.LC_even_row > td {
7279: background-color: $data_table_dark;
1.425 albertel 7280: padding: 2px;
1.900 bisitz 7281: vertical-align: top;
1.347 albertel 7282: }
1.795 www 7283:
1.809 bisitz 7284: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 7285: background-color: $data_table_dark;
1.900 bisitz 7286: vertical-align: top;
1.347 albertel 7287: }
1.795 www 7288:
1.425 albertel 7289: table.LC_data_table tr.LC_data_table_highlight td {
7290: background-color: $data_table_darker;
7291: }
1.795 www 7292:
1.639 raeburn 7293: table.LC_data_table tr td.LC_leftcol_header {
7294: background-color: $data_table_head;
7295: font-weight: bold;
7296: }
1.795 www 7297:
1.451 albertel 7298: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 7299: table.LC_nested tr.LC_empty_row td {
1.421 albertel 7300: font-weight: bold;
7301: font-style: italic;
7302: text-align: center;
7303: padding: 8px;
1.347 albertel 7304: }
1.795 www 7305:
1.1114 raeburn 7306: table.LC_data_table tr.LC_empty_row td,
7307: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 7308: background-color: $sidebg;
7309: }
7310:
7311: table.LC_nested tr.LC_empty_row td {
7312: background-color: #FFFFFF;
7313: }
7314:
1.890 droeschl 7315: table.LC_caption {
7316: }
7317:
1.507 raeburn 7318: table.LC_nested tr.LC_empty_row td {
1.465 albertel 7319: padding: 4ex
7320: }
1.795 www 7321:
1.507 raeburn 7322: table.LC_nested_outer tr th {
7323: font-weight: bold;
1.801 tempelho 7324: color:$fontmenu;
1.507 raeburn 7325: background-color: $data_table_head;
1.701 harmsja 7326: font-size: small;
1.507 raeburn 7327: border-bottom: 1px solid #000000;
7328: }
1.795 www 7329:
1.507 raeburn 7330: table.LC_nested_outer tr td.LC_subheader {
7331: background-color: $data_table_head;
7332: font-weight: bold;
7333: font-size: small;
7334: border-bottom: 1px solid #000000;
7335: text-align: right;
1.451 albertel 7336: }
1.795 www 7337:
1.507 raeburn 7338: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7339: background-color: #CCCCCC;
1.451 albertel 7340: font-weight: bold;
7341: font-size: small;
1.507 raeburn 7342: text-align: center;
7343: }
1.795 www 7344:
1.589 raeburn 7345: table.LC_nested tr.LC_info_row td.LC_left_item,
7346: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7347: text-align: left;
1.451 albertel 7348: }
1.795 www 7349:
1.507 raeburn 7350: table.LC_nested td {
1.735 bisitz 7351: background-color: #FFFFFF;
1.451 albertel 7352: font-size: small;
1.507 raeburn 7353: }
1.795 www 7354:
1.507 raeburn 7355: table.LC_nested_outer tr th.LC_right_item,
7356: table.LC_nested tr.LC_info_row td.LC_right_item,
7357: table.LC_nested tr.LC_odd_row td.LC_right_item,
7358: table.LC_nested tr td.LC_right_item {
1.451 albertel 7359: text-align: right;
7360: }
7361:
1.507 raeburn 7362: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7363: background-color: #EEEEEE;
1.451 albertel 7364: }
7365:
1.473 raeburn 7366: table.LC_createuser {
7367: }
7368:
7369: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7370: font-size: small;
1.473 raeburn 7371: }
7372:
7373: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7374: background-color: #CCCCCC;
1.473 raeburn 7375: font-weight: bold;
7376: text-align: center;
7377: }
7378:
1.349 albertel 7379: table.LC_calendar {
7380: border: 1px solid #000000;
7381: border-collapse: collapse;
1.917 raeburn 7382: width: 98%;
1.349 albertel 7383: }
1.795 www 7384:
1.349 albertel 7385: table.LC_calendar_pickdate {
7386: font-size: xx-small;
7387: }
1.795 www 7388:
1.349 albertel 7389: table.LC_calendar tr td {
7390: border: 1px solid #000000;
7391: vertical-align: top;
1.917 raeburn 7392: width: 14%;
1.349 albertel 7393: }
1.795 www 7394:
1.349 albertel 7395: table.LC_calendar tr td.LC_calendar_day_empty {
7396: background-color: $data_table_dark;
7397: }
1.795 www 7398:
1.779 bisitz 7399: table.LC_calendar tr td.LC_calendar_day_current {
7400: background-color: $data_table_highlight;
1.777 tempelho 7401: }
1.795 www 7402:
1.938 bisitz 7403: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7404: background-color: $mail_new;
7405: }
1.795 www 7406:
1.938 bisitz 7407: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7408: background-color: $mail_new_hover;
7409: }
1.795 www 7410:
1.938 bisitz 7411: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7412: background-color: $mail_read;
7413: }
1.795 www 7414:
1.938 bisitz 7415: /*
7416: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7417: background-color: $mail_read_hover;
7418: }
1.938 bisitz 7419: */
1.795 www 7420:
1.938 bisitz 7421: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7422: background-color: $mail_replied;
7423: }
1.795 www 7424:
1.938 bisitz 7425: /*
7426: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7427: background-color: $mail_replied_hover;
7428: }
1.938 bisitz 7429: */
1.795 www 7430:
1.938 bisitz 7431: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7432: background-color: $mail_other;
7433: }
1.795 www 7434:
1.938 bisitz 7435: /*
7436: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7437: background-color: $mail_other_hover;
7438: }
1.938 bisitz 7439: */
1.494 raeburn 7440:
1.777 tempelho 7441: table.LC_data_table tr > td.LC_browser_file,
7442: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7443: background: #AAEE77;
1.389 albertel 7444: }
1.795 www 7445:
1.777 tempelho 7446: table.LC_data_table tr > td.LC_browser_file_locked,
7447: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7448: background: #FFAA99;
1.387 albertel 7449: }
1.795 www 7450:
1.777 tempelho 7451: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7452: background: #888888;
1.779 bisitz 7453: }
1.795 www 7454:
1.777 tempelho 7455: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7456: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7457: background: #F8F866;
1.777 tempelho 7458: }
1.795 www 7459:
1.696 bisitz 7460: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7461: background: #E0E8FF;
1.387 albertel 7462: }
1.696 bisitz 7463:
1.707 bisitz 7464: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7465: /* background: #77FF77; */
1.707 bisitz 7466: }
1.795 www 7467:
1.707 bisitz 7468: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7469: border-right: 8px solid #FFFF77;
1.707 bisitz 7470: }
1.795 www 7471:
1.707 bisitz 7472: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7473: border-right: 8px solid #FFAA77;
1.707 bisitz 7474: }
1.795 www 7475:
1.707 bisitz 7476: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7477: border-right: 8px solid #FF7777;
1.707 bisitz 7478: }
1.795 www 7479:
1.707 bisitz 7480: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7481: border-right: 8px solid #AAFF77;
1.707 bisitz 7482: }
1.795 www 7483:
1.707 bisitz 7484: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7485: border-right: 8px solid #11CC55;
1.707 bisitz 7486: }
7487:
1.388 albertel 7488: span.LC_current_location {
1.701 harmsja 7489: font-size:larger;
1.388 albertel 7490: background: $pgbg;
7491: }
1.387 albertel 7492:
1.1029 www 7493: span.LC_current_nav_location {
7494: font-weight:bold;
7495: background: $sidebg;
7496: }
7497:
1.395 albertel 7498: span.LC_parm_menu_item {
7499: font-size: larger;
7500: }
1.795 www 7501:
1.395 albertel 7502: span.LC_parm_scope_all {
7503: color: red;
7504: }
1.795 www 7505:
1.395 albertel 7506: span.LC_parm_scope_folder {
7507: color: green;
7508: }
1.795 www 7509:
1.395 albertel 7510: span.LC_parm_scope_resource {
7511: color: orange;
7512: }
1.795 www 7513:
1.395 albertel 7514: span.LC_parm_part {
7515: color: blue;
7516: }
1.795 www 7517:
1.911 bisitz 7518: span.LC_parm_folder,
7519: span.LC_parm_symb {
1.395 albertel 7520: font-size: x-small;
7521: font-family: $mono;
7522: color: #AAAAAA;
7523: }
7524:
1.977 bisitz 7525: ul.LC_parm_parmlist li {
7526: display: inline-block;
7527: padding: 0.3em 0.8em;
7528: vertical-align: top;
7529: width: 150px;
7530: border-top:1px solid $lg_border_color;
7531: }
7532:
1.795 www 7533: td.LC_parm_overview_level_menu,
7534: td.LC_parm_overview_map_menu,
7535: td.LC_parm_overview_parm_selectors,
7536: td.LC_parm_overview_restrictions {
1.396 albertel 7537: border: 1px solid black;
7538: border-collapse: collapse;
7539: }
1.795 www 7540:
1.1285 raeburn 7541: span.LC_parm_recursive,
7542: td.LC_parm_recursive {
7543: font-weight: bold;
7544: font-size: smaller;
7545: }
7546:
1.396 albertel 7547: table.LC_parm_overview_restrictions td {
7548: border-width: 1px 4px 1px 4px;
7549: border-style: solid;
7550: border-color: $pgbg;
7551: text-align: center;
7552: }
1.795 www 7553:
1.396 albertel 7554: table.LC_parm_overview_restrictions th {
7555: background: $tabbg;
7556: border-width: 1px 4px 1px 4px;
7557: border-style: solid;
7558: border-color: $pgbg;
7559: }
1.795 www 7560:
1.398 albertel 7561: table#LC_helpmenu {
1.803 bisitz 7562: border: none;
1.398 albertel 7563: height: 55px;
1.803 bisitz 7564: border-spacing: 0;
1.398 albertel 7565: }
7566:
7567: table#LC_helpmenu fieldset legend {
7568: font-size: larger;
7569: }
1.795 www 7570:
1.397 albertel 7571: table#LC_helpmenu_links {
7572: width: 100%;
7573: border: 1px solid black;
7574: background: $pgbg;
1.803 bisitz 7575: padding: 0;
1.397 albertel 7576: border-spacing: 1px;
7577: }
1.795 www 7578:
1.397 albertel 7579: table#LC_helpmenu_links tr td {
7580: padding: 1px;
7581: background: $tabbg;
1.399 albertel 7582: text-align: center;
7583: font-weight: bold;
1.397 albertel 7584: }
1.396 albertel 7585:
1.795 www 7586: table#LC_helpmenu_links a:link,
7587: table#LC_helpmenu_links a:visited,
1.397 albertel 7588: table#LC_helpmenu_links a:active {
7589: text-decoration: none;
7590: color: $font;
7591: }
1.795 www 7592:
1.397 albertel 7593: table#LC_helpmenu_links a:hover {
7594: text-decoration: underline;
7595: color: $vlink;
7596: }
1.396 albertel 7597:
1.417 albertel 7598: .LC_chrt_popup_exists {
7599: border: 1px solid #339933;
7600: margin: -1px;
7601: }
1.795 www 7602:
1.417 albertel 7603: .LC_chrt_popup_up {
7604: border: 1px solid yellow;
7605: margin: -1px;
7606: }
1.795 www 7607:
1.417 albertel 7608: .LC_chrt_popup {
7609: border: 1px solid #8888FF;
7610: background: #CCCCFF;
7611: }
1.795 www 7612:
1.421 albertel 7613: table.LC_pick_box {
7614: border-collapse: separate;
7615: background: white;
7616: border: 1px solid black;
7617: border-spacing: 1px;
7618: }
1.795 www 7619:
1.421 albertel 7620: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7621: background: $sidebg;
1.421 albertel 7622: font-weight: bold;
1.900 bisitz 7623: text-align: left;
1.740 bisitz 7624: vertical-align: top;
1.421 albertel 7625: width: 184px;
7626: padding: 8px;
7627: }
1.795 www 7628:
1.579 raeburn 7629: table.LC_pick_box td.LC_pick_box_value {
7630: text-align: left;
7631: padding: 8px;
7632: }
1.795 www 7633:
1.579 raeburn 7634: table.LC_pick_box td.LC_pick_box_select {
7635: text-align: left;
7636: padding: 8px;
7637: }
1.795 www 7638:
1.424 albertel 7639: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7640: padding: 0;
1.421 albertel 7641: height: 1px;
7642: background: black;
7643: }
1.795 www 7644:
1.421 albertel 7645: table.LC_pick_box td.LC_pick_box_submit {
7646: text-align: right;
7647: }
1.795 www 7648:
1.579 raeburn 7649: table.LC_pick_box td.LC_evenrow_value {
7650: text-align: left;
7651: padding: 8px;
7652: background-color: $data_table_light;
7653: }
1.795 www 7654:
1.579 raeburn 7655: table.LC_pick_box td.LC_oddrow_value {
7656: text-align: left;
7657: padding: 8px;
7658: background-color: $data_table_light;
7659: }
1.795 www 7660:
1.579 raeburn 7661: span.LC_helpform_receipt_cat {
7662: font-weight: bold;
7663: }
1.795 www 7664:
1.424 albertel 7665: table.LC_group_priv_box {
7666: background: white;
7667: border: 1px solid black;
7668: border-spacing: 1px;
7669: }
1.795 www 7670:
1.424 albertel 7671: table.LC_group_priv_box td.LC_pick_box_title {
7672: background: $tabbg;
7673: font-weight: bold;
7674: text-align: right;
7675: width: 184px;
7676: }
1.795 www 7677:
1.424 albertel 7678: table.LC_group_priv_box td.LC_groups_fixed {
7679: background: $data_table_light;
7680: text-align: center;
7681: }
1.795 www 7682:
1.424 albertel 7683: table.LC_group_priv_box td.LC_groups_optional {
7684: background: $data_table_dark;
7685: text-align: center;
7686: }
1.795 www 7687:
1.424 albertel 7688: table.LC_group_priv_box td.LC_groups_functionality {
7689: background: $data_table_darker;
7690: text-align: center;
7691: font-weight: bold;
7692: }
1.795 www 7693:
1.424 albertel 7694: table.LC_group_priv td {
7695: text-align: left;
1.803 bisitz 7696: padding: 0;
1.424 albertel 7697: }
7698:
7699: .LC_navbuttons {
7700: margin: 2ex 0ex 2ex 0ex;
7701: }
1.795 www 7702:
1.423 albertel 7703: .LC_topic_bar {
7704: font-weight: bold;
7705: background: $tabbg;
1.918 wenzelju 7706: margin: 1em 0em 1em 2em;
1.805 bisitz 7707: padding: 3px;
1.918 wenzelju 7708: font-size: 1.2em;
1.423 albertel 7709: }
1.795 www 7710:
1.423 albertel 7711: .LC_topic_bar span {
1.918 wenzelju 7712: left: 0.5em;
7713: position: absolute;
1.423 albertel 7714: vertical-align: middle;
1.918 wenzelju 7715: font-size: 1.2em;
1.423 albertel 7716: }
1.795 www 7717:
1.423 albertel 7718: table.LC_course_group_status {
7719: margin: 20px;
7720: }
1.795 www 7721:
1.423 albertel 7722: table.LC_status_selector td {
7723: vertical-align: top;
7724: text-align: center;
1.424 albertel 7725: padding: 4px;
7726: }
1.795 www 7727:
1.599 albertel 7728: div.LC_feedback_link {
1.616 albertel 7729: clear: both;
1.829 kalberla 7730: background: $sidebg;
1.779 bisitz 7731: width: 100%;
1.829 kalberla 7732: padding-bottom: 10px;
7733: border: 1px $tabbg solid;
1.833 kalberla 7734: height: 22px;
7735: line-height: 22px;
7736: padding-top: 5px;
7737: }
7738:
7739: div.LC_feedback_link img {
7740: height: 22px;
1.867 kalberla 7741: vertical-align:middle;
1.829 kalberla 7742: }
7743:
1.911 bisitz 7744: div.LC_feedback_link a {
1.829 kalberla 7745: text-decoration: none;
1.489 raeburn 7746: }
1.795 www 7747:
1.867 kalberla 7748: div.LC_comblock {
1.911 bisitz 7749: display:inline;
1.867 kalberla 7750: color:$font;
7751: font-size:90%;
7752: }
7753:
7754: div.LC_feedback_link div.LC_comblock {
7755: padding-left:5px;
7756: }
7757:
7758: div.LC_feedback_link div.LC_comblock a {
7759: color:$font;
7760: }
7761:
1.489 raeburn 7762: span.LC_feedback_link {
1.858 bisitz 7763: /* background: $feedback_link_bg; */
1.599 albertel 7764: font-size: larger;
7765: }
1.795 www 7766:
1.599 albertel 7767: span.LC_message_link {
1.858 bisitz 7768: /* background: $feedback_link_bg; */
1.599 albertel 7769: font-size: larger;
7770: position: absolute;
7771: right: 1em;
1.489 raeburn 7772: }
1.421 albertel 7773:
1.515 albertel 7774: table.LC_prior_tries {
1.524 albertel 7775: border: 1px solid #000000;
7776: border-collapse: separate;
7777: border-spacing: 1px;
1.515 albertel 7778: }
1.523 albertel 7779:
1.515 albertel 7780: table.LC_prior_tries td {
1.524 albertel 7781: padding: 2px;
1.515 albertel 7782: }
1.523 albertel 7783:
7784: .LC_answer_correct {
1.795 www 7785: background: lightgreen;
7786: color: darkgreen;
7787: padding: 6px;
1.523 albertel 7788: }
1.795 www 7789:
1.523 albertel 7790: .LC_answer_charged_try {
1.797 www 7791: background: #FFAAAA;
1.795 www 7792: color: darkred;
7793: padding: 6px;
1.523 albertel 7794: }
1.795 www 7795:
1.779 bisitz 7796: .LC_answer_not_charged_try,
1.523 albertel 7797: .LC_answer_no_grade,
7798: .LC_answer_late {
1.795 www 7799: background: lightyellow;
1.523 albertel 7800: color: black;
1.795 www 7801: padding: 6px;
1.523 albertel 7802: }
1.795 www 7803:
1.523 albertel 7804: .LC_answer_previous {
1.795 www 7805: background: lightblue;
7806: color: darkblue;
7807: padding: 6px;
1.523 albertel 7808: }
1.795 www 7809:
1.779 bisitz 7810: .LC_answer_no_message {
1.777 tempelho 7811: background: #FFFFFF;
7812: color: black;
1.795 www 7813: padding: 6px;
1.779 bisitz 7814: }
1.795 www 7815:
1.1334 raeburn 7816: .LC_answer_unknown,
7817: .LC_answer_warning {
1.779 bisitz 7818: background: orange;
7819: color: black;
1.795 www 7820: padding: 6px;
1.777 tempelho 7821: }
1.795 www 7822:
1.529 albertel 7823: span.LC_prior_numerical,
7824: span.LC_prior_string,
7825: span.LC_prior_custom,
7826: span.LC_prior_reaction,
7827: span.LC_prior_math {
1.925 bisitz 7828: font-family: $mono;
1.523 albertel 7829: white-space: pre;
7830: }
7831:
1.525 albertel 7832: span.LC_prior_string {
1.925 bisitz 7833: font-family: $mono;
1.525 albertel 7834: white-space: pre;
7835: }
7836:
1.523 albertel 7837: table.LC_prior_option {
7838: width: 100%;
7839: border-collapse: collapse;
7840: }
1.795 www 7841:
1.911 bisitz 7842: table.LC_prior_rank,
1.795 www 7843: table.LC_prior_match {
1.528 albertel 7844: border-collapse: collapse;
7845: }
1.795 www 7846:
1.528 albertel 7847: table.LC_prior_option tr td,
7848: table.LC_prior_rank tr td,
7849: table.LC_prior_match tr td {
1.524 albertel 7850: border: 1px solid #000000;
1.515 albertel 7851: }
7852:
1.855 bisitz 7853: .LC_nobreak {
1.544 albertel 7854: white-space: nowrap;
1.519 raeburn 7855: }
7856:
1.576 raeburn 7857: span.LC_cusr_emph {
7858: font-style: italic;
7859: }
7860:
1.633 raeburn 7861: span.LC_cusr_subheading {
7862: font-weight: normal;
7863: font-size: 85%;
7864: }
7865:
1.861 bisitz 7866: div.LC_docs_entry_move {
1.859 bisitz 7867: border: 1px solid #BBBBBB;
1.545 albertel 7868: background: #DDDDDD;
1.861 bisitz 7869: width: 22px;
1.859 bisitz 7870: padding: 1px;
7871: margin: 0;
1.545 albertel 7872: }
7873:
1.861 bisitz 7874: table.LC_data_table tr > td.LC_docs_entry_commands,
7875: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7876: font-size: x-small;
7877: }
1.795 www 7878:
1.861 bisitz 7879: .LC_docs_entry_parameter {
7880: white-space: nowrap;
7881: }
7882:
1.544 albertel 7883: .LC_docs_copy {
1.545 albertel 7884: color: #000099;
1.544 albertel 7885: }
1.795 www 7886:
1.544 albertel 7887: .LC_docs_cut {
1.545 albertel 7888: color: #550044;
1.544 albertel 7889: }
1.795 www 7890:
1.544 albertel 7891: .LC_docs_rename {
1.545 albertel 7892: color: #009900;
1.544 albertel 7893: }
1.795 www 7894:
1.544 albertel 7895: .LC_docs_remove {
1.545 albertel 7896: color: #990000;
7897: }
7898:
1.1284 raeburn 7899: .LC_docs_alias {
7900: color: #440055;
7901: }
7902:
1.1286 raeburn 7903: .LC_domprefs_email,
1.1284 raeburn 7904: .LC_docs_alias_name,
1.547 albertel 7905: .LC_docs_reinit_warn,
7906: .LC_docs_ext_edit {
7907: font-size: x-small;
7908: }
7909:
1.545 albertel 7910: table.LC_docs_adddocs td,
7911: table.LC_docs_adddocs th {
7912: border: 1px solid #BBBBBB;
7913: padding: 4px;
7914: background: #DDDDDD;
1.543 albertel 7915: }
7916:
1.584 albertel 7917: table.LC_sty_begin {
7918: background: #BBFFBB;
7919: }
1.795 www 7920:
1.584 albertel 7921: table.LC_sty_end {
7922: background: #FFBBBB;
7923: }
7924:
1.589 raeburn 7925: table.LC_double_column {
1.803 bisitz 7926: border-width: 0;
1.589 raeburn 7927: border-collapse: collapse;
7928: width: 100%;
7929: padding: 2px;
7930: }
7931:
7932: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7933: top: 2px;
1.589 raeburn 7934: left: 2px;
7935: width: 47%;
7936: vertical-align: top;
7937: }
7938:
7939: table.LC_double_column tr td.LC_right_col {
7940: top: 2px;
1.779 bisitz 7941: right: 2px;
1.589 raeburn 7942: width: 47%;
7943: vertical-align: top;
7944: }
7945:
1.591 raeburn 7946: div.LC_left_float {
7947: float: left;
7948: padding-right: 5%;
1.597 albertel 7949: padding-bottom: 4px;
1.591 raeburn 7950: }
7951:
7952: div.LC_clear_float_header {
1.597 albertel 7953: padding-bottom: 2px;
1.591 raeburn 7954: }
7955:
7956: div.LC_clear_float_footer {
1.597 albertel 7957: padding-top: 10px;
1.591 raeburn 7958: clear: both;
7959: }
7960:
1.597 albertel 7961: div.LC_grade_show_user {
1.941 bisitz 7962: /* border-left: 5px solid $sidebg; */
7963: border-top: 5px solid #000000;
7964: margin: 50px 0 0 0;
1.936 bisitz 7965: padding: 15px 0 5px 10px;
1.597 albertel 7966: }
1.795 www 7967:
1.936 bisitz 7968: div.LC_grade_show_user_odd_row {
1.941 bisitz 7969: /* border-left: 5px solid #000000; */
7970: }
7971:
7972: div.LC_grade_show_user div.LC_Box {
7973: margin-right: 50px;
1.597 albertel 7974: }
7975:
7976: div.LC_grade_submissions,
7977: div.LC_grade_message_center,
1.936 bisitz 7978: div.LC_grade_info_links {
1.597 albertel 7979: margin: 5px;
7980: width: 99%;
7981: background: #FFFFFF;
7982: }
1.795 www 7983:
1.597 albertel 7984: div.LC_grade_submissions_header,
1.936 bisitz 7985: div.LC_grade_message_center_header {
1.705 tempelho 7986: font-weight: bold;
7987: font-size: large;
1.597 albertel 7988: }
1.795 www 7989:
1.597 albertel 7990: div.LC_grade_submissions_body,
1.936 bisitz 7991: div.LC_grade_message_center_body {
1.597 albertel 7992: border: 1px solid black;
7993: width: 99%;
7994: background: #FFFFFF;
7995: }
1.795 www 7996:
1.613 albertel 7997: table.LC_scantron_action {
7998: width: 100%;
7999: }
1.795 www 8000:
1.613 albertel 8001: table.LC_scantron_action tr th {
1.698 harmsja 8002: font-weight:bold;
8003: font-style:normal;
1.613 albertel 8004: }
1.795 www 8005:
1.779 bisitz 8006: .LC_edit_problem_header,
1.614 albertel 8007: div.LC_edit_problem_footer {
1.705 tempelho 8008: font-weight: normal;
8009: font-size: medium;
1.602 albertel 8010: margin: 2px;
1.1060 bisitz 8011: background-color: $sidebg;
1.600 albertel 8012: }
1.795 www 8013:
1.600 albertel 8014: div.LC_edit_problem_header,
1.602 albertel 8015: div.LC_edit_problem_header div,
1.614 albertel 8016: div.LC_edit_problem_footer,
8017: div.LC_edit_problem_footer div,
1.602 albertel 8018: div.LC_edit_problem_editxml_header,
8019: div.LC_edit_problem_editxml_header div {
1.1205 golterma 8020: z-index: 100;
1.600 albertel 8021: }
1.795 www 8022:
1.600 albertel 8023: div.LC_edit_problem_header_title {
1.705 tempelho 8024: font-weight: bold;
8025: font-size: larger;
1.602 albertel 8026: background: $tabbg;
8027: padding: 3px;
1.1060 bisitz 8028: margin: 0 0 5px 0;
1.602 albertel 8029: }
1.795 www 8030:
1.602 albertel 8031: table.LC_edit_problem_header_title {
8032: width: 100%;
1.600 albertel 8033: background: $tabbg;
1.602 albertel 8034: }
8035:
1.1205 golterma 8036: div.LC_edit_actionbar {
8037: background-color: $sidebg;
1.1218 droeschl 8038: margin: 0;
8039: padding: 0;
8040: line-height: 200%;
1.602 albertel 8041: }
1.795 www 8042:
1.1218 droeschl 8043: div.LC_edit_actionbar div{
8044: padding: 0;
8045: margin: 0;
8046: display: inline-block;
1.600 albertel 8047: }
1.795 www 8048:
1.1124 bisitz 8049: .LC_edit_opt {
8050: padding-left: 1em;
8051: white-space: nowrap;
8052: }
8053:
1.1152 golterma 8054: .LC_edit_problem_latexhelper{
8055: text-align: right;
8056: }
8057:
8058: #LC_edit_problem_colorful div{
8059: margin-left: 40px;
8060: }
8061:
1.1205 golterma 8062: #LC_edit_problem_codemirror div{
8063: margin-left: 0px;
8064: }
8065:
1.911 bisitz 8066: img.stift {
1.803 bisitz 8067: border-width: 0;
8068: vertical-align: middle;
1.677 riegler 8069: }
1.680 riegler 8070:
1.923 bisitz 8071: table td.LC_mainmenu_col_fieldset {
1.680 riegler 8072: vertical-align: top;
1.777 tempelho 8073: }
1.795 www 8074:
1.716 raeburn 8075: div.LC_createcourse {
1.911 bisitz 8076: margin: 10px 10px 10px 10px;
1.716 raeburn 8077: }
8078:
1.917 raeburn 8079: .LC_dccid {
1.1130 raeburn 8080: float: right;
1.917 raeburn 8081: margin: 0.2em 0 0 0;
8082: padding: 0;
8083: font-size: 90%;
8084: display:none;
8085: }
8086:
1.897 wenzelju 8087: ol.LC_primary_menu a:hover,
1.721 harmsja 8088: ol#LC_MenuBreadcrumbs a:hover,
8089: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 8090: ul#LC_secondary_menu a:hover,
1.721 harmsja 8091: .LC_FormSectionClearButton input:hover
1.795 www 8092: ul.LC_TabContent li:hover a {
1.952 onken 8093: color:$button_hover;
1.911 bisitz 8094: text-decoration:none;
1.693 droeschl 8095: }
8096:
1.779 bisitz 8097: h1 {
1.911 bisitz 8098: padding: 0;
8099: line-height:130%;
1.693 droeschl 8100: }
1.698 harmsja 8101:
1.911 bisitz 8102: h2,
8103: h3,
8104: h4,
8105: h5,
8106: h6 {
8107: margin: 5px 0 5px 0;
8108: padding: 0;
8109: line-height:130%;
1.693 droeschl 8110: }
1.795 www 8111:
8112: .LC_hcell {
1.911 bisitz 8113: padding:3px 15px 3px 15px;
8114: margin: 0;
8115: background-color:$tabbg;
8116: color:$fontmenu;
8117: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 8118: }
1.795 www 8119:
1.840 bisitz 8120: .LC_Box > .LC_hcell {
1.911 bisitz 8121: margin: 0 -10px 10px -10px;
1.835 bisitz 8122: }
8123:
1.721 harmsja 8124: .LC_noBorder {
1.911 bisitz 8125: border: 0;
1.698 harmsja 8126: }
1.693 droeschl 8127:
1.721 harmsja 8128: .LC_FormSectionClearButton input {
1.911 bisitz 8129: background-color:transparent;
8130: border: none;
8131: cursor:pointer;
8132: text-decoration:underline;
1.693 droeschl 8133: }
1.763 bisitz 8134:
8135: .LC_help_open_topic {
1.911 bisitz 8136: color: #FFFFFF;
8137: background-color: #EEEEFF;
8138: margin: 1px;
8139: padding: 4px;
8140: border: 1px solid #000033;
8141: white-space: nowrap;
8142: /* vertical-align: middle; */
1.759 neumanie 8143: }
1.693 droeschl 8144:
1.911 bisitz 8145: dl,
8146: ul,
8147: div,
8148: fieldset {
8149: margin: 10px 10px 10px 0;
8150: /* overflow: hidden; */
1.693 droeschl 8151: }
1.795 www 8152:
1.1211 raeburn 8153: article.geogebraweb div {
8154: margin: 0;
8155: }
8156:
1.838 bisitz 8157: fieldset > legend {
1.911 bisitz 8158: font-weight: bold;
8159: padding: 0 5px 0 5px;
1.838 bisitz 8160: }
8161:
1.813 bisitz 8162: #LC_nav_bar {
1.911 bisitz 8163: float: left;
1.995 raeburn 8164: background-color: $pgbg_or_bgcolor;
1.966 bisitz 8165: margin: 0 0 2px 0;
1.807 droeschl 8166: }
8167:
1.916 droeschl 8168: #LC_realm {
8169: margin: 0.2em 0 0 0;
8170: padding: 0;
8171: font-weight: bold;
8172: text-align: center;
1.995 raeburn 8173: background-color: $pgbg_or_bgcolor;
1.916 droeschl 8174: }
8175:
1.911 bisitz 8176: #LC_nav_bar em {
8177: font-weight: bold;
8178: font-style: normal;
1.807 droeschl 8179: }
8180:
1.897 wenzelju 8181: ol.LC_primary_menu {
1.934 droeschl 8182: margin: 0;
1.1076 raeburn 8183: padding: 0;
1.807 droeschl 8184: }
8185:
1.852 droeschl 8186: ol#LC_PathBreadcrumbs {
1.911 bisitz 8187: margin: 0;
1.693 droeschl 8188: }
8189:
1.897 wenzelju 8190: ol.LC_primary_menu li {
1.1076 raeburn 8191: color: RGB(80, 80, 80);
8192: vertical-align: middle;
8193: text-align: left;
8194: list-style: none;
1.1205 golterma 8195: position: relative;
1.1076 raeburn 8196: float: left;
1.1205 golterma 8197: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
8198: line-height: 1.5em;
1.1076 raeburn 8199: }
8200:
1.1205 golterma 8201: ol.LC_primary_menu li a,
8202: ol.LC_primary_menu li p {
1.1076 raeburn 8203: display: block;
8204: margin: 0;
8205: padding: 0 5px 0 10px;
8206: text-decoration: none;
8207: }
8208:
1.1205 golterma 8209: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
8210: display: inline-block;
8211: width: 95%;
8212: text-align: left;
8213: }
8214:
8215: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
8216: display: inline-block;
8217: width: 5%;
8218: float: right;
8219: text-align: right;
8220: font-size: 70%;
8221: }
8222:
8223: ol.LC_primary_menu ul {
1.1076 raeburn 8224: display: none;
1.1205 golterma 8225: width: 15em;
1.1076 raeburn 8226: background-color: $data_table_light;
1.1205 golterma 8227: position: absolute;
8228: top: 100%;
1.1076 raeburn 8229: }
8230:
1.1205 golterma 8231: ol.LC_primary_menu ul ul {
8232: left: 100%;
8233: top: 0;
8234: }
8235:
8236: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 8237: display: block;
8238: position: absolute;
8239: margin: 0;
8240: padding: 0;
1.1078 raeburn 8241: z-index: 2;
1.1076 raeburn 8242: }
8243:
8244: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 8245: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 8246: font-size: 90%;
1.911 bisitz 8247: vertical-align: top;
1.1076 raeburn 8248: float: none;
1.1079 raeburn 8249: border-left: 1px solid black;
8250: border-right: 1px solid black;
1.1205 golterma 8251: /* A dark bottom border to visualize different menu options;
8252: overwritten in the create_submenu routine for the last border-bottom of the menu */
8253: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 8254: }
8255:
1.1205 golterma 8256: ol.LC_primary_menu li li p:hover {
8257: color:$button_hover;
8258: text-decoration:none;
8259: background-color:$data_table_dark;
1.1076 raeburn 8260: }
8261:
8262: ol.LC_primary_menu li li a:hover {
8263: color:$button_hover;
8264: background-color:$data_table_dark;
1.693 droeschl 8265: }
8266:
1.1205 golterma 8267: /* Font-size equal to the size of the predecessors*/
8268: ol.LC_primary_menu li:hover li li {
8269: font-size: 100%;
8270: }
8271:
1.897 wenzelju 8272: ol.LC_primary_menu li img {
1.911 bisitz 8273: vertical-align: bottom;
1.934 droeschl 8274: height: 1.1em;
1.1077 raeburn 8275: margin: 0.2em 0 0 0;
1.693 droeschl 8276: }
8277:
1.897 wenzelju 8278: ol.LC_primary_menu a {
1.911 bisitz 8279: color: RGB(80, 80, 80);
8280: text-decoration: none;
1.693 droeschl 8281: }
1.795 www 8282:
1.949 droeschl 8283: ol.LC_primary_menu a.LC_new_message {
8284: font-weight:bold;
8285: color: darkred;
8286: }
8287:
1.975 raeburn 8288: ol.LC_docs_parameters {
8289: margin-left: 0;
8290: padding: 0;
8291: list-style: none;
8292: }
8293:
8294: ol.LC_docs_parameters li {
8295: margin: 0;
8296: padding-right: 20px;
8297: display: inline;
8298: }
8299:
1.976 raeburn 8300: ol.LC_docs_parameters li:before {
8301: content: "\\002022 \\0020";
8302: }
8303:
8304: li.LC_docs_parameters_title {
8305: font-weight: bold;
8306: }
8307:
8308: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
8309: content: "";
8310: }
8311:
1.897 wenzelju 8312: ul#LC_secondary_menu {
1.1107 raeburn 8313: clear: right;
1.911 bisitz 8314: color: $fontmenu;
8315: background: $tabbg;
8316: list-style: none;
8317: padding: 0;
8318: margin: 0;
8319: width: 100%;
1.995 raeburn 8320: text-align: left;
1.1107 raeburn 8321: float: left;
1.808 droeschl 8322: }
8323:
1.897 wenzelju 8324: ul#LC_secondary_menu li {
1.911 bisitz 8325: font-weight: bold;
8326: line-height: 1.8em;
1.1107 raeburn 8327: border-right: 1px solid black;
8328: float: left;
8329: }
8330:
8331: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
8332: background-color: $data_table_light;
8333: }
8334:
8335: ul#LC_secondary_menu li a {
1.911 bisitz 8336: padding: 0 0.8em;
1.1107 raeburn 8337: }
8338:
8339: ul#LC_secondary_menu li ul {
8340: display: none;
8341: }
8342:
8343: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8344: display: block;
8345: position: absolute;
8346: margin: 0;
8347: padding: 0;
8348: list-style:none;
8349: float: none;
8350: background-color: $data_table_light;
8351: z-index: 2;
8352: margin-left: -1px;
8353: }
8354:
8355: ul#LC_secondary_menu li ul li {
8356: font-size: 90%;
8357: vertical-align: top;
8358: border-left: 1px solid black;
1.911 bisitz 8359: border-right: 1px solid black;
1.1119 raeburn 8360: background-color: $data_table_light;
1.1107 raeburn 8361: list-style:none;
8362: float: none;
8363: }
8364:
8365: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8366: background-color: $data_table_dark;
1.807 droeschl 8367: }
8368:
1.847 tempelho 8369: ul.LC_TabContent {
1.911 bisitz 8370: display:block;
8371: background: $sidebg;
8372: border-bottom: solid 1px $lg_border_color;
8373: list-style:none;
1.1020 raeburn 8374: margin: -1px -10px 0 -10px;
1.911 bisitz 8375: padding: 0;
1.693 droeschl 8376: }
8377:
1.795 www 8378: ul.LC_TabContent li,
8379: ul.LC_TabContentBigger li {
1.911 bisitz 8380: float:left;
1.741 harmsja 8381: }
1.795 www 8382:
1.897 wenzelju 8383: ul#LC_secondary_menu li a {
1.911 bisitz 8384: color: $fontmenu;
8385: text-decoration: none;
1.693 droeschl 8386: }
1.795 www 8387:
1.721 harmsja 8388: ul.LC_TabContent {
1.952 onken 8389: min-height:20px;
1.721 harmsja 8390: }
1.795 www 8391:
8392: ul.LC_TabContent li {
1.911 bisitz 8393: vertical-align:middle;
1.959 onken 8394: padding: 0 16px 0 10px;
1.911 bisitz 8395: background-color:$tabbg;
8396: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8397: border-left: solid 1px $font;
1.721 harmsja 8398: }
1.795 www 8399:
1.847 tempelho 8400: ul.LC_TabContent .right {
1.911 bisitz 8401: float:right;
1.847 tempelho 8402: }
8403:
1.911 bisitz 8404: ul.LC_TabContent li a,
8405: ul.LC_TabContent li {
8406: color:rgb(47,47,47);
8407: text-decoration:none;
8408: font-size:95%;
8409: font-weight:bold;
1.952 onken 8410: min-height:20px;
8411: }
8412:
1.959 onken 8413: ul.LC_TabContent li a:hover,
8414: ul.LC_TabContent li a:focus {
1.952 onken 8415: color: $button_hover;
1.959 onken 8416: background:none;
8417: outline:none;
1.952 onken 8418: }
8419:
8420: ul.LC_TabContent li:hover {
8421: color: $button_hover;
8422: cursor:pointer;
1.721 harmsja 8423: }
1.795 www 8424:
1.911 bisitz 8425: ul.LC_TabContent li.active {
1.952 onken 8426: color: $font;
1.911 bisitz 8427: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8428: border-bottom:solid 1px #FFFFFF;
8429: cursor: default;
1.744 ehlerst 8430: }
1.795 www 8431:
1.959 onken 8432: ul.LC_TabContent li.active a {
8433: color:$font;
8434: background:#FFFFFF;
8435: outline: none;
8436: }
1.1047 raeburn 8437:
8438: ul.LC_TabContent li.goback {
8439: float: left;
8440: border-left: none;
8441: }
8442:
1.870 tempelho 8443: #maincoursedoc {
1.911 bisitz 8444: clear:both;
1.870 tempelho 8445: }
8446:
8447: ul.LC_TabContentBigger {
1.911 bisitz 8448: display:block;
8449: list-style:none;
8450: padding: 0;
1.870 tempelho 8451: }
8452:
1.795 www 8453: ul.LC_TabContentBigger li {
1.911 bisitz 8454: vertical-align:bottom;
8455: height: 30px;
8456: font-size:110%;
8457: font-weight:bold;
8458: color: #737373;
1.841 tempelho 8459: }
8460:
1.957 onken 8461: ul.LC_TabContentBigger li.active {
8462: position: relative;
8463: top: 1px;
8464: }
8465:
1.870 tempelho 8466: ul.LC_TabContentBigger li a {
1.911 bisitz 8467: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8468: height: 30px;
8469: line-height: 30px;
8470: text-align: center;
8471: display: block;
8472: text-decoration: none;
1.958 onken 8473: outline: none;
1.741 harmsja 8474: }
1.795 www 8475:
1.870 tempelho 8476: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8477: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8478: color:$font;
1.744 ehlerst 8479: }
1.795 www 8480:
1.870 tempelho 8481: ul.LC_TabContentBigger li b {
1.911 bisitz 8482: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8483: display: block;
8484: float: left;
8485: padding: 0 30px;
1.957 onken 8486: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8487: }
8488:
1.956 onken 8489: ul.LC_TabContentBigger li:hover b {
8490: color:$button_hover;
8491: }
8492:
1.870 tempelho 8493: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8494: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8495: color:$font;
1.957 onken 8496: border: 0;
1.741 harmsja 8497: }
1.693 droeschl 8498:
1.870 tempelho 8499:
1.862 bisitz 8500: ul.LC_CourseBreadcrumbs {
8501: background: $sidebg;
1.1020 raeburn 8502: height: 2em;
1.862 bisitz 8503: padding-left: 10px;
1.1020 raeburn 8504: margin: 0;
1.862 bisitz 8505: list-style-position: inside;
8506: }
8507:
1.911 bisitz 8508: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8509: ol#LC_PathBreadcrumbs {
1.911 bisitz 8510: padding-left: 10px;
8511: margin: 0;
1.933 droeschl 8512: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8513: }
8514:
1.911 bisitz 8515: ol#LC_MenuBreadcrumbs li,
8516: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8517: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8518: display: inline;
1.933 droeschl 8519: white-space: normal;
1.693 droeschl 8520: }
8521:
1.823 bisitz 8522: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8523: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8524: text-decoration: none;
8525: font-size:90%;
1.693 droeschl 8526: }
1.795 www 8527:
1.969 droeschl 8528: ol#LC_MenuBreadcrumbs h1 {
8529: display: inline;
8530: font-size: 90%;
8531: line-height: 2.5em;
8532: margin: 0;
8533: padding: 0;
8534: }
8535:
1.795 www 8536: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8537: text-decoration:none;
8538: font-size:100%;
8539: font-weight:bold;
1.693 droeschl 8540: }
1.795 www 8541:
1.840 bisitz 8542: .LC_Box {
1.911 bisitz 8543: border: solid 1px $lg_border_color;
8544: padding: 0 10px 10px 10px;
1.746 neumanie 8545: }
1.795 www 8546:
1.1020 raeburn 8547: .LC_DocsBox {
8548: border: solid 1px $lg_border_color;
8549: padding: 0 0 10px 10px;
8550: }
8551:
1.795 www 8552: .LC_AboutMe_Image {
1.911 bisitz 8553: float:left;
8554: margin-right:10px;
1.747 neumanie 8555: }
1.795 www 8556:
8557: .LC_Clear_AboutMe_Image {
1.911 bisitz 8558: clear:left;
1.747 neumanie 8559: }
1.795 www 8560:
1.721 harmsja 8561: dl.LC_ListStyleClean dt {
1.911 bisitz 8562: padding-right: 5px;
8563: display: table-header-group;
1.693 droeschl 8564: }
8565:
1.721 harmsja 8566: dl.LC_ListStyleClean dd {
1.911 bisitz 8567: display: table-row;
1.693 droeschl 8568: }
8569:
1.721 harmsja 8570: .LC_ListStyleClean,
8571: .LC_ListStyleSimple,
8572: .LC_ListStyleNormal,
1.795 www 8573: .LC_ListStyleSpecial {
1.911 bisitz 8574: /* display:block; */
8575: list-style-position: inside;
8576: list-style-type: none;
8577: overflow: hidden;
8578: padding: 0;
1.693 droeschl 8579: }
8580:
1.721 harmsja 8581: .LC_ListStyleSimple li,
8582: .LC_ListStyleSimple dd,
8583: .LC_ListStyleNormal li,
8584: .LC_ListStyleNormal dd,
8585: .LC_ListStyleSpecial li,
1.795 www 8586: .LC_ListStyleSpecial dd {
1.911 bisitz 8587: margin: 0;
8588: padding: 5px 5px 5px 10px;
8589: clear: both;
1.693 droeschl 8590: }
8591:
1.721 harmsja 8592: .LC_ListStyleClean li,
8593: .LC_ListStyleClean dd {
1.911 bisitz 8594: padding-top: 0;
8595: padding-bottom: 0;
1.693 droeschl 8596: }
8597:
1.721 harmsja 8598: .LC_ListStyleSimple dd,
1.795 www 8599: .LC_ListStyleSimple li {
1.911 bisitz 8600: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8601: }
8602:
1.721 harmsja 8603: .LC_ListStyleSpecial li,
8604: .LC_ListStyleSpecial dd {
1.911 bisitz 8605: list-style-type: none;
8606: background-color: RGB(220, 220, 220);
8607: margin-bottom: 4px;
1.693 droeschl 8608: }
8609:
1.721 harmsja 8610: table.LC_SimpleTable {
1.911 bisitz 8611: margin:5px;
8612: border:solid 1px $lg_border_color;
1.795 www 8613: }
1.693 droeschl 8614:
1.721 harmsja 8615: table.LC_SimpleTable tr {
1.911 bisitz 8616: padding: 0;
8617: border:solid 1px $lg_border_color;
1.693 droeschl 8618: }
1.795 www 8619:
8620: table.LC_SimpleTable thead {
1.911 bisitz 8621: background:rgb(220,220,220);
1.693 droeschl 8622: }
8623:
1.721 harmsja 8624: div.LC_columnSection {
1.911 bisitz 8625: display: block;
8626: clear: both;
8627: overflow: hidden;
8628: margin: 0;
1.693 droeschl 8629: }
8630:
1.721 harmsja 8631: div.LC_columnSection>* {
1.911 bisitz 8632: float: left;
8633: margin: 10px 20px 10px 0;
8634: overflow:hidden;
1.693 droeschl 8635: }
1.721 harmsja 8636:
1.795 www 8637: table em {
1.911 bisitz 8638: font-weight: bold;
8639: font-style: normal;
1.748 schulted 8640: }
1.795 www 8641:
1.779 bisitz 8642: table.LC_tableBrowseRes,
1.795 www 8643: table.LC_tableOfContent {
1.911 bisitz 8644: border:none;
8645: border-spacing: 1px;
8646: padding: 3px;
8647: background-color: #FFFFFF;
8648: font-size: 90%;
1.753 droeschl 8649: }
1.789 droeschl 8650:
1.911 bisitz 8651: table.LC_tableOfContent {
8652: border-collapse: collapse;
1.789 droeschl 8653: }
8654:
1.771 droeschl 8655: table.LC_tableBrowseRes a,
1.768 schulted 8656: table.LC_tableOfContent a {
1.911 bisitz 8657: background-color: transparent;
8658: text-decoration: none;
1.753 droeschl 8659: }
8660:
1.795 www 8661: table.LC_tableOfContent img {
1.911 bisitz 8662: border: none;
8663: height: 1.3em;
8664: vertical-align: text-bottom;
8665: margin-right: 0.3em;
1.753 droeschl 8666: }
1.757 schulted 8667:
1.795 www 8668: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8669: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8670: }
8671:
1.795 www 8672: a#LC_content_toolbar_everything {
1.911 bisitz 8673: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8674: }
8675:
1.795 www 8676: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8677: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8678: }
8679:
1.795 www 8680: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8681: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8682: }
8683:
1.795 www 8684: a#LC_content_toolbar_changefolder {
1.911 bisitz 8685: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8686: }
8687:
1.795 www 8688: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8689: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8690: }
8691:
1.1043 raeburn 8692: a#LC_content_toolbar_edittoplevel {
8693: background-image:url(/res/adm/pages/edittoplevel.gif);
8694: }
8695:
1.1384 raeburn 8696: a#LC_content_toolbar_printout {
8697: background-image:url(/res/adm/pages/printout.gif);
8698: }
8699:
1.795 www 8700: ul#LC_toolbar li a:hover {
1.911 bisitz 8701: background-position: bottom center;
1.757 schulted 8702: }
8703:
1.795 www 8704: ul#LC_toolbar {
1.911 bisitz 8705: padding: 0;
8706: margin: 2px;
8707: list-style:none;
8708: position:relative;
8709: background-color:white;
1.1082 raeburn 8710: overflow: auto;
1.757 schulted 8711: }
8712:
1.795 www 8713: ul#LC_toolbar li {
1.911 bisitz 8714: border:1px solid white;
8715: padding: 0;
8716: margin: 0;
8717: float: left;
8718: display:inline;
8719: vertical-align:middle;
1.1082 raeburn 8720: white-space: nowrap;
1.911 bisitz 8721: }
1.757 schulted 8722:
1.783 amueller 8723:
1.795 www 8724: a.LC_toolbarItem {
1.911 bisitz 8725: display:block;
8726: padding: 0;
8727: margin: 0;
8728: height: 32px;
8729: width: 32px;
8730: color:white;
8731: border: none;
8732: background-repeat:no-repeat;
8733: background-color:transparent;
1.757 schulted 8734: }
8735:
1.915 droeschl 8736: ul.LC_funclist {
8737: margin: 0;
8738: padding: 0.5em 1em 0.5em 0;
8739: }
8740:
1.933 droeschl 8741: ul.LC_funclist > li:first-child {
8742: font-weight:bold;
8743: margin-left:0.8em;
8744: }
8745:
1.915 droeschl 8746: ul.LC_funclist + ul.LC_funclist {
8747: /*
8748: left border as a seperator if we have more than
8749: one list
8750: */
8751: border-left: 1px solid $sidebg;
8752: /*
8753: this hides the left border behind the border of the
8754: outer box if element is wrapped to the next 'line'
8755: */
8756: margin-left: -1px;
8757: }
8758:
1.843 bisitz 8759: ul.LC_funclist li {
1.915 droeschl 8760: display: inline;
1.782 bisitz 8761: white-space: nowrap;
1.915 droeschl 8762: margin: 0 0 0 25px;
8763: line-height: 150%;
1.782 bisitz 8764: }
8765:
1.974 wenzelju 8766: .LC_hidden {
8767: display: none;
8768: }
8769:
1.1030 www 8770: .LCmodal-overlay {
8771: position:fixed;
8772: top:0;
8773: right:0;
8774: bottom:0;
8775: left:0;
8776: height:100%;
8777: width:100%;
8778: margin:0;
8779: padding:0;
8780: background:#999;
8781: opacity:.75;
8782: filter: alpha(opacity=75);
8783: -moz-opacity: 0.75;
8784: z-index:101;
8785: }
8786:
8787: * html .LCmodal-overlay {
8788: position: absolute;
8789: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8790: }
8791:
8792: .LCmodal-window {
8793: position:fixed;
8794: top:50%;
8795: left:50%;
8796: margin:0;
8797: padding:0;
8798: z-index:102;
8799: }
8800:
8801: * html .LCmodal-window {
8802: position:absolute;
8803: }
8804:
8805: .LCclose-window {
8806: position:absolute;
8807: width:32px;
8808: height:32px;
8809: right:8px;
8810: top:8px;
8811: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8812: text-indent:-99999px;
8813: overflow:hidden;
8814: cursor:pointer;
8815: }
8816:
1.1369 raeburn 8817: .LCisDisabled {
8818: cursor: not-allowed;
8819: opacity: 0.5;
8820: }
8821:
8822: a[aria-disabled="true"] {
8823: color: currentColor;
8824: display: inline-block; /* For IE11/ MS Edge bug */
8825: pointer-events: none;
8826: text-decoration: none;
8827: }
8828:
1.1335 raeburn 8829: pre.LC_wordwrap {
8830: white-space: pre-wrap;
8831: white-space: -moz-pre-wrap;
8832: white-space: -pre-wrap;
8833: white-space: -o-pre-wrap;
8834: word-wrap: break-word;
8835: }
8836:
1.1100 raeburn 8837: /*
1.1231 damieng 8838: styles used for response display
8839: */
8840: div.LC_radiofoil, div.LC_rankfoil {
8841: margin: .5em 0em .5em 0em;
8842: }
8843: table.LC_itemgroup {
8844: margin-top: 1em;
8845: }
8846:
8847: /*
1.1100 raeburn 8848: styles used by TTH when "Default set of options to pass to tth/m
8849: when converting TeX" in course settings has been set
8850:
8851: option passed: -t
8852:
8853: */
8854:
8855: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8856: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8857: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8858: td div.norm {line-height:normal;}
8859:
8860: /*
8861: option passed -y3
8862: */
8863:
8864: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8865: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8866: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8867:
1.1230 damieng 8868: /*
8869: sections with roles, for content only
8870: */
8871: section[class^="role-"] {
8872: padding-left: 10px;
8873: padding-right: 5px;
8874: margin-top: 8px;
8875: margin-bottom: 8px;
8876: border: 1px solid #2A4;
8877: border-radius: 5px;
8878: box-shadow: 0px 1px 1px #BBB;
8879: }
8880: section[class^="role-"]>h1 {
8881: position: relative;
8882: margin: 0px;
8883: padding-top: 10px;
8884: padding-left: 40px;
8885: }
8886: section[class^="role-"]>h1:before {
8887: position: absolute;
8888: left: -5px;
8889: top: 5px;
8890: }
8891: section.role-activity>h1:before {
8892: content:url('/adm/daxe/images/section_icons/activity.png');
8893: }
8894: section.role-advice>h1:before {
8895: content:url('/adm/daxe/images/section_icons/advice.png');
8896: }
8897: section.role-bibliography>h1:before {
8898: content:url('/adm/daxe/images/section_icons/bibliography.png');
8899: }
8900: section.role-citation>h1:before {
8901: content:url('/adm/daxe/images/section_icons/citation.png');
8902: }
8903: section.role-conclusion>h1:before {
8904: content:url('/adm/daxe/images/section_icons/conclusion.png');
8905: }
8906: section.role-definition>h1:before {
8907: content:url('/adm/daxe/images/section_icons/definition.png');
8908: }
8909: section.role-demonstration>h1:before {
8910: content:url('/adm/daxe/images/section_icons/demonstration.png');
8911: }
8912: section.role-example>h1:before {
8913: content:url('/adm/daxe/images/section_icons/example.png');
8914: }
8915: section.role-explanation>h1:before {
8916: content:url('/adm/daxe/images/section_icons/explanation.png');
8917: }
8918: section.role-introduction>h1:before {
8919: content:url('/adm/daxe/images/section_icons/introduction.png');
8920: }
8921: section.role-method>h1:before {
8922: content:url('/adm/daxe/images/section_icons/method.png');
8923: }
8924: section.role-more_information>h1:before {
8925: content:url('/adm/daxe/images/section_icons/more_information.png');
8926: }
8927: section.role-objectives>h1:before {
8928: content:url('/adm/daxe/images/section_icons/objectives.png');
8929: }
8930: section.role-prerequisites>h1:before {
8931: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8932: }
8933: section.role-remark>h1:before {
8934: content:url('/adm/daxe/images/section_icons/remark.png');
8935: }
8936: section.role-reminder>h1:before {
8937: content:url('/adm/daxe/images/section_icons/reminder.png');
8938: }
8939: section.role-summary>h1:before {
8940: content:url('/adm/daxe/images/section_icons/summary.png');
8941: }
8942: section.role-syntax>h1:before {
8943: content:url('/adm/daxe/images/section_icons/syntax.png');
8944: }
8945: section.role-warning>h1:before {
8946: content:url('/adm/daxe/images/section_icons/warning.png');
8947: }
8948:
1.1269 raeburn 8949: #LC_minitab_header {
8950: float:left;
8951: width:100%;
8952: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8953: font-size:93%;
8954: line-height:normal;
8955: margin: 0.5em 0 0.5em 0;
8956: }
8957: #LC_minitab_header ul {
8958: margin:0;
8959: padding:10px 10px 0;
8960: list-style:none;
8961: }
8962: #LC_minitab_header li {
8963: float:left;
8964: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8965: margin:0;
8966: padding:0 0 0 9px;
8967: }
8968: #LC_minitab_header a {
8969: display:block;
8970: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8971: padding:5px 15px 4px 6px;
8972: }
8973: #LC_minitab_header #LC_current_minitab {
8974: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8975: }
8976: #LC_minitab_header #LC_current_minitab a {
8977: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8978: padding-bottom:5px;
8979: }
8980:
8981:
1.343 albertel 8982: END
8983: }
8984:
1.306 albertel 8985: =pod
8986:
8987: =item * &headtag()
8988:
8989: Returns a uniform footer for LON-CAPA web pages.
8990:
1.307 albertel 8991: Inputs: $title - optional title for the head
8992: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8993: $args - optional arguments
1.319 albertel 8994: force_register - if is true call registerurl so the remote is
8995: informed
1.415 albertel 8996: redirect -> array ref of
8997: 1- seconds before redirect occurs
8998: 2- url to redirect to
8999: 3- whether the side effect should occur
1.315 albertel 9000: (side effect of setting
9001: $env{'internal.head.redirect'} to the url
1.1386 raeburn 9002: redirected to)
9003: 4- whether the redirect target should be
9004: the opener of the current (pop-up)
9005: window (side effect of setting
9006: $env{'internal.head.to_opener'} to
9007: 1, if true.
1.1388 raeburn 9008: 5- whether encrypt check should be skipped
1.352 albertel 9009: domain -> force to color decorate a page for a specific
9010: domain
9011: function -> force usage of a specific rolish color scheme
9012: bgcolor -> override the default page bgcolor
1.460 albertel 9013: no_auto_mt_title
9014: -> prevent &mt()ing the title arg
1.464 albertel 9015:
1.306 albertel 9016: =cut
9017:
9018: sub headtag {
1.313 albertel 9019: my ($title,$head_extra,$args) = @_;
1.306 albertel 9020:
1.363 albertel 9021: my $function = $args->{'function'} || &get_users_function();
9022: my $domain = $args->{'domain'} || &determinedomain();
9023: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 9024: my $httphost = $args->{'use_absolute'};
1.418 albertel 9025: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 9026: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 9027: #time(),
1.418 albertel 9028: $env{'environment.color.timestamp'},
1.363 albertel 9029: $function,$domain,$bgcolor);
9030:
1.369 www 9031: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 9032:
1.308 albertel 9033: my $result =
9034: '<head>'.
1.1160 raeburn 9035: &font_settings($args);
1.319 albertel 9036:
1.1188 raeburn 9037: my $inhibitprint;
9038: if ($args->{'print_suppress'}) {
9039: $inhibitprint = &print_suppression();
9040: }
1.1064 raeburn 9041:
1.461 albertel 9042: if (!$args->{'frameset'}) {
9043: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
9044: }
1.962 droeschl 9045: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
9046: $result .= Apache::lonxml::display_title();
1.319 albertel 9047: }
1.436 albertel 9048: if (!$args->{'no_nav_bar'}
9049: && !$args->{'only_body'}
9050: && !$args->{'frameset'}) {
1.1154 raeburn 9051: $result .= &help_menu_js($httphost);
1.1032 www 9052: $result.=&modal_window();
1.1038 www 9053: $result.=&togglebox_script();
1.1034 www 9054: $result.=&wishlist_window();
1.1041 www 9055: $result.=&LCprogressbarUpdate_script();
1.1034 www 9056: } else {
9057: if ($args->{'add_modal'}) {
9058: $result.=&modal_window();
9059: }
9060: if ($args->{'add_wishlist'}) {
9061: $result.=&wishlist_window();
9062: }
1.1038 www 9063: if ($args->{'add_togglebox'}) {
9064: $result.=&togglebox_script();
9065: }
1.1041 www 9066: if ($args->{'add_progressbar'}) {
9067: $result.=&LCprogressbarUpdate_script();
9068: }
1.436 albertel 9069: }
1.314 albertel 9070: if (ref($args->{'redirect'})) {
1.1388 raeburn 9071: my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
9072: if (!$skip_enc_check) {
9073: $url = &Apache::lonenc::check_encrypt($url);
9074: }
1.414 albertel 9075: if (!$inhibit_continue) {
9076: $env{'internal.head.redirect'} = $url;
9077: }
1.1386 raeburn 9078: $result.=<<"ADDMETA";
1.313 albertel 9079: <meta http-equiv="pragma" content="no-cache" />
1.1386 raeburn 9080: ADDMETA
9081: if ($to_opener) {
9082: $env{'internal.head.to_opener'} = 1;
9083: my $dest = &js_escape($url);
9084: my $timeout = int($time * 1000);
9085: $result .=<<"ENDJS";
9086: <script type="text/javascript">
9087: // <![CDATA[
9088: function LC_To_Opener() {
9089: var dest = '$dest';
9090: if (dest != '') {
9091: if (window.opener != null && !window.opener.closed) {
9092: window.opener.location.href=dest;
9093: window.close();
9094: } else {
9095: window.location.href=dest;
9096: }
9097: }
9098: }
9099: \$(document).ready(function () {
9100: setTimeout('LC_To_Opener()',$timeout);
9101: });
9102: // ]]>
9103: </script>
9104: ENDJS
9105: } else {
9106: $result.=<<"ADDMETA";
1.344 albertel 9107: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 9108: ADDMETA
1.1386 raeburn 9109: }
1.1210 raeburn 9110: } else {
9111: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
9112: my $requrl = $env{'request.uri'};
9113: if ($requrl eq '') {
9114: $requrl = $ENV{'REQUEST_URI'};
9115: $requrl =~ s/\?.+$//;
9116: }
9117: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
9118: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
9119: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
9120: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
9121: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
9122: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 9123: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 9124: my ($offload,$offloadoth);
1.1210 raeburn 9125: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
9126: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 9127: $offload = 1;
1.1353 raeburn 9128: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9129: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9130: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9131: $offloadoth = 1;
9132: $dom_in_use = $env{'user.domain'};
9133: }
9134: }
1.1340 raeburn 9135: }
9136: }
9137: unless ($offload) {
9138: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
9139: if ($domdefs{'offloadoth'}{$lonhost}) {
9140: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9141: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9142: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9143: $offload = 1;
1.1352 raeburn 9144: $offloadoth = 1;
1.1340 raeburn 9145: $dom_in_use = $env{'user.domain'};
9146: }
1.1210 raeburn 9147: }
1.1340 raeburn 9148: }
9149: }
9150: }
9151: if ($offload) {
1.1358 raeburn 9152: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1352 raeburn 9153: if (($newserver eq '') && ($offloadoth)) {
9154: my @domains = &Apache::lonnet::current_machine_domains();
9155: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
9156: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
9157: }
9158: }
1.1340 raeburn 9159: if (($newserver) && ($newserver ne $lonhost)) {
9160: my $numsec = 5;
9161: my $timeout = $numsec * 1000;
9162: my ($newurl,$locknum,%locks,$msg);
9163: if ($env{'request.role.adv'}) {
9164: ($locknum,%locks) = &Apache::lonnet::get_locks();
9165: }
9166: my $disable_submit = 0;
9167: if ($requrl =~ /$LONCAPA::assess_re/) {
9168: $disable_submit = 1;
9169: }
9170: if ($locknum) {
9171: my @lockinfo = sort(values(%locks));
1.1354 raeburn 9172: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 9173: join(", ",sort(values(%locks)))."\n";
9174: if (&show_course()) {
9175: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
9176: } else {
9177: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 9178: }
1.1340 raeburn 9179: } else {
9180: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
9181: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
9182: }
9183: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
9184: $newurl = '/adm/switchserver?otherserver='.$newserver;
9185: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
9186: $newurl .= '&role='.$env{'request.role'};
9187: }
9188: if ($env{'request.symb'}) {
9189: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
9190: if ($shownsymb =~ m{^/enc/}) {
9191: my $reqdmajor = 2;
9192: my $reqdminor = 11;
9193: my $reqdsubminor = 3;
9194: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
9195: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
9196: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
9197: if (($major eq '' && $minor eq '') ||
9198: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
9199: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
9200: ($reqdsubminor > $subminor))))) {
9201: undef($shownsymb);
9202: }
1.1210 raeburn 9203: }
1.1340 raeburn 9204: if ($shownsymb) {
9205: &js_escape(\$shownsymb);
9206: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 9207: }
1.1340 raeburn 9208: } else {
9209: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
9210: &js_escape(\$shownurl);
9211: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 9212: }
1.1340 raeburn 9213: }
9214: &js_escape(\$msg);
9215: $result.=<<OFFLOAD
1.1210 raeburn 9216: <meta http-equiv="pragma" content="no-cache" />
9217: <script type="text/javascript">
1.1215 raeburn 9218: // <![CDATA[
1.1210 raeburn 9219: function LC_Offload_Now() {
9220: var dest = "$newurl";
9221: if (dest != '') {
9222: window.location.href="$newurl";
9223: }
9224: }
1.1214 raeburn 9225: \$(document).ready(function () {
9226: window.alert('$msg');
9227: if ($disable_submit) {
1.1210 raeburn 9228: \$(".LC_hwk_submit").prop("disabled", true);
9229: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 9230: }
9231: setTimeout('LC_Offload_Now()', $timeout);
9232: });
1.1215 raeburn 9233: // ]]>
1.1210 raeburn 9234: </script>
9235: OFFLOAD
9236: }
9237: }
9238: }
9239: }
9240: }
1.313 albertel 9241: }
1.306 albertel 9242: if (!defined($title)) {
9243: $title = 'The LearningOnline Network with CAPA';
9244: }
1.460 albertel 9245: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
9246: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 9247: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
9248: if (!$args->{'frameset'}) {
9249: $result .= ' /';
9250: }
9251: $result .= '>'
1.1064 raeburn 9252: .$inhibitprint
1.414 albertel 9253: .$head_extra;
1.1242 raeburn 9254: my $clientmobile;
9255: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
9256: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
9257: } else {
9258: $clientmobile = $env{'browser.mobile'};
9259: }
9260: if ($clientmobile) {
1.1137 raeburn 9261: $result .= '
9262: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
9263: <meta name="apple-mobile-web-app-capable" content="yes" />';
9264: }
1.1278 raeburn 9265: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 9266: return $result.'</head>';
1.306 albertel 9267: }
9268:
9269: =pod
9270:
1.340 albertel 9271: =item * &font_settings()
9272:
9273: Returns neccessary <meta> to set the proper encoding
9274:
1.1160 raeburn 9275: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 9276:
9277: =cut
9278:
9279: sub font_settings {
1.1160 raeburn 9280: my ($args) = @_;
1.340 albertel 9281: my $headerstring='';
1.1160 raeburn 9282: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
9283: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 9284: $headerstring.=
9285: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
9286: if (!$args->{'frameset'}) {
9287: $headerstring.= ' /';
9288: }
9289: $headerstring .= '>'."\n";
1.340 albertel 9290: }
9291: return $headerstring;
9292: }
9293:
1.341 albertel 9294: =pod
9295:
1.1064 raeburn 9296: =item * &print_suppression()
9297:
9298: In course context returns css which causes the body to be blank when media="print",
9299: if printout generation is unavailable for the current resource.
9300:
9301: This could be because:
9302:
9303: (a) printstartdate is in the future
9304:
9305: (b) printenddate is in the past
9306:
9307: (c) there is an active exam block with "printout"
9308: functionality blocked
9309:
9310: Users with pav, pfo or evb privileges are exempt.
9311:
9312: Inputs: none
9313:
9314: =cut
9315:
9316:
9317: sub print_suppression {
9318: my $noprint;
9319: if ($env{'request.course.id'}) {
9320: my $scope = $env{'request.course.id'};
9321: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9322: (&Apache::lonnet::allowed('pfo',$scope))) {
9323: return;
9324: }
9325: if ($env{'request.course.sec'} ne '') {
9326: $scope .= "/$env{'request.course.sec'}";
9327: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9328: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 9329: return;
1.1064 raeburn 9330: }
9331: }
9332: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9333: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 9334: my $clientip = &Apache::lonnet::get_requestor_ip();
9335: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 9336: if ($blocked) {
9337: my $checkrole = "cm./$cdom/$cnum";
9338: if ($env{'request.course.sec'} ne '') {
9339: $checkrole .= "/$env{'request.course.sec'}";
9340: }
9341: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
9342: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
9343: $noprint = 1;
9344: }
9345: }
9346: unless ($noprint) {
9347: my $symb = &Apache::lonnet::symbread();
9348: if ($symb ne '') {
9349: my $navmap = Apache::lonnavmaps::navmap->new();
9350: if (ref($navmap)) {
9351: my $res = $navmap->getBySymb($symb);
9352: if (ref($res)) {
9353: if (!$res->resprintable()) {
9354: $noprint = 1;
9355: }
9356: }
9357: }
9358: }
9359: }
9360: if ($noprint) {
9361: return <<"ENDSTYLE";
9362: <style type="text/css" media="print">
9363: body { display:none }
9364: </style>
9365: ENDSTYLE
9366: }
9367: }
9368: return;
9369: }
9370:
9371: =pod
9372:
1.341 albertel 9373: =item * &xml_begin()
9374:
9375: Returns the needed doctype and <html>
9376:
9377: Inputs: none
9378:
9379: =cut
9380:
9381: sub xml_begin {
1.1168 raeburn 9382: my ($is_frameset) = @_;
1.341 albertel 9383: my $output='';
9384:
9385: if ($env{'browser.mathml'}) {
9386: $output='<?xml version="1.0"?>'
9387: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9388: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9389:
9390: # .'<!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">] >'
9391: .'<!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">'
9392: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9393: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 9394: } elsif ($is_frameset) {
9395: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
9396: '<html>'."\n";
1.341 albertel 9397: } else {
1.1168 raeburn 9398: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9399: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9400: }
9401: return $output;
9402: }
1.340 albertel 9403:
9404: =pod
9405:
1.306 albertel 9406: =item * &start_page()
9407:
9408: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9409:
1.648 raeburn 9410: Inputs:
9411:
9412: =over 4
9413:
9414: $title - optional title for the page
9415:
9416: $head_extra - optional extra HTML to incude inside the <head>
9417:
9418: $args - additional optional args supported are:
9419:
9420: =over 8
9421:
9422: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 9423: arg on
1.814 bisitz 9424: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 9425: add_entries -> additional attributes to add to the <body>
9426: domain -> force to color decorate a page for a
1.317 albertel 9427: specific domain
1.648 raeburn 9428: function -> force usage of a specific rolish color
1.317 albertel 9429: scheme
1.648 raeburn 9430: redirect -> see &headtag()
9431: bgcolor -> override the default page bg color
9432: js_ready -> return a string ready for being used in
1.317 albertel 9433: a javascript writeln
1.648 raeburn 9434: html_encode -> return a string ready for being used in
1.320 albertel 9435: a html attribute
1.648 raeburn 9436: force_register -> if is true will turn on the &bodytag()
1.317 albertel 9437: $forcereg arg
1.648 raeburn 9438: frameset -> if true will start with a <frameset>
1.330 albertel 9439: rather than <body>
1.648 raeburn 9440: skip_phases -> hash ref of
1.338 albertel 9441: head -> skip the <html><head> generation
9442: body -> skip all <body> generation
1.648 raeburn 9443: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 9444: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 9445: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 9446: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
9447: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 9448: group -> includes the current group, if page is for a
1.1274 raeburn 9449: specific group
9450: use_absolute -> for request for external resource or syllabus, this
9451: will contain https://<hostname> if server uses
9452: https (as per hosts.tab), but request is for http
9453: hostname -> hostname, originally from $r->hostname(), (optional).
1.1369 raeburn 9454: links_disabled -> Links in primary and secondary menus are disabled
9455: (Can enable them once page has loaded - see lonroles.pm
9456: for an example).
1.1380 raeburn 9457: links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 9458:
1.648 raeburn 9459: =back
1.460 albertel 9460:
1.648 raeburn 9461: =back
1.562 albertel 9462:
1.306 albertel 9463: =cut
9464:
9465: sub start_page {
1.309 albertel 9466: my ($title,$head_extra,$args) = @_;
1.318 albertel 9467: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 9468:
1.315 albertel 9469: $env{'internal.start_page'}++;
1.1359 raeburn 9470: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 9471:
1.338 albertel 9472: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 9473: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 9474: }
1.1316 raeburn 9475:
9476: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 9477: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
9478: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
9479: $args->{'no_primary_menu'} = 1;
9480: }
9481: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
9482: $args->{'no_inline_menu'} = 1;
9483: }
9484: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
9485: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
9486: }
9487: } else {
9488: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9489: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
9490: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
9491: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
9492: $args->{'no_primary_menu'} = 1;
9493: }
9494: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
9495: $args->{'no_inline_menu'} = 1;
9496: }
9497: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
9498: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
9499: }
9500: }
9501: }
1.1316 raeburn 9502: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
9503: $env{'course.'.$env{'request.course.id'}.'.domain'},
9504: $env{'course.'.$env{'request.course.id'}.'.num'});
1.1359 raeburn 9505: } elsif ($env{'request.course.id'}) {
9506: my $expiretime=600;
9507: if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
9508: &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
9509: }
9510: my ($deeplinkmenu,$menuref);
9511: ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
9512: if ($menucoll) {
9513: if (ref($menuref) eq 'HASH') {
9514: %menu = %{$menuref};
9515: }
9516: if ($menu{'top'} eq 'n') {
9517: $args->{'no_primary_menu'} = 1;
9518: }
9519: if ($menu{'inline'} eq 'n') {
9520: unless (&Apache::lonnet::allowed('opa')) {
9521: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9522: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9523: my $crstype = &course_type();
9524: my $now = time;
9525: my $ccrole;
9526: if ($crstype eq 'Community') {
9527: $ccrole = 'co';
9528: } else {
9529: $ccrole = 'cc';
9530: }
9531: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
9532: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
9533: if ((($start) && ($start<0)) ||
9534: (($end) && ($end<$now)) ||
9535: (($start) && ($now<$start))) {
9536: $args->{'no_inline_menu'} = 1;
9537: }
9538: } else {
9539: $args->{'no_inline_menu'} = 1;
9540: }
9541: }
9542: }
9543: }
1.1316 raeburn 9544: }
1.1359 raeburn 9545:
1.1385 raeburn 9546: my $showncrumbs;
1.338 albertel 9547: if (! exists($args->{'skip_phases'}{'body'}) ) {
9548: if ($args->{'frameset'}) {
9549: my $attr_string = &make_attr_string($args->{'force_register'},
9550: $args->{'add_entries'});
9551: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9552: } else {
9553: $result .=
9554: &bodytag($title,
9555: $args->{'function'}, $args->{'add_entries'},
9556: $args->{'only_body'}, $args->{'domain'},
9557: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 9558: $args->{'bgcolor'}, $args,
1.1385 raeburn 9559: \@advtools,$ltiscope,$ltiuri,\%ltimenu,$menucoll,
9560: \%menu,\$showncrumbs);
1.831 bisitz 9561: }
1.330 albertel 9562: }
1.338 albertel 9563:
1.315 albertel 9564: if ($args->{'js_ready'}) {
1.713 kaisler 9565: $result = &js_ready($result);
1.315 albertel 9566: }
1.320 albertel 9567: if ($args->{'html_encode'}) {
1.713 kaisler 9568: $result = &html_encode($result);
9569: }
9570:
1.813 bisitz 9571: # Preparation for new and consistent functionlist at top of screen
9572: # if ($args->{'functionlist'}) {
9573: # $result .= &build_functionlist();
9574: #}
9575:
1.964 droeschl 9576: # Don't add anything more if only_body wanted or in const space
9577: return $result if $args->{'only_body'}
9578: || $env{'request.state'} eq 'construct';
1.813 bisitz 9579:
9580: #Breadcrumbs
1.758 kaisler 9581: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1385 raeburn 9582: unless ($showncrumbs) {
1.758 kaisler 9583: &Apache::lonhtmlcommon::clear_breadcrumbs();
9584: #if any br links exists, add them to the breadcrumbs
9585: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9586: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9587: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9588: }
9589: }
1.1096 raeburn 9590: # if @advtools array contains items add then to the breadcrumbs
9591: if (@advtools > 0) {
9592: &Apache::lonmenu::advtools_crumbs(@advtools);
9593: }
1.1272 raeburn 9594: my $menulink;
9595: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
9596: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 9597: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 9598: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
9599: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
9600: (!$env{'request.role.adv'}))) {
9601: $menulink = 0;
9602: } else {
9603: undef($menulink);
9604: }
1.1385 raeburn 9605: my $linkprotout;
9606: if ($env{'request.deeplink.login'}) {
9607: my $linkprotout = &Apache::lonmenu::linkprot_exit();
9608: if ($linkprotout) {
9609: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
9610: }
9611: }
1.758 kaisler 9612: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9613: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 9614: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 9615: } else {
1.1272 raeburn 9616: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9617: }
1.1385 raeburn 9618: }
1.320 albertel 9619: }
1.315 albertel 9620: return $result;
1.306 albertel 9621: }
9622:
9623: sub end_page {
1.315 albertel 9624: my ($args) = @_;
9625: $env{'internal.end_page'}++;
1.330 albertel 9626: my $result;
1.335 albertel 9627: if ($args->{'discussion'}) {
9628: my ($target,$parser);
9629: if (ref($args->{'discussion'})) {
9630: ($target,$parser) =($args->{'discussion'}{'target'},
9631: $args->{'discussion'}{'parser'});
9632: }
9633: $result .= &Apache::lonxml::xmlend($target,$parser);
9634: }
1.330 albertel 9635: if ($args->{'frameset'}) {
9636: $result .= '</frameset>';
9637: } else {
1.635 raeburn 9638: $result .= &endbodytag($args);
1.330 albertel 9639: }
1.1080 raeburn 9640: unless ($args->{'notbody'}) {
9641: $result .= "\n</html>";
9642: }
1.330 albertel 9643:
1.315 albertel 9644: if ($args->{'js_ready'}) {
1.317 albertel 9645: $result = &js_ready($result);
1.315 albertel 9646: }
1.335 albertel 9647:
1.320 albertel 9648: if ($args->{'html_encode'}) {
9649: $result = &html_encode($result);
9650: }
1.335 albertel 9651:
1.315 albertel 9652: return $result;
9653: }
9654:
1.1359 raeburn 9655: sub menucoll_in_effect {
9656: my ($menucoll,$deeplinkmenu,%menu);
9657: if ($env{'request.course.id'}) {
9658: $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
1.1362 raeburn 9659: if ($env{'request.deeplink.login'}) {
1.1370 raeburn 9660: my ($deeplink_symb,$deeplink,$check_login_symb);
1.1362 raeburn 9661: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9662: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9663: if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9664: if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9665: my $navmap = Apache::lonnavmaps::navmap->new();
9666: if (ref($navmap)) {
9667: $deeplink = $navmap->get_mapparam(undef,
9668: &Apache::lonnet::declutter($env{'request.noversionuri'}),
9669: '0.deeplink');
1.1370 raeburn 9670: } else {
9671: $check_login_symb = 1;
1.1362 raeburn 9672: }
9673: } else {
1.1370 raeburn 9674: my $symb = &Apache::lonnet::symbread();
9675: if ($symb) {
9676: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9677: } else {
9678: $check_login_symb = 1;
9679: }
1.1362 raeburn 9680: }
9681: } else {
1.1370 raeburn 9682: $check_login_symb = 1;
9683: }
9684: if ($check_login_symb) {
1.1362 raeburn 9685: $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9686: if ($deeplink_symb =~ /\.(page|sequence)$/) {
9687: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9688: my $navmap = Apache::lonnavmaps::navmap->new();
9689: if (ref($navmap)) {
9690: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9691: }
9692: } else {
9693: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9694: }
9695: }
1.1359 raeburn 9696: if ($deeplink ne '') {
1.1378 raeburn 9697: my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
1.1359 raeburn 9698: if ($display =~ /^\d+$/) {
9699: $deeplinkmenu = 1;
9700: $menucoll = $display;
9701: }
9702: }
9703: }
9704: if ($menucoll) {
9705: %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9706: }
9707: }
9708: return ($menucoll,$deeplinkmenu,\%menu);
9709: }
9710:
1.1362 raeburn 9711: sub deeplink_login_symb {
9712: my ($cnum,$cdom) = @_;
9713: my $login_symb;
9714: if ($env{'request.deeplink.login'}) {
1.1364 raeburn 9715: $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9716: }
9717: return $login_symb;
9718: }
9719:
9720: sub symb_from_tinyurl {
9721: my ($url,$cnum,$cdom) = @_;
9722: if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9723: my $key = $1;
9724: my ($tinyurl,$login);
9725: my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9726: if (defined($cached)) {
9727: $tinyurl = $result;
9728: } else {
9729: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9730: my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9731: if ($currtiny{$key} ne '') {
9732: $tinyurl = $currtiny{$key};
9733: &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
1.1362 raeburn 9734: }
1.1364 raeburn 9735: }
9736: if ($tinyurl ne '') {
9737: my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9738: if (wantarray) {
9739: return ($cnumreq,$symb);
9740: } elsif ($cnumreq eq $cnum) {
9741: return $symb;
1.1362 raeburn 9742: }
9743: }
9744: }
1.1364 raeburn 9745: if (wantarray) {
9746: return ();
9747: } else {
9748: return;
9749: }
1.1362 raeburn 9750: }
9751:
1.1034 www 9752: sub wishlist_window {
9753: return(<<'ENDWISHLIST');
1.1046 raeburn 9754: <script type="text/javascript">
1.1034 www 9755: // <![CDATA[
9756: // <!-- BEGIN LON-CAPA Internal
9757: function set_wishlistlink(title, path) {
9758: if (!title) {
9759: title = document.title;
9760: title = title.replace(/^LON-CAPA /,'');
9761: }
1.1175 raeburn 9762: title = encodeURIComponent(title);
1.1203 raeburn 9763: title = title.replace("'","\\\'");
1.1034 www 9764: if (!path) {
9765: path = location.pathname;
9766: }
1.1175 raeburn 9767: path = encodeURIComponent(path);
1.1203 raeburn 9768: path = path.replace("'","\\\'");
1.1034 www 9769: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9770: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9771: }
9772: // END LON-CAPA Internal -->
9773: // ]]>
9774: </script>
9775: ENDWISHLIST
9776: }
9777:
1.1030 www 9778: sub modal_window {
9779: return(<<'ENDMODAL');
1.1046 raeburn 9780: <script type="text/javascript">
1.1030 www 9781: // <![CDATA[
9782: // <!-- BEGIN LON-CAPA Internal
9783: var modalWindow = {
9784: parent:"body",
9785: windowId:null,
9786: content:null,
9787: width:null,
9788: height:null,
9789: close:function()
9790: {
9791: $(".LCmodal-window").remove();
9792: $(".LCmodal-overlay").remove();
9793: },
9794: open:function()
9795: {
9796: var modal = "";
9797: modal += "<div class=\"LCmodal-overlay\"></div>";
9798: 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;\">";
9799: modal += this.content;
9800: modal += "</div>";
9801:
9802: $(this.parent).append(modal);
9803:
9804: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9805: $(".LCclose-window").click(function(){modalWindow.close();});
9806: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9807: }
9808: };
1.1140 raeburn 9809: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9810: {
1.1266 raeburn 9811: source = source.replace(/'/g,"'");
1.1030 www 9812: modalWindow.windowId = "myModal";
9813: modalWindow.width = width;
9814: modalWindow.height = height;
1.1196 raeburn 9815: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9816: modalWindow.open();
1.1208 raeburn 9817: };
1.1030 www 9818: // END LON-CAPA Internal -->
9819: // ]]>
9820: </script>
9821: ENDMODAL
9822: }
9823:
9824: sub modal_link {
1.1140 raeburn 9825: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9826: unless ($width) { $width=480; }
9827: unless ($height) { $height=400; }
1.1031 www 9828: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9829: unless ($transparency) { $transparency='true'; }
9830:
1.1074 raeburn 9831: my $target_attr;
9832: if (defined($target)) {
9833: $target_attr = 'target="'.$target.'"';
9834: }
9835: return <<"ENDLINK";
1.1336 raeburn 9836: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9837: ENDLINK
1.1030 www 9838: }
9839:
1.1032 www 9840: sub modal_adhoc_script {
1.1365 raeburn 9841: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9842: my $mathjax;
9843: if ($possmathjax) {
9844: $mathjax = <<'ENDJAX';
9845: if (typeof MathJax == 'object') {
9846: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9847: }
9848: ENDJAX
9849: }
1.1032 www 9850: return (<<ENDADHOC);
1.1046 raeburn 9851: <script type="text/javascript">
1.1032 www 9852: // <![CDATA[
9853: var $funcname = function()
9854: {
9855: modalWindow.windowId = "myModal";
9856: modalWindow.width = $width;
9857: modalWindow.height = $height;
9858: modalWindow.content = '$content';
9859: modalWindow.open();
1.1365 raeburn 9860: $mathjax
1.1032 www 9861: };
9862: // ]]>
9863: </script>
9864: ENDADHOC
9865: }
9866:
1.1041 www 9867: sub modal_adhoc_inner {
1.1365 raeburn 9868: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 9869: my $innerwidth=$width-20;
9870: $content=&js_ready(
1.1140 raeburn 9871: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9872: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9873: $content.
1.1041 www 9874: &end_scrollbox().
1.1140 raeburn 9875: &end_page()
1.1041 www 9876: );
1.1365 raeburn 9877: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 9878: }
9879:
9880: sub modal_adhoc_window {
1.1365 raeburn 9881: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
9882: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 9883: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9884: }
9885:
9886: sub modal_adhoc_launch {
9887: my ($funcname,$width,$height,$content)=@_;
9888: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9889: <script type="text/javascript">
9890: // <![CDATA[
9891: $funcname();
9892: // ]]>
9893: </script>
9894: ENDLAUNCH
9895: }
9896:
9897: sub modal_adhoc_close {
9898: return (<<ENDCLOSE);
9899: <script type="text/javascript">
9900: // <![CDATA[
9901: modalWindow.close();
9902: // ]]>
9903: </script>
9904: ENDCLOSE
9905: }
9906:
1.1038 www 9907: sub togglebox_script {
9908: return(<<ENDTOGGLE);
9909: <script type="text/javascript">
9910: // <![CDATA[
9911: function LCtoggleDisplay(id,hidetext,showtext) {
9912: link = document.getElementById(id + "link").childNodes[0];
9913: with (document.getElementById(id).style) {
9914: if (display == "none" ) {
9915: display = "inline";
9916: link.nodeValue = hidetext;
9917: } else {
9918: display = "none";
9919: link.nodeValue = showtext;
9920: }
9921: }
9922: }
9923: // ]]>
9924: </script>
9925: ENDTOGGLE
9926: }
9927:
1.1039 www 9928: sub start_togglebox {
9929: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9930: unless ($heading) { $heading=''; } else { $heading.=' '; }
9931: unless ($showtext) { $showtext=&mt('show'); }
9932: unless ($hidetext) { $hidetext=&mt('hide'); }
9933: unless ($headerbg) { $headerbg='#FFFFFF'; }
9934: return &start_data_table().
9935: &start_data_table_header_row().
9936: '<td bgcolor="'.$headerbg.'">'.$heading.
9937: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9938: $showtext.'\')">'.$showtext.'</a>]</td>'.
9939: &end_data_table_header_row().
9940: '<tr id="'.$id.'" style="display:none""><td>';
9941: }
9942:
9943: sub end_togglebox {
9944: return '</td></tr>'.&end_data_table();
9945: }
9946:
1.1041 www 9947: sub LCprogressbar_script {
1.1302 raeburn 9948: my ($id,$number_to_do)=@_;
9949: if ($number_to_do) {
9950: return(<<ENDPROGRESS);
1.1041 www 9951: <script type="text/javascript">
9952: // <![CDATA[
1.1045 www 9953: \$('#progressbar$id').progressbar({
1.1041 www 9954: value: 0,
9955: change: function(event, ui) {
9956: var newVal = \$(this).progressbar('option', 'value');
9957: \$('.pblabel', this).text(LCprogressTxt);
9958: }
9959: });
9960: // ]]>
9961: </script>
9962: ENDPROGRESS
1.1302 raeburn 9963: } else {
9964: return(<<ENDPROGRESS);
9965: <script type="text/javascript">
9966: // <![CDATA[
9967: \$('#progressbar$id').progressbar({
9968: value: false,
9969: create: function(event, ui) {
9970: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9971: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9972: }
9973: });
9974: // ]]>
9975: </script>
9976: ENDPROGRESS
9977: }
1.1041 www 9978: }
9979:
9980: sub LCprogressbarUpdate_script {
9981: return(<<ENDPROGRESSUPDATE);
9982: <style type="text/css">
9983: .ui-progressbar { position:relative; }
1.1302 raeburn 9984: .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 9985: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9986: </style>
9987: <script type="text/javascript">
9988: // <![CDATA[
1.1045 www 9989: var LCprogressTxt='---';
9990:
1.1302 raeburn 9991: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9992: LCprogressTxt=progresstext;
1.1302 raeburn 9993: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9994: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9995: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9996: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9997: } else {
9998: \$('#progressbar'+id).progressbar('value',percent);
9999: }
1.1041 www 10000: }
10001: // ]]>
10002: </script>
10003: ENDPROGRESSUPDATE
10004: }
10005:
1.1042 www 10006: my $LClastpercent;
1.1045 www 10007: my $LCidcnt;
10008: my $LCcurrentid;
1.1042 www 10009:
1.1041 www 10010: sub LCprogressbar {
1.1302 raeburn 10011: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 10012: $LClastpercent=0;
1.1045 www 10013: $LCidcnt++;
10014: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 10015: my ($starting,$content);
10016: if ($number_to_do) {
10017: $starting=&mt('Starting');
10018: $content=(<<ENDPROGBAR);
10019: $preamble
1.1045 www 10020: <div id="progressbar$LCcurrentid">
1.1041 www 10021: <span class="pblabel">$starting</span>
10022: </div>
10023: ENDPROGBAR
1.1302 raeburn 10024: } else {
10025: $starting=&mt('Loading...');
10026: $LClastpercent='false';
10027: $content=(<<ENDPROGBAR);
10028: $preamble
10029: <div id="progressbar$LCcurrentid">
10030: <div class="progress-label">$starting</div>
10031: </div>
10032: ENDPROGBAR
10033: }
10034: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 10035: }
10036:
10037: sub LCprogressbarUpdate {
1.1302 raeburn 10038: my ($r,$val,$text,$number_to_do)=@_;
10039: if ($number_to_do) {
10040: unless ($val) {
10041: if ($LClastpercent) {
10042: $val=$LClastpercent;
10043: } else {
10044: $val=0;
10045: }
10046: }
10047: if ($val<0) { $val=0; }
10048: if ($val>100) { $val=0; }
10049: $LClastpercent=$val;
10050: unless ($text) { $text=$val.'%'; }
10051: } else {
10052: $val = 'false';
1.1042 www 10053: }
1.1041 www 10054: $text=&js_ready($text);
1.1044 www 10055: &r_print($r,<<ENDUPDATE);
1.1041 www 10056: <script type="text/javascript">
10057: // <![CDATA[
1.1302 raeburn 10058: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 10059: // ]]>
10060: </script>
10061: ENDUPDATE
1.1035 www 10062: }
10063:
1.1042 www 10064: sub LCprogressbarClose {
10065: my ($r)=@_;
10066: $LClastpercent=0;
1.1044 www 10067: &r_print($r,<<ENDCLOSE);
1.1042 www 10068: <script type="text/javascript">
10069: // <![CDATA[
1.1045 www 10070: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 10071: // ]]>
10072: </script>
10073: ENDCLOSE
1.1044 www 10074: }
10075:
10076: sub r_print {
10077: my ($r,$to_print)=@_;
10078: if ($r) {
10079: $r->print($to_print);
10080: $r->rflush();
10081: } else {
10082: print($to_print);
10083: }
1.1042 www 10084: }
10085:
1.320 albertel 10086: sub html_encode {
10087: my ($result) = @_;
10088:
1.322 albertel 10089: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 10090:
10091: return $result;
10092: }
1.1044 www 10093:
1.317 albertel 10094: sub js_ready {
10095: my ($result) = @_;
10096:
1.323 albertel 10097: $result =~ s/[\n\r]/ /xmsg;
10098: $result =~ s/\\/\\\\/xmsg;
10099: $result =~ s/'/\\'/xmsg;
1.372 albertel 10100: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 10101:
10102: return $result;
10103: }
10104:
1.315 albertel 10105: sub validate_page {
10106: if ( exists($env{'internal.start_page'})
1.316 albertel 10107: && $env{'internal.start_page'} > 1) {
10108: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 10109: $env{'internal.start_page'}.' '.
1.316 albertel 10110: $ENV{'request.filename'});
1.315 albertel 10111: }
10112: if ( exists($env{'internal.end_page'})
1.316 albertel 10113: && $env{'internal.end_page'} > 1) {
10114: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 10115: $env{'internal.end_page'}.' '.
1.316 albertel 10116: $env{'request.filename'});
1.315 albertel 10117: }
10118: if ( exists($env{'internal.start_page'})
10119: && ! exists($env{'internal.end_page'})) {
1.316 albertel 10120: &Apache::lonnet::logthis('start_page called without end_page '.
10121: $env{'request.filename'});
1.315 albertel 10122: }
10123: if ( ! exists($env{'internal.start_page'})
10124: && exists($env{'internal.end_page'})) {
1.316 albertel 10125: &Apache::lonnet::logthis('end_page called without start_page'.
10126: $env{'request.filename'});
1.315 albertel 10127: }
1.306 albertel 10128: }
1.315 albertel 10129:
1.996 www 10130:
10131: sub start_scrollbox {
1.1140 raeburn 10132: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 10133: unless ($outerwidth) { $outerwidth='520px'; }
10134: unless ($width) { $width='500px'; }
10135: unless ($height) { $height='200px'; }
1.1075 raeburn 10136: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 10137: if ($id ne '') {
1.1140 raeburn 10138: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 10139: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 10140: }
1.1075 raeburn 10141: if ($bgcolor ne '') {
10142: $tdcol = "background-color: $bgcolor;";
10143: }
1.1137 raeburn 10144: my $nicescroll_js;
10145: if ($env{'browser.mobile'}) {
1.1140 raeburn 10146: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
10147: }
10148: return <<"END";
10149: $nicescroll_js
10150:
10151: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
10152: <div style="overflow:auto; width:$width; height:$height;"$div_id>
10153: END
10154: }
10155:
10156: sub end_scrollbox {
10157: return '</div></td></tr></table>';
10158: }
10159:
10160: sub nicescroll_javascript {
10161: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
10162: my %options;
10163: if (ref($cursor) eq 'HASH') {
10164: %options = %{$cursor};
10165: }
10166: unless ($options{'railalign'} =~ /^left|right$/) {
10167: $options{'railalign'} = 'left';
10168: }
10169: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10170: my $function = &get_users_function();
10171: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 10172: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 10173: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 10174: }
1.1140 raeburn 10175: }
10176: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
10177: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 10178: $options{'cursoropacity'}='1.0';
10179: }
1.1140 raeburn 10180: } else {
10181: $options{'cursoropacity'}='1.0';
10182: }
10183: if ($options{'cursorfixedheight'} eq 'none') {
10184: delete($options{'cursorfixedheight'});
10185: } else {
10186: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
10187: }
10188: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
10189: delete($options{'railoffset'});
10190: }
10191: my @niceoptions;
10192: while (my($key,$value) = each(%options)) {
10193: if ($value =~ /^\{.+\}$/) {
10194: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 10195: } else {
1.1140 raeburn 10196: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 10197: }
1.1140 raeburn 10198: }
10199: my $nicescroll_js = '
1.1137 raeburn 10200: $(document).ready(
1.1140 raeburn 10201: function() {
10202: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
10203: }
1.1137 raeburn 10204: );
10205: ';
1.1140 raeburn 10206: if ($framecheck) {
10207: $nicescroll_js .= '
10208: function expand_div(caller) {
10209: if (top === self) {
10210: document.getElementById("'.$id.'").style.width = "auto";
10211: document.getElementById("'.$id.'").style.height = "auto";
10212: } else {
10213: try {
10214: if (parent.frames) {
10215: if (parent.frames.length > 1) {
10216: var framesrc = parent.frames[1].location.href;
10217: var currsrc = framesrc.replace(/\#.*$/,"");
10218: if ((caller == "search") || (currsrc == "'.$location.'")) {
10219: document.getElementById("'.$id.'").style.width = "auto";
10220: document.getElementById("'.$id.'").style.height = "auto";
10221: }
10222: }
10223: }
10224: } catch (e) {
10225: return;
10226: }
1.1137 raeburn 10227: }
1.1140 raeburn 10228: return;
1.996 www 10229: }
1.1140 raeburn 10230: ';
10231: }
10232: if ($needjsready) {
10233: $nicescroll_js = '
10234: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
10235: } else {
10236: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
10237: }
10238: return $nicescroll_js;
1.996 www 10239: }
10240:
1.318 albertel 10241: sub simple_error_page {
1.1150 bisitz 10242: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 10243: my %displayargs;
1.1151 raeburn 10244: if (ref($args) eq 'HASH') {
10245: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 10246: if ($args->{'only_body'}) {
10247: $displayargs{'only_body'} = 1;
10248: }
10249: if ($args->{'no_nav_bar'}) {
10250: $displayargs{'no_nav_bar'} = 1;
10251: }
1.1151 raeburn 10252: } else {
10253: $msg = &mt($msg);
10254: }
1.1150 bisitz 10255:
1.318 albertel 10256: my $page =
1.1304 raeburn 10257: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 10258: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 10259: &Apache::loncommon::end_page();
10260: if (ref($r)) {
10261: $r->print($page);
1.327 albertel 10262: return;
1.318 albertel 10263: }
10264: return $page;
10265: }
1.347 albertel 10266:
10267: {
1.610 albertel 10268: my @row_count;
1.961 onken 10269:
10270: sub start_data_table_count {
10271: unshift(@row_count, 0);
10272: return;
10273: }
10274:
10275: sub end_data_table_count {
10276: shift(@row_count);
10277: return;
10278: }
10279:
1.347 albertel 10280: sub start_data_table {
1.1018 raeburn 10281: my ($add_class,$id) = @_;
1.422 albertel 10282: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 10283: my $table_id;
10284: if (defined($id)) {
10285: $table_id = ' id="'.$id.'"';
10286: }
1.961 onken 10287: &start_data_table_count();
1.1018 raeburn 10288: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 10289: }
10290:
10291: sub end_data_table {
1.961 onken 10292: &end_data_table_count();
1.389 albertel 10293: return '</table>'."\n";;
1.347 albertel 10294: }
10295:
10296: sub start_data_table_row {
1.974 wenzelju 10297: my ($add_class, $id) = @_;
1.610 albertel 10298: $row_count[0]++;
10299: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 10300: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 10301: $id = (' id="'.$id.'"') unless ($id eq '');
10302: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 10303: }
1.471 banghart 10304:
10305: sub continue_data_table_row {
1.974 wenzelju 10306: my ($add_class, $id) = @_;
1.610 albertel 10307: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 10308: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10309: $id = (' id="'.$id.'"') unless ($id eq '');
10310: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 10311: }
1.347 albertel 10312:
10313: sub end_data_table_row {
1.389 albertel 10314: return '</tr>'."\n";;
1.347 albertel 10315: }
1.367 www 10316:
1.421 albertel 10317: sub start_data_table_empty_row {
1.707 bisitz 10318: # $row_count[0]++;
1.421 albertel 10319: return '<tr class="LC_empty_row" >'."\n";;
10320: }
10321:
10322: sub end_data_table_empty_row {
10323: return '</tr>'."\n";;
10324: }
10325:
1.367 www 10326: sub start_data_table_header_row {
1.389 albertel 10327: return '<tr class="LC_header_row">'."\n";;
1.367 www 10328: }
10329:
10330: sub end_data_table_header_row {
1.389 albertel 10331: return '</tr>'."\n";;
1.367 www 10332: }
1.890 droeschl 10333:
10334: sub data_table_caption {
10335: my $caption = shift;
10336: return "<caption class=\"LC_caption\">$caption</caption>";
10337: }
1.347 albertel 10338: }
10339:
1.548 albertel 10340: =pod
10341:
10342: =item * &inhibit_menu_check($arg)
10343:
10344: Checks for a inhibitmenu state and generates output to preserve it
10345:
10346: Inputs: $arg - can be any of
10347: - undef - in which case the return value is a string
10348: to add into arguments list of a uri
10349: - 'input' - in which case the return value is a HTML
10350: <form> <input> field of type hidden to
10351: preserve the value
10352: - a url - in which case the return value is the url with
10353: the neccesary cgi args added to preserve the
10354: inhibitmenu state
10355: - a ref to a url - no return value, but the string is
10356: updated to include the neccessary cgi
10357: args to preserve the inhibitmenu state
10358:
10359: =cut
10360:
10361: sub inhibit_menu_check {
10362: my ($arg) = @_;
10363: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
10364: if ($arg eq 'input') {
10365: if ($env{'form.inhibitmenu'}) {
10366: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
10367: } else {
10368: return
10369: }
10370: }
10371: if ($env{'form.inhibitmenu'}) {
10372: if (ref($arg)) {
10373: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10374: } elsif ($arg eq '') {
10375: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
10376: } else {
10377: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10378: }
10379: }
10380: if (!ref($arg)) {
10381: return $arg;
10382: }
10383: }
10384:
1.251 albertel 10385: ###############################################
1.182 matthew 10386:
10387: =pod
10388:
1.549 albertel 10389: =back
10390:
10391: =head1 User Information Routines
10392:
10393: =over 4
10394:
1.405 albertel 10395: =item * &get_users_function()
1.182 matthew 10396:
10397: Used by &bodytag to determine the current users primary role.
10398: Returns either 'student','coordinator','admin', or 'author'.
10399:
10400: =cut
10401:
10402: ###############################################
10403: sub get_users_function {
1.815 tempelho 10404: my $function = 'norole';
1.818 tempelho 10405: if ($env{'request.role'}=~/^(st)/) {
10406: $function='student';
10407: }
1.907 raeburn 10408: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 10409: $function='coordinator';
10410: }
1.258 albertel 10411: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 10412: $function='admin';
10413: }
1.826 bisitz 10414: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 10415: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 10416: $function='author';
10417: }
10418: return $function;
1.54 www 10419: }
1.99 www 10420:
10421: ###############################################
10422:
1.233 raeburn 10423: =pod
10424:
1.821 raeburn 10425: =item * &show_course()
10426:
10427: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
10428: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
10429:
10430: Inputs:
10431: None
10432:
10433: Outputs:
10434: Scalar: 1 if 'Course' to be used, 0 otherwise.
10435:
10436: =cut
10437:
10438: ###############################################
10439: sub show_course {
10440: my $course = !$env{'user.adv'};
10441: if (!$env{'user.adv'}) {
10442: foreach my $env (keys(%env)) {
10443: next if ($env !~ m/^user\.priv\./);
10444: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
10445: $course = 0;
10446: last;
10447: }
10448: }
10449: }
10450: return $course;
10451: }
10452:
10453: ###############################################
10454:
10455: =pod
10456:
1.542 raeburn 10457: =item * &check_user_status()
1.274 raeburn 10458:
10459: Determines current status of supplied role for a
10460: specific user. Roles can be active, previous or future.
10461:
10462: Inputs:
10463: user's domain, user's username, course's domain,
1.375 raeburn 10464: course's number, optional section ID.
1.274 raeburn 10465:
10466: Outputs:
10467: role status: active, previous or future.
10468:
10469: =cut
10470:
10471: sub check_user_status {
1.412 raeburn 10472: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 10473: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 10474: my @uroles = keys(%userinfo);
1.274 raeburn 10475: my $srchstr;
10476: my $active_chk = 'none';
1.412 raeburn 10477: my $now = time;
1.274 raeburn 10478: if (@uroles > 0) {
1.908 raeburn 10479: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 10480: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
10481: } else {
1.412 raeburn 10482: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
10483: }
10484: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 10485: my $role_end = 0;
10486: my $role_start = 0;
10487: $active_chk = 'active';
1.412 raeburn 10488: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
10489: $role_end = $1;
10490: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
10491: $role_start = $1;
1.274 raeburn 10492: }
10493: }
10494: if ($role_start > 0) {
1.412 raeburn 10495: if ($now < $role_start) {
1.274 raeburn 10496: $active_chk = 'future';
10497: }
10498: }
10499: if ($role_end > 0) {
1.412 raeburn 10500: if ($now > $role_end) {
1.274 raeburn 10501: $active_chk = 'previous';
10502: }
10503: }
10504: }
10505: }
10506: return $active_chk;
10507: }
10508:
10509: ###############################################
10510:
10511: =pod
10512:
1.405 albertel 10513: =item * &get_sections()
1.233 raeburn 10514:
10515: Determines all the sections for a course including
10516: sections with students and sections containing other roles.
1.419 raeburn 10517: Incoming parameters:
10518:
10519: 1. domain
10520: 2. course number
10521: 3. reference to array containing roles for which sections should
10522: be gathered (optional).
10523: 4. reference to array containing status types for which sections
10524: should be gathered (optional).
10525:
10526: If the third argument is undefined, sections are gathered for any role.
10527: If the fourth argument is undefined, sections are gathered for any status.
10528: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10529:
1.374 raeburn 10530: Returns section hash (keys are section IDs, values are
10531: number of users in each section), subject to the
1.419 raeburn 10532: optional roles filter, optional status filter
1.233 raeburn 10533:
10534: =cut
10535:
10536: ###############################################
10537: sub get_sections {
1.419 raeburn 10538: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10539: if (!defined($cdom) || !defined($cnum)) {
10540: my $cid = $env{'request.course.id'};
10541:
10542: return if (!defined($cid));
10543:
10544: $cdom = $env{'course.'.$cid.'.domain'};
10545: $cnum = $env{'course.'.$cid.'.num'};
10546: }
10547:
10548: my %sectioncount;
1.419 raeburn 10549: my $now = time;
1.240 albertel 10550:
1.1118 raeburn 10551: my $check_students = 1;
10552: my $only_students = 0;
10553: if (ref($possible_roles) eq 'ARRAY') {
10554: if (grep(/^st$/,@{$possible_roles})) {
10555: if (@{$possible_roles} == 1) {
10556: $only_students = 1;
10557: }
10558: } else {
10559: $check_students = 0;
10560: }
10561: }
10562:
10563: if ($check_students) {
1.276 albertel 10564: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10565: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10566: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10567: my $start_index = &Apache::loncoursedata::CL_START();
10568: my $end_index = &Apache::loncoursedata::CL_END();
10569: my $status;
1.366 albertel 10570: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10571: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10572: $data->[$status_index],
10573: $data->[$start_index],
10574: $data->[$end_index]);
10575: if ($stu_status eq 'Active') {
10576: $status = 'active';
10577: } elsif ($end < $now) {
10578: $status = 'previous';
10579: } elsif ($start > $now) {
10580: $status = 'future';
10581: }
10582: if ($section ne '-1' && $section !~ /^\s*$/) {
10583: if ((!defined($possible_status)) || (($status ne '') &&
10584: (grep/^\Q$status\E$/,@{$possible_status}))) {
10585: $sectioncount{$section}++;
10586: }
1.240 albertel 10587: }
10588: }
10589: }
1.1118 raeburn 10590: if ($only_students) {
10591: return %sectioncount;
10592: }
1.240 albertel 10593: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10594: foreach my $user (sort(keys(%courseroles))) {
10595: if ($user !~ /^(\w{2})/) { next; }
10596: my ($role) = ($user =~ /^(\w{2})/);
10597: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10598: my ($section,$status);
1.240 albertel 10599: if ($role eq 'cr' &&
10600: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10601: $section=$1;
10602: }
10603: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10604: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10605: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10606: if ($end == -1 && $start == -1) {
10607: next; #deleted role
10608: }
10609: if (!defined($possible_status)) {
10610: $sectioncount{$section}++;
10611: } else {
10612: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10613: $status = 'active';
10614: } elsif ($end < $now) {
10615: $status = 'future';
10616: } elsif ($start > $now) {
10617: $status = 'previous';
10618: }
10619: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10620: $sectioncount{$section}++;
10621: }
10622: }
1.233 raeburn 10623: }
1.366 albertel 10624: return %sectioncount;
1.233 raeburn 10625: }
10626:
1.274 raeburn 10627: ###############################################
1.294 raeburn 10628:
10629: =pod
1.405 albertel 10630:
10631: =item * &get_course_users()
10632:
1.275 raeburn 10633: Retrieves usernames:domains for users in the specified course
10634: with specific role(s), and access status.
10635:
10636: Incoming parameters:
1.277 albertel 10637: 1. course domain
10638: 2. course number
10639: 3. access status: users must have - either active,
1.275 raeburn 10640: previous, future, or all.
1.277 albertel 10641: 4. reference to array of permissible roles
1.288 raeburn 10642: 5. reference to array of section restrictions (optional)
10643: 6. reference to results object (hash of hashes).
10644: 7. reference to optional userdata hash
1.609 raeburn 10645: 8. reference to optional statushash
1.630 raeburn 10646: 9. flag if privileged users (except those set to unhide in
10647: course settings) should be excluded
1.609 raeburn 10648: Keys of top level results hash are roles.
1.275 raeburn 10649: Keys of inner hashes are username:domain, with
10650: values set to access type.
1.288 raeburn 10651: Optional userdata hash returns an array with arguments in the
10652: same order as loncoursedata::get_classlist() for student data.
10653:
1.609 raeburn 10654: Optional statushash returns
10655:
1.288 raeburn 10656: Entries for end, start, section and status are blank because
10657: of the possibility of multiple values for non-student roles.
10658:
1.275 raeburn 10659: =cut
1.405 albertel 10660:
1.275 raeburn 10661: ###############################################
1.405 albertel 10662:
1.275 raeburn 10663: sub get_course_users {
1.630 raeburn 10664: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10665: my %idx = ();
1.419 raeburn 10666: my %seclists;
1.288 raeburn 10667:
10668: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10669: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10670: $idx{end} = &Apache::loncoursedata::CL_END();
10671: $idx{start} = &Apache::loncoursedata::CL_START();
10672: $idx{id} = &Apache::loncoursedata::CL_ID();
10673: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10674: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10675: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10676:
1.290 albertel 10677: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10678: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10679: my $now = time;
1.277 albertel 10680: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10681: my $match = 0;
1.412 raeburn 10682: my $secmatch = 0;
1.419 raeburn 10683: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10684: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10685: if ($section eq '') {
10686: $section = 'none';
10687: }
1.291 albertel 10688: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10689: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10690: $secmatch = 1;
10691: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10692: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10693: $secmatch = 1;
10694: }
10695: } else {
1.419 raeburn 10696: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10697: $secmatch = 1;
10698: }
1.290 albertel 10699: }
1.412 raeburn 10700: if (!$secmatch) {
10701: next;
10702: }
1.419 raeburn 10703: }
1.275 raeburn 10704: if (defined($$types{'active'})) {
1.288 raeburn 10705: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10706: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10707: $match = 1;
1.275 raeburn 10708: }
10709: }
10710: if (defined($$types{'previous'})) {
1.609 raeburn 10711: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10712: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10713: $match = 1;
1.275 raeburn 10714: }
10715: }
10716: if (defined($$types{'future'})) {
1.609 raeburn 10717: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10718: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10719: $match = 1;
1.275 raeburn 10720: }
10721: }
1.609 raeburn 10722: if ($match) {
10723: push(@{$seclists{$student}},$section);
10724: if (ref($userdata) eq 'HASH') {
10725: $$userdata{$student} = $$classlist{$student};
10726: }
10727: if (ref($statushash) eq 'HASH') {
10728: $statushash->{$student}{'st'}{$section} = $status;
10729: }
1.288 raeburn 10730: }
1.275 raeburn 10731: }
10732: }
1.412 raeburn 10733: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10734: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10735: my $now = time;
1.609 raeburn 10736: my %displaystatus = ( previous => 'Expired',
10737: active => 'Active',
10738: future => 'Future',
10739: );
1.1121 raeburn 10740: my (%nothide,@possdoms);
1.630 raeburn 10741: if ($hidepriv) {
10742: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10743: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10744: if ($user !~ /:/) {
10745: $nothide{join(':',split(/[\@]/,$user))}=1;
10746: } else {
10747: $nothide{$user} = 1;
10748: }
10749: }
1.1121 raeburn 10750: my @possdoms = ($cdom);
10751: if ($coursehash{'checkforpriv'}) {
10752: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10753: }
1.630 raeburn 10754: }
1.439 raeburn 10755: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10756: my $match = 0;
1.412 raeburn 10757: my $secmatch = 0;
1.439 raeburn 10758: my $status;
1.412 raeburn 10759: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10760: $user =~ s/:$//;
1.439 raeburn 10761: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10762: if ($end == -1 || $start == -1) {
10763: next;
10764: }
10765: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10766: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10767: my ($uname,$udom) = split(/:/,$user);
10768: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10769: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10770: $secmatch = 1;
10771: } elsif ($usec eq '') {
1.420 albertel 10772: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10773: $secmatch = 1;
10774: }
10775: } else {
10776: if (grep(/^\Q$usec\E$/,@{$sections})) {
10777: $secmatch = 1;
10778: }
10779: }
10780: if (!$secmatch) {
10781: next;
10782: }
1.288 raeburn 10783: }
1.419 raeburn 10784: if ($usec eq '') {
10785: $usec = 'none';
10786: }
1.275 raeburn 10787: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10788: if ($hidepriv) {
1.1121 raeburn 10789: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10790: (!$nothide{$uname.':'.$udom})) {
10791: next;
10792: }
10793: }
1.503 raeburn 10794: if ($end > 0 && $end < $now) {
1.439 raeburn 10795: $status = 'previous';
10796: } elsif ($start > $now) {
10797: $status = 'future';
10798: } else {
10799: $status = 'active';
10800: }
1.277 albertel 10801: foreach my $type (keys(%{$types})) {
1.275 raeburn 10802: if ($status eq $type) {
1.420 albertel 10803: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10804: push(@{$$users{$role}{$user}},$type);
10805: }
1.288 raeburn 10806: $match = 1;
10807: }
10808: }
1.419 raeburn 10809: if (($match) && (ref($userdata) eq 'HASH')) {
10810: if (!exists($$userdata{$uname.':'.$udom})) {
10811: &get_user_info($udom,$uname,\%idx,$userdata);
10812: }
1.420 albertel 10813: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10814: push(@{$seclists{$uname.':'.$udom}},$usec);
10815: }
1.609 raeburn 10816: if (ref($statushash) eq 'HASH') {
10817: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10818: }
1.275 raeburn 10819: }
10820: }
10821: }
10822: }
1.290 albertel 10823: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10824: if ((defined($cdom)) && (defined($cnum))) {
10825: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10826: if ( defined($csettings{'internal.courseowner'}) ) {
10827: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10828: next if ($owner eq '');
10829: my ($ownername,$ownerdom);
10830: if ($owner =~ /^([^:]+):([^:]+)$/) {
10831: $ownername = $1;
10832: $ownerdom = $2;
10833: } else {
10834: $ownername = $owner;
10835: $ownerdom = $cdom;
10836: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10837: }
10838: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10839: if (defined($userdata) &&
1.609 raeburn 10840: !exists($$userdata{$owner})) {
10841: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10842: if (!grep(/^none$/,@{$seclists{$owner}})) {
10843: push(@{$seclists{$owner}},'none');
10844: }
10845: if (ref($statushash) eq 'HASH') {
10846: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10847: }
1.290 albertel 10848: }
1.279 raeburn 10849: }
10850: }
10851: }
1.419 raeburn 10852: foreach my $user (keys(%seclists)) {
10853: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10854: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10855: }
1.275 raeburn 10856: }
10857: return;
10858: }
10859:
1.288 raeburn 10860: sub get_user_info {
10861: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10862: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10863: &plainname($uname,$udom,'lastname');
1.291 albertel 10864: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10865: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10866: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10867: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10868: return;
10869: }
1.275 raeburn 10870:
1.472 raeburn 10871: ###############################################
10872:
10873: =pod
10874:
10875: =item * &get_user_quota()
10876:
1.1134 raeburn 10877: Retrieves quota assigned for storage of user files.
10878: Default is to report quota for portfolio files.
1.472 raeburn 10879:
10880: Incoming parameters:
10881: 1. user's username
10882: 2. user's domain
1.1134 raeburn 10883: 3. quota name - portfolio, author, or course
1.1136 raeburn 10884: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10885: 4. crstype - official, unofficial, textbook, placement or community,
10886: if quota name is course
1.472 raeburn 10887:
10888: Returns:
1.1163 raeburn 10889: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10890: 2. (Optional) Type of setting: custom or default
10891: (individually assigned or default for user's
10892: institutional status).
10893: 3. (Optional) - User's institutional status (e.g., faculty, staff
10894: or student - types as defined in localenroll::inst_usertypes
10895: for user's domain, which determines default quota for user.
10896: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10897:
10898: If a value has been stored in the user's environment,
1.536 raeburn 10899: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10900: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10901:
10902: =cut
10903:
10904: ###############################################
10905:
10906:
10907: sub get_user_quota {
1.1136 raeburn 10908: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10909: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10910: if (!defined($udom)) {
10911: $udom = $env{'user.domain'};
10912: }
10913: if (!defined($uname)) {
10914: $uname = $env{'user.name'};
10915: }
10916: if (($udom eq '' || $uname eq '') ||
10917: ($udom eq 'public') && ($uname eq 'public')) {
10918: $quota = 0;
1.536 raeburn 10919: $quotatype = 'default';
10920: $defquota = 0;
1.472 raeburn 10921: } else {
1.536 raeburn 10922: my $inststatus;
1.1134 raeburn 10923: if ($quotaname eq 'course') {
10924: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10925: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10926: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10927: } else {
10928: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10929: $quota = $cenv{'internal.uploadquota'};
10930: }
1.536 raeburn 10931: } else {
1.1134 raeburn 10932: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10933: if ($quotaname eq 'author') {
10934: $quota = $env{'environment.authorquota'};
10935: } else {
10936: $quota = $env{'environment.portfolioquota'};
10937: }
10938: $inststatus = $env{'environment.inststatus'};
10939: } else {
10940: my %userenv =
10941: &Apache::lonnet::get('environment',['portfolioquota',
10942: 'authorquota','inststatus'],$udom,$uname);
10943: my ($tmp) = keys(%userenv);
10944: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10945: if ($quotaname eq 'author') {
10946: $quota = $userenv{'authorquota'};
10947: } else {
10948: $quota = $userenv{'portfolioquota'};
10949: }
10950: $inststatus = $userenv{'inststatus'};
10951: } else {
10952: undef(%userenv);
10953: }
10954: }
10955: }
10956: if ($quota eq '' || wantarray) {
10957: if ($quotaname eq 'course') {
10958: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10959: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10960: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10961: ($crstype eq 'placement')) {
1.1136 raeburn 10962: $defquota = $domdefs{$crstype.'quota'};
10963: }
10964: if ($defquota eq '') {
10965: $defquota = 500;
10966: }
1.1134 raeburn 10967: } else {
10968: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10969: }
10970: if ($quota eq '') {
10971: $quota = $defquota;
10972: $quotatype = 'default';
10973: } else {
10974: $quotatype = 'custom';
10975: }
1.472 raeburn 10976: }
10977: }
1.536 raeburn 10978: if (wantarray) {
10979: return ($quota,$quotatype,$settingstatus,$defquota);
10980: } else {
10981: return $quota;
10982: }
1.472 raeburn 10983: }
10984:
10985: ###############################################
10986:
10987: =pod
10988:
10989: =item * &default_quota()
10990:
1.536 raeburn 10991: Retrieves default quota assigned for storage of user portfolio files,
10992: given an (optional) user's institutional status.
1.472 raeburn 10993:
10994: Incoming parameters:
1.1142 raeburn 10995:
1.472 raeburn 10996: 1. domain
1.536 raeburn 10997: 2. (Optional) institutional status(es). This is a : separated list of
10998: status types (e.g., faculty, staff, student etc.)
10999: which apply to the user for whom the default is being retrieved.
11000: If the institutional status string in undefined, the domain
1.1134 raeburn 11001: default quota will be returned.
11002: 3. quota name - portfolio, author, or course
11003: (if no quota name provided, defaults to portfolio).
1.472 raeburn 11004:
11005: Returns:
1.1142 raeburn 11006:
1.1163 raeburn 11007: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 11008: 2. (Optional) institutional type which determined the value of the
11009: default quota.
1.472 raeburn 11010:
11011: If a value has been stored in the domain's configuration db,
11012: it will return that, otherwise it returns 20 (for backwards
11013: compatibility with domains which have not set up a configuration
1.1163 raeburn 11014: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 11015:
1.536 raeburn 11016: If the user's status includes multiple types (e.g., staff and student),
11017: the largest default quota which applies to the user determines the
11018: default quota returned.
11019:
1.472 raeburn 11020: =cut
11021:
11022: ###############################################
11023:
11024:
11025: sub default_quota {
1.1134 raeburn 11026: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 11027: my ($defquota,$settingstatus);
11028: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 11029: ['quotas'],$udom);
1.1134 raeburn 11030: my $key = 'defaultquota';
11031: if ($quotaname eq 'author') {
11032: $key = 'authorquota';
11033: }
1.622 raeburn 11034: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 11035: if ($inststatus ne '') {
1.765 raeburn 11036: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 11037: foreach my $item (@statuses) {
1.1134 raeburn 11038: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11039: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 11040: if ($defquota eq '') {
1.1134 raeburn 11041: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11042: $settingstatus = $item;
1.1134 raeburn 11043: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
11044: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11045: $settingstatus = $item;
11046: }
11047: }
1.1134 raeburn 11048: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11049: if ($quotahash{'quotas'}{$item} ne '') {
11050: if ($defquota eq '') {
11051: $defquota = $quotahash{'quotas'}{$item};
11052: $settingstatus = $item;
11053: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
11054: $defquota = $quotahash{'quotas'}{$item};
11055: $settingstatus = $item;
11056: }
1.536 raeburn 11057: }
11058: }
11059: }
11060: }
11061: if ($defquota eq '') {
1.1134 raeburn 11062: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11063: $defquota = $quotahash{'quotas'}{$key}{'default'};
11064: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11065: $defquota = $quotahash{'quotas'}{'default'};
11066: }
1.536 raeburn 11067: $settingstatus = 'default';
1.1139 raeburn 11068: if ($defquota eq '') {
11069: if ($quotaname eq 'author') {
11070: $defquota = 500;
11071: }
11072: }
1.536 raeburn 11073: }
11074: } else {
11075: $settingstatus = 'default';
1.1134 raeburn 11076: if ($quotaname eq 'author') {
11077: $defquota = 500;
11078: } else {
11079: $defquota = 20;
11080: }
1.536 raeburn 11081: }
11082: if (wantarray) {
11083: return ($defquota,$settingstatus);
1.472 raeburn 11084: } else {
1.536 raeburn 11085: return $defquota;
1.472 raeburn 11086: }
11087: }
11088:
1.1135 raeburn 11089: ###############################################
11090:
11091: =pod
11092:
1.1136 raeburn 11093: =item * &excess_filesize_warning()
1.1135 raeburn 11094:
11095: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 11096: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 11097: space to be exceeded.
1.1136 raeburn 11098:
11099: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 11100: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 11101:
1.1165 raeburn 11102: Inputs: 7
1.1136 raeburn 11103: 1. username or coursenum
1.1135 raeburn 11104: 2. domain
1.1136 raeburn 11105: 3. context ('author' or 'course')
1.1135 raeburn 11106: 4. filename of file for which action is being requested
11107: 5. filesize (kB) of file
11108: 6. action being taken: copy or upload.
1.1237 raeburn 11109: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 11110:
11111: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 11112: otherwise return null.
11113:
11114: =back
1.1135 raeburn 11115:
11116: =cut
11117:
1.1136 raeburn 11118: sub excess_filesize_warning {
1.1165 raeburn 11119: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 11120: my $current_disk_usage = 0;
1.1165 raeburn 11121: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 11122: if ($context eq 'author') {
11123: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
11124: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
11125: } else {
11126: foreach my $subdir ('docs','supplemental') {
11127: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
11128: }
11129: }
1.1135 raeburn 11130: $disk_quota = int($disk_quota * 1000);
11131: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 11132: return '<p class="LC_warning">'.
1.1135 raeburn 11133: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 11134: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
11135: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 11136: $disk_quota,$current_disk_usage).
11137: '</p>';
11138: }
11139: return;
11140: }
11141:
11142: ###############################################
11143:
11144:
1.1136 raeburn 11145:
11146:
1.384 raeburn 11147: sub get_secgrprole_info {
11148: my ($cdom,$cnum,$needroles,$type) = @_;
11149: my %sections_count = &get_sections($cdom,$cnum);
11150: my @sections = (sort {$a <=> $b} keys(%sections_count));
11151: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
11152: my @groups = sort(keys(%curr_groups));
11153: my $allroles = [];
11154: my $rolehash;
11155: my $accesshash = {
11156: active => 'Currently has access',
11157: future => 'Will have future access',
11158: previous => 'Previously had access',
11159: };
11160: if ($needroles) {
11161: $rolehash = {'all' => 'all'};
1.385 albertel 11162: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11163: if (&Apache::lonnet::error(%user_roles)) {
11164: undef(%user_roles);
11165: }
11166: foreach my $item (keys(%user_roles)) {
1.384 raeburn 11167: my ($role)=split(/\:/,$item,2);
11168: if ($role eq 'cr') { next; }
11169: if ($role =~ /^cr/) {
11170: $$rolehash{$role} = (split('/',$role))[3];
11171: } else {
11172: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
11173: }
11174: }
11175: foreach my $key (sort(keys(%{$rolehash}))) {
11176: push(@{$allroles},$key);
11177: }
11178: push (@{$allroles},'st');
11179: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
11180: }
11181: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
11182: }
11183:
1.555 raeburn 11184: sub user_picker {
1.1279 raeburn 11185: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 11186: my $currdom = $dom;
1.1253 raeburn 11187: my @alldoms = &Apache::lonnet::all_domains();
11188: if (@alldoms == 1) {
11189: my %domsrch = &Apache::lonnet::get_dom('configuration',
11190: ['directorysrch'],$alldoms[0]);
11191: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
11192: my $showdom = $domdesc;
11193: if ($showdom eq '') {
11194: $showdom = $dom;
11195: }
11196: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
11197: if ((!$domsrch{'directorysrch'}{'available'}) &&
11198: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
11199: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
11200: }
11201: }
11202: }
1.555 raeburn 11203: my %curr_selected = (
11204: srchin => 'dom',
1.580 raeburn 11205: srchby => 'lastname',
1.555 raeburn 11206: );
11207: my $srchterm;
1.625 raeburn 11208: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 11209: if ($srch->{'srchby'} ne '') {
11210: $curr_selected{'srchby'} = $srch->{'srchby'};
11211: }
11212: if ($srch->{'srchin'} ne '') {
11213: $curr_selected{'srchin'} = $srch->{'srchin'};
11214: }
11215: if ($srch->{'srchtype'} ne '') {
11216: $curr_selected{'srchtype'} = $srch->{'srchtype'};
11217: }
11218: if ($srch->{'srchdomain'} ne '') {
11219: $currdom = $srch->{'srchdomain'};
11220: }
11221: $srchterm = $srch->{'srchterm'};
11222: }
1.1222 damieng 11223: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 11224: 'usr' => 'Search criteria',
1.563 raeburn 11225: 'doma' => 'Domain/institution to search',
1.558 albertel 11226: 'uname' => 'username',
11227: 'lastname' => 'last name',
1.555 raeburn 11228: 'lastfirst' => 'last name, first name',
1.558 albertel 11229: 'crs' => 'in this course',
1.576 raeburn 11230: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 11231: 'alc' => 'all LON-CAPA',
1.573 raeburn 11232: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 11233: 'exact' => 'is',
11234: 'contains' => 'contains',
1.569 raeburn 11235: 'begins' => 'begins with',
1.1222 damieng 11236: );
11237: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 11238: 'youm' => "You must include some text to search for.",
11239: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
11240: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
11241: 'yomc' => "You must choose a domain when using an institutional directory search.",
11242: 'ymcd' => "You must choose a domain when using a domain search.",
11243: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
11244: 'whse' => "When searching by last,first you must include at least one character in the first name.",
11245: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 11246: );
1.1222 damieng 11247: &html_escape(\%html_lt);
11248: &js_escape(\%js_lt);
1.1255 raeburn 11249: my $domform;
1.1277 raeburn 11250: my $allow_blank = 1;
1.1255 raeburn 11251: if ($fixeddom) {
1.1277 raeburn 11252: $allow_blank = 0;
11253: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 11254: } else {
1.1287 raeburn 11255: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 11256: my ($trusted,$untrusted);
1.1287 raeburn 11257: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 11258: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 11259: } elsif ($context eq 'author') {
1.1288 raeburn 11260: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 11261: } elsif ($context eq 'domain') {
1.1288 raeburn 11262: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 11263: }
1.1288 raeburn 11264: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 11265: }
1.563 raeburn 11266: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 11267:
11268: my @srchins = ('crs','dom','alc','instd');
11269:
11270: foreach my $option (@srchins) {
11271: # FIXME 'alc' option unavailable until
11272: # loncreateuser::print_user_query_page()
11273: # has been completed.
11274: next if ($option eq 'alc');
1.880 raeburn 11275: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 11276: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 11277: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 11278: if ($curr_selected{'srchin'} eq $option) {
11279: $srchinsel .= '
1.1222 damieng 11280: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 11281: } else {
11282: $srchinsel .= '
1.1222 damieng 11283: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 11284: }
1.555 raeburn 11285: }
1.563 raeburn 11286: $srchinsel .= "\n </select>\n";
1.555 raeburn 11287:
11288: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 11289: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 11290: if ($curr_selected{'srchby'} eq $option) {
11291: $srchbysel .= '
1.1222 damieng 11292: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11293: } else {
11294: $srchbysel .= '
1.1222 damieng 11295: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11296: }
11297: }
11298: $srchbysel .= "\n </select>\n";
11299:
11300: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 11301: foreach my $option ('begins','contains','exact') {
1.555 raeburn 11302: if ($curr_selected{'srchtype'} eq $option) {
11303: $srchtypesel .= '
1.1222 damieng 11304: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11305: } else {
11306: $srchtypesel .= '
1.1222 damieng 11307: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11308: }
11309: }
11310: $srchtypesel .= "\n </select>\n";
11311:
1.558 albertel 11312: my ($newuserscript,$new_user_create);
1.994 raeburn 11313: my $context_dom = $env{'request.role.domain'};
11314: if ($context eq 'requestcrs') {
11315: if ($env{'form.coursedom'} ne '') {
11316: $context_dom = $env{'form.coursedom'};
11317: }
11318: }
1.556 raeburn 11319: if ($forcenewuser) {
1.576 raeburn 11320: if (ref($srch) eq 'HASH') {
1.994 raeburn 11321: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 11322: if ($cancreate) {
11323: $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>';
11324: } else {
1.799 bisitz 11325: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 11326: my %usertypetext = (
11327: official => 'institutional',
11328: unofficial => 'non-institutional',
11329: );
1.799 bisitz 11330: $new_user_create = '<p class="LC_warning">'
11331: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
11332: .' '
11333: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
11334: ,'<a href="'.$helplink.'">','</a>')
11335: .'</p><br />';
1.627 raeburn 11336: }
1.576 raeburn 11337: }
11338: }
11339:
1.556 raeburn 11340: $newuserscript = <<"ENDSCRIPT";
11341:
1.570 raeburn 11342: function setSearch(createnew,callingForm) {
1.556 raeburn 11343: if (createnew == 1) {
1.570 raeburn 11344: for (var i=0; i<callingForm.srchby.length; i++) {
11345: if (callingForm.srchby.options[i].value == 'uname') {
11346: callingForm.srchby.selectedIndex = i;
1.556 raeburn 11347: }
11348: }
1.570 raeburn 11349: for (var i=0; i<callingForm.srchin.length; i++) {
11350: if ( callingForm.srchin.options[i].value == 'dom') {
11351: callingForm.srchin.selectedIndex = i;
1.556 raeburn 11352: }
11353: }
1.570 raeburn 11354: for (var i=0; i<callingForm.srchtype.length; i++) {
11355: if (callingForm.srchtype.options[i].value == 'exact') {
11356: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 11357: }
11358: }
1.570 raeburn 11359: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 11360: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 11361: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 11362: }
11363: }
11364: }
11365: }
11366: ENDSCRIPT
1.558 albertel 11367:
1.556 raeburn 11368: }
11369:
1.555 raeburn 11370: my $output = <<"END_BLOCK";
1.556 raeburn 11371: <script type="text/javascript">
1.824 bisitz 11372: // <![CDATA[
1.570 raeburn 11373: function validateEntry(callingForm) {
1.558 albertel 11374:
1.556 raeburn 11375: var checkok = 1;
1.558 albertel 11376: var srchin;
1.570 raeburn 11377: for (var i=0; i<callingForm.srchin.length; i++) {
11378: if ( callingForm.srchin[i].checked ) {
11379: srchin = callingForm.srchin[i].value;
1.558 albertel 11380: }
11381: }
11382:
1.570 raeburn 11383: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
11384: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
11385: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
11386: var srchterm = callingForm.srchterm.value;
11387: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 11388: var msg = "";
11389:
11390: if (srchterm == "") {
11391: checkok = 0;
1.1222 damieng 11392: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 11393: }
11394:
1.569 raeburn 11395: if (srchtype== 'begins') {
11396: if (srchterm.length < 2) {
11397: checkok = 0;
1.1222 damieng 11398: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 11399: }
11400: }
11401:
1.556 raeburn 11402: if (srchtype== 'contains') {
11403: if (srchterm.length < 3) {
11404: checkok = 0;
1.1222 damieng 11405: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 11406: }
11407: }
11408: if (srchin == 'instd') {
11409: if (srchdomain == '') {
11410: checkok = 0;
1.1222 damieng 11411: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 11412: }
11413: }
11414: if (srchin == 'dom') {
11415: if (srchdomain == '') {
11416: checkok = 0;
1.1222 damieng 11417: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 11418: }
11419: }
11420: if (srchby == 'lastfirst') {
11421: if (srchterm.indexOf(",") == -1) {
11422: checkok = 0;
1.1222 damieng 11423: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 11424: }
11425: if (srchterm.indexOf(",") == srchterm.length -1) {
11426: checkok = 0;
1.1222 damieng 11427: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 11428: }
11429: }
11430: if (checkok == 0) {
1.1222 damieng 11431: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 11432: return;
11433: }
11434: if (checkok == 1) {
1.570 raeburn 11435: callingForm.submit();
1.556 raeburn 11436: }
11437: }
11438:
11439: $newuserscript
11440:
1.824 bisitz 11441: // ]]>
1.556 raeburn 11442: </script>
1.558 albertel 11443:
11444: $new_user_create
11445:
1.555 raeburn 11446: END_BLOCK
1.558 albertel 11447:
1.876 raeburn 11448: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 11449: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 11450: $domform.
11451: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 11452: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 11453: $srchbysel.
11454: $srchtypesel.
11455: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
11456: $srchinsel.
11457: &Apache::lonhtmlcommon::row_closure(1).
11458: &Apache::lonhtmlcommon::end_pick_box().
11459: '<br />';
1.1253 raeburn 11460: return ($output,1);
1.555 raeburn 11461: }
11462:
1.612 raeburn 11463: sub user_rule_check {
1.615 raeburn 11464: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 11465: my ($response,%inst_response);
1.612 raeburn 11466: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 11467: if (keys(%{$usershash}) > 1) {
11468: my (%by_username,%by_id,%userdoms);
11469: my $checkid;
11470: if (ref($checks) eq 'HASH') {
11471: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
11472: $checkid = 1;
11473: }
11474: }
11475: foreach my $user (keys(%{$usershash})) {
11476: my ($uname,$udom) = split(/:/,$user);
11477: if ($checkid) {
11478: if (ref($usershash->{$user}) eq 'HASH') {
11479: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 11480: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 11481: $userdoms{$udom} = 1;
1.1227 raeburn 11482: if (ref($inst_results) eq 'HASH') {
11483: $inst_results->{$uname.':'.$udom} = {};
11484: }
1.1226 raeburn 11485: }
11486: }
11487: } else {
11488: $by_username{$udom}{$uname} = 1;
11489: $userdoms{$udom} = 1;
1.1227 raeburn 11490: if (ref($inst_results) eq 'HASH') {
11491: $inst_results->{$uname.':'.$udom} = {};
11492: }
1.1226 raeburn 11493: }
11494: }
11495: foreach my $udom (keys(%userdoms)) {
11496: if (!$got_rules->{$udom}) {
11497: my %domconfig = &Apache::lonnet::get_dom('configuration',
11498: ['usercreation'],$udom);
11499: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11500: foreach my $item ('username','id') {
11501: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 11502: $$curr_rules{$udom}{$item} =
11503: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 11504: }
11505: }
11506: }
11507: $got_rules->{$udom} = 1;
11508: }
1.612 raeburn 11509: }
1.1226 raeburn 11510: if ($checkid) {
11511: foreach my $udom (keys(%by_id)) {
11512: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11513: if ($outcome eq 'ok') {
1.1227 raeburn 11514: foreach my $id (keys(%{$by_id{$udom}})) {
11515: my $uname = $by_id{$udom}{$id};
11516: $inst_response{$uname.':'.$udom} = $outcome;
11517: }
1.1226 raeburn 11518: if (ref($results) eq 'HASH') {
11519: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 11520: if (exists($inst_response{$uname.':'.$udom})) {
11521: $inst_response{$uname.':'.$udom} = $outcome;
11522: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11523: }
1.1226 raeburn 11524: }
11525: }
11526: }
1.612 raeburn 11527: }
1.615 raeburn 11528: } else {
1.1226 raeburn 11529: foreach my $udom (keys(%by_username)) {
11530: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11531: if ($outcome eq 'ok') {
1.1227 raeburn 11532: foreach my $uname (keys(%{$by_username{$udom}})) {
11533: $inst_response{$uname.':'.$udom} = $outcome;
11534: }
1.1226 raeburn 11535: if (ref($results) eq 'HASH') {
11536: foreach my $uname (keys(%{$results})) {
11537: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11538: }
11539: }
11540: }
11541: }
1.612 raeburn 11542: }
1.1226 raeburn 11543: } elsif (keys(%{$usershash}) == 1) {
11544: my $user = (keys(%{$usershash}))[0];
11545: my ($uname,$udom) = split(/:/,$user);
11546: if (($udom ne '') && ($uname ne '')) {
11547: if (ref($usershash->{$user}) eq 'HASH') {
11548: if (ref($checks) eq 'HASH') {
11549: if (defined($checks->{'username'})) {
11550: ($inst_response{$user},%{$inst_results->{$user}}) =
11551: &Apache::lonnet::get_instuser($udom,$uname);
11552: } elsif (defined($checks->{'id'})) {
11553: if ($usershash->{$user}->{'id'} ne '') {
11554: ($inst_response{$user},%{$inst_results->{$user}}) =
11555: &Apache::lonnet::get_instuser($udom,undef,
11556: $usershash->{$user}->{'id'});
11557: } else {
11558: ($inst_response{$user},%{$inst_results->{$user}}) =
11559: &Apache::lonnet::get_instuser($udom,$uname);
11560: }
1.585 raeburn 11561: }
1.1226 raeburn 11562: } else {
11563: ($inst_response{$user},%{$inst_results->{$user}}) =
11564: &Apache::lonnet::get_instuser($udom,$uname);
11565: return;
11566: }
11567: if (!$got_rules->{$udom}) {
11568: my %domconfig = &Apache::lonnet::get_dom('configuration',
11569: ['usercreation'],$udom);
11570: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11571: foreach my $item ('username','id') {
11572: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11573: $$curr_rules{$udom}{$item} =
11574: $domconfig{'usercreation'}{$item.'_rule'};
11575: }
11576: }
11577: }
11578: $got_rules->{$udom} = 1;
1.585 raeburn 11579: }
11580: }
1.1226 raeburn 11581: } else {
11582: return;
11583: }
11584: } else {
11585: return;
11586: }
11587: foreach my $user (keys(%{$usershash})) {
11588: my ($uname,$udom) = split(/:/,$user);
11589: next if (($udom eq '') || ($uname eq ''));
11590: my $id;
1.1227 raeburn 11591: if (ref($inst_results) eq 'HASH') {
11592: if (ref($inst_results->{$user}) eq 'HASH') {
11593: $id = $inst_results->{$user}->{'id'};
11594: }
11595: }
11596: if ($id eq '') {
11597: if (ref($usershash->{$user})) {
11598: $id = $usershash->{$user}->{'id'};
11599: }
1.585 raeburn 11600: }
1.612 raeburn 11601: foreach my $item (keys(%{$checks})) {
11602: if (ref($$curr_rules{$udom}) eq 'HASH') {
11603: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11604: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 11605: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11606: $$curr_rules{$udom}{$item});
1.612 raeburn 11607: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11608: if ($rule_check{$rule}) {
11609: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 11610: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11611: if (ref($inst_results) eq 'HASH') {
11612: if (ref($inst_results->{$user}) eq 'HASH') {
11613: if (keys(%{$inst_results->{$user}}) == 0) {
11614: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 11615: } elsif ($item eq 'id') {
11616: if ($inst_results->{$user}->{'id'} eq '') {
11617: $$alerts{$item}{$udom}{$uname} = 1;
11618: }
1.615 raeburn 11619: }
1.612 raeburn 11620: }
11621: }
1.615 raeburn 11622: }
11623: last;
1.585 raeburn 11624: }
11625: }
11626: }
11627: }
11628: }
11629: }
11630: }
11631: }
1.612 raeburn 11632: return;
11633: }
11634:
11635: sub user_rule_formats {
11636: my ($domain,$domdesc,$curr_rules,$check) = @_;
11637: my %text = (
11638: 'username' => 'Usernames',
11639: 'id' => 'IDs',
11640: );
11641: my $output;
11642: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11643: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11644: if (@{$ruleorder} > 0) {
1.1102 raeburn 11645: $output = '<br />'.
11646: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11647: '<span class="LC_cusr_emph">','</span>',$domdesc).
11648: ' <ul>';
1.612 raeburn 11649: foreach my $rule (@{$ruleorder}) {
11650: if (ref($curr_rules) eq 'ARRAY') {
11651: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11652: if (ref($rules->{$rule}) eq 'HASH') {
11653: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11654: $rules->{$rule}{'desc'}.'</li>';
11655: }
11656: }
11657: }
11658: }
11659: $output .= '</ul>';
11660: }
11661: }
11662: return $output;
11663: }
11664:
11665: sub instrule_disallow_msg {
1.615 raeburn 11666: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11667: my $response;
11668: my %text = (
11669: item => 'username',
11670: items => 'usernames',
11671: match => 'matches',
11672: do => 'does',
11673: action => 'a username',
11674: one => 'one',
11675: );
11676: if ($count > 1) {
11677: $text{'item'} = 'usernames';
11678: $text{'match'} ='match';
11679: $text{'do'} = 'do';
11680: $text{'action'} = 'usernames',
11681: $text{'one'} = 'ones';
11682: }
11683: if ($checkitem eq 'id') {
11684: $text{'items'} = 'IDs';
11685: $text{'item'} = 'ID';
11686: $text{'action'} = 'an ID';
1.615 raeburn 11687: if ($count > 1) {
11688: $text{'item'} = 'IDs';
11689: $text{'action'} = 'IDs';
11690: }
1.612 raeburn 11691: }
1.674 bisitz 11692: $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 11693: if ($mode eq 'upload') {
11694: if ($checkitem eq 'username') {
11695: $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'}.");
11696: } elsif ($checkitem eq 'id') {
1.674 bisitz 11697: $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 11698: }
1.669 raeburn 11699: } elsif ($mode eq 'selfcreate') {
11700: if ($checkitem eq 'id') {
11701: $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.");
11702: }
1.615 raeburn 11703: } else {
11704: if ($checkitem eq 'username') {
11705: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11706: } elsif ($checkitem eq 'id') {
11707: $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.");
11708: }
1.612 raeburn 11709: }
11710: return $response;
1.585 raeburn 11711: }
11712:
1.624 raeburn 11713: sub personal_data_fieldtitles {
11714: my %fieldtitles = &Apache::lonlocal::texthash (
11715: id => 'Student/Employee ID',
11716: permanentemail => 'E-mail address',
11717: lastname => 'Last Name',
11718: firstname => 'First Name',
11719: middlename => 'Middle Name',
11720: generation => 'Generation',
11721: gen => 'Generation',
1.765 raeburn 11722: inststatus => 'Affiliation',
1.624 raeburn 11723: );
11724: return %fieldtitles;
11725: }
11726:
1.642 raeburn 11727: sub sorted_inst_types {
11728: my ($dom) = @_;
1.1185 raeburn 11729: my ($usertypes,$order);
11730: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11731: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11732: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11733: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11734: } else {
11735: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11736: }
1.642 raeburn 11737: my $othertitle = &mt('All users');
11738: if ($env{'request.course.id'}) {
1.668 raeburn 11739: $othertitle = &mt('Any users');
1.642 raeburn 11740: }
11741: my @types;
11742: if (ref($order) eq 'ARRAY') {
11743: @types = @{$order};
11744: }
11745: if (@types == 0) {
11746: if (ref($usertypes) eq 'HASH') {
11747: @types = sort(keys(%{$usertypes}));
11748: }
11749: }
11750: if (keys(%{$usertypes}) > 0) {
11751: $othertitle = &mt('Other users');
11752: }
11753: return ($othertitle,$usertypes,\@types);
11754: }
11755:
1.645 raeburn 11756: sub get_institutional_codes {
1.1361 raeburn 11757: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11758: # Get complete list of course sections to update
11759: my @currsections = ();
11760: my @currxlists = ();
1.1361 raeburn 11761: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11762: my $coursecode = $$settings{'internal.coursecode'};
1.1361 raeburn 11763: my $crskey = $crs.':'.$coursecode;
11764: @{$unclutteredsec{$crskey}} = ();
11765: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11766:
11767: if ($$settings{'internal.sectionnums'} ne '') {
11768: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11769: }
11770:
11771: if ($$settings{'internal.crosslistings'} ne '') {
11772: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11773: }
11774:
11775: if (@currxlists > 0) {
1.1361 raeburn 11776: foreach my $xl (@currxlists) {
11777: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11778: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 11779: push(@{$allcourses},$1);
1.645 raeburn 11780: $$LC_code{$1} = $2;
11781: }
11782: }
11783: }
11784: }
1.1361 raeburn 11785:
1.645 raeburn 11786: if (@currsections > 0) {
1.1361 raeburn 11787: foreach my $sec (@currsections) {
11788: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11789: my $instsec = $1;
1.645 raeburn 11790: my $lc_sec = $2;
1.1361 raeburn 11791: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11792: push(@{$unclutteredsec{$crskey}},$instsec);
11793: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11794: }
11795: }
11796: }
11797: }
11798:
11799: if (@{$unclutteredsec{$crskey}} > 0) {
11800: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11801: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11802: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11803: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11804: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1263 raeburn 11805: push(@{$allcourses},$sec);
1.1361 raeburn 11806: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11807: }
11808: }
11809: }
11810: }
11811: return;
11812: }
11813:
1.971 raeburn 11814: sub get_standard_codeitems {
11815: return ('Year','Semester','Department','Number','Section');
11816: }
11817:
1.112 bowersj2 11818: =pod
11819:
1.780 raeburn 11820: =head1 Slot Helpers
11821:
11822: =over 4
11823:
11824: =item * sorted_slots()
11825:
1.1040 raeburn 11826: Sorts an array of slot names in order of an optional sort key,
11827: default sort is by slot start time (earliest first).
1.780 raeburn 11828:
11829: Inputs:
11830:
11831: =over 4
11832:
11833: slotsarr - Reference to array of unsorted slot names.
11834:
11835: slots - Reference to hash of hash, where outer hash keys are slot names.
11836:
1.1040 raeburn 11837: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11838:
1.549 albertel 11839: =back
11840:
1.780 raeburn 11841: Returns:
11842:
11843: =over 4
11844:
1.1040 raeburn 11845: sorted - An array of slot names sorted by a specified sort key
11846: (default sort key is start time of the slot).
1.780 raeburn 11847:
11848: =back
11849:
11850: =cut
11851:
11852:
11853: sub sorted_slots {
1.1040 raeburn 11854: my ($slotsarr,$slots,$sortkey) = @_;
11855: if ($sortkey eq '') {
11856: $sortkey = 'starttime';
11857: }
1.780 raeburn 11858: my @sorted;
11859: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11860: @sorted =
11861: sort {
11862: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11863: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11864: }
11865: if (ref($slots->{$a})) { return -1;}
11866: if (ref($slots->{$b})) { return 1;}
11867: return 0;
11868: } @{$slotsarr};
11869: }
11870: return @sorted;
11871: }
11872:
1.1040 raeburn 11873: =pod
11874:
11875: =item * get_future_slots()
11876:
11877: Inputs:
11878:
11879: =over 4
11880:
11881: cnum - course number
11882:
11883: cdom - course domain
11884:
11885: now - current UNIX time
11886:
11887: symb - optional symb
11888:
11889: =back
11890:
11891: Returns:
11892:
11893: =over 4
11894:
11895: sorted_reservable - ref to array of student_schedulable slots currently
11896: reservable, ordered by end date of reservation period.
11897:
11898: reservable_now - ref to hash of student_schedulable slots currently
11899: reservable.
11900:
11901: Keys in inner hash are:
11902: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11903: (b) endreserve: end date of reservation period.
11904: (c) uniqueperiod: start,end dates when slot is to be uniquely
11905: selected.
1.1040 raeburn 11906:
11907: sorted_future - ref to array of student_schedulable slots reservable in
11908: the future, ordered by start date of reservation period.
11909:
11910: future_reservable - ref to hash of student_schedulable slots reservable
11911: in the future.
11912:
11913: Keys in inner hash are:
11914: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11915: (b) startreserve: start date of reservation period.
11916: (c) uniqueperiod: start,end dates when slot is to be uniquely
11917: selected.
1.1040 raeburn 11918:
11919: =back
11920:
11921: =cut
11922:
11923: sub get_future_slots {
11924: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11925: my $map;
11926: if ($symb) {
11927: ($map) = &Apache::lonnet::decode_symb($symb);
11928: }
1.1040 raeburn 11929: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11930: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11931: foreach my $slot (keys(%slots)) {
11932: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11933: if ($symb) {
1.1229 raeburn 11934: if ($slots{$slot}->{'symb'} ne '') {
11935: my $canuse;
11936: my %oksymbs;
11937: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11938: map { $oksymbs{$_} = 1; } @slotsymbs;
11939: if ($oksymbs{$symb}) {
11940: $canuse = 1;
11941: } else {
11942: foreach my $item (@slotsymbs) {
11943: if ($item =~ /\.(page|sequence)$/) {
11944: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11945: if (($map ne '') && ($map eq $sloturl)) {
11946: $canuse = 1;
11947: last;
11948: }
11949: }
11950: }
11951: }
11952: next unless ($canuse);
11953: }
1.1040 raeburn 11954: }
11955: if (($slots{$slot}->{'starttime'} > $now) &&
11956: ($slots{$slot}->{'endtime'} > $now)) {
11957: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11958: my $userallowed = 0;
11959: if ($slots{$slot}->{'allowedsections'}) {
11960: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11961: if (!defined($env{'request.role.sec'})
11962: && grep(/^No section assigned$/,@allowed_sec)) {
11963: $userallowed=1;
11964: } else {
11965: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11966: $userallowed=1;
11967: }
11968: }
11969: unless ($userallowed) {
11970: if (defined($env{'request.course.groups'})) {
11971: my @groups = split(/:/,$env{'request.course.groups'});
11972: foreach my $group (@groups) {
11973: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11974: $userallowed=1;
11975: last;
11976: }
11977: }
11978: }
11979: }
11980: }
11981: if ($slots{$slot}->{'allowedusers'}) {
11982: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11983: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11984: if (grep(/^\Q$user\E$/,@allowed_users)) {
11985: $userallowed = 1;
11986: }
11987: }
11988: next unless($userallowed);
11989: }
11990: my $startreserve = $slots{$slot}->{'startreserve'};
11991: my $endreserve = $slots{$slot}->{'endreserve'};
11992: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11993: my $uniqueperiod;
11994: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11995: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11996: }
1.1040 raeburn 11997: if (($startreserve < $now) &&
11998: (!$endreserve || $endreserve > $now)) {
11999: my $lastres = $endreserve;
12000: if (!$lastres) {
12001: $lastres = $slots{$slot}->{'starttime'};
12002: }
12003: $reservable_now{$slot} = {
12004: symb => $symb,
1.1250 raeburn 12005: endreserve => $lastres,
12006: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12007: };
12008: } elsif (($startreserve > $now) &&
12009: (!$endreserve || $endreserve > $startreserve)) {
12010: $future_reservable{$slot} = {
12011: symb => $symb,
1.1250 raeburn 12012: startreserve => $startreserve,
12013: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12014: };
12015: }
12016: }
12017: }
12018: my @unsorted_reservable = keys(%reservable_now);
12019: if (@unsorted_reservable > 0) {
12020: @sorted_reservable =
12021: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
12022: }
12023: my @unsorted_future = keys(%future_reservable);
12024: if (@unsorted_future > 0) {
12025: @sorted_future =
12026: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
12027: }
12028: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
12029: }
1.780 raeburn 12030:
12031: =pod
12032:
1.1057 foxr 12033: =back
12034:
1.549 albertel 12035: =head1 HTTP Helpers
12036:
12037: =over 4
12038:
1.648 raeburn 12039: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 12040:
1.258 albertel 12041: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 12042: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 12043: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 12044:
12045: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
12046: $possible_names is an ref to an array of form element names. As an example:
12047: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 12048: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 12049:
12050: =cut
1.1 albertel 12051:
1.6 albertel 12052: sub get_unprocessed_cgi {
1.25 albertel 12053: my ($query,$possible_names)= @_;
1.26 matthew 12054: # $Apache::lonxml::debug=1;
1.356 albertel 12055: foreach my $pair (split(/&/,$query)) {
12056: my ($name, $value) = split(/=/,$pair);
1.369 www 12057: $name = &unescape($name);
1.25 albertel 12058: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
12059: $value =~ tr/+/ /;
12060: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 12061: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 12062: }
1.16 harris41 12063: }
1.6 albertel 12064: }
12065:
1.112 bowersj2 12066: =pod
12067:
1.648 raeburn 12068: =item * &cacheheader()
1.112 bowersj2 12069:
12070: returns cache-controlling header code
12071:
12072: =cut
12073:
1.7 albertel 12074: sub cacheheader {
1.258 albertel 12075: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 12076: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
12077: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 12078: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
12079: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 12080: return $output;
1.7 albertel 12081: }
12082:
1.112 bowersj2 12083: =pod
12084:
1.648 raeburn 12085: =item * &no_cache($r)
1.112 bowersj2 12086:
12087: specifies header code to not have cache
12088:
12089: =cut
12090:
1.9 albertel 12091: sub no_cache {
1.216 albertel 12092: my ($r) = @_;
12093: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 12094: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 12095: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
12096: $r->no_cache(1);
12097: $r->header_out("Expires" => $date);
12098: $r->header_out("Pragma" => "no-cache");
1.123 www 12099: }
12100:
12101: sub content_type {
1.181 albertel 12102: my ($r,$type,$charset) = @_;
1.299 foxr 12103: if ($r) {
12104: # Note that printout.pl calls this with undef for $r.
12105: &no_cache($r);
12106: }
1.258 albertel 12107: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 12108: unless ($charset) {
12109: $charset=&Apache::lonlocal::current_encoding;
12110: }
12111: if ($charset) { $type.='; charset='.$charset; }
12112: if ($r) {
12113: $r->content_type($type);
12114: } else {
12115: print("Content-type: $type\n\n");
12116: }
1.9 albertel 12117: }
1.25 albertel 12118:
1.112 bowersj2 12119: =pod
12120:
1.648 raeburn 12121: =item * &add_to_env($name,$value)
1.112 bowersj2 12122:
1.258 albertel 12123: adds $name to the %env hash with value
1.112 bowersj2 12124: $value, if $name already exists, the entry is converted to an array
12125: reference and $value is added to the array.
12126:
12127: =cut
12128:
1.25 albertel 12129: sub add_to_env {
12130: my ($name,$value)=@_;
1.258 albertel 12131: if (defined($env{$name})) {
12132: if (ref($env{$name})) {
1.25 albertel 12133: #already have multiple values
1.258 albertel 12134: push(@{ $env{$name} },$value);
1.25 albertel 12135: } else {
12136: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 12137: my $first=$env{$name};
12138: undef($env{$name});
12139: push(@{ $env{$name} },$first,$value);
1.25 albertel 12140: }
12141: } else {
1.258 albertel 12142: $env{$name}=$value;
1.25 albertel 12143: }
1.31 albertel 12144: }
1.149 albertel 12145:
12146: =pod
12147:
1.648 raeburn 12148: =item * &get_env_multiple($name)
1.149 albertel 12149:
1.258 albertel 12150: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 12151: values may be defined and end up as an array ref.
12152:
12153: returns an array of values
12154:
12155: =cut
12156:
12157: sub get_env_multiple {
12158: my ($name) = @_;
12159: my @values;
1.258 albertel 12160: if (defined($env{$name})) {
1.149 albertel 12161: # exists is it an array
1.258 albertel 12162: if (ref($env{$name})) {
12163: @values=@{ $env{$name} };
1.149 albertel 12164: } else {
1.258 albertel 12165: $values[0]=$env{$name};
1.149 albertel 12166: }
12167: }
12168: return(@values);
12169: }
12170:
1.1249 damieng 12171: # Looks at given dependencies, and returns something depending on the context.
12172: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
12173: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
12174: # For all other contexts, returns ($output, $counter, $numpathchg).
12175: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
12176: # $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.
12177: # $numpathchg: integer with the number of cleaned up dependency paths.
12178: # \%existing: hash reference clean path -> 1 only for existing dependencies.
12179: # \%mapping: hash reference clean path -> original path for all dependencies.
12180: # @param {string} actionurl - The path to the handler, indicative of the context.
12181: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
12182: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
12183: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
12184: # @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)
12185: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 12186: sub ask_for_embedded_content {
1.1249 damieng 12187: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 12188: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 12189: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 12190: %currsubfile,%unused,$rem);
1.1071 raeburn 12191: my $counter = 0;
12192: my $numnew = 0;
1.987 raeburn 12193: my $numremref = 0;
12194: my $numinvalid = 0;
12195: my $numpathchg = 0;
12196: my $numexisting = 0;
1.1071 raeburn 12197: my $numunused = 0;
12198: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 12199: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 12200: my $heading = &mt('Upload embedded files');
12201: my $buttontext = &mt('Upload');
12202:
1.1249 damieng 12203: # fills these variables based on the context:
12204: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
12205: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 12206: if ($env{'request.course.id'}) {
1.1123 raeburn 12207: if ($actionurl eq '/adm/dependencies') {
12208: $navmap = Apache::lonnavmaps::navmap->new();
12209: }
12210: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12211: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 12212: }
1.1123 raeburn 12213: if (($actionurl eq '/adm/portfolio') ||
12214: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 12215: my $current_path='/';
12216: if ($env{'form.currentpath'}) {
12217: $current_path = $env{'form.currentpath'};
12218: }
12219: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 12220: $udom = $cdom;
12221: $uname = $cnum;
1.984 raeburn 12222: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
12223: } else {
12224: $udom = $env{'user.domain'};
12225: $uname = $env{'user.name'};
12226: $url = '/userfiles/portfolio';
12227: }
1.987 raeburn 12228: $toplevel = $url.'/';
1.984 raeburn 12229: $url .= $current_path;
12230: $getpropath = 1;
1.987 raeburn 12231: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12232: ($actionurl eq '/adm/imsimport')) {
1.1022 www 12233: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 12234: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 12235: $toplevel = $url;
1.984 raeburn 12236: if ($rest ne '') {
1.987 raeburn 12237: $url .= $rest;
12238: }
12239: } elsif ($actionurl eq '/adm/coursedocs') {
12240: if (ref($args) eq 'HASH') {
1.1071 raeburn 12241: $url = $args->{'docs_url'};
12242: $toplevel = $url;
1.1084 raeburn 12243: if ($args->{'context'} eq 'paste') {
12244: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
12245: ($path) =
12246: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12247: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12248: $fileloc =~ s{^/}{};
12249: }
1.1071 raeburn 12250: }
1.1084 raeburn 12251: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 12252: if ($env{'request.course.id'} ne '') {
12253: if (ref($args) eq 'HASH') {
12254: $url = $args->{'docs_url'};
12255: $title = $args->{'docs_title'};
1.1126 raeburn 12256: $toplevel = $url;
12257: unless ($toplevel =~ m{^/}) {
12258: $toplevel = "/$url";
12259: }
1.1085 raeburn 12260: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 12261: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
12262: $path = $1;
12263: } else {
12264: ($path) =
12265: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12266: }
1.1195 raeburn 12267: if ($toplevel=~/^\/*(uploaded|editupload)/) {
12268: $fileloc = $toplevel;
12269: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
12270: my ($udom,$uname,$fname) =
12271: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
12272: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
12273: } else {
12274: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12275: }
1.1071 raeburn 12276: $fileloc =~ s{^/}{};
12277: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
12278: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
12279: }
1.987 raeburn 12280: }
1.1123 raeburn 12281: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12282: $udom = $cdom;
12283: $uname = $cnum;
12284: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
12285: $toplevel = $url;
12286: $path = $url;
12287: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
12288: $fileloc =~ s{^/}{};
1.987 raeburn 12289: }
1.1249 damieng 12290:
12291: # parses the dependency paths to get some info
12292: # fills $newfiles, $mapping, $subdependencies, $dependencies
12293: # $newfiles: hash URL -> 1 for new files or external URLs
12294: # (will be completed later)
12295: # $mapping:
12296: # for external URLs: external URL -> external URL
12297: # for relative paths: clean path -> original path
12298: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
12299: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 12300: foreach my $file (keys(%{$allfiles})) {
12301: my $embed_file;
12302: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
12303: $embed_file = $1;
12304: } else {
12305: $embed_file = $file;
12306: }
1.1158 raeburn 12307: my ($absolutepath,$cleaned_file);
12308: if ($embed_file =~ m{^\w+://}) {
12309: $cleaned_file = $embed_file;
1.1147 raeburn 12310: $newfiles{$cleaned_file} = 1;
12311: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12312: } else {
1.1158 raeburn 12313: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 12314: if ($embed_file =~ m{^/}) {
12315: $absolutepath = $embed_file;
12316: }
1.1147 raeburn 12317: if ($cleaned_file =~ m{/}) {
12318: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 12319: $path = &check_for_traversal($path,$url,$toplevel);
12320: my $item = $fname;
12321: if ($path ne '') {
12322: $item = $path.'/'.$fname;
12323: $subdependencies{$path}{$fname} = 1;
12324: } else {
12325: $dependencies{$item} = 1;
12326: }
12327: if ($absolutepath) {
12328: $mapping{$item} = $absolutepath;
12329: } else {
12330: $mapping{$item} = $embed_file;
12331: }
12332: } else {
12333: $dependencies{$embed_file} = 1;
12334: if ($absolutepath) {
1.1147 raeburn 12335: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 12336: } else {
1.1147 raeburn 12337: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12338: }
12339: }
1.984 raeburn 12340: }
12341: }
1.1249 damieng 12342:
12343: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
12344: # and lists
12345: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
12346: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
12347: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
12348: # the path had to be cleaned up
12349: # $existing: hash clean path -> 1 if the file exists
12350: # $numexisting: number of keys in $existing
12351: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
12352: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
12353: # dependency subdirectories that are
12354: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 12355: my $dirptr = 16384;
1.984 raeburn 12356: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 12357: $currsubfile{$path} = {};
1.1123 raeburn 12358: if (($actionurl eq '/adm/portfolio') ||
12359: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12360: my ($sublistref,$listerror) =
12361: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
12362: if (ref($sublistref) eq 'ARRAY') {
12363: foreach my $line (@{$sublistref}) {
12364: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 12365: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 12366: }
1.984 raeburn 12367: }
1.987 raeburn 12368: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12369: if (opendir(my $dir,$url.'/'.$path)) {
12370: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 12371: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
12372: }
1.1084 raeburn 12373: } elsif (($actionurl eq '/adm/dependencies') ||
12374: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12375: ($args->{'context'} eq 'paste')) ||
12376: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12377: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 12378: my $dir;
12379: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12380: $dir = $fileloc;
12381: } else {
12382: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12383: }
1.1071 raeburn 12384: if ($dir ne '') {
12385: my ($sublistref,$listerror) =
12386: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
12387: if (ref($sublistref) eq 'ARRAY') {
12388: foreach my $line (@{$sublistref}) {
12389: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
12390: undef,$mtime)=split(/\&/,$line,12);
12391: unless (($testdir&$dirptr) ||
12392: ($file_name =~ /^\.\.?$/)) {
12393: $currsubfile{$path}{$file_name} = [$size,$mtime];
12394: }
12395: }
12396: }
12397: }
1.984 raeburn 12398: }
12399: }
12400: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 12401: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 12402: my $item = $path.'/'.$file;
12403: unless ($mapping{$item} eq $item) {
12404: $pathchanges{$item} = 1;
12405: }
12406: $existing{$item} = 1;
12407: $numexisting ++;
12408: } else {
12409: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 12410: }
12411: }
1.1071 raeburn 12412: if ($actionurl eq '/adm/dependencies') {
12413: foreach my $path (keys(%currsubfile)) {
12414: if (ref($currsubfile{$path}) eq 'HASH') {
12415: foreach my $file (keys(%{$currsubfile{$path}})) {
12416: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 12417: next if (($rem ne '') &&
12418: (($env{"httpref.$rem"."$path/$file"} ne '') ||
12419: (ref($navmap) &&
12420: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
12421: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12422: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 12423: $unused{$path.'/'.$file} = 1;
12424: }
12425: }
12426: }
12427: }
12428: }
1.984 raeburn 12429: }
1.1249 damieng 12430:
12431: # fills $currfile, hash file name -> 1 or [$size,$mtime]
12432: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 12433: my %currfile;
1.1123 raeburn 12434: if (($actionurl eq '/adm/portfolio') ||
12435: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12436: my ($dirlistref,$listerror) =
12437: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
12438: if (ref($dirlistref) eq 'ARRAY') {
12439: foreach my $line (@{$dirlistref}) {
12440: my ($file_name,$rest) = split(/\&/,$line,2);
12441: $currfile{$file_name} = 1;
12442: }
1.984 raeburn 12443: }
1.987 raeburn 12444: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12445: if (opendir(my $dir,$url)) {
1.987 raeburn 12446: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 12447: map {$currfile{$_} = 1;} @dir_list;
12448: }
1.1084 raeburn 12449: } elsif (($actionurl eq '/adm/dependencies') ||
12450: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12451: ($args->{'context'} eq 'paste')) ||
12452: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12453: if ($env{'request.course.id'} ne '') {
12454: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12455: if ($dir ne '') {
12456: my ($dirlistref,$listerror) =
12457: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
12458: if (ref($dirlistref) eq 'ARRAY') {
12459: foreach my $line (@{$dirlistref}) {
12460: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
12461: $size,undef,$mtime)=split(/\&/,$line,12);
12462: unless (($testdir&$dirptr) ||
12463: ($file_name =~ /^\.\.?$/)) {
12464: $currfile{$file_name} = [$size,$mtime];
12465: }
12466: }
12467: }
12468: }
12469: }
1.984 raeburn 12470: }
1.1249 damieng 12471: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
12472: # are not in subdirectories, using $currfile
1.984 raeburn 12473: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 12474: if (exists($currfile{$file})) {
1.987 raeburn 12475: unless ($mapping{$file} eq $file) {
12476: $pathchanges{$file} = 1;
12477: }
12478: $existing{$file} = 1;
12479: $numexisting ++;
12480: } else {
1.984 raeburn 12481: $newfiles{$file} = 1;
12482: }
12483: }
1.1071 raeburn 12484: foreach my $file (keys(%currfile)) {
12485: unless (($file eq $filename) ||
12486: ($file eq $filename.'.bak') ||
12487: ($dependencies{$file})) {
1.1085 raeburn 12488: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 12489: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
12490: next if (($rem ne '') &&
12491: (($env{"httpref.$rem".$file} ne '') ||
12492: (ref($navmap) &&
12493: (($navmap->getResourceByUrl($rem.$file) ne '') ||
12494: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12495: ($navmap->getResourceByUrl($rem.$1)))))));
12496: }
1.1085 raeburn 12497: }
1.1071 raeburn 12498: $unused{$file} = 1;
12499: }
12500: }
1.1249 damieng 12501:
12502: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 12503: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
12504: ($args->{'context'} eq 'paste')) {
12505: $counter = scalar(keys(%existing));
12506: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 12507: return ($output,$counter,$numpathchg,\%existing);
12508: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
12509: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
12510: $counter = scalar(keys(%existing));
12511: $numpathchg = scalar(keys(%pathchanges));
12512: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 12513: }
1.1249 damieng 12514:
12515: # returns HTML otherwise, with dependency results and to ask for more uploads
12516:
12517: # $upload_output: missing dependencies (with upload form)
12518: # $modify_output: uploaded dependencies (in use)
12519: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 12520: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 12521: if ($actionurl eq '/adm/dependencies') {
12522: next if ($embed_file =~ m{^\w+://});
12523: }
1.660 raeburn 12524: $upload_output .= &start_data_table_row().
1.1123 raeburn 12525: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 12526: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 12527: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 12528: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
12529: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 12530: }
1.1123 raeburn 12531: $upload_output .= '</td>';
1.1071 raeburn 12532: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 12533: $upload_output.='<td align="right">'.
12534: '<span class="LC_info LC_fontsize_medium">'.
12535: &mt("URL points to web address").'</span>';
1.987 raeburn 12536: $numremref++;
1.660 raeburn 12537: } elsif ($args->{'error_on_invalid_names'}
12538: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 12539: $upload_output.='<td align="right"><span class="LC_warning">'.
12540: &mt('Invalid characters').'</span>';
1.987 raeburn 12541: $numinvalid++;
1.660 raeburn 12542: } else {
1.1123 raeburn 12543: $upload_output .= '<td>'.
12544: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 12545: $embed_file,\%mapping,
1.1071 raeburn 12546: $allfiles,$codebase,'upload');
12547: $counter ++;
12548: $numnew ++;
1.987 raeburn 12549: }
12550: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
12551: }
12552: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 12553: if ($actionurl eq '/adm/dependencies') {
12554: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
12555: $modify_output .= &start_data_table_row().
12556: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
12557: '<img src="'.&icon($embed_file).'" border="0" />'.
12558: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
12559: '<td>'.$size.'</td>'.
12560: '<td>'.$mtime.'</td>'.
12561: '<td><label><input type="checkbox" name="mod_upload_dep" '.
12562: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
12563: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
12564: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
12565: &embedded_file_element('upload_embedded',$counter,
12566: $embed_file,\%mapping,
12567: $allfiles,$codebase,'modify').
12568: '</div></td>'.
12569: &end_data_table_row()."\n";
12570: $counter ++;
12571: } else {
12572: $upload_output .= &start_data_table_row().
1.1123 raeburn 12573: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
12574: '<span class="LC_filename">'.$embed_file.'</span></td>'.
12575: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 12576: &Apache::loncommon::end_data_table_row()."\n";
12577: }
12578: }
12579: my $delidx = $counter;
12580: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
12581: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
12582: $delete_output .= &start_data_table_row().
12583: '<td><img src="'.&icon($oldfile).'" />'.
12584: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
12585: '<td>'.$size.'</td>'.
12586: '<td>'.$mtime.'</td>'.
12587: '<td><label><input type="checkbox" name="del_upload_dep" '.
12588: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12589: &embedded_file_element('upload_embedded',$delidx,
12590: $oldfile,\%mapping,$allfiles,
12591: $codebase,'delete').'</td>'.
12592: &end_data_table_row()."\n";
12593: $numunused ++;
12594: $delidx ++;
1.987 raeburn 12595: }
12596: if ($upload_output) {
12597: $upload_output = &start_data_table().
12598: $upload_output.
12599: &end_data_table()."\n";
12600: }
1.1071 raeburn 12601: if ($modify_output) {
12602: $modify_output = &start_data_table().
12603: &start_data_table_header_row().
12604: '<th>'.&mt('File').'</th>'.
12605: '<th>'.&mt('Size (KB)').'</th>'.
12606: '<th>'.&mt('Modified').'</th>'.
12607: '<th>'.&mt('Upload replacement?').'</th>'.
12608: &end_data_table_header_row().
12609: $modify_output.
12610: &end_data_table()."\n";
12611: }
12612: if ($delete_output) {
12613: $delete_output = &start_data_table().
12614: &start_data_table_header_row().
12615: '<th>'.&mt('File').'</th>'.
12616: '<th>'.&mt('Size (KB)').'</th>'.
12617: '<th>'.&mt('Modified').'</th>'.
12618: '<th>'.&mt('Delete?').'</th>'.
12619: &end_data_table_header_row().
12620: $delete_output.
12621: &end_data_table()."\n";
12622: }
1.987 raeburn 12623: my $applies = 0;
12624: if ($numremref) {
12625: $applies ++;
12626: }
12627: if ($numinvalid) {
12628: $applies ++;
12629: }
12630: if ($numexisting) {
12631: $applies ++;
12632: }
1.1071 raeburn 12633: if ($counter || $numunused) {
1.987 raeburn 12634: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12635: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12636: $state.'<h3>'.$heading.'</h3>';
12637: if ($actionurl eq '/adm/dependencies') {
12638: if ($numnew) {
12639: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12640: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12641: $upload_output.'<br />'."\n";
12642: }
12643: if ($numexisting) {
12644: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12645: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12646: $modify_output.'<br />'."\n";
12647: $buttontext = &mt('Save changes');
12648: }
12649: if ($numunused) {
12650: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12651: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12652: $delete_output.'<br />'."\n";
12653: $buttontext = &mt('Save changes');
12654: }
12655: } else {
12656: $output .= $upload_output.'<br />'."\n";
12657: }
12658: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12659: $counter.'" />'."\n";
12660: if ($actionurl eq '/adm/dependencies') {
12661: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12662: $numnew.'" />'."\n";
12663: } elsif ($actionurl eq '') {
1.987 raeburn 12664: $output .= '<input type="hidden" name="phase" value="three" />';
12665: }
12666: } elsif ($applies) {
12667: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12668: if ($applies > 1) {
12669: $output .=
1.1123 raeburn 12670: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12671: if ($numremref) {
12672: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12673: }
12674: if ($numinvalid) {
12675: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12676: }
12677: if ($numexisting) {
12678: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12679: }
12680: $output .= '</ul><br />';
12681: } elsif ($numremref) {
12682: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12683: } elsif ($numinvalid) {
12684: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12685: } elsif ($numexisting) {
12686: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12687: }
12688: $output .= $upload_output.'<br />';
12689: }
12690: my ($pathchange_output,$chgcount);
1.1071 raeburn 12691: $chgcount = $counter;
1.987 raeburn 12692: if (keys(%pathchanges) > 0) {
12693: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12694: if ($counter) {
1.987 raeburn 12695: $output .= &embedded_file_element('pathchange',$chgcount,
12696: $embed_file,\%mapping,
1.1071 raeburn 12697: $allfiles,$codebase,'change');
1.987 raeburn 12698: } else {
12699: $pathchange_output .=
12700: &start_data_table_row().
12701: '<td><input type ="checkbox" name="namechange" value="'.
12702: $chgcount.'" checked="checked" /></td>'.
12703: '<td>'.$mapping{$embed_file}.'</td>'.
12704: '<td>'.$embed_file.
12705: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12706: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12707: '</td>'.&end_data_table_row();
1.660 raeburn 12708: }
1.987 raeburn 12709: $numpathchg ++;
12710: $chgcount ++;
1.660 raeburn 12711: }
12712: }
1.1127 raeburn 12713: if (($counter) || ($numunused)) {
1.987 raeburn 12714: if ($numpathchg) {
12715: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12716: $numpathchg.'" />'."\n";
12717: }
12718: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12719: ($actionurl eq '/adm/imsimport')) {
12720: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12721: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12722: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12723: } elsif ($actionurl eq '/adm/dependencies') {
12724: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12725: }
1.1123 raeburn 12726: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12727: } elsif ($numpathchg) {
12728: my %pathchange = ();
12729: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12730: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12731: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 12732: }
1.987 raeburn 12733: }
1.1071 raeburn 12734: return ($output,$counter,$numpathchg);
1.987 raeburn 12735: }
12736:
1.1147 raeburn 12737: =pod
12738:
12739: =item * clean_path($name)
12740:
12741: Performs clean-up of directories, subdirectories and filename in an
12742: embedded object, referenced in an HTML file which is being uploaded
12743: to a course or portfolio, where
12744: "Upload embedded images/multimedia files if HTML file" checkbox was
12745: checked.
12746:
12747: Clean-up is similar to replacements in lonnet::clean_filename()
12748: except each / between sub-directory and next level is preserved.
12749:
12750: =cut
12751:
12752: sub clean_path {
12753: my ($embed_file) = @_;
12754: $embed_file =~s{^/+}{};
12755: my @contents;
12756: if ($embed_file =~ m{/}) {
12757: @contents = split(/\//,$embed_file);
12758: } else {
12759: @contents = ($embed_file);
12760: }
12761: my $lastidx = scalar(@contents)-1;
12762: for (my $i=0; $i<=$lastidx; $i++) {
12763: $contents[$i]=~s{\\}{/}g;
12764: $contents[$i]=~s/\s+/\_/g;
12765: $contents[$i]=~s{[^/\w\.\-]}{}g;
12766: if ($i == $lastidx) {
12767: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12768: }
12769: }
12770: if ($lastidx > 0) {
12771: return join('/',@contents);
12772: } else {
12773: return $contents[0];
12774: }
12775: }
12776:
1.987 raeburn 12777: sub embedded_file_element {
1.1071 raeburn 12778: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12779: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12780: (ref($codebase) eq 'HASH'));
12781: my $output;
1.1071 raeburn 12782: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12783: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12784: }
12785: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12786: &escape($embed_file).'" />';
12787: unless (($context eq 'upload_embedded') &&
12788: ($mapping->{$embed_file} eq $embed_file)) {
12789: $output .='
12790: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12791: }
12792: my $attrib;
12793: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12794: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12795: }
12796: $output .=
12797: "\n\t\t".
12798: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12799: $attrib.'" />';
12800: if (exists($codebase->{$mapping->{$embed_file}})) {
12801: $output .=
12802: "\n\t\t".
12803: '<input name="codebase_'.$num.'" type="hidden" value="'.
12804: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12805: }
1.987 raeburn 12806: return $output;
1.660 raeburn 12807: }
12808:
1.1071 raeburn 12809: sub get_dependency_details {
12810: my ($currfile,$currsubfile,$embed_file) = @_;
12811: my ($size,$mtime,$showsize,$showmtime);
12812: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12813: if ($embed_file =~ m{/}) {
12814: my ($path,$fname) = split(/\//,$embed_file);
12815: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12816: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12817: }
12818: } else {
12819: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12820: ($size,$mtime) = @{$currfile->{$embed_file}};
12821: }
12822: }
12823: $showsize = $size/1024.0;
12824: $showsize = sprintf("%.1f",$showsize);
12825: if ($mtime > 0) {
12826: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12827: }
12828: }
12829: return ($showsize,$showmtime);
12830: }
12831:
12832: sub ask_embedded_js {
12833: return <<"END";
12834: <script type="text/javascript"">
12835: // <![CDATA[
12836: function toggleBrowse(counter) {
12837: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12838: var fileid = document.getElementById('embedded_item_'+counter);
12839: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12840: if (chkboxid.checked == true) {
12841: uploaddivid.style.display='block';
12842: } else {
12843: uploaddivid.style.display='none';
12844: fileid.value = '';
12845: }
12846: }
12847: // ]]>
12848: </script>
12849:
12850: END
12851: }
12852:
1.661 raeburn 12853: sub upload_embedded {
12854: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12855: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12856: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12857: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12858: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12859: my $orig_uploaded_filename =
12860: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12861: foreach my $type ('orig','ref','attrib','codebase') {
12862: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12863: $env{'form.embedded_'.$type.'_'.$i} =
12864: &unescape($env{'form.embedded_'.$type.'_'.$i});
12865: }
12866: }
1.661 raeburn 12867: my ($path,$fname) =
12868: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12869: # no path, whole string is fname
12870: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12871: $fname = &Apache::lonnet::clean_filename($fname);
12872: # See if there is anything left
12873: next if ($fname eq '');
12874:
12875: # Check if file already exists as a file or directory.
12876: my ($state,$msg);
12877: if ($context eq 'portfolio') {
12878: my $port_path = $dirpath;
12879: if ($group ne '') {
12880: $port_path = "groups/$group/$port_path";
12881: }
1.987 raeburn 12882: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12883: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12884: $dir_root,$port_path,$disk_quota,
12885: $current_disk_usage,$uname,$udom);
12886: if ($state eq 'will_exceed_quota'
1.984 raeburn 12887: || $state eq 'file_locked') {
1.661 raeburn 12888: $output .= $msg;
12889: next;
12890: }
12891: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12892: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12893: if ($state eq 'exists') {
12894: $output .= $msg;
12895: next;
12896: }
12897: }
12898: # Check if extension is valid
12899: if (($fname =~ /\.(\w+)$/) &&
12900: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12901: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12902: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12903: next;
12904: } elsif (($fname =~ /\.(\w+)$/) &&
12905: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12906: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12907: next;
12908: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12909: $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 12910: next;
12911: }
12912: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12913: my $subdir = $path;
12914: $subdir =~ s{/+$}{};
1.661 raeburn 12915: if ($context eq 'portfolio') {
1.984 raeburn 12916: my $result;
12917: if ($state eq 'existingfile') {
12918: $result=
12919: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12920: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12921: } else {
1.984 raeburn 12922: $result=
12923: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12924: $dirpath.
1.1123 raeburn 12925: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12926: if ($result !~ m|^/uploaded/|) {
12927: $output .= '<span class="LC_error">'
12928: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12929: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12930: .'</span><br />';
12931: next;
12932: } else {
1.987 raeburn 12933: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12934: $path.$fname.'</span>').'<br />';
1.984 raeburn 12935: }
1.661 raeburn 12936: }
1.1123 raeburn 12937: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12938: my $extendedsubdir = $dirpath.'/'.$subdir;
12939: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12940: my $result =
1.1126 raeburn 12941: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12942: if ($result !~ m|^/uploaded/|) {
12943: $output .= '<span class="LC_error">'
12944: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12945: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12946: .'</span><br />';
12947: next;
12948: } else {
12949: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12950: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12951: if ($context eq 'syllabus') {
12952: &Apache::lonnet::make_public_indefinitely($result);
12953: }
1.987 raeburn 12954: }
1.661 raeburn 12955: } else {
12956: # Save the file
12957: my $target = $env{'form.embedded_item_'.$i};
12958: my $fullpath = $dir_root.$dirpath.'/'.$path;
12959: my $dest = $fullpath.$fname;
12960: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12961: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12962: my $count;
12963: my $filepath = $dir_root;
1.1027 raeburn 12964: foreach my $subdir (@parts) {
12965: $filepath .= "/$subdir";
12966: if (!-e $filepath) {
1.661 raeburn 12967: mkdir($filepath,0770);
12968: }
12969: }
12970: my $fh;
12971: if (!open($fh,'>'.$dest)) {
12972: &Apache::lonnet::logthis('Failed to create '.$dest);
12973: $output .= '<span class="LC_error">'.
1.1071 raeburn 12974: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12975: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12976: '</span><br />';
12977: } else {
12978: if (!print $fh $env{'form.embedded_item_'.$i}) {
12979: &Apache::lonnet::logthis('Failed to write to '.$dest);
12980: $output .= '<span class="LC_error">'.
1.1071 raeburn 12981: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12982: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12983: '</span><br />';
12984: } else {
1.987 raeburn 12985: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12986: $url.'</span>').'<br />';
12987: unless ($context eq 'testbank') {
12988: $footer .= &mt('View embedded file: [_1]',
12989: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12990: }
12991: }
12992: close($fh);
12993: }
12994: }
12995: if ($env{'form.embedded_ref_'.$i}) {
12996: $pathchange{$i} = 1;
12997: }
12998: }
12999: if ($output) {
13000: $output = '<p>'.$output.'</p>';
13001: }
13002: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
13003: $returnflag = 'ok';
1.1071 raeburn 13004: my $numpathchgs = scalar(keys(%pathchange));
13005: if ($numpathchgs > 0) {
1.987 raeburn 13006: if ($context eq 'portfolio') {
13007: $output .= '<p>'.&mt('or').'</p>';
13008: } elsif ($context eq 'testbank') {
1.1071 raeburn 13009: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
13010: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 13011: $returnflag = 'modify_orightml';
13012: }
13013: }
1.1071 raeburn 13014: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 13015: }
13016:
13017: sub modify_html_form {
13018: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
13019: my $end = 0;
13020: my $modifyform;
13021: if ($context eq 'upload_embedded') {
13022: return unless (ref($pathchange) eq 'HASH');
13023: if ($env{'form.number_embedded_items'}) {
13024: $end += $env{'form.number_embedded_items'};
13025: }
13026: if ($env{'form.number_pathchange_items'}) {
13027: $end += $env{'form.number_pathchange_items'};
13028: }
13029: if ($end) {
13030: for (my $i=0; $i<$end; $i++) {
13031: if ($i < $env{'form.number_embedded_items'}) {
13032: next unless($pathchange->{$i});
13033: }
13034: $modifyform .=
13035: &start_data_table_row().
13036: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
13037: 'checked="checked" /></td>'.
13038: '<td>'.$env{'form.embedded_ref_'.$i}.
13039: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
13040: &escape($env{'form.embedded_ref_'.$i}).'" />'.
13041: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
13042: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
13043: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
13044: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
13045: '<td>'.$env{'form.embedded_orig_'.$i}.
13046: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
13047: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
13048: &end_data_table_row();
1.1071 raeburn 13049: }
1.987 raeburn 13050: }
13051: } else {
13052: $modifyform = $pathchgtable;
13053: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
13054: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
13055: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
13056: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
13057: }
13058: }
13059: if ($modifyform) {
1.1071 raeburn 13060: if ($actionurl eq '/adm/dependencies') {
13061: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
13062: }
1.987 raeburn 13063: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
13064: '<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".
13065: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
13066: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
13067: '</ol></p>'."\n".'<p>'.
13068: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
13069: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
13070: &start_data_table()."\n".
13071: &start_data_table_header_row().
13072: '<th>'.&mt('Change?').'</th>'.
13073: '<th>'.&mt('Current reference').'</th>'.
13074: '<th>'.&mt('Required reference').'</th>'.
13075: &end_data_table_header_row()."\n".
13076: $modifyform.
13077: &end_data_table().'<br />'."\n".$hiddenstate.
13078: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
13079: '</form>'."\n";
13080: }
13081: return;
13082: }
13083:
13084: sub modify_html_refs {
1.1123 raeburn 13085: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 13086: my $container;
13087: if ($context eq 'portfolio') {
13088: $container = $env{'form.container'};
13089: } elsif ($context eq 'coursedoc') {
13090: $container = $env{'form.primaryurl'};
1.1071 raeburn 13091: } elsif ($context eq 'manage_dependencies') {
13092: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
13093: $container = "/$container";
1.1123 raeburn 13094: } elsif ($context eq 'syllabus') {
13095: $container = $url;
1.987 raeburn 13096: } else {
1.1027 raeburn 13097: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 13098: }
13099: my (%allfiles,%codebase,$output,$content);
13100: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 13101: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 13102: if (wantarray) {
13103: return ('',0,0);
13104: } else {
13105: return;
13106: }
13107: }
13108: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13109: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 13110: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
13111: if (wantarray) {
13112: return ('',0,0);
13113: } else {
13114: return;
13115: }
13116: }
1.987 raeburn 13117: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 13118: if ($content eq '-1') {
13119: if (wantarray) {
13120: return ('',0,0);
13121: } else {
13122: return;
13123: }
13124: }
1.987 raeburn 13125: } else {
1.1071 raeburn 13126: unless ($container =~ /^\Q$dir_root\E/) {
13127: if (wantarray) {
13128: return ('',0,0);
13129: } else {
13130: return;
13131: }
13132: }
1.1317 raeburn 13133: if (open(my $fh,'<',$container)) {
1.987 raeburn 13134: $content = join('', <$fh>);
13135: close($fh);
13136: } else {
1.1071 raeburn 13137: if (wantarray) {
13138: return ('',0,0);
13139: } else {
13140: return;
13141: }
1.987 raeburn 13142: }
13143: }
13144: my ($count,$codebasecount) = (0,0);
13145: my $mm = new File::MMagic;
13146: my $mime_type = $mm->checktype_contents($content);
13147: if ($mime_type eq 'text/html') {
13148: my $parse_result =
13149: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
13150: \%codebase,\$content);
13151: if ($parse_result eq 'ok') {
13152: foreach my $i (@changes) {
13153: my $orig = &unescape($env{'form.embedded_orig_'.$i});
13154: my $ref = &unescape($env{'form.embedded_ref_'.$i});
13155: if ($allfiles{$ref}) {
13156: my $newname = $orig;
13157: my ($attrib_regexp,$codebase);
1.1006 raeburn 13158: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 13159: if ($attrib_regexp =~ /:/) {
13160: $attrib_regexp =~ s/\:/|/g;
13161: }
13162: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13163: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13164: $count += $numchg;
1.1123 raeburn 13165: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 13166: delete($allfiles{$ref});
1.987 raeburn 13167: }
13168: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 13169: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 13170: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
13171: $codebasecount ++;
13172: }
13173: }
13174: }
1.1123 raeburn 13175: my $skiprewrites;
1.987 raeburn 13176: if ($count || $codebasecount) {
13177: my $saveresult;
1.1071 raeburn 13178: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13179: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 13180: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13181: if ($url eq $container) {
13182: my ($fname) = ($container =~ m{/([^/]+)$});
13183: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13184: $count,'<span class="LC_filename">'.
1.1071 raeburn 13185: $fname.'</span>').'</p>';
1.987 raeburn 13186: } else {
13187: $output = '<p class="LC_error">'.
13188: &mt('Error: update failed for: [_1].',
13189: '<span class="LC_filename">'.
13190: $container.'</span>').'</p>';
13191: }
1.1123 raeburn 13192: if ($context eq 'syllabus') {
13193: unless ($saveresult eq 'ok') {
13194: $skiprewrites = 1;
13195: }
13196: }
1.987 raeburn 13197: } else {
1.1317 raeburn 13198: if (open(my $fh,'>',$container)) {
1.987 raeburn 13199: print $fh $content;
13200: close($fh);
13201: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13202: $count,'<span class="LC_filename">'.
13203: $container.'</span>').'</p>';
1.661 raeburn 13204: } else {
1.987 raeburn 13205: $output = '<p class="LC_error">'.
13206: &mt('Error: could not update [_1].',
13207: '<span class="LC_filename">'.
13208: $container.'</span>').'</p>';
1.661 raeburn 13209: }
13210: }
13211: }
1.1123 raeburn 13212: if (($context eq 'syllabus') && (!$skiprewrites)) {
13213: my ($actionurl,$state);
13214: $actionurl = "/public/$udom/$uname/syllabus";
13215: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
13216: &ask_for_embedded_content($actionurl,$state,\%allfiles,
13217: \%codebase,
13218: {'context' => 'rewrites',
13219: 'ignore_remote_references' => 1,});
13220: if (ref($mapping) eq 'HASH') {
13221: my $rewrites = 0;
13222: foreach my $key (keys(%{$mapping})) {
13223: next if ($key =~ m{^https?://});
13224: my $ref = $mapping->{$key};
13225: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
13226: my $attrib;
13227: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
13228: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
13229: }
13230: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13231: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13232: $rewrites += $numchg;
13233: }
13234: }
13235: if ($rewrites) {
13236: my $saveresult;
13237: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13238: if ($url eq $container) {
13239: my ($fname) = ($container =~ m{/([^/]+)$});
13240: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
13241: $count,'<span class="LC_filename">'.
13242: $fname.'</span>').'</p>';
13243: } else {
13244: $output .= '<p class="LC_error">'.
13245: &mt('Error: could not update links in [_1].',
13246: '<span class="LC_filename">'.
13247: $container.'</span>').'</p>';
13248:
13249: }
13250: }
13251: }
13252: }
1.987 raeburn 13253: } else {
13254: &logthis('Failed to parse '.$container.
13255: ' to modify references: '.$parse_result);
1.661 raeburn 13256: }
13257: }
1.1071 raeburn 13258: if (wantarray) {
13259: return ($output,$count,$codebasecount);
13260: } else {
13261: return $output;
13262: }
1.661 raeburn 13263: }
13264:
13265: sub check_for_existing {
13266: my ($path,$fname,$element) = @_;
13267: my ($state,$msg);
13268: if (-d $path.'/'.$fname) {
13269: $state = 'exists';
13270: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13271: } elsif (-e $path.'/'.$fname) {
13272: $state = 'exists';
13273: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13274: }
13275: if ($state eq 'exists') {
13276: $msg = '<span class="LC_error">'.$msg.'</span><br />';
13277: }
13278: return ($state,$msg);
13279: }
13280:
13281: sub check_for_upload {
13282: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
13283: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 13284: my $filesize = length($env{'form.'.$element});
13285: if (!$filesize) {
13286: my $msg = '<span class="LC_error">'.
13287: &mt('Unable to upload [_1]. (size = [_2] bytes)',
13288: '<span class="LC_filename">'.$fname.'</span>',
13289: $filesize).'<br />'.
1.1007 raeburn 13290: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 13291: '</span>';
13292: return ('zero_bytes',$msg);
13293: }
13294: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 13295: my $getpropath = 1;
1.1021 raeburn 13296: my ($dirlistref,$listerror) =
13297: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 13298: my $found_file = 0;
13299: my $locked_file = 0;
1.991 raeburn 13300: my @lockers;
13301: my $navmap;
13302: if ($env{'request.course.id'}) {
13303: $navmap = Apache::lonnavmaps::navmap->new();
13304: }
1.1021 raeburn 13305: if (ref($dirlistref) eq 'ARRAY') {
13306: foreach my $line (@{$dirlistref}) {
13307: my ($file_name,$rest)=split(/\&/,$line,2);
13308: if ($file_name eq $fname){
13309: $file_name = $path.$file_name;
13310: if ($group ne '') {
13311: $file_name = $group.$file_name;
13312: }
13313: $found_file = 1;
13314: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
13315: foreach my $lock (@lockers) {
13316: if (ref($lock) eq 'ARRAY') {
13317: my ($symb,$crsid) = @{$lock};
13318: if ($crsid eq $env{'request.course.id'}) {
13319: if (ref($navmap)) {
13320: my $res = $navmap->getBySymb($symb);
13321: foreach my $part (@{$res->parts()}) {
13322: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
13323: unless (($slot_status == $res->RESERVED) ||
13324: ($slot_status == $res->RESERVED_LOCATION)) {
13325: $locked_file = 1;
13326: }
1.991 raeburn 13327: }
1.1021 raeburn 13328: } else {
13329: $locked_file = 1;
1.991 raeburn 13330: }
13331: } else {
13332: $locked_file = 1;
13333: }
13334: }
1.1021 raeburn 13335: }
13336: } else {
13337: my @info = split(/\&/,$rest);
13338: my $currsize = $info[6]/1000;
13339: if ($currsize < $filesize) {
13340: my $extra = $filesize - $currsize;
13341: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 13342: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 13343: &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 13344: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
13345: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
13346: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 13347: return ('will_exceed_quota',$msg);
13348: }
1.984 raeburn 13349: }
13350: }
1.661 raeburn 13351: }
13352: }
13353: }
13354: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 13355: my $msg = '<p class="LC_warning">'.
13356: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 13357: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 13358: return ('will_exceed_quota',$msg);
13359: } elsif ($found_file) {
13360: if ($locked_file) {
1.1179 bisitz 13361: my $msg = '<p class="LC_warning">';
1.661 raeburn 13362: $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 13363: $msg .= '</p>';
1.661 raeburn 13364: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
13365: return ('file_locked',$msg);
13366: } else {
1.1179 bisitz 13367: my $msg = '<p class="LC_error">';
1.984 raeburn 13368: $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 13369: $msg .= '</p>';
1.984 raeburn 13370: return ('existingfile',$msg);
1.661 raeburn 13371: }
13372: }
13373: }
13374:
1.987 raeburn 13375: sub check_for_traversal {
13376: my ($path,$url,$toplevel) = @_;
13377: my @parts=split(/\//,$path);
13378: my $cleanpath;
13379: my $fullpath = $url;
13380: for (my $i=0;$i<@parts;$i++) {
13381: next if ($parts[$i] eq '.');
13382: if ($parts[$i] eq '..') {
13383: $fullpath =~ s{([^/]+/)$}{};
13384: } else {
13385: $fullpath .= $parts[$i].'/';
13386: }
13387: }
13388: if ($fullpath =~ /^\Q$url\E(.*)$/) {
13389: $cleanpath = $1;
13390: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
13391: my $curr_toprel = $1;
13392: my @parts = split(/\//,$curr_toprel);
13393: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
13394: my @urlparts = split(/\//,$url_toprel);
13395: my $doubledots;
13396: my $startdiff = -1;
13397: for (my $i=0; $i<@urlparts; $i++) {
13398: if ($startdiff == -1) {
13399: unless ($urlparts[$i] eq $parts[$i]) {
13400: $startdiff = $i;
13401: $doubledots .= '../';
13402: }
13403: } else {
13404: $doubledots .= '../';
13405: }
13406: }
13407: if ($startdiff > -1) {
13408: $cleanpath = $doubledots;
13409: for (my $i=$startdiff; $i<@parts; $i++) {
13410: $cleanpath .= $parts[$i].'/';
13411: }
13412: }
13413: }
13414: $cleanpath =~ s{(/)$}{};
13415: return $cleanpath;
13416: }
1.31 albertel 13417:
1.1053 raeburn 13418: sub is_archive_file {
13419: my ($mimetype) = @_;
13420: if (($mimetype eq 'application/octet-stream') ||
13421: ($mimetype eq 'application/x-stuffit') ||
13422: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
13423: return 1;
13424: }
13425: return;
13426: }
13427:
13428: sub decompress_form {
1.1065 raeburn 13429: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 13430: my %lt = &Apache::lonlocal::texthash (
13431: this => 'This file is an archive file.',
1.1067 raeburn 13432: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 13433: itsc => 'Its contents are as follows:',
1.1053 raeburn 13434: youm => 'You may wish to extract its contents.',
13435: extr => 'Extract contents',
1.1067 raeburn 13436: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
13437: proa => 'Process automatically?',
1.1053 raeburn 13438: yes => 'Yes',
13439: no => 'No',
1.1067 raeburn 13440: fold => 'Title for folder containing movie',
13441: movi => 'Title for page containing embedded movie',
1.1053 raeburn 13442: );
1.1065 raeburn 13443: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 13444: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 13445: my $info = &list_archive_contents($fileloc,\@paths);
13446: if (@paths) {
13447: foreach my $path (@paths) {
13448: $path =~ s{^/}{};
1.1067 raeburn 13449: if ($path =~ m{^([^/]+)/$}) {
13450: $topdir = $1;
13451: }
1.1065 raeburn 13452: if ($path =~ m{^([^/]+)/}) {
13453: $toplevel{$1} = $path;
13454: } else {
13455: $toplevel{$path} = $path;
13456: }
13457: }
13458: }
1.1067 raeburn 13459: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 13460: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 13461: "$topdir/media/",
13462: "$topdir/media/$topdir.mp4",
13463: "$topdir/media/FirstFrame.png",
13464: "$topdir/media/player.swf",
13465: "$topdir/media/swfobject.js",
13466: "$topdir/media/expressInstall.swf");
1.1197 raeburn 13467: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 13468: "$topdir/$topdir.mp4",
13469: "$topdir/$topdir\_config.xml",
13470: "$topdir/$topdir\_controller.swf",
13471: "$topdir/$topdir\_embed.css",
13472: "$topdir/$topdir\_First_Frame.png",
13473: "$topdir/$topdir\_player.html",
13474: "$topdir/$topdir\_Thumbnails.png",
13475: "$topdir/playerProductInstall.swf",
13476: "$topdir/scripts/",
13477: "$topdir/scripts/config_xml.js",
13478: "$topdir/scripts/handlebars.js",
13479: "$topdir/scripts/jquery-1.7.1.min.js",
13480: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
13481: "$topdir/scripts/modernizr.js",
13482: "$topdir/scripts/player-min.js",
13483: "$topdir/scripts/swfobject.js",
13484: "$topdir/skins/",
13485: "$topdir/skins/configuration_express.xml",
13486: "$topdir/skins/express_show/",
13487: "$topdir/skins/express_show/player-min.css",
13488: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 13489: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
13490: "$topdir/$topdir.mp4",
13491: "$topdir/$topdir\_config.xml",
13492: "$topdir/$topdir\_controller.swf",
13493: "$topdir/$topdir\_embed.css",
13494: "$topdir/$topdir\_First_Frame.png",
13495: "$topdir/$topdir\_player.html",
13496: "$topdir/$topdir\_Thumbnails.png",
13497: "$topdir/playerProductInstall.swf",
13498: "$topdir/scripts/",
13499: "$topdir/scripts/config_xml.js",
13500: "$topdir/scripts/techsmith-smart-player.min.js",
13501: "$topdir/skins/",
13502: "$topdir/skins/configuration_express.xml",
13503: "$topdir/skins/express_show/",
13504: "$topdir/skins/express_show/spritesheet.min.css",
13505: "$topdir/skins/express_show/spritesheet.png",
13506: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 13507: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 13508: if (@diffs == 0) {
1.1164 raeburn 13509: $is_camtasia = 6;
13510: } else {
1.1197 raeburn 13511: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 13512: if (@diffs == 0) {
13513: $is_camtasia = 8;
1.1197 raeburn 13514: } else {
13515: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
13516: if (@diffs == 0) {
13517: $is_camtasia = 8;
13518: }
1.1164 raeburn 13519: }
1.1067 raeburn 13520: }
13521: }
13522: my $output;
13523: if ($is_camtasia) {
13524: $output = <<"ENDCAM";
13525: <script type="text/javascript" language="Javascript">
13526: // <![CDATA[
13527:
13528: function camtasiaToggle() {
13529: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
13530: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 13531: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 13532: document.getElementById('camtasia_titles').style.display='block';
13533: } else {
13534: document.getElementById('camtasia_titles').style.display='none';
13535: }
13536: }
13537: }
13538: return;
13539: }
13540:
13541: // ]]>
13542: </script>
13543: <p>$lt{'camt'}</p>
13544: ENDCAM
1.1065 raeburn 13545: } else {
1.1067 raeburn 13546: $output = '<p>'.$lt{'this'};
13547: if ($info eq '') {
13548: $output .= ' '.$lt{'youm'}.'</p>'."\n";
13549: } else {
13550: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
13551: '<div><pre>'.$info.'</pre></div>';
13552: }
1.1065 raeburn 13553: }
1.1067 raeburn 13554: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 13555: my $duplicates;
13556: my $num = 0;
13557: if (ref($dirlist) eq 'ARRAY') {
13558: foreach my $item (@{$dirlist}) {
13559: if (ref($item) eq 'ARRAY') {
13560: if (exists($toplevel{$item->[0]})) {
13561: $duplicates .=
13562: &start_data_table_row().
13563: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
13564: 'value="0" checked="checked" />'.&mt('No').'</label>'.
13565: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
13566: 'value="1" />'.&mt('Yes').'</label>'.
13567: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
13568: '<td>'.$item->[0].'</td>';
13569: if ($item->[2]) {
13570: $duplicates .= '<td>'.&mt('Directory').'</td>';
13571: } else {
13572: $duplicates .= '<td>'.&mt('File').'</td>';
13573: }
13574: $duplicates .= '<td>'.$item->[3].'</td>'.
13575: '<td>'.
13576: &Apache::lonlocal::locallocaltime($item->[4]).
13577: '</td>'.
13578: &end_data_table_row();
13579: $num ++;
13580: }
13581: }
13582: }
13583: }
13584: my $itemcount;
13585: if (@paths > 0) {
13586: $itemcount = scalar(@paths);
13587: } else {
13588: $itemcount = 1;
13589: }
1.1067 raeburn 13590: if ($is_camtasia) {
13591: $output .= $lt{'auto'}.'<br />'.
13592: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 13593: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13594: $lt{'yes'}.'</label> <label>'.
13595: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13596: $lt{'no'}.'</label></span><br />'.
13597: '<div id="camtasia_titles" style="display:block">'.
13598: &Apache::lonhtmlcommon::start_pick_box().
13599: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13600: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13601: &Apache::lonhtmlcommon::row_closure().
13602: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13603: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13604: &Apache::lonhtmlcommon::row_closure(1).
13605: &Apache::lonhtmlcommon::end_pick_box().
13606: '</div>';
13607: }
1.1065 raeburn 13608: $output .=
13609: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13610: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13611: "\n";
1.1065 raeburn 13612: if ($duplicates ne '') {
13613: $output .= '<p><span class="LC_warning">'.
13614: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13615: &start_data_table().
13616: &start_data_table_header_row().
13617: '<th>'.&mt('Overwrite?').'</th>'.
13618: '<th>'.&mt('Name').'</th>'.
13619: '<th>'.&mt('Type').'</th>'.
13620: '<th>'.&mt('Size').'</th>'.
13621: '<th>'.&mt('Last modified').'</th>'.
13622: &end_data_table_header_row().
13623: $duplicates.
13624: &end_data_table().
13625: '</p>';
13626: }
1.1067 raeburn 13627: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13628: if (ref($hiddenelements) eq 'HASH') {
13629: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13630: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13631: }
13632: }
13633: $output .= <<"END";
1.1067 raeburn 13634: <br />
1.1053 raeburn 13635: <input type="submit" name="decompress" value="$lt{'extr'}" />
13636: </form>
13637: $noextract
13638: END
13639: return $output;
13640: }
13641:
1.1065 raeburn 13642: sub decompression_utility {
13643: my ($program) = @_;
13644: my @utilities = ('tar','gunzip','bunzip2','unzip');
13645: my $location;
13646: if (grep(/^\Q$program\E$/,@utilities)) {
13647: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13648: '/usr/sbin/') {
13649: if (-x $dir.$program) {
13650: $location = $dir.$program;
13651: last;
13652: }
13653: }
13654: }
13655: return $location;
13656: }
13657:
13658: sub list_archive_contents {
13659: my ($file,$pathsref) = @_;
13660: my (@cmd,$output);
13661: my $needsregexp;
13662: if ($file =~ /\.zip$/) {
13663: @cmd = (&decompression_utility('unzip'),"-l");
13664: $needsregexp = 1;
13665: } elsif (($file =~ m/\.tar\.gz$/) ||
13666: ($file =~ /\.tgz$/)) {
13667: @cmd = (&decompression_utility('tar'),"-ztf");
13668: } elsif ($file =~ /\.tar\.bz2$/) {
13669: @cmd = (&decompression_utility('tar'),"-jtf");
13670: } elsif ($file =~ m|\.tar$|) {
13671: @cmd = (&decompression_utility('tar'),"-tf");
13672: }
13673: if (@cmd) {
13674: undef($!);
13675: undef($@);
13676: if (open(my $fh,"-|", @cmd, $file)) {
13677: while (my $line = <$fh>) {
13678: $output .= $line;
13679: chomp($line);
13680: my $item;
13681: if ($needsregexp) {
13682: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13683: } else {
13684: $item = $line;
13685: }
13686: if ($item ne '') {
13687: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13688: push(@{$pathsref},$item);
13689: }
13690: }
13691: }
13692: close($fh);
13693: }
13694: }
13695: return $output;
13696: }
13697:
1.1053 raeburn 13698: sub decompress_uploaded_file {
13699: my ($file,$dir) = @_;
13700: &Apache::lonnet::appenv({'cgi.file' => $file});
13701: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13702: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13703: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13704: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13705: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13706: my $decompressed = $env{'cgi.decompressed'};
13707: &Apache::lonnet::delenv('cgi.file');
13708: &Apache::lonnet::delenv('cgi.dir');
13709: &Apache::lonnet::delenv('cgi.decompressed');
13710: return ($decompressed,$result);
13711: }
13712:
1.1055 raeburn 13713: sub process_decompression {
13714: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 13715: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13716: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13717: &mt('Unexpected file path.').'</p>'."\n";
13718: }
13719: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13720: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13721: &mt('Unexpected course context.').'</p>'."\n";
13722: }
1.1293 raeburn 13723: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 13724: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13725: &mt('Filename contained unexpected characters.').'</p>'."\n";
13726: }
1.1055 raeburn 13727: my ($dir,$error,$warning,$output);
1.1180 raeburn 13728: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 13729: $error = &mt('Filename not a supported archive file type.').
13730: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13731: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13732: } else {
13733: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13734: if ($docuhome eq 'no_host') {
13735: $error = &mt('Could not determine home server for course.');
13736: } else {
13737: my @ids=&Apache::lonnet::current_machine_ids();
13738: my $currdir = "$dir_root/$destination";
13739: if (grep(/^\Q$docuhome\E$/,@ids)) {
13740: $dir = &LONCAPA::propath($docudom,$docuname).
13741: "$dir_root/$destination";
13742: } else {
13743: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13744: "$dir_root/$docudom/$docuname/$destination";
13745: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13746: $error = &mt('Archive file not found.');
13747: }
13748: }
1.1065 raeburn 13749: my (@to_overwrite,@to_skip);
13750: if ($env{'form.archive_overwrite_total'} > 0) {
13751: my $total = $env{'form.archive_overwrite_total'};
13752: for (my $i=0; $i<$total; $i++) {
13753: if ($env{'form.archive_overwrite_'.$i} == 1) {
13754: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13755: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13756: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13757: }
13758: }
13759: }
13760: my $numskip = scalar(@to_skip);
1.1292 raeburn 13761: my $numoverwrite = scalar(@to_overwrite);
13762: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13763: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13764: } elsif ($dir eq '') {
1.1055 raeburn 13765: $error = &mt('Directory containing archive file unavailable.');
13766: } elsif (!$error) {
1.1065 raeburn 13767: my ($decompressed,$display);
1.1292 raeburn 13768: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13769: my $tempdir = time.'_'.$$.int(rand(10000));
13770: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 13771: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13772: ($decompressed,$display) =
13773: &decompress_uploaded_file($file,"$dir/$tempdir");
13774: foreach my $item (@to_skip) {
13775: if (($item ne '') && ($item !~ /\.\./)) {
13776: if (-f "$dir/$tempdir/$item") {
13777: unlink("$dir/$tempdir/$item");
13778: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 13779: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 13780: }
13781: }
13782: }
13783: foreach my $item (@to_overwrite) {
13784: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13785: if (($item ne '') && ($item !~ /\.\./)) {
13786: if (-f "$dir/$item") {
13787: unlink("$dir/$item");
13788: } elsif (-d "$dir/$item") {
1.1300 raeburn 13789: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 13790: }
13791: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13792: }
1.1065 raeburn 13793: }
13794: }
1.1292 raeburn 13795: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 13796: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 13797: }
1.1065 raeburn 13798: }
13799: } else {
13800: ($decompressed,$display) =
13801: &decompress_uploaded_file($file,$dir);
13802: }
1.1055 raeburn 13803: if ($decompressed eq 'ok') {
1.1065 raeburn 13804: $output = '<p class="LC_info">'.
13805: &mt('Files extracted successfully from archive.').
13806: '</p>'."\n";
1.1055 raeburn 13807: my ($warning,$result,@contents);
13808: my ($newdirlistref,$newlisterror) =
13809: &Apache::lonnet::dirlist($currdir,$docudom,
13810: $docuname,1);
13811: my (%is_dir,%changes,@newitems);
13812: my $dirptr = 16384;
1.1065 raeburn 13813: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13814: foreach my $dir_line (@{$newdirlistref}) {
13815: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 13816: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13817: push(@newitems,$item);
13818: if ($dirptr&$testdir) {
13819: $is_dir{$item} = 1;
13820: }
13821: $changes{$item} = 1;
13822: }
13823: }
13824: }
13825: if (keys(%changes) > 0) {
13826: foreach my $item (sort(@newitems)) {
13827: if ($changes{$item}) {
13828: push(@contents,$item);
13829: }
13830: }
13831: }
13832: if (@contents > 0) {
1.1067 raeburn 13833: my $wantform;
13834: unless ($env{'form.autoextract_camtasia'}) {
13835: $wantform = 1;
13836: }
1.1056 raeburn 13837: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13838: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13839: $currdir,\%is_dir,
13840: \%children,\%parent,
1.1056 raeburn 13841: \@contents,\%dirorder,
13842: \%titles,$wantform);
1.1055 raeburn 13843: if ($datatable ne '') {
13844: $output .= &archive_options_form('decompressed',$datatable,
13845: $count,$hiddenelem);
1.1065 raeburn 13846: my $startcount = 6;
1.1055 raeburn 13847: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13848: \%titles,\%children);
1.1055 raeburn 13849: }
1.1067 raeburn 13850: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13851: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13852: my %displayed;
13853: my $total = 1;
13854: $env{'form.archive_directory'} = [];
13855: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13856: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13857: $path =~ s{/$}{};
13858: my $item;
13859: if ($path ne '') {
13860: $item = "$path/$titles{$i}";
13861: } else {
13862: $item = $titles{$i};
13863: }
13864: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13865: if ($item eq $contents[0]) {
13866: push(@{$env{'form.archive_directory'}},$i);
13867: $env{'form.archive_'.$i} = 'display';
13868: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13869: $displayed{'folder'} = $i;
1.1164 raeburn 13870: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13871: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13872: $env{'form.archive_'.$i} = 'display';
13873: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13874: $displayed{'web'} = $i;
13875: } else {
1.1164 raeburn 13876: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13877: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13878: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13879: push(@{$env{'form.archive_directory'}},$i);
13880: }
13881: $env{'form.archive_'.$i} = 'dependency';
13882: }
13883: $total ++;
13884: }
13885: for (my $i=1; $i<$total; $i++) {
13886: next if ($i == $displayed{'web'});
13887: next if ($i == $displayed{'folder'});
13888: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13889: }
13890: $env{'form.phase'} = 'decompress_cleanup';
13891: $env{'form.archivedelete'} = 1;
13892: $env{'form.archive_count'} = $total-1;
13893: $output .=
13894: &process_extracted_files('coursedocs',$docudom,
13895: $docuname,$destination,
13896: $dir_root,$hiddenelem);
13897: }
1.1055 raeburn 13898: } else {
13899: $warning = &mt('No new items extracted from archive file.');
13900: }
13901: } else {
13902: $output = $display;
13903: $error = &mt('An error occurred during extraction from the archive file.');
13904: }
13905: }
13906: }
13907: }
13908: if ($error) {
13909: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13910: $error.'</p>'."\n";
13911: }
13912: if ($warning) {
13913: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13914: }
13915: return $output;
13916: }
13917:
13918: sub get_extracted {
1.1056 raeburn 13919: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13920: $titles,$wantform) = @_;
1.1055 raeburn 13921: my $count = 0;
13922: my $depth = 0;
13923: my $datatable;
1.1056 raeburn 13924: my @hierarchy;
1.1055 raeburn 13925: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13926: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13927: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13928: foreach my $item (@{$contents}) {
13929: $count ++;
1.1056 raeburn 13930: @{$dirorder->{$count}} = @hierarchy;
13931: $titles->{$count} = $item;
1.1055 raeburn 13932: &archive_hierarchy($depth,$count,$parent,$children);
13933: if ($wantform) {
13934: $datatable .= &archive_row($is_dir->{$item},$item,
13935: $currdir,$depth,$count);
13936: }
13937: if ($is_dir->{$item}) {
13938: $depth ++;
1.1056 raeburn 13939: push(@hierarchy,$count);
13940: $parent->{$depth} = $count;
1.1055 raeburn 13941: $datatable .=
13942: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13943: \$depth,\$count,\@hierarchy,$dirorder,
13944: $children,$parent,$titles,$wantform);
1.1055 raeburn 13945: $depth --;
1.1056 raeburn 13946: pop(@hierarchy);
1.1055 raeburn 13947: }
13948: }
13949: return ($count,$datatable);
13950: }
13951:
13952: sub recurse_extracted_archive {
1.1056 raeburn 13953: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13954: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13955: my $result='';
1.1056 raeburn 13956: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13957: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13958: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13959: return $result;
13960: }
13961: my $dirptr = 16384;
13962: my ($newdirlistref,$newlisterror) =
13963: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13964: if (ref($newdirlistref) eq 'ARRAY') {
13965: foreach my $dir_line (@{$newdirlistref}) {
13966: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13967: unless ($item =~ /^\.+$/) {
13968: $$count ++;
1.1056 raeburn 13969: @{$dirorder->{$$count}} = @{$hierarchy};
13970: $titles->{$$count} = $item;
1.1055 raeburn 13971: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13972:
1.1055 raeburn 13973: my $is_dir;
13974: if ($dirptr&$testdir) {
13975: $is_dir = 1;
13976: }
13977: if ($wantform) {
13978: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13979: }
13980: if ($is_dir) {
13981: $$depth ++;
1.1056 raeburn 13982: push(@{$hierarchy},$$count);
13983: $parent->{$$depth} = $$count;
1.1055 raeburn 13984: $result .=
13985: &recurse_extracted_archive("$currdir/$item",$docudom,
13986: $docuname,$depth,$count,
1.1056 raeburn 13987: $hierarchy,$dirorder,$children,
13988: $parent,$titles,$wantform);
1.1055 raeburn 13989: $$depth --;
1.1056 raeburn 13990: pop(@{$hierarchy});
1.1055 raeburn 13991: }
13992: }
13993: }
13994: }
13995: return $result;
13996: }
13997:
13998: sub archive_hierarchy {
13999: my ($depth,$count,$parent,$children) =@_;
14000: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
14001: if (exists($parent->{$depth})) {
14002: $children->{$parent->{$depth}} .= $count.':';
14003: }
14004: }
14005: return;
14006: }
14007:
14008: sub archive_row {
14009: my ($is_dir,$item,$currdir,$depth,$count) = @_;
14010: my ($name) = ($item =~ m{([^/]+)$});
14011: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 14012: 'display' => 'Add as file',
1.1055 raeburn 14013: 'dependency' => 'Include as dependency',
14014: 'discard' => 'Discard',
14015: );
14016: if ($is_dir) {
1.1059 raeburn 14017: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 14018: }
1.1056 raeburn 14019: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
14020: my $offset = 0;
1.1055 raeburn 14021: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 14022: $offset ++;
1.1065 raeburn 14023: if ($action ne 'display') {
14024: $offset ++;
14025: }
1.1055 raeburn 14026: $output .= '<td><span class="LC_nobreak">'.
14027: '<label><input type="radio" name="archive_'.$count.
14028: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
14029: my $text = $choices{$action};
14030: if ($is_dir) {
14031: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
14032: if ($action eq 'display') {
1.1059 raeburn 14033: $text = &mt('Add as folder');
1.1055 raeburn 14034: }
1.1056 raeburn 14035: } else {
14036: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
14037:
14038: }
14039: $output .= ' /> '.$choices{$action}.'</label></span>';
14040: if ($action eq 'dependency') {
14041: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
14042: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
14043: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
14044: '<option value=""></option>'."\n".
14045: '</select>'."\n".
14046: '</div>';
1.1059 raeburn 14047: } elsif ($action eq 'display') {
14048: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
14049: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
14050: '</div>';
1.1055 raeburn 14051: }
1.1056 raeburn 14052: $output .= '</td>';
1.1055 raeburn 14053: }
14054: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
14055: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
14056: for (my $i=0; $i<$depth; $i++) {
14057: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
14058: }
14059: if ($is_dir) {
14060: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
14061: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
14062: } else {
14063: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
14064: }
14065: $output .= ' '.$name.'</td>'."\n".
14066: &end_data_table_row();
14067: return $output;
14068: }
14069:
14070: sub archive_options_form {
1.1065 raeburn 14071: my ($form,$display,$count,$hiddenelem) = @_;
14072: my %lt = &Apache::lonlocal::texthash(
14073: perm => 'Permanently remove archive file?',
14074: hows => 'How should each extracted item be incorporated in the course?',
14075: cont => 'Content actions for all',
14076: addf => 'Add as folder/file',
14077: incd => 'Include as dependency for a displayed file',
14078: disc => 'Discard',
14079: no => 'No',
14080: yes => 'Yes',
14081: save => 'Save',
14082: );
14083: my $output = <<"END";
14084: <form name="$form" method="post" action="">
14085: <p><span class="LC_nobreak">$lt{'perm'}
14086: <label>
14087: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
14088: </label>
14089:
14090: <label>
14091: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
14092: </span>
14093: </p>
14094: <input type="hidden" name="phase" value="decompress_cleanup" />
14095: <br />$lt{'hows'}
14096: <div class="LC_columnSection">
14097: <fieldset>
14098: <legend>$lt{'cont'}</legend>
14099: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
14100: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
14101: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
14102: </fieldset>
14103: </div>
14104: END
14105: return $output.
1.1055 raeburn 14106: &start_data_table()."\n".
1.1065 raeburn 14107: $display."\n".
1.1055 raeburn 14108: &end_data_table()."\n".
14109: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
14110: $hiddenelem.
1.1065 raeburn 14111: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 14112: '</form>';
14113: }
14114:
14115: sub archive_javascript {
1.1056 raeburn 14116: my ($startcount,$numitems,$titles,$children) = @_;
14117: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 14118: my $maintitle = $env{'form.comment'};
1.1055 raeburn 14119: my $scripttag = <<START;
14120: <script type="text/javascript">
14121: // <![CDATA[
14122:
14123: function checkAll(form,prefix) {
14124: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
14125: for (var i=0; i < form.elements.length; i++) {
14126: var id = form.elements[i].id;
14127: if ((id != '') && (id != undefined)) {
14128: if (idstr.test(id)) {
14129: if (form.elements[i].type == 'radio') {
14130: form.elements[i].checked = true;
1.1056 raeburn 14131: var nostart = i-$startcount;
1.1059 raeburn 14132: var offset = nostart%7;
14133: var count = (nostart-offset)/7;
1.1056 raeburn 14134: dependencyCheck(form,count,offset);
1.1055 raeburn 14135: }
14136: }
14137: }
14138: }
14139: }
14140:
14141: function propagateCheck(form,count) {
14142: if (count > 0) {
1.1059 raeburn 14143: var startelement = $startcount + ((count-1) * 7);
14144: for (var j=1; j<6; j++) {
14145: if ((j != 2) && (j != 4)) {
1.1056 raeburn 14146: var item = startelement + j;
14147: if (form.elements[item].type == 'radio') {
14148: if (form.elements[item].checked) {
14149: containerCheck(form,count,j);
14150: break;
14151: }
1.1055 raeburn 14152: }
14153: }
14154: }
14155: }
14156: }
14157:
14158: numitems = $numitems
1.1056 raeburn 14159: var titles = new Array(numitems);
14160: var parents = new Array(numitems);
1.1055 raeburn 14161: for (var i=0; i<numitems; i++) {
1.1056 raeburn 14162: parents[i] = new Array;
1.1055 raeburn 14163: }
1.1059 raeburn 14164: var maintitle = '$maintitle';
1.1055 raeburn 14165:
14166: START
14167:
1.1056 raeburn 14168: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
14169: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 14170: for (my $i=0; $i<@contents; $i ++) {
14171: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
14172: }
14173: }
14174:
1.1056 raeburn 14175: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
14176: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
14177: }
14178:
1.1055 raeburn 14179: $scripttag .= <<END;
14180:
14181: function containerCheck(form,count,offset) {
14182: if (count > 0) {
1.1056 raeburn 14183: dependencyCheck(form,count,offset);
1.1059 raeburn 14184: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 14185: form.elements[item].checked = true;
14186: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
14187: if (parents[count].length > 0) {
14188: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 14189: containerCheck(form,parents[count][j],offset);
14190: }
14191: }
14192: }
14193: }
14194: }
14195:
14196: function dependencyCheck(form,count,offset) {
14197: if (count > 0) {
1.1059 raeburn 14198: var chosen = (offset+$startcount)+7*(count-1);
14199: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 14200: var currtype = form.elements[depitem].type;
14201: if (form.elements[chosen].value == 'dependency') {
14202: document.getElementById('arc_depon_'+count).style.display='block';
14203: form.elements[depitem].options.length = 0;
14204: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 14205: for (var i=1; i<=numitems; i++) {
14206: if (i == count) {
14207: continue;
14208: }
1.1059 raeburn 14209: var startelement = $startcount + (i-1) * 7;
14210: for (var j=1; j<6; j++) {
14211: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 14212: var item = startelement + j;
14213: if (form.elements[item].type == 'radio') {
14214: if (form.elements[item].checked) {
14215: if (form.elements[item].value == 'display') {
14216: var n = form.elements[depitem].options.length;
14217: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
14218: }
14219: }
14220: }
14221: }
14222: }
14223: }
14224: } else {
14225: document.getElementById('arc_depon_'+count).style.display='none';
14226: form.elements[depitem].options.length = 0;
14227: form.elements[depitem].options[0] = new Option('Select','',true,true);
14228: }
1.1059 raeburn 14229: titleCheck(form,count,offset);
1.1056 raeburn 14230: }
14231: }
14232:
14233: function propagateSelect(form,count,offset) {
14234: if (count > 0) {
1.1065 raeburn 14235: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 14236: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
14237: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14238: if (parents[count].length > 0) {
14239: for (var j=0; j<parents[count].length; j++) {
14240: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 14241: }
14242: }
14243: }
14244: }
14245: }
1.1056 raeburn 14246:
14247: function containerSelect(form,count,offset,picked) {
14248: if (count > 0) {
1.1065 raeburn 14249: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 14250: if (form.elements[item].type == 'radio') {
14251: if (form.elements[item].value == 'dependency') {
14252: if (form.elements[item+1].type == 'select-one') {
14253: for (var i=0; i<form.elements[item+1].options.length; i++) {
14254: if (form.elements[item+1].options[i].value == picked) {
14255: form.elements[item+1].selectedIndex = i;
14256: break;
14257: }
14258: }
14259: }
14260: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14261: if (parents[count].length > 0) {
14262: for (var j=0; j<parents[count].length; j++) {
14263: containerSelect(form,parents[count][j],offset,picked);
14264: }
14265: }
14266: }
14267: }
14268: }
14269: }
14270: }
14271:
1.1059 raeburn 14272: function titleCheck(form,count,offset) {
14273: if (count > 0) {
14274: var chosen = (offset+$startcount)+7*(count-1);
14275: var depitem = $startcount + ((count-1) * 7) + 2;
14276: var currtype = form.elements[depitem].type;
14277: if (form.elements[chosen].value == 'display') {
14278: document.getElementById('arc_title_'+count).style.display='block';
14279: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
14280: document.getElementById('archive_title_'+count).value=maintitle;
14281: }
14282: } else {
14283: document.getElementById('arc_title_'+count).style.display='none';
14284: if (currtype == 'text') {
14285: document.getElementById('archive_title_'+count).value='';
14286: }
14287: }
14288: }
14289: return;
14290: }
14291:
1.1055 raeburn 14292: // ]]>
14293: </script>
14294: END
14295: return $scripttag;
14296: }
14297:
14298: sub process_extracted_files {
1.1067 raeburn 14299: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 14300: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 14301: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 14302: my @ids=&Apache::lonnet::current_machine_ids();
14303: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 14304: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 14305: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14306: if (grep(/^\Q$docuhome\E$/,@ids)) {
14307: $prefix = &LONCAPA::propath($docudom,$docuname);
14308: $pathtocheck = "$dir_root/$destination";
14309: $dir = $dir_root;
14310: $ishome = 1;
14311: } else {
14312: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
14313: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 14314: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 14315: }
14316: my $currdir = "$dir_root/$destination";
14317: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
14318: if ($env{'form.folderpath'}) {
14319: my @items = split('&',$env{'form.folderpath'});
14320: $folders{'0'} = $items[-2];
1.1099 raeburn 14321: if ($env{'form.folderpath'} =~ /\:1$/) {
14322: $containers{'0'}='page';
14323: } else {
14324: $containers{'0'}='sequence';
14325: }
1.1055 raeburn 14326: }
14327: my @archdirs = &get_env_multiple('form.archive_directory');
14328: if ($numitems) {
14329: for (my $i=1; $i<=$numitems; $i++) {
14330: my $path = $env{'form.archive_content_'.$i};
14331: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
14332: my $item = $1;
14333: $toplevelitems{$item} = $i;
14334: if (grep(/^\Q$i\E$/,@archdirs)) {
14335: $is_dir{$item} = 1;
14336: }
14337: }
14338: }
14339: }
1.1067 raeburn 14340: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 14341: if (keys(%toplevelitems) > 0) {
14342: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 14343: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
14344: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 14345: }
1.1066 raeburn 14346: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 14347: if ($numitems) {
14348: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 14349: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 14350: my $path = $env{'form.archive_content_'.$i};
14351: if ($path =~ /^\Q$pathtocheck\E/) {
14352: if ($env{'form.archive_'.$i} eq 'discard') {
14353: if ($prefix ne '' && $path ne '') {
14354: if (-e $prefix.$path) {
1.1066 raeburn 14355: if ((@archdirs > 0) &&
14356: (grep(/^\Q$i\E$/,@archdirs))) {
14357: $todeletedir{$prefix.$path} = 1;
14358: } else {
14359: $todelete{$prefix.$path} = 1;
14360: }
1.1055 raeburn 14361: }
14362: }
14363: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 14364: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 14365: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 14366: $docstitle = $env{'form.archive_title_'.$i};
14367: if ($docstitle eq '') {
14368: $docstitle = $title;
14369: }
1.1055 raeburn 14370: $outer = 0;
1.1056 raeburn 14371: if (ref($dirorder{$i}) eq 'ARRAY') {
14372: if (@{$dirorder{$i}} > 0) {
14373: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 14374: if ($env{'form.archive_'.$item} eq 'display') {
14375: $outer = $item;
14376: last;
14377: }
14378: }
14379: }
14380: }
14381: my ($errtext,$fatal) =
14382: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
14383: '/'.$folders{$outer}.'.'.
14384: $containers{$outer});
14385: next if ($fatal);
14386: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
14387: if ($context eq 'coursedocs') {
1.1056 raeburn 14388: $mapinner{$i} = time;
1.1055 raeburn 14389: $folders{$i} = 'default_'.$mapinner{$i};
14390: $containers{$i} = 'sequence';
14391: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14392: $folders{$i}.'.'.$containers{$i};
14393: my $newidx = &LONCAPA::map::getresidx();
14394: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 14395: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 14396: push(@LONCAPA::map::order,$newidx);
14397: my ($outtext,$errtext) =
14398: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14399: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 14400: '.'.$containers{$outer},1,1);
1.1056 raeburn 14401: $newseqid{$i} = $newidx;
1.1067 raeburn 14402: unless ($errtext) {
1.1294 raeburn 14403: $result .= '<li>'.&mt('Folder: [_1] added to course',
14404: &HTML::Entities::encode($docstitle,'<>&"')).
14405: '</li>'."\n";
1.1067 raeburn 14406: }
1.1055 raeburn 14407: }
14408: } else {
14409: if ($context eq 'coursedocs') {
14410: my $newidx=&LONCAPA::map::getresidx();
14411: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14412: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
14413: $title;
1.1392 raeburn 14414: if (($outer !~ /\D/) &&
14415: (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
14416: ($newidx !~ /\D/)) {
1.1294 raeburn 14417: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
14418: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
14419: }
14420: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14421: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
14422: }
14423: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14424: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
14425: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
14426: unless ($ishome) {
14427: my $fetch = "$newdest{$i}/$title";
14428: $fetch =~ s/^\Q$prefix$dir\E//;
14429: $prompttofetch{$fetch} = 1;
14430: }
1.1292 raeburn 14431: }
1.1067 raeburn 14432: }
1.1294 raeburn 14433: $LONCAPA::map::resources[$newidx]=
14434: $docstitle.':'.$url.':false:normal:res';
14435: push(@LONCAPA::map::order, $newidx);
14436: my ($outtext,$errtext)=
14437: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14438: $docuname.'/'.$folders{$outer}.
14439: '.'.$containers{$outer},1,1);
14440: unless ($errtext) {
14441: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
14442: $result .= '<li>'.&mt('File: [_1] added to course',
14443: &HTML::Entities::encode($docstitle,'<>&"')).
14444: '</li>'."\n";
14445: }
1.1067 raeburn 14446: }
1.1294 raeburn 14447: } else {
14448: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14449: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 14450: }
1.1055 raeburn 14451: }
14452: }
1.1086 raeburn 14453: }
14454: } else {
1.1294 raeburn 14455: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14456: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 14457: }
14458: }
14459: for (my $i=1; $i<=$numitems; $i++) {
14460: next unless ($env{'form.archive_'.$i} eq 'dependency');
14461: my $path = $env{'form.archive_content_'.$i};
14462: if ($path =~ /^\Q$pathtocheck\E/) {
14463: my ($title) = ($path =~ m{/([^/]+)$});
14464: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
14465: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
14466: if (ref($dirorder{$i}) eq 'ARRAY') {
14467: my ($itemidx,$fullpath,$relpath);
14468: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
14469: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 14470: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 14471: if ($dirorder{$i}->[$j] eq $container) {
14472: $itemidx = $j;
1.1056 raeburn 14473: }
14474: }
1.1086 raeburn 14475: }
14476: if ($itemidx eq '') {
14477: $itemidx = 0;
14478: }
14479: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
14480: if ($mapinner{$referrer{$i}}) {
14481: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
14482: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14483: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14484: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14485: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14486: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14487: if (!-e $fullpath) {
14488: mkdir($fullpath,0755);
1.1056 raeburn 14489: }
14490: }
1.1086 raeburn 14491: } else {
14492: last;
1.1056 raeburn 14493: }
1.1086 raeburn 14494: }
14495: }
14496: } elsif ($newdest{$referrer{$i}}) {
14497: $fullpath = $newdest{$referrer{$i}};
14498: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14499: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
14500: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
14501: last;
14502: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14503: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14504: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14505: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14506: if (!-e $fullpath) {
14507: mkdir($fullpath,0755);
1.1056 raeburn 14508: }
14509: }
1.1086 raeburn 14510: } else {
14511: last;
1.1056 raeburn 14512: }
1.1055 raeburn 14513: }
14514: }
1.1086 raeburn 14515: if ($fullpath ne '') {
14516: if (-e "$prefix$path") {
1.1292 raeburn 14517: unless (rename("$prefix$path","$fullpath/$title")) {
14518: $warning .= &mt('Failed to rename dependency').'<br />';
14519: }
1.1086 raeburn 14520: }
14521: if (-e "$fullpath/$title") {
14522: my $showpath;
14523: if ($relpath ne '') {
14524: $showpath = "$relpath/$title";
14525: } else {
14526: $showpath = "/$title";
14527: }
1.1294 raeburn 14528: $result .= '<li>'.&mt('[_1] included as a dependency',
14529: &HTML::Entities::encode($showpath,'<>&"')).
14530: '</li>'."\n";
1.1292 raeburn 14531: unless ($ishome) {
14532: my $fetch = "$fullpath/$title";
14533: $fetch =~ s/^\Q$prefix$dir\E//;
14534: $prompttofetch{$fetch} = 1;
14535: }
1.1086 raeburn 14536: }
14537: }
1.1055 raeburn 14538: }
1.1086 raeburn 14539: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
14540: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 14541: &HTML::Entities::encode($path,'<>&"'),
14542: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
14543: '<br />';
1.1055 raeburn 14544: }
14545: } else {
1.1294 raeburn 14546: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 14547: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 14548: }
14549: }
14550: if (keys(%todelete)) {
14551: foreach my $key (keys(%todelete)) {
14552: unlink($key);
1.1066 raeburn 14553: }
14554: }
14555: if (keys(%todeletedir)) {
14556: foreach my $key (keys(%todeletedir)) {
14557: rmdir($key);
14558: }
14559: }
14560: foreach my $dir (sort(keys(%is_dir))) {
14561: if (($pathtocheck ne '') && ($dir ne '')) {
14562: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 14563: }
14564: }
1.1067 raeburn 14565: if ($result ne '') {
14566: $output .= '<ul>'."\n".
14567: $result."\n".
14568: '</ul>';
14569: }
14570: unless ($ishome) {
14571: my $replicationfail;
14572: foreach my $item (keys(%prompttofetch)) {
14573: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
14574: unless ($fetchresult eq 'ok') {
14575: $replicationfail .= '<li>'.$item.'</li>'."\n";
14576: }
14577: }
14578: if ($replicationfail) {
14579: $output .= '<p class="LC_error">'.
14580: &mt('Course home server failed to retrieve:').'<ul>'.
14581: $replicationfail.
14582: '</ul></p>';
14583: }
14584: }
1.1055 raeburn 14585: } else {
14586: $warning = &mt('No items found in archive.');
14587: }
14588: if ($error) {
14589: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14590: $error.'</p>'."\n";
14591: }
14592: if ($warning) {
14593: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14594: }
14595: return $output;
14596: }
14597:
1.1066 raeburn 14598: sub cleanup_empty_dirs {
14599: my ($path) = @_;
14600: if (($path ne '') && (-d $path)) {
14601: if (opendir(my $dirh,$path)) {
14602: my @dircontents = grep(!/^\./,readdir($dirh));
14603: my $numitems = 0;
14604: foreach my $item (@dircontents) {
14605: if (-d "$path/$item") {
1.1111 raeburn 14606: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14607: if (-e "$path/$item") {
14608: $numitems ++;
14609: }
14610: } else {
14611: $numitems ++;
14612: }
14613: }
14614: if ($numitems == 0) {
14615: rmdir($path);
14616: }
14617: closedir($dirh);
14618: }
14619: }
14620: return;
14621: }
14622:
1.41 ng 14623: =pod
1.45 matthew 14624:
1.1162 raeburn 14625: =item * &get_folder_hierarchy()
1.1068 raeburn 14626:
14627: Provides hierarchy of names of folders/sub-folders containing the current
14628: item,
14629:
14630: Inputs: 3
14631: - $navmap - navmaps object
14632:
14633: - $map - url for map (either the trigger itself, or map containing
14634: the resource, which is the trigger).
14635:
14636: - $showitem - 1 => show title for map itself; 0 => do not show.
14637:
14638: Outputs: 1 @pathitems - array of folder/subfolder names.
14639:
14640: =cut
14641:
14642: sub get_folder_hierarchy {
14643: my ($navmap,$map,$showitem) = @_;
14644: my @pathitems;
14645: if (ref($navmap)) {
14646: my $mapres = $navmap->getResourceByUrl($map);
14647: if (ref($mapres)) {
14648: my $pcslist = $mapres->map_hierarchy();
14649: if ($pcslist ne '') {
14650: my @pcs = split(/,/,$pcslist);
14651: foreach my $pc (@pcs) {
14652: if ($pc == 1) {
1.1129 raeburn 14653: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14654: } else {
14655: my $res = $navmap->getByMapPc($pc);
14656: if (ref($res)) {
14657: my $title = $res->compTitle();
14658: $title =~ s/\W+/_/g;
14659: if ($title ne '') {
14660: push(@pathitems,$title);
14661: }
14662: }
14663: }
14664: }
14665: }
1.1071 raeburn 14666: if ($showitem) {
14667: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 14668: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14669: } else {
14670: my $maptitle = $mapres->compTitle();
14671: $maptitle =~ s/\W+/_/g;
14672: if ($maptitle ne '') {
14673: push(@pathitems,$maptitle);
14674: }
1.1068 raeburn 14675: }
14676: }
14677: }
14678: }
14679: return @pathitems;
14680: }
14681:
14682: =pod
14683:
1.1015 raeburn 14684: =item * &get_turnedin_filepath()
14685:
14686: Determines path in a user's portfolio file for storage of files uploaded
14687: to a specific essayresponse or dropbox item.
14688:
14689: Inputs: 3 required + 1 optional.
14690: $symb is symb for resource, $uname and $udom are for current user (required).
14691: $caller is optional (can be "submission", if routine is called when storing
14692: an upoaded file when "Submit Answer" button was pressed).
14693:
14694: Returns array containing $path and $multiresp.
14695: $path is path in portfolio. $multiresp is 1 if this resource contains more
14696: than one file upload item. Callers of routine should append partid as a
14697: subdirectory to $path in cases where $multiresp is 1.
14698:
14699: Called by: homework/essayresponse.pm and homework/structuretags.pm
14700:
14701: =cut
14702:
14703: sub get_turnedin_filepath {
14704: my ($symb,$uname,$udom,$caller) = @_;
14705: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14706: my $turnindir;
14707: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14708: $turnindir = $userhash{'turnindir'};
14709: my ($path,$multiresp);
14710: if ($turnindir eq '') {
14711: if ($caller eq 'submission') {
14712: $turnindir = &mt('turned in');
14713: $turnindir =~ s/\W+/_/g;
14714: my %newhash = (
14715: 'turnindir' => $turnindir,
14716: );
14717: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14718: }
14719: }
14720: if ($turnindir ne '') {
14721: $path = '/'.$turnindir.'/';
14722: my ($multipart,$turnin,@pathitems);
14723: my $navmap = Apache::lonnavmaps::navmap->new();
14724: if (defined($navmap)) {
14725: my $mapres = $navmap->getResourceByUrl($map);
14726: if (ref($mapres)) {
14727: my $pcslist = $mapres->map_hierarchy();
14728: if ($pcslist ne '') {
14729: foreach my $pc (split(/,/,$pcslist)) {
14730: my $res = $navmap->getByMapPc($pc);
14731: if (ref($res)) {
14732: my $title = $res->compTitle();
14733: $title =~ s/\W+/_/g;
14734: if ($title ne '') {
1.1149 raeburn 14735: if (($pc > 1) && (length($title) > 12)) {
14736: $title = substr($title,0,12);
14737: }
1.1015 raeburn 14738: push(@pathitems,$title);
14739: }
14740: }
14741: }
14742: }
14743: my $maptitle = $mapres->compTitle();
14744: $maptitle =~ s/\W+/_/g;
14745: if ($maptitle ne '') {
1.1149 raeburn 14746: if (length($maptitle) > 12) {
14747: $maptitle = substr($maptitle,0,12);
14748: }
1.1015 raeburn 14749: push(@pathitems,$maptitle);
14750: }
14751: unless ($env{'request.state'} eq 'construct') {
14752: my $res = $navmap->getBySymb($symb);
14753: if (ref($res)) {
14754: my $partlist = $res->parts();
14755: my $totaluploads = 0;
14756: if (ref($partlist) eq 'ARRAY') {
14757: foreach my $part (@{$partlist}) {
14758: my @types = $res->responseType($part);
14759: my @ids = $res->responseIds($part);
14760: for (my $i=0; $i < scalar(@ids); $i++) {
14761: if ($types[$i] eq 'essay') {
14762: my $partid = $part.'_'.$ids[$i];
14763: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14764: $totaluploads ++;
14765: }
14766: }
14767: }
14768: }
14769: if ($totaluploads > 1) {
14770: $multiresp = 1;
14771: }
14772: }
14773: }
14774: }
14775: } else {
14776: return;
14777: }
14778: } else {
14779: return;
14780: }
14781: my $restitle=&Apache::lonnet::gettitle($symb);
14782: $restitle =~ s/\W+/_/g;
14783: if ($restitle eq '') {
14784: $restitle = ($resurl =~ m{/[^/]+$});
14785: if ($restitle eq '') {
14786: $restitle = time;
14787: }
14788: }
1.1149 raeburn 14789: if (length($restitle) > 12) {
14790: $restitle = substr($restitle,0,12);
14791: }
1.1015 raeburn 14792: push(@pathitems,$restitle);
14793: $path .= join('/',@pathitems);
14794: }
14795: return ($path,$multiresp);
14796: }
14797:
14798: =pod
14799:
1.464 albertel 14800: =back
1.41 ng 14801:
1.112 bowersj2 14802: =head1 CSV Upload/Handling functions
1.38 albertel 14803:
1.41 ng 14804: =over 4
14805:
1.648 raeburn 14806: =item * &upfile_store($r)
1.41 ng 14807:
14808: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14809: needs $env{'form.upfile'}
1.41 ng 14810: returns $datatoken to be put into hidden field
14811:
14812: =cut
1.31 albertel 14813:
14814: sub upfile_store {
14815: my $r=shift;
1.258 albertel 14816: $env{'form.upfile'}=~s/\r/\n/gs;
14817: $env{'form.upfile'}=~s/\f/\n/gs;
14818: $env{'form.upfile'}=~s/\n+/\n/gs;
14819: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14820:
1.1299 raeburn 14821: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14822: '_enroll_'.$env{'request.course.id'}.'_'.
14823: time.'_'.$$);
14824: return if ($datatoken eq '');
14825:
1.31 albertel 14826: {
1.158 raeburn 14827: my $datafile = $r->dir_config('lonDaemons').
14828: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14829: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14830: print $fh $env{'form.upfile'};
1.158 raeburn 14831: close($fh);
14832: }
1.31 albertel 14833: }
14834: return $datatoken;
14835: }
14836:
1.56 matthew 14837: =pod
14838:
1.1290 raeburn 14839: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14840:
14841: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14842: $datatoken is the name to assign to the temporary file.
1.258 albertel 14843: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14844:
14845: =cut
1.31 albertel 14846:
14847: sub load_tmp_file {
1.1290 raeburn 14848: my ($r,$datatoken) = @_;
14849: return if ($datatoken eq '');
1.31 albertel 14850: my @studentdata=();
14851: {
1.158 raeburn 14852: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14853: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14854: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14855: @studentdata=<$fh>;
14856: close($fh);
14857: }
1.31 albertel 14858: }
1.258 albertel 14859: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14860: }
14861:
1.1290 raeburn 14862: sub valid_datatoken {
14863: my ($datatoken) = @_;
1.1325 raeburn 14864: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14865: return $datatoken;
14866: }
14867: return;
14868: }
14869:
1.56 matthew 14870: =pod
14871:
1.648 raeburn 14872: =item * &upfile_record_sep()
1.41 ng 14873:
14874: Separate uploaded file into records
14875: returns array of records,
1.258 albertel 14876: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14877:
14878: =cut
1.31 albertel 14879:
14880: sub upfile_record_sep {
1.258 albertel 14881: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14882: } else {
1.248 albertel 14883: my @records;
1.258 albertel 14884: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14885: if ($line=~/^\s*$/) { next; }
14886: push(@records,$line);
14887: }
14888: return @records;
1.31 albertel 14889: }
14890: }
14891:
1.56 matthew 14892: =pod
14893:
1.648 raeburn 14894: =item * &record_sep($record)
1.41 ng 14895:
1.258 albertel 14896: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14897:
14898: =cut
14899:
1.263 www 14900: sub takeleft {
14901: my $index=shift;
14902: return substr('0000'.$index,-4,4);
14903: }
14904:
1.31 albertel 14905: sub record_sep {
14906: my $record=shift;
14907: my %components=();
1.258 albertel 14908: if ($env{'form.upfiletype'} eq 'xml') {
14909: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14910: my $i=0;
1.356 albertel 14911: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14912: $field=~s/^(\"|\')//;
14913: $field=~s/(\"|\')$//;
1.263 www 14914: $components{&takeleft($i)}=$field;
1.31 albertel 14915: $i++;
14916: }
1.258 albertel 14917: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14918: my $i=0;
1.356 albertel 14919: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14920: $field=~s/^(\"|\')//;
14921: $field=~s/(\"|\')$//;
1.263 www 14922: $components{&takeleft($i)}=$field;
1.31 albertel 14923: $i++;
14924: }
14925: } else {
1.561 www 14926: my $separator=',';
1.480 banghart 14927: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14928: $separator=';';
1.480 banghart 14929: }
1.31 albertel 14930: my $i=0;
1.561 www 14931: # the character we are looking for to indicate the end of a quote or a record
14932: my $looking_for=$separator;
14933: # do not add the characters to the fields
14934: my $ignore=0;
14935: # we just encountered a separator (or the beginning of the record)
14936: my $just_found_separator=1;
14937: # store the field we are working on here
14938: my $field='';
14939: # work our way through all characters in record
14940: foreach my $character ($record=~/(.)/g) {
14941: if ($character eq $looking_for) {
14942: if ($character ne $separator) {
14943: # Found the end of a quote, again looking for separator
14944: $looking_for=$separator;
14945: $ignore=1;
14946: } else {
14947: # Found a separator, store away what we got
14948: $components{&takeleft($i)}=$field;
14949: $i++;
14950: $just_found_separator=1;
14951: $ignore=0;
14952: $field='';
14953: }
14954: next;
14955: }
14956: # single or double quotation marks after a separator indicate beginning of a quote
14957: # we are now looking for the end of the quote and need to ignore separators
14958: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14959: $looking_for=$character;
14960: next;
14961: }
14962: # ignore would be true after we reached the end of a quote
14963: if ($ignore) { next; }
14964: if (($just_found_separator) && ($character=~/\s/)) { next; }
14965: $field.=$character;
14966: $just_found_separator=0;
1.31 albertel 14967: }
1.561 www 14968: # catch the very last entry, since we never encountered the separator
14969: $components{&takeleft($i)}=$field;
1.31 albertel 14970: }
14971: return %components;
14972: }
14973:
1.144 matthew 14974: ######################################################
14975: ######################################################
14976:
1.56 matthew 14977: =pod
14978:
1.648 raeburn 14979: =item * &upfile_select_html()
1.41 ng 14980:
1.144 matthew 14981: Return HTML code to select a file from the users machine and specify
14982: the file type.
1.41 ng 14983:
14984: =cut
14985:
1.144 matthew 14986: ######################################################
14987: ######################################################
1.31 albertel 14988: sub upfile_select_html {
1.144 matthew 14989: my %Types = (
14990: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14991: semisv => &mt('Semicolon separated values'),
1.144 matthew 14992: space => &mt('Space separated'),
14993: tab => &mt('Tabulator separated'),
14994: # xml => &mt('HTML/XML'),
14995: );
14996: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14997: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14998: foreach my $type (sort(keys(%Types))) {
14999: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
15000: }
15001: $Str .= "</select>\n";
15002: return $Str;
1.31 albertel 15003: }
15004:
1.301 albertel 15005: sub get_samples {
15006: my ($records,$toget) = @_;
15007: my @samples=({});
15008: my $got=0;
15009: foreach my $rec (@$records) {
15010: my %temp = &record_sep($rec);
15011: if (! grep(/\S/, values(%temp))) { next; }
15012: if (%temp) {
15013: $samples[$got]=\%temp;
15014: $got++;
15015: if ($got == $toget) { last; }
15016: }
15017: }
15018: return \@samples;
15019: }
15020:
1.144 matthew 15021: ######################################################
15022: ######################################################
15023:
1.56 matthew 15024: =pod
15025:
1.648 raeburn 15026: =item * &csv_print_samples($r,$records)
1.41 ng 15027:
15028: Prints a table of sample values from each column uploaded $r is an
15029: Apache Request ref, $records is an arrayref from
15030: &Apache::loncommon::upfile_record_sep
15031:
15032: =cut
15033:
1.144 matthew 15034: ######################################################
15035: ######################################################
1.31 albertel 15036: sub csv_print_samples {
15037: my ($r,$records) = @_;
1.662 bisitz 15038: my $samples = &get_samples($records,5);
1.301 albertel 15039:
1.594 raeburn 15040: $r->print(&mt('Samples').'<br />'.&start_data_table().
15041: &start_data_table_header_row());
1.356 albertel 15042: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 15043: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 15044: $r->print(&end_data_table_header_row());
1.301 albertel 15045: foreach my $hash (@$samples) {
1.594 raeburn 15046: $r->print(&start_data_table_row());
1.356 albertel 15047: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 15048: $r->print('<td>');
1.356 albertel 15049: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 15050: $r->print('</td>');
15051: }
1.594 raeburn 15052: $r->print(&end_data_table_row());
1.31 albertel 15053: }
1.594 raeburn 15054: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 15055: }
15056:
1.144 matthew 15057: ######################################################
15058: ######################################################
15059:
1.56 matthew 15060: =pod
15061:
1.648 raeburn 15062: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 15063:
15064: Prints a table to create associations between values and table columns.
1.144 matthew 15065:
1.41 ng 15066: $r is an Apache Request ref,
15067: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 15068: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 15069:
15070: =cut
15071:
1.144 matthew 15072: ######################################################
15073: ######################################################
1.31 albertel 15074: sub csv_print_select_table {
15075: my ($r,$records,$d) = @_;
1.301 albertel 15076: my $i=0;
15077: my $samples = &get_samples($records,1);
1.144 matthew 15078: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 15079: &start_data_table().&start_data_table_header_row().
1.144 matthew 15080: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 15081: '<th>'.&mt('Column').'</th>'.
15082: &end_data_table_header_row()."\n");
1.356 albertel 15083: foreach my $array_ref (@$d) {
15084: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 15085: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 15086:
1.875 bisitz 15087: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 15088: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 15089: $r->print('<option value="none"></option>');
1.356 albertel 15090: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
15091: $r->print('<option value="'.$sample.'"'.
15092: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 15093: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 15094: }
1.594 raeburn 15095: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 15096: $i++;
15097: }
1.594 raeburn 15098: $r->print(&end_data_table());
1.31 albertel 15099: $i--;
15100: return $i;
15101: }
1.56 matthew 15102:
1.144 matthew 15103: ######################################################
15104: ######################################################
15105:
1.56 matthew 15106: =pod
1.31 albertel 15107:
1.648 raeburn 15108: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 15109:
15110: Prints a table of sample values from the upload and can make associate samples to internal names.
15111:
15112: $r is an Apache Request ref,
15113: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
15114: $d is an array of 2 element arrays (internal name, displayed name)
15115:
15116: =cut
15117:
1.144 matthew 15118: ######################################################
15119: ######################################################
1.31 albertel 15120: sub csv_samples_select_table {
15121: my ($r,$records,$d) = @_;
15122: my $i=0;
1.144 matthew 15123: #
1.662 bisitz 15124: my $max_samples = 5;
15125: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 15126: $r->print(&start_data_table().
15127: &start_data_table_header_row().'<th>'.
15128: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
15129: &end_data_table_header_row());
1.301 albertel 15130:
15131: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 15132: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 15133: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 15134: foreach my $option (@$d) {
15135: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 15136: $r->print('<option value="'.$value.'"'.
1.253 albertel 15137: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 15138: $display.'</option>');
1.31 albertel 15139: }
15140: $r->print('</select></td><td>');
1.662 bisitz 15141: foreach my $line (0..($max_samples-1)) {
1.301 albertel 15142: if (defined($samples->[$line]{$key})) {
15143: $r->print($samples->[$line]{$key}."<br />\n");
15144: }
15145: }
1.594 raeburn 15146: $r->print('</td>'.&end_data_table_row());
1.31 albertel 15147: $i++;
15148: }
1.594 raeburn 15149: $r->print(&end_data_table());
1.31 albertel 15150: $i--;
15151: return($i);
1.115 matthew 15152: }
15153:
1.144 matthew 15154: ######################################################
15155: ######################################################
15156:
1.115 matthew 15157: =pod
15158:
1.648 raeburn 15159: =item * &clean_excel_name($name)
1.115 matthew 15160:
15161: Returns a replacement for $name which does not contain any illegal characters.
15162:
15163: =cut
15164:
1.144 matthew 15165: ######################################################
15166: ######################################################
1.115 matthew 15167: sub clean_excel_name {
15168: my ($name) = @_;
15169: $name =~ s/[:\*\?\/\\]//g;
15170: if (length($name) > 31) {
15171: $name = substr($name,0,31);
15172: }
15173: return $name;
1.25 albertel 15174: }
1.84 albertel 15175:
1.85 albertel 15176: =pod
15177:
1.648 raeburn 15178: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 15179:
15180: Returns either 1 or undef
15181:
15182: 1 if the part is to be hidden, undef if it is to be shown
15183:
15184: Arguments are:
15185:
15186: $id the id of the part to be checked
15187: $symb, optional the symb of the resource to check
15188: $udom, optional the domain of the user to check for
15189: $uname, optional the username of the user to check for
15190:
15191: =cut
1.84 albertel 15192:
15193: sub check_if_partid_hidden {
15194: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 15195: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 15196: $symb,$udom,$uname);
1.141 albertel 15197: my $truth=1;
15198: #if the string starts with !, then the list is the list to show not hide
15199: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 15200: my @hiddenlist=split(/,/,$hiddenparts);
15201: foreach my $checkid (@hiddenlist) {
1.141 albertel 15202: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 15203: }
1.141 albertel 15204: return !$truth;
1.84 albertel 15205: }
1.127 matthew 15206:
1.138 matthew 15207:
15208: ############################################################
15209: ############################################################
15210:
15211: =pod
15212:
1.157 matthew 15213: =back
15214:
1.138 matthew 15215: =head1 cgi-bin script and graphing routines
15216:
1.157 matthew 15217: =over 4
15218:
1.648 raeburn 15219: =item * &get_cgi_id()
1.138 matthew 15220:
15221: Inputs: none
15222:
15223: Returns an id which can be used to pass environment variables
15224: to various cgi-bin scripts. These environment variables will
15225: be removed from the users environment after a given time by
15226: the routine &Apache::lonnet::transfer_profile_to_env.
15227:
15228: =cut
15229:
15230: ############################################################
15231: ############################################################
1.152 albertel 15232: my $uniq=0;
1.136 matthew 15233: sub get_cgi_id {
1.154 albertel 15234: $uniq=($uniq+1)%100000;
1.280 albertel 15235: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 15236: }
15237:
1.127 matthew 15238: ############################################################
15239: ############################################################
15240:
15241: =pod
15242:
1.648 raeburn 15243: =item * &DrawBarGraph()
1.127 matthew 15244:
1.138 matthew 15245: Facilitates the plotting of data in a (stacked) bar graph.
15246: Puts plot definition data into the users environment in order for
15247: graph.png to plot it. Returns an <img> tag for the plot.
15248: The bars on the plot are labeled '1','2',...,'n'.
15249:
15250: Inputs:
15251:
15252: =over 4
15253:
15254: =item $Title: string, the title of the plot
15255:
15256: =item $xlabel: string, text describing the X-axis of the plot
15257:
15258: =item $ylabel: string, text describing the Y-axis of the plot
15259:
15260: =item $Max: scalar, the maximum Y value to use in the plot
15261: If $Max is < any data point, the graph will not be rendered.
15262:
1.140 matthew 15263: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 15264: they are plotted. If undefined, default values will be used.
15265:
1.178 matthew 15266: =item $labels: array ref holding the labels to use on the x-axis for the bars.
15267:
1.138 matthew 15268: =item @Values: An array of array references. Each array reference holds data
15269: to be plotted in a stacked bar chart.
15270:
1.239 matthew 15271: =item If the final element of @Values is a hash reference the key/value
15272: pairs will be added to the graph definition.
15273:
1.138 matthew 15274: =back
15275:
15276: Returns:
15277:
15278: An <img> tag which references graph.png and the appropriate identifying
15279: information for the plot.
15280:
1.127 matthew 15281: =cut
15282:
15283: ############################################################
15284: ############################################################
1.134 matthew 15285: sub DrawBarGraph {
1.178 matthew 15286: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 15287: #
15288: if (! defined($colors)) {
15289: $colors = ['#33ff00',
15290: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
15291: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
15292: ];
15293: }
1.228 matthew 15294: my $extra_settings = {};
15295: if (ref($Values[-1]) eq 'HASH') {
15296: $extra_settings = pop(@Values);
15297: }
1.127 matthew 15298: #
1.136 matthew 15299: my $identifier = &get_cgi_id();
15300: my $id = 'cgi.'.$identifier;
1.129 matthew 15301: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 15302: return '';
15303: }
1.225 matthew 15304: #
15305: my @Labels;
15306: if (defined($labels)) {
15307: @Labels = @$labels;
15308: } else {
15309: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 15310: push(@Labels,$i+1);
1.225 matthew 15311: }
15312: }
15313: #
1.129 matthew 15314: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 15315: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 15316: my %ValuesHash;
15317: my $NumSets=1;
15318: foreach my $array (@Values) {
15319: next if (! ref($array));
1.136 matthew 15320: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 15321: join(',',@$array);
1.129 matthew 15322: }
1.127 matthew 15323: #
1.136 matthew 15324: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 15325: if ($NumBars < 3) {
15326: $width = 120+$NumBars*32;
1.220 matthew 15327: $xskip = 1;
1.225 matthew 15328: $bar_width = 30;
15329: } elsif ($NumBars < 5) {
15330: $width = 120+$NumBars*20;
15331: $xskip = 1;
15332: $bar_width = 20;
1.220 matthew 15333: } elsif ($NumBars < 10) {
1.136 matthew 15334: $width = 120+$NumBars*15;
15335: $xskip = 1;
15336: $bar_width = 15;
15337: } elsif ($NumBars <= 25) {
15338: $width = 120+$NumBars*11;
15339: $xskip = 5;
15340: $bar_width = 8;
15341: } elsif ($NumBars <= 50) {
15342: $width = 120+$NumBars*8;
15343: $xskip = 5;
15344: $bar_width = 4;
15345: } else {
15346: $width = 120+$NumBars*8;
15347: $xskip = 5;
15348: $bar_width = 4;
15349: }
15350: #
1.137 matthew 15351: $Max = 1 if ($Max < 1);
15352: if ( int($Max) < $Max ) {
15353: $Max++;
15354: $Max = int($Max);
15355: }
1.127 matthew 15356: $Title = '' if (! defined($Title));
15357: $xlabel = '' if (! defined($xlabel));
15358: $ylabel = '' if (! defined($ylabel));
1.369 www 15359: $ValuesHash{$id.'.title'} = &escape($Title);
15360: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
15361: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 15362: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 15363: $ValuesHash{$id.'.NumBars'} = $NumBars;
15364: $ValuesHash{$id.'.NumSets'} = $NumSets;
15365: $ValuesHash{$id.'.PlotType'} = 'bar';
15366: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15367: $ValuesHash{$id.'.height'} = $height;
15368: $ValuesHash{$id.'.width'} = $width;
15369: $ValuesHash{$id.'.xskip'} = $xskip;
15370: $ValuesHash{$id.'.bar_width'} = $bar_width;
15371: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 15372: #
1.228 matthew 15373: # Deal with other parameters
15374: while (my ($key,$value) = each(%$extra_settings)) {
15375: $ValuesHash{$id.'.'.$key} = $value;
15376: }
15377: #
1.646 raeburn 15378: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 15379: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15380: }
15381:
15382: ############################################################
15383: ############################################################
15384:
15385: =pod
15386:
1.648 raeburn 15387: =item * &DrawXYGraph()
1.137 matthew 15388:
1.138 matthew 15389: Facilitates the plotting of data in an XY graph.
15390: Puts plot definition data into the users environment in order for
15391: graph.png to plot it. Returns an <img> tag for the plot.
15392:
15393: Inputs:
15394:
15395: =over 4
15396:
15397: =item $Title: string, the title of the plot
15398:
15399: =item $xlabel: string, text describing the X-axis of the plot
15400:
15401: =item $ylabel: string, text describing the Y-axis of the plot
15402:
15403: =item $Max: scalar, the maximum Y value to use in the plot
15404: If $Max is < any data point, the graph will not be rendered.
15405:
15406: =item $colors: Array ref containing the hex color codes for the data to be
15407: plotted in. If undefined, default values will be used.
15408:
15409: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15410:
15411: =item $Ydata: Array ref containing Array refs.
1.185 www 15412: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 15413:
15414: =item %Values: hash indicating or overriding any default values which are
15415: passed to graph.png.
15416: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15417:
15418: =back
15419:
15420: Returns:
15421:
15422: An <img> tag which references graph.png and the appropriate identifying
15423: information for the plot.
15424:
1.137 matthew 15425: =cut
15426:
15427: ############################################################
15428: ############################################################
15429: sub DrawXYGraph {
15430: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
15431: #
15432: # Create the identifier for the graph
15433: my $identifier = &get_cgi_id();
15434: my $id = 'cgi.'.$identifier;
15435: #
15436: $Title = '' if (! defined($Title));
15437: $xlabel = '' if (! defined($xlabel));
15438: $ylabel = '' if (! defined($ylabel));
15439: my %ValuesHash =
15440: (
1.369 www 15441: $id.'.title' => &escape($Title),
15442: $id.'.xlabel' => &escape($xlabel),
15443: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 15444: $id.'.y_max_value'=> $Max,
15445: $id.'.labels' => join(',',@$Xlabels),
15446: $id.'.PlotType' => 'XY',
15447: );
15448: #
15449: if (defined($colors) && ref($colors) eq 'ARRAY') {
15450: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15451: }
15452: #
15453: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
15454: return '';
15455: }
15456: my $NumSets=1;
1.138 matthew 15457: foreach my $array (@{$Ydata}){
1.137 matthew 15458: next if (! ref($array));
15459: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
15460: }
1.138 matthew 15461: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 15462: #
15463: # Deal with other parameters
15464: while (my ($key,$value) = each(%Values)) {
15465: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 15466: }
15467: #
1.646 raeburn 15468: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 15469: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15470: }
15471:
15472: ############################################################
15473: ############################################################
15474:
15475: =pod
15476:
1.648 raeburn 15477: =item * &DrawXYYGraph()
1.138 matthew 15478:
15479: Facilitates the plotting of data in an XY graph with two Y axes.
15480: Puts plot definition data into the users environment in order for
15481: graph.png to plot it. Returns an <img> tag for the plot.
15482:
15483: Inputs:
15484:
15485: =over 4
15486:
15487: =item $Title: string, the title of the plot
15488:
15489: =item $xlabel: string, text describing the X-axis of the plot
15490:
15491: =item $ylabel: string, text describing the Y-axis of the plot
15492:
15493: =item $colors: Array ref containing the hex color codes for the data to be
15494: plotted in. If undefined, default values will be used.
15495:
15496: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15497:
15498: =item $Ydata1: The first data set
15499:
15500: =item $Min1: The minimum value of the left Y-axis
15501:
15502: =item $Max1: The maximum value of the left Y-axis
15503:
15504: =item $Ydata2: The second data set
15505:
15506: =item $Min2: The minimum value of the right Y-axis
15507:
15508: =item $Max2: The maximum value of the left Y-axis
15509:
15510: =item %Values: hash indicating or overriding any default values which are
15511: passed to graph.png.
15512: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15513:
15514: =back
15515:
15516: Returns:
15517:
15518: An <img> tag which references graph.png and the appropriate identifying
15519: information for the plot.
1.136 matthew 15520:
15521: =cut
15522:
15523: ############################################################
15524: ############################################################
1.137 matthew 15525: sub DrawXYYGraph {
15526: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
15527: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 15528: #
15529: # Create the identifier for the graph
15530: my $identifier = &get_cgi_id();
15531: my $id = 'cgi.'.$identifier;
15532: #
15533: $Title = '' if (! defined($Title));
15534: $xlabel = '' if (! defined($xlabel));
15535: $ylabel = '' if (! defined($ylabel));
15536: my %ValuesHash =
15537: (
1.369 www 15538: $id.'.title' => &escape($Title),
15539: $id.'.xlabel' => &escape($xlabel),
15540: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 15541: $id.'.labels' => join(',',@$Xlabels),
15542: $id.'.PlotType' => 'XY',
15543: $id.'.NumSets' => 2,
1.137 matthew 15544: $id.'.two_axes' => 1,
15545: $id.'.y1_max_value' => $Max1,
15546: $id.'.y1_min_value' => $Min1,
15547: $id.'.y2_max_value' => $Max2,
15548: $id.'.y2_min_value' => $Min2,
1.136 matthew 15549: );
15550: #
1.137 matthew 15551: if (defined($colors) && ref($colors) eq 'ARRAY') {
15552: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15553: }
15554: #
15555: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
15556: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 15557: return '';
15558: }
15559: my $NumSets=1;
1.137 matthew 15560: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 15561: next if (! ref($array));
15562: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 15563: }
15564: #
15565: # Deal with other parameters
15566: while (my ($key,$value) = each(%Values)) {
15567: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 15568: }
15569: #
1.646 raeburn 15570: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 15571: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 15572: }
15573:
15574: ############################################################
15575: ############################################################
15576:
15577: =pod
15578:
1.157 matthew 15579: =back
15580:
1.139 matthew 15581: =head1 Statistics helper routines?
15582:
15583: Bad place for them but what the hell.
15584:
1.157 matthew 15585: =over 4
15586:
1.648 raeburn 15587: =item * &chartlink()
1.139 matthew 15588:
15589: Returns a link to the chart for a specific student.
15590:
15591: Inputs:
15592:
15593: =over 4
15594:
15595: =item $linktext: The text of the link
15596:
15597: =item $sname: The students username
15598:
15599: =item $sdomain: The students domain
15600:
15601: =back
15602:
1.157 matthew 15603: =back
15604:
1.139 matthew 15605: =cut
15606:
15607: ############################################################
15608: ############################################################
15609: sub chartlink {
15610: my ($linktext, $sname, $sdomain) = @_;
15611: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15612: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15613: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15614: '">'.$linktext.'</a>';
1.153 matthew 15615: }
15616:
15617: #######################################################
15618: #######################################################
15619:
15620: =pod
15621:
15622: =head1 Course Environment Routines
1.157 matthew 15623:
15624: =over 4
1.153 matthew 15625:
1.648 raeburn 15626: =item * &restore_course_settings()
1.153 matthew 15627:
1.648 raeburn 15628: =item * &store_course_settings()
1.153 matthew 15629:
15630: Restores/Store indicated form parameters from the course environment.
15631: Will not overwrite existing values of the form parameters.
15632:
15633: Inputs:
15634: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15635:
15636: a hash ref describing the data to be stored. For example:
15637:
15638: %Save_Parameters = ('Status' => 'scalar',
15639: 'chartoutputmode' => 'scalar',
15640: 'chartoutputdata' => 'scalar',
15641: 'Section' => 'array',
1.373 raeburn 15642: 'Group' => 'array',
1.153 matthew 15643: 'StudentData' => 'array',
15644: 'Maps' => 'array');
15645:
15646: Returns: both routines return nothing
15647:
1.631 raeburn 15648: =back
15649:
1.153 matthew 15650: =cut
15651:
15652: #######################################################
15653: #######################################################
15654: sub store_course_settings {
1.496 albertel 15655: return &store_settings($env{'request.course.id'},@_);
15656: }
15657:
15658: sub store_settings {
1.153 matthew 15659: # save to the environment
15660: # appenv the same items, just to be safe
1.300 albertel 15661: my $udom = $env{'user.domain'};
15662: my $uname = $env{'user.name'};
1.496 albertel 15663: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15664: my %SaveHash;
15665: my %AppHash;
15666: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15667: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15668: my $envname = 'environment.'.$basename;
1.258 albertel 15669: if (exists($env{'form.'.$setting})) {
1.153 matthew 15670: # Save this value away
15671: if ($type eq 'scalar' &&
1.258 albertel 15672: (! exists($env{$envname}) ||
15673: $env{$envname} ne $env{'form.'.$setting})) {
15674: $SaveHash{$basename} = $env{'form.'.$setting};
15675: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15676: } elsif ($type eq 'array') {
15677: my $stored_form;
1.258 albertel 15678: if (ref($env{'form.'.$setting})) {
1.153 matthew 15679: $stored_form = join(',',
15680: map {
1.369 www 15681: &escape($_);
1.258 albertel 15682: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15683: } else {
15684: $stored_form =
1.369 www 15685: &escape($env{'form.'.$setting});
1.153 matthew 15686: }
15687: # Determine if the array contents are the same.
1.258 albertel 15688: if ($stored_form ne $env{$envname}) {
1.153 matthew 15689: $SaveHash{$basename} = $stored_form;
15690: $AppHash{$envname} = $stored_form;
15691: }
15692: }
15693: }
15694: }
15695: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15696: $udom,$uname);
1.153 matthew 15697: if ($put_result !~ /^(ok|delayed)/) {
15698: &Apache::lonnet::logthis('unable to save form parameters, '.
15699: 'got error:'.$put_result);
15700: }
15701: # Make sure these settings stick around in this session, too
1.646 raeburn 15702: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15703: return;
15704: }
15705:
15706: sub restore_course_settings {
1.499 albertel 15707: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15708: }
15709:
15710: sub restore_settings {
15711: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15712: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15713: next if (exists($env{'form.'.$setting}));
1.496 albertel 15714: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15715: '.'.$setting;
1.258 albertel 15716: if (exists($env{$envname})) {
1.153 matthew 15717: if ($type eq 'scalar') {
1.258 albertel 15718: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15719: } elsif ($type eq 'array') {
1.258 albertel 15720: $env{'form.'.$setting} = [
1.153 matthew 15721: map {
1.369 www 15722: &unescape($_);
1.258 albertel 15723: } split(',',$env{$envname})
1.153 matthew 15724: ];
15725: }
15726: }
15727: }
1.127 matthew 15728: }
15729:
1.618 raeburn 15730: #######################################################
15731: #######################################################
15732:
15733: =pod
15734:
15735: =head1 Domain E-mail Routines
15736:
15737: =over 4
15738:
1.648 raeburn 15739: =item * &build_recipient_list()
1.618 raeburn 15740:
1.1144 raeburn 15741: Build recipient lists for following types of e-mail:
1.766 raeburn 15742: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 15743: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15744: module change checking, student/employee ID conflict checks, as
15745: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15746: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15747:
15748: Inputs:
1.619 raeburn 15749: defmail (scalar - email address of default recipient),
1.1144 raeburn 15750: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15751: requestsmail, updatesmail, or idconflictsmail).
15752:
1.619 raeburn 15753: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 15754:
1.619 raeburn 15755: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 15756: i.e., predates configuration by DC via domainprefs.pm
15757:
15758: $requname username of requester (if mailing type is helpdeskmail)
15759:
15760: $requdom domain of requester (if mailing type is helpdeskmail)
15761:
15762: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15763:
1.618 raeburn 15764:
1.655 raeburn 15765: Returns: comma separated list of addresses to which to send e-mail.
15766:
15767: =back
1.618 raeburn 15768:
15769: =cut
15770:
15771: ############################################################
15772: ############################################################
15773: sub build_recipient_list {
1.1297 raeburn 15774: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15775: my @recipients;
1.1270 raeburn 15776: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15777: my %domconfig =
1.1270 raeburn 15778: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15779: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15780: if (exists($domconfig{'contacts'}{$mailing})) {
15781: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15782: my @contacts = ('adminemail','supportemail');
15783: foreach my $item (@contacts) {
15784: if ($domconfig{'contacts'}{$mailing}{$item}) {
15785: my $addr = $domconfig{'contacts'}{$item};
15786: if (!grep(/^\Q$addr\E$/,@recipients)) {
15787: push(@recipients,$addr);
15788: }
1.619 raeburn 15789: }
1.1270 raeburn 15790: }
15791: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15792: if ($mailing eq 'helpdeskmail') {
15793: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15794: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15795: my @ok_bccs;
15796: foreach my $bcc (@bccs) {
15797: $bcc =~ s/^\s+//g;
15798: $bcc =~ s/\s+$//g;
15799: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15800: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15801: push(@ok_bccs,$bcc);
15802: }
15803: }
15804: }
15805: if (@ok_bccs > 0) {
15806: $allbcc = join(', ',@ok_bccs);
15807: }
15808: }
15809: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15810: }
15811: }
1.766 raeburn 15812: } elsif ($origmail ne '') {
1.1270 raeburn 15813: $lastresort = $origmail;
1.618 raeburn 15814: }
1.1297 raeburn 15815: if ($mailing eq 'helpdeskmail') {
15816: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15817: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15818: my ($inststatus,$inststatus_checked);
15819: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15820: ($env{'user.domain'} ne 'public')) {
15821: $inststatus_checked = 1;
15822: $inststatus = $env{'environment.inststatus'};
15823: }
15824: unless ($inststatus_checked) {
15825: if (($requname ne '') && ($requdom ne '')) {
15826: if (($requname =~ /^$match_username$/) &&
15827: ($requdom =~ /^$match_domain$/) &&
15828: (&Apache::lonnet::domain($requdom))) {
15829: my $requhome = &Apache::lonnet::homeserver($requname,
15830: $requdom);
15831: unless ($requhome eq 'no_host') {
15832: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15833: $inststatus = $userenv{'inststatus'};
15834: $inststatus_checked = 1;
15835: }
15836: }
15837: }
15838: }
15839: unless ($inststatus_checked) {
15840: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15841: my %srch = (srchby => 'email',
15842: srchdomain => $defdom,
15843: srchterm => $reqemail,
15844: srchtype => 'exact');
15845: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15846: foreach my $uname (keys(%srch_results)) {
15847: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15848: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15849: $inststatus_checked = 1;
15850: last;
15851: }
15852: }
15853: unless ($inststatus_checked) {
15854: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15855: if ($dirsrchres eq 'ok') {
15856: foreach my $uname (keys(%srch_results)) {
15857: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15858: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15859: $inststatus_checked = 1;
15860: last;
15861: }
15862: }
15863: }
15864: }
15865: }
15866: }
15867: if ($inststatus ne '') {
15868: foreach my $status (split(/\:/,$inststatus)) {
15869: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15870: my @contacts = ('adminemail','supportemail');
15871: foreach my $item (@contacts) {
15872: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15873: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15874: if (!grep(/^\Q$addr\E$/,@recipients)) {
15875: push(@recipients,$addr);
15876: }
15877: }
15878: }
15879: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15880: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15881: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15882: my @ok_bccs;
15883: foreach my $bcc (@bccs) {
15884: $bcc =~ s/^\s+//g;
15885: $bcc =~ s/\s+$//g;
15886: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15887: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15888: push(@ok_bccs,$bcc);
15889: }
15890: }
15891: }
15892: if (@ok_bccs > 0) {
15893: $allbcc = join(', ',@ok_bccs);
15894: }
15895: }
15896: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15897: last;
15898: }
15899: }
15900: }
15901: }
15902: }
1.619 raeburn 15903: } elsif ($origmail ne '') {
1.1270 raeburn 15904: $lastresort = $origmail;
15905: }
1.1297 raeburn 15906: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15907: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15908: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15909: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15910: my %what = (
15911: perlvar => 1,
15912: );
15913: my $primary = &Apache::lonnet::domain($defdom,'primary');
15914: if ($primary) {
15915: my $gotaddr;
15916: my ($result,$returnhash) =
15917: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15918: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15919: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15920: $lastresort = $returnhash->{'lonSupportEMail'};
15921: $gotaddr = 1;
15922: }
15923: }
15924: unless ($gotaddr) {
15925: my $uintdom = &Apache::lonnet::internet_dom($primary);
15926: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15927: unless ($uintdom eq $intdom) {
15928: my %domconfig =
15929: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15930: if (ref($domconfig{'contacts'}) eq 'HASH') {
15931: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15932: my @contacts = ('adminemail','supportemail');
15933: foreach my $item (@contacts) {
15934: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15935: my $addr = $domconfig{'contacts'}{$item};
15936: if (!grep(/^\Q$addr\E$/,@recipients)) {
15937: push(@recipients,$addr);
15938: }
15939: }
15940: }
15941: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15942: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15943: }
15944: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15945: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15946: my @ok_bccs;
15947: foreach my $bcc (@bccs) {
15948: $bcc =~ s/^\s+//g;
15949: $bcc =~ s/\s+$//g;
15950: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15951: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15952: push(@ok_bccs,$bcc);
15953: }
15954: }
15955: }
15956: if (@ok_bccs > 0) {
15957: $allbcc = join(', ',@ok_bccs);
15958: }
15959: }
15960: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15961: }
15962: }
15963: }
15964: }
15965: }
15966: }
1.618 raeburn 15967: }
1.688 raeburn 15968: if (defined($defmail)) {
15969: if ($defmail ne '') {
15970: push(@recipients,$defmail);
15971: }
1.618 raeburn 15972: }
15973: if ($otheremails) {
1.619 raeburn 15974: my @others;
15975: if ($otheremails =~ /,/) {
15976: @others = split(/,/,$otheremails);
1.618 raeburn 15977: } else {
1.619 raeburn 15978: push(@others,$otheremails);
15979: }
15980: foreach my $addr (@others) {
15981: if (!grep(/^\Q$addr\E$/,@recipients)) {
15982: push(@recipients,$addr);
15983: }
1.618 raeburn 15984: }
15985: }
1.1298 raeburn 15986: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15987: if ((!@recipients) && ($lastresort ne '')) {
15988: push(@recipients,$lastresort);
15989: }
15990: } elsif ($lastresort ne '') {
15991: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15992: push(@recipients,$lastresort);
15993: }
15994: }
1.1271 raeburn 15995: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15996: if (wantarray) {
15997: return ($recipientlist,$allbcc,$addtext);
15998: } else {
15999: return $recipientlist;
16000: }
1.618 raeburn 16001: }
16002:
1.127 matthew 16003: ############################################################
16004: ############################################################
1.154 albertel 16005:
1.655 raeburn 16006: =pod
16007:
1.1224 musolffc 16008: =over 4
16009:
1.1223 musolffc 16010: =item * &mime_email()
16011:
16012: Sends an email with a possible attachment
16013:
16014: Inputs:
16015:
16016: =over 4
16017:
16018: from - Sender's email address
16019:
1.1343 raeburn 16020: replyto - Reply-To email address
16021:
1.1223 musolffc 16022: to - Email address of recipient
16023:
16024: subject - Subject of email
16025:
16026: body - Body of email
16027:
16028: cc_string - Carbon copy email address
16029:
16030: bcc - Blind carbon copy email address
16031:
16032: attachment_path - Path of file to be attached
16033:
16034: file_name - Name of file to be attached
16035:
16036: attachment_text - The body of an attachment of type "TEXT"
16037:
16038: =back
16039:
16040: =back
16041:
16042: =cut
16043:
16044: ############################################################
16045: ############################################################
16046:
16047: sub mime_email {
1.1343 raeburn 16048: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
16049: $file_name,$attachment_text) = @_;
16050:
1.1223 musolffc 16051: my $msg = MIME::Lite->new(
16052: From => $from,
16053: To => $to,
16054: Subject => $subject,
16055: Type =>'TEXT',
16056: Data => $body,
16057: );
1.1343 raeburn 16058: if ($replyto ne '') {
16059: $msg->add("Reply-To" => $replyto);
16060: }
1.1223 musolffc 16061: if ($cc_string ne '') {
16062: $msg->add("Cc" => $cc_string);
16063: }
16064: if ($bcc ne '') {
16065: $msg->add("Bcc" => $bcc);
16066: }
16067: $msg->attr("content-type" => "text/plain");
16068: $msg->attr("content-type.charset" => "UTF-8");
16069: # Attach file if given
16070: if ($attachment_path) {
16071: unless ($file_name) {
16072: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
16073: }
16074: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
16075: $msg->attach(Type => $type,
16076: Path => $attachment_path,
16077: Filename => $file_name
16078: );
16079: # Otherwise attach text if given
16080: } elsif ($attachment_text) {
16081: $msg->attach(Type => 'TEXT',
16082: Data => $attachment_text);
16083: }
16084: # Send it
16085: $msg->send('sendmail');
16086: }
16087:
16088: ############################################################
16089: ############################################################
16090:
16091: =pod
16092:
1.655 raeburn 16093: =head1 Course Catalog Routines
16094:
16095: =over 4
16096:
16097: =item * &gather_categories()
16098:
16099: Converts category definitions - keys of categories hash stored in
16100: coursecategories in configuration.db on the primary library server in a
16101: domain - to an array. Also generates javascript and idx hash used to
16102: generate Domain Coordinator interface for editing Course Categories.
16103:
16104: Inputs:
1.663 raeburn 16105:
1.655 raeburn 16106: categories (reference to hash of category definitions).
1.663 raeburn 16107:
1.655 raeburn 16108: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16109: categories and subcategories).
1.663 raeburn 16110:
1.655 raeburn 16111: idx (reference to hash of counters used in Domain Coordinator interface for
16112: editing Course Categories).
1.663 raeburn 16113:
1.655 raeburn 16114: jsarray (reference to array of categories used to create Javascript arrays for
16115: Domain Coordinator interface for editing Course Categories).
16116:
16117: Returns: nothing
16118:
16119: Side effects: populates cats, idx and jsarray.
16120:
16121: =cut
16122:
16123: sub gather_categories {
16124: my ($categories,$cats,$idx,$jsarray) = @_;
16125: my %counters;
16126: my $num = 0;
16127: foreach my $item (keys(%{$categories})) {
16128: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16129: if ($container eq '' && $depth == 0) {
16130: $cats->[$depth][$categories->{$item}] = $cat;
16131: } else {
16132: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
16133: }
16134: my ($escitem,$tail) = split(/:/,$item,2);
16135: if ($counters{$tail} eq '') {
16136: $counters{$tail} = $num;
16137: $num ++;
16138: }
16139: if (ref($idx) eq 'HASH') {
16140: $idx->{$item} = $counters{$tail};
16141: }
16142: if (ref($jsarray) eq 'ARRAY') {
16143: push(@{$jsarray->[$counters{$tail}]},$item);
16144: }
16145: }
16146: return;
16147: }
16148:
16149: =pod
16150:
16151: =item * &extract_categories()
16152:
16153: Used to generate breadcrumb trails for course categories.
16154:
16155: Inputs:
1.663 raeburn 16156:
1.655 raeburn 16157: categories (reference to hash of category definitions).
1.663 raeburn 16158:
1.655 raeburn 16159: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16160: categories and subcategories).
1.663 raeburn 16161:
1.655 raeburn 16162: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 16163:
1.655 raeburn 16164: allitems (reference to hash - key is category key
16165: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16166:
1.655 raeburn 16167: idx (reference to hash of counters used in Domain Coordinator interface for
16168: editing Course Categories).
1.663 raeburn 16169:
1.655 raeburn 16170: jsarray (reference to array of categories used to create Javascript arrays for
16171: Domain Coordinator interface for editing Course Categories).
16172:
1.665 raeburn 16173: subcats (reference to hash of arrays containing all subcategories within each
16174: category, -recursive)
16175:
1.1321 raeburn 16176: maxd (reference to hash used to hold max depth for all top-level categories).
16177:
1.655 raeburn 16178: Returns: nothing
16179:
16180: Side effects: populates trails and allitems hash references.
16181:
16182: =cut
16183:
16184: sub extract_categories {
1.1321 raeburn 16185: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 16186: if (ref($categories) eq 'HASH') {
16187: &gather_categories($categories,$cats,$idx,$jsarray);
16188: if (ref($cats->[0]) eq 'ARRAY') {
16189: for (my $i=0; $i<@{$cats->[0]}; $i++) {
16190: my $name = $cats->[0][$i];
16191: my $item = &escape($name).'::0';
16192: my $trailstr;
16193: if ($name eq 'instcode') {
16194: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 16195: } elsif ($name eq 'communities') {
16196: $trailstr = &mt('Communities');
1.1239 raeburn 16197: } elsif ($name eq 'placement') {
16198: $trailstr = &mt('Placement Tests');
1.655 raeburn 16199: } else {
16200: $trailstr = $name;
16201: }
16202: if ($allitems->{$item} eq '') {
16203: push(@{$trails},$trailstr);
16204: $allitems->{$item} = scalar(@{$trails})-1;
16205: }
16206: my @parents = ($name);
16207: if (ref($cats->[1]{$name}) eq 'ARRAY') {
16208: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
16209: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 16210: if (ref($subcats) eq 'HASH') {
16211: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
16212: }
1.1321 raeburn 16213: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 16214: }
16215: } else {
16216: if (ref($subcats) eq 'HASH') {
16217: $subcats->{$item} = [];
1.655 raeburn 16218: }
1.1321 raeburn 16219: if (ref($maxd) eq 'HASH') {
16220: $maxd->{$name} = 1;
16221: }
1.655 raeburn 16222: }
16223: }
16224: }
16225: }
16226: return;
16227: }
16228:
16229: =pod
16230:
1.1162 raeburn 16231: =item * &recurse_categories()
1.655 raeburn 16232:
16233: Recursively used to generate breadcrumb trails for course categories.
16234:
16235: Inputs:
1.663 raeburn 16236:
1.655 raeburn 16237: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16238: categories and subcategories).
1.663 raeburn 16239:
1.655 raeburn 16240: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 16241:
16242: category (current course category, for which breadcrumb trail is being generated).
16243:
16244: trails (reference to array of breadcrumb trails for each category).
16245:
1.655 raeburn 16246: allitems (reference to hash - key is category key
16247: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16248:
1.655 raeburn 16249: parents (array containing containers directories for current category,
16250: back to top level).
16251:
16252: Returns: nothing
16253:
16254: Side effects: populates trails and allitems hash references
16255:
16256: =cut
16257:
16258: sub recurse_categories {
1.1321 raeburn 16259: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 16260: my $shallower = $depth - 1;
16261: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
16262: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
16263: my $name = $cats->[$depth]{$category}[$k];
16264: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16265: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16266: if ($allitems->{$item} eq '') {
16267: push(@{$trails},$trailstr);
16268: $allitems->{$item} = scalar(@{$trails})-1;
16269: }
16270: my $deeper = $depth+1;
16271: push(@{$parents},$category);
1.665 raeburn 16272: if (ref($subcats) eq 'HASH') {
16273: my $subcat = &escape($name).':'.$category.':'.$depth;
16274: for (my $j=@{$parents}; $j>=0; $j--) {
16275: my $higher;
16276: if ($j > 0) {
16277: $higher = &escape($parents->[$j]).':'.
16278: &escape($parents->[$j-1]).':'.$j;
16279: } else {
16280: $higher = &escape($parents->[$j]).'::'.$j;
16281: }
16282: push(@{$subcats->{$higher}},$subcat);
16283: }
16284: }
16285: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 16286: $subcats,$maxd);
1.655 raeburn 16287: pop(@{$parents});
16288: }
16289: } else {
16290: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16291: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16292: if ($allitems->{$item} eq '') {
16293: push(@{$trails},$trailstr);
16294: $allitems->{$item} = scalar(@{$trails})-1;
16295: }
1.1321 raeburn 16296: if (ref($maxd) eq 'HASH') {
16297: if ($depth > $maxd->{$parents->[0]}) {
16298: $maxd->{$parents->[0]} = $depth;
16299: }
16300: }
1.655 raeburn 16301: }
16302: return;
16303: }
16304:
1.663 raeburn 16305: =pod
16306:
1.1162 raeburn 16307: =item * &assign_categories_table()
1.663 raeburn 16308:
16309: Create a datatable for display of hierarchical categories in a domain,
16310: with checkboxes to allow a course to be categorized.
16311:
16312: Inputs:
16313:
16314: cathash - reference to hash of categories defined for the domain (from
16315: configuration.db)
16316:
16317: currcat - scalar with an & separated list of categories assigned to a course.
16318:
1.919 raeburn 16319: type - scalar contains course type (Course or Community).
16320:
1.1260 raeburn 16321: disabled - scalar (optional) contains disabled="disabled" if input elements are
16322: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16323:
1.663 raeburn 16324: Returns: $output (markup to be displayed)
16325:
16326: =cut
16327:
16328: sub assign_categories_table {
1.1259 raeburn 16329: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 16330: my $output;
16331: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 16332: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
16333: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 16334: $maxdepth = scalar(@cats);
16335: if (@cats > 0) {
16336: my $itemcount = 0;
16337: if (ref($cats[0]) eq 'ARRAY') {
16338: my @currcategories;
16339: if ($currcat ne '') {
16340: @currcategories = split('&',$currcat);
16341: }
1.919 raeburn 16342: my $table;
1.663 raeburn 16343: for (my $i=0; $i<@{$cats[0]}; $i++) {
16344: my $parent = $cats[0][$i];
1.919 raeburn 16345: next if ($parent eq 'instcode');
16346: if ($type eq 'Community') {
16347: next unless ($parent eq 'communities');
1.1239 raeburn 16348: } elsif ($type eq 'Placement') {
16349: next unless ($parent eq 'placement');
1.919 raeburn 16350: } else {
1.1239 raeburn 16351: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 16352: }
1.663 raeburn 16353: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
16354: my $item = &escape($parent).'::0';
16355: my $checked = '';
16356: if (@currcategories > 0) {
16357: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 16358: $checked = ' checked="checked"';
1.663 raeburn 16359: }
16360: }
1.919 raeburn 16361: my $parent_title = $parent;
16362: if ($parent eq 'communities') {
16363: $parent_title = &mt('Communities');
1.1239 raeburn 16364: } elsif ($parent eq 'placement') {
16365: $parent_title = &mt('Placement Tests');
1.919 raeburn 16366: }
16367: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
16368: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16369: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 16370: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 16371: my $depth = 1;
16372: push(@path,$parent);
1.1259 raeburn 16373: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 16374: pop(@path);
1.919 raeburn 16375: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 16376: $itemcount ++;
16377: }
1.919 raeburn 16378: if ($itemcount) {
16379: $output = &Apache::loncommon::start_data_table().
16380: $table.
16381: &Apache::loncommon::end_data_table();
16382: }
1.663 raeburn 16383: }
16384: }
16385: }
16386: return $output;
16387: }
16388:
16389: =pod
16390:
1.1162 raeburn 16391: =item * &assign_category_rows()
1.663 raeburn 16392:
16393: Create a datatable row for display of nested categories in a domain,
16394: with checkboxes to allow a course to be categorized,called recursively.
16395:
16396: Inputs:
16397:
16398: itemcount - track row number for alternating colors
16399:
16400: cats - reference to array of arrays/hashes which encapsulates hierarchy of
16401: categories and subcategories.
16402:
16403: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
16404:
16405: parent - parent of current category item
16406:
16407: path - Array containing all categories back up through the hierarchy from the
16408: current category to the top level.
16409:
16410: currcategories - reference to array of current categories assigned to the course
16411:
1.1260 raeburn 16412: disabled - scalar (optional) contains disabled="disabled" if input elements are
16413: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16414:
1.663 raeburn 16415: Returns: $output (markup to be displayed).
16416:
16417: =cut
16418:
16419: sub assign_category_rows {
1.1259 raeburn 16420: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 16421: my ($text,$name,$item,$chgstr);
16422: if (ref($cats) eq 'ARRAY') {
16423: my $maxdepth = scalar(@{$cats});
16424: if (ref($cats->[$depth]) eq 'HASH') {
16425: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
16426: my $numchildren = @{$cats->[$depth]{$parent}};
16427: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 16428: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 16429: for (my $j=0; $j<$numchildren; $j++) {
16430: $name = $cats->[$depth]{$parent}[$j];
16431: $item = &escape($name).':'.&escape($parent).':'.$depth;
16432: my $deeper = $depth+1;
16433: my $checked = '';
16434: if (ref($currcategories) eq 'ARRAY') {
16435: if (@{$currcategories} > 0) {
16436: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 16437: $checked = ' checked="checked"';
1.663 raeburn 16438: }
16439: }
16440: }
1.664 raeburn 16441: $text .= '<tr><td><span class="LC_nobreak"><label>'.
16442: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16443: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 16444: '<input type="hidden" name="catname" value="'.$name.'" />'.
16445: '</td><td>';
1.663 raeburn 16446: if (ref($path) eq 'ARRAY') {
16447: push(@{$path},$name);
1.1259 raeburn 16448: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 16449: pop(@{$path});
16450: }
16451: $text .= '</td></tr>';
16452: }
16453: $text .= '</table></td>';
16454: }
16455: }
16456: }
16457: return $text;
16458: }
16459:
1.1181 raeburn 16460: =pod
16461:
16462: =back
16463:
16464: =cut
16465:
1.655 raeburn 16466: ############################################################
16467: ############################################################
16468:
16469:
1.443 albertel 16470: sub commit_customrole {
1.664 raeburn 16471: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.1399 raeburn 16472: my $result = &Apache::lonnet::assigncustomrole(
16473: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context);
1.630 raeburn 16474: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 16475: ($start?', '.&mt('starting').' '.localtime($start):'').
1.1399 raeburn 16476: ($end?', ending '.localtime($end):'').': <b>'.$result.'</b><br />';
16477: if (wantarray) {
16478: return ($output,$result);
16479: } else {
16480: return $output;
16481: }
1.443 albertel 16482: }
16483:
16484: sub commit_standardrole {
1.1116 raeburn 16485: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.1399 raeburn 16486: my ($output,$logmsg,$linefeed,$result);
1.541 raeburn 16487: if ($context eq 'auto') {
16488: $linefeed = "\n";
16489: } else {
16490: $linefeed = "<br />\n";
16491: }
1.443 albertel 16492: if ($three eq 'st') {
1.1399 raeburn 16493: $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
16494: $one,$two,$sec,$context,$credits);
1.541 raeburn 16495: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 16496: ($result eq 'unknown_course') || ($result eq 'refused')) {
16497: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 16498: } else {
1.541 raeburn 16499: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 16500: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16501: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
16502: if ($context eq 'auto') {
16503: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
16504: } else {
16505: $output .= '<b>'.$result.'</b>'.$linefeed.
16506: &mt('Add to classlist').': <b>ok</b>';
16507: }
16508: $output .= $linefeed;
1.443 albertel 16509: }
16510: } else {
16511: $output = &mt('Assigning').' '.$three.' in '.$url.
16512: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16513: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.1399 raeburn 16514: $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 16515: if ($context eq 'auto') {
16516: $output .= $result.$linefeed;
16517: } else {
16518: $output .= '<b>'.$result.'</b>'.$linefeed;
16519: }
1.443 albertel 16520: }
1.1399 raeburn 16521: if (wantarray) {
16522: return ($output,$result);
16523: } else {
16524: return $output;
16525: }
1.443 albertel 16526: }
16527:
16528: sub commit_studentrole {
1.1116 raeburn 16529: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
16530: $credits) = @_;
1.626 raeburn 16531: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 16532: if ($context eq 'auto') {
16533: $linefeed = "\n";
16534: } else {
16535: $linefeed = '<br />'."\n";
16536: }
1.443 albertel 16537: if (defined($one) && defined($two)) {
16538: my $cid=$one.'_'.$two;
16539: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
16540: my $secchange = 0;
16541: my $expire_role_result;
16542: my $modify_section_result;
1.628 raeburn 16543: if ($oldsec ne '-1') {
16544: if ($oldsec ne $sec) {
1.443 albertel 16545: $secchange = 1;
1.628 raeburn 16546: my $now = time;
1.443 albertel 16547: my $uurl='/'.$cid;
16548: $uurl=~s/\_/\//g;
16549: if ($oldsec) {
16550: $uurl.='/'.$oldsec;
16551: }
1.626 raeburn 16552: $oldsecurl = $uurl;
1.628 raeburn 16553: $expire_role_result =
1.1398 raeburn 16554: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','','',$context);
1.628 raeburn 16555: if ($env{'request.course.sec'} ne '') {
16556: if ($expire_role_result eq 'refused') {
16557: my @roles = ('st');
16558: my @statuses = ('previous');
16559: my @roledoms = ($one);
16560: my $withsec = 1;
16561: my %roleshash =
16562: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
16563: \@statuses,\@roles,\@roledoms,$withsec);
16564: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
16565: my ($oldstart,$oldend) =
16566: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
16567: if ($oldend > 0 && $oldend <= $now) {
16568: $expire_role_result = 'ok';
16569: }
16570: }
16571: }
16572: }
1.443 albertel 16573: $result = $expire_role_result;
16574: }
16575: }
16576: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 16577: $modify_section_result =
16578: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
16579: undef,undef,undef,$sec,
16580: $end,$start,'','',$cid,
16581: '',$context,$credits);
1.443 albertel 16582: if ($modify_section_result =~ /^ok/) {
16583: if ($secchange == 1) {
1.628 raeburn 16584: if ($sec eq '') {
16585: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
16586: } else {
16587: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
16588: }
1.443 albertel 16589: } elsif ($oldsec eq '-1') {
1.628 raeburn 16590: if ($sec eq '') {
16591: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
16592: } else {
16593: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16594: }
1.443 albertel 16595: } else {
1.628 raeburn 16596: if ($sec eq '') {
16597: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
16598: } else {
16599: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16600: }
1.443 albertel 16601: }
16602: } else {
1.1115 raeburn 16603: if ($secchange) {
1.628 raeburn 16604: $$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;
16605: } else {
16606: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
16607: }
1.443 albertel 16608: }
16609: $result = $modify_section_result;
16610: } elsif ($secchange == 1) {
1.628 raeburn 16611: if ($oldsec eq '') {
1.1103 raeburn 16612: $$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 16613: } else {
16614: $$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;
16615: }
1.626 raeburn 16616: if ($expire_role_result eq 'refused') {
16617: my $newsecurl = '/'.$cid;
16618: $newsecurl =~ s/\_/\//g;
16619: if ($sec ne '') {
16620: $newsecurl.='/'.$sec;
16621: }
16622: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
16623: if ($sec eq '') {
16624: $$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;
16625: } else {
16626: $$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;
16627: }
16628: }
16629: }
1.443 albertel 16630: }
16631: } else {
1.626 raeburn 16632: $$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 16633: $result = "error: incomplete course id\n";
16634: }
16635: return $result;
16636: }
16637:
1.1108 raeburn 16638: sub show_role_extent {
16639: my ($scope,$context,$role) = @_;
16640: $scope =~ s{^/}{};
16641: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
16642: push(@courseroles,'co');
16643: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
16644: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
16645: $scope =~ s{/}{_};
16646: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
16647: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
16648: my ($audom,$auname) = split(/\//,$scope);
16649: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
16650: &Apache::loncommon::plainname($auname,$audom).'</span>');
16651: } else {
16652: $scope =~ s{/$}{};
16653: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
16654: &Apache::lonnet::domain($scope,'description').'</span>');
16655: }
16656: }
16657:
1.443 albertel 16658: ############################################################
16659: ############################################################
16660:
1.566 albertel 16661: sub check_clone {
1.578 raeburn 16662: my ($args,$linefeed) = @_;
1.566 albertel 16663: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
16664: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
16665: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 16666: my $clonetitle;
16667: my @clonemsg;
1.566 albertel 16668: my $can_clone = 0;
1.944 raeburn 16669: my $lctype = lc($args->{'crstype'});
1.908 raeburn 16670: if ($lctype ne 'community') {
16671: $lctype = 'course';
16672: }
1.566 albertel 16673: if ($clonehome eq 'no_host') {
1.944 raeburn 16674: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16675: push(@clonemsg,({
16676: mt => 'No new community created.',
16677: args => [],
16678: },
16679: {
16680: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16681: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16682: }));
1.908 raeburn 16683: } else {
1.1344 raeburn 16684: push(@clonemsg,({
16685: mt => 'No new course created.',
16686: args => [],
16687: },
16688: {
16689: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16690: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16691: }));
16692: }
1.566 albertel 16693: } else {
16694: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 16695: $clonetitle = $clonedesc{'description'};
1.944 raeburn 16696: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16697: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 16698: push(@clonemsg,({
16699: mt => 'No new community created.',
16700: args => [],
16701: },
16702: {
16703: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16704: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16705: }));
16706: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16707: }
16708: }
1.1262 raeburn 16709: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16710: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16711: $can_clone = 1;
16712: } else {
1.1221 raeburn 16713: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16714: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 16715: if ($clonehash{'cloners'} eq '') {
16716: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16717: if ($domdefs{'canclone'}) {
16718: unless ($domdefs{'canclone'} eq 'none') {
16719: if ($domdefs{'canclone'} eq 'domain') {
16720: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16721: $can_clone = 1;
16722: }
16723: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16724: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16725: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16726: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16727: $can_clone = 1;
16728: }
16729: }
16730: }
16731: }
1.578 raeburn 16732: } else {
1.1221 raeburn 16733: my @cloners = split(/,/,$clonehash{'cloners'});
16734: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16735: $can_clone = 1;
1.1221 raeburn 16736: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16737: $can_clone = 1;
1.1225 raeburn 16738: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16739: $can_clone = 1;
1.1221 raeburn 16740: }
16741: unless ($can_clone) {
1.1225 raeburn 16742: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16743: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 16744: my (%gotdomdefaults,%gotcodedefaults);
16745: foreach my $cloner (@cloners) {
16746: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16747: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16748: my (%codedefaults,@code_order);
16749: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16750: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16751: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16752: }
16753: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16754: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16755: }
16756: } else {
16757: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16758: \%codedefaults,
16759: \@code_order);
16760: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16761: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16762: }
16763: if (@code_order > 0) {
16764: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16765: $cloner,$clonehash{'internal.coursecode'},
16766: $args->{'crscode'})) {
16767: $can_clone = 1;
16768: last;
16769: }
16770: }
16771: }
16772: }
16773: }
1.1225 raeburn 16774: }
16775: }
16776: unless ($can_clone) {
16777: my $ccrole = 'cc';
16778: if ($args->{'crstype'} eq 'Community') {
16779: $ccrole = 'co';
16780: }
16781: my %roleshash =
16782: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16783: $args->{'ccdomain'},
16784: 'userroles',['active'],[$ccrole],
16785: [$args->{'clonedomain'}]);
16786: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16787: $can_clone = 1;
16788: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16789: $args->{'ccuname'},$args->{'ccdomain'})) {
16790: $can_clone = 1;
1.1221 raeburn 16791: }
16792: }
16793: unless ($can_clone) {
16794: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16795: push(@clonemsg,({
16796: mt => 'No new community created.',
16797: args => [],
16798: },
16799: {
16800: 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]).',
16801: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16802: }));
1.942 raeburn 16803: } else {
1.1344 raeburn 16804: push(@clonemsg,({
16805: mt => 'No new course created.',
16806: args => [],
16807: },
16808: {
16809: 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]).',
16810: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16811: }));
1.1221 raeburn 16812: }
1.566 albertel 16813: }
1.578 raeburn 16814: }
1.566 albertel 16815: }
1.1344 raeburn 16816: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16817: }
16818:
1.444 albertel 16819: sub construct_course {
1.1262 raeburn 16820: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 16821: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16822: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16823: my $linefeed = '<br />'."\n";
16824: if ($context eq 'auto') {
16825: $linefeed = "\n";
16826: }
1.566 albertel 16827:
16828: #
16829: # Are we cloning?
16830: #
1.1344 raeburn 16831: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16832: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 16833: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16834: if (!$can_clone) {
1.1344 raeburn 16835: return (0,$outcome,$clonemsgref);
1.566 albertel 16836: }
16837: }
16838:
1.444 albertel 16839: #
16840: # Open course
16841: #
1.1239 raeburn 16842: my $showncrstype;
16843: if ($args->{'crstype'} eq 'Placement') {
16844: $showncrstype = 'placement test';
16845: } else {
16846: $showncrstype = lc($args->{'crstype'});
16847: }
1.444 albertel 16848: my %cenv=();
16849: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16850: $args->{'cdescr'},
16851: $args->{'curl'},
16852: $args->{'course_home'},
16853: $args->{'nonstandard'},
16854: $args->{'crscode'},
16855: $args->{'ccuname'}.':'.
16856: $args->{'ccdomain'},
1.882 raeburn 16857: $args->{'crstype'},
1.1344 raeburn 16858: $cnum,$context,$category,
16859: $callercontext);
1.444 albertel 16860:
16861: # Note: The testing routines depend on this being output; see
16862: # Utils::Course. This needs to at least be output as a comment
16863: # if anyone ever decides to not show this, and Utils::Course::new
16864: # will need to be suitably modified.
1.1344 raeburn 16865: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16866: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16867: } else {
16868: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16869: }
1.943 raeburn 16870: if ($$courseid =~ /^error:/) {
1.1344 raeburn 16871: return (0,$outcome,$clonemsgref);
1.943 raeburn 16872: }
16873:
1.444 albertel 16874: #
16875: # Check if created correctly
16876: #
1.479 albertel 16877: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16878: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16879: if ($crsuhome eq 'no_host') {
1.1344 raeburn 16880: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16881: $outcome .= &mt_user($user_lh,
16882: 'Course creation failed, unrecognized course home server.');
16883: } else {
16884: $outcome .= &mt('Course creation failed, unrecognized course home server.');
16885: }
16886: $outcome .= $linefeed;
16887: return (0,$outcome,$clonemsgref);
1.943 raeburn 16888: }
1.541 raeburn 16889: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16890:
1.444 albertel 16891: #
1.566 albertel 16892: # Do the cloning
16893: #
1.1344 raeburn 16894: my @clonemsg;
1.566 albertel 16895: if ($can_clone && $cloneid) {
1.1344 raeburn 16896: push(@clonemsg,
16897: {
16898: mt => 'Created [_1] by cloning from [_2]',
16899: args => [$showncrstype,$clonetitle],
16900: });
1.566 albertel 16901: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16902: # Copy all files
1.1344 raeburn 16903: my @info =
16904: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16905: $args->{'dateshift'},$args->{'crscode'},
16906: $args->{'ccuname'}.':'.$args->{'ccdomain'},
16907: $args->{'tinyurls'});
16908: if (@info) {
16909: push(@clonemsg,@info);
16910: }
1.444 albertel 16911: # Restore URL
1.566 albertel 16912: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16913: # Restore title
1.566 albertel 16914: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16915: # Restore creation date, creator and creation context.
16916: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16917: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16918: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16919: # Mark as cloned
1.566 albertel 16920: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16921: # Need to clone grading mode
16922: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16923: $cenv{'grading'}=$newenv{'grading'};
16924: # Do not clone these environment entries
16925: &Apache::lonnet::del('environment',
16926: ['default_enrollment_start_date',
16927: 'default_enrollment_end_date',
16928: 'question.email',
16929: 'policy.email',
16930: 'comment.email',
16931: 'pch.users.denied',
1.725 raeburn 16932: 'plc.users.denied',
16933: 'hidefromcat',
1.1121 raeburn 16934: 'checkforpriv',
1.1355 raeburn 16935: 'categories'],
1.638 www 16936: $$crsudom,$$crsunum);
1.1170 raeburn 16937: if ($args->{'textbook'}) {
16938: $cenv{'internal.textbook'} = $args->{'textbook'};
16939: }
1.444 albertel 16940: }
1.566 albertel 16941:
1.444 albertel 16942: #
16943: # Set environment (will override cloned, if existing)
16944: #
16945: my @sections = ();
16946: my @xlists = ();
16947: if ($args->{'crstype'}) {
16948: $cenv{'type'}=$args->{'crstype'};
16949: }
1.1371 raeburn 16950: if ($args->{'lti'}) {
16951: $cenv{'internal.lti'}=$args->{'lti'};
16952: }
1.444 albertel 16953: if ($args->{'crsid'}) {
16954: $cenv{'courseid'}=$args->{'crsid'};
16955: }
16956: if ($args->{'crscode'}) {
16957: $cenv{'internal.coursecode'}=$args->{'crscode'};
16958: }
16959: if ($args->{'crsquota'} ne '') {
16960: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16961: } else {
16962: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16963: }
16964: if ($args->{'ccuname'}) {
16965: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16966: ':'.$args->{'ccdomain'};
16967: } else {
16968: $cenv{'internal.courseowner'} = $args->{'curruser'};
16969: }
1.1116 raeburn 16970: if ($args->{'defaultcredits'}) {
16971: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16972: }
1.444 albertel 16973: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16974: if ($args->{'crssections'}) {
16975: $cenv{'internal.sectionnums'} = '';
16976: if ($args->{'crssections'} =~ m/,/) {
16977: @sections = split/,/,$args->{'crssections'};
16978: } else {
16979: $sections[0] = $args->{'crssections'};
16980: }
16981: if (@sections > 0) {
16982: foreach my $item (@sections) {
16983: my ($sec,$gp) = split/:/,$item;
16984: my $class = $args->{'crscode'}.$sec;
16985: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16986: $cenv{'internal.sectionnums'} .= $item.',';
16987: unless ($addcheck eq 'ok') {
1.1263 raeburn 16988: push(@badclasses,$class);
1.444 albertel 16989: }
16990: }
16991: $cenv{'internal.sectionnums'} =~ s/,$//;
16992: }
16993: }
16994: # do not hide course coordinator from staff listing,
16995: # even if privileged
16996: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16997: # add course coordinator's domain to domains to check for privileged users
16998: # if different to course domain
16999: if ($$crsudom ne $args->{'ccdomain'}) {
17000: $cenv{'checkforpriv'} = $args->{'ccdomain'};
17001: }
1.444 albertel 17002: # add crosslistings
17003: if ($args->{'crsxlist'}) {
17004: $cenv{'internal.crosslistings'}='';
17005: if ($args->{'crsxlist'} =~ m/,/) {
17006: @xlists = split/,/,$args->{'crsxlist'};
17007: } else {
17008: $xlists[0] = $args->{'crsxlist'};
17009: }
17010: if (@xlists > 0) {
17011: foreach my $item (@xlists) {
17012: my ($xl,$gp) = split/:/,$item;
17013: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
17014: $cenv{'internal.crosslistings'} .= $item.',';
17015: unless ($addcheck eq 'ok') {
1.1263 raeburn 17016: push(@badclasses,$xl);
1.444 albertel 17017: }
17018: }
17019: $cenv{'internal.crosslistings'} =~ s/,$//;
17020: }
17021: }
17022: if ($args->{'autoadds'}) {
17023: $cenv{'internal.autoadds'}=$args->{'autoadds'};
17024: }
17025: if ($args->{'autodrops'}) {
17026: $cenv{'internal.autodrops'}=$args->{'autodrops'};
17027: }
17028: # check for notification of enrollment changes
17029: my @notified = ();
17030: if ($args->{'notify_owner'}) {
17031: if ($args->{'ccuname'} ne '') {
17032: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
17033: }
17034: }
17035: if ($args->{'notify_dc'}) {
17036: if ($uname ne '') {
1.630 raeburn 17037: push(@notified,$uname.':'.$udom);
1.444 albertel 17038: }
17039: }
17040: if (@notified > 0) {
17041: my $notifylist;
17042: if (@notified > 1) {
17043: $notifylist = join(',',@notified);
17044: } else {
17045: $notifylist = $notified[0];
17046: }
17047: $cenv{'internal.notifylist'} = $notifylist;
17048: }
17049: if (@badclasses > 0) {
17050: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 17051: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
17052: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
17053: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 17054: );
1.1264 raeburn 17055: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
17056: &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 17057: if ($context eq 'auto') {
17058: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 17059: } else {
1.566 albertel 17060: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 17061: }
17062: foreach my $item (@badclasses) {
1.541 raeburn 17063: if ($context eq 'auto') {
1.1261 raeburn 17064: $outcome .= " - $item\n";
1.541 raeburn 17065: } else {
1.1261 raeburn 17066: $outcome .= "<li>$item</li>\n";
1.541 raeburn 17067: }
1.1261 raeburn 17068: }
17069: if ($context eq 'auto') {
17070: $outcome .= $linefeed;
17071: } else {
17072: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 17073: }
1.444 albertel 17074: }
17075: if ($args->{'no_end_date'}) {
17076: $args->{'endaccess'} = 0;
17077: }
17078: $cenv{'internal.autostart'}=$args->{'enrollstart'};
17079: $cenv{'internal.autoend'}=$args->{'enrollend'};
17080: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
17081: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
17082: if ($args->{'showphotos'}) {
17083: $cenv{'internal.showphotos'}=$args->{'showphotos'};
17084: }
17085: $cenv{'internal.authtype'} = $args->{'authtype'};
17086: $cenv{'internal.autharg'} = $args->{'autharg'};
17087: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
17088: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 17089: 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');
17090: if ($context eq 'auto') {
17091: $outcome .= $krb_msg;
17092: } else {
1.566 albertel 17093: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 17094: }
17095: $outcome .= $linefeed;
1.444 albertel 17096: }
17097: }
17098: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
17099: if ($args->{'setpolicy'}) {
17100: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17101: }
17102: if ($args->{'setcontent'}) {
17103: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17104: }
1.1251 raeburn 17105: if ($args->{'setcomment'}) {
17106: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17107: }
1.444 albertel 17108: }
17109: if ($args->{'reshome'}) {
17110: $cenv{'reshome'}=$args->{'reshome'}.'/';
17111: $cenv{'reshome'}=~s/\/+$/\//;
17112: }
17113: #
17114: # course has keyed access
17115: #
17116: if ($args->{'setkeys'}) {
17117: $cenv{'keyaccess'}='yes';
17118: }
17119: # if specified, key authority is not course, but user
17120: # only active if keyaccess is yes
17121: if ($args->{'keyauth'}) {
1.487 albertel 17122: my ($user,$domain) = split(':',$args->{'keyauth'});
17123: $user = &LONCAPA::clean_username($user);
17124: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 17125: if ($user ne '' && $domain ne '') {
1.487 albertel 17126: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 17127: }
17128: }
17129:
1.1166 raeburn 17130: #
1.1167 raeburn 17131: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 17132: #
17133: if ($args->{'uniquecode'}) {
17134: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
17135: if ($code) {
17136: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 17137: my %crsinfo =
17138: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
17139: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
17140: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
17141: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
17142: }
1.1166 raeburn 17143: if (ref($coderef)) {
17144: $$coderef = $code;
17145: }
17146: }
17147: }
17148:
1.444 albertel 17149: if ($args->{'disresdis'}) {
17150: $cenv{'pch.roles.denied'}='st';
17151: }
17152: if ($args->{'disablechat'}) {
17153: $cenv{'plc.roles.denied'}='st';
17154: }
17155:
17156: # Record we've not yet viewed the Course Initialization Helper for this
17157: # course
17158: $cenv{'course.helper.not.run'} = 1;
17159: #
17160: # Use new Randomseed
17161: #
17162: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
17163: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
17164: #
17165: # The encryption code and receipt prefix for this course
17166: #
17167: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
17168: $cenv{'internal.encpref'}=100+int(9*rand(99));
17169: #
17170: # By default, use standard grading
17171: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
17172:
1.541 raeburn 17173: $outcome .= $linefeed.&mt('Setting environment').': '.
17174: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17175: #
17176: # Open all assignments
17177: #
17178: if ($args->{'openall'}) {
1.1341 raeburn 17179: my $opendate = time;
17180: if ($args->{'openallfrom'} =~ /^\d+$/) {
17181: $opendate = $args->{'openallfrom'};
17182: }
1.444 albertel 17183: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 17184: my %storecontent = ($storeunder => $opendate,
1.444 albertel 17185: $storeunder.'.type' => 'date_start');
1.1341 raeburn 17186: $outcome .= &mt('All assignments open starting [_1]',
17187: &Apache::lonlocal::locallocaltime($opendate)).': '.
17188: &Apache::lonnet::cput
17189: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17190: }
17191: #
17192: # Set first page
17193: #
17194: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
17195: || ($cloneid)) {
17196: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 17197:
17198: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
17199: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
17200:
1.444 albertel 17201: $outcome .= ($fatal?$errtext:'read ok').' - ';
17202: my $title; my $url;
17203: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 17204: $title=&mt('Syllabus');
1.444 albertel 17205: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
17206: } else {
1.963 raeburn 17207: $title=&mt('Table of Contents');
1.444 albertel 17208: $url='/adm/navmaps';
17209: }
1.445 albertel 17210:
17211: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
17212: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
17213:
17214: if ($errtext) { $fatal=2; }
1.541 raeburn 17215: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 17216: }
1.566 albertel 17217:
1.1237 raeburn 17218: #
17219: # Set params for Placement Tests
17220: #
1.1239 raeburn 17221: if ($args->{'crstype'} eq 'Placement') {
17222: my %storecontent;
17223: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
17224: my %defaults = (
17225: buttonshide => { value => 'yes',
17226: type => 'string_yesno',},
17227: type => { value => 'randomizetry',
17228: type => 'string_questiontype',},
17229: maxtries => { value => 1,
17230: type => 'int_pos',},
17231: problemstatus => { value => 'no',
17232: type => 'string_problemstatus',},
17233: );
17234: foreach my $key (keys(%defaults)) {
17235: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
17236: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
17237: }
1.1237 raeburn 17238: &Apache::lonnet::cput
17239: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
17240: }
17241:
1.1344 raeburn 17242: return (1,$outcome,\@clonemsg);
1.444 albertel 17243: }
17244:
1.1166 raeburn 17245: sub make_unique_code {
17246: my ($cdom,$cnum) = @_;
17247: # get lock on uniquecodes db
17248: my $lockhash = {
17249: $cnum."\0".'uniquecodes' => $env{'user.name'}.
17250: ':'.$env{'user.domain'},
17251: };
17252: my $tries = 0;
17253: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17254: my ($code,$error);
17255:
17256: while (($gotlock ne 'ok') && ($tries<3)) {
17257: $tries ++;
17258: sleep 1;
17259: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17260: }
17261: if ($gotlock eq 'ok') {
17262: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
17263: my $gotcode;
17264: my $attempts = 0;
17265: while ((!$gotcode) && ($attempts < 100)) {
17266: $code = &generate_code();
17267: if (!exists($currcodes{$code})) {
17268: $gotcode = 1;
17269: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
17270: $error = 'nostore';
17271: }
17272: }
17273: $attempts ++;
17274: }
17275: my @del_lock = ($cnum."\0".'uniquecodes');
17276: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
17277: } else {
17278: $error = 'nolock';
17279: }
17280: return ($code,$error);
17281: }
17282:
17283: sub generate_code {
17284: my $code;
17285: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
17286: for (my $i=0; $i<6; $i++) {
17287: my $lettnum = int (rand 2);
17288: my $item = '';
17289: if ($lettnum) {
17290: $item = $letts[int( rand(18) )];
17291: } else {
17292: $item = 1+int( rand(8) );
17293: }
17294: $code .= $item;
17295: }
17296: return $code;
17297: }
17298:
1.444 albertel 17299: ############################################################
17300: ############################################################
17301:
1.1237 raeburn 17302: # Community, Course and Placement Test
1.378 raeburn 17303: sub course_type {
17304: my ($cid) = @_;
17305: if (!defined($cid)) {
17306: $cid = $env{'request.course.id'};
17307: }
1.404 albertel 17308: if (defined($env{'course.'.$cid.'.type'})) {
17309: return $env{'course.'.$cid.'.type'};
1.378 raeburn 17310: } else {
17311: return 'Course';
1.377 raeburn 17312: }
17313: }
1.156 albertel 17314:
1.406 raeburn 17315: sub group_term {
17316: my $crstype = &course_type();
17317: my %names = (
17318: 'Course' => 'group',
1.865 raeburn 17319: 'Community' => 'group',
1.1237 raeburn 17320: 'Placement' => 'group',
1.406 raeburn 17321: );
17322: return $names{$crstype};
17323: }
17324:
1.902 raeburn 17325: sub course_types {
1.1310 raeburn 17326: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 17327: my %typename = (
17328: official => 'Official course',
17329: unofficial => 'Unofficial course',
17330: community => 'Community',
1.1165 raeburn 17331: textbook => 'Textbook course',
1.1237 raeburn 17332: placement => 'Placement test',
1.1310 raeburn 17333: lti => 'LTI provider',
1.902 raeburn 17334: );
17335: return (\@types,\%typename);
17336: }
17337:
1.156 albertel 17338: sub icon {
17339: my ($file)=@_;
1.505 albertel 17340: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 17341: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 17342: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 17343: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
17344: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
17345: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17346: $curfext.".gif") {
17347: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17348: $curfext.".gif";
17349: }
17350: }
1.249 albertel 17351: return &lonhttpdurl($iconname);
1.154 albertel 17352: }
1.84 albertel 17353:
1.575 albertel 17354: sub lonhttpdurl {
1.692 www 17355: #
17356: # Had been used for "small fry" static images on separate port 8080.
17357: # Modify here if lightweight http functionality desired again.
17358: # Currently eliminated due to increasing firewall issues.
17359: #
1.575 albertel 17360: my ($url)=@_;
1.692 www 17361: return $url;
1.215 albertel 17362: }
17363:
1.213 albertel 17364: sub connection_aborted {
17365: my ($r)=@_;
17366: $r->print(" ");$r->rflush();
17367: my $c = $r->connection;
17368: return $c->aborted();
17369: }
17370:
1.221 foxr 17371: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 17372: # strings as 'strings'.
17373: sub escape_single {
1.221 foxr 17374: my ($input) = @_;
1.223 albertel 17375: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 17376: $input =~ s/\'/\\\'/g; # Esacpe the 's....
17377: return $input;
17378: }
1.223 albertel 17379:
1.222 foxr 17380: # Same as escape_single, but escape's "'s This
17381: # can be used for "strings"
17382: sub escape_double {
17383: my ($input) = @_;
17384: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
17385: $input =~ s/\"/\\\"/g; # Esacpe the "s....
17386: return $input;
17387: }
1.223 albertel 17388:
1.222 foxr 17389: # Escapes the last element of a full URL.
17390: sub escape_url {
17391: my ($url) = @_;
1.238 raeburn 17392: my @urlslices = split(/\//, $url,-1);
1.369 www 17393: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 17394: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 17395: }
1.462 albertel 17396:
1.820 raeburn 17397: sub compare_arrays {
17398: my ($arrayref1,$arrayref2) = @_;
17399: my (@difference,%count);
17400: @difference = ();
17401: %count = ();
17402: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
17403: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
17404: foreach my $element (keys(%count)) {
17405: if ($count{$element} == 1) {
17406: push(@difference,$element);
17407: }
17408: }
17409: }
17410: return @difference;
17411: }
17412:
1.1322 raeburn 17413: sub lon_status_items {
17414: my %defaults = (
17415: E => 100,
17416: W => 4,
17417: N => 1,
1.1324 raeburn 17418: U => 5,
1.1322 raeburn 17419: threshold => 200,
17420: sysmail => 2500,
17421: );
17422: my %names = (
17423: E => 'Errors',
17424: W => 'Warnings',
17425: N => 'Notices',
1.1324 raeburn 17426: U => 'Unsent',
1.1322 raeburn 17427: );
17428: return (\%defaults,\%names);
17429: }
17430:
1.817 bisitz 17431: # -------------------------------------------------------- Initialize user login
1.462 albertel 17432: sub init_user_environment {
1.463 albertel 17433: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 17434: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
17435:
17436: my $public=($username eq 'public' && $domain eq 'public');
17437:
1.1062 raeburn 17438: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 17439: my $now=time;
17440:
17441: if ($public) {
17442: my $max_public=100;
17443: my $oldest;
17444: my $oldest_time=0;
17445: for(my $next=1;$next<=$max_public;$next++) {
17446: if (-e $lonids."/publicuser_$next.id") {
17447: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
17448: if ($mtime<$oldest_time || !$oldest_time) {
17449: $oldest_time=$mtime;
17450: $oldest=$next;
17451: }
17452: } else {
17453: $cookie="publicuser_$next";
17454: last;
17455: }
17456: }
17457: if (!$cookie) { $cookie="publicuser_$oldest"; }
17458: } else {
1.1275 raeburn 17459: # See if old ID present, if so, remove if this isn't a robot,
17460: # killing any existing non-robot sessions
1.463 albertel 17461: if (!$args->{'robot'}) {
17462: opendir(DIR,$lonids);
17463: while ($filename=readdir(DIR)) {
17464: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 17465: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
17466: &GDBM_READER(),0640)) {
1.1295 raeburn 17467: my $linkedfile;
1.1320 raeburn 17468: if (exists($oldenv{'user.linkedenv'})) {
17469: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 17470: }
1.1320 raeburn 17471: untie(%oldenv);
17472: if (unlink("$lonids/$filename")) {
17473: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
17474: if (-l "$lonids/$linkedfile.id") {
17475: unlink("$lonids/$linkedfile.id");
17476: }
1.1295 raeburn 17477: }
17478: }
17479: } else {
17480: unlink($lonids.'/'.$filename);
17481: }
1.463 albertel 17482: }
1.462 albertel 17483: }
1.463 albertel 17484: closedir(DIR);
1.1204 raeburn 17485: # If there is a undeleted lockfile for the user's paste buffer remove it.
17486: my $namespace = 'nohist_courseeditor';
17487: my $lockingkey = 'paste'."\0".'locked_num';
17488: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
17489: $domain,$username);
17490: if (exists($lockhash{$lockingkey})) {
17491: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
17492: unless ($delresult eq 'ok') {
17493: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
17494: }
17495: }
1.462 albertel 17496: }
17497: # Give them a new cookie
1.463 albertel 17498: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 17499: : $now.$$.int(rand(10000)));
1.463 albertel 17500: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 17501:
17502: # Initialize roles
17503:
1.1062 raeburn 17504: ($userroles,$firstaccenv,$timerintenv) =
17505: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 17506: }
17507: # ------------------------------------ Check browser type and MathML capability
17508:
1.1194 raeburn 17509: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
17510: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 17511:
17512: # ------------------------------------------------------------- Get environment
17513:
17514: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
17515: my ($tmp) = keys(%userenv);
1.1275 raeburn 17516: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 17517: undef(%userenv);
17518: }
17519: if (($userenv{'interface'}) && (!$form->{'interface'})) {
17520: $form->{'interface'}=$userenv{'interface'};
17521: }
17522: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
17523:
17524: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 17525: foreach my $option ('interface','localpath','localres') {
17526: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 17527: }
17528: # --------------------------------------------------------- Write first profile
17529:
17530: {
1.1350 raeburn 17531: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 17532: my %initial_env =
17533: ("user.name" => $username,
17534: "user.domain" => $domain,
17535: "user.home" => $authhost,
17536: "browser.type" => $clientbrowser,
17537: "browser.version" => $clientversion,
17538: "browser.mathml" => $clientmathml,
17539: "browser.unicode" => $clientunicode,
17540: "browser.os" => $clientos,
1.1137 raeburn 17541: "browser.mobile" => $clientmobile,
1.1141 raeburn 17542: "browser.info" => $clientinfo,
1.1194 raeburn 17543: "browser.osversion" => $clientosversion,
1.462 albertel 17544: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
17545: "request.course.fn" => '',
17546: "request.course.uri" => '',
17547: "request.course.sec" => '',
17548: "request.role" => 'cm',
17549: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 17550: "request.host" => $ip,);
1.462 albertel 17551:
17552: if ($form->{'localpath'}) {
17553: $initial_env{"browser.localpath"} = $form->{'localpath'};
17554: $initial_env{"browser.localres"} = $form->{'localres'};
17555: }
17556:
17557: if ($form->{'interface'}) {
17558: $form->{'interface'}=~s/\W//gs;
17559: $initial_env{"browser.interface"} = $form->{'interface'};
17560: $env{'browser.interface'}=$form->{'interface'};
17561: }
17562:
1.1157 raeburn 17563: if ($form->{'iptoken'}) {
17564: my $lonhost = $r->dir_config('lonHostID');
17565: $initial_env{"user.noloadbalance"} = $lonhost;
17566: $env{'user.noloadbalance'} = $lonhost;
17567: }
17568:
1.1268 raeburn 17569: if ($form->{'noloadbalance'}) {
17570: my @hosts = &Apache::lonnet::current_machine_ids();
17571: my $hosthere = $form->{'noloadbalance'};
17572: if (grep(/^\Q$hosthere\E$/,@hosts)) {
17573: $initial_env{"user.noloadbalance"} = $hosthere;
17574: $env{'user.noloadbalance'} = $hosthere;
17575: }
17576: }
17577:
1.1016 raeburn 17578: unless ($domain eq 'public') {
1.1273 raeburn 17579: my %is_adv = ( is_adv => $env{'user.adv'} );
17580: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
17581:
1.1387 raeburn 17582: foreach my $tool ('aboutme','blog','webdav','portfolio','timezone') {
1.1273 raeburn 17583: $userenv{'availabletools.'.$tool} =
17584: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
17585: undef,\%userenv,\%domdef,\%is_adv);
17586: }
1.980 raeburn 17587:
1.1311 raeburn 17588: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 17589: $userenv{'canrequest.'.$crstype} =
17590: &Apache::lonnet::usertools_access($username,$domain,$crstype,
17591: 'reload','requestcourses',
17592: \%userenv,\%domdef,\%is_adv);
17593: }
1.724 raeburn 17594:
1.1273 raeburn 17595: $userenv{'canrequest.author'} =
17596: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
17597: 'reload','requestauthor',
1.980 raeburn 17598: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 17599: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
17600: $domain,$username);
17601: my $reqstatus = $reqauthor{'author_status'};
17602: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
17603: if (ref($reqauthor{'author'}) eq 'HASH') {
17604: $userenv{'requestauthorqueued'} = $reqstatus.':'.
17605: $reqauthor{'author'}{'timestamp'};
17606: }
1.1092 raeburn 17607: }
1.1287 raeburn 17608: my ($types,$typename) = &course_types();
17609: if (ref($types) eq 'ARRAY') {
17610: my @options = ('approval','validate','autolimit');
17611: my $optregex = join('|',@options);
17612: my (%willtrust,%trustchecked);
17613: foreach my $type (@{$types}) {
17614: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
17615: if ($dom_str ne '') {
17616: my $updatedstr = '';
17617: my @possdomains = split(',',$dom_str);
17618: foreach my $entry (@possdomains) {
17619: my ($extdom,$extopt) = split(':',$entry);
17620: unless ($trustchecked{$extdom}) {
17621: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
17622: $trustchecked{$extdom} = 1;
17623: }
17624: if ($willtrust{$extdom}) {
17625: $updatedstr .= $entry.',';
17626: }
17627: }
17628: $updatedstr =~ s/,$//;
17629: if ($updatedstr) {
17630: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
17631: } else {
17632: delete($userenv{'reqcrsotherdom.'.$type});
17633: }
17634: }
17635: }
17636: }
1.1092 raeburn 17637: }
1.462 albertel 17638: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 17639:
1.462 albertel 17640: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
17641: &GDBM_WRCREAT(),0640)) {
17642: &_add_to_env(\%disk_env,\%initial_env);
17643: &_add_to_env(\%disk_env,\%userenv,'environment.');
17644: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 17645: if (ref($firstaccenv) eq 'HASH') {
17646: &_add_to_env(\%disk_env,$firstaccenv);
17647: }
17648: if (ref($timerintenv) eq 'HASH') {
17649: &_add_to_env(\%disk_env,$timerintenv);
17650: }
1.463 albertel 17651: if (ref($args->{'extra_env'})) {
17652: &_add_to_env(\%disk_env,$args->{'extra_env'});
17653: }
1.462 albertel 17654: untie(%disk_env);
17655: } else {
1.705 tempelho 17656: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
17657: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 17658: return 'error: '.$!;
17659: }
17660: }
17661: $env{'request.role'}='cm';
17662: $env{'request.role.adv'}=$env{'user.adv'};
17663: $env{'browser.type'}=$clientbrowser;
17664:
17665: return $cookie;
17666:
17667: }
17668:
17669: sub _add_to_env {
17670: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 17671: if (ref($env_data) eq 'HASH') {
17672: while (my ($key,$value) = each(%$env_data)) {
17673: $idf->{$prefix.$key} = $value;
17674: $env{$prefix.$key} = $value;
17675: }
1.462 albertel 17676: }
17677: }
17678:
1.685 tempelho 17679: # --- Get the symbolic name of a problem and the url
17680: sub get_symb {
17681: my ($request,$silent) = @_;
1.726 raeburn 17682: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 17683: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
17684: if ($symb eq '') {
17685: if (!$silent) {
1.1071 raeburn 17686: if (ref($request)) {
17687: $request->print("Unable to handle ambiguous references:$url:.");
17688: }
1.685 tempelho 17689: return ();
17690: }
17691: }
17692: &Apache::lonenc::check_decrypt(\$symb);
17693: return ($symb);
17694: }
17695:
17696: # --------------------------------------------------------------Get annotation
17697:
17698: sub get_annotation {
17699: my ($symb,$enc) = @_;
17700:
17701: my $key = $symb;
17702: if (!$enc) {
17703: $key =
17704: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
17705: }
17706: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
17707: return $annotation{$key};
17708: }
17709:
17710: sub clean_symb {
1.731 raeburn 17711: my ($symb,$delete_enc) = @_;
1.685 tempelho 17712:
17713: &Apache::lonenc::check_decrypt(\$symb);
17714: my $enc = $env{'request.enc'};
1.731 raeburn 17715: if ($delete_enc) {
1.730 raeburn 17716: delete($env{'request.enc'});
17717: }
1.685 tempelho 17718:
17719: return ($symb,$enc);
17720: }
1.462 albertel 17721:
1.1181 raeburn 17722: ############################################################
17723: ############################################################
17724:
17725: =pod
17726:
17727: =head1 Routines for building display used to search for courses
17728:
17729:
17730: =over 4
17731:
17732: =item * &build_filters()
17733:
17734: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 17735: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17736: and quotacheck.pl
17737:
1.1181 raeburn 17738:
17739: Inputs:
17740:
17741: filterlist - anonymous array of fields to include as potential filters
17742:
17743: crstype - course type
17744:
17745: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17746: to pop-open a course selector (will contain "extra element").
17747:
17748: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17749:
17750: filter - anonymous hash of criteria and their values
17751:
17752: action - form action
17753:
17754: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17755:
1.1182 raeburn 17756: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 17757:
17758: cloneruname - username of owner of new course who wants to clone
17759:
17760: clonerudom - domain of owner of new course who wants to clone
17761:
17762: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17763:
17764: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17765:
17766: codedom - domain
17767:
17768: formname - value of form element named "form".
17769:
17770: fixeddom - domain, if fixed.
17771:
17772: prevphase - value to assign to form element named "phase" when going back to the previous screen
17773:
17774: cnameelement - name of form element in form on opener page which will receive title of selected course
17775:
17776: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17777:
17778: cdomelement - name of form element in form on opener page which will receive domain of selected course
17779:
17780: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17781:
17782: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17783:
17784: clonewarning - warning message about missing information for intended course owner when DC creates a course
17785:
1.1182 raeburn 17786:
1.1181 raeburn 17787: Returns: $output - HTML for display of search criteria, and hidden form elements.
17788:
1.1182 raeburn 17789:
1.1181 raeburn 17790: Side Effects: None
17791:
17792: =cut
17793:
17794: # ---------------------------------------------- search for courses based on last activity etc.
17795:
17796: sub build_filters {
17797: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17798: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17799: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17800: $cnameelement,$cnumelement,$cdomelement,$setroles,
17801: $clonetext,$clonewarning) = @_;
1.1182 raeburn 17802: my ($list,$jscript);
1.1181 raeburn 17803: my $onchange = 'javascript:updateFilters(this)';
17804: my ($domainselectform,$sincefilterform,$createdfilterform,
17805: $ownerdomselectform,$persondomselectform,$instcodeform,
17806: $typeselectform,$instcodetitle);
17807: if ($formname eq '') {
17808: $formname = $caller;
17809: }
17810: foreach my $item (@{$filterlist}) {
17811: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17812: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17813: if ($item eq 'domainfilter') {
17814: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17815: } elsif ($item eq 'coursefilter') {
17816: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17817: } elsif ($item eq 'ownerfilter') {
17818: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17819: } elsif ($item eq 'ownerdomfilter') {
17820: $filter->{'ownerdomfilter'} =
17821: &LONCAPA::clean_domain($filter->{$item});
17822: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17823: 'ownerdomfilter',1);
17824: } elsif ($item eq 'personfilter') {
17825: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17826: } elsif ($item eq 'persondomfilter') {
17827: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17828: 'persondomfilter',1);
17829: } else {
17830: $filter->{$item} =~ s/\W//g;
17831: }
17832: if (!$filter->{$item}) {
17833: $filter->{$item} = '';
17834: }
17835: }
17836: if ($item eq 'domainfilter') {
17837: my $allow_blank = 1;
17838: if ($formname eq 'portform') {
17839: $allow_blank=0;
17840: } elsif ($formname eq 'studentform') {
17841: $allow_blank=0;
17842: }
17843: if ($fixeddom) {
17844: $domainselectform = '<input type="hidden" name="domainfilter"'.
17845: ' value="'.$codedom.'" />'.
17846: &Apache::lonnet::domain($codedom,'description');
17847: } else {
17848: $domainselectform = &select_dom_form($filter->{$item},
17849: 'domainfilter',
17850: $allow_blank,'',$onchange);
17851: }
17852: } else {
17853: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17854: }
17855: }
17856:
17857: # last course activity filter and selection
17858: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17859:
17860: # course created filter and selection
17861: if (exists($filter->{'createdfilter'})) {
17862: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17863: }
17864:
1.1239 raeburn 17865: my $prefix = $crstype;
17866: if ($crstype eq 'Placement') {
17867: $prefix = 'Placement Test'
17868: }
1.1181 raeburn 17869: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 17870: 'cac' => "$prefix Activity",
17871: 'ccr' => "$prefix Created",
17872: 'cde' => "$prefix Title",
17873: 'cdo' => "$prefix Domain",
1.1181 raeburn 17874: 'ins' => 'Institutional Code',
17875: 'inc' => 'Institutional Categorization',
1.1239 raeburn 17876: 'cow' => "$prefix Owner/Co-owner",
17877: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 17878: 'cog' => 'Type',
17879: );
17880:
17881: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17882: my $typeval = 'Course';
17883: if ($crstype eq 'Community') {
17884: $typeval = 'Community';
1.1239 raeburn 17885: } elsif ($crstype eq 'Placement') {
17886: $typeval = 'Placement';
1.1181 raeburn 17887: }
17888: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17889: } else {
17890: $typeselectform = '<select name="type" size="1"';
17891: if ($onchange) {
17892: $typeselectform .= ' onchange="'.$onchange.'"';
17893: }
17894: $typeselectform .= '>'."\n";
1.1237 raeburn 17895: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 17896: my $shown;
17897: if ($posstype eq 'Placement') {
17898: $shown = &mt('Placement Test');
17899: } else {
17900: $shown = &mt($posstype);
17901: }
1.1181 raeburn 17902: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 17903: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 17904: }
17905: $typeselectform.="</select>";
17906: }
17907:
17908: my ($cloneableonlyform,$cloneabletitle);
17909: if (exists($filter->{'cloneableonly'})) {
17910: my $cloneableon = '';
17911: my $cloneableoff = ' checked="checked"';
17912: if ($filter->{'cloneableonly'}) {
17913: $cloneableon = $cloneableoff;
17914: $cloneableoff = '';
17915: }
17916: $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>';
17917: if ($formname eq 'ccrs') {
1.1187 bisitz 17918: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17919: } else {
17920: $cloneabletitle = &mt('Cloneable by you');
17921: }
17922: }
17923: my $officialjs;
17924: if ($crstype eq 'Course') {
17925: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17926: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17927: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17928: if ($codedom) {
1.1181 raeburn 17929: $officialjs = 1;
17930: ($instcodeform,$jscript,$$numtitlesref) =
17931: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17932: $officialjs,$codetitlesref);
17933: if ($jscript) {
1.1182 raeburn 17934: $jscript = '<script type="text/javascript">'."\n".
17935: '// <![CDATA['."\n".
17936: $jscript."\n".
17937: '// ]]>'."\n".
17938: '</script>'."\n";
1.1181 raeburn 17939: }
17940: }
17941: if ($instcodeform eq '') {
17942: $instcodeform =
17943: '<input type="text" name="instcodefilter" size="10" value="'.
17944: $list->{'instcodefilter'}.'" />';
17945: $instcodetitle = $lt{'ins'};
17946: } else {
17947: $instcodetitle = $lt{'inc'};
17948: }
17949: if ($fixeddom) {
17950: $instcodetitle .= '<br />('.$codedom.')';
17951: }
17952: }
17953: }
17954: my $output = qq|
17955: <form method="post" name="filterpicker" action="$action">
17956: <input type="hidden" name="form" value="$formname" />
17957: |;
17958: if ($formname eq 'modifycourse') {
17959: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17960: '<input type="hidden" name="prevphase" value="'.
17961: $prevphase.'" />'."\n";
1.1198 musolffc 17962: } elsif ($formname eq 'quotacheck') {
17963: $output .= qq|
17964: <input type="hidden" name="sortby" value="" />
17965: <input type="hidden" name="sortorder" value="" />
17966: |;
17967: } else {
1.1181 raeburn 17968: my $name_input;
17969: if ($cnameelement ne '') {
17970: $name_input = '<input type="hidden" name="cnameelement" value="'.
17971: $cnameelement.'" />';
17972: }
17973: $output .= qq|
1.1182 raeburn 17974: <input type="hidden" name="cnumelement" value="$cnumelement" />
17975: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 17976: $name_input
17977: $roleelement
17978: $multelement
17979: $typeelement
17980: |;
17981: if ($formname eq 'portform') {
17982: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17983: }
17984: }
17985: if ($fixeddom) {
17986: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17987: }
17988: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17989: if ($sincefilterform) {
17990: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17991: .$sincefilterform
17992: .&Apache::lonhtmlcommon::row_closure();
17993: }
17994: if ($createdfilterform) {
17995: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17996: .$createdfilterform
17997: .&Apache::lonhtmlcommon::row_closure();
17998: }
17999: if ($domainselectform) {
18000: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
18001: .$domainselectform
18002: .&Apache::lonhtmlcommon::row_closure();
18003: }
18004: if ($typeselectform) {
18005: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
18006: $output .= $typeselectform;
18007: } else {
18008: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
18009: .$typeselectform
18010: .&Apache::lonhtmlcommon::row_closure();
18011: }
18012: }
18013: if ($instcodeform) {
18014: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
18015: .$instcodeform
18016: .&Apache::lonhtmlcommon::row_closure();
18017: }
18018: if (exists($filter->{'ownerfilter'})) {
18019: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
18020: '<table><tr><td>'.&mt('Username').'<br />'.
18021: '<input type="text" name="ownerfilter" size="20" value="'.
18022: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18023: $ownerdomselectform.'</td></tr></table>'.
18024: &Apache::lonhtmlcommon::row_closure();
18025: }
18026: if (exists($filter->{'personfilter'})) {
18027: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
18028: '<table><tr><td>'.&mt('Username').'<br />'.
18029: '<input type="text" name="personfilter" size="20" value="'.
18030: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18031: $persondomselectform.'</td></tr></table>'.
18032: &Apache::lonhtmlcommon::row_closure();
18033: }
18034: if (exists($filter->{'coursefilter'})) {
18035: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
18036: .'<input type="text" name="coursefilter" size="25" value="'
18037: .$list->{'coursefilter'}.'" />'
18038: .&Apache::lonhtmlcommon::row_closure();
18039: }
18040: if ($cloneableonlyform) {
18041: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
18042: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
18043: }
18044: if (exists($filter->{'descriptfilter'})) {
18045: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
18046: .'<input type="text" name="descriptfilter" size="40" value="'
18047: .$list->{'descriptfilter'}.'" />'
18048: .&Apache::lonhtmlcommon::row_closure(1);
18049: }
18050: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
18051: '<input type="hidden" name="updater" value="" />'."\n".
18052: '<input type="submit" name="gosearch" value="'.
18053: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
18054: return $jscript.$clonewarning.$output;
18055: }
18056:
18057: =pod
18058:
18059: =item * &timebased_select_form()
18060:
1.1182 raeburn 18061: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 18062: filter e.g., Course Activity, Course Created, when searching for courses
18063: or communities
18064:
18065: Inputs:
18066:
18067: item - name of form element (sincefilter or createdfilter)
18068:
18069: filter - anonymous hash of criteria and their values
18070:
18071: Returns: HTML for a select box contained a blank, then six time selections,
18072: with value set in incoming form variables currently selected.
18073:
18074: Side Effects: None
18075:
18076: =cut
18077:
18078: sub timebased_select_form {
18079: my ($item,$filter) = @_;
18080: if (ref($filter) eq 'HASH') {
18081: $filter->{$item} =~ s/[^\d-]//g;
18082: if (!$filter->{$item}) { $filter->{$item}=-1; }
18083: return &select_form(
18084: $filter->{$item},
18085: $item,
18086: { '-1' => '',
18087: '86400' => &mt('today'),
18088: '604800' => &mt('last week'),
18089: '2592000' => &mt('last month'),
18090: '7776000' => &mt('last three months'),
18091: '15552000' => &mt('last six months'),
18092: '31104000' => &mt('last year'),
18093: 'select_form_order' =>
18094: ['-1','86400','604800','2592000','7776000',
18095: '15552000','31104000']});
18096: }
18097: }
18098:
18099: =pod
18100:
18101: =item * &js_changer()
18102:
18103: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 18104: when course type or domain is changed, and also to hide 'Searching ...' on
18105: page load completion for page showing search result.
1.1181 raeburn 18106:
18107: Inputs: None
18108:
1.1183 raeburn 18109: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 18110:
18111: Side Effects: None
18112:
18113: =cut
18114:
18115: sub js_changer {
18116: return <<ENDJS;
18117: <script type="text/javascript">
18118: // <![CDATA[
18119: function updateFilters(caller) {
18120: if (typeof(caller) != "undefined") {
18121: document.filterpicker.updater.value = caller.name;
18122: }
18123: document.filterpicker.submit();
18124: }
1.1183 raeburn 18125:
18126: function hideSearching() {
18127: if (document.getElementById('searching')) {
18128: document.getElementById('searching').style.display = 'none';
18129: }
18130: return;
18131: }
18132:
1.1181 raeburn 18133: // ]]>
18134: </script>
18135:
18136: ENDJS
18137: }
18138:
18139: =pod
18140:
1.1182 raeburn 18141: =item * &search_courses()
18142:
18143: Process selected filters form course search form and pass to lonnet::courseiddump
18144: to retrieve a hash for which keys are courseIDs which match the selected filters.
18145:
18146: Inputs:
18147:
18148: dom - domain being searched
18149:
18150: type - course type ('Course' or 'Community' or '.' if any).
18151:
18152: filter - anonymous hash of criteria and their values
18153:
18154: numtitles - for institutional codes - number of categories
18155:
18156: cloneruname - optional username of new course owner
18157:
18158: clonerudom - optional domain of new course owner
18159:
1.1221 raeburn 18160: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 18161: (used when DC is using course creation form)
18162:
18163: codetitles - reference to array of titles of components in institutional codes (official courses).
18164:
1.1221 raeburn 18165: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
18166: (and so can clone automatically)
18167:
18168: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
18169:
18170: reqinstcode - institutional code of new course, where search_courses is used to identify potential
18171: courses to clone
1.1182 raeburn 18172:
18173: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
18174:
18175:
18176: Side Effects: None
18177:
18178: =cut
18179:
18180:
18181: sub search_courses {
1.1221 raeburn 18182: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
18183: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 18184: my (%courses,%showcourses,$cloner);
18185: if (($filter->{'ownerfilter'} ne '') ||
18186: ($filter->{'ownerdomfilter'} ne '')) {
18187: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
18188: $filter->{'ownerdomfilter'};
18189: }
18190: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
18191: if (!$filter->{$item}) {
18192: $filter->{$item}='.';
18193: }
18194: }
18195: my $now = time;
18196: my $timefilter =
18197: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
18198: my ($createdbefore,$createdafter);
18199: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
18200: $createdbefore = $now;
18201: $createdafter = $now-$filter->{'createdfilter'};
18202: }
18203: my ($instcodefilter,$regexpok);
18204: if ($numtitles) {
18205: if ($env{'form.official'} eq 'on') {
18206: $instcodefilter =
18207: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18208: $regexpok = 1;
18209: } elsif ($env{'form.official'} eq 'off') {
18210: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18211: unless ($instcodefilter eq '') {
18212: $regexpok = -1;
18213: }
18214: }
18215: } else {
18216: $instcodefilter = $filter->{'instcodefilter'};
18217: }
18218: if ($instcodefilter eq '') { $instcodefilter = '.'; }
18219: if ($type eq '') { $type = '.'; }
18220:
18221: if (($clonerudom ne '') && ($cloneruname ne '')) {
18222: $cloner = $cloneruname.':'.$clonerudom;
18223: }
18224: %courses = &Apache::lonnet::courseiddump($dom,
18225: $filter->{'descriptfilter'},
18226: $timefilter,
18227: $instcodefilter,
18228: $filter->{'combownerfilter'},
18229: $filter->{'coursefilter'},
18230: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 18231: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 18232: $filter->{'cloneableonly'},
18233: $createdbefore,$createdafter,undef,
1.1221 raeburn 18234: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 18235: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
18236: my $ccrole;
18237: if ($type eq 'Community') {
18238: $ccrole = 'co';
18239: } else {
18240: $ccrole = 'cc';
18241: }
18242: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
18243: $filter->{'persondomfilter'},
18244: 'userroles',undef,
18245: [$ccrole,'in','ad','ep','ta','cr'],
18246: $dom);
18247: foreach my $role (keys(%rolehash)) {
18248: my ($cnum,$cdom,$courserole) = split(':',$role);
18249: my $cid = $cdom.'_'.$cnum;
18250: if (exists($courses{$cid})) {
18251: if (ref($courses{$cid}) eq 'HASH') {
18252: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
18253: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 18254: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 18255: }
18256: } else {
18257: $courses{$cid}{roles} = [$courserole];
18258: }
18259: $showcourses{$cid} = $courses{$cid};
18260: }
18261: }
18262: }
18263: %courses = %showcourses;
18264: }
18265: return %courses;
18266: }
18267:
18268: =pod
18269:
1.1181 raeburn 18270: =back
18271:
1.1207 raeburn 18272: =head1 Routines for version requirements for current course.
18273:
18274: =over 4
18275:
18276: =item * &check_release_required()
18277:
18278: Compares required LON-CAPA version with version on server, and
18279: if required version is newer looks for a server with the required version.
18280:
18281: Looks first at servers in user's owen domain; if none suitable, looks at
18282: servers in course's domain are permitted to host sessions for user's domain.
18283:
18284: Inputs:
18285:
18286: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18287:
18288: $courseid - Course ID of current course
18289:
18290: $rolecode - User's current role in course (for switchserver query string).
18291:
18292: $required - LON-CAPA version needed by course (format: Major.Minor).
18293:
18294:
18295: Returns:
18296:
18297: $switchserver - query string tp append to /adm/switchserver call (if
18298: current server's LON-CAPA version is too old.
18299:
18300: $warning - Message is displayed if no suitable server could be found.
18301:
18302: =cut
18303:
18304: sub check_release_required {
18305: my ($loncaparev,$courseid,$rolecode,$required) = @_;
18306: my ($switchserver,$warning);
18307: if ($required ne '') {
18308: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
18309: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18310: if ($reqdmajor ne '' && $reqdminor ne '') {
18311: my $otherserver;
18312: if (($major eq '' && $minor eq '') ||
18313: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
18314: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
18315: my $switchlcrev =
18316: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
18317: $userdomserver);
18318: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18319: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
18320: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
18321: my $cdom = $env{'course.'.$courseid.'.domain'};
18322: if ($cdom ne $env{'user.domain'}) {
18323: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
18324: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
18325: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18326: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
18327: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
18328: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
18329: my $canhost =
18330: &Apache::lonnet::can_host_session($env{'user.domain'},
18331: $coursedomserver,
18332: $remoterev,
18333: $udomdefaults{'remotesessions'},
18334: $defdomdefaults{'hostedsessions'});
18335:
18336: if ($canhost) {
18337: $otherserver = $coursedomserver;
18338: } else {
18339: $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.");
18340: }
18341: } else {
18342: $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).");
18343: }
18344: } else {
18345: $otherserver = $userdomserver;
18346: }
18347: }
18348: if ($otherserver ne '') {
18349: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
18350: }
18351: }
18352: }
18353: return ($switchserver,$warning);
18354: }
18355:
18356: =pod
18357:
18358: =item * &check_release_result()
18359:
18360: Inputs:
18361:
18362: $switchwarning - Warning message if no suitable server found to host session.
18363:
18364: $switchserver - query string to append to /adm/switchserver containing lonHostID
18365: and current role.
18366:
18367: Returns: HTML to display with information about requirement to switch server.
18368: Either displaying warning with link to Roles/Courses screen or
18369: display link to switchserver.
18370:
1.1181 raeburn 18371: =cut
18372:
1.1207 raeburn 18373: sub check_release_result {
18374: my ($switchwarning,$switchserver) = @_;
18375: my $output = &start_page('Selected course unavailable on this server').
18376: '<p class="LC_warning">';
18377: if ($switchwarning) {
18378: $output .= $switchwarning.'<br /><a href="/adm/roles">';
18379: if (&show_course()) {
18380: $output .= &mt('Display courses');
18381: } else {
18382: $output .= &mt('Display roles');
18383: }
18384: $output .= '</a>';
18385: } elsif ($switchserver) {
18386: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
18387: '<br />'.
18388: '<a href="/adm/switchserver?'.$switchserver.'">'.
18389: &mt('Switch Server').
18390: '</a>';
18391: }
18392: $output .= '</p>'.&end_page();
18393: return $output;
18394: }
18395:
18396: =pod
18397:
18398: =item * &needs_coursereinit()
18399:
18400: Determine if course contents stored for user's session needs to be
18401: refreshed, because content has changed since "Big Hash" last tied.
18402:
18403: Check for change is made if time last checked is more than 10 minutes ago
18404: (by default).
18405:
18406: Inputs:
18407:
18408: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18409:
18410: $interval (optional) - Time which may elapse (in s) between last check for content
18411: change in current course. (default: 600 s).
18412:
18413: Returns: an array; first element is:
18414:
18415: =over 4
18416:
18417: 'switch' - if content updates mean user's session
18418: needs to be switched to a server running a newer LON-CAPA version
18419:
18420: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
18421: on current server hosting user's session
18422:
18423: '' - if no action required.
18424:
18425: =back
18426:
18427: If first item element is 'switch':
18428:
18429: second item is $switchwarning - Warning message if no suitable server found to host session.
18430:
18431: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
18432: and current role.
18433:
18434: otherwise: no other elements returned.
18435:
18436: =back
18437:
18438: =cut
18439:
18440: sub needs_coursereinit {
18441: my ($loncaparev,$interval) = @_;
18442: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
18443: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18444: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18445: my $now = time;
18446: if ($interval eq '') {
18447: $interval = 600;
18448: }
18449: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 18450: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1372 raeburn 18451: my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 18452: if ($blocked) {
18453: return ();
18454: }
1.1391 raeburn 18455: my $update;
18456: my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
18457: my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);
18458: if ($lastmainchange > $env{'request.course.tied'}) {
18459: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18460: if ($needswitch) {
18461: return ('switch',$switchwarning,$switchserver);
18462: }
18463: $update = 'main';
18464: }
18465: if ($lastsuppchange > $env{'request.course.suppupdated'}) {
18466: if ($update) {
18467: $update = 'both';
18468: } else {
18469: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18470: if ($needswitch) {
18471: return ('switch',$switchwarning,$switchserver);
18472: } else {
18473: $update = 'supp';
1.1207 raeburn 18474: }
18475: }
1.1391 raeburn 18476: return ($update);
18477: }
18478: }
18479: return ();
18480: }
18481:
18482: sub switch_for_update {
18483: my ($loncaparev,$cdom,$cnum) = @_;
18484: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18485: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
18486: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
18487: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
18488: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
18489: $curr_reqd_hash{'internal.releaserequired'}});
18490: my ($switchserver,$switchwarning) =
18491: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
18492: $curr_reqd_hash{'internal.releaserequired'});
18493: if ($switchwarning ne '' || $switchserver ne '') {
18494: return ('switch',$switchwarning,$switchserver);
18495: }
1.1207 raeburn 18496: }
18497: }
18498: return ();
18499: }
1.1181 raeburn 18500:
1.1083 raeburn 18501: sub update_content_constraints {
1.1395 raeburn 18502: my ($cdom,$cnum,$chome,$cid) = @_;
1.1083 raeburn 18503: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18504: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 18505: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 18506: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 18507: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 18508: if ($item eq 'resourcetag') {
18509: if ($name eq 'responsetype') {
18510: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
18511: }
1.1307 raeburn 18512: } elsif ($item eq 'course') {
18513: if ($name eq 'courserestype') {
18514: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
18515: }
1.1083 raeburn 18516: }
18517: }
18518: my $navmap = Apache::lonnavmaps::navmap->new();
18519: if (defined($navmap)) {
1.1307 raeburn 18520: my (%allresponses,%allcrsrestypes);
18521: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
18522: if ($res->is_tool()) {
18523: if ($allcrsrestypes{'exttool'}) {
18524: $allcrsrestypes{'exttool'} ++;
18525: } else {
18526: $allcrsrestypes{'exttool'} = 1;
18527: }
18528: next;
18529: }
1.1083 raeburn 18530: my %responses = $res->responseTypes();
18531: foreach my $key (keys(%responses)) {
18532: next unless(exists($checkresponsetypes{$key}));
18533: $allresponses{$key} += $responses{$key};
18534: }
18535: }
18536: foreach my $key (keys(%allresponses)) {
18537: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
18538: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18539: ($reqdmajor,$reqdminor) = ($major,$minor);
18540: }
18541: }
1.1307 raeburn 18542: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 18543: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 18544: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18545: ($reqdmajor,$reqdminor) = ($major,$minor);
18546: }
18547: }
1.1083 raeburn 18548: undef($navmap);
18549: }
1.1391 raeburn 18550: if (&Apache::lonnet::count_supptools($cnum,$cdom,1)) {
1.1308 raeburn 18551: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
18552: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18553: ($reqdmajor,$reqdminor) = ($major,$minor);
18554: }
18555: }
1.1083 raeburn 18556: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
18557: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
18558: }
18559: return;
18560: }
18561:
1.1110 raeburn 18562: sub allmaps_incourse {
18563: my ($cdom,$cnum,$chome,$cid) = @_;
18564: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
18565: $cid = $env{'request.course.id'};
18566: $cdom = $env{'course.'.$cid.'.domain'};
18567: $cnum = $env{'course.'.$cid.'.num'};
18568: $chome = $env{'course.'.$cid.'.home'};
18569: }
18570: my %allmaps = ();
18571: my $lastchange =
18572: &Apache::lonnet::get_coursechange($cdom,$cnum);
18573: if ($lastchange > $env{'request.course.tied'}) {
18574: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
18575: unless ($ferr) {
1.1395 raeburn 18576: &update_content_constraints($cdom,$cnum,$chome,$cid);
1.1110 raeburn 18577: }
18578: }
18579: my $navmap = Apache::lonnavmaps::navmap->new();
18580: if (defined($navmap)) {
18581: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
18582: $allmaps{$res->src()} = 1;
18583: }
18584: }
18585: return \%allmaps;
18586: }
18587:
1.1083 raeburn 18588: sub parse_supplemental_title {
18589: my ($title) = @_;
18590:
18591: my ($foldertitle,$renametitle);
18592: if ($title =~ /&&&/) {
18593: $title = &HTML::Entites::decode($title);
18594: }
18595: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
18596: $renametitle=$4;
18597: my ($time,$uname,$udom) = ($1,$2,$3);
18598: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
18599: my $name = &plainname($uname,$udom);
18600: $name = &HTML::Entities::encode($name,'"<>&\'');
18601: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.1401 ! raeburn 18602: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
! 18603: if ($foldertitle ne '') {
! 18604: $title .= ': <br />'.$foldertitle;
! 18605: }
1.1083 raeburn 18606: }
18607: if (wantarray) {
18608: return ($title,$foldertitle,$renametitle);
18609: }
18610: return $title;
18611: }
18612:
1.1395 raeburn 18613: sub get_supplemental {
18614: my ($cnum,$cdom,$ignorecache,$possdel)=@_;
18615: my $hashid=$cnum.':'.$cdom;
18616: my ($supplemental,$cached,$set_httprefs);
18617: unless ($ignorecache) {
18618: ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);
18619: }
18620: unless (defined($cached)) {
18621: my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
18622: unless ($chome eq 'no_host') {
18623: my @order = @LONCAPA::map::order;
18624: my @resources = @LONCAPA::map::resources;
18625: my @resparms = @LONCAPA::map::resparms;
18626: my @zombies = @LONCAPA::map::zombies;
18627: my ($errors,%ids,%hidden);
18628: $errors =
18629: &recurse_supplemental($cnum,$cdom,'supplemental.sequence',
18630: $errors,$possdel,\%ids,\%hidden);
18631: @LONCAPA::map::order = @order;
18632: @LONCAPA::map::resources = @resources;
18633: @LONCAPA::map::resparms = @resparms;
18634: @LONCAPA::map::zombies = @zombies;
18635: $set_httprefs = 1;
18636: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18637: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18638: }
18639: $supplemental = {
18640: ids => \%ids,
18641: hidden => \%hidden,
18642: };
18643: &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);
18644: }
18645: }
18646: return ($supplemental,$set_httprefs);
18647: }
18648:
1.1143 raeburn 18649: sub recurse_supplemental {
1.1391 raeburn 18650: my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;
18651: if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {
18652: my $mapnum;
18653: if ($suppmap eq 'supplemental.sequence') {
18654: $mapnum = 0;
18655: } else {
18656: ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);
18657: }
1.1143 raeburn 18658: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
18659: if ($fatal) {
18660: $errors ++;
18661: } else {
1.1389 raeburn 18662: my @order = @LONCAPA::map::order;
18663: if (@order > 0) {
18664: my @resources = @LONCAPA::map::resources;
1.1391 raeburn 18665: my @resparms = @LONCAPA::map::resparms;
1.1389 raeburn 18666: foreach my $idx (@order) {
18667: my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1143 raeburn 18668: if (($src ne '') && ($status eq 'res')) {
1.1391 raeburn 18669: my $id = $mapnum.':'.$idx;
18670: push(@{$suppids->{$src}},$id);
18671: if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {
18672: $hiddensupp->{$id} = 1;
18673: }
1.1146 raeburn 18674: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1391 raeburn 18675: $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,
18676: $hiddensupp,$hiddensupp->{$id});
1.1143 raeburn 18677: } else {
1.1391 raeburn 18678: my $allowed;
18679: if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {
18680: $allowed = 1;
18681: } elsif ($possdel) {
18682: foreach my $item (@{$suppids->{$src}}) {
18683: next if ($item eq $id);
18684: unless ($hiddensupp->{$item}) {
18685: $allowed = 1;
18686: last;
18687: }
18688: }
18689: if ((!$allowed) && (exists($env{'httpref.'.$src}))) {
18690: &Apache::lonnet::delenv('httpref.'.$src);
18691: }
18692: }
18693: if ($allowed && (!exists($env{'httpref.'.$src}))) {
18694: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
1.1308 raeburn 18695: }
1.1143 raeburn 18696: }
18697: }
18698: }
18699: }
18700: }
18701: }
1.1391 raeburn 18702: return $errors;
18703: }
18704:
18705: sub set_supp_httprefs {
18706: my ($cnum,$cdom,$supplemental,$possdel) = @_;
18707: if (ref($supplemental) eq 'HASH') {
18708: if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {
18709: foreach my $src (keys(%{$supplemental->{'ids'}})) {
18710: next if ($src =~ /\.sequence$/);
18711: if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {
18712: my $allowed;
18713: if ($env{'request.role.adv'}) {
18714: $allowed = 1;
18715: } else {
18716: foreach my $id (@{$supplemental->{'ids'}->{$src}}) {
18717: unless ($supplemental->{'hidden'}->{$id}) {
18718: $allowed = 1;
18719: last;
18720: }
18721: }
18722: }
18723: if (exists($env{'httpref.'.$src})) {
18724: if ($possdel) {
18725: unless ($allowed) {
18726: &Apache::lonnet::delenv('httpref.'.$src);
18727: }
18728: }
18729: } elsif ($allowed) {
18730: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
18731: }
18732: }
18733: }
18734: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18735: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18736: }
18737: }
18738: }
18739: }
18740:
18741: sub get_supp_parameter {
18742: my ($resparm,$name)=@_;
18743: return if ($resparm eq '');
18744: my $value=undef;
18745: my $ptype=undef;
18746: foreach (split('&&&',$resparm)) {
18747: my ($thistype,$thisname,$thisvalue)=split('___',$_);
18748: if ($thisname eq $name) {
18749: $value=$thisvalue;
18750: $ptype=$thistype;
18751: }
18752: }
18753: return $value;
1.1143 raeburn 18754: }
18755:
1.1101 raeburn 18756: sub symb_to_docspath {
1.1267 raeburn 18757: my ($symb,$navmapref) = @_;
18758: return unless ($symb && ref($navmapref));
1.1101 raeburn 18759: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
18760: if ($resurl=~/\.(sequence|page)$/) {
18761: $mapurl=$resurl;
18762: } elsif ($resurl eq 'adm/navmaps') {
18763: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
18764: }
18765: my $mapresobj;
1.1267 raeburn 18766: unless (ref($$navmapref)) {
18767: $$navmapref = Apache::lonnavmaps::navmap->new();
18768: }
18769: if (ref($$navmapref)) {
18770: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 18771: }
18772: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
18773: my $type=$2;
18774: my $path;
18775: if (ref($mapresobj)) {
18776: my $pcslist = $mapresobj->map_hierarchy();
18777: if ($pcslist ne '') {
18778: foreach my $pc (split(/,/,$pcslist)) {
18779: next if ($pc <= 1);
1.1267 raeburn 18780: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 18781: if (ref($res)) {
18782: my $thisurl = $res->src();
18783: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18784: my $thistitle = $res->title();
18785: $path .= '&'.
18786: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 18787: &escape($thistitle).
1.1101 raeburn 18788: ':'.$res->randompick().
18789: ':'.$res->randomout().
18790: ':'.$res->encrypted().
18791: ':'.$res->randomorder().
18792: ':'.$res->is_page();
18793: }
18794: }
18795: }
18796: $path =~ s/^\&//;
18797: my $maptitle = $mapresobj->title();
18798: if ($mapurl eq 'default') {
1.1129 raeburn 18799: $maptitle = 'Main Content';
1.1101 raeburn 18800: }
18801: $path .= (($path ne '')? '&' : '').
18802: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18803: &escape($maptitle).
1.1101 raeburn 18804: ':'.$mapresobj->randompick().
18805: ':'.$mapresobj->randomout().
18806: ':'.$mapresobj->encrypted().
18807: ':'.$mapresobj->randomorder().
18808: ':'.$mapresobj->is_page();
18809: } else {
18810: my $maptitle = &Apache::lonnet::gettitle($mapurl);
18811: my $ispage = (($type eq 'page')? 1 : '');
18812: if ($mapurl eq 'default') {
1.1129 raeburn 18813: $maptitle = 'Main Content';
1.1101 raeburn 18814: }
18815: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18816: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 18817: }
18818: unless ($mapurl eq 'default') {
18819: $path = 'default&'.
1.1146 raeburn 18820: &escape('Main Content').
1.1101 raeburn 18821: ':::::&'.$path;
18822: }
18823: return $path;
18824: }
18825:
1.1393 raeburn 18826: sub validate_folderpath {
18827: my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;
18828: if ($env{'form.folderpath'} ne '') {
18829: my @items = split(/\&/,$env{'form.folderpath'});
1.1394 raeburn 18830: my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);
1.1393 raeburn 18831: for (my $i=0; $i<@items; $i++) {
18832: my $odd = $i%2;
18833: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
18834: $badpath = 1;
1.1394 raeburn 18835: } elsif ($odd && $supplementalflag) {
1.1393 raeburn 18836: my $idx = $i-1;
1.1394 raeburn 18837: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
18838: my $esc_name = $1;
18839: if ((!$allowed) || ($items[$idx] eq 'supplemental')) {
18840: $supppath .= '&'.$esc_name;
18841: $changed = 1;
18842: } else {
18843: $supppath .= '&'.$items[$i];
18844: }
18845: } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {
18846: $changed = 1;
1.1393 raeburn 18847: my $is_hidden;
18848: unless ($got_supp) {
1.1395 raeburn 18849: my ($supplemental) = &get_supplemental($coursenum,$coursedom);
1.1393 raeburn 18850: if (ref($supplemental) eq 'HASH') {
18851: if (ref($supplemental->{'hidden'}) eq 'HASH') {
18852: %supphidden = %{$supplemental->{'hidden'}};
18853: }
18854: if (ref($supplemental->{'ids'}) eq 'HASH') {
18855: %suppids = %{$supplemental->{'ids'}};
18856: }
18857: }
18858: $got_supp = 1;
18859: }
18860: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
18861: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
18862: if ($supphidden{$mapid}) {
18863: $is_hidden = 1;
18864: }
18865: }
1.1394 raeburn 18866: $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';
18867: } else {
18868: $supppath .= '&'.$items[$i];
1.1393 raeburn 18869: }
18870: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
18871: $badpath = 1;
1.1394 raeburn 18872: } elsif ($supplementalflag) {
1.1393 raeburn 18873: $supppath .= '&'.$items[$i];
18874: }
18875: last if ($badpath);
18876: }
18877: if ($badpath) {
18878: delete($env{'form.folderpath'});
1.1394 raeburn 18879: } elsif ($changed && $supplementalflag) {
1.1393 raeburn 18880: $supppath =~ s/^\&//;
18881: $env{'form.folderpath'} = $supppath;
18882: }
18883: }
18884: return;
18885: }
18886:
1.1094 raeburn 18887: sub captcha_display {
1.1327 raeburn 18888: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18889: my ($output,$error);
1.1234 raeburn 18890: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 18891: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18892: if ($captcha eq 'original') {
1.1094 raeburn 18893: $output = &create_captcha();
18894: unless ($output) {
1.1172 raeburn 18895: $error = 'captcha';
1.1094 raeburn 18896: }
18897: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18898: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 18899: unless ($output) {
1.1172 raeburn 18900: $error = 'recaptcha';
1.1094 raeburn 18901: }
18902: }
1.1234 raeburn 18903: return ($output,$error,$captcha,$version);
1.1094 raeburn 18904: }
18905:
18906: sub captcha_response {
1.1327 raeburn 18907: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18908: my ($captcha_chk,$captcha_error);
1.1327 raeburn 18909: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18910: if ($captcha eq 'original') {
1.1094 raeburn 18911: ($captcha_chk,$captcha_error) = &check_captcha();
18912: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18913: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 18914: } else {
18915: $captcha_chk = 1;
18916: }
18917: return ($captcha_chk,$captcha_error);
18918: }
18919:
18920: sub get_captcha_config {
1.1327 raeburn 18921: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 18922: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 18923: my $hostname = &Apache::lonnet::hostname($lonhost);
18924: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18925: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 18926: if ($context eq 'usercreation') {
18927: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18928: if (ref($domconfig{$context}) eq 'HASH') {
18929: $hashtocheck = $domconfig{$context}{'cancreate'};
18930: if (ref($hashtocheck) eq 'HASH') {
18931: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18932: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18933: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18934: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18935: }
18936: if ($privkey && $pubkey) {
18937: $captcha = 'recaptcha';
1.1234 raeburn 18938: $version = $hashtocheck->{'recaptchaversion'};
18939: if ($version ne '2') {
18940: $version = 1;
18941: }
1.1095 raeburn 18942: } else {
18943: $captcha = 'original';
18944: }
18945: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
18946: $captcha = 'original';
18947: }
1.1094 raeburn 18948: }
1.1095 raeburn 18949: } else {
18950: $captcha = 'captcha';
18951: }
18952: } elsif ($context eq 'login') {
18953: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
18954: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
18955: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
18956: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 18957: if ($privkey && $pubkey) {
18958: $captcha = 'recaptcha';
1.1234 raeburn 18959: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
18960: if ($version ne '2') {
18961: $version = 1;
18962: }
1.1095 raeburn 18963: } else {
18964: $captcha = 'original';
1.1094 raeburn 18965: }
1.1095 raeburn 18966: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18967: $captcha = 'original';
1.1094 raeburn 18968: }
1.1327 raeburn 18969: } elsif ($context eq 'passwords') {
18970: if ($dom_in_effect) {
18971: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18972: if ($passwdconf{'captcha'} eq 'recaptcha') {
18973: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18974: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18975: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18976: }
18977: if ($privkey && $pubkey) {
18978: $captcha = 'recaptcha';
18979: $version = $passwdconf{'recaptchaversion'};
18980: if ($version ne '2') {
18981: $version = 1;
18982: }
18983: } else {
18984: $captcha = 'original';
18985: }
18986: } elsif ($passwdconf{'captcha'} ne 'notused') {
18987: $captcha = 'original';
18988: }
18989: }
18990: }
1.1234 raeburn 18991: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 18992: }
18993:
18994: sub create_captcha {
18995: my %captcha_params = &captcha_settings();
18996: my ($output,$maxtries,$tries) = ('',10,0);
18997: while ($tries < $maxtries) {
18998: $tries ++;
18999: my $captcha = Authen::Captcha->new (
19000: output_folder => $captcha_params{'output_dir'},
19001: data_folder => $captcha_params{'db_dir'},
19002: );
19003: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
19004:
19005: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
19006: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1367 raeburn 19007: '<span class="LC_nobreak">'.
1.1094 raeburn 19008: &mt('Type in the letters/numbers shown below').' '.
1.1390 raeburn 19009: '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1367 raeburn 19010: '</span><br />'.
1.1176 raeburn 19011: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 19012: last;
19013: }
19014: }
1.1323 raeburn 19015: if ($output eq '') {
19016: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
19017: }
1.1094 raeburn 19018: return $output;
19019: }
19020:
19021: sub captcha_settings {
19022: my %captcha_params = (
19023: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
19024: www_output_dir => "/captchaspool",
19025: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
19026: numchars => '5',
19027: );
19028: return %captcha_params;
19029: }
19030:
19031: sub check_captcha {
19032: my ($captcha_chk,$captcha_error);
19033: my $code = $env{'form.code'};
19034: my $md5sum = $env{'form.crypt'};
19035: my %captcha_params = &captcha_settings();
19036: my $captcha = Authen::Captcha->new(
19037: output_folder => $captcha_params{'output_dir'},
19038: data_folder => $captcha_params{'db_dir'},
19039: );
1.1109 raeburn 19040: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 19041: my %captcha_hash = (
19042: 0 => 'Code not checked (file error)',
19043: -1 => 'Failed: code expired',
19044: -2 => 'Failed: invalid code (not in database)',
19045: -3 => 'Failed: invalid code (code does not match crypt)',
19046: );
19047: if ($captcha_chk != 1) {
19048: $captcha_error = $captcha_hash{$captcha_chk}
19049: }
19050: return ($captcha_chk,$captcha_error);
19051: }
19052:
19053: sub create_recaptcha {
1.1234 raeburn 19054: my ($pubkey,$version) = @_;
19055: if ($version >= 2) {
1.1367 raeburn 19056: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
19057: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1234 raeburn 19058: } else {
19059: my $use_ssl;
19060: if ($ENV{'SERVER_PORT'} == 443) {
19061: $use_ssl = 1;
19062: }
19063: my $captcha = Captcha::reCAPTCHA->new;
19064: return $captcha->get_options_setter({theme => 'white'})."\n".
19065: $captcha->get_html($pubkey,undef,$use_ssl).
19066: &mt('If the text is hard to read, [_1] will replace them.',
19067: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
19068: '<br /><br />';
19069: }
1.1094 raeburn 19070: }
19071:
19072: sub check_recaptcha {
1.1234 raeburn 19073: my ($privkey,$version) = @_;
1.1094 raeburn 19074: my $captcha_chk;
1.1350 raeburn 19075: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 19076: if ($version >= 2) {
19077: my %info = (
19078: secret => $privkey,
19079: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 19080: remoteip => $ip,
1.1234 raeburn 19081: );
1.1280 raeburn 19082: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
19083: $request->content(join('&',map {
19084: my $name = escape($_);
19085: "$name=" . ( ref($info{$_}) eq 'ARRAY'
19086: ? join("&$name=", map {escape($_) } @{$info{$_}})
19087: : &escape($info{$_}) );
19088: } keys(%info)));
19089: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 19090: if ($response->is_success) {
19091: my $data = JSON::DWIW->from_json($response->decoded_content);
19092: if (ref($data) eq 'HASH') {
19093: if ($data->{'success'}) {
19094: $captcha_chk = 1;
19095: }
19096: }
19097: }
19098: } else {
19099: my $captcha = Captcha::reCAPTCHA->new;
19100: my $captcha_result =
19101: $captcha->check_answer(
19102: $privkey,
1.1350 raeburn 19103: $ip,
1.1234 raeburn 19104: $env{'form.recaptcha_challenge_field'},
19105: $env{'form.recaptcha_response_field'},
19106: );
19107: if ($captcha_result->{is_valid}) {
19108: $captcha_chk = 1;
19109: }
1.1094 raeburn 19110: }
19111: return $captcha_chk;
19112: }
19113:
1.1174 raeburn 19114: sub emailusername_info {
1.1244 raeburn 19115: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 19116: my %titles = &Apache::lonlocal::texthash (
19117: lastname => 'Last Name',
19118: firstname => 'First Name',
19119: institution => 'School/college/university',
19120: location => "School's city, state/province, country",
19121: web => "School's web address",
19122: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 19123: id => 'Student/Employee ID',
1.1174 raeburn 19124: );
19125: return (\@fields,\%titles);
19126: }
19127:
1.1161 raeburn 19128: sub cleanup_html {
19129: my ($incoming) = @_;
19130: my $outgoing;
19131: if ($incoming ne '') {
19132: $outgoing = $incoming;
19133: $outgoing =~ s/;/;/g;
19134: $outgoing =~ s/\#/#/g;
19135: $outgoing =~ s/\&/&/g;
19136: $outgoing =~ s/</</g;
19137: $outgoing =~ s/>/>/g;
19138: $outgoing =~ s/\(/(/g;
19139: $outgoing =~ s/\)/)/g;
19140: $outgoing =~ s/"/"/g;
19141: $outgoing =~ s/'/'/g;
19142: $outgoing =~ s/\$/$/g;
19143: $outgoing =~ s{/}{/}g;
19144: $outgoing =~ s/=/=/g;
19145: $outgoing =~ s/\\/\/g
19146: }
19147: return $outgoing;
19148: }
19149:
1.1190 musolffc 19150: # Checks for critical messages and returns a redirect url if one exists.
19151: # $interval indicates how often to check for messages.
1.1282 raeburn 19152: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 19153: sub critical_redirect {
1.1282 raeburn 19154: my ($interval,$context) = @_;
1.1356 raeburn 19155: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
19156: return ();
19157: }
1.1190 musolffc 19158: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 19159: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
19160: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
19161: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 19162: my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 19163: if ($blocked) {
19164: my $checkrole = "cm./$cdom/$cnum";
19165: if ($env{'request.course.sec'} ne '') {
19166: $checkrole .= "/$env{'request.course.sec'}";
19167: }
19168: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
19169: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
19170: return;
19171: }
19172: }
19173: }
1.1190 musolffc 19174: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
19175: $env{'user.name'});
19176: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 19177: my $redirecturl;
1.1190 musolffc 19178: if ($what[0]) {
1.1356 raeburn 19179: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1190 musolffc 19180: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 19181: my $url=&Apache::lonnet::absolute_url().$redirecturl;
19182: return (1, $url);
1.1190 musolffc 19183: }
1.1191 raeburn 19184: }
19185: }
19186: return ();
1.1190 musolffc 19187: }
19188:
1.1174 raeburn 19189: # Use:
19190: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
19191: #
19192: ##################################################
19193: # password associated functions #
19194: ##################################################
19195: sub des_keys {
19196: # Make a new key for DES encryption.
19197: # Each key has two parts which are returned separately.
19198: # Please note: Each key must be passed through the &hex function
19199: # before it is output to the web browser. The hex versions cannot
19200: # be used to decrypt.
19201: my @hexstr=('0','1','2','3','4','5','6','7',
19202: '8','9','a','b','c','d','e','f');
19203: my $lkey='';
19204: for (0..7) {
19205: $lkey.=$hexstr[rand(15)];
19206: }
19207: my $ukey='';
19208: for (0..7) {
19209: $ukey.=$hexstr[rand(15)];
19210: }
19211: return ($lkey,$ukey);
19212: }
19213:
19214: sub des_decrypt {
19215: my ($key,$cyphertext) = @_;
19216: my $keybin=pack("H16",$key);
19217: my $cypher;
19218: if ($Crypt::DES::VERSION>=2.03) {
19219: $cypher=new Crypt::DES $keybin;
19220: } else {
19221: $cypher=new DES $keybin;
19222: }
1.1233 raeburn 19223: my $plaintext='';
19224: my $cypherlength = length($cyphertext);
19225: my $numchunks = int($cypherlength/32);
19226: for (my $j=0; $j<$numchunks; $j++) {
19227: my $start = $j*32;
19228: my $cypherblock = substr($cyphertext,$start,32);
19229: my $chunk =
19230: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
19231: $chunk .=
19232: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
19233: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
19234: $plaintext .= $chunk;
19235: }
1.1174 raeburn 19236: return $plaintext;
19237: }
19238:
1.1344 raeburn 19239: sub get_requested_shorturls {
1.1309 raeburn 19240: my ($cdom,$cnum,$navmap) = @_;
19241: return unless (ref($navmap));
1.1344 raeburn 19242: my ($numnew,$errors);
1.1309 raeburn 19243: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
19244: if (@toshorten) {
19245: my (%maps,%resources,%titles);
19246: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
19247: 'shorturls',$cdom,$cnum);
19248: if (keys(%resources)) {
1.1344 raeburn 19249: my %tocreate;
1.1309 raeburn 19250: foreach my $item (sort {$a <=> $b} (@toshorten)) {
19251: my $symb = $resources{$item};
19252: if ($symb) {
19253: $tocreate{$cnum.'&'.$symb} = 1;
19254: }
19255: }
1.1344 raeburn 19256: if (keys(%tocreate)) {
19257: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
19258: \%tocreate);
19259: }
1.1309 raeburn 19260: }
1.1344 raeburn 19261: }
19262: return ($numnew,$errors);
19263: }
19264:
19265: sub make_short_symbs {
19266: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
19267: my ($numnew,@errors);
19268: if (ref($tocreateref) eq 'HASH') {
19269: my %tocreate = %{$tocreateref};
1.1309 raeburn 19270: if (keys(%tocreate)) {
19271: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
19272: my $su = Short::URL->new(no_vowels => 1);
19273: my $init = '';
19274: my (%newunique,%addcourse,%courseonly,%failed);
19275: # get lock on tiny db
19276: my $now = time;
1.1344 raeburn 19277: if ($lockuser eq '') {
19278: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
19279: }
1.1309 raeburn 19280: my $lockhash = {
1.1344 raeburn 19281: "lock\0$now" => $lockuser,
1.1309 raeburn 19282: };
19283: my $tries = 0;
19284: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
19285: my ($code,$error);
19286: while (($gotlock ne 'ok') && ($tries<3)) {
19287: $tries ++;
19288: sleep 1;
1.1319 raeburn 19289: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 19290: }
19291: if ($gotlock eq 'ok') {
19292: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
19293: \%addcourse,\%courseonly,\%failed);
19294: if (keys(%failed)) {
19295: my $numfailed = scalar(keys(%failed));
19296: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
19297: }
19298: if (keys(%newunique)) {
19299: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
19300: if ($putres eq 'ok') {
19301: $numnew = scalar(keys(%newunique));
19302: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
19303: unless ($newputres eq 'ok') {
19304: push(@errors,&mt('error: could not store course look-up of short URLs'));
19305: }
19306: } else {
19307: push(@errors,&mt('error: could not store unique six character URLs'));
19308: }
19309: }
19310: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
19311: unless ($dellockres eq 'ok') {
19312: push(@errors,&mt('error: could not release lockfile'));
19313: }
19314: } else {
19315: push(@errors,&mt('error: could not obtain lockfile'));
19316: }
19317: if (keys(%courseonly)) {
19318: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
19319: if ($result ne 'ok') {
19320: push(@errors,&mt('error: could not update course look-up of short URLs'));
19321: }
19322: }
19323: }
19324: }
19325: return ($numnew,\@errors);
19326: }
19327:
19328: sub shorten_symbs {
19329: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
19330: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
19331: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
19332: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
19333: my (%possibles,%collisions);
19334: foreach my $key (keys(%{$tocreate})) {
19335: my $num = String::CRC32::crc32($key);
19336: my $tiny = $su->encode($num,$init);
19337: if ($tiny) {
19338: $possibles{$tiny} = $key;
19339: }
19340: }
19341: if (!$init) {
19342: $init = 1;
19343: } else {
19344: $init ++;
19345: }
19346: if (keys(%possibles)) {
19347: my @posstiny = keys(%possibles);
19348: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
19349: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
19350: if (keys(%currtiny)) {
19351: foreach my $key (keys(%currtiny)) {
19352: next if ($currtiny{$key} eq '');
19353: if ($currtiny{$key} eq $possibles{$key}) {
19354: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
19355: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19356: $courseonly->{$tsymb} = $key;
19357: }
19358: } else {
19359: $collisions{$possibles{$key}} = 1;
19360: }
19361: delete($possibles{$key});
19362: }
19363: }
19364: foreach my $key (keys(%possibles)) {
19365: $newunique->{$key} = $possibles{$key};
19366: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
19367: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19368: $addcourse->{$tsymb} = $key;
19369: }
19370: }
19371: }
19372: if (keys(%collisions)) {
19373: if ($init <5) {
19374: if (!$init) {
19375: $init = 1;
19376: } else {
19377: $init ++;
19378: }
19379: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
19380: $newunique,$addcourse,$courseonly,$failed);
19381: } else {
19382: foreach my $key (keys(%collisions)) {
19383: $failed->{$key} = 1;
19384: }
19385: }
19386: }
19387: return $init;
19388: }
19389:
1.1328 raeburn 19390: sub is_nonframeable {
1.1329 raeburn 19391: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
19392: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 19393: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 19394:
19395: $remprotocol = lc($remprotocol);
19396: $remhost = lc($remhost);
19397: my $remport = 80;
19398: if ($remprotocol eq 'https') {
19399: $remport = 443;
19400: }
1.1330 raeburn 19401: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 19402: if ($cached) {
19403: unless ($nocache) {
19404: if ($result) {
19405: return 1;
19406: } else {
19407: return 0;
19408: }
19409: }
19410: }
1.1328 raeburn 19411: my $uselink;
19412: my $request = new HTTP::Request('HEAD',$url);
19413: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
19414: if ($response->is_success()) {
19415: my $secpolicy = lc($response->header('content-security-policy'));
19416: my $xframeop = lc($response->header('x-frame-options'));
19417: $secpolicy =~ s/^\s+|\s+$//g;
19418: $xframeop =~ s/^\s+|\s+$//g;
19419: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 19420: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 19421: my ($origin,$protocol,$port);
19422: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
19423: $port = $ENV{'SERVER_PORT'};
19424: } else {
19425: $port = 80;
19426: }
19427: if ($absolute eq '') {
19428: $protocol = 'http:';
19429: if ($port == 443) {
19430: $protocol = 'https:';
19431: }
19432: $origin = $protocol.'//'.lc($hostname);
19433: } else {
19434: $origin = lc($absolute);
19435: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
19436: }
19437: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
19438: my $framepolicy = $1;
19439: $framepolicy =~ s/^\s+|\s+$//g;
19440: my @policies = split(/\s+/,$framepolicy);
19441: if (@policies) {
19442: if (grep(/^\Q'none'\E$/,@policies)) {
19443: $uselink = 1;
19444: } else {
19445: $uselink = 1;
19446: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
19447: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
19448: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
19449: undef($uselink);
19450: }
19451: if ($uselink) {
19452: if (grep(/^\Q'self'\E$/,@policies)) {
19453: if (($origin ne '') && ($remotehost eq $origin)) {
19454: undef($uselink);
19455: }
19456: }
19457: }
19458: if ($uselink) {
19459: my @possok;
19460: if ($ip ne '') {
19461: push(@possok,$ip);
19462: }
19463: my $hoststr = '';
19464: foreach my $part (reverse(split(/\./,$hostname))) {
19465: if ($hoststr eq '') {
19466: $hoststr = $part;
19467: } else {
19468: $hoststr = "$part.$hoststr";
19469: }
19470: if ($hoststr eq $hostname) {
19471: push(@possok,$hostname);
19472: } else {
19473: push(@possok,"*.$hoststr");
19474: }
19475: }
19476: if (@possok) {
19477: foreach my $poss (@possok) {
19478: last if (!$uselink);
19479: foreach my $policy (@policies) {
19480: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
19481: undef($uselink);
19482: last;
19483: }
19484: }
19485: }
19486: }
19487: }
19488: }
19489: }
19490: } elsif ($xframeop ne '') {
19491: $uselink = 1;
19492: my @policies = split(/\s*,\s*/,$xframeop);
19493: if (@policies) {
19494: unless (grep(/^deny$/,@policies)) {
19495: if ($origin ne '') {
19496: if (grep(/^sameorigin$/,@policies)) {
19497: if ($remotehost eq $origin) {
19498: undef($uselink);
19499: }
19500: }
19501: if ($uselink) {
19502: foreach my $policy (@policies) {
19503: if ($policy =~ /^allow-from\s*(.+)$/) {
19504: my $allowfrom = $1;
19505: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
19506: undef($uselink);
19507: last;
19508: }
19509: }
19510: }
19511: }
19512: }
19513: }
19514: }
19515: }
19516: }
19517: }
1.1329 raeburn 19518: if ($nocache) {
19519: if ($cached) {
19520: my $devalidate;
19521: if ($uselink && !$result) {
19522: $devalidate = 1;
19523: } elsif (!$uselink && $result) {
19524: $devalidate = 1;
19525: }
19526: if ($devalidate) {
19527: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
19528: }
19529: }
19530: } else {
19531: if ($uselink) {
19532: $result = 1;
19533: } else {
19534: $result = 0;
19535: }
19536: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
19537: }
1.1328 raeburn 19538: return $uselink;
19539: }
19540:
1.1359 raeburn 19541: sub page_menu {
19542: my ($menucolls,$menunum) = @_;
19543: my %menu;
19544: foreach my $item (split(/;/,$menucolls)) {
19545: my ($num,$value) = split(/\%/,$item);
19546: if ($num eq $menunum) {
19547: my @entries = split(/\&/,$value);
19548: foreach my $entry (@entries) {
19549: my ($name,$fields) = split(/=/,$entry);
1.1368 raeburn 19550: if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
1.1359 raeburn 19551: $menu{$name} = $fields;
19552: } else {
19553: my @shown;
19554: if ($fields =~ /,/) {
19555: @shown = split(/,/,$fields);
19556: } else {
19557: @shown = ($fields);
19558: }
19559: if (@shown) {
19560: foreach my $field (@shown) {
19561: next if ($field eq '');
19562: $menu{$field} = 1;
19563: }
19564: }
19565: }
19566: }
19567: }
19568: }
19569: return %menu;
19570: }
19571:
1.112 bowersj2 19572: 1;
19573: __END__;
1.41 ng 19574:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>