Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.168
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.168! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.167 2024/07/04 23:00:26 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.158 raeburn 5832: my ($left,$right) = Apache::lonmenu::primary_menu($args->{'links_disabled'});
1.1075.2.2 raeburn 5833:
1.916 droeschl 5834: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5835: if ($dc_info) {
1.1075.2.158 raeburn 5836: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5837: }
1.1075.2.38 raeburn 5838: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5839: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5840: return $bodytag;
5841: }
1.894 droeschl 5842:
1.927 raeburn 5843: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5844: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5845: }
1.916 droeschl 5846:
1.1075.2.38 raeburn 5847: $bodytag .= $right;
1.852 droeschl 5848:
1.917 raeburn 5849: if ($dc_info) {
5850: $dc_info = &dc_courseid_toggle($dc_info);
5851: }
5852: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5853:
1.1075.2.61 raeburn 5854: #if directed to not display the secondary menu, don't.
5855: if ($args->{'no_secondary_menu'}) {
5856: return $bodytag;
5857: }
1.903 droeschl 5858: #don't show menus for public users
1.954 raeburn 5859: if (!$public){
1.1075.2.158 raeburn 5860: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$args->{'links_disabled'});
1.903 droeschl 5861: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5862: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5863: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5864: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.133 raeburn 5865: $args->{'bread_crumbs'},'','',$hostname);
1.1075.2.116 raeburn 5866: } elsif ($forcereg) {
1.1075.2.22 raeburn 5867: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5868: $args->{'group'},
1.1075.2.161 raeburn 5869: $args->{'hide_buttons'},
5870: $hostname);
1.1075.2.15 raeburn 5871: } else {
1.1075.2.21 raeburn 5872: my $forbodytag;
5873: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5874: $forcereg,$args->{'group'},
5875: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5876: $advtoolsref,'',$hostname,
5877: \$forbodytag);
1.1075.2.21 raeburn 5878: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5879: $bodytag .= $forbodytag;
5880: }
1.920 raeburn 5881: }
1.903 droeschl 5882: }else{
5883: # this is to seperate menu from content when there's no secondary
5884: # menu. Especially needed for public accessible ressources.
5885: $bodytag .= '<hr style="clear:both" />';
5886: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5887: }
1.903 droeschl 5888:
1.235 raeburn 5889: return $bodytag;
1.1075.2.12 raeburn 5890: }
5891:
5892: #
5893: # Top frame rendering, Remote is up
5894: #
5895:
5896: my $imgsrc = $img;
5897: if ($img =~ /^\/adm/) {
5898: $imgsrc = &lonhttpdurl($img);
5899: }
5900: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5901:
1.1075.2.60 raeburn 5902: my $help=($no_inline_link?''
5903: :&Apache::loncommon::top_nav_help('Help'));
5904:
1.1075.2.12 raeburn 5905: # Explicit link to get inline menu
5906: my $menu= ($no_inline_link?''
5907: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5908:
5909: if ($dc_info) {
5910: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5911: }
5912:
1.1075.2.38 raeburn 5913: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5914: unless ($public) {
5915: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5916: undef,'LC_menubuttons_link');
5917: }
5918:
1.1075.2.12 raeburn 5919: unless ($env{'form.inhibitmenu'}) {
5920: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5921: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5922: <li>$help</li>
1.1075.2.12 raeburn 5923: <li>$menu</li>
5924: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5925: }
1.1075.2.13 raeburn 5926: if ($env{'request.state'} eq 'construct') {
5927: if (!$public){
5928: if ($env{'request.state'} eq 'construct') {
5929: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5930: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5931: &Apache::lonhtmlcommon::scripttag('','end').
5932: &Apache::lonmenu::innerregister($forcereg,
5933: $args->{'bread_crumbs'});
5934: }
5935: }
5936: }
1.1075.2.21 raeburn 5937: return $bodytag."\n".$funclist;
1.182 matthew 5938: }
5939:
1.917 raeburn 5940: sub dc_courseid_toggle {
5941: my ($dc_info) = @_;
1.980 raeburn 5942: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5943: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5944: &mt('(More ...)').'</a></span>'.
5945: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5946: }
5947:
1.330 albertel 5948: sub make_attr_string {
5949: my ($register,$attr_ref) = @_;
5950:
5951: if ($attr_ref && !ref($attr_ref)) {
5952: die("addentries Must be a hash ref ".
5953: join(':',caller(1))." ".
5954: join(':',caller(0))." ");
5955: }
5956:
5957: if ($register) {
1.339 albertel 5958: my ($on_load,$on_unload);
5959: foreach my $key (keys(%{$attr_ref})) {
5960: if (lc($key) eq 'onload') {
5961: $on_load.=$attr_ref->{$key}.';';
5962: delete($attr_ref->{$key});
5963:
5964: } elsif (lc($key) eq 'onunload') {
5965: $on_unload.=$attr_ref->{$key}.';';
5966: delete($attr_ref->{$key});
5967: }
5968: }
1.1075.2.12 raeburn 5969: if ($env{'environment.remote'} eq 'on') {
5970: $attr_ref->{'onload'} =
5971: &Apache::lonmenu::loadevents(). $on_load;
5972: $attr_ref->{'onunload'}=
5973: &Apache::lonmenu::unloadevents().$on_unload;
5974: } else {
5975: $attr_ref->{'onload'} = $on_load;
5976: $attr_ref->{'onunload'}= $on_unload;
5977: }
1.330 albertel 5978: }
1.339 albertel 5979:
1.330 albertel 5980: my $attr_string;
1.1075.2.56 raeburn 5981: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5982: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5983: }
5984: return $attr_string;
5985: }
5986:
5987:
1.182 matthew 5988: ###############################################
1.251 albertel 5989: ###############################################
5990:
5991: =pod
5992:
5993: =item * &endbodytag()
5994:
5995: Returns a uniform footer for LON-CAPA web pages.
5996:
1.635 raeburn 5997: Inputs: 1 - optional reference to an args hash
5998: If in the hash, key for noredirectlink has a value which evaluates to true,
5999: a 'Continue' link is not displayed if the page contains an
6000: internal redirect in the <head></head> section,
6001: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6002:
6003: =cut
6004:
6005: sub endbodytag {
1.635 raeburn 6006: my ($args) = @_;
1.1075.2.6 raeburn 6007: my $endbodytag;
6008: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6009: $endbodytag='</body>';
6010: }
1.315 albertel 6011: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6012: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6013: $endbodytag=
6014: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6015: &mt('Continue').'</a>'.
6016: $endbodytag;
6017: }
1.315 albertel 6018: }
1.1075.2.165 raeburn 6019: if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
6020: $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
6021: }
1.251 albertel 6022: return $endbodytag;
6023: }
6024:
1.352 albertel 6025: =pod
6026:
6027: =item * &standard_css()
6028:
6029: Returns a style sheet
6030:
6031: Inputs: (all optional)
6032: domain -> force to color decorate a page for a specific
6033: domain
6034: function -> force usage of a specific rolish color scheme
6035: bgcolor -> override the default page bgcolor
6036:
6037: =cut
6038:
1.343 albertel 6039: sub standard_css {
1.345 albertel 6040: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6041: $function = &get_users_function() if (!$function);
6042: my $img = &designparm($function.'.img', $domain);
6043: my $tabbg = &designparm($function.'.tabbg', $domain);
6044: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6045: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6046: #second colour for later usage
1.345 albertel 6047: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6048: my $pgbg_or_bgcolor =
6049: $bgcolor ||
1.352 albertel 6050: &designparm($function.'.pgbg', $domain);
1.382 albertel 6051: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6052: my $alink = &designparm($function.'.alink', $domain);
6053: my $vlink = &designparm($function.'.vlink', $domain);
6054: my $link = &designparm($function.'.link', $domain);
6055:
1.602 albertel 6056: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6057: my $mono = 'monospace';
1.850 bisitz 6058: my $data_table_head = $sidebg;
6059: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6060: my $data_table_dark = '#E0E0E0';
1.470 banghart 6061: my $data_table_darker = '#CCCCCC';
1.349 albertel 6062: my $data_table_highlight = '#FFFF00';
1.352 albertel 6063: my $mail_new = '#FFBB77';
6064: my $mail_new_hover = '#DD9955';
6065: my $mail_read = '#BBBB77';
6066: my $mail_read_hover = '#999944';
6067: my $mail_replied = '#AAAA88';
6068: my $mail_replied_hover = '#888855';
6069: my $mail_other = '#99BBBB';
6070: my $mail_other_hover = '#669999';
1.391 albertel 6071: my $table_header = '#DDDDDD';
1.489 raeburn 6072: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6073: my $lg_border_color = '#C8C8C8';
1.952 onken 6074: my $button_hover = '#BF2317';
1.392 albertel 6075:
1.608 albertel 6076: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6077: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6078: : '0 3px 0 4px';
1.448 albertel 6079:
1.523 albertel 6080:
1.343 albertel 6081: return <<END;
1.947 droeschl 6082:
6083: /* needed for iframe to allow 100% height in FF */
6084: body, html {
6085: margin: 0;
6086: padding: 0 0.5%;
6087: height: 99%; /* to avoid scrollbars */
6088: }
6089:
1.795 www 6090: body {
1.911 bisitz 6091: font-family: $sans;
6092: line-height:130%;
6093: font-size:0.83em;
6094: color:$font;
1.795 www 6095: }
6096:
1.959 onken 6097: a:focus,
6098: a:focus img {
1.795 www 6099: color: red;
6100: }
1.698 harmsja 6101:
1.911 bisitz 6102: form, .inline {
6103: display: inline;
1.795 www 6104: }
1.721 harmsja 6105:
1.795 www 6106: .LC_right {
1.911 bisitz 6107: text-align:right;
1.795 www 6108: }
6109:
6110: .LC_middle {
1.911 bisitz 6111: vertical-align:middle;
1.795 www 6112: }
1.721 harmsja 6113:
1.1075.2.38 raeburn 6114: .LC_floatleft {
6115: float: left;
6116: }
6117:
6118: .LC_floatright {
6119: float: right;
6120: }
6121:
1.911 bisitz 6122: .LC_400Box {
6123: width:400px;
6124: }
1.721 harmsja 6125:
1.947 droeschl 6126: .LC_iframecontainer {
6127: width: 98%;
6128: margin: 0;
6129: position: fixed;
6130: top: 8.5em;
6131: bottom: 0;
6132: }
6133:
6134: .LC_iframecontainer iframe{
6135: border: none;
6136: width: 100%;
6137: height: 100%;
6138: }
6139:
1.778 bisitz 6140: .LC_filename {
6141: font-family: $mono;
6142: white-space:pre;
1.921 bisitz 6143: font-size: 120%;
1.778 bisitz 6144: }
6145:
6146: .LC_fileicon {
6147: border: none;
6148: height: 1.3em;
6149: vertical-align: text-bottom;
6150: margin-right: 0.3em;
6151: text-decoration:none;
6152: }
6153:
1.1008 www 6154: .LC_setting {
6155: text-decoration:underline;
6156: }
6157:
1.350 albertel 6158: .LC_error {
6159: color: red;
6160: }
1.795 www 6161:
1.1075.2.15 raeburn 6162: .LC_warning {
6163: color: darkorange;
6164: }
6165:
1.457 albertel 6166: .LC_diff_removed {
1.733 bisitz 6167: color: red;
1.394 albertel 6168: }
1.532 albertel 6169:
6170: .LC_info,
1.457 albertel 6171: .LC_success,
6172: .LC_diff_added {
1.350 albertel 6173: color: green;
6174: }
1.795 www 6175:
1.802 bisitz 6176: div.LC_confirm_box {
6177: background-color: #FAFAFA;
6178: border: 1px solid $lg_border_color;
6179: margin-right: 0;
6180: padding: 5px;
6181: }
6182:
6183: div.LC_confirm_box .LC_error img,
6184: div.LC_confirm_box .LC_success img {
6185: vertical-align: middle;
6186: }
6187:
1.1075.2.108 raeburn 6188: .LC_maxwidth {
6189: max-width: 100%;
6190: height: auto;
6191: }
6192:
6193: .LC_textsize_mobile {
6194: \@media only screen and (max-device-width: 480px) {
6195: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6196: }
6197: }
6198:
1.440 albertel 6199: .LC_icon {
1.771 droeschl 6200: border: none;
1.790 droeschl 6201: vertical-align: middle;
1.771 droeschl 6202: }
6203:
1.543 albertel 6204: .LC_docs_spacer {
6205: width: 25px;
6206: height: 1px;
1.771 droeschl 6207: border: none;
1.543 albertel 6208: }
1.346 albertel 6209:
1.532 albertel 6210: .LC_internal_info {
1.735 bisitz 6211: color: #999999;
1.532 albertel 6212: }
6213:
1.794 www 6214: .LC_discussion {
1.1050 www 6215: background: $data_table_dark;
1.911 bisitz 6216: border: 1px solid black;
6217: margin: 2px;
1.794 www 6218: }
6219:
6220: .LC_disc_action_left {
1.1050 www 6221: background: $sidebg;
1.911 bisitz 6222: text-align: left;
1.1050 www 6223: padding: 4px;
6224: margin: 2px;
1.794 www 6225: }
6226:
6227: .LC_disc_action_right {
1.1050 www 6228: background: $sidebg;
1.911 bisitz 6229: text-align: right;
1.1050 www 6230: padding: 4px;
6231: margin: 2px;
1.794 www 6232: }
6233:
6234: .LC_disc_new_item {
1.911 bisitz 6235: background: white;
6236: border: 2px solid red;
1.1050 www 6237: margin: 4px;
6238: padding: 4px;
1.794 www 6239: }
6240:
6241: .LC_disc_old_item {
1.911 bisitz 6242: background: white;
1.1050 www 6243: margin: 4px;
6244: padding: 4px;
1.794 www 6245: }
6246:
1.458 albertel 6247: table.LC_pastsubmission {
6248: border: 1px solid black;
6249: margin: 2px;
6250: }
6251:
1.924 bisitz 6252: table#LC_menubuttons {
1.345 albertel 6253: width: 100%;
6254: background: $pgbg;
1.392 albertel 6255: border: 2px;
1.402 albertel 6256: border-collapse: separate;
1.803 bisitz 6257: padding: 0;
1.345 albertel 6258: }
1.392 albertel 6259:
1.801 tempelho 6260: table#LC_title_bar a {
6261: color: $fontmenu;
6262: }
1.836 bisitz 6263:
1.807 droeschl 6264: table#LC_title_bar {
1.819 tempelho 6265: clear: both;
1.836 bisitz 6266: display: none;
1.807 droeschl 6267: }
6268:
1.795 www 6269: table#LC_title_bar,
1.933 droeschl 6270: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6271: table#LC_title_bar.LC_with_remote {
1.359 albertel 6272: width: 100%;
1.392 albertel 6273: border-color: $pgbg;
6274: border-style: solid;
6275: border-width: $border;
1.379 albertel 6276: background: $pgbg;
1.801 tempelho 6277: color: $fontmenu;
1.392 albertel 6278: border-collapse: collapse;
1.803 bisitz 6279: padding: 0;
1.819 tempelho 6280: margin: 0;
1.359 albertel 6281: }
1.795 www 6282:
1.933 droeschl 6283: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6284: margin: 0;
6285: padding: 0;
1.933 droeschl 6286: position: relative;
6287: list-style: none;
1.913 droeschl 6288: }
1.933 droeschl 6289: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6290: display: inline;
6291: }
1.933 droeschl 6292:
6293: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6294: padding: 0;
1.933 droeschl 6295: margin: 0;
6296: float: left;
1.913 droeschl 6297: }
1.933 droeschl 6298: .LC_breadcrumb_tools_tools {
6299: padding: 0;
6300: margin: 0;
1.913 droeschl 6301: float: right;
6302: }
6303:
1.359 albertel 6304: table#LC_title_bar td {
6305: background: $tabbg;
6306: }
1.795 www 6307:
1.911 bisitz 6308: table#LC_menubuttons img {
1.803 bisitz 6309: border: none;
1.346 albertel 6310: }
1.795 www 6311:
1.842 droeschl 6312: .LC_breadcrumbs_component {
1.911 bisitz 6313: float: right;
6314: margin: 0 1em;
1.357 albertel 6315: }
1.842 droeschl 6316: .LC_breadcrumbs_component img {
1.911 bisitz 6317: vertical-align: middle;
1.777 tempelho 6318: }
1.795 www 6319:
1.1075.2.108 raeburn 6320: .LC_breadcrumbs_hoverable {
6321: background: $sidebg;
6322: }
6323:
1.383 albertel 6324: td.LC_table_cell_checkbox {
6325: text-align: center;
6326: }
1.795 www 6327:
6328: .LC_fontsize_small {
1.911 bisitz 6329: font-size: 70%;
1.705 tempelho 6330: }
6331:
1.844 bisitz 6332: #LC_breadcrumbs {
1.911 bisitz 6333: clear:both;
6334: background: $sidebg;
6335: border-bottom: 1px solid $lg_border_color;
6336: line-height: 2.5em;
1.933 droeschl 6337: overflow: hidden;
1.911 bisitz 6338: margin: 0;
6339: padding: 0;
1.995 raeburn 6340: text-align: left;
1.819 tempelho 6341: }
1.862 bisitz 6342:
1.1075.2.16 raeburn 6343: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6344: clear:both;
6345: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6346: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6347: margin: 0 0 10px 0;
1.966 bisitz 6348: padding: 3px;
1.995 raeburn 6349: text-align: left;
1.822 bisitz 6350: }
6351:
1.795 www 6352: .LC_fontsize_medium {
1.911 bisitz 6353: font-size: 85%;
1.705 tempelho 6354: }
6355:
1.795 www 6356: .LC_fontsize_large {
1.911 bisitz 6357: font-size: 120%;
1.705 tempelho 6358: }
6359:
1.346 albertel 6360: .LC_menubuttons_inline_text {
6361: color: $font;
1.698 harmsja 6362: font-size: 90%;
1.701 harmsja 6363: padding-left:3px;
1.346 albertel 6364: }
6365:
1.934 droeschl 6366: .LC_menubuttons_inline_text img{
6367: vertical-align: middle;
6368: }
6369:
1.1051 www 6370: li.LC_menubuttons_inline_text img {
1.951 onken 6371: cursor:pointer;
1.1002 droeschl 6372: text-decoration: none;
1.951 onken 6373: }
6374:
1.526 www 6375: .LC_menubuttons_link {
6376: text-decoration: none;
6377: }
1.795 www 6378:
1.522 albertel 6379: .LC_menubuttons_category {
1.521 www 6380: color: $font;
1.526 www 6381: background: $pgbg;
1.521 www 6382: font-size: larger;
6383: font-weight: bold;
6384: }
6385:
1.346 albertel 6386: td.LC_menubuttons_text {
1.911 bisitz 6387: color: $font;
1.346 albertel 6388: }
1.706 harmsja 6389:
1.346 albertel 6390: .LC_current_location {
6391: background: $tabbg;
6392: }
1.795 www 6393:
1.1075.2.134 raeburn 6394: td.LC_zero_height {
6395: line-height: 0;
6396: cellpadding: 0;
6397: }
6398:
1.938 bisitz 6399: table.LC_data_table {
1.347 albertel 6400: border: 1px solid #000000;
1.402 albertel 6401: border-collapse: separate;
1.426 albertel 6402: border-spacing: 1px;
1.610 albertel 6403: background: $pgbg;
1.347 albertel 6404: }
1.795 www 6405:
1.422 albertel 6406: .LC_data_table_dense {
6407: font-size: small;
6408: }
1.795 www 6409:
1.507 raeburn 6410: table.LC_nested_outer {
6411: border: 1px solid #000000;
1.589 raeburn 6412: border-collapse: collapse;
1.803 bisitz 6413: border-spacing: 0;
1.507 raeburn 6414: width: 100%;
6415: }
1.795 www 6416:
1.879 raeburn 6417: table.LC_innerpickbox,
1.507 raeburn 6418: table.LC_nested {
1.803 bisitz 6419: border: none;
1.589 raeburn 6420: border-collapse: collapse;
1.803 bisitz 6421: border-spacing: 0;
1.507 raeburn 6422: width: 100%;
6423: }
1.795 www 6424:
1.911 bisitz 6425: table.LC_data_table tr th,
6426: table.LC_calendar tr th,
1.879 raeburn 6427: table.LC_prior_tries tr th,
6428: table.LC_innerpickbox tr th {
1.349 albertel 6429: font-weight: bold;
6430: background-color: $data_table_head;
1.801 tempelho 6431: color:$fontmenu;
1.701 harmsja 6432: font-size:90%;
1.347 albertel 6433: }
1.795 www 6434:
1.879 raeburn 6435: table.LC_innerpickbox tr th,
6436: table.LC_innerpickbox tr td {
6437: vertical-align: top;
6438: }
6439:
1.711 raeburn 6440: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6441: background-color: #CCCCCC;
1.711 raeburn 6442: font-weight: bold;
6443: text-align: left;
6444: }
1.795 www 6445:
1.912 bisitz 6446: table.LC_data_table tr.LC_odd_row > td {
6447: background-color: $data_table_light;
6448: padding: 2px;
6449: vertical-align: top;
6450: }
6451:
1.809 bisitz 6452: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6453: background-color: $data_table_light;
1.912 bisitz 6454: vertical-align: top;
6455: }
6456:
6457: table.LC_data_table tr.LC_even_row > td {
6458: background-color: $data_table_dark;
1.425 albertel 6459: padding: 2px;
1.900 bisitz 6460: vertical-align: top;
1.347 albertel 6461: }
1.795 www 6462:
1.809 bisitz 6463: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6464: background-color: $data_table_dark;
1.900 bisitz 6465: vertical-align: top;
1.347 albertel 6466: }
1.795 www 6467:
1.425 albertel 6468: table.LC_data_table tr.LC_data_table_highlight td {
6469: background-color: $data_table_darker;
6470: }
1.795 www 6471:
1.639 raeburn 6472: table.LC_data_table tr td.LC_leftcol_header {
6473: background-color: $data_table_head;
6474: font-weight: bold;
6475: }
1.795 www 6476:
1.451 albertel 6477: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6478: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6479: font-weight: bold;
6480: font-style: italic;
6481: text-align: center;
6482: padding: 8px;
1.347 albertel 6483: }
1.795 www 6484:
1.1075.2.30 raeburn 6485: table.LC_data_table tr.LC_empty_row td,
6486: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6487: background-color: $sidebg;
6488: }
6489:
6490: table.LC_nested tr.LC_empty_row td {
6491: background-color: #FFFFFF;
6492: }
6493:
1.890 droeschl 6494: table.LC_caption {
6495: }
6496:
1.507 raeburn 6497: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6498: padding: 4ex
6499: }
1.795 www 6500:
1.507 raeburn 6501: table.LC_nested_outer tr th {
6502: font-weight: bold;
1.801 tempelho 6503: color:$fontmenu;
1.507 raeburn 6504: background-color: $data_table_head;
1.701 harmsja 6505: font-size: small;
1.507 raeburn 6506: border-bottom: 1px solid #000000;
6507: }
1.795 www 6508:
1.507 raeburn 6509: table.LC_nested_outer tr td.LC_subheader {
6510: background-color: $data_table_head;
6511: font-weight: bold;
6512: font-size: small;
6513: border-bottom: 1px solid #000000;
6514: text-align: right;
1.451 albertel 6515: }
1.795 www 6516:
1.507 raeburn 6517: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6518: background-color: #CCCCCC;
1.451 albertel 6519: font-weight: bold;
6520: font-size: small;
1.507 raeburn 6521: text-align: center;
6522: }
1.795 www 6523:
1.589 raeburn 6524: table.LC_nested tr.LC_info_row td.LC_left_item,
6525: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6526: text-align: left;
1.451 albertel 6527: }
1.795 www 6528:
1.507 raeburn 6529: table.LC_nested td {
1.735 bisitz 6530: background-color: #FFFFFF;
1.451 albertel 6531: font-size: small;
1.507 raeburn 6532: }
1.795 www 6533:
1.507 raeburn 6534: table.LC_nested_outer tr th.LC_right_item,
6535: table.LC_nested tr.LC_info_row td.LC_right_item,
6536: table.LC_nested tr.LC_odd_row td.LC_right_item,
6537: table.LC_nested tr td.LC_right_item {
1.451 albertel 6538: text-align: right;
6539: }
6540:
1.507 raeburn 6541: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6542: background-color: #EEEEEE;
1.451 albertel 6543: }
6544:
1.473 raeburn 6545: table.LC_createuser {
6546: }
6547:
6548: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6549: font-size: small;
1.473 raeburn 6550: }
6551:
6552: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6553: background-color: #CCCCCC;
1.473 raeburn 6554: font-weight: bold;
6555: text-align: center;
6556: }
6557:
1.349 albertel 6558: table.LC_calendar {
6559: border: 1px solid #000000;
6560: border-collapse: collapse;
1.917 raeburn 6561: width: 98%;
1.349 albertel 6562: }
1.795 www 6563:
1.349 albertel 6564: table.LC_calendar_pickdate {
6565: font-size: xx-small;
6566: }
1.795 www 6567:
1.349 albertel 6568: table.LC_calendar tr td {
6569: border: 1px solid #000000;
6570: vertical-align: top;
1.917 raeburn 6571: width: 14%;
1.349 albertel 6572: }
1.795 www 6573:
1.349 albertel 6574: table.LC_calendar tr td.LC_calendar_day_empty {
6575: background-color: $data_table_dark;
6576: }
1.795 www 6577:
1.779 bisitz 6578: table.LC_calendar tr td.LC_calendar_day_current {
6579: background-color: $data_table_highlight;
1.777 tempelho 6580: }
1.795 www 6581:
1.938 bisitz 6582: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6583: background-color: $mail_new;
6584: }
1.795 www 6585:
1.938 bisitz 6586: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6587: background-color: $mail_new_hover;
6588: }
1.795 www 6589:
1.938 bisitz 6590: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6591: background-color: $mail_read;
6592: }
1.795 www 6593:
1.938 bisitz 6594: /*
6595: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6596: background-color: $mail_read_hover;
6597: }
1.938 bisitz 6598: */
1.795 www 6599:
1.938 bisitz 6600: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6601: background-color: $mail_replied;
6602: }
1.795 www 6603:
1.938 bisitz 6604: /*
6605: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6606: background-color: $mail_replied_hover;
6607: }
1.938 bisitz 6608: */
1.795 www 6609:
1.938 bisitz 6610: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6611: background-color: $mail_other;
6612: }
1.795 www 6613:
1.938 bisitz 6614: /*
6615: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6616: background-color: $mail_other_hover;
6617: }
1.938 bisitz 6618: */
1.494 raeburn 6619:
1.777 tempelho 6620: table.LC_data_table tr > td.LC_browser_file,
6621: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6622: background: #AAEE77;
1.389 albertel 6623: }
1.795 www 6624:
1.777 tempelho 6625: table.LC_data_table tr > td.LC_browser_file_locked,
6626: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6627: background: #FFAA99;
1.387 albertel 6628: }
1.795 www 6629:
1.777 tempelho 6630: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6631: background: #888888;
1.779 bisitz 6632: }
1.795 www 6633:
1.777 tempelho 6634: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6635: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6636: background: #F8F866;
1.777 tempelho 6637: }
1.795 www 6638:
1.696 bisitz 6639: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6640: background: #E0E8FF;
1.387 albertel 6641: }
1.696 bisitz 6642:
1.707 bisitz 6643: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6644: /* background: #77FF77; */
1.707 bisitz 6645: }
1.795 www 6646:
1.707 bisitz 6647: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6648: border-right: 8px solid #FFFF77;
1.707 bisitz 6649: }
1.795 www 6650:
1.707 bisitz 6651: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6652: border-right: 8px solid #FFAA77;
1.707 bisitz 6653: }
1.795 www 6654:
1.707 bisitz 6655: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6656: border-right: 8px solid #FF7777;
1.707 bisitz 6657: }
1.795 www 6658:
1.707 bisitz 6659: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6660: border-right: 8px solid #AAFF77;
1.707 bisitz 6661: }
1.795 www 6662:
1.707 bisitz 6663: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6664: border-right: 8px solid #11CC55;
1.707 bisitz 6665: }
6666:
1.388 albertel 6667: span.LC_current_location {
1.701 harmsja 6668: font-size:larger;
1.388 albertel 6669: background: $pgbg;
6670: }
1.387 albertel 6671:
1.1029 www 6672: span.LC_current_nav_location {
6673: font-weight:bold;
6674: background: $sidebg;
6675: }
6676:
1.395 albertel 6677: span.LC_parm_menu_item {
6678: font-size: larger;
6679: }
1.795 www 6680:
1.395 albertel 6681: span.LC_parm_scope_all {
6682: color: red;
6683: }
1.795 www 6684:
1.395 albertel 6685: span.LC_parm_scope_folder {
6686: color: green;
6687: }
1.795 www 6688:
1.395 albertel 6689: span.LC_parm_scope_resource {
6690: color: orange;
6691: }
1.795 www 6692:
1.395 albertel 6693: span.LC_parm_part {
6694: color: blue;
6695: }
1.795 www 6696:
1.911 bisitz 6697: span.LC_parm_folder,
6698: span.LC_parm_symb {
1.395 albertel 6699: font-size: x-small;
6700: font-family: $mono;
6701: color: #AAAAAA;
6702: }
6703:
1.977 bisitz 6704: ul.LC_parm_parmlist li {
6705: display: inline-block;
6706: padding: 0.3em 0.8em;
6707: vertical-align: top;
6708: width: 150px;
6709: border-top:1px solid $lg_border_color;
6710: }
6711:
1.795 www 6712: td.LC_parm_overview_level_menu,
6713: td.LC_parm_overview_map_menu,
6714: td.LC_parm_overview_parm_selectors,
6715: td.LC_parm_overview_restrictions {
1.396 albertel 6716: border: 1px solid black;
6717: border-collapse: collapse;
6718: }
1.795 www 6719:
1.396 albertel 6720: table.LC_parm_overview_restrictions td {
6721: border-width: 1px 4px 1px 4px;
6722: border-style: solid;
6723: border-color: $pgbg;
6724: text-align: center;
6725: }
1.795 www 6726:
1.396 albertel 6727: table.LC_parm_overview_restrictions th {
6728: background: $tabbg;
6729: border-width: 1px 4px 1px 4px;
6730: border-style: solid;
6731: border-color: $pgbg;
6732: }
1.795 www 6733:
1.398 albertel 6734: table#LC_helpmenu {
1.803 bisitz 6735: border: none;
1.398 albertel 6736: height: 55px;
1.803 bisitz 6737: border-spacing: 0;
1.398 albertel 6738: }
6739:
6740: table#LC_helpmenu fieldset legend {
6741: font-size: larger;
6742: }
1.795 www 6743:
1.397 albertel 6744: table#LC_helpmenu_links {
6745: width: 100%;
6746: border: 1px solid black;
6747: background: $pgbg;
1.803 bisitz 6748: padding: 0;
1.397 albertel 6749: border-spacing: 1px;
6750: }
1.795 www 6751:
1.397 albertel 6752: table#LC_helpmenu_links tr td {
6753: padding: 1px;
6754: background: $tabbg;
1.399 albertel 6755: text-align: center;
6756: font-weight: bold;
1.397 albertel 6757: }
1.396 albertel 6758:
1.795 www 6759: table#LC_helpmenu_links a:link,
6760: table#LC_helpmenu_links a:visited,
1.397 albertel 6761: table#LC_helpmenu_links a:active {
6762: text-decoration: none;
6763: color: $font;
6764: }
1.795 www 6765:
1.397 albertel 6766: table#LC_helpmenu_links a:hover {
6767: text-decoration: underline;
6768: color: $vlink;
6769: }
1.396 albertel 6770:
1.417 albertel 6771: .LC_chrt_popup_exists {
6772: border: 1px solid #339933;
6773: margin: -1px;
6774: }
1.795 www 6775:
1.417 albertel 6776: .LC_chrt_popup_up {
6777: border: 1px solid yellow;
6778: margin: -1px;
6779: }
1.795 www 6780:
1.417 albertel 6781: .LC_chrt_popup {
6782: border: 1px solid #8888FF;
6783: background: #CCCCFF;
6784: }
1.795 www 6785:
1.421 albertel 6786: table.LC_pick_box {
6787: border-collapse: separate;
6788: background: white;
6789: border: 1px solid black;
6790: border-spacing: 1px;
6791: }
1.795 www 6792:
1.421 albertel 6793: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6794: background: $sidebg;
1.421 albertel 6795: font-weight: bold;
1.900 bisitz 6796: text-align: left;
1.740 bisitz 6797: vertical-align: top;
1.421 albertel 6798: width: 184px;
6799: padding: 8px;
6800: }
1.795 www 6801:
1.579 raeburn 6802: table.LC_pick_box td.LC_pick_box_value {
6803: text-align: left;
6804: padding: 8px;
6805: }
1.795 www 6806:
1.579 raeburn 6807: table.LC_pick_box td.LC_pick_box_select {
6808: text-align: left;
6809: padding: 8px;
6810: }
1.795 www 6811:
1.424 albertel 6812: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6813: padding: 0;
1.421 albertel 6814: height: 1px;
6815: background: black;
6816: }
1.795 www 6817:
1.421 albertel 6818: table.LC_pick_box td.LC_pick_box_submit {
6819: text-align: right;
6820: }
1.795 www 6821:
1.579 raeburn 6822: table.LC_pick_box td.LC_evenrow_value {
6823: text-align: left;
6824: padding: 8px;
6825: background-color: $data_table_light;
6826: }
1.795 www 6827:
1.579 raeburn 6828: table.LC_pick_box td.LC_oddrow_value {
6829: text-align: left;
6830: padding: 8px;
6831: background-color: $data_table_light;
6832: }
1.795 www 6833:
1.579 raeburn 6834: span.LC_helpform_receipt_cat {
6835: font-weight: bold;
6836: }
1.795 www 6837:
1.424 albertel 6838: table.LC_group_priv_box {
6839: background: white;
6840: border: 1px solid black;
6841: border-spacing: 1px;
6842: }
1.795 www 6843:
1.424 albertel 6844: table.LC_group_priv_box td.LC_pick_box_title {
6845: background: $tabbg;
6846: font-weight: bold;
6847: text-align: right;
6848: width: 184px;
6849: }
1.795 www 6850:
1.424 albertel 6851: table.LC_group_priv_box td.LC_groups_fixed {
6852: background: $data_table_light;
6853: text-align: center;
6854: }
1.795 www 6855:
1.424 albertel 6856: table.LC_group_priv_box td.LC_groups_optional {
6857: background: $data_table_dark;
6858: text-align: center;
6859: }
1.795 www 6860:
1.424 albertel 6861: table.LC_group_priv_box td.LC_groups_functionality {
6862: background: $data_table_darker;
6863: text-align: center;
6864: font-weight: bold;
6865: }
1.795 www 6866:
1.424 albertel 6867: table.LC_group_priv td {
6868: text-align: left;
1.803 bisitz 6869: padding: 0;
1.424 albertel 6870: }
6871:
6872: .LC_navbuttons {
6873: margin: 2ex 0ex 2ex 0ex;
6874: }
1.795 www 6875:
1.423 albertel 6876: .LC_topic_bar {
6877: font-weight: bold;
6878: background: $tabbg;
1.918 wenzelju 6879: margin: 1em 0em 1em 2em;
1.805 bisitz 6880: padding: 3px;
1.918 wenzelju 6881: font-size: 1.2em;
1.423 albertel 6882: }
1.795 www 6883:
1.423 albertel 6884: .LC_topic_bar span {
1.918 wenzelju 6885: left: 0.5em;
6886: position: absolute;
1.423 albertel 6887: vertical-align: middle;
1.918 wenzelju 6888: font-size: 1.2em;
1.423 albertel 6889: }
1.795 www 6890:
1.423 albertel 6891: table.LC_course_group_status {
6892: margin: 20px;
6893: }
1.795 www 6894:
1.423 albertel 6895: table.LC_status_selector td {
6896: vertical-align: top;
6897: text-align: center;
1.424 albertel 6898: padding: 4px;
6899: }
1.795 www 6900:
1.599 albertel 6901: div.LC_feedback_link {
1.616 albertel 6902: clear: both;
1.829 kalberla 6903: background: $sidebg;
1.779 bisitz 6904: width: 100%;
1.829 kalberla 6905: padding-bottom: 10px;
6906: border: 1px $tabbg solid;
1.833 kalberla 6907: height: 22px;
6908: line-height: 22px;
6909: padding-top: 5px;
6910: }
6911:
6912: div.LC_feedback_link img {
6913: height: 22px;
1.867 kalberla 6914: vertical-align:middle;
1.829 kalberla 6915: }
6916:
1.911 bisitz 6917: div.LC_feedback_link a {
1.829 kalberla 6918: text-decoration: none;
1.489 raeburn 6919: }
1.795 www 6920:
1.867 kalberla 6921: div.LC_comblock {
1.911 bisitz 6922: display:inline;
1.867 kalberla 6923: color:$font;
6924: font-size:90%;
6925: }
6926:
6927: div.LC_feedback_link div.LC_comblock {
6928: padding-left:5px;
6929: }
6930:
6931: div.LC_feedback_link div.LC_comblock a {
6932: color:$font;
6933: }
6934:
1.489 raeburn 6935: span.LC_feedback_link {
1.858 bisitz 6936: /* background: $feedback_link_bg; */
1.599 albertel 6937: font-size: larger;
6938: }
1.795 www 6939:
1.599 albertel 6940: span.LC_message_link {
1.858 bisitz 6941: /* background: $feedback_link_bg; */
1.599 albertel 6942: font-size: larger;
6943: position: absolute;
6944: right: 1em;
1.489 raeburn 6945: }
1.421 albertel 6946:
1.515 albertel 6947: table.LC_prior_tries {
1.524 albertel 6948: border: 1px solid #000000;
6949: border-collapse: separate;
6950: border-spacing: 1px;
1.515 albertel 6951: }
1.523 albertel 6952:
1.515 albertel 6953: table.LC_prior_tries td {
1.524 albertel 6954: padding: 2px;
1.515 albertel 6955: }
1.523 albertel 6956:
6957: .LC_answer_correct {
1.795 www 6958: background: lightgreen;
6959: color: darkgreen;
6960: padding: 6px;
1.523 albertel 6961: }
1.795 www 6962:
1.523 albertel 6963: .LC_answer_charged_try {
1.797 www 6964: background: #FFAAAA;
1.795 www 6965: color: darkred;
6966: padding: 6px;
1.523 albertel 6967: }
1.795 www 6968:
1.779 bisitz 6969: .LC_answer_not_charged_try,
1.523 albertel 6970: .LC_answer_no_grade,
6971: .LC_answer_late {
1.795 www 6972: background: lightyellow;
1.523 albertel 6973: color: black;
1.795 www 6974: padding: 6px;
1.523 albertel 6975: }
1.795 www 6976:
1.523 albertel 6977: .LC_answer_previous {
1.795 www 6978: background: lightblue;
6979: color: darkblue;
6980: padding: 6px;
1.523 albertel 6981: }
1.795 www 6982:
1.779 bisitz 6983: .LC_answer_no_message {
1.777 tempelho 6984: background: #FFFFFF;
6985: color: black;
1.795 www 6986: padding: 6px;
1.779 bisitz 6987: }
1.795 www 6988:
1.1075.2.140 raeburn 6989: .LC_answer_unknown,
6990: .LC_answer_warning {
1.779 bisitz 6991: background: orange;
6992: color: black;
1.795 www 6993: padding: 6px;
1.777 tempelho 6994: }
1.795 www 6995:
1.529 albertel 6996: span.LC_prior_numerical,
6997: span.LC_prior_string,
6998: span.LC_prior_custom,
6999: span.LC_prior_reaction,
7000: span.LC_prior_math {
1.925 bisitz 7001: font-family: $mono;
1.523 albertel 7002: white-space: pre;
7003: }
7004:
1.525 albertel 7005: span.LC_prior_string {
1.925 bisitz 7006: font-family: $mono;
1.525 albertel 7007: white-space: pre;
7008: }
7009:
1.523 albertel 7010: table.LC_prior_option {
7011: width: 100%;
7012: border-collapse: collapse;
7013: }
1.795 www 7014:
1.911 bisitz 7015: table.LC_prior_rank,
1.795 www 7016: table.LC_prior_match {
1.528 albertel 7017: border-collapse: collapse;
7018: }
1.795 www 7019:
1.528 albertel 7020: table.LC_prior_option tr td,
7021: table.LC_prior_rank tr td,
7022: table.LC_prior_match tr td {
1.524 albertel 7023: border: 1px solid #000000;
1.515 albertel 7024: }
7025:
1.855 bisitz 7026: .LC_nobreak {
1.544 albertel 7027: white-space: nowrap;
1.519 raeburn 7028: }
7029:
1.576 raeburn 7030: span.LC_cusr_emph {
7031: font-style: italic;
7032: }
7033:
1.633 raeburn 7034: span.LC_cusr_subheading {
7035: font-weight: normal;
7036: font-size: 85%;
7037: }
7038:
1.861 bisitz 7039: div.LC_docs_entry_move {
1.859 bisitz 7040: border: 1px solid #BBBBBB;
1.545 albertel 7041: background: #DDDDDD;
1.861 bisitz 7042: width: 22px;
1.859 bisitz 7043: padding: 1px;
7044: margin: 0;
1.545 albertel 7045: }
7046:
1.861 bisitz 7047: table.LC_data_table tr > td.LC_docs_entry_commands,
7048: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7049: font-size: x-small;
7050: }
1.795 www 7051:
1.861 bisitz 7052: .LC_docs_entry_parameter {
7053: white-space: nowrap;
7054: }
7055:
1.544 albertel 7056: .LC_docs_copy {
1.545 albertel 7057: color: #000099;
1.544 albertel 7058: }
1.795 www 7059:
1.544 albertel 7060: .LC_docs_cut {
1.545 albertel 7061: color: #550044;
1.544 albertel 7062: }
1.795 www 7063:
1.544 albertel 7064: .LC_docs_rename {
1.545 albertel 7065: color: #009900;
1.544 albertel 7066: }
1.795 www 7067:
1.544 albertel 7068: .LC_docs_remove {
1.545 albertel 7069: color: #990000;
7070: }
7071:
1.1075.2.134 raeburn 7072: .LC_domprefs_email,
1.547 albertel 7073: .LC_docs_reinit_warn,
7074: .LC_docs_ext_edit {
7075: font-size: x-small;
7076: }
7077:
1.545 albertel 7078: table.LC_docs_adddocs td,
7079: table.LC_docs_adddocs th {
7080: border: 1px solid #BBBBBB;
7081: padding: 4px;
7082: background: #DDDDDD;
1.543 albertel 7083: }
7084:
1.584 albertel 7085: table.LC_sty_begin {
7086: background: #BBFFBB;
7087: }
1.795 www 7088:
1.584 albertel 7089: table.LC_sty_end {
7090: background: #FFBBBB;
7091: }
7092:
1.589 raeburn 7093: table.LC_double_column {
1.803 bisitz 7094: border-width: 0;
1.589 raeburn 7095: border-collapse: collapse;
7096: width: 100%;
7097: padding: 2px;
7098: }
7099:
7100: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7101: top: 2px;
1.589 raeburn 7102: left: 2px;
7103: width: 47%;
7104: vertical-align: top;
7105: }
7106:
7107: table.LC_double_column tr td.LC_right_col {
7108: top: 2px;
1.779 bisitz 7109: right: 2px;
1.589 raeburn 7110: width: 47%;
7111: vertical-align: top;
7112: }
7113:
1.591 raeburn 7114: div.LC_left_float {
7115: float: left;
7116: padding-right: 5%;
1.597 albertel 7117: padding-bottom: 4px;
1.591 raeburn 7118: }
7119:
7120: div.LC_clear_float_header {
1.597 albertel 7121: padding-bottom: 2px;
1.591 raeburn 7122: }
7123:
7124: div.LC_clear_float_footer {
1.597 albertel 7125: padding-top: 10px;
1.591 raeburn 7126: clear: both;
7127: }
7128:
1.597 albertel 7129: div.LC_grade_show_user {
1.941 bisitz 7130: /* border-left: 5px solid $sidebg; */
7131: border-top: 5px solid #000000;
7132: margin: 50px 0 0 0;
1.936 bisitz 7133: padding: 15px 0 5px 10px;
1.597 albertel 7134: }
1.795 www 7135:
1.936 bisitz 7136: div.LC_grade_show_user_odd_row {
1.941 bisitz 7137: /* border-left: 5px solid #000000; */
7138: }
7139:
7140: div.LC_grade_show_user div.LC_Box {
7141: margin-right: 50px;
1.597 albertel 7142: }
7143:
7144: div.LC_grade_submissions,
7145: div.LC_grade_message_center,
1.936 bisitz 7146: div.LC_grade_info_links {
1.597 albertel 7147: margin: 5px;
7148: width: 99%;
7149: background: #FFFFFF;
7150: }
1.795 www 7151:
1.597 albertel 7152: div.LC_grade_submissions_header,
1.936 bisitz 7153: div.LC_grade_message_center_header {
1.705 tempelho 7154: font-weight: bold;
7155: font-size: large;
1.597 albertel 7156: }
1.795 www 7157:
1.597 albertel 7158: div.LC_grade_submissions_body,
1.936 bisitz 7159: div.LC_grade_message_center_body {
1.597 albertel 7160: border: 1px solid black;
7161: width: 99%;
7162: background: #FFFFFF;
7163: }
1.795 www 7164:
1.613 albertel 7165: table.LC_scantron_action {
7166: width: 100%;
7167: }
1.795 www 7168:
1.613 albertel 7169: table.LC_scantron_action tr th {
1.698 harmsja 7170: font-weight:bold;
7171: font-style:normal;
1.613 albertel 7172: }
1.795 www 7173:
1.779 bisitz 7174: .LC_edit_problem_header,
1.614 albertel 7175: div.LC_edit_problem_footer {
1.705 tempelho 7176: font-weight: normal;
7177: font-size: medium;
1.602 albertel 7178: margin: 2px;
1.1060 bisitz 7179: background-color: $sidebg;
1.600 albertel 7180: }
1.795 www 7181:
1.600 albertel 7182: div.LC_edit_problem_header,
1.602 albertel 7183: div.LC_edit_problem_header div,
1.614 albertel 7184: div.LC_edit_problem_footer,
7185: div.LC_edit_problem_footer div,
1.602 albertel 7186: div.LC_edit_problem_editxml_header,
7187: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7188: z-index: 100;
1.600 albertel 7189: }
1.795 www 7190:
1.600 albertel 7191: div.LC_edit_problem_header_title {
1.705 tempelho 7192: font-weight: bold;
7193: font-size: larger;
1.602 albertel 7194: background: $tabbg;
7195: padding: 3px;
1.1060 bisitz 7196: margin: 0 0 5px 0;
1.602 albertel 7197: }
1.795 www 7198:
1.602 albertel 7199: table.LC_edit_problem_header_title {
7200: width: 100%;
1.600 albertel 7201: background: $tabbg;
1.602 albertel 7202: }
7203:
1.1075.2.112 raeburn 7204: div.LC_edit_actionbar {
7205: background-color: $sidebg;
7206: margin: 0;
7207: padding: 0;
7208: line-height: 200%;
1.602 albertel 7209: }
1.795 www 7210:
1.1075.2.112 raeburn 7211: div.LC_edit_actionbar div{
7212: padding: 0;
7213: margin: 0;
7214: display: inline-block;
1.600 albertel 7215: }
1.795 www 7216:
1.1075.2.34 raeburn 7217: .LC_edit_opt {
7218: padding-left: 1em;
7219: white-space: nowrap;
7220: }
7221:
1.1075.2.57 raeburn 7222: .LC_edit_problem_latexhelper{
7223: text-align: right;
7224: }
7225:
7226: #LC_edit_problem_colorful div{
7227: margin-left: 40px;
7228: }
7229:
1.1075.2.112 raeburn 7230: #LC_edit_problem_codemirror div{
7231: margin-left: 0px;
7232: }
7233:
1.911 bisitz 7234: img.stift {
1.803 bisitz 7235: border-width: 0;
7236: vertical-align: middle;
1.677 riegler 7237: }
1.680 riegler 7238:
1.923 bisitz 7239: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7240: vertical-align: top;
1.777 tempelho 7241: }
1.795 www 7242:
1.716 raeburn 7243: div.LC_createcourse {
1.911 bisitz 7244: margin: 10px 10px 10px 10px;
1.716 raeburn 7245: }
7246:
1.917 raeburn 7247: .LC_dccid {
1.1075.2.38 raeburn 7248: float: right;
1.917 raeburn 7249: margin: 0.2em 0 0 0;
7250: padding: 0;
7251: font-size: 90%;
7252: display:none;
7253: }
7254:
1.897 wenzelju 7255: ol.LC_primary_menu a:hover,
1.721 harmsja 7256: ol#LC_MenuBreadcrumbs a:hover,
7257: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7258: ul#LC_secondary_menu a:hover,
1.721 harmsja 7259: .LC_FormSectionClearButton input:hover
1.795 www 7260: ul.LC_TabContent li:hover a {
1.952 onken 7261: color:$button_hover;
1.911 bisitz 7262: text-decoration:none;
1.693 droeschl 7263: }
7264:
1.779 bisitz 7265: h1 {
1.911 bisitz 7266: padding: 0;
7267: line-height:130%;
1.693 droeschl 7268: }
1.698 harmsja 7269:
1.911 bisitz 7270: h2,
7271: h3,
7272: h4,
7273: h5,
7274: h6 {
7275: margin: 5px 0 5px 0;
7276: padding: 0;
7277: line-height:130%;
1.693 droeschl 7278: }
1.795 www 7279:
7280: .LC_hcell {
1.911 bisitz 7281: padding:3px 15px 3px 15px;
7282: margin: 0;
7283: background-color:$tabbg;
7284: color:$fontmenu;
7285: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7286: }
1.795 www 7287:
1.840 bisitz 7288: .LC_Box > .LC_hcell {
1.911 bisitz 7289: margin: 0 -10px 10px -10px;
1.835 bisitz 7290: }
7291:
1.721 harmsja 7292: .LC_noBorder {
1.911 bisitz 7293: border: 0;
1.698 harmsja 7294: }
1.693 droeschl 7295:
1.721 harmsja 7296: .LC_FormSectionClearButton input {
1.911 bisitz 7297: background-color:transparent;
7298: border: none;
7299: cursor:pointer;
7300: text-decoration:underline;
1.693 droeschl 7301: }
1.763 bisitz 7302:
7303: .LC_help_open_topic {
1.911 bisitz 7304: color: #FFFFFF;
7305: background-color: #EEEEFF;
7306: margin: 1px;
7307: padding: 4px;
7308: border: 1px solid #000033;
7309: white-space: nowrap;
7310: /* vertical-align: middle; */
1.759 neumanie 7311: }
1.693 droeschl 7312:
1.911 bisitz 7313: dl,
7314: ul,
7315: div,
7316: fieldset {
7317: margin: 10px 10px 10px 0;
7318: /* overflow: hidden; */
1.693 droeschl 7319: }
1.795 www 7320:
1.1075.2.90 raeburn 7321: article.geogebraweb div {
7322: margin: 0;
7323: }
7324:
1.838 bisitz 7325: fieldset > legend {
1.911 bisitz 7326: font-weight: bold;
7327: padding: 0 5px 0 5px;
1.838 bisitz 7328: }
7329:
1.813 bisitz 7330: #LC_nav_bar {
1.911 bisitz 7331: float: left;
1.995 raeburn 7332: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7333: margin: 0 0 2px 0;
1.807 droeschl 7334: }
7335:
1.916 droeschl 7336: #LC_realm {
7337: margin: 0.2em 0 0 0;
7338: padding: 0;
7339: font-weight: bold;
7340: text-align: center;
1.995 raeburn 7341: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7342: }
7343:
1.911 bisitz 7344: #LC_nav_bar em {
7345: font-weight: bold;
7346: font-style: normal;
1.807 droeschl 7347: }
7348:
1.897 wenzelju 7349: ol.LC_primary_menu {
1.934 droeschl 7350: margin: 0;
1.1075.2.2 raeburn 7351: padding: 0;
1.807 droeschl 7352: }
7353:
1.852 droeschl 7354: ol#LC_PathBreadcrumbs {
1.911 bisitz 7355: margin: 0;
1.693 droeschl 7356: }
7357:
1.897 wenzelju 7358: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7359: color: RGB(80, 80, 80);
7360: vertical-align: middle;
7361: text-align: left;
7362: list-style: none;
1.1075.2.112 raeburn 7363: position: relative;
1.1075.2.2 raeburn 7364: float: left;
1.1075.2.112 raeburn 7365: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7366: line-height: 1.5em;
1.1075.2.2 raeburn 7367: }
7368:
1.1075.2.113 raeburn 7369: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7370: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7371: display: block;
7372: margin: 0;
7373: padding: 0 5px 0 10px;
7374: text-decoration: none;
7375: }
7376:
1.1075.2.112 raeburn 7377: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7378: display: inline-block;
7379: width: 95%;
7380: text-align: left;
7381: }
7382:
7383: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7384: display: inline-block;
7385: width: 5%;
7386: float: right;
7387: text-align: right;
7388: font-size: 70%;
7389: }
7390:
7391: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7392: display: none;
1.1075.2.112 raeburn 7393: width: 15em;
1.1075.2.2 raeburn 7394: background-color: $data_table_light;
1.1075.2.112 raeburn 7395: position: absolute;
7396: top: 100%;
7397: }
7398:
7399: ol.LC_primary_menu ul ul {
7400: left: 100%;
7401: top: 0;
1.1075.2.2 raeburn 7402: }
7403:
1.1075.2.112 raeburn 7404: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7405: display: block;
7406: position: absolute;
7407: margin: 0;
7408: padding: 0;
1.1075.2.5 raeburn 7409: z-index: 2;
1.1075.2.2 raeburn 7410: }
7411:
7412: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7413: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7414: font-size: 90%;
1.911 bisitz 7415: vertical-align: top;
1.1075.2.2 raeburn 7416: float: none;
1.1075.2.5 raeburn 7417: border-left: 1px solid black;
7418: border-right: 1px solid black;
1.1075.2.112 raeburn 7419: /* A dark bottom border to visualize different menu options;
7420: overwritten in the create_submenu routine for the last border-bottom of the menu */
7421: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7422: }
7423:
1.1075.2.112 raeburn 7424: ol.LC_primary_menu li li p:hover {
7425: color:$button_hover;
7426: text-decoration:none;
7427: background-color:$data_table_dark;
1.1075.2.2 raeburn 7428: }
7429:
7430: ol.LC_primary_menu li li a:hover {
7431: color:$button_hover;
7432: background-color:$data_table_dark;
1.693 droeschl 7433: }
7434:
1.1075.2.112 raeburn 7435: /* Font-size equal to the size of the predecessors*/
7436: ol.LC_primary_menu li:hover li li {
7437: font-size: 100%;
7438: }
7439:
1.897 wenzelju 7440: ol.LC_primary_menu li img {
1.911 bisitz 7441: vertical-align: bottom;
1.934 droeschl 7442: height: 1.1em;
1.1075.2.3 raeburn 7443: margin: 0.2em 0 0 0;
1.693 droeschl 7444: }
7445:
1.897 wenzelju 7446: ol.LC_primary_menu a {
1.911 bisitz 7447: color: RGB(80, 80, 80);
7448: text-decoration: none;
1.693 droeschl 7449: }
1.795 www 7450:
1.949 droeschl 7451: ol.LC_primary_menu a.LC_new_message {
7452: font-weight:bold;
7453: color: darkred;
7454: }
7455:
1.975 raeburn 7456: ol.LC_docs_parameters {
7457: margin-left: 0;
7458: padding: 0;
7459: list-style: none;
7460: }
7461:
7462: ol.LC_docs_parameters li {
7463: margin: 0;
7464: padding-right: 20px;
7465: display: inline;
7466: }
7467:
1.976 raeburn 7468: ol.LC_docs_parameters li:before {
7469: content: "\\002022 \\0020";
7470: }
7471:
7472: li.LC_docs_parameters_title {
7473: font-weight: bold;
7474: }
7475:
7476: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7477: content: "";
7478: }
7479:
1.897 wenzelju 7480: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7481: clear: right;
1.911 bisitz 7482: color: $fontmenu;
7483: background: $tabbg;
7484: list-style: none;
7485: padding: 0;
7486: margin: 0;
7487: width: 100%;
1.995 raeburn 7488: text-align: left;
1.1075.2.4 raeburn 7489: float: left;
1.808 droeschl 7490: }
7491:
1.897 wenzelju 7492: ul#LC_secondary_menu li {
1.911 bisitz 7493: font-weight: bold;
7494: line-height: 1.8em;
7495: border-right: 1px solid black;
1.1075.2.4 raeburn 7496: float: left;
7497: }
7498:
7499: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7500: background-color: $data_table_light;
7501: }
7502:
7503: ul#LC_secondary_menu li a {
7504: padding: 0 0.8em;
7505: }
7506:
7507: ul#LC_secondary_menu li ul {
7508: display: none;
7509: }
7510:
7511: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7512: display: block;
7513: position: absolute;
7514: margin: 0;
7515: padding: 0;
7516: list-style:none;
7517: float: none;
7518: background-color: $data_table_light;
1.1075.2.5 raeburn 7519: z-index: 2;
1.1075.2.10 raeburn 7520: margin-left: -1px;
1.1075.2.4 raeburn 7521: }
7522:
7523: ul#LC_secondary_menu li ul li {
7524: font-size: 90%;
7525: vertical-align: top;
7526: border-left: 1px solid black;
7527: border-right: 1px solid black;
1.1075.2.33 raeburn 7528: background-color: $data_table_light;
1.1075.2.4 raeburn 7529: list-style:none;
7530: float: none;
7531: }
7532:
7533: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7534: background-color: $data_table_dark;
1.807 droeschl 7535: }
7536:
1.847 tempelho 7537: ul.LC_TabContent {
1.911 bisitz 7538: display:block;
7539: background: $sidebg;
7540: border-bottom: solid 1px $lg_border_color;
7541: list-style:none;
1.1020 raeburn 7542: margin: -1px -10px 0 -10px;
1.911 bisitz 7543: padding: 0;
1.693 droeschl 7544: }
7545:
1.795 www 7546: ul.LC_TabContent li,
7547: ul.LC_TabContentBigger li {
1.911 bisitz 7548: float:left;
1.741 harmsja 7549: }
1.795 www 7550:
1.897 wenzelju 7551: ul#LC_secondary_menu li a {
1.911 bisitz 7552: color: $fontmenu;
7553: text-decoration: none;
1.693 droeschl 7554: }
1.795 www 7555:
1.721 harmsja 7556: ul.LC_TabContent {
1.952 onken 7557: min-height:20px;
1.721 harmsja 7558: }
1.795 www 7559:
7560: ul.LC_TabContent li {
1.911 bisitz 7561: vertical-align:middle;
1.959 onken 7562: padding: 0 16px 0 10px;
1.911 bisitz 7563: background-color:$tabbg;
7564: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7565: border-left: solid 1px $font;
1.721 harmsja 7566: }
1.795 www 7567:
1.847 tempelho 7568: ul.LC_TabContent .right {
1.911 bisitz 7569: float:right;
1.847 tempelho 7570: }
7571:
1.911 bisitz 7572: ul.LC_TabContent li a,
7573: ul.LC_TabContent li {
7574: color:rgb(47,47,47);
7575: text-decoration:none;
7576: font-size:95%;
7577: font-weight:bold;
1.952 onken 7578: min-height:20px;
7579: }
7580:
1.959 onken 7581: ul.LC_TabContent li a:hover,
7582: ul.LC_TabContent li a:focus {
1.952 onken 7583: color: $button_hover;
1.959 onken 7584: background:none;
7585: outline:none;
1.952 onken 7586: }
7587:
7588: ul.LC_TabContent li:hover {
7589: color: $button_hover;
7590: cursor:pointer;
1.721 harmsja 7591: }
1.795 www 7592:
1.911 bisitz 7593: ul.LC_TabContent li.active {
1.952 onken 7594: color: $font;
1.911 bisitz 7595: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7596: border-bottom:solid 1px #FFFFFF;
7597: cursor: default;
1.744 ehlerst 7598: }
1.795 www 7599:
1.959 onken 7600: ul.LC_TabContent li.active a {
7601: color:$font;
7602: background:#FFFFFF;
7603: outline: none;
7604: }
1.1047 raeburn 7605:
7606: ul.LC_TabContent li.goback {
7607: float: left;
7608: border-left: none;
7609: }
7610:
1.870 tempelho 7611: #maincoursedoc {
1.911 bisitz 7612: clear:both;
1.870 tempelho 7613: }
7614:
7615: ul.LC_TabContentBigger {
1.911 bisitz 7616: display:block;
7617: list-style:none;
7618: padding: 0;
1.870 tempelho 7619: }
7620:
1.795 www 7621: ul.LC_TabContentBigger li {
1.911 bisitz 7622: vertical-align:bottom;
7623: height: 30px;
7624: font-size:110%;
7625: font-weight:bold;
7626: color: #737373;
1.841 tempelho 7627: }
7628:
1.957 onken 7629: ul.LC_TabContentBigger li.active {
7630: position: relative;
7631: top: 1px;
7632: }
7633:
1.870 tempelho 7634: ul.LC_TabContentBigger li a {
1.911 bisitz 7635: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7636: height: 30px;
7637: line-height: 30px;
7638: text-align: center;
7639: display: block;
7640: text-decoration: none;
1.958 onken 7641: outline: none;
1.741 harmsja 7642: }
1.795 www 7643:
1.870 tempelho 7644: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7645: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7646: color:$font;
1.744 ehlerst 7647: }
1.795 www 7648:
1.870 tempelho 7649: ul.LC_TabContentBigger li b {
1.911 bisitz 7650: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7651: display: block;
7652: float: left;
7653: padding: 0 30px;
1.957 onken 7654: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7655: }
7656:
1.956 onken 7657: ul.LC_TabContentBigger li:hover b {
7658: color:$button_hover;
7659: }
7660:
1.870 tempelho 7661: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7662: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7663: color:$font;
1.957 onken 7664: border: 0;
1.741 harmsja 7665: }
1.693 droeschl 7666:
1.870 tempelho 7667:
1.862 bisitz 7668: ul.LC_CourseBreadcrumbs {
7669: background: $sidebg;
1.1020 raeburn 7670: height: 2em;
1.862 bisitz 7671: padding-left: 10px;
1.1020 raeburn 7672: margin: 0;
1.862 bisitz 7673: list-style-position: inside;
7674: }
7675:
1.911 bisitz 7676: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7677: ol#LC_PathBreadcrumbs {
1.911 bisitz 7678: padding-left: 10px;
7679: margin: 0;
1.933 droeschl 7680: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7681: }
7682:
1.911 bisitz 7683: ol#LC_MenuBreadcrumbs li,
7684: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7685: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7686: display: inline;
1.933 droeschl 7687: white-space: normal;
1.693 droeschl 7688: }
7689:
1.823 bisitz 7690: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7691: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7692: text-decoration: none;
7693: font-size:90%;
1.693 droeschl 7694: }
1.795 www 7695:
1.969 droeschl 7696: ol#LC_MenuBreadcrumbs h1 {
7697: display: inline;
7698: font-size: 90%;
7699: line-height: 2.5em;
7700: margin: 0;
7701: padding: 0;
7702: }
7703:
1.795 www 7704: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7705: text-decoration:none;
7706: font-size:100%;
7707: font-weight:bold;
1.693 droeschl 7708: }
1.795 www 7709:
1.840 bisitz 7710: .LC_Box {
1.911 bisitz 7711: border: solid 1px $lg_border_color;
7712: padding: 0 10px 10px 10px;
1.746 neumanie 7713: }
1.795 www 7714:
1.1020 raeburn 7715: .LC_DocsBox {
7716: border: solid 1px $lg_border_color;
7717: padding: 0 0 10px 10px;
7718: }
7719:
1.795 www 7720: .LC_AboutMe_Image {
1.911 bisitz 7721: float:left;
7722: margin-right:10px;
1.747 neumanie 7723: }
1.795 www 7724:
7725: .LC_Clear_AboutMe_Image {
1.911 bisitz 7726: clear:left;
1.747 neumanie 7727: }
1.795 www 7728:
1.721 harmsja 7729: dl.LC_ListStyleClean dt {
1.911 bisitz 7730: padding-right: 5px;
7731: display: table-header-group;
1.693 droeschl 7732: }
7733:
1.721 harmsja 7734: dl.LC_ListStyleClean dd {
1.911 bisitz 7735: display: table-row;
1.693 droeschl 7736: }
7737:
1.721 harmsja 7738: .LC_ListStyleClean,
7739: .LC_ListStyleSimple,
7740: .LC_ListStyleNormal,
1.795 www 7741: .LC_ListStyleSpecial {
1.911 bisitz 7742: /* display:block; */
7743: list-style-position: inside;
7744: list-style-type: none;
7745: overflow: hidden;
7746: padding: 0;
1.693 droeschl 7747: }
7748:
1.721 harmsja 7749: .LC_ListStyleSimple li,
7750: .LC_ListStyleSimple dd,
7751: .LC_ListStyleNormal li,
7752: .LC_ListStyleNormal dd,
7753: .LC_ListStyleSpecial li,
1.795 www 7754: .LC_ListStyleSpecial dd {
1.911 bisitz 7755: margin: 0;
7756: padding: 5px 5px 5px 10px;
7757: clear: both;
1.693 droeschl 7758: }
7759:
1.721 harmsja 7760: .LC_ListStyleClean li,
7761: .LC_ListStyleClean dd {
1.911 bisitz 7762: padding-top: 0;
7763: padding-bottom: 0;
1.693 droeschl 7764: }
7765:
1.721 harmsja 7766: .LC_ListStyleSimple dd,
1.795 www 7767: .LC_ListStyleSimple li {
1.911 bisitz 7768: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7769: }
7770:
1.721 harmsja 7771: .LC_ListStyleSpecial li,
7772: .LC_ListStyleSpecial dd {
1.911 bisitz 7773: list-style-type: none;
7774: background-color: RGB(220, 220, 220);
7775: margin-bottom: 4px;
1.693 droeschl 7776: }
7777:
1.721 harmsja 7778: table.LC_SimpleTable {
1.911 bisitz 7779: margin:5px;
7780: border:solid 1px $lg_border_color;
1.795 www 7781: }
1.693 droeschl 7782:
1.721 harmsja 7783: table.LC_SimpleTable tr {
1.911 bisitz 7784: padding: 0;
7785: border:solid 1px $lg_border_color;
1.693 droeschl 7786: }
1.795 www 7787:
7788: table.LC_SimpleTable thead {
1.911 bisitz 7789: background:rgb(220,220,220);
1.693 droeschl 7790: }
7791:
1.721 harmsja 7792: div.LC_columnSection {
1.911 bisitz 7793: display: block;
7794: clear: both;
7795: overflow: hidden;
7796: margin: 0;
1.693 droeschl 7797: }
7798:
1.721 harmsja 7799: div.LC_columnSection>* {
1.911 bisitz 7800: float: left;
7801: margin: 10px 20px 10px 0;
7802: overflow:hidden;
1.693 droeschl 7803: }
1.721 harmsja 7804:
1.795 www 7805: table em {
1.911 bisitz 7806: font-weight: bold;
7807: font-style: normal;
1.748 schulted 7808: }
1.795 www 7809:
1.779 bisitz 7810: table.LC_tableBrowseRes,
1.795 www 7811: table.LC_tableOfContent {
1.911 bisitz 7812: border:none;
7813: border-spacing: 1px;
7814: padding: 3px;
7815: background-color: #FFFFFF;
7816: font-size: 90%;
1.753 droeschl 7817: }
1.789 droeschl 7818:
1.911 bisitz 7819: table.LC_tableOfContent {
7820: border-collapse: collapse;
1.789 droeschl 7821: }
7822:
1.771 droeschl 7823: table.LC_tableBrowseRes a,
1.768 schulted 7824: table.LC_tableOfContent a {
1.911 bisitz 7825: background-color: transparent;
7826: text-decoration: none;
1.753 droeschl 7827: }
7828:
1.795 www 7829: table.LC_tableOfContent img {
1.911 bisitz 7830: border: none;
7831: height: 1.3em;
7832: vertical-align: text-bottom;
7833: margin-right: 0.3em;
1.753 droeschl 7834: }
1.757 schulted 7835:
1.795 www 7836: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7837: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7838: }
7839:
1.795 www 7840: a#LC_content_toolbar_everything {
1.911 bisitz 7841: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7842: }
7843:
1.795 www 7844: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7845: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7846: }
7847:
1.795 www 7848: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7849: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7850: }
7851:
1.795 www 7852: a#LC_content_toolbar_changefolder {
1.911 bisitz 7853: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7854: }
7855:
1.795 www 7856: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7857: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7858: }
7859:
1.1043 raeburn 7860: a#LC_content_toolbar_edittoplevel {
7861: background-image:url(/res/adm/pages/edittoplevel.gif);
7862: }
7863:
1.795 www 7864: ul#LC_toolbar li a:hover {
1.911 bisitz 7865: background-position: bottom center;
1.757 schulted 7866: }
7867:
1.795 www 7868: ul#LC_toolbar {
1.911 bisitz 7869: padding: 0;
7870: margin: 2px;
7871: list-style:none;
7872: position:relative;
7873: background-color:white;
1.1075.2.9 raeburn 7874: overflow: auto;
1.757 schulted 7875: }
7876:
1.795 www 7877: ul#LC_toolbar li {
1.911 bisitz 7878: border:1px solid white;
7879: padding: 0;
7880: margin: 0;
7881: float: left;
7882: display:inline;
7883: vertical-align:middle;
1.1075.2.9 raeburn 7884: white-space: nowrap;
1.911 bisitz 7885: }
1.757 schulted 7886:
1.783 amueller 7887:
1.795 www 7888: a.LC_toolbarItem {
1.911 bisitz 7889: display:block;
7890: padding: 0;
7891: margin: 0;
7892: height: 32px;
7893: width: 32px;
7894: color:white;
7895: border: none;
7896: background-repeat:no-repeat;
7897: background-color:transparent;
1.757 schulted 7898: }
7899:
1.915 droeschl 7900: ul.LC_funclist {
7901: margin: 0;
7902: padding: 0.5em 1em 0.5em 0;
7903: }
7904:
1.933 droeschl 7905: ul.LC_funclist > li:first-child {
7906: font-weight:bold;
7907: margin-left:0.8em;
7908: }
7909:
1.915 droeschl 7910: ul.LC_funclist + ul.LC_funclist {
7911: /*
7912: left border as a seperator if we have more than
7913: one list
7914: */
7915: border-left: 1px solid $sidebg;
7916: /*
7917: this hides the left border behind the border of the
7918: outer box if element is wrapped to the next 'line'
7919: */
7920: margin-left: -1px;
7921: }
7922:
1.843 bisitz 7923: ul.LC_funclist li {
1.915 droeschl 7924: display: inline;
1.782 bisitz 7925: white-space: nowrap;
1.915 droeschl 7926: margin: 0 0 0 25px;
7927: line-height: 150%;
1.782 bisitz 7928: }
7929:
1.974 wenzelju 7930: .LC_hidden {
7931: display: none;
7932: }
7933:
1.1030 www 7934: .LCmodal-overlay {
7935: position:fixed;
7936: top:0;
7937: right:0;
7938: bottom:0;
7939: left:0;
7940: height:100%;
7941: width:100%;
7942: margin:0;
7943: padding:0;
7944: background:#999;
7945: opacity:.75;
7946: filter: alpha(opacity=75);
7947: -moz-opacity: 0.75;
7948: z-index:101;
7949: }
7950:
7951: * html .LCmodal-overlay {
7952: position: absolute;
7953: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7954: }
7955:
7956: .LCmodal-window {
7957: position:fixed;
7958: top:50%;
7959: left:50%;
7960: margin:0;
7961: padding:0;
7962: z-index:102;
7963: }
7964:
7965: * html .LCmodal-window {
7966: position:absolute;
7967: }
7968:
7969: .LCclose-window {
7970: position:absolute;
7971: width:32px;
7972: height:32px;
7973: right:8px;
7974: top:8px;
7975: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7976: text-indent:-99999px;
7977: overflow:hidden;
7978: cursor:pointer;
7979: }
7980:
1.1075.2.158 raeburn 7981: .LCisDisabled {
7982: cursor: not-allowed;
7983: opacity: 0.5;
7984: }
7985:
7986: a[aria-disabled="true"] {
7987: color: currentColor;
7988: display: inline-block; /* For IE11/ MS Edge bug */
7989: pointer-events: none;
7990: text-decoration: none;
7991: }
7992:
1.1075.2.141 raeburn 7993: pre.LC_wordwrap {
7994: white-space: pre-wrap;
7995: white-space: -moz-pre-wrap;
7996: white-space: -pre-wrap;
7997: white-space: -o-pre-wrap;
7998: word-wrap: break-word;
7999: }
8000:
1.1075.2.17 raeburn 8001: /*
8002: styles used by TTH when "Default set of options to pass to tth/m
8003: when converting TeX" in course settings has been set
8004:
8005: option passed: -t
8006:
8007: */
8008:
8009: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8010: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8011: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8012: td div.norm {line-height:normal;}
8013:
8014: /*
8015: option passed -y3
8016: */
8017:
8018: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8019: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8020: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8021:
1.1075.2.121 raeburn 8022: #LC_minitab_header {
8023: float:left;
8024: width:100%;
8025: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8026: font-size:93%;
8027: line-height:normal;
8028: margin: 0.5em 0 0.5em 0;
8029: }
8030: #LC_minitab_header ul {
8031: margin:0;
8032: padding:10px 10px 0;
8033: list-style:none;
8034: }
8035: #LC_minitab_header li {
8036: float:left;
8037: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8038: margin:0;
8039: padding:0 0 0 9px;
8040: }
8041: #LC_minitab_header a {
8042: display:block;
8043: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8044: padding:5px 15px 4px 6px;
8045: }
8046: #LC_minitab_header #LC_current_minitab {
8047: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8048: }
8049: #LC_minitab_header #LC_current_minitab a {
8050: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8051: padding-bottom:5px;
8052: }
8053:
8054:
1.343 albertel 8055: END
8056: }
8057:
1.306 albertel 8058: =pod
8059:
8060: =item * &headtag()
8061:
8062: Returns a uniform footer for LON-CAPA web pages.
8063:
1.307 albertel 8064: Inputs: $title - optional title for the head
8065: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8066: $args - optional arguments
1.319 albertel 8067: force_register - if is true call registerurl so the remote is
8068: informed
1.415 albertel 8069: redirect -> array ref of
8070: 1- seconds before redirect occurs
8071: 2- url to redirect to
8072: 3- whether the side effect should occur
1.315 albertel 8073: (side effect of setting
8074: $env{'internal.head.redirect'} to the url
8075: redirected too)
1.1075.2.166 raeburn 8076: 4- whether encrypt check should be skipped
1.352 albertel 8077: domain -> force to color decorate a page for a specific
8078: domain
8079: function -> force usage of a specific rolish color scheme
8080: bgcolor -> override the default page bgcolor
1.460 albertel 8081: no_auto_mt_title
8082: -> prevent &mt()ing the title arg
1.464 albertel 8083:
1.306 albertel 8084: =cut
8085:
8086: sub headtag {
1.313 albertel 8087: my ($title,$head_extra,$args) = @_;
1.306 albertel 8088:
1.363 albertel 8089: my $function = $args->{'function'} || &get_users_function();
8090: my $domain = $args->{'domain'} || &determinedomain();
8091: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 8092: my $httphost = $args->{'use_absolute'};
1.418 albertel 8093: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8094: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8095: #time(),
1.418 albertel 8096: $env{'environment.color.timestamp'},
1.363 albertel 8097: $function,$domain,$bgcolor);
8098:
1.369 www 8099: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8100:
1.308 albertel 8101: my $result =
8102: '<head>'.
1.1075.2.56 raeburn 8103: &font_settings($args);
1.319 albertel 8104:
1.1075.2.72 raeburn 8105: my $inhibitprint;
8106: if ($args->{'print_suppress'}) {
8107: $inhibitprint = &print_suppression();
8108: }
1.1064 raeburn 8109:
1.461 albertel 8110: if (!$args->{'frameset'}) {
8111: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8112: }
1.1075.2.12 raeburn 8113: if ($args->{'force_register'}) {
8114: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 8115: }
1.436 albertel 8116: if (!$args->{'no_nav_bar'}
8117: && !$args->{'only_body'}
8118: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 8119: $result .= &help_menu_js($httphost);
1.1032 www 8120: $result.=&modal_window();
1.1038 www 8121: $result.=&togglebox_script();
1.1034 www 8122: $result.=&wishlist_window();
1.1041 www 8123: $result.=&LCprogressbarUpdate_script();
1.1034 www 8124: } else {
8125: if ($args->{'add_modal'}) {
8126: $result.=&modal_window();
8127: }
8128: if ($args->{'add_wishlist'}) {
8129: $result.=&wishlist_window();
8130: }
1.1038 www 8131: if ($args->{'add_togglebox'}) {
8132: $result.=&togglebox_script();
8133: }
1.1041 www 8134: if ($args->{'add_progressbar'}) {
8135: $result.=&LCprogressbarUpdate_script();
8136: }
1.436 albertel 8137: }
1.314 albertel 8138: if (ref($args->{'redirect'})) {
1.1075.2.166 raeburn 8139: my ($time,$url,$inhibit_continue,$skip_enc_check) = @{$args->{'redirect'}};
8140: if (!$skip_enc_check) {
8141: $url = &Apache::lonenc::check_encrypt($url);
8142: }
1.414 albertel 8143: if (!$inhibit_continue) {
8144: $env{'internal.head.redirect'} = $url;
8145: }
1.313 albertel 8146: $result.=<<ADDMETA
8147: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8148: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8149: ADDMETA
1.1075.2.89 raeburn 8150: } else {
8151: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8152: my $requrl = $env{'request.uri'};
8153: if ($requrl eq '') {
8154: $requrl = $ENV{'REQUEST_URI'};
8155: $requrl =~ s/\?.+$//;
8156: }
8157: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8158: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8159: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8160: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8161: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8162: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 8163: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1075.2.151 raeburn 8164: my ($offload,$offloadoth);
1.1075.2.89 raeburn 8165: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8166: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 8167: $offload = 1;
1.1075.2.151 raeburn 8168: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8169: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8170: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8171: $offloadoth = 1;
8172: $dom_in_use = $env{'user.domain'};
8173: }
8174: }
1.1075.2.145 raeburn 8175: }
8176: }
8177: unless ($offload) {
8178: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8179: if ($domdefs{'offloadoth'}{$lonhost}) {
8180: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8181: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8182: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8183: $offload = 1;
1.1075.2.151 raeburn 8184: $offloadoth = 1;
1.1075.2.145 raeburn 8185: $dom_in_use = $env{'user.domain'};
8186: }
1.1075.2.89 raeburn 8187: }
1.1075.2.145 raeburn 8188: }
8189: }
8190: }
8191: if ($offload) {
1.1075.2.158 raeburn 8192: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1075.2.151 raeburn 8193: if (($newserver eq '') && ($offloadoth)) {
8194: my @domains = &Apache::lonnet::current_machine_domains();
8195: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
8196: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8197: }
8198: }
1.1075.2.145 raeburn 8199: if (($newserver) && ($newserver ne $lonhost)) {
8200: my $numsec = 5;
8201: my $timeout = $numsec * 1000;
8202: my ($newurl,$locknum,%locks,$msg);
8203: if ($env{'request.role.adv'}) {
8204: ($locknum,%locks) = &Apache::lonnet::get_locks();
8205: }
8206: my $disable_submit = 0;
8207: if ($requrl =~ /$LONCAPA::assess_re/) {
8208: $disable_submit = 1;
8209: }
8210: if ($locknum) {
8211: my @lockinfo = sort(values(%locks));
1.1075.2.153 raeburn 8212: $msg = &mt('Once the following tasks are complete:')." \n".
1.1075.2.145 raeburn 8213: join(", ",sort(values(%locks)))."\n";
8214: if (&show_course()) {
8215: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 8216: } else {
1.1075.2.145 raeburn 8217: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
8218: }
8219: } else {
8220: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8221: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8222: }
8223: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8224: $newurl = '/adm/switchserver?otherserver='.$newserver;
8225: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8226: $newurl .= '&role='.$env{'request.role'};
8227: }
8228: if ($env{'request.symb'}) {
8229: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8230: if ($shownsymb =~ m{^/enc/}) {
8231: my $reqdmajor = 2;
8232: my $reqdminor = 11;
8233: my $reqdsubminor = 3;
8234: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8235: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8236: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8237: if (($major eq '' && $minor eq '') ||
8238: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8239: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8240: ($reqdsubminor > $subminor))))) {
8241: undef($shownsymb);
8242: }
1.1075.2.89 raeburn 8243: }
1.1075.2.145 raeburn 8244: if ($shownsymb) {
8245: &js_escape(\$shownsymb);
8246: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 8247: }
1.1075.2.145 raeburn 8248: } else {
8249: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8250: &js_escape(\$shownurl);
8251: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 8252: }
1.1075.2.145 raeburn 8253: }
8254: &js_escape(\$msg);
8255: $result.=<<OFFLOAD
1.1075.2.89 raeburn 8256: <meta http-equiv="pragma" content="no-cache" />
8257: <script type="text/javascript">
1.1075.2.92 raeburn 8258: // <![CDATA[
1.1075.2.89 raeburn 8259: function LC_Offload_Now() {
8260: var dest = "$newurl";
8261: if (dest != '') {
8262: window.location.href="$newurl";
8263: }
8264: }
1.1075.2.92 raeburn 8265: \$(document).ready(function () {
8266: window.alert('$msg');
8267: if ($disable_submit) {
1.1075.2.89 raeburn 8268: \$(".LC_hwk_submit").prop("disabled", true);
8269: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 8270: }
8271: setTimeout('LC_Offload_Now()', $timeout);
8272: });
8273: // ]]>
1.1075.2.89 raeburn 8274: </script>
8275: OFFLOAD
8276: }
8277: }
8278: }
8279: }
8280: }
1.313 albertel 8281: }
1.306 albertel 8282: if (!defined($title)) {
8283: $title = 'The LearningOnline Network with CAPA';
8284: }
1.460 albertel 8285: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.168! raeburn 8286: if ($title =~ /^LON-CAPA\s+/) {
! 8287: $result .= '<title> '.$title.'</title>';
! 8288: } else {
! 8289: $result .= '<title> LON-CAPA '.$title.'</title>';
! 8290: }
! 8291: $result .= "\n".'<link rel="stylesheet" type="text/css" href="'.$url.'"';
1.1075.2.61 raeburn 8292: if (!$args->{'frameset'}) {
8293: $result .= ' /';
8294: }
8295: $result .= '>'
1.1064 raeburn 8296: .$inhibitprint
1.414 albertel 8297: .$head_extra;
1.1075.2.108 raeburn 8298: my $clientmobile;
8299: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8300: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8301: } else {
8302: $clientmobile = $env{'browser.mobile'};
8303: }
8304: if ($clientmobile) {
1.1075.2.42 raeburn 8305: $result .= '
8306: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8307: <meta name="apple-mobile-web-app-capable" content="yes" />';
8308: }
1.1075.2.126 raeburn 8309: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8310: return $result.'</head>';
1.306 albertel 8311: }
8312:
8313: =pod
8314:
1.340 albertel 8315: =item * &font_settings()
8316:
8317: Returns neccessary <meta> to set the proper encoding
8318:
1.1075.2.56 raeburn 8319: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8320:
8321: =cut
8322:
8323: sub font_settings {
1.1075.2.56 raeburn 8324: my ($args) = @_;
1.340 albertel 8325: my $headerstring='';
1.1075.2.56 raeburn 8326: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8327: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8328: $headerstring.=
1.1075.2.61 raeburn 8329: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8330: if (!$args->{'frameset'}) {
8331: $headerstring.= ' /';
8332: }
8333: $headerstring .= '>'."\n";
1.340 albertel 8334: }
8335: return $headerstring;
8336: }
8337:
1.341 albertel 8338: =pod
8339:
1.1064 raeburn 8340: =item * &print_suppression()
8341:
8342: In course context returns css which causes the body to be blank when media="print",
8343: if printout generation is unavailable for the current resource.
8344:
8345: This could be because:
8346:
8347: (a) printstartdate is in the future
8348:
8349: (b) printenddate is in the past
8350:
8351: (c) there is an active exam block with "printout"
8352: functionality blocked
8353:
8354: Users with pav, pfo or evb privileges are exempt.
8355:
8356: Inputs: none
8357:
8358: =cut
8359:
8360:
8361: sub print_suppression {
8362: my $noprint;
8363: if ($env{'request.course.id'}) {
8364: my $scope = $env{'request.course.id'};
8365: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8366: (&Apache::lonnet::allowed('pfo',$scope))) {
8367: return;
8368: }
8369: if ($env{'request.course.sec'} ne '') {
8370: $scope .= "/$env{'request.course.sec'}";
8371: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8372: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8373: return;
1.1064 raeburn 8374: }
8375: }
8376: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8377: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.158 raeburn 8378: my $clientip = &Apache::lonnet::get_requestor_ip();
8379: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 8380: if ($blocked) {
8381: my $checkrole = "cm./$cdom/$cnum";
8382: if ($env{'request.course.sec'} ne '') {
8383: $checkrole .= "/$env{'request.course.sec'}";
8384: }
8385: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8386: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8387: $noprint = 1;
8388: }
8389: }
8390: unless ($noprint) {
8391: my $symb = &Apache::lonnet::symbread();
8392: if ($symb ne '') {
8393: my $navmap = Apache::lonnavmaps::navmap->new();
8394: if (ref($navmap)) {
8395: my $res = $navmap->getBySymb($symb);
8396: if (ref($res)) {
8397: if (!$res->resprintable()) {
8398: $noprint = 1;
8399: }
8400: }
8401: }
8402: }
8403: }
8404: if ($noprint) {
8405: return <<"ENDSTYLE";
8406: <style type="text/css" media="print">
8407: body { display:none }
8408: </style>
8409: ENDSTYLE
8410: }
8411: }
8412: return;
8413: }
8414:
8415: =pod
8416:
1.341 albertel 8417: =item * &xml_begin()
8418:
8419: Returns the needed doctype and <html>
8420:
8421: Inputs: none
8422:
8423: =cut
8424:
8425: sub xml_begin {
1.1075.2.61 raeburn 8426: my ($is_frameset) = @_;
1.341 albertel 8427: my $output='';
8428:
8429: if ($env{'browser.mathml'}) {
8430: $output='<?xml version="1.0"?>'
8431: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8432: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8433:
8434: # .'<!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">] >'
8435: .'<!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">'
8436: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8437: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8438: } elsif ($is_frameset) {
8439: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8440: '<html>'."\n";
1.341 albertel 8441: } else {
1.1075.2.61 raeburn 8442: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8443: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8444: }
8445: return $output;
8446: }
1.340 albertel 8447:
8448: =pod
8449:
1.306 albertel 8450: =item * &start_page()
8451:
8452: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8453:
1.648 raeburn 8454: Inputs:
8455:
8456: =over 4
8457:
8458: $title - optional title for the page
8459:
8460: $head_extra - optional extra HTML to incude inside the <head>
8461:
8462: $args - additional optional args supported are:
8463:
8464: =over 8
8465:
8466: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8467: arg on
1.814 bisitz 8468: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8469: add_entries -> additional attributes to add to the <body>
8470: domain -> force to color decorate a page for a
1.317 albertel 8471: specific domain
1.648 raeburn 8472: function -> force usage of a specific rolish color
1.317 albertel 8473: scheme
1.648 raeburn 8474: redirect -> see &headtag()
8475: bgcolor -> override the default page bg color
8476: js_ready -> return a string ready for being used in
1.317 albertel 8477: a javascript writeln
1.648 raeburn 8478: html_encode -> return a string ready for being used in
1.320 albertel 8479: a html attribute
1.648 raeburn 8480: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8481: $forcereg arg
1.648 raeburn 8482: frameset -> if true will start with a <frameset>
1.330 albertel 8483: rather than <body>
1.648 raeburn 8484: skip_phases -> hash ref of
1.338 albertel 8485: head -> skip the <html><head> generation
8486: body -> skip all <body> generation
1.1075.2.12 raeburn 8487: no_inline_link -> if true and in remote mode, don't show the
8488: 'Switch To Inline Menu' link
1.648 raeburn 8489: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8490: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8491: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8492: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8493: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8494: group -> includes the current group, if page is for a
8495: specific group
1.1075.2.133 raeburn 8496: use_absolute -> for request for external resource or syllabus, this
8497: will contain https://<hostname> if server uses
8498: https (as per hosts.tab), but request is for http
8499: hostname -> hostname, originally from $r->hostname(), (optional).
1.1075.2.158 raeburn 8500: links_disabled -> Links in primary and secondary menus are disabled
8501: (Can enable them once page has loaded - see lonroles.pm
8502: for an example).
1.361 albertel 8503:
1.648 raeburn 8504: =back
1.460 albertel 8505:
1.648 raeburn 8506: =back
1.562 albertel 8507:
1.306 albertel 8508: =cut
8509:
8510: sub start_page {
1.309 albertel 8511: my ($title,$head_extra,$args) = @_;
1.318 albertel 8512: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8513:
1.315 albertel 8514: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8515: my ($result,@advtools);
1.964 droeschl 8516:
1.338 albertel 8517: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8518: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8519: }
8520:
8521: if (! exists($args->{'skip_phases'}{'body'}) ) {
8522: if ($args->{'frameset'}) {
8523: my $attr_string = &make_attr_string($args->{'force_register'},
8524: $args->{'add_entries'});
8525: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8526: } else {
8527: $result .=
8528: &bodytag($title,
8529: $args->{'function'}, $args->{'add_entries'},
8530: $args->{'only_body'}, $args->{'domain'},
8531: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8532: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8533: $args, \@advtools);
1.831 bisitz 8534: }
1.330 albertel 8535: }
1.338 albertel 8536:
1.315 albertel 8537: if ($args->{'js_ready'}) {
1.713 kaisler 8538: $result = &js_ready($result);
1.315 albertel 8539: }
1.320 albertel 8540: if ($args->{'html_encode'}) {
1.713 kaisler 8541: $result = &html_encode($result);
8542: }
8543:
1.813 bisitz 8544: # Preparation for new and consistent functionlist at top of screen
8545: # if ($args->{'functionlist'}) {
8546: # $result .= &build_functionlist();
8547: #}
8548:
1.964 droeschl 8549: # Don't add anything more if only_body wanted or in const space
8550: return $result if $args->{'only_body'}
8551: || $env{'request.state'} eq 'construct';
1.813 bisitz 8552:
8553: #Breadcrumbs
1.758 kaisler 8554: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8555: &Apache::lonhtmlcommon::clear_breadcrumbs();
8556: #if any br links exists, add them to the breadcrumbs
8557: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8558: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8559: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8560: }
8561: }
1.1075.2.19 raeburn 8562: # if @advtools array contains items add then to the breadcrumbs
8563: if (@advtools > 0) {
8564: &Apache::lonmenu::advtools_crumbs(@advtools);
8565: }
1.1075.2.123 raeburn 8566: my $menulink;
8567: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8568: if (exists($args->{'bread_crumbs_nomenu'})) {
8569: $menulink = 0;
8570: } else {
8571: undef($menulink);
8572: }
1.758 kaisler 8573: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8574: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8575: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8576: }else{
1.1075.2.123 raeburn 8577: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8578: }
1.1075.2.24 raeburn 8579: } elsif (($env{'environment.remote'} eq 'on') &&
8580: ($env{'form.inhibitmenu'} ne 'yes') &&
8581: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8582: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8583: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8584: }
1.315 albertel 8585: return $result;
1.306 albertel 8586: }
8587:
8588: sub end_page {
1.315 albertel 8589: my ($args) = @_;
8590: $env{'internal.end_page'}++;
1.330 albertel 8591: my $result;
1.335 albertel 8592: if ($args->{'discussion'}) {
8593: my ($target,$parser);
8594: if (ref($args->{'discussion'})) {
8595: ($target,$parser) =($args->{'discussion'}{'target'},
8596: $args->{'discussion'}{'parser'});
8597: }
8598: $result .= &Apache::lonxml::xmlend($target,$parser);
8599: }
1.330 albertel 8600: if ($args->{'frameset'}) {
8601: $result .= '</frameset>';
8602: } else {
1.635 raeburn 8603: $result .= &endbodytag($args);
1.330 albertel 8604: }
1.1075.2.6 raeburn 8605: unless ($args->{'notbody'}) {
8606: $result .= "\n</html>";
8607: }
1.330 albertel 8608:
1.315 albertel 8609: if ($args->{'js_ready'}) {
1.317 albertel 8610: $result = &js_ready($result);
1.315 albertel 8611: }
1.335 albertel 8612:
1.320 albertel 8613: if ($args->{'html_encode'}) {
8614: $result = &html_encode($result);
8615: }
1.335 albertel 8616:
1.315 albertel 8617: return $result;
8618: }
8619:
1.1034 www 8620: sub wishlist_window {
8621: return(<<'ENDWISHLIST');
1.1046 raeburn 8622: <script type="text/javascript">
1.1034 www 8623: // <![CDATA[
8624: // <!-- BEGIN LON-CAPA Internal
8625: function set_wishlistlink(title, path) {
8626: if (!title) {
8627: title = document.title;
8628: title = title.replace(/^LON-CAPA /,'');
8629: }
1.1075.2.65 raeburn 8630: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8631: title = title.replace("'","\\\'");
1.1034 www 8632: if (!path) {
8633: path = location.pathname;
8634: }
1.1075.2.65 raeburn 8635: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8636: path = path.replace("'","\\\'");
1.1034 www 8637: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8638: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8639: }
8640: // END LON-CAPA Internal -->
8641: // ]]>
8642: </script>
8643: ENDWISHLIST
8644: }
8645:
1.1030 www 8646: sub modal_window {
8647: return(<<'ENDMODAL');
1.1046 raeburn 8648: <script type="text/javascript">
1.1030 www 8649: // <![CDATA[
8650: // <!-- BEGIN LON-CAPA Internal
8651: var modalWindow = {
8652: parent:"body",
8653: windowId:null,
8654: content:null,
8655: width:null,
8656: height:null,
8657: close:function()
8658: {
8659: $(".LCmodal-window").remove();
8660: $(".LCmodal-overlay").remove();
8661: },
8662: open:function()
8663: {
8664: var modal = "";
8665: modal += "<div class=\"LCmodal-overlay\"></div>";
8666: 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;\">";
8667: modal += this.content;
8668: modal += "</div>";
8669:
8670: $(this.parent).append(modal);
8671:
8672: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8673: $(".LCclose-window").click(function(){modalWindow.close();});
8674: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8675: }
8676: };
1.1075.2.42 raeburn 8677: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8678: {
1.1075.2.119 raeburn 8679: source = source.replace(/'/g,"'");
1.1030 www 8680: modalWindow.windowId = "myModal";
8681: modalWindow.width = width;
8682: modalWindow.height = height;
1.1075.2.80 raeburn 8683: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8684: modalWindow.open();
1.1075.2.87 raeburn 8685: };
1.1030 www 8686: // END LON-CAPA Internal -->
8687: // ]]>
8688: </script>
8689: ENDMODAL
8690: }
8691:
8692: sub modal_link {
1.1075.2.42 raeburn 8693: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8694: unless ($width) { $width=480; }
8695: unless ($height) { $height=400; }
1.1031 www 8696: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8697: unless ($transparency) { $transparency='true'; }
8698:
1.1074 raeburn 8699: my $target_attr;
8700: if (defined($target)) {
8701: $target_attr = 'target="'.$target.'"';
8702: }
8703: return <<"ENDLINK";
1.1075.2.143 raeburn 8704: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 8705: ENDLINK
1.1030 www 8706: }
8707:
1.1032 www 8708: sub modal_adhoc_script {
1.1075.2.155 raeburn 8709: my ($funcname,$width,$height,$content,$possmathjax)=@_;
8710: my $mathjax;
8711: if ($possmathjax) {
8712: $mathjax = <<'ENDJAX';
8713: if (typeof MathJax == 'object') {
8714: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
8715: }
8716: ENDJAX
8717: }
1.1032 www 8718: return (<<ENDADHOC);
1.1046 raeburn 8719: <script type="text/javascript">
1.1032 www 8720: // <![CDATA[
8721: var $funcname = function()
8722: {
8723: modalWindow.windowId = "myModal";
8724: modalWindow.width = $width;
8725: modalWindow.height = $height;
8726: modalWindow.content = '$content';
8727: modalWindow.open();
1.1075.2.155 raeburn 8728: $mathjax
1.1032 www 8729: };
8730: // ]]>
8731: </script>
8732: ENDADHOC
8733: }
8734:
1.1041 www 8735: sub modal_adhoc_inner {
1.1075.2.155 raeburn 8736: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 8737: my $innerwidth=$width-20;
8738: $content=&js_ready(
1.1042 www 8739: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8740: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8741: $content.
1.1041 www 8742: &end_scrollbox().
1.1075.2.42 raeburn 8743: &end_page()
1.1041 www 8744: );
1.1075.2.155 raeburn 8745: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 8746: }
8747:
8748: sub modal_adhoc_window {
1.1075.2.155 raeburn 8749: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
8750: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 8751: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8752: }
8753:
8754: sub modal_adhoc_launch {
8755: my ($funcname,$width,$height,$content)=@_;
8756: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8757: <script type="text/javascript">
8758: // <![CDATA[
8759: $funcname();
8760: // ]]>
8761: </script>
8762: ENDLAUNCH
8763: }
8764:
8765: sub modal_adhoc_close {
8766: return (<<ENDCLOSE);
8767: <script type="text/javascript">
8768: // <![CDATA[
8769: modalWindow.close();
8770: // ]]>
8771: </script>
8772: ENDCLOSE
8773: }
8774:
1.1038 www 8775: sub togglebox_script {
8776: return(<<ENDTOGGLE);
8777: <script type="text/javascript">
8778: // <![CDATA[
8779: function LCtoggleDisplay(id,hidetext,showtext) {
8780: link = document.getElementById(id + "link").childNodes[0];
8781: with (document.getElementById(id).style) {
8782: if (display == "none" ) {
8783: display = "inline";
8784: link.nodeValue = hidetext;
8785: } else {
8786: display = "none";
8787: link.nodeValue = showtext;
8788: }
8789: }
8790: }
8791: // ]]>
8792: </script>
8793: ENDTOGGLE
8794: }
8795:
1.1039 www 8796: sub start_togglebox {
8797: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8798: unless ($heading) { $heading=''; } else { $heading.=' '; }
8799: unless ($showtext) { $showtext=&mt('show'); }
8800: unless ($hidetext) { $hidetext=&mt('hide'); }
8801: unless ($headerbg) { $headerbg='#FFFFFF'; }
8802: return &start_data_table().
8803: &start_data_table_header_row().
8804: '<td bgcolor="'.$headerbg.'">'.$heading.
8805: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8806: $showtext.'\')">'.$showtext.'</a>]</td>'.
8807: &end_data_table_header_row().
8808: '<tr id="'.$id.'" style="display:none""><td>';
8809: }
8810:
8811: sub end_togglebox {
8812: return '</td></tr>'.&end_data_table();
8813: }
8814:
1.1041 www 8815: sub LCprogressbar_script {
1.1075.2.130 raeburn 8816: my ($id,$number_to_do)=@_;
8817: if ($number_to_do) {
8818: return(<<ENDPROGRESS);
1.1041 www 8819: <script type="text/javascript">
8820: // <![CDATA[
1.1045 www 8821: \$('#progressbar$id').progressbar({
1.1041 www 8822: value: 0,
8823: change: function(event, ui) {
8824: var newVal = \$(this).progressbar('option', 'value');
8825: \$('.pblabel', this).text(LCprogressTxt);
8826: }
8827: });
8828: // ]]>
8829: </script>
8830: ENDPROGRESS
1.1075.2.130 raeburn 8831: } else {
8832: return(<<ENDPROGRESS);
8833: <script type="text/javascript">
8834: // <![CDATA[
8835: \$('#progressbar$id').progressbar({
8836: value: false,
8837: create: function(event, ui) {
8838: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8839: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8840: }
8841: });
8842: // ]]>
8843: </script>
8844: ENDPROGRESS
8845: }
1.1041 www 8846: }
8847:
8848: sub LCprogressbarUpdate_script {
8849: return(<<ENDPROGRESSUPDATE);
8850: <style type="text/css">
8851: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8852: .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 8853: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8854: </style>
8855: <script type="text/javascript">
8856: // <![CDATA[
1.1045 www 8857: var LCprogressTxt='---';
8858:
1.1075.2.130 raeburn 8859: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8860: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8861: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8862: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8863: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8864: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8865: } else {
8866: \$('#progressbar'+id).progressbar('value',percent);
8867: }
1.1041 www 8868: }
8869: // ]]>
8870: </script>
8871: ENDPROGRESSUPDATE
8872: }
8873:
1.1042 www 8874: my $LClastpercent;
1.1045 www 8875: my $LCidcnt;
8876: my $LCcurrentid;
1.1042 www 8877:
1.1041 www 8878: sub LCprogressbar {
1.1075.2.130 raeburn 8879: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8880: $LClastpercent=0;
1.1045 www 8881: $LCidcnt++;
8882: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8883: my ($starting,$content);
8884: if ($number_to_do) {
8885: $starting=&mt('Starting');
8886: $content=(<<ENDPROGBAR);
8887: $preamble
1.1045 www 8888: <div id="progressbar$LCcurrentid">
1.1041 www 8889: <span class="pblabel">$starting</span>
8890: </div>
8891: ENDPROGBAR
1.1075.2.130 raeburn 8892: } else {
8893: $starting=&mt('Loading...');
8894: $LClastpercent='false';
8895: $content=(<<ENDPROGBAR);
8896: $preamble
8897: <div id="progressbar$LCcurrentid">
8898: <div class="progress-label">$starting</div>
8899: </div>
8900: ENDPROGBAR
8901: }
8902: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8903: }
8904:
8905: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8906: my ($r,$val,$text,$number_to_do)=@_;
8907: if ($number_to_do) {
8908: unless ($val) {
8909: if ($LClastpercent) {
8910: $val=$LClastpercent;
8911: } else {
8912: $val=0;
8913: }
8914: }
8915: if ($val<0) { $val=0; }
8916: if ($val>100) { $val=0; }
8917: $LClastpercent=$val;
8918: unless ($text) { $text=$val.'%'; }
8919: } else {
8920: $val = 'false';
1.1042 www 8921: }
1.1041 www 8922: $text=&js_ready($text);
1.1044 www 8923: &r_print($r,<<ENDUPDATE);
1.1041 www 8924: <script type="text/javascript">
8925: // <![CDATA[
1.1075.2.130 raeburn 8926: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8927: // ]]>
8928: </script>
8929: ENDUPDATE
1.1035 www 8930: }
8931:
1.1042 www 8932: sub LCprogressbarClose {
8933: my ($r)=@_;
8934: $LClastpercent=0;
1.1044 www 8935: &r_print($r,<<ENDCLOSE);
1.1042 www 8936: <script type="text/javascript">
8937: // <![CDATA[
1.1045 www 8938: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8939: // ]]>
8940: </script>
8941: ENDCLOSE
1.1044 www 8942: }
8943:
8944: sub r_print {
8945: my ($r,$to_print)=@_;
8946: if ($r) {
8947: $r->print($to_print);
8948: $r->rflush();
8949: } else {
8950: print($to_print);
8951: }
1.1042 www 8952: }
8953:
1.320 albertel 8954: sub html_encode {
8955: my ($result) = @_;
8956:
1.322 albertel 8957: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8958:
8959: return $result;
8960: }
1.1044 www 8961:
1.317 albertel 8962: sub js_ready {
8963: my ($result) = @_;
8964:
1.323 albertel 8965: $result =~ s/[\n\r]/ /xmsg;
8966: $result =~ s/\\/\\\\/xmsg;
8967: $result =~ s/'/\\'/xmsg;
1.372 albertel 8968: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8969:
8970: return $result;
8971: }
8972:
1.315 albertel 8973: sub validate_page {
8974: if ( exists($env{'internal.start_page'})
1.316 albertel 8975: && $env{'internal.start_page'} > 1) {
8976: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8977: $env{'internal.start_page'}.' '.
1.316 albertel 8978: $ENV{'request.filename'});
1.315 albertel 8979: }
8980: if ( exists($env{'internal.end_page'})
1.316 albertel 8981: && $env{'internal.end_page'} > 1) {
8982: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8983: $env{'internal.end_page'}.' '.
1.316 albertel 8984: $env{'request.filename'});
1.315 albertel 8985: }
8986: if ( exists($env{'internal.start_page'})
8987: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8988: &Apache::lonnet::logthis('start_page called without end_page '.
8989: $env{'request.filename'});
1.315 albertel 8990: }
8991: if ( ! exists($env{'internal.start_page'})
8992: && exists($env{'internal.end_page'})) {
1.316 albertel 8993: &Apache::lonnet::logthis('end_page called without start_page'.
8994: $env{'request.filename'});
1.315 albertel 8995: }
1.306 albertel 8996: }
1.315 albertel 8997:
1.996 www 8998:
8999: sub start_scrollbox {
1.1075.2.56 raeburn 9000: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9001: unless ($outerwidth) { $outerwidth='520px'; }
9002: unless ($width) { $width='500px'; }
9003: unless ($height) { $height='200px'; }
1.1075 raeburn 9004: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9005: if ($id ne '') {
1.1075.2.42 raeburn 9006: $table_id = ' id="table_'.$id.'"';
9007: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9008: }
1.1075 raeburn 9009: if ($bgcolor ne '') {
9010: $tdcol = "background-color: $bgcolor;";
9011: }
1.1075.2.42 raeburn 9012: my $nicescroll_js;
9013: if ($env{'browser.mobile'}) {
9014: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9015: }
1.1075 raeburn 9016: return <<"END";
1.1075.2.42 raeburn 9017: $nicescroll_js
9018:
9019: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 9020: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 9021: END
1.996 www 9022: }
9023:
9024: sub end_scrollbox {
1.1036 www 9025: return '</div></td></tr></table>';
1.996 www 9026: }
9027:
1.1075.2.42 raeburn 9028: sub nicescroll_javascript {
9029: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9030: my %options;
9031: if (ref($cursor) eq 'HASH') {
9032: %options = %{$cursor};
9033: }
9034: unless ($options{'railalign'} =~ /^left|right$/) {
9035: $options{'railalign'} = 'left';
9036: }
9037: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9038: my $function = &get_users_function();
9039: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
9040: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9041: $options{'cursorcolor'} = '#00F';
9042: }
9043: }
9044: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9045: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
9046: $options{'cursoropacity'}='1.0';
9047: }
9048: } else {
9049: $options{'cursoropacity'}='1.0';
9050: }
9051: if ($options{'cursorfixedheight'} eq 'none') {
9052: delete($options{'cursorfixedheight'});
9053: } else {
9054: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9055: }
9056: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9057: delete($options{'railoffset'});
9058: }
9059: my @niceoptions;
9060: while (my($key,$value) = each(%options)) {
9061: if ($value =~ /^\{.+\}$/) {
9062: push(@niceoptions,$key.':'.$value);
9063: } else {
9064: push(@niceoptions,$key.':"'.$value.'"');
9065: }
9066: }
9067: my $nicescroll_js = '
9068: $(document).ready(
9069: function() {
9070: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9071: }
9072: );
9073: ';
9074: if ($framecheck) {
9075: $nicescroll_js .= '
9076: function expand_div(caller) {
9077: if (top === self) {
9078: document.getElementById("'.$id.'").style.width = "auto";
9079: document.getElementById("'.$id.'").style.height = "auto";
9080: } else {
9081: try {
9082: if (parent.frames) {
9083: if (parent.frames.length > 1) {
9084: var framesrc = parent.frames[1].location.href;
9085: var currsrc = framesrc.replace(/\#.*$/,"");
9086: if ((caller == "search") || (currsrc == "'.$location.'")) {
9087: document.getElementById("'.$id.'").style.width = "auto";
9088: document.getElementById("'.$id.'").style.height = "auto";
9089: }
9090: }
9091: }
9092: } catch (e) {
9093: return;
9094: }
9095: }
9096: return;
9097: }
9098: ';
9099: }
9100: if ($needjsready) {
9101: $nicescroll_js = '
9102: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9103: } else {
9104: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9105: }
9106: return $nicescroll_js;
9107: }
9108:
1.318 albertel 9109: sub simple_error_page {
1.1075.2.49 raeburn 9110: my ($r,$title,$msg,$args) = @_;
9111: if (ref($args) eq 'HASH') {
9112: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9113: } else {
9114: $msg = &mt($msg);
9115: }
9116:
1.318 albertel 9117: my $page =
9118: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 9119: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9120: &Apache::loncommon::end_page();
9121: if (ref($r)) {
9122: $r->print($page);
1.327 albertel 9123: return;
1.318 albertel 9124: }
9125: return $page;
9126: }
1.347 albertel 9127:
9128: {
1.610 albertel 9129: my @row_count;
1.961 onken 9130:
9131: sub start_data_table_count {
9132: unshift(@row_count, 0);
9133: return;
9134: }
9135:
9136: sub end_data_table_count {
9137: shift(@row_count);
9138: return;
9139: }
9140:
1.347 albertel 9141: sub start_data_table {
1.1018 raeburn 9142: my ($add_class,$id) = @_;
1.422 albertel 9143: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9144: my $table_id;
9145: if (defined($id)) {
9146: $table_id = ' id="'.$id.'"';
9147: }
1.961 onken 9148: &start_data_table_count();
1.1018 raeburn 9149: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9150: }
9151:
9152: sub end_data_table {
1.961 onken 9153: &end_data_table_count();
1.389 albertel 9154: return '</table>'."\n";;
1.347 albertel 9155: }
9156:
9157: sub start_data_table_row {
1.974 wenzelju 9158: my ($add_class, $id) = @_;
1.610 albertel 9159: $row_count[0]++;
9160: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9161: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9162: $id = (' id="'.$id.'"') unless ($id eq '');
9163: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9164: }
1.471 banghart 9165:
9166: sub continue_data_table_row {
1.974 wenzelju 9167: my ($add_class, $id) = @_;
1.610 albertel 9168: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9169: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9170: $id = (' id="'.$id.'"') unless ($id eq '');
9171: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9172: }
1.347 albertel 9173:
9174: sub end_data_table_row {
1.389 albertel 9175: return '</tr>'."\n";;
1.347 albertel 9176: }
1.367 www 9177:
1.421 albertel 9178: sub start_data_table_empty_row {
1.707 bisitz 9179: # $row_count[0]++;
1.421 albertel 9180: return '<tr class="LC_empty_row" >'."\n";;
9181: }
9182:
9183: sub end_data_table_empty_row {
9184: return '</tr>'."\n";;
9185: }
9186:
1.367 www 9187: sub start_data_table_header_row {
1.389 albertel 9188: return '<tr class="LC_header_row">'."\n";;
1.367 www 9189: }
9190:
9191: sub end_data_table_header_row {
1.389 albertel 9192: return '</tr>'."\n";;
1.367 www 9193: }
1.890 droeschl 9194:
9195: sub data_table_caption {
9196: my $caption = shift;
9197: return "<caption class=\"LC_caption\">$caption</caption>";
9198: }
1.347 albertel 9199: }
9200:
1.548 albertel 9201: =pod
9202:
9203: =item * &inhibit_menu_check($arg)
9204:
9205: Checks for a inhibitmenu state and generates output to preserve it
9206:
9207: Inputs: $arg - can be any of
9208: - undef - in which case the return value is a string
9209: to add into arguments list of a uri
9210: - 'input' - in which case the return value is a HTML
9211: <form> <input> field of type hidden to
9212: preserve the value
9213: - a url - in which case the return value is the url with
9214: the neccesary cgi args added to preserve the
9215: inhibitmenu state
9216: - a ref to a url - no return value, but the string is
9217: updated to include the neccessary cgi
9218: args to preserve the inhibitmenu state
9219:
9220: =cut
9221:
9222: sub inhibit_menu_check {
9223: my ($arg) = @_;
9224: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9225: if ($arg eq 'input') {
9226: if ($env{'form.inhibitmenu'}) {
9227: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9228: } else {
9229: return
9230: }
9231: }
9232: if ($env{'form.inhibitmenu'}) {
9233: if (ref($arg)) {
9234: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9235: } elsif ($arg eq '') {
9236: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9237: } else {
9238: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9239: }
9240: }
9241: if (!ref($arg)) {
9242: return $arg;
9243: }
9244: }
9245:
1.251 albertel 9246: ###############################################
1.182 matthew 9247:
9248: =pod
9249:
1.549 albertel 9250: =back
9251:
9252: =head1 User Information Routines
9253:
9254: =over 4
9255:
1.405 albertel 9256: =item * &get_users_function()
1.182 matthew 9257:
9258: Used by &bodytag to determine the current users primary role.
9259: Returns either 'student','coordinator','admin', or 'author'.
9260:
9261: =cut
9262:
9263: ###############################################
9264: sub get_users_function {
1.815 tempelho 9265: my $function = 'norole';
1.818 tempelho 9266: if ($env{'request.role'}=~/^(st)/) {
9267: $function='student';
9268: }
1.907 raeburn 9269: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9270: $function='coordinator';
9271: }
1.258 albertel 9272: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9273: $function='admin';
9274: }
1.826 bisitz 9275: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9276: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9277: $function='author';
9278: }
9279: return $function;
1.54 www 9280: }
1.99 www 9281:
9282: ###############################################
9283:
1.233 raeburn 9284: =pod
9285:
1.821 raeburn 9286: =item * &show_course()
9287:
9288: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9289: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9290:
9291: Inputs:
9292: None
9293:
9294: Outputs:
9295: Scalar: 1 if 'Course' to be used, 0 otherwise.
9296:
9297: =cut
9298:
9299: ###############################################
9300: sub show_course {
9301: my $course = !$env{'user.adv'};
9302: if (!$env{'user.adv'}) {
9303: foreach my $env (keys(%env)) {
9304: next if ($env !~ m/^user\.priv\./);
9305: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9306: $course = 0;
9307: last;
9308: }
9309: }
9310: }
9311: return $course;
9312: }
9313:
9314: ###############################################
9315:
9316: =pod
9317:
1.542 raeburn 9318: =item * &check_user_status()
1.274 raeburn 9319:
9320: Determines current status of supplied role for a
9321: specific user. Roles can be active, previous or future.
9322:
9323: Inputs:
9324: user's domain, user's username, course's domain,
1.375 raeburn 9325: course's number, optional section ID.
1.274 raeburn 9326:
9327: Outputs:
9328: role status: active, previous or future.
9329:
9330: =cut
9331:
9332: sub check_user_status {
1.412 raeburn 9333: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9334: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9335: my @uroles = keys(%userinfo);
1.274 raeburn 9336: my $srchstr;
9337: my $active_chk = 'none';
1.412 raeburn 9338: my $now = time;
1.274 raeburn 9339: if (@uroles > 0) {
1.908 raeburn 9340: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9341: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9342: } else {
1.412 raeburn 9343: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9344: }
9345: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9346: my $role_end = 0;
9347: my $role_start = 0;
9348: $active_chk = 'active';
1.412 raeburn 9349: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9350: $role_end = $1;
9351: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9352: $role_start = $1;
1.274 raeburn 9353: }
9354: }
9355: if ($role_start > 0) {
1.412 raeburn 9356: if ($now < $role_start) {
1.274 raeburn 9357: $active_chk = 'future';
9358: }
9359: }
9360: if ($role_end > 0) {
1.412 raeburn 9361: if ($now > $role_end) {
1.274 raeburn 9362: $active_chk = 'previous';
9363: }
9364: }
9365: }
9366: }
9367: return $active_chk;
9368: }
9369:
9370: ###############################################
9371:
9372: =pod
9373:
1.405 albertel 9374: =item * &get_sections()
1.233 raeburn 9375:
9376: Determines all the sections for a course including
9377: sections with students and sections containing other roles.
1.419 raeburn 9378: Incoming parameters:
9379:
9380: 1. domain
9381: 2. course number
9382: 3. reference to array containing roles for which sections should
9383: be gathered (optional).
9384: 4. reference to array containing status types for which sections
9385: should be gathered (optional).
9386:
9387: If the third argument is undefined, sections are gathered for any role.
9388: If the fourth argument is undefined, sections are gathered for any status.
9389: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9390:
1.374 raeburn 9391: Returns section hash (keys are section IDs, values are
9392: number of users in each section), subject to the
1.419 raeburn 9393: optional roles filter, optional status filter
1.233 raeburn 9394:
9395: =cut
9396:
9397: ###############################################
9398: sub get_sections {
1.419 raeburn 9399: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9400: if (!defined($cdom) || !defined($cnum)) {
9401: my $cid = $env{'request.course.id'};
9402:
9403: return if (!defined($cid));
9404:
9405: $cdom = $env{'course.'.$cid.'.domain'};
9406: $cnum = $env{'course.'.$cid.'.num'};
9407: }
9408:
9409: my %sectioncount;
1.419 raeburn 9410: my $now = time;
1.240 albertel 9411:
1.1075.2.33 raeburn 9412: my $check_students = 1;
9413: my $only_students = 0;
9414: if (ref($possible_roles) eq 'ARRAY') {
9415: if (grep(/^st$/,@{$possible_roles})) {
9416: if (@{$possible_roles} == 1) {
9417: $only_students = 1;
9418: }
9419: } else {
9420: $check_students = 0;
9421: }
9422: }
9423:
9424: if ($check_students) {
1.276 albertel 9425: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9426: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9427: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9428: my $start_index = &Apache::loncoursedata::CL_START();
9429: my $end_index = &Apache::loncoursedata::CL_END();
9430: my $status;
1.366 albertel 9431: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9432: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9433: $data->[$status_index],
9434: $data->[$start_index],
9435: $data->[$end_index]);
9436: if ($stu_status eq 'Active') {
9437: $status = 'active';
9438: } elsif ($end < $now) {
9439: $status = 'previous';
9440: } elsif ($start > $now) {
9441: $status = 'future';
9442: }
9443: if ($section ne '-1' && $section !~ /^\s*$/) {
9444: if ((!defined($possible_status)) || (($status ne '') &&
9445: (grep/^\Q$status\E$/,@{$possible_status}))) {
9446: $sectioncount{$section}++;
9447: }
1.240 albertel 9448: }
9449: }
9450: }
1.1075.2.33 raeburn 9451: if ($only_students) {
9452: return %sectioncount;
9453: }
1.240 albertel 9454: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9455: foreach my $user (sort(keys(%courseroles))) {
9456: if ($user !~ /^(\w{2})/) { next; }
9457: my ($role) = ($user =~ /^(\w{2})/);
9458: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9459: my ($section,$status);
1.240 albertel 9460: if ($role eq 'cr' &&
9461: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9462: $section=$1;
9463: }
9464: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9465: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9466: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9467: if ($end == -1 && $start == -1) {
9468: next; #deleted role
9469: }
9470: if (!defined($possible_status)) {
9471: $sectioncount{$section}++;
9472: } else {
9473: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9474: $status = 'active';
9475: } elsif ($end < $now) {
9476: $status = 'future';
9477: } elsif ($start > $now) {
9478: $status = 'previous';
9479: }
9480: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9481: $sectioncount{$section}++;
9482: }
9483: }
1.233 raeburn 9484: }
1.366 albertel 9485: return %sectioncount;
1.233 raeburn 9486: }
9487:
1.274 raeburn 9488: ###############################################
1.294 raeburn 9489:
9490: =pod
1.405 albertel 9491:
9492: =item * &get_course_users()
9493:
1.275 raeburn 9494: Retrieves usernames:domains for users in the specified course
9495: with specific role(s), and access status.
9496:
9497: Incoming parameters:
1.277 albertel 9498: 1. course domain
9499: 2. course number
9500: 3. access status: users must have - either active,
1.275 raeburn 9501: previous, future, or all.
1.277 albertel 9502: 4. reference to array of permissible roles
1.288 raeburn 9503: 5. reference to array of section restrictions (optional)
9504: 6. reference to results object (hash of hashes).
9505: 7. reference to optional userdata hash
1.609 raeburn 9506: 8. reference to optional statushash
1.630 raeburn 9507: 9. flag if privileged users (except those set to unhide in
9508: course settings) should be excluded
1.609 raeburn 9509: Keys of top level results hash are roles.
1.275 raeburn 9510: Keys of inner hashes are username:domain, with
9511: values set to access type.
1.288 raeburn 9512: Optional userdata hash returns an array with arguments in the
9513: same order as loncoursedata::get_classlist() for student data.
9514:
1.609 raeburn 9515: Optional statushash returns
9516:
1.288 raeburn 9517: Entries for end, start, section and status are blank because
9518: of the possibility of multiple values for non-student roles.
9519:
1.275 raeburn 9520: =cut
1.405 albertel 9521:
1.275 raeburn 9522: ###############################################
1.405 albertel 9523:
1.275 raeburn 9524: sub get_course_users {
1.630 raeburn 9525: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9526: my %idx = ();
1.419 raeburn 9527: my %seclists;
1.288 raeburn 9528:
9529: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9530: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9531: $idx{end} = &Apache::loncoursedata::CL_END();
9532: $idx{start} = &Apache::loncoursedata::CL_START();
9533: $idx{id} = &Apache::loncoursedata::CL_ID();
9534: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9535: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9536: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9537:
1.290 albertel 9538: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9539: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9540: my $now = time;
1.277 albertel 9541: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9542: my $match = 0;
1.412 raeburn 9543: my $secmatch = 0;
1.419 raeburn 9544: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9545: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9546: if ($section eq '') {
9547: $section = 'none';
9548: }
1.291 albertel 9549: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9550: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9551: $secmatch = 1;
9552: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9553: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9554: $secmatch = 1;
9555: }
9556: } else {
1.419 raeburn 9557: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9558: $secmatch = 1;
9559: }
1.290 albertel 9560: }
1.412 raeburn 9561: if (!$secmatch) {
9562: next;
9563: }
1.419 raeburn 9564: }
1.275 raeburn 9565: if (defined($$types{'active'})) {
1.288 raeburn 9566: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9567: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9568: $match = 1;
1.275 raeburn 9569: }
9570: }
9571: if (defined($$types{'previous'})) {
1.609 raeburn 9572: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9573: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9574: $match = 1;
1.275 raeburn 9575: }
9576: }
9577: if (defined($$types{'future'})) {
1.609 raeburn 9578: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9579: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9580: $match = 1;
1.275 raeburn 9581: }
9582: }
1.609 raeburn 9583: if ($match) {
9584: push(@{$seclists{$student}},$section);
9585: if (ref($userdata) eq 'HASH') {
9586: $$userdata{$student} = $$classlist{$student};
9587: }
9588: if (ref($statushash) eq 'HASH') {
9589: $statushash->{$student}{'st'}{$section} = $status;
9590: }
1.288 raeburn 9591: }
1.275 raeburn 9592: }
9593: }
1.412 raeburn 9594: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9595: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9596: my $now = time;
1.609 raeburn 9597: my %displaystatus = ( previous => 'Expired',
9598: active => 'Active',
9599: future => 'Future',
9600: );
1.1075.2.36 raeburn 9601: my (%nothide,@possdoms);
1.630 raeburn 9602: if ($hidepriv) {
9603: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9604: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9605: if ($user !~ /:/) {
9606: $nothide{join(':',split(/[\@]/,$user))}=1;
9607: } else {
9608: $nothide{$user} = 1;
9609: }
9610: }
1.1075.2.36 raeburn 9611: my @possdoms = ($cdom);
9612: if ($coursehash{'checkforpriv'}) {
9613: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9614: }
1.630 raeburn 9615: }
1.439 raeburn 9616: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9617: my $match = 0;
1.412 raeburn 9618: my $secmatch = 0;
1.439 raeburn 9619: my $status;
1.412 raeburn 9620: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9621: $user =~ s/:$//;
1.439 raeburn 9622: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9623: if ($end == -1 || $start == -1) {
9624: next;
9625: }
9626: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9627: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9628: my ($uname,$udom) = split(/:/,$user);
9629: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9630: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9631: $secmatch = 1;
9632: } elsif ($usec eq '') {
1.420 albertel 9633: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9634: $secmatch = 1;
9635: }
9636: } else {
9637: if (grep(/^\Q$usec\E$/,@{$sections})) {
9638: $secmatch = 1;
9639: }
9640: }
9641: if (!$secmatch) {
9642: next;
9643: }
1.288 raeburn 9644: }
1.419 raeburn 9645: if ($usec eq '') {
9646: $usec = 'none';
9647: }
1.275 raeburn 9648: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9649: if ($hidepriv) {
1.1075.2.36 raeburn 9650: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9651: (!$nothide{$uname.':'.$udom})) {
9652: next;
9653: }
9654: }
1.503 raeburn 9655: if ($end > 0 && $end < $now) {
1.439 raeburn 9656: $status = 'previous';
9657: } elsif ($start > $now) {
9658: $status = 'future';
9659: } else {
9660: $status = 'active';
9661: }
1.277 albertel 9662: foreach my $type (keys(%{$types})) {
1.275 raeburn 9663: if ($status eq $type) {
1.420 albertel 9664: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9665: push(@{$$users{$role}{$user}},$type);
9666: }
1.288 raeburn 9667: $match = 1;
9668: }
9669: }
1.419 raeburn 9670: if (($match) && (ref($userdata) eq 'HASH')) {
9671: if (!exists($$userdata{$uname.':'.$udom})) {
9672: &get_user_info($udom,$uname,\%idx,$userdata);
9673: }
1.420 albertel 9674: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9675: push(@{$seclists{$uname.':'.$udom}},$usec);
9676: }
1.609 raeburn 9677: if (ref($statushash) eq 'HASH') {
9678: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9679: }
1.275 raeburn 9680: }
9681: }
9682: }
9683: }
1.290 albertel 9684: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9685: if ((defined($cdom)) && (defined($cnum))) {
9686: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9687: if ( defined($csettings{'internal.courseowner'}) ) {
9688: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9689: next if ($owner eq '');
9690: my ($ownername,$ownerdom);
9691: if ($owner =~ /^([^:]+):([^:]+)$/) {
9692: $ownername = $1;
9693: $ownerdom = $2;
9694: } else {
9695: $ownername = $owner;
9696: $ownerdom = $cdom;
9697: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9698: }
9699: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9700: if (defined($userdata) &&
1.609 raeburn 9701: !exists($$userdata{$owner})) {
9702: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9703: if (!grep(/^none$/,@{$seclists{$owner}})) {
9704: push(@{$seclists{$owner}},'none');
9705: }
9706: if (ref($statushash) eq 'HASH') {
9707: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9708: }
1.290 albertel 9709: }
1.279 raeburn 9710: }
9711: }
9712: }
1.419 raeburn 9713: foreach my $user (keys(%seclists)) {
9714: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9715: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9716: }
1.275 raeburn 9717: }
9718: return;
9719: }
9720:
1.288 raeburn 9721: sub get_user_info {
9722: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9723: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9724: &plainname($uname,$udom,'lastname');
1.291 albertel 9725: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9726: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9727: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9728: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9729: return;
9730: }
1.275 raeburn 9731:
1.472 raeburn 9732: ###############################################
9733:
9734: =pod
9735:
9736: =item * &get_user_quota()
9737:
1.1075.2.41 raeburn 9738: Retrieves quota assigned for storage of user files.
9739: Default is to report quota for portfolio files.
1.472 raeburn 9740:
9741: Incoming parameters:
9742: 1. user's username
9743: 2. user's domain
1.1075.2.41 raeburn 9744: 3. quota name - portfolio, author, or course
9745: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9746: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9747: course
1.472 raeburn 9748:
9749: Returns:
1.1075.2.58 raeburn 9750: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9751: 2. (Optional) Type of setting: custom or default
9752: (individually assigned or default for user's
9753: institutional status).
9754: 3. (Optional) - User's institutional status (e.g., faculty, staff
9755: or student - types as defined in localenroll::inst_usertypes
9756: for user's domain, which determines default quota for user.
9757: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9758:
9759: If a value has been stored in the user's environment,
1.536 raeburn 9760: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9761: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9762:
9763: =cut
9764:
9765: ###############################################
9766:
9767:
9768: sub get_user_quota {
1.1075.2.42 raeburn 9769: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9770: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9771: if (!defined($udom)) {
9772: $udom = $env{'user.domain'};
9773: }
9774: if (!defined($uname)) {
9775: $uname = $env{'user.name'};
9776: }
9777: if (($udom eq '' || $uname eq '') ||
9778: ($udom eq 'public') && ($uname eq 'public')) {
9779: $quota = 0;
1.536 raeburn 9780: $quotatype = 'default';
9781: $defquota = 0;
1.472 raeburn 9782: } else {
1.536 raeburn 9783: my $inststatus;
1.1075.2.41 raeburn 9784: if ($quotaname eq 'course') {
9785: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9786: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9787: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9788: } else {
9789: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9790: $quota = $cenv{'internal.uploadquota'};
9791: }
1.536 raeburn 9792: } else {
1.1075.2.41 raeburn 9793: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9794: if ($quotaname eq 'author') {
9795: $quota = $env{'environment.authorquota'};
9796: } else {
9797: $quota = $env{'environment.portfolioquota'};
9798: }
9799: $inststatus = $env{'environment.inststatus'};
9800: } else {
9801: my %userenv =
9802: &Apache::lonnet::get('environment',['portfolioquota',
9803: 'authorquota','inststatus'],$udom,$uname);
9804: my ($tmp) = keys(%userenv);
9805: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9806: if ($quotaname eq 'author') {
9807: $quota = $userenv{'authorquota'};
9808: } else {
9809: $quota = $userenv{'portfolioquota'};
9810: }
9811: $inststatus = $userenv{'inststatus'};
9812: } else {
9813: undef(%userenv);
9814: }
9815: }
9816: }
9817: if ($quota eq '' || wantarray) {
9818: if ($quotaname eq 'course') {
9819: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9820: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9821: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9822: $defquota = $domdefs{$crstype.'quota'};
9823: }
9824: if ($defquota eq '') {
9825: $defquota = 500;
9826: }
1.1075.2.41 raeburn 9827: } else {
9828: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9829: }
9830: if ($quota eq '') {
9831: $quota = $defquota;
9832: $quotatype = 'default';
9833: } else {
9834: $quotatype = 'custom';
9835: }
1.472 raeburn 9836: }
9837: }
1.536 raeburn 9838: if (wantarray) {
9839: return ($quota,$quotatype,$settingstatus,$defquota);
9840: } else {
9841: return $quota;
9842: }
1.472 raeburn 9843: }
9844:
9845: ###############################################
9846:
9847: =pod
9848:
9849: =item * &default_quota()
9850:
1.536 raeburn 9851: Retrieves default quota assigned for storage of user portfolio files,
9852: given an (optional) user's institutional status.
1.472 raeburn 9853:
9854: Incoming parameters:
1.1075.2.42 raeburn 9855:
1.472 raeburn 9856: 1. domain
1.536 raeburn 9857: 2. (Optional) institutional status(es). This is a : separated list of
9858: status types (e.g., faculty, staff, student etc.)
9859: which apply to the user for whom the default is being retrieved.
9860: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9861: default quota will be returned.
9862: 3. quota name - portfolio, author, or course
9863: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9864:
9865: Returns:
1.1075.2.42 raeburn 9866:
1.1075.2.58 raeburn 9867: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9868: 2. (Optional) institutional type which determined the value of the
9869: default quota.
1.472 raeburn 9870:
9871: If a value has been stored in the domain's configuration db,
9872: it will return that, otherwise it returns 20 (for backwards
9873: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9874: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9875:
1.536 raeburn 9876: If the user's status includes multiple types (e.g., staff and student),
9877: the largest default quota which applies to the user determines the
9878: default quota returned.
9879:
1.472 raeburn 9880: =cut
9881:
9882: ###############################################
9883:
9884:
9885: sub default_quota {
1.1075.2.41 raeburn 9886: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9887: my ($defquota,$settingstatus);
9888: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9889: ['quotas'],$udom);
1.1075.2.41 raeburn 9890: my $key = 'defaultquota';
9891: if ($quotaname eq 'author') {
9892: $key = 'authorquota';
9893: }
1.622 raeburn 9894: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9895: if ($inststatus ne '') {
1.765 raeburn 9896: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9897: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9898: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9899: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9900: if ($defquota eq '') {
1.1075.2.41 raeburn 9901: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9902: $settingstatus = $item;
1.1075.2.41 raeburn 9903: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9904: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9905: $settingstatus = $item;
9906: }
9907: }
1.1075.2.41 raeburn 9908: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9909: if ($quotahash{'quotas'}{$item} ne '') {
9910: if ($defquota eq '') {
9911: $defquota = $quotahash{'quotas'}{$item};
9912: $settingstatus = $item;
9913: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9914: $defquota = $quotahash{'quotas'}{$item};
9915: $settingstatus = $item;
9916: }
1.536 raeburn 9917: }
9918: }
9919: }
9920: }
9921: if ($defquota eq '') {
1.1075.2.41 raeburn 9922: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9923: $defquota = $quotahash{'quotas'}{$key}{'default'};
9924: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9925: $defquota = $quotahash{'quotas'}{'default'};
9926: }
1.536 raeburn 9927: $settingstatus = 'default';
1.1075.2.42 raeburn 9928: if ($defquota eq '') {
9929: if ($quotaname eq 'author') {
9930: $defquota = 500;
9931: }
9932: }
1.536 raeburn 9933: }
9934: } else {
9935: $settingstatus = 'default';
1.1075.2.41 raeburn 9936: if ($quotaname eq 'author') {
9937: $defquota = 500;
9938: } else {
9939: $defquota = 20;
9940: }
1.536 raeburn 9941: }
9942: if (wantarray) {
9943: return ($defquota,$settingstatus);
1.472 raeburn 9944: } else {
1.536 raeburn 9945: return $defquota;
1.472 raeburn 9946: }
9947: }
9948:
1.1075.2.41 raeburn 9949: ###############################################
9950:
9951: =pod
9952:
1.1075.2.42 raeburn 9953: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9954:
9955: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9956: of existing file within authoring space will cause quota for the authoring
9957: space to be exceeded.
9958:
9959: Same, if upload of a file directly to a course/community via Course Editor
9960: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9961:
1.1075.2.61 raeburn 9962: Inputs: 7
1.1075.2.42 raeburn 9963: 1. username or coursenum
1.1075.2.41 raeburn 9964: 2. domain
1.1075.2.42 raeburn 9965: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9966: 4. filename of file for which action is being requested
9967: 5. filesize (kB) of file
9968: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9969: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9970:
9971: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9972: otherwise return null.
9973:
1.1075.2.42 raeburn 9974: =back
9975:
1.1075.2.41 raeburn 9976: =cut
9977:
1.1075.2.42 raeburn 9978: sub excess_filesize_warning {
1.1075.2.59 raeburn 9979: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9980: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9981: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9982: if ($context eq 'author') {
9983: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9984: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9985: } else {
9986: foreach my $subdir ('docs','supplemental') {
9987: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9988: }
9989: }
1.1075.2.41 raeburn 9990: $disk_quota = int($disk_quota * 1000);
9991: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9992: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9993: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9994: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9995: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9996: $disk_quota,$current_disk_usage).
9997: '</p>';
9998: }
9999: return;
10000: }
10001:
10002: ###############################################
10003:
10004:
1.384 raeburn 10005: sub get_secgrprole_info {
10006: my ($cdom,$cnum,$needroles,$type) = @_;
10007: my %sections_count = &get_sections($cdom,$cnum);
10008: my @sections = (sort {$a <=> $b} keys(%sections_count));
10009: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10010: my @groups = sort(keys(%curr_groups));
10011: my $allroles = [];
10012: my $rolehash;
10013: my $accesshash = {
10014: active => 'Currently has access',
10015: future => 'Will have future access',
10016: previous => 'Previously had access',
10017: };
10018: if ($needroles) {
10019: $rolehash = {'all' => 'all'};
1.385 albertel 10020: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10021: if (&Apache::lonnet::error(%user_roles)) {
10022: undef(%user_roles);
10023: }
10024: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10025: my ($role)=split(/\:/,$item,2);
10026: if ($role eq 'cr') { next; }
10027: if ($role =~ /^cr/) {
10028: $$rolehash{$role} = (split('/',$role))[3];
10029: } else {
10030: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10031: }
10032: }
10033: foreach my $key (sort(keys(%{$rolehash}))) {
10034: push(@{$allroles},$key);
10035: }
10036: push (@{$allroles},'st');
10037: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10038: }
10039: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10040: }
10041:
1.555 raeburn 10042: sub user_picker {
1.1075.2.127 raeburn 10043: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10044: my $currdom = $dom;
1.1075.2.114 raeburn 10045: my @alldoms = &Apache::lonnet::all_domains();
10046: if (@alldoms == 1) {
10047: my %domsrch = &Apache::lonnet::get_dom('configuration',
10048: ['directorysrch'],$alldoms[0]);
10049: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10050: my $showdom = $domdesc;
10051: if ($showdom eq '') {
10052: $showdom = $dom;
10053: }
10054: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10055: if ((!$domsrch{'directorysrch'}{'available'}) &&
10056: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10057: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10058: }
10059: }
10060: }
1.555 raeburn 10061: my %curr_selected = (
10062: srchin => 'dom',
1.580 raeburn 10063: srchby => 'lastname',
1.555 raeburn 10064: );
10065: my $srchterm;
1.625 raeburn 10066: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10067: if ($srch->{'srchby'} ne '') {
10068: $curr_selected{'srchby'} = $srch->{'srchby'};
10069: }
10070: if ($srch->{'srchin'} ne '') {
10071: $curr_selected{'srchin'} = $srch->{'srchin'};
10072: }
10073: if ($srch->{'srchtype'} ne '') {
10074: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10075: }
10076: if ($srch->{'srchdomain'} ne '') {
10077: $currdom = $srch->{'srchdomain'};
10078: }
10079: $srchterm = $srch->{'srchterm'};
10080: }
1.1075.2.98 raeburn 10081: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10082: 'usr' => 'Search criteria',
1.563 raeburn 10083: 'doma' => 'Domain/institution to search',
1.558 albertel 10084: 'uname' => 'username',
10085: 'lastname' => 'last name',
1.555 raeburn 10086: 'lastfirst' => 'last name, first name',
1.558 albertel 10087: 'crs' => 'in this course',
1.576 raeburn 10088: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10089: 'alc' => 'all LON-CAPA',
1.573 raeburn 10090: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10091: 'exact' => 'is',
10092: 'contains' => 'contains',
1.569 raeburn 10093: 'begins' => 'begins with',
1.1075.2.98 raeburn 10094: );
10095: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10096: 'youm' => "You must include some text to search for.",
10097: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10098: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10099: 'yomc' => "You must choose a domain when using an institutional directory search.",
10100: 'ymcd' => "You must choose a domain when using a domain search.",
10101: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10102: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10103: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10104: );
1.1075.2.98 raeburn 10105: &html_escape(\%html_lt);
10106: &js_escape(\%js_lt);
1.1075.2.115 raeburn 10107: my $domform;
1.1075.2.126 raeburn 10108: my $allow_blank = 1;
1.1075.2.115 raeburn 10109: if ($fixeddom) {
1.1075.2.126 raeburn 10110: $allow_blank = 0;
10111: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 10112: } else {
1.1075.2.126 raeburn 10113: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 10114: }
1.563 raeburn 10115: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10116:
10117: my @srchins = ('crs','dom','alc','instd');
10118:
10119: foreach my $option (@srchins) {
10120: # FIXME 'alc' option unavailable until
10121: # loncreateuser::print_user_query_page()
10122: # has been completed.
10123: next if ($option eq 'alc');
1.880 raeburn 10124: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10125: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 10126: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10127: if ($curr_selected{'srchin'} eq $option) {
10128: $srchinsel .= '
1.1075.2.98 raeburn 10129: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10130: } else {
10131: $srchinsel .= '
1.1075.2.98 raeburn 10132: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10133: }
1.555 raeburn 10134: }
1.563 raeburn 10135: $srchinsel .= "\n </select>\n";
1.555 raeburn 10136:
10137: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10138: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10139: if ($curr_selected{'srchby'} eq $option) {
10140: $srchbysel .= '
1.1075.2.98 raeburn 10141: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10142: } else {
10143: $srchbysel .= '
1.1075.2.98 raeburn 10144: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10145: }
10146: }
10147: $srchbysel .= "\n </select>\n";
10148:
10149: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10150: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10151: if ($curr_selected{'srchtype'} eq $option) {
10152: $srchtypesel .= '
1.1075.2.98 raeburn 10153: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10154: } else {
10155: $srchtypesel .= '
1.1075.2.98 raeburn 10156: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10157: }
10158: }
10159: $srchtypesel .= "\n </select>\n";
10160:
1.558 albertel 10161: my ($newuserscript,$new_user_create);
1.994 raeburn 10162: my $context_dom = $env{'request.role.domain'};
10163: if ($context eq 'requestcrs') {
10164: if ($env{'form.coursedom'} ne '') {
10165: $context_dom = $env{'form.coursedom'};
10166: }
10167: }
1.556 raeburn 10168: if ($forcenewuser) {
1.576 raeburn 10169: if (ref($srch) eq 'HASH') {
1.994 raeburn 10170: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10171: if ($cancreate) {
10172: $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>';
10173: } else {
1.799 bisitz 10174: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10175: my %usertypetext = (
10176: official => 'institutional',
10177: unofficial => 'non-institutional',
10178: );
1.799 bisitz 10179: $new_user_create = '<p class="LC_warning">'
10180: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10181: .' '
10182: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10183: ,'<a href="'.$helplink.'">','</a>')
10184: .'</p><br />';
1.627 raeburn 10185: }
1.576 raeburn 10186: }
10187: }
10188:
1.556 raeburn 10189: $newuserscript = <<"ENDSCRIPT";
10190:
1.570 raeburn 10191: function setSearch(createnew,callingForm) {
1.556 raeburn 10192: if (createnew == 1) {
1.570 raeburn 10193: for (var i=0; i<callingForm.srchby.length; i++) {
10194: if (callingForm.srchby.options[i].value == 'uname') {
10195: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10196: }
10197: }
1.570 raeburn 10198: for (var i=0; i<callingForm.srchin.length; i++) {
10199: if ( callingForm.srchin.options[i].value == 'dom') {
10200: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10201: }
10202: }
1.570 raeburn 10203: for (var i=0; i<callingForm.srchtype.length; i++) {
10204: if (callingForm.srchtype.options[i].value == 'exact') {
10205: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10206: }
10207: }
1.570 raeburn 10208: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10209: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10210: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10211: }
10212: }
10213: }
10214: }
10215: ENDSCRIPT
1.558 albertel 10216:
1.556 raeburn 10217: }
10218:
1.555 raeburn 10219: my $output = <<"END_BLOCK";
1.556 raeburn 10220: <script type="text/javascript">
1.824 bisitz 10221: // <![CDATA[
1.570 raeburn 10222: function validateEntry(callingForm) {
1.558 albertel 10223:
1.556 raeburn 10224: var checkok = 1;
1.558 albertel 10225: var srchin;
1.570 raeburn 10226: for (var i=0; i<callingForm.srchin.length; i++) {
10227: if ( callingForm.srchin[i].checked ) {
10228: srchin = callingForm.srchin[i].value;
1.558 albertel 10229: }
10230: }
10231:
1.570 raeburn 10232: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10233: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10234: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10235: var srchterm = callingForm.srchterm.value;
10236: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10237: var msg = "";
10238:
10239: if (srchterm == "") {
10240: checkok = 0;
1.1075.2.98 raeburn 10241: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10242: }
10243:
1.569 raeburn 10244: if (srchtype== 'begins') {
10245: if (srchterm.length < 2) {
10246: checkok = 0;
1.1075.2.98 raeburn 10247: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10248: }
10249: }
10250:
1.556 raeburn 10251: if (srchtype== 'contains') {
10252: if (srchterm.length < 3) {
10253: checkok = 0;
1.1075.2.98 raeburn 10254: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10255: }
10256: }
10257: if (srchin == 'instd') {
10258: if (srchdomain == '') {
10259: checkok = 0;
1.1075.2.98 raeburn 10260: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10261: }
10262: }
10263: if (srchin == 'dom') {
10264: if (srchdomain == '') {
10265: checkok = 0;
1.1075.2.98 raeburn 10266: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10267: }
10268: }
10269: if (srchby == 'lastfirst') {
10270: if (srchterm.indexOf(",") == -1) {
10271: checkok = 0;
1.1075.2.98 raeburn 10272: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10273: }
10274: if (srchterm.indexOf(",") == srchterm.length -1) {
10275: checkok = 0;
1.1075.2.98 raeburn 10276: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10277: }
10278: }
10279: if (checkok == 0) {
1.1075.2.98 raeburn 10280: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10281: return;
10282: }
10283: if (checkok == 1) {
1.570 raeburn 10284: callingForm.submit();
1.556 raeburn 10285: }
10286: }
10287:
10288: $newuserscript
10289:
1.824 bisitz 10290: // ]]>
1.556 raeburn 10291: </script>
1.558 albertel 10292:
10293: $new_user_create
10294:
1.555 raeburn 10295: END_BLOCK
1.558 albertel 10296:
1.876 raeburn 10297: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 10298: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10299: $domform.
10300: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 10301: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10302: $srchbysel.
10303: $srchtypesel.
10304: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10305: $srchinsel.
10306: &Apache::lonhtmlcommon::row_closure(1).
10307: &Apache::lonhtmlcommon::end_pick_box().
10308: '<br />';
1.1075.2.114 raeburn 10309: return ($output,1);
1.555 raeburn 10310: }
10311:
1.612 raeburn 10312: sub user_rule_check {
1.615 raeburn 10313: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10314: my ($response,%inst_response);
1.612 raeburn 10315: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10316: if (keys(%{$usershash}) > 1) {
10317: my (%by_username,%by_id,%userdoms);
10318: my $checkid;
1.612 raeburn 10319: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10320: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10321: $checkid = 1;
10322: }
10323: }
10324: foreach my $user (keys(%{$usershash})) {
10325: my ($uname,$udom) = split(/:/,$user);
10326: if ($checkid) {
10327: if (ref($usershash->{$user}) eq 'HASH') {
10328: if ($usershash->{$user}->{'id'} ne '') {
10329: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10330: $userdoms{$udom} = 1;
10331: if (ref($inst_results) eq 'HASH') {
10332: $inst_results->{$uname.':'.$udom} = {};
10333: }
10334: }
10335: }
10336: } else {
10337: $by_username{$udom}{$uname} = 1;
10338: $userdoms{$udom} = 1;
10339: if (ref($inst_results) eq 'HASH') {
10340: $inst_results->{$uname.':'.$udom} = {};
10341: }
10342: }
10343: }
10344: foreach my $udom (keys(%userdoms)) {
10345: if (!$got_rules->{$udom}) {
10346: my %domconfig = &Apache::lonnet::get_dom('configuration',
10347: ['usercreation'],$udom);
10348: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10349: foreach my $item ('username','id') {
10350: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10351: $$curr_rules{$udom}{$item} =
10352: $domconfig{'usercreation'}{$item.'_rule'};
10353: }
10354: }
10355: }
10356: $got_rules->{$udom} = 1;
10357: }
10358: }
10359: if ($checkid) {
10360: foreach my $udom (keys(%by_id)) {
10361: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10362: if ($outcome eq 'ok') {
10363: foreach my $id (keys(%{$by_id{$udom}})) {
10364: my $uname = $by_id{$udom}{$id};
10365: $inst_response{$uname.':'.$udom} = $outcome;
10366: }
10367: if (ref($results) eq 'HASH') {
10368: foreach my $uname (keys(%{$results})) {
10369: if (exists($inst_response{$uname.':'.$udom})) {
10370: $inst_response{$uname.':'.$udom} = $outcome;
10371: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10372: }
10373: }
10374: }
10375: }
1.612 raeburn 10376: }
1.615 raeburn 10377: } else {
1.1075.2.99 raeburn 10378: foreach my $udom (keys(%by_username)) {
10379: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10380: if ($outcome eq 'ok') {
10381: foreach my $uname (keys(%{$by_username{$udom}})) {
10382: $inst_response{$uname.':'.$udom} = $outcome;
10383: }
10384: if (ref($results) eq 'HASH') {
10385: foreach my $uname (keys(%{$results})) {
10386: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10387: }
10388: }
10389: }
10390: }
1.612 raeburn 10391: }
1.1075.2.99 raeburn 10392: } elsif (keys(%{$usershash}) == 1) {
10393: my $user = (keys(%{$usershash}))[0];
10394: my ($uname,$udom) = split(/:/,$user);
10395: if (($udom ne '') && ($uname ne '')) {
10396: if (ref($usershash->{$user}) eq 'HASH') {
10397: if (ref($checks) eq 'HASH') {
10398: if (defined($checks->{'username'})) {
10399: ($inst_response{$user},%{$inst_results->{$user}}) =
10400: &Apache::lonnet::get_instuser($udom,$uname);
10401: } elsif (defined($checks->{'id'})) {
10402: if ($usershash->{$user}->{'id'} ne '') {
10403: ($inst_response{$user},%{$inst_results->{$user}}) =
10404: &Apache::lonnet::get_instuser($udom,undef,
10405: $usershash->{$user}->{'id'});
10406: } else {
10407: ($inst_response{$user},%{$inst_results->{$user}}) =
10408: &Apache::lonnet::get_instuser($udom,$uname);
10409: }
10410: }
10411: } else {
10412: ($inst_response{$user},%{$inst_results->{$user}}) =
10413: &Apache::lonnet::get_instuser($udom,$uname);
10414: return;
10415: }
10416: if (!$got_rules->{$udom}) {
10417: my %domconfig = &Apache::lonnet::get_dom('configuration',
10418: ['usercreation'],$udom);
10419: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10420: foreach my $item ('username','id') {
10421: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10422: $$curr_rules{$udom}{$item} =
10423: $domconfig{'usercreation'}{$item.'_rule'};
10424: }
10425: }
1.585 raeburn 10426: }
1.1075.2.99 raeburn 10427: $got_rules->{$udom} = 1;
1.585 raeburn 10428: }
10429: }
1.1075.2.99 raeburn 10430: } else {
10431: return;
10432: }
10433: } else {
10434: return;
10435: }
10436: foreach my $user (keys(%{$usershash})) {
10437: my ($uname,$udom) = split(/:/,$user);
10438: next if (($udom eq '') || ($uname eq ''));
10439: my $id;
10440: if (ref($inst_results) eq 'HASH') {
10441: if (ref($inst_results->{$user}) eq 'HASH') {
10442: $id = $inst_results->{$user}->{'id'};
10443: }
10444: }
10445: if ($id eq '') {
10446: if (ref($usershash->{$user})) {
10447: $id = $usershash->{$user}->{'id'};
10448: }
1.585 raeburn 10449: }
1.612 raeburn 10450: foreach my $item (keys(%{$checks})) {
10451: if (ref($$curr_rules{$udom}) eq 'HASH') {
10452: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10453: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10454: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10455: $$curr_rules{$udom}{$item});
1.612 raeburn 10456: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10457: if ($rule_check{$rule}) {
10458: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10459: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10460: if (ref($inst_results) eq 'HASH') {
10461: if (ref($inst_results->{$user}) eq 'HASH') {
10462: if (keys(%{$inst_results->{$user}}) == 0) {
10463: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10464: } elsif ($item eq 'id') {
10465: if ($inst_results->{$user}->{'id'} eq '') {
10466: $$alerts{$item}{$udom}{$uname} = 1;
10467: }
1.615 raeburn 10468: }
1.612 raeburn 10469: }
10470: }
1.615 raeburn 10471: }
10472: last;
1.585 raeburn 10473: }
10474: }
10475: }
10476: }
10477: }
10478: }
10479: }
10480: }
1.612 raeburn 10481: return;
10482: }
10483:
10484: sub user_rule_formats {
10485: my ($domain,$domdesc,$curr_rules,$check) = @_;
10486: my %text = (
10487: 'username' => 'Usernames',
10488: 'id' => 'IDs',
10489: );
10490: my $output;
10491: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10492: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10493: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10494: $output = '<br />'.
10495: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10496: '<span class="LC_cusr_emph">','</span>',$domdesc).
10497: ' <ul>';
1.612 raeburn 10498: foreach my $rule (@{$ruleorder}) {
10499: if (ref($curr_rules) eq 'ARRAY') {
10500: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10501: if (ref($rules->{$rule}) eq 'HASH') {
10502: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10503: $rules->{$rule}{'desc'}.'</li>';
10504: }
10505: }
10506: }
10507: }
10508: $output .= '</ul>';
10509: }
10510: }
10511: return $output;
10512: }
10513:
10514: sub instrule_disallow_msg {
1.615 raeburn 10515: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10516: my $response;
10517: my %text = (
10518: item => 'username',
10519: items => 'usernames',
10520: match => 'matches',
10521: do => 'does',
10522: action => 'a username',
10523: one => 'one',
10524: );
10525: if ($count > 1) {
10526: $text{'item'} = 'usernames';
10527: $text{'match'} ='match';
10528: $text{'do'} = 'do';
10529: $text{'action'} = 'usernames',
10530: $text{'one'} = 'ones';
10531: }
10532: if ($checkitem eq 'id') {
10533: $text{'items'} = 'IDs';
10534: $text{'item'} = 'ID';
10535: $text{'action'} = 'an ID';
1.615 raeburn 10536: if ($count > 1) {
10537: $text{'item'} = 'IDs';
10538: $text{'action'} = 'IDs';
10539: }
1.612 raeburn 10540: }
1.674 bisitz 10541: $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 10542: if ($mode eq 'upload') {
10543: if ($checkitem eq 'username') {
10544: $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'}.");
10545: } elsif ($checkitem eq 'id') {
1.674 bisitz 10546: $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 10547: }
1.669 raeburn 10548: } elsif ($mode eq 'selfcreate') {
10549: if ($checkitem eq 'id') {
10550: $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.");
10551: }
1.615 raeburn 10552: } else {
10553: if ($checkitem eq 'username') {
10554: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10555: } elsif ($checkitem eq 'id') {
10556: $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.");
10557: }
1.612 raeburn 10558: }
10559: return $response;
1.585 raeburn 10560: }
10561:
1.624 raeburn 10562: sub personal_data_fieldtitles {
10563: my %fieldtitles = &Apache::lonlocal::texthash (
10564: id => 'Student/Employee ID',
10565: permanentemail => 'E-mail address',
10566: lastname => 'Last Name',
10567: firstname => 'First Name',
10568: middlename => 'Middle Name',
10569: generation => 'Generation',
10570: gen => 'Generation',
1.765 raeburn 10571: inststatus => 'Affiliation',
1.624 raeburn 10572: );
10573: return %fieldtitles;
10574: }
10575:
1.642 raeburn 10576: sub sorted_inst_types {
10577: my ($dom) = @_;
1.1075.2.70 raeburn 10578: my ($usertypes,$order);
10579: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10580: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10581: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10582: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10583: } else {
10584: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10585: }
1.642 raeburn 10586: my $othertitle = &mt('All users');
10587: if ($env{'request.course.id'}) {
1.668 raeburn 10588: $othertitle = &mt('Any users');
1.642 raeburn 10589: }
10590: my @types;
10591: if (ref($order) eq 'ARRAY') {
10592: @types = @{$order};
10593: }
10594: if (@types == 0) {
10595: if (ref($usertypes) eq 'HASH') {
10596: @types = sort(keys(%{$usertypes}));
10597: }
10598: }
10599: if (keys(%{$usertypes}) > 0) {
10600: $othertitle = &mt('Other users');
10601: }
10602: return ($othertitle,$usertypes,\@types);
10603: }
10604:
1.645 raeburn 10605: sub get_institutional_codes {
1.1075.2.157 raeburn 10606: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 10607: # Get complete list of course sections to update
10608: my @currsections = ();
10609: my @currxlists = ();
1.1075.2.157 raeburn 10610: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 10611: my $coursecode = $$settings{'internal.coursecode'};
1.1075.2.157 raeburn 10612: my $crskey = $crs.':'.$coursecode;
10613: @{$unclutteredsec{$crskey}} = ();
10614: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 10615:
10616: if ($$settings{'internal.sectionnums'} ne '') {
10617: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10618: }
10619:
10620: if ($$settings{'internal.crosslistings'} ne '') {
10621: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10622: }
10623:
10624: if (@currxlists > 0) {
1.1075.2.157 raeburn 10625: foreach my $xl (@currxlists) {
10626: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 10627: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10628: push(@{$allcourses},$1);
1.645 raeburn 10629: $$LC_code{$1} = $2;
10630: }
10631: }
10632: }
10633: }
1.1075.2.157 raeburn 10634:
1.645 raeburn 10635: if (@currsections > 0) {
1.1075.2.157 raeburn 10636: foreach my $sec (@currsections) {
10637: if ($sec =~ m/^(\w+):(\w*)$/ ) {
10638: my $instsec = $1;
1.645 raeburn 10639: my $lc_sec = $2;
1.1075.2.157 raeburn 10640: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
10641: push(@{$unclutteredsec{$crskey}},$instsec);
10642: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
10643: }
10644: }
10645: }
10646: }
10647:
10648: if (@{$unclutteredsec{$crskey}} > 0) {
10649: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
10650: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
10651: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
10652: my $sec = $coursecode.$formattedsec{$crskey}[$i];
10653: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1075.2.119 raeburn 10654: push(@{$allcourses},$sec);
1.1075.2.157 raeburn 10655: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 10656: }
10657: }
10658: }
10659: }
10660: return;
10661: }
10662:
1.971 raeburn 10663: sub get_standard_codeitems {
10664: return ('Year','Semester','Department','Number','Section');
10665: }
10666:
1.112 bowersj2 10667: =pod
10668:
1.780 raeburn 10669: =head1 Slot Helpers
10670:
10671: =over 4
10672:
10673: =item * sorted_slots()
10674:
1.1040 raeburn 10675: Sorts an array of slot names in order of an optional sort key,
10676: default sort is by slot start time (earliest first).
1.780 raeburn 10677:
10678: Inputs:
10679:
10680: =over 4
10681:
10682: slotsarr - Reference to array of unsorted slot names.
10683:
10684: slots - Reference to hash of hash, where outer hash keys are slot names.
10685:
1.1040 raeburn 10686: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10687:
1.549 albertel 10688: =back
10689:
1.780 raeburn 10690: Returns:
10691:
10692: =over 4
10693:
1.1040 raeburn 10694: sorted - An array of slot names sorted by a specified sort key
10695: (default sort key is start time of the slot).
1.780 raeburn 10696:
10697: =back
10698:
10699: =cut
10700:
10701:
10702: sub sorted_slots {
1.1040 raeburn 10703: my ($slotsarr,$slots,$sortkey) = @_;
10704: if ($sortkey eq '') {
10705: $sortkey = 'starttime';
10706: }
1.780 raeburn 10707: my @sorted;
10708: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10709: @sorted =
10710: sort {
10711: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10712: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10713: }
10714: if (ref($slots->{$a})) { return -1;}
10715: if (ref($slots->{$b})) { return 1;}
10716: return 0;
10717: } @{$slotsarr};
10718: }
10719: return @sorted;
10720: }
10721:
1.1040 raeburn 10722: =pod
10723:
10724: =item * get_future_slots()
10725:
10726: Inputs:
10727:
10728: =over 4
10729:
10730: cnum - course number
10731:
10732: cdom - course domain
10733:
10734: now - current UNIX time
10735:
10736: symb - optional symb
10737:
10738: =back
10739:
10740: Returns:
10741:
10742: =over 4
10743:
10744: sorted_reservable - ref to array of student_schedulable slots currently
10745: reservable, ordered by end date of reservation period.
10746:
10747: reservable_now - ref to hash of student_schedulable slots currently
10748: reservable.
10749:
10750: Keys in inner hash are:
10751: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10752: (b) endreserve: end date of reservation period.
10753: (c) uniqueperiod: start,end dates when slot is to be uniquely
10754: selected.
1.1040 raeburn 10755:
10756: sorted_future - ref to array of student_schedulable slots reservable in
10757: the future, ordered by start date of reservation period.
10758:
10759: future_reservable - ref to hash of student_schedulable slots reservable
10760: in the future.
10761:
10762: Keys in inner hash are:
10763: (a) symb: either blank or symb to which slot use is restricted.
10764: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10765: (c) uniqueperiod: start,end dates when slot is to be uniquely
10766: selected.
1.1040 raeburn 10767:
10768: =back
10769:
10770: =cut
10771:
10772: sub get_future_slots {
10773: my ($cnum,$cdom,$now,$symb) = @_;
10774: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10775: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10776: foreach my $slot (keys(%slots)) {
10777: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10778: if ($symb) {
10779: next if (($slots{$slot}->{'symb'} ne '') &&
10780: ($slots{$slot}->{'symb'} ne $symb));
10781: }
10782: if (($slots{$slot}->{'starttime'} > $now) &&
10783: ($slots{$slot}->{'endtime'} > $now)) {
10784: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10785: my $userallowed = 0;
10786: if ($slots{$slot}->{'allowedsections'}) {
10787: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10788: if (!defined($env{'request.role.sec'})
10789: && grep(/^No section assigned$/,@allowed_sec)) {
10790: $userallowed=1;
10791: } else {
10792: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10793: $userallowed=1;
10794: }
10795: }
10796: unless ($userallowed) {
10797: if (defined($env{'request.course.groups'})) {
10798: my @groups = split(/:/,$env{'request.course.groups'});
10799: foreach my $group (@groups) {
10800: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10801: $userallowed=1;
10802: last;
10803: }
10804: }
10805: }
10806: }
10807: }
10808: if ($slots{$slot}->{'allowedusers'}) {
10809: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10810: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10811: if (grep(/^\Q$user\E$/,@allowed_users)) {
10812: $userallowed = 1;
10813: }
10814: }
10815: next unless($userallowed);
10816: }
10817: my $startreserve = $slots{$slot}->{'startreserve'};
10818: my $endreserve = $slots{$slot}->{'endreserve'};
10819: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10820: my $uniqueperiod;
10821: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10822: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10823: }
1.1040 raeburn 10824: if (($startreserve < $now) &&
10825: (!$endreserve || $endreserve > $now)) {
10826: my $lastres = $endreserve;
10827: if (!$lastres) {
10828: $lastres = $slots{$slot}->{'starttime'};
10829: }
10830: $reservable_now{$slot} = {
10831: symb => $symb,
1.1075.2.104 raeburn 10832: endreserve => $lastres,
10833: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10834: };
10835: } elsif (($startreserve > $now) &&
10836: (!$endreserve || $endreserve > $startreserve)) {
10837: $future_reservable{$slot} = {
10838: symb => $symb,
1.1075.2.104 raeburn 10839: startreserve => $startreserve,
10840: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10841: };
10842: }
10843: }
10844: }
10845: my @unsorted_reservable = keys(%reservable_now);
10846: if (@unsorted_reservable > 0) {
10847: @sorted_reservable =
10848: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10849: }
10850: my @unsorted_future = keys(%future_reservable);
10851: if (@unsorted_future > 0) {
10852: @sorted_future =
10853: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10854: }
10855: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10856: }
1.780 raeburn 10857:
10858: =pod
10859:
1.1057 foxr 10860: =back
10861:
1.549 albertel 10862: =head1 HTTP Helpers
10863:
10864: =over 4
10865:
1.648 raeburn 10866: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10867:
1.258 albertel 10868: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10869: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10870: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10871:
10872: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10873: $possible_names is an ref to an array of form element names. As an example:
10874: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10875: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10876:
10877: =cut
1.1 albertel 10878:
1.6 albertel 10879: sub get_unprocessed_cgi {
1.25 albertel 10880: my ($query,$possible_names)= @_;
1.26 matthew 10881: # $Apache::lonxml::debug=1;
1.356 albertel 10882: foreach my $pair (split(/&/,$query)) {
10883: my ($name, $value) = split(/=/,$pair);
1.369 www 10884: $name = &unescape($name);
1.25 albertel 10885: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10886: $value =~ tr/+/ /;
10887: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10888: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10889: }
1.16 harris41 10890: }
1.6 albertel 10891: }
10892:
1.112 bowersj2 10893: =pod
10894:
1.648 raeburn 10895: =item * &cacheheader()
1.112 bowersj2 10896:
10897: returns cache-controlling header code
10898:
10899: =cut
10900:
1.7 albertel 10901: sub cacheheader {
1.258 albertel 10902: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10903: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10904: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10905: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10906: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10907: return $output;
1.7 albertel 10908: }
10909:
1.112 bowersj2 10910: =pod
10911:
1.648 raeburn 10912: =item * &no_cache($r)
1.112 bowersj2 10913:
10914: specifies header code to not have cache
10915:
10916: =cut
10917:
1.9 albertel 10918: sub no_cache {
1.216 albertel 10919: my ($r) = @_;
10920: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10921: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10922: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10923: $r->no_cache(1);
10924: $r->header_out("Expires" => $date);
10925: $r->header_out("Pragma" => "no-cache");
1.123 www 10926: }
10927:
10928: sub content_type {
1.181 albertel 10929: my ($r,$type,$charset) = @_;
1.299 foxr 10930: if ($r) {
10931: # Note that printout.pl calls this with undef for $r.
10932: &no_cache($r);
10933: }
1.258 albertel 10934: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10935: unless ($charset) {
10936: $charset=&Apache::lonlocal::current_encoding;
10937: }
10938: if ($charset) { $type.='; charset='.$charset; }
10939: if ($r) {
10940: $r->content_type($type);
10941: } else {
10942: print("Content-type: $type\n\n");
10943: }
1.9 albertel 10944: }
1.25 albertel 10945:
1.112 bowersj2 10946: =pod
10947:
1.648 raeburn 10948: =item * &add_to_env($name,$value)
1.112 bowersj2 10949:
1.258 albertel 10950: adds $name to the %env hash with value
1.112 bowersj2 10951: $value, if $name already exists, the entry is converted to an array
10952: reference and $value is added to the array.
10953:
10954: =cut
10955:
1.25 albertel 10956: sub add_to_env {
10957: my ($name,$value)=@_;
1.258 albertel 10958: if (defined($env{$name})) {
10959: if (ref($env{$name})) {
1.25 albertel 10960: #already have multiple values
1.258 albertel 10961: push(@{ $env{$name} },$value);
1.25 albertel 10962: } else {
10963: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10964: my $first=$env{$name};
10965: undef($env{$name});
10966: push(@{ $env{$name} },$first,$value);
1.25 albertel 10967: }
10968: } else {
1.258 albertel 10969: $env{$name}=$value;
1.25 albertel 10970: }
1.31 albertel 10971: }
1.149 albertel 10972:
10973: =pod
10974:
1.648 raeburn 10975: =item * &get_env_multiple($name)
1.149 albertel 10976:
1.258 albertel 10977: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10978: values may be defined and end up as an array ref.
10979:
10980: returns an array of values
10981:
10982: =cut
10983:
10984: sub get_env_multiple {
10985: my ($name) = @_;
10986: my @values;
1.258 albertel 10987: if (defined($env{$name})) {
1.149 albertel 10988: # exists is it an array
1.258 albertel 10989: if (ref($env{$name})) {
10990: @values=@{ $env{$name} };
1.149 albertel 10991: } else {
1.258 albertel 10992: $values[0]=$env{$name};
1.149 albertel 10993: }
10994: }
10995: return(@values);
10996: }
10997:
1.660 raeburn 10998: sub ask_for_embedded_content {
10999: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11000: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 11001: %currsubfile,%unused,$rem);
1.1071 raeburn 11002: my $counter = 0;
11003: my $numnew = 0;
1.987 raeburn 11004: my $numremref = 0;
11005: my $numinvalid = 0;
11006: my $numpathchg = 0;
11007: my $numexisting = 0;
1.1071 raeburn 11008: my $numunused = 0;
11009: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 11010: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11011: my $heading = &mt('Upload embedded files');
11012: my $buttontext = &mt('Upload');
11013:
1.1075.2.11 raeburn 11014: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 11015: if ($actionurl eq '/adm/dependencies') {
11016: $navmap = Apache::lonnavmaps::navmap->new();
11017: }
11018: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11019: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 11020: }
1.1075.2.35 raeburn 11021: if (($actionurl eq '/adm/portfolio') ||
11022: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11023: my $current_path='/';
11024: if ($env{'form.currentpath'}) {
11025: $current_path = $env{'form.currentpath'};
11026: }
11027: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 11028: $udom = $cdom;
11029: $uname = $cnum;
1.984 raeburn 11030: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11031: } else {
11032: $udom = $env{'user.domain'};
11033: $uname = $env{'user.name'};
11034: $url = '/userfiles/portfolio';
11035: }
1.987 raeburn 11036: $toplevel = $url.'/';
1.984 raeburn 11037: $url .= $current_path;
11038: $getpropath = 1;
1.987 raeburn 11039: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11040: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11041: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11042: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11043: $toplevel = $url;
1.984 raeburn 11044: if ($rest ne '') {
1.987 raeburn 11045: $url .= $rest;
11046: }
11047: } elsif ($actionurl eq '/adm/coursedocs') {
11048: if (ref($args) eq 'HASH') {
1.1071 raeburn 11049: $url = $args->{'docs_url'};
11050: $toplevel = $url;
1.1075.2.11 raeburn 11051: if ($args->{'context'} eq 'paste') {
11052: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11053: ($path) =
11054: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11055: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11056: $fileloc =~ s{^/}{};
11057: }
1.1071 raeburn 11058: }
11059: } elsif ($actionurl eq '/adm/dependencies') {
11060: if ($env{'request.course.id'} ne '') {
11061: if (ref($args) eq 'HASH') {
11062: $url = $args->{'docs_url'};
11063: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 11064: $toplevel = $url;
11065: unless ($toplevel =~ m{^/}) {
11066: $toplevel = "/$url";
11067: }
1.1075.2.11 raeburn 11068: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 11069: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11070: $path = $1;
11071: } else {
11072: ($path) =
11073: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11074: }
1.1075.2.79 raeburn 11075: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11076: $fileloc = $toplevel;
11077: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11078: my ($udom,$uname,$fname) =
11079: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11080: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11081: } else {
11082: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11083: }
1.1071 raeburn 11084: $fileloc =~ s{^/}{};
11085: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11086: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11087: }
1.987 raeburn 11088: }
1.1075.2.35 raeburn 11089: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11090: $udom = $cdom;
11091: $uname = $cnum;
11092: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11093: $toplevel = $url;
11094: $path = $url;
11095: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11096: $fileloc =~ s{^/}{};
11097: }
11098: foreach my $file (keys(%{$allfiles})) {
11099: my $embed_file;
11100: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11101: $embed_file = $1;
11102: } else {
11103: $embed_file = $file;
11104: }
1.1075.2.55 raeburn 11105: my ($absolutepath,$cleaned_file);
11106: if ($embed_file =~ m{^\w+://}) {
11107: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 11108: $newfiles{$cleaned_file} = 1;
11109: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11110: } else {
1.1075.2.55 raeburn 11111: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11112: if ($embed_file =~ m{^/}) {
11113: $absolutepath = $embed_file;
11114: }
1.1075.2.47 raeburn 11115: if ($cleaned_file =~ m{/}) {
11116: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11117: $path = &check_for_traversal($path,$url,$toplevel);
11118: my $item = $fname;
11119: if ($path ne '') {
11120: $item = $path.'/'.$fname;
11121: $subdependencies{$path}{$fname} = 1;
11122: } else {
11123: $dependencies{$item} = 1;
11124: }
11125: if ($absolutepath) {
11126: $mapping{$item} = $absolutepath;
11127: } else {
11128: $mapping{$item} = $embed_file;
11129: }
11130: } else {
11131: $dependencies{$embed_file} = 1;
11132: if ($absolutepath) {
1.1075.2.47 raeburn 11133: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11134: } else {
1.1075.2.47 raeburn 11135: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11136: }
11137: }
1.984 raeburn 11138: }
11139: }
1.1071 raeburn 11140: my $dirptr = 16384;
1.984 raeburn 11141: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11142: $currsubfile{$path} = {};
1.1075.2.35 raeburn 11143: if (($actionurl eq '/adm/portfolio') ||
11144: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11145: my ($sublistref,$listerror) =
11146: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11147: if (ref($sublistref) eq 'ARRAY') {
11148: foreach my $line (@{$sublistref}) {
11149: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11150: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11151: }
1.984 raeburn 11152: }
1.987 raeburn 11153: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11154: if (opendir(my $dir,$url.'/'.$path)) {
11155: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11156: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11157: }
1.1075.2.11 raeburn 11158: } elsif (($actionurl eq '/adm/dependencies') ||
11159: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11160: ($args->{'context'} eq 'paste')) ||
11161: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11162: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 11163: my $dir;
11164: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11165: $dir = $fileloc;
11166: } else {
11167: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11168: }
1.1071 raeburn 11169: if ($dir ne '') {
11170: my ($sublistref,$listerror) =
11171: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11172: if (ref($sublistref) eq 'ARRAY') {
11173: foreach my $line (@{$sublistref}) {
11174: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11175: undef,$mtime)=split(/\&/,$line,12);
11176: unless (($testdir&$dirptr) ||
11177: ($file_name =~ /^\.\.?$/)) {
11178: $currsubfile{$path}{$file_name} = [$size,$mtime];
11179: }
11180: }
11181: }
11182: }
1.984 raeburn 11183: }
11184: }
11185: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11186: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11187: my $item = $path.'/'.$file;
11188: unless ($mapping{$item} eq $item) {
11189: $pathchanges{$item} = 1;
11190: }
11191: $existing{$item} = 1;
11192: $numexisting ++;
11193: } else {
11194: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11195: }
11196: }
1.1071 raeburn 11197: if ($actionurl eq '/adm/dependencies') {
11198: foreach my $path (keys(%currsubfile)) {
11199: if (ref($currsubfile{$path}) eq 'HASH') {
11200: foreach my $file (keys(%{$currsubfile{$path}})) {
11201: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 11202: next if (($rem ne '') &&
11203: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11204: (ref($navmap) &&
11205: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11206: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11207: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11208: $unused{$path.'/'.$file} = 1;
11209: }
11210: }
11211: }
11212: }
11213: }
1.984 raeburn 11214: }
1.987 raeburn 11215: my %currfile;
1.1075.2.35 raeburn 11216: if (($actionurl eq '/adm/portfolio') ||
11217: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11218: my ($dirlistref,$listerror) =
11219: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11220: if (ref($dirlistref) eq 'ARRAY') {
11221: foreach my $line (@{$dirlistref}) {
11222: my ($file_name,$rest) = split(/\&/,$line,2);
11223: $currfile{$file_name} = 1;
11224: }
1.984 raeburn 11225: }
1.987 raeburn 11226: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11227: if (opendir(my $dir,$url)) {
1.987 raeburn 11228: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11229: map {$currfile{$_} = 1;} @dir_list;
11230: }
1.1075.2.11 raeburn 11231: } elsif (($actionurl eq '/adm/dependencies') ||
11232: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11233: ($args->{'context'} eq 'paste')) ||
11234: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11235: if ($env{'request.course.id'} ne '') {
11236: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11237: if ($dir ne '') {
11238: my ($dirlistref,$listerror) =
11239: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11240: if (ref($dirlistref) eq 'ARRAY') {
11241: foreach my $line (@{$dirlistref}) {
11242: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11243: $size,undef,$mtime)=split(/\&/,$line,12);
11244: unless (($testdir&$dirptr) ||
11245: ($file_name =~ /^\.\.?$/)) {
11246: $currfile{$file_name} = [$size,$mtime];
11247: }
11248: }
11249: }
11250: }
11251: }
1.984 raeburn 11252: }
11253: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11254: if (exists($currfile{$file})) {
1.987 raeburn 11255: unless ($mapping{$file} eq $file) {
11256: $pathchanges{$file} = 1;
11257: }
11258: $existing{$file} = 1;
11259: $numexisting ++;
11260: } else {
1.984 raeburn 11261: $newfiles{$file} = 1;
11262: }
11263: }
1.1071 raeburn 11264: foreach my $file (keys(%currfile)) {
11265: unless (($file eq $filename) ||
11266: ($file eq $filename.'.bak') ||
11267: ($dependencies{$file})) {
1.1075.2.11 raeburn 11268: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 11269: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11270: next if (($rem ne '') &&
11271: (($env{"httpref.$rem".$file} ne '') ||
11272: (ref($navmap) &&
11273: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11274: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11275: ($navmap->getResourceByUrl($rem.$1)))))));
11276: }
1.1075.2.11 raeburn 11277: }
1.1071 raeburn 11278: $unused{$file} = 1;
11279: }
11280: }
1.1075.2.11 raeburn 11281: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11282: ($args->{'context'} eq 'paste')) {
11283: $counter = scalar(keys(%existing));
11284: $numpathchg = scalar(keys(%pathchanges));
11285: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 11286: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11287: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11288: $counter = scalar(keys(%existing));
11289: $numpathchg = scalar(keys(%pathchanges));
11290: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 11291: }
1.984 raeburn 11292: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11293: if ($actionurl eq '/adm/dependencies') {
11294: next if ($embed_file =~ m{^\w+://});
11295: }
1.660 raeburn 11296: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11297: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11298: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11299: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 11300: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11301: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11302: }
1.1075.2.35 raeburn 11303: $upload_output .= '</td>';
1.1071 raeburn 11304: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 11305: $upload_output.='<td align="right">'.
11306: '<span class="LC_info LC_fontsize_medium">'.
11307: &mt("URL points to web address").'</span>';
1.987 raeburn 11308: $numremref++;
1.660 raeburn 11309: } elsif ($args->{'error_on_invalid_names'}
11310: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 11311: $upload_output.='<td align="right"><span class="LC_warning">'.
11312: &mt('Invalid characters').'</span>';
1.987 raeburn 11313: $numinvalid++;
1.660 raeburn 11314: } else {
1.1075.2.35 raeburn 11315: $upload_output .= '<td>'.
11316: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11317: $embed_file,\%mapping,
1.1071 raeburn 11318: $allfiles,$codebase,'upload');
11319: $counter ++;
11320: $numnew ++;
1.987 raeburn 11321: }
11322: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11323: }
11324: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11325: if ($actionurl eq '/adm/dependencies') {
11326: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11327: $modify_output .= &start_data_table_row().
11328: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11329: '<img src="'.&icon($embed_file).'" border="0" />'.
11330: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11331: '<td>'.$size.'</td>'.
11332: '<td>'.$mtime.'</td>'.
11333: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11334: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11335: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11336: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11337: &embedded_file_element('upload_embedded',$counter,
11338: $embed_file,\%mapping,
11339: $allfiles,$codebase,'modify').
11340: '</div></td>'.
11341: &end_data_table_row()."\n";
11342: $counter ++;
11343: } else {
11344: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11345: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11346: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11347: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11348: &Apache::loncommon::end_data_table_row()."\n";
11349: }
11350: }
11351: my $delidx = $counter;
11352: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11353: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11354: $delete_output .= &start_data_table_row().
11355: '<td><img src="'.&icon($oldfile).'" />'.
11356: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11357: '<td>'.$size.'</td>'.
11358: '<td>'.$mtime.'</td>'.
11359: '<td><label><input type="checkbox" name="del_upload_dep" '.
11360: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11361: &embedded_file_element('upload_embedded',$delidx,
11362: $oldfile,\%mapping,$allfiles,
11363: $codebase,'delete').'</td>'.
11364: &end_data_table_row()."\n";
11365: $numunused ++;
11366: $delidx ++;
1.987 raeburn 11367: }
11368: if ($upload_output) {
11369: $upload_output = &start_data_table().
11370: $upload_output.
11371: &end_data_table()."\n";
11372: }
1.1071 raeburn 11373: if ($modify_output) {
11374: $modify_output = &start_data_table().
11375: &start_data_table_header_row().
11376: '<th>'.&mt('File').'</th>'.
11377: '<th>'.&mt('Size (KB)').'</th>'.
11378: '<th>'.&mt('Modified').'</th>'.
11379: '<th>'.&mt('Upload replacement?').'</th>'.
11380: &end_data_table_header_row().
11381: $modify_output.
11382: &end_data_table()."\n";
11383: }
11384: if ($delete_output) {
11385: $delete_output = &start_data_table().
11386: &start_data_table_header_row().
11387: '<th>'.&mt('File').'</th>'.
11388: '<th>'.&mt('Size (KB)').'</th>'.
11389: '<th>'.&mt('Modified').'</th>'.
11390: '<th>'.&mt('Delete?').'</th>'.
11391: &end_data_table_header_row().
11392: $delete_output.
11393: &end_data_table()."\n";
11394: }
1.987 raeburn 11395: my $applies = 0;
11396: if ($numremref) {
11397: $applies ++;
11398: }
11399: if ($numinvalid) {
11400: $applies ++;
11401: }
11402: if ($numexisting) {
11403: $applies ++;
11404: }
1.1071 raeburn 11405: if ($counter || $numunused) {
1.987 raeburn 11406: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11407: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11408: $state.'<h3>'.$heading.'</h3>';
11409: if ($actionurl eq '/adm/dependencies') {
11410: if ($numnew) {
11411: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11412: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11413: $upload_output.'<br />'."\n";
11414: }
11415: if ($numexisting) {
11416: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11417: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11418: $modify_output.'<br />'."\n";
11419: $buttontext = &mt('Save changes');
11420: }
11421: if ($numunused) {
11422: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11423: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11424: $delete_output.'<br />'."\n";
11425: $buttontext = &mt('Save changes');
11426: }
11427: } else {
11428: $output .= $upload_output.'<br />'."\n";
11429: }
11430: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11431: $counter.'" />'."\n";
11432: if ($actionurl eq '/adm/dependencies') {
11433: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11434: $numnew.'" />'."\n";
11435: } elsif ($actionurl eq '') {
1.987 raeburn 11436: $output .= '<input type="hidden" name="phase" value="three" />';
11437: }
11438: } elsif ($applies) {
11439: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11440: if ($applies > 1) {
11441: $output .=
1.1075.2.35 raeburn 11442: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11443: if ($numremref) {
11444: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11445: }
11446: if ($numinvalid) {
11447: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11448: }
11449: if ($numexisting) {
11450: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11451: }
11452: $output .= '</ul><br />';
11453: } elsif ($numremref) {
11454: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11455: } elsif ($numinvalid) {
11456: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11457: } elsif ($numexisting) {
11458: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11459: }
11460: $output .= $upload_output.'<br />';
11461: }
11462: my ($pathchange_output,$chgcount);
1.1071 raeburn 11463: $chgcount = $counter;
1.987 raeburn 11464: if (keys(%pathchanges) > 0) {
11465: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11466: if ($counter) {
1.987 raeburn 11467: $output .= &embedded_file_element('pathchange',$chgcount,
11468: $embed_file,\%mapping,
1.1071 raeburn 11469: $allfiles,$codebase,'change');
1.987 raeburn 11470: } else {
11471: $pathchange_output .=
11472: &start_data_table_row().
11473: '<td><input type ="checkbox" name="namechange" value="'.
11474: $chgcount.'" checked="checked" /></td>'.
11475: '<td>'.$mapping{$embed_file}.'</td>'.
11476: '<td>'.$embed_file.
11477: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11478: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11479: '</td>'.&end_data_table_row();
1.660 raeburn 11480: }
1.987 raeburn 11481: $numpathchg ++;
11482: $chgcount ++;
1.660 raeburn 11483: }
11484: }
1.1075.2.35 raeburn 11485: if (($counter) || ($numunused)) {
1.987 raeburn 11486: if ($numpathchg) {
11487: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11488: $numpathchg.'" />'."\n";
11489: }
11490: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11491: ($actionurl eq '/adm/imsimport')) {
11492: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11493: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11494: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11495: } elsif ($actionurl eq '/adm/dependencies') {
11496: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11497: }
1.1075.2.35 raeburn 11498: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11499: } elsif ($numpathchg) {
11500: my %pathchange = ();
11501: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11502: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11503: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11504: }
1.987 raeburn 11505: }
1.1071 raeburn 11506: return ($output,$counter,$numpathchg);
1.987 raeburn 11507: }
11508:
1.1075.2.47 raeburn 11509: =pod
11510:
11511: =item * clean_path($name)
11512:
11513: Performs clean-up of directories, subdirectories and filename in an
11514: embedded object, referenced in an HTML file which is being uploaded
11515: to a course or portfolio, where
11516: "Upload embedded images/multimedia files if HTML file" checkbox was
11517: checked.
11518:
11519: Clean-up is similar to replacements in lonnet::clean_filename()
11520: except each / between sub-directory and next level is preserved.
11521:
11522: =cut
11523:
11524: sub clean_path {
11525: my ($embed_file) = @_;
11526: $embed_file =~s{^/+}{};
11527: my @contents;
11528: if ($embed_file =~ m{/}) {
11529: @contents = split(/\//,$embed_file);
11530: } else {
11531: @contents = ($embed_file);
11532: }
11533: my $lastidx = scalar(@contents)-1;
11534: for (my $i=0; $i<=$lastidx; $i++) {
11535: $contents[$i]=~s{\\}{/}g;
11536: $contents[$i]=~s/\s+/\_/g;
11537: $contents[$i]=~s{[^/\w\.\-]}{}g;
11538: if ($i == $lastidx) {
11539: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11540: }
11541: }
11542: if ($lastidx > 0) {
11543: return join('/',@contents);
11544: } else {
11545: return $contents[0];
11546: }
11547: }
11548:
1.987 raeburn 11549: sub embedded_file_element {
1.1071 raeburn 11550: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11551: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11552: (ref($codebase) eq 'HASH'));
11553: my $output;
1.1071 raeburn 11554: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11555: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11556: }
11557: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11558: &escape($embed_file).'" />';
11559: unless (($context eq 'upload_embedded') &&
11560: ($mapping->{$embed_file} eq $embed_file)) {
11561: $output .='
11562: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11563: }
11564: my $attrib;
11565: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11566: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11567: }
11568: $output .=
11569: "\n\t\t".
11570: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11571: $attrib.'" />';
11572: if (exists($codebase->{$mapping->{$embed_file}})) {
11573: $output .=
11574: "\n\t\t".
11575: '<input name="codebase_'.$num.'" type="hidden" value="'.
11576: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11577: }
1.987 raeburn 11578: return $output;
1.660 raeburn 11579: }
11580:
1.1071 raeburn 11581: sub get_dependency_details {
11582: my ($currfile,$currsubfile,$embed_file) = @_;
11583: my ($size,$mtime,$showsize,$showmtime);
11584: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11585: if ($embed_file =~ m{/}) {
11586: my ($path,$fname) = split(/\//,$embed_file);
11587: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11588: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11589: }
11590: } else {
11591: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11592: ($size,$mtime) = @{$currfile->{$embed_file}};
11593: }
11594: }
11595: $showsize = $size/1024.0;
11596: $showsize = sprintf("%.1f",$showsize);
11597: if ($mtime > 0) {
11598: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11599: }
11600: }
11601: return ($showsize,$showmtime);
11602: }
11603:
11604: sub ask_embedded_js {
11605: return <<"END";
11606: <script type="text/javascript"">
11607: // <![CDATA[
11608: function toggleBrowse(counter) {
11609: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11610: var fileid = document.getElementById('embedded_item_'+counter);
11611: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11612: if (chkboxid.checked == true) {
11613: uploaddivid.style.display='block';
11614: } else {
11615: uploaddivid.style.display='none';
11616: fileid.value = '';
11617: }
11618: }
11619: // ]]>
11620: </script>
11621:
11622: END
11623: }
11624:
1.661 raeburn 11625: sub upload_embedded {
11626: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11627: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11628: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11629: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11630: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11631: my $orig_uploaded_filename =
11632: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11633: foreach my $type ('orig','ref','attrib','codebase') {
11634: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11635: $env{'form.embedded_'.$type.'_'.$i} =
11636: &unescape($env{'form.embedded_'.$type.'_'.$i});
11637: }
11638: }
1.661 raeburn 11639: my ($path,$fname) =
11640: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11641: # no path, whole string is fname
11642: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11643: $fname = &Apache::lonnet::clean_filename($fname);
11644: # See if there is anything left
11645: next if ($fname eq '');
11646:
11647: # Check if file already exists as a file or directory.
11648: my ($state,$msg);
11649: if ($context eq 'portfolio') {
11650: my $port_path = $dirpath;
11651: if ($group ne '') {
11652: $port_path = "groups/$group/$port_path";
11653: }
1.987 raeburn 11654: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11655: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11656: $dir_root,$port_path,$disk_quota,
11657: $current_disk_usage,$uname,$udom);
11658: if ($state eq 'will_exceed_quota'
1.984 raeburn 11659: || $state eq 'file_locked') {
1.661 raeburn 11660: $output .= $msg;
11661: next;
11662: }
11663: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11664: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11665: if ($state eq 'exists') {
11666: $output .= $msg;
11667: next;
11668: }
11669: }
11670: # Check if extension is valid
11671: if (($fname =~ /\.(\w+)$/) &&
11672: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11673: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11674: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11675: next;
11676: } elsif (($fname =~ /\.(\w+)$/) &&
11677: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11678: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11679: next;
11680: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11681: $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 11682: next;
11683: }
11684: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11685: my $subdir = $path;
11686: $subdir =~ s{/+$}{};
1.661 raeburn 11687: if ($context eq 'portfolio') {
1.984 raeburn 11688: my $result;
11689: if ($state eq 'existingfile') {
11690: $result=
11691: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11692: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11693: } else {
1.984 raeburn 11694: $result=
11695: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11696: $dirpath.
1.1075.2.35 raeburn 11697: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11698: if ($result !~ m|^/uploaded/|) {
11699: $output .= '<span class="LC_error">'
11700: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11701: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11702: .'</span><br />';
11703: next;
11704: } else {
1.987 raeburn 11705: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11706: $path.$fname.'</span>').'<br />';
1.984 raeburn 11707: }
1.661 raeburn 11708: }
1.1075.2.35 raeburn 11709: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11710: my $extendedsubdir = $dirpath.'/'.$subdir;
11711: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11712: my $result =
1.1075.2.35 raeburn 11713: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11714: if ($result !~ m|^/uploaded/|) {
11715: $output .= '<span class="LC_error">'
11716: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11717: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11718: .'</span><br />';
11719: next;
11720: } else {
11721: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11722: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11723: if ($context eq 'syllabus') {
11724: &Apache::lonnet::make_public_indefinitely($result);
11725: }
1.987 raeburn 11726: }
1.661 raeburn 11727: } else {
11728: # Save the file
11729: my $target = $env{'form.embedded_item_'.$i};
11730: my $fullpath = $dir_root.$dirpath.'/'.$path;
11731: my $dest = $fullpath.$fname;
11732: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11733: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11734: my $count;
11735: my $filepath = $dir_root;
1.1027 raeburn 11736: foreach my $subdir (@parts) {
11737: $filepath .= "/$subdir";
11738: if (!-e $filepath) {
1.661 raeburn 11739: mkdir($filepath,0770);
11740: }
11741: }
11742: my $fh;
11743: if (!open($fh,'>'.$dest)) {
11744: &Apache::lonnet::logthis('Failed to create '.$dest);
11745: $output .= '<span class="LC_error">'.
1.1071 raeburn 11746: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11747: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11748: '</span><br />';
11749: } else {
11750: if (!print $fh $env{'form.embedded_item_'.$i}) {
11751: &Apache::lonnet::logthis('Failed to write to '.$dest);
11752: $output .= '<span class="LC_error">'.
1.1071 raeburn 11753: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11754: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11755: '</span><br />';
11756: } else {
1.987 raeburn 11757: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11758: $url.'</span>').'<br />';
11759: unless ($context eq 'testbank') {
11760: $footer .= &mt('View embedded file: [_1]',
11761: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11762: }
11763: }
11764: close($fh);
11765: }
11766: }
11767: if ($env{'form.embedded_ref_'.$i}) {
11768: $pathchange{$i} = 1;
11769: }
11770: }
11771: if ($output) {
11772: $output = '<p>'.$output.'</p>';
11773: }
11774: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11775: $returnflag = 'ok';
1.1071 raeburn 11776: my $numpathchgs = scalar(keys(%pathchange));
11777: if ($numpathchgs > 0) {
1.987 raeburn 11778: if ($context eq 'portfolio') {
11779: $output .= '<p>'.&mt('or').'</p>';
11780: } elsif ($context eq 'testbank') {
1.1071 raeburn 11781: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11782: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11783: $returnflag = 'modify_orightml';
11784: }
11785: }
1.1071 raeburn 11786: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11787: }
11788:
11789: sub modify_html_form {
11790: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11791: my $end = 0;
11792: my $modifyform;
11793: if ($context eq 'upload_embedded') {
11794: return unless (ref($pathchange) eq 'HASH');
11795: if ($env{'form.number_embedded_items'}) {
11796: $end += $env{'form.number_embedded_items'};
11797: }
11798: if ($env{'form.number_pathchange_items'}) {
11799: $end += $env{'form.number_pathchange_items'};
11800: }
11801: if ($end) {
11802: for (my $i=0; $i<$end; $i++) {
11803: if ($i < $env{'form.number_embedded_items'}) {
11804: next unless($pathchange->{$i});
11805: }
11806: $modifyform .=
11807: &start_data_table_row().
11808: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11809: 'checked="checked" /></td>'.
11810: '<td>'.$env{'form.embedded_ref_'.$i}.
11811: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11812: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11813: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11814: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11815: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11816: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11817: '<td>'.$env{'form.embedded_orig_'.$i}.
11818: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11819: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11820: &end_data_table_row();
1.1071 raeburn 11821: }
1.987 raeburn 11822: }
11823: } else {
11824: $modifyform = $pathchgtable;
11825: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11826: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11827: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11828: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11829: }
11830: }
11831: if ($modifyform) {
1.1071 raeburn 11832: if ($actionurl eq '/adm/dependencies') {
11833: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11834: }
1.987 raeburn 11835: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11836: '<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".
11837: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11838: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11839: '</ol></p>'."\n".'<p>'.
11840: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11841: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11842: &start_data_table()."\n".
11843: &start_data_table_header_row().
11844: '<th>'.&mt('Change?').'</th>'.
11845: '<th>'.&mt('Current reference').'</th>'.
11846: '<th>'.&mt('Required reference').'</th>'.
11847: &end_data_table_header_row()."\n".
11848: $modifyform.
11849: &end_data_table().'<br />'."\n".$hiddenstate.
11850: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11851: '</form>'."\n";
11852: }
11853: return;
11854: }
11855:
11856: sub modify_html_refs {
1.1075.2.35 raeburn 11857: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11858: my $container;
11859: if ($context eq 'portfolio') {
11860: $container = $env{'form.container'};
11861: } elsif ($context eq 'coursedoc') {
11862: $container = $env{'form.primaryurl'};
1.1071 raeburn 11863: } elsif ($context eq 'manage_dependencies') {
11864: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11865: $container = "/$container";
1.1075.2.35 raeburn 11866: } elsif ($context eq 'syllabus') {
11867: $container = $url;
1.987 raeburn 11868: } else {
1.1027 raeburn 11869: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11870: }
11871: my (%allfiles,%codebase,$output,$content);
11872: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11873: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11874: if (wantarray) {
11875: return ('',0,0);
11876: } else {
11877: return;
11878: }
11879: }
11880: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11881: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11882: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11883: if (wantarray) {
11884: return ('',0,0);
11885: } else {
11886: return;
11887: }
11888: }
1.987 raeburn 11889: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11890: if ($content eq '-1') {
11891: if (wantarray) {
11892: return ('',0,0);
11893: } else {
11894: return;
11895: }
11896: }
1.987 raeburn 11897: } else {
1.1071 raeburn 11898: unless ($container =~ /^\Q$dir_root\E/) {
11899: if (wantarray) {
11900: return ('',0,0);
11901: } else {
11902: return;
11903: }
11904: }
1.1075.2.128 raeburn 11905: if (open(my $fh,'<',$container)) {
1.987 raeburn 11906: $content = join('', <$fh>);
11907: close($fh);
11908: } else {
1.1071 raeburn 11909: if (wantarray) {
11910: return ('',0,0);
11911: } else {
11912: return;
11913: }
1.987 raeburn 11914: }
11915: }
11916: my ($count,$codebasecount) = (0,0);
11917: my $mm = new File::MMagic;
11918: my $mime_type = $mm->checktype_contents($content);
11919: if ($mime_type eq 'text/html') {
11920: my $parse_result =
11921: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11922: \%codebase,\$content);
11923: if ($parse_result eq 'ok') {
11924: foreach my $i (@changes) {
11925: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11926: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11927: if ($allfiles{$ref}) {
11928: my $newname = $orig;
11929: my ($attrib_regexp,$codebase);
1.1006 raeburn 11930: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11931: if ($attrib_regexp =~ /:/) {
11932: $attrib_regexp =~ s/\:/|/g;
11933: }
11934: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11935: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11936: $count += $numchg;
1.1075.2.35 raeburn 11937: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11938: delete($allfiles{$ref});
1.987 raeburn 11939: }
11940: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11941: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11942: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11943: $codebasecount ++;
11944: }
11945: }
11946: }
1.1075.2.35 raeburn 11947: my $skiprewrites;
1.987 raeburn 11948: if ($count || $codebasecount) {
11949: my $saveresult;
1.1071 raeburn 11950: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11951: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11952: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11953: if ($url eq $container) {
11954: my ($fname) = ($container =~ m{/([^/]+)$});
11955: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11956: $count,'<span class="LC_filename">'.
1.1071 raeburn 11957: $fname.'</span>').'</p>';
1.987 raeburn 11958: } else {
11959: $output = '<p class="LC_error">'.
11960: &mt('Error: update failed for: [_1].',
11961: '<span class="LC_filename">'.
11962: $container.'</span>').'</p>';
11963: }
1.1075.2.35 raeburn 11964: if ($context eq 'syllabus') {
11965: unless ($saveresult eq 'ok') {
11966: $skiprewrites = 1;
11967: }
11968: }
1.987 raeburn 11969: } else {
1.1075.2.128 raeburn 11970: if (open(my $fh,'>',$container)) {
1.987 raeburn 11971: print $fh $content;
11972: close($fh);
11973: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11974: $count,'<span class="LC_filename">'.
11975: $container.'</span>').'</p>';
1.661 raeburn 11976: } else {
1.987 raeburn 11977: $output = '<p class="LC_error">'.
11978: &mt('Error: could not update [_1].',
11979: '<span class="LC_filename">'.
11980: $container.'</span>').'</p>';
1.661 raeburn 11981: }
11982: }
11983: }
1.1075.2.35 raeburn 11984: if (($context eq 'syllabus') && (!$skiprewrites)) {
11985: my ($actionurl,$state);
11986: $actionurl = "/public/$udom/$uname/syllabus";
11987: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11988: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11989: \%codebase,
11990: {'context' => 'rewrites',
11991: 'ignore_remote_references' => 1,});
11992: if (ref($mapping) eq 'HASH') {
11993: my $rewrites = 0;
11994: foreach my $key (keys(%{$mapping})) {
11995: next if ($key =~ m{^https?://});
11996: my $ref = $mapping->{$key};
11997: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11998: my $attrib;
11999: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12000: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12001: }
12002: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12003: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12004: $rewrites += $numchg;
12005: }
12006: }
12007: if ($rewrites) {
12008: my $saveresult;
12009: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12010: if ($url eq $container) {
12011: my ($fname) = ($container =~ m{/([^/]+)$});
12012: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12013: $count,'<span class="LC_filename">'.
12014: $fname.'</span>').'</p>';
12015: } else {
12016: $output .= '<p class="LC_error">'.
12017: &mt('Error: could not update links in [_1].',
12018: '<span class="LC_filename">'.
12019: $container.'</span>').'</p>';
12020:
12021: }
12022: }
12023: }
12024: }
1.987 raeburn 12025: } else {
12026: &logthis('Failed to parse '.$container.
12027: ' to modify references: '.$parse_result);
1.661 raeburn 12028: }
12029: }
1.1071 raeburn 12030: if (wantarray) {
12031: return ($output,$count,$codebasecount);
12032: } else {
12033: return $output;
12034: }
1.661 raeburn 12035: }
12036:
12037: sub check_for_existing {
12038: my ($path,$fname,$element) = @_;
12039: my ($state,$msg);
12040: if (-d $path.'/'.$fname) {
12041: $state = 'exists';
12042: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12043: } elsif (-e $path.'/'.$fname) {
12044: $state = 'exists';
12045: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12046: }
12047: if ($state eq 'exists') {
12048: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12049: }
12050: return ($state,$msg);
12051: }
12052:
12053: sub check_for_upload {
12054: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12055: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12056: my $filesize = length($env{'form.'.$element});
12057: if (!$filesize) {
12058: my $msg = '<span class="LC_error">'.
12059: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12060: '<span class="LC_filename">'.$fname.'</span>',
12061: $filesize).'<br />'.
1.1007 raeburn 12062: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12063: '</span>';
12064: return ('zero_bytes',$msg);
12065: }
12066: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12067: my $getpropath = 1;
1.1021 raeburn 12068: my ($dirlistref,$listerror) =
12069: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12070: my $found_file = 0;
12071: my $locked_file = 0;
1.991 raeburn 12072: my @lockers;
12073: my $navmap;
12074: if ($env{'request.course.id'}) {
12075: $navmap = Apache::lonnavmaps::navmap->new();
12076: }
1.1021 raeburn 12077: if (ref($dirlistref) eq 'ARRAY') {
12078: foreach my $line (@{$dirlistref}) {
12079: my ($file_name,$rest)=split(/\&/,$line,2);
12080: if ($file_name eq $fname){
12081: $file_name = $path.$file_name;
12082: if ($group ne '') {
12083: $file_name = $group.$file_name;
12084: }
12085: $found_file = 1;
12086: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12087: foreach my $lock (@lockers) {
12088: if (ref($lock) eq 'ARRAY') {
12089: my ($symb,$crsid) = @{$lock};
12090: if ($crsid eq $env{'request.course.id'}) {
12091: if (ref($navmap)) {
12092: my $res = $navmap->getBySymb($symb);
12093: foreach my $part (@{$res->parts()}) {
12094: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12095: unless (($slot_status == $res->RESERVED) ||
12096: ($slot_status == $res->RESERVED_LOCATION)) {
12097: $locked_file = 1;
12098: }
1.991 raeburn 12099: }
1.1021 raeburn 12100: } else {
12101: $locked_file = 1;
1.991 raeburn 12102: }
12103: } else {
12104: $locked_file = 1;
12105: }
12106: }
1.1021 raeburn 12107: }
12108: } else {
12109: my @info = split(/\&/,$rest);
12110: my $currsize = $info[6]/1000;
12111: if ($currsize < $filesize) {
12112: my $extra = $filesize - $currsize;
12113: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 12114: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12115: &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 12116: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12117: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12118: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12119: return ('will_exceed_quota',$msg);
12120: }
1.984 raeburn 12121: }
12122: }
1.661 raeburn 12123: }
12124: }
12125: }
12126: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 12127: my $msg = '<p class="LC_warning">'.
12128: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
12129: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12130: return ('will_exceed_quota',$msg);
12131: } elsif ($found_file) {
12132: if ($locked_file) {
1.1075.2.69 raeburn 12133: my $msg = '<p class="LC_warning">';
1.661 raeburn 12134: $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 12135: $msg .= '</p>';
1.661 raeburn 12136: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12137: return ('file_locked',$msg);
12138: } else {
1.1075.2.69 raeburn 12139: my $msg = '<p class="LC_error">';
1.984 raeburn 12140: $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 12141: $msg .= '</p>';
1.984 raeburn 12142: return ('existingfile',$msg);
1.661 raeburn 12143: }
12144: }
12145: }
12146:
1.987 raeburn 12147: sub check_for_traversal {
12148: my ($path,$url,$toplevel) = @_;
12149: my @parts=split(/\//,$path);
12150: my $cleanpath;
12151: my $fullpath = $url;
12152: for (my $i=0;$i<@parts;$i++) {
12153: next if ($parts[$i] eq '.');
12154: if ($parts[$i] eq '..') {
12155: $fullpath =~ s{([^/]+/)$}{};
12156: } else {
12157: $fullpath .= $parts[$i].'/';
12158: }
12159: }
12160: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12161: $cleanpath = $1;
12162: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12163: my $curr_toprel = $1;
12164: my @parts = split(/\//,$curr_toprel);
12165: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12166: my @urlparts = split(/\//,$url_toprel);
12167: my $doubledots;
12168: my $startdiff = -1;
12169: for (my $i=0; $i<@urlparts; $i++) {
12170: if ($startdiff == -1) {
12171: unless ($urlparts[$i] eq $parts[$i]) {
12172: $startdiff = $i;
12173: $doubledots .= '../';
12174: }
12175: } else {
12176: $doubledots .= '../';
12177: }
12178: }
12179: if ($startdiff > -1) {
12180: $cleanpath = $doubledots;
12181: for (my $i=$startdiff; $i<@parts; $i++) {
12182: $cleanpath .= $parts[$i].'/';
12183: }
12184: }
12185: }
12186: $cleanpath =~ s{(/)$}{};
12187: return $cleanpath;
12188: }
1.31 albertel 12189:
1.1053 raeburn 12190: sub is_archive_file {
12191: my ($mimetype) = @_;
12192: if (($mimetype eq 'application/octet-stream') ||
12193: ($mimetype eq 'application/x-stuffit') ||
12194: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12195: return 1;
12196: }
12197: return;
12198: }
12199:
12200: sub decompress_form {
1.1065 raeburn 12201: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12202: my %lt = &Apache::lonlocal::texthash (
12203: this => 'This file is an archive file.',
1.1067 raeburn 12204: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12205: itsc => 'Its contents are as follows:',
1.1053 raeburn 12206: youm => 'You may wish to extract its contents.',
12207: extr => 'Extract contents',
1.1067 raeburn 12208: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12209: proa => 'Process automatically?',
1.1053 raeburn 12210: yes => 'Yes',
12211: no => 'No',
1.1067 raeburn 12212: fold => 'Title for folder containing movie',
12213: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12214: );
1.1065 raeburn 12215: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12216: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12217: my $info = &list_archive_contents($fileloc,\@paths);
12218: if (@paths) {
12219: foreach my $path (@paths) {
12220: $path =~ s{^/}{};
1.1067 raeburn 12221: if ($path =~ m{^([^/]+)/$}) {
12222: $topdir = $1;
12223: }
1.1065 raeburn 12224: if ($path =~ m{^([^/]+)/}) {
12225: $toplevel{$1} = $path;
12226: } else {
12227: $toplevel{$path} = $path;
12228: }
12229: }
12230: }
1.1067 raeburn 12231: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 12232: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12233: "$topdir/media/",
12234: "$topdir/media/$topdir.mp4",
12235: "$topdir/media/FirstFrame.png",
12236: "$topdir/media/player.swf",
12237: "$topdir/media/swfobject.js",
12238: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 12239: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 12240: "$topdir/$topdir.mp4",
12241: "$topdir/$topdir\_config.xml",
12242: "$topdir/$topdir\_controller.swf",
12243: "$topdir/$topdir\_embed.css",
12244: "$topdir/$topdir\_First_Frame.png",
12245: "$topdir/$topdir\_player.html",
12246: "$topdir/$topdir\_Thumbnails.png",
12247: "$topdir/playerProductInstall.swf",
12248: "$topdir/scripts/",
12249: "$topdir/scripts/config_xml.js",
12250: "$topdir/scripts/handlebars.js",
12251: "$topdir/scripts/jquery-1.7.1.min.js",
12252: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12253: "$topdir/scripts/modernizr.js",
12254: "$topdir/scripts/player-min.js",
12255: "$topdir/scripts/swfobject.js",
12256: "$topdir/skins/",
12257: "$topdir/skins/configuration_express.xml",
12258: "$topdir/skins/express_show/",
12259: "$topdir/skins/express_show/player-min.css",
12260: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 12261: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12262: "$topdir/$topdir.mp4",
12263: "$topdir/$topdir\_config.xml",
12264: "$topdir/$topdir\_controller.swf",
12265: "$topdir/$topdir\_embed.css",
12266: "$topdir/$topdir\_First_Frame.png",
12267: "$topdir/$topdir\_player.html",
12268: "$topdir/$topdir\_Thumbnails.png",
12269: "$topdir/playerProductInstall.swf",
12270: "$topdir/scripts/",
12271: "$topdir/scripts/config_xml.js",
12272: "$topdir/scripts/techsmith-smart-player.min.js",
12273: "$topdir/skins/",
12274: "$topdir/skins/configuration_express.xml",
12275: "$topdir/skins/express_show/",
12276: "$topdir/skins/express_show/spritesheet.min.css",
12277: "$topdir/skins/express_show/spritesheet.png",
12278: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 12279: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12280: if (@diffs == 0) {
1.1075.2.59 raeburn 12281: $is_camtasia = 6;
12282: } else {
1.1075.2.81 raeburn 12283: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 12284: if (@diffs == 0) {
12285: $is_camtasia = 8;
1.1075.2.81 raeburn 12286: } else {
12287: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12288: if (@diffs == 0) {
12289: $is_camtasia = 8;
12290: }
1.1075.2.59 raeburn 12291: }
1.1067 raeburn 12292: }
12293: }
12294: my $output;
12295: if ($is_camtasia) {
12296: $output = <<"ENDCAM";
12297: <script type="text/javascript" language="Javascript">
12298: // <![CDATA[
12299:
12300: function camtasiaToggle() {
12301: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12302: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 12303: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12304: document.getElementById('camtasia_titles').style.display='block';
12305: } else {
12306: document.getElementById('camtasia_titles').style.display='none';
12307: }
12308: }
12309: }
12310: return;
12311: }
12312:
12313: // ]]>
12314: </script>
12315: <p>$lt{'camt'}</p>
12316: ENDCAM
1.1065 raeburn 12317: } else {
1.1067 raeburn 12318: $output = '<p>'.$lt{'this'};
12319: if ($info eq '') {
12320: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12321: } else {
12322: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12323: '<div><pre>'.$info.'</pre></div>';
12324: }
1.1065 raeburn 12325: }
1.1067 raeburn 12326: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12327: my $duplicates;
12328: my $num = 0;
12329: if (ref($dirlist) eq 'ARRAY') {
12330: foreach my $item (@{$dirlist}) {
12331: if (ref($item) eq 'ARRAY') {
12332: if (exists($toplevel{$item->[0]})) {
12333: $duplicates .=
12334: &start_data_table_row().
12335: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12336: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12337: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12338: 'value="1" />'.&mt('Yes').'</label>'.
12339: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12340: '<td>'.$item->[0].'</td>';
12341: if ($item->[2]) {
12342: $duplicates .= '<td>'.&mt('Directory').'</td>';
12343: } else {
12344: $duplicates .= '<td>'.&mt('File').'</td>';
12345: }
12346: $duplicates .= '<td>'.$item->[3].'</td>'.
12347: '<td>'.
12348: &Apache::lonlocal::locallocaltime($item->[4]).
12349: '</td>'.
12350: &end_data_table_row();
12351: $num ++;
12352: }
12353: }
12354: }
12355: }
12356: my $itemcount;
12357: if (@paths > 0) {
12358: $itemcount = scalar(@paths);
12359: } else {
12360: $itemcount = 1;
12361: }
1.1067 raeburn 12362: if ($is_camtasia) {
12363: $output .= $lt{'auto'}.'<br />'.
12364: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12365: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12366: $lt{'yes'}.'</label> <label>'.
12367: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12368: $lt{'no'}.'</label></span><br />'.
12369: '<div id="camtasia_titles" style="display:block">'.
12370: &Apache::lonhtmlcommon::start_pick_box().
12371: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12372: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12373: &Apache::lonhtmlcommon::row_closure().
12374: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12375: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12376: &Apache::lonhtmlcommon::row_closure(1).
12377: &Apache::lonhtmlcommon::end_pick_box().
12378: '</div>';
12379: }
1.1065 raeburn 12380: $output .=
12381: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12382: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12383: "\n";
1.1065 raeburn 12384: if ($duplicates ne '') {
12385: $output .= '<p><span class="LC_warning">'.
12386: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12387: &start_data_table().
12388: &start_data_table_header_row().
12389: '<th>'.&mt('Overwrite?').'</th>'.
12390: '<th>'.&mt('Name').'</th>'.
12391: '<th>'.&mt('Type').'</th>'.
12392: '<th>'.&mt('Size').'</th>'.
12393: '<th>'.&mt('Last modified').'</th>'.
12394: &end_data_table_header_row().
12395: $duplicates.
12396: &end_data_table().
12397: '</p>';
12398: }
1.1067 raeburn 12399: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12400: if (ref($hiddenelements) eq 'HASH') {
12401: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12402: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12403: }
12404: }
12405: $output .= <<"END";
1.1067 raeburn 12406: <br />
1.1053 raeburn 12407: <input type="submit" name="decompress" value="$lt{'extr'}" />
12408: </form>
12409: $noextract
12410: END
12411: return $output;
12412: }
12413:
1.1065 raeburn 12414: sub decompression_utility {
12415: my ($program) = @_;
12416: my @utilities = ('tar','gunzip','bunzip2','unzip');
12417: my $location;
12418: if (grep(/^\Q$program\E$/,@utilities)) {
12419: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12420: '/usr/sbin/') {
12421: if (-x $dir.$program) {
12422: $location = $dir.$program;
12423: last;
12424: }
12425: }
12426: }
12427: return $location;
12428: }
12429:
12430: sub list_archive_contents {
12431: my ($file,$pathsref) = @_;
12432: my (@cmd,$output);
12433: my $needsregexp;
12434: if ($file =~ /\.zip$/) {
12435: @cmd = (&decompression_utility('unzip'),"-l");
12436: $needsregexp = 1;
12437: } elsif (($file =~ m/\.tar\.gz$/) ||
12438: ($file =~ /\.tgz$/)) {
12439: @cmd = (&decompression_utility('tar'),"-ztf");
12440: } elsif ($file =~ /\.tar\.bz2$/) {
12441: @cmd = (&decompression_utility('tar'),"-jtf");
12442: } elsif ($file =~ m|\.tar$|) {
12443: @cmd = (&decompression_utility('tar'),"-tf");
12444: }
12445: if (@cmd) {
12446: undef($!);
12447: undef($@);
12448: if (open(my $fh,"-|", @cmd, $file)) {
12449: while (my $line = <$fh>) {
12450: $output .= $line;
12451: chomp($line);
12452: my $item;
12453: if ($needsregexp) {
12454: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12455: } else {
12456: $item = $line;
12457: }
12458: if ($item ne '') {
12459: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12460: push(@{$pathsref},$item);
12461: }
12462: }
12463: }
12464: close($fh);
12465: }
12466: }
12467: return $output;
12468: }
12469:
1.1053 raeburn 12470: sub decompress_uploaded_file {
12471: my ($file,$dir) = @_;
12472: &Apache::lonnet::appenv({'cgi.file' => $file});
12473: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12474: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12475: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12476: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12477: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12478: my $decompressed = $env{'cgi.decompressed'};
12479: &Apache::lonnet::delenv('cgi.file');
12480: &Apache::lonnet::delenv('cgi.dir');
12481: &Apache::lonnet::delenv('cgi.decompressed');
12482: return ($decompressed,$result);
12483: }
12484:
1.1055 raeburn 12485: sub process_decompression {
12486: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12487: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12488: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12489: &mt('Unexpected file path.').'</p>'."\n";
12490: }
12491: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12492: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12493: &mt('Unexpected course context.').'</p>'."\n";
12494: }
12495: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12496: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12497: &mt('Filename contained unexpected characters.').'</p>'."\n";
12498: }
1.1055 raeburn 12499: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12500: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12501: $error = &mt('Filename not a supported archive file type.').
12502: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12503: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12504: } else {
12505: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12506: if ($docuhome eq 'no_host') {
12507: $error = &mt('Could not determine home server for course.');
12508: } else {
12509: my @ids=&Apache::lonnet::current_machine_ids();
12510: my $currdir = "$dir_root/$destination";
12511: if (grep(/^\Q$docuhome\E$/,@ids)) {
12512: $dir = &LONCAPA::propath($docudom,$docuname).
12513: "$dir_root/$destination";
12514: } else {
12515: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12516: "$dir_root/$docudom/$docuname/$destination";
12517: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12518: $error = &mt('Archive file not found.');
12519: }
12520: }
1.1065 raeburn 12521: my (@to_overwrite,@to_skip);
12522: if ($env{'form.archive_overwrite_total'} > 0) {
12523: my $total = $env{'form.archive_overwrite_total'};
12524: for (my $i=0; $i<$total; $i++) {
12525: if ($env{'form.archive_overwrite_'.$i} == 1) {
12526: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12527: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12528: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12529: }
12530: }
12531: }
12532: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12533: my $numoverwrite = scalar(@to_overwrite);
12534: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12535: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12536: } elsif ($dir eq '') {
1.1055 raeburn 12537: $error = &mt('Directory containing archive file unavailable.');
12538: } elsif (!$error) {
1.1065 raeburn 12539: my ($decompressed,$display);
1.1075.2.128 raeburn 12540: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12541: my $tempdir = time.'_'.$$.int(rand(10000));
12542: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12543: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12544: ($decompressed,$display) =
12545: &decompress_uploaded_file($file,"$dir/$tempdir");
12546: foreach my $item (@to_skip) {
12547: if (($item ne '') && ($item !~ /\.\./)) {
12548: if (-f "$dir/$tempdir/$item") {
12549: unlink("$dir/$tempdir/$item");
12550: } elsif (-d "$dir/$tempdir/$item") {
12551: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12552: }
12553: }
12554: }
12555: foreach my $item (@to_overwrite) {
12556: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12557: if (($item ne '') && ($item !~ /\.\./)) {
12558: if (-f "$dir/$item") {
12559: unlink("$dir/$item");
12560: } elsif (-d "$dir/$item") {
12561: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12562: }
12563: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12564: }
1.1065 raeburn 12565: }
12566: }
1.1075.2.128 raeburn 12567: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12568: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12569: }
1.1065 raeburn 12570: }
12571: } else {
12572: ($decompressed,$display) =
12573: &decompress_uploaded_file($file,$dir);
12574: }
1.1055 raeburn 12575: if ($decompressed eq 'ok') {
1.1065 raeburn 12576: $output = '<p class="LC_info">'.
12577: &mt('Files extracted successfully from archive.').
12578: '</p>'."\n";
1.1055 raeburn 12579: my ($warning,$result,@contents);
12580: my ($newdirlistref,$newlisterror) =
12581: &Apache::lonnet::dirlist($currdir,$docudom,
12582: $docuname,1);
12583: my (%is_dir,%changes,@newitems);
12584: my $dirptr = 16384;
1.1065 raeburn 12585: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12586: foreach my $dir_line (@{$newdirlistref}) {
12587: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12588: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12589: push(@newitems,$item);
12590: if ($dirptr&$testdir) {
12591: $is_dir{$item} = 1;
12592: }
12593: $changes{$item} = 1;
12594: }
12595: }
12596: }
12597: if (keys(%changes) > 0) {
12598: foreach my $item (sort(@newitems)) {
12599: if ($changes{$item}) {
12600: push(@contents,$item);
12601: }
12602: }
12603: }
12604: if (@contents > 0) {
1.1067 raeburn 12605: my $wantform;
12606: unless ($env{'form.autoextract_camtasia'}) {
12607: $wantform = 1;
12608: }
1.1056 raeburn 12609: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12610: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12611: $currdir,\%is_dir,
12612: \%children,\%parent,
1.1056 raeburn 12613: \@contents,\%dirorder,
12614: \%titles,$wantform);
1.1055 raeburn 12615: if ($datatable ne '') {
12616: $output .= &archive_options_form('decompressed',$datatable,
12617: $count,$hiddenelem);
1.1065 raeburn 12618: my $startcount = 6;
1.1055 raeburn 12619: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12620: \%titles,\%children);
1.1055 raeburn 12621: }
1.1067 raeburn 12622: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12623: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12624: my %displayed;
12625: my $total = 1;
12626: $env{'form.archive_directory'} = [];
12627: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12628: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12629: $path =~ s{/$}{};
12630: my $item;
12631: if ($path ne '') {
12632: $item = "$path/$titles{$i}";
12633: } else {
12634: $item = $titles{$i};
12635: }
12636: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12637: if ($item eq $contents[0]) {
12638: push(@{$env{'form.archive_directory'}},$i);
12639: $env{'form.archive_'.$i} = 'display';
12640: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12641: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12642: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12643: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12644: $env{'form.archive_'.$i} = 'display';
12645: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12646: $displayed{'web'} = $i;
12647: } else {
1.1075.2.59 raeburn 12648: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12649: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12650: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12651: push(@{$env{'form.archive_directory'}},$i);
12652: }
12653: $env{'form.archive_'.$i} = 'dependency';
12654: }
12655: $total ++;
12656: }
12657: for (my $i=1; $i<$total; $i++) {
12658: next if ($i == $displayed{'web'});
12659: next if ($i == $displayed{'folder'});
12660: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12661: }
12662: $env{'form.phase'} = 'decompress_cleanup';
12663: $env{'form.archivedelete'} = 1;
12664: $env{'form.archive_count'} = $total-1;
12665: $output .=
12666: &process_extracted_files('coursedocs',$docudom,
12667: $docuname,$destination,
12668: $dir_root,$hiddenelem);
12669: }
1.1055 raeburn 12670: } else {
12671: $warning = &mt('No new items extracted from archive file.');
12672: }
12673: } else {
12674: $output = $display;
12675: $error = &mt('An error occurred during extraction from the archive file.');
12676: }
12677: }
12678: }
12679: }
12680: if ($error) {
12681: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12682: $error.'</p>'."\n";
12683: }
12684: if ($warning) {
12685: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12686: }
12687: return $output;
12688: }
12689:
12690: sub get_extracted {
1.1056 raeburn 12691: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12692: $titles,$wantform) = @_;
1.1055 raeburn 12693: my $count = 0;
12694: my $depth = 0;
12695: my $datatable;
1.1056 raeburn 12696: my @hierarchy;
1.1055 raeburn 12697: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12698: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12699: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12700: foreach my $item (@{$contents}) {
12701: $count ++;
1.1056 raeburn 12702: @{$dirorder->{$count}} = @hierarchy;
12703: $titles->{$count} = $item;
1.1055 raeburn 12704: &archive_hierarchy($depth,$count,$parent,$children);
12705: if ($wantform) {
12706: $datatable .= &archive_row($is_dir->{$item},$item,
12707: $currdir,$depth,$count);
12708: }
12709: if ($is_dir->{$item}) {
12710: $depth ++;
1.1056 raeburn 12711: push(@hierarchy,$count);
12712: $parent->{$depth} = $count;
1.1055 raeburn 12713: $datatable .=
12714: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12715: \$depth,\$count,\@hierarchy,$dirorder,
12716: $children,$parent,$titles,$wantform);
1.1055 raeburn 12717: $depth --;
1.1056 raeburn 12718: pop(@hierarchy);
1.1055 raeburn 12719: }
12720: }
12721: return ($count,$datatable);
12722: }
12723:
12724: sub recurse_extracted_archive {
1.1056 raeburn 12725: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12726: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12727: my $result='';
1.1056 raeburn 12728: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12729: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12730: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12731: return $result;
12732: }
12733: my $dirptr = 16384;
12734: my ($newdirlistref,$newlisterror) =
12735: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12736: if (ref($newdirlistref) eq 'ARRAY') {
12737: foreach my $dir_line (@{$newdirlistref}) {
12738: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12739: unless ($item =~ /^\.+$/) {
12740: $$count ++;
1.1056 raeburn 12741: @{$dirorder->{$$count}} = @{$hierarchy};
12742: $titles->{$$count} = $item;
1.1055 raeburn 12743: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12744:
1.1055 raeburn 12745: my $is_dir;
12746: if ($dirptr&$testdir) {
12747: $is_dir = 1;
12748: }
12749: if ($wantform) {
12750: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12751: }
12752: if ($is_dir) {
12753: $$depth ++;
1.1056 raeburn 12754: push(@{$hierarchy},$$count);
12755: $parent->{$$depth} = $$count;
1.1055 raeburn 12756: $result .=
12757: &recurse_extracted_archive("$currdir/$item",$docudom,
12758: $docuname,$depth,$count,
1.1056 raeburn 12759: $hierarchy,$dirorder,$children,
12760: $parent,$titles,$wantform);
1.1055 raeburn 12761: $$depth --;
1.1056 raeburn 12762: pop(@{$hierarchy});
1.1055 raeburn 12763: }
12764: }
12765: }
12766: }
12767: return $result;
12768: }
12769:
12770: sub archive_hierarchy {
12771: my ($depth,$count,$parent,$children) =@_;
12772: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12773: if (exists($parent->{$depth})) {
12774: $children->{$parent->{$depth}} .= $count.':';
12775: }
12776: }
12777: return;
12778: }
12779:
12780: sub archive_row {
12781: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12782: my ($name) = ($item =~ m{([^/]+)$});
12783: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12784: 'display' => 'Add as file',
1.1055 raeburn 12785: 'dependency' => 'Include as dependency',
12786: 'discard' => 'Discard',
12787: );
12788: if ($is_dir) {
1.1059 raeburn 12789: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12790: }
1.1056 raeburn 12791: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12792: my $offset = 0;
1.1055 raeburn 12793: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12794: $offset ++;
1.1065 raeburn 12795: if ($action ne 'display') {
12796: $offset ++;
12797: }
1.1055 raeburn 12798: $output .= '<td><span class="LC_nobreak">'.
12799: '<label><input type="radio" name="archive_'.$count.
12800: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12801: my $text = $choices{$action};
12802: if ($is_dir) {
12803: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12804: if ($action eq 'display') {
1.1059 raeburn 12805: $text = &mt('Add as folder');
1.1055 raeburn 12806: }
1.1056 raeburn 12807: } else {
12808: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12809:
12810: }
12811: $output .= ' /> '.$choices{$action}.'</label></span>';
12812: if ($action eq 'dependency') {
12813: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12814: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12815: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12816: '<option value=""></option>'."\n".
12817: '</select>'."\n".
12818: '</div>';
1.1059 raeburn 12819: } elsif ($action eq 'display') {
12820: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12821: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12822: '</div>';
1.1055 raeburn 12823: }
1.1056 raeburn 12824: $output .= '</td>';
1.1055 raeburn 12825: }
12826: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12827: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12828: for (my $i=0; $i<$depth; $i++) {
12829: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12830: }
12831: if ($is_dir) {
12832: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12833: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12834: } else {
12835: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12836: }
12837: $output .= ' '.$name.'</td>'."\n".
12838: &end_data_table_row();
12839: return $output;
12840: }
12841:
12842: sub archive_options_form {
1.1065 raeburn 12843: my ($form,$display,$count,$hiddenelem) = @_;
12844: my %lt = &Apache::lonlocal::texthash(
12845: perm => 'Permanently remove archive file?',
12846: hows => 'How should each extracted item be incorporated in the course?',
12847: cont => 'Content actions for all',
12848: addf => 'Add as folder/file',
12849: incd => 'Include as dependency for a displayed file',
12850: disc => 'Discard',
12851: no => 'No',
12852: yes => 'Yes',
12853: save => 'Save',
12854: );
12855: my $output = <<"END";
12856: <form name="$form" method="post" action="">
12857: <p><span class="LC_nobreak">$lt{'perm'}
12858: <label>
12859: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12860: </label>
12861:
12862: <label>
12863: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12864: </span>
12865: </p>
12866: <input type="hidden" name="phase" value="decompress_cleanup" />
12867: <br />$lt{'hows'}
12868: <div class="LC_columnSection">
12869: <fieldset>
12870: <legend>$lt{'cont'}</legend>
12871: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12872: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12873: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12874: </fieldset>
12875: </div>
12876: END
12877: return $output.
1.1055 raeburn 12878: &start_data_table()."\n".
1.1065 raeburn 12879: $display."\n".
1.1055 raeburn 12880: &end_data_table()."\n".
12881: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12882: $hiddenelem.
1.1065 raeburn 12883: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12884: '</form>';
12885: }
12886:
12887: sub archive_javascript {
1.1056 raeburn 12888: my ($startcount,$numitems,$titles,$children) = @_;
12889: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12890: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12891: my $scripttag = <<START;
12892: <script type="text/javascript">
12893: // <![CDATA[
12894:
12895: function checkAll(form,prefix) {
12896: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12897: for (var i=0; i < form.elements.length; i++) {
12898: var id = form.elements[i].id;
12899: if ((id != '') && (id != undefined)) {
12900: if (idstr.test(id)) {
12901: if (form.elements[i].type == 'radio') {
12902: form.elements[i].checked = true;
1.1056 raeburn 12903: var nostart = i-$startcount;
1.1059 raeburn 12904: var offset = nostart%7;
12905: var count = (nostart-offset)/7;
1.1056 raeburn 12906: dependencyCheck(form,count,offset);
1.1055 raeburn 12907: }
12908: }
12909: }
12910: }
12911: }
12912:
12913: function propagateCheck(form,count) {
12914: if (count > 0) {
1.1059 raeburn 12915: var startelement = $startcount + ((count-1) * 7);
12916: for (var j=1; j<6; j++) {
12917: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12918: var item = startelement + j;
12919: if (form.elements[item].type == 'radio') {
12920: if (form.elements[item].checked) {
12921: containerCheck(form,count,j);
12922: break;
12923: }
1.1055 raeburn 12924: }
12925: }
12926: }
12927: }
12928: }
12929:
12930: numitems = $numitems
1.1056 raeburn 12931: var titles = new Array(numitems);
12932: var parents = new Array(numitems);
1.1055 raeburn 12933: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12934: parents[i] = new Array;
1.1055 raeburn 12935: }
1.1059 raeburn 12936: var maintitle = '$maintitle';
1.1055 raeburn 12937:
12938: START
12939:
1.1056 raeburn 12940: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12941: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12942: for (my $i=0; $i<@contents; $i ++) {
12943: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12944: }
12945: }
12946:
1.1056 raeburn 12947: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12948: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12949: }
12950:
1.1055 raeburn 12951: $scripttag .= <<END;
12952:
12953: function containerCheck(form,count,offset) {
12954: if (count > 0) {
1.1056 raeburn 12955: dependencyCheck(form,count,offset);
1.1059 raeburn 12956: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12957: form.elements[item].checked = true;
12958: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12959: if (parents[count].length > 0) {
12960: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12961: containerCheck(form,parents[count][j],offset);
12962: }
12963: }
12964: }
12965: }
12966: }
12967:
12968: function dependencyCheck(form,count,offset) {
12969: if (count > 0) {
1.1059 raeburn 12970: var chosen = (offset+$startcount)+7*(count-1);
12971: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12972: var currtype = form.elements[depitem].type;
12973: if (form.elements[chosen].value == 'dependency') {
12974: document.getElementById('arc_depon_'+count).style.display='block';
12975: form.elements[depitem].options.length = 0;
12976: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12977: for (var i=1; i<=numitems; i++) {
12978: if (i == count) {
12979: continue;
12980: }
1.1059 raeburn 12981: var startelement = $startcount + (i-1) * 7;
12982: for (var j=1; j<6; j++) {
12983: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12984: var item = startelement + j;
12985: if (form.elements[item].type == 'radio') {
12986: if (form.elements[item].checked) {
12987: if (form.elements[item].value == 'display') {
12988: var n = form.elements[depitem].options.length;
12989: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12990: }
12991: }
12992: }
12993: }
12994: }
12995: }
12996: } else {
12997: document.getElementById('arc_depon_'+count).style.display='none';
12998: form.elements[depitem].options.length = 0;
12999: form.elements[depitem].options[0] = new Option('Select','',true,true);
13000: }
1.1059 raeburn 13001: titleCheck(form,count,offset);
1.1056 raeburn 13002: }
13003: }
13004:
13005: function propagateSelect(form,count,offset) {
13006: if (count > 0) {
1.1065 raeburn 13007: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13008: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13009: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13010: if (parents[count].length > 0) {
13011: for (var j=0; j<parents[count].length; j++) {
13012: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13013: }
13014: }
13015: }
13016: }
13017: }
1.1056 raeburn 13018:
13019: function containerSelect(form,count,offset,picked) {
13020: if (count > 0) {
1.1065 raeburn 13021: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13022: if (form.elements[item].type == 'radio') {
13023: if (form.elements[item].value == 'dependency') {
13024: if (form.elements[item+1].type == 'select-one') {
13025: for (var i=0; i<form.elements[item+1].options.length; i++) {
13026: if (form.elements[item+1].options[i].value == picked) {
13027: form.elements[item+1].selectedIndex = i;
13028: break;
13029: }
13030: }
13031: }
13032: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13033: if (parents[count].length > 0) {
13034: for (var j=0; j<parents[count].length; j++) {
13035: containerSelect(form,parents[count][j],offset,picked);
13036: }
13037: }
13038: }
13039: }
13040: }
13041: }
13042: }
13043:
1.1059 raeburn 13044: function titleCheck(form,count,offset) {
13045: if (count > 0) {
13046: var chosen = (offset+$startcount)+7*(count-1);
13047: var depitem = $startcount + ((count-1) * 7) + 2;
13048: var currtype = form.elements[depitem].type;
13049: if (form.elements[chosen].value == 'display') {
13050: document.getElementById('arc_title_'+count).style.display='block';
13051: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13052: document.getElementById('archive_title_'+count).value=maintitle;
13053: }
13054: } else {
13055: document.getElementById('arc_title_'+count).style.display='none';
13056: if (currtype == 'text') {
13057: document.getElementById('archive_title_'+count).value='';
13058: }
13059: }
13060: }
13061: return;
13062: }
13063:
1.1055 raeburn 13064: // ]]>
13065: </script>
13066: END
13067: return $scripttag;
13068: }
13069:
13070: sub process_extracted_files {
1.1067 raeburn 13071: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13072: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 13073: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13074: my @ids=&Apache::lonnet::current_machine_ids();
13075: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13076: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13077: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13078: if (grep(/^\Q$docuhome\E$/,@ids)) {
13079: $prefix = &LONCAPA::propath($docudom,$docuname);
13080: $pathtocheck = "$dir_root/$destination";
13081: $dir = $dir_root;
13082: $ishome = 1;
13083: } else {
13084: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13085: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 13086: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13087: }
13088: my $currdir = "$dir_root/$destination";
13089: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13090: if ($env{'form.folderpath'}) {
13091: my @items = split('&',$env{'form.folderpath'});
13092: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 13093: if ($env{'form.folderpath'} =~ /\:1$/) {
13094: $containers{'0'}='page';
13095: } else {
13096: $containers{'0'}='sequence';
13097: }
1.1055 raeburn 13098: }
13099: my @archdirs = &get_env_multiple('form.archive_directory');
13100: if ($numitems) {
13101: for (my $i=1; $i<=$numitems; $i++) {
13102: my $path = $env{'form.archive_content_'.$i};
13103: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13104: my $item = $1;
13105: $toplevelitems{$item} = $i;
13106: if (grep(/^\Q$i\E$/,@archdirs)) {
13107: $is_dir{$item} = 1;
13108: }
13109: }
13110: }
13111: }
1.1067 raeburn 13112: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13113: if (keys(%toplevelitems) > 0) {
13114: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13115: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13116: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13117: }
1.1066 raeburn 13118: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13119: if ($numitems) {
13120: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 13121: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13122: my $path = $env{'form.archive_content_'.$i};
13123: if ($path =~ /^\Q$pathtocheck\E/) {
13124: if ($env{'form.archive_'.$i} eq 'discard') {
13125: if ($prefix ne '' && $path ne '') {
13126: if (-e $prefix.$path) {
1.1066 raeburn 13127: if ((@archdirs > 0) &&
13128: (grep(/^\Q$i\E$/,@archdirs))) {
13129: $todeletedir{$prefix.$path} = 1;
13130: } else {
13131: $todelete{$prefix.$path} = 1;
13132: }
1.1055 raeburn 13133: }
13134: }
13135: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13136: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13137: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13138: $docstitle = $env{'form.archive_title_'.$i};
13139: if ($docstitle eq '') {
13140: $docstitle = $title;
13141: }
1.1055 raeburn 13142: $outer = 0;
1.1056 raeburn 13143: if (ref($dirorder{$i}) eq 'ARRAY') {
13144: if (@{$dirorder{$i}} > 0) {
13145: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13146: if ($env{'form.archive_'.$item} eq 'display') {
13147: $outer = $item;
13148: last;
13149: }
13150: }
13151: }
13152: }
13153: my ($errtext,$fatal) =
13154: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13155: '/'.$folders{$outer}.'.'.
13156: $containers{$outer});
13157: next if ($fatal);
13158: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13159: if ($context eq 'coursedocs') {
1.1056 raeburn 13160: $mapinner{$i} = time;
1.1055 raeburn 13161: $folders{$i} = 'default_'.$mapinner{$i};
13162: $containers{$i} = 'sequence';
13163: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13164: $folders{$i}.'.'.$containers{$i};
13165: my $newidx = &LONCAPA::map::getresidx();
13166: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13167: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13168: push(@LONCAPA::map::order,$newidx);
13169: my ($outtext,$errtext) =
13170: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13171: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 13172: '.'.$containers{$outer},1,1);
1.1056 raeburn 13173: $newseqid{$i} = $newidx;
1.1067 raeburn 13174: unless ($errtext) {
1.1075.2.128 raeburn 13175: $result .= '<li>'.&mt('Folder: [_1] added to course',
13176: &HTML::Entities::encode($docstitle,'<>&"'))..
13177: '</li>'."\n";
1.1067 raeburn 13178: }
1.1055 raeburn 13179: }
13180: } else {
13181: if ($context eq 'coursedocs') {
13182: my $newidx=&LONCAPA::map::getresidx();
13183: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13184: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13185: $title;
1.1075.2.167 raeburn 13186: if (($outer !~ /\D/) &&
13187: (($mapinner{$outer} eq 'default') || ($mapinner{$outer} !~ /\D/)) &&
13188: ($newidx !~ /\D/)) {
1.1075.2.128 raeburn 13189: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13190: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 13191: }
1.1075.2.128 raeburn 13192: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13193: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13194: }
13195: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13196: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13197: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13198: unless ($ishome) {
13199: my $fetch = "$newdest{$i}/$title";
13200: $fetch =~ s/^\Q$prefix$dir\E//;
13201: $prompttofetch{$fetch} = 1;
13202: }
13203: }
13204: }
13205: $LONCAPA::map::resources[$newidx]=
13206: $docstitle.':'.$url.':false:normal:res';
13207: push(@LONCAPA::map::order, $newidx);
13208: my ($outtext,$errtext)=
13209: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13210: $docuname.'/'.$folders{$outer}.
13211: '.'.$containers{$outer},1,1);
13212: unless ($errtext) {
13213: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13214: $result .= '<li>'.&mt('File: [_1] added to course',
13215: &HTML::Entities::encode($docstitle,'<>&"')).
13216: '</li>'."\n";
13217: }
1.1067 raeburn 13218: }
1.1075.2.128 raeburn 13219: } else {
13220: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13221: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 13222: }
1.1055 raeburn 13223: }
13224: }
1.1075.2.11 raeburn 13225: }
13226: } else {
1.1075.2.128 raeburn 13227: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13228: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 13229: }
13230: }
13231: for (my $i=1; $i<=$numitems; $i++) {
13232: next unless ($env{'form.archive_'.$i} eq 'dependency');
13233: my $path = $env{'form.archive_content_'.$i};
13234: if ($path =~ /^\Q$pathtocheck\E/) {
13235: my ($title) = ($path =~ m{/([^/]+)$});
13236: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13237: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13238: if (ref($dirorder{$i}) eq 'ARRAY') {
13239: my ($itemidx,$fullpath,$relpath);
13240: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13241: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13242: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 13243: if ($dirorder{$i}->[$j] eq $container) {
13244: $itemidx = $j;
1.1056 raeburn 13245: }
13246: }
1.1075.2.11 raeburn 13247: }
13248: if ($itemidx eq '') {
13249: $itemidx = 0;
13250: }
13251: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13252: if ($mapinner{$referrer{$i}}) {
13253: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13254: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13255: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13256: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13257: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13258: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13259: if (!-e $fullpath) {
13260: mkdir($fullpath,0755);
1.1056 raeburn 13261: }
13262: }
1.1075.2.11 raeburn 13263: } else {
13264: last;
1.1056 raeburn 13265: }
1.1075.2.11 raeburn 13266: }
13267: }
13268: } elsif ($newdest{$referrer{$i}}) {
13269: $fullpath = $newdest{$referrer{$i}};
13270: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13271: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13272: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13273: last;
13274: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13275: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13276: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13277: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13278: if (!-e $fullpath) {
13279: mkdir($fullpath,0755);
1.1056 raeburn 13280: }
13281: }
1.1075.2.11 raeburn 13282: } else {
13283: last;
1.1056 raeburn 13284: }
1.1075.2.11 raeburn 13285: }
13286: }
13287: if ($fullpath ne '') {
13288: if (-e "$prefix$path") {
1.1075.2.128 raeburn 13289: unless (rename("$prefix$path","$fullpath/$title")) {
13290: $warning .= &mt('Failed to rename dependency').'<br />';
13291: }
1.1075.2.11 raeburn 13292: }
13293: if (-e "$fullpath/$title") {
13294: my $showpath;
13295: if ($relpath ne '') {
13296: $showpath = "$relpath/$title";
13297: } else {
13298: $showpath = "/$title";
1.1056 raeburn 13299: }
1.1075.2.128 raeburn 13300: $result .= '<li>'.&mt('[_1] included as a dependency',
13301: &HTML::Entities::encode($showpath,'<>&"')).
13302: '</li>'."\n";
13303: unless ($ishome) {
13304: my $fetch = "$fullpath/$title";
13305: $fetch =~ s/^\Q$prefix$dir\E//;
13306: $prompttofetch{$fetch} = 1;
13307: }
1.1055 raeburn 13308: }
13309: }
13310: }
1.1075.2.11 raeburn 13311: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13312: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 13313: &HTML::Entities::encode($path,'<>&"'),
13314: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13315: '<br />';
1.1055 raeburn 13316: }
13317: } else {
1.1075.2.128 raeburn 13318: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13319: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13320: }
13321: }
13322: if (keys(%todelete)) {
13323: foreach my $key (keys(%todelete)) {
13324: unlink($key);
1.1066 raeburn 13325: }
13326: }
13327: if (keys(%todeletedir)) {
13328: foreach my $key (keys(%todeletedir)) {
13329: rmdir($key);
13330: }
13331: }
13332: foreach my $dir (sort(keys(%is_dir))) {
13333: if (($pathtocheck ne '') && ($dir ne '')) {
13334: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13335: }
13336: }
1.1067 raeburn 13337: if ($result ne '') {
13338: $output .= '<ul>'."\n".
13339: $result."\n".
13340: '</ul>';
13341: }
13342: unless ($ishome) {
13343: my $replicationfail;
13344: foreach my $item (keys(%prompttofetch)) {
13345: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13346: unless ($fetchresult eq 'ok') {
13347: $replicationfail .= '<li>'.$item.'</li>'."\n";
13348: }
13349: }
13350: if ($replicationfail) {
13351: $output .= '<p class="LC_error">'.
13352: &mt('Course home server failed to retrieve:').'<ul>'.
13353: $replicationfail.
13354: '</ul></p>';
13355: }
13356: }
1.1055 raeburn 13357: } else {
13358: $warning = &mt('No items found in archive.');
13359: }
13360: if ($error) {
13361: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13362: $error.'</p>'."\n";
13363: }
13364: if ($warning) {
13365: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13366: }
13367: return $output;
13368: }
13369:
1.1066 raeburn 13370: sub cleanup_empty_dirs {
13371: my ($path) = @_;
13372: if (($path ne '') && (-d $path)) {
13373: if (opendir(my $dirh,$path)) {
13374: my @dircontents = grep(!/^\./,readdir($dirh));
13375: my $numitems = 0;
13376: foreach my $item (@dircontents) {
13377: if (-d "$path/$item") {
1.1075.2.28 raeburn 13378: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13379: if (-e "$path/$item") {
13380: $numitems ++;
13381: }
13382: } else {
13383: $numitems ++;
13384: }
13385: }
13386: if ($numitems == 0) {
13387: rmdir($path);
13388: }
13389: closedir($dirh);
13390: }
13391: }
13392: return;
13393: }
13394:
1.41 ng 13395: =pod
1.45 matthew 13396:
1.1075.2.56 raeburn 13397: =item * &get_folder_hierarchy()
1.1068 raeburn 13398:
13399: Provides hierarchy of names of folders/sub-folders containing the current
13400: item,
13401:
13402: Inputs: 3
13403: - $navmap - navmaps object
13404:
13405: - $map - url for map (either the trigger itself, or map containing
13406: the resource, which is the trigger).
13407:
13408: - $showitem - 1 => show title for map itself; 0 => do not show.
13409:
13410: Outputs: 1 @pathitems - array of folder/subfolder names.
13411:
13412: =cut
13413:
13414: sub get_folder_hierarchy {
13415: my ($navmap,$map,$showitem) = @_;
13416: my @pathitems;
13417: if (ref($navmap)) {
13418: my $mapres = $navmap->getResourceByUrl($map);
13419: if (ref($mapres)) {
13420: my $pcslist = $mapres->map_hierarchy();
13421: if ($pcslist ne '') {
13422: my @pcs = split(/,/,$pcslist);
13423: foreach my $pc (@pcs) {
13424: if ($pc == 1) {
1.1075.2.38 raeburn 13425: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13426: } else {
13427: my $res = $navmap->getByMapPc($pc);
13428: if (ref($res)) {
13429: my $title = $res->compTitle();
13430: $title =~ s/\W+/_/g;
13431: if ($title ne '') {
13432: push(@pathitems,$title);
13433: }
13434: }
13435: }
13436: }
13437: }
1.1071 raeburn 13438: if ($showitem) {
13439: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13440: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13441: } else {
13442: my $maptitle = $mapres->compTitle();
13443: $maptitle =~ s/\W+/_/g;
13444: if ($maptitle ne '') {
13445: push(@pathitems,$maptitle);
13446: }
1.1068 raeburn 13447: }
13448: }
13449: }
13450: }
13451: return @pathitems;
13452: }
13453:
13454: =pod
13455:
1.1015 raeburn 13456: =item * &get_turnedin_filepath()
13457:
13458: Determines path in a user's portfolio file for storage of files uploaded
13459: to a specific essayresponse or dropbox item.
13460:
13461: Inputs: 3 required + 1 optional.
13462: $symb is symb for resource, $uname and $udom are for current user (required).
13463: $caller is optional (can be "submission", if routine is called when storing
13464: an upoaded file when "Submit Answer" button was pressed).
13465:
13466: Returns array containing $path and $multiresp.
13467: $path is path in portfolio. $multiresp is 1 if this resource contains more
13468: than one file upload item. Callers of routine should append partid as a
13469: subdirectory to $path in cases where $multiresp is 1.
13470:
13471: Called by: homework/essayresponse.pm and homework/structuretags.pm
13472:
13473: =cut
13474:
13475: sub get_turnedin_filepath {
13476: my ($symb,$uname,$udom,$caller) = @_;
13477: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13478: my $turnindir;
13479: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13480: $turnindir = $userhash{'turnindir'};
13481: my ($path,$multiresp);
13482: if ($turnindir eq '') {
13483: if ($caller eq 'submission') {
13484: $turnindir = &mt('turned in');
13485: $turnindir =~ s/\W+/_/g;
13486: my %newhash = (
13487: 'turnindir' => $turnindir,
13488: );
13489: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13490: }
13491: }
13492: if ($turnindir ne '') {
13493: $path = '/'.$turnindir.'/';
13494: my ($multipart,$turnin,@pathitems);
13495: my $navmap = Apache::lonnavmaps::navmap->new();
13496: if (defined($navmap)) {
13497: my $mapres = $navmap->getResourceByUrl($map);
13498: if (ref($mapres)) {
13499: my $pcslist = $mapres->map_hierarchy();
13500: if ($pcslist ne '') {
13501: foreach my $pc (split(/,/,$pcslist)) {
13502: my $res = $navmap->getByMapPc($pc);
13503: if (ref($res)) {
13504: my $title = $res->compTitle();
13505: $title =~ s/\W+/_/g;
13506: if ($title ne '') {
1.1075.2.48 raeburn 13507: if (($pc > 1) && (length($title) > 12)) {
13508: $title = substr($title,0,12);
13509: }
1.1015 raeburn 13510: push(@pathitems,$title);
13511: }
13512: }
13513: }
13514: }
13515: my $maptitle = $mapres->compTitle();
13516: $maptitle =~ s/\W+/_/g;
13517: if ($maptitle ne '') {
1.1075.2.48 raeburn 13518: if (length($maptitle) > 12) {
13519: $maptitle = substr($maptitle,0,12);
13520: }
1.1015 raeburn 13521: push(@pathitems,$maptitle);
13522: }
13523: unless ($env{'request.state'} eq 'construct') {
13524: my $res = $navmap->getBySymb($symb);
13525: if (ref($res)) {
13526: my $partlist = $res->parts();
13527: my $totaluploads = 0;
13528: if (ref($partlist) eq 'ARRAY') {
13529: foreach my $part (@{$partlist}) {
13530: my @types = $res->responseType($part);
13531: my @ids = $res->responseIds($part);
13532: for (my $i=0; $i < scalar(@ids); $i++) {
13533: if ($types[$i] eq 'essay') {
13534: my $partid = $part.'_'.$ids[$i];
13535: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13536: $totaluploads ++;
13537: }
13538: }
13539: }
13540: }
13541: if ($totaluploads > 1) {
13542: $multiresp = 1;
13543: }
13544: }
13545: }
13546: }
13547: } else {
13548: return;
13549: }
13550: } else {
13551: return;
13552: }
13553: my $restitle=&Apache::lonnet::gettitle($symb);
13554: $restitle =~ s/\W+/_/g;
13555: if ($restitle eq '') {
13556: $restitle = ($resurl =~ m{/[^/]+$});
13557: if ($restitle eq '') {
13558: $restitle = time;
13559: }
13560: }
1.1075.2.48 raeburn 13561: if (length($restitle) > 12) {
13562: $restitle = substr($restitle,0,12);
13563: }
1.1015 raeburn 13564: push(@pathitems,$restitle);
13565: $path .= join('/',@pathitems);
13566: }
13567: return ($path,$multiresp);
13568: }
13569:
13570: =pod
13571:
1.464 albertel 13572: =back
1.41 ng 13573:
1.112 bowersj2 13574: =head1 CSV Upload/Handling functions
1.38 albertel 13575:
1.41 ng 13576: =over 4
13577:
1.648 raeburn 13578: =item * &upfile_store($r)
1.41 ng 13579:
13580: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13581: needs $env{'form.upfile'}
1.41 ng 13582: returns $datatoken to be put into hidden field
13583:
13584: =cut
1.31 albertel 13585:
13586: sub upfile_store {
13587: my $r=shift;
1.258 albertel 13588: $env{'form.upfile'}=~s/\r/\n/gs;
13589: $env{'form.upfile'}=~s/\f/\n/gs;
13590: $env{'form.upfile'}=~s/\n+/\n/gs;
13591: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13592:
1.1075.2.128 raeburn 13593: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13594: '_enroll_'.$env{'request.course.id'}.'_'.
13595: time.'_'.$$);
13596: return if ($datatoken eq '');
13597:
1.31 albertel 13598: {
1.158 raeburn 13599: my $datafile = $r->dir_config('lonDaemons').
13600: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13601: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13602: print $fh $env{'form.upfile'};
1.158 raeburn 13603: close($fh);
13604: }
1.31 albertel 13605: }
13606: return $datatoken;
13607: }
13608:
1.56 matthew 13609: =pod
13610:
1.1075.2.128 raeburn 13611: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13612:
13613: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13614: $datatoken is the name to assign to the temporary file.
1.258 albertel 13615: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13616:
13617: =cut
1.31 albertel 13618:
13619: sub load_tmp_file {
1.1075.2.128 raeburn 13620: my ($r,$datatoken) = @_;
13621: return if ($datatoken eq '');
1.31 albertel 13622: my @studentdata=();
13623: {
1.158 raeburn 13624: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13625: '/tmp/'.$datatoken.'.tmp';
13626: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13627: @studentdata=<$fh>;
13628: close($fh);
13629: }
1.31 albertel 13630: }
1.258 albertel 13631: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13632: }
13633:
1.1075.2.128 raeburn 13634: sub valid_datatoken {
13635: my ($datatoken) = @_;
1.1075.2.131 raeburn 13636: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13637: return $datatoken;
13638: }
13639: return;
13640: }
13641:
1.56 matthew 13642: =pod
13643:
1.648 raeburn 13644: =item * &upfile_record_sep()
1.41 ng 13645:
13646: Separate uploaded file into records
13647: returns array of records,
1.258 albertel 13648: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13649:
13650: =cut
1.31 albertel 13651:
13652: sub upfile_record_sep {
1.258 albertel 13653: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13654: } else {
1.248 albertel 13655: my @records;
1.258 albertel 13656: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13657: if ($line=~/^\s*$/) { next; }
13658: push(@records,$line);
13659: }
13660: return @records;
1.31 albertel 13661: }
13662: }
13663:
1.56 matthew 13664: =pod
13665:
1.648 raeburn 13666: =item * &record_sep($record)
1.41 ng 13667:
1.258 albertel 13668: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13669:
13670: =cut
13671:
1.263 www 13672: sub takeleft {
13673: my $index=shift;
13674: return substr('0000'.$index,-4,4);
13675: }
13676:
1.31 albertel 13677: sub record_sep {
13678: my $record=shift;
13679: my %components=();
1.258 albertel 13680: if ($env{'form.upfiletype'} eq 'xml') {
13681: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13682: my $i=0;
1.356 albertel 13683: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13684: $field=~s/^(\"|\')//;
13685: $field=~s/(\"|\')$//;
1.263 www 13686: $components{&takeleft($i)}=$field;
1.31 albertel 13687: $i++;
13688: }
1.258 albertel 13689: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13690: my $i=0;
1.356 albertel 13691: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13692: $field=~s/^(\"|\')//;
13693: $field=~s/(\"|\')$//;
1.263 www 13694: $components{&takeleft($i)}=$field;
1.31 albertel 13695: $i++;
13696: }
13697: } else {
1.561 www 13698: my $separator=',';
1.480 banghart 13699: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13700: $separator=';';
1.480 banghart 13701: }
1.31 albertel 13702: my $i=0;
1.561 www 13703: # the character we are looking for to indicate the end of a quote or a record
13704: my $looking_for=$separator;
13705: # do not add the characters to the fields
13706: my $ignore=0;
13707: # we just encountered a separator (or the beginning of the record)
13708: my $just_found_separator=1;
13709: # store the field we are working on here
13710: my $field='';
13711: # work our way through all characters in record
13712: foreach my $character ($record=~/(.)/g) {
13713: if ($character eq $looking_for) {
13714: if ($character ne $separator) {
13715: # Found the end of a quote, again looking for separator
13716: $looking_for=$separator;
13717: $ignore=1;
13718: } else {
13719: # Found a separator, store away what we got
13720: $components{&takeleft($i)}=$field;
13721: $i++;
13722: $just_found_separator=1;
13723: $ignore=0;
13724: $field='';
13725: }
13726: next;
13727: }
13728: # single or double quotation marks after a separator indicate beginning of a quote
13729: # we are now looking for the end of the quote and need to ignore separators
13730: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13731: $looking_for=$character;
13732: next;
13733: }
13734: # ignore would be true after we reached the end of a quote
13735: if ($ignore) { next; }
13736: if (($just_found_separator) && ($character=~/\s/)) { next; }
13737: $field.=$character;
13738: $just_found_separator=0;
1.31 albertel 13739: }
1.561 www 13740: # catch the very last entry, since we never encountered the separator
13741: $components{&takeleft($i)}=$field;
1.31 albertel 13742: }
13743: return %components;
13744: }
13745:
1.144 matthew 13746: ######################################################
13747: ######################################################
13748:
1.56 matthew 13749: =pod
13750:
1.648 raeburn 13751: =item * &upfile_select_html()
1.41 ng 13752:
1.144 matthew 13753: Return HTML code to select a file from the users machine and specify
13754: the file type.
1.41 ng 13755:
13756: =cut
13757:
1.144 matthew 13758: ######################################################
13759: ######################################################
1.31 albertel 13760: sub upfile_select_html {
1.144 matthew 13761: my %Types = (
13762: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13763: semisv => &mt('Semicolon separated values'),
1.144 matthew 13764: space => &mt('Space separated'),
13765: tab => &mt('Tabulator separated'),
13766: # xml => &mt('HTML/XML'),
13767: );
13768: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13769: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13770: foreach my $type (sort(keys(%Types))) {
13771: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13772: }
13773: $Str .= "</select>\n";
13774: return $Str;
1.31 albertel 13775: }
13776:
1.301 albertel 13777: sub get_samples {
13778: my ($records,$toget) = @_;
13779: my @samples=({});
13780: my $got=0;
13781: foreach my $rec (@$records) {
13782: my %temp = &record_sep($rec);
13783: if (! grep(/\S/, values(%temp))) { next; }
13784: if (%temp) {
13785: $samples[$got]=\%temp;
13786: $got++;
13787: if ($got == $toget) { last; }
13788: }
13789: }
13790: return \@samples;
13791: }
13792:
1.144 matthew 13793: ######################################################
13794: ######################################################
13795:
1.56 matthew 13796: =pod
13797:
1.648 raeburn 13798: =item * &csv_print_samples($r,$records)
1.41 ng 13799:
13800: Prints a table of sample values from each column uploaded $r is an
13801: Apache Request ref, $records is an arrayref from
13802: &Apache::loncommon::upfile_record_sep
13803:
13804: =cut
13805:
1.144 matthew 13806: ######################################################
13807: ######################################################
1.31 albertel 13808: sub csv_print_samples {
13809: my ($r,$records) = @_;
1.662 bisitz 13810: my $samples = &get_samples($records,5);
1.301 albertel 13811:
1.594 raeburn 13812: $r->print(&mt('Samples').'<br />'.&start_data_table().
13813: &start_data_table_header_row());
1.356 albertel 13814: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13815: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13816: $r->print(&end_data_table_header_row());
1.301 albertel 13817: foreach my $hash (@$samples) {
1.594 raeburn 13818: $r->print(&start_data_table_row());
1.356 albertel 13819: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13820: $r->print('<td>');
1.356 albertel 13821: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13822: $r->print('</td>');
13823: }
1.594 raeburn 13824: $r->print(&end_data_table_row());
1.31 albertel 13825: }
1.594 raeburn 13826: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13827: }
13828:
1.144 matthew 13829: ######################################################
13830: ######################################################
13831:
1.56 matthew 13832: =pod
13833:
1.648 raeburn 13834: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13835:
13836: Prints a table to create associations between values and table columns.
1.144 matthew 13837:
1.41 ng 13838: $r is an Apache Request ref,
13839: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13840: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13841:
13842: =cut
13843:
1.144 matthew 13844: ######################################################
13845: ######################################################
1.31 albertel 13846: sub csv_print_select_table {
13847: my ($r,$records,$d) = @_;
1.301 albertel 13848: my $i=0;
13849: my $samples = &get_samples($records,1);
1.144 matthew 13850: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13851: &start_data_table().&start_data_table_header_row().
1.144 matthew 13852: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13853: '<th>'.&mt('Column').'</th>'.
13854: &end_data_table_header_row()."\n");
1.356 albertel 13855: foreach my $array_ref (@$d) {
13856: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13857: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13858:
1.875 bisitz 13859: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13860: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13861: $r->print('<option value="none"></option>');
1.356 albertel 13862: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13863: $r->print('<option value="'.$sample.'"'.
13864: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13865: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13866: }
1.594 raeburn 13867: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13868: $i++;
13869: }
1.594 raeburn 13870: $r->print(&end_data_table());
1.31 albertel 13871: $i--;
13872: return $i;
13873: }
1.56 matthew 13874:
1.144 matthew 13875: ######################################################
13876: ######################################################
13877:
1.56 matthew 13878: =pod
1.31 albertel 13879:
1.648 raeburn 13880: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13881:
13882: Prints a table of sample values from the upload and can make associate samples to internal names.
13883:
13884: $r is an Apache Request ref,
13885: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13886: $d is an array of 2 element arrays (internal name, displayed name)
13887:
13888: =cut
13889:
1.144 matthew 13890: ######################################################
13891: ######################################################
1.31 albertel 13892: sub csv_samples_select_table {
13893: my ($r,$records,$d) = @_;
13894: my $i=0;
1.144 matthew 13895: #
1.662 bisitz 13896: my $max_samples = 5;
13897: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13898: $r->print(&start_data_table().
13899: &start_data_table_header_row().'<th>'.
13900: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13901: &end_data_table_header_row());
1.301 albertel 13902:
13903: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13904: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13905: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13906: foreach my $option (@$d) {
13907: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13908: $r->print('<option value="'.$value.'"'.
1.253 albertel 13909: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13910: $display.'</option>');
1.31 albertel 13911: }
13912: $r->print('</select></td><td>');
1.662 bisitz 13913: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13914: if (defined($samples->[$line]{$key})) {
13915: $r->print($samples->[$line]{$key}."<br />\n");
13916: }
13917: }
1.594 raeburn 13918: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13919: $i++;
13920: }
1.594 raeburn 13921: $r->print(&end_data_table());
1.31 albertel 13922: $i--;
13923: return($i);
1.115 matthew 13924: }
13925:
1.144 matthew 13926: ######################################################
13927: ######################################################
13928:
1.115 matthew 13929: =pod
13930:
1.648 raeburn 13931: =item * &clean_excel_name($name)
1.115 matthew 13932:
13933: Returns a replacement for $name which does not contain any illegal characters.
13934:
13935: =cut
13936:
1.144 matthew 13937: ######################################################
13938: ######################################################
1.115 matthew 13939: sub clean_excel_name {
13940: my ($name) = @_;
13941: $name =~ s/[:\*\?\/\\]//g;
13942: if (length($name) > 31) {
13943: $name = substr($name,0,31);
13944: }
13945: return $name;
1.25 albertel 13946: }
1.84 albertel 13947:
1.85 albertel 13948: =pod
13949:
1.648 raeburn 13950: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13951:
13952: Returns either 1 or undef
13953:
13954: 1 if the part is to be hidden, undef if it is to be shown
13955:
13956: Arguments are:
13957:
13958: $id the id of the part to be checked
13959: $symb, optional the symb of the resource to check
13960: $udom, optional the domain of the user to check for
13961: $uname, optional the username of the user to check for
13962:
13963: =cut
1.84 albertel 13964:
13965: sub check_if_partid_hidden {
13966: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13967: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13968: $symb,$udom,$uname);
1.141 albertel 13969: my $truth=1;
13970: #if the string starts with !, then the list is the list to show not hide
13971: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13972: my @hiddenlist=split(/,/,$hiddenparts);
13973: foreach my $checkid (@hiddenlist) {
1.141 albertel 13974: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13975: }
1.141 albertel 13976: return !$truth;
1.84 albertel 13977: }
1.127 matthew 13978:
1.138 matthew 13979:
13980: ############################################################
13981: ############################################################
13982:
13983: =pod
13984:
1.157 matthew 13985: =back
13986:
1.138 matthew 13987: =head1 cgi-bin script and graphing routines
13988:
1.157 matthew 13989: =over 4
13990:
1.648 raeburn 13991: =item * &get_cgi_id()
1.138 matthew 13992:
13993: Inputs: none
13994:
13995: Returns an id which can be used to pass environment variables
13996: to various cgi-bin scripts. These environment variables will
13997: be removed from the users environment after a given time by
13998: the routine &Apache::lonnet::transfer_profile_to_env.
13999:
14000: =cut
14001:
14002: ############################################################
14003: ############################################################
1.152 albertel 14004: my $uniq=0;
1.136 matthew 14005: sub get_cgi_id {
1.154 albertel 14006: $uniq=($uniq+1)%100000;
1.280 albertel 14007: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14008: }
14009:
1.127 matthew 14010: ############################################################
14011: ############################################################
14012:
14013: =pod
14014:
1.648 raeburn 14015: =item * &DrawBarGraph()
1.127 matthew 14016:
1.138 matthew 14017: Facilitates the plotting of data in a (stacked) bar graph.
14018: Puts plot definition data into the users environment in order for
14019: graph.png to plot it. Returns an <img> tag for the plot.
14020: The bars on the plot are labeled '1','2',...,'n'.
14021:
14022: Inputs:
14023:
14024: =over 4
14025:
14026: =item $Title: string, the title of the plot
14027:
14028: =item $xlabel: string, text describing the X-axis of the plot
14029:
14030: =item $ylabel: string, text describing the Y-axis of the plot
14031:
14032: =item $Max: scalar, the maximum Y value to use in the plot
14033: If $Max is < any data point, the graph will not be rendered.
14034:
1.140 matthew 14035: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14036: they are plotted. If undefined, default values will be used.
14037:
1.178 matthew 14038: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14039:
1.138 matthew 14040: =item @Values: An array of array references. Each array reference holds data
14041: to be plotted in a stacked bar chart.
14042:
1.239 matthew 14043: =item If the final element of @Values is a hash reference the key/value
14044: pairs will be added to the graph definition.
14045:
1.138 matthew 14046: =back
14047:
14048: Returns:
14049:
14050: An <img> tag which references graph.png and the appropriate identifying
14051: information for the plot.
14052:
1.127 matthew 14053: =cut
14054:
14055: ############################################################
14056: ############################################################
1.134 matthew 14057: sub DrawBarGraph {
1.178 matthew 14058: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14059: #
14060: if (! defined($colors)) {
14061: $colors = ['#33ff00',
14062: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14063: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14064: ];
14065: }
1.228 matthew 14066: my $extra_settings = {};
14067: if (ref($Values[-1]) eq 'HASH') {
14068: $extra_settings = pop(@Values);
14069: }
1.127 matthew 14070: #
1.136 matthew 14071: my $identifier = &get_cgi_id();
14072: my $id = 'cgi.'.$identifier;
1.129 matthew 14073: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14074: return '';
14075: }
1.225 matthew 14076: #
14077: my @Labels;
14078: if (defined($labels)) {
14079: @Labels = @$labels;
14080: } else {
14081: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 14082: push(@Labels,$i+1);
1.225 matthew 14083: }
14084: }
14085: #
1.129 matthew 14086: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14087: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14088: my %ValuesHash;
14089: my $NumSets=1;
14090: foreach my $array (@Values) {
14091: next if (! ref($array));
1.136 matthew 14092: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14093: join(',',@$array);
1.129 matthew 14094: }
1.127 matthew 14095: #
1.136 matthew 14096: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14097: if ($NumBars < 3) {
14098: $width = 120+$NumBars*32;
1.220 matthew 14099: $xskip = 1;
1.225 matthew 14100: $bar_width = 30;
14101: } elsif ($NumBars < 5) {
14102: $width = 120+$NumBars*20;
14103: $xskip = 1;
14104: $bar_width = 20;
1.220 matthew 14105: } elsif ($NumBars < 10) {
1.136 matthew 14106: $width = 120+$NumBars*15;
14107: $xskip = 1;
14108: $bar_width = 15;
14109: } elsif ($NumBars <= 25) {
14110: $width = 120+$NumBars*11;
14111: $xskip = 5;
14112: $bar_width = 8;
14113: } elsif ($NumBars <= 50) {
14114: $width = 120+$NumBars*8;
14115: $xskip = 5;
14116: $bar_width = 4;
14117: } else {
14118: $width = 120+$NumBars*8;
14119: $xskip = 5;
14120: $bar_width = 4;
14121: }
14122: #
1.137 matthew 14123: $Max = 1 if ($Max < 1);
14124: if ( int($Max) < $Max ) {
14125: $Max++;
14126: $Max = int($Max);
14127: }
1.127 matthew 14128: $Title = '' if (! defined($Title));
14129: $xlabel = '' if (! defined($xlabel));
14130: $ylabel = '' if (! defined($ylabel));
1.369 www 14131: $ValuesHash{$id.'.title'} = &escape($Title);
14132: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14133: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14134: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14135: $ValuesHash{$id.'.NumBars'} = $NumBars;
14136: $ValuesHash{$id.'.NumSets'} = $NumSets;
14137: $ValuesHash{$id.'.PlotType'} = 'bar';
14138: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14139: $ValuesHash{$id.'.height'} = $height;
14140: $ValuesHash{$id.'.width'} = $width;
14141: $ValuesHash{$id.'.xskip'} = $xskip;
14142: $ValuesHash{$id.'.bar_width'} = $bar_width;
14143: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14144: #
1.228 matthew 14145: # Deal with other parameters
14146: while (my ($key,$value) = each(%$extra_settings)) {
14147: $ValuesHash{$id.'.'.$key} = $value;
14148: }
14149: #
1.646 raeburn 14150: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14151: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14152: }
14153:
14154: ############################################################
14155: ############################################################
14156:
14157: =pod
14158:
1.648 raeburn 14159: =item * &DrawXYGraph()
1.137 matthew 14160:
1.138 matthew 14161: Facilitates the plotting of data in an XY graph.
14162: Puts plot definition data into the users environment in order for
14163: graph.png to plot it. Returns an <img> tag for the plot.
14164:
14165: Inputs:
14166:
14167: =over 4
14168:
14169: =item $Title: string, the title of the plot
14170:
14171: =item $xlabel: string, text describing the X-axis of the plot
14172:
14173: =item $ylabel: string, text describing the Y-axis of the plot
14174:
14175: =item $Max: scalar, the maximum Y value to use in the plot
14176: If $Max is < any data point, the graph will not be rendered.
14177:
14178: =item $colors: Array ref containing the hex color codes for the data to be
14179: plotted in. If undefined, default values will be used.
14180:
14181: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14182:
14183: =item $Ydata: Array ref containing Array refs.
1.185 www 14184: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14185:
14186: =item %Values: hash indicating or overriding any default values which are
14187: passed to graph.png.
14188: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14189:
14190: =back
14191:
14192: Returns:
14193:
14194: An <img> tag which references graph.png and the appropriate identifying
14195: information for the plot.
14196:
1.137 matthew 14197: =cut
14198:
14199: ############################################################
14200: ############################################################
14201: sub DrawXYGraph {
14202: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14203: #
14204: # Create the identifier for the graph
14205: my $identifier = &get_cgi_id();
14206: my $id = 'cgi.'.$identifier;
14207: #
14208: $Title = '' if (! defined($Title));
14209: $xlabel = '' if (! defined($xlabel));
14210: $ylabel = '' if (! defined($ylabel));
14211: my %ValuesHash =
14212: (
1.369 www 14213: $id.'.title' => &escape($Title),
14214: $id.'.xlabel' => &escape($xlabel),
14215: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14216: $id.'.y_max_value'=> $Max,
14217: $id.'.labels' => join(',',@$Xlabels),
14218: $id.'.PlotType' => 'XY',
14219: );
14220: #
14221: if (defined($colors) && ref($colors) eq 'ARRAY') {
14222: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14223: }
14224: #
14225: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14226: return '';
14227: }
14228: my $NumSets=1;
1.138 matthew 14229: foreach my $array (@{$Ydata}){
1.137 matthew 14230: next if (! ref($array));
14231: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14232: }
1.138 matthew 14233: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14234: #
14235: # Deal with other parameters
14236: while (my ($key,$value) = each(%Values)) {
14237: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14238: }
14239: #
1.646 raeburn 14240: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14241: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14242: }
14243:
14244: ############################################################
14245: ############################################################
14246:
14247: =pod
14248:
1.648 raeburn 14249: =item * &DrawXYYGraph()
1.138 matthew 14250:
14251: Facilitates the plotting of data in an XY graph with two Y axes.
14252: Puts plot definition data into the users environment in order for
14253: graph.png to plot it. Returns an <img> tag for the plot.
14254:
14255: Inputs:
14256:
14257: =over 4
14258:
14259: =item $Title: string, the title of the plot
14260:
14261: =item $xlabel: string, text describing the X-axis of the plot
14262:
14263: =item $ylabel: string, text describing the Y-axis of the plot
14264:
14265: =item $colors: Array ref containing the hex color codes for the data to be
14266: plotted in. If undefined, default values will be used.
14267:
14268: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14269:
14270: =item $Ydata1: The first data set
14271:
14272: =item $Min1: The minimum value of the left Y-axis
14273:
14274: =item $Max1: The maximum value of the left Y-axis
14275:
14276: =item $Ydata2: The second data set
14277:
14278: =item $Min2: The minimum value of the right Y-axis
14279:
14280: =item $Max2: The maximum value of the left Y-axis
14281:
14282: =item %Values: hash indicating or overriding any default values which are
14283: passed to graph.png.
14284: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14285:
14286: =back
14287:
14288: Returns:
14289:
14290: An <img> tag which references graph.png and the appropriate identifying
14291: information for the plot.
1.136 matthew 14292:
14293: =cut
14294:
14295: ############################################################
14296: ############################################################
1.137 matthew 14297: sub DrawXYYGraph {
14298: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14299: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14300: #
14301: # Create the identifier for the graph
14302: my $identifier = &get_cgi_id();
14303: my $id = 'cgi.'.$identifier;
14304: #
14305: $Title = '' if (! defined($Title));
14306: $xlabel = '' if (! defined($xlabel));
14307: $ylabel = '' if (! defined($ylabel));
14308: my %ValuesHash =
14309: (
1.369 www 14310: $id.'.title' => &escape($Title),
14311: $id.'.xlabel' => &escape($xlabel),
14312: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14313: $id.'.labels' => join(',',@$Xlabels),
14314: $id.'.PlotType' => 'XY',
14315: $id.'.NumSets' => 2,
1.137 matthew 14316: $id.'.two_axes' => 1,
14317: $id.'.y1_max_value' => $Max1,
14318: $id.'.y1_min_value' => $Min1,
14319: $id.'.y2_max_value' => $Max2,
14320: $id.'.y2_min_value' => $Min2,
1.136 matthew 14321: );
14322: #
1.137 matthew 14323: if (defined($colors) && ref($colors) eq 'ARRAY') {
14324: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14325: }
14326: #
14327: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14328: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14329: return '';
14330: }
14331: my $NumSets=1;
1.137 matthew 14332: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14333: next if (! ref($array));
14334: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14335: }
14336: #
14337: # Deal with other parameters
14338: while (my ($key,$value) = each(%Values)) {
14339: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14340: }
14341: #
1.646 raeburn 14342: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14343: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14344: }
14345:
14346: ############################################################
14347: ############################################################
14348:
14349: =pod
14350:
1.157 matthew 14351: =back
14352:
1.139 matthew 14353: =head1 Statistics helper routines?
14354:
14355: Bad place for them but what the hell.
14356:
1.157 matthew 14357: =over 4
14358:
1.648 raeburn 14359: =item * &chartlink()
1.139 matthew 14360:
14361: Returns a link to the chart for a specific student.
14362:
14363: Inputs:
14364:
14365: =over 4
14366:
14367: =item $linktext: The text of the link
14368:
14369: =item $sname: The students username
14370:
14371: =item $sdomain: The students domain
14372:
14373: =back
14374:
1.157 matthew 14375: =back
14376:
1.139 matthew 14377: =cut
14378:
14379: ############################################################
14380: ############################################################
14381: sub chartlink {
14382: my ($linktext, $sname, $sdomain) = @_;
14383: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14384: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14385: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14386: '">'.$linktext.'</a>';
1.153 matthew 14387: }
14388:
14389: #######################################################
14390: #######################################################
14391:
14392: =pod
14393:
14394: =head1 Course Environment Routines
1.157 matthew 14395:
14396: =over 4
1.153 matthew 14397:
1.648 raeburn 14398: =item * &restore_course_settings()
1.153 matthew 14399:
1.648 raeburn 14400: =item * &store_course_settings()
1.153 matthew 14401:
14402: Restores/Store indicated form parameters from the course environment.
14403: Will not overwrite existing values of the form parameters.
14404:
14405: Inputs:
14406: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14407:
14408: a hash ref describing the data to be stored. For example:
14409:
14410: %Save_Parameters = ('Status' => 'scalar',
14411: 'chartoutputmode' => 'scalar',
14412: 'chartoutputdata' => 'scalar',
14413: 'Section' => 'array',
1.373 raeburn 14414: 'Group' => 'array',
1.153 matthew 14415: 'StudentData' => 'array',
14416: 'Maps' => 'array');
14417:
14418: Returns: both routines return nothing
14419:
1.631 raeburn 14420: =back
14421:
1.153 matthew 14422: =cut
14423:
14424: #######################################################
14425: #######################################################
14426: sub store_course_settings {
1.496 albertel 14427: return &store_settings($env{'request.course.id'},@_);
14428: }
14429:
14430: sub store_settings {
1.153 matthew 14431: # save to the environment
14432: # appenv the same items, just to be safe
1.300 albertel 14433: my $udom = $env{'user.domain'};
14434: my $uname = $env{'user.name'};
1.496 albertel 14435: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14436: my %SaveHash;
14437: my %AppHash;
14438: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14439: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14440: my $envname = 'environment.'.$basename;
1.258 albertel 14441: if (exists($env{'form.'.$setting})) {
1.153 matthew 14442: # Save this value away
14443: if ($type eq 'scalar' &&
1.258 albertel 14444: (! exists($env{$envname}) ||
14445: $env{$envname} ne $env{'form.'.$setting})) {
14446: $SaveHash{$basename} = $env{'form.'.$setting};
14447: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14448: } elsif ($type eq 'array') {
14449: my $stored_form;
1.258 albertel 14450: if (ref($env{'form.'.$setting})) {
1.153 matthew 14451: $stored_form = join(',',
14452: map {
1.369 www 14453: &escape($_);
1.258 albertel 14454: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14455: } else {
14456: $stored_form =
1.369 www 14457: &escape($env{'form.'.$setting});
1.153 matthew 14458: }
14459: # Determine if the array contents are the same.
1.258 albertel 14460: if ($stored_form ne $env{$envname}) {
1.153 matthew 14461: $SaveHash{$basename} = $stored_form;
14462: $AppHash{$envname} = $stored_form;
14463: }
14464: }
14465: }
14466: }
14467: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14468: $udom,$uname);
1.153 matthew 14469: if ($put_result !~ /^(ok|delayed)/) {
14470: &Apache::lonnet::logthis('unable to save form parameters, '.
14471: 'got error:'.$put_result);
14472: }
14473: # Make sure these settings stick around in this session, too
1.646 raeburn 14474: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14475: return;
14476: }
14477:
14478: sub restore_course_settings {
1.499 albertel 14479: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14480: }
14481:
14482: sub restore_settings {
14483: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14484: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14485: next if (exists($env{'form.'.$setting}));
1.496 albertel 14486: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14487: '.'.$setting;
1.258 albertel 14488: if (exists($env{$envname})) {
1.153 matthew 14489: if ($type eq 'scalar') {
1.258 albertel 14490: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14491: } elsif ($type eq 'array') {
1.258 albertel 14492: $env{'form.'.$setting} = [
1.153 matthew 14493: map {
1.369 www 14494: &unescape($_);
1.258 albertel 14495: } split(',',$env{$envname})
1.153 matthew 14496: ];
14497: }
14498: }
14499: }
1.127 matthew 14500: }
14501:
1.618 raeburn 14502: #######################################################
14503: #######################################################
14504:
14505: =pod
14506:
14507: =head1 Domain E-mail Routines
14508:
14509: =over 4
14510:
1.648 raeburn 14511: =item * &build_recipient_list()
1.618 raeburn 14512:
1.1075.2.44 raeburn 14513: Build recipient lists for following types of e-mail:
1.766 raeburn 14514: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14515: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14516: module change checking, student/employee ID conflict checks, as
14517: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14518: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14519:
14520: Inputs:
1.1075.2.44 raeburn 14521: defmail (scalar - email address of default recipient),
14522: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14523: requestsmail, updatesmail, or idconflictsmail).
14524:
1.619 raeburn 14525: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14526:
14527: origmail (scalar - email address of recipient from loncapa.conf,
14528: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14529:
1.1075.2.139 raeburn 14530: $requname username of requester (if mailing type is helpdeskmail)
14531:
14532: $requdom domain of requester (if mailing type is helpdeskmail)
14533:
14534: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14535:
1.655 raeburn 14536: Returns: comma separated list of addresses to which to send e-mail.
14537:
14538: =back
1.618 raeburn 14539:
14540: =cut
14541:
14542: ############################################################
14543: ############################################################
14544: sub build_recipient_list {
1.1075.2.139 raeburn 14545: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14546: my @recipients;
1.1075.2.122 raeburn 14547: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14548: my %domconfig =
1.1075.2.122 raeburn 14549: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14550: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14551: if (exists($domconfig{'contacts'}{$mailing})) {
14552: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14553: my @contacts = ('adminemail','supportemail');
14554: foreach my $item (@contacts) {
14555: if ($domconfig{'contacts'}{$mailing}{$item}) {
14556: my $addr = $domconfig{'contacts'}{$item};
14557: if (!grep(/^\Q$addr\E$/,@recipients)) {
14558: push(@recipients,$addr);
14559: }
1.619 raeburn 14560: }
1.1075.2.122 raeburn 14561: }
14562: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14563: if ($mailing eq 'helpdeskmail') {
14564: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14565: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14566: my @ok_bccs;
14567: foreach my $bcc (@bccs) {
14568: $bcc =~ s/^\s+//g;
14569: $bcc =~ s/\s+$//g;
14570: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14571: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14572: push(@ok_bccs,$bcc);
14573: }
14574: }
14575: }
14576: if (@ok_bccs > 0) {
14577: $allbcc = join(', ',@ok_bccs);
14578: }
14579: }
14580: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14581: }
14582: }
1.766 raeburn 14583: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14584: $lastresort = $origmail;
1.618 raeburn 14585: }
1.1075.2.139 raeburn 14586: if ($mailing eq 'helpdeskmail') {
14587: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14588: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14589: my ($inststatus,$inststatus_checked);
14590: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14591: ($env{'user.domain'} ne 'public')) {
14592: $inststatus_checked = 1;
14593: $inststatus = $env{'environment.inststatus'};
14594: }
14595: unless ($inststatus_checked) {
14596: if (($requname ne '') && ($requdom ne '')) {
14597: if (($requname =~ /^$match_username$/) &&
14598: ($requdom =~ /^$match_domain$/) &&
14599: (&Apache::lonnet::domain($requdom))) {
14600: my $requhome = &Apache::lonnet::homeserver($requname,
14601: $requdom);
14602: unless ($requhome eq 'no_host') {
14603: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14604: $inststatus = $userenv{'inststatus'};
14605: $inststatus_checked = 1;
14606: }
14607: }
14608: }
14609: }
14610: unless ($inststatus_checked) {
14611: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14612: my %srch = (srchby => 'email',
14613: srchdomain => $defdom,
14614: srchterm => $reqemail,
14615: srchtype => 'exact');
14616: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14617: foreach my $uname (keys(%srch_results)) {
14618: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14619: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14620: $inststatus_checked = 1;
14621: last;
14622: }
14623: }
14624: unless ($inststatus_checked) {
14625: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14626: if ($dirsrchres eq 'ok') {
14627: foreach my $uname (keys(%srch_results)) {
14628: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14629: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14630: $inststatus_checked = 1;
14631: last;
14632: }
14633: }
14634: }
14635: }
14636: }
14637: }
14638: if ($inststatus ne '') {
14639: foreach my $status (split(/\:/,$inststatus)) {
14640: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14641: my @contacts = ('adminemail','supportemail');
14642: foreach my $item (@contacts) {
14643: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14644: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14645: if (!grep(/^\Q$addr\E$/,@recipients)) {
14646: push(@recipients,$addr);
14647: }
14648: }
14649: }
14650: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14651: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14652: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14653: my @ok_bccs;
14654: foreach my $bcc (@bccs) {
14655: $bcc =~ s/^\s+//g;
14656: $bcc =~ s/\s+$//g;
14657: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14658: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14659: push(@ok_bccs,$bcc);
14660: }
14661: }
14662: }
14663: if (@ok_bccs > 0) {
14664: $allbcc = join(', ',@ok_bccs);
14665: }
14666: }
14667: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14668: last;
14669: }
14670: }
14671: }
14672: }
14673: }
1.619 raeburn 14674: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14675: $lastresort = $origmail;
14676: }
1.1075.2.128 raeburn 14677: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14678: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14679: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14680: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14681: my %what = (
14682: perlvar => 1,
14683: );
14684: my $primary = &Apache::lonnet::domain($defdom,'primary');
14685: if ($primary) {
14686: my $gotaddr;
14687: my ($result,$returnhash) =
14688: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14689: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14690: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14691: $lastresort = $returnhash->{'lonSupportEMail'};
14692: $gotaddr = 1;
14693: }
14694: }
14695: unless ($gotaddr) {
14696: my $uintdom = &Apache::lonnet::internet_dom($primary);
14697: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14698: unless ($uintdom eq $intdom) {
14699: my %domconfig =
14700: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14701: if (ref($domconfig{'contacts'}) eq 'HASH') {
14702: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14703: my @contacts = ('adminemail','supportemail');
14704: foreach my $item (@contacts) {
14705: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14706: my $addr = $domconfig{'contacts'}{$item};
14707: if (!grep(/^\Q$addr\E$/,@recipients)) {
14708: push(@recipients,$addr);
14709: }
14710: }
14711: }
14712: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14713: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14714: }
14715: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14716: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14717: my @ok_bccs;
14718: foreach my $bcc (@bccs) {
14719: $bcc =~ s/^\s+//g;
14720: $bcc =~ s/\s+$//g;
14721: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14722: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14723: push(@ok_bccs,$bcc);
14724: }
14725: }
14726: }
14727: if (@ok_bccs > 0) {
14728: $allbcc = join(', ',@ok_bccs);
14729: }
14730: }
14731: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14732: }
14733: }
14734: }
14735: }
14736: }
14737: }
1.618 raeburn 14738: }
1.688 raeburn 14739: if (defined($defmail)) {
14740: if ($defmail ne '') {
14741: push(@recipients,$defmail);
14742: }
1.618 raeburn 14743: }
14744: if ($otheremails) {
1.619 raeburn 14745: my @others;
14746: if ($otheremails =~ /,/) {
14747: @others = split(/,/,$otheremails);
1.618 raeburn 14748: } else {
1.619 raeburn 14749: push(@others,$otheremails);
14750: }
14751: foreach my $addr (@others) {
14752: if (!grep(/^\Q$addr\E$/,@recipients)) {
14753: push(@recipients,$addr);
14754: }
1.618 raeburn 14755: }
14756: }
1.1075.2.128 raeburn 14757: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14758: if ((!@recipients) && ($lastresort ne '')) {
14759: push(@recipients,$lastresort);
14760: }
14761: } elsif ($lastresort ne '') {
14762: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14763: push(@recipients,$lastresort);
14764: }
14765: }
14766: my $recipientlist = join(',',@recipients);
14767: if (wantarray) {
14768: return ($recipientlist,$allbcc,$addtext);
14769: } else {
14770: return $recipientlist;
14771: }
1.618 raeburn 14772: }
14773:
1.127 matthew 14774: ############################################################
14775: ############################################################
1.154 albertel 14776:
1.655 raeburn 14777: =pod
14778:
14779: =head1 Course Catalog Routines
14780:
14781: =over 4
14782:
14783: =item * &gather_categories()
14784:
14785: Converts category definitions - keys of categories hash stored in
14786: coursecategories in configuration.db on the primary library server in a
14787: domain - to an array. Also generates javascript and idx hash used to
14788: generate Domain Coordinator interface for editing Course Categories.
14789:
14790: Inputs:
1.663 raeburn 14791:
1.655 raeburn 14792: categories (reference to hash of category definitions).
1.663 raeburn 14793:
1.655 raeburn 14794: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14795: categories and subcategories).
1.663 raeburn 14796:
1.655 raeburn 14797: idx (reference to hash of counters used in Domain Coordinator interface for
14798: editing Course Categories).
1.663 raeburn 14799:
1.655 raeburn 14800: jsarray (reference to array of categories used to create Javascript arrays for
14801: Domain Coordinator interface for editing Course Categories).
14802:
14803: Returns: nothing
14804:
14805: Side effects: populates cats, idx and jsarray.
14806:
14807: =cut
14808:
14809: sub gather_categories {
14810: my ($categories,$cats,$idx,$jsarray) = @_;
14811: my %counters;
14812: my $num = 0;
14813: foreach my $item (keys(%{$categories})) {
14814: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14815: if ($container eq '' && $depth == 0) {
14816: $cats->[$depth][$categories->{$item}] = $cat;
14817: } else {
14818: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14819: }
14820: my ($escitem,$tail) = split(/:/,$item,2);
14821: if ($counters{$tail} eq '') {
14822: $counters{$tail} = $num;
14823: $num ++;
14824: }
14825: if (ref($idx) eq 'HASH') {
14826: $idx->{$item} = $counters{$tail};
14827: }
14828: if (ref($jsarray) eq 'ARRAY') {
14829: push(@{$jsarray->[$counters{$tail}]},$item);
14830: }
14831: }
14832: return;
14833: }
14834:
14835: =pod
14836:
14837: =item * &extract_categories()
14838:
14839: Used to generate breadcrumb trails for course categories.
14840:
14841: Inputs:
1.663 raeburn 14842:
1.655 raeburn 14843: categories (reference to hash of category definitions).
1.663 raeburn 14844:
1.655 raeburn 14845: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14846: categories and subcategories).
1.663 raeburn 14847:
1.655 raeburn 14848: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14849:
1.655 raeburn 14850: allitems (reference to hash - key is category key
14851: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14852:
1.655 raeburn 14853: idx (reference to hash of counters used in Domain Coordinator interface for
14854: editing Course Categories).
1.663 raeburn 14855:
1.655 raeburn 14856: jsarray (reference to array of categories used to create Javascript arrays for
14857: Domain Coordinator interface for editing Course Categories).
14858:
1.665 raeburn 14859: subcats (reference to hash of arrays containing all subcategories within each
14860: category, -recursive)
14861:
1.1075.2.132 raeburn 14862: maxd (reference to hash used to hold max depth for all top-level categories).
14863:
1.655 raeburn 14864: Returns: nothing
14865:
14866: Side effects: populates trails and allitems hash references.
14867:
14868: =cut
14869:
14870: sub extract_categories {
1.1075.2.132 raeburn 14871: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14872: if (ref($categories) eq 'HASH') {
14873: &gather_categories($categories,$cats,$idx,$jsarray);
14874: if (ref($cats->[0]) eq 'ARRAY') {
14875: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14876: my $name = $cats->[0][$i];
14877: my $item = &escape($name).'::0';
14878: my $trailstr;
14879: if ($name eq 'instcode') {
14880: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14881: } elsif ($name eq 'communities') {
14882: $trailstr = &mt('Communities');
1.655 raeburn 14883: } else {
14884: $trailstr = $name;
14885: }
14886: if ($allitems->{$item} eq '') {
14887: push(@{$trails},$trailstr);
14888: $allitems->{$item} = scalar(@{$trails})-1;
14889: }
14890: my @parents = ($name);
14891: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14892: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14893: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14894: if (ref($subcats) eq 'HASH') {
14895: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14896: }
1.1075.2.132 raeburn 14897: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14898: }
14899: } else {
14900: if (ref($subcats) eq 'HASH') {
14901: $subcats->{$item} = [];
1.655 raeburn 14902: }
1.1075.2.132 raeburn 14903: if (ref($maxd) eq 'HASH') {
14904: $maxd->{$name} = 1;
14905: }
1.655 raeburn 14906: }
14907: }
14908: }
14909: }
14910: return;
14911: }
14912:
14913: =pod
14914:
1.1075.2.56 raeburn 14915: =item * &recurse_categories()
1.655 raeburn 14916:
14917: Recursively used to generate breadcrumb trails for course categories.
14918:
14919: Inputs:
1.663 raeburn 14920:
1.655 raeburn 14921: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14922: categories and subcategories).
1.663 raeburn 14923:
1.655 raeburn 14924: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14925:
14926: category (current course category, for which breadcrumb trail is being generated).
14927:
14928: trails (reference to array of breadcrumb trails for each category).
14929:
1.655 raeburn 14930: allitems (reference to hash - key is category key
14931: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14932:
1.655 raeburn 14933: parents (array containing containers directories for current category,
14934: back to top level).
14935:
14936: Returns: nothing
14937:
14938: Side effects: populates trails and allitems hash references
14939:
14940: =cut
14941:
14942: sub recurse_categories {
1.1075.2.132 raeburn 14943: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14944: my $shallower = $depth - 1;
14945: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14946: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14947: my $name = $cats->[$depth]{$category}[$k];
14948: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.164 raeburn 14949: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14950: if ($allitems->{$item} eq '') {
14951: push(@{$trails},$trailstr);
14952: $allitems->{$item} = scalar(@{$trails})-1;
14953: }
14954: my $deeper = $depth+1;
14955: push(@{$parents},$category);
1.665 raeburn 14956: if (ref($subcats) eq 'HASH') {
14957: my $subcat = &escape($name).':'.$category.':'.$depth;
14958: for (my $j=@{$parents}; $j>=0; $j--) {
14959: my $higher;
14960: if ($j > 0) {
14961: $higher = &escape($parents->[$j]).':'.
14962: &escape($parents->[$j-1]).':'.$j;
14963: } else {
14964: $higher = &escape($parents->[$j]).'::'.$j;
14965: }
14966: push(@{$subcats->{$higher}},$subcat);
14967: }
14968: }
14969: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 14970: $subcats,$maxd);
1.655 raeburn 14971: pop(@{$parents});
14972: }
14973: } else {
14974: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 14975: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14976: if ($allitems->{$item} eq '') {
14977: push(@{$trails},$trailstr);
14978: $allitems->{$item} = scalar(@{$trails})-1;
14979: }
1.1075.2.132 raeburn 14980: if (ref($maxd) eq 'HASH') {
14981: if ($depth > $maxd->{$parents->[0]}) {
14982: $maxd->{$parents->[0]} = $depth;
14983: }
14984: }
1.655 raeburn 14985: }
14986: return;
14987: }
14988:
1.663 raeburn 14989: =pod
14990:
1.1075.2.56 raeburn 14991: =item * &assign_categories_table()
1.663 raeburn 14992:
14993: Create a datatable for display of hierarchical categories in a domain,
14994: with checkboxes to allow a course to be categorized.
14995:
14996: Inputs:
14997:
14998: cathash - reference to hash of categories defined for the domain (from
14999: configuration.db)
15000:
15001: currcat - scalar with an & separated list of categories assigned to a course.
15002:
1.919 raeburn 15003: type - scalar contains course type (Course or Community).
15004:
1.1075.2.117 raeburn 15005: disabled - scalar (optional) contains disabled="disabled" if input elements are
15006: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15007:
1.663 raeburn 15008: Returns: $output (markup to be displayed)
15009:
15010: =cut
15011:
15012: sub assign_categories_table {
1.1075.2.117 raeburn 15013: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15014: my $output;
15015: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 15016: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15017: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15018: $maxdepth = scalar(@cats);
15019: if (@cats > 0) {
15020: my $itemcount = 0;
15021: if (ref($cats[0]) eq 'ARRAY') {
15022: my @currcategories;
15023: if ($currcat ne '') {
15024: @currcategories = split('&',$currcat);
15025: }
1.919 raeburn 15026: my $table;
1.663 raeburn 15027: for (my $i=0; $i<@{$cats[0]}; $i++) {
15028: my $parent = $cats[0][$i];
1.919 raeburn 15029: next if ($parent eq 'instcode');
15030: if ($type eq 'Community') {
15031: next unless ($parent eq 'communities');
15032: } else {
15033: next if ($parent eq 'communities');
15034: }
1.663 raeburn 15035: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15036: my $item = &escape($parent).'::0';
15037: my $checked = '';
15038: if (@currcategories > 0) {
15039: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15040: $checked = ' checked="checked"';
1.663 raeburn 15041: }
15042: }
1.919 raeburn 15043: my $parent_title = $parent;
15044: if ($parent eq 'communities') {
15045: $parent_title = &mt('Communities');
15046: }
15047: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15048: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15049: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15050: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15051: my $depth = 1;
15052: push(@path,$parent);
1.1075.2.117 raeburn 15053: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15054: pop(@path);
1.919 raeburn 15055: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15056: $itemcount ++;
15057: }
1.919 raeburn 15058: if ($itemcount) {
15059: $output = &Apache::loncommon::start_data_table().
15060: $table.
15061: &Apache::loncommon::end_data_table();
15062: }
1.663 raeburn 15063: }
15064: }
15065: }
15066: return $output;
15067: }
15068:
15069: =pod
15070:
1.1075.2.56 raeburn 15071: =item * &assign_category_rows()
1.663 raeburn 15072:
15073: Create a datatable row for display of nested categories in a domain,
15074: with checkboxes to allow a course to be categorized,called recursively.
15075:
15076: Inputs:
15077:
15078: itemcount - track row number for alternating colors
15079:
15080: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15081: categories and subcategories.
15082:
15083: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15084:
15085: parent - parent of current category item
15086:
15087: path - Array containing all categories back up through the hierarchy from the
15088: current category to the top level.
15089:
15090: currcategories - reference to array of current categories assigned to the course
15091:
1.1075.2.117 raeburn 15092: disabled - scalar (optional) contains disabled="disabled" if input elements are
15093: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15094:
1.663 raeburn 15095: Returns: $output (markup to be displayed).
15096:
15097: =cut
15098:
15099: sub assign_category_rows {
1.1075.2.117 raeburn 15100: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15101: my ($text,$name,$item,$chgstr);
15102: if (ref($cats) eq 'ARRAY') {
15103: my $maxdepth = scalar(@{$cats});
15104: if (ref($cats->[$depth]) eq 'HASH') {
15105: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15106: my $numchildren = @{$cats->[$depth]{$parent}};
15107: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 15108: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15109: for (my $j=0; $j<$numchildren; $j++) {
15110: $name = $cats->[$depth]{$parent}[$j];
15111: $item = &escape($name).':'.&escape($parent).':'.$depth;
15112: my $deeper = $depth+1;
15113: my $checked = '';
15114: if (ref($currcategories) eq 'ARRAY') {
15115: if (@{$currcategories} > 0) {
15116: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15117: $checked = ' checked="checked"';
1.663 raeburn 15118: }
15119: }
15120: }
1.664 raeburn 15121: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15122: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15123: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15124: '<input type="hidden" name="catname" value="'.$name.'" />'.
15125: '</td><td>';
1.663 raeburn 15126: if (ref($path) eq 'ARRAY') {
15127: push(@{$path},$name);
1.1075.2.117 raeburn 15128: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15129: pop(@{$path});
15130: }
15131: $text .= '</td></tr>';
15132: }
15133: $text .= '</table></td>';
15134: }
15135: }
15136: }
15137: return $text;
15138: }
15139:
1.1075.2.69 raeburn 15140: =pod
15141:
15142: =back
15143:
15144: =cut
15145:
1.655 raeburn 15146: ############################################################
15147: ############################################################
15148:
15149:
1.443 albertel 15150: sub commit_customrole {
1.664 raeburn 15151: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15152: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15153: ($start?', '.&mt('starting').' '.localtime($start):'').
15154: ($end?', ending '.localtime($end):'').': <b>'.
15155: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15156: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15157: '</b><br />';
15158: return $output;
15159: }
15160:
15161: sub commit_standardrole {
1.1075.2.31 raeburn 15162: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15163: my ($output,$logmsg,$linefeed);
15164: if ($context eq 'auto') {
15165: $linefeed = "\n";
15166: } else {
15167: $linefeed = "<br />\n";
15168: }
1.443 albertel 15169: if ($three eq 'st') {
1.541 raeburn 15170: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 15171: $one,$two,$sec,$context,$credits);
1.541 raeburn 15172: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15173: ($result eq 'unknown_course') || ($result eq 'refused')) {
15174: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15175: } else {
1.541 raeburn 15176: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15177: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15178: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15179: if ($context eq 'auto') {
15180: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15181: } else {
15182: $output .= '<b>'.$result.'</b>'.$linefeed.
15183: &mt('Add to classlist').': <b>ok</b>';
15184: }
15185: $output .= $linefeed;
1.443 albertel 15186: }
15187: } else {
15188: $output = &mt('Assigning').' '.$three.' in '.$url.
15189: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15190: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15191: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15192: if ($context eq 'auto') {
15193: $output .= $result.$linefeed;
15194: } else {
15195: $output .= '<b>'.$result.'</b>'.$linefeed;
15196: }
1.443 albertel 15197: }
15198: return $output;
15199: }
15200:
15201: sub commit_studentrole {
1.1075.2.31 raeburn 15202: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15203: $credits) = @_;
1.626 raeburn 15204: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15205: if ($context eq 'auto') {
15206: $linefeed = "\n";
15207: } else {
15208: $linefeed = '<br />'."\n";
15209: }
1.443 albertel 15210: if (defined($one) && defined($two)) {
15211: my $cid=$one.'_'.$two;
15212: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15213: my $secchange = 0;
15214: my $expire_role_result;
15215: my $modify_section_result;
1.628 raeburn 15216: if ($oldsec ne '-1') {
15217: if ($oldsec ne $sec) {
1.443 albertel 15218: $secchange = 1;
1.628 raeburn 15219: my $now = time;
1.443 albertel 15220: my $uurl='/'.$cid;
15221: $uurl=~s/\_/\//g;
15222: if ($oldsec) {
15223: $uurl.='/'.$oldsec;
15224: }
1.626 raeburn 15225: $oldsecurl = $uurl;
1.628 raeburn 15226: $expire_role_result =
1.1075.2.167 raeburn 15227: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,
15228: '','','',$context);
1.628 raeburn 15229: if ($env{'request.course.sec'} ne '') {
15230: if ($expire_role_result eq 'refused') {
15231: my @roles = ('st');
15232: my @statuses = ('previous');
15233: my @roledoms = ($one);
15234: my $withsec = 1;
15235: my %roleshash =
15236: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15237: \@statuses,\@roles,\@roledoms,$withsec);
15238: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15239: my ($oldstart,$oldend) =
15240: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15241: if ($oldend > 0 && $oldend <= $now) {
15242: $expire_role_result = 'ok';
15243: }
15244: }
15245: }
15246: }
1.443 albertel 15247: $result = $expire_role_result;
15248: }
15249: }
15250: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 15251: $modify_section_result =
15252: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15253: undef,undef,undef,$sec,
15254: $end,$start,'','',$cid,
15255: '',$context,$credits);
1.443 albertel 15256: if ($modify_section_result =~ /^ok/) {
15257: if ($secchange == 1) {
1.628 raeburn 15258: if ($sec eq '') {
15259: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15260: } else {
15261: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15262: }
1.443 albertel 15263: } elsif ($oldsec eq '-1') {
1.628 raeburn 15264: if ($sec eq '') {
15265: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15266: } else {
15267: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15268: }
1.443 albertel 15269: } else {
1.628 raeburn 15270: if ($sec eq '') {
15271: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15272: } else {
15273: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15274: }
1.443 albertel 15275: }
15276: } else {
1.628 raeburn 15277: if ($secchange) {
15278: $$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;
15279: } else {
15280: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15281: }
1.443 albertel 15282: }
15283: $result = $modify_section_result;
15284: } elsif ($secchange == 1) {
1.628 raeburn 15285: if ($oldsec eq '') {
1.1075.2.20 raeburn 15286: $$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 15287: } else {
15288: $$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;
15289: }
1.626 raeburn 15290: if ($expire_role_result eq 'refused') {
15291: my $newsecurl = '/'.$cid;
15292: $newsecurl =~ s/\_/\//g;
15293: if ($sec ne '') {
15294: $newsecurl.='/'.$sec;
15295: }
15296: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15297: if ($sec eq '') {
15298: $$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;
15299: } else {
15300: $$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;
15301: }
15302: }
15303: }
1.443 albertel 15304: }
15305: } else {
1.626 raeburn 15306: $$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 15307: $result = "error: incomplete course id\n";
15308: }
15309: return $result;
15310: }
15311:
1.1075.2.25 raeburn 15312: sub show_role_extent {
15313: my ($scope,$context,$role) = @_;
15314: $scope =~ s{^/}{};
15315: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15316: push(@courseroles,'co');
15317: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15318: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15319: $scope =~ s{/}{_};
15320: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15321: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15322: my ($audom,$auname) = split(/\//,$scope);
15323: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15324: &Apache::loncommon::plainname($auname,$audom).'</span>');
15325: } else {
15326: $scope =~ s{/$}{};
15327: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15328: &Apache::lonnet::domain($scope,'description').'</span>');
15329: }
15330: }
15331:
1.443 albertel 15332: ############################################################
15333: ############################################################
15334:
1.566 albertel 15335: sub check_clone {
1.578 raeburn 15336: my ($args,$linefeed) = @_;
1.566 albertel 15337: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15338: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15339: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15340: my $clonemsg;
15341: my $can_clone = 0;
1.944 raeburn 15342: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15343: if ($lctype ne 'community') {
15344: $lctype = 'course';
15345: }
1.566 albertel 15346: if ($clonehome eq 'no_host') {
1.944 raeburn 15347: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15348: $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'});
15349: } else {
15350: $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'});
15351: }
1.566 albertel 15352: } else {
15353: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15354: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15355: if ($clonedesc{'type'} ne 'Community') {
15356: $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'});
15357: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15358: }
15359: }
1.1075.2.119 raeburn 15360: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15361: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15362: $can_clone = 1;
15363: } else {
1.1075.2.95 raeburn 15364: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15365: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 15366: if ($clonehash{'cloners'} eq '') {
15367: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15368: if ($domdefs{'canclone'}) {
15369: unless ($domdefs{'canclone'} eq 'none') {
15370: if ($domdefs{'canclone'} eq 'domain') {
15371: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15372: $can_clone = 1;
15373: }
15374: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15375: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15376: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15377: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15378: $can_clone = 1;
15379: }
15380: }
15381: }
1.908 raeburn 15382: }
1.1075.2.95 raeburn 15383: } else {
15384: my @cloners = split(/,/,$clonehash{'cloners'});
15385: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15386: $can_clone = 1;
1.1075.2.95 raeburn 15387: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15388: $can_clone = 1;
1.1075.2.96 raeburn 15389: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15390: $can_clone = 1;
1.1075.2.95 raeburn 15391: }
15392: unless ($can_clone) {
1.1075.2.96 raeburn 15393: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15394: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 15395: my (%gotdomdefaults,%gotcodedefaults);
15396: foreach my $cloner (@cloners) {
15397: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15398: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15399: my (%codedefaults,@code_order);
15400: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15401: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15402: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15403: }
15404: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15405: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15406: }
15407: } else {
15408: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15409: \%codedefaults,
15410: \@code_order);
15411: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15412: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15413: }
15414: if (@code_order > 0) {
15415: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15416: $cloner,$clonehash{'internal.coursecode'},
15417: $args->{'crscode'})) {
15418: $can_clone = 1;
15419: last;
15420: }
15421: }
15422: }
15423: }
15424: }
1.1075.2.96 raeburn 15425: }
15426: }
15427: unless ($can_clone) {
15428: my $ccrole = 'cc';
15429: if ($args->{'crstype'} eq 'Community') {
15430: $ccrole = 'co';
15431: }
15432: my %roleshash =
15433: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15434: $args->{'ccdomain'},
15435: 'userroles',['active'],[$ccrole],
15436: [$args->{'clonedomain'}]);
15437: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15438: $can_clone = 1;
15439: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15440: $args->{'ccuname'},$args->{'ccdomain'})) {
15441: $can_clone = 1;
1.1075.2.95 raeburn 15442: }
15443: }
15444: unless ($can_clone) {
15445: if ($args->{'crstype'} eq 'Community') {
15446: $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'});
15447: } else {
15448: $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 15449: }
1.566 albertel 15450: }
1.578 raeburn 15451: }
1.566 albertel 15452: }
15453: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15454: }
15455:
1.444 albertel 15456: sub construct_course {
1.1075.2.119 raeburn 15457: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15458: $cnum,$category,$coderef) = @_;
1.444 albertel 15459: my $outcome;
1.541 raeburn 15460: my $linefeed = '<br />'."\n";
15461: if ($context eq 'auto') {
15462: $linefeed = "\n";
15463: }
1.566 albertel 15464:
15465: #
15466: # Are we cloning?
15467: #
15468: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15469: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15470: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15471: if ($context ne 'auto') {
1.578 raeburn 15472: if ($clonemsg ne '') {
15473: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15474: }
1.566 albertel 15475: }
15476: $outcome .= $clonemsg.$linefeed;
15477:
15478: if (!$can_clone) {
15479: return (0,$outcome);
15480: }
15481: }
15482:
1.444 albertel 15483: #
15484: # Open course
15485: #
15486: my $crstype = lc($args->{'crstype'});
15487: my %cenv=();
15488: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15489: $args->{'cdescr'},
15490: $args->{'curl'},
15491: $args->{'course_home'},
15492: $args->{'nonstandard'},
15493: $args->{'crscode'},
15494: $args->{'ccuname'}.':'.
15495: $args->{'ccdomain'},
1.882 raeburn 15496: $args->{'crstype'},
1.885 raeburn 15497: $cnum,$context,$category);
1.444 albertel 15498:
15499: # Note: The testing routines depend on this being output; see
15500: # Utils::Course. This needs to at least be output as a comment
15501: # if anyone ever decides to not show this, and Utils::Course::new
15502: # will need to be suitably modified.
1.541 raeburn 15503: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 15504: if ($$courseid =~ /^error:/) {
15505: return (0,$outcome);
15506: }
15507:
1.444 albertel 15508: #
15509: # Check if created correctly
15510: #
1.479 albertel 15511: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15512: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15513: if ($crsuhome eq 'no_host') {
15514: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15515: return (0,$outcome);
15516: }
1.541 raeburn 15517: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15518:
1.444 albertel 15519: #
1.566 albertel 15520: # Do the cloning
15521: #
15522: if ($can_clone && $cloneid) {
15523: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
15524: if ($context ne 'auto') {
15525: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15526: }
15527: $outcome .= $clonemsg.$linefeed;
15528: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15529: # Copy all files
1.637 www 15530: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15531: # Restore URL
1.566 albertel 15532: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15533: # Restore title
1.566 albertel 15534: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15535: # Restore creation date, creator and creation context.
15536: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15537: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15538: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15539: # Mark as cloned
1.566 albertel 15540: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15541: # Need to clone grading mode
15542: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15543: $cenv{'grading'}=$newenv{'grading'};
15544: # Do not clone these environment entries
15545: &Apache::lonnet::del('environment',
15546: ['default_enrollment_start_date',
15547: 'default_enrollment_end_date',
15548: 'question.email',
15549: 'policy.email',
15550: 'comment.email',
15551: 'pch.users.denied',
1.725 raeburn 15552: 'plc.users.denied',
15553: 'hidefromcat',
1.1075.2.36 raeburn 15554: 'checkforpriv',
1.1075.2.158 raeburn 15555: 'categories'],
1.638 www 15556: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15557: if ($args->{'textbook'}) {
15558: $cenv{'internal.textbook'} = $args->{'textbook'};
15559: }
1.444 albertel 15560: }
1.566 albertel 15561:
1.444 albertel 15562: #
15563: # Set environment (will override cloned, if existing)
15564: #
15565: my @sections = ();
15566: my @xlists = ();
15567: if ($args->{'crstype'}) {
15568: $cenv{'type'}=$args->{'crstype'};
15569: }
15570: if ($args->{'crsid'}) {
15571: $cenv{'courseid'}=$args->{'crsid'};
15572: }
15573: if ($args->{'crscode'}) {
15574: $cenv{'internal.coursecode'}=$args->{'crscode'};
15575: }
15576: if ($args->{'crsquota'} ne '') {
15577: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15578: } else {
15579: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15580: }
15581: if ($args->{'ccuname'}) {
15582: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15583: ':'.$args->{'ccdomain'};
15584: } else {
15585: $cenv{'internal.courseowner'} = $args->{'curruser'};
15586: }
1.1075.2.31 raeburn 15587: if ($args->{'defaultcredits'}) {
15588: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15589: }
1.444 albertel 15590: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.1075.2.166 raeburn 15591: my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.
1.444 albertel 15592: if ($args->{'crssections'}) {
15593: $cenv{'internal.sectionnums'} = '';
15594: if ($args->{'crssections'} =~ m/,/) {
15595: @sections = split/,/,$args->{'crssections'};
15596: } else {
15597: $sections[0] = $args->{'crssections'};
15598: }
15599: if (@sections > 0) {
15600: foreach my $item (@sections) {
15601: my ($sec,$gp) = split/:/,$item;
15602: my $class = $args->{'crscode'}.$sec;
15603: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15604: $cenv{'internal.sectionnums'} .= $item.',';
1.1075.2.166 raeburn 15605: if ($addcheck eq 'ok') {
15606: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
15607: push(@oklcsecs,$gp);
15608: }
15609: } else {
1.1075.2.119 raeburn 15610: push(@badclasses,$class);
1.444 albertel 15611: }
15612: }
15613: $cenv{'internal.sectionnums'} =~ s/,$//;
15614: }
15615: }
15616: # do not hide course coordinator from staff listing,
15617: # even if privileged
15618: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15619: # add course coordinator's domain to domains to check for privileged users
15620: # if different to course domain
15621: if ($$crsudom ne $args->{'ccdomain'}) {
15622: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15623: }
1.444 albertel 15624: # add crosslistings
15625: if ($args->{'crsxlist'}) {
15626: $cenv{'internal.crosslistings'}='';
15627: if ($args->{'crsxlist'} =~ m/,/) {
15628: @xlists = split/,/,$args->{'crsxlist'};
15629: } else {
15630: $xlists[0] = $args->{'crsxlist'};
15631: }
15632: if (@xlists > 0) {
15633: foreach my $item (@xlists) {
15634: my ($xl,$gp) = split/:/,$item;
15635: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15636: $cenv{'internal.crosslistings'} .= $item.',';
1.1075.2.166 raeburn 15637: if ($addcheck eq 'ok') {
15638: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
15639: push(@oklcsecs,$gp);
15640: }
15641: } else {
1.1075.2.119 raeburn 15642: push(@badclasses,$xl);
1.444 albertel 15643: }
15644: }
15645: $cenv{'internal.crosslistings'} =~ s/,$//;
15646: }
15647: }
15648: if ($args->{'autoadds'}) {
15649: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15650: }
15651: if ($args->{'autodrops'}) {
15652: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15653: }
15654: # check for notification of enrollment changes
15655: my @notified = ();
15656: if ($args->{'notify_owner'}) {
15657: if ($args->{'ccuname'} ne '') {
15658: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15659: }
15660: }
15661: if ($args->{'notify_dc'}) {
15662: if ($uname ne '') {
1.630 raeburn 15663: push(@notified,$uname.':'.$udom);
1.444 albertel 15664: }
15665: }
15666: if (@notified > 0) {
15667: my $notifylist;
15668: if (@notified > 1) {
15669: $notifylist = join(',',@notified);
15670: } else {
15671: $notifylist = $notified[0];
15672: }
15673: $cenv{'internal.notifylist'} = $notifylist;
15674: }
15675: if (@badclasses > 0) {
15676: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15677: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15678: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15679: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15680: );
1.1075.2.119 raeburn 15681: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15682: &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 15683: if ($context eq 'auto') {
15684: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15685: } else {
1.566 albertel 15686: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15687: }
15688: foreach my $item (@badclasses) {
1.541 raeburn 15689: if ($context eq 'auto') {
1.1075.2.119 raeburn 15690: $outcome .= " - $item\n";
1.541 raeburn 15691: } else {
1.1075.2.119 raeburn 15692: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15693: }
1.1075.2.119 raeburn 15694: }
15695: if ($context eq 'auto') {
15696: $outcome .= $linefeed;
15697: } else {
15698: $outcome .= "</ul><br /><br /></div>\n";
15699: }
1.444 albertel 15700: }
15701: if ($args->{'no_end_date'}) {
15702: $args->{'endaccess'} = 0;
15703: }
1.1075.2.166 raeburn 15704: # If an official course with institutional sections is created by cloning
15705: # an existing course, section-specific hiding of course totals in student's
15706: # view of grades as copied from cloned course, will be checked for valid
15707: # sections.
15708: if (($can_clone && $cloneid) &&
15709: ($cenv{'internal.coursecode'} ne '') &&
15710: ($cenv{'grading'} eq 'standard') &&
15711: ($cenv{'hidetotals'} ne '') &&
15712: ($cenv{'hidetotals'} ne 'all')) {
15713: my @hidesecs;
15714: my $deletehidetotals;
15715: if (@oklcsecs) {
15716: foreach my $sec (split(/,/,$cenv{'hidetotals'})) {
15717: if (grep(/^\Q$sec$/,@oklcsecs)) {
15718: push(@hidesecs,$sec);
15719: }
15720: }
15721: if (@hidesecs) {
15722: $cenv{'hidetotals'} = join(',',@hidesecs);
15723: } else {
15724: $deletehidetotals = 1;
15725: }
15726: } else {
15727: $deletehidetotals = 1;
15728: }
15729: if ($deletehidetotals) {
15730: delete($cenv{'hidetotals'});
15731: &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);
15732: }
15733: }
1.444 albertel 15734: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15735: $cenv{'internal.autoend'}=$args->{'enrollend'};
15736: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15737: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15738: if ($args->{'showphotos'}) {
15739: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15740: }
15741: $cenv{'internal.authtype'} = $args->{'authtype'};
15742: $cenv{'internal.autharg'} = $args->{'autharg'};
15743: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15744: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15745: 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');
15746: if ($context eq 'auto') {
15747: $outcome .= $krb_msg;
15748: } else {
1.566 albertel 15749: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15750: }
15751: $outcome .= $linefeed;
1.444 albertel 15752: }
15753: }
15754: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15755: if ($args->{'setpolicy'}) {
15756: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15757: }
15758: if ($args->{'setcontent'}) {
15759: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15760: }
1.1075.2.110 raeburn 15761: if ($args->{'setcomment'}) {
15762: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15763: }
1.444 albertel 15764: }
15765: if ($args->{'reshome'}) {
15766: $cenv{'reshome'}=$args->{'reshome'}.'/';
15767: $cenv{'reshome'}=~s/\/+$/\//;
15768: }
15769: #
15770: # course has keyed access
15771: #
15772: if ($args->{'setkeys'}) {
15773: $cenv{'keyaccess'}='yes';
15774: }
15775: # if specified, key authority is not course, but user
15776: # only active if keyaccess is yes
15777: if ($args->{'keyauth'}) {
1.487 albertel 15778: my ($user,$domain) = split(':',$args->{'keyauth'});
15779: $user = &LONCAPA::clean_username($user);
15780: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15781: if ($user ne '' && $domain ne '') {
1.487 albertel 15782: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15783: }
15784: }
15785:
1.1075.2.59 raeburn 15786: #
15787: # generate and store uniquecode (available to course requester), if course should have one.
15788: #
15789: if ($args->{'uniquecode'}) {
15790: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15791: if ($code) {
15792: $cenv{'internal.uniquecode'} = $code;
15793: my %crsinfo =
15794: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15795: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15796: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15797: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15798: }
15799: if (ref($coderef)) {
15800: $$coderef = $code;
15801: }
15802: }
15803: }
15804:
1.444 albertel 15805: if ($args->{'disresdis'}) {
15806: $cenv{'pch.roles.denied'}='st';
15807: }
15808: if ($args->{'disablechat'}) {
15809: $cenv{'plc.roles.denied'}='st';
15810: }
15811:
15812: # Record we've not yet viewed the Course Initialization Helper for this
15813: # course
15814: $cenv{'course.helper.not.run'} = 1;
15815: #
15816: # Use new Randomseed
15817: #
15818: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15819: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15820: #
15821: # The encryption code and receipt prefix for this course
15822: #
15823: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15824: $cenv{'internal.encpref'}=100+int(9*rand(99));
15825: #
15826: # By default, use standard grading
15827: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15828:
1.541 raeburn 15829: $outcome .= $linefeed.&mt('Setting environment').': '.
15830: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15831: #
15832: # Open all assignments
15833: #
15834: if ($args->{'openall'}) {
1.1075.2.146 raeburn 15835: my $opendate = time;
15836: if ($args->{'openallfrom'} =~ /^\d+$/) {
15837: $opendate = $args->{'openallfrom'};
15838: }
1.444 albertel 15839: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 15840: my %storecontent = ($storeunder => $opendate,
1.444 albertel 15841: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 15842: $outcome .= &mt('All assignments open starting [_1]',
15843: &Apache::lonlocal::locallocaltime($opendate)).': '.
15844: &Apache::lonnet::cput
15845: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15846: }
15847: #
15848: # Set first page
15849: #
15850: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15851: || ($cloneid)) {
1.445 albertel 15852: use LONCAPA::map;
1.444 albertel 15853: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15854:
15855: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15856: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15857:
1.444 albertel 15858: $outcome .= ($fatal?$errtext:'read ok').' - ';
15859: my $title; my $url;
15860: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15861: $title=&mt('Syllabus');
1.444 albertel 15862: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15863: } else {
1.963 raeburn 15864: $title=&mt('Table of Contents');
1.444 albertel 15865: $url='/adm/navmaps';
15866: }
1.445 albertel 15867:
15868: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15869: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15870:
15871: if ($errtext) { $fatal=2; }
1.541 raeburn 15872: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15873: }
1.566 albertel 15874:
15875: return (1,$outcome);
1.444 albertel 15876: }
15877:
1.1075.2.59 raeburn 15878: sub make_unique_code {
15879: my ($cdom,$cnum) = @_;
15880: # get lock on uniquecodes db
15881: my $lockhash = {
15882: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15883: ':'.$env{'user.domain'},
15884: };
15885: my $tries = 0;
15886: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15887: my ($code,$error);
15888:
15889: while (($gotlock ne 'ok') && ($tries<3)) {
15890: $tries ++;
15891: sleep 1;
15892: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15893: }
15894: if ($gotlock eq 'ok') {
15895: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15896: my $gotcode;
15897: my $attempts = 0;
15898: while ((!$gotcode) && ($attempts < 100)) {
15899: $code = &generate_code();
15900: if (!exists($currcodes{$code})) {
15901: $gotcode = 1;
15902: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15903: $error = 'nostore';
15904: }
15905: }
15906: $attempts ++;
15907: }
15908: my @del_lock = ($cnum."\0".'uniquecodes');
15909: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15910: } else {
15911: $error = 'nolock';
15912: }
15913: return ($code,$error);
15914: }
15915:
15916: sub generate_code {
15917: my $code;
15918: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15919: for (my $i=0; $i<6; $i++) {
15920: my $lettnum = int (rand 2);
15921: my $item = '';
15922: if ($lettnum) {
15923: $item = $letts[int( rand(18) )];
15924: } else {
15925: $item = 1+int( rand(8) );
15926: }
15927: $code .= $item;
15928: }
15929: return $code;
15930: }
15931:
1.444 albertel 15932: ############################################################
15933: ############################################################
15934:
1.953 droeschl 15935: #SD
15936: # only Community and Course, or anything else?
1.378 raeburn 15937: sub course_type {
15938: my ($cid) = @_;
15939: if (!defined($cid)) {
15940: $cid = $env{'request.course.id'};
15941: }
1.404 albertel 15942: if (defined($env{'course.'.$cid.'.type'})) {
15943: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15944: } else {
15945: return 'Course';
1.377 raeburn 15946: }
15947: }
1.156 albertel 15948:
1.406 raeburn 15949: sub group_term {
15950: my $crstype = &course_type();
15951: my %names = (
15952: 'Course' => 'group',
1.865 raeburn 15953: 'Community' => 'group',
1.406 raeburn 15954: );
15955: return $names{$crstype};
15956: }
15957:
1.902 raeburn 15958: sub course_types {
1.1075.2.59 raeburn 15959: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15960: my %typename = (
15961: official => 'Official course',
15962: unofficial => 'Unofficial course',
15963: community => 'Community',
1.1075.2.59 raeburn 15964: textbook => 'Textbook course',
1.902 raeburn 15965: );
15966: return (\@types,\%typename);
15967: }
15968:
1.156 albertel 15969: sub icon {
15970: my ($file)=@_;
1.505 albertel 15971: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15972: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15973: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15974: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15975: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15976: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15977: $curfext.".gif") {
15978: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15979: $curfext.".gif";
15980: }
15981: }
1.249 albertel 15982: return &lonhttpdurl($iconname);
1.154 albertel 15983: }
1.84 albertel 15984:
1.575 albertel 15985: sub lonhttpdurl {
1.692 www 15986: #
15987: # Had been used for "small fry" static images on separate port 8080.
15988: # Modify here if lightweight http functionality desired again.
15989: # Currently eliminated due to increasing firewall issues.
15990: #
1.575 albertel 15991: my ($url)=@_;
1.692 www 15992: return $url;
1.215 albertel 15993: }
15994:
1.213 albertel 15995: sub connection_aborted {
15996: my ($r)=@_;
15997: $r->print(" ");$r->rflush();
15998: my $c = $r->connection;
15999: return $c->aborted();
16000: }
16001:
1.221 foxr 16002: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16003: # strings as 'strings'.
16004: sub escape_single {
1.221 foxr 16005: my ($input) = @_;
1.223 albertel 16006: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16007: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16008: return $input;
16009: }
1.223 albertel 16010:
1.222 foxr 16011: # Same as escape_single, but escape's "'s This
16012: # can be used for "strings"
16013: sub escape_double {
16014: my ($input) = @_;
16015: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16016: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16017: return $input;
16018: }
1.223 albertel 16019:
1.222 foxr 16020: # Escapes the last element of a full URL.
16021: sub escape_url {
16022: my ($url) = @_;
1.238 raeburn 16023: my @urlslices = split(/\//, $url,-1);
1.369 www 16024: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 16025: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16026: }
1.462 albertel 16027:
1.820 raeburn 16028: sub compare_arrays {
16029: my ($arrayref1,$arrayref2) = @_;
16030: my (@difference,%count);
16031: @difference = ();
16032: %count = ();
16033: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16034: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16035: foreach my $element (keys(%count)) {
16036: if ($count{$element} == 1) {
16037: push(@difference,$element);
16038: }
16039: }
16040: }
16041: return @difference;
16042: }
16043:
1.1075.2.152 raeburn 16044: sub lon_status_items {
16045: my %defaults = (
16046: E => 100,
16047: W => 4,
16048: N => 1,
16049: U => 5,
16050: threshold => 200,
16051: sysmail => 2500,
16052: );
16053: my %names = (
16054: E => 'Errors',
16055: W => 'Warnings',
16056: N => 'Notices',
16057: U => 'Unsent',
16058: );
16059: return (\%defaults,\%names);
16060: }
16061:
1.817 bisitz 16062: # -------------------------------------------------------- Initialize user login
1.462 albertel 16063: sub init_user_environment {
1.463 albertel 16064: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16065: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16066:
16067: my $public=($username eq 'public' && $domain eq 'public');
16068:
16069: # See if old ID present, if so, remove
16070:
1.1062 raeburn 16071: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16072: my $now=time;
16073:
16074: if ($public) {
16075: my $max_public=100;
16076: my $oldest;
16077: my $oldest_time=0;
16078: for(my $next=1;$next<=$max_public;$next++) {
16079: if (-e $lonids."/publicuser_$next.id") {
16080: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16081: if ($mtime<$oldest_time || !$oldest_time) {
16082: $oldest_time=$mtime;
16083: $oldest=$next;
16084: }
16085: } else {
16086: $cookie="publicuser_$next";
16087: last;
16088: }
16089: }
16090: if (!$cookie) { $cookie="publicuser_$oldest"; }
16091: } else {
1.463 albertel 16092: # if this isn't a robot, kill any existing non-robot sessions
16093: if (!$args->{'robot'}) {
16094: opendir(DIR,$lonids);
16095: while ($filename=readdir(DIR)) {
16096: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 16097: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16098: &GDBM_READER(),0640)) {
16099: my $linkedfile;
16100: if (exists($oldenv{'user.linkedenv'})) {
16101: $linkedfile = $oldenv{'user.linkedenv'};
16102: }
16103: untie(%oldenv);
16104: if (unlink("$lonids/$filename")) {
16105: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16106: if (-l "$lonids/$linkedfile.id") {
16107: unlink("$lonids/$linkedfile.id");
16108: }
16109: }
16110: }
16111: } else {
16112: unlink($lonids.'/'.$filename);
16113: }
1.463 albertel 16114: }
1.462 albertel 16115: }
1.463 albertel 16116: closedir(DIR);
1.1075.2.84 raeburn 16117: # If there is a undeleted lockfile for the user's paste buffer remove it.
16118: my $namespace = 'nohist_courseeditor';
16119: my $lockingkey = 'paste'."\0".'locked_num';
16120: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16121: $domain,$username);
16122: if (exists($lockhash{$lockingkey})) {
16123: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16124: unless ($delresult eq 'ok') {
16125: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16126: }
16127: }
1.462 albertel 16128: }
16129: # Give them a new cookie
1.463 albertel 16130: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16131: : $now.$$.int(rand(10000)));
1.463 albertel 16132: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16133:
16134: # Initialize roles
16135:
1.1062 raeburn 16136: ($userroles,$firstaccenv,$timerintenv) =
16137: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16138: }
16139: # ------------------------------------ Check browser type and MathML capability
16140:
1.1075.2.77 raeburn 16141: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16142: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16143:
16144: # ------------------------------------------------------------- Get environment
16145:
16146: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16147: my ($tmp) = keys(%userenv);
16148: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
16149: } else {
16150: undef(%userenv);
16151: }
16152: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16153: $form->{'interface'}=$userenv{'interface'};
16154: }
16155: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16156:
16157: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16158: foreach my $option ('interface','localpath','localres') {
16159: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16160: }
16161: # --------------------------------------------------------- Write first profile
16162:
16163: {
1.1075.2.150 raeburn 16164: my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 16165: my %initial_env =
16166: ("user.name" => $username,
16167: "user.domain" => $domain,
16168: "user.home" => $authhost,
16169: "browser.type" => $clientbrowser,
16170: "browser.version" => $clientversion,
16171: "browser.mathml" => $clientmathml,
16172: "browser.unicode" => $clientunicode,
16173: "browser.os" => $clientos,
1.1075.2.42 raeburn 16174: "browser.mobile" => $clientmobile,
16175: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 16176: "browser.osversion" => $clientosversion,
1.462 albertel 16177: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16178: "request.course.fn" => '',
16179: "request.course.uri" => '',
16180: "request.course.sec" => '',
16181: "request.role" => 'cm',
16182: "request.role.adv" => $env{'user.adv'},
1.1075.2.150 raeburn 16183: "request.host" => $ip,);
1.462 albertel 16184:
16185: if ($form->{'localpath'}) {
16186: $initial_env{"browser.localpath"} = $form->{'localpath'};
16187: $initial_env{"browser.localres"} = $form->{'localres'};
16188: }
16189:
16190: if ($form->{'interface'}) {
16191: $form->{'interface'}=~s/\W//gs;
16192: $initial_env{"browser.interface"} = $form->{'interface'};
16193: $env{'browser.interface'}=$form->{'interface'};
16194: }
16195:
1.1075.2.54 raeburn 16196: if ($form->{'iptoken'}) {
16197: my $lonhost = $r->dir_config('lonHostID');
16198: $initial_env{"user.noloadbalance"} = $lonhost;
16199: $env{'user.noloadbalance'} = $lonhost;
16200: }
16201:
1.1075.2.120 raeburn 16202: if ($form->{'noloadbalance'}) {
16203: my @hosts = &Apache::lonnet::current_machine_ids();
16204: my $hosthere = $form->{'noloadbalance'};
16205: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16206: $initial_env{"user.noloadbalance"} = $hosthere;
16207: $env{'user.noloadbalance'} = $hosthere;
16208: }
16209: }
16210:
1.1016 raeburn 16211: unless ($domain eq 'public') {
1.1075.2.125 raeburn 16212: my %is_adv = ( is_adv => $env{'user.adv'} );
16213: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 16214:
1.1075.2.125 raeburn 16215: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16216: $userenv{'availabletools.'.$tool} =
16217: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16218: undef,\%userenv,\%domdef,\%is_adv);
16219: }
1.724 raeburn 16220:
1.1075.2.125 raeburn 16221: foreach my $crstype ('official','unofficial','community','textbook') {
16222: $userenv{'canrequest.'.$crstype} =
16223: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16224: 'reload','requestcourses',
16225: \%userenv,\%domdef,\%is_adv);
16226: }
1.765 raeburn 16227:
1.1075.2.125 raeburn 16228: $userenv{'canrequest.author'} =
16229: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16230: 'reload','requestauthor',
16231: \%userenv,\%domdef,\%is_adv);
16232: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16233: $domain,$username);
16234: my $reqstatus = $reqauthor{'author_status'};
16235: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16236: if (ref($reqauthor{'author'}) eq 'HASH') {
16237: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16238: $reqauthor{'author'}{'timestamp'};
16239: }
1.1075.2.14 raeburn 16240: }
16241: }
16242:
1.462 albertel 16243: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16244:
1.462 albertel 16245: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16246: &GDBM_WRCREAT(),0640)) {
16247: &_add_to_env(\%disk_env,\%initial_env);
16248: &_add_to_env(\%disk_env,\%userenv,'environment.');
16249: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16250: if (ref($firstaccenv) eq 'HASH') {
16251: &_add_to_env(\%disk_env,$firstaccenv);
16252: }
16253: if (ref($timerintenv) eq 'HASH') {
16254: &_add_to_env(\%disk_env,$timerintenv);
16255: }
1.463 albertel 16256: if (ref($args->{'extra_env'})) {
16257: &_add_to_env(\%disk_env,$args->{'extra_env'});
16258: }
1.462 albertel 16259: untie(%disk_env);
16260: } else {
1.705 tempelho 16261: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16262: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16263: return 'error: '.$!;
16264: }
16265: }
16266: $env{'request.role'}='cm';
16267: $env{'request.role.adv'}=$env{'user.adv'};
16268: $env{'browser.type'}=$clientbrowser;
16269:
16270: return $cookie;
16271:
16272: }
16273:
16274: sub _add_to_env {
16275: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16276: if (ref($env_data) eq 'HASH') {
16277: while (my ($key,$value) = each(%$env_data)) {
16278: $idf->{$prefix.$key} = $value;
16279: $env{$prefix.$key} = $value;
16280: }
1.462 albertel 16281: }
16282: }
16283:
1.685 tempelho 16284: # --- Get the symbolic name of a problem and the url
16285: sub get_symb {
16286: my ($request,$silent) = @_;
1.726 raeburn 16287: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16288: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16289: if ($symb eq '') {
16290: if (!$silent) {
1.1071 raeburn 16291: if (ref($request)) {
16292: $request->print("Unable to handle ambiguous references:$url:.");
16293: }
1.685 tempelho 16294: return ();
16295: }
16296: }
16297: &Apache::lonenc::check_decrypt(\$symb);
16298: return ($symb);
16299: }
16300:
16301: # --------------------------------------------------------------Get annotation
16302:
16303: sub get_annotation {
16304: my ($symb,$enc) = @_;
16305:
16306: my $key = $symb;
16307: if (!$enc) {
16308: $key =
16309: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16310: }
16311: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16312: return $annotation{$key};
16313: }
16314:
16315: sub clean_symb {
1.731 raeburn 16316: my ($symb,$delete_enc) = @_;
1.685 tempelho 16317:
16318: &Apache::lonenc::check_decrypt(\$symb);
16319: my $enc = $env{'request.enc'};
1.731 raeburn 16320: if ($delete_enc) {
1.730 raeburn 16321: delete($env{'request.enc'});
16322: }
1.685 tempelho 16323:
16324: return ($symb,$enc);
16325: }
1.462 albertel 16326:
1.1075.2.69 raeburn 16327: ############################################################
16328: ############################################################
16329:
16330: =pod
16331:
16332: =head1 Routines for building display used to search for courses
16333:
16334:
16335: =over 4
16336:
16337: =item * &build_filters()
16338:
16339: Create markup for a table used to set filters to use when selecting
16340: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16341: and quotacheck.pl
16342:
16343:
16344: Inputs:
16345:
16346: filterlist - anonymous array of fields to include as potential filters
16347:
16348: crstype - course type
16349:
16350: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16351: to pop-open a course selector (will contain "extra element").
16352:
16353: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16354:
16355: filter - anonymous hash of criteria and their values
16356:
16357: action - form action
16358:
16359: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16360:
16361: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
16362:
16363: cloneruname - username of owner of new course who wants to clone
16364:
16365: clonerudom - domain of owner of new course who wants to clone
16366:
16367: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16368:
16369: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16370:
16371: codedom - domain
16372:
16373: formname - value of form element named "form".
16374:
16375: fixeddom - domain, if fixed.
16376:
16377: prevphase - value to assign to form element named "phase" when going back to the previous screen
16378:
16379: cnameelement - name of form element in form on opener page which will receive title of selected course
16380:
16381: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16382:
16383: cdomelement - name of form element in form on opener page which will receive domain of selected course
16384:
16385: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16386:
16387: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16388:
16389: clonewarning - warning message about missing information for intended course owner when DC creates a course
16390:
16391:
16392: Returns: $output - HTML for display of search criteria, and hidden form elements.
16393:
16394:
16395: Side Effects: None
16396:
16397: =cut
16398:
16399: # ---------------------------------------------- search for courses based on last activity etc.
16400:
16401: sub build_filters {
16402: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16403: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16404: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16405: $cnameelement,$cnumelement,$cdomelement,$setroles,
16406: $clonetext,$clonewarning) = @_;
16407: my ($list,$jscript);
16408: my $onchange = 'javascript:updateFilters(this)';
16409: my ($domainselectform,$sincefilterform,$createdfilterform,
16410: $ownerdomselectform,$persondomselectform,$instcodeform,
16411: $typeselectform,$instcodetitle);
16412: if ($formname eq '') {
16413: $formname = $caller;
16414: }
16415: foreach my $item (@{$filterlist}) {
16416: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16417: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16418: if ($item eq 'domainfilter') {
16419: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16420: } elsif ($item eq 'coursefilter') {
16421: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16422: } elsif ($item eq 'ownerfilter') {
16423: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16424: } elsif ($item eq 'ownerdomfilter') {
16425: $filter->{'ownerdomfilter'} =
16426: &LONCAPA::clean_domain($filter->{$item});
16427: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16428: 'ownerdomfilter',1);
16429: } elsif ($item eq 'personfilter') {
16430: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16431: } elsif ($item eq 'persondomfilter') {
16432: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16433: 'persondomfilter',1);
16434: } else {
16435: $filter->{$item} =~ s/\W//g;
16436: }
16437: if (!$filter->{$item}) {
16438: $filter->{$item} = '';
16439: }
16440: }
16441: if ($item eq 'domainfilter') {
16442: my $allow_blank = 1;
16443: if ($formname eq 'portform') {
16444: $allow_blank=0;
16445: } elsif ($formname eq 'studentform') {
16446: $allow_blank=0;
16447: }
16448: if ($fixeddom) {
16449: $domainselectform = '<input type="hidden" name="domainfilter"'.
16450: ' value="'.$codedom.'" />'.
16451: &Apache::lonnet::domain($codedom,'description');
16452: } else {
16453: $domainselectform = &select_dom_form($filter->{$item},
16454: 'domainfilter',
16455: $allow_blank,'',$onchange);
16456: }
16457: } else {
16458: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16459: }
16460: }
16461:
16462: # last course activity filter and selection
16463: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16464:
16465: # course created filter and selection
16466: if (exists($filter->{'createdfilter'})) {
16467: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16468: }
16469:
16470: my %lt = &Apache::lonlocal::texthash(
16471: 'cac' => "$crstype Activity",
16472: 'ccr' => "$crstype Created",
16473: 'cde' => "$crstype Title",
16474: 'cdo' => "$crstype Domain",
16475: 'ins' => 'Institutional Code',
16476: 'inc' => 'Institutional Categorization',
16477: 'cow' => "$crstype Owner/Co-owner",
16478: 'cop' => "$crstype Personnel Includes",
16479: 'cog' => 'Type',
16480: );
16481:
16482: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16483: my $typeval = 'Course';
16484: if ($crstype eq 'Community') {
16485: $typeval = 'Community';
16486: }
16487: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16488: } else {
16489: $typeselectform = '<select name="type" size="1"';
16490: if ($onchange) {
16491: $typeselectform .= ' onchange="'.$onchange.'"';
16492: }
16493: $typeselectform .= '>'."\n";
16494: foreach my $posstype ('Course','Community') {
16495: $typeselectform.='<option value="'.$posstype.'"'.
16496: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16497: }
16498: $typeselectform.="</select>";
16499: }
16500:
16501: my ($cloneableonlyform,$cloneabletitle);
16502: if (exists($filter->{'cloneableonly'})) {
16503: my $cloneableon = '';
16504: my $cloneableoff = ' checked="checked"';
16505: if ($filter->{'cloneableonly'}) {
16506: $cloneableon = $cloneableoff;
16507: $cloneableoff = '';
16508: }
16509: $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>';
16510: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16511: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16512: } else {
16513: $cloneabletitle = &mt('Cloneable by you');
16514: }
16515: }
16516: my $officialjs;
16517: if ($crstype eq 'Course') {
16518: if (exists($filter->{'instcodefilter'})) {
16519: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16520: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16521: if ($codedom) {
16522: $officialjs = 1;
16523: ($instcodeform,$jscript,$$numtitlesref) =
16524: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16525: $officialjs,$codetitlesref);
16526: if ($jscript) {
16527: $jscript = '<script type="text/javascript">'."\n".
16528: '// <![CDATA['."\n".
16529: $jscript."\n".
16530: '// ]]>'."\n".
16531: '</script>'."\n";
16532: }
16533: }
16534: if ($instcodeform eq '') {
16535: $instcodeform =
16536: '<input type="text" name="instcodefilter" size="10" value="'.
16537: $list->{'instcodefilter'}.'" />';
16538: $instcodetitle = $lt{'ins'};
16539: } else {
16540: $instcodetitle = $lt{'inc'};
16541: }
16542: if ($fixeddom) {
16543: $instcodetitle .= '<br />('.$codedom.')';
16544: }
16545: }
16546: }
16547: my $output = qq|
16548: <form method="post" name="filterpicker" action="$action">
16549: <input type="hidden" name="form" value="$formname" />
16550: |;
16551: if ($formname eq 'modifycourse') {
16552: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16553: '<input type="hidden" name="prevphase" value="'.
16554: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16555: } elsif ($formname eq 'quotacheck') {
16556: $output .= qq|
16557: <input type="hidden" name="sortby" value="" />
16558: <input type="hidden" name="sortorder" value="" />
16559: |;
16560: } else {
1.1075.2.69 raeburn 16561: my $name_input;
16562: if ($cnameelement ne '') {
16563: $name_input = '<input type="hidden" name="cnameelement" value="'.
16564: $cnameelement.'" />';
16565: }
16566: $output .= qq|
16567: <input type="hidden" name="cnumelement" value="$cnumelement" />
16568: <input type="hidden" name="cdomelement" value="$cdomelement" />
16569: $name_input
16570: $roleelement
16571: $multelement
16572: $typeelement
16573: |;
16574: if ($formname eq 'portform') {
16575: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16576: }
16577: }
16578: if ($fixeddom) {
16579: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16580: }
16581: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16582: if ($sincefilterform) {
16583: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16584: .$sincefilterform
16585: .&Apache::lonhtmlcommon::row_closure();
16586: }
16587: if ($createdfilterform) {
16588: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16589: .$createdfilterform
16590: .&Apache::lonhtmlcommon::row_closure();
16591: }
16592: if ($domainselectform) {
16593: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16594: .$domainselectform
16595: .&Apache::lonhtmlcommon::row_closure();
16596: }
16597: if ($typeselectform) {
16598: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16599: $output .= $typeselectform;
16600: } else {
16601: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16602: .$typeselectform
16603: .&Apache::lonhtmlcommon::row_closure();
16604: }
16605: }
16606: if ($instcodeform) {
16607: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16608: .$instcodeform
16609: .&Apache::lonhtmlcommon::row_closure();
16610: }
16611: if (exists($filter->{'ownerfilter'})) {
16612: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16613: '<table><tr><td>'.&mt('Username').'<br />'.
16614: '<input type="text" name="ownerfilter" size="20" value="'.
16615: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16616: $ownerdomselectform.'</td></tr></table>'.
16617: &Apache::lonhtmlcommon::row_closure();
16618: }
16619: if (exists($filter->{'personfilter'})) {
16620: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16621: '<table><tr><td>'.&mt('Username').'<br />'.
16622: '<input type="text" name="personfilter" size="20" value="'.
16623: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16624: $persondomselectform.'</td></tr></table>'.
16625: &Apache::lonhtmlcommon::row_closure();
16626: }
16627: if (exists($filter->{'coursefilter'})) {
16628: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16629: .'<input type="text" name="coursefilter" size="25" value="'
16630: .$list->{'coursefilter'}.'" />'
16631: .&Apache::lonhtmlcommon::row_closure();
16632: }
16633: if ($cloneableonlyform) {
16634: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16635: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16636: }
16637: if (exists($filter->{'descriptfilter'})) {
16638: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16639: .'<input type="text" name="descriptfilter" size="40" value="'
16640: .$list->{'descriptfilter'}.'" />'
16641: .&Apache::lonhtmlcommon::row_closure(1);
16642: }
16643: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16644: '<input type="hidden" name="updater" value="" />'."\n".
16645: '<input type="submit" name="gosearch" value="'.
16646: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16647: return $jscript.$clonewarning.$output;
16648: }
16649:
16650: =pod
16651:
16652: =item * &timebased_select_form()
16653:
16654: Create markup for a dropdown list used to select a time-based
16655: filter e.g., Course Activity, Course Created, when searching for courses
16656: or communities
16657:
16658: Inputs:
16659:
16660: item - name of form element (sincefilter or createdfilter)
16661:
16662: filter - anonymous hash of criteria and their values
16663:
16664: Returns: HTML for a select box contained a blank, then six time selections,
16665: with value set in incoming form variables currently selected.
16666:
16667: Side Effects: None
16668:
16669: =cut
16670:
16671: sub timebased_select_form {
16672: my ($item,$filter) = @_;
16673: if (ref($filter) eq 'HASH') {
16674: $filter->{$item} =~ s/[^\d-]//g;
16675: if (!$filter->{$item}) { $filter->{$item}=-1; }
16676: return &select_form(
16677: $filter->{$item},
16678: $item,
16679: { '-1' => '',
16680: '86400' => &mt('today'),
16681: '604800' => &mt('last week'),
16682: '2592000' => &mt('last month'),
16683: '7776000' => &mt('last three months'),
16684: '15552000' => &mt('last six months'),
16685: '31104000' => &mt('last year'),
16686: 'select_form_order' =>
16687: ['-1','86400','604800','2592000','7776000',
16688: '15552000','31104000']});
16689: }
16690: }
16691:
16692: =pod
16693:
16694: =item * &js_changer()
16695:
16696: Create script tag containing Javascript used to submit course search form
16697: when course type or domain is changed, and also to hide 'Searching ...' on
16698: page load completion for page showing search result.
16699:
16700: Inputs: None
16701:
16702: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16703:
16704: Side Effects: None
16705:
16706: =cut
16707:
16708: sub js_changer {
16709: return <<ENDJS;
16710: <script type="text/javascript">
16711: // <![CDATA[
16712: function updateFilters(caller) {
16713: if (typeof(caller) != "undefined") {
16714: document.filterpicker.updater.value = caller.name;
16715: }
16716: document.filterpicker.submit();
16717: }
16718:
16719: function hideSearching() {
16720: if (document.getElementById('searching')) {
16721: document.getElementById('searching').style.display = 'none';
16722: }
16723: return;
16724: }
16725:
16726: // ]]>
16727: </script>
16728:
16729: ENDJS
16730: }
16731:
16732: =pod
16733:
16734: =item * &search_courses()
16735:
16736: Process selected filters form course search form and pass to lonnet::courseiddump
16737: to retrieve a hash for which keys are courseIDs which match the selected filters.
16738:
16739: Inputs:
16740:
16741: dom - domain being searched
16742:
16743: type - course type ('Course' or 'Community' or '.' if any).
16744:
16745: filter - anonymous hash of criteria and their values
16746:
16747: numtitles - for institutional codes - number of categories
16748:
16749: cloneruname - optional username of new course owner
16750:
16751: clonerudom - optional domain of new course owner
16752:
1.1075.2.95 raeburn 16753: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16754: (used when DC is using course creation form)
16755:
16756: codetitles - reference to array of titles of components in institutional codes (official courses).
16757:
1.1075.2.95 raeburn 16758: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16759: (and so can clone automatically)
16760:
16761: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16762:
16763: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16764: courses to clone
1.1075.2.69 raeburn 16765:
16766: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16767:
16768:
16769: Side Effects: None
16770:
16771: =cut
16772:
16773:
16774: sub search_courses {
1.1075.2.95 raeburn 16775: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16776: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16777: my (%courses,%showcourses,$cloner);
16778: if (($filter->{'ownerfilter'} ne '') ||
16779: ($filter->{'ownerdomfilter'} ne '')) {
16780: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16781: $filter->{'ownerdomfilter'};
16782: }
16783: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16784: if (!$filter->{$item}) {
16785: $filter->{$item}='.';
16786: }
16787: }
16788: my $now = time;
16789: my $timefilter =
16790: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16791: my ($createdbefore,$createdafter);
16792: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16793: $createdbefore = $now;
16794: $createdafter = $now-$filter->{'createdfilter'};
16795: }
16796: my ($instcodefilter,$regexpok);
16797: if ($numtitles) {
16798: if ($env{'form.official'} eq 'on') {
16799: $instcodefilter =
16800: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16801: $regexpok = 1;
16802: } elsif ($env{'form.official'} eq 'off') {
16803: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16804: unless ($instcodefilter eq '') {
16805: $regexpok = -1;
16806: }
16807: }
16808: } else {
16809: $instcodefilter = $filter->{'instcodefilter'};
16810: }
16811: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16812: if ($type eq '') { $type = '.'; }
16813:
16814: if (($clonerudom ne '') && ($cloneruname ne '')) {
16815: $cloner = $cloneruname.':'.$clonerudom;
16816: }
16817: %courses = &Apache::lonnet::courseiddump($dom,
16818: $filter->{'descriptfilter'},
16819: $timefilter,
16820: $instcodefilter,
16821: $filter->{'combownerfilter'},
16822: $filter->{'coursefilter'},
16823: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16824: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16825: $filter->{'cloneableonly'},
16826: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16827: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16828: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16829: my $ccrole;
16830: if ($type eq 'Community') {
16831: $ccrole = 'co';
16832: } else {
16833: $ccrole = 'cc';
16834: }
16835: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16836: $filter->{'persondomfilter'},
16837: 'userroles',undef,
16838: [$ccrole,'in','ad','ep','ta','cr'],
16839: $dom);
16840: foreach my $role (keys(%rolehash)) {
16841: my ($cnum,$cdom,$courserole) = split(':',$role);
16842: my $cid = $cdom.'_'.$cnum;
16843: if (exists($courses{$cid})) {
16844: if (ref($courses{$cid}) eq 'HASH') {
16845: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16846: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16847: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16848: }
16849: } else {
16850: $courses{$cid}{roles} = [$courserole];
16851: }
16852: $showcourses{$cid} = $courses{$cid};
16853: }
16854: }
16855: }
16856: %courses = %showcourses;
16857: }
16858: return %courses;
16859: }
16860:
16861: =pod
16862:
16863: =back
16864:
1.1075.2.88 raeburn 16865: =head1 Routines for version requirements for current course.
16866:
16867: =over 4
16868:
16869: =item * &check_release_required()
16870:
16871: Compares required LON-CAPA version with version on server, and
16872: if required version is newer looks for a server with the required version.
16873:
16874: Looks first at servers in user's owen domain; if none suitable, looks at
16875: servers in course's domain are permitted to host sessions for user's domain.
16876:
16877: Inputs:
16878:
16879: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16880:
16881: $courseid - Course ID of current course
16882:
16883: $rolecode - User's current role in course (for switchserver query string).
16884:
16885: $required - LON-CAPA version needed by course (format: Major.Minor).
16886:
16887:
16888: Returns:
16889:
16890: $switchserver - query string tp append to /adm/switchserver call (if
16891: current server's LON-CAPA version is too old.
16892:
16893: $warning - Message is displayed if no suitable server could be found.
16894:
16895: =cut
16896:
16897: sub check_release_required {
16898: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16899: my ($switchserver,$warning);
16900: if ($required ne '') {
16901: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16902: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16903: if ($reqdmajor ne '' && $reqdminor ne '') {
16904: my $otherserver;
16905: if (($major eq '' && $minor eq '') ||
16906: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16907: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16908: my $switchlcrev =
16909: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16910: $userdomserver);
16911: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16912: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16913: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16914: my $cdom = $env{'course.'.$courseid.'.domain'};
16915: if ($cdom ne $env{'user.domain'}) {
16916: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16917: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16918: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16919: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16920: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16921: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16922: my $canhost =
16923: &Apache::lonnet::can_host_session($env{'user.domain'},
16924: $coursedomserver,
16925: $remoterev,
16926: $udomdefaults{'remotesessions'},
16927: $defdomdefaults{'hostedsessions'});
16928:
16929: if ($canhost) {
16930: $otherserver = $coursedomserver;
16931: } else {
16932: $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.");
16933: }
16934: } else {
16935: $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).");
16936: }
16937: } else {
16938: $otherserver = $userdomserver;
16939: }
16940: }
16941: if ($otherserver ne '') {
16942: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16943: }
16944: }
16945: }
16946: return ($switchserver,$warning);
16947: }
16948:
16949: =pod
16950:
16951: =item * &check_release_result()
16952:
16953: Inputs:
16954:
16955: $switchwarning - Warning message if no suitable server found to host session.
16956:
16957: $switchserver - query string to append to /adm/switchserver containing lonHostID
16958: and current role.
16959:
16960: Returns: HTML to display with information about requirement to switch server.
16961: Either displaying warning with link to Roles/Courses screen or
16962: display link to switchserver.
16963:
1.1075.2.69 raeburn 16964: =cut
16965:
1.1075.2.88 raeburn 16966: sub check_release_result {
16967: my ($switchwarning,$switchserver) = @_;
16968: my $output = &start_page('Selected course unavailable on this server').
16969: '<p class="LC_warning">';
16970: if ($switchwarning) {
16971: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16972: if (&show_course()) {
16973: $output .= &mt('Display courses');
16974: } else {
16975: $output .= &mt('Display roles');
16976: }
16977: $output .= '</a>';
16978: } elsif ($switchserver) {
16979: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16980: '<br />'.
16981: '<a href="/adm/switchserver?'.$switchserver.'">'.
16982: &mt('Switch Server').
16983: '</a>';
16984: }
16985: $output .= '</p>'.&end_page();
16986: return $output;
16987: }
16988:
16989: =pod
16990:
16991: =item * &needs_coursereinit()
16992:
16993: Determine if course contents stored for user's session needs to be
16994: refreshed, because content has changed since "Big Hash" last tied.
16995:
16996: Check for change is made if time last checked is more than 10 minutes ago
16997: (by default).
16998:
16999: Inputs:
17000:
17001: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17002:
17003: $interval (optional) - Time which may elapse (in s) between last check for content
17004: change in current course. (default: 600 s).
17005:
17006: Returns: an array; first element is:
17007:
17008: =over 4
17009:
17010: 'switch' - if content updates mean user's session
17011: needs to be switched to a server running a newer LON-CAPA version
17012:
17013: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17014: on current server hosting user's session
17015:
17016: '' - if no action required.
17017:
17018: =back
17019:
17020: If first item element is 'switch':
17021:
17022: second item is $switchwarning - Warning message if no suitable server found to host session.
17023:
17024: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17025: and current role.
17026:
17027: otherwise: no other elements returned.
17028:
17029: =back
17030:
17031: =cut
17032:
17033: sub needs_coursereinit {
17034: my ($loncaparev,$interval) = @_;
17035: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17036: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17037: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17038: my $now = time;
17039: if ($interval eq '') {
17040: $interval = 600;
17041: }
17042: if (($now-$env{'request.course.timechecked'})>$interval) {
17043: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17044: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
17045: if ($lastchange > $env{'request.course.tied'}) {
17046: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17047: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17048: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17049: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17050: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17051: $curr_reqd_hash{'internal.releaserequired'}});
17052: my ($switchserver,$switchwarning) =
17053: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17054: $curr_reqd_hash{'internal.releaserequired'});
17055: if ($switchwarning ne '' || $switchserver ne '') {
17056: return ('switch',$switchwarning,$switchserver);
17057: }
17058: }
17059: }
17060: return ('update');
17061: }
17062: }
17063: return ();
17064: }
1.1075.2.69 raeburn 17065:
1.1075.2.11 raeburn 17066: sub update_content_constraints {
17067: my ($cdom,$cnum,$chome,$cid) = @_;
17068: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17069: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
17070: my %checkresponsetypes;
17071: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
17072: my ($item,$name,$value) = split(/:/,$key);
17073: if ($item eq 'resourcetag') {
17074: if ($name eq 'responsetype') {
17075: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17076: }
17077: }
17078: }
17079: my $navmap = Apache::lonnavmaps::navmap->new();
17080: if (defined($navmap)) {
17081: my %allresponses;
17082: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17083: my %responses = $res->responseTypes();
17084: foreach my $key (keys(%responses)) {
17085: next unless(exists($checkresponsetypes{$key}));
17086: $allresponses{$key} += $responses{$key};
17087: }
17088: }
17089: foreach my $key (keys(%allresponses)) {
17090: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17091: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17092: ($reqdmajor,$reqdminor) = ($major,$minor);
17093: }
17094: }
17095: undef($navmap);
17096: }
17097: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17098: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17099: }
17100: return;
17101: }
17102:
1.1075.2.27 raeburn 17103: sub allmaps_incourse {
17104: my ($cdom,$cnum,$chome,$cid) = @_;
17105: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17106: $cid = $env{'request.course.id'};
17107: $cdom = $env{'course.'.$cid.'.domain'};
17108: $cnum = $env{'course.'.$cid.'.num'};
17109: $chome = $env{'course.'.$cid.'.home'};
17110: }
17111: my %allmaps = ();
17112: my $lastchange =
17113: &Apache::lonnet::get_coursechange($cdom,$cnum);
17114: if ($lastchange > $env{'request.course.tied'}) {
17115: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17116: unless ($ferr) {
17117: &update_content_constraints($cdom,$cnum,$chome,$cid);
17118: }
17119: }
17120: my $navmap = Apache::lonnavmaps::navmap->new();
17121: if (defined($navmap)) {
17122: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17123: $allmaps{$res->src()} = 1;
17124: }
17125: }
17126: return \%allmaps;
17127: }
17128:
1.1075.2.11 raeburn 17129: sub parse_supplemental_title {
17130: my ($title) = @_;
17131:
17132: my ($foldertitle,$renametitle);
17133: if ($title =~ /&&&/) {
17134: $title = &HTML::Entites::decode($title);
17135: }
17136: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17137: $renametitle=$4;
17138: my ($time,$uname,$udom) = ($1,$2,$3);
17139: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17140: my $name = &plainname($uname,$udom);
17141: $name = &HTML::Entities::encode($name,'"<>&\'');
17142: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17143: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17144: $name.': <br />'.$foldertitle;
17145: }
17146: if (wantarray) {
17147: return ($title,$foldertitle,$renametitle);
17148: }
17149: return $title;
17150: }
17151:
1.1075.2.43 raeburn 17152: sub recurse_supplemental {
17153: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
17154: if ($suppmap) {
17155: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17156: if ($fatal) {
17157: $errors ++;
17158: } else {
1.1075.2.167 raeburn 17159: my @order = @LONCAPA::map::order;
17160: if (@order > 0) {
17161: my @resources = @LONCAPA::map::resources;
17162: my @resparms = @LONCAPA::map::resparms;
17163: foreach my $idx (@order) {
17164: my ($title,$src,$ext,$type,$status)=split(/\:/,$resources[$idx]);
1.1075.2.43 raeburn 17165: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 17166: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
17167: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 17168: } else {
17169: $numfiles ++;
17170: }
17171: }
17172: }
17173: }
17174: }
17175: }
17176: return ($numfiles,$errors);
17177: }
17178:
1.1075.2.18 raeburn 17179: sub symb_to_docspath {
1.1075.2.119 raeburn 17180: my ($symb,$navmapref) = @_;
17181: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 17182: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17183: if ($resurl=~/\.(sequence|page)$/) {
17184: $mapurl=$resurl;
17185: } elsif ($resurl eq 'adm/navmaps') {
17186: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17187: }
17188: my $mapresobj;
1.1075.2.119 raeburn 17189: unless (ref($$navmapref)) {
17190: $$navmapref = Apache::lonnavmaps::navmap->new();
17191: }
17192: if (ref($$navmapref)) {
17193: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 17194: }
17195: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17196: my $type=$2;
17197: my $path;
17198: if (ref($mapresobj)) {
17199: my $pcslist = $mapresobj->map_hierarchy();
17200: if ($pcslist ne '') {
17201: foreach my $pc (split(/,/,$pcslist)) {
17202: next if ($pc <= 1);
1.1075.2.119 raeburn 17203: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 17204: if (ref($res)) {
17205: my $thisurl = $res->src();
17206: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17207: my $thistitle = $res->title();
17208: $path .= '&'.
17209: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 17210: &escape($thistitle).
1.1075.2.18 raeburn 17211: ':'.$res->randompick().
17212: ':'.$res->randomout().
17213: ':'.$res->encrypted().
17214: ':'.$res->randomorder().
17215: ':'.$res->is_page();
17216: }
17217: }
17218: }
17219: $path =~ s/^\&//;
17220: my $maptitle = $mapresobj->title();
17221: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17222: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17223: }
17224: $path .= (($path ne '')? '&' : '').
17225: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17226: &escape($maptitle).
1.1075.2.18 raeburn 17227: ':'.$mapresobj->randompick().
17228: ':'.$mapresobj->randomout().
17229: ':'.$mapresobj->encrypted().
17230: ':'.$mapresobj->randomorder().
17231: ':'.$mapresobj->is_page();
17232: } else {
17233: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17234: my $ispage = (($type eq 'page')? 1 : '');
17235: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17236: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17237: }
17238: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17239: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 17240: }
17241: unless ($mapurl eq 'default') {
17242: $path = 'default&'.
1.1075.2.46 raeburn 17243: &escape('Main Content').
1.1075.2.18 raeburn 17244: ':::::&'.$path;
17245: }
17246: return $path;
17247: }
17248:
1.1075.2.14 raeburn 17249: sub captcha_display {
1.1075.2.137 raeburn 17250: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17251: my ($output,$error);
1.1075.2.107 raeburn 17252: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 17253: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17254: if ($captcha eq 'original') {
17255: $output = &create_captcha();
17256: unless ($output) {
17257: $error = 'captcha';
17258: }
17259: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17260: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 17261: unless ($output) {
17262: $error = 'recaptcha';
17263: }
17264: }
1.1075.2.107 raeburn 17265: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 17266: }
17267:
17268: sub captcha_response {
1.1075.2.137 raeburn 17269: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17270: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 17271: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17272: if ($captcha eq 'original') {
17273: ($captcha_chk,$captcha_error) = &check_captcha();
17274: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17275: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 17276: } else {
17277: $captcha_chk = 1;
17278: }
17279: return ($captcha_chk,$captcha_error);
17280: }
17281:
17282: sub get_captcha_config {
1.1075.2.137 raeburn 17283: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 17284: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 17285: my $hostname = &Apache::lonnet::hostname($lonhost);
17286: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17287: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17288: if ($context eq 'usercreation') {
17289: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17290: if (ref($domconfig{$context}) eq 'HASH') {
17291: $hashtocheck = $domconfig{$context}{'cancreate'};
17292: if (ref($hashtocheck) eq 'HASH') {
17293: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17294: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17295: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17296: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17297: }
17298: if ($privkey && $pubkey) {
17299: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17300: $version = $hashtocheck->{'recaptchaversion'};
17301: if ($version ne '2') {
17302: $version = 1;
17303: }
1.1075.2.14 raeburn 17304: } else {
17305: $captcha = 'original';
17306: }
17307: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17308: $captcha = 'original';
17309: }
17310: }
17311: } else {
17312: $captcha = 'captcha';
17313: }
17314: } elsif ($context eq 'login') {
17315: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17316: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17317: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17318: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
17319: if ($privkey && $pubkey) {
17320: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17321: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17322: if ($version ne '2') {
17323: $version = 1;
17324: }
1.1075.2.14 raeburn 17325: } else {
17326: $captcha = 'original';
17327: }
17328: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17329: $captcha = 'original';
17330: }
1.1075.2.137 raeburn 17331: } elsif ($context eq 'passwords') {
17332: if ($dom_in_effect) {
17333: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17334: if ($passwdconf{'captcha'} eq 'recaptcha') {
17335: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17336: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17337: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17338: }
17339: if ($privkey && $pubkey) {
17340: $captcha = 'recaptcha';
17341: $version = $passwdconf{'recaptchaversion'};
17342: if ($version ne '2') {
17343: $version = 1;
17344: }
17345: } else {
17346: $captcha = 'original';
17347: }
17348: } elsif ($passwdconf{'captcha'} ne 'notused') {
17349: $captcha = 'original';
17350: }
17351: }
1.1075.2.14 raeburn 17352: }
1.1075.2.107 raeburn 17353: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 17354: }
17355:
17356: sub create_captcha {
17357: my %captcha_params = &captcha_settings();
17358: my ($output,$maxtries,$tries) = ('',10,0);
17359: while ($tries < $maxtries) {
17360: $tries ++;
17361: my $captcha = Authen::Captcha->new (
17362: output_folder => $captcha_params{'output_dir'},
17363: data_folder => $captcha_params{'db_dir'},
17364: );
17365: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17366:
17367: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17368: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1075.2.158 raeburn 17369: '<span class="LC_nobreak">'.
1.1075.2.14 raeburn 17370: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.167 raeburn 17371: '<input type="text" size="5" name="code" value="" autocomplete="new-password" />'.
1.1075.2.158 raeburn 17372: '</span><br />'.
1.1075.2.66 raeburn 17373: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 17374: last;
17375: }
17376: }
1.1075.2.158 raeburn 17377: if ($output eq '') {
17378: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
17379: }
1.1075.2.14 raeburn 17380: return $output;
17381: }
17382:
17383: sub captcha_settings {
17384: my %captcha_params = (
17385: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17386: www_output_dir => "/captchaspool",
17387: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17388: numchars => '5',
17389: );
17390: return %captcha_params;
17391: }
17392:
17393: sub check_captcha {
17394: my ($captcha_chk,$captcha_error);
17395: my $code = $env{'form.code'};
17396: my $md5sum = $env{'form.crypt'};
17397: my %captcha_params = &captcha_settings();
17398: my $captcha = Authen::Captcha->new(
17399: output_folder => $captcha_params{'output_dir'},
17400: data_folder => $captcha_params{'db_dir'},
17401: );
1.1075.2.26 raeburn 17402: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 17403: my %captcha_hash = (
17404: 0 => 'Code not checked (file error)',
17405: -1 => 'Failed: code expired',
17406: -2 => 'Failed: invalid code (not in database)',
17407: -3 => 'Failed: invalid code (code does not match crypt)',
17408: );
17409: if ($captcha_chk != 1) {
17410: $captcha_error = $captcha_hash{$captcha_chk}
17411: }
17412: return ($captcha_chk,$captcha_error);
17413: }
17414:
17415: sub create_recaptcha {
1.1075.2.107 raeburn 17416: my ($pubkey,$version) = @_;
17417: if ($version >= 2) {
1.1075.2.158 raeburn 17418: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
17419: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1075.2.107 raeburn 17420: } else {
17421: my $use_ssl;
17422: if ($ENV{'SERVER_PORT'} == 443) {
17423: $use_ssl = 1;
17424: }
17425: my $captcha = Captcha::reCAPTCHA->new;
17426: return $captcha->get_options_setter({theme => 'white'})."\n".
17427: $captcha->get_html($pubkey,undef,$use_ssl).
17428: &mt('If the text is hard to read, [_1] will replace them.',
17429: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17430: '<br /><br />';
17431: }
1.1075.2.14 raeburn 17432: }
17433:
17434: sub check_recaptcha {
1.1075.2.107 raeburn 17435: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 17436: my $captcha_chk;
1.1075.2.150 raeburn 17437: my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 17438: if ($version >= 2) {
17439: my $ua = LWP::UserAgent->new;
17440: $ua->timeout(10);
17441: my %info = (
17442: secret => $privkey,
17443: response => $env{'form.g-recaptcha-response'},
1.1075.2.150 raeburn 17444: remoteip => $ip,
1.1075.2.107 raeburn 17445: );
17446: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17447: if ($response->is_success) {
17448: my $data = JSON::DWIW->from_json($response->decoded_content);
17449: if (ref($data) eq 'HASH') {
17450: if ($data->{'success'}) {
17451: $captcha_chk = 1;
17452: }
17453: }
17454: }
17455: } else {
17456: my $captcha = Captcha::reCAPTCHA->new;
17457: my $captcha_result =
17458: $captcha->check_answer(
17459: $privkey,
1.1075.2.150 raeburn 17460: $ip,
1.1075.2.107 raeburn 17461: $env{'form.recaptcha_challenge_field'},
17462: $env{'form.recaptcha_response_field'},
17463: );
17464: if ($captcha_result->{is_valid}) {
17465: $captcha_chk = 1;
17466: }
1.1075.2.14 raeburn 17467: }
17468: return $captcha_chk;
17469: }
17470:
1.1075.2.64 raeburn 17471: sub emailusername_info {
1.1075.2.103 raeburn 17472: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 17473: my %titles = &Apache::lonlocal::texthash (
17474: lastname => 'Last Name',
17475: firstname => 'First Name',
17476: institution => 'School/college/university',
17477: location => "School's city, state/province, country",
17478: web => "School's web address",
17479: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 17480: id => 'Student/Employee ID',
1.1075.2.64 raeburn 17481: );
17482: return (\@fields,\%titles);
17483: }
17484:
1.1075.2.56 raeburn 17485: sub cleanup_html {
17486: my ($incoming) = @_;
17487: my $outgoing;
17488: if ($incoming ne '') {
17489: $outgoing = $incoming;
17490: $outgoing =~ s/;/;/g;
17491: $outgoing =~ s/\#/#/g;
17492: $outgoing =~ s/\&/&/g;
17493: $outgoing =~ s/</</g;
17494: $outgoing =~ s/>/>/g;
17495: $outgoing =~ s/\(/(/g;
17496: $outgoing =~ s/\)/)/g;
17497: $outgoing =~ s/"/"/g;
17498: $outgoing =~ s/'/'/g;
17499: $outgoing =~ s/\$/$/g;
17500: $outgoing =~ s{/}{/}g;
17501: $outgoing =~ s/=/=/g;
17502: $outgoing =~ s/\\/\/g
17503: }
17504: return $outgoing;
17505: }
17506:
1.1075.2.74 raeburn 17507: # Checks for critical messages and returns a redirect url if one exists.
17508: # $interval indicates how often to check for messages.
17509: sub critical_redirect {
17510: my ($interval) = @_;
1.1075.2.158 raeburn 17511: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
17512: return ();
17513: }
1.1075.2.74 raeburn 17514: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17515: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17516: $env{'user.name'});
17517: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17518: my $redirecturl;
17519: if ($what[0]) {
1.1075.2.158 raeburn 17520: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1075.2.74 raeburn 17521: $redirecturl='/adm/email?critical=display';
17522: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17523: return (1, $url);
17524: }
17525: }
17526: }
17527: return ();
17528: }
17529:
1.1075.2.64 raeburn 17530: # Use:
17531: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17532: #
17533: ##################################################
17534: # password associated functions #
17535: ##################################################
17536: sub des_keys {
17537: # Make a new key for DES encryption.
17538: # Each key has two parts which are returned separately.
17539: # Please note: Each key must be passed through the &hex function
17540: # before it is output to the web browser. The hex versions cannot
17541: # be used to decrypt.
17542: my @hexstr=('0','1','2','3','4','5','6','7',
17543: '8','9','a','b','c','d','e','f');
17544: my $lkey='';
17545: for (0..7) {
17546: $lkey.=$hexstr[rand(15)];
17547: }
17548: my $ukey='';
17549: for (0..7) {
17550: $ukey.=$hexstr[rand(15)];
17551: }
17552: return ($lkey,$ukey);
17553: }
17554:
17555: sub des_decrypt {
17556: my ($key,$cyphertext) = @_;
17557: my $keybin=pack("H16",$key);
17558: my $cypher;
17559: if ($Crypt::DES::VERSION>=2.03) {
17560: $cypher=new Crypt::DES $keybin;
17561: } else {
17562: $cypher=new DES $keybin;
17563: }
1.1075.2.106 raeburn 17564: my $plaintext='';
17565: my $cypherlength = length($cyphertext);
17566: my $numchunks = int($cypherlength/32);
17567: for (my $j=0; $j<$numchunks; $j++) {
17568: my $start = $j*32;
17569: my $cypherblock = substr($cyphertext,$start,32);
17570: my $chunk =
17571: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17572: $chunk .=
17573: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17574: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17575: $plaintext .= $chunk;
17576: }
1.1075.2.64 raeburn 17577: return $plaintext;
17578: }
17579:
1.1075.2.135 raeburn 17580: sub is_nonframeable {
17581: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
17582: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
17583: return if (($remprotocol eq '') || ($remhost eq ''));
17584:
17585: $remprotocol = lc($remprotocol);
17586: $remhost = lc($remhost);
17587: my $remport = 80;
17588: if ($remprotocol eq 'https') {
17589: $remport = 443;
17590: }
17591: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
17592: if ($cached) {
17593: unless ($nocache) {
17594: if ($result) {
17595: return 1;
17596: } else {
17597: return 0;
17598: }
17599: }
17600: }
17601: my $uselink;
17602: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 17603: my $ua = LWP::UserAgent->new;
17604: $ua->timeout(5);
17605: my $response=$ua->request($request);
1.1075.2.135 raeburn 17606: if ($response->is_success()) {
17607: my $secpolicy = lc($response->header('content-security-policy'));
17608: my $xframeop = lc($response->header('x-frame-options'));
17609: $secpolicy =~ s/^\s+|\s+$//g;
17610: $xframeop =~ s/^\s+|\s+$//g;
17611: if (($secpolicy ne '') || ($xframeop ne '')) {
17612: my $remotehost = $remprotocol.'://'.$remhost;
17613: my ($origin,$protocol,$port);
17614: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17615: $port = $ENV{'SERVER_PORT'};
17616: } else {
17617: $port = 80;
17618: }
17619: if ($absolute eq '') {
17620: $protocol = 'http:';
17621: if ($port == 443) {
17622: $protocol = 'https:';
17623: }
17624: $origin = $protocol.'//'.lc($hostname);
17625: } else {
17626: $origin = lc($absolute);
17627: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17628: }
17629: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17630: my $framepolicy = $1;
17631: $framepolicy =~ s/^\s+|\s+$//g;
17632: my @policies = split(/\s+/,$framepolicy);
17633: if (@policies) {
17634: if (grep(/^\Q'none'\E$/,@policies)) {
17635: $uselink = 1;
17636: } else {
17637: $uselink = 1;
17638: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17639: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17640: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17641: undef($uselink);
17642: }
17643: if ($uselink) {
17644: if (grep(/^\Q'self'\E$/,@policies)) {
17645: if (($origin ne '') && ($remotehost eq $origin)) {
17646: undef($uselink);
17647: }
17648: }
17649: }
17650: if ($uselink) {
17651: my @possok;
17652: if ($ip ne '') {
17653: push(@possok,$ip);
17654: }
17655: my $hoststr = '';
17656: foreach my $part (reverse(split(/\./,$hostname))) {
17657: if ($hoststr eq '') {
17658: $hoststr = $part;
17659: } else {
17660: $hoststr = "$part.$hoststr";
17661: }
17662: if ($hoststr eq $hostname) {
17663: push(@possok,$hostname);
17664: } else {
17665: push(@possok,"*.$hoststr");
17666: }
17667: }
17668: if (@possok) {
17669: foreach my $poss (@possok) {
17670: last if (!$uselink);
17671: foreach my $policy (@policies) {
17672: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17673: undef($uselink);
17674: last;
17675: }
17676: }
17677: }
17678: }
17679: }
17680: }
17681: }
17682: } elsif ($xframeop ne '') {
17683: $uselink = 1;
17684: my @policies = split(/\s*,\s*/,$xframeop);
17685: if (@policies) {
17686: unless (grep(/^deny$/,@policies)) {
17687: if ($origin ne '') {
17688: if (grep(/^sameorigin$/,@policies)) {
17689: if ($remotehost eq $origin) {
17690: undef($uselink);
17691: }
17692: }
17693: if ($uselink) {
17694: foreach my $policy (@policies) {
17695: if ($policy =~ /^allow-from\s*(.+)$/) {
17696: my $allowfrom = $1;
17697: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17698: undef($uselink);
17699: last;
17700: }
17701: }
17702: }
17703: }
17704: }
17705: }
17706: }
17707: }
17708: }
17709: }
17710: if ($nocache) {
17711: if ($cached) {
17712: my $devalidate;
17713: if ($uselink && !$result) {
17714: $devalidate = 1;
17715: } elsif (!$uselink && $result) {
17716: $devalidate = 1;
17717: }
17718: if ($devalidate) {
17719: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17720: }
17721: }
17722: } else {
17723: if ($uselink) {
17724: $result = 1;
17725: } else {
17726: $result = 0;
17727: }
17728: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17729: }
17730: return $uselink;
17731: }
17732:
1.112 bowersj2 17733: 1;
17734: __END__;
1.41 ng 17735:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>