Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.171
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.171! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.170 2024/10/05 23:19:24 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.52 raeburn 5813: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5814: Apache::lonmenu::serverform();
5815: my $forbodytag;
5816: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5817: $forcereg,$args->{'group'},
5818: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5819: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 5820: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5821: $funclist = $forbodytag;
5822: }
5823: } else {
1.903 droeschl 5824:
5825: # if ($env{'request.state'} eq 'construct') {
5826: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5827: # }
5828:
1.1075.2.38 raeburn 5829: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5830: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5831:
1.1075.2.171! raeburn 5832: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} eq 'construct')) {
! 5833: unless ($env{'form.inhibitmenu'}) {
! 5834: $bodytag .= &inline_for_remote($public,$role,$realm,$dc_info,$no_inline_link);
! 5835: }
! 5836: } else {
! 5837: my ($left,$right) = Apache::lonmenu::primary_menu($args->{'links_disabled'});
1.1075.2.2 raeburn 5838:
1.1075.2.171! raeburn 5839: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
! 5840: if ($dc_info) {
! 5841: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
! 5842: }
! 5843: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
! 5844: <em>$realm</em> $dc_info</div>|;
! 5845:
! 5846: return $bodytag;
1.1075.2.1 raeburn 5847: }
1.894 droeschl 5848:
1.1075.2.171! raeburn 5849: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
! 5850: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
! 5851: }
1.916 droeschl 5852:
1.1075.2.171! raeburn 5853: $bodytag .= $right;
1.852 droeschl 5854:
1.1075.2.171! raeburn 5855: if ($dc_info) {
! 5856: $dc_info = &dc_courseid_toggle($dc_info);
! 5857: }
! 5858: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 5859: }
1.916 droeschl 5860:
1.1075.2.61 raeburn 5861: #if directed to not display the secondary menu, don't.
5862: if ($args->{'no_secondary_menu'}) {
5863: return $bodytag;
5864: }
1.903 droeschl 5865: #don't show menus for public users
1.954 raeburn 5866: if (!$public){
1.1075.2.171! raeburn 5867: unless (($env{'environment.remote'} eq 'on') &&
! 5868: ($env{'request.state'} eq 'construct')) {
! 5869: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$args->{'links_disabled'});
! 5870: }
1.903 droeschl 5871: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5872: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5873: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5874: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.133 raeburn 5875: $args->{'bread_crumbs'},'','',$hostname);
1.1075.2.116 raeburn 5876: } elsif ($forcereg) {
1.1075.2.22 raeburn 5877: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5878: $args->{'group'},
1.1075.2.161 raeburn 5879: $args->{'hide_buttons'},
5880: $hostname);
1.1075.2.15 raeburn 5881: } else {
1.1075.2.21 raeburn 5882: my $forbodytag;
5883: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5884: $forcereg,$args->{'group'},
5885: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5886: $advtoolsref,'',$hostname,
5887: \$forbodytag);
1.1075.2.21 raeburn 5888: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5889: $bodytag .= $forbodytag;
5890: }
1.920 raeburn 5891: }
1.903 droeschl 5892: }else{
5893: # this is to seperate menu from content when there's no secondary
5894: # menu. Especially needed for public accessible ressources.
5895: $bodytag .= '<hr style="clear:both" />';
5896: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5897: }
1.903 droeschl 5898:
1.235 raeburn 5899: return $bodytag;
1.1075.2.12 raeburn 5900: }
5901:
5902: #
5903: # Top frame rendering, Remote is up
5904: #
5905:
1.1075.2.60 raeburn 5906: my $help=($no_inline_link?''
5907: :&Apache::loncommon::top_nav_help('Help'));
5908:
1.1075.2.12 raeburn 5909: # Explicit link to get inline menu
5910: my $menu= ($no_inline_link?''
5911: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5912:
5913: if ($dc_info) {
5914: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5915: }
5916:
1.1075.2.38 raeburn 5917: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5918: unless ($public) {
5919: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5920: undef,'LC_menubuttons_link');
5921: }
5922:
1.1075.2.12 raeburn 5923: unless ($env{'form.inhibitmenu'}) {
1.1075.2.171! raeburn 5924: $bodytag .= &inline_for_remote($public,$role,$realm,$dc_info,$no_inline_link);
1.1075.2.12 raeburn 5925: }
1.1075.2.21 raeburn 5926: return $bodytag."\n".$funclist;
1.182 matthew 5927: }
5928:
1.1075.2.171! raeburn 5929: sub inline_for_remote {
! 5930: my ($public,$role,$realm,$dc_info,$no_inline_link) = @_;
! 5931: my $help=($no_inline_link?''
! 5932: :&Apache::loncommon::top_nav_help('Help'));
! 5933:
! 5934: # Explicit link to get inline menu
! 5935: my $menu= ($no_inline_link?''
! 5936: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
! 5937:
! 5938: if ($dc_info) {
! 5939: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
! 5940: }
! 5941:
! 5942: my $name = &plainname($env{'user.name'},$env{'user.domain'});
! 5943: unless ($public) {
! 5944: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
! 5945: undef,'LC_menubuttons_link');
! 5946: }
! 5947:
! 5948: return qq|<div id="LC_nav_bar">$name $role</div>
! 5949: <ol class="LC_primary_menu LC_floatright LC_right">
! 5950: <li>$help</li>
! 5951: <li>$menu</li>
! 5952: </ol><div id="LC_realm"> $realm $dc_info</div>|;
! 5953: }
! 5954:
1.917 raeburn 5955: sub dc_courseid_toggle {
5956: my ($dc_info) = @_;
1.980 raeburn 5957: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5958: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5959: &mt('(More ...)').'</a></span>'.
5960: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5961: }
5962:
1.330 albertel 5963: sub make_attr_string {
5964: my ($register,$attr_ref) = @_;
5965:
5966: if ($attr_ref && !ref($attr_ref)) {
5967: die("addentries Must be a hash ref ".
5968: join(':',caller(1))." ".
5969: join(':',caller(0))." ");
5970: }
5971:
5972: if ($register) {
1.339 albertel 5973: my ($on_load,$on_unload);
5974: foreach my $key (keys(%{$attr_ref})) {
5975: if (lc($key) eq 'onload') {
5976: $on_load.=$attr_ref->{$key}.';';
5977: delete($attr_ref->{$key});
5978:
5979: } elsif (lc($key) eq 'onunload') {
5980: $on_unload.=$attr_ref->{$key}.';';
5981: delete($attr_ref->{$key});
5982: }
5983: }
1.1075.2.12 raeburn 5984: if ($env{'environment.remote'} eq 'on') {
5985: $attr_ref->{'onload'} =
5986: &Apache::lonmenu::loadevents(). $on_load;
5987: $attr_ref->{'onunload'}=
5988: &Apache::lonmenu::unloadevents().$on_unload;
5989: } else {
5990: $attr_ref->{'onload'} = $on_load;
5991: $attr_ref->{'onunload'}= $on_unload;
5992: }
1.330 albertel 5993: }
1.339 albertel 5994:
1.330 albertel 5995: my $attr_string;
1.1075.2.56 raeburn 5996: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5997: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5998: }
5999: return $attr_string;
6000: }
6001:
6002:
1.182 matthew 6003: ###############################################
1.251 albertel 6004: ###############################################
6005:
6006: =pod
6007:
6008: =item * &endbodytag()
6009:
6010: Returns a uniform footer for LON-CAPA web pages.
6011:
1.635 raeburn 6012: Inputs: 1 - optional reference to an args hash
6013: If in the hash, key for noredirectlink has a value which evaluates to true,
6014: a 'Continue' link is not displayed if the page contains an
6015: internal redirect in the <head></head> section,
6016: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6017:
6018: =cut
6019:
6020: sub endbodytag {
1.635 raeburn 6021: my ($args) = @_;
1.1075.2.6 raeburn 6022: my $endbodytag;
6023: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6024: $endbodytag='</body>';
6025: }
1.315 albertel 6026: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6027: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6028: $endbodytag=
6029: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6030: &mt('Continue').'</a>'.
6031: $endbodytag;
6032: }
1.315 albertel 6033: }
1.1075.2.165 raeburn 6034: if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
6035: $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
6036: }
1.251 albertel 6037: return $endbodytag;
6038: }
6039:
1.352 albertel 6040: =pod
6041:
6042: =item * &standard_css()
6043:
6044: Returns a style sheet
6045:
6046: Inputs: (all optional)
6047: domain -> force to color decorate a page for a specific
6048: domain
6049: function -> force usage of a specific rolish color scheme
6050: bgcolor -> override the default page bgcolor
6051:
6052: =cut
6053:
1.343 albertel 6054: sub standard_css {
1.345 albertel 6055: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6056: $function = &get_users_function() if (!$function);
6057: my $img = &designparm($function.'.img', $domain);
6058: my $tabbg = &designparm($function.'.tabbg', $domain);
6059: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6060: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6061: #second colour for later usage
1.345 albertel 6062: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6063: my $pgbg_or_bgcolor =
6064: $bgcolor ||
1.352 albertel 6065: &designparm($function.'.pgbg', $domain);
1.382 albertel 6066: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6067: my $alink = &designparm($function.'.alink', $domain);
6068: my $vlink = &designparm($function.'.vlink', $domain);
6069: my $link = &designparm($function.'.link', $domain);
6070:
1.602 albertel 6071: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6072: my $mono = 'monospace';
1.850 bisitz 6073: my $data_table_head = $sidebg;
6074: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6075: my $data_table_dark = '#E0E0E0';
1.470 banghart 6076: my $data_table_darker = '#CCCCCC';
1.349 albertel 6077: my $data_table_highlight = '#FFFF00';
1.352 albertel 6078: my $mail_new = '#FFBB77';
6079: my $mail_new_hover = '#DD9955';
6080: my $mail_read = '#BBBB77';
6081: my $mail_read_hover = '#999944';
6082: my $mail_replied = '#AAAA88';
6083: my $mail_replied_hover = '#888855';
6084: my $mail_other = '#99BBBB';
6085: my $mail_other_hover = '#669999';
1.391 albertel 6086: my $table_header = '#DDDDDD';
1.489 raeburn 6087: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6088: my $lg_border_color = '#C8C8C8';
1.952 onken 6089: my $button_hover = '#BF2317';
1.392 albertel 6090:
1.608 albertel 6091: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6092: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6093: : '0 3px 0 4px';
1.448 albertel 6094:
1.523 albertel 6095:
1.343 albertel 6096: return <<END;
1.947 droeschl 6097:
6098: /* needed for iframe to allow 100% height in FF */
6099: body, html {
6100: margin: 0;
6101: padding: 0 0.5%;
6102: height: 99%; /* to avoid scrollbars */
6103: }
6104:
1.795 www 6105: body {
1.911 bisitz 6106: font-family: $sans;
6107: line-height:130%;
6108: font-size:0.83em;
6109: color:$font;
1.795 www 6110: }
6111:
1.959 onken 6112: a:focus,
6113: a:focus img {
1.795 www 6114: color: red;
6115: }
1.698 harmsja 6116:
1.911 bisitz 6117: form, .inline {
6118: display: inline;
1.795 www 6119: }
1.721 harmsja 6120:
1.795 www 6121: .LC_right {
1.911 bisitz 6122: text-align:right;
1.795 www 6123: }
6124:
6125: .LC_middle {
1.911 bisitz 6126: vertical-align:middle;
1.795 www 6127: }
1.721 harmsja 6128:
1.1075.2.38 raeburn 6129: .LC_floatleft {
6130: float: left;
6131: }
6132:
6133: .LC_floatright {
6134: float: right;
6135: }
6136:
1.911 bisitz 6137: .LC_400Box {
6138: width:400px;
6139: }
1.721 harmsja 6140:
1.947 droeschl 6141: .LC_iframecontainer {
6142: width: 98%;
6143: margin: 0;
6144: position: fixed;
6145: top: 8.5em;
6146: bottom: 0;
6147: }
6148:
6149: .LC_iframecontainer iframe{
6150: border: none;
6151: width: 100%;
6152: height: 100%;
6153: }
6154:
1.778 bisitz 6155: .LC_filename {
6156: font-family: $mono;
6157: white-space:pre;
1.921 bisitz 6158: font-size: 120%;
1.778 bisitz 6159: }
6160:
6161: .LC_fileicon {
6162: border: none;
6163: height: 1.3em;
6164: vertical-align: text-bottom;
6165: margin-right: 0.3em;
6166: text-decoration:none;
6167: }
6168:
1.1008 www 6169: .LC_setting {
6170: text-decoration:underline;
6171: }
6172:
1.350 albertel 6173: .LC_error {
6174: color: red;
6175: }
1.795 www 6176:
1.1075.2.15 raeburn 6177: .LC_warning {
6178: color: darkorange;
6179: }
6180:
1.457 albertel 6181: .LC_diff_removed {
1.733 bisitz 6182: color: red;
1.394 albertel 6183: }
1.532 albertel 6184:
6185: .LC_info,
1.457 albertel 6186: .LC_success,
6187: .LC_diff_added {
1.350 albertel 6188: color: green;
6189: }
1.795 www 6190:
1.802 bisitz 6191: div.LC_confirm_box {
6192: background-color: #FAFAFA;
6193: border: 1px solid $lg_border_color;
6194: margin-right: 0;
6195: padding: 5px;
6196: }
6197:
6198: div.LC_confirm_box .LC_error img,
6199: div.LC_confirm_box .LC_success img {
6200: vertical-align: middle;
6201: }
6202:
1.1075.2.108 raeburn 6203: .LC_maxwidth {
6204: max-width: 100%;
6205: height: auto;
6206: }
6207:
6208: .LC_textsize_mobile {
6209: \@media only screen and (max-device-width: 480px) {
6210: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6211: }
6212: }
6213:
1.440 albertel 6214: .LC_icon {
1.771 droeschl 6215: border: none;
1.790 droeschl 6216: vertical-align: middle;
1.771 droeschl 6217: }
6218:
1.543 albertel 6219: .LC_docs_spacer {
6220: width: 25px;
6221: height: 1px;
1.771 droeschl 6222: border: none;
1.543 albertel 6223: }
1.346 albertel 6224:
1.532 albertel 6225: .LC_internal_info {
1.735 bisitz 6226: color: #999999;
1.532 albertel 6227: }
6228:
1.794 www 6229: .LC_discussion {
1.1050 www 6230: background: $data_table_dark;
1.911 bisitz 6231: border: 1px solid black;
6232: margin: 2px;
1.794 www 6233: }
6234:
6235: .LC_disc_action_left {
1.1050 www 6236: background: $sidebg;
1.911 bisitz 6237: text-align: left;
1.1050 www 6238: padding: 4px;
6239: margin: 2px;
1.794 www 6240: }
6241:
6242: .LC_disc_action_right {
1.1050 www 6243: background: $sidebg;
1.911 bisitz 6244: text-align: right;
1.1050 www 6245: padding: 4px;
6246: margin: 2px;
1.794 www 6247: }
6248:
6249: .LC_disc_new_item {
1.911 bisitz 6250: background: white;
6251: border: 2px solid red;
1.1050 www 6252: margin: 4px;
6253: padding: 4px;
1.794 www 6254: }
6255:
6256: .LC_disc_old_item {
1.911 bisitz 6257: background: white;
1.1050 www 6258: margin: 4px;
6259: padding: 4px;
1.794 www 6260: }
6261:
1.458 albertel 6262: table.LC_pastsubmission {
6263: border: 1px solid black;
6264: margin: 2px;
6265: }
6266:
1.924 bisitz 6267: table#LC_menubuttons {
1.345 albertel 6268: width: 100%;
6269: background: $pgbg;
1.392 albertel 6270: border: 2px;
1.402 albertel 6271: border-collapse: separate;
1.803 bisitz 6272: padding: 0;
1.345 albertel 6273: }
1.392 albertel 6274:
1.801 tempelho 6275: table#LC_title_bar a {
6276: color: $fontmenu;
6277: }
1.836 bisitz 6278:
1.807 droeschl 6279: table#LC_title_bar {
1.819 tempelho 6280: clear: both;
1.836 bisitz 6281: display: none;
1.807 droeschl 6282: }
6283:
1.795 www 6284: table#LC_title_bar,
1.933 droeschl 6285: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6286: table#LC_title_bar.LC_with_remote {
1.359 albertel 6287: width: 100%;
1.392 albertel 6288: border-color: $pgbg;
6289: border-style: solid;
6290: border-width: $border;
1.379 albertel 6291: background: $pgbg;
1.801 tempelho 6292: color: $fontmenu;
1.392 albertel 6293: border-collapse: collapse;
1.803 bisitz 6294: padding: 0;
1.819 tempelho 6295: margin: 0;
1.359 albertel 6296: }
1.795 www 6297:
1.933 droeschl 6298: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6299: margin: 0;
6300: padding: 0;
1.933 droeschl 6301: position: relative;
6302: list-style: none;
1.913 droeschl 6303: }
1.933 droeschl 6304: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6305: display: inline;
6306: }
1.933 droeschl 6307:
6308: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6309: padding: 0;
1.933 droeschl 6310: margin: 0;
6311: float: left;
1.913 droeschl 6312: }
1.933 droeschl 6313: .LC_breadcrumb_tools_tools {
6314: padding: 0;
6315: margin: 0;
1.913 droeschl 6316: float: right;
6317: }
6318:
1.359 albertel 6319: table#LC_title_bar td {
6320: background: $tabbg;
6321: }
1.795 www 6322:
1.911 bisitz 6323: table#LC_menubuttons img {
1.803 bisitz 6324: border: none;
1.346 albertel 6325: }
1.795 www 6326:
1.842 droeschl 6327: .LC_breadcrumbs_component {
1.911 bisitz 6328: float: right;
6329: margin: 0 1em;
1.357 albertel 6330: }
1.842 droeschl 6331: .LC_breadcrumbs_component img {
1.911 bisitz 6332: vertical-align: middle;
1.777 tempelho 6333: }
1.795 www 6334:
1.1075.2.108 raeburn 6335: .LC_breadcrumbs_hoverable {
6336: background: $sidebg;
6337: }
6338:
1.383 albertel 6339: td.LC_table_cell_checkbox {
6340: text-align: center;
6341: }
1.795 www 6342:
6343: .LC_fontsize_small {
1.911 bisitz 6344: font-size: 70%;
1.705 tempelho 6345: }
6346:
1.844 bisitz 6347: #LC_breadcrumbs {
1.911 bisitz 6348: clear:both;
6349: background: $sidebg;
6350: border-bottom: 1px solid $lg_border_color;
6351: line-height: 2.5em;
1.933 droeschl 6352: overflow: hidden;
1.911 bisitz 6353: margin: 0;
6354: padding: 0;
1.995 raeburn 6355: text-align: left;
1.819 tempelho 6356: }
1.862 bisitz 6357:
1.1075.2.16 raeburn 6358: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6359: clear:both;
6360: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6361: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6362: margin: 0 0 10px 0;
1.966 bisitz 6363: padding: 3px;
1.995 raeburn 6364: text-align: left;
1.822 bisitz 6365: }
6366:
1.795 www 6367: .LC_fontsize_medium {
1.911 bisitz 6368: font-size: 85%;
1.705 tempelho 6369: }
6370:
1.795 www 6371: .LC_fontsize_large {
1.911 bisitz 6372: font-size: 120%;
1.705 tempelho 6373: }
6374:
1.346 albertel 6375: .LC_menubuttons_inline_text {
6376: color: $font;
1.698 harmsja 6377: font-size: 90%;
1.701 harmsja 6378: padding-left:3px;
1.346 albertel 6379: }
6380:
1.934 droeschl 6381: .LC_menubuttons_inline_text img{
6382: vertical-align: middle;
6383: }
6384:
1.1051 www 6385: li.LC_menubuttons_inline_text img {
1.951 onken 6386: cursor:pointer;
1.1002 droeschl 6387: text-decoration: none;
1.951 onken 6388: }
6389:
1.526 www 6390: .LC_menubuttons_link {
6391: text-decoration: none;
6392: }
1.795 www 6393:
1.522 albertel 6394: .LC_menubuttons_category {
1.521 www 6395: color: $font;
1.526 www 6396: background: $pgbg;
1.521 www 6397: font-size: larger;
6398: font-weight: bold;
6399: }
6400:
1.346 albertel 6401: td.LC_menubuttons_text {
1.911 bisitz 6402: color: $font;
1.346 albertel 6403: }
1.706 harmsja 6404:
1.346 albertel 6405: .LC_current_location {
6406: background: $tabbg;
6407: }
1.795 www 6408:
1.1075.2.134 raeburn 6409: td.LC_zero_height {
6410: line-height: 0;
6411: cellpadding: 0;
6412: }
6413:
1.938 bisitz 6414: table.LC_data_table {
1.347 albertel 6415: border: 1px solid #000000;
1.402 albertel 6416: border-collapse: separate;
1.426 albertel 6417: border-spacing: 1px;
1.610 albertel 6418: background: $pgbg;
1.347 albertel 6419: }
1.795 www 6420:
1.422 albertel 6421: .LC_data_table_dense {
6422: font-size: small;
6423: }
1.795 www 6424:
1.507 raeburn 6425: table.LC_nested_outer {
6426: border: 1px solid #000000;
1.589 raeburn 6427: border-collapse: collapse;
1.803 bisitz 6428: border-spacing: 0;
1.507 raeburn 6429: width: 100%;
6430: }
1.795 www 6431:
1.879 raeburn 6432: table.LC_innerpickbox,
1.507 raeburn 6433: table.LC_nested {
1.803 bisitz 6434: border: none;
1.589 raeburn 6435: border-collapse: collapse;
1.803 bisitz 6436: border-spacing: 0;
1.507 raeburn 6437: width: 100%;
6438: }
1.795 www 6439:
1.911 bisitz 6440: table.LC_data_table tr th,
6441: table.LC_calendar tr th,
1.879 raeburn 6442: table.LC_prior_tries tr th,
6443: table.LC_innerpickbox tr th {
1.349 albertel 6444: font-weight: bold;
6445: background-color: $data_table_head;
1.801 tempelho 6446: color:$fontmenu;
1.701 harmsja 6447: font-size:90%;
1.347 albertel 6448: }
1.795 www 6449:
1.879 raeburn 6450: table.LC_innerpickbox tr th,
6451: table.LC_innerpickbox tr td {
6452: vertical-align: top;
6453: }
6454:
1.711 raeburn 6455: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6456: background-color: #CCCCCC;
1.711 raeburn 6457: font-weight: bold;
6458: text-align: left;
6459: }
1.795 www 6460:
1.912 bisitz 6461: table.LC_data_table tr.LC_odd_row > td {
6462: background-color: $data_table_light;
6463: padding: 2px;
6464: vertical-align: top;
6465: }
6466:
1.809 bisitz 6467: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6468: background-color: $data_table_light;
1.912 bisitz 6469: vertical-align: top;
6470: }
6471:
6472: table.LC_data_table tr.LC_even_row > td {
6473: background-color: $data_table_dark;
1.425 albertel 6474: padding: 2px;
1.900 bisitz 6475: vertical-align: top;
1.347 albertel 6476: }
1.795 www 6477:
1.809 bisitz 6478: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6479: background-color: $data_table_dark;
1.900 bisitz 6480: vertical-align: top;
1.347 albertel 6481: }
1.795 www 6482:
1.425 albertel 6483: table.LC_data_table tr.LC_data_table_highlight td {
6484: background-color: $data_table_darker;
6485: }
1.795 www 6486:
1.639 raeburn 6487: table.LC_data_table tr td.LC_leftcol_header {
6488: background-color: $data_table_head;
6489: font-weight: bold;
6490: }
1.795 www 6491:
1.451 albertel 6492: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6493: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6494: font-weight: bold;
6495: font-style: italic;
6496: text-align: center;
6497: padding: 8px;
1.347 albertel 6498: }
1.795 www 6499:
1.1075.2.30 raeburn 6500: table.LC_data_table tr.LC_empty_row td,
6501: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6502: background-color: $sidebg;
6503: }
6504:
6505: table.LC_nested tr.LC_empty_row td {
6506: background-color: #FFFFFF;
6507: }
6508:
1.890 droeschl 6509: table.LC_caption {
6510: }
6511:
1.507 raeburn 6512: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6513: padding: 4ex
6514: }
1.795 www 6515:
1.507 raeburn 6516: table.LC_nested_outer tr th {
6517: font-weight: bold;
1.801 tempelho 6518: color:$fontmenu;
1.507 raeburn 6519: background-color: $data_table_head;
1.701 harmsja 6520: font-size: small;
1.507 raeburn 6521: border-bottom: 1px solid #000000;
6522: }
1.795 www 6523:
1.507 raeburn 6524: table.LC_nested_outer tr td.LC_subheader {
6525: background-color: $data_table_head;
6526: font-weight: bold;
6527: font-size: small;
6528: border-bottom: 1px solid #000000;
6529: text-align: right;
1.451 albertel 6530: }
1.795 www 6531:
1.507 raeburn 6532: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6533: background-color: #CCCCCC;
1.451 albertel 6534: font-weight: bold;
6535: font-size: small;
1.507 raeburn 6536: text-align: center;
6537: }
1.795 www 6538:
1.589 raeburn 6539: table.LC_nested tr.LC_info_row td.LC_left_item,
6540: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6541: text-align: left;
1.451 albertel 6542: }
1.795 www 6543:
1.507 raeburn 6544: table.LC_nested td {
1.735 bisitz 6545: background-color: #FFFFFF;
1.451 albertel 6546: font-size: small;
1.507 raeburn 6547: }
1.795 www 6548:
1.507 raeburn 6549: table.LC_nested_outer tr th.LC_right_item,
6550: table.LC_nested tr.LC_info_row td.LC_right_item,
6551: table.LC_nested tr.LC_odd_row td.LC_right_item,
6552: table.LC_nested tr td.LC_right_item {
1.451 albertel 6553: text-align: right;
6554: }
6555:
1.507 raeburn 6556: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6557: background-color: #EEEEEE;
1.451 albertel 6558: }
6559:
1.473 raeburn 6560: table.LC_createuser {
6561: }
6562:
6563: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6564: font-size: small;
1.473 raeburn 6565: }
6566:
6567: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6568: background-color: #CCCCCC;
1.473 raeburn 6569: font-weight: bold;
6570: text-align: center;
6571: }
6572:
1.349 albertel 6573: table.LC_calendar {
6574: border: 1px solid #000000;
6575: border-collapse: collapse;
1.917 raeburn 6576: width: 98%;
1.349 albertel 6577: }
1.795 www 6578:
1.349 albertel 6579: table.LC_calendar_pickdate {
6580: font-size: xx-small;
6581: }
1.795 www 6582:
1.349 albertel 6583: table.LC_calendar tr td {
6584: border: 1px solid #000000;
6585: vertical-align: top;
1.917 raeburn 6586: width: 14%;
1.349 albertel 6587: }
1.795 www 6588:
1.349 albertel 6589: table.LC_calendar tr td.LC_calendar_day_empty {
6590: background-color: $data_table_dark;
6591: }
1.795 www 6592:
1.779 bisitz 6593: table.LC_calendar tr td.LC_calendar_day_current {
6594: background-color: $data_table_highlight;
1.777 tempelho 6595: }
1.795 www 6596:
1.938 bisitz 6597: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6598: background-color: $mail_new;
6599: }
1.795 www 6600:
1.938 bisitz 6601: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6602: background-color: $mail_new_hover;
6603: }
1.795 www 6604:
1.938 bisitz 6605: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6606: background-color: $mail_read;
6607: }
1.795 www 6608:
1.938 bisitz 6609: /*
6610: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6611: background-color: $mail_read_hover;
6612: }
1.938 bisitz 6613: */
1.795 www 6614:
1.938 bisitz 6615: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6616: background-color: $mail_replied;
6617: }
1.795 www 6618:
1.938 bisitz 6619: /*
6620: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6621: background-color: $mail_replied_hover;
6622: }
1.938 bisitz 6623: */
1.795 www 6624:
1.938 bisitz 6625: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6626: background-color: $mail_other;
6627: }
1.795 www 6628:
1.938 bisitz 6629: /*
6630: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6631: background-color: $mail_other_hover;
6632: }
1.938 bisitz 6633: */
1.494 raeburn 6634:
1.777 tempelho 6635: table.LC_data_table tr > td.LC_browser_file,
6636: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6637: background: #AAEE77;
1.389 albertel 6638: }
1.795 www 6639:
1.777 tempelho 6640: table.LC_data_table tr > td.LC_browser_file_locked,
6641: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6642: background: #FFAA99;
1.387 albertel 6643: }
1.795 www 6644:
1.777 tempelho 6645: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6646: background: #888888;
1.779 bisitz 6647: }
1.795 www 6648:
1.777 tempelho 6649: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6650: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6651: background: #F8F866;
1.777 tempelho 6652: }
1.795 www 6653:
1.696 bisitz 6654: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6655: background: #E0E8FF;
1.387 albertel 6656: }
1.696 bisitz 6657:
1.707 bisitz 6658: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6659: /* background: #77FF77; */
1.707 bisitz 6660: }
1.795 www 6661:
1.707 bisitz 6662: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6663: border-right: 8px solid #FFFF77;
1.707 bisitz 6664: }
1.795 www 6665:
1.707 bisitz 6666: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6667: border-right: 8px solid #FFAA77;
1.707 bisitz 6668: }
1.795 www 6669:
1.707 bisitz 6670: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6671: border-right: 8px solid #FF7777;
1.707 bisitz 6672: }
1.795 www 6673:
1.707 bisitz 6674: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6675: border-right: 8px solid #AAFF77;
1.707 bisitz 6676: }
1.795 www 6677:
1.707 bisitz 6678: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6679: border-right: 8px solid #11CC55;
1.707 bisitz 6680: }
6681:
1.388 albertel 6682: span.LC_current_location {
1.701 harmsja 6683: font-size:larger;
1.388 albertel 6684: background: $pgbg;
6685: }
1.387 albertel 6686:
1.1029 www 6687: span.LC_current_nav_location {
6688: font-weight:bold;
6689: background: $sidebg;
6690: }
6691:
1.395 albertel 6692: span.LC_parm_menu_item {
6693: font-size: larger;
6694: }
1.795 www 6695:
1.395 albertel 6696: span.LC_parm_scope_all {
6697: color: red;
6698: }
1.795 www 6699:
1.395 albertel 6700: span.LC_parm_scope_folder {
6701: color: green;
6702: }
1.795 www 6703:
1.395 albertel 6704: span.LC_parm_scope_resource {
6705: color: orange;
6706: }
1.795 www 6707:
1.395 albertel 6708: span.LC_parm_part {
6709: color: blue;
6710: }
1.795 www 6711:
1.911 bisitz 6712: span.LC_parm_folder,
6713: span.LC_parm_symb {
1.395 albertel 6714: font-size: x-small;
6715: font-family: $mono;
6716: color: #AAAAAA;
6717: }
6718:
1.977 bisitz 6719: ul.LC_parm_parmlist li {
6720: display: inline-block;
6721: padding: 0.3em 0.8em;
6722: vertical-align: top;
6723: width: 150px;
6724: border-top:1px solid $lg_border_color;
6725: }
6726:
1.795 www 6727: td.LC_parm_overview_level_menu,
6728: td.LC_parm_overview_map_menu,
6729: td.LC_parm_overview_parm_selectors,
6730: td.LC_parm_overview_restrictions {
1.396 albertel 6731: border: 1px solid black;
6732: border-collapse: collapse;
6733: }
1.795 www 6734:
1.396 albertel 6735: table.LC_parm_overview_restrictions td {
6736: border-width: 1px 4px 1px 4px;
6737: border-style: solid;
6738: border-color: $pgbg;
6739: text-align: center;
6740: }
1.795 www 6741:
1.396 albertel 6742: table.LC_parm_overview_restrictions th {
6743: background: $tabbg;
6744: border-width: 1px 4px 1px 4px;
6745: border-style: solid;
6746: border-color: $pgbg;
6747: }
1.795 www 6748:
1.398 albertel 6749: table#LC_helpmenu {
1.803 bisitz 6750: border: none;
1.398 albertel 6751: height: 55px;
1.803 bisitz 6752: border-spacing: 0;
1.398 albertel 6753: }
6754:
6755: table#LC_helpmenu fieldset legend {
6756: font-size: larger;
6757: }
1.795 www 6758:
1.397 albertel 6759: table#LC_helpmenu_links {
6760: width: 100%;
6761: border: 1px solid black;
6762: background: $pgbg;
1.803 bisitz 6763: padding: 0;
1.397 albertel 6764: border-spacing: 1px;
6765: }
1.795 www 6766:
1.397 albertel 6767: table#LC_helpmenu_links tr td {
6768: padding: 1px;
6769: background: $tabbg;
1.399 albertel 6770: text-align: center;
6771: font-weight: bold;
1.397 albertel 6772: }
1.396 albertel 6773:
1.795 www 6774: table#LC_helpmenu_links a:link,
6775: table#LC_helpmenu_links a:visited,
1.397 albertel 6776: table#LC_helpmenu_links a:active {
6777: text-decoration: none;
6778: color: $font;
6779: }
1.795 www 6780:
1.397 albertel 6781: table#LC_helpmenu_links a:hover {
6782: text-decoration: underline;
6783: color: $vlink;
6784: }
1.396 albertel 6785:
1.417 albertel 6786: .LC_chrt_popup_exists {
6787: border: 1px solid #339933;
6788: margin: -1px;
6789: }
1.795 www 6790:
1.417 albertel 6791: .LC_chrt_popup_up {
6792: border: 1px solid yellow;
6793: margin: -1px;
6794: }
1.795 www 6795:
1.417 albertel 6796: .LC_chrt_popup {
6797: border: 1px solid #8888FF;
6798: background: #CCCCFF;
6799: }
1.795 www 6800:
1.421 albertel 6801: table.LC_pick_box {
6802: border-collapse: separate;
6803: background: white;
6804: border: 1px solid black;
6805: border-spacing: 1px;
6806: }
1.795 www 6807:
1.421 albertel 6808: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6809: background: $sidebg;
1.421 albertel 6810: font-weight: bold;
1.900 bisitz 6811: text-align: left;
1.740 bisitz 6812: vertical-align: top;
1.421 albertel 6813: width: 184px;
6814: padding: 8px;
6815: }
1.795 www 6816:
1.579 raeburn 6817: table.LC_pick_box td.LC_pick_box_value {
6818: text-align: left;
6819: padding: 8px;
6820: }
1.795 www 6821:
1.579 raeburn 6822: table.LC_pick_box td.LC_pick_box_select {
6823: text-align: left;
6824: padding: 8px;
6825: }
1.795 www 6826:
1.424 albertel 6827: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6828: padding: 0;
1.421 albertel 6829: height: 1px;
6830: background: black;
6831: }
1.795 www 6832:
1.421 albertel 6833: table.LC_pick_box td.LC_pick_box_submit {
6834: text-align: right;
6835: }
1.795 www 6836:
1.579 raeburn 6837: table.LC_pick_box td.LC_evenrow_value {
6838: text-align: left;
6839: padding: 8px;
6840: background-color: $data_table_light;
6841: }
1.795 www 6842:
1.579 raeburn 6843: table.LC_pick_box td.LC_oddrow_value {
6844: text-align: left;
6845: padding: 8px;
6846: background-color: $data_table_light;
6847: }
1.795 www 6848:
1.579 raeburn 6849: span.LC_helpform_receipt_cat {
6850: font-weight: bold;
6851: }
1.795 www 6852:
1.424 albertel 6853: table.LC_group_priv_box {
6854: background: white;
6855: border: 1px solid black;
6856: border-spacing: 1px;
6857: }
1.795 www 6858:
1.424 albertel 6859: table.LC_group_priv_box td.LC_pick_box_title {
6860: background: $tabbg;
6861: font-weight: bold;
6862: text-align: right;
6863: width: 184px;
6864: }
1.795 www 6865:
1.424 albertel 6866: table.LC_group_priv_box td.LC_groups_fixed {
6867: background: $data_table_light;
6868: text-align: center;
6869: }
1.795 www 6870:
1.424 albertel 6871: table.LC_group_priv_box td.LC_groups_optional {
6872: background: $data_table_dark;
6873: text-align: center;
6874: }
1.795 www 6875:
1.424 albertel 6876: table.LC_group_priv_box td.LC_groups_functionality {
6877: background: $data_table_darker;
6878: text-align: center;
6879: font-weight: bold;
6880: }
1.795 www 6881:
1.424 albertel 6882: table.LC_group_priv td {
6883: text-align: left;
1.803 bisitz 6884: padding: 0;
1.424 albertel 6885: }
6886:
6887: .LC_navbuttons {
6888: margin: 2ex 0ex 2ex 0ex;
6889: }
1.795 www 6890:
1.423 albertel 6891: .LC_topic_bar {
6892: font-weight: bold;
6893: background: $tabbg;
1.918 wenzelju 6894: margin: 1em 0em 1em 2em;
1.805 bisitz 6895: padding: 3px;
1.918 wenzelju 6896: font-size: 1.2em;
1.423 albertel 6897: }
1.795 www 6898:
1.423 albertel 6899: .LC_topic_bar span {
1.918 wenzelju 6900: left: 0.5em;
6901: position: absolute;
1.423 albertel 6902: vertical-align: middle;
1.918 wenzelju 6903: font-size: 1.2em;
1.423 albertel 6904: }
1.795 www 6905:
1.423 albertel 6906: table.LC_course_group_status {
6907: margin: 20px;
6908: }
1.795 www 6909:
1.423 albertel 6910: table.LC_status_selector td {
6911: vertical-align: top;
6912: text-align: center;
1.424 albertel 6913: padding: 4px;
6914: }
1.795 www 6915:
1.599 albertel 6916: div.LC_feedback_link {
1.616 albertel 6917: clear: both;
1.829 kalberla 6918: background: $sidebg;
1.779 bisitz 6919: width: 100%;
1.829 kalberla 6920: padding-bottom: 10px;
6921: border: 1px $tabbg solid;
1.833 kalberla 6922: height: 22px;
6923: line-height: 22px;
6924: padding-top: 5px;
6925: }
6926:
6927: div.LC_feedback_link img {
6928: height: 22px;
1.867 kalberla 6929: vertical-align:middle;
1.829 kalberla 6930: }
6931:
1.911 bisitz 6932: div.LC_feedback_link a {
1.829 kalberla 6933: text-decoration: none;
1.489 raeburn 6934: }
1.795 www 6935:
1.867 kalberla 6936: div.LC_comblock {
1.911 bisitz 6937: display:inline;
1.867 kalberla 6938: color:$font;
6939: font-size:90%;
6940: }
6941:
6942: div.LC_feedback_link div.LC_comblock {
6943: padding-left:5px;
6944: }
6945:
6946: div.LC_feedback_link div.LC_comblock a {
6947: color:$font;
6948: }
6949:
1.489 raeburn 6950: span.LC_feedback_link {
1.858 bisitz 6951: /* background: $feedback_link_bg; */
1.599 albertel 6952: font-size: larger;
6953: }
1.795 www 6954:
1.599 albertel 6955: span.LC_message_link {
1.858 bisitz 6956: /* background: $feedback_link_bg; */
1.599 albertel 6957: font-size: larger;
6958: position: absolute;
6959: right: 1em;
1.489 raeburn 6960: }
1.421 albertel 6961:
1.515 albertel 6962: table.LC_prior_tries {
1.524 albertel 6963: border: 1px solid #000000;
6964: border-collapse: separate;
6965: border-spacing: 1px;
1.515 albertel 6966: }
1.523 albertel 6967:
1.515 albertel 6968: table.LC_prior_tries td {
1.524 albertel 6969: padding: 2px;
1.515 albertel 6970: }
1.523 albertel 6971:
6972: .LC_answer_correct {
1.795 www 6973: background: lightgreen;
6974: color: darkgreen;
6975: padding: 6px;
1.523 albertel 6976: }
1.795 www 6977:
1.523 albertel 6978: .LC_answer_charged_try {
1.797 www 6979: background: #FFAAAA;
1.795 www 6980: color: darkred;
6981: padding: 6px;
1.523 albertel 6982: }
1.795 www 6983:
1.779 bisitz 6984: .LC_answer_not_charged_try,
1.523 albertel 6985: .LC_answer_no_grade,
6986: .LC_answer_late {
1.795 www 6987: background: lightyellow;
1.523 albertel 6988: color: black;
1.795 www 6989: padding: 6px;
1.523 albertel 6990: }
1.795 www 6991:
1.523 albertel 6992: .LC_answer_previous {
1.795 www 6993: background: lightblue;
6994: color: darkblue;
6995: padding: 6px;
1.523 albertel 6996: }
1.795 www 6997:
1.779 bisitz 6998: .LC_answer_no_message {
1.777 tempelho 6999: background: #FFFFFF;
7000: color: black;
1.795 www 7001: padding: 6px;
1.779 bisitz 7002: }
1.795 www 7003:
1.1075.2.140 raeburn 7004: .LC_answer_unknown,
7005: .LC_answer_warning {
1.779 bisitz 7006: background: orange;
7007: color: black;
1.795 www 7008: padding: 6px;
1.777 tempelho 7009: }
1.795 www 7010:
1.529 albertel 7011: span.LC_prior_numerical,
7012: span.LC_prior_string,
7013: span.LC_prior_custom,
7014: span.LC_prior_reaction,
7015: span.LC_prior_math {
1.925 bisitz 7016: font-family: $mono;
1.523 albertel 7017: white-space: pre;
7018: }
7019:
1.525 albertel 7020: span.LC_prior_string {
1.925 bisitz 7021: font-family: $mono;
1.525 albertel 7022: white-space: pre;
7023: }
7024:
1.523 albertel 7025: table.LC_prior_option {
7026: width: 100%;
7027: border-collapse: collapse;
7028: }
1.795 www 7029:
1.911 bisitz 7030: table.LC_prior_rank,
1.795 www 7031: table.LC_prior_match {
1.528 albertel 7032: border-collapse: collapse;
7033: }
1.795 www 7034:
1.528 albertel 7035: table.LC_prior_option tr td,
7036: table.LC_prior_rank tr td,
7037: table.LC_prior_match tr td {
1.524 albertel 7038: border: 1px solid #000000;
1.515 albertel 7039: }
7040:
1.855 bisitz 7041: .LC_nobreak {
1.544 albertel 7042: white-space: nowrap;
1.519 raeburn 7043: }
7044:
1.576 raeburn 7045: span.LC_cusr_emph {
7046: font-style: italic;
7047: }
7048:
1.633 raeburn 7049: span.LC_cusr_subheading {
7050: font-weight: normal;
7051: font-size: 85%;
7052: }
7053:
1.861 bisitz 7054: div.LC_docs_entry_move {
1.859 bisitz 7055: border: 1px solid #BBBBBB;
1.545 albertel 7056: background: #DDDDDD;
1.861 bisitz 7057: width: 22px;
1.859 bisitz 7058: padding: 1px;
7059: margin: 0;
1.545 albertel 7060: }
7061:
1.861 bisitz 7062: table.LC_data_table tr > td.LC_docs_entry_commands,
7063: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7064: font-size: x-small;
7065: }
1.795 www 7066:
1.861 bisitz 7067: .LC_docs_entry_parameter {
7068: white-space: nowrap;
7069: }
7070:
1.544 albertel 7071: .LC_docs_copy {
1.545 albertel 7072: color: #000099;
1.544 albertel 7073: }
1.795 www 7074:
1.544 albertel 7075: .LC_docs_cut {
1.545 albertel 7076: color: #550044;
1.544 albertel 7077: }
1.795 www 7078:
1.544 albertel 7079: .LC_docs_rename {
1.545 albertel 7080: color: #009900;
1.544 albertel 7081: }
1.795 www 7082:
1.544 albertel 7083: .LC_docs_remove {
1.545 albertel 7084: color: #990000;
7085: }
7086:
1.1075.2.134 raeburn 7087: .LC_domprefs_email,
1.547 albertel 7088: .LC_docs_reinit_warn,
7089: .LC_docs_ext_edit {
7090: font-size: x-small;
7091: }
7092:
1.545 albertel 7093: table.LC_docs_adddocs td,
7094: table.LC_docs_adddocs th {
7095: border: 1px solid #BBBBBB;
7096: padding: 4px;
7097: background: #DDDDDD;
1.543 albertel 7098: }
7099:
1.584 albertel 7100: table.LC_sty_begin {
7101: background: #BBFFBB;
7102: }
1.795 www 7103:
1.584 albertel 7104: table.LC_sty_end {
7105: background: #FFBBBB;
7106: }
7107:
1.589 raeburn 7108: table.LC_double_column {
1.803 bisitz 7109: border-width: 0;
1.589 raeburn 7110: border-collapse: collapse;
7111: width: 100%;
7112: padding: 2px;
7113: }
7114:
7115: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7116: top: 2px;
1.589 raeburn 7117: left: 2px;
7118: width: 47%;
7119: vertical-align: top;
7120: }
7121:
7122: table.LC_double_column tr td.LC_right_col {
7123: top: 2px;
1.779 bisitz 7124: right: 2px;
1.589 raeburn 7125: width: 47%;
7126: vertical-align: top;
7127: }
7128:
1.591 raeburn 7129: div.LC_left_float {
7130: float: left;
7131: padding-right: 5%;
1.597 albertel 7132: padding-bottom: 4px;
1.591 raeburn 7133: }
7134:
7135: div.LC_clear_float_header {
1.597 albertel 7136: padding-bottom: 2px;
1.591 raeburn 7137: }
7138:
7139: div.LC_clear_float_footer {
1.597 albertel 7140: padding-top: 10px;
1.591 raeburn 7141: clear: both;
7142: }
7143:
1.597 albertel 7144: div.LC_grade_show_user {
1.941 bisitz 7145: /* border-left: 5px solid $sidebg; */
7146: border-top: 5px solid #000000;
7147: margin: 50px 0 0 0;
1.936 bisitz 7148: padding: 15px 0 5px 10px;
1.597 albertel 7149: }
1.795 www 7150:
1.936 bisitz 7151: div.LC_grade_show_user_odd_row {
1.941 bisitz 7152: /* border-left: 5px solid #000000; */
7153: }
7154:
7155: div.LC_grade_show_user div.LC_Box {
7156: margin-right: 50px;
1.597 albertel 7157: }
7158:
7159: div.LC_grade_submissions,
7160: div.LC_grade_message_center,
1.936 bisitz 7161: div.LC_grade_info_links {
1.597 albertel 7162: margin: 5px;
7163: width: 99%;
7164: background: #FFFFFF;
7165: }
1.795 www 7166:
1.597 albertel 7167: div.LC_grade_submissions_header,
1.936 bisitz 7168: div.LC_grade_message_center_header {
1.705 tempelho 7169: font-weight: bold;
7170: font-size: large;
1.597 albertel 7171: }
1.795 www 7172:
1.597 albertel 7173: div.LC_grade_submissions_body,
1.936 bisitz 7174: div.LC_grade_message_center_body {
1.597 albertel 7175: border: 1px solid black;
7176: width: 99%;
7177: background: #FFFFFF;
7178: }
1.795 www 7179:
1.613 albertel 7180: table.LC_scantron_action {
7181: width: 100%;
7182: }
1.795 www 7183:
1.613 albertel 7184: table.LC_scantron_action tr th {
1.698 harmsja 7185: font-weight:bold;
7186: font-style:normal;
1.613 albertel 7187: }
1.795 www 7188:
1.779 bisitz 7189: .LC_edit_problem_header,
1.614 albertel 7190: div.LC_edit_problem_footer {
1.705 tempelho 7191: font-weight: normal;
7192: font-size: medium;
1.602 albertel 7193: margin: 2px;
1.1060 bisitz 7194: background-color: $sidebg;
1.600 albertel 7195: }
1.795 www 7196:
1.600 albertel 7197: div.LC_edit_problem_header,
1.602 albertel 7198: div.LC_edit_problem_header div,
1.614 albertel 7199: div.LC_edit_problem_footer,
7200: div.LC_edit_problem_footer div,
1.602 albertel 7201: div.LC_edit_problem_editxml_header,
7202: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7203: z-index: 100;
1.600 albertel 7204: }
1.795 www 7205:
1.600 albertel 7206: div.LC_edit_problem_header_title {
1.705 tempelho 7207: font-weight: bold;
7208: font-size: larger;
1.602 albertel 7209: background: $tabbg;
7210: padding: 3px;
1.1060 bisitz 7211: margin: 0 0 5px 0;
1.602 albertel 7212: }
1.795 www 7213:
1.602 albertel 7214: table.LC_edit_problem_header_title {
7215: width: 100%;
1.600 albertel 7216: background: $tabbg;
1.602 albertel 7217: }
7218:
1.1075.2.112 raeburn 7219: div.LC_edit_actionbar {
7220: background-color: $sidebg;
7221: margin: 0;
7222: padding: 0;
7223: line-height: 200%;
1.602 albertel 7224: }
1.795 www 7225:
1.1075.2.112 raeburn 7226: div.LC_edit_actionbar div{
7227: padding: 0;
7228: margin: 0;
7229: display: inline-block;
1.600 albertel 7230: }
1.795 www 7231:
1.1075.2.34 raeburn 7232: .LC_edit_opt {
7233: padding-left: 1em;
7234: white-space: nowrap;
7235: }
7236:
1.1075.2.57 raeburn 7237: .LC_edit_problem_latexhelper{
7238: text-align: right;
7239: }
7240:
7241: #LC_edit_problem_colorful div{
7242: margin-left: 40px;
7243: }
7244:
1.1075.2.112 raeburn 7245: #LC_edit_problem_codemirror div{
7246: margin-left: 0px;
7247: }
7248:
1.911 bisitz 7249: img.stift {
1.803 bisitz 7250: border-width: 0;
7251: vertical-align: middle;
1.677 riegler 7252: }
1.680 riegler 7253:
1.923 bisitz 7254: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7255: vertical-align: top;
1.777 tempelho 7256: }
1.795 www 7257:
1.716 raeburn 7258: div.LC_createcourse {
1.911 bisitz 7259: margin: 10px 10px 10px 10px;
1.716 raeburn 7260: }
7261:
1.917 raeburn 7262: .LC_dccid {
1.1075.2.38 raeburn 7263: float: right;
1.917 raeburn 7264: margin: 0.2em 0 0 0;
7265: padding: 0;
7266: font-size: 90%;
7267: display:none;
7268: }
7269:
1.897 wenzelju 7270: ol.LC_primary_menu a:hover,
1.721 harmsja 7271: ol#LC_MenuBreadcrumbs a:hover,
7272: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7273: ul#LC_secondary_menu a:hover,
1.721 harmsja 7274: .LC_FormSectionClearButton input:hover
1.795 www 7275: ul.LC_TabContent li:hover a {
1.952 onken 7276: color:$button_hover;
1.911 bisitz 7277: text-decoration:none;
1.693 droeschl 7278: }
7279:
1.779 bisitz 7280: h1 {
1.911 bisitz 7281: padding: 0;
7282: line-height:130%;
1.693 droeschl 7283: }
1.698 harmsja 7284:
1.911 bisitz 7285: h2,
7286: h3,
7287: h4,
7288: h5,
7289: h6 {
7290: margin: 5px 0 5px 0;
7291: padding: 0;
7292: line-height:130%;
1.693 droeschl 7293: }
1.795 www 7294:
7295: .LC_hcell {
1.911 bisitz 7296: padding:3px 15px 3px 15px;
7297: margin: 0;
7298: background-color:$tabbg;
7299: color:$fontmenu;
7300: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7301: }
1.795 www 7302:
1.840 bisitz 7303: .LC_Box > .LC_hcell {
1.911 bisitz 7304: margin: 0 -10px 10px -10px;
1.835 bisitz 7305: }
7306:
1.721 harmsja 7307: .LC_noBorder {
1.911 bisitz 7308: border: 0;
1.698 harmsja 7309: }
1.693 droeschl 7310:
1.721 harmsja 7311: .LC_FormSectionClearButton input {
1.911 bisitz 7312: background-color:transparent;
7313: border: none;
7314: cursor:pointer;
7315: text-decoration:underline;
1.693 droeschl 7316: }
1.763 bisitz 7317:
7318: .LC_help_open_topic {
1.911 bisitz 7319: color: #FFFFFF;
7320: background-color: #EEEEFF;
7321: margin: 1px;
7322: padding: 4px;
7323: border: 1px solid #000033;
7324: white-space: nowrap;
7325: /* vertical-align: middle; */
1.759 neumanie 7326: }
1.693 droeschl 7327:
1.911 bisitz 7328: dl,
7329: ul,
7330: div,
7331: fieldset {
7332: margin: 10px 10px 10px 0;
7333: /* overflow: hidden; */
1.693 droeschl 7334: }
1.795 www 7335:
1.1075.2.90 raeburn 7336: article.geogebraweb div {
7337: margin: 0;
7338: }
7339:
1.838 bisitz 7340: fieldset > legend {
1.911 bisitz 7341: font-weight: bold;
7342: padding: 0 5px 0 5px;
1.838 bisitz 7343: }
7344:
1.813 bisitz 7345: #LC_nav_bar {
1.911 bisitz 7346: float: left;
1.995 raeburn 7347: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7348: margin: 0 0 2px 0;
1.807 droeschl 7349: }
7350:
1.916 droeschl 7351: #LC_realm {
7352: margin: 0.2em 0 0 0;
7353: padding: 0;
7354: font-weight: bold;
7355: text-align: center;
1.995 raeburn 7356: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7357: }
7358:
1.911 bisitz 7359: #LC_nav_bar em {
7360: font-weight: bold;
7361: font-style: normal;
1.807 droeschl 7362: }
7363:
1.897 wenzelju 7364: ol.LC_primary_menu {
1.934 droeschl 7365: margin: 0;
1.1075.2.2 raeburn 7366: padding: 0;
1.807 droeschl 7367: }
7368:
1.852 droeschl 7369: ol#LC_PathBreadcrumbs {
1.911 bisitz 7370: margin: 0;
1.693 droeschl 7371: }
7372:
1.897 wenzelju 7373: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7374: color: RGB(80, 80, 80);
7375: vertical-align: middle;
7376: text-align: left;
7377: list-style: none;
1.1075.2.112 raeburn 7378: position: relative;
1.1075.2.2 raeburn 7379: float: left;
1.1075.2.112 raeburn 7380: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7381: line-height: 1.5em;
1.1075.2.2 raeburn 7382: }
7383:
1.1075.2.113 raeburn 7384: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7385: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7386: display: block;
7387: margin: 0;
7388: padding: 0 5px 0 10px;
7389: text-decoration: none;
7390: }
7391:
1.1075.2.112 raeburn 7392: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7393: display: inline-block;
7394: width: 95%;
7395: text-align: left;
7396: }
7397:
7398: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7399: display: inline-block;
7400: width: 5%;
7401: float: right;
7402: text-align: right;
7403: font-size: 70%;
7404: }
7405:
7406: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7407: display: none;
1.1075.2.112 raeburn 7408: width: 15em;
1.1075.2.2 raeburn 7409: background-color: $data_table_light;
1.1075.2.112 raeburn 7410: position: absolute;
7411: top: 100%;
7412: }
7413:
7414: ol.LC_primary_menu ul ul {
7415: left: 100%;
7416: top: 0;
1.1075.2.2 raeburn 7417: }
7418:
1.1075.2.112 raeburn 7419: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7420: display: block;
7421: position: absolute;
7422: margin: 0;
7423: padding: 0;
1.1075.2.5 raeburn 7424: z-index: 2;
1.1075.2.2 raeburn 7425: }
7426:
7427: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7428: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7429: font-size: 90%;
1.911 bisitz 7430: vertical-align: top;
1.1075.2.2 raeburn 7431: float: none;
1.1075.2.5 raeburn 7432: border-left: 1px solid black;
7433: border-right: 1px solid black;
1.1075.2.112 raeburn 7434: /* A dark bottom border to visualize different menu options;
7435: overwritten in the create_submenu routine for the last border-bottom of the menu */
7436: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7437: }
7438:
1.1075.2.112 raeburn 7439: ol.LC_primary_menu li li p:hover {
7440: color:$button_hover;
7441: text-decoration:none;
7442: background-color:$data_table_dark;
1.1075.2.2 raeburn 7443: }
7444:
7445: ol.LC_primary_menu li li a:hover {
7446: color:$button_hover;
7447: background-color:$data_table_dark;
1.693 droeschl 7448: }
7449:
1.1075.2.112 raeburn 7450: /* Font-size equal to the size of the predecessors*/
7451: ol.LC_primary_menu li:hover li li {
7452: font-size: 100%;
7453: }
7454:
1.897 wenzelju 7455: ol.LC_primary_menu li img {
1.911 bisitz 7456: vertical-align: bottom;
1.934 droeschl 7457: height: 1.1em;
1.1075.2.3 raeburn 7458: margin: 0.2em 0 0 0;
1.693 droeschl 7459: }
7460:
1.897 wenzelju 7461: ol.LC_primary_menu a {
1.911 bisitz 7462: color: RGB(80, 80, 80);
7463: text-decoration: none;
1.693 droeschl 7464: }
1.795 www 7465:
1.949 droeschl 7466: ol.LC_primary_menu a.LC_new_message {
7467: font-weight:bold;
7468: color: darkred;
7469: }
7470:
1.975 raeburn 7471: ol.LC_docs_parameters {
7472: margin-left: 0;
7473: padding: 0;
7474: list-style: none;
7475: }
7476:
7477: ol.LC_docs_parameters li {
7478: margin: 0;
7479: padding-right: 20px;
7480: display: inline;
7481: }
7482:
1.976 raeburn 7483: ol.LC_docs_parameters li:before {
7484: content: "\\002022 \\0020";
7485: }
7486:
7487: li.LC_docs_parameters_title {
7488: font-weight: bold;
7489: }
7490:
7491: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7492: content: "";
7493: }
7494:
1.897 wenzelju 7495: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7496: clear: right;
1.911 bisitz 7497: color: $fontmenu;
7498: background: $tabbg;
7499: list-style: none;
7500: padding: 0;
7501: margin: 0;
7502: width: 100%;
1.995 raeburn 7503: text-align: left;
1.1075.2.4 raeburn 7504: float: left;
1.808 droeschl 7505: }
7506:
1.897 wenzelju 7507: ul#LC_secondary_menu li {
1.911 bisitz 7508: font-weight: bold;
7509: line-height: 1.8em;
7510: border-right: 1px solid black;
1.1075.2.4 raeburn 7511: float: left;
7512: }
7513:
7514: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7515: background-color: $data_table_light;
7516: }
7517:
7518: ul#LC_secondary_menu li a {
7519: padding: 0 0.8em;
7520: }
7521:
7522: ul#LC_secondary_menu li ul {
7523: display: none;
7524: }
7525:
7526: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7527: display: block;
7528: position: absolute;
7529: margin: 0;
7530: padding: 0;
7531: list-style:none;
7532: float: none;
7533: background-color: $data_table_light;
1.1075.2.5 raeburn 7534: z-index: 2;
1.1075.2.10 raeburn 7535: margin-left: -1px;
1.1075.2.4 raeburn 7536: }
7537:
7538: ul#LC_secondary_menu li ul li {
7539: font-size: 90%;
7540: vertical-align: top;
7541: border-left: 1px solid black;
7542: border-right: 1px solid black;
1.1075.2.33 raeburn 7543: background-color: $data_table_light;
1.1075.2.4 raeburn 7544: list-style:none;
7545: float: none;
7546: }
7547:
7548: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7549: background-color: $data_table_dark;
1.807 droeschl 7550: }
7551:
1.847 tempelho 7552: ul.LC_TabContent {
1.911 bisitz 7553: display:block;
7554: background: $sidebg;
7555: border-bottom: solid 1px $lg_border_color;
7556: list-style:none;
1.1020 raeburn 7557: margin: -1px -10px 0 -10px;
1.911 bisitz 7558: padding: 0;
1.693 droeschl 7559: }
7560:
1.795 www 7561: ul.LC_TabContent li,
7562: ul.LC_TabContentBigger li {
1.911 bisitz 7563: float:left;
1.741 harmsja 7564: }
1.795 www 7565:
1.897 wenzelju 7566: ul#LC_secondary_menu li a {
1.911 bisitz 7567: color: $fontmenu;
7568: text-decoration: none;
1.693 droeschl 7569: }
1.795 www 7570:
1.721 harmsja 7571: ul.LC_TabContent {
1.952 onken 7572: min-height:20px;
1.721 harmsja 7573: }
1.795 www 7574:
7575: ul.LC_TabContent li {
1.911 bisitz 7576: vertical-align:middle;
1.959 onken 7577: padding: 0 16px 0 10px;
1.911 bisitz 7578: background-color:$tabbg;
7579: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7580: border-left: solid 1px $font;
1.721 harmsja 7581: }
1.795 www 7582:
1.847 tempelho 7583: ul.LC_TabContent .right {
1.911 bisitz 7584: float:right;
1.847 tempelho 7585: }
7586:
1.911 bisitz 7587: ul.LC_TabContent li a,
7588: ul.LC_TabContent li {
7589: color:rgb(47,47,47);
7590: text-decoration:none;
7591: font-size:95%;
7592: font-weight:bold;
1.952 onken 7593: min-height:20px;
7594: }
7595:
1.959 onken 7596: ul.LC_TabContent li a:hover,
7597: ul.LC_TabContent li a:focus {
1.952 onken 7598: color: $button_hover;
1.959 onken 7599: background:none;
7600: outline:none;
1.952 onken 7601: }
7602:
7603: ul.LC_TabContent li:hover {
7604: color: $button_hover;
7605: cursor:pointer;
1.721 harmsja 7606: }
1.795 www 7607:
1.911 bisitz 7608: ul.LC_TabContent li.active {
1.952 onken 7609: color: $font;
1.911 bisitz 7610: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7611: border-bottom:solid 1px #FFFFFF;
7612: cursor: default;
1.744 ehlerst 7613: }
1.795 www 7614:
1.959 onken 7615: ul.LC_TabContent li.active a {
7616: color:$font;
7617: background:#FFFFFF;
7618: outline: none;
7619: }
1.1047 raeburn 7620:
7621: ul.LC_TabContent li.goback {
7622: float: left;
7623: border-left: none;
7624: }
7625:
1.870 tempelho 7626: #maincoursedoc {
1.911 bisitz 7627: clear:both;
1.870 tempelho 7628: }
7629:
7630: ul.LC_TabContentBigger {
1.911 bisitz 7631: display:block;
7632: list-style:none;
7633: padding: 0;
1.870 tempelho 7634: }
7635:
1.795 www 7636: ul.LC_TabContentBigger li {
1.911 bisitz 7637: vertical-align:bottom;
7638: height: 30px;
7639: font-size:110%;
7640: font-weight:bold;
7641: color: #737373;
1.841 tempelho 7642: }
7643:
1.957 onken 7644: ul.LC_TabContentBigger li.active {
7645: position: relative;
7646: top: 1px;
7647: }
7648:
1.870 tempelho 7649: ul.LC_TabContentBigger li a {
1.911 bisitz 7650: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7651: height: 30px;
7652: line-height: 30px;
7653: text-align: center;
7654: display: block;
7655: text-decoration: none;
1.958 onken 7656: outline: none;
1.741 harmsja 7657: }
1.795 www 7658:
1.870 tempelho 7659: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7660: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7661: color:$font;
1.744 ehlerst 7662: }
1.795 www 7663:
1.870 tempelho 7664: ul.LC_TabContentBigger li b {
1.911 bisitz 7665: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7666: display: block;
7667: float: left;
7668: padding: 0 30px;
1.957 onken 7669: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7670: }
7671:
1.956 onken 7672: ul.LC_TabContentBigger li:hover b {
7673: color:$button_hover;
7674: }
7675:
1.870 tempelho 7676: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7677: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7678: color:$font;
1.957 onken 7679: border: 0;
1.741 harmsja 7680: }
1.693 droeschl 7681:
1.870 tempelho 7682:
1.862 bisitz 7683: ul.LC_CourseBreadcrumbs {
7684: background: $sidebg;
1.1020 raeburn 7685: height: 2em;
1.862 bisitz 7686: padding-left: 10px;
1.1020 raeburn 7687: margin: 0;
1.862 bisitz 7688: list-style-position: inside;
7689: }
7690:
1.911 bisitz 7691: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7692: ol#LC_PathBreadcrumbs {
1.911 bisitz 7693: padding-left: 10px;
7694: margin: 0;
1.933 droeschl 7695: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7696: }
7697:
1.911 bisitz 7698: ol#LC_MenuBreadcrumbs li,
7699: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7700: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7701: display: inline;
1.933 droeschl 7702: white-space: normal;
1.693 droeschl 7703: }
7704:
1.823 bisitz 7705: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7706: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7707: text-decoration: none;
7708: font-size:90%;
1.693 droeschl 7709: }
1.795 www 7710:
1.969 droeschl 7711: ol#LC_MenuBreadcrumbs h1 {
7712: display: inline;
7713: font-size: 90%;
7714: line-height: 2.5em;
7715: margin: 0;
7716: padding: 0;
7717: }
7718:
1.795 www 7719: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7720: text-decoration:none;
7721: font-size:100%;
7722: font-weight:bold;
1.693 droeschl 7723: }
1.795 www 7724:
1.840 bisitz 7725: .LC_Box {
1.911 bisitz 7726: border: solid 1px $lg_border_color;
7727: padding: 0 10px 10px 10px;
1.746 neumanie 7728: }
1.795 www 7729:
1.1020 raeburn 7730: .LC_DocsBox {
7731: border: solid 1px $lg_border_color;
7732: padding: 0 0 10px 10px;
7733: }
7734:
1.795 www 7735: .LC_AboutMe_Image {
1.911 bisitz 7736: float:left;
7737: margin-right:10px;
1.747 neumanie 7738: }
1.795 www 7739:
7740: .LC_Clear_AboutMe_Image {
1.911 bisitz 7741: clear:left;
1.747 neumanie 7742: }
1.795 www 7743:
1.721 harmsja 7744: dl.LC_ListStyleClean dt {
1.911 bisitz 7745: padding-right: 5px;
7746: display: table-header-group;
1.693 droeschl 7747: }
7748:
1.721 harmsja 7749: dl.LC_ListStyleClean dd {
1.911 bisitz 7750: display: table-row;
1.693 droeschl 7751: }
7752:
1.721 harmsja 7753: .LC_ListStyleClean,
7754: .LC_ListStyleSimple,
7755: .LC_ListStyleNormal,
1.795 www 7756: .LC_ListStyleSpecial {
1.911 bisitz 7757: /* display:block; */
7758: list-style-position: inside;
7759: list-style-type: none;
7760: overflow: hidden;
7761: padding: 0;
1.693 droeschl 7762: }
7763:
1.721 harmsja 7764: .LC_ListStyleSimple li,
7765: .LC_ListStyleSimple dd,
7766: .LC_ListStyleNormal li,
7767: .LC_ListStyleNormal dd,
7768: .LC_ListStyleSpecial li,
1.795 www 7769: .LC_ListStyleSpecial dd {
1.911 bisitz 7770: margin: 0;
7771: padding: 5px 5px 5px 10px;
7772: clear: both;
1.693 droeschl 7773: }
7774:
1.721 harmsja 7775: .LC_ListStyleClean li,
7776: .LC_ListStyleClean dd {
1.911 bisitz 7777: padding-top: 0;
7778: padding-bottom: 0;
1.693 droeschl 7779: }
7780:
1.721 harmsja 7781: .LC_ListStyleSimple dd,
1.795 www 7782: .LC_ListStyleSimple li {
1.911 bisitz 7783: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7784: }
7785:
1.721 harmsja 7786: .LC_ListStyleSpecial li,
7787: .LC_ListStyleSpecial dd {
1.911 bisitz 7788: list-style-type: none;
7789: background-color: RGB(220, 220, 220);
7790: margin-bottom: 4px;
1.693 droeschl 7791: }
7792:
1.721 harmsja 7793: table.LC_SimpleTable {
1.911 bisitz 7794: margin:5px;
7795: border:solid 1px $lg_border_color;
1.795 www 7796: }
1.693 droeschl 7797:
1.721 harmsja 7798: table.LC_SimpleTable tr {
1.911 bisitz 7799: padding: 0;
7800: border:solid 1px $lg_border_color;
1.693 droeschl 7801: }
1.795 www 7802:
7803: table.LC_SimpleTable thead {
1.911 bisitz 7804: background:rgb(220,220,220);
1.693 droeschl 7805: }
7806:
1.721 harmsja 7807: div.LC_columnSection {
1.911 bisitz 7808: display: block;
7809: clear: both;
7810: overflow: hidden;
7811: margin: 0;
1.693 droeschl 7812: }
7813:
1.721 harmsja 7814: div.LC_columnSection>* {
1.911 bisitz 7815: float: left;
7816: margin: 10px 20px 10px 0;
7817: overflow:hidden;
1.693 droeschl 7818: }
1.721 harmsja 7819:
1.795 www 7820: table em {
1.911 bisitz 7821: font-weight: bold;
7822: font-style: normal;
1.748 schulted 7823: }
1.795 www 7824:
1.779 bisitz 7825: table.LC_tableBrowseRes,
1.795 www 7826: table.LC_tableOfContent {
1.911 bisitz 7827: border:none;
7828: border-spacing: 1px;
7829: padding: 3px;
7830: background-color: #FFFFFF;
7831: font-size: 90%;
1.753 droeschl 7832: }
1.789 droeschl 7833:
1.911 bisitz 7834: table.LC_tableOfContent {
7835: border-collapse: collapse;
1.789 droeschl 7836: }
7837:
1.771 droeschl 7838: table.LC_tableBrowseRes a,
1.768 schulted 7839: table.LC_tableOfContent a {
1.911 bisitz 7840: background-color: transparent;
7841: text-decoration: none;
1.753 droeschl 7842: }
7843:
1.795 www 7844: table.LC_tableOfContent img {
1.911 bisitz 7845: border: none;
7846: height: 1.3em;
7847: vertical-align: text-bottom;
7848: margin-right: 0.3em;
1.753 droeschl 7849: }
1.757 schulted 7850:
1.795 www 7851: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7852: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7853: }
7854:
1.795 www 7855: a#LC_content_toolbar_everything {
1.911 bisitz 7856: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7857: }
7858:
1.795 www 7859: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7860: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7861: }
7862:
1.795 www 7863: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7864: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7865: }
7866:
1.795 www 7867: a#LC_content_toolbar_changefolder {
1.911 bisitz 7868: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7869: }
7870:
1.795 www 7871: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7872: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7873: }
7874:
1.1043 raeburn 7875: a#LC_content_toolbar_edittoplevel {
7876: background-image:url(/res/adm/pages/edittoplevel.gif);
7877: }
7878:
1.795 www 7879: ul#LC_toolbar li a:hover {
1.911 bisitz 7880: background-position: bottom center;
1.757 schulted 7881: }
7882:
1.795 www 7883: ul#LC_toolbar {
1.911 bisitz 7884: padding: 0;
7885: margin: 2px;
7886: list-style:none;
7887: position:relative;
7888: background-color:white;
1.1075.2.9 raeburn 7889: overflow: auto;
1.757 schulted 7890: }
7891:
1.795 www 7892: ul#LC_toolbar li {
1.911 bisitz 7893: border:1px solid white;
7894: padding: 0;
7895: margin: 0;
7896: float: left;
7897: display:inline;
7898: vertical-align:middle;
1.1075.2.9 raeburn 7899: white-space: nowrap;
1.911 bisitz 7900: }
1.757 schulted 7901:
1.783 amueller 7902:
1.795 www 7903: a.LC_toolbarItem {
1.911 bisitz 7904: display:block;
7905: padding: 0;
7906: margin: 0;
7907: height: 32px;
7908: width: 32px;
7909: color:white;
7910: border: none;
7911: background-repeat:no-repeat;
7912: background-color:transparent;
1.757 schulted 7913: }
7914:
1.915 droeschl 7915: ul.LC_funclist {
7916: margin: 0;
7917: padding: 0.5em 1em 0.5em 0;
7918: }
7919:
1.933 droeschl 7920: ul.LC_funclist > li:first-child {
7921: font-weight:bold;
7922: margin-left:0.8em;
7923: }
7924:
1.915 droeschl 7925: ul.LC_funclist + ul.LC_funclist {
7926: /*
7927: left border as a seperator if we have more than
7928: one list
7929: */
7930: border-left: 1px solid $sidebg;
7931: /*
7932: this hides the left border behind the border of the
7933: outer box if element is wrapped to the next 'line'
7934: */
7935: margin-left: -1px;
7936: }
7937:
1.843 bisitz 7938: ul.LC_funclist li {
1.915 droeschl 7939: display: inline;
1.782 bisitz 7940: white-space: nowrap;
1.915 droeschl 7941: margin: 0 0 0 25px;
7942: line-height: 150%;
1.782 bisitz 7943: }
7944:
1.974 wenzelju 7945: .LC_hidden {
7946: display: none;
7947: }
7948:
1.1030 www 7949: .LCmodal-overlay {
7950: position:fixed;
7951: top:0;
7952: right:0;
7953: bottom:0;
7954: left:0;
7955: height:100%;
7956: width:100%;
7957: margin:0;
7958: padding:0;
7959: background:#999;
7960: opacity:.75;
7961: filter: alpha(opacity=75);
7962: -moz-opacity: 0.75;
7963: z-index:101;
7964: }
7965:
7966: * html .LCmodal-overlay {
7967: position: absolute;
7968: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7969: }
7970:
7971: .LCmodal-window {
7972: position:fixed;
7973: top:50%;
7974: left:50%;
7975: margin:0;
7976: padding:0;
7977: z-index:102;
7978: }
7979:
7980: * html .LCmodal-window {
7981: position:absolute;
7982: }
7983:
7984: .LCclose-window {
7985: position:absolute;
7986: width:32px;
7987: height:32px;
7988: right:8px;
7989: top:8px;
7990: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7991: text-indent:-99999px;
7992: overflow:hidden;
7993: cursor:pointer;
7994: }
7995:
1.1075.2.158 raeburn 7996: .LCisDisabled {
7997: cursor: not-allowed;
7998: opacity: 0.5;
7999: }
8000:
8001: a[aria-disabled="true"] {
8002: color: currentColor;
8003: display: inline-block; /* For IE11/ MS Edge bug */
8004: pointer-events: none;
8005: text-decoration: none;
8006: }
8007:
1.1075.2.141 raeburn 8008: pre.LC_wordwrap {
8009: white-space: pre-wrap;
8010: white-space: -moz-pre-wrap;
8011: white-space: -pre-wrap;
8012: white-space: -o-pre-wrap;
8013: word-wrap: break-word;
8014: }
8015:
1.1075.2.17 raeburn 8016: /*
8017: styles used by TTH when "Default set of options to pass to tth/m
8018: when converting TeX" in course settings has been set
8019:
8020: option passed: -t
8021:
8022: */
8023:
8024: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8025: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8026: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8027: td div.norm {line-height:normal;}
8028:
8029: /*
8030: option passed -y3
8031: */
8032:
8033: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8034: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8035: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8036:
1.1075.2.121 raeburn 8037: #LC_minitab_header {
8038: float:left;
8039: width:100%;
8040: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8041: font-size:93%;
8042: line-height:normal;
8043: margin: 0.5em 0 0.5em 0;
8044: }
8045: #LC_minitab_header ul {
8046: margin:0;
8047: padding:10px 10px 0;
8048: list-style:none;
8049: }
8050: #LC_minitab_header li {
8051: float:left;
8052: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8053: margin:0;
8054: padding:0 0 0 9px;
8055: }
8056: #LC_minitab_header a {
8057: display:block;
8058: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8059: padding:5px 15px 4px 6px;
8060: }
8061: #LC_minitab_header #LC_current_minitab {
8062: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8063: }
8064: #LC_minitab_header #LC_current_minitab a {
8065: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8066: padding-bottom:5px;
8067: }
8068:
8069:
1.343 albertel 8070: END
8071: }
8072:
1.306 albertel 8073: =pod
8074:
8075: =item * &headtag()
8076:
8077: Returns a uniform footer for LON-CAPA web pages.
8078:
1.307 albertel 8079: Inputs: $title - optional title for the head
8080: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8081: $args - optional arguments
1.319 albertel 8082: force_register - if is true call registerurl so the remote is
8083: informed
1.415 albertel 8084: redirect -> array ref of
8085: 1- seconds before redirect occurs
8086: 2- url to redirect to
8087: 3- whether the side effect should occur
1.315 albertel 8088: (side effect of setting
8089: $env{'internal.head.redirect'} to the url
8090: redirected too)
1.1075.2.166 raeburn 8091: 4- whether encrypt check should be skipped
1.352 albertel 8092: domain -> force to color decorate a page for a specific
8093: domain
8094: function -> force usage of a specific rolish color scheme
8095: bgcolor -> override the default page bgcolor
1.460 albertel 8096: no_auto_mt_title
8097: -> prevent &mt()ing the title arg
1.464 albertel 8098:
1.306 albertel 8099: =cut
8100:
8101: sub headtag {
1.313 albertel 8102: my ($title,$head_extra,$args) = @_;
1.306 albertel 8103:
1.363 albertel 8104: my $function = $args->{'function'} || &get_users_function();
8105: my $domain = $args->{'domain'} || &determinedomain();
8106: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 8107: my $httphost = $args->{'use_absolute'};
1.418 albertel 8108: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8109: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8110: #time(),
1.418 albertel 8111: $env{'environment.color.timestamp'},
1.363 albertel 8112: $function,$domain,$bgcolor);
8113:
1.369 www 8114: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8115:
1.308 albertel 8116: my $result =
8117: '<head>'.
1.1075.2.56 raeburn 8118: &font_settings($args);
1.319 albertel 8119:
1.1075.2.72 raeburn 8120: my $inhibitprint;
8121: if ($args->{'print_suppress'}) {
8122: $inhibitprint = &print_suppression();
8123: }
1.1064 raeburn 8124:
1.461 albertel 8125: if (!$args->{'frameset'}) {
8126: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8127: }
1.1075.2.12 raeburn 8128: if ($args->{'force_register'}) {
8129: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 8130: }
1.436 albertel 8131: if (!$args->{'no_nav_bar'}
8132: && !$args->{'only_body'}
8133: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 8134: $result .= &help_menu_js($httphost);
1.1032 www 8135: $result.=&modal_window();
1.1038 www 8136: $result.=&togglebox_script();
1.1034 www 8137: $result.=&wishlist_window();
1.1041 www 8138: $result.=&LCprogressbarUpdate_script();
1.1034 www 8139: } else {
8140: if ($args->{'add_modal'}) {
8141: $result.=&modal_window();
8142: }
8143: if ($args->{'add_wishlist'}) {
8144: $result.=&wishlist_window();
8145: }
1.1038 www 8146: if ($args->{'add_togglebox'}) {
8147: $result.=&togglebox_script();
8148: }
1.1041 www 8149: if ($args->{'add_progressbar'}) {
8150: $result.=&LCprogressbarUpdate_script();
8151: }
1.436 albertel 8152: }
1.314 albertel 8153: if (ref($args->{'redirect'})) {
1.1075.2.166 raeburn 8154: my ($time,$url,$inhibit_continue,$skip_enc_check) = @{$args->{'redirect'}};
8155: if (!$skip_enc_check) {
8156: $url = &Apache::lonenc::check_encrypt($url);
8157: }
1.414 albertel 8158: if (!$inhibit_continue) {
8159: $env{'internal.head.redirect'} = $url;
8160: }
1.313 albertel 8161: $result.=<<ADDMETA
8162: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8163: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8164: ADDMETA
1.1075.2.89 raeburn 8165: } else {
8166: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8167: my $requrl = $env{'request.uri'};
8168: if ($requrl eq '') {
8169: $requrl = $ENV{'REQUEST_URI'};
8170: $requrl =~ s/\?.+$//;
8171: }
8172: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8173: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8174: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8175: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8176: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8177: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 8178: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1075.2.151 raeburn 8179: my ($offload,$offloadoth);
1.1075.2.89 raeburn 8180: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8181: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 8182: $offload = 1;
1.1075.2.151 raeburn 8183: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8184: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8185: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8186: $offloadoth = 1;
8187: $dom_in_use = $env{'user.domain'};
8188: }
8189: }
1.1075.2.145 raeburn 8190: }
8191: }
8192: unless ($offload) {
8193: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8194: if ($domdefs{'offloadoth'}{$lonhost}) {
8195: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8196: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8197: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8198: $offload = 1;
1.1075.2.151 raeburn 8199: $offloadoth = 1;
1.1075.2.145 raeburn 8200: $dom_in_use = $env{'user.domain'};
8201: }
1.1075.2.89 raeburn 8202: }
1.1075.2.145 raeburn 8203: }
8204: }
8205: }
8206: if ($offload) {
1.1075.2.158 raeburn 8207: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1075.2.151 raeburn 8208: if (($newserver eq '') && ($offloadoth)) {
8209: my @domains = &Apache::lonnet::current_machine_domains();
8210: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
8211: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8212: }
8213: }
1.1075.2.145 raeburn 8214: if (($newserver) && ($newserver ne $lonhost)) {
8215: my $numsec = 5;
8216: my $timeout = $numsec * 1000;
8217: my ($newurl,$locknum,%locks,$msg);
8218: if ($env{'request.role.adv'}) {
8219: ($locknum,%locks) = &Apache::lonnet::get_locks();
8220: }
8221: my $disable_submit = 0;
8222: if ($requrl =~ /$LONCAPA::assess_re/) {
8223: $disable_submit = 1;
8224: }
8225: if ($locknum) {
8226: my @lockinfo = sort(values(%locks));
1.1075.2.153 raeburn 8227: $msg = &mt('Once the following tasks are complete:')." \n".
1.1075.2.145 raeburn 8228: join(", ",sort(values(%locks)))."\n";
8229: if (&show_course()) {
8230: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 8231: } else {
1.1075.2.145 raeburn 8232: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
8233: }
8234: } else {
8235: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8236: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8237: }
8238: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8239: $newurl = '/adm/switchserver?otherserver='.$newserver;
8240: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8241: $newurl .= '&role='.$env{'request.role'};
8242: }
8243: if ($env{'request.symb'}) {
8244: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8245: if ($shownsymb =~ m{^/enc/}) {
8246: my $reqdmajor = 2;
8247: my $reqdminor = 11;
8248: my $reqdsubminor = 3;
8249: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8250: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8251: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8252: if (($major eq '' && $minor eq '') ||
8253: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8254: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8255: ($reqdsubminor > $subminor))))) {
8256: undef($shownsymb);
8257: }
1.1075.2.89 raeburn 8258: }
1.1075.2.145 raeburn 8259: if ($shownsymb) {
8260: &js_escape(\$shownsymb);
8261: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 8262: }
1.1075.2.145 raeburn 8263: } else {
8264: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8265: &js_escape(\$shownurl);
8266: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 8267: }
1.1075.2.145 raeburn 8268: }
8269: &js_escape(\$msg);
8270: $result.=<<OFFLOAD
1.1075.2.89 raeburn 8271: <meta http-equiv="pragma" content="no-cache" />
8272: <script type="text/javascript">
1.1075.2.92 raeburn 8273: // <![CDATA[
1.1075.2.89 raeburn 8274: function LC_Offload_Now() {
8275: var dest = "$newurl";
8276: if (dest != '') {
8277: window.location.href="$newurl";
8278: }
8279: }
1.1075.2.92 raeburn 8280: \$(document).ready(function () {
8281: window.alert('$msg');
8282: if ($disable_submit) {
1.1075.2.89 raeburn 8283: \$(".LC_hwk_submit").prop("disabled", true);
8284: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 8285: }
8286: setTimeout('LC_Offload_Now()', $timeout);
8287: });
8288: // ]]>
1.1075.2.89 raeburn 8289: </script>
8290: OFFLOAD
8291: }
8292: }
8293: }
8294: }
8295: }
1.313 albertel 8296: }
1.306 albertel 8297: if (!defined($title)) {
8298: $title = 'The LearningOnline Network with CAPA';
8299: }
1.460 albertel 8300: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.168 raeburn 8301: if ($title =~ /^LON-CAPA\s+/) {
8302: $result .= '<title> '.$title.'</title>';
8303: } else {
8304: $result .= '<title> LON-CAPA '.$title.'</title>';
8305: }
8306: $result .= "\n".'<link rel="stylesheet" type="text/css" href="'.$url.'"';
1.1075.2.61 raeburn 8307: if (!$args->{'frameset'}) {
8308: $result .= ' /';
8309: }
8310: $result .= '>'
1.1064 raeburn 8311: .$inhibitprint
1.414 albertel 8312: .$head_extra;
1.1075.2.108 raeburn 8313: my $clientmobile;
8314: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8315: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8316: } else {
8317: $clientmobile = $env{'browser.mobile'};
8318: }
8319: if ($clientmobile) {
1.1075.2.42 raeburn 8320: $result .= '
8321: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8322: <meta name="apple-mobile-web-app-capable" content="yes" />';
8323: }
1.1075.2.126 raeburn 8324: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8325: return $result.'</head>';
1.306 albertel 8326: }
8327:
8328: =pod
8329:
1.340 albertel 8330: =item * &font_settings()
8331:
8332: Returns neccessary <meta> to set the proper encoding
8333:
1.1075.2.56 raeburn 8334: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8335:
8336: =cut
8337:
8338: sub font_settings {
1.1075.2.56 raeburn 8339: my ($args) = @_;
1.340 albertel 8340: my $headerstring='';
1.1075.2.56 raeburn 8341: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8342: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8343: $headerstring.=
1.1075.2.61 raeburn 8344: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8345: if (!$args->{'frameset'}) {
8346: $headerstring.= ' /';
8347: }
8348: $headerstring .= '>'."\n";
1.340 albertel 8349: }
8350: return $headerstring;
8351: }
8352:
1.341 albertel 8353: =pod
8354:
1.1064 raeburn 8355: =item * &print_suppression()
8356:
8357: In course context returns css which causes the body to be blank when media="print",
8358: if printout generation is unavailable for the current resource.
8359:
8360: This could be because:
8361:
8362: (a) printstartdate is in the future
8363:
8364: (b) printenddate is in the past
8365:
8366: (c) there is an active exam block with "printout"
8367: functionality blocked
8368:
8369: Users with pav, pfo or evb privileges are exempt.
8370:
8371: Inputs: none
8372:
8373: =cut
8374:
8375:
8376: sub print_suppression {
8377: my $noprint;
8378: if ($env{'request.course.id'}) {
8379: my $scope = $env{'request.course.id'};
8380: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8381: (&Apache::lonnet::allowed('pfo',$scope))) {
8382: return;
8383: }
8384: if ($env{'request.course.sec'} ne '') {
8385: $scope .= "/$env{'request.course.sec'}";
8386: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8387: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8388: return;
1.1064 raeburn 8389: }
8390: }
8391: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8392: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.158 raeburn 8393: my $clientip = &Apache::lonnet::get_requestor_ip();
8394: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 8395: if ($blocked) {
8396: my $checkrole = "cm./$cdom/$cnum";
8397: if ($env{'request.course.sec'} ne '') {
8398: $checkrole .= "/$env{'request.course.sec'}";
8399: }
8400: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8401: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8402: $noprint = 1;
8403: }
8404: }
8405: unless ($noprint) {
8406: my $symb = &Apache::lonnet::symbread();
8407: if ($symb ne '') {
8408: my $navmap = Apache::lonnavmaps::navmap->new();
8409: if (ref($navmap)) {
8410: my $res = $navmap->getBySymb($symb);
8411: if (ref($res)) {
8412: if (!$res->resprintable()) {
8413: $noprint = 1;
8414: }
8415: }
8416: }
8417: }
8418: }
8419: if ($noprint) {
8420: return <<"ENDSTYLE";
8421: <style type="text/css" media="print">
8422: body { display:none }
8423: </style>
8424: ENDSTYLE
8425: }
8426: }
8427: return;
8428: }
8429:
8430: =pod
8431:
1.341 albertel 8432: =item * &xml_begin()
8433:
8434: Returns the needed doctype and <html>
8435:
8436: Inputs: none
8437:
8438: =cut
8439:
8440: sub xml_begin {
1.1075.2.61 raeburn 8441: my ($is_frameset) = @_;
1.341 albertel 8442: my $output='';
8443:
8444: if ($env{'browser.mathml'}) {
8445: $output='<?xml version="1.0"?>'
8446: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8447: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8448:
8449: # .'<!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">] >'
8450: .'<!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">'
8451: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8452: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8453: } elsif ($is_frameset) {
8454: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8455: '<html>'."\n";
1.341 albertel 8456: } else {
1.1075.2.61 raeburn 8457: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8458: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8459: }
8460: return $output;
8461: }
1.340 albertel 8462:
8463: =pod
8464:
1.306 albertel 8465: =item * &start_page()
8466:
8467: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8468:
1.648 raeburn 8469: Inputs:
8470:
8471: =over 4
8472:
8473: $title - optional title for the page
8474:
8475: $head_extra - optional extra HTML to incude inside the <head>
8476:
8477: $args - additional optional args supported are:
8478:
8479: =over 8
8480:
8481: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8482: arg on
1.814 bisitz 8483: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8484: add_entries -> additional attributes to add to the <body>
8485: domain -> force to color decorate a page for a
1.317 albertel 8486: specific domain
1.648 raeburn 8487: function -> force usage of a specific rolish color
1.317 albertel 8488: scheme
1.648 raeburn 8489: redirect -> see &headtag()
8490: bgcolor -> override the default page bg color
8491: js_ready -> return a string ready for being used in
1.317 albertel 8492: a javascript writeln
1.648 raeburn 8493: html_encode -> return a string ready for being used in
1.320 albertel 8494: a html attribute
1.648 raeburn 8495: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8496: $forcereg arg
1.648 raeburn 8497: frameset -> if true will start with a <frameset>
1.330 albertel 8498: rather than <body>
1.648 raeburn 8499: skip_phases -> hash ref of
1.338 albertel 8500: head -> skip the <html><head> generation
8501: body -> skip all <body> generation
1.1075.2.12 raeburn 8502: no_inline_link -> if true and in remote mode, don't show the
8503: 'Switch To Inline Menu' link
1.648 raeburn 8504: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8505: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8506: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8507: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8508: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8509: group -> includes the current group, if page is for a
8510: specific group
1.1075.2.133 raeburn 8511: use_absolute -> for request for external resource or syllabus, this
8512: will contain https://<hostname> if server uses
8513: https (as per hosts.tab), but request is for http
8514: hostname -> hostname, originally from $r->hostname(), (optional).
1.1075.2.158 raeburn 8515: links_disabled -> Links in primary and secondary menus are disabled
8516: (Can enable them once page has loaded - see lonroles.pm
8517: for an example).
1.361 albertel 8518:
1.648 raeburn 8519: =back
1.460 albertel 8520:
1.648 raeburn 8521: =back
1.562 albertel 8522:
1.306 albertel 8523: =cut
8524:
8525: sub start_page {
1.309 albertel 8526: my ($title,$head_extra,$args) = @_;
1.318 albertel 8527: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8528:
1.315 albertel 8529: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8530: my ($result,@advtools);
1.964 droeschl 8531:
1.338 albertel 8532: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8533: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8534: }
8535:
8536: if (! exists($args->{'skip_phases'}{'body'}) ) {
8537: if ($args->{'frameset'}) {
8538: my $attr_string = &make_attr_string($args->{'force_register'},
8539: $args->{'add_entries'});
8540: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8541: } else {
8542: $result .=
8543: &bodytag($title,
8544: $args->{'function'}, $args->{'add_entries'},
8545: $args->{'only_body'}, $args->{'domain'},
8546: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8547: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8548: $args, \@advtools);
1.831 bisitz 8549: }
1.330 albertel 8550: }
1.338 albertel 8551:
1.315 albertel 8552: if ($args->{'js_ready'}) {
1.713 kaisler 8553: $result = &js_ready($result);
1.315 albertel 8554: }
1.320 albertel 8555: if ($args->{'html_encode'}) {
1.713 kaisler 8556: $result = &html_encode($result);
8557: }
8558:
1.813 bisitz 8559: # Preparation for new and consistent functionlist at top of screen
8560: # if ($args->{'functionlist'}) {
8561: # $result .= &build_functionlist();
8562: #}
8563:
1.964 droeschl 8564: # Don't add anything more if only_body wanted or in const space
8565: return $result if $args->{'only_body'}
8566: || $env{'request.state'} eq 'construct';
1.813 bisitz 8567:
8568: #Breadcrumbs
1.758 kaisler 8569: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8570: &Apache::lonhtmlcommon::clear_breadcrumbs();
8571: #if any br links exists, add them to the breadcrumbs
8572: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8573: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8574: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8575: }
8576: }
1.1075.2.19 raeburn 8577: # if @advtools array contains items add then to the breadcrumbs
8578: if (@advtools > 0) {
8579: &Apache::lonmenu::advtools_crumbs(@advtools);
8580: }
1.1075.2.123 raeburn 8581: my $menulink;
8582: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8583: if (exists($args->{'bread_crumbs_nomenu'})) {
8584: $menulink = 0;
8585: } else {
8586: undef($menulink);
8587: }
1.758 kaisler 8588: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8589: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8590: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8591: }else{
1.1075.2.123 raeburn 8592: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8593: }
1.1075.2.24 raeburn 8594: } elsif (($env{'environment.remote'} eq 'on') &&
8595: ($env{'form.inhibitmenu'} ne 'yes') &&
8596: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8597: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8598: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8599: }
1.315 albertel 8600: return $result;
1.306 albertel 8601: }
8602:
8603: sub end_page {
1.315 albertel 8604: my ($args) = @_;
8605: $env{'internal.end_page'}++;
1.330 albertel 8606: my $result;
1.335 albertel 8607: if ($args->{'discussion'}) {
8608: my ($target,$parser);
8609: if (ref($args->{'discussion'})) {
8610: ($target,$parser) =($args->{'discussion'}{'target'},
8611: $args->{'discussion'}{'parser'});
8612: }
8613: $result .= &Apache::lonxml::xmlend($target,$parser);
8614: }
1.330 albertel 8615: if ($args->{'frameset'}) {
8616: $result .= '</frameset>';
8617: } else {
1.635 raeburn 8618: $result .= &endbodytag($args);
1.330 albertel 8619: }
1.1075.2.6 raeburn 8620: unless ($args->{'notbody'}) {
8621: $result .= "\n</html>";
8622: }
1.330 albertel 8623:
1.315 albertel 8624: if ($args->{'js_ready'}) {
1.317 albertel 8625: $result = &js_ready($result);
1.315 albertel 8626: }
1.335 albertel 8627:
1.320 albertel 8628: if ($args->{'html_encode'}) {
8629: $result = &html_encode($result);
8630: }
1.335 albertel 8631:
1.315 albertel 8632: return $result;
8633: }
8634:
1.1034 www 8635: sub wishlist_window {
8636: return(<<'ENDWISHLIST');
1.1046 raeburn 8637: <script type="text/javascript">
1.1034 www 8638: // <![CDATA[
8639: // <!-- BEGIN LON-CAPA Internal
8640: function set_wishlistlink(title, path) {
8641: if (!title) {
8642: title = document.title;
8643: title = title.replace(/^LON-CAPA /,'');
8644: }
1.1075.2.65 raeburn 8645: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8646: title = title.replace("'","\\\'");
1.1034 www 8647: if (!path) {
8648: path = location.pathname;
8649: }
1.1075.2.65 raeburn 8650: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8651: path = path.replace("'","\\\'");
1.1034 www 8652: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8653: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8654: }
8655: // END LON-CAPA Internal -->
8656: // ]]>
8657: </script>
8658: ENDWISHLIST
8659: }
8660:
1.1030 www 8661: sub modal_window {
8662: return(<<'ENDMODAL');
1.1046 raeburn 8663: <script type="text/javascript">
1.1030 www 8664: // <![CDATA[
8665: // <!-- BEGIN LON-CAPA Internal
8666: var modalWindow = {
8667: parent:"body",
8668: windowId:null,
8669: content:null,
8670: width:null,
8671: height:null,
8672: close:function()
8673: {
8674: $(".LCmodal-window").remove();
8675: $(".LCmodal-overlay").remove();
8676: },
8677: open:function()
8678: {
8679: var modal = "";
8680: modal += "<div class=\"LCmodal-overlay\"></div>";
8681: 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;\">";
8682: modal += this.content;
8683: modal += "</div>";
8684:
8685: $(this.parent).append(modal);
8686:
8687: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8688: $(".LCclose-window").click(function(){modalWindow.close();});
8689: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8690: }
8691: };
1.1075.2.42 raeburn 8692: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8693: {
1.1075.2.119 raeburn 8694: source = source.replace(/'/g,"'");
1.1030 www 8695: modalWindow.windowId = "myModal";
8696: modalWindow.width = width;
8697: modalWindow.height = height;
1.1075.2.80 raeburn 8698: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8699: modalWindow.open();
1.1075.2.87 raeburn 8700: };
1.1030 www 8701: // END LON-CAPA Internal -->
8702: // ]]>
8703: </script>
8704: ENDMODAL
8705: }
8706:
8707: sub modal_link {
1.1075.2.42 raeburn 8708: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8709: unless ($width) { $width=480; }
8710: unless ($height) { $height=400; }
1.1031 www 8711: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8712: unless ($transparency) { $transparency='true'; }
8713:
1.1074 raeburn 8714: my $target_attr;
8715: if (defined($target)) {
8716: $target_attr = 'target="'.$target.'"';
8717: }
8718: return <<"ENDLINK";
1.1075.2.143 raeburn 8719: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 8720: ENDLINK
1.1030 www 8721: }
8722:
1.1032 www 8723: sub modal_adhoc_script {
1.1075.2.155 raeburn 8724: my ($funcname,$width,$height,$content,$possmathjax)=@_;
8725: my $mathjax;
8726: if ($possmathjax) {
8727: $mathjax = <<'ENDJAX';
8728: if (typeof MathJax == 'object') {
8729: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
8730: }
8731: ENDJAX
8732: }
1.1032 www 8733: return (<<ENDADHOC);
1.1046 raeburn 8734: <script type="text/javascript">
1.1032 www 8735: // <![CDATA[
8736: var $funcname = function()
8737: {
8738: modalWindow.windowId = "myModal";
8739: modalWindow.width = $width;
8740: modalWindow.height = $height;
8741: modalWindow.content = '$content';
8742: modalWindow.open();
1.1075.2.155 raeburn 8743: $mathjax
1.1032 www 8744: };
8745: // ]]>
8746: </script>
8747: ENDADHOC
8748: }
8749:
1.1041 www 8750: sub modal_adhoc_inner {
1.1075.2.155 raeburn 8751: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 8752: my $innerwidth=$width-20;
8753: $content=&js_ready(
1.1042 www 8754: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8755: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8756: $content.
1.1041 www 8757: &end_scrollbox().
1.1075.2.42 raeburn 8758: &end_page()
1.1041 www 8759: );
1.1075.2.155 raeburn 8760: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 8761: }
8762:
8763: sub modal_adhoc_window {
1.1075.2.155 raeburn 8764: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
8765: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 8766: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8767: }
8768:
8769: sub modal_adhoc_launch {
8770: my ($funcname,$width,$height,$content)=@_;
8771: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8772: <script type="text/javascript">
8773: // <![CDATA[
8774: $funcname();
8775: // ]]>
8776: </script>
8777: ENDLAUNCH
8778: }
8779:
8780: sub modal_adhoc_close {
8781: return (<<ENDCLOSE);
8782: <script type="text/javascript">
8783: // <![CDATA[
8784: modalWindow.close();
8785: // ]]>
8786: </script>
8787: ENDCLOSE
8788: }
8789:
1.1038 www 8790: sub togglebox_script {
8791: return(<<ENDTOGGLE);
8792: <script type="text/javascript">
8793: // <![CDATA[
8794: function LCtoggleDisplay(id,hidetext,showtext) {
8795: link = document.getElementById(id + "link").childNodes[0];
8796: with (document.getElementById(id).style) {
8797: if (display == "none" ) {
8798: display = "inline";
8799: link.nodeValue = hidetext;
8800: } else {
8801: display = "none";
8802: link.nodeValue = showtext;
8803: }
8804: }
8805: }
8806: // ]]>
8807: </script>
8808: ENDTOGGLE
8809: }
8810:
1.1039 www 8811: sub start_togglebox {
8812: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8813: unless ($heading) { $heading=''; } else { $heading.=' '; }
8814: unless ($showtext) { $showtext=&mt('show'); }
8815: unless ($hidetext) { $hidetext=&mt('hide'); }
8816: unless ($headerbg) { $headerbg='#FFFFFF'; }
8817: return &start_data_table().
8818: &start_data_table_header_row().
8819: '<td bgcolor="'.$headerbg.'">'.$heading.
8820: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8821: $showtext.'\')">'.$showtext.'</a>]</td>'.
8822: &end_data_table_header_row().
8823: '<tr id="'.$id.'" style="display:none""><td>';
8824: }
8825:
8826: sub end_togglebox {
8827: return '</td></tr>'.&end_data_table();
8828: }
8829:
1.1041 www 8830: sub LCprogressbar_script {
1.1075.2.130 raeburn 8831: my ($id,$number_to_do)=@_;
8832: if ($number_to_do) {
8833: return(<<ENDPROGRESS);
1.1041 www 8834: <script type="text/javascript">
8835: // <![CDATA[
1.1045 www 8836: \$('#progressbar$id').progressbar({
1.1041 www 8837: value: 0,
8838: change: function(event, ui) {
8839: var newVal = \$(this).progressbar('option', 'value');
8840: \$('.pblabel', this).text(LCprogressTxt);
8841: }
8842: });
8843: // ]]>
8844: </script>
8845: ENDPROGRESS
1.1075.2.130 raeburn 8846: } else {
8847: return(<<ENDPROGRESS);
8848: <script type="text/javascript">
8849: // <![CDATA[
8850: \$('#progressbar$id').progressbar({
8851: value: false,
8852: create: function(event, ui) {
8853: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8854: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8855: }
8856: });
8857: // ]]>
8858: </script>
8859: ENDPROGRESS
8860: }
1.1041 www 8861: }
8862:
8863: sub LCprogressbarUpdate_script {
8864: return(<<ENDPROGRESSUPDATE);
8865: <style type="text/css">
8866: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8867: .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 8868: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8869: </style>
8870: <script type="text/javascript">
8871: // <![CDATA[
1.1045 www 8872: var LCprogressTxt='---';
8873:
1.1075.2.130 raeburn 8874: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8875: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8876: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8877: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8878: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8879: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8880: } else {
8881: \$('#progressbar'+id).progressbar('value',percent);
8882: }
1.1041 www 8883: }
8884: // ]]>
8885: </script>
8886: ENDPROGRESSUPDATE
8887: }
8888:
1.1042 www 8889: my $LClastpercent;
1.1045 www 8890: my $LCidcnt;
8891: my $LCcurrentid;
1.1042 www 8892:
1.1041 www 8893: sub LCprogressbar {
1.1075.2.130 raeburn 8894: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8895: $LClastpercent=0;
1.1045 www 8896: $LCidcnt++;
8897: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8898: my ($starting,$content);
8899: if ($number_to_do) {
8900: $starting=&mt('Starting');
8901: $content=(<<ENDPROGBAR);
8902: $preamble
1.1045 www 8903: <div id="progressbar$LCcurrentid">
1.1041 www 8904: <span class="pblabel">$starting</span>
8905: </div>
8906: ENDPROGBAR
1.1075.2.130 raeburn 8907: } else {
8908: $starting=&mt('Loading...');
8909: $LClastpercent='false';
8910: $content=(<<ENDPROGBAR);
8911: $preamble
8912: <div id="progressbar$LCcurrentid">
8913: <div class="progress-label">$starting</div>
8914: </div>
8915: ENDPROGBAR
8916: }
8917: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8918: }
8919:
8920: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8921: my ($r,$val,$text,$number_to_do)=@_;
8922: if ($number_to_do) {
8923: unless ($val) {
8924: if ($LClastpercent) {
8925: $val=$LClastpercent;
8926: } else {
8927: $val=0;
8928: }
8929: }
8930: if ($val<0) { $val=0; }
8931: if ($val>100) { $val=0; }
8932: $LClastpercent=$val;
8933: unless ($text) { $text=$val.'%'; }
8934: } else {
8935: $val = 'false';
1.1042 www 8936: }
1.1041 www 8937: $text=&js_ready($text);
1.1044 www 8938: &r_print($r,<<ENDUPDATE);
1.1041 www 8939: <script type="text/javascript">
8940: // <![CDATA[
1.1075.2.130 raeburn 8941: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8942: // ]]>
8943: </script>
8944: ENDUPDATE
1.1035 www 8945: }
8946:
1.1042 www 8947: sub LCprogressbarClose {
8948: my ($r)=@_;
8949: $LClastpercent=0;
1.1044 www 8950: &r_print($r,<<ENDCLOSE);
1.1042 www 8951: <script type="text/javascript">
8952: // <![CDATA[
1.1045 www 8953: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8954: // ]]>
8955: </script>
8956: ENDCLOSE
1.1044 www 8957: }
8958:
8959: sub r_print {
8960: my ($r,$to_print)=@_;
8961: if ($r) {
8962: $r->print($to_print);
8963: $r->rflush();
8964: } else {
8965: print($to_print);
8966: }
1.1042 www 8967: }
8968:
1.320 albertel 8969: sub html_encode {
8970: my ($result) = @_;
8971:
1.322 albertel 8972: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8973:
8974: return $result;
8975: }
1.1044 www 8976:
1.317 albertel 8977: sub js_ready {
8978: my ($result) = @_;
8979:
1.323 albertel 8980: $result =~ s/[\n\r]/ /xmsg;
8981: $result =~ s/\\/\\\\/xmsg;
8982: $result =~ s/'/\\'/xmsg;
1.372 albertel 8983: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8984:
8985: return $result;
8986: }
8987:
1.315 albertel 8988: sub validate_page {
8989: if ( exists($env{'internal.start_page'})
1.316 albertel 8990: && $env{'internal.start_page'} > 1) {
8991: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8992: $env{'internal.start_page'}.' '.
1.316 albertel 8993: $ENV{'request.filename'});
1.315 albertel 8994: }
8995: if ( exists($env{'internal.end_page'})
1.316 albertel 8996: && $env{'internal.end_page'} > 1) {
8997: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8998: $env{'internal.end_page'}.' '.
1.316 albertel 8999: $env{'request.filename'});
1.315 albertel 9000: }
9001: if ( exists($env{'internal.start_page'})
9002: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9003: &Apache::lonnet::logthis('start_page called without end_page '.
9004: $env{'request.filename'});
1.315 albertel 9005: }
9006: if ( ! exists($env{'internal.start_page'})
9007: && exists($env{'internal.end_page'})) {
1.316 albertel 9008: &Apache::lonnet::logthis('end_page called without start_page'.
9009: $env{'request.filename'});
1.315 albertel 9010: }
1.306 albertel 9011: }
1.315 albertel 9012:
1.996 www 9013:
9014: sub start_scrollbox {
1.1075.2.56 raeburn 9015: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9016: unless ($outerwidth) { $outerwidth='520px'; }
9017: unless ($width) { $width='500px'; }
9018: unless ($height) { $height='200px'; }
1.1075 raeburn 9019: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9020: if ($id ne '') {
1.1075.2.42 raeburn 9021: $table_id = ' id="table_'.$id.'"';
9022: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9023: }
1.1075 raeburn 9024: if ($bgcolor ne '') {
9025: $tdcol = "background-color: $bgcolor;";
9026: }
1.1075.2.42 raeburn 9027: my $nicescroll_js;
9028: if ($env{'browser.mobile'}) {
9029: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9030: }
1.1075 raeburn 9031: return <<"END";
1.1075.2.42 raeburn 9032: $nicescroll_js
9033:
9034: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 9035: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 9036: END
1.996 www 9037: }
9038:
9039: sub end_scrollbox {
1.1036 www 9040: return '</div></td></tr></table>';
1.996 www 9041: }
9042:
1.1075.2.42 raeburn 9043: sub nicescroll_javascript {
9044: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9045: my %options;
9046: if (ref($cursor) eq 'HASH') {
9047: %options = %{$cursor};
9048: }
9049: unless ($options{'railalign'} =~ /^left|right$/) {
9050: $options{'railalign'} = 'left';
9051: }
9052: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9053: my $function = &get_users_function();
9054: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
9055: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9056: $options{'cursorcolor'} = '#00F';
9057: }
9058: }
9059: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9060: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
9061: $options{'cursoropacity'}='1.0';
9062: }
9063: } else {
9064: $options{'cursoropacity'}='1.0';
9065: }
9066: if ($options{'cursorfixedheight'} eq 'none') {
9067: delete($options{'cursorfixedheight'});
9068: } else {
9069: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9070: }
9071: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9072: delete($options{'railoffset'});
9073: }
9074: my @niceoptions;
9075: while (my($key,$value) = each(%options)) {
9076: if ($value =~ /^\{.+\}$/) {
9077: push(@niceoptions,$key.':'.$value);
9078: } else {
9079: push(@niceoptions,$key.':"'.$value.'"');
9080: }
9081: }
9082: my $nicescroll_js = '
9083: $(document).ready(
9084: function() {
9085: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9086: }
9087: );
9088: ';
9089: if ($framecheck) {
9090: $nicescroll_js .= '
9091: function expand_div(caller) {
9092: if (top === self) {
9093: document.getElementById("'.$id.'").style.width = "auto";
9094: document.getElementById("'.$id.'").style.height = "auto";
9095: } else {
9096: try {
9097: if (parent.frames) {
9098: if (parent.frames.length > 1) {
9099: var framesrc = parent.frames[1].location.href;
9100: var currsrc = framesrc.replace(/\#.*$/,"");
9101: if ((caller == "search") || (currsrc == "'.$location.'")) {
9102: document.getElementById("'.$id.'").style.width = "auto";
9103: document.getElementById("'.$id.'").style.height = "auto";
9104: }
9105: }
9106: }
9107: } catch (e) {
9108: return;
9109: }
9110: }
9111: return;
9112: }
9113: ';
9114: }
9115: if ($needjsready) {
9116: $nicescroll_js = '
9117: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9118: } else {
9119: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9120: }
9121: return $nicescroll_js;
9122: }
9123:
1.318 albertel 9124: sub simple_error_page {
1.1075.2.49 raeburn 9125: my ($r,$title,$msg,$args) = @_;
9126: if (ref($args) eq 'HASH') {
9127: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9128: } else {
9129: $msg = &mt($msg);
9130: }
9131:
1.318 albertel 9132: my $page =
9133: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 9134: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9135: &Apache::loncommon::end_page();
9136: if (ref($r)) {
9137: $r->print($page);
1.327 albertel 9138: return;
1.318 albertel 9139: }
9140: return $page;
9141: }
1.347 albertel 9142:
9143: {
1.610 albertel 9144: my @row_count;
1.961 onken 9145:
9146: sub start_data_table_count {
9147: unshift(@row_count, 0);
9148: return;
9149: }
9150:
9151: sub end_data_table_count {
9152: shift(@row_count);
9153: return;
9154: }
9155:
1.347 albertel 9156: sub start_data_table {
1.1018 raeburn 9157: my ($add_class,$id) = @_;
1.422 albertel 9158: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9159: my $table_id;
9160: if (defined($id)) {
9161: $table_id = ' id="'.$id.'"';
9162: }
1.961 onken 9163: &start_data_table_count();
1.1018 raeburn 9164: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9165: }
9166:
9167: sub end_data_table {
1.961 onken 9168: &end_data_table_count();
1.389 albertel 9169: return '</table>'."\n";;
1.347 albertel 9170: }
9171:
9172: sub start_data_table_row {
1.974 wenzelju 9173: my ($add_class, $id) = @_;
1.610 albertel 9174: $row_count[0]++;
9175: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9176: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9177: $id = (' id="'.$id.'"') unless ($id eq '');
9178: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9179: }
1.471 banghart 9180:
9181: sub continue_data_table_row {
1.974 wenzelju 9182: my ($add_class, $id) = @_;
1.610 albertel 9183: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9184: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9185: $id = (' id="'.$id.'"') unless ($id eq '');
9186: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9187: }
1.347 albertel 9188:
9189: sub end_data_table_row {
1.389 albertel 9190: return '</tr>'."\n";;
1.347 albertel 9191: }
1.367 www 9192:
1.421 albertel 9193: sub start_data_table_empty_row {
1.707 bisitz 9194: # $row_count[0]++;
1.421 albertel 9195: return '<tr class="LC_empty_row" >'."\n";;
9196: }
9197:
9198: sub end_data_table_empty_row {
9199: return '</tr>'."\n";;
9200: }
9201:
1.367 www 9202: sub start_data_table_header_row {
1.389 albertel 9203: return '<tr class="LC_header_row">'."\n";;
1.367 www 9204: }
9205:
9206: sub end_data_table_header_row {
1.389 albertel 9207: return '</tr>'."\n";;
1.367 www 9208: }
1.890 droeschl 9209:
9210: sub data_table_caption {
9211: my $caption = shift;
9212: return "<caption class=\"LC_caption\">$caption</caption>";
9213: }
1.347 albertel 9214: }
9215:
1.548 albertel 9216: =pod
9217:
9218: =item * &inhibit_menu_check($arg)
9219:
9220: Checks for a inhibitmenu state and generates output to preserve it
9221:
9222: Inputs: $arg - can be any of
9223: - undef - in which case the return value is a string
9224: to add into arguments list of a uri
9225: - 'input' - in which case the return value is a HTML
9226: <form> <input> field of type hidden to
9227: preserve the value
9228: - a url - in which case the return value is the url with
9229: the neccesary cgi args added to preserve the
9230: inhibitmenu state
9231: - a ref to a url - no return value, but the string is
9232: updated to include the neccessary cgi
9233: args to preserve the inhibitmenu state
9234:
9235: =cut
9236:
9237: sub inhibit_menu_check {
9238: my ($arg) = @_;
9239: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9240: if ($arg eq 'input') {
9241: if ($env{'form.inhibitmenu'}) {
9242: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9243: } else {
9244: return
9245: }
9246: }
9247: if ($env{'form.inhibitmenu'}) {
9248: if (ref($arg)) {
9249: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9250: } elsif ($arg eq '') {
9251: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9252: } else {
9253: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9254: }
9255: }
9256: if (!ref($arg)) {
9257: return $arg;
9258: }
9259: }
9260:
1.251 albertel 9261: ###############################################
1.182 matthew 9262:
9263: =pod
9264:
1.549 albertel 9265: =back
9266:
9267: =head1 User Information Routines
9268:
9269: =over 4
9270:
1.405 albertel 9271: =item * &get_users_function()
1.182 matthew 9272:
9273: Used by &bodytag to determine the current users primary role.
9274: Returns either 'student','coordinator','admin', or 'author'.
9275:
9276: =cut
9277:
9278: ###############################################
9279: sub get_users_function {
1.815 tempelho 9280: my $function = 'norole';
1.818 tempelho 9281: if ($env{'request.role'}=~/^(st)/) {
9282: $function='student';
9283: }
1.907 raeburn 9284: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9285: $function='coordinator';
9286: }
1.258 albertel 9287: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9288: $function='admin';
9289: }
1.826 bisitz 9290: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9291: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9292: $function='author';
9293: }
9294: return $function;
1.54 www 9295: }
1.99 www 9296:
9297: ###############################################
9298:
1.233 raeburn 9299: =pod
9300:
1.821 raeburn 9301: =item * &show_course()
9302:
9303: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9304: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9305:
9306: Inputs:
9307: None
9308:
9309: Outputs:
9310: Scalar: 1 if 'Course' to be used, 0 otherwise.
9311:
9312: =cut
9313:
9314: ###############################################
9315: sub show_course {
9316: my $course = !$env{'user.adv'};
9317: if (!$env{'user.adv'}) {
9318: foreach my $env (keys(%env)) {
9319: next if ($env !~ m/^user\.priv\./);
9320: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9321: $course = 0;
9322: last;
9323: }
9324: }
9325: }
9326: return $course;
9327: }
9328:
9329: ###############################################
9330:
9331: =pod
9332:
1.542 raeburn 9333: =item * &check_user_status()
1.274 raeburn 9334:
9335: Determines current status of supplied role for a
9336: specific user. Roles can be active, previous or future.
9337:
9338: Inputs:
9339: user's domain, user's username, course's domain,
1.375 raeburn 9340: course's number, optional section ID.
1.274 raeburn 9341:
9342: Outputs:
9343: role status: active, previous or future.
9344:
9345: =cut
9346:
9347: sub check_user_status {
1.412 raeburn 9348: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9349: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9350: my @uroles = keys(%userinfo);
1.274 raeburn 9351: my $srchstr;
9352: my $active_chk = 'none';
1.412 raeburn 9353: my $now = time;
1.274 raeburn 9354: if (@uroles > 0) {
1.908 raeburn 9355: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9356: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9357: } else {
1.412 raeburn 9358: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9359: }
9360: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9361: my $role_end = 0;
9362: my $role_start = 0;
9363: $active_chk = 'active';
1.412 raeburn 9364: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9365: $role_end = $1;
9366: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9367: $role_start = $1;
1.274 raeburn 9368: }
9369: }
9370: if ($role_start > 0) {
1.412 raeburn 9371: if ($now < $role_start) {
1.274 raeburn 9372: $active_chk = 'future';
9373: }
9374: }
9375: if ($role_end > 0) {
1.412 raeburn 9376: if ($now > $role_end) {
1.274 raeburn 9377: $active_chk = 'previous';
9378: }
9379: }
9380: }
9381: }
9382: return $active_chk;
9383: }
9384:
9385: ###############################################
9386:
9387: =pod
9388:
1.405 albertel 9389: =item * &get_sections()
1.233 raeburn 9390:
9391: Determines all the sections for a course including
9392: sections with students and sections containing other roles.
1.419 raeburn 9393: Incoming parameters:
9394:
9395: 1. domain
9396: 2. course number
9397: 3. reference to array containing roles for which sections should
9398: be gathered (optional).
9399: 4. reference to array containing status types for which sections
9400: should be gathered (optional).
9401:
9402: If the third argument is undefined, sections are gathered for any role.
9403: If the fourth argument is undefined, sections are gathered for any status.
9404: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9405:
1.374 raeburn 9406: Returns section hash (keys are section IDs, values are
9407: number of users in each section), subject to the
1.419 raeburn 9408: optional roles filter, optional status filter
1.233 raeburn 9409:
9410: =cut
9411:
9412: ###############################################
9413: sub get_sections {
1.419 raeburn 9414: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9415: if (!defined($cdom) || !defined($cnum)) {
9416: my $cid = $env{'request.course.id'};
9417:
9418: return if (!defined($cid));
9419:
9420: $cdom = $env{'course.'.$cid.'.domain'};
9421: $cnum = $env{'course.'.$cid.'.num'};
9422: }
9423:
9424: my %sectioncount;
1.419 raeburn 9425: my $now = time;
1.240 albertel 9426:
1.1075.2.33 raeburn 9427: my $check_students = 1;
9428: my $only_students = 0;
9429: if (ref($possible_roles) eq 'ARRAY') {
9430: if (grep(/^st$/,@{$possible_roles})) {
9431: if (@{$possible_roles} == 1) {
9432: $only_students = 1;
9433: }
9434: } else {
9435: $check_students = 0;
9436: }
9437: }
9438:
9439: if ($check_students) {
1.276 albertel 9440: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9441: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9442: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9443: my $start_index = &Apache::loncoursedata::CL_START();
9444: my $end_index = &Apache::loncoursedata::CL_END();
9445: my $status;
1.366 albertel 9446: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9447: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9448: $data->[$status_index],
9449: $data->[$start_index],
9450: $data->[$end_index]);
9451: if ($stu_status eq 'Active') {
9452: $status = 'active';
9453: } elsif ($end < $now) {
9454: $status = 'previous';
9455: } elsif ($start > $now) {
9456: $status = 'future';
9457: }
9458: if ($section ne '-1' && $section !~ /^\s*$/) {
9459: if ((!defined($possible_status)) || (($status ne '') &&
9460: (grep/^\Q$status\E$/,@{$possible_status}))) {
9461: $sectioncount{$section}++;
9462: }
1.240 albertel 9463: }
9464: }
9465: }
1.1075.2.33 raeburn 9466: if ($only_students) {
9467: return %sectioncount;
9468: }
1.240 albertel 9469: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9470: foreach my $user (sort(keys(%courseroles))) {
9471: if ($user !~ /^(\w{2})/) { next; }
9472: my ($role) = ($user =~ /^(\w{2})/);
9473: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9474: my ($section,$status);
1.240 albertel 9475: if ($role eq 'cr' &&
9476: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9477: $section=$1;
9478: }
9479: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9480: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9481: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9482: if ($end == -1 && $start == -1) {
9483: next; #deleted role
9484: }
9485: if (!defined($possible_status)) {
9486: $sectioncount{$section}++;
9487: } else {
9488: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9489: $status = 'active';
9490: } elsif ($end < $now) {
9491: $status = 'future';
9492: } elsif ($start > $now) {
9493: $status = 'previous';
9494: }
9495: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9496: $sectioncount{$section}++;
9497: }
9498: }
1.233 raeburn 9499: }
1.366 albertel 9500: return %sectioncount;
1.233 raeburn 9501: }
9502:
1.274 raeburn 9503: ###############################################
1.294 raeburn 9504:
9505: =pod
1.405 albertel 9506:
9507: =item * &get_course_users()
9508:
1.275 raeburn 9509: Retrieves usernames:domains for users in the specified course
9510: with specific role(s), and access status.
9511:
9512: Incoming parameters:
1.277 albertel 9513: 1. course domain
9514: 2. course number
9515: 3. access status: users must have - either active,
1.275 raeburn 9516: previous, future, or all.
1.277 albertel 9517: 4. reference to array of permissible roles
1.288 raeburn 9518: 5. reference to array of section restrictions (optional)
9519: 6. reference to results object (hash of hashes).
9520: 7. reference to optional userdata hash
1.609 raeburn 9521: 8. reference to optional statushash
1.630 raeburn 9522: 9. flag if privileged users (except those set to unhide in
9523: course settings) should be excluded
1.609 raeburn 9524: Keys of top level results hash are roles.
1.275 raeburn 9525: Keys of inner hashes are username:domain, with
9526: values set to access type.
1.288 raeburn 9527: Optional userdata hash returns an array with arguments in the
9528: same order as loncoursedata::get_classlist() for student data.
9529:
1.609 raeburn 9530: Optional statushash returns
9531:
1.288 raeburn 9532: Entries for end, start, section and status are blank because
9533: of the possibility of multiple values for non-student roles.
9534:
1.275 raeburn 9535: =cut
1.405 albertel 9536:
1.275 raeburn 9537: ###############################################
1.405 albertel 9538:
1.275 raeburn 9539: sub get_course_users {
1.630 raeburn 9540: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9541: my %idx = ();
1.419 raeburn 9542: my %seclists;
1.288 raeburn 9543:
9544: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9545: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9546: $idx{end} = &Apache::loncoursedata::CL_END();
9547: $idx{start} = &Apache::loncoursedata::CL_START();
9548: $idx{id} = &Apache::loncoursedata::CL_ID();
9549: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9550: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9551: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9552:
1.290 albertel 9553: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9554: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9555: my $now = time;
1.277 albertel 9556: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9557: my $match = 0;
1.412 raeburn 9558: my $secmatch = 0;
1.419 raeburn 9559: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9560: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9561: if ($section eq '') {
9562: $section = 'none';
9563: }
1.291 albertel 9564: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9565: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9566: $secmatch = 1;
9567: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9568: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9569: $secmatch = 1;
9570: }
9571: } else {
1.419 raeburn 9572: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9573: $secmatch = 1;
9574: }
1.290 albertel 9575: }
1.412 raeburn 9576: if (!$secmatch) {
9577: next;
9578: }
1.419 raeburn 9579: }
1.275 raeburn 9580: if (defined($$types{'active'})) {
1.288 raeburn 9581: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9582: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9583: $match = 1;
1.275 raeburn 9584: }
9585: }
9586: if (defined($$types{'previous'})) {
1.609 raeburn 9587: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9588: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9589: $match = 1;
1.275 raeburn 9590: }
9591: }
9592: if (defined($$types{'future'})) {
1.609 raeburn 9593: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9594: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9595: $match = 1;
1.275 raeburn 9596: }
9597: }
1.609 raeburn 9598: if ($match) {
9599: push(@{$seclists{$student}},$section);
9600: if (ref($userdata) eq 'HASH') {
9601: $$userdata{$student} = $$classlist{$student};
9602: }
9603: if (ref($statushash) eq 'HASH') {
9604: $statushash->{$student}{'st'}{$section} = $status;
9605: }
1.288 raeburn 9606: }
1.275 raeburn 9607: }
9608: }
1.412 raeburn 9609: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9610: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9611: my $now = time;
1.609 raeburn 9612: my %displaystatus = ( previous => 'Expired',
9613: active => 'Active',
9614: future => 'Future',
9615: );
1.1075.2.36 raeburn 9616: my (%nothide,@possdoms);
1.630 raeburn 9617: if ($hidepriv) {
9618: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9619: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9620: if ($user !~ /:/) {
9621: $nothide{join(':',split(/[\@]/,$user))}=1;
9622: } else {
9623: $nothide{$user} = 1;
9624: }
9625: }
1.1075.2.36 raeburn 9626: my @possdoms = ($cdom);
9627: if ($coursehash{'checkforpriv'}) {
9628: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9629: }
1.630 raeburn 9630: }
1.439 raeburn 9631: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9632: my $match = 0;
1.412 raeburn 9633: my $secmatch = 0;
1.439 raeburn 9634: my $status;
1.412 raeburn 9635: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9636: $user =~ s/:$//;
1.439 raeburn 9637: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9638: if ($end == -1 || $start == -1) {
9639: next;
9640: }
9641: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9642: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9643: my ($uname,$udom) = split(/:/,$user);
9644: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9645: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9646: $secmatch = 1;
9647: } elsif ($usec eq '') {
1.420 albertel 9648: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9649: $secmatch = 1;
9650: }
9651: } else {
9652: if (grep(/^\Q$usec\E$/,@{$sections})) {
9653: $secmatch = 1;
9654: }
9655: }
9656: if (!$secmatch) {
9657: next;
9658: }
1.288 raeburn 9659: }
1.419 raeburn 9660: if ($usec eq '') {
9661: $usec = 'none';
9662: }
1.275 raeburn 9663: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9664: if ($hidepriv) {
1.1075.2.36 raeburn 9665: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9666: (!$nothide{$uname.':'.$udom})) {
9667: next;
9668: }
9669: }
1.503 raeburn 9670: if ($end > 0 && $end < $now) {
1.439 raeburn 9671: $status = 'previous';
9672: } elsif ($start > $now) {
9673: $status = 'future';
9674: } else {
9675: $status = 'active';
9676: }
1.277 albertel 9677: foreach my $type (keys(%{$types})) {
1.275 raeburn 9678: if ($status eq $type) {
1.420 albertel 9679: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9680: push(@{$$users{$role}{$user}},$type);
9681: }
1.288 raeburn 9682: $match = 1;
9683: }
9684: }
1.419 raeburn 9685: if (($match) && (ref($userdata) eq 'HASH')) {
9686: if (!exists($$userdata{$uname.':'.$udom})) {
9687: &get_user_info($udom,$uname,\%idx,$userdata);
9688: }
1.420 albertel 9689: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9690: push(@{$seclists{$uname.':'.$udom}},$usec);
9691: }
1.609 raeburn 9692: if (ref($statushash) eq 'HASH') {
9693: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9694: }
1.275 raeburn 9695: }
9696: }
9697: }
9698: }
1.290 albertel 9699: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9700: if ((defined($cdom)) && (defined($cnum))) {
9701: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9702: if ( defined($csettings{'internal.courseowner'}) ) {
9703: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9704: next if ($owner eq '');
9705: my ($ownername,$ownerdom);
9706: if ($owner =~ /^([^:]+):([^:]+)$/) {
9707: $ownername = $1;
9708: $ownerdom = $2;
9709: } else {
9710: $ownername = $owner;
9711: $ownerdom = $cdom;
9712: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9713: }
9714: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9715: if (defined($userdata) &&
1.609 raeburn 9716: !exists($$userdata{$owner})) {
9717: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9718: if (!grep(/^none$/,@{$seclists{$owner}})) {
9719: push(@{$seclists{$owner}},'none');
9720: }
9721: if (ref($statushash) eq 'HASH') {
9722: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9723: }
1.290 albertel 9724: }
1.279 raeburn 9725: }
9726: }
9727: }
1.419 raeburn 9728: foreach my $user (keys(%seclists)) {
9729: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9730: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9731: }
1.275 raeburn 9732: }
9733: return;
9734: }
9735:
1.288 raeburn 9736: sub get_user_info {
9737: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9738: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9739: &plainname($uname,$udom,'lastname');
1.291 albertel 9740: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9741: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9742: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9743: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9744: return;
9745: }
1.275 raeburn 9746:
1.472 raeburn 9747: ###############################################
9748:
9749: =pod
9750:
9751: =item * &get_user_quota()
9752:
1.1075.2.41 raeburn 9753: Retrieves quota assigned for storage of user files.
9754: Default is to report quota for portfolio files.
1.472 raeburn 9755:
9756: Incoming parameters:
9757: 1. user's username
9758: 2. user's domain
1.1075.2.41 raeburn 9759: 3. quota name - portfolio, author, or course
9760: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9761: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9762: course
1.472 raeburn 9763:
9764: Returns:
1.1075.2.58 raeburn 9765: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9766: 2. (Optional) Type of setting: custom or default
9767: (individually assigned or default for user's
9768: institutional status).
9769: 3. (Optional) - User's institutional status (e.g., faculty, staff
9770: or student - types as defined in localenroll::inst_usertypes
9771: for user's domain, which determines default quota for user.
9772: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9773:
9774: If a value has been stored in the user's environment,
1.536 raeburn 9775: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9776: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9777:
9778: =cut
9779:
9780: ###############################################
9781:
9782:
9783: sub get_user_quota {
1.1075.2.42 raeburn 9784: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9785: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9786: if (!defined($udom)) {
9787: $udom = $env{'user.domain'};
9788: }
9789: if (!defined($uname)) {
9790: $uname = $env{'user.name'};
9791: }
9792: if (($udom eq '' || $uname eq '') ||
9793: ($udom eq 'public') && ($uname eq 'public')) {
9794: $quota = 0;
1.536 raeburn 9795: $quotatype = 'default';
9796: $defquota = 0;
1.472 raeburn 9797: } else {
1.536 raeburn 9798: my $inststatus;
1.1075.2.41 raeburn 9799: if ($quotaname eq 'course') {
9800: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9801: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9802: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9803: } else {
9804: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9805: $quota = $cenv{'internal.uploadquota'};
9806: }
1.536 raeburn 9807: } else {
1.1075.2.41 raeburn 9808: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9809: if ($quotaname eq 'author') {
9810: $quota = $env{'environment.authorquota'};
9811: } else {
9812: $quota = $env{'environment.portfolioquota'};
9813: }
9814: $inststatus = $env{'environment.inststatus'};
9815: } else {
9816: my %userenv =
9817: &Apache::lonnet::get('environment',['portfolioquota',
9818: 'authorquota','inststatus'],$udom,$uname);
9819: my ($tmp) = keys(%userenv);
9820: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9821: if ($quotaname eq 'author') {
9822: $quota = $userenv{'authorquota'};
9823: } else {
9824: $quota = $userenv{'portfolioquota'};
9825: }
9826: $inststatus = $userenv{'inststatus'};
9827: } else {
9828: undef(%userenv);
9829: }
9830: }
9831: }
9832: if ($quota eq '' || wantarray) {
9833: if ($quotaname eq 'course') {
9834: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9835: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9836: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9837: $defquota = $domdefs{$crstype.'quota'};
9838: }
9839: if ($defquota eq '') {
9840: $defquota = 500;
9841: }
1.1075.2.41 raeburn 9842: } else {
9843: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9844: }
9845: if ($quota eq '') {
9846: $quota = $defquota;
9847: $quotatype = 'default';
9848: } else {
9849: $quotatype = 'custom';
9850: }
1.472 raeburn 9851: }
9852: }
1.536 raeburn 9853: if (wantarray) {
9854: return ($quota,$quotatype,$settingstatus,$defquota);
9855: } else {
9856: return $quota;
9857: }
1.472 raeburn 9858: }
9859:
9860: ###############################################
9861:
9862: =pod
9863:
9864: =item * &default_quota()
9865:
1.536 raeburn 9866: Retrieves default quota assigned for storage of user portfolio files,
9867: given an (optional) user's institutional status.
1.472 raeburn 9868:
9869: Incoming parameters:
1.1075.2.42 raeburn 9870:
1.472 raeburn 9871: 1. domain
1.536 raeburn 9872: 2. (Optional) institutional status(es). This is a : separated list of
9873: status types (e.g., faculty, staff, student etc.)
9874: which apply to the user for whom the default is being retrieved.
9875: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9876: default quota will be returned.
9877: 3. quota name - portfolio, author, or course
9878: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9879:
9880: Returns:
1.1075.2.42 raeburn 9881:
1.1075.2.58 raeburn 9882: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9883: 2. (Optional) institutional type which determined the value of the
9884: default quota.
1.472 raeburn 9885:
9886: If a value has been stored in the domain's configuration db,
9887: it will return that, otherwise it returns 20 (for backwards
9888: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9889: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9890:
1.536 raeburn 9891: If the user's status includes multiple types (e.g., staff and student),
9892: the largest default quota which applies to the user determines the
9893: default quota returned.
9894:
1.472 raeburn 9895: =cut
9896:
9897: ###############################################
9898:
9899:
9900: sub default_quota {
1.1075.2.41 raeburn 9901: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9902: my ($defquota,$settingstatus);
9903: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9904: ['quotas'],$udom);
1.1075.2.41 raeburn 9905: my $key = 'defaultquota';
9906: if ($quotaname eq 'author') {
9907: $key = 'authorquota';
9908: }
1.622 raeburn 9909: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9910: if ($inststatus ne '') {
1.765 raeburn 9911: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9912: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9913: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9914: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9915: if ($defquota eq '') {
1.1075.2.41 raeburn 9916: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9917: $settingstatus = $item;
1.1075.2.41 raeburn 9918: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9919: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9920: $settingstatus = $item;
9921: }
9922: }
1.1075.2.41 raeburn 9923: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9924: if ($quotahash{'quotas'}{$item} ne '') {
9925: if ($defquota eq '') {
9926: $defquota = $quotahash{'quotas'}{$item};
9927: $settingstatus = $item;
9928: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9929: $defquota = $quotahash{'quotas'}{$item};
9930: $settingstatus = $item;
9931: }
1.536 raeburn 9932: }
9933: }
9934: }
9935: }
9936: if ($defquota eq '') {
1.1075.2.41 raeburn 9937: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9938: $defquota = $quotahash{'quotas'}{$key}{'default'};
9939: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9940: $defquota = $quotahash{'quotas'}{'default'};
9941: }
1.536 raeburn 9942: $settingstatus = 'default';
1.1075.2.42 raeburn 9943: if ($defquota eq '') {
9944: if ($quotaname eq 'author') {
9945: $defquota = 500;
9946: }
9947: }
1.536 raeburn 9948: }
9949: } else {
9950: $settingstatus = 'default';
1.1075.2.41 raeburn 9951: if ($quotaname eq 'author') {
9952: $defquota = 500;
9953: } else {
9954: $defquota = 20;
9955: }
1.536 raeburn 9956: }
9957: if (wantarray) {
9958: return ($defquota,$settingstatus);
1.472 raeburn 9959: } else {
1.536 raeburn 9960: return $defquota;
1.472 raeburn 9961: }
9962: }
9963:
1.1075.2.41 raeburn 9964: ###############################################
9965:
9966: =pod
9967:
1.1075.2.42 raeburn 9968: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9969:
9970: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9971: of existing file within authoring space will cause quota for the authoring
9972: space to be exceeded.
9973:
9974: Same, if upload of a file directly to a course/community via Course Editor
9975: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9976:
1.1075.2.61 raeburn 9977: Inputs: 7
1.1075.2.42 raeburn 9978: 1. username or coursenum
1.1075.2.41 raeburn 9979: 2. domain
1.1075.2.42 raeburn 9980: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9981: 4. filename of file for which action is being requested
9982: 5. filesize (kB) of file
9983: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9984: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9985:
9986: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9987: otherwise return null.
9988:
1.1075.2.42 raeburn 9989: =back
9990:
1.1075.2.41 raeburn 9991: =cut
9992:
1.1075.2.42 raeburn 9993: sub excess_filesize_warning {
1.1075.2.59 raeburn 9994: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9995: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9996: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9997: if ($context eq 'author') {
9998: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9999: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10000: } else {
10001: foreach my $subdir ('docs','supplemental') {
10002: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10003: }
10004: }
1.1075.2.41 raeburn 10005: $disk_quota = int($disk_quota * 1000);
10006: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 10007: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 10008: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 10009: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10010: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 10011: $disk_quota,$current_disk_usage).
10012: '</p>';
10013: }
10014: return;
10015: }
10016:
10017: ###############################################
10018:
10019:
1.384 raeburn 10020: sub get_secgrprole_info {
10021: my ($cdom,$cnum,$needroles,$type) = @_;
10022: my %sections_count = &get_sections($cdom,$cnum);
10023: my @sections = (sort {$a <=> $b} keys(%sections_count));
10024: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10025: my @groups = sort(keys(%curr_groups));
10026: my $allroles = [];
10027: my $rolehash;
10028: my $accesshash = {
10029: active => 'Currently has access',
10030: future => 'Will have future access',
10031: previous => 'Previously had access',
10032: };
10033: if ($needroles) {
10034: $rolehash = {'all' => 'all'};
1.385 albertel 10035: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10036: if (&Apache::lonnet::error(%user_roles)) {
10037: undef(%user_roles);
10038: }
10039: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10040: my ($role)=split(/\:/,$item,2);
10041: if ($role eq 'cr') { next; }
10042: if ($role =~ /^cr/) {
10043: $$rolehash{$role} = (split('/',$role))[3];
10044: } else {
10045: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10046: }
10047: }
10048: foreach my $key (sort(keys(%{$rolehash}))) {
10049: push(@{$allroles},$key);
10050: }
10051: push (@{$allroles},'st');
10052: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10053: }
10054: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10055: }
10056:
1.555 raeburn 10057: sub user_picker {
1.1075.2.127 raeburn 10058: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10059: my $currdom = $dom;
1.1075.2.114 raeburn 10060: my @alldoms = &Apache::lonnet::all_domains();
10061: if (@alldoms == 1) {
10062: my %domsrch = &Apache::lonnet::get_dom('configuration',
10063: ['directorysrch'],$alldoms[0]);
10064: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10065: my $showdom = $domdesc;
10066: if ($showdom eq '') {
10067: $showdom = $dom;
10068: }
10069: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10070: if ((!$domsrch{'directorysrch'}{'available'}) &&
10071: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10072: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10073: }
10074: }
10075: }
1.555 raeburn 10076: my %curr_selected = (
10077: srchin => 'dom',
1.580 raeburn 10078: srchby => 'lastname',
1.555 raeburn 10079: );
10080: my $srchterm;
1.625 raeburn 10081: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10082: if ($srch->{'srchby'} ne '') {
10083: $curr_selected{'srchby'} = $srch->{'srchby'};
10084: }
10085: if ($srch->{'srchin'} ne '') {
10086: $curr_selected{'srchin'} = $srch->{'srchin'};
10087: }
10088: if ($srch->{'srchtype'} ne '') {
10089: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10090: }
10091: if ($srch->{'srchdomain'} ne '') {
10092: $currdom = $srch->{'srchdomain'};
10093: }
10094: $srchterm = $srch->{'srchterm'};
10095: }
1.1075.2.98 raeburn 10096: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10097: 'usr' => 'Search criteria',
1.563 raeburn 10098: 'doma' => 'Domain/institution to search',
1.558 albertel 10099: 'uname' => 'username',
10100: 'lastname' => 'last name',
1.555 raeburn 10101: 'lastfirst' => 'last name, first name',
1.558 albertel 10102: 'crs' => 'in this course',
1.576 raeburn 10103: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10104: 'alc' => 'all LON-CAPA',
1.573 raeburn 10105: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10106: 'exact' => 'is',
10107: 'contains' => 'contains',
1.569 raeburn 10108: 'begins' => 'begins with',
1.1075.2.98 raeburn 10109: );
10110: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10111: 'youm' => "You must include some text to search for.",
10112: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10113: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10114: 'yomc' => "You must choose a domain when using an institutional directory search.",
10115: 'ymcd' => "You must choose a domain when using a domain search.",
10116: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10117: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10118: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10119: );
1.1075.2.98 raeburn 10120: &html_escape(\%html_lt);
10121: &js_escape(\%js_lt);
1.1075.2.115 raeburn 10122: my $domform;
1.1075.2.126 raeburn 10123: my $allow_blank = 1;
1.1075.2.115 raeburn 10124: if ($fixeddom) {
1.1075.2.126 raeburn 10125: $allow_blank = 0;
10126: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 10127: } else {
1.1075.2.126 raeburn 10128: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 10129: }
1.563 raeburn 10130: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10131:
10132: my @srchins = ('crs','dom','alc','instd');
10133:
10134: foreach my $option (@srchins) {
10135: # FIXME 'alc' option unavailable until
10136: # loncreateuser::print_user_query_page()
10137: # has been completed.
10138: next if ($option eq 'alc');
1.880 raeburn 10139: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10140: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 10141: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10142: if ($curr_selected{'srchin'} eq $option) {
10143: $srchinsel .= '
1.1075.2.98 raeburn 10144: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10145: } else {
10146: $srchinsel .= '
1.1075.2.98 raeburn 10147: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10148: }
1.555 raeburn 10149: }
1.563 raeburn 10150: $srchinsel .= "\n </select>\n";
1.555 raeburn 10151:
10152: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10153: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10154: if ($curr_selected{'srchby'} eq $option) {
10155: $srchbysel .= '
1.1075.2.98 raeburn 10156: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10157: } else {
10158: $srchbysel .= '
1.1075.2.98 raeburn 10159: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10160: }
10161: }
10162: $srchbysel .= "\n </select>\n";
10163:
10164: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10165: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10166: if ($curr_selected{'srchtype'} eq $option) {
10167: $srchtypesel .= '
1.1075.2.98 raeburn 10168: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10169: } else {
10170: $srchtypesel .= '
1.1075.2.98 raeburn 10171: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10172: }
10173: }
10174: $srchtypesel .= "\n </select>\n";
10175:
1.558 albertel 10176: my ($newuserscript,$new_user_create);
1.994 raeburn 10177: my $context_dom = $env{'request.role.domain'};
10178: if ($context eq 'requestcrs') {
10179: if ($env{'form.coursedom'} ne '') {
10180: $context_dom = $env{'form.coursedom'};
10181: }
10182: }
1.556 raeburn 10183: if ($forcenewuser) {
1.576 raeburn 10184: if (ref($srch) eq 'HASH') {
1.994 raeburn 10185: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10186: if ($cancreate) {
10187: $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>';
10188: } else {
1.799 bisitz 10189: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10190: my %usertypetext = (
10191: official => 'institutional',
10192: unofficial => 'non-institutional',
10193: );
1.799 bisitz 10194: $new_user_create = '<p class="LC_warning">'
10195: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10196: .' '
10197: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10198: ,'<a href="'.$helplink.'">','</a>')
10199: .'</p><br />';
1.627 raeburn 10200: }
1.576 raeburn 10201: }
10202: }
10203:
1.556 raeburn 10204: $newuserscript = <<"ENDSCRIPT";
10205:
1.570 raeburn 10206: function setSearch(createnew,callingForm) {
1.556 raeburn 10207: if (createnew == 1) {
1.570 raeburn 10208: for (var i=0; i<callingForm.srchby.length; i++) {
10209: if (callingForm.srchby.options[i].value == 'uname') {
10210: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10211: }
10212: }
1.570 raeburn 10213: for (var i=0; i<callingForm.srchin.length; i++) {
10214: if ( callingForm.srchin.options[i].value == 'dom') {
10215: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10216: }
10217: }
1.570 raeburn 10218: for (var i=0; i<callingForm.srchtype.length; i++) {
10219: if (callingForm.srchtype.options[i].value == 'exact') {
10220: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10221: }
10222: }
1.570 raeburn 10223: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10224: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10225: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10226: }
10227: }
10228: }
10229: }
10230: ENDSCRIPT
1.558 albertel 10231:
1.556 raeburn 10232: }
10233:
1.555 raeburn 10234: my $output = <<"END_BLOCK";
1.556 raeburn 10235: <script type="text/javascript">
1.824 bisitz 10236: // <![CDATA[
1.570 raeburn 10237: function validateEntry(callingForm) {
1.558 albertel 10238:
1.556 raeburn 10239: var checkok = 1;
1.558 albertel 10240: var srchin;
1.570 raeburn 10241: for (var i=0; i<callingForm.srchin.length; i++) {
10242: if ( callingForm.srchin[i].checked ) {
10243: srchin = callingForm.srchin[i].value;
1.558 albertel 10244: }
10245: }
10246:
1.570 raeburn 10247: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10248: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10249: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10250: var srchterm = callingForm.srchterm.value;
10251: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10252: var msg = "";
10253:
10254: if (srchterm == "") {
10255: checkok = 0;
1.1075.2.98 raeburn 10256: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10257: }
10258:
1.569 raeburn 10259: if (srchtype== 'begins') {
10260: if (srchterm.length < 2) {
10261: checkok = 0;
1.1075.2.98 raeburn 10262: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10263: }
10264: }
10265:
1.556 raeburn 10266: if (srchtype== 'contains') {
10267: if (srchterm.length < 3) {
10268: checkok = 0;
1.1075.2.98 raeburn 10269: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10270: }
10271: }
10272: if (srchin == 'instd') {
10273: if (srchdomain == '') {
10274: checkok = 0;
1.1075.2.98 raeburn 10275: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10276: }
10277: }
10278: if (srchin == 'dom') {
10279: if (srchdomain == '') {
10280: checkok = 0;
1.1075.2.98 raeburn 10281: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10282: }
10283: }
10284: if (srchby == 'lastfirst') {
10285: if (srchterm.indexOf(",") == -1) {
10286: checkok = 0;
1.1075.2.98 raeburn 10287: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10288: }
10289: if (srchterm.indexOf(",") == srchterm.length -1) {
10290: checkok = 0;
1.1075.2.98 raeburn 10291: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10292: }
10293: }
10294: if (checkok == 0) {
1.1075.2.98 raeburn 10295: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10296: return;
10297: }
10298: if (checkok == 1) {
1.570 raeburn 10299: callingForm.submit();
1.556 raeburn 10300: }
10301: }
10302:
10303: $newuserscript
10304:
1.824 bisitz 10305: // ]]>
1.556 raeburn 10306: </script>
1.558 albertel 10307:
10308: $new_user_create
10309:
1.555 raeburn 10310: END_BLOCK
1.558 albertel 10311:
1.876 raeburn 10312: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 10313: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10314: $domform.
10315: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 10316: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10317: $srchbysel.
10318: $srchtypesel.
10319: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10320: $srchinsel.
10321: &Apache::lonhtmlcommon::row_closure(1).
10322: &Apache::lonhtmlcommon::end_pick_box().
10323: '<br />';
1.1075.2.114 raeburn 10324: return ($output,1);
1.555 raeburn 10325: }
10326:
1.612 raeburn 10327: sub user_rule_check {
1.615 raeburn 10328: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10329: my ($response,%inst_response);
1.612 raeburn 10330: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10331: if (keys(%{$usershash}) > 1) {
10332: my (%by_username,%by_id,%userdoms);
10333: my $checkid;
1.612 raeburn 10334: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10335: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10336: $checkid = 1;
10337: }
10338: }
10339: foreach my $user (keys(%{$usershash})) {
10340: my ($uname,$udom) = split(/:/,$user);
10341: if ($checkid) {
10342: if (ref($usershash->{$user}) eq 'HASH') {
10343: if ($usershash->{$user}->{'id'} ne '') {
10344: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10345: $userdoms{$udom} = 1;
10346: if (ref($inst_results) eq 'HASH') {
10347: $inst_results->{$uname.':'.$udom} = {};
10348: }
10349: }
10350: }
10351: } else {
10352: $by_username{$udom}{$uname} = 1;
10353: $userdoms{$udom} = 1;
10354: if (ref($inst_results) eq 'HASH') {
10355: $inst_results->{$uname.':'.$udom} = {};
10356: }
10357: }
10358: }
10359: foreach my $udom (keys(%userdoms)) {
10360: if (!$got_rules->{$udom}) {
10361: my %domconfig = &Apache::lonnet::get_dom('configuration',
10362: ['usercreation'],$udom);
10363: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10364: foreach my $item ('username','id') {
10365: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10366: $$curr_rules{$udom}{$item} =
10367: $domconfig{'usercreation'}{$item.'_rule'};
10368: }
10369: }
10370: }
10371: $got_rules->{$udom} = 1;
10372: }
10373: }
10374: if ($checkid) {
10375: foreach my $udom (keys(%by_id)) {
10376: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10377: if ($outcome eq 'ok') {
10378: foreach my $id (keys(%{$by_id{$udom}})) {
10379: my $uname = $by_id{$udom}{$id};
10380: $inst_response{$uname.':'.$udom} = $outcome;
10381: }
10382: if (ref($results) eq 'HASH') {
10383: foreach my $uname (keys(%{$results})) {
10384: if (exists($inst_response{$uname.':'.$udom})) {
10385: $inst_response{$uname.':'.$udom} = $outcome;
10386: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10387: }
10388: }
10389: }
10390: }
1.612 raeburn 10391: }
1.615 raeburn 10392: } else {
1.1075.2.99 raeburn 10393: foreach my $udom (keys(%by_username)) {
10394: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10395: if ($outcome eq 'ok') {
10396: foreach my $uname (keys(%{$by_username{$udom}})) {
10397: $inst_response{$uname.':'.$udom} = $outcome;
10398: }
10399: if (ref($results) eq 'HASH') {
10400: foreach my $uname (keys(%{$results})) {
10401: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10402: }
10403: }
10404: }
10405: }
1.612 raeburn 10406: }
1.1075.2.99 raeburn 10407: } elsif (keys(%{$usershash}) == 1) {
10408: my $user = (keys(%{$usershash}))[0];
10409: my ($uname,$udom) = split(/:/,$user);
10410: if (($udom ne '') && ($uname ne '')) {
10411: if (ref($usershash->{$user}) eq 'HASH') {
10412: if (ref($checks) eq 'HASH') {
10413: if (defined($checks->{'username'})) {
10414: ($inst_response{$user},%{$inst_results->{$user}}) =
10415: &Apache::lonnet::get_instuser($udom,$uname);
10416: } elsif (defined($checks->{'id'})) {
10417: if ($usershash->{$user}->{'id'} ne '') {
10418: ($inst_response{$user},%{$inst_results->{$user}}) =
10419: &Apache::lonnet::get_instuser($udom,undef,
10420: $usershash->{$user}->{'id'});
10421: } else {
10422: ($inst_response{$user},%{$inst_results->{$user}}) =
10423: &Apache::lonnet::get_instuser($udom,$uname);
10424: }
10425: }
10426: } else {
10427: ($inst_response{$user},%{$inst_results->{$user}}) =
10428: &Apache::lonnet::get_instuser($udom,$uname);
10429: return;
10430: }
10431: if (!$got_rules->{$udom}) {
10432: my %domconfig = &Apache::lonnet::get_dom('configuration',
10433: ['usercreation'],$udom);
10434: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10435: foreach my $item ('username','id') {
10436: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10437: $$curr_rules{$udom}{$item} =
10438: $domconfig{'usercreation'}{$item.'_rule'};
10439: }
10440: }
1.585 raeburn 10441: }
1.1075.2.99 raeburn 10442: $got_rules->{$udom} = 1;
1.585 raeburn 10443: }
10444: }
1.1075.2.99 raeburn 10445: } else {
10446: return;
10447: }
10448: } else {
10449: return;
10450: }
10451: foreach my $user (keys(%{$usershash})) {
10452: my ($uname,$udom) = split(/:/,$user);
10453: next if (($udom eq '') || ($uname eq ''));
10454: my $id;
10455: if (ref($inst_results) eq 'HASH') {
10456: if (ref($inst_results->{$user}) eq 'HASH') {
10457: $id = $inst_results->{$user}->{'id'};
10458: }
10459: }
10460: if ($id eq '') {
10461: if (ref($usershash->{$user})) {
10462: $id = $usershash->{$user}->{'id'};
10463: }
1.585 raeburn 10464: }
1.612 raeburn 10465: foreach my $item (keys(%{$checks})) {
10466: if (ref($$curr_rules{$udom}) eq 'HASH') {
10467: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10468: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10469: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10470: $$curr_rules{$udom}{$item});
1.612 raeburn 10471: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10472: if ($rule_check{$rule}) {
10473: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10474: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10475: if (ref($inst_results) eq 'HASH') {
10476: if (ref($inst_results->{$user}) eq 'HASH') {
10477: if (keys(%{$inst_results->{$user}}) == 0) {
10478: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10479: } elsif ($item eq 'id') {
10480: if ($inst_results->{$user}->{'id'} eq '') {
10481: $$alerts{$item}{$udom}{$uname} = 1;
10482: }
1.615 raeburn 10483: }
1.612 raeburn 10484: }
10485: }
1.615 raeburn 10486: }
10487: last;
1.585 raeburn 10488: }
10489: }
10490: }
10491: }
10492: }
10493: }
10494: }
10495: }
1.612 raeburn 10496: return;
10497: }
10498:
10499: sub user_rule_formats {
10500: my ($domain,$domdesc,$curr_rules,$check) = @_;
10501: my %text = (
10502: 'username' => 'Usernames',
10503: 'id' => 'IDs',
10504: );
10505: my $output;
10506: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10507: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10508: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10509: $output = '<br />'.
10510: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10511: '<span class="LC_cusr_emph">','</span>',$domdesc).
10512: ' <ul>';
1.612 raeburn 10513: foreach my $rule (@{$ruleorder}) {
10514: if (ref($curr_rules) eq 'ARRAY') {
10515: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10516: if (ref($rules->{$rule}) eq 'HASH') {
10517: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10518: $rules->{$rule}{'desc'}.'</li>';
10519: }
10520: }
10521: }
10522: }
10523: $output .= '</ul>';
10524: }
10525: }
10526: return $output;
10527: }
10528:
10529: sub instrule_disallow_msg {
1.615 raeburn 10530: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10531: my $response;
10532: my %text = (
10533: item => 'username',
10534: items => 'usernames',
10535: match => 'matches',
10536: do => 'does',
10537: action => 'a username',
10538: one => 'one',
10539: );
10540: if ($count > 1) {
10541: $text{'item'} = 'usernames';
10542: $text{'match'} ='match';
10543: $text{'do'} = 'do';
10544: $text{'action'} = 'usernames',
10545: $text{'one'} = 'ones';
10546: }
10547: if ($checkitem eq 'id') {
10548: $text{'items'} = 'IDs';
10549: $text{'item'} = 'ID';
10550: $text{'action'} = 'an ID';
1.615 raeburn 10551: if ($count > 1) {
10552: $text{'item'} = 'IDs';
10553: $text{'action'} = 'IDs';
10554: }
1.612 raeburn 10555: }
1.674 bisitz 10556: $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 10557: if ($mode eq 'upload') {
10558: if ($checkitem eq 'username') {
10559: $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'}.");
10560: } elsif ($checkitem eq 'id') {
1.674 bisitz 10561: $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 10562: }
1.669 raeburn 10563: } elsif ($mode eq 'selfcreate') {
10564: if ($checkitem eq 'id') {
10565: $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.");
10566: }
1.615 raeburn 10567: } else {
10568: if ($checkitem eq 'username') {
10569: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10570: } elsif ($checkitem eq 'id') {
10571: $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.");
10572: }
1.612 raeburn 10573: }
10574: return $response;
1.585 raeburn 10575: }
10576:
1.624 raeburn 10577: sub personal_data_fieldtitles {
10578: my %fieldtitles = &Apache::lonlocal::texthash (
10579: id => 'Student/Employee ID',
10580: permanentemail => 'E-mail address',
10581: lastname => 'Last Name',
10582: firstname => 'First Name',
10583: middlename => 'Middle Name',
10584: generation => 'Generation',
10585: gen => 'Generation',
1.765 raeburn 10586: inststatus => 'Affiliation',
1.624 raeburn 10587: );
10588: return %fieldtitles;
10589: }
10590:
1.642 raeburn 10591: sub sorted_inst_types {
10592: my ($dom) = @_;
1.1075.2.70 raeburn 10593: my ($usertypes,$order);
10594: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10595: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10596: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10597: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10598: } else {
10599: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10600: }
1.642 raeburn 10601: my $othertitle = &mt('All users');
10602: if ($env{'request.course.id'}) {
1.668 raeburn 10603: $othertitle = &mt('Any users');
1.642 raeburn 10604: }
10605: my @types;
10606: if (ref($order) eq 'ARRAY') {
10607: @types = @{$order};
10608: }
10609: if (@types == 0) {
10610: if (ref($usertypes) eq 'HASH') {
10611: @types = sort(keys(%{$usertypes}));
10612: }
10613: }
10614: if (keys(%{$usertypes}) > 0) {
10615: $othertitle = &mt('Other users');
10616: }
10617: return ($othertitle,$usertypes,\@types);
10618: }
10619:
1.645 raeburn 10620: sub get_institutional_codes {
1.1075.2.157 raeburn 10621: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 10622: # Get complete list of course sections to update
10623: my @currsections = ();
10624: my @currxlists = ();
1.1075.2.157 raeburn 10625: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 10626: my $coursecode = $$settings{'internal.coursecode'};
1.1075.2.157 raeburn 10627: my $crskey = $crs.':'.$coursecode;
10628: @{$unclutteredsec{$crskey}} = ();
10629: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 10630:
10631: if ($$settings{'internal.sectionnums'} ne '') {
10632: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10633: }
10634:
10635: if ($$settings{'internal.crosslistings'} ne '') {
10636: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10637: }
10638:
10639: if (@currxlists > 0) {
1.1075.2.157 raeburn 10640: foreach my $xl (@currxlists) {
10641: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 10642: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10643: push(@{$allcourses},$1);
1.645 raeburn 10644: $$LC_code{$1} = $2;
10645: }
10646: }
10647: }
10648: }
1.1075.2.157 raeburn 10649:
1.645 raeburn 10650: if (@currsections > 0) {
1.1075.2.157 raeburn 10651: foreach my $sec (@currsections) {
10652: if ($sec =~ m/^(\w+):(\w*)$/ ) {
10653: my $instsec = $1;
1.645 raeburn 10654: my $lc_sec = $2;
1.1075.2.157 raeburn 10655: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
10656: push(@{$unclutteredsec{$crskey}},$instsec);
10657: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
10658: }
10659: }
10660: }
10661: }
10662:
10663: if (@{$unclutteredsec{$crskey}} > 0) {
10664: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
10665: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
10666: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
10667: my $sec = $coursecode.$formattedsec{$crskey}[$i];
10668: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1075.2.119 raeburn 10669: push(@{$allcourses},$sec);
1.1075.2.157 raeburn 10670: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 10671: }
10672: }
10673: }
10674: }
10675: return;
10676: }
10677:
1.971 raeburn 10678: sub get_standard_codeitems {
10679: return ('Year','Semester','Department','Number','Section');
10680: }
10681:
1.112 bowersj2 10682: =pod
10683:
1.780 raeburn 10684: =head1 Slot Helpers
10685:
10686: =over 4
10687:
10688: =item * sorted_slots()
10689:
1.1040 raeburn 10690: Sorts an array of slot names in order of an optional sort key,
10691: default sort is by slot start time (earliest first).
1.780 raeburn 10692:
10693: Inputs:
10694:
10695: =over 4
10696:
10697: slotsarr - Reference to array of unsorted slot names.
10698:
10699: slots - Reference to hash of hash, where outer hash keys are slot names.
10700:
1.1040 raeburn 10701: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10702:
1.549 albertel 10703: =back
10704:
1.780 raeburn 10705: Returns:
10706:
10707: =over 4
10708:
1.1040 raeburn 10709: sorted - An array of slot names sorted by a specified sort key
10710: (default sort key is start time of the slot).
1.780 raeburn 10711:
10712: =back
10713:
10714: =cut
10715:
10716:
10717: sub sorted_slots {
1.1040 raeburn 10718: my ($slotsarr,$slots,$sortkey) = @_;
10719: if ($sortkey eq '') {
10720: $sortkey = 'starttime';
10721: }
1.780 raeburn 10722: my @sorted;
10723: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10724: @sorted =
10725: sort {
10726: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10727: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10728: }
10729: if (ref($slots->{$a})) { return -1;}
10730: if (ref($slots->{$b})) { return 1;}
10731: return 0;
10732: } @{$slotsarr};
10733: }
10734: return @sorted;
10735: }
10736:
1.1040 raeburn 10737: =pod
10738:
10739: =item * get_future_slots()
10740:
10741: Inputs:
10742:
10743: =over 4
10744:
10745: cnum - course number
10746:
10747: cdom - course domain
10748:
10749: now - current UNIX time
10750:
10751: symb - optional symb
10752:
10753: =back
10754:
10755: Returns:
10756:
10757: =over 4
10758:
10759: sorted_reservable - ref to array of student_schedulable slots currently
10760: reservable, ordered by end date of reservation period.
10761:
10762: reservable_now - ref to hash of student_schedulable slots currently
10763: reservable.
10764:
10765: Keys in inner hash are:
10766: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10767: (b) endreserve: end date of reservation period.
10768: (c) uniqueperiod: start,end dates when slot is to be uniquely
10769: selected.
1.1040 raeburn 10770:
10771: sorted_future - ref to array of student_schedulable slots reservable in
10772: the future, ordered by start date of reservation period.
10773:
10774: future_reservable - ref to hash of student_schedulable slots reservable
10775: in the future.
10776:
10777: Keys in inner hash are:
10778: (a) symb: either blank or symb to which slot use is restricted.
10779: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10780: (c) uniqueperiod: start,end dates when slot is to be uniquely
10781: selected.
1.1040 raeburn 10782:
10783: =back
10784:
10785: =cut
10786:
10787: sub get_future_slots {
10788: my ($cnum,$cdom,$now,$symb) = @_;
10789: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10790: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10791: foreach my $slot (keys(%slots)) {
10792: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10793: if ($symb) {
10794: next if (($slots{$slot}->{'symb'} ne '') &&
10795: ($slots{$slot}->{'symb'} ne $symb));
10796: }
10797: if (($slots{$slot}->{'starttime'} > $now) &&
10798: ($slots{$slot}->{'endtime'} > $now)) {
10799: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10800: my $userallowed = 0;
10801: if ($slots{$slot}->{'allowedsections'}) {
10802: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10803: if (!defined($env{'request.role.sec'})
10804: && grep(/^No section assigned$/,@allowed_sec)) {
10805: $userallowed=1;
10806: } else {
10807: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10808: $userallowed=1;
10809: }
10810: }
10811: unless ($userallowed) {
10812: if (defined($env{'request.course.groups'})) {
10813: my @groups = split(/:/,$env{'request.course.groups'});
10814: foreach my $group (@groups) {
10815: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10816: $userallowed=1;
10817: last;
10818: }
10819: }
10820: }
10821: }
10822: }
10823: if ($slots{$slot}->{'allowedusers'}) {
10824: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10825: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10826: if (grep(/^\Q$user\E$/,@allowed_users)) {
10827: $userallowed = 1;
10828: }
10829: }
10830: next unless($userallowed);
10831: }
10832: my $startreserve = $slots{$slot}->{'startreserve'};
10833: my $endreserve = $slots{$slot}->{'endreserve'};
10834: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10835: my $uniqueperiod;
10836: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10837: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10838: }
1.1040 raeburn 10839: if (($startreserve < $now) &&
10840: (!$endreserve || $endreserve > $now)) {
10841: my $lastres = $endreserve;
10842: if (!$lastres) {
10843: $lastres = $slots{$slot}->{'starttime'};
10844: }
10845: $reservable_now{$slot} = {
10846: symb => $symb,
1.1075.2.104 raeburn 10847: endreserve => $lastres,
10848: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10849: };
10850: } elsif (($startreserve > $now) &&
10851: (!$endreserve || $endreserve > $startreserve)) {
10852: $future_reservable{$slot} = {
10853: symb => $symb,
1.1075.2.104 raeburn 10854: startreserve => $startreserve,
10855: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10856: };
10857: }
10858: }
10859: }
10860: my @unsorted_reservable = keys(%reservable_now);
10861: if (@unsorted_reservable > 0) {
10862: @sorted_reservable =
10863: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10864: }
10865: my @unsorted_future = keys(%future_reservable);
10866: if (@unsorted_future > 0) {
10867: @sorted_future =
10868: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10869: }
10870: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10871: }
1.780 raeburn 10872:
10873: =pod
10874:
1.1057 foxr 10875: =back
10876:
1.549 albertel 10877: =head1 HTTP Helpers
10878:
10879: =over 4
10880:
1.648 raeburn 10881: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10882:
1.258 albertel 10883: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10884: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10885: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10886:
10887: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10888: $possible_names is an ref to an array of form element names. As an example:
10889: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10890: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10891:
10892: =cut
1.1 albertel 10893:
1.6 albertel 10894: sub get_unprocessed_cgi {
1.25 albertel 10895: my ($query,$possible_names)= @_;
1.26 matthew 10896: # $Apache::lonxml::debug=1;
1.356 albertel 10897: foreach my $pair (split(/&/,$query)) {
10898: my ($name, $value) = split(/=/,$pair);
1.369 www 10899: $name = &unescape($name);
1.25 albertel 10900: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10901: $value =~ tr/+/ /;
10902: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10903: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10904: }
1.16 harris41 10905: }
1.6 albertel 10906: }
10907:
1.112 bowersj2 10908: =pod
10909:
1.648 raeburn 10910: =item * &cacheheader()
1.112 bowersj2 10911:
10912: returns cache-controlling header code
10913:
10914: =cut
10915:
1.7 albertel 10916: sub cacheheader {
1.258 albertel 10917: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10918: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10919: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10920: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10921: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10922: return $output;
1.7 albertel 10923: }
10924:
1.112 bowersj2 10925: =pod
10926:
1.648 raeburn 10927: =item * &no_cache($r)
1.112 bowersj2 10928:
10929: specifies header code to not have cache
10930:
10931: =cut
10932:
1.9 albertel 10933: sub no_cache {
1.216 albertel 10934: my ($r) = @_;
10935: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10936: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10937: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10938: $r->no_cache(1);
10939: $r->header_out("Expires" => $date);
10940: $r->header_out("Pragma" => "no-cache");
1.123 www 10941: }
10942:
10943: sub content_type {
1.181 albertel 10944: my ($r,$type,$charset) = @_;
1.299 foxr 10945: if ($r) {
10946: # Note that printout.pl calls this with undef for $r.
10947: &no_cache($r);
10948: }
1.258 albertel 10949: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10950: unless ($charset) {
10951: $charset=&Apache::lonlocal::current_encoding;
10952: }
10953: if ($charset) { $type.='; charset='.$charset; }
10954: if ($r) {
10955: $r->content_type($type);
10956: } else {
10957: print("Content-type: $type\n\n");
10958: }
1.9 albertel 10959: }
1.25 albertel 10960:
1.112 bowersj2 10961: =pod
10962:
1.648 raeburn 10963: =item * &add_to_env($name,$value)
1.112 bowersj2 10964:
1.258 albertel 10965: adds $name to the %env hash with value
1.112 bowersj2 10966: $value, if $name already exists, the entry is converted to an array
10967: reference and $value is added to the array.
10968:
10969: =cut
10970:
1.25 albertel 10971: sub add_to_env {
10972: my ($name,$value)=@_;
1.258 albertel 10973: if (defined($env{$name})) {
10974: if (ref($env{$name})) {
1.25 albertel 10975: #already have multiple values
1.258 albertel 10976: push(@{ $env{$name} },$value);
1.25 albertel 10977: } else {
10978: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10979: my $first=$env{$name};
10980: undef($env{$name});
10981: push(@{ $env{$name} },$first,$value);
1.25 albertel 10982: }
10983: } else {
1.258 albertel 10984: $env{$name}=$value;
1.25 albertel 10985: }
1.31 albertel 10986: }
1.149 albertel 10987:
10988: =pod
10989:
1.648 raeburn 10990: =item * &get_env_multiple($name)
1.149 albertel 10991:
1.258 albertel 10992: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10993: values may be defined and end up as an array ref.
10994:
10995: returns an array of values
10996:
10997: =cut
10998:
10999: sub get_env_multiple {
11000: my ($name) = @_;
11001: my @values;
1.258 albertel 11002: if (defined($env{$name})) {
1.149 albertel 11003: # exists is it an array
1.258 albertel 11004: if (ref($env{$name})) {
11005: @values=@{ $env{$name} };
1.149 albertel 11006: } else {
1.258 albertel 11007: $values[0]=$env{$name};
1.149 albertel 11008: }
11009: }
11010: return(@values);
11011: }
11012:
1.660 raeburn 11013: sub ask_for_embedded_content {
11014: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11015: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 11016: %currsubfile,%unused,$rem);
1.1071 raeburn 11017: my $counter = 0;
11018: my $numnew = 0;
1.987 raeburn 11019: my $numremref = 0;
11020: my $numinvalid = 0;
11021: my $numpathchg = 0;
11022: my $numexisting = 0;
1.1071 raeburn 11023: my $numunused = 0;
11024: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 11025: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11026: my $heading = &mt('Upload embedded files');
11027: my $buttontext = &mt('Upload');
11028:
1.1075.2.11 raeburn 11029: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 11030: if ($actionurl eq '/adm/dependencies') {
11031: $navmap = Apache::lonnavmaps::navmap->new();
11032: }
11033: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11034: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 11035: }
1.1075.2.35 raeburn 11036: if (($actionurl eq '/adm/portfolio') ||
11037: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11038: my $current_path='/';
11039: if ($env{'form.currentpath'}) {
11040: $current_path = $env{'form.currentpath'};
11041: }
11042: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 11043: $udom = $cdom;
11044: $uname = $cnum;
1.984 raeburn 11045: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11046: } else {
11047: $udom = $env{'user.domain'};
11048: $uname = $env{'user.name'};
11049: $url = '/userfiles/portfolio';
11050: }
1.987 raeburn 11051: $toplevel = $url.'/';
1.984 raeburn 11052: $url .= $current_path;
11053: $getpropath = 1;
1.987 raeburn 11054: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11055: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11056: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11057: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11058: $toplevel = $url;
1.984 raeburn 11059: if ($rest ne '') {
1.987 raeburn 11060: $url .= $rest;
11061: }
11062: } elsif ($actionurl eq '/adm/coursedocs') {
11063: if (ref($args) eq 'HASH') {
1.1071 raeburn 11064: $url = $args->{'docs_url'};
11065: $toplevel = $url;
1.1075.2.11 raeburn 11066: if ($args->{'context'} eq 'paste') {
11067: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11068: ($path) =
11069: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11070: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11071: $fileloc =~ s{^/}{};
11072: }
1.1071 raeburn 11073: }
11074: } elsif ($actionurl eq '/adm/dependencies') {
11075: if ($env{'request.course.id'} ne '') {
11076: if (ref($args) eq 'HASH') {
11077: $url = $args->{'docs_url'};
11078: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 11079: $toplevel = $url;
11080: unless ($toplevel =~ m{^/}) {
11081: $toplevel = "/$url";
11082: }
1.1075.2.11 raeburn 11083: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 11084: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11085: $path = $1;
11086: } else {
11087: ($path) =
11088: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11089: }
1.1075.2.79 raeburn 11090: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11091: $fileloc = $toplevel;
11092: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11093: my ($udom,$uname,$fname) =
11094: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11095: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11096: } else {
11097: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11098: }
1.1071 raeburn 11099: $fileloc =~ s{^/}{};
11100: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11101: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11102: }
1.987 raeburn 11103: }
1.1075.2.35 raeburn 11104: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11105: $udom = $cdom;
11106: $uname = $cnum;
11107: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11108: $toplevel = $url;
11109: $path = $url;
11110: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11111: $fileloc =~ s{^/}{};
11112: }
11113: foreach my $file (keys(%{$allfiles})) {
11114: my $embed_file;
11115: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11116: $embed_file = $1;
11117: } else {
11118: $embed_file = $file;
11119: }
1.1075.2.55 raeburn 11120: my ($absolutepath,$cleaned_file);
11121: if ($embed_file =~ m{^\w+://}) {
11122: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 11123: $newfiles{$cleaned_file} = 1;
11124: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11125: } else {
1.1075.2.55 raeburn 11126: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11127: if ($embed_file =~ m{^/}) {
11128: $absolutepath = $embed_file;
11129: }
1.1075.2.47 raeburn 11130: if ($cleaned_file =~ m{/}) {
11131: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11132: $path = &check_for_traversal($path,$url,$toplevel);
11133: my $item = $fname;
11134: if ($path ne '') {
11135: $item = $path.'/'.$fname;
11136: $subdependencies{$path}{$fname} = 1;
11137: } else {
11138: $dependencies{$item} = 1;
11139: }
11140: if ($absolutepath) {
11141: $mapping{$item} = $absolutepath;
11142: } else {
11143: $mapping{$item} = $embed_file;
11144: }
11145: } else {
11146: $dependencies{$embed_file} = 1;
11147: if ($absolutepath) {
1.1075.2.47 raeburn 11148: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11149: } else {
1.1075.2.47 raeburn 11150: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11151: }
11152: }
1.984 raeburn 11153: }
11154: }
1.1071 raeburn 11155: my $dirptr = 16384;
1.984 raeburn 11156: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11157: $currsubfile{$path} = {};
1.1075.2.35 raeburn 11158: if (($actionurl eq '/adm/portfolio') ||
11159: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11160: my ($sublistref,$listerror) =
11161: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11162: if (ref($sublistref) eq 'ARRAY') {
11163: foreach my $line (@{$sublistref}) {
11164: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11165: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11166: }
1.984 raeburn 11167: }
1.987 raeburn 11168: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11169: if (opendir(my $dir,$url.'/'.$path)) {
11170: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11171: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11172: }
1.1075.2.11 raeburn 11173: } elsif (($actionurl eq '/adm/dependencies') ||
11174: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11175: ($args->{'context'} eq 'paste')) ||
11176: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11177: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 11178: my $dir;
11179: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11180: $dir = $fileloc;
11181: } else {
11182: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11183: }
1.1071 raeburn 11184: if ($dir ne '') {
11185: my ($sublistref,$listerror) =
11186: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11187: if (ref($sublistref) eq 'ARRAY') {
11188: foreach my $line (@{$sublistref}) {
11189: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11190: undef,$mtime)=split(/\&/,$line,12);
11191: unless (($testdir&$dirptr) ||
11192: ($file_name =~ /^\.\.?$/)) {
11193: $currsubfile{$path}{$file_name} = [$size,$mtime];
11194: }
11195: }
11196: }
11197: }
1.984 raeburn 11198: }
11199: }
11200: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11201: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11202: my $item = $path.'/'.$file;
11203: unless ($mapping{$item} eq $item) {
11204: $pathchanges{$item} = 1;
11205: }
11206: $existing{$item} = 1;
11207: $numexisting ++;
11208: } else {
11209: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11210: }
11211: }
1.1071 raeburn 11212: if ($actionurl eq '/adm/dependencies') {
11213: foreach my $path (keys(%currsubfile)) {
11214: if (ref($currsubfile{$path}) eq 'HASH') {
11215: foreach my $file (keys(%{$currsubfile{$path}})) {
11216: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 11217: next if (($rem ne '') &&
11218: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11219: (ref($navmap) &&
11220: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11221: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11222: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11223: $unused{$path.'/'.$file} = 1;
11224: }
11225: }
11226: }
11227: }
11228: }
1.984 raeburn 11229: }
1.987 raeburn 11230: my %currfile;
1.1075.2.35 raeburn 11231: if (($actionurl eq '/adm/portfolio') ||
11232: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11233: my ($dirlistref,$listerror) =
11234: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11235: if (ref($dirlistref) eq 'ARRAY') {
11236: foreach my $line (@{$dirlistref}) {
11237: my ($file_name,$rest) = split(/\&/,$line,2);
11238: $currfile{$file_name} = 1;
11239: }
1.984 raeburn 11240: }
1.987 raeburn 11241: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11242: if (opendir(my $dir,$url)) {
1.987 raeburn 11243: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11244: map {$currfile{$_} = 1;} @dir_list;
11245: }
1.1075.2.11 raeburn 11246: } elsif (($actionurl eq '/adm/dependencies') ||
11247: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11248: ($args->{'context'} eq 'paste')) ||
11249: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11250: if ($env{'request.course.id'} ne '') {
11251: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11252: if ($dir ne '') {
11253: my ($dirlistref,$listerror) =
11254: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11255: if (ref($dirlistref) eq 'ARRAY') {
11256: foreach my $line (@{$dirlistref}) {
11257: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11258: $size,undef,$mtime)=split(/\&/,$line,12);
11259: unless (($testdir&$dirptr) ||
11260: ($file_name =~ /^\.\.?$/)) {
11261: $currfile{$file_name} = [$size,$mtime];
11262: }
11263: }
11264: }
11265: }
11266: }
1.984 raeburn 11267: }
11268: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11269: if (exists($currfile{$file})) {
1.987 raeburn 11270: unless ($mapping{$file} eq $file) {
11271: $pathchanges{$file} = 1;
11272: }
11273: $existing{$file} = 1;
11274: $numexisting ++;
11275: } else {
1.984 raeburn 11276: $newfiles{$file} = 1;
11277: }
11278: }
1.1071 raeburn 11279: foreach my $file (keys(%currfile)) {
11280: unless (($file eq $filename) ||
11281: ($file eq $filename.'.bak') ||
11282: ($dependencies{$file})) {
1.1075.2.11 raeburn 11283: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 11284: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11285: next if (($rem ne '') &&
11286: (($env{"httpref.$rem".$file} ne '') ||
11287: (ref($navmap) &&
11288: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11289: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11290: ($navmap->getResourceByUrl($rem.$1)))))));
11291: }
1.1075.2.11 raeburn 11292: }
1.1071 raeburn 11293: $unused{$file} = 1;
11294: }
11295: }
1.1075.2.11 raeburn 11296: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11297: ($args->{'context'} eq 'paste')) {
11298: $counter = scalar(keys(%existing));
11299: $numpathchg = scalar(keys(%pathchanges));
11300: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 11301: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11302: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11303: $counter = scalar(keys(%existing));
11304: $numpathchg = scalar(keys(%pathchanges));
11305: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 11306: }
1.984 raeburn 11307: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11308: if ($actionurl eq '/adm/dependencies') {
11309: next if ($embed_file =~ m{^\w+://});
11310: }
1.660 raeburn 11311: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11312: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11313: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11314: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 11315: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11316: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11317: }
1.1075.2.35 raeburn 11318: $upload_output .= '</td>';
1.1071 raeburn 11319: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 11320: $upload_output.='<td align="right">'.
11321: '<span class="LC_info LC_fontsize_medium">'.
11322: &mt("URL points to web address").'</span>';
1.987 raeburn 11323: $numremref++;
1.660 raeburn 11324: } elsif ($args->{'error_on_invalid_names'}
11325: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 11326: $upload_output.='<td align="right"><span class="LC_warning">'.
11327: &mt('Invalid characters').'</span>';
1.987 raeburn 11328: $numinvalid++;
1.660 raeburn 11329: } else {
1.1075.2.35 raeburn 11330: $upload_output .= '<td>'.
11331: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11332: $embed_file,\%mapping,
1.1071 raeburn 11333: $allfiles,$codebase,'upload');
11334: $counter ++;
11335: $numnew ++;
1.987 raeburn 11336: }
11337: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11338: }
11339: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11340: if ($actionurl eq '/adm/dependencies') {
11341: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11342: $modify_output .= &start_data_table_row().
11343: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11344: '<img src="'.&icon($embed_file).'" border="0" />'.
11345: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11346: '<td>'.$size.'</td>'.
11347: '<td>'.$mtime.'</td>'.
11348: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11349: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11350: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11351: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11352: &embedded_file_element('upload_embedded',$counter,
11353: $embed_file,\%mapping,
11354: $allfiles,$codebase,'modify').
11355: '</div></td>'.
11356: &end_data_table_row()."\n";
11357: $counter ++;
11358: } else {
11359: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11360: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11361: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11362: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11363: &Apache::loncommon::end_data_table_row()."\n";
11364: }
11365: }
11366: my $delidx = $counter;
11367: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11368: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11369: $delete_output .= &start_data_table_row().
11370: '<td><img src="'.&icon($oldfile).'" />'.
11371: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11372: '<td>'.$size.'</td>'.
11373: '<td>'.$mtime.'</td>'.
11374: '<td><label><input type="checkbox" name="del_upload_dep" '.
11375: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11376: &embedded_file_element('upload_embedded',$delidx,
11377: $oldfile,\%mapping,$allfiles,
11378: $codebase,'delete').'</td>'.
11379: &end_data_table_row()."\n";
11380: $numunused ++;
11381: $delidx ++;
1.987 raeburn 11382: }
11383: if ($upload_output) {
11384: $upload_output = &start_data_table().
11385: $upload_output.
11386: &end_data_table()."\n";
11387: }
1.1071 raeburn 11388: if ($modify_output) {
11389: $modify_output = &start_data_table().
11390: &start_data_table_header_row().
11391: '<th>'.&mt('File').'</th>'.
11392: '<th>'.&mt('Size (KB)').'</th>'.
11393: '<th>'.&mt('Modified').'</th>'.
11394: '<th>'.&mt('Upload replacement?').'</th>'.
11395: &end_data_table_header_row().
11396: $modify_output.
11397: &end_data_table()."\n";
11398: }
11399: if ($delete_output) {
11400: $delete_output = &start_data_table().
11401: &start_data_table_header_row().
11402: '<th>'.&mt('File').'</th>'.
11403: '<th>'.&mt('Size (KB)').'</th>'.
11404: '<th>'.&mt('Modified').'</th>'.
11405: '<th>'.&mt('Delete?').'</th>'.
11406: &end_data_table_header_row().
11407: $delete_output.
11408: &end_data_table()."\n";
11409: }
1.987 raeburn 11410: my $applies = 0;
11411: if ($numremref) {
11412: $applies ++;
11413: }
11414: if ($numinvalid) {
11415: $applies ++;
11416: }
11417: if ($numexisting) {
11418: $applies ++;
11419: }
1.1071 raeburn 11420: if ($counter || $numunused) {
1.987 raeburn 11421: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11422: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11423: $state.'<h3>'.$heading.'</h3>';
11424: if ($actionurl eq '/adm/dependencies') {
11425: if ($numnew) {
11426: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11427: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11428: $upload_output.'<br />'."\n";
11429: }
11430: if ($numexisting) {
11431: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11432: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11433: $modify_output.'<br />'."\n";
11434: $buttontext = &mt('Save changes');
11435: }
11436: if ($numunused) {
11437: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11438: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11439: $delete_output.'<br />'."\n";
11440: $buttontext = &mt('Save changes');
11441: }
11442: } else {
11443: $output .= $upload_output.'<br />'."\n";
11444: }
11445: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11446: $counter.'" />'."\n";
11447: if ($actionurl eq '/adm/dependencies') {
11448: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11449: $numnew.'" />'."\n";
11450: } elsif ($actionurl eq '') {
1.987 raeburn 11451: $output .= '<input type="hidden" name="phase" value="three" />';
11452: }
11453: } elsif ($applies) {
11454: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11455: if ($applies > 1) {
11456: $output .=
1.1075.2.35 raeburn 11457: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11458: if ($numremref) {
11459: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11460: }
11461: if ($numinvalid) {
11462: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11463: }
11464: if ($numexisting) {
11465: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11466: }
11467: $output .= '</ul><br />';
11468: } elsif ($numremref) {
11469: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11470: } elsif ($numinvalid) {
11471: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11472: } elsif ($numexisting) {
11473: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11474: }
11475: $output .= $upload_output.'<br />';
11476: }
11477: my ($pathchange_output,$chgcount);
1.1071 raeburn 11478: $chgcount = $counter;
1.987 raeburn 11479: if (keys(%pathchanges) > 0) {
11480: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11481: if ($counter) {
1.987 raeburn 11482: $output .= &embedded_file_element('pathchange',$chgcount,
11483: $embed_file,\%mapping,
1.1071 raeburn 11484: $allfiles,$codebase,'change');
1.987 raeburn 11485: } else {
11486: $pathchange_output .=
11487: &start_data_table_row().
11488: '<td><input type ="checkbox" name="namechange" value="'.
11489: $chgcount.'" checked="checked" /></td>'.
11490: '<td>'.$mapping{$embed_file}.'</td>'.
11491: '<td>'.$embed_file.
11492: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11493: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11494: '</td>'.&end_data_table_row();
1.660 raeburn 11495: }
1.987 raeburn 11496: $numpathchg ++;
11497: $chgcount ++;
1.660 raeburn 11498: }
11499: }
1.1075.2.35 raeburn 11500: if (($counter) || ($numunused)) {
1.987 raeburn 11501: if ($numpathchg) {
11502: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11503: $numpathchg.'" />'."\n";
11504: }
11505: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11506: ($actionurl eq '/adm/imsimport')) {
11507: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11508: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11509: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11510: } elsif ($actionurl eq '/adm/dependencies') {
11511: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11512: }
1.1075.2.35 raeburn 11513: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11514: } elsif ($numpathchg) {
11515: my %pathchange = ();
11516: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11517: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11518: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11519: }
1.987 raeburn 11520: }
1.1071 raeburn 11521: return ($output,$counter,$numpathchg);
1.987 raeburn 11522: }
11523:
1.1075.2.47 raeburn 11524: =pod
11525:
11526: =item * clean_path($name)
11527:
11528: Performs clean-up of directories, subdirectories and filename in an
11529: embedded object, referenced in an HTML file which is being uploaded
11530: to a course or portfolio, where
11531: "Upload embedded images/multimedia files if HTML file" checkbox was
11532: checked.
11533:
11534: Clean-up is similar to replacements in lonnet::clean_filename()
11535: except each / between sub-directory and next level is preserved.
11536:
11537: =cut
11538:
11539: sub clean_path {
11540: my ($embed_file) = @_;
11541: $embed_file =~s{^/+}{};
11542: my @contents;
11543: if ($embed_file =~ m{/}) {
11544: @contents = split(/\//,$embed_file);
11545: } else {
11546: @contents = ($embed_file);
11547: }
11548: my $lastidx = scalar(@contents)-1;
11549: for (my $i=0; $i<=$lastidx; $i++) {
11550: $contents[$i]=~s{\\}{/}g;
11551: $contents[$i]=~s/\s+/\_/g;
11552: $contents[$i]=~s{[^/\w\.\-]}{}g;
11553: if ($i == $lastidx) {
11554: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11555: }
11556: }
11557: if ($lastidx > 0) {
11558: return join('/',@contents);
11559: } else {
11560: return $contents[0];
11561: }
11562: }
11563:
1.987 raeburn 11564: sub embedded_file_element {
1.1071 raeburn 11565: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11566: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11567: (ref($codebase) eq 'HASH'));
11568: my $output;
1.1071 raeburn 11569: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11570: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11571: }
11572: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11573: &escape($embed_file).'" />';
11574: unless (($context eq 'upload_embedded') &&
11575: ($mapping->{$embed_file} eq $embed_file)) {
11576: $output .='
11577: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11578: }
11579: my $attrib;
11580: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11581: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11582: }
11583: $output .=
11584: "\n\t\t".
11585: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11586: $attrib.'" />';
11587: if (exists($codebase->{$mapping->{$embed_file}})) {
11588: $output .=
11589: "\n\t\t".
11590: '<input name="codebase_'.$num.'" type="hidden" value="'.
11591: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11592: }
1.987 raeburn 11593: return $output;
1.660 raeburn 11594: }
11595:
1.1071 raeburn 11596: sub get_dependency_details {
11597: my ($currfile,$currsubfile,$embed_file) = @_;
11598: my ($size,$mtime,$showsize,$showmtime);
11599: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11600: if ($embed_file =~ m{/}) {
11601: my ($path,$fname) = split(/\//,$embed_file);
11602: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11603: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11604: }
11605: } else {
11606: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11607: ($size,$mtime) = @{$currfile->{$embed_file}};
11608: }
11609: }
11610: $showsize = $size/1024.0;
11611: $showsize = sprintf("%.1f",$showsize);
11612: if ($mtime > 0) {
11613: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11614: }
11615: }
11616: return ($showsize,$showmtime);
11617: }
11618:
11619: sub ask_embedded_js {
11620: return <<"END";
11621: <script type="text/javascript"">
11622: // <![CDATA[
11623: function toggleBrowse(counter) {
11624: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11625: var fileid = document.getElementById('embedded_item_'+counter);
11626: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11627: if (chkboxid.checked == true) {
11628: uploaddivid.style.display='block';
11629: } else {
11630: uploaddivid.style.display='none';
11631: fileid.value = '';
11632: }
11633: }
11634: // ]]>
11635: </script>
11636:
11637: END
11638: }
11639:
1.661 raeburn 11640: sub upload_embedded {
11641: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11642: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11643: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11644: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11645: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11646: my $orig_uploaded_filename =
11647: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11648: foreach my $type ('orig','ref','attrib','codebase') {
11649: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11650: $env{'form.embedded_'.$type.'_'.$i} =
11651: &unescape($env{'form.embedded_'.$type.'_'.$i});
11652: }
11653: }
1.661 raeburn 11654: my ($path,$fname) =
11655: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11656: # no path, whole string is fname
11657: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11658: $fname = &Apache::lonnet::clean_filename($fname);
11659: # See if there is anything left
11660: next if ($fname eq '');
11661:
11662: # Check if file already exists as a file or directory.
11663: my ($state,$msg);
11664: if ($context eq 'portfolio') {
11665: my $port_path = $dirpath;
11666: if ($group ne '') {
11667: $port_path = "groups/$group/$port_path";
11668: }
1.987 raeburn 11669: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11670: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11671: $dir_root,$port_path,$disk_quota,
11672: $current_disk_usage,$uname,$udom);
11673: if ($state eq 'will_exceed_quota'
1.984 raeburn 11674: || $state eq 'file_locked') {
1.661 raeburn 11675: $output .= $msg;
11676: next;
11677: }
11678: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11679: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11680: if ($state eq 'exists') {
11681: $output .= $msg;
11682: next;
11683: }
11684: }
11685: # Check if extension is valid
11686: if (($fname =~ /\.(\w+)$/) &&
11687: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11688: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11689: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11690: next;
11691: } elsif (($fname =~ /\.(\w+)$/) &&
11692: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11693: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11694: next;
11695: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11696: $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 11697: next;
11698: }
11699: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11700: my $subdir = $path;
11701: $subdir =~ s{/+$}{};
1.661 raeburn 11702: if ($context eq 'portfolio') {
1.984 raeburn 11703: my $result;
11704: if ($state eq 'existingfile') {
11705: $result=
11706: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11707: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11708: } else {
1.984 raeburn 11709: $result=
11710: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11711: $dirpath.
1.1075.2.35 raeburn 11712: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11713: if ($result !~ m|^/uploaded/|) {
11714: $output .= '<span class="LC_error">'
11715: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11716: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11717: .'</span><br />';
11718: next;
11719: } else {
1.987 raeburn 11720: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11721: $path.$fname.'</span>').'<br />';
1.984 raeburn 11722: }
1.661 raeburn 11723: }
1.1075.2.35 raeburn 11724: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11725: my $extendedsubdir = $dirpath.'/'.$subdir;
11726: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11727: my $result =
1.1075.2.35 raeburn 11728: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11729: if ($result !~ m|^/uploaded/|) {
11730: $output .= '<span class="LC_error">'
11731: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11732: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11733: .'</span><br />';
11734: next;
11735: } else {
11736: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11737: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11738: if ($context eq 'syllabus') {
11739: &Apache::lonnet::make_public_indefinitely($result);
11740: }
1.987 raeburn 11741: }
1.661 raeburn 11742: } else {
11743: # Save the file
11744: my $target = $env{'form.embedded_item_'.$i};
11745: my $fullpath = $dir_root.$dirpath.'/'.$path;
11746: my $dest = $fullpath.$fname;
11747: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11748: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11749: my $count;
11750: my $filepath = $dir_root;
1.1027 raeburn 11751: foreach my $subdir (@parts) {
11752: $filepath .= "/$subdir";
11753: if (!-e $filepath) {
1.661 raeburn 11754: mkdir($filepath,0770);
11755: }
11756: }
11757: my $fh;
11758: if (!open($fh,'>'.$dest)) {
11759: &Apache::lonnet::logthis('Failed to create '.$dest);
11760: $output .= '<span class="LC_error">'.
1.1071 raeburn 11761: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11762: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11763: '</span><br />';
11764: } else {
11765: if (!print $fh $env{'form.embedded_item_'.$i}) {
11766: &Apache::lonnet::logthis('Failed to write to '.$dest);
11767: $output .= '<span class="LC_error">'.
1.1071 raeburn 11768: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11769: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11770: '</span><br />';
11771: } else {
1.987 raeburn 11772: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11773: $url.'</span>').'<br />';
11774: unless ($context eq 'testbank') {
11775: $footer .= &mt('View embedded file: [_1]',
11776: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11777: }
11778: }
11779: close($fh);
11780: }
11781: }
11782: if ($env{'form.embedded_ref_'.$i}) {
11783: $pathchange{$i} = 1;
11784: }
11785: }
11786: if ($output) {
11787: $output = '<p>'.$output.'</p>';
11788: }
11789: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11790: $returnflag = 'ok';
1.1071 raeburn 11791: my $numpathchgs = scalar(keys(%pathchange));
11792: if ($numpathchgs > 0) {
1.987 raeburn 11793: if ($context eq 'portfolio') {
11794: $output .= '<p>'.&mt('or').'</p>';
11795: } elsif ($context eq 'testbank') {
1.1071 raeburn 11796: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11797: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11798: $returnflag = 'modify_orightml';
11799: }
11800: }
1.1071 raeburn 11801: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11802: }
11803:
11804: sub modify_html_form {
11805: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11806: my $end = 0;
11807: my $modifyform;
11808: if ($context eq 'upload_embedded') {
11809: return unless (ref($pathchange) eq 'HASH');
11810: if ($env{'form.number_embedded_items'}) {
11811: $end += $env{'form.number_embedded_items'};
11812: }
11813: if ($env{'form.number_pathchange_items'}) {
11814: $end += $env{'form.number_pathchange_items'};
11815: }
11816: if ($end) {
11817: for (my $i=0; $i<$end; $i++) {
11818: if ($i < $env{'form.number_embedded_items'}) {
11819: next unless($pathchange->{$i});
11820: }
11821: $modifyform .=
11822: &start_data_table_row().
11823: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11824: 'checked="checked" /></td>'.
11825: '<td>'.$env{'form.embedded_ref_'.$i}.
11826: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11827: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11828: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11829: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11830: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11831: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11832: '<td>'.$env{'form.embedded_orig_'.$i}.
11833: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11834: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11835: &end_data_table_row();
1.1071 raeburn 11836: }
1.987 raeburn 11837: }
11838: } else {
11839: $modifyform = $pathchgtable;
11840: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11841: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11842: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11843: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11844: }
11845: }
11846: if ($modifyform) {
1.1071 raeburn 11847: if ($actionurl eq '/adm/dependencies') {
11848: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11849: }
1.987 raeburn 11850: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11851: '<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".
11852: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11853: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11854: '</ol></p>'."\n".'<p>'.
11855: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11856: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11857: &start_data_table()."\n".
11858: &start_data_table_header_row().
11859: '<th>'.&mt('Change?').'</th>'.
11860: '<th>'.&mt('Current reference').'</th>'.
11861: '<th>'.&mt('Required reference').'</th>'.
11862: &end_data_table_header_row()."\n".
11863: $modifyform.
11864: &end_data_table().'<br />'."\n".$hiddenstate.
11865: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11866: '</form>'."\n";
11867: }
11868: return;
11869: }
11870:
11871: sub modify_html_refs {
1.1075.2.35 raeburn 11872: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11873: my $container;
11874: if ($context eq 'portfolio') {
11875: $container = $env{'form.container'};
11876: } elsif ($context eq 'coursedoc') {
11877: $container = $env{'form.primaryurl'};
1.1071 raeburn 11878: } elsif ($context eq 'manage_dependencies') {
11879: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11880: $container = "/$container";
1.1075.2.35 raeburn 11881: } elsif ($context eq 'syllabus') {
11882: $container = $url;
1.987 raeburn 11883: } else {
1.1027 raeburn 11884: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11885: }
11886: my (%allfiles,%codebase,$output,$content);
11887: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11888: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11889: if (wantarray) {
11890: return ('',0,0);
11891: } else {
11892: return;
11893: }
11894: }
11895: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11896: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11897: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11898: if (wantarray) {
11899: return ('',0,0);
11900: } else {
11901: return;
11902: }
11903: }
1.987 raeburn 11904: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11905: if ($content eq '-1') {
11906: if (wantarray) {
11907: return ('',0,0);
11908: } else {
11909: return;
11910: }
11911: }
1.987 raeburn 11912: } else {
1.1071 raeburn 11913: unless ($container =~ /^\Q$dir_root\E/) {
11914: if (wantarray) {
11915: return ('',0,0);
11916: } else {
11917: return;
11918: }
11919: }
1.1075.2.128 raeburn 11920: if (open(my $fh,'<',$container)) {
1.987 raeburn 11921: $content = join('', <$fh>);
11922: close($fh);
11923: } else {
1.1071 raeburn 11924: if (wantarray) {
11925: return ('',0,0);
11926: } else {
11927: return;
11928: }
1.987 raeburn 11929: }
11930: }
11931: my ($count,$codebasecount) = (0,0);
11932: my $mm = new File::MMagic;
11933: my $mime_type = $mm->checktype_contents($content);
11934: if ($mime_type eq 'text/html') {
11935: my $parse_result =
11936: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11937: \%codebase,\$content);
11938: if ($parse_result eq 'ok') {
11939: foreach my $i (@changes) {
11940: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11941: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11942: if ($allfiles{$ref}) {
11943: my $newname = $orig;
11944: my ($attrib_regexp,$codebase);
1.1006 raeburn 11945: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11946: if ($attrib_regexp =~ /:/) {
11947: $attrib_regexp =~ s/\:/|/g;
11948: }
11949: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11950: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11951: $count += $numchg;
1.1075.2.35 raeburn 11952: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11953: delete($allfiles{$ref});
1.987 raeburn 11954: }
11955: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11956: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11957: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11958: $codebasecount ++;
11959: }
11960: }
11961: }
1.1075.2.35 raeburn 11962: my $skiprewrites;
1.987 raeburn 11963: if ($count || $codebasecount) {
11964: my $saveresult;
1.1071 raeburn 11965: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11966: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11967: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11968: if ($url eq $container) {
11969: my ($fname) = ($container =~ m{/([^/]+)$});
11970: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11971: $count,'<span class="LC_filename">'.
1.1071 raeburn 11972: $fname.'</span>').'</p>';
1.987 raeburn 11973: } else {
11974: $output = '<p class="LC_error">'.
11975: &mt('Error: update failed for: [_1].',
11976: '<span class="LC_filename">'.
11977: $container.'</span>').'</p>';
11978: }
1.1075.2.35 raeburn 11979: if ($context eq 'syllabus') {
11980: unless ($saveresult eq 'ok') {
11981: $skiprewrites = 1;
11982: }
11983: }
1.987 raeburn 11984: } else {
1.1075.2.128 raeburn 11985: if (open(my $fh,'>',$container)) {
1.987 raeburn 11986: print $fh $content;
11987: close($fh);
11988: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11989: $count,'<span class="LC_filename">'.
11990: $container.'</span>').'</p>';
1.661 raeburn 11991: } else {
1.987 raeburn 11992: $output = '<p class="LC_error">'.
11993: &mt('Error: could not update [_1].',
11994: '<span class="LC_filename">'.
11995: $container.'</span>').'</p>';
1.661 raeburn 11996: }
11997: }
11998: }
1.1075.2.35 raeburn 11999: if (($context eq 'syllabus') && (!$skiprewrites)) {
12000: my ($actionurl,$state);
12001: $actionurl = "/public/$udom/$uname/syllabus";
12002: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12003: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12004: \%codebase,
12005: {'context' => 'rewrites',
12006: 'ignore_remote_references' => 1,});
12007: if (ref($mapping) eq 'HASH') {
12008: my $rewrites = 0;
12009: foreach my $key (keys(%{$mapping})) {
12010: next if ($key =~ m{^https?://});
12011: my $ref = $mapping->{$key};
12012: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12013: my $attrib;
12014: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12015: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12016: }
12017: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12018: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12019: $rewrites += $numchg;
12020: }
12021: }
12022: if ($rewrites) {
12023: my $saveresult;
12024: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12025: if ($url eq $container) {
12026: my ($fname) = ($container =~ m{/([^/]+)$});
12027: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12028: $count,'<span class="LC_filename">'.
12029: $fname.'</span>').'</p>';
12030: } else {
12031: $output .= '<p class="LC_error">'.
12032: &mt('Error: could not update links in [_1].',
12033: '<span class="LC_filename">'.
12034: $container.'</span>').'</p>';
12035:
12036: }
12037: }
12038: }
12039: }
1.987 raeburn 12040: } else {
12041: &logthis('Failed to parse '.$container.
12042: ' to modify references: '.$parse_result);
1.661 raeburn 12043: }
12044: }
1.1071 raeburn 12045: if (wantarray) {
12046: return ($output,$count,$codebasecount);
12047: } else {
12048: return $output;
12049: }
1.661 raeburn 12050: }
12051:
12052: sub check_for_existing {
12053: my ($path,$fname,$element) = @_;
12054: my ($state,$msg);
12055: if (-d $path.'/'.$fname) {
12056: $state = 'exists';
12057: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12058: } elsif (-e $path.'/'.$fname) {
12059: $state = 'exists';
12060: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12061: }
12062: if ($state eq 'exists') {
12063: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12064: }
12065: return ($state,$msg);
12066: }
12067:
12068: sub check_for_upload {
12069: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12070: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12071: my $filesize = length($env{'form.'.$element});
12072: if (!$filesize) {
12073: my $msg = '<span class="LC_error">'.
12074: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12075: '<span class="LC_filename">'.$fname.'</span>',
12076: $filesize).'<br />'.
1.1007 raeburn 12077: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12078: '</span>';
12079: return ('zero_bytes',$msg);
12080: }
12081: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12082: my $getpropath = 1;
1.1021 raeburn 12083: my ($dirlistref,$listerror) =
12084: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12085: my $found_file = 0;
12086: my $locked_file = 0;
1.991 raeburn 12087: my @lockers;
12088: my $navmap;
12089: if ($env{'request.course.id'}) {
12090: $navmap = Apache::lonnavmaps::navmap->new();
12091: }
1.1021 raeburn 12092: if (ref($dirlistref) eq 'ARRAY') {
12093: foreach my $line (@{$dirlistref}) {
12094: my ($file_name,$rest)=split(/\&/,$line,2);
12095: if ($file_name eq $fname){
12096: $file_name = $path.$file_name;
12097: if ($group ne '') {
12098: $file_name = $group.$file_name;
12099: }
12100: $found_file = 1;
12101: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12102: foreach my $lock (@lockers) {
12103: if (ref($lock) eq 'ARRAY') {
12104: my ($symb,$crsid) = @{$lock};
12105: if ($crsid eq $env{'request.course.id'}) {
12106: if (ref($navmap)) {
12107: my $res = $navmap->getBySymb($symb);
12108: foreach my $part (@{$res->parts()}) {
12109: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12110: unless (($slot_status == $res->RESERVED) ||
12111: ($slot_status == $res->RESERVED_LOCATION)) {
12112: $locked_file = 1;
12113: }
1.991 raeburn 12114: }
1.1021 raeburn 12115: } else {
12116: $locked_file = 1;
1.991 raeburn 12117: }
12118: } else {
12119: $locked_file = 1;
12120: }
12121: }
1.1021 raeburn 12122: }
12123: } else {
12124: my @info = split(/\&/,$rest);
12125: my $currsize = $info[6]/1000;
12126: if ($currsize < $filesize) {
12127: my $extra = $filesize - $currsize;
12128: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 12129: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12130: &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 12131: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12132: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12133: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12134: return ('will_exceed_quota',$msg);
12135: }
1.984 raeburn 12136: }
12137: }
1.661 raeburn 12138: }
12139: }
12140: }
12141: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 12142: my $msg = '<p class="LC_warning">'.
12143: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
12144: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12145: return ('will_exceed_quota',$msg);
12146: } elsif ($found_file) {
12147: if ($locked_file) {
1.1075.2.69 raeburn 12148: my $msg = '<p class="LC_warning">';
1.661 raeburn 12149: $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 12150: $msg .= '</p>';
1.661 raeburn 12151: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12152: return ('file_locked',$msg);
12153: } else {
1.1075.2.69 raeburn 12154: my $msg = '<p class="LC_error">';
1.984 raeburn 12155: $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 12156: $msg .= '</p>';
1.984 raeburn 12157: return ('existingfile',$msg);
1.661 raeburn 12158: }
12159: }
12160: }
12161:
1.987 raeburn 12162: sub check_for_traversal {
12163: my ($path,$url,$toplevel) = @_;
12164: my @parts=split(/\//,$path);
12165: my $cleanpath;
12166: my $fullpath = $url;
12167: for (my $i=0;$i<@parts;$i++) {
12168: next if ($parts[$i] eq '.');
12169: if ($parts[$i] eq '..') {
12170: $fullpath =~ s{([^/]+/)$}{};
12171: } else {
12172: $fullpath .= $parts[$i].'/';
12173: }
12174: }
12175: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12176: $cleanpath = $1;
12177: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12178: my $curr_toprel = $1;
12179: my @parts = split(/\//,$curr_toprel);
12180: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12181: my @urlparts = split(/\//,$url_toprel);
12182: my $doubledots;
12183: my $startdiff = -1;
12184: for (my $i=0; $i<@urlparts; $i++) {
12185: if ($startdiff == -1) {
12186: unless ($urlparts[$i] eq $parts[$i]) {
12187: $startdiff = $i;
12188: $doubledots .= '../';
12189: }
12190: } else {
12191: $doubledots .= '../';
12192: }
12193: }
12194: if ($startdiff > -1) {
12195: $cleanpath = $doubledots;
12196: for (my $i=$startdiff; $i<@parts; $i++) {
12197: $cleanpath .= $parts[$i].'/';
12198: }
12199: }
12200: }
12201: $cleanpath =~ s{(/)$}{};
12202: return $cleanpath;
12203: }
1.31 albertel 12204:
1.1053 raeburn 12205: sub is_archive_file {
12206: my ($mimetype) = @_;
12207: if (($mimetype eq 'application/octet-stream') ||
12208: ($mimetype eq 'application/x-stuffit') ||
12209: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12210: return 1;
12211: }
12212: return;
12213: }
12214:
12215: sub decompress_form {
1.1065 raeburn 12216: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12217: my %lt = &Apache::lonlocal::texthash (
12218: this => 'This file is an archive file.',
1.1067 raeburn 12219: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12220: itsc => 'Its contents are as follows:',
1.1053 raeburn 12221: youm => 'You may wish to extract its contents.',
12222: extr => 'Extract contents',
1.1067 raeburn 12223: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12224: proa => 'Process automatically?',
1.1053 raeburn 12225: yes => 'Yes',
12226: no => 'No',
1.1067 raeburn 12227: fold => 'Title for folder containing movie',
12228: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12229: );
1.1065 raeburn 12230: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12231: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12232: my $info = &list_archive_contents($fileloc,\@paths);
12233: if (@paths) {
12234: foreach my $path (@paths) {
12235: $path =~ s{^/}{};
1.1067 raeburn 12236: if ($path =~ m{^([^/]+)/$}) {
12237: $topdir = $1;
12238: }
1.1065 raeburn 12239: if ($path =~ m{^([^/]+)/}) {
12240: $toplevel{$1} = $path;
12241: } else {
12242: $toplevel{$path} = $path;
12243: }
12244: }
12245: }
1.1067 raeburn 12246: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 12247: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12248: "$topdir/media/",
12249: "$topdir/media/$topdir.mp4",
12250: "$topdir/media/FirstFrame.png",
12251: "$topdir/media/player.swf",
12252: "$topdir/media/swfobject.js",
12253: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 12254: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 12255: "$topdir/$topdir.mp4",
12256: "$topdir/$topdir\_config.xml",
12257: "$topdir/$topdir\_controller.swf",
12258: "$topdir/$topdir\_embed.css",
12259: "$topdir/$topdir\_First_Frame.png",
12260: "$topdir/$topdir\_player.html",
12261: "$topdir/$topdir\_Thumbnails.png",
12262: "$topdir/playerProductInstall.swf",
12263: "$topdir/scripts/",
12264: "$topdir/scripts/config_xml.js",
12265: "$topdir/scripts/handlebars.js",
12266: "$topdir/scripts/jquery-1.7.1.min.js",
12267: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12268: "$topdir/scripts/modernizr.js",
12269: "$topdir/scripts/player-min.js",
12270: "$topdir/scripts/swfobject.js",
12271: "$topdir/skins/",
12272: "$topdir/skins/configuration_express.xml",
12273: "$topdir/skins/express_show/",
12274: "$topdir/skins/express_show/player-min.css",
12275: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 12276: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12277: "$topdir/$topdir.mp4",
12278: "$topdir/$topdir\_config.xml",
12279: "$topdir/$topdir\_controller.swf",
12280: "$topdir/$topdir\_embed.css",
12281: "$topdir/$topdir\_First_Frame.png",
12282: "$topdir/$topdir\_player.html",
12283: "$topdir/$topdir\_Thumbnails.png",
12284: "$topdir/playerProductInstall.swf",
12285: "$topdir/scripts/",
12286: "$topdir/scripts/config_xml.js",
12287: "$topdir/scripts/techsmith-smart-player.min.js",
12288: "$topdir/skins/",
12289: "$topdir/skins/configuration_express.xml",
12290: "$topdir/skins/express_show/",
12291: "$topdir/skins/express_show/spritesheet.min.css",
12292: "$topdir/skins/express_show/spritesheet.png",
12293: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 12294: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12295: if (@diffs == 0) {
1.1075.2.59 raeburn 12296: $is_camtasia = 6;
12297: } else {
1.1075.2.81 raeburn 12298: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 12299: if (@diffs == 0) {
12300: $is_camtasia = 8;
1.1075.2.81 raeburn 12301: } else {
12302: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12303: if (@diffs == 0) {
12304: $is_camtasia = 8;
12305: }
1.1075.2.59 raeburn 12306: }
1.1067 raeburn 12307: }
12308: }
12309: my $output;
12310: if ($is_camtasia) {
12311: $output = <<"ENDCAM";
12312: <script type="text/javascript" language="Javascript">
12313: // <![CDATA[
12314:
12315: function camtasiaToggle() {
12316: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12317: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 12318: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12319: document.getElementById('camtasia_titles').style.display='block';
12320: } else {
12321: document.getElementById('camtasia_titles').style.display='none';
12322: }
12323: }
12324: }
12325: return;
12326: }
12327:
12328: // ]]>
12329: </script>
12330: <p>$lt{'camt'}</p>
12331: ENDCAM
1.1065 raeburn 12332: } else {
1.1067 raeburn 12333: $output = '<p>'.$lt{'this'};
12334: if ($info eq '') {
12335: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12336: } else {
12337: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12338: '<div><pre>'.$info.'</pre></div>';
12339: }
1.1065 raeburn 12340: }
1.1067 raeburn 12341: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12342: my $duplicates;
12343: my $num = 0;
12344: if (ref($dirlist) eq 'ARRAY') {
12345: foreach my $item (@{$dirlist}) {
12346: if (ref($item) eq 'ARRAY') {
12347: if (exists($toplevel{$item->[0]})) {
12348: $duplicates .=
12349: &start_data_table_row().
12350: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12351: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12352: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12353: 'value="1" />'.&mt('Yes').'</label>'.
12354: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12355: '<td>'.$item->[0].'</td>';
12356: if ($item->[2]) {
12357: $duplicates .= '<td>'.&mt('Directory').'</td>';
12358: } else {
12359: $duplicates .= '<td>'.&mt('File').'</td>';
12360: }
12361: $duplicates .= '<td>'.$item->[3].'</td>'.
12362: '<td>'.
12363: &Apache::lonlocal::locallocaltime($item->[4]).
12364: '</td>'.
12365: &end_data_table_row();
12366: $num ++;
12367: }
12368: }
12369: }
12370: }
12371: my $itemcount;
12372: if (@paths > 0) {
12373: $itemcount = scalar(@paths);
12374: } else {
12375: $itemcount = 1;
12376: }
1.1067 raeburn 12377: if ($is_camtasia) {
12378: $output .= $lt{'auto'}.'<br />'.
12379: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12380: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12381: $lt{'yes'}.'</label> <label>'.
12382: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12383: $lt{'no'}.'</label></span><br />'.
12384: '<div id="camtasia_titles" style="display:block">'.
12385: &Apache::lonhtmlcommon::start_pick_box().
12386: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12387: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12388: &Apache::lonhtmlcommon::row_closure().
12389: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12390: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12391: &Apache::lonhtmlcommon::row_closure(1).
12392: &Apache::lonhtmlcommon::end_pick_box().
12393: '</div>';
12394: }
1.1065 raeburn 12395: $output .=
12396: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12397: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12398: "\n";
1.1065 raeburn 12399: if ($duplicates ne '') {
12400: $output .= '<p><span class="LC_warning">'.
12401: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12402: &start_data_table().
12403: &start_data_table_header_row().
12404: '<th>'.&mt('Overwrite?').'</th>'.
12405: '<th>'.&mt('Name').'</th>'.
12406: '<th>'.&mt('Type').'</th>'.
12407: '<th>'.&mt('Size').'</th>'.
12408: '<th>'.&mt('Last modified').'</th>'.
12409: &end_data_table_header_row().
12410: $duplicates.
12411: &end_data_table().
12412: '</p>';
12413: }
1.1067 raeburn 12414: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12415: if (ref($hiddenelements) eq 'HASH') {
12416: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12417: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12418: }
12419: }
12420: $output .= <<"END";
1.1067 raeburn 12421: <br />
1.1053 raeburn 12422: <input type="submit" name="decompress" value="$lt{'extr'}" />
12423: </form>
12424: $noextract
12425: END
12426: return $output;
12427: }
12428:
1.1065 raeburn 12429: sub decompression_utility {
12430: my ($program) = @_;
12431: my @utilities = ('tar','gunzip','bunzip2','unzip');
12432: my $location;
12433: if (grep(/^\Q$program\E$/,@utilities)) {
12434: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12435: '/usr/sbin/') {
12436: if (-x $dir.$program) {
12437: $location = $dir.$program;
12438: last;
12439: }
12440: }
12441: }
12442: return $location;
12443: }
12444:
12445: sub list_archive_contents {
12446: my ($file,$pathsref) = @_;
12447: my (@cmd,$output);
12448: my $needsregexp;
12449: if ($file =~ /\.zip$/) {
12450: @cmd = (&decompression_utility('unzip'),"-l");
12451: $needsregexp = 1;
12452: } elsif (($file =~ m/\.tar\.gz$/) ||
12453: ($file =~ /\.tgz$/)) {
12454: @cmd = (&decompression_utility('tar'),"-ztf");
12455: } elsif ($file =~ /\.tar\.bz2$/) {
12456: @cmd = (&decompression_utility('tar'),"-jtf");
12457: } elsif ($file =~ m|\.tar$|) {
12458: @cmd = (&decompression_utility('tar'),"-tf");
12459: }
12460: if (@cmd) {
12461: undef($!);
12462: undef($@);
12463: if (open(my $fh,"-|", @cmd, $file)) {
12464: while (my $line = <$fh>) {
12465: $output .= $line;
12466: chomp($line);
12467: my $item;
12468: if ($needsregexp) {
12469: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12470: } else {
12471: $item = $line;
12472: }
12473: if ($item ne '') {
12474: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12475: push(@{$pathsref},$item);
12476: }
12477: }
12478: }
12479: close($fh);
12480: }
12481: }
12482: return $output;
12483: }
12484:
1.1053 raeburn 12485: sub decompress_uploaded_file {
12486: my ($file,$dir) = @_;
12487: &Apache::lonnet::appenv({'cgi.file' => $file});
12488: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12489: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12490: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12491: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12492: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12493: my $decompressed = $env{'cgi.decompressed'};
12494: &Apache::lonnet::delenv('cgi.file');
12495: &Apache::lonnet::delenv('cgi.dir');
12496: &Apache::lonnet::delenv('cgi.decompressed');
12497: return ($decompressed,$result);
12498: }
12499:
1.1055 raeburn 12500: sub process_decompression {
12501: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12502: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12503: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12504: &mt('Unexpected file path.').'</p>'."\n";
12505: }
12506: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12507: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12508: &mt('Unexpected course context.').'</p>'."\n";
12509: }
12510: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12511: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12512: &mt('Filename contained unexpected characters.').'</p>'."\n";
12513: }
1.1055 raeburn 12514: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12515: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12516: $error = &mt('Filename not a supported archive file type.').
12517: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12518: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12519: } else {
12520: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12521: if ($docuhome eq 'no_host') {
12522: $error = &mt('Could not determine home server for course.');
12523: } else {
12524: my @ids=&Apache::lonnet::current_machine_ids();
12525: my $currdir = "$dir_root/$destination";
12526: if (grep(/^\Q$docuhome\E$/,@ids)) {
12527: $dir = &LONCAPA::propath($docudom,$docuname).
12528: "$dir_root/$destination";
12529: } else {
12530: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12531: "$dir_root/$docudom/$docuname/$destination";
12532: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12533: $error = &mt('Archive file not found.');
12534: }
12535: }
1.1065 raeburn 12536: my (@to_overwrite,@to_skip);
12537: if ($env{'form.archive_overwrite_total'} > 0) {
12538: my $total = $env{'form.archive_overwrite_total'};
12539: for (my $i=0; $i<$total; $i++) {
12540: if ($env{'form.archive_overwrite_'.$i} == 1) {
12541: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12542: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12543: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12544: }
12545: }
12546: }
12547: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12548: my $numoverwrite = scalar(@to_overwrite);
12549: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12550: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12551: } elsif ($dir eq '') {
1.1055 raeburn 12552: $error = &mt('Directory containing archive file unavailable.');
12553: } elsif (!$error) {
1.1065 raeburn 12554: my ($decompressed,$display);
1.1075.2.128 raeburn 12555: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12556: my $tempdir = time.'_'.$$.int(rand(10000));
12557: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12558: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12559: ($decompressed,$display) =
12560: &decompress_uploaded_file($file,"$dir/$tempdir");
12561: foreach my $item (@to_skip) {
12562: if (($item ne '') && ($item !~ /\.\./)) {
12563: if (-f "$dir/$tempdir/$item") {
12564: unlink("$dir/$tempdir/$item");
12565: } elsif (-d "$dir/$tempdir/$item") {
12566: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12567: }
12568: }
12569: }
12570: foreach my $item (@to_overwrite) {
12571: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12572: if (($item ne '') && ($item !~ /\.\./)) {
12573: if (-f "$dir/$item") {
12574: unlink("$dir/$item");
12575: } elsif (-d "$dir/$item") {
12576: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12577: }
12578: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12579: }
1.1065 raeburn 12580: }
12581: }
1.1075.2.128 raeburn 12582: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12583: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12584: }
1.1065 raeburn 12585: }
12586: } else {
12587: ($decompressed,$display) =
12588: &decompress_uploaded_file($file,$dir);
12589: }
1.1055 raeburn 12590: if ($decompressed eq 'ok') {
1.1065 raeburn 12591: $output = '<p class="LC_info">'.
12592: &mt('Files extracted successfully from archive.').
12593: '</p>'."\n";
1.1055 raeburn 12594: my ($warning,$result,@contents);
12595: my ($newdirlistref,$newlisterror) =
12596: &Apache::lonnet::dirlist($currdir,$docudom,
12597: $docuname,1);
12598: my (%is_dir,%changes,@newitems);
12599: my $dirptr = 16384;
1.1065 raeburn 12600: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12601: foreach my $dir_line (@{$newdirlistref}) {
12602: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12603: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12604: push(@newitems,$item);
12605: if ($dirptr&$testdir) {
12606: $is_dir{$item} = 1;
12607: }
12608: $changes{$item} = 1;
12609: }
12610: }
12611: }
12612: if (keys(%changes) > 0) {
12613: foreach my $item (sort(@newitems)) {
12614: if ($changes{$item}) {
12615: push(@contents,$item);
12616: }
12617: }
12618: }
12619: if (@contents > 0) {
1.1067 raeburn 12620: my $wantform;
12621: unless ($env{'form.autoextract_camtasia'}) {
12622: $wantform = 1;
12623: }
1.1056 raeburn 12624: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12625: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12626: $currdir,\%is_dir,
12627: \%children,\%parent,
1.1056 raeburn 12628: \@contents,\%dirorder,
12629: \%titles,$wantform);
1.1055 raeburn 12630: if ($datatable ne '') {
12631: $output .= &archive_options_form('decompressed',$datatable,
12632: $count,$hiddenelem);
1.1065 raeburn 12633: my $startcount = 6;
1.1055 raeburn 12634: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12635: \%titles,\%children);
1.1055 raeburn 12636: }
1.1067 raeburn 12637: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12638: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12639: my %displayed;
12640: my $total = 1;
12641: $env{'form.archive_directory'} = [];
12642: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12643: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12644: $path =~ s{/$}{};
12645: my $item;
12646: if ($path ne '') {
12647: $item = "$path/$titles{$i}";
12648: } else {
12649: $item = $titles{$i};
12650: }
12651: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12652: if ($item eq $contents[0]) {
12653: push(@{$env{'form.archive_directory'}},$i);
12654: $env{'form.archive_'.$i} = 'display';
12655: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12656: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12657: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12658: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12659: $env{'form.archive_'.$i} = 'display';
12660: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12661: $displayed{'web'} = $i;
12662: } else {
1.1075.2.59 raeburn 12663: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12664: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12665: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12666: push(@{$env{'form.archive_directory'}},$i);
12667: }
12668: $env{'form.archive_'.$i} = 'dependency';
12669: }
12670: $total ++;
12671: }
12672: for (my $i=1; $i<$total; $i++) {
12673: next if ($i == $displayed{'web'});
12674: next if ($i == $displayed{'folder'});
12675: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12676: }
12677: $env{'form.phase'} = 'decompress_cleanup';
12678: $env{'form.archivedelete'} = 1;
12679: $env{'form.archive_count'} = $total-1;
12680: $output .=
12681: &process_extracted_files('coursedocs',$docudom,
12682: $docuname,$destination,
12683: $dir_root,$hiddenelem);
12684: }
1.1055 raeburn 12685: } else {
12686: $warning = &mt('No new items extracted from archive file.');
12687: }
12688: } else {
12689: $output = $display;
12690: $error = &mt('An error occurred during extraction from the archive file.');
12691: }
12692: }
12693: }
12694: }
12695: if ($error) {
12696: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12697: $error.'</p>'."\n";
12698: }
12699: if ($warning) {
12700: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12701: }
12702: return $output;
12703: }
12704:
12705: sub get_extracted {
1.1056 raeburn 12706: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12707: $titles,$wantform) = @_;
1.1055 raeburn 12708: my $count = 0;
12709: my $depth = 0;
12710: my $datatable;
1.1056 raeburn 12711: my @hierarchy;
1.1055 raeburn 12712: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12713: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12714: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12715: foreach my $item (@{$contents}) {
12716: $count ++;
1.1056 raeburn 12717: @{$dirorder->{$count}} = @hierarchy;
12718: $titles->{$count} = $item;
1.1055 raeburn 12719: &archive_hierarchy($depth,$count,$parent,$children);
12720: if ($wantform) {
12721: $datatable .= &archive_row($is_dir->{$item},$item,
12722: $currdir,$depth,$count);
12723: }
12724: if ($is_dir->{$item}) {
12725: $depth ++;
1.1056 raeburn 12726: push(@hierarchy,$count);
12727: $parent->{$depth} = $count;
1.1055 raeburn 12728: $datatable .=
12729: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12730: \$depth,\$count,\@hierarchy,$dirorder,
12731: $children,$parent,$titles,$wantform);
1.1055 raeburn 12732: $depth --;
1.1056 raeburn 12733: pop(@hierarchy);
1.1055 raeburn 12734: }
12735: }
12736: return ($count,$datatable);
12737: }
12738:
12739: sub recurse_extracted_archive {
1.1056 raeburn 12740: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12741: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12742: my $result='';
1.1056 raeburn 12743: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12744: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12745: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12746: return $result;
12747: }
12748: my $dirptr = 16384;
12749: my ($newdirlistref,$newlisterror) =
12750: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12751: if (ref($newdirlistref) eq 'ARRAY') {
12752: foreach my $dir_line (@{$newdirlistref}) {
12753: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12754: unless ($item =~ /^\.+$/) {
12755: $$count ++;
1.1056 raeburn 12756: @{$dirorder->{$$count}} = @{$hierarchy};
12757: $titles->{$$count} = $item;
1.1055 raeburn 12758: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12759:
1.1055 raeburn 12760: my $is_dir;
12761: if ($dirptr&$testdir) {
12762: $is_dir = 1;
12763: }
12764: if ($wantform) {
12765: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12766: }
12767: if ($is_dir) {
12768: $$depth ++;
1.1056 raeburn 12769: push(@{$hierarchy},$$count);
12770: $parent->{$$depth} = $$count;
1.1055 raeburn 12771: $result .=
12772: &recurse_extracted_archive("$currdir/$item",$docudom,
12773: $docuname,$depth,$count,
1.1056 raeburn 12774: $hierarchy,$dirorder,$children,
12775: $parent,$titles,$wantform);
1.1055 raeburn 12776: $$depth --;
1.1056 raeburn 12777: pop(@{$hierarchy});
1.1055 raeburn 12778: }
12779: }
12780: }
12781: }
12782: return $result;
12783: }
12784:
12785: sub archive_hierarchy {
12786: my ($depth,$count,$parent,$children) =@_;
12787: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12788: if (exists($parent->{$depth})) {
12789: $children->{$parent->{$depth}} .= $count.':';
12790: }
12791: }
12792: return;
12793: }
12794:
12795: sub archive_row {
12796: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12797: my ($name) = ($item =~ m{([^/]+)$});
12798: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12799: 'display' => 'Add as file',
1.1055 raeburn 12800: 'dependency' => 'Include as dependency',
12801: 'discard' => 'Discard',
12802: );
12803: if ($is_dir) {
1.1059 raeburn 12804: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12805: }
1.1056 raeburn 12806: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12807: my $offset = 0;
1.1055 raeburn 12808: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12809: $offset ++;
1.1065 raeburn 12810: if ($action ne 'display') {
12811: $offset ++;
12812: }
1.1055 raeburn 12813: $output .= '<td><span class="LC_nobreak">'.
12814: '<label><input type="radio" name="archive_'.$count.
12815: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12816: my $text = $choices{$action};
12817: if ($is_dir) {
12818: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12819: if ($action eq 'display') {
1.1059 raeburn 12820: $text = &mt('Add as folder');
1.1055 raeburn 12821: }
1.1056 raeburn 12822: } else {
12823: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12824:
12825: }
12826: $output .= ' /> '.$choices{$action}.'</label></span>';
12827: if ($action eq 'dependency') {
12828: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12829: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12830: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12831: '<option value=""></option>'."\n".
12832: '</select>'."\n".
12833: '</div>';
1.1059 raeburn 12834: } elsif ($action eq 'display') {
12835: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12836: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12837: '</div>';
1.1055 raeburn 12838: }
1.1056 raeburn 12839: $output .= '</td>';
1.1055 raeburn 12840: }
12841: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12842: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12843: for (my $i=0; $i<$depth; $i++) {
12844: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12845: }
12846: if ($is_dir) {
12847: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12848: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12849: } else {
12850: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12851: }
12852: $output .= ' '.$name.'</td>'."\n".
12853: &end_data_table_row();
12854: return $output;
12855: }
12856:
12857: sub archive_options_form {
1.1065 raeburn 12858: my ($form,$display,$count,$hiddenelem) = @_;
12859: my %lt = &Apache::lonlocal::texthash(
12860: perm => 'Permanently remove archive file?',
12861: hows => 'How should each extracted item be incorporated in the course?',
12862: cont => 'Content actions for all',
12863: addf => 'Add as folder/file',
12864: incd => 'Include as dependency for a displayed file',
12865: disc => 'Discard',
12866: no => 'No',
12867: yes => 'Yes',
12868: save => 'Save',
12869: );
12870: my $output = <<"END";
12871: <form name="$form" method="post" action="">
12872: <p><span class="LC_nobreak">$lt{'perm'}
12873: <label>
12874: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12875: </label>
12876:
12877: <label>
12878: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12879: </span>
12880: </p>
12881: <input type="hidden" name="phase" value="decompress_cleanup" />
12882: <br />$lt{'hows'}
12883: <div class="LC_columnSection">
12884: <fieldset>
12885: <legend>$lt{'cont'}</legend>
12886: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12887: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12888: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12889: </fieldset>
12890: </div>
12891: END
12892: return $output.
1.1055 raeburn 12893: &start_data_table()."\n".
1.1065 raeburn 12894: $display."\n".
1.1055 raeburn 12895: &end_data_table()."\n".
12896: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12897: $hiddenelem.
1.1065 raeburn 12898: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12899: '</form>';
12900: }
12901:
12902: sub archive_javascript {
1.1056 raeburn 12903: my ($startcount,$numitems,$titles,$children) = @_;
12904: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12905: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12906: my $scripttag = <<START;
12907: <script type="text/javascript">
12908: // <![CDATA[
12909:
12910: function checkAll(form,prefix) {
12911: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12912: for (var i=0; i < form.elements.length; i++) {
12913: var id = form.elements[i].id;
12914: if ((id != '') && (id != undefined)) {
12915: if (idstr.test(id)) {
12916: if (form.elements[i].type == 'radio') {
12917: form.elements[i].checked = true;
1.1056 raeburn 12918: var nostart = i-$startcount;
1.1059 raeburn 12919: var offset = nostart%7;
12920: var count = (nostart-offset)/7;
1.1056 raeburn 12921: dependencyCheck(form,count,offset);
1.1055 raeburn 12922: }
12923: }
12924: }
12925: }
12926: }
12927:
12928: function propagateCheck(form,count) {
12929: if (count > 0) {
1.1059 raeburn 12930: var startelement = $startcount + ((count-1) * 7);
12931: for (var j=1; j<6; j++) {
12932: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12933: var item = startelement + j;
12934: if (form.elements[item].type == 'radio') {
12935: if (form.elements[item].checked) {
12936: containerCheck(form,count,j);
12937: break;
12938: }
1.1055 raeburn 12939: }
12940: }
12941: }
12942: }
12943: }
12944:
12945: numitems = $numitems
1.1056 raeburn 12946: var titles = new Array(numitems);
12947: var parents = new Array(numitems);
1.1055 raeburn 12948: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12949: parents[i] = new Array;
1.1055 raeburn 12950: }
1.1059 raeburn 12951: var maintitle = '$maintitle';
1.1055 raeburn 12952:
12953: START
12954:
1.1056 raeburn 12955: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12956: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12957: for (my $i=0; $i<@contents; $i ++) {
12958: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12959: }
12960: }
12961:
1.1056 raeburn 12962: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12963: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12964: }
12965:
1.1055 raeburn 12966: $scripttag .= <<END;
12967:
12968: function containerCheck(form,count,offset) {
12969: if (count > 0) {
1.1056 raeburn 12970: dependencyCheck(form,count,offset);
1.1059 raeburn 12971: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12972: form.elements[item].checked = true;
12973: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12974: if (parents[count].length > 0) {
12975: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12976: containerCheck(form,parents[count][j],offset);
12977: }
12978: }
12979: }
12980: }
12981: }
12982:
12983: function dependencyCheck(form,count,offset) {
12984: if (count > 0) {
1.1059 raeburn 12985: var chosen = (offset+$startcount)+7*(count-1);
12986: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12987: var currtype = form.elements[depitem].type;
12988: if (form.elements[chosen].value == 'dependency') {
12989: document.getElementById('arc_depon_'+count).style.display='block';
12990: form.elements[depitem].options.length = 0;
12991: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12992: for (var i=1; i<=numitems; i++) {
12993: if (i == count) {
12994: continue;
12995: }
1.1059 raeburn 12996: var startelement = $startcount + (i-1) * 7;
12997: for (var j=1; j<6; j++) {
12998: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12999: var item = startelement + j;
13000: if (form.elements[item].type == 'radio') {
13001: if (form.elements[item].checked) {
13002: if (form.elements[item].value == 'display') {
13003: var n = form.elements[depitem].options.length;
13004: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13005: }
13006: }
13007: }
13008: }
13009: }
13010: }
13011: } else {
13012: document.getElementById('arc_depon_'+count).style.display='none';
13013: form.elements[depitem].options.length = 0;
13014: form.elements[depitem].options[0] = new Option('Select','',true,true);
13015: }
1.1059 raeburn 13016: titleCheck(form,count,offset);
1.1056 raeburn 13017: }
13018: }
13019:
13020: function propagateSelect(form,count,offset) {
13021: if (count > 0) {
1.1065 raeburn 13022: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13023: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13024: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13025: if (parents[count].length > 0) {
13026: for (var j=0; j<parents[count].length; j++) {
13027: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13028: }
13029: }
13030: }
13031: }
13032: }
1.1056 raeburn 13033:
13034: function containerSelect(form,count,offset,picked) {
13035: if (count > 0) {
1.1065 raeburn 13036: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13037: if (form.elements[item].type == 'radio') {
13038: if (form.elements[item].value == 'dependency') {
13039: if (form.elements[item+1].type == 'select-one') {
13040: for (var i=0; i<form.elements[item+1].options.length; i++) {
13041: if (form.elements[item+1].options[i].value == picked) {
13042: form.elements[item+1].selectedIndex = i;
13043: break;
13044: }
13045: }
13046: }
13047: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13048: if (parents[count].length > 0) {
13049: for (var j=0; j<parents[count].length; j++) {
13050: containerSelect(form,parents[count][j],offset,picked);
13051: }
13052: }
13053: }
13054: }
13055: }
13056: }
13057: }
13058:
1.1059 raeburn 13059: function titleCheck(form,count,offset) {
13060: if (count > 0) {
13061: var chosen = (offset+$startcount)+7*(count-1);
13062: var depitem = $startcount + ((count-1) * 7) + 2;
13063: var currtype = form.elements[depitem].type;
13064: if (form.elements[chosen].value == 'display') {
13065: document.getElementById('arc_title_'+count).style.display='block';
13066: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13067: document.getElementById('archive_title_'+count).value=maintitle;
13068: }
13069: } else {
13070: document.getElementById('arc_title_'+count).style.display='none';
13071: if (currtype == 'text') {
13072: document.getElementById('archive_title_'+count).value='';
13073: }
13074: }
13075: }
13076: return;
13077: }
13078:
1.1055 raeburn 13079: // ]]>
13080: </script>
13081: END
13082: return $scripttag;
13083: }
13084:
13085: sub process_extracted_files {
1.1067 raeburn 13086: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13087: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 13088: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13089: my @ids=&Apache::lonnet::current_machine_ids();
13090: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13091: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13092: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13093: if (grep(/^\Q$docuhome\E$/,@ids)) {
13094: $prefix = &LONCAPA::propath($docudom,$docuname);
13095: $pathtocheck = "$dir_root/$destination";
13096: $dir = $dir_root;
13097: $ishome = 1;
13098: } else {
13099: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13100: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 13101: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13102: }
13103: my $currdir = "$dir_root/$destination";
13104: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13105: if ($env{'form.folderpath'}) {
13106: my @items = split('&',$env{'form.folderpath'});
13107: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 13108: if ($env{'form.folderpath'} =~ /\:1$/) {
13109: $containers{'0'}='page';
13110: } else {
13111: $containers{'0'}='sequence';
13112: }
1.1055 raeburn 13113: }
13114: my @archdirs = &get_env_multiple('form.archive_directory');
13115: if ($numitems) {
13116: for (my $i=1; $i<=$numitems; $i++) {
13117: my $path = $env{'form.archive_content_'.$i};
13118: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13119: my $item = $1;
13120: $toplevelitems{$item} = $i;
13121: if (grep(/^\Q$i\E$/,@archdirs)) {
13122: $is_dir{$item} = 1;
13123: }
13124: }
13125: }
13126: }
1.1067 raeburn 13127: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13128: if (keys(%toplevelitems) > 0) {
13129: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13130: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13131: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13132: }
1.1066 raeburn 13133: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13134: if ($numitems) {
13135: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 13136: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13137: my $path = $env{'form.archive_content_'.$i};
13138: if ($path =~ /^\Q$pathtocheck\E/) {
13139: if ($env{'form.archive_'.$i} eq 'discard') {
13140: if ($prefix ne '' && $path ne '') {
13141: if (-e $prefix.$path) {
1.1066 raeburn 13142: if ((@archdirs > 0) &&
13143: (grep(/^\Q$i\E$/,@archdirs))) {
13144: $todeletedir{$prefix.$path} = 1;
13145: } else {
13146: $todelete{$prefix.$path} = 1;
13147: }
1.1055 raeburn 13148: }
13149: }
13150: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13151: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13152: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13153: $docstitle = $env{'form.archive_title_'.$i};
13154: if ($docstitle eq '') {
13155: $docstitle = $title;
13156: }
1.1055 raeburn 13157: $outer = 0;
1.1056 raeburn 13158: if (ref($dirorder{$i}) eq 'ARRAY') {
13159: if (@{$dirorder{$i}} > 0) {
13160: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13161: if ($env{'form.archive_'.$item} eq 'display') {
13162: $outer = $item;
13163: last;
13164: }
13165: }
13166: }
13167: }
13168: my ($errtext,$fatal) =
13169: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13170: '/'.$folders{$outer}.'.'.
13171: $containers{$outer});
13172: next if ($fatal);
13173: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13174: if ($context eq 'coursedocs') {
1.1056 raeburn 13175: $mapinner{$i} = time;
1.1055 raeburn 13176: $folders{$i} = 'default_'.$mapinner{$i};
13177: $containers{$i} = 'sequence';
13178: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13179: $folders{$i}.'.'.$containers{$i};
13180: my $newidx = &LONCAPA::map::getresidx();
13181: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13182: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13183: push(@LONCAPA::map::order,$newidx);
13184: my ($outtext,$errtext) =
13185: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13186: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 13187: '.'.$containers{$outer},1,1);
1.1056 raeburn 13188: $newseqid{$i} = $newidx;
1.1067 raeburn 13189: unless ($errtext) {
1.1075.2.128 raeburn 13190: $result .= '<li>'.&mt('Folder: [_1] added to course',
13191: &HTML::Entities::encode($docstitle,'<>&"'))..
13192: '</li>'."\n";
1.1067 raeburn 13193: }
1.1055 raeburn 13194: }
13195: } else {
13196: if ($context eq 'coursedocs') {
13197: my $newidx=&LONCAPA::map::getresidx();
13198: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13199: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13200: $title;
1.1075.2.167 raeburn 13201: if (($outer !~ /\D/) &&
13202: (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
13203: ($newidx !~ /\D/)) {
1.1075.2.128 raeburn 13204: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13205: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 13206: }
1.1075.2.128 raeburn 13207: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13208: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13209: }
13210: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13211: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13212: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13213: unless ($ishome) {
13214: my $fetch = "$newdest{$i}/$title";
13215: $fetch =~ s/^\Q$prefix$dir\E//;
13216: $prompttofetch{$fetch} = 1;
13217: }
13218: }
13219: }
13220: $LONCAPA::map::resources[$newidx]=
13221: $docstitle.':'.$url.':false:normal:res';
13222: push(@LONCAPA::map::order, $newidx);
13223: my ($outtext,$errtext)=
13224: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13225: $docuname.'/'.$folders{$outer}.
13226: '.'.$containers{$outer},1,1);
13227: unless ($errtext) {
13228: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13229: $result .= '<li>'.&mt('File: [_1] added to course',
13230: &HTML::Entities::encode($docstitle,'<>&"')).
13231: '</li>'."\n";
13232: }
1.1067 raeburn 13233: }
1.1075.2.128 raeburn 13234: } else {
13235: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13236: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 13237: }
1.1055 raeburn 13238: }
13239: }
1.1075.2.11 raeburn 13240: }
13241: } else {
1.1075.2.128 raeburn 13242: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13243: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 13244: }
13245: }
13246: for (my $i=1; $i<=$numitems; $i++) {
13247: next unless ($env{'form.archive_'.$i} eq 'dependency');
13248: my $path = $env{'form.archive_content_'.$i};
13249: if ($path =~ /^\Q$pathtocheck\E/) {
13250: my ($title) = ($path =~ m{/([^/]+)$});
13251: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13252: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13253: if (ref($dirorder{$i}) eq 'ARRAY') {
13254: my ($itemidx,$fullpath,$relpath);
13255: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13256: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13257: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 13258: if ($dirorder{$i}->[$j] eq $container) {
13259: $itemidx = $j;
1.1056 raeburn 13260: }
13261: }
1.1075.2.11 raeburn 13262: }
13263: if ($itemidx eq '') {
13264: $itemidx = 0;
13265: }
13266: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13267: if ($mapinner{$referrer{$i}}) {
13268: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13269: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13270: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13271: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13272: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13273: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13274: if (!-e $fullpath) {
13275: mkdir($fullpath,0755);
1.1056 raeburn 13276: }
13277: }
1.1075.2.11 raeburn 13278: } else {
13279: last;
1.1056 raeburn 13280: }
1.1075.2.11 raeburn 13281: }
13282: }
13283: } elsif ($newdest{$referrer{$i}}) {
13284: $fullpath = $newdest{$referrer{$i}};
13285: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13286: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13287: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13288: last;
13289: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13290: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13291: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13292: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13293: if (!-e $fullpath) {
13294: mkdir($fullpath,0755);
1.1056 raeburn 13295: }
13296: }
1.1075.2.11 raeburn 13297: } else {
13298: last;
1.1056 raeburn 13299: }
1.1075.2.11 raeburn 13300: }
13301: }
13302: if ($fullpath ne '') {
13303: if (-e "$prefix$path") {
1.1075.2.128 raeburn 13304: unless (rename("$prefix$path","$fullpath/$title")) {
13305: $warning .= &mt('Failed to rename dependency').'<br />';
13306: }
1.1075.2.11 raeburn 13307: }
13308: if (-e "$fullpath/$title") {
13309: my $showpath;
13310: if ($relpath ne '') {
13311: $showpath = "$relpath/$title";
13312: } else {
13313: $showpath = "/$title";
1.1056 raeburn 13314: }
1.1075.2.128 raeburn 13315: $result .= '<li>'.&mt('[_1] included as a dependency',
13316: &HTML::Entities::encode($showpath,'<>&"')).
13317: '</li>'."\n";
13318: unless ($ishome) {
13319: my $fetch = "$fullpath/$title";
13320: $fetch =~ s/^\Q$prefix$dir\E//;
13321: $prompttofetch{$fetch} = 1;
13322: }
1.1055 raeburn 13323: }
13324: }
13325: }
1.1075.2.11 raeburn 13326: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13327: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 13328: &HTML::Entities::encode($path,'<>&"'),
13329: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13330: '<br />';
1.1055 raeburn 13331: }
13332: } else {
1.1075.2.128 raeburn 13333: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13334: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13335: }
13336: }
13337: if (keys(%todelete)) {
13338: foreach my $key (keys(%todelete)) {
13339: unlink($key);
1.1066 raeburn 13340: }
13341: }
13342: if (keys(%todeletedir)) {
13343: foreach my $key (keys(%todeletedir)) {
13344: rmdir($key);
13345: }
13346: }
13347: foreach my $dir (sort(keys(%is_dir))) {
13348: if (($pathtocheck ne '') && ($dir ne '')) {
13349: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13350: }
13351: }
1.1067 raeburn 13352: if ($result ne '') {
13353: $output .= '<ul>'."\n".
13354: $result."\n".
13355: '</ul>';
13356: }
13357: unless ($ishome) {
13358: my $replicationfail;
13359: foreach my $item (keys(%prompttofetch)) {
13360: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13361: unless ($fetchresult eq 'ok') {
13362: $replicationfail .= '<li>'.$item.'</li>'."\n";
13363: }
13364: }
13365: if ($replicationfail) {
13366: $output .= '<p class="LC_error">'.
13367: &mt('Course home server failed to retrieve:').'<ul>'.
13368: $replicationfail.
13369: '</ul></p>';
13370: }
13371: }
1.1055 raeburn 13372: } else {
13373: $warning = &mt('No items found in archive.');
13374: }
13375: if ($error) {
13376: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13377: $error.'</p>'."\n";
13378: }
13379: if ($warning) {
13380: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13381: }
13382: return $output;
13383: }
13384:
1.1066 raeburn 13385: sub cleanup_empty_dirs {
13386: my ($path) = @_;
13387: if (($path ne '') && (-d $path)) {
13388: if (opendir(my $dirh,$path)) {
13389: my @dircontents = grep(!/^\./,readdir($dirh));
13390: my $numitems = 0;
13391: foreach my $item (@dircontents) {
13392: if (-d "$path/$item") {
1.1075.2.28 raeburn 13393: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13394: if (-e "$path/$item") {
13395: $numitems ++;
13396: }
13397: } else {
13398: $numitems ++;
13399: }
13400: }
13401: if ($numitems == 0) {
13402: rmdir($path);
13403: }
13404: closedir($dirh);
13405: }
13406: }
13407: return;
13408: }
13409:
1.41 ng 13410: =pod
1.45 matthew 13411:
1.1075.2.56 raeburn 13412: =item * &get_folder_hierarchy()
1.1068 raeburn 13413:
13414: Provides hierarchy of names of folders/sub-folders containing the current
13415: item,
13416:
13417: Inputs: 3
13418: - $navmap - navmaps object
13419:
13420: - $map - url for map (either the trigger itself, or map containing
13421: the resource, which is the trigger).
13422:
13423: - $showitem - 1 => show title for map itself; 0 => do not show.
13424:
13425: Outputs: 1 @pathitems - array of folder/subfolder names.
13426:
13427: =cut
13428:
13429: sub get_folder_hierarchy {
13430: my ($navmap,$map,$showitem) = @_;
13431: my @pathitems;
13432: if (ref($navmap)) {
13433: my $mapres = $navmap->getResourceByUrl($map);
13434: if (ref($mapres)) {
13435: my $pcslist = $mapres->map_hierarchy();
13436: if ($pcslist ne '') {
13437: my @pcs = split(/,/,$pcslist);
13438: foreach my $pc (@pcs) {
13439: if ($pc == 1) {
1.1075.2.38 raeburn 13440: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13441: } else {
13442: my $res = $navmap->getByMapPc($pc);
13443: if (ref($res)) {
13444: my $title = $res->compTitle();
13445: $title =~ s/\W+/_/g;
13446: if ($title ne '') {
13447: push(@pathitems,$title);
13448: }
13449: }
13450: }
13451: }
13452: }
1.1071 raeburn 13453: if ($showitem) {
13454: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13455: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13456: } else {
13457: my $maptitle = $mapres->compTitle();
13458: $maptitle =~ s/\W+/_/g;
13459: if ($maptitle ne '') {
13460: push(@pathitems,$maptitle);
13461: }
1.1068 raeburn 13462: }
13463: }
13464: }
13465: }
13466: return @pathitems;
13467: }
13468:
13469: =pod
13470:
1.1015 raeburn 13471: =item * &get_turnedin_filepath()
13472:
13473: Determines path in a user's portfolio file for storage of files uploaded
13474: to a specific essayresponse or dropbox item.
13475:
13476: Inputs: 3 required + 1 optional.
13477: $symb is symb for resource, $uname and $udom are for current user (required).
13478: $caller is optional (can be "submission", if routine is called when storing
13479: an upoaded file when "Submit Answer" button was pressed).
13480:
13481: Returns array containing $path and $multiresp.
13482: $path is path in portfolio. $multiresp is 1 if this resource contains more
13483: than one file upload item. Callers of routine should append partid as a
13484: subdirectory to $path in cases where $multiresp is 1.
13485:
13486: Called by: homework/essayresponse.pm and homework/structuretags.pm
13487:
13488: =cut
13489:
13490: sub get_turnedin_filepath {
13491: my ($symb,$uname,$udom,$caller) = @_;
13492: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13493: my $turnindir;
13494: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13495: $turnindir = $userhash{'turnindir'};
13496: my ($path,$multiresp);
13497: if ($turnindir eq '') {
13498: if ($caller eq 'submission') {
13499: $turnindir = &mt('turned in');
13500: $turnindir =~ s/\W+/_/g;
13501: my %newhash = (
13502: 'turnindir' => $turnindir,
13503: );
13504: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13505: }
13506: }
13507: if ($turnindir ne '') {
13508: $path = '/'.$turnindir.'/';
13509: my ($multipart,$turnin,@pathitems);
13510: my $navmap = Apache::lonnavmaps::navmap->new();
13511: if (defined($navmap)) {
13512: my $mapres = $navmap->getResourceByUrl($map);
13513: if (ref($mapres)) {
13514: my $pcslist = $mapres->map_hierarchy();
13515: if ($pcslist ne '') {
13516: foreach my $pc (split(/,/,$pcslist)) {
13517: my $res = $navmap->getByMapPc($pc);
13518: if (ref($res)) {
13519: my $title = $res->compTitle();
13520: $title =~ s/\W+/_/g;
13521: if ($title ne '') {
1.1075.2.48 raeburn 13522: if (($pc > 1) && (length($title) > 12)) {
13523: $title = substr($title,0,12);
13524: }
1.1015 raeburn 13525: push(@pathitems,$title);
13526: }
13527: }
13528: }
13529: }
13530: my $maptitle = $mapres->compTitle();
13531: $maptitle =~ s/\W+/_/g;
13532: if ($maptitle ne '') {
1.1075.2.48 raeburn 13533: if (length($maptitle) > 12) {
13534: $maptitle = substr($maptitle,0,12);
13535: }
1.1015 raeburn 13536: push(@pathitems,$maptitle);
13537: }
13538: unless ($env{'request.state'} eq 'construct') {
13539: my $res = $navmap->getBySymb($symb);
13540: if (ref($res)) {
13541: my $partlist = $res->parts();
13542: my $totaluploads = 0;
13543: if (ref($partlist) eq 'ARRAY') {
13544: foreach my $part (@{$partlist}) {
13545: my @types = $res->responseType($part);
13546: my @ids = $res->responseIds($part);
13547: for (my $i=0; $i < scalar(@ids); $i++) {
13548: if ($types[$i] eq 'essay') {
13549: my $partid = $part.'_'.$ids[$i];
13550: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13551: $totaluploads ++;
13552: }
13553: }
13554: }
13555: }
13556: if ($totaluploads > 1) {
13557: $multiresp = 1;
13558: }
13559: }
13560: }
13561: }
13562: } else {
13563: return;
13564: }
13565: } else {
13566: return;
13567: }
13568: my $restitle=&Apache::lonnet::gettitle($symb);
13569: $restitle =~ s/\W+/_/g;
13570: if ($restitle eq '') {
13571: $restitle = ($resurl =~ m{/[^/]+$});
13572: if ($restitle eq '') {
13573: $restitle = time;
13574: }
13575: }
1.1075.2.48 raeburn 13576: if (length($restitle) > 12) {
13577: $restitle = substr($restitle,0,12);
13578: }
1.1015 raeburn 13579: push(@pathitems,$restitle);
13580: $path .= join('/',@pathitems);
13581: }
13582: return ($path,$multiresp);
13583: }
13584:
13585: =pod
13586:
1.464 albertel 13587: =back
1.41 ng 13588:
1.112 bowersj2 13589: =head1 CSV Upload/Handling functions
1.38 albertel 13590:
1.41 ng 13591: =over 4
13592:
1.648 raeburn 13593: =item * &upfile_store($r)
1.41 ng 13594:
13595: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13596: needs $env{'form.upfile'}
1.41 ng 13597: returns $datatoken to be put into hidden field
13598:
13599: =cut
1.31 albertel 13600:
13601: sub upfile_store {
13602: my $r=shift;
1.258 albertel 13603: $env{'form.upfile'}=~s/\r/\n/gs;
13604: $env{'form.upfile'}=~s/\f/\n/gs;
13605: $env{'form.upfile'}=~s/\n+/\n/gs;
13606: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13607:
1.1075.2.128 raeburn 13608: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13609: '_enroll_'.$env{'request.course.id'}.'_'.
13610: time.'_'.$$);
13611: return if ($datatoken eq '');
13612:
1.31 albertel 13613: {
1.158 raeburn 13614: my $datafile = $r->dir_config('lonDaemons').
13615: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13616: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13617: print $fh $env{'form.upfile'};
1.158 raeburn 13618: close($fh);
13619: }
1.31 albertel 13620: }
13621: return $datatoken;
13622: }
13623:
1.56 matthew 13624: =pod
13625:
1.1075.2.128 raeburn 13626: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13627:
13628: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13629: $datatoken is the name to assign to the temporary file.
1.258 albertel 13630: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13631:
13632: =cut
1.31 albertel 13633:
13634: sub load_tmp_file {
1.1075.2.128 raeburn 13635: my ($r,$datatoken) = @_;
13636: return if ($datatoken eq '');
1.31 albertel 13637: my @studentdata=();
13638: {
1.158 raeburn 13639: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13640: '/tmp/'.$datatoken.'.tmp';
13641: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13642: @studentdata=<$fh>;
13643: close($fh);
13644: }
1.31 albertel 13645: }
1.258 albertel 13646: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13647: }
13648:
1.1075.2.128 raeburn 13649: sub valid_datatoken {
13650: my ($datatoken) = @_;
1.1075.2.131 raeburn 13651: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13652: return $datatoken;
13653: }
13654: return;
13655: }
13656:
1.56 matthew 13657: =pod
13658:
1.648 raeburn 13659: =item * &upfile_record_sep()
1.41 ng 13660:
13661: Separate uploaded file into records
13662: returns array of records,
1.258 albertel 13663: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13664:
13665: =cut
1.31 albertel 13666:
13667: sub upfile_record_sep {
1.258 albertel 13668: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13669: } else {
1.248 albertel 13670: my @records;
1.258 albertel 13671: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13672: if ($line=~/^\s*$/) { next; }
13673: push(@records,$line);
13674: }
13675: return @records;
1.31 albertel 13676: }
13677: }
13678:
1.56 matthew 13679: =pod
13680:
1.648 raeburn 13681: =item * &record_sep($record)
1.41 ng 13682:
1.258 albertel 13683: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13684:
13685: =cut
13686:
1.263 www 13687: sub takeleft {
13688: my $index=shift;
13689: return substr('0000'.$index,-4,4);
13690: }
13691:
1.31 albertel 13692: sub record_sep {
13693: my $record=shift;
13694: my %components=();
1.258 albertel 13695: if ($env{'form.upfiletype'} eq 'xml') {
13696: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13697: my $i=0;
1.356 albertel 13698: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13699: $field=~s/^(\"|\')//;
13700: $field=~s/(\"|\')$//;
1.263 www 13701: $components{&takeleft($i)}=$field;
1.31 albertel 13702: $i++;
13703: }
1.258 albertel 13704: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13705: my $i=0;
1.356 albertel 13706: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13707: $field=~s/^(\"|\')//;
13708: $field=~s/(\"|\')$//;
1.263 www 13709: $components{&takeleft($i)}=$field;
1.31 albertel 13710: $i++;
13711: }
13712: } else {
1.561 www 13713: my $separator=',';
1.480 banghart 13714: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13715: $separator=';';
1.480 banghart 13716: }
1.31 albertel 13717: my $i=0;
1.561 www 13718: # the character we are looking for to indicate the end of a quote or a record
13719: my $looking_for=$separator;
13720: # do not add the characters to the fields
13721: my $ignore=0;
13722: # we just encountered a separator (or the beginning of the record)
13723: my $just_found_separator=1;
13724: # store the field we are working on here
13725: my $field='';
13726: # work our way through all characters in record
13727: foreach my $character ($record=~/(.)/g) {
13728: if ($character eq $looking_for) {
13729: if ($character ne $separator) {
13730: # Found the end of a quote, again looking for separator
13731: $looking_for=$separator;
13732: $ignore=1;
13733: } else {
13734: # Found a separator, store away what we got
13735: $components{&takeleft($i)}=$field;
13736: $i++;
13737: $just_found_separator=1;
13738: $ignore=0;
13739: $field='';
13740: }
13741: next;
13742: }
13743: # single or double quotation marks after a separator indicate beginning of a quote
13744: # we are now looking for the end of the quote and need to ignore separators
13745: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13746: $looking_for=$character;
13747: next;
13748: }
13749: # ignore would be true after we reached the end of a quote
13750: if ($ignore) { next; }
13751: if (($just_found_separator) && ($character=~/\s/)) { next; }
13752: $field.=$character;
13753: $just_found_separator=0;
1.31 albertel 13754: }
1.561 www 13755: # catch the very last entry, since we never encountered the separator
13756: $components{&takeleft($i)}=$field;
1.31 albertel 13757: }
13758: return %components;
13759: }
13760:
1.144 matthew 13761: ######################################################
13762: ######################################################
13763:
1.56 matthew 13764: =pod
13765:
1.648 raeburn 13766: =item * &upfile_select_html()
1.41 ng 13767:
1.144 matthew 13768: Return HTML code to select a file from the users machine and specify
13769: the file type.
1.41 ng 13770:
13771: =cut
13772:
1.144 matthew 13773: ######################################################
13774: ######################################################
1.31 albertel 13775: sub upfile_select_html {
1.144 matthew 13776: my %Types = (
13777: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13778: semisv => &mt('Semicolon separated values'),
1.144 matthew 13779: space => &mt('Space separated'),
13780: tab => &mt('Tabulator separated'),
13781: # xml => &mt('HTML/XML'),
13782: );
13783: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13784: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13785: foreach my $type (sort(keys(%Types))) {
13786: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13787: }
13788: $Str .= "</select>\n";
13789: return $Str;
1.31 albertel 13790: }
13791:
1.301 albertel 13792: sub get_samples {
13793: my ($records,$toget) = @_;
13794: my @samples=({});
13795: my $got=0;
13796: foreach my $rec (@$records) {
13797: my %temp = &record_sep($rec);
13798: if (! grep(/\S/, values(%temp))) { next; }
13799: if (%temp) {
13800: $samples[$got]=\%temp;
13801: $got++;
13802: if ($got == $toget) { last; }
13803: }
13804: }
13805: return \@samples;
13806: }
13807:
1.144 matthew 13808: ######################################################
13809: ######################################################
13810:
1.56 matthew 13811: =pod
13812:
1.648 raeburn 13813: =item * &csv_print_samples($r,$records)
1.41 ng 13814:
13815: Prints a table of sample values from each column uploaded $r is an
13816: Apache Request ref, $records is an arrayref from
13817: &Apache::loncommon::upfile_record_sep
13818:
13819: =cut
13820:
1.144 matthew 13821: ######################################################
13822: ######################################################
1.31 albertel 13823: sub csv_print_samples {
13824: my ($r,$records) = @_;
1.662 bisitz 13825: my $samples = &get_samples($records,5);
1.301 albertel 13826:
1.594 raeburn 13827: $r->print(&mt('Samples').'<br />'.&start_data_table().
13828: &start_data_table_header_row());
1.356 albertel 13829: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13830: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13831: $r->print(&end_data_table_header_row());
1.301 albertel 13832: foreach my $hash (@$samples) {
1.594 raeburn 13833: $r->print(&start_data_table_row());
1.356 albertel 13834: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13835: $r->print('<td>');
1.356 albertel 13836: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13837: $r->print('</td>');
13838: }
1.594 raeburn 13839: $r->print(&end_data_table_row());
1.31 albertel 13840: }
1.594 raeburn 13841: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13842: }
13843:
1.144 matthew 13844: ######################################################
13845: ######################################################
13846:
1.56 matthew 13847: =pod
13848:
1.648 raeburn 13849: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13850:
13851: Prints a table to create associations between values and table columns.
1.144 matthew 13852:
1.41 ng 13853: $r is an Apache Request ref,
13854: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13855: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13856:
13857: =cut
13858:
1.144 matthew 13859: ######################################################
13860: ######################################################
1.31 albertel 13861: sub csv_print_select_table {
13862: my ($r,$records,$d) = @_;
1.301 albertel 13863: my $i=0;
13864: my $samples = &get_samples($records,1);
1.144 matthew 13865: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13866: &start_data_table().&start_data_table_header_row().
1.144 matthew 13867: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13868: '<th>'.&mt('Column').'</th>'.
13869: &end_data_table_header_row()."\n");
1.356 albertel 13870: foreach my $array_ref (@$d) {
13871: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13872: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13873:
1.875 bisitz 13874: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13875: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13876: $r->print('<option value="none"></option>');
1.356 albertel 13877: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13878: $r->print('<option value="'.$sample.'"'.
13879: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13880: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13881: }
1.594 raeburn 13882: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13883: $i++;
13884: }
1.594 raeburn 13885: $r->print(&end_data_table());
1.31 albertel 13886: $i--;
13887: return $i;
13888: }
1.56 matthew 13889:
1.144 matthew 13890: ######################################################
13891: ######################################################
13892:
1.56 matthew 13893: =pod
1.31 albertel 13894:
1.648 raeburn 13895: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13896:
13897: Prints a table of sample values from the upload and can make associate samples to internal names.
13898:
13899: $r is an Apache Request ref,
13900: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13901: $d is an array of 2 element arrays (internal name, displayed name)
13902:
13903: =cut
13904:
1.144 matthew 13905: ######################################################
13906: ######################################################
1.31 albertel 13907: sub csv_samples_select_table {
13908: my ($r,$records,$d) = @_;
13909: my $i=0;
1.144 matthew 13910: #
1.662 bisitz 13911: my $max_samples = 5;
13912: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13913: $r->print(&start_data_table().
13914: &start_data_table_header_row().'<th>'.
13915: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13916: &end_data_table_header_row());
1.301 albertel 13917:
13918: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13919: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13920: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13921: foreach my $option (@$d) {
13922: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13923: $r->print('<option value="'.$value.'"'.
1.253 albertel 13924: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13925: $display.'</option>');
1.31 albertel 13926: }
13927: $r->print('</select></td><td>');
1.662 bisitz 13928: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13929: if (defined($samples->[$line]{$key})) {
13930: $r->print($samples->[$line]{$key}."<br />\n");
13931: }
13932: }
1.594 raeburn 13933: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13934: $i++;
13935: }
1.594 raeburn 13936: $r->print(&end_data_table());
1.31 albertel 13937: $i--;
13938: return($i);
1.115 matthew 13939: }
13940:
1.144 matthew 13941: ######################################################
13942: ######################################################
13943:
1.115 matthew 13944: =pod
13945:
1.648 raeburn 13946: =item * &clean_excel_name($name)
1.115 matthew 13947:
13948: Returns a replacement for $name which does not contain any illegal characters.
13949:
13950: =cut
13951:
1.144 matthew 13952: ######################################################
13953: ######################################################
1.115 matthew 13954: sub clean_excel_name {
13955: my ($name) = @_;
13956: $name =~ s/[:\*\?\/\\]//g;
13957: if (length($name) > 31) {
13958: $name = substr($name,0,31);
13959: }
13960: return $name;
1.25 albertel 13961: }
1.84 albertel 13962:
1.85 albertel 13963: =pod
13964:
1.648 raeburn 13965: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13966:
13967: Returns either 1 or undef
13968:
13969: 1 if the part is to be hidden, undef if it is to be shown
13970:
13971: Arguments are:
13972:
13973: $id the id of the part to be checked
13974: $symb, optional the symb of the resource to check
13975: $udom, optional the domain of the user to check for
13976: $uname, optional the username of the user to check for
13977:
13978: =cut
1.84 albertel 13979:
13980: sub check_if_partid_hidden {
13981: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13982: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13983: $symb,$udom,$uname);
1.141 albertel 13984: my $truth=1;
13985: #if the string starts with !, then the list is the list to show not hide
13986: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13987: my @hiddenlist=split(/,/,$hiddenparts);
13988: foreach my $checkid (@hiddenlist) {
1.141 albertel 13989: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13990: }
1.141 albertel 13991: return !$truth;
1.84 albertel 13992: }
1.127 matthew 13993:
1.138 matthew 13994:
13995: ############################################################
13996: ############################################################
13997:
13998: =pod
13999:
1.157 matthew 14000: =back
14001:
1.138 matthew 14002: =head1 cgi-bin script and graphing routines
14003:
1.157 matthew 14004: =over 4
14005:
1.648 raeburn 14006: =item * &get_cgi_id()
1.138 matthew 14007:
14008: Inputs: none
14009:
14010: Returns an id which can be used to pass environment variables
14011: to various cgi-bin scripts. These environment variables will
14012: be removed from the users environment after a given time by
14013: the routine &Apache::lonnet::transfer_profile_to_env.
14014:
14015: =cut
14016:
14017: ############################################################
14018: ############################################################
1.152 albertel 14019: my $uniq=0;
1.136 matthew 14020: sub get_cgi_id {
1.154 albertel 14021: $uniq=($uniq+1)%100000;
1.280 albertel 14022: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14023: }
14024:
1.127 matthew 14025: ############################################################
14026: ############################################################
14027:
14028: =pod
14029:
1.648 raeburn 14030: =item * &DrawBarGraph()
1.127 matthew 14031:
1.138 matthew 14032: Facilitates the plotting of data in a (stacked) bar graph.
14033: Puts plot definition data into the users environment in order for
14034: graph.png to plot it. Returns an <img> tag for the plot.
14035: The bars on the plot are labeled '1','2',...,'n'.
14036:
14037: Inputs:
14038:
14039: =over 4
14040:
14041: =item $Title: string, the title of the plot
14042:
14043: =item $xlabel: string, text describing the X-axis of the plot
14044:
14045: =item $ylabel: string, text describing the Y-axis of the plot
14046:
14047: =item $Max: scalar, the maximum Y value to use in the plot
14048: If $Max is < any data point, the graph will not be rendered.
14049:
1.140 matthew 14050: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14051: they are plotted. If undefined, default values will be used.
14052:
1.178 matthew 14053: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14054:
1.138 matthew 14055: =item @Values: An array of array references. Each array reference holds data
14056: to be plotted in a stacked bar chart.
14057:
1.239 matthew 14058: =item If the final element of @Values is a hash reference the key/value
14059: pairs will be added to the graph definition.
14060:
1.138 matthew 14061: =back
14062:
14063: Returns:
14064:
14065: An <img> tag which references graph.png and the appropriate identifying
14066: information for the plot.
14067:
1.127 matthew 14068: =cut
14069:
14070: ############################################################
14071: ############################################################
1.134 matthew 14072: sub DrawBarGraph {
1.178 matthew 14073: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14074: #
14075: if (! defined($colors)) {
14076: $colors = ['#33ff00',
14077: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14078: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14079: ];
14080: }
1.228 matthew 14081: my $extra_settings = {};
14082: if (ref($Values[-1]) eq 'HASH') {
14083: $extra_settings = pop(@Values);
14084: }
1.127 matthew 14085: #
1.136 matthew 14086: my $identifier = &get_cgi_id();
14087: my $id = 'cgi.'.$identifier;
1.129 matthew 14088: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14089: return '';
14090: }
1.225 matthew 14091: #
14092: my @Labels;
14093: if (defined($labels)) {
14094: @Labels = @$labels;
14095: } else {
14096: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 14097: push(@Labels,$i+1);
1.225 matthew 14098: }
14099: }
14100: #
1.129 matthew 14101: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14102: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14103: my %ValuesHash;
14104: my $NumSets=1;
14105: foreach my $array (@Values) {
14106: next if (! ref($array));
1.136 matthew 14107: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14108: join(',',@$array);
1.129 matthew 14109: }
1.127 matthew 14110: #
1.136 matthew 14111: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14112: if ($NumBars < 3) {
14113: $width = 120+$NumBars*32;
1.220 matthew 14114: $xskip = 1;
1.225 matthew 14115: $bar_width = 30;
14116: } elsif ($NumBars < 5) {
14117: $width = 120+$NumBars*20;
14118: $xskip = 1;
14119: $bar_width = 20;
1.220 matthew 14120: } elsif ($NumBars < 10) {
1.136 matthew 14121: $width = 120+$NumBars*15;
14122: $xskip = 1;
14123: $bar_width = 15;
14124: } elsif ($NumBars <= 25) {
14125: $width = 120+$NumBars*11;
14126: $xskip = 5;
14127: $bar_width = 8;
14128: } elsif ($NumBars <= 50) {
14129: $width = 120+$NumBars*8;
14130: $xskip = 5;
14131: $bar_width = 4;
14132: } else {
14133: $width = 120+$NumBars*8;
14134: $xskip = 5;
14135: $bar_width = 4;
14136: }
14137: #
1.137 matthew 14138: $Max = 1 if ($Max < 1);
14139: if ( int($Max) < $Max ) {
14140: $Max++;
14141: $Max = int($Max);
14142: }
1.127 matthew 14143: $Title = '' if (! defined($Title));
14144: $xlabel = '' if (! defined($xlabel));
14145: $ylabel = '' if (! defined($ylabel));
1.369 www 14146: $ValuesHash{$id.'.title'} = &escape($Title);
14147: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14148: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14149: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14150: $ValuesHash{$id.'.NumBars'} = $NumBars;
14151: $ValuesHash{$id.'.NumSets'} = $NumSets;
14152: $ValuesHash{$id.'.PlotType'} = 'bar';
14153: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14154: $ValuesHash{$id.'.height'} = $height;
14155: $ValuesHash{$id.'.width'} = $width;
14156: $ValuesHash{$id.'.xskip'} = $xskip;
14157: $ValuesHash{$id.'.bar_width'} = $bar_width;
14158: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14159: #
1.228 matthew 14160: # Deal with other parameters
14161: while (my ($key,$value) = each(%$extra_settings)) {
14162: $ValuesHash{$id.'.'.$key} = $value;
14163: }
14164: #
1.646 raeburn 14165: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14166: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14167: }
14168:
14169: ############################################################
14170: ############################################################
14171:
14172: =pod
14173:
1.648 raeburn 14174: =item * &DrawXYGraph()
1.137 matthew 14175:
1.138 matthew 14176: Facilitates the plotting of data in an XY graph.
14177: Puts plot definition data into the users environment in order for
14178: graph.png to plot it. Returns an <img> tag for the plot.
14179:
14180: Inputs:
14181:
14182: =over 4
14183:
14184: =item $Title: string, the title of the plot
14185:
14186: =item $xlabel: string, text describing the X-axis of the plot
14187:
14188: =item $ylabel: string, text describing the Y-axis of the plot
14189:
14190: =item $Max: scalar, the maximum Y value to use in the plot
14191: If $Max is < any data point, the graph will not be rendered.
14192:
14193: =item $colors: Array ref containing the hex color codes for the data to be
14194: plotted in. If undefined, default values will be used.
14195:
14196: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14197:
14198: =item $Ydata: Array ref containing Array refs.
1.185 www 14199: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14200:
14201: =item %Values: hash indicating or overriding any default values which are
14202: passed to graph.png.
14203: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14204:
14205: =back
14206:
14207: Returns:
14208:
14209: An <img> tag which references graph.png and the appropriate identifying
14210: information for the plot.
14211:
1.137 matthew 14212: =cut
14213:
14214: ############################################################
14215: ############################################################
14216: sub DrawXYGraph {
14217: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14218: #
14219: # Create the identifier for the graph
14220: my $identifier = &get_cgi_id();
14221: my $id = 'cgi.'.$identifier;
14222: #
14223: $Title = '' if (! defined($Title));
14224: $xlabel = '' if (! defined($xlabel));
14225: $ylabel = '' if (! defined($ylabel));
14226: my %ValuesHash =
14227: (
1.369 www 14228: $id.'.title' => &escape($Title),
14229: $id.'.xlabel' => &escape($xlabel),
14230: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14231: $id.'.y_max_value'=> $Max,
14232: $id.'.labels' => join(',',@$Xlabels),
14233: $id.'.PlotType' => 'XY',
14234: );
14235: #
14236: if (defined($colors) && ref($colors) eq 'ARRAY') {
14237: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14238: }
14239: #
14240: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14241: return '';
14242: }
14243: my $NumSets=1;
1.138 matthew 14244: foreach my $array (@{$Ydata}){
1.137 matthew 14245: next if (! ref($array));
14246: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14247: }
1.138 matthew 14248: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14249: #
14250: # Deal with other parameters
14251: while (my ($key,$value) = each(%Values)) {
14252: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14253: }
14254: #
1.646 raeburn 14255: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14256: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14257: }
14258:
14259: ############################################################
14260: ############################################################
14261:
14262: =pod
14263:
1.648 raeburn 14264: =item * &DrawXYYGraph()
1.138 matthew 14265:
14266: Facilitates the plotting of data in an XY graph with two Y axes.
14267: Puts plot definition data into the users environment in order for
14268: graph.png to plot it. Returns an <img> tag for the plot.
14269:
14270: Inputs:
14271:
14272: =over 4
14273:
14274: =item $Title: string, the title of the plot
14275:
14276: =item $xlabel: string, text describing the X-axis of the plot
14277:
14278: =item $ylabel: string, text describing the Y-axis of the plot
14279:
14280: =item $colors: Array ref containing the hex color codes for the data to be
14281: plotted in. If undefined, default values will be used.
14282:
14283: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14284:
14285: =item $Ydata1: The first data set
14286:
14287: =item $Min1: The minimum value of the left Y-axis
14288:
14289: =item $Max1: The maximum value of the left Y-axis
14290:
14291: =item $Ydata2: The second data set
14292:
14293: =item $Min2: The minimum value of the right Y-axis
14294:
14295: =item $Max2: The maximum value of the left Y-axis
14296:
14297: =item %Values: hash indicating or overriding any default values which are
14298: passed to graph.png.
14299: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14300:
14301: =back
14302:
14303: Returns:
14304:
14305: An <img> tag which references graph.png and the appropriate identifying
14306: information for the plot.
1.136 matthew 14307:
14308: =cut
14309:
14310: ############################################################
14311: ############################################################
1.137 matthew 14312: sub DrawXYYGraph {
14313: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14314: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14315: #
14316: # Create the identifier for the graph
14317: my $identifier = &get_cgi_id();
14318: my $id = 'cgi.'.$identifier;
14319: #
14320: $Title = '' if (! defined($Title));
14321: $xlabel = '' if (! defined($xlabel));
14322: $ylabel = '' if (! defined($ylabel));
14323: my %ValuesHash =
14324: (
1.369 www 14325: $id.'.title' => &escape($Title),
14326: $id.'.xlabel' => &escape($xlabel),
14327: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14328: $id.'.labels' => join(',',@$Xlabels),
14329: $id.'.PlotType' => 'XY',
14330: $id.'.NumSets' => 2,
1.137 matthew 14331: $id.'.two_axes' => 1,
14332: $id.'.y1_max_value' => $Max1,
14333: $id.'.y1_min_value' => $Min1,
14334: $id.'.y2_max_value' => $Max2,
14335: $id.'.y2_min_value' => $Min2,
1.136 matthew 14336: );
14337: #
1.137 matthew 14338: if (defined($colors) && ref($colors) eq 'ARRAY') {
14339: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14340: }
14341: #
14342: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14343: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14344: return '';
14345: }
14346: my $NumSets=1;
1.137 matthew 14347: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14348: next if (! ref($array));
14349: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14350: }
14351: #
14352: # Deal with other parameters
14353: while (my ($key,$value) = each(%Values)) {
14354: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14355: }
14356: #
1.646 raeburn 14357: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14358: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14359: }
14360:
14361: ############################################################
14362: ############################################################
14363:
14364: =pod
14365:
1.157 matthew 14366: =back
14367:
1.139 matthew 14368: =head1 Statistics helper routines?
14369:
14370: Bad place for them but what the hell.
14371:
1.157 matthew 14372: =over 4
14373:
1.648 raeburn 14374: =item * &chartlink()
1.139 matthew 14375:
14376: Returns a link to the chart for a specific student.
14377:
14378: Inputs:
14379:
14380: =over 4
14381:
14382: =item $linktext: The text of the link
14383:
14384: =item $sname: The students username
14385:
14386: =item $sdomain: The students domain
14387:
14388: =back
14389:
1.157 matthew 14390: =back
14391:
1.139 matthew 14392: =cut
14393:
14394: ############################################################
14395: ############################################################
14396: sub chartlink {
14397: my ($linktext, $sname, $sdomain) = @_;
14398: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14399: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14400: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14401: '">'.$linktext.'</a>';
1.153 matthew 14402: }
14403:
14404: #######################################################
14405: #######################################################
14406:
14407: =pod
14408:
14409: =head1 Course Environment Routines
1.157 matthew 14410:
14411: =over 4
1.153 matthew 14412:
1.648 raeburn 14413: =item * &restore_course_settings()
1.153 matthew 14414:
1.648 raeburn 14415: =item * &store_course_settings()
1.153 matthew 14416:
14417: Restores/Store indicated form parameters from the course environment.
14418: Will not overwrite existing values of the form parameters.
14419:
14420: Inputs:
14421: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14422:
14423: a hash ref describing the data to be stored. For example:
14424:
14425: %Save_Parameters = ('Status' => 'scalar',
14426: 'chartoutputmode' => 'scalar',
14427: 'chartoutputdata' => 'scalar',
14428: 'Section' => 'array',
1.373 raeburn 14429: 'Group' => 'array',
1.153 matthew 14430: 'StudentData' => 'array',
14431: 'Maps' => 'array');
14432:
14433: Returns: both routines return nothing
14434:
1.631 raeburn 14435: =back
14436:
1.153 matthew 14437: =cut
14438:
14439: #######################################################
14440: #######################################################
14441: sub store_course_settings {
1.496 albertel 14442: return &store_settings($env{'request.course.id'},@_);
14443: }
14444:
14445: sub store_settings {
1.153 matthew 14446: # save to the environment
14447: # appenv the same items, just to be safe
1.300 albertel 14448: my $udom = $env{'user.domain'};
14449: my $uname = $env{'user.name'};
1.496 albertel 14450: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14451: my %SaveHash;
14452: my %AppHash;
14453: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14454: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14455: my $envname = 'environment.'.$basename;
1.258 albertel 14456: if (exists($env{'form.'.$setting})) {
1.153 matthew 14457: # Save this value away
14458: if ($type eq 'scalar' &&
1.258 albertel 14459: (! exists($env{$envname}) ||
14460: $env{$envname} ne $env{'form.'.$setting})) {
14461: $SaveHash{$basename} = $env{'form.'.$setting};
14462: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14463: } elsif ($type eq 'array') {
14464: my $stored_form;
1.258 albertel 14465: if (ref($env{'form.'.$setting})) {
1.153 matthew 14466: $stored_form = join(',',
14467: map {
1.369 www 14468: &escape($_);
1.258 albertel 14469: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14470: } else {
14471: $stored_form =
1.369 www 14472: &escape($env{'form.'.$setting});
1.153 matthew 14473: }
14474: # Determine if the array contents are the same.
1.258 albertel 14475: if ($stored_form ne $env{$envname}) {
1.153 matthew 14476: $SaveHash{$basename} = $stored_form;
14477: $AppHash{$envname} = $stored_form;
14478: }
14479: }
14480: }
14481: }
14482: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14483: $udom,$uname);
1.153 matthew 14484: if ($put_result !~ /^(ok|delayed)/) {
14485: &Apache::lonnet::logthis('unable to save form parameters, '.
14486: 'got error:'.$put_result);
14487: }
14488: # Make sure these settings stick around in this session, too
1.646 raeburn 14489: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14490: return;
14491: }
14492:
14493: sub restore_course_settings {
1.499 albertel 14494: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14495: }
14496:
14497: sub restore_settings {
14498: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14499: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14500: next if (exists($env{'form.'.$setting}));
1.496 albertel 14501: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14502: '.'.$setting;
1.258 albertel 14503: if (exists($env{$envname})) {
1.153 matthew 14504: if ($type eq 'scalar') {
1.258 albertel 14505: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14506: } elsif ($type eq 'array') {
1.258 albertel 14507: $env{'form.'.$setting} = [
1.153 matthew 14508: map {
1.369 www 14509: &unescape($_);
1.258 albertel 14510: } split(',',$env{$envname})
1.153 matthew 14511: ];
14512: }
14513: }
14514: }
1.127 matthew 14515: }
14516:
1.618 raeburn 14517: #######################################################
14518: #######################################################
14519:
14520: =pod
14521:
14522: =head1 Domain E-mail Routines
14523:
14524: =over 4
14525:
1.648 raeburn 14526: =item * &build_recipient_list()
1.618 raeburn 14527:
1.1075.2.44 raeburn 14528: Build recipient lists for following types of e-mail:
1.766 raeburn 14529: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14530: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14531: module change checking, student/employee ID conflict checks, as
14532: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14533: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14534:
14535: Inputs:
1.1075.2.44 raeburn 14536: defmail (scalar - email address of default recipient),
14537: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14538: requestsmail, updatesmail, or idconflictsmail).
14539:
1.619 raeburn 14540: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14541:
14542: origmail (scalar - email address of recipient from loncapa.conf,
14543: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14544:
1.1075.2.139 raeburn 14545: $requname username of requester (if mailing type is helpdeskmail)
14546:
14547: $requdom domain of requester (if mailing type is helpdeskmail)
14548:
14549: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14550:
1.655 raeburn 14551: Returns: comma separated list of addresses to which to send e-mail.
14552:
14553: =back
1.618 raeburn 14554:
14555: =cut
14556:
14557: ############################################################
14558: ############################################################
14559: sub build_recipient_list {
1.1075.2.139 raeburn 14560: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14561: my @recipients;
1.1075.2.122 raeburn 14562: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14563: my %domconfig =
1.1075.2.122 raeburn 14564: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14565: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14566: if (exists($domconfig{'contacts'}{$mailing})) {
14567: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14568: my @contacts = ('adminemail','supportemail');
14569: foreach my $item (@contacts) {
14570: if ($domconfig{'contacts'}{$mailing}{$item}) {
14571: my $addr = $domconfig{'contacts'}{$item};
14572: if (!grep(/^\Q$addr\E$/,@recipients)) {
14573: push(@recipients,$addr);
14574: }
1.619 raeburn 14575: }
1.1075.2.122 raeburn 14576: }
14577: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14578: if ($mailing eq 'helpdeskmail') {
14579: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14580: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14581: my @ok_bccs;
14582: foreach my $bcc (@bccs) {
14583: $bcc =~ s/^\s+//g;
14584: $bcc =~ s/\s+$//g;
14585: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14586: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14587: push(@ok_bccs,$bcc);
14588: }
14589: }
14590: }
14591: if (@ok_bccs > 0) {
14592: $allbcc = join(', ',@ok_bccs);
14593: }
14594: }
14595: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14596: }
14597: }
1.766 raeburn 14598: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14599: $lastresort = $origmail;
1.618 raeburn 14600: }
1.1075.2.139 raeburn 14601: if ($mailing eq 'helpdeskmail') {
14602: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14603: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14604: my ($inststatus,$inststatus_checked);
14605: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14606: ($env{'user.domain'} ne 'public')) {
14607: $inststatus_checked = 1;
14608: $inststatus = $env{'environment.inststatus'};
14609: }
14610: unless ($inststatus_checked) {
14611: if (($requname ne '') && ($requdom ne '')) {
14612: if (($requname =~ /^$match_username$/) &&
14613: ($requdom =~ /^$match_domain$/) &&
14614: (&Apache::lonnet::domain($requdom))) {
14615: my $requhome = &Apache::lonnet::homeserver($requname,
14616: $requdom);
14617: unless ($requhome eq 'no_host') {
14618: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14619: $inststatus = $userenv{'inststatus'};
14620: $inststatus_checked = 1;
14621: }
14622: }
14623: }
14624: }
14625: unless ($inststatus_checked) {
14626: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14627: my %srch = (srchby => 'email',
14628: srchdomain => $defdom,
14629: srchterm => $reqemail,
14630: srchtype => 'exact');
14631: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14632: foreach my $uname (keys(%srch_results)) {
14633: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14634: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14635: $inststatus_checked = 1;
14636: last;
14637: }
14638: }
14639: unless ($inststatus_checked) {
14640: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14641: if ($dirsrchres eq 'ok') {
14642: foreach my $uname (keys(%srch_results)) {
14643: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14644: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14645: $inststatus_checked = 1;
14646: last;
14647: }
14648: }
14649: }
14650: }
14651: }
14652: }
14653: if ($inststatus ne '') {
14654: foreach my $status (split(/\:/,$inststatus)) {
14655: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14656: my @contacts = ('adminemail','supportemail');
14657: foreach my $item (@contacts) {
14658: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14659: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14660: if (!grep(/^\Q$addr\E$/,@recipients)) {
14661: push(@recipients,$addr);
14662: }
14663: }
14664: }
14665: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14666: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14667: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14668: my @ok_bccs;
14669: foreach my $bcc (@bccs) {
14670: $bcc =~ s/^\s+//g;
14671: $bcc =~ s/\s+$//g;
14672: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14673: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14674: push(@ok_bccs,$bcc);
14675: }
14676: }
14677: }
14678: if (@ok_bccs > 0) {
14679: $allbcc = join(', ',@ok_bccs);
14680: }
14681: }
14682: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14683: last;
14684: }
14685: }
14686: }
14687: }
14688: }
1.619 raeburn 14689: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14690: $lastresort = $origmail;
14691: }
1.1075.2.128 raeburn 14692: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14693: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14694: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14695: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14696: my %what = (
14697: perlvar => 1,
14698: );
14699: my $primary = &Apache::lonnet::domain($defdom,'primary');
14700: if ($primary) {
14701: my $gotaddr;
14702: my ($result,$returnhash) =
14703: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14704: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14705: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14706: $lastresort = $returnhash->{'lonSupportEMail'};
14707: $gotaddr = 1;
14708: }
14709: }
14710: unless ($gotaddr) {
14711: my $uintdom = &Apache::lonnet::internet_dom($primary);
14712: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14713: unless ($uintdom eq $intdom) {
14714: my %domconfig =
14715: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14716: if (ref($domconfig{'contacts'}) eq 'HASH') {
14717: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14718: my @contacts = ('adminemail','supportemail');
14719: foreach my $item (@contacts) {
14720: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14721: my $addr = $domconfig{'contacts'}{$item};
14722: if (!grep(/^\Q$addr\E$/,@recipients)) {
14723: push(@recipients,$addr);
14724: }
14725: }
14726: }
14727: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14728: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14729: }
14730: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14731: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14732: my @ok_bccs;
14733: foreach my $bcc (@bccs) {
14734: $bcc =~ s/^\s+//g;
14735: $bcc =~ s/\s+$//g;
14736: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14737: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14738: push(@ok_bccs,$bcc);
14739: }
14740: }
14741: }
14742: if (@ok_bccs > 0) {
14743: $allbcc = join(', ',@ok_bccs);
14744: }
14745: }
14746: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14747: }
14748: }
14749: }
14750: }
14751: }
14752: }
1.618 raeburn 14753: }
1.688 raeburn 14754: if (defined($defmail)) {
14755: if ($defmail ne '') {
14756: push(@recipients,$defmail);
14757: }
1.618 raeburn 14758: }
14759: if ($otheremails) {
1.619 raeburn 14760: my @others;
14761: if ($otheremails =~ /,/) {
14762: @others = split(/,/,$otheremails);
1.618 raeburn 14763: } else {
1.619 raeburn 14764: push(@others,$otheremails);
14765: }
14766: foreach my $addr (@others) {
14767: if (!grep(/^\Q$addr\E$/,@recipients)) {
14768: push(@recipients,$addr);
14769: }
1.618 raeburn 14770: }
14771: }
1.1075.2.128 raeburn 14772: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14773: if ((!@recipients) && ($lastresort ne '')) {
14774: push(@recipients,$lastresort);
14775: }
14776: } elsif ($lastresort ne '') {
14777: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14778: push(@recipients,$lastresort);
14779: }
14780: }
14781: my $recipientlist = join(',',@recipients);
14782: if (wantarray) {
14783: return ($recipientlist,$allbcc,$addtext);
14784: } else {
14785: return $recipientlist;
14786: }
1.618 raeburn 14787: }
14788:
1.127 matthew 14789: ############################################################
14790: ############################################################
1.154 albertel 14791:
1.655 raeburn 14792: =pod
14793:
14794: =head1 Course Catalog Routines
14795:
14796: =over 4
14797:
14798: =item * &gather_categories()
14799:
14800: Converts category definitions - keys of categories hash stored in
14801: coursecategories in configuration.db on the primary library server in a
14802: domain - to an array. Also generates javascript and idx hash used to
14803: generate Domain Coordinator interface for editing Course Categories.
14804:
14805: Inputs:
1.663 raeburn 14806:
1.655 raeburn 14807: categories (reference to hash of category definitions).
1.663 raeburn 14808:
1.655 raeburn 14809: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14810: categories and subcategories).
1.663 raeburn 14811:
1.655 raeburn 14812: idx (reference to hash of counters used in Domain Coordinator interface for
14813: editing Course Categories).
1.663 raeburn 14814:
1.655 raeburn 14815: jsarray (reference to array of categories used to create Javascript arrays for
14816: Domain Coordinator interface for editing Course Categories).
14817:
14818: Returns: nothing
14819:
14820: Side effects: populates cats, idx and jsarray.
14821:
14822: =cut
14823:
14824: sub gather_categories {
14825: my ($categories,$cats,$idx,$jsarray) = @_;
14826: my %counters;
14827: my $num = 0;
14828: foreach my $item (keys(%{$categories})) {
14829: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14830: if ($container eq '' && $depth == 0) {
14831: $cats->[$depth][$categories->{$item}] = $cat;
14832: } else {
14833: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14834: }
14835: my ($escitem,$tail) = split(/:/,$item,2);
14836: if ($counters{$tail} eq '') {
14837: $counters{$tail} = $num;
14838: $num ++;
14839: }
14840: if (ref($idx) eq 'HASH') {
14841: $idx->{$item} = $counters{$tail};
14842: }
14843: if (ref($jsarray) eq 'ARRAY') {
14844: push(@{$jsarray->[$counters{$tail}]},$item);
14845: }
14846: }
14847: return;
14848: }
14849:
14850: =pod
14851:
14852: =item * &extract_categories()
14853:
14854: Used to generate breadcrumb trails for course categories.
14855:
14856: Inputs:
1.663 raeburn 14857:
1.655 raeburn 14858: categories (reference to hash of category definitions).
1.663 raeburn 14859:
1.655 raeburn 14860: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14861: categories and subcategories).
1.663 raeburn 14862:
1.655 raeburn 14863: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14864:
1.655 raeburn 14865: allitems (reference to hash - key is category key
14866: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14867:
1.655 raeburn 14868: idx (reference to hash of counters used in Domain Coordinator interface for
14869: editing Course Categories).
1.663 raeburn 14870:
1.655 raeburn 14871: jsarray (reference to array of categories used to create Javascript arrays for
14872: Domain Coordinator interface for editing Course Categories).
14873:
1.665 raeburn 14874: subcats (reference to hash of arrays containing all subcategories within each
14875: category, -recursive)
14876:
1.1075.2.132 raeburn 14877: maxd (reference to hash used to hold max depth for all top-level categories).
14878:
1.655 raeburn 14879: Returns: nothing
14880:
14881: Side effects: populates trails and allitems hash references.
14882:
14883: =cut
14884:
14885: sub extract_categories {
1.1075.2.132 raeburn 14886: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14887: if (ref($categories) eq 'HASH') {
14888: &gather_categories($categories,$cats,$idx,$jsarray);
14889: if (ref($cats->[0]) eq 'ARRAY') {
14890: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14891: my $name = $cats->[0][$i];
14892: my $item = &escape($name).'::0';
14893: my $trailstr;
14894: if ($name eq 'instcode') {
14895: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14896: } elsif ($name eq 'communities') {
14897: $trailstr = &mt('Communities');
1.655 raeburn 14898: } else {
14899: $trailstr = $name;
14900: }
14901: if ($allitems->{$item} eq '') {
14902: push(@{$trails},$trailstr);
14903: $allitems->{$item} = scalar(@{$trails})-1;
14904: }
14905: my @parents = ($name);
14906: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14907: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14908: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14909: if (ref($subcats) eq 'HASH') {
14910: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14911: }
1.1075.2.132 raeburn 14912: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14913: }
14914: } else {
14915: if (ref($subcats) eq 'HASH') {
14916: $subcats->{$item} = [];
1.655 raeburn 14917: }
1.1075.2.132 raeburn 14918: if (ref($maxd) eq 'HASH') {
14919: $maxd->{$name} = 1;
14920: }
1.655 raeburn 14921: }
14922: }
14923: }
14924: }
14925: return;
14926: }
14927:
14928: =pod
14929:
1.1075.2.56 raeburn 14930: =item * &recurse_categories()
1.655 raeburn 14931:
14932: Recursively used to generate breadcrumb trails for course categories.
14933:
14934: Inputs:
1.663 raeburn 14935:
1.655 raeburn 14936: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14937: categories and subcategories).
1.663 raeburn 14938:
1.655 raeburn 14939: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14940:
14941: category (current course category, for which breadcrumb trail is being generated).
14942:
14943: trails (reference to array of breadcrumb trails for each category).
14944:
1.655 raeburn 14945: allitems (reference to hash - key is category key
14946: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14947:
1.655 raeburn 14948: parents (array containing containers directories for current category,
14949: back to top level).
14950:
14951: Returns: nothing
14952:
14953: Side effects: populates trails and allitems hash references
14954:
14955: =cut
14956:
14957: sub recurse_categories {
1.1075.2.132 raeburn 14958: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14959: my $shallower = $depth - 1;
14960: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14961: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14962: my $name = $cats->[$depth]{$category}[$k];
14963: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.164 raeburn 14964: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14965: if ($allitems->{$item} eq '') {
14966: push(@{$trails},$trailstr);
14967: $allitems->{$item} = scalar(@{$trails})-1;
14968: }
14969: my $deeper = $depth+1;
14970: push(@{$parents},$category);
1.665 raeburn 14971: if (ref($subcats) eq 'HASH') {
14972: my $subcat = &escape($name).':'.$category.':'.$depth;
14973: for (my $j=@{$parents}; $j>=0; $j--) {
14974: my $higher;
14975: if ($j > 0) {
14976: $higher = &escape($parents->[$j]).':'.
14977: &escape($parents->[$j-1]).':'.$j;
14978: } else {
14979: $higher = &escape($parents->[$j]).'::'.$j;
14980: }
14981: push(@{$subcats->{$higher}},$subcat);
14982: }
14983: }
14984: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 14985: $subcats,$maxd);
1.655 raeburn 14986: pop(@{$parents});
14987: }
14988: } else {
14989: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 14990: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14991: if ($allitems->{$item} eq '') {
14992: push(@{$trails},$trailstr);
14993: $allitems->{$item} = scalar(@{$trails})-1;
14994: }
1.1075.2.132 raeburn 14995: if (ref($maxd) eq 'HASH') {
14996: if ($depth > $maxd->{$parents->[0]}) {
14997: $maxd->{$parents->[0]} = $depth;
14998: }
14999: }
1.655 raeburn 15000: }
15001: return;
15002: }
15003:
1.663 raeburn 15004: =pod
15005:
1.1075.2.56 raeburn 15006: =item * &assign_categories_table()
1.663 raeburn 15007:
15008: Create a datatable for display of hierarchical categories in a domain,
15009: with checkboxes to allow a course to be categorized.
15010:
15011: Inputs:
15012:
15013: cathash - reference to hash of categories defined for the domain (from
15014: configuration.db)
15015:
15016: currcat - scalar with an & separated list of categories assigned to a course.
15017:
1.919 raeburn 15018: type - scalar contains course type (Course or Community).
15019:
1.1075.2.117 raeburn 15020: disabled - scalar (optional) contains disabled="disabled" if input elements are
15021: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15022:
1.663 raeburn 15023: Returns: $output (markup to be displayed)
15024:
15025: =cut
15026:
15027: sub assign_categories_table {
1.1075.2.117 raeburn 15028: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15029: my $output;
15030: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 15031: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15032: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15033: $maxdepth = scalar(@cats);
15034: if (@cats > 0) {
15035: my $itemcount = 0;
15036: if (ref($cats[0]) eq 'ARRAY') {
15037: my @currcategories;
15038: if ($currcat ne '') {
15039: @currcategories = split('&',$currcat);
15040: }
1.919 raeburn 15041: my $table;
1.663 raeburn 15042: for (my $i=0; $i<@{$cats[0]}; $i++) {
15043: my $parent = $cats[0][$i];
1.919 raeburn 15044: next if ($parent eq 'instcode');
15045: if ($type eq 'Community') {
15046: next unless ($parent eq 'communities');
15047: } else {
15048: next if ($parent eq 'communities');
15049: }
1.663 raeburn 15050: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15051: my $item = &escape($parent).'::0';
15052: my $checked = '';
15053: if (@currcategories > 0) {
15054: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15055: $checked = ' checked="checked"';
1.663 raeburn 15056: }
15057: }
1.919 raeburn 15058: my $parent_title = $parent;
15059: if ($parent eq 'communities') {
15060: $parent_title = &mt('Communities');
15061: }
15062: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15063: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15064: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15065: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15066: my $depth = 1;
15067: push(@path,$parent);
1.1075.2.117 raeburn 15068: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15069: pop(@path);
1.919 raeburn 15070: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15071: $itemcount ++;
15072: }
1.919 raeburn 15073: if ($itemcount) {
15074: $output = &Apache::loncommon::start_data_table().
15075: $table.
15076: &Apache::loncommon::end_data_table();
15077: }
1.663 raeburn 15078: }
15079: }
15080: }
15081: return $output;
15082: }
15083:
15084: =pod
15085:
1.1075.2.56 raeburn 15086: =item * &assign_category_rows()
1.663 raeburn 15087:
15088: Create a datatable row for display of nested categories in a domain,
15089: with checkboxes to allow a course to be categorized,called recursively.
15090:
15091: Inputs:
15092:
15093: itemcount - track row number for alternating colors
15094:
15095: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15096: categories and subcategories.
15097:
15098: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15099:
15100: parent - parent of current category item
15101:
15102: path - Array containing all categories back up through the hierarchy from the
15103: current category to the top level.
15104:
15105: currcategories - reference to array of current categories assigned to the course
15106:
1.1075.2.117 raeburn 15107: disabled - scalar (optional) contains disabled="disabled" if input elements are
15108: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15109:
1.663 raeburn 15110: Returns: $output (markup to be displayed).
15111:
15112: =cut
15113:
15114: sub assign_category_rows {
1.1075.2.117 raeburn 15115: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15116: my ($text,$name,$item,$chgstr);
15117: if (ref($cats) eq 'ARRAY') {
15118: my $maxdepth = scalar(@{$cats});
15119: if (ref($cats->[$depth]) eq 'HASH') {
15120: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15121: my $numchildren = @{$cats->[$depth]{$parent}};
15122: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 15123: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15124: for (my $j=0; $j<$numchildren; $j++) {
15125: $name = $cats->[$depth]{$parent}[$j];
15126: $item = &escape($name).':'.&escape($parent).':'.$depth;
15127: my $deeper = $depth+1;
15128: my $checked = '';
15129: if (ref($currcategories) eq 'ARRAY') {
15130: if (@{$currcategories} > 0) {
15131: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15132: $checked = ' checked="checked"';
1.663 raeburn 15133: }
15134: }
15135: }
1.664 raeburn 15136: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15137: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15138: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15139: '<input type="hidden" name="catname" value="'.$name.'" />'.
15140: '</td><td>';
1.663 raeburn 15141: if (ref($path) eq 'ARRAY') {
15142: push(@{$path},$name);
1.1075.2.117 raeburn 15143: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15144: pop(@{$path});
15145: }
15146: $text .= '</td></tr>';
15147: }
15148: $text .= '</table></td>';
15149: }
15150: }
15151: }
15152: return $text;
15153: }
15154:
1.1075.2.69 raeburn 15155: =pod
15156:
15157: =back
15158:
15159: =cut
15160:
1.655 raeburn 15161: ############################################################
15162: ############################################################
15163:
15164:
1.443 albertel 15165: sub commit_customrole {
1.664 raeburn 15166: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15167: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15168: ($start?', '.&mt('starting').' '.localtime($start):'').
15169: ($end?', ending '.localtime($end):'').': <b>'.
15170: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15171: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15172: '</b><br />';
15173: return $output;
15174: }
15175:
15176: sub commit_standardrole {
1.1075.2.31 raeburn 15177: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15178: my ($output,$logmsg,$linefeed);
15179: if ($context eq 'auto') {
15180: $linefeed = "\n";
15181: } else {
15182: $linefeed = "<br />\n";
15183: }
1.443 albertel 15184: if ($three eq 'st') {
1.541 raeburn 15185: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 15186: $one,$two,$sec,$context,$credits);
1.541 raeburn 15187: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15188: ($result eq 'unknown_course') || ($result eq 'refused')) {
15189: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15190: } else {
1.541 raeburn 15191: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15192: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15193: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15194: if ($context eq 'auto') {
15195: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15196: } else {
15197: $output .= '<b>'.$result.'</b>'.$linefeed.
15198: &mt('Add to classlist').': <b>ok</b>';
15199: }
15200: $output .= $linefeed;
1.443 albertel 15201: }
15202: } else {
15203: $output = &mt('Assigning').' '.$three.' in '.$url.
15204: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15205: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15206: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15207: if ($context eq 'auto') {
15208: $output .= $result.$linefeed;
15209: } else {
15210: $output .= '<b>'.$result.'</b>'.$linefeed;
15211: }
1.443 albertel 15212: }
15213: return $output;
15214: }
15215:
15216: sub commit_studentrole {
1.1075.2.31 raeburn 15217: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15218: $credits) = @_;
1.626 raeburn 15219: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15220: if ($context eq 'auto') {
15221: $linefeed = "\n";
15222: } else {
15223: $linefeed = '<br />'."\n";
15224: }
1.443 albertel 15225: if (defined($one) && defined($two)) {
15226: my $cid=$one.'_'.$two;
15227: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15228: my $secchange = 0;
15229: my $expire_role_result;
15230: my $modify_section_result;
1.628 raeburn 15231: if ($oldsec ne '-1') {
15232: if ($oldsec ne $sec) {
1.443 albertel 15233: $secchange = 1;
1.628 raeburn 15234: my $now = time;
1.443 albertel 15235: my $uurl='/'.$cid;
15236: $uurl=~s/\_/\//g;
15237: if ($oldsec) {
15238: $uurl.='/'.$oldsec;
15239: }
1.626 raeburn 15240: $oldsecurl = $uurl;
1.628 raeburn 15241: $expire_role_result =
1.1075.2.167 raeburn 15242: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,
15243: '','','',$context);
1.628 raeburn 15244: if ($env{'request.course.sec'} ne '') {
15245: if ($expire_role_result eq 'refused') {
15246: my @roles = ('st');
15247: my @statuses = ('previous');
15248: my @roledoms = ($one);
15249: my $withsec = 1;
15250: my %roleshash =
15251: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15252: \@statuses,\@roles,\@roledoms,$withsec);
15253: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15254: my ($oldstart,$oldend) =
15255: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15256: if ($oldend > 0 && $oldend <= $now) {
15257: $expire_role_result = 'ok';
15258: }
15259: }
15260: }
15261: }
1.443 albertel 15262: $result = $expire_role_result;
15263: }
15264: }
15265: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 15266: $modify_section_result =
15267: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15268: undef,undef,undef,$sec,
15269: $end,$start,'','',$cid,
15270: '',$context,$credits);
1.443 albertel 15271: if ($modify_section_result =~ /^ok/) {
15272: if ($secchange == 1) {
1.628 raeburn 15273: if ($sec eq '') {
15274: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15275: } else {
15276: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15277: }
1.443 albertel 15278: } elsif ($oldsec eq '-1') {
1.628 raeburn 15279: if ($sec eq '') {
15280: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15281: } else {
15282: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15283: }
1.443 albertel 15284: } else {
1.628 raeburn 15285: if ($sec eq '') {
15286: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15287: } else {
15288: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15289: }
1.443 albertel 15290: }
15291: } else {
1.628 raeburn 15292: if ($secchange) {
15293: $$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;
15294: } else {
15295: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15296: }
1.443 albertel 15297: }
15298: $result = $modify_section_result;
15299: } elsif ($secchange == 1) {
1.628 raeburn 15300: if ($oldsec eq '') {
1.1075.2.20 raeburn 15301: $$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 15302: } else {
15303: $$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;
15304: }
1.626 raeburn 15305: if ($expire_role_result eq 'refused') {
15306: my $newsecurl = '/'.$cid;
15307: $newsecurl =~ s/\_/\//g;
15308: if ($sec ne '') {
15309: $newsecurl.='/'.$sec;
15310: }
15311: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15312: if ($sec eq '') {
15313: $$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;
15314: } else {
15315: $$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;
15316: }
15317: }
15318: }
1.443 albertel 15319: }
15320: } else {
1.626 raeburn 15321: $$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 15322: $result = "error: incomplete course id\n";
15323: }
15324: return $result;
15325: }
15326:
1.1075.2.25 raeburn 15327: sub show_role_extent {
15328: my ($scope,$context,$role) = @_;
15329: $scope =~ s{^/}{};
15330: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15331: push(@courseroles,'co');
15332: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15333: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15334: $scope =~ s{/}{_};
15335: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15336: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15337: my ($audom,$auname) = split(/\//,$scope);
15338: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15339: &Apache::loncommon::plainname($auname,$audom).'</span>');
15340: } else {
15341: $scope =~ s{/$}{};
15342: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15343: &Apache::lonnet::domain($scope,'description').'</span>');
15344: }
15345: }
15346:
1.443 albertel 15347: ############################################################
15348: ############################################################
15349:
1.566 albertel 15350: sub check_clone {
1.578 raeburn 15351: my ($args,$linefeed) = @_;
1.566 albertel 15352: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15353: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15354: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15355: my $clonemsg;
15356: my $can_clone = 0;
1.944 raeburn 15357: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15358: if ($lctype ne 'community') {
15359: $lctype = 'course';
15360: }
1.566 albertel 15361: if ($clonehome eq 'no_host') {
1.944 raeburn 15362: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15363: $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'});
15364: } else {
15365: $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'});
15366: }
1.566 albertel 15367: } else {
15368: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15369: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15370: if ($clonedesc{'type'} ne 'Community') {
15371: $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'});
15372: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15373: }
15374: }
1.1075.2.119 raeburn 15375: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15376: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15377: $can_clone = 1;
15378: } else {
1.1075.2.95 raeburn 15379: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15380: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 15381: if ($clonehash{'cloners'} eq '') {
15382: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15383: if ($domdefs{'canclone'}) {
15384: unless ($domdefs{'canclone'} eq 'none') {
15385: if ($domdefs{'canclone'} eq 'domain') {
15386: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15387: $can_clone = 1;
15388: }
15389: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15390: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15391: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15392: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15393: $can_clone = 1;
15394: }
15395: }
15396: }
1.908 raeburn 15397: }
1.1075.2.95 raeburn 15398: } else {
15399: my @cloners = split(/,/,$clonehash{'cloners'});
15400: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15401: $can_clone = 1;
1.1075.2.95 raeburn 15402: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15403: $can_clone = 1;
1.1075.2.96 raeburn 15404: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15405: $can_clone = 1;
1.1075.2.95 raeburn 15406: }
15407: unless ($can_clone) {
1.1075.2.96 raeburn 15408: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15409: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 15410: my (%gotdomdefaults,%gotcodedefaults);
15411: foreach my $cloner (@cloners) {
15412: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15413: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15414: my (%codedefaults,@code_order);
15415: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15416: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15417: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15418: }
15419: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15420: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15421: }
15422: } else {
15423: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15424: \%codedefaults,
15425: \@code_order);
15426: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15427: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15428: }
15429: if (@code_order > 0) {
15430: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15431: $cloner,$clonehash{'internal.coursecode'},
15432: $args->{'crscode'})) {
15433: $can_clone = 1;
15434: last;
15435: }
15436: }
15437: }
15438: }
15439: }
1.1075.2.96 raeburn 15440: }
15441: }
15442: unless ($can_clone) {
15443: my $ccrole = 'cc';
15444: if ($args->{'crstype'} eq 'Community') {
15445: $ccrole = 'co';
15446: }
15447: my %roleshash =
15448: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15449: $args->{'ccdomain'},
15450: 'userroles',['active'],[$ccrole],
15451: [$args->{'clonedomain'}]);
15452: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15453: $can_clone = 1;
15454: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15455: $args->{'ccuname'},$args->{'ccdomain'})) {
15456: $can_clone = 1;
1.1075.2.95 raeburn 15457: }
15458: }
15459: unless ($can_clone) {
15460: if ($args->{'crstype'} eq 'Community') {
15461: $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'});
15462: } else {
15463: $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 15464: }
1.566 albertel 15465: }
1.578 raeburn 15466: }
1.566 albertel 15467: }
15468: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15469: }
15470:
1.444 albertel 15471: sub construct_course {
1.1075.2.119 raeburn 15472: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15473: $cnum,$category,$coderef) = @_;
1.444 albertel 15474: my $outcome;
1.541 raeburn 15475: my $linefeed = '<br />'."\n";
15476: if ($context eq 'auto') {
15477: $linefeed = "\n";
15478: }
1.566 albertel 15479:
15480: #
15481: # Are we cloning?
15482: #
15483: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15484: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15485: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15486: if ($context ne 'auto') {
1.578 raeburn 15487: if ($clonemsg ne '') {
15488: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15489: }
1.566 albertel 15490: }
15491: $outcome .= $clonemsg.$linefeed;
15492:
15493: if (!$can_clone) {
15494: return (0,$outcome);
15495: }
15496: }
15497:
1.444 albertel 15498: #
15499: # Open course
15500: #
15501: my $crstype = lc($args->{'crstype'});
15502: my %cenv=();
15503: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15504: $args->{'cdescr'},
15505: $args->{'curl'},
15506: $args->{'course_home'},
15507: $args->{'nonstandard'},
15508: $args->{'crscode'},
15509: $args->{'ccuname'}.':'.
15510: $args->{'ccdomain'},
1.882 raeburn 15511: $args->{'crstype'},
1.885 raeburn 15512: $cnum,$context,$category);
1.444 albertel 15513:
15514: # Note: The testing routines depend on this being output; see
15515: # Utils::Course. This needs to at least be output as a comment
15516: # if anyone ever decides to not show this, and Utils::Course::new
15517: # will need to be suitably modified.
1.541 raeburn 15518: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 15519: if ($$courseid =~ /^error:/) {
15520: return (0,$outcome);
15521: }
15522:
1.444 albertel 15523: #
15524: # Check if created correctly
15525: #
1.479 albertel 15526: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15527: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15528: if ($crsuhome eq 'no_host') {
15529: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15530: return (0,$outcome);
15531: }
1.541 raeburn 15532: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15533:
1.444 albertel 15534: #
1.566 albertel 15535: # Do the cloning
15536: #
15537: if ($can_clone && $cloneid) {
15538: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
15539: if ($context ne 'auto') {
15540: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15541: }
15542: $outcome .= $clonemsg.$linefeed;
15543: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15544: # Copy all files
1.637 www 15545: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15546: # Restore URL
1.566 albertel 15547: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15548: # Restore title
1.566 albertel 15549: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15550: # Restore creation date, creator and creation context.
15551: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15552: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15553: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15554: # Mark as cloned
1.566 albertel 15555: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15556: # Need to clone grading mode
15557: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15558: $cenv{'grading'}=$newenv{'grading'};
15559: # Do not clone these environment entries
15560: &Apache::lonnet::del('environment',
15561: ['default_enrollment_start_date',
15562: 'default_enrollment_end_date',
15563: 'question.email',
15564: 'policy.email',
15565: 'comment.email',
15566: 'pch.users.denied',
1.725 raeburn 15567: 'plc.users.denied',
15568: 'hidefromcat',
1.1075.2.36 raeburn 15569: 'checkforpriv',
1.1075.2.158 raeburn 15570: 'categories'],
1.638 www 15571: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15572: if ($args->{'textbook'}) {
15573: $cenv{'internal.textbook'} = $args->{'textbook'};
15574: }
1.444 albertel 15575: }
1.566 albertel 15576:
1.444 albertel 15577: #
15578: # Set environment (will override cloned, if existing)
15579: #
15580: my @sections = ();
15581: my @xlists = ();
15582: if ($args->{'crstype'}) {
15583: $cenv{'type'}=$args->{'crstype'};
15584: }
15585: if ($args->{'crsid'}) {
15586: $cenv{'courseid'}=$args->{'crsid'};
15587: }
15588: if ($args->{'crscode'}) {
15589: $cenv{'internal.coursecode'}=$args->{'crscode'};
15590: }
15591: if ($args->{'crsquota'} ne '') {
15592: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15593: } else {
15594: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15595: }
15596: if ($args->{'ccuname'}) {
15597: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15598: ':'.$args->{'ccdomain'};
15599: } else {
15600: $cenv{'internal.courseowner'} = $args->{'curruser'};
15601: }
1.1075.2.31 raeburn 15602: if ($args->{'defaultcredits'}) {
15603: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15604: }
1.444 albertel 15605: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.1075.2.166 raeburn 15606: my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.
1.444 albertel 15607: if ($args->{'crssections'}) {
15608: $cenv{'internal.sectionnums'} = '';
15609: if ($args->{'crssections'} =~ m/,/) {
15610: @sections = split/,/,$args->{'crssections'};
15611: } else {
15612: $sections[0] = $args->{'crssections'};
15613: }
15614: if (@sections > 0) {
15615: foreach my $item (@sections) {
15616: my ($sec,$gp) = split/:/,$item;
15617: my $class = $args->{'crscode'}.$sec;
15618: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15619: $cenv{'internal.sectionnums'} .= $item.',';
1.1075.2.166 raeburn 15620: if ($addcheck eq 'ok') {
15621: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
15622: push(@oklcsecs,$gp);
15623: }
15624: } else {
1.1075.2.119 raeburn 15625: push(@badclasses,$class);
1.444 albertel 15626: }
15627: }
15628: $cenv{'internal.sectionnums'} =~ s/,$//;
15629: }
15630: }
15631: # do not hide course coordinator from staff listing,
15632: # even if privileged
15633: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15634: # add course coordinator's domain to domains to check for privileged users
15635: # if different to course domain
15636: if ($$crsudom ne $args->{'ccdomain'}) {
15637: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15638: }
1.444 albertel 15639: # add crosslistings
15640: if ($args->{'crsxlist'}) {
15641: $cenv{'internal.crosslistings'}='';
15642: if ($args->{'crsxlist'} =~ m/,/) {
15643: @xlists = split/,/,$args->{'crsxlist'};
15644: } else {
15645: $xlists[0] = $args->{'crsxlist'};
15646: }
15647: if (@xlists > 0) {
15648: foreach my $item (@xlists) {
15649: my ($xl,$gp) = split/:/,$item;
15650: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15651: $cenv{'internal.crosslistings'} .= $item.',';
1.1075.2.166 raeburn 15652: if ($addcheck eq 'ok') {
15653: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
15654: push(@oklcsecs,$gp);
15655: }
15656: } else {
1.1075.2.119 raeburn 15657: push(@badclasses,$xl);
1.444 albertel 15658: }
15659: }
15660: $cenv{'internal.crosslistings'} =~ s/,$//;
15661: }
15662: }
15663: if ($args->{'autoadds'}) {
15664: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15665: }
15666: if ($args->{'autodrops'}) {
15667: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15668: }
15669: # check for notification of enrollment changes
15670: my @notified = ();
15671: if ($args->{'notify_owner'}) {
15672: if ($args->{'ccuname'} ne '') {
15673: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15674: }
15675: }
15676: if ($args->{'notify_dc'}) {
15677: if ($uname ne '') {
1.630 raeburn 15678: push(@notified,$uname.':'.$udom);
1.444 albertel 15679: }
15680: }
15681: if (@notified > 0) {
15682: my $notifylist;
15683: if (@notified > 1) {
15684: $notifylist = join(',',@notified);
15685: } else {
15686: $notifylist = $notified[0];
15687: }
15688: $cenv{'internal.notifylist'} = $notifylist;
15689: }
15690: if (@badclasses > 0) {
15691: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15692: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15693: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15694: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15695: );
1.1075.2.119 raeburn 15696: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15697: &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 15698: if ($context eq 'auto') {
15699: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15700: } else {
1.566 albertel 15701: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15702: }
15703: foreach my $item (@badclasses) {
1.541 raeburn 15704: if ($context eq 'auto') {
1.1075.2.119 raeburn 15705: $outcome .= " - $item\n";
1.541 raeburn 15706: } else {
1.1075.2.119 raeburn 15707: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15708: }
1.1075.2.119 raeburn 15709: }
15710: if ($context eq 'auto') {
15711: $outcome .= $linefeed;
15712: } else {
15713: $outcome .= "</ul><br /><br /></div>\n";
15714: }
1.444 albertel 15715: }
15716: if ($args->{'no_end_date'}) {
15717: $args->{'endaccess'} = 0;
15718: }
1.1075.2.166 raeburn 15719: # If an official course with institutional sections is created by cloning
15720: # an existing course, section-specific hiding of course totals in student's
15721: # view of grades as copied from cloned course, will be checked for valid
15722: # sections.
15723: if (($can_clone && $cloneid) &&
15724: ($cenv{'internal.coursecode'} ne '') &&
15725: ($cenv{'grading'} eq 'standard') &&
15726: ($cenv{'hidetotals'} ne '') &&
15727: ($cenv{'hidetotals'} ne 'all')) {
15728: my @hidesecs;
15729: my $deletehidetotals;
15730: if (@oklcsecs) {
15731: foreach my $sec (split(/,/,$cenv{'hidetotals'})) {
15732: if (grep(/^\Q$sec$/,@oklcsecs)) {
15733: push(@hidesecs,$sec);
15734: }
15735: }
15736: if (@hidesecs) {
15737: $cenv{'hidetotals'} = join(',',@hidesecs);
15738: } else {
15739: $deletehidetotals = 1;
15740: }
15741: } else {
15742: $deletehidetotals = 1;
15743: }
15744: if ($deletehidetotals) {
15745: delete($cenv{'hidetotals'});
15746: &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);
15747: }
15748: }
1.444 albertel 15749: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15750: $cenv{'internal.autoend'}=$args->{'enrollend'};
15751: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15752: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15753: if ($args->{'showphotos'}) {
15754: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15755: }
15756: $cenv{'internal.authtype'} = $args->{'authtype'};
15757: $cenv{'internal.autharg'} = $args->{'autharg'};
15758: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15759: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15760: 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');
15761: if ($context eq 'auto') {
15762: $outcome .= $krb_msg;
15763: } else {
1.566 albertel 15764: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15765: }
15766: $outcome .= $linefeed;
1.444 albertel 15767: }
15768: }
15769: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15770: if ($args->{'setpolicy'}) {
15771: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15772: }
15773: if ($args->{'setcontent'}) {
15774: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15775: }
1.1075.2.110 raeburn 15776: if ($args->{'setcomment'}) {
15777: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15778: }
1.444 albertel 15779: }
15780: if ($args->{'reshome'}) {
15781: $cenv{'reshome'}=$args->{'reshome'}.'/';
15782: $cenv{'reshome'}=~s/\/+$/\//;
15783: }
15784: #
15785: # course has keyed access
15786: #
15787: if ($args->{'setkeys'}) {
15788: $cenv{'keyaccess'}='yes';
15789: }
15790: # if specified, key authority is not course, but user
15791: # only active if keyaccess is yes
15792: if ($args->{'keyauth'}) {
1.487 albertel 15793: my ($user,$domain) = split(':',$args->{'keyauth'});
15794: $user = &LONCAPA::clean_username($user);
15795: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15796: if ($user ne '' && $domain ne '') {
1.487 albertel 15797: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15798: }
15799: }
15800:
1.1075.2.59 raeburn 15801: #
15802: # generate and store uniquecode (available to course requester), if course should have one.
15803: #
15804: if ($args->{'uniquecode'}) {
15805: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15806: if ($code) {
15807: $cenv{'internal.uniquecode'} = $code;
15808: my %crsinfo =
15809: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15810: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15811: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15812: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15813: }
15814: if (ref($coderef)) {
15815: $$coderef = $code;
15816: }
15817: }
15818: }
15819:
1.444 albertel 15820: if ($args->{'disresdis'}) {
15821: $cenv{'pch.roles.denied'}='st';
15822: }
15823: if ($args->{'disablechat'}) {
15824: $cenv{'plc.roles.denied'}='st';
15825: }
15826:
15827: # Record we've not yet viewed the Course Initialization Helper for this
15828: # course
15829: $cenv{'course.helper.not.run'} = 1;
15830: #
15831: # Use new Randomseed
15832: #
15833: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15834: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15835: #
15836: # The encryption code and receipt prefix for this course
15837: #
15838: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15839: $cenv{'internal.encpref'}=100+int(9*rand(99));
15840: #
15841: # By default, use standard grading
15842: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15843:
1.541 raeburn 15844: $outcome .= $linefeed.&mt('Setting environment').': '.
15845: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15846: #
15847: # Open all assignments
15848: #
15849: if ($args->{'openall'}) {
1.1075.2.146 raeburn 15850: my $opendate = time;
15851: if ($args->{'openallfrom'} =~ /^\d+$/) {
15852: $opendate = $args->{'openallfrom'};
15853: }
1.444 albertel 15854: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 15855: my %storecontent = ($storeunder => $opendate,
1.444 albertel 15856: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 15857: $outcome .= &mt('All assignments open starting [_1]',
15858: &Apache::lonlocal::locallocaltime($opendate)).': '.
15859: &Apache::lonnet::cput
15860: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15861: }
15862: #
15863: # Set first page
15864: #
15865: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15866: || ($cloneid)) {
1.445 albertel 15867: use LONCAPA::map;
1.444 albertel 15868: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15869:
15870: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15871: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15872:
1.444 albertel 15873: $outcome .= ($fatal?$errtext:'read ok').' - ';
15874: my $title; my $url;
15875: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15876: $title=&mt('Syllabus');
1.444 albertel 15877: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15878: } else {
1.963 raeburn 15879: $title=&mt('Table of Contents');
1.444 albertel 15880: $url='/adm/navmaps';
15881: }
1.445 albertel 15882:
15883: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15884: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15885:
15886: if ($errtext) { $fatal=2; }
1.541 raeburn 15887: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15888: }
1.566 albertel 15889:
15890: return (1,$outcome);
1.444 albertel 15891: }
15892:
1.1075.2.59 raeburn 15893: sub make_unique_code {
15894: my ($cdom,$cnum) = @_;
15895: # get lock on uniquecodes db
15896: my $lockhash = {
15897: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15898: ':'.$env{'user.domain'},
15899: };
15900: my $tries = 0;
15901: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15902: my ($code,$error);
15903:
15904: while (($gotlock ne 'ok') && ($tries<3)) {
15905: $tries ++;
15906: sleep 1;
15907: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15908: }
15909: if ($gotlock eq 'ok') {
15910: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15911: my $gotcode;
15912: my $attempts = 0;
15913: while ((!$gotcode) && ($attempts < 100)) {
15914: $code = &generate_code();
15915: if (!exists($currcodes{$code})) {
15916: $gotcode = 1;
15917: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15918: $error = 'nostore';
15919: }
15920: }
15921: $attempts ++;
15922: }
15923: my @del_lock = ($cnum."\0".'uniquecodes');
15924: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15925: } else {
15926: $error = 'nolock';
15927: }
15928: return ($code,$error);
15929: }
15930:
15931: sub generate_code {
15932: my $code;
15933: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15934: for (my $i=0; $i<6; $i++) {
15935: my $lettnum = int (rand 2);
15936: my $item = '';
15937: if ($lettnum) {
15938: $item = $letts[int( rand(18) )];
15939: } else {
15940: $item = 1+int( rand(8) );
15941: }
15942: $code .= $item;
15943: }
15944: return $code;
15945: }
15946:
1.444 albertel 15947: ############################################################
15948: ############################################################
15949:
1.953 droeschl 15950: #SD
15951: # only Community and Course, or anything else?
1.378 raeburn 15952: sub course_type {
15953: my ($cid) = @_;
15954: if (!defined($cid)) {
15955: $cid = $env{'request.course.id'};
15956: }
1.404 albertel 15957: if (defined($env{'course.'.$cid.'.type'})) {
15958: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15959: } else {
15960: return 'Course';
1.377 raeburn 15961: }
15962: }
1.156 albertel 15963:
1.406 raeburn 15964: sub group_term {
15965: my $crstype = &course_type();
15966: my %names = (
15967: 'Course' => 'group',
1.865 raeburn 15968: 'Community' => 'group',
1.406 raeburn 15969: );
15970: return $names{$crstype};
15971: }
15972:
1.902 raeburn 15973: sub course_types {
1.1075.2.59 raeburn 15974: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15975: my %typename = (
15976: official => 'Official course',
15977: unofficial => 'Unofficial course',
15978: community => 'Community',
1.1075.2.59 raeburn 15979: textbook => 'Textbook course',
1.902 raeburn 15980: );
15981: return (\@types,\%typename);
15982: }
15983:
1.156 albertel 15984: sub icon {
15985: my ($file)=@_;
1.505 albertel 15986: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15987: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15988: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15989: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15990: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15991: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15992: $curfext.".gif") {
15993: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15994: $curfext.".gif";
15995: }
15996: }
1.249 albertel 15997: return &lonhttpdurl($iconname);
1.154 albertel 15998: }
1.84 albertel 15999:
1.575 albertel 16000: sub lonhttpdurl {
1.692 www 16001: #
16002: # Had been used for "small fry" static images on separate port 8080.
16003: # Modify here if lightweight http functionality desired again.
16004: # Currently eliminated due to increasing firewall issues.
16005: #
1.575 albertel 16006: my ($url)=@_;
1.692 www 16007: return $url;
1.215 albertel 16008: }
16009:
1.213 albertel 16010: sub connection_aborted {
16011: my ($r)=@_;
16012: $r->print(" ");$r->rflush();
16013: my $c = $r->connection;
16014: return $c->aborted();
16015: }
16016:
1.221 foxr 16017: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16018: # strings as 'strings'.
16019: sub escape_single {
1.221 foxr 16020: my ($input) = @_;
1.223 albertel 16021: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16022: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16023: return $input;
16024: }
1.223 albertel 16025:
1.222 foxr 16026: # Same as escape_single, but escape's "'s This
16027: # can be used for "strings"
16028: sub escape_double {
16029: my ($input) = @_;
16030: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16031: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16032: return $input;
16033: }
1.223 albertel 16034:
1.222 foxr 16035: # Escapes the last element of a full URL.
16036: sub escape_url {
16037: my ($url) = @_;
1.238 raeburn 16038: my @urlslices = split(/\//, $url,-1);
1.369 www 16039: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 16040: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16041: }
1.462 albertel 16042:
1.820 raeburn 16043: sub compare_arrays {
16044: my ($arrayref1,$arrayref2) = @_;
16045: my (@difference,%count);
16046: @difference = ();
16047: %count = ();
16048: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16049: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16050: foreach my $element (keys(%count)) {
16051: if ($count{$element} == 1) {
16052: push(@difference,$element);
16053: }
16054: }
16055: }
16056: return @difference;
16057: }
16058:
1.1075.2.152 raeburn 16059: sub lon_status_items {
16060: my %defaults = (
16061: E => 100,
16062: W => 4,
16063: N => 1,
16064: U => 5,
16065: threshold => 200,
16066: sysmail => 2500,
16067: );
16068: my %names = (
16069: E => 'Errors',
16070: W => 'Warnings',
16071: N => 'Notices',
16072: U => 'Unsent',
16073: );
16074: return (\%defaults,\%names);
16075: }
16076:
1.817 bisitz 16077: # -------------------------------------------------------- Initialize user login
1.462 albertel 16078: sub init_user_environment {
1.463 albertel 16079: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16080: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16081:
16082: my $public=($username eq 'public' && $domain eq 'public');
16083:
16084: # See if old ID present, if so, remove
16085:
1.1062 raeburn 16086: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16087: my $now=time;
16088:
16089: if ($public) {
16090: my $max_public=100;
16091: my $oldest;
16092: my $oldest_time=0;
16093: for(my $next=1;$next<=$max_public;$next++) {
16094: if (-e $lonids."/publicuser_$next.id") {
16095: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16096: if ($mtime<$oldest_time || !$oldest_time) {
16097: $oldest_time=$mtime;
16098: $oldest=$next;
16099: }
16100: } else {
16101: $cookie="publicuser_$next";
16102: last;
16103: }
16104: }
16105: if (!$cookie) { $cookie="publicuser_$oldest"; }
16106: } else {
1.463 albertel 16107: # if this isn't a robot, kill any existing non-robot sessions
16108: if (!$args->{'robot'}) {
16109: opendir(DIR,$lonids);
16110: while ($filename=readdir(DIR)) {
16111: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 16112: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16113: &GDBM_READER(),0640)) {
16114: my $linkedfile;
16115: if (exists($oldenv{'user.linkedenv'})) {
16116: $linkedfile = $oldenv{'user.linkedenv'};
16117: }
16118: untie(%oldenv);
16119: if (unlink("$lonids/$filename")) {
16120: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16121: if (-l "$lonids/$linkedfile.id") {
16122: unlink("$lonids/$linkedfile.id");
16123: }
16124: }
16125: }
16126: } else {
16127: unlink($lonids.'/'.$filename);
16128: }
1.463 albertel 16129: }
1.462 albertel 16130: }
1.463 albertel 16131: closedir(DIR);
1.1075.2.84 raeburn 16132: # If there is a undeleted lockfile for the user's paste buffer remove it.
16133: my $namespace = 'nohist_courseeditor';
16134: my $lockingkey = 'paste'."\0".'locked_num';
16135: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16136: $domain,$username);
16137: if (exists($lockhash{$lockingkey})) {
16138: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16139: unless ($delresult eq 'ok') {
16140: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16141: }
16142: }
1.462 albertel 16143: }
16144: # Give them a new cookie
1.463 albertel 16145: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16146: : $now.$$.int(rand(10000)));
1.463 albertel 16147: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16148:
16149: # Initialize roles
16150:
1.1062 raeburn 16151: ($userroles,$firstaccenv,$timerintenv) =
16152: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16153: }
16154: # ------------------------------------ Check browser type and MathML capability
16155:
1.1075.2.77 raeburn 16156: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16157: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16158:
16159: # ------------------------------------------------------------- Get environment
16160:
16161: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16162: my ($tmp) = keys(%userenv);
16163: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
16164: } else {
16165: undef(%userenv);
16166: }
16167: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16168: $form->{'interface'}=$userenv{'interface'};
16169: }
16170: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16171:
16172: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16173: foreach my $option ('interface','localpath','localres') {
16174: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16175: }
16176: # --------------------------------------------------------- Write first profile
16177:
16178: {
1.1075.2.150 raeburn 16179: my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 16180: my %initial_env =
16181: ("user.name" => $username,
16182: "user.domain" => $domain,
16183: "user.home" => $authhost,
16184: "browser.type" => $clientbrowser,
16185: "browser.version" => $clientversion,
16186: "browser.mathml" => $clientmathml,
16187: "browser.unicode" => $clientunicode,
16188: "browser.os" => $clientos,
1.1075.2.42 raeburn 16189: "browser.mobile" => $clientmobile,
16190: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 16191: "browser.osversion" => $clientosversion,
1.462 albertel 16192: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16193: "request.course.fn" => '',
16194: "request.course.uri" => '',
16195: "request.course.sec" => '',
16196: "request.role" => 'cm',
16197: "request.role.adv" => $env{'user.adv'},
1.1075.2.150 raeburn 16198: "request.host" => $ip,);
1.462 albertel 16199:
16200: if ($form->{'localpath'}) {
16201: $initial_env{"browser.localpath"} = $form->{'localpath'};
16202: $initial_env{"browser.localres"} = $form->{'localres'};
16203: }
16204:
16205: if ($form->{'interface'}) {
16206: $form->{'interface'}=~s/\W//gs;
16207: $initial_env{"browser.interface"} = $form->{'interface'};
16208: $env{'browser.interface'}=$form->{'interface'};
16209: }
16210:
1.1075.2.54 raeburn 16211: if ($form->{'iptoken'}) {
16212: my $lonhost = $r->dir_config('lonHostID');
16213: $initial_env{"user.noloadbalance"} = $lonhost;
16214: $env{'user.noloadbalance'} = $lonhost;
16215: }
16216:
1.1075.2.120 raeburn 16217: if ($form->{'noloadbalance'}) {
16218: my @hosts = &Apache::lonnet::current_machine_ids();
16219: my $hosthere = $form->{'noloadbalance'};
16220: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16221: $initial_env{"user.noloadbalance"} = $hosthere;
16222: $env{'user.noloadbalance'} = $hosthere;
16223: }
16224: }
16225:
1.1016 raeburn 16226: unless ($domain eq 'public') {
1.1075.2.125 raeburn 16227: my %is_adv = ( is_adv => $env{'user.adv'} );
16228: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 16229:
1.1075.2.125 raeburn 16230: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16231: $userenv{'availabletools.'.$tool} =
16232: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16233: undef,\%userenv,\%domdef,\%is_adv);
16234: }
1.724 raeburn 16235:
1.1075.2.125 raeburn 16236: foreach my $crstype ('official','unofficial','community','textbook') {
16237: $userenv{'canrequest.'.$crstype} =
16238: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16239: 'reload','requestcourses',
16240: \%userenv,\%domdef,\%is_adv);
16241: }
1.765 raeburn 16242:
1.1075.2.125 raeburn 16243: $userenv{'canrequest.author'} =
16244: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16245: 'reload','requestauthor',
16246: \%userenv,\%domdef,\%is_adv);
16247: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16248: $domain,$username);
16249: my $reqstatus = $reqauthor{'author_status'};
16250: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16251: if (ref($reqauthor{'author'}) eq 'HASH') {
16252: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16253: $reqauthor{'author'}{'timestamp'};
16254: }
1.1075.2.14 raeburn 16255: }
16256: }
16257:
1.462 albertel 16258: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16259:
1.462 albertel 16260: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16261: &GDBM_WRCREAT(),0640)) {
16262: &_add_to_env(\%disk_env,\%initial_env);
16263: &_add_to_env(\%disk_env,\%userenv,'environment.');
16264: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16265: if (ref($firstaccenv) eq 'HASH') {
16266: &_add_to_env(\%disk_env,$firstaccenv);
16267: }
16268: if (ref($timerintenv) eq 'HASH') {
16269: &_add_to_env(\%disk_env,$timerintenv);
16270: }
1.463 albertel 16271: if (ref($args->{'extra_env'})) {
16272: &_add_to_env(\%disk_env,$args->{'extra_env'});
16273: }
1.462 albertel 16274: untie(%disk_env);
16275: } else {
1.705 tempelho 16276: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16277: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16278: return 'error: '.$!;
16279: }
16280: }
16281: $env{'request.role'}='cm';
16282: $env{'request.role.adv'}=$env{'user.adv'};
16283: $env{'browser.type'}=$clientbrowser;
16284:
16285: return $cookie;
16286:
16287: }
16288:
16289: sub _add_to_env {
16290: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16291: if (ref($env_data) eq 'HASH') {
16292: while (my ($key,$value) = each(%$env_data)) {
16293: $idf->{$prefix.$key} = $value;
16294: $env{$prefix.$key} = $value;
16295: }
1.462 albertel 16296: }
16297: }
16298:
1.685 tempelho 16299: # --- Get the symbolic name of a problem and the url
16300: sub get_symb {
16301: my ($request,$silent) = @_;
1.726 raeburn 16302: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16303: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16304: if ($symb eq '') {
16305: if (!$silent) {
1.1071 raeburn 16306: if (ref($request)) {
16307: $request->print("Unable to handle ambiguous references:$url:.");
16308: }
1.685 tempelho 16309: return ();
16310: }
16311: }
16312: &Apache::lonenc::check_decrypt(\$symb);
16313: return ($symb);
16314: }
16315:
16316: # --------------------------------------------------------------Get annotation
16317:
16318: sub get_annotation {
16319: my ($symb,$enc) = @_;
16320:
16321: my $key = $symb;
16322: if (!$enc) {
16323: $key =
16324: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16325: }
16326: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16327: return $annotation{$key};
16328: }
16329:
16330: sub clean_symb {
1.731 raeburn 16331: my ($symb,$delete_enc) = @_;
1.685 tempelho 16332:
16333: &Apache::lonenc::check_decrypt(\$symb);
16334: my $enc = $env{'request.enc'};
1.731 raeburn 16335: if ($delete_enc) {
1.730 raeburn 16336: delete($env{'request.enc'});
16337: }
1.685 tempelho 16338:
16339: return ($symb,$enc);
16340: }
1.462 albertel 16341:
1.1075.2.69 raeburn 16342: ############################################################
16343: ############################################################
16344:
16345: =pod
16346:
16347: =head1 Routines for building display used to search for courses
16348:
16349:
16350: =over 4
16351:
16352: =item * &build_filters()
16353:
16354: Create markup for a table used to set filters to use when selecting
16355: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16356: and quotacheck.pl
16357:
16358:
16359: Inputs:
16360:
16361: filterlist - anonymous array of fields to include as potential filters
16362:
16363: crstype - course type
16364:
16365: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16366: to pop-open a course selector (will contain "extra element").
16367:
16368: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16369:
16370: filter - anonymous hash of criteria and their values
16371:
16372: action - form action
16373:
16374: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16375:
16376: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
16377:
16378: cloneruname - username of owner of new course who wants to clone
16379:
16380: clonerudom - domain of owner of new course who wants to clone
16381:
16382: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16383:
16384: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16385:
16386: codedom - domain
16387:
16388: formname - value of form element named "form".
16389:
16390: fixeddom - domain, if fixed.
16391:
16392: prevphase - value to assign to form element named "phase" when going back to the previous screen
16393:
16394: cnameelement - name of form element in form on opener page which will receive title of selected course
16395:
16396: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16397:
16398: cdomelement - name of form element in form on opener page which will receive domain of selected course
16399:
16400: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16401:
16402: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16403:
16404: clonewarning - warning message about missing information for intended course owner when DC creates a course
16405:
16406:
16407: Returns: $output - HTML for display of search criteria, and hidden form elements.
16408:
16409:
16410: Side Effects: None
16411:
16412: =cut
16413:
16414: # ---------------------------------------------- search for courses based on last activity etc.
16415:
16416: sub build_filters {
16417: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16418: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16419: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16420: $cnameelement,$cnumelement,$cdomelement,$setroles,
16421: $clonetext,$clonewarning) = @_;
16422: my ($list,$jscript);
16423: my $onchange = 'javascript:updateFilters(this)';
16424: my ($domainselectform,$sincefilterform,$createdfilterform,
16425: $ownerdomselectform,$persondomselectform,$instcodeform,
16426: $typeselectform,$instcodetitle);
16427: if ($formname eq '') {
16428: $formname = $caller;
16429: }
16430: foreach my $item (@{$filterlist}) {
16431: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16432: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16433: if ($item eq 'domainfilter') {
16434: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16435: } elsif ($item eq 'coursefilter') {
16436: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16437: } elsif ($item eq 'ownerfilter') {
16438: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16439: } elsif ($item eq 'ownerdomfilter') {
16440: $filter->{'ownerdomfilter'} =
16441: &LONCAPA::clean_domain($filter->{$item});
16442: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16443: 'ownerdomfilter',1);
16444: } elsif ($item eq 'personfilter') {
16445: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16446: } elsif ($item eq 'persondomfilter') {
16447: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16448: 'persondomfilter',1);
16449: } else {
16450: $filter->{$item} =~ s/\W//g;
16451: }
16452: if (!$filter->{$item}) {
16453: $filter->{$item} = '';
16454: }
16455: }
16456: if ($item eq 'domainfilter') {
16457: my $allow_blank = 1;
16458: if ($formname eq 'portform') {
16459: $allow_blank=0;
16460: } elsif ($formname eq 'studentform') {
16461: $allow_blank=0;
16462: }
16463: if ($fixeddom) {
16464: $domainselectform = '<input type="hidden" name="domainfilter"'.
16465: ' value="'.$codedom.'" />'.
16466: &Apache::lonnet::domain($codedom,'description');
16467: } else {
16468: $domainselectform = &select_dom_form($filter->{$item},
16469: 'domainfilter',
16470: $allow_blank,'',$onchange);
16471: }
16472: } else {
16473: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16474: }
16475: }
16476:
16477: # last course activity filter and selection
16478: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16479:
16480: # course created filter and selection
16481: if (exists($filter->{'createdfilter'})) {
16482: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16483: }
16484:
16485: my %lt = &Apache::lonlocal::texthash(
16486: 'cac' => "$crstype Activity",
16487: 'ccr' => "$crstype Created",
16488: 'cde' => "$crstype Title",
16489: 'cdo' => "$crstype Domain",
16490: 'ins' => 'Institutional Code',
16491: 'inc' => 'Institutional Categorization',
16492: 'cow' => "$crstype Owner/Co-owner",
16493: 'cop' => "$crstype Personnel Includes",
16494: 'cog' => 'Type',
16495: );
16496:
16497: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16498: my $typeval = 'Course';
16499: if ($crstype eq 'Community') {
16500: $typeval = 'Community';
16501: }
16502: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16503: } else {
16504: $typeselectform = '<select name="type" size="1"';
16505: if ($onchange) {
16506: $typeselectform .= ' onchange="'.$onchange.'"';
16507: }
16508: $typeselectform .= '>'."\n";
16509: foreach my $posstype ('Course','Community') {
16510: $typeselectform.='<option value="'.$posstype.'"'.
16511: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16512: }
16513: $typeselectform.="</select>";
16514: }
16515:
16516: my ($cloneableonlyform,$cloneabletitle);
16517: if (exists($filter->{'cloneableonly'})) {
16518: my $cloneableon = '';
16519: my $cloneableoff = ' checked="checked"';
16520: if ($filter->{'cloneableonly'}) {
16521: $cloneableon = $cloneableoff;
16522: $cloneableoff = '';
16523: }
16524: $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>';
16525: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16526: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16527: } else {
16528: $cloneabletitle = &mt('Cloneable by you');
16529: }
16530: }
16531: my $officialjs;
16532: if ($crstype eq 'Course') {
16533: if (exists($filter->{'instcodefilter'})) {
16534: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16535: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16536: if ($codedom) {
16537: $officialjs = 1;
16538: ($instcodeform,$jscript,$$numtitlesref) =
16539: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16540: $officialjs,$codetitlesref);
16541: if ($jscript) {
16542: $jscript = '<script type="text/javascript">'."\n".
16543: '// <![CDATA['."\n".
16544: $jscript."\n".
16545: '// ]]>'."\n".
16546: '</script>'."\n";
16547: }
16548: }
16549: if ($instcodeform eq '') {
16550: $instcodeform =
16551: '<input type="text" name="instcodefilter" size="10" value="'.
16552: $list->{'instcodefilter'}.'" />';
16553: $instcodetitle = $lt{'ins'};
16554: } else {
16555: $instcodetitle = $lt{'inc'};
16556: }
16557: if ($fixeddom) {
16558: $instcodetitle .= '<br />('.$codedom.')';
16559: }
16560: }
16561: }
16562: my $output = qq|
16563: <form method="post" name="filterpicker" action="$action">
16564: <input type="hidden" name="form" value="$formname" />
16565: |;
16566: if ($formname eq 'modifycourse') {
16567: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16568: '<input type="hidden" name="prevphase" value="'.
16569: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16570: } elsif ($formname eq 'quotacheck') {
16571: $output .= qq|
16572: <input type="hidden" name="sortby" value="" />
16573: <input type="hidden" name="sortorder" value="" />
16574: |;
16575: } else {
1.1075.2.69 raeburn 16576: my $name_input;
16577: if ($cnameelement ne '') {
16578: $name_input = '<input type="hidden" name="cnameelement" value="'.
16579: $cnameelement.'" />';
16580: }
16581: $output .= qq|
16582: <input type="hidden" name="cnumelement" value="$cnumelement" />
16583: <input type="hidden" name="cdomelement" value="$cdomelement" />
16584: $name_input
16585: $roleelement
16586: $multelement
16587: $typeelement
16588: |;
16589: if ($formname eq 'portform') {
16590: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16591: }
16592: }
16593: if ($fixeddom) {
16594: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16595: }
16596: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16597: if ($sincefilterform) {
16598: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16599: .$sincefilterform
16600: .&Apache::lonhtmlcommon::row_closure();
16601: }
16602: if ($createdfilterform) {
16603: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16604: .$createdfilterform
16605: .&Apache::lonhtmlcommon::row_closure();
16606: }
16607: if ($domainselectform) {
16608: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16609: .$domainselectform
16610: .&Apache::lonhtmlcommon::row_closure();
16611: }
16612: if ($typeselectform) {
16613: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16614: $output .= $typeselectform;
16615: } else {
16616: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16617: .$typeselectform
16618: .&Apache::lonhtmlcommon::row_closure();
16619: }
16620: }
16621: if ($instcodeform) {
16622: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16623: .$instcodeform
16624: .&Apache::lonhtmlcommon::row_closure();
16625: }
16626: if (exists($filter->{'ownerfilter'})) {
16627: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16628: '<table><tr><td>'.&mt('Username').'<br />'.
16629: '<input type="text" name="ownerfilter" size="20" value="'.
16630: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16631: $ownerdomselectform.'</td></tr></table>'.
16632: &Apache::lonhtmlcommon::row_closure();
16633: }
16634: if (exists($filter->{'personfilter'})) {
16635: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16636: '<table><tr><td>'.&mt('Username').'<br />'.
16637: '<input type="text" name="personfilter" size="20" value="'.
16638: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16639: $persondomselectform.'</td></tr></table>'.
16640: &Apache::lonhtmlcommon::row_closure();
16641: }
16642: if (exists($filter->{'coursefilter'})) {
16643: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16644: .'<input type="text" name="coursefilter" size="25" value="'
16645: .$list->{'coursefilter'}.'" />'
16646: .&Apache::lonhtmlcommon::row_closure();
16647: }
16648: if ($cloneableonlyform) {
16649: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16650: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16651: }
16652: if (exists($filter->{'descriptfilter'})) {
16653: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16654: .'<input type="text" name="descriptfilter" size="40" value="'
16655: .$list->{'descriptfilter'}.'" />'
16656: .&Apache::lonhtmlcommon::row_closure(1);
16657: }
16658: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16659: '<input type="hidden" name="updater" value="" />'."\n".
16660: '<input type="submit" name="gosearch" value="'.
16661: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16662: return $jscript.$clonewarning.$output;
16663: }
16664:
16665: =pod
16666:
16667: =item * &timebased_select_form()
16668:
16669: Create markup for a dropdown list used to select a time-based
16670: filter e.g., Course Activity, Course Created, when searching for courses
16671: or communities
16672:
16673: Inputs:
16674:
16675: item - name of form element (sincefilter or createdfilter)
16676:
16677: filter - anonymous hash of criteria and their values
16678:
16679: Returns: HTML for a select box contained a blank, then six time selections,
16680: with value set in incoming form variables currently selected.
16681:
16682: Side Effects: None
16683:
16684: =cut
16685:
16686: sub timebased_select_form {
16687: my ($item,$filter) = @_;
16688: if (ref($filter) eq 'HASH') {
16689: $filter->{$item} =~ s/[^\d-]//g;
16690: if (!$filter->{$item}) { $filter->{$item}=-1; }
16691: return &select_form(
16692: $filter->{$item},
16693: $item,
16694: { '-1' => '',
16695: '86400' => &mt('today'),
16696: '604800' => &mt('last week'),
16697: '2592000' => &mt('last month'),
16698: '7776000' => &mt('last three months'),
16699: '15552000' => &mt('last six months'),
16700: '31104000' => &mt('last year'),
16701: 'select_form_order' =>
16702: ['-1','86400','604800','2592000','7776000',
16703: '15552000','31104000']});
16704: }
16705: }
16706:
16707: =pod
16708:
16709: =item * &js_changer()
16710:
16711: Create script tag containing Javascript used to submit course search form
16712: when course type or domain is changed, and also to hide 'Searching ...' on
16713: page load completion for page showing search result.
16714:
16715: Inputs: None
16716:
16717: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16718:
16719: Side Effects: None
16720:
16721: =cut
16722:
16723: sub js_changer {
16724: return <<ENDJS;
16725: <script type="text/javascript">
16726: // <![CDATA[
16727: function updateFilters(caller) {
16728: if (typeof(caller) != "undefined") {
16729: document.filterpicker.updater.value = caller.name;
16730: }
16731: document.filterpicker.submit();
16732: }
16733:
16734: function hideSearching() {
16735: if (document.getElementById('searching')) {
16736: document.getElementById('searching').style.display = 'none';
16737: }
16738: return;
16739: }
16740:
16741: // ]]>
16742: </script>
16743:
16744: ENDJS
16745: }
16746:
16747: =pod
16748:
16749: =item * &search_courses()
16750:
16751: Process selected filters form course search form and pass to lonnet::courseiddump
16752: to retrieve a hash for which keys are courseIDs which match the selected filters.
16753:
16754: Inputs:
16755:
16756: dom - domain being searched
16757:
16758: type - course type ('Course' or 'Community' or '.' if any).
16759:
16760: filter - anonymous hash of criteria and their values
16761:
16762: numtitles - for institutional codes - number of categories
16763:
16764: cloneruname - optional username of new course owner
16765:
16766: clonerudom - optional domain of new course owner
16767:
1.1075.2.95 raeburn 16768: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16769: (used when DC is using course creation form)
16770:
16771: codetitles - reference to array of titles of components in institutional codes (official courses).
16772:
1.1075.2.95 raeburn 16773: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16774: (and so can clone automatically)
16775:
16776: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16777:
16778: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16779: courses to clone
1.1075.2.69 raeburn 16780:
16781: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16782:
16783:
16784: Side Effects: None
16785:
16786: =cut
16787:
16788:
16789: sub search_courses {
1.1075.2.95 raeburn 16790: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16791: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16792: my (%courses,%showcourses,$cloner);
16793: if (($filter->{'ownerfilter'} ne '') ||
16794: ($filter->{'ownerdomfilter'} ne '')) {
16795: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16796: $filter->{'ownerdomfilter'};
16797: }
16798: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16799: if (!$filter->{$item}) {
16800: $filter->{$item}='.';
16801: }
16802: }
16803: my $now = time;
16804: my $timefilter =
16805: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16806: my ($createdbefore,$createdafter);
16807: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16808: $createdbefore = $now;
16809: $createdafter = $now-$filter->{'createdfilter'};
16810: }
16811: my ($instcodefilter,$regexpok);
16812: if ($numtitles) {
16813: if ($env{'form.official'} eq 'on') {
16814: $instcodefilter =
16815: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16816: $regexpok = 1;
16817: } elsif ($env{'form.official'} eq 'off') {
16818: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16819: unless ($instcodefilter eq '') {
16820: $regexpok = -1;
16821: }
16822: }
16823: } else {
16824: $instcodefilter = $filter->{'instcodefilter'};
16825: }
16826: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16827: if ($type eq '') { $type = '.'; }
16828:
16829: if (($clonerudom ne '') && ($cloneruname ne '')) {
16830: $cloner = $cloneruname.':'.$clonerudom;
16831: }
16832: %courses = &Apache::lonnet::courseiddump($dom,
16833: $filter->{'descriptfilter'},
16834: $timefilter,
16835: $instcodefilter,
16836: $filter->{'combownerfilter'},
16837: $filter->{'coursefilter'},
16838: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16839: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16840: $filter->{'cloneableonly'},
16841: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16842: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16843: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16844: my $ccrole;
16845: if ($type eq 'Community') {
16846: $ccrole = 'co';
16847: } else {
16848: $ccrole = 'cc';
16849: }
16850: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16851: $filter->{'persondomfilter'},
16852: 'userroles',undef,
16853: [$ccrole,'in','ad','ep','ta','cr'],
16854: $dom);
16855: foreach my $role (keys(%rolehash)) {
16856: my ($cnum,$cdom,$courserole) = split(':',$role);
16857: my $cid = $cdom.'_'.$cnum;
16858: if (exists($courses{$cid})) {
16859: if (ref($courses{$cid}) eq 'HASH') {
16860: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16861: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16862: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16863: }
16864: } else {
16865: $courses{$cid}{roles} = [$courserole];
16866: }
16867: $showcourses{$cid} = $courses{$cid};
16868: }
16869: }
16870: }
16871: %courses = %showcourses;
16872: }
16873: return %courses;
16874: }
16875:
16876: =pod
16877:
16878: =back
16879:
1.1075.2.88 raeburn 16880: =head1 Routines for version requirements for current course.
16881:
16882: =over 4
16883:
16884: =item * &check_release_required()
16885:
16886: Compares required LON-CAPA version with version on server, and
16887: if required version is newer looks for a server with the required version.
16888:
16889: Looks first at servers in user's owen domain; if none suitable, looks at
16890: servers in course's domain are permitted to host sessions for user's domain.
16891:
16892: Inputs:
16893:
16894: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16895:
16896: $courseid - Course ID of current course
16897:
16898: $rolecode - User's current role in course (for switchserver query string).
16899:
16900: $required - LON-CAPA version needed by course (format: Major.Minor).
16901:
16902:
16903: Returns:
16904:
16905: $switchserver - query string tp append to /adm/switchserver call (if
16906: current server's LON-CAPA version is too old.
16907:
16908: $warning - Message is displayed if no suitable server could be found.
16909:
16910: =cut
16911:
16912: sub check_release_required {
16913: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16914: my ($switchserver,$warning);
16915: if ($required ne '') {
16916: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16917: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16918: if ($reqdmajor ne '' && $reqdminor ne '') {
16919: my $otherserver;
16920: if (($major eq '' && $minor eq '') ||
16921: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16922: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16923: my $switchlcrev =
16924: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16925: $userdomserver);
16926: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16927: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16928: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16929: my $cdom = $env{'course.'.$courseid.'.domain'};
16930: if ($cdom ne $env{'user.domain'}) {
16931: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16932: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16933: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16934: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16935: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16936: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16937: my $canhost =
16938: &Apache::lonnet::can_host_session($env{'user.domain'},
16939: $coursedomserver,
16940: $remoterev,
16941: $udomdefaults{'remotesessions'},
16942: $defdomdefaults{'hostedsessions'});
16943:
16944: if ($canhost) {
16945: $otherserver = $coursedomserver;
16946: } else {
16947: $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.");
16948: }
16949: } else {
16950: $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).");
16951: }
16952: } else {
16953: $otherserver = $userdomserver;
16954: }
16955: }
16956: if ($otherserver ne '') {
16957: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16958: }
16959: }
16960: }
16961: return ($switchserver,$warning);
16962: }
16963:
16964: =pod
16965:
16966: =item * &check_release_result()
16967:
16968: Inputs:
16969:
16970: $switchwarning - Warning message if no suitable server found to host session.
16971:
16972: $switchserver - query string to append to /adm/switchserver containing lonHostID
16973: and current role.
16974:
16975: Returns: HTML to display with information about requirement to switch server.
16976: Either displaying warning with link to Roles/Courses screen or
16977: display link to switchserver.
16978:
1.1075.2.69 raeburn 16979: =cut
16980:
1.1075.2.88 raeburn 16981: sub check_release_result {
16982: my ($switchwarning,$switchserver) = @_;
16983: my $output = &start_page('Selected course unavailable on this server').
16984: '<p class="LC_warning">';
16985: if ($switchwarning) {
16986: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16987: if (&show_course()) {
16988: $output .= &mt('Display courses');
16989: } else {
16990: $output .= &mt('Display roles');
16991: }
16992: $output .= '</a>';
16993: } elsif ($switchserver) {
16994: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16995: '<br />'.
16996: '<a href="/adm/switchserver?'.$switchserver.'">'.
16997: &mt('Switch Server').
16998: '</a>';
16999: }
17000: $output .= '</p>'.&end_page();
17001: return $output;
17002: }
17003:
17004: =pod
17005:
17006: =item * &needs_coursereinit()
17007:
17008: Determine if course contents stored for user's session needs to be
17009: refreshed, because content has changed since "Big Hash" last tied.
17010:
17011: Check for change is made if time last checked is more than 10 minutes ago
17012: (by default).
17013:
17014: Inputs:
17015:
17016: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17017:
17018: $interval (optional) - Time which may elapse (in s) between last check for content
17019: change in current course. (default: 600 s).
17020:
17021: Returns: an array; first element is:
17022:
17023: =over 4
17024:
17025: 'switch' - if content updates mean user's session
17026: needs to be switched to a server running a newer LON-CAPA version
17027:
17028: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17029: on current server hosting user's session
17030:
17031: '' - if no action required.
17032:
17033: =back
17034:
17035: If first item element is 'switch':
17036:
17037: second item is $switchwarning - Warning message if no suitable server found to host session.
17038:
17039: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17040: and current role.
17041:
17042: otherwise: no other elements returned.
17043:
17044: =back
17045:
17046: =cut
17047:
17048: sub needs_coursereinit {
17049: my ($loncaparev,$interval) = @_;
17050: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17051: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17052: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17053: my $now = time;
17054: if ($interval eq '') {
17055: $interval = 600;
17056: }
17057: if (($now-$env{'request.course.timechecked'})>$interval) {
17058: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17059: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
17060: if ($lastchange > $env{'request.course.tied'}) {
17061: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17062: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17063: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17064: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17065: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17066: $curr_reqd_hash{'internal.releaserequired'}});
17067: my ($switchserver,$switchwarning) =
17068: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17069: $curr_reqd_hash{'internal.releaserequired'});
17070: if ($switchwarning ne '' || $switchserver ne '') {
17071: return ('switch',$switchwarning,$switchserver);
17072: }
17073: }
17074: }
17075: return ('update');
17076: }
17077: }
17078: return ();
17079: }
1.1075.2.69 raeburn 17080:
1.1075.2.11 raeburn 17081: sub update_content_constraints {
17082: my ($cdom,$cnum,$chome,$cid) = @_;
17083: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17084: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
17085: my %checkresponsetypes;
17086: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
17087: my ($item,$name,$value) = split(/:/,$key);
17088: if ($item eq 'resourcetag') {
17089: if ($name eq 'responsetype') {
17090: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17091: }
17092: }
17093: }
17094: my $navmap = Apache::lonnavmaps::navmap->new();
17095: if (defined($navmap)) {
17096: my %allresponses;
17097: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17098: my %responses = $res->responseTypes();
17099: foreach my $key (keys(%responses)) {
17100: next unless(exists($checkresponsetypes{$key}));
17101: $allresponses{$key} += $responses{$key};
17102: }
17103: }
17104: foreach my $key (keys(%allresponses)) {
17105: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17106: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17107: ($reqdmajor,$reqdminor) = ($major,$minor);
17108: }
17109: }
17110: undef($navmap);
17111: }
17112: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17113: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17114: }
17115: return;
17116: }
17117:
1.1075.2.27 raeburn 17118: sub allmaps_incourse {
17119: my ($cdom,$cnum,$chome,$cid) = @_;
17120: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17121: $cid = $env{'request.course.id'};
17122: $cdom = $env{'course.'.$cid.'.domain'};
17123: $cnum = $env{'course.'.$cid.'.num'};
17124: $chome = $env{'course.'.$cid.'.home'};
17125: }
17126: my %allmaps = ();
17127: my $lastchange =
17128: &Apache::lonnet::get_coursechange($cdom,$cnum);
17129: if ($lastchange > $env{'request.course.tied'}) {
17130: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17131: unless ($ferr) {
17132: &update_content_constraints($cdom,$cnum,$chome,$cid);
17133: }
17134: }
17135: my $navmap = Apache::lonnavmaps::navmap->new();
17136: if (defined($navmap)) {
17137: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17138: $allmaps{$res->src()} = 1;
17139: }
17140: }
17141: return \%allmaps;
17142: }
17143:
1.1075.2.11 raeburn 17144: sub parse_supplemental_title {
17145: my ($title) = @_;
17146:
17147: my ($foldertitle,$renametitle);
17148: if ($title =~ /&&&/) {
17149: $title = &HTML::Entites::decode($title);
17150: }
17151: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17152: $renametitle=$4;
17153: my ($time,$uname,$udom) = ($1,$2,$3);
17154: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17155: my $name = &plainname($uname,$udom);
17156: $name = &HTML::Entities::encode($name,'"<>&\'');
17157: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17158: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17159: $name.': <br />'.$foldertitle;
17160: }
17161: if (wantarray) {
17162: return ($title,$foldertitle,$renametitle);
17163: }
17164: return $title;
17165: }
17166:
1.1075.2.43 raeburn 17167: sub recurse_supplemental {
17168: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
17169: if ($suppmap) {
17170: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17171: if ($fatal) {
17172: $errors ++;
17173: } else {
1.1075.2.167 raeburn 17174: my @order = @LONCAPA::map::order;
17175: if (@order > 0) {
17176: my @resources = @LONCAPA::map::resources;
17177: my @resparms = @LONCAPA::map::resparms;
17178: foreach my $idx (@order) {
17179: my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1075.2.43 raeburn 17180: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 17181: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
17182: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 17183: } else {
17184: $numfiles ++;
17185: }
17186: }
17187: }
17188: }
17189: }
17190: }
17191: return ($numfiles,$errors);
17192: }
17193:
1.1075.2.18 raeburn 17194: sub symb_to_docspath {
1.1075.2.119 raeburn 17195: my ($symb,$navmapref) = @_;
17196: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 17197: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17198: if ($resurl=~/\.(sequence|page)$/) {
17199: $mapurl=$resurl;
17200: } elsif ($resurl eq 'adm/navmaps') {
17201: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17202: }
17203: my $mapresobj;
1.1075.2.119 raeburn 17204: unless (ref($$navmapref)) {
17205: $$navmapref = Apache::lonnavmaps::navmap->new();
17206: }
17207: if (ref($$navmapref)) {
17208: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 17209: }
17210: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17211: my $type=$2;
17212: my $path;
17213: if (ref($mapresobj)) {
17214: my $pcslist = $mapresobj->map_hierarchy();
17215: if ($pcslist ne '') {
17216: foreach my $pc (split(/,/,$pcslist)) {
17217: next if ($pc <= 1);
1.1075.2.119 raeburn 17218: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 17219: if (ref($res)) {
17220: my $thisurl = $res->src();
17221: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17222: my $thistitle = $res->title();
17223: $path .= '&'.
17224: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 17225: &escape($thistitle).
1.1075.2.18 raeburn 17226: ':'.$res->randompick().
17227: ':'.$res->randomout().
17228: ':'.$res->encrypted().
17229: ':'.$res->randomorder().
17230: ':'.$res->is_page();
17231: }
17232: }
17233: }
17234: $path =~ s/^\&//;
17235: my $maptitle = $mapresobj->title();
17236: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17237: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17238: }
17239: $path .= (($path ne '')? '&' : '').
17240: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17241: &escape($maptitle).
1.1075.2.18 raeburn 17242: ':'.$mapresobj->randompick().
17243: ':'.$mapresobj->randomout().
17244: ':'.$mapresobj->encrypted().
17245: ':'.$mapresobj->randomorder().
17246: ':'.$mapresobj->is_page();
17247: } else {
17248: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17249: my $ispage = (($type eq 'page')? 1 : '');
17250: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17251: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17252: }
17253: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17254: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 17255: }
17256: unless ($mapurl eq 'default') {
17257: $path = 'default&'.
1.1075.2.46 raeburn 17258: &escape('Main Content').
1.1075.2.18 raeburn 17259: ':::::&'.$path;
17260: }
17261: return $path;
17262: }
17263:
1.1075.2.14 raeburn 17264: sub captcha_display {
1.1075.2.137 raeburn 17265: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17266: my ($output,$error);
1.1075.2.107 raeburn 17267: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 17268: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17269: if ($captcha eq 'original') {
17270: $output = &create_captcha();
17271: unless ($output) {
17272: $error = 'captcha';
17273: }
17274: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17275: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 17276: unless ($output) {
17277: $error = 'recaptcha';
17278: }
17279: }
1.1075.2.107 raeburn 17280: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 17281: }
17282:
17283: sub captcha_response {
1.1075.2.137 raeburn 17284: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17285: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 17286: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17287: if ($captcha eq 'original') {
17288: ($captcha_chk,$captcha_error) = &check_captcha();
17289: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17290: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 17291: } else {
17292: $captcha_chk = 1;
17293: }
17294: return ($captcha_chk,$captcha_error);
17295: }
17296:
17297: sub get_captcha_config {
1.1075.2.137 raeburn 17298: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 17299: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 17300: my $hostname = &Apache::lonnet::hostname($lonhost);
17301: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17302: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17303: if ($context eq 'usercreation') {
17304: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17305: if (ref($domconfig{$context}) eq 'HASH') {
17306: $hashtocheck = $domconfig{$context}{'cancreate'};
17307: if (ref($hashtocheck) eq 'HASH') {
17308: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17309: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17310: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17311: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17312: }
17313: if ($privkey && $pubkey) {
17314: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17315: $version = $hashtocheck->{'recaptchaversion'};
17316: if ($version ne '2') {
17317: $version = 1;
17318: }
1.1075.2.14 raeburn 17319: } else {
17320: $captcha = 'original';
17321: }
17322: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17323: $captcha = 'original';
17324: }
17325: }
17326: } else {
17327: $captcha = 'captcha';
17328: }
17329: } elsif ($context eq 'login') {
17330: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17331: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17332: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17333: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
17334: if ($privkey && $pubkey) {
17335: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17336: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17337: if ($version ne '2') {
17338: $version = 1;
17339: }
1.1075.2.14 raeburn 17340: } else {
17341: $captcha = 'original';
17342: }
17343: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17344: $captcha = 'original';
17345: }
1.1075.2.137 raeburn 17346: } elsif ($context eq 'passwords') {
17347: if ($dom_in_effect) {
17348: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17349: if ($passwdconf{'captcha'} eq 'recaptcha') {
17350: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17351: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17352: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17353: }
17354: if ($privkey && $pubkey) {
17355: $captcha = 'recaptcha';
17356: $version = $passwdconf{'recaptchaversion'};
17357: if ($version ne '2') {
17358: $version = 1;
17359: }
17360: } else {
17361: $captcha = 'original';
17362: }
17363: } elsif ($passwdconf{'captcha'} ne 'notused') {
17364: $captcha = 'original';
17365: }
17366: }
1.1075.2.14 raeburn 17367: }
1.1075.2.107 raeburn 17368: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 17369: }
17370:
17371: sub create_captcha {
17372: my %captcha_params = &captcha_settings();
17373: my ($output,$maxtries,$tries) = ('',10,0);
17374: while ($tries < $maxtries) {
17375: $tries ++;
17376: my $captcha = Authen::Captcha->new (
17377: output_folder => $captcha_params{'output_dir'},
17378: data_folder => $captcha_params{'db_dir'},
17379: );
17380: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17381:
17382: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17383: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1075.2.158 raeburn 17384: '<span class="LC_nobreak">'.
1.1075.2.14 raeburn 17385: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.167 raeburn 17386: '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1075.2.158 raeburn 17387: '</span><br />'.
1.1075.2.66 raeburn 17388: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 17389: last;
17390: }
17391: }
1.1075.2.158 raeburn 17392: if ($output eq '') {
17393: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
17394: }
1.1075.2.14 raeburn 17395: return $output;
17396: }
17397:
17398: sub captcha_settings {
17399: my %captcha_params = (
17400: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17401: www_output_dir => "/captchaspool",
17402: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17403: numchars => '5',
17404: );
17405: return %captcha_params;
17406: }
17407:
17408: sub check_captcha {
17409: my ($captcha_chk,$captcha_error);
17410: my $code = $env{'form.code'};
17411: my $md5sum = $env{'form.crypt'};
17412: my %captcha_params = &captcha_settings();
17413: my $captcha = Authen::Captcha->new(
17414: output_folder => $captcha_params{'output_dir'},
17415: data_folder => $captcha_params{'db_dir'},
17416: );
1.1075.2.26 raeburn 17417: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 17418: my %captcha_hash = (
17419: 0 => 'Code not checked (file error)',
17420: -1 => 'Failed: code expired',
17421: -2 => 'Failed: invalid code (not in database)',
17422: -3 => 'Failed: invalid code (code does not match crypt)',
17423: );
17424: if ($captcha_chk != 1) {
17425: $captcha_error = $captcha_hash{$captcha_chk}
17426: }
17427: return ($captcha_chk,$captcha_error);
17428: }
17429:
17430: sub create_recaptcha {
1.1075.2.107 raeburn 17431: my ($pubkey,$version) = @_;
17432: if ($version >= 2) {
1.1075.2.158 raeburn 17433: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
17434: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1075.2.107 raeburn 17435: } else {
17436: my $use_ssl;
17437: if ($ENV{'SERVER_PORT'} == 443) {
17438: $use_ssl = 1;
17439: }
17440: my $captcha = Captcha::reCAPTCHA->new;
17441: return $captcha->get_options_setter({theme => 'white'})."\n".
17442: $captcha->get_html($pubkey,undef,$use_ssl).
17443: &mt('If the text is hard to read, [_1] will replace them.',
17444: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17445: '<br /><br />';
17446: }
1.1075.2.14 raeburn 17447: }
17448:
17449: sub check_recaptcha {
1.1075.2.107 raeburn 17450: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 17451: my $captcha_chk;
1.1075.2.150 raeburn 17452: my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 17453: if ($version >= 2) {
17454: my $ua = LWP::UserAgent->new;
17455: $ua->timeout(10);
17456: my %info = (
17457: secret => $privkey,
17458: response => $env{'form.g-recaptcha-response'},
1.1075.2.150 raeburn 17459: remoteip => $ip,
1.1075.2.107 raeburn 17460: );
17461: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17462: if ($response->is_success) {
17463: my $data = JSON::DWIW->from_json($response->decoded_content);
17464: if (ref($data) eq 'HASH') {
17465: if ($data->{'success'}) {
17466: $captcha_chk = 1;
17467: }
17468: }
17469: }
17470: } else {
17471: my $captcha = Captcha::reCAPTCHA->new;
17472: my $captcha_result =
17473: $captcha->check_answer(
17474: $privkey,
1.1075.2.150 raeburn 17475: $ip,
1.1075.2.107 raeburn 17476: $env{'form.recaptcha_challenge_field'},
17477: $env{'form.recaptcha_response_field'},
17478: );
17479: if ($captcha_result->{is_valid}) {
17480: $captcha_chk = 1;
17481: }
1.1075.2.14 raeburn 17482: }
17483: return $captcha_chk;
17484: }
17485:
1.1075.2.64 raeburn 17486: sub emailusername_info {
1.1075.2.103 raeburn 17487: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 17488: my %titles = &Apache::lonlocal::texthash (
17489: lastname => 'Last Name',
17490: firstname => 'First Name',
17491: institution => 'School/college/university',
17492: location => "School's city, state/province, country",
17493: web => "School's web address",
17494: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 17495: id => 'Student/Employee ID',
1.1075.2.64 raeburn 17496: );
17497: return (\@fields,\%titles);
17498: }
17499:
1.1075.2.56 raeburn 17500: sub cleanup_html {
17501: my ($incoming) = @_;
17502: my $outgoing;
17503: if ($incoming ne '') {
17504: $outgoing = $incoming;
17505: $outgoing =~ s/;/;/g;
17506: $outgoing =~ s/\#/#/g;
17507: $outgoing =~ s/\&/&/g;
17508: $outgoing =~ s/</</g;
17509: $outgoing =~ s/>/>/g;
17510: $outgoing =~ s/\(/(/g;
17511: $outgoing =~ s/\)/)/g;
17512: $outgoing =~ s/"/"/g;
17513: $outgoing =~ s/'/'/g;
17514: $outgoing =~ s/\$/$/g;
17515: $outgoing =~ s{/}{/}g;
17516: $outgoing =~ s/=/=/g;
17517: $outgoing =~ s/\\/\/g
17518: }
17519: return $outgoing;
17520: }
17521:
1.1075.2.74 raeburn 17522: # Checks for critical messages and returns a redirect url if one exists.
17523: # $interval indicates how often to check for messages.
17524: sub critical_redirect {
17525: my ($interval) = @_;
1.1075.2.158 raeburn 17526: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
17527: return ();
17528: }
1.1075.2.74 raeburn 17529: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17530: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17531: $env{'user.name'});
17532: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17533: my $redirecturl;
17534: if ($what[0]) {
1.1075.2.158 raeburn 17535: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1075.2.74 raeburn 17536: $redirecturl='/adm/email?critical=display';
17537: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17538: return (1, $url);
17539: }
17540: }
17541: }
17542: return ();
17543: }
17544:
1.1075.2.64 raeburn 17545: # Use:
17546: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17547: #
17548: ##################################################
17549: # password associated functions #
17550: ##################################################
17551: sub des_keys {
17552: # Make a new key for DES encryption.
17553: # Each key has two parts which are returned separately.
17554: # Please note: Each key must be passed through the &hex function
17555: # before it is output to the web browser. The hex versions cannot
17556: # be used to decrypt.
17557: my @hexstr=('0','1','2','3','4','5','6','7',
17558: '8','9','a','b','c','d','e','f');
17559: my $lkey='';
17560: for (0..7) {
17561: $lkey.=$hexstr[rand(15)];
17562: }
17563: my $ukey='';
17564: for (0..7) {
17565: $ukey.=$hexstr[rand(15)];
17566: }
17567: return ($lkey,$ukey);
17568: }
17569:
17570: sub des_decrypt {
17571: my ($key,$cyphertext) = @_;
17572: my $keybin=pack("H16",$key);
17573: my $cypher;
17574: if ($Crypt::DES::VERSION>=2.03) {
17575: $cypher=new Crypt::DES $keybin;
17576: } else {
17577: $cypher=new DES $keybin;
17578: }
1.1075.2.106 raeburn 17579: my $plaintext='';
17580: my $cypherlength = length($cyphertext);
17581: my $numchunks = int($cypherlength/32);
17582: for (my $j=0; $j<$numchunks; $j++) {
17583: my $start = $j*32;
17584: my $cypherblock = substr($cyphertext,$start,32);
17585: my $chunk =
17586: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17587: $chunk .=
17588: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17589: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17590: $plaintext .= $chunk;
17591: }
1.1075.2.64 raeburn 17592: return $plaintext;
17593: }
17594:
1.1075.2.135 raeburn 17595: sub is_nonframeable {
17596: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
17597: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
17598: return if (($remprotocol eq '') || ($remhost eq ''));
17599:
17600: $remprotocol = lc($remprotocol);
17601: $remhost = lc($remhost);
17602: my $remport = 80;
17603: if ($remprotocol eq 'https') {
17604: $remport = 443;
17605: }
17606: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
17607: if ($cached) {
17608: unless ($nocache) {
17609: if ($result) {
17610: return 1;
17611: } else {
17612: return 0;
17613: }
17614: }
17615: }
17616: my $uselink;
17617: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 17618: my $ua = LWP::UserAgent->new;
17619: $ua->timeout(5);
17620: my $response=$ua->request($request);
1.1075.2.135 raeburn 17621: if ($response->is_success()) {
17622: my $secpolicy = lc($response->header('content-security-policy'));
17623: my $xframeop = lc($response->header('x-frame-options'));
17624: $secpolicy =~ s/^\s+|\s+$//g;
17625: $xframeop =~ s/^\s+|\s+$//g;
17626: if (($secpolicy ne '') || ($xframeop ne '')) {
17627: my $remotehost = $remprotocol.'://'.$remhost;
17628: my ($origin,$protocol,$port);
17629: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17630: $port = $ENV{'SERVER_PORT'};
17631: } else {
17632: $port = 80;
17633: }
17634: if ($absolute eq '') {
17635: $protocol = 'http:';
17636: if ($port == 443) {
17637: $protocol = 'https:';
17638: }
17639: $origin = $protocol.'//'.lc($hostname);
17640: } else {
17641: $origin = lc($absolute);
17642: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17643: }
17644: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17645: my $framepolicy = $1;
17646: $framepolicy =~ s/^\s+|\s+$//g;
17647: my @policies = split(/\s+/,$framepolicy);
17648: if (@policies) {
17649: if (grep(/^\Q'none'\E$/,@policies)) {
17650: $uselink = 1;
17651: } else {
17652: $uselink = 1;
17653: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17654: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17655: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17656: undef($uselink);
17657: }
17658: if ($uselink) {
17659: if (grep(/^\Q'self'\E$/,@policies)) {
17660: if (($origin ne '') && ($remotehost eq $origin)) {
17661: undef($uselink);
17662: }
17663: }
17664: }
17665: if ($uselink) {
17666: my @possok;
17667: if ($ip ne '') {
17668: push(@possok,$ip);
17669: }
17670: my $hoststr = '';
17671: foreach my $part (reverse(split(/\./,$hostname))) {
17672: if ($hoststr eq '') {
17673: $hoststr = $part;
17674: } else {
17675: $hoststr = "$part.$hoststr";
17676: }
17677: if ($hoststr eq $hostname) {
17678: push(@possok,$hostname);
17679: } else {
17680: push(@possok,"*.$hoststr");
17681: }
17682: }
17683: if (@possok) {
17684: foreach my $poss (@possok) {
17685: last if (!$uselink);
17686: foreach my $policy (@policies) {
17687: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17688: undef($uselink);
17689: last;
17690: }
17691: }
17692: }
17693: }
17694: }
17695: }
17696: }
17697: } elsif ($xframeop ne '') {
17698: $uselink = 1;
17699: my @policies = split(/\s*,\s*/,$xframeop);
17700: if (@policies) {
17701: unless (grep(/^deny$/,@policies)) {
17702: if ($origin ne '') {
17703: if (grep(/^sameorigin$/,@policies)) {
17704: if ($remotehost eq $origin) {
17705: undef($uselink);
17706: }
17707: }
17708: if ($uselink) {
17709: foreach my $policy (@policies) {
17710: if ($policy =~ /^allow-from\s*(.+)$/) {
17711: my $allowfrom = $1;
17712: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17713: undef($uselink);
17714: last;
17715: }
17716: }
17717: }
17718: }
17719: }
17720: }
17721: }
17722: }
17723: }
17724: }
17725: if ($nocache) {
17726: if ($cached) {
17727: my $devalidate;
17728: if ($uselink && !$result) {
17729: $devalidate = 1;
17730: } elsif (!$uselink && $result) {
17731: $devalidate = 1;
17732: }
17733: if ($devalidate) {
17734: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17735: }
17736: }
17737: } else {
17738: if ($uselink) {
17739: $result = 1;
17740: } else {
17741: $result = 0;
17742: }
17743: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17744: }
17745: return $uselink;
17746: }
17747:
1.112 bowersj2 17748: 1;
17749: __END__;
1.41 ng 17750:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>