Annotation of loncom/interface/loncommon.pm, revision 1.1405
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1405 ! raeburn 4: # $Id: loncommon.pm,v 1.1404 2023/04/02 03:16:27 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: }
1.1402 raeburn 1854: populateCrsSelects(form,dirsel,filesel,1,include,1,0,1,1,0);
1.1400 raeburn 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 = '';
1.1402 raeburn 1862: populateCrsSelects(form,dirsel,filesel,0,'',1,0,1,0,1);
1.1400 raeburn 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.1402 raeburn 1877: if ((document.getElementById('hascrsres_'+element)) &&
1878: (document.getElementById('nocrsres_'+element))) {
1879: if (numdirs) {
1880: document.getElementById('hascrsres_'+element).style.display='inline-block';
1881: document.getElementById('nocrsres_'+element).style.display='none';
1882: } else {
1883: document.getElementById('hascrsres_'+element).style.display='none';
1884: document.getElementById('nocrsres_'+element).style.display='inline-block';
1885: }
1886: }
1.1248 raeburn 1887: form.elements['coursepath_'+element].selectedIndex = 0;
1888: if (numdirs > 1) {
1.1400 raeburn 1889: var selelem = form.elements['coursefile_'+element];
1890: var i, len = selelem.options.length -1;
1891: if (len >=0) {
1892: for (i = len; i >= 0; i--) {
1893: selelem.remove(i);
1894: }
1895: selelem.options[0] = new Option('','');
1896: }
1.1248 raeburn 1897: }
1898: }
1.1400 raeburn 1899: }
1.1248 raeburn 1900: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1901: }
1902: if (document.getElementById('chooser_'+element+'_upload')) {
1903: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1904: if (document.getElementById('uploadcrsres_'+element)) {
1905: document.getElementById('uploadcrsres_'+element).value = '';
1906: }
1907: }
1908: return;
1909: }
1910:
1.1400 raeburn 1911: function toggleCrsUpload(form,element) {
1.1248 raeburn 1912: if (document.getElementById('chooser_'+element+'_crsres')) {
1913: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1914: }
1915: if (document.getElementById('chooser_'+element+'_upload')) {
1916: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1917: if (curr == 'none') {
1.1400 raeburn 1918: form.elements['newsubdir_'+element][0].checked = true;
1919: toggleNewsubdir(form,element);
1920: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1921: if (document.getElementById('uploadcrsres_'+element)) {
1922: document.getElementById('uploadcrsres_'+element).value = '';
1.1248 raeburn 1923: }
1924: }
1925: }
1926: return;
1927: }
1928:
1929: function toggleResImport(form,element) {
1930: var choices = new Array('crsres','upload');
1931: for (var i=0; i<choices.length; i++) {
1932: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1933: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1934: }
1935: }
1936: }
1937:
1938: function toggleNewsubdir(form,element) {
1939: var newsub = form.elements['newsubdir_'+element];
1940: if (newsub) {
1941: if (newsub.length) {
1942: for (var j=0; j<newsub.length; j++) {
1943: if (newsub[j].checked) {
1944: if (document.getElementById('newsubdirname_'+element)) {
1945: if (newsub[j].value == '1') {
1946: document.getElementById('newsubdirname_'+element).type = "text";
1947: if (document.getElementById('newsubdir_'+element)) {
1948: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1949: }
1950: } else {
1951: document.getElementById('newsubdirname_'+element).type = "hidden";
1952: document.getElementById('newsubdirname_'+element).value = "";
1953: document.getElementById('newsubdir_'+element).innerHTML = "";
1954: }
1955: }
1956: break;
1957: }
1958: }
1959: }
1960: }
1961: }
1962:
1963: function updateCrsFile(form,element) {
1964: var directory = form.elements['coursepath_'+element];
1965: var filename = form.elements['coursefile_'+element];
1966: var path = directory.options[directory.selectedIndex].value;
1967: var file = filename.options[filename.selectedIndex].value;
1.1400 raeburn 1968: if (file != '') {
1969: form.elements[element].value = '$respath';
1970: if (path == '/') {
1971: form.elements[element].value += file;
1972: } else {
1973: form.elements[element].value += path+'/'+file;
1974: }
1975: unClean();
1976: if (document.getElementById('previewimg_'+element)) {
1977: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1978: var newsrc = document.getElementById('previewimg_'+element).src;
1979: }
1980: if (document.getElementById('showimg_'+element)) {
1981: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1982: }
1.1248 raeburn 1983: }
1984: toggleChooser(form,element);
1985: return;
1986: }
1987:
1988: function uploadDone(suffix,name) {
1989: if (name) {
1990: document.forms["lonhomework"].elements[suffix].value = name;
1991: unClean();
1992: toggleChooser(document.forms["lonhomework"],suffix);
1993: }
1994: }
1995:
1996: \$(document).ready(function(){
1997:
1998: \$(document).delegate('form :submit', 'click', function( event ) {
1999: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
2000: var buttonId = this.id;
2001: var suffix = buttonId.toString();
2002: suffix = suffix.replace(/^crsupload_/,'');
2003: event.preventDefault();
2004: document.lonhomework.target = 'crsupload_target_'+suffix;
2005: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
2006: \$(this.form).submit();
2007: document.lonhomework.target = '';
2008: if (document.getElementById('crsuploadto_'+suffix)) {
2009: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
2010: }
2011: return false;
2012: }
2013: });
2014: });
2015: END
2016: }
1.1205 golterma 2017: return <<"COLORFULEDIT"
2018: <script type="text/javascript">
2019: // <![CDATA[>
2020: function fold_box(curDepth, lastresource){
2021:
2022: // we need a list because there can be several blocks you need to fold in one tag
2023: var block = document.getElementsByName('foldblock_'+curDepth);
2024: // but there is only one folding button per tag
2025: var foldbutton = document.getElementById('folding_btn_'+curDepth);
2026:
2027: if(block.item(0).style.display == 'none'){
2028:
2029: foldbutton.value = '@{[&mt("Hide")]}';
2030: for (i = 0; i < block.length; i++){
2031: block.item(i).style.display = '';
2032: }
2033: }else{
2034:
2035: foldbutton.value = '@{[&mt("Show")]}';
2036: for (i = 0; i < block.length; i++){
2037: // block.item(i).style.visibility = 'collapse';
2038: block.item(i).style.display = 'none';
2039: }
2040: };
2041: saveState(lastresource);
2042: }
2043:
2044: function saveState (lastresource) {
2045:
2046: var tag_list = getTagList();
2047: if(tag_list != null){
2048: var timestamp = new Date().getTime();
2049: var key = lastresource;
2050:
2051: // the value pattern is: 'time;key1,value1;key2,value2; ... '
2052: // starting with timestamp
2053: var value = timestamp+';';
2054:
2055: // building the list of key-value pairs
2056: for(var i = 0; i < tag_list.length; i++){
2057: value += tag_list[i]+',';
2058: value += document.getElementsByName(tag_list[i])[0].style.display+';';
2059: }
2060:
2061: // only iterate whole storage if nothing to override
2062: if(localStorage.getItem(key) == null){
2063:
2064: // prevent storage from growing large
2065: if(localStorage.length > 50){
2066: var regex_getTimestamp = /^(?:\d)+;/;
2067: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2068: var oldest_key;
2069:
2070: for(var i = 1; i < localStorage.length; i++){
2071: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2072: oldest_key = localStorage.key(i);
2073: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2074: }
2075: }
2076: localStorage.removeItem(oldest_key);
2077: }
2078: }
2079: localStorage.setItem(key,value);
2080: }
2081: }
2082:
2083: // restore folding status of blocks (on page load)
2084: function restoreState (lastresource) {
2085: if(localStorage.getItem(lastresource) != null){
2086: var key = lastresource;
2087: var value = localStorage.getItem(key);
2088: var regex_delTimestamp = /^\d+;/;
2089:
2090: value.replace(regex_delTimestamp, '');
2091:
2092: var valueArr = value.split(';');
2093: var pairs;
2094: var elements;
2095: for (var i = 0; i < valueArr.length; i++){
2096: pairs = valueArr[i].split(',');
2097: elements = document.getElementsByName(pairs[0]);
2098:
2099: for (var j = 0; j < elements.length; j++){
2100: elements[j].style.display = pairs[1];
2101: if (pairs[1] == "none"){
2102: var regex_id = /([_\\d]+)\$/;
2103: regex_id.exec(pairs[0]);
2104: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2105: }
2106: }
2107: }
2108: }
2109: }
2110:
2111: function getTagList () {
2112:
2113: var stringToSearch = document.lonhomework.innerHTML;
2114:
2115: var ret = new Array();
2116: var regex_findBlock = /(foldblock_.*?)"/g;
2117: var tag_list = stringToSearch.match(regex_findBlock);
2118:
2119: if(tag_list != null){
2120: for(var i = 0; i < tag_list.length; i++){
2121: ret.push(tag_list[i].replace(/"/, ''));
2122: }
2123: }
2124: return ret;
2125: }
2126:
2127: function saveScrollPosition (resource) {
2128: var tag_list = getTagList();
2129:
2130: // we dont always want to jump to the first block
2131: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2132: if(\$(window).scrollTop() > 170){
2133: if(tag_list != null){
2134: var result;
2135: for(var i = 0; i < tag_list.length; i++){
2136: if(isElementInViewport(tag_list[i])){
2137: result += tag_list[i]+';';
2138: }
2139: }
2140: sessionStorage.setItem('anchor_'+resource, result);
2141: }
2142: } else {
2143: // we dont need to save zero, just delete the item to leave everything tidy
2144: sessionStorage.removeItem('anchor_'+resource);
2145: }
2146: }
2147:
2148: function restoreScrollPosition(resource){
2149:
2150: var elem = sessionStorage.getItem('anchor_'+resource);
2151: if(elem != null){
2152: var tag_list = elem.split(';');
2153: var elem_list;
2154:
2155: for(var i = 0; i < tag_list.length; i++){
2156: elem_list = document.getElementsByName(tag_list[i]);
2157:
2158: if(elem_list.length > 0){
2159: elem = elem_list[0];
2160: break;
2161: }
2162: }
2163: elem.scrollIntoView();
2164: }
2165: }
2166:
2167: function isElementInViewport(el) {
2168:
2169: // change to last element instead of first
2170: var elem = document.getElementsByName(el);
2171: var rect = elem[0].getBoundingClientRect();
2172:
2173: return (
2174: rect.top >= 0 &&
2175: rect.left >= 0 &&
2176: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2177: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2178: );
2179: }
2180:
2181: function autosize(depth){
2182: var cmInst = window['cm'+depth];
2183: var fitsizeButton = document.getElementById('fitsize'+depth);
2184:
2185: // is fixed size, switching to dynamic
2186: if (sessionStorage.getItem("autosized_"+depth) == null) {
2187: cmInst.setSize("","auto");
2188: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2189: sessionStorage.setItem("autosized_"+depth, "yes");
2190:
2191: // is dynamic size, switching to fixed
2192: } else {
2193: cmInst.setSize("","300px");
2194: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2195: sessionStorage.removeItem("autosized_"+depth);
2196: }
2197: }
2198:
1.1248 raeburn 2199: $browse_or_search
1.1205 golterma 2200:
2201: // ]]>
2202: </script>
2203: COLORFULEDIT
2204: }
2205:
2206: sub xmleditor_js {
2207: return <<XMLEDIT
2208: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2209: <script type="text/javascript">
2210: // <![CDATA[>
2211:
2212: function saveScrollPosition (resource) {
2213:
2214: var scrollPos = \$(window).scrollTop();
2215: sessionStorage.setItem(resource,scrollPos);
2216: }
2217:
2218: function restoreScrollPosition(resource){
2219:
2220: var scrollPos = sessionStorage.getItem(resource);
2221: \$(window).scrollTop(scrollPos);
2222: }
2223:
2224: // unless internet explorer
2225: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2226:
2227: \$(document).ready(function() {
2228: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2229: });
2230: }
2231:
2232: // inserts text at cursor position into codemirror (xml editor only)
2233: function insertText(text){
2234: cm.focus();
2235: var curPos = cm.getCursor();
2236: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2237: }
2238: // ]]>
2239: </script>
2240: XMLEDIT
2241: }
2242:
2243: sub insert_folding_button {
2244: my $curDepth = $Apache::lonxml::curdepth;
2245: my $lastresource = $env{'request.ambiguous'};
2246:
2247: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2248: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2249: }
2250:
1.1248 raeburn 2251: sub crsauthor_url {
2252: my ($url) = @_;
2253: if ($url eq '') {
2254: $url = $ENV{'REQUEST_URI'};
2255: }
2256: my ($cnum,$cdom);
2257: if ($env{'request.course.id'}) {
2258: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2259: if ($audom ne '' && $auname ne '') {
2260: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2261: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2262: $cnum = $auname;
2263: $cdom = $audom;
2264: }
2265: }
2266: }
2267: return ($cnum,$cdom);
2268: }
2269:
2270: sub import_crsauthor_form {
1.1400 raeburn 2271: my ($firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2272: return (0) unless ($env{'request.course.id'});
2273: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2274: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2275: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2276: return (0) unless (($cnum ne '') && ($cdom ne ''));
2277: my @ids=&Apache::lonnet::current_machine_ids();
1.1400 raeburn 2278: my ($output,$is_home,$toppath,%subdirs,%files,%selimport_menus,$include,$exclude);
1.1402 raeburn 2279:
1.1248 raeburn 2280: if (grep(/^\Q$crshome\E$/,@ids)) {
2281: $is_home = 1;
2282: }
1.1400 raeburn 2283: $toppath = "/priv/$cdom/$cnum";
2284: my $nonemptydir = 1;
2285: my $js_only;
2286: if ($only) {
2287: map { $include->{$_} = 1; } split(/\s*,\s*/,$only);
2288: $js_only = join(',',map { &js_escape($_); } sort(keys(%{$include})));
2289: }
2290: $exclude = &Apache::lonnet::priv_exclude();
1.1402 raeburn 2291: &Apache::lonnet::recursedirs($is_home,1,$include,$exclude,1,0,$toppath,'',\%subdirs,\%files);
1.1400 raeburn 2292: my $numdirs = scalar(keys(%files));
1.1248 raeburn 2293: my %lt = &Apache::lonlocal::texthash (
2294: fnam => 'Filename',
2295: dire => 'Directory',
1.1400 raeburn 2296: se => 'Select',
1.1248 raeburn 2297: );
1.1402 raeburn 2298: $output = $lt{'dire'}.': '.
1.1400 raeburn 2299: '<select id="'.$firstselectname.'" name="'.$firstselectname.'" '.
1.1402 raeburn 2300: 'onchange="populateCrsSelects(this.form,'."'$firstselectname','$secondselectname',1,'$js_only',0,1,0,0,0".');">'.
1.1400 raeburn 2301: '<option value="" selected="selected">'.$lt{'se'}.'</option>';
1.1402 raeburn 2302: if ($files{'/'}) {
2303: $output .= '<option value="/">/</option>'."\n";
2304: }
1.1400 raeburn 2305: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
1.1402 raeburn 2306: next if ($key eq '/');
1.1400 raeburn 2307: $output .= '<option value="'.$key.'">'.$key.'</option>'."\n";
2308: }
2309: $output .= '</select><br />'."\n".
1.1402 raeburn 2310: $lt{'fnam'}.': <select id="'.$secondselectname.'" name="'.$secondselectname.'">'."\n".
1.1400 raeburn 2311: '<option value="" selected="selected"></option>'."\n".
1.1402 raeburn 2312: '</select>'."\n".
2313: '<input type="hidden" id="crsres_include_'.$suffix.'" value="'.$only.'" />';
1.1400 raeburn 2314: return ($numdirs,$output);
2315: }
2316:
2317: sub show_crsfiles_js {
2318: my $excluderef = &Apache::lonnet::priv_exclude();
2319: my $se = &js_escape(&mt('Select'));
2320: my $exclude;
2321: if (ref($excluderef) eq 'HASH') {
2322: $exclude = join(',', map { &js_escape($_); } sort(keys(%{$excluderef})));
2323: }
2324: my $js = <<"END";
2325:
2326:
1.1402 raeburn 2327: function populateCrsSelects (form,dirsel,filesel,exc,include,setdir,setfile,recurse,nonemptydir,addtopdir) {
1.1400 raeburn 2328: var relpath = '';
2329: if ((setfile) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2330: var currdir = form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value;
2331: if (currdir == '') {
2332: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2333: selelem = form.elements[filesel];
2334: var j, numfiles = selelem.options.length -1;
2335: if (numfiles >=0) {
2336: for (j = numfiles; j >= 0; j--) {
2337: selelem.remove(j);
2338: }
2339: }
2340: if (selelem.options.length == 0) {
2341: selelem.options[selelem.options.length] = new Option('','');
2342: selelem.selectedIndex = 0;
1.1248 raeburn 2343: }
2344: }
1.1400 raeburn 2345: return;
2346: } else {
2347: relpath = encodeURIComponent(form.elements[dirsel].options[form.elements[dirsel].selectedIndex].value);
1.1248 raeburn 2348: }
2349: }
1.1400 raeburn 2350: var http = new XMLHttpRequest();
2351: var url = "/adm/courseauthor";
2352: var crsrole = "$env{'request.role'}";
2353: var exclude = '';
2354: if (exc) {
2355: exclude = '$exclude';
2356: }
1.1402 raeburn 2357: var params = "role=course&files=1&rec="+recurse+"&nonempty="+nonemptydir+"&exc="+exclude+"&inc="+include+"&addtop="+addtopdir+"&path="+relpath;
1.1400 raeburn 2358: http.open("POST", url, true);
2359: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
2360: http.onreadystatechange = function() {
2361: if (http.readyState == 4 && http.status == 200) {
2362: var data = JSON.parse(http.responseText);
2363: var selelem;
2364: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
2365: if (Array.isArray(data.dirs)) {
2366: selelem = form.elements[dirsel];
2367: var i, numdirs = selelem.options.length -1;
2368: if (numdirs >=0) {
2369: for (i = numdirs; i >= 0; i--) {
2370: selelem.remove(i);
2371: }
2372: }
2373: var len = data.dirs.length;
2374: if (len) {
1.1402 raeburn 2375: selelem.options[selelem.options.length] = new Option('$se','');
1.1400 raeburn 2376: var j;
2377: for (j = 0; j < len; j++) {
2378: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
2379: }
2380: selelem.selectedIndex = 0;
2381: }
2382: if (!setfile) {
2383: if ((filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2384: selelem = form.elements[filesel];
2385: var j, numfiles = selelem.options.length -1;
2386: if (numfiles >=0) {
2387: for (j = numfiles; j >= 0; j--) {
2388: selelem.remove(j);
2389: }
2390: }
2391: if (selelem.options.length == 0) {
2392: selelem.options[selelem.options.length] = new Option('','');
2393: selelem.selectedIndex = 0;
2394: }
2395: }
2396: }
2397: }
2398: }
2399: if ((setfile) && (filesel != null) && (filesel != 'undefined') && (filesel != '')) {
2400: selelem = form.elements[filesel];
2401: var i, numfiles = selelem.options.length -1;
2402: if (numfiles >=0) {
2403: for (i = numfiles; i >= 0; i--) {
2404: selelem.remove(i);
2405: }
2406: }
2407: var x;
2408: for (x in data.files) {
2409: if (Array.isArray(data.files[x])) {
2410: if (data.files[x].length > 1) {
2411: selelem.options[selelem.options.length] = new Option('$se','');
2412: }
2413: var len = data.files[x].length;
2414: if (len) {
2415: var k;
2416: for (k = 0; k < len; k++) {
2417: selelem.options[selelem.options.length] = new Option(data.files[x][k],data.files[x][k]);
2418: }
2419: selelem.selectedIndex = 0;
2420: }
2421: }
2422: }
2423: if (selelem.options.length == 0) {
2424: selelem.options[selelem.options.length] = new Option('','');
2425: selelem.selectedIndex = 0;
2426: }
1.1248 raeburn 2427: }
2428: }
2429: }
1.1400 raeburn 2430: http.send(params);
1.1248 raeburn 2431: }
1.1400 raeburn 2432: END
1.1248 raeburn 2433: }
2434:
1.565 albertel 2435: =pod
2436:
1.256 matthew 2437: =head1 Excel and CSV file utility routines
2438:
2439: =cut
2440:
2441: ###############################################################
2442: ###############################################################
2443:
2444: =pod
2445:
1.1162 raeburn 2446: =over 4
2447:
1.648 raeburn 2448: =item * &csv_translate($text)
1.37 matthew 2449:
1.185 www 2450: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2451: format.
2452:
2453: =cut
2454:
1.180 matthew 2455: ###############################################################
2456: ###############################################################
1.37 matthew 2457: sub csv_translate {
2458: my $text = shift;
2459: $text =~ s/\"/\"\"/g;
1.209 albertel 2460: $text =~ s/\n/ /g;
1.37 matthew 2461: return $text;
2462: }
1.180 matthew 2463:
2464: ###############################################################
2465: ###############################################################
2466:
2467: =pod
2468:
1.648 raeburn 2469: =item * &define_excel_formats()
1.180 matthew 2470:
2471: Define some commonly used Excel cell formats.
2472:
2473: Currently supported formats:
2474:
2475: =over 4
2476:
2477: =item header
2478:
2479: =item bold
2480:
2481: =item h1
2482:
2483: =item h2
2484:
2485: =item h3
2486:
1.256 matthew 2487: =item h4
2488:
2489: =item i
2490:
1.180 matthew 2491: =item date
2492:
2493: =back
2494:
2495: Inputs: $workbook
2496:
2497: Returns: $format, a hash reference.
2498:
1.1057 foxr 2499:
1.180 matthew 2500: =cut
2501:
2502: ###############################################################
2503: ###############################################################
2504: sub define_excel_formats {
2505: my ($workbook) = @_;
2506: my $format;
2507: $format->{'header'} = $workbook->add_format(bold => 1,
2508: bottom => 1,
2509: align => 'center');
2510: $format->{'bold'} = $workbook->add_format(bold=>1);
2511: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2512: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2513: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2514: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2515: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2516: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2517: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2518: return $format;
2519: }
2520:
2521: ###############################################################
2522: ###############################################################
1.113 bowersj2 2523:
2524: =pod
2525:
1.648 raeburn 2526: =item * &create_workbook()
1.255 matthew 2527:
2528: Create an Excel worksheet. If it fails, output message on the
2529: request object and return undefs.
2530:
2531: Inputs: Apache request object
2532:
2533: Returns (undef) on failure,
2534: Excel worksheet object, scalar with filename, and formats
2535: from &Apache::loncommon::define_excel_formats on success
2536:
2537: =cut
2538:
2539: ###############################################################
2540: ###############################################################
2541: sub create_workbook {
2542: my ($r) = @_;
2543: #
2544: # Create the excel spreadsheet
2545: my $filename = '/prtspool/'.
1.258 albertel 2546: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2547: time.'_'.rand(1000000000).'.xls';
2548: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2549: if (! defined($workbook)) {
2550: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2551: $r->print(
2552: '<p class="LC_error">'
2553: .&mt('Problems occurred in creating the new Excel file.')
2554: .' '.&mt('This error has been logged.')
2555: .' '.&mt('Please alert your LON-CAPA administrator.')
2556: .'</p>'
2557: );
1.255 matthew 2558: return (undef);
2559: }
2560: #
1.1014 foxr 2561: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2562: #
2563: my $format = &Apache::loncommon::define_excel_formats($workbook);
2564: return ($workbook,$filename,$format);
2565: }
2566:
2567: ###############################################################
2568: ###############################################################
2569:
2570: =pod
2571:
1.648 raeburn 2572: =item * &create_text_file()
1.113 bowersj2 2573:
1.542 raeburn 2574: Create a file to write to and eventually make available to the user.
1.256 matthew 2575: If file creation fails, outputs an error message on the request object and
2576: return undefs.
1.113 bowersj2 2577:
1.256 matthew 2578: Inputs: Apache request object, and file suffix
1.113 bowersj2 2579:
1.256 matthew 2580: Returns (undef) on failure,
2581: Filehandle and filename on success.
1.113 bowersj2 2582:
2583: =cut
2584:
1.256 matthew 2585: ###############################################################
2586: ###############################################################
2587: sub create_text_file {
2588: my ($r,$suffix) = @_;
2589: if (! defined($suffix)) { $suffix = 'txt'; };
2590: my $fh;
2591: my $filename = '/prtspool/'.
1.258 albertel 2592: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2593: time.'_'.rand(1000000000).'.'.$suffix;
2594: $fh = Apache::File->new('>/home/httpd'.$filename);
2595: if (! defined($fh)) {
2596: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2597: $r->print(
2598: '<p class="LC_error">'
2599: .&mt('Problems occurred in creating the output file.')
2600: .' '.&mt('This error has been logged.')
2601: .' '.&mt('Please alert your LON-CAPA administrator.')
2602: .'</p>'
2603: );
1.113 bowersj2 2604: }
1.256 matthew 2605: return ($fh,$filename)
1.113 bowersj2 2606: }
2607:
2608:
1.256 matthew 2609: =pod
1.113 bowersj2 2610:
2611: =back
2612:
2613: =cut
1.37 matthew 2614:
2615: ###############################################################
1.33 matthew 2616: ## Home server <option> list generating code ##
2617: ###############################################################
1.35 matthew 2618:
1.169 www 2619: # ------------------------------------------
2620:
2621: sub domain_select {
1.1289 raeburn 2622: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2623: my @possdoms;
2624: if (ref($incdoms) eq 'ARRAY') {
2625: @possdoms = @{$incdoms};
2626: } else {
2627: @possdoms = &Apache::lonnet::all_domains();
2628: }
2629:
1.169 www 2630: my %domains=map {
1.514 albertel 2631: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2632: } @possdoms;
2633:
2634: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2635: foreach my $dom (@{$excdoms}) {
2636: delete($domains{$dom});
2637: }
2638: }
2639:
1.169 www 2640: if ($multiple) {
2641: $domains{''}=&mt('Any domain');
1.550 albertel 2642: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2643: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2644: } else {
1.550 albertel 2645: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2646: return &select_form($name,$value,\%domains);
1.169 www 2647: }
2648: }
2649:
1.282 albertel 2650: #-------------------------------------------
2651:
2652: =pod
2653:
1.519 raeburn 2654: =head1 Routines for form select boxes
2655:
2656: =over 4
2657:
1.648 raeburn 2658: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2659:
2660: Returns a string containing a <select> element int multiple mode
2661:
2662:
2663: Args:
2664: $name - name of the <select> element
1.506 raeburn 2665: $value - scalar or array ref of values that should already be selected
1.282 albertel 2666: $size - number of rows long the select element is
1.283 albertel 2667: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2668: (shown text should already have been &mt())
1.506 raeburn 2669: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2670:
1.282 albertel 2671: =cut
2672:
2673: #-------------------------------------------
1.169 www 2674: sub multiple_select_form {
1.284 albertel 2675: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2676: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2677: my $output='';
1.191 matthew 2678: if (! defined($size)) {
2679: $size = 4;
1.283 albertel 2680: if (scalar(keys(%$hash))<4) {
2681: $size = scalar(keys(%$hash));
1.191 matthew 2682: }
2683: }
1.734 bisitz 2684: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2685: my @order;
1.506 raeburn 2686: if (ref($order) eq 'ARRAY') {
2687: @order = @{$order};
2688: } else {
2689: @order = sort(keys(%$hash));
1.501 banghart 2690: }
2691: if (exists($$hash{'select_form_order'})) {
2692: @order = @{$$hash{'select_form_order'}};
2693: }
2694:
1.284 albertel 2695: foreach my $key (@order) {
1.356 albertel 2696: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2697: $output.='selected="selected" ' if ($selected{$key});
2698: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2699: }
2700: $output.="</select>\n";
2701: return $output;
2702: }
2703:
1.88 www 2704: #-------------------------------------------
2705:
2706: =pod
2707:
1.1254 raeburn 2708: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2709:
2710: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2711: allow a user to select options from a ref to a hash containing:
2712: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2713: a javascript onchange item, e.g., onchange="this.form.submit();".
2714: An optional arg -- $readonly -- if true will cause the select form
2715: to be disabled, e.g., for the case where an instructor has a section-
2716: specific role, and is viewing/modifying parameters.
1.970 raeburn 2717:
1.88 www 2718: See lonrights.pm for an example invocation and use.
2719:
2720: =cut
2721:
2722: #-------------------------------------------
2723: sub select_form {
1.1228 raeburn 2724: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2725: return unless (ref($hashref) eq 'HASH');
2726: if ($onchange) {
2727: $onchange = ' onchange="'.$onchange.'"';
2728: }
1.1228 raeburn 2729: my $disabled;
2730: if ($readonly) {
2731: $disabled = ' disabled="disabled"';
2732: }
2733: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2734: my @keys;
1.970 raeburn 2735: if (exists($hashref->{'select_form_order'})) {
2736: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2737: } else {
1.970 raeburn 2738: @keys=sort(keys(%{$hashref}));
1.128 albertel 2739: }
1.356 albertel 2740: foreach my $key (@keys) {
2741: $selectform.=
2742: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2743: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2744: ">".$hashref->{$key}."</option>\n";
1.88 www 2745: }
2746: $selectform.="</select>";
2747: return $selectform;
2748: }
2749:
1.475 www 2750: # For display filters
2751:
2752: sub display_filter {
1.1074 raeburn 2753: my ($context) = @_;
1.475 www 2754: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2755: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2756: my $phraseinput = 'hidden';
2757: my $includeinput = 'hidden';
2758: my ($checked,$includetypestext);
2759: if ($env{'form.displayfilter'} eq 'containing') {
2760: $phraseinput = 'text';
2761: if ($context eq 'parmslog') {
2762: $includeinput = 'checkbox';
2763: if ($env{'form.includetypes'}) {
2764: $checked = ' checked="checked"';
2765: }
2766: $includetypestext = &mt('Include parameter types');
2767: }
2768: } else {
2769: $includetypestext = ' ';
2770: }
2771: my ($additional,$secondid,$thirdid);
2772: if ($context eq 'parmslog') {
2773: $additional =
2774: '<label><input type="'.$includeinput.'" name="includetypes"'.
2775: $checked.' name="includetypes" value="1" id="includetypes" />'.
2776: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2777: '</label>';
2778: $secondid = 'includetypes';
2779: $thirdid = 'includetypestext';
2780: }
2781: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2782: '$secondid','$thirdid')";
2783: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.1403 raeburn 2784: &Apache::lonmeta::selectbox('show',$env{'form.show'},'',undef,
1.475 www 2785: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2786: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2787: &mt('Filter: [_1]',
1.477 www 2788: &select_form($env{'form.displayfilter'},
2789: 'displayfilter',
1.970 raeburn 2790: {'currentfolder' => 'Current folder/page',
1.477 www 2791: 'containing' => 'Containing phrase',
1.1074 raeburn 2792: 'none' => 'None'},$onchange)).' '.
2793: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2794: &HTML::Entities::encode($env{'form.containingphrase'}).
2795: '" />'.$additional;
2796: }
2797:
2798: sub display_filter_js {
2799: my $includetext = &mt('Include parameter types');
2800: return <<"ENDJS";
2801:
2802: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2803: var firstType = 'hidden';
2804: if (setter.options[setter.selectedIndex].value == 'containing') {
2805: firstType = 'text';
2806: }
2807: firstObject = document.getElementById(firstid);
2808: if (typeof(firstObject) == 'object') {
2809: if (firstObject.type != firstType) {
2810: changeInputType(firstObject,firstType);
2811: }
2812: }
2813: if (context == 'parmslog') {
2814: var secondType = 'hidden';
2815: if (firstType == 'text') {
2816: secondType = 'checkbox';
2817: }
2818: secondObject = document.getElementById(secondid);
2819: if (typeof(secondObject) == 'object') {
2820: if (secondObject.type != secondType) {
2821: changeInputType(secondObject,secondType);
2822: }
2823: }
2824: var textItem = document.getElementById(thirdid);
2825: var currtext = textItem.innerHTML;
2826: var newtext;
2827: if (firstType == 'text') {
2828: newtext = '$includetext';
2829: } else {
2830: newtext = ' ';
2831: }
2832: if (currtext != newtext) {
2833: textItem.innerHTML = newtext;
2834: }
2835: }
2836: return;
2837: }
2838:
2839: function changeInputType(oldObject,newType) {
2840: var newObject = document.createElement('input');
2841: newObject.type = newType;
2842: if (oldObject.size) {
2843: newObject.size = oldObject.size;
2844: }
2845: if (oldObject.value) {
2846: newObject.value = oldObject.value;
2847: }
2848: if (oldObject.name) {
2849: newObject.name = oldObject.name;
2850: }
2851: if (oldObject.id) {
2852: newObject.id = oldObject.id;
2853: }
2854: oldObject.parentNode.replaceChild(newObject,oldObject);
2855: return;
2856: }
2857:
2858: ENDJS
1.475 www 2859: }
2860:
1.167 www 2861: sub gradeleveldescription {
2862: my $gradelevel=shift;
2863: my %gradelevels=(0 => 'Not specified',
2864: 1 => 'Grade 1',
2865: 2 => 'Grade 2',
2866: 3 => 'Grade 3',
2867: 4 => 'Grade 4',
2868: 5 => 'Grade 5',
2869: 6 => 'Grade 6',
2870: 7 => 'Grade 7',
2871: 8 => 'Grade 8',
2872: 9 => 'Grade 9',
2873: 10 => 'Grade 10',
2874: 11 => 'Grade 11',
2875: 12 => 'Grade 12',
2876: 13 => 'Grade 13',
2877: 14 => '100 Level',
2878: 15 => '200 Level',
2879: 16 => '300 Level',
2880: 17 => '400 Level',
2881: 18 => 'Graduate Level');
2882: return &mt($gradelevels{$gradelevel});
2883: }
2884:
1.163 www 2885: sub select_level_form {
2886: my ($deflevel,$name)=@_;
2887: unless ($deflevel) { $deflevel=0; }
1.167 www 2888: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2889: for (my $i=0; $i<=18; $i++) {
2890: $selectform.="<option value=\"$i\" ".
1.253 albertel 2891: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2892: ">".&gradeleveldescription($i)."</option>\n";
2893: }
2894: $selectform.="</select>";
2895: return $selectform;
1.163 www 2896: }
1.167 www 2897:
1.35 matthew 2898: #-------------------------------------------
2899:
1.45 matthew 2900: =pod
2901:
1.1256 raeburn 2902: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2903:
2904: Returns a string containing a <select name='$name' size='1'> form to
2905: allow a user to select the domain to preform an operation in.
2906: See loncreateuser.pm for an example invocation and use.
2907:
1.90 www 2908: If the $includeempty flag is set, it also includes an empty choice ("no domain
2909: selected");
2910:
1.743 raeburn 2911: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2912:
1.910 raeburn 2913: 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.
2914:
1.1121 raeburn 2915: The optional $incdoms is a reference to an array of domains which will be the only available options.
2916:
2917: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2918:
1.1256 raeburn 2919: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2920:
1.35 matthew 2921: =cut
2922:
2923: #-------------------------------------------
1.34 matthew 2924: sub select_dom_form {
1.1256 raeburn 2925: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2926: if ($onchange) {
1.874 raeburn 2927: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2928: }
1.1256 raeburn 2929: if ($disabled) {
2930: $disabled = ' disabled="disabled"';
2931: }
1.1121 raeburn 2932: my (@domains,%exclude);
1.910 raeburn 2933: if (ref($incdoms) eq 'ARRAY') {
2934: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2935: } else {
2936: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2937: }
1.90 www 2938: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2939: if (ref($excdoms) eq 'ARRAY') {
2940: map { $exclude{$_} = 1; } @{$excdoms};
2941: }
1.1256 raeburn 2942: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2943: foreach my $dom (@domains) {
1.1121 raeburn 2944: next if ($exclude{$dom});
1.356 albertel 2945: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2946: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2947: if ($showdomdesc) {
2948: if ($dom ne '') {
2949: my $domdesc = &Apache::lonnet::domain($dom,'description');
2950: if ($domdesc ne '') {
2951: $selectdomain .= ' ('.$domdesc.')';
2952: }
2953: }
2954: }
2955: $selectdomain .= "</option>\n";
1.34 matthew 2956: }
2957: $selectdomain.="</select>";
2958: return $selectdomain;
2959: }
2960:
1.35 matthew 2961: #-------------------------------------------
2962:
1.45 matthew 2963: =pod
2964:
1.648 raeburn 2965: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2966:
1.586 raeburn 2967: input: 4 arguments (two required, two optional) -
2968: $domain - domain of new user
2969: $name - name of form element
2970: $default - Value of 'default' causes a default item to be first
2971: option, and selected by default.
2972: $hide - Value of 'hide' causes hiding of the name of the server,
2973: if 1 server found, or default, if 0 found.
1.594 raeburn 2974: output: returns 2 items:
1.586 raeburn 2975: (a) form element which contains either:
2976: (i) <select name="$name">
2977: <option value="$hostid1">$hostid $servers{$hostid}</option>
2978: <option value="$hostid2">$hostid $servers{$hostid}</option>
2979: </select>
2980: form item if there are multiple library servers in $domain, or
2981: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2982: if there is only one library server in $domain.
2983:
2984: (b) number of library servers found.
2985:
2986: See loncreateuser.pm for example of use.
1.35 matthew 2987:
2988: =cut
2989:
2990: #-------------------------------------------
1.586 raeburn 2991: sub home_server_form_item {
2992: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2993: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2994: my $result;
2995: my $numlib = keys(%servers);
2996: if ($numlib > 1) {
2997: $result .= '<select name="'.$name.'" />'."\n";
2998: if ($default) {
1.804 bisitz 2999: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 3000: '</option>'."\n";
3001: }
3002: foreach my $hostid (sort(keys(%servers))) {
3003: $result.= '<option value="'.$hostid.'">'.
3004: $hostid.' '.$servers{$hostid}."</option>\n";
3005: }
3006: $result .= '</select>'."\n";
3007: } elsif ($numlib == 1) {
3008: my $hostid;
3009: foreach my $item (keys(%servers)) {
3010: $hostid = $item;
3011: }
3012: $result .= '<input type="hidden" name="'.$name.'" value="'.
3013: $hostid.'" />';
3014: if (!$hide) {
3015: $result .= $hostid.' '.$servers{$hostid};
3016: }
3017: $result .= "\n";
3018: } elsif ($default) {
3019: $result .= '<input type="hidden" name="'.$name.
3020: '" value="default" />';
3021: if (!$hide) {
3022: $result .= &mt('default');
3023: }
3024: $result .= "\n";
1.33 matthew 3025: }
1.586 raeburn 3026: return ($result,$numlib);
1.33 matthew 3027: }
1.112 bowersj2 3028:
3029: =pod
3030:
1.534 albertel 3031: =back
3032:
1.112 bowersj2 3033: =cut
1.87 matthew 3034:
3035: ###############################################################
1.112 bowersj2 3036: ## Decoding User Agent ##
1.87 matthew 3037: ###############################################################
3038:
3039: =pod
3040:
1.112 bowersj2 3041: =head1 Decoding the User Agent
3042:
3043: =over 4
3044:
3045: =item * &decode_user_agent()
1.87 matthew 3046:
3047: Inputs: $r
3048:
3049: Outputs:
3050:
3051: =over 4
3052:
1.112 bowersj2 3053: =item * $httpbrowser
1.87 matthew 3054:
1.112 bowersj2 3055: =item * $clientbrowser
1.87 matthew 3056:
1.112 bowersj2 3057: =item * $clientversion
1.87 matthew 3058:
1.112 bowersj2 3059: =item * $clientmathml
1.87 matthew 3060:
1.112 bowersj2 3061: =item * $clientunicode
1.87 matthew 3062:
1.112 bowersj2 3063: =item * $clientos
1.87 matthew 3064:
1.1137 raeburn 3065: =item * $clientmobile
3066:
1.1141 raeburn 3067: =item * $clientinfo
3068:
1.1194 raeburn 3069: =item * $clientosversion
3070:
1.87 matthew 3071: =back
3072:
1.157 matthew 3073: =back
3074:
1.87 matthew 3075: =cut
3076:
3077: ###############################################################
3078: ###############################################################
3079: sub decode_user_agent {
1.247 albertel 3080: my ($r)=@_;
1.87 matthew 3081: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
3082: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
3083: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 3084: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 3085: my $clientbrowser='unknown';
3086: my $clientversion='0';
3087: my $clientmathml='';
3088: my $clientunicode='0';
1.1137 raeburn 3089: my $clientmobile=0;
1.1194 raeburn 3090: my $clientosversion='';
1.87 matthew 3091: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 3092: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 3093: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
3094: $clientbrowser=$bname;
3095: $httpbrowser=~/$vreg/i;
3096: $clientversion=$1;
3097: $clientmathml=($clientversion>=$minv);
3098: $clientunicode=($clientversion>=$univ);
3099: }
3100: }
3101: my $clientos='unknown';
1.1141 raeburn 3102: my $clientinfo;
1.87 matthew 3103: if (($httpbrowser=~/linux/i) ||
3104: ($httpbrowser=~/unix/i) ||
3105: ($httpbrowser=~/ux/i) ||
3106: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
3107: if (($httpbrowser=~/vax/i) ||
3108: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
3109: if ($httpbrowser=~/next/i) { $clientos='next'; }
3110: if (($httpbrowser=~/mac/i) ||
3111: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 3112: if ($httpbrowser=~/win/i) {
3113: $clientos='win';
3114: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
3115: $clientosversion = $1;
3116: }
3117: }
1.87 matthew 3118: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 3119: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
3120: $clientmobile=lc($1);
3121: }
1.1141 raeburn 3122: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
3123: $clientinfo = 'firefox-'.$1;
3124: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3125: $clientinfo = 'chromeframe-'.$1;
3126: }
1.87 matthew 3127: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3128: $clientunicode,$clientos,$clientmobile,$clientinfo,
3129: $clientosversion);
1.87 matthew 3130: }
3131:
1.32 matthew 3132: ###############################################################
3133: ## Authentication changing form generation subroutines ##
3134: ###############################################################
3135: ##
3136: ## All of the authform_xxxxxxx subroutines take their inputs in a
3137: ## hash, and have reasonable default values.
3138: ##
3139: ## formname = the name given in the <form> tag.
1.35 matthew 3140: #-------------------------------------------
3141:
1.45 matthew 3142: =pod
3143:
1.112 bowersj2 3144: =head1 Authentication Routines
3145:
3146: =over 4
3147:
1.648 raeburn 3148: =item * &authform_xxxxxx()
1.35 matthew 3149:
3150: The authform_xxxxxx subroutines provide javascript and html forms which
3151: handle some of the conveniences required for authentication forms.
3152: This is not an optimal method, but it works.
3153:
3154: =over 4
3155:
1.112 bowersj2 3156: =item * authform_header
1.35 matthew 3157:
1.112 bowersj2 3158: =item * authform_authorwarning
1.35 matthew 3159:
1.112 bowersj2 3160: =item * authform_nochange
1.35 matthew 3161:
1.112 bowersj2 3162: =item * authform_kerberos
1.35 matthew 3163:
1.112 bowersj2 3164: =item * authform_internal
1.35 matthew 3165:
1.112 bowersj2 3166: =item * authform_filesystem
1.35 matthew 3167:
1.1310 raeburn 3168: =item * authform_lti
3169:
1.35 matthew 3170: =back
3171:
1.648 raeburn 3172: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3173:
1.35 matthew 3174: =cut
3175:
3176: #-------------------------------------------
1.32 matthew 3177: sub authform_header{
3178: my %in = (
3179: formname => 'cu',
1.80 albertel 3180: kerb_def_dom => '',
1.32 matthew 3181: @_,
3182: );
3183: $in{'formname'} = 'document.' . $in{'formname'};
3184: my $result='';
1.80 albertel 3185:
3186: #---------------------------------------------- Code for upper case translation
3187: my $Javascript_toUpperCase;
3188: unless ($in{kerb_def_dom}) {
3189: $Javascript_toUpperCase =<<"END";
3190: switch (choice) {
3191: case 'krb': currentform.elements[choicearg].value =
3192: currentform.elements[choicearg].value.toUpperCase();
3193: break;
3194: default:
3195: }
3196: END
3197: } else {
3198: $Javascript_toUpperCase = "";
3199: }
3200:
1.165 raeburn 3201: my $radioval = "'nochange'";
1.591 raeburn 3202: if (defined($in{'curr_authtype'})) {
3203: if ($in{'curr_authtype'} ne '') {
3204: $radioval = "'".$in{'curr_authtype'}."arg'";
3205: }
1.174 matthew 3206: }
1.165 raeburn 3207: my $argfield = 'null';
1.591 raeburn 3208: if (defined($in{'mode'})) {
1.165 raeburn 3209: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3210: if (defined($in{'curr_autharg'})) {
3211: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3212: $argfield = "'$in{'curr_autharg'}'";
3213: }
3214: }
3215: }
3216: }
3217:
1.32 matthew 3218: $result.=<<"END";
3219: var current = new Object();
1.165 raeburn 3220: current.radiovalue = $radioval;
3221: current.argfield = $argfield;
1.32 matthew 3222:
3223: function changed_radio(choice,currentform) {
3224: var choicearg = choice + 'arg';
3225: // If a radio button in changed, we need to change the argfield
3226: if (current.radiovalue != choice) {
3227: current.radiovalue = choice;
3228: if (current.argfield != null) {
3229: currentform.elements[current.argfield].value = '';
3230: }
3231: if (choice == 'nochange') {
3232: current.argfield = null;
3233: } else {
3234: current.argfield = choicearg;
3235: switch(choice) {
3236: case 'krb':
3237: currentform.elements[current.argfield].value =
3238: "$in{'kerb_def_dom'}";
3239: break;
3240: default:
3241: break;
3242: }
3243: }
3244: }
3245: return;
3246: }
1.22 www 3247:
1.32 matthew 3248: function changed_text(choice,currentform) {
3249: var choicearg = choice + 'arg';
3250: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3251: $Javascript_toUpperCase
1.32 matthew 3252: // clear old field
3253: if ((current.argfield != choicearg) && (current.argfield != null)) {
3254: currentform.elements[current.argfield].value = '';
3255: }
3256: current.argfield = choicearg;
3257: }
3258: set_auth_radio_buttons(choice,currentform);
3259: return;
1.20 www 3260: }
1.32 matthew 3261:
3262: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3263: var numauthchoices = currentform.login.length;
3264: if (typeof numauthchoices == "undefined") {
3265: return;
3266: }
1.32 matthew 3267: var i=0;
1.986 raeburn 3268: while (i < numauthchoices) {
1.32 matthew 3269: if (currentform.login[i].value == newvalue) { break; }
3270: i++;
3271: }
1.986 raeburn 3272: if (i == numauthchoices) {
1.32 matthew 3273: return;
3274: }
3275: current.radiovalue = newvalue;
3276: currentform.login[i].checked = true;
3277: return;
3278: }
3279: END
3280: return $result;
3281: }
3282:
1.1106 raeburn 3283: sub authform_authorwarning {
1.32 matthew 3284: my $result='';
1.144 matthew 3285: $result='<i>'.
3286: &mt('As a general rule, only authors or co-authors should be '.
3287: 'filesystem authenticated '.
3288: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3289: return $result;
3290: }
3291:
1.1106 raeburn 3292: sub authform_nochange {
1.32 matthew 3293: my %in = (
3294: formname => 'document.cu',
3295: kerb_def_dom => 'MSU.EDU',
3296: @_,
3297: );
1.1106 raeburn 3298: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3299: my $result;
1.1104 raeburn 3300: if (!$authnum) {
1.1105 raeburn 3301: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3302: } else {
3303: $result = '<label>'.&mt('[_1] Do not change login data',
3304: '<input type="radio" name="login" value="nochange" '.
3305: 'checked="checked" onclick="'.
1.281 albertel 3306: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3307: '</label>';
1.586 raeburn 3308: }
1.32 matthew 3309: return $result;
3310: }
3311:
1.591 raeburn 3312: sub authform_kerberos {
1.32 matthew 3313: my %in = (
3314: formname => 'document.cu',
3315: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3316: kerb_def_auth => 'krb4',
1.32 matthew 3317: @_,
3318: );
1.586 raeburn 3319: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3320: $autharg,$jscall,$disabled);
1.1106 raeburn 3321: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3322: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3323: $check5 = ' checked="checked"';
1.80 albertel 3324: } else {
1.772 bisitz 3325: $check4 = ' checked="checked"';
1.80 albertel 3326: }
1.1259 raeburn 3327: if ($in{'readonly'}) {
3328: $disabled = ' disabled="disabled"';
3329: }
1.165 raeburn 3330: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3331: if (defined($in{'curr_authtype'})) {
3332: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3333: $krbcheck = ' checked="checked"';
1.623 raeburn 3334: if (defined($in{'mode'})) {
3335: if ($in{'mode'} eq 'modifyuser') {
3336: $krbcheck = '';
3337: }
3338: }
1.591 raeburn 3339: if (defined($in{'curr_kerb_ver'})) {
3340: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3341: $check5 = ' checked="checked"';
1.591 raeburn 3342: $check4 = '';
3343: } else {
1.772 bisitz 3344: $check4 = ' checked="checked"';
1.591 raeburn 3345: $check5 = '';
3346: }
1.586 raeburn 3347: }
1.591 raeburn 3348: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3349: $krbarg = $in{'curr_autharg'};
3350: }
1.586 raeburn 3351: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3352: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3353: $result =
3354: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3355: $in{'curr_autharg'},$krbver);
3356: } else {
3357: $result =
3358: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3359: }
3360: return $result;
3361: }
3362: }
3363: } else {
3364: if ($authnum == 1) {
1.784 bisitz 3365: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3366: }
3367: }
1.586 raeburn 3368: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3369: return;
1.587 raeburn 3370: } elsif ($authtype eq '') {
1.591 raeburn 3371: if (defined($in{'mode'})) {
1.587 raeburn 3372: if ($in{'mode'} eq 'modifycourse') {
3373: if ($authnum == 1) {
1.1259 raeburn 3374: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3375: }
3376: }
3377: }
1.586 raeburn 3378: }
3379: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3380: if ($authtype eq '') {
3381: $authtype = '<input type="radio" name="login" value="krb" '.
3382: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3383: $krbcheck.$disabled.' />';
1.586 raeburn 3384: }
3385: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3386: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3387: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3388: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3389: $in{'curr_authtype'} eq 'krb4')) {
3390: $result .= &mt
1.144 matthew 3391: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3392: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3393: '<label>'.$authtype,
1.281 albertel 3394: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3395: 'value="'.$krbarg.'" '.
1.1259 raeburn 3396: 'onchange="'.$jscall.'"'.$disabled.' />',
3397: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3398: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3399: '</label>');
1.586 raeburn 3400: } elsif ($can_assign{'krb4'}) {
3401: $result .= &mt
3402: ('[_1] Kerberos authenticated with domain [_2] '.
3403: '[_3] Version 4 [_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="4" />',
3409: '</label>');
3410: } elsif ($can_assign{'krb5'}) {
3411: $result .= &mt
3412: ('[_1] Kerberos authenticated with domain [_2] '.
3413: '[_3] Version 5 [_4]',
3414: '<label>'.$authtype,
3415: '</label><input type="text" size="10" name="krbarg" '.
3416: 'value="'.$krbarg.'" '.
1.1259 raeburn 3417: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3418: '<label><input type="hidden" name="krbver" value="5" />',
3419: '</label>');
3420: }
1.32 matthew 3421: return $result;
3422: }
3423:
1.1106 raeburn 3424: sub authform_internal {
1.586 raeburn 3425: my %in = (
1.32 matthew 3426: formname => 'document.cu',
3427: kerb_def_dom => 'MSU.EDU',
3428: @_,
3429: );
1.1259 raeburn 3430: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3431: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3432: if ($in{'readonly'}) {
3433: $disabled = ' disabled="disabled"';
3434: }
1.591 raeburn 3435: if (defined($in{'curr_authtype'})) {
3436: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3437: if ($can_assign{'int'}) {
1.772 bisitz 3438: $intcheck = 'checked="checked" ';
1.623 raeburn 3439: if (defined($in{'mode'})) {
3440: if ($in{'mode'} eq 'modifyuser') {
3441: $intcheck = '';
3442: }
3443: }
1.591 raeburn 3444: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3445: $intarg = $in{'curr_autharg'};
3446: }
3447: } else {
3448: $result = &mt('Currently internally authenticated.');
3449: return $result;
1.165 raeburn 3450: }
3451: }
1.586 raeburn 3452: } else {
3453: if ($authnum == 1) {
1.784 bisitz 3454: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3455: }
3456: }
3457: if (!$can_assign{'int'}) {
3458: return;
1.587 raeburn 3459: } elsif ($authtype eq '') {
1.591 raeburn 3460: if (defined($in{'mode'})) {
1.587 raeburn 3461: if ($in{'mode'} eq 'modifycourse') {
3462: if ($authnum == 1) {
1.1259 raeburn 3463: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3464: }
3465: }
3466: }
1.165 raeburn 3467: }
1.586 raeburn 3468: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3469: if ($authtype eq '') {
3470: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3471: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3472: }
1.605 bisitz 3473: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3474: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3475: $result = &mt
1.144 matthew 3476: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3477: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3478: $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 3479: return $result;
3480: }
3481:
1.1104 raeburn 3482: sub authform_local {
1.32 matthew 3483: my %in = (
3484: formname => 'document.cu',
3485: kerb_def_dom => 'MSU.EDU',
3486: @_,
3487: );
1.1259 raeburn 3488: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3489: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3490: if ($in{'readonly'}) {
3491: $disabled = ' disabled="disabled"';
3492: }
1.591 raeburn 3493: if (defined($in{'curr_authtype'})) {
3494: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3495: if ($can_assign{'loc'}) {
1.772 bisitz 3496: $loccheck = 'checked="checked" ';
1.623 raeburn 3497: if (defined($in{'mode'})) {
3498: if ($in{'mode'} eq 'modifyuser') {
3499: $loccheck = '';
3500: }
3501: }
1.591 raeburn 3502: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3503: $locarg = $in{'curr_autharg'};
3504: }
3505: } else {
3506: $result = &mt('Currently using local (institutional) authentication.');
3507: return $result;
1.165 raeburn 3508: }
3509: }
1.586 raeburn 3510: } else {
3511: if ($authnum == 1) {
1.784 bisitz 3512: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3513: }
3514: }
3515: if (!$can_assign{'loc'}) {
3516: return;
1.587 raeburn 3517: } elsif ($authtype eq '') {
1.591 raeburn 3518: if (defined($in{'mode'})) {
1.587 raeburn 3519: if ($in{'mode'} eq 'modifycourse') {
3520: if ($authnum == 1) {
1.1259 raeburn 3521: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3522: }
3523: }
3524: }
1.165 raeburn 3525: }
1.586 raeburn 3526: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3527: if ($authtype eq '') {
3528: $authtype = '<input type="radio" name="login" value="loc" '.
3529: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3530: $jscall.'"'.$disabled.' />';
1.586 raeburn 3531: }
3532: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3533: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3534: $result = &mt('[_1] Local Authentication with argument [_2]',
3535: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3536: return $result;
3537: }
3538:
1.1106 raeburn 3539: sub authform_filesystem {
1.32 matthew 3540: my %in = (
3541: formname => 'document.cu',
3542: kerb_def_dom => 'MSU.EDU',
3543: @_,
3544: );
1.1259 raeburn 3545: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3546: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3547: if ($in{'readonly'}) {
3548: $disabled = ' disabled="disabled"';
3549: }
1.591 raeburn 3550: if (defined($in{'curr_authtype'})) {
3551: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3552: if ($can_assign{'fsys'}) {
1.772 bisitz 3553: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3554: if (defined($in{'mode'})) {
3555: if ($in{'mode'} eq 'modifyuser') {
3556: $fsyscheck = '';
3557: }
3558: }
1.586 raeburn 3559: } else {
3560: $result = &mt('Currently Filesystem Authenticated.');
3561: return $result;
1.1259 raeburn 3562: }
1.586 raeburn 3563: }
3564: } else {
3565: if ($authnum == 1) {
1.784 bisitz 3566: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3567: }
3568: }
3569: if (!$can_assign{'fsys'}) {
3570: return;
1.587 raeburn 3571: } elsif ($authtype eq '') {
1.591 raeburn 3572: if (defined($in{'mode'})) {
1.587 raeburn 3573: if ($in{'mode'} eq 'modifycourse') {
3574: if ($authnum == 1) {
1.1259 raeburn 3575: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3576: }
3577: }
3578: }
1.586 raeburn 3579: }
3580: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3581: if ($authtype eq '') {
3582: $authtype = '<input type="radio" name="login" value="fsys" '.
3583: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3584: $jscall.'"'.$disabled.' />';
1.586 raeburn 3585: }
1.1310 raeburn 3586: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3587: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3588: $result = &mt
1.144 matthew 3589: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3590: '<label>'.$authtype,'</label>'.$autharg);
3591: return $result;
3592: }
3593:
3594: sub authform_lti {
3595: my %in = (
3596: formname => 'document.cu',
3597: kerb_def_dom => 'MSU.EDU',
3598: @_,
3599: );
3600: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3601: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3602: if ($in{'readonly'}) {
3603: $disabled = ' disabled="disabled"';
3604: }
3605: if (defined($in{'curr_authtype'})) {
3606: if ($in{'curr_authtype'} eq 'lti') {
3607: if ($can_assign{'lti'}) {
3608: $lticheck = 'checked="checked" ';
3609: if (defined($in{'mode'})) {
3610: if ($in{'mode'} eq 'modifyuser') {
3611: $lticheck = '';
3612: }
3613: }
3614: } else {
3615: $result = &mt('Currently LTI Authenticated.');
3616: return $result;
3617: }
3618: }
3619: } else {
3620: if ($authnum == 1) {
3621: $authtype = '<input type="hidden" name="login" value="lti" />';
3622: }
3623: }
3624: if (!$can_assign{'lti'}) {
3625: return;
3626: } elsif ($authtype eq '') {
3627: if (defined($in{'mode'})) {
3628: if ($in{'mode'} eq 'modifycourse') {
3629: if ($authnum == 1) {
3630: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3631: }
3632: }
3633: }
3634: }
3635: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3636: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3637: $authtype = '<input type="radio" name="login" value="lti" '.
3638: $lticheck.' onchange="'.$jscall.'" onclick="'.
3639: $jscall.'"'.$disabled.' />';
3640: }
3641: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3642: if ($authtype) {
3643: $result = &mt('[_1] LTI Authenticated',
3644: '<label>'.$authtype.'</label>'.$autharg);
3645: } else {
3646: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3647: $autharg;
3648: }
1.32 matthew 3649: return $result;
3650: }
3651:
1.586 raeburn 3652: sub get_assignable_auth {
3653: my ($dom) = @_;
3654: if ($dom eq '') {
3655: $dom = $env{'request.role.domain'};
3656: }
3657: my %can_assign = (
3658: krb4 => 1,
3659: krb5 => 1,
3660: int => 1,
3661: loc => 1,
1.1310 raeburn 3662: lti => 1,
1.586 raeburn 3663: );
3664: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3665: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3666: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3667: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3668: my $context;
3669: if ($env{'request.role'} =~ /^au/) {
3670: $context = 'author';
1.1259 raeburn 3671: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3672: $context = 'domain';
3673: } elsif ($env{'request.course.id'}) {
3674: $context = 'course';
3675: }
3676: if ($context) {
3677: if (ref($authhash->{$context}) eq 'HASH') {
3678: %can_assign = %{$authhash->{$context}};
3679: }
3680: }
3681: }
3682: }
3683: my $authnum = 0;
3684: foreach my $key (keys(%can_assign)) {
3685: if ($can_assign{$key}) {
3686: $authnum ++;
3687: }
3688: }
3689: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3690: $authnum --;
3691: }
3692: return ($authnum,%can_assign);
3693: }
3694:
1.1331 raeburn 3695: sub check_passwd_rules {
3696: my ($domain,$plainpass) = @_;
3697: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3698: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3699: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3700: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3701: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3702: if ($passwdconf{'min'} > $min) {
3703: $min = $passwdconf{'min'};
3704: }
1.1331 raeburn 3705: }
3706: if ($passwdconf{'max'} =~ /^\d+$/) {
3707: $max = $passwdconf{'max'};
3708: }
3709: @chars = @{$passwdconf{'chars'}};
3710: }
3711: if (($min) && (length($plainpass) < $min)) {
3712: push(@brokerule,'min');
3713: }
3714: if (($max) && (length($plainpass) > $max)) {
3715: push(@brokerule,'max');
3716: }
3717: if (@chars) {
3718: my %rules;
3719: map { $rules{$_} = 1; } @chars;
3720: if ($rules{'uc'}) {
3721: unless ($plainpass =~ /[A-Z]/) {
3722: push(@brokerule,'uc');
3723: }
3724: }
3725: if ($rules{'lc'}) {
1.1332 raeburn 3726: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3727: push(@brokerule,'lc');
3728: }
3729: }
3730: if ($rules{'num'}) {
3731: unless ($plainpass =~ /\d/) {
3732: push(@brokerule,'num');
3733: }
3734: }
3735: if ($rules{'spec'}) {
3736: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3737: push(@brokerule,'spec');
3738: }
3739: }
3740: }
3741: if (@brokerule) {
3742: my %rulenames = &Apache::lonlocal::texthash(
3743: uc => 'At least one upper case letter',
3744: lc => 'At least one lower case letter',
3745: num => 'At least one number',
3746: spec => 'At least one non-alphanumeric',
3747: );
3748: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3749: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3750: $rulenames{'num'} .= ': 0123456789';
3751: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3752: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3753: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3754: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1336 raeburn 3755: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1331 raeburn 3756: if (grep(/^$rule$/,@brokerule)) {
3757: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3758: }
3759: }
3760: $warning .= '</ul>';
3761: }
1.1332 raeburn 3762: if (wantarray) {
3763: return @brokerule;
3764: }
1.1331 raeburn 3765: return $warning;
3766: }
3767:
1.1376 raeburn 3768: sub passwd_validation_js {
1.1377 raeburn 3769: my ($currpasswdval,$domain,$context,$id) = @_;
3770: my (%passwdconf,$alertmsg);
3771: if ($context eq 'linkprot') {
3772: my %domconfig = &Apache::lonnet::get_dom('configuration',['ltisec'],$domain);
3773: if (ref($domconfig{'ltisec'}) eq 'HASH') {
3774: if (ref($domconfig{'ltisec'}{'rules'}) eq 'HASH') {
3775: %passwdconf = %{$domconfig{'ltisec'}{'rules'}};
3776: }
3777: }
3778: if ($id eq 'add') {
3779: $alertmsg = &mt('Secret for added launcher did not satisfy requirement(s):').'\n\n';
3780: } elsif ($id =~ /^\d+$/) {
3781: my $pos = $id+1;
3782: $alertmsg = &mt('Secret for launcher [_1] did not satisfy requirement(s):','#'.$pos).'\n\n';
3783: } else {
3784: $alertmsg = &mt('A secret did not satisfy requirement(s):').'\n\n';
3785: }
3786: } else {
3787: %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3788: $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
3789: }
1.1376 raeburn 3790: my ($min,$max,@chars,$numrules,$intargjs,%alert);
3791: $numrules = 0;
3792: $min = $Apache::lonnet::passwdmin;
3793: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3794: if ($passwdconf{'min'} =~ /^\d+$/) {
3795: if ($passwdconf{'min'} > $min) {
3796: $min = $passwdconf{'min'};
3797: }
3798: }
3799: if ($passwdconf{'max'} =~ /^\d+$/) {
3800: $max = $passwdconf{'max'};
3801: $numrules ++;
3802: }
3803: @chars = @{$passwdconf{'chars'}};
3804: if (@chars) {
3805: $numrules ++;
3806: }
3807: }
3808: if ($min > 0) {
3809: $numrules ++;
3810: }
3811: if (($min > 0) || ($max ne '') || (@chars > 0)) {
3812: if ($min) {
3813: $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
3814: }
3815: if ($max) {
3816: $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
3817: }
3818: my (@charalerts,@charrules);
3819: if (@chars) {
3820: if (grep(/^uc$/,@chars)) {
3821: push(@charalerts,&mt('contain at least one upper case letter'));
3822: push(@charrules,'uc');
3823: }
3824: if (grep(/^lc$/,@chars)) {
3825: push(@charalerts,&mt('contain at least one lower case letter'));
3826: push(@charrules,'lc');
3827: }
3828: if (grep(/^num$/,@chars)) {
3829: push(@charalerts,&mt('contain at least one number'));
3830: push(@charrules,'num');
3831: }
3832: if (grep(/^spec$/,@chars)) {
3833: push(@charalerts,&mt('contain at least one non-alphanumeric'));
3834: push(@charrules,'spec');
3835: }
3836: }
3837: $intargjs = qq| var rulesmsg = '';\n|.
3838: qq| var currpwval = $currpasswdval;\n|;
3839: if ($min) {
3840: $intargjs .= qq|
3841: if (currpwval.length < $min) {
3842: rulesmsg += ' - $alert{min}';
3843: }
3844: |;
3845: }
3846: if ($max) {
3847: $intargjs .= qq|
3848: if (currpwval.length > $max) {
3849: rulesmsg += ' - $alert{max}';
3850: }
3851: |;
3852: }
3853: if (@chars > 0) {
3854: my $charrulestr = '"'.join('","',@charrules).'"';
3855: my $charalertstr = '"'.join('","',@charalerts).'"';
3856: $intargjs .= qq| var brokerules = new Array();\n|.
3857: qq| var charrules = new Array($charrulestr);\n|.
3858: qq| var charalerts = new Array($charalertstr);\n|;
3859: my %rules;
3860: map { $rules{$_} = 1; } @chars;
3861: if ($rules{'uc'}) {
3862: $intargjs .= qq|
3863: var ucRegExp = /[A-Z]/;
3864: if (!ucRegExp.test(currpwval)) {
3865: brokerules.push('uc');
3866: }
3867: |;
3868: }
3869: if ($rules{'lc'}) {
3870: $intargjs .= qq|
3871: var lcRegExp = /[a-z]/;
3872: if (!lcRegExp.test(currpwval)) {
3873: brokerules.push('lc');
3874: }
3875: |;
3876: }
3877: if ($rules{'num'}) {
3878: $intargjs .= qq|
3879: var numRegExp = /[0-9]/;
3880: if (!numRegExp.test(currpwval)) {
3881: brokerules.push('num');
3882: }
3883: |;
3884: }
3885: if ($rules{'spec'}) {
3886: $intargjs .= q|
3887: var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\^\]_`{\|}~]/;
3888: if (!specRegExp.test(currpwval)) {
3889: brokerules.push('spec');
3890: }
3891: |;
3892: }
3893: $intargjs .= qq|
3894: if (brokerules.length > 0) {
3895: for (var i=0; i<brokerules.length; i++) {
3896: for (var j=0; j<charrules.length; j++) {
3897: if (brokerules[i] == charrules[j]) {
3898: rulesmsg += ' - '+charalerts[j]+'\\n';
3899: break;
3900: }
3901: }
3902: }
3903: }
3904: |;
3905: }
3906: $intargjs .= qq|
3907: if (rulesmsg != '') {
3908: rulesmsg = '$alertmsg'+rulesmsg;
3909: alert(rulesmsg);
3910: return false;
3911: }
3912: |;
3913: }
3914: return ($numrules,$intargjs);
3915: }
3916:
1.80 albertel 3917: ###############################################################
3918: ## Get Kerberos Defaults for Domain ##
3919: ###############################################################
3920: ##
3921: ## Returns default kerberos version and an associated argument
3922: ## as listed in file domain.tab. If not listed, provides
3923: ## appropriate default domain and kerberos version.
3924: ##
3925: #-------------------------------------------
3926:
3927: =pod
3928:
1.648 raeburn 3929: =item * &get_kerberos_defaults()
1.80 albertel 3930:
3931: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3932: version and domain. If not found, it defaults to version 4 and the
3933: domain of the server.
1.80 albertel 3934:
1.648 raeburn 3935: =over 4
3936:
1.80 albertel 3937: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3938:
1.648 raeburn 3939: =back
3940:
3941: =back
3942:
1.80 albertel 3943: =cut
3944:
3945: #-------------------------------------------
3946: sub get_kerberos_defaults {
3947: my $domain=shift;
1.641 raeburn 3948: my ($krbdef,$krbdefdom);
3949: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3950: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3951: $krbdef = $domdefaults{'auth_def'};
3952: $krbdefdom = $domdefaults{'auth_arg_def'};
3953: } else {
1.80 albertel 3954: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3955: my $krbdefdom=$1;
3956: $krbdefdom=~tr/a-z/A-Z/;
3957: $krbdef = "krb4";
3958: }
3959: return ($krbdef,$krbdefdom);
3960: }
1.112 bowersj2 3961:
1.32 matthew 3962:
1.46 matthew 3963: ###############################################################
3964: ## Thesaurus Functions ##
3965: ###############################################################
1.20 www 3966:
1.46 matthew 3967: =pod
1.20 www 3968:
1.112 bowersj2 3969: =head1 Thesaurus Functions
3970:
3971: =over 4
3972:
1.648 raeburn 3973: =item * &initialize_keywords()
1.46 matthew 3974:
3975: Initializes the package variable %Keywords if it is empty. Uses the
3976: package variable $thesaurus_db_file.
3977:
3978: =cut
3979:
3980: ###################################################
3981:
3982: sub initialize_keywords {
3983: return 1 if (scalar keys(%Keywords));
3984: # If we are here, %Keywords is empty, so fill it up
3985: # Make sure the file we need exists...
3986: if (! -e $thesaurus_db_file) {
3987: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3988: " failed because it does not exist");
3989: return 0;
3990: }
3991: # Set up the hash as a database
3992: my %thesaurus_db;
3993: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3994: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3995: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3996: $thesaurus_db_file);
3997: return 0;
3998: }
3999: # Get the average number of appearances of a word.
4000: my $avecount = $thesaurus_db{'average.count'};
4001: # Put keywords (those that appear > average) into %Keywords
4002: while (my ($word,$data)=each (%thesaurus_db)) {
4003: my ($count,undef) = split /:/,$data;
4004: $Keywords{$word}++ if ($count > $avecount);
4005: }
4006: untie %thesaurus_db;
4007: # Remove special values from %Keywords.
1.356 albertel 4008: foreach my $value ('total.count','average.count') {
4009: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 4010: }
1.46 matthew 4011: return 1;
4012: }
4013:
4014: ###################################################
4015:
4016: =pod
4017:
1.648 raeburn 4018: =item * &keyword($word)
1.46 matthew 4019:
4020: Returns true if $word is a keyword. A keyword is a word that appears more
4021: than the average number of times in the thesaurus database. Calls
4022: &initialize_keywords
4023:
4024: =cut
4025:
4026: ###################################################
1.20 www 4027:
4028: sub keyword {
1.46 matthew 4029: return if (!&initialize_keywords());
4030: my $word=lc(shift());
4031: $word=~s/\W//g;
4032: return exists($Keywords{$word});
1.20 www 4033: }
1.46 matthew 4034:
4035: ###############################################################
4036:
4037: =pod
1.20 www 4038:
1.648 raeburn 4039: =item * &get_related_words()
1.46 matthew 4040:
1.160 matthew 4041: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 4042: an array of words. If the keyword is not in the thesaurus, an empty array
4043: will be returned. The order of the words returned is determined by the
4044: database which holds them.
4045:
4046: Uses global $thesaurus_db_file.
4047:
1.1057 foxr 4048:
1.46 matthew 4049: =cut
4050:
4051: ###############################################################
4052: sub get_related_words {
4053: my $keyword = shift;
4054: my %thesaurus_db;
4055: if (! -e $thesaurus_db_file) {
4056: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
4057: "failed because the file does not exist");
4058: return ();
4059: }
4060: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 4061: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 4062: return ();
4063: }
4064: my @Words=();
1.429 www 4065: my $count=0;
1.46 matthew 4066: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 4067: # The first element is the number of times
4068: # the word appears. We do not need it now.
1.429 www 4069: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
4070: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
4071: my $threshold=$mostfrequentcount/10;
4072: foreach my $possibleword (@RelatedWords) {
4073: my ($word,$wordcount)=split(/\,/,$possibleword);
4074: if ($wordcount>$threshold) {
4075: push(@Words,$word);
4076: $count++;
4077: if ($count>10) { last; }
4078: }
1.20 www 4079: }
4080: }
1.46 matthew 4081: untie %thesaurus_db;
4082: return @Words;
1.14 harris41 4083: }
1.1090 foxr 4084: ###############################################################
4085: #
4086: # Spell checking
4087: #
4088:
4089: =pod
4090:
1.1142 raeburn 4091: =back
4092:
1.1090 foxr 4093: =head1 Spell checking
4094:
4095: =over 4
4096:
4097: =item * &check_spelling($wordlist $language)
4098:
4099: Takes a string containing words and feeds it to an external
4100: spellcheck program via a pipeline. Returns a string containing
4101: them mis-spelled words.
4102:
4103: Parameters:
4104:
4105: =over 4
4106:
4107: =item - $wordlist
4108:
4109: String that will be fed into the spellcheck program.
4110:
4111: =item - $language
4112:
4113: Language string that specifies the language for which the spell
4114: check will be performed.
4115:
4116: =back
4117:
4118: =back
4119:
4120: Note: This sub assumes that aspell is installed.
4121:
4122:
4123: =cut
4124:
1.46 matthew 4125:
1.1090 foxr 4126: sub check_spelling {
4127: my ($wordlist, $language) = @_;
1.1091 foxr 4128: my @misspellings;
4129:
4130: # Generate the speller and set the langauge.
4131: # if explicitly selected:
1.1090 foxr 4132:
1.1091 foxr 4133: my $speller = Text::Aspell->new;
1.1090 foxr 4134: if ($language) {
1.1091 foxr 4135: $speller->set_option('lang', $language);
1.1090 foxr 4136: }
4137:
1.1091 foxr 4138: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 4139:
1.1091 foxr 4140: my @words = split(/\s+/, $wordlist);
1.1090 foxr 4141:
1.1091 foxr 4142: foreach my $word (@words) {
4143: if(! $speller->check($word)) {
4144: push(@misspellings, $word);
1.1090 foxr 4145: }
4146: }
1.1091 foxr 4147: return join(' ', @misspellings);
4148:
1.1090 foxr 4149: }
4150:
1.61 www 4151: # -------------------------------------------------------------- Plaintext name
1.81 albertel 4152: =pod
4153:
1.112 bowersj2 4154: =head1 User Name Functions
4155:
4156: =over 4
4157:
1.648 raeburn 4158: =item * &plainname($uname,$udom,$first)
1.81 albertel 4159:
1.112 bowersj2 4160: Takes a users logon name and returns it as a string in
1.226 albertel 4161: "first middle last generation" form
4162: if $first is set to 'lastname' then it returns it as
4163: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 4164:
4165: =cut
1.61 www 4166:
1.295 www 4167:
1.81 albertel 4168: ###############################################################
1.61 www 4169: sub plainname {
1.226 albertel 4170: my ($uname,$udom,$first)=@_;
1.537 albertel 4171: return if (!defined($uname) || !defined($udom));
1.295 www 4172: my %names=&getnames($uname,$udom);
1.226 albertel 4173: my $name=&Apache::lonnet::format_name($names{'firstname'},
4174: $names{'middlename'},
4175: $names{'lastname'},
4176: $names{'generation'},$first);
4177: $name=~s/^\s+//;
1.62 www 4178: $name=~s/\s+$//;
4179: $name=~s/\s+/ /g;
1.353 albertel 4180: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 4181: return $name;
1.61 www 4182: }
1.66 www 4183:
4184: # -------------------------------------------------------------------- Nickname
1.81 albertel 4185: =pod
4186:
1.648 raeburn 4187: =item * &nickname($uname,$udom)
1.81 albertel 4188:
4189: Gets a users name and returns it as a string as
4190:
4191: ""nickname""
1.66 www 4192:
1.81 albertel 4193: if the user has a nickname or
4194:
4195: "first middle last generation"
4196:
4197: if the user does not
4198:
4199: =cut
1.66 www 4200:
4201: sub nickname {
4202: my ($uname,$udom)=@_;
1.537 albertel 4203: return if (!defined($uname) || !defined($udom));
1.295 www 4204: my %names=&getnames($uname,$udom);
1.68 albertel 4205: my $name=$names{'nickname'};
1.66 www 4206: if ($name) {
4207: $name='"'.$name.'"';
4208: } else {
4209: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
4210: $names{'lastname'}.' '.$names{'generation'};
4211: $name=~s/\s+$//;
4212: $name=~s/\s+/ /g;
4213: }
4214: return $name;
4215: }
4216:
1.295 www 4217: sub getnames {
4218: my ($uname,$udom)=@_;
1.537 albertel 4219: return if (!defined($uname) || !defined($udom));
1.433 albertel 4220: if ($udom eq 'public' && $uname eq 'public') {
4221: return ('lastname' => &mt('Public'));
4222: }
1.295 www 4223: my $id=$uname.':'.$udom;
4224: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
4225: if ($cached) {
4226: return %{$names};
4227: } else {
4228: my %loadnames=&Apache::lonnet::get('environment',
4229: ['firstname','middlename','lastname','generation','nickname'],
4230: $udom,$uname);
4231: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
4232: return %loadnames;
4233: }
4234: }
1.61 www 4235:
1.542 raeburn 4236: # -------------------------------------------------------------------- getemails
1.648 raeburn 4237:
1.542 raeburn 4238: =pod
4239:
1.648 raeburn 4240: =item * &getemails($uname,$udom)
1.542 raeburn 4241:
4242: Gets a user's email information and returns it as a hash with keys:
4243: notification, critnotification, permanentemail
4244:
4245: For notification and critnotification, values are comma-separated lists
1.648 raeburn 4246: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 4247:
1.648 raeburn 4248:
1.542 raeburn 4249: =cut
4250:
1.648 raeburn 4251:
1.466 albertel 4252: sub getemails {
4253: my ($uname,$udom)=@_;
4254: if ($udom eq 'public' && $uname eq 'public') {
4255: return;
4256: }
1.467 www 4257: if (!$udom) { $udom=$env{'user.domain'}; }
4258: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 4259: my $id=$uname.':'.$udom;
4260: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
4261: if ($cached) {
4262: return %{$names};
4263: } else {
4264: my %loadnames=&Apache::lonnet::get('environment',
4265: ['notification','critnotification',
4266: 'permanentemail'],
4267: $udom,$uname);
4268: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
4269: return %loadnames;
4270: }
4271: }
4272:
1.551 albertel 4273: sub flush_email_cache {
4274: my ($uname,$udom)=@_;
4275: if (!$udom) { $udom =$env{'user.domain'}; }
4276: if (!$uname) { $uname=$env{'user.name'}; }
4277: return if ($udom eq 'public' && $uname eq 'public');
4278: my $id=$uname.':'.$udom;
4279: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4280: }
4281:
1.728 raeburn 4282: # -------------------------------------------------------------------- getlangs
4283:
4284: =pod
4285:
4286: =item * &getlangs($uname,$udom)
4287:
4288: Gets a user's language preference and returns it as a hash with key:
4289: language.
4290:
4291: =cut
4292:
4293:
4294: sub getlangs {
4295: my ($uname,$udom) = @_;
4296: if (!$udom) { $udom =$env{'user.domain'}; }
4297: if (!$uname) { $uname=$env{'user.name'}; }
4298: my $id=$uname.':'.$udom;
4299: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4300: if ($cached) {
4301: return %{$langs};
4302: } else {
4303: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4304: $udom,$uname);
4305: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4306: return %loadlangs;
4307: }
4308: }
4309:
4310: sub flush_langs_cache {
4311: my ($uname,$udom)=@_;
4312: if (!$udom) { $udom =$env{'user.domain'}; }
4313: if (!$uname) { $uname=$env{'user.name'}; }
4314: return if ($udom eq 'public' && $uname eq 'public');
4315: my $id=$uname.':'.$udom;
4316: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4317: }
4318:
1.61 www 4319: # ------------------------------------------------------------------ Screenname
1.81 albertel 4320:
4321: =pod
4322:
1.648 raeburn 4323: =item * &screenname($uname,$udom)
1.81 albertel 4324:
4325: Gets a users screenname and returns it as a string
4326:
4327: =cut
1.61 www 4328:
4329: sub screenname {
4330: my ($uname,$udom)=@_;
1.258 albertel 4331: if ($uname eq $env{'user.name'} &&
4332: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4333: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4334: return $names{'screenname'};
1.62 www 4335: }
4336:
1.212 albertel 4337:
1.802 bisitz 4338: # ------------------------------------------------------------- Confirm Wrapper
4339: =pod
4340:
1.1142 raeburn 4341: =item * &confirmwrapper($message)
1.802 bisitz 4342:
4343: Wrap messages about completion of operation in box
4344:
4345: =cut
4346:
4347: sub confirmwrapper {
4348: my ($message)=@_;
4349: if ($message) {
4350: return "\n".'<div class="LC_confirm_box">'."\n"
4351: .$message."\n"
4352: .'</div>'."\n";
4353: } else {
4354: return $message;
4355: }
4356: }
4357:
1.62 www 4358: # ------------------------------------------------------------- Message Wrapper
4359:
4360: sub messagewrapper {
1.369 www 4361: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4362: return
1.441 albertel 4363: '<a href="/adm/email?compose=individual&'.
4364: 'recname='.$username.'&recdom='.$domain.
4365: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4366: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4367: }
1.802 bisitz 4368:
1.74 www 4369: # --------------------------------------------------------------- Notes Wrapper
4370:
4371: sub noteswrapper {
4372: my ($link,$un,$do)=@_;
4373: return
1.896 amueller 4374: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4375: }
1.802 bisitz 4376:
1.62 www 4377: # ------------------------------------------------------------- Aboutme Wrapper
4378:
4379: sub aboutmewrapper {
1.1070 raeburn 4380: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4381: if (!defined($username) && !defined($domain)) {
4382: return;
4383: }
1.1096 raeburn 4384: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4385: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4386: }
4387:
4388: # ------------------------------------------------------------ Syllabus Wrapper
4389:
4390: sub syllabuswrapper {
1.707 bisitz 4391: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4392: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4393: }
1.14 harris41 4394:
1.1397 raeburn 4395: # -----------------------------------------------------------------------------
4396:
1.1396 raeburn 4397: sub aboutme_on {
4398: my ($uname,$udom)=@_;
4399: unless ($uname) { $uname=$env{'user.name'}; }
4400: unless ($udom) { $udom=$env{'user.domain'}; }
4401: return if ($udom eq 'public' && $uname eq 'public');
4402: my $hashkey=$uname.':'.$udom;
4403: my ($aboutme,$cached)=&Apache::lonnet::is_cached_new('aboutme',$hashkey);
4404: if ($cached) {
4405: return $aboutme;
4406: }
4407: $aboutme = &Apache::lonnet::usertools_access($uname,$udom,'aboutme');
4408: &Apache::lonnet::do_cache_new('aboutme',$hashkey,$aboutme,3600);
4409: return $aboutme;
4410: }
4411:
4412: sub devalidate_aboutme_cache {
4413: my ($uname,$udom)=@_;
4414: if (!$udom) { $udom =$env{'user.domain'}; }
4415: if (!$uname) { $uname=$env{'user.name'}; }
4416: return if ($udom eq 'public' && $uname eq 'public');
4417: my $id=$uname.':'.$udom;
4418: &Apache::lonnet::devalidate_cache_new('aboutme',$id);
4419: }
4420:
1.208 matthew 4421: sub track_student_link {
1.887 raeburn 4422: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4423: my $link ="/adm/trackstudent?";
1.208 matthew 4424: my $title = 'View recent activity';
4425: if (defined($sname) && $sname !~ /^\s*$/ &&
4426: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4427: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4428: $title .= ' of this student';
1.268 albertel 4429: }
1.208 matthew 4430: if (defined($target) && $target !~ /^\s*$/) {
4431: $target = qq{target="$target"};
4432: } else {
4433: $target = '';
4434: }
1.268 albertel 4435: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4436: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4437: $title = &mt($title);
4438: $linktext = &mt($linktext);
1.448 albertel 4439: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4440: &help_open_topic('View_recent_activity');
1.208 matthew 4441: }
4442:
1.781 raeburn 4443: sub slot_reservations_link {
4444: my ($linktext,$sname,$sdom,$target) = @_;
4445: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4446: my $title = 'View slot reservation history';
4447: if (defined($sname) && $sname !~ /^\s*$/ &&
4448: defined($sdom) && $sdom !~ /^\s*$/) {
4449: $link .= "&uname=$sname&udom=$sdom";
4450: $title .= ' of this student';
4451: }
4452: if (defined($target) && $target !~ /^\s*$/) {
4453: $target = qq{target="$target"};
4454: } else {
4455: $target = '';
4456: }
4457: $title = &mt($title);
4458: $linktext = &mt($linktext);
4459: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4460: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4461:
4462: }
4463:
1.508 www 4464: # ===================================================== Display a student photo
4465:
4466:
1.509 albertel 4467: sub student_image_tag {
1.508 www 4468: my ($domain,$user)=@_;
4469: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4470: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4471: return '<img src="'.$imgsrc.'" align="right" />';
4472: } else {
4473: return '';
4474: }
4475: }
4476:
1.112 bowersj2 4477: =pod
4478:
4479: =back
4480:
4481: =head1 Access .tab File Data
4482:
4483: =over 4
4484:
1.648 raeburn 4485: =item * &languageids()
1.112 bowersj2 4486:
4487: returns list of all language ids
4488:
4489: =cut
4490:
1.14 harris41 4491: sub languageids {
1.16 harris41 4492: return sort(keys(%language));
1.14 harris41 4493: }
4494:
1.112 bowersj2 4495: =pod
4496:
1.648 raeburn 4497: =item * &languagedescription()
1.112 bowersj2 4498:
4499: returns description of a specified language id
4500:
4501: =cut
4502:
1.14 harris41 4503: sub languagedescription {
1.125 www 4504: my $code=shift;
4505: return ($supported_language{$code}?'* ':'').
4506: $language{$code}.
1.126 www 4507: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4508: }
4509:
1.1048 foxr 4510: =pod
4511:
4512: =item * &plainlanguagedescription
4513:
4514: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4515: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4516:
4517: =cut
4518:
1.145 www 4519: sub plainlanguagedescription {
4520: my $code=shift;
4521: return $language{$code};
4522: }
4523:
1.1048 foxr 4524: =pod
4525:
4526: =item * &supportedlanguagecode
4527:
4528: Returns the supported language code (e.g. sptutf maps to pt) given a language
4529: code.
4530:
4531: =cut
4532:
1.145 www 4533: sub supportedlanguagecode {
4534: my $code=shift;
4535: return $supported_language{$code};
1.97 www 4536: }
4537:
1.112 bowersj2 4538: =pod
4539:
1.1048 foxr 4540: =item * &latexlanguage()
4541:
4542: Given a language key code returns the correspondnig language to use
4543: to select the correct hyphenation on LaTeX printouts. This is undef if there
4544: is no supported hyphenation for the language code.
4545:
4546: =cut
4547:
4548: sub latexlanguage {
4549: my $code = shift;
4550: return $latex_language{$code};
4551: }
4552:
4553: =pod
4554:
4555: =item * &latexhyphenation()
4556:
4557: Same as above but what's supplied is the language as it might be stored
4558: in the metadata.
4559:
4560: =cut
4561:
4562: sub latexhyphenation {
4563: my $key = shift;
4564: return $latex_language_bykey{$key};
4565: }
4566:
4567: =pod
4568:
1.648 raeburn 4569: =item * ©rightids()
1.112 bowersj2 4570:
4571: returns list of all copyrights
4572:
4573: =cut
4574:
4575: sub copyrightids {
4576: return sort(keys(%cprtag));
4577: }
4578:
4579: =pod
4580:
1.648 raeburn 4581: =item * ©rightdescription()
1.112 bowersj2 4582:
4583: returns description of a specified copyright id
4584:
4585: =cut
4586:
4587: sub copyrightdescription {
1.166 www 4588: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4589: }
1.197 matthew 4590:
4591: =pod
4592:
1.648 raeburn 4593: =item * &source_copyrightids()
1.192 taceyjo1 4594:
4595: returns list of all source copyrights
4596:
4597: =cut
4598:
4599: sub source_copyrightids {
4600: return sort(keys(%scprtag));
4601: }
4602:
4603: =pod
4604:
1.648 raeburn 4605: =item * &source_copyrightdescription()
1.192 taceyjo1 4606:
4607: returns description of a specified source copyright id
4608:
4609: =cut
4610:
4611: sub source_copyrightdescription {
4612: return &mt($scprtag{shift(@_)});
4613: }
1.112 bowersj2 4614:
4615: =pod
4616:
1.648 raeburn 4617: =item * &filecategories()
1.112 bowersj2 4618:
4619: returns list of all file categories
4620:
4621: =cut
4622:
4623: sub filecategories {
4624: return sort(keys(%category_extensions));
4625: }
4626:
4627: =pod
4628:
1.648 raeburn 4629: =item * &filecategorytypes()
1.112 bowersj2 4630:
4631: returns list of file types belonging to a given file
4632: category
4633:
4634: =cut
4635:
4636: sub filecategorytypes {
1.356 albertel 4637: my ($cat) = @_;
1.1248 raeburn 4638: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4639: return @{$category_extensions{lc($cat)}};
4640: } else {
4641: return ();
4642: }
1.112 bowersj2 4643: }
4644:
4645: =pod
4646:
1.648 raeburn 4647: =item * &fileembstyle()
1.112 bowersj2 4648:
4649: returns embedding style for a specified file type
4650:
4651: =cut
4652:
4653: sub fileembstyle {
4654: return $fe{lc(shift(@_))};
1.169 www 4655: }
4656:
1.351 www 4657: sub filemimetype {
4658: return $fm{lc(shift(@_))};
4659: }
4660:
1.169 www 4661:
4662: sub filecategoryselect {
4663: my ($name,$value)=@_;
1.189 matthew 4664: return &select_form($value,$name,
1.970 raeburn 4665: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4666: }
4667:
4668: =pod
4669:
1.648 raeburn 4670: =item * &filedescription()
1.112 bowersj2 4671:
4672: returns description for a specified file type
4673:
4674: =cut
4675:
4676: sub filedescription {
1.188 matthew 4677: my $file_description = $fd{lc(shift())};
4678: $file_description =~ s:([\[\]]):~$1:g;
4679: return &mt($file_description);
1.112 bowersj2 4680: }
4681:
4682: =pod
4683:
1.648 raeburn 4684: =item * &filedescriptionex()
1.112 bowersj2 4685:
4686: returns description for a specified file type with
4687: extra formatting
4688:
4689: =cut
4690:
4691: sub filedescriptionex {
4692: my $ex=shift;
1.188 matthew 4693: my $file_description = $fd{lc($ex)};
4694: $file_description =~ s:([\[\]]):~$1:g;
4695: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4696: }
4697:
4698: # End of .tab access
4699: =pod
4700:
4701: =back
4702:
4703: =cut
4704:
4705: # ------------------------------------------------------------------ File Types
4706: sub fileextensions {
4707: return sort(keys(%fe));
4708: }
4709:
1.97 www 4710: # ----------------------------------------------------------- Display Languages
4711: # returns a hash with all desired display languages
4712: #
4713:
4714: sub display_languages {
4715: my %languages=();
1.695 raeburn 4716: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4717: $languages{$lang}=1;
1.97 www 4718: }
4719: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4720: if ($env{'form.displaylanguage'}) {
1.356 albertel 4721: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4722: $languages{$lang}=1;
1.97 www 4723: }
4724: }
4725: return %languages;
1.14 harris41 4726: }
4727:
1.582 albertel 4728: sub languages {
4729: my ($possible_langs) = @_;
1.695 raeburn 4730: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4731: if (!ref($possible_langs)) {
4732: if( wantarray ) {
4733: return @preferred_langs;
4734: } else {
4735: return $preferred_langs[0];
4736: }
4737: }
4738: my %possibilities = map { $_ => 1 } (@$possible_langs);
4739: my @preferred_possibilities;
4740: foreach my $preferred_lang (@preferred_langs) {
4741: if (exists($possibilities{$preferred_lang})) {
4742: push(@preferred_possibilities, $preferred_lang);
4743: }
4744: }
4745: if( wantarray ) {
4746: return @preferred_possibilities;
4747: }
4748: return $preferred_possibilities[0];
4749: }
4750:
1.742 raeburn 4751: sub user_lang {
4752: my ($touname,$toudom,$fromcid) = @_;
4753: my @userlangs;
4754: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4755: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4756: $env{'course.'.$fromcid.'.languages'}));
4757: } else {
4758: my %langhash = &getlangs($touname,$toudom);
4759: if ($langhash{'languages'} ne '') {
4760: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4761: } else {
4762: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4763: if ($domdefs{'lang_def'} ne '') {
4764: @userlangs = ($domdefs{'lang_def'});
4765: }
4766: }
4767: }
4768: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4769: my $user_lh = Apache::localize->get_handle(@languages);
4770: return $user_lh;
4771: }
4772:
4773:
1.112 bowersj2 4774: ###############################################################
4775: ## Student Answer Attempts ##
4776: ###############################################################
4777:
4778: =pod
4779:
4780: =head1 Alternate Problem Views
4781:
4782: =over 4
4783:
1.648 raeburn 4784: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4785: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4786:
4787: Return string with previous attempt on problem. Arguments:
4788:
4789: =over 4
4790:
4791: =item * $symb: Problem, including path
4792:
4793: =item * $username: username of the desired student
4794:
4795: =item * $domain: domain of the desired student
1.14 harris41 4796:
1.112 bowersj2 4797: =item * $course: Course ID
1.14 harris41 4798:
1.112 bowersj2 4799: =item * $getattempt: Leave blank for all attempts, otherwise put
4800: something
1.14 harris41 4801:
1.112 bowersj2 4802: =item * $regexp: if string matches this regexp, the string will be
4803: sent to $gradesub
1.14 harris41 4804:
1.112 bowersj2 4805: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4806:
1.1199 raeburn 4807: =item * $usec: section of the desired student
4808:
4809: =item * $identifier: counter for student (multiple students one problem) or
4810: problem (one student; whole sequence).
4811:
1.112 bowersj2 4812: =back
1.14 harris41 4813:
1.112 bowersj2 4814: The output string is a table containing all desired attempts, if any.
1.16 harris41 4815:
1.112 bowersj2 4816: =cut
1.1 albertel 4817:
4818: sub get_previous_attempt {
1.1199 raeburn 4819: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4820: my $prevattempts='';
1.43 ng 4821: no strict 'refs';
1.1 albertel 4822: if ($symb) {
1.3 albertel 4823: my (%returnhash)=
4824: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4825: if ($returnhash{'version'}) {
4826: my %lasthash=();
4827: my $version;
4828: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4829: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4830: if ($key =~ /\.rawrndseed$/) {
4831: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4832: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4833: } else {
4834: $lasthash{$key}=$returnhash{$version.':'.$key};
4835: }
1.19 harris41 4836: }
1.1 albertel 4837: }
1.596 albertel 4838: $prevattempts=&start_data_table().&start_data_table_header_row();
4839: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4840: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4841: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4842: foreach my $key (sort(keys(%lasthash))) {
4843: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4844: if ($#parts > 0) {
1.31 albertel 4845: my $data=$parts[-1];
1.989 raeburn 4846: next if ($data eq 'foilorder');
1.31 albertel 4847: pop(@parts);
1.1010 www 4848: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4849: if ($data eq 'type') {
4850: unless ($showsurv) {
4851: my $id = join(',',@parts);
4852: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4853: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4854: $lasthidden{$ign.'.'.$id} = 1;
4855: }
1.945 raeburn 4856: }
1.1199 raeburn 4857: if ($identifier ne '') {
4858: my $id = join(',',@parts);
4859: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4860: $domain,$username,$usec,undef,$course) =~ /^no/) {
4861: $hidestatus{$ign.'.'.$id} = 1;
4862: }
4863: }
4864: } elsif ($data eq 'regrader') {
4865: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4866: my $id = join(',',@parts);
4867: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4868: }
1.1010 www 4869: }
1.31 albertel 4870: } else {
1.41 ng 4871: if ($#parts == 0) {
4872: $prevattempts.='<th>'.$parts[0].'</th>';
4873: } else {
4874: $prevattempts.='<th>'.$ign.'</th>';
4875: }
1.31 albertel 4876: }
1.16 harris41 4877: }
1.596 albertel 4878: $prevattempts.=&end_data_table_header_row();
1.40 ng 4879: if ($getattempt eq '') {
1.1199 raeburn 4880: my (%solved,%resets,%probstatus);
1.1200 raeburn 4881: if (($identifier ne '') && (keys(%regraded) > 0)) {
4882: for ($version=1;$version<=$returnhash{'version'};$version++) {
4883: foreach my $id (keys(%regraded)) {
4884: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4885: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4886: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4887: push(@{$resets{$id}},$version);
1.1199 raeburn 4888: }
4889: }
4890: }
1.1200 raeburn 4891: }
4892: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4893: my (@hidden,@unsolved);
1.945 raeburn 4894: if (%typeparts) {
4895: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4896: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4897: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4898: push(@hidden,$id);
1.1199 raeburn 4899: } elsif ($identifier ne '') {
4900: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4901: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4902: ($hidestatus{$id})) {
1.1200 raeburn 4903: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4904: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4905: push(@{$solved{$id}},$version);
4906: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4907: (ref($solved{$id}) eq 'ARRAY')) {
4908: my $skip;
4909: if (ref($resets{$id}) eq 'ARRAY') {
4910: foreach my $reset (@{$resets{$id}}) {
4911: if ($reset > $solved{$id}[-1]) {
4912: $skip=1;
4913: last;
4914: }
4915: }
4916: }
4917: unless ($skip) {
4918: my ($ign,$partslist) = split(/\./,$id,2);
4919: push(@unsolved,$partslist);
4920: }
4921: }
4922: }
1.945 raeburn 4923: }
4924: }
4925: }
4926: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4927: '<td>'.&mt('Transaction [_1]',$version);
4928: if (@unsolved) {
4929: $prevattempts .= '<span class="LC_nobreak"><label>'.
4930: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4931: &mt('Hide').'</label></span>';
4932: }
4933: $prevattempts .= '</td>';
1.945 raeburn 4934: if (@hidden) {
4935: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4936: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4937: my $hide;
4938: foreach my $id (@hidden) {
4939: if ($key =~ /^\Q$id\E/) {
4940: $hide = 1;
4941: last;
4942: }
4943: }
4944: if ($hide) {
4945: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4946: if (($data eq 'award') || ($data eq 'awarddetail')) {
4947: my $value = &format_previous_attempt_value($key,
4948: $returnhash{$version.':'.$key});
1.1173 kruse 4949: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4950: } else {
4951: $prevattempts.='<td> </td>';
4952: }
4953: } else {
4954: if ($key =~ /\./) {
1.1212 raeburn 4955: my $value = $returnhash{$version.':'.$key};
4956: if ($key =~ /\.rndseed$/) {
4957: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4958: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4959: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4960: }
4961: }
4962: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4963: ' </td>';
1.945 raeburn 4964: } else {
4965: $prevattempts.='<td> </td>';
4966: }
4967: }
4968: }
4969: } else {
4970: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4971: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4972: my $value = $returnhash{$version.':'.$key};
4973: if ($key =~ /\.rndseed$/) {
4974: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4975: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4976: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4977: }
4978: }
4979: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4980: ' </td>';
1.945 raeburn 4981: }
4982: }
4983: $prevattempts.=&end_data_table_row();
1.40 ng 4984: }
1.1 albertel 4985: }
1.945 raeburn 4986: my @currhidden = keys(%lasthidden);
1.596 albertel 4987: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4988: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4989: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4990: if (%typeparts) {
4991: my $hidden;
4992: foreach my $id (@currhidden) {
4993: if ($key =~ /^\Q$id\E/) {
4994: $hidden = 1;
4995: last;
4996: }
4997: }
4998: if ($hidden) {
4999: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
5000: if (($data eq 'award') || ($data eq 'awarddetail')) {
5001: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5002: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5003: $value = &$gradesub($value);
5004: }
1.1173 kruse 5005: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 5006: } else {
5007: $prevattempts.='<td> </td>';
5008: }
5009: } else {
5010: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5011: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5012: $value = &$gradesub($value);
5013: }
1.1173 kruse 5014: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5015: }
5016: } else {
5017: my $value = &format_previous_attempt_value($key,$lasthash{$key});
5018: if ($key =~/$regexp$/ && (defined &$gradesub)) {
5019: $value = &$gradesub($value);
5020: }
1.1173 kruse 5021: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 5022: }
1.16 harris41 5023: }
1.596 albertel 5024: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 5025: } else {
1.1305 raeburn 5026: my $msg;
5027: if ($symb =~ /ext\.tool$/) {
5028: $msg = &mt('No grade passed back.');
5029: } else {
5030: $msg = &mt('Nothing submitted - no attempts.');
5031: }
1.596 albertel 5032: $prevattempts=
5033: &start_data_table().&start_data_table_row().
1.1305 raeburn 5034: '<td>'.$msg.'</td>'.
1.596 albertel 5035: &end_data_table_row().&end_data_table();
1.1 albertel 5036: }
5037: } else {
1.596 albertel 5038: $prevattempts=
5039: &start_data_table().&start_data_table_row().
5040: '<td>'.&mt('No data.').'</td>'.
5041: &end_data_table_row().&end_data_table();
1.1 albertel 5042: }
1.10 albertel 5043: }
5044:
1.581 albertel 5045: sub format_previous_attempt_value {
5046: my ($key,$value) = @_;
1.1011 www 5047: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 5048: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 5049: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 5050: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 5051: } elsif ($key =~ /answerstring$/) {
5052: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 5053: my @answer = %answers;
5054: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 5055: my @anskeys = sort(keys(%answers));
5056: if (@anskeys == 1) {
5057: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 5058: if ($answer =~ m{\0}) {
5059: $answer =~ s{\0}{,}g;
1.988 raeburn 5060: }
5061: my $tag_internal_answer_name = 'INTERNAL';
5062: if ($anskeys[0] eq $tag_internal_answer_name) {
5063: $value = $answer;
5064: } else {
5065: $value = $anskeys[0].'='.$answer;
5066: }
5067: } else {
5068: foreach my $ans (@anskeys) {
5069: my $answer = $answers{$ans};
1.1001 raeburn 5070: if ($answer =~ m{\0}) {
5071: $answer =~ s{\0}{,}g;
1.988 raeburn 5072: }
5073: $value .= $ans.'='.$answer.'<br />';;
5074: }
5075: }
1.581 albertel 5076: } else {
1.1173 kruse 5077: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 5078: }
5079: return $value;
5080: }
5081:
5082:
1.107 albertel 5083: sub relative_to_absolute {
5084: my ($url,$output)=@_;
5085: my $parser=HTML::TokeParser->new(\$output);
5086: my $token;
5087: my $thisdir=$url;
5088: my @rlinks=();
5089: while ($token=$parser->get_token) {
5090: if ($token->[0] eq 'S') {
5091: if ($token->[1] eq 'a') {
5092: if ($token->[2]->{'href'}) {
5093: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
5094: }
5095: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
5096: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
5097: } elsif ($token->[1] eq 'base') {
5098: $thisdir=$token->[2]->{'href'};
5099: }
5100: }
5101: }
5102: $thisdir=~s-/[^/]*$--;
1.356 albertel 5103: foreach my $link (@rlinks) {
1.726 raeburn 5104: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 5105: ($link=~/^\//) ||
5106: ($link=~/^javascript:/i) ||
5107: ($link=~/^mailto:/i) ||
5108: ($link=~/^\#/)) {
5109: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
5110: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 5111: }
5112: }
5113: # -------------------------------------------------- Deal with Applet codebases
5114: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
5115: return $output;
5116: }
5117:
1.112 bowersj2 5118: =pod
5119:
1.648 raeburn 5120: =item * &get_student_view()
1.112 bowersj2 5121:
5122: show a snapshot of what student was looking at
5123:
5124: =cut
5125:
1.10 albertel 5126: sub get_student_view {
1.186 albertel 5127: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 5128: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5129: my (%form);
1.10 albertel 5130: my @elements=('symb','courseid','domain','username');
5131: foreach my $element (@elements) {
1.186 albertel 5132: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5133: }
1.186 albertel 5134: if (defined($moreenv)) {
5135: %form=(%form,%{$moreenv});
5136: }
1.236 albertel 5137: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 5138: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 5139: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
5140: $feedurl =~ s{^/adm/wrapper}{};
5141: }
1.650 www 5142: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 5143: $userview=~s/\<body[^\>]*\>//gi;
5144: $userview=~s/\<\/body\>//gi;
5145: $userview=~s/\<html\>//gi;
5146: $userview=~s/\<\/html\>//gi;
5147: $userview=~s/\<head\>//gi;
5148: $userview=~s/\<\/head\>//gi;
5149: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 5150: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 5151: if (wantarray) {
5152: return ($userview,$response);
5153: } else {
5154: return $userview;
5155: }
5156: }
5157:
5158: sub get_student_view_with_retries {
5159: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
5160:
5161: my $ok = 0; # True if we got a good response.
5162: my $content;
5163: my $response;
5164:
5165: # Try to get the student_view done. within the retries count:
5166:
5167: do {
5168: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
5169: $ok = $response->is_success;
5170: if (!$ok) {
5171: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
5172: }
5173: $retries--;
5174: } while (!$ok && ($retries > 0));
5175:
5176: if (!$ok) {
5177: $content = ''; # On error return an empty content.
5178: }
1.651 www 5179: if (wantarray) {
5180: return ($content, $response);
5181: } else {
5182: return $content;
5183: }
1.11 albertel 5184: }
5185:
1.1349 raeburn 5186: sub css_links {
5187: my ($currsymb,$level) = @_;
5188: my ($links,@symbs,%cssrefs,%httpref);
5189: if ($level eq 'map') {
5190: my $navmap = Apache::lonnavmaps::navmap->new();
5191: if (ref($navmap)) {
5192: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
5193: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
5194: foreach my $res (@resources) {
5195: if (ref($res) && $res->symb()) {
5196: push(@symbs,$res->symb());
5197: }
5198: }
5199: }
5200: } else {
5201: @symbs = ($currsymb);
5202: }
5203: foreach my $symb (@symbs) {
5204: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
5205: if ($css_href =~ /\S/) {
5206: unless ($css_href =~ m{https?://}) {
5207: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
5208: my $proburl = &Apache::lonnet::clutter($url);
5209: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
5210: unless ($css_href =~ m{^/}) {
5211: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
5212: }
5213: if ($css_href =~ m{^/(res|uploaded)/}) {
5214: unless (($httpref{'httpref.'.$css_href}) ||
5215: (&Apache::lonnet::is_on_map($css_href))) {
5216: my $thisurl = $proburl;
5217: if ($env{'httpref.'.$proburl}) {
5218: $thisurl = $env{'httpref.'.$proburl};
5219: }
5220: $httpref{'httpref.'.$css_href} = $thisurl;
5221: }
5222: }
5223: }
5224: $cssrefs{$css_href} = 1;
5225: }
5226: }
5227: if (keys(%httpref)) {
5228: &Apache::lonnet::appenv(\%httpref);
5229: }
5230: if (keys(%cssrefs)) {
5231: foreach my $css_href (keys(%cssrefs)) {
5232: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
5233: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
5234: }
5235: }
5236: return $links;
5237: }
5238:
1.112 bowersj2 5239: =pod
5240:
1.648 raeburn 5241: =item * &get_student_answers()
1.112 bowersj2 5242:
5243: show a snapshot of how student was answering problem
5244:
5245: =cut
5246:
1.11 albertel 5247: sub get_student_answers {
1.100 sakharuk 5248: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 5249: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 5250: my (%moreenv);
1.11 albertel 5251: my @elements=('symb','courseid','domain','username');
5252: foreach my $element (@elements) {
1.186 albertel 5253: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 5254: }
1.186 albertel 5255: $moreenv{'grade_target'}='answer';
5256: %moreenv=(%form,%moreenv);
1.497 raeburn 5257: $feedurl = &Apache::lonnet::clutter($feedurl);
5258: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 5259: return $userview;
1.1 albertel 5260: }
1.116 albertel 5261:
5262: =pod
5263:
5264: =item * &submlink()
5265:
1.242 albertel 5266: Inputs: $text $uname $udom $symb $target
1.116 albertel 5267:
5268: Returns: A link to grades.pm such as to see the SUBM view of a student
5269:
5270: =cut
5271:
5272: ###############################################
5273: sub submlink {
1.242 albertel 5274: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 5275: if (!($uname && $udom)) {
5276: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5277: &Apache::lonnet::whichuser($symb);
1.116 albertel 5278: if (!$symb) { $symb=$cursymb; }
5279: }
1.254 matthew 5280: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5281: $symb=&escape($symb);
1.960 bisitz 5282: if ($target) { $target=" target=\"$target\""; }
5283: return
5284: '<a href="/adm/grades?command=submission'.
5285: '&symb='.$symb.
5286: '&student='.$uname.
5287: '&userdom='.$udom.'"'.
5288: $target.'>'.$text.'</a>';
1.242 albertel 5289: }
5290: ##############################################
5291:
5292: =pod
5293:
5294: =item * &pgrdlink()
5295:
5296: Inputs: $text $uname $udom $symb $target
5297:
5298: Returns: A link to grades.pm such as to see the PGRD view of a student
5299:
5300: =cut
5301:
5302: ###############################################
5303: sub pgrdlink {
5304: my $link=&submlink(@_);
5305: $link=~s/(&command=submission)/$1&showgrading=yes/;
5306: return $link;
5307: }
5308: ##############################################
5309:
5310: =pod
5311:
5312: =item * &pprmlink()
5313:
5314: Inputs: $text $uname $udom $symb $target
5315:
5316: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 5317: student and a specific resource
1.242 albertel 5318:
5319: =cut
5320:
5321: ###############################################
5322: sub pprmlink {
5323: my ($text,$uname,$udom,$symb,$target)=@_;
5324: if (!($uname && $udom)) {
5325: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5326: &Apache::lonnet::whichuser($symb);
1.242 albertel 5327: if (!$symb) { $symb=$cursymb; }
5328: }
1.254 matthew 5329: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5330: $symb=&escape($symb);
1.242 albertel 5331: if ($target) { $target="target=\"$target\""; }
1.595 albertel 5332: return '<a href="/adm/parmset?command=set&'.
5333: 'symb='.$symb.'&uname='.$uname.
5334: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 5335: }
5336: ##############################################
1.37 matthew 5337:
1.112 bowersj2 5338: =pod
5339:
5340: =back
5341:
5342: =cut
5343:
1.37 matthew 5344: ###############################################
1.51 www 5345:
5346:
5347: sub timehash {
1.687 raeburn 5348: my ($thistime) = @_;
5349: my $timezone = &Apache::lonlocal::gettimezone();
5350: my $dt = DateTime->from_epoch(epoch => $thistime)
5351: ->set_time_zone($timezone);
5352: my $wday = $dt->day_of_week();
5353: if ($wday == 7) { $wday = 0; }
5354: return ( 'second' => $dt->second(),
5355: 'minute' => $dt->minute(),
5356: 'hour' => $dt->hour(),
5357: 'day' => $dt->day_of_month(),
5358: 'month' => $dt->month(),
5359: 'year' => $dt->year(),
5360: 'weekday' => $wday,
5361: 'dayyear' => $dt->day_of_year(),
5362: 'dlsav' => $dt->is_dst() );
1.51 www 5363: }
5364:
1.370 www 5365: sub utc_string {
5366: my ($date)=@_;
1.371 www 5367: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5368: }
5369:
1.51 www 5370: sub maketime {
5371: my %th=@_;
1.687 raeburn 5372: my ($epoch_time,$timezone,$dt);
5373: $timezone = &Apache::lonlocal::gettimezone();
5374: eval {
5375: $dt = DateTime->new( year => $th{'year'},
5376: month => $th{'month'},
5377: day => $th{'day'},
5378: hour => $th{'hour'},
5379: minute => $th{'minute'},
5380: second => $th{'second'},
5381: time_zone => $timezone,
5382: );
5383: };
5384: if (!$@) {
5385: $epoch_time = $dt->epoch;
5386: if ($epoch_time) {
5387: return $epoch_time;
5388: }
5389: }
1.51 www 5390: return POSIX::mktime(
5391: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5392: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5393: }
5394:
5395: #########################################
1.51 www 5396:
5397: sub findallcourses {
1.482 raeburn 5398: my ($roles,$uname,$udom) = @_;
1.355 albertel 5399: my %roles;
5400: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5401: my %courses;
1.51 www 5402: my $now=time;
1.482 raeburn 5403: if (!defined($uname)) {
5404: $uname = $env{'user.name'};
5405: }
5406: if (!defined($udom)) {
5407: $udom = $env{'user.domain'};
5408: }
5409: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5410: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5411: if (!%roles) {
5412: %roles = (
5413: cc => 1,
1.907 raeburn 5414: co => 1,
1.482 raeburn 5415: in => 1,
5416: ep => 1,
5417: ta => 1,
5418: cr => 1,
5419: st => 1,
5420: );
5421: }
5422: foreach my $entry (keys(%roleshash)) {
5423: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5424: if ($trole =~ /^cr/) {
5425: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5426: } else {
5427: next if (!exists($roles{$trole}));
5428: }
5429: if ($tend) {
5430: next if ($tend < $now);
5431: }
5432: if ($tstart) {
5433: next if ($tstart > $now);
5434: }
1.1058 raeburn 5435: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5436: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5437: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5438: if ($secpart eq '') {
5439: ($cnum,$role) = split(/_/,$cnumpart);
5440: $sec = 'none';
1.1058 raeburn 5441: $value .= $cnum.'/';
1.482 raeburn 5442: } else {
5443: $cnum = $cnumpart;
5444: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5445: $value .= $cnum.'/'.$sec;
5446: }
5447: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5448: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5449: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5450: }
5451: } else {
5452: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5453: }
1.482 raeburn 5454: }
5455: } else {
5456: foreach my $key (keys(%env)) {
1.483 albertel 5457: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5458: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5459: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5460: next if ($role eq 'ca' || $role eq 'aa');
5461: next if (%roles && !exists($roles{$role}));
5462: my ($starttime,$endtime)=split(/\./,$env{$key});
5463: my $active=1;
5464: if ($starttime) {
5465: if ($now<$starttime) { $active=0; }
5466: }
5467: if ($endtime) {
5468: if ($now>$endtime) { $active=0; }
5469: }
5470: if ($active) {
1.1058 raeburn 5471: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5472: if ($sec eq '') {
5473: $sec = 'none';
1.1058 raeburn 5474: } else {
5475: $value .= $sec;
5476: }
5477: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5478: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5479: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5480: }
5481: } else {
5482: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5483: }
1.474 raeburn 5484: }
5485: }
1.51 www 5486: }
5487: }
1.474 raeburn 5488: return %courses;
1.51 www 5489: }
1.37 matthew 5490:
1.54 www 5491: ###############################################
1.474 raeburn 5492:
5493: sub blockcheck {
1.1372 raeburn 5494: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
5495: unless (($activity eq 'docs') || ($activity eq 'reinit') || ($activity eq 'alert')) {
5496: my ($has_evb,$check_ipaccess);
5497: my $dom = $env{'user.domain'};
5498: if ($env{'request.course.id'}) {
5499: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5500: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5501: my $checkrole = "cm./$cdom/$cnum";
5502: my $sec = $env{'request.course.sec'};
5503: if ($sec ne '') {
5504: $checkrole .= "/$sec";
5505: }
5506: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
5507: ($env{'request.role'} !~ /^st/)) {
5508: $has_evb = 1;
5509: }
5510: unless ($has_evb) {
5511: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
5512: ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
5513: if ($udom eq $cdom) {
5514: $check_ipaccess = 1;
5515: }
5516: }
5517: }
1.1375 raeburn 5518: } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
5519: ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
5520: my $checkrole;
5521: if ($env{'request.role.domain'} eq '') {
5522: $checkrole = "cm./$env{'user.domain'}/";
5523: } else {
5524: $checkrole = "cm./$env{'request.role.domain'}/";
5525: }
5526: if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
5527: $has_evb = 1;
5528: }
1.1372 raeburn 5529: }
5530: unless ($has_evb || $check_ipaccess) {
5531: my @machinedoms = &Apache::lonnet::current_machine_domains();
5532: if (($dom eq 'public') && ($activity eq 'port')) {
5533: $dom = $udom;
5534: }
5535: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
5536: $check_ipaccess = 1;
5537: } else {
5538: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
5539: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
5540: my $prim = &Apache::lonnet::domain($dom,'primary');
5541: my $intdom = &Apache::lonnet::internet_dom($prim);
5542: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
5543: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5544: $check_ipaccess = 1;
5545: }
5546: }
5547: }
5548: }
5549: if ($check_ipaccess) {
5550: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
5551: unless (defined($cached)) {
5552: my %domconfig =
5553: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
5554: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
5555: }
5556: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
5557: foreach my $id (keys(%{$ipaccessref})) {
5558: if (ref($ipaccessref->{$id}) eq 'HASH') {
5559: my $range = $ipaccessref->{$id}->{'ip'};
5560: if ($range) {
5561: if (&Apache::lonnet::ip_match($clientip,$range)) {
5562: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
5563: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
5564: return ('','','',$id,$dom);
5565: last;
5566: }
5567: }
5568: }
5569: }
5570: }
5571: }
5572: }
5573: }
1.1373 raeburn 5574: if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5575: return ();
5576: }
1.1372 raeburn 5577: }
1.1189 raeburn 5578: if (defined($udom) && defined($uname)) {
5579: # If uname and udom are for a course, check for blocks in the course.
5580: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5581: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5582: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 5583: return ($startblock,$endblock,$triggerblock);
5584: }
5585: } else {
1.490 raeburn 5586: $udom = $env{'user.domain'};
5587: $uname = $env{'user.name'};
5588: }
5589:
1.502 raeburn 5590: my $startblock = 0;
5591: my $endblock = 0;
1.1062 raeburn 5592: my $triggerblock = '';
1.1373 raeburn 5593: my %live_courses;
5594: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
5595: %live_courses = &findallcourses(undef,$uname,$udom);
5596: }
1.474 raeburn 5597:
1.490 raeburn 5598: # If uname is for a user, and activity is course-specific, i.e.,
5599: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5600:
1.490 raeburn 5601: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5602: $activity eq 'groups' || $activity eq 'printout' ||
1.1346 raeburn 5603: $activity eq 'search' || $activity eq 'reinit' ||
5604: $activity eq 'alert') &&
1.1189 raeburn 5605: ($env{'request.course.id'})) {
1.490 raeburn 5606: foreach my $key (keys(%live_courses)) {
5607: if ($key ne $env{'request.course.id'}) {
5608: delete($live_courses{$key});
5609: }
5610: }
5611: }
5612:
5613: my $otheruser = 0;
5614: my %own_courses;
5615: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5616: # Resource belongs to user other than current user.
5617: $otheruser = 1;
5618: # Gather courses for current user
5619: %own_courses =
5620: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5621: }
5622:
5623: # Gather active course roles - course coordinator, instructor,
5624: # exam proctor, ta, student, or custom role.
1.474 raeburn 5625:
5626: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5627: my ($cdom,$cnum);
5628: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5629: $cdom = $env{'course.'.$course.'.domain'};
5630: $cnum = $env{'course.'.$course.'.num'};
5631: } else {
1.490 raeburn 5632: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5633: }
5634: my $no_ownblock = 0;
5635: my $no_userblock = 0;
1.533 raeburn 5636: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5637: # Check if current user has 'evb' priv for this
5638: if (defined($own_courses{$course})) {
5639: foreach my $sec (keys(%{$own_courses{$course}})) {
5640: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5641: if ($sec ne 'none') {
5642: $checkrole .= '/'.$sec;
5643: }
5644: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5645: $no_ownblock = 1;
5646: last;
5647: }
5648: }
5649: }
5650: # if they have 'evb' priv and are currently not playing student
5651: next if (($no_ownblock) &&
5652: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5653: }
1.474 raeburn 5654: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5655: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5656: if ($sec ne 'none') {
1.482 raeburn 5657: $checkrole .= '/'.$sec;
1.474 raeburn 5658: }
1.490 raeburn 5659: if ($otheruser) {
5660: # Resource belongs to user other than current user.
5661: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5662: my (%allroles,%userroles);
5663: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5664: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5665: my ($trole,$tdom,$tnum,$tsec);
5666: if ($entry =~ /^cr/) {
5667: ($trole,$tdom,$tnum,$tsec) =
5668: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5669: } else {
5670: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5671: }
5672: my ($spec,$area,$trest);
5673: $area = '/'.$tdom.'/'.$tnum;
5674: $trest = $tnum;
5675: if ($tsec ne '') {
5676: $area .= '/'.$tsec;
5677: $trest .= '/'.$tsec;
5678: }
5679: $spec = $trole.'.'.$area;
5680: if ($trole =~ /^cr/) {
5681: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5682: $tdom,$spec,$trest,$area);
5683: } else {
5684: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5685: $tdom,$spec,$trest,$area);
5686: }
5687: }
1.1276 raeburn 5688: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5689: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5690: if ($1) {
5691: $no_userblock = 1;
5692: last;
5693: }
1.486 raeburn 5694: }
5695: }
1.490 raeburn 5696: } else {
5697: # Resource belongs to current user
5698: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5699: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5700: $no_ownblock = 1;
5701: last;
5702: }
1.474 raeburn 5703: }
5704: }
5705: # if they have the evb priv and are currently not playing student
1.482 raeburn 5706: next if (($no_ownblock) &&
1.491 albertel 5707: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5708: next if ($no_userblock);
1.474 raeburn 5709:
1.1303 raeburn 5710: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5711: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5712:
1.1062 raeburn 5713: my ($start,$end,$trigger) =
1.1347 raeburn 5714: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5715: if (($start != 0) &&
5716: (($startblock == 0) || ($startblock > $start))) {
5717: $startblock = $start;
1.1062 raeburn 5718: if ($trigger ne '') {
5719: $triggerblock = $trigger;
5720: }
1.502 raeburn 5721: }
5722: if (($end != 0) &&
5723: (($endblock == 0) || ($endblock < $end))) {
5724: $endblock = $end;
1.1062 raeburn 5725: if ($trigger ne '') {
5726: $triggerblock = $trigger;
5727: }
1.502 raeburn 5728: }
1.490 raeburn 5729: }
1.1062 raeburn 5730: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5731: }
5732:
5733: sub get_blocks {
1.1347 raeburn 5734: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5735: my $startblock = 0;
5736: my $endblock = 0;
1.1062 raeburn 5737: my $triggerblock = '';
1.490 raeburn 5738: my $course = $cdom.'_'.$cnum;
5739: $setters->{$course} = {};
5740: $setters->{$course}{'staff'} = [];
5741: $setters->{$course}{'times'} = [];
1.1062 raeburn 5742: $setters->{$course}{'triggers'} = [];
5743: my (@blockers,%triggered);
5744: my $now = time;
5745: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5746: if ($activity eq 'docs') {
1.1348 raeburn 5747: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5748: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5749: $blocked = 1;
5750: $nosymbcache = 1;
1.1348 raeburn 5751: $noenccheck = 1;
1.1347 raeburn 5752: }
1.1348 raeburn 5753: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5754: foreach my $block (@blockers) {
5755: if ($block =~ /^firstaccess____(.+)$/) {
5756: my $item = $1;
5757: my $type = 'map';
5758: my $timersymb = $item;
5759: if ($item eq 'course') {
5760: $type = 'course';
5761: } elsif ($item =~ /___\d+___/) {
5762: $type = 'resource';
5763: } else {
5764: $timersymb = &Apache::lonnet::symbread($item);
5765: }
5766: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5767: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5768: $triggered{$block} = {
5769: start => $start,
5770: end => $end,
5771: type => $type,
5772: };
5773: }
5774: }
5775: } else {
5776: foreach my $block (keys(%commblocks)) {
5777: if ($block =~ m/^(\d+)____(\d+)$/) {
5778: my ($start,$end) = ($1,$2);
5779: if ($start <= time && $end >= time) {
5780: if (ref($commblocks{$block}) eq 'HASH') {
5781: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5782: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5783: unless(grep(/^\Q$block\E$/,@blockers)) {
5784: push(@blockers,$block);
5785: }
5786: }
5787: }
5788: }
5789: }
5790: } elsif ($block =~ /^firstaccess____(.+)$/) {
5791: my $item = $1;
5792: my $timersymb = $item;
5793: my $type = 'map';
5794: if ($item eq 'course') {
5795: $type = 'course';
5796: } elsif ($item =~ /___\d+___/) {
5797: $type = 'resource';
5798: } else {
5799: $timersymb = &Apache::lonnet::symbread($item);
5800: }
5801: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5802: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5803: if ($start && $end) {
5804: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5805: if (ref($commblocks{$block}) eq 'HASH') {
5806: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5807: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5808: unless(grep(/^\Q$block\E$/,@blockers)) {
5809: push(@blockers,$block);
5810: $triggered{$block} = {
5811: start => $start,
5812: end => $end,
5813: type => $type,
5814: };
5815: }
5816: }
5817: }
1.1062 raeburn 5818: }
5819: }
1.490 raeburn 5820: }
1.1062 raeburn 5821: }
5822: }
5823: }
5824: foreach my $blocker (@blockers) {
5825: my ($staff_name,$staff_dom,$title,$blocks) =
5826: &parse_block_record($commblocks{$blocker});
5827: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5828: my ($start,$end,$triggertype);
5829: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5830: ($start,$end) = ($1,$2);
5831: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5832: $start = $triggered{$blocker}{'start'};
5833: $end = $triggered{$blocker}{'end'};
5834: $triggertype = $triggered{$blocker}{'type'};
5835: }
5836: if ($start) {
5837: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5838: if ($triggertype) {
5839: push(@{$$setters{$course}{'triggers'}},$triggertype);
5840: } else {
5841: push(@{$$setters{$course}{'triggers'}},0);
5842: }
5843: if ( ($startblock == 0) || ($startblock > $start) ) {
5844: $startblock = $start;
5845: if ($triggertype) {
5846: $triggerblock = $blocker;
1.474 raeburn 5847: }
5848: }
1.1062 raeburn 5849: if ( ($endblock == 0) || ($endblock < $end) ) {
5850: $endblock = $end;
5851: if ($triggertype) {
5852: $triggerblock = $blocker;
5853: }
5854: }
1.474 raeburn 5855: }
5856: }
1.1062 raeburn 5857: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5858: }
5859:
5860: sub parse_block_record {
5861: my ($record) = @_;
5862: my ($setuname,$setudom,$title,$blocks);
5863: if (ref($record) eq 'HASH') {
5864: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5865: $title = &unescape($record->{'event'});
5866: $blocks = $record->{'blocks'};
5867: } else {
5868: my @data = split(/:/,$record,3);
5869: if (scalar(@data) eq 2) {
5870: $title = $data[1];
5871: ($setuname,$setudom) = split(/@/,$data[0]);
5872: } else {
5873: ($setuname,$setudom,$title) = @data;
5874: }
5875: $blocks = { 'com' => 'on' };
5876: }
5877: return ($setuname,$setudom,$title,$blocks);
5878: }
5879:
1.854 kalberla 5880: sub blocking_status {
1.1372 raeburn 5881: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5882: my %setters;
1.890 droeschl 5883:
1.1061 raeburn 5884: # check for active blocking
1.1372 raeburn 5885: if ($clientip eq '') {
5886: $clientip = &Apache::lonnet::get_requestor_ip();
5887: }
5888: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5889: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5890: my $blocked = 0;
1.1372 raeburn 5891: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5892: $blocked = 1;
5893: }
1.890 droeschl 5894:
1.1061 raeburn 5895: # caller just wants to know whether a block is active
5896: if (!wantarray) { return $blocked; }
5897:
5898: # build a link to a popup window containing the details
5899: my $querystring = "?activity=$activity";
1.1351 raeburn 5900: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5901: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1232 raeburn 5902: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5903: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5904: } elsif ($activity eq 'docs') {
1.1347 raeburn 5905: my $showurl = &Apache::lonenc::check_encrypt($url);
5906: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5907: if ($symb) {
5908: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5909: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5910: }
1.1062 raeburn 5911: }
1.1061 raeburn 5912:
5913: my $output .= <<'END_MYBLOCK';
5914: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5915: var options = "width=" + w + ",height=" + h + ",";
5916: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5917: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5918: var newWin = window.open(url, wdwName, options);
5919: newWin.focus();
5920: }
1.890 droeschl 5921: END_MYBLOCK
1.854 kalberla 5922:
1.1061 raeburn 5923: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5924:
1.1061 raeburn 5925: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5926: my $text = &mt('Communication Blocked');
1.1217 raeburn 5927: my $class = 'LC_comblock';
1.1062 raeburn 5928: if ($activity eq 'docs') {
5929: $text = &mt('Content Access Blocked');
1.1217 raeburn 5930: $class = '';
1.1063 raeburn 5931: } elsif ($activity eq 'printout') {
5932: $text = &mt('Printing Blocked');
1.1232 raeburn 5933: } elsif ($activity eq 'passwd') {
5934: $text = &mt('Password Changing Blocked');
1.1345 raeburn 5935: } elsif ($activity eq 'grades') {
5936: $text = &mt('Gradebook Blocked');
1.1346 raeburn 5937: } elsif ($activity eq 'search') {
5938: $text = &mt('Search Blocked');
1.1282 raeburn 5939: } elsif ($activity eq 'alert') {
5940: $text = &mt('Checking Critical Messages Blocked');
5941: } elsif ($activity eq 'reinit') {
5942: $text = &mt('Checking Course Update Blocked');
1.1351 raeburn 5943: } elsif ($activity eq 'about') {
5944: $text = &mt('Access to User Information Pages Blocked');
1.1373 raeburn 5945: } elsif ($activity eq 'wishlist') {
5946: $text = &mt('Access to Stored Links Blocked');
5947: } elsif ($activity eq 'annotate') {
5948: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 5949: }
1.1061 raeburn 5950: $output .= <<"END_BLOCK";
1.1217 raeburn 5951: <div class='$class'>
1.869 kalberla 5952: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5953: title='$text'>
5954: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5955: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5956: title='$text'>$text</a>
1.867 kalberla 5957: </div>
5958:
5959: END_BLOCK
1.474 raeburn 5960:
1.1061 raeburn 5961: return ($blocked, $output);
1.854 kalberla 5962: }
1.490 raeburn 5963:
1.60 matthew 5964: ###############################################
5965:
1.682 raeburn 5966: sub check_ip_acc {
1.1201 raeburn 5967: my ($acc,$clientip)=@_;
1.682 raeburn 5968: &Apache::lonxml::debug("acc is $acc");
5969: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5970: return 1;
5971: }
1.1339 raeburn 5972: my ($ip,$allowed);
5973: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5974: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5975: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5976: } else {
1.1350 raeburn 5977: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5978: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1339 raeburn 5979: }
1.682 raeburn 5980:
5981: my $name;
1.1219 raeburn 5982: my %access = (
5983: allowfrom => 1,
5984: denyfrom => 0,
5985: );
5986: my @allows;
5987: my @denies;
5988: foreach my $item (split(',',$acc)) {
5989: $item =~ s/^\s*//;
5990: $item =~ s/\s*$//;
5991: my $pattern;
5992: if ($item =~ /^\!(.+)$/) {
5993: push(@denies,$1);
5994: } else {
5995: push(@allows,$item);
5996: }
5997: }
5998: my $numdenies = scalar(@denies);
5999: my $numallows = scalar(@allows);
6000: my $count = 0;
6001: foreach my $pattern (@denies,@allows) {
6002: $count ++;
6003: my $acctype = 'allowfrom';
6004: if ($count <= $numdenies) {
6005: $acctype = 'denyfrom';
6006: }
1.682 raeburn 6007: if ($pattern =~ /\*$/) {
6008: #35.8.*
6009: $pattern=~s/\*//;
1.1219 raeburn 6010: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6011: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
6012: #35.8.3.[34-56]
6013: my $low=$2;
6014: my $high=$3;
6015: $pattern=$1;
6016: if ($ip =~ /^\Q$pattern\E/) {
6017: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 6018: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 6019: }
6020: } elsif ($pattern =~ /^\*/) {
6021: #*.msu.edu
6022: $pattern=~s/\*//;
6023: if (!defined($name)) {
6024: use Socket;
6025: my $netaddr=inet_aton($ip);
6026: ($name)=gethostbyaddr($netaddr,AF_INET);
6027: }
1.1219 raeburn 6028: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 6029: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
6030: #127.0.0.1
1.1219 raeburn 6031: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 6032: } else {
6033: #some.name.com
6034: if (!defined($name)) {
6035: use Socket;
6036: my $netaddr=inet_aton($ip);
6037: ($name)=gethostbyaddr($netaddr,AF_INET);
6038: }
1.1219 raeburn 6039: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
6040: }
6041: if ($allowed =~ /^(0|1)$/) { last; }
6042: }
6043: if ($allowed eq '') {
6044: if ($numdenies && !$numallows) {
6045: $allowed = 1;
6046: } else {
6047: $allowed = 0;
1.682 raeburn 6048: }
6049: }
6050: return $allowed;
6051: }
6052:
6053: ###############################################
6054:
1.60 matthew 6055: =pod
6056:
1.112 bowersj2 6057: =head1 Domain Template Functions
6058:
6059: =over 4
6060:
6061: =item * &determinedomain()
1.60 matthew 6062:
6063: Inputs: $domain (usually will be undef)
6064:
1.63 www 6065: Returns: Determines which domain should be used for designs
1.60 matthew 6066:
6067: =cut
1.54 www 6068:
1.60 matthew 6069: ###############################################
1.63 www 6070: sub determinedomain {
6071: my $domain=shift;
1.531 albertel 6072: if (! $domain) {
1.60 matthew 6073: # Determine domain if we have not been given one
1.893 raeburn 6074: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 6075: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
6076: if ($env{'request.role.domain'}) {
6077: $domain=$env{'request.role.domain'};
1.60 matthew 6078: }
6079: }
1.63 www 6080: return $domain;
6081: }
6082: ###############################################
1.517 raeburn 6083:
1.518 albertel 6084: sub devalidate_domconfig_cache {
6085: my ($udom)=@_;
6086: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
6087: }
6088:
6089: # ---------------------- Get domain configuration for a domain
6090: sub get_domainconf {
6091: my ($udom) = @_;
6092: my $cachetime=1800;
6093: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
6094: if (defined($cached)) { return %{$result}; }
6095:
6096: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 6097: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 6098: my (%designhash,%legacy);
1.518 albertel 6099: if (keys(%domconfig) > 0) {
6100: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 6101: if (keys(%{$domconfig{'login'}})) {
6102: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 6103: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 6104: if (($key eq 'loginvia') || ($key eq 'headtag')) {
6105: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6106: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
6107: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
6108: if ($key eq 'loginvia') {
6109: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
6110: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
6111: $designhash{$udom.'.login.loginvia'} = $server;
6112: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
6113:
6114: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
6115: } else {
6116: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
6117: }
1.948 raeburn 6118: }
1.1208 raeburn 6119: } elsif ($key eq 'headtag') {
6120: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
6121: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 6122: }
1.946 raeburn 6123: }
1.1208 raeburn 6124: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
6125: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
6126: }
1.946 raeburn 6127: }
6128: }
6129: }
1.1366 raeburn 6130: } elsif ($key eq 'saml') {
6131: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
6132: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
6133: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
6134: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
1.1386 raeburn 6135: foreach my $item ('text','img','alt','url','title','window','notsso') {
1.1366 raeburn 6136: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
6137: }
6138: }
6139: }
6140: }
1.946 raeburn 6141: } else {
6142: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
6143: $designhash{$udom.'.login.'.$key.'_'.$img} =
6144: $domconfig{'login'}{$key}{$img};
6145: }
1.699 raeburn 6146: }
6147: } else {
6148: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
6149: }
1.632 raeburn 6150: }
6151: } else {
6152: $legacy{'login'} = 1;
1.518 albertel 6153: }
1.632 raeburn 6154: } else {
6155: $legacy{'login'} = 1;
1.518 albertel 6156: }
6157: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 6158: if (keys(%{$domconfig{'rolecolors'}})) {
6159: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
6160: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
6161: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
6162: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
6163: }
1.518 albertel 6164: }
6165: }
1.632 raeburn 6166: } else {
6167: $legacy{'rolecolors'} = 1;
1.518 albertel 6168: }
1.632 raeburn 6169: } else {
6170: $legacy{'rolecolors'} = 1;
1.518 albertel 6171: }
1.948 raeburn 6172: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6173: if ($domconfig{'autoenroll'}{'co-owners'}) {
6174: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
6175: }
6176: }
1.632 raeburn 6177: if (keys(%legacy) > 0) {
6178: my %legacyhash = &get_legacy_domconf($udom);
6179: foreach my $item (keys(%legacyhash)) {
6180: if ($item =~ /^\Q$udom\E\.login/) {
6181: if ($legacy{'login'}) {
6182: $designhash{$item} = $legacyhash{$item};
6183: }
6184: } else {
6185: if ($legacy{'rolecolors'}) {
6186: $designhash{$item} = $legacyhash{$item};
6187: }
1.518 albertel 6188: }
6189: }
6190: }
1.632 raeburn 6191: } else {
6192: %designhash = &get_legacy_domconf($udom);
1.518 albertel 6193: }
6194: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
6195: $cachetime);
6196: return %designhash;
6197: }
6198:
1.632 raeburn 6199: sub get_legacy_domconf {
6200: my ($udom) = @_;
6201: my %legacyhash;
6202: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
6203: my $designfile = $designdir.'/'.$udom.'.tab';
6204: if (-e $designfile) {
1.1317 raeburn 6205: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 6206: while (my $line = <$fh>) {
6207: next if ($line =~ /^\#/);
6208: chomp($line);
6209: my ($key,$val)=(split(/\=/,$line));
6210: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
6211: }
6212: close($fh);
6213: }
6214: }
1.1026 raeburn 6215: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 6216: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
6217: }
6218: return %legacyhash;
6219: }
6220:
1.63 www 6221: =pod
6222:
1.112 bowersj2 6223: =item * &domainlogo()
1.63 www 6224:
6225: Inputs: $domain (usually will be undef)
6226:
6227: Returns: A link to a domain logo, if the domain logo exists.
6228: If the domain logo does not exist, a description of the domain.
6229:
6230: =cut
1.112 bowersj2 6231:
1.63 www 6232: ###############################################
6233: sub domainlogo {
1.517 raeburn 6234: my $domain = &determinedomain(shift);
1.518 albertel 6235: my %designhash = &get_domainconf($domain);
1.517 raeburn 6236: # See if there is a logo
6237: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 6238: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 6239: if ($imgsrc =~ m{^/(adm|res)/}) {
6240: if ($imgsrc =~ m{^/res/}) {
6241: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
6242: &Apache::lonnet::repcopy($local_name);
6243: }
6244: $imgsrc = &lonhttpdurl($imgsrc);
1.1374 raeburn 6245: }
6246: my $alttext = $domain;
6247: if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
6248: $alttext = $designhash{$domain.'.login.alttext_domlogo'};
6249: }
6250: return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 6251: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
6252: return &Apache::lonnet::domain($domain,'description');
1.59 www 6253: } else {
1.60 matthew 6254: return '';
1.59 www 6255: }
6256: }
1.63 www 6257: ##############################################
6258:
6259: =pod
6260:
1.112 bowersj2 6261: =item * &designparm()
1.63 www 6262:
6263: Inputs: $which parameter; $domain (usually will be undef)
6264:
6265: Returns: value of designparamter $which
6266:
6267: =cut
1.112 bowersj2 6268:
1.397 albertel 6269:
1.400 albertel 6270: ##############################################
1.397 albertel 6271: sub designparm {
6272: my ($which,$domain)=@_;
6273: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 6274: return $env{'environment.color.'.$which};
1.96 www 6275: }
1.63 www 6276: $domain=&determinedomain($domain);
1.1016 raeburn 6277: my %domdesign;
6278: unless ($domain eq 'public') {
6279: %domdesign = &get_domainconf($domain);
6280: }
1.520 raeburn 6281: my $output;
1.517 raeburn 6282: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 6283: $output = $domdesign{$domain.'.'.$which};
1.63 www 6284: } else {
1.520 raeburn 6285: $output = $defaultdesign{$which};
6286: }
6287: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 6288: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 6289: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 6290: if ($output =~ m{^/res/}) {
6291: my $local_name = &Apache::lonnet::filelocation('',$output);
6292: &Apache::lonnet::repcopy($local_name);
6293: }
1.520 raeburn 6294: $output = &lonhttpdurl($output);
6295: }
1.63 www 6296: }
1.520 raeburn 6297: return $output;
1.63 www 6298: }
1.59 www 6299:
1.822 bisitz 6300: ##############################################
6301: =pod
6302:
1.832 bisitz 6303: =item * &authorspace()
6304:
1.1028 raeburn 6305: Inputs: $url (usually will be undef).
1.832 bisitz 6306:
1.1132 raeburn 6307: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 6308: directory being viewed (or for which action is being taken).
6309: If $url is provided, and begins /priv/<domain>/<uname>
6310: the path will be that portion of the $context argument.
6311: Otherwise the path will be for the author space of the current
6312: user when the current role is author, or for that of the
6313: co-author/assistant co-author space when the current role
6314: is co-author or assistant co-author.
1.832 bisitz 6315:
6316: =cut
6317:
6318: sub authorspace {
1.1028 raeburn 6319: my ($url) = @_;
6320: if ($url ne '') {
6321: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
6322: return $1;
6323: }
6324: }
1.832 bisitz 6325: my $caname = '';
1.1024 www 6326: my $cadom = '';
1.1028 raeburn 6327: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 6328: ($cadom,$caname) =
1.832 bisitz 6329: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 6330: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 6331: $caname = $env{'user.name'};
1.1024 www 6332: $cadom = $env{'user.domain'};
1.832 bisitz 6333: }
1.1028 raeburn 6334: if (($caname ne '') && ($cadom ne '')) {
6335: return "/priv/$cadom/$caname/";
6336: }
6337: return;
1.832 bisitz 6338: }
6339:
6340: ##############################################
6341: =pod
6342:
1.822 bisitz 6343: =item * &head_subbox()
6344:
6345: Inputs: $content (contains HTML code with page functions, etc.)
6346:
6347: Returns: HTML div with $content
6348: To be included in page header
6349:
6350: =cut
6351:
6352: sub head_subbox {
6353: my ($content)=@_;
6354: my $output =
1.993 raeburn 6355: '<div class="LC_head_subbox">'
1.822 bisitz 6356: .$content
6357: .'</div>'
6358: }
6359:
6360: ##############################################
6361: =pod
6362:
6363: =item * &CSTR_pageheader()
6364:
1.1026 raeburn 6365: Input: (optional) filename from which breadcrumb trail is built.
6366: In most cases no input as needed, as $env{'request.filename'}
6367: is appropriate for use in building the breadcrumb trail.
1.1379 raeburn 6368: frameset flag
6369: If page header is being requested for use in a frameset, then
6370: the second (option) argument -- frameset will be true, and
6371: the target attribute set for links should be target="_parent".
1.822 bisitz 6372:
6373: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 6374: To be included on Authoring Space pages
1.822 bisitz 6375:
6376: =cut
6377:
6378: sub CSTR_pageheader {
1.1379 raeburn 6379: my ($trailfile,$frameset) = @_;
1.1026 raeburn 6380: if ($trailfile eq '') {
6381: $trailfile = $env{'request.filename'};
6382: }
6383:
6384: # this is for resources; directories have customtitle, and crumbs
6385: # and select recent are created in lonpubdir.pm
6386:
6387: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 6388: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 6389: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 6390: my $formaction = "/priv/$udom/$uname/$thisdisfn";
6391: $formaction =~ s{/+}{/}g;
1.822 bisitz 6392:
6393: my $parentpath = '';
6394: my $lastitem = '';
6395: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
6396: $parentpath = $1;
6397: $lastitem = $2;
6398: } else {
6399: $lastitem = $thisdisfn;
6400: }
1.921 bisitz 6401:
1.1246 raeburn 6402: my ($crsauthor,$title);
6403: if (($env{'request.course.id'}) &&
6404: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 6405: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 6406: $crsauthor = 1;
6407: $title = &mt('Course Authoring Space');
6408: } else {
6409: $title = &mt('Authoring Space');
6410: }
6411:
1.1379 raeburn 6412: my ($target,$crumbtarget) = (' target="_top"','_top');
6413: if ($frameset) {
6414: $target = ' target="_parent"';
6415: $crumbtarget = '_parent';
6416: } elsif (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 6417: $target = '';
6418: $crumbtarget = '';
1.1379 raeburn 6419: } elsif (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'})) {
1.1378 raeburn 6420: $target = ' target="'.$env{'request.deeplink.target'}.'"';
6421: $crumbtarget = $env{'request.deeplink.target'};
6422: }
1.1313 raeburn 6423:
1.921 bisitz 6424: my $output =
1.822 bisitz 6425: '<div>'
6426: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 6427: .'<b>'.$title.'</b> '
1.1314 raeburn 6428: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6429: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6430:
6431: if ($lastitem) {
6432: $output .=
6433: '<span class="LC_filename">'
6434: .$lastitem
6435: .'</span>';
6436: }
1.1245 raeburn 6437:
1.1246 raeburn 6438: if ($crsauthor) {
1.1379 raeburn 6439: $output .= '</form>'.&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6440: } else {
6441: $output .=
6442: '<br />'
1.1314 raeburn 6443: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 6444: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6445: .'</form>'
1.1379 raeburn 6446: .&Apache::lonmenu::constspaceform($frameset);
1.1246 raeburn 6447: }
6448: $output .= '</div>';
1.921 bisitz 6449:
6450: return $output;
1.822 bisitz 6451: }
6452:
1.60 matthew 6453: ###############################################
6454: ###############################################
6455:
6456: =pod
6457:
1.112 bowersj2 6458: =back
6459:
1.549 albertel 6460: =head1 HTML Helpers
1.112 bowersj2 6461:
6462: =over 4
6463:
6464: =item * &bodytag()
1.60 matthew 6465:
6466: Returns a uniform header for LON-CAPA web pages.
6467:
6468: Inputs:
6469:
1.112 bowersj2 6470: =over 4
6471:
6472: =item * $title, A title to be displayed on the page.
6473:
6474: =item * $function, the current role (can be undef).
6475:
6476: =item * $addentries, extra parameters for the <body> tag.
6477:
6478: =item * $bodyonly, if defined, only return the <body> tag.
6479:
6480: =item * $domain, if defined, force a given domain.
6481:
6482: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6483: text interface only)
1.60 matthew 6484:
1.814 bisitz 6485: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6486: navigational links
1.317 albertel 6487:
1.338 albertel 6488: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6489:
1.460 albertel 6490: =item * $args, optional argument valid values are
6491: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6492: use_absolute -> for external resource or syllabus, this will
6493: contain https://<hostname> if server uses
6494: https (as per hosts.tab), but request is for http
6495: hostname -> hostname, from $r->hostname().
1.460 albertel 6496:
1.1096 raeburn 6497: =item * $advtoolsref, optional argument, ref to an array containing
6498: inlineremote items to be added in "Functions" menu below
6499: breadcrumbs.
6500:
1.1316 raeburn 6501: =item * $ltiscope, optional argument, will be one of: resource, map or
6502: course, if LON-CAPA is in LTI Provider context. Value is
6503: the scope of use, i.e., launch was for access to a single, a map
6504: or the entire course.
6505:
6506: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6507: context, this will contain the URL for the landing item in
6508: the course, after launch from an LTI Consumer
6509:
1.1318 raeburn 6510: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6511: context, this will contain a reference to hash of items
6512: to be included in the page header and/or inline menu.
6513:
1.1385 raeburn 6514: =item * $menucoll, optional argument, if specific menu collection is in
6515: effect, either set as the default for the course, or set for
6516: the deeplink paramater for $env{'request.deeplink.login'}
6517: then $menucoll will be the number of that collection.
6518:
6519: =item * $menuref, optional argument, reference to a hash, containing the
6520: menu options included for the menu in effect, based on the
6521: configuration for the numbered menu collection in use.
6522:
6523: =item * $showncrumbsref, reference to a scalar. Calls to lonmenu::innerregister
6524: within &bodytag() can result in calls to lonhtmlcommon::breadcrumbs(),
6525: if so, $showncrumbsref is set there to 1, and will propagate back
6526: via &bodytag() to &start_page(), to prevent lonhtmlcommon::breadcrumbs()
6527: being called a second time.
6528:
1.112 bowersj2 6529: =back
6530:
1.60 matthew 6531: Returns: A uniform header for LON-CAPA web pages.
6532: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6533: If $bodyonly is undef or zero, an html string containing a <body> tag and
6534: other decorations will be returned.
6535:
6536: =cut
6537:
1.54 www 6538: sub bodytag {
1.831 bisitz 6539: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1359 raeburn 6540: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,
1.1385 raeburn 6541: $ltimenu,$menucoll,$menuref,$showncrumbsref)=@_;
1.339 albertel 6542:
1.954 raeburn 6543: my $public;
6544: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6545: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6546: $public = 1;
6547: }
1.460 albertel 6548: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6549: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6550: my $hostname = $args->{'hostname'};
1.339 albertel 6551:
1.183 matthew 6552: $function = &get_users_function() if (!$function);
1.339 albertel 6553: my $img = &designparm($function.'.img',$domain);
6554: my $font = &designparm($function.'.font',$domain);
6555: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6556:
1.803 bisitz 6557: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6558: 'bgcolor' => $pgbg,
1.339 albertel 6559: 'text' => $font,
6560: 'alink' => &designparm($function.'.alink',$domain),
6561: 'vlink' => &designparm($function.'.vlink',$domain),
6562: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6563: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6564:
1.63 www 6565: # role and realm
1.1178 raeburn 6566: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6567: if ($realm) {
6568: $realm = '/'.$realm;
6569: }
1.1357 raeburn 6570: if ($role eq 'ca') {
1.479 albertel 6571: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6572: $realm = &plainname($rname,$rdom);
1.378 raeburn 6573: }
1.55 www 6574: # realm
1.1357 raeburn 6575: my ($cid,$sec);
1.258 albertel 6576: if ($env{'request.course.id'}) {
1.1357 raeburn 6577: $cid = $env{'request.course.id'};
6578: if ($env{'request.course.sec'}) {
6579: $sec = $env{'request.course.sec'};
6580: }
6581: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6582: if (&Apache::lonnet::is_course($1,$2)) {
6583: $cid = $1.'_'.$2;
6584: $sec = $3;
6585: }
6586: }
6587: if ($cid) {
1.378 raeburn 6588: if ($env{'request.role'} !~ /^cr/) {
6589: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6590: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6591: if ($env{'request.role.desc'}) {
6592: $role = $env{'request.role.desc'};
6593: } else {
6594: $role = &mt('Helpdesk[_1]',' '.$2);
6595: }
1.1257 raeburn 6596: } else {
6597: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6598: }
1.1357 raeburn 6599: if ($sec) {
6600: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6601: }
1.1357 raeburn 6602: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6603: } else {
6604: $role = &Apache::lonnet::plaintext($role);
1.54 www 6605: }
1.433 albertel 6606:
1.359 albertel 6607: if (!$realm) { $realm=' '; }
1.330 albertel 6608:
1.438 albertel 6609: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6610:
1.101 www 6611: # construct main body tag
1.359 albertel 6612: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6613: &Apache::lontexconvert::init_math_support();
1.252 albertel 6614:
1.1131 raeburn 6615: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6616:
1.1130 raeburn 6617: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6618: return $bodytag;
1.1130 raeburn 6619: }
1.359 albertel 6620:
1.954 raeburn 6621: if ($public) {
1.433 albertel 6622: undef($role);
6623: }
1.1318 raeburn 6624:
1.1359 raeburn 6625: my $showcrstitle = 1;
1.1357 raeburn 6626: if (($cid) && ($env{'request.lti.login'})) {
1.1318 raeburn 6627: if (ref($ltimenu) eq 'HASH') {
6628: unless ($ltimenu->{'role'}) {
6629: undef($role);
6630: }
6631: unless ($ltimenu->{'coursetitle'}) {
6632: $realm=' ';
1.1359 raeburn 6633: $showcrstitle = 0;
6634: }
6635: }
6636: } elsif (($cid) && ($menucoll)) {
6637: if (ref($menuref) eq 'HASH') {
6638: unless ($menuref->{'role'}) {
6639: undef($role);
6640: }
6641: unless ($menuref->{'crs'}) {
6642: $realm=' ';
6643: $showcrstitle = 0;
1.1318 raeburn 6644: }
6645: }
6646: }
6647:
1.762 bisitz 6648: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6649: #
6650: # Extra info if you are the DC
6651: my $dc_info = '';
1.1359 raeburn 6652: if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1357 raeburn 6653: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6654: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6655: $dc_info =~ s/\s+$//;
1.359 albertel 6656: }
6657:
1.1237 raeburn 6658: my $crstype;
1.1357 raeburn 6659: if ($cid) {
6660: $crstype = $env{'course.'.$cid.'.type'};
1.1237 raeburn 6661: } elsif ($args->{'crstype'}) {
6662: $crstype = $args->{'crstype'};
6663: }
6664: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6665: undef($role);
6666: } else {
1.1242 raeburn 6667: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6668: }
1.853 droeschl 6669:
1.903 droeschl 6670: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6671:
6672: # if ($env{'request.state'} eq 'construct') {
6673: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6674: # }
6675:
1.1130 raeburn 6676: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6677: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6678:
1.1318 raeburn 6679: unless ($args->{'no_primary_menu'}) {
1.1369 raeburn 6680: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
1.1380 raeburn 6681: $args->{'links_disabled'},
6682: $args->{'links_target'});
1.359 albertel 6683:
1.1318 raeburn 6684: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6685: if ($dc_info) {
6686: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6687: }
6688: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6689: <em>$realm</em> $dc_info</div>|;
6690: return $bodytag;
6691: }
1.894 droeschl 6692:
1.1318 raeburn 6693: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6694: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6695: }
1.916 droeschl 6696:
1.1318 raeburn 6697: $bodytag .= $right;
1.852 droeschl 6698:
1.1318 raeburn 6699: if ($dc_info) {
6700: $dc_info = &dc_courseid_toggle($dc_info);
6701: }
6702: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6703: }
1.916 droeschl 6704:
1.1169 raeburn 6705: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6706: if ($args->{'no_secondary_menu'}) {
6707: return $bodytag;
6708: }
1.1169 raeburn 6709: #don't show menus for public users
1.954 raeburn 6710: if (!$public){
1.1318 raeburn 6711: unless ($args->{'no_inline_menu'}) {
6712: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
1.1359 raeburn 6713: $args->{'no_primary_menu'},
1.1369 raeburn 6714: $menucoll,$menuref,
1.1380 raeburn 6715: $args->{'links_disabled'},
6716: $args->{'links_target'});
1.1318 raeburn 6717: }
1.903 droeschl 6718: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6719: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6720: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6721: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1385 raeburn 6722: $args->{'bread_crumbs'},'','',$hostname,
6723: $ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 6724: } elsif ($forcereg) {
6725: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1385 raeburn 6726: $args->{'group'},$args->{'hide_buttons'},
6727: $hostname,$ltiscope,$ltiuri,$showncrumbsref);
1.1096 raeburn 6728: } else {
6729: $bodytag .=
6730: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6731: $forcereg,$args->{'group'},
6732: $args->{'bread_crumbs'},
1.1274 raeburn 6733: $advtoolsref,'',$hostname);
1.920 raeburn 6734: }
1.903 droeschl 6735: }else{
6736: # this is to seperate menu from content when there's no secondary
6737: # menu. Especially needed for public accessible ressources.
6738: $bodytag .= '<hr style="clear:both" />';
6739: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6740: }
1.903 droeschl 6741:
1.235 raeburn 6742: return $bodytag;
1.182 matthew 6743: }
6744:
1.917 raeburn 6745: sub dc_courseid_toggle {
6746: my ($dc_info) = @_;
1.980 raeburn 6747: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6748: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6749: &mt('(More ...)').'</a></span>'.
6750: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6751: }
6752:
1.330 albertel 6753: sub make_attr_string {
6754: my ($register,$attr_ref) = @_;
6755:
6756: if ($attr_ref && !ref($attr_ref)) {
6757: die("addentries Must be a hash ref ".
6758: join(':',caller(1))." ".
6759: join(':',caller(0))." ");
6760: }
6761:
6762: if ($register) {
1.339 albertel 6763: my ($on_load,$on_unload);
6764: foreach my $key (keys(%{$attr_ref})) {
6765: if (lc($key) eq 'onload') {
6766: $on_load.=$attr_ref->{$key}.';';
6767: delete($attr_ref->{$key});
6768:
6769: } elsif (lc($key) eq 'onunload') {
6770: $on_unload.=$attr_ref->{$key}.';';
6771: delete($attr_ref->{$key});
6772: }
6773: }
1.953 droeschl 6774: $attr_ref->{'onload'} = $on_load;
6775: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6776: }
1.339 albertel 6777:
1.330 albertel 6778: my $attr_string;
1.1159 raeburn 6779: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6780: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6781: }
6782: return $attr_string;
6783: }
6784:
6785:
1.182 matthew 6786: ###############################################
1.251 albertel 6787: ###############################################
6788:
6789: =pod
6790:
6791: =item * &endbodytag()
6792:
6793: Returns a uniform footer for LON-CAPA web pages.
6794:
1.635 raeburn 6795: Inputs: 1 - optional reference to an args hash
6796: If in the hash, key for noredirectlink has a value which evaluates to true,
6797: a 'Continue' link is not displayed if the page contains an
6798: internal redirect in the <head></head> section,
6799: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6800:
6801: =cut
6802:
6803: sub endbodytag {
1.635 raeburn 6804: my ($args) = @_;
1.1080 raeburn 6805: my $endbodytag;
6806: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6807: $endbodytag='</body>';
6808: }
1.315 albertel 6809: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6810: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
1.1386 raeburn 6811: my ($endbodyjs,$idattr);
6812: if ($env{'internal.head.to_opener'}) {
6813: my $linkid = 'LC_continue_link';
6814: $idattr = ' id="'.$linkid.'"';
6815: my $redirect_for_js = &js_escape($env{'internal.head.redirect'});
6816: $endbodyjs=<<ENDJS;
6817: <script type="text/javascript">
6818: // <![CDATA[
6819: function ebFunction(evt) {
6820: evt.preventDefault();
6821: var dest = '$redirect_for_js';
6822: if (window.opener != null && !window.opener.closed) {
6823: window.opener.location.href=dest;
6824: window.close();
6825: } else {
6826: window.location.href=dest;
6827: }
6828: return false;
6829: }
6830:
6831: \$(document).ready(function () {
6832: if (document.getElementById('$linkid')) {
6833: var clickelem = document.getElementById('$linkid');
6834: clickelem.addEventListener('click',ebFunction,false);
6835: }
6836: });
6837: // ]]>
6838: </script>
6839: ENDJS
6840: }
1.635 raeburn 6841: $endbodytag=
1.1386 raeburn 6842: "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".
1.635 raeburn 6843: &mt('Continue').'</a>'.
6844: $endbodytag;
6845: }
1.315 albertel 6846: }
1.251 albertel 6847: return $endbodytag;
6848: }
6849:
1.352 albertel 6850: =pod
6851:
6852: =item * &standard_css()
6853:
6854: Returns a style sheet
6855:
6856: Inputs: (all optional)
6857: domain -> force to color decorate a page for a specific
6858: domain
6859: function -> force usage of a specific rolish color scheme
6860: bgcolor -> override the default page bgcolor
6861:
6862: =cut
6863:
1.343 albertel 6864: sub standard_css {
1.345 albertel 6865: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6866: $function = &get_users_function() if (!$function);
6867: my $img = &designparm($function.'.img', $domain);
6868: my $tabbg = &designparm($function.'.tabbg', $domain);
6869: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6870: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6871: #second colour for later usage
1.345 albertel 6872: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6873: my $pgbg_or_bgcolor =
6874: $bgcolor ||
1.352 albertel 6875: &designparm($function.'.pgbg', $domain);
1.382 albertel 6876: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6877: my $alink = &designparm($function.'.alink', $domain);
6878: my $vlink = &designparm($function.'.vlink', $domain);
6879: my $link = &designparm($function.'.link', $domain);
6880:
1.602 albertel 6881: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6882: my $mono = 'monospace';
1.850 bisitz 6883: my $data_table_head = $sidebg;
6884: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6885: my $data_table_dark = '#E0E0E0';
1.470 banghart 6886: my $data_table_darker = '#CCCCCC';
1.349 albertel 6887: my $data_table_highlight = '#FFFF00';
1.352 albertel 6888: my $mail_new = '#FFBB77';
6889: my $mail_new_hover = '#DD9955';
6890: my $mail_read = '#BBBB77';
6891: my $mail_read_hover = '#999944';
6892: my $mail_replied = '#AAAA88';
6893: my $mail_replied_hover = '#888855';
6894: my $mail_other = '#99BBBB';
6895: my $mail_other_hover = '#669999';
1.391 albertel 6896: my $table_header = '#DDDDDD';
1.489 raeburn 6897: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6898: my $lg_border_color = '#C8C8C8';
1.952 onken 6899: my $button_hover = '#BF2317';
1.392 albertel 6900:
1.608 albertel 6901: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6902: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6903: : '0 3px 0 4px';
1.448 albertel 6904:
1.523 albertel 6905:
1.343 albertel 6906: return <<END;
1.947 droeschl 6907:
6908: /* needed for iframe to allow 100% height in FF */
6909: body, html {
6910: margin: 0;
6911: padding: 0 0.5%;
6912: height: 99%; /* to avoid scrollbars */
6913: }
6914:
1.795 www 6915: body {
1.911 bisitz 6916: font-family: $sans;
6917: line-height:130%;
6918: font-size:0.83em;
6919: color:$font;
1.795 www 6920: }
6921:
1.959 onken 6922: a:focus,
6923: a:focus img {
1.795 www 6924: color: red;
6925: }
1.698 harmsja 6926:
1.911 bisitz 6927: form, .inline {
6928: display: inline;
1.795 www 6929: }
1.721 harmsja 6930:
1.795 www 6931: .LC_right {
1.911 bisitz 6932: text-align:right;
1.795 www 6933: }
6934:
6935: .LC_middle {
1.911 bisitz 6936: vertical-align:middle;
1.795 www 6937: }
1.721 harmsja 6938:
1.1130 raeburn 6939: .LC_floatleft {
6940: float: left;
6941: }
6942:
6943: .LC_floatright {
6944: float: right;
6945: }
6946:
1.911 bisitz 6947: .LC_400Box {
6948: width:400px;
6949: }
1.721 harmsja 6950:
1.947 droeschl 6951: .LC_iframecontainer {
6952: width: 98%;
6953: margin: 0;
6954: position: fixed;
6955: top: 8.5em;
6956: bottom: 0;
6957: }
6958:
6959: .LC_iframecontainer iframe{
6960: border: none;
6961: width: 100%;
6962: height: 100%;
6963: }
6964:
1.778 bisitz 6965: .LC_filename {
6966: font-family: $mono;
6967: white-space:pre;
1.921 bisitz 6968: font-size: 120%;
1.778 bisitz 6969: }
6970:
6971: .LC_fileicon {
6972: border: none;
6973: height: 1.3em;
6974: vertical-align: text-bottom;
6975: margin-right: 0.3em;
6976: text-decoration:none;
6977: }
6978:
1.1008 www 6979: .LC_setting {
6980: text-decoration:underline;
6981: }
6982:
1.350 albertel 6983: .LC_error {
6984: color: red;
6985: }
1.795 www 6986:
1.1097 bisitz 6987: .LC_warning {
6988: color: darkorange;
6989: }
6990:
1.457 albertel 6991: .LC_diff_removed {
1.733 bisitz 6992: color: red;
1.394 albertel 6993: }
1.532 albertel 6994:
6995: .LC_info,
1.457 albertel 6996: .LC_success,
6997: .LC_diff_added {
1.350 albertel 6998: color: green;
6999: }
1.795 www 7000:
1.802 bisitz 7001: div.LC_confirm_box {
7002: background-color: #FAFAFA;
7003: border: 1px solid $lg_border_color;
7004: margin-right: 0;
7005: padding: 5px;
7006: }
7007:
7008: div.LC_confirm_box .LC_error img,
7009: div.LC_confirm_box .LC_success img {
7010: vertical-align: middle;
7011: }
7012:
1.1242 raeburn 7013: .LC_maxwidth {
7014: max-width: 100%;
7015: height: auto;
7016: }
7017:
1.1243 raeburn 7018: .LC_textsize_mobile {
7019: \@media only screen and (max-device-width: 480px) {
7020: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
7021: }
7022: }
7023:
1.440 albertel 7024: .LC_icon {
1.771 droeschl 7025: border: none;
1.790 droeschl 7026: vertical-align: middle;
1.771 droeschl 7027: }
7028:
1.543 albertel 7029: .LC_docs_spacer {
7030: width: 25px;
7031: height: 1px;
1.771 droeschl 7032: border: none;
1.543 albertel 7033: }
1.346 albertel 7034:
1.532 albertel 7035: .LC_internal_info {
1.735 bisitz 7036: color: #999999;
1.532 albertel 7037: }
7038:
1.794 www 7039: .LC_discussion {
1.1050 www 7040: background: $data_table_dark;
1.911 bisitz 7041: border: 1px solid black;
7042: margin: 2px;
1.794 www 7043: }
7044:
7045: .LC_disc_action_left {
1.1050 www 7046: background: $sidebg;
1.911 bisitz 7047: text-align: left;
1.1050 www 7048: padding: 4px;
7049: margin: 2px;
1.794 www 7050: }
7051:
7052: .LC_disc_action_right {
1.1050 www 7053: background: $sidebg;
1.911 bisitz 7054: text-align: right;
1.1050 www 7055: padding: 4px;
7056: margin: 2px;
1.794 www 7057: }
7058:
7059: .LC_disc_new_item {
1.911 bisitz 7060: background: white;
7061: border: 2px solid red;
1.1050 www 7062: margin: 4px;
7063: padding: 4px;
1.794 www 7064: }
7065:
7066: .LC_disc_old_item {
1.911 bisitz 7067: background: white;
1.1050 www 7068: margin: 4px;
7069: padding: 4px;
1.794 www 7070: }
7071:
1.458 albertel 7072: table.LC_pastsubmission {
7073: border: 1px solid black;
7074: margin: 2px;
7075: }
7076:
1.924 bisitz 7077: table#LC_menubuttons {
1.345 albertel 7078: width: 100%;
7079: background: $pgbg;
1.392 albertel 7080: border: 2px;
1.402 albertel 7081: border-collapse: separate;
1.803 bisitz 7082: padding: 0;
1.345 albertel 7083: }
1.392 albertel 7084:
1.801 tempelho 7085: table#LC_title_bar a {
7086: color: $fontmenu;
7087: }
1.836 bisitz 7088:
1.807 droeschl 7089: table#LC_title_bar {
1.819 tempelho 7090: clear: both;
1.836 bisitz 7091: display: none;
1.807 droeschl 7092: }
7093:
1.795 www 7094: table#LC_title_bar,
1.933 droeschl 7095: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 7096: table#LC_title_bar.LC_with_remote {
1.359 albertel 7097: width: 100%;
1.392 albertel 7098: border-color: $pgbg;
7099: border-style: solid;
7100: border-width: $border;
1.379 albertel 7101: background: $pgbg;
1.801 tempelho 7102: color: $fontmenu;
1.392 albertel 7103: border-collapse: collapse;
1.803 bisitz 7104: padding: 0;
1.819 tempelho 7105: margin: 0;
1.359 albertel 7106: }
1.795 www 7107:
1.933 droeschl 7108: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 7109: margin: 0;
7110: padding: 0;
1.933 droeschl 7111: position: relative;
7112: list-style: none;
1.913 droeschl 7113: }
1.933 droeschl 7114: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 7115: display: inline;
7116: }
1.933 droeschl 7117:
7118: .LC_breadcrumb_tools_navigation {
1.913 droeschl 7119: padding: 0;
1.933 droeschl 7120: margin: 0;
7121: float: left;
1.913 droeschl 7122: }
1.933 droeschl 7123: .LC_breadcrumb_tools_tools {
7124: padding: 0;
7125: margin: 0;
1.913 droeschl 7126: float: right;
7127: }
7128:
1.1240 raeburn 7129: .LC_placement_prog {
7130: padding-right: 20px;
7131: font-weight: bold;
7132: font-size: 90%;
7133: }
7134:
1.359 albertel 7135: table#LC_title_bar td {
7136: background: $tabbg;
7137: }
1.795 www 7138:
1.911 bisitz 7139: table#LC_menubuttons img {
1.803 bisitz 7140: border: none;
1.346 albertel 7141: }
1.795 www 7142:
1.842 droeschl 7143: .LC_breadcrumbs_component {
1.911 bisitz 7144: float: right;
7145: margin: 0 1em;
1.357 albertel 7146: }
1.842 droeschl 7147: .LC_breadcrumbs_component img {
1.911 bisitz 7148: vertical-align: middle;
1.777 tempelho 7149: }
1.795 www 7150:
1.1243 raeburn 7151: .LC_breadcrumbs_hoverable {
7152: background: $sidebg;
7153: }
7154:
1.383 albertel 7155: td.LC_table_cell_checkbox {
7156: text-align: center;
7157: }
1.795 www 7158:
7159: .LC_fontsize_small {
1.911 bisitz 7160: font-size: 70%;
1.705 tempelho 7161: }
7162:
1.844 bisitz 7163: #LC_breadcrumbs {
1.911 bisitz 7164: clear:both;
7165: background: $sidebg;
7166: border-bottom: 1px solid $lg_border_color;
7167: line-height: 2.5em;
1.933 droeschl 7168: overflow: hidden;
1.911 bisitz 7169: margin: 0;
7170: padding: 0;
1.995 raeburn 7171: text-align: left;
1.819 tempelho 7172: }
1.862 bisitz 7173:
1.1098 bisitz 7174: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 7175: clear:both;
7176: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 7177: border: 1px solid $sidebg;
1.1098 bisitz 7178: margin: 0 0 10px 0;
1.966 bisitz 7179: padding: 3px;
1.995 raeburn 7180: text-align: left;
1.822 bisitz 7181: }
7182:
1.795 www 7183: .LC_fontsize_medium {
1.911 bisitz 7184: font-size: 85%;
1.705 tempelho 7185: }
7186:
1.795 www 7187: .LC_fontsize_large {
1.911 bisitz 7188: font-size: 120%;
1.705 tempelho 7189: }
7190:
1.346 albertel 7191: .LC_menubuttons_inline_text {
7192: color: $font;
1.698 harmsja 7193: font-size: 90%;
1.701 harmsja 7194: padding-left:3px;
1.346 albertel 7195: }
7196:
1.934 droeschl 7197: .LC_menubuttons_inline_text img{
7198: vertical-align: middle;
7199: }
7200:
1.1051 www 7201: li.LC_menubuttons_inline_text img {
1.951 onken 7202: cursor:pointer;
1.1002 droeschl 7203: text-decoration: none;
1.951 onken 7204: }
7205:
1.526 www 7206: .LC_menubuttons_link {
7207: text-decoration: none;
7208: }
1.795 www 7209:
1.522 albertel 7210: .LC_menubuttons_category {
1.521 www 7211: color: $font;
1.526 www 7212: background: $pgbg;
1.521 www 7213: font-size: larger;
7214: font-weight: bold;
7215: }
7216:
1.346 albertel 7217: td.LC_menubuttons_text {
1.911 bisitz 7218: color: $font;
1.346 albertel 7219: }
1.706 harmsja 7220:
1.346 albertel 7221: .LC_current_location {
7222: background: $tabbg;
7223: }
1.795 www 7224:
1.1286 raeburn 7225: td.LC_zero_height {
7226: line-height: 0;
7227: cellpadding: 0;
7228: }
7229:
1.938 bisitz 7230: table.LC_data_table {
1.347 albertel 7231: border: 1px solid #000000;
1.402 albertel 7232: border-collapse: separate;
1.426 albertel 7233: border-spacing: 1px;
1.610 albertel 7234: background: $pgbg;
1.347 albertel 7235: }
1.795 www 7236:
1.422 albertel 7237: .LC_data_table_dense {
7238: font-size: small;
7239: }
1.795 www 7240:
1.507 raeburn 7241: table.LC_nested_outer {
7242: border: 1px solid #000000;
1.589 raeburn 7243: border-collapse: collapse;
1.803 bisitz 7244: border-spacing: 0;
1.507 raeburn 7245: width: 100%;
7246: }
1.795 www 7247:
1.879 raeburn 7248: table.LC_innerpickbox,
1.507 raeburn 7249: table.LC_nested {
1.803 bisitz 7250: border: none;
1.589 raeburn 7251: border-collapse: collapse;
1.803 bisitz 7252: border-spacing: 0;
1.507 raeburn 7253: width: 100%;
7254: }
1.795 www 7255:
1.911 bisitz 7256: table.LC_data_table tr th,
7257: table.LC_calendar tr th,
1.879 raeburn 7258: table.LC_prior_tries tr th,
7259: table.LC_innerpickbox tr th {
1.349 albertel 7260: font-weight: bold;
7261: background-color: $data_table_head;
1.801 tempelho 7262: color:$fontmenu;
1.701 harmsja 7263: font-size:90%;
1.347 albertel 7264: }
1.795 www 7265:
1.879 raeburn 7266: table.LC_innerpickbox tr th,
7267: table.LC_innerpickbox tr td {
7268: vertical-align: top;
7269: }
7270:
1.711 raeburn 7271: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 7272: background-color: #CCCCCC;
1.711 raeburn 7273: font-weight: bold;
7274: text-align: left;
7275: }
1.795 www 7276:
1.912 bisitz 7277: table.LC_data_table tr.LC_odd_row > td {
7278: background-color: $data_table_light;
7279: padding: 2px;
7280: vertical-align: top;
7281: }
7282:
1.809 bisitz 7283: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 7284: background-color: $data_table_light;
1.912 bisitz 7285: vertical-align: top;
7286: }
7287:
7288: table.LC_data_table tr.LC_even_row > td {
7289: background-color: $data_table_dark;
1.425 albertel 7290: padding: 2px;
1.900 bisitz 7291: vertical-align: top;
1.347 albertel 7292: }
1.795 www 7293:
1.809 bisitz 7294: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 7295: background-color: $data_table_dark;
1.900 bisitz 7296: vertical-align: top;
1.347 albertel 7297: }
1.795 www 7298:
1.425 albertel 7299: table.LC_data_table tr.LC_data_table_highlight td {
7300: background-color: $data_table_darker;
7301: }
1.795 www 7302:
1.639 raeburn 7303: table.LC_data_table tr td.LC_leftcol_header {
7304: background-color: $data_table_head;
7305: font-weight: bold;
7306: }
1.795 www 7307:
1.451 albertel 7308: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 7309: table.LC_nested tr.LC_empty_row td {
1.421 albertel 7310: font-weight: bold;
7311: font-style: italic;
7312: text-align: center;
7313: padding: 8px;
1.347 albertel 7314: }
1.795 www 7315:
1.1114 raeburn 7316: table.LC_data_table tr.LC_empty_row td,
7317: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 7318: background-color: $sidebg;
7319: }
7320:
7321: table.LC_nested tr.LC_empty_row td {
7322: background-color: #FFFFFF;
7323: }
7324:
1.890 droeschl 7325: table.LC_caption {
7326: }
7327:
1.507 raeburn 7328: table.LC_nested tr.LC_empty_row td {
1.465 albertel 7329: padding: 4ex
7330: }
1.795 www 7331:
1.507 raeburn 7332: table.LC_nested_outer tr th {
7333: font-weight: bold;
1.801 tempelho 7334: color:$fontmenu;
1.507 raeburn 7335: background-color: $data_table_head;
1.701 harmsja 7336: font-size: small;
1.507 raeburn 7337: border-bottom: 1px solid #000000;
7338: }
1.795 www 7339:
1.507 raeburn 7340: table.LC_nested_outer tr td.LC_subheader {
7341: background-color: $data_table_head;
7342: font-weight: bold;
7343: font-size: small;
7344: border-bottom: 1px solid #000000;
7345: text-align: right;
1.451 albertel 7346: }
1.795 www 7347:
1.507 raeburn 7348: table.LC_nested tr.LC_info_row td {
1.735 bisitz 7349: background-color: #CCCCCC;
1.451 albertel 7350: font-weight: bold;
7351: font-size: small;
1.507 raeburn 7352: text-align: center;
7353: }
1.795 www 7354:
1.589 raeburn 7355: table.LC_nested tr.LC_info_row td.LC_left_item,
7356: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 7357: text-align: left;
1.451 albertel 7358: }
1.795 www 7359:
1.507 raeburn 7360: table.LC_nested td {
1.735 bisitz 7361: background-color: #FFFFFF;
1.451 albertel 7362: font-size: small;
1.507 raeburn 7363: }
1.795 www 7364:
1.507 raeburn 7365: table.LC_nested_outer tr th.LC_right_item,
7366: table.LC_nested tr.LC_info_row td.LC_right_item,
7367: table.LC_nested tr.LC_odd_row td.LC_right_item,
7368: table.LC_nested tr td.LC_right_item {
1.451 albertel 7369: text-align: right;
7370: }
7371:
1.507 raeburn 7372: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 7373: background-color: #EEEEEE;
1.451 albertel 7374: }
7375:
1.473 raeburn 7376: table.LC_createuser {
7377: }
7378:
7379: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 7380: font-size: small;
1.473 raeburn 7381: }
7382:
7383: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 7384: background-color: #CCCCCC;
1.473 raeburn 7385: font-weight: bold;
7386: text-align: center;
7387: }
7388:
1.349 albertel 7389: table.LC_calendar {
7390: border: 1px solid #000000;
7391: border-collapse: collapse;
1.917 raeburn 7392: width: 98%;
1.349 albertel 7393: }
1.795 www 7394:
1.349 albertel 7395: table.LC_calendar_pickdate {
7396: font-size: xx-small;
7397: }
1.795 www 7398:
1.349 albertel 7399: table.LC_calendar tr td {
7400: border: 1px solid #000000;
7401: vertical-align: top;
1.917 raeburn 7402: width: 14%;
1.349 albertel 7403: }
1.795 www 7404:
1.349 albertel 7405: table.LC_calendar tr td.LC_calendar_day_empty {
7406: background-color: $data_table_dark;
7407: }
1.795 www 7408:
1.779 bisitz 7409: table.LC_calendar tr td.LC_calendar_day_current {
7410: background-color: $data_table_highlight;
1.777 tempelho 7411: }
1.795 www 7412:
1.938 bisitz 7413: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 7414: background-color: $mail_new;
7415: }
1.795 www 7416:
1.938 bisitz 7417: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 7418: background-color: $mail_new_hover;
7419: }
1.795 www 7420:
1.938 bisitz 7421: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 7422: background-color: $mail_read;
7423: }
1.795 www 7424:
1.938 bisitz 7425: /*
7426: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 7427: background-color: $mail_read_hover;
7428: }
1.938 bisitz 7429: */
1.795 www 7430:
1.938 bisitz 7431: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 7432: background-color: $mail_replied;
7433: }
1.795 www 7434:
1.938 bisitz 7435: /*
7436: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 7437: background-color: $mail_replied_hover;
7438: }
1.938 bisitz 7439: */
1.795 www 7440:
1.938 bisitz 7441: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 7442: background-color: $mail_other;
7443: }
1.795 www 7444:
1.938 bisitz 7445: /*
7446: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 7447: background-color: $mail_other_hover;
7448: }
1.938 bisitz 7449: */
1.494 raeburn 7450:
1.777 tempelho 7451: table.LC_data_table tr > td.LC_browser_file,
7452: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 7453: background: #AAEE77;
1.389 albertel 7454: }
1.795 www 7455:
1.777 tempelho 7456: table.LC_data_table tr > td.LC_browser_file_locked,
7457: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7458: background: #FFAA99;
1.387 albertel 7459: }
1.795 www 7460:
1.777 tempelho 7461: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7462: background: #888888;
1.779 bisitz 7463: }
1.795 www 7464:
1.777 tempelho 7465: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7466: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7467: background: #F8F866;
1.777 tempelho 7468: }
1.795 www 7469:
1.696 bisitz 7470: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7471: background: #E0E8FF;
1.387 albertel 7472: }
1.696 bisitz 7473:
1.707 bisitz 7474: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7475: /* background: #77FF77; */
1.707 bisitz 7476: }
1.795 www 7477:
1.707 bisitz 7478: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7479: border-right: 8px solid #FFFF77;
1.707 bisitz 7480: }
1.795 www 7481:
1.707 bisitz 7482: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7483: border-right: 8px solid #FFAA77;
1.707 bisitz 7484: }
1.795 www 7485:
1.707 bisitz 7486: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7487: border-right: 8px solid #FF7777;
1.707 bisitz 7488: }
1.795 www 7489:
1.707 bisitz 7490: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7491: border-right: 8px solid #AAFF77;
1.707 bisitz 7492: }
1.795 www 7493:
1.707 bisitz 7494: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7495: border-right: 8px solid #11CC55;
1.707 bisitz 7496: }
7497:
1.388 albertel 7498: span.LC_current_location {
1.701 harmsja 7499: font-size:larger;
1.388 albertel 7500: background: $pgbg;
7501: }
1.387 albertel 7502:
1.1029 www 7503: span.LC_current_nav_location {
7504: font-weight:bold;
7505: background: $sidebg;
7506: }
7507:
1.395 albertel 7508: span.LC_parm_menu_item {
7509: font-size: larger;
7510: }
1.795 www 7511:
1.395 albertel 7512: span.LC_parm_scope_all {
7513: color: red;
7514: }
1.795 www 7515:
1.395 albertel 7516: span.LC_parm_scope_folder {
7517: color: green;
7518: }
1.795 www 7519:
1.395 albertel 7520: span.LC_parm_scope_resource {
7521: color: orange;
7522: }
1.795 www 7523:
1.395 albertel 7524: span.LC_parm_part {
7525: color: blue;
7526: }
1.795 www 7527:
1.911 bisitz 7528: span.LC_parm_folder,
7529: span.LC_parm_symb {
1.395 albertel 7530: font-size: x-small;
7531: font-family: $mono;
7532: color: #AAAAAA;
7533: }
7534:
1.977 bisitz 7535: ul.LC_parm_parmlist li {
7536: display: inline-block;
7537: padding: 0.3em 0.8em;
7538: vertical-align: top;
7539: width: 150px;
7540: border-top:1px solid $lg_border_color;
7541: }
7542:
1.795 www 7543: td.LC_parm_overview_level_menu,
7544: td.LC_parm_overview_map_menu,
7545: td.LC_parm_overview_parm_selectors,
7546: td.LC_parm_overview_restrictions {
1.396 albertel 7547: border: 1px solid black;
7548: border-collapse: collapse;
7549: }
1.795 www 7550:
1.1285 raeburn 7551: span.LC_parm_recursive,
7552: td.LC_parm_recursive {
7553: font-weight: bold;
7554: font-size: smaller;
7555: }
7556:
1.396 albertel 7557: table.LC_parm_overview_restrictions td {
7558: border-width: 1px 4px 1px 4px;
7559: border-style: solid;
7560: border-color: $pgbg;
7561: text-align: center;
7562: }
1.795 www 7563:
1.396 albertel 7564: table.LC_parm_overview_restrictions th {
7565: background: $tabbg;
7566: border-width: 1px 4px 1px 4px;
7567: border-style: solid;
7568: border-color: $pgbg;
7569: }
1.795 www 7570:
1.398 albertel 7571: table#LC_helpmenu {
1.803 bisitz 7572: border: none;
1.398 albertel 7573: height: 55px;
1.803 bisitz 7574: border-spacing: 0;
1.398 albertel 7575: }
7576:
7577: table#LC_helpmenu fieldset legend {
7578: font-size: larger;
7579: }
1.795 www 7580:
1.397 albertel 7581: table#LC_helpmenu_links {
7582: width: 100%;
7583: border: 1px solid black;
7584: background: $pgbg;
1.803 bisitz 7585: padding: 0;
1.397 albertel 7586: border-spacing: 1px;
7587: }
1.795 www 7588:
1.397 albertel 7589: table#LC_helpmenu_links tr td {
7590: padding: 1px;
7591: background: $tabbg;
1.399 albertel 7592: text-align: center;
7593: font-weight: bold;
1.397 albertel 7594: }
1.396 albertel 7595:
1.795 www 7596: table#LC_helpmenu_links a:link,
7597: table#LC_helpmenu_links a:visited,
1.397 albertel 7598: table#LC_helpmenu_links a:active {
7599: text-decoration: none;
7600: color: $font;
7601: }
1.795 www 7602:
1.397 albertel 7603: table#LC_helpmenu_links a:hover {
7604: text-decoration: underline;
7605: color: $vlink;
7606: }
1.396 albertel 7607:
1.417 albertel 7608: .LC_chrt_popup_exists {
7609: border: 1px solid #339933;
7610: margin: -1px;
7611: }
1.795 www 7612:
1.417 albertel 7613: .LC_chrt_popup_up {
7614: border: 1px solid yellow;
7615: margin: -1px;
7616: }
1.795 www 7617:
1.417 albertel 7618: .LC_chrt_popup {
7619: border: 1px solid #8888FF;
7620: background: #CCCCFF;
7621: }
1.795 www 7622:
1.421 albertel 7623: table.LC_pick_box {
7624: border-collapse: separate;
7625: background: white;
7626: border: 1px solid black;
7627: border-spacing: 1px;
7628: }
1.795 www 7629:
1.421 albertel 7630: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7631: background: $sidebg;
1.421 albertel 7632: font-weight: bold;
1.900 bisitz 7633: text-align: left;
1.740 bisitz 7634: vertical-align: top;
1.421 albertel 7635: width: 184px;
7636: padding: 8px;
7637: }
1.795 www 7638:
1.579 raeburn 7639: table.LC_pick_box td.LC_pick_box_value {
7640: text-align: left;
7641: padding: 8px;
7642: }
1.795 www 7643:
1.579 raeburn 7644: table.LC_pick_box td.LC_pick_box_select {
7645: text-align: left;
7646: padding: 8px;
7647: }
1.795 www 7648:
1.424 albertel 7649: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7650: padding: 0;
1.421 albertel 7651: height: 1px;
7652: background: black;
7653: }
1.795 www 7654:
1.421 albertel 7655: table.LC_pick_box td.LC_pick_box_submit {
7656: text-align: right;
7657: }
1.795 www 7658:
1.579 raeburn 7659: table.LC_pick_box td.LC_evenrow_value {
7660: text-align: left;
7661: padding: 8px;
7662: background-color: $data_table_light;
7663: }
1.795 www 7664:
1.579 raeburn 7665: table.LC_pick_box td.LC_oddrow_value {
7666: text-align: left;
7667: padding: 8px;
7668: background-color: $data_table_light;
7669: }
1.795 www 7670:
1.579 raeburn 7671: span.LC_helpform_receipt_cat {
7672: font-weight: bold;
7673: }
1.795 www 7674:
1.424 albertel 7675: table.LC_group_priv_box {
7676: background: white;
7677: border: 1px solid black;
7678: border-spacing: 1px;
7679: }
1.795 www 7680:
1.424 albertel 7681: table.LC_group_priv_box td.LC_pick_box_title {
7682: background: $tabbg;
7683: font-weight: bold;
7684: text-align: right;
7685: width: 184px;
7686: }
1.795 www 7687:
1.424 albertel 7688: table.LC_group_priv_box td.LC_groups_fixed {
7689: background: $data_table_light;
7690: text-align: center;
7691: }
1.795 www 7692:
1.424 albertel 7693: table.LC_group_priv_box td.LC_groups_optional {
7694: background: $data_table_dark;
7695: text-align: center;
7696: }
1.795 www 7697:
1.424 albertel 7698: table.LC_group_priv_box td.LC_groups_functionality {
7699: background: $data_table_darker;
7700: text-align: center;
7701: font-weight: bold;
7702: }
1.795 www 7703:
1.424 albertel 7704: table.LC_group_priv td {
7705: text-align: left;
1.803 bisitz 7706: padding: 0;
1.424 albertel 7707: }
7708:
7709: .LC_navbuttons {
7710: margin: 2ex 0ex 2ex 0ex;
7711: }
1.795 www 7712:
1.423 albertel 7713: .LC_topic_bar {
7714: font-weight: bold;
7715: background: $tabbg;
1.918 wenzelju 7716: margin: 1em 0em 1em 2em;
1.805 bisitz 7717: padding: 3px;
1.918 wenzelju 7718: font-size: 1.2em;
1.423 albertel 7719: }
1.795 www 7720:
1.423 albertel 7721: .LC_topic_bar span {
1.918 wenzelju 7722: left: 0.5em;
7723: position: absolute;
1.423 albertel 7724: vertical-align: middle;
1.918 wenzelju 7725: font-size: 1.2em;
1.423 albertel 7726: }
1.795 www 7727:
1.423 albertel 7728: table.LC_course_group_status {
7729: margin: 20px;
7730: }
1.795 www 7731:
1.423 albertel 7732: table.LC_status_selector td {
7733: vertical-align: top;
7734: text-align: center;
1.424 albertel 7735: padding: 4px;
7736: }
1.795 www 7737:
1.599 albertel 7738: div.LC_feedback_link {
1.616 albertel 7739: clear: both;
1.829 kalberla 7740: background: $sidebg;
1.779 bisitz 7741: width: 100%;
1.829 kalberla 7742: padding-bottom: 10px;
7743: border: 1px $tabbg solid;
1.833 kalberla 7744: height: 22px;
7745: line-height: 22px;
7746: padding-top: 5px;
7747: }
7748:
7749: div.LC_feedback_link img {
7750: height: 22px;
1.867 kalberla 7751: vertical-align:middle;
1.829 kalberla 7752: }
7753:
1.911 bisitz 7754: div.LC_feedback_link a {
1.829 kalberla 7755: text-decoration: none;
1.489 raeburn 7756: }
1.795 www 7757:
1.867 kalberla 7758: div.LC_comblock {
1.911 bisitz 7759: display:inline;
1.867 kalberla 7760: color:$font;
7761: font-size:90%;
7762: }
7763:
7764: div.LC_feedback_link div.LC_comblock {
7765: padding-left:5px;
7766: }
7767:
7768: div.LC_feedback_link div.LC_comblock a {
7769: color:$font;
7770: }
7771:
1.489 raeburn 7772: span.LC_feedback_link {
1.858 bisitz 7773: /* background: $feedback_link_bg; */
1.599 albertel 7774: font-size: larger;
7775: }
1.795 www 7776:
1.599 albertel 7777: span.LC_message_link {
1.858 bisitz 7778: /* background: $feedback_link_bg; */
1.599 albertel 7779: font-size: larger;
7780: position: absolute;
7781: right: 1em;
1.489 raeburn 7782: }
1.421 albertel 7783:
1.515 albertel 7784: table.LC_prior_tries {
1.524 albertel 7785: border: 1px solid #000000;
7786: border-collapse: separate;
7787: border-spacing: 1px;
1.515 albertel 7788: }
1.523 albertel 7789:
1.515 albertel 7790: table.LC_prior_tries td {
1.524 albertel 7791: padding: 2px;
1.515 albertel 7792: }
1.523 albertel 7793:
7794: .LC_answer_correct {
1.795 www 7795: background: lightgreen;
7796: color: darkgreen;
7797: padding: 6px;
1.523 albertel 7798: }
1.795 www 7799:
1.523 albertel 7800: .LC_answer_charged_try {
1.797 www 7801: background: #FFAAAA;
1.795 www 7802: color: darkred;
7803: padding: 6px;
1.523 albertel 7804: }
1.795 www 7805:
1.779 bisitz 7806: .LC_answer_not_charged_try,
1.523 albertel 7807: .LC_answer_no_grade,
7808: .LC_answer_late {
1.795 www 7809: background: lightyellow;
1.523 albertel 7810: color: black;
1.795 www 7811: padding: 6px;
1.523 albertel 7812: }
1.795 www 7813:
1.523 albertel 7814: .LC_answer_previous {
1.795 www 7815: background: lightblue;
7816: color: darkblue;
7817: padding: 6px;
1.523 albertel 7818: }
1.795 www 7819:
1.779 bisitz 7820: .LC_answer_no_message {
1.777 tempelho 7821: background: #FFFFFF;
7822: color: black;
1.795 www 7823: padding: 6px;
1.779 bisitz 7824: }
1.795 www 7825:
1.1334 raeburn 7826: .LC_answer_unknown,
7827: .LC_answer_warning {
1.779 bisitz 7828: background: orange;
7829: color: black;
1.795 www 7830: padding: 6px;
1.777 tempelho 7831: }
1.795 www 7832:
1.529 albertel 7833: span.LC_prior_numerical,
7834: span.LC_prior_string,
7835: span.LC_prior_custom,
7836: span.LC_prior_reaction,
7837: span.LC_prior_math {
1.925 bisitz 7838: font-family: $mono;
1.523 albertel 7839: white-space: pre;
7840: }
7841:
1.525 albertel 7842: span.LC_prior_string {
1.925 bisitz 7843: font-family: $mono;
1.525 albertel 7844: white-space: pre;
7845: }
7846:
1.523 albertel 7847: table.LC_prior_option {
7848: width: 100%;
7849: border-collapse: collapse;
7850: }
1.795 www 7851:
1.911 bisitz 7852: table.LC_prior_rank,
1.795 www 7853: table.LC_prior_match {
1.528 albertel 7854: border-collapse: collapse;
7855: }
1.795 www 7856:
1.528 albertel 7857: table.LC_prior_option tr td,
7858: table.LC_prior_rank tr td,
7859: table.LC_prior_match tr td {
1.524 albertel 7860: border: 1px solid #000000;
1.515 albertel 7861: }
7862:
1.855 bisitz 7863: .LC_nobreak {
1.544 albertel 7864: white-space: nowrap;
1.519 raeburn 7865: }
7866:
1.576 raeburn 7867: span.LC_cusr_emph {
7868: font-style: italic;
7869: }
7870:
1.633 raeburn 7871: span.LC_cusr_subheading {
7872: font-weight: normal;
7873: font-size: 85%;
7874: }
7875:
1.861 bisitz 7876: div.LC_docs_entry_move {
1.859 bisitz 7877: border: 1px solid #BBBBBB;
1.545 albertel 7878: background: #DDDDDD;
1.861 bisitz 7879: width: 22px;
1.859 bisitz 7880: padding: 1px;
7881: margin: 0;
1.545 albertel 7882: }
7883:
1.861 bisitz 7884: table.LC_data_table tr > td.LC_docs_entry_commands,
7885: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7886: font-size: x-small;
7887: }
1.795 www 7888:
1.861 bisitz 7889: .LC_docs_entry_parameter {
7890: white-space: nowrap;
7891: }
7892:
1.544 albertel 7893: .LC_docs_copy {
1.545 albertel 7894: color: #000099;
1.544 albertel 7895: }
1.795 www 7896:
1.544 albertel 7897: .LC_docs_cut {
1.545 albertel 7898: color: #550044;
1.544 albertel 7899: }
1.795 www 7900:
1.544 albertel 7901: .LC_docs_rename {
1.545 albertel 7902: color: #009900;
1.544 albertel 7903: }
1.795 www 7904:
1.544 albertel 7905: .LC_docs_remove {
1.545 albertel 7906: color: #990000;
7907: }
7908:
1.1284 raeburn 7909: .LC_docs_alias {
7910: color: #440055;
7911: }
7912:
1.1286 raeburn 7913: .LC_domprefs_email,
1.1284 raeburn 7914: .LC_docs_alias_name,
1.547 albertel 7915: .LC_docs_reinit_warn,
7916: .LC_docs_ext_edit {
7917: font-size: x-small;
7918: }
7919:
1.545 albertel 7920: table.LC_docs_adddocs td,
7921: table.LC_docs_adddocs th {
7922: border: 1px solid #BBBBBB;
7923: padding: 4px;
7924: background: #DDDDDD;
1.543 albertel 7925: }
7926:
1.584 albertel 7927: table.LC_sty_begin {
7928: background: #BBFFBB;
7929: }
1.795 www 7930:
1.584 albertel 7931: table.LC_sty_end {
7932: background: #FFBBBB;
7933: }
7934:
1.589 raeburn 7935: table.LC_double_column {
1.803 bisitz 7936: border-width: 0;
1.589 raeburn 7937: border-collapse: collapse;
7938: width: 100%;
7939: padding: 2px;
7940: }
7941:
7942: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7943: top: 2px;
1.589 raeburn 7944: left: 2px;
7945: width: 47%;
7946: vertical-align: top;
7947: }
7948:
7949: table.LC_double_column tr td.LC_right_col {
7950: top: 2px;
1.779 bisitz 7951: right: 2px;
1.589 raeburn 7952: width: 47%;
7953: vertical-align: top;
7954: }
7955:
1.591 raeburn 7956: div.LC_left_float {
7957: float: left;
7958: padding-right: 5%;
1.597 albertel 7959: padding-bottom: 4px;
1.591 raeburn 7960: }
7961:
7962: div.LC_clear_float_header {
1.597 albertel 7963: padding-bottom: 2px;
1.591 raeburn 7964: }
7965:
7966: div.LC_clear_float_footer {
1.597 albertel 7967: padding-top: 10px;
1.591 raeburn 7968: clear: both;
7969: }
7970:
1.597 albertel 7971: div.LC_grade_show_user {
1.941 bisitz 7972: /* border-left: 5px solid $sidebg; */
7973: border-top: 5px solid #000000;
7974: margin: 50px 0 0 0;
1.936 bisitz 7975: padding: 15px 0 5px 10px;
1.597 albertel 7976: }
1.795 www 7977:
1.936 bisitz 7978: div.LC_grade_show_user_odd_row {
1.941 bisitz 7979: /* border-left: 5px solid #000000; */
7980: }
7981:
7982: div.LC_grade_show_user div.LC_Box {
7983: margin-right: 50px;
1.597 albertel 7984: }
7985:
7986: div.LC_grade_submissions,
7987: div.LC_grade_message_center,
1.936 bisitz 7988: div.LC_grade_info_links {
1.597 albertel 7989: margin: 5px;
7990: width: 99%;
7991: background: #FFFFFF;
7992: }
1.795 www 7993:
1.597 albertel 7994: div.LC_grade_submissions_header,
1.936 bisitz 7995: div.LC_grade_message_center_header {
1.705 tempelho 7996: font-weight: bold;
7997: font-size: large;
1.597 albertel 7998: }
1.795 www 7999:
1.597 albertel 8000: div.LC_grade_submissions_body,
1.936 bisitz 8001: div.LC_grade_message_center_body {
1.597 albertel 8002: border: 1px solid black;
8003: width: 99%;
8004: background: #FFFFFF;
8005: }
1.795 www 8006:
1.613 albertel 8007: table.LC_scantron_action {
8008: width: 100%;
8009: }
1.795 www 8010:
1.613 albertel 8011: table.LC_scantron_action tr th {
1.698 harmsja 8012: font-weight:bold;
8013: font-style:normal;
1.613 albertel 8014: }
1.795 www 8015:
1.779 bisitz 8016: .LC_edit_problem_header,
1.614 albertel 8017: div.LC_edit_problem_footer {
1.705 tempelho 8018: font-weight: normal;
8019: font-size: medium;
1.602 albertel 8020: margin: 2px;
1.1060 bisitz 8021: background-color: $sidebg;
1.600 albertel 8022: }
1.795 www 8023:
1.600 albertel 8024: div.LC_edit_problem_header,
1.602 albertel 8025: div.LC_edit_problem_header div,
1.614 albertel 8026: div.LC_edit_problem_footer,
8027: div.LC_edit_problem_footer div,
1.602 albertel 8028: div.LC_edit_problem_editxml_header,
8029: div.LC_edit_problem_editxml_header div {
1.1205 golterma 8030: z-index: 100;
1.600 albertel 8031: }
1.795 www 8032:
1.600 albertel 8033: div.LC_edit_problem_header_title {
1.705 tempelho 8034: font-weight: bold;
8035: font-size: larger;
1.602 albertel 8036: background: $tabbg;
8037: padding: 3px;
1.1060 bisitz 8038: margin: 0 0 5px 0;
1.602 albertel 8039: }
1.795 www 8040:
1.602 albertel 8041: table.LC_edit_problem_header_title {
8042: width: 100%;
1.600 albertel 8043: background: $tabbg;
1.602 albertel 8044: }
8045:
1.1205 golterma 8046: div.LC_edit_actionbar {
8047: background-color: $sidebg;
1.1218 droeschl 8048: margin: 0;
8049: padding: 0;
8050: line-height: 200%;
1.602 albertel 8051: }
1.795 www 8052:
1.1218 droeschl 8053: div.LC_edit_actionbar div{
8054: padding: 0;
8055: margin: 0;
8056: display: inline-block;
1.600 albertel 8057: }
1.795 www 8058:
1.1124 bisitz 8059: .LC_edit_opt {
8060: padding-left: 1em;
8061: white-space: nowrap;
8062: }
8063:
1.1152 golterma 8064: .LC_edit_problem_latexhelper{
8065: text-align: right;
8066: }
8067:
8068: #LC_edit_problem_colorful div{
8069: margin-left: 40px;
8070: }
8071:
1.1205 golterma 8072: #LC_edit_problem_codemirror div{
8073: margin-left: 0px;
8074: }
8075:
1.911 bisitz 8076: img.stift {
1.803 bisitz 8077: border-width: 0;
8078: vertical-align: middle;
1.677 riegler 8079: }
1.680 riegler 8080:
1.923 bisitz 8081: table td.LC_mainmenu_col_fieldset {
1.680 riegler 8082: vertical-align: top;
1.777 tempelho 8083: }
1.795 www 8084:
1.716 raeburn 8085: div.LC_createcourse {
1.911 bisitz 8086: margin: 10px 10px 10px 10px;
1.716 raeburn 8087: }
8088:
1.917 raeburn 8089: .LC_dccid {
1.1130 raeburn 8090: float: right;
1.917 raeburn 8091: margin: 0.2em 0 0 0;
8092: padding: 0;
8093: font-size: 90%;
8094: display:none;
8095: }
8096:
1.897 wenzelju 8097: ol.LC_primary_menu a:hover,
1.721 harmsja 8098: ol#LC_MenuBreadcrumbs a:hover,
8099: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 8100: ul#LC_secondary_menu a:hover,
1.721 harmsja 8101: .LC_FormSectionClearButton input:hover
1.795 www 8102: ul.LC_TabContent li:hover a {
1.952 onken 8103: color:$button_hover;
1.911 bisitz 8104: text-decoration:none;
1.693 droeschl 8105: }
8106:
1.779 bisitz 8107: h1 {
1.911 bisitz 8108: padding: 0;
8109: line-height:130%;
1.693 droeschl 8110: }
1.698 harmsja 8111:
1.911 bisitz 8112: h2,
8113: h3,
8114: h4,
8115: h5,
8116: h6 {
8117: margin: 5px 0 5px 0;
8118: padding: 0;
8119: line-height:130%;
1.693 droeschl 8120: }
1.795 www 8121:
8122: .LC_hcell {
1.911 bisitz 8123: padding:3px 15px 3px 15px;
8124: margin: 0;
8125: background-color:$tabbg;
8126: color:$fontmenu;
8127: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 8128: }
1.795 www 8129:
1.840 bisitz 8130: .LC_Box > .LC_hcell {
1.911 bisitz 8131: margin: 0 -10px 10px -10px;
1.835 bisitz 8132: }
8133:
1.721 harmsja 8134: .LC_noBorder {
1.911 bisitz 8135: border: 0;
1.698 harmsja 8136: }
1.693 droeschl 8137:
1.721 harmsja 8138: .LC_FormSectionClearButton input {
1.911 bisitz 8139: background-color:transparent;
8140: border: none;
8141: cursor:pointer;
8142: text-decoration:underline;
1.693 droeschl 8143: }
1.763 bisitz 8144:
8145: .LC_help_open_topic {
1.911 bisitz 8146: color: #FFFFFF;
8147: background-color: #EEEEFF;
8148: margin: 1px;
8149: padding: 4px;
8150: border: 1px solid #000033;
8151: white-space: nowrap;
8152: /* vertical-align: middle; */
1.759 neumanie 8153: }
1.693 droeschl 8154:
1.911 bisitz 8155: dl,
8156: ul,
8157: div,
8158: fieldset {
8159: margin: 10px 10px 10px 0;
8160: /* overflow: hidden; */
1.693 droeschl 8161: }
1.795 www 8162:
1.1404 raeburn 8163: fieldset#LC_selectuser {
8164: margin: 0;
8165: padding: 0;
8166: }
8167:
1.1211 raeburn 8168: article.geogebraweb div {
8169: margin: 0;
8170: }
8171:
1.838 bisitz 8172: fieldset > legend {
1.911 bisitz 8173: font-weight: bold;
8174: padding: 0 5px 0 5px;
1.838 bisitz 8175: }
8176:
1.813 bisitz 8177: #LC_nav_bar {
1.911 bisitz 8178: float: left;
1.995 raeburn 8179: background-color: $pgbg_or_bgcolor;
1.966 bisitz 8180: margin: 0 0 2px 0;
1.807 droeschl 8181: }
8182:
1.916 droeschl 8183: #LC_realm {
8184: margin: 0.2em 0 0 0;
8185: padding: 0;
8186: font-weight: bold;
8187: text-align: center;
1.995 raeburn 8188: background-color: $pgbg_or_bgcolor;
1.916 droeschl 8189: }
8190:
1.911 bisitz 8191: #LC_nav_bar em {
8192: font-weight: bold;
8193: font-style: normal;
1.807 droeschl 8194: }
8195:
1.897 wenzelju 8196: ol.LC_primary_menu {
1.934 droeschl 8197: margin: 0;
1.1076 raeburn 8198: padding: 0;
1.807 droeschl 8199: }
8200:
1.852 droeschl 8201: ol#LC_PathBreadcrumbs {
1.911 bisitz 8202: margin: 0;
1.693 droeschl 8203: }
8204:
1.897 wenzelju 8205: ol.LC_primary_menu li {
1.1076 raeburn 8206: color: RGB(80, 80, 80);
8207: vertical-align: middle;
8208: text-align: left;
8209: list-style: none;
1.1205 golterma 8210: position: relative;
1.1076 raeburn 8211: float: left;
1.1205 golterma 8212: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
8213: line-height: 1.5em;
1.1076 raeburn 8214: }
8215:
1.1205 golterma 8216: ol.LC_primary_menu li a,
8217: ol.LC_primary_menu li p {
1.1076 raeburn 8218: display: block;
8219: margin: 0;
8220: padding: 0 5px 0 10px;
8221: text-decoration: none;
8222: }
8223:
1.1205 golterma 8224: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
8225: display: inline-block;
8226: width: 95%;
8227: text-align: left;
8228: }
8229:
8230: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
8231: display: inline-block;
8232: width: 5%;
8233: float: right;
8234: text-align: right;
8235: font-size: 70%;
8236: }
8237:
8238: ol.LC_primary_menu ul {
1.1076 raeburn 8239: display: none;
1.1205 golterma 8240: width: 15em;
1.1076 raeburn 8241: background-color: $data_table_light;
1.1205 golterma 8242: position: absolute;
8243: top: 100%;
1.1076 raeburn 8244: }
8245:
1.1205 golterma 8246: ol.LC_primary_menu ul ul {
8247: left: 100%;
8248: top: 0;
8249: }
8250:
8251: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 8252: display: block;
8253: position: absolute;
8254: margin: 0;
8255: padding: 0;
1.1078 raeburn 8256: z-index: 2;
1.1076 raeburn 8257: }
8258:
8259: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 8260: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 8261: font-size: 90%;
1.911 bisitz 8262: vertical-align: top;
1.1076 raeburn 8263: float: none;
1.1079 raeburn 8264: border-left: 1px solid black;
8265: border-right: 1px solid black;
1.1205 golterma 8266: /* A dark bottom border to visualize different menu options;
8267: overwritten in the create_submenu routine for the last border-bottom of the menu */
8268: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 8269: }
8270:
1.1205 golterma 8271: ol.LC_primary_menu li li p:hover {
8272: color:$button_hover;
8273: text-decoration:none;
8274: background-color:$data_table_dark;
1.1076 raeburn 8275: }
8276:
8277: ol.LC_primary_menu li li a:hover {
8278: color:$button_hover;
8279: background-color:$data_table_dark;
1.693 droeschl 8280: }
8281:
1.1205 golterma 8282: /* Font-size equal to the size of the predecessors*/
8283: ol.LC_primary_menu li:hover li li {
8284: font-size: 100%;
8285: }
8286:
1.897 wenzelju 8287: ol.LC_primary_menu li img {
1.911 bisitz 8288: vertical-align: bottom;
1.934 droeschl 8289: height: 1.1em;
1.1077 raeburn 8290: margin: 0.2em 0 0 0;
1.693 droeschl 8291: }
8292:
1.897 wenzelju 8293: ol.LC_primary_menu a {
1.911 bisitz 8294: color: RGB(80, 80, 80);
8295: text-decoration: none;
1.693 droeschl 8296: }
1.795 www 8297:
1.949 droeschl 8298: ol.LC_primary_menu a.LC_new_message {
8299: font-weight:bold;
8300: color: darkred;
8301: }
8302:
1.975 raeburn 8303: ol.LC_docs_parameters {
8304: margin-left: 0;
8305: padding: 0;
8306: list-style: none;
8307: }
8308:
8309: ol.LC_docs_parameters li {
8310: margin: 0;
8311: padding-right: 20px;
8312: display: inline;
8313: }
8314:
1.976 raeburn 8315: ol.LC_docs_parameters li:before {
8316: content: "\\002022 \\0020";
8317: }
8318:
8319: li.LC_docs_parameters_title {
8320: font-weight: bold;
8321: }
8322:
8323: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
8324: content: "";
8325: }
8326:
1.897 wenzelju 8327: ul#LC_secondary_menu {
1.1107 raeburn 8328: clear: right;
1.911 bisitz 8329: color: $fontmenu;
8330: background: $tabbg;
8331: list-style: none;
8332: padding: 0;
8333: margin: 0;
8334: width: 100%;
1.995 raeburn 8335: text-align: left;
1.1107 raeburn 8336: float: left;
1.808 droeschl 8337: }
8338:
1.897 wenzelju 8339: ul#LC_secondary_menu li {
1.911 bisitz 8340: font-weight: bold;
8341: line-height: 1.8em;
1.1107 raeburn 8342: border-right: 1px solid black;
8343: float: left;
8344: }
8345:
8346: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
8347: background-color: $data_table_light;
8348: }
8349:
8350: ul#LC_secondary_menu li a {
1.911 bisitz 8351: padding: 0 0.8em;
1.1107 raeburn 8352: }
8353:
8354: ul#LC_secondary_menu li ul {
8355: display: none;
8356: }
8357:
8358: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
8359: display: block;
8360: position: absolute;
8361: margin: 0;
8362: padding: 0;
8363: list-style:none;
8364: float: none;
8365: background-color: $data_table_light;
8366: z-index: 2;
8367: margin-left: -1px;
8368: }
8369:
8370: ul#LC_secondary_menu li ul li {
8371: font-size: 90%;
8372: vertical-align: top;
8373: border-left: 1px solid black;
1.911 bisitz 8374: border-right: 1px solid black;
1.1119 raeburn 8375: background-color: $data_table_light;
1.1107 raeburn 8376: list-style:none;
8377: float: none;
8378: }
8379:
8380: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
8381: background-color: $data_table_dark;
1.807 droeschl 8382: }
8383:
1.847 tempelho 8384: ul.LC_TabContent {
1.911 bisitz 8385: display:block;
8386: background: $sidebg;
8387: border-bottom: solid 1px $lg_border_color;
8388: list-style:none;
1.1020 raeburn 8389: margin: -1px -10px 0 -10px;
1.911 bisitz 8390: padding: 0;
1.693 droeschl 8391: }
8392:
1.795 www 8393: ul.LC_TabContent li,
8394: ul.LC_TabContentBigger li {
1.911 bisitz 8395: float:left;
1.741 harmsja 8396: }
1.795 www 8397:
1.897 wenzelju 8398: ul#LC_secondary_menu li a {
1.911 bisitz 8399: color: $fontmenu;
8400: text-decoration: none;
1.693 droeschl 8401: }
1.795 www 8402:
1.721 harmsja 8403: ul.LC_TabContent {
1.952 onken 8404: min-height:20px;
1.721 harmsja 8405: }
1.795 www 8406:
8407: ul.LC_TabContent li {
1.911 bisitz 8408: vertical-align:middle;
1.959 onken 8409: padding: 0 16px 0 10px;
1.911 bisitz 8410: background-color:$tabbg;
8411: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 8412: border-left: solid 1px $font;
1.721 harmsja 8413: }
1.795 www 8414:
1.847 tempelho 8415: ul.LC_TabContent .right {
1.911 bisitz 8416: float:right;
1.847 tempelho 8417: }
8418:
1.911 bisitz 8419: ul.LC_TabContent li a,
8420: ul.LC_TabContent li {
8421: color:rgb(47,47,47);
8422: text-decoration:none;
8423: font-size:95%;
8424: font-weight:bold;
1.952 onken 8425: min-height:20px;
8426: }
8427:
1.959 onken 8428: ul.LC_TabContent li a:hover,
8429: ul.LC_TabContent li a:focus {
1.952 onken 8430: color: $button_hover;
1.959 onken 8431: background:none;
8432: outline:none;
1.952 onken 8433: }
8434:
8435: ul.LC_TabContent li:hover {
8436: color: $button_hover;
8437: cursor:pointer;
1.721 harmsja 8438: }
1.795 www 8439:
1.911 bisitz 8440: ul.LC_TabContent li.active {
1.952 onken 8441: color: $font;
1.911 bisitz 8442: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 8443: border-bottom:solid 1px #FFFFFF;
8444: cursor: default;
1.744 ehlerst 8445: }
1.795 www 8446:
1.959 onken 8447: ul.LC_TabContent li.active a {
8448: color:$font;
8449: background:#FFFFFF;
8450: outline: none;
8451: }
1.1047 raeburn 8452:
8453: ul.LC_TabContent li.goback {
8454: float: left;
8455: border-left: none;
8456: }
8457:
1.870 tempelho 8458: #maincoursedoc {
1.911 bisitz 8459: clear:both;
1.870 tempelho 8460: }
8461:
8462: ul.LC_TabContentBigger {
1.911 bisitz 8463: display:block;
8464: list-style:none;
8465: padding: 0;
1.870 tempelho 8466: }
8467:
1.795 www 8468: ul.LC_TabContentBigger li {
1.911 bisitz 8469: vertical-align:bottom;
8470: height: 30px;
8471: font-size:110%;
8472: font-weight:bold;
8473: color: #737373;
1.841 tempelho 8474: }
8475:
1.957 onken 8476: ul.LC_TabContentBigger li.active {
8477: position: relative;
8478: top: 1px;
8479: }
8480:
1.870 tempelho 8481: ul.LC_TabContentBigger li a {
1.911 bisitz 8482: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8483: height: 30px;
8484: line-height: 30px;
8485: text-align: center;
8486: display: block;
8487: text-decoration: none;
1.958 onken 8488: outline: none;
1.741 harmsja 8489: }
1.795 www 8490:
1.870 tempelho 8491: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8492: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8493: color:$font;
1.744 ehlerst 8494: }
1.795 www 8495:
1.870 tempelho 8496: ul.LC_TabContentBigger li b {
1.911 bisitz 8497: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8498: display: block;
8499: float: left;
8500: padding: 0 30px;
1.957 onken 8501: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8502: }
8503:
1.956 onken 8504: ul.LC_TabContentBigger li:hover b {
8505: color:$button_hover;
8506: }
8507:
1.870 tempelho 8508: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8509: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8510: color:$font;
1.957 onken 8511: border: 0;
1.741 harmsja 8512: }
1.693 droeschl 8513:
1.870 tempelho 8514:
1.862 bisitz 8515: ul.LC_CourseBreadcrumbs {
8516: background: $sidebg;
1.1020 raeburn 8517: height: 2em;
1.862 bisitz 8518: padding-left: 10px;
1.1020 raeburn 8519: margin: 0;
1.862 bisitz 8520: list-style-position: inside;
8521: }
8522:
1.911 bisitz 8523: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8524: ol#LC_PathBreadcrumbs {
1.911 bisitz 8525: padding-left: 10px;
8526: margin: 0;
1.933 droeschl 8527: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8528: }
8529:
1.911 bisitz 8530: ol#LC_MenuBreadcrumbs li,
8531: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8532: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8533: display: inline;
1.933 droeschl 8534: white-space: normal;
1.693 droeschl 8535: }
8536:
1.823 bisitz 8537: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8538: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8539: text-decoration: none;
8540: font-size:90%;
1.693 droeschl 8541: }
1.795 www 8542:
1.969 droeschl 8543: ol#LC_MenuBreadcrumbs h1 {
8544: display: inline;
8545: font-size: 90%;
8546: line-height: 2.5em;
8547: margin: 0;
8548: padding: 0;
8549: }
8550:
1.795 www 8551: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8552: text-decoration:none;
8553: font-size:100%;
8554: font-weight:bold;
1.693 droeschl 8555: }
1.795 www 8556:
1.840 bisitz 8557: .LC_Box {
1.911 bisitz 8558: border: solid 1px $lg_border_color;
8559: padding: 0 10px 10px 10px;
1.746 neumanie 8560: }
1.795 www 8561:
1.1020 raeburn 8562: .LC_DocsBox {
8563: border: solid 1px $lg_border_color;
8564: padding: 0 0 10px 10px;
8565: }
8566:
1.795 www 8567: .LC_AboutMe_Image {
1.911 bisitz 8568: float:left;
8569: margin-right:10px;
1.747 neumanie 8570: }
1.795 www 8571:
8572: .LC_Clear_AboutMe_Image {
1.911 bisitz 8573: clear:left;
1.747 neumanie 8574: }
1.795 www 8575:
1.721 harmsja 8576: dl.LC_ListStyleClean dt {
1.911 bisitz 8577: padding-right: 5px;
8578: display: table-header-group;
1.693 droeschl 8579: }
8580:
1.721 harmsja 8581: dl.LC_ListStyleClean dd {
1.911 bisitz 8582: display: table-row;
1.693 droeschl 8583: }
8584:
1.721 harmsja 8585: .LC_ListStyleClean,
8586: .LC_ListStyleSimple,
8587: .LC_ListStyleNormal,
1.795 www 8588: .LC_ListStyleSpecial {
1.911 bisitz 8589: /* display:block; */
8590: list-style-position: inside;
8591: list-style-type: none;
8592: overflow: hidden;
8593: padding: 0;
1.693 droeschl 8594: }
8595:
1.721 harmsja 8596: .LC_ListStyleSimple li,
8597: .LC_ListStyleSimple dd,
8598: .LC_ListStyleNormal li,
8599: .LC_ListStyleNormal dd,
8600: .LC_ListStyleSpecial li,
1.795 www 8601: .LC_ListStyleSpecial dd {
1.911 bisitz 8602: margin: 0;
8603: padding: 5px 5px 5px 10px;
8604: clear: both;
1.693 droeschl 8605: }
8606:
1.721 harmsja 8607: .LC_ListStyleClean li,
8608: .LC_ListStyleClean dd {
1.911 bisitz 8609: padding-top: 0;
8610: padding-bottom: 0;
1.693 droeschl 8611: }
8612:
1.721 harmsja 8613: .LC_ListStyleSimple dd,
1.795 www 8614: .LC_ListStyleSimple li {
1.911 bisitz 8615: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8616: }
8617:
1.721 harmsja 8618: .LC_ListStyleSpecial li,
8619: .LC_ListStyleSpecial dd {
1.911 bisitz 8620: list-style-type: none;
8621: background-color: RGB(220, 220, 220);
8622: margin-bottom: 4px;
1.693 droeschl 8623: }
8624:
1.721 harmsja 8625: table.LC_SimpleTable {
1.911 bisitz 8626: margin:5px;
8627: border:solid 1px $lg_border_color;
1.795 www 8628: }
1.693 droeschl 8629:
1.721 harmsja 8630: table.LC_SimpleTable tr {
1.911 bisitz 8631: padding: 0;
8632: border:solid 1px $lg_border_color;
1.693 droeschl 8633: }
1.795 www 8634:
8635: table.LC_SimpleTable thead {
1.911 bisitz 8636: background:rgb(220,220,220);
1.693 droeschl 8637: }
8638:
1.721 harmsja 8639: div.LC_columnSection {
1.911 bisitz 8640: display: block;
8641: clear: both;
8642: overflow: hidden;
8643: margin: 0;
1.693 droeschl 8644: }
8645:
1.721 harmsja 8646: div.LC_columnSection>* {
1.911 bisitz 8647: float: left;
8648: margin: 10px 20px 10px 0;
8649: overflow:hidden;
1.693 droeschl 8650: }
1.721 harmsja 8651:
1.795 www 8652: table em {
1.911 bisitz 8653: font-weight: bold;
8654: font-style: normal;
1.748 schulted 8655: }
1.795 www 8656:
1.779 bisitz 8657: table.LC_tableBrowseRes,
1.795 www 8658: table.LC_tableOfContent {
1.911 bisitz 8659: border:none;
8660: border-spacing: 1px;
8661: padding: 3px;
8662: background-color: #FFFFFF;
8663: font-size: 90%;
1.753 droeschl 8664: }
1.789 droeschl 8665:
1.911 bisitz 8666: table.LC_tableOfContent {
8667: border-collapse: collapse;
1.789 droeschl 8668: }
8669:
1.771 droeschl 8670: table.LC_tableBrowseRes a,
1.768 schulted 8671: table.LC_tableOfContent a {
1.911 bisitz 8672: background-color: transparent;
8673: text-decoration: none;
1.753 droeschl 8674: }
8675:
1.795 www 8676: table.LC_tableOfContent img {
1.911 bisitz 8677: border: none;
8678: height: 1.3em;
8679: vertical-align: text-bottom;
8680: margin-right: 0.3em;
1.753 droeschl 8681: }
1.757 schulted 8682:
1.795 www 8683: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8684: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8685: }
8686:
1.795 www 8687: a#LC_content_toolbar_everything {
1.911 bisitz 8688: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8689: }
8690:
1.795 www 8691: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8692: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8693: }
8694:
1.795 www 8695: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8696: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8697: }
8698:
1.795 www 8699: a#LC_content_toolbar_changefolder {
1.911 bisitz 8700: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8701: }
8702:
1.795 www 8703: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8704: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8705: }
8706:
1.1043 raeburn 8707: a#LC_content_toolbar_edittoplevel {
8708: background-image:url(/res/adm/pages/edittoplevel.gif);
8709: }
8710:
1.1384 raeburn 8711: a#LC_content_toolbar_printout {
8712: background-image:url(/res/adm/pages/printout.gif);
8713: }
8714:
1.795 www 8715: ul#LC_toolbar li a:hover {
1.911 bisitz 8716: background-position: bottom center;
1.757 schulted 8717: }
8718:
1.795 www 8719: ul#LC_toolbar {
1.911 bisitz 8720: padding: 0;
8721: margin: 2px;
8722: list-style:none;
8723: position:relative;
8724: background-color:white;
1.1082 raeburn 8725: overflow: auto;
1.757 schulted 8726: }
8727:
1.795 www 8728: ul#LC_toolbar li {
1.911 bisitz 8729: border:1px solid white;
8730: padding: 0;
8731: margin: 0;
8732: float: left;
8733: display:inline;
8734: vertical-align:middle;
1.1082 raeburn 8735: white-space: nowrap;
1.911 bisitz 8736: }
1.757 schulted 8737:
1.783 amueller 8738:
1.795 www 8739: a.LC_toolbarItem {
1.911 bisitz 8740: display:block;
8741: padding: 0;
8742: margin: 0;
8743: height: 32px;
8744: width: 32px;
8745: color:white;
8746: border: none;
8747: background-repeat:no-repeat;
8748: background-color:transparent;
1.757 schulted 8749: }
8750:
1.915 droeschl 8751: ul.LC_funclist {
8752: margin: 0;
8753: padding: 0.5em 1em 0.5em 0;
8754: }
8755:
1.933 droeschl 8756: ul.LC_funclist > li:first-child {
8757: font-weight:bold;
8758: margin-left:0.8em;
8759: }
8760:
1.915 droeschl 8761: ul.LC_funclist + ul.LC_funclist {
8762: /*
8763: left border as a seperator if we have more than
8764: one list
8765: */
8766: border-left: 1px solid $sidebg;
8767: /*
8768: this hides the left border behind the border of the
8769: outer box if element is wrapped to the next 'line'
8770: */
8771: margin-left: -1px;
8772: }
8773:
1.843 bisitz 8774: ul.LC_funclist li {
1.915 droeschl 8775: display: inline;
1.782 bisitz 8776: white-space: nowrap;
1.915 droeschl 8777: margin: 0 0 0 25px;
8778: line-height: 150%;
1.782 bisitz 8779: }
8780:
1.974 wenzelju 8781: .LC_hidden {
8782: display: none;
8783: }
8784:
1.1030 www 8785: .LCmodal-overlay {
8786: position:fixed;
8787: top:0;
8788: right:0;
8789: bottom:0;
8790: left:0;
8791: height:100%;
8792: width:100%;
8793: margin:0;
8794: padding:0;
8795: background:#999;
8796: opacity:.75;
8797: filter: alpha(opacity=75);
8798: -moz-opacity: 0.75;
8799: z-index:101;
8800: }
8801:
8802: * html .LCmodal-overlay {
8803: position: absolute;
8804: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8805: }
8806:
8807: .LCmodal-window {
8808: position:fixed;
8809: top:50%;
8810: left:50%;
8811: margin:0;
8812: padding:0;
8813: z-index:102;
8814: }
8815:
8816: * html .LCmodal-window {
8817: position:absolute;
8818: }
8819:
8820: .LCclose-window {
8821: position:absolute;
8822: width:32px;
8823: height:32px;
8824: right:8px;
8825: top:8px;
8826: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8827: text-indent:-99999px;
8828: overflow:hidden;
8829: cursor:pointer;
8830: }
8831:
1.1369 raeburn 8832: .LCisDisabled {
8833: cursor: not-allowed;
8834: opacity: 0.5;
8835: }
8836:
8837: a[aria-disabled="true"] {
8838: color: currentColor;
8839: display: inline-block; /* For IE11/ MS Edge bug */
8840: pointer-events: none;
8841: text-decoration: none;
8842: }
8843:
1.1335 raeburn 8844: pre.LC_wordwrap {
8845: white-space: pre-wrap;
8846: white-space: -moz-pre-wrap;
8847: white-space: -pre-wrap;
8848: white-space: -o-pre-wrap;
8849: word-wrap: break-word;
8850: }
8851:
1.1100 raeburn 8852: /*
1.1231 damieng 8853: styles used for response display
8854: */
8855: div.LC_radiofoil, div.LC_rankfoil {
8856: margin: .5em 0em .5em 0em;
8857: }
8858: table.LC_itemgroup {
8859: margin-top: 1em;
8860: }
8861:
8862: /*
1.1100 raeburn 8863: styles used by TTH when "Default set of options to pass to tth/m
8864: when converting TeX" in course settings has been set
8865:
8866: option passed: -t
8867:
8868: */
8869:
8870: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8871: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8872: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8873: td div.norm {line-height:normal;}
8874:
8875: /*
8876: option passed -y3
8877: */
8878:
8879: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8880: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8881: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8882:
1.1230 damieng 8883: /*
8884: sections with roles, for content only
8885: */
8886: section[class^="role-"] {
8887: padding-left: 10px;
8888: padding-right: 5px;
8889: margin-top: 8px;
8890: margin-bottom: 8px;
8891: border: 1px solid #2A4;
8892: border-radius: 5px;
8893: box-shadow: 0px 1px 1px #BBB;
8894: }
8895: section[class^="role-"]>h1 {
8896: position: relative;
8897: margin: 0px;
8898: padding-top: 10px;
8899: padding-left: 40px;
8900: }
8901: section[class^="role-"]>h1:before {
8902: position: absolute;
8903: left: -5px;
8904: top: 5px;
8905: }
8906: section.role-activity>h1:before {
8907: content:url('/adm/daxe/images/section_icons/activity.png');
8908: }
8909: section.role-advice>h1:before {
8910: content:url('/adm/daxe/images/section_icons/advice.png');
8911: }
8912: section.role-bibliography>h1:before {
8913: content:url('/adm/daxe/images/section_icons/bibliography.png');
8914: }
8915: section.role-citation>h1:before {
8916: content:url('/adm/daxe/images/section_icons/citation.png');
8917: }
8918: section.role-conclusion>h1:before {
8919: content:url('/adm/daxe/images/section_icons/conclusion.png');
8920: }
8921: section.role-definition>h1:before {
8922: content:url('/adm/daxe/images/section_icons/definition.png');
8923: }
8924: section.role-demonstration>h1:before {
8925: content:url('/adm/daxe/images/section_icons/demonstration.png');
8926: }
8927: section.role-example>h1:before {
8928: content:url('/adm/daxe/images/section_icons/example.png');
8929: }
8930: section.role-explanation>h1:before {
8931: content:url('/adm/daxe/images/section_icons/explanation.png');
8932: }
8933: section.role-introduction>h1:before {
8934: content:url('/adm/daxe/images/section_icons/introduction.png');
8935: }
8936: section.role-method>h1:before {
8937: content:url('/adm/daxe/images/section_icons/method.png');
8938: }
8939: section.role-more_information>h1:before {
8940: content:url('/adm/daxe/images/section_icons/more_information.png');
8941: }
8942: section.role-objectives>h1:before {
8943: content:url('/adm/daxe/images/section_icons/objectives.png');
8944: }
8945: section.role-prerequisites>h1:before {
8946: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8947: }
8948: section.role-remark>h1:before {
8949: content:url('/adm/daxe/images/section_icons/remark.png');
8950: }
8951: section.role-reminder>h1:before {
8952: content:url('/adm/daxe/images/section_icons/reminder.png');
8953: }
8954: section.role-summary>h1:before {
8955: content:url('/adm/daxe/images/section_icons/summary.png');
8956: }
8957: section.role-syntax>h1:before {
8958: content:url('/adm/daxe/images/section_icons/syntax.png');
8959: }
8960: section.role-warning>h1:before {
8961: content:url('/adm/daxe/images/section_icons/warning.png');
8962: }
8963:
1.1269 raeburn 8964: #LC_minitab_header {
8965: float:left;
8966: width:100%;
8967: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8968: font-size:93%;
8969: line-height:normal;
8970: margin: 0.5em 0 0.5em 0;
8971: }
8972: #LC_minitab_header ul {
8973: margin:0;
8974: padding:10px 10px 0;
8975: list-style:none;
8976: }
8977: #LC_minitab_header li {
8978: float:left;
8979: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8980: margin:0;
8981: padding:0 0 0 9px;
8982: }
8983: #LC_minitab_header a {
8984: display:block;
8985: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8986: padding:5px 15px 4px 6px;
8987: }
8988: #LC_minitab_header #LC_current_minitab {
8989: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8990: }
8991: #LC_minitab_header #LC_current_minitab a {
8992: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8993: padding-bottom:5px;
8994: }
8995:
8996:
1.343 albertel 8997: END
8998: }
8999:
1.306 albertel 9000: =pod
9001:
9002: =item * &headtag()
9003:
9004: Returns a uniform footer for LON-CAPA web pages.
9005:
1.307 albertel 9006: Inputs: $title - optional title for the head
9007: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 9008: $args - optional arguments
1.319 albertel 9009: force_register - if is true call registerurl so the remote is
9010: informed
1.415 albertel 9011: redirect -> array ref of
9012: 1- seconds before redirect occurs
9013: 2- url to redirect to
9014: 3- whether the side effect should occur
1.315 albertel 9015: (side effect of setting
9016: $env{'internal.head.redirect'} to the url
1.1386 raeburn 9017: redirected to)
9018: 4- whether the redirect target should be
9019: the opener of the current (pop-up)
9020: window (side effect of setting
9021: $env{'internal.head.to_opener'} to
9022: 1, if true.
1.1388 raeburn 9023: 5- whether encrypt check should be skipped
1.352 albertel 9024: domain -> force to color decorate a page for a specific
9025: domain
9026: function -> force usage of a specific rolish color scheme
9027: bgcolor -> override the default page bgcolor
1.460 albertel 9028: no_auto_mt_title
9029: -> prevent &mt()ing the title arg
1.464 albertel 9030:
1.306 albertel 9031: =cut
9032:
9033: sub headtag {
1.313 albertel 9034: my ($title,$head_extra,$args) = @_;
1.306 albertel 9035:
1.363 albertel 9036: my $function = $args->{'function'} || &get_users_function();
9037: my $domain = $args->{'domain'} || &determinedomain();
9038: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 9039: my $httphost = $args->{'use_absolute'};
1.418 albertel 9040: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 9041: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 9042: #time(),
1.418 albertel 9043: $env{'environment.color.timestamp'},
1.363 albertel 9044: $function,$domain,$bgcolor);
9045:
1.369 www 9046: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 9047:
1.308 albertel 9048: my $result =
9049: '<head>'.
1.1160 raeburn 9050: &font_settings($args);
1.319 albertel 9051:
1.1188 raeburn 9052: my $inhibitprint;
9053: if ($args->{'print_suppress'}) {
9054: $inhibitprint = &print_suppression();
9055: }
1.1064 raeburn 9056:
1.461 albertel 9057: if (!$args->{'frameset'}) {
9058: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
9059: }
1.962 droeschl 9060: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
9061: $result .= Apache::lonxml::display_title();
1.319 albertel 9062: }
1.436 albertel 9063: if (!$args->{'no_nav_bar'}
9064: && !$args->{'only_body'}
9065: && !$args->{'frameset'}) {
1.1154 raeburn 9066: $result .= &help_menu_js($httphost);
1.1032 www 9067: $result.=&modal_window();
1.1038 www 9068: $result.=&togglebox_script();
1.1034 www 9069: $result.=&wishlist_window();
1.1041 www 9070: $result.=&LCprogressbarUpdate_script();
1.1034 www 9071: } else {
9072: if ($args->{'add_modal'}) {
9073: $result.=&modal_window();
9074: }
9075: if ($args->{'add_wishlist'}) {
9076: $result.=&wishlist_window();
9077: }
1.1038 www 9078: if ($args->{'add_togglebox'}) {
9079: $result.=&togglebox_script();
9080: }
1.1041 www 9081: if ($args->{'add_progressbar'}) {
9082: $result.=&LCprogressbarUpdate_script();
9083: }
1.436 albertel 9084: }
1.314 albertel 9085: if (ref($args->{'redirect'})) {
1.1388 raeburn 9086: my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
9087: if (!$skip_enc_check) {
9088: $url = &Apache::lonenc::check_encrypt($url);
9089: }
1.414 albertel 9090: if (!$inhibit_continue) {
9091: $env{'internal.head.redirect'} = $url;
9092: }
1.1386 raeburn 9093: $result.=<<"ADDMETA";
1.313 albertel 9094: <meta http-equiv="pragma" content="no-cache" />
1.1386 raeburn 9095: ADDMETA
9096: if ($to_opener) {
9097: $env{'internal.head.to_opener'} = 1;
9098: my $dest = &js_escape($url);
9099: my $timeout = int($time * 1000);
9100: $result .=<<"ENDJS";
9101: <script type="text/javascript">
9102: // <![CDATA[
9103: function LC_To_Opener() {
9104: var dest = '$dest';
9105: if (dest != '') {
9106: if (window.opener != null && !window.opener.closed) {
9107: window.opener.location.href=dest;
9108: window.close();
9109: } else {
9110: window.location.href=dest;
9111: }
9112: }
9113: }
9114: \$(document).ready(function () {
9115: setTimeout('LC_To_Opener()',$timeout);
9116: });
9117: // ]]>
9118: </script>
9119: ENDJS
9120: } else {
9121: $result.=<<"ADDMETA";
1.344 albertel 9122: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 9123: ADDMETA
1.1386 raeburn 9124: }
1.1210 raeburn 9125: } else {
9126: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
9127: my $requrl = $env{'request.uri'};
9128: if ($requrl eq '') {
9129: $requrl = $ENV{'REQUEST_URI'};
9130: $requrl =~ s/\?.+$//;
9131: }
9132: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
9133: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
9134: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
9135: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
9136: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
9137: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 9138: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 9139: my ($offload,$offloadoth);
1.1210 raeburn 9140: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
9141: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 9142: $offload = 1;
1.1353 raeburn 9143: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9144: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9145: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9146: $offloadoth = 1;
9147: $dom_in_use = $env{'user.domain'};
9148: }
9149: }
1.1340 raeburn 9150: }
9151: }
9152: unless ($offload) {
9153: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
9154: if ($domdefs{'offloadoth'}{$lonhost}) {
9155: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
9156: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
9157: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
9158: $offload = 1;
1.1352 raeburn 9159: $offloadoth = 1;
1.1340 raeburn 9160: $dom_in_use = $env{'user.domain'};
9161: }
1.1210 raeburn 9162: }
1.1340 raeburn 9163: }
9164: }
9165: }
9166: if ($offload) {
1.1358 raeburn 9167: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1352 raeburn 9168: if (($newserver eq '') && ($offloadoth)) {
9169: my @domains = &Apache::lonnet::current_machine_domains();
9170: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
9171: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
9172: }
9173: }
1.1340 raeburn 9174: if (($newserver) && ($newserver ne $lonhost)) {
9175: my $numsec = 5;
9176: my $timeout = $numsec * 1000;
9177: my ($newurl,$locknum,%locks,$msg);
9178: if ($env{'request.role.adv'}) {
9179: ($locknum,%locks) = &Apache::lonnet::get_locks();
9180: }
9181: my $disable_submit = 0;
9182: if ($requrl =~ /$LONCAPA::assess_re/) {
9183: $disable_submit = 1;
9184: }
9185: if ($locknum) {
9186: my @lockinfo = sort(values(%locks));
1.1354 raeburn 9187: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 9188: join(", ",sort(values(%locks)))."\n";
9189: if (&show_course()) {
9190: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
9191: } else {
9192: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 9193: }
1.1340 raeburn 9194: } else {
9195: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
9196: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
9197: }
9198: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
9199: $newurl = '/adm/switchserver?otherserver='.$newserver;
9200: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
9201: $newurl .= '&role='.$env{'request.role'};
9202: }
9203: if ($env{'request.symb'}) {
9204: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
9205: if ($shownsymb =~ m{^/enc/}) {
9206: my $reqdmajor = 2;
9207: my $reqdminor = 11;
9208: my $reqdsubminor = 3;
9209: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
9210: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
9211: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
9212: if (($major eq '' && $minor eq '') ||
9213: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
9214: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
9215: ($reqdsubminor > $subminor))))) {
9216: undef($shownsymb);
9217: }
1.1210 raeburn 9218: }
1.1340 raeburn 9219: if ($shownsymb) {
9220: &js_escape(\$shownsymb);
9221: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 9222: }
1.1340 raeburn 9223: } else {
9224: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
9225: &js_escape(\$shownurl);
9226: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 9227: }
1.1340 raeburn 9228: }
9229: &js_escape(\$msg);
9230: $result.=<<OFFLOAD
1.1210 raeburn 9231: <meta http-equiv="pragma" content="no-cache" />
9232: <script type="text/javascript">
1.1215 raeburn 9233: // <![CDATA[
1.1210 raeburn 9234: function LC_Offload_Now() {
9235: var dest = "$newurl";
9236: if (dest != '') {
9237: window.location.href="$newurl";
9238: }
9239: }
1.1214 raeburn 9240: \$(document).ready(function () {
9241: window.alert('$msg');
9242: if ($disable_submit) {
1.1210 raeburn 9243: \$(".LC_hwk_submit").prop("disabled", true);
9244: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 9245: }
9246: setTimeout('LC_Offload_Now()', $timeout);
9247: });
1.1215 raeburn 9248: // ]]>
1.1210 raeburn 9249: </script>
9250: OFFLOAD
9251: }
9252: }
9253: }
9254: }
9255: }
1.313 albertel 9256: }
1.306 albertel 9257: if (!defined($title)) {
9258: $title = 'The LearningOnline Network with CAPA';
9259: }
1.460 albertel 9260: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
9261: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 9262: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
9263: if (!$args->{'frameset'}) {
9264: $result .= ' /';
9265: }
9266: $result .= '>'
1.1064 raeburn 9267: .$inhibitprint
1.414 albertel 9268: .$head_extra;
1.1242 raeburn 9269: my $clientmobile;
9270: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
9271: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
9272: } else {
9273: $clientmobile = $env{'browser.mobile'};
9274: }
9275: if ($clientmobile) {
1.1137 raeburn 9276: $result .= '
9277: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
9278: <meta name="apple-mobile-web-app-capable" content="yes" />';
9279: }
1.1278 raeburn 9280: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 9281: return $result.'</head>';
1.306 albertel 9282: }
9283:
9284: =pod
9285:
1.340 albertel 9286: =item * &font_settings()
9287:
9288: Returns neccessary <meta> to set the proper encoding
9289:
1.1160 raeburn 9290: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 9291:
9292: =cut
9293:
9294: sub font_settings {
1.1160 raeburn 9295: my ($args) = @_;
1.340 albertel 9296: my $headerstring='';
1.1160 raeburn 9297: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
9298: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 9299: $headerstring.=
9300: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
9301: if (!$args->{'frameset'}) {
9302: $headerstring.= ' /';
9303: }
9304: $headerstring .= '>'."\n";
1.340 albertel 9305: }
9306: return $headerstring;
9307: }
9308:
1.341 albertel 9309: =pod
9310:
1.1064 raeburn 9311: =item * &print_suppression()
9312:
9313: In course context returns css which causes the body to be blank when media="print",
9314: if printout generation is unavailable for the current resource.
9315:
9316: This could be because:
9317:
9318: (a) printstartdate is in the future
9319:
9320: (b) printenddate is in the past
9321:
9322: (c) there is an active exam block with "printout"
9323: functionality blocked
9324:
9325: Users with pav, pfo or evb privileges are exempt.
9326:
9327: Inputs: none
9328:
9329: =cut
9330:
9331:
9332: sub print_suppression {
9333: my $noprint;
9334: if ($env{'request.course.id'}) {
9335: my $scope = $env{'request.course.id'};
9336: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9337: (&Apache::lonnet::allowed('pfo',$scope))) {
9338: return;
9339: }
9340: if ($env{'request.course.sec'} ne '') {
9341: $scope .= "/$env{'request.course.sec'}";
9342: if ((&Apache::lonnet::allowed('pav',$scope)) ||
9343: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 9344: return;
1.1064 raeburn 9345: }
9346: }
9347: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9348: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 9349: my $clientip = &Apache::lonnet::get_requestor_ip();
9350: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 9351: if ($blocked) {
9352: my $checkrole = "cm./$cdom/$cnum";
9353: if ($env{'request.course.sec'} ne '') {
9354: $checkrole .= "/$env{'request.course.sec'}";
9355: }
9356: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
9357: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
9358: $noprint = 1;
9359: }
9360: }
9361: unless ($noprint) {
9362: my $symb = &Apache::lonnet::symbread();
9363: if ($symb ne '') {
9364: my $navmap = Apache::lonnavmaps::navmap->new();
9365: if (ref($navmap)) {
9366: my $res = $navmap->getBySymb($symb);
9367: if (ref($res)) {
9368: if (!$res->resprintable()) {
9369: $noprint = 1;
9370: }
9371: }
9372: }
9373: }
9374: }
9375: if ($noprint) {
9376: return <<"ENDSTYLE";
9377: <style type="text/css" media="print">
9378: body { display:none }
9379: </style>
9380: ENDSTYLE
9381: }
9382: }
9383: return;
9384: }
9385:
9386: =pod
9387:
1.341 albertel 9388: =item * &xml_begin()
9389:
9390: Returns the needed doctype and <html>
9391:
9392: Inputs: none
9393:
9394: =cut
9395:
9396: sub xml_begin {
1.1168 raeburn 9397: my ($is_frameset) = @_;
1.341 albertel 9398: my $output='';
9399:
9400: if ($env{'browser.mathml'}) {
9401: $output='<?xml version="1.0"?>'
9402: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
9403: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
9404:
9405: # .'<!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">] >'
9406: .'<!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">'
9407: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
9408: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 9409: } elsif ($is_frameset) {
9410: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
9411: '<html>'."\n";
1.341 albertel 9412: } else {
1.1168 raeburn 9413: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
9414: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 9415: }
9416: return $output;
9417: }
1.340 albertel 9418:
9419: =pod
9420:
1.306 albertel 9421: =item * &start_page()
9422:
9423: Returns a complete <html> .. <body> section for LON-CAPA web pages.
9424:
1.648 raeburn 9425: Inputs:
9426:
9427: =over 4
9428:
9429: $title - optional title for the page
9430:
9431: $head_extra - optional extra HTML to incude inside the <head>
9432:
9433: $args - additional optional args supported are:
9434:
9435: =over 8
9436:
9437: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 9438: arg on
1.814 bisitz 9439: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 9440: add_entries -> additional attributes to add to the <body>
9441: domain -> force to color decorate a page for a
1.317 albertel 9442: specific domain
1.648 raeburn 9443: function -> force usage of a specific rolish color
1.317 albertel 9444: scheme
1.648 raeburn 9445: redirect -> see &headtag()
9446: bgcolor -> override the default page bg color
9447: js_ready -> return a string ready for being used in
1.317 albertel 9448: a javascript writeln
1.648 raeburn 9449: html_encode -> return a string ready for being used in
1.320 albertel 9450: a html attribute
1.648 raeburn 9451: force_register -> if is true will turn on the &bodytag()
1.317 albertel 9452: $forcereg arg
1.648 raeburn 9453: frameset -> if true will start with a <frameset>
1.330 albertel 9454: rather than <body>
1.648 raeburn 9455: skip_phases -> hash ref of
1.338 albertel 9456: head -> skip the <html><head> generation
9457: body -> skip all <body> generation
1.648 raeburn 9458: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 9459: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 9460: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 9461: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
9462: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 9463: group -> includes the current group, if page is for a
1.1274 raeburn 9464: specific group
9465: use_absolute -> for request for external resource or syllabus, this
9466: will contain https://<hostname> if server uses
9467: https (as per hosts.tab), but request is for http
9468: hostname -> hostname, originally from $r->hostname(), (optional).
1.1369 raeburn 9469: links_disabled -> Links in primary and secondary menus are disabled
9470: (Can enable them once page has loaded - see lonroles.pm
9471: for an example).
1.1380 raeburn 9472: links_target -> Target for links, e.g., _parent (optional).
1.361 albertel 9473:
1.648 raeburn 9474: =back
1.460 albertel 9475:
1.648 raeburn 9476: =back
1.562 albertel 9477:
1.306 albertel 9478: =cut
9479:
9480: sub start_page {
1.309 albertel 9481: my ($title,$head_extra,$args) = @_;
1.318 albertel 9482: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 9483:
1.315 albertel 9484: $env{'internal.start_page'}++;
1.1359 raeburn 9485: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 9486:
1.338 albertel 9487: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 9488: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 9489: }
1.1316 raeburn 9490:
9491: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 9492: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
9493: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
9494: $args->{'no_primary_menu'} = 1;
9495: }
9496: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
9497: $args->{'no_inline_menu'} = 1;
9498: }
9499: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
9500: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
9501: }
9502: } else {
9503: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9504: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
9505: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
9506: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
9507: $args->{'no_primary_menu'} = 1;
9508: }
9509: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
9510: $args->{'no_inline_menu'} = 1;
9511: }
9512: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
9513: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
9514: }
9515: }
9516: }
1.1316 raeburn 9517: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
9518: $env{'course.'.$env{'request.course.id'}.'.domain'},
9519: $env{'course.'.$env{'request.course.id'}.'.num'});
1.1359 raeburn 9520: } elsif ($env{'request.course.id'}) {
9521: my $expiretime=600;
9522: if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
9523: &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
9524: }
9525: my ($deeplinkmenu,$menuref);
9526: ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
9527: if ($menucoll) {
9528: if (ref($menuref) eq 'HASH') {
9529: %menu = %{$menuref};
9530: }
9531: if ($menu{'top'} eq 'n') {
9532: $args->{'no_primary_menu'} = 1;
9533: }
9534: if ($menu{'inline'} eq 'n') {
9535: unless (&Apache::lonnet::allowed('opa')) {
9536: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9537: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9538: my $crstype = &course_type();
9539: my $now = time;
9540: my $ccrole;
9541: if ($crstype eq 'Community') {
9542: $ccrole = 'co';
9543: } else {
9544: $ccrole = 'cc';
9545: }
9546: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
9547: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
9548: if ((($start) && ($start<0)) ||
9549: (($end) && ($end<$now)) ||
9550: (($start) && ($now<$start))) {
9551: $args->{'no_inline_menu'} = 1;
9552: }
9553: } else {
9554: $args->{'no_inline_menu'} = 1;
9555: }
9556: }
9557: }
9558: }
1.1316 raeburn 9559: }
1.1359 raeburn 9560:
1.1385 raeburn 9561: my $showncrumbs;
1.338 albertel 9562: if (! exists($args->{'skip_phases'}{'body'}) ) {
9563: if ($args->{'frameset'}) {
9564: my $attr_string = &make_attr_string($args->{'force_register'},
9565: $args->{'add_entries'});
9566: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9567: } else {
9568: $result .=
9569: &bodytag($title,
9570: $args->{'function'}, $args->{'add_entries'},
9571: $args->{'only_body'}, $args->{'domain'},
9572: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 9573: $args->{'bgcolor'}, $args,
1.1385 raeburn 9574: \@advtools,$ltiscope,$ltiuri,\%ltimenu,$menucoll,
9575: \%menu,\$showncrumbs);
1.831 bisitz 9576: }
1.330 albertel 9577: }
1.338 albertel 9578:
1.315 albertel 9579: if ($args->{'js_ready'}) {
1.713 kaisler 9580: $result = &js_ready($result);
1.315 albertel 9581: }
1.320 albertel 9582: if ($args->{'html_encode'}) {
1.713 kaisler 9583: $result = &html_encode($result);
9584: }
9585:
1.813 bisitz 9586: # Preparation for new and consistent functionlist at top of screen
9587: # if ($args->{'functionlist'}) {
9588: # $result .= &build_functionlist();
9589: #}
9590:
1.964 droeschl 9591: # Don't add anything more if only_body wanted or in const space
9592: return $result if $args->{'only_body'}
9593: || $env{'request.state'} eq 'construct';
1.813 bisitz 9594:
9595: #Breadcrumbs
1.758 kaisler 9596: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
1.1385 raeburn 9597: unless ($showncrumbs) {
1.758 kaisler 9598: &Apache::lonhtmlcommon::clear_breadcrumbs();
9599: #if any br links exists, add them to the breadcrumbs
9600: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9601: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9602: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9603: }
9604: }
1.1096 raeburn 9605: # if @advtools array contains items add then to the breadcrumbs
9606: if (@advtools > 0) {
9607: &Apache::lonmenu::advtools_crumbs(@advtools);
9608: }
1.1272 raeburn 9609: my $menulink;
9610: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
9611: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 9612: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 9613: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
9614: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
9615: (!$env{'request.role.adv'}))) {
9616: $menulink = 0;
9617: } else {
9618: undef($menulink);
9619: }
1.1385 raeburn 9620: my $linkprotout;
9621: if ($env{'request.deeplink.login'}) {
9622: my $linkprotout = &Apache::lonmenu::linkprot_exit();
9623: if ($linkprotout) {
9624: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
9625: }
9626: }
1.758 kaisler 9627: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9628: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 9629: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 9630: } else {
1.1272 raeburn 9631: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9632: }
1.1385 raeburn 9633: }
1.320 albertel 9634: }
1.315 albertel 9635: return $result;
1.306 albertel 9636: }
9637:
9638: sub end_page {
1.315 albertel 9639: my ($args) = @_;
9640: $env{'internal.end_page'}++;
1.330 albertel 9641: my $result;
1.335 albertel 9642: if ($args->{'discussion'}) {
9643: my ($target,$parser);
9644: if (ref($args->{'discussion'})) {
9645: ($target,$parser) =($args->{'discussion'}{'target'},
9646: $args->{'discussion'}{'parser'});
9647: }
9648: $result .= &Apache::lonxml::xmlend($target,$parser);
9649: }
1.330 albertel 9650: if ($args->{'frameset'}) {
9651: $result .= '</frameset>';
9652: } else {
1.635 raeburn 9653: $result .= &endbodytag($args);
1.330 albertel 9654: }
1.1080 raeburn 9655: unless ($args->{'notbody'}) {
9656: $result .= "\n</html>";
9657: }
1.330 albertel 9658:
1.315 albertel 9659: if ($args->{'js_ready'}) {
1.317 albertel 9660: $result = &js_ready($result);
1.315 albertel 9661: }
1.335 albertel 9662:
1.320 albertel 9663: if ($args->{'html_encode'}) {
9664: $result = &html_encode($result);
9665: }
1.335 albertel 9666:
1.315 albertel 9667: return $result;
9668: }
9669:
1.1359 raeburn 9670: sub menucoll_in_effect {
9671: my ($menucoll,$deeplinkmenu,%menu);
9672: if ($env{'request.course.id'}) {
9673: $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
1.1362 raeburn 9674: if ($env{'request.deeplink.login'}) {
1.1370 raeburn 9675: my ($deeplink_symb,$deeplink,$check_login_symb);
1.1362 raeburn 9676: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9677: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9678: if ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/}) {
9679: if ($env{'request.noversionuri'} =~ /\.(page|sequence)$/) {
9680: my $navmap = Apache::lonnavmaps::navmap->new();
9681: if (ref($navmap)) {
9682: $deeplink = $navmap->get_mapparam(undef,
9683: &Apache::lonnet::declutter($env{'request.noversionuri'}),
9684: '0.deeplink');
1.1370 raeburn 9685: } else {
9686: $check_login_symb = 1;
1.1362 raeburn 9687: }
9688: } else {
1.1370 raeburn 9689: my $symb = &Apache::lonnet::symbread();
9690: if ($symb) {
9691: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
9692: } else {
9693: $check_login_symb = 1;
9694: }
1.1362 raeburn 9695: }
9696: } else {
1.1370 raeburn 9697: $check_login_symb = 1;
9698: }
9699: if ($check_login_symb) {
1.1362 raeburn 9700: $deeplink_symb = &deeplink_login_symb($cnum,$cdom);
9701: if ($deeplink_symb =~ /\.(page|sequence)$/) {
9702: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
9703: my $navmap = Apache::lonnavmaps::navmap->new();
9704: if (ref($navmap)) {
9705: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
9706: }
9707: } else {
9708: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
9709: }
9710: }
1.1359 raeburn 9711: if ($deeplink ne '') {
1.1378 raeburn 9712: my ($state,$others,$listed,$scope,$protect,$display,$target) = split(/,/,$deeplink);
1.1359 raeburn 9713: if ($display =~ /^\d+$/) {
9714: $deeplinkmenu = 1;
9715: $menucoll = $display;
9716: }
9717: }
9718: }
9719: if ($menucoll) {
9720: %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9721: }
9722: }
9723: return ($menucoll,$deeplinkmenu,\%menu);
9724: }
9725:
1.1362 raeburn 9726: sub deeplink_login_symb {
9727: my ($cnum,$cdom) = @_;
9728: my $login_symb;
9729: if ($env{'request.deeplink.login'}) {
1.1364 raeburn 9730: $login_symb = &symb_from_tinyurl($env{'request.deeplink.login'},$cnum,$cdom);
9731: }
9732: return $login_symb;
9733: }
9734:
9735: sub symb_from_tinyurl {
9736: my ($url,$cnum,$cdom) = @_;
9737: if ($url =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
9738: my $key = $1;
9739: my ($tinyurl,$login);
9740: my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
9741: if (defined($cached)) {
9742: $tinyurl = $result;
9743: } else {
9744: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
9745: my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
9746: if ($currtiny{$key} ne '') {
9747: $tinyurl = $currtiny{$key};
9748: &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
1.1362 raeburn 9749: }
1.1364 raeburn 9750: }
9751: if ($tinyurl ne '') {
9752: my ($cnumreq,$symb) = split(/\&/,$tinyurl);
9753: if (wantarray) {
9754: return ($cnumreq,$symb);
9755: } elsif ($cnumreq eq $cnum) {
9756: return $symb;
1.1362 raeburn 9757: }
9758: }
9759: }
1.1364 raeburn 9760: if (wantarray) {
9761: return ();
9762: } else {
9763: return;
9764: }
1.1362 raeburn 9765: }
9766:
1.1405 ! raeburn 9767: sub usable_exttools {
! 9768: my %tooltypes;
! 9769: if ($env{'request.course.id'}) {
! 9770: if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'}) {
! 9771: if ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'both') {
! 9772: %tooltypes = (
! 9773: crs => 1,
! 9774: dom => 1,
! 9775: );
! 9776: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'crs') {
! 9777: $tooltypes{'crs'} = 1;
! 9778: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.exttool'} eq 'dom') {
! 9779: $tooltypes{'dom'} = 1;
! 9780: }
! 9781: } else {
! 9782: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
! 9783: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
! 9784: my $crstype = lc($env{'course.'.$env{'request.course.id'}.'.type'});
! 9785: if ($crstype eq '') {
! 9786: $crstype = 'course';
! 9787: }
! 9788: if ($crstype eq 'course') {
! 9789: if ($env{'course.'.$env{'request.course.id'}.'internal.coursecode'}) {
! 9790: $crstype = 'official';
! 9791: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
! 9792: $crstype = 'textbook';
! 9793: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.lti'}) {
! 9794: $crstype = 'lti';
! 9795: } else {
! 9796: $crstype = 'unofficial';
! 9797: }
! 9798: }
! 9799: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
! 9800: if ($domdefaults{$crstype.'domexttool'}) {
! 9801: $tooltypes{'dom'} = 1;
! 9802: }
! 9803: if ($domdefaults{$crstype.'exttool'}) {
! 9804: $tooltypes{'crs'} = 1;
! 9805: }
! 9806: }
! 9807: }
! 9808: return %tooltypes;
! 9809: }
! 9810:
1.1034 www 9811: sub wishlist_window {
9812: return(<<'ENDWISHLIST');
1.1046 raeburn 9813: <script type="text/javascript">
1.1034 www 9814: // <![CDATA[
9815: // <!-- BEGIN LON-CAPA Internal
9816: function set_wishlistlink(title, path) {
9817: if (!title) {
9818: title = document.title;
9819: title = title.replace(/^LON-CAPA /,'');
9820: }
1.1175 raeburn 9821: title = encodeURIComponent(title);
1.1203 raeburn 9822: title = title.replace("'","\\\'");
1.1034 www 9823: if (!path) {
9824: path = location.pathname;
9825: }
1.1175 raeburn 9826: path = encodeURIComponent(path);
1.1203 raeburn 9827: path = path.replace("'","\\\'");
1.1034 www 9828: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9829: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9830: }
9831: // END LON-CAPA Internal -->
9832: // ]]>
9833: </script>
9834: ENDWISHLIST
9835: }
9836:
1.1030 www 9837: sub modal_window {
9838: return(<<'ENDMODAL');
1.1046 raeburn 9839: <script type="text/javascript">
1.1030 www 9840: // <![CDATA[
9841: // <!-- BEGIN LON-CAPA Internal
9842: var modalWindow = {
9843: parent:"body",
9844: windowId:null,
9845: content:null,
9846: width:null,
9847: height:null,
9848: close:function()
9849: {
9850: $(".LCmodal-window").remove();
9851: $(".LCmodal-overlay").remove();
9852: },
9853: open:function()
9854: {
9855: var modal = "";
9856: modal += "<div class=\"LCmodal-overlay\"></div>";
9857: 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;\">";
9858: modal += this.content;
9859: modal += "</div>";
9860:
9861: $(this.parent).append(modal);
9862:
9863: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9864: $(".LCclose-window").click(function(){modalWindow.close();});
9865: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9866: }
9867: };
1.1140 raeburn 9868: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9869: {
1.1266 raeburn 9870: source = source.replace(/'/g,"'");
1.1030 www 9871: modalWindow.windowId = "myModal";
9872: modalWindow.width = width;
9873: modalWindow.height = height;
1.1196 raeburn 9874: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9875: modalWindow.open();
1.1208 raeburn 9876: };
1.1030 www 9877: // END LON-CAPA Internal -->
9878: // ]]>
9879: </script>
9880: ENDMODAL
9881: }
9882:
9883: sub modal_link {
1.1140 raeburn 9884: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9885: unless ($width) { $width=480; }
9886: unless ($height) { $height=400; }
1.1031 www 9887: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9888: unless ($transparency) { $transparency='true'; }
9889:
1.1074 raeburn 9890: my $target_attr;
9891: if (defined($target)) {
9892: $target_attr = 'target="'.$target.'"';
9893: }
9894: return <<"ENDLINK";
1.1336 raeburn 9895: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9896: ENDLINK
1.1030 www 9897: }
9898:
1.1032 www 9899: sub modal_adhoc_script {
1.1365 raeburn 9900: my ($funcname,$width,$height,$content,$possmathjax)=@_;
9901: my $mathjax;
9902: if ($possmathjax) {
9903: $mathjax = <<'ENDJAX';
9904: if (typeof MathJax == 'object') {
9905: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
9906: }
9907: ENDJAX
9908: }
1.1032 www 9909: return (<<ENDADHOC);
1.1046 raeburn 9910: <script type="text/javascript">
1.1032 www 9911: // <![CDATA[
9912: var $funcname = function()
9913: {
9914: modalWindow.windowId = "myModal";
9915: modalWindow.width = $width;
9916: modalWindow.height = $height;
9917: modalWindow.content = '$content';
9918: modalWindow.open();
1.1365 raeburn 9919: $mathjax
1.1032 www 9920: };
9921: // ]]>
9922: </script>
9923: ENDADHOC
9924: }
9925:
1.1041 www 9926: sub modal_adhoc_inner {
1.1365 raeburn 9927: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 9928: my $innerwidth=$width-20;
9929: $content=&js_ready(
1.1140 raeburn 9930: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9931: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9932: $content.
1.1041 www 9933: &end_scrollbox().
1.1140 raeburn 9934: &end_page()
1.1041 www 9935: );
1.1365 raeburn 9936: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 9937: }
9938:
9939: sub modal_adhoc_window {
1.1365 raeburn 9940: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
9941: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 9942: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9943: }
9944:
9945: sub modal_adhoc_launch {
9946: my ($funcname,$width,$height,$content)=@_;
9947: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9948: <script type="text/javascript">
9949: // <![CDATA[
9950: $funcname();
9951: // ]]>
9952: </script>
9953: ENDLAUNCH
9954: }
9955:
9956: sub modal_adhoc_close {
9957: return (<<ENDCLOSE);
9958: <script type="text/javascript">
9959: // <![CDATA[
9960: modalWindow.close();
9961: // ]]>
9962: </script>
9963: ENDCLOSE
9964: }
9965:
1.1038 www 9966: sub togglebox_script {
9967: return(<<ENDTOGGLE);
9968: <script type="text/javascript">
9969: // <![CDATA[
9970: function LCtoggleDisplay(id,hidetext,showtext) {
9971: link = document.getElementById(id + "link").childNodes[0];
9972: with (document.getElementById(id).style) {
9973: if (display == "none" ) {
9974: display = "inline";
9975: link.nodeValue = hidetext;
9976: } else {
9977: display = "none";
9978: link.nodeValue = showtext;
9979: }
9980: }
9981: }
9982: // ]]>
9983: </script>
9984: ENDTOGGLE
9985: }
9986:
1.1039 www 9987: sub start_togglebox {
9988: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9989: unless ($heading) { $heading=''; } else { $heading.=' '; }
9990: unless ($showtext) { $showtext=&mt('show'); }
9991: unless ($hidetext) { $hidetext=&mt('hide'); }
9992: unless ($headerbg) { $headerbg='#FFFFFF'; }
9993: return &start_data_table().
9994: &start_data_table_header_row().
9995: '<td bgcolor="'.$headerbg.'">'.$heading.
9996: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9997: $showtext.'\')">'.$showtext.'</a>]</td>'.
9998: &end_data_table_header_row().
9999: '<tr id="'.$id.'" style="display:none""><td>';
10000: }
10001:
10002: sub end_togglebox {
10003: return '</td></tr>'.&end_data_table();
10004: }
10005:
1.1041 www 10006: sub LCprogressbar_script {
1.1302 raeburn 10007: my ($id,$number_to_do)=@_;
10008: if ($number_to_do) {
10009: return(<<ENDPROGRESS);
1.1041 www 10010: <script type="text/javascript">
10011: // <![CDATA[
1.1045 www 10012: \$('#progressbar$id').progressbar({
1.1041 www 10013: value: 0,
10014: change: function(event, ui) {
10015: var newVal = \$(this).progressbar('option', 'value');
10016: \$('.pblabel', this).text(LCprogressTxt);
10017: }
10018: });
10019: // ]]>
10020: </script>
10021: ENDPROGRESS
1.1302 raeburn 10022: } else {
10023: return(<<ENDPROGRESS);
10024: <script type="text/javascript">
10025: // <![CDATA[
10026: \$('#progressbar$id').progressbar({
10027: value: false,
10028: create: function(event, ui) {
10029: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
10030: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
10031: }
10032: });
10033: // ]]>
10034: </script>
10035: ENDPROGRESS
10036: }
1.1041 www 10037: }
10038:
10039: sub LCprogressbarUpdate_script {
10040: return(<<ENDPROGRESSUPDATE);
10041: <style type="text/css">
10042: .ui-progressbar { position:relative; }
1.1302 raeburn 10043: .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 10044: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
10045: </style>
10046: <script type="text/javascript">
10047: // <![CDATA[
1.1045 www 10048: var LCprogressTxt='---';
10049:
1.1302 raeburn 10050: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 10051: LCprogressTxt=progresstext;
1.1302 raeburn 10052: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
10053: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
10054: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 10055: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
10056: } else {
10057: \$('#progressbar'+id).progressbar('value',percent);
10058: }
1.1041 www 10059: }
10060: // ]]>
10061: </script>
10062: ENDPROGRESSUPDATE
10063: }
10064:
1.1042 www 10065: my $LClastpercent;
1.1045 www 10066: my $LCidcnt;
10067: my $LCcurrentid;
1.1042 www 10068:
1.1041 www 10069: sub LCprogressbar {
1.1302 raeburn 10070: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 10071: $LClastpercent=0;
1.1045 www 10072: $LCidcnt++;
10073: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 10074: my ($starting,$content);
10075: if ($number_to_do) {
10076: $starting=&mt('Starting');
10077: $content=(<<ENDPROGBAR);
10078: $preamble
1.1045 www 10079: <div id="progressbar$LCcurrentid">
1.1041 www 10080: <span class="pblabel">$starting</span>
10081: </div>
10082: ENDPROGBAR
1.1302 raeburn 10083: } else {
10084: $starting=&mt('Loading...');
10085: $LClastpercent='false';
10086: $content=(<<ENDPROGBAR);
10087: $preamble
10088: <div id="progressbar$LCcurrentid">
10089: <div class="progress-label">$starting</div>
10090: </div>
10091: ENDPROGBAR
10092: }
10093: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 10094: }
10095:
10096: sub LCprogressbarUpdate {
1.1302 raeburn 10097: my ($r,$val,$text,$number_to_do)=@_;
10098: if ($number_to_do) {
10099: unless ($val) {
10100: if ($LClastpercent) {
10101: $val=$LClastpercent;
10102: } else {
10103: $val=0;
10104: }
10105: }
10106: if ($val<0) { $val=0; }
10107: if ($val>100) { $val=0; }
10108: $LClastpercent=$val;
10109: unless ($text) { $text=$val.'%'; }
10110: } else {
10111: $val = 'false';
1.1042 www 10112: }
1.1041 www 10113: $text=&js_ready($text);
1.1044 www 10114: &r_print($r,<<ENDUPDATE);
1.1041 www 10115: <script type="text/javascript">
10116: // <![CDATA[
1.1302 raeburn 10117: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 10118: // ]]>
10119: </script>
10120: ENDUPDATE
1.1035 www 10121: }
10122:
1.1042 www 10123: sub LCprogressbarClose {
10124: my ($r)=@_;
10125: $LClastpercent=0;
1.1044 www 10126: &r_print($r,<<ENDCLOSE);
1.1042 www 10127: <script type="text/javascript">
10128: // <![CDATA[
1.1045 www 10129: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 10130: // ]]>
10131: </script>
10132: ENDCLOSE
1.1044 www 10133: }
10134:
10135: sub r_print {
10136: my ($r,$to_print)=@_;
10137: if ($r) {
10138: $r->print($to_print);
10139: $r->rflush();
10140: } else {
10141: print($to_print);
10142: }
1.1042 www 10143: }
10144:
1.320 albertel 10145: sub html_encode {
10146: my ($result) = @_;
10147:
1.322 albertel 10148: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 10149:
10150: return $result;
10151: }
1.1044 www 10152:
1.317 albertel 10153: sub js_ready {
10154: my ($result) = @_;
10155:
1.323 albertel 10156: $result =~ s/[\n\r]/ /xmsg;
10157: $result =~ s/\\/\\\\/xmsg;
10158: $result =~ s/'/\\'/xmsg;
1.372 albertel 10159: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 10160:
10161: return $result;
10162: }
10163:
1.315 albertel 10164: sub validate_page {
10165: if ( exists($env{'internal.start_page'})
1.316 albertel 10166: && $env{'internal.start_page'} > 1) {
10167: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 10168: $env{'internal.start_page'}.' '.
1.316 albertel 10169: $ENV{'request.filename'});
1.315 albertel 10170: }
10171: if ( exists($env{'internal.end_page'})
1.316 albertel 10172: && $env{'internal.end_page'} > 1) {
10173: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 10174: $env{'internal.end_page'}.' '.
1.316 albertel 10175: $env{'request.filename'});
1.315 albertel 10176: }
10177: if ( exists($env{'internal.start_page'})
10178: && ! exists($env{'internal.end_page'})) {
1.316 albertel 10179: &Apache::lonnet::logthis('start_page called without end_page '.
10180: $env{'request.filename'});
1.315 albertel 10181: }
10182: if ( ! exists($env{'internal.start_page'})
10183: && exists($env{'internal.end_page'})) {
1.316 albertel 10184: &Apache::lonnet::logthis('end_page called without start_page'.
10185: $env{'request.filename'});
1.315 albertel 10186: }
1.306 albertel 10187: }
1.315 albertel 10188:
1.996 www 10189:
10190: sub start_scrollbox {
1.1140 raeburn 10191: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 10192: unless ($outerwidth) { $outerwidth='520px'; }
10193: unless ($width) { $width='500px'; }
10194: unless ($height) { $height='200px'; }
1.1075 raeburn 10195: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 10196: if ($id ne '') {
1.1140 raeburn 10197: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 10198: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 10199: }
1.1075 raeburn 10200: if ($bgcolor ne '') {
10201: $tdcol = "background-color: $bgcolor;";
10202: }
1.1137 raeburn 10203: my $nicescroll_js;
10204: if ($env{'browser.mobile'}) {
1.1140 raeburn 10205: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
10206: }
10207: return <<"END";
10208: $nicescroll_js
10209:
10210: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
10211: <div style="overflow:auto; width:$width; height:$height;"$div_id>
10212: END
10213: }
10214:
10215: sub end_scrollbox {
10216: return '</div></td></tr></table>';
10217: }
10218:
10219: sub nicescroll_javascript {
10220: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
10221: my %options;
10222: if (ref($cursor) eq 'HASH') {
10223: %options = %{$cursor};
10224: }
10225: unless ($options{'railalign'} =~ /^left|right$/) {
10226: $options{'railalign'} = 'left';
10227: }
10228: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
10229: my $function = &get_users_function();
10230: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 10231: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 10232: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 10233: }
1.1140 raeburn 10234: }
10235: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
10236: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 10237: $options{'cursoropacity'}='1.0';
10238: }
1.1140 raeburn 10239: } else {
10240: $options{'cursoropacity'}='1.0';
10241: }
10242: if ($options{'cursorfixedheight'} eq 'none') {
10243: delete($options{'cursorfixedheight'});
10244: } else {
10245: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
10246: }
10247: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
10248: delete($options{'railoffset'});
10249: }
10250: my @niceoptions;
10251: while (my($key,$value) = each(%options)) {
10252: if ($value =~ /^\{.+\}$/) {
10253: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 10254: } else {
1.1140 raeburn 10255: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 10256: }
1.1140 raeburn 10257: }
10258: my $nicescroll_js = '
1.1137 raeburn 10259: $(document).ready(
1.1140 raeburn 10260: function() {
10261: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
10262: }
1.1137 raeburn 10263: );
10264: ';
1.1140 raeburn 10265: if ($framecheck) {
10266: $nicescroll_js .= '
10267: function expand_div(caller) {
10268: if (top === self) {
10269: document.getElementById("'.$id.'").style.width = "auto";
10270: document.getElementById("'.$id.'").style.height = "auto";
10271: } else {
10272: try {
10273: if (parent.frames) {
10274: if (parent.frames.length > 1) {
10275: var framesrc = parent.frames[1].location.href;
10276: var currsrc = framesrc.replace(/\#.*$/,"");
10277: if ((caller == "search") || (currsrc == "'.$location.'")) {
10278: document.getElementById("'.$id.'").style.width = "auto";
10279: document.getElementById("'.$id.'").style.height = "auto";
10280: }
10281: }
10282: }
10283: } catch (e) {
10284: return;
10285: }
1.1137 raeburn 10286: }
1.1140 raeburn 10287: return;
1.996 www 10288: }
1.1140 raeburn 10289: ';
10290: }
10291: if ($needjsready) {
10292: $nicescroll_js = '
10293: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
10294: } else {
10295: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
10296: }
10297: return $nicescroll_js;
1.996 www 10298: }
10299:
1.318 albertel 10300: sub simple_error_page {
1.1150 bisitz 10301: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 10302: my %displayargs;
1.1151 raeburn 10303: if (ref($args) eq 'HASH') {
10304: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 10305: if ($args->{'only_body'}) {
10306: $displayargs{'only_body'} = 1;
10307: }
10308: if ($args->{'no_nav_bar'}) {
10309: $displayargs{'no_nav_bar'} = 1;
10310: }
1.1151 raeburn 10311: } else {
10312: $msg = &mt($msg);
10313: }
1.1150 bisitz 10314:
1.318 albertel 10315: my $page =
1.1304 raeburn 10316: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 10317: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 10318: &Apache::loncommon::end_page();
10319: if (ref($r)) {
10320: $r->print($page);
1.327 albertel 10321: return;
1.318 albertel 10322: }
10323: return $page;
10324: }
1.347 albertel 10325:
10326: {
1.610 albertel 10327: my @row_count;
1.961 onken 10328:
10329: sub start_data_table_count {
10330: unshift(@row_count, 0);
10331: return;
10332: }
10333:
10334: sub end_data_table_count {
10335: shift(@row_count);
10336: return;
10337: }
10338:
1.347 albertel 10339: sub start_data_table {
1.1018 raeburn 10340: my ($add_class,$id) = @_;
1.422 albertel 10341: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 10342: my $table_id;
10343: if (defined($id)) {
10344: $table_id = ' id="'.$id.'"';
10345: }
1.961 onken 10346: &start_data_table_count();
1.1018 raeburn 10347: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 10348: }
10349:
10350: sub end_data_table {
1.961 onken 10351: &end_data_table_count();
1.389 albertel 10352: return '</table>'."\n";;
1.347 albertel 10353: }
10354:
10355: sub start_data_table_row {
1.974 wenzelju 10356: my ($add_class, $id) = @_;
1.610 albertel 10357: $row_count[0]++;
10358: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 10359: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 10360: $id = (' id="'.$id.'"') unless ($id eq '');
10361: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 10362: }
1.471 banghart 10363:
10364: sub continue_data_table_row {
1.974 wenzelju 10365: my ($add_class, $id) = @_;
1.610 albertel 10366: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 10367: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
10368: $id = (' id="'.$id.'"') unless ($id eq '');
10369: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 10370: }
1.347 albertel 10371:
10372: sub end_data_table_row {
1.389 albertel 10373: return '</tr>'."\n";;
1.347 albertel 10374: }
1.367 www 10375:
1.421 albertel 10376: sub start_data_table_empty_row {
1.707 bisitz 10377: # $row_count[0]++;
1.421 albertel 10378: return '<tr class="LC_empty_row" >'."\n";;
10379: }
10380:
10381: sub end_data_table_empty_row {
10382: return '</tr>'."\n";;
10383: }
10384:
1.367 www 10385: sub start_data_table_header_row {
1.389 albertel 10386: return '<tr class="LC_header_row">'."\n";;
1.367 www 10387: }
10388:
10389: sub end_data_table_header_row {
1.389 albertel 10390: return '</tr>'."\n";;
1.367 www 10391: }
1.890 droeschl 10392:
10393: sub data_table_caption {
10394: my $caption = shift;
10395: return "<caption class=\"LC_caption\">$caption</caption>";
10396: }
1.347 albertel 10397: }
10398:
1.548 albertel 10399: =pod
10400:
10401: =item * &inhibit_menu_check($arg)
10402:
10403: Checks for a inhibitmenu state and generates output to preserve it
10404:
10405: Inputs: $arg - can be any of
10406: - undef - in which case the return value is a string
10407: to add into arguments list of a uri
10408: - 'input' - in which case the return value is a HTML
10409: <form> <input> field of type hidden to
10410: preserve the value
10411: - a url - in which case the return value is the url with
10412: the neccesary cgi args added to preserve the
10413: inhibitmenu state
10414: - a ref to a url - no return value, but the string is
10415: updated to include the neccessary cgi
10416: args to preserve the inhibitmenu state
10417:
10418: =cut
10419:
10420: sub inhibit_menu_check {
10421: my ($arg) = @_;
10422: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
10423: if ($arg eq 'input') {
10424: if ($env{'form.inhibitmenu'}) {
10425: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
10426: } else {
10427: return
10428: }
10429: }
10430: if ($env{'form.inhibitmenu'}) {
10431: if (ref($arg)) {
10432: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10433: } elsif ($arg eq '') {
10434: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
10435: } else {
10436: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
10437: }
10438: }
10439: if (!ref($arg)) {
10440: return $arg;
10441: }
10442: }
10443:
1.251 albertel 10444: ###############################################
1.182 matthew 10445:
10446: =pod
10447:
1.549 albertel 10448: =back
10449:
10450: =head1 User Information Routines
10451:
10452: =over 4
10453:
1.405 albertel 10454: =item * &get_users_function()
1.182 matthew 10455:
10456: Used by &bodytag to determine the current users primary role.
10457: Returns either 'student','coordinator','admin', or 'author'.
10458:
10459: =cut
10460:
10461: ###############################################
10462: sub get_users_function {
1.815 tempelho 10463: my $function = 'norole';
1.818 tempelho 10464: if ($env{'request.role'}=~/^(st)/) {
10465: $function='student';
10466: }
1.907 raeburn 10467: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 10468: $function='coordinator';
10469: }
1.258 albertel 10470: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 10471: $function='admin';
10472: }
1.826 bisitz 10473: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 10474: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 10475: $function='author';
10476: }
10477: return $function;
1.54 www 10478: }
1.99 www 10479:
10480: ###############################################
10481:
1.233 raeburn 10482: =pod
10483:
1.821 raeburn 10484: =item * &show_course()
10485:
10486: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
10487: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
10488:
10489: Inputs:
10490: None
10491:
10492: Outputs:
10493: Scalar: 1 if 'Course' to be used, 0 otherwise.
10494:
10495: =cut
10496:
10497: ###############################################
10498: sub show_course {
10499: my $course = !$env{'user.adv'};
10500: if (!$env{'user.adv'}) {
10501: foreach my $env (keys(%env)) {
10502: next if ($env !~ m/^user\.priv\./);
10503: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
10504: $course = 0;
10505: last;
10506: }
10507: }
10508: }
10509: return $course;
10510: }
10511:
10512: ###############################################
10513:
10514: =pod
10515:
1.542 raeburn 10516: =item * &check_user_status()
1.274 raeburn 10517:
10518: Determines current status of supplied role for a
10519: specific user. Roles can be active, previous or future.
10520:
10521: Inputs:
10522: user's domain, user's username, course's domain,
1.375 raeburn 10523: course's number, optional section ID.
1.274 raeburn 10524:
10525: Outputs:
10526: role status: active, previous or future.
10527:
10528: =cut
10529:
10530: sub check_user_status {
1.412 raeburn 10531: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 10532: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 10533: my @uroles = keys(%userinfo);
1.274 raeburn 10534: my $srchstr;
10535: my $active_chk = 'none';
1.412 raeburn 10536: my $now = time;
1.274 raeburn 10537: if (@uroles > 0) {
1.908 raeburn 10538: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 10539: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
10540: } else {
1.412 raeburn 10541: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
10542: }
10543: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 10544: my $role_end = 0;
10545: my $role_start = 0;
10546: $active_chk = 'active';
1.412 raeburn 10547: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
10548: $role_end = $1;
10549: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
10550: $role_start = $1;
1.274 raeburn 10551: }
10552: }
10553: if ($role_start > 0) {
1.412 raeburn 10554: if ($now < $role_start) {
1.274 raeburn 10555: $active_chk = 'future';
10556: }
10557: }
10558: if ($role_end > 0) {
1.412 raeburn 10559: if ($now > $role_end) {
1.274 raeburn 10560: $active_chk = 'previous';
10561: }
10562: }
10563: }
10564: }
10565: return $active_chk;
10566: }
10567:
10568: ###############################################
10569:
10570: =pod
10571:
1.405 albertel 10572: =item * &get_sections()
1.233 raeburn 10573:
10574: Determines all the sections for a course including
10575: sections with students and sections containing other roles.
1.419 raeburn 10576: Incoming parameters:
10577:
10578: 1. domain
10579: 2. course number
10580: 3. reference to array containing roles for which sections should
10581: be gathered (optional).
10582: 4. reference to array containing status types for which sections
10583: should be gathered (optional).
10584:
10585: If the third argument is undefined, sections are gathered for any role.
10586: If the fourth argument is undefined, sections are gathered for any status.
10587: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 10588:
1.374 raeburn 10589: Returns section hash (keys are section IDs, values are
10590: number of users in each section), subject to the
1.419 raeburn 10591: optional roles filter, optional status filter
1.233 raeburn 10592:
10593: =cut
10594:
10595: ###############################################
10596: sub get_sections {
1.419 raeburn 10597: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 10598: if (!defined($cdom) || !defined($cnum)) {
10599: my $cid = $env{'request.course.id'};
10600:
10601: return if (!defined($cid));
10602:
10603: $cdom = $env{'course.'.$cid.'.domain'};
10604: $cnum = $env{'course.'.$cid.'.num'};
10605: }
10606:
10607: my %sectioncount;
1.419 raeburn 10608: my $now = time;
1.240 albertel 10609:
1.1118 raeburn 10610: my $check_students = 1;
10611: my $only_students = 0;
10612: if (ref($possible_roles) eq 'ARRAY') {
10613: if (grep(/^st$/,@{$possible_roles})) {
10614: if (@{$possible_roles} == 1) {
10615: $only_students = 1;
10616: }
10617: } else {
10618: $check_students = 0;
10619: }
10620: }
10621:
10622: if ($check_students) {
1.276 albertel 10623: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 10624: my $sec_index = &Apache::loncoursedata::CL_SECTION();
10625: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 10626: my $start_index = &Apache::loncoursedata::CL_START();
10627: my $end_index = &Apache::loncoursedata::CL_END();
10628: my $status;
1.366 albertel 10629: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 10630: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
10631: $data->[$status_index],
10632: $data->[$start_index],
10633: $data->[$end_index]);
10634: if ($stu_status eq 'Active') {
10635: $status = 'active';
10636: } elsif ($end < $now) {
10637: $status = 'previous';
10638: } elsif ($start > $now) {
10639: $status = 'future';
10640: }
10641: if ($section ne '-1' && $section !~ /^\s*$/) {
10642: if ((!defined($possible_status)) || (($status ne '') &&
10643: (grep/^\Q$status\E$/,@{$possible_status}))) {
10644: $sectioncount{$section}++;
10645: }
1.240 albertel 10646: }
10647: }
10648: }
1.1118 raeburn 10649: if ($only_students) {
10650: return %sectioncount;
10651: }
1.240 albertel 10652: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10653: foreach my $user (sort(keys(%courseroles))) {
10654: if ($user !~ /^(\w{2})/) { next; }
10655: my ($role) = ($user =~ /^(\w{2})/);
10656: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10657: my ($section,$status);
1.240 albertel 10658: if ($role eq 'cr' &&
10659: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10660: $section=$1;
10661: }
10662: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10663: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10664: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10665: if ($end == -1 && $start == -1) {
10666: next; #deleted role
10667: }
10668: if (!defined($possible_status)) {
10669: $sectioncount{$section}++;
10670: } else {
10671: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10672: $status = 'active';
10673: } elsif ($end < $now) {
10674: $status = 'future';
10675: } elsif ($start > $now) {
10676: $status = 'previous';
10677: }
10678: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10679: $sectioncount{$section}++;
10680: }
10681: }
1.233 raeburn 10682: }
1.366 albertel 10683: return %sectioncount;
1.233 raeburn 10684: }
10685:
1.274 raeburn 10686: ###############################################
1.294 raeburn 10687:
10688: =pod
1.405 albertel 10689:
10690: =item * &get_course_users()
10691:
1.275 raeburn 10692: Retrieves usernames:domains for users in the specified course
10693: with specific role(s), and access status.
10694:
10695: Incoming parameters:
1.277 albertel 10696: 1. course domain
10697: 2. course number
10698: 3. access status: users must have - either active,
1.275 raeburn 10699: previous, future, or all.
1.277 albertel 10700: 4. reference to array of permissible roles
1.288 raeburn 10701: 5. reference to array of section restrictions (optional)
10702: 6. reference to results object (hash of hashes).
10703: 7. reference to optional userdata hash
1.609 raeburn 10704: 8. reference to optional statushash
1.630 raeburn 10705: 9. flag if privileged users (except those set to unhide in
10706: course settings) should be excluded
1.609 raeburn 10707: Keys of top level results hash are roles.
1.275 raeburn 10708: Keys of inner hashes are username:domain, with
10709: values set to access type.
1.288 raeburn 10710: Optional userdata hash returns an array with arguments in the
10711: same order as loncoursedata::get_classlist() for student data.
10712:
1.609 raeburn 10713: Optional statushash returns
10714:
1.288 raeburn 10715: Entries for end, start, section and status are blank because
10716: of the possibility of multiple values for non-student roles.
10717:
1.275 raeburn 10718: =cut
1.405 albertel 10719:
1.275 raeburn 10720: ###############################################
1.405 albertel 10721:
1.275 raeburn 10722: sub get_course_users {
1.630 raeburn 10723: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10724: my %idx = ();
1.419 raeburn 10725: my %seclists;
1.288 raeburn 10726:
10727: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10728: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10729: $idx{end} = &Apache::loncoursedata::CL_END();
10730: $idx{start} = &Apache::loncoursedata::CL_START();
10731: $idx{id} = &Apache::loncoursedata::CL_ID();
10732: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10733: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10734: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10735:
1.290 albertel 10736: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10737: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10738: my $now = time;
1.277 albertel 10739: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10740: my $match = 0;
1.412 raeburn 10741: my $secmatch = 0;
1.419 raeburn 10742: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10743: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10744: if ($section eq '') {
10745: $section = 'none';
10746: }
1.291 albertel 10747: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10748: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10749: $secmatch = 1;
10750: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10751: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10752: $secmatch = 1;
10753: }
10754: } else {
1.419 raeburn 10755: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10756: $secmatch = 1;
10757: }
1.290 albertel 10758: }
1.412 raeburn 10759: if (!$secmatch) {
10760: next;
10761: }
1.419 raeburn 10762: }
1.275 raeburn 10763: if (defined($$types{'active'})) {
1.288 raeburn 10764: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10765: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10766: $match = 1;
1.275 raeburn 10767: }
10768: }
10769: if (defined($$types{'previous'})) {
1.609 raeburn 10770: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10771: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10772: $match = 1;
1.275 raeburn 10773: }
10774: }
10775: if (defined($$types{'future'})) {
1.609 raeburn 10776: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10777: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10778: $match = 1;
1.275 raeburn 10779: }
10780: }
1.609 raeburn 10781: if ($match) {
10782: push(@{$seclists{$student}},$section);
10783: if (ref($userdata) eq 'HASH') {
10784: $$userdata{$student} = $$classlist{$student};
10785: }
10786: if (ref($statushash) eq 'HASH') {
10787: $statushash->{$student}{'st'}{$section} = $status;
10788: }
1.288 raeburn 10789: }
1.275 raeburn 10790: }
10791: }
1.412 raeburn 10792: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10793: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10794: my $now = time;
1.609 raeburn 10795: my %displaystatus = ( previous => 'Expired',
10796: active => 'Active',
10797: future => 'Future',
10798: );
1.1121 raeburn 10799: my (%nothide,@possdoms);
1.630 raeburn 10800: if ($hidepriv) {
10801: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10802: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10803: if ($user !~ /:/) {
10804: $nothide{join(':',split(/[\@]/,$user))}=1;
10805: } else {
10806: $nothide{$user} = 1;
10807: }
10808: }
1.1121 raeburn 10809: my @possdoms = ($cdom);
10810: if ($coursehash{'checkforpriv'}) {
10811: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10812: }
1.630 raeburn 10813: }
1.439 raeburn 10814: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10815: my $match = 0;
1.412 raeburn 10816: my $secmatch = 0;
1.439 raeburn 10817: my $status;
1.412 raeburn 10818: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10819: $user =~ s/:$//;
1.439 raeburn 10820: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10821: if ($end == -1 || $start == -1) {
10822: next;
10823: }
10824: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10825: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10826: my ($uname,$udom) = split(/:/,$user);
10827: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10828: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10829: $secmatch = 1;
10830: } elsif ($usec eq '') {
1.420 albertel 10831: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10832: $secmatch = 1;
10833: }
10834: } else {
10835: if (grep(/^\Q$usec\E$/,@{$sections})) {
10836: $secmatch = 1;
10837: }
10838: }
10839: if (!$secmatch) {
10840: next;
10841: }
1.288 raeburn 10842: }
1.419 raeburn 10843: if ($usec eq '') {
10844: $usec = 'none';
10845: }
1.275 raeburn 10846: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10847: if ($hidepriv) {
1.1121 raeburn 10848: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10849: (!$nothide{$uname.':'.$udom})) {
10850: next;
10851: }
10852: }
1.503 raeburn 10853: if ($end > 0 && $end < $now) {
1.439 raeburn 10854: $status = 'previous';
10855: } elsif ($start > $now) {
10856: $status = 'future';
10857: } else {
10858: $status = 'active';
10859: }
1.277 albertel 10860: foreach my $type (keys(%{$types})) {
1.275 raeburn 10861: if ($status eq $type) {
1.420 albertel 10862: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10863: push(@{$$users{$role}{$user}},$type);
10864: }
1.288 raeburn 10865: $match = 1;
10866: }
10867: }
1.419 raeburn 10868: if (($match) && (ref($userdata) eq 'HASH')) {
10869: if (!exists($$userdata{$uname.':'.$udom})) {
10870: &get_user_info($udom,$uname,\%idx,$userdata);
10871: }
1.420 albertel 10872: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10873: push(@{$seclists{$uname.':'.$udom}},$usec);
10874: }
1.609 raeburn 10875: if (ref($statushash) eq 'HASH') {
10876: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10877: }
1.275 raeburn 10878: }
10879: }
10880: }
10881: }
1.290 albertel 10882: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10883: if ((defined($cdom)) && (defined($cnum))) {
10884: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10885: if ( defined($csettings{'internal.courseowner'}) ) {
10886: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10887: next if ($owner eq '');
10888: my ($ownername,$ownerdom);
10889: if ($owner =~ /^([^:]+):([^:]+)$/) {
10890: $ownername = $1;
10891: $ownerdom = $2;
10892: } else {
10893: $ownername = $owner;
10894: $ownerdom = $cdom;
10895: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10896: }
10897: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10898: if (defined($userdata) &&
1.609 raeburn 10899: !exists($$userdata{$owner})) {
10900: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10901: if (!grep(/^none$/,@{$seclists{$owner}})) {
10902: push(@{$seclists{$owner}},'none');
10903: }
10904: if (ref($statushash) eq 'HASH') {
10905: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10906: }
1.290 albertel 10907: }
1.279 raeburn 10908: }
10909: }
10910: }
1.419 raeburn 10911: foreach my $user (keys(%seclists)) {
10912: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10913: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10914: }
1.275 raeburn 10915: }
10916: return;
10917: }
10918:
1.288 raeburn 10919: sub get_user_info {
10920: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10921: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10922: &plainname($uname,$udom,'lastname');
1.291 albertel 10923: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10924: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10925: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10926: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10927: return;
10928: }
1.275 raeburn 10929:
1.472 raeburn 10930: ###############################################
10931:
10932: =pod
10933:
10934: =item * &get_user_quota()
10935:
1.1134 raeburn 10936: Retrieves quota assigned for storage of user files.
10937: Default is to report quota for portfolio files.
1.472 raeburn 10938:
10939: Incoming parameters:
10940: 1. user's username
10941: 2. user's domain
1.1134 raeburn 10942: 3. quota name - portfolio, author, or course
1.1136 raeburn 10943: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10944: 4. crstype - official, unofficial, textbook, placement or community,
10945: if quota name is course
1.472 raeburn 10946:
10947: Returns:
1.1163 raeburn 10948: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10949: 2. (Optional) Type of setting: custom or default
10950: (individually assigned or default for user's
10951: institutional status).
10952: 3. (Optional) - User's institutional status (e.g., faculty, staff
10953: or student - types as defined in localenroll::inst_usertypes
10954: for user's domain, which determines default quota for user.
10955: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10956:
10957: If a value has been stored in the user's environment,
1.536 raeburn 10958: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10959: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10960:
10961: =cut
10962:
10963: ###############################################
10964:
10965:
10966: sub get_user_quota {
1.1136 raeburn 10967: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10968: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10969: if (!defined($udom)) {
10970: $udom = $env{'user.domain'};
10971: }
10972: if (!defined($uname)) {
10973: $uname = $env{'user.name'};
10974: }
10975: if (($udom eq '' || $uname eq '') ||
10976: ($udom eq 'public') && ($uname eq 'public')) {
10977: $quota = 0;
1.536 raeburn 10978: $quotatype = 'default';
10979: $defquota = 0;
1.472 raeburn 10980: } else {
1.536 raeburn 10981: my $inststatus;
1.1134 raeburn 10982: if ($quotaname eq 'course') {
10983: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10984: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10985: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10986: } else {
10987: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10988: $quota = $cenv{'internal.uploadquota'};
10989: }
1.536 raeburn 10990: } else {
1.1134 raeburn 10991: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10992: if ($quotaname eq 'author') {
10993: $quota = $env{'environment.authorquota'};
10994: } else {
10995: $quota = $env{'environment.portfolioquota'};
10996: }
10997: $inststatus = $env{'environment.inststatus'};
10998: } else {
10999: my %userenv =
11000: &Apache::lonnet::get('environment',['portfolioquota',
11001: 'authorquota','inststatus'],$udom,$uname);
11002: my ($tmp) = keys(%userenv);
11003: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
11004: if ($quotaname eq 'author') {
11005: $quota = $userenv{'authorquota'};
11006: } else {
11007: $quota = $userenv{'portfolioquota'};
11008: }
11009: $inststatus = $userenv{'inststatus'};
11010: } else {
11011: undef(%userenv);
11012: }
11013: }
11014: }
11015: if ($quota eq '' || wantarray) {
11016: if ($quotaname eq 'course') {
11017: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 11018: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 11019: ($crstype eq 'community') || ($crstype eq 'textbook') ||
11020: ($crstype eq 'placement')) {
1.1136 raeburn 11021: $defquota = $domdefs{$crstype.'quota'};
11022: }
11023: if ($defquota eq '') {
11024: $defquota = 500;
11025: }
1.1134 raeburn 11026: } else {
11027: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
11028: }
11029: if ($quota eq '') {
11030: $quota = $defquota;
11031: $quotatype = 'default';
11032: } else {
11033: $quotatype = 'custom';
11034: }
1.472 raeburn 11035: }
11036: }
1.536 raeburn 11037: if (wantarray) {
11038: return ($quota,$quotatype,$settingstatus,$defquota);
11039: } else {
11040: return $quota;
11041: }
1.472 raeburn 11042: }
11043:
11044: ###############################################
11045:
11046: =pod
11047:
11048: =item * &default_quota()
11049:
1.536 raeburn 11050: Retrieves default quota assigned for storage of user portfolio files,
11051: given an (optional) user's institutional status.
1.472 raeburn 11052:
11053: Incoming parameters:
1.1142 raeburn 11054:
1.472 raeburn 11055: 1. domain
1.536 raeburn 11056: 2. (Optional) institutional status(es). This is a : separated list of
11057: status types (e.g., faculty, staff, student etc.)
11058: which apply to the user for whom the default is being retrieved.
11059: If the institutional status string in undefined, the domain
1.1134 raeburn 11060: default quota will be returned.
11061: 3. quota name - portfolio, author, or course
11062: (if no quota name provided, defaults to portfolio).
1.472 raeburn 11063:
11064: Returns:
1.1142 raeburn 11065:
1.1163 raeburn 11066: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 11067: 2. (Optional) institutional type which determined the value of the
11068: default quota.
1.472 raeburn 11069:
11070: If a value has been stored in the domain's configuration db,
11071: it will return that, otherwise it returns 20 (for backwards
11072: compatibility with domains which have not set up a configuration
1.1163 raeburn 11073: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 11074:
1.536 raeburn 11075: If the user's status includes multiple types (e.g., staff and student),
11076: the largest default quota which applies to the user determines the
11077: default quota returned.
11078:
1.472 raeburn 11079: =cut
11080:
11081: ###############################################
11082:
11083:
11084: sub default_quota {
1.1134 raeburn 11085: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 11086: my ($defquota,$settingstatus);
11087: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 11088: ['quotas'],$udom);
1.1134 raeburn 11089: my $key = 'defaultquota';
11090: if ($quotaname eq 'author') {
11091: $key = 'authorquota';
11092: }
1.622 raeburn 11093: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 11094: if ($inststatus ne '') {
1.765 raeburn 11095: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 11096: foreach my $item (@statuses) {
1.1134 raeburn 11097: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11098: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 11099: if ($defquota eq '') {
1.1134 raeburn 11100: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11101: $settingstatus = $item;
1.1134 raeburn 11102: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
11103: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 11104: $settingstatus = $item;
11105: }
11106: }
1.1134 raeburn 11107: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11108: if ($quotahash{'quotas'}{$item} ne '') {
11109: if ($defquota eq '') {
11110: $defquota = $quotahash{'quotas'}{$item};
11111: $settingstatus = $item;
11112: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
11113: $defquota = $quotahash{'quotas'}{$item};
11114: $settingstatus = $item;
11115: }
1.536 raeburn 11116: }
11117: }
11118: }
11119: }
11120: if ($defquota eq '') {
1.1134 raeburn 11121: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
11122: $defquota = $quotahash{'quotas'}{$key}{'default'};
11123: } elsif ($key eq 'defaultquota') {
1.711 raeburn 11124: $defquota = $quotahash{'quotas'}{'default'};
11125: }
1.536 raeburn 11126: $settingstatus = 'default';
1.1139 raeburn 11127: if ($defquota eq '') {
11128: if ($quotaname eq 'author') {
11129: $defquota = 500;
11130: }
11131: }
1.536 raeburn 11132: }
11133: } else {
11134: $settingstatus = 'default';
1.1134 raeburn 11135: if ($quotaname eq 'author') {
11136: $defquota = 500;
11137: } else {
11138: $defquota = 20;
11139: }
1.536 raeburn 11140: }
11141: if (wantarray) {
11142: return ($defquota,$settingstatus);
1.472 raeburn 11143: } else {
1.536 raeburn 11144: return $defquota;
1.472 raeburn 11145: }
11146: }
11147:
1.1135 raeburn 11148: ###############################################
11149:
11150: =pod
11151:
1.1136 raeburn 11152: =item * &excess_filesize_warning()
1.1135 raeburn 11153:
11154: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 11155: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 11156: space to be exceeded.
1.1136 raeburn 11157:
11158: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 11159: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 11160:
1.1165 raeburn 11161: Inputs: 7
1.1136 raeburn 11162: 1. username or coursenum
1.1135 raeburn 11163: 2. domain
1.1136 raeburn 11164: 3. context ('author' or 'course')
1.1135 raeburn 11165: 4. filename of file for which action is being requested
11166: 5. filesize (kB) of file
11167: 6. action being taken: copy or upload.
1.1237 raeburn 11168: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 11169:
11170: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 11171: otherwise return null.
11172:
11173: =back
1.1135 raeburn 11174:
11175: =cut
11176:
1.1136 raeburn 11177: sub excess_filesize_warning {
1.1165 raeburn 11178: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 11179: my $current_disk_usage = 0;
1.1165 raeburn 11180: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 11181: if ($context eq 'author') {
11182: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
11183: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
11184: } else {
11185: foreach my $subdir ('docs','supplemental') {
11186: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
11187: }
11188: }
1.1135 raeburn 11189: $disk_quota = int($disk_quota * 1000);
11190: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 11191: return '<p class="LC_warning">'.
1.1135 raeburn 11192: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 11193: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
11194: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 11195: $disk_quota,$current_disk_usage).
11196: '</p>';
11197: }
11198: return;
11199: }
11200:
11201: ###############################################
11202:
11203:
1.1136 raeburn 11204:
11205:
1.384 raeburn 11206: sub get_secgrprole_info {
11207: my ($cdom,$cnum,$needroles,$type) = @_;
11208: my %sections_count = &get_sections($cdom,$cnum);
11209: my @sections = (sort {$a <=> $b} keys(%sections_count));
11210: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
11211: my @groups = sort(keys(%curr_groups));
11212: my $allroles = [];
11213: my $rolehash;
11214: my $accesshash = {
11215: active => 'Currently has access',
11216: future => 'Will have future access',
11217: previous => 'Previously had access',
11218: };
11219: if ($needroles) {
11220: $rolehash = {'all' => 'all'};
1.385 albertel 11221: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
11222: if (&Apache::lonnet::error(%user_roles)) {
11223: undef(%user_roles);
11224: }
11225: foreach my $item (keys(%user_roles)) {
1.384 raeburn 11226: my ($role)=split(/\:/,$item,2);
11227: if ($role eq 'cr') { next; }
11228: if ($role =~ /^cr/) {
11229: $$rolehash{$role} = (split('/',$role))[3];
11230: } else {
11231: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
11232: }
11233: }
11234: foreach my $key (sort(keys(%{$rolehash}))) {
11235: push(@{$allroles},$key);
11236: }
11237: push (@{$allroles},'st');
11238: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
11239: }
11240: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
11241: }
11242:
1.555 raeburn 11243: sub user_picker {
1.1279 raeburn 11244: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 11245: my $currdom = $dom;
1.1253 raeburn 11246: my @alldoms = &Apache::lonnet::all_domains();
11247: if (@alldoms == 1) {
11248: my %domsrch = &Apache::lonnet::get_dom('configuration',
11249: ['directorysrch'],$alldoms[0]);
11250: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
11251: my $showdom = $domdesc;
11252: if ($showdom eq '') {
11253: $showdom = $dom;
11254: }
11255: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
11256: if ((!$domsrch{'directorysrch'}{'available'}) &&
11257: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
11258: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
11259: }
11260: }
11261: }
1.555 raeburn 11262: my %curr_selected = (
11263: srchin => 'dom',
1.580 raeburn 11264: srchby => 'lastname',
1.555 raeburn 11265: );
11266: my $srchterm;
1.625 raeburn 11267: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 11268: if ($srch->{'srchby'} ne '') {
11269: $curr_selected{'srchby'} = $srch->{'srchby'};
11270: }
11271: if ($srch->{'srchin'} ne '') {
11272: $curr_selected{'srchin'} = $srch->{'srchin'};
11273: }
11274: if ($srch->{'srchtype'} ne '') {
11275: $curr_selected{'srchtype'} = $srch->{'srchtype'};
11276: }
11277: if ($srch->{'srchdomain'} ne '') {
11278: $currdom = $srch->{'srchdomain'};
11279: }
11280: $srchterm = $srch->{'srchterm'};
11281: }
1.1222 damieng 11282: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 11283: 'usr' => 'Search criteria',
1.563 raeburn 11284: 'doma' => 'Domain/institution to search',
1.558 albertel 11285: 'uname' => 'username',
11286: 'lastname' => 'last name',
1.555 raeburn 11287: 'lastfirst' => 'last name, first name',
1.558 albertel 11288: 'crs' => 'in this course',
1.576 raeburn 11289: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 11290: 'alc' => 'all LON-CAPA',
1.573 raeburn 11291: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 11292: 'exact' => 'is',
11293: 'contains' => 'contains',
1.569 raeburn 11294: 'begins' => 'begins with',
1.1222 damieng 11295: );
11296: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 11297: 'youm' => "You must include some text to search for.",
11298: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
11299: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
11300: 'yomc' => "You must choose a domain when using an institutional directory search.",
11301: 'ymcd' => "You must choose a domain when using a domain search.",
11302: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
11303: 'whse' => "When searching by last,first you must include at least one character in the first name.",
11304: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 11305: );
1.1222 damieng 11306: &html_escape(\%html_lt);
11307: &js_escape(\%js_lt);
1.1255 raeburn 11308: my $domform;
1.1277 raeburn 11309: my $allow_blank = 1;
1.1255 raeburn 11310: if ($fixeddom) {
1.1277 raeburn 11311: $allow_blank = 0;
11312: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 11313: } else {
1.1287 raeburn 11314: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 11315: my ($trusted,$untrusted);
1.1287 raeburn 11316: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 11317: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 11318: } elsif ($context eq 'author') {
1.1288 raeburn 11319: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 11320: } elsif ($context eq 'domain') {
1.1288 raeburn 11321: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 11322: }
1.1288 raeburn 11323: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 11324: }
1.563 raeburn 11325: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 11326:
11327: my @srchins = ('crs','dom','alc','instd');
11328:
11329: foreach my $option (@srchins) {
11330: # FIXME 'alc' option unavailable until
11331: # loncreateuser::print_user_query_page()
11332: # has been completed.
11333: next if ($option eq 'alc');
1.880 raeburn 11334: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 11335: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 11336: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 11337: if ($curr_selected{'srchin'} eq $option) {
11338: $srchinsel .= '
1.1222 damieng 11339: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 11340: } else {
11341: $srchinsel .= '
1.1222 damieng 11342: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 11343: }
1.555 raeburn 11344: }
1.563 raeburn 11345: $srchinsel .= "\n </select>\n";
1.555 raeburn 11346:
11347: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 11348: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 11349: if ($curr_selected{'srchby'} eq $option) {
11350: $srchbysel .= '
1.1222 damieng 11351: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11352: } else {
11353: $srchbysel .= '
1.1222 damieng 11354: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11355: }
11356: }
11357: $srchbysel .= "\n </select>\n";
11358:
11359: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 11360: foreach my $option ('begins','contains','exact') {
1.555 raeburn 11361: if ($curr_selected{'srchtype'} eq $option) {
11362: $srchtypesel .= '
1.1222 damieng 11363: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 11364: } else {
11365: $srchtypesel .= '
1.1222 damieng 11366: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 11367: }
11368: }
11369: $srchtypesel .= "\n </select>\n";
11370:
1.558 albertel 11371: my ($newuserscript,$new_user_create);
1.994 raeburn 11372: my $context_dom = $env{'request.role.domain'};
11373: if ($context eq 'requestcrs') {
11374: if ($env{'form.coursedom'} ne '') {
11375: $context_dom = $env{'form.coursedom'};
11376: }
11377: }
1.556 raeburn 11378: if ($forcenewuser) {
1.576 raeburn 11379: if (ref($srch) eq 'HASH') {
1.994 raeburn 11380: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 11381: if ($cancreate) {
11382: $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>';
11383: } else {
1.799 bisitz 11384: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 11385: my %usertypetext = (
11386: official => 'institutional',
11387: unofficial => 'non-institutional',
11388: );
1.799 bisitz 11389: $new_user_create = '<p class="LC_warning">'
11390: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
11391: .' '
11392: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
11393: ,'<a href="'.$helplink.'">','</a>')
11394: .'</p><br />';
1.627 raeburn 11395: }
1.576 raeburn 11396: }
11397: }
11398:
1.556 raeburn 11399: $newuserscript = <<"ENDSCRIPT";
11400:
1.570 raeburn 11401: function setSearch(createnew,callingForm) {
1.556 raeburn 11402: if (createnew == 1) {
1.570 raeburn 11403: for (var i=0; i<callingForm.srchby.length; i++) {
11404: if (callingForm.srchby.options[i].value == 'uname') {
11405: callingForm.srchby.selectedIndex = i;
1.556 raeburn 11406: }
11407: }
1.570 raeburn 11408: for (var i=0; i<callingForm.srchin.length; i++) {
11409: if ( callingForm.srchin.options[i].value == 'dom') {
11410: callingForm.srchin.selectedIndex = i;
1.556 raeburn 11411: }
11412: }
1.570 raeburn 11413: for (var i=0; i<callingForm.srchtype.length; i++) {
11414: if (callingForm.srchtype.options[i].value == 'exact') {
11415: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 11416: }
11417: }
1.570 raeburn 11418: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 11419: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 11420: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 11421: }
11422: }
11423: }
11424: }
11425: ENDSCRIPT
1.558 albertel 11426:
1.556 raeburn 11427: }
11428:
1.555 raeburn 11429: my $output = <<"END_BLOCK";
1.556 raeburn 11430: <script type="text/javascript">
1.824 bisitz 11431: // <![CDATA[
1.570 raeburn 11432: function validateEntry(callingForm) {
1.558 albertel 11433:
1.556 raeburn 11434: var checkok = 1;
1.558 albertel 11435: var srchin;
1.570 raeburn 11436: for (var i=0; i<callingForm.srchin.length; i++) {
11437: if ( callingForm.srchin[i].checked ) {
11438: srchin = callingForm.srchin[i].value;
1.558 albertel 11439: }
11440: }
11441:
1.570 raeburn 11442: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
11443: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
11444: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
11445: var srchterm = callingForm.srchterm.value;
11446: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 11447: var msg = "";
11448:
11449: if (srchterm == "") {
11450: checkok = 0;
1.1222 damieng 11451: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 11452: }
11453:
1.569 raeburn 11454: if (srchtype== 'begins') {
11455: if (srchterm.length < 2) {
11456: checkok = 0;
1.1222 damieng 11457: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 11458: }
11459: }
11460:
1.556 raeburn 11461: if (srchtype== 'contains') {
11462: if (srchterm.length < 3) {
11463: checkok = 0;
1.1222 damieng 11464: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 11465: }
11466: }
11467: if (srchin == 'instd') {
11468: if (srchdomain == '') {
11469: checkok = 0;
1.1222 damieng 11470: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 11471: }
11472: }
11473: if (srchin == 'dom') {
11474: if (srchdomain == '') {
11475: checkok = 0;
1.1222 damieng 11476: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 11477: }
11478: }
11479: if (srchby == 'lastfirst') {
11480: if (srchterm.indexOf(",") == -1) {
11481: checkok = 0;
1.1222 damieng 11482: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 11483: }
11484: if (srchterm.indexOf(",") == srchterm.length -1) {
11485: checkok = 0;
1.1222 damieng 11486: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 11487: }
11488: }
11489: if (checkok == 0) {
1.1222 damieng 11490: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 11491: return;
11492: }
11493: if (checkok == 1) {
1.570 raeburn 11494: callingForm.submit();
1.556 raeburn 11495: }
11496: }
11497:
11498: $newuserscript
11499:
1.824 bisitz 11500: // ]]>
1.556 raeburn 11501: </script>
1.558 albertel 11502:
11503: $new_user_create
11504:
1.555 raeburn 11505: END_BLOCK
1.558 albertel 11506:
1.876 raeburn 11507: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 11508: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 11509: $domform.
11510: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 11511: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 11512: $srchbysel.
11513: $srchtypesel.
11514: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
11515: $srchinsel.
11516: &Apache::lonhtmlcommon::row_closure(1).
11517: &Apache::lonhtmlcommon::end_pick_box().
11518: '<br />';
1.1253 raeburn 11519: return ($output,1);
1.555 raeburn 11520: }
11521:
1.612 raeburn 11522: sub user_rule_check {
1.615 raeburn 11523: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 11524: my ($response,%inst_response);
1.612 raeburn 11525: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 11526: if (keys(%{$usershash}) > 1) {
11527: my (%by_username,%by_id,%userdoms);
11528: my $checkid;
11529: if (ref($checks) eq 'HASH') {
11530: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
11531: $checkid = 1;
11532: }
11533: }
11534: foreach my $user (keys(%{$usershash})) {
11535: my ($uname,$udom) = split(/:/,$user);
11536: if ($checkid) {
11537: if (ref($usershash->{$user}) eq 'HASH') {
11538: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 11539: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 11540: $userdoms{$udom} = 1;
1.1227 raeburn 11541: if (ref($inst_results) eq 'HASH') {
11542: $inst_results->{$uname.':'.$udom} = {};
11543: }
1.1226 raeburn 11544: }
11545: }
11546: } else {
11547: $by_username{$udom}{$uname} = 1;
11548: $userdoms{$udom} = 1;
1.1227 raeburn 11549: if (ref($inst_results) eq 'HASH') {
11550: $inst_results->{$uname.':'.$udom} = {};
11551: }
1.1226 raeburn 11552: }
11553: }
11554: foreach my $udom (keys(%userdoms)) {
11555: if (!$got_rules->{$udom}) {
11556: my %domconfig = &Apache::lonnet::get_dom('configuration',
11557: ['usercreation'],$udom);
11558: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11559: foreach my $item ('username','id') {
11560: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 11561: $$curr_rules{$udom}{$item} =
11562: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 11563: }
11564: }
11565: }
11566: $got_rules->{$udom} = 1;
11567: }
1.612 raeburn 11568: }
1.1226 raeburn 11569: if ($checkid) {
11570: foreach my $udom (keys(%by_id)) {
11571: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
11572: if ($outcome eq 'ok') {
1.1227 raeburn 11573: foreach my $id (keys(%{$by_id{$udom}})) {
11574: my $uname = $by_id{$udom}{$id};
11575: $inst_response{$uname.':'.$udom} = $outcome;
11576: }
1.1226 raeburn 11577: if (ref($results) eq 'HASH') {
11578: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 11579: if (exists($inst_response{$uname.':'.$udom})) {
11580: $inst_response{$uname.':'.$udom} = $outcome;
11581: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11582: }
1.1226 raeburn 11583: }
11584: }
11585: }
1.612 raeburn 11586: }
1.615 raeburn 11587: } else {
1.1226 raeburn 11588: foreach my $udom (keys(%by_username)) {
11589: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
11590: if ($outcome eq 'ok') {
1.1227 raeburn 11591: foreach my $uname (keys(%{$by_username{$udom}})) {
11592: $inst_response{$uname.':'.$udom} = $outcome;
11593: }
1.1226 raeburn 11594: if (ref($results) eq 'HASH') {
11595: foreach my $uname (keys(%{$results})) {
11596: $inst_results->{$uname.':'.$udom} = $results->{$uname};
11597: }
11598: }
11599: }
11600: }
1.612 raeburn 11601: }
1.1226 raeburn 11602: } elsif (keys(%{$usershash}) == 1) {
11603: my $user = (keys(%{$usershash}))[0];
11604: my ($uname,$udom) = split(/:/,$user);
11605: if (($udom ne '') && ($uname ne '')) {
11606: if (ref($usershash->{$user}) eq 'HASH') {
11607: if (ref($checks) eq 'HASH') {
11608: if (defined($checks->{'username'})) {
11609: ($inst_response{$user},%{$inst_results->{$user}}) =
11610: &Apache::lonnet::get_instuser($udom,$uname);
11611: } elsif (defined($checks->{'id'})) {
11612: if ($usershash->{$user}->{'id'} ne '') {
11613: ($inst_response{$user},%{$inst_results->{$user}}) =
11614: &Apache::lonnet::get_instuser($udom,undef,
11615: $usershash->{$user}->{'id'});
11616: } else {
11617: ($inst_response{$user},%{$inst_results->{$user}}) =
11618: &Apache::lonnet::get_instuser($udom,$uname);
11619: }
1.585 raeburn 11620: }
1.1226 raeburn 11621: } else {
11622: ($inst_response{$user},%{$inst_results->{$user}}) =
11623: &Apache::lonnet::get_instuser($udom,$uname);
11624: return;
11625: }
11626: if (!$got_rules->{$udom}) {
11627: my %domconfig = &Apache::lonnet::get_dom('configuration',
11628: ['usercreation'],$udom);
11629: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11630: foreach my $item ('username','id') {
11631: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
11632: $$curr_rules{$udom}{$item} =
11633: $domconfig{'usercreation'}{$item.'_rule'};
11634: }
11635: }
11636: }
11637: $got_rules->{$udom} = 1;
1.585 raeburn 11638: }
11639: }
1.1226 raeburn 11640: } else {
11641: return;
11642: }
11643: } else {
11644: return;
11645: }
11646: foreach my $user (keys(%{$usershash})) {
11647: my ($uname,$udom) = split(/:/,$user);
11648: next if (($udom eq '') || ($uname eq ''));
11649: my $id;
1.1227 raeburn 11650: if (ref($inst_results) eq 'HASH') {
11651: if (ref($inst_results->{$user}) eq 'HASH') {
11652: $id = $inst_results->{$user}->{'id'};
11653: }
11654: }
11655: if ($id eq '') {
11656: if (ref($usershash->{$user})) {
11657: $id = $usershash->{$user}->{'id'};
11658: }
1.585 raeburn 11659: }
1.612 raeburn 11660: foreach my $item (keys(%{$checks})) {
11661: if (ref($$curr_rules{$udom}) eq 'HASH') {
11662: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11663: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 11664: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11665: $$curr_rules{$udom}{$item});
1.612 raeburn 11666: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11667: if ($rule_check{$rule}) {
11668: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 11669: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11670: if (ref($inst_results) eq 'HASH') {
11671: if (ref($inst_results->{$user}) eq 'HASH') {
11672: if (keys(%{$inst_results->{$user}}) == 0) {
11673: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 11674: } elsif ($item eq 'id') {
11675: if ($inst_results->{$user}->{'id'} eq '') {
11676: $$alerts{$item}{$udom}{$uname} = 1;
11677: }
1.615 raeburn 11678: }
1.612 raeburn 11679: }
11680: }
1.615 raeburn 11681: }
11682: last;
1.585 raeburn 11683: }
11684: }
11685: }
11686: }
11687: }
11688: }
11689: }
11690: }
1.612 raeburn 11691: return;
11692: }
11693:
11694: sub user_rule_formats {
11695: my ($domain,$domdesc,$curr_rules,$check) = @_;
11696: my %text = (
11697: 'username' => 'Usernames',
11698: 'id' => 'IDs',
11699: );
11700: my $output;
11701: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11702: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11703: if (@{$ruleorder} > 0) {
1.1102 raeburn 11704: $output = '<br />'.
11705: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11706: '<span class="LC_cusr_emph">','</span>',$domdesc).
11707: ' <ul>';
1.612 raeburn 11708: foreach my $rule (@{$ruleorder}) {
11709: if (ref($curr_rules) eq 'ARRAY') {
11710: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11711: if (ref($rules->{$rule}) eq 'HASH') {
11712: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11713: $rules->{$rule}{'desc'}.'</li>';
11714: }
11715: }
11716: }
11717: }
11718: $output .= '</ul>';
11719: }
11720: }
11721: return $output;
11722: }
11723:
11724: sub instrule_disallow_msg {
1.615 raeburn 11725: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11726: my $response;
11727: my %text = (
11728: item => 'username',
11729: items => 'usernames',
11730: match => 'matches',
11731: do => 'does',
11732: action => 'a username',
11733: one => 'one',
11734: );
11735: if ($count > 1) {
11736: $text{'item'} = 'usernames';
11737: $text{'match'} ='match';
11738: $text{'do'} = 'do';
11739: $text{'action'} = 'usernames',
11740: $text{'one'} = 'ones';
11741: }
11742: if ($checkitem eq 'id') {
11743: $text{'items'} = 'IDs';
11744: $text{'item'} = 'ID';
11745: $text{'action'} = 'an ID';
1.615 raeburn 11746: if ($count > 1) {
11747: $text{'item'} = 'IDs';
11748: $text{'action'} = 'IDs';
11749: }
1.612 raeburn 11750: }
1.674 bisitz 11751: $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 11752: if ($mode eq 'upload') {
11753: if ($checkitem eq 'username') {
11754: $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'}.");
11755: } elsif ($checkitem eq 'id') {
1.674 bisitz 11756: $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 11757: }
1.669 raeburn 11758: } elsif ($mode eq 'selfcreate') {
11759: if ($checkitem eq 'id') {
11760: $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.");
11761: }
1.615 raeburn 11762: } else {
11763: if ($checkitem eq 'username') {
11764: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11765: } elsif ($checkitem eq 'id') {
11766: $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.");
11767: }
1.612 raeburn 11768: }
11769: return $response;
1.585 raeburn 11770: }
11771:
1.624 raeburn 11772: sub personal_data_fieldtitles {
11773: my %fieldtitles = &Apache::lonlocal::texthash (
11774: id => 'Student/Employee ID',
11775: permanentemail => 'E-mail address',
11776: lastname => 'Last Name',
11777: firstname => 'First Name',
11778: middlename => 'Middle Name',
11779: generation => 'Generation',
11780: gen => 'Generation',
1.765 raeburn 11781: inststatus => 'Affiliation',
1.624 raeburn 11782: );
11783: return %fieldtitles;
11784: }
11785:
1.642 raeburn 11786: sub sorted_inst_types {
11787: my ($dom) = @_;
1.1185 raeburn 11788: my ($usertypes,$order);
11789: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11790: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11791: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11792: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11793: } else {
11794: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11795: }
1.642 raeburn 11796: my $othertitle = &mt('All users');
11797: if ($env{'request.course.id'}) {
1.668 raeburn 11798: $othertitle = &mt('Any users');
1.642 raeburn 11799: }
11800: my @types;
11801: if (ref($order) eq 'ARRAY') {
11802: @types = @{$order};
11803: }
11804: if (@types == 0) {
11805: if (ref($usertypes) eq 'HASH') {
11806: @types = sort(keys(%{$usertypes}));
11807: }
11808: }
11809: if (keys(%{$usertypes}) > 0) {
11810: $othertitle = &mt('Other users');
11811: }
11812: return ($othertitle,$usertypes,\@types);
11813: }
11814:
1.645 raeburn 11815: sub get_institutional_codes {
1.1361 raeburn 11816: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 11817: # Get complete list of course sections to update
11818: my @currsections = ();
11819: my @currxlists = ();
1.1361 raeburn 11820: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 11821: my $coursecode = $$settings{'internal.coursecode'};
1.1361 raeburn 11822: my $crskey = $crs.':'.$coursecode;
11823: @{$unclutteredsec{$crskey}} = ();
11824: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 11825:
11826: if ($$settings{'internal.sectionnums'} ne '') {
11827: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11828: }
11829:
11830: if ($$settings{'internal.crosslistings'} ne '') {
11831: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11832: }
11833:
11834: if (@currxlists > 0) {
1.1361 raeburn 11835: foreach my $xl (@currxlists) {
11836: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 11837: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 11838: push(@{$allcourses},$1);
1.645 raeburn 11839: $$LC_code{$1} = $2;
11840: }
11841: }
11842: }
11843: }
1.1361 raeburn 11844:
1.645 raeburn 11845: if (@currsections > 0) {
1.1361 raeburn 11846: foreach my $sec (@currsections) {
11847: if ($sec =~ m/^(\w+):(\w*)$/ ) {
11848: my $instsec = $1;
1.645 raeburn 11849: my $lc_sec = $2;
1.1361 raeburn 11850: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
11851: push(@{$unclutteredsec{$crskey}},$instsec);
11852: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
11853: }
11854: }
11855: }
11856: }
11857:
11858: if (@{$unclutteredsec{$crskey}} > 0) {
11859: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
11860: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
11861: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
11862: my $sec = $coursecode.$formattedsec{$crskey}[$i];
11863: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1263 raeburn 11864: push(@{$allcourses},$sec);
1.1361 raeburn 11865: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 11866: }
11867: }
11868: }
11869: }
11870: return;
11871: }
11872:
1.971 raeburn 11873: sub get_standard_codeitems {
11874: return ('Year','Semester','Department','Number','Section');
11875: }
11876:
1.112 bowersj2 11877: =pod
11878:
1.780 raeburn 11879: =head1 Slot Helpers
11880:
11881: =over 4
11882:
11883: =item * sorted_slots()
11884:
1.1040 raeburn 11885: Sorts an array of slot names in order of an optional sort key,
11886: default sort is by slot start time (earliest first).
1.780 raeburn 11887:
11888: Inputs:
11889:
11890: =over 4
11891:
11892: slotsarr - Reference to array of unsorted slot names.
11893:
11894: slots - Reference to hash of hash, where outer hash keys are slot names.
11895:
1.1040 raeburn 11896: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11897:
1.549 albertel 11898: =back
11899:
1.780 raeburn 11900: Returns:
11901:
11902: =over 4
11903:
1.1040 raeburn 11904: sorted - An array of slot names sorted by a specified sort key
11905: (default sort key is start time of the slot).
1.780 raeburn 11906:
11907: =back
11908:
11909: =cut
11910:
11911:
11912: sub sorted_slots {
1.1040 raeburn 11913: my ($slotsarr,$slots,$sortkey) = @_;
11914: if ($sortkey eq '') {
11915: $sortkey = 'starttime';
11916: }
1.780 raeburn 11917: my @sorted;
11918: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11919: @sorted =
11920: sort {
11921: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11922: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11923: }
11924: if (ref($slots->{$a})) { return -1;}
11925: if (ref($slots->{$b})) { return 1;}
11926: return 0;
11927: } @{$slotsarr};
11928: }
11929: return @sorted;
11930: }
11931:
1.1040 raeburn 11932: =pod
11933:
11934: =item * get_future_slots()
11935:
11936: Inputs:
11937:
11938: =over 4
11939:
11940: cnum - course number
11941:
11942: cdom - course domain
11943:
11944: now - current UNIX time
11945:
11946: symb - optional symb
11947:
11948: =back
11949:
11950: Returns:
11951:
11952: =over 4
11953:
11954: sorted_reservable - ref to array of student_schedulable slots currently
11955: reservable, ordered by end date of reservation period.
11956:
11957: reservable_now - ref to hash of student_schedulable slots currently
11958: reservable.
11959:
11960: Keys in inner hash are:
11961: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11962: (b) endreserve: end date of reservation period.
11963: (c) uniqueperiod: start,end dates when slot is to be uniquely
11964: selected.
1.1040 raeburn 11965:
11966: sorted_future - ref to array of student_schedulable slots reservable in
11967: the future, ordered by start date of reservation period.
11968:
11969: future_reservable - ref to hash of student_schedulable slots reservable
11970: in the future.
11971:
11972: Keys in inner hash are:
11973: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11974: (b) startreserve: start date of reservation period.
11975: (c) uniqueperiod: start,end dates when slot is to be uniquely
11976: selected.
1.1040 raeburn 11977:
11978: =back
11979:
11980: =cut
11981:
11982: sub get_future_slots {
11983: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11984: my $map;
11985: if ($symb) {
11986: ($map) = &Apache::lonnet::decode_symb($symb);
11987: }
1.1040 raeburn 11988: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11989: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11990: foreach my $slot (keys(%slots)) {
11991: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11992: if ($symb) {
1.1229 raeburn 11993: if ($slots{$slot}->{'symb'} ne '') {
11994: my $canuse;
11995: my %oksymbs;
11996: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11997: map { $oksymbs{$_} = 1; } @slotsymbs;
11998: if ($oksymbs{$symb}) {
11999: $canuse = 1;
12000: } else {
12001: foreach my $item (@slotsymbs) {
12002: if ($item =~ /\.(page|sequence)$/) {
12003: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
12004: if (($map ne '') && ($map eq $sloturl)) {
12005: $canuse = 1;
12006: last;
12007: }
12008: }
12009: }
12010: }
12011: next unless ($canuse);
12012: }
1.1040 raeburn 12013: }
12014: if (($slots{$slot}->{'starttime'} > $now) &&
12015: ($slots{$slot}->{'endtime'} > $now)) {
12016: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
12017: my $userallowed = 0;
12018: if ($slots{$slot}->{'allowedsections'}) {
12019: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
12020: if (!defined($env{'request.role.sec'})
12021: && grep(/^No section assigned$/,@allowed_sec)) {
12022: $userallowed=1;
12023: } else {
12024: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
12025: $userallowed=1;
12026: }
12027: }
12028: unless ($userallowed) {
12029: if (defined($env{'request.course.groups'})) {
12030: my @groups = split(/:/,$env{'request.course.groups'});
12031: foreach my $group (@groups) {
12032: if (grep(/^\Q$group\E$/,@allowed_sec)) {
12033: $userallowed=1;
12034: last;
12035: }
12036: }
12037: }
12038: }
12039: }
12040: if ($slots{$slot}->{'allowedusers'}) {
12041: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
12042: my $user = $env{'user.name'}.':'.$env{'user.domain'};
12043: if (grep(/^\Q$user\E$/,@allowed_users)) {
12044: $userallowed = 1;
12045: }
12046: }
12047: next unless($userallowed);
12048: }
12049: my $startreserve = $slots{$slot}->{'startreserve'};
12050: my $endreserve = $slots{$slot}->{'endreserve'};
12051: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 12052: my $uniqueperiod;
12053: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
12054: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
12055: }
1.1040 raeburn 12056: if (($startreserve < $now) &&
12057: (!$endreserve || $endreserve > $now)) {
12058: my $lastres = $endreserve;
12059: if (!$lastres) {
12060: $lastres = $slots{$slot}->{'starttime'};
12061: }
12062: $reservable_now{$slot} = {
12063: symb => $symb,
1.1250 raeburn 12064: endreserve => $lastres,
12065: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12066: };
12067: } elsif (($startreserve > $now) &&
12068: (!$endreserve || $endreserve > $startreserve)) {
12069: $future_reservable{$slot} = {
12070: symb => $symb,
1.1250 raeburn 12071: startreserve => $startreserve,
12072: uniqueperiod => $uniqueperiod,
1.1040 raeburn 12073: };
12074: }
12075: }
12076: }
12077: my @unsorted_reservable = keys(%reservable_now);
12078: if (@unsorted_reservable > 0) {
12079: @sorted_reservable =
12080: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
12081: }
12082: my @unsorted_future = keys(%future_reservable);
12083: if (@unsorted_future > 0) {
12084: @sorted_future =
12085: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
12086: }
12087: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
12088: }
1.780 raeburn 12089:
12090: =pod
12091:
1.1057 foxr 12092: =back
12093:
1.549 albertel 12094: =head1 HTTP Helpers
12095:
12096: =over 4
12097:
1.648 raeburn 12098: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 12099:
1.258 albertel 12100: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 12101: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 12102: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 12103:
12104: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
12105: $possible_names is an ref to an array of form element names. As an example:
12106: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 12107: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 12108:
12109: =cut
1.1 albertel 12110:
1.6 albertel 12111: sub get_unprocessed_cgi {
1.25 albertel 12112: my ($query,$possible_names)= @_;
1.26 matthew 12113: # $Apache::lonxml::debug=1;
1.356 albertel 12114: foreach my $pair (split(/&/,$query)) {
12115: my ($name, $value) = split(/=/,$pair);
1.369 www 12116: $name = &unescape($name);
1.25 albertel 12117: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
12118: $value =~ tr/+/ /;
12119: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 12120: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 12121: }
1.16 harris41 12122: }
1.6 albertel 12123: }
12124:
1.112 bowersj2 12125: =pod
12126:
1.648 raeburn 12127: =item * &cacheheader()
1.112 bowersj2 12128:
12129: returns cache-controlling header code
12130:
12131: =cut
12132:
1.7 albertel 12133: sub cacheheader {
1.258 albertel 12134: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 12135: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
12136: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 12137: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
12138: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 12139: return $output;
1.7 albertel 12140: }
12141:
1.112 bowersj2 12142: =pod
12143:
1.648 raeburn 12144: =item * &no_cache($r)
1.112 bowersj2 12145:
12146: specifies header code to not have cache
12147:
12148: =cut
12149:
1.9 albertel 12150: sub no_cache {
1.216 albertel 12151: my ($r) = @_;
12152: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 12153: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 12154: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
12155: $r->no_cache(1);
12156: $r->header_out("Expires" => $date);
12157: $r->header_out("Pragma" => "no-cache");
1.123 www 12158: }
12159:
12160: sub content_type {
1.181 albertel 12161: my ($r,$type,$charset) = @_;
1.299 foxr 12162: if ($r) {
12163: # Note that printout.pl calls this with undef for $r.
12164: &no_cache($r);
12165: }
1.258 albertel 12166: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 12167: unless ($charset) {
12168: $charset=&Apache::lonlocal::current_encoding;
12169: }
12170: if ($charset) { $type.='; charset='.$charset; }
12171: if ($r) {
12172: $r->content_type($type);
12173: } else {
12174: print("Content-type: $type\n\n");
12175: }
1.9 albertel 12176: }
1.25 albertel 12177:
1.112 bowersj2 12178: =pod
12179:
1.648 raeburn 12180: =item * &add_to_env($name,$value)
1.112 bowersj2 12181:
1.258 albertel 12182: adds $name to the %env hash with value
1.112 bowersj2 12183: $value, if $name already exists, the entry is converted to an array
12184: reference and $value is added to the array.
12185:
12186: =cut
12187:
1.25 albertel 12188: sub add_to_env {
12189: my ($name,$value)=@_;
1.258 albertel 12190: if (defined($env{$name})) {
12191: if (ref($env{$name})) {
1.25 albertel 12192: #already have multiple values
1.258 albertel 12193: push(@{ $env{$name} },$value);
1.25 albertel 12194: } else {
12195: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 12196: my $first=$env{$name};
12197: undef($env{$name});
12198: push(@{ $env{$name} },$first,$value);
1.25 albertel 12199: }
12200: } else {
1.258 albertel 12201: $env{$name}=$value;
1.25 albertel 12202: }
1.31 albertel 12203: }
1.149 albertel 12204:
12205: =pod
12206:
1.648 raeburn 12207: =item * &get_env_multiple($name)
1.149 albertel 12208:
1.258 albertel 12209: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 12210: values may be defined and end up as an array ref.
12211:
12212: returns an array of values
12213:
12214: =cut
12215:
12216: sub get_env_multiple {
12217: my ($name) = @_;
12218: my @values;
1.258 albertel 12219: if (defined($env{$name})) {
1.149 albertel 12220: # exists is it an array
1.258 albertel 12221: if (ref($env{$name})) {
12222: @values=@{ $env{$name} };
1.149 albertel 12223: } else {
1.258 albertel 12224: $values[0]=$env{$name};
1.149 albertel 12225: }
12226: }
12227: return(@values);
12228: }
12229:
1.1249 damieng 12230: # Looks at given dependencies, and returns something depending on the context.
12231: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
12232: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
12233: # For all other contexts, returns ($output, $counter, $numpathchg).
12234: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
12235: # $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.
12236: # $numpathchg: integer with the number of cleaned up dependency paths.
12237: # \%existing: hash reference clean path -> 1 only for existing dependencies.
12238: # \%mapping: hash reference clean path -> original path for all dependencies.
12239: # @param {string} actionurl - The path to the handler, indicative of the context.
12240: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
12241: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
12242: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
12243: # @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)
12244: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 12245: sub ask_for_embedded_content {
1.1249 damieng 12246: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 12247: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 12248: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 12249: %currsubfile,%unused,$rem);
1.1071 raeburn 12250: my $counter = 0;
12251: my $numnew = 0;
1.987 raeburn 12252: my $numremref = 0;
12253: my $numinvalid = 0;
12254: my $numpathchg = 0;
12255: my $numexisting = 0;
1.1071 raeburn 12256: my $numunused = 0;
12257: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 12258: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 12259: my $heading = &mt('Upload embedded files');
12260: my $buttontext = &mt('Upload');
12261:
1.1249 damieng 12262: # fills these variables based on the context:
12263: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
12264: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 12265: if ($env{'request.course.id'}) {
1.1123 raeburn 12266: if ($actionurl eq '/adm/dependencies') {
12267: $navmap = Apache::lonnavmaps::navmap->new();
12268: }
12269: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12270: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 12271: }
1.1123 raeburn 12272: if (($actionurl eq '/adm/portfolio') ||
12273: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 12274: my $current_path='/';
12275: if ($env{'form.currentpath'}) {
12276: $current_path = $env{'form.currentpath'};
12277: }
12278: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 12279: $udom = $cdom;
12280: $uname = $cnum;
1.984 raeburn 12281: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
12282: } else {
12283: $udom = $env{'user.domain'};
12284: $uname = $env{'user.name'};
12285: $url = '/userfiles/portfolio';
12286: }
1.987 raeburn 12287: $toplevel = $url.'/';
1.984 raeburn 12288: $url .= $current_path;
12289: $getpropath = 1;
1.987 raeburn 12290: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12291: ($actionurl eq '/adm/imsimport')) {
1.1022 www 12292: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 12293: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 12294: $toplevel = $url;
1.984 raeburn 12295: if ($rest ne '') {
1.987 raeburn 12296: $url .= $rest;
12297: }
12298: } elsif ($actionurl eq '/adm/coursedocs') {
12299: if (ref($args) eq 'HASH') {
1.1071 raeburn 12300: $url = $args->{'docs_url'};
12301: $toplevel = $url;
1.1084 raeburn 12302: if ($args->{'context'} eq 'paste') {
12303: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
12304: ($path) =
12305: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12306: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12307: $fileloc =~ s{^/}{};
12308: }
1.1071 raeburn 12309: }
1.1084 raeburn 12310: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 12311: if ($env{'request.course.id'} ne '') {
12312: if (ref($args) eq 'HASH') {
12313: $url = $args->{'docs_url'};
12314: $title = $args->{'docs_title'};
1.1126 raeburn 12315: $toplevel = $url;
12316: unless ($toplevel =~ m{^/}) {
12317: $toplevel = "/$url";
12318: }
1.1085 raeburn 12319: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 12320: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
12321: $path = $1;
12322: } else {
12323: ($path) =
12324: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
12325: }
1.1195 raeburn 12326: if ($toplevel=~/^\/*(uploaded|editupload)/) {
12327: $fileloc = $toplevel;
12328: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
12329: my ($udom,$uname,$fname) =
12330: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
12331: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
12332: } else {
12333: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
12334: }
1.1071 raeburn 12335: $fileloc =~ s{^/}{};
12336: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
12337: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
12338: }
1.987 raeburn 12339: }
1.1123 raeburn 12340: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12341: $udom = $cdom;
12342: $uname = $cnum;
12343: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
12344: $toplevel = $url;
12345: $path = $url;
12346: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
12347: $fileloc =~ s{^/}{};
1.987 raeburn 12348: }
1.1249 damieng 12349:
12350: # parses the dependency paths to get some info
12351: # fills $newfiles, $mapping, $subdependencies, $dependencies
12352: # $newfiles: hash URL -> 1 for new files or external URLs
12353: # (will be completed later)
12354: # $mapping:
12355: # for external URLs: external URL -> external URL
12356: # for relative paths: clean path -> original path
12357: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
12358: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 12359: foreach my $file (keys(%{$allfiles})) {
12360: my $embed_file;
12361: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
12362: $embed_file = $1;
12363: } else {
12364: $embed_file = $file;
12365: }
1.1158 raeburn 12366: my ($absolutepath,$cleaned_file);
12367: if ($embed_file =~ m{^\w+://}) {
12368: $cleaned_file = $embed_file;
1.1147 raeburn 12369: $newfiles{$cleaned_file} = 1;
12370: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12371: } else {
1.1158 raeburn 12372: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 12373: if ($embed_file =~ m{^/}) {
12374: $absolutepath = $embed_file;
12375: }
1.1147 raeburn 12376: if ($cleaned_file =~ m{/}) {
12377: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 12378: $path = &check_for_traversal($path,$url,$toplevel);
12379: my $item = $fname;
12380: if ($path ne '') {
12381: $item = $path.'/'.$fname;
12382: $subdependencies{$path}{$fname} = 1;
12383: } else {
12384: $dependencies{$item} = 1;
12385: }
12386: if ($absolutepath) {
12387: $mapping{$item} = $absolutepath;
12388: } else {
12389: $mapping{$item} = $embed_file;
12390: }
12391: } else {
12392: $dependencies{$embed_file} = 1;
12393: if ($absolutepath) {
1.1147 raeburn 12394: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 12395: } else {
1.1147 raeburn 12396: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 12397: }
12398: }
1.984 raeburn 12399: }
12400: }
1.1249 damieng 12401:
12402: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
12403: # and lists
12404: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
12405: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
12406: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
12407: # the path had to be cleaned up
12408: # $existing: hash clean path -> 1 if the file exists
12409: # $numexisting: number of keys in $existing
12410: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
12411: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
12412: # dependency subdirectories that are
12413: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 12414: my $dirptr = 16384;
1.984 raeburn 12415: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 12416: $currsubfile{$path} = {};
1.1123 raeburn 12417: if (($actionurl eq '/adm/portfolio') ||
12418: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12419: my ($sublistref,$listerror) =
12420: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
12421: if (ref($sublistref) eq 'ARRAY') {
12422: foreach my $line (@{$sublistref}) {
12423: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 12424: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 12425: }
1.984 raeburn 12426: }
1.987 raeburn 12427: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12428: if (opendir(my $dir,$url.'/'.$path)) {
12429: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 12430: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
12431: }
1.1084 raeburn 12432: } elsif (($actionurl eq '/adm/dependencies') ||
12433: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12434: ($args->{'context'} eq 'paste')) ||
12435: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12436: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 12437: my $dir;
12438: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
12439: $dir = $fileloc;
12440: } else {
12441: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12442: }
1.1071 raeburn 12443: if ($dir ne '') {
12444: my ($sublistref,$listerror) =
12445: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
12446: if (ref($sublistref) eq 'ARRAY') {
12447: foreach my $line (@{$sublistref}) {
12448: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
12449: undef,$mtime)=split(/\&/,$line,12);
12450: unless (($testdir&$dirptr) ||
12451: ($file_name =~ /^\.\.?$/)) {
12452: $currsubfile{$path}{$file_name} = [$size,$mtime];
12453: }
12454: }
12455: }
12456: }
1.984 raeburn 12457: }
12458: }
12459: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 12460: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 12461: my $item = $path.'/'.$file;
12462: unless ($mapping{$item} eq $item) {
12463: $pathchanges{$item} = 1;
12464: }
12465: $existing{$item} = 1;
12466: $numexisting ++;
12467: } else {
12468: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 12469: }
12470: }
1.1071 raeburn 12471: if ($actionurl eq '/adm/dependencies') {
12472: foreach my $path (keys(%currsubfile)) {
12473: if (ref($currsubfile{$path}) eq 'HASH') {
12474: foreach my $file (keys(%{$currsubfile{$path}})) {
12475: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 12476: next if (($rem ne '') &&
12477: (($env{"httpref.$rem"."$path/$file"} ne '') ||
12478: (ref($navmap) &&
12479: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
12480: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12481: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 12482: $unused{$path.'/'.$file} = 1;
12483: }
12484: }
12485: }
12486: }
12487: }
1.984 raeburn 12488: }
1.1249 damieng 12489:
12490: # fills $currfile, hash file name -> 1 or [$size,$mtime]
12491: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 12492: my %currfile;
1.1123 raeburn 12493: if (($actionurl eq '/adm/portfolio') ||
12494: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 12495: my ($dirlistref,$listerror) =
12496: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
12497: if (ref($dirlistref) eq 'ARRAY') {
12498: foreach my $line (@{$dirlistref}) {
12499: my ($file_name,$rest) = split(/\&/,$line,2);
12500: $currfile{$file_name} = 1;
12501: }
1.984 raeburn 12502: }
1.987 raeburn 12503: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 12504: if (opendir(my $dir,$url)) {
1.987 raeburn 12505: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 12506: map {$currfile{$_} = 1;} @dir_list;
12507: }
1.1084 raeburn 12508: } elsif (($actionurl eq '/adm/dependencies') ||
12509: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 12510: ($args->{'context'} eq 'paste')) ||
12511: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 12512: if ($env{'request.course.id'} ne '') {
12513: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
12514: if ($dir ne '') {
12515: my ($dirlistref,$listerror) =
12516: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
12517: if (ref($dirlistref) eq 'ARRAY') {
12518: foreach my $line (@{$dirlistref}) {
12519: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
12520: $size,undef,$mtime)=split(/\&/,$line,12);
12521: unless (($testdir&$dirptr) ||
12522: ($file_name =~ /^\.\.?$/)) {
12523: $currfile{$file_name} = [$size,$mtime];
12524: }
12525: }
12526: }
12527: }
12528: }
1.984 raeburn 12529: }
1.1249 damieng 12530: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
12531: # are not in subdirectories, using $currfile
1.984 raeburn 12532: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 12533: if (exists($currfile{$file})) {
1.987 raeburn 12534: unless ($mapping{$file} eq $file) {
12535: $pathchanges{$file} = 1;
12536: }
12537: $existing{$file} = 1;
12538: $numexisting ++;
12539: } else {
1.984 raeburn 12540: $newfiles{$file} = 1;
12541: }
12542: }
1.1071 raeburn 12543: foreach my $file (keys(%currfile)) {
12544: unless (($file eq $filename) ||
12545: ($file eq $filename.'.bak') ||
12546: ($dependencies{$file})) {
1.1085 raeburn 12547: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 12548: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
12549: next if (($rem ne '') &&
12550: (($env{"httpref.$rem".$file} ne '') ||
12551: (ref($navmap) &&
12552: (($navmap->getResourceByUrl($rem.$file) ne '') ||
12553: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
12554: ($navmap->getResourceByUrl($rem.$1)))))));
12555: }
1.1085 raeburn 12556: }
1.1071 raeburn 12557: $unused{$file} = 1;
12558: }
12559: }
1.1249 damieng 12560:
12561: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 12562: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
12563: ($args->{'context'} eq 'paste')) {
12564: $counter = scalar(keys(%existing));
12565: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 12566: return ($output,$counter,$numpathchg,\%existing);
12567: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
12568: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
12569: $counter = scalar(keys(%existing));
12570: $numpathchg = scalar(keys(%pathchanges));
12571: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 12572: }
1.1249 damieng 12573:
12574: # returns HTML otherwise, with dependency results and to ask for more uploads
12575:
12576: # $upload_output: missing dependencies (with upload form)
12577: # $modify_output: uploaded dependencies (in use)
12578: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 12579: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 12580: if ($actionurl eq '/adm/dependencies') {
12581: next if ($embed_file =~ m{^\w+://});
12582: }
1.660 raeburn 12583: $upload_output .= &start_data_table_row().
1.1123 raeburn 12584: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 12585: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 12586: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 12587: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
12588: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 12589: }
1.1123 raeburn 12590: $upload_output .= '</td>';
1.1071 raeburn 12591: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 12592: $upload_output.='<td align="right">'.
12593: '<span class="LC_info LC_fontsize_medium">'.
12594: &mt("URL points to web address").'</span>';
1.987 raeburn 12595: $numremref++;
1.660 raeburn 12596: } elsif ($args->{'error_on_invalid_names'}
12597: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 12598: $upload_output.='<td align="right"><span class="LC_warning">'.
12599: &mt('Invalid characters').'</span>';
1.987 raeburn 12600: $numinvalid++;
1.660 raeburn 12601: } else {
1.1123 raeburn 12602: $upload_output .= '<td>'.
12603: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 12604: $embed_file,\%mapping,
1.1071 raeburn 12605: $allfiles,$codebase,'upload');
12606: $counter ++;
12607: $numnew ++;
1.987 raeburn 12608: }
12609: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
12610: }
12611: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 12612: if ($actionurl eq '/adm/dependencies') {
12613: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
12614: $modify_output .= &start_data_table_row().
12615: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
12616: '<img src="'.&icon($embed_file).'" border="0" />'.
12617: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
12618: '<td>'.$size.'</td>'.
12619: '<td>'.$mtime.'</td>'.
12620: '<td><label><input type="checkbox" name="mod_upload_dep" '.
12621: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
12622: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
12623: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
12624: &embedded_file_element('upload_embedded',$counter,
12625: $embed_file,\%mapping,
12626: $allfiles,$codebase,'modify').
12627: '</div></td>'.
12628: &end_data_table_row()."\n";
12629: $counter ++;
12630: } else {
12631: $upload_output .= &start_data_table_row().
1.1123 raeburn 12632: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
12633: '<span class="LC_filename">'.$embed_file.'</span></td>'.
12634: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 12635: &Apache::loncommon::end_data_table_row()."\n";
12636: }
12637: }
12638: my $delidx = $counter;
12639: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
12640: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
12641: $delete_output .= &start_data_table_row().
12642: '<td><img src="'.&icon($oldfile).'" />'.
12643: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
12644: '<td>'.$size.'</td>'.
12645: '<td>'.$mtime.'</td>'.
12646: '<td><label><input type="checkbox" name="del_upload_dep" '.
12647: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
12648: &embedded_file_element('upload_embedded',$delidx,
12649: $oldfile,\%mapping,$allfiles,
12650: $codebase,'delete').'</td>'.
12651: &end_data_table_row()."\n";
12652: $numunused ++;
12653: $delidx ++;
1.987 raeburn 12654: }
12655: if ($upload_output) {
12656: $upload_output = &start_data_table().
12657: $upload_output.
12658: &end_data_table()."\n";
12659: }
1.1071 raeburn 12660: if ($modify_output) {
12661: $modify_output = &start_data_table().
12662: &start_data_table_header_row().
12663: '<th>'.&mt('File').'</th>'.
12664: '<th>'.&mt('Size (KB)').'</th>'.
12665: '<th>'.&mt('Modified').'</th>'.
12666: '<th>'.&mt('Upload replacement?').'</th>'.
12667: &end_data_table_header_row().
12668: $modify_output.
12669: &end_data_table()."\n";
12670: }
12671: if ($delete_output) {
12672: $delete_output = &start_data_table().
12673: &start_data_table_header_row().
12674: '<th>'.&mt('File').'</th>'.
12675: '<th>'.&mt('Size (KB)').'</th>'.
12676: '<th>'.&mt('Modified').'</th>'.
12677: '<th>'.&mt('Delete?').'</th>'.
12678: &end_data_table_header_row().
12679: $delete_output.
12680: &end_data_table()."\n";
12681: }
1.987 raeburn 12682: my $applies = 0;
12683: if ($numremref) {
12684: $applies ++;
12685: }
12686: if ($numinvalid) {
12687: $applies ++;
12688: }
12689: if ($numexisting) {
12690: $applies ++;
12691: }
1.1071 raeburn 12692: if ($counter || $numunused) {
1.987 raeburn 12693: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12694: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12695: $state.'<h3>'.$heading.'</h3>';
12696: if ($actionurl eq '/adm/dependencies') {
12697: if ($numnew) {
12698: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12699: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12700: $upload_output.'<br />'."\n";
12701: }
12702: if ($numexisting) {
12703: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12704: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12705: $modify_output.'<br />'."\n";
12706: $buttontext = &mt('Save changes');
12707: }
12708: if ($numunused) {
12709: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12710: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12711: $delete_output.'<br />'."\n";
12712: $buttontext = &mt('Save changes');
12713: }
12714: } else {
12715: $output .= $upload_output.'<br />'."\n";
12716: }
12717: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12718: $counter.'" />'."\n";
12719: if ($actionurl eq '/adm/dependencies') {
12720: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12721: $numnew.'" />'."\n";
12722: } elsif ($actionurl eq '') {
1.987 raeburn 12723: $output .= '<input type="hidden" name="phase" value="three" />';
12724: }
12725: } elsif ($applies) {
12726: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12727: if ($applies > 1) {
12728: $output .=
1.1123 raeburn 12729: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12730: if ($numremref) {
12731: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12732: }
12733: if ($numinvalid) {
12734: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12735: }
12736: if ($numexisting) {
12737: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12738: }
12739: $output .= '</ul><br />';
12740: } elsif ($numremref) {
12741: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12742: } elsif ($numinvalid) {
12743: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12744: } elsif ($numexisting) {
12745: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12746: }
12747: $output .= $upload_output.'<br />';
12748: }
12749: my ($pathchange_output,$chgcount);
1.1071 raeburn 12750: $chgcount = $counter;
1.987 raeburn 12751: if (keys(%pathchanges) > 0) {
12752: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12753: if ($counter) {
1.987 raeburn 12754: $output .= &embedded_file_element('pathchange',$chgcount,
12755: $embed_file,\%mapping,
1.1071 raeburn 12756: $allfiles,$codebase,'change');
1.987 raeburn 12757: } else {
12758: $pathchange_output .=
12759: &start_data_table_row().
12760: '<td><input type ="checkbox" name="namechange" value="'.
12761: $chgcount.'" checked="checked" /></td>'.
12762: '<td>'.$mapping{$embed_file}.'</td>'.
12763: '<td>'.$embed_file.
12764: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12765: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12766: '</td>'.&end_data_table_row();
1.660 raeburn 12767: }
1.987 raeburn 12768: $numpathchg ++;
12769: $chgcount ++;
1.660 raeburn 12770: }
12771: }
1.1127 raeburn 12772: if (($counter) || ($numunused)) {
1.987 raeburn 12773: if ($numpathchg) {
12774: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12775: $numpathchg.'" />'."\n";
12776: }
12777: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12778: ($actionurl eq '/adm/imsimport')) {
12779: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12780: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12781: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12782: } elsif ($actionurl eq '/adm/dependencies') {
12783: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12784: }
1.1123 raeburn 12785: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12786: } elsif ($numpathchg) {
12787: my %pathchange = ();
12788: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12789: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12790: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 12791: }
1.987 raeburn 12792: }
1.1071 raeburn 12793: return ($output,$counter,$numpathchg);
1.987 raeburn 12794: }
12795:
1.1147 raeburn 12796: =pod
12797:
12798: =item * clean_path($name)
12799:
12800: Performs clean-up of directories, subdirectories and filename in an
12801: embedded object, referenced in an HTML file which is being uploaded
12802: to a course or portfolio, where
12803: "Upload embedded images/multimedia files if HTML file" checkbox was
12804: checked.
12805:
12806: Clean-up is similar to replacements in lonnet::clean_filename()
12807: except each / between sub-directory and next level is preserved.
12808:
12809: =cut
12810:
12811: sub clean_path {
12812: my ($embed_file) = @_;
12813: $embed_file =~s{^/+}{};
12814: my @contents;
12815: if ($embed_file =~ m{/}) {
12816: @contents = split(/\//,$embed_file);
12817: } else {
12818: @contents = ($embed_file);
12819: }
12820: my $lastidx = scalar(@contents)-1;
12821: for (my $i=0; $i<=$lastidx; $i++) {
12822: $contents[$i]=~s{\\}{/}g;
12823: $contents[$i]=~s/\s+/\_/g;
12824: $contents[$i]=~s{[^/\w\.\-]}{}g;
12825: if ($i == $lastidx) {
12826: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12827: }
12828: }
12829: if ($lastidx > 0) {
12830: return join('/',@contents);
12831: } else {
12832: return $contents[0];
12833: }
12834: }
12835:
1.987 raeburn 12836: sub embedded_file_element {
1.1071 raeburn 12837: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12838: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12839: (ref($codebase) eq 'HASH'));
12840: my $output;
1.1071 raeburn 12841: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12842: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12843: }
12844: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12845: &escape($embed_file).'" />';
12846: unless (($context eq 'upload_embedded') &&
12847: ($mapping->{$embed_file} eq $embed_file)) {
12848: $output .='
12849: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12850: }
12851: my $attrib;
12852: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12853: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12854: }
12855: $output .=
12856: "\n\t\t".
12857: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12858: $attrib.'" />';
12859: if (exists($codebase->{$mapping->{$embed_file}})) {
12860: $output .=
12861: "\n\t\t".
12862: '<input name="codebase_'.$num.'" type="hidden" value="'.
12863: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12864: }
1.987 raeburn 12865: return $output;
1.660 raeburn 12866: }
12867:
1.1071 raeburn 12868: sub get_dependency_details {
12869: my ($currfile,$currsubfile,$embed_file) = @_;
12870: my ($size,$mtime,$showsize,$showmtime);
12871: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12872: if ($embed_file =~ m{/}) {
12873: my ($path,$fname) = split(/\//,$embed_file);
12874: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12875: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12876: }
12877: } else {
12878: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12879: ($size,$mtime) = @{$currfile->{$embed_file}};
12880: }
12881: }
12882: $showsize = $size/1024.0;
12883: $showsize = sprintf("%.1f",$showsize);
12884: if ($mtime > 0) {
12885: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12886: }
12887: }
12888: return ($showsize,$showmtime);
12889: }
12890:
12891: sub ask_embedded_js {
12892: return <<"END";
12893: <script type="text/javascript"">
12894: // <![CDATA[
12895: function toggleBrowse(counter) {
12896: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12897: var fileid = document.getElementById('embedded_item_'+counter);
12898: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12899: if (chkboxid.checked == true) {
12900: uploaddivid.style.display='block';
12901: } else {
12902: uploaddivid.style.display='none';
12903: fileid.value = '';
12904: }
12905: }
12906: // ]]>
12907: </script>
12908:
12909: END
12910: }
12911:
1.661 raeburn 12912: sub upload_embedded {
12913: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12914: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12915: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12916: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12917: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12918: my $orig_uploaded_filename =
12919: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12920: foreach my $type ('orig','ref','attrib','codebase') {
12921: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12922: $env{'form.embedded_'.$type.'_'.$i} =
12923: &unescape($env{'form.embedded_'.$type.'_'.$i});
12924: }
12925: }
1.661 raeburn 12926: my ($path,$fname) =
12927: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12928: # no path, whole string is fname
12929: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12930: $fname = &Apache::lonnet::clean_filename($fname);
12931: # See if there is anything left
12932: next if ($fname eq '');
12933:
12934: # Check if file already exists as a file or directory.
12935: my ($state,$msg);
12936: if ($context eq 'portfolio') {
12937: my $port_path = $dirpath;
12938: if ($group ne '') {
12939: $port_path = "groups/$group/$port_path";
12940: }
1.987 raeburn 12941: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12942: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12943: $dir_root,$port_path,$disk_quota,
12944: $current_disk_usage,$uname,$udom);
12945: if ($state eq 'will_exceed_quota'
1.984 raeburn 12946: || $state eq 'file_locked') {
1.661 raeburn 12947: $output .= $msg;
12948: next;
12949: }
12950: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12951: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12952: if ($state eq 'exists') {
12953: $output .= $msg;
12954: next;
12955: }
12956: }
12957: # Check if extension is valid
12958: if (($fname =~ /\.(\w+)$/) &&
12959: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12960: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12961: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12962: next;
12963: } elsif (($fname =~ /\.(\w+)$/) &&
12964: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12965: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12966: next;
12967: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12968: $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 12969: next;
12970: }
12971: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12972: my $subdir = $path;
12973: $subdir =~ s{/+$}{};
1.661 raeburn 12974: if ($context eq 'portfolio') {
1.984 raeburn 12975: my $result;
12976: if ($state eq 'existingfile') {
12977: $result=
12978: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12979: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12980: } else {
1.984 raeburn 12981: $result=
12982: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12983: $dirpath.
1.1123 raeburn 12984: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12985: if ($result !~ m|^/uploaded/|) {
12986: $output .= '<span class="LC_error">'
12987: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12988: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12989: .'</span><br />';
12990: next;
12991: } else {
1.987 raeburn 12992: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12993: $path.$fname.'</span>').'<br />';
1.984 raeburn 12994: }
1.661 raeburn 12995: }
1.1123 raeburn 12996: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12997: my $extendedsubdir = $dirpath.'/'.$subdir;
12998: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12999: my $result =
1.1126 raeburn 13000: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 13001: if ($result !~ m|^/uploaded/|) {
13002: $output .= '<span class="LC_error">'
13003: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
13004: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
13005: .'</span><br />';
13006: next;
13007: } else {
13008: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13009: $path.$fname.'</span>').'<br />';
1.1125 raeburn 13010: if ($context eq 'syllabus') {
13011: &Apache::lonnet::make_public_indefinitely($result);
13012: }
1.987 raeburn 13013: }
1.661 raeburn 13014: } else {
13015: # Save the file
13016: my $target = $env{'form.embedded_item_'.$i};
13017: my $fullpath = $dir_root.$dirpath.'/'.$path;
13018: my $dest = $fullpath.$fname;
13019: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 13020: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 13021: my $count;
13022: my $filepath = $dir_root;
1.1027 raeburn 13023: foreach my $subdir (@parts) {
13024: $filepath .= "/$subdir";
13025: if (!-e $filepath) {
1.661 raeburn 13026: mkdir($filepath,0770);
13027: }
13028: }
13029: my $fh;
13030: if (!open($fh,'>'.$dest)) {
13031: &Apache::lonnet::logthis('Failed to create '.$dest);
13032: $output .= '<span class="LC_error">'.
1.1071 raeburn 13033: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
13034: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 13035: '</span><br />';
13036: } else {
13037: if (!print $fh $env{'form.embedded_item_'.$i}) {
13038: &Apache::lonnet::logthis('Failed to write to '.$dest);
13039: $output .= '<span class="LC_error">'.
1.1071 raeburn 13040: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
13041: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 13042: '</span><br />';
13043: } else {
1.987 raeburn 13044: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
13045: $url.'</span>').'<br />';
13046: unless ($context eq 'testbank') {
13047: $footer .= &mt('View embedded file: [_1]',
13048: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
13049: }
13050: }
13051: close($fh);
13052: }
13053: }
13054: if ($env{'form.embedded_ref_'.$i}) {
13055: $pathchange{$i} = 1;
13056: }
13057: }
13058: if ($output) {
13059: $output = '<p>'.$output.'</p>';
13060: }
13061: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
13062: $returnflag = 'ok';
1.1071 raeburn 13063: my $numpathchgs = scalar(keys(%pathchange));
13064: if ($numpathchgs > 0) {
1.987 raeburn 13065: if ($context eq 'portfolio') {
13066: $output .= '<p>'.&mt('or').'</p>';
13067: } elsif ($context eq 'testbank') {
1.1071 raeburn 13068: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
13069: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 13070: $returnflag = 'modify_orightml';
13071: }
13072: }
1.1071 raeburn 13073: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 13074: }
13075:
13076: sub modify_html_form {
13077: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
13078: my $end = 0;
13079: my $modifyform;
13080: if ($context eq 'upload_embedded') {
13081: return unless (ref($pathchange) eq 'HASH');
13082: if ($env{'form.number_embedded_items'}) {
13083: $end += $env{'form.number_embedded_items'};
13084: }
13085: if ($env{'form.number_pathchange_items'}) {
13086: $end += $env{'form.number_pathchange_items'};
13087: }
13088: if ($end) {
13089: for (my $i=0; $i<$end; $i++) {
13090: if ($i < $env{'form.number_embedded_items'}) {
13091: next unless($pathchange->{$i});
13092: }
13093: $modifyform .=
13094: &start_data_table_row().
13095: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
13096: 'checked="checked" /></td>'.
13097: '<td>'.$env{'form.embedded_ref_'.$i}.
13098: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
13099: &escape($env{'form.embedded_ref_'.$i}).'" />'.
13100: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
13101: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
13102: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
13103: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
13104: '<td>'.$env{'form.embedded_orig_'.$i}.
13105: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
13106: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
13107: &end_data_table_row();
1.1071 raeburn 13108: }
1.987 raeburn 13109: }
13110: } else {
13111: $modifyform = $pathchgtable;
13112: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
13113: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
13114: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
13115: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
13116: }
13117: }
13118: if ($modifyform) {
1.1071 raeburn 13119: if ($actionurl eq '/adm/dependencies') {
13120: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
13121: }
1.987 raeburn 13122: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
13123: '<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".
13124: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
13125: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
13126: '</ol></p>'."\n".'<p>'.
13127: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
13128: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
13129: &start_data_table()."\n".
13130: &start_data_table_header_row().
13131: '<th>'.&mt('Change?').'</th>'.
13132: '<th>'.&mt('Current reference').'</th>'.
13133: '<th>'.&mt('Required reference').'</th>'.
13134: &end_data_table_header_row()."\n".
13135: $modifyform.
13136: &end_data_table().'<br />'."\n".$hiddenstate.
13137: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
13138: '</form>'."\n";
13139: }
13140: return;
13141: }
13142:
13143: sub modify_html_refs {
1.1123 raeburn 13144: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 13145: my $container;
13146: if ($context eq 'portfolio') {
13147: $container = $env{'form.container'};
13148: } elsif ($context eq 'coursedoc') {
13149: $container = $env{'form.primaryurl'};
1.1071 raeburn 13150: } elsif ($context eq 'manage_dependencies') {
13151: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
13152: $container = "/$container";
1.1123 raeburn 13153: } elsif ($context eq 'syllabus') {
13154: $container = $url;
1.987 raeburn 13155: } else {
1.1027 raeburn 13156: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 13157: }
13158: my (%allfiles,%codebase,$output,$content);
13159: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 13160: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 13161: if (wantarray) {
13162: return ('',0,0);
13163: } else {
13164: return;
13165: }
13166: }
13167: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13168: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 13169: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
13170: if (wantarray) {
13171: return ('',0,0);
13172: } else {
13173: return;
13174: }
13175: }
1.987 raeburn 13176: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 13177: if ($content eq '-1') {
13178: if (wantarray) {
13179: return ('',0,0);
13180: } else {
13181: return;
13182: }
13183: }
1.987 raeburn 13184: } else {
1.1071 raeburn 13185: unless ($container =~ /^\Q$dir_root\E/) {
13186: if (wantarray) {
13187: return ('',0,0);
13188: } else {
13189: return;
13190: }
13191: }
1.1317 raeburn 13192: if (open(my $fh,'<',$container)) {
1.987 raeburn 13193: $content = join('', <$fh>);
13194: close($fh);
13195: } else {
1.1071 raeburn 13196: if (wantarray) {
13197: return ('',0,0);
13198: } else {
13199: return;
13200: }
1.987 raeburn 13201: }
13202: }
13203: my ($count,$codebasecount) = (0,0);
13204: my $mm = new File::MMagic;
13205: my $mime_type = $mm->checktype_contents($content);
13206: if ($mime_type eq 'text/html') {
13207: my $parse_result =
13208: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
13209: \%codebase,\$content);
13210: if ($parse_result eq 'ok') {
13211: foreach my $i (@changes) {
13212: my $orig = &unescape($env{'form.embedded_orig_'.$i});
13213: my $ref = &unescape($env{'form.embedded_ref_'.$i});
13214: if ($allfiles{$ref}) {
13215: my $newname = $orig;
13216: my ($attrib_regexp,$codebase);
1.1006 raeburn 13217: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 13218: if ($attrib_regexp =~ /:/) {
13219: $attrib_regexp =~ s/\:/|/g;
13220: }
13221: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13222: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13223: $count += $numchg;
1.1123 raeburn 13224: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 13225: delete($allfiles{$ref});
1.987 raeburn 13226: }
13227: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 13228: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 13229: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
13230: $codebasecount ++;
13231: }
13232: }
13233: }
1.1123 raeburn 13234: my $skiprewrites;
1.987 raeburn 13235: if ($count || $codebasecount) {
13236: my $saveresult;
1.1071 raeburn 13237: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 13238: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 13239: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13240: if ($url eq $container) {
13241: my ($fname) = ($container =~ m{/([^/]+)$});
13242: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13243: $count,'<span class="LC_filename">'.
1.1071 raeburn 13244: $fname.'</span>').'</p>';
1.987 raeburn 13245: } else {
13246: $output = '<p class="LC_error">'.
13247: &mt('Error: update failed for: [_1].',
13248: '<span class="LC_filename">'.
13249: $container.'</span>').'</p>';
13250: }
1.1123 raeburn 13251: if ($context eq 'syllabus') {
13252: unless ($saveresult eq 'ok') {
13253: $skiprewrites = 1;
13254: }
13255: }
1.987 raeburn 13256: } else {
1.1317 raeburn 13257: if (open(my $fh,'>',$container)) {
1.987 raeburn 13258: print $fh $content;
13259: close($fh);
13260: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
13261: $count,'<span class="LC_filename">'.
13262: $container.'</span>').'</p>';
1.661 raeburn 13263: } else {
1.987 raeburn 13264: $output = '<p class="LC_error">'.
13265: &mt('Error: could not update [_1].',
13266: '<span class="LC_filename">'.
13267: $container.'</span>').'</p>';
1.661 raeburn 13268: }
13269: }
13270: }
1.1123 raeburn 13271: if (($context eq 'syllabus') && (!$skiprewrites)) {
13272: my ($actionurl,$state);
13273: $actionurl = "/public/$udom/$uname/syllabus";
13274: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
13275: &ask_for_embedded_content($actionurl,$state,\%allfiles,
13276: \%codebase,
13277: {'context' => 'rewrites',
13278: 'ignore_remote_references' => 1,});
13279: if (ref($mapping) eq 'HASH') {
13280: my $rewrites = 0;
13281: foreach my $key (keys(%{$mapping})) {
13282: next if ($key =~ m{^https?://});
13283: my $ref = $mapping->{$key};
13284: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
13285: my $attrib;
13286: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
13287: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
13288: }
13289: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
13290: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
13291: $rewrites += $numchg;
13292: }
13293: }
13294: if ($rewrites) {
13295: my $saveresult;
13296: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
13297: if ($url eq $container) {
13298: my ($fname) = ($container =~ m{/([^/]+)$});
13299: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
13300: $count,'<span class="LC_filename">'.
13301: $fname.'</span>').'</p>';
13302: } else {
13303: $output .= '<p class="LC_error">'.
13304: &mt('Error: could not update links in [_1].',
13305: '<span class="LC_filename">'.
13306: $container.'</span>').'</p>';
13307:
13308: }
13309: }
13310: }
13311: }
1.987 raeburn 13312: } else {
13313: &logthis('Failed to parse '.$container.
13314: ' to modify references: '.$parse_result);
1.661 raeburn 13315: }
13316: }
1.1071 raeburn 13317: if (wantarray) {
13318: return ($output,$count,$codebasecount);
13319: } else {
13320: return $output;
13321: }
1.661 raeburn 13322: }
13323:
13324: sub check_for_existing {
13325: my ($path,$fname,$element) = @_;
13326: my ($state,$msg);
13327: if (-d $path.'/'.$fname) {
13328: $state = 'exists';
13329: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13330: } elsif (-e $path.'/'.$fname) {
13331: $state = 'exists';
13332: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
13333: }
13334: if ($state eq 'exists') {
13335: $msg = '<span class="LC_error">'.$msg.'</span><br />';
13336: }
13337: return ($state,$msg);
13338: }
13339:
13340: sub check_for_upload {
13341: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
13342: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 13343: my $filesize = length($env{'form.'.$element});
13344: if (!$filesize) {
13345: my $msg = '<span class="LC_error">'.
13346: &mt('Unable to upload [_1]. (size = [_2] bytes)',
13347: '<span class="LC_filename">'.$fname.'</span>',
13348: $filesize).'<br />'.
1.1007 raeburn 13349: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 13350: '</span>';
13351: return ('zero_bytes',$msg);
13352: }
13353: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 13354: my $getpropath = 1;
1.1021 raeburn 13355: my ($dirlistref,$listerror) =
13356: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 13357: my $found_file = 0;
13358: my $locked_file = 0;
1.991 raeburn 13359: my @lockers;
13360: my $navmap;
13361: if ($env{'request.course.id'}) {
13362: $navmap = Apache::lonnavmaps::navmap->new();
13363: }
1.1021 raeburn 13364: if (ref($dirlistref) eq 'ARRAY') {
13365: foreach my $line (@{$dirlistref}) {
13366: my ($file_name,$rest)=split(/\&/,$line,2);
13367: if ($file_name eq $fname){
13368: $file_name = $path.$file_name;
13369: if ($group ne '') {
13370: $file_name = $group.$file_name;
13371: }
13372: $found_file = 1;
13373: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
13374: foreach my $lock (@lockers) {
13375: if (ref($lock) eq 'ARRAY') {
13376: my ($symb,$crsid) = @{$lock};
13377: if ($crsid eq $env{'request.course.id'}) {
13378: if (ref($navmap)) {
13379: my $res = $navmap->getBySymb($symb);
13380: foreach my $part (@{$res->parts()}) {
13381: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
13382: unless (($slot_status == $res->RESERVED) ||
13383: ($slot_status == $res->RESERVED_LOCATION)) {
13384: $locked_file = 1;
13385: }
1.991 raeburn 13386: }
1.1021 raeburn 13387: } else {
13388: $locked_file = 1;
1.991 raeburn 13389: }
13390: } else {
13391: $locked_file = 1;
13392: }
13393: }
1.1021 raeburn 13394: }
13395: } else {
13396: my @info = split(/\&/,$rest);
13397: my $currsize = $info[6]/1000;
13398: if ($currsize < $filesize) {
13399: my $extra = $filesize - $currsize;
13400: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 13401: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 13402: &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 13403: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
13404: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
13405: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 13406: return ('will_exceed_quota',$msg);
13407: }
1.984 raeburn 13408: }
13409: }
1.661 raeburn 13410: }
13411: }
13412: }
13413: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 13414: my $msg = '<p class="LC_warning">'.
13415: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 13416: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 13417: return ('will_exceed_quota',$msg);
13418: } elsif ($found_file) {
13419: if ($locked_file) {
1.1179 bisitz 13420: my $msg = '<p class="LC_warning">';
1.661 raeburn 13421: $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 13422: $msg .= '</p>';
1.661 raeburn 13423: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
13424: return ('file_locked',$msg);
13425: } else {
1.1179 bisitz 13426: my $msg = '<p class="LC_error">';
1.984 raeburn 13427: $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 13428: $msg .= '</p>';
1.984 raeburn 13429: return ('existingfile',$msg);
1.661 raeburn 13430: }
13431: }
13432: }
13433:
1.987 raeburn 13434: sub check_for_traversal {
13435: my ($path,$url,$toplevel) = @_;
13436: my @parts=split(/\//,$path);
13437: my $cleanpath;
13438: my $fullpath = $url;
13439: for (my $i=0;$i<@parts;$i++) {
13440: next if ($parts[$i] eq '.');
13441: if ($parts[$i] eq '..') {
13442: $fullpath =~ s{([^/]+/)$}{};
13443: } else {
13444: $fullpath .= $parts[$i].'/';
13445: }
13446: }
13447: if ($fullpath =~ /^\Q$url\E(.*)$/) {
13448: $cleanpath = $1;
13449: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
13450: my $curr_toprel = $1;
13451: my @parts = split(/\//,$curr_toprel);
13452: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
13453: my @urlparts = split(/\//,$url_toprel);
13454: my $doubledots;
13455: my $startdiff = -1;
13456: for (my $i=0; $i<@urlparts; $i++) {
13457: if ($startdiff == -1) {
13458: unless ($urlparts[$i] eq $parts[$i]) {
13459: $startdiff = $i;
13460: $doubledots .= '../';
13461: }
13462: } else {
13463: $doubledots .= '../';
13464: }
13465: }
13466: if ($startdiff > -1) {
13467: $cleanpath = $doubledots;
13468: for (my $i=$startdiff; $i<@parts; $i++) {
13469: $cleanpath .= $parts[$i].'/';
13470: }
13471: }
13472: }
13473: $cleanpath =~ s{(/)$}{};
13474: return $cleanpath;
13475: }
1.31 albertel 13476:
1.1053 raeburn 13477: sub is_archive_file {
13478: my ($mimetype) = @_;
13479: if (($mimetype eq 'application/octet-stream') ||
13480: ($mimetype eq 'application/x-stuffit') ||
13481: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
13482: return 1;
13483: }
13484: return;
13485: }
13486:
13487: sub decompress_form {
1.1065 raeburn 13488: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 13489: my %lt = &Apache::lonlocal::texthash (
13490: this => 'This file is an archive file.',
1.1067 raeburn 13491: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 13492: itsc => 'Its contents are as follows:',
1.1053 raeburn 13493: youm => 'You may wish to extract its contents.',
13494: extr => 'Extract contents',
1.1067 raeburn 13495: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
13496: proa => 'Process automatically?',
1.1053 raeburn 13497: yes => 'Yes',
13498: no => 'No',
1.1067 raeburn 13499: fold => 'Title for folder containing movie',
13500: movi => 'Title for page containing embedded movie',
1.1053 raeburn 13501: );
1.1065 raeburn 13502: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 13503: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 13504: my $info = &list_archive_contents($fileloc,\@paths);
13505: if (@paths) {
13506: foreach my $path (@paths) {
13507: $path =~ s{^/}{};
1.1067 raeburn 13508: if ($path =~ m{^([^/]+)/$}) {
13509: $topdir = $1;
13510: }
1.1065 raeburn 13511: if ($path =~ m{^([^/]+)/}) {
13512: $toplevel{$1} = $path;
13513: } else {
13514: $toplevel{$path} = $path;
13515: }
13516: }
13517: }
1.1067 raeburn 13518: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 13519: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 13520: "$topdir/media/",
13521: "$topdir/media/$topdir.mp4",
13522: "$topdir/media/FirstFrame.png",
13523: "$topdir/media/player.swf",
13524: "$topdir/media/swfobject.js",
13525: "$topdir/media/expressInstall.swf");
1.1197 raeburn 13526: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 13527: "$topdir/$topdir.mp4",
13528: "$topdir/$topdir\_config.xml",
13529: "$topdir/$topdir\_controller.swf",
13530: "$topdir/$topdir\_embed.css",
13531: "$topdir/$topdir\_First_Frame.png",
13532: "$topdir/$topdir\_player.html",
13533: "$topdir/$topdir\_Thumbnails.png",
13534: "$topdir/playerProductInstall.swf",
13535: "$topdir/scripts/",
13536: "$topdir/scripts/config_xml.js",
13537: "$topdir/scripts/handlebars.js",
13538: "$topdir/scripts/jquery-1.7.1.min.js",
13539: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
13540: "$topdir/scripts/modernizr.js",
13541: "$topdir/scripts/player-min.js",
13542: "$topdir/scripts/swfobject.js",
13543: "$topdir/skins/",
13544: "$topdir/skins/configuration_express.xml",
13545: "$topdir/skins/express_show/",
13546: "$topdir/skins/express_show/player-min.css",
13547: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 13548: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
13549: "$topdir/$topdir.mp4",
13550: "$topdir/$topdir\_config.xml",
13551: "$topdir/$topdir\_controller.swf",
13552: "$topdir/$topdir\_embed.css",
13553: "$topdir/$topdir\_First_Frame.png",
13554: "$topdir/$topdir\_player.html",
13555: "$topdir/$topdir\_Thumbnails.png",
13556: "$topdir/playerProductInstall.swf",
13557: "$topdir/scripts/",
13558: "$topdir/scripts/config_xml.js",
13559: "$topdir/scripts/techsmith-smart-player.min.js",
13560: "$topdir/skins/",
13561: "$topdir/skins/configuration_express.xml",
13562: "$topdir/skins/express_show/",
13563: "$topdir/skins/express_show/spritesheet.min.css",
13564: "$topdir/skins/express_show/spritesheet.png",
13565: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 13566: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 13567: if (@diffs == 0) {
1.1164 raeburn 13568: $is_camtasia = 6;
13569: } else {
1.1197 raeburn 13570: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 13571: if (@diffs == 0) {
13572: $is_camtasia = 8;
1.1197 raeburn 13573: } else {
13574: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
13575: if (@diffs == 0) {
13576: $is_camtasia = 8;
13577: }
1.1164 raeburn 13578: }
1.1067 raeburn 13579: }
13580: }
13581: my $output;
13582: if ($is_camtasia) {
13583: $output = <<"ENDCAM";
13584: <script type="text/javascript" language="Javascript">
13585: // <![CDATA[
13586:
13587: function camtasiaToggle() {
13588: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
13589: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 13590: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 13591: document.getElementById('camtasia_titles').style.display='block';
13592: } else {
13593: document.getElementById('camtasia_titles').style.display='none';
13594: }
13595: }
13596: }
13597: return;
13598: }
13599:
13600: // ]]>
13601: </script>
13602: <p>$lt{'camt'}</p>
13603: ENDCAM
1.1065 raeburn 13604: } else {
1.1067 raeburn 13605: $output = '<p>'.$lt{'this'};
13606: if ($info eq '') {
13607: $output .= ' '.$lt{'youm'}.'</p>'."\n";
13608: } else {
13609: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
13610: '<div><pre>'.$info.'</pre></div>';
13611: }
1.1065 raeburn 13612: }
1.1067 raeburn 13613: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 13614: my $duplicates;
13615: my $num = 0;
13616: if (ref($dirlist) eq 'ARRAY') {
13617: foreach my $item (@{$dirlist}) {
13618: if (ref($item) eq 'ARRAY') {
13619: if (exists($toplevel{$item->[0]})) {
13620: $duplicates .=
13621: &start_data_table_row().
13622: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
13623: 'value="0" checked="checked" />'.&mt('No').'</label>'.
13624: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
13625: 'value="1" />'.&mt('Yes').'</label>'.
13626: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
13627: '<td>'.$item->[0].'</td>';
13628: if ($item->[2]) {
13629: $duplicates .= '<td>'.&mt('Directory').'</td>';
13630: } else {
13631: $duplicates .= '<td>'.&mt('File').'</td>';
13632: }
13633: $duplicates .= '<td>'.$item->[3].'</td>'.
13634: '<td>'.
13635: &Apache::lonlocal::locallocaltime($item->[4]).
13636: '</td>'.
13637: &end_data_table_row();
13638: $num ++;
13639: }
13640: }
13641: }
13642: }
13643: my $itemcount;
13644: if (@paths > 0) {
13645: $itemcount = scalar(@paths);
13646: } else {
13647: $itemcount = 1;
13648: }
1.1067 raeburn 13649: if ($is_camtasia) {
13650: $output .= $lt{'auto'}.'<br />'.
13651: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 13652: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 13653: $lt{'yes'}.'</label> <label>'.
13654: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
13655: $lt{'no'}.'</label></span><br />'.
13656: '<div id="camtasia_titles" style="display:block">'.
13657: &Apache::lonhtmlcommon::start_pick_box().
13658: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
13659: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
13660: &Apache::lonhtmlcommon::row_closure().
13661: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
13662: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
13663: &Apache::lonhtmlcommon::row_closure(1).
13664: &Apache::lonhtmlcommon::end_pick_box().
13665: '</div>';
13666: }
1.1065 raeburn 13667: $output .=
13668: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 13669: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
13670: "\n";
1.1065 raeburn 13671: if ($duplicates ne '') {
13672: $output .= '<p><span class="LC_warning">'.
13673: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13674: &start_data_table().
13675: &start_data_table_header_row().
13676: '<th>'.&mt('Overwrite?').'</th>'.
13677: '<th>'.&mt('Name').'</th>'.
13678: '<th>'.&mt('Type').'</th>'.
13679: '<th>'.&mt('Size').'</th>'.
13680: '<th>'.&mt('Last modified').'</th>'.
13681: &end_data_table_header_row().
13682: $duplicates.
13683: &end_data_table().
13684: '</p>';
13685: }
1.1067 raeburn 13686: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13687: if (ref($hiddenelements) eq 'HASH') {
13688: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13689: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13690: }
13691: }
13692: $output .= <<"END";
1.1067 raeburn 13693: <br />
1.1053 raeburn 13694: <input type="submit" name="decompress" value="$lt{'extr'}" />
13695: </form>
13696: $noextract
13697: END
13698: return $output;
13699: }
13700:
1.1065 raeburn 13701: sub decompression_utility {
13702: my ($program) = @_;
13703: my @utilities = ('tar','gunzip','bunzip2','unzip');
13704: my $location;
13705: if (grep(/^\Q$program\E$/,@utilities)) {
13706: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13707: '/usr/sbin/') {
13708: if (-x $dir.$program) {
13709: $location = $dir.$program;
13710: last;
13711: }
13712: }
13713: }
13714: return $location;
13715: }
13716:
13717: sub list_archive_contents {
13718: my ($file,$pathsref) = @_;
13719: my (@cmd,$output);
13720: my $needsregexp;
13721: if ($file =~ /\.zip$/) {
13722: @cmd = (&decompression_utility('unzip'),"-l");
13723: $needsregexp = 1;
13724: } elsif (($file =~ m/\.tar\.gz$/) ||
13725: ($file =~ /\.tgz$/)) {
13726: @cmd = (&decompression_utility('tar'),"-ztf");
13727: } elsif ($file =~ /\.tar\.bz2$/) {
13728: @cmd = (&decompression_utility('tar'),"-jtf");
13729: } elsif ($file =~ m|\.tar$|) {
13730: @cmd = (&decompression_utility('tar'),"-tf");
13731: }
13732: if (@cmd) {
13733: undef($!);
13734: undef($@);
13735: if (open(my $fh,"-|", @cmd, $file)) {
13736: while (my $line = <$fh>) {
13737: $output .= $line;
13738: chomp($line);
13739: my $item;
13740: if ($needsregexp) {
13741: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13742: } else {
13743: $item = $line;
13744: }
13745: if ($item ne '') {
13746: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13747: push(@{$pathsref},$item);
13748: }
13749: }
13750: }
13751: close($fh);
13752: }
13753: }
13754: return $output;
13755: }
13756:
1.1053 raeburn 13757: sub decompress_uploaded_file {
13758: my ($file,$dir) = @_;
13759: &Apache::lonnet::appenv({'cgi.file' => $file});
13760: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13761: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13762: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13763: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13764: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13765: my $decompressed = $env{'cgi.decompressed'};
13766: &Apache::lonnet::delenv('cgi.file');
13767: &Apache::lonnet::delenv('cgi.dir');
13768: &Apache::lonnet::delenv('cgi.decompressed');
13769: return ($decompressed,$result);
13770: }
13771:
1.1055 raeburn 13772: sub process_decompression {
13773: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 13774: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13775: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13776: &mt('Unexpected file path.').'</p>'."\n";
13777: }
13778: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13779: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13780: &mt('Unexpected course context.').'</p>'."\n";
13781: }
1.1293 raeburn 13782: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 13783: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13784: &mt('Filename contained unexpected characters.').'</p>'."\n";
13785: }
1.1055 raeburn 13786: my ($dir,$error,$warning,$output);
1.1180 raeburn 13787: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 13788: $error = &mt('Filename not a supported archive file type.').
13789: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13790: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13791: } else {
13792: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13793: if ($docuhome eq 'no_host') {
13794: $error = &mt('Could not determine home server for course.');
13795: } else {
13796: my @ids=&Apache::lonnet::current_machine_ids();
13797: my $currdir = "$dir_root/$destination";
13798: if (grep(/^\Q$docuhome\E$/,@ids)) {
13799: $dir = &LONCAPA::propath($docudom,$docuname).
13800: "$dir_root/$destination";
13801: } else {
13802: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13803: "$dir_root/$docudom/$docuname/$destination";
13804: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13805: $error = &mt('Archive file not found.');
13806: }
13807: }
1.1065 raeburn 13808: my (@to_overwrite,@to_skip);
13809: if ($env{'form.archive_overwrite_total'} > 0) {
13810: my $total = $env{'form.archive_overwrite_total'};
13811: for (my $i=0; $i<$total; $i++) {
13812: if ($env{'form.archive_overwrite_'.$i} == 1) {
13813: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13814: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13815: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13816: }
13817: }
13818: }
13819: my $numskip = scalar(@to_skip);
1.1292 raeburn 13820: my $numoverwrite = scalar(@to_overwrite);
13821: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13822: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13823: } elsif ($dir eq '') {
1.1055 raeburn 13824: $error = &mt('Directory containing archive file unavailable.');
13825: } elsif (!$error) {
1.1065 raeburn 13826: my ($decompressed,$display);
1.1292 raeburn 13827: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13828: my $tempdir = time.'_'.$$.int(rand(10000));
13829: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 13830: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13831: ($decompressed,$display) =
13832: &decompress_uploaded_file($file,"$dir/$tempdir");
13833: foreach my $item (@to_skip) {
13834: if (($item ne '') && ($item !~ /\.\./)) {
13835: if (-f "$dir/$tempdir/$item") {
13836: unlink("$dir/$tempdir/$item");
13837: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 13838: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 13839: }
13840: }
13841: }
13842: foreach my $item (@to_overwrite) {
13843: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13844: if (($item ne '') && ($item !~ /\.\./)) {
13845: if (-f "$dir/$item") {
13846: unlink("$dir/$item");
13847: } elsif (-d "$dir/$item") {
1.1300 raeburn 13848: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 13849: }
13850: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13851: }
1.1065 raeburn 13852: }
13853: }
1.1292 raeburn 13854: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 13855: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 13856: }
1.1065 raeburn 13857: }
13858: } else {
13859: ($decompressed,$display) =
13860: &decompress_uploaded_file($file,$dir);
13861: }
1.1055 raeburn 13862: if ($decompressed eq 'ok') {
1.1065 raeburn 13863: $output = '<p class="LC_info">'.
13864: &mt('Files extracted successfully from archive.').
13865: '</p>'."\n";
1.1055 raeburn 13866: my ($warning,$result,@contents);
13867: my ($newdirlistref,$newlisterror) =
13868: &Apache::lonnet::dirlist($currdir,$docudom,
13869: $docuname,1);
13870: my (%is_dir,%changes,@newitems);
13871: my $dirptr = 16384;
1.1065 raeburn 13872: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13873: foreach my $dir_line (@{$newdirlistref}) {
13874: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 13875: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13876: push(@newitems,$item);
13877: if ($dirptr&$testdir) {
13878: $is_dir{$item} = 1;
13879: }
13880: $changes{$item} = 1;
13881: }
13882: }
13883: }
13884: if (keys(%changes) > 0) {
13885: foreach my $item (sort(@newitems)) {
13886: if ($changes{$item}) {
13887: push(@contents,$item);
13888: }
13889: }
13890: }
13891: if (@contents > 0) {
1.1067 raeburn 13892: my $wantform;
13893: unless ($env{'form.autoextract_camtasia'}) {
13894: $wantform = 1;
13895: }
1.1056 raeburn 13896: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13897: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13898: $currdir,\%is_dir,
13899: \%children,\%parent,
1.1056 raeburn 13900: \@contents,\%dirorder,
13901: \%titles,$wantform);
1.1055 raeburn 13902: if ($datatable ne '') {
13903: $output .= &archive_options_form('decompressed',$datatable,
13904: $count,$hiddenelem);
1.1065 raeburn 13905: my $startcount = 6;
1.1055 raeburn 13906: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13907: \%titles,\%children);
1.1055 raeburn 13908: }
1.1067 raeburn 13909: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13910: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13911: my %displayed;
13912: my $total = 1;
13913: $env{'form.archive_directory'} = [];
13914: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13915: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13916: $path =~ s{/$}{};
13917: my $item;
13918: if ($path ne '') {
13919: $item = "$path/$titles{$i}";
13920: } else {
13921: $item = $titles{$i};
13922: }
13923: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13924: if ($item eq $contents[0]) {
13925: push(@{$env{'form.archive_directory'}},$i);
13926: $env{'form.archive_'.$i} = 'display';
13927: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13928: $displayed{'folder'} = $i;
1.1164 raeburn 13929: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13930: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13931: $env{'form.archive_'.$i} = 'display';
13932: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13933: $displayed{'web'} = $i;
13934: } else {
1.1164 raeburn 13935: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13936: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13937: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13938: push(@{$env{'form.archive_directory'}},$i);
13939: }
13940: $env{'form.archive_'.$i} = 'dependency';
13941: }
13942: $total ++;
13943: }
13944: for (my $i=1; $i<$total; $i++) {
13945: next if ($i == $displayed{'web'});
13946: next if ($i == $displayed{'folder'});
13947: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13948: }
13949: $env{'form.phase'} = 'decompress_cleanup';
13950: $env{'form.archivedelete'} = 1;
13951: $env{'form.archive_count'} = $total-1;
13952: $output .=
13953: &process_extracted_files('coursedocs',$docudom,
13954: $docuname,$destination,
13955: $dir_root,$hiddenelem);
13956: }
1.1055 raeburn 13957: } else {
13958: $warning = &mt('No new items extracted from archive file.');
13959: }
13960: } else {
13961: $output = $display;
13962: $error = &mt('An error occurred during extraction from the archive file.');
13963: }
13964: }
13965: }
13966: }
13967: if ($error) {
13968: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13969: $error.'</p>'."\n";
13970: }
13971: if ($warning) {
13972: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13973: }
13974: return $output;
13975: }
13976:
13977: sub get_extracted {
1.1056 raeburn 13978: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13979: $titles,$wantform) = @_;
1.1055 raeburn 13980: my $count = 0;
13981: my $depth = 0;
13982: my $datatable;
1.1056 raeburn 13983: my @hierarchy;
1.1055 raeburn 13984: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13985: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13986: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13987: foreach my $item (@{$contents}) {
13988: $count ++;
1.1056 raeburn 13989: @{$dirorder->{$count}} = @hierarchy;
13990: $titles->{$count} = $item;
1.1055 raeburn 13991: &archive_hierarchy($depth,$count,$parent,$children);
13992: if ($wantform) {
13993: $datatable .= &archive_row($is_dir->{$item},$item,
13994: $currdir,$depth,$count);
13995: }
13996: if ($is_dir->{$item}) {
13997: $depth ++;
1.1056 raeburn 13998: push(@hierarchy,$count);
13999: $parent->{$depth} = $count;
1.1055 raeburn 14000: $datatable .=
14001: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 14002: \$depth,\$count,\@hierarchy,$dirorder,
14003: $children,$parent,$titles,$wantform);
1.1055 raeburn 14004: $depth --;
1.1056 raeburn 14005: pop(@hierarchy);
1.1055 raeburn 14006: }
14007: }
14008: return ($count,$datatable);
14009: }
14010:
14011: sub recurse_extracted_archive {
1.1056 raeburn 14012: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
14013: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 14014: my $result='';
1.1056 raeburn 14015: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
14016: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
14017: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 14018: return $result;
14019: }
14020: my $dirptr = 16384;
14021: my ($newdirlistref,$newlisterror) =
14022: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
14023: if (ref($newdirlistref) eq 'ARRAY') {
14024: foreach my $dir_line (@{$newdirlistref}) {
14025: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
14026: unless ($item =~ /^\.+$/) {
14027: $$count ++;
1.1056 raeburn 14028: @{$dirorder->{$$count}} = @{$hierarchy};
14029: $titles->{$$count} = $item;
1.1055 raeburn 14030: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 14031:
1.1055 raeburn 14032: my $is_dir;
14033: if ($dirptr&$testdir) {
14034: $is_dir = 1;
14035: }
14036: if ($wantform) {
14037: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
14038: }
14039: if ($is_dir) {
14040: $$depth ++;
1.1056 raeburn 14041: push(@{$hierarchy},$$count);
14042: $parent->{$$depth} = $$count;
1.1055 raeburn 14043: $result .=
14044: &recurse_extracted_archive("$currdir/$item",$docudom,
14045: $docuname,$depth,$count,
1.1056 raeburn 14046: $hierarchy,$dirorder,$children,
14047: $parent,$titles,$wantform);
1.1055 raeburn 14048: $$depth --;
1.1056 raeburn 14049: pop(@{$hierarchy});
1.1055 raeburn 14050: }
14051: }
14052: }
14053: }
14054: return $result;
14055: }
14056:
14057: sub archive_hierarchy {
14058: my ($depth,$count,$parent,$children) =@_;
14059: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
14060: if (exists($parent->{$depth})) {
14061: $children->{$parent->{$depth}} .= $count.':';
14062: }
14063: }
14064: return;
14065: }
14066:
14067: sub archive_row {
14068: my ($is_dir,$item,$currdir,$depth,$count) = @_;
14069: my ($name) = ($item =~ m{([^/]+)$});
14070: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 14071: 'display' => 'Add as file',
1.1055 raeburn 14072: 'dependency' => 'Include as dependency',
14073: 'discard' => 'Discard',
14074: );
14075: if ($is_dir) {
1.1059 raeburn 14076: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 14077: }
1.1056 raeburn 14078: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
14079: my $offset = 0;
1.1055 raeburn 14080: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 14081: $offset ++;
1.1065 raeburn 14082: if ($action ne 'display') {
14083: $offset ++;
14084: }
1.1055 raeburn 14085: $output .= '<td><span class="LC_nobreak">'.
14086: '<label><input type="radio" name="archive_'.$count.
14087: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
14088: my $text = $choices{$action};
14089: if ($is_dir) {
14090: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
14091: if ($action eq 'display') {
1.1059 raeburn 14092: $text = &mt('Add as folder');
1.1055 raeburn 14093: }
1.1056 raeburn 14094: } else {
14095: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
14096:
14097: }
14098: $output .= ' /> '.$choices{$action}.'</label></span>';
14099: if ($action eq 'dependency') {
14100: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
14101: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
14102: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
14103: '<option value=""></option>'."\n".
14104: '</select>'."\n".
14105: '</div>';
1.1059 raeburn 14106: } elsif ($action eq 'display') {
14107: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
14108: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
14109: '</div>';
1.1055 raeburn 14110: }
1.1056 raeburn 14111: $output .= '</td>';
1.1055 raeburn 14112: }
14113: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
14114: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
14115: for (my $i=0; $i<$depth; $i++) {
14116: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
14117: }
14118: if ($is_dir) {
14119: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
14120: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
14121: } else {
14122: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
14123: }
14124: $output .= ' '.$name.'</td>'."\n".
14125: &end_data_table_row();
14126: return $output;
14127: }
14128:
14129: sub archive_options_form {
1.1065 raeburn 14130: my ($form,$display,$count,$hiddenelem) = @_;
14131: my %lt = &Apache::lonlocal::texthash(
14132: perm => 'Permanently remove archive file?',
14133: hows => 'How should each extracted item be incorporated in the course?',
14134: cont => 'Content actions for all',
14135: addf => 'Add as folder/file',
14136: incd => 'Include as dependency for a displayed file',
14137: disc => 'Discard',
14138: no => 'No',
14139: yes => 'Yes',
14140: save => 'Save',
14141: );
14142: my $output = <<"END";
14143: <form name="$form" method="post" action="">
14144: <p><span class="LC_nobreak">$lt{'perm'}
14145: <label>
14146: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
14147: </label>
14148:
14149: <label>
14150: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
14151: </span>
14152: </p>
14153: <input type="hidden" name="phase" value="decompress_cleanup" />
14154: <br />$lt{'hows'}
14155: <div class="LC_columnSection">
14156: <fieldset>
14157: <legend>$lt{'cont'}</legend>
14158: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
14159: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
14160: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
14161: </fieldset>
14162: </div>
14163: END
14164: return $output.
1.1055 raeburn 14165: &start_data_table()."\n".
1.1065 raeburn 14166: $display."\n".
1.1055 raeburn 14167: &end_data_table()."\n".
14168: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
14169: $hiddenelem.
1.1065 raeburn 14170: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 14171: '</form>';
14172: }
14173:
14174: sub archive_javascript {
1.1056 raeburn 14175: my ($startcount,$numitems,$titles,$children) = @_;
14176: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 14177: my $maintitle = $env{'form.comment'};
1.1055 raeburn 14178: my $scripttag = <<START;
14179: <script type="text/javascript">
14180: // <![CDATA[
14181:
14182: function checkAll(form,prefix) {
14183: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
14184: for (var i=0; i < form.elements.length; i++) {
14185: var id = form.elements[i].id;
14186: if ((id != '') && (id != undefined)) {
14187: if (idstr.test(id)) {
14188: if (form.elements[i].type == 'radio') {
14189: form.elements[i].checked = true;
1.1056 raeburn 14190: var nostart = i-$startcount;
1.1059 raeburn 14191: var offset = nostart%7;
14192: var count = (nostart-offset)/7;
1.1056 raeburn 14193: dependencyCheck(form,count,offset);
1.1055 raeburn 14194: }
14195: }
14196: }
14197: }
14198: }
14199:
14200: function propagateCheck(form,count) {
14201: if (count > 0) {
1.1059 raeburn 14202: var startelement = $startcount + ((count-1) * 7);
14203: for (var j=1; j<6; j++) {
14204: if ((j != 2) && (j != 4)) {
1.1056 raeburn 14205: var item = startelement + j;
14206: if (form.elements[item].type == 'radio') {
14207: if (form.elements[item].checked) {
14208: containerCheck(form,count,j);
14209: break;
14210: }
1.1055 raeburn 14211: }
14212: }
14213: }
14214: }
14215: }
14216:
14217: numitems = $numitems
1.1056 raeburn 14218: var titles = new Array(numitems);
14219: var parents = new Array(numitems);
1.1055 raeburn 14220: for (var i=0; i<numitems; i++) {
1.1056 raeburn 14221: parents[i] = new Array;
1.1055 raeburn 14222: }
1.1059 raeburn 14223: var maintitle = '$maintitle';
1.1055 raeburn 14224:
14225: START
14226:
1.1056 raeburn 14227: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
14228: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 14229: for (my $i=0; $i<@contents; $i ++) {
14230: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
14231: }
14232: }
14233:
1.1056 raeburn 14234: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
14235: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
14236: }
14237:
1.1055 raeburn 14238: $scripttag .= <<END;
14239:
14240: function containerCheck(form,count,offset) {
14241: if (count > 0) {
1.1056 raeburn 14242: dependencyCheck(form,count,offset);
1.1059 raeburn 14243: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 14244: form.elements[item].checked = true;
14245: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
14246: if (parents[count].length > 0) {
14247: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 14248: containerCheck(form,parents[count][j],offset);
14249: }
14250: }
14251: }
14252: }
14253: }
14254:
14255: function dependencyCheck(form,count,offset) {
14256: if (count > 0) {
1.1059 raeburn 14257: var chosen = (offset+$startcount)+7*(count-1);
14258: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 14259: var currtype = form.elements[depitem].type;
14260: if (form.elements[chosen].value == 'dependency') {
14261: document.getElementById('arc_depon_'+count).style.display='block';
14262: form.elements[depitem].options.length = 0;
14263: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 14264: for (var i=1; i<=numitems; i++) {
14265: if (i == count) {
14266: continue;
14267: }
1.1059 raeburn 14268: var startelement = $startcount + (i-1) * 7;
14269: for (var j=1; j<6; j++) {
14270: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 14271: var item = startelement + j;
14272: if (form.elements[item].type == 'radio') {
14273: if (form.elements[item].checked) {
14274: if (form.elements[item].value == 'display') {
14275: var n = form.elements[depitem].options.length;
14276: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
14277: }
14278: }
14279: }
14280: }
14281: }
14282: }
14283: } else {
14284: document.getElementById('arc_depon_'+count).style.display='none';
14285: form.elements[depitem].options.length = 0;
14286: form.elements[depitem].options[0] = new Option('Select','',true,true);
14287: }
1.1059 raeburn 14288: titleCheck(form,count,offset);
1.1056 raeburn 14289: }
14290: }
14291:
14292: function propagateSelect(form,count,offset) {
14293: if (count > 0) {
1.1065 raeburn 14294: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 14295: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
14296: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14297: if (parents[count].length > 0) {
14298: for (var j=0; j<parents[count].length; j++) {
14299: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 14300: }
14301: }
14302: }
14303: }
14304: }
1.1056 raeburn 14305:
14306: function containerSelect(form,count,offset,picked) {
14307: if (count > 0) {
1.1065 raeburn 14308: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 14309: if (form.elements[item].type == 'radio') {
14310: if (form.elements[item].value == 'dependency') {
14311: if (form.elements[item+1].type == 'select-one') {
14312: for (var i=0; i<form.elements[item+1].options.length; i++) {
14313: if (form.elements[item+1].options[i].value == picked) {
14314: form.elements[item+1].selectedIndex = i;
14315: break;
14316: }
14317: }
14318: }
14319: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
14320: if (parents[count].length > 0) {
14321: for (var j=0; j<parents[count].length; j++) {
14322: containerSelect(form,parents[count][j],offset,picked);
14323: }
14324: }
14325: }
14326: }
14327: }
14328: }
14329: }
14330:
1.1059 raeburn 14331: function titleCheck(form,count,offset) {
14332: if (count > 0) {
14333: var chosen = (offset+$startcount)+7*(count-1);
14334: var depitem = $startcount + ((count-1) * 7) + 2;
14335: var currtype = form.elements[depitem].type;
14336: if (form.elements[chosen].value == 'display') {
14337: document.getElementById('arc_title_'+count).style.display='block';
14338: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
14339: document.getElementById('archive_title_'+count).value=maintitle;
14340: }
14341: } else {
14342: document.getElementById('arc_title_'+count).style.display='none';
14343: if (currtype == 'text') {
14344: document.getElementById('archive_title_'+count).value='';
14345: }
14346: }
14347: }
14348: return;
14349: }
14350:
1.1055 raeburn 14351: // ]]>
14352: </script>
14353: END
14354: return $scripttag;
14355: }
14356:
14357: sub process_extracted_files {
1.1067 raeburn 14358: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 14359: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 14360: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 14361: my @ids=&Apache::lonnet::current_machine_ids();
14362: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 14363: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 14364: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
14365: if (grep(/^\Q$docuhome\E$/,@ids)) {
14366: $prefix = &LONCAPA::propath($docudom,$docuname);
14367: $pathtocheck = "$dir_root/$destination";
14368: $dir = $dir_root;
14369: $ishome = 1;
14370: } else {
14371: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
14372: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 14373: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 14374: }
14375: my $currdir = "$dir_root/$destination";
14376: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
14377: if ($env{'form.folderpath'}) {
14378: my @items = split('&',$env{'form.folderpath'});
14379: $folders{'0'} = $items[-2];
1.1099 raeburn 14380: if ($env{'form.folderpath'} =~ /\:1$/) {
14381: $containers{'0'}='page';
14382: } else {
14383: $containers{'0'}='sequence';
14384: }
1.1055 raeburn 14385: }
14386: my @archdirs = &get_env_multiple('form.archive_directory');
14387: if ($numitems) {
14388: for (my $i=1; $i<=$numitems; $i++) {
14389: my $path = $env{'form.archive_content_'.$i};
14390: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
14391: my $item = $1;
14392: $toplevelitems{$item} = $i;
14393: if (grep(/^\Q$i\E$/,@archdirs)) {
14394: $is_dir{$item} = 1;
14395: }
14396: }
14397: }
14398: }
1.1067 raeburn 14399: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 14400: if (keys(%toplevelitems) > 0) {
14401: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 14402: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
14403: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 14404: }
1.1066 raeburn 14405: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 14406: if ($numitems) {
14407: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 14408: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 14409: my $path = $env{'form.archive_content_'.$i};
14410: if ($path =~ /^\Q$pathtocheck\E/) {
14411: if ($env{'form.archive_'.$i} eq 'discard') {
14412: if ($prefix ne '' && $path ne '') {
14413: if (-e $prefix.$path) {
1.1066 raeburn 14414: if ((@archdirs > 0) &&
14415: (grep(/^\Q$i\E$/,@archdirs))) {
14416: $todeletedir{$prefix.$path} = 1;
14417: } else {
14418: $todelete{$prefix.$path} = 1;
14419: }
1.1055 raeburn 14420: }
14421: }
14422: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 14423: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 14424: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 14425: $docstitle = $env{'form.archive_title_'.$i};
14426: if ($docstitle eq '') {
14427: $docstitle = $title;
14428: }
1.1055 raeburn 14429: $outer = 0;
1.1056 raeburn 14430: if (ref($dirorder{$i}) eq 'ARRAY') {
14431: if (@{$dirorder{$i}} > 0) {
14432: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 14433: if ($env{'form.archive_'.$item} eq 'display') {
14434: $outer = $item;
14435: last;
14436: }
14437: }
14438: }
14439: }
14440: my ($errtext,$fatal) =
14441: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
14442: '/'.$folders{$outer}.'.'.
14443: $containers{$outer});
14444: next if ($fatal);
14445: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
14446: if ($context eq 'coursedocs') {
1.1056 raeburn 14447: $mapinner{$i} = time;
1.1055 raeburn 14448: $folders{$i} = 'default_'.$mapinner{$i};
14449: $containers{$i} = 'sequence';
14450: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14451: $folders{$i}.'.'.$containers{$i};
14452: my $newidx = &LONCAPA::map::getresidx();
14453: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 14454: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 14455: push(@LONCAPA::map::order,$newidx);
14456: my ($outtext,$errtext) =
14457: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14458: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 14459: '.'.$containers{$outer},1,1);
1.1056 raeburn 14460: $newseqid{$i} = $newidx;
1.1067 raeburn 14461: unless ($errtext) {
1.1294 raeburn 14462: $result .= '<li>'.&mt('Folder: [_1] added to course',
14463: &HTML::Entities::encode($docstitle,'<>&"')).
14464: '</li>'."\n";
1.1067 raeburn 14465: }
1.1055 raeburn 14466: }
14467: } else {
14468: if ($context eq 'coursedocs') {
14469: my $newidx=&LONCAPA::map::getresidx();
14470: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
14471: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
14472: $title;
1.1392 raeburn 14473: if (($outer !~ /\D/) &&
14474: (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
14475: ($newidx !~ /\D/)) {
1.1294 raeburn 14476: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
14477: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
14478: }
14479: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14480: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
14481: }
14482: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
14483: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
14484: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
14485: unless ($ishome) {
14486: my $fetch = "$newdest{$i}/$title";
14487: $fetch =~ s/^\Q$prefix$dir\E//;
14488: $prompttofetch{$fetch} = 1;
14489: }
1.1292 raeburn 14490: }
1.1067 raeburn 14491: }
1.1294 raeburn 14492: $LONCAPA::map::resources[$newidx]=
14493: $docstitle.':'.$url.':false:normal:res';
14494: push(@LONCAPA::map::order, $newidx);
14495: my ($outtext,$errtext)=
14496: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
14497: $docuname.'/'.$folders{$outer}.
14498: '.'.$containers{$outer},1,1);
14499: unless ($errtext) {
14500: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
14501: $result .= '<li>'.&mt('File: [_1] added to course',
14502: &HTML::Entities::encode($docstitle,'<>&"')).
14503: '</li>'."\n";
14504: }
1.1067 raeburn 14505: }
1.1294 raeburn 14506: } else {
14507: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14508: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 14509: }
1.1055 raeburn 14510: }
14511: }
1.1086 raeburn 14512: }
14513: } else {
1.1294 raeburn 14514: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
14515: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 14516: }
14517: }
14518: for (my $i=1; $i<=$numitems; $i++) {
14519: next unless ($env{'form.archive_'.$i} eq 'dependency');
14520: my $path = $env{'form.archive_content_'.$i};
14521: if ($path =~ /^\Q$pathtocheck\E/) {
14522: my ($title) = ($path =~ m{/([^/]+)$});
14523: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
14524: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
14525: if (ref($dirorder{$i}) eq 'ARRAY') {
14526: my ($itemidx,$fullpath,$relpath);
14527: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
14528: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 14529: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 14530: if ($dirorder{$i}->[$j] eq $container) {
14531: $itemidx = $j;
1.1056 raeburn 14532: }
14533: }
1.1086 raeburn 14534: }
14535: if ($itemidx eq '') {
14536: $itemidx = 0;
14537: }
14538: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
14539: if ($mapinner{$referrer{$i}}) {
14540: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
14541: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14542: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14543: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14544: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14545: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14546: if (!-e $fullpath) {
14547: mkdir($fullpath,0755);
1.1056 raeburn 14548: }
14549: }
1.1086 raeburn 14550: } else {
14551: last;
1.1056 raeburn 14552: }
1.1086 raeburn 14553: }
14554: }
14555: } elsif ($newdest{$referrer{$i}}) {
14556: $fullpath = $newdest{$referrer{$i}};
14557: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
14558: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
14559: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
14560: last;
14561: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
14562: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
14563: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
14564: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
14565: if (!-e $fullpath) {
14566: mkdir($fullpath,0755);
1.1056 raeburn 14567: }
14568: }
1.1086 raeburn 14569: } else {
14570: last;
1.1056 raeburn 14571: }
1.1055 raeburn 14572: }
14573: }
1.1086 raeburn 14574: if ($fullpath ne '') {
14575: if (-e "$prefix$path") {
1.1292 raeburn 14576: unless (rename("$prefix$path","$fullpath/$title")) {
14577: $warning .= &mt('Failed to rename dependency').'<br />';
14578: }
1.1086 raeburn 14579: }
14580: if (-e "$fullpath/$title") {
14581: my $showpath;
14582: if ($relpath ne '') {
14583: $showpath = "$relpath/$title";
14584: } else {
14585: $showpath = "/$title";
14586: }
1.1294 raeburn 14587: $result .= '<li>'.&mt('[_1] included as a dependency',
14588: &HTML::Entities::encode($showpath,'<>&"')).
14589: '</li>'."\n";
1.1292 raeburn 14590: unless ($ishome) {
14591: my $fetch = "$fullpath/$title";
14592: $fetch =~ s/^\Q$prefix$dir\E//;
14593: $prompttofetch{$fetch} = 1;
14594: }
1.1086 raeburn 14595: }
14596: }
1.1055 raeburn 14597: }
1.1086 raeburn 14598: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
14599: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 14600: &HTML::Entities::encode($path,'<>&"'),
14601: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
14602: '<br />';
1.1055 raeburn 14603: }
14604: } else {
1.1294 raeburn 14605: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 14606: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 14607: }
14608: }
14609: if (keys(%todelete)) {
14610: foreach my $key (keys(%todelete)) {
14611: unlink($key);
1.1066 raeburn 14612: }
14613: }
14614: if (keys(%todeletedir)) {
14615: foreach my $key (keys(%todeletedir)) {
14616: rmdir($key);
14617: }
14618: }
14619: foreach my $dir (sort(keys(%is_dir))) {
14620: if (($pathtocheck ne '') && ($dir ne '')) {
14621: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 14622: }
14623: }
1.1067 raeburn 14624: if ($result ne '') {
14625: $output .= '<ul>'."\n".
14626: $result."\n".
14627: '</ul>';
14628: }
14629: unless ($ishome) {
14630: my $replicationfail;
14631: foreach my $item (keys(%prompttofetch)) {
14632: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
14633: unless ($fetchresult eq 'ok') {
14634: $replicationfail .= '<li>'.$item.'</li>'."\n";
14635: }
14636: }
14637: if ($replicationfail) {
14638: $output .= '<p class="LC_error">'.
14639: &mt('Course home server failed to retrieve:').'<ul>'.
14640: $replicationfail.
14641: '</ul></p>';
14642: }
14643: }
1.1055 raeburn 14644: } else {
14645: $warning = &mt('No items found in archive.');
14646: }
14647: if ($error) {
14648: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
14649: $error.'</p>'."\n";
14650: }
14651: if ($warning) {
14652: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
14653: }
14654: return $output;
14655: }
14656:
1.1066 raeburn 14657: sub cleanup_empty_dirs {
14658: my ($path) = @_;
14659: if (($path ne '') && (-d $path)) {
14660: if (opendir(my $dirh,$path)) {
14661: my @dircontents = grep(!/^\./,readdir($dirh));
14662: my $numitems = 0;
14663: foreach my $item (@dircontents) {
14664: if (-d "$path/$item") {
1.1111 raeburn 14665: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 14666: if (-e "$path/$item") {
14667: $numitems ++;
14668: }
14669: } else {
14670: $numitems ++;
14671: }
14672: }
14673: if ($numitems == 0) {
14674: rmdir($path);
14675: }
14676: closedir($dirh);
14677: }
14678: }
14679: return;
14680: }
14681:
1.41 ng 14682: =pod
1.45 matthew 14683:
1.1162 raeburn 14684: =item * &get_folder_hierarchy()
1.1068 raeburn 14685:
14686: Provides hierarchy of names of folders/sub-folders containing the current
14687: item,
14688:
14689: Inputs: 3
14690: - $navmap - navmaps object
14691:
14692: - $map - url for map (either the trigger itself, or map containing
14693: the resource, which is the trigger).
14694:
14695: - $showitem - 1 => show title for map itself; 0 => do not show.
14696:
14697: Outputs: 1 @pathitems - array of folder/subfolder names.
14698:
14699: =cut
14700:
14701: sub get_folder_hierarchy {
14702: my ($navmap,$map,$showitem) = @_;
14703: my @pathitems;
14704: if (ref($navmap)) {
14705: my $mapres = $navmap->getResourceByUrl($map);
14706: if (ref($mapres)) {
14707: my $pcslist = $mapres->map_hierarchy();
14708: if ($pcslist ne '') {
14709: my @pcs = split(/,/,$pcslist);
14710: foreach my $pc (@pcs) {
14711: if ($pc == 1) {
1.1129 raeburn 14712: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14713: } else {
14714: my $res = $navmap->getByMapPc($pc);
14715: if (ref($res)) {
14716: my $title = $res->compTitle();
14717: $title =~ s/\W+/_/g;
14718: if ($title ne '') {
14719: push(@pathitems,$title);
14720: }
14721: }
14722: }
14723: }
14724: }
1.1071 raeburn 14725: if ($showitem) {
14726: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 14727: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14728: } else {
14729: my $maptitle = $mapres->compTitle();
14730: $maptitle =~ s/\W+/_/g;
14731: if ($maptitle ne '') {
14732: push(@pathitems,$maptitle);
14733: }
1.1068 raeburn 14734: }
14735: }
14736: }
14737: }
14738: return @pathitems;
14739: }
14740:
14741: =pod
14742:
1.1015 raeburn 14743: =item * &get_turnedin_filepath()
14744:
14745: Determines path in a user's portfolio file for storage of files uploaded
14746: to a specific essayresponse or dropbox item.
14747:
14748: Inputs: 3 required + 1 optional.
14749: $symb is symb for resource, $uname and $udom are for current user (required).
14750: $caller is optional (can be "submission", if routine is called when storing
14751: an upoaded file when "Submit Answer" button was pressed).
14752:
14753: Returns array containing $path and $multiresp.
14754: $path is path in portfolio. $multiresp is 1 if this resource contains more
14755: than one file upload item. Callers of routine should append partid as a
14756: subdirectory to $path in cases where $multiresp is 1.
14757:
14758: Called by: homework/essayresponse.pm and homework/structuretags.pm
14759:
14760: =cut
14761:
14762: sub get_turnedin_filepath {
14763: my ($symb,$uname,$udom,$caller) = @_;
14764: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14765: my $turnindir;
14766: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14767: $turnindir = $userhash{'turnindir'};
14768: my ($path,$multiresp);
14769: if ($turnindir eq '') {
14770: if ($caller eq 'submission') {
14771: $turnindir = &mt('turned in');
14772: $turnindir =~ s/\W+/_/g;
14773: my %newhash = (
14774: 'turnindir' => $turnindir,
14775: );
14776: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14777: }
14778: }
14779: if ($turnindir ne '') {
14780: $path = '/'.$turnindir.'/';
14781: my ($multipart,$turnin,@pathitems);
14782: my $navmap = Apache::lonnavmaps::navmap->new();
14783: if (defined($navmap)) {
14784: my $mapres = $navmap->getResourceByUrl($map);
14785: if (ref($mapres)) {
14786: my $pcslist = $mapres->map_hierarchy();
14787: if ($pcslist ne '') {
14788: foreach my $pc (split(/,/,$pcslist)) {
14789: my $res = $navmap->getByMapPc($pc);
14790: if (ref($res)) {
14791: my $title = $res->compTitle();
14792: $title =~ s/\W+/_/g;
14793: if ($title ne '') {
1.1149 raeburn 14794: if (($pc > 1) && (length($title) > 12)) {
14795: $title = substr($title,0,12);
14796: }
1.1015 raeburn 14797: push(@pathitems,$title);
14798: }
14799: }
14800: }
14801: }
14802: my $maptitle = $mapres->compTitle();
14803: $maptitle =~ s/\W+/_/g;
14804: if ($maptitle ne '') {
1.1149 raeburn 14805: if (length($maptitle) > 12) {
14806: $maptitle = substr($maptitle,0,12);
14807: }
1.1015 raeburn 14808: push(@pathitems,$maptitle);
14809: }
14810: unless ($env{'request.state'} eq 'construct') {
14811: my $res = $navmap->getBySymb($symb);
14812: if (ref($res)) {
14813: my $partlist = $res->parts();
14814: my $totaluploads = 0;
14815: if (ref($partlist) eq 'ARRAY') {
14816: foreach my $part (@{$partlist}) {
14817: my @types = $res->responseType($part);
14818: my @ids = $res->responseIds($part);
14819: for (my $i=0; $i < scalar(@ids); $i++) {
14820: if ($types[$i] eq 'essay') {
14821: my $partid = $part.'_'.$ids[$i];
14822: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14823: $totaluploads ++;
14824: }
14825: }
14826: }
14827: }
14828: if ($totaluploads > 1) {
14829: $multiresp = 1;
14830: }
14831: }
14832: }
14833: }
14834: } else {
14835: return;
14836: }
14837: } else {
14838: return;
14839: }
14840: my $restitle=&Apache::lonnet::gettitle($symb);
14841: $restitle =~ s/\W+/_/g;
14842: if ($restitle eq '') {
14843: $restitle = ($resurl =~ m{/[^/]+$});
14844: if ($restitle eq '') {
14845: $restitle = time;
14846: }
14847: }
1.1149 raeburn 14848: if (length($restitle) > 12) {
14849: $restitle = substr($restitle,0,12);
14850: }
1.1015 raeburn 14851: push(@pathitems,$restitle);
14852: $path .= join('/',@pathitems);
14853: }
14854: return ($path,$multiresp);
14855: }
14856:
14857: =pod
14858:
1.464 albertel 14859: =back
1.41 ng 14860:
1.112 bowersj2 14861: =head1 CSV Upload/Handling functions
1.38 albertel 14862:
1.41 ng 14863: =over 4
14864:
1.648 raeburn 14865: =item * &upfile_store($r)
1.41 ng 14866:
14867: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14868: needs $env{'form.upfile'}
1.41 ng 14869: returns $datatoken to be put into hidden field
14870:
14871: =cut
1.31 albertel 14872:
14873: sub upfile_store {
14874: my $r=shift;
1.258 albertel 14875: $env{'form.upfile'}=~s/\r/\n/gs;
14876: $env{'form.upfile'}=~s/\f/\n/gs;
14877: $env{'form.upfile'}=~s/\n+/\n/gs;
14878: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14879:
1.1299 raeburn 14880: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14881: '_enroll_'.$env{'request.course.id'}.'_'.
14882: time.'_'.$$);
14883: return if ($datatoken eq '');
14884:
1.31 albertel 14885: {
1.158 raeburn 14886: my $datafile = $r->dir_config('lonDaemons').
14887: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14888: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14889: print $fh $env{'form.upfile'};
1.158 raeburn 14890: close($fh);
14891: }
1.31 albertel 14892: }
14893: return $datatoken;
14894: }
14895:
1.56 matthew 14896: =pod
14897:
1.1290 raeburn 14898: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14899:
14900: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14901: $datatoken is the name to assign to the temporary file.
1.258 albertel 14902: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14903:
14904: =cut
1.31 albertel 14905:
14906: sub load_tmp_file {
1.1290 raeburn 14907: my ($r,$datatoken) = @_;
14908: return if ($datatoken eq '');
1.31 albertel 14909: my @studentdata=();
14910: {
1.158 raeburn 14911: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14912: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14913: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14914: @studentdata=<$fh>;
14915: close($fh);
14916: }
1.31 albertel 14917: }
1.258 albertel 14918: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14919: }
14920:
1.1290 raeburn 14921: sub valid_datatoken {
14922: my ($datatoken) = @_;
1.1325 raeburn 14923: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14924: return $datatoken;
14925: }
14926: return;
14927: }
14928:
1.56 matthew 14929: =pod
14930:
1.648 raeburn 14931: =item * &upfile_record_sep()
1.41 ng 14932:
14933: Separate uploaded file into records
14934: returns array of records,
1.258 albertel 14935: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14936:
14937: =cut
1.31 albertel 14938:
14939: sub upfile_record_sep {
1.258 albertel 14940: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14941: } else {
1.248 albertel 14942: my @records;
1.258 albertel 14943: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14944: if ($line=~/^\s*$/) { next; }
14945: push(@records,$line);
14946: }
14947: return @records;
1.31 albertel 14948: }
14949: }
14950:
1.56 matthew 14951: =pod
14952:
1.648 raeburn 14953: =item * &record_sep($record)
1.41 ng 14954:
1.258 albertel 14955: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14956:
14957: =cut
14958:
1.263 www 14959: sub takeleft {
14960: my $index=shift;
14961: return substr('0000'.$index,-4,4);
14962: }
14963:
1.31 albertel 14964: sub record_sep {
14965: my $record=shift;
14966: my %components=();
1.258 albertel 14967: if ($env{'form.upfiletype'} eq 'xml') {
14968: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14969: my $i=0;
1.356 albertel 14970: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14971: $field=~s/^(\"|\')//;
14972: $field=~s/(\"|\')$//;
1.263 www 14973: $components{&takeleft($i)}=$field;
1.31 albertel 14974: $i++;
14975: }
1.258 albertel 14976: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14977: my $i=0;
1.356 albertel 14978: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14979: $field=~s/^(\"|\')//;
14980: $field=~s/(\"|\')$//;
1.263 www 14981: $components{&takeleft($i)}=$field;
1.31 albertel 14982: $i++;
14983: }
14984: } else {
1.561 www 14985: my $separator=',';
1.480 banghart 14986: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14987: $separator=';';
1.480 banghart 14988: }
1.31 albertel 14989: my $i=0;
1.561 www 14990: # the character we are looking for to indicate the end of a quote or a record
14991: my $looking_for=$separator;
14992: # do not add the characters to the fields
14993: my $ignore=0;
14994: # we just encountered a separator (or the beginning of the record)
14995: my $just_found_separator=1;
14996: # store the field we are working on here
14997: my $field='';
14998: # work our way through all characters in record
14999: foreach my $character ($record=~/(.)/g) {
15000: if ($character eq $looking_for) {
15001: if ($character ne $separator) {
15002: # Found the end of a quote, again looking for separator
15003: $looking_for=$separator;
15004: $ignore=1;
15005: } else {
15006: # Found a separator, store away what we got
15007: $components{&takeleft($i)}=$field;
15008: $i++;
15009: $just_found_separator=1;
15010: $ignore=0;
15011: $field='';
15012: }
15013: next;
15014: }
15015: # single or double quotation marks after a separator indicate beginning of a quote
15016: # we are now looking for the end of the quote and need to ignore separators
15017: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
15018: $looking_for=$character;
15019: next;
15020: }
15021: # ignore would be true after we reached the end of a quote
15022: if ($ignore) { next; }
15023: if (($just_found_separator) && ($character=~/\s/)) { next; }
15024: $field.=$character;
15025: $just_found_separator=0;
1.31 albertel 15026: }
1.561 www 15027: # catch the very last entry, since we never encountered the separator
15028: $components{&takeleft($i)}=$field;
1.31 albertel 15029: }
15030: return %components;
15031: }
15032:
1.144 matthew 15033: ######################################################
15034: ######################################################
15035:
1.56 matthew 15036: =pod
15037:
1.648 raeburn 15038: =item * &upfile_select_html()
1.41 ng 15039:
1.144 matthew 15040: Return HTML code to select a file from the users machine and specify
15041: the file type.
1.41 ng 15042:
15043: =cut
15044:
1.144 matthew 15045: ######################################################
15046: ######################################################
1.31 albertel 15047: sub upfile_select_html {
1.144 matthew 15048: my %Types = (
15049: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 15050: semisv => &mt('Semicolon separated values'),
1.144 matthew 15051: space => &mt('Space separated'),
15052: tab => &mt('Tabulator separated'),
15053: # xml => &mt('HTML/XML'),
15054: );
15055: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 15056: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 15057: foreach my $type (sort(keys(%Types))) {
15058: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
15059: }
15060: $Str .= "</select>\n";
15061: return $Str;
1.31 albertel 15062: }
15063:
1.301 albertel 15064: sub get_samples {
15065: my ($records,$toget) = @_;
15066: my @samples=({});
15067: my $got=0;
15068: foreach my $rec (@$records) {
15069: my %temp = &record_sep($rec);
15070: if (! grep(/\S/, values(%temp))) { next; }
15071: if (%temp) {
15072: $samples[$got]=\%temp;
15073: $got++;
15074: if ($got == $toget) { last; }
15075: }
15076: }
15077: return \@samples;
15078: }
15079:
1.144 matthew 15080: ######################################################
15081: ######################################################
15082:
1.56 matthew 15083: =pod
15084:
1.648 raeburn 15085: =item * &csv_print_samples($r,$records)
1.41 ng 15086:
15087: Prints a table of sample values from each column uploaded $r is an
15088: Apache Request ref, $records is an arrayref from
15089: &Apache::loncommon::upfile_record_sep
15090:
15091: =cut
15092:
1.144 matthew 15093: ######################################################
15094: ######################################################
1.31 albertel 15095: sub csv_print_samples {
15096: my ($r,$records) = @_;
1.662 bisitz 15097: my $samples = &get_samples($records,5);
1.301 albertel 15098:
1.594 raeburn 15099: $r->print(&mt('Samples').'<br />'.&start_data_table().
15100: &start_data_table_header_row());
1.356 albertel 15101: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 15102: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 15103: $r->print(&end_data_table_header_row());
1.301 albertel 15104: foreach my $hash (@$samples) {
1.594 raeburn 15105: $r->print(&start_data_table_row());
1.356 albertel 15106: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 15107: $r->print('<td>');
1.356 albertel 15108: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 15109: $r->print('</td>');
15110: }
1.594 raeburn 15111: $r->print(&end_data_table_row());
1.31 albertel 15112: }
1.594 raeburn 15113: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 15114: }
15115:
1.144 matthew 15116: ######################################################
15117: ######################################################
15118:
1.56 matthew 15119: =pod
15120:
1.648 raeburn 15121: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 15122:
15123: Prints a table to create associations between values and table columns.
1.144 matthew 15124:
1.41 ng 15125: $r is an Apache Request ref,
15126: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 15127: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 15128:
15129: =cut
15130:
1.144 matthew 15131: ######################################################
15132: ######################################################
1.31 albertel 15133: sub csv_print_select_table {
15134: my ($r,$records,$d) = @_;
1.301 albertel 15135: my $i=0;
15136: my $samples = &get_samples($records,1);
1.144 matthew 15137: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 15138: &start_data_table().&start_data_table_header_row().
1.144 matthew 15139: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 15140: '<th>'.&mt('Column').'</th>'.
15141: &end_data_table_header_row()."\n");
1.356 albertel 15142: foreach my $array_ref (@$d) {
15143: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 15144: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 15145:
1.875 bisitz 15146: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 15147: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 15148: $r->print('<option value="none"></option>');
1.356 albertel 15149: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
15150: $r->print('<option value="'.$sample.'"'.
15151: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 15152: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 15153: }
1.594 raeburn 15154: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 15155: $i++;
15156: }
1.594 raeburn 15157: $r->print(&end_data_table());
1.31 albertel 15158: $i--;
15159: return $i;
15160: }
1.56 matthew 15161:
1.144 matthew 15162: ######################################################
15163: ######################################################
15164:
1.56 matthew 15165: =pod
1.31 albertel 15166:
1.648 raeburn 15167: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 15168:
15169: Prints a table of sample values from the upload and can make associate samples to internal names.
15170:
15171: $r is an Apache Request ref,
15172: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
15173: $d is an array of 2 element arrays (internal name, displayed name)
15174:
15175: =cut
15176:
1.144 matthew 15177: ######################################################
15178: ######################################################
1.31 albertel 15179: sub csv_samples_select_table {
15180: my ($r,$records,$d) = @_;
15181: my $i=0;
1.144 matthew 15182: #
1.662 bisitz 15183: my $max_samples = 5;
15184: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 15185: $r->print(&start_data_table().
15186: &start_data_table_header_row().'<th>'.
15187: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
15188: &end_data_table_header_row());
1.301 albertel 15189:
15190: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 15191: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 15192: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 15193: foreach my $option (@$d) {
15194: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 15195: $r->print('<option value="'.$value.'"'.
1.253 albertel 15196: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 15197: $display.'</option>');
1.31 albertel 15198: }
15199: $r->print('</select></td><td>');
1.662 bisitz 15200: foreach my $line (0..($max_samples-1)) {
1.301 albertel 15201: if (defined($samples->[$line]{$key})) {
15202: $r->print($samples->[$line]{$key}."<br />\n");
15203: }
15204: }
1.594 raeburn 15205: $r->print('</td>'.&end_data_table_row());
1.31 albertel 15206: $i++;
15207: }
1.594 raeburn 15208: $r->print(&end_data_table());
1.31 albertel 15209: $i--;
15210: return($i);
1.115 matthew 15211: }
15212:
1.144 matthew 15213: ######################################################
15214: ######################################################
15215:
1.115 matthew 15216: =pod
15217:
1.648 raeburn 15218: =item * &clean_excel_name($name)
1.115 matthew 15219:
15220: Returns a replacement for $name which does not contain any illegal characters.
15221:
15222: =cut
15223:
1.144 matthew 15224: ######################################################
15225: ######################################################
1.115 matthew 15226: sub clean_excel_name {
15227: my ($name) = @_;
15228: $name =~ s/[:\*\?\/\\]//g;
15229: if (length($name) > 31) {
15230: $name = substr($name,0,31);
15231: }
15232: return $name;
1.25 albertel 15233: }
1.84 albertel 15234:
1.85 albertel 15235: =pod
15236:
1.648 raeburn 15237: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 15238:
15239: Returns either 1 or undef
15240:
15241: 1 if the part is to be hidden, undef if it is to be shown
15242:
15243: Arguments are:
15244:
15245: $id the id of the part to be checked
15246: $symb, optional the symb of the resource to check
15247: $udom, optional the domain of the user to check for
15248: $uname, optional the username of the user to check for
15249:
15250: =cut
1.84 albertel 15251:
15252: sub check_if_partid_hidden {
15253: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 15254: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 15255: $symb,$udom,$uname);
1.141 albertel 15256: my $truth=1;
15257: #if the string starts with !, then the list is the list to show not hide
15258: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 15259: my @hiddenlist=split(/,/,$hiddenparts);
15260: foreach my $checkid (@hiddenlist) {
1.141 albertel 15261: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 15262: }
1.141 albertel 15263: return !$truth;
1.84 albertel 15264: }
1.127 matthew 15265:
1.138 matthew 15266:
15267: ############################################################
15268: ############################################################
15269:
15270: =pod
15271:
1.157 matthew 15272: =back
15273:
1.138 matthew 15274: =head1 cgi-bin script and graphing routines
15275:
1.157 matthew 15276: =over 4
15277:
1.648 raeburn 15278: =item * &get_cgi_id()
1.138 matthew 15279:
15280: Inputs: none
15281:
15282: Returns an id which can be used to pass environment variables
15283: to various cgi-bin scripts. These environment variables will
15284: be removed from the users environment after a given time by
15285: the routine &Apache::lonnet::transfer_profile_to_env.
15286:
15287: =cut
15288:
15289: ############################################################
15290: ############################################################
1.152 albertel 15291: my $uniq=0;
1.136 matthew 15292: sub get_cgi_id {
1.154 albertel 15293: $uniq=($uniq+1)%100000;
1.280 albertel 15294: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 15295: }
15296:
1.127 matthew 15297: ############################################################
15298: ############################################################
15299:
15300: =pod
15301:
1.648 raeburn 15302: =item * &DrawBarGraph()
1.127 matthew 15303:
1.138 matthew 15304: Facilitates the plotting of data in a (stacked) bar graph.
15305: Puts plot definition data into the users environment in order for
15306: graph.png to plot it. Returns an <img> tag for the plot.
15307: The bars on the plot are labeled '1','2',...,'n'.
15308:
15309: Inputs:
15310:
15311: =over 4
15312:
15313: =item $Title: string, the title of the plot
15314:
15315: =item $xlabel: string, text describing the X-axis of the plot
15316:
15317: =item $ylabel: string, text describing the Y-axis of the plot
15318:
15319: =item $Max: scalar, the maximum Y value to use in the plot
15320: If $Max is < any data point, the graph will not be rendered.
15321:
1.140 matthew 15322: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 15323: they are plotted. If undefined, default values will be used.
15324:
1.178 matthew 15325: =item $labels: array ref holding the labels to use on the x-axis for the bars.
15326:
1.138 matthew 15327: =item @Values: An array of array references. Each array reference holds data
15328: to be plotted in a stacked bar chart.
15329:
1.239 matthew 15330: =item If the final element of @Values is a hash reference the key/value
15331: pairs will be added to the graph definition.
15332:
1.138 matthew 15333: =back
15334:
15335: Returns:
15336:
15337: An <img> tag which references graph.png and the appropriate identifying
15338: information for the plot.
15339:
1.127 matthew 15340: =cut
15341:
15342: ############################################################
15343: ############################################################
1.134 matthew 15344: sub DrawBarGraph {
1.178 matthew 15345: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 15346: #
15347: if (! defined($colors)) {
15348: $colors = ['#33ff00',
15349: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
15350: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
15351: ];
15352: }
1.228 matthew 15353: my $extra_settings = {};
15354: if (ref($Values[-1]) eq 'HASH') {
15355: $extra_settings = pop(@Values);
15356: }
1.127 matthew 15357: #
1.136 matthew 15358: my $identifier = &get_cgi_id();
15359: my $id = 'cgi.'.$identifier;
1.129 matthew 15360: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 15361: return '';
15362: }
1.225 matthew 15363: #
15364: my @Labels;
15365: if (defined($labels)) {
15366: @Labels = @$labels;
15367: } else {
15368: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 15369: push(@Labels,$i+1);
1.225 matthew 15370: }
15371: }
15372: #
1.129 matthew 15373: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 15374: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 15375: my %ValuesHash;
15376: my $NumSets=1;
15377: foreach my $array (@Values) {
15378: next if (! ref($array));
1.136 matthew 15379: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 15380: join(',',@$array);
1.129 matthew 15381: }
1.127 matthew 15382: #
1.136 matthew 15383: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 15384: if ($NumBars < 3) {
15385: $width = 120+$NumBars*32;
1.220 matthew 15386: $xskip = 1;
1.225 matthew 15387: $bar_width = 30;
15388: } elsif ($NumBars < 5) {
15389: $width = 120+$NumBars*20;
15390: $xskip = 1;
15391: $bar_width = 20;
1.220 matthew 15392: } elsif ($NumBars < 10) {
1.136 matthew 15393: $width = 120+$NumBars*15;
15394: $xskip = 1;
15395: $bar_width = 15;
15396: } elsif ($NumBars <= 25) {
15397: $width = 120+$NumBars*11;
15398: $xskip = 5;
15399: $bar_width = 8;
15400: } elsif ($NumBars <= 50) {
15401: $width = 120+$NumBars*8;
15402: $xskip = 5;
15403: $bar_width = 4;
15404: } else {
15405: $width = 120+$NumBars*8;
15406: $xskip = 5;
15407: $bar_width = 4;
15408: }
15409: #
1.137 matthew 15410: $Max = 1 if ($Max < 1);
15411: if ( int($Max) < $Max ) {
15412: $Max++;
15413: $Max = int($Max);
15414: }
1.127 matthew 15415: $Title = '' if (! defined($Title));
15416: $xlabel = '' if (! defined($xlabel));
15417: $ylabel = '' if (! defined($ylabel));
1.369 www 15418: $ValuesHash{$id.'.title'} = &escape($Title);
15419: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
15420: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 15421: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 15422: $ValuesHash{$id.'.NumBars'} = $NumBars;
15423: $ValuesHash{$id.'.NumSets'} = $NumSets;
15424: $ValuesHash{$id.'.PlotType'} = 'bar';
15425: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15426: $ValuesHash{$id.'.height'} = $height;
15427: $ValuesHash{$id.'.width'} = $width;
15428: $ValuesHash{$id.'.xskip'} = $xskip;
15429: $ValuesHash{$id.'.bar_width'} = $bar_width;
15430: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 15431: #
1.228 matthew 15432: # Deal with other parameters
15433: while (my ($key,$value) = each(%$extra_settings)) {
15434: $ValuesHash{$id.'.'.$key} = $value;
15435: }
15436: #
1.646 raeburn 15437: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 15438: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15439: }
15440:
15441: ############################################################
15442: ############################################################
15443:
15444: =pod
15445:
1.648 raeburn 15446: =item * &DrawXYGraph()
1.137 matthew 15447:
1.138 matthew 15448: Facilitates the plotting of data in an XY graph.
15449: Puts plot definition data into the users environment in order for
15450: graph.png to plot it. Returns an <img> tag for the plot.
15451:
15452: Inputs:
15453:
15454: =over 4
15455:
15456: =item $Title: string, the title of the plot
15457:
15458: =item $xlabel: string, text describing the X-axis of the plot
15459:
15460: =item $ylabel: string, text describing the Y-axis of the plot
15461:
15462: =item $Max: scalar, the maximum Y value to use in the plot
15463: If $Max is < any data point, the graph will not be rendered.
15464:
15465: =item $colors: Array ref containing the hex color codes for the data to be
15466: plotted in. If undefined, default values will be used.
15467:
15468: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15469:
15470: =item $Ydata: Array ref containing Array refs.
1.185 www 15471: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 15472:
15473: =item %Values: hash indicating or overriding any default values which are
15474: passed to graph.png.
15475: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15476:
15477: =back
15478:
15479: Returns:
15480:
15481: An <img> tag which references graph.png and the appropriate identifying
15482: information for the plot.
15483:
1.137 matthew 15484: =cut
15485:
15486: ############################################################
15487: ############################################################
15488: sub DrawXYGraph {
15489: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
15490: #
15491: # Create the identifier for the graph
15492: my $identifier = &get_cgi_id();
15493: my $id = 'cgi.'.$identifier;
15494: #
15495: $Title = '' if (! defined($Title));
15496: $xlabel = '' if (! defined($xlabel));
15497: $ylabel = '' if (! defined($ylabel));
15498: my %ValuesHash =
15499: (
1.369 www 15500: $id.'.title' => &escape($Title),
15501: $id.'.xlabel' => &escape($xlabel),
15502: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 15503: $id.'.y_max_value'=> $Max,
15504: $id.'.labels' => join(',',@$Xlabels),
15505: $id.'.PlotType' => 'XY',
15506: );
15507: #
15508: if (defined($colors) && ref($colors) eq 'ARRAY') {
15509: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15510: }
15511: #
15512: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
15513: return '';
15514: }
15515: my $NumSets=1;
1.138 matthew 15516: foreach my $array (@{$Ydata}){
1.137 matthew 15517: next if (! ref($array));
15518: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
15519: }
1.138 matthew 15520: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 15521: #
15522: # Deal with other parameters
15523: while (my ($key,$value) = each(%Values)) {
15524: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 15525: }
15526: #
1.646 raeburn 15527: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 15528: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
15529: }
15530:
15531: ############################################################
15532: ############################################################
15533:
15534: =pod
15535:
1.648 raeburn 15536: =item * &DrawXYYGraph()
1.138 matthew 15537:
15538: Facilitates the plotting of data in an XY graph with two Y axes.
15539: Puts plot definition data into the users environment in order for
15540: graph.png to plot it. Returns an <img> tag for the plot.
15541:
15542: Inputs:
15543:
15544: =over 4
15545:
15546: =item $Title: string, the title of the plot
15547:
15548: =item $xlabel: string, text describing the X-axis of the plot
15549:
15550: =item $ylabel: string, text describing the Y-axis of the plot
15551:
15552: =item $colors: Array ref containing the hex color codes for the data to be
15553: plotted in. If undefined, default values will be used.
15554:
15555: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
15556:
15557: =item $Ydata1: The first data set
15558:
15559: =item $Min1: The minimum value of the left Y-axis
15560:
15561: =item $Max1: The maximum value of the left Y-axis
15562:
15563: =item $Ydata2: The second data set
15564:
15565: =item $Min2: The minimum value of the right Y-axis
15566:
15567: =item $Max2: The maximum value of the left Y-axis
15568:
15569: =item %Values: hash indicating or overriding any default values which are
15570: passed to graph.png.
15571: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
15572:
15573: =back
15574:
15575: Returns:
15576:
15577: An <img> tag which references graph.png and the appropriate identifying
15578: information for the plot.
1.136 matthew 15579:
15580: =cut
15581:
15582: ############################################################
15583: ############################################################
1.137 matthew 15584: sub DrawXYYGraph {
15585: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
15586: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 15587: #
15588: # Create the identifier for the graph
15589: my $identifier = &get_cgi_id();
15590: my $id = 'cgi.'.$identifier;
15591: #
15592: $Title = '' if (! defined($Title));
15593: $xlabel = '' if (! defined($xlabel));
15594: $ylabel = '' if (! defined($ylabel));
15595: my %ValuesHash =
15596: (
1.369 www 15597: $id.'.title' => &escape($Title),
15598: $id.'.xlabel' => &escape($xlabel),
15599: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 15600: $id.'.labels' => join(',',@$Xlabels),
15601: $id.'.PlotType' => 'XY',
15602: $id.'.NumSets' => 2,
1.137 matthew 15603: $id.'.two_axes' => 1,
15604: $id.'.y1_max_value' => $Max1,
15605: $id.'.y1_min_value' => $Min1,
15606: $id.'.y2_max_value' => $Max2,
15607: $id.'.y2_min_value' => $Min2,
1.136 matthew 15608: );
15609: #
1.137 matthew 15610: if (defined($colors) && ref($colors) eq 'ARRAY') {
15611: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
15612: }
15613: #
15614: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
15615: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 15616: return '';
15617: }
15618: my $NumSets=1;
1.137 matthew 15619: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 15620: next if (! ref($array));
15621: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 15622: }
15623: #
15624: # Deal with other parameters
15625: while (my ($key,$value) = each(%Values)) {
15626: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 15627: }
15628: #
1.646 raeburn 15629: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 15630: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 15631: }
15632:
15633: ############################################################
15634: ############################################################
15635:
15636: =pod
15637:
1.157 matthew 15638: =back
15639:
1.139 matthew 15640: =head1 Statistics helper routines?
15641:
15642: Bad place for them but what the hell.
15643:
1.157 matthew 15644: =over 4
15645:
1.648 raeburn 15646: =item * &chartlink()
1.139 matthew 15647:
15648: Returns a link to the chart for a specific student.
15649:
15650: Inputs:
15651:
15652: =over 4
15653:
15654: =item $linktext: The text of the link
15655:
15656: =item $sname: The students username
15657:
15658: =item $sdomain: The students domain
15659:
15660: =back
15661:
1.157 matthew 15662: =back
15663:
1.139 matthew 15664: =cut
15665:
15666: ############################################################
15667: ############################################################
15668: sub chartlink {
15669: my ($linktext, $sname, $sdomain) = @_;
15670: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 15671: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 15672: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 15673: '">'.$linktext.'</a>';
1.153 matthew 15674: }
15675:
15676: #######################################################
15677: #######################################################
15678:
15679: =pod
15680:
15681: =head1 Course Environment Routines
1.157 matthew 15682:
15683: =over 4
1.153 matthew 15684:
1.648 raeburn 15685: =item * &restore_course_settings()
1.153 matthew 15686:
1.648 raeburn 15687: =item * &store_course_settings()
1.153 matthew 15688:
15689: Restores/Store indicated form parameters from the course environment.
15690: Will not overwrite existing values of the form parameters.
15691:
15692: Inputs:
15693: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15694:
15695: a hash ref describing the data to be stored. For example:
15696:
15697: %Save_Parameters = ('Status' => 'scalar',
15698: 'chartoutputmode' => 'scalar',
15699: 'chartoutputdata' => 'scalar',
15700: 'Section' => 'array',
1.373 raeburn 15701: 'Group' => 'array',
1.153 matthew 15702: 'StudentData' => 'array',
15703: 'Maps' => 'array');
15704:
15705: Returns: both routines return nothing
15706:
1.631 raeburn 15707: =back
15708:
1.153 matthew 15709: =cut
15710:
15711: #######################################################
15712: #######################################################
15713: sub store_course_settings {
1.496 albertel 15714: return &store_settings($env{'request.course.id'},@_);
15715: }
15716:
15717: sub store_settings {
1.153 matthew 15718: # save to the environment
15719: # appenv the same items, just to be safe
1.300 albertel 15720: my $udom = $env{'user.domain'};
15721: my $uname = $env{'user.name'};
1.496 albertel 15722: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15723: my %SaveHash;
15724: my %AppHash;
15725: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15726: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15727: my $envname = 'environment.'.$basename;
1.258 albertel 15728: if (exists($env{'form.'.$setting})) {
1.153 matthew 15729: # Save this value away
15730: if ($type eq 'scalar' &&
1.258 albertel 15731: (! exists($env{$envname}) ||
15732: $env{$envname} ne $env{'form.'.$setting})) {
15733: $SaveHash{$basename} = $env{'form.'.$setting};
15734: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15735: } elsif ($type eq 'array') {
15736: my $stored_form;
1.258 albertel 15737: if (ref($env{'form.'.$setting})) {
1.153 matthew 15738: $stored_form = join(',',
15739: map {
1.369 www 15740: &escape($_);
1.258 albertel 15741: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15742: } else {
15743: $stored_form =
1.369 www 15744: &escape($env{'form.'.$setting});
1.153 matthew 15745: }
15746: # Determine if the array contents are the same.
1.258 albertel 15747: if ($stored_form ne $env{$envname}) {
1.153 matthew 15748: $SaveHash{$basename} = $stored_form;
15749: $AppHash{$envname} = $stored_form;
15750: }
15751: }
15752: }
15753: }
15754: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15755: $udom,$uname);
1.153 matthew 15756: if ($put_result !~ /^(ok|delayed)/) {
15757: &Apache::lonnet::logthis('unable to save form parameters, '.
15758: 'got error:'.$put_result);
15759: }
15760: # Make sure these settings stick around in this session, too
1.646 raeburn 15761: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15762: return;
15763: }
15764:
15765: sub restore_course_settings {
1.499 albertel 15766: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15767: }
15768:
15769: sub restore_settings {
15770: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15771: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15772: next if (exists($env{'form.'.$setting}));
1.496 albertel 15773: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15774: '.'.$setting;
1.258 albertel 15775: if (exists($env{$envname})) {
1.153 matthew 15776: if ($type eq 'scalar') {
1.258 albertel 15777: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15778: } elsif ($type eq 'array') {
1.258 albertel 15779: $env{'form.'.$setting} = [
1.153 matthew 15780: map {
1.369 www 15781: &unescape($_);
1.258 albertel 15782: } split(',',$env{$envname})
1.153 matthew 15783: ];
15784: }
15785: }
15786: }
1.127 matthew 15787: }
15788:
1.618 raeburn 15789: #######################################################
15790: #######################################################
15791:
15792: =pod
15793:
15794: =head1 Domain E-mail Routines
15795:
15796: =over 4
15797:
1.648 raeburn 15798: =item * &build_recipient_list()
1.618 raeburn 15799:
1.1144 raeburn 15800: Build recipient lists for following types of e-mail:
1.766 raeburn 15801: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 15802: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15803: module change checking, student/employee ID conflict checks, as
15804: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15805: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15806:
15807: Inputs:
1.619 raeburn 15808: defmail (scalar - email address of default recipient),
1.1144 raeburn 15809: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15810: requestsmail, updatesmail, or idconflictsmail).
15811:
1.619 raeburn 15812: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 15813:
1.619 raeburn 15814: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 15815: i.e., predates configuration by DC via domainprefs.pm
15816:
15817: $requname username of requester (if mailing type is helpdeskmail)
15818:
15819: $requdom domain of requester (if mailing type is helpdeskmail)
15820:
15821: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15822:
1.618 raeburn 15823:
1.655 raeburn 15824: Returns: comma separated list of addresses to which to send e-mail.
15825:
15826: =back
1.618 raeburn 15827:
15828: =cut
15829:
15830: ############################################################
15831: ############################################################
15832: sub build_recipient_list {
1.1297 raeburn 15833: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15834: my @recipients;
1.1270 raeburn 15835: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15836: my %domconfig =
1.1270 raeburn 15837: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15838: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15839: if (exists($domconfig{'contacts'}{$mailing})) {
15840: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15841: my @contacts = ('adminemail','supportemail');
15842: foreach my $item (@contacts) {
15843: if ($domconfig{'contacts'}{$mailing}{$item}) {
15844: my $addr = $domconfig{'contacts'}{$item};
15845: if (!grep(/^\Q$addr\E$/,@recipients)) {
15846: push(@recipients,$addr);
15847: }
1.619 raeburn 15848: }
1.1270 raeburn 15849: }
15850: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15851: if ($mailing eq 'helpdeskmail') {
15852: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15853: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15854: my @ok_bccs;
15855: foreach my $bcc (@bccs) {
15856: $bcc =~ s/^\s+//g;
15857: $bcc =~ s/\s+$//g;
15858: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15859: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15860: push(@ok_bccs,$bcc);
15861: }
15862: }
15863: }
15864: if (@ok_bccs > 0) {
15865: $allbcc = join(', ',@ok_bccs);
15866: }
15867: }
15868: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15869: }
15870: }
1.766 raeburn 15871: } elsif ($origmail ne '') {
1.1270 raeburn 15872: $lastresort = $origmail;
1.618 raeburn 15873: }
1.1297 raeburn 15874: if ($mailing eq 'helpdeskmail') {
15875: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15876: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15877: my ($inststatus,$inststatus_checked);
15878: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15879: ($env{'user.domain'} ne 'public')) {
15880: $inststatus_checked = 1;
15881: $inststatus = $env{'environment.inststatus'};
15882: }
15883: unless ($inststatus_checked) {
15884: if (($requname ne '') && ($requdom ne '')) {
15885: if (($requname =~ /^$match_username$/) &&
15886: ($requdom =~ /^$match_domain$/) &&
15887: (&Apache::lonnet::domain($requdom))) {
15888: my $requhome = &Apache::lonnet::homeserver($requname,
15889: $requdom);
15890: unless ($requhome eq 'no_host') {
15891: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15892: $inststatus = $userenv{'inststatus'};
15893: $inststatus_checked = 1;
15894: }
15895: }
15896: }
15897: }
15898: unless ($inststatus_checked) {
15899: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15900: my %srch = (srchby => 'email',
15901: srchdomain => $defdom,
15902: srchterm => $reqemail,
15903: srchtype => 'exact');
15904: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15905: foreach my $uname (keys(%srch_results)) {
15906: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15907: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15908: $inststatus_checked = 1;
15909: last;
15910: }
15911: }
15912: unless ($inststatus_checked) {
15913: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15914: if ($dirsrchres eq 'ok') {
15915: foreach my $uname (keys(%srch_results)) {
15916: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15917: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15918: $inststatus_checked = 1;
15919: last;
15920: }
15921: }
15922: }
15923: }
15924: }
15925: }
15926: if ($inststatus ne '') {
15927: foreach my $status (split(/\:/,$inststatus)) {
15928: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15929: my @contacts = ('adminemail','supportemail');
15930: foreach my $item (@contacts) {
15931: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15932: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15933: if (!grep(/^\Q$addr\E$/,@recipients)) {
15934: push(@recipients,$addr);
15935: }
15936: }
15937: }
15938: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15939: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15940: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15941: my @ok_bccs;
15942: foreach my $bcc (@bccs) {
15943: $bcc =~ s/^\s+//g;
15944: $bcc =~ s/\s+$//g;
15945: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15946: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15947: push(@ok_bccs,$bcc);
15948: }
15949: }
15950: }
15951: if (@ok_bccs > 0) {
15952: $allbcc = join(', ',@ok_bccs);
15953: }
15954: }
15955: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15956: last;
15957: }
15958: }
15959: }
15960: }
15961: }
1.619 raeburn 15962: } elsif ($origmail ne '') {
1.1270 raeburn 15963: $lastresort = $origmail;
15964: }
1.1297 raeburn 15965: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15966: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15967: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15968: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15969: my %what = (
15970: perlvar => 1,
15971: );
15972: my $primary = &Apache::lonnet::domain($defdom,'primary');
15973: if ($primary) {
15974: my $gotaddr;
15975: my ($result,$returnhash) =
15976: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15977: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15978: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15979: $lastresort = $returnhash->{'lonSupportEMail'};
15980: $gotaddr = 1;
15981: }
15982: }
15983: unless ($gotaddr) {
15984: my $uintdom = &Apache::lonnet::internet_dom($primary);
15985: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15986: unless ($uintdom eq $intdom) {
15987: my %domconfig =
15988: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15989: if (ref($domconfig{'contacts'}) eq 'HASH') {
15990: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15991: my @contacts = ('adminemail','supportemail');
15992: foreach my $item (@contacts) {
15993: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15994: my $addr = $domconfig{'contacts'}{$item};
15995: if (!grep(/^\Q$addr\E$/,@recipients)) {
15996: push(@recipients,$addr);
15997: }
15998: }
15999: }
16000: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
16001: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
16002: }
16003: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
16004: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
16005: my @ok_bccs;
16006: foreach my $bcc (@bccs) {
16007: $bcc =~ s/^\s+//g;
16008: $bcc =~ s/\s+$//g;
16009: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
16010: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
16011: push(@ok_bccs,$bcc);
16012: }
16013: }
16014: }
16015: if (@ok_bccs > 0) {
16016: $allbcc = join(', ',@ok_bccs);
16017: }
16018: }
16019: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
16020: }
16021: }
16022: }
16023: }
16024: }
16025: }
1.618 raeburn 16026: }
1.688 raeburn 16027: if (defined($defmail)) {
16028: if ($defmail ne '') {
16029: push(@recipients,$defmail);
16030: }
1.618 raeburn 16031: }
16032: if ($otheremails) {
1.619 raeburn 16033: my @others;
16034: if ($otheremails =~ /,/) {
16035: @others = split(/,/,$otheremails);
1.618 raeburn 16036: } else {
1.619 raeburn 16037: push(@others,$otheremails);
16038: }
16039: foreach my $addr (@others) {
16040: if (!grep(/^\Q$addr\E$/,@recipients)) {
16041: push(@recipients,$addr);
16042: }
1.618 raeburn 16043: }
16044: }
1.1298 raeburn 16045: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 16046: if ((!@recipients) && ($lastresort ne '')) {
16047: push(@recipients,$lastresort);
16048: }
16049: } elsif ($lastresort ne '') {
16050: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
16051: push(@recipients,$lastresort);
16052: }
16053: }
1.1271 raeburn 16054: my $recipientlist = join(',',@recipients);
1.1270 raeburn 16055: if (wantarray) {
16056: return ($recipientlist,$allbcc,$addtext);
16057: } else {
16058: return $recipientlist;
16059: }
1.618 raeburn 16060: }
16061:
1.127 matthew 16062: ############################################################
16063: ############################################################
1.154 albertel 16064:
1.655 raeburn 16065: =pod
16066:
1.1224 musolffc 16067: =over 4
16068:
1.1223 musolffc 16069: =item * &mime_email()
16070:
16071: Sends an email with a possible attachment
16072:
16073: Inputs:
16074:
16075: =over 4
16076:
16077: from - Sender's email address
16078:
1.1343 raeburn 16079: replyto - Reply-To email address
16080:
1.1223 musolffc 16081: to - Email address of recipient
16082:
16083: subject - Subject of email
16084:
16085: body - Body of email
16086:
16087: cc_string - Carbon copy email address
16088:
16089: bcc - Blind carbon copy email address
16090:
16091: attachment_path - Path of file to be attached
16092:
16093: file_name - Name of file to be attached
16094:
16095: attachment_text - The body of an attachment of type "TEXT"
16096:
16097: =back
16098:
16099: =back
16100:
16101: =cut
16102:
16103: ############################################################
16104: ############################################################
16105:
16106: sub mime_email {
1.1343 raeburn 16107: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
16108: $file_name,$attachment_text) = @_;
16109:
1.1223 musolffc 16110: my $msg = MIME::Lite->new(
16111: From => $from,
16112: To => $to,
16113: Subject => $subject,
16114: Type =>'TEXT',
16115: Data => $body,
16116: );
1.1343 raeburn 16117: if ($replyto ne '') {
16118: $msg->add("Reply-To" => $replyto);
16119: }
1.1223 musolffc 16120: if ($cc_string ne '') {
16121: $msg->add("Cc" => $cc_string);
16122: }
16123: if ($bcc ne '') {
16124: $msg->add("Bcc" => $bcc);
16125: }
16126: $msg->attr("content-type" => "text/plain");
16127: $msg->attr("content-type.charset" => "UTF-8");
16128: # Attach file if given
16129: if ($attachment_path) {
16130: unless ($file_name) {
16131: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
16132: }
16133: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
16134: $msg->attach(Type => $type,
16135: Path => $attachment_path,
16136: Filename => $file_name
16137: );
16138: # Otherwise attach text if given
16139: } elsif ($attachment_text) {
16140: $msg->attach(Type => 'TEXT',
16141: Data => $attachment_text);
16142: }
16143: # Send it
16144: $msg->send('sendmail');
16145: }
16146:
16147: ############################################################
16148: ############################################################
16149:
16150: =pod
16151:
1.655 raeburn 16152: =head1 Course Catalog Routines
16153:
16154: =over 4
16155:
16156: =item * &gather_categories()
16157:
16158: Converts category definitions - keys of categories hash stored in
16159: coursecategories in configuration.db on the primary library server in a
16160: domain - to an array. Also generates javascript and idx hash used to
16161: generate Domain Coordinator interface for editing Course Categories.
16162:
16163: Inputs:
1.663 raeburn 16164:
1.655 raeburn 16165: categories (reference to hash of category definitions).
1.663 raeburn 16166:
1.655 raeburn 16167: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16168: categories and subcategories).
1.663 raeburn 16169:
1.655 raeburn 16170: idx (reference to hash of counters used in Domain Coordinator interface for
16171: editing Course Categories).
1.663 raeburn 16172:
1.655 raeburn 16173: jsarray (reference to array of categories used to create Javascript arrays for
16174: Domain Coordinator interface for editing Course Categories).
16175:
16176: Returns: nothing
16177:
16178: Side effects: populates cats, idx and jsarray.
16179:
16180: =cut
16181:
16182: sub gather_categories {
16183: my ($categories,$cats,$idx,$jsarray) = @_;
16184: my %counters;
16185: my $num = 0;
16186: foreach my $item (keys(%{$categories})) {
16187: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16188: if ($container eq '' && $depth == 0) {
16189: $cats->[$depth][$categories->{$item}] = $cat;
16190: } else {
16191: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
16192: }
16193: my ($escitem,$tail) = split(/:/,$item,2);
16194: if ($counters{$tail} eq '') {
16195: $counters{$tail} = $num;
16196: $num ++;
16197: }
16198: if (ref($idx) eq 'HASH') {
16199: $idx->{$item} = $counters{$tail};
16200: }
16201: if (ref($jsarray) eq 'ARRAY') {
16202: push(@{$jsarray->[$counters{$tail}]},$item);
16203: }
16204: }
16205: return;
16206: }
16207:
16208: =pod
16209:
16210: =item * &extract_categories()
16211:
16212: Used to generate breadcrumb trails for course categories.
16213:
16214: Inputs:
1.663 raeburn 16215:
1.655 raeburn 16216: categories (reference to hash of category definitions).
1.663 raeburn 16217:
1.655 raeburn 16218: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16219: categories and subcategories).
1.663 raeburn 16220:
1.655 raeburn 16221: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 16222:
1.655 raeburn 16223: allitems (reference to hash - key is category key
16224: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16225:
1.655 raeburn 16226: idx (reference to hash of counters used in Domain Coordinator interface for
16227: editing Course Categories).
1.663 raeburn 16228:
1.655 raeburn 16229: jsarray (reference to array of categories used to create Javascript arrays for
16230: Domain Coordinator interface for editing Course Categories).
16231:
1.665 raeburn 16232: subcats (reference to hash of arrays containing all subcategories within each
16233: category, -recursive)
16234:
1.1321 raeburn 16235: maxd (reference to hash used to hold max depth for all top-level categories).
16236:
1.655 raeburn 16237: Returns: nothing
16238:
16239: Side effects: populates trails and allitems hash references.
16240:
16241: =cut
16242:
16243: sub extract_categories {
1.1321 raeburn 16244: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 16245: if (ref($categories) eq 'HASH') {
16246: &gather_categories($categories,$cats,$idx,$jsarray);
16247: if (ref($cats->[0]) eq 'ARRAY') {
16248: for (my $i=0; $i<@{$cats->[0]}; $i++) {
16249: my $name = $cats->[0][$i];
16250: my $item = &escape($name).'::0';
16251: my $trailstr;
16252: if ($name eq 'instcode') {
16253: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 16254: } elsif ($name eq 'communities') {
16255: $trailstr = &mt('Communities');
1.1239 raeburn 16256: } elsif ($name eq 'placement') {
16257: $trailstr = &mt('Placement Tests');
1.655 raeburn 16258: } else {
16259: $trailstr = $name;
16260: }
16261: if ($allitems->{$item} eq '') {
16262: push(@{$trails},$trailstr);
16263: $allitems->{$item} = scalar(@{$trails})-1;
16264: }
16265: my @parents = ($name);
16266: if (ref($cats->[1]{$name}) eq 'ARRAY') {
16267: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
16268: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 16269: if (ref($subcats) eq 'HASH') {
16270: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
16271: }
1.1321 raeburn 16272: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 16273: }
16274: } else {
16275: if (ref($subcats) eq 'HASH') {
16276: $subcats->{$item} = [];
1.655 raeburn 16277: }
1.1321 raeburn 16278: if (ref($maxd) eq 'HASH') {
16279: $maxd->{$name} = 1;
16280: }
1.655 raeburn 16281: }
16282: }
16283: }
16284: }
16285: return;
16286: }
16287:
16288: =pod
16289:
1.1162 raeburn 16290: =item * &recurse_categories()
1.655 raeburn 16291:
16292: Recursively used to generate breadcrumb trails for course categories.
16293:
16294: Inputs:
1.663 raeburn 16295:
1.655 raeburn 16296: cats (reference to array of arrays/hashes which encapsulates hierarchy of
16297: categories and subcategories).
1.663 raeburn 16298:
1.655 raeburn 16299: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 16300:
16301: category (current course category, for which breadcrumb trail is being generated).
16302:
16303: trails (reference to array of breadcrumb trails for each category).
16304:
1.655 raeburn 16305: allitems (reference to hash - key is category key
16306: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 16307:
1.655 raeburn 16308: parents (array containing containers directories for current category,
16309: back to top level).
16310:
16311: Returns: nothing
16312:
16313: Side effects: populates trails and allitems hash references
16314:
16315: =cut
16316:
16317: sub recurse_categories {
1.1321 raeburn 16318: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 16319: my $shallower = $depth - 1;
16320: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
16321: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
16322: my $name = $cats->[$depth]{$category}[$k];
16323: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16324: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16325: if ($allitems->{$item} eq '') {
16326: push(@{$trails},$trailstr);
16327: $allitems->{$item} = scalar(@{$trails})-1;
16328: }
16329: my $deeper = $depth+1;
16330: push(@{$parents},$category);
1.665 raeburn 16331: if (ref($subcats) eq 'HASH') {
16332: my $subcat = &escape($name).':'.$category.':'.$depth;
16333: for (my $j=@{$parents}; $j>=0; $j--) {
16334: my $higher;
16335: if ($j > 0) {
16336: $higher = &escape($parents->[$j]).':'.
16337: &escape($parents->[$j-1]).':'.$j;
16338: } else {
16339: $higher = &escape($parents->[$j]).'::'.$j;
16340: }
16341: push(@{$subcats->{$higher}},$subcat);
16342: }
16343: }
16344: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 16345: $subcats,$maxd);
1.655 raeburn 16346: pop(@{$parents});
16347: }
16348: } else {
16349: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 16350: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 16351: if ($allitems->{$item} eq '') {
16352: push(@{$trails},$trailstr);
16353: $allitems->{$item} = scalar(@{$trails})-1;
16354: }
1.1321 raeburn 16355: if (ref($maxd) eq 'HASH') {
16356: if ($depth > $maxd->{$parents->[0]}) {
16357: $maxd->{$parents->[0]} = $depth;
16358: }
16359: }
1.655 raeburn 16360: }
16361: return;
16362: }
16363:
1.663 raeburn 16364: =pod
16365:
1.1162 raeburn 16366: =item * &assign_categories_table()
1.663 raeburn 16367:
16368: Create a datatable for display of hierarchical categories in a domain,
16369: with checkboxes to allow a course to be categorized.
16370:
16371: Inputs:
16372:
16373: cathash - reference to hash of categories defined for the domain (from
16374: configuration.db)
16375:
16376: currcat - scalar with an & separated list of categories assigned to a course.
16377:
1.919 raeburn 16378: type - scalar contains course type (Course or Community).
16379:
1.1260 raeburn 16380: disabled - scalar (optional) contains disabled="disabled" if input elements are
16381: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16382:
1.663 raeburn 16383: Returns: $output (markup to be displayed)
16384:
16385: =cut
16386:
16387: sub assign_categories_table {
1.1259 raeburn 16388: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 16389: my $output;
16390: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 16391: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
16392: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 16393: $maxdepth = scalar(@cats);
16394: if (@cats > 0) {
16395: my $itemcount = 0;
16396: if (ref($cats[0]) eq 'ARRAY') {
16397: my @currcategories;
16398: if ($currcat ne '') {
16399: @currcategories = split('&',$currcat);
16400: }
1.919 raeburn 16401: my $table;
1.663 raeburn 16402: for (my $i=0; $i<@{$cats[0]}; $i++) {
16403: my $parent = $cats[0][$i];
1.919 raeburn 16404: next if ($parent eq 'instcode');
16405: if ($type eq 'Community') {
16406: next unless ($parent eq 'communities');
1.1239 raeburn 16407: } elsif ($type eq 'Placement') {
16408: next unless ($parent eq 'placement');
1.919 raeburn 16409: } else {
1.1239 raeburn 16410: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 16411: }
1.663 raeburn 16412: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
16413: my $item = &escape($parent).'::0';
16414: my $checked = '';
16415: if (@currcategories > 0) {
16416: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 16417: $checked = ' checked="checked"';
1.663 raeburn 16418: }
16419: }
1.919 raeburn 16420: my $parent_title = $parent;
16421: if ($parent eq 'communities') {
16422: $parent_title = &mt('Communities');
1.1239 raeburn 16423: } elsif ($parent eq 'placement') {
16424: $parent_title = &mt('Placement Tests');
1.919 raeburn 16425: }
16426: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
16427: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16428: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 16429: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 16430: my $depth = 1;
16431: push(@path,$parent);
1.1259 raeburn 16432: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 16433: pop(@path);
1.919 raeburn 16434: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 16435: $itemcount ++;
16436: }
1.919 raeburn 16437: if ($itemcount) {
16438: $output = &Apache::loncommon::start_data_table().
16439: $table.
16440: &Apache::loncommon::end_data_table();
16441: }
1.663 raeburn 16442: }
16443: }
16444: }
16445: return $output;
16446: }
16447:
16448: =pod
16449:
1.1162 raeburn 16450: =item * &assign_category_rows()
1.663 raeburn 16451:
16452: Create a datatable row for display of nested categories in a domain,
16453: with checkboxes to allow a course to be categorized,called recursively.
16454:
16455: Inputs:
16456:
16457: itemcount - track row number for alternating colors
16458:
16459: cats - reference to array of arrays/hashes which encapsulates hierarchy of
16460: categories and subcategories.
16461:
16462: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
16463:
16464: parent - parent of current category item
16465:
16466: path - Array containing all categories back up through the hierarchy from the
16467: current category to the top level.
16468:
16469: currcategories - reference to array of current categories assigned to the course
16470:
1.1260 raeburn 16471: disabled - scalar (optional) contains disabled="disabled" if input elements are
16472: to be readonly (e.g., Domain Helpdesk role viewing course settings).
16473:
1.663 raeburn 16474: Returns: $output (markup to be displayed).
16475:
16476: =cut
16477:
16478: sub assign_category_rows {
1.1259 raeburn 16479: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 16480: my ($text,$name,$item,$chgstr);
16481: if (ref($cats) eq 'ARRAY') {
16482: my $maxdepth = scalar(@{$cats});
16483: if (ref($cats->[$depth]) eq 'HASH') {
16484: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
16485: my $numchildren = @{$cats->[$depth]{$parent}};
16486: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 16487: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 16488: for (my $j=0; $j<$numchildren; $j++) {
16489: $name = $cats->[$depth]{$parent}[$j];
16490: $item = &escape($name).':'.&escape($parent).':'.$depth;
16491: my $deeper = $depth+1;
16492: my $checked = '';
16493: if (ref($currcategories) eq 'ARRAY') {
16494: if (@{$currcategories} > 0) {
16495: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 16496: $checked = ' checked="checked"';
1.663 raeburn 16497: }
16498: }
16499: }
1.664 raeburn 16500: $text .= '<tr><td><span class="LC_nobreak"><label>'.
16501: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 16502: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 16503: '<input type="hidden" name="catname" value="'.$name.'" />'.
16504: '</td><td>';
1.663 raeburn 16505: if (ref($path) eq 'ARRAY') {
16506: push(@{$path},$name);
1.1259 raeburn 16507: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 16508: pop(@{$path});
16509: }
16510: $text .= '</td></tr>';
16511: }
16512: $text .= '</table></td>';
16513: }
16514: }
16515: }
16516: return $text;
16517: }
16518:
1.1181 raeburn 16519: =pod
16520:
16521: =back
16522:
16523: =cut
16524:
1.655 raeburn 16525: ############################################################
16526: ############################################################
16527:
16528:
1.443 albertel 16529: sub commit_customrole {
1.664 raeburn 16530: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.1399 raeburn 16531: my $result = &Apache::lonnet::assigncustomrole(
16532: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context);
1.630 raeburn 16533: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 16534: ($start?', '.&mt('starting').' '.localtime($start):'').
1.1399 raeburn 16535: ($end?', ending '.localtime($end):'').': <b>'.$result.'</b><br />';
16536: if (wantarray) {
16537: return ($output,$result);
16538: } else {
16539: return $output;
16540: }
1.443 albertel 16541: }
16542:
16543: sub commit_standardrole {
1.1116 raeburn 16544: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.1399 raeburn 16545: my ($output,$logmsg,$linefeed,$result);
1.541 raeburn 16546: if ($context eq 'auto') {
16547: $linefeed = "\n";
16548: } else {
16549: $linefeed = "<br />\n";
16550: }
1.443 albertel 16551: if ($three eq 'st') {
1.1399 raeburn 16552: $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
16553: $one,$two,$sec,$context,$credits);
1.541 raeburn 16554: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 16555: ($result eq 'unknown_course') || ($result eq 'refused')) {
16556: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 16557: } else {
1.541 raeburn 16558: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 16559: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16560: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
16561: if ($context eq 'auto') {
16562: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
16563: } else {
16564: $output .= '<b>'.$result.'</b>'.$linefeed.
16565: &mt('Add to classlist').': <b>ok</b>';
16566: }
16567: $output .= $linefeed;
1.443 albertel 16568: }
16569: } else {
16570: $output = &mt('Assigning').' '.$three.' in '.$url.
16571: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 16572: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.1399 raeburn 16573: $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 16574: if ($context eq 'auto') {
16575: $output .= $result.$linefeed;
16576: } else {
16577: $output .= '<b>'.$result.'</b>'.$linefeed;
16578: }
1.443 albertel 16579: }
1.1399 raeburn 16580: if (wantarray) {
16581: return ($output,$result);
16582: } else {
16583: return $output;
16584: }
1.443 albertel 16585: }
16586:
16587: sub commit_studentrole {
1.1116 raeburn 16588: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
16589: $credits) = @_;
1.626 raeburn 16590: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 16591: if ($context eq 'auto') {
16592: $linefeed = "\n";
16593: } else {
16594: $linefeed = '<br />'."\n";
16595: }
1.443 albertel 16596: if (defined($one) && defined($two)) {
16597: my $cid=$one.'_'.$two;
16598: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
16599: my $secchange = 0;
16600: my $expire_role_result;
16601: my $modify_section_result;
1.628 raeburn 16602: if ($oldsec ne '-1') {
16603: if ($oldsec ne $sec) {
1.443 albertel 16604: $secchange = 1;
1.628 raeburn 16605: my $now = time;
1.443 albertel 16606: my $uurl='/'.$cid;
16607: $uurl=~s/\_/\//g;
16608: if ($oldsec) {
16609: $uurl.='/'.$oldsec;
16610: }
1.626 raeburn 16611: $oldsecurl = $uurl;
1.628 raeburn 16612: $expire_role_result =
1.1398 raeburn 16613: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','','',$context);
1.628 raeburn 16614: if ($env{'request.course.sec'} ne '') {
16615: if ($expire_role_result eq 'refused') {
16616: my @roles = ('st');
16617: my @statuses = ('previous');
16618: my @roledoms = ($one);
16619: my $withsec = 1;
16620: my %roleshash =
16621: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
16622: \@statuses,\@roles,\@roledoms,$withsec);
16623: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
16624: my ($oldstart,$oldend) =
16625: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
16626: if ($oldend > 0 && $oldend <= $now) {
16627: $expire_role_result = 'ok';
16628: }
16629: }
16630: }
16631: }
1.443 albertel 16632: $result = $expire_role_result;
16633: }
16634: }
16635: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 16636: $modify_section_result =
16637: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
16638: undef,undef,undef,$sec,
16639: $end,$start,'','',$cid,
16640: '',$context,$credits);
1.443 albertel 16641: if ($modify_section_result =~ /^ok/) {
16642: if ($secchange == 1) {
1.628 raeburn 16643: if ($sec eq '') {
16644: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
16645: } else {
16646: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
16647: }
1.443 albertel 16648: } elsif ($oldsec eq '-1') {
1.628 raeburn 16649: if ($sec eq '') {
16650: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
16651: } else {
16652: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16653: }
1.443 albertel 16654: } else {
1.628 raeburn 16655: if ($sec eq '') {
16656: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
16657: } else {
16658: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
16659: }
1.443 albertel 16660: }
16661: } else {
1.1115 raeburn 16662: if ($secchange) {
1.628 raeburn 16663: $$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;
16664: } else {
16665: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
16666: }
1.443 albertel 16667: }
16668: $result = $modify_section_result;
16669: } elsif ($secchange == 1) {
1.628 raeburn 16670: if ($oldsec eq '') {
1.1103 raeburn 16671: $$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 16672: } else {
16673: $$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;
16674: }
1.626 raeburn 16675: if ($expire_role_result eq 'refused') {
16676: my $newsecurl = '/'.$cid;
16677: $newsecurl =~ s/\_/\//g;
16678: if ($sec ne '') {
16679: $newsecurl.='/'.$sec;
16680: }
16681: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
16682: if ($sec eq '') {
16683: $$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;
16684: } else {
16685: $$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;
16686: }
16687: }
16688: }
1.443 albertel 16689: }
16690: } else {
1.626 raeburn 16691: $$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 16692: $result = "error: incomplete course id\n";
16693: }
16694: return $result;
16695: }
16696:
1.1108 raeburn 16697: sub show_role_extent {
16698: my ($scope,$context,$role) = @_;
16699: $scope =~ s{^/}{};
16700: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
16701: push(@courseroles,'co');
16702: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
16703: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
16704: $scope =~ s{/}{_};
16705: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
16706: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
16707: my ($audom,$auname) = split(/\//,$scope);
16708: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
16709: &Apache::loncommon::plainname($auname,$audom).'</span>');
16710: } else {
16711: $scope =~ s{/$}{};
16712: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
16713: &Apache::lonnet::domain($scope,'description').'</span>');
16714: }
16715: }
16716:
1.443 albertel 16717: ############################################################
16718: ############################################################
16719:
1.566 albertel 16720: sub check_clone {
1.578 raeburn 16721: my ($args,$linefeed) = @_;
1.566 albertel 16722: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
16723: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
16724: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 16725: my $clonetitle;
16726: my @clonemsg;
1.566 albertel 16727: my $can_clone = 0;
1.944 raeburn 16728: my $lctype = lc($args->{'crstype'});
1.908 raeburn 16729: if ($lctype ne 'community') {
16730: $lctype = 'course';
16731: }
1.566 albertel 16732: if ($clonehome eq 'no_host') {
1.944 raeburn 16733: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16734: push(@clonemsg,({
16735: mt => 'No new community created.',
16736: args => [],
16737: },
16738: {
16739: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16740: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16741: }));
1.908 raeburn 16742: } else {
1.1344 raeburn 16743: push(@clonemsg,({
16744: mt => 'No new course created.',
16745: args => [],
16746: },
16747: {
16748: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16749: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16750: }));
16751: }
1.566 albertel 16752: } else {
16753: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 16754: $clonetitle = $clonedesc{'description'};
1.944 raeburn 16755: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16756: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 16757: push(@clonemsg,({
16758: mt => 'No new community created.',
16759: args => [],
16760: },
16761: {
16762: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16763: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16764: }));
16765: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16766: }
16767: }
1.1262 raeburn 16768: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16769: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16770: $can_clone = 1;
16771: } else {
1.1221 raeburn 16772: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16773: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 16774: if ($clonehash{'cloners'} eq '') {
16775: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16776: if ($domdefs{'canclone'}) {
16777: unless ($domdefs{'canclone'} eq 'none') {
16778: if ($domdefs{'canclone'} eq 'domain') {
16779: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16780: $can_clone = 1;
16781: }
16782: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16783: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16784: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16785: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16786: $can_clone = 1;
16787: }
16788: }
16789: }
16790: }
1.578 raeburn 16791: } else {
1.1221 raeburn 16792: my @cloners = split(/,/,$clonehash{'cloners'});
16793: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16794: $can_clone = 1;
1.1221 raeburn 16795: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16796: $can_clone = 1;
1.1225 raeburn 16797: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16798: $can_clone = 1;
1.1221 raeburn 16799: }
16800: unless ($can_clone) {
1.1225 raeburn 16801: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16802: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 16803: my (%gotdomdefaults,%gotcodedefaults);
16804: foreach my $cloner (@cloners) {
16805: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16806: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16807: my (%codedefaults,@code_order);
16808: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16809: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16810: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16811: }
16812: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16813: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16814: }
16815: } else {
16816: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16817: \%codedefaults,
16818: \@code_order);
16819: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16820: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16821: }
16822: if (@code_order > 0) {
16823: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16824: $cloner,$clonehash{'internal.coursecode'},
16825: $args->{'crscode'})) {
16826: $can_clone = 1;
16827: last;
16828: }
16829: }
16830: }
16831: }
16832: }
1.1225 raeburn 16833: }
16834: }
16835: unless ($can_clone) {
16836: my $ccrole = 'cc';
16837: if ($args->{'crstype'} eq 'Community') {
16838: $ccrole = 'co';
16839: }
16840: my %roleshash =
16841: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16842: $args->{'ccdomain'},
16843: 'userroles',['active'],[$ccrole],
16844: [$args->{'clonedomain'}]);
16845: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16846: $can_clone = 1;
16847: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16848: $args->{'ccuname'},$args->{'ccdomain'})) {
16849: $can_clone = 1;
1.1221 raeburn 16850: }
16851: }
16852: unless ($can_clone) {
16853: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16854: push(@clonemsg,({
16855: mt => 'No new community created.',
16856: args => [],
16857: },
16858: {
16859: 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]).',
16860: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16861: }));
1.942 raeburn 16862: } else {
1.1344 raeburn 16863: push(@clonemsg,({
16864: mt => 'No new course created.',
16865: args => [],
16866: },
16867: {
16868: 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]).',
16869: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16870: }));
1.1221 raeburn 16871: }
1.566 albertel 16872: }
1.578 raeburn 16873: }
1.566 albertel 16874: }
1.1344 raeburn 16875: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16876: }
16877:
1.444 albertel 16878: sub construct_course {
1.1262 raeburn 16879: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 16880: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16881: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16882: my $linefeed = '<br />'."\n";
16883: if ($context eq 'auto') {
16884: $linefeed = "\n";
16885: }
1.566 albertel 16886:
16887: #
16888: # Are we cloning?
16889: #
1.1344 raeburn 16890: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16891: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 16892: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16893: if (!$can_clone) {
1.1344 raeburn 16894: return (0,$outcome,$clonemsgref);
1.566 albertel 16895: }
16896: }
16897:
1.444 albertel 16898: #
16899: # Open course
16900: #
1.1239 raeburn 16901: my $showncrstype;
16902: if ($args->{'crstype'} eq 'Placement') {
16903: $showncrstype = 'placement test';
16904: } else {
16905: $showncrstype = lc($args->{'crstype'});
16906: }
1.444 albertel 16907: my %cenv=();
16908: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16909: $args->{'cdescr'},
16910: $args->{'curl'},
16911: $args->{'course_home'},
16912: $args->{'nonstandard'},
16913: $args->{'crscode'},
16914: $args->{'ccuname'}.':'.
16915: $args->{'ccdomain'},
1.882 raeburn 16916: $args->{'crstype'},
1.1344 raeburn 16917: $cnum,$context,$category,
16918: $callercontext);
1.444 albertel 16919:
16920: # Note: The testing routines depend on this being output; see
16921: # Utils::Course. This needs to at least be output as a comment
16922: # if anyone ever decides to not show this, and Utils::Course::new
16923: # will need to be suitably modified.
1.1344 raeburn 16924: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16925: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16926: } else {
16927: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16928: }
1.943 raeburn 16929: if ($$courseid =~ /^error:/) {
1.1344 raeburn 16930: return (0,$outcome,$clonemsgref);
1.943 raeburn 16931: }
16932:
1.444 albertel 16933: #
16934: # Check if created correctly
16935: #
1.479 albertel 16936: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16937: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16938: if ($crsuhome eq 'no_host') {
1.1344 raeburn 16939: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16940: $outcome .= &mt_user($user_lh,
16941: 'Course creation failed, unrecognized course home server.');
16942: } else {
16943: $outcome .= &mt('Course creation failed, unrecognized course home server.');
16944: }
16945: $outcome .= $linefeed;
16946: return (0,$outcome,$clonemsgref);
1.943 raeburn 16947: }
1.541 raeburn 16948: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16949:
1.444 albertel 16950: #
1.566 albertel 16951: # Do the cloning
16952: #
1.1344 raeburn 16953: my @clonemsg;
1.566 albertel 16954: if ($can_clone && $cloneid) {
1.1344 raeburn 16955: push(@clonemsg,
16956: {
16957: mt => 'Created [_1] by cloning from [_2]',
16958: args => [$showncrstype,$clonetitle],
16959: });
1.566 albertel 16960: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16961: # Copy all files
1.1344 raeburn 16962: my @info =
16963: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16964: $args->{'dateshift'},$args->{'crscode'},
16965: $args->{'ccuname'}.':'.$args->{'ccdomain'},
16966: $args->{'tinyurls'});
16967: if (@info) {
16968: push(@clonemsg,@info);
16969: }
1.444 albertel 16970: # Restore URL
1.566 albertel 16971: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16972: # Restore title
1.566 albertel 16973: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16974: # Restore creation date, creator and creation context.
16975: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16976: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16977: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16978: # Mark as cloned
1.566 albertel 16979: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16980: # Need to clone grading mode
16981: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16982: $cenv{'grading'}=$newenv{'grading'};
16983: # Do not clone these environment entries
16984: &Apache::lonnet::del('environment',
16985: ['default_enrollment_start_date',
16986: 'default_enrollment_end_date',
16987: 'question.email',
16988: 'policy.email',
16989: 'comment.email',
16990: 'pch.users.denied',
1.725 raeburn 16991: 'plc.users.denied',
16992: 'hidefromcat',
1.1121 raeburn 16993: 'checkforpriv',
1.1355 raeburn 16994: 'categories'],
1.638 www 16995: $$crsudom,$$crsunum);
1.1170 raeburn 16996: if ($args->{'textbook'}) {
16997: $cenv{'internal.textbook'} = $args->{'textbook'};
16998: }
1.444 albertel 16999: }
1.566 albertel 17000:
1.444 albertel 17001: #
17002: # Set environment (will override cloned, if existing)
17003: #
17004: my @sections = ();
17005: my @xlists = ();
17006: if ($args->{'crstype'}) {
17007: $cenv{'type'}=$args->{'crstype'};
17008: }
1.1371 raeburn 17009: if ($args->{'lti'}) {
17010: $cenv{'internal.lti'}=$args->{'lti'};
17011: }
1.444 albertel 17012: if ($args->{'crsid'}) {
17013: $cenv{'courseid'}=$args->{'crsid'};
17014: }
17015: if ($args->{'crscode'}) {
17016: $cenv{'internal.coursecode'}=$args->{'crscode'};
17017: }
17018: if ($args->{'crsquota'} ne '') {
17019: $cenv{'internal.coursequota'}=$args->{'crsquota'};
17020: } else {
17021: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
17022: }
17023: if ($args->{'ccuname'}) {
17024: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
17025: ':'.$args->{'ccdomain'};
17026: } else {
17027: $cenv{'internal.courseowner'} = $args->{'curruser'};
17028: }
1.1116 raeburn 17029: if ($args->{'defaultcredits'}) {
17030: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
17031: }
1.444 albertel 17032: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
17033: if ($args->{'crssections'}) {
17034: $cenv{'internal.sectionnums'} = '';
17035: if ($args->{'crssections'} =~ m/,/) {
17036: @sections = split/,/,$args->{'crssections'};
17037: } else {
17038: $sections[0] = $args->{'crssections'};
17039: }
17040: if (@sections > 0) {
17041: foreach my $item (@sections) {
17042: my ($sec,$gp) = split/:/,$item;
17043: my $class = $args->{'crscode'}.$sec;
17044: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
17045: $cenv{'internal.sectionnums'} .= $item.',';
17046: unless ($addcheck eq 'ok') {
1.1263 raeburn 17047: push(@badclasses,$class);
1.444 albertel 17048: }
17049: }
17050: $cenv{'internal.sectionnums'} =~ s/,$//;
17051: }
17052: }
17053: # do not hide course coordinator from staff listing,
17054: # even if privileged
17055: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 17056: # add course coordinator's domain to domains to check for privileged users
17057: # if different to course domain
17058: if ($$crsudom ne $args->{'ccdomain'}) {
17059: $cenv{'checkforpriv'} = $args->{'ccdomain'};
17060: }
1.444 albertel 17061: # add crosslistings
17062: if ($args->{'crsxlist'}) {
17063: $cenv{'internal.crosslistings'}='';
17064: if ($args->{'crsxlist'} =~ m/,/) {
17065: @xlists = split/,/,$args->{'crsxlist'};
17066: } else {
17067: $xlists[0] = $args->{'crsxlist'};
17068: }
17069: if (@xlists > 0) {
17070: foreach my $item (@xlists) {
17071: my ($xl,$gp) = split/:/,$item;
17072: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
17073: $cenv{'internal.crosslistings'} .= $item.',';
17074: unless ($addcheck eq 'ok') {
1.1263 raeburn 17075: push(@badclasses,$xl);
1.444 albertel 17076: }
17077: }
17078: $cenv{'internal.crosslistings'} =~ s/,$//;
17079: }
17080: }
17081: if ($args->{'autoadds'}) {
17082: $cenv{'internal.autoadds'}=$args->{'autoadds'};
17083: }
17084: if ($args->{'autodrops'}) {
17085: $cenv{'internal.autodrops'}=$args->{'autodrops'};
17086: }
17087: # check for notification of enrollment changes
17088: my @notified = ();
17089: if ($args->{'notify_owner'}) {
17090: if ($args->{'ccuname'} ne '') {
17091: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
17092: }
17093: }
17094: if ($args->{'notify_dc'}) {
17095: if ($uname ne '') {
1.630 raeburn 17096: push(@notified,$uname.':'.$udom);
1.444 albertel 17097: }
17098: }
17099: if (@notified > 0) {
17100: my $notifylist;
17101: if (@notified > 1) {
17102: $notifylist = join(',',@notified);
17103: } else {
17104: $notifylist = $notified[0];
17105: }
17106: $cenv{'internal.notifylist'} = $notifylist;
17107: }
17108: if (@badclasses > 0) {
17109: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 17110: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
17111: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
17112: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 17113: );
1.1264 raeburn 17114: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
17115: &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 17116: if ($context eq 'auto') {
17117: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 17118: } else {
1.566 albertel 17119: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 17120: }
17121: foreach my $item (@badclasses) {
1.541 raeburn 17122: if ($context eq 'auto') {
1.1261 raeburn 17123: $outcome .= " - $item\n";
1.541 raeburn 17124: } else {
1.1261 raeburn 17125: $outcome .= "<li>$item</li>\n";
1.541 raeburn 17126: }
1.1261 raeburn 17127: }
17128: if ($context eq 'auto') {
17129: $outcome .= $linefeed;
17130: } else {
17131: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 17132: }
1.444 albertel 17133: }
17134: if ($args->{'no_end_date'}) {
17135: $args->{'endaccess'} = 0;
17136: }
17137: $cenv{'internal.autostart'}=$args->{'enrollstart'};
17138: $cenv{'internal.autoend'}=$args->{'enrollend'};
17139: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
17140: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
17141: if ($args->{'showphotos'}) {
17142: $cenv{'internal.showphotos'}=$args->{'showphotos'};
17143: }
17144: $cenv{'internal.authtype'} = $args->{'authtype'};
17145: $cenv{'internal.autharg'} = $args->{'autharg'};
17146: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
17147: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 17148: 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');
17149: if ($context eq 'auto') {
17150: $outcome .= $krb_msg;
17151: } else {
1.566 albertel 17152: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 17153: }
17154: $outcome .= $linefeed;
1.444 albertel 17155: }
17156: }
17157: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
17158: if ($args->{'setpolicy'}) {
17159: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17160: }
17161: if ($args->{'setcontent'}) {
17162: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17163: }
1.1251 raeburn 17164: if ($args->{'setcomment'}) {
17165: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
17166: }
1.444 albertel 17167: }
17168: if ($args->{'reshome'}) {
17169: $cenv{'reshome'}=$args->{'reshome'}.'/';
17170: $cenv{'reshome'}=~s/\/+$/\//;
17171: }
17172: #
17173: # course has keyed access
17174: #
17175: if ($args->{'setkeys'}) {
17176: $cenv{'keyaccess'}='yes';
17177: }
17178: # if specified, key authority is not course, but user
17179: # only active if keyaccess is yes
17180: if ($args->{'keyauth'}) {
1.487 albertel 17181: my ($user,$domain) = split(':',$args->{'keyauth'});
17182: $user = &LONCAPA::clean_username($user);
17183: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 17184: if ($user ne '' && $domain ne '') {
1.487 albertel 17185: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 17186: }
17187: }
17188:
1.1166 raeburn 17189: #
1.1167 raeburn 17190: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 17191: #
17192: if ($args->{'uniquecode'}) {
17193: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
17194: if ($code) {
17195: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 17196: my %crsinfo =
17197: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
17198: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
17199: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
17200: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
17201: }
1.1166 raeburn 17202: if (ref($coderef)) {
17203: $$coderef = $code;
17204: }
17205: }
17206: }
17207:
1.444 albertel 17208: if ($args->{'disresdis'}) {
17209: $cenv{'pch.roles.denied'}='st';
17210: }
17211: if ($args->{'disablechat'}) {
17212: $cenv{'plc.roles.denied'}='st';
17213: }
17214:
17215: # Record we've not yet viewed the Course Initialization Helper for this
17216: # course
17217: $cenv{'course.helper.not.run'} = 1;
17218: #
17219: # Use new Randomseed
17220: #
17221: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
17222: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
17223: #
17224: # The encryption code and receipt prefix for this course
17225: #
17226: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
17227: $cenv{'internal.encpref'}=100+int(9*rand(99));
17228: #
17229: # By default, use standard grading
17230: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
17231:
1.541 raeburn 17232: $outcome .= $linefeed.&mt('Setting environment').': '.
17233: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17234: #
17235: # Open all assignments
17236: #
17237: if ($args->{'openall'}) {
1.1341 raeburn 17238: my $opendate = time;
17239: if ($args->{'openallfrom'} =~ /^\d+$/) {
17240: $opendate = $args->{'openallfrom'};
17241: }
1.444 albertel 17242: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 17243: my %storecontent = ($storeunder => $opendate,
1.444 albertel 17244: $storeunder.'.type' => 'date_start');
1.1341 raeburn 17245: $outcome .= &mt('All assignments open starting [_1]',
17246: &Apache::lonlocal::locallocaltime($opendate)).': '.
17247: &Apache::lonnet::cput
17248: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 17249: }
17250: #
17251: # Set first page
17252: #
17253: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
17254: || ($cloneid)) {
17255: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 17256:
17257: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
17258: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
17259:
1.444 albertel 17260: $outcome .= ($fatal?$errtext:'read ok').' - ';
17261: my $title; my $url;
17262: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 17263: $title=&mt('Syllabus');
1.444 albertel 17264: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
17265: } else {
1.963 raeburn 17266: $title=&mt('Table of Contents');
1.444 albertel 17267: $url='/adm/navmaps';
17268: }
1.445 albertel 17269:
17270: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
17271: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
17272:
17273: if ($errtext) { $fatal=2; }
1.541 raeburn 17274: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 17275: }
1.566 albertel 17276:
1.1237 raeburn 17277: #
17278: # Set params for Placement Tests
17279: #
1.1239 raeburn 17280: if ($args->{'crstype'} eq 'Placement') {
17281: my %storecontent;
17282: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
17283: my %defaults = (
17284: buttonshide => { value => 'yes',
17285: type => 'string_yesno',},
17286: type => { value => 'randomizetry',
17287: type => 'string_questiontype',},
17288: maxtries => { value => 1,
17289: type => 'int_pos',},
17290: problemstatus => { value => 'no',
17291: type => 'string_problemstatus',},
17292: );
17293: foreach my $key (keys(%defaults)) {
17294: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
17295: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
17296: }
1.1237 raeburn 17297: &Apache::lonnet::cput
17298: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
17299: }
17300:
1.1344 raeburn 17301: return (1,$outcome,\@clonemsg);
1.444 albertel 17302: }
17303:
1.1166 raeburn 17304: sub make_unique_code {
17305: my ($cdom,$cnum) = @_;
17306: # get lock on uniquecodes db
17307: my $lockhash = {
17308: $cnum."\0".'uniquecodes' => $env{'user.name'}.
17309: ':'.$env{'user.domain'},
17310: };
17311: my $tries = 0;
17312: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17313: my ($code,$error);
17314:
17315: while (($gotlock ne 'ok') && ($tries<3)) {
17316: $tries ++;
17317: sleep 1;
17318: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17319: }
17320: if ($gotlock eq 'ok') {
17321: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
17322: my $gotcode;
17323: my $attempts = 0;
17324: while ((!$gotcode) && ($attempts < 100)) {
17325: $code = &generate_code();
17326: if (!exists($currcodes{$code})) {
17327: $gotcode = 1;
17328: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
17329: $error = 'nostore';
17330: }
17331: }
17332: $attempts ++;
17333: }
17334: my @del_lock = ($cnum."\0".'uniquecodes');
17335: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
17336: } else {
17337: $error = 'nolock';
17338: }
17339: return ($code,$error);
17340: }
17341:
17342: sub generate_code {
17343: my $code;
17344: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
17345: for (my $i=0; $i<6; $i++) {
17346: my $lettnum = int (rand 2);
17347: my $item = '';
17348: if ($lettnum) {
17349: $item = $letts[int( rand(18) )];
17350: } else {
17351: $item = 1+int( rand(8) );
17352: }
17353: $code .= $item;
17354: }
17355: return $code;
17356: }
17357:
1.444 albertel 17358: ############################################################
17359: ############################################################
17360:
1.1237 raeburn 17361: # Community, Course and Placement Test
1.378 raeburn 17362: sub course_type {
17363: my ($cid) = @_;
17364: if (!defined($cid)) {
17365: $cid = $env{'request.course.id'};
17366: }
1.404 albertel 17367: if (defined($env{'course.'.$cid.'.type'})) {
17368: return $env{'course.'.$cid.'.type'};
1.378 raeburn 17369: } else {
17370: return 'Course';
1.377 raeburn 17371: }
17372: }
1.156 albertel 17373:
1.406 raeburn 17374: sub group_term {
17375: my $crstype = &course_type();
17376: my %names = (
17377: 'Course' => 'group',
1.865 raeburn 17378: 'Community' => 'group',
1.1237 raeburn 17379: 'Placement' => 'group',
1.406 raeburn 17380: );
17381: return $names{$crstype};
17382: }
17383:
1.902 raeburn 17384: sub course_types {
1.1310 raeburn 17385: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 17386: my %typename = (
17387: official => 'Official course',
17388: unofficial => 'Unofficial course',
17389: community => 'Community',
1.1165 raeburn 17390: textbook => 'Textbook course',
1.1237 raeburn 17391: placement => 'Placement test',
1.1310 raeburn 17392: lti => 'LTI provider',
1.902 raeburn 17393: );
17394: return (\@types,\%typename);
17395: }
17396:
1.156 albertel 17397: sub icon {
17398: my ($file)=@_;
1.505 albertel 17399: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 17400: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 17401: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 17402: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
17403: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
17404: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17405: $curfext.".gif") {
17406: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
17407: $curfext.".gif";
17408: }
17409: }
1.249 albertel 17410: return &lonhttpdurl($iconname);
1.154 albertel 17411: }
1.84 albertel 17412:
1.575 albertel 17413: sub lonhttpdurl {
1.692 www 17414: #
17415: # Had been used for "small fry" static images on separate port 8080.
17416: # Modify here if lightweight http functionality desired again.
17417: # Currently eliminated due to increasing firewall issues.
17418: #
1.575 albertel 17419: my ($url)=@_;
1.692 www 17420: return $url;
1.215 albertel 17421: }
17422:
1.213 albertel 17423: sub connection_aborted {
17424: my ($r)=@_;
17425: $r->print(" ");$r->rflush();
17426: my $c = $r->connection;
17427: return $c->aborted();
17428: }
17429:
1.221 foxr 17430: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 17431: # strings as 'strings'.
17432: sub escape_single {
1.221 foxr 17433: my ($input) = @_;
1.223 albertel 17434: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 17435: $input =~ s/\'/\\\'/g; # Esacpe the 's....
17436: return $input;
17437: }
1.223 albertel 17438:
1.222 foxr 17439: # Same as escape_single, but escape's "'s This
17440: # can be used for "strings"
17441: sub escape_double {
17442: my ($input) = @_;
17443: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
17444: $input =~ s/\"/\\\"/g; # Esacpe the "s....
17445: return $input;
17446: }
1.223 albertel 17447:
1.222 foxr 17448: # Escapes the last element of a full URL.
17449: sub escape_url {
17450: my ($url) = @_;
1.238 raeburn 17451: my @urlslices = split(/\//, $url,-1);
1.369 www 17452: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 17453: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 17454: }
1.462 albertel 17455:
1.820 raeburn 17456: sub compare_arrays {
17457: my ($arrayref1,$arrayref2) = @_;
17458: my (@difference,%count);
17459: @difference = ();
17460: %count = ();
17461: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
17462: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
17463: foreach my $element (keys(%count)) {
17464: if ($count{$element} == 1) {
17465: push(@difference,$element);
17466: }
17467: }
17468: }
17469: return @difference;
17470: }
17471:
1.1322 raeburn 17472: sub lon_status_items {
17473: my %defaults = (
17474: E => 100,
17475: W => 4,
17476: N => 1,
1.1324 raeburn 17477: U => 5,
1.1322 raeburn 17478: threshold => 200,
17479: sysmail => 2500,
17480: );
17481: my %names = (
17482: E => 'Errors',
17483: W => 'Warnings',
17484: N => 'Notices',
1.1324 raeburn 17485: U => 'Unsent',
1.1322 raeburn 17486: );
17487: return (\%defaults,\%names);
17488: }
17489:
1.817 bisitz 17490: # -------------------------------------------------------- Initialize user login
1.462 albertel 17491: sub init_user_environment {
1.463 albertel 17492: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 17493: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
17494:
17495: my $public=($username eq 'public' && $domain eq 'public');
17496:
1.1062 raeburn 17497: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 17498: my $now=time;
17499:
17500: if ($public) {
17501: my $max_public=100;
17502: my $oldest;
17503: my $oldest_time=0;
17504: for(my $next=1;$next<=$max_public;$next++) {
17505: if (-e $lonids."/publicuser_$next.id") {
17506: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
17507: if ($mtime<$oldest_time || !$oldest_time) {
17508: $oldest_time=$mtime;
17509: $oldest=$next;
17510: }
17511: } else {
17512: $cookie="publicuser_$next";
17513: last;
17514: }
17515: }
17516: if (!$cookie) { $cookie="publicuser_$oldest"; }
17517: } else {
1.1275 raeburn 17518: # See if old ID present, if so, remove if this isn't a robot,
17519: # killing any existing non-robot sessions
1.463 albertel 17520: if (!$args->{'robot'}) {
17521: opendir(DIR,$lonids);
17522: while ($filename=readdir(DIR)) {
17523: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 17524: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
17525: &GDBM_READER(),0640)) {
1.1295 raeburn 17526: my $linkedfile;
1.1320 raeburn 17527: if (exists($oldenv{'user.linkedenv'})) {
17528: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 17529: }
1.1320 raeburn 17530: untie(%oldenv);
17531: if (unlink("$lonids/$filename")) {
17532: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
17533: if (-l "$lonids/$linkedfile.id") {
17534: unlink("$lonids/$linkedfile.id");
17535: }
1.1295 raeburn 17536: }
17537: }
17538: } else {
17539: unlink($lonids.'/'.$filename);
17540: }
1.463 albertel 17541: }
1.462 albertel 17542: }
1.463 albertel 17543: closedir(DIR);
1.1204 raeburn 17544: # If there is a undeleted lockfile for the user's paste buffer remove it.
17545: my $namespace = 'nohist_courseeditor';
17546: my $lockingkey = 'paste'."\0".'locked_num';
17547: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
17548: $domain,$username);
17549: if (exists($lockhash{$lockingkey})) {
17550: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
17551: unless ($delresult eq 'ok') {
17552: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
17553: }
17554: }
1.462 albertel 17555: }
17556: # Give them a new cookie
1.463 albertel 17557: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 17558: : $now.$$.int(rand(10000)));
1.463 albertel 17559: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 17560:
17561: # Initialize roles
17562:
1.1062 raeburn 17563: ($userroles,$firstaccenv,$timerintenv) =
17564: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 17565: }
17566: # ------------------------------------ Check browser type and MathML capability
17567:
1.1194 raeburn 17568: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
17569: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 17570:
17571: # ------------------------------------------------------------- Get environment
17572:
17573: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
17574: my ($tmp) = keys(%userenv);
1.1275 raeburn 17575: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 17576: undef(%userenv);
17577: }
17578: if (($userenv{'interface'}) && (!$form->{'interface'})) {
17579: $form->{'interface'}=$userenv{'interface'};
17580: }
17581: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
17582:
17583: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 17584: foreach my $option ('interface','localpath','localres') {
17585: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 17586: }
17587: # --------------------------------------------------------- Write first profile
17588:
17589: {
1.1350 raeburn 17590: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 17591: my %initial_env =
17592: ("user.name" => $username,
17593: "user.domain" => $domain,
17594: "user.home" => $authhost,
17595: "browser.type" => $clientbrowser,
17596: "browser.version" => $clientversion,
17597: "browser.mathml" => $clientmathml,
17598: "browser.unicode" => $clientunicode,
17599: "browser.os" => $clientos,
1.1137 raeburn 17600: "browser.mobile" => $clientmobile,
1.1141 raeburn 17601: "browser.info" => $clientinfo,
1.1194 raeburn 17602: "browser.osversion" => $clientosversion,
1.462 albertel 17603: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
17604: "request.course.fn" => '',
17605: "request.course.uri" => '',
17606: "request.course.sec" => '',
17607: "request.role" => 'cm',
17608: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 17609: "request.host" => $ip,);
1.462 albertel 17610:
17611: if ($form->{'localpath'}) {
17612: $initial_env{"browser.localpath"} = $form->{'localpath'};
17613: $initial_env{"browser.localres"} = $form->{'localres'};
17614: }
17615:
17616: if ($form->{'interface'}) {
17617: $form->{'interface'}=~s/\W//gs;
17618: $initial_env{"browser.interface"} = $form->{'interface'};
17619: $env{'browser.interface'}=$form->{'interface'};
17620: }
17621:
1.1157 raeburn 17622: if ($form->{'iptoken'}) {
17623: my $lonhost = $r->dir_config('lonHostID');
17624: $initial_env{"user.noloadbalance"} = $lonhost;
17625: $env{'user.noloadbalance'} = $lonhost;
17626: }
17627:
1.1268 raeburn 17628: if ($form->{'noloadbalance'}) {
17629: my @hosts = &Apache::lonnet::current_machine_ids();
17630: my $hosthere = $form->{'noloadbalance'};
17631: if (grep(/^\Q$hosthere\E$/,@hosts)) {
17632: $initial_env{"user.noloadbalance"} = $hosthere;
17633: $env{'user.noloadbalance'} = $hosthere;
17634: }
17635: }
17636:
1.1016 raeburn 17637: unless ($domain eq 'public') {
1.1273 raeburn 17638: my %is_adv = ( is_adv => $env{'user.adv'} );
17639: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
17640:
1.1387 raeburn 17641: foreach my $tool ('aboutme','blog','webdav','portfolio','timezone') {
1.1273 raeburn 17642: $userenv{'availabletools.'.$tool} =
17643: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
17644: undef,\%userenv,\%domdef,\%is_adv);
17645: }
1.980 raeburn 17646:
1.1311 raeburn 17647: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 17648: $userenv{'canrequest.'.$crstype} =
17649: &Apache::lonnet::usertools_access($username,$domain,$crstype,
17650: 'reload','requestcourses',
17651: \%userenv,\%domdef,\%is_adv);
17652: }
1.724 raeburn 17653:
1.1273 raeburn 17654: $userenv{'canrequest.author'} =
17655: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
17656: 'reload','requestauthor',
1.980 raeburn 17657: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 17658: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
17659: $domain,$username);
17660: my $reqstatus = $reqauthor{'author_status'};
17661: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
17662: if (ref($reqauthor{'author'}) eq 'HASH') {
17663: $userenv{'requestauthorqueued'} = $reqstatus.':'.
17664: $reqauthor{'author'}{'timestamp'};
17665: }
1.1092 raeburn 17666: }
1.1287 raeburn 17667: my ($types,$typename) = &course_types();
17668: if (ref($types) eq 'ARRAY') {
17669: my @options = ('approval','validate','autolimit');
17670: my $optregex = join('|',@options);
17671: my (%willtrust,%trustchecked);
17672: foreach my $type (@{$types}) {
17673: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
17674: if ($dom_str ne '') {
17675: my $updatedstr = '';
17676: my @possdomains = split(',',$dom_str);
17677: foreach my $entry (@possdomains) {
17678: my ($extdom,$extopt) = split(':',$entry);
17679: unless ($trustchecked{$extdom}) {
17680: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
17681: $trustchecked{$extdom} = 1;
17682: }
17683: if ($willtrust{$extdom}) {
17684: $updatedstr .= $entry.',';
17685: }
17686: }
17687: $updatedstr =~ s/,$//;
17688: if ($updatedstr) {
17689: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
17690: } else {
17691: delete($userenv{'reqcrsotherdom.'.$type});
17692: }
17693: }
17694: }
17695: }
1.1092 raeburn 17696: }
1.462 albertel 17697: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 17698:
1.462 albertel 17699: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
17700: &GDBM_WRCREAT(),0640)) {
17701: &_add_to_env(\%disk_env,\%initial_env);
17702: &_add_to_env(\%disk_env,\%userenv,'environment.');
17703: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 17704: if (ref($firstaccenv) eq 'HASH') {
17705: &_add_to_env(\%disk_env,$firstaccenv);
17706: }
17707: if (ref($timerintenv) eq 'HASH') {
17708: &_add_to_env(\%disk_env,$timerintenv);
17709: }
1.463 albertel 17710: if (ref($args->{'extra_env'})) {
17711: &_add_to_env(\%disk_env,$args->{'extra_env'});
17712: }
1.462 albertel 17713: untie(%disk_env);
17714: } else {
1.705 tempelho 17715: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
17716: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 17717: return 'error: '.$!;
17718: }
17719: }
17720: $env{'request.role'}='cm';
17721: $env{'request.role.adv'}=$env{'user.adv'};
17722: $env{'browser.type'}=$clientbrowser;
17723:
17724: return $cookie;
17725:
17726: }
17727:
17728: sub _add_to_env {
17729: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 17730: if (ref($env_data) eq 'HASH') {
17731: while (my ($key,$value) = each(%$env_data)) {
17732: $idf->{$prefix.$key} = $value;
17733: $env{$prefix.$key} = $value;
17734: }
1.462 albertel 17735: }
17736: }
17737:
1.685 tempelho 17738: # --- Get the symbolic name of a problem and the url
17739: sub get_symb {
17740: my ($request,$silent) = @_;
1.726 raeburn 17741: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 17742: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
17743: if ($symb eq '') {
17744: if (!$silent) {
1.1071 raeburn 17745: if (ref($request)) {
17746: $request->print("Unable to handle ambiguous references:$url:.");
17747: }
1.685 tempelho 17748: return ();
17749: }
17750: }
17751: &Apache::lonenc::check_decrypt(\$symb);
17752: return ($symb);
17753: }
17754:
17755: # --------------------------------------------------------------Get annotation
17756:
17757: sub get_annotation {
17758: my ($symb,$enc) = @_;
17759:
17760: my $key = $symb;
17761: if (!$enc) {
17762: $key =
17763: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
17764: }
17765: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
17766: return $annotation{$key};
17767: }
17768:
17769: sub clean_symb {
1.731 raeburn 17770: my ($symb,$delete_enc) = @_;
1.685 tempelho 17771:
17772: &Apache::lonenc::check_decrypt(\$symb);
17773: my $enc = $env{'request.enc'};
1.731 raeburn 17774: if ($delete_enc) {
1.730 raeburn 17775: delete($env{'request.enc'});
17776: }
1.685 tempelho 17777:
17778: return ($symb,$enc);
17779: }
1.462 albertel 17780:
1.1181 raeburn 17781: ############################################################
17782: ############################################################
17783:
17784: =pod
17785:
17786: =head1 Routines for building display used to search for courses
17787:
17788:
17789: =over 4
17790:
17791: =item * &build_filters()
17792:
17793: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 17794: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17795: and quotacheck.pl
17796:
1.1181 raeburn 17797:
17798: Inputs:
17799:
17800: filterlist - anonymous array of fields to include as potential filters
17801:
17802: crstype - course type
17803:
17804: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17805: to pop-open a course selector (will contain "extra element").
17806:
17807: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17808:
17809: filter - anonymous hash of criteria and their values
17810:
17811: action - form action
17812:
17813: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17814:
1.1182 raeburn 17815: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 17816:
17817: cloneruname - username of owner of new course who wants to clone
17818:
17819: clonerudom - domain of owner of new course who wants to clone
17820:
17821: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17822:
17823: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17824:
17825: codedom - domain
17826:
17827: formname - value of form element named "form".
17828:
17829: fixeddom - domain, if fixed.
17830:
17831: prevphase - value to assign to form element named "phase" when going back to the previous screen
17832:
17833: cnameelement - name of form element in form on opener page which will receive title of selected course
17834:
17835: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17836:
17837: cdomelement - name of form element in form on opener page which will receive domain of selected course
17838:
17839: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17840:
17841: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17842:
17843: clonewarning - warning message about missing information for intended course owner when DC creates a course
17844:
1.1182 raeburn 17845:
1.1181 raeburn 17846: Returns: $output - HTML for display of search criteria, and hidden form elements.
17847:
1.1182 raeburn 17848:
1.1181 raeburn 17849: Side Effects: None
17850:
17851: =cut
17852:
17853: # ---------------------------------------------- search for courses based on last activity etc.
17854:
17855: sub build_filters {
17856: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17857: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17858: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17859: $cnameelement,$cnumelement,$cdomelement,$setroles,
17860: $clonetext,$clonewarning) = @_;
1.1182 raeburn 17861: my ($list,$jscript);
1.1181 raeburn 17862: my $onchange = 'javascript:updateFilters(this)';
17863: my ($domainselectform,$sincefilterform,$createdfilterform,
17864: $ownerdomselectform,$persondomselectform,$instcodeform,
17865: $typeselectform,$instcodetitle);
17866: if ($formname eq '') {
17867: $formname = $caller;
17868: }
17869: foreach my $item (@{$filterlist}) {
17870: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17871: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17872: if ($item eq 'domainfilter') {
17873: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17874: } elsif ($item eq 'coursefilter') {
17875: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17876: } elsif ($item eq 'ownerfilter') {
17877: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17878: } elsif ($item eq 'ownerdomfilter') {
17879: $filter->{'ownerdomfilter'} =
17880: &LONCAPA::clean_domain($filter->{$item});
17881: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17882: 'ownerdomfilter',1);
17883: } elsif ($item eq 'personfilter') {
17884: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17885: } elsif ($item eq 'persondomfilter') {
17886: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17887: 'persondomfilter',1);
17888: } else {
17889: $filter->{$item} =~ s/\W//g;
17890: }
17891: if (!$filter->{$item}) {
17892: $filter->{$item} = '';
17893: }
17894: }
17895: if ($item eq 'domainfilter') {
17896: my $allow_blank = 1;
17897: if ($formname eq 'portform') {
17898: $allow_blank=0;
17899: } elsif ($formname eq 'studentform') {
17900: $allow_blank=0;
17901: }
17902: if ($fixeddom) {
17903: $domainselectform = '<input type="hidden" name="domainfilter"'.
17904: ' value="'.$codedom.'" />'.
17905: &Apache::lonnet::domain($codedom,'description');
17906: } else {
17907: $domainselectform = &select_dom_form($filter->{$item},
17908: 'domainfilter',
17909: $allow_blank,'',$onchange);
17910: }
17911: } else {
17912: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17913: }
17914: }
17915:
17916: # last course activity filter and selection
17917: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17918:
17919: # course created filter and selection
17920: if (exists($filter->{'createdfilter'})) {
17921: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17922: }
17923:
1.1239 raeburn 17924: my $prefix = $crstype;
17925: if ($crstype eq 'Placement') {
17926: $prefix = 'Placement Test'
17927: }
1.1181 raeburn 17928: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 17929: 'cac' => "$prefix Activity",
17930: 'ccr' => "$prefix Created",
17931: 'cde' => "$prefix Title",
17932: 'cdo' => "$prefix Domain",
1.1181 raeburn 17933: 'ins' => 'Institutional Code',
17934: 'inc' => 'Institutional Categorization',
1.1239 raeburn 17935: 'cow' => "$prefix Owner/Co-owner",
17936: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 17937: 'cog' => 'Type',
17938: );
17939:
17940: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17941: my $typeval = 'Course';
17942: if ($crstype eq 'Community') {
17943: $typeval = 'Community';
1.1239 raeburn 17944: } elsif ($crstype eq 'Placement') {
17945: $typeval = 'Placement';
1.1181 raeburn 17946: }
17947: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17948: } else {
17949: $typeselectform = '<select name="type" size="1"';
17950: if ($onchange) {
17951: $typeselectform .= ' onchange="'.$onchange.'"';
17952: }
17953: $typeselectform .= '>'."\n";
1.1237 raeburn 17954: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 17955: my $shown;
17956: if ($posstype eq 'Placement') {
17957: $shown = &mt('Placement Test');
17958: } else {
17959: $shown = &mt($posstype);
17960: }
1.1181 raeburn 17961: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 17962: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 17963: }
17964: $typeselectform.="</select>";
17965: }
17966:
17967: my ($cloneableonlyform,$cloneabletitle);
17968: if (exists($filter->{'cloneableonly'})) {
17969: my $cloneableon = '';
17970: my $cloneableoff = ' checked="checked"';
17971: if ($filter->{'cloneableonly'}) {
17972: $cloneableon = $cloneableoff;
17973: $cloneableoff = '';
17974: }
17975: $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>';
17976: if ($formname eq 'ccrs') {
1.1187 bisitz 17977: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17978: } else {
17979: $cloneabletitle = &mt('Cloneable by you');
17980: }
17981: }
17982: my $officialjs;
17983: if ($crstype eq 'Course') {
17984: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17985: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17986: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17987: if ($codedom) {
1.1181 raeburn 17988: $officialjs = 1;
17989: ($instcodeform,$jscript,$$numtitlesref) =
17990: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17991: $officialjs,$codetitlesref);
17992: if ($jscript) {
1.1182 raeburn 17993: $jscript = '<script type="text/javascript">'."\n".
17994: '// <![CDATA['."\n".
17995: $jscript."\n".
17996: '// ]]>'."\n".
17997: '</script>'."\n";
1.1181 raeburn 17998: }
17999: }
18000: if ($instcodeform eq '') {
18001: $instcodeform =
18002: '<input type="text" name="instcodefilter" size="10" value="'.
18003: $list->{'instcodefilter'}.'" />';
18004: $instcodetitle = $lt{'ins'};
18005: } else {
18006: $instcodetitle = $lt{'inc'};
18007: }
18008: if ($fixeddom) {
18009: $instcodetitle .= '<br />('.$codedom.')';
18010: }
18011: }
18012: }
18013: my $output = qq|
18014: <form method="post" name="filterpicker" action="$action">
18015: <input type="hidden" name="form" value="$formname" />
18016: |;
18017: if ($formname eq 'modifycourse') {
18018: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
18019: '<input type="hidden" name="prevphase" value="'.
18020: $prevphase.'" />'."\n";
1.1198 musolffc 18021: } elsif ($formname eq 'quotacheck') {
18022: $output .= qq|
18023: <input type="hidden" name="sortby" value="" />
18024: <input type="hidden" name="sortorder" value="" />
18025: |;
18026: } else {
1.1181 raeburn 18027: my $name_input;
18028: if ($cnameelement ne '') {
18029: $name_input = '<input type="hidden" name="cnameelement" value="'.
18030: $cnameelement.'" />';
18031: }
18032: $output .= qq|
1.1182 raeburn 18033: <input type="hidden" name="cnumelement" value="$cnumelement" />
18034: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 18035: $name_input
18036: $roleelement
18037: $multelement
18038: $typeelement
18039: |;
18040: if ($formname eq 'portform') {
18041: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
18042: }
18043: }
18044: if ($fixeddom) {
18045: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
18046: }
18047: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
18048: if ($sincefilterform) {
18049: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
18050: .$sincefilterform
18051: .&Apache::lonhtmlcommon::row_closure();
18052: }
18053: if ($createdfilterform) {
18054: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
18055: .$createdfilterform
18056: .&Apache::lonhtmlcommon::row_closure();
18057: }
18058: if ($domainselectform) {
18059: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
18060: .$domainselectform
18061: .&Apache::lonhtmlcommon::row_closure();
18062: }
18063: if ($typeselectform) {
18064: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
18065: $output .= $typeselectform;
18066: } else {
18067: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
18068: .$typeselectform
18069: .&Apache::lonhtmlcommon::row_closure();
18070: }
18071: }
18072: if ($instcodeform) {
18073: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
18074: .$instcodeform
18075: .&Apache::lonhtmlcommon::row_closure();
18076: }
18077: if (exists($filter->{'ownerfilter'})) {
18078: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
18079: '<table><tr><td>'.&mt('Username').'<br />'.
18080: '<input type="text" name="ownerfilter" size="20" value="'.
18081: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18082: $ownerdomselectform.'</td></tr></table>'.
18083: &Apache::lonhtmlcommon::row_closure();
18084: }
18085: if (exists($filter->{'personfilter'})) {
18086: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
18087: '<table><tr><td>'.&mt('Username').'<br />'.
18088: '<input type="text" name="personfilter" size="20" value="'.
18089: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
18090: $persondomselectform.'</td></tr></table>'.
18091: &Apache::lonhtmlcommon::row_closure();
18092: }
18093: if (exists($filter->{'coursefilter'})) {
18094: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
18095: .'<input type="text" name="coursefilter" size="25" value="'
18096: .$list->{'coursefilter'}.'" />'
18097: .&Apache::lonhtmlcommon::row_closure();
18098: }
18099: if ($cloneableonlyform) {
18100: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
18101: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
18102: }
18103: if (exists($filter->{'descriptfilter'})) {
18104: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
18105: .'<input type="text" name="descriptfilter" size="40" value="'
18106: .$list->{'descriptfilter'}.'" />'
18107: .&Apache::lonhtmlcommon::row_closure(1);
18108: }
18109: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
18110: '<input type="hidden" name="updater" value="" />'."\n".
18111: '<input type="submit" name="gosearch" value="'.
18112: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
18113: return $jscript.$clonewarning.$output;
18114: }
18115:
18116: =pod
18117:
18118: =item * &timebased_select_form()
18119:
1.1182 raeburn 18120: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 18121: filter e.g., Course Activity, Course Created, when searching for courses
18122: or communities
18123:
18124: Inputs:
18125:
18126: item - name of form element (sincefilter or createdfilter)
18127:
18128: filter - anonymous hash of criteria and their values
18129:
18130: Returns: HTML for a select box contained a blank, then six time selections,
18131: with value set in incoming form variables currently selected.
18132:
18133: Side Effects: None
18134:
18135: =cut
18136:
18137: sub timebased_select_form {
18138: my ($item,$filter) = @_;
18139: if (ref($filter) eq 'HASH') {
18140: $filter->{$item} =~ s/[^\d-]//g;
18141: if (!$filter->{$item}) { $filter->{$item}=-1; }
18142: return &select_form(
18143: $filter->{$item},
18144: $item,
18145: { '-1' => '',
18146: '86400' => &mt('today'),
18147: '604800' => &mt('last week'),
18148: '2592000' => &mt('last month'),
18149: '7776000' => &mt('last three months'),
18150: '15552000' => &mt('last six months'),
18151: '31104000' => &mt('last year'),
18152: 'select_form_order' =>
18153: ['-1','86400','604800','2592000','7776000',
18154: '15552000','31104000']});
18155: }
18156: }
18157:
18158: =pod
18159:
18160: =item * &js_changer()
18161:
18162: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 18163: when course type or domain is changed, and also to hide 'Searching ...' on
18164: page load completion for page showing search result.
1.1181 raeburn 18165:
18166: Inputs: None
18167:
1.1183 raeburn 18168: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 18169:
18170: Side Effects: None
18171:
18172: =cut
18173:
18174: sub js_changer {
18175: return <<ENDJS;
18176: <script type="text/javascript">
18177: // <![CDATA[
18178: function updateFilters(caller) {
18179: if (typeof(caller) != "undefined") {
18180: document.filterpicker.updater.value = caller.name;
18181: }
18182: document.filterpicker.submit();
18183: }
1.1183 raeburn 18184:
18185: function hideSearching() {
18186: if (document.getElementById('searching')) {
18187: document.getElementById('searching').style.display = 'none';
18188: }
18189: return;
18190: }
18191:
1.1181 raeburn 18192: // ]]>
18193: </script>
18194:
18195: ENDJS
18196: }
18197:
18198: =pod
18199:
1.1182 raeburn 18200: =item * &search_courses()
18201:
18202: Process selected filters form course search form and pass to lonnet::courseiddump
18203: to retrieve a hash for which keys are courseIDs which match the selected filters.
18204:
18205: Inputs:
18206:
18207: dom - domain being searched
18208:
18209: type - course type ('Course' or 'Community' or '.' if any).
18210:
18211: filter - anonymous hash of criteria and their values
18212:
18213: numtitles - for institutional codes - number of categories
18214:
18215: cloneruname - optional username of new course owner
18216:
18217: clonerudom - optional domain of new course owner
18218:
1.1221 raeburn 18219: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 18220: (used when DC is using course creation form)
18221:
18222: codetitles - reference to array of titles of components in institutional codes (official courses).
18223:
1.1221 raeburn 18224: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
18225: (and so can clone automatically)
18226:
18227: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
18228:
18229: reqinstcode - institutional code of new course, where search_courses is used to identify potential
18230: courses to clone
1.1182 raeburn 18231:
18232: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
18233:
18234:
18235: Side Effects: None
18236:
18237: =cut
18238:
18239:
18240: sub search_courses {
1.1221 raeburn 18241: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
18242: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 18243: my (%courses,%showcourses,$cloner);
18244: if (($filter->{'ownerfilter'} ne '') ||
18245: ($filter->{'ownerdomfilter'} ne '')) {
18246: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
18247: $filter->{'ownerdomfilter'};
18248: }
18249: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
18250: if (!$filter->{$item}) {
18251: $filter->{$item}='.';
18252: }
18253: }
18254: my $now = time;
18255: my $timefilter =
18256: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
18257: my ($createdbefore,$createdafter);
18258: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
18259: $createdbefore = $now;
18260: $createdafter = $now-$filter->{'createdfilter'};
18261: }
18262: my ($instcodefilter,$regexpok);
18263: if ($numtitles) {
18264: if ($env{'form.official'} eq 'on') {
18265: $instcodefilter =
18266: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18267: $regexpok = 1;
18268: } elsif ($env{'form.official'} eq 'off') {
18269: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
18270: unless ($instcodefilter eq '') {
18271: $regexpok = -1;
18272: }
18273: }
18274: } else {
18275: $instcodefilter = $filter->{'instcodefilter'};
18276: }
18277: if ($instcodefilter eq '') { $instcodefilter = '.'; }
18278: if ($type eq '') { $type = '.'; }
18279:
18280: if (($clonerudom ne '') && ($cloneruname ne '')) {
18281: $cloner = $cloneruname.':'.$clonerudom;
18282: }
18283: %courses = &Apache::lonnet::courseiddump($dom,
18284: $filter->{'descriptfilter'},
18285: $timefilter,
18286: $instcodefilter,
18287: $filter->{'combownerfilter'},
18288: $filter->{'coursefilter'},
18289: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 18290: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 18291: $filter->{'cloneableonly'},
18292: $createdbefore,$createdafter,undef,
1.1221 raeburn 18293: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 18294: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
18295: my $ccrole;
18296: if ($type eq 'Community') {
18297: $ccrole = 'co';
18298: } else {
18299: $ccrole = 'cc';
18300: }
18301: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
18302: $filter->{'persondomfilter'},
18303: 'userroles',undef,
18304: [$ccrole,'in','ad','ep','ta','cr'],
18305: $dom);
18306: foreach my $role (keys(%rolehash)) {
18307: my ($cnum,$cdom,$courserole) = split(':',$role);
18308: my $cid = $cdom.'_'.$cnum;
18309: if (exists($courses{$cid})) {
18310: if (ref($courses{$cid}) eq 'HASH') {
18311: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
18312: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 18313: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 18314: }
18315: } else {
18316: $courses{$cid}{roles} = [$courserole];
18317: }
18318: $showcourses{$cid} = $courses{$cid};
18319: }
18320: }
18321: }
18322: %courses = %showcourses;
18323: }
18324: return %courses;
18325: }
18326:
18327: =pod
18328:
1.1181 raeburn 18329: =back
18330:
1.1207 raeburn 18331: =head1 Routines for version requirements for current course.
18332:
18333: =over 4
18334:
18335: =item * &check_release_required()
18336:
18337: Compares required LON-CAPA version with version on server, and
18338: if required version is newer looks for a server with the required version.
18339:
18340: Looks first at servers in user's owen domain; if none suitable, looks at
18341: servers in course's domain are permitted to host sessions for user's domain.
18342:
18343: Inputs:
18344:
18345: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18346:
18347: $courseid - Course ID of current course
18348:
18349: $rolecode - User's current role in course (for switchserver query string).
18350:
18351: $required - LON-CAPA version needed by course (format: Major.Minor).
18352:
18353:
18354: Returns:
18355:
18356: $switchserver - query string tp append to /adm/switchserver call (if
18357: current server's LON-CAPA version is too old.
18358:
18359: $warning - Message is displayed if no suitable server could be found.
18360:
18361: =cut
18362:
18363: sub check_release_required {
18364: my ($loncaparev,$courseid,$rolecode,$required) = @_;
18365: my ($switchserver,$warning);
18366: if ($required ne '') {
18367: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
18368: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18369: if ($reqdmajor ne '' && $reqdminor ne '') {
18370: my $otherserver;
18371: if (($major eq '' && $minor eq '') ||
18372: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
18373: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
18374: my $switchlcrev =
18375: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
18376: $userdomserver);
18377: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
18378: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
18379: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
18380: my $cdom = $env{'course.'.$courseid.'.domain'};
18381: if ($cdom ne $env{'user.domain'}) {
18382: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
18383: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
18384: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
18385: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
18386: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
18387: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
18388: my $canhost =
18389: &Apache::lonnet::can_host_session($env{'user.domain'},
18390: $coursedomserver,
18391: $remoterev,
18392: $udomdefaults{'remotesessions'},
18393: $defdomdefaults{'hostedsessions'});
18394:
18395: if ($canhost) {
18396: $otherserver = $coursedomserver;
18397: } else {
18398: $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.");
18399: }
18400: } else {
18401: $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).");
18402: }
18403: } else {
18404: $otherserver = $userdomserver;
18405: }
18406: }
18407: if ($otherserver ne '') {
18408: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
18409: }
18410: }
18411: }
18412: return ($switchserver,$warning);
18413: }
18414:
18415: =pod
18416:
18417: =item * &check_release_result()
18418:
18419: Inputs:
18420:
18421: $switchwarning - Warning message if no suitable server found to host session.
18422:
18423: $switchserver - query string to append to /adm/switchserver containing lonHostID
18424: and current role.
18425:
18426: Returns: HTML to display with information about requirement to switch server.
18427: Either displaying warning with link to Roles/Courses screen or
18428: display link to switchserver.
18429:
1.1181 raeburn 18430: =cut
18431:
1.1207 raeburn 18432: sub check_release_result {
18433: my ($switchwarning,$switchserver) = @_;
18434: my $output = &start_page('Selected course unavailable on this server').
18435: '<p class="LC_warning">';
18436: if ($switchwarning) {
18437: $output .= $switchwarning.'<br /><a href="/adm/roles">';
18438: if (&show_course()) {
18439: $output .= &mt('Display courses');
18440: } else {
18441: $output .= &mt('Display roles');
18442: }
18443: $output .= '</a>';
18444: } elsif ($switchserver) {
18445: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
18446: '<br />'.
18447: '<a href="/adm/switchserver?'.$switchserver.'">'.
18448: &mt('Switch Server').
18449: '</a>';
18450: }
18451: $output .= '</p>'.&end_page();
18452: return $output;
18453: }
18454:
18455: =pod
18456:
18457: =item * &needs_coursereinit()
18458:
18459: Determine if course contents stored for user's session needs to be
18460: refreshed, because content has changed since "Big Hash" last tied.
18461:
18462: Check for change is made if time last checked is more than 10 minutes ago
18463: (by default).
18464:
18465: Inputs:
18466:
18467: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
18468:
18469: $interval (optional) - Time which may elapse (in s) between last check for content
18470: change in current course. (default: 600 s).
18471:
18472: Returns: an array; first element is:
18473:
18474: =over 4
18475:
18476: 'switch' - if content updates mean user's session
18477: needs to be switched to a server running a newer LON-CAPA version
18478:
18479: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
18480: on current server hosting user's session
18481:
18482: '' - if no action required.
18483:
18484: =back
18485:
18486: If first item element is 'switch':
18487:
18488: second item is $switchwarning - Warning message if no suitable server found to host session.
18489:
18490: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
18491: and current role.
18492:
18493: otherwise: no other elements returned.
18494:
18495: =back
18496:
18497: =cut
18498:
18499: sub needs_coursereinit {
18500: my ($loncaparev,$interval) = @_;
18501: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
18502: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18503: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18504: my $now = time;
18505: if ($interval eq '') {
18506: $interval = 600;
18507: }
18508: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 18509: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1372 raeburn 18510: my $blocked = &blocking_status('reinit',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 18511: if ($blocked) {
18512: return ();
18513: }
1.1391 raeburn 18514: my $update;
18515: my $lastmainchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
18516: my $lastsuppchange = &Apache::lonnet::get_suppchange($cdom,$cnum);
18517: if ($lastmainchange > $env{'request.course.tied'}) {
18518: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18519: if ($needswitch) {
18520: return ('switch',$switchwarning,$switchserver);
18521: }
18522: $update = 'main';
18523: }
18524: if ($lastsuppchange > $env{'request.course.suppupdated'}) {
18525: if ($update) {
18526: $update = 'both';
18527: } else {
18528: my ($needswitch,$switchwarning,$switchserver) = &switch_for_update($loncaparev,$cdom,$cnum);
18529: if ($needswitch) {
18530: return ('switch',$switchwarning,$switchserver);
18531: } else {
18532: $update = 'supp';
1.1207 raeburn 18533: }
18534: }
1.1391 raeburn 18535: return ($update);
18536: }
18537: }
18538: return ();
18539: }
18540:
18541: sub switch_for_update {
18542: my ($loncaparev,$cdom,$cnum) = @_;
18543: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18544: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
18545: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
18546: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
18547: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
18548: $curr_reqd_hash{'internal.releaserequired'}});
18549: my ($switchserver,$switchwarning) =
18550: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
18551: $curr_reqd_hash{'internal.releaserequired'});
18552: if ($switchwarning ne '' || $switchserver ne '') {
18553: return ('switch',$switchwarning,$switchserver);
18554: }
1.1207 raeburn 18555: }
18556: }
18557: return ();
18558: }
1.1181 raeburn 18559:
1.1083 raeburn 18560: sub update_content_constraints {
1.1395 raeburn 18561: my ($cdom,$cnum,$chome,$cid) = @_;
1.1083 raeburn 18562: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
18563: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 18564: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 18565: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 18566: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 18567: if ($item eq 'resourcetag') {
18568: if ($name eq 'responsetype') {
18569: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
18570: }
1.1307 raeburn 18571: } elsif ($item eq 'course') {
18572: if ($name eq 'courserestype') {
18573: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
18574: }
1.1083 raeburn 18575: }
18576: }
18577: my $navmap = Apache::lonnavmaps::navmap->new();
18578: if (defined($navmap)) {
1.1307 raeburn 18579: my (%allresponses,%allcrsrestypes);
18580: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
18581: if ($res->is_tool()) {
18582: if ($allcrsrestypes{'exttool'}) {
18583: $allcrsrestypes{'exttool'} ++;
18584: } else {
18585: $allcrsrestypes{'exttool'} = 1;
18586: }
18587: next;
18588: }
1.1083 raeburn 18589: my %responses = $res->responseTypes();
18590: foreach my $key (keys(%responses)) {
18591: next unless(exists($checkresponsetypes{$key}));
18592: $allresponses{$key} += $responses{$key};
18593: }
18594: }
18595: foreach my $key (keys(%allresponses)) {
18596: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
18597: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18598: ($reqdmajor,$reqdminor) = ($major,$minor);
18599: }
18600: }
1.1307 raeburn 18601: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 18602: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 18603: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18604: ($reqdmajor,$reqdminor) = ($major,$minor);
18605: }
18606: }
1.1083 raeburn 18607: undef($navmap);
18608: }
1.1391 raeburn 18609: if (&Apache::lonnet::count_supptools($cnum,$cdom,1)) {
1.1308 raeburn 18610: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
18611: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
18612: ($reqdmajor,$reqdminor) = ($major,$minor);
18613: }
18614: }
1.1083 raeburn 18615: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
18616: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
18617: }
18618: return;
18619: }
18620:
1.1110 raeburn 18621: sub allmaps_incourse {
18622: my ($cdom,$cnum,$chome,$cid) = @_;
18623: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
18624: $cid = $env{'request.course.id'};
18625: $cdom = $env{'course.'.$cid.'.domain'};
18626: $cnum = $env{'course.'.$cid.'.num'};
18627: $chome = $env{'course.'.$cid.'.home'};
18628: }
18629: my %allmaps = ();
18630: my $lastchange =
18631: &Apache::lonnet::get_coursechange($cdom,$cnum);
18632: if ($lastchange > $env{'request.course.tied'}) {
18633: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
18634: unless ($ferr) {
1.1395 raeburn 18635: &update_content_constraints($cdom,$cnum,$chome,$cid);
1.1110 raeburn 18636: }
18637: }
18638: my $navmap = Apache::lonnavmaps::navmap->new();
18639: if (defined($navmap)) {
18640: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
18641: $allmaps{$res->src()} = 1;
18642: }
18643: }
18644: return \%allmaps;
18645: }
18646:
1.1083 raeburn 18647: sub parse_supplemental_title {
18648: my ($title) = @_;
18649:
18650: my ($foldertitle,$renametitle);
18651: if ($title =~ /&&&/) {
18652: $title = &HTML::Entites::decode($title);
18653: }
18654: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
18655: $renametitle=$4;
18656: my ($time,$uname,$udom) = ($1,$2,$3);
18657: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
18658: my $name = &plainname($uname,$udom);
18659: $name = &HTML::Entities::encode($name,'"<>&\'');
18660: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.1401 raeburn 18661: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.$name;
1.1402 raeburn 18662: if ($foldertitle ne '') {
1.1401 raeburn 18663: $title .= ': <br />'.$foldertitle;
18664: }
1.1083 raeburn 18665: }
18666: if (wantarray) {
18667: return ($title,$foldertitle,$renametitle);
18668: }
18669: return $title;
18670: }
18671:
1.1395 raeburn 18672: sub get_supplemental {
18673: my ($cnum,$cdom,$ignorecache,$possdel)=@_;
18674: my $hashid=$cnum.':'.$cdom;
18675: my ($supplemental,$cached,$set_httprefs);
18676: unless ($ignorecache) {
18677: ($supplemental,$cached) = &Apache::lonnet::is_cached_new('supplemental',$hashid);
18678: }
18679: unless (defined($cached)) {
18680: my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
18681: unless ($chome eq 'no_host') {
18682: my @order = @LONCAPA::map::order;
18683: my @resources = @LONCAPA::map::resources;
18684: my @resparms = @LONCAPA::map::resparms;
18685: my @zombies = @LONCAPA::map::zombies;
18686: my ($errors,%ids,%hidden);
18687: $errors =
18688: &recurse_supplemental($cnum,$cdom,'supplemental.sequence',
18689: $errors,$possdel,\%ids,\%hidden);
18690: @LONCAPA::map::order = @order;
18691: @LONCAPA::map::resources = @resources;
18692: @LONCAPA::map::resparms = @resparms;
18693: @LONCAPA::map::zombies = @zombies;
18694: $set_httprefs = 1;
18695: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18696: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18697: }
18698: $supplemental = {
18699: ids => \%ids,
18700: hidden => \%hidden,
18701: };
18702: &Apache::lonnet::do_cache_new('supplemental',$hashid,$supplemental,600);
18703: }
18704: }
18705: return ($supplemental,$set_httprefs);
18706: }
18707:
1.1143 raeburn 18708: sub recurse_supplemental {
1.1391 raeburn 18709: my ($cnum,$cdom,$suppmap,$errors,$possdel,$suppids,$hiddensupp,$hidden) = @_;
18710: if (($suppmap) && (ref($suppids) eq 'HASH') && (ref($hiddensupp) eq 'HASH')) {
18711: my $mapnum;
18712: if ($suppmap eq 'supplemental.sequence') {
18713: $mapnum = 0;
18714: } else {
18715: ($mapnum) = ($suppmap =~ /^supplemental_(\d+)\.sequence$/);
18716: }
1.1143 raeburn 18717: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
18718: if ($fatal) {
18719: $errors ++;
18720: } else {
1.1389 raeburn 18721: my @order = @LONCAPA::map::order;
18722: if (@order > 0) {
18723: my @resources = @LONCAPA::map::resources;
1.1391 raeburn 18724: my @resparms = @LONCAPA::map::resparms;
1.1389 raeburn 18725: foreach my $idx (@order) {
18726: my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1143 raeburn 18727: if (($src ne '') && ($status eq 'res')) {
1.1391 raeburn 18728: my $id = $mapnum.':'.$idx;
18729: push(@{$suppids->{$src}},$id);
18730: if (($hidden) || (&get_supp_parameter($resparms[$idx],'parameter_hiddenresource') =~ /^yes/i)) {
18731: $hiddensupp->{$id} = 1;
18732: }
1.1146 raeburn 18733: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1391 raeburn 18734: $errors = &recurse_supplemental($cnum,$cdom,$1,$errors,$possdel,$suppids,
18735: $hiddensupp,$hiddensupp->{$id});
1.1143 raeburn 18736: } else {
1.1391 raeburn 18737: my $allowed;
18738: if (($env{'request.role.adv'}) || (!$hiddensupp->{$id})) {
18739: $allowed = 1;
18740: } elsif ($possdel) {
18741: foreach my $item (@{$suppids->{$src}}) {
18742: next if ($item eq $id);
18743: unless ($hiddensupp->{$item}) {
18744: $allowed = 1;
18745: last;
18746: }
18747: }
18748: if ((!$allowed) && (exists($env{'httpref.'.$src}))) {
18749: &Apache::lonnet::delenv('httpref.'.$src);
18750: }
18751: }
18752: if ($allowed && (!exists($env{'httpref.'.$src}))) {
18753: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
1.1308 raeburn 18754: }
1.1143 raeburn 18755: }
18756: }
18757: }
18758: }
18759: }
18760: }
1.1391 raeburn 18761: return $errors;
18762: }
18763:
18764: sub set_supp_httprefs {
18765: my ($cnum,$cdom,$supplemental,$possdel) = @_;
18766: if (ref($supplemental) eq 'HASH') {
18767: if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) {
18768: foreach my $src (keys(%{$supplemental->{'ids'}})) {
18769: next if ($src =~ /\.sequence$/);
18770: if (ref($supplemental->{'ids'}->{$src}) eq 'ARRAY') {
18771: my $allowed;
18772: if ($env{'request.role.adv'}) {
18773: $allowed = 1;
18774: } else {
18775: foreach my $id (@{$supplemental->{'ids'}->{$src}}) {
18776: unless ($supplemental->{'hidden'}->{$id}) {
18777: $allowed = 1;
18778: last;
18779: }
18780: }
18781: }
18782: if (exists($env{'httpref.'.$src})) {
18783: if ($possdel) {
18784: unless ($allowed) {
18785: &Apache::lonnet::delenv('httpref.'.$src);
18786: }
18787: }
18788: } elsif ($allowed) {
18789: &Apache::lonnet::allowuploaded('/adm/coursedoc',$src);
18790: }
18791: }
18792: }
18793: if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
18794: &Apache::lonnet::appenv({'request.course.suppupdated' => time});
18795: }
18796: }
18797: }
18798: }
18799:
18800: sub get_supp_parameter {
18801: my ($resparm,$name)=@_;
18802: return if ($resparm eq '');
18803: my $value=undef;
18804: my $ptype=undef;
18805: foreach (split('&&&',$resparm)) {
18806: my ($thistype,$thisname,$thisvalue)=split('___',$_);
18807: if ($thisname eq $name) {
18808: $value=$thisvalue;
18809: $ptype=$thistype;
18810: }
18811: }
18812: return $value;
1.1143 raeburn 18813: }
18814:
1.1101 raeburn 18815: sub symb_to_docspath {
1.1267 raeburn 18816: my ($symb,$navmapref) = @_;
18817: return unless ($symb && ref($navmapref));
1.1101 raeburn 18818: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
18819: if ($resurl=~/\.(sequence|page)$/) {
18820: $mapurl=$resurl;
18821: } elsif ($resurl eq 'adm/navmaps') {
18822: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
18823: }
18824: my $mapresobj;
1.1267 raeburn 18825: unless (ref($$navmapref)) {
18826: $$navmapref = Apache::lonnavmaps::navmap->new();
18827: }
18828: if (ref($$navmapref)) {
18829: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 18830: }
18831: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
18832: my $type=$2;
18833: my $path;
18834: if (ref($mapresobj)) {
18835: my $pcslist = $mapresobj->map_hierarchy();
18836: if ($pcslist ne '') {
18837: foreach my $pc (split(/,/,$pcslist)) {
18838: next if ($pc <= 1);
1.1267 raeburn 18839: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 18840: if (ref($res)) {
18841: my $thisurl = $res->src();
18842: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18843: my $thistitle = $res->title();
18844: $path .= '&'.
18845: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 18846: &escape($thistitle).
1.1101 raeburn 18847: ':'.$res->randompick().
18848: ':'.$res->randomout().
18849: ':'.$res->encrypted().
18850: ':'.$res->randomorder().
18851: ':'.$res->is_page();
18852: }
18853: }
18854: }
18855: $path =~ s/^\&//;
18856: my $maptitle = $mapresobj->title();
18857: if ($mapurl eq 'default') {
1.1129 raeburn 18858: $maptitle = 'Main Content';
1.1101 raeburn 18859: }
18860: $path .= (($path ne '')? '&' : '').
18861: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18862: &escape($maptitle).
1.1101 raeburn 18863: ':'.$mapresobj->randompick().
18864: ':'.$mapresobj->randomout().
18865: ':'.$mapresobj->encrypted().
18866: ':'.$mapresobj->randomorder().
18867: ':'.$mapresobj->is_page();
18868: } else {
18869: my $maptitle = &Apache::lonnet::gettitle($mapurl);
18870: my $ispage = (($type eq 'page')? 1 : '');
18871: if ($mapurl eq 'default') {
1.1129 raeburn 18872: $maptitle = 'Main Content';
1.1101 raeburn 18873: }
18874: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18875: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 18876: }
18877: unless ($mapurl eq 'default') {
18878: $path = 'default&'.
1.1146 raeburn 18879: &escape('Main Content').
1.1101 raeburn 18880: ':::::&'.$path;
18881: }
18882: return $path;
18883: }
18884:
1.1393 raeburn 18885: sub validate_folderpath {
18886: my ($supplementalflag,$allowed,$coursenum,$coursedom) = @_;
18887: if ($env{'form.folderpath'} ne '') {
18888: my @items = split(/\&/,$env{'form.folderpath'});
1.1394 raeburn 18889: my ($badpath,$changed,$got_supp,$supppath,%supphidden,%suppids);
1.1393 raeburn 18890: for (my $i=0; $i<@items; $i++) {
18891: my $odd = $i%2;
18892: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
18893: $badpath = 1;
1.1394 raeburn 18894: } elsif ($odd && $supplementalflag) {
1.1393 raeburn 18895: my $idx = $i-1;
1.1394 raeburn 18896: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
18897: my $esc_name = $1;
18898: if ((!$allowed) || ($items[$idx] eq 'supplemental')) {
18899: $supppath .= '&'.$esc_name;
18900: $changed = 1;
18901: } else {
18902: $supppath .= '&'.$items[$i];
18903: }
18904: } elsif (($allowed) && ($items[$idx] ne 'supplemental')) {
18905: $changed = 1;
1.1393 raeburn 18906: my $is_hidden;
18907: unless ($got_supp) {
1.1395 raeburn 18908: my ($supplemental) = &get_supplemental($coursenum,$coursedom);
1.1393 raeburn 18909: if (ref($supplemental) eq 'HASH') {
18910: if (ref($supplemental->{'hidden'}) eq 'HASH') {
18911: %supphidden = %{$supplemental->{'hidden'}};
18912: }
18913: if (ref($supplemental->{'ids'}) eq 'HASH') {
18914: %suppids = %{$supplemental->{'ids'}};
18915: }
18916: }
18917: $got_supp = 1;
18918: }
18919: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
18920: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
18921: if ($supphidden{$mapid}) {
18922: $is_hidden = 1;
18923: }
18924: }
1.1394 raeburn 18925: $supppath .= '&'.$items[$i].'::'.$is_hidden.':::';
18926: } else {
18927: $supppath .= '&'.$items[$i];
1.1393 raeburn 18928: }
18929: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
18930: $badpath = 1;
1.1394 raeburn 18931: } elsif ($supplementalflag) {
1.1393 raeburn 18932: $supppath .= '&'.$items[$i];
18933: }
18934: last if ($badpath);
18935: }
18936: if ($badpath) {
18937: delete($env{'form.folderpath'});
1.1394 raeburn 18938: } elsif ($changed && $supplementalflag) {
1.1393 raeburn 18939: $supppath =~ s/^\&//;
18940: $env{'form.folderpath'} = $supppath;
18941: }
18942: }
18943: return;
18944: }
18945:
1.1094 raeburn 18946: sub captcha_display {
1.1327 raeburn 18947: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18948: my ($output,$error);
1.1234 raeburn 18949: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 18950: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18951: if ($captcha eq 'original') {
1.1094 raeburn 18952: $output = &create_captcha();
18953: unless ($output) {
1.1172 raeburn 18954: $error = 'captcha';
1.1094 raeburn 18955: }
18956: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18957: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 18958: unless ($output) {
1.1172 raeburn 18959: $error = 'recaptcha';
1.1094 raeburn 18960: }
18961: }
1.1234 raeburn 18962: return ($output,$error,$captcha,$version);
1.1094 raeburn 18963: }
18964:
18965: sub captcha_response {
1.1327 raeburn 18966: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18967: my ($captcha_chk,$captcha_error);
1.1327 raeburn 18968: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18969: if ($captcha eq 'original') {
1.1094 raeburn 18970: ($captcha_chk,$captcha_error) = &check_captcha();
18971: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18972: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 18973: } else {
18974: $captcha_chk = 1;
18975: }
18976: return ($captcha_chk,$captcha_error);
18977: }
18978:
18979: sub get_captcha_config {
1.1327 raeburn 18980: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 18981: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 18982: my $hostname = &Apache::lonnet::hostname($lonhost);
18983: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18984: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 18985: if ($context eq 'usercreation') {
18986: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18987: if (ref($domconfig{$context}) eq 'HASH') {
18988: $hashtocheck = $domconfig{$context}{'cancreate'};
18989: if (ref($hashtocheck) eq 'HASH') {
18990: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18991: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18992: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18993: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18994: }
18995: if ($privkey && $pubkey) {
18996: $captcha = 'recaptcha';
1.1234 raeburn 18997: $version = $hashtocheck->{'recaptchaversion'};
18998: if ($version ne '2') {
18999: $version = 1;
19000: }
1.1095 raeburn 19001: } else {
19002: $captcha = 'original';
19003: }
19004: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
19005: $captcha = 'original';
19006: }
1.1094 raeburn 19007: }
1.1095 raeburn 19008: } else {
19009: $captcha = 'captcha';
19010: }
19011: } elsif ($context eq 'login') {
19012: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
19013: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
19014: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
19015: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 19016: if ($privkey && $pubkey) {
19017: $captcha = 'recaptcha';
1.1234 raeburn 19018: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
19019: if ($version ne '2') {
19020: $version = 1;
19021: }
1.1095 raeburn 19022: } else {
19023: $captcha = 'original';
1.1094 raeburn 19024: }
1.1095 raeburn 19025: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
19026: $captcha = 'original';
1.1094 raeburn 19027: }
1.1327 raeburn 19028: } elsif ($context eq 'passwords') {
19029: if ($dom_in_effect) {
19030: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
19031: if ($passwdconf{'captcha'} eq 'recaptcha') {
19032: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
19033: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
19034: $privkey = $passwdconf{'recaptchakeys'}{'private'};
19035: }
19036: if ($privkey && $pubkey) {
19037: $captcha = 'recaptcha';
19038: $version = $passwdconf{'recaptchaversion'};
19039: if ($version ne '2') {
19040: $version = 1;
19041: }
19042: } else {
19043: $captcha = 'original';
19044: }
19045: } elsif ($passwdconf{'captcha'} ne 'notused') {
19046: $captcha = 'original';
19047: }
19048: }
19049: }
1.1234 raeburn 19050: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 19051: }
19052:
19053: sub create_captcha {
19054: my %captcha_params = &captcha_settings();
19055: my ($output,$maxtries,$tries) = ('',10,0);
19056: while ($tries < $maxtries) {
19057: $tries ++;
19058: my $captcha = Authen::Captcha->new (
19059: output_folder => $captcha_params{'output_dir'},
19060: data_folder => $captcha_params{'db_dir'},
19061: );
19062: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
19063:
19064: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
19065: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1367 raeburn 19066: '<span class="LC_nobreak">'.
1.1094 raeburn 19067: &mt('Type in the letters/numbers shown below').' '.
1.1390 raeburn 19068: '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1367 raeburn 19069: '</span><br />'.
1.1176 raeburn 19070: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 19071: last;
19072: }
19073: }
1.1323 raeburn 19074: if ($output eq '') {
19075: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
19076: }
1.1094 raeburn 19077: return $output;
19078: }
19079:
19080: sub captcha_settings {
19081: my %captcha_params = (
19082: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
19083: www_output_dir => "/captchaspool",
19084: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
19085: numchars => '5',
19086: );
19087: return %captcha_params;
19088: }
19089:
19090: sub check_captcha {
19091: my ($captcha_chk,$captcha_error);
19092: my $code = $env{'form.code'};
19093: my $md5sum = $env{'form.crypt'};
19094: my %captcha_params = &captcha_settings();
19095: my $captcha = Authen::Captcha->new(
19096: output_folder => $captcha_params{'output_dir'},
19097: data_folder => $captcha_params{'db_dir'},
19098: );
1.1109 raeburn 19099: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 19100: my %captcha_hash = (
19101: 0 => 'Code not checked (file error)',
19102: -1 => 'Failed: code expired',
19103: -2 => 'Failed: invalid code (not in database)',
19104: -3 => 'Failed: invalid code (code does not match crypt)',
19105: );
19106: if ($captcha_chk != 1) {
19107: $captcha_error = $captcha_hash{$captcha_chk}
19108: }
19109: return ($captcha_chk,$captcha_error);
19110: }
19111:
19112: sub create_recaptcha {
1.1234 raeburn 19113: my ($pubkey,$version) = @_;
19114: if ($version >= 2) {
1.1367 raeburn 19115: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
19116: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1234 raeburn 19117: } else {
19118: my $use_ssl;
19119: if ($ENV{'SERVER_PORT'} == 443) {
19120: $use_ssl = 1;
19121: }
19122: my $captcha = Captcha::reCAPTCHA->new;
19123: return $captcha->get_options_setter({theme => 'white'})."\n".
19124: $captcha->get_html($pubkey,undef,$use_ssl).
19125: &mt('If the text is hard to read, [_1] will replace them.',
19126: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
19127: '<br /><br />';
19128: }
1.1094 raeburn 19129: }
19130:
19131: sub check_recaptcha {
1.1234 raeburn 19132: my ($privkey,$version) = @_;
1.1094 raeburn 19133: my $captcha_chk;
1.1350 raeburn 19134: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 19135: if ($version >= 2) {
19136: my %info = (
19137: secret => $privkey,
19138: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 19139: remoteip => $ip,
1.1234 raeburn 19140: );
1.1280 raeburn 19141: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
19142: $request->content(join('&',map {
19143: my $name = escape($_);
19144: "$name=" . ( ref($info{$_}) eq 'ARRAY'
19145: ? join("&$name=", map {escape($_) } @{$info{$_}})
19146: : &escape($info{$_}) );
19147: } keys(%info)));
19148: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 19149: if ($response->is_success) {
19150: my $data = JSON::DWIW->from_json($response->decoded_content);
19151: if (ref($data) eq 'HASH') {
19152: if ($data->{'success'}) {
19153: $captcha_chk = 1;
19154: }
19155: }
19156: }
19157: } else {
19158: my $captcha = Captcha::reCAPTCHA->new;
19159: my $captcha_result =
19160: $captcha->check_answer(
19161: $privkey,
1.1350 raeburn 19162: $ip,
1.1234 raeburn 19163: $env{'form.recaptcha_challenge_field'},
19164: $env{'form.recaptcha_response_field'},
19165: );
19166: if ($captcha_result->{is_valid}) {
19167: $captcha_chk = 1;
19168: }
1.1094 raeburn 19169: }
19170: return $captcha_chk;
19171: }
19172:
1.1174 raeburn 19173: sub emailusername_info {
1.1244 raeburn 19174: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 19175: my %titles = &Apache::lonlocal::texthash (
19176: lastname => 'Last Name',
19177: firstname => 'First Name',
19178: institution => 'School/college/university',
19179: location => "School's city, state/province, country",
19180: web => "School's web address",
19181: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 19182: id => 'Student/Employee ID',
1.1174 raeburn 19183: );
19184: return (\@fields,\%titles);
19185: }
19186:
1.1161 raeburn 19187: sub cleanup_html {
19188: my ($incoming) = @_;
19189: my $outgoing;
19190: if ($incoming ne '') {
19191: $outgoing = $incoming;
19192: $outgoing =~ s/;/;/g;
19193: $outgoing =~ s/\#/#/g;
19194: $outgoing =~ s/\&/&/g;
19195: $outgoing =~ s/</</g;
19196: $outgoing =~ s/>/>/g;
19197: $outgoing =~ s/\(/(/g;
19198: $outgoing =~ s/\)/)/g;
19199: $outgoing =~ s/"/"/g;
19200: $outgoing =~ s/'/'/g;
19201: $outgoing =~ s/\$/$/g;
19202: $outgoing =~ s{/}{/}g;
19203: $outgoing =~ s/=/=/g;
19204: $outgoing =~ s/\\/\/g
19205: }
19206: return $outgoing;
19207: }
19208:
1.1190 musolffc 19209: # Checks for critical messages and returns a redirect url if one exists.
19210: # $interval indicates how often to check for messages.
1.1282 raeburn 19211: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 19212: sub critical_redirect {
1.1282 raeburn 19213: my ($interval,$context) = @_;
1.1356 raeburn 19214: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
19215: return ();
19216: }
1.1190 musolffc 19217: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 19218: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
19219: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
19220: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1372 raeburn 19221: my $blocked = &blocking_status('alert',undef,$cnum,$cdom,undef,1);
1.1282 raeburn 19222: if ($blocked) {
19223: my $checkrole = "cm./$cdom/$cnum";
19224: if ($env{'request.course.sec'} ne '') {
19225: $checkrole .= "/$env{'request.course.sec'}";
19226: }
19227: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
19228: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
19229: return;
19230: }
19231: }
19232: }
1.1190 musolffc 19233: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
19234: $env{'user.name'});
19235: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 19236: my $redirecturl;
1.1190 musolffc 19237: if ($what[0]) {
1.1356 raeburn 19238: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1190 musolffc 19239: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 19240: my $url=&Apache::lonnet::absolute_url().$redirecturl;
19241: return (1, $url);
1.1190 musolffc 19242: }
1.1191 raeburn 19243: }
19244: }
19245: return ();
1.1190 musolffc 19246: }
19247:
1.1174 raeburn 19248: # Use:
19249: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
19250: #
19251: ##################################################
19252: # password associated functions #
19253: ##################################################
19254: sub des_keys {
19255: # Make a new key for DES encryption.
19256: # Each key has two parts which are returned separately.
19257: # Please note: Each key must be passed through the &hex function
19258: # before it is output to the web browser. The hex versions cannot
19259: # be used to decrypt.
19260: my @hexstr=('0','1','2','3','4','5','6','7',
19261: '8','9','a','b','c','d','e','f');
19262: my $lkey='';
19263: for (0..7) {
19264: $lkey.=$hexstr[rand(15)];
19265: }
19266: my $ukey='';
19267: for (0..7) {
19268: $ukey.=$hexstr[rand(15)];
19269: }
19270: return ($lkey,$ukey);
19271: }
19272:
19273: sub des_decrypt {
19274: my ($key,$cyphertext) = @_;
19275: my $keybin=pack("H16",$key);
19276: my $cypher;
19277: if ($Crypt::DES::VERSION>=2.03) {
19278: $cypher=new Crypt::DES $keybin;
19279: } else {
19280: $cypher=new DES $keybin;
19281: }
1.1233 raeburn 19282: my $plaintext='';
19283: my $cypherlength = length($cyphertext);
19284: my $numchunks = int($cypherlength/32);
19285: for (my $j=0; $j<$numchunks; $j++) {
19286: my $start = $j*32;
19287: my $cypherblock = substr($cyphertext,$start,32);
19288: my $chunk =
19289: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
19290: $chunk .=
19291: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
19292: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
19293: $plaintext .= $chunk;
19294: }
1.1174 raeburn 19295: return $plaintext;
19296: }
19297:
1.1344 raeburn 19298: sub get_requested_shorturls {
1.1309 raeburn 19299: my ($cdom,$cnum,$navmap) = @_;
19300: return unless (ref($navmap));
1.1344 raeburn 19301: my ($numnew,$errors);
1.1309 raeburn 19302: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
19303: if (@toshorten) {
19304: my (%maps,%resources,%titles);
19305: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
19306: 'shorturls',$cdom,$cnum);
19307: if (keys(%resources)) {
1.1344 raeburn 19308: my %tocreate;
1.1309 raeburn 19309: foreach my $item (sort {$a <=> $b} (@toshorten)) {
19310: my $symb = $resources{$item};
19311: if ($symb) {
19312: $tocreate{$cnum.'&'.$symb} = 1;
19313: }
19314: }
1.1344 raeburn 19315: if (keys(%tocreate)) {
19316: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
19317: \%tocreate);
19318: }
1.1309 raeburn 19319: }
1.1344 raeburn 19320: }
19321: return ($numnew,$errors);
19322: }
19323:
19324: sub make_short_symbs {
19325: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
19326: my ($numnew,@errors);
19327: if (ref($tocreateref) eq 'HASH') {
19328: my %tocreate = %{$tocreateref};
1.1309 raeburn 19329: if (keys(%tocreate)) {
19330: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
19331: my $su = Short::URL->new(no_vowels => 1);
19332: my $init = '';
19333: my (%newunique,%addcourse,%courseonly,%failed);
19334: # get lock on tiny db
19335: my $now = time;
1.1344 raeburn 19336: if ($lockuser eq '') {
19337: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
19338: }
1.1309 raeburn 19339: my $lockhash = {
1.1344 raeburn 19340: "lock\0$now" => $lockuser,
1.1309 raeburn 19341: };
19342: my $tries = 0;
19343: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
19344: my ($code,$error);
19345: while (($gotlock ne 'ok') && ($tries<3)) {
19346: $tries ++;
19347: sleep 1;
1.1319 raeburn 19348: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 19349: }
19350: if ($gotlock eq 'ok') {
19351: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
19352: \%addcourse,\%courseonly,\%failed);
19353: if (keys(%failed)) {
19354: my $numfailed = scalar(keys(%failed));
19355: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
19356: }
19357: if (keys(%newunique)) {
19358: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
19359: if ($putres eq 'ok') {
19360: $numnew = scalar(keys(%newunique));
19361: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
19362: unless ($newputres eq 'ok') {
19363: push(@errors,&mt('error: could not store course look-up of short URLs'));
19364: }
19365: } else {
19366: push(@errors,&mt('error: could not store unique six character URLs'));
19367: }
19368: }
19369: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
19370: unless ($dellockres eq 'ok') {
19371: push(@errors,&mt('error: could not release lockfile'));
19372: }
19373: } else {
19374: push(@errors,&mt('error: could not obtain lockfile'));
19375: }
19376: if (keys(%courseonly)) {
19377: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
19378: if ($result ne 'ok') {
19379: push(@errors,&mt('error: could not update course look-up of short URLs'));
19380: }
19381: }
19382: }
19383: }
19384: return ($numnew,\@errors);
19385: }
19386:
19387: sub shorten_symbs {
19388: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
19389: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
19390: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
19391: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
19392: my (%possibles,%collisions);
19393: foreach my $key (keys(%{$tocreate})) {
19394: my $num = String::CRC32::crc32($key);
19395: my $tiny = $su->encode($num,$init);
19396: if ($tiny) {
19397: $possibles{$tiny} = $key;
19398: }
19399: }
19400: if (!$init) {
19401: $init = 1;
19402: } else {
19403: $init ++;
19404: }
19405: if (keys(%possibles)) {
19406: my @posstiny = keys(%possibles);
19407: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
19408: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
19409: if (keys(%currtiny)) {
19410: foreach my $key (keys(%currtiny)) {
19411: next if ($currtiny{$key} eq '');
19412: if ($currtiny{$key} eq $possibles{$key}) {
19413: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
19414: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19415: $courseonly->{$tsymb} = $key;
19416: }
19417: } else {
19418: $collisions{$possibles{$key}} = 1;
19419: }
19420: delete($possibles{$key});
19421: }
19422: }
19423: foreach my $key (keys(%possibles)) {
19424: $newunique->{$key} = $possibles{$key};
19425: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
19426: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
19427: $addcourse->{$tsymb} = $key;
19428: }
19429: }
19430: }
19431: if (keys(%collisions)) {
19432: if ($init <5) {
19433: if (!$init) {
19434: $init = 1;
19435: } else {
19436: $init ++;
19437: }
19438: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
19439: $newunique,$addcourse,$courseonly,$failed);
19440: } else {
19441: foreach my $key (keys(%collisions)) {
19442: $failed->{$key} = 1;
19443: }
19444: }
19445: }
19446: return $init;
19447: }
19448:
1.1328 raeburn 19449: sub is_nonframeable {
1.1329 raeburn 19450: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
19451: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 19452: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 19453:
19454: $remprotocol = lc($remprotocol);
19455: $remhost = lc($remhost);
19456: my $remport = 80;
19457: if ($remprotocol eq 'https') {
19458: $remport = 443;
19459: }
1.1330 raeburn 19460: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 19461: if ($cached) {
19462: unless ($nocache) {
19463: if ($result) {
19464: return 1;
19465: } else {
19466: return 0;
19467: }
19468: }
19469: }
1.1328 raeburn 19470: my $uselink;
19471: my $request = new HTTP::Request('HEAD',$url);
19472: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
19473: if ($response->is_success()) {
19474: my $secpolicy = lc($response->header('content-security-policy'));
19475: my $xframeop = lc($response->header('x-frame-options'));
19476: $secpolicy =~ s/^\s+|\s+$//g;
19477: $xframeop =~ s/^\s+|\s+$//g;
19478: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 19479: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 19480: my ($origin,$protocol,$port);
19481: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
19482: $port = $ENV{'SERVER_PORT'};
19483: } else {
19484: $port = 80;
19485: }
19486: if ($absolute eq '') {
19487: $protocol = 'http:';
19488: if ($port == 443) {
19489: $protocol = 'https:';
19490: }
19491: $origin = $protocol.'//'.lc($hostname);
19492: } else {
19493: $origin = lc($absolute);
19494: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
19495: }
19496: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
19497: my $framepolicy = $1;
19498: $framepolicy =~ s/^\s+|\s+$//g;
19499: my @policies = split(/\s+/,$framepolicy);
19500: if (@policies) {
19501: if (grep(/^\Q'none'\E$/,@policies)) {
19502: $uselink = 1;
19503: } else {
19504: $uselink = 1;
19505: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
19506: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
19507: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
19508: undef($uselink);
19509: }
19510: if ($uselink) {
19511: if (grep(/^\Q'self'\E$/,@policies)) {
19512: if (($origin ne '') && ($remotehost eq $origin)) {
19513: undef($uselink);
19514: }
19515: }
19516: }
19517: if ($uselink) {
19518: my @possok;
19519: if ($ip ne '') {
19520: push(@possok,$ip);
19521: }
19522: my $hoststr = '';
19523: foreach my $part (reverse(split(/\./,$hostname))) {
19524: if ($hoststr eq '') {
19525: $hoststr = $part;
19526: } else {
19527: $hoststr = "$part.$hoststr";
19528: }
19529: if ($hoststr eq $hostname) {
19530: push(@possok,$hostname);
19531: } else {
19532: push(@possok,"*.$hoststr");
19533: }
19534: }
19535: if (@possok) {
19536: foreach my $poss (@possok) {
19537: last if (!$uselink);
19538: foreach my $policy (@policies) {
19539: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
19540: undef($uselink);
19541: last;
19542: }
19543: }
19544: }
19545: }
19546: }
19547: }
19548: }
19549: } elsif ($xframeop ne '') {
19550: $uselink = 1;
19551: my @policies = split(/\s*,\s*/,$xframeop);
19552: if (@policies) {
19553: unless (grep(/^deny$/,@policies)) {
19554: if ($origin ne '') {
19555: if (grep(/^sameorigin$/,@policies)) {
19556: if ($remotehost eq $origin) {
19557: undef($uselink);
19558: }
19559: }
19560: if ($uselink) {
19561: foreach my $policy (@policies) {
19562: if ($policy =~ /^allow-from\s*(.+)$/) {
19563: my $allowfrom = $1;
19564: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
19565: undef($uselink);
19566: last;
19567: }
19568: }
19569: }
19570: }
19571: }
19572: }
19573: }
19574: }
19575: }
19576: }
1.1329 raeburn 19577: if ($nocache) {
19578: if ($cached) {
19579: my $devalidate;
19580: if ($uselink && !$result) {
19581: $devalidate = 1;
19582: } elsif (!$uselink && $result) {
19583: $devalidate = 1;
19584: }
19585: if ($devalidate) {
19586: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
19587: }
19588: }
19589: } else {
19590: if ($uselink) {
19591: $result = 1;
19592: } else {
19593: $result = 0;
19594: }
19595: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
19596: }
1.1328 raeburn 19597: return $uselink;
19598: }
19599:
1.1359 raeburn 19600: sub page_menu {
19601: my ($menucolls,$menunum) = @_;
19602: my %menu;
19603: foreach my $item (split(/;/,$menucolls)) {
19604: my ($num,$value) = split(/\%/,$item);
19605: if ($num eq $menunum) {
19606: my @entries = split(/\&/,$value);
19607: foreach my $entry (@entries) {
19608: my ($name,$fields) = split(/=/,$entry);
1.1368 raeburn 19609: if (($name eq 'top') || ($name eq 'inline') || ($name eq 'foot') || ($name eq 'main')) {
1.1359 raeburn 19610: $menu{$name} = $fields;
19611: } else {
19612: my @shown;
19613: if ($fields =~ /,/) {
19614: @shown = split(/,/,$fields);
19615: } else {
19616: @shown = ($fields);
19617: }
19618: if (@shown) {
19619: foreach my $field (@shown) {
19620: next if ($field eq '');
19621: $menu{$field} = 1;
19622: }
19623: }
19624: }
19625: }
19626: }
19627: }
19628: return %menu;
19629: }
19630:
1.112 bowersj2 19631: 1;
19632: __END__;
1.41 ng 19633:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>