Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.175
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1075.2.175! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.174 2024/10/08 19:45:01 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.139 matthew 64: use HTML::Entities;
1.334 albertel 65: use Apache::lonhtmlcommon();
66: use Apache::loncoursedata();
1.344 albertel 67: use Apache::lontexconvert();
1.444 albertel 68: use Apache::lonclonecourse();
1.1075.2.25 raeburn 69: use Apache::lonuserutils();
1.1075.2.27 raeburn 70: use Apache::lonuserstate();
1.1075.2.69 raeburn 71: use Apache::courseclassifier();
1.479 albertel 72: use LONCAPA qw(:DEFAULT :match);
1.1075.2.135 raeburn 73: use HTTP::Request;
1.657 raeburn 74: use DateTime::TimeZone;
1.1075.2.102 raeburn 75: use DateTime::Locale;
1.1075.2.94 raeburn 76: use Encode();
1.1075.2.14 raeburn 77: use Authen::Captcha;
78: use Captcha::reCAPTCHA;
1.1075.2.107 raeburn 79: use JSON::DWIW;
80: use LWP::UserAgent;
1.1075.2.64 raeburn 81: use Crypt::DES;
82: use DynaLoader; # for Crypt::DES version
1.1075.2.128 raeburn 83: use File::Copy();
84: use File::Path();
1.117 www 85:
1.517 raeburn 86: # ---------------------------------------------- Designs
87: use vars qw(%defaultdesign);
88:
1.22 www 89: my $readit;
90:
1.517 raeburn 91:
1.157 matthew 92: ##
93: ## Global Variables
94: ##
1.46 matthew 95:
1.643 foxr 96:
97: # ----------------------------------------------- SSI with retries:
98: #
99:
100: =pod
101:
1.648 raeburn 102: =head1 Server Side include with retries:
1.643 foxr 103:
104: =over 4
105:
1.648 raeburn 106: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 107:
108: Performs an ssi with some number of retries. Retries continue either
109: until the result is ok or until the retry count supplied by the
110: caller is exhausted.
111:
112: Inputs:
1.648 raeburn 113:
114: =over 4
115:
1.643 foxr 116: resource - Identifies the resource to insert.
1.648 raeburn 117:
1.643 foxr 118: retries - Count of the number of retries allowed.
1.648 raeburn 119:
1.643 foxr 120: form - Hash that identifies the rendering options.
121:
1.648 raeburn 122: =back
123:
124: Returns:
125:
126: =over 4
127:
1.643 foxr 128: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 129:
1.643 foxr 130: response - The response from the last attempt (which may or may not have been successful.
131:
1.648 raeburn 132: =back
133:
134: =back
135:
1.643 foxr 136: =cut
137:
138: sub ssi_with_retries {
139: my ($resource, $retries, %form) = @_;
140:
141:
142: my $ok = 0; # True if we got a good response.
143: my $content;
144: my $response;
145:
146: # Try to get the ssi done. within the retries count:
147:
148: do {
149: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
150: $ok = $response->is_success;
1.650 www 151: if (!$ok) {
152: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
153: }
1.643 foxr 154: $retries--;
155: } while (!$ok && ($retries > 0));
156:
157: if (!$ok) {
158: $content = ''; # On error return an empty content.
159: }
160: return ($content, $response);
161:
162: }
163:
164:
165:
1.20 www 166: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 167: my %language;
1.124 www 168: my %supported_language;
1.1048 foxr 169: my %latex_language; # For choosing hyphenation in <transl..>
170: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 171: my %cprtag;
1.192 taceyjo1 172: my %scprtag;
1.351 www 173: my %fe; my %fd; my %fm;
1.41 ng 174: my %category_extensions;
1.12 harris41 175:
1.46 matthew 176: # ---------------------------------------------- Thesaurus variables
1.144 matthew 177: #
178: # %Keywords:
179: # A hash used by &keyword to determine if a word is considered a keyword.
180: # $thesaurus_db_file
181: # Scalar containing the full path to the thesaurus database.
1.46 matthew 182:
183: my %Keywords;
184: my $thesaurus_db_file;
185:
1.144 matthew 186: #
187: # Initialize values from language.tab, copyright.tab, filetypes.tab,
188: # thesaurus.tab, and filecategories.tab.
189: #
1.18 www 190: BEGIN {
1.46 matthew 191: # Variable initialization
192: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
193: #
1.22 www 194: unless ($readit) {
1.12 harris41 195: # ------------------------------------------------------------------- languages
196: {
1.158 raeburn 197: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
198: '/language.tab';
1.1075.2.128 raeburn 199: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 200: while (my $line = <$fh>) {
201: next if ($line=~/^\#/);
202: chomp($line);
1.1048 foxr 203: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 204: $language{$key}=$val.' - '.$enc;
205: if ($sup) {
206: $supported_language{$key}=$sup;
207: }
1.1048 foxr 208: if ($latex) {
209: $latex_language_bykey{$key} = $latex;
210: $latex_language{$two} = $latex;
211: }
1.158 raeburn 212: }
213: close($fh);
214: }
1.12 harris41 215: }
216: # ------------------------------------------------------------------ copyrights
217: {
1.158 raeburn 218: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
219: '/copyright.tab';
1.1075.2.128 raeburn 220: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 221: while (my $line = <$fh>) {
222: next if ($line=~/^\#/);
223: chomp($line);
224: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 225: $cprtag{$key}=$val;
226: }
227: close($fh);
228: }
1.12 harris41 229: }
1.351 www 230: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 231: {
232: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
233: '/source_copyright.tab';
1.1075.2.128 raeburn 234: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 235: while (my $line = <$fh>) {
236: next if ($line =~ /^\#/);
237: chomp($line);
238: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 239: $scprtag{$key}=$val;
240: }
241: close($fh);
242: }
243: }
1.63 www 244:
1.517 raeburn 245: # -------------------------------------------------------------- default domain designs
1.63 www 246: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 247: my $designfile = $designdir.'/default.tab';
1.1075.2.128 raeburn 248: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 249: while (my $line = <$fh>) {
250: next if ($line =~ /^\#/);
251: chomp($line);
252: my ($key,$val)=(split(/\=/,$line));
253: if ($val) { $defaultdesign{$key}=$val; }
254: }
255: close($fh);
1.63 www 256: }
257:
1.15 harris41 258: # ------------------------------------------------------------- file categories
259: {
1.158 raeburn 260: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
261: '/filecategories.tab';
1.1075.2.128 raeburn 262: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 263: while (my $line = <$fh>) {
264: next if ($line =~ /^\#/);
265: chomp($line);
266: my ($extension,$category)=(split(/\s+/,$line,2));
1.1075.2.119 raeburn 267: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 268: }
269: close($fh);
270: }
271:
1.15 harris41 272: }
1.12 harris41 273: # ------------------------------------------------------------------ file types
274: {
1.158 raeburn 275: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
276: '/filetypes.tab';
1.1075.2.128 raeburn 277: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 278: while (my $line = <$fh>) {
279: next if ($line =~ /^\#/);
280: chomp($line);
281: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 282: if ($descr ne '') {
283: $fe{$ending}=lc($emb);
284: $fd{$ending}=$descr;
1.351 www 285: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 286: }
287: }
288: close($fh);
289: }
1.12 harris41 290: }
1.22 www 291: &Apache::lonnet::logthis(
1.705 tempelho 292: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 293: $readit=1;
1.46 matthew 294: } # end of unless($readit)
1.32 matthew 295:
296: }
1.112 bowersj2 297:
1.42 matthew 298: ###############################################################
299: ## HTML and Javascript Helper Functions ##
300: ###############################################################
301:
302: =pod
303:
1.112 bowersj2 304: =head1 HTML and Javascript Functions
1.42 matthew 305:
1.112 bowersj2 306: =over 4
307:
1.648 raeburn 308: =item * &browser_and_searcher_javascript()
1.112 bowersj2 309:
310: X<browsing, javascript>X<searching, javascript>Returns a string
311: containing javascript with two functions, C<openbrowser> and
312: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
313: tags.
1.42 matthew 314:
1.648 raeburn 315: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 316:
317: inputs: formname, elementname, only, omit
318:
319: formname and elementname indicate the name of the html form and name of
320: the element that the results of the browsing selection are to be placed in.
321:
322: Specifying 'only' will restrict the browser to displaying only files
1.185 www 323: with the given extension. Can be a comma separated list.
1.42 matthew 324:
325: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 326: with the given extension. Can be a comma separated list.
1.42 matthew 327:
1.648 raeburn 328: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 329:
330: Inputs: formname, elementname
331:
332: formname and elementname specify the name of the html form and the name
333: of the element the selection from the search results will be placed in.
1.542 raeburn 334:
1.42 matthew 335: =cut
336:
337: sub browser_and_searcher_javascript {
1.199 albertel 338: my ($mode)=@_;
339: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 340: my $resurl=&escape_single(&lastresurl());
1.42 matthew 341: return <<END;
1.219 albertel 342: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 343: var editbrowser = null;
1.135 albertel 344: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 345: var url = '$resurl/?';
1.42 matthew 346: if (editbrowser == null) {
347: url += 'launch=1&';
348: }
349: url += 'catalogmode=interactive&';
1.199 albertel 350: url += 'mode=$mode&';
1.611 albertel 351: url += 'inhibitmenu=yes&';
1.42 matthew 352: url += 'form=' + formname + '&';
353: if (only != null) {
354: url += 'only=' + only + '&';
1.217 albertel 355: } else {
356: url += 'only=&';
357: }
1.42 matthew 358: if (omit != null) {
359: url += 'omit=' + omit + '&';
1.217 albertel 360: } else {
361: url += 'omit=&';
362: }
1.135 albertel 363: if (titleelement != null) {
364: url += 'titleelement=' + titleelement + '&';
1.217 albertel 365: } else {
366: url += 'titleelement=&';
367: }
1.42 matthew 368: url += 'element=' + elementname + '';
369: var title = 'Browser';
1.435 albertel 370: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 371: options += ',width=700,height=600';
372: editbrowser = open(url,title,options,'1');
373: editbrowser.focus();
374: }
375: var editsearcher;
1.135 albertel 376: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 377: var url = '/adm/searchcat?';
378: if (editsearcher == null) {
379: url += 'launch=1&';
380: }
381: url += 'catalogmode=interactive&';
1.199 albertel 382: url += 'mode=$mode&';
1.42 matthew 383: url += 'form=' + formname + '&';
1.135 albertel 384: if (titleelement != null) {
385: url += 'titleelement=' + titleelement + '&';
1.217 albertel 386: } else {
387: url += 'titleelement=&';
388: }
1.42 matthew 389: url += 'element=' + elementname + '';
390: var title = 'Search';
1.435 albertel 391: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 392: options += ',width=700,height=600';
393: editsearcher = open(url,title,options,'1');
394: editsearcher.focus();
395: }
1.219 albertel 396: // END LON-CAPA Internal -->
1.42 matthew 397: END
1.170 www 398: }
399:
400: sub lastresurl {
1.258 albertel 401: if ($env{'environment.lastresurl'}) {
402: return $env{'environment.lastresurl'}
1.170 www 403: } else {
404: return '/res';
405: }
406: }
407:
408: sub storeresurl {
409: my $resurl=&Apache::lonnet::clutter(shift);
410: unless ($resurl=~/^\/res/) { return 0; }
411: $resurl=~s/\/$//;
412: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 413: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 414: return 1;
1.42 matthew 415: }
416:
1.74 www 417: sub studentbrowser_javascript {
1.111 www 418: unless (
1.258 albertel 419: (($env{'request.course.id'}) &&
1.302 albertel 420: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
421: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
422: '/'.$env{'request.course.sec'})
423: ))
1.258 albertel 424: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 425: ) { return ''; }
1.74 www 426: return (<<'ENDSTDBRW');
1.776 bisitz 427: <script type="text/javascript" language="Javascript">
1.824 bisitz 428: // <![CDATA[
1.74 www 429: var stdeditbrowser;
1.1075.2.143 raeburn 430: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv) {
1.74 www 431: var url = '/adm/pickstudent?';
432: var filter;
1.558 albertel 433: if (!ignorefilter) {
434: eval('filter=document.'+formname+'.'+uname+'.value;');
435: }
1.74 www 436: if (filter != null) {
437: if (filter != '') {
438: url += 'filter='+filter+'&';
439: }
440: }
441: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 442: '&udomelement='+udom+
443: '&clicker='+clicker;
1.111 www 444: if (roleflag) { url+="&roles=1"; }
1.1075.2.143 raeburn 445: if (courseadv == 'condition') {
446: if (document.getElementById('courseadv')) {
447: courseadv = document.getElementById('courseadv').value;
448: }
449: }
450: if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.102 www 451: var title = 'Student_Browser';
1.74 www 452: var options = 'scrollbars=1,resizable=1,menubar=0';
453: options += ',width=700,height=600';
454: stdeditbrowser = open(url,title,options,'1');
455: stdeditbrowser.focus();
456: }
1.824 bisitz 457: // ]]>
1.74 www 458: </script>
459: ENDSTDBRW
460: }
1.42 matthew 461:
1.1003 www 462: sub resourcebrowser_javascript {
463: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 464: return (<<'ENDRESBRW');
1.1003 www 465: <script type="text/javascript" language="Javascript">
466: // <![CDATA[
467: var reseditbrowser;
1.1004 www 468: function openresbrowser(formname,reslink) {
1.1005 www 469: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 470: var title = 'Resource_Browser';
471: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 472: options += ',width=700,height=500';
1.1004 www 473: reseditbrowser = open(url,title,options,'1');
474: reseditbrowser.focus();
1.1003 www 475: }
476: // ]]>
477: </script>
1.1004 www 478: ENDRESBRW
1.1003 www 479: }
480:
1.74 www 481: sub selectstudent_link {
1.1075.2.143 raeburn 482: my ($form,$unameele,$udomele,$courseadv,$clickerid)=@_;
1.999 www 483: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
484: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
485: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 486: if ($env{'request.course.id'}) {
1.302 albertel 487: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
488: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
489: '/'.$env{'request.course.sec'})) {
1.111 www 490: return '';
491: }
1.999 www 492: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1075.2.143 raeburn 493: if ($courseadv eq 'only') {
494: $callargs .= ",'',1,'$courseadv'";
495: } elsif ($courseadv eq 'none') {
496: $callargs .= ",'','','$courseadv'";
497: } elsif ($courseadv eq 'condition') {
498: $callargs .= ",'','','$courseadv'";
1.793 raeburn 499: }
500: return '<span class="LC_nobreak">'.
501: '<a href="javascript:openstdbrowser('.$callargs.');">'.
502: &mt('Select User').'</a></span>';
1.74 www 503: }
1.258 albertel 504: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 505: $callargs .= ",'',1";
1.793 raeburn 506: return '<span class="LC_nobreak">'.
507: '<a href="javascript:openstdbrowser('.$callargs.');">'.
508: &mt('Select User').'</a></span>';
1.111 www 509: }
510: return '';
1.91 www 511: }
512:
1.1004 www 513: sub selectresource_link {
514: my ($form,$reslink,$arg)=@_;
515:
516: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
517: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
518: unless ($env{'request.course.id'}) { return $arg; }
519: return '<span class="LC_nobreak">'.
520: '<a href="javascript:openresbrowser('.$callargs.');">'.
521: $arg.'</a></span>';
522: }
523:
524:
525:
1.653 raeburn 526: sub authorbrowser_javascript {
527: return <<"ENDAUTHORBRW";
1.776 bisitz 528: <script type="text/javascript" language="JavaScript">
1.824 bisitz 529: // <![CDATA[
1.653 raeburn 530: var stdeditbrowser;
531:
532: function openauthorbrowser(formname,udom) {
533: var url = '/adm/pickauthor?';
534: url += 'form='+formname+'&roledom='+udom;
535: var title = 'Author_Browser';
536: var options = 'scrollbars=1,resizable=1,menubar=0';
537: options += ',width=700,height=600';
538: stdeditbrowser = open(url,title,options,'1');
539: stdeditbrowser.focus();
540: }
541:
1.824 bisitz 542: // ]]>
1.653 raeburn 543: </script>
544: ENDAUTHORBRW
545: }
546:
1.91 www 547: sub coursebrowser_javascript {
1.1075.2.31 raeburn 548: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1075.2.95 raeburn 549: $credits_element,$instcode) = @_;
1.932 raeburn 550: my $wintitle = 'Course_Browser';
1.931 raeburn 551: if ($crstype eq 'Community') {
1.932 raeburn 552: $wintitle = 'Community_Browser';
1.909 raeburn 553: }
1.876 raeburn 554: my $id_functions = &javascript_index_functions();
555: my $output = '
1.776 bisitz 556: <script type="text/javascript" language="JavaScript">
1.824 bisitz 557: // <![CDATA[
1.468 raeburn 558: var stdeditbrowser;'."\n";
1.876 raeburn 559:
560: $output .= <<"ENDSTDBRW";
1.909 raeburn 561: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 562: var url = '/adm/pickcourse?';
1.895 raeburn 563: var formid = getFormIdByName(formname);
1.876 raeburn 564: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 565: if (domainfilter != null) {
566: if (domainfilter != '') {
567: url += 'domainfilter='+domainfilter+'&';
568: }
569: }
1.91 www 570: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 571: '&cdomelement='+udom+
572: '&cnameelement='+desc;
1.468 raeburn 573: if (extra_element !=null && extra_element != '') {
1.594 raeburn 574: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 575: url += '&roleelement='+extra_element;
576: if (domainfilter == null || domainfilter == '') {
577: url += '&domainfilter='+extra_element;
578: }
1.234 raeburn 579: }
1.468 raeburn 580: else {
581: if (formname == 'portform') {
582: url += '&setroles='+extra_element;
1.800 raeburn 583: } else {
584: if (formname == 'rules') {
585: url += '&fixeddom='+extra_element;
586: }
1.468 raeburn 587: }
588: }
1.230 raeburn 589: }
1.909 raeburn 590: if (type != null && type != '') {
591: url += '&type='+type;
592: }
593: if (type_elem != null && type_elem != '') {
594: url += '&typeelement='+type_elem;
595: }
1.872 raeburn 596: if (formname == 'ccrs') {
597: var ownername = document.forms[formid].ccuname.value;
598: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1075.2.101 raeburn 599: url += '&cloner='+ownername+':'+ownerdom;
600: if (type == 'Course') {
601: url += '&crscode='+document.forms[formid].crscode.value;
602: }
1.1075.2.95 raeburn 603: }
604: if (formname == 'requestcrs') {
605: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 606: }
1.293 raeburn 607: if (multflag !=null && multflag != '') {
608: url += '&multiple='+multflag;
609: }
1.909 raeburn 610: var title = '$wintitle';
1.91 www 611: var options = 'scrollbars=1,resizable=1,menubar=0';
612: options += ',width=700,height=600';
613: stdeditbrowser = open(url,title,options,'1');
614: stdeditbrowser.focus();
615: }
1.876 raeburn 616: $id_functions
617: ENDSTDBRW
1.1075.2.31 raeburn 618: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
619: $output .= &setsec_javascript($sec_element,$formname,$role_element,
620: $credits_element);
1.876 raeburn 621: }
622: $output .= '
623: // ]]>
624: </script>';
625: return $output;
626: }
627:
628: sub javascript_index_functions {
629: return <<"ENDJS";
630:
631: function getFormIdByName(formname) {
632: for (var i=0;i<document.forms.length;i++) {
633: if (document.forms[i].name == formname) {
634: return i;
635: }
636: }
637: return -1;
638: }
639:
640: function getIndexByName(formid,item) {
641: for (var i=0;i<document.forms[formid].elements.length;i++) {
642: if (document.forms[formid].elements[i].name == item) {
643: return i;
644: }
645: }
646: return -1;
647: }
1.468 raeburn 648:
1.876 raeburn 649: function getDomainFromSelectbox(formname,udom) {
650: var userdom;
651: var formid = getFormIdByName(formname);
652: if (formid > -1) {
653: var domid = getIndexByName(formid,udom);
654: if (domid > -1) {
655: if (document.forms[formid].elements[domid].type == 'select-one') {
656: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
657: }
658: if (document.forms[formid].elements[domid].type == 'hidden') {
659: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 660: }
661: }
662: }
1.876 raeburn 663: return userdom;
664: }
665:
666: ENDJS
1.468 raeburn 667:
1.876 raeburn 668: }
669:
1.1017 raeburn 670: sub javascript_array_indexof {
1.1018 raeburn 671: return <<ENDJS;
1.1017 raeburn 672: <script type="text/javascript" language="JavaScript">
673: // <![CDATA[
674:
675: if (!Array.prototype.indexOf) {
676: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
677: "use strict";
678: if (this === void 0 || this === null) {
679: throw new TypeError();
680: }
681: var t = Object(this);
682: var len = t.length >>> 0;
683: if (len === 0) {
684: return -1;
685: }
686: var n = 0;
687: if (arguments.length > 0) {
688: n = Number(arguments[1]);
689: if (n !== n) { // shortcut for verifying if it's NaN
690: n = 0;
691: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
692: n = (n > 0 || -1) * Math.floor(Math.abs(n));
693: }
694: }
695: if (n >= len) {
696: return -1;
697: }
698: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
699: for (; k < len; k++) {
700: if (k in t && t[k] === searchElement) {
701: return k;
702: }
703: }
704: return -1;
705: }
706: }
707:
708: // ]]>
709: </script>
710:
711: ENDJS
712:
713: }
714:
1.876 raeburn 715: sub userbrowser_javascript {
716: my $id_functions = &javascript_index_functions();
717: return <<"ENDUSERBRW";
718:
1.888 raeburn 719: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 720: var url = '/adm/pickuser?';
721: var userdom = getDomainFromSelectbox(formname,udom);
722: if (userdom != null) {
723: if (userdom != '') {
724: url += 'srchdom='+userdom+'&';
725: }
726: }
727: url += 'form=' + formname + '&unameelement='+uname+
728: '&udomelement='+udom+
729: '&ulastelement='+ulast+
730: '&ufirstelement='+ufirst+
731: '&uemailelement='+uemail+
1.881 raeburn 732: '&hideudomelement='+hideudom+
733: '&coursedom='+crsdom;
1.888 raeburn 734: if ((caller != null) && (caller != undefined)) {
735: url += '&caller='+caller;
736: }
1.876 raeburn 737: var title = 'User_Browser';
738: var options = 'scrollbars=1,resizable=1,menubar=0';
739: options += ',width=700,height=600';
740: var stdeditbrowser = open(url,title,options,'1');
741: stdeditbrowser.focus();
742: }
743:
1.888 raeburn 744: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 745: var formid = getFormIdByName(formname);
746: if (formid > -1) {
1.888 raeburn 747: var unameid = getIndexByName(formid,uname);
1.876 raeburn 748: var domid = getIndexByName(formid,udom);
749: var hidedomid = getIndexByName(formid,origdom);
750: if (hidedomid > -1) {
751: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 752: var unameval = document.forms[formid].elements[unameid].value;
753: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
754: if (domid > -1) {
755: var slct = document.forms[formid].elements[domid];
756: if (slct.type == 'select-one') {
757: var i;
758: for (i=0;i<slct.length;i++) {
759: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
760: }
761: }
762: if (slct.type == 'hidden') {
763: slct.value = fixeddom;
1.876 raeburn 764: }
765: }
1.468 raeburn 766: }
767: }
768: }
1.876 raeburn 769: return;
770: }
771:
772: $id_functions
773: ENDUSERBRW
1.468 raeburn 774: }
775:
776: sub setsec_javascript {
1.1075.2.31 raeburn 777: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 778: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
779: $communityrolestr);
780: if ($role_element ne '') {
781: my @allroles = ('st','ta','ep','in','ad');
782: foreach my $crstype ('Course','Community') {
783: if ($crstype eq 'Community') {
784: foreach my $role (@allroles) {
785: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
786: }
787: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
788: } else {
789: foreach my $role (@allroles) {
790: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
791: }
792: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
793: }
794: }
795: $rolestr = '"'.join('","',@allroles).'"';
796: $courserolestr = '"'.join('","',@courserolenames).'"';
797: $communityrolestr = '"'.join('","',@communityrolenames).'"';
798: }
1.468 raeburn 799: my $setsections = qq|
800: function setSect(sectionlist) {
1.629 raeburn 801: var sectionsArray = new Array();
802: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
803: sectionsArray = sectionlist.split(",");
804: }
1.468 raeburn 805: var numSections = sectionsArray.length;
806: document.$formname.$sec_element.length = 0;
807: if (numSections == 0) {
808: document.$formname.$sec_element.multiple=false;
809: document.$formname.$sec_element.size=1;
810: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
811: } else {
812: if (numSections == 1) {
813: document.$formname.$sec_element.multiple=false;
814: document.$formname.$sec_element.size=1;
815: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
816: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
817: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
818: } else {
819: for (var i=0; i<numSections; i++) {
820: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
821: }
822: document.$formname.$sec_element.multiple=true
823: if (numSections < 3) {
824: document.$formname.$sec_element.size=numSections;
825: } else {
826: document.$formname.$sec_element.size=3;
827: }
828: document.$formname.$sec_element.options[0].selected = false
829: }
830: }
1.91 www 831: }
1.905 raeburn 832:
833: function setRole(crstype) {
1.468 raeburn 834: |;
1.905 raeburn 835: if ($role_element eq '') {
836: $setsections .= ' return;
837: }
838: ';
839: } else {
840: $setsections .= qq|
841: var elementLength = document.$formname.$role_element.length;
842: var allroles = Array($rolestr);
843: var courserolenames = Array($courserolestr);
844: var communityrolenames = Array($communityrolestr);
845: if (elementLength != undefined) {
846: if (document.$formname.$role_element.options[5].value == 'cc') {
847: if (crstype == 'Course') {
848: return;
849: } else {
850: allroles[5] = 'co';
851: for (var i=0; i<6; i++) {
852: document.$formname.$role_element.options[i].value = allroles[i];
853: document.$formname.$role_element.options[i].text = communityrolenames[i];
854: }
855: }
856: } else {
857: if (crstype == 'Community') {
858: return;
859: } else {
860: allroles[5] = 'cc';
861: for (var i=0; i<6; i++) {
862: document.$formname.$role_element.options[i].value = allroles[i];
863: document.$formname.$role_element.options[i].text = courserolenames[i];
864: }
865: }
866: }
867: }
868: return;
869: }
870: |;
871: }
1.1075.2.31 raeburn 872: if ($credits_element) {
873: $setsections .= qq|
874: function setCredits(defaultcredits) {
875: document.$formname.$credits_element.value = defaultcredits;
876: return;
877: }
878: |;
879: }
1.468 raeburn 880: return $setsections;
881: }
882:
1.91 www 883: sub selectcourse_link {
1.909 raeburn 884: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
885: $typeelement) = @_;
886: my $type = $selecttype;
1.871 raeburn 887: my $linktext = &mt('Select Course');
888: if ($selecttype eq 'Community') {
1.909 raeburn 889: $linktext = &mt('Select Community');
1.906 raeburn 890: } elsif ($selecttype eq 'Course/Community') {
891: $linktext = &mt('Select Course/Community');
1.909 raeburn 892: $type = '';
1.1019 raeburn 893: } elsif ($selecttype eq 'Select') {
894: $linktext = &mt('Select');
895: $type = '';
1.871 raeburn 896: }
1.787 bisitz 897: return '<span class="LC_nobreak">'
898: ."<a href='"
899: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
900: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 901: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 902: ."'>".$linktext.'</a>'
1.787 bisitz 903: .'</span>';
1.74 www 904: }
1.42 matthew 905:
1.653 raeburn 906: sub selectauthor_link {
907: my ($form,$udom)=@_;
908: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
909: &mt('Select Author').'</a>';
910: }
911:
1.876 raeburn 912: sub selectuser_link {
1.881 raeburn 913: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 914: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 915: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 916: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 917: ');">'.$linktext.'</a>';
1.876 raeburn 918: }
919:
1.273 raeburn 920: sub check_uncheck_jscript {
921: my $jscript = <<"ENDSCRT";
922: function checkAll(field) {
923: if (field.length > 0) {
924: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 925: if (!field[i].disabled) {
926: field[i].checked = true;
927: }
1.273 raeburn 928: }
929: } else {
1.1075.2.14 raeburn 930: if (!field.disabled) {
931: field.checked = true;
932: }
1.273 raeburn 933: }
934: }
935:
936: function uncheckAll(field) {
937: if (field.length > 0) {
938: for (i = 0; i < field.length; i++) {
939: field[i].checked = false ;
1.543 albertel 940: }
941: } else {
1.273 raeburn 942: field.checked = false ;
943: }
944: }
945: ENDSCRT
946: return $jscript;
947: }
948:
1.656 www 949: sub select_timezone {
1.1075.2.115 raeburn 950: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
951: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 952: if ($includeempty) {
953: $output .= '<option value=""';
954: if (($selected eq '') || ($selected eq 'local')) {
955: $output .= ' selected="selected" ';
956: }
957: $output .= '> </option>';
958: }
1.657 raeburn 959: my @timezones = DateTime::TimeZone->all_names;
960: foreach my $tzone (@timezones) {
961: $output.= '<option value="'.$tzone.'"';
962: if ($tzone eq $selected) {
963: $output.=' selected="selected"';
964: }
965: $output.=">$tzone</option>\n";
1.656 www 966: }
967: $output.="</select>";
968: return $output;
969: }
1.273 raeburn 970:
1.687 raeburn 971: sub select_datelocale {
1.1075.2.115 raeburn 972: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
973: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 974: if ($includeempty) {
975: $output .= '<option value=""';
976: if ($selected eq '') {
977: $output .= ' selected="selected" ';
978: }
979: $output .= '> </option>';
980: }
1.1075.2.102 raeburn 981: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 982: my (@possibles,%locale_names);
1.1075.2.102 raeburn 983: my @locales = DateTime::Locale->ids();
984: foreach my $id (@locales) {
985: if ($id ne '') {
986: my ($en_terr,$native_terr);
987: my $loc = DateTime::Locale->load($id);
988: if (ref($loc)) {
989: $en_terr = $loc->name();
990: $native_terr = $loc->native_name();
1.687 raeburn 991: if (grep(/^en$/,@languages) || !@languages) {
992: if ($en_terr ne '') {
993: $locale_names{$id} = '('.$en_terr.')';
994: } elsif ($native_terr ne '') {
995: $locale_names{$id} = $native_terr;
996: }
997: } else {
998: if ($native_terr ne '') {
999: $locale_names{$id} = $native_terr.' ';
1000: } elsif ($en_terr ne '') {
1001: $locale_names{$id} = '('.$en_terr.')';
1002: }
1003: }
1.1075.2.94 raeburn 1004: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1075.2.102 raeburn 1005: push(@possibles,$id);
1.687 raeburn 1006: }
1007: }
1008: }
1009: foreach my $item (sort(@possibles)) {
1010: $output.= '<option value="'.$item.'"';
1011: if ($item eq $selected) {
1012: $output.=' selected="selected"';
1013: }
1014: $output.=">$item";
1015: if ($locale_names{$item} ne '') {
1.1075.2.94 raeburn 1016: $output.=' '.$locale_names{$item};
1.687 raeburn 1017: }
1018: $output.="</option>\n";
1019: }
1020: $output.="</select>";
1021: return $output;
1022: }
1023:
1.792 raeburn 1024: sub select_language {
1.1075.2.115 raeburn 1025: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1026: my %langchoices;
1027: if ($includeempty) {
1.1075.2.32 raeburn 1028: %langchoices = ('' => 'No language preference');
1.792 raeburn 1029: }
1030: foreach my $id (&languageids()) {
1031: my $code = &supportedlanguagecode($id);
1032: if ($code) {
1033: $langchoices{$code} = &plainlanguagedescription($id);
1034: }
1035: }
1.1075.2.32 raeburn 1036: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1075.2.115 raeburn 1037: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1038: }
1039:
1.42 matthew 1040: =pod
1.36 matthew 1041:
1.648 raeburn 1042: =item * &linked_select_forms(...)
1.36 matthew 1043:
1044: linked_select_forms returns a string containing a <script></script> block
1045: and html for two <select> menus. The select menus will be linked in that
1046: changing the value of the first menu will result in new values being placed
1047: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1048: order unless a defined order is provided.
1.36 matthew 1049:
1050: linked_select_forms takes the following ordered inputs:
1051:
1052: =over 4
1053:
1.112 bowersj2 1054: =item * $formname, the name of the <form> tag
1.36 matthew 1055:
1.112 bowersj2 1056: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1057:
1.112 bowersj2 1058: =item * $firstdefault, the default value for the first menu
1.36 matthew 1059:
1.112 bowersj2 1060: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1061:
1.112 bowersj2 1062: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1063:
1.112 bowersj2 1064: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1065:
1.609 raeburn 1066: =item * $menuorder, the order of values in the first menu
1067:
1.1075.2.31 raeburn 1068: =item * $onchangefirst, additional javascript call to execute for an onchange
1069: event for the first <select> tag
1070:
1071: =item * $onchangesecond, additional javascript call to execute for an onchange
1072: event for the second <select> tag
1073:
1.41 ng 1074: =back
1075:
1.36 matthew 1076: Below is an example of such a hash. Only the 'text', 'default', and
1077: 'select2' keys must appear as stated. keys(%menu) are the possible
1078: values for the first select menu. The text that coincides with the
1.41 ng 1079: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1080: and text for the second menu are given in the hash pointed to by
1081: $menu{$choice1}->{'select2'}.
1082:
1.112 bowersj2 1083: my %menu = ( A1 => { text =>"Choice A1" ,
1084: default => "B3",
1085: select2 => {
1086: B1 => "Choice B1",
1087: B2 => "Choice B2",
1088: B3 => "Choice B3",
1089: B4 => "Choice B4"
1.609 raeburn 1090: },
1091: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1092: },
1093: A2 => { text =>"Choice A2" ,
1094: default => "C2",
1095: select2 => {
1096: C1 => "Choice C1",
1097: C2 => "Choice C2",
1098: C3 => "Choice C3"
1.609 raeburn 1099: },
1100: order => ['C2','C1','C3'],
1.112 bowersj2 1101: },
1102: A3 => { text =>"Choice A3" ,
1103: default => "D6",
1104: select2 => {
1105: D1 => "Choice D1",
1106: D2 => "Choice D2",
1107: D3 => "Choice D3",
1108: D4 => "Choice D4",
1109: D5 => "Choice D5",
1110: D6 => "Choice D6",
1111: D7 => "Choice D7"
1.609 raeburn 1112: },
1113: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1114: }
1115: );
1.36 matthew 1116:
1117: =cut
1118:
1119: sub linked_select_forms {
1120: my ($formname,
1121: $middletext,
1122: $firstdefault,
1123: $firstselectname,
1124: $secondselectname,
1.609 raeburn 1125: $hashref,
1126: $menuorder,
1.1075.2.31 raeburn 1127: $onchangefirst,
1128: $onchangesecond
1.36 matthew 1129: ) = @_;
1130: my $second = "document.$formname.$secondselectname";
1131: my $first = "document.$formname.$firstselectname";
1132: # output the javascript to do the changing
1133: my $result = '';
1.776 bisitz 1134: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1135: $result.="// <![CDATA[\n";
1.36 matthew 1136: $result.="var select2data = new Object();\n";
1137: $" = '","';
1138: my $debug = '';
1139: foreach my $s1 (sort(keys(%$hashref))) {
1140: $result.="select2data.d_$s1 = new Object();\n";
1141: $result.="select2data.d_$s1.def = new String('".
1142: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1143: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1144: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1145: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1146: @s2values = @{$hashref->{$s1}->{'order'}};
1147: }
1.36 matthew 1148: $result.="\"@s2values\");\n";
1149: $result.="select2data.d_$s1.texts = new Array(";
1150: my @s2texts;
1151: foreach my $value (@s2values) {
1.1075.2.119 raeburn 1152: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1153: }
1154: $result.="\"@s2texts\");\n";
1155: }
1156: $"=' ';
1157: $result.= <<"END";
1158:
1159: function select1_changed() {
1160: // Determine new choice
1161: var newvalue = "d_" + $first.value;
1162: // update select2
1163: var values = select2data[newvalue].values;
1164: var texts = select2data[newvalue].texts;
1165: var select2def = select2data[newvalue].def;
1166: var i;
1167: // out with the old
1168: for (i = 0; i < $second.options.length; i++) {
1169: $second.options[i] = null;
1170: }
1171: // in with the nuclear
1172: for (i=0;i<values.length; i++) {
1173: $second.options[i] = new Option(values[i]);
1.143 matthew 1174: $second.options[i].value = values[i];
1.36 matthew 1175: $second.options[i].text = texts[i];
1176: if (values[i] == select2def) {
1177: $second.options[i].selected = true;
1178: }
1179: }
1180: }
1.824 bisitz 1181: // ]]>
1.36 matthew 1182: </script>
1183: END
1184: # output the initial values for the selection lists
1.1075.2.31 raeburn 1185: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1186: my @order = sort(keys(%{$hashref}));
1187: if (ref($menuorder) eq 'ARRAY') {
1188: @order = @{$menuorder};
1189: }
1190: foreach my $value (@order) {
1.36 matthew 1191: $result.=" <option value=\"$value\" ";
1.253 albertel 1192: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1193: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1194: }
1195: $result .= "</select>\n";
1196: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1197: $result .= $middletext;
1.1075.2.31 raeburn 1198: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1199: if ($onchangesecond) {
1200: $result .= ' onchange="'.$onchangesecond.'"';
1201: }
1202: $result .= ">\n";
1.36 matthew 1203: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1204:
1205: my @secondorder = sort(keys(%select2));
1206: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1207: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1208: }
1209: foreach my $value (@secondorder) {
1.36 matthew 1210: $result.=" <option value=\"$value\" ";
1.253 albertel 1211: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1212: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1213: }
1214: $result .= "</select>\n";
1215: # return $debug;
1216: return $result;
1217: } # end of sub linked_select_forms {
1218:
1.45 matthew 1219: =pod
1.44 bowersj2 1220:
1.973 raeburn 1221: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1222:
1.112 bowersj2 1223: Returns a string corresponding to an HTML link to the given help
1224: $topic, where $topic corresponds to the name of a .tex file in
1225: /home/httpd/html/adm/help/tex, with underscores replaced by
1226: spaces.
1227:
1228: $text will optionally be linked to the same topic, allowing you to
1229: link text in addition to the graphic. If you do not want to link
1230: text, but wish to specify one of the later parameters, pass an
1231: empty string.
1232:
1233: $stayOnPage is a value that will be interpreted as a boolean. If true,
1234: the link will not open a new window. If false, the link will open
1235: a new window using Javascript. (Default is false.)
1236:
1237: $width and $height are optional numerical parameters that will
1238: override the width and height of the popped up window, which may
1.973 raeburn 1239: be useful for certain help topics with big pictures included.
1240:
1241: $imgid is the id of the img tag used for the help icon. This may be
1242: used in a javascript call to switch the image src. See
1243: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1244:
1245: =cut
1246:
1247: sub help_open_topic {
1.973 raeburn 1248: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1249: $text = "" if (not defined $text);
1.44 bowersj2 1250: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1251: $width = 500 if (not defined $width);
1.44 bowersj2 1252: $height = 400 if (not defined $height);
1253: my $filename = $topic;
1254: $filename =~ s/ /_/g;
1255:
1.48 bowersj2 1256: my $template = "";
1257: my $link;
1.572 banghart 1258:
1.159 www 1259: $topic=~s/\W/\_/g;
1.44 bowersj2 1260:
1.572 banghart 1261: if (!$stayOnPage) {
1.1075.2.50 raeburn 1262: if ($env{'browser.mobile'}) {
1263: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1264: } else {
1265: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1266: }
1.1037 www 1267: } elsif ($stayOnPage eq 'popup') {
1268: $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 1269: } else {
1.48 bowersj2 1270: $link = "/adm/help/${filename}.hlp";
1271: }
1272:
1273: # Add the text
1.755 neumanie 1274: if ($text ne "") {
1.763 bisitz 1275: $template.='<span class="LC_help_open_topic">'
1276: .'<a target="_top" href="'.$link.'">'
1277: .$text.'</a>';
1.48 bowersj2 1278: }
1279:
1.763 bisitz 1280: # (Always) Add the graphic
1.179 matthew 1281: my $title = &mt('Online Help');
1.667 raeburn 1282: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1283: if ($imgid ne '') {
1284: $imgid = ' id="'.$imgid.'"';
1285: }
1.763 bisitz 1286: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1287: .'<img src="'.$helpicon.'" border="0"'
1288: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1289: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1290: .' /></a>';
1291: if ($text ne "") {
1292: $template.='</span>';
1293: }
1.44 bowersj2 1294: return $template;
1295:
1.106 bowersj2 1296: }
1297:
1298: # This is a quicky function for Latex cheatsheet editing, since it
1299: # appears in at least four places
1300: sub helpLatexCheatsheet {
1.1037 www 1301: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1302: my $out;
1.106 bowersj2 1303: my $addOther = '';
1.732 raeburn 1304: if ($topic) {
1.1037 www 1305: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1306: }
1307: $out = '<span>' # Start cheatsheet
1308: .$addOther
1309: .'<span>'
1.1037 www 1310: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1311: .'</span> <span>'
1.1037 www 1312: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1313: .'</span>';
1.732 raeburn 1314: unless ($not_author) {
1.763 bisitz 1315: $out .= ' <span>'
1.1037 www 1316: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1317: .'</span> <span>'
1.1075.2.78 raeburn 1318: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1319: .'</span>';
1.732 raeburn 1320: }
1.763 bisitz 1321: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1322: return $out;
1.172 www 1323: }
1324:
1.430 albertel 1325: sub general_help {
1326: my $helptopic='Student_Intro';
1327: if ($env{'request.role'}=~/^(ca|au)/) {
1328: $helptopic='Authoring_Intro';
1.907 raeburn 1329: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1330: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1331: } elsif ($env{'request.role'}=~/^dc/) {
1332: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1333: }
1334: return $helptopic;
1335: }
1336:
1337: sub update_help_link {
1338: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1339: my $origurl = $ENV{'REQUEST_URI'};
1340: $origurl=~s|^/~|/priv/|;
1341: my $timestamp = time;
1342: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1343: $$datum = &escape($$datum);
1344: }
1345:
1346: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1347: my $output .= <<"ENDOUTPUT";
1348: <script type="text/javascript">
1.824 bisitz 1349: // <![CDATA[
1.430 albertel 1350: banner_link = '$banner_link';
1.824 bisitz 1351: // ]]>
1.430 albertel 1352: </script>
1353: ENDOUTPUT
1354: return $output;
1355: }
1356:
1357: # now just updates the help link and generates a blue icon
1.193 raeburn 1358: sub help_open_menu {
1.430 albertel 1359: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1360: = @_;
1.949 droeschl 1361: $stayOnPage = 1;
1.430 albertel 1362: my $output;
1363: if ($component_help) {
1364: if (!$text) {
1365: $output=&help_open_topic($component_help,undef,$stayOnPage,
1366: $width,$height);
1367: } else {
1368: my $help_text;
1369: $help_text=&unescape($topic);
1370: $output='<table><tr><td>'.
1371: &help_open_topic($component_help,$help_text,$stayOnPage,
1372: $width,$height).'</td></tr></table>';
1373: }
1374: }
1375: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1376: return $output.$banner_link;
1377: }
1378:
1379: sub top_nav_help {
1.1075.2.158 raeburn 1380: my ($text,$linkattr) = @_;
1.436 albertel 1381: $text = &mt($text);
1.1075.2.60 raeburn 1382: my $stay_on_page;
1383: unless ($env{'environment.remote'} eq 'on') {
1384: $stay_on_page = 1;
1385: }
1.1075.2.61 raeburn 1386: my ($link,$banner_link);
1387: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1388: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1389: : "javascript:helpMenu('open')";
1390: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1391: }
1.201 raeburn 1392: my $title = &mt('Get help');
1.1075.2.61 raeburn 1393: if ($link) {
1394: return <<"END";
1.436 albertel 1395: $banner_link
1.1075.2.158 raeburn 1396: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1397: END
1.1075.2.61 raeburn 1398: } else {
1399: return ' '.$text.' ';
1400: }
1.436 albertel 1401: }
1402:
1403: sub help_menu_js {
1.1075.2.52 raeburn 1404: my ($httphost) = @_;
1.949 droeschl 1405: my $stayOnPage = 1;
1.436 albertel 1406: my $width = 620;
1407: my $height = 600;
1.430 albertel 1408: my $helptopic=&general_help();
1.1075.2.52 raeburn 1409: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1410: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1411: my $start_page =
1412: &Apache::loncommon::start_page('Help Menu', undef,
1413: {'frameset' => 1,
1414: 'js_ready' => 1,
1.1075.2.136 raeburn 1415: 'use_absolute' => $httphost,
1.331 albertel 1416: 'add_entries' => {
1417: 'border' => '0',
1.579 raeburn 1418: 'rows' => "110,*",},});
1.331 albertel 1419: my $end_page =
1420: &Apache::loncommon::end_page({'frameset' => 1,
1421: 'js_ready' => 1,});
1422:
1.436 albertel 1423: my $template .= <<"ENDTEMPLATE";
1424: <script type="text/javascript">
1.877 bisitz 1425: // <![CDATA[
1.253 albertel 1426: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1427: var banner_link = '';
1.243 raeburn 1428: function helpMenu(target) {
1429: var caller = this;
1430: if (target == 'open') {
1431: var newWindow = null;
1432: try {
1.262 albertel 1433: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1434: }
1435: catch(error) {
1436: writeHelp(caller);
1437: return;
1438: }
1439: if (newWindow) {
1440: caller = newWindow;
1441: }
1.193 raeburn 1442: }
1.243 raeburn 1443: writeHelp(caller);
1444: return;
1445: }
1446: function writeHelp(caller) {
1.1075.2.61 raeburn 1447: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1448: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1449: caller.document.close();
1450: caller.focus();
1.193 raeburn 1451: }
1.877 bisitz 1452: // END LON-CAPA Internal -->
1.253 albertel 1453: // ]]>
1.436 albertel 1454: </script>
1.193 raeburn 1455: ENDTEMPLATE
1456: return $template;
1457: }
1458:
1.172 www 1459: sub help_open_bug {
1460: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1461: unless ($env{'user.adv'}) { return ''; }
1.172 www 1462: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1463: $text = "" if (not defined $text);
1464: $stayOnPage=1;
1.184 albertel 1465: $width = 600 if (not defined $width);
1466: $height = 600 if (not defined $height);
1.172 www 1467:
1468: $topic=~s/\W+/\+/g;
1469: my $link='';
1470: my $template='';
1.379 albertel 1471: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1472: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1473: if (!$stayOnPage)
1474: {
1475: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1476: }
1477: else
1478: {
1479: $link = $url;
1480: }
1481: # Add the text
1482: if ($text ne "")
1483: {
1484: $template .=
1485: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1486: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1487: }
1488:
1489: # Add the graphic
1.179 matthew 1490: my $title = &mt('Report a Bug');
1.215 albertel 1491: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1492: $template .= <<"ENDTEMPLATE";
1.436 albertel 1493: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1494: ENDTEMPLATE
1495: if ($text ne '') { $template.='</td></tr></table>' };
1496: return $template;
1497:
1498: }
1499:
1500: sub help_open_faq {
1501: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1502: unless ($env{'user.adv'}) { return ''; }
1.172 www 1503: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1504: $text = "" if (not defined $text);
1505: $stayOnPage=1;
1506: $width = 350 if (not defined $width);
1507: $height = 400 if (not defined $height);
1508:
1509: $topic=~s/\W+/\+/g;
1510: my $link='';
1511: my $template='';
1512: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1513: if (!$stayOnPage)
1514: {
1515: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1516: }
1517: else
1518: {
1519: $link = $url;
1520: }
1521:
1522: # Add the text
1523: if ($text ne "")
1524: {
1525: $template .=
1.173 www 1526: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1527: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1528: }
1529:
1530: # Add the graphic
1.179 matthew 1531: my $title = &mt('View the FAQ');
1.215 albertel 1532: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1533: $template .= <<"ENDTEMPLATE";
1.436 albertel 1534: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1535: ENDTEMPLATE
1536: if ($text ne '') { $template.='</td></tr></table>' };
1537: return $template;
1538:
1.44 bowersj2 1539: }
1.37 matthew 1540:
1.180 matthew 1541: ###############################################################
1542: ###############################################################
1543:
1.45 matthew 1544: =pod
1545:
1.648 raeburn 1546: =item * &change_content_javascript():
1.256 matthew 1547:
1548: This and the next function allow you to create small sections of an
1549: otherwise static HTML page that you can update on the fly with
1550: Javascript, even in Netscape 4.
1551:
1552: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1553: must be written to the HTML page once. It will prove the Javascript
1554: function "change(name, content)". Calling the change function with the
1555: name of the section
1556: you want to update, matching the name passed to C<changable_area>, and
1557: the new content you want to put in there, will put the content into
1558: that area.
1559:
1560: B<Note>: Netscape 4 only reserves enough space for the changable area
1561: to contain room for the original contents. You need to "make space"
1562: for whatever changes you wish to make, and be B<sure> to check your
1563: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1564: it's adequate for updating a one-line status display, but little more.
1565: This script will set the space to 100% width, so you only need to
1566: worry about height in Netscape 4.
1567:
1568: Modern browsers are much less limiting, and if you can commit to the
1569: user not using Netscape 4, this feature may be used freely with
1570: pretty much any HTML.
1571:
1572: =cut
1573:
1574: sub change_content_javascript {
1575: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1576: if ($env{'browser.type'} eq 'netscape' &&
1577: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1578: return (<<NETSCAPE4);
1579: function change(name, content) {
1580: doc = document.layers[name+"___escape"].layers[0].document;
1581: doc.open();
1582: doc.write(content);
1583: doc.close();
1584: }
1585: NETSCAPE4
1586: } else {
1587: # Otherwise, we need to use semi-standards-compliant code
1588: # (technically, "innerHTML" isn't standard but the equivalent
1589: # is really scary, and every useful browser supports it
1590: return (<<DOMBASED);
1591: function change(name, content) {
1592: element = document.getElementById(name);
1593: element.innerHTML = content;
1594: }
1595: DOMBASED
1596: }
1597: }
1598:
1599: =pod
1600:
1.648 raeburn 1601: =item * &changable_area($name,$origContent):
1.256 matthew 1602:
1603: This provides a "changable area" that can be modified on the fly via
1604: the Javascript code provided in C<change_content_javascript>. $name is
1605: the name you will use to reference the area later; do not repeat the
1606: same name on a given HTML page more then once. $origContent is what
1607: the area will originally contain, which can be left blank.
1608:
1609: =cut
1610:
1611: sub changable_area {
1612: my ($name, $origContent) = @_;
1613:
1.258 albertel 1614: if ($env{'browser.type'} eq 'netscape' &&
1615: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1616: # If this is netscape 4, we need to use the Layer tag
1617: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1618: } else {
1619: return "<span id='$name'>$origContent</span>";
1620: }
1621: }
1622:
1623: =pod
1624:
1.648 raeburn 1625: =item * &viewport_geometry_js
1.590 raeburn 1626:
1627: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1628:
1629: =cut
1630:
1631:
1632: sub viewport_geometry_js {
1633: return <<"GEOMETRY";
1634: var Geometry = {};
1635: function init_geometry() {
1636: if (Geometry.init) { return };
1637: Geometry.init=1;
1638: if (window.innerHeight) {
1639: Geometry.getViewportHeight = function() { return window.innerHeight; };
1640: Geometry.getViewportWidth = function() { return window.innerWidth; };
1641: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1642: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1643: }
1644: else if (document.documentElement && document.documentElement.clientHeight) {
1645: Geometry.getViewportHeight =
1646: function() { return document.documentElement.clientHeight; };
1647: Geometry.getViewportWidth =
1648: function() { return document.documentElement.clientWidth; };
1649:
1650: Geometry.getHorizontalScroll =
1651: function() { return document.documentElement.scrollLeft; };
1652: Geometry.getVerticalScroll =
1653: function() { return document.documentElement.scrollTop; };
1654: }
1655: else if (document.body.clientHeight) {
1656: Geometry.getViewportHeight =
1657: function() { return document.body.clientHeight; };
1658: Geometry.getViewportWidth =
1659: function() { return document.body.clientWidth; };
1660: Geometry.getHorizontalScroll =
1661: function() { return document.body.scrollLeft; };
1662: Geometry.getVerticalScroll =
1663: function() { return document.body.scrollTop; };
1664: }
1665: }
1666:
1667: GEOMETRY
1668: }
1669:
1670: =pod
1671:
1.648 raeburn 1672: =item * &viewport_size_js()
1.590 raeburn 1673:
1674: 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.
1675:
1676: =cut
1677:
1678: sub viewport_size_js {
1679: my $geometry = &viewport_geometry_js();
1680: return <<"DIMS";
1681:
1682: $geometry
1683:
1684: function getViewportDims(width,height) {
1685: init_geometry();
1686: width.value = Geometry.getViewportWidth();
1687: height.value = Geometry.getViewportHeight();
1688: return;
1689: }
1690:
1691: DIMS
1692: }
1693:
1694: =pod
1695:
1.648 raeburn 1696: =item * &resize_textarea_js()
1.565 albertel 1697:
1698: emits the needed javascript to resize a textarea to be as big as possible
1699:
1700: creates a function resize_textrea that takes two IDs first should be
1701: the id of the element to resize, second should be the id of a div that
1702: surrounds everything that comes after the textarea, this routine needs
1703: to be attached to the <body> for the onload and onresize events.
1704:
1.648 raeburn 1705: =back
1.565 albertel 1706:
1707: =cut
1708:
1709: sub resize_textarea_js {
1.590 raeburn 1710: my $geometry = &viewport_geometry_js();
1.565 albertel 1711: return <<"RESIZE";
1712: <script type="text/javascript">
1.824 bisitz 1713: // <![CDATA[
1.590 raeburn 1714: $geometry
1.565 albertel 1715:
1.588 albertel 1716: function getX(element) {
1717: var x = 0;
1718: while (element) {
1719: x += element.offsetLeft;
1720: element = element.offsetParent;
1721: }
1722: return x;
1723: }
1724: function getY(element) {
1725: var y = 0;
1726: while (element) {
1727: y += element.offsetTop;
1728: element = element.offsetParent;
1729: }
1730: return y;
1731: }
1732:
1733:
1.565 albertel 1734: function resize_textarea(textarea_id,bottom_id) {
1735: init_geometry();
1736: var textarea = document.getElementById(textarea_id);
1737: //alert(textarea);
1738:
1.588 albertel 1739: var textarea_top = getY(textarea);
1.565 albertel 1740: var textarea_height = textarea.offsetHeight;
1741: var bottom = document.getElementById(bottom_id);
1.588 albertel 1742: var bottom_top = getY(bottom);
1.565 albertel 1743: var bottom_height = bottom.offsetHeight;
1744: var window_height = Geometry.getViewportHeight();
1.588 albertel 1745: var fudge = 23;
1.565 albertel 1746: var new_height = window_height-fudge-textarea_top-bottom_height;
1747: if (new_height < 300) {
1748: new_height = 300;
1749: }
1750: textarea.style.height=new_height+'px';
1751: }
1.824 bisitz 1752: // ]]>
1.565 albertel 1753: </script>
1754: RESIZE
1755:
1756: }
1757:
1.1075.2.112 raeburn 1758: sub colorfuleditor_js {
1759: return <<"COLORFULEDIT"
1760: <script type="text/javascript">
1761: // <![CDATA[>
1762: function fold_box(curDepth, lastresource){
1763:
1764: // we need a list because there can be several blocks you need to fold in one tag
1765: var block = document.getElementsByName('foldblock_'+curDepth);
1766: // but there is only one folding button per tag
1767: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1768:
1769: if(block.item(0).style.display == 'none'){
1770:
1771: foldbutton.value = '@{[&mt("Hide")]}';
1772: for (i = 0; i < block.length; i++){
1773: block.item(i).style.display = '';
1774: }
1775: }else{
1776:
1777: foldbutton.value = '@{[&mt("Show")]}';
1778: for (i = 0; i < block.length; i++){
1779: // block.item(i).style.visibility = 'collapse';
1780: block.item(i).style.display = 'none';
1781: }
1782: };
1783: saveState(lastresource);
1784: }
1785:
1786: function saveState (lastresource) {
1787:
1788: var tag_list = getTagList();
1789: if(tag_list != null){
1790: var timestamp = new Date().getTime();
1791: var key = lastresource;
1792:
1793: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1794: // starting with timestamp
1795: var value = timestamp+';';
1796:
1797: // building the list of key-value pairs
1798: for(var i = 0; i < tag_list.length; i++){
1799: value += tag_list[i]+',';
1800: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1801: }
1802:
1803: // only iterate whole storage if nothing to override
1804: if(localStorage.getItem(key) == null){
1805:
1806: // prevent storage from growing large
1807: if(localStorage.length > 50){
1808: var regex_getTimestamp = /^(?:\d)+;/;
1809: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1810: var oldest_key;
1811:
1812: for(var i = 1; i < localStorage.length; i++){
1813: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1814: oldest_key = localStorage.key(i);
1815: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1816: }
1817: }
1818: localStorage.removeItem(oldest_key);
1819: }
1820: }
1821: localStorage.setItem(key,value);
1822: }
1823: }
1824:
1825: // restore folding status of blocks (on page load)
1826: function restoreState (lastresource) {
1827: if(localStorage.getItem(lastresource) != null){
1828: var key = lastresource;
1829: var value = localStorage.getItem(key);
1830: var regex_delTimestamp = /^\d+;/;
1831:
1832: value.replace(regex_delTimestamp, '');
1833:
1834: var valueArr = value.split(';');
1835: var pairs;
1836: var elements;
1837: for (var i = 0; i < valueArr.length; i++){
1838: pairs = valueArr[i].split(',');
1839: elements = document.getElementsByName(pairs[0]);
1840:
1841: for (var j = 0; j < elements.length; j++){
1842: elements[j].style.display = pairs[1];
1843: if (pairs[1] == "none"){
1844: var regex_id = /([_\\d]+)\$/;
1845: regex_id.exec(pairs[0]);
1846: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1847: }
1848: }
1849: }
1850: }
1851: }
1852:
1853: function getTagList () {
1854:
1855: var stringToSearch = document.lonhomework.innerHTML;
1856:
1857: var ret = new Array();
1858: var regex_findBlock = /(foldblock_.*?)"/g;
1859: var tag_list = stringToSearch.match(regex_findBlock);
1860:
1861: if(tag_list != null){
1862: for(var i = 0; i < tag_list.length; i++){
1863: ret.push(tag_list[i].replace(/"/, ''));
1864: }
1865: }
1866: return ret;
1867: }
1868:
1869: function saveScrollPosition (resource) {
1870: var tag_list = getTagList();
1871:
1872: // we dont always want to jump to the first block
1873: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1874: if(\$(window).scrollTop() > 170){
1875: if(tag_list != null){
1876: var result;
1877: for(var i = 0; i < tag_list.length; i++){
1878: if(isElementInViewport(tag_list[i])){
1879: result += tag_list[i]+';';
1880: }
1881: }
1882: sessionStorage.setItem('anchor_'+resource, result);
1883: }
1884: } else {
1885: // we dont need to save zero, just delete the item to leave everything tidy
1886: sessionStorage.removeItem('anchor_'+resource);
1887: }
1888: }
1889:
1890: function restoreScrollPosition(resource){
1891:
1892: var elem = sessionStorage.getItem('anchor_'+resource);
1893: if(elem != null){
1894: var tag_list = elem.split(';');
1895: var elem_list;
1896:
1897: for(var i = 0; i < tag_list.length; i++){
1898: elem_list = document.getElementsByName(tag_list[i]);
1899:
1900: if(elem_list.length > 0){
1901: elem = elem_list[0];
1902: break;
1903: }
1904: }
1905: elem.scrollIntoView();
1906: }
1907: }
1908:
1909: function isElementInViewport(el) {
1910:
1911: // change to last element instead of first
1912: var elem = document.getElementsByName(el);
1913: var rect = elem[0].getBoundingClientRect();
1914:
1915: return (
1916: rect.top >= 0 &&
1917: rect.left >= 0 &&
1918: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1919: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1920: );
1921: }
1922:
1923: function autosize(depth){
1924: var cmInst = window['cm'+depth];
1925: var fitsizeButton = document.getElementById('fitsize'+depth);
1926:
1927: // is fixed size, switching to dynamic
1928: if (sessionStorage.getItem("autosized_"+depth) == null) {
1929: cmInst.setSize("","auto");
1930: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1931: sessionStorage.setItem("autosized_"+depth, "yes");
1932:
1933: // is dynamic size, switching to fixed
1934: } else {
1935: cmInst.setSize("","300px");
1936: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1937: sessionStorage.removeItem("autosized_"+depth);
1938: }
1939: }
1940:
1941:
1942:
1943: // ]]>
1944: </script>
1945: COLORFULEDIT
1946: }
1947:
1948: sub xmleditor_js {
1949: return <<XMLEDIT
1950: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1951: <script type="text/javascript">
1952: // <![CDATA[>
1953:
1954: function saveScrollPosition (resource) {
1955:
1956: var scrollPos = \$(window).scrollTop();
1957: sessionStorage.setItem(resource,scrollPos);
1958: }
1959:
1960: function restoreScrollPosition(resource){
1961:
1962: var scrollPos = sessionStorage.getItem(resource);
1963: \$(window).scrollTop(scrollPos);
1964: }
1965:
1966: // unless internet explorer
1967: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1968:
1969: \$(document).ready(function() {
1970: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1971: });
1972: }
1973:
1974: // inserts text at cursor position into codemirror (xml editor only)
1975: function insertText(text){
1976: cm.focus();
1977: var curPos = cm.getCursor();
1978: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1979: }
1980: // ]]>
1981: </script>
1982: XMLEDIT
1983: }
1984:
1985: sub insert_folding_button {
1986: my $curDepth = $Apache::lonxml::curdepth;
1987: my $lastresource = $env{'request.ambiguous'};
1988:
1989: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
1990: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
1991: }
1992:
1993:
1.565 albertel 1994: =pod
1995:
1.256 matthew 1996: =head1 Excel and CSV file utility routines
1997:
1998: =cut
1999:
2000: ###############################################################
2001: ###############################################################
2002:
2003: =pod
2004:
1.1075.2.56 raeburn 2005: =over 4
2006:
1.648 raeburn 2007: =item * &csv_translate($text)
1.37 matthew 2008:
1.185 www 2009: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2010: format.
2011:
2012: =cut
2013:
1.180 matthew 2014: ###############################################################
2015: ###############################################################
1.37 matthew 2016: sub csv_translate {
2017: my $text = shift;
2018: $text =~ s/\"/\"\"/g;
1.209 albertel 2019: $text =~ s/\n/ /g;
1.37 matthew 2020: return $text;
2021: }
1.180 matthew 2022:
2023: ###############################################################
2024: ###############################################################
2025:
2026: =pod
2027:
1.648 raeburn 2028: =item * &define_excel_formats()
1.180 matthew 2029:
2030: Define some commonly used Excel cell formats.
2031:
2032: Currently supported formats:
2033:
2034: =over 4
2035:
2036: =item header
2037:
2038: =item bold
2039:
2040: =item h1
2041:
2042: =item h2
2043:
2044: =item h3
2045:
1.256 matthew 2046: =item h4
2047:
2048: =item i
2049:
1.180 matthew 2050: =item date
2051:
2052: =back
2053:
2054: Inputs: $workbook
2055:
2056: Returns: $format, a hash reference.
2057:
1.1057 foxr 2058:
1.180 matthew 2059: =cut
2060:
2061: ###############################################################
2062: ###############################################################
2063: sub define_excel_formats {
2064: my ($workbook) = @_;
2065: my $format;
2066: $format->{'header'} = $workbook->add_format(bold => 1,
2067: bottom => 1,
2068: align => 'center');
2069: $format->{'bold'} = $workbook->add_format(bold=>1);
2070: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2071: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2072: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2073: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2074: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2075: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2076: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2077: return $format;
2078: }
2079:
2080: ###############################################################
2081: ###############################################################
1.113 bowersj2 2082:
2083: =pod
2084:
1.648 raeburn 2085: =item * &create_workbook()
1.255 matthew 2086:
2087: Create an Excel worksheet. If it fails, output message on the
2088: request object and return undefs.
2089:
2090: Inputs: Apache request object
2091:
2092: Returns (undef) on failure,
2093: Excel worksheet object, scalar with filename, and formats
2094: from &Apache::loncommon::define_excel_formats on success
2095:
2096: =cut
2097:
2098: ###############################################################
2099: ###############################################################
2100: sub create_workbook {
2101: my ($r) = @_;
2102: #
2103: # Create the excel spreadsheet
2104: my $filename = '/prtspool/'.
1.258 albertel 2105: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2106: time.'_'.rand(1000000000).'.xls';
2107: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2108: if (! defined($workbook)) {
2109: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2110: $r->print(
2111: '<p class="LC_error">'
2112: .&mt('Problems occurred in creating the new Excel file.')
2113: .' '.&mt('This error has been logged.')
2114: .' '.&mt('Please alert your LON-CAPA administrator.')
2115: .'</p>'
2116: );
1.255 matthew 2117: return (undef);
2118: }
2119: #
1.1014 foxr 2120: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2121: #
2122: my $format = &Apache::loncommon::define_excel_formats($workbook);
2123: return ($workbook,$filename,$format);
2124: }
2125:
2126: ###############################################################
2127: ###############################################################
2128:
2129: =pod
2130:
1.648 raeburn 2131: =item * &create_text_file()
1.113 bowersj2 2132:
1.542 raeburn 2133: Create a file to write to and eventually make available to the user.
1.256 matthew 2134: If file creation fails, outputs an error message on the request object and
2135: return undefs.
1.113 bowersj2 2136:
1.256 matthew 2137: Inputs: Apache request object, and file suffix
1.113 bowersj2 2138:
1.256 matthew 2139: Returns (undef) on failure,
2140: Filehandle and filename on success.
1.113 bowersj2 2141:
2142: =cut
2143:
1.256 matthew 2144: ###############################################################
2145: ###############################################################
2146: sub create_text_file {
2147: my ($r,$suffix) = @_;
2148: if (! defined($suffix)) { $suffix = 'txt'; };
2149: my $fh;
2150: my $filename = '/prtspool/'.
1.258 albertel 2151: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2152: time.'_'.rand(1000000000).'.'.$suffix;
2153: $fh = Apache::File->new('>/home/httpd'.$filename);
2154: if (! defined($fh)) {
2155: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2156: $r->print(
2157: '<p class="LC_error">'
2158: .&mt('Problems occurred in creating the output file.')
2159: .' '.&mt('This error has been logged.')
2160: .' '.&mt('Please alert your LON-CAPA administrator.')
2161: .'</p>'
2162: );
1.113 bowersj2 2163: }
1.256 matthew 2164: return ($fh,$filename)
1.113 bowersj2 2165: }
2166:
2167:
1.256 matthew 2168: =pod
1.113 bowersj2 2169:
2170: =back
2171:
2172: =cut
1.37 matthew 2173:
2174: ###############################################################
1.33 matthew 2175: ## Home server <option> list generating code ##
2176: ###############################################################
1.35 matthew 2177:
1.169 www 2178: # ------------------------------------------
2179:
2180: sub domain_select {
2181: my ($name,$value,$multiple)=@_;
2182: my %domains=map {
1.514 albertel 2183: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2184: } &Apache::lonnet::all_domains();
1.169 www 2185: if ($multiple) {
2186: $domains{''}=&mt('Any domain');
1.550 albertel 2187: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2188: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2189: } else {
1.550 albertel 2190: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2191: return &select_form($name,$value,\%domains);
1.169 www 2192: }
2193: }
2194:
1.282 albertel 2195: #-------------------------------------------
2196:
2197: =pod
2198:
1.519 raeburn 2199: =head1 Routines for form select boxes
2200:
2201: =over 4
2202:
1.648 raeburn 2203: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2204:
2205: Returns a string containing a <select> element int multiple mode
2206:
2207:
2208: Args:
2209: $name - name of the <select> element
1.506 raeburn 2210: $value - scalar or array ref of values that should already be selected
1.282 albertel 2211: $size - number of rows long the select element is
1.283 albertel 2212: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2213: (shown text should already have been &mt())
1.506 raeburn 2214: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2215:
1.282 albertel 2216: =cut
2217:
2218: #-------------------------------------------
1.169 www 2219: sub multiple_select_form {
1.284 albertel 2220: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2221: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2222: my $output='';
1.191 matthew 2223: if (! defined($size)) {
2224: $size = 4;
1.283 albertel 2225: if (scalar(keys(%$hash))<4) {
2226: $size = scalar(keys(%$hash));
1.191 matthew 2227: }
2228: }
1.734 bisitz 2229: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2230: my @order;
1.506 raeburn 2231: if (ref($order) eq 'ARRAY') {
2232: @order = @{$order};
2233: } else {
2234: @order = sort(keys(%$hash));
1.501 banghart 2235: }
2236: if (exists($$hash{'select_form_order'})) {
2237: @order = @{$$hash{'select_form_order'}};
2238: }
2239:
1.284 albertel 2240: foreach my $key (@order) {
1.356 albertel 2241: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2242: $output.='selected="selected" ' if ($selected{$key});
2243: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2244: }
2245: $output.="</select>\n";
2246: return $output;
2247: }
2248:
1.88 www 2249: #-------------------------------------------
2250:
2251: =pod
2252:
1.1075.2.115 raeburn 2253: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2254:
2255: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2256: allow a user to select options from a ref to a hash containing:
2257: option_name => displayed text. An optional $onchange can include
1.1075.2.115 raeburn 2258: a javascript onchange item, e.g., onchange="this.form.submit();".
2259: An optional arg -- $readonly -- if true will cause the select form
2260: to be disabled, e.g., for the case where an instructor has a section-
2261: specific role, and is viewing/modifying parameters.
1.970 raeburn 2262:
1.88 www 2263: See lonrights.pm for an example invocation and use.
2264:
2265: =cut
2266:
2267: #-------------------------------------------
2268: sub select_form {
1.1075.2.115 raeburn 2269: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2270: return unless (ref($hashref) eq 'HASH');
2271: if ($onchange) {
2272: $onchange = ' onchange="'.$onchange.'"';
2273: }
1.1075.2.129 raeburn 2274: my $disabled;
2275: if ($readonly) {
2276: $disabled = ' disabled="disabled"';
2277: }
2278: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2279: my @keys;
1.970 raeburn 2280: if (exists($hashref->{'select_form_order'})) {
2281: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2282: } else {
1.970 raeburn 2283: @keys=sort(keys(%{$hashref}));
1.128 albertel 2284: }
1.356 albertel 2285: foreach my $key (@keys) {
2286: $selectform.=
2287: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2288: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2289: ">".$hashref->{$key}."</option>\n";
1.88 www 2290: }
2291: $selectform.="</select>";
2292: return $selectform;
2293: }
2294:
1.475 www 2295: # For display filters
2296:
2297: sub display_filter {
1.1074 raeburn 2298: my ($context) = @_;
1.475 www 2299: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2300: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2301: my $phraseinput = 'hidden';
2302: my $includeinput = 'hidden';
2303: my ($checked,$includetypestext);
2304: if ($env{'form.displayfilter'} eq 'containing') {
2305: $phraseinput = 'text';
2306: if ($context eq 'parmslog') {
2307: $includeinput = 'checkbox';
2308: if ($env{'form.includetypes'}) {
2309: $checked = ' checked="checked"';
2310: }
2311: $includetypestext = &mt('Include parameter types');
2312: }
2313: } else {
2314: $includetypestext = ' ';
2315: }
2316: my ($additional,$secondid,$thirdid);
2317: if ($context eq 'parmslog') {
2318: $additional =
2319: '<label><input type="'.$includeinput.'" name="includetypes"'.
2320: $checked.' name="includetypes" value="1" id="includetypes" />'.
2321: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2322: '</label>';
2323: $secondid = 'includetypes';
2324: $thirdid = 'includetypestext';
2325: }
2326: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2327: '$secondid','$thirdid')";
2328: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2329: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2330: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2331: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2332: &mt('Filter: [_1]',
1.477 www 2333: &select_form($env{'form.displayfilter'},
2334: 'displayfilter',
1.970 raeburn 2335: {'currentfolder' => 'Current folder/page',
1.477 www 2336: 'containing' => 'Containing phrase',
1.1074 raeburn 2337: 'none' => 'None'},$onchange)).' '.
2338: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2339: &HTML::Entities::encode($env{'form.containingphrase'}).
2340: '" />'.$additional;
2341: }
2342:
2343: sub display_filter_js {
2344: my $includetext = &mt('Include parameter types');
2345: return <<"ENDJS";
2346:
2347: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2348: var firstType = 'hidden';
2349: if (setter.options[setter.selectedIndex].value == 'containing') {
2350: firstType = 'text';
2351: }
2352: firstObject = document.getElementById(firstid);
2353: if (typeof(firstObject) == 'object') {
2354: if (firstObject.type != firstType) {
2355: changeInputType(firstObject,firstType);
2356: }
2357: }
2358: if (context == 'parmslog') {
2359: var secondType = 'hidden';
2360: if (firstType == 'text') {
2361: secondType = 'checkbox';
2362: }
2363: secondObject = document.getElementById(secondid);
2364: if (typeof(secondObject) == 'object') {
2365: if (secondObject.type != secondType) {
2366: changeInputType(secondObject,secondType);
2367: }
2368: }
2369: var textItem = document.getElementById(thirdid);
2370: var currtext = textItem.innerHTML;
2371: var newtext;
2372: if (firstType == 'text') {
2373: newtext = '$includetext';
2374: } else {
2375: newtext = ' ';
2376: }
2377: if (currtext != newtext) {
2378: textItem.innerHTML = newtext;
2379: }
2380: }
2381: return;
2382: }
2383:
2384: function changeInputType(oldObject,newType) {
2385: var newObject = document.createElement('input');
2386: newObject.type = newType;
2387: if (oldObject.size) {
2388: newObject.size = oldObject.size;
2389: }
2390: if (oldObject.value) {
2391: newObject.value = oldObject.value;
2392: }
2393: if (oldObject.name) {
2394: newObject.name = oldObject.name;
2395: }
2396: if (oldObject.id) {
2397: newObject.id = oldObject.id;
2398: }
2399: oldObject.parentNode.replaceChild(newObject,oldObject);
2400: return;
2401: }
2402:
2403: ENDJS
1.475 www 2404: }
2405:
1.167 www 2406: sub gradeleveldescription {
2407: my $gradelevel=shift;
2408: my %gradelevels=(0 => 'Not specified',
2409: 1 => 'Grade 1',
2410: 2 => 'Grade 2',
2411: 3 => 'Grade 3',
2412: 4 => 'Grade 4',
2413: 5 => 'Grade 5',
2414: 6 => 'Grade 6',
2415: 7 => 'Grade 7',
2416: 8 => 'Grade 8',
2417: 9 => 'Grade 9',
2418: 10 => 'Grade 10',
2419: 11 => 'Grade 11',
2420: 12 => 'Grade 12',
2421: 13 => 'Grade 13',
2422: 14 => '100 Level',
2423: 15 => '200 Level',
2424: 16 => '300 Level',
2425: 17 => '400 Level',
2426: 18 => 'Graduate Level');
2427: return &mt($gradelevels{$gradelevel});
2428: }
2429:
1.163 www 2430: sub select_level_form {
2431: my ($deflevel,$name)=@_;
2432: unless ($deflevel) { $deflevel=0; }
1.167 www 2433: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2434: for (my $i=0; $i<=18; $i++) {
2435: $selectform.="<option value=\"$i\" ".
1.253 albertel 2436: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2437: ">".&gradeleveldescription($i)."</option>\n";
2438: }
2439: $selectform.="</select>";
2440: return $selectform;
1.163 www 2441: }
1.167 www 2442:
1.35 matthew 2443: #-------------------------------------------
2444:
1.45 matthew 2445: =pod
2446:
1.1075.2.115 raeburn 2447: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2448:
2449: Returns a string containing a <select name='$name' size='1'> form to
2450: allow a user to select the domain to preform an operation in.
2451: See loncreateuser.pm for an example invocation and use.
2452:
1.90 www 2453: If the $includeempty flag is set, it also includes an empty choice ("no domain
2454: selected");
2455:
1.743 raeburn 2456: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2457:
1.910 raeburn 2458: 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.
2459:
1.1075.2.36 raeburn 2460: The optional $incdoms is a reference to an array of domains which will be the only available options.
2461:
1.1075.2.115 raeburn 2462: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
2463:
2464: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
1.563 raeburn 2465:
1.35 matthew 2466: =cut
2467:
2468: #-------------------------------------------
1.34 matthew 2469: sub select_dom_form {
1.1075.2.115 raeburn 2470: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2471: if ($onchange) {
1.874 raeburn 2472: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2473: }
1.1075.2.115 raeburn 2474: if ($disabled) {
2475: $disabled = ' disabled="disabled"';
2476: }
1.1075.2.36 raeburn 2477: my (@domains,%exclude);
1.910 raeburn 2478: if (ref($incdoms) eq 'ARRAY') {
2479: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2480: } else {
2481: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2482: }
1.90 www 2483: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2484: if (ref($excdoms) eq 'ARRAY') {
2485: map { $exclude{$_} = 1; } @{$excdoms};
2486: }
1.1075.2.115 raeburn 2487: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2488: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2489: next if ($exclude{$dom});
1.356 albertel 2490: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2491: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2492: if ($showdomdesc) {
2493: if ($dom ne '') {
2494: my $domdesc = &Apache::lonnet::domain($dom,'description');
2495: if ($domdesc ne '') {
2496: $selectdomain .= ' ('.$domdesc.')';
2497: }
2498: }
2499: }
2500: $selectdomain .= "</option>\n";
1.34 matthew 2501: }
2502: $selectdomain.="</select>";
2503: return $selectdomain;
2504: }
2505:
1.35 matthew 2506: #-------------------------------------------
2507:
1.45 matthew 2508: =pod
2509:
1.648 raeburn 2510: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2511:
1.586 raeburn 2512: input: 4 arguments (two required, two optional) -
2513: $domain - domain of new user
2514: $name - name of form element
2515: $default - Value of 'default' causes a default item to be first
2516: option, and selected by default.
2517: $hide - Value of 'hide' causes hiding of the name of the server,
2518: if 1 server found, or default, if 0 found.
1.594 raeburn 2519: output: returns 2 items:
1.586 raeburn 2520: (a) form element which contains either:
2521: (i) <select name="$name">
2522: <option value="$hostid1">$hostid $servers{$hostid}</option>
2523: <option value="$hostid2">$hostid $servers{$hostid}</option>
2524: </select>
2525: form item if there are multiple library servers in $domain, or
2526: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2527: if there is only one library server in $domain.
2528:
2529: (b) number of library servers found.
2530:
2531: See loncreateuser.pm for example of use.
1.35 matthew 2532:
2533: =cut
2534:
2535: #-------------------------------------------
1.586 raeburn 2536: sub home_server_form_item {
2537: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2538: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2539: my $result;
2540: my $numlib = keys(%servers);
2541: if ($numlib > 1) {
2542: $result .= '<select name="'.$name.'" />'."\n";
2543: if ($default) {
1.804 bisitz 2544: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2545: '</option>'."\n";
2546: }
2547: foreach my $hostid (sort(keys(%servers))) {
2548: $result.= '<option value="'.$hostid.'">'.
2549: $hostid.' '.$servers{$hostid}."</option>\n";
2550: }
2551: $result .= '</select>'."\n";
2552: } elsif ($numlib == 1) {
2553: my $hostid;
2554: foreach my $item (keys(%servers)) {
2555: $hostid = $item;
2556: }
2557: $result .= '<input type="hidden" name="'.$name.'" value="'.
2558: $hostid.'" />';
2559: if (!$hide) {
2560: $result .= $hostid.' '.$servers{$hostid};
2561: }
2562: $result .= "\n";
2563: } elsif ($default) {
2564: $result .= '<input type="hidden" name="'.$name.
2565: '" value="default" />';
2566: if (!$hide) {
2567: $result .= &mt('default');
2568: }
2569: $result .= "\n";
1.33 matthew 2570: }
1.586 raeburn 2571: return ($result,$numlib);
1.33 matthew 2572: }
1.112 bowersj2 2573:
2574: =pod
2575:
1.534 albertel 2576: =back
2577:
1.112 bowersj2 2578: =cut
1.87 matthew 2579:
2580: ###############################################################
1.112 bowersj2 2581: ## Decoding User Agent ##
1.87 matthew 2582: ###############################################################
2583:
2584: =pod
2585:
1.112 bowersj2 2586: =head1 Decoding the User Agent
2587:
2588: =over 4
2589:
2590: =item * &decode_user_agent()
1.87 matthew 2591:
2592: Inputs: $r
2593:
2594: Outputs:
2595:
2596: =over 4
2597:
1.112 bowersj2 2598: =item * $httpbrowser
1.87 matthew 2599:
1.112 bowersj2 2600: =item * $clientbrowser
1.87 matthew 2601:
1.112 bowersj2 2602: =item * $clientversion
1.87 matthew 2603:
1.112 bowersj2 2604: =item * $clientmathml
1.87 matthew 2605:
1.112 bowersj2 2606: =item * $clientunicode
1.87 matthew 2607:
1.112 bowersj2 2608: =item * $clientos
1.87 matthew 2609:
1.1075.2.42 raeburn 2610: =item * $clientmobile
2611:
2612: =item * $clientinfo
2613:
1.1075.2.77 raeburn 2614: =item * $clientosversion
2615:
1.87 matthew 2616: =back
2617:
1.157 matthew 2618: =back
2619:
1.87 matthew 2620: =cut
2621:
2622: ###############################################################
2623: ###############################################################
2624: sub decode_user_agent {
1.247 albertel 2625: my ($r)=@_;
1.87 matthew 2626: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2627: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2628: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2629: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2630: my $clientbrowser='unknown';
2631: my $clientversion='0';
2632: my $clientmathml='';
2633: my $clientunicode='0';
1.1075.2.42 raeburn 2634: my $clientmobile=0;
1.1075.2.77 raeburn 2635: my $clientosversion='';
1.87 matthew 2636: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2637: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2638: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2639: $clientbrowser=$bname;
2640: $httpbrowser=~/$vreg/i;
2641: $clientversion=$1;
2642: $clientmathml=($clientversion>=$minv);
2643: $clientunicode=($clientversion>=$univ);
2644: }
2645: }
2646: my $clientos='unknown';
1.1075.2.42 raeburn 2647: my $clientinfo;
1.87 matthew 2648: if (($httpbrowser=~/linux/i) ||
2649: ($httpbrowser=~/unix/i) ||
2650: ($httpbrowser=~/ux/i) ||
2651: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2652: if (($httpbrowser=~/vax/i) ||
2653: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2654: if ($httpbrowser=~/next/i) { $clientos='next'; }
2655: if (($httpbrowser=~/mac/i) ||
2656: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2657: if ($httpbrowser=~/win/i) {
2658: $clientos='win';
2659: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2660: $clientosversion = $1;
2661: }
2662: }
1.87 matthew 2663: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2664: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2665: $clientmobile=lc($1);
2666: }
2667: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2668: $clientinfo = 'firefox-'.$1;
2669: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2670: $clientinfo = 'chromeframe-'.$1;
2671: }
1.87 matthew 2672: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2673: $clientunicode,$clientos,$clientmobile,$clientinfo,
2674: $clientosversion);
1.87 matthew 2675: }
2676:
1.32 matthew 2677: ###############################################################
2678: ## Authentication changing form generation subroutines ##
2679: ###############################################################
2680: ##
2681: ## All of the authform_xxxxxxx subroutines take their inputs in a
2682: ## hash, and have reasonable default values.
2683: ##
2684: ## formname = the name given in the <form> tag.
1.35 matthew 2685: #-------------------------------------------
2686:
1.45 matthew 2687: =pod
2688:
1.112 bowersj2 2689: =head1 Authentication Routines
2690:
2691: =over 4
2692:
1.648 raeburn 2693: =item * &authform_xxxxxx()
1.35 matthew 2694:
2695: The authform_xxxxxx subroutines provide javascript and html forms which
2696: handle some of the conveniences required for authentication forms.
2697: This is not an optimal method, but it works.
2698:
2699: =over 4
2700:
1.112 bowersj2 2701: =item * authform_header
1.35 matthew 2702:
1.112 bowersj2 2703: =item * authform_authorwarning
1.35 matthew 2704:
1.112 bowersj2 2705: =item * authform_nochange
1.35 matthew 2706:
1.112 bowersj2 2707: =item * authform_kerberos
1.35 matthew 2708:
1.112 bowersj2 2709: =item * authform_internal
1.35 matthew 2710:
1.112 bowersj2 2711: =item * authform_filesystem
1.35 matthew 2712:
2713: =back
2714:
1.648 raeburn 2715: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2716:
1.35 matthew 2717: =cut
2718:
2719: #-------------------------------------------
1.32 matthew 2720: sub authform_header{
2721: my %in = (
2722: formname => 'cu',
1.80 albertel 2723: kerb_def_dom => '',
1.32 matthew 2724: @_,
2725: );
2726: $in{'formname'} = 'document.' . $in{'formname'};
2727: my $result='';
1.80 albertel 2728:
2729: #---------------------------------------------- Code for upper case translation
2730: my $Javascript_toUpperCase;
2731: unless ($in{kerb_def_dom}) {
2732: $Javascript_toUpperCase =<<"END";
2733: switch (choice) {
2734: case 'krb': currentform.elements[choicearg].value =
2735: currentform.elements[choicearg].value.toUpperCase();
2736: break;
2737: default:
2738: }
2739: END
2740: } else {
2741: $Javascript_toUpperCase = "";
2742: }
2743:
1.165 raeburn 2744: my $radioval = "'nochange'";
1.591 raeburn 2745: if (defined($in{'curr_authtype'})) {
2746: if ($in{'curr_authtype'} ne '') {
2747: $radioval = "'".$in{'curr_authtype'}."arg'";
2748: }
1.174 matthew 2749: }
1.165 raeburn 2750: my $argfield = 'null';
1.591 raeburn 2751: if (defined($in{'mode'})) {
1.165 raeburn 2752: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2753: if (defined($in{'curr_autharg'})) {
2754: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2755: $argfield = "'$in{'curr_autharg'}'";
2756: }
2757: }
2758: }
2759: }
2760:
1.32 matthew 2761: $result.=<<"END";
2762: var current = new Object();
1.165 raeburn 2763: current.radiovalue = $radioval;
2764: current.argfield = $argfield;
1.32 matthew 2765:
2766: function changed_radio(choice,currentform) {
2767: var choicearg = choice + 'arg';
2768: // If a radio button in changed, we need to change the argfield
2769: if (current.radiovalue != choice) {
2770: current.radiovalue = choice;
2771: if (current.argfield != null) {
2772: currentform.elements[current.argfield].value = '';
2773: }
2774: if (choice == 'nochange') {
2775: current.argfield = null;
2776: } else {
2777: current.argfield = choicearg;
2778: switch(choice) {
2779: case 'krb':
2780: currentform.elements[current.argfield].value =
2781: "$in{'kerb_def_dom'}";
2782: break;
2783: default:
2784: break;
2785: }
2786: }
2787: }
2788: return;
2789: }
1.22 www 2790:
1.32 matthew 2791: function changed_text(choice,currentform) {
2792: var choicearg = choice + 'arg';
2793: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2794: $Javascript_toUpperCase
1.32 matthew 2795: // clear old field
2796: if ((current.argfield != choicearg) && (current.argfield != null)) {
2797: currentform.elements[current.argfield].value = '';
2798: }
2799: current.argfield = choicearg;
2800: }
2801: set_auth_radio_buttons(choice,currentform);
2802: return;
1.20 www 2803: }
1.32 matthew 2804:
2805: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2806: var numauthchoices = currentform.login.length;
2807: if (typeof numauthchoices == "undefined") {
2808: return;
2809: }
1.32 matthew 2810: var i=0;
1.986 raeburn 2811: while (i < numauthchoices) {
1.32 matthew 2812: if (currentform.login[i].value == newvalue) { break; }
2813: i++;
2814: }
1.986 raeburn 2815: if (i == numauthchoices) {
1.32 matthew 2816: return;
2817: }
2818: current.radiovalue = newvalue;
2819: currentform.login[i].checked = true;
2820: return;
2821: }
2822: END
2823: return $result;
2824: }
2825:
1.1075.2.20 raeburn 2826: sub authform_authorwarning {
1.32 matthew 2827: my $result='';
1.144 matthew 2828: $result='<i>'.
2829: &mt('As a general rule, only authors or co-authors should be '.
2830: 'filesystem authenticated '.
2831: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2832: return $result;
2833: }
2834:
1.1075.2.20 raeburn 2835: sub authform_nochange {
1.32 matthew 2836: my %in = (
2837: formname => 'document.cu',
2838: kerb_def_dom => 'MSU.EDU',
2839: @_,
2840: );
1.1075.2.20 raeburn 2841: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2842: my $result;
1.1075.2.20 raeburn 2843: if (!$authnum) {
2844: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2845: } else {
2846: $result = '<label>'.&mt('[_1] Do not change login data',
2847: '<input type="radio" name="login" value="nochange" '.
2848: 'checked="checked" onclick="'.
1.281 albertel 2849: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2850: '</label>';
1.586 raeburn 2851: }
1.32 matthew 2852: return $result;
2853: }
2854:
1.591 raeburn 2855: sub authform_kerberos {
1.32 matthew 2856: my %in = (
2857: formname => 'document.cu',
2858: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2859: kerb_def_auth => 'krb4',
1.32 matthew 2860: @_,
2861: );
1.586 raeburn 2862: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1075.2.117 raeburn 2863: $autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2864: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2865: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2866: $check5 = ' checked="checked"';
1.80 albertel 2867: } else {
1.772 bisitz 2868: $check4 = ' checked="checked"';
1.80 albertel 2869: }
1.1075.2.117 raeburn 2870: if ($in{'readonly'}) {
2871: $disabled = ' disabled="disabled"';
2872: }
1.165 raeburn 2873: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2874: if (defined($in{'curr_authtype'})) {
2875: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2876: $krbcheck = ' checked="checked"';
1.623 raeburn 2877: if (defined($in{'mode'})) {
2878: if ($in{'mode'} eq 'modifyuser') {
2879: $krbcheck = '';
2880: }
2881: }
1.591 raeburn 2882: if (defined($in{'curr_kerb_ver'})) {
2883: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2884: $check5 = ' checked="checked"';
1.591 raeburn 2885: $check4 = '';
2886: } else {
1.772 bisitz 2887: $check4 = ' checked="checked"';
1.591 raeburn 2888: $check5 = '';
2889: }
1.586 raeburn 2890: }
1.591 raeburn 2891: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2892: $krbarg = $in{'curr_autharg'};
2893: }
1.586 raeburn 2894: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2895: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2896: $result =
2897: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2898: $in{'curr_autharg'},$krbver);
2899: } else {
2900: $result =
2901: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2902: }
2903: return $result;
2904: }
2905: }
2906: } else {
2907: if ($authnum == 1) {
1.784 bisitz 2908: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2909: }
2910: }
1.586 raeburn 2911: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2912: return;
1.587 raeburn 2913: } elsif ($authtype eq '') {
1.591 raeburn 2914: if (defined($in{'mode'})) {
1.587 raeburn 2915: if ($in{'mode'} eq 'modifycourse') {
2916: if ($authnum == 1) {
1.1075.2.117 raeburn 2917: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 2918: }
2919: }
2920: }
1.586 raeburn 2921: }
2922: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2923: if ($authtype eq '') {
2924: $authtype = '<input type="radio" name="login" value="krb" '.
2925: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1075.2.117 raeburn 2926: $krbcheck.$disabled.' />';
1.586 raeburn 2927: }
2928: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2929: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2930: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2931: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2932: $in{'curr_authtype'} eq 'krb4')) {
2933: $result .= &mt
1.144 matthew 2934: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2935: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2936: '<label>'.$authtype,
1.281 albertel 2937: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2938: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2939: 'onchange="'.$jscall.'"'.$disabled.' />',
2940: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
2941: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 2942: '</label>');
1.586 raeburn 2943: } elsif ($can_assign{'krb4'}) {
2944: $result .= &mt
2945: ('[_1] Kerberos authenticated with domain [_2] '.
2946: '[_3] Version 4 [_4]',
2947: '<label>'.$authtype,
2948: '</label><input type="text" size="10" name="krbarg" '.
2949: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2950: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2951: '<label><input type="hidden" name="krbver" value="4" />',
2952: '</label>');
2953: } elsif ($can_assign{'krb5'}) {
2954: $result .= &mt
2955: ('[_1] Kerberos authenticated with domain [_2] '.
2956: '[_3] Version 5 [_4]',
2957: '<label>'.$authtype,
2958: '</label><input type="text" size="10" name="krbarg" '.
2959: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2960: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2961: '<label><input type="hidden" name="krbver" value="5" />',
2962: '</label>');
2963: }
1.32 matthew 2964: return $result;
2965: }
2966:
1.1075.2.20 raeburn 2967: sub authform_internal {
1.586 raeburn 2968: my %in = (
1.32 matthew 2969: formname => 'document.cu',
2970: kerb_def_dom => 'MSU.EDU',
2971: @_,
2972: );
1.1075.2.117 raeburn 2973: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2974: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 2975: if ($in{'readonly'}) {
2976: $disabled = ' disabled="disabled"';
2977: }
1.591 raeburn 2978: if (defined($in{'curr_authtype'})) {
2979: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2980: if ($can_assign{'int'}) {
1.772 bisitz 2981: $intcheck = 'checked="checked" ';
1.623 raeburn 2982: if (defined($in{'mode'})) {
2983: if ($in{'mode'} eq 'modifyuser') {
2984: $intcheck = '';
2985: }
2986: }
1.591 raeburn 2987: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2988: $intarg = $in{'curr_autharg'};
2989: }
2990: } else {
2991: $result = &mt('Currently internally authenticated.');
2992: return $result;
1.165 raeburn 2993: }
2994: }
1.586 raeburn 2995: } else {
2996: if ($authnum == 1) {
1.784 bisitz 2997: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2998: }
2999: }
3000: if (!$can_assign{'int'}) {
3001: return;
1.587 raeburn 3002: } elsif ($authtype eq '') {
1.591 raeburn 3003: if (defined($in{'mode'})) {
1.587 raeburn 3004: if ($in{'mode'} eq 'modifycourse') {
3005: if ($authnum == 1) {
1.1075.2.117 raeburn 3006: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3007: }
3008: }
3009: }
1.165 raeburn 3010: }
1.586 raeburn 3011: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3012: if ($authtype eq '') {
3013: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1075.2.117 raeburn 3014: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3015: }
1.605 bisitz 3016: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1075.2.117 raeburn 3017: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3018: $result = &mt
1.144 matthew 3019: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3020: '<label>'.$authtype,'</label>'.$autharg);
1.1075.2.118 raeburn 3021: $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 3022: return $result;
3023: }
3024:
1.1075.2.20 raeburn 3025: sub authform_local {
1.32 matthew 3026: my %in = (
3027: formname => 'document.cu',
3028: kerb_def_dom => 'MSU.EDU',
3029: @_,
3030: );
1.1075.2.117 raeburn 3031: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3032: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3033: if ($in{'readonly'}) {
3034: $disabled = ' disabled="disabled"';
3035: }
1.591 raeburn 3036: if (defined($in{'curr_authtype'})) {
3037: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3038: if ($can_assign{'loc'}) {
1.772 bisitz 3039: $loccheck = 'checked="checked" ';
1.623 raeburn 3040: if (defined($in{'mode'})) {
3041: if ($in{'mode'} eq 'modifyuser') {
3042: $loccheck = '';
3043: }
3044: }
1.591 raeburn 3045: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3046: $locarg = $in{'curr_autharg'};
3047: }
3048: } else {
3049: $result = &mt('Currently using local (institutional) authentication.');
3050: return $result;
1.165 raeburn 3051: }
3052: }
1.586 raeburn 3053: } else {
3054: if ($authnum == 1) {
1.784 bisitz 3055: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3056: }
3057: }
3058: if (!$can_assign{'loc'}) {
3059: return;
1.587 raeburn 3060: } elsif ($authtype eq '') {
1.591 raeburn 3061: if (defined($in{'mode'})) {
1.587 raeburn 3062: if ($in{'mode'} eq 'modifycourse') {
3063: if ($authnum == 1) {
1.1075.2.117 raeburn 3064: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3065: }
3066: }
3067: }
1.165 raeburn 3068: }
1.586 raeburn 3069: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3070: if ($authtype eq '') {
3071: $authtype = '<input type="radio" name="login" value="loc" '.
3072: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3073: $jscall.'"'.$disabled.' />';
1.586 raeburn 3074: }
3075: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1075.2.117 raeburn 3076: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3077: $result = &mt('[_1] Local Authentication with argument [_2]',
3078: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3079: return $result;
3080: }
3081:
1.1075.2.20 raeburn 3082: sub authform_filesystem {
1.32 matthew 3083: my %in = (
3084: formname => 'document.cu',
3085: kerb_def_dom => 'MSU.EDU',
3086: @_,
3087: );
1.1075.2.117 raeburn 3088: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3089: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3090: if ($in{'readonly'}) {
3091: $disabled = ' disabled="disabled"';
3092: }
1.591 raeburn 3093: if (defined($in{'curr_authtype'})) {
3094: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3095: if ($can_assign{'fsys'}) {
1.772 bisitz 3096: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3097: if (defined($in{'mode'})) {
3098: if ($in{'mode'} eq 'modifyuser') {
3099: $fsyscheck = '';
3100: }
3101: }
1.586 raeburn 3102: } else {
3103: $result = &mt('Currently Filesystem Authenticated.');
3104: return $result;
3105: }
3106: }
3107: } else {
3108: if ($authnum == 1) {
1.784 bisitz 3109: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3110: }
3111: }
3112: if (!$can_assign{'fsys'}) {
3113: return;
1.587 raeburn 3114: } elsif ($authtype eq '') {
1.591 raeburn 3115: if (defined($in{'mode'})) {
1.587 raeburn 3116: if ($in{'mode'} eq 'modifycourse') {
3117: if ($authnum == 1) {
1.1075.2.117 raeburn 3118: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3119: }
3120: }
3121: }
1.586 raeburn 3122: }
3123: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3124: if ($authtype eq '') {
3125: $authtype = '<input type="radio" name="login" value="fsys" '.
3126: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3127: $jscall.'"'.$disabled.' />';
1.586 raeburn 3128: }
1.1075.2.158 raeburn 3129: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1075.2.117 raeburn 3130: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3131: $result = &mt
1.144 matthew 3132: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1075.2.158 raeburn 3133: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3134: return $result;
3135: }
3136:
1.586 raeburn 3137: sub get_assignable_auth {
3138: my ($dom) = @_;
3139: if ($dom eq '') {
3140: $dom = $env{'request.role.domain'};
3141: }
3142: my %can_assign = (
3143: krb4 => 1,
3144: krb5 => 1,
3145: int => 1,
3146: loc => 1,
3147: );
3148: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3149: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3150: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3151: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3152: my $context;
3153: if ($env{'request.role'} =~ /^au/) {
3154: $context = 'author';
1.1075.2.117 raeburn 3155: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3156: $context = 'domain';
3157: } elsif ($env{'request.course.id'}) {
3158: $context = 'course';
3159: }
3160: if ($context) {
3161: if (ref($authhash->{$context}) eq 'HASH') {
3162: %can_assign = %{$authhash->{$context}};
3163: }
3164: }
3165: }
3166: }
3167: my $authnum = 0;
3168: foreach my $key (keys(%can_assign)) {
3169: if ($can_assign{$key}) {
3170: $authnum ++;
3171: }
3172: }
3173: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3174: $authnum --;
3175: }
3176: return ($authnum,%can_assign);
3177: }
3178:
1.1075.2.137 raeburn 3179: sub check_passwd_rules {
3180: my ($domain,$plainpass) = @_;
3181: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3182: my ($min,$max,@chars,@brokerule,$warning);
1.1075.2.138 raeburn 3183: $min = $Apache::lonnet::passwdmin;
1.1075.2.137 raeburn 3184: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3185: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1075.2.138 raeburn 3186: if ($passwdconf{'min'} > $min) {
3187: $min = $passwdconf{'min'};
3188: }
1.1075.2.137 raeburn 3189: }
3190: if ($passwdconf{'max'} =~ /^\d+$/) {
3191: $max = $passwdconf{'max'};
3192: }
3193: @chars = @{$passwdconf{'chars'}};
3194: }
3195: if (($min) && (length($plainpass) < $min)) {
3196: push(@brokerule,'min');
3197: }
3198: if (($max) && (length($plainpass) > $max)) {
3199: push(@brokerule,'max');
3200: }
3201: if (@chars) {
3202: my %rules;
3203: map { $rules{$_} = 1; } @chars;
3204: if ($rules{'uc'}) {
3205: unless ($plainpass =~ /[A-Z]/) {
3206: push(@brokerule,'uc');
3207: }
3208: }
3209: if ($rules{'lc'}) {
3210: unless ($plainpass =~ /[a-z]/) {
3211: push(@brokerule,'lc');
3212: }
3213: }
3214: if ($rules{'num'}) {
3215: unless ($plainpass =~ /\d/) {
3216: push(@brokerule,'num');
3217: }
3218: }
3219: if ($rules{'spec'}) {
3220: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3221: push(@brokerule,'spec');
3222: }
3223: }
3224: }
3225: if (@brokerule) {
3226: my %rulenames = &Apache::lonlocal::texthash(
3227: uc => 'At least one upper case letter',
3228: lc => 'At least one lower case letter',
3229: num => 'At least one number',
3230: spec => 'At least one non-alphanumeric',
3231: );
3232: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3233: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3234: $rulenames{'num'} .= ': 0123456789';
3235: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3236: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3237: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3238: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1075.2.143 raeburn 3239: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1075.2.137 raeburn 3240: if (grep(/^$rule$/,@brokerule)) {
3241: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3242: }
3243: }
3244: $warning .= '</ul>';
3245: }
3246: if (wantarray) {
3247: return @brokerule;
3248: }
3249: return $warning;
3250: }
3251:
1.80 albertel 3252: ###############################################################
3253: ## Get Kerberos Defaults for Domain ##
3254: ###############################################################
3255: ##
3256: ## Returns default kerberos version and an associated argument
3257: ## as listed in file domain.tab. If not listed, provides
3258: ## appropriate default domain and kerberos version.
3259: ##
3260: #-------------------------------------------
3261:
3262: =pod
3263:
1.648 raeburn 3264: =item * &get_kerberos_defaults()
1.80 albertel 3265:
3266: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3267: version and domain. If not found, it defaults to version 4 and the
3268: domain of the server.
1.80 albertel 3269:
1.648 raeburn 3270: =over 4
3271:
1.80 albertel 3272: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3273:
1.648 raeburn 3274: =back
3275:
3276: =back
3277:
1.80 albertel 3278: =cut
3279:
3280: #-------------------------------------------
3281: sub get_kerberos_defaults {
3282: my $domain=shift;
1.641 raeburn 3283: my ($krbdef,$krbdefdom);
3284: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3285: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3286: $krbdef = $domdefaults{'auth_def'};
3287: $krbdefdom = $domdefaults{'auth_arg_def'};
3288: } else {
1.80 albertel 3289: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3290: my $krbdefdom=$1;
3291: $krbdefdom=~tr/a-z/A-Z/;
3292: $krbdef = "krb4";
3293: }
3294: return ($krbdef,$krbdefdom);
3295: }
1.112 bowersj2 3296:
1.32 matthew 3297:
1.46 matthew 3298: ###############################################################
3299: ## Thesaurus Functions ##
3300: ###############################################################
1.20 www 3301:
1.46 matthew 3302: =pod
1.20 www 3303:
1.112 bowersj2 3304: =head1 Thesaurus Functions
3305:
3306: =over 4
3307:
1.648 raeburn 3308: =item * &initialize_keywords()
1.46 matthew 3309:
3310: Initializes the package variable %Keywords if it is empty. Uses the
3311: package variable $thesaurus_db_file.
3312:
3313: =cut
3314:
3315: ###################################################
3316:
3317: sub initialize_keywords {
3318: return 1 if (scalar keys(%Keywords));
3319: # If we are here, %Keywords is empty, so fill it up
3320: # Make sure the file we need exists...
3321: if (! -e $thesaurus_db_file) {
3322: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3323: " failed because it does not exist");
3324: return 0;
3325: }
3326: # Set up the hash as a database
3327: my %thesaurus_db;
3328: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3329: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3330: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3331: $thesaurus_db_file);
3332: return 0;
3333: }
3334: # Get the average number of appearances of a word.
3335: my $avecount = $thesaurus_db{'average.count'};
3336: # Put keywords (those that appear > average) into %Keywords
3337: while (my ($word,$data)=each (%thesaurus_db)) {
3338: my ($count,undef) = split /:/,$data;
3339: $Keywords{$word}++ if ($count > $avecount);
3340: }
3341: untie %thesaurus_db;
3342: # Remove special values from %Keywords.
1.356 albertel 3343: foreach my $value ('total.count','average.count') {
3344: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3345: }
1.46 matthew 3346: return 1;
3347: }
3348:
3349: ###################################################
3350:
3351: =pod
3352:
1.648 raeburn 3353: =item * &keyword($word)
1.46 matthew 3354:
3355: Returns true if $word is a keyword. A keyword is a word that appears more
3356: than the average number of times in the thesaurus database. Calls
3357: &initialize_keywords
3358:
3359: =cut
3360:
3361: ###################################################
1.20 www 3362:
3363: sub keyword {
1.46 matthew 3364: return if (!&initialize_keywords());
3365: my $word=lc(shift());
3366: $word=~s/\W//g;
3367: return exists($Keywords{$word});
1.20 www 3368: }
1.46 matthew 3369:
3370: ###############################################################
3371:
3372: =pod
1.20 www 3373:
1.648 raeburn 3374: =item * &get_related_words()
1.46 matthew 3375:
1.160 matthew 3376: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3377: an array of words. If the keyword is not in the thesaurus, an empty array
3378: will be returned. The order of the words returned is determined by the
3379: database which holds them.
3380:
3381: Uses global $thesaurus_db_file.
3382:
1.1057 foxr 3383:
1.46 matthew 3384: =cut
3385:
3386: ###############################################################
3387: sub get_related_words {
3388: my $keyword = shift;
3389: my %thesaurus_db;
3390: if (! -e $thesaurus_db_file) {
3391: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3392: "failed because the file does not exist");
3393: return ();
3394: }
3395: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3396: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3397: return ();
3398: }
3399: my @Words=();
1.429 www 3400: my $count=0;
1.46 matthew 3401: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3402: # The first element is the number of times
3403: # the word appears. We do not need it now.
1.429 www 3404: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3405: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3406: my $threshold=$mostfrequentcount/10;
3407: foreach my $possibleword (@RelatedWords) {
3408: my ($word,$wordcount)=split(/\,/,$possibleword);
3409: if ($wordcount>$threshold) {
3410: push(@Words,$word);
3411: $count++;
3412: if ($count>10) { last; }
3413: }
1.20 www 3414: }
3415: }
1.46 matthew 3416: untie %thesaurus_db;
3417: return @Words;
1.14 harris41 3418: }
1.46 matthew 3419:
1.112 bowersj2 3420: =pod
3421:
3422: =back
3423:
3424: =cut
1.61 www 3425:
3426: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3427: =pod
3428:
1.112 bowersj2 3429: =head1 User Name Functions
3430:
3431: =over 4
3432:
1.648 raeburn 3433: =item * &plainname($uname,$udom,$first)
1.81 albertel 3434:
1.112 bowersj2 3435: Takes a users logon name and returns it as a string in
1.226 albertel 3436: "first middle last generation" form
3437: if $first is set to 'lastname' then it returns it as
3438: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3439:
3440: =cut
1.61 www 3441:
1.295 www 3442:
1.81 albertel 3443: ###############################################################
1.61 www 3444: sub plainname {
1.226 albertel 3445: my ($uname,$udom,$first)=@_;
1.537 albertel 3446: return if (!defined($uname) || !defined($udom));
1.295 www 3447: my %names=&getnames($uname,$udom);
1.226 albertel 3448: my $name=&Apache::lonnet::format_name($names{'firstname'},
3449: $names{'middlename'},
3450: $names{'lastname'},
3451: $names{'generation'},$first);
3452: $name=~s/^\s+//;
1.62 www 3453: $name=~s/\s+$//;
3454: $name=~s/\s+/ /g;
1.353 albertel 3455: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3456: return $name;
1.61 www 3457: }
1.66 www 3458:
3459: # -------------------------------------------------------------------- Nickname
1.81 albertel 3460: =pod
3461:
1.648 raeburn 3462: =item * &nickname($uname,$udom)
1.81 albertel 3463:
3464: Gets a users name and returns it as a string as
3465:
3466: ""nickname""
1.66 www 3467:
1.81 albertel 3468: if the user has a nickname or
3469:
3470: "first middle last generation"
3471:
3472: if the user does not
3473:
3474: =cut
1.66 www 3475:
3476: sub nickname {
3477: my ($uname,$udom)=@_;
1.537 albertel 3478: return if (!defined($uname) || !defined($udom));
1.295 www 3479: my %names=&getnames($uname,$udom);
1.68 albertel 3480: my $name=$names{'nickname'};
1.66 www 3481: if ($name) {
3482: $name='"'.$name.'"';
3483: } else {
3484: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3485: $names{'lastname'}.' '.$names{'generation'};
3486: $name=~s/\s+$//;
3487: $name=~s/\s+/ /g;
3488: }
3489: return $name;
3490: }
3491:
1.295 www 3492: sub getnames {
3493: my ($uname,$udom)=@_;
1.537 albertel 3494: return if (!defined($uname) || !defined($udom));
1.433 albertel 3495: if ($udom eq 'public' && $uname eq 'public') {
3496: return ('lastname' => &mt('Public'));
3497: }
1.295 www 3498: my $id=$uname.':'.$udom;
3499: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3500: if ($cached) {
3501: return %{$names};
3502: } else {
3503: my %loadnames=&Apache::lonnet::get('environment',
3504: ['firstname','middlename','lastname','generation','nickname'],
3505: $udom,$uname);
3506: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3507: return %loadnames;
3508: }
3509: }
1.61 www 3510:
1.542 raeburn 3511: # -------------------------------------------------------------------- getemails
1.648 raeburn 3512:
1.542 raeburn 3513: =pod
3514:
1.648 raeburn 3515: =item * &getemails($uname,$udom)
1.542 raeburn 3516:
3517: Gets a user's email information and returns it as a hash with keys:
3518: notification, critnotification, permanentemail
3519:
3520: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3521: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3522:
1.648 raeburn 3523:
1.542 raeburn 3524: =cut
3525:
1.648 raeburn 3526:
1.466 albertel 3527: sub getemails {
3528: my ($uname,$udom)=@_;
3529: if ($udom eq 'public' && $uname eq 'public') {
3530: return;
3531: }
1.467 www 3532: if (!$udom) { $udom=$env{'user.domain'}; }
3533: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3534: my $id=$uname.':'.$udom;
3535: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3536: if ($cached) {
3537: return %{$names};
3538: } else {
3539: my %loadnames=&Apache::lonnet::get('environment',
3540: ['notification','critnotification',
3541: 'permanentemail'],
3542: $udom,$uname);
3543: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3544: return %loadnames;
3545: }
3546: }
3547:
1.551 albertel 3548: sub flush_email_cache {
3549: my ($uname,$udom)=@_;
3550: if (!$udom) { $udom =$env{'user.domain'}; }
3551: if (!$uname) { $uname=$env{'user.name'}; }
3552: return if ($udom eq 'public' && $uname eq 'public');
3553: my $id=$uname.':'.$udom;
3554: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3555: }
3556:
1.728 raeburn 3557: # -------------------------------------------------------------------- getlangs
3558:
3559: =pod
3560:
3561: =item * &getlangs($uname,$udom)
3562:
3563: Gets a user's language preference and returns it as a hash with key:
3564: language.
3565:
3566: =cut
3567:
3568:
3569: sub getlangs {
3570: my ($uname,$udom) = @_;
3571: if (!$udom) { $udom =$env{'user.domain'}; }
3572: if (!$uname) { $uname=$env{'user.name'}; }
3573: my $id=$uname.':'.$udom;
3574: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3575: if ($cached) {
3576: return %{$langs};
3577: } else {
3578: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3579: $udom,$uname);
3580: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3581: return %loadlangs;
3582: }
3583: }
3584:
3585: sub flush_langs_cache {
3586: my ($uname,$udom)=@_;
3587: if (!$udom) { $udom =$env{'user.domain'}; }
3588: if (!$uname) { $uname=$env{'user.name'}; }
3589: return if ($udom eq 'public' && $uname eq 'public');
3590: my $id=$uname.':'.$udom;
3591: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3592: }
3593:
1.61 www 3594: # ------------------------------------------------------------------ Screenname
1.81 albertel 3595:
3596: =pod
3597:
1.648 raeburn 3598: =item * &screenname($uname,$udom)
1.81 albertel 3599:
3600: Gets a users screenname and returns it as a string
3601:
3602: =cut
1.61 www 3603:
3604: sub screenname {
3605: my ($uname,$udom)=@_;
1.258 albertel 3606: if ($uname eq $env{'user.name'} &&
3607: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3608: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3609: return $names{'screenname'};
1.62 www 3610: }
3611:
1.212 albertel 3612:
1.802 bisitz 3613: # ------------------------------------------------------------- Confirm Wrapper
3614: =pod
3615:
1.1075.2.42 raeburn 3616: =item * &confirmwrapper($message)
1.802 bisitz 3617:
3618: Wrap messages about completion of operation in box
3619:
3620: =cut
3621:
3622: sub confirmwrapper {
3623: my ($message)=@_;
3624: if ($message) {
3625: return "\n".'<div class="LC_confirm_box">'."\n"
3626: .$message."\n"
3627: .'</div>'."\n";
3628: } else {
3629: return $message;
3630: }
3631: }
3632:
1.62 www 3633: # ------------------------------------------------------------- Message Wrapper
3634:
3635: sub messagewrapper {
1.369 www 3636: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3637: return
1.441 albertel 3638: '<a href="/adm/email?compose=individual&'.
3639: 'recname='.$username.'&recdom='.$domain.
3640: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3641: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3642: }
1.802 bisitz 3643:
1.74 www 3644: # --------------------------------------------------------------- Notes Wrapper
3645:
3646: sub noteswrapper {
3647: my ($link,$un,$do)=@_;
3648: return
1.896 amueller 3649: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3650: }
1.802 bisitz 3651:
1.62 www 3652: # ------------------------------------------------------------- Aboutme Wrapper
3653:
3654: sub aboutmewrapper {
1.1070 raeburn 3655: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3656: if (!defined($username) && !defined($domain)) {
3657: return;
3658: }
1.1075.2.15 raeburn 3659: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3660: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3661: }
3662:
3663: # ------------------------------------------------------------ Syllabus Wrapper
3664:
3665: sub syllabuswrapper {
1.707 bisitz 3666: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3667: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3668: }
1.14 harris41 3669:
1.802 bisitz 3670: # -----------------------------------------------------------------------------
3671:
1.1075.2.167 raeburn 3672: sub aboutme_on {
3673: my ($uname,$udom)=@_;
3674: unless ($uname) { $uname=$env{'user.name'}; }
3675: unless ($udom) { $udom=$env{'user.domain'}; }
3676: return if ($udom eq 'public' && $uname eq 'public');
3677: my $hashkey=$uname.':'.$udom;
3678: my ($aboutme,$cached)=&Apache::lonnet::is_cached_new('aboutme',$hashkey);
3679: if ($cached) {
3680: return $aboutme;
3681: }
3682: $aboutme = &Apache::lonnet::usertools_access($uname,$udom,'aboutme');
3683: &Apache::lonnet::do_cache_new('aboutme',$hashkey,$aboutme,3600);
3684: return $aboutme;
3685: }
3686:
3687: sub devalidate_aboutme_cache {
3688: my ($uname,$udom)=@_;
3689: if (!$udom) { $udom =$env{'user.domain'}; }
3690: if (!$uname) { $uname=$env{'user.name'}; }
3691: return if ($udom eq 'public' && $uname eq 'public');
3692: my $id=$uname.':'.$udom;
3693: &Apache::lonnet::devalidate_cache_new('aboutme',$id);
3694: }
3695:
1.208 matthew 3696: sub track_student_link {
1.887 raeburn 3697: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3698: my $link ="/adm/trackstudent?";
1.208 matthew 3699: my $title = 'View recent activity';
3700: if (defined($sname) && $sname !~ /^\s*$/ &&
3701: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3702: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3703: $title .= ' of this student';
1.268 albertel 3704: }
1.208 matthew 3705: if (defined($target) && $target !~ /^\s*$/) {
3706: $target = qq{target="$target"};
3707: } else {
3708: $target = '';
3709: }
1.268 albertel 3710: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3711: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3712: $title = &mt($title);
3713: $linktext = &mt($linktext);
1.448 albertel 3714: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3715: &help_open_topic('View_recent_activity');
1.208 matthew 3716: }
3717:
1.781 raeburn 3718: sub slot_reservations_link {
3719: my ($linktext,$sname,$sdom,$target) = @_;
3720: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3721: my $title = 'View slot reservation history';
3722: if (defined($sname) && $sname !~ /^\s*$/ &&
3723: defined($sdom) && $sdom !~ /^\s*$/) {
3724: $link .= "&uname=$sname&udom=$sdom";
3725: $title .= ' of this student';
3726: }
3727: if (defined($target) && $target !~ /^\s*$/) {
3728: $target = qq{target="$target"};
3729: } else {
3730: $target = '';
3731: }
3732: $title = &mt($title);
3733: $linktext = &mt($linktext);
3734: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3735: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3736:
3737: }
3738:
1.508 www 3739: # ===================================================== Display a student photo
3740:
3741:
1.509 albertel 3742: sub student_image_tag {
1.508 www 3743: my ($domain,$user)=@_;
3744: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3745: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3746: return '<img src="'.$imgsrc.'" align="right" />';
3747: } else {
3748: return '';
3749: }
3750: }
3751:
1.112 bowersj2 3752: =pod
3753:
3754: =back
3755:
3756: =head1 Access .tab File Data
3757:
3758: =over 4
3759:
1.648 raeburn 3760: =item * &languageids()
1.112 bowersj2 3761:
3762: returns list of all language ids
3763:
3764: =cut
3765:
1.14 harris41 3766: sub languageids {
1.16 harris41 3767: return sort(keys(%language));
1.14 harris41 3768: }
3769:
1.112 bowersj2 3770: =pod
3771:
1.648 raeburn 3772: =item * &languagedescription()
1.112 bowersj2 3773:
3774: returns description of a specified language id
3775:
3776: =cut
3777:
1.14 harris41 3778: sub languagedescription {
1.125 www 3779: my $code=shift;
3780: return ($supported_language{$code}?'* ':'').
3781: $language{$code}.
1.126 www 3782: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3783: }
3784:
1.1048 foxr 3785: =pod
3786:
3787: =item * &plainlanguagedescription
3788:
3789: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3790: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3791:
3792: =cut
3793:
1.145 www 3794: sub plainlanguagedescription {
3795: my $code=shift;
3796: return $language{$code};
3797: }
3798:
1.1048 foxr 3799: =pod
3800:
3801: =item * &supportedlanguagecode
3802:
3803: Returns the supported language code (e.g. sptutf maps to pt) given a language
3804: code.
3805:
3806: =cut
3807:
1.145 www 3808: sub supportedlanguagecode {
3809: my $code=shift;
3810: return $supported_language{$code};
1.97 www 3811: }
3812:
1.112 bowersj2 3813: =pod
3814:
1.1048 foxr 3815: =item * &latexlanguage()
3816:
3817: Given a language key code returns the correspondnig language to use
3818: to select the correct hyphenation on LaTeX printouts. This is undef if there
3819: is no supported hyphenation for the language code.
3820:
3821: =cut
3822:
3823: sub latexlanguage {
3824: my $code = shift;
3825: return $latex_language{$code};
3826: }
3827:
3828: =pod
3829:
3830: =item * &latexhyphenation()
3831:
3832: Same as above but what's supplied is the language as it might be stored
3833: in the metadata.
3834:
3835: =cut
3836:
3837: sub latexhyphenation {
3838: my $key = shift;
3839: return $latex_language_bykey{$key};
3840: }
3841:
3842: =pod
3843:
1.648 raeburn 3844: =item * ©rightids()
1.112 bowersj2 3845:
3846: returns list of all copyrights
3847:
3848: =cut
3849:
3850: sub copyrightids {
3851: return sort(keys(%cprtag));
3852: }
3853:
3854: =pod
3855:
1.648 raeburn 3856: =item * ©rightdescription()
1.112 bowersj2 3857:
3858: returns description of a specified copyright id
3859:
3860: =cut
3861:
3862: sub copyrightdescription {
1.166 www 3863: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3864: }
1.197 matthew 3865:
3866: =pod
3867:
1.648 raeburn 3868: =item * &source_copyrightids()
1.192 taceyjo1 3869:
3870: returns list of all source copyrights
3871:
3872: =cut
3873:
3874: sub source_copyrightids {
3875: return sort(keys(%scprtag));
3876: }
3877:
3878: =pod
3879:
1.648 raeburn 3880: =item * &source_copyrightdescription()
1.192 taceyjo1 3881:
3882: returns description of a specified source copyright id
3883:
3884: =cut
3885:
3886: sub source_copyrightdescription {
3887: return &mt($scprtag{shift(@_)});
3888: }
1.112 bowersj2 3889:
3890: =pod
3891:
1.648 raeburn 3892: =item * &filecategories()
1.112 bowersj2 3893:
3894: returns list of all file categories
3895:
3896: =cut
3897:
3898: sub filecategories {
3899: return sort(keys(%category_extensions));
3900: }
3901:
3902: =pod
3903:
1.648 raeburn 3904: =item * &filecategorytypes()
1.112 bowersj2 3905:
3906: returns list of file types belonging to a given file
3907: category
3908:
3909: =cut
3910:
3911: sub filecategorytypes {
1.356 albertel 3912: my ($cat) = @_;
3913: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3914: }
3915:
3916: =pod
3917:
1.648 raeburn 3918: =item * &fileembstyle()
1.112 bowersj2 3919:
3920: returns embedding style for a specified file type
3921:
3922: =cut
3923:
3924: sub fileembstyle {
3925: return $fe{lc(shift(@_))};
1.169 www 3926: }
3927:
1.351 www 3928: sub filemimetype {
3929: return $fm{lc(shift(@_))};
3930: }
3931:
1.169 www 3932:
3933: sub filecategoryselect {
3934: my ($name,$value)=@_;
1.189 matthew 3935: return &select_form($value,$name,
1.970 raeburn 3936: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3937: }
3938:
3939: =pod
3940:
1.648 raeburn 3941: =item * &filedescription()
1.112 bowersj2 3942:
3943: returns description for a specified file type
3944:
3945: =cut
3946:
3947: sub filedescription {
1.188 matthew 3948: my $file_description = $fd{lc(shift())};
3949: $file_description =~ s:([\[\]]):~$1:g;
3950: return &mt($file_description);
1.112 bowersj2 3951: }
3952:
3953: =pod
3954:
1.648 raeburn 3955: =item * &filedescriptionex()
1.112 bowersj2 3956:
3957: returns description for a specified file type with
3958: extra formatting
3959:
3960: =cut
3961:
3962: sub filedescriptionex {
3963: my $ex=shift;
1.188 matthew 3964: my $file_description = $fd{lc($ex)};
3965: $file_description =~ s:([\[\]]):~$1:g;
3966: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3967: }
3968:
3969: # End of .tab access
3970: =pod
3971:
3972: =back
3973:
3974: =cut
3975:
3976: # ------------------------------------------------------------------ File Types
3977: sub fileextensions {
3978: return sort(keys(%fe));
3979: }
3980:
1.97 www 3981: # ----------------------------------------------------------- Display Languages
3982: # returns a hash with all desired display languages
3983: #
3984:
3985: sub display_languages {
3986: my %languages=();
1.695 raeburn 3987: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3988: $languages{$lang}=1;
1.97 www 3989: }
3990: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3991: if ($env{'form.displaylanguage'}) {
1.356 albertel 3992: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3993: $languages{$lang}=1;
1.97 www 3994: }
3995: }
3996: return %languages;
1.14 harris41 3997: }
3998:
1.582 albertel 3999: sub languages {
4000: my ($possible_langs) = @_;
1.695 raeburn 4001: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4002: if (!ref($possible_langs)) {
4003: if( wantarray ) {
4004: return @preferred_langs;
4005: } else {
4006: return $preferred_langs[0];
4007: }
4008: }
4009: my %possibilities = map { $_ => 1 } (@$possible_langs);
4010: my @preferred_possibilities;
4011: foreach my $preferred_lang (@preferred_langs) {
4012: if (exists($possibilities{$preferred_lang})) {
4013: push(@preferred_possibilities, $preferred_lang);
4014: }
4015: }
4016: if( wantarray ) {
4017: return @preferred_possibilities;
4018: }
4019: return $preferred_possibilities[0];
4020: }
4021:
1.742 raeburn 4022: sub user_lang {
4023: my ($touname,$toudom,$fromcid) = @_;
4024: my @userlangs;
4025: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4026: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4027: $env{'course.'.$fromcid.'.languages'}));
4028: } else {
4029: my %langhash = &getlangs($touname,$toudom);
4030: if ($langhash{'languages'} ne '') {
4031: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4032: } else {
4033: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4034: if ($domdefs{'lang_def'} ne '') {
4035: @userlangs = ($domdefs{'lang_def'});
4036: }
4037: }
4038: }
4039: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4040: my $user_lh = Apache::localize->get_handle(@languages);
4041: return $user_lh;
4042: }
4043:
4044:
1.112 bowersj2 4045: ###############################################################
4046: ## Student Answer Attempts ##
4047: ###############################################################
4048:
4049: =pod
4050:
4051: =head1 Alternate Problem Views
4052:
4053: =over 4
4054:
1.648 raeburn 4055: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 4056: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4057:
4058: Return string with previous attempt on problem. Arguments:
4059:
4060: =over 4
4061:
4062: =item * $symb: Problem, including path
4063:
4064: =item * $username: username of the desired student
4065:
4066: =item * $domain: domain of the desired student
1.14 harris41 4067:
1.112 bowersj2 4068: =item * $course: Course ID
1.14 harris41 4069:
1.112 bowersj2 4070: =item * $getattempt: Leave blank for all attempts, otherwise put
4071: something
1.14 harris41 4072:
1.112 bowersj2 4073: =item * $regexp: if string matches this regexp, the string will be
4074: sent to $gradesub
1.14 harris41 4075:
1.112 bowersj2 4076: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4077:
1.1075.2.86 raeburn 4078: =item * $usec: section of the desired student
4079:
4080: =item * $identifier: counter for student (multiple students one problem) or
4081: problem (one student; whole sequence).
4082:
1.112 bowersj2 4083: =back
1.14 harris41 4084:
1.112 bowersj2 4085: The output string is a table containing all desired attempts, if any.
1.16 harris41 4086:
1.112 bowersj2 4087: =cut
1.1 albertel 4088:
4089: sub get_previous_attempt {
1.1075.2.86 raeburn 4090: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4091: my $prevattempts='';
1.43 ng 4092: no strict 'refs';
1.1 albertel 4093: if ($symb) {
1.3 albertel 4094: my (%returnhash)=
4095: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4096: if ($returnhash{'version'}) {
4097: my %lasthash=();
4098: my $version;
4099: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 4100: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4101: if ($key =~ /\.rawrndseed$/) {
4102: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4103: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4104: } else {
4105: $lasthash{$key}=$returnhash{$version.':'.$key};
4106: }
1.19 harris41 4107: }
1.1 albertel 4108: }
1.596 albertel 4109: $prevattempts=&start_data_table().&start_data_table_header_row();
4110: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4111: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4112: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4113: foreach my $key (sort(keys(%lasthash))) {
4114: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4115: if ($#parts > 0) {
1.31 albertel 4116: my $data=$parts[-1];
1.989 raeburn 4117: next if ($data eq 'foilorder');
1.31 albertel 4118: pop(@parts);
1.1010 www 4119: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4120: if ($data eq 'type') {
4121: unless ($showsurv) {
4122: my $id = join(',',@parts);
4123: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4124: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4125: $lasthidden{$ign.'.'.$id} = 1;
4126: }
1.945 raeburn 4127: }
1.1075.2.86 raeburn 4128: if ($identifier ne '') {
4129: my $id = join(',',@parts);
4130: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4131: $domain,$username,$usec,undef,$course) =~ /^no/) {
4132: $hidestatus{$ign.'.'.$id} = 1;
4133: }
4134: }
4135: } elsif ($data eq 'regrader') {
4136: if (($identifier ne '') && (@parts)) {
4137: my $id = join(',',@parts);
4138: $regraded{$ign.'.'.$id} = 1;
4139: }
1.1010 www 4140: }
1.31 albertel 4141: } else {
1.41 ng 4142: if ($#parts == 0) {
4143: $prevattempts.='<th>'.$parts[0].'</th>';
4144: } else {
4145: $prevattempts.='<th>'.$ign.'</th>';
4146: }
1.31 albertel 4147: }
1.16 harris41 4148: }
1.596 albertel 4149: $prevattempts.=&end_data_table_header_row();
1.40 ng 4150: if ($getattempt eq '') {
1.1075.2.86 raeburn 4151: my (%solved,%resets,%probstatus);
4152: if (($identifier ne '') && (keys(%regraded) > 0)) {
4153: for ($version=1;$version<=$returnhash{'version'};$version++) {
4154: foreach my $id (keys(%regraded)) {
4155: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4156: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4157: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4158: push(@{$resets{$id}},$version);
4159: }
4160: }
4161: }
4162: }
1.40 ng 4163: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4164: my (@hidden,@unsolved);
1.945 raeburn 4165: if (%typeparts) {
4166: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4167: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4168: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4169: push(@hidden,$id);
1.1075.2.86 raeburn 4170: } elsif ($identifier ne '') {
4171: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4172: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4173: ($hidestatus{$id})) {
4174: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4175: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4176: push(@{$solved{$id}},$version);
4177: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4178: (ref($solved{$id}) eq 'ARRAY')) {
4179: my $skip;
4180: if (ref($resets{$id}) eq 'ARRAY') {
4181: foreach my $reset (@{$resets{$id}}) {
4182: if ($reset > $solved{$id}[-1]) {
4183: $skip=1;
4184: last;
4185: }
4186: }
4187: }
4188: unless ($skip) {
4189: my ($ign,$partslist) = split(/\./,$id,2);
4190: push(@unsolved,$partslist);
4191: }
4192: }
4193: }
1.945 raeburn 4194: }
4195: }
4196: }
4197: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4198: '<td>'.&mt('Transaction [_1]',$version);
4199: if (@unsolved) {
4200: $prevattempts .= '<span class="LC_nobreak"><label>'.
4201: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4202: &mt('Hide').'</label></span>';
4203: }
4204: $prevattempts .= '</td>';
1.945 raeburn 4205: if (@hidden) {
4206: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4207: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4208: my $hide;
4209: foreach my $id (@hidden) {
4210: if ($key =~ /^\Q$id\E/) {
4211: $hide = 1;
4212: last;
4213: }
4214: }
4215: if ($hide) {
4216: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4217: if (($data eq 'award') || ($data eq 'awarddetail')) {
4218: my $value = &format_previous_attempt_value($key,
4219: $returnhash{$version.':'.$key});
4220: $prevattempts.='<td>'.$value.' </td>';
4221: } else {
4222: $prevattempts.='<td> </td>';
4223: }
4224: } else {
4225: if ($key =~ /\./) {
1.1075.2.91 raeburn 4226: my $value = $returnhash{$version.':'.$key};
4227: if ($key =~ /\.rndseed$/) {
4228: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4229: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4230: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4231: }
4232: }
4233: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4234: ' </td>';
1.945 raeburn 4235: } else {
4236: $prevattempts.='<td> </td>';
4237: }
4238: }
4239: }
4240: } else {
4241: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4242: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4243: my $value = $returnhash{$version.':'.$key};
4244: if ($key =~ /\.rndseed$/) {
4245: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4246: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4247: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4248: }
4249: }
4250: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4251: ' </td>';
1.945 raeburn 4252: }
4253: }
4254: $prevattempts.=&end_data_table_row();
1.40 ng 4255: }
1.1 albertel 4256: }
1.945 raeburn 4257: my @currhidden = keys(%lasthidden);
1.596 albertel 4258: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4259: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4260: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4261: if (%typeparts) {
4262: my $hidden;
4263: foreach my $id (@currhidden) {
4264: if ($key =~ /^\Q$id\E/) {
4265: $hidden = 1;
4266: last;
4267: }
4268: }
4269: if ($hidden) {
4270: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4271: if (($data eq 'award') || ($data eq 'awarddetail')) {
4272: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4273: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4274: $value = &$gradesub($value);
4275: }
4276: $prevattempts.='<td>'.$value.' </td>';
4277: } else {
4278: $prevattempts.='<td> </td>';
4279: }
4280: } else {
4281: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4282: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4283: $value = &$gradesub($value);
4284: }
4285: $prevattempts.='<td>'.$value.' </td>';
4286: }
4287: } else {
4288: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4289: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4290: $value = &$gradesub($value);
4291: }
4292: $prevattempts.='<td>'.$value.' </td>';
4293: }
1.16 harris41 4294: }
1.596 albertel 4295: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4296: } else {
1.596 albertel 4297: $prevattempts=
4298: &start_data_table().&start_data_table_row().
4299: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4300: &end_data_table_row().&end_data_table();
1.1 albertel 4301: }
4302: } else {
1.596 albertel 4303: $prevattempts=
4304: &start_data_table().&start_data_table_row().
4305: '<td>'.&mt('No data.').'</td>'.
4306: &end_data_table_row().&end_data_table();
1.1 albertel 4307: }
1.10 albertel 4308: }
4309:
1.581 albertel 4310: sub format_previous_attempt_value {
4311: my ($key,$value) = @_;
1.1011 www 4312: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4313: $value = &Apache::lonlocal::locallocaltime($value);
4314: } elsif (ref($value) eq 'ARRAY') {
4315: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4316: } elsif ($key =~ /answerstring$/) {
4317: my %answers = &Apache::lonnet::str2hash($value);
4318: my @anskeys = sort(keys(%answers));
4319: if (@anskeys == 1) {
4320: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4321: if ($answer =~ m{\0}) {
4322: $answer =~ s{\0}{,}g;
1.988 raeburn 4323: }
4324: my $tag_internal_answer_name = 'INTERNAL';
4325: if ($anskeys[0] eq $tag_internal_answer_name) {
4326: $value = $answer;
4327: } else {
4328: $value = $anskeys[0].'='.$answer;
4329: }
4330: } else {
4331: foreach my $ans (@anskeys) {
4332: my $answer = $answers{$ans};
1.1001 raeburn 4333: if ($answer =~ m{\0}) {
4334: $answer =~ s{\0}{,}g;
1.988 raeburn 4335: }
4336: $value .= $ans.'='.$answer.'<br />';;
4337: }
4338: }
1.581 albertel 4339: } else {
4340: $value = &unescape($value);
4341: }
4342: return $value;
4343: }
4344:
4345:
1.107 albertel 4346: sub relative_to_absolute {
4347: my ($url,$output)=@_;
4348: my $parser=HTML::TokeParser->new(\$output);
4349: my $token;
4350: my $thisdir=$url;
4351: my @rlinks=();
4352: while ($token=$parser->get_token) {
4353: if ($token->[0] eq 'S') {
4354: if ($token->[1] eq 'a') {
4355: if ($token->[2]->{'href'}) {
4356: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4357: }
4358: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4359: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4360: } elsif ($token->[1] eq 'base') {
4361: $thisdir=$token->[2]->{'href'};
4362: }
4363: }
4364: }
4365: $thisdir=~s-/[^/]*$--;
1.356 albertel 4366: foreach my $link (@rlinks) {
1.726 raeburn 4367: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4368: ($link=~/^\//) ||
4369: ($link=~/^javascript:/i) ||
4370: ($link=~/^mailto:/i) ||
4371: ($link=~/^\#/)) {
4372: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4373: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4374: }
4375: }
4376: # -------------------------------------------------- Deal with Applet codebases
4377: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4378: return $output;
4379: }
4380:
1.112 bowersj2 4381: =pod
4382:
1.648 raeburn 4383: =item * &get_student_view()
1.112 bowersj2 4384:
4385: show a snapshot of what student was looking at
4386:
4387: =cut
4388:
1.10 albertel 4389: sub get_student_view {
1.186 albertel 4390: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4391: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4392: my (%form);
1.10 albertel 4393: my @elements=('symb','courseid','domain','username');
4394: foreach my $element (@elements) {
1.186 albertel 4395: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4396: }
1.186 albertel 4397: if (defined($moreenv)) {
4398: %form=(%form,%{$moreenv});
4399: }
1.236 albertel 4400: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4401: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4402: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4403: $userview=~s/\<body[^\>]*\>//gi;
4404: $userview=~s/\<\/body\>//gi;
4405: $userview=~s/\<html\>//gi;
4406: $userview=~s/\<\/html\>//gi;
4407: $userview=~s/\<head\>//gi;
4408: $userview=~s/\<\/head\>//gi;
4409: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4410: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4411: if (wantarray) {
4412: return ($userview,$response);
4413: } else {
4414: return $userview;
4415: }
4416: }
4417:
4418: sub get_student_view_with_retries {
4419: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4420:
4421: my $ok = 0; # True if we got a good response.
4422: my $content;
4423: my $response;
4424:
4425: # Try to get the student_view done. within the retries count:
4426:
4427: do {
4428: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4429: $ok = $response->is_success;
4430: if (!$ok) {
4431: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4432: }
4433: $retries--;
4434: } while (!$ok && ($retries > 0));
4435:
4436: if (!$ok) {
4437: $content = ''; # On error return an empty content.
4438: }
1.651 www 4439: if (wantarray) {
4440: return ($content, $response);
4441: } else {
4442: return $content;
4443: }
1.11 albertel 4444: }
4445:
1.1075.2.149 raeburn 4446: sub css_links {
4447: my ($currsymb,$level) = @_;
4448: my ($links,@symbs,%cssrefs,%httpref);
4449: if ($level eq 'map') {
4450: my $navmap = Apache::lonnavmaps::navmap->new();
4451: if (ref($navmap)) {
4452: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
4453: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
4454: foreach my $res (@resources) {
4455: if (ref($res) && $res->symb()) {
4456: push(@symbs,$res->symb());
4457: }
4458: }
4459: }
4460: } else {
4461: @symbs = ($currsymb);
4462: }
4463: foreach my $symb (@symbs) {
4464: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
4465: if ($css_href =~ /\S/) {
4466: unless ($css_href =~ m{https?://}) {
4467: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
4468: my $proburl = &Apache::lonnet::clutter($url);
4469: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
4470: unless ($css_href =~ m{^/}) {
4471: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
4472: }
4473: if ($css_href =~ m{^/(res|uploaded)/}) {
4474: unless (($httpref{'httpref.'.$css_href}) ||
4475: (&Apache::lonnet::is_on_map($css_href))) {
4476: my $thisurl = $proburl;
4477: if ($env{'httpref.'.$proburl}) {
4478: $thisurl = $env{'httpref.'.$proburl};
4479: }
4480: $httpref{'httpref.'.$css_href} = $thisurl;
4481: }
4482: }
4483: }
4484: $cssrefs{$css_href} = 1;
4485: }
4486: }
4487: if (keys(%httpref)) {
4488: &Apache::lonnet::appenv(\%httpref);
4489: }
4490: if (keys(%cssrefs)) {
4491: foreach my $css_href (keys(%cssrefs)) {
4492: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
4493: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
4494: }
4495: }
4496: return $links;
4497: }
4498:
1.112 bowersj2 4499: =pod
4500:
1.648 raeburn 4501: =item * &get_student_answers()
1.112 bowersj2 4502:
4503: show a snapshot of how student was answering problem
4504:
4505: =cut
4506:
1.11 albertel 4507: sub get_student_answers {
1.100 sakharuk 4508: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4509: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4510: my (%moreenv);
1.11 albertel 4511: my @elements=('symb','courseid','domain','username');
4512: foreach my $element (@elements) {
1.186 albertel 4513: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4514: }
1.186 albertel 4515: $moreenv{'grade_target'}='answer';
4516: %moreenv=(%form,%moreenv);
1.497 raeburn 4517: $feedurl = &Apache::lonnet::clutter($feedurl);
4518: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4519: return $userview;
1.1 albertel 4520: }
1.116 albertel 4521:
4522: =pod
4523:
4524: =item * &submlink()
4525:
1.242 albertel 4526: Inputs: $text $uname $udom $symb $target
1.116 albertel 4527:
4528: Returns: A link to grades.pm such as to see the SUBM view of a student
4529:
4530: =cut
4531:
4532: ###############################################
4533: sub submlink {
1.242 albertel 4534: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4535: if (!($uname && $udom)) {
4536: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4537: &Apache::lonnet::whichuser($symb);
1.116 albertel 4538: if (!$symb) { $symb=$cursymb; }
4539: }
1.254 matthew 4540: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4541: $symb=&escape($symb);
1.960 bisitz 4542: if ($target) { $target=" target=\"$target\""; }
4543: return
4544: '<a href="/adm/grades?command=submission'.
4545: '&symb='.$symb.
4546: '&student='.$uname.
4547: '&userdom='.$udom.'"'.
4548: $target.'>'.$text.'</a>';
1.242 albertel 4549: }
4550: ##############################################
4551:
4552: =pod
4553:
4554: =item * &pgrdlink()
4555:
4556: Inputs: $text $uname $udom $symb $target
4557:
4558: Returns: A link to grades.pm such as to see the PGRD view of a student
4559:
4560: =cut
4561:
4562: ###############################################
4563: sub pgrdlink {
4564: my $link=&submlink(@_);
4565: $link=~s/(&command=submission)/$1&showgrading=yes/;
4566: return $link;
4567: }
4568: ##############################################
4569:
4570: =pod
4571:
4572: =item * &pprmlink()
4573:
4574: Inputs: $text $uname $udom $symb $target
4575:
4576: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4577: student and a specific resource
1.242 albertel 4578:
4579: =cut
4580:
4581: ###############################################
4582: sub pprmlink {
4583: my ($text,$uname,$udom,$symb,$target)=@_;
4584: if (!($uname && $udom)) {
4585: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4586: &Apache::lonnet::whichuser($symb);
1.242 albertel 4587: if (!$symb) { $symb=$cursymb; }
4588: }
1.254 matthew 4589: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4590: $symb=&escape($symb);
1.242 albertel 4591: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4592: return '<a href="/adm/parmset?command=set&'.
4593: 'symb='.$symb.'&uname='.$uname.
4594: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4595: }
4596: ##############################################
1.37 matthew 4597:
1.112 bowersj2 4598: =pod
4599:
4600: =back
4601:
4602: =cut
4603:
1.37 matthew 4604: ###############################################
1.51 www 4605:
4606:
4607: sub timehash {
1.687 raeburn 4608: my ($thistime) = @_;
4609: my $timezone = &Apache::lonlocal::gettimezone();
4610: my $dt = DateTime->from_epoch(epoch => $thistime)
4611: ->set_time_zone($timezone);
4612: my $wday = $dt->day_of_week();
4613: if ($wday == 7) { $wday = 0; }
4614: return ( 'second' => $dt->second(),
4615: 'minute' => $dt->minute(),
4616: 'hour' => $dt->hour(),
4617: 'day' => $dt->day_of_month(),
4618: 'month' => $dt->month(),
4619: 'year' => $dt->year(),
4620: 'weekday' => $wday,
4621: 'dayyear' => $dt->day_of_year(),
4622: 'dlsav' => $dt->is_dst() );
1.51 www 4623: }
4624:
1.370 www 4625: sub utc_string {
4626: my ($date)=@_;
1.371 www 4627: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4628: }
4629:
1.51 www 4630: sub maketime {
4631: my %th=@_;
1.687 raeburn 4632: my ($epoch_time,$timezone,$dt);
4633: $timezone = &Apache::lonlocal::gettimezone();
4634: eval {
4635: $dt = DateTime->new( year => $th{'year'},
4636: month => $th{'month'},
4637: day => $th{'day'},
4638: hour => $th{'hour'},
4639: minute => $th{'minute'},
4640: second => $th{'second'},
4641: time_zone => $timezone,
4642: );
4643: };
4644: if (!$@) {
4645: $epoch_time = $dt->epoch;
4646: if ($epoch_time) {
4647: return $epoch_time;
4648: }
4649: }
1.51 www 4650: return POSIX::mktime(
4651: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4652: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4653: }
4654:
4655: #########################################
1.51 www 4656:
4657: sub findallcourses {
1.482 raeburn 4658: my ($roles,$uname,$udom) = @_;
1.355 albertel 4659: my %roles;
4660: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4661: my %courses;
1.51 www 4662: my $now=time;
1.482 raeburn 4663: if (!defined($uname)) {
4664: $uname = $env{'user.name'};
4665: }
4666: if (!defined($udom)) {
4667: $udom = $env{'user.domain'};
4668: }
4669: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4670: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4671: if (!%roles) {
4672: %roles = (
4673: cc => 1,
1.907 raeburn 4674: co => 1,
1.482 raeburn 4675: in => 1,
4676: ep => 1,
4677: ta => 1,
4678: cr => 1,
4679: st => 1,
4680: );
4681: }
4682: foreach my $entry (keys(%roleshash)) {
4683: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4684: if ($trole =~ /^cr/) {
4685: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4686: } else {
4687: next if (!exists($roles{$trole}));
4688: }
4689: if ($tend) {
4690: next if ($tend < $now);
4691: }
4692: if ($tstart) {
4693: next if ($tstart > $now);
4694: }
1.1058 raeburn 4695: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4696: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4697: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4698: if ($secpart eq '') {
4699: ($cnum,$role) = split(/_/,$cnumpart);
4700: $sec = 'none';
1.1058 raeburn 4701: $value .= $cnum.'/';
1.482 raeburn 4702: } else {
4703: $cnum = $cnumpart;
4704: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4705: $value .= $cnum.'/'.$sec;
4706: }
4707: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4708: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4709: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4710: }
4711: } else {
4712: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4713: }
1.482 raeburn 4714: }
4715: } else {
4716: foreach my $key (keys(%env)) {
1.483 albertel 4717: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4718: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4719: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4720: next if ($role eq 'ca' || $role eq 'aa');
4721: next if (%roles && !exists($roles{$role}));
4722: my ($starttime,$endtime)=split(/\./,$env{$key});
4723: my $active=1;
4724: if ($starttime) {
4725: if ($now<$starttime) { $active=0; }
4726: }
4727: if ($endtime) {
4728: if ($now>$endtime) { $active=0; }
4729: }
4730: if ($active) {
1.1058 raeburn 4731: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4732: if ($sec eq '') {
4733: $sec = 'none';
1.1058 raeburn 4734: } else {
4735: $value .= $sec;
4736: }
4737: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4738: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4739: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4740: }
4741: } else {
4742: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4743: }
1.474 raeburn 4744: }
4745: }
1.51 www 4746: }
4747: }
1.474 raeburn 4748: return %courses;
1.51 www 4749: }
1.37 matthew 4750:
1.54 www 4751: ###############################################
1.474 raeburn 4752:
4753: sub blockcheck {
1.1075.2.158 raeburn 4754: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.490 raeburn 4755:
1.1075.2.158 raeburn 4756: unless ($activity eq 'docs') {
4757: my ($has_evb,$check_ipaccess);
4758: my $dom = $env{'user.domain'};
4759: if ($env{'request.course.id'}) {
4760: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4761: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4762: my $checkrole = "cm./$cdom/$cnum";
4763: my $sec = $env{'request.course.sec'};
4764: if ($sec ne '') {
4765: $checkrole .= "/$sec";
4766: }
4767: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
4768: ($env{'request.role'} !~ /^st/)) {
4769: $has_evb = 1;
4770: }
4771: unless ($has_evb) {
4772: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
4773: ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
4774: if ($udom eq $cdom) {
4775: $check_ipaccess = 1;
4776: }
4777: }
4778: }
1.1075.2.163 raeburn 4779: } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
4780: ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
4781: my $checkrole;
4782: if ($env{'request.role.domain'} eq '') {
4783: $checkrole = "cm./$env{'user.domain'}/";
4784: } else {
4785: $checkrole = "cm./$env{'request.role.domain'}/";
4786: }
4787: if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
4788: $has_evb = 1;
4789: }
1.1075.2.158 raeburn 4790: }
4791: unless ($has_evb || $check_ipaccess) {
4792: my @machinedoms = &Apache::lonnet::current_machine_domains();
4793: if (($dom eq 'public') && ($activity eq 'port')) {
4794: $dom = $udom;
4795: }
4796: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
4797: $check_ipaccess = 1;
4798: } else {
4799: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
4800: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
4801: my $prim = &Apache::lonnet::domain($dom,'primary');
4802: my $intdom = &Apache::lonnet::internet_dom($prim);
4803: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
4804: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4805: $check_ipaccess = 1;
4806: }
4807: }
4808: }
4809: }
4810: if ($check_ipaccess) {
4811: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
4812: unless (defined($cached)) {
4813: my %domconfig =
4814: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
4815: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
4816: }
4817: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
4818: foreach my $id (keys(%{$ipaccessref})) {
4819: if (ref($ipaccessref->{$id}) eq 'HASH') {
4820: my $range = $ipaccessref->{$id}->{'ip'};
4821: if ($range) {
4822: if (&Apache::lonnet::ip_match($clientip,$range)) {
4823: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
4824: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
4825: return ('','','',$id,$dom);
4826: last;
4827: }
4828: }
4829: }
4830: }
4831: }
4832: }
4833: }
4834: }
1.1075.2.164 raeburn 4835: if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
4836: return ();
4837: }
1.1075.2.158 raeburn 4838: }
1.1075.2.73 raeburn 4839: if (defined($udom) && defined($uname)) {
4840: # If uname and udom are for a course, check for blocks in the course.
4841: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4842: my ($startblock,$endblock,$triggerblock) =
1.1075.2.147 raeburn 4843: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1075.2.73 raeburn 4844: return ($startblock,$endblock,$triggerblock);
4845: }
4846: } else {
1.490 raeburn 4847: $udom = $env{'user.domain'};
4848: $uname = $env{'user.name'};
4849: }
4850:
1.502 raeburn 4851: my $startblock = 0;
4852: my $endblock = 0;
1.1062 raeburn 4853: my $triggerblock = '';
1.1075.2.160 raeburn 4854: my %live_courses;
4855: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
4856: %live_courses = &findallcourses(undef,$uname,$udom);
4857: }
1.474 raeburn 4858:
1.490 raeburn 4859: # If uname is for a user, and activity is course-specific, i.e.,
4860: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4861:
1.490 raeburn 4862: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4863: $activity eq 'groups' || $activity eq 'printout') &&
4864: ($env{'request.course.id'})) {
1.490 raeburn 4865: foreach my $key (keys(%live_courses)) {
4866: if ($key ne $env{'request.course.id'}) {
4867: delete($live_courses{$key});
4868: }
4869: }
4870: }
4871:
4872: my $otheruser = 0;
4873: my %own_courses;
4874: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4875: # Resource belongs to user other than current user.
4876: $otheruser = 1;
4877: # Gather courses for current user
4878: %own_courses =
4879: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4880: }
4881:
4882: # Gather active course roles - course coordinator, instructor,
4883: # exam proctor, ta, student, or custom role.
1.474 raeburn 4884:
4885: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4886: my ($cdom,$cnum);
4887: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4888: $cdom = $env{'course.'.$course.'.domain'};
4889: $cnum = $env{'course.'.$course.'.num'};
4890: } else {
1.490 raeburn 4891: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4892: }
4893: my $no_ownblock = 0;
4894: my $no_userblock = 0;
1.533 raeburn 4895: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4896: # Check if current user has 'evb' priv for this
4897: if (defined($own_courses{$course})) {
4898: foreach my $sec (keys(%{$own_courses{$course}})) {
4899: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4900: if ($sec ne 'none') {
4901: $checkrole .= '/'.$sec;
4902: }
4903: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4904: $no_ownblock = 1;
4905: last;
4906: }
4907: }
4908: }
4909: # if they have 'evb' priv and are currently not playing student
4910: next if (($no_ownblock) &&
4911: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4912: }
1.474 raeburn 4913: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4914: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4915: if ($sec ne 'none') {
1.482 raeburn 4916: $checkrole .= '/'.$sec;
1.474 raeburn 4917: }
1.490 raeburn 4918: if ($otheruser) {
4919: # Resource belongs to user other than current user.
4920: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4921: my (%allroles,%userroles);
4922: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4923: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4924: my ($trole,$tdom,$tnum,$tsec);
4925: if ($entry =~ /^cr/) {
4926: ($trole,$tdom,$tnum,$tsec) =
4927: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4928: } else {
4929: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4930: }
4931: my ($spec,$area,$trest);
4932: $area = '/'.$tdom.'/'.$tnum;
4933: $trest = $tnum;
4934: if ($tsec ne '') {
4935: $area .= '/'.$tsec;
4936: $trest .= '/'.$tsec;
4937: }
4938: $spec = $trole.'.'.$area;
4939: if ($trole =~ /^cr/) {
4940: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4941: $tdom,$spec,$trest,$area);
4942: } else {
4943: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4944: $tdom,$spec,$trest,$area);
4945: }
4946: }
1.1075.2.124 raeburn 4947: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 4948: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4949: if ($1) {
4950: $no_userblock = 1;
4951: last;
4952: }
1.486 raeburn 4953: }
4954: }
1.490 raeburn 4955: } else {
4956: # Resource belongs to current user
4957: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4958: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4959: $no_ownblock = 1;
4960: last;
4961: }
1.474 raeburn 4962: }
4963: }
4964: # if they have the evb priv and are currently not playing student
1.482 raeburn 4965: next if (($no_ownblock) &&
1.491 albertel 4966: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4967: next if ($no_userblock);
1.474 raeburn 4968:
1.1075.2.128 raeburn 4969: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 4970: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4971:
1.1062 raeburn 4972: my ($start,$end,$trigger) =
1.1075.2.147 raeburn 4973: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 4974: if (($start != 0) &&
4975: (($startblock == 0) || ($startblock > $start))) {
4976: $startblock = $start;
1.1062 raeburn 4977: if ($trigger ne '') {
4978: $triggerblock = $trigger;
4979: }
1.502 raeburn 4980: }
4981: if (($end != 0) &&
4982: (($endblock == 0) || ($endblock < $end))) {
4983: $endblock = $end;
1.1062 raeburn 4984: if ($trigger ne '') {
4985: $triggerblock = $trigger;
4986: }
1.502 raeburn 4987: }
1.490 raeburn 4988: }
1.1062 raeburn 4989: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4990: }
4991:
4992: sub get_blocks {
1.1075.2.147 raeburn 4993: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 4994: my $startblock = 0;
4995: my $endblock = 0;
1.1062 raeburn 4996: my $triggerblock = '';
1.490 raeburn 4997: my $course = $cdom.'_'.$cnum;
4998: $setters->{$course} = {};
4999: $setters->{$course}{'staff'} = [];
5000: $setters->{$course}{'times'} = [];
1.1062 raeburn 5001: $setters->{$course}{'triggers'} = [];
5002: my (@blockers,%triggered);
5003: my $now = time;
5004: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5005: if ($activity eq 'docs') {
1.1075.2.148 raeburn 5006: my ($blocked,$nosymbcache,$noenccheck);
1.1075.2.147 raeburn 5007: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5008: $blocked = 1;
5009: $nosymbcache = 1;
1.1075.2.148 raeburn 5010: $noenccheck = 1;
1.1075.2.147 raeburn 5011: }
1.1075.2.148 raeburn 5012: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5013: foreach my $block (@blockers) {
5014: if ($block =~ /^firstaccess____(.+)$/) {
5015: my $item = $1;
5016: my $type = 'map';
5017: my $timersymb = $item;
5018: if ($item eq 'course') {
5019: $type = 'course';
5020: } elsif ($item =~ /___\d+___/) {
5021: $type = 'resource';
5022: } else {
5023: $timersymb = &Apache::lonnet::symbread($item);
5024: }
5025: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5026: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5027: $triggered{$block} = {
5028: start => $start,
5029: end => $end,
5030: type => $type,
5031: };
5032: }
5033: }
5034: } else {
5035: foreach my $block (keys(%commblocks)) {
5036: if ($block =~ m/^(\d+)____(\d+)$/) {
5037: my ($start,$end) = ($1,$2);
5038: if ($start <= time && $end >= time) {
5039: if (ref($commblocks{$block}) eq 'HASH') {
5040: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5041: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5042: unless(grep(/^\Q$block\E$/,@blockers)) {
5043: push(@blockers,$block);
5044: }
5045: }
5046: }
5047: }
5048: }
5049: } elsif ($block =~ /^firstaccess____(.+)$/) {
5050: my $item = $1;
5051: my $timersymb = $item;
5052: my $type = 'map';
5053: if ($item eq 'course') {
5054: $type = 'course';
5055: } elsif ($item =~ /___\d+___/) {
5056: $type = 'resource';
5057: } else {
5058: $timersymb = &Apache::lonnet::symbread($item);
5059: }
5060: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5061: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5062: if ($start && $end) {
5063: if (($start <= time) && ($end >= time)) {
1.1075.2.158 raeburn 5064: if (ref($commblocks{$block}) eq 'HASH') {
5065: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5066: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5067: unless(grep(/^\Q$block\E$/,@blockers)) {
5068: push(@blockers,$block);
5069: $triggered{$block} = {
5070: start => $start,
5071: end => $end,
5072: type => $type,
5073: };
5074: }
5075: }
5076: }
1.1062 raeburn 5077: }
5078: }
1.490 raeburn 5079: }
1.1062 raeburn 5080: }
5081: }
5082: }
5083: foreach my $blocker (@blockers) {
5084: my ($staff_name,$staff_dom,$title,$blocks) =
5085: &parse_block_record($commblocks{$blocker});
5086: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5087: my ($start,$end,$triggertype);
5088: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5089: ($start,$end) = ($1,$2);
5090: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5091: $start = $triggered{$blocker}{'start'};
5092: $end = $triggered{$blocker}{'end'};
5093: $triggertype = $triggered{$blocker}{'type'};
5094: }
5095: if ($start) {
5096: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5097: if ($triggertype) {
5098: push(@{$$setters{$course}{'triggers'}},$triggertype);
5099: } else {
5100: push(@{$$setters{$course}{'triggers'}},0);
5101: }
5102: if ( ($startblock == 0) || ($startblock > $start) ) {
5103: $startblock = $start;
5104: if ($triggertype) {
5105: $triggerblock = $blocker;
1.474 raeburn 5106: }
5107: }
1.1062 raeburn 5108: if ( ($endblock == 0) || ($endblock < $end) ) {
5109: $endblock = $end;
5110: if ($triggertype) {
5111: $triggerblock = $blocker;
5112: }
5113: }
1.474 raeburn 5114: }
5115: }
1.1062 raeburn 5116: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5117: }
5118:
5119: sub parse_block_record {
5120: my ($record) = @_;
5121: my ($setuname,$setudom,$title,$blocks);
5122: if (ref($record) eq 'HASH') {
5123: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5124: $title = &unescape($record->{'event'});
5125: $blocks = $record->{'blocks'};
5126: } else {
5127: my @data = split(/:/,$record,3);
5128: if (scalar(@data) eq 2) {
5129: $title = $data[1];
5130: ($setuname,$setudom) = split(/@/,$data[0]);
5131: } else {
5132: ($setuname,$setudom,$title) = @data;
5133: }
5134: $blocks = { 'com' => 'on' };
5135: }
5136: return ($setuname,$setudom,$title,$blocks);
5137: }
5138:
1.854 kalberla 5139: sub blocking_status {
1.1075.2.158 raeburn 5140: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5141: my %setters;
1.890 droeschl 5142:
1.1061 raeburn 5143: # check for active blocking
1.1075.2.158 raeburn 5144: if ($clientip eq '') {
5145: $clientip = &Apache::lonnet::get_requestor_ip();
5146: }
5147: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5148: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5149: my $blocked = 0;
1.1075.2.158 raeburn 5150: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5151: $blocked = 1;
5152: }
1.890 droeschl 5153:
1.1061 raeburn 5154: # caller just wants to know whether a block is active
5155: if (!wantarray) { return $blocked; }
5156:
5157: # build a link to a popup window containing the details
5158: my $querystring = "?activity=$activity";
1.1075.2.158 raeburn 5159: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5160: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1075.2.97 raeburn 5161: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5162: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5163: } elsif ($activity eq 'docs') {
1.1075.2.147 raeburn 5164: my $showurl = &Apache::lonenc::check_encrypt($url);
5165: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5166: if ($symb) {
5167: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5168: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5169: }
1.1062 raeburn 5170: }
1.1061 raeburn 5171:
5172: my $output .= <<'END_MYBLOCK';
5173: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5174: var options = "width=" + w + ",height=" + h + ",";
5175: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5176: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5177: var newWin = window.open(url, wdwName, options);
5178: newWin.focus();
5179: }
1.890 droeschl 5180: END_MYBLOCK
1.854 kalberla 5181:
1.1061 raeburn 5182: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5183:
1.1061 raeburn 5184: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5185: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 5186: my $class = 'LC_comblock';
1.1062 raeburn 5187: if ($activity eq 'docs') {
5188: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 5189: $class = '';
1.1063 raeburn 5190: } elsif ($activity eq 'printout') {
5191: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 5192: } elsif ($activity eq 'passwd') {
5193: $text = &mt('Password Changing Blocked');
1.1075.2.158 raeburn 5194: } elsif ($activity eq 'grades') {
5195: $text = &mt('Gradebook Blocked');
5196: } elsif ($activity eq 'search') {
5197: $text = &mt('Search Blocked');
5198: } elsif ($activity eq 'about') {
5199: $text = &mt('Access to User Information Pages Blocked');
1.1075.2.160 raeburn 5200: } elsif ($activity eq 'wishlist') {
5201: $text = &mt('Access to Stored Links Blocked');
5202: } elsif ($activity eq 'annotate') {
5203: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 5204: }
1.1061 raeburn 5205: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 5206: <div class='$class'>
1.869 kalberla 5207: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5208: title='$text'>
5209: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5210: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5211: title='$text'>$text</a>
1.867 kalberla 5212: </div>
5213:
5214: END_BLOCK
1.474 raeburn 5215:
1.1061 raeburn 5216: return ($blocked, $output);
1.854 kalberla 5217: }
1.490 raeburn 5218:
1.60 matthew 5219: ###############################################
5220:
1.682 raeburn 5221: sub check_ip_acc {
1.1075.2.105 raeburn 5222: my ($acc,$clientip)=@_;
1.682 raeburn 5223: &Apache::lonxml::debug("acc is $acc");
5224: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5225: return 1;
5226: }
5227: my $allowed=0;
1.1075.2.144 raeburn 5228: my $ip;
5229: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5230: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5231: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5232: } else {
1.1075.2.150 raeburn 5233: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5234: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1075.2.144 raeburn 5235: }
1.682 raeburn 5236:
5237: my $name;
5238: foreach my $pattern (split(',',$acc)) {
5239: $pattern =~ s/^\s*//;
5240: $pattern =~ s/\s*$//;
5241: if ($pattern =~ /\*$/) {
5242: #35.8.*
5243: $pattern=~s/\*//;
5244: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5245: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5246: #35.8.3.[34-56]
5247: my $low=$2;
5248: my $high=$3;
5249: $pattern=$1;
5250: if ($ip =~ /^\Q$pattern\E/) {
5251: my $last=(split(/\./,$ip))[3];
5252: if ($last <=$high && $last >=$low) { $allowed=1; }
5253: }
5254: } elsif ($pattern =~ /^\*/) {
5255: #*.msu.edu
5256: $pattern=~s/\*//;
5257: if (!defined($name)) {
5258: use Socket;
5259: my $netaddr=inet_aton($ip);
5260: ($name)=gethostbyaddr($netaddr,AF_INET);
5261: }
5262: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5263: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5264: #127.0.0.1
5265: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5266: } else {
5267: #some.name.com
5268: if (!defined($name)) {
5269: use Socket;
5270: my $netaddr=inet_aton($ip);
5271: ($name)=gethostbyaddr($netaddr,AF_INET);
5272: }
5273: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5274: }
5275: if ($allowed) { last; }
5276: }
5277: return $allowed;
5278: }
5279:
5280: ###############################################
5281:
1.60 matthew 5282: =pod
5283:
1.112 bowersj2 5284: =head1 Domain Template Functions
5285:
5286: =over 4
5287:
5288: =item * &determinedomain()
1.60 matthew 5289:
5290: Inputs: $domain (usually will be undef)
5291:
1.63 www 5292: Returns: Determines which domain should be used for designs
1.60 matthew 5293:
5294: =cut
1.54 www 5295:
1.60 matthew 5296: ###############################################
1.63 www 5297: sub determinedomain {
5298: my $domain=shift;
1.531 albertel 5299: if (! $domain) {
1.60 matthew 5300: # Determine domain if we have not been given one
1.893 raeburn 5301: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5302: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5303: if ($env{'request.role.domain'}) {
5304: $domain=$env{'request.role.domain'};
1.60 matthew 5305: }
5306: }
1.63 www 5307: return $domain;
5308: }
5309: ###############################################
1.517 raeburn 5310:
1.518 albertel 5311: sub devalidate_domconfig_cache {
5312: my ($udom)=@_;
5313: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5314: }
5315:
5316: # ---------------------- Get domain configuration for a domain
5317: sub get_domainconf {
5318: my ($udom) = @_;
5319: my $cachetime=1800;
5320: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5321: if (defined($cached)) { return %{$result}; }
5322:
5323: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5324: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5325: my (%designhash,%legacy);
1.518 albertel 5326: if (keys(%domconfig) > 0) {
5327: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5328: if (keys(%{$domconfig{'login'}})) {
5329: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5330: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5331: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5332: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5333: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5334: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5335: if ($key eq 'loginvia') {
5336: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5337: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5338: $designhash{$udom.'.login.loginvia'} = $server;
5339: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5340: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5341: } else {
5342: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5343: }
1.948 raeburn 5344: }
1.1075.2.87 raeburn 5345: } elsif ($key eq 'headtag') {
5346: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5347: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5348: }
1.946 raeburn 5349: }
1.1075.2.87 raeburn 5350: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5351: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5352: }
1.946 raeburn 5353: }
5354: }
5355: }
1.1075.2.158 raeburn 5356: } elsif ($key eq 'saml') {
5357: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5358: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
5359: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
5360: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
5361: foreach my $item ('text','img','alt','url','title','notsso') {
5362: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
5363: }
5364: }
5365: }
5366: }
1.946 raeburn 5367: } else {
5368: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5369: $designhash{$udom.'.login.'.$key.'_'.$img} =
5370: $domconfig{'login'}{$key}{$img};
5371: }
1.699 raeburn 5372: }
5373: } else {
5374: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5375: }
1.632 raeburn 5376: }
5377: } else {
5378: $legacy{'login'} = 1;
1.518 albertel 5379: }
1.632 raeburn 5380: } else {
5381: $legacy{'login'} = 1;
1.518 albertel 5382: }
5383: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5384: if (keys(%{$domconfig{'rolecolors'}})) {
5385: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5386: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5387: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5388: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5389: }
1.518 albertel 5390: }
5391: }
1.632 raeburn 5392: } else {
5393: $legacy{'rolecolors'} = 1;
1.518 albertel 5394: }
1.632 raeburn 5395: } else {
5396: $legacy{'rolecolors'} = 1;
1.518 albertel 5397: }
1.948 raeburn 5398: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5399: if ($domconfig{'autoenroll'}{'co-owners'}) {
5400: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5401: }
5402: }
1.632 raeburn 5403: if (keys(%legacy) > 0) {
5404: my %legacyhash = &get_legacy_domconf($udom);
5405: foreach my $item (keys(%legacyhash)) {
5406: if ($item =~ /^\Q$udom\E\.login/) {
5407: if ($legacy{'login'}) {
5408: $designhash{$item} = $legacyhash{$item};
5409: }
5410: } else {
5411: if ($legacy{'rolecolors'}) {
5412: $designhash{$item} = $legacyhash{$item};
5413: }
1.518 albertel 5414: }
5415: }
5416: }
1.632 raeburn 5417: } else {
5418: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5419: }
5420: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5421: $cachetime);
5422: return %designhash;
5423: }
5424:
1.632 raeburn 5425: sub get_legacy_domconf {
5426: my ($udom) = @_;
5427: my %legacyhash;
5428: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5429: my $designfile = $designdir.'/'.$udom.'.tab';
5430: if (-e $designfile) {
1.1075.2.128 raeburn 5431: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5432: while (my $line = <$fh>) {
5433: next if ($line =~ /^\#/);
5434: chomp($line);
5435: my ($key,$val)=(split(/\=/,$line));
5436: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5437: }
5438: close($fh);
5439: }
5440: }
1.1026 raeburn 5441: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5442: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5443: }
5444: return %legacyhash;
5445: }
5446:
1.63 www 5447: =pod
5448:
1.112 bowersj2 5449: =item * &domainlogo()
1.63 www 5450:
5451: Inputs: $domain (usually will be undef)
5452:
5453: Returns: A link to a domain logo, if the domain logo exists.
5454: If the domain logo does not exist, a description of the domain.
5455:
5456: =cut
1.112 bowersj2 5457:
1.63 www 5458: ###############################################
5459: sub domainlogo {
1.517 raeburn 5460: my $domain = &determinedomain(shift);
1.518 albertel 5461: my %designhash = &get_domainconf($domain);
1.517 raeburn 5462: # See if there is a logo
5463: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5464: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5465: if ($imgsrc =~ m{^/(adm|res)/}) {
5466: if ($imgsrc =~ m{^/res/}) {
5467: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5468: &Apache::lonnet::repcopy($local_name);
5469: }
5470: $imgsrc = &lonhttpdurl($imgsrc);
1.1075.2.162 raeburn 5471: }
5472: my $alttext = $domain;
5473: if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
5474: $alttext = $designhash{$domain.'.login.alttext_domlogo'};
5475: }
5476: return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 5477: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5478: return &Apache::lonnet::domain($domain,'description');
1.59 www 5479: } else {
1.60 matthew 5480: return '';
1.59 www 5481: }
5482: }
1.63 www 5483: ##############################################
5484:
5485: =pod
5486:
1.112 bowersj2 5487: =item * &designparm()
1.63 www 5488:
5489: Inputs: $which parameter; $domain (usually will be undef)
5490:
5491: Returns: value of designparamter $which
5492:
5493: =cut
1.112 bowersj2 5494:
1.397 albertel 5495:
1.400 albertel 5496: ##############################################
1.397 albertel 5497: sub designparm {
5498: my ($which,$domain)=@_;
5499: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5500: return $env{'environment.color.'.$which};
1.96 www 5501: }
1.63 www 5502: $domain=&determinedomain($domain);
1.1016 raeburn 5503: my %domdesign;
5504: unless ($domain eq 'public') {
5505: %domdesign = &get_domainconf($domain);
5506: }
1.520 raeburn 5507: my $output;
1.517 raeburn 5508: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5509: $output = $domdesign{$domain.'.'.$which};
1.63 www 5510: } else {
1.520 raeburn 5511: $output = $defaultdesign{$which};
5512: }
5513: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5514: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5515: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5516: if ($output =~ m{^/res/}) {
5517: my $local_name = &Apache::lonnet::filelocation('',$output);
5518: &Apache::lonnet::repcopy($local_name);
5519: }
1.520 raeburn 5520: $output = &lonhttpdurl($output);
5521: }
1.63 www 5522: }
1.520 raeburn 5523: return $output;
1.63 www 5524: }
1.59 www 5525:
1.822 bisitz 5526: ##############################################
5527: =pod
5528:
1.832 bisitz 5529: =item * &authorspace()
5530:
1.1028 raeburn 5531: Inputs: $url (usually will be undef).
1.832 bisitz 5532:
1.1075.2.40 raeburn 5533: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5534: directory being viewed (or for which action is being taken).
5535: If $url is provided, and begins /priv/<domain>/<uname>
5536: the path will be that portion of the $context argument.
5537: Otherwise the path will be for the author space of the current
5538: user when the current role is author, or for that of the
5539: co-author/assistant co-author space when the current role
5540: is co-author or assistant co-author.
1.832 bisitz 5541:
5542: =cut
5543:
5544: sub authorspace {
1.1028 raeburn 5545: my ($url) = @_;
5546: if ($url ne '') {
5547: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5548: return $1;
5549: }
5550: }
1.832 bisitz 5551: my $caname = '';
1.1024 www 5552: my $cadom = '';
1.1028 raeburn 5553: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5554: ($cadom,$caname) =
1.832 bisitz 5555: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5556: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5557: $caname = $env{'user.name'};
1.1024 www 5558: $cadom = $env{'user.domain'};
1.832 bisitz 5559: }
1.1028 raeburn 5560: if (($caname ne '') && ($cadom ne '')) {
5561: return "/priv/$cadom/$caname/";
5562: }
5563: return;
1.832 bisitz 5564: }
5565:
5566: ##############################################
5567: =pod
5568:
1.822 bisitz 5569: =item * &head_subbox()
5570:
5571: Inputs: $content (contains HTML code with page functions, etc.)
5572:
5573: Returns: HTML div with $content
5574: To be included in page header
5575:
5576: =cut
5577:
5578: sub head_subbox {
5579: my ($content)=@_;
5580: my $output =
1.993 raeburn 5581: '<div class="LC_head_subbox">'
1.822 bisitz 5582: .$content
5583: .'</div>'
5584: }
5585:
5586: ##############################################
5587: =pod
5588:
5589: =item * &CSTR_pageheader()
5590:
1.1026 raeburn 5591: Input: (optional) filename from which breadcrumb trail is built.
5592: In most cases no input as needed, as $env{'request.filename'}
5593: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5594:
5595: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5596: To be included on Authoring Space pages
1.822 bisitz 5597:
5598: =cut
5599:
5600: sub CSTR_pageheader {
1.1026 raeburn 5601: my ($trailfile) = @_;
5602: if ($trailfile eq '') {
5603: $trailfile = $env{'request.filename'};
5604: }
5605:
5606: # this is for resources; directories have customtitle, and crumbs
5607: # and select recent are created in lonpubdir.pm
5608:
5609: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5610: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5611: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5612: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5613: $formaction =~ s{/+}{/}g;
1.822 bisitz 5614:
5615: my $parentpath = '';
5616: my $lastitem = '';
5617: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5618: $parentpath = $1;
5619: $lastitem = $2;
5620: } else {
5621: $lastitem = $thisdisfn;
5622: }
1.921 bisitz 5623:
5624: my $output =
1.822 bisitz 5625: '<div>'
5626: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5627: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5628: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5629: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5630: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5631:
5632: if ($lastitem) {
5633: $output .=
5634: '<span class="LC_filename">'
5635: .$lastitem
5636: .'</span>';
5637: }
5638: $output .=
5639: '<br />'
1.822 bisitz 5640: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5641: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5642: .'</form>'
5643: .&Apache::lonmenu::constspaceform()
5644: .'</div>';
1.921 bisitz 5645:
5646: return $output;
1.822 bisitz 5647: }
5648:
1.60 matthew 5649: ###############################################
5650: ###############################################
5651:
5652: =pod
5653:
1.112 bowersj2 5654: =back
5655:
1.549 albertel 5656: =head1 HTML Helpers
1.112 bowersj2 5657:
5658: =over 4
5659:
5660: =item * &bodytag()
1.60 matthew 5661:
5662: Returns a uniform header for LON-CAPA web pages.
5663:
5664: Inputs:
5665:
1.112 bowersj2 5666: =over 4
5667:
5668: =item * $title, A title to be displayed on the page.
5669:
5670: =item * $function, the current role (can be undef).
5671:
5672: =item * $addentries, extra parameters for the <body> tag.
5673:
5674: =item * $bodyonly, if defined, only return the <body> tag.
5675:
5676: =item * $domain, if defined, force a given domain.
5677:
5678: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5679: text interface only)
1.60 matthew 5680:
1.814 bisitz 5681: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5682: navigational links
1.317 albertel 5683:
1.338 albertel 5684: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5685:
1.1075.2.12 raeburn 5686: =item * $no_inline_link, if true and in remote mode, don't show the
5687: 'Switch To Inline Menu' link
5688:
1.460 albertel 5689: =item * $args, optional argument valid values are
5690: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 5691: use_absolute -> for external resource or syllabus, this will
5692: contain https://<hostname> if server uses
5693: https (as per hosts.tab), but request is for http
5694: hostname -> hostname, from $r->hostname().
1.460 albertel 5695:
1.1075.2.15 raeburn 5696: =item * $advtoolsref, optional argument, ref to an array containing
5697: inlineremote items to be added in "Functions" menu below
5698: breadcrumbs.
5699:
1.112 bowersj2 5700: =back
5701:
1.60 matthew 5702: Returns: A uniform header for LON-CAPA web pages.
5703: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5704: If $bodyonly is undef or zero, an html string containing a <body> tag and
5705: other decorations will be returned.
5706:
5707: =cut
5708:
1.54 www 5709: sub bodytag {
1.831 bisitz 5710: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5711: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5712:
1.954 raeburn 5713: my $public;
5714: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5715: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5716: $public = 1;
5717: }
1.460 albertel 5718: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5719: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 5720: my $hostname = $args->{'hostname'};
1.339 albertel 5721:
1.183 matthew 5722: $function = &get_users_function() if (!$function);
1.339 albertel 5723: my $img = &designparm($function.'.img',$domain);
5724: my $font = &designparm($function.'.font',$domain);
5725: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5726:
1.803 bisitz 5727: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5728: 'bgcolor' => $pgbg,
1.339 albertel 5729: 'text' => $font,
5730: 'alink' => &designparm($function.'.alink',$domain),
5731: 'vlink' => &designparm($function.'.vlink',$domain),
5732: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5733: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5734:
1.63 www 5735: # role and realm
1.1075.2.68 raeburn 5736: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5737: if ($realm) {
5738: $realm = '/'.$realm;
5739: }
1.1075.2.159 raeburn 5740: if ($role eq 'ca') {
1.479 albertel 5741: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5742: $realm = &plainname($rname,$rdom);
1.378 raeburn 5743: }
1.55 www 5744: # realm
1.1075.2.158 raeburn 5745: my ($cid,$sec);
1.258 albertel 5746: if ($env{'request.course.id'}) {
1.1075.2.158 raeburn 5747: $cid = $env{'request.course.id'};
5748: if ($env{'request.course.sec'}) {
5749: $sec = $env{'request.course.sec'};
5750: }
5751: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
5752: if (&Apache::lonnet::is_course($1,$2)) {
5753: $cid = $1.'_'.$2;
5754: $sec = $3;
5755: }
5756: }
5757: if ($cid) {
1.378 raeburn 5758: if ($env{'request.role'} !~ /^cr/) {
5759: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5760: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5761: if ($env{'request.role.desc'}) {
5762: $role = $env{'request.role.desc'};
5763: } else {
5764: $role = &mt('Helpdesk[_1]',' '.$2);
5765: }
1.1075.2.115 raeburn 5766: } else {
5767: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5768: }
1.1075.2.158 raeburn 5769: if ($sec) {
5770: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 5771: }
1.1075.2.158 raeburn 5772: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 5773: } else {
5774: $role = &Apache::lonnet::plaintext($role);
1.54 www 5775: }
1.433 albertel 5776:
1.359 albertel 5777: if (!$realm) { $realm=' '; }
1.330 albertel 5778:
1.438 albertel 5779: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5780:
1.101 www 5781: # construct main body tag
1.359 albertel 5782: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5783: &Apache::lontexconvert::init_math_support();
1.252 albertel 5784:
1.1075.2.38 raeburn 5785: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5786:
5787: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5788: return $bodytag;
1.1075.2.38 raeburn 5789: }
1.359 albertel 5790:
1.954 raeburn 5791: if ($public) {
1.433 albertel 5792: undef($role);
5793: }
1.1075.2.158 raeburn 5794:
1.762 bisitz 5795: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5796: #
5797: # Extra info if you are the DC
5798: my $dc_info = '';
1.1075.2.159 raeburn 5799: if (($env{'user.adv'}) && ($env{'request.course.id'}) &&
1.1075.2.158 raeburn 5800: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 5801: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5802: $dc_info =~ s/\s+$//;
1.359 albertel 5803: }
5804:
1.1075.2.108 raeburn 5805: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5806:
1.1075.2.13 raeburn 5807: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5808:
1.1075.2.38 raeburn 5809:
5810:
1.1075.2.21 raeburn 5811: my $funclist;
5812: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.174 raeburn 5813: unless ($args->{'switchserver'}) {
5814: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
5815: Apache::lonmenu::serverform();
5816: my $forbodytag;
5817: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5818: $forcereg,$args->{'group'},
5819: $args->{'bread_crumbs'},
5820: $advtoolsref,'','',\$forbodytag);
5821: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5822: $funclist = $forbodytag;
5823: }
5824: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.1075.2.21 raeburn 5825: }
5826: } else {
1.903 droeschl 5827:
5828: # if ($env{'request.state'} eq 'construct') {
5829: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5830: # }
5831:
1.1075.2.172 raeburn 5832: my $need_endlcint;
5833: unless ($args->{'switchserver'}) {
5834: $bodytag .= Apache::lonhtmlcommon::scripttag(
5835: Apache::lonmenu::utilityfunctions($httphost), 'start');
5836: $need_endlcint = 1;
5837: }
1.359 albertel 5838:
1.1075.2.171 raeburn 5839: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} eq 'construct')) {
5840: unless ($env{'form.inhibitmenu'}) {
5841: $bodytag .= &inline_for_remote($public,$role,$realm,$dc_info,$no_inline_link);
5842: }
5843: } else {
5844: my ($left,$right) = Apache::lonmenu::primary_menu($args->{'links_disabled'});
1.1075.2.2 raeburn 5845:
1.1075.2.171 raeburn 5846: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
5847: if ($dc_info) {
5848: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5849: }
5850: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
5851: <em>$realm</em> $dc_info</div>|;
1.1075.2.172 raeburn 5852: if ($need_endlcint) {
5853: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5854: }
1.1075.2.171 raeburn 5855: return $bodytag;
1.1075.2.1 raeburn 5856: }
1.894 droeschl 5857:
1.1075.2.171 raeburn 5858: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
5859: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
5860: }
1.916 droeschl 5861:
1.1075.2.171 raeburn 5862: $bodytag .= $right;
1.852 droeschl 5863:
1.1075.2.171 raeburn 5864: if ($dc_info) {
5865: $dc_info = &dc_courseid_toggle($dc_info);
5866: }
5867: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 5868: }
1.916 droeschl 5869:
1.1075.2.61 raeburn 5870: #if directed to not display the secondary menu, don't.
5871: if ($args->{'no_secondary_menu'}) {
1.1075.2.172 raeburn 5872: if ($need_endlcint) {
5873: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5874: }
1.1075.2.61 raeburn 5875: return $bodytag;
5876: }
1.903 droeschl 5877: #don't show menus for public users
1.954 raeburn 5878: if (!$public){
1.1075.2.171 raeburn 5879: unless (($env{'environment.remote'} eq 'on') &&
5880: ($env{'request.state'} eq 'construct')) {
5881: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$args->{'links_disabled'});
5882: }
1.903 droeschl 5883: $bodytag .= Apache::lonmenu::serverform();
1.1075.2.172 raeburn 5884: if ($need_endlcint) {
5885: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5886: }
1.920 raeburn 5887: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5888: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.133 raeburn 5889: $args->{'bread_crumbs'},'','',$hostname);
1.1075.2.116 raeburn 5890: } elsif ($forcereg) {
1.1075.2.22 raeburn 5891: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5892: $args->{'group'},
1.1075.2.161 raeburn 5893: $args->{'hide_buttons'},
5894: $hostname);
1.1075.2.15 raeburn 5895: } else {
1.1075.2.21 raeburn 5896: my $forbodytag;
5897: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5898: $forcereg,$args->{'group'},
5899: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5900: $advtoolsref,'',$hostname,
5901: \$forbodytag);
1.1075.2.21 raeburn 5902: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5903: $bodytag .= $forbodytag;
5904: }
1.920 raeburn 5905: }
1.1075.2.172 raeburn 5906: } else {
5907: # this is to separate menu from content when there's no secondary
1.903 droeschl 5908: # menu. Especially needed for public accessible ressources.
5909: $bodytag .= '<hr style="clear:both" />';
1.1075.2.172 raeburn 5910: if ($need_endlcint) {
5911: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5912: }
1.235 raeburn 5913: }
1.903 droeschl 5914:
1.235 raeburn 5915: return $bodytag;
1.1075.2.12 raeburn 5916: }
5917:
5918: #
5919: # Top frame rendering, Remote is up
5920: #
5921:
1.1075.2.173 raeburn 5922: my $linkattr;
5923: if ($args->{'links_disabled'}) {
5924: $linkattr = 'class="LCisDisabled" aria-disabled="true"';
5925: }
5926:
1.1075.2.60 raeburn 5927: my $help=($no_inline_link?''
1.1075.2.173 raeburn 5928: :&top_nav_help('Help',$linkattr));
1.1075.2.60 raeburn 5929:
1.1075.2.12 raeburn 5930: # Explicit link to get inline menu
5931: my $menu= ($no_inline_link?''
1.1075.2.173 raeburn 5932: :'<a href="/adm/remote?action=collapse" $linkattr target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
1.1075.2.12 raeburn 5933:
5934: if ($dc_info) {
5935: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5936: }
5937:
1.1075.2.38 raeburn 5938: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5939: unless ($public) {
1.1075.2.173 raeburn 5940: my $class = 'LC_menubuttons_link';
5941: if ($args->{'links_disabled'}) {
5942: $class .= ' LCisDisabled';
5943: }
1.1075.2.38 raeburn 5944: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
1.1075.2.173 raeburn 5945: undef,$class);
1.1075.2.38 raeburn 5946: }
5947:
1.1075.2.12 raeburn 5948: unless ($env{'form.inhibitmenu'}) {
1.1075.2.171 raeburn 5949: $bodytag .= &inline_for_remote($public,$role,$realm,$dc_info,$no_inline_link);
1.1075.2.12 raeburn 5950: }
1.1075.2.21 raeburn 5951: return $bodytag."\n".$funclist;
1.182 matthew 5952: }
5953:
1.1075.2.171 raeburn 5954: sub inline_for_remote {
5955: my ($public,$role,$realm,$dc_info,$no_inline_link) = @_;
5956: my $help=($no_inline_link?''
5957: :&Apache::loncommon::top_nav_help('Help'));
5958:
5959: # Explicit link to get inline menu
5960: my $menu= ($no_inline_link?''
5961: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5962:
5963: if ($dc_info) {
5964: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5965: }
5966:
5967: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5968: unless ($public) {
5969: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5970: undef,'LC_menubuttons_link');
5971: }
5972:
5973: return qq|<div id="LC_nav_bar">$name $role</div>
5974: <ol class="LC_primary_menu LC_floatright LC_right">
5975: <li>$help</li>
5976: <li>$menu</li>
5977: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5978: }
5979:
1.917 raeburn 5980: sub dc_courseid_toggle {
5981: my ($dc_info) = @_;
1.980 raeburn 5982: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5983: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5984: &mt('(More ...)').'</a></span>'.
5985: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5986: }
5987:
1.330 albertel 5988: sub make_attr_string {
5989: my ($register,$attr_ref) = @_;
5990:
5991: if ($attr_ref && !ref($attr_ref)) {
5992: die("addentries Must be a hash ref ".
5993: join(':',caller(1))." ".
5994: join(':',caller(0))." ");
5995: }
5996:
5997: if ($register) {
1.339 albertel 5998: my ($on_load,$on_unload);
5999: foreach my $key (keys(%{$attr_ref})) {
6000: if (lc($key) eq 'onload') {
6001: $on_load.=$attr_ref->{$key}.';';
6002: delete($attr_ref->{$key});
6003:
6004: } elsif (lc($key) eq 'onunload') {
6005: $on_unload.=$attr_ref->{$key}.';';
6006: delete($attr_ref->{$key});
6007: }
6008: }
1.1075.2.12 raeburn 6009: if ($env{'environment.remote'} eq 'on') {
6010: $attr_ref->{'onload'} =
6011: &Apache::lonmenu::loadevents(). $on_load;
6012: $attr_ref->{'onunload'}=
6013: &Apache::lonmenu::unloadevents().$on_unload;
6014: } else {
6015: $attr_ref->{'onload'} = $on_load;
6016: $attr_ref->{'onunload'}= $on_unload;
6017: }
1.330 albertel 6018: }
1.339 albertel 6019:
1.330 albertel 6020: my $attr_string;
1.1075.2.56 raeburn 6021: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6022: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6023: }
6024: return $attr_string;
6025: }
6026:
6027:
1.182 matthew 6028: ###############################################
1.251 albertel 6029: ###############################################
6030:
6031: =pod
6032:
6033: =item * &endbodytag()
6034:
6035: Returns a uniform footer for LON-CAPA web pages.
6036:
1.635 raeburn 6037: Inputs: 1 - optional reference to an args hash
6038: If in the hash, key for noredirectlink has a value which evaluates to true,
6039: a 'Continue' link is not displayed if the page contains an
6040: internal redirect in the <head></head> section,
6041: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6042:
6043: =cut
6044:
6045: sub endbodytag {
1.635 raeburn 6046: my ($args) = @_;
1.1075.2.6 raeburn 6047: my $endbodytag;
6048: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6049: $endbodytag='</body>';
6050: }
1.315 albertel 6051: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6052: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6053: $endbodytag=
6054: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6055: &mt('Continue').'</a>'.
6056: $endbodytag;
6057: }
1.315 albertel 6058: }
1.1075.2.165 raeburn 6059: if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
6060: $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
6061: }
1.251 albertel 6062: return $endbodytag;
6063: }
6064:
1.352 albertel 6065: =pod
6066:
6067: =item * &standard_css()
6068:
6069: Returns a style sheet
6070:
6071: Inputs: (all optional)
6072: domain -> force to color decorate a page for a specific
6073: domain
6074: function -> force usage of a specific rolish color scheme
6075: bgcolor -> override the default page bgcolor
6076:
6077: =cut
6078:
1.343 albertel 6079: sub standard_css {
1.345 albertel 6080: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6081: $function = &get_users_function() if (!$function);
6082: my $img = &designparm($function.'.img', $domain);
6083: my $tabbg = &designparm($function.'.tabbg', $domain);
6084: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6085: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6086: #second colour for later usage
1.345 albertel 6087: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6088: my $pgbg_or_bgcolor =
6089: $bgcolor ||
1.352 albertel 6090: &designparm($function.'.pgbg', $domain);
1.382 albertel 6091: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6092: my $alink = &designparm($function.'.alink', $domain);
6093: my $vlink = &designparm($function.'.vlink', $domain);
6094: my $link = &designparm($function.'.link', $domain);
6095:
1.602 albertel 6096: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6097: my $mono = 'monospace';
1.850 bisitz 6098: my $data_table_head = $sidebg;
6099: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6100: my $data_table_dark = '#E0E0E0';
1.470 banghart 6101: my $data_table_darker = '#CCCCCC';
1.349 albertel 6102: my $data_table_highlight = '#FFFF00';
1.352 albertel 6103: my $mail_new = '#FFBB77';
6104: my $mail_new_hover = '#DD9955';
6105: my $mail_read = '#BBBB77';
6106: my $mail_read_hover = '#999944';
6107: my $mail_replied = '#AAAA88';
6108: my $mail_replied_hover = '#888855';
6109: my $mail_other = '#99BBBB';
6110: my $mail_other_hover = '#669999';
1.391 albertel 6111: my $table_header = '#DDDDDD';
1.489 raeburn 6112: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6113: my $lg_border_color = '#C8C8C8';
1.952 onken 6114: my $button_hover = '#BF2317';
1.392 albertel 6115:
1.608 albertel 6116: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6117: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6118: : '0 3px 0 4px';
1.448 albertel 6119:
1.523 albertel 6120:
1.343 albertel 6121: return <<END;
1.947 droeschl 6122:
6123: /* needed for iframe to allow 100% height in FF */
6124: body, html {
6125: margin: 0;
6126: padding: 0 0.5%;
6127: height: 99%; /* to avoid scrollbars */
6128: }
6129:
1.795 www 6130: body {
1.911 bisitz 6131: font-family: $sans;
6132: line-height:130%;
6133: font-size:0.83em;
6134: color:$font;
1.795 www 6135: }
6136:
1.959 onken 6137: a:focus,
6138: a:focus img {
1.795 www 6139: color: red;
6140: }
1.698 harmsja 6141:
1.911 bisitz 6142: form, .inline {
6143: display: inline;
1.795 www 6144: }
1.721 harmsja 6145:
1.795 www 6146: .LC_right {
1.911 bisitz 6147: text-align:right;
1.795 www 6148: }
6149:
6150: .LC_middle {
1.911 bisitz 6151: vertical-align:middle;
1.795 www 6152: }
1.721 harmsja 6153:
1.1075.2.38 raeburn 6154: .LC_floatleft {
6155: float: left;
6156: }
6157:
6158: .LC_floatright {
6159: float: right;
6160: }
6161:
1.911 bisitz 6162: .LC_400Box {
6163: width:400px;
6164: }
1.721 harmsja 6165:
1.947 droeschl 6166: .LC_iframecontainer {
6167: width: 98%;
6168: margin: 0;
6169: position: fixed;
6170: top: 8.5em;
6171: bottom: 0;
6172: }
6173:
6174: .LC_iframecontainer iframe{
6175: border: none;
6176: width: 100%;
6177: height: 100%;
6178: }
6179:
1.778 bisitz 6180: .LC_filename {
6181: font-family: $mono;
6182: white-space:pre;
1.921 bisitz 6183: font-size: 120%;
1.778 bisitz 6184: }
6185:
6186: .LC_fileicon {
6187: border: none;
6188: height: 1.3em;
6189: vertical-align: text-bottom;
6190: margin-right: 0.3em;
6191: text-decoration:none;
6192: }
6193:
1.1008 www 6194: .LC_setting {
6195: text-decoration:underline;
6196: }
6197:
1.350 albertel 6198: .LC_error {
6199: color: red;
6200: }
1.795 www 6201:
1.1075.2.15 raeburn 6202: .LC_warning {
6203: color: darkorange;
6204: }
6205:
1.457 albertel 6206: .LC_diff_removed {
1.733 bisitz 6207: color: red;
1.394 albertel 6208: }
1.532 albertel 6209:
6210: .LC_info,
1.457 albertel 6211: .LC_success,
6212: .LC_diff_added {
1.350 albertel 6213: color: green;
6214: }
1.795 www 6215:
1.802 bisitz 6216: div.LC_confirm_box {
6217: background-color: #FAFAFA;
6218: border: 1px solid $lg_border_color;
6219: margin-right: 0;
6220: padding: 5px;
6221: }
6222:
6223: div.LC_confirm_box .LC_error img,
6224: div.LC_confirm_box .LC_success img {
6225: vertical-align: middle;
6226: }
6227:
1.1075.2.108 raeburn 6228: .LC_maxwidth {
6229: max-width: 100%;
6230: height: auto;
6231: }
6232:
6233: .LC_textsize_mobile {
6234: \@media only screen and (max-device-width: 480px) {
6235: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6236: }
6237: }
6238:
1.440 albertel 6239: .LC_icon {
1.771 droeschl 6240: border: none;
1.790 droeschl 6241: vertical-align: middle;
1.771 droeschl 6242: }
6243:
1.543 albertel 6244: .LC_docs_spacer {
6245: width: 25px;
6246: height: 1px;
1.771 droeschl 6247: border: none;
1.543 albertel 6248: }
1.346 albertel 6249:
1.532 albertel 6250: .LC_internal_info {
1.735 bisitz 6251: color: #999999;
1.532 albertel 6252: }
6253:
1.794 www 6254: .LC_discussion {
1.1050 www 6255: background: $data_table_dark;
1.911 bisitz 6256: border: 1px solid black;
6257: margin: 2px;
1.794 www 6258: }
6259:
6260: .LC_disc_action_left {
1.1050 www 6261: background: $sidebg;
1.911 bisitz 6262: text-align: left;
1.1050 www 6263: padding: 4px;
6264: margin: 2px;
1.794 www 6265: }
6266:
6267: .LC_disc_action_right {
1.1050 www 6268: background: $sidebg;
1.911 bisitz 6269: text-align: right;
1.1050 www 6270: padding: 4px;
6271: margin: 2px;
1.794 www 6272: }
6273:
6274: .LC_disc_new_item {
1.911 bisitz 6275: background: white;
6276: border: 2px solid red;
1.1050 www 6277: margin: 4px;
6278: padding: 4px;
1.794 www 6279: }
6280:
6281: .LC_disc_old_item {
1.911 bisitz 6282: background: white;
1.1050 www 6283: margin: 4px;
6284: padding: 4px;
1.794 www 6285: }
6286:
1.458 albertel 6287: table.LC_pastsubmission {
6288: border: 1px solid black;
6289: margin: 2px;
6290: }
6291:
1.924 bisitz 6292: table#LC_menubuttons {
1.345 albertel 6293: width: 100%;
6294: background: $pgbg;
1.392 albertel 6295: border: 2px;
1.402 albertel 6296: border-collapse: separate;
1.803 bisitz 6297: padding: 0;
1.345 albertel 6298: }
1.392 albertel 6299:
1.801 tempelho 6300: table#LC_title_bar a {
6301: color: $fontmenu;
6302: }
1.836 bisitz 6303:
1.807 droeschl 6304: table#LC_title_bar {
1.819 tempelho 6305: clear: both;
1.836 bisitz 6306: display: none;
1.807 droeschl 6307: }
6308:
1.795 www 6309: table#LC_title_bar,
1.933 droeschl 6310: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6311: table#LC_title_bar.LC_with_remote {
1.359 albertel 6312: width: 100%;
1.392 albertel 6313: border-color: $pgbg;
6314: border-style: solid;
6315: border-width: $border;
1.379 albertel 6316: background: $pgbg;
1.801 tempelho 6317: color: $fontmenu;
1.392 albertel 6318: border-collapse: collapse;
1.803 bisitz 6319: padding: 0;
1.819 tempelho 6320: margin: 0;
1.359 albertel 6321: }
1.795 www 6322:
1.933 droeschl 6323: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6324: margin: 0;
6325: padding: 0;
1.933 droeschl 6326: position: relative;
6327: list-style: none;
1.913 droeschl 6328: }
1.933 droeschl 6329: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6330: display: inline;
6331: }
1.933 droeschl 6332:
6333: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6334: padding: 0;
1.933 droeschl 6335: margin: 0;
6336: float: left;
1.913 droeschl 6337: }
1.933 droeschl 6338: .LC_breadcrumb_tools_tools {
6339: padding: 0;
6340: margin: 0;
1.913 droeschl 6341: float: right;
6342: }
6343:
1.359 albertel 6344: table#LC_title_bar td {
6345: background: $tabbg;
6346: }
1.795 www 6347:
1.911 bisitz 6348: table#LC_menubuttons img {
1.803 bisitz 6349: border: none;
1.346 albertel 6350: }
1.795 www 6351:
1.842 droeschl 6352: .LC_breadcrumbs_component {
1.911 bisitz 6353: float: right;
6354: margin: 0 1em;
1.357 albertel 6355: }
1.842 droeschl 6356: .LC_breadcrumbs_component img {
1.911 bisitz 6357: vertical-align: middle;
1.777 tempelho 6358: }
1.795 www 6359:
1.1075.2.108 raeburn 6360: .LC_breadcrumbs_hoverable {
6361: background: $sidebg;
6362: }
6363:
1.383 albertel 6364: td.LC_table_cell_checkbox {
6365: text-align: center;
6366: }
1.795 www 6367:
6368: .LC_fontsize_small {
1.911 bisitz 6369: font-size: 70%;
1.705 tempelho 6370: }
6371:
1.844 bisitz 6372: #LC_breadcrumbs {
1.911 bisitz 6373: clear:both;
6374: background: $sidebg;
6375: border-bottom: 1px solid $lg_border_color;
6376: line-height: 2.5em;
1.933 droeschl 6377: overflow: hidden;
1.911 bisitz 6378: margin: 0;
6379: padding: 0;
1.995 raeburn 6380: text-align: left;
1.819 tempelho 6381: }
1.862 bisitz 6382:
1.1075.2.16 raeburn 6383: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6384: clear:both;
6385: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6386: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6387: margin: 0 0 10px 0;
1.966 bisitz 6388: padding: 3px;
1.995 raeburn 6389: text-align: left;
1.822 bisitz 6390: }
6391:
1.795 www 6392: .LC_fontsize_medium {
1.911 bisitz 6393: font-size: 85%;
1.705 tempelho 6394: }
6395:
1.795 www 6396: .LC_fontsize_large {
1.911 bisitz 6397: font-size: 120%;
1.705 tempelho 6398: }
6399:
1.346 albertel 6400: .LC_menubuttons_inline_text {
6401: color: $font;
1.698 harmsja 6402: font-size: 90%;
1.701 harmsja 6403: padding-left:3px;
1.346 albertel 6404: }
6405:
1.934 droeschl 6406: .LC_menubuttons_inline_text img{
6407: vertical-align: middle;
6408: }
6409:
1.1051 www 6410: li.LC_menubuttons_inline_text img {
1.951 onken 6411: cursor:pointer;
1.1002 droeschl 6412: text-decoration: none;
1.951 onken 6413: }
6414:
1.526 www 6415: .LC_menubuttons_link {
6416: text-decoration: none;
6417: }
1.795 www 6418:
1.522 albertel 6419: .LC_menubuttons_category {
1.521 www 6420: color: $font;
1.526 www 6421: background: $pgbg;
1.521 www 6422: font-size: larger;
6423: font-weight: bold;
6424: }
6425:
1.346 albertel 6426: td.LC_menubuttons_text {
1.911 bisitz 6427: color: $font;
1.346 albertel 6428: }
1.706 harmsja 6429:
1.346 albertel 6430: .LC_current_location {
6431: background: $tabbg;
6432: }
1.795 www 6433:
1.1075.2.134 raeburn 6434: td.LC_zero_height {
6435: line-height: 0;
6436: cellpadding: 0;
6437: }
6438:
1.938 bisitz 6439: table.LC_data_table {
1.347 albertel 6440: border: 1px solid #000000;
1.402 albertel 6441: border-collapse: separate;
1.426 albertel 6442: border-spacing: 1px;
1.610 albertel 6443: background: $pgbg;
1.347 albertel 6444: }
1.795 www 6445:
1.422 albertel 6446: .LC_data_table_dense {
6447: font-size: small;
6448: }
1.795 www 6449:
1.507 raeburn 6450: table.LC_nested_outer {
6451: border: 1px solid #000000;
1.589 raeburn 6452: border-collapse: collapse;
1.803 bisitz 6453: border-spacing: 0;
1.507 raeburn 6454: width: 100%;
6455: }
1.795 www 6456:
1.879 raeburn 6457: table.LC_innerpickbox,
1.507 raeburn 6458: table.LC_nested {
1.803 bisitz 6459: border: none;
1.589 raeburn 6460: border-collapse: collapse;
1.803 bisitz 6461: border-spacing: 0;
1.507 raeburn 6462: width: 100%;
6463: }
1.795 www 6464:
1.911 bisitz 6465: table.LC_data_table tr th,
6466: table.LC_calendar tr th,
1.879 raeburn 6467: table.LC_prior_tries tr th,
6468: table.LC_innerpickbox tr th {
1.349 albertel 6469: font-weight: bold;
6470: background-color: $data_table_head;
1.801 tempelho 6471: color:$fontmenu;
1.701 harmsja 6472: font-size:90%;
1.347 albertel 6473: }
1.795 www 6474:
1.879 raeburn 6475: table.LC_innerpickbox tr th,
6476: table.LC_innerpickbox tr td {
6477: vertical-align: top;
6478: }
6479:
1.711 raeburn 6480: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6481: background-color: #CCCCCC;
1.711 raeburn 6482: font-weight: bold;
6483: text-align: left;
6484: }
1.795 www 6485:
1.912 bisitz 6486: table.LC_data_table tr.LC_odd_row > td {
6487: background-color: $data_table_light;
6488: padding: 2px;
6489: vertical-align: top;
6490: }
6491:
1.809 bisitz 6492: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6493: background-color: $data_table_light;
1.912 bisitz 6494: vertical-align: top;
6495: }
6496:
6497: table.LC_data_table tr.LC_even_row > td {
6498: background-color: $data_table_dark;
1.425 albertel 6499: padding: 2px;
1.900 bisitz 6500: vertical-align: top;
1.347 albertel 6501: }
1.795 www 6502:
1.809 bisitz 6503: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6504: background-color: $data_table_dark;
1.900 bisitz 6505: vertical-align: top;
1.347 albertel 6506: }
1.795 www 6507:
1.425 albertel 6508: table.LC_data_table tr.LC_data_table_highlight td {
6509: background-color: $data_table_darker;
6510: }
1.795 www 6511:
1.639 raeburn 6512: table.LC_data_table tr td.LC_leftcol_header {
6513: background-color: $data_table_head;
6514: font-weight: bold;
6515: }
1.795 www 6516:
1.451 albertel 6517: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6518: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6519: font-weight: bold;
6520: font-style: italic;
6521: text-align: center;
6522: padding: 8px;
1.347 albertel 6523: }
1.795 www 6524:
1.1075.2.30 raeburn 6525: table.LC_data_table tr.LC_empty_row td,
6526: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6527: background-color: $sidebg;
6528: }
6529:
6530: table.LC_nested tr.LC_empty_row td {
6531: background-color: #FFFFFF;
6532: }
6533:
1.890 droeschl 6534: table.LC_caption {
6535: }
6536:
1.507 raeburn 6537: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6538: padding: 4ex
6539: }
1.795 www 6540:
1.507 raeburn 6541: table.LC_nested_outer tr th {
6542: font-weight: bold;
1.801 tempelho 6543: color:$fontmenu;
1.507 raeburn 6544: background-color: $data_table_head;
1.701 harmsja 6545: font-size: small;
1.507 raeburn 6546: border-bottom: 1px solid #000000;
6547: }
1.795 www 6548:
1.507 raeburn 6549: table.LC_nested_outer tr td.LC_subheader {
6550: background-color: $data_table_head;
6551: font-weight: bold;
6552: font-size: small;
6553: border-bottom: 1px solid #000000;
6554: text-align: right;
1.451 albertel 6555: }
1.795 www 6556:
1.507 raeburn 6557: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6558: background-color: #CCCCCC;
1.451 albertel 6559: font-weight: bold;
6560: font-size: small;
1.507 raeburn 6561: text-align: center;
6562: }
1.795 www 6563:
1.589 raeburn 6564: table.LC_nested tr.LC_info_row td.LC_left_item,
6565: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6566: text-align: left;
1.451 albertel 6567: }
1.795 www 6568:
1.507 raeburn 6569: table.LC_nested td {
1.735 bisitz 6570: background-color: #FFFFFF;
1.451 albertel 6571: font-size: small;
1.507 raeburn 6572: }
1.795 www 6573:
1.507 raeburn 6574: table.LC_nested_outer tr th.LC_right_item,
6575: table.LC_nested tr.LC_info_row td.LC_right_item,
6576: table.LC_nested tr.LC_odd_row td.LC_right_item,
6577: table.LC_nested tr td.LC_right_item {
1.451 albertel 6578: text-align: right;
6579: }
6580:
1.507 raeburn 6581: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6582: background-color: #EEEEEE;
1.451 albertel 6583: }
6584:
1.473 raeburn 6585: table.LC_createuser {
6586: }
6587:
6588: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6589: font-size: small;
1.473 raeburn 6590: }
6591:
6592: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6593: background-color: #CCCCCC;
1.473 raeburn 6594: font-weight: bold;
6595: text-align: center;
6596: }
6597:
1.349 albertel 6598: table.LC_calendar {
6599: border: 1px solid #000000;
6600: border-collapse: collapse;
1.917 raeburn 6601: width: 98%;
1.349 albertel 6602: }
1.795 www 6603:
1.349 albertel 6604: table.LC_calendar_pickdate {
6605: font-size: xx-small;
6606: }
1.795 www 6607:
1.349 albertel 6608: table.LC_calendar tr td {
6609: border: 1px solid #000000;
6610: vertical-align: top;
1.917 raeburn 6611: width: 14%;
1.349 albertel 6612: }
1.795 www 6613:
1.349 albertel 6614: table.LC_calendar tr td.LC_calendar_day_empty {
6615: background-color: $data_table_dark;
6616: }
1.795 www 6617:
1.779 bisitz 6618: table.LC_calendar tr td.LC_calendar_day_current {
6619: background-color: $data_table_highlight;
1.777 tempelho 6620: }
1.795 www 6621:
1.938 bisitz 6622: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6623: background-color: $mail_new;
6624: }
1.795 www 6625:
1.938 bisitz 6626: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6627: background-color: $mail_new_hover;
6628: }
1.795 www 6629:
1.938 bisitz 6630: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6631: background-color: $mail_read;
6632: }
1.795 www 6633:
1.938 bisitz 6634: /*
6635: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6636: background-color: $mail_read_hover;
6637: }
1.938 bisitz 6638: */
1.795 www 6639:
1.938 bisitz 6640: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6641: background-color: $mail_replied;
6642: }
1.795 www 6643:
1.938 bisitz 6644: /*
6645: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6646: background-color: $mail_replied_hover;
6647: }
1.938 bisitz 6648: */
1.795 www 6649:
1.938 bisitz 6650: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6651: background-color: $mail_other;
6652: }
1.795 www 6653:
1.938 bisitz 6654: /*
6655: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6656: background-color: $mail_other_hover;
6657: }
1.938 bisitz 6658: */
1.494 raeburn 6659:
1.777 tempelho 6660: table.LC_data_table tr > td.LC_browser_file,
6661: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6662: background: #AAEE77;
1.389 albertel 6663: }
1.795 www 6664:
1.777 tempelho 6665: table.LC_data_table tr > td.LC_browser_file_locked,
6666: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6667: background: #FFAA99;
1.387 albertel 6668: }
1.795 www 6669:
1.777 tempelho 6670: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6671: background: #888888;
1.779 bisitz 6672: }
1.795 www 6673:
1.777 tempelho 6674: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6675: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6676: background: #F8F866;
1.777 tempelho 6677: }
1.795 www 6678:
1.696 bisitz 6679: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6680: background: #E0E8FF;
1.387 albertel 6681: }
1.696 bisitz 6682:
1.707 bisitz 6683: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6684: /* background: #77FF77; */
1.707 bisitz 6685: }
1.795 www 6686:
1.707 bisitz 6687: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6688: border-right: 8px solid #FFFF77;
1.707 bisitz 6689: }
1.795 www 6690:
1.707 bisitz 6691: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6692: border-right: 8px solid #FFAA77;
1.707 bisitz 6693: }
1.795 www 6694:
1.707 bisitz 6695: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6696: border-right: 8px solid #FF7777;
1.707 bisitz 6697: }
1.795 www 6698:
1.707 bisitz 6699: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6700: border-right: 8px solid #AAFF77;
1.707 bisitz 6701: }
1.795 www 6702:
1.707 bisitz 6703: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6704: border-right: 8px solid #11CC55;
1.707 bisitz 6705: }
6706:
1.388 albertel 6707: span.LC_current_location {
1.701 harmsja 6708: font-size:larger;
1.388 albertel 6709: background: $pgbg;
6710: }
1.387 albertel 6711:
1.1029 www 6712: span.LC_current_nav_location {
6713: font-weight:bold;
6714: background: $sidebg;
6715: }
6716:
1.395 albertel 6717: span.LC_parm_menu_item {
6718: font-size: larger;
6719: }
1.795 www 6720:
1.395 albertel 6721: span.LC_parm_scope_all {
6722: color: red;
6723: }
1.795 www 6724:
1.395 albertel 6725: span.LC_parm_scope_folder {
6726: color: green;
6727: }
1.795 www 6728:
1.395 albertel 6729: span.LC_parm_scope_resource {
6730: color: orange;
6731: }
1.795 www 6732:
1.395 albertel 6733: span.LC_parm_part {
6734: color: blue;
6735: }
1.795 www 6736:
1.911 bisitz 6737: span.LC_parm_folder,
6738: span.LC_parm_symb {
1.395 albertel 6739: font-size: x-small;
6740: font-family: $mono;
6741: color: #AAAAAA;
6742: }
6743:
1.977 bisitz 6744: ul.LC_parm_parmlist li {
6745: display: inline-block;
6746: padding: 0.3em 0.8em;
6747: vertical-align: top;
6748: width: 150px;
6749: border-top:1px solid $lg_border_color;
6750: }
6751:
1.795 www 6752: td.LC_parm_overview_level_menu,
6753: td.LC_parm_overview_map_menu,
6754: td.LC_parm_overview_parm_selectors,
6755: td.LC_parm_overview_restrictions {
1.396 albertel 6756: border: 1px solid black;
6757: border-collapse: collapse;
6758: }
1.795 www 6759:
1.396 albertel 6760: table.LC_parm_overview_restrictions td {
6761: border-width: 1px 4px 1px 4px;
6762: border-style: solid;
6763: border-color: $pgbg;
6764: text-align: center;
6765: }
1.795 www 6766:
1.396 albertel 6767: table.LC_parm_overview_restrictions th {
6768: background: $tabbg;
6769: border-width: 1px 4px 1px 4px;
6770: border-style: solid;
6771: border-color: $pgbg;
6772: }
1.795 www 6773:
1.398 albertel 6774: table#LC_helpmenu {
1.803 bisitz 6775: border: none;
1.398 albertel 6776: height: 55px;
1.803 bisitz 6777: border-spacing: 0;
1.398 albertel 6778: }
6779:
6780: table#LC_helpmenu fieldset legend {
6781: font-size: larger;
6782: }
1.795 www 6783:
1.397 albertel 6784: table#LC_helpmenu_links {
6785: width: 100%;
6786: border: 1px solid black;
6787: background: $pgbg;
1.803 bisitz 6788: padding: 0;
1.397 albertel 6789: border-spacing: 1px;
6790: }
1.795 www 6791:
1.397 albertel 6792: table#LC_helpmenu_links tr td {
6793: padding: 1px;
6794: background: $tabbg;
1.399 albertel 6795: text-align: center;
6796: font-weight: bold;
1.397 albertel 6797: }
1.396 albertel 6798:
1.795 www 6799: table#LC_helpmenu_links a:link,
6800: table#LC_helpmenu_links a:visited,
1.397 albertel 6801: table#LC_helpmenu_links a:active {
6802: text-decoration: none;
6803: color: $font;
6804: }
1.795 www 6805:
1.397 albertel 6806: table#LC_helpmenu_links a:hover {
6807: text-decoration: underline;
6808: color: $vlink;
6809: }
1.396 albertel 6810:
1.417 albertel 6811: .LC_chrt_popup_exists {
6812: border: 1px solid #339933;
6813: margin: -1px;
6814: }
1.795 www 6815:
1.417 albertel 6816: .LC_chrt_popup_up {
6817: border: 1px solid yellow;
6818: margin: -1px;
6819: }
1.795 www 6820:
1.417 albertel 6821: .LC_chrt_popup {
6822: border: 1px solid #8888FF;
6823: background: #CCCCFF;
6824: }
1.795 www 6825:
1.421 albertel 6826: table.LC_pick_box {
6827: border-collapse: separate;
6828: background: white;
6829: border: 1px solid black;
6830: border-spacing: 1px;
6831: }
1.795 www 6832:
1.421 albertel 6833: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6834: background: $sidebg;
1.421 albertel 6835: font-weight: bold;
1.900 bisitz 6836: text-align: left;
1.740 bisitz 6837: vertical-align: top;
1.421 albertel 6838: width: 184px;
6839: padding: 8px;
6840: }
1.795 www 6841:
1.579 raeburn 6842: table.LC_pick_box td.LC_pick_box_value {
6843: text-align: left;
6844: padding: 8px;
6845: }
1.795 www 6846:
1.579 raeburn 6847: table.LC_pick_box td.LC_pick_box_select {
6848: text-align: left;
6849: padding: 8px;
6850: }
1.795 www 6851:
1.424 albertel 6852: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6853: padding: 0;
1.421 albertel 6854: height: 1px;
6855: background: black;
6856: }
1.795 www 6857:
1.421 albertel 6858: table.LC_pick_box td.LC_pick_box_submit {
6859: text-align: right;
6860: }
1.795 www 6861:
1.579 raeburn 6862: table.LC_pick_box td.LC_evenrow_value {
6863: text-align: left;
6864: padding: 8px;
6865: background-color: $data_table_light;
6866: }
1.795 www 6867:
1.579 raeburn 6868: table.LC_pick_box td.LC_oddrow_value {
6869: text-align: left;
6870: padding: 8px;
6871: background-color: $data_table_light;
6872: }
1.795 www 6873:
1.579 raeburn 6874: span.LC_helpform_receipt_cat {
6875: font-weight: bold;
6876: }
1.795 www 6877:
1.424 albertel 6878: table.LC_group_priv_box {
6879: background: white;
6880: border: 1px solid black;
6881: border-spacing: 1px;
6882: }
1.795 www 6883:
1.424 albertel 6884: table.LC_group_priv_box td.LC_pick_box_title {
6885: background: $tabbg;
6886: font-weight: bold;
6887: text-align: right;
6888: width: 184px;
6889: }
1.795 www 6890:
1.424 albertel 6891: table.LC_group_priv_box td.LC_groups_fixed {
6892: background: $data_table_light;
6893: text-align: center;
6894: }
1.795 www 6895:
1.424 albertel 6896: table.LC_group_priv_box td.LC_groups_optional {
6897: background: $data_table_dark;
6898: text-align: center;
6899: }
1.795 www 6900:
1.424 albertel 6901: table.LC_group_priv_box td.LC_groups_functionality {
6902: background: $data_table_darker;
6903: text-align: center;
6904: font-weight: bold;
6905: }
1.795 www 6906:
1.424 albertel 6907: table.LC_group_priv td {
6908: text-align: left;
1.803 bisitz 6909: padding: 0;
1.424 albertel 6910: }
6911:
6912: .LC_navbuttons {
6913: margin: 2ex 0ex 2ex 0ex;
6914: }
1.795 www 6915:
1.423 albertel 6916: .LC_topic_bar {
6917: font-weight: bold;
6918: background: $tabbg;
1.918 wenzelju 6919: margin: 1em 0em 1em 2em;
1.805 bisitz 6920: padding: 3px;
1.918 wenzelju 6921: font-size: 1.2em;
1.423 albertel 6922: }
1.795 www 6923:
1.423 albertel 6924: .LC_topic_bar span {
1.918 wenzelju 6925: left: 0.5em;
6926: position: absolute;
1.423 albertel 6927: vertical-align: middle;
1.918 wenzelju 6928: font-size: 1.2em;
1.423 albertel 6929: }
1.795 www 6930:
1.423 albertel 6931: table.LC_course_group_status {
6932: margin: 20px;
6933: }
1.795 www 6934:
1.423 albertel 6935: table.LC_status_selector td {
6936: vertical-align: top;
6937: text-align: center;
1.424 albertel 6938: padding: 4px;
6939: }
1.795 www 6940:
1.599 albertel 6941: div.LC_feedback_link {
1.616 albertel 6942: clear: both;
1.829 kalberla 6943: background: $sidebg;
1.779 bisitz 6944: width: 100%;
1.829 kalberla 6945: padding-bottom: 10px;
6946: border: 1px $tabbg solid;
1.833 kalberla 6947: height: 22px;
6948: line-height: 22px;
6949: padding-top: 5px;
6950: }
6951:
6952: div.LC_feedback_link img {
6953: height: 22px;
1.867 kalberla 6954: vertical-align:middle;
1.829 kalberla 6955: }
6956:
1.911 bisitz 6957: div.LC_feedback_link a {
1.829 kalberla 6958: text-decoration: none;
1.489 raeburn 6959: }
1.795 www 6960:
1.867 kalberla 6961: div.LC_comblock {
1.911 bisitz 6962: display:inline;
1.867 kalberla 6963: color:$font;
6964: font-size:90%;
6965: }
6966:
6967: div.LC_feedback_link div.LC_comblock {
6968: padding-left:5px;
6969: }
6970:
6971: div.LC_feedback_link div.LC_comblock a {
6972: color:$font;
6973: }
6974:
1.489 raeburn 6975: span.LC_feedback_link {
1.858 bisitz 6976: /* background: $feedback_link_bg; */
1.599 albertel 6977: font-size: larger;
6978: }
1.795 www 6979:
1.599 albertel 6980: span.LC_message_link {
1.858 bisitz 6981: /* background: $feedback_link_bg; */
1.599 albertel 6982: font-size: larger;
6983: position: absolute;
6984: right: 1em;
1.489 raeburn 6985: }
1.421 albertel 6986:
1.515 albertel 6987: table.LC_prior_tries {
1.524 albertel 6988: border: 1px solid #000000;
6989: border-collapse: separate;
6990: border-spacing: 1px;
1.515 albertel 6991: }
1.523 albertel 6992:
1.515 albertel 6993: table.LC_prior_tries td {
1.524 albertel 6994: padding: 2px;
1.515 albertel 6995: }
1.523 albertel 6996:
6997: .LC_answer_correct {
1.795 www 6998: background: lightgreen;
6999: color: darkgreen;
7000: padding: 6px;
1.523 albertel 7001: }
1.795 www 7002:
1.523 albertel 7003: .LC_answer_charged_try {
1.797 www 7004: background: #FFAAAA;
1.795 www 7005: color: darkred;
7006: padding: 6px;
1.523 albertel 7007: }
1.795 www 7008:
1.779 bisitz 7009: .LC_answer_not_charged_try,
1.523 albertel 7010: .LC_answer_no_grade,
7011: .LC_answer_late {
1.795 www 7012: background: lightyellow;
1.523 albertel 7013: color: black;
1.795 www 7014: padding: 6px;
1.523 albertel 7015: }
1.795 www 7016:
1.523 albertel 7017: .LC_answer_previous {
1.795 www 7018: background: lightblue;
7019: color: darkblue;
7020: padding: 6px;
1.523 albertel 7021: }
1.795 www 7022:
1.779 bisitz 7023: .LC_answer_no_message {
1.777 tempelho 7024: background: #FFFFFF;
7025: color: black;
1.795 www 7026: padding: 6px;
1.779 bisitz 7027: }
1.795 www 7028:
1.1075.2.140 raeburn 7029: .LC_answer_unknown,
7030: .LC_answer_warning {
1.779 bisitz 7031: background: orange;
7032: color: black;
1.795 www 7033: padding: 6px;
1.777 tempelho 7034: }
1.795 www 7035:
1.529 albertel 7036: span.LC_prior_numerical,
7037: span.LC_prior_string,
7038: span.LC_prior_custom,
7039: span.LC_prior_reaction,
7040: span.LC_prior_math {
1.925 bisitz 7041: font-family: $mono;
1.523 albertel 7042: white-space: pre;
7043: }
7044:
1.525 albertel 7045: span.LC_prior_string {
1.925 bisitz 7046: font-family: $mono;
1.525 albertel 7047: white-space: pre;
7048: }
7049:
1.523 albertel 7050: table.LC_prior_option {
7051: width: 100%;
7052: border-collapse: collapse;
7053: }
1.795 www 7054:
1.911 bisitz 7055: table.LC_prior_rank,
1.795 www 7056: table.LC_prior_match {
1.528 albertel 7057: border-collapse: collapse;
7058: }
1.795 www 7059:
1.528 albertel 7060: table.LC_prior_option tr td,
7061: table.LC_prior_rank tr td,
7062: table.LC_prior_match tr td {
1.524 albertel 7063: border: 1px solid #000000;
1.515 albertel 7064: }
7065:
1.855 bisitz 7066: .LC_nobreak {
1.544 albertel 7067: white-space: nowrap;
1.519 raeburn 7068: }
7069:
1.576 raeburn 7070: span.LC_cusr_emph {
7071: font-style: italic;
7072: }
7073:
1.633 raeburn 7074: span.LC_cusr_subheading {
7075: font-weight: normal;
7076: font-size: 85%;
7077: }
7078:
1.861 bisitz 7079: div.LC_docs_entry_move {
1.859 bisitz 7080: border: 1px solid #BBBBBB;
1.545 albertel 7081: background: #DDDDDD;
1.861 bisitz 7082: width: 22px;
1.859 bisitz 7083: padding: 1px;
7084: margin: 0;
1.545 albertel 7085: }
7086:
1.861 bisitz 7087: table.LC_data_table tr > td.LC_docs_entry_commands,
7088: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7089: font-size: x-small;
7090: }
1.795 www 7091:
1.861 bisitz 7092: .LC_docs_entry_parameter {
7093: white-space: nowrap;
7094: }
7095:
1.544 albertel 7096: .LC_docs_copy {
1.545 albertel 7097: color: #000099;
1.544 albertel 7098: }
1.795 www 7099:
1.544 albertel 7100: .LC_docs_cut {
1.545 albertel 7101: color: #550044;
1.544 albertel 7102: }
1.795 www 7103:
1.544 albertel 7104: .LC_docs_rename {
1.545 albertel 7105: color: #009900;
1.544 albertel 7106: }
1.795 www 7107:
1.544 albertel 7108: .LC_docs_remove {
1.545 albertel 7109: color: #990000;
7110: }
7111:
1.1075.2.134 raeburn 7112: .LC_domprefs_email,
1.547 albertel 7113: .LC_docs_reinit_warn,
7114: .LC_docs_ext_edit {
7115: font-size: x-small;
7116: }
7117:
1.545 albertel 7118: table.LC_docs_adddocs td,
7119: table.LC_docs_adddocs th {
7120: border: 1px solid #BBBBBB;
7121: padding: 4px;
7122: background: #DDDDDD;
1.543 albertel 7123: }
7124:
1.584 albertel 7125: table.LC_sty_begin {
7126: background: #BBFFBB;
7127: }
1.795 www 7128:
1.584 albertel 7129: table.LC_sty_end {
7130: background: #FFBBBB;
7131: }
7132:
1.589 raeburn 7133: table.LC_double_column {
1.803 bisitz 7134: border-width: 0;
1.589 raeburn 7135: border-collapse: collapse;
7136: width: 100%;
7137: padding: 2px;
7138: }
7139:
7140: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7141: top: 2px;
1.589 raeburn 7142: left: 2px;
7143: width: 47%;
7144: vertical-align: top;
7145: }
7146:
7147: table.LC_double_column tr td.LC_right_col {
7148: top: 2px;
1.779 bisitz 7149: right: 2px;
1.589 raeburn 7150: width: 47%;
7151: vertical-align: top;
7152: }
7153:
1.591 raeburn 7154: div.LC_left_float {
7155: float: left;
7156: padding-right: 5%;
1.597 albertel 7157: padding-bottom: 4px;
1.591 raeburn 7158: }
7159:
7160: div.LC_clear_float_header {
1.597 albertel 7161: padding-bottom: 2px;
1.591 raeburn 7162: }
7163:
7164: div.LC_clear_float_footer {
1.597 albertel 7165: padding-top: 10px;
1.591 raeburn 7166: clear: both;
7167: }
7168:
1.597 albertel 7169: div.LC_grade_show_user {
1.941 bisitz 7170: /* border-left: 5px solid $sidebg; */
7171: border-top: 5px solid #000000;
7172: margin: 50px 0 0 0;
1.936 bisitz 7173: padding: 15px 0 5px 10px;
1.597 albertel 7174: }
1.795 www 7175:
1.936 bisitz 7176: div.LC_grade_show_user_odd_row {
1.941 bisitz 7177: /* border-left: 5px solid #000000; */
7178: }
7179:
7180: div.LC_grade_show_user div.LC_Box {
7181: margin-right: 50px;
1.597 albertel 7182: }
7183:
7184: div.LC_grade_submissions,
7185: div.LC_grade_message_center,
1.936 bisitz 7186: div.LC_grade_info_links {
1.597 albertel 7187: margin: 5px;
7188: width: 99%;
7189: background: #FFFFFF;
7190: }
1.795 www 7191:
1.597 albertel 7192: div.LC_grade_submissions_header,
1.936 bisitz 7193: div.LC_grade_message_center_header {
1.705 tempelho 7194: font-weight: bold;
7195: font-size: large;
1.597 albertel 7196: }
1.795 www 7197:
1.597 albertel 7198: div.LC_grade_submissions_body,
1.936 bisitz 7199: div.LC_grade_message_center_body {
1.597 albertel 7200: border: 1px solid black;
7201: width: 99%;
7202: background: #FFFFFF;
7203: }
1.795 www 7204:
1.613 albertel 7205: table.LC_scantron_action {
7206: width: 100%;
7207: }
1.795 www 7208:
1.613 albertel 7209: table.LC_scantron_action tr th {
1.698 harmsja 7210: font-weight:bold;
7211: font-style:normal;
1.613 albertel 7212: }
1.795 www 7213:
1.779 bisitz 7214: .LC_edit_problem_header,
1.614 albertel 7215: div.LC_edit_problem_footer {
1.705 tempelho 7216: font-weight: normal;
7217: font-size: medium;
1.602 albertel 7218: margin: 2px;
1.1060 bisitz 7219: background-color: $sidebg;
1.600 albertel 7220: }
1.795 www 7221:
1.600 albertel 7222: div.LC_edit_problem_header,
1.602 albertel 7223: div.LC_edit_problem_header div,
1.614 albertel 7224: div.LC_edit_problem_footer,
7225: div.LC_edit_problem_footer div,
1.602 albertel 7226: div.LC_edit_problem_editxml_header,
7227: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7228: z-index: 100;
1.600 albertel 7229: }
1.795 www 7230:
1.600 albertel 7231: div.LC_edit_problem_header_title {
1.705 tempelho 7232: font-weight: bold;
7233: font-size: larger;
1.602 albertel 7234: background: $tabbg;
7235: padding: 3px;
1.1060 bisitz 7236: margin: 0 0 5px 0;
1.602 albertel 7237: }
1.795 www 7238:
1.602 albertel 7239: table.LC_edit_problem_header_title {
7240: width: 100%;
1.600 albertel 7241: background: $tabbg;
1.602 albertel 7242: }
7243:
1.1075.2.112 raeburn 7244: div.LC_edit_actionbar {
7245: background-color: $sidebg;
7246: margin: 0;
7247: padding: 0;
7248: line-height: 200%;
1.602 albertel 7249: }
1.795 www 7250:
1.1075.2.112 raeburn 7251: div.LC_edit_actionbar div{
7252: padding: 0;
7253: margin: 0;
7254: display: inline-block;
1.600 albertel 7255: }
1.795 www 7256:
1.1075.2.34 raeburn 7257: .LC_edit_opt {
7258: padding-left: 1em;
7259: white-space: nowrap;
7260: }
7261:
1.1075.2.57 raeburn 7262: .LC_edit_problem_latexhelper{
7263: text-align: right;
7264: }
7265:
7266: #LC_edit_problem_colorful div{
7267: margin-left: 40px;
7268: }
7269:
1.1075.2.112 raeburn 7270: #LC_edit_problem_codemirror div{
7271: margin-left: 0px;
7272: }
7273:
1.911 bisitz 7274: img.stift {
1.803 bisitz 7275: border-width: 0;
7276: vertical-align: middle;
1.677 riegler 7277: }
1.680 riegler 7278:
1.923 bisitz 7279: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7280: vertical-align: top;
1.777 tempelho 7281: }
1.795 www 7282:
1.716 raeburn 7283: div.LC_createcourse {
1.911 bisitz 7284: margin: 10px 10px 10px 10px;
1.716 raeburn 7285: }
7286:
1.917 raeburn 7287: .LC_dccid {
1.1075.2.38 raeburn 7288: float: right;
1.917 raeburn 7289: margin: 0.2em 0 0 0;
7290: padding: 0;
7291: font-size: 90%;
7292: display:none;
7293: }
7294:
1.897 wenzelju 7295: ol.LC_primary_menu a:hover,
1.721 harmsja 7296: ol#LC_MenuBreadcrumbs a:hover,
7297: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7298: ul#LC_secondary_menu a:hover,
1.721 harmsja 7299: .LC_FormSectionClearButton input:hover
1.795 www 7300: ul.LC_TabContent li:hover a {
1.952 onken 7301: color:$button_hover;
1.911 bisitz 7302: text-decoration:none;
1.693 droeschl 7303: }
7304:
1.779 bisitz 7305: h1 {
1.911 bisitz 7306: padding: 0;
7307: line-height:130%;
1.693 droeschl 7308: }
1.698 harmsja 7309:
1.911 bisitz 7310: h2,
7311: h3,
7312: h4,
7313: h5,
7314: h6 {
7315: margin: 5px 0 5px 0;
7316: padding: 0;
7317: line-height:130%;
1.693 droeschl 7318: }
1.795 www 7319:
7320: .LC_hcell {
1.911 bisitz 7321: padding:3px 15px 3px 15px;
7322: margin: 0;
7323: background-color:$tabbg;
7324: color:$fontmenu;
7325: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7326: }
1.795 www 7327:
1.840 bisitz 7328: .LC_Box > .LC_hcell {
1.911 bisitz 7329: margin: 0 -10px 10px -10px;
1.835 bisitz 7330: }
7331:
1.721 harmsja 7332: .LC_noBorder {
1.911 bisitz 7333: border: 0;
1.698 harmsja 7334: }
1.693 droeschl 7335:
1.721 harmsja 7336: .LC_FormSectionClearButton input {
1.911 bisitz 7337: background-color:transparent;
7338: border: none;
7339: cursor:pointer;
7340: text-decoration:underline;
1.693 droeschl 7341: }
1.763 bisitz 7342:
7343: .LC_help_open_topic {
1.911 bisitz 7344: color: #FFFFFF;
7345: background-color: #EEEEFF;
7346: margin: 1px;
7347: padding: 4px;
7348: border: 1px solid #000033;
7349: white-space: nowrap;
7350: /* vertical-align: middle; */
1.759 neumanie 7351: }
1.693 droeschl 7352:
1.911 bisitz 7353: dl,
7354: ul,
7355: div,
7356: fieldset {
7357: margin: 10px 10px 10px 0;
7358: /* overflow: hidden; */
1.693 droeschl 7359: }
1.795 www 7360:
1.1075.2.90 raeburn 7361: article.geogebraweb div {
7362: margin: 0;
7363: }
7364:
1.838 bisitz 7365: fieldset > legend {
1.911 bisitz 7366: font-weight: bold;
7367: padding: 0 5px 0 5px;
1.838 bisitz 7368: }
7369:
1.813 bisitz 7370: #LC_nav_bar {
1.911 bisitz 7371: float: left;
1.995 raeburn 7372: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7373: margin: 0 0 2px 0;
1.807 droeschl 7374: }
7375:
1.916 droeschl 7376: #LC_realm {
7377: margin: 0.2em 0 0 0;
7378: padding: 0;
7379: font-weight: bold;
7380: text-align: center;
1.995 raeburn 7381: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7382: }
7383:
1.911 bisitz 7384: #LC_nav_bar em {
7385: font-weight: bold;
7386: font-style: normal;
1.807 droeschl 7387: }
7388:
1.897 wenzelju 7389: ol.LC_primary_menu {
1.934 droeschl 7390: margin: 0;
1.1075.2.2 raeburn 7391: padding: 0;
1.807 droeschl 7392: }
7393:
1.852 droeschl 7394: ol#LC_PathBreadcrumbs {
1.911 bisitz 7395: margin: 0;
1.693 droeschl 7396: }
7397:
1.897 wenzelju 7398: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7399: color: RGB(80, 80, 80);
7400: vertical-align: middle;
7401: text-align: left;
7402: list-style: none;
1.1075.2.112 raeburn 7403: position: relative;
1.1075.2.2 raeburn 7404: float: left;
1.1075.2.112 raeburn 7405: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7406: line-height: 1.5em;
1.1075.2.2 raeburn 7407: }
7408:
1.1075.2.113 raeburn 7409: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7410: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7411: display: block;
7412: margin: 0;
7413: padding: 0 5px 0 10px;
7414: text-decoration: none;
7415: }
7416:
1.1075.2.112 raeburn 7417: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7418: display: inline-block;
7419: width: 95%;
7420: text-align: left;
7421: }
7422:
7423: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7424: display: inline-block;
7425: width: 5%;
7426: float: right;
7427: text-align: right;
7428: font-size: 70%;
7429: }
7430:
7431: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7432: display: none;
1.1075.2.112 raeburn 7433: width: 15em;
1.1075.2.2 raeburn 7434: background-color: $data_table_light;
1.1075.2.112 raeburn 7435: position: absolute;
7436: top: 100%;
7437: }
7438:
7439: ol.LC_primary_menu ul ul {
7440: left: 100%;
7441: top: 0;
1.1075.2.2 raeburn 7442: }
7443:
1.1075.2.112 raeburn 7444: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7445: display: block;
7446: position: absolute;
7447: margin: 0;
7448: padding: 0;
1.1075.2.5 raeburn 7449: z-index: 2;
1.1075.2.2 raeburn 7450: }
7451:
7452: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7453: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7454: font-size: 90%;
1.911 bisitz 7455: vertical-align: top;
1.1075.2.2 raeburn 7456: float: none;
1.1075.2.5 raeburn 7457: border-left: 1px solid black;
7458: border-right: 1px solid black;
1.1075.2.112 raeburn 7459: /* A dark bottom border to visualize different menu options;
7460: overwritten in the create_submenu routine for the last border-bottom of the menu */
7461: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7462: }
7463:
1.1075.2.112 raeburn 7464: ol.LC_primary_menu li li p:hover {
7465: color:$button_hover;
7466: text-decoration:none;
7467: background-color:$data_table_dark;
1.1075.2.2 raeburn 7468: }
7469:
7470: ol.LC_primary_menu li li a:hover {
7471: color:$button_hover;
7472: background-color:$data_table_dark;
1.693 droeschl 7473: }
7474:
1.1075.2.112 raeburn 7475: /* Font-size equal to the size of the predecessors*/
7476: ol.LC_primary_menu li:hover li li {
7477: font-size: 100%;
7478: }
7479:
1.897 wenzelju 7480: ol.LC_primary_menu li img {
1.911 bisitz 7481: vertical-align: bottom;
1.934 droeschl 7482: height: 1.1em;
1.1075.2.3 raeburn 7483: margin: 0.2em 0 0 0;
1.693 droeschl 7484: }
7485:
1.897 wenzelju 7486: ol.LC_primary_menu a {
1.911 bisitz 7487: color: RGB(80, 80, 80);
7488: text-decoration: none;
1.693 droeschl 7489: }
1.795 www 7490:
1.949 droeschl 7491: ol.LC_primary_menu a.LC_new_message {
7492: font-weight:bold;
7493: color: darkred;
7494: }
7495:
1.975 raeburn 7496: ol.LC_docs_parameters {
7497: margin-left: 0;
7498: padding: 0;
7499: list-style: none;
7500: }
7501:
7502: ol.LC_docs_parameters li {
7503: margin: 0;
7504: padding-right: 20px;
7505: display: inline;
7506: }
7507:
1.976 raeburn 7508: ol.LC_docs_parameters li:before {
7509: content: "\\002022 \\0020";
7510: }
7511:
7512: li.LC_docs_parameters_title {
7513: font-weight: bold;
7514: }
7515:
7516: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7517: content: "";
7518: }
7519:
1.897 wenzelju 7520: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7521: clear: right;
1.911 bisitz 7522: color: $fontmenu;
7523: background: $tabbg;
7524: list-style: none;
7525: padding: 0;
7526: margin: 0;
7527: width: 100%;
1.995 raeburn 7528: text-align: left;
1.1075.2.4 raeburn 7529: float: left;
1.808 droeschl 7530: }
7531:
1.897 wenzelju 7532: ul#LC_secondary_menu li {
1.911 bisitz 7533: font-weight: bold;
7534: line-height: 1.8em;
7535: border-right: 1px solid black;
1.1075.2.4 raeburn 7536: float: left;
7537: }
7538:
7539: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7540: background-color: $data_table_light;
7541: }
7542:
7543: ul#LC_secondary_menu li a {
7544: padding: 0 0.8em;
7545: }
7546:
7547: ul#LC_secondary_menu li ul {
7548: display: none;
7549: }
7550:
7551: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7552: display: block;
7553: position: absolute;
7554: margin: 0;
7555: padding: 0;
7556: list-style:none;
7557: float: none;
7558: background-color: $data_table_light;
1.1075.2.5 raeburn 7559: z-index: 2;
1.1075.2.10 raeburn 7560: margin-left: -1px;
1.1075.2.4 raeburn 7561: }
7562:
7563: ul#LC_secondary_menu li ul li {
7564: font-size: 90%;
7565: vertical-align: top;
7566: border-left: 1px solid black;
7567: border-right: 1px solid black;
1.1075.2.33 raeburn 7568: background-color: $data_table_light;
1.1075.2.4 raeburn 7569: list-style:none;
7570: float: none;
7571: }
7572:
7573: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7574: background-color: $data_table_dark;
1.807 droeschl 7575: }
7576:
1.847 tempelho 7577: ul.LC_TabContent {
1.911 bisitz 7578: display:block;
7579: background: $sidebg;
7580: border-bottom: solid 1px $lg_border_color;
7581: list-style:none;
1.1020 raeburn 7582: margin: -1px -10px 0 -10px;
1.911 bisitz 7583: padding: 0;
1.693 droeschl 7584: }
7585:
1.795 www 7586: ul.LC_TabContent li,
7587: ul.LC_TabContentBigger li {
1.911 bisitz 7588: float:left;
1.741 harmsja 7589: }
1.795 www 7590:
1.897 wenzelju 7591: ul#LC_secondary_menu li a {
1.911 bisitz 7592: color: $fontmenu;
7593: text-decoration: none;
1.693 droeschl 7594: }
1.795 www 7595:
1.721 harmsja 7596: ul.LC_TabContent {
1.952 onken 7597: min-height:20px;
1.721 harmsja 7598: }
1.795 www 7599:
7600: ul.LC_TabContent li {
1.911 bisitz 7601: vertical-align:middle;
1.959 onken 7602: padding: 0 16px 0 10px;
1.911 bisitz 7603: background-color:$tabbg;
7604: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7605: border-left: solid 1px $font;
1.721 harmsja 7606: }
1.795 www 7607:
1.847 tempelho 7608: ul.LC_TabContent .right {
1.911 bisitz 7609: float:right;
1.847 tempelho 7610: }
7611:
1.911 bisitz 7612: ul.LC_TabContent li a,
7613: ul.LC_TabContent li {
7614: color:rgb(47,47,47);
7615: text-decoration:none;
7616: font-size:95%;
7617: font-weight:bold;
1.952 onken 7618: min-height:20px;
7619: }
7620:
1.959 onken 7621: ul.LC_TabContent li a:hover,
7622: ul.LC_TabContent li a:focus {
1.952 onken 7623: color: $button_hover;
1.959 onken 7624: background:none;
7625: outline:none;
1.952 onken 7626: }
7627:
7628: ul.LC_TabContent li:hover {
7629: color: $button_hover;
7630: cursor:pointer;
1.721 harmsja 7631: }
1.795 www 7632:
1.911 bisitz 7633: ul.LC_TabContent li.active {
1.952 onken 7634: color: $font;
1.911 bisitz 7635: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7636: border-bottom:solid 1px #FFFFFF;
7637: cursor: default;
1.744 ehlerst 7638: }
1.795 www 7639:
1.959 onken 7640: ul.LC_TabContent li.active a {
7641: color:$font;
7642: background:#FFFFFF;
7643: outline: none;
7644: }
1.1047 raeburn 7645:
7646: ul.LC_TabContent li.goback {
7647: float: left;
7648: border-left: none;
7649: }
7650:
1.870 tempelho 7651: #maincoursedoc {
1.911 bisitz 7652: clear:both;
1.870 tempelho 7653: }
7654:
7655: ul.LC_TabContentBigger {
1.911 bisitz 7656: display:block;
7657: list-style:none;
7658: padding: 0;
1.870 tempelho 7659: }
7660:
1.795 www 7661: ul.LC_TabContentBigger li {
1.911 bisitz 7662: vertical-align:bottom;
7663: height: 30px;
7664: font-size:110%;
7665: font-weight:bold;
7666: color: #737373;
1.841 tempelho 7667: }
7668:
1.957 onken 7669: ul.LC_TabContentBigger li.active {
7670: position: relative;
7671: top: 1px;
7672: }
7673:
1.870 tempelho 7674: ul.LC_TabContentBigger li a {
1.911 bisitz 7675: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7676: height: 30px;
7677: line-height: 30px;
7678: text-align: center;
7679: display: block;
7680: text-decoration: none;
1.958 onken 7681: outline: none;
1.741 harmsja 7682: }
1.795 www 7683:
1.870 tempelho 7684: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7685: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7686: color:$font;
1.744 ehlerst 7687: }
1.795 www 7688:
1.870 tempelho 7689: ul.LC_TabContentBigger li b {
1.911 bisitz 7690: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7691: display: block;
7692: float: left;
7693: padding: 0 30px;
1.957 onken 7694: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7695: }
7696:
1.956 onken 7697: ul.LC_TabContentBigger li:hover b {
7698: color:$button_hover;
7699: }
7700:
1.870 tempelho 7701: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7702: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7703: color:$font;
1.957 onken 7704: border: 0;
1.741 harmsja 7705: }
1.693 droeschl 7706:
1.870 tempelho 7707:
1.862 bisitz 7708: ul.LC_CourseBreadcrumbs {
7709: background: $sidebg;
1.1020 raeburn 7710: height: 2em;
1.862 bisitz 7711: padding-left: 10px;
1.1020 raeburn 7712: margin: 0;
1.862 bisitz 7713: list-style-position: inside;
7714: }
7715:
1.911 bisitz 7716: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7717: ol#LC_PathBreadcrumbs {
1.911 bisitz 7718: padding-left: 10px;
7719: margin: 0;
1.933 droeschl 7720: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7721: }
7722:
1.911 bisitz 7723: ol#LC_MenuBreadcrumbs li,
7724: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7725: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7726: display: inline;
1.933 droeschl 7727: white-space: normal;
1.693 droeschl 7728: }
7729:
1.823 bisitz 7730: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7731: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7732: text-decoration: none;
7733: font-size:90%;
1.693 droeschl 7734: }
1.795 www 7735:
1.969 droeschl 7736: ol#LC_MenuBreadcrumbs h1 {
7737: display: inline;
7738: font-size: 90%;
7739: line-height: 2.5em;
7740: margin: 0;
7741: padding: 0;
7742: }
7743:
1.795 www 7744: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7745: text-decoration:none;
7746: font-size:100%;
7747: font-weight:bold;
1.693 droeschl 7748: }
1.795 www 7749:
1.840 bisitz 7750: .LC_Box {
1.911 bisitz 7751: border: solid 1px $lg_border_color;
7752: padding: 0 10px 10px 10px;
1.746 neumanie 7753: }
1.795 www 7754:
1.1020 raeburn 7755: .LC_DocsBox {
7756: border: solid 1px $lg_border_color;
7757: padding: 0 0 10px 10px;
7758: }
7759:
1.795 www 7760: .LC_AboutMe_Image {
1.911 bisitz 7761: float:left;
7762: margin-right:10px;
1.747 neumanie 7763: }
1.795 www 7764:
7765: .LC_Clear_AboutMe_Image {
1.911 bisitz 7766: clear:left;
1.747 neumanie 7767: }
1.795 www 7768:
1.721 harmsja 7769: dl.LC_ListStyleClean dt {
1.911 bisitz 7770: padding-right: 5px;
7771: display: table-header-group;
1.693 droeschl 7772: }
7773:
1.721 harmsja 7774: dl.LC_ListStyleClean dd {
1.911 bisitz 7775: display: table-row;
1.693 droeschl 7776: }
7777:
1.721 harmsja 7778: .LC_ListStyleClean,
7779: .LC_ListStyleSimple,
7780: .LC_ListStyleNormal,
1.795 www 7781: .LC_ListStyleSpecial {
1.911 bisitz 7782: /* display:block; */
7783: list-style-position: inside;
7784: list-style-type: none;
7785: overflow: hidden;
7786: padding: 0;
1.693 droeschl 7787: }
7788:
1.721 harmsja 7789: .LC_ListStyleSimple li,
7790: .LC_ListStyleSimple dd,
7791: .LC_ListStyleNormal li,
7792: .LC_ListStyleNormal dd,
7793: .LC_ListStyleSpecial li,
1.795 www 7794: .LC_ListStyleSpecial dd {
1.911 bisitz 7795: margin: 0;
7796: padding: 5px 5px 5px 10px;
7797: clear: both;
1.693 droeschl 7798: }
7799:
1.721 harmsja 7800: .LC_ListStyleClean li,
7801: .LC_ListStyleClean dd {
1.911 bisitz 7802: padding-top: 0;
7803: padding-bottom: 0;
1.693 droeschl 7804: }
7805:
1.721 harmsja 7806: .LC_ListStyleSimple dd,
1.795 www 7807: .LC_ListStyleSimple li {
1.911 bisitz 7808: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7809: }
7810:
1.721 harmsja 7811: .LC_ListStyleSpecial li,
7812: .LC_ListStyleSpecial dd {
1.911 bisitz 7813: list-style-type: none;
7814: background-color: RGB(220, 220, 220);
7815: margin-bottom: 4px;
1.693 droeschl 7816: }
7817:
1.721 harmsja 7818: table.LC_SimpleTable {
1.911 bisitz 7819: margin:5px;
7820: border:solid 1px $lg_border_color;
1.795 www 7821: }
1.693 droeschl 7822:
1.721 harmsja 7823: table.LC_SimpleTable tr {
1.911 bisitz 7824: padding: 0;
7825: border:solid 1px $lg_border_color;
1.693 droeschl 7826: }
1.795 www 7827:
7828: table.LC_SimpleTable thead {
1.911 bisitz 7829: background:rgb(220,220,220);
1.693 droeschl 7830: }
7831:
1.721 harmsja 7832: div.LC_columnSection {
1.911 bisitz 7833: display: block;
7834: clear: both;
7835: overflow: hidden;
7836: margin: 0;
1.693 droeschl 7837: }
7838:
1.721 harmsja 7839: div.LC_columnSection>* {
1.911 bisitz 7840: float: left;
7841: margin: 10px 20px 10px 0;
7842: overflow:hidden;
1.693 droeschl 7843: }
1.721 harmsja 7844:
1.795 www 7845: table em {
1.911 bisitz 7846: font-weight: bold;
7847: font-style: normal;
1.748 schulted 7848: }
1.795 www 7849:
1.779 bisitz 7850: table.LC_tableBrowseRes,
1.795 www 7851: table.LC_tableOfContent {
1.911 bisitz 7852: border:none;
7853: border-spacing: 1px;
7854: padding: 3px;
7855: background-color: #FFFFFF;
7856: font-size: 90%;
1.753 droeschl 7857: }
1.789 droeschl 7858:
1.911 bisitz 7859: table.LC_tableOfContent {
7860: border-collapse: collapse;
1.789 droeschl 7861: }
7862:
1.771 droeschl 7863: table.LC_tableBrowseRes a,
1.768 schulted 7864: table.LC_tableOfContent a {
1.911 bisitz 7865: background-color: transparent;
7866: text-decoration: none;
1.753 droeschl 7867: }
7868:
1.795 www 7869: table.LC_tableOfContent img {
1.911 bisitz 7870: border: none;
7871: height: 1.3em;
7872: vertical-align: text-bottom;
7873: margin-right: 0.3em;
1.753 droeschl 7874: }
1.757 schulted 7875:
1.795 www 7876: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7877: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7878: }
7879:
1.795 www 7880: a#LC_content_toolbar_everything {
1.911 bisitz 7881: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7882: }
7883:
1.795 www 7884: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7885: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7886: }
7887:
1.795 www 7888: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7889: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7890: }
7891:
1.795 www 7892: a#LC_content_toolbar_changefolder {
1.911 bisitz 7893: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7894: }
7895:
1.795 www 7896: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7897: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7898: }
7899:
1.1043 raeburn 7900: a#LC_content_toolbar_edittoplevel {
7901: background-image:url(/res/adm/pages/edittoplevel.gif);
7902: }
7903:
1.795 www 7904: ul#LC_toolbar li a:hover {
1.911 bisitz 7905: background-position: bottom center;
1.757 schulted 7906: }
7907:
1.795 www 7908: ul#LC_toolbar {
1.911 bisitz 7909: padding: 0;
7910: margin: 2px;
7911: list-style:none;
7912: position:relative;
7913: background-color:white;
1.1075.2.9 raeburn 7914: overflow: auto;
1.757 schulted 7915: }
7916:
1.795 www 7917: ul#LC_toolbar li {
1.911 bisitz 7918: border:1px solid white;
7919: padding: 0;
7920: margin: 0;
7921: float: left;
7922: display:inline;
7923: vertical-align:middle;
1.1075.2.9 raeburn 7924: white-space: nowrap;
1.911 bisitz 7925: }
1.757 schulted 7926:
1.783 amueller 7927:
1.795 www 7928: a.LC_toolbarItem {
1.911 bisitz 7929: display:block;
7930: padding: 0;
7931: margin: 0;
7932: height: 32px;
7933: width: 32px;
7934: color:white;
7935: border: none;
7936: background-repeat:no-repeat;
7937: background-color:transparent;
1.757 schulted 7938: }
7939:
1.915 droeschl 7940: ul.LC_funclist {
7941: margin: 0;
7942: padding: 0.5em 1em 0.5em 0;
7943: }
7944:
1.933 droeschl 7945: ul.LC_funclist > li:first-child {
7946: font-weight:bold;
7947: margin-left:0.8em;
7948: }
7949:
1.915 droeschl 7950: ul.LC_funclist + ul.LC_funclist {
7951: /*
7952: left border as a seperator if we have more than
7953: one list
7954: */
7955: border-left: 1px solid $sidebg;
7956: /*
7957: this hides the left border behind the border of the
7958: outer box if element is wrapped to the next 'line'
7959: */
7960: margin-left: -1px;
7961: }
7962:
1.843 bisitz 7963: ul.LC_funclist li {
1.915 droeschl 7964: display: inline;
1.782 bisitz 7965: white-space: nowrap;
1.915 droeschl 7966: margin: 0 0 0 25px;
7967: line-height: 150%;
1.782 bisitz 7968: }
7969:
1.974 wenzelju 7970: .LC_hidden {
7971: display: none;
7972: }
7973:
1.1030 www 7974: .LCmodal-overlay {
7975: position:fixed;
7976: top:0;
7977: right:0;
7978: bottom:0;
7979: left:0;
7980: height:100%;
7981: width:100%;
7982: margin:0;
7983: padding:0;
7984: background:#999;
7985: opacity:.75;
7986: filter: alpha(opacity=75);
7987: -moz-opacity: 0.75;
7988: z-index:101;
7989: }
7990:
7991: * html .LCmodal-overlay {
7992: position: absolute;
7993: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7994: }
7995:
7996: .LCmodal-window {
7997: position:fixed;
7998: top:50%;
7999: left:50%;
8000: margin:0;
8001: padding:0;
8002: z-index:102;
8003: }
8004:
8005: * html .LCmodal-window {
8006: position:absolute;
8007: }
8008:
8009: .LCclose-window {
8010: position:absolute;
8011: width:32px;
8012: height:32px;
8013: right:8px;
8014: top:8px;
8015: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8016: text-indent:-99999px;
8017: overflow:hidden;
8018: cursor:pointer;
8019: }
8020:
1.1075.2.158 raeburn 8021: .LCisDisabled {
8022: cursor: not-allowed;
8023: opacity: 0.5;
8024: }
8025:
8026: a[aria-disabled="true"] {
8027: color: currentColor;
8028: display: inline-block; /* For IE11/ MS Edge bug */
8029: pointer-events: none;
8030: text-decoration: none;
8031: }
8032:
1.1075.2.141 raeburn 8033: pre.LC_wordwrap {
8034: white-space: pre-wrap;
8035: white-space: -moz-pre-wrap;
8036: white-space: -pre-wrap;
8037: white-space: -o-pre-wrap;
8038: word-wrap: break-word;
8039: }
8040:
1.1075.2.17 raeburn 8041: /*
8042: styles used by TTH when "Default set of options to pass to tth/m
8043: when converting TeX" in course settings has been set
8044:
8045: option passed: -t
8046:
8047: */
8048:
8049: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8050: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8051: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8052: td div.norm {line-height:normal;}
8053:
8054: /*
8055: option passed -y3
8056: */
8057:
8058: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8059: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8060: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8061:
1.1075.2.121 raeburn 8062: #LC_minitab_header {
8063: float:left;
8064: width:100%;
8065: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8066: font-size:93%;
8067: line-height:normal;
8068: margin: 0.5em 0 0.5em 0;
8069: }
8070: #LC_minitab_header ul {
8071: margin:0;
8072: padding:10px 10px 0;
8073: list-style:none;
8074: }
8075: #LC_minitab_header li {
8076: float:left;
8077: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8078: margin:0;
8079: padding:0 0 0 9px;
8080: }
8081: #LC_minitab_header a {
8082: display:block;
8083: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8084: padding:5px 15px 4px 6px;
8085: }
8086: #LC_minitab_header #LC_current_minitab {
8087: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8088: }
8089: #LC_minitab_header #LC_current_minitab a {
8090: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8091: padding-bottom:5px;
8092: }
8093:
8094:
1.343 albertel 8095: END
8096: }
8097:
1.306 albertel 8098: =pod
8099:
8100: =item * &headtag()
8101:
8102: Returns a uniform footer for LON-CAPA web pages.
8103:
1.307 albertel 8104: Inputs: $title - optional title for the head
8105: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8106: $args - optional arguments
1.319 albertel 8107: force_register - if is true call registerurl so the remote is
8108: informed
1.415 albertel 8109: redirect -> array ref of
8110: 1- seconds before redirect occurs
8111: 2- url to redirect to
8112: 3- whether the side effect should occur
1.315 albertel 8113: (side effect of setting
8114: $env{'internal.head.redirect'} to the url
8115: redirected too)
1.1075.2.166 raeburn 8116: 4- whether encrypt check should be skipped
1.352 albertel 8117: domain -> force to color decorate a page for a specific
8118: domain
8119: function -> force usage of a specific rolish color scheme
8120: bgcolor -> override the default page bgcolor
1.460 albertel 8121: no_auto_mt_title
8122: -> prevent &mt()ing the title arg
1.464 albertel 8123:
1.306 albertel 8124: =cut
8125:
8126: sub headtag {
1.313 albertel 8127: my ($title,$head_extra,$args) = @_;
1.306 albertel 8128:
1.363 albertel 8129: my $function = $args->{'function'} || &get_users_function();
8130: my $domain = $args->{'domain'} || &determinedomain();
8131: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 8132: my $httphost = $args->{'use_absolute'};
1.418 albertel 8133: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8134: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8135: #time(),
1.418 albertel 8136: $env{'environment.color.timestamp'},
1.363 albertel 8137: $function,$domain,$bgcolor);
8138:
1.369 www 8139: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8140:
1.308 albertel 8141: my $result =
8142: '<head>'.
1.1075.2.56 raeburn 8143: &font_settings($args);
1.319 albertel 8144:
1.1075.2.72 raeburn 8145: my $inhibitprint;
8146: if ($args->{'print_suppress'}) {
8147: $inhibitprint = &print_suppression();
8148: }
1.1064 raeburn 8149:
1.1075.2.172 raeburn 8150: if (!$args->{'frameset'} && !$args->{'switchserver'}) {
1.461 albertel 8151: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8152: }
1.1075.2.12 raeburn 8153: if ($args->{'force_register'}) {
8154: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 8155: }
1.436 albertel 8156: if (!$args->{'no_nav_bar'}
8157: && !$args->{'only_body'}
1.1075.2.172 raeburn 8158: && !$args->{'frameset'}
8159: && !$args->{'switchserver'}) {
1.1075.2.52 raeburn 8160: $result .= &help_menu_js($httphost);
1.1032 www 8161: $result.=&modal_window();
1.1038 www 8162: $result.=&togglebox_script();
1.1034 www 8163: $result.=&wishlist_window();
1.1041 www 8164: $result.=&LCprogressbarUpdate_script();
1.1034 www 8165: } else {
8166: if ($args->{'add_modal'}) {
8167: $result.=&modal_window();
8168: }
8169: if ($args->{'add_wishlist'}) {
8170: $result.=&wishlist_window();
8171: }
1.1038 www 8172: if ($args->{'add_togglebox'}) {
8173: $result.=&togglebox_script();
8174: }
1.1041 www 8175: if ($args->{'add_progressbar'}) {
8176: $result.=&LCprogressbarUpdate_script();
8177: }
1.436 albertel 8178: }
1.314 albertel 8179: if (ref($args->{'redirect'})) {
1.1075.2.166 raeburn 8180: my ($time,$url,$inhibit_continue,$skip_enc_check) = @{$args->{'redirect'}};
8181: if (!$skip_enc_check) {
8182: $url = &Apache::lonenc::check_encrypt($url);
8183: }
1.414 albertel 8184: if (!$inhibit_continue) {
8185: $env{'internal.head.redirect'} = $url;
8186: }
1.313 albertel 8187: $result.=<<ADDMETA
8188: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8189: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8190: ADDMETA
1.1075.2.89 raeburn 8191: } else {
8192: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8193: my $requrl = $env{'request.uri'};
8194: if ($requrl eq '') {
8195: $requrl = $ENV{'REQUEST_URI'};
8196: $requrl =~ s/\?.+$//;
8197: }
8198: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8199: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8200: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8201: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8202: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8203: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 8204: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1075.2.151 raeburn 8205: my ($offload,$offloadoth);
1.1075.2.89 raeburn 8206: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8207: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 8208: $offload = 1;
1.1075.2.151 raeburn 8209: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8210: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8211: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8212: $offloadoth = 1;
8213: $dom_in_use = $env{'user.domain'};
8214: }
8215: }
1.1075.2.145 raeburn 8216: }
8217: }
8218: unless ($offload) {
8219: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8220: if ($domdefs{'offloadoth'}{$lonhost}) {
8221: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8222: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8223: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8224: $offload = 1;
1.1075.2.151 raeburn 8225: $offloadoth = 1;
1.1075.2.145 raeburn 8226: $dom_in_use = $env{'user.domain'};
8227: }
1.1075.2.89 raeburn 8228: }
1.1075.2.145 raeburn 8229: }
8230: }
8231: }
8232: if ($offload) {
1.1075.2.158 raeburn 8233: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1075.2.151 raeburn 8234: if (($newserver eq '') && ($offloadoth)) {
8235: my @domains = &Apache::lonnet::current_machine_domains();
8236: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
8237: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8238: }
8239: }
1.1075.2.145 raeburn 8240: if (($newserver) && ($newserver ne $lonhost)) {
8241: my $numsec = 5;
8242: my $timeout = $numsec * 1000;
8243: my ($newurl,$locknum,%locks,$msg);
8244: if ($env{'request.role.adv'}) {
8245: ($locknum,%locks) = &Apache::lonnet::get_locks();
8246: }
8247: my $disable_submit = 0;
8248: if ($requrl =~ /$LONCAPA::assess_re/) {
8249: $disable_submit = 1;
8250: }
8251: if ($locknum) {
8252: my @lockinfo = sort(values(%locks));
1.1075.2.153 raeburn 8253: $msg = &mt('Once the following tasks are complete:')." \n".
1.1075.2.145 raeburn 8254: join(", ",sort(values(%locks)))."\n";
8255: if (&show_course()) {
8256: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 8257: } else {
1.1075.2.145 raeburn 8258: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
8259: }
8260: } else {
8261: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8262: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8263: }
8264: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8265: $newurl = '/adm/switchserver?otherserver='.$newserver;
8266: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8267: $newurl .= '&role='.$env{'request.role'};
8268: }
8269: if ($env{'request.symb'}) {
8270: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8271: if ($shownsymb =~ m{^/enc/}) {
8272: my $reqdmajor = 2;
8273: my $reqdminor = 11;
8274: my $reqdsubminor = 3;
8275: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8276: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8277: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8278: if (($major eq '' && $minor eq '') ||
8279: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8280: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8281: ($reqdsubminor > $subminor))))) {
8282: undef($shownsymb);
8283: }
1.1075.2.89 raeburn 8284: }
1.1075.2.145 raeburn 8285: if ($shownsymb) {
8286: &js_escape(\$shownsymb);
8287: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 8288: }
1.1075.2.145 raeburn 8289: } else {
8290: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8291: &js_escape(\$shownurl);
8292: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 8293: }
1.1075.2.145 raeburn 8294: }
8295: &js_escape(\$msg);
8296: $result.=<<OFFLOAD
1.1075.2.89 raeburn 8297: <meta http-equiv="pragma" content="no-cache" />
8298: <script type="text/javascript">
1.1075.2.92 raeburn 8299: // <![CDATA[
1.1075.2.89 raeburn 8300: function LC_Offload_Now() {
8301: var dest = "$newurl";
8302: if (dest != '') {
8303: window.location.href="$newurl";
8304: }
8305: }
1.1075.2.92 raeburn 8306: \$(document).ready(function () {
8307: window.alert('$msg');
8308: if ($disable_submit) {
1.1075.2.89 raeburn 8309: \$(".LC_hwk_submit").prop("disabled", true);
8310: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 8311: }
8312: setTimeout('LC_Offload_Now()', $timeout);
8313: });
8314: // ]]>
1.1075.2.89 raeburn 8315: </script>
8316: OFFLOAD
8317: }
8318: }
8319: }
8320: }
8321: }
1.313 albertel 8322: }
1.306 albertel 8323: if (!defined($title)) {
8324: $title = 'The LearningOnline Network with CAPA';
8325: }
1.460 albertel 8326: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.168 raeburn 8327: if ($title =~ /^LON-CAPA\s+/) {
8328: $result .= '<title> '.$title.'</title>';
8329: } else {
8330: $result .= '<title> LON-CAPA '.$title.'</title>';
8331: }
8332: $result .= "\n".'<link rel="stylesheet" type="text/css" href="'.$url.'"';
1.1075.2.61 raeburn 8333: if (!$args->{'frameset'}) {
8334: $result .= ' /';
8335: }
8336: $result .= '>'
1.1064 raeburn 8337: .$inhibitprint
1.414 albertel 8338: .$head_extra;
1.1075.2.108 raeburn 8339: my $clientmobile;
8340: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8341: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8342: } else {
8343: $clientmobile = $env{'browser.mobile'};
8344: }
8345: if ($clientmobile) {
1.1075.2.42 raeburn 8346: $result .= '
8347: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8348: <meta name="apple-mobile-web-app-capable" content="yes" />';
8349: }
1.1075.2.126 raeburn 8350: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8351: return $result.'</head>';
1.306 albertel 8352: }
8353:
8354: =pod
8355:
1.340 albertel 8356: =item * &font_settings()
8357:
8358: Returns neccessary <meta> to set the proper encoding
8359:
1.1075.2.56 raeburn 8360: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8361:
8362: =cut
8363:
8364: sub font_settings {
1.1075.2.56 raeburn 8365: my ($args) = @_;
1.340 albertel 8366: my $headerstring='';
1.1075.2.56 raeburn 8367: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8368: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8369: $headerstring.=
1.1075.2.61 raeburn 8370: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8371: if (!$args->{'frameset'}) {
8372: $headerstring.= ' /';
8373: }
8374: $headerstring .= '>'."\n";
1.340 albertel 8375: }
8376: return $headerstring;
8377: }
8378:
1.341 albertel 8379: =pod
8380:
1.1064 raeburn 8381: =item * &print_suppression()
8382:
8383: In course context returns css which causes the body to be blank when media="print",
8384: if printout generation is unavailable for the current resource.
8385:
8386: This could be because:
8387:
8388: (a) printstartdate is in the future
8389:
8390: (b) printenddate is in the past
8391:
8392: (c) there is an active exam block with "printout"
8393: functionality blocked
8394:
8395: Users with pav, pfo or evb privileges are exempt.
8396:
8397: Inputs: none
8398:
8399: =cut
8400:
8401:
8402: sub print_suppression {
8403: my $noprint;
8404: if ($env{'request.course.id'}) {
8405: my $scope = $env{'request.course.id'};
8406: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8407: (&Apache::lonnet::allowed('pfo',$scope))) {
8408: return;
8409: }
8410: if ($env{'request.course.sec'} ne '') {
8411: $scope .= "/$env{'request.course.sec'}";
8412: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8413: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8414: return;
1.1064 raeburn 8415: }
8416: }
8417: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8418: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.158 raeburn 8419: my $clientip = &Apache::lonnet::get_requestor_ip();
8420: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 8421: if ($blocked) {
8422: my $checkrole = "cm./$cdom/$cnum";
8423: if ($env{'request.course.sec'} ne '') {
8424: $checkrole .= "/$env{'request.course.sec'}";
8425: }
8426: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8427: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8428: $noprint = 1;
8429: }
8430: }
8431: unless ($noprint) {
8432: my $symb = &Apache::lonnet::symbread();
8433: if ($symb ne '') {
8434: my $navmap = Apache::lonnavmaps::navmap->new();
8435: if (ref($navmap)) {
8436: my $res = $navmap->getBySymb($symb);
8437: if (ref($res)) {
8438: if (!$res->resprintable()) {
8439: $noprint = 1;
8440: }
8441: }
8442: }
8443: }
8444: }
8445: if ($noprint) {
8446: return <<"ENDSTYLE";
8447: <style type="text/css" media="print">
8448: body { display:none }
8449: </style>
8450: ENDSTYLE
8451: }
8452: }
8453: return;
8454: }
8455:
8456: =pod
8457:
1.341 albertel 8458: =item * &xml_begin()
8459:
8460: Returns the needed doctype and <html>
8461:
8462: Inputs: none
8463:
8464: =cut
8465:
8466: sub xml_begin {
1.1075.2.61 raeburn 8467: my ($is_frameset) = @_;
1.341 albertel 8468: my $output='';
8469:
8470: if ($env{'browser.mathml'}) {
8471: $output='<?xml version="1.0"?>'
8472: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8473: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8474:
8475: # .'<!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">] >'
8476: .'<!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">'
8477: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8478: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8479: } elsif ($is_frameset) {
8480: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8481: '<html>'."\n";
1.341 albertel 8482: } else {
1.1075.2.61 raeburn 8483: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8484: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8485: }
8486: return $output;
8487: }
1.340 albertel 8488:
8489: =pod
8490:
1.306 albertel 8491: =item * &start_page()
8492:
8493: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8494:
1.648 raeburn 8495: Inputs:
8496:
8497: =over 4
8498:
8499: $title - optional title for the page
8500:
8501: $head_extra - optional extra HTML to incude inside the <head>
8502:
8503: $args - additional optional args supported are:
8504:
8505: =over 8
8506:
8507: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8508: arg on
1.814 bisitz 8509: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8510: add_entries -> additional attributes to add to the <body>
8511: domain -> force to color decorate a page for a
1.317 albertel 8512: specific domain
1.648 raeburn 8513: function -> force usage of a specific rolish color
1.317 albertel 8514: scheme
1.648 raeburn 8515: redirect -> see &headtag()
8516: bgcolor -> override the default page bg color
8517: js_ready -> return a string ready for being used in
1.317 albertel 8518: a javascript writeln
1.648 raeburn 8519: html_encode -> return a string ready for being used in
1.320 albertel 8520: a html attribute
1.648 raeburn 8521: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8522: $forcereg arg
1.648 raeburn 8523: frameset -> if true will start with a <frameset>
1.330 albertel 8524: rather than <body>
1.648 raeburn 8525: skip_phases -> hash ref of
1.338 albertel 8526: head -> skip the <html><head> generation
8527: body -> skip all <body> generation
1.1075.2.12 raeburn 8528: no_inline_link -> if true and in remote mode, don't show the
8529: 'Switch To Inline Menu' link
1.648 raeburn 8530: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8531: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8532: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.175! raeburn 8533: bread_crumbs_style -> breadcrumbs are contained within <div id="LC_breadcrumbs">,
! 8534: and &standard_css() contains CSS for #LC_breadcrumbs, if you want
! 8535: to override those values, or add to them, specify the value to
! 8536: include in the style attribute to include in the div tag by using
! 8537: bread_crumbs_style (e.g., overflow: visible)
1.1075.2.123 raeburn 8538: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8539: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8540: group -> includes the current group, if page is for a
8541: specific group
1.1075.2.133 raeburn 8542: use_absolute -> for request for external resource or syllabus, this
8543: will contain https://<hostname> if server uses
8544: https (as per hosts.tab), but request is for http
8545: hostname -> hostname, originally from $r->hostname(), (optional).
1.1075.2.158 raeburn 8546: links_disabled -> Links in primary and secondary menus are disabled
8547: (Can enable them once page has loaded - see lonroles.pm
8548: for an example).
1.361 albertel 8549:
1.648 raeburn 8550: =back
1.460 albertel 8551:
1.648 raeburn 8552: =back
1.562 albertel 8553:
1.306 albertel 8554: =cut
8555:
8556: sub start_page {
1.309 albertel 8557: my ($title,$head_extra,$args) = @_;
1.318 albertel 8558: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8559:
1.315 albertel 8560: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8561: my ($result,@advtools);
1.964 droeschl 8562:
1.338 albertel 8563: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8564: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8565: }
8566:
8567: if (! exists($args->{'skip_phases'}{'body'}) ) {
8568: if ($args->{'frameset'}) {
8569: my $attr_string = &make_attr_string($args->{'force_register'},
8570: $args->{'add_entries'});
8571: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8572: } else {
8573: $result .=
8574: &bodytag($title,
8575: $args->{'function'}, $args->{'add_entries'},
8576: $args->{'only_body'}, $args->{'domain'},
8577: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8578: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8579: $args, \@advtools);
1.831 bisitz 8580: }
1.330 albertel 8581: }
1.338 albertel 8582:
1.315 albertel 8583: if ($args->{'js_ready'}) {
1.713 kaisler 8584: $result = &js_ready($result);
1.315 albertel 8585: }
1.320 albertel 8586: if ($args->{'html_encode'}) {
1.713 kaisler 8587: $result = &html_encode($result);
8588: }
8589:
1.813 bisitz 8590: # Preparation for new and consistent functionlist at top of screen
8591: # if ($args->{'functionlist'}) {
8592: # $result .= &build_functionlist();
8593: #}
8594:
1.964 droeschl 8595: # Don't add anything more if only_body wanted or in const space
8596: return $result if $args->{'only_body'}
8597: || $env{'request.state'} eq 'construct';
1.813 bisitz 8598:
8599: #Breadcrumbs
1.758 kaisler 8600: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8601: &Apache::lonhtmlcommon::clear_breadcrumbs();
8602: #if any br links exists, add them to the breadcrumbs
8603: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8604: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8605: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8606: }
8607: }
1.1075.2.19 raeburn 8608: # if @advtools array contains items add then to the breadcrumbs
8609: if (@advtools > 0) {
8610: &Apache::lonmenu::advtools_crumbs(@advtools);
8611: }
1.1075.2.123 raeburn 8612: my $menulink;
8613: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8614: if (exists($args->{'bread_crumbs_nomenu'})) {
8615: $menulink = 0;
8616: } else {
8617: undef($menulink);
8618: }
1.758 kaisler 8619: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8620: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.175! raeburn 8621: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},
! 8622: '',$menulink,'',
! 8623: $args->{'bread_crumbs_style'});
1.758 kaisler 8624: }else{
1.1075.2.175! raeburn 8625: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink,'',
! 8626: $args->{'bread_crumbs_style'});
1.758 kaisler 8627: }
1.1075.2.24 raeburn 8628: } elsif (($env{'environment.remote'} eq 'on') &&
8629: ($env{'form.inhibitmenu'} ne 'yes') &&
8630: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8631: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8632: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8633: }
1.315 albertel 8634: return $result;
1.306 albertel 8635: }
8636:
8637: sub end_page {
1.315 albertel 8638: my ($args) = @_;
8639: $env{'internal.end_page'}++;
1.330 albertel 8640: my $result;
1.335 albertel 8641: if ($args->{'discussion'}) {
8642: my ($target,$parser);
8643: if (ref($args->{'discussion'})) {
8644: ($target,$parser) =($args->{'discussion'}{'target'},
8645: $args->{'discussion'}{'parser'});
8646: }
8647: $result .= &Apache::lonxml::xmlend($target,$parser);
8648: }
1.330 albertel 8649: if ($args->{'frameset'}) {
8650: $result .= '</frameset>';
8651: } else {
1.635 raeburn 8652: $result .= &endbodytag($args);
1.330 albertel 8653: }
1.1075.2.6 raeburn 8654: unless ($args->{'notbody'}) {
8655: $result .= "\n</html>";
8656: }
1.330 albertel 8657:
1.315 albertel 8658: if ($args->{'js_ready'}) {
1.317 albertel 8659: $result = &js_ready($result);
1.315 albertel 8660: }
1.335 albertel 8661:
1.320 albertel 8662: if ($args->{'html_encode'}) {
8663: $result = &html_encode($result);
8664: }
1.335 albertel 8665:
1.315 albertel 8666: return $result;
8667: }
8668:
1.1034 www 8669: sub wishlist_window {
8670: return(<<'ENDWISHLIST');
1.1046 raeburn 8671: <script type="text/javascript">
1.1034 www 8672: // <![CDATA[
8673: // <!-- BEGIN LON-CAPA Internal
8674: function set_wishlistlink(title, path) {
8675: if (!title) {
8676: title = document.title;
8677: title = title.replace(/^LON-CAPA /,'');
8678: }
1.1075.2.65 raeburn 8679: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8680: title = title.replace("'","\\\'");
1.1034 www 8681: if (!path) {
8682: path = location.pathname;
8683: }
1.1075.2.65 raeburn 8684: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8685: path = path.replace("'","\\\'");
1.1034 www 8686: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8687: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8688: }
8689: // END LON-CAPA Internal -->
8690: // ]]>
8691: </script>
8692: ENDWISHLIST
8693: }
8694:
1.1030 www 8695: sub modal_window {
8696: return(<<'ENDMODAL');
1.1046 raeburn 8697: <script type="text/javascript">
1.1030 www 8698: // <![CDATA[
8699: // <!-- BEGIN LON-CAPA Internal
8700: var modalWindow = {
8701: parent:"body",
8702: windowId:null,
8703: content:null,
8704: width:null,
8705: height:null,
8706: close:function()
8707: {
8708: $(".LCmodal-window").remove();
8709: $(".LCmodal-overlay").remove();
8710: },
8711: open:function()
8712: {
8713: var modal = "";
8714: modal += "<div class=\"LCmodal-overlay\"></div>";
8715: 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;\">";
8716: modal += this.content;
8717: modal += "</div>";
8718:
8719: $(this.parent).append(modal);
8720:
8721: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8722: $(".LCclose-window").click(function(){modalWindow.close();});
8723: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8724: }
8725: };
1.1075.2.42 raeburn 8726: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8727: {
1.1075.2.119 raeburn 8728: source = source.replace(/'/g,"'");
1.1030 www 8729: modalWindow.windowId = "myModal";
8730: modalWindow.width = width;
8731: modalWindow.height = height;
1.1075.2.80 raeburn 8732: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8733: modalWindow.open();
1.1075.2.87 raeburn 8734: };
1.1030 www 8735: // END LON-CAPA Internal -->
8736: // ]]>
8737: </script>
8738: ENDMODAL
8739: }
8740:
8741: sub modal_link {
1.1075.2.42 raeburn 8742: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8743: unless ($width) { $width=480; }
8744: unless ($height) { $height=400; }
1.1031 www 8745: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8746: unless ($transparency) { $transparency='true'; }
8747:
1.1074 raeburn 8748: my $target_attr;
8749: if (defined($target)) {
8750: $target_attr = 'target="'.$target.'"';
8751: }
8752: return <<"ENDLINK";
1.1075.2.143 raeburn 8753: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 8754: ENDLINK
1.1030 www 8755: }
8756:
1.1032 www 8757: sub modal_adhoc_script {
1.1075.2.155 raeburn 8758: my ($funcname,$width,$height,$content,$possmathjax)=@_;
8759: my $mathjax;
8760: if ($possmathjax) {
8761: $mathjax = <<'ENDJAX';
8762: if (typeof MathJax == 'object') {
8763: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
8764: }
8765: ENDJAX
8766: }
1.1032 www 8767: return (<<ENDADHOC);
1.1046 raeburn 8768: <script type="text/javascript">
1.1032 www 8769: // <![CDATA[
8770: var $funcname = function()
8771: {
8772: modalWindow.windowId = "myModal";
8773: modalWindow.width = $width;
8774: modalWindow.height = $height;
8775: modalWindow.content = '$content';
8776: modalWindow.open();
1.1075.2.155 raeburn 8777: $mathjax
1.1032 www 8778: };
8779: // ]]>
8780: </script>
8781: ENDADHOC
8782: }
8783:
1.1041 www 8784: sub modal_adhoc_inner {
1.1075.2.155 raeburn 8785: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 8786: my $innerwidth=$width-20;
8787: $content=&js_ready(
1.1042 www 8788: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8789: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8790: $content.
1.1041 www 8791: &end_scrollbox().
1.1075.2.42 raeburn 8792: &end_page()
1.1041 www 8793: );
1.1075.2.155 raeburn 8794: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 8795: }
8796:
8797: sub modal_adhoc_window {
1.1075.2.155 raeburn 8798: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
8799: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 8800: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8801: }
8802:
8803: sub modal_adhoc_launch {
8804: my ($funcname,$width,$height,$content)=@_;
8805: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8806: <script type="text/javascript">
8807: // <![CDATA[
8808: $funcname();
8809: // ]]>
8810: </script>
8811: ENDLAUNCH
8812: }
8813:
8814: sub modal_adhoc_close {
8815: return (<<ENDCLOSE);
8816: <script type="text/javascript">
8817: // <![CDATA[
8818: modalWindow.close();
8819: // ]]>
8820: </script>
8821: ENDCLOSE
8822: }
8823:
1.1038 www 8824: sub togglebox_script {
8825: return(<<ENDTOGGLE);
8826: <script type="text/javascript">
8827: // <![CDATA[
8828: function LCtoggleDisplay(id,hidetext,showtext) {
8829: link = document.getElementById(id + "link").childNodes[0];
8830: with (document.getElementById(id).style) {
8831: if (display == "none" ) {
8832: display = "inline";
8833: link.nodeValue = hidetext;
8834: } else {
8835: display = "none";
8836: link.nodeValue = showtext;
8837: }
8838: }
8839: }
8840: // ]]>
8841: </script>
8842: ENDTOGGLE
8843: }
8844:
1.1039 www 8845: sub start_togglebox {
8846: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8847: unless ($heading) { $heading=''; } else { $heading.=' '; }
8848: unless ($showtext) { $showtext=&mt('show'); }
8849: unless ($hidetext) { $hidetext=&mt('hide'); }
8850: unless ($headerbg) { $headerbg='#FFFFFF'; }
8851: return &start_data_table().
8852: &start_data_table_header_row().
8853: '<td bgcolor="'.$headerbg.'">'.$heading.
8854: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8855: $showtext.'\')">'.$showtext.'</a>]</td>'.
8856: &end_data_table_header_row().
8857: '<tr id="'.$id.'" style="display:none""><td>';
8858: }
8859:
8860: sub end_togglebox {
8861: return '</td></tr>'.&end_data_table();
8862: }
8863:
1.1041 www 8864: sub LCprogressbar_script {
1.1075.2.130 raeburn 8865: my ($id,$number_to_do)=@_;
8866: if ($number_to_do) {
8867: return(<<ENDPROGRESS);
1.1041 www 8868: <script type="text/javascript">
8869: // <![CDATA[
1.1045 www 8870: \$('#progressbar$id').progressbar({
1.1041 www 8871: value: 0,
8872: change: function(event, ui) {
8873: var newVal = \$(this).progressbar('option', 'value');
8874: \$('.pblabel', this).text(LCprogressTxt);
8875: }
8876: });
8877: // ]]>
8878: </script>
8879: ENDPROGRESS
1.1075.2.130 raeburn 8880: } else {
8881: return(<<ENDPROGRESS);
8882: <script type="text/javascript">
8883: // <![CDATA[
8884: \$('#progressbar$id').progressbar({
8885: value: false,
8886: create: function(event, ui) {
8887: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8888: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8889: }
8890: });
8891: // ]]>
8892: </script>
8893: ENDPROGRESS
8894: }
1.1041 www 8895: }
8896:
8897: sub LCprogressbarUpdate_script {
8898: return(<<ENDPROGRESSUPDATE);
8899: <style type="text/css">
8900: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8901: .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 8902: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8903: </style>
8904: <script type="text/javascript">
8905: // <![CDATA[
1.1045 www 8906: var LCprogressTxt='---';
8907:
1.1075.2.130 raeburn 8908: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8909: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8910: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8911: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8912: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8913: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8914: } else {
8915: \$('#progressbar'+id).progressbar('value',percent);
8916: }
1.1041 www 8917: }
8918: // ]]>
8919: </script>
8920: ENDPROGRESSUPDATE
8921: }
8922:
1.1042 www 8923: my $LClastpercent;
1.1045 www 8924: my $LCidcnt;
8925: my $LCcurrentid;
1.1042 www 8926:
1.1041 www 8927: sub LCprogressbar {
1.1075.2.130 raeburn 8928: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8929: $LClastpercent=0;
1.1045 www 8930: $LCidcnt++;
8931: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8932: my ($starting,$content);
8933: if ($number_to_do) {
8934: $starting=&mt('Starting');
8935: $content=(<<ENDPROGBAR);
8936: $preamble
1.1045 www 8937: <div id="progressbar$LCcurrentid">
1.1041 www 8938: <span class="pblabel">$starting</span>
8939: </div>
8940: ENDPROGBAR
1.1075.2.130 raeburn 8941: } else {
8942: $starting=&mt('Loading...');
8943: $LClastpercent='false';
8944: $content=(<<ENDPROGBAR);
8945: $preamble
8946: <div id="progressbar$LCcurrentid">
8947: <div class="progress-label">$starting</div>
8948: </div>
8949: ENDPROGBAR
8950: }
8951: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8952: }
8953:
8954: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8955: my ($r,$val,$text,$number_to_do)=@_;
8956: if ($number_to_do) {
8957: unless ($val) {
8958: if ($LClastpercent) {
8959: $val=$LClastpercent;
8960: } else {
8961: $val=0;
8962: }
8963: }
8964: if ($val<0) { $val=0; }
8965: if ($val>100) { $val=0; }
8966: $LClastpercent=$val;
8967: unless ($text) { $text=$val.'%'; }
8968: } else {
8969: $val = 'false';
1.1042 www 8970: }
1.1041 www 8971: $text=&js_ready($text);
1.1044 www 8972: &r_print($r,<<ENDUPDATE);
1.1041 www 8973: <script type="text/javascript">
8974: // <![CDATA[
1.1075.2.130 raeburn 8975: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8976: // ]]>
8977: </script>
8978: ENDUPDATE
1.1035 www 8979: }
8980:
1.1042 www 8981: sub LCprogressbarClose {
8982: my ($r)=@_;
8983: $LClastpercent=0;
1.1044 www 8984: &r_print($r,<<ENDCLOSE);
1.1042 www 8985: <script type="text/javascript">
8986: // <![CDATA[
1.1045 www 8987: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8988: // ]]>
8989: </script>
8990: ENDCLOSE
1.1044 www 8991: }
8992:
8993: sub r_print {
8994: my ($r,$to_print)=@_;
8995: if ($r) {
8996: $r->print($to_print);
8997: $r->rflush();
8998: } else {
8999: print($to_print);
9000: }
1.1042 www 9001: }
9002:
1.320 albertel 9003: sub html_encode {
9004: my ($result) = @_;
9005:
1.322 albertel 9006: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9007:
9008: return $result;
9009: }
1.1044 www 9010:
1.317 albertel 9011: sub js_ready {
9012: my ($result) = @_;
9013:
1.323 albertel 9014: $result =~ s/[\n\r]/ /xmsg;
9015: $result =~ s/\\/\\\\/xmsg;
9016: $result =~ s/'/\\'/xmsg;
1.372 albertel 9017: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9018:
9019: return $result;
9020: }
9021:
1.315 albertel 9022: sub validate_page {
9023: if ( exists($env{'internal.start_page'})
1.316 albertel 9024: && $env{'internal.start_page'} > 1) {
9025: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9026: $env{'internal.start_page'}.' '.
1.316 albertel 9027: $ENV{'request.filename'});
1.315 albertel 9028: }
9029: if ( exists($env{'internal.end_page'})
1.316 albertel 9030: && $env{'internal.end_page'} > 1) {
9031: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9032: $env{'internal.end_page'}.' '.
1.316 albertel 9033: $env{'request.filename'});
1.315 albertel 9034: }
9035: if ( exists($env{'internal.start_page'})
9036: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9037: &Apache::lonnet::logthis('start_page called without end_page '.
9038: $env{'request.filename'});
1.315 albertel 9039: }
9040: if ( ! exists($env{'internal.start_page'})
9041: && exists($env{'internal.end_page'})) {
1.316 albertel 9042: &Apache::lonnet::logthis('end_page called without start_page'.
9043: $env{'request.filename'});
1.315 albertel 9044: }
1.306 albertel 9045: }
1.315 albertel 9046:
1.996 www 9047:
9048: sub start_scrollbox {
1.1075.2.56 raeburn 9049: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9050: unless ($outerwidth) { $outerwidth='520px'; }
9051: unless ($width) { $width='500px'; }
9052: unless ($height) { $height='200px'; }
1.1075 raeburn 9053: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9054: if ($id ne '') {
1.1075.2.42 raeburn 9055: $table_id = ' id="table_'.$id.'"';
9056: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9057: }
1.1075 raeburn 9058: if ($bgcolor ne '') {
9059: $tdcol = "background-color: $bgcolor;";
9060: }
1.1075.2.42 raeburn 9061: my $nicescroll_js;
9062: if ($env{'browser.mobile'}) {
9063: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9064: }
1.1075 raeburn 9065: return <<"END";
1.1075.2.42 raeburn 9066: $nicescroll_js
9067:
9068: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 9069: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 9070: END
1.996 www 9071: }
9072:
9073: sub end_scrollbox {
1.1036 www 9074: return '</div></td></tr></table>';
1.996 www 9075: }
9076:
1.1075.2.42 raeburn 9077: sub nicescroll_javascript {
9078: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9079: my %options;
9080: if (ref($cursor) eq 'HASH') {
9081: %options = %{$cursor};
9082: }
9083: unless ($options{'railalign'} =~ /^left|right$/) {
9084: $options{'railalign'} = 'left';
9085: }
9086: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9087: my $function = &get_users_function();
9088: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
9089: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9090: $options{'cursorcolor'} = '#00F';
9091: }
9092: }
9093: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9094: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
9095: $options{'cursoropacity'}='1.0';
9096: }
9097: } else {
9098: $options{'cursoropacity'}='1.0';
9099: }
9100: if ($options{'cursorfixedheight'} eq 'none') {
9101: delete($options{'cursorfixedheight'});
9102: } else {
9103: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9104: }
9105: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9106: delete($options{'railoffset'});
9107: }
9108: my @niceoptions;
9109: while (my($key,$value) = each(%options)) {
9110: if ($value =~ /^\{.+\}$/) {
9111: push(@niceoptions,$key.':'.$value);
9112: } else {
9113: push(@niceoptions,$key.':"'.$value.'"');
9114: }
9115: }
9116: my $nicescroll_js = '
9117: $(document).ready(
9118: function() {
9119: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9120: }
9121: );
9122: ';
9123: if ($framecheck) {
9124: $nicescroll_js .= '
9125: function expand_div(caller) {
9126: if (top === self) {
9127: document.getElementById("'.$id.'").style.width = "auto";
9128: document.getElementById("'.$id.'").style.height = "auto";
9129: } else {
9130: try {
9131: if (parent.frames) {
9132: if (parent.frames.length > 1) {
9133: var framesrc = parent.frames[1].location.href;
9134: var currsrc = framesrc.replace(/\#.*$/,"");
9135: if ((caller == "search") || (currsrc == "'.$location.'")) {
9136: document.getElementById("'.$id.'").style.width = "auto";
9137: document.getElementById("'.$id.'").style.height = "auto";
9138: }
9139: }
9140: }
9141: } catch (e) {
9142: return;
9143: }
9144: }
9145: return;
9146: }
9147: ';
9148: }
9149: if ($needjsready) {
9150: $nicescroll_js = '
9151: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9152: } else {
9153: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9154: }
9155: return $nicescroll_js;
9156: }
9157:
1.318 albertel 9158: sub simple_error_page {
1.1075.2.49 raeburn 9159: my ($r,$title,$msg,$args) = @_;
9160: if (ref($args) eq 'HASH') {
9161: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9162: } else {
9163: $msg = &mt($msg);
9164: }
9165:
1.318 albertel 9166: my $page =
9167: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 9168: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9169: &Apache::loncommon::end_page();
9170: if (ref($r)) {
9171: $r->print($page);
1.327 albertel 9172: return;
1.318 albertel 9173: }
9174: return $page;
9175: }
1.347 albertel 9176:
9177: {
1.610 albertel 9178: my @row_count;
1.961 onken 9179:
9180: sub start_data_table_count {
9181: unshift(@row_count, 0);
9182: return;
9183: }
9184:
9185: sub end_data_table_count {
9186: shift(@row_count);
9187: return;
9188: }
9189:
1.347 albertel 9190: sub start_data_table {
1.1018 raeburn 9191: my ($add_class,$id) = @_;
1.422 albertel 9192: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9193: my $table_id;
9194: if (defined($id)) {
9195: $table_id = ' id="'.$id.'"';
9196: }
1.961 onken 9197: &start_data_table_count();
1.1018 raeburn 9198: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9199: }
9200:
9201: sub end_data_table {
1.961 onken 9202: &end_data_table_count();
1.389 albertel 9203: return '</table>'."\n";;
1.347 albertel 9204: }
9205:
9206: sub start_data_table_row {
1.974 wenzelju 9207: my ($add_class, $id) = @_;
1.610 albertel 9208: $row_count[0]++;
9209: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9210: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9211: $id = (' id="'.$id.'"') unless ($id eq '');
9212: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9213: }
1.471 banghart 9214:
9215: sub continue_data_table_row {
1.974 wenzelju 9216: my ($add_class, $id) = @_;
1.610 albertel 9217: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9218: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9219: $id = (' id="'.$id.'"') unless ($id eq '');
9220: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9221: }
1.347 albertel 9222:
9223: sub end_data_table_row {
1.389 albertel 9224: return '</tr>'."\n";;
1.347 albertel 9225: }
1.367 www 9226:
1.421 albertel 9227: sub start_data_table_empty_row {
1.707 bisitz 9228: # $row_count[0]++;
1.421 albertel 9229: return '<tr class="LC_empty_row" >'."\n";;
9230: }
9231:
9232: sub end_data_table_empty_row {
9233: return '</tr>'."\n";;
9234: }
9235:
1.367 www 9236: sub start_data_table_header_row {
1.389 albertel 9237: return '<tr class="LC_header_row">'."\n";;
1.367 www 9238: }
9239:
9240: sub end_data_table_header_row {
1.389 albertel 9241: return '</tr>'."\n";;
1.367 www 9242: }
1.890 droeschl 9243:
9244: sub data_table_caption {
9245: my $caption = shift;
9246: return "<caption class=\"LC_caption\">$caption</caption>";
9247: }
1.347 albertel 9248: }
9249:
1.548 albertel 9250: =pod
9251:
9252: =item * &inhibit_menu_check($arg)
9253:
9254: Checks for a inhibitmenu state and generates output to preserve it
9255:
9256: Inputs: $arg - can be any of
9257: - undef - in which case the return value is a string
9258: to add into arguments list of a uri
9259: - 'input' - in which case the return value is a HTML
9260: <form> <input> field of type hidden to
9261: preserve the value
9262: - a url - in which case the return value is the url with
9263: the neccesary cgi args added to preserve the
9264: inhibitmenu state
9265: - a ref to a url - no return value, but the string is
9266: updated to include the neccessary cgi
9267: args to preserve the inhibitmenu state
9268:
9269: =cut
9270:
9271: sub inhibit_menu_check {
9272: my ($arg) = @_;
9273: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9274: if ($arg eq 'input') {
9275: if ($env{'form.inhibitmenu'}) {
9276: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9277: } else {
9278: return
9279: }
9280: }
9281: if ($env{'form.inhibitmenu'}) {
9282: if (ref($arg)) {
9283: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9284: } elsif ($arg eq '') {
9285: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9286: } else {
9287: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9288: }
9289: }
9290: if (!ref($arg)) {
9291: return $arg;
9292: }
9293: }
9294:
1.251 albertel 9295: ###############################################
1.182 matthew 9296:
9297: =pod
9298:
1.549 albertel 9299: =back
9300:
9301: =head1 User Information Routines
9302:
9303: =over 4
9304:
1.405 albertel 9305: =item * &get_users_function()
1.182 matthew 9306:
9307: Used by &bodytag to determine the current users primary role.
9308: Returns either 'student','coordinator','admin', or 'author'.
9309:
9310: =cut
9311:
9312: ###############################################
9313: sub get_users_function {
1.815 tempelho 9314: my $function = 'norole';
1.818 tempelho 9315: if ($env{'request.role'}=~/^(st)/) {
9316: $function='student';
9317: }
1.907 raeburn 9318: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9319: $function='coordinator';
9320: }
1.258 albertel 9321: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9322: $function='admin';
9323: }
1.826 bisitz 9324: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9325: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9326: $function='author';
9327: }
9328: return $function;
1.54 www 9329: }
1.99 www 9330:
9331: ###############################################
9332:
1.233 raeburn 9333: =pod
9334:
1.821 raeburn 9335: =item * &show_course()
9336:
9337: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9338: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9339:
9340: Inputs:
9341: None
9342:
9343: Outputs:
9344: Scalar: 1 if 'Course' to be used, 0 otherwise.
9345:
9346: =cut
9347:
9348: ###############################################
9349: sub show_course {
9350: my $course = !$env{'user.adv'};
9351: if (!$env{'user.adv'}) {
9352: foreach my $env (keys(%env)) {
9353: next if ($env !~ m/^user\.priv\./);
9354: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9355: $course = 0;
9356: last;
9357: }
9358: }
9359: }
9360: return $course;
9361: }
9362:
9363: ###############################################
9364:
9365: =pod
9366:
1.542 raeburn 9367: =item * &check_user_status()
1.274 raeburn 9368:
9369: Determines current status of supplied role for a
9370: specific user. Roles can be active, previous or future.
9371:
9372: Inputs:
9373: user's domain, user's username, course's domain,
1.375 raeburn 9374: course's number, optional section ID.
1.274 raeburn 9375:
9376: Outputs:
9377: role status: active, previous or future.
9378:
9379: =cut
9380:
9381: sub check_user_status {
1.412 raeburn 9382: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9383: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9384: my @uroles = keys(%userinfo);
1.274 raeburn 9385: my $srchstr;
9386: my $active_chk = 'none';
1.412 raeburn 9387: my $now = time;
1.274 raeburn 9388: if (@uroles > 0) {
1.908 raeburn 9389: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9390: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9391: } else {
1.412 raeburn 9392: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9393: }
9394: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9395: my $role_end = 0;
9396: my $role_start = 0;
9397: $active_chk = 'active';
1.412 raeburn 9398: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9399: $role_end = $1;
9400: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9401: $role_start = $1;
1.274 raeburn 9402: }
9403: }
9404: if ($role_start > 0) {
1.412 raeburn 9405: if ($now < $role_start) {
1.274 raeburn 9406: $active_chk = 'future';
9407: }
9408: }
9409: if ($role_end > 0) {
1.412 raeburn 9410: if ($now > $role_end) {
1.274 raeburn 9411: $active_chk = 'previous';
9412: }
9413: }
9414: }
9415: }
9416: return $active_chk;
9417: }
9418:
9419: ###############################################
9420:
9421: =pod
9422:
1.405 albertel 9423: =item * &get_sections()
1.233 raeburn 9424:
9425: Determines all the sections for a course including
9426: sections with students and sections containing other roles.
1.419 raeburn 9427: Incoming parameters:
9428:
9429: 1. domain
9430: 2. course number
9431: 3. reference to array containing roles for which sections should
9432: be gathered (optional).
9433: 4. reference to array containing status types for which sections
9434: should be gathered (optional).
9435:
9436: If the third argument is undefined, sections are gathered for any role.
9437: If the fourth argument is undefined, sections are gathered for any status.
9438: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9439:
1.374 raeburn 9440: Returns section hash (keys are section IDs, values are
9441: number of users in each section), subject to the
1.419 raeburn 9442: optional roles filter, optional status filter
1.233 raeburn 9443:
9444: =cut
9445:
9446: ###############################################
9447: sub get_sections {
1.419 raeburn 9448: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9449: if (!defined($cdom) || !defined($cnum)) {
9450: my $cid = $env{'request.course.id'};
9451:
9452: return if (!defined($cid));
9453:
9454: $cdom = $env{'course.'.$cid.'.domain'};
9455: $cnum = $env{'course.'.$cid.'.num'};
9456: }
9457:
9458: my %sectioncount;
1.419 raeburn 9459: my $now = time;
1.240 albertel 9460:
1.1075.2.33 raeburn 9461: my $check_students = 1;
9462: my $only_students = 0;
9463: if (ref($possible_roles) eq 'ARRAY') {
9464: if (grep(/^st$/,@{$possible_roles})) {
9465: if (@{$possible_roles} == 1) {
9466: $only_students = 1;
9467: }
9468: } else {
9469: $check_students = 0;
9470: }
9471: }
9472:
9473: if ($check_students) {
1.276 albertel 9474: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9475: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9476: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9477: my $start_index = &Apache::loncoursedata::CL_START();
9478: my $end_index = &Apache::loncoursedata::CL_END();
9479: my $status;
1.366 albertel 9480: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9481: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9482: $data->[$status_index],
9483: $data->[$start_index],
9484: $data->[$end_index]);
9485: if ($stu_status eq 'Active') {
9486: $status = 'active';
9487: } elsif ($end < $now) {
9488: $status = 'previous';
9489: } elsif ($start > $now) {
9490: $status = 'future';
9491: }
9492: if ($section ne '-1' && $section !~ /^\s*$/) {
9493: if ((!defined($possible_status)) || (($status ne '') &&
9494: (grep/^\Q$status\E$/,@{$possible_status}))) {
9495: $sectioncount{$section}++;
9496: }
1.240 albertel 9497: }
9498: }
9499: }
1.1075.2.33 raeburn 9500: if ($only_students) {
9501: return %sectioncount;
9502: }
1.240 albertel 9503: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9504: foreach my $user (sort(keys(%courseroles))) {
9505: if ($user !~ /^(\w{2})/) { next; }
9506: my ($role) = ($user =~ /^(\w{2})/);
9507: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9508: my ($section,$status);
1.240 albertel 9509: if ($role eq 'cr' &&
9510: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9511: $section=$1;
9512: }
9513: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9514: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9515: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9516: if ($end == -1 && $start == -1) {
9517: next; #deleted role
9518: }
9519: if (!defined($possible_status)) {
9520: $sectioncount{$section}++;
9521: } else {
9522: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9523: $status = 'active';
9524: } elsif ($end < $now) {
9525: $status = 'future';
9526: } elsif ($start > $now) {
9527: $status = 'previous';
9528: }
9529: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9530: $sectioncount{$section}++;
9531: }
9532: }
1.233 raeburn 9533: }
1.366 albertel 9534: return %sectioncount;
1.233 raeburn 9535: }
9536:
1.274 raeburn 9537: ###############################################
1.294 raeburn 9538:
9539: =pod
1.405 albertel 9540:
9541: =item * &get_course_users()
9542:
1.275 raeburn 9543: Retrieves usernames:domains for users in the specified course
9544: with specific role(s), and access status.
9545:
9546: Incoming parameters:
1.277 albertel 9547: 1. course domain
9548: 2. course number
9549: 3. access status: users must have - either active,
1.275 raeburn 9550: previous, future, or all.
1.277 albertel 9551: 4. reference to array of permissible roles
1.288 raeburn 9552: 5. reference to array of section restrictions (optional)
9553: 6. reference to results object (hash of hashes).
9554: 7. reference to optional userdata hash
1.609 raeburn 9555: 8. reference to optional statushash
1.630 raeburn 9556: 9. flag if privileged users (except those set to unhide in
9557: course settings) should be excluded
1.609 raeburn 9558: Keys of top level results hash are roles.
1.275 raeburn 9559: Keys of inner hashes are username:domain, with
9560: values set to access type.
1.288 raeburn 9561: Optional userdata hash returns an array with arguments in the
9562: same order as loncoursedata::get_classlist() for student data.
9563:
1.609 raeburn 9564: Optional statushash returns
9565:
1.288 raeburn 9566: Entries for end, start, section and status are blank because
9567: of the possibility of multiple values for non-student roles.
9568:
1.275 raeburn 9569: =cut
1.405 albertel 9570:
1.275 raeburn 9571: ###############################################
1.405 albertel 9572:
1.275 raeburn 9573: sub get_course_users {
1.630 raeburn 9574: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9575: my %idx = ();
1.419 raeburn 9576: my %seclists;
1.288 raeburn 9577:
9578: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9579: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9580: $idx{end} = &Apache::loncoursedata::CL_END();
9581: $idx{start} = &Apache::loncoursedata::CL_START();
9582: $idx{id} = &Apache::loncoursedata::CL_ID();
9583: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9584: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9585: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9586:
1.290 albertel 9587: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9588: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9589: my $now = time;
1.277 albertel 9590: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9591: my $match = 0;
1.412 raeburn 9592: my $secmatch = 0;
1.419 raeburn 9593: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9594: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9595: if ($section eq '') {
9596: $section = 'none';
9597: }
1.291 albertel 9598: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9599: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9600: $secmatch = 1;
9601: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9602: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9603: $secmatch = 1;
9604: }
9605: } else {
1.419 raeburn 9606: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9607: $secmatch = 1;
9608: }
1.290 albertel 9609: }
1.412 raeburn 9610: if (!$secmatch) {
9611: next;
9612: }
1.419 raeburn 9613: }
1.275 raeburn 9614: if (defined($$types{'active'})) {
1.288 raeburn 9615: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9616: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9617: $match = 1;
1.275 raeburn 9618: }
9619: }
9620: if (defined($$types{'previous'})) {
1.609 raeburn 9621: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9622: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9623: $match = 1;
1.275 raeburn 9624: }
9625: }
9626: if (defined($$types{'future'})) {
1.609 raeburn 9627: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9628: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9629: $match = 1;
1.275 raeburn 9630: }
9631: }
1.609 raeburn 9632: if ($match) {
9633: push(@{$seclists{$student}},$section);
9634: if (ref($userdata) eq 'HASH') {
9635: $$userdata{$student} = $$classlist{$student};
9636: }
9637: if (ref($statushash) eq 'HASH') {
9638: $statushash->{$student}{'st'}{$section} = $status;
9639: }
1.288 raeburn 9640: }
1.275 raeburn 9641: }
9642: }
1.412 raeburn 9643: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9644: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9645: my $now = time;
1.609 raeburn 9646: my %displaystatus = ( previous => 'Expired',
9647: active => 'Active',
9648: future => 'Future',
9649: );
1.1075.2.36 raeburn 9650: my (%nothide,@possdoms);
1.630 raeburn 9651: if ($hidepriv) {
9652: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9653: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9654: if ($user !~ /:/) {
9655: $nothide{join(':',split(/[\@]/,$user))}=1;
9656: } else {
9657: $nothide{$user} = 1;
9658: }
9659: }
1.1075.2.36 raeburn 9660: my @possdoms = ($cdom);
9661: if ($coursehash{'checkforpriv'}) {
9662: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9663: }
1.630 raeburn 9664: }
1.439 raeburn 9665: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9666: my $match = 0;
1.412 raeburn 9667: my $secmatch = 0;
1.439 raeburn 9668: my $status;
1.412 raeburn 9669: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9670: $user =~ s/:$//;
1.439 raeburn 9671: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9672: if ($end == -1 || $start == -1) {
9673: next;
9674: }
9675: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9676: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9677: my ($uname,$udom) = split(/:/,$user);
9678: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9679: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9680: $secmatch = 1;
9681: } elsif ($usec eq '') {
1.420 albertel 9682: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9683: $secmatch = 1;
9684: }
9685: } else {
9686: if (grep(/^\Q$usec\E$/,@{$sections})) {
9687: $secmatch = 1;
9688: }
9689: }
9690: if (!$secmatch) {
9691: next;
9692: }
1.288 raeburn 9693: }
1.419 raeburn 9694: if ($usec eq '') {
9695: $usec = 'none';
9696: }
1.275 raeburn 9697: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9698: if ($hidepriv) {
1.1075.2.36 raeburn 9699: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9700: (!$nothide{$uname.':'.$udom})) {
9701: next;
9702: }
9703: }
1.503 raeburn 9704: if ($end > 0 && $end < $now) {
1.439 raeburn 9705: $status = 'previous';
9706: } elsif ($start > $now) {
9707: $status = 'future';
9708: } else {
9709: $status = 'active';
9710: }
1.277 albertel 9711: foreach my $type (keys(%{$types})) {
1.275 raeburn 9712: if ($status eq $type) {
1.420 albertel 9713: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9714: push(@{$$users{$role}{$user}},$type);
9715: }
1.288 raeburn 9716: $match = 1;
9717: }
9718: }
1.419 raeburn 9719: if (($match) && (ref($userdata) eq 'HASH')) {
9720: if (!exists($$userdata{$uname.':'.$udom})) {
9721: &get_user_info($udom,$uname,\%idx,$userdata);
9722: }
1.420 albertel 9723: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9724: push(@{$seclists{$uname.':'.$udom}},$usec);
9725: }
1.609 raeburn 9726: if (ref($statushash) eq 'HASH') {
9727: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9728: }
1.275 raeburn 9729: }
9730: }
9731: }
9732: }
1.290 albertel 9733: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9734: if ((defined($cdom)) && (defined($cnum))) {
9735: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9736: if ( defined($csettings{'internal.courseowner'}) ) {
9737: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9738: next if ($owner eq '');
9739: my ($ownername,$ownerdom);
9740: if ($owner =~ /^([^:]+):([^:]+)$/) {
9741: $ownername = $1;
9742: $ownerdom = $2;
9743: } else {
9744: $ownername = $owner;
9745: $ownerdom = $cdom;
9746: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9747: }
9748: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9749: if (defined($userdata) &&
1.609 raeburn 9750: !exists($$userdata{$owner})) {
9751: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9752: if (!grep(/^none$/,@{$seclists{$owner}})) {
9753: push(@{$seclists{$owner}},'none');
9754: }
9755: if (ref($statushash) eq 'HASH') {
9756: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9757: }
1.290 albertel 9758: }
1.279 raeburn 9759: }
9760: }
9761: }
1.419 raeburn 9762: foreach my $user (keys(%seclists)) {
9763: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9764: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9765: }
1.275 raeburn 9766: }
9767: return;
9768: }
9769:
1.288 raeburn 9770: sub get_user_info {
9771: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9772: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9773: &plainname($uname,$udom,'lastname');
1.291 albertel 9774: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9775: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9776: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9777: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9778: return;
9779: }
1.275 raeburn 9780:
1.472 raeburn 9781: ###############################################
9782:
9783: =pod
9784:
9785: =item * &get_user_quota()
9786:
1.1075.2.41 raeburn 9787: Retrieves quota assigned for storage of user files.
9788: Default is to report quota for portfolio files.
1.472 raeburn 9789:
9790: Incoming parameters:
9791: 1. user's username
9792: 2. user's domain
1.1075.2.41 raeburn 9793: 3. quota name - portfolio, author, or course
9794: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9795: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9796: course
1.472 raeburn 9797:
9798: Returns:
1.1075.2.58 raeburn 9799: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9800: 2. (Optional) Type of setting: custom or default
9801: (individually assigned or default for user's
9802: institutional status).
9803: 3. (Optional) - User's institutional status (e.g., faculty, staff
9804: or student - types as defined in localenroll::inst_usertypes
9805: for user's domain, which determines default quota for user.
9806: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9807:
9808: If a value has been stored in the user's environment,
1.536 raeburn 9809: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9810: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9811:
9812: =cut
9813:
9814: ###############################################
9815:
9816:
9817: sub get_user_quota {
1.1075.2.42 raeburn 9818: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9819: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9820: if (!defined($udom)) {
9821: $udom = $env{'user.domain'};
9822: }
9823: if (!defined($uname)) {
9824: $uname = $env{'user.name'};
9825: }
9826: if (($udom eq '' || $uname eq '') ||
9827: ($udom eq 'public') && ($uname eq 'public')) {
9828: $quota = 0;
1.536 raeburn 9829: $quotatype = 'default';
9830: $defquota = 0;
1.472 raeburn 9831: } else {
1.536 raeburn 9832: my $inststatus;
1.1075.2.41 raeburn 9833: if ($quotaname eq 'course') {
9834: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9835: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9836: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9837: } else {
9838: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9839: $quota = $cenv{'internal.uploadquota'};
9840: }
1.536 raeburn 9841: } else {
1.1075.2.41 raeburn 9842: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9843: if ($quotaname eq 'author') {
9844: $quota = $env{'environment.authorquota'};
9845: } else {
9846: $quota = $env{'environment.portfolioquota'};
9847: }
9848: $inststatus = $env{'environment.inststatus'};
9849: } else {
9850: my %userenv =
9851: &Apache::lonnet::get('environment',['portfolioquota',
9852: 'authorquota','inststatus'],$udom,$uname);
9853: my ($tmp) = keys(%userenv);
9854: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9855: if ($quotaname eq 'author') {
9856: $quota = $userenv{'authorquota'};
9857: } else {
9858: $quota = $userenv{'portfolioquota'};
9859: }
9860: $inststatus = $userenv{'inststatus'};
9861: } else {
9862: undef(%userenv);
9863: }
9864: }
9865: }
9866: if ($quota eq '' || wantarray) {
9867: if ($quotaname eq 'course') {
9868: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9869: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9870: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9871: $defquota = $domdefs{$crstype.'quota'};
9872: }
9873: if ($defquota eq '') {
9874: $defquota = 500;
9875: }
1.1075.2.41 raeburn 9876: } else {
9877: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9878: }
9879: if ($quota eq '') {
9880: $quota = $defquota;
9881: $quotatype = 'default';
9882: } else {
9883: $quotatype = 'custom';
9884: }
1.472 raeburn 9885: }
9886: }
1.536 raeburn 9887: if (wantarray) {
9888: return ($quota,$quotatype,$settingstatus,$defquota);
9889: } else {
9890: return $quota;
9891: }
1.472 raeburn 9892: }
9893:
9894: ###############################################
9895:
9896: =pod
9897:
9898: =item * &default_quota()
9899:
1.536 raeburn 9900: Retrieves default quota assigned for storage of user portfolio files,
9901: given an (optional) user's institutional status.
1.472 raeburn 9902:
9903: Incoming parameters:
1.1075.2.42 raeburn 9904:
1.472 raeburn 9905: 1. domain
1.536 raeburn 9906: 2. (Optional) institutional status(es). This is a : separated list of
9907: status types (e.g., faculty, staff, student etc.)
9908: which apply to the user for whom the default is being retrieved.
9909: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9910: default quota will be returned.
9911: 3. quota name - portfolio, author, or course
9912: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9913:
9914: Returns:
1.1075.2.42 raeburn 9915:
1.1075.2.58 raeburn 9916: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9917: 2. (Optional) institutional type which determined the value of the
9918: default quota.
1.472 raeburn 9919:
9920: If a value has been stored in the domain's configuration db,
9921: it will return that, otherwise it returns 20 (for backwards
9922: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9923: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9924:
1.536 raeburn 9925: If the user's status includes multiple types (e.g., staff and student),
9926: the largest default quota which applies to the user determines the
9927: default quota returned.
9928:
1.472 raeburn 9929: =cut
9930:
9931: ###############################################
9932:
9933:
9934: sub default_quota {
1.1075.2.41 raeburn 9935: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9936: my ($defquota,$settingstatus);
9937: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9938: ['quotas'],$udom);
1.1075.2.41 raeburn 9939: my $key = 'defaultquota';
9940: if ($quotaname eq 'author') {
9941: $key = 'authorquota';
9942: }
1.622 raeburn 9943: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9944: if ($inststatus ne '') {
1.765 raeburn 9945: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9946: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9947: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9948: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9949: if ($defquota eq '') {
1.1075.2.41 raeburn 9950: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9951: $settingstatus = $item;
1.1075.2.41 raeburn 9952: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9953: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9954: $settingstatus = $item;
9955: }
9956: }
1.1075.2.41 raeburn 9957: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9958: if ($quotahash{'quotas'}{$item} ne '') {
9959: if ($defquota eq '') {
9960: $defquota = $quotahash{'quotas'}{$item};
9961: $settingstatus = $item;
9962: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9963: $defquota = $quotahash{'quotas'}{$item};
9964: $settingstatus = $item;
9965: }
1.536 raeburn 9966: }
9967: }
9968: }
9969: }
9970: if ($defquota eq '') {
1.1075.2.41 raeburn 9971: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9972: $defquota = $quotahash{'quotas'}{$key}{'default'};
9973: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9974: $defquota = $quotahash{'quotas'}{'default'};
9975: }
1.536 raeburn 9976: $settingstatus = 'default';
1.1075.2.42 raeburn 9977: if ($defquota eq '') {
9978: if ($quotaname eq 'author') {
9979: $defquota = 500;
9980: }
9981: }
1.536 raeburn 9982: }
9983: } else {
9984: $settingstatus = 'default';
1.1075.2.41 raeburn 9985: if ($quotaname eq 'author') {
9986: $defquota = 500;
9987: } else {
9988: $defquota = 20;
9989: }
1.536 raeburn 9990: }
9991: if (wantarray) {
9992: return ($defquota,$settingstatus);
1.472 raeburn 9993: } else {
1.536 raeburn 9994: return $defquota;
1.472 raeburn 9995: }
9996: }
9997:
1.1075.2.41 raeburn 9998: ###############################################
9999:
10000: =pod
10001:
1.1075.2.42 raeburn 10002: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 10003:
10004: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 10005: of existing file within authoring space will cause quota for the authoring
10006: space to be exceeded.
10007:
10008: Same, if upload of a file directly to a course/community via Course Editor
10009: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 10010:
1.1075.2.61 raeburn 10011: Inputs: 7
1.1075.2.42 raeburn 10012: 1. username or coursenum
1.1075.2.41 raeburn 10013: 2. domain
1.1075.2.42 raeburn 10014: 3. context ('author' or 'course')
1.1075.2.41 raeburn 10015: 4. filename of file for which action is being requested
10016: 5. filesize (kB) of file
10017: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 10018: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 10019:
10020: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
10021: otherwise return null.
10022:
1.1075.2.42 raeburn 10023: =back
10024:
1.1075.2.41 raeburn 10025: =cut
10026:
1.1075.2.42 raeburn 10027: sub excess_filesize_warning {
1.1075.2.59 raeburn 10028: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 10029: my $current_disk_usage = 0;
1.1075.2.59 raeburn 10030: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 10031: if ($context eq 'author') {
10032: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10033: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10034: } else {
10035: foreach my $subdir ('docs','supplemental') {
10036: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10037: }
10038: }
1.1075.2.41 raeburn 10039: $disk_quota = int($disk_quota * 1000);
10040: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 10041: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 10042: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 10043: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10044: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 10045: $disk_quota,$current_disk_usage).
10046: '</p>';
10047: }
10048: return;
10049: }
10050:
10051: ###############################################
10052:
10053:
1.384 raeburn 10054: sub get_secgrprole_info {
10055: my ($cdom,$cnum,$needroles,$type) = @_;
10056: my %sections_count = &get_sections($cdom,$cnum);
10057: my @sections = (sort {$a <=> $b} keys(%sections_count));
10058: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10059: my @groups = sort(keys(%curr_groups));
10060: my $allroles = [];
10061: my $rolehash;
10062: my $accesshash = {
10063: active => 'Currently has access',
10064: future => 'Will have future access',
10065: previous => 'Previously had access',
10066: };
10067: if ($needroles) {
10068: $rolehash = {'all' => 'all'};
1.385 albertel 10069: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10070: if (&Apache::lonnet::error(%user_roles)) {
10071: undef(%user_roles);
10072: }
10073: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10074: my ($role)=split(/\:/,$item,2);
10075: if ($role eq 'cr') { next; }
10076: if ($role =~ /^cr/) {
10077: $$rolehash{$role} = (split('/',$role))[3];
10078: } else {
10079: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10080: }
10081: }
10082: foreach my $key (sort(keys(%{$rolehash}))) {
10083: push(@{$allroles},$key);
10084: }
10085: push (@{$allroles},'st');
10086: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10087: }
10088: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10089: }
10090:
1.555 raeburn 10091: sub user_picker {
1.1075.2.127 raeburn 10092: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10093: my $currdom = $dom;
1.1075.2.114 raeburn 10094: my @alldoms = &Apache::lonnet::all_domains();
10095: if (@alldoms == 1) {
10096: my %domsrch = &Apache::lonnet::get_dom('configuration',
10097: ['directorysrch'],$alldoms[0]);
10098: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10099: my $showdom = $domdesc;
10100: if ($showdom eq '') {
10101: $showdom = $dom;
10102: }
10103: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10104: if ((!$domsrch{'directorysrch'}{'available'}) &&
10105: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10106: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10107: }
10108: }
10109: }
1.555 raeburn 10110: my %curr_selected = (
10111: srchin => 'dom',
1.580 raeburn 10112: srchby => 'lastname',
1.555 raeburn 10113: );
10114: my $srchterm;
1.625 raeburn 10115: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10116: if ($srch->{'srchby'} ne '') {
10117: $curr_selected{'srchby'} = $srch->{'srchby'};
10118: }
10119: if ($srch->{'srchin'} ne '') {
10120: $curr_selected{'srchin'} = $srch->{'srchin'};
10121: }
10122: if ($srch->{'srchtype'} ne '') {
10123: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10124: }
10125: if ($srch->{'srchdomain'} ne '') {
10126: $currdom = $srch->{'srchdomain'};
10127: }
10128: $srchterm = $srch->{'srchterm'};
10129: }
1.1075.2.98 raeburn 10130: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10131: 'usr' => 'Search criteria',
1.563 raeburn 10132: 'doma' => 'Domain/institution to search',
1.558 albertel 10133: 'uname' => 'username',
10134: 'lastname' => 'last name',
1.555 raeburn 10135: 'lastfirst' => 'last name, first name',
1.558 albertel 10136: 'crs' => 'in this course',
1.576 raeburn 10137: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10138: 'alc' => 'all LON-CAPA',
1.573 raeburn 10139: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10140: 'exact' => 'is',
10141: 'contains' => 'contains',
1.569 raeburn 10142: 'begins' => 'begins with',
1.1075.2.98 raeburn 10143: );
10144: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10145: 'youm' => "You must include some text to search for.",
10146: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10147: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10148: 'yomc' => "You must choose a domain when using an institutional directory search.",
10149: 'ymcd' => "You must choose a domain when using a domain search.",
10150: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10151: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10152: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10153: );
1.1075.2.98 raeburn 10154: &html_escape(\%html_lt);
10155: &js_escape(\%js_lt);
1.1075.2.115 raeburn 10156: my $domform;
1.1075.2.126 raeburn 10157: my $allow_blank = 1;
1.1075.2.115 raeburn 10158: if ($fixeddom) {
1.1075.2.126 raeburn 10159: $allow_blank = 0;
10160: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 10161: } else {
1.1075.2.126 raeburn 10162: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 10163: }
1.563 raeburn 10164: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10165:
10166: my @srchins = ('crs','dom','alc','instd');
10167:
10168: foreach my $option (@srchins) {
10169: # FIXME 'alc' option unavailable until
10170: # loncreateuser::print_user_query_page()
10171: # has been completed.
10172: next if ($option eq 'alc');
1.880 raeburn 10173: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10174: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 10175: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10176: if ($curr_selected{'srchin'} eq $option) {
10177: $srchinsel .= '
1.1075.2.98 raeburn 10178: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10179: } else {
10180: $srchinsel .= '
1.1075.2.98 raeburn 10181: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10182: }
1.555 raeburn 10183: }
1.563 raeburn 10184: $srchinsel .= "\n </select>\n";
1.555 raeburn 10185:
10186: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10187: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10188: if ($curr_selected{'srchby'} eq $option) {
10189: $srchbysel .= '
1.1075.2.98 raeburn 10190: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10191: } else {
10192: $srchbysel .= '
1.1075.2.98 raeburn 10193: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10194: }
10195: }
10196: $srchbysel .= "\n </select>\n";
10197:
10198: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10199: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10200: if ($curr_selected{'srchtype'} eq $option) {
10201: $srchtypesel .= '
1.1075.2.98 raeburn 10202: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10203: } else {
10204: $srchtypesel .= '
1.1075.2.98 raeburn 10205: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10206: }
10207: }
10208: $srchtypesel .= "\n </select>\n";
10209:
1.558 albertel 10210: my ($newuserscript,$new_user_create);
1.994 raeburn 10211: my $context_dom = $env{'request.role.domain'};
10212: if ($context eq 'requestcrs') {
10213: if ($env{'form.coursedom'} ne '') {
10214: $context_dom = $env{'form.coursedom'};
10215: }
10216: }
1.556 raeburn 10217: if ($forcenewuser) {
1.576 raeburn 10218: if (ref($srch) eq 'HASH') {
1.994 raeburn 10219: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10220: if ($cancreate) {
10221: $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>';
10222: } else {
1.799 bisitz 10223: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10224: my %usertypetext = (
10225: official => 'institutional',
10226: unofficial => 'non-institutional',
10227: );
1.799 bisitz 10228: $new_user_create = '<p class="LC_warning">'
10229: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10230: .' '
10231: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10232: ,'<a href="'.$helplink.'">','</a>')
10233: .'</p><br />';
1.627 raeburn 10234: }
1.576 raeburn 10235: }
10236: }
10237:
1.556 raeburn 10238: $newuserscript = <<"ENDSCRIPT";
10239:
1.570 raeburn 10240: function setSearch(createnew,callingForm) {
1.556 raeburn 10241: if (createnew == 1) {
1.570 raeburn 10242: for (var i=0; i<callingForm.srchby.length; i++) {
10243: if (callingForm.srchby.options[i].value == 'uname') {
10244: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10245: }
10246: }
1.570 raeburn 10247: for (var i=0; i<callingForm.srchin.length; i++) {
10248: if ( callingForm.srchin.options[i].value == 'dom') {
10249: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10250: }
10251: }
1.570 raeburn 10252: for (var i=0; i<callingForm.srchtype.length; i++) {
10253: if (callingForm.srchtype.options[i].value == 'exact') {
10254: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10255: }
10256: }
1.570 raeburn 10257: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10258: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10259: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10260: }
10261: }
10262: }
10263: }
10264: ENDSCRIPT
1.558 albertel 10265:
1.556 raeburn 10266: }
10267:
1.555 raeburn 10268: my $output = <<"END_BLOCK";
1.556 raeburn 10269: <script type="text/javascript">
1.824 bisitz 10270: // <![CDATA[
1.570 raeburn 10271: function validateEntry(callingForm) {
1.558 albertel 10272:
1.556 raeburn 10273: var checkok = 1;
1.558 albertel 10274: var srchin;
1.570 raeburn 10275: for (var i=0; i<callingForm.srchin.length; i++) {
10276: if ( callingForm.srchin[i].checked ) {
10277: srchin = callingForm.srchin[i].value;
1.558 albertel 10278: }
10279: }
10280:
1.570 raeburn 10281: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10282: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10283: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10284: var srchterm = callingForm.srchterm.value;
10285: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10286: var msg = "";
10287:
10288: if (srchterm == "") {
10289: checkok = 0;
1.1075.2.98 raeburn 10290: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10291: }
10292:
1.569 raeburn 10293: if (srchtype== 'begins') {
10294: if (srchterm.length < 2) {
10295: checkok = 0;
1.1075.2.98 raeburn 10296: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10297: }
10298: }
10299:
1.556 raeburn 10300: if (srchtype== 'contains') {
10301: if (srchterm.length < 3) {
10302: checkok = 0;
1.1075.2.98 raeburn 10303: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10304: }
10305: }
10306: if (srchin == 'instd') {
10307: if (srchdomain == '') {
10308: checkok = 0;
1.1075.2.98 raeburn 10309: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10310: }
10311: }
10312: if (srchin == 'dom') {
10313: if (srchdomain == '') {
10314: checkok = 0;
1.1075.2.98 raeburn 10315: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10316: }
10317: }
10318: if (srchby == 'lastfirst') {
10319: if (srchterm.indexOf(",") == -1) {
10320: checkok = 0;
1.1075.2.98 raeburn 10321: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10322: }
10323: if (srchterm.indexOf(",") == srchterm.length -1) {
10324: checkok = 0;
1.1075.2.98 raeburn 10325: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10326: }
10327: }
10328: if (checkok == 0) {
1.1075.2.98 raeburn 10329: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10330: return;
10331: }
10332: if (checkok == 1) {
1.570 raeburn 10333: callingForm.submit();
1.556 raeburn 10334: }
10335: }
10336:
10337: $newuserscript
10338:
1.824 bisitz 10339: // ]]>
1.556 raeburn 10340: </script>
1.558 albertel 10341:
10342: $new_user_create
10343:
1.555 raeburn 10344: END_BLOCK
1.558 albertel 10345:
1.876 raeburn 10346: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 10347: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10348: $domform.
10349: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 10350: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10351: $srchbysel.
10352: $srchtypesel.
10353: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10354: $srchinsel.
10355: &Apache::lonhtmlcommon::row_closure(1).
10356: &Apache::lonhtmlcommon::end_pick_box().
10357: '<br />';
1.1075.2.114 raeburn 10358: return ($output,1);
1.555 raeburn 10359: }
10360:
1.612 raeburn 10361: sub user_rule_check {
1.615 raeburn 10362: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10363: my ($response,%inst_response);
1.612 raeburn 10364: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10365: if (keys(%{$usershash}) > 1) {
10366: my (%by_username,%by_id,%userdoms);
10367: my $checkid;
1.612 raeburn 10368: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10369: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10370: $checkid = 1;
10371: }
10372: }
10373: foreach my $user (keys(%{$usershash})) {
10374: my ($uname,$udom) = split(/:/,$user);
10375: if ($checkid) {
10376: if (ref($usershash->{$user}) eq 'HASH') {
10377: if ($usershash->{$user}->{'id'} ne '') {
10378: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10379: $userdoms{$udom} = 1;
10380: if (ref($inst_results) eq 'HASH') {
10381: $inst_results->{$uname.':'.$udom} = {};
10382: }
10383: }
10384: }
10385: } else {
10386: $by_username{$udom}{$uname} = 1;
10387: $userdoms{$udom} = 1;
10388: if (ref($inst_results) eq 'HASH') {
10389: $inst_results->{$uname.':'.$udom} = {};
10390: }
10391: }
10392: }
10393: foreach my $udom (keys(%userdoms)) {
10394: if (!$got_rules->{$udom}) {
10395: my %domconfig = &Apache::lonnet::get_dom('configuration',
10396: ['usercreation'],$udom);
10397: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10398: foreach my $item ('username','id') {
10399: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10400: $$curr_rules{$udom}{$item} =
10401: $domconfig{'usercreation'}{$item.'_rule'};
10402: }
10403: }
10404: }
10405: $got_rules->{$udom} = 1;
10406: }
10407: }
10408: if ($checkid) {
10409: foreach my $udom (keys(%by_id)) {
10410: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10411: if ($outcome eq 'ok') {
10412: foreach my $id (keys(%{$by_id{$udom}})) {
10413: my $uname = $by_id{$udom}{$id};
10414: $inst_response{$uname.':'.$udom} = $outcome;
10415: }
10416: if (ref($results) eq 'HASH') {
10417: foreach my $uname (keys(%{$results})) {
10418: if (exists($inst_response{$uname.':'.$udom})) {
10419: $inst_response{$uname.':'.$udom} = $outcome;
10420: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10421: }
10422: }
10423: }
10424: }
1.612 raeburn 10425: }
1.615 raeburn 10426: } else {
1.1075.2.99 raeburn 10427: foreach my $udom (keys(%by_username)) {
10428: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10429: if ($outcome eq 'ok') {
10430: foreach my $uname (keys(%{$by_username{$udom}})) {
10431: $inst_response{$uname.':'.$udom} = $outcome;
10432: }
10433: if (ref($results) eq 'HASH') {
10434: foreach my $uname (keys(%{$results})) {
10435: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10436: }
10437: }
10438: }
10439: }
1.612 raeburn 10440: }
1.1075.2.99 raeburn 10441: } elsif (keys(%{$usershash}) == 1) {
10442: my $user = (keys(%{$usershash}))[0];
10443: my ($uname,$udom) = split(/:/,$user);
10444: if (($udom ne '') && ($uname ne '')) {
10445: if (ref($usershash->{$user}) eq 'HASH') {
10446: if (ref($checks) eq 'HASH') {
10447: if (defined($checks->{'username'})) {
10448: ($inst_response{$user},%{$inst_results->{$user}}) =
10449: &Apache::lonnet::get_instuser($udom,$uname);
10450: } elsif (defined($checks->{'id'})) {
10451: if ($usershash->{$user}->{'id'} ne '') {
10452: ($inst_response{$user},%{$inst_results->{$user}}) =
10453: &Apache::lonnet::get_instuser($udom,undef,
10454: $usershash->{$user}->{'id'});
10455: } else {
10456: ($inst_response{$user},%{$inst_results->{$user}}) =
10457: &Apache::lonnet::get_instuser($udom,$uname);
10458: }
10459: }
10460: } else {
10461: ($inst_response{$user},%{$inst_results->{$user}}) =
10462: &Apache::lonnet::get_instuser($udom,$uname);
10463: return;
10464: }
10465: if (!$got_rules->{$udom}) {
10466: my %domconfig = &Apache::lonnet::get_dom('configuration',
10467: ['usercreation'],$udom);
10468: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10469: foreach my $item ('username','id') {
10470: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10471: $$curr_rules{$udom}{$item} =
10472: $domconfig{'usercreation'}{$item.'_rule'};
10473: }
10474: }
1.585 raeburn 10475: }
1.1075.2.99 raeburn 10476: $got_rules->{$udom} = 1;
1.585 raeburn 10477: }
10478: }
1.1075.2.99 raeburn 10479: } else {
10480: return;
10481: }
10482: } else {
10483: return;
10484: }
10485: foreach my $user (keys(%{$usershash})) {
10486: my ($uname,$udom) = split(/:/,$user);
10487: next if (($udom eq '') || ($uname eq ''));
10488: my $id;
10489: if (ref($inst_results) eq 'HASH') {
10490: if (ref($inst_results->{$user}) eq 'HASH') {
10491: $id = $inst_results->{$user}->{'id'};
10492: }
10493: }
10494: if ($id eq '') {
10495: if (ref($usershash->{$user})) {
10496: $id = $usershash->{$user}->{'id'};
10497: }
1.585 raeburn 10498: }
1.612 raeburn 10499: foreach my $item (keys(%{$checks})) {
10500: if (ref($$curr_rules{$udom}) eq 'HASH') {
10501: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10502: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10503: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10504: $$curr_rules{$udom}{$item});
1.612 raeburn 10505: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10506: if ($rule_check{$rule}) {
10507: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10508: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10509: if (ref($inst_results) eq 'HASH') {
10510: if (ref($inst_results->{$user}) eq 'HASH') {
10511: if (keys(%{$inst_results->{$user}}) == 0) {
10512: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10513: } elsif ($item eq 'id') {
10514: if ($inst_results->{$user}->{'id'} eq '') {
10515: $$alerts{$item}{$udom}{$uname} = 1;
10516: }
1.615 raeburn 10517: }
1.612 raeburn 10518: }
10519: }
1.615 raeburn 10520: }
10521: last;
1.585 raeburn 10522: }
10523: }
10524: }
10525: }
10526: }
10527: }
10528: }
10529: }
1.612 raeburn 10530: return;
10531: }
10532:
10533: sub user_rule_formats {
10534: my ($domain,$domdesc,$curr_rules,$check) = @_;
10535: my %text = (
10536: 'username' => 'Usernames',
10537: 'id' => 'IDs',
10538: );
10539: my $output;
10540: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10541: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10542: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10543: $output = '<br />'.
10544: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10545: '<span class="LC_cusr_emph">','</span>',$domdesc).
10546: ' <ul>';
1.612 raeburn 10547: foreach my $rule (@{$ruleorder}) {
10548: if (ref($curr_rules) eq 'ARRAY') {
10549: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10550: if (ref($rules->{$rule}) eq 'HASH') {
10551: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10552: $rules->{$rule}{'desc'}.'</li>';
10553: }
10554: }
10555: }
10556: }
10557: $output .= '</ul>';
10558: }
10559: }
10560: return $output;
10561: }
10562:
10563: sub instrule_disallow_msg {
1.615 raeburn 10564: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10565: my $response;
10566: my %text = (
10567: item => 'username',
10568: items => 'usernames',
10569: match => 'matches',
10570: do => 'does',
10571: action => 'a username',
10572: one => 'one',
10573: );
10574: if ($count > 1) {
10575: $text{'item'} = 'usernames';
10576: $text{'match'} ='match';
10577: $text{'do'} = 'do';
10578: $text{'action'} = 'usernames',
10579: $text{'one'} = 'ones';
10580: }
10581: if ($checkitem eq 'id') {
10582: $text{'items'} = 'IDs';
10583: $text{'item'} = 'ID';
10584: $text{'action'} = 'an ID';
1.615 raeburn 10585: if ($count > 1) {
10586: $text{'item'} = 'IDs';
10587: $text{'action'} = 'IDs';
10588: }
1.612 raeburn 10589: }
1.674 bisitz 10590: $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 10591: if ($mode eq 'upload') {
10592: if ($checkitem eq 'username') {
10593: $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'}.");
10594: } elsif ($checkitem eq 'id') {
1.674 bisitz 10595: $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 10596: }
1.669 raeburn 10597: } elsif ($mode eq 'selfcreate') {
10598: if ($checkitem eq 'id') {
10599: $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.");
10600: }
1.615 raeburn 10601: } else {
10602: if ($checkitem eq 'username') {
10603: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10604: } elsif ($checkitem eq 'id') {
10605: $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.");
10606: }
1.612 raeburn 10607: }
10608: return $response;
1.585 raeburn 10609: }
10610:
1.624 raeburn 10611: sub personal_data_fieldtitles {
10612: my %fieldtitles = &Apache::lonlocal::texthash (
10613: id => 'Student/Employee ID',
10614: permanentemail => 'E-mail address',
10615: lastname => 'Last Name',
10616: firstname => 'First Name',
10617: middlename => 'Middle Name',
10618: generation => 'Generation',
10619: gen => 'Generation',
1.765 raeburn 10620: inststatus => 'Affiliation',
1.624 raeburn 10621: );
10622: return %fieldtitles;
10623: }
10624:
1.642 raeburn 10625: sub sorted_inst_types {
10626: my ($dom) = @_;
1.1075.2.70 raeburn 10627: my ($usertypes,$order);
10628: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10629: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10630: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10631: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10632: } else {
10633: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10634: }
1.642 raeburn 10635: my $othertitle = &mt('All users');
10636: if ($env{'request.course.id'}) {
1.668 raeburn 10637: $othertitle = &mt('Any users');
1.642 raeburn 10638: }
10639: my @types;
10640: if (ref($order) eq 'ARRAY') {
10641: @types = @{$order};
10642: }
10643: if (@types == 0) {
10644: if (ref($usertypes) eq 'HASH') {
10645: @types = sort(keys(%{$usertypes}));
10646: }
10647: }
10648: if (keys(%{$usertypes}) > 0) {
10649: $othertitle = &mt('Other users');
10650: }
10651: return ($othertitle,$usertypes,\@types);
10652: }
10653:
1.645 raeburn 10654: sub get_institutional_codes {
1.1075.2.157 raeburn 10655: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 10656: # Get complete list of course sections to update
10657: my @currsections = ();
10658: my @currxlists = ();
1.1075.2.157 raeburn 10659: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 10660: my $coursecode = $$settings{'internal.coursecode'};
1.1075.2.157 raeburn 10661: my $crskey = $crs.':'.$coursecode;
10662: @{$unclutteredsec{$crskey}} = ();
10663: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 10664:
10665: if ($$settings{'internal.sectionnums'} ne '') {
10666: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10667: }
10668:
10669: if ($$settings{'internal.crosslistings'} ne '') {
10670: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10671: }
10672:
10673: if (@currxlists > 0) {
1.1075.2.157 raeburn 10674: foreach my $xl (@currxlists) {
10675: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 10676: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10677: push(@{$allcourses},$1);
1.645 raeburn 10678: $$LC_code{$1} = $2;
10679: }
10680: }
10681: }
10682: }
1.1075.2.157 raeburn 10683:
1.645 raeburn 10684: if (@currsections > 0) {
1.1075.2.157 raeburn 10685: foreach my $sec (@currsections) {
10686: if ($sec =~ m/^(\w+):(\w*)$/ ) {
10687: my $instsec = $1;
1.645 raeburn 10688: my $lc_sec = $2;
1.1075.2.157 raeburn 10689: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
10690: push(@{$unclutteredsec{$crskey}},$instsec);
10691: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
10692: }
10693: }
10694: }
10695: }
10696:
10697: if (@{$unclutteredsec{$crskey}} > 0) {
10698: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
10699: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
10700: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
10701: my $sec = $coursecode.$formattedsec{$crskey}[$i];
10702: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1075.2.119 raeburn 10703: push(@{$allcourses},$sec);
1.1075.2.157 raeburn 10704: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 10705: }
10706: }
10707: }
10708: }
10709: return;
10710: }
10711:
1.971 raeburn 10712: sub get_standard_codeitems {
10713: return ('Year','Semester','Department','Number','Section');
10714: }
10715:
1.112 bowersj2 10716: =pod
10717:
1.780 raeburn 10718: =head1 Slot Helpers
10719:
10720: =over 4
10721:
10722: =item * sorted_slots()
10723:
1.1040 raeburn 10724: Sorts an array of slot names in order of an optional sort key,
10725: default sort is by slot start time (earliest first).
1.780 raeburn 10726:
10727: Inputs:
10728:
10729: =over 4
10730:
10731: slotsarr - Reference to array of unsorted slot names.
10732:
10733: slots - Reference to hash of hash, where outer hash keys are slot names.
10734:
1.1040 raeburn 10735: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10736:
1.549 albertel 10737: =back
10738:
1.780 raeburn 10739: Returns:
10740:
10741: =over 4
10742:
1.1040 raeburn 10743: sorted - An array of slot names sorted by a specified sort key
10744: (default sort key is start time of the slot).
1.780 raeburn 10745:
10746: =back
10747:
10748: =cut
10749:
10750:
10751: sub sorted_slots {
1.1040 raeburn 10752: my ($slotsarr,$slots,$sortkey) = @_;
10753: if ($sortkey eq '') {
10754: $sortkey = 'starttime';
10755: }
1.780 raeburn 10756: my @sorted;
10757: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10758: @sorted =
10759: sort {
10760: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10761: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10762: }
10763: if (ref($slots->{$a})) { return -1;}
10764: if (ref($slots->{$b})) { return 1;}
10765: return 0;
10766: } @{$slotsarr};
10767: }
10768: return @sorted;
10769: }
10770:
1.1040 raeburn 10771: =pod
10772:
10773: =item * get_future_slots()
10774:
10775: Inputs:
10776:
10777: =over 4
10778:
10779: cnum - course number
10780:
10781: cdom - course domain
10782:
10783: now - current UNIX time
10784:
10785: symb - optional symb
10786:
10787: =back
10788:
10789: Returns:
10790:
10791: =over 4
10792:
10793: sorted_reservable - ref to array of student_schedulable slots currently
10794: reservable, ordered by end date of reservation period.
10795:
10796: reservable_now - ref to hash of student_schedulable slots currently
10797: reservable.
10798:
10799: Keys in inner hash are:
10800: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10801: (b) endreserve: end date of reservation period.
10802: (c) uniqueperiod: start,end dates when slot is to be uniquely
10803: selected.
1.1040 raeburn 10804:
10805: sorted_future - ref to array of student_schedulable slots reservable in
10806: the future, ordered by start date of reservation period.
10807:
10808: future_reservable - ref to hash of student_schedulable slots reservable
10809: in the future.
10810:
10811: Keys in inner hash are:
10812: (a) symb: either blank or symb to which slot use is restricted.
10813: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10814: (c) uniqueperiod: start,end dates when slot is to be uniquely
10815: selected.
1.1040 raeburn 10816:
10817: =back
10818:
10819: =cut
10820:
10821: sub get_future_slots {
10822: my ($cnum,$cdom,$now,$symb) = @_;
10823: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10824: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10825: foreach my $slot (keys(%slots)) {
10826: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10827: if ($symb) {
10828: next if (($slots{$slot}->{'symb'} ne '') &&
10829: ($slots{$slot}->{'symb'} ne $symb));
10830: }
10831: if (($slots{$slot}->{'starttime'} > $now) &&
10832: ($slots{$slot}->{'endtime'} > $now)) {
10833: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10834: my $userallowed = 0;
10835: if ($slots{$slot}->{'allowedsections'}) {
10836: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10837: if (!defined($env{'request.role.sec'})
10838: && grep(/^No section assigned$/,@allowed_sec)) {
10839: $userallowed=1;
10840: } else {
10841: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10842: $userallowed=1;
10843: }
10844: }
10845: unless ($userallowed) {
10846: if (defined($env{'request.course.groups'})) {
10847: my @groups = split(/:/,$env{'request.course.groups'});
10848: foreach my $group (@groups) {
10849: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10850: $userallowed=1;
10851: last;
10852: }
10853: }
10854: }
10855: }
10856: }
10857: if ($slots{$slot}->{'allowedusers'}) {
10858: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10859: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10860: if (grep(/^\Q$user\E$/,@allowed_users)) {
10861: $userallowed = 1;
10862: }
10863: }
10864: next unless($userallowed);
10865: }
10866: my $startreserve = $slots{$slot}->{'startreserve'};
10867: my $endreserve = $slots{$slot}->{'endreserve'};
10868: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10869: my $uniqueperiod;
10870: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10871: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10872: }
1.1040 raeburn 10873: if (($startreserve < $now) &&
10874: (!$endreserve || $endreserve > $now)) {
10875: my $lastres = $endreserve;
10876: if (!$lastres) {
10877: $lastres = $slots{$slot}->{'starttime'};
10878: }
10879: $reservable_now{$slot} = {
10880: symb => $symb,
1.1075.2.104 raeburn 10881: endreserve => $lastres,
10882: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10883: };
10884: } elsif (($startreserve > $now) &&
10885: (!$endreserve || $endreserve > $startreserve)) {
10886: $future_reservable{$slot} = {
10887: symb => $symb,
1.1075.2.104 raeburn 10888: startreserve => $startreserve,
10889: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10890: };
10891: }
10892: }
10893: }
10894: my @unsorted_reservable = keys(%reservable_now);
10895: if (@unsorted_reservable > 0) {
10896: @sorted_reservable =
10897: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10898: }
10899: my @unsorted_future = keys(%future_reservable);
10900: if (@unsorted_future > 0) {
10901: @sorted_future =
10902: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10903: }
10904: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10905: }
1.780 raeburn 10906:
10907: =pod
10908:
1.1057 foxr 10909: =back
10910:
1.549 albertel 10911: =head1 HTTP Helpers
10912:
10913: =over 4
10914:
1.648 raeburn 10915: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10916:
1.258 albertel 10917: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10918: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10919: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10920:
10921: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10922: $possible_names is an ref to an array of form element names. As an example:
10923: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10924: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10925:
10926: =cut
1.1 albertel 10927:
1.6 albertel 10928: sub get_unprocessed_cgi {
1.25 albertel 10929: my ($query,$possible_names)= @_;
1.26 matthew 10930: # $Apache::lonxml::debug=1;
1.356 albertel 10931: foreach my $pair (split(/&/,$query)) {
10932: my ($name, $value) = split(/=/,$pair);
1.369 www 10933: $name = &unescape($name);
1.25 albertel 10934: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10935: $value =~ tr/+/ /;
10936: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10937: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10938: }
1.16 harris41 10939: }
1.6 albertel 10940: }
10941:
1.112 bowersj2 10942: =pod
10943:
1.648 raeburn 10944: =item * &cacheheader()
1.112 bowersj2 10945:
10946: returns cache-controlling header code
10947:
10948: =cut
10949:
1.7 albertel 10950: sub cacheheader {
1.258 albertel 10951: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10952: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10953: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10954: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10955: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10956: return $output;
1.7 albertel 10957: }
10958:
1.112 bowersj2 10959: =pod
10960:
1.648 raeburn 10961: =item * &no_cache($r)
1.112 bowersj2 10962:
10963: specifies header code to not have cache
10964:
10965: =cut
10966:
1.9 albertel 10967: sub no_cache {
1.216 albertel 10968: my ($r) = @_;
10969: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10970: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10971: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10972: $r->no_cache(1);
10973: $r->header_out("Expires" => $date);
10974: $r->header_out("Pragma" => "no-cache");
1.123 www 10975: }
10976:
10977: sub content_type {
1.181 albertel 10978: my ($r,$type,$charset) = @_;
1.299 foxr 10979: if ($r) {
10980: # Note that printout.pl calls this with undef for $r.
10981: &no_cache($r);
10982: }
1.258 albertel 10983: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10984: unless ($charset) {
10985: $charset=&Apache::lonlocal::current_encoding;
10986: }
10987: if ($charset) { $type.='; charset='.$charset; }
10988: if ($r) {
10989: $r->content_type($type);
10990: } else {
10991: print("Content-type: $type\n\n");
10992: }
1.9 albertel 10993: }
1.25 albertel 10994:
1.112 bowersj2 10995: =pod
10996:
1.648 raeburn 10997: =item * &add_to_env($name,$value)
1.112 bowersj2 10998:
1.258 albertel 10999: adds $name to the %env hash with value
1.112 bowersj2 11000: $value, if $name already exists, the entry is converted to an array
11001: reference and $value is added to the array.
11002:
11003: =cut
11004:
1.25 albertel 11005: sub add_to_env {
11006: my ($name,$value)=@_;
1.258 albertel 11007: if (defined($env{$name})) {
11008: if (ref($env{$name})) {
1.25 albertel 11009: #already have multiple values
1.258 albertel 11010: push(@{ $env{$name} },$value);
1.25 albertel 11011: } else {
11012: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11013: my $first=$env{$name};
11014: undef($env{$name});
11015: push(@{ $env{$name} },$first,$value);
1.25 albertel 11016: }
11017: } else {
1.258 albertel 11018: $env{$name}=$value;
1.25 albertel 11019: }
1.31 albertel 11020: }
1.149 albertel 11021:
11022: =pod
11023:
1.648 raeburn 11024: =item * &get_env_multiple($name)
1.149 albertel 11025:
1.258 albertel 11026: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11027: values may be defined and end up as an array ref.
11028:
11029: returns an array of values
11030:
11031: =cut
11032:
11033: sub get_env_multiple {
11034: my ($name) = @_;
11035: my @values;
1.258 albertel 11036: if (defined($env{$name})) {
1.149 albertel 11037: # exists is it an array
1.258 albertel 11038: if (ref($env{$name})) {
11039: @values=@{ $env{$name} };
1.149 albertel 11040: } else {
1.258 albertel 11041: $values[0]=$env{$name};
1.149 albertel 11042: }
11043: }
11044: return(@values);
11045: }
11046:
1.660 raeburn 11047: sub ask_for_embedded_content {
11048: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11049: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 11050: %currsubfile,%unused,$rem);
1.1071 raeburn 11051: my $counter = 0;
11052: my $numnew = 0;
1.987 raeburn 11053: my $numremref = 0;
11054: my $numinvalid = 0;
11055: my $numpathchg = 0;
11056: my $numexisting = 0;
1.1071 raeburn 11057: my $numunused = 0;
11058: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 11059: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11060: my $heading = &mt('Upload embedded files');
11061: my $buttontext = &mt('Upload');
11062:
1.1075.2.11 raeburn 11063: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 11064: if ($actionurl eq '/adm/dependencies') {
11065: $navmap = Apache::lonnavmaps::navmap->new();
11066: }
11067: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11068: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 11069: }
1.1075.2.35 raeburn 11070: if (($actionurl eq '/adm/portfolio') ||
11071: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11072: my $current_path='/';
11073: if ($env{'form.currentpath'}) {
11074: $current_path = $env{'form.currentpath'};
11075: }
11076: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 11077: $udom = $cdom;
11078: $uname = $cnum;
1.984 raeburn 11079: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11080: } else {
11081: $udom = $env{'user.domain'};
11082: $uname = $env{'user.name'};
11083: $url = '/userfiles/portfolio';
11084: }
1.987 raeburn 11085: $toplevel = $url.'/';
1.984 raeburn 11086: $url .= $current_path;
11087: $getpropath = 1;
1.987 raeburn 11088: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11089: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11090: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11091: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11092: $toplevel = $url;
1.984 raeburn 11093: if ($rest ne '') {
1.987 raeburn 11094: $url .= $rest;
11095: }
11096: } elsif ($actionurl eq '/adm/coursedocs') {
11097: if (ref($args) eq 'HASH') {
1.1071 raeburn 11098: $url = $args->{'docs_url'};
11099: $toplevel = $url;
1.1075.2.11 raeburn 11100: if ($args->{'context'} eq 'paste') {
11101: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11102: ($path) =
11103: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11104: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11105: $fileloc =~ s{^/}{};
11106: }
1.1071 raeburn 11107: }
11108: } elsif ($actionurl eq '/adm/dependencies') {
11109: if ($env{'request.course.id'} ne '') {
11110: if (ref($args) eq 'HASH') {
11111: $url = $args->{'docs_url'};
11112: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 11113: $toplevel = $url;
11114: unless ($toplevel =~ m{^/}) {
11115: $toplevel = "/$url";
11116: }
1.1075.2.11 raeburn 11117: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 11118: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11119: $path = $1;
11120: } else {
11121: ($path) =
11122: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11123: }
1.1075.2.79 raeburn 11124: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11125: $fileloc = $toplevel;
11126: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11127: my ($udom,$uname,$fname) =
11128: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11129: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11130: } else {
11131: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11132: }
1.1071 raeburn 11133: $fileloc =~ s{^/}{};
11134: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11135: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11136: }
1.987 raeburn 11137: }
1.1075.2.35 raeburn 11138: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11139: $udom = $cdom;
11140: $uname = $cnum;
11141: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11142: $toplevel = $url;
11143: $path = $url;
11144: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11145: $fileloc =~ s{^/}{};
11146: }
11147: foreach my $file (keys(%{$allfiles})) {
11148: my $embed_file;
11149: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11150: $embed_file = $1;
11151: } else {
11152: $embed_file = $file;
11153: }
1.1075.2.55 raeburn 11154: my ($absolutepath,$cleaned_file);
11155: if ($embed_file =~ m{^\w+://}) {
11156: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 11157: $newfiles{$cleaned_file} = 1;
11158: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11159: } else {
1.1075.2.55 raeburn 11160: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11161: if ($embed_file =~ m{^/}) {
11162: $absolutepath = $embed_file;
11163: }
1.1075.2.47 raeburn 11164: if ($cleaned_file =~ m{/}) {
11165: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11166: $path = &check_for_traversal($path,$url,$toplevel);
11167: my $item = $fname;
11168: if ($path ne '') {
11169: $item = $path.'/'.$fname;
11170: $subdependencies{$path}{$fname} = 1;
11171: } else {
11172: $dependencies{$item} = 1;
11173: }
11174: if ($absolutepath) {
11175: $mapping{$item} = $absolutepath;
11176: } else {
11177: $mapping{$item} = $embed_file;
11178: }
11179: } else {
11180: $dependencies{$embed_file} = 1;
11181: if ($absolutepath) {
1.1075.2.47 raeburn 11182: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11183: } else {
1.1075.2.47 raeburn 11184: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11185: }
11186: }
1.984 raeburn 11187: }
11188: }
1.1071 raeburn 11189: my $dirptr = 16384;
1.984 raeburn 11190: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11191: $currsubfile{$path} = {};
1.1075.2.35 raeburn 11192: if (($actionurl eq '/adm/portfolio') ||
11193: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11194: my ($sublistref,$listerror) =
11195: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11196: if (ref($sublistref) eq 'ARRAY') {
11197: foreach my $line (@{$sublistref}) {
11198: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11199: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11200: }
1.984 raeburn 11201: }
1.987 raeburn 11202: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11203: if (opendir(my $dir,$url.'/'.$path)) {
11204: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11205: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11206: }
1.1075.2.11 raeburn 11207: } elsif (($actionurl eq '/adm/dependencies') ||
11208: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11209: ($args->{'context'} eq 'paste')) ||
11210: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11211: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 11212: my $dir;
11213: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11214: $dir = $fileloc;
11215: } else {
11216: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11217: }
1.1071 raeburn 11218: if ($dir ne '') {
11219: my ($sublistref,$listerror) =
11220: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11221: if (ref($sublistref) eq 'ARRAY') {
11222: foreach my $line (@{$sublistref}) {
11223: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11224: undef,$mtime)=split(/\&/,$line,12);
11225: unless (($testdir&$dirptr) ||
11226: ($file_name =~ /^\.\.?$/)) {
11227: $currsubfile{$path}{$file_name} = [$size,$mtime];
11228: }
11229: }
11230: }
11231: }
1.984 raeburn 11232: }
11233: }
11234: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11235: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11236: my $item = $path.'/'.$file;
11237: unless ($mapping{$item} eq $item) {
11238: $pathchanges{$item} = 1;
11239: }
11240: $existing{$item} = 1;
11241: $numexisting ++;
11242: } else {
11243: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11244: }
11245: }
1.1071 raeburn 11246: if ($actionurl eq '/adm/dependencies') {
11247: foreach my $path (keys(%currsubfile)) {
11248: if (ref($currsubfile{$path}) eq 'HASH') {
11249: foreach my $file (keys(%{$currsubfile{$path}})) {
11250: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 11251: next if (($rem ne '') &&
11252: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11253: (ref($navmap) &&
11254: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11255: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11256: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11257: $unused{$path.'/'.$file} = 1;
11258: }
11259: }
11260: }
11261: }
11262: }
1.984 raeburn 11263: }
1.987 raeburn 11264: my %currfile;
1.1075.2.35 raeburn 11265: if (($actionurl eq '/adm/portfolio') ||
11266: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11267: my ($dirlistref,$listerror) =
11268: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11269: if (ref($dirlistref) eq 'ARRAY') {
11270: foreach my $line (@{$dirlistref}) {
11271: my ($file_name,$rest) = split(/\&/,$line,2);
11272: $currfile{$file_name} = 1;
11273: }
1.984 raeburn 11274: }
1.987 raeburn 11275: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11276: if (opendir(my $dir,$url)) {
1.987 raeburn 11277: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11278: map {$currfile{$_} = 1;} @dir_list;
11279: }
1.1075.2.11 raeburn 11280: } elsif (($actionurl eq '/adm/dependencies') ||
11281: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11282: ($args->{'context'} eq 'paste')) ||
11283: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11284: if ($env{'request.course.id'} ne '') {
11285: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11286: if ($dir ne '') {
11287: my ($dirlistref,$listerror) =
11288: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11289: if (ref($dirlistref) eq 'ARRAY') {
11290: foreach my $line (@{$dirlistref}) {
11291: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11292: $size,undef,$mtime)=split(/\&/,$line,12);
11293: unless (($testdir&$dirptr) ||
11294: ($file_name =~ /^\.\.?$/)) {
11295: $currfile{$file_name} = [$size,$mtime];
11296: }
11297: }
11298: }
11299: }
11300: }
1.984 raeburn 11301: }
11302: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11303: if (exists($currfile{$file})) {
1.987 raeburn 11304: unless ($mapping{$file} eq $file) {
11305: $pathchanges{$file} = 1;
11306: }
11307: $existing{$file} = 1;
11308: $numexisting ++;
11309: } else {
1.984 raeburn 11310: $newfiles{$file} = 1;
11311: }
11312: }
1.1071 raeburn 11313: foreach my $file (keys(%currfile)) {
11314: unless (($file eq $filename) ||
11315: ($file eq $filename.'.bak') ||
11316: ($dependencies{$file})) {
1.1075.2.11 raeburn 11317: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 11318: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11319: next if (($rem ne '') &&
11320: (($env{"httpref.$rem".$file} ne '') ||
11321: (ref($navmap) &&
11322: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11323: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11324: ($navmap->getResourceByUrl($rem.$1)))))));
11325: }
1.1075.2.11 raeburn 11326: }
1.1071 raeburn 11327: $unused{$file} = 1;
11328: }
11329: }
1.1075.2.11 raeburn 11330: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11331: ($args->{'context'} eq 'paste')) {
11332: $counter = scalar(keys(%existing));
11333: $numpathchg = scalar(keys(%pathchanges));
11334: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 11335: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11336: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11337: $counter = scalar(keys(%existing));
11338: $numpathchg = scalar(keys(%pathchanges));
11339: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 11340: }
1.984 raeburn 11341: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11342: if ($actionurl eq '/adm/dependencies') {
11343: next if ($embed_file =~ m{^\w+://});
11344: }
1.660 raeburn 11345: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11346: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11347: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11348: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 11349: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11350: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11351: }
1.1075.2.35 raeburn 11352: $upload_output .= '</td>';
1.1071 raeburn 11353: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 11354: $upload_output.='<td align="right">'.
11355: '<span class="LC_info LC_fontsize_medium">'.
11356: &mt("URL points to web address").'</span>';
1.987 raeburn 11357: $numremref++;
1.660 raeburn 11358: } elsif ($args->{'error_on_invalid_names'}
11359: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 11360: $upload_output.='<td align="right"><span class="LC_warning">'.
11361: &mt('Invalid characters').'</span>';
1.987 raeburn 11362: $numinvalid++;
1.660 raeburn 11363: } else {
1.1075.2.35 raeburn 11364: $upload_output .= '<td>'.
11365: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11366: $embed_file,\%mapping,
1.1071 raeburn 11367: $allfiles,$codebase,'upload');
11368: $counter ++;
11369: $numnew ++;
1.987 raeburn 11370: }
11371: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11372: }
11373: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11374: if ($actionurl eq '/adm/dependencies') {
11375: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11376: $modify_output .= &start_data_table_row().
11377: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11378: '<img src="'.&icon($embed_file).'" border="0" />'.
11379: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11380: '<td>'.$size.'</td>'.
11381: '<td>'.$mtime.'</td>'.
11382: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11383: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11384: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11385: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11386: &embedded_file_element('upload_embedded',$counter,
11387: $embed_file,\%mapping,
11388: $allfiles,$codebase,'modify').
11389: '</div></td>'.
11390: &end_data_table_row()."\n";
11391: $counter ++;
11392: } else {
11393: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11394: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11395: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11396: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11397: &Apache::loncommon::end_data_table_row()."\n";
11398: }
11399: }
11400: my $delidx = $counter;
11401: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11402: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11403: $delete_output .= &start_data_table_row().
11404: '<td><img src="'.&icon($oldfile).'" />'.
11405: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11406: '<td>'.$size.'</td>'.
11407: '<td>'.$mtime.'</td>'.
11408: '<td><label><input type="checkbox" name="del_upload_dep" '.
11409: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11410: &embedded_file_element('upload_embedded',$delidx,
11411: $oldfile,\%mapping,$allfiles,
11412: $codebase,'delete').'</td>'.
11413: &end_data_table_row()."\n";
11414: $numunused ++;
11415: $delidx ++;
1.987 raeburn 11416: }
11417: if ($upload_output) {
11418: $upload_output = &start_data_table().
11419: $upload_output.
11420: &end_data_table()."\n";
11421: }
1.1071 raeburn 11422: if ($modify_output) {
11423: $modify_output = &start_data_table().
11424: &start_data_table_header_row().
11425: '<th>'.&mt('File').'</th>'.
11426: '<th>'.&mt('Size (KB)').'</th>'.
11427: '<th>'.&mt('Modified').'</th>'.
11428: '<th>'.&mt('Upload replacement?').'</th>'.
11429: &end_data_table_header_row().
11430: $modify_output.
11431: &end_data_table()."\n";
11432: }
11433: if ($delete_output) {
11434: $delete_output = &start_data_table().
11435: &start_data_table_header_row().
11436: '<th>'.&mt('File').'</th>'.
11437: '<th>'.&mt('Size (KB)').'</th>'.
11438: '<th>'.&mt('Modified').'</th>'.
11439: '<th>'.&mt('Delete?').'</th>'.
11440: &end_data_table_header_row().
11441: $delete_output.
11442: &end_data_table()."\n";
11443: }
1.987 raeburn 11444: my $applies = 0;
11445: if ($numremref) {
11446: $applies ++;
11447: }
11448: if ($numinvalid) {
11449: $applies ++;
11450: }
11451: if ($numexisting) {
11452: $applies ++;
11453: }
1.1071 raeburn 11454: if ($counter || $numunused) {
1.987 raeburn 11455: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11456: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11457: $state.'<h3>'.$heading.'</h3>';
11458: if ($actionurl eq '/adm/dependencies') {
11459: if ($numnew) {
11460: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11461: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11462: $upload_output.'<br />'."\n";
11463: }
11464: if ($numexisting) {
11465: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11466: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11467: $modify_output.'<br />'."\n";
11468: $buttontext = &mt('Save changes');
11469: }
11470: if ($numunused) {
11471: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11472: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11473: $delete_output.'<br />'."\n";
11474: $buttontext = &mt('Save changes');
11475: }
11476: } else {
11477: $output .= $upload_output.'<br />'."\n";
11478: }
11479: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11480: $counter.'" />'."\n";
11481: if ($actionurl eq '/adm/dependencies') {
11482: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11483: $numnew.'" />'."\n";
11484: } elsif ($actionurl eq '') {
1.987 raeburn 11485: $output .= '<input type="hidden" name="phase" value="three" />';
11486: }
11487: } elsif ($applies) {
11488: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11489: if ($applies > 1) {
11490: $output .=
1.1075.2.35 raeburn 11491: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11492: if ($numremref) {
11493: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11494: }
11495: if ($numinvalid) {
11496: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11497: }
11498: if ($numexisting) {
11499: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11500: }
11501: $output .= '</ul><br />';
11502: } elsif ($numremref) {
11503: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11504: } elsif ($numinvalid) {
11505: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11506: } elsif ($numexisting) {
11507: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11508: }
11509: $output .= $upload_output.'<br />';
11510: }
11511: my ($pathchange_output,$chgcount);
1.1071 raeburn 11512: $chgcount = $counter;
1.987 raeburn 11513: if (keys(%pathchanges) > 0) {
11514: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11515: if ($counter) {
1.987 raeburn 11516: $output .= &embedded_file_element('pathchange',$chgcount,
11517: $embed_file,\%mapping,
1.1071 raeburn 11518: $allfiles,$codebase,'change');
1.987 raeburn 11519: } else {
11520: $pathchange_output .=
11521: &start_data_table_row().
11522: '<td><input type ="checkbox" name="namechange" value="'.
11523: $chgcount.'" checked="checked" /></td>'.
11524: '<td>'.$mapping{$embed_file}.'</td>'.
11525: '<td>'.$embed_file.
11526: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11527: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11528: '</td>'.&end_data_table_row();
1.660 raeburn 11529: }
1.987 raeburn 11530: $numpathchg ++;
11531: $chgcount ++;
1.660 raeburn 11532: }
11533: }
1.1075.2.35 raeburn 11534: if (($counter) || ($numunused)) {
1.987 raeburn 11535: if ($numpathchg) {
11536: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11537: $numpathchg.'" />'."\n";
11538: }
11539: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11540: ($actionurl eq '/adm/imsimport')) {
11541: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11542: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11543: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11544: } elsif ($actionurl eq '/adm/dependencies') {
11545: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11546: }
1.1075.2.35 raeburn 11547: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11548: } elsif ($numpathchg) {
11549: my %pathchange = ();
11550: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11551: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11552: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11553: }
1.987 raeburn 11554: }
1.1071 raeburn 11555: return ($output,$counter,$numpathchg);
1.987 raeburn 11556: }
11557:
1.1075.2.47 raeburn 11558: =pod
11559:
11560: =item * clean_path($name)
11561:
11562: Performs clean-up of directories, subdirectories and filename in an
11563: embedded object, referenced in an HTML file which is being uploaded
11564: to a course or portfolio, where
11565: "Upload embedded images/multimedia files if HTML file" checkbox was
11566: checked.
11567:
11568: Clean-up is similar to replacements in lonnet::clean_filename()
11569: except each / between sub-directory and next level is preserved.
11570:
11571: =cut
11572:
11573: sub clean_path {
11574: my ($embed_file) = @_;
11575: $embed_file =~s{^/+}{};
11576: my @contents;
11577: if ($embed_file =~ m{/}) {
11578: @contents = split(/\//,$embed_file);
11579: } else {
11580: @contents = ($embed_file);
11581: }
11582: my $lastidx = scalar(@contents)-1;
11583: for (my $i=0; $i<=$lastidx; $i++) {
11584: $contents[$i]=~s{\\}{/}g;
11585: $contents[$i]=~s/\s+/\_/g;
11586: $contents[$i]=~s{[^/\w\.\-]}{}g;
11587: if ($i == $lastidx) {
11588: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11589: }
11590: }
11591: if ($lastidx > 0) {
11592: return join('/',@contents);
11593: } else {
11594: return $contents[0];
11595: }
11596: }
11597:
1.987 raeburn 11598: sub embedded_file_element {
1.1071 raeburn 11599: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11600: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11601: (ref($codebase) eq 'HASH'));
11602: my $output;
1.1071 raeburn 11603: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11604: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11605: }
11606: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11607: &escape($embed_file).'" />';
11608: unless (($context eq 'upload_embedded') &&
11609: ($mapping->{$embed_file} eq $embed_file)) {
11610: $output .='
11611: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11612: }
11613: my $attrib;
11614: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11615: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11616: }
11617: $output .=
11618: "\n\t\t".
11619: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11620: $attrib.'" />';
11621: if (exists($codebase->{$mapping->{$embed_file}})) {
11622: $output .=
11623: "\n\t\t".
11624: '<input name="codebase_'.$num.'" type="hidden" value="'.
11625: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11626: }
1.987 raeburn 11627: return $output;
1.660 raeburn 11628: }
11629:
1.1071 raeburn 11630: sub get_dependency_details {
11631: my ($currfile,$currsubfile,$embed_file) = @_;
11632: my ($size,$mtime,$showsize,$showmtime);
11633: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11634: if ($embed_file =~ m{/}) {
11635: my ($path,$fname) = split(/\//,$embed_file);
11636: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11637: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11638: }
11639: } else {
11640: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11641: ($size,$mtime) = @{$currfile->{$embed_file}};
11642: }
11643: }
11644: $showsize = $size/1024.0;
11645: $showsize = sprintf("%.1f",$showsize);
11646: if ($mtime > 0) {
11647: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11648: }
11649: }
11650: return ($showsize,$showmtime);
11651: }
11652:
11653: sub ask_embedded_js {
11654: return <<"END";
11655: <script type="text/javascript"">
11656: // <![CDATA[
11657: function toggleBrowse(counter) {
11658: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11659: var fileid = document.getElementById('embedded_item_'+counter);
11660: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11661: if (chkboxid.checked == true) {
11662: uploaddivid.style.display='block';
11663: } else {
11664: uploaddivid.style.display='none';
11665: fileid.value = '';
11666: }
11667: }
11668: // ]]>
11669: </script>
11670:
11671: END
11672: }
11673:
1.661 raeburn 11674: sub upload_embedded {
11675: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11676: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11677: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11678: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11679: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11680: my $orig_uploaded_filename =
11681: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11682: foreach my $type ('orig','ref','attrib','codebase') {
11683: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11684: $env{'form.embedded_'.$type.'_'.$i} =
11685: &unescape($env{'form.embedded_'.$type.'_'.$i});
11686: }
11687: }
1.661 raeburn 11688: my ($path,$fname) =
11689: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11690: # no path, whole string is fname
11691: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11692: $fname = &Apache::lonnet::clean_filename($fname);
11693: # See if there is anything left
11694: next if ($fname eq '');
11695:
11696: # Check if file already exists as a file or directory.
11697: my ($state,$msg);
11698: if ($context eq 'portfolio') {
11699: my $port_path = $dirpath;
11700: if ($group ne '') {
11701: $port_path = "groups/$group/$port_path";
11702: }
1.987 raeburn 11703: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11704: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11705: $dir_root,$port_path,$disk_quota,
11706: $current_disk_usage,$uname,$udom);
11707: if ($state eq 'will_exceed_quota'
1.984 raeburn 11708: || $state eq 'file_locked') {
1.661 raeburn 11709: $output .= $msg;
11710: next;
11711: }
11712: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11713: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11714: if ($state eq 'exists') {
11715: $output .= $msg;
11716: next;
11717: }
11718: }
11719: # Check if extension is valid
11720: if (($fname =~ /\.(\w+)$/) &&
11721: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11722: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11723: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11724: next;
11725: } elsif (($fname =~ /\.(\w+)$/) &&
11726: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11727: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11728: next;
11729: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11730: $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 11731: next;
11732: }
11733: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11734: my $subdir = $path;
11735: $subdir =~ s{/+$}{};
1.661 raeburn 11736: if ($context eq 'portfolio') {
1.984 raeburn 11737: my $result;
11738: if ($state eq 'existingfile') {
11739: $result=
11740: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11741: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11742: } else {
1.984 raeburn 11743: $result=
11744: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11745: $dirpath.
1.1075.2.35 raeburn 11746: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11747: if ($result !~ m|^/uploaded/|) {
11748: $output .= '<span class="LC_error">'
11749: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11750: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11751: .'</span><br />';
11752: next;
11753: } else {
1.987 raeburn 11754: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11755: $path.$fname.'</span>').'<br />';
1.984 raeburn 11756: }
1.661 raeburn 11757: }
1.1075.2.35 raeburn 11758: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11759: my $extendedsubdir = $dirpath.'/'.$subdir;
11760: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11761: my $result =
1.1075.2.35 raeburn 11762: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11763: if ($result !~ m|^/uploaded/|) {
11764: $output .= '<span class="LC_error">'
11765: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11766: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11767: .'</span><br />';
11768: next;
11769: } else {
11770: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11771: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11772: if ($context eq 'syllabus') {
11773: &Apache::lonnet::make_public_indefinitely($result);
11774: }
1.987 raeburn 11775: }
1.661 raeburn 11776: } else {
11777: # Save the file
11778: my $target = $env{'form.embedded_item_'.$i};
11779: my $fullpath = $dir_root.$dirpath.'/'.$path;
11780: my $dest = $fullpath.$fname;
11781: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11782: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11783: my $count;
11784: my $filepath = $dir_root;
1.1027 raeburn 11785: foreach my $subdir (@parts) {
11786: $filepath .= "/$subdir";
11787: if (!-e $filepath) {
1.661 raeburn 11788: mkdir($filepath,0770);
11789: }
11790: }
11791: my $fh;
11792: if (!open($fh,'>'.$dest)) {
11793: &Apache::lonnet::logthis('Failed to create '.$dest);
11794: $output .= '<span class="LC_error">'.
1.1071 raeburn 11795: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11796: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11797: '</span><br />';
11798: } else {
11799: if (!print $fh $env{'form.embedded_item_'.$i}) {
11800: &Apache::lonnet::logthis('Failed to write to '.$dest);
11801: $output .= '<span class="LC_error">'.
1.1071 raeburn 11802: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11803: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11804: '</span><br />';
11805: } else {
1.987 raeburn 11806: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11807: $url.'</span>').'<br />';
11808: unless ($context eq 'testbank') {
11809: $footer .= &mt('View embedded file: [_1]',
11810: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11811: }
11812: }
11813: close($fh);
11814: }
11815: }
11816: if ($env{'form.embedded_ref_'.$i}) {
11817: $pathchange{$i} = 1;
11818: }
11819: }
11820: if ($output) {
11821: $output = '<p>'.$output.'</p>';
11822: }
11823: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11824: $returnflag = 'ok';
1.1071 raeburn 11825: my $numpathchgs = scalar(keys(%pathchange));
11826: if ($numpathchgs > 0) {
1.987 raeburn 11827: if ($context eq 'portfolio') {
11828: $output .= '<p>'.&mt('or').'</p>';
11829: } elsif ($context eq 'testbank') {
1.1071 raeburn 11830: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11831: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11832: $returnflag = 'modify_orightml';
11833: }
11834: }
1.1071 raeburn 11835: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11836: }
11837:
11838: sub modify_html_form {
11839: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11840: my $end = 0;
11841: my $modifyform;
11842: if ($context eq 'upload_embedded') {
11843: return unless (ref($pathchange) eq 'HASH');
11844: if ($env{'form.number_embedded_items'}) {
11845: $end += $env{'form.number_embedded_items'};
11846: }
11847: if ($env{'form.number_pathchange_items'}) {
11848: $end += $env{'form.number_pathchange_items'};
11849: }
11850: if ($end) {
11851: for (my $i=0; $i<$end; $i++) {
11852: if ($i < $env{'form.number_embedded_items'}) {
11853: next unless($pathchange->{$i});
11854: }
11855: $modifyform .=
11856: &start_data_table_row().
11857: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11858: 'checked="checked" /></td>'.
11859: '<td>'.$env{'form.embedded_ref_'.$i}.
11860: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11861: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11862: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11863: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11864: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11865: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11866: '<td>'.$env{'form.embedded_orig_'.$i}.
11867: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11868: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11869: &end_data_table_row();
1.1071 raeburn 11870: }
1.987 raeburn 11871: }
11872: } else {
11873: $modifyform = $pathchgtable;
11874: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11875: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11876: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11877: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11878: }
11879: }
11880: if ($modifyform) {
1.1071 raeburn 11881: if ($actionurl eq '/adm/dependencies') {
11882: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11883: }
1.987 raeburn 11884: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11885: '<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".
11886: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11887: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11888: '</ol></p>'."\n".'<p>'.
11889: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11890: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11891: &start_data_table()."\n".
11892: &start_data_table_header_row().
11893: '<th>'.&mt('Change?').'</th>'.
11894: '<th>'.&mt('Current reference').'</th>'.
11895: '<th>'.&mt('Required reference').'</th>'.
11896: &end_data_table_header_row()."\n".
11897: $modifyform.
11898: &end_data_table().'<br />'."\n".$hiddenstate.
11899: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11900: '</form>'."\n";
11901: }
11902: return;
11903: }
11904:
11905: sub modify_html_refs {
1.1075.2.35 raeburn 11906: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11907: my $container;
11908: if ($context eq 'portfolio') {
11909: $container = $env{'form.container'};
11910: } elsif ($context eq 'coursedoc') {
11911: $container = $env{'form.primaryurl'};
1.1071 raeburn 11912: } elsif ($context eq 'manage_dependencies') {
11913: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11914: $container = "/$container";
1.1075.2.35 raeburn 11915: } elsif ($context eq 'syllabus') {
11916: $container = $url;
1.987 raeburn 11917: } else {
1.1027 raeburn 11918: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11919: }
11920: my (%allfiles,%codebase,$output,$content);
11921: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11922: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11923: if (wantarray) {
11924: return ('',0,0);
11925: } else {
11926: return;
11927: }
11928: }
11929: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11930: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11931: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11932: if (wantarray) {
11933: return ('',0,0);
11934: } else {
11935: return;
11936: }
11937: }
1.987 raeburn 11938: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11939: if ($content eq '-1') {
11940: if (wantarray) {
11941: return ('',0,0);
11942: } else {
11943: return;
11944: }
11945: }
1.987 raeburn 11946: } else {
1.1071 raeburn 11947: unless ($container =~ /^\Q$dir_root\E/) {
11948: if (wantarray) {
11949: return ('',0,0);
11950: } else {
11951: return;
11952: }
11953: }
1.1075.2.128 raeburn 11954: if (open(my $fh,'<',$container)) {
1.987 raeburn 11955: $content = join('', <$fh>);
11956: close($fh);
11957: } else {
1.1071 raeburn 11958: if (wantarray) {
11959: return ('',0,0);
11960: } else {
11961: return;
11962: }
1.987 raeburn 11963: }
11964: }
11965: my ($count,$codebasecount) = (0,0);
11966: my $mm = new File::MMagic;
11967: my $mime_type = $mm->checktype_contents($content);
11968: if ($mime_type eq 'text/html') {
11969: my $parse_result =
11970: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11971: \%codebase,\$content);
11972: if ($parse_result eq 'ok') {
11973: foreach my $i (@changes) {
11974: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11975: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11976: if ($allfiles{$ref}) {
11977: my $newname = $orig;
11978: my ($attrib_regexp,$codebase);
1.1006 raeburn 11979: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11980: if ($attrib_regexp =~ /:/) {
11981: $attrib_regexp =~ s/\:/|/g;
11982: }
11983: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11984: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11985: $count += $numchg;
1.1075.2.35 raeburn 11986: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11987: delete($allfiles{$ref});
1.987 raeburn 11988: }
11989: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11990: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11991: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11992: $codebasecount ++;
11993: }
11994: }
11995: }
1.1075.2.35 raeburn 11996: my $skiprewrites;
1.987 raeburn 11997: if ($count || $codebasecount) {
11998: my $saveresult;
1.1071 raeburn 11999: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 12000: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12001: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12002: if ($url eq $container) {
12003: my ($fname) = ($container =~ m{/([^/]+)$});
12004: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12005: $count,'<span class="LC_filename">'.
1.1071 raeburn 12006: $fname.'</span>').'</p>';
1.987 raeburn 12007: } else {
12008: $output = '<p class="LC_error">'.
12009: &mt('Error: update failed for: [_1].',
12010: '<span class="LC_filename">'.
12011: $container.'</span>').'</p>';
12012: }
1.1075.2.35 raeburn 12013: if ($context eq 'syllabus') {
12014: unless ($saveresult eq 'ok') {
12015: $skiprewrites = 1;
12016: }
12017: }
1.987 raeburn 12018: } else {
1.1075.2.128 raeburn 12019: if (open(my $fh,'>',$container)) {
1.987 raeburn 12020: print $fh $content;
12021: close($fh);
12022: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12023: $count,'<span class="LC_filename">'.
12024: $container.'</span>').'</p>';
1.661 raeburn 12025: } else {
1.987 raeburn 12026: $output = '<p class="LC_error">'.
12027: &mt('Error: could not update [_1].',
12028: '<span class="LC_filename">'.
12029: $container.'</span>').'</p>';
1.661 raeburn 12030: }
12031: }
12032: }
1.1075.2.35 raeburn 12033: if (($context eq 'syllabus') && (!$skiprewrites)) {
12034: my ($actionurl,$state);
12035: $actionurl = "/public/$udom/$uname/syllabus";
12036: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12037: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12038: \%codebase,
12039: {'context' => 'rewrites',
12040: 'ignore_remote_references' => 1,});
12041: if (ref($mapping) eq 'HASH') {
12042: my $rewrites = 0;
12043: foreach my $key (keys(%{$mapping})) {
12044: next if ($key =~ m{^https?://});
12045: my $ref = $mapping->{$key};
12046: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12047: my $attrib;
12048: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12049: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12050: }
12051: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12052: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12053: $rewrites += $numchg;
12054: }
12055: }
12056: if ($rewrites) {
12057: my $saveresult;
12058: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12059: if ($url eq $container) {
12060: my ($fname) = ($container =~ m{/([^/]+)$});
12061: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12062: $count,'<span class="LC_filename">'.
12063: $fname.'</span>').'</p>';
12064: } else {
12065: $output .= '<p class="LC_error">'.
12066: &mt('Error: could not update links in [_1].',
12067: '<span class="LC_filename">'.
12068: $container.'</span>').'</p>';
12069:
12070: }
12071: }
12072: }
12073: }
1.987 raeburn 12074: } else {
12075: &logthis('Failed to parse '.$container.
12076: ' to modify references: '.$parse_result);
1.661 raeburn 12077: }
12078: }
1.1071 raeburn 12079: if (wantarray) {
12080: return ($output,$count,$codebasecount);
12081: } else {
12082: return $output;
12083: }
1.661 raeburn 12084: }
12085:
12086: sub check_for_existing {
12087: my ($path,$fname,$element) = @_;
12088: my ($state,$msg);
12089: if (-d $path.'/'.$fname) {
12090: $state = 'exists';
12091: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12092: } elsif (-e $path.'/'.$fname) {
12093: $state = 'exists';
12094: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12095: }
12096: if ($state eq 'exists') {
12097: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12098: }
12099: return ($state,$msg);
12100: }
12101:
12102: sub check_for_upload {
12103: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12104: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12105: my $filesize = length($env{'form.'.$element});
12106: if (!$filesize) {
12107: my $msg = '<span class="LC_error">'.
12108: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12109: '<span class="LC_filename">'.$fname.'</span>',
12110: $filesize).'<br />'.
1.1007 raeburn 12111: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12112: '</span>';
12113: return ('zero_bytes',$msg);
12114: }
12115: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12116: my $getpropath = 1;
1.1021 raeburn 12117: my ($dirlistref,$listerror) =
12118: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12119: my $found_file = 0;
12120: my $locked_file = 0;
1.991 raeburn 12121: my @lockers;
12122: my $navmap;
12123: if ($env{'request.course.id'}) {
12124: $navmap = Apache::lonnavmaps::navmap->new();
12125: }
1.1021 raeburn 12126: if (ref($dirlistref) eq 'ARRAY') {
12127: foreach my $line (@{$dirlistref}) {
12128: my ($file_name,$rest)=split(/\&/,$line,2);
12129: if ($file_name eq $fname){
12130: $file_name = $path.$file_name;
12131: if ($group ne '') {
12132: $file_name = $group.$file_name;
12133: }
12134: $found_file = 1;
12135: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12136: foreach my $lock (@lockers) {
12137: if (ref($lock) eq 'ARRAY') {
12138: my ($symb,$crsid) = @{$lock};
12139: if ($crsid eq $env{'request.course.id'}) {
12140: if (ref($navmap)) {
12141: my $res = $navmap->getBySymb($symb);
12142: foreach my $part (@{$res->parts()}) {
12143: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12144: unless (($slot_status == $res->RESERVED) ||
12145: ($slot_status == $res->RESERVED_LOCATION)) {
12146: $locked_file = 1;
12147: }
1.991 raeburn 12148: }
1.1021 raeburn 12149: } else {
12150: $locked_file = 1;
1.991 raeburn 12151: }
12152: } else {
12153: $locked_file = 1;
12154: }
12155: }
1.1021 raeburn 12156: }
12157: } else {
12158: my @info = split(/\&/,$rest);
12159: my $currsize = $info[6]/1000;
12160: if ($currsize < $filesize) {
12161: my $extra = $filesize - $currsize;
12162: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 12163: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12164: &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.1075.2.69 raeburn 12165: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12166: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12167: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12168: return ('will_exceed_quota',$msg);
12169: }
1.984 raeburn 12170: }
12171: }
1.661 raeburn 12172: }
12173: }
12174: }
12175: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 12176: my $msg = '<p class="LC_warning">'.
12177: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
12178: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12179: return ('will_exceed_quota',$msg);
12180: } elsif ($found_file) {
12181: if ($locked_file) {
1.1075.2.69 raeburn 12182: my $msg = '<p class="LC_warning">';
1.661 raeburn 12183: $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.1075.2.69 raeburn 12184: $msg .= '</p>';
1.661 raeburn 12185: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12186: return ('file_locked',$msg);
12187: } else {
1.1075.2.69 raeburn 12188: my $msg = '<p class="LC_error">';
1.984 raeburn 12189: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.1075.2.69 raeburn 12190: $msg .= '</p>';
1.984 raeburn 12191: return ('existingfile',$msg);
1.661 raeburn 12192: }
12193: }
12194: }
12195:
1.987 raeburn 12196: sub check_for_traversal {
12197: my ($path,$url,$toplevel) = @_;
12198: my @parts=split(/\//,$path);
12199: my $cleanpath;
12200: my $fullpath = $url;
12201: for (my $i=0;$i<@parts;$i++) {
12202: next if ($parts[$i] eq '.');
12203: if ($parts[$i] eq '..') {
12204: $fullpath =~ s{([^/]+/)$}{};
12205: } else {
12206: $fullpath .= $parts[$i].'/';
12207: }
12208: }
12209: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12210: $cleanpath = $1;
12211: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12212: my $curr_toprel = $1;
12213: my @parts = split(/\//,$curr_toprel);
12214: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12215: my @urlparts = split(/\//,$url_toprel);
12216: my $doubledots;
12217: my $startdiff = -1;
12218: for (my $i=0; $i<@urlparts; $i++) {
12219: if ($startdiff == -1) {
12220: unless ($urlparts[$i] eq $parts[$i]) {
12221: $startdiff = $i;
12222: $doubledots .= '../';
12223: }
12224: } else {
12225: $doubledots .= '../';
12226: }
12227: }
12228: if ($startdiff > -1) {
12229: $cleanpath = $doubledots;
12230: for (my $i=$startdiff; $i<@parts; $i++) {
12231: $cleanpath .= $parts[$i].'/';
12232: }
12233: }
12234: }
12235: $cleanpath =~ s{(/)$}{};
12236: return $cleanpath;
12237: }
1.31 albertel 12238:
1.1053 raeburn 12239: sub is_archive_file {
12240: my ($mimetype) = @_;
12241: if (($mimetype eq 'application/octet-stream') ||
12242: ($mimetype eq 'application/x-stuffit') ||
12243: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12244: return 1;
12245: }
12246: return;
12247: }
12248:
12249: sub decompress_form {
1.1065 raeburn 12250: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12251: my %lt = &Apache::lonlocal::texthash (
12252: this => 'This file is an archive file.',
1.1067 raeburn 12253: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12254: itsc => 'Its contents are as follows:',
1.1053 raeburn 12255: youm => 'You may wish to extract its contents.',
12256: extr => 'Extract contents',
1.1067 raeburn 12257: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12258: proa => 'Process automatically?',
1.1053 raeburn 12259: yes => 'Yes',
12260: no => 'No',
1.1067 raeburn 12261: fold => 'Title for folder containing movie',
12262: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12263: );
1.1065 raeburn 12264: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12265: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12266: my $info = &list_archive_contents($fileloc,\@paths);
12267: if (@paths) {
12268: foreach my $path (@paths) {
12269: $path =~ s{^/}{};
1.1067 raeburn 12270: if ($path =~ m{^([^/]+)/$}) {
12271: $topdir = $1;
12272: }
1.1065 raeburn 12273: if ($path =~ m{^([^/]+)/}) {
12274: $toplevel{$1} = $path;
12275: } else {
12276: $toplevel{$path} = $path;
12277: }
12278: }
12279: }
1.1067 raeburn 12280: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 12281: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12282: "$topdir/media/",
12283: "$topdir/media/$topdir.mp4",
12284: "$topdir/media/FirstFrame.png",
12285: "$topdir/media/player.swf",
12286: "$topdir/media/swfobject.js",
12287: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 12288: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 12289: "$topdir/$topdir.mp4",
12290: "$topdir/$topdir\_config.xml",
12291: "$topdir/$topdir\_controller.swf",
12292: "$topdir/$topdir\_embed.css",
12293: "$topdir/$topdir\_First_Frame.png",
12294: "$topdir/$topdir\_player.html",
12295: "$topdir/$topdir\_Thumbnails.png",
12296: "$topdir/playerProductInstall.swf",
12297: "$topdir/scripts/",
12298: "$topdir/scripts/config_xml.js",
12299: "$topdir/scripts/handlebars.js",
12300: "$topdir/scripts/jquery-1.7.1.min.js",
12301: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12302: "$topdir/scripts/modernizr.js",
12303: "$topdir/scripts/player-min.js",
12304: "$topdir/scripts/swfobject.js",
12305: "$topdir/skins/",
12306: "$topdir/skins/configuration_express.xml",
12307: "$topdir/skins/express_show/",
12308: "$topdir/skins/express_show/player-min.css",
12309: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 12310: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12311: "$topdir/$topdir.mp4",
12312: "$topdir/$topdir\_config.xml",
12313: "$topdir/$topdir\_controller.swf",
12314: "$topdir/$topdir\_embed.css",
12315: "$topdir/$topdir\_First_Frame.png",
12316: "$topdir/$topdir\_player.html",
12317: "$topdir/$topdir\_Thumbnails.png",
12318: "$topdir/playerProductInstall.swf",
12319: "$topdir/scripts/",
12320: "$topdir/scripts/config_xml.js",
12321: "$topdir/scripts/techsmith-smart-player.min.js",
12322: "$topdir/skins/",
12323: "$topdir/skins/configuration_express.xml",
12324: "$topdir/skins/express_show/",
12325: "$topdir/skins/express_show/spritesheet.min.css",
12326: "$topdir/skins/express_show/spritesheet.png",
12327: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 12328: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12329: if (@diffs == 0) {
1.1075.2.59 raeburn 12330: $is_camtasia = 6;
12331: } else {
1.1075.2.81 raeburn 12332: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 12333: if (@diffs == 0) {
12334: $is_camtasia = 8;
1.1075.2.81 raeburn 12335: } else {
12336: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12337: if (@diffs == 0) {
12338: $is_camtasia = 8;
12339: }
1.1075.2.59 raeburn 12340: }
1.1067 raeburn 12341: }
12342: }
12343: my $output;
12344: if ($is_camtasia) {
12345: $output = <<"ENDCAM";
12346: <script type="text/javascript" language="Javascript">
12347: // <![CDATA[
12348:
12349: function camtasiaToggle() {
12350: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12351: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 12352: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12353: document.getElementById('camtasia_titles').style.display='block';
12354: } else {
12355: document.getElementById('camtasia_titles').style.display='none';
12356: }
12357: }
12358: }
12359: return;
12360: }
12361:
12362: // ]]>
12363: </script>
12364: <p>$lt{'camt'}</p>
12365: ENDCAM
1.1065 raeburn 12366: } else {
1.1067 raeburn 12367: $output = '<p>'.$lt{'this'};
12368: if ($info eq '') {
12369: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12370: } else {
12371: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12372: '<div><pre>'.$info.'</pre></div>';
12373: }
1.1065 raeburn 12374: }
1.1067 raeburn 12375: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12376: my $duplicates;
12377: my $num = 0;
12378: if (ref($dirlist) eq 'ARRAY') {
12379: foreach my $item (@{$dirlist}) {
12380: if (ref($item) eq 'ARRAY') {
12381: if (exists($toplevel{$item->[0]})) {
12382: $duplicates .=
12383: &start_data_table_row().
12384: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12385: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12386: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12387: 'value="1" />'.&mt('Yes').'</label>'.
12388: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12389: '<td>'.$item->[0].'</td>';
12390: if ($item->[2]) {
12391: $duplicates .= '<td>'.&mt('Directory').'</td>';
12392: } else {
12393: $duplicates .= '<td>'.&mt('File').'</td>';
12394: }
12395: $duplicates .= '<td>'.$item->[3].'</td>'.
12396: '<td>'.
12397: &Apache::lonlocal::locallocaltime($item->[4]).
12398: '</td>'.
12399: &end_data_table_row();
12400: $num ++;
12401: }
12402: }
12403: }
12404: }
12405: my $itemcount;
12406: if (@paths > 0) {
12407: $itemcount = scalar(@paths);
12408: } else {
12409: $itemcount = 1;
12410: }
1.1067 raeburn 12411: if ($is_camtasia) {
12412: $output .= $lt{'auto'}.'<br />'.
12413: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12414: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12415: $lt{'yes'}.'</label> <label>'.
12416: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12417: $lt{'no'}.'</label></span><br />'.
12418: '<div id="camtasia_titles" style="display:block">'.
12419: &Apache::lonhtmlcommon::start_pick_box().
12420: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12421: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12422: &Apache::lonhtmlcommon::row_closure().
12423: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12424: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12425: &Apache::lonhtmlcommon::row_closure(1).
12426: &Apache::lonhtmlcommon::end_pick_box().
12427: '</div>';
12428: }
1.1065 raeburn 12429: $output .=
12430: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12431: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12432: "\n";
1.1065 raeburn 12433: if ($duplicates ne '') {
12434: $output .= '<p><span class="LC_warning">'.
12435: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12436: &start_data_table().
12437: &start_data_table_header_row().
12438: '<th>'.&mt('Overwrite?').'</th>'.
12439: '<th>'.&mt('Name').'</th>'.
12440: '<th>'.&mt('Type').'</th>'.
12441: '<th>'.&mt('Size').'</th>'.
12442: '<th>'.&mt('Last modified').'</th>'.
12443: &end_data_table_header_row().
12444: $duplicates.
12445: &end_data_table().
12446: '</p>';
12447: }
1.1067 raeburn 12448: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12449: if (ref($hiddenelements) eq 'HASH') {
12450: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12451: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12452: }
12453: }
12454: $output .= <<"END";
1.1067 raeburn 12455: <br />
1.1053 raeburn 12456: <input type="submit" name="decompress" value="$lt{'extr'}" />
12457: </form>
12458: $noextract
12459: END
12460: return $output;
12461: }
12462:
1.1065 raeburn 12463: sub decompression_utility {
12464: my ($program) = @_;
12465: my @utilities = ('tar','gunzip','bunzip2','unzip');
12466: my $location;
12467: if (grep(/^\Q$program\E$/,@utilities)) {
12468: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12469: '/usr/sbin/') {
12470: if (-x $dir.$program) {
12471: $location = $dir.$program;
12472: last;
12473: }
12474: }
12475: }
12476: return $location;
12477: }
12478:
12479: sub list_archive_contents {
12480: my ($file,$pathsref) = @_;
12481: my (@cmd,$output);
12482: my $needsregexp;
12483: if ($file =~ /\.zip$/) {
12484: @cmd = (&decompression_utility('unzip'),"-l");
12485: $needsregexp = 1;
12486: } elsif (($file =~ m/\.tar\.gz$/) ||
12487: ($file =~ /\.tgz$/)) {
12488: @cmd = (&decompression_utility('tar'),"-ztf");
12489: } elsif ($file =~ /\.tar\.bz2$/) {
12490: @cmd = (&decompression_utility('tar'),"-jtf");
12491: } elsif ($file =~ m|\.tar$|) {
12492: @cmd = (&decompression_utility('tar'),"-tf");
12493: }
12494: if (@cmd) {
12495: undef($!);
12496: undef($@);
12497: if (open(my $fh,"-|", @cmd, $file)) {
12498: while (my $line = <$fh>) {
12499: $output .= $line;
12500: chomp($line);
12501: my $item;
12502: if ($needsregexp) {
12503: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12504: } else {
12505: $item = $line;
12506: }
12507: if ($item ne '') {
12508: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12509: push(@{$pathsref},$item);
12510: }
12511: }
12512: }
12513: close($fh);
12514: }
12515: }
12516: return $output;
12517: }
12518:
1.1053 raeburn 12519: sub decompress_uploaded_file {
12520: my ($file,$dir) = @_;
12521: &Apache::lonnet::appenv({'cgi.file' => $file});
12522: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12523: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12524: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12525: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12526: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12527: my $decompressed = $env{'cgi.decompressed'};
12528: &Apache::lonnet::delenv('cgi.file');
12529: &Apache::lonnet::delenv('cgi.dir');
12530: &Apache::lonnet::delenv('cgi.decompressed');
12531: return ($decompressed,$result);
12532: }
12533:
1.1055 raeburn 12534: sub process_decompression {
12535: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12536: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12537: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12538: &mt('Unexpected file path.').'</p>'."\n";
12539: }
12540: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12541: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12542: &mt('Unexpected course context.').'</p>'."\n";
12543: }
12544: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12545: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12546: &mt('Filename contained unexpected characters.').'</p>'."\n";
12547: }
1.1055 raeburn 12548: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12549: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12550: $error = &mt('Filename not a supported archive file type.').
12551: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12552: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12553: } else {
12554: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12555: if ($docuhome eq 'no_host') {
12556: $error = &mt('Could not determine home server for course.');
12557: } else {
12558: my @ids=&Apache::lonnet::current_machine_ids();
12559: my $currdir = "$dir_root/$destination";
12560: if (grep(/^\Q$docuhome\E$/,@ids)) {
12561: $dir = &LONCAPA::propath($docudom,$docuname).
12562: "$dir_root/$destination";
12563: } else {
12564: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12565: "$dir_root/$docudom/$docuname/$destination";
12566: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12567: $error = &mt('Archive file not found.');
12568: }
12569: }
1.1065 raeburn 12570: my (@to_overwrite,@to_skip);
12571: if ($env{'form.archive_overwrite_total'} > 0) {
12572: my $total = $env{'form.archive_overwrite_total'};
12573: for (my $i=0; $i<$total; $i++) {
12574: if ($env{'form.archive_overwrite_'.$i} == 1) {
12575: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12576: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12577: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12578: }
12579: }
12580: }
12581: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12582: my $numoverwrite = scalar(@to_overwrite);
12583: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12584: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12585: } elsif ($dir eq '') {
1.1055 raeburn 12586: $error = &mt('Directory containing archive file unavailable.');
12587: } elsif (!$error) {
1.1065 raeburn 12588: my ($decompressed,$display);
1.1075.2.128 raeburn 12589: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12590: my $tempdir = time.'_'.$$.int(rand(10000));
12591: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12592: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12593: ($decompressed,$display) =
12594: &decompress_uploaded_file($file,"$dir/$tempdir");
12595: foreach my $item (@to_skip) {
12596: if (($item ne '') && ($item !~ /\.\./)) {
12597: if (-f "$dir/$tempdir/$item") {
12598: unlink("$dir/$tempdir/$item");
12599: } elsif (-d "$dir/$tempdir/$item") {
12600: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12601: }
12602: }
12603: }
12604: foreach my $item (@to_overwrite) {
12605: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12606: if (($item ne '') && ($item !~ /\.\./)) {
12607: if (-f "$dir/$item") {
12608: unlink("$dir/$item");
12609: } elsif (-d "$dir/$item") {
12610: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12611: }
12612: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12613: }
1.1065 raeburn 12614: }
12615: }
1.1075.2.128 raeburn 12616: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12617: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12618: }
1.1065 raeburn 12619: }
12620: } else {
12621: ($decompressed,$display) =
12622: &decompress_uploaded_file($file,$dir);
12623: }
1.1055 raeburn 12624: if ($decompressed eq 'ok') {
1.1065 raeburn 12625: $output = '<p class="LC_info">'.
12626: &mt('Files extracted successfully from archive.').
12627: '</p>'."\n";
1.1055 raeburn 12628: my ($warning,$result,@contents);
12629: my ($newdirlistref,$newlisterror) =
12630: &Apache::lonnet::dirlist($currdir,$docudom,
12631: $docuname,1);
12632: my (%is_dir,%changes,@newitems);
12633: my $dirptr = 16384;
1.1065 raeburn 12634: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12635: foreach my $dir_line (@{$newdirlistref}) {
12636: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12637: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12638: push(@newitems,$item);
12639: if ($dirptr&$testdir) {
12640: $is_dir{$item} = 1;
12641: }
12642: $changes{$item} = 1;
12643: }
12644: }
12645: }
12646: if (keys(%changes) > 0) {
12647: foreach my $item (sort(@newitems)) {
12648: if ($changes{$item}) {
12649: push(@contents,$item);
12650: }
12651: }
12652: }
12653: if (@contents > 0) {
1.1067 raeburn 12654: my $wantform;
12655: unless ($env{'form.autoextract_camtasia'}) {
12656: $wantform = 1;
12657: }
1.1056 raeburn 12658: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12659: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12660: $currdir,\%is_dir,
12661: \%children,\%parent,
1.1056 raeburn 12662: \@contents,\%dirorder,
12663: \%titles,$wantform);
1.1055 raeburn 12664: if ($datatable ne '') {
12665: $output .= &archive_options_form('decompressed',$datatable,
12666: $count,$hiddenelem);
1.1065 raeburn 12667: my $startcount = 6;
1.1055 raeburn 12668: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12669: \%titles,\%children);
1.1055 raeburn 12670: }
1.1067 raeburn 12671: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12672: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12673: my %displayed;
12674: my $total = 1;
12675: $env{'form.archive_directory'} = [];
12676: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12677: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12678: $path =~ s{/$}{};
12679: my $item;
12680: if ($path ne '') {
12681: $item = "$path/$titles{$i}";
12682: } else {
12683: $item = $titles{$i};
12684: }
12685: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12686: if ($item eq $contents[0]) {
12687: push(@{$env{'form.archive_directory'}},$i);
12688: $env{'form.archive_'.$i} = 'display';
12689: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12690: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12691: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12692: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12693: $env{'form.archive_'.$i} = 'display';
12694: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12695: $displayed{'web'} = $i;
12696: } else {
1.1075.2.59 raeburn 12697: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12698: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12699: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12700: push(@{$env{'form.archive_directory'}},$i);
12701: }
12702: $env{'form.archive_'.$i} = 'dependency';
12703: }
12704: $total ++;
12705: }
12706: for (my $i=1; $i<$total; $i++) {
12707: next if ($i == $displayed{'web'});
12708: next if ($i == $displayed{'folder'});
12709: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12710: }
12711: $env{'form.phase'} = 'decompress_cleanup';
12712: $env{'form.archivedelete'} = 1;
12713: $env{'form.archive_count'} = $total-1;
12714: $output .=
12715: &process_extracted_files('coursedocs',$docudom,
12716: $docuname,$destination,
12717: $dir_root,$hiddenelem);
12718: }
1.1055 raeburn 12719: } else {
12720: $warning = &mt('No new items extracted from archive file.');
12721: }
12722: } else {
12723: $output = $display;
12724: $error = &mt('An error occurred during extraction from the archive file.');
12725: }
12726: }
12727: }
12728: }
12729: if ($error) {
12730: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12731: $error.'</p>'."\n";
12732: }
12733: if ($warning) {
12734: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12735: }
12736: return $output;
12737: }
12738:
12739: sub get_extracted {
1.1056 raeburn 12740: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12741: $titles,$wantform) = @_;
1.1055 raeburn 12742: my $count = 0;
12743: my $depth = 0;
12744: my $datatable;
1.1056 raeburn 12745: my @hierarchy;
1.1055 raeburn 12746: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12747: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12748: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12749: foreach my $item (@{$contents}) {
12750: $count ++;
1.1056 raeburn 12751: @{$dirorder->{$count}} = @hierarchy;
12752: $titles->{$count} = $item;
1.1055 raeburn 12753: &archive_hierarchy($depth,$count,$parent,$children);
12754: if ($wantform) {
12755: $datatable .= &archive_row($is_dir->{$item},$item,
12756: $currdir,$depth,$count);
12757: }
12758: if ($is_dir->{$item}) {
12759: $depth ++;
1.1056 raeburn 12760: push(@hierarchy,$count);
12761: $parent->{$depth} = $count;
1.1055 raeburn 12762: $datatable .=
12763: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12764: \$depth,\$count,\@hierarchy,$dirorder,
12765: $children,$parent,$titles,$wantform);
1.1055 raeburn 12766: $depth --;
1.1056 raeburn 12767: pop(@hierarchy);
1.1055 raeburn 12768: }
12769: }
12770: return ($count,$datatable);
12771: }
12772:
12773: sub recurse_extracted_archive {
1.1056 raeburn 12774: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12775: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12776: my $result='';
1.1056 raeburn 12777: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12778: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12779: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12780: return $result;
12781: }
12782: my $dirptr = 16384;
12783: my ($newdirlistref,$newlisterror) =
12784: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12785: if (ref($newdirlistref) eq 'ARRAY') {
12786: foreach my $dir_line (@{$newdirlistref}) {
12787: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12788: unless ($item =~ /^\.+$/) {
12789: $$count ++;
1.1056 raeburn 12790: @{$dirorder->{$$count}} = @{$hierarchy};
12791: $titles->{$$count} = $item;
1.1055 raeburn 12792: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12793:
1.1055 raeburn 12794: my $is_dir;
12795: if ($dirptr&$testdir) {
12796: $is_dir = 1;
12797: }
12798: if ($wantform) {
12799: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12800: }
12801: if ($is_dir) {
12802: $$depth ++;
1.1056 raeburn 12803: push(@{$hierarchy},$$count);
12804: $parent->{$$depth} = $$count;
1.1055 raeburn 12805: $result .=
12806: &recurse_extracted_archive("$currdir/$item",$docudom,
12807: $docuname,$depth,$count,
1.1056 raeburn 12808: $hierarchy,$dirorder,$children,
12809: $parent,$titles,$wantform);
1.1055 raeburn 12810: $$depth --;
1.1056 raeburn 12811: pop(@{$hierarchy});
1.1055 raeburn 12812: }
12813: }
12814: }
12815: }
12816: return $result;
12817: }
12818:
12819: sub archive_hierarchy {
12820: my ($depth,$count,$parent,$children) =@_;
12821: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12822: if (exists($parent->{$depth})) {
12823: $children->{$parent->{$depth}} .= $count.':';
12824: }
12825: }
12826: return;
12827: }
12828:
12829: sub archive_row {
12830: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12831: my ($name) = ($item =~ m{([^/]+)$});
12832: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12833: 'display' => 'Add as file',
1.1055 raeburn 12834: 'dependency' => 'Include as dependency',
12835: 'discard' => 'Discard',
12836: );
12837: if ($is_dir) {
1.1059 raeburn 12838: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12839: }
1.1056 raeburn 12840: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12841: my $offset = 0;
1.1055 raeburn 12842: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12843: $offset ++;
1.1065 raeburn 12844: if ($action ne 'display') {
12845: $offset ++;
12846: }
1.1055 raeburn 12847: $output .= '<td><span class="LC_nobreak">'.
12848: '<label><input type="radio" name="archive_'.$count.
12849: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12850: my $text = $choices{$action};
12851: if ($is_dir) {
12852: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12853: if ($action eq 'display') {
1.1059 raeburn 12854: $text = &mt('Add as folder');
1.1055 raeburn 12855: }
1.1056 raeburn 12856: } else {
12857: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12858:
12859: }
12860: $output .= ' /> '.$choices{$action}.'</label></span>';
12861: if ($action eq 'dependency') {
12862: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12863: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12864: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12865: '<option value=""></option>'."\n".
12866: '</select>'."\n".
12867: '</div>';
1.1059 raeburn 12868: } elsif ($action eq 'display') {
12869: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12870: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12871: '</div>';
1.1055 raeburn 12872: }
1.1056 raeburn 12873: $output .= '</td>';
1.1055 raeburn 12874: }
12875: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12876: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12877: for (my $i=0; $i<$depth; $i++) {
12878: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12879: }
12880: if ($is_dir) {
12881: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12882: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12883: } else {
12884: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12885: }
12886: $output .= ' '.$name.'</td>'."\n".
12887: &end_data_table_row();
12888: return $output;
12889: }
12890:
12891: sub archive_options_form {
1.1065 raeburn 12892: my ($form,$display,$count,$hiddenelem) = @_;
12893: my %lt = &Apache::lonlocal::texthash(
12894: perm => 'Permanently remove archive file?',
12895: hows => 'How should each extracted item be incorporated in the course?',
12896: cont => 'Content actions for all',
12897: addf => 'Add as folder/file',
12898: incd => 'Include as dependency for a displayed file',
12899: disc => 'Discard',
12900: no => 'No',
12901: yes => 'Yes',
12902: save => 'Save',
12903: );
12904: my $output = <<"END";
12905: <form name="$form" method="post" action="">
12906: <p><span class="LC_nobreak">$lt{'perm'}
12907: <label>
12908: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12909: </label>
12910:
12911: <label>
12912: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12913: </span>
12914: </p>
12915: <input type="hidden" name="phase" value="decompress_cleanup" />
12916: <br />$lt{'hows'}
12917: <div class="LC_columnSection">
12918: <fieldset>
12919: <legend>$lt{'cont'}</legend>
12920: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12921: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12922: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12923: </fieldset>
12924: </div>
12925: END
12926: return $output.
1.1055 raeburn 12927: &start_data_table()."\n".
1.1065 raeburn 12928: $display."\n".
1.1055 raeburn 12929: &end_data_table()."\n".
12930: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12931: $hiddenelem.
1.1065 raeburn 12932: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12933: '</form>';
12934: }
12935:
12936: sub archive_javascript {
1.1056 raeburn 12937: my ($startcount,$numitems,$titles,$children) = @_;
12938: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12939: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12940: my $scripttag = <<START;
12941: <script type="text/javascript">
12942: // <![CDATA[
12943:
12944: function checkAll(form,prefix) {
12945: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12946: for (var i=0; i < form.elements.length; i++) {
12947: var id = form.elements[i].id;
12948: if ((id != '') && (id != undefined)) {
12949: if (idstr.test(id)) {
12950: if (form.elements[i].type == 'radio') {
12951: form.elements[i].checked = true;
1.1056 raeburn 12952: var nostart = i-$startcount;
1.1059 raeburn 12953: var offset = nostart%7;
12954: var count = (nostart-offset)/7;
1.1056 raeburn 12955: dependencyCheck(form,count,offset);
1.1055 raeburn 12956: }
12957: }
12958: }
12959: }
12960: }
12961:
12962: function propagateCheck(form,count) {
12963: if (count > 0) {
1.1059 raeburn 12964: var startelement = $startcount + ((count-1) * 7);
12965: for (var j=1; j<6; j++) {
12966: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12967: var item = startelement + j;
12968: if (form.elements[item].type == 'radio') {
12969: if (form.elements[item].checked) {
12970: containerCheck(form,count,j);
12971: break;
12972: }
1.1055 raeburn 12973: }
12974: }
12975: }
12976: }
12977: }
12978:
12979: numitems = $numitems
1.1056 raeburn 12980: var titles = new Array(numitems);
12981: var parents = new Array(numitems);
1.1055 raeburn 12982: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12983: parents[i] = new Array;
1.1055 raeburn 12984: }
1.1059 raeburn 12985: var maintitle = '$maintitle';
1.1055 raeburn 12986:
12987: START
12988:
1.1056 raeburn 12989: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12990: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12991: for (my $i=0; $i<@contents; $i ++) {
12992: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12993: }
12994: }
12995:
1.1056 raeburn 12996: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12997: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12998: }
12999:
1.1055 raeburn 13000: $scripttag .= <<END;
13001:
13002: function containerCheck(form,count,offset) {
13003: if (count > 0) {
1.1056 raeburn 13004: dependencyCheck(form,count,offset);
1.1059 raeburn 13005: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13006: form.elements[item].checked = true;
13007: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13008: if (parents[count].length > 0) {
13009: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13010: containerCheck(form,parents[count][j],offset);
13011: }
13012: }
13013: }
13014: }
13015: }
13016:
13017: function dependencyCheck(form,count,offset) {
13018: if (count > 0) {
1.1059 raeburn 13019: var chosen = (offset+$startcount)+7*(count-1);
13020: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13021: var currtype = form.elements[depitem].type;
13022: if (form.elements[chosen].value == 'dependency') {
13023: document.getElementById('arc_depon_'+count).style.display='block';
13024: form.elements[depitem].options.length = 0;
13025: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 13026: for (var i=1; i<=numitems; i++) {
13027: if (i == count) {
13028: continue;
13029: }
1.1059 raeburn 13030: var startelement = $startcount + (i-1) * 7;
13031: for (var j=1; j<6; j++) {
13032: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13033: var item = startelement + j;
13034: if (form.elements[item].type == 'radio') {
13035: if (form.elements[item].checked) {
13036: if (form.elements[item].value == 'display') {
13037: var n = form.elements[depitem].options.length;
13038: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13039: }
13040: }
13041: }
13042: }
13043: }
13044: }
13045: } else {
13046: document.getElementById('arc_depon_'+count).style.display='none';
13047: form.elements[depitem].options.length = 0;
13048: form.elements[depitem].options[0] = new Option('Select','',true,true);
13049: }
1.1059 raeburn 13050: titleCheck(form,count,offset);
1.1056 raeburn 13051: }
13052: }
13053:
13054: function propagateSelect(form,count,offset) {
13055: if (count > 0) {
1.1065 raeburn 13056: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13057: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13058: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13059: if (parents[count].length > 0) {
13060: for (var j=0; j<parents[count].length; j++) {
13061: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13062: }
13063: }
13064: }
13065: }
13066: }
1.1056 raeburn 13067:
13068: function containerSelect(form,count,offset,picked) {
13069: if (count > 0) {
1.1065 raeburn 13070: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13071: if (form.elements[item].type == 'radio') {
13072: if (form.elements[item].value == 'dependency') {
13073: if (form.elements[item+1].type == 'select-one') {
13074: for (var i=0; i<form.elements[item+1].options.length; i++) {
13075: if (form.elements[item+1].options[i].value == picked) {
13076: form.elements[item+1].selectedIndex = i;
13077: break;
13078: }
13079: }
13080: }
13081: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13082: if (parents[count].length > 0) {
13083: for (var j=0; j<parents[count].length; j++) {
13084: containerSelect(form,parents[count][j],offset,picked);
13085: }
13086: }
13087: }
13088: }
13089: }
13090: }
13091: }
13092:
1.1059 raeburn 13093: function titleCheck(form,count,offset) {
13094: if (count > 0) {
13095: var chosen = (offset+$startcount)+7*(count-1);
13096: var depitem = $startcount + ((count-1) * 7) + 2;
13097: var currtype = form.elements[depitem].type;
13098: if (form.elements[chosen].value == 'display') {
13099: document.getElementById('arc_title_'+count).style.display='block';
13100: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13101: document.getElementById('archive_title_'+count).value=maintitle;
13102: }
13103: } else {
13104: document.getElementById('arc_title_'+count).style.display='none';
13105: if (currtype == 'text') {
13106: document.getElementById('archive_title_'+count).value='';
13107: }
13108: }
13109: }
13110: return;
13111: }
13112:
1.1055 raeburn 13113: // ]]>
13114: </script>
13115: END
13116: return $scripttag;
13117: }
13118:
13119: sub process_extracted_files {
1.1067 raeburn 13120: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13121: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 13122: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13123: my @ids=&Apache::lonnet::current_machine_ids();
13124: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13125: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13126: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13127: if (grep(/^\Q$docuhome\E$/,@ids)) {
13128: $prefix = &LONCAPA::propath($docudom,$docuname);
13129: $pathtocheck = "$dir_root/$destination";
13130: $dir = $dir_root;
13131: $ishome = 1;
13132: } else {
13133: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13134: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 13135: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13136: }
13137: my $currdir = "$dir_root/$destination";
13138: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13139: if ($env{'form.folderpath'}) {
13140: my @items = split('&',$env{'form.folderpath'});
13141: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 13142: if ($env{'form.folderpath'} =~ /\:1$/) {
13143: $containers{'0'}='page';
13144: } else {
13145: $containers{'0'}='sequence';
13146: }
1.1055 raeburn 13147: }
13148: my @archdirs = &get_env_multiple('form.archive_directory');
13149: if ($numitems) {
13150: for (my $i=1; $i<=$numitems; $i++) {
13151: my $path = $env{'form.archive_content_'.$i};
13152: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13153: my $item = $1;
13154: $toplevelitems{$item} = $i;
13155: if (grep(/^\Q$i\E$/,@archdirs)) {
13156: $is_dir{$item} = 1;
13157: }
13158: }
13159: }
13160: }
1.1067 raeburn 13161: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13162: if (keys(%toplevelitems) > 0) {
13163: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13164: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13165: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13166: }
1.1066 raeburn 13167: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13168: if ($numitems) {
13169: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 13170: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13171: my $path = $env{'form.archive_content_'.$i};
13172: if ($path =~ /^\Q$pathtocheck\E/) {
13173: if ($env{'form.archive_'.$i} eq 'discard') {
13174: if ($prefix ne '' && $path ne '') {
13175: if (-e $prefix.$path) {
1.1066 raeburn 13176: if ((@archdirs > 0) &&
13177: (grep(/^\Q$i\E$/,@archdirs))) {
13178: $todeletedir{$prefix.$path} = 1;
13179: } else {
13180: $todelete{$prefix.$path} = 1;
13181: }
1.1055 raeburn 13182: }
13183: }
13184: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13185: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13186: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13187: $docstitle = $env{'form.archive_title_'.$i};
13188: if ($docstitle eq '') {
13189: $docstitle = $title;
13190: }
1.1055 raeburn 13191: $outer = 0;
1.1056 raeburn 13192: if (ref($dirorder{$i}) eq 'ARRAY') {
13193: if (@{$dirorder{$i}} > 0) {
13194: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13195: if ($env{'form.archive_'.$item} eq 'display') {
13196: $outer = $item;
13197: last;
13198: }
13199: }
13200: }
13201: }
13202: my ($errtext,$fatal) =
13203: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13204: '/'.$folders{$outer}.'.'.
13205: $containers{$outer});
13206: next if ($fatal);
13207: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13208: if ($context eq 'coursedocs') {
1.1056 raeburn 13209: $mapinner{$i} = time;
1.1055 raeburn 13210: $folders{$i} = 'default_'.$mapinner{$i};
13211: $containers{$i} = 'sequence';
13212: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13213: $folders{$i}.'.'.$containers{$i};
13214: my $newidx = &LONCAPA::map::getresidx();
13215: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13216: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13217: push(@LONCAPA::map::order,$newidx);
13218: my ($outtext,$errtext) =
13219: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13220: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 13221: '.'.$containers{$outer},1,1);
1.1056 raeburn 13222: $newseqid{$i} = $newidx;
1.1067 raeburn 13223: unless ($errtext) {
1.1075.2.128 raeburn 13224: $result .= '<li>'.&mt('Folder: [_1] added to course',
13225: &HTML::Entities::encode($docstitle,'<>&"'))..
13226: '</li>'."\n";
1.1067 raeburn 13227: }
1.1055 raeburn 13228: }
13229: } else {
13230: if ($context eq 'coursedocs') {
13231: my $newidx=&LONCAPA::map::getresidx();
13232: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13233: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13234: $title;
1.1075.2.167 raeburn 13235: if (($outer !~ /\D/) &&
13236: (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
13237: ($newidx !~ /\D/)) {
1.1075.2.128 raeburn 13238: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13239: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 13240: }
1.1075.2.128 raeburn 13241: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13242: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13243: }
13244: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13245: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13246: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13247: unless ($ishome) {
13248: my $fetch = "$newdest{$i}/$title";
13249: $fetch =~ s/^\Q$prefix$dir\E//;
13250: $prompttofetch{$fetch} = 1;
13251: }
13252: }
13253: }
13254: $LONCAPA::map::resources[$newidx]=
13255: $docstitle.':'.$url.':false:normal:res';
13256: push(@LONCAPA::map::order, $newidx);
13257: my ($outtext,$errtext)=
13258: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13259: $docuname.'/'.$folders{$outer}.
13260: '.'.$containers{$outer},1,1);
13261: unless ($errtext) {
13262: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13263: $result .= '<li>'.&mt('File: [_1] added to course',
13264: &HTML::Entities::encode($docstitle,'<>&"')).
13265: '</li>'."\n";
13266: }
1.1067 raeburn 13267: }
1.1075.2.128 raeburn 13268: } else {
13269: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13270: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 13271: }
1.1055 raeburn 13272: }
13273: }
1.1075.2.11 raeburn 13274: }
13275: } else {
1.1075.2.128 raeburn 13276: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13277: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 13278: }
13279: }
13280: for (my $i=1; $i<=$numitems; $i++) {
13281: next unless ($env{'form.archive_'.$i} eq 'dependency');
13282: my $path = $env{'form.archive_content_'.$i};
13283: if ($path =~ /^\Q$pathtocheck\E/) {
13284: my ($title) = ($path =~ m{/([^/]+)$});
13285: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13286: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13287: if (ref($dirorder{$i}) eq 'ARRAY') {
13288: my ($itemidx,$fullpath,$relpath);
13289: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13290: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13291: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 13292: if ($dirorder{$i}->[$j] eq $container) {
13293: $itemidx = $j;
1.1056 raeburn 13294: }
13295: }
1.1075.2.11 raeburn 13296: }
13297: if ($itemidx eq '') {
13298: $itemidx = 0;
13299: }
13300: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13301: if ($mapinner{$referrer{$i}}) {
13302: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13303: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13304: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13305: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13306: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13307: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13308: if (!-e $fullpath) {
13309: mkdir($fullpath,0755);
1.1056 raeburn 13310: }
13311: }
1.1075.2.11 raeburn 13312: } else {
13313: last;
1.1056 raeburn 13314: }
1.1075.2.11 raeburn 13315: }
13316: }
13317: } elsif ($newdest{$referrer{$i}}) {
13318: $fullpath = $newdest{$referrer{$i}};
13319: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13320: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13321: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13322: last;
13323: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13324: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13325: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13326: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13327: if (!-e $fullpath) {
13328: mkdir($fullpath,0755);
1.1056 raeburn 13329: }
13330: }
1.1075.2.11 raeburn 13331: } else {
13332: last;
1.1056 raeburn 13333: }
1.1075.2.11 raeburn 13334: }
13335: }
13336: if ($fullpath ne '') {
13337: if (-e "$prefix$path") {
1.1075.2.128 raeburn 13338: unless (rename("$prefix$path","$fullpath/$title")) {
13339: $warning .= &mt('Failed to rename dependency').'<br />';
13340: }
1.1075.2.11 raeburn 13341: }
13342: if (-e "$fullpath/$title") {
13343: my $showpath;
13344: if ($relpath ne '') {
13345: $showpath = "$relpath/$title";
13346: } else {
13347: $showpath = "/$title";
1.1056 raeburn 13348: }
1.1075.2.128 raeburn 13349: $result .= '<li>'.&mt('[_1] included as a dependency',
13350: &HTML::Entities::encode($showpath,'<>&"')).
13351: '</li>'."\n";
13352: unless ($ishome) {
13353: my $fetch = "$fullpath/$title";
13354: $fetch =~ s/^\Q$prefix$dir\E//;
13355: $prompttofetch{$fetch} = 1;
13356: }
1.1055 raeburn 13357: }
13358: }
13359: }
1.1075.2.11 raeburn 13360: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13361: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 13362: &HTML::Entities::encode($path,'<>&"'),
13363: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13364: '<br />';
1.1055 raeburn 13365: }
13366: } else {
1.1075.2.128 raeburn 13367: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13368: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13369: }
13370: }
13371: if (keys(%todelete)) {
13372: foreach my $key (keys(%todelete)) {
13373: unlink($key);
1.1066 raeburn 13374: }
13375: }
13376: if (keys(%todeletedir)) {
13377: foreach my $key (keys(%todeletedir)) {
13378: rmdir($key);
13379: }
13380: }
13381: foreach my $dir (sort(keys(%is_dir))) {
13382: if (($pathtocheck ne '') && ($dir ne '')) {
13383: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13384: }
13385: }
1.1067 raeburn 13386: if ($result ne '') {
13387: $output .= '<ul>'."\n".
13388: $result."\n".
13389: '</ul>';
13390: }
13391: unless ($ishome) {
13392: my $replicationfail;
13393: foreach my $item (keys(%prompttofetch)) {
13394: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13395: unless ($fetchresult eq 'ok') {
13396: $replicationfail .= '<li>'.$item.'</li>'."\n";
13397: }
13398: }
13399: if ($replicationfail) {
13400: $output .= '<p class="LC_error">'.
13401: &mt('Course home server failed to retrieve:').'<ul>'.
13402: $replicationfail.
13403: '</ul></p>';
13404: }
13405: }
1.1055 raeburn 13406: } else {
13407: $warning = &mt('No items found in archive.');
13408: }
13409: if ($error) {
13410: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13411: $error.'</p>'."\n";
13412: }
13413: if ($warning) {
13414: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13415: }
13416: return $output;
13417: }
13418:
1.1066 raeburn 13419: sub cleanup_empty_dirs {
13420: my ($path) = @_;
13421: if (($path ne '') && (-d $path)) {
13422: if (opendir(my $dirh,$path)) {
13423: my @dircontents = grep(!/^\./,readdir($dirh));
13424: my $numitems = 0;
13425: foreach my $item (@dircontents) {
13426: if (-d "$path/$item") {
1.1075.2.28 raeburn 13427: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13428: if (-e "$path/$item") {
13429: $numitems ++;
13430: }
13431: } else {
13432: $numitems ++;
13433: }
13434: }
13435: if ($numitems == 0) {
13436: rmdir($path);
13437: }
13438: closedir($dirh);
13439: }
13440: }
13441: return;
13442: }
13443:
1.41 ng 13444: =pod
1.45 matthew 13445:
1.1075.2.56 raeburn 13446: =item * &get_folder_hierarchy()
1.1068 raeburn 13447:
13448: Provides hierarchy of names of folders/sub-folders containing the current
13449: item,
13450:
13451: Inputs: 3
13452: - $navmap - navmaps object
13453:
13454: - $map - url for map (either the trigger itself, or map containing
13455: the resource, which is the trigger).
13456:
13457: - $showitem - 1 => show title for map itself; 0 => do not show.
13458:
13459: Outputs: 1 @pathitems - array of folder/subfolder names.
13460:
13461: =cut
13462:
13463: sub get_folder_hierarchy {
13464: my ($navmap,$map,$showitem) = @_;
13465: my @pathitems;
13466: if (ref($navmap)) {
13467: my $mapres = $navmap->getResourceByUrl($map);
13468: if (ref($mapres)) {
13469: my $pcslist = $mapres->map_hierarchy();
13470: if ($pcslist ne '') {
13471: my @pcs = split(/,/,$pcslist);
13472: foreach my $pc (@pcs) {
13473: if ($pc == 1) {
1.1075.2.38 raeburn 13474: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13475: } else {
13476: my $res = $navmap->getByMapPc($pc);
13477: if (ref($res)) {
13478: my $title = $res->compTitle();
13479: $title =~ s/\W+/_/g;
13480: if ($title ne '') {
13481: push(@pathitems,$title);
13482: }
13483: }
13484: }
13485: }
13486: }
1.1071 raeburn 13487: if ($showitem) {
13488: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13489: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13490: } else {
13491: my $maptitle = $mapres->compTitle();
13492: $maptitle =~ s/\W+/_/g;
13493: if ($maptitle ne '') {
13494: push(@pathitems,$maptitle);
13495: }
1.1068 raeburn 13496: }
13497: }
13498: }
13499: }
13500: return @pathitems;
13501: }
13502:
13503: =pod
13504:
1.1015 raeburn 13505: =item * &get_turnedin_filepath()
13506:
13507: Determines path in a user's portfolio file for storage of files uploaded
13508: to a specific essayresponse or dropbox item.
13509:
13510: Inputs: 3 required + 1 optional.
13511: $symb is symb for resource, $uname and $udom are for current user (required).
13512: $caller is optional (can be "submission", if routine is called when storing
13513: an upoaded file when "Submit Answer" button was pressed).
13514:
13515: Returns array containing $path and $multiresp.
13516: $path is path in portfolio. $multiresp is 1 if this resource contains more
13517: than one file upload item. Callers of routine should append partid as a
13518: subdirectory to $path in cases where $multiresp is 1.
13519:
13520: Called by: homework/essayresponse.pm and homework/structuretags.pm
13521:
13522: =cut
13523:
13524: sub get_turnedin_filepath {
13525: my ($symb,$uname,$udom,$caller) = @_;
13526: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13527: my $turnindir;
13528: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13529: $turnindir = $userhash{'turnindir'};
13530: my ($path,$multiresp);
13531: if ($turnindir eq '') {
13532: if ($caller eq 'submission') {
13533: $turnindir = &mt('turned in');
13534: $turnindir =~ s/\W+/_/g;
13535: my %newhash = (
13536: 'turnindir' => $turnindir,
13537: );
13538: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13539: }
13540: }
13541: if ($turnindir ne '') {
13542: $path = '/'.$turnindir.'/';
13543: my ($multipart,$turnin,@pathitems);
13544: my $navmap = Apache::lonnavmaps::navmap->new();
13545: if (defined($navmap)) {
13546: my $mapres = $navmap->getResourceByUrl($map);
13547: if (ref($mapres)) {
13548: my $pcslist = $mapres->map_hierarchy();
13549: if ($pcslist ne '') {
13550: foreach my $pc (split(/,/,$pcslist)) {
13551: my $res = $navmap->getByMapPc($pc);
13552: if (ref($res)) {
13553: my $title = $res->compTitle();
13554: $title =~ s/\W+/_/g;
13555: if ($title ne '') {
1.1075.2.48 raeburn 13556: if (($pc > 1) && (length($title) > 12)) {
13557: $title = substr($title,0,12);
13558: }
1.1015 raeburn 13559: push(@pathitems,$title);
13560: }
13561: }
13562: }
13563: }
13564: my $maptitle = $mapres->compTitle();
13565: $maptitle =~ s/\W+/_/g;
13566: if ($maptitle ne '') {
1.1075.2.48 raeburn 13567: if (length($maptitle) > 12) {
13568: $maptitle = substr($maptitle,0,12);
13569: }
1.1015 raeburn 13570: push(@pathitems,$maptitle);
13571: }
13572: unless ($env{'request.state'} eq 'construct') {
13573: my $res = $navmap->getBySymb($symb);
13574: if (ref($res)) {
13575: my $partlist = $res->parts();
13576: my $totaluploads = 0;
13577: if (ref($partlist) eq 'ARRAY') {
13578: foreach my $part (@{$partlist}) {
13579: my @types = $res->responseType($part);
13580: my @ids = $res->responseIds($part);
13581: for (my $i=0; $i < scalar(@ids); $i++) {
13582: if ($types[$i] eq 'essay') {
13583: my $partid = $part.'_'.$ids[$i];
13584: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13585: $totaluploads ++;
13586: }
13587: }
13588: }
13589: }
13590: if ($totaluploads > 1) {
13591: $multiresp = 1;
13592: }
13593: }
13594: }
13595: }
13596: } else {
13597: return;
13598: }
13599: } else {
13600: return;
13601: }
13602: my $restitle=&Apache::lonnet::gettitle($symb);
13603: $restitle =~ s/\W+/_/g;
13604: if ($restitle eq '') {
13605: $restitle = ($resurl =~ m{/[^/]+$});
13606: if ($restitle eq '') {
13607: $restitle = time;
13608: }
13609: }
1.1075.2.48 raeburn 13610: if (length($restitle) > 12) {
13611: $restitle = substr($restitle,0,12);
13612: }
1.1015 raeburn 13613: push(@pathitems,$restitle);
13614: $path .= join('/',@pathitems);
13615: }
13616: return ($path,$multiresp);
13617: }
13618:
13619: =pod
13620:
1.464 albertel 13621: =back
1.41 ng 13622:
1.112 bowersj2 13623: =head1 CSV Upload/Handling functions
1.38 albertel 13624:
1.41 ng 13625: =over 4
13626:
1.648 raeburn 13627: =item * &upfile_store($r)
1.41 ng 13628:
13629: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13630: needs $env{'form.upfile'}
1.41 ng 13631: returns $datatoken to be put into hidden field
13632:
13633: =cut
1.31 albertel 13634:
13635: sub upfile_store {
13636: my $r=shift;
1.258 albertel 13637: $env{'form.upfile'}=~s/\r/\n/gs;
13638: $env{'form.upfile'}=~s/\f/\n/gs;
13639: $env{'form.upfile'}=~s/\n+/\n/gs;
13640: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13641:
1.1075.2.128 raeburn 13642: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13643: '_enroll_'.$env{'request.course.id'}.'_'.
13644: time.'_'.$$);
13645: return if ($datatoken eq '');
13646:
1.31 albertel 13647: {
1.158 raeburn 13648: my $datafile = $r->dir_config('lonDaemons').
13649: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13650: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13651: print $fh $env{'form.upfile'};
1.158 raeburn 13652: close($fh);
13653: }
1.31 albertel 13654: }
13655: return $datatoken;
13656: }
13657:
1.56 matthew 13658: =pod
13659:
1.1075.2.128 raeburn 13660: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13661:
13662: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13663: $datatoken is the name to assign to the temporary file.
1.258 albertel 13664: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13665:
13666: =cut
1.31 albertel 13667:
13668: sub load_tmp_file {
1.1075.2.128 raeburn 13669: my ($r,$datatoken) = @_;
13670: return if ($datatoken eq '');
1.31 albertel 13671: my @studentdata=();
13672: {
1.158 raeburn 13673: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13674: '/tmp/'.$datatoken.'.tmp';
13675: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13676: @studentdata=<$fh>;
13677: close($fh);
13678: }
1.31 albertel 13679: }
1.258 albertel 13680: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13681: }
13682:
1.1075.2.128 raeburn 13683: sub valid_datatoken {
13684: my ($datatoken) = @_;
1.1075.2.131 raeburn 13685: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13686: return $datatoken;
13687: }
13688: return;
13689: }
13690:
1.56 matthew 13691: =pod
13692:
1.648 raeburn 13693: =item * &upfile_record_sep()
1.41 ng 13694:
13695: Separate uploaded file into records
13696: returns array of records,
1.258 albertel 13697: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13698:
13699: =cut
1.31 albertel 13700:
13701: sub upfile_record_sep {
1.258 albertel 13702: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13703: } else {
1.248 albertel 13704: my @records;
1.258 albertel 13705: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13706: if ($line=~/^\s*$/) { next; }
13707: push(@records,$line);
13708: }
13709: return @records;
1.31 albertel 13710: }
13711: }
13712:
1.56 matthew 13713: =pod
13714:
1.648 raeburn 13715: =item * &record_sep($record)
1.41 ng 13716:
1.258 albertel 13717: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13718:
13719: =cut
13720:
1.263 www 13721: sub takeleft {
13722: my $index=shift;
13723: return substr('0000'.$index,-4,4);
13724: }
13725:
1.31 albertel 13726: sub record_sep {
13727: my $record=shift;
13728: my %components=();
1.258 albertel 13729: if ($env{'form.upfiletype'} eq 'xml') {
13730: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13731: my $i=0;
1.356 albertel 13732: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13733: $field=~s/^(\"|\')//;
13734: $field=~s/(\"|\')$//;
1.263 www 13735: $components{&takeleft($i)}=$field;
1.31 albertel 13736: $i++;
13737: }
1.258 albertel 13738: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13739: my $i=0;
1.356 albertel 13740: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13741: $field=~s/^(\"|\')//;
13742: $field=~s/(\"|\')$//;
1.263 www 13743: $components{&takeleft($i)}=$field;
1.31 albertel 13744: $i++;
13745: }
13746: } else {
1.561 www 13747: my $separator=',';
1.480 banghart 13748: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13749: $separator=';';
1.480 banghart 13750: }
1.31 albertel 13751: my $i=0;
1.561 www 13752: # the character we are looking for to indicate the end of a quote or a record
13753: my $looking_for=$separator;
13754: # do not add the characters to the fields
13755: my $ignore=0;
13756: # we just encountered a separator (or the beginning of the record)
13757: my $just_found_separator=1;
13758: # store the field we are working on here
13759: my $field='';
13760: # work our way through all characters in record
13761: foreach my $character ($record=~/(.)/g) {
13762: if ($character eq $looking_for) {
13763: if ($character ne $separator) {
13764: # Found the end of a quote, again looking for separator
13765: $looking_for=$separator;
13766: $ignore=1;
13767: } else {
13768: # Found a separator, store away what we got
13769: $components{&takeleft($i)}=$field;
13770: $i++;
13771: $just_found_separator=1;
13772: $ignore=0;
13773: $field='';
13774: }
13775: next;
13776: }
13777: # single or double quotation marks after a separator indicate beginning of a quote
13778: # we are now looking for the end of the quote and need to ignore separators
13779: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13780: $looking_for=$character;
13781: next;
13782: }
13783: # ignore would be true after we reached the end of a quote
13784: if ($ignore) { next; }
13785: if (($just_found_separator) && ($character=~/\s/)) { next; }
13786: $field.=$character;
13787: $just_found_separator=0;
1.31 albertel 13788: }
1.561 www 13789: # catch the very last entry, since we never encountered the separator
13790: $components{&takeleft($i)}=$field;
1.31 albertel 13791: }
13792: return %components;
13793: }
13794:
1.144 matthew 13795: ######################################################
13796: ######################################################
13797:
1.56 matthew 13798: =pod
13799:
1.648 raeburn 13800: =item * &upfile_select_html()
1.41 ng 13801:
1.144 matthew 13802: Return HTML code to select a file from the users machine and specify
13803: the file type.
1.41 ng 13804:
13805: =cut
13806:
1.144 matthew 13807: ######################################################
13808: ######################################################
1.31 albertel 13809: sub upfile_select_html {
1.144 matthew 13810: my %Types = (
13811: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13812: semisv => &mt('Semicolon separated values'),
1.144 matthew 13813: space => &mt('Space separated'),
13814: tab => &mt('Tabulator separated'),
13815: # xml => &mt('HTML/XML'),
13816: );
13817: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13818: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13819: foreach my $type (sort(keys(%Types))) {
13820: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13821: }
13822: $Str .= "</select>\n";
13823: return $Str;
1.31 albertel 13824: }
13825:
1.301 albertel 13826: sub get_samples {
13827: my ($records,$toget) = @_;
13828: my @samples=({});
13829: my $got=0;
13830: foreach my $rec (@$records) {
13831: my %temp = &record_sep($rec);
13832: if (! grep(/\S/, values(%temp))) { next; }
13833: if (%temp) {
13834: $samples[$got]=\%temp;
13835: $got++;
13836: if ($got == $toget) { last; }
13837: }
13838: }
13839: return \@samples;
13840: }
13841:
1.144 matthew 13842: ######################################################
13843: ######################################################
13844:
1.56 matthew 13845: =pod
13846:
1.648 raeburn 13847: =item * &csv_print_samples($r,$records)
1.41 ng 13848:
13849: Prints a table of sample values from each column uploaded $r is an
13850: Apache Request ref, $records is an arrayref from
13851: &Apache::loncommon::upfile_record_sep
13852:
13853: =cut
13854:
1.144 matthew 13855: ######################################################
13856: ######################################################
1.31 albertel 13857: sub csv_print_samples {
13858: my ($r,$records) = @_;
1.662 bisitz 13859: my $samples = &get_samples($records,5);
1.301 albertel 13860:
1.594 raeburn 13861: $r->print(&mt('Samples').'<br />'.&start_data_table().
13862: &start_data_table_header_row());
1.356 albertel 13863: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13864: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13865: $r->print(&end_data_table_header_row());
1.301 albertel 13866: foreach my $hash (@$samples) {
1.594 raeburn 13867: $r->print(&start_data_table_row());
1.356 albertel 13868: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13869: $r->print('<td>');
1.356 albertel 13870: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13871: $r->print('</td>');
13872: }
1.594 raeburn 13873: $r->print(&end_data_table_row());
1.31 albertel 13874: }
1.594 raeburn 13875: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13876: }
13877:
1.144 matthew 13878: ######################################################
13879: ######################################################
13880:
1.56 matthew 13881: =pod
13882:
1.648 raeburn 13883: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13884:
13885: Prints a table to create associations between values and table columns.
1.144 matthew 13886:
1.41 ng 13887: $r is an Apache Request ref,
13888: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13889: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13890:
13891: =cut
13892:
1.144 matthew 13893: ######################################################
13894: ######################################################
1.31 albertel 13895: sub csv_print_select_table {
13896: my ($r,$records,$d) = @_;
1.301 albertel 13897: my $i=0;
13898: my $samples = &get_samples($records,1);
1.144 matthew 13899: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13900: &start_data_table().&start_data_table_header_row().
1.144 matthew 13901: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13902: '<th>'.&mt('Column').'</th>'.
13903: &end_data_table_header_row()."\n");
1.356 albertel 13904: foreach my $array_ref (@$d) {
13905: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13906: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13907:
1.875 bisitz 13908: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13909: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13910: $r->print('<option value="none"></option>');
1.356 albertel 13911: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13912: $r->print('<option value="'.$sample.'"'.
13913: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13914: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13915: }
1.594 raeburn 13916: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13917: $i++;
13918: }
1.594 raeburn 13919: $r->print(&end_data_table());
1.31 albertel 13920: $i--;
13921: return $i;
13922: }
1.56 matthew 13923:
1.144 matthew 13924: ######################################################
13925: ######################################################
13926:
1.56 matthew 13927: =pod
1.31 albertel 13928:
1.648 raeburn 13929: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13930:
13931: Prints a table of sample values from the upload and can make associate samples to internal names.
13932:
13933: $r is an Apache Request ref,
13934: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13935: $d is an array of 2 element arrays (internal name, displayed name)
13936:
13937: =cut
13938:
1.144 matthew 13939: ######################################################
13940: ######################################################
1.31 albertel 13941: sub csv_samples_select_table {
13942: my ($r,$records,$d) = @_;
13943: my $i=0;
1.144 matthew 13944: #
1.662 bisitz 13945: my $max_samples = 5;
13946: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13947: $r->print(&start_data_table().
13948: &start_data_table_header_row().'<th>'.
13949: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13950: &end_data_table_header_row());
1.301 albertel 13951:
13952: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13953: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13954: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13955: foreach my $option (@$d) {
13956: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13957: $r->print('<option value="'.$value.'"'.
1.253 albertel 13958: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13959: $display.'</option>');
1.31 albertel 13960: }
13961: $r->print('</select></td><td>');
1.662 bisitz 13962: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13963: if (defined($samples->[$line]{$key})) {
13964: $r->print($samples->[$line]{$key}."<br />\n");
13965: }
13966: }
1.594 raeburn 13967: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13968: $i++;
13969: }
1.594 raeburn 13970: $r->print(&end_data_table());
1.31 albertel 13971: $i--;
13972: return($i);
1.115 matthew 13973: }
13974:
1.144 matthew 13975: ######################################################
13976: ######################################################
13977:
1.115 matthew 13978: =pod
13979:
1.648 raeburn 13980: =item * &clean_excel_name($name)
1.115 matthew 13981:
13982: Returns a replacement for $name which does not contain any illegal characters.
13983:
13984: =cut
13985:
1.144 matthew 13986: ######################################################
13987: ######################################################
1.115 matthew 13988: sub clean_excel_name {
13989: my ($name) = @_;
13990: $name =~ s/[:\*\?\/\\]//g;
13991: if (length($name) > 31) {
13992: $name = substr($name,0,31);
13993: }
13994: return $name;
1.25 albertel 13995: }
1.84 albertel 13996:
1.85 albertel 13997: =pod
13998:
1.648 raeburn 13999: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14000:
14001: Returns either 1 or undef
14002:
14003: 1 if the part is to be hidden, undef if it is to be shown
14004:
14005: Arguments are:
14006:
14007: $id the id of the part to be checked
14008: $symb, optional the symb of the resource to check
14009: $udom, optional the domain of the user to check for
14010: $uname, optional the username of the user to check for
14011:
14012: =cut
1.84 albertel 14013:
14014: sub check_if_partid_hidden {
14015: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14016: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14017: $symb,$udom,$uname);
1.141 albertel 14018: my $truth=1;
14019: #if the string starts with !, then the list is the list to show not hide
14020: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14021: my @hiddenlist=split(/,/,$hiddenparts);
14022: foreach my $checkid (@hiddenlist) {
1.141 albertel 14023: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14024: }
1.141 albertel 14025: return !$truth;
1.84 albertel 14026: }
1.127 matthew 14027:
1.138 matthew 14028:
14029: ############################################################
14030: ############################################################
14031:
14032: =pod
14033:
1.157 matthew 14034: =back
14035:
1.138 matthew 14036: =head1 cgi-bin script and graphing routines
14037:
1.157 matthew 14038: =over 4
14039:
1.648 raeburn 14040: =item * &get_cgi_id()
1.138 matthew 14041:
14042: Inputs: none
14043:
14044: Returns an id which can be used to pass environment variables
14045: to various cgi-bin scripts. These environment variables will
14046: be removed from the users environment after a given time by
14047: the routine &Apache::lonnet::transfer_profile_to_env.
14048:
14049: =cut
14050:
14051: ############################################################
14052: ############################################################
1.152 albertel 14053: my $uniq=0;
1.136 matthew 14054: sub get_cgi_id {
1.154 albertel 14055: $uniq=($uniq+1)%100000;
1.280 albertel 14056: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14057: }
14058:
1.127 matthew 14059: ############################################################
14060: ############################################################
14061:
14062: =pod
14063:
1.648 raeburn 14064: =item * &DrawBarGraph()
1.127 matthew 14065:
1.138 matthew 14066: Facilitates the plotting of data in a (stacked) bar graph.
14067: Puts plot definition data into the users environment in order for
14068: graph.png to plot it. Returns an <img> tag for the plot.
14069: The bars on the plot are labeled '1','2',...,'n'.
14070:
14071: Inputs:
14072:
14073: =over 4
14074:
14075: =item $Title: string, the title of the plot
14076:
14077: =item $xlabel: string, text describing the X-axis of the plot
14078:
14079: =item $ylabel: string, text describing the Y-axis of the plot
14080:
14081: =item $Max: scalar, the maximum Y value to use in the plot
14082: If $Max is < any data point, the graph will not be rendered.
14083:
1.140 matthew 14084: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14085: they are plotted. If undefined, default values will be used.
14086:
1.178 matthew 14087: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14088:
1.138 matthew 14089: =item @Values: An array of array references. Each array reference holds data
14090: to be plotted in a stacked bar chart.
14091:
1.239 matthew 14092: =item If the final element of @Values is a hash reference the key/value
14093: pairs will be added to the graph definition.
14094:
1.138 matthew 14095: =back
14096:
14097: Returns:
14098:
14099: An <img> tag which references graph.png and the appropriate identifying
14100: information for the plot.
14101:
1.127 matthew 14102: =cut
14103:
14104: ############################################################
14105: ############################################################
1.134 matthew 14106: sub DrawBarGraph {
1.178 matthew 14107: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14108: #
14109: if (! defined($colors)) {
14110: $colors = ['#33ff00',
14111: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14112: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14113: ];
14114: }
1.228 matthew 14115: my $extra_settings = {};
14116: if (ref($Values[-1]) eq 'HASH') {
14117: $extra_settings = pop(@Values);
14118: }
1.127 matthew 14119: #
1.136 matthew 14120: my $identifier = &get_cgi_id();
14121: my $id = 'cgi.'.$identifier;
1.129 matthew 14122: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14123: return '';
14124: }
1.225 matthew 14125: #
14126: my @Labels;
14127: if (defined($labels)) {
14128: @Labels = @$labels;
14129: } else {
14130: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 14131: push(@Labels,$i+1);
1.225 matthew 14132: }
14133: }
14134: #
1.129 matthew 14135: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14136: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14137: my %ValuesHash;
14138: my $NumSets=1;
14139: foreach my $array (@Values) {
14140: next if (! ref($array));
1.136 matthew 14141: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14142: join(',',@$array);
1.129 matthew 14143: }
1.127 matthew 14144: #
1.136 matthew 14145: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14146: if ($NumBars < 3) {
14147: $width = 120+$NumBars*32;
1.220 matthew 14148: $xskip = 1;
1.225 matthew 14149: $bar_width = 30;
14150: } elsif ($NumBars < 5) {
14151: $width = 120+$NumBars*20;
14152: $xskip = 1;
14153: $bar_width = 20;
1.220 matthew 14154: } elsif ($NumBars < 10) {
1.136 matthew 14155: $width = 120+$NumBars*15;
14156: $xskip = 1;
14157: $bar_width = 15;
14158: } elsif ($NumBars <= 25) {
14159: $width = 120+$NumBars*11;
14160: $xskip = 5;
14161: $bar_width = 8;
14162: } elsif ($NumBars <= 50) {
14163: $width = 120+$NumBars*8;
14164: $xskip = 5;
14165: $bar_width = 4;
14166: } else {
14167: $width = 120+$NumBars*8;
14168: $xskip = 5;
14169: $bar_width = 4;
14170: }
14171: #
1.137 matthew 14172: $Max = 1 if ($Max < 1);
14173: if ( int($Max) < $Max ) {
14174: $Max++;
14175: $Max = int($Max);
14176: }
1.127 matthew 14177: $Title = '' if (! defined($Title));
14178: $xlabel = '' if (! defined($xlabel));
14179: $ylabel = '' if (! defined($ylabel));
1.369 www 14180: $ValuesHash{$id.'.title'} = &escape($Title);
14181: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14182: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14183: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14184: $ValuesHash{$id.'.NumBars'} = $NumBars;
14185: $ValuesHash{$id.'.NumSets'} = $NumSets;
14186: $ValuesHash{$id.'.PlotType'} = 'bar';
14187: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14188: $ValuesHash{$id.'.height'} = $height;
14189: $ValuesHash{$id.'.width'} = $width;
14190: $ValuesHash{$id.'.xskip'} = $xskip;
14191: $ValuesHash{$id.'.bar_width'} = $bar_width;
14192: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14193: #
1.228 matthew 14194: # Deal with other parameters
14195: while (my ($key,$value) = each(%$extra_settings)) {
14196: $ValuesHash{$id.'.'.$key} = $value;
14197: }
14198: #
1.646 raeburn 14199: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14200: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14201: }
14202:
14203: ############################################################
14204: ############################################################
14205:
14206: =pod
14207:
1.648 raeburn 14208: =item * &DrawXYGraph()
1.137 matthew 14209:
1.138 matthew 14210: Facilitates the plotting of data in an XY graph.
14211: Puts plot definition data into the users environment in order for
14212: graph.png to plot it. Returns an <img> tag for the plot.
14213:
14214: Inputs:
14215:
14216: =over 4
14217:
14218: =item $Title: string, the title of the plot
14219:
14220: =item $xlabel: string, text describing the X-axis of the plot
14221:
14222: =item $ylabel: string, text describing the Y-axis of the plot
14223:
14224: =item $Max: scalar, the maximum Y value to use in the plot
14225: If $Max is < any data point, the graph will not be rendered.
14226:
14227: =item $colors: Array ref containing the hex color codes for the data to be
14228: plotted in. If undefined, default values will be used.
14229:
14230: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14231:
14232: =item $Ydata: Array ref containing Array refs.
1.185 www 14233: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14234:
14235: =item %Values: hash indicating or overriding any default values which are
14236: passed to graph.png.
14237: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14238:
14239: =back
14240:
14241: Returns:
14242:
14243: An <img> tag which references graph.png and the appropriate identifying
14244: information for the plot.
14245:
1.137 matthew 14246: =cut
14247:
14248: ############################################################
14249: ############################################################
14250: sub DrawXYGraph {
14251: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14252: #
14253: # Create the identifier for the graph
14254: my $identifier = &get_cgi_id();
14255: my $id = 'cgi.'.$identifier;
14256: #
14257: $Title = '' if (! defined($Title));
14258: $xlabel = '' if (! defined($xlabel));
14259: $ylabel = '' if (! defined($ylabel));
14260: my %ValuesHash =
14261: (
1.369 www 14262: $id.'.title' => &escape($Title),
14263: $id.'.xlabel' => &escape($xlabel),
14264: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14265: $id.'.y_max_value'=> $Max,
14266: $id.'.labels' => join(',',@$Xlabels),
14267: $id.'.PlotType' => 'XY',
14268: );
14269: #
14270: if (defined($colors) && ref($colors) eq 'ARRAY') {
14271: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14272: }
14273: #
14274: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14275: return '';
14276: }
14277: my $NumSets=1;
1.138 matthew 14278: foreach my $array (@{$Ydata}){
1.137 matthew 14279: next if (! ref($array));
14280: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14281: }
1.138 matthew 14282: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14283: #
14284: # Deal with other parameters
14285: while (my ($key,$value) = each(%Values)) {
14286: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14287: }
14288: #
1.646 raeburn 14289: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14290: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14291: }
14292:
14293: ############################################################
14294: ############################################################
14295:
14296: =pod
14297:
1.648 raeburn 14298: =item * &DrawXYYGraph()
1.138 matthew 14299:
14300: Facilitates the plotting of data in an XY graph with two Y axes.
14301: Puts plot definition data into the users environment in order for
14302: graph.png to plot it. Returns an <img> tag for the plot.
14303:
14304: Inputs:
14305:
14306: =over 4
14307:
14308: =item $Title: string, the title of the plot
14309:
14310: =item $xlabel: string, text describing the X-axis of the plot
14311:
14312: =item $ylabel: string, text describing the Y-axis of the plot
14313:
14314: =item $colors: Array ref containing the hex color codes for the data to be
14315: plotted in. If undefined, default values will be used.
14316:
14317: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14318:
14319: =item $Ydata1: The first data set
14320:
14321: =item $Min1: The minimum value of the left Y-axis
14322:
14323: =item $Max1: The maximum value of the left Y-axis
14324:
14325: =item $Ydata2: The second data set
14326:
14327: =item $Min2: The minimum value of the right Y-axis
14328:
14329: =item $Max2: The maximum value of the left Y-axis
14330:
14331: =item %Values: hash indicating or overriding any default values which are
14332: passed to graph.png.
14333: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14334:
14335: =back
14336:
14337: Returns:
14338:
14339: An <img> tag which references graph.png and the appropriate identifying
14340: information for the plot.
1.136 matthew 14341:
14342: =cut
14343:
14344: ############################################################
14345: ############################################################
1.137 matthew 14346: sub DrawXYYGraph {
14347: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14348: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14349: #
14350: # Create the identifier for the graph
14351: my $identifier = &get_cgi_id();
14352: my $id = 'cgi.'.$identifier;
14353: #
14354: $Title = '' if (! defined($Title));
14355: $xlabel = '' if (! defined($xlabel));
14356: $ylabel = '' if (! defined($ylabel));
14357: my %ValuesHash =
14358: (
1.369 www 14359: $id.'.title' => &escape($Title),
14360: $id.'.xlabel' => &escape($xlabel),
14361: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14362: $id.'.labels' => join(',',@$Xlabels),
14363: $id.'.PlotType' => 'XY',
14364: $id.'.NumSets' => 2,
1.137 matthew 14365: $id.'.two_axes' => 1,
14366: $id.'.y1_max_value' => $Max1,
14367: $id.'.y1_min_value' => $Min1,
14368: $id.'.y2_max_value' => $Max2,
14369: $id.'.y2_min_value' => $Min2,
1.136 matthew 14370: );
14371: #
1.137 matthew 14372: if (defined($colors) && ref($colors) eq 'ARRAY') {
14373: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14374: }
14375: #
14376: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14377: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14378: return '';
14379: }
14380: my $NumSets=1;
1.137 matthew 14381: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14382: next if (! ref($array));
14383: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14384: }
14385: #
14386: # Deal with other parameters
14387: while (my ($key,$value) = each(%Values)) {
14388: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14389: }
14390: #
1.646 raeburn 14391: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14392: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14393: }
14394:
14395: ############################################################
14396: ############################################################
14397:
14398: =pod
14399:
1.157 matthew 14400: =back
14401:
1.139 matthew 14402: =head1 Statistics helper routines?
14403:
14404: Bad place for them but what the hell.
14405:
1.157 matthew 14406: =over 4
14407:
1.648 raeburn 14408: =item * &chartlink()
1.139 matthew 14409:
14410: Returns a link to the chart for a specific student.
14411:
14412: Inputs:
14413:
14414: =over 4
14415:
14416: =item $linktext: The text of the link
14417:
14418: =item $sname: The students username
14419:
14420: =item $sdomain: The students domain
14421:
14422: =back
14423:
1.157 matthew 14424: =back
14425:
1.139 matthew 14426: =cut
14427:
14428: ############################################################
14429: ############################################################
14430: sub chartlink {
14431: my ($linktext, $sname, $sdomain) = @_;
14432: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14433: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14434: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14435: '">'.$linktext.'</a>';
1.153 matthew 14436: }
14437:
14438: #######################################################
14439: #######################################################
14440:
14441: =pod
14442:
14443: =head1 Course Environment Routines
1.157 matthew 14444:
14445: =over 4
1.153 matthew 14446:
1.648 raeburn 14447: =item * &restore_course_settings()
1.153 matthew 14448:
1.648 raeburn 14449: =item * &store_course_settings()
1.153 matthew 14450:
14451: Restores/Store indicated form parameters from the course environment.
14452: Will not overwrite existing values of the form parameters.
14453:
14454: Inputs:
14455: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14456:
14457: a hash ref describing the data to be stored. For example:
14458:
14459: %Save_Parameters = ('Status' => 'scalar',
14460: 'chartoutputmode' => 'scalar',
14461: 'chartoutputdata' => 'scalar',
14462: 'Section' => 'array',
1.373 raeburn 14463: 'Group' => 'array',
1.153 matthew 14464: 'StudentData' => 'array',
14465: 'Maps' => 'array');
14466:
14467: Returns: both routines return nothing
14468:
1.631 raeburn 14469: =back
14470:
1.153 matthew 14471: =cut
14472:
14473: #######################################################
14474: #######################################################
14475: sub store_course_settings {
1.496 albertel 14476: return &store_settings($env{'request.course.id'},@_);
14477: }
14478:
14479: sub store_settings {
1.153 matthew 14480: # save to the environment
14481: # appenv the same items, just to be safe
1.300 albertel 14482: my $udom = $env{'user.domain'};
14483: my $uname = $env{'user.name'};
1.496 albertel 14484: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14485: my %SaveHash;
14486: my %AppHash;
14487: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14488: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14489: my $envname = 'environment.'.$basename;
1.258 albertel 14490: if (exists($env{'form.'.$setting})) {
1.153 matthew 14491: # Save this value away
14492: if ($type eq 'scalar' &&
1.258 albertel 14493: (! exists($env{$envname}) ||
14494: $env{$envname} ne $env{'form.'.$setting})) {
14495: $SaveHash{$basename} = $env{'form.'.$setting};
14496: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14497: } elsif ($type eq 'array') {
14498: my $stored_form;
1.258 albertel 14499: if (ref($env{'form.'.$setting})) {
1.153 matthew 14500: $stored_form = join(',',
14501: map {
1.369 www 14502: &escape($_);
1.258 albertel 14503: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14504: } else {
14505: $stored_form =
1.369 www 14506: &escape($env{'form.'.$setting});
1.153 matthew 14507: }
14508: # Determine if the array contents are the same.
1.258 albertel 14509: if ($stored_form ne $env{$envname}) {
1.153 matthew 14510: $SaveHash{$basename} = $stored_form;
14511: $AppHash{$envname} = $stored_form;
14512: }
14513: }
14514: }
14515: }
14516: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14517: $udom,$uname);
1.153 matthew 14518: if ($put_result !~ /^(ok|delayed)/) {
14519: &Apache::lonnet::logthis('unable to save form parameters, '.
14520: 'got error:'.$put_result);
14521: }
14522: # Make sure these settings stick around in this session, too
1.646 raeburn 14523: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14524: return;
14525: }
14526:
14527: sub restore_course_settings {
1.499 albertel 14528: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14529: }
14530:
14531: sub restore_settings {
14532: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14533: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14534: next if (exists($env{'form.'.$setting}));
1.496 albertel 14535: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14536: '.'.$setting;
1.258 albertel 14537: if (exists($env{$envname})) {
1.153 matthew 14538: if ($type eq 'scalar') {
1.258 albertel 14539: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14540: } elsif ($type eq 'array') {
1.258 albertel 14541: $env{'form.'.$setting} = [
1.153 matthew 14542: map {
1.369 www 14543: &unescape($_);
1.258 albertel 14544: } split(',',$env{$envname})
1.153 matthew 14545: ];
14546: }
14547: }
14548: }
1.127 matthew 14549: }
14550:
1.618 raeburn 14551: #######################################################
14552: #######################################################
14553:
14554: =pod
14555:
14556: =head1 Domain E-mail Routines
14557:
14558: =over 4
14559:
1.648 raeburn 14560: =item * &build_recipient_list()
1.618 raeburn 14561:
1.1075.2.44 raeburn 14562: Build recipient lists for following types of e-mail:
1.766 raeburn 14563: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14564: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14565: module change checking, student/employee ID conflict checks, as
14566: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14567: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14568:
14569: Inputs:
1.1075.2.44 raeburn 14570: defmail (scalar - email address of default recipient),
14571: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14572: requestsmail, updatesmail, or idconflictsmail).
14573:
1.619 raeburn 14574: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14575:
14576: origmail (scalar - email address of recipient from loncapa.conf,
14577: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14578:
1.1075.2.139 raeburn 14579: $requname username of requester (if mailing type is helpdeskmail)
14580:
14581: $requdom domain of requester (if mailing type is helpdeskmail)
14582:
14583: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14584:
1.655 raeburn 14585: Returns: comma separated list of addresses to which to send e-mail.
14586:
14587: =back
1.618 raeburn 14588:
14589: =cut
14590:
14591: ############################################################
14592: ############################################################
14593: sub build_recipient_list {
1.1075.2.139 raeburn 14594: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14595: my @recipients;
1.1075.2.122 raeburn 14596: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14597: my %domconfig =
1.1075.2.122 raeburn 14598: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14599: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14600: if (exists($domconfig{'contacts'}{$mailing})) {
14601: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14602: my @contacts = ('adminemail','supportemail');
14603: foreach my $item (@contacts) {
14604: if ($domconfig{'contacts'}{$mailing}{$item}) {
14605: my $addr = $domconfig{'contacts'}{$item};
14606: if (!grep(/^\Q$addr\E$/,@recipients)) {
14607: push(@recipients,$addr);
14608: }
1.619 raeburn 14609: }
1.1075.2.122 raeburn 14610: }
14611: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14612: if ($mailing eq 'helpdeskmail') {
14613: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14614: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14615: my @ok_bccs;
14616: foreach my $bcc (@bccs) {
14617: $bcc =~ s/^\s+//g;
14618: $bcc =~ s/\s+$//g;
14619: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14620: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14621: push(@ok_bccs,$bcc);
14622: }
14623: }
14624: }
14625: if (@ok_bccs > 0) {
14626: $allbcc = join(', ',@ok_bccs);
14627: }
14628: }
14629: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14630: }
14631: }
1.766 raeburn 14632: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14633: $lastresort = $origmail;
1.618 raeburn 14634: }
1.1075.2.139 raeburn 14635: if ($mailing eq 'helpdeskmail') {
14636: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14637: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14638: my ($inststatus,$inststatus_checked);
14639: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14640: ($env{'user.domain'} ne 'public')) {
14641: $inststatus_checked = 1;
14642: $inststatus = $env{'environment.inststatus'};
14643: }
14644: unless ($inststatus_checked) {
14645: if (($requname ne '') && ($requdom ne '')) {
14646: if (($requname =~ /^$match_username$/) &&
14647: ($requdom =~ /^$match_domain$/) &&
14648: (&Apache::lonnet::domain($requdom))) {
14649: my $requhome = &Apache::lonnet::homeserver($requname,
14650: $requdom);
14651: unless ($requhome eq 'no_host') {
14652: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14653: $inststatus = $userenv{'inststatus'};
14654: $inststatus_checked = 1;
14655: }
14656: }
14657: }
14658: }
14659: unless ($inststatus_checked) {
14660: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14661: my %srch = (srchby => 'email',
14662: srchdomain => $defdom,
14663: srchterm => $reqemail,
14664: srchtype => 'exact');
14665: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14666: foreach my $uname (keys(%srch_results)) {
14667: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14668: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14669: $inststatus_checked = 1;
14670: last;
14671: }
14672: }
14673: unless ($inststatus_checked) {
14674: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14675: if ($dirsrchres eq 'ok') {
14676: foreach my $uname (keys(%srch_results)) {
14677: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14678: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14679: $inststatus_checked = 1;
14680: last;
14681: }
14682: }
14683: }
14684: }
14685: }
14686: }
14687: if ($inststatus ne '') {
14688: foreach my $status (split(/\:/,$inststatus)) {
14689: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14690: my @contacts = ('adminemail','supportemail');
14691: foreach my $item (@contacts) {
14692: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14693: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14694: if (!grep(/^\Q$addr\E$/,@recipients)) {
14695: push(@recipients,$addr);
14696: }
14697: }
14698: }
14699: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14700: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14701: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14702: my @ok_bccs;
14703: foreach my $bcc (@bccs) {
14704: $bcc =~ s/^\s+//g;
14705: $bcc =~ s/\s+$//g;
14706: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14707: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14708: push(@ok_bccs,$bcc);
14709: }
14710: }
14711: }
14712: if (@ok_bccs > 0) {
14713: $allbcc = join(', ',@ok_bccs);
14714: }
14715: }
14716: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14717: last;
14718: }
14719: }
14720: }
14721: }
14722: }
1.619 raeburn 14723: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14724: $lastresort = $origmail;
14725: }
1.1075.2.128 raeburn 14726: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14727: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14728: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14729: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14730: my %what = (
14731: perlvar => 1,
14732: );
14733: my $primary = &Apache::lonnet::domain($defdom,'primary');
14734: if ($primary) {
14735: my $gotaddr;
14736: my ($result,$returnhash) =
14737: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14738: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14739: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14740: $lastresort = $returnhash->{'lonSupportEMail'};
14741: $gotaddr = 1;
14742: }
14743: }
14744: unless ($gotaddr) {
14745: my $uintdom = &Apache::lonnet::internet_dom($primary);
14746: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14747: unless ($uintdom eq $intdom) {
14748: my %domconfig =
14749: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14750: if (ref($domconfig{'contacts'}) eq 'HASH') {
14751: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14752: my @contacts = ('adminemail','supportemail');
14753: foreach my $item (@contacts) {
14754: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14755: my $addr = $domconfig{'contacts'}{$item};
14756: if (!grep(/^\Q$addr\E$/,@recipients)) {
14757: push(@recipients,$addr);
14758: }
14759: }
14760: }
14761: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14762: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14763: }
14764: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14765: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14766: my @ok_bccs;
14767: foreach my $bcc (@bccs) {
14768: $bcc =~ s/^\s+//g;
14769: $bcc =~ s/\s+$//g;
14770: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14771: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14772: push(@ok_bccs,$bcc);
14773: }
14774: }
14775: }
14776: if (@ok_bccs > 0) {
14777: $allbcc = join(', ',@ok_bccs);
14778: }
14779: }
14780: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14781: }
14782: }
14783: }
14784: }
14785: }
14786: }
1.618 raeburn 14787: }
1.688 raeburn 14788: if (defined($defmail)) {
14789: if ($defmail ne '') {
14790: push(@recipients,$defmail);
14791: }
1.618 raeburn 14792: }
14793: if ($otheremails) {
1.619 raeburn 14794: my @others;
14795: if ($otheremails =~ /,/) {
14796: @others = split(/,/,$otheremails);
1.618 raeburn 14797: } else {
1.619 raeburn 14798: push(@others,$otheremails);
14799: }
14800: foreach my $addr (@others) {
14801: if (!grep(/^\Q$addr\E$/,@recipients)) {
14802: push(@recipients,$addr);
14803: }
1.618 raeburn 14804: }
14805: }
1.1075.2.128 raeburn 14806: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14807: if ((!@recipients) && ($lastresort ne '')) {
14808: push(@recipients,$lastresort);
14809: }
14810: } elsif ($lastresort ne '') {
14811: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14812: push(@recipients,$lastresort);
14813: }
14814: }
14815: my $recipientlist = join(',',@recipients);
14816: if (wantarray) {
14817: return ($recipientlist,$allbcc,$addtext);
14818: } else {
14819: return $recipientlist;
14820: }
1.618 raeburn 14821: }
14822:
1.127 matthew 14823: ############################################################
14824: ############################################################
1.154 albertel 14825:
1.655 raeburn 14826: =pod
14827:
14828: =head1 Course Catalog Routines
14829:
14830: =over 4
14831:
14832: =item * &gather_categories()
14833:
14834: Converts category definitions - keys of categories hash stored in
14835: coursecategories in configuration.db on the primary library server in a
14836: domain - to an array. Also generates javascript and idx hash used to
14837: generate Domain Coordinator interface for editing Course Categories.
14838:
14839: Inputs:
1.663 raeburn 14840:
1.655 raeburn 14841: categories (reference to hash of category definitions).
1.663 raeburn 14842:
1.655 raeburn 14843: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14844: categories and subcategories).
1.663 raeburn 14845:
1.655 raeburn 14846: idx (reference to hash of counters used in Domain Coordinator interface for
14847: editing Course Categories).
1.663 raeburn 14848:
1.655 raeburn 14849: jsarray (reference to array of categories used to create Javascript arrays for
14850: Domain Coordinator interface for editing Course Categories).
14851:
14852: Returns: nothing
14853:
14854: Side effects: populates cats, idx and jsarray.
14855:
14856: =cut
14857:
14858: sub gather_categories {
14859: my ($categories,$cats,$idx,$jsarray) = @_;
14860: my %counters;
14861: my $num = 0;
14862: foreach my $item (keys(%{$categories})) {
14863: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14864: if ($container eq '' && $depth == 0) {
14865: $cats->[$depth][$categories->{$item}] = $cat;
14866: } else {
14867: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14868: }
14869: my ($escitem,$tail) = split(/:/,$item,2);
14870: if ($counters{$tail} eq '') {
14871: $counters{$tail} = $num;
14872: $num ++;
14873: }
14874: if (ref($idx) eq 'HASH') {
14875: $idx->{$item} = $counters{$tail};
14876: }
14877: if (ref($jsarray) eq 'ARRAY') {
14878: push(@{$jsarray->[$counters{$tail}]},$item);
14879: }
14880: }
14881: return;
14882: }
14883:
14884: =pod
14885:
14886: =item * &extract_categories()
14887:
14888: Used to generate breadcrumb trails for course categories.
14889:
14890: Inputs:
1.663 raeburn 14891:
1.655 raeburn 14892: categories (reference to hash of category definitions).
1.663 raeburn 14893:
1.655 raeburn 14894: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14895: categories and subcategories).
1.663 raeburn 14896:
1.655 raeburn 14897: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14898:
1.655 raeburn 14899: allitems (reference to hash - key is category key
14900: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14901:
1.655 raeburn 14902: idx (reference to hash of counters used in Domain Coordinator interface for
14903: editing Course Categories).
1.663 raeburn 14904:
1.655 raeburn 14905: jsarray (reference to array of categories used to create Javascript arrays for
14906: Domain Coordinator interface for editing Course Categories).
14907:
1.665 raeburn 14908: subcats (reference to hash of arrays containing all subcategories within each
14909: category, -recursive)
14910:
1.1075.2.132 raeburn 14911: maxd (reference to hash used to hold max depth for all top-level categories).
14912:
1.655 raeburn 14913: Returns: nothing
14914:
14915: Side effects: populates trails and allitems hash references.
14916:
14917: =cut
14918:
14919: sub extract_categories {
1.1075.2.132 raeburn 14920: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14921: if (ref($categories) eq 'HASH') {
14922: &gather_categories($categories,$cats,$idx,$jsarray);
14923: if (ref($cats->[0]) eq 'ARRAY') {
14924: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14925: my $name = $cats->[0][$i];
14926: my $item = &escape($name).'::0';
14927: my $trailstr;
14928: if ($name eq 'instcode') {
14929: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14930: } elsif ($name eq 'communities') {
14931: $trailstr = &mt('Communities');
1.655 raeburn 14932: } else {
14933: $trailstr = $name;
14934: }
14935: if ($allitems->{$item} eq '') {
14936: push(@{$trails},$trailstr);
14937: $allitems->{$item} = scalar(@{$trails})-1;
14938: }
14939: my @parents = ($name);
14940: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14941: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14942: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14943: if (ref($subcats) eq 'HASH') {
14944: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14945: }
1.1075.2.132 raeburn 14946: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14947: }
14948: } else {
14949: if (ref($subcats) eq 'HASH') {
14950: $subcats->{$item} = [];
1.655 raeburn 14951: }
1.1075.2.132 raeburn 14952: if (ref($maxd) eq 'HASH') {
14953: $maxd->{$name} = 1;
14954: }
1.655 raeburn 14955: }
14956: }
14957: }
14958: }
14959: return;
14960: }
14961:
14962: =pod
14963:
1.1075.2.56 raeburn 14964: =item * &recurse_categories()
1.655 raeburn 14965:
14966: Recursively used to generate breadcrumb trails for course categories.
14967:
14968: Inputs:
1.663 raeburn 14969:
1.655 raeburn 14970: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14971: categories and subcategories).
1.663 raeburn 14972:
1.655 raeburn 14973: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14974:
14975: category (current course category, for which breadcrumb trail is being generated).
14976:
14977: trails (reference to array of breadcrumb trails for each category).
14978:
1.655 raeburn 14979: allitems (reference to hash - key is category key
14980: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14981:
1.655 raeburn 14982: parents (array containing containers directories for current category,
14983: back to top level).
14984:
14985: Returns: nothing
14986:
14987: Side effects: populates trails and allitems hash references
14988:
14989: =cut
14990:
14991: sub recurse_categories {
1.1075.2.132 raeburn 14992: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14993: my $shallower = $depth - 1;
14994: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14995: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14996: my $name = $cats->[$depth]{$category}[$k];
14997: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.164 raeburn 14998: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14999: if ($allitems->{$item} eq '') {
15000: push(@{$trails},$trailstr);
15001: $allitems->{$item} = scalar(@{$trails})-1;
15002: }
15003: my $deeper = $depth+1;
15004: push(@{$parents},$category);
1.665 raeburn 15005: if (ref($subcats) eq 'HASH') {
15006: my $subcat = &escape($name).':'.$category.':'.$depth;
15007: for (my $j=@{$parents}; $j>=0; $j--) {
15008: my $higher;
15009: if ($j > 0) {
15010: $higher = &escape($parents->[$j]).':'.
15011: &escape($parents->[$j-1]).':'.$j;
15012: } else {
15013: $higher = &escape($parents->[$j]).'::'.$j;
15014: }
15015: push(@{$subcats->{$higher}},$subcat);
15016: }
15017: }
15018: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 15019: $subcats,$maxd);
1.655 raeburn 15020: pop(@{$parents});
15021: }
15022: } else {
15023: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 15024: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15025: if ($allitems->{$item} eq '') {
15026: push(@{$trails},$trailstr);
15027: $allitems->{$item} = scalar(@{$trails})-1;
15028: }
1.1075.2.132 raeburn 15029: if (ref($maxd) eq 'HASH') {
15030: if ($depth > $maxd->{$parents->[0]}) {
15031: $maxd->{$parents->[0]} = $depth;
15032: }
15033: }
1.655 raeburn 15034: }
15035: return;
15036: }
15037:
1.663 raeburn 15038: =pod
15039:
1.1075.2.56 raeburn 15040: =item * &assign_categories_table()
1.663 raeburn 15041:
15042: Create a datatable for display of hierarchical categories in a domain,
15043: with checkboxes to allow a course to be categorized.
15044:
15045: Inputs:
15046:
15047: cathash - reference to hash of categories defined for the domain (from
15048: configuration.db)
15049:
15050: currcat - scalar with an & separated list of categories assigned to a course.
15051:
1.919 raeburn 15052: type - scalar contains course type (Course or Community).
15053:
1.1075.2.117 raeburn 15054: disabled - scalar (optional) contains disabled="disabled" if input elements are
15055: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15056:
1.663 raeburn 15057: Returns: $output (markup to be displayed)
15058:
15059: =cut
15060:
15061: sub assign_categories_table {
1.1075.2.117 raeburn 15062: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15063: my $output;
15064: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 15065: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15066: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15067: $maxdepth = scalar(@cats);
15068: if (@cats > 0) {
15069: my $itemcount = 0;
15070: if (ref($cats[0]) eq 'ARRAY') {
15071: my @currcategories;
15072: if ($currcat ne '') {
15073: @currcategories = split('&',$currcat);
15074: }
1.919 raeburn 15075: my $table;
1.663 raeburn 15076: for (my $i=0; $i<@{$cats[0]}; $i++) {
15077: my $parent = $cats[0][$i];
1.919 raeburn 15078: next if ($parent eq 'instcode');
15079: if ($type eq 'Community') {
15080: next unless ($parent eq 'communities');
15081: } else {
15082: next if ($parent eq 'communities');
15083: }
1.663 raeburn 15084: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15085: my $item = &escape($parent).'::0';
15086: my $checked = '';
15087: if (@currcategories > 0) {
15088: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15089: $checked = ' checked="checked"';
1.663 raeburn 15090: }
15091: }
1.919 raeburn 15092: my $parent_title = $parent;
15093: if ($parent eq 'communities') {
15094: $parent_title = &mt('Communities');
15095: }
15096: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15097: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15098: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15099: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15100: my $depth = 1;
15101: push(@path,$parent);
1.1075.2.117 raeburn 15102: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15103: pop(@path);
1.919 raeburn 15104: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15105: $itemcount ++;
15106: }
1.919 raeburn 15107: if ($itemcount) {
15108: $output = &Apache::loncommon::start_data_table().
15109: $table.
15110: &Apache::loncommon::end_data_table();
15111: }
1.663 raeburn 15112: }
15113: }
15114: }
15115: return $output;
15116: }
15117:
15118: =pod
15119:
1.1075.2.56 raeburn 15120: =item * &assign_category_rows()
1.663 raeburn 15121:
15122: Create a datatable row for display of nested categories in a domain,
15123: with checkboxes to allow a course to be categorized,called recursively.
15124:
15125: Inputs:
15126:
15127: itemcount - track row number for alternating colors
15128:
15129: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15130: categories and subcategories.
15131:
15132: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15133:
15134: parent - parent of current category item
15135:
15136: path - Array containing all categories back up through the hierarchy from the
15137: current category to the top level.
15138:
15139: currcategories - reference to array of current categories assigned to the course
15140:
1.1075.2.117 raeburn 15141: disabled - scalar (optional) contains disabled="disabled" if input elements are
15142: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15143:
1.663 raeburn 15144: Returns: $output (markup to be displayed).
15145:
15146: =cut
15147:
15148: sub assign_category_rows {
1.1075.2.117 raeburn 15149: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15150: my ($text,$name,$item,$chgstr);
15151: if (ref($cats) eq 'ARRAY') {
15152: my $maxdepth = scalar(@{$cats});
15153: if (ref($cats->[$depth]) eq 'HASH') {
15154: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15155: my $numchildren = @{$cats->[$depth]{$parent}};
15156: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 15157: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15158: for (my $j=0; $j<$numchildren; $j++) {
15159: $name = $cats->[$depth]{$parent}[$j];
15160: $item = &escape($name).':'.&escape($parent).':'.$depth;
15161: my $deeper = $depth+1;
15162: my $checked = '';
15163: if (ref($currcategories) eq 'ARRAY') {
15164: if (@{$currcategories} > 0) {
15165: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15166: $checked = ' checked="checked"';
1.663 raeburn 15167: }
15168: }
15169: }
1.664 raeburn 15170: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15171: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15172: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15173: '<input type="hidden" name="catname" value="'.$name.'" />'.
15174: '</td><td>';
1.663 raeburn 15175: if (ref($path) eq 'ARRAY') {
15176: push(@{$path},$name);
1.1075.2.117 raeburn 15177: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15178: pop(@{$path});
15179: }
15180: $text .= '</td></tr>';
15181: }
15182: $text .= '</table></td>';
15183: }
15184: }
15185: }
15186: return $text;
15187: }
15188:
1.1075.2.69 raeburn 15189: =pod
15190:
15191: =back
15192:
15193: =cut
15194:
1.655 raeburn 15195: ############################################################
15196: ############################################################
15197:
15198:
1.443 albertel 15199: sub commit_customrole {
1.664 raeburn 15200: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15201: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15202: ($start?', '.&mt('starting').' '.localtime($start):'').
15203: ($end?', ending '.localtime($end):'').': <b>'.
15204: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15205: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15206: '</b><br />';
15207: return $output;
15208: }
15209:
15210: sub commit_standardrole {
1.1075.2.31 raeburn 15211: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15212: my ($output,$logmsg,$linefeed);
15213: if ($context eq 'auto') {
15214: $linefeed = "\n";
15215: } else {
15216: $linefeed = "<br />\n";
15217: }
1.443 albertel 15218: if ($three eq 'st') {
1.541 raeburn 15219: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 15220: $one,$two,$sec,$context,$credits);
1.541 raeburn 15221: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15222: ($result eq 'unknown_course') || ($result eq 'refused')) {
15223: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15224: } else {
1.541 raeburn 15225: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15226: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15227: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15228: if ($context eq 'auto') {
15229: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15230: } else {
15231: $output .= '<b>'.$result.'</b>'.$linefeed.
15232: &mt('Add to classlist').': <b>ok</b>';
15233: }
15234: $output .= $linefeed;
1.443 albertel 15235: }
15236: } else {
15237: $output = &mt('Assigning').' '.$three.' in '.$url.
15238: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15239: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15240: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15241: if ($context eq 'auto') {
15242: $output .= $result.$linefeed;
15243: } else {
15244: $output .= '<b>'.$result.'</b>'.$linefeed;
15245: }
1.443 albertel 15246: }
15247: return $output;
15248: }
15249:
15250: sub commit_studentrole {
1.1075.2.31 raeburn 15251: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15252: $credits) = @_;
1.626 raeburn 15253: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15254: if ($context eq 'auto') {
15255: $linefeed = "\n";
15256: } else {
15257: $linefeed = '<br />'."\n";
15258: }
1.443 albertel 15259: if (defined($one) && defined($two)) {
15260: my $cid=$one.'_'.$two;
15261: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15262: my $secchange = 0;
15263: my $expire_role_result;
15264: my $modify_section_result;
1.628 raeburn 15265: if ($oldsec ne '-1') {
15266: if ($oldsec ne $sec) {
1.443 albertel 15267: $secchange = 1;
1.628 raeburn 15268: my $now = time;
1.443 albertel 15269: my $uurl='/'.$cid;
15270: $uurl=~s/\_/\//g;
15271: if ($oldsec) {
15272: $uurl.='/'.$oldsec;
15273: }
1.626 raeburn 15274: $oldsecurl = $uurl;
1.628 raeburn 15275: $expire_role_result =
1.1075.2.167 raeburn 15276: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,
15277: '','','',$context);
1.628 raeburn 15278: if ($env{'request.course.sec'} ne '') {
15279: if ($expire_role_result eq 'refused') {
15280: my @roles = ('st');
15281: my @statuses = ('previous');
15282: my @roledoms = ($one);
15283: my $withsec = 1;
15284: my %roleshash =
15285: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15286: \@statuses,\@roles,\@roledoms,$withsec);
15287: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15288: my ($oldstart,$oldend) =
15289: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15290: if ($oldend > 0 && $oldend <= $now) {
15291: $expire_role_result = 'ok';
15292: }
15293: }
15294: }
15295: }
1.443 albertel 15296: $result = $expire_role_result;
15297: }
15298: }
15299: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 15300: $modify_section_result =
15301: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15302: undef,undef,undef,$sec,
15303: $end,$start,'','',$cid,
15304: '',$context,$credits);
1.443 albertel 15305: if ($modify_section_result =~ /^ok/) {
15306: if ($secchange == 1) {
1.628 raeburn 15307: if ($sec eq '') {
15308: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15309: } else {
15310: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15311: }
1.443 albertel 15312: } elsif ($oldsec eq '-1') {
1.628 raeburn 15313: if ($sec eq '') {
15314: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15315: } else {
15316: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15317: }
1.443 albertel 15318: } else {
1.628 raeburn 15319: if ($sec eq '') {
15320: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15321: } else {
15322: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15323: }
1.443 albertel 15324: }
15325: } else {
1.628 raeburn 15326: if ($secchange) {
15327: $$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;
15328: } else {
15329: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15330: }
1.443 albertel 15331: }
15332: $result = $modify_section_result;
15333: } elsif ($secchange == 1) {
1.628 raeburn 15334: if ($oldsec eq '') {
1.1075.2.20 raeburn 15335: $$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 15336: } else {
15337: $$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;
15338: }
1.626 raeburn 15339: if ($expire_role_result eq 'refused') {
15340: my $newsecurl = '/'.$cid;
15341: $newsecurl =~ s/\_/\//g;
15342: if ($sec ne '') {
15343: $newsecurl.='/'.$sec;
15344: }
15345: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15346: if ($sec eq '') {
15347: $$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;
15348: } else {
15349: $$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;
15350: }
15351: }
15352: }
1.443 albertel 15353: }
15354: } else {
1.626 raeburn 15355: $$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 15356: $result = "error: incomplete course id\n";
15357: }
15358: return $result;
15359: }
15360:
1.1075.2.25 raeburn 15361: sub show_role_extent {
15362: my ($scope,$context,$role) = @_;
15363: $scope =~ s{^/}{};
15364: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15365: push(@courseroles,'co');
15366: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15367: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15368: $scope =~ s{/}{_};
15369: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15370: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15371: my ($audom,$auname) = split(/\//,$scope);
15372: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15373: &Apache::loncommon::plainname($auname,$audom).'</span>');
15374: } else {
15375: $scope =~ s{/$}{};
15376: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15377: &Apache::lonnet::domain($scope,'description').'</span>');
15378: }
15379: }
15380:
1.443 albertel 15381: ############################################################
15382: ############################################################
15383:
1.566 albertel 15384: sub check_clone {
1.578 raeburn 15385: my ($args,$linefeed) = @_;
1.566 albertel 15386: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15387: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15388: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15389: my $clonemsg;
15390: my $can_clone = 0;
1.944 raeburn 15391: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15392: if ($lctype ne 'community') {
15393: $lctype = 'course';
15394: }
1.566 albertel 15395: if ($clonehome eq 'no_host') {
1.944 raeburn 15396: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15397: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15398: } else {
15399: $clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15400: }
1.566 albertel 15401: } else {
15402: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15403: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15404: if ($clonedesc{'type'} ne 'Community') {
15405: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15406: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15407: }
15408: }
1.1075.2.119 raeburn 15409: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15410: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15411: $can_clone = 1;
15412: } else {
1.1075.2.95 raeburn 15413: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15414: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 15415: if ($clonehash{'cloners'} eq '') {
15416: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15417: if ($domdefs{'canclone'}) {
15418: unless ($domdefs{'canclone'} eq 'none') {
15419: if ($domdefs{'canclone'} eq 'domain') {
15420: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15421: $can_clone = 1;
15422: }
15423: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15424: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15425: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15426: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15427: $can_clone = 1;
15428: }
15429: }
15430: }
1.908 raeburn 15431: }
1.1075.2.95 raeburn 15432: } else {
15433: my @cloners = split(/,/,$clonehash{'cloners'});
15434: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15435: $can_clone = 1;
1.1075.2.95 raeburn 15436: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15437: $can_clone = 1;
1.1075.2.96 raeburn 15438: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15439: $can_clone = 1;
1.1075.2.95 raeburn 15440: }
15441: unless ($can_clone) {
1.1075.2.96 raeburn 15442: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15443: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 15444: my (%gotdomdefaults,%gotcodedefaults);
15445: foreach my $cloner (@cloners) {
15446: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15447: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15448: my (%codedefaults,@code_order);
15449: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15450: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15451: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15452: }
15453: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15454: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15455: }
15456: } else {
15457: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15458: \%codedefaults,
15459: \@code_order);
15460: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15461: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15462: }
15463: if (@code_order > 0) {
15464: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15465: $cloner,$clonehash{'internal.coursecode'},
15466: $args->{'crscode'})) {
15467: $can_clone = 1;
15468: last;
15469: }
15470: }
15471: }
15472: }
15473: }
1.1075.2.96 raeburn 15474: }
15475: }
15476: unless ($can_clone) {
15477: my $ccrole = 'cc';
15478: if ($args->{'crstype'} eq 'Community') {
15479: $ccrole = 'co';
15480: }
15481: my %roleshash =
15482: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15483: $args->{'ccdomain'},
15484: 'userroles',['active'],[$ccrole],
15485: [$args->{'clonedomain'}]);
15486: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15487: $can_clone = 1;
15488: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15489: $args->{'ccuname'},$args->{'ccdomain'})) {
15490: $can_clone = 1;
1.1075.2.95 raeburn 15491: }
15492: }
15493: unless ($can_clone) {
15494: if ($args->{'crstype'} eq 'Community') {
15495: $clonemsg = &mt('No new community created.').$linefeed.&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]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
15496: } else {
15497: $clonemsg = &mt('No new course created.').$linefeed.&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]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
1.578 raeburn 15498: }
1.566 albertel 15499: }
1.578 raeburn 15500: }
1.566 albertel 15501: }
15502: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15503: }
15504:
1.444 albertel 15505: sub construct_course {
1.1075.2.119 raeburn 15506: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15507: $cnum,$category,$coderef) = @_;
1.444 albertel 15508: my $outcome;
1.541 raeburn 15509: my $linefeed = '<br />'."\n";
15510: if ($context eq 'auto') {
15511: $linefeed = "\n";
15512: }
1.566 albertel 15513:
15514: #
15515: # Are we cloning?
15516: #
15517: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15518: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15519: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15520: if ($context ne 'auto') {
1.578 raeburn 15521: if ($clonemsg ne '') {
15522: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15523: }
1.566 albertel 15524: }
15525: $outcome .= $clonemsg.$linefeed;
15526:
15527: if (!$can_clone) {
15528: return (0,$outcome);
15529: }
15530: }
15531:
1.444 albertel 15532: #
15533: # Open course
15534: #
15535: my $crstype = lc($args->{'crstype'});
15536: my %cenv=();
15537: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15538: $args->{'cdescr'},
15539: $args->{'curl'},
15540: $args->{'course_home'},
15541: $args->{'nonstandard'},
15542: $args->{'crscode'},
15543: $args->{'ccuname'}.':'.
15544: $args->{'ccdomain'},
1.882 raeburn 15545: $args->{'crstype'},
1.885 raeburn 15546: $cnum,$context,$category);
1.444 albertel 15547:
15548: # Note: The testing routines depend on this being output; see
15549: # Utils::Course. This needs to at least be output as a comment
15550: # if anyone ever decides to not show this, and Utils::Course::new
15551: # will need to be suitably modified.
1.541 raeburn 15552: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 15553: if ($$courseid =~ /^error:/) {
15554: return (0,$outcome);
15555: }
15556:
1.444 albertel 15557: #
15558: # Check if created correctly
15559: #
1.479 albertel 15560: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15561: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15562: if ($crsuhome eq 'no_host') {
15563: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15564: return (0,$outcome);
15565: }
1.541 raeburn 15566: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15567:
1.444 albertel 15568: #
1.566 albertel 15569: # Do the cloning
15570: #
15571: if ($can_clone && $cloneid) {
15572: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
15573: if ($context ne 'auto') {
15574: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15575: }
15576: $outcome .= $clonemsg.$linefeed;
15577: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15578: # Copy all files
1.637 www 15579: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15580: # Restore URL
1.566 albertel 15581: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15582: # Restore title
1.566 albertel 15583: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15584: # Restore creation date, creator and creation context.
15585: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15586: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15587: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15588: # Mark as cloned
1.566 albertel 15589: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15590: # Need to clone grading mode
15591: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15592: $cenv{'grading'}=$newenv{'grading'};
15593: # Do not clone these environment entries
15594: &Apache::lonnet::del('environment',
15595: ['default_enrollment_start_date',
15596: 'default_enrollment_end_date',
15597: 'question.email',
15598: 'policy.email',
15599: 'comment.email',
15600: 'pch.users.denied',
1.725 raeburn 15601: 'plc.users.denied',
15602: 'hidefromcat',
1.1075.2.36 raeburn 15603: 'checkforpriv',
1.1075.2.158 raeburn 15604: 'categories'],
1.638 www 15605: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15606: if ($args->{'textbook'}) {
15607: $cenv{'internal.textbook'} = $args->{'textbook'};
15608: }
1.444 albertel 15609: }
1.566 albertel 15610:
1.444 albertel 15611: #
15612: # Set environment (will override cloned, if existing)
15613: #
15614: my @sections = ();
15615: my @xlists = ();
15616: if ($args->{'crstype'}) {
15617: $cenv{'type'}=$args->{'crstype'};
15618: }
15619: if ($args->{'crsid'}) {
15620: $cenv{'courseid'}=$args->{'crsid'};
15621: }
15622: if ($args->{'crscode'}) {
15623: $cenv{'internal.coursecode'}=$args->{'crscode'};
15624: }
15625: if ($args->{'crsquota'} ne '') {
15626: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15627: } else {
15628: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15629: }
15630: if ($args->{'ccuname'}) {
15631: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15632: ':'.$args->{'ccdomain'};
15633: } else {
15634: $cenv{'internal.courseowner'} = $args->{'curruser'};
15635: }
1.1075.2.31 raeburn 15636: if ($args->{'defaultcredits'}) {
15637: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15638: }
1.444 albertel 15639: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.1075.2.166 raeburn 15640: my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.
1.444 albertel 15641: if ($args->{'crssections'}) {
15642: $cenv{'internal.sectionnums'} = '';
15643: if ($args->{'crssections'} =~ m/,/) {
15644: @sections = split/,/,$args->{'crssections'};
15645: } else {
15646: $sections[0] = $args->{'crssections'};
15647: }
15648: if (@sections > 0) {
15649: foreach my $item (@sections) {
15650: my ($sec,$gp) = split/:/,$item;
15651: my $class = $args->{'crscode'}.$sec;
15652: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15653: $cenv{'internal.sectionnums'} .= $item.',';
1.1075.2.166 raeburn 15654: if ($addcheck eq 'ok') {
15655: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
15656: push(@oklcsecs,$gp);
15657: }
15658: } else {
1.1075.2.119 raeburn 15659: push(@badclasses,$class);
1.444 albertel 15660: }
15661: }
15662: $cenv{'internal.sectionnums'} =~ s/,$//;
15663: }
15664: }
15665: # do not hide course coordinator from staff listing,
15666: # even if privileged
15667: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15668: # add course coordinator's domain to domains to check for privileged users
15669: # if different to course domain
15670: if ($$crsudom ne $args->{'ccdomain'}) {
15671: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15672: }
1.444 albertel 15673: # add crosslistings
15674: if ($args->{'crsxlist'}) {
15675: $cenv{'internal.crosslistings'}='';
15676: if ($args->{'crsxlist'} =~ m/,/) {
15677: @xlists = split/,/,$args->{'crsxlist'};
15678: } else {
15679: $xlists[0] = $args->{'crsxlist'};
15680: }
15681: if (@xlists > 0) {
15682: foreach my $item (@xlists) {
15683: my ($xl,$gp) = split/:/,$item;
15684: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15685: $cenv{'internal.crosslistings'} .= $item.',';
1.1075.2.166 raeburn 15686: if ($addcheck eq 'ok') {
15687: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
15688: push(@oklcsecs,$gp);
15689: }
15690: } else {
1.1075.2.119 raeburn 15691: push(@badclasses,$xl);
1.444 albertel 15692: }
15693: }
15694: $cenv{'internal.crosslistings'} =~ s/,$//;
15695: }
15696: }
15697: if ($args->{'autoadds'}) {
15698: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15699: }
15700: if ($args->{'autodrops'}) {
15701: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15702: }
15703: # check for notification of enrollment changes
15704: my @notified = ();
15705: if ($args->{'notify_owner'}) {
15706: if ($args->{'ccuname'} ne '') {
15707: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15708: }
15709: }
15710: if ($args->{'notify_dc'}) {
15711: if ($uname ne '') {
1.630 raeburn 15712: push(@notified,$uname.':'.$udom);
1.444 albertel 15713: }
15714: }
15715: if (@notified > 0) {
15716: my $notifylist;
15717: if (@notified > 1) {
15718: $notifylist = join(',',@notified);
15719: } else {
15720: $notifylist = $notified[0];
15721: }
15722: $cenv{'internal.notifylist'} = $notifylist;
15723: }
15724: if (@badclasses > 0) {
15725: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15726: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15727: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15728: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15729: );
1.1075.2.119 raeburn 15730: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15731: &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 15732: if ($context eq 'auto') {
15733: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15734: } else {
1.566 albertel 15735: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15736: }
15737: foreach my $item (@badclasses) {
1.541 raeburn 15738: if ($context eq 'auto') {
1.1075.2.119 raeburn 15739: $outcome .= " - $item\n";
1.541 raeburn 15740: } else {
1.1075.2.119 raeburn 15741: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15742: }
1.1075.2.119 raeburn 15743: }
15744: if ($context eq 'auto') {
15745: $outcome .= $linefeed;
15746: } else {
15747: $outcome .= "</ul><br /><br /></div>\n";
15748: }
1.444 albertel 15749: }
15750: if ($args->{'no_end_date'}) {
15751: $args->{'endaccess'} = 0;
15752: }
1.1075.2.166 raeburn 15753: # If an official course with institutional sections is created by cloning
15754: # an existing course, section-specific hiding of course totals in student's
15755: # view of grades as copied from cloned course, will be checked for valid
15756: # sections.
15757: if (($can_clone && $cloneid) &&
15758: ($cenv{'internal.coursecode'} ne '') &&
15759: ($cenv{'grading'} eq 'standard') &&
15760: ($cenv{'hidetotals'} ne '') &&
15761: ($cenv{'hidetotals'} ne 'all')) {
15762: my @hidesecs;
15763: my $deletehidetotals;
15764: if (@oklcsecs) {
15765: foreach my $sec (split(/,/,$cenv{'hidetotals'})) {
15766: if (grep(/^\Q$sec$/,@oklcsecs)) {
15767: push(@hidesecs,$sec);
15768: }
15769: }
15770: if (@hidesecs) {
15771: $cenv{'hidetotals'} = join(',',@hidesecs);
15772: } else {
15773: $deletehidetotals = 1;
15774: }
15775: } else {
15776: $deletehidetotals = 1;
15777: }
15778: if ($deletehidetotals) {
15779: delete($cenv{'hidetotals'});
15780: &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);
15781: }
15782: }
1.444 albertel 15783: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15784: $cenv{'internal.autoend'}=$args->{'enrollend'};
15785: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15786: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15787: if ($args->{'showphotos'}) {
15788: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15789: }
15790: $cenv{'internal.authtype'} = $args->{'authtype'};
15791: $cenv{'internal.autharg'} = $args->{'autharg'};
15792: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15793: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15794: 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');
15795: if ($context eq 'auto') {
15796: $outcome .= $krb_msg;
15797: } else {
1.566 albertel 15798: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15799: }
15800: $outcome .= $linefeed;
1.444 albertel 15801: }
15802: }
15803: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15804: if ($args->{'setpolicy'}) {
15805: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15806: }
15807: if ($args->{'setcontent'}) {
15808: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15809: }
1.1075.2.110 raeburn 15810: if ($args->{'setcomment'}) {
15811: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15812: }
1.444 albertel 15813: }
15814: if ($args->{'reshome'}) {
15815: $cenv{'reshome'}=$args->{'reshome'}.'/';
15816: $cenv{'reshome'}=~s/\/+$/\//;
15817: }
15818: #
15819: # course has keyed access
15820: #
15821: if ($args->{'setkeys'}) {
15822: $cenv{'keyaccess'}='yes';
15823: }
15824: # if specified, key authority is not course, but user
15825: # only active if keyaccess is yes
15826: if ($args->{'keyauth'}) {
1.487 albertel 15827: my ($user,$domain) = split(':',$args->{'keyauth'});
15828: $user = &LONCAPA::clean_username($user);
15829: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15830: if ($user ne '' && $domain ne '') {
1.487 albertel 15831: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15832: }
15833: }
15834:
1.1075.2.59 raeburn 15835: #
15836: # generate and store uniquecode (available to course requester), if course should have one.
15837: #
15838: if ($args->{'uniquecode'}) {
15839: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15840: if ($code) {
15841: $cenv{'internal.uniquecode'} = $code;
15842: my %crsinfo =
15843: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15844: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15845: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15846: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15847: }
15848: if (ref($coderef)) {
15849: $$coderef = $code;
15850: }
15851: }
15852: }
15853:
1.444 albertel 15854: if ($args->{'disresdis'}) {
15855: $cenv{'pch.roles.denied'}='st';
15856: }
15857: if ($args->{'disablechat'}) {
15858: $cenv{'plc.roles.denied'}='st';
15859: }
15860:
15861: # Record we've not yet viewed the Course Initialization Helper for this
15862: # course
15863: $cenv{'course.helper.not.run'} = 1;
15864: #
15865: # Use new Randomseed
15866: #
15867: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15868: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15869: #
15870: # The encryption code and receipt prefix for this course
15871: #
15872: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15873: $cenv{'internal.encpref'}=100+int(9*rand(99));
15874: #
15875: # By default, use standard grading
15876: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15877:
1.541 raeburn 15878: $outcome .= $linefeed.&mt('Setting environment').': '.
15879: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15880: #
15881: # Open all assignments
15882: #
15883: if ($args->{'openall'}) {
1.1075.2.146 raeburn 15884: my $opendate = time;
15885: if ($args->{'openallfrom'} =~ /^\d+$/) {
15886: $opendate = $args->{'openallfrom'};
15887: }
1.444 albertel 15888: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 15889: my %storecontent = ($storeunder => $opendate,
1.444 albertel 15890: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 15891: $outcome .= &mt('All assignments open starting [_1]',
15892: &Apache::lonlocal::locallocaltime($opendate)).': '.
15893: &Apache::lonnet::cput
15894: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15895: }
15896: #
15897: # Set first page
15898: #
15899: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15900: || ($cloneid)) {
1.445 albertel 15901: use LONCAPA::map;
1.444 albertel 15902: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15903:
15904: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15905: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15906:
1.444 albertel 15907: $outcome .= ($fatal?$errtext:'read ok').' - ';
15908: my $title; my $url;
15909: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15910: $title=&mt('Syllabus');
1.444 albertel 15911: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15912: } else {
1.963 raeburn 15913: $title=&mt('Table of Contents');
1.444 albertel 15914: $url='/adm/navmaps';
15915: }
1.445 albertel 15916:
15917: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15918: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15919:
15920: if ($errtext) { $fatal=2; }
1.541 raeburn 15921: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15922: }
1.566 albertel 15923:
15924: return (1,$outcome);
1.444 albertel 15925: }
15926:
1.1075.2.59 raeburn 15927: sub make_unique_code {
15928: my ($cdom,$cnum) = @_;
15929: # get lock on uniquecodes db
15930: my $lockhash = {
15931: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15932: ':'.$env{'user.domain'},
15933: };
15934: my $tries = 0;
15935: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15936: my ($code,$error);
15937:
15938: while (($gotlock ne 'ok') && ($tries<3)) {
15939: $tries ++;
15940: sleep 1;
15941: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15942: }
15943: if ($gotlock eq 'ok') {
15944: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15945: my $gotcode;
15946: my $attempts = 0;
15947: while ((!$gotcode) && ($attempts < 100)) {
15948: $code = &generate_code();
15949: if (!exists($currcodes{$code})) {
15950: $gotcode = 1;
15951: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15952: $error = 'nostore';
15953: }
15954: }
15955: $attempts ++;
15956: }
15957: my @del_lock = ($cnum."\0".'uniquecodes');
15958: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15959: } else {
15960: $error = 'nolock';
15961: }
15962: return ($code,$error);
15963: }
15964:
15965: sub generate_code {
15966: my $code;
15967: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15968: for (my $i=0; $i<6; $i++) {
15969: my $lettnum = int (rand 2);
15970: my $item = '';
15971: if ($lettnum) {
15972: $item = $letts[int( rand(18) )];
15973: } else {
15974: $item = 1+int( rand(8) );
15975: }
15976: $code .= $item;
15977: }
15978: return $code;
15979: }
15980:
1.444 albertel 15981: ############################################################
15982: ############################################################
15983:
1.953 droeschl 15984: #SD
15985: # only Community and Course, or anything else?
1.378 raeburn 15986: sub course_type {
15987: my ($cid) = @_;
15988: if (!defined($cid)) {
15989: $cid = $env{'request.course.id'};
15990: }
1.404 albertel 15991: if (defined($env{'course.'.$cid.'.type'})) {
15992: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15993: } else {
15994: return 'Course';
1.377 raeburn 15995: }
15996: }
1.156 albertel 15997:
1.406 raeburn 15998: sub group_term {
15999: my $crstype = &course_type();
16000: my %names = (
16001: 'Course' => 'group',
1.865 raeburn 16002: 'Community' => 'group',
1.406 raeburn 16003: );
16004: return $names{$crstype};
16005: }
16006:
1.902 raeburn 16007: sub course_types {
1.1075.2.59 raeburn 16008: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 16009: my %typename = (
16010: official => 'Official course',
16011: unofficial => 'Unofficial course',
16012: community => 'Community',
1.1075.2.59 raeburn 16013: textbook => 'Textbook course',
1.902 raeburn 16014: );
16015: return (\@types,\%typename);
16016: }
16017:
1.156 albertel 16018: sub icon {
16019: my ($file)=@_;
1.505 albertel 16020: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16021: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16022: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16023: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16024: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16025: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16026: $curfext.".gif") {
16027: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16028: $curfext.".gif";
16029: }
16030: }
1.249 albertel 16031: return &lonhttpdurl($iconname);
1.154 albertel 16032: }
1.84 albertel 16033:
1.575 albertel 16034: sub lonhttpdurl {
1.692 www 16035: #
16036: # Had been used for "small fry" static images on separate port 8080.
16037: # Modify here if lightweight http functionality desired again.
16038: # Currently eliminated due to increasing firewall issues.
16039: #
1.575 albertel 16040: my ($url)=@_;
1.692 www 16041: return $url;
1.215 albertel 16042: }
16043:
1.213 albertel 16044: sub connection_aborted {
16045: my ($r)=@_;
16046: $r->print(" ");$r->rflush();
16047: my $c = $r->connection;
16048: return $c->aborted();
16049: }
16050:
1.221 foxr 16051: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16052: # strings as 'strings'.
16053: sub escape_single {
1.221 foxr 16054: my ($input) = @_;
1.223 albertel 16055: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16056: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16057: return $input;
16058: }
1.223 albertel 16059:
1.222 foxr 16060: # Same as escape_single, but escape's "'s This
16061: # can be used for "strings"
16062: sub escape_double {
16063: my ($input) = @_;
16064: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16065: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16066: return $input;
16067: }
1.223 albertel 16068:
1.222 foxr 16069: # Escapes the last element of a full URL.
16070: sub escape_url {
16071: my ($url) = @_;
1.238 raeburn 16072: my @urlslices = split(/\//, $url,-1);
1.369 www 16073: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 16074: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16075: }
1.462 albertel 16076:
1.820 raeburn 16077: sub compare_arrays {
16078: my ($arrayref1,$arrayref2) = @_;
16079: my (@difference,%count);
16080: @difference = ();
16081: %count = ();
16082: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16083: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16084: foreach my $element (keys(%count)) {
16085: if ($count{$element} == 1) {
16086: push(@difference,$element);
16087: }
16088: }
16089: }
16090: return @difference;
16091: }
16092:
1.1075.2.152 raeburn 16093: sub lon_status_items {
16094: my %defaults = (
16095: E => 100,
16096: W => 4,
16097: N => 1,
16098: U => 5,
16099: threshold => 200,
16100: sysmail => 2500,
16101: );
16102: my %names = (
16103: E => 'Errors',
16104: W => 'Warnings',
16105: N => 'Notices',
16106: U => 'Unsent',
16107: );
16108: return (\%defaults,\%names);
16109: }
16110:
1.817 bisitz 16111: # -------------------------------------------------------- Initialize user login
1.462 albertel 16112: sub init_user_environment {
1.463 albertel 16113: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16114: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16115:
16116: my $public=($username eq 'public' && $domain eq 'public');
16117:
16118: # See if old ID present, if so, remove
16119:
1.1062 raeburn 16120: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16121: my $now=time;
16122:
16123: if ($public) {
16124: my $max_public=100;
16125: my $oldest;
16126: my $oldest_time=0;
16127: for(my $next=1;$next<=$max_public;$next++) {
16128: if (-e $lonids."/publicuser_$next.id") {
16129: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16130: if ($mtime<$oldest_time || !$oldest_time) {
16131: $oldest_time=$mtime;
16132: $oldest=$next;
16133: }
16134: } else {
16135: $cookie="publicuser_$next";
16136: last;
16137: }
16138: }
16139: if (!$cookie) { $cookie="publicuser_$oldest"; }
16140: } else {
1.463 albertel 16141: # if this isn't a robot, kill any existing non-robot sessions
16142: if (!$args->{'robot'}) {
16143: opendir(DIR,$lonids);
16144: while ($filename=readdir(DIR)) {
16145: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 16146: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16147: &GDBM_READER(),0640)) {
16148: my $linkedfile;
16149: if (exists($oldenv{'user.linkedenv'})) {
16150: $linkedfile = $oldenv{'user.linkedenv'};
16151: }
16152: untie(%oldenv);
16153: if (unlink("$lonids/$filename")) {
16154: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16155: if (-l "$lonids/$linkedfile.id") {
16156: unlink("$lonids/$linkedfile.id");
16157: }
16158: }
16159: }
16160: } else {
16161: unlink($lonids.'/'.$filename);
16162: }
1.463 albertel 16163: }
1.462 albertel 16164: }
1.463 albertel 16165: closedir(DIR);
1.1075.2.84 raeburn 16166: # If there is a undeleted lockfile for the user's paste buffer remove it.
16167: my $namespace = 'nohist_courseeditor';
16168: my $lockingkey = 'paste'."\0".'locked_num';
16169: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16170: $domain,$username);
16171: if (exists($lockhash{$lockingkey})) {
16172: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16173: unless ($delresult eq 'ok') {
16174: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16175: }
16176: }
1.462 albertel 16177: }
16178: # Give them a new cookie
1.463 albertel 16179: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16180: : $now.$$.int(rand(10000)));
1.463 albertel 16181: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16182:
16183: # Initialize roles
16184:
1.1062 raeburn 16185: ($userroles,$firstaccenv,$timerintenv) =
16186: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16187: }
16188: # ------------------------------------ Check browser type and MathML capability
16189:
1.1075.2.77 raeburn 16190: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16191: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16192:
16193: # ------------------------------------------------------------- Get environment
16194:
16195: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16196: my ($tmp) = keys(%userenv);
16197: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
16198: } else {
16199: undef(%userenv);
16200: }
16201: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16202: $form->{'interface'}=$userenv{'interface'};
16203: }
16204: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16205:
16206: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16207: foreach my $option ('interface','localpath','localres') {
16208: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16209: }
16210: # --------------------------------------------------------- Write first profile
16211:
16212: {
1.1075.2.150 raeburn 16213: my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 16214: my %initial_env =
16215: ("user.name" => $username,
16216: "user.domain" => $domain,
16217: "user.home" => $authhost,
16218: "browser.type" => $clientbrowser,
16219: "browser.version" => $clientversion,
16220: "browser.mathml" => $clientmathml,
16221: "browser.unicode" => $clientunicode,
16222: "browser.os" => $clientos,
1.1075.2.42 raeburn 16223: "browser.mobile" => $clientmobile,
16224: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 16225: "browser.osversion" => $clientosversion,
1.462 albertel 16226: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16227: "request.course.fn" => '',
16228: "request.course.uri" => '',
16229: "request.course.sec" => '',
16230: "request.role" => 'cm',
16231: "request.role.adv" => $env{'user.adv'},
1.1075.2.150 raeburn 16232: "request.host" => $ip,);
1.462 albertel 16233:
16234: if ($form->{'localpath'}) {
16235: $initial_env{"browser.localpath"} = $form->{'localpath'};
16236: $initial_env{"browser.localres"} = $form->{'localres'};
16237: }
16238:
16239: if ($form->{'interface'}) {
16240: $form->{'interface'}=~s/\W//gs;
16241: $initial_env{"browser.interface"} = $form->{'interface'};
16242: $env{'browser.interface'}=$form->{'interface'};
16243: }
16244:
1.1075.2.54 raeburn 16245: if ($form->{'iptoken'}) {
16246: my $lonhost = $r->dir_config('lonHostID');
16247: $initial_env{"user.noloadbalance"} = $lonhost;
16248: $env{'user.noloadbalance'} = $lonhost;
16249: }
16250:
1.1075.2.120 raeburn 16251: if ($form->{'noloadbalance'}) {
16252: my @hosts = &Apache::lonnet::current_machine_ids();
16253: my $hosthere = $form->{'noloadbalance'};
16254: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16255: $initial_env{"user.noloadbalance"} = $hosthere;
16256: $env{'user.noloadbalance'} = $hosthere;
16257: }
16258: }
16259:
1.1016 raeburn 16260: unless ($domain eq 'public') {
1.1075.2.125 raeburn 16261: my %is_adv = ( is_adv => $env{'user.adv'} );
16262: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 16263:
1.1075.2.125 raeburn 16264: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16265: $userenv{'availabletools.'.$tool} =
16266: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16267: undef,\%userenv,\%domdef,\%is_adv);
16268: }
1.724 raeburn 16269:
1.1075.2.125 raeburn 16270: foreach my $crstype ('official','unofficial','community','textbook') {
16271: $userenv{'canrequest.'.$crstype} =
16272: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16273: 'reload','requestcourses',
16274: \%userenv,\%domdef,\%is_adv);
16275: }
1.765 raeburn 16276:
1.1075.2.125 raeburn 16277: $userenv{'canrequest.author'} =
16278: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16279: 'reload','requestauthor',
16280: \%userenv,\%domdef,\%is_adv);
16281: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16282: $domain,$username);
16283: my $reqstatus = $reqauthor{'author_status'};
16284: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16285: if (ref($reqauthor{'author'}) eq 'HASH') {
16286: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16287: $reqauthor{'author'}{'timestamp'};
16288: }
1.1075.2.14 raeburn 16289: }
16290: }
16291:
1.462 albertel 16292: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16293:
1.462 albertel 16294: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16295: &GDBM_WRCREAT(),0640)) {
16296: &_add_to_env(\%disk_env,\%initial_env);
16297: &_add_to_env(\%disk_env,\%userenv,'environment.');
16298: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16299: if (ref($firstaccenv) eq 'HASH') {
16300: &_add_to_env(\%disk_env,$firstaccenv);
16301: }
16302: if (ref($timerintenv) eq 'HASH') {
16303: &_add_to_env(\%disk_env,$timerintenv);
16304: }
1.463 albertel 16305: if (ref($args->{'extra_env'})) {
16306: &_add_to_env(\%disk_env,$args->{'extra_env'});
16307: }
1.462 albertel 16308: untie(%disk_env);
16309: } else {
1.705 tempelho 16310: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16311: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16312: return 'error: '.$!;
16313: }
16314: }
16315: $env{'request.role'}='cm';
16316: $env{'request.role.adv'}=$env{'user.adv'};
16317: $env{'browser.type'}=$clientbrowser;
16318:
16319: return $cookie;
16320:
16321: }
16322:
16323: sub _add_to_env {
16324: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16325: if (ref($env_data) eq 'HASH') {
16326: while (my ($key,$value) = each(%$env_data)) {
16327: $idf->{$prefix.$key} = $value;
16328: $env{$prefix.$key} = $value;
16329: }
1.462 albertel 16330: }
16331: }
16332:
1.685 tempelho 16333: # --- Get the symbolic name of a problem and the url
16334: sub get_symb {
16335: my ($request,$silent) = @_;
1.726 raeburn 16336: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16337: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16338: if ($symb eq '') {
16339: if (!$silent) {
1.1071 raeburn 16340: if (ref($request)) {
16341: $request->print("Unable to handle ambiguous references:$url:.");
16342: }
1.685 tempelho 16343: return ();
16344: }
16345: }
16346: &Apache::lonenc::check_decrypt(\$symb);
16347: return ($symb);
16348: }
16349:
16350: # --------------------------------------------------------------Get annotation
16351:
16352: sub get_annotation {
16353: my ($symb,$enc) = @_;
16354:
16355: my $key = $symb;
16356: if (!$enc) {
16357: $key =
16358: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16359: }
16360: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16361: return $annotation{$key};
16362: }
16363:
16364: sub clean_symb {
1.731 raeburn 16365: my ($symb,$delete_enc) = @_;
1.685 tempelho 16366:
16367: &Apache::lonenc::check_decrypt(\$symb);
16368: my $enc = $env{'request.enc'};
1.731 raeburn 16369: if ($delete_enc) {
1.730 raeburn 16370: delete($env{'request.enc'});
16371: }
1.685 tempelho 16372:
16373: return ($symb,$enc);
16374: }
1.462 albertel 16375:
1.1075.2.69 raeburn 16376: ############################################################
16377: ############################################################
16378:
16379: =pod
16380:
16381: =head1 Routines for building display used to search for courses
16382:
16383:
16384: =over 4
16385:
16386: =item * &build_filters()
16387:
16388: Create markup for a table used to set filters to use when selecting
16389: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16390: and quotacheck.pl
16391:
16392:
16393: Inputs:
16394:
16395: filterlist - anonymous array of fields to include as potential filters
16396:
16397: crstype - course type
16398:
16399: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16400: to pop-open a course selector (will contain "extra element").
16401:
16402: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16403:
16404: filter - anonymous hash of criteria and their values
16405:
16406: action - form action
16407:
16408: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16409:
16410: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
16411:
16412: cloneruname - username of owner of new course who wants to clone
16413:
16414: clonerudom - domain of owner of new course who wants to clone
16415:
16416: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16417:
16418: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16419:
16420: codedom - domain
16421:
16422: formname - value of form element named "form".
16423:
16424: fixeddom - domain, if fixed.
16425:
16426: prevphase - value to assign to form element named "phase" when going back to the previous screen
16427:
16428: cnameelement - name of form element in form on opener page which will receive title of selected course
16429:
16430: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16431:
16432: cdomelement - name of form element in form on opener page which will receive domain of selected course
16433:
16434: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16435:
16436: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16437:
16438: clonewarning - warning message about missing information for intended course owner when DC creates a course
16439:
16440:
16441: Returns: $output - HTML for display of search criteria, and hidden form elements.
16442:
16443:
16444: Side Effects: None
16445:
16446: =cut
16447:
16448: # ---------------------------------------------- search for courses based on last activity etc.
16449:
16450: sub build_filters {
16451: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16452: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16453: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16454: $cnameelement,$cnumelement,$cdomelement,$setroles,
16455: $clonetext,$clonewarning) = @_;
16456: my ($list,$jscript);
16457: my $onchange = 'javascript:updateFilters(this)';
16458: my ($domainselectform,$sincefilterform,$createdfilterform,
16459: $ownerdomselectform,$persondomselectform,$instcodeform,
16460: $typeselectform,$instcodetitle);
16461: if ($formname eq '') {
16462: $formname = $caller;
16463: }
16464: foreach my $item (@{$filterlist}) {
16465: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16466: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16467: if ($item eq 'domainfilter') {
16468: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16469: } elsif ($item eq 'coursefilter') {
16470: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16471: } elsif ($item eq 'ownerfilter') {
16472: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16473: } elsif ($item eq 'ownerdomfilter') {
16474: $filter->{'ownerdomfilter'} =
16475: &LONCAPA::clean_domain($filter->{$item});
16476: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16477: 'ownerdomfilter',1);
16478: } elsif ($item eq 'personfilter') {
16479: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16480: } elsif ($item eq 'persondomfilter') {
16481: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16482: 'persondomfilter',1);
16483: } else {
16484: $filter->{$item} =~ s/\W//g;
16485: }
16486: if (!$filter->{$item}) {
16487: $filter->{$item} = '';
16488: }
16489: }
16490: if ($item eq 'domainfilter') {
16491: my $allow_blank = 1;
16492: if ($formname eq 'portform') {
16493: $allow_blank=0;
16494: } elsif ($formname eq 'studentform') {
16495: $allow_blank=0;
16496: }
16497: if ($fixeddom) {
16498: $domainselectform = '<input type="hidden" name="domainfilter"'.
16499: ' value="'.$codedom.'" />'.
16500: &Apache::lonnet::domain($codedom,'description');
16501: } else {
16502: $domainselectform = &select_dom_form($filter->{$item},
16503: 'domainfilter',
16504: $allow_blank,'',$onchange);
16505: }
16506: } else {
16507: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16508: }
16509: }
16510:
16511: # last course activity filter and selection
16512: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16513:
16514: # course created filter and selection
16515: if (exists($filter->{'createdfilter'})) {
16516: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16517: }
16518:
16519: my %lt = &Apache::lonlocal::texthash(
16520: 'cac' => "$crstype Activity",
16521: 'ccr' => "$crstype Created",
16522: 'cde' => "$crstype Title",
16523: 'cdo' => "$crstype Domain",
16524: 'ins' => 'Institutional Code',
16525: 'inc' => 'Institutional Categorization',
16526: 'cow' => "$crstype Owner/Co-owner",
16527: 'cop' => "$crstype Personnel Includes",
16528: 'cog' => 'Type',
16529: );
16530:
16531: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16532: my $typeval = 'Course';
16533: if ($crstype eq 'Community') {
16534: $typeval = 'Community';
16535: }
16536: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16537: } else {
16538: $typeselectform = '<select name="type" size="1"';
16539: if ($onchange) {
16540: $typeselectform .= ' onchange="'.$onchange.'"';
16541: }
16542: $typeselectform .= '>'."\n";
16543: foreach my $posstype ('Course','Community') {
16544: $typeselectform.='<option value="'.$posstype.'"'.
16545: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16546: }
16547: $typeselectform.="</select>";
16548: }
16549:
16550: my ($cloneableonlyform,$cloneabletitle);
16551: if (exists($filter->{'cloneableonly'})) {
16552: my $cloneableon = '';
16553: my $cloneableoff = ' checked="checked"';
16554: if ($filter->{'cloneableonly'}) {
16555: $cloneableon = $cloneableoff;
16556: $cloneableoff = '';
16557: }
16558: $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>';
16559: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16560: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16561: } else {
16562: $cloneabletitle = &mt('Cloneable by you');
16563: }
16564: }
16565: my $officialjs;
16566: if ($crstype eq 'Course') {
16567: if (exists($filter->{'instcodefilter'})) {
16568: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16569: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16570: if ($codedom) {
16571: $officialjs = 1;
16572: ($instcodeform,$jscript,$$numtitlesref) =
16573: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16574: $officialjs,$codetitlesref);
16575: if ($jscript) {
16576: $jscript = '<script type="text/javascript">'."\n".
16577: '// <![CDATA['."\n".
16578: $jscript."\n".
16579: '// ]]>'."\n".
16580: '</script>'."\n";
16581: }
16582: }
16583: if ($instcodeform eq '') {
16584: $instcodeform =
16585: '<input type="text" name="instcodefilter" size="10" value="'.
16586: $list->{'instcodefilter'}.'" />';
16587: $instcodetitle = $lt{'ins'};
16588: } else {
16589: $instcodetitle = $lt{'inc'};
16590: }
16591: if ($fixeddom) {
16592: $instcodetitle .= '<br />('.$codedom.')';
16593: }
16594: }
16595: }
16596: my $output = qq|
16597: <form method="post" name="filterpicker" action="$action">
16598: <input type="hidden" name="form" value="$formname" />
16599: |;
16600: if ($formname eq 'modifycourse') {
16601: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16602: '<input type="hidden" name="prevphase" value="'.
16603: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16604: } elsif ($formname eq 'quotacheck') {
16605: $output .= qq|
16606: <input type="hidden" name="sortby" value="" />
16607: <input type="hidden" name="sortorder" value="" />
16608: |;
16609: } else {
1.1075.2.69 raeburn 16610: my $name_input;
16611: if ($cnameelement ne '') {
16612: $name_input = '<input type="hidden" name="cnameelement" value="'.
16613: $cnameelement.'" />';
16614: }
16615: $output .= qq|
16616: <input type="hidden" name="cnumelement" value="$cnumelement" />
16617: <input type="hidden" name="cdomelement" value="$cdomelement" />
16618: $name_input
16619: $roleelement
16620: $multelement
16621: $typeelement
16622: |;
16623: if ($formname eq 'portform') {
16624: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16625: }
16626: }
16627: if ($fixeddom) {
16628: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16629: }
16630: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16631: if ($sincefilterform) {
16632: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16633: .$sincefilterform
16634: .&Apache::lonhtmlcommon::row_closure();
16635: }
16636: if ($createdfilterform) {
16637: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16638: .$createdfilterform
16639: .&Apache::lonhtmlcommon::row_closure();
16640: }
16641: if ($domainselectform) {
16642: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16643: .$domainselectform
16644: .&Apache::lonhtmlcommon::row_closure();
16645: }
16646: if ($typeselectform) {
16647: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16648: $output .= $typeselectform;
16649: } else {
16650: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16651: .$typeselectform
16652: .&Apache::lonhtmlcommon::row_closure();
16653: }
16654: }
16655: if ($instcodeform) {
16656: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16657: .$instcodeform
16658: .&Apache::lonhtmlcommon::row_closure();
16659: }
16660: if (exists($filter->{'ownerfilter'})) {
16661: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16662: '<table><tr><td>'.&mt('Username').'<br />'.
16663: '<input type="text" name="ownerfilter" size="20" value="'.
16664: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16665: $ownerdomselectform.'</td></tr></table>'.
16666: &Apache::lonhtmlcommon::row_closure();
16667: }
16668: if (exists($filter->{'personfilter'})) {
16669: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16670: '<table><tr><td>'.&mt('Username').'<br />'.
16671: '<input type="text" name="personfilter" size="20" value="'.
16672: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16673: $persondomselectform.'</td></tr></table>'.
16674: &Apache::lonhtmlcommon::row_closure();
16675: }
16676: if (exists($filter->{'coursefilter'})) {
16677: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16678: .'<input type="text" name="coursefilter" size="25" value="'
16679: .$list->{'coursefilter'}.'" />'
16680: .&Apache::lonhtmlcommon::row_closure();
16681: }
16682: if ($cloneableonlyform) {
16683: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16684: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16685: }
16686: if (exists($filter->{'descriptfilter'})) {
16687: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16688: .'<input type="text" name="descriptfilter" size="40" value="'
16689: .$list->{'descriptfilter'}.'" />'
16690: .&Apache::lonhtmlcommon::row_closure(1);
16691: }
16692: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16693: '<input type="hidden" name="updater" value="" />'."\n".
16694: '<input type="submit" name="gosearch" value="'.
16695: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16696: return $jscript.$clonewarning.$output;
16697: }
16698:
16699: =pod
16700:
16701: =item * &timebased_select_form()
16702:
16703: Create markup for a dropdown list used to select a time-based
16704: filter e.g., Course Activity, Course Created, when searching for courses
16705: or communities
16706:
16707: Inputs:
16708:
16709: item - name of form element (sincefilter or createdfilter)
16710:
16711: filter - anonymous hash of criteria and their values
16712:
16713: Returns: HTML for a select box contained a blank, then six time selections,
16714: with value set in incoming form variables currently selected.
16715:
16716: Side Effects: None
16717:
16718: =cut
16719:
16720: sub timebased_select_form {
16721: my ($item,$filter) = @_;
16722: if (ref($filter) eq 'HASH') {
16723: $filter->{$item} =~ s/[^\d-]//g;
16724: if (!$filter->{$item}) { $filter->{$item}=-1; }
16725: return &select_form(
16726: $filter->{$item},
16727: $item,
16728: { '-1' => '',
16729: '86400' => &mt('today'),
16730: '604800' => &mt('last week'),
16731: '2592000' => &mt('last month'),
16732: '7776000' => &mt('last three months'),
16733: '15552000' => &mt('last six months'),
16734: '31104000' => &mt('last year'),
16735: 'select_form_order' =>
16736: ['-1','86400','604800','2592000','7776000',
16737: '15552000','31104000']});
16738: }
16739: }
16740:
16741: =pod
16742:
16743: =item * &js_changer()
16744:
16745: Create script tag containing Javascript used to submit course search form
16746: when course type or domain is changed, and also to hide 'Searching ...' on
16747: page load completion for page showing search result.
16748:
16749: Inputs: None
16750:
16751: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16752:
16753: Side Effects: None
16754:
16755: =cut
16756:
16757: sub js_changer {
16758: return <<ENDJS;
16759: <script type="text/javascript">
16760: // <![CDATA[
16761: function updateFilters(caller) {
16762: if (typeof(caller) != "undefined") {
16763: document.filterpicker.updater.value = caller.name;
16764: }
16765: document.filterpicker.submit();
16766: }
16767:
16768: function hideSearching() {
16769: if (document.getElementById('searching')) {
16770: document.getElementById('searching').style.display = 'none';
16771: }
16772: return;
16773: }
16774:
16775: // ]]>
16776: </script>
16777:
16778: ENDJS
16779: }
16780:
16781: =pod
16782:
16783: =item * &search_courses()
16784:
16785: Process selected filters form course search form and pass to lonnet::courseiddump
16786: to retrieve a hash for which keys are courseIDs which match the selected filters.
16787:
16788: Inputs:
16789:
16790: dom - domain being searched
16791:
16792: type - course type ('Course' or 'Community' or '.' if any).
16793:
16794: filter - anonymous hash of criteria and their values
16795:
16796: numtitles - for institutional codes - number of categories
16797:
16798: cloneruname - optional username of new course owner
16799:
16800: clonerudom - optional domain of new course owner
16801:
1.1075.2.95 raeburn 16802: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16803: (used when DC is using course creation form)
16804:
16805: codetitles - reference to array of titles of components in institutional codes (official courses).
16806:
1.1075.2.95 raeburn 16807: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16808: (and so can clone automatically)
16809:
16810: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16811:
16812: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16813: courses to clone
1.1075.2.69 raeburn 16814:
16815: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16816:
16817:
16818: Side Effects: None
16819:
16820: =cut
16821:
16822:
16823: sub search_courses {
1.1075.2.95 raeburn 16824: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16825: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16826: my (%courses,%showcourses,$cloner);
16827: if (($filter->{'ownerfilter'} ne '') ||
16828: ($filter->{'ownerdomfilter'} ne '')) {
16829: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16830: $filter->{'ownerdomfilter'};
16831: }
16832: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16833: if (!$filter->{$item}) {
16834: $filter->{$item}='.';
16835: }
16836: }
16837: my $now = time;
16838: my $timefilter =
16839: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16840: my ($createdbefore,$createdafter);
16841: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16842: $createdbefore = $now;
16843: $createdafter = $now-$filter->{'createdfilter'};
16844: }
16845: my ($instcodefilter,$regexpok);
16846: if ($numtitles) {
16847: if ($env{'form.official'} eq 'on') {
16848: $instcodefilter =
16849: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16850: $regexpok = 1;
16851: } elsif ($env{'form.official'} eq 'off') {
16852: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16853: unless ($instcodefilter eq '') {
16854: $regexpok = -1;
16855: }
16856: }
16857: } else {
16858: $instcodefilter = $filter->{'instcodefilter'};
16859: }
16860: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16861: if ($type eq '') { $type = '.'; }
16862:
16863: if (($clonerudom ne '') && ($cloneruname ne '')) {
16864: $cloner = $cloneruname.':'.$clonerudom;
16865: }
16866: %courses = &Apache::lonnet::courseiddump($dom,
16867: $filter->{'descriptfilter'},
16868: $timefilter,
16869: $instcodefilter,
16870: $filter->{'combownerfilter'},
16871: $filter->{'coursefilter'},
16872: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16873: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16874: $filter->{'cloneableonly'},
16875: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16876: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16877: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16878: my $ccrole;
16879: if ($type eq 'Community') {
16880: $ccrole = 'co';
16881: } else {
16882: $ccrole = 'cc';
16883: }
16884: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16885: $filter->{'persondomfilter'},
16886: 'userroles',undef,
16887: [$ccrole,'in','ad','ep','ta','cr'],
16888: $dom);
16889: foreach my $role (keys(%rolehash)) {
16890: my ($cnum,$cdom,$courserole) = split(':',$role);
16891: my $cid = $cdom.'_'.$cnum;
16892: if (exists($courses{$cid})) {
16893: if (ref($courses{$cid}) eq 'HASH') {
16894: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16895: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16896: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16897: }
16898: } else {
16899: $courses{$cid}{roles} = [$courserole];
16900: }
16901: $showcourses{$cid} = $courses{$cid};
16902: }
16903: }
16904: }
16905: %courses = %showcourses;
16906: }
16907: return %courses;
16908: }
16909:
16910: =pod
16911:
16912: =back
16913:
1.1075.2.88 raeburn 16914: =head1 Routines for version requirements for current course.
16915:
16916: =over 4
16917:
16918: =item * &check_release_required()
16919:
16920: Compares required LON-CAPA version with version on server, and
16921: if required version is newer looks for a server with the required version.
16922:
16923: Looks first at servers in user's owen domain; if none suitable, looks at
16924: servers in course's domain are permitted to host sessions for user's domain.
16925:
16926: Inputs:
16927:
16928: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16929:
16930: $courseid - Course ID of current course
16931:
16932: $rolecode - User's current role in course (for switchserver query string).
16933:
16934: $required - LON-CAPA version needed by course (format: Major.Minor).
16935:
16936:
16937: Returns:
16938:
16939: $switchserver - query string tp append to /adm/switchserver call (if
16940: current server's LON-CAPA version is too old.
16941:
16942: $warning - Message is displayed if no suitable server could be found.
16943:
16944: =cut
16945:
16946: sub check_release_required {
16947: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16948: my ($switchserver,$warning);
16949: if ($required ne '') {
16950: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16951: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16952: if ($reqdmajor ne '' && $reqdminor ne '') {
16953: my $otherserver;
16954: if (($major eq '' && $minor eq '') ||
16955: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16956: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16957: my $switchlcrev =
16958: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16959: $userdomserver);
16960: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16961: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16962: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16963: my $cdom = $env{'course.'.$courseid.'.domain'};
16964: if ($cdom ne $env{'user.domain'}) {
16965: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16966: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16967: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16968: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16969: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16970: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16971: my $canhost =
16972: &Apache::lonnet::can_host_session($env{'user.domain'},
16973: $coursedomserver,
16974: $remoterev,
16975: $udomdefaults{'remotesessions'},
16976: $defdomdefaults{'hostedsessions'});
16977:
16978: if ($canhost) {
16979: $otherserver = $coursedomserver;
16980: } else {
16981: $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.");
16982: }
16983: } else {
16984: $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).");
16985: }
16986: } else {
16987: $otherserver = $userdomserver;
16988: }
16989: }
16990: if ($otherserver ne '') {
16991: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16992: }
16993: }
16994: }
16995: return ($switchserver,$warning);
16996: }
16997:
16998: =pod
16999:
17000: =item * &check_release_result()
17001:
17002: Inputs:
17003:
17004: $switchwarning - Warning message if no suitable server found to host session.
17005:
17006: $switchserver - query string to append to /adm/switchserver containing lonHostID
17007: and current role.
17008:
17009: Returns: HTML to display with information about requirement to switch server.
17010: Either displaying warning with link to Roles/Courses screen or
17011: display link to switchserver.
17012:
1.1075.2.69 raeburn 17013: =cut
17014:
1.1075.2.88 raeburn 17015: sub check_release_result {
17016: my ($switchwarning,$switchserver) = @_;
17017: my $output = &start_page('Selected course unavailable on this server').
17018: '<p class="LC_warning">';
17019: if ($switchwarning) {
17020: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17021: if (&show_course()) {
17022: $output .= &mt('Display courses');
17023: } else {
17024: $output .= &mt('Display roles');
17025: }
17026: $output .= '</a>';
17027: } elsif ($switchserver) {
17028: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17029: '<br />'.
17030: '<a href="/adm/switchserver?'.$switchserver.'">'.
17031: &mt('Switch Server').
17032: '</a>';
17033: }
17034: $output .= '</p>'.&end_page();
17035: return $output;
17036: }
17037:
17038: =pod
17039:
17040: =item * &needs_coursereinit()
17041:
17042: Determine if course contents stored for user's session needs to be
17043: refreshed, because content has changed since "Big Hash" last tied.
17044:
17045: Check for change is made if time last checked is more than 10 minutes ago
17046: (by default).
17047:
17048: Inputs:
17049:
17050: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17051:
17052: $interval (optional) - Time which may elapse (in s) between last check for content
17053: change in current course. (default: 600 s).
17054:
17055: Returns: an array; first element is:
17056:
17057: =over 4
17058:
17059: 'switch' - if content updates mean user's session
17060: needs to be switched to a server running a newer LON-CAPA version
17061:
17062: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17063: on current server hosting user's session
17064:
17065: '' - if no action required.
17066:
17067: =back
17068:
17069: If first item element is 'switch':
17070:
17071: second item is $switchwarning - Warning message if no suitable server found to host session.
17072:
17073: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17074: and current role.
17075:
17076: otherwise: no other elements returned.
17077:
17078: =back
17079:
17080: =cut
17081:
17082: sub needs_coursereinit {
17083: my ($loncaparev,$interval) = @_;
17084: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17085: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17086: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17087: my $now = time;
17088: if ($interval eq '') {
17089: $interval = 600;
17090: }
17091: if (($now-$env{'request.course.timechecked'})>$interval) {
17092: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17093: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
17094: if ($lastchange > $env{'request.course.tied'}) {
17095: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17096: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17097: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17098: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17099: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17100: $curr_reqd_hash{'internal.releaserequired'}});
17101: my ($switchserver,$switchwarning) =
17102: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17103: $curr_reqd_hash{'internal.releaserequired'});
17104: if ($switchwarning ne '' || $switchserver ne '') {
17105: return ('switch',$switchwarning,$switchserver);
17106: }
17107: }
17108: }
17109: return ('update');
17110: }
17111: }
17112: return ();
17113: }
1.1075.2.69 raeburn 17114:
1.1075.2.11 raeburn 17115: sub update_content_constraints {
17116: my ($cdom,$cnum,$chome,$cid) = @_;
17117: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17118: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
17119: my %checkresponsetypes;
17120: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
17121: my ($item,$name,$value) = split(/:/,$key);
17122: if ($item eq 'resourcetag') {
17123: if ($name eq 'responsetype') {
17124: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17125: }
17126: }
17127: }
17128: my $navmap = Apache::lonnavmaps::navmap->new();
17129: if (defined($navmap)) {
17130: my %allresponses;
17131: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17132: my %responses = $res->responseTypes();
17133: foreach my $key (keys(%responses)) {
17134: next unless(exists($checkresponsetypes{$key}));
17135: $allresponses{$key} += $responses{$key};
17136: }
17137: }
17138: foreach my $key (keys(%allresponses)) {
17139: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17140: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17141: ($reqdmajor,$reqdminor) = ($major,$minor);
17142: }
17143: }
17144: undef($navmap);
17145: }
17146: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17147: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17148: }
17149: return;
17150: }
17151:
1.1075.2.27 raeburn 17152: sub allmaps_incourse {
17153: my ($cdom,$cnum,$chome,$cid) = @_;
17154: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17155: $cid = $env{'request.course.id'};
17156: $cdom = $env{'course.'.$cid.'.domain'};
17157: $cnum = $env{'course.'.$cid.'.num'};
17158: $chome = $env{'course.'.$cid.'.home'};
17159: }
17160: my %allmaps = ();
17161: my $lastchange =
17162: &Apache::lonnet::get_coursechange($cdom,$cnum);
17163: if ($lastchange > $env{'request.course.tied'}) {
17164: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17165: unless ($ferr) {
17166: &update_content_constraints($cdom,$cnum,$chome,$cid);
17167: }
17168: }
17169: my $navmap = Apache::lonnavmaps::navmap->new();
17170: if (defined($navmap)) {
17171: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17172: $allmaps{$res->src()} = 1;
17173: }
17174: }
17175: return \%allmaps;
17176: }
17177:
1.1075.2.11 raeburn 17178: sub parse_supplemental_title {
17179: my ($title) = @_;
17180:
17181: my ($foldertitle,$renametitle);
17182: if ($title =~ /&&&/) {
17183: $title = &HTML::Entites::decode($title);
17184: }
17185: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17186: $renametitle=$4;
17187: my ($time,$uname,$udom) = ($1,$2,$3);
17188: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17189: my $name = &plainname($uname,$udom);
17190: $name = &HTML::Entities::encode($name,'"<>&\'');
17191: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17192: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17193: $name.': <br />'.$foldertitle;
17194: }
17195: if (wantarray) {
17196: return ($title,$foldertitle,$renametitle);
17197: }
17198: return $title;
17199: }
17200:
1.1075.2.43 raeburn 17201: sub recurse_supplemental {
17202: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
17203: if ($suppmap) {
17204: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17205: if ($fatal) {
17206: $errors ++;
17207: } else {
1.1075.2.167 raeburn 17208: my @order = @LONCAPA::map::order;
17209: if (@order > 0) {
17210: my @resources = @LONCAPA::map::resources;
17211: my @resparms = @LONCAPA::map::resparms;
17212: foreach my $idx (@order) {
17213: my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1075.2.43 raeburn 17214: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 17215: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
17216: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 17217: } else {
17218: $numfiles ++;
17219: }
17220: }
17221: }
17222: }
17223: }
17224: }
17225: return ($numfiles,$errors);
17226: }
17227:
1.1075.2.18 raeburn 17228: sub symb_to_docspath {
1.1075.2.119 raeburn 17229: my ($symb,$navmapref) = @_;
17230: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 17231: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17232: if ($resurl=~/\.(sequence|page)$/) {
17233: $mapurl=$resurl;
17234: } elsif ($resurl eq 'adm/navmaps') {
17235: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17236: }
17237: my $mapresobj;
1.1075.2.119 raeburn 17238: unless (ref($$navmapref)) {
17239: $$navmapref = Apache::lonnavmaps::navmap->new();
17240: }
17241: if (ref($$navmapref)) {
17242: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 17243: }
17244: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17245: my $type=$2;
17246: my $path;
17247: if (ref($mapresobj)) {
17248: my $pcslist = $mapresobj->map_hierarchy();
17249: if ($pcslist ne '') {
17250: foreach my $pc (split(/,/,$pcslist)) {
17251: next if ($pc <= 1);
1.1075.2.119 raeburn 17252: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 17253: if (ref($res)) {
17254: my $thisurl = $res->src();
17255: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17256: my $thistitle = $res->title();
17257: $path .= '&'.
17258: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 17259: &escape($thistitle).
1.1075.2.18 raeburn 17260: ':'.$res->randompick().
17261: ':'.$res->randomout().
17262: ':'.$res->encrypted().
17263: ':'.$res->randomorder().
17264: ':'.$res->is_page();
17265: }
17266: }
17267: }
17268: $path =~ s/^\&//;
17269: my $maptitle = $mapresobj->title();
17270: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17271: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17272: }
17273: $path .= (($path ne '')? '&' : '').
17274: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17275: &escape($maptitle).
1.1075.2.18 raeburn 17276: ':'.$mapresobj->randompick().
17277: ':'.$mapresobj->randomout().
17278: ':'.$mapresobj->encrypted().
17279: ':'.$mapresobj->randomorder().
17280: ':'.$mapresobj->is_page();
17281: } else {
17282: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17283: my $ispage = (($type eq 'page')? 1 : '');
17284: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17285: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17286: }
17287: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17288: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 17289: }
17290: unless ($mapurl eq 'default') {
17291: $path = 'default&'.
1.1075.2.46 raeburn 17292: &escape('Main Content').
1.1075.2.18 raeburn 17293: ':::::&'.$path;
17294: }
17295: return $path;
17296: }
17297:
1.1075.2.14 raeburn 17298: sub captcha_display {
1.1075.2.137 raeburn 17299: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17300: my ($output,$error);
1.1075.2.107 raeburn 17301: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 17302: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17303: if ($captcha eq 'original') {
17304: $output = &create_captcha();
17305: unless ($output) {
17306: $error = 'captcha';
17307: }
17308: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17309: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 17310: unless ($output) {
17311: $error = 'recaptcha';
17312: }
17313: }
1.1075.2.107 raeburn 17314: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 17315: }
17316:
17317: sub captcha_response {
1.1075.2.137 raeburn 17318: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17319: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 17320: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17321: if ($captcha eq 'original') {
17322: ($captcha_chk,$captcha_error) = &check_captcha();
17323: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17324: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 17325: } else {
17326: $captcha_chk = 1;
17327: }
17328: return ($captcha_chk,$captcha_error);
17329: }
17330:
17331: sub get_captcha_config {
1.1075.2.137 raeburn 17332: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 17333: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 17334: my $hostname = &Apache::lonnet::hostname($lonhost);
17335: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17336: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17337: if ($context eq 'usercreation') {
17338: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17339: if (ref($domconfig{$context}) eq 'HASH') {
17340: $hashtocheck = $domconfig{$context}{'cancreate'};
17341: if (ref($hashtocheck) eq 'HASH') {
17342: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17343: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17344: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17345: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17346: }
17347: if ($privkey && $pubkey) {
17348: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17349: $version = $hashtocheck->{'recaptchaversion'};
17350: if ($version ne '2') {
17351: $version = 1;
17352: }
1.1075.2.14 raeburn 17353: } else {
17354: $captcha = 'original';
17355: }
17356: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17357: $captcha = 'original';
17358: }
17359: }
17360: } else {
17361: $captcha = 'captcha';
17362: }
17363: } elsif ($context eq 'login') {
17364: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17365: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17366: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17367: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
17368: if ($privkey && $pubkey) {
17369: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17370: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17371: if ($version ne '2') {
17372: $version = 1;
17373: }
1.1075.2.14 raeburn 17374: } else {
17375: $captcha = 'original';
17376: }
17377: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17378: $captcha = 'original';
17379: }
1.1075.2.137 raeburn 17380: } elsif ($context eq 'passwords') {
17381: if ($dom_in_effect) {
17382: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17383: if ($passwdconf{'captcha'} eq 'recaptcha') {
17384: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17385: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17386: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17387: }
17388: if ($privkey && $pubkey) {
17389: $captcha = 'recaptcha';
17390: $version = $passwdconf{'recaptchaversion'};
17391: if ($version ne '2') {
17392: $version = 1;
17393: }
17394: } else {
17395: $captcha = 'original';
17396: }
17397: } elsif ($passwdconf{'captcha'} ne 'notused') {
17398: $captcha = 'original';
17399: }
17400: }
1.1075.2.14 raeburn 17401: }
1.1075.2.107 raeburn 17402: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 17403: }
17404:
17405: sub create_captcha {
17406: my %captcha_params = &captcha_settings();
17407: my ($output,$maxtries,$tries) = ('',10,0);
17408: while ($tries < $maxtries) {
17409: $tries ++;
17410: my $captcha = Authen::Captcha->new (
17411: output_folder => $captcha_params{'output_dir'},
17412: data_folder => $captcha_params{'db_dir'},
17413: );
17414: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17415:
17416: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17417: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1075.2.158 raeburn 17418: '<span class="LC_nobreak">'.
1.1075.2.14 raeburn 17419: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.167 raeburn 17420: '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1075.2.158 raeburn 17421: '</span><br />'.
1.1075.2.66 raeburn 17422: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 17423: last;
17424: }
17425: }
1.1075.2.158 raeburn 17426: if ($output eq '') {
17427: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
17428: }
1.1075.2.14 raeburn 17429: return $output;
17430: }
17431:
17432: sub captcha_settings {
17433: my %captcha_params = (
17434: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17435: www_output_dir => "/captchaspool",
17436: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17437: numchars => '5',
17438: );
17439: return %captcha_params;
17440: }
17441:
17442: sub check_captcha {
17443: my ($captcha_chk,$captcha_error);
17444: my $code = $env{'form.code'};
17445: my $md5sum = $env{'form.crypt'};
17446: my %captcha_params = &captcha_settings();
17447: my $captcha = Authen::Captcha->new(
17448: output_folder => $captcha_params{'output_dir'},
17449: data_folder => $captcha_params{'db_dir'},
17450: );
1.1075.2.26 raeburn 17451: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 17452: my %captcha_hash = (
17453: 0 => 'Code not checked (file error)',
17454: -1 => 'Failed: code expired',
17455: -2 => 'Failed: invalid code (not in database)',
17456: -3 => 'Failed: invalid code (code does not match crypt)',
17457: );
17458: if ($captcha_chk != 1) {
17459: $captcha_error = $captcha_hash{$captcha_chk}
17460: }
17461: return ($captcha_chk,$captcha_error);
17462: }
17463:
17464: sub create_recaptcha {
1.1075.2.107 raeburn 17465: my ($pubkey,$version) = @_;
17466: if ($version >= 2) {
1.1075.2.158 raeburn 17467: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
17468: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1075.2.107 raeburn 17469: } else {
17470: my $use_ssl;
17471: if ($ENV{'SERVER_PORT'} == 443) {
17472: $use_ssl = 1;
17473: }
17474: my $captcha = Captcha::reCAPTCHA->new;
17475: return $captcha->get_options_setter({theme => 'white'})."\n".
17476: $captcha->get_html($pubkey,undef,$use_ssl).
17477: &mt('If the text is hard to read, [_1] will replace them.',
17478: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17479: '<br /><br />';
17480: }
1.1075.2.14 raeburn 17481: }
17482:
17483: sub check_recaptcha {
1.1075.2.107 raeburn 17484: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 17485: my $captcha_chk;
1.1075.2.150 raeburn 17486: my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 17487: if ($version >= 2) {
17488: my $ua = LWP::UserAgent->new;
17489: $ua->timeout(10);
17490: my %info = (
17491: secret => $privkey,
17492: response => $env{'form.g-recaptcha-response'},
1.1075.2.150 raeburn 17493: remoteip => $ip,
1.1075.2.107 raeburn 17494: );
17495: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17496: if ($response->is_success) {
17497: my $data = JSON::DWIW->from_json($response->decoded_content);
17498: if (ref($data) eq 'HASH') {
17499: if ($data->{'success'}) {
17500: $captcha_chk = 1;
17501: }
17502: }
17503: }
17504: } else {
17505: my $captcha = Captcha::reCAPTCHA->new;
17506: my $captcha_result =
17507: $captcha->check_answer(
17508: $privkey,
1.1075.2.150 raeburn 17509: $ip,
1.1075.2.107 raeburn 17510: $env{'form.recaptcha_challenge_field'},
17511: $env{'form.recaptcha_response_field'},
17512: );
17513: if ($captcha_result->{is_valid}) {
17514: $captcha_chk = 1;
17515: }
1.1075.2.14 raeburn 17516: }
17517: return $captcha_chk;
17518: }
17519:
1.1075.2.64 raeburn 17520: sub emailusername_info {
1.1075.2.103 raeburn 17521: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 17522: my %titles = &Apache::lonlocal::texthash (
17523: lastname => 'Last Name',
17524: firstname => 'First Name',
17525: institution => 'School/college/university',
17526: location => "School's city, state/province, country",
17527: web => "School's web address",
17528: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 17529: id => 'Student/Employee ID',
1.1075.2.64 raeburn 17530: );
17531: return (\@fields,\%titles);
17532: }
17533:
1.1075.2.56 raeburn 17534: sub cleanup_html {
17535: my ($incoming) = @_;
17536: my $outgoing;
17537: if ($incoming ne '') {
17538: $outgoing = $incoming;
17539: $outgoing =~ s/;/;/g;
17540: $outgoing =~ s/\#/#/g;
17541: $outgoing =~ s/\&/&/g;
17542: $outgoing =~ s/</</g;
17543: $outgoing =~ s/>/>/g;
17544: $outgoing =~ s/\(/(/g;
17545: $outgoing =~ s/\)/)/g;
17546: $outgoing =~ s/"/"/g;
17547: $outgoing =~ s/'/'/g;
17548: $outgoing =~ s/\$/$/g;
17549: $outgoing =~ s{/}{/}g;
17550: $outgoing =~ s/=/=/g;
17551: $outgoing =~ s/\\/\/g
17552: }
17553: return $outgoing;
17554: }
17555:
1.1075.2.74 raeburn 17556: # Checks for critical messages and returns a redirect url if one exists.
17557: # $interval indicates how often to check for messages.
17558: sub critical_redirect {
17559: my ($interval) = @_;
1.1075.2.158 raeburn 17560: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
17561: return ();
17562: }
1.1075.2.74 raeburn 17563: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17564: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17565: $env{'user.name'});
17566: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17567: my $redirecturl;
17568: if ($what[0]) {
1.1075.2.158 raeburn 17569: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1075.2.74 raeburn 17570: $redirecturl='/adm/email?critical=display';
17571: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17572: return (1, $url);
17573: }
17574: }
17575: }
17576: return ();
17577: }
17578:
1.1075.2.64 raeburn 17579: # Use:
17580: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17581: #
17582: ##################################################
17583: # password associated functions #
17584: ##################################################
17585: sub des_keys {
17586: # Make a new key for DES encryption.
17587: # Each key has two parts which are returned separately.
17588: # Please note: Each key must be passed through the &hex function
17589: # before it is output to the web browser. The hex versions cannot
17590: # be used to decrypt.
17591: my @hexstr=('0','1','2','3','4','5','6','7',
17592: '8','9','a','b','c','d','e','f');
17593: my $lkey='';
17594: for (0..7) {
17595: $lkey.=$hexstr[rand(15)];
17596: }
17597: my $ukey='';
17598: for (0..7) {
17599: $ukey.=$hexstr[rand(15)];
17600: }
17601: return ($lkey,$ukey);
17602: }
17603:
17604: sub des_decrypt {
17605: my ($key,$cyphertext) = @_;
17606: my $keybin=pack("H16",$key);
17607: my $cypher;
17608: if ($Crypt::DES::VERSION>=2.03) {
17609: $cypher=new Crypt::DES $keybin;
17610: } else {
17611: $cypher=new DES $keybin;
17612: }
1.1075.2.106 raeburn 17613: my $plaintext='';
17614: my $cypherlength = length($cyphertext);
17615: my $numchunks = int($cypherlength/32);
17616: for (my $j=0; $j<$numchunks; $j++) {
17617: my $start = $j*32;
17618: my $cypherblock = substr($cyphertext,$start,32);
17619: my $chunk =
17620: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17621: $chunk .=
17622: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17623: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17624: $plaintext .= $chunk;
17625: }
1.1075.2.64 raeburn 17626: return $plaintext;
17627: }
17628:
1.1075.2.135 raeburn 17629: sub is_nonframeable {
17630: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
17631: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
17632: return if (($remprotocol eq '') || ($remhost eq ''));
17633:
17634: $remprotocol = lc($remprotocol);
17635: $remhost = lc($remhost);
17636: my $remport = 80;
17637: if ($remprotocol eq 'https') {
17638: $remport = 443;
17639: }
17640: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
17641: if ($cached) {
17642: unless ($nocache) {
17643: if ($result) {
17644: return 1;
17645: } else {
17646: return 0;
17647: }
17648: }
17649: }
17650: my $uselink;
17651: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 17652: my $ua = LWP::UserAgent->new;
17653: $ua->timeout(5);
17654: my $response=$ua->request($request);
1.1075.2.135 raeburn 17655: if ($response->is_success()) {
17656: my $secpolicy = lc($response->header('content-security-policy'));
17657: my $xframeop = lc($response->header('x-frame-options'));
17658: $secpolicy =~ s/^\s+|\s+$//g;
17659: $xframeop =~ s/^\s+|\s+$//g;
17660: if (($secpolicy ne '') || ($xframeop ne '')) {
17661: my $remotehost = $remprotocol.'://'.$remhost;
17662: my ($origin,$protocol,$port);
17663: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17664: $port = $ENV{'SERVER_PORT'};
17665: } else {
17666: $port = 80;
17667: }
17668: if ($absolute eq '') {
17669: $protocol = 'http:';
17670: if ($port == 443) {
17671: $protocol = 'https:';
17672: }
17673: $origin = $protocol.'//'.lc($hostname);
17674: } else {
17675: $origin = lc($absolute);
17676: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17677: }
17678: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17679: my $framepolicy = $1;
17680: $framepolicy =~ s/^\s+|\s+$//g;
17681: my @policies = split(/\s+/,$framepolicy);
17682: if (@policies) {
17683: if (grep(/^\Q'none'\E$/,@policies)) {
17684: $uselink = 1;
17685: } else {
17686: $uselink = 1;
17687: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17688: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17689: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17690: undef($uselink);
17691: }
17692: if ($uselink) {
17693: if (grep(/^\Q'self'\E$/,@policies)) {
17694: if (($origin ne '') && ($remotehost eq $origin)) {
17695: undef($uselink);
17696: }
17697: }
17698: }
17699: if ($uselink) {
17700: my @possok;
17701: if ($ip ne '') {
17702: push(@possok,$ip);
17703: }
17704: my $hoststr = '';
17705: foreach my $part (reverse(split(/\./,$hostname))) {
17706: if ($hoststr eq '') {
17707: $hoststr = $part;
17708: } else {
17709: $hoststr = "$part.$hoststr";
17710: }
17711: if ($hoststr eq $hostname) {
17712: push(@possok,$hostname);
17713: } else {
17714: push(@possok,"*.$hoststr");
17715: }
17716: }
17717: if (@possok) {
17718: foreach my $poss (@possok) {
17719: last if (!$uselink);
17720: foreach my $policy (@policies) {
17721: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17722: undef($uselink);
17723: last;
17724: }
17725: }
17726: }
17727: }
17728: }
17729: }
17730: }
17731: } elsif ($xframeop ne '') {
17732: $uselink = 1;
17733: my @policies = split(/\s*,\s*/,$xframeop);
17734: if (@policies) {
17735: unless (grep(/^deny$/,@policies)) {
17736: if ($origin ne '') {
17737: if (grep(/^sameorigin$/,@policies)) {
17738: if ($remotehost eq $origin) {
17739: undef($uselink);
17740: }
17741: }
17742: if ($uselink) {
17743: foreach my $policy (@policies) {
17744: if ($policy =~ /^allow-from\s*(.+)$/) {
17745: my $allowfrom = $1;
17746: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17747: undef($uselink);
17748: last;
17749: }
17750: }
17751: }
17752: }
17753: }
17754: }
17755: }
17756: }
17757: }
17758: }
17759: if ($nocache) {
17760: if ($cached) {
17761: my $devalidate;
17762: if ($uselink && !$result) {
17763: $devalidate = 1;
17764: } elsif (!$uselink && $result) {
17765: $devalidate = 1;
17766: }
17767: if ($devalidate) {
17768: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17769: }
17770: }
17771: } else {
17772: if ($uselink) {
17773: $result = 1;
17774: } else {
17775: $result = 0;
17776: }
17777: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17778: }
17779: return $uselink;
17780: }
17781:
1.112 bowersj2 17782: 1;
17783: __END__;
1.41 ng 17784:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>