Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.166
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.166! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.165 2023/09/11 13:54:11 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.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1075.2.25 raeburn 70: use Apache::lonuserutils();
1.1075.2.27 raeburn 71: use Apache::lonuserstate();
1.1075.2.69 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1075.2.135 raeburn 74: use HTTP::Request;
1.657 raeburn 75: use DateTime::TimeZone;
1.1075.2.102 raeburn 76: use DateTime::Locale;
1.1075.2.94 raeburn 77: use Encode();
1.1075.2.14 raeburn 78: use Authen::Captcha;
79: use Captcha::reCAPTCHA;
1.1075.2.107 raeburn 80: use JSON::DWIW;
81: use LWP::UserAgent;
1.1075.2.64 raeburn 82: use Crypt::DES;
83: use DynaLoader; # for Crypt::DES version
1.1075.2.128 raeburn 84: use File::Copy();
85: use File::Path();
1.117 www 86:
1.517 raeburn 87: # ---------------------------------------------- Designs
88: use vars qw(%defaultdesign);
89:
1.22 www 90: my $readit;
91:
1.517 raeburn 92:
1.157 matthew 93: ##
94: ## Global Variables
95: ##
1.46 matthew 96:
1.643 foxr 97:
98: # ----------------------------------------------- SSI with retries:
99: #
100:
101: =pod
102:
1.648 raeburn 103: =head1 Server Side include with retries:
1.643 foxr 104:
105: =over 4
106:
1.648 raeburn 107: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 108:
109: Performs an ssi with some number of retries. Retries continue either
110: until the result is ok or until the retry count supplied by the
111: caller is exhausted.
112:
113: Inputs:
1.648 raeburn 114:
115: =over 4
116:
1.643 foxr 117: resource - Identifies the resource to insert.
1.648 raeburn 118:
1.643 foxr 119: retries - Count of the number of retries allowed.
1.648 raeburn 120:
1.643 foxr 121: form - Hash that identifies the rendering options.
122:
1.648 raeburn 123: =back
124:
125: Returns:
126:
127: =over 4
128:
1.643 foxr 129: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 130:
1.643 foxr 131: response - The response from the last attempt (which may or may not have been successful.
132:
1.648 raeburn 133: =back
134:
135: =back
136:
1.643 foxr 137: =cut
138:
139: sub ssi_with_retries {
140: my ($resource, $retries, %form) = @_;
141:
142:
143: my $ok = 0; # True if we got a good response.
144: my $content;
145: my $response;
146:
147: # Try to get the ssi done. within the retries count:
148:
149: do {
150: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
151: $ok = $response->is_success;
1.650 www 152: if (!$ok) {
153: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
154: }
1.643 foxr 155: $retries--;
156: } while (!$ok && ($retries > 0));
157:
158: if (!$ok) {
159: $content = ''; # On error return an empty content.
160: }
161: return ($content, $response);
162:
163: }
164:
165:
166:
1.20 www 167: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 168: my %language;
1.124 www 169: my %supported_language;
1.1048 foxr 170: my %latex_language; # For choosing hyphenation in <transl..>
171: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 172: my %cprtag;
1.192 taceyjo1 173: my %scprtag;
1.351 www 174: my %fe; my %fd; my %fm;
1.41 ng 175: my %category_extensions;
1.12 harris41 176:
1.46 matthew 177: # ---------------------------------------------- Thesaurus variables
1.144 matthew 178: #
179: # %Keywords:
180: # A hash used by &keyword to determine if a word is considered a keyword.
181: # $thesaurus_db_file
182: # Scalar containing the full path to the thesaurus database.
1.46 matthew 183:
184: my %Keywords;
185: my $thesaurus_db_file;
186:
1.144 matthew 187: #
188: # Initialize values from language.tab, copyright.tab, filetypes.tab,
189: # thesaurus.tab, and filecategories.tab.
190: #
1.18 www 191: BEGIN {
1.46 matthew 192: # Variable initialization
193: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
194: #
1.22 www 195: unless ($readit) {
1.12 harris41 196: # ------------------------------------------------------------------- languages
197: {
1.158 raeburn 198: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
199: '/language.tab';
1.1075.2.128 raeburn 200: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 201: while (my $line = <$fh>) {
202: next if ($line=~/^\#/);
203: chomp($line);
1.1048 foxr 204: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 205: $language{$key}=$val.' - '.$enc;
206: if ($sup) {
207: $supported_language{$key}=$sup;
208: }
1.1048 foxr 209: if ($latex) {
210: $latex_language_bykey{$key} = $latex;
211: $latex_language{$two} = $latex;
212: }
1.158 raeburn 213: }
214: close($fh);
215: }
1.12 harris41 216: }
217: # ------------------------------------------------------------------ copyrights
218: {
1.158 raeburn 219: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
220: '/copyright.tab';
1.1075.2.128 raeburn 221: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 222: while (my $line = <$fh>) {
223: next if ($line=~/^\#/);
224: chomp($line);
225: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 226: $cprtag{$key}=$val;
227: }
228: close($fh);
229: }
1.12 harris41 230: }
1.351 www 231: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 232: {
233: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
234: '/source_copyright.tab';
1.1075.2.128 raeburn 235: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 236: while (my $line = <$fh>) {
237: next if ($line =~ /^\#/);
238: chomp($line);
239: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 240: $scprtag{$key}=$val;
241: }
242: close($fh);
243: }
244: }
1.63 www 245:
1.517 raeburn 246: # -------------------------------------------------------------- default domain designs
1.63 www 247: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 248: my $designfile = $designdir.'/default.tab';
1.1075.2.128 raeburn 249: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 250: while (my $line = <$fh>) {
251: next if ($line =~ /^\#/);
252: chomp($line);
253: my ($key,$val)=(split(/\=/,$line));
254: if ($val) { $defaultdesign{$key}=$val; }
255: }
256: close($fh);
1.63 www 257: }
258:
1.15 harris41 259: # ------------------------------------------------------------- file categories
260: {
1.158 raeburn 261: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
262: '/filecategories.tab';
1.1075.2.128 raeburn 263: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 264: while (my $line = <$fh>) {
265: next if ($line =~ /^\#/);
266: chomp($line);
267: my ($extension,$category)=(split(/\s+/,$line,2));
1.1075.2.119 raeburn 268: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 269: }
270: close($fh);
271: }
272:
1.15 harris41 273: }
1.12 harris41 274: # ------------------------------------------------------------------ file types
275: {
1.158 raeburn 276: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
277: '/filetypes.tab';
1.1075.2.128 raeburn 278: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 279: while (my $line = <$fh>) {
280: next if ($line =~ /^\#/);
281: chomp($line);
282: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 283: if ($descr ne '') {
284: $fe{$ending}=lc($emb);
285: $fd{$ending}=$descr;
1.351 www 286: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 287: }
288: }
289: close($fh);
290: }
1.12 harris41 291: }
1.22 www 292: &Apache::lonnet::logthis(
1.705 tempelho 293: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 294: $readit=1;
1.46 matthew 295: } # end of unless($readit)
1.32 matthew 296:
297: }
1.112 bowersj2 298:
1.42 matthew 299: ###############################################################
300: ## HTML and Javascript Helper Functions ##
301: ###############################################################
302:
303: =pod
304:
1.112 bowersj2 305: =head1 HTML and Javascript Functions
1.42 matthew 306:
1.112 bowersj2 307: =over 4
308:
1.648 raeburn 309: =item * &browser_and_searcher_javascript()
1.112 bowersj2 310:
311: X<browsing, javascript>X<searching, javascript>Returns a string
312: containing javascript with two functions, C<openbrowser> and
313: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
314: tags.
1.42 matthew 315:
1.648 raeburn 316: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 317:
318: inputs: formname, elementname, only, omit
319:
320: formname and elementname indicate the name of the html form and name of
321: the element that the results of the browsing selection are to be placed in.
322:
323: Specifying 'only' will restrict the browser to displaying only files
1.185 www 324: with the given extension. Can be a comma separated list.
1.42 matthew 325:
326: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 327: with the given extension. Can be a comma separated list.
1.42 matthew 328:
1.648 raeburn 329: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 330:
331: Inputs: formname, elementname
332:
333: formname and elementname specify the name of the html form and the name
334: of the element the selection from the search results will be placed in.
1.542 raeburn 335:
1.42 matthew 336: =cut
337:
338: sub browser_and_searcher_javascript {
1.199 albertel 339: my ($mode)=@_;
340: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 341: my $resurl=&escape_single(&lastresurl());
1.42 matthew 342: return <<END;
1.219 albertel 343: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 344: var editbrowser = null;
1.135 albertel 345: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 346: var url = '$resurl/?';
1.42 matthew 347: if (editbrowser == null) {
348: url += 'launch=1&';
349: }
350: url += 'catalogmode=interactive&';
1.199 albertel 351: url += 'mode=$mode&';
1.611 albertel 352: url += 'inhibitmenu=yes&';
1.42 matthew 353: url += 'form=' + formname + '&';
354: if (only != null) {
355: url += 'only=' + only + '&';
1.217 albertel 356: } else {
357: url += 'only=&';
358: }
1.42 matthew 359: if (omit != null) {
360: url += 'omit=' + omit + '&';
1.217 albertel 361: } else {
362: url += 'omit=&';
363: }
1.135 albertel 364: if (titleelement != null) {
365: url += 'titleelement=' + titleelement + '&';
1.217 albertel 366: } else {
367: url += 'titleelement=&';
368: }
1.42 matthew 369: url += 'element=' + elementname + '';
370: var title = 'Browser';
1.435 albertel 371: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 372: options += ',width=700,height=600';
373: editbrowser = open(url,title,options,'1');
374: editbrowser.focus();
375: }
376: var editsearcher;
1.135 albertel 377: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 378: var url = '/adm/searchcat?';
379: if (editsearcher == null) {
380: url += 'launch=1&';
381: }
382: url += 'catalogmode=interactive&';
1.199 albertel 383: url += 'mode=$mode&';
1.42 matthew 384: url += 'form=' + formname + '&';
1.135 albertel 385: if (titleelement != null) {
386: url += 'titleelement=' + titleelement + '&';
1.217 albertel 387: } else {
388: url += 'titleelement=&';
389: }
1.42 matthew 390: url += 'element=' + elementname + '';
391: var title = 'Search';
1.435 albertel 392: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 393: options += ',width=700,height=600';
394: editsearcher = open(url,title,options,'1');
395: editsearcher.focus();
396: }
1.219 albertel 397: // END LON-CAPA Internal -->
1.42 matthew 398: END
1.170 www 399: }
400:
401: sub lastresurl {
1.258 albertel 402: if ($env{'environment.lastresurl'}) {
403: return $env{'environment.lastresurl'}
1.170 www 404: } else {
405: return '/res';
406: }
407: }
408:
409: sub storeresurl {
410: my $resurl=&Apache::lonnet::clutter(shift);
411: unless ($resurl=~/^\/res/) { return 0; }
412: $resurl=~s/\/$//;
413: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 414: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 415: return 1;
1.42 matthew 416: }
417:
1.74 www 418: sub studentbrowser_javascript {
1.111 www 419: unless (
1.258 albertel 420: (($env{'request.course.id'}) &&
1.302 albertel 421: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
422: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
423: '/'.$env{'request.course.sec'})
424: ))
1.258 albertel 425: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 426: ) { return ''; }
1.74 www 427: return (<<'ENDSTDBRW');
1.776 bisitz 428: <script type="text/javascript" language="Javascript">
1.824 bisitz 429: // <![CDATA[
1.74 www 430: var stdeditbrowser;
1.1075.2.143 raeburn 431: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv) {
1.74 www 432: var url = '/adm/pickstudent?';
433: var filter;
1.558 albertel 434: if (!ignorefilter) {
435: eval('filter=document.'+formname+'.'+uname+'.value;');
436: }
1.74 www 437: if (filter != null) {
438: if (filter != '') {
439: url += 'filter='+filter+'&';
440: }
441: }
442: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 443: '&udomelement='+udom+
444: '&clicker='+clicker;
1.111 www 445: if (roleflag) { url+="&roles=1"; }
1.1075.2.143 raeburn 446: if (courseadv == 'condition') {
447: if (document.getElementById('courseadv')) {
448: courseadv = document.getElementById('courseadv').value;
449: }
450: }
451: if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.102 www 452: var title = 'Student_Browser';
1.74 www 453: var options = 'scrollbars=1,resizable=1,menubar=0';
454: options += ',width=700,height=600';
455: stdeditbrowser = open(url,title,options,'1');
456: stdeditbrowser.focus();
457: }
1.824 bisitz 458: // ]]>
1.74 www 459: </script>
460: ENDSTDBRW
461: }
1.42 matthew 462:
1.1003 www 463: sub resourcebrowser_javascript {
464: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 465: return (<<'ENDRESBRW');
1.1003 www 466: <script type="text/javascript" language="Javascript">
467: // <![CDATA[
468: var reseditbrowser;
1.1004 www 469: function openresbrowser(formname,reslink) {
1.1005 www 470: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 471: var title = 'Resource_Browser';
472: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 473: options += ',width=700,height=500';
1.1004 www 474: reseditbrowser = open(url,title,options,'1');
475: reseditbrowser.focus();
1.1003 www 476: }
477: // ]]>
478: </script>
1.1004 www 479: ENDRESBRW
1.1003 www 480: }
481:
1.74 www 482: sub selectstudent_link {
1.1075.2.143 raeburn 483: my ($form,$unameele,$udomele,$courseadv,$clickerid)=@_;
1.999 www 484: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
485: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
486: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 487: if ($env{'request.course.id'}) {
1.302 albertel 488: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
489: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
490: '/'.$env{'request.course.sec'})) {
1.111 www 491: return '';
492: }
1.999 www 493: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1075.2.143 raeburn 494: if ($courseadv eq 'only') {
495: $callargs .= ",'',1,'$courseadv'";
496: } elsif ($courseadv eq 'none') {
497: $callargs .= ",'','','$courseadv'";
498: } elsif ($courseadv eq 'condition') {
499: $callargs .= ",'','','$courseadv'";
1.793 raeburn 500: }
501: return '<span class="LC_nobreak">'.
502: '<a href="javascript:openstdbrowser('.$callargs.');">'.
503: &mt('Select User').'</a></span>';
1.74 www 504: }
1.258 albertel 505: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 506: $callargs .= ",'',1";
1.793 raeburn 507: return '<span class="LC_nobreak">'.
508: '<a href="javascript:openstdbrowser('.$callargs.');">'.
509: &mt('Select User').'</a></span>';
1.111 www 510: }
511: return '';
1.91 www 512: }
513:
1.1004 www 514: sub selectresource_link {
515: my ($form,$reslink,$arg)=@_;
516:
517: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
518: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
519: unless ($env{'request.course.id'}) { return $arg; }
520: return '<span class="LC_nobreak">'.
521: '<a href="javascript:openresbrowser('.$callargs.');">'.
522: $arg.'</a></span>';
523: }
524:
525:
526:
1.653 raeburn 527: sub authorbrowser_javascript {
528: return <<"ENDAUTHORBRW";
1.776 bisitz 529: <script type="text/javascript" language="JavaScript">
1.824 bisitz 530: // <![CDATA[
1.653 raeburn 531: var stdeditbrowser;
532:
533: function openauthorbrowser(formname,udom) {
534: var url = '/adm/pickauthor?';
535: url += 'form='+formname+'&roledom='+udom;
536: var title = 'Author_Browser';
537: var options = 'scrollbars=1,resizable=1,menubar=0';
538: options += ',width=700,height=600';
539: stdeditbrowser = open(url,title,options,'1');
540: stdeditbrowser.focus();
541: }
542:
1.824 bisitz 543: // ]]>
1.653 raeburn 544: </script>
545: ENDAUTHORBRW
546: }
547:
1.91 www 548: sub coursebrowser_javascript {
1.1075.2.31 raeburn 549: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1075.2.95 raeburn 550: $credits_element,$instcode) = @_;
1.932 raeburn 551: my $wintitle = 'Course_Browser';
1.931 raeburn 552: if ($crstype eq 'Community') {
1.932 raeburn 553: $wintitle = 'Community_Browser';
1.909 raeburn 554: }
1.876 raeburn 555: my $id_functions = &javascript_index_functions();
556: my $output = '
1.776 bisitz 557: <script type="text/javascript" language="JavaScript">
1.824 bisitz 558: // <![CDATA[
1.468 raeburn 559: var stdeditbrowser;'."\n";
1.876 raeburn 560:
561: $output .= <<"ENDSTDBRW";
1.909 raeburn 562: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 563: var url = '/adm/pickcourse?';
1.895 raeburn 564: var formid = getFormIdByName(formname);
1.876 raeburn 565: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 566: if (domainfilter != null) {
567: if (domainfilter != '') {
568: url += 'domainfilter='+domainfilter+'&';
569: }
570: }
1.91 www 571: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 572: '&cdomelement='+udom+
573: '&cnameelement='+desc;
1.468 raeburn 574: if (extra_element !=null && extra_element != '') {
1.594 raeburn 575: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 576: url += '&roleelement='+extra_element;
577: if (domainfilter == null || domainfilter == '') {
578: url += '&domainfilter='+extra_element;
579: }
1.234 raeburn 580: }
1.468 raeburn 581: else {
582: if (formname == 'portform') {
583: url += '&setroles='+extra_element;
1.800 raeburn 584: } else {
585: if (formname == 'rules') {
586: url += '&fixeddom='+extra_element;
587: }
1.468 raeburn 588: }
589: }
1.230 raeburn 590: }
1.909 raeburn 591: if (type != null && type != '') {
592: url += '&type='+type;
593: }
594: if (type_elem != null && type_elem != '') {
595: url += '&typeelement='+type_elem;
596: }
1.872 raeburn 597: if (formname == 'ccrs') {
598: var ownername = document.forms[formid].ccuname.value;
599: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1075.2.101 raeburn 600: url += '&cloner='+ownername+':'+ownerdom;
601: if (type == 'Course') {
602: url += '&crscode='+document.forms[formid].crscode.value;
603: }
1.1075.2.95 raeburn 604: }
605: if (formname == 'requestcrs') {
606: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 607: }
1.293 raeburn 608: if (multflag !=null && multflag != '') {
609: url += '&multiple='+multflag;
610: }
1.909 raeburn 611: var title = '$wintitle';
1.91 www 612: var options = 'scrollbars=1,resizable=1,menubar=0';
613: options += ',width=700,height=600';
614: stdeditbrowser = open(url,title,options,'1');
615: stdeditbrowser.focus();
616: }
1.876 raeburn 617: $id_functions
618: ENDSTDBRW
1.1075.2.31 raeburn 619: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
620: $output .= &setsec_javascript($sec_element,$formname,$role_element,
621: $credits_element);
1.876 raeburn 622: }
623: $output .= '
624: // ]]>
625: </script>';
626: return $output;
627: }
628:
629: sub javascript_index_functions {
630: return <<"ENDJS";
631:
632: function getFormIdByName(formname) {
633: for (var i=0;i<document.forms.length;i++) {
634: if (document.forms[i].name == formname) {
635: return i;
636: }
637: }
638: return -1;
639: }
640:
641: function getIndexByName(formid,item) {
642: for (var i=0;i<document.forms[formid].elements.length;i++) {
643: if (document.forms[formid].elements[i].name == item) {
644: return i;
645: }
646: }
647: return -1;
648: }
1.468 raeburn 649:
1.876 raeburn 650: function getDomainFromSelectbox(formname,udom) {
651: var userdom;
652: var formid = getFormIdByName(formname);
653: if (formid > -1) {
654: var domid = getIndexByName(formid,udom);
655: if (domid > -1) {
656: if (document.forms[formid].elements[domid].type == 'select-one') {
657: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
658: }
659: if (document.forms[formid].elements[domid].type == 'hidden') {
660: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 661: }
662: }
663: }
1.876 raeburn 664: return userdom;
665: }
666:
667: ENDJS
1.468 raeburn 668:
1.876 raeburn 669: }
670:
1.1017 raeburn 671: sub javascript_array_indexof {
1.1018 raeburn 672: return <<ENDJS;
1.1017 raeburn 673: <script type="text/javascript" language="JavaScript">
674: // <![CDATA[
675:
676: if (!Array.prototype.indexOf) {
677: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
678: "use strict";
679: if (this === void 0 || this === null) {
680: throw new TypeError();
681: }
682: var t = Object(this);
683: var len = t.length >>> 0;
684: if (len === 0) {
685: return -1;
686: }
687: var n = 0;
688: if (arguments.length > 0) {
689: n = Number(arguments[1]);
690: if (n !== n) { // shortcut for verifying if it's NaN
691: n = 0;
692: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
693: n = (n > 0 || -1) * Math.floor(Math.abs(n));
694: }
695: }
696: if (n >= len) {
697: return -1;
698: }
699: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
700: for (; k < len; k++) {
701: if (k in t && t[k] === searchElement) {
702: return k;
703: }
704: }
705: return -1;
706: }
707: }
708:
709: // ]]>
710: </script>
711:
712: ENDJS
713:
714: }
715:
1.876 raeburn 716: sub userbrowser_javascript {
717: my $id_functions = &javascript_index_functions();
718: return <<"ENDUSERBRW";
719:
1.888 raeburn 720: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 721: var url = '/adm/pickuser?';
722: var userdom = getDomainFromSelectbox(formname,udom);
723: if (userdom != null) {
724: if (userdom != '') {
725: url += 'srchdom='+userdom+'&';
726: }
727: }
728: url += 'form=' + formname + '&unameelement='+uname+
729: '&udomelement='+udom+
730: '&ulastelement='+ulast+
731: '&ufirstelement='+ufirst+
732: '&uemailelement='+uemail+
1.881 raeburn 733: '&hideudomelement='+hideudom+
734: '&coursedom='+crsdom;
1.888 raeburn 735: if ((caller != null) && (caller != undefined)) {
736: url += '&caller='+caller;
737: }
1.876 raeburn 738: var title = 'User_Browser';
739: var options = 'scrollbars=1,resizable=1,menubar=0';
740: options += ',width=700,height=600';
741: var stdeditbrowser = open(url,title,options,'1');
742: stdeditbrowser.focus();
743: }
744:
1.888 raeburn 745: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 746: var formid = getFormIdByName(formname);
747: if (formid > -1) {
1.888 raeburn 748: var unameid = getIndexByName(formid,uname);
1.876 raeburn 749: var domid = getIndexByName(formid,udom);
750: var hidedomid = getIndexByName(formid,origdom);
751: if (hidedomid > -1) {
752: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 753: var unameval = document.forms[formid].elements[unameid].value;
754: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
755: if (domid > -1) {
756: var slct = document.forms[formid].elements[domid];
757: if (slct.type == 'select-one') {
758: var i;
759: for (i=0;i<slct.length;i++) {
760: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
761: }
762: }
763: if (slct.type == 'hidden') {
764: slct.value = fixeddom;
1.876 raeburn 765: }
766: }
1.468 raeburn 767: }
768: }
769: }
1.876 raeburn 770: return;
771: }
772:
773: $id_functions
774: ENDUSERBRW
1.468 raeburn 775: }
776:
777: sub setsec_javascript {
1.1075.2.31 raeburn 778: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 779: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
780: $communityrolestr);
781: if ($role_element ne '') {
782: my @allroles = ('st','ta','ep','in','ad');
783: foreach my $crstype ('Course','Community') {
784: if ($crstype eq 'Community') {
785: foreach my $role (@allroles) {
786: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
787: }
788: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
789: } else {
790: foreach my $role (@allroles) {
791: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
792: }
793: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
794: }
795: }
796: $rolestr = '"'.join('","',@allroles).'"';
797: $courserolestr = '"'.join('","',@courserolenames).'"';
798: $communityrolestr = '"'.join('","',@communityrolenames).'"';
799: }
1.468 raeburn 800: my $setsections = qq|
801: function setSect(sectionlist) {
1.629 raeburn 802: var sectionsArray = new Array();
803: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
804: sectionsArray = sectionlist.split(",");
805: }
1.468 raeburn 806: var numSections = sectionsArray.length;
807: document.$formname.$sec_element.length = 0;
808: if (numSections == 0) {
809: document.$formname.$sec_element.multiple=false;
810: document.$formname.$sec_element.size=1;
811: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
812: } else {
813: if (numSections == 1) {
814: document.$formname.$sec_element.multiple=false;
815: document.$formname.$sec_element.size=1;
816: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
817: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
818: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
819: } else {
820: for (var i=0; i<numSections; i++) {
821: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
822: }
823: document.$formname.$sec_element.multiple=true
824: if (numSections < 3) {
825: document.$formname.$sec_element.size=numSections;
826: } else {
827: document.$formname.$sec_element.size=3;
828: }
829: document.$formname.$sec_element.options[0].selected = false
830: }
831: }
1.91 www 832: }
1.905 raeburn 833:
834: function setRole(crstype) {
1.468 raeburn 835: |;
1.905 raeburn 836: if ($role_element eq '') {
837: $setsections .= ' return;
838: }
839: ';
840: } else {
841: $setsections .= qq|
842: var elementLength = document.$formname.$role_element.length;
843: var allroles = Array($rolestr);
844: var courserolenames = Array($courserolestr);
845: var communityrolenames = Array($communityrolestr);
846: if (elementLength != undefined) {
847: if (document.$formname.$role_element.options[5].value == 'cc') {
848: if (crstype == 'Course') {
849: return;
850: } else {
851: allroles[5] = 'co';
852: for (var i=0; i<6; i++) {
853: document.$formname.$role_element.options[i].value = allroles[i];
854: document.$formname.$role_element.options[i].text = communityrolenames[i];
855: }
856: }
857: } else {
858: if (crstype == 'Community') {
859: return;
860: } else {
861: allroles[5] = 'cc';
862: for (var i=0; i<6; i++) {
863: document.$formname.$role_element.options[i].value = allroles[i];
864: document.$formname.$role_element.options[i].text = courserolenames[i];
865: }
866: }
867: }
868: }
869: return;
870: }
871: |;
872: }
1.1075.2.31 raeburn 873: if ($credits_element) {
874: $setsections .= qq|
875: function setCredits(defaultcredits) {
876: document.$formname.$credits_element.value = defaultcredits;
877: return;
878: }
879: |;
880: }
1.468 raeburn 881: return $setsections;
882: }
883:
1.91 www 884: sub selectcourse_link {
1.909 raeburn 885: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
886: $typeelement) = @_;
887: my $type = $selecttype;
1.871 raeburn 888: my $linktext = &mt('Select Course');
889: if ($selecttype eq 'Community') {
1.909 raeburn 890: $linktext = &mt('Select Community');
1.906 raeburn 891: } elsif ($selecttype eq 'Course/Community') {
892: $linktext = &mt('Select Course/Community');
1.909 raeburn 893: $type = '';
1.1019 raeburn 894: } elsif ($selecttype eq 'Select') {
895: $linktext = &mt('Select');
896: $type = '';
1.871 raeburn 897: }
1.787 bisitz 898: return '<span class="LC_nobreak">'
899: ."<a href='"
900: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
901: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 902: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 903: ."'>".$linktext.'</a>'
1.787 bisitz 904: .'</span>';
1.74 www 905: }
1.42 matthew 906:
1.653 raeburn 907: sub selectauthor_link {
908: my ($form,$udom)=@_;
909: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
910: &mt('Select Author').'</a>';
911: }
912:
1.876 raeburn 913: sub selectuser_link {
1.881 raeburn 914: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 915: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 916: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 917: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 918: ');">'.$linktext.'</a>';
1.876 raeburn 919: }
920:
1.273 raeburn 921: sub check_uncheck_jscript {
922: my $jscript = <<"ENDSCRT";
923: function checkAll(field) {
924: if (field.length > 0) {
925: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 926: if (!field[i].disabled) {
927: field[i].checked = true;
928: }
1.273 raeburn 929: }
930: } else {
1.1075.2.14 raeburn 931: if (!field.disabled) {
932: field.checked = true;
933: }
1.273 raeburn 934: }
935: }
936:
937: function uncheckAll(field) {
938: if (field.length > 0) {
939: for (i = 0; i < field.length; i++) {
940: field[i].checked = false ;
1.543 albertel 941: }
942: } else {
1.273 raeburn 943: field.checked = false ;
944: }
945: }
946: ENDSCRT
947: return $jscript;
948: }
949:
1.656 www 950: sub select_timezone {
1.1075.2.115 raeburn 951: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
952: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 953: if ($includeempty) {
954: $output .= '<option value=""';
955: if (($selected eq '') || ($selected eq 'local')) {
956: $output .= ' selected="selected" ';
957: }
958: $output .= '> </option>';
959: }
1.657 raeburn 960: my @timezones = DateTime::TimeZone->all_names;
961: foreach my $tzone (@timezones) {
962: $output.= '<option value="'.$tzone.'"';
963: if ($tzone eq $selected) {
964: $output.=' selected="selected"';
965: }
966: $output.=">$tzone</option>\n";
1.656 www 967: }
968: $output.="</select>";
969: return $output;
970: }
1.273 raeburn 971:
1.687 raeburn 972: sub select_datelocale {
1.1075.2.115 raeburn 973: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
974: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 975: if ($includeempty) {
976: $output .= '<option value=""';
977: if ($selected eq '') {
978: $output .= ' selected="selected" ';
979: }
980: $output .= '> </option>';
981: }
1.1075.2.102 raeburn 982: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 983: my (@possibles,%locale_names);
1.1075.2.102 raeburn 984: my @locales = DateTime::Locale->ids();
985: foreach my $id (@locales) {
986: if ($id ne '') {
987: my ($en_terr,$native_terr);
988: my $loc = DateTime::Locale->load($id);
989: if (ref($loc)) {
990: $en_terr = $loc->name();
991: $native_terr = $loc->native_name();
1.687 raeburn 992: if (grep(/^en$/,@languages) || !@languages) {
993: if ($en_terr ne '') {
994: $locale_names{$id} = '('.$en_terr.')';
995: } elsif ($native_terr ne '') {
996: $locale_names{$id} = $native_terr;
997: }
998: } else {
999: if ($native_terr ne '') {
1000: $locale_names{$id} = $native_terr.' ';
1001: } elsif ($en_terr ne '') {
1002: $locale_names{$id} = '('.$en_terr.')';
1003: }
1004: }
1.1075.2.94 raeburn 1005: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1075.2.102 raeburn 1006: push(@possibles,$id);
1.687 raeburn 1007: }
1008: }
1009: }
1010: foreach my $item (sort(@possibles)) {
1011: $output.= '<option value="'.$item.'"';
1012: if ($item eq $selected) {
1013: $output.=' selected="selected"';
1014: }
1015: $output.=">$item";
1016: if ($locale_names{$item} ne '') {
1.1075.2.94 raeburn 1017: $output.=' '.$locale_names{$item};
1.687 raeburn 1018: }
1019: $output.="</option>\n";
1020: }
1021: $output.="</select>";
1022: return $output;
1023: }
1024:
1.792 raeburn 1025: sub select_language {
1.1075.2.115 raeburn 1026: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1027: my %langchoices;
1028: if ($includeempty) {
1.1075.2.32 raeburn 1029: %langchoices = ('' => 'No language preference');
1.792 raeburn 1030: }
1031: foreach my $id (&languageids()) {
1032: my $code = &supportedlanguagecode($id);
1033: if ($code) {
1034: $langchoices{$code} = &plainlanguagedescription($id);
1035: }
1036: }
1.1075.2.32 raeburn 1037: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1075.2.115 raeburn 1038: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1039: }
1040:
1.42 matthew 1041: =pod
1.36 matthew 1042:
1.648 raeburn 1043: =item * &linked_select_forms(...)
1.36 matthew 1044:
1045: linked_select_forms returns a string containing a <script></script> block
1046: and html for two <select> menus. The select menus will be linked in that
1047: changing the value of the first menu will result in new values being placed
1048: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1049: order unless a defined order is provided.
1.36 matthew 1050:
1051: linked_select_forms takes the following ordered inputs:
1052:
1053: =over 4
1054:
1.112 bowersj2 1055: =item * $formname, the name of the <form> tag
1.36 matthew 1056:
1.112 bowersj2 1057: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1058:
1.112 bowersj2 1059: =item * $firstdefault, the default value for the first menu
1.36 matthew 1060:
1.112 bowersj2 1061: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1062:
1.112 bowersj2 1063: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1064:
1.112 bowersj2 1065: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1066:
1.609 raeburn 1067: =item * $menuorder, the order of values in the first menu
1068:
1.1075.2.31 raeburn 1069: =item * $onchangefirst, additional javascript call to execute for an onchange
1070: event for the first <select> tag
1071:
1072: =item * $onchangesecond, additional javascript call to execute for an onchange
1073: event for the second <select> tag
1074:
1.41 ng 1075: =back
1076:
1.36 matthew 1077: Below is an example of such a hash. Only the 'text', 'default', and
1078: 'select2' keys must appear as stated. keys(%menu) are the possible
1079: values for the first select menu. The text that coincides with the
1.41 ng 1080: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1081: and text for the second menu are given in the hash pointed to by
1082: $menu{$choice1}->{'select2'}.
1083:
1.112 bowersj2 1084: my %menu = ( A1 => { text =>"Choice A1" ,
1085: default => "B3",
1086: select2 => {
1087: B1 => "Choice B1",
1088: B2 => "Choice B2",
1089: B3 => "Choice B3",
1090: B4 => "Choice B4"
1.609 raeburn 1091: },
1092: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1093: },
1094: A2 => { text =>"Choice A2" ,
1095: default => "C2",
1096: select2 => {
1097: C1 => "Choice C1",
1098: C2 => "Choice C2",
1099: C3 => "Choice C3"
1.609 raeburn 1100: },
1101: order => ['C2','C1','C3'],
1.112 bowersj2 1102: },
1103: A3 => { text =>"Choice A3" ,
1104: default => "D6",
1105: select2 => {
1106: D1 => "Choice D1",
1107: D2 => "Choice D2",
1108: D3 => "Choice D3",
1109: D4 => "Choice D4",
1110: D5 => "Choice D5",
1111: D6 => "Choice D6",
1112: D7 => "Choice D7"
1.609 raeburn 1113: },
1114: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1115: }
1116: );
1.36 matthew 1117:
1118: =cut
1119:
1120: sub linked_select_forms {
1121: my ($formname,
1122: $middletext,
1123: $firstdefault,
1124: $firstselectname,
1125: $secondselectname,
1.609 raeburn 1126: $hashref,
1127: $menuorder,
1.1075.2.31 raeburn 1128: $onchangefirst,
1129: $onchangesecond
1.36 matthew 1130: ) = @_;
1131: my $second = "document.$formname.$secondselectname";
1132: my $first = "document.$formname.$firstselectname";
1133: # output the javascript to do the changing
1134: my $result = '';
1.776 bisitz 1135: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1136: $result.="// <![CDATA[\n";
1.36 matthew 1137: $result.="var select2data = new Object();\n";
1138: $" = '","';
1139: my $debug = '';
1140: foreach my $s1 (sort(keys(%$hashref))) {
1141: $result.="select2data.d_$s1 = new Object();\n";
1142: $result.="select2data.d_$s1.def = new String('".
1143: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1144: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1145: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1146: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1147: @s2values = @{$hashref->{$s1}->{'order'}};
1148: }
1.36 matthew 1149: $result.="\"@s2values\");\n";
1150: $result.="select2data.d_$s1.texts = new Array(";
1151: my @s2texts;
1152: foreach my $value (@s2values) {
1.1075.2.119 raeburn 1153: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1154: }
1155: $result.="\"@s2texts\");\n";
1156: }
1157: $"=' ';
1158: $result.= <<"END";
1159:
1160: function select1_changed() {
1161: // Determine new choice
1162: var newvalue = "d_" + $first.value;
1163: // update select2
1164: var values = select2data[newvalue].values;
1165: var texts = select2data[newvalue].texts;
1166: var select2def = select2data[newvalue].def;
1167: var i;
1168: // out with the old
1169: for (i = 0; i < $second.options.length; i++) {
1170: $second.options[i] = null;
1171: }
1172: // in with the nuclear
1173: for (i=0;i<values.length; i++) {
1174: $second.options[i] = new Option(values[i]);
1.143 matthew 1175: $second.options[i].value = values[i];
1.36 matthew 1176: $second.options[i].text = texts[i];
1177: if (values[i] == select2def) {
1178: $second.options[i].selected = true;
1179: }
1180: }
1181: }
1.824 bisitz 1182: // ]]>
1.36 matthew 1183: </script>
1184: END
1185: # output the initial values for the selection lists
1.1075.2.31 raeburn 1186: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1187: my @order = sort(keys(%{$hashref}));
1188: if (ref($menuorder) eq 'ARRAY') {
1189: @order = @{$menuorder};
1190: }
1191: foreach my $value (@order) {
1.36 matthew 1192: $result.=" <option value=\"$value\" ";
1.253 albertel 1193: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1194: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1195: }
1196: $result .= "</select>\n";
1197: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1198: $result .= $middletext;
1.1075.2.31 raeburn 1199: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1200: if ($onchangesecond) {
1201: $result .= ' onchange="'.$onchangesecond.'"';
1202: }
1203: $result .= ">\n";
1.36 matthew 1204: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1205:
1206: my @secondorder = sort(keys(%select2));
1207: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1208: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1209: }
1210: foreach my $value (@secondorder) {
1.36 matthew 1211: $result.=" <option value=\"$value\" ";
1.253 albertel 1212: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1213: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1214: }
1215: $result .= "</select>\n";
1216: # return $debug;
1217: return $result;
1218: } # end of sub linked_select_forms {
1219:
1.45 matthew 1220: =pod
1.44 bowersj2 1221:
1.973 raeburn 1222: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1223:
1.112 bowersj2 1224: Returns a string corresponding to an HTML link to the given help
1225: $topic, where $topic corresponds to the name of a .tex file in
1226: /home/httpd/html/adm/help/tex, with underscores replaced by
1227: spaces.
1228:
1229: $text will optionally be linked to the same topic, allowing you to
1230: link text in addition to the graphic. If you do not want to link
1231: text, but wish to specify one of the later parameters, pass an
1232: empty string.
1233:
1234: $stayOnPage is a value that will be interpreted as a boolean. If true,
1235: the link will not open a new window. If false, the link will open
1236: a new window using Javascript. (Default is false.)
1237:
1238: $width and $height are optional numerical parameters that will
1239: override the width and height of the popped up window, which may
1.973 raeburn 1240: be useful for certain help topics with big pictures included.
1241:
1242: $imgid is the id of the img tag used for the help icon. This may be
1243: used in a javascript call to switch the image src. See
1244: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1245:
1246: =cut
1247:
1248: sub help_open_topic {
1.973 raeburn 1249: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1250: $text = "" if (not defined $text);
1.44 bowersj2 1251: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1252: $width = 500 if (not defined $width);
1.44 bowersj2 1253: $height = 400 if (not defined $height);
1254: my $filename = $topic;
1255: $filename =~ s/ /_/g;
1256:
1.48 bowersj2 1257: my $template = "";
1258: my $link;
1.572 banghart 1259:
1.159 www 1260: $topic=~s/\W/\_/g;
1.44 bowersj2 1261:
1.572 banghart 1262: if (!$stayOnPage) {
1.1075.2.50 raeburn 1263: if ($env{'browser.mobile'}) {
1264: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1265: } else {
1266: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1267: }
1.1037 www 1268: } elsif ($stayOnPage eq 'popup') {
1269: $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 1270: } else {
1.48 bowersj2 1271: $link = "/adm/help/${filename}.hlp";
1272: }
1273:
1274: # Add the text
1.755 neumanie 1275: if ($text ne "") {
1.763 bisitz 1276: $template.='<span class="LC_help_open_topic">'
1277: .'<a target="_top" href="'.$link.'">'
1278: .$text.'</a>';
1.48 bowersj2 1279: }
1280:
1.763 bisitz 1281: # (Always) Add the graphic
1.179 matthew 1282: my $title = &mt('Online Help');
1.667 raeburn 1283: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1284: if ($imgid ne '') {
1285: $imgid = ' id="'.$imgid.'"';
1286: }
1.763 bisitz 1287: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1288: .'<img src="'.$helpicon.'" border="0"'
1289: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1290: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1291: .' /></a>';
1292: if ($text ne "") {
1293: $template.='</span>';
1294: }
1.44 bowersj2 1295: return $template;
1296:
1.106 bowersj2 1297: }
1298:
1299: # This is a quicky function for Latex cheatsheet editing, since it
1300: # appears in at least four places
1301: sub helpLatexCheatsheet {
1.1037 www 1302: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1303: my $out;
1.106 bowersj2 1304: my $addOther = '';
1.732 raeburn 1305: if ($topic) {
1.1037 www 1306: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1307: }
1308: $out = '<span>' # Start cheatsheet
1309: .$addOther
1310: .'<span>'
1.1037 www 1311: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1312: .'</span> <span>'
1.1037 www 1313: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1314: .'</span>';
1.732 raeburn 1315: unless ($not_author) {
1.763 bisitz 1316: $out .= ' <span>'
1.1037 www 1317: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1318: .'</span> <span>'
1.1075.2.78 raeburn 1319: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1320: .'</span>';
1.732 raeburn 1321: }
1.763 bisitz 1322: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1323: return $out;
1.172 www 1324: }
1325:
1.430 albertel 1326: sub general_help {
1327: my $helptopic='Student_Intro';
1328: if ($env{'request.role'}=~/^(ca|au)/) {
1329: $helptopic='Authoring_Intro';
1.907 raeburn 1330: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1331: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1332: } elsif ($env{'request.role'}=~/^dc/) {
1333: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1334: }
1335: return $helptopic;
1336: }
1337:
1338: sub update_help_link {
1339: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1340: my $origurl = $ENV{'REQUEST_URI'};
1341: $origurl=~s|^/~|/priv/|;
1342: my $timestamp = time;
1343: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1344: $$datum = &escape($$datum);
1345: }
1346:
1347: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1348: my $output .= <<"ENDOUTPUT";
1349: <script type="text/javascript">
1.824 bisitz 1350: // <![CDATA[
1.430 albertel 1351: banner_link = '$banner_link';
1.824 bisitz 1352: // ]]>
1.430 albertel 1353: </script>
1354: ENDOUTPUT
1355: return $output;
1356: }
1357:
1358: # now just updates the help link and generates a blue icon
1.193 raeburn 1359: sub help_open_menu {
1.430 albertel 1360: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1361: = @_;
1.949 droeschl 1362: $stayOnPage = 1;
1.430 albertel 1363: my $output;
1364: if ($component_help) {
1365: if (!$text) {
1366: $output=&help_open_topic($component_help,undef,$stayOnPage,
1367: $width,$height);
1368: } else {
1369: my $help_text;
1370: $help_text=&unescape($topic);
1371: $output='<table><tr><td>'.
1372: &help_open_topic($component_help,$help_text,$stayOnPage,
1373: $width,$height).'</td></tr></table>';
1374: }
1375: }
1376: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1377: return $output.$banner_link;
1378: }
1379:
1380: sub top_nav_help {
1.1075.2.158 raeburn 1381: my ($text,$linkattr) = @_;
1.436 albertel 1382: $text = &mt($text);
1.1075.2.60 raeburn 1383: my $stay_on_page;
1384: unless ($env{'environment.remote'} eq 'on') {
1385: $stay_on_page = 1;
1386: }
1.1075.2.61 raeburn 1387: my ($link,$banner_link);
1388: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1389: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1390: : "javascript:helpMenu('open')";
1391: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1392: }
1.201 raeburn 1393: my $title = &mt('Get help');
1.1075.2.61 raeburn 1394: if ($link) {
1395: return <<"END";
1.436 albertel 1396: $banner_link
1.1075.2.158 raeburn 1397: <a href="$link" title="$title" $linkattr>$text</a>
1.436 albertel 1398: END
1.1075.2.61 raeburn 1399: } else {
1400: return ' '.$text.' ';
1401: }
1.436 albertel 1402: }
1403:
1404: sub help_menu_js {
1.1075.2.52 raeburn 1405: my ($httphost) = @_;
1.949 droeschl 1406: my $stayOnPage = 1;
1.436 albertel 1407: my $width = 620;
1408: my $height = 600;
1.430 albertel 1409: my $helptopic=&general_help();
1.1075.2.52 raeburn 1410: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1411: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1412: my $start_page =
1413: &Apache::loncommon::start_page('Help Menu', undef,
1414: {'frameset' => 1,
1415: 'js_ready' => 1,
1.1075.2.136 raeburn 1416: 'use_absolute' => $httphost,
1.331 albertel 1417: 'add_entries' => {
1418: 'border' => '0',
1.579 raeburn 1419: 'rows' => "110,*",},});
1.331 albertel 1420: my $end_page =
1421: &Apache::loncommon::end_page({'frameset' => 1,
1422: 'js_ready' => 1,});
1423:
1.436 albertel 1424: my $template .= <<"ENDTEMPLATE";
1425: <script type="text/javascript">
1.877 bisitz 1426: // <![CDATA[
1.253 albertel 1427: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1428: var banner_link = '';
1.243 raeburn 1429: function helpMenu(target) {
1430: var caller = this;
1431: if (target == 'open') {
1432: var newWindow = null;
1433: try {
1.262 albertel 1434: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1435: }
1436: catch(error) {
1437: writeHelp(caller);
1438: return;
1439: }
1440: if (newWindow) {
1441: caller = newWindow;
1442: }
1.193 raeburn 1443: }
1.243 raeburn 1444: writeHelp(caller);
1445: return;
1446: }
1447: function writeHelp(caller) {
1.1075.2.61 raeburn 1448: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1449: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1450: caller.document.close();
1451: caller.focus();
1.193 raeburn 1452: }
1.877 bisitz 1453: // END LON-CAPA Internal -->
1.253 albertel 1454: // ]]>
1.436 albertel 1455: </script>
1.193 raeburn 1456: ENDTEMPLATE
1457: return $template;
1458: }
1459:
1.172 www 1460: sub help_open_bug {
1461: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1462: unless ($env{'user.adv'}) { return ''; }
1.172 www 1463: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1464: $text = "" if (not defined $text);
1465: $stayOnPage=1;
1.184 albertel 1466: $width = 600 if (not defined $width);
1467: $height = 600 if (not defined $height);
1.172 www 1468:
1469: $topic=~s/\W+/\+/g;
1470: my $link='';
1471: my $template='';
1.379 albertel 1472: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1473: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1474: if (!$stayOnPage)
1475: {
1476: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1477: }
1478: else
1479: {
1480: $link = $url;
1481: }
1482: # Add the text
1483: if ($text ne "")
1484: {
1485: $template .=
1486: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1487: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1488: }
1489:
1490: # Add the graphic
1.179 matthew 1491: my $title = &mt('Report a Bug');
1.215 albertel 1492: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1493: $template .= <<"ENDTEMPLATE";
1.436 albertel 1494: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1495: ENDTEMPLATE
1496: if ($text ne '') { $template.='</td></tr></table>' };
1497: return $template;
1498:
1499: }
1500:
1501: sub help_open_faq {
1502: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1503: unless ($env{'user.adv'}) { return ''; }
1.172 www 1504: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1505: $text = "" if (not defined $text);
1506: $stayOnPage=1;
1507: $width = 350 if (not defined $width);
1508: $height = 400 if (not defined $height);
1509:
1510: $topic=~s/\W+/\+/g;
1511: my $link='';
1512: my $template='';
1513: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1514: if (!$stayOnPage)
1515: {
1516: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1517: }
1518: else
1519: {
1520: $link = $url;
1521: }
1522:
1523: # Add the text
1524: if ($text ne "")
1525: {
1526: $template .=
1.173 www 1527: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1528: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1529: }
1530:
1531: # Add the graphic
1.179 matthew 1532: my $title = &mt('View the FAQ');
1.215 albertel 1533: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1534: $template .= <<"ENDTEMPLATE";
1.436 albertel 1535: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1536: ENDTEMPLATE
1537: if ($text ne '') { $template.='</td></tr></table>' };
1538: return $template;
1539:
1.44 bowersj2 1540: }
1.37 matthew 1541:
1.180 matthew 1542: ###############################################################
1543: ###############################################################
1544:
1.45 matthew 1545: =pod
1546:
1.648 raeburn 1547: =item * &change_content_javascript():
1.256 matthew 1548:
1549: This and the next function allow you to create small sections of an
1550: otherwise static HTML page that you can update on the fly with
1551: Javascript, even in Netscape 4.
1552:
1553: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1554: must be written to the HTML page once. It will prove the Javascript
1555: function "change(name, content)". Calling the change function with the
1556: name of the section
1557: you want to update, matching the name passed to C<changable_area>, and
1558: the new content you want to put in there, will put the content into
1559: that area.
1560:
1561: B<Note>: Netscape 4 only reserves enough space for the changable area
1562: to contain room for the original contents. You need to "make space"
1563: for whatever changes you wish to make, and be B<sure> to check your
1564: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1565: it's adequate for updating a one-line status display, but little more.
1566: This script will set the space to 100% width, so you only need to
1567: worry about height in Netscape 4.
1568:
1569: Modern browsers are much less limiting, and if you can commit to the
1570: user not using Netscape 4, this feature may be used freely with
1571: pretty much any HTML.
1572:
1573: =cut
1574:
1575: sub change_content_javascript {
1576: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1577: if ($env{'browser.type'} eq 'netscape' &&
1578: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1579: return (<<NETSCAPE4);
1580: function change(name, content) {
1581: doc = document.layers[name+"___escape"].layers[0].document;
1582: doc.open();
1583: doc.write(content);
1584: doc.close();
1585: }
1586: NETSCAPE4
1587: } else {
1588: # Otherwise, we need to use semi-standards-compliant code
1589: # (technically, "innerHTML" isn't standard but the equivalent
1590: # is really scary, and every useful browser supports it
1591: return (<<DOMBASED);
1592: function change(name, content) {
1593: element = document.getElementById(name);
1594: element.innerHTML = content;
1595: }
1596: DOMBASED
1597: }
1598: }
1599:
1600: =pod
1601:
1.648 raeburn 1602: =item * &changable_area($name,$origContent):
1.256 matthew 1603:
1604: This provides a "changable area" that can be modified on the fly via
1605: the Javascript code provided in C<change_content_javascript>. $name is
1606: the name you will use to reference the area later; do not repeat the
1607: same name on a given HTML page more then once. $origContent is what
1608: the area will originally contain, which can be left blank.
1609:
1610: =cut
1611:
1612: sub changable_area {
1613: my ($name, $origContent) = @_;
1614:
1.258 albertel 1615: if ($env{'browser.type'} eq 'netscape' &&
1616: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1617: # If this is netscape 4, we need to use the Layer tag
1618: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1619: } else {
1620: return "<span id='$name'>$origContent</span>";
1621: }
1622: }
1623:
1624: =pod
1625:
1.648 raeburn 1626: =item * &viewport_geometry_js
1.590 raeburn 1627:
1628: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1629:
1630: =cut
1631:
1632:
1633: sub viewport_geometry_js {
1634: return <<"GEOMETRY";
1635: var Geometry = {};
1636: function init_geometry() {
1637: if (Geometry.init) { return };
1638: Geometry.init=1;
1639: if (window.innerHeight) {
1640: Geometry.getViewportHeight = function() { return window.innerHeight; };
1641: Geometry.getViewportWidth = function() { return window.innerWidth; };
1642: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1643: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1644: }
1645: else if (document.documentElement && document.documentElement.clientHeight) {
1646: Geometry.getViewportHeight =
1647: function() { return document.documentElement.clientHeight; };
1648: Geometry.getViewportWidth =
1649: function() { return document.documentElement.clientWidth; };
1650:
1651: Geometry.getHorizontalScroll =
1652: function() { return document.documentElement.scrollLeft; };
1653: Geometry.getVerticalScroll =
1654: function() { return document.documentElement.scrollTop; };
1655: }
1656: else if (document.body.clientHeight) {
1657: Geometry.getViewportHeight =
1658: function() { return document.body.clientHeight; };
1659: Geometry.getViewportWidth =
1660: function() { return document.body.clientWidth; };
1661: Geometry.getHorizontalScroll =
1662: function() { return document.body.scrollLeft; };
1663: Geometry.getVerticalScroll =
1664: function() { return document.body.scrollTop; };
1665: }
1666: }
1667:
1668: GEOMETRY
1669: }
1670:
1671: =pod
1672:
1.648 raeburn 1673: =item * &viewport_size_js()
1.590 raeburn 1674:
1675: 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.
1676:
1677: =cut
1678:
1679: sub viewport_size_js {
1680: my $geometry = &viewport_geometry_js();
1681: return <<"DIMS";
1682:
1683: $geometry
1684:
1685: function getViewportDims(width,height) {
1686: init_geometry();
1687: width.value = Geometry.getViewportWidth();
1688: height.value = Geometry.getViewportHeight();
1689: return;
1690: }
1691:
1692: DIMS
1693: }
1694:
1695: =pod
1696:
1.648 raeburn 1697: =item * &resize_textarea_js()
1.565 albertel 1698:
1699: emits the needed javascript to resize a textarea to be as big as possible
1700:
1701: creates a function resize_textrea that takes two IDs first should be
1702: the id of the element to resize, second should be the id of a div that
1703: surrounds everything that comes after the textarea, this routine needs
1704: to be attached to the <body> for the onload and onresize events.
1705:
1.648 raeburn 1706: =back
1.565 albertel 1707:
1708: =cut
1709:
1710: sub resize_textarea_js {
1.590 raeburn 1711: my $geometry = &viewport_geometry_js();
1.565 albertel 1712: return <<"RESIZE";
1713: <script type="text/javascript">
1.824 bisitz 1714: // <![CDATA[
1.590 raeburn 1715: $geometry
1.565 albertel 1716:
1.588 albertel 1717: function getX(element) {
1718: var x = 0;
1719: while (element) {
1720: x += element.offsetLeft;
1721: element = element.offsetParent;
1722: }
1723: return x;
1724: }
1725: function getY(element) {
1726: var y = 0;
1727: while (element) {
1728: y += element.offsetTop;
1729: element = element.offsetParent;
1730: }
1731: return y;
1732: }
1733:
1734:
1.565 albertel 1735: function resize_textarea(textarea_id,bottom_id) {
1736: init_geometry();
1737: var textarea = document.getElementById(textarea_id);
1738: //alert(textarea);
1739:
1.588 albertel 1740: var textarea_top = getY(textarea);
1.565 albertel 1741: var textarea_height = textarea.offsetHeight;
1742: var bottom = document.getElementById(bottom_id);
1.588 albertel 1743: var bottom_top = getY(bottom);
1.565 albertel 1744: var bottom_height = bottom.offsetHeight;
1745: var window_height = Geometry.getViewportHeight();
1.588 albertel 1746: var fudge = 23;
1.565 albertel 1747: var new_height = window_height-fudge-textarea_top-bottom_height;
1748: if (new_height < 300) {
1749: new_height = 300;
1750: }
1751: textarea.style.height=new_height+'px';
1752: }
1.824 bisitz 1753: // ]]>
1.565 albertel 1754: </script>
1755: RESIZE
1756:
1757: }
1758:
1.1075.2.112 raeburn 1759: sub colorfuleditor_js {
1760: return <<"COLORFULEDIT"
1761: <script type="text/javascript">
1762: // <![CDATA[>
1763: function fold_box(curDepth, lastresource){
1764:
1765: // we need a list because there can be several blocks you need to fold in one tag
1766: var block = document.getElementsByName('foldblock_'+curDepth);
1767: // but there is only one folding button per tag
1768: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1769:
1770: if(block.item(0).style.display == 'none'){
1771:
1772: foldbutton.value = '@{[&mt("Hide")]}';
1773: for (i = 0; i < block.length; i++){
1774: block.item(i).style.display = '';
1775: }
1776: }else{
1777:
1778: foldbutton.value = '@{[&mt("Show")]}';
1779: for (i = 0; i < block.length; i++){
1780: // block.item(i).style.visibility = 'collapse';
1781: block.item(i).style.display = 'none';
1782: }
1783: };
1784: saveState(lastresource);
1785: }
1786:
1787: function saveState (lastresource) {
1788:
1789: var tag_list = getTagList();
1790: if(tag_list != null){
1791: var timestamp = new Date().getTime();
1792: var key = lastresource;
1793:
1794: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1795: // starting with timestamp
1796: var value = timestamp+';';
1797:
1798: // building the list of key-value pairs
1799: for(var i = 0; i < tag_list.length; i++){
1800: value += tag_list[i]+',';
1801: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1802: }
1803:
1804: // only iterate whole storage if nothing to override
1805: if(localStorage.getItem(key) == null){
1806:
1807: // prevent storage from growing large
1808: if(localStorage.length > 50){
1809: var regex_getTimestamp = /^(?:\d)+;/;
1810: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1811: var oldest_key;
1812:
1813: for(var i = 1; i < localStorage.length; i++){
1814: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1815: oldest_key = localStorage.key(i);
1816: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1817: }
1818: }
1819: localStorage.removeItem(oldest_key);
1820: }
1821: }
1822: localStorage.setItem(key,value);
1823: }
1824: }
1825:
1826: // restore folding status of blocks (on page load)
1827: function restoreState (lastresource) {
1828: if(localStorage.getItem(lastresource) != null){
1829: var key = lastresource;
1830: var value = localStorage.getItem(key);
1831: var regex_delTimestamp = /^\d+;/;
1832:
1833: value.replace(regex_delTimestamp, '');
1834:
1835: var valueArr = value.split(';');
1836: var pairs;
1837: var elements;
1838: for (var i = 0; i < valueArr.length; i++){
1839: pairs = valueArr[i].split(',');
1840: elements = document.getElementsByName(pairs[0]);
1841:
1842: for (var j = 0; j < elements.length; j++){
1843: elements[j].style.display = pairs[1];
1844: if (pairs[1] == "none"){
1845: var regex_id = /([_\\d]+)\$/;
1846: regex_id.exec(pairs[0]);
1847: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1848: }
1849: }
1850: }
1851: }
1852: }
1853:
1854: function getTagList () {
1855:
1856: var stringToSearch = document.lonhomework.innerHTML;
1857:
1858: var ret = new Array();
1859: var regex_findBlock = /(foldblock_.*?)"/g;
1860: var tag_list = stringToSearch.match(regex_findBlock);
1861:
1862: if(tag_list != null){
1863: for(var i = 0; i < tag_list.length; i++){
1864: ret.push(tag_list[i].replace(/"/, ''));
1865: }
1866: }
1867: return ret;
1868: }
1869:
1870: function saveScrollPosition (resource) {
1871: var tag_list = getTagList();
1872:
1873: // we dont always want to jump to the first block
1874: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1875: if(\$(window).scrollTop() > 170){
1876: if(tag_list != null){
1877: var result;
1878: for(var i = 0; i < tag_list.length; i++){
1879: if(isElementInViewport(tag_list[i])){
1880: result += tag_list[i]+';';
1881: }
1882: }
1883: sessionStorage.setItem('anchor_'+resource, result);
1884: }
1885: } else {
1886: // we dont need to save zero, just delete the item to leave everything tidy
1887: sessionStorage.removeItem('anchor_'+resource);
1888: }
1889: }
1890:
1891: function restoreScrollPosition(resource){
1892:
1893: var elem = sessionStorage.getItem('anchor_'+resource);
1894: if(elem != null){
1895: var tag_list = elem.split(';');
1896: var elem_list;
1897:
1898: for(var i = 0; i < tag_list.length; i++){
1899: elem_list = document.getElementsByName(tag_list[i]);
1900:
1901: if(elem_list.length > 0){
1902: elem = elem_list[0];
1903: break;
1904: }
1905: }
1906: elem.scrollIntoView();
1907: }
1908: }
1909:
1910: function isElementInViewport(el) {
1911:
1912: // change to last element instead of first
1913: var elem = document.getElementsByName(el);
1914: var rect = elem[0].getBoundingClientRect();
1915:
1916: return (
1917: rect.top >= 0 &&
1918: rect.left >= 0 &&
1919: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1920: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1921: );
1922: }
1923:
1924: function autosize(depth){
1925: var cmInst = window['cm'+depth];
1926: var fitsizeButton = document.getElementById('fitsize'+depth);
1927:
1928: // is fixed size, switching to dynamic
1929: if (sessionStorage.getItem("autosized_"+depth) == null) {
1930: cmInst.setSize("","auto");
1931: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1932: sessionStorage.setItem("autosized_"+depth, "yes");
1933:
1934: // is dynamic size, switching to fixed
1935: } else {
1936: cmInst.setSize("","300px");
1937: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1938: sessionStorage.removeItem("autosized_"+depth);
1939: }
1940: }
1941:
1942:
1943:
1944: // ]]>
1945: </script>
1946: COLORFULEDIT
1947: }
1948:
1949: sub xmleditor_js {
1950: return <<XMLEDIT
1951: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1952: <script type="text/javascript">
1953: // <![CDATA[>
1954:
1955: function saveScrollPosition (resource) {
1956:
1957: var scrollPos = \$(window).scrollTop();
1958: sessionStorage.setItem(resource,scrollPos);
1959: }
1960:
1961: function restoreScrollPosition(resource){
1962:
1963: var scrollPos = sessionStorage.getItem(resource);
1964: \$(window).scrollTop(scrollPos);
1965: }
1966:
1967: // unless internet explorer
1968: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1969:
1970: \$(document).ready(function() {
1971: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1972: });
1973: }
1974:
1975: // inserts text at cursor position into codemirror (xml editor only)
1976: function insertText(text){
1977: cm.focus();
1978: var curPos = cm.getCursor();
1979: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1980: }
1981: // ]]>
1982: </script>
1983: XMLEDIT
1984: }
1985:
1986: sub insert_folding_button {
1987: my $curDepth = $Apache::lonxml::curdepth;
1988: my $lastresource = $env{'request.ambiguous'};
1989:
1990: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
1991: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
1992: }
1993:
1994:
1.565 albertel 1995: =pod
1996:
1.256 matthew 1997: =head1 Excel and CSV file utility routines
1998:
1999: =cut
2000:
2001: ###############################################################
2002: ###############################################################
2003:
2004: =pod
2005:
1.1075.2.56 raeburn 2006: =over 4
2007:
1.648 raeburn 2008: =item * &csv_translate($text)
1.37 matthew 2009:
1.185 www 2010: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2011: format.
2012:
2013: =cut
2014:
1.180 matthew 2015: ###############################################################
2016: ###############################################################
1.37 matthew 2017: sub csv_translate {
2018: my $text = shift;
2019: $text =~ s/\"/\"\"/g;
1.209 albertel 2020: $text =~ s/\n/ /g;
1.37 matthew 2021: return $text;
2022: }
1.180 matthew 2023:
2024: ###############################################################
2025: ###############################################################
2026:
2027: =pod
2028:
1.648 raeburn 2029: =item * &define_excel_formats()
1.180 matthew 2030:
2031: Define some commonly used Excel cell formats.
2032:
2033: Currently supported formats:
2034:
2035: =over 4
2036:
2037: =item header
2038:
2039: =item bold
2040:
2041: =item h1
2042:
2043: =item h2
2044:
2045: =item h3
2046:
1.256 matthew 2047: =item h4
2048:
2049: =item i
2050:
1.180 matthew 2051: =item date
2052:
2053: =back
2054:
2055: Inputs: $workbook
2056:
2057: Returns: $format, a hash reference.
2058:
1.1057 foxr 2059:
1.180 matthew 2060: =cut
2061:
2062: ###############################################################
2063: ###############################################################
2064: sub define_excel_formats {
2065: my ($workbook) = @_;
2066: my $format;
2067: $format->{'header'} = $workbook->add_format(bold => 1,
2068: bottom => 1,
2069: align => 'center');
2070: $format->{'bold'} = $workbook->add_format(bold=>1);
2071: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2072: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2073: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2074: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2075: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2076: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2077: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2078: return $format;
2079: }
2080:
2081: ###############################################################
2082: ###############################################################
1.113 bowersj2 2083:
2084: =pod
2085:
1.648 raeburn 2086: =item * &create_workbook()
1.255 matthew 2087:
2088: Create an Excel worksheet. If it fails, output message on the
2089: request object and return undefs.
2090:
2091: Inputs: Apache request object
2092:
2093: Returns (undef) on failure,
2094: Excel worksheet object, scalar with filename, and formats
2095: from &Apache::loncommon::define_excel_formats on success
2096:
2097: =cut
2098:
2099: ###############################################################
2100: ###############################################################
2101: sub create_workbook {
2102: my ($r) = @_;
2103: #
2104: # Create the excel spreadsheet
2105: my $filename = '/prtspool/'.
1.258 albertel 2106: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2107: time.'_'.rand(1000000000).'.xls';
2108: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2109: if (! defined($workbook)) {
2110: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2111: $r->print(
2112: '<p class="LC_error">'
2113: .&mt('Problems occurred in creating the new Excel file.')
2114: .' '.&mt('This error has been logged.')
2115: .' '.&mt('Please alert your LON-CAPA administrator.')
2116: .'</p>'
2117: );
1.255 matthew 2118: return (undef);
2119: }
2120: #
1.1014 foxr 2121: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2122: #
2123: my $format = &Apache::loncommon::define_excel_formats($workbook);
2124: return ($workbook,$filename,$format);
2125: }
2126:
2127: ###############################################################
2128: ###############################################################
2129:
2130: =pod
2131:
1.648 raeburn 2132: =item * &create_text_file()
1.113 bowersj2 2133:
1.542 raeburn 2134: Create a file to write to and eventually make available to the user.
1.256 matthew 2135: If file creation fails, outputs an error message on the request object and
2136: return undefs.
1.113 bowersj2 2137:
1.256 matthew 2138: Inputs: Apache request object, and file suffix
1.113 bowersj2 2139:
1.256 matthew 2140: Returns (undef) on failure,
2141: Filehandle and filename on success.
1.113 bowersj2 2142:
2143: =cut
2144:
1.256 matthew 2145: ###############################################################
2146: ###############################################################
2147: sub create_text_file {
2148: my ($r,$suffix) = @_;
2149: if (! defined($suffix)) { $suffix = 'txt'; };
2150: my $fh;
2151: my $filename = '/prtspool/'.
1.258 albertel 2152: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2153: time.'_'.rand(1000000000).'.'.$suffix;
2154: $fh = Apache::File->new('>/home/httpd'.$filename);
2155: if (! defined($fh)) {
2156: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2157: $r->print(
2158: '<p class="LC_error">'
2159: .&mt('Problems occurred in creating the output file.')
2160: .' '.&mt('This error has been logged.')
2161: .' '.&mt('Please alert your LON-CAPA administrator.')
2162: .'</p>'
2163: );
1.113 bowersj2 2164: }
1.256 matthew 2165: return ($fh,$filename)
1.113 bowersj2 2166: }
2167:
2168:
1.256 matthew 2169: =pod
1.113 bowersj2 2170:
2171: =back
2172:
2173: =cut
1.37 matthew 2174:
2175: ###############################################################
1.33 matthew 2176: ## Home server <option> list generating code ##
2177: ###############################################################
1.35 matthew 2178:
1.169 www 2179: # ------------------------------------------
2180:
2181: sub domain_select {
2182: my ($name,$value,$multiple)=@_;
2183: my %domains=map {
1.514 albertel 2184: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2185: } &Apache::lonnet::all_domains();
1.169 www 2186: if ($multiple) {
2187: $domains{''}=&mt('Any domain');
1.550 albertel 2188: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2189: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2190: } else {
1.550 albertel 2191: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2192: return &select_form($name,$value,\%domains);
1.169 www 2193: }
2194: }
2195:
1.282 albertel 2196: #-------------------------------------------
2197:
2198: =pod
2199:
1.519 raeburn 2200: =head1 Routines for form select boxes
2201:
2202: =over 4
2203:
1.648 raeburn 2204: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2205:
2206: Returns a string containing a <select> element int multiple mode
2207:
2208:
2209: Args:
2210: $name - name of the <select> element
1.506 raeburn 2211: $value - scalar or array ref of values that should already be selected
1.282 albertel 2212: $size - number of rows long the select element is
1.283 albertel 2213: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2214: (shown text should already have been &mt())
1.506 raeburn 2215: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2216:
1.282 albertel 2217: =cut
2218:
2219: #-------------------------------------------
1.169 www 2220: sub multiple_select_form {
1.284 albertel 2221: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2222: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2223: my $output='';
1.191 matthew 2224: if (! defined($size)) {
2225: $size = 4;
1.283 albertel 2226: if (scalar(keys(%$hash))<4) {
2227: $size = scalar(keys(%$hash));
1.191 matthew 2228: }
2229: }
1.734 bisitz 2230: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2231: my @order;
1.506 raeburn 2232: if (ref($order) eq 'ARRAY') {
2233: @order = @{$order};
2234: } else {
2235: @order = sort(keys(%$hash));
1.501 banghart 2236: }
2237: if (exists($$hash{'select_form_order'})) {
2238: @order = @{$$hash{'select_form_order'}};
2239: }
2240:
1.284 albertel 2241: foreach my $key (@order) {
1.356 albertel 2242: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2243: $output.='selected="selected" ' if ($selected{$key});
2244: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2245: }
2246: $output.="</select>\n";
2247: return $output;
2248: }
2249:
1.88 www 2250: #-------------------------------------------
2251:
2252: =pod
2253:
1.1075.2.115 raeburn 2254: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2255:
2256: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2257: allow a user to select options from a ref to a hash containing:
2258: option_name => displayed text. An optional $onchange can include
1.1075.2.115 raeburn 2259: a javascript onchange item, e.g., onchange="this.form.submit();".
2260: An optional arg -- $readonly -- if true will cause the select form
2261: to be disabled, e.g., for the case where an instructor has a section-
2262: specific role, and is viewing/modifying parameters.
1.970 raeburn 2263:
1.88 www 2264: See lonrights.pm for an example invocation and use.
2265:
2266: =cut
2267:
2268: #-------------------------------------------
2269: sub select_form {
1.1075.2.115 raeburn 2270: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2271: return unless (ref($hashref) eq 'HASH');
2272: if ($onchange) {
2273: $onchange = ' onchange="'.$onchange.'"';
2274: }
1.1075.2.129 raeburn 2275: my $disabled;
2276: if ($readonly) {
2277: $disabled = ' disabled="disabled"';
2278: }
2279: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2280: my @keys;
1.970 raeburn 2281: if (exists($hashref->{'select_form_order'})) {
2282: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2283: } else {
1.970 raeburn 2284: @keys=sort(keys(%{$hashref}));
1.128 albertel 2285: }
1.356 albertel 2286: foreach my $key (@keys) {
2287: $selectform.=
2288: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2289: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2290: ">".$hashref->{$key}."</option>\n";
1.88 www 2291: }
2292: $selectform.="</select>";
2293: return $selectform;
2294: }
2295:
1.475 www 2296: # For display filters
2297:
2298: sub display_filter {
1.1074 raeburn 2299: my ($context) = @_;
1.475 www 2300: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2301: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2302: my $phraseinput = 'hidden';
2303: my $includeinput = 'hidden';
2304: my ($checked,$includetypestext);
2305: if ($env{'form.displayfilter'} eq 'containing') {
2306: $phraseinput = 'text';
2307: if ($context eq 'parmslog') {
2308: $includeinput = 'checkbox';
2309: if ($env{'form.includetypes'}) {
2310: $checked = ' checked="checked"';
2311: }
2312: $includetypestext = &mt('Include parameter types');
2313: }
2314: } else {
2315: $includetypestext = ' ';
2316: }
2317: my ($additional,$secondid,$thirdid);
2318: if ($context eq 'parmslog') {
2319: $additional =
2320: '<label><input type="'.$includeinput.'" name="includetypes"'.
2321: $checked.' name="includetypes" value="1" id="includetypes" />'.
2322: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2323: '</label>';
2324: $secondid = 'includetypes';
2325: $thirdid = 'includetypestext';
2326: }
2327: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2328: '$secondid','$thirdid')";
2329: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2330: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2331: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2332: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2333: &mt('Filter: [_1]',
1.477 www 2334: &select_form($env{'form.displayfilter'},
2335: 'displayfilter',
1.970 raeburn 2336: {'currentfolder' => 'Current folder/page',
1.477 www 2337: 'containing' => 'Containing phrase',
1.1074 raeburn 2338: 'none' => 'None'},$onchange)).' '.
2339: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2340: &HTML::Entities::encode($env{'form.containingphrase'}).
2341: '" />'.$additional;
2342: }
2343:
2344: sub display_filter_js {
2345: my $includetext = &mt('Include parameter types');
2346: return <<"ENDJS";
2347:
2348: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2349: var firstType = 'hidden';
2350: if (setter.options[setter.selectedIndex].value == 'containing') {
2351: firstType = 'text';
2352: }
2353: firstObject = document.getElementById(firstid);
2354: if (typeof(firstObject) == 'object') {
2355: if (firstObject.type != firstType) {
2356: changeInputType(firstObject,firstType);
2357: }
2358: }
2359: if (context == 'parmslog') {
2360: var secondType = 'hidden';
2361: if (firstType == 'text') {
2362: secondType = 'checkbox';
2363: }
2364: secondObject = document.getElementById(secondid);
2365: if (typeof(secondObject) == 'object') {
2366: if (secondObject.type != secondType) {
2367: changeInputType(secondObject,secondType);
2368: }
2369: }
2370: var textItem = document.getElementById(thirdid);
2371: var currtext = textItem.innerHTML;
2372: var newtext;
2373: if (firstType == 'text') {
2374: newtext = '$includetext';
2375: } else {
2376: newtext = ' ';
2377: }
2378: if (currtext != newtext) {
2379: textItem.innerHTML = newtext;
2380: }
2381: }
2382: return;
2383: }
2384:
2385: function changeInputType(oldObject,newType) {
2386: var newObject = document.createElement('input');
2387: newObject.type = newType;
2388: if (oldObject.size) {
2389: newObject.size = oldObject.size;
2390: }
2391: if (oldObject.value) {
2392: newObject.value = oldObject.value;
2393: }
2394: if (oldObject.name) {
2395: newObject.name = oldObject.name;
2396: }
2397: if (oldObject.id) {
2398: newObject.id = oldObject.id;
2399: }
2400: oldObject.parentNode.replaceChild(newObject,oldObject);
2401: return;
2402: }
2403:
2404: ENDJS
1.475 www 2405: }
2406:
1.167 www 2407: sub gradeleveldescription {
2408: my $gradelevel=shift;
2409: my %gradelevels=(0 => 'Not specified',
2410: 1 => 'Grade 1',
2411: 2 => 'Grade 2',
2412: 3 => 'Grade 3',
2413: 4 => 'Grade 4',
2414: 5 => 'Grade 5',
2415: 6 => 'Grade 6',
2416: 7 => 'Grade 7',
2417: 8 => 'Grade 8',
2418: 9 => 'Grade 9',
2419: 10 => 'Grade 10',
2420: 11 => 'Grade 11',
2421: 12 => 'Grade 12',
2422: 13 => 'Grade 13',
2423: 14 => '100 Level',
2424: 15 => '200 Level',
2425: 16 => '300 Level',
2426: 17 => '400 Level',
2427: 18 => 'Graduate Level');
2428: return &mt($gradelevels{$gradelevel});
2429: }
2430:
1.163 www 2431: sub select_level_form {
2432: my ($deflevel,$name)=@_;
2433: unless ($deflevel) { $deflevel=0; }
1.167 www 2434: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2435: for (my $i=0; $i<=18; $i++) {
2436: $selectform.="<option value=\"$i\" ".
1.253 albertel 2437: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2438: ">".&gradeleveldescription($i)."</option>\n";
2439: }
2440: $selectform.="</select>";
2441: return $selectform;
1.163 www 2442: }
1.167 www 2443:
1.35 matthew 2444: #-------------------------------------------
2445:
1.45 matthew 2446: =pod
2447:
1.1075.2.115 raeburn 2448: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2449:
2450: Returns a string containing a <select name='$name' size='1'> form to
2451: allow a user to select the domain to preform an operation in.
2452: See loncreateuser.pm for an example invocation and use.
2453:
1.90 www 2454: If the $includeempty flag is set, it also includes an empty choice ("no domain
2455: selected");
2456:
1.743 raeburn 2457: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2458:
1.910 raeburn 2459: 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.
2460:
1.1075.2.36 raeburn 2461: The optional $incdoms is a reference to an array of domains which will be the only available options.
2462:
1.1075.2.115 raeburn 2463: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
2464:
2465: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
1.563 raeburn 2466:
1.35 matthew 2467: =cut
2468:
2469: #-------------------------------------------
1.34 matthew 2470: sub select_dom_form {
1.1075.2.115 raeburn 2471: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2472: if ($onchange) {
1.874 raeburn 2473: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2474: }
1.1075.2.115 raeburn 2475: if ($disabled) {
2476: $disabled = ' disabled="disabled"';
2477: }
1.1075.2.36 raeburn 2478: my (@domains,%exclude);
1.910 raeburn 2479: if (ref($incdoms) eq 'ARRAY') {
2480: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2481: } else {
2482: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2483: }
1.90 www 2484: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2485: if (ref($excdoms) eq 'ARRAY') {
2486: map { $exclude{$_} = 1; } @{$excdoms};
2487: }
1.1075.2.115 raeburn 2488: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2489: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2490: next if ($exclude{$dom});
1.356 albertel 2491: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2492: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2493: if ($showdomdesc) {
2494: if ($dom ne '') {
2495: my $domdesc = &Apache::lonnet::domain($dom,'description');
2496: if ($domdesc ne '') {
2497: $selectdomain .= ' ('.$domdesc.')';
2498: }
2499: }
2500: }
2501: $selectdomain .= "</option>\n";
1.34 matthew 2502: }
2503: $selectdomain.="</select>";
2504: return $selectdomain;
2505: }
2506:
1.35 matthew 2507: #-------------------------------------------
2508:
1.45 matthew 2509: =pod
2510:
1.648 raeburn 2511: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2512:
1.586 raeburn 2513: input: 4 arguments (two required, two optional) -
2514: $domain - domain of new user
2515: $name - name of form element
2516: $default - Value of 'default' causes a default item to be first
2517: option, and selected by default.
2518: $hide - Value of 'hide' causes hiding of the name of the server,
2519: if 1 server found, or default, if 0 found.
1.594 raeburn 2520: output: returns 2 items:
1.586 raeburn 2521: (a) form element which contains either:
2522: (i) <select name="$name">
2523: <option value="$hostid1">$hostid $servers{$hostid}</option>
2524: <option value="$hostid2">$hostid $servers{$hostid}</option>
2525: </select>
2526: form item if there are multiple library servers in $domain, or
2527: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2528: if there is only one library server in $domain.
2529:
2530: (b) number of library servers found.
2531:
2532: See loncreateuser.pm for example of use.
1.35 matthew 2533:
2534: =cut
2535:
2536: #-------------------------------------------
1.586 raeburn 2537: sub home_server_form_item {
2538: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2539: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2540: my $result;
2541: my $numlib = keys(%servers);
2542: if ($numlib > 1) {
2543: $result .= '<select name="'.$name.'" />'."\n";
2544: if ($default) {
1.804 bisitz 2545: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2546: '</option>'."\n";
2547: }
2548: foreach my $hostid (sort(keys(%servers))) {
2549: $result.= '<option value="'.$hostid.'">'.
2550: $hostid.' '.$servers{$hostid}."</option>\n";
2551: }
2552: $result .= '</select>'."\n";
2553: } elsif ($numlib == 1) {
2554: my $hostid;
2555: foreach my $item (keys(%servers)) {
2556: $hostid = $item;
2557: }
2558: $result .= '<input type="hidden" name="'.$name.'" value="'.
2559: $hostid.'" />';
2560: if (!$hide) {
2561: $result .= $hostid.' '.$servers{$hostid};
2562: }
2563: $result .= "\n";
2564: } elsif ($default) {
2565: $result .= '<input type="hidden" name="'.$name.
2566: '" value="default" />';
2567: if (!$hide) {
2568: $result .= &mt('default');
2569: }
2570: $result .= "\n";
1.33 matthew 2571: }
1.586 raeburn 2572: return ($result,$numlib);
1.33 matthew 2573: }
1.112 bowersj2 2574:
2575: =pod
2576:
1.534 albertel 2577: =back
2578:
1.112 bowersj2 2579: =cut
1.87 matthew 2580:
2581: ###############################################################
1.112 bowersj2 2582: ## Decoding User Agent ##
1.87 matthew 2583: ###############################################################
2584:
2585: =pod
2586:
1.112 bowersj2 2587: =head1 Decoding the User Agent
2588:
2589: =over 4
2590:
2591: =item * &decode_user_agent()
1.87 matthew 2592:
2593: Inputs: $r
2594:
2595: Outputs:
2596:
2597: =over 4
2598:
1.112 bowersj2 2599: =item * $httpbrowser
1.87 matthew 2600:
1.112 bowersj2 2601: =item * $clientbrowser
1.87 matthew 2602:
1.112 bowersj2 2603: =item * $clientversion
1.87 matthew 2604:
1.112 bowersj2 2605: =item * $clientmathml
1.87 matthew 2606:
1.112 bowersj2 2607: =item * $clientunicode
1.87 matthew 2608:
1.112 bowersj2 2609: =item * $clientos
1.87 matthew 2610:
1.1075.2.42 raeburn 2611: =item * $clientmobile
2612:
2613: =item * $clientinfo
2614:
1.1075.2.77 raeburn 2615: =item * $clientosversion
2616:
1.87 matthew 2617: =back
2618:
1.157 matthew 2619: =back
2620:
1.87 matthew 2621: =cut
2622:
2623: ###############################################################
2624: ###############################################################
2625: sub decode_user_agent {
1.247 albertel 2626: my ($r)=@_;
1.87 matthew 2627: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2628: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2629: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2630: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2631: my $clientbrowser='unknown';
2632: my $clientversion='0';
2633: my $clientmathml='';
2634: my $clientunicode='0';
1.1075.2.42 raeburn 2635: my $clientmobile=0;
1.1075.2.77 raeburn 2636: my $clientosversion='';
1.87 matthew 2637: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2638: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2639: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2640: $clientbrowser=$bname;
2641: $httpbrowser=~/$vreg/i;
2642: $clientversion=$1;
2643: $clientmathml=($clientversion>=$minv);
2644: $clientunicode=($clientversion>=$univ);
2645: }
2646: }
2647: my $clientos='unknown';
1.1075.2.42 raeburn 2648: my $clientinfo;
1.87 matthew 2649: if (($httpbrowser=~/linux/i) ||
2650: ($httpbrowser=~/unix/i) ||
2651: ($httpbrowser=~/ux/i) ||
2652: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2653: if (($httpbrowser=~/vax/i) ||
2654: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2655: if ($httpbrowser=~/next/i) { $clientos='next'; }
2656: if (($httpbrowser=~/mac/i) ||
2657: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2658: if ($httpbrowser=~/win/i) {
2659: $clientos='win';
2660: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2661: $clientosversion = $1;
2662: }
2663: }
1.87 matthew 2664: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2665: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2666: $clientmobile=lc($1);
2667: }
2668: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2669: $clientinfo = 'firefox-'.$1;
2670: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2671: $clientinfo = 'chromeframe-'.$1;
2672: }
1.87 matthew 2673: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2674: $clientunicode,$clientos,$clientmobile,$clientinfo,
2675: $clientosversion);
1.87 matthew 2676: }
2677:
1.32 matthew 2678: ###############################################################
2679: ## Authentication changing form generation subroutines ##
2680: ###############################################################
2681: ##
2682: ## All of the authform_xxxxxxx subroutines take their inputs in a
2683: ## hash, and have reasonable default values.
2684: ##
2685: ## formname = the name given in the <form> tag.
1.35 matthew 2686: #-------------------------------------------
2687:
1.45 matthew 2688: =pod
2689:
1.112 bowersj2 2690: =head1 Authentication Routines
2691:
2692: =over 4
2693:
1.648 raeburn 2694: =item * &authform_xxxxxx()
1.35 matthew 2695:
2696: The authform_xxxxxx subroutines provide javascript and html forms which
2697: handle some of the conveniences required for authentication forms.
2698: This is not an optimal method, but it works.
2699:
2700: =over 4
2701:
1.112 bowersj2 2702: =item * authform_header
1.35 matthew 2703:
1.112 bowersj2 2704: =item * authform_authorwarning
1.35 matthew 2705:
1.112 bowersj2 2706: =item * authform_nochange
1.35 matthew 2707:
1.112 bowersj2 2708: =item * authform_kerberos
1.35 matthew 2709:
1.112 bowersj2 2710: =item * authform_internal
1.35 matthew 2711:
1.112 bowersj2 2712: =item * authform_filesystem
1.35 matthew 2713:
2714: =back
2715:
1.648 raeburn 2716: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2717:
1.35 matthew 2718: =cut
2719:
2720: #-------------------------------------------
1.32 matthew 2721: sub authform_header{
2722: my %in = (
2723: formname => 'cu',
1.80 albertel 2724: kerb_def_dom => '',
1.32 matthew 2725: @_,
2726: );
2727: $in{'formname'} = 'document.' . $in{'formname'};
2728: my $result='';
1.80 albertel 2729:
2730: #---------------------------------------------- Code for upper case translation
2731: my $Javascript_toUpperCase;
2732: unless ($in{kerb_def_dom}) {
2733: $Javascript_toUpperCase =<<"END";
2734: switch (choice) {
2735: case 'krb': currentform.elements[choicearg].value =
2736: currentform.elements[choicearg].value.toUpperCase();
2737: break;
2738: default:
2739: }
2740: END
2741: } else {
2742: $Javascript_toUpperCase = "";
2743: }
2744:
1.165 raeburn 2745: my $radioval = "'nochange'";
1.591 raeburn 2746: if (defined($in{'curr_authtype'})) {
2747: if ($in{'curr_authtype'} ne '') {
2748: $radioval = "'".$in{'curr_authtype'}."arg'";
2749: }
1.174 matthew 2750: }
1.165 raeburn 2751: my $argfield = 'null';
1.591 raeburn 2752: if (defined($in{'mode'})) {
1.165 raeburn 2753: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2754: if (defined($in{'curr_autharg'})) {
2755: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2756: $argfield = "'$in{'curr_autharg'}'";
2757: }
2758: }
2759: }
2760: }
2761:
1.32 matthew 2762: $result.=<<"END";
2763: var current = new Object();
1.165 raeburn 2764: current.radiovalue = $radioval;
2765: current.argfield = $argfield;
1.32 matthew 2766:
2767: function changed_radio(choice,currentform) {
2768: var choicearg = choice + 'arg';
2769: // If a radio button in changed, we need to change the argfield
2770: if (current.radiovalue != choice) {
2771: current.radiovalue = choice;
2772: if (current.argfield != null) {
2773: currentform.elements[current.argfield].value = '';
2774: }
2775: if (choice == 'nochange') {
2776: current.argfield = null;
2777: } else {
2778: current.argfield = choicearg;
2779: switch(choice) {
2780: case 'krb':
2781: currentform.elements[current.argfield].value =
2782: "$in{'kerb_def_dom'}";
2783: break;
2784: default:
2785: break;
2786: }
2787: }
2788: }
2789: return;
2790: }
1.22 www 2791:
1.32 matthew 2792: function changed_text(choice,currentform) {
2793: var choicearg = choice + 'arg';
2794: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2795: $Javascript_toUpperCase
1.32 matthew 2796: // clear old field
2797: if ((current.argfield != choicearg) && (current.argfield != null)) {
2798: currentform.elements[current.argfield].value = '';
2799: }
2800: current.argfield = choicearg;
2801: }
2802: set_auth_radio_buttons(choice,currentform);
2803: return;
1.20 www 2804: }
1.32 matthew 2805:
2806: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2807: var numauthchoices = currentform.login.length;
2808: if (typeof numauthchoices == "undefined") {
2809: return;
2810: }
1.32 matthew 2811: var i=0;
1.986 raeburn 2812: while (i < numauthchoices) {
1.32 matthew 2813: if (currentform.login[i].value == newvalue) { break; }
2814: i++;
2815: }
1.986 raeburn 2816: if (i == numauthchoices) {
1.32 matthew 2817: return;
2818: }
2819: current.radiovalue = newvalue;
2820: currentform.login[i].checked = true;
2821: return;
2822: }
2823: END
2824: return $result;
2825: }
2826:
1.1075.2.20 raeburn 2827: sub authform_authorwarning {
1.32 matthew 2828: my $result='';
1.144 matthew 2829: $result='<i>'.
2830: &mt('As a general rule, only authors or co-authors should be '.
2831: 'filesystem authenticated '.
2832: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2833: return $result;
2834: }
2835:
1.1075.2.20 raeburn 2836: sub authform_nochange {
1.32 matthew 2837: my %in = (
2838: formname => 'document.cu',
2839: kerb_def_dom => 'MSU.EDU',
2840: @_,
2841: );
1.1075.2.20 raeburn 2842: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2843: my $result;
1.1075.2.20 raeburn 2844: if (!$authnum) {
2845: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2846: } else {
2847: $result = '<label>'.&mt('[_1] Do not change login data',
2848: '<input type="radio" name="login" value="nochange" '.
2849: 'checked="checked" onclick="'.
1.281 albertel 2850: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2851: '</label>';
1.586 raeburn 2852: }
1.32 matthew 2853: return $result;
2854: }
2855:
1.591 raeburn 2856: sub authform_kerberos {
1.32 matthew 2857: my %in = (
2858: formname => 'document.cu',
2859: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2860: kerb_def_auth => 'krb4',
1.32 matthew 2861: @_,
2862: );
1.586 raeburn 2863: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1075.2.117 raeburn 2864: $autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2865: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2866: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2867: $check5 = ' checked="checked"';
1.80 albertel 2868: } else {
1.772 bisitz 2869: $check4 = ' checked="checked"';
1.80 albertel 2870: }
1.1075.2.117 raeburn 2871: if ($in{'readonly'}) {
2872: $disabled = ' disabled="disabled"';
2873: }
1.165 raeburn 2874: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2875: if (defined($in{'curr_authtype'})) {
2876: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2877: $krbcheck = ' checked="checked"';
1.623 raeburn 2878: if (defined($in{'mode'})) {
2879: if ($in{'mode'} eq 'modifyuser') {
2880: $krbcheck = '';
2881: }
2882: }
1.591 raeburn 2883: if (defined($in{'curr_kerb_ver'})) {
2884: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2885: $check5 = ' checked="checked"';
1.591 raeburn 2886: $check4 = '';
2887: } else {
1.772 bisitz 2888: $check4 = ' checked="checked"';
1.591 raeburn 2889: $check5 = '';
2890: }
1.586 raeburn 2891: }
1.591 raeburn 2892: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2893: $krbarg = $in{'curr_autharg'};
2894: }
1.586 raeburn 2895: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2896: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2897: $result =
2898: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2899: $in{'curr_autharg'},$krbver);
2900: } else {
2901: $result =
2902: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2903: }
2904: return $result;
2905: }
2906: }
2907: } else {
2908: if ($authnum == 1) {
1.784 bisitz 2909: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2910: }
2911: }
1.586 raeburn 2912: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2913: return;
1.587 raeburn 2914: } elsif ($authtype eq '') {
1.591 raeburn 2915: if (defined($in{'mode'})) {
1.587 raeburn 2916: if ($in{'mode'} eq 'modifycourse') {
2917: if ($authnum == 1) {
1.1075.2.117 raeburn 2918: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 2919: }
2920: }
2921: }
1.586 raeburn 2922: }
2923: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2924: if ($authtype eq '') {
2925: $authtype = '<input type="radio" name="login" value="krb" '.
2926: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1075.2.117 raeburn 2927: $krbcheck.$disabled.' />';
1.586 raeburn 2928: }
2929: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2930: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2931: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2932: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2933: $in{'curr_authtype'} eq 'krb4')) {
2934: $result .= &mt
1.144 matthew 2935: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2936: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2937: '<label>'.$authtype,
1.281 albertel 2938: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2939: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2940: 'onchange="'.$jscall.'"'.$disabled.' />',
2941: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
2942: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 2943: '</label>');
1.586 raeburn 2944: } elsif ($can_assign{'krb4'}) {
2945: $result .= &mt
2946: ('[_1] Kerberos authenticated with domain [_2] '.
2947: '[_3] Version 4 [_4]',
2948: '<label>'.$authtype,
2949: '</label><input type="text" size="10" name="krbarg" '.
2950: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2951: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2952: '<label><input type="hidden" name="krbver" value="4" />',
2953: '</label>');
2954: } elsif ($can_assign{'krb5'}) {
2955: $result .= &mt
2956: ('[_1] Kerberos authenticated with domain [_2] '.
2957: '[_3] Version 5 [_4]',
2958: '<label>'.$authtype,
2959: '</label><input type="text" size="10" name="krbarg" '.
2960: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2961: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2962: '<label><input type="hidden" name="krbver" value="5" />',
2963: '</label>');
2964: }
1.32 matthew 2965: return $result;
2966: }
2967:
1.1075.2.20 raeburn 2968: sub authform_internal {
1.586 raeburn 2969: my %in = (
1.32 matthew 2970: formname => 'document.cu',
2971: kerb_def_dom => 'MSU.EDU',
2972: @_,
2973: );
1.1075.2.117 raeburn 2974: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2975: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 2976: if ($in{'readonly'}) {
2977: $disabled = ' disabled="disabled"';
2978: }
1.591 raeburn 2979: if (defined($in{'curr_authtype'})) {
2980: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2981: if ($can_assign{'int'}) {
1.772 bisitz 2982: $intcheck = 'checked="checked" ';
1.623 raeburn 2983: if (defined($in{'mode'})) {
2984: if ($in{'mode'} eq 'modifyuser') {
2985: $intcheck = '';
2986: }
2987: }
1.591 raeburn 2988: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2989: $intarg = $in{'curr_autharg'};
2990: }
2991: } else {
2992: $result = &mt('Currently internally authenticated.');
2993: return $result;
1.165 raeburn 2994: }
2995: }
1.586 raeburn 2996: } else {
2997: if ($authnum == 1) {
1.784 bisitz 2998: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2999: }
3000: }
3001: if (!$can_assign{'int'}) {
3002: return;
1.587 raeburn 3003: } elsif ($authtype eq '') {
1.591 raeburn 3004: if (defined($in{'mode'})) {
1.587 raeburn 3005: if ($in{'mode'} eq 'modifycourse') {
3006: if ($authnum == 1) {
1.1075.2.117 raeburn 3007: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3008: }
3009: }
3010: }
1.165 raeburn 3011: }
1.586 raeburn 3012: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3013: if ($authtype eq '') {
3014: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1075.2.117 raeburn 3015: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3016: }
1.605 bisitz 3017: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1075.2.117 raeburn 3018: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3019: $result = &mt
1.144 matthew 3020: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3021: '<label>'.$authtype,'</label>'.$autharg);
1.1075.2.118 raeburn 3022: $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 3023: return $result;
3024: }
3025:
1.1075.2.20 raeburn 3026: sub authform_local {
1.32 matthew 3027: my %in = (
3028: formname => 'document.cu',
3029: kerb_def_dom => 'MSU.EDU',
3030: @_,
3031: );
1.1075.2.117 raeburn 3032: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3033: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3034: if ($in{'readonly'}) {
3035: $disabled = ' disabled="disabled"';
3036: }
1.591 raeburn 3037: if (defined($in{'curr_authtype'})) {
3038: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3039: if ($can_assign{'loc'}) {
1.772 bisitz 3040: $loccheck = 'checked="checked" ';
1.623 raeburn 3041: if (defined($in{'mode'})) {
3042: if ($in{'mode'} eq 'modifyuser') {
3043: $loccheck = '';
3044: }
3045: }
1.591 raeburn 3046: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3047: $locarg = $in{'curr_autharg'};
3048: }
3049: } else {
3050: $result = &mt('Currently using local (institutional) authentication.');
3051: return $result;
1.165 raeburn 3052: }
3053: }
1.586 raeburn 3054: } else {
3055: if ($authnum == 1) {
1.784 bisitz 3056: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3057: }
3058: }
3059: if (!$can_assign{'loc'}) {
3060: return;
1.587 raeburn 3061: } elsif ($authtype eq '') {
1.591 raeburn 3062: if (defined($in{'mode'})) {
1.587 raeburn 3063: if ($in{'mode'} eq 'modifycourse') {
3064: if ($authnum == 1) {
1.1075.2.117 raeburn 3065: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3066: }
3067: }
3068: }
1.165 raeburn 3069: }
1.586 raeburn 3070: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3071: if ($authtype eq '') {
3072: $authtype = '<input type="radio" name="login" value="loc" '.
3073: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3074: $jscall.'"'.$disabled.' />';
1.586 raeburn 3075: }
3076: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1075.2.117 raeburn 3077: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3078: $result = &mt('[_1] Local Authentication with argument [_2]',
3079: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3080: return $result;
3081: }
3082:
1.1075.2.20 raeburn 3083: sub authform_filesystem {
1.32 matthew 3084: my %in = (
3085: formname => 'document.cu',
3086: kerb_def_dom => 'MSU.EDU',
3087: @_,
3088: );
1.1075.2.117 raeburn 3089: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3090: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3091: if ($in{'readonly'}) {
3092: $disabled = ' disabled="disabled"';
3093: }
1.591 raeburn 3094: if (defined($in{'curr_authtype'})) {
3095: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3096: if ($can_assign{'fsys'}) {
1.772 bisitz 3097: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3098: if (defined($in{'mode'})) {
3099: if ($in{'mode'} eq 'modifyuser') {
3100: $fsyscheck = '';
3101: }
3102: }
1.586 raeburn 3103: } else {
3104: $result = &mt('Currently Filesystem Authenticated.');
3105: return $result;
3106: }
3107: }
3108: } else {
3109: if ($authnum == 1) {
1.784 bisitz 3110: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3111: }
3112: }
3113: if (!$can_assign{'fsys'}) {
3114: return;
1.587 raeburn 3115: } elsif ($authtype eq '') {
1.591 raeburn 3116: if (defined($in{'mode'})) {
1.587 raeburn 3117: if ($in{'mode'} eq 'modifycourse') {
3118: if ($authnum == 1) {
1.1075.2.117 raeburn 3119: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3120: }
3121: }
3122: }
1.586 raeburn 3123: }
3124: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3125: if ($authtype eq '') {
3126: $authtype = '<input type="radio" name="login" value="fsys" '.
3127: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3128: $jscall.'"'.$disabled.' />';
1.586 raeburn 3129: }
1.1075.2.158 raeburn 3130: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1075.2.117 raeburn 3131: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3132: $result = &mt
1.144 matthew 3133: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1075.2.158 raeburn 3134: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3135: return $result;
3136: }
3137:
1.586 raeburn 3138: sub get_assignable_auth {
3139: my ($dom) = @_;
3140: if ($dom eq '') {
3141: $dom = $env{'request.role.domain'};
3142: }
3143: my %can_assign = (
3144: krb4 => 1,
3145: krb5 => 1,
3146: int => 1,
3147: loc => 1,
3148: );
3149: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3150: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3151: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3152: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3153: my $context;
3154: if ($env{'request.role'} =~ /^au/) {
3155: $context = 'author';
1.1075.2.117 raeburn 3156: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3157: $context = 'domain';
3158: } elsif ($env{'request.course.id'}) {
3159: $context = 'course';
3160: }
3161: if ($context) {
3162: if (ref($authhash->{$context}) eq 'HASH') {
3163: %can_assign = %{$authhash->{$context}};
3164: }
3165: }
3166: }
3167: }
3168: my $authnum = 0;
3169: foreach my $key (keys(%can_assign)) {
3170: if ($can_assign{$key}) {
3171: $authnum ++;
3172: }
3173: }
3174: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3175: $authnum --;
3176: }
3177: return ($authnum,%can_assign);
3178: }
3179:
1.1075.2.137 raeburn 3180: sub check_passwd_rules {
3181: my ($domain,$plainpass) = @_;
3182: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3183: my ($min,$max,@chars,@brokerule,$warning);
1.1075.2.138 raeburn 3184: $min = $Apache::lonnet::passwdmin;
1.1075.2.137 raeburn 3185: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3186: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1075.2.138 raeburn 3187: if ($passwdconf{'min'} > $min) {
3188: $min = $passwdconf{'min'};
3189: }
1.1075.2.137 raeburn 3190: }
3191: if ($passwdconf{'max'} =~ /^\d+$/) {
3192: $max = $passwdconf{'max'};
3193: }
3194: @chars = @{$passwdconf{'chars'}};
3195: }
3196: if (($min) && (length($plainpass) < $min)) {
3197: push(@brokerule,'min');
3198: }
3199: if (($max) && (length($plainpass) > $max)) {
3200: push(@brokerule,'max');
3201: }
3202: if (@chars) {
3203: my %rules;
3204: map { $rules{$_} = 1; } @chars;
3205: if ($rules{'uc'}) {
3206: unless ($plainpass =~ /[A-Z]/) {
3207: push(@brokerule,'uc');
3208: }
3209: }
3210: if ($rules{'lc'}) {
3211: unless ($plainpass =~ /[a-z]/) {
3212: push(@brokerule,'lc');
3213: }
3214: }
3215: if ($rules{'num'}) {
3216: unless ($plainpass =~ /\d/) {
3217: push(@brokerule,'num');
3218: }
3219: }
3220: if ($rules{'spec'}) {
3221: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3222: push(@brokerule,'spec');
3223: }
3224: }
3225: }
3226: if (@brokerule) {
3227: my %rulenames = &Apache::lonlocal::texthash(
3228: uc => 'At least one upper case letter',
3229: lc => 'At least one lower case letter',
3230: num => 'At least one number',
3231: spec => 'At least one non-alphanumeric',
3232: );
3233: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3234: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3235: $rulenames{'num'} .= ': 0123456789';
3236: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3237: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3238: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3239: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1075.2.143 raeburn 3240: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1075.2.137 raeburn 3241: if (grep(/^$rule$/,@brokerule)) {
3242: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3243: }
3244: }
3245: $warning .= '</ul>';
3246: }
3247: if (wantarray) {
3248: return @brokerule;
3249: }
3250: return $warning;
3251: }
3252:
1.80 albertel 3253: ###############################################################
3254: ## Get Kerberos Defaults for Domain ##
3255: ###############################################################
3256: ##
3257: ## Returns default kerberos version and an associated argument
3258: ## as listed in file domain.tab. If not listed, provides
3259: ## appropriate default domain and kerberos version.
3260: ##
3261: #-------------------------------------------
3262:
3263: =pod
3264:
1.648 raeburn 3265: =item * &get_kerberos_defaults()
1.80 albertel 3266:
3267: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3268: version and domain. If not found, it defaults to version 4 and the
3269: domain of the server.
1.80 albertel 3270:
1.648 raeburn 3271: =over 4
3272:
1.80 albertel 3273: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3274:
1.648 raeburn 3275: =back
3276:
3277: =back
3278:
1.80 albertel 3279: =cut
3280:
3281: #-------------------------------------------
3282: sub get_kerberos_defaults {
3283: my $domain=shift;
1.641 raeburn 3284: my ($krbdef,$krbdefdom);
3285: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3286: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3287: $krbdef = $domdefaults{'auth_def'};
3288: $krbdefdom = $domdefaults{'auth_arg_def'};
3289: } else {
1.80 albertel 3290: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3291: my $krbdefdom=$1;
3292: $krbdefdom=~tr/a-z/A-Z/;
3293: $krbdef = "krb4";
3294: }
3295: return ($krbdef,$krbdefdom);
3296: }
1.112 bowersj2 3297:
1.32 matthew 3298:
1.46 matthew 3299: ###############################################################
3300: ## Thesaurus Functions ##
3301: ###############################################################
1.20 www 3302:
1.46 matthew 3303: =pod
1.20 www 3304:
1.112 bowersj2 3305: =head1 Thesaurus Functions
3306:
3307: =over 4
3308:
1.648 raeburn 3309: =item * &initialize_keywords()
1.46 matthew 3310:
3311: Initializes the package variable %Keywords if it is empty. Uses the
3312: package variable $thesaurus_db_file.
3313:
3314: =cut
3315:
3316: ###################################################
3317:
3318: sub initialize_keywords {
3319: return 1 if (scalar keys(%Keywords));
3320: # If we are here, %Keywords is empty, so fill it up
3321: # Make sure the file we need exists...
3322: if (! -e $thesaurus_db_file) {
3323: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3324: " failed because it does not exist");
3325: return 0;
3326: }
3327: # Set up the hash as a database
3328: my %thesaurus_db;
3329: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3330: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3331: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3332: $thesaurus_db_file);
3333: return 0;
3334: }
3335: # Get the average number of appearances of a word.
3336: my $avecount = $thesaurus_db{'average.count'};
3337: # Put keywords (those that appear > average) into %Keywords
3338: while (my ($word,$data)=each (%thesaurus_db)) {
3339: my ($count,undef) = split /:/,$data;
3340: $Keywords{$word}++ if ($count > $avecount);
3341: }
3342: untie %thesaurus_db;
3343: # Remove special values from %Keywords.
1.356 albertel 3344: foreach my $value ('total.count','average.count') {
3345: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3346: }
1.46 matthew 3347: return 1;
3348: }
3349:
3350: ###################################################
3351:
3352: =pod
3353:
1.648 raeburn 3354: =item * &keyword($word)
1.46 matthew 3355:
3356: Returns true if $word is a keyword. A keyword is a word that appears more
3357: than the average number of times in the thesaurus database. Calls
3358: &initialize_keywords
3359:
3360: =cut
3361:
3362: ###################################################
1.20 www 3363:
3364: sub keyword {
1.46 matthew 3365: return if (!&initialize_keywords());
3366: my $word=lc(shift());
3367: $word=~s/\W//g;
3368: return exists($Keywords{$word});
1.20 www 3369: }
1.46 matthew 3370:
3371: ###############################################################
3372:
3373: =pod
1.20 www 3374:
1.648 raeburn 3375: =item * &get_related_words()
1.46 matthew 3376:
1.160 matthew 3377: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3378: an array of words. If the keyword is not in the thesaurus, an empty array
3379: will be returned. The order of the words returned is determined by the
3380: database which holds them.
3381:
3382: Uses global $thesaurus_db_file.
3383:
1.1057 foxr 3384:
1.46 matthew 3385: =cut
3386:
3387: ###############################################################
3388: sub get_related_words {
3389: my $keyword = shift;
3390: my %thesaurus_db;
3391: if (! -e $thesaurus_db_file) {
3392: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3393: "failed because the file does not exist");
3394: return ();
3395: }
3396: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3397: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3398: return ();
3399: }
3400: my @Words=();
1.429 www 3401: my $count=0;
1.46 matthew 3402: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3403: # The first element is the number of times
3404: # the word appears. We do not need it now.
1.429 www 3405: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3406: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3407: my $threshold=$mostfrequentcount/10;
3408: foreach my $possibleword (@RelatedWords) {
3409: my ($word,$wordcount)=split(/\,/,$possibleword);
3410: if ($wordcount>$threshold) {
3411: push(@Words,$word);
3412: $count++;
3413: if ($count>10) { last; }
3414: }
1.20 www 3415: }
3416: }
1.46 matthew 3417: untie %thesaurus_db;
3418: return @Words;
1.14 harris41 3419: }
1.46 matthew 3420:
1.112 bowersj2 3421: =pod
3422:
3423: =back
3424:
3425: =cut
1.61 www 3426:
3427: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3428: =pod
3429:
1.112 bowersj2 3430: =head1 User Name Functions
3431:
3432: =over 4
3433:
1.648 raeburn 3434: =item * &plainname($uname,$udom,$first)
1.81 albertel 3435:
1.112 bowersj2 3436: Takes a users logon name and returns it as a string in
1.226 albertel 3437: "first middle last generation" form
3438: if $first is set to 'lastname' then it returns it as
3439: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3440:
3441: =cut
1.61 www 3442:
1.295 www 3443:
1.81 albertel 3444: ###############################################################
1.61 www 3445: sub plainname {
1.226 albertel 3446: my ($uname,$udom,$first)=@_;
1.537 albertel 3447: return if (!defined($uname) || !defined($udom));
1.295 www 3448: my %names=&getnames($uname,$udom);
1.226 albertel 3449: my $name=&Apache::lonnet::format_name($names{'firstname'},
3450: $names{'middlename'},
3451: $names{'lastname'},
3452: $names{'generation'},$first);
3453: $name=~s/^\s+//;
1.62 www 3454: $name=~s/\s+$//;
3455: $name=~s/\s+/ /g;
1.353 albertel 3456: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3457: return $name;
1.61 www 3458: }
1.66 www 3459:
3460: # -------------------------------------------------------------------- Nickname
1.81 albertel 3461: =pod
3462:
1.648 raeburn 3463: =item * &nickname($uname,$udom)
1.81 albertel 3464:
3465: Gets a users name and returns it as a string as
3466:
3467: ""nickname""
1.66 www 3468:
1.81 albertel 3469: if the user has a nickname or
3470:
3471: "first middle last generation"
3472:
3473: if the user does not
3474:
3475: =cut
1.66 www 3476:
3477: sub nickname {
3478: my ($uname,$udom)=@_;
1.537 albertel 3479: return if (!defined($uname) || !defined($udom));
1.295 www 3480: my %names=&getnames($uname,$udom);
1.68 albertel 3481: my $name=$names{'nickname'};
1.66 www 3482: if ($name) {
3483: $name='"'.$name.'"';
3484: } else {
3485: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3486: $names{'lastname'}.' '.$names{'generation'};
3487: $name=~s/\s+$//;
3488: $name=~s/\s+/ /g;
3489: }
3490: return $name;
3491: }
3492:
1.295 www 3493: sub getnames {
3494: my ($uname,$udom)=@_;
1.537 albertel 3495: return if (!defined($uname) || !defined($udom));
1.433 albertel 3496: if ($udom eq 'public' && $uname eq 'public') {
3497: return ('lastname' => &mt('Public'));
3498: }
1.295 www 3499: my $id=$uname.':'.$udom;
3500: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3501: if ($cached) {
3502: return %{$names};
3503: } else {
3504: my %loadnames=&Apache::lonnet::get('environment',
3505: ['firstname','middlename','lastname','generation','nickname'],
3506: $udom,$uname);
3507: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3508: return %loadnames;
3509: }
3510: }
1.61 www 3511:
1.542 raeburn 3512: # -------------------------------------------------------------------- getemails
1.648 raeburn 3513:
1.542 raeburn 3514: =pod
3515:
1.648 raeburn 3516: =item * &getemails($uname,$udom)
1.542 raeburn 3517:
3518: Gets a user's email information and returns it as a hash with keys:
3519: notification, critnotification, permanentemail
3520:
3521: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3522: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3523:
1.648 raeburn 3524:
1.542 raeburn 3525: =cut
3526:
1.648 raeburn 3527:
1.466 albertel 3528: sub getemails {
3529: my ($uname,$udom)=@_;
3530: if ($udom eq 'public' && $uname eq 'public') {
3531: return;
3532: }
1.467 www 3533: if (!$udom) { $udom=$env{'user.domain'}; }
3534: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3535: my $id=$uname.':'.$udom;
3536: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3537: if ($cached) {
3538: return %{$names};
3539: } else {
3540: my %loadnames=&Apache::lonnet::get('environment',
3541: ['notification','critnotification',
3542: 'permanentemail'],
3543: $udom,$uname);
3544: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3545: return %loadnames;
3546: }
3547: }
3548:
1.551 albertel 3549: sub flush_email_cache {
3550: my ($uname,$udom)=@_;
3551: if (!$udom) { $udom =$env{'user.domain'}; }
3552: if (!$uname) { $uname=$env{'user.name'}; }
3553: return if ($udom eq 'public' && $uname eq 'public');
3554: my $id=$uname.':'.$udom;
3555: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3556: }
3557:
1.728 raeburn 3558: # -------------------------------------------------------------------- getlangs
3559:
3560: =pod
3561:
3562: =item * &getlangs($uname,$udom)
3563:
3564: Gets a user's language preference and returns it as a hash with key:
3565: language.
3566:
3567: =cut
3568:
3569:
3570: sub getlangs {
3571: my ($uname,$udom) = @_;
3572: if (!$udom) { $udom =$env{'user.domain'}; }
3573: if (!$uname) { $uname=$env{'user.name'}; }
3574: my $id=$uname.':'.$udom;
3575: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3576: if ($cached) {
3577: return %{$langs};
3578: } else {
3579: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3580: $udom,$uname);
3581: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3582: return %loadlangs;
3583: }
3584: }
3585:
3586: sub flush_langs_cache {
3587: my ($uname,$udom)=@_;
3588: if (!$udom) { $udom =$env{'user.domain'}; }
3589: if (!$uname) { $uname=$env{'user.name'}; }
3590: return if ($udom eq 'public' && $uname eq 'public');
3591: my $id=$uname.':'.$udom;
3592: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3593: }
3594:
1.61 www 3595: # ------------------------------------------------------------------ Screenname
1.81 albertel 3596:
3597: =pod
3598:
1.648 raeburn 3599: =item * &screenname($uname,$udom)
1.81 albertel 3600:
3601: Gets a users screenname and returns it as a string
3602:
3603: =cut
1.61 www 3604:
3605: sub screenname {
3606: my ($uname,$udom)=@_;
1.258 albertel 3607: if ($uname eq $env{'user.name'} &&
3608: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3609: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3610: return $names{'screenname'};
1.62 www 3611: }
3612:
1.212 albertel 3613:
1.802 bisitz 3614: # ------------------------------------------------------------- Confirm Wrapper
3615: =pod
3616:
1.1075.2.42 raeburn 3617: =item * &confirmwrapper($message)
1.802 bisitz 3618:
3619: Wrap messages about completion of operation in box
3620:
3621: =cut
3622:
3623: sub confirmwrapper {
3624: my ($message)=@_;
3625: if ($message) {
3626: return "\n".'<div class="LC_confirm_box">'."\n"
3627: .$message."\n"
3628: .'</div>'."\n";
3629: } else {
3630: return $message;
3631: }
3632: }
3633:
1.62 www 3634: # ------------------------------------------------------------- Message Wrapper
3635:
3636: sub messagewrapper {
1.369 www 3637: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3638: return
1.441 albertel 3639: '<a href="/adm/email?compose=individual&'.
3640: 'recname='.$username.'&recdom='.$domain.
3641: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3642: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3643: }
1.802 bisitz 3644:
1.74 www 3645: # --------------------------------------------------------------- Notes Wrapper
3646:
3647: sub noteswrapper {
3648: my ($link,$un,$do)=@_;
3649: return
1.896 amueller 3650: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3651: }
1.802 bisitz 3652:
1.62 www 3653: # ------------------------------------------------------------- Aboutme Wrapper
3654:
3655: sub aboutmewrapper {
1.1070 raeburn 3656: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3657: if (!defined($username) && !defined($domain)) {
3658: return;
3659: }
1.1075.2.15 raeburn 3660: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3661: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3662: }
3663:
3664: # ------------------------------------------------------------ Syllabus Wrapper
3665:
3666: sub syllabuswrapper {
1.707 bisitz 3667: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3668: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3669: }
1.14 harris41 3670:
1.802 bisitz 3671: # -----------------------------------------------------------------------------
3672:
1.208 matthew 3673: sub track_student_link {
1.887 raeburn 3674: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3675: my $link ="/adm/trackstudent?";
1.208 matthew 3676: my $title = 'View recent activity';
3677: if (defined($sname) && $sname !~ /^\s*$/ &&
3678: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3679: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3680: $title .= ' of this student';
1.268 albertel 3681: }
1.208 matthew 3682: if (defined($target) && $target !~ /^\s*$/) {
3683: $target = qq{target="$target"};
3684: } else {
3685: $target = '';
3686: }
1.268 albertel 3687: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3688: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3689: $title = &mt($title);
3690: $linktext = &mt($linktext);
1.448 albertel 3691: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3692: &help_open_topic('View_recent_activity');
1.208 matthew 3693: }
3694:
1.781 raeburn 3695: sub slot_reservations_link {
3696: my ($linktext,$sname,$sdom,$target) = @_;
3697: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3698: my $title = 'View slot reservation history';
3699: if (defined($sname) && $sname !~ /^\s*$/ &&
3700: defined($sdom) && $sdom !~ /^\s*$/) {
3701: $link .= "&uname=$sname&udom=$sdom";
3702: $title .= ' of this student';
3703: }
3704: if (defined($target) && $target !~ /^\s*$/) {
3705: $target = qq{target="$target"};
3706: } else {
3707: $target = '';
3708: }
3709: $title = &mt($title);
3710: $linktext = &mt($linktext);
3711: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3712: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3713:
3714: }
3715:
1.508 www 3716: # ===================================================== Display a student photo
3717:
3718:
1.509 albertel 3719: sub student_image_tag {
1.508 www 3720: my ($domain,$user)=@_;
3721: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3722: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3723: return '<img src="'.$imgsrc.'" align="right" />';
3724: } else {
3725: return '';
3726: }
3727: }
3728:
1.112 bowersj2 3729: =pod
3730:
3731: =back
3732:
3733: =head1 Access .tab File Data
3734:
3735: =over 4
3736:
1.648 raeburn 3737: =item * &languageids()
1.112 bowersj2 3738:
3739: returns list of all language ids
3740:
3741: =cut
3742:
1.14 harris41 3743: sub languageids {
1.16 harris41 3744: return sort(keys(%language));
1.14 harris41 3745: }
3746:
1.112 bowersj2 3747: =pod
3748:
1.648 raeburn 3749: =item * &languagedescription()
1.112 bowersj2 3750:
3751: returns description of a specified language id
3752:
3753: =cut
3754:
1.14 harris41 3755: sub languagedescription {
1.125 www 3756: my $code=shift;
3757: return ($supported_language{$code}?'* ':'').
3758: $language{$code}.
1.126 www 3759: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3760: }
3761:
1.1048 foxr 3762: =pod
3763:
3764: =item * &plainlanguagedescription
3765:
3766: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3767: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3768:
3769: =cut
3770:
1.145 www 3771: sub plainlanguagedescription {
3772: my $code=shift;
3773: return $language{$code};
3774: }
3775:
1.1048 foxr 3776: =pod
3777:
3778: =item * &supportedlanguagecode
3779:
3780: Returns the supported language code (e.g. sptutf maps to pt) given a language
3781: code.
3782:
3783: =cut
3784:
1.145 www 3785: sub supportedlanguagecode {
3786: my $code=shift;
3787: return $supported_language{$code};
1.97 www 3788: }
3789:
1.112 bowersj2 3790: =pod
3791:
1.1048 foxr 3792: =item * &latexlanguage()
3793:
3794: Given a language key code returns the correspondnig language to use
3795: to select the correct hyphenation on LaTeX printouts. This is undef if there
3796: is no supported hyphenation for the language code.
3797:
3798: =cut
3799:
3800: sub latexlanguage {
3801: my $code = shift;
3802: return $latex_language{$code};
3803: }
3804:
3805: =pod
3806:
3807: =item * &latexhyphenation()
3808:
3809: Same as above but what's supplied is the language as it might be stored
3810: in the metadata.
3811:
3812: =cut
3813:
3814: sub latexhyphenation {
3815: my $key = shift;
3816: return $latex_language_bykey{$key};
3817: }
3818:
3819: =pod
3820:
1.648 raeburn 3821: =item * ©rightids()
1.112 bowersj2 3822:
3823: returns list of all copyrights
3824:
3825: =cut
3826:
3827: sub copyrightids {
3828: return sort(keys(%cprtag));
3829: }
3830:
3831: =pod
3832:
1.648 raeburn 3833: =item * ©rightdescription()
1.112 bowersj2 3834:
3835: returns description of a specified copyright id
3836:
3837: =cut
3838:
3839: sub copyrightdescription {
1.166 www 3840: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3841: }
1.197 matthew 3842:
3843: =pod
3844:
1.648 raeburn 3845: =item * &source_copyrightids()
1.192 taceyjo1 3846:
3847: returns list of all source copyrights
3848:
3849: =cut
3850:
3851: sub source_copyrightids {
3852: return sort(keys(%scprtag));
3853: }
3854:
3855: =pod
3856:
1.648 raeburn 3857: =item * &source_copyrightdescription()
1.192 taceyjo1 3858:
3859: returns description of a specified source copyright id
3860:
3861: =cut
3862:
3863: sub source_copyrightdescription {
3864: return &mt($scprtag{shift(@_)});
3865: }
1.112 bowersj2 3866:
3867: =pod
3868:
1.648 raeburn 3869: =item * &filecategories()
1.112 bowersj2 3870:
3871: returns list of all file categories
3872:
3873: =cut
3874:
3875: sub filecategories {
3876: return sort(keys(%category_extensions));
3877: }
3878:
3879: =pod
3880:
1.648 raeburn 3881: =item * &filecategorytypes()
1.112 bowersj2 3882:
3883: returns list of file types belonging to a given file
3884: category
3885:
3886: =cut
3887:
3888: sub filecategorytypes {
1.356 albertel 3889: my ($cat) = @_;
3890: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3891: }
3892:
3893: =pod
3894:
1.648 raeburn 3895: =item * &fileembstyle()
1.112 bowersj2 3896:
3897: returns embedding style for a specified file type
3898:
3899: =cut
3900:
3901: sub fileembstyle {
3902: return $fe{lc(shift(@_))};
1.169 www 3903: }
3904:
1.351 www 3905: sub filemimetype {
3906: return $fm{lc(shift(@_))};
3907: }
3908:
1.169 www 3909:
3910: sub filecategoryselect {
3911: my ($name,$value)=@_;
1.189 matthew 3912: return &select_form($value,$name,
1.970 raeburn 3913: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3914: }
3915:
3916: =pod
3917:
1.648 raeburn 3918: =item * &filedescription()
1.112 bowersj2 3919:
3920: returns description for a specified file type
3921:
3922: =cut
3923:
3924: sub filedescription {
1.188 matthew 3925: my $file_description = $fd{lc(shift())};
3926: $file_description =~ s:([\[\]]):~$1:g;
3927: return &mt($file_description);
1.112 bowersj2 3928: }
3929:
3930: =pod
3931:
1.648 raeburn 3932: =item * &filedescriptionex()
1.112 bowersj2 3933:
3934: returns description for a specified file type with
3935: extra formatting
3936:
3937: =cut
3938:
3939: sub filedescriptionex {
3940: my $ex=shift;
1.188 matthew 3941: my $file_description = $fd{lc($ex)};
3942: $file_description =~ s:([\[\]]):~$1:g;
3943: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3944: }
3945:
3946: # End of .tab access
3947: =pod
3948:
3949: =back
3950:
3951: =cut
3952:
3953: # ------------------------------------------------------------------ File Types
3954: sub fileextensions {
3955: return sort(keys(%fe));
3956: }
3957:
1.97 www 3958: # ----------------------------------------------------------- Display Languages
3959: # returns a hash with all desired display languages
3960: #
3961:
3962: sub display_languages {
3963: my %languages=();
1.695 raeburn 3964: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3965: $languages{$lang}=1;
1.97 www 3966: }
3967: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3968: if ($env{'form.displaylanguage'}) {
1.356 albertel 3969: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3970: $languages{$lang}=1;
1.97 www 3971: }
3972: }
3973: return %languages;
1.14 harris41 3974: }
3975:
1.582 albertel 3976: sub languages {
3977: my ($possible_langs) = @_;
1.695 raeburn 3978: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3979: if (!ref($possible_langs)) {
3980: if( wantarray ) {
3981: return @preferred_langs;
3982: } else {
3983: return $preferred_langs[0];
3984: }
3985: }
3986: my %possibilities = map { $_ => 1 } (@$possible_langs);
3987: my @preferred_possibilities;
3988: foreach my $preferred_lang (@preferred_langs) {
3989: if (exists($possibilities{$preferred_lang})) {
3990: push(@preferred_possibilities, $preferred_lang);
3991: }
3992: }
3993: if( wantarray ) {
3994: return @preferred_possibilities;
3995: }
3996: return $preferred_possibilities[0];
3997: }
3998:
1.742 raeburn 3999: sub user_lang {
4000: my ($touname,$toudom,$fromcid) = @_;
4001: my @userlangs;
4002: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4003: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4004: $env{'course.'.$fromcid.'.languages'}));
4005: } else {
4006: my %langhash = &getlangs($touname,$toudom);
4007: if ($langhash{'languages'} ne '') {
4008: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4009: } else {
4010: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4011: if ($domdefs{'lang_def'} ne '') {
4012: @userlangs = ($domdefs{'lang_def'});
4013: }
4014: }
4015: }
4016: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4017: my $user_lh = Apache::localize->get_handle(@languages);
4018: return $user_lh;
4019: }
4020:
4021:
1.112 bowersj2 4022: ###############################################################
4023: ## Student Answer Attempts ##
4024: ###############################################################
4025:
4026: =pod
4027:
4028: =head1 Alternate Problem Views
4029:
4030: =over 4
4031:
1.648 raeburn 4032: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 4033: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4034:
4035: Return string with previous attempt on problem. Arguments:
4036:
4037: =over 4
4038:
4039: =item * $symb: Problem, including path
4040:
4041: =item * $username: username of the desired student
4042:
4043: =item * $domain: domain of the desired student
1.14 harris41 4044:
1.112 bowersj2 4045: =item * $course: Course ID
1.14 harris41 4046:
1.112 bowersj2 4047: =item * $getattempt: Leave blank for all attempts, otherwise put
4048: something
1.14 harris41 4049:
1.112 bowersj2 4050: =item * $regexp: if string matches this regexp, the string will be
4051: sent to $gradesub
1.14 harris41 4052:
1.112 bowersj2 4053: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4054:
1.1075.2.86 raeburn 4055: =item * $usec: section of the desired student
4056:
4057: =item * $identifier: counter for student (multiple students one problem) or
4058: problem (one student; whole sequence).
4059:
1.112 bowersj2 4060: =back
1.14 harris41 4061:
1.112 bowersj2 4062: The output string is a table containing all desired attempts, if any.
1.16 harris41 4063:
1.112 bowersj2 4064: =cut
1.1 albertel 4065:
4066: sub get_previous_attempt {
1.1075.2.86 raeburn 4067: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4068: my $prevattempts='';
1.43 ng 4069: no strict 'refs';
1.1 albertel 4070: if ($symb) {
1.3 albertel 4071: my (%returnhash)=
4072: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4073: if ($returnhash{'version'}) {
4074: my %lasthash=();
4075: my $version;
4076: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 4077: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4078: if ($key =~ /\.rawrndseed$/) {
4079: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4080: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4081: } else {
4082: $lasthash{$key}=$returnhash{$version.':'.$key};
4083: }
1.19 harris41 4084: }
1.1 albertel 4085: }
1.596 albertel 4086: $prevattempts=&start_data_table().&start_data_table_header_row();
4087: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4088: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4089: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4090: foreach my $key (sort(keys(%lasthash))) {
4091: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4092: if ($#parts > 0) {
1.31 albertel 4093: my $data=$parts[-1];
1.989 raeburn 4094: next if ($data eq 'foilorder');
1.31 albertel 4095: pop(@parts);
1.1010 www 4096: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4097: if ($data eq 'type') {
4098: unless ($showsurv) {
4099: my $id = join(',',@parts);
4100: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4101: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4102: $lasthidden{$ign.'.'.$id} = 1;
4103: }
1.945 raeburn 4104: }
1.1075.2.86 raeburn 4105: if ($identifier ne '') {
4106: my $id = join(',',@parts);
4107: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4108: $domain,$username,$usec,undef,$course) =~ /^no/) {
4109: $hidestatus{$ign.'.'.$id} = 1;
4110: }
4111: }
4112: } elsif ($data eq 'regrader') {
4113: if (($identifier ne '') && (@parts)) {
4114: my $id = join(',',@parts);
4115: $regraded{$ign.'.'.$id} = 1;
4116: }
1.1010 www 4117: }
1.31 albertel 4118: } else {
1.41 ng 4119: if ($#parts == 0) {
4120: $prevattempts.='<th>'.$parts[0].'</th>';
4121: } else {
4122: $prevattempts.='<th>'.$ign.'</th>';
4123: }
1.31 albertel 4124: }
1.16 harris41 4125: }
1.596 albertel 4126: $prevattempts.=&end_data_table_header_row();
1.40 ng 4127: if ($getattempt eq '') {
1.1075.2.86 raeburn 4128: my (%solved,%resets,%probstatus);
4129: if (($identifier ne '') && (keys(%regraded) > 0)) {
4130: for ($version=1;$version<=$returnhash{'version'};$version++) {
4131: foreach my $id (keys(%regraded)) {
4132: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4133: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4134: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4135: push(@{$resets{$id}},$version);
4136: }
4137: }
4138: }
4139: }
1.40 ng 4140: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4141: my (@hidden,@unsolved);
1.945 raeburn 4142: if (%typeparts) {
4143: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4144: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4145: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4146: push(@hidden,$id);
1.1075.2.86 raeburn 4147: } elsif ($identifier ne '') {
4148: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4149: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4150: ($hidestatus{$id})) {
4151: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4152: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4153: push(@{$solved{$id}},$version);
4154: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4155: (ref($solved{$id}) eq 'ARRAY')) {
4156: my $skip;
4157: if (ref($resets{$id}) eq 'ARRAY') {
4158: foreach my $reset (@{$resets{$id}}) {
4159: if ($reset > $solved{$id}[-1]) {
4160: $skip=1;
4161: last;
4162: }
4163: }
4164: }
4165: unless ($skip) {
4166: my ($ign,$partslist) = split(/\./,$id,2);
4167: push(@unsolved,$partslist);
4168: }
4169: }
4170: }
1.945 raeburn 4171: }
4172: }
4173: }
4174: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4175: '<td>'.&mt('Transaction [_1]',$version);
4176: if (@unsolved) {
4177: $prevattempts .= '<span class="LC_nobreak"><label>'.
4178: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4179: &mt('Hide').'</label></span>';
4180: }
4181: $prevattempts .= '</td>';
1.945 raeburn 4182: if (@hidden) {
4183: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4184: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4185: my $hide;
4186: foreach my $id (@hidden) {
4187: if ($key =~ /^\Q$id\E/) {
4188: $hide = 1;
4189: last;
4190: }
4191: }
4192: if ($hide) {
4193: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4194: if (($data eq 'award') || ($data eq 'awarddetail')) {
4195: my $value = &format_previous_attempt_value($key,
4196: $returnhash{$version.':'.$key});
4197: $prevattempts.='<td>'.$value.' </td>';
4198: } else {
4199: $prevattempts.='<td> </td>';
4200: }
4201: } else {
4202: if ($key =~ /\./) {
1.1075.2.91 raeburn 4203: my $value = $returnhash{$version.':'.$key};
4204: if ($key =~ /\.rndseed$/) {
4205: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4206: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4207: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4208: }
4209: }
4210: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4211: ' </td>';
1.945 raeburn 4212: } else {
4213: $prevattempts.='<td> </td>';
4214: }
4215: }
4216: }
4217: } else {
4218: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4219: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4220: my $value = $returnhash{$version.':'.$key};
4221: if ($key =~ /\.rndseed$/) {
4222: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4223: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4224: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4225: }
4226: }
4227: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4228: ' </td>';
1.945 raeburn 4229: }
4230: }
4231: $prevattempts.=&end_data_table_row();
1.40 ng 4232: }
1.1 albertel 4233: }
1.945 raeburn 4234: my @currhidden = keys(%lasthidden);
1.596 albertel 4235: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4236: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4237: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4238: if (%typeparts) {
4239: my $hidden;
4240: foreach my $id (@currhidden) {
4241: if ($key =~ /^\Q$id\E/) {
4242: $hidden = 1;
4243: last;
4244: }
4245: }
4246: if ($hidden) {
4247: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4248: if (($data eq 'award') || ($data eq 'awarddetail')) {
4249: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4250: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4251: $value = &$gradesub($value);
4252: }
4253: $prevattempts.='<td>'.$value.' </td>';
4254: } else {
4255: $prevattempts.='<td> </td>';
4256: }
4257: } else {
4258: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4259: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4260: $value = &$gradesub($value);
4261: }
4262: $prevattempts.='<td>'.$value.' </td>';
4263: }
4264: } else {
4265: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4266: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4267: $value = &$gradesub($value);
4268: }
4269: $prevattempts.='<td>'.$value.' </td>';
4270: }
1.16 harris41 4271: }
1.596 albertel 4272: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4273: } else {
1.596 albertel 4274: $prevattempts=
4275: &start_data_table().&start_data_table_row().
4276: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4277: &end_data_table_row().&end_data_table();
1.1 albertel 4278: }
4279: } else {
1.596 albertel 4280: $prevattempts=
4281: &start_data_table().&start_data_table_row().
4282: '<td>'.&mt('No data.').'</td>'.
4283: &end_data_table_row().&end_data_table();
1.1 albertel 4284: }
1.10 albertel 4285: }
4286:
1.581 albertel 4287: sub format_previous_attempt_value {
4288: my ($key,$value) = @_;
1.1011 www 4289: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4290: $value = &Apache::lonlocal::locallocaltime($value);
4291: } elsif (ref($value) eq 'ARRAY') {
4292: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4293: } elsif ($key =~ /answerstring$/) {
4294: my %answers = &Apache::lonnet::str2hash($value);
4295: my @anskeys = sort(keys(%answers));
4296: if (@anskeys == 1) {
4297: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4298: if ($answer =~ m{\0}) {
4299: $answer =~ s{\0}{,}g;
1.988 raeburn 4300: }
4301: my $tag_internal_answer_name = 'INTERNAL';
4302: if ($anskeys[0] eq $tag_internal_answer_name) {
4303: $value = $answer;
4304: } else {
4305: $value = $anskeys[0].'='.$answer;
4306: }
4307: } else {
4308: foreach my $ans (@anskeys) {
4309: my $answer = $answers{$ans};
1.1001 raeburn 4310: if ($answer =~ m{\0}) {
4311: $answer =~ s{\0}{,}g;
1.988 raeburn 4312: }
4313: $value .= $ans.'='.$answer.'<br />';;
4314: }
4315: }
1.581 albertel 4316: } else {
4317: $value = &unescape($value);
4318: }
4319: return $value;
4320: }
4321:
4322:
1.107 albertel 4323: sub relative_to_absolute {
4324: my ($url,$output)=@_;
4325: my $parser=HTML::TokeParser->new(\$output);
4326: my $token;
4327: my $thisdir=$url;
4328: my @rlinks=();
4329: while ($token=$parser->get_token) {
4330: if ($token->[0] eq 'S') {
4331: if ($token->[1] eq 'a') {
4332: if ($token->[2]->{'href'}) {
4333: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4334: }
4335: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4336: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4337: } elsif ($token->[1] eq 'base') {
4338: $thisdir=$token->[2]->{'href'};
4339: }
4340: }
4341: }
4342: $thisdir=~s-/[^/]*$--;
1.356 albertel 4343: foreach my $link (@rlinks) {
1.726 raeburn 4344: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4345: ($link=~/^\//) ||
4346: ($link=~/^javascript:/i) ||
4347: ($link=~/^mailto:/i) ||
4348: ($link=~/^\#/)) {
4349: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4350: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4351: }
4352: }
4353: # -------------------------------------------------- Deal with Applet codebases
4354: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4355: return $output;
4356: }
4357:
1.112 bowersj2 4358: =pod
4359:
1.648 raeburn 4360: =item * &get_student_view()
1.112 bowersj2 4361:
4362: show a snapshot of what student was looking at
4363:
4364: =cut
4365:
1.10 albertel 4366: sub get_student_view {
1.186 albertel 4367: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4368: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4369: my (%form);
1.10 albertel 4370: my @elements=('symb','courseid','domain','username');
4371: foreach my $element (@elements) {
1.186 albertel 4372: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4373: }
1.186 albertel 4374: if (defined($moreenv)) {
4375: %form=(%form,%{$moreenv});
4376: }
1.236 albertel 4377: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4378: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4379: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4380: $userview=~s/\<body[^\>]*\>//gi;
4381: $userview=~s/\<\/body\>//gi;
4382: $userview=~s/\<html\>//gi;
4383: $userview=~s/\<\/html\>//gi;
4384: $userview=~s/\<head\>//gi;
4385: $userview=~s/\<\/head\>//gi;
4386: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4387: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4388: if (wantarray) {
4389: return ($userview,$response);
4390: } else {
4391: return $userview;
4392: }
4393: }
4394:
4395: sub get_student_view_with_retries {
4396: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4397:
4398: my $ok = 0; # True if we got a good response.
4399: my $content;
4400: my $response;
4401:
4402: # Try to get the student_view done. within the retries count:
4403:
4404: do {
4405: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4406: $ok = $response->is_success;
4407: if (!$ok) {
4408: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4409: }
4410: $retries--;
4411: } while (!$ok && ($retries > 0));
4412:
4413: if (!$ok) {
4414: $content = ''; # On error return an empty content.
4415: }
1.651 www 4416: if (wantarray) {
4417: return ($content, $response);
4418: } else {
4419: return $content;
4420: }
1.11 albertel 4421: }
4422:
1.1075.2.149 raeburn 4423: sub css_links {
4424: my ($currsymb,$level) = @_;
4425: my ($links,@symbs,%cssrefs,%httpref);
4426: if ($level eq 'map') {
4427: my $navmap = Apache::lonnavmaps::navmap->new();
4428: if (ref($navmap)) {
4429: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
4430: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
4431: foreach my $res (@resources) {
4432: if (ref($res) && $res->symb()) {
4433: push(@symbs,$res->symb());
4434: }
4435: }
4436: }
4437: } else {
4438: @symbs = ($currsymb);
4439: }
4440: foreach my $symb (@symbs) {
4441: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
4442: if ($css_href =~ /\S/) {
4443: unless ($css_href =~ m{https?://}) {
4444: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
4445: my $proburl = &Apache::lonnet::clutter($url);
4446: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
4447: unless ($css_href =~ m{^/}) {
4448: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
4449: }
4450: if ($css_href =~ m{^/(res|uploaded)/}) {
4451: unless (($httpref{'httpref.'.$css_href}) ||
4452: (&Apache::lonnet::is_on_map($css_href))) {
4453: my $thisurl = $proburl;
4454: if ($env{'httpref.'.$proburl}) {
4455: $thisurl = $env{'httpref.'.$proburl};
4456: }
4457: $httpref{'httpref.'.$css_href} = $thisurl;
4458: }
4459: }
4460: }
4461: $cssrefs{$css_href} = 1;
4462: }
4463: }
4464: if (keys(%httpref)) {
4465: &Apache::lonnet::appenv(\%httpref);
4466: }
4467: if (keys(%cssrefs)) {
4468: foreach my $css_href (keys(%cssrefs)) {
4469: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
4470: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
4471: }
4472: }
4473: return $links;
4474: }
4475:
1.112 bowersj2 4476: =pod
4477:
1.648 raeburn 4478: =item * &get_student_answers()
1.112 bowersj2 4479:
4480: show a snapshot of how student was answering problem
4481:
4482: =cut
4483:
1.11 albertel 4484: sub get_student_answers {
1.100 sakharuk 4485: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4486: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4487: my (%moreenv);
1.11 albertel 4488: my @elements=('symb','courseid','domain','username');
4489: foreach my $element (@elements) {
1.186 albertel 4490: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4491: }
1.186 albertel 4492: $moreenv{'grade_target'}='answer';
4493: %moreenv=(%form,%moreenv);
1.497 raeburn 4494: $feedurl = &Apache::lonnet::clutter($feedurl);
4495: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4496: return $userview;
1.1 albertel 4497: }
1.116 albertel 4498:
4499: =pod
4500:
4501: =item * &submlink()
4502:
1.242 albertel 4503: Inputs: $text $uname $udom $symb $target
1.116 albertel 4504:
4505: Returns: A link to grades.pm such as to see the SUBM view of a student
4506:
4507: =cut
4508:
4509: ###############################################
4510: sub submlink {
1.242 albertel 4511: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4512: if (!($uname && $udom)) {
4513: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4514: &Apache::lonnet::whichuser($symb);
1.116 albertel 4515: if (!$symb) { $symb=$cursymb; }
4516: }
1.254 matthew 4517: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4518: $symb=&escape($symb);
1.960 bisitz 4519: if ($target) { $target=" target=\"$target\""; }
4520: return
4521: '<a href="/adm/grades?command=submission'.
4522: '&symb='.$symb.
4523: '&student='.$uname.
4524: '&userdom='.$udom.'"'.
4525: $target.'>'.$text.'</a>';
1.242 albertel 4526: }
4527: ##############################################
4528:
4529: =pod
4530:
4531: =item * &pgrdlink()
4532:
4533: Inputs: $text $uname $udom $symb $target
4534:
4535: Returns: A link to grades.pm such as to see the PGRD view of a student
4536:
4537: =cut
4538:
4539: ###############################################
4540: sub pgrdlink {
4541: my $link=&submlink(@_);
4542: $link=~s/(&command=submission)/$1&showgrading=yes/;
4543: return $link;
4544: }
4545: ##############################################
4546:
4547: =pod
4548:
4549: =item * &pprmlink()
4550:
4551: Inputs: $text $uname $udom $symb $target
4552:
4553: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4554: student and a specific resource
1.242 albertel 4555:
4556: =cut
4557:
4558: ###############################################
4559: sub pprmlink {
4560: my ($text,$uname,$udom,$symb,$target)=@_;
4561: if (!($uname && $udom)) {
4562: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4563: &Apache::lonnet::whichuser($symb);
1.242 albertel 4564: if (!$symb) { $symb=$cursymb; }
4565: }
1.254 matthew 4566: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4567: $symb=&escape($symb);
1.242 albertel 4568: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4569: return '<a href="/adm/parmset?command=set&'.
4570: 'symb='.$symb.'&uname='.$uname.
4571: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4572: }
4573: ##############################################
1.37 matthew 4574:
1.112 bowersj2 4575: =pod
4576:
4577: =back
4578:
4579: =cut
4580:
1.37 matthew 4581: ###############################################
1.51 www 4582:
4583:
4584: sub timehash {
1.687 raeburn 4585: my ($thistime) = @_;
4586: my $timezone = &Apache::lonlocal::gettimezone();
4587: my $dt = DateTime->from_epoch(epoch => $thistime)
4588: ->set_time_zone($timezone);
4589: my $wday = $dt->day_of_week();
4590: if ($wday == 7) { $wday = 0; }
4591: return ( 'second' => $dt->second(),
4592: 'minute' => $dt->minute(),
4593: 'hour' => $dt->hour(),
4594: 'day' => $dt->day_of_month(),
4595: 'month' => $dt->month(),
4596: 'year' => $dt->year(),
4597: 'weekday' => $wday,
4598: 'dayyear' => $dt->day_of_year(),
4599: 'dlsav' => $dt->is_dst() );
1.51 www 4600: }
4601:
1.370 www 4602: sub utc_string {
4603: my ($date)=@_;
1.371 www 4604: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4605: }
4606:
1.51 www 4607: sub maketime {
4608: my %th=@_;
1.687 raeburn 4609: my ($epoch_time,$timezone,$dt);
4610: $timezone = &Apache::lonlocal::gettimezone();
4611: eval {
4612: $dt = DateTime->new( year => $th{'year'},
4613: month => $th{'month'},
4614: day => $th{'day'},
4615: hour => $th{'hour'},
4616: minute => $th{'minute'},
4617: second => $th{'second'},
4618: time_zone => $timezone,
4619: );
4620: };
4621: if (!$@) {
4622: $epoch_time = $dt->epoch;
4623: if ($epoch_time) {
4624: return $epoch_time;
4625: }
4626: }
1.51 www 4627: return POSIX::mktime(
4628: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4629: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4630: }
4631:
4632: #########################################
1.51 www 4633:
4634: sub findallcourses {
1.482 raeburn 4635: my ($roles,$uname,$udom) = @_;
1.355 albertel 4636: my %roles;
4637: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4638: my %courses;
1.51 www 4639: my $now=time;
1.482 raeburn 4640: if (!defined($uname)) {
4641: $uname = $env{'user.name'};
4642: }
4643: if (!defined($udom)) {
4644: $udom = $env{'user.domain'};
4645: }
4646: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4647: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4648: if (!%roles) {
4649: %roles = (
4650: cc => 1,
1.907 raeburn 4651: co => 1,
1.482 raeburn 4652: in => 1,
4653: ep => 1,
4654: ta => 1,
4655: cr => 1,
4656: st => 1,
4657: );
4658: }
4659: foreach my $entry (keys(%roleshash)) {
4660: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4661: if ($trole =~ /^cr/) {
4662: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4663: } else {
4664: next if (!exists($roles{$trole}));
4665: }
4666: if ($tend) {
4667: next if ($tend < $now);
4668: }
4669: if ($tstart) {
4670: next if ($tstart > $now);
4671: }
1.1058 raeburn 4672: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4673: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4674: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4675: if ($secpart eq '') {
4676: ($cnum,$role) = split(/_/,$cnumpart);
4677: $sec = 'none';
1.1058 raeburn 4678: $value .= $cnum.'/';
1.482 raeburn 4679: } else {
4680: $cnum = $cnumpart;
4681: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4682: $value .= $cnum.'/'.$sec;
4683: }
4684: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4685: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4686: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4687: }
4688: } else {
4689: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4690: }
1.482 raeburn 4691: }
4692: } else {
4693: foreach my $key (keys(%env)) {
1.483 albertel 4694: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4695: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4696: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4697: next if ($role eq 'ca' || $role eq 'aa');
4698: next if (%roles && !exists($roles{$role}));
4699: my ($starttime,$endtime)=split(/\./,$env{$key});
4700: my $active=1;
4701: if ($starttime) {
4702: if ($now<$starttime) { $active=0; }
4703: }
4704: if ($endtime) {
4705: if ($now>$endtime) { $active=0; }
4706: }
4707: if ($active) {
1.1058 raeburn 4708: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4709: if ($sec eq '') {
4710: $sec = 'none';
1.1058 raeburn 4711: } else {
4712: $value .= $sec;
4713: }
4714: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4715: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4716: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4717: }
4718: } else {
4719: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4720: }
1.474 raeburn 4721: }
4722: }
1.51 www 4723: }
4724: }
1.474 raeburn 4725: return %courses;
1.51 www 4726: }
1.37 matthew 4727:
1.54 www 4728: ###############################################
1.474 raeburn 4729:
4730: sub blockcheck {
1.1075.2.158 raeburn 4731: my ($setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.490 raeburn 4732:
1.1075.2.158 raeburn 4733: unless ($activity eq 'docs') {
4734: my ($has_evb,$check_ipaccess);
4735: my $dom = $env{'user.domain'};
4736: if ($env{'request.course.id'}) {
4737: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4738: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4739: my $checkrole = "cm./$cdom/$cnum";
4740: my $sec = $env{'request.course.sec'};
4741: if ($sec ne '') {
4742: $checkrole .= "/$sec";
4743: }
4744: if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
4745: ($env{'request.role'} !~ /^st/)) {
4746: $has_evb = 1;
4747: }
4748: unless ($has_evb) {
4749: if (($activity eq 'printout') || ($activity eq 'grades') || ($activity eq 'search') ||
4750: ($activity eq 'boards') || ($activity eq 'groups') || ($activity eq 'chat')) {
4751: if ($udom eq $cdom) {
4752: $check_ipaccess = 1;
4753: }
4754: }
4755: }
1.1075.2.163 raeburn 4756: } elsif (($activity eq 'com') || ($activity eq 'port') || ($activity eq 'blogs') ||
4757: ($activity eq 'about') || ($activity eq 'wishlist') || ($activity eq 'passwd')) {
4758: my $checkrole;
4759: if ($env{'request.role.domain'} eq '') {
4760: $checkrole = "cm./$env{'user.domain'}/";
4761: } else {
4762: $checkrole = "cm./$env{'request.role.domain'}/";
4763: }
4764: if (($checkrole) && (&Apache::lonnet::allowed('evb',undef,undef,$checkrole))) {
4765: $has_evb = 1;
4766: }
1.1075.2.158 raeburn 4767: }
4768: unless ($has_evb || $check_ipaccess) {
4769: my @machinedoms = &Apache::lonnet::current_machine_domains();
4770: if (($dom eq 'public') && ($activity eq 'port')) {
4771: $dom = $udom;
4772: }
4773: if (($dom ne '') && (grep(/^\Q$dom\E$/,@machinedoms))) {
4774: $check_ipaccess = 1;
4775: } else {
4776: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
4777: my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
4778: my $prim = &Apache::lonnet::domain($dom,'primary');
4779: my $intdom = &Apache::lonnet::internet_dom($prim);
4780: if (($intdom ne '') && (ref($internet_names) eq 'ARRAY')) {
4781: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4782: $check_ipaccess = 1;
4783: }
4784: }
4785: }
4786: }
4787: if ($check_ipaccess) {
4788: my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$dom);
4789: unless (defined($cached)) {
4790: my %domconfig =
4791: &Apache::lonnet::get_dom('configuration',['ipaccess'],$dom);
4792: $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$dom,$domconfig{'ipaccess'},1800);
4793: }
4794: if ((ref($ipaccessref) eq 'HASH') && ($clientip)) {
4795: foreach my $id (keys(%{$ipaccessref})) {
4796: if (ref($ipaccessref->{$id}) eq 'HASH') {
4797: my $range = $ipaccessref->{$id}->{'ip'};
4798: if ($range) {
4799: if (&Apache::lonnet::ip_match($clientip,$range)) {
4800: if (ref($ipaccessref->{$id}->{'commblocks'}) eq 'HASH') {
4801: if ($ipaccessref->{$id}->{'commblocks'}->{$activity} eq 'on') {
4802: return ('','','',$id,$dom);
4803: last;
4804: }
4805: }
4806: }
4807: }
4808: }
4809: }
4810: }
4811: }
1.1075.2.164 raeburn 4812: if (($activity eq 'wishlist') || ($activity eq 'annotate')) {
4813: return ();
4814: }
1.1075.2.158 raeburn 4815: }
1.1075.2.73 raeburn 4816: if (defined($udom) && defined($uname)) {
4817: # If uname and udom are for a course, check for blocks in the course.
4818: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4819: my ($startblock,$endblock,$triggerblock) =
1.1075.2.147 raeburn 4820: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1075.2.73 raeburn 4821: return ($startblock,$endblock,$triggerblock);
4822: }
4823: } else {
1.490 raeburn 4824: $udom = $env{'user.domain'};
4825: $uname = $env{'user.name'};
4826: }
4827:
1.502 raeburn 4828: my $startblock = 0;
4829: my $endblock = 0;
1.1062 raeburn 4830: my $triggerblock = '';
1.1075.2.160 raeburn 4831: my %live_courses;
4832: unless (($activity eq 'wishlist') || ($activity eq 'annotate')) {
4833: %live_courses = &findallcourses(undef,$uname,$udom);
4834: }
1.474 raeburn 4835:
1.490 raeburn 4836: # If uname is for a user, and activity is course-specific, i.e.,
4837: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4838:
1.490 raeburn 4839: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4840: $activity eq 'groups' || $activity eq 'printout') &&
4841: ($env{'request.course.id'})) {
1.490 raeburn 4842: foreach my $key (keys(%live_courses)) {
4843: if ($key ne $env{'request.course.id'}) {
4844: delete($live_courses{$key});
4845: }
4846: }
4847: }
4848:
4849: my $otheruser = 0;
4850: my %own_courses;
4851: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4852: # Resource belongs to user other than current user.
4853: $otheruser = 1;
4854: # Gather courses for current user
4855: %own_courses =
4856: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4857: }
4858:
4859: # Gather active course roles - course coordinator, instructor,
4860: # exam proctor, ta, student, or custom role.
1.474 raeburn 4861:
4862: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4863: my ($cdom,$cnum);
4864: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4865: $cdom = $env{'course.'.$course.'.domain'};
4866: $cnum = $env{'course.'.$course.'.num'};
4867: } else {
1.490 raeburn 4868: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4869: }
4870: my $no_ownblock = 0;
4871: my $no_userblock = 0;
1.533 raeburn 4872: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4873: # Check if current user has 'evb' priv for this
4874: if (defined($own_courses{$course})) {
4875: foreach my $sec (keys(%{$own_courses{$course}})) {
4876: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4877: if ($sec ne 'none') {
4878: $checkrole .= '/'.$sec;
4879: }
4880: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4881: $no_ownblock = 1;
4882: last;
4883: }
4884: }
4885: }
4886: # if they have 'evb' priv and are currently not playing student
4887: next if (($no_ownblock) &&
4888: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4889: }
1.474 raeburn 4890: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4891: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4892: if ($sec ne 'none') {
1.482 raeburn 4893: $checkrole .= '/'.$sec;
1.474 raeburn 4894: }
1.490 raeburn 4895: if ($otheruser) {
4896: # Resource belongs to user other than current user.
4897: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4898: my (%allroles,%userroles);
4899: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4900: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4901: my ($trole,$tdom,$tnum,$tsec);
4902: if ($entry =~ /^cr/) {
4903: ($trole,$tdom,$tnum,$tsec) =
4904: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4905: } else {
4906: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4907: }
4908: my ($spec,$area,$trest);
4909: $area = '/'.$tdom.'/'.$tnum;
4910: $trest = $tnum;
4911: if ($tsec ne '') {
4912: $area .= '/'.$tsec;
4913: $trest .= '/'.$tsec;
4914: }
4915: $spec = $trole.'.'.$area;
4916: if ($trole =~ /^cr/) {
4917: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4918: $tdom,$spec,$trest,$area);
4919: } else {
4920: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4921: $tdom,$spec,$trest,$area);
4922: }
4923: }
1.1075.2.124 raeburn 4924: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 4925: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4926: if ($1) {
4927: $no_userblock = 1;
4928: last;
4929: }
1.486 raeburn 4930: }
4931: }
1.490 raeburn 4932: } else {
4933: # Resource belongs to current user
4934: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4935: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4936: $no_ownblock = 1;
4937: last;
4938: }
1.474 raeburn 4939: }
4940: }
4941: # if they have the evb priv and are currently not playing student
1.482 raeburn 4942: next if (($no_ownblock) &&
1.491 albertel 4943: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4944: next if ($no_userblock);
1.474 raeburn 4945:
1.1075.2.128 raeburn 4946: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 4947: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4948:
1.1062 raeburn 4949: my ($start,$end,$trigger) =
1.1075.2.147 raeburn 4950: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 4951: if (($start != 0) &&
4952: (($startblock == 0) || ($startblock > $start))) {
4953: $startblock = $start;
1.1062 raeburn 4954: if ($trigger ne '') {
4955: $triggerblock = $trigger;
4956: }
1.502 raeburn 4957: }
4958: if (($end != 0) &&
4959: (($endblock == 0) || ($endblock < $end))) {
4960: $endblock = $end;
1.1062 raeburn 4961: if ($trigger ne '') {
4962: $triggerblock = $trigger;
4963: }
1.502 raeburn 4964: }
1.490 raeburn 4965: }
1.1062 raeburn 4966: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4967: }
4968:
4969: sub get_blocks {
1.1075.2.147 raeburn 4970: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 4971: my $startblock = 0;
4972: my $endblock = 0;
1.1062 raeburn 4973: my $triggerblock = '';
1.490 raeburn 4974: my $course = $cdom.'_'.$cnum;
4975: $setters->{$course} = {};
4976: $setters->{$course}{'staff'} = [];
4977: $setters->{$course}{'times'} = [];
1.1062 raeburn 4978: $setters->{$course}{'triggers'} = [];
4979: my (@blockers,%triggered);
4980: my $now = time;
4981: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4982: if ($activity eq 'docs') {
1.1075.2.148 raeburn 4983: my ($blocked,$nosymbcache,$noenccheck);
1.1075.2.147 raeburn 4984: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
4985: $blocked = 1;
4986: $nosymbcache = 1;
1.1075.2.148 raeburn 4987: $noenccheck = 1;
1.1075.2.147 raeburn 4988: }
1.1075.2.148 raeburn 4989: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 4990: foreach my $block (@blockers) {
4991: if ($block =~ /^firstaccess____(.+)$/) {
4992: my $item = $1;
4993: my $type = 'map';
4994: my $timersymb = $item;
4995: if ($item eq 'course') {
4996: $type = 'course';
4997: } elsif ($item =~ /___\d+___/) {
4998: $type = 'resource';
4999: } else {
5000: $timersymb = &Apache::lonnet::symbread($item);
5001: }
5002: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5003: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5004: $triggered{$block} = {
5005: start => $start,
5006: end => $end,
5007: type => $type,
5008: };
5009: }
5010: }
5011: } else {
5012: foreach my $block (keys(%commblocks)) {
5013: if ($block =~ m/^(\d+)____(\d+)$/) {
5014: my ($start,$end) = ($1,$2);
5015: if ($start <= time && $end >= time) {
5016: if (ref($commblocks{$block}) eq 'HASH') {
5017: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5018: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5019: unless(grep(/^\Q$block\E$/,@blockers)) {
5020: push(@blockers,$block);
5021: }
5022: }
5023: }
5024: }
5025: }
5026: } elsif ($block =~ /^firstaccess____(.+)$/) {
5027: my $item = $1;
5028: my $timersymb = $item;
5029: my $type = 'map';
5030: if ($item eq 'course') {
5031: $type = 'course';
5032: } elsif ($item =~ /___\d+___/) {
5033: $type = 'resource';
5034: } else {
5035: $timersymb = &Apache::lonnet::symbread($item);
5036: }
5037: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5038: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5039: if ($start && $end) {
5040: if (($start <= time) && ($end >= time)) {
1.1075.2.158 raeburn 5041: if (ref($commblocks{$block}) eq 'HASH') {
5042: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5043: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5044: unless(grep(/^\Q$block\E$/,@blockers)) {
5045: push(@blockers,$block);
5046: $triggered{$block} = {
5047: start => $start,
5048: end => $end,
5049: type => $type,
5050: };
5051: }
5052: }
5053: }
1.1062 raeburn 5054: }
5055: }
1.490 raeburn 5056: }
1.1062 raeburn 5057: }
5058: }
5059: }
5060: foreach my $blocker (@blockers) {
5061: my ($staff_name,$staff_dom,$title,$blocks) =
5062: &parse_block_record($commblocks{$blocker});
5063: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5064: my ($start,$end,$triggertype);
5065: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5066: ($start,$end) = ($1,$2);
5067: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5068: $start = $triggered{$blocker}{'start'};
5069: $end = $triggered{$blocker}{'end'};
5070: $triggertype = $triggered{$blocker}{'type'};
5071: }
5072: if ($start) {
5073: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5074: if ($triggertype) {
5075: push(@{$$setters{$course}{'triggers'}},$triggertype);
5076: } else {
5077: push(@{$$setters{$course}{'triggers'}},0);
5078: }
5079: if ( ($startblock == 0) || ($startblock > $start) ) {
5080: $startblock = $start;
5081: if ($triggertype) {
5082: $triggerblock = $blocker;
1.474 raeburn 5083: }
5084: }
1.1062 raeburn 5085: if ( ($endblock == 0) || ($endblock < $end) ) {
5086: $endblock = $end;
5087: if ($triggertype) {
5088: $triggerblock = $blocker;
5089: }
5090: }
1.474 raeburn 5091: }
5092: }
1.1062 raeburn 5093: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5094: }
5095:
5096: sub parse_block_record {
5097: my ($record) = @_;
5098: my ($setuname,$setudom,$title,$blocks);
5099: if (ref($record) eq 'HASH') {
5100: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5101: $title = &unescape($record->{'event'});
5102: $blocks = $record->{'blocks'};
5103: } else {
5104: my @data = split(/:/,$record,3);
5105: if (scalar(@data) eq 2) {
5106: $title = $data[1];
5107: ($setuname,$setudom) = split(/@/,$data[0]);
5108: } else {
5109: ($setuname,$setudom,$title) = @data;
5110: }
5111: $blocks = { 'com' => 'on' };
5112: }
5113: return ($setuname,$setudom,$title,$blocks);
5114: }
5115:
1.854 kalberla 5116: sub blocking_status {
1.1075.2.158 raeburn 5117: my ($activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5118: my %setters;
1.890 droeschl 5119:
1.1061 raeburn 5120: # check for active blocking
1.1075.2.158 raeburn 5121: if ($clientip eq '') {
5122: $clientip = &Apache::lonnet::get_requestor_ip();
5123: }
5124: my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
5125: &blockcheck(\%setters,$activity,$clientip,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5126: my $blocked = 0;
1.1075.2.158 raeburn 5127: if (($startblock && $endblock) || ($by_ip)) {
1.1062 raeburn 5128: $blocked = 1;
5129: }
1.890 droeschl 5130:
1.1061 raeburn 5131: # caller just wants to know whether a block is active
5132: if (!wantarray) { return $blocked; }
5133:
5134: # build a link to a popup window containing the details
5135: my $querystring = "?activity=$activity";
1.1075.2.158 raeburn 5136: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5137: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1075.2.97 raeburn 5138: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5139: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5140: } elsif ($activity eq 'docs') {
1.1075.2.147 raeburn 5141: my $showurl = &Apache::lonenc::check_encrypt($url);
5142: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5143: if ($symb) {
5144: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5145: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5146: }
1.1062 raeburn 5147: }
1.1061 raeburn 5148:
5149: my $output .= <<'END_MYBLOCK';
5150: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5151: var options = "width=" + w + ",height=" + h + ",";
5152: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5153: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5154: var newWin = window.open(url, wdwName, options);
5155: newWin.focus();
5156: }
1.890 droeschl 5157: END_MYBLOCK
1.854 kalberla 5158:
1.1061 raeburn 5159: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5160:
1.1061 raeburn 5161: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5162: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 5163: my $class = 'LC_comblock';
1.1062 raeburn 5164: if ($activity eq 'docs') {
5165: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 5166: $class = '';
1.1063 raeburn 5167: } elsif ($activity eq 'printout') {
5168: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 5169: } elsif ($activity eq 'passwd') {
5170: $text = &mt('Password Changing Blocked');
1.1075.2.158 raeburn 5171: } elsif ($activity eq 'grades') {
5172: $text = &mt('Gradebook Blocked');
5173: } elsif ($activity eq 'search') {
5174: $text = &mt('Search Blocked');
5175: } elsif ($activity eq 'about') {
5176: $text = &mt('Access to User Information Pages Blocked');
1.1075.2.160 raeburn 5177: } elsif ($activity eq 'wishlist') {
5178: $text = &mt('Access to Stored Links Blocked');
5179: } elsif ($activity eq 'annotate') {
5180: $text = &mt('Access to Annotations Blocked');
1.1062 raeburn 5181: }
1.1061 raeburn 5182: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 5183: <div class='$class'>
1.869 kalberla 5184: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5185: title='$text'>
5186: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5187: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5188: title='$text'>$text</a>
1.867 kalberla 5189: </div>
5190:
5191: END_BLOCK
1.474 raeburn 5192:
1.1061 raeburn 5193: return ($blocked, $output);
1.854 kalberla 5194: }
1.490 raeburn 5195:
1.60 matthew 5196: ###############################################
5197:
1.682 raeburn 5198: sub check_ip_acc {
1.1075.2.105 raeburn 5199: my ($acc,$clientip)=@_;
1.682 raeburn 5200: &Apache::lonxml::debug("acc is $acc");
5201: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5202: return 1;
5203: }
5204: my $allowed=0;
1.1075.2.144 raeburn 5205: my $ip;
5206: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5207: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5208: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5209: } else {
1.1075.2.150 raeburn 5210: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5211: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1075.2.144 raeburn 5212: }
1.682 raeburn 5213:
5214: my $name;
5215: foreach my $pattern (split(',',$acc)) {
5216: $pattern =~ s/^\s*//;
5217: $pattern =~ s/\s*$//;
5218: if ($pattern =~ /\*$/) {
5219: #35.8.*
5220: $pattern=~s/\*//;
5221: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5222: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5223: #35.8.3.[34-56]
5224: my $low=$2;
5225: my $high=$3;
5226: $pattern=$1;
5227: if ($ip =~ /^\Q$pattern\E/) {
5228: my $last=(split(/\./,$ip))[3];
5229: if ($last <=$high && $last >=$low) { $allowed=1; }
5230: }
5231: } elsif ($pattern =~ /^\*/) {
5232: #*.msu.edu
5233: $pattern=~s/\*//;
5234: if (!defined($name)) {
5235: use Socket;
5236: my $netaddr=inet_aton($ip);
5237: ($name)=gethostbyaddr($netaddr,AF_INET);
5238: }
5239: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5240: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5241: #127.0.0.1
5242: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5243: } else {
5244: #some.name.com
5245: if (!defined($name)) {
5246: use Socket;
5247: my $netaddr=inet_aton($ip);
5248: ($name)=gethostbyaddr($netaddr,AF_INET);
5249: }
5250: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5251: }
5252: if ($allowed) { last; }
5253: }
5254: return $allowed;
5255: }
5256:
5257: ###############################################
5258:
1.60 matthew 5259: =pod
5260:
1.112 bowersj2 5261: =head1 Domain Template Functions
5262:
5263: =over 4
5264:
5265: =item * &determinedomain()
1.60 matthew 5266:
5267: Inputs: $domain (usually will be undef)
5268:
1.63 www 5269: Returns: Determines which domain should be used for designs
1.60 matthew 5270:
5271: =cut
1.54 www 5272:
1.60 matthew 5273: ###############################################
1.63 www 5274: sub determinedomain {
5275: my $domain=shift;
1.531 albertel 5276: if (! $domain) {
1.60 matthew 5277: # Determine domain if we have not been given one
1.893 raeburn 5278: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5279: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5280: if ($env{'request.role.domain'}) {
5281: $domain=$env{'request.role.domain'};
1.60 matthew 5282: }
5283: }
1.63 www 5284: return $domain;
5285: }
5286: ###############################################
1.517 raeburn 5287:
1.518 albertel 5288: sub devalidate_domconfig_cache {
5289: my ($udom)=@_;
5290: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5291: }
5292:
5293: # ---------------------- Get domain configuration for a domain
5294: sub get_domainconf {
5295: my ($udom) = @_;
5296: my $cachetime=1800;
5297: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5298: if (defined($cached)) { return %{$result}; }
5299:
5300: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5301: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5302: my (%designhash,%legacy);
1.518 albertel 5303: if (keys(%domconfig) > 0) {
5304: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5305: if (keys(%{$domconfig{'login'}})) {
5306: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5307: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5308: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5309: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5310: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5311: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5312: if ($key eq 'loginvia') {
5313: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5314: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5315: $designhash{$udom.'.login.loginvia'} = $server;
5316: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5317: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5318: } else {
5319: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5320: }
1.948 raeburn 5321: }
1.1075.2.87 raeburn 5322: } elsif ($key eq 'headtag') {
5323: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5324: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5325: }
1.946 raeburn 5326: }
1.1075.2.87 raeburn 5327: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5328: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5329: }
1.946 raeburn 5330: }
5331: }
5332: }
1.1075.2.158 raeburn 5333: } elsif ($key eq 'saml') {
5334: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5335: foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
5336: if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
5337: $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
5338: foreach my $item ('text','img','alt','url','title','notsso') {
5339: $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
5340: }
5341: }
5342: }
5343: }
1.946 raeburn 5344: } else {
5345: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5346: $designhash{$udom.'.login.'.$key.'_'.$img} =
5347: $domconfig{'login'}{$key}{$img};
5348: }
1.699 raeburn 5349: }
5350: } else {
5351: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5352: }
1.632 raeburn 5353: }
5354: } else {
5355: $legacy{'login'} = 1;
1.518 albertel 5356: }
1.632 raeburn 5357: } else {
5358: $legacy{'login'} = 1;
1.518 albertel 5359: }
5360: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5361: if (keys(%{$domconfig{'rolecolors'}})) {
5362: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5363: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5364: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5365: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5366: }
1.518 albertel 5367: }
5368: }
1.632 raeburn 5369: } else {
5370: $legacy{'rolecolors'} = 1;
1.518 albertel 5371: }
1.632 raeburn 5372: } else {
5373: $legacy{'rolecolors'} = 1;
1.518 albertel 5374: }
1.948 raeburn 5375: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5376: if ($domconfig{'autoenroll'}{'co-owners'}) {
5377: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5378: }
5379: }
1.632 raeburn 5380: if (keys(%legacy) > 0) {
5381: my %legacyhash = &get_legacy_domconf($udom);
5382: foreach my $item (keys(%legacyhash)) {
5383: if ($item =~ /^\Q$udom\E\.login/) {
5384: if ($legacy{'login'}) {
5385: $designhash{$item} = $legacyhash{$item};
5386: }
5387: } else {
5388: if ($legacy{'rolecolors'}) {
5389: $designhash{$item} = $legacyhash{$item};
5390: }
1.518 albertel 5391: }
5392: }
5393: }
1.632 raeburn 5394: } else {
5395: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5396: }
5397: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5398: $cachetime);
5399: return %designhash;
5400: }
5401:
1.632 raeburn 5402: sub get_legacy_domconf {
5403: my ($udom) = @_;
5404: my %legacyhash;
5405: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5406: my $designfile = $designdir.'/'.$udom.'.tab';
5407: if (-e $designfile) {
1.1075.2.128 raeburn 5408: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5409: while (my $line = <$fh>) {
5410: next if ($line =~ /^\#/);
5411: chomp($line);
5412: my ($key,$val)=(split(/\=/,$line));
5413: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5414: }
5415: close($fh);
5416: }
5417: }
1.1026 raeburn 5418: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5419: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5420: }
5421: return %legacyhash;
5422: }
5423:
1.63 www 5424: =pod
5425:
1.112 bowersj2 5426: =item * &domainlogo()
1.63 www 5427:
5428: Inputs: $domain (usually will be undef)
5429:
5430: Returns: A link to a domain logo, if the domain logo exists.
5431: If the domain logo does not exist, a description of the domain.
5432:
5433: =cut
1.112 bowersj2 5434:
1.63 www 5435: ###############################################
5436: sub domainlogo {
1.517 raeburn 5437: my $domain = &determinedomain(shift);
1.518 albertel 5438: my %designhash = &get_domainconf($domain);
1.517 raeburn 5439: # See if there is a logo
5440: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5441: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5442: if ($imgsrc =~ m{^/(adm|res)/}) {
5443: if ($imgsrc =~ m{^/res/}) {
5444: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5445: &Apache::lonnet::repcopy($local_name);
5446: }
5447: $imgsrc = &lonhttpdurl($imgsrc);
1.1075.2.162 raeburn 5448: }
5449: my $alttext = $domain;
5450: if ($designhash{$domain.'.login.alttext_domlogo'} ne '') {
5451: $alttext = $designhash{$domain.'.login.alttext_domlogo'};
5452: }
5453: return '<img src="'.$imgsrc.'" alt="'.$alttext.'" id="lclogindomlogo" />';
1.514 albertel 5454: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5455: return &Apache::lonnet::domain($domain,'description');
1.59 www 5456: } else {
1.60 matthew 5457: return '';
1.59 www 5458: }
5459: }
1.63 www 5460: ##############################################
5461:
5462: =pod
5463:
1.112 bowersj2 5464: =item * &designparm()
1.63 www 5465:
5466: Inputs: $which parameter; $domain (usually will be undef)
5467:
5468: Returns: value of designparamter $which
5469:
5470: =cut
1.112 bowersj2 5471:
1.397 albertel 5472:
1.400 albertel 5473: ##############################################
1.397 albertel 5474: sub designparm {
5475: my ($which,$domain)=@_;
5476: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5477: return $env{'environment.color.'.$which};
1.96 www 5478: }
1.63 www 5479: $domain=&determinedomain($domain);
1.1016 raeburn 5480: my %domdesign;
5481: unless ($domain eq 'public') {
5482: %domdesign = &get_domainconf($domain);
5483: }
1.520 raeburn 5484: my $output;
1.517 raeburn 5485: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5486: $output = $domdesign{$domain.'.'.$which};
1.63 www 5487: } else {
1.520 raeburn 5488: $output = $defaultdesign{$which};
5489: }
5490: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5491: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5492: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5493: if ($output =~ m{^/res/}) {
5494: my $local_name = &Apache::lonnet::filelocation('',$output);
5495: &Apache::lonnet::repcopy($local_name);
5496: }
1.520 raeburn 5497: $output = &lonhttpdurl($output);
5498: }
1.63 www 5499: }
1.520 raeburn 5500: return $output;
1.63 www 5501: }
1.59 www 5502:
1.822 bisitz 5503: ##############################################
5504: =pod
5505:
1.832 bisitz 5506: =item * &authorspace()
5507:
1.1028 raeburn 5508: Inputs: $url (usually will be undef).
1.832 bisitz 5509:
1.1075.2.40 raeburn 5510: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5511: directory being viewed (or for which action is being taken).
5512: If $url is provided, and begins /priv/<domain>/<uname>
5513: the path will be that portion of the $context argument.
5514: Otherwise the path will be for the author space of the current
5515: user when the current role is author, or for that of the
5516: co-author/assistant co-author space when the current role
5517: is co-author or assistant co-author.
1.832 bisitz 5518:
5519: =cut
5520:
5521: sub authorspace {
1.1028 raeburn 5522: my ($url) = @_;
5523: if ($url ne '') {
5524: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5525: return $1;
5526: }
5527: }
1.832 bisitz 5528: my $caname = '';
1.1024 www 5529: my $cadom = '';
1.1028 raeburn 5530: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5531: ($cadom,$caname) =
1.832 bisitz 5532: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5533: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5534: $caname = $env{'user.name'};
1.1024 www 5535: $cadom = $env{'user.domain'};
1.832 bisitz 5536: }
1.1028 raeburn 5537: if (($caname ne '') && ($cadom ne '')) {
5538: return "/priv/$cadom/$caname/";
5539: }
5540: return;
1.832 bisitz 5541: }
5542:
5543: ##############################################
5544: =pod
5545:
1.822 bisitz 5546: =item * &head_subbox()
5547:
5548: Inputs: $content (contains HTML code with page functions, etc.)
5549:
5550: Returns: HTML div with $content
5551: To be included in page header
5552:
5553: =cut
5554:
5555: sub head_subbox {
5556: my ($content)=@_;
5557: my $output =
1.993 raeburn 5558: '<div class="LC_head_subbox">'
1.822 bisitz 5559: .$content
5560: .'</div>'
5561: }
5562:
5563: ##############################################
5564: =pod
5565:
5566: =item * &CSTR_pageheader()
5567:
1.1026 raeburn 5568: Input: (optional) filename from which breadcrumb trail is built.
5569: In most cases no input as needed, as $env{'request.filename'}
5570: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5571:
5572: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5573: To be included on Authoring Space pages
1.822 bisitz 5574:
5575: =cut
5576:
5577: sub CSTR_pageheader {
1.1026 raeburn 5578: my ($trailfile) = @_;
5579: if ($trailfile eq '') {
5580: $trailfile = $env{'request.filename'};
5581: }
5582:
5583: # this is for resources; directories have customtitle, and crumbs
5584: # and select recent are created in lonpubdir.pm
5585:
5586: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5587: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5588: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5589: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5590: $formaction =~ s{/+}{/}g;
1.822 bisitz 5591:
5592: my $parentpath = '';
5593: my $lastitem = '';
5594: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5595: $parentpath = $1;
5596: $lastitem = $2;
5597: } else {
5598: $lastitem = $thisdisfn;
5599: }
1.921 bisitz 5600:
5601: my $output =
1.822 bisitz 5602: '<div>'
5603: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5604: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5605: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5606: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5607: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5608:
5609: if ($lastitem) {
5610: $output .=
5611: '<span class="LC_filename">'
5612: .$lastitem
5613: .'</span>';
5614: }
5615: $output .=
5616: '<br />'
1.822 bisitz 5617: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5618: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5619: .'</form>'
5620: .&Apache::lonmenu::constspaceform()
5621: .'</div>';
1.921 bisitz 5622:
5623: return $output;
1.822 bisitz 5624: }
5625:
1.60 matthew 5626: ###############################################
5627: ###############################################
5628:
5629: =pod
5630:
1.112 bowersj2 5631: =back
5632:
1.549 albertel 5633: =head1 HTML Helpers
1.112 bowersj2 5634:
5635: =over 4
5636:
5637: =item * &bodytag()
1.60 matthew 5638:
5639: Returns a uniform header for LON-CAPA web pages.
5640:
5641: Inputs:
5642:
1.112 bowersj2 5643: =over 4
5644:
5645: =item * $title, A title to be displayed on the page.
5646:
5647: =item * $function, the current role (can be undef).
5648:
5649: =item * $addentries, extra parameters for the <body> tag.
5650:
5651: =item * $bodyonly, if defined, only return the <body> tag.
5652:
5653: =item * $domain, if defined, force a given domain.
5654:
5655: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5656: text interface only)
1.60 matthew 5657:
1.814 bisitz 5658: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5659: navigational links
1.317 albertel 5660:
1.338 albertel 5661: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5662:
1.1075.2.12 raeburn 5663: =item * $no_inline_link, if true and in remote mode, don't show the
5664: 'Switch To Inline Menu' link
5665:
1.460 albertel 5666: =item * $args, optional argument valid values are
5667: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 5668: use_absolute -> for external resource or syllabus, this will
5669: contain https://<hostname> if server uses
5670: https (as per hosts.tab), but request is for http
5671: hostname -> hostname, from $r->hostname().
1.460 albertel 5672:
1.1075.2.15 raeburn 5673: =item * $advtoolsref, optional argument, ref to an array containing
5674: inlineremote items to be added in "Functions" menu below
5675: breadcrumbs.
5676:
1.112 bowersj2 5677: =back
5678:
1.60 matthew 5679: Returns: A uniform header for LON-CAPA web pages.
5680: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5681: If $bodyonly is undef or zero, an html string containing a <body> tag and
5682: other decorations will be returned.
5683:
5684: =cut
5685:
1.54 www 5686: sub bodytag {
1.831 bisitz 5687: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5688: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5689:
1.954 raeburn 5690: my $public;
5691: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5692: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5693: $public = 1;
5694: }
1.460 albertel 5695: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5696: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 5697: my $hostname = $args->{'hostname'};
1.339 albertel 5698:
1.183 matthew 5699: $function = &get_users_function() if (!$function);
1.339 albertel 5700: my $img = &designparm($function.'.img',$domain);
5701: my $font = &designparm($function.'.font',$domain);
5702: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5703:
1.803 bisitz 5704: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5705: 'bgcolor' => $pgbg,
1.339 albertel 5706: 'text' => $font,
5707: 'alink' => &designparm($function.'.alink',$domain),
5708: 'vlink' => &designparm($function.'.vlink',$domain),
5709: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5710: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5711:
1.63 www 5712: # role and realm
1.1075.2.68 raeburn 5713: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5714: if ($realm) {
5715: $realm = '/'.$realm;
5716: }
1.1075.2.159 raeburn 5717: if ($role eq 'ca') {
1.479 albertel 5718: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5719: $realm = &plainname($rname,$rdom);
1.378 raeburn 5720: }
1.55 www 5721: # realm
1.1075.2.158 raeburn 5722: my ($cid,$sec);
1.258 albertel 5723: if ($env{'request.course.id'}) {
1.1075.2.158 raeburn 5724: $cid = $env{'request.course.id'};
5725: if ($env{'request.course.sec'}) {
5726: $sec = $env{'request.course.sec'};
5727: }
5728: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
5729: if (&Apache::lonnet::is_course($1,$2)) {
5730: $cid = $1.'_'.$2;
5731: $sec = $3;
5732: }
5733: }
5734: if ($cid) {
1.378 raeburn 5735: if ($env{'request.role'} !~ /^cr/) {
5736: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5737: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5738: if ($env{'request.role.desc'}) {
5739: $role = $env{'request.role.desc'};
5740: } else {
5741: $role = &mt('Helpdesk[_1]',' '.$2);
5742: }
1.1075.2.115 raeburn 5743: } else {
5744: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5745: }
1.1075.2.158 raeburn 5746: if ($sec) {
5747: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 5748: }
1.1075.2.158 raeburn 5749: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 5750: } else {
5751: $role = &Apache::lonnet::plaintext($role);
1.54 www 5752: }
1.433 albertel 5753:
1.359 albertel 5754: if (!$realm) { $realm=' '; }
1.330 albertel 5755:
1.438 albertel 5756: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5757:
1.101 www 5758: # construct main body tag
1.359 albertel 5759: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5760: &Apache::lontexconvert::init_math_support();
1.252 albertel 5761:
1.1075.2.38 raeburn 5762: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5763:
5764: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5765: return $bodytag;
1.1075.2.38 raeburn 5766: }
1.359 albertel 5767:
1.954 raeburn 5768: if ($public) {
1.433 albertel 5769: undef($role);
5770: }
1.1075.2.158 raeburn 5771:
1.762 bisitz 5772: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5773: #
5774: # Extra info if you are the DC
5775: my $dc_info = '';
1.1075.2.159 raeburn 5776: if (($env{'user.adv'}) && ($env{'request.course.id'}) &&
1.1075.2.158 raeburn 5777: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 5778: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5779: $dc_info =~ s/\s+$//;
1.359 albertel 5780: }
5781:
1.1075.2.108 raeburn 5782: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5783:
1.1075.2.13 raeburn 5784: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5785:
1.1075.2.38 raeburn 5786:
5787:
1.1075.2.21 raeburn 5788: my $funclist;
5789: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5790: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5791: Apache::lonmenu::serverform();
5792: my $forbodytag;
5793: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5794: $forcereg,$args->{'group'},
5795: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5796: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 5797: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5798: $funclist = $forbodytag;
5799: }
5800: } else {
1.903 droeschl 5801:
5802: # if ($env{'request.state'} eq 'construct') {
5803: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5804: # }
5805:
1.1075.2.38 raeburn 5806: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5807: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5808:
1.1075.2.158 raeburn 5809: my ($left,$right) = Apache::lonmenu::primary_menu($args->{'links_disabled'});
1.1075.2.2 raeburn 5810:
1.916 droeschl 5811: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5812: if ($dc_info) {
1.1075.2.158 raeburn 5813: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5814: }
1.1075.2.38 raeburn 5815: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5816: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5817: return $bodytag;
5818: }
1.894 droeschl 5819:
1.927 raeburn 5820: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5821: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5822: }
1.916 droeschl 5823:
1.1075.2.38 raeburn 5824: $bodytag .= $right;
1.852 droeschl 5825:
1.917 raeburn 5826: if ($dc_info) {
5827: $dc_info = &dc_courseid_toggle($dc_info);
5828: }
5829: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5830:
1.1075.2.61 raeburn 5831: #if directed to not display the secondary menu, don't.
5832: if ($args->{'no_secondary_menu'}) {
5833: return $bodytag;
5834: }
1.903 droeschl 5835: #don't show menus for public users
1.954 raeburn 5836: if (!$public){
1.1075.2.158 raeburn 5837: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$args->{'links_disabled'});
1.903 droeschl 5838: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5839: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5840: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5841: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.133 raeburn 5842: $args->{'bread_crumbs'},'','',$hostname);
1.1075.2.116 raeburn 5843: } elsif ($forcereg) {
1.1075.2.22 raeburn 5844: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5845: $args->{'group'},
1.1075.2.161 raeburn 5846: $args->{'hide_buttons'},
5847: $hostname);
1.1075.2.15 raeburn 5848: } else {
1.1075.2.21 raeburn 5849: my $forbodytag;
5850: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5851: $forcereg,$args->{'group'},
5852: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5853: $advtoolsref,'',$hostname,
5854: \$forbodytag);
1.1075.2.21 raeburn 5855: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5856: $bodytag .= $forbodytag;
5857: }
1.920 raeburn 5858: }
1.903 droeschl 5859: }else{
5860: # this is to seperate menu from content when there's no secondary
5861: # menu. Especially needed for public accessible ressources.
5862: $bodytag .= '<hr style="clear:both" />';
5863: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5864: }
1.903 droeschl 5865:
1.235 raeburn 5866: return $bodytag;
1.1075.2.12 raeburn 5867: }
5868:
5869: #
5870: # Top frame rendering, Remote is up
5871: #
5872:
5873: my $imgsrc = $img;
5874: if ($img =~ /^\/adm/) {
5875: $imgsrc = &lonhttpdurl($img);
5876: }
5877: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5878:
1.1075.2.60 raeburn 5879: my $help=($no_inline_link?''
5880: :&Apache::loncommon::top_nav_help('Help'));
5881:
1.1075.2.12 raeburn 5882: # Explicit link to get inline menu
5883: my $menu= ($no_inline_link?''
5884: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5885:
5886: if ($dc_info) {
5887: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5888: }
5889:
1.1075.2.38 raeburn 5890: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5891: unless ($public) {
5892: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5893: undef,'LC_menubuttons_link');
5894: }
5895:
1.1075.2.12 raeburn 5896: unless ($env{'form.inhibitmenu'}) {
5897: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5898: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5899: <li>$help</li>
1.1075.2.12 raeburn 5900: <li>$menu</li>
5901: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5902: }
1.1075.2.13 raeburn 5903: if ($env{'request.state'} eq 'construct') {
5904: if (!$public){
5905: if ($env{'request.state'} eq 'construct') {
5906: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5907: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5908: &Apache::lonhtmlcommon::scripttag('','end').
5909: &Apache::lonmenu::innerregister($forcereg,
5910: $args->{'bread_crumbs'});
5911: }
5912: }
5913: }
1.1075.2.21 raeburn 5914: return $bodytag."\n".$funclist;
1.182 matthew 5915: }
5916:
1.917 raeburn 5917: sub dc_courseid_toggle {
5918: my ($dc_info) = @_;
1.980 raeburn 5919: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5920: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5921: &mt('(More ...)').'</a></span>'.
5922: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5923: }
5924:
1.330 albertel 5925: sub make_attr_string {
5926: my ($register,$attr_ref) = @_;
5927:
5928: if ($attr_ref && !ref($attr_ref)) {
5929: die("addentries Must be a hash ref ".
5930: join(':',caller(1))." ".
5931: join(':',caller(0))." ");
5932: }
5933:
5934: if ($register) {
1.339 albertel 5935: my ($on_load,$on_unload);
5936: foreach my $key (keys(%{$attr_ref})) {
5937: if (lc($key) eq 'onload') {
5938: $on_load.=$attr_ref->{$key}.';';
5939: delete($attr_ref->{$key});
5940:
5941: } elsif (lc($key) eq 'onunload') {
5942: $on_unload.=$attr_ref->{$key}.';';
5943: delete($attr_ref->{$key});
5944: }
5945: }
1.1075.2.12 raeburn 5946: if ($env{'environment.remote'} eq 'on') {
5947: $attr_ref->{'onload'} =
5948: &Apache::lonmenu::loadevents(). $on_load;
5949: $attr_ref->{'onunload'}=
5950: &Apache::lonmenu::unloadevents().$on_unload;
5951: } else {
5952: $attr_ref->{'onload'} = $on_load;
5953: $attr_ref->{'onunload'}= $on_unload;
5954: }
1.330 albertel 5955: }
1.339 albertel 5956:
1.330 albertel 5957: my $attr_string;
1.1075.2.56 raeburn 5958: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5959: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5960: }
5961: return $attr_string;
5962: }
5963:
5964:
1.182 matthew 5965: ###############################################
1.251 albertel 5966: ###############################################
5967:
5968: =pod
5969:
5970: =item * &endbodytag()
5971:
5972: Returns a uniform footer for LON-CAPA web pages.
5973:
1.635 raeburn 5974: Inputs: 1 - optional reference to an args hash
5975: If in the hash, key for noredirectlink has a value which evaluates to true,
5976: a 'Continue' link is not displayed if the page contains an
5977: internal redirect in the <head></head> section,
5978: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5979:
5980: =cut
5981:
5982: sub endbodytag {
1.635 raeburn 5983: my ($args) = @_;
1.1075.2.6 raeburn 5984: my $endbodytag;
5985: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5986: $endbodytag='</body>';
5987: }
1.315 albertel 5988: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5989: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5990: $endbodytag=
5991: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5992: &mt('Continue').'</a>'.
5993: $endbodytag;
5994: }
1.315 albertel 5995: }
1.1075.2.165 raeburn 5996: if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
5997: $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
5998: }
1.251 albertel 5999: return $endbodytag;
6000: }
6001:
1.352 albertel 6002: =pod
6003:
6004: =item * &standard_css()
6005:
6006: Returns a style sheet
6007:
6008: Inputs: (all optional)
6009: domain -> force to color decorate a page for a specific
6010: domain
6011: function -> force usage of a specific rolish color scheme
6012: bgcolor -> override the default page bgcolor
6013:
6014: =cut
6015:
1.343 albertel 6016: sub standard_css {
1.345 albertel 6017: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6018: $function = &get_users_function() if (!$function);
6019: my $img = &designparm($function.'.img', $domain);
6020: my $tabbg = &designparm($function.'.tabbg', $domain);
6021: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6022: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6023: #second colour for later usage
1.345 albertel 6024: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6025: my $pgbg_or_bgcolor =
6026: $bgcolor ||
1.352 albertel 6027: &designparm($function.'.pgbg', $domain);
1.382 albertel 6028: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6029: my $alink = &designparm($function.'.alink', $domain);
6030: my $vlink = &designparm($function.'.vlink', $domain);
6031: my $link = &designparm($function.'.link', $domain);
6032:
1.602 albertel 6033: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6034: my $mono = 'monospace';
1.850 bisitz 6035: my $data_table_head = $sidebg;
6036: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6037: my $data_table_dark = '#E0E0E0';
1.470 banghart 6038: my $data_table_darker = '#CCCCCC';
1.349 albertel 6039: my $data_table_highlight = '#FFFF00';
1.352 albertel 6040: my $mail_new = '#FFBB77';
6041: my $mail_new_hover = '#DD9955';
6042: my $mail_read = '#BBBB77';
6043: my $mail_read_hover = '#999944';
6044: my $mail_replied = '#AAAA88';
6045: my $mail_replied_hover = '#888855';
6046: my $mail_other = '#99BBBB';
6047: my $mail_other_hover = '#669999';
1.391 albertel 6048: my $table_header = '#DDDDDD';
1.489 raeburn 6049: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6050: my $lg_border_color = '#C8C8C8';
1.952 onken 6051: my $button_hover = '#BF2317';
1.392 albertel 6052:
1.608 albertel 6053: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6054: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6055: : '0 3px 0 4px';
1.448 albertel 6056:
1.523 albertel 6057:
1.343 albertel 6058: return <<END;
1.947 droeschl 6059:
6060: /* needed for iframe to allow 100% height in FF */
6061: body, html {
6062: margin: 0;
6063: padding: 0 0.5%;
6064: height: 99%; /* to avoid scrollbars */
6065: }
6066:
1.795 www 6067: body {
1.911 bisitz 6068: font-family: $sans;
6069: line-height:130%;
6070: font-size:0.83em;
6071: color:$font;
1.795 www 6072: }
6073:
1.959 onken 6074: a:focus,
6075: a:focus img {
1.795 www 6076: color: red;
6077: }
1.698 harmsja 6078:
1.911 bisitz 6079: form, .inline {
6080: display: inline;
1.795 www 6081: }
1.721 harmsja 6082:
1.795 www 6083: .LC_right {
1.911 bisitz 6084: text-align:right;
1.795 www 6085: }
6086:
6087: .LC_middle {
1.911 bisitz 6088: vertical-align:middle;
1.795 www 6089: }
1.721 harmsja 6090:
1.1075.2.38 raeburn 6091: .LC_floatleft {
6092: float: left;
6093: }
6094:
6095: .LC_floatright {
6096: float: right;
6097: }
6098:
1.911 bisitz 6099: .LC_400Box {
6100: width:400px;
6101: }
1.721 harmsja 6102:
1.947 droeschl 6103: .LC_iframecontainer {
6104: width: 98%;
6105: margin: 0;
6106: position: fixed;
6107: top: 8.5em;
6108: bottom: 0;
6109: }
6110:
6111: .LC_iframecontainer iframe{
6112: border: none;
6113: width: 100%;
6114: height: 100%;
6115: }
6116:
1.778 bisitz 6117: .LC_filename {
6118: font-family: $mono;
6119: white-space:pre;
1.921 bisitz 6120: font-size: 120%;
1.778 bisitz 6121: }
6122:
6123: .LC_fileicon {
6124: border: none;
6125: height: 1.3em;
6126: vertical-align: text-bottom;
6127: margin-right: 0.3em;
6128: text-decoration:none;
6129: }
6130:
1.1008 www 6131: .LC_setting {
6132: text-decoration:underline;
6133: }
6134:
1.350 albertel 6135: .LC_error {
6136: color: red;
6137: }
1.795 www 6138:
1.1075.2.15 raeburn 6139: .LC_warning {
6140: color: darkorange;
6141: }
6142:
1.457 albertel 6143: .LC_diff_removed {
1.733 bisitz 6144: color: red;
1.394 albertel 6145: }
1.532 albertel 6146:
6147: .LC_info,
1.457 albertel 6148: .LC_success,
6149: .LC_diff_added {
1.350 albertel 6150: color: green;
6151: }
1.795 www 6152:
1.802 bisitz 6153: div.LC_confirm_box {
6154: background-color: #FAFAFA;
6155: border: 1px solid $lg_border_color;
6156: margin-right: 0;
6157: padding: 5px;
6158: }
6159:
6160: div.LC_confirm_box .LC_error img,
6161: div.LC_confirm_box .LC_success img {
6162: vertical-align: middle;
6163: }
6164:
1.1075.2.108 raeburn 6165: .LC_maxwidth {
6166: max-width: 100%;
6167: height: auto;
6168: }
6169:
6170: .LC_textsize_mobile {
6171: \@media only screen and (max-device-width: 480px) {
6172: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6173: }
6174: }
6175:
1.440 albertel 6176: .LC_icon {
1.771 droeschl 6177: border: none;
1.790 droeschl 6178: vertical-align: middle;
1.771 droeschl 6179: }
6180:
1.543 albertel 6181: .LC_docs_spacer {
6182: width: 25px;
6183: height: 1px;
1.771 droeschl 6184: border: none;
1.543 albertel 6185: }
1.346 albertel 6186:
1.532 albertel 6187: .LC_internal_info {
1.735 bisitz 6188: color: #999999;
1.532 albertel 6189: }
6190:
1.794 www 6191: .LC_discussion {
1.1050 www 6192: background: $data_table_dark;
1.911 bisitz 6193: border: 1px solid black;
6194: margin: 2px;
1.794 www 6195: }
6196:
6197: .LC_disc_action_left {
1.1050 www 6198: background: $sidebg;
1.911 bisitz 6199: text-align: left;
1.1050 www 6200: padding: 4px;
6201: margin: 2px;
1.794 www 6202: }
6203:
6204: .LC_disc_action_right {
1.1050 www 6205: background: $sidebg;
1.911 bisitz 6206: text-align: right;
1.1050 www 6207: padding: 4px;
6208: margin: 2px;
1.794 www 6209: }
6210:
6211: .LC_disc_new_item {
1.911 bisitz 6212: background: white;
6213: border: 2px solid red;
1.1050 www 6214: margin: 4px;
6215: padding: 4px;
1.794 www 6216: }
6217:
6218: .LC_disc_old_item {
1.911 bisitz 6219: background: white;
1.1050 www 6220: margin: 4px;
6221: padding: 4px;
1.794 www 6222: }
6223:
1.458 albertel 6224: table.LC_pastsubmission {
6225: border: 1px solid black;
6226: margin: 2px;
6227: }
6228:
1.924 bisitz 6229: table#LC_menubuttons {
1.345 albertel 6230: width: 100%;
6231: background: $pgbg;
1.392 albertel 6232: border: 2px;
1.402 albertel 6233: border-collapse: separate;
1.803 bisitz 6234: padding: 0;
1.345 albertel 6235: }
1.392 albertel 6236:
1.801 tempelho 6237: table#LC_title_bar a {
6238: color: $fontmenu;
6239: }
1.836 bisitz 6240:
1.807 droeschl 6241: table#LC_title_bar {
1.819 tempelho 6242: clear: both;
1.836 bisitz 6243: display: none;
1.807 droeschl 6244: }
6245:
1.795 www 6246: table#LC_title_bar,
1.933 droeschl 6247: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6248: table#LC_title_bar.LC_with_remote {
1.359 albertel 6249: width: 100%;
1.392 albertel 6250: border-color: $pgbg;
6251: border-style: solid;
6252: border-width: $border;
1.379 albertel 6253: background: $pgbg;
1.801 tempelho 6254: color: $fontmenu;
1.392 albertel 6255: border-collapse: collapse;
1.803 bisitz 6256: padding: 0;
1.819 tempelho 6257: margin: 0;
1.359 albertel 6258: }
1.795 www 6259:
1.933 droeschl 6260: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6261: margin: 0;
6262: padding: 0;
1.933 droeschl 6263: position: relative;
6264: list-style: none;
1.913 droeschl 6265: }
1.933 droeschl 6266: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6267: display: inline;
6268: }
1.933 droeschl 6269:
6270: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6271: padding: 0;
1.933 droeschl 6272: margin: 0;
6273: float: left;
1.913 droeschl 6274: }
1.933 droeschl 6275: .LC_breadcrumb_tools_tools {
6276: padding: 0;
6277: margin: 0;
1.913 droeschl 6278: float: right;
6279: }
6280:
1.359 albertel 6281: table#LC_title_bar td {
6282: background: $tabbg;
6283: }
1.795 www 6284:
1.911 bisitz 6285: table#LC_menubuttons img {
1.803 bisitz 6286: border: none;
1.346 albertel 6287: }
1.795 www 6288:
1.842 droeschl 6289: .LC_breadcrumbs_component {
1.911 bisitz 6290: float: right;
6291: margin: 0 1em;
1.357 albertel 6292: }
1.842 droeschl 6293: .LC_breadcrumbs_component img {
1.911 bisitz 6294: vertical-align: middle;
1.777 tempelho 6295: }
1.795 www 6296:
1.1075.2.108 raeburn 6297: .LC_breadcrumbs_hoverable {
6298: background: $sidebg;
6299: }
6300:
1.383 albertel 6301: td.LC_table_cell_checkbox {
6302: text-align: center;
6303: }
1.795 www 6304:
6305: .LC_fontsize_small {
1.911 bisitz 6306: font-size: 70%;
1.705 tempelho 6307: }
6308:
1.844 bisitz 6309: #LC_breadcrumbs {
1.911 bisitz 6310: clear:both;
6311: background: $sidebg;
6312: border-bottom: 1px solid $lg_border_color;
6313: line-height: 2.5em;
1.933 droeschl 6314: overflow: hidden;
1.911 bisitz 6315: margin: 0;
6316: padding: 0;
1.995 raeburn 6317: text-align: left;
1.819 tempelho 6318: }
1.862 bisitz 6319:
1.1075.2.16 raeburn 6320: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6321: clear:both;
6322: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6323: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6324: margin: 0 0 10px 0;
1.966 bisitz 6325: padding: 3px;
1.995 raeburn 6326: text-align: left;
1.822 bisitz 6327: }
6328:
1.795 www 6329: .LC_fontsize_medium {
1.911 bisitz 6330: font-size: 85%;
1.705 tempelho 6331: }
6332:
1.795 www 6333: .LC_fontsize_large {
1.911 bisitz 6334: font-size: 120%;
1.705 tempelho 6335: }
6336:
1.346 albertel 6337: .LC_menubuttons_inline_text {
6338: color: $font;
1.698 harmsja 6339: font-size: 90%;
1.701 harmsja 6340: padding-left:3px;
1.346 albertel 6341: }
6342:
1.934 droeschl 6343: .LC_menubuttons_inline_text img{
6344: vertical-align: middle;
6345: }
6346:
1.1051 www 6347: li.LC_menubuttons_inline_text img {
1.951 onken 6348: cursor:pointer;
1.1002 droeschl 6349: text-decoration: none;
1.951 onken 6350: }
6351:
1.526 www 6352: .LC_menubuttons_link {
6353: text-decoration: none;
6354: }
1.795 www 6355:
1.522 albertel 6356: .LC_menubuttons_category {
1.521 www 6357: color: $font;
1.526 www 6358: background: $pgbg;
1.521 www 6359: font-size: larger;
6360: font-weight: bold;
6361: }
6362:
1.346 albertel 6363: td.LC_menubuttons_text {
1.911 bisitz 6364: color: $font;
1.346 albertel 6365: }
1.706 harmsja 6366:
1.346 albertel 6367: .LC_current_location {
6368: background: $tabbg;
6369: }
1.795 www 6370:
1.1075.2.134 raeburn 6371: td.LC_zero_height {
6372: line-height: 0;
6373: cellpadding: 0;
6374: }
6375:
1.938 bisitz 6376: table.LC_data_table {
1.347 albertel 6377: border: 1px solid #000000;
1.402 albertel 6378: border-collapse: separate;
1.426 albertel 6379: border-spacing: 1px;
1.610 albertel 6380: background: $pgbg;
1.347 albertel 6381: }
1.795 www 6382:
1.422 albertel 6383: .LC_data_table_dense {
6384: font-size: small;
6385: }
1.795 www 6386:
1.507 raeburn 6387: table.LC_nested_outer {
6388: border: 1px solid #000000;
1.589 raeburn 6389: border-collapse: collapse;
1.803 bisitz 6390: border-spacing: 0;
1.507 raeburn 6391: width: 100%;
6392: }
1.795 www 6393:
1.879 raeburn 6394: table.LC_innerpickbox,
1.507 raeburn 6395: table.LC_nested {
1.803 bisitz 6396: border: none;
1.589 raeburn 6397: border-collapse: collapse;
1.803 bisitz 6398: border-spacing: 0;
1.507 raeburn 6399: width: 100%;
6400: }
1.795 www 6401:
1.911 bisitz 6402: table.LC_data_table tr th,
6403: table.LC_calendar tr th,
1.879 raeburn 6404: table.LC_prior_tries tr th,
6405: table.LC_innerpickbox tr th {
1.349 albertel 6406: font-weight: bold;
6407: background-color: $data_table_head;
1.801 tempelho 6408: color:$fontmenu;
1.701 harmsja 6409: font-size:90%;
1.347 albertel 6410: }
1.795 www 6411:
1.879 raeburn 6412: table.LC_innerpickbox tr th,
6413: table.LC_innerpickbox tr td {
6414: vertical-align: top;
6415: }
6416:
1.711 raeburn 6417: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6418: background-color: #CCCCCC;
1.711 raeburn 6419: font-weight: bold;
6420: text-align: left;
6421: }
1.795 www 6422:
1.912 bisitz 6423: table.LC_data_table tr.LC_odd_row > td {
6424: background-color: $data_table_light;
6425: padding: 2px;
6426: vertical-align: top;
6427: }
6428:
1.809 bisitz 6429: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6430: background-color: $data_table_light;
1.912 bisitz 6431: vertical-align: top;
6432: }
6433:
6434: table.LC_data_table tr.LC_even_row > td {
6435: background-color: $data_table_dark;
1.425 albertel 6436: padding: 2px;
1.900 bisitz 6437: vertical-align: top;
1.347 albertel 6438: }
1.795 www 6439:
1.809 bisitz 6440: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6441: background-color: $data_table_dark;
1.900 bisitz 6442: vertical-align: top;
1.347 albertel 6443: }
1.795 www 6444:
1.425 albertel 6445: table.LC_data_table tr.LC_data_table_highlight td {
6446: background-color: $data_table_darker;
6447: }
1.795 www 6448:
1.639 raeburn 6449: table.LC_data_table tr td.LC_leftcol_header {
6450: background-color: $data_table_head;
6451: font-weight: bold;
6452: }
1.795 www 6453:
1.451 albertel 6454: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6455: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6456: font-weight: bold;
6457: font-style: italic;
6458: text-align: center;
6459: padding: 8px;
1.347 albertel 6460: }
1.795 www 6461:
1.1075.2.30 raeburn 6462: table.LC_data_table tr.LC_empty_row td,
6463: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6464: background-color: $sidebg;
6465: }
6466:
6467: table.LC_nested tr.LC_empty_row td {
6468: background-color: #FFFFFF;
6469: }
6470:
1.890 droeschl 6471: table.LC_caption {
6472: }
6473:
1.507 raeburn 6474: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6475: padding: 4ex
6476: }
1.795 www 6477:
1.507 raeburn 6478: table.LC_nested_outer tr th {
6479: font-weight: bold;
1.801 tempelho 6480: color:$fontmenu;
1.507 raeburn 6481: background-color: $data_table_head;
1.701 harmsja 6482: font-size: small;
1.507 raeburn 6483: border-bottom: 1px solid #000000;
6484: }
1.795 www 6485:
1.507 raeburn 6486: table.LC_nested_outer tr td.LC_subheader {
6487: background-color: $data_table_head;
6488: font-weight: bold;
6489: font-size: small;
6490: border-bottom: 1px solid #000000;
6491: text-align: right;
1.451 albertel 6492: }
1.795 www 6493:
1.507 raeburn 6494: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6495: background-color: #CCCCCC;
1.451 albertel 6496: font-weight: bold;
6497: font-size: small;
1.507 raeburn 6498: text-align: center;
6499: }
1.795 www 6500:
1.589 raeburn 6501: table.LC_nested tr.LC_info_row td.LC_left_item,
6502: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6503: text-align: left;
1.451 albertel 6504: }
1.795 www 6505:
1.507 raeburn 6506: table.LC_nested td {
1.735 bisitz 6507: background-color: #FFFFFF;
1.451 albertel 6508: font-size: small;
1.507 raeburn 6509: }
1.795 www 6510:
1.507 raeburn 6511: table.LC_nested_outer tr th.LC_right_item,
6512: table.LC_nested tr.LC_info_row td.LC_right_item,
6513: table.LC_nested tr.LC_odd_row td.LC_right_item,
6514: table.LC_nested tr td.LC_right_item {
1.451 albertel 6515: text-align: right;
6516: }
6517:
1.507 raeburn 6518: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6519: background-color: #EEEEEE;
1.451 albertel 6520: }
6521:
1.473 raeburn 6522: table.LC_createuser {
6523: }
6524:
6525: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6526: font-size: small;
1.473 raeburn 6527: }
6528:
6529: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6530: background-color: #CCCCCC;
1.473 raeburn 6531: font-weight: bold;
6532: text-align: center;
6533: }
6534:
1.349 albertel 6535: table.LC_calendar {
6536: border: 1px solid #000000;
6537: border-collapse: collapse;
1.917 raeburn 6538: width: 98%;
1.349 albertel 6539: }
1.795 www 6540:
1.349 albertel 6541: table.LC_calendar_pickdate {
6542: font-size: xx-small;
6543: }
1.795 www 6544:
1.349 albertel 6545: table.LC_calendar tr td {
6546: border: 1px solid #000000;
6547: vertical-align: top;
1.917 raeburn 6548: width: 14%;
1.349 albertel 6549: }
1.795 www 6550:
1.349 albertel 6551: table.LC_calendar tr td.LC_calendar_day_empty {
6552: background-color: $data_table_dark;
6553: }
1.795 www 6554:
1.779 bisitz 6555: table.LC_calendar tr td.LC_calendar_day_current {
6556: background-color: $data_table_highlight;
1.777 tempelho 6557: }
1.795 www 6558:
1.938 bisitz 6559: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6560: background-color: $mail_new;
6561: }
1.795 www 6562:
1.938 bisitz 6563: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6564: background-color: $mail_new_hover;
6565: }
1.795 www 6566:
1.938 bisitz 6567: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6568: background-color: $mail_read;
6569: }
1.795 www 6570:
1.938 bisitz 6571: /*
6572: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6573: background-color: $mail_read_hover;
6574: }
1.938 bisitz 6575: */
1.795 www 6576:
1.938 bisitz 6577: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6578: background-color: $mail_replied;
6579: }
1.795 www 6580:
1.938 bisitz 6581: /*
6582: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6583: background-color: $mail_replied_hover;
6584: }
1.938 bisitz 6585: */
1.795 www 6586:
1.938 bisitz 6587: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6588: background-color: $mail_other;
6589: }
1.795 www 6590:
1.938 bisitz 6591: /*
6592: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6593: background-color: $mail_other_hover;
6594: }
1.938 bisitz 6595: */
1.494 raeburn 6596:
1.777 tempelho 6597: table.LC_data_table tr > td.LC_browser_file,
6598: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6599: background: #AAEE77;
1.389 albertel 6600: }
1.795 www 6601:
1.777 tempelho 6602: table.LC_data_table tr > td.LC_browser_file_locked,
6603: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6604: background: #FFAA99;
1.387 albertel 6605: }
1.795 www 6606:
1.777 tempelho 6607: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6608: background: #888888;
1.779 bisitz 6609: }
1.795 www 6610:
1.777 tempelho 6611: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6612: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6613: background: #F8F866;
1.777 tempelho 6614: }
1.795 www 6615:
1.696 bisitz 6616: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6617: background: #E0E8FF;
1.387 albertel 6618: }
1.696 bisitz 6619:
1.707 bisitz 6620: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6621: /* background: #77FF77; */
1.707 bisitz 6622: }
1.795 www 6623:
1.707 bisitz 6624: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6625: border-right: 8px solid #FFFF77;
1.707 bisitz 6626: }
1.795 www 6627:
1.707 bisitz 6628: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6629: border-right: 8px solid #FFAA77;
1.707 bisitz 6630: }
1.795 www 6631:
1.707 bisitz 6632: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6633: border-right: 8px solid #FF7777;
1.707 bisitz 6634: }
1.795 www 6635:
1.707 bisitz 6636: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6637: border-right: 8px solid #AAFF77;
1.707 bisitz 6638: }
1.795 www 6639:
1.707 bisitz 6640: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6641: border-right: 8px solid #11CC55;
1.707 bisitz 6642: }
6643:
1.388 albertel 6644: span.LC_current_location {
1.701 harmsja 6645: font-size:larger;
1.388 albertel 6646: background: $pgbg;
6647: }
1.387 albertel 6648:
1.1029 www 6649: span.LC_current_nav_location {
6650: font-weight:bold;
6651: background: $sidebg;
6652: }
6653:
1.395 albertel 6654: span.LC_parm_menu_item {
6655: font-size: larger;
6656: }
1.795 www 6657:
1.395 albertel 6658: span.LC_parm_scope_all {
6659: color: red;
6660: }
1.795 www 6661:
1.395 albertel 6662: span.LC_parm_scope_folder {
6663: color: green;
6664: }
1.795 www 6665:
1.395 albertel 6666: span.LC_parm_scope_resource {
6667: color: orange;
6668: }
1.795 www 6669:
1.395 albertel 6670: span.LC_parm_part {
6671: color: blue;
6672: }
1.795 www 6673:
1.911 bisitz 6674: span.LC_parm_folder,
6675: span.LC_parm_symb {
1.395 albertel 6676: font-size: x-small;
6677: font-family: $mono;
6678: color: #AAAAAA;
6679: }
6680:
1.977 bisitz 6681: ul.LC_parm_parmlist li {
6682: display: inline-block;
6683: padding: 0.3em 0.8em;
6684: vertical-align: top;
6685: width: 150px;
6686: border-top:1px solid $lg_border_color;
6687: }
6688:
1.795 www 6689: td.LC_parm_overview_level_menu,
6690: td.LC_parm_overview_map_menu,
6691: td.LC_parm_overview_parm_selectors,
6692: td.LC_parm_overview_restrictions {
1.396 albertel 6693: border: 1px solid black;
6694: border-collapse: collapse;
6695: }
1.795 www 6696:
1.396 albertel 6697: table.LC_parm_overview_restrictions td {
6698: border-width: 1px 4px 1px 4px;
6699: border-style: solid;
6700: border-color: $pgbg;
6701: text-align: center;
6702: }
1.795 www 6703:
1.396 albertel 6704: table.LC_parm_overview_restrictions th {
6705: background: $tabbg;
6706: border-width: 1px 4px 1px 4px;
6707: border-style: solid;
6708: border-color: $pgbg;
6709: }
1.795 www 6710:
1.398 albertel 6711: table#LC_helpmenu {
1.803 bisitz 6712: border: none;
1.398 albertel 6713: height: 55px;
1.803 bisitz 6714: border-spacing: 0;
1.398 albertel 6715: }
6716:
6717: table#LC_helpmenu fieldset legend {
6718: font-size: larger;
6719: }
1.795 www 6720:
1.397 albertel 6721: table#LC_helpmenu_links {
6722: width: 100%;
6723: border: 1px solid black;
6724: background: $pgbg;
1.803 bisitz 6725: padding: 0;
1.397 albertel 6726: border-spacing: 1px;
6727: }
1.795 www 6728:
1.397 albertel 6729: table#LC_helpmenu_links tr td {
6730: padding: 1px;
6731: background: $tabbg;
1.399 albertel 6732: text-align: center;
6733: font-weight: bold;
1.397 albertel 6734: }
1.396 albertel 6735:
1.795 www 6736: table#LC_helpmenu_links a:link,
6737: table#LC_helpmenu_links a:visited,
1.397 albertel 6738: table#LC_helpmenu_links a:active {
6739: text-decoration: none;
6740: color: $font;
6741: }
1.795 www 6742:
1.397 albertel 6743: table#LC_helpmenu_links a:hover {
6744: text-decoration: underline;
6745: color: $vlink;
6746: }
1.396 albertel 6747:
1.417 albertel 6748: .LC_chrt_popup_exists {
6749: border: 1px solid #339933;
6750: margin: -1px;
6751: }
1.795 www 6752:
1.417 albertel 6753: .LC_chrt_popup_up {
6754: border: 1px solid yellow;
6755: margin: -1px;
6756: }
1.795 www 6757:
1.417 albertel 6758: .LC_chrt_popup {
6759: border: 1px solid #8888FF;
6760: background: #CCCCFF;
6761: }
1.795 www 6762:
1.421 albertel 6763: table.LC_pick_box {
6764: border-collapse: separate;
6765: background: white;
6766: border: 1px solid black;
6767: border-spacing: 1px;
6768: }
1.795 www 6769:
1.421 albertel 6770: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6771: background: $sidebg;
1.421 albertel 6772: font-weight: bold;
1.900 bisitz 6773: text-align: left;
1.740 bisitz 6774: vertical-align: top;
1.421 albertel 6775: width: 184px;
6776: padding: 8px;
6777: }
1.795 www 6778:
1.579 raeburn 6779: table.LC_pick_box td.LC_pick_box_value {
6780: text-align: left;
6781: padding: 8px;
6782: }
1.795 www 6783:
1.579 raeburn 6784: table.LC_pick_box td.LC_pick_box_select {
6785: text-align: left;
6786: padding: 8px;
6787: }
1.795 www 6788:
1.424 albertel 6789: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6790: padding: 0;
1.421 albertel 6791: height: 1px;
6792: background: black;
6793: }
1.795 www 6794:
1.421 albertel 6795: table.LC_pick_box td.LC_pick_box_submit {
6796: text-align: right;
6797: }
1.795 www 6798:
1.579 raeburn 6799: table.LC_pick_box td.LC_evenrow_value {
6800: text-align: left;
6801: padding: 8px;
6802: background-color: $data_table_light;
6803: }
1.795 www 6804:
1.579 raeburn 6805: table.LC_pick_box td.LC_oddrow_value {
6806: text-align: left;
6807: padding: 8px;
6808: background-color: $data_table_light;
6809: }
1.795 www 6810:
1.579 raeburn 6811: span.LC_helpform_receipt_cat {
6812: font-weight: bold;
6813: }
1.795 www 6814:
1.424 albertel 6815: table.LC_group_priv_box {
6816: background: white;
6817: border: 1px solid black;
6818: border-spacing: 1px;
6819: }
1.795 www 6820:
1.424 albertel 6821: table.LC_group_priv_box td.LC_pick_box_title {
6822: background: $tabbg;
6823: font-weight: bold;
6824: text-align: right;
6825: width: 184px;
6826: }
1.795 www 6827:
1.424 albertel 6828: table.LC_group_priv_box td.LC_groups_fixed {
6829: background: $data_table_light;
6830: text-align: center;
6831: }
1.795 www 6832:
1.424 albertel 6833: table.LC_group_priv_box td.LC_groups_optional {
6834: background: $data_table_dark;
6835: text-align: center;
6836: }
1.795 www 6837:
1.424 albertel 6838: table.LC_group_priv_box td.LC_groups_functionality {
6839: background: $data_table_darker;
6840: text-align: center;
6841: font-weight: bold;
6842: }
1.795 www 6843:
1.424 albertel 6844: table.LC_group_priv td {
6845: text-align: left;
1.803 bisitz 6846: padding: 0;
1.424 albertel 6847: }
6848:
6849: .LC_navbuttons {
6850: margin: 2ex 0ex 2ex 0ex;
6851: }
1.795 www 6852:
1.423 albertel 6853: .LC_topic_bar {
6854: font-weight: bold;
6855: background: $tabbg;
1.918 wenzelju 6856: margin: 1em 0em 1em 2em;
1.805 bisitz 6857: padding: 3px;
1.918 wenzelju 6858: font-size: 1.2em;
1.423 albertel 6859: }
1.795 www 6860:
1.423 albertel 6861: .LC_topic_bar span {
1.918 wenzelju 6862: left: 0.5em;
6863: position: absolute;
1.423 albertel 6864: vertical-align: middle;
1.918 wenzelju 6865: font-size: 1.2em;
1.423 albertel 6866: }
1.795 www 6867:
1.423 albertel 6868: table.LC_course_group_status {
6869: margin: 20px;
6870: }
1.795 www 6871:
1.423 albertel 6872: table.LC_status_selector td {
6873: vertical-align: top;
6874: text-align: center;
1.424 albertel 6875: padding: 4px;
6876: }
1.795 www 6877:
1.599 albertel 6878: div.LC_feedback_link {
1.616 albertel 6879: clear: both;
1.829 kalberla 6880: background: $sidebg;
1.779 bisitz 6881: width: 100%;
1.829 kalberla 6882: padding-bottom: 10px;
6883: border: 1px $tabbg solid;
1.833 kalberla 6884: height: 22px;
6885: line-height: 22px;
6886: padding-top: 5px;
6887: }
6888:
6889: div.LC_feedback_link img {
6890: height: 22px;
1.867 kalberla 6891: vertical-align:middle;
1.829 kalberla 6892: }
6893:
1.911 bisitz 6894: div.LC_feedback_link a {
1.829 kalberla 6895: text-decoration: none;
1.489 raeburn 6896: }
1.795 www 6897:
1.867 kalberla 6898: div.LC_comblock {
1.911 bisitz 6899: display:inline;
1.867 kalberla 6900: color:$font;
6901: font-size:90%;
6902: }
6903:
6904: div.LC_feedback_link div.LC_comblock {
6905: padding-left:5px;
6906: }
6907:
6908: div.LC_feedback_link div.LC_comblock a {
6909: color:$font;
6910: }
6911:
1.489 raeburn 6912: span.LC_feedback_link {
1.858 bisitz 6913: /* background: $feedback_link_bg; */
1.599 albertel 6914: font-size: larger;
6915: }
1.795 www 6916:
1.599 albertel 6917: span.LC_message_link {
1.858 bisitz 6918: /* background: $feedback_link_bg; */
1.599 albertel 6919: font-size: larger;
6920: position: absolute;
6921: right: 1em;
1.489 raeburn 6922: }
1.421 albertel 6923:
1.515 albertel 6924: table.LC_prior_tries {
1.524 albertel 6925: border: 1px solid #000000;
6926: border-collapse: separate;
6927: border-spacing: 1px;
1.515 albertel 6928: }
1.523 albertel 6929:
1.515 albertel 6930: table.LC_prior_tries td {
1.524 albertel 6931: padding: 2px;
1.515 albertel 6932: }
1.523 albertel 6933:
6934: .LC_answer_correct {
1.795 www 6935: background: lightgreen;
6936: color: darkgreen;
6937: padding: 6px;
1.523 albertel 6938: }
1.795 www 6939:
1.523 albertel 6940: .LC_answer_charged_try {
1.797 www 6941: background: #FFAAAA;
1.795 www 6942: color: darkred;
6943: padding: 6px;
1.523 albertel 6944: }
1.795 www 6945:
1.779 bisitz 6946: .LC_answer_not_charged_try,
1.523 albertel 6947: .LC_answer_no_grade,
6948: .LC_answer_late {
1.795 www 6949: background: lightyellow;
1.523 albertel 6950: color: black;
1.795 www 6951: padding: 6px;
1.523 albertel 6952: }
1.795 www 6953:
1.523 albertel 6954: .LC_answer_previous {
1.795 www 6955: background: lightblue;
6956: color: darkblue;
6957: padding: 6px;
1.523 albertel 6958: }
1.795 www 6959:
1.779 bisitz 6960: .LC_answer_no_message {
1.777 tempelho 6961: background: #FFFFFF;
6962: color: black;
1.795 www 6963: padding: 6px;
1.779 bisitz 6964: }
1.795 www 6965:
1.1075.2.140 raeburn 6966: .LC_answer_unknown,
6967: .LC_answer_warning {
1.779 bisitz 6968: background: orange;
6969: color: black;
1.795 www 6970: padding: 6px;
1.777 tempelho 6971: }
1.795 www 6972:
1.529 albertel 6973: span.LC_prior_numerical,
6974: span.LC_prior_string,
6975: span.LC_prior_custom,
6976: span.LC_prior_reaction,
6977: span.LC_prior_math {
1.925 bisitz 6978: font-family: $mono;
1.523 albertel 6979: white-space: pre;
6980: }
6981:
1.525 albertel 6982: span.LC_prior_string {
1.925 bisitz 6983: font-family: $mono;
1.525 albertel 6984: white-space: pre;
6985: }
6986:
1.523 albertel 6987: table.LC_prior_option {
6988: width: 100%;
6989: border-collapse: collapse;
6990: }
1.795 www 6991:
1.911 bisitz 6992: table.LC_prior_rank,
1.795 www 6993: table.LC_prior_match {
1.528 albertel 6994: border-collapse: collapse;
6995: }
1.795 www 6996:
1.528 albertel 6997: table.LC_prior_option tr td,
6998: table.LC_prior_rank tr td,
6999: table.LC_prior_match tr td {
1.524 albertel 7000: border: 1px solid #000000;
1.515 albertel 7001: }
7002:
1.855 bisitz 7003: .LC_nobreak {
1.544 albertel 7004: white-space: nowrap;
1.519 raeburn 7005: }
7006:
1.576 raeburn 7007: span.LC_cusr_emph {
7008: font-style: italic;
7009: }
7010:
1.633 raeburn 7011: span.LC_cusr_subheading {
7012: font-weight: normal;
7013: font-size: 85%;
7014: }
7015:
1.861 bisitz 7016: div.LC_docs_entry_move {
1.859 bisitz 7017: border: 1px solid #BBBBBB;
1.545 albertel 7018: background: #DDDDDD;
1.861 bisitz 7019: width: 22px;
1.859 bisitz 7020: padding: 1px;
7021: margin: 0;
1.545 albertel 7022: }
7023:
1.861 bisitz 7024: table.LC_data_table tr > td.LC_docs_entry_commands,
7025: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7026: font-size: x-small;
7027: }
1.795 www 7028:
1.861 bisitz 7029: .LC_docs_entry_parameter {
7030: white-space: nowrap;
7031: }
7032:
1.544 albertel 7033: .LC_docs_copy {
1.545 albertel 7034: color: #000099;
1.544 albertel 7035: }
1.795 www 7036:
1.544 albertel 7037: .LC_docs_cut {
1.545 albertel 7038: color: #550044;
1.544 albertel 7039: }
1.795 www 7040:
1.544 albertel 7041: .LC_docs_rename {
1.545 albertel 7042: color: #009900;
1.544 albertel 7043: }
1.795 www 7044:
1.544 albertel 7045: .LC_docs_remove {
1.545 albertel 7046: color: #990000;
7047: }
7048:
1.1075.2.134 raeburn 7049: .LC_domprefs_email,
1.547 albertel 7050: .LC_docs_reinit_warn,
7051: .LC_docs_ext_edit {
7052: font-size: x-small;
7053: }
7054:
1.545 albertel 7055: table.LC_docs_adddocs td,
7056: table.LC_docs_adddocs th {
7057: border: 1px solid #BBBBBB;
7058: padding: 4px;
7059: background: #DDDDDD;
1.543 albertel 7060: }
7061:
1.584 albertel 7062: table.LC_sty_begin {
7063: background: #BBFFBB;
7064: }
1.795 www 7065:
1.584 albertel 7066: table.LC_sty_end {
7067: background: #FFBBBB;
7068: }
7069:
1.589 raeburn 7070: table.LC_double_column {
1.803 bisitz 7071: border-width: 0;
1.589 raeburn 7072: border-collapse: collapse;
7073: width: 100%;
7074: padding: 2px;
7075: }
7076:
7077: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7078: top: 2px;
1.589 raeburn 7079: left: 2px;
7080: width: 47%;
7081: vertical-align: top;
7082: }
7083:
7084: table.LC_double_column tr td.LC_right_col {
7085: top: 2px;
1.779 bisitz 7086: right: 2px;
1.589 raeburn 7087: width: 47%;
7088: vertical-align: top;
7089: }
7090:
1.591 raeburn 7091: div.LC_left_float {
7092: float: left;
7093: padding-right: 5%;
1.597 albertel 7094: padding-bottom: 4px;
1.591 raeburn 7095: }
7096:
7097: div.LC_clear_float_header {
1.597 albertel 7098: padding-bottom: 2px;
1.591 raeburn 7099: }
7100:
7101: div.LC_clear_float_footer {
1.597 albertel 7102: padding-top: 10px;
1.591 raeburn 7103: clear: both;
7104: }
7105:
1.597 albertel 7106: div.LC_grade_show_user {
1.941 bisitz 7107: /* border-left: 5px solid $sidebg; */
7108: border-top: 5px solid #000000;
7109: margin: 50px 0 0 0;
1.936 bisitz 7110: padding: 15px 0 5px 10px;
1.597 albertel 7111: }
1.795 www 7112:
1.936 bisitz 7113: div.LC_grade_show_user_odd_row {
1.941 bisitz 7114: /* border-left: 5px solid #000000; */
7115: }
7116:
7117: div.LC_grade_show_user div.LC_Box {
7118: margin-right: 50px;
1.597 albertel 7119: }
7120:
7121: div.LC_grade_submissions,
7122: div.LC_grade_message_center,
1.936 bisitz 7123: div.LC_grade_info_links {
1.597 albertel 7124: margin: 5px;
7125: width: 99%;
7126: background: #FFFFFF;
7127: }
1.795 www 7128:
1.597 albertel 7129: div.LC_grade_submissions_header,
1.936 bisitz 7130: div.LC_grade_message_center_header {
1.705 tempelho 7131: font-weight: bold;
7132: font-size: large;
1.597 albertel 7133: }
1.795 www 7134:
1.597 albertel 7135: div.LC_grade_submissions_body,
1.936 bisitz 7136: div.LC_grade_message_center_body {
1.597 albertel 7137: border: 1px solid black;
7138: width: 99%;
7139: background: #FFFFFF;
7140: }
1.795 www 7141:
1.613 albertel 7142: table.LC_scantron_action {
7143: width: 100%;
7144: }
1.795 www 7145:
1.613 albertel 7146: table.LC_scantron_action tr th {
1.698 harmsja 7147: font-weight:bold;
7148: font-style:normal;
1.613 albertel 7149: }
1.795 www 7150:
1.779 bisitz 7151: .LC_edit_problem_header,
1.614 albertel 7152: div.LC_edit_problem_footer {
1.705 tempelho 7153: font-weight: normal;
7154: font-size: medium;
1.602 albertel 7155: margin: 2px;
1.1060 bisitz 7156: background-color: $sidebg;
1.600 albertel 7157: }
1.795 www 7158:
1.600 albertel 7159: div.LC_edit_problem_header,
1.602 albertel 7160: div.LC_edit_problem_header div,
1.614 albertel 7161: div.LC_edit_problem_footer,
7162: div.LC_edit_problem_footer div,
1.602 albertel 7163: div.LC_edit_problem_editxml_header,
7164: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7165: z-index: 100;
1.600 albertel 7166: }
1.795 www 7167:
1.600 albertel 7168: div.LC_edit_problem_header_title {
1.705 tempelho 7169: font-weight: bold;
7170: font-size: larger;
1.602 albertel 7171: background: $tabbg;
7172: padding: 3px;
1.1060 bisitz 7173: margin: 0 0 5px 0;
1.602 albertel 7174: }
1.795 www 7175:
1.602 albertel 7176: table.LC_edit_problem_header_title {
7177: width: 100%;
1.600 albertel 7178: background: $tabbg;
1.602 albertel 7179: }
7180:
1.1075.2.112 raeburn 7181: div.LC_edit_actionbar {
7182: background-color: $sidebg;
7183: margin: 0;
7184: padding: 0;
7185: line-height: 200%;
1.602 albertel 7186: }
1.795 www 7187:
1.1075.2.112 raeburn 7188: div.LC_edit_actionbar div{
7189: padding: 0;
7190: margin: 0;
7191: display: inline-block;
1.600 albertel 7192: }
1.795 www 7193:
1.1075.2.34 raeburn 7194: .LC_edit_opt {
7195: padding-left: 1em;
7196: white-space: nowrap;
7197: }
7198:
1.1075.2.57 raeburn 7199: .LC_edit_problem_latexhelper{
7200: text-align: right;
7201: }
7202:
7203: #LC_edit_problem_colorful div{
7204: margin-left: 40px;
7205: }
7206:
1.1075.2.112 raeburn 7207: #LC_edit_problem_codemirror div{
7208: margin-left: 0px;
7209: }
7210:
1.911 bisitz 7211: img.stift {
1.803 bisitz 7212: border-width: 0;
7213: vertical-align: middle;
1.677 riegler 7214: }
1.680 riegler 7215:
1.923 bisitz 7216: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7217: vertical-align: top;
1.777 tempelho 7218: }
1.795 www 7219:
1.716 raeburn 7220: div.LC_createcourse {
1.911 bisitz 7221: margin: 10px 10px 10px 10px;
1.716 raeburn 7222: }
7223:
1.917 raeburn 7224: .LC_dccid {
1.1075.2.38 raeburn 7225: float: right;
1.917 raeburn 7226: margin: 0.2em 0 0 0;
7227: padding: 0;
7228: font-size: 90%;
7229: display:none;
7230: }
7231:
1.897 wenzelju 7232: ol.LC_primary_menu a:hover,
1.721 harmsja 7233: ol#LC_MenuBreadcrumbs a:hover,
7234: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7235: ul#LC_secondary_menu a:hover,
1.721 harmsja 7236: .LC_FormSectionClearButton input:hover
1.795 www 7237: ul.LC_TabContent li:hover a {
1.952 onken 7238: color:$button_hover;
1.911 bisitz 7239: text-decoration:none;
1.693 droeschl 7240: }
7241:
1.779 bisitz 7242: h1 {
1.911 bisitz 7243: padding: 0;
7244: line-height:130%;
1.693 droeschl 7245: }
1.698 harmsja 7246:
1.911 bisitz 7247: h2,
7248: h3,
7249: h4,
7250: h5,
7251: h6 {
7252: margin: 5px 0 5px 0;
7253: padding: 0;
7254: line-height:130%;
1.693 droeschl 7255: }
1.795 www 7256:
7257: .LC_hcell {
1.911 bisitz 7258: padding:3px 15px 3px 15px;
7259: margin: 0;
7260: background-color:$tabbg;
7261: color:$fontmenu;
7262: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7263: }
1.795 www 7264:
1.840 bisitz 7265: .LC_Box > .LC_hcell {
1.911 bisitz 7266: margin: 0 -10px 10px -10px;
1.835 bisitz 7267: }
7268:
1.721 harmsja 7269: .LC_noBorder {
1.911 bisitz 7270: border: 0;
1.698 harmsja 7271: }
1.693 droeschl 7272:
1.721 harmsja 7273: .LC_FormSectionClearButton input {
1.911 bisitz 7274: background-color:transparent;
7275: border: none;
7276: cursor:pointer;
7277: text-decoration:underline;
1.693 droeschl 7278: }
1.763 bisitz 7279:
7280: .LC_help_open_topic {
1.911 bisitz 7281: color: #FFFFFF;
7282: background-color: #EEEEFF;
7283: margin: 1px;
7284: padding: 4px;
7285: border: 1px solid #000033;
7286: white-space: nowrap;
7287: /* vertical-align: middle; */
1.759 neumanie 7288: }
1.693 droeschl 7289:
1.911 bisitz 7290: dl,
7291: ul,
7292: div,
7293: fieldset {
7294: margin: 10px 10px 10px 0;
7295: /* overflow: hidden; */
1.693 droeschl 7296: }
1.795 www 7297:
1.1075.2.90 raeburn 7298: article.geogebraweb div {
7299: margin: 0;
7300: }
7301:
1.838 bisitz 7302: fieldset > legend {
1.911 bisitz 7303: font-weight: bold;
7304: padding: 0 5px 0 5px;
1.838 bisitz 7305: }
7306:
1.813 bisitz 7307: #LC_nav_bar {
1.911 bisitz 7308: float: left;
1.995 raeburn 7309: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7310: margin: 0 0 2px 0;
1.807 droeschl 7311: }
7312:
1.916 droeschl 7313: #LC_realm {
7314: margin: 0.2em 0 0 0;
7315: padding: 0;
7316: font-weight: bold;
7317: text-align: center;
1.995 raeburn 7318: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7319: }
7320:
1.911 bisitz 7321: #LC_nav_bar em {
7322: font-weight: bold;
7323: font-style: normal;
1.807 droeschl 7324: }
7325:
1.897 wenzelju 7326: ol.LC_primary_menu {
1.934 droeschl 7327: margin: 0;
1.1075.2.2 raeburn 7328: padding: 0;
1.807 droeschl 7329: }
7330:
1.852 droeschl 7331: ol#LC_PathBreadcrumbs {
1.911 bisitz 7332: margin: 0;
1.693 droeschl 7333: }
7334:
1.897 wenzelju 7335: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7336: color: RGB(80, 80, 80);
7337: vertical-align: middle;
7338: text-align: left;
7339: list-style: none;
1.1075.2.112 raeburn 7340: position: relative;
1.1075.2.2 raeburn 7341: float: left;
1.1075.2.112 raeburn 7342: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7343: line-height: 1.5em;
1.1075.2.2 raeburn 7344: }
7345:
1.1075.2.113 raeburn 7346: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7347: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7348: display: block;
7349: margin: 0;
7350: padding: 0 5px 0 10px;
7351: text-decoration: none;
7352: }
7353:
1.1075.2.112 raeburn 7354: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7355: display: inline-block;
7356: width: 95%;
7357: text-align: left;
7358: }
7359:
7360: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7361: display: inline-block;
7362: width: 5%;
7363: float: right;
7364: text-align: right;
7365: font-size: 70%;
7366: }
7367:
7368: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7369: display: none;
1.1075.2.112 raeburn 7370: width: 15em;
1.1075.2.2 raeburn 7371: background-color: $data_table_light;
1.1075.2.112 raeburn 7372: position: absolute;
7373: top: 100%;
7374: }
7375:
7376: ol.LC_primary_menu ul ul {
7377: left: 100%;
7378: top: 0;
1.1075.2.2 raeburn 7379: }
7380:
1.1075.2.112 raeburn 7381: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7382: display: block;
7383: position: absolute;
7384: margin: 0;
7385: padding: 0;
1.1075.2.5 raeburn 7386: z-index: 2;
1.1075.2.2 raeburn 7387: }
7388:
7389: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7390: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7391: font-size: 90%;
1.911 bisitz 7392: vertical-align: top;
1.1075.2.2 raeburn 7393: float: none;
1.1075.2.5 raeburn 7394: border-left: 1px solid black;
7395: border-right: 1px solid black;
1.1075.2.112 raeburn 7396: /* A dark bottom border to visualize different menu options;
7397: overwritten in the create_submenu routine for the last border-bottom of the menu */
7398: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7399: }
7400:
1.1075.2.112 raeburn 7401: ol.LC_primary_menu li li p:hover {
7402: color:$button_hover;
7403: text-decoration:none;
7404: background-color:$data_table_dark;
1.1075.2.2 raeburn 7405: }
7406:
7407: ol.LC_primary_menu li li a:hover {
7408: color:$button_hover;
7409: background-color:$data_table_dark;
1.693 droeschl 7410: }
7411:
1.1075.2.112 raeburn 7412: /* Font-size equal to the size of the predecessors*/
7413: ol.LC_primary_menu li:hover li li {
7414: font-size: 100%;
7415: }
7416:
1.897 wenzelju 7417: ol.LC_primary_menu li img {
1.911 bisitz 7418: vertical-align: bottom;
1.934 droeschl 7419: height: 1.1em;
1.1075.2.3 raeburn 7420: margin: 0.2em 0 0 0;
1.693 droeschl 7421: }
7422:
1.897 wenzelju 7423: ol.LC_primary_menu a {
1.911 bisitz 7424: color: RGB(80, 80, 80);
7425: text-decoration: none;
1.693 droeschl 7426: }
1.795 www 7427:
1.949 droeschl 7428: ol.LC_primary_menu a.LC_new_message {
7429: font-weight:bold;
7430: color: darkred;
7431: }
7432:
1.975 raeburn 7433: ol.LC_docs_parameters {
7434: margin-left: 0;
7435: padding: 0;
7436: list-style: none;
7437: }
7438:
7439: ol.LC_docs_parameters li {
7440: margin: 0;
7441: padding-right: 20px;
7442: display: inline;
7443: }
7444:
1.976 raeburn 7445: ol.LC_docs_parameters li:before {
7446: content: "\\002022 \\0020";
7447: }
7448:
7449: li.LC_docs_parameters_title {
7450: font-weight: bold;
7451: }
7452:
7453: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7454: content: "";
7455: }
7456:
1.897 wenzelju 7457: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7458: clear: right;
1.911 bisitz 7459: color: $fontmenu;
7460: background: $tabbg;
7461: list-style: none;
7462: padding: 0;
7463: margin: 0;
7464: width: 100%;
1.995 raeburn 7465: text-align: left;
1.1075.2.4 raeburn 7466: float: left;
1.808 droeschl 7467: }
7468:
1.897 wenzelju 7469: ul#LC_secondary_menu li {
1.911 bisitz 7470: font-weight: bold;
7471: line-height: 1.8em;
7472: border-right: 1px solid black;
1.1075.2.4 raeburn 7473: float: left;
7474: }
7475:
7476: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7477: background-color: $data_table_light;
7478: }
7479:
7480: ul#LC_secondary_menu li a {
7481: padding: 0 0.8em;
7482: }
7483:
7484: ul#LC_secondary_menu li ul {
7485: display: none;
7486: }
7487:
7488: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7489: display: block;
7490: position: absolute;
7491: margin: 0;
7492: padding: 0;
7493: list-style:none;
7494: float: none;
7495: background-color: $data_table_light;
1.1075.2.5 raeburn 7496: z-index: 2;
1.1075.2.10 raeburn 7497: margin-left: -1px;
1.1075.2.4 raeburn 7498: }
7499:
7500: ul#LC_secondary_menu li ul li {
7501: font-size: 90%;
7502: vertical-align: top;
7503: border-left: 1px solid black;
7504: border-right: 1px solid black;
1.1075.2.33 raeburn 7505: background-color: $data_table_light;
1.1075.2.4 raeburn 7506: list-style:none;
7507: float: none;
7508: }
7509:
7510: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7511: background-color: $data_table_dark;
1.807 droeschl 7512: }
7513:
1.847 tempelho 7514: ul.LC_TabContent {
1.911 bisitz 7515: display:block;
7516: background: $sidebg;
7517: border-bottom: solid 1px $lg_border_color;
7518: list-style:none;
1.1020 raeburn 7519: margin: -1px -10px 0 -10px;
1.911 bisitz 7520: padding: 0;
1.693 droeschl 7521: }
7522:
1.795 www 7523: ul.LC_TabContent li,
7524: ul.LC_TabContentBigger li {
1.911 bisitz 7525: float:left;
1.741 harmsja 7526: }
1.795 www 7527:
1.897 wenzelju 7528: ul#LC_secondary_menu li a {
1.911 bisitz 7529: color: $fontmenu;
7530: text-decoration: none;
1.693 droeschl 7531: }
1.795 www 7532:
1.721 harmsja 7533: ul.LC_TabContent {
1.952 onken 7534: min-height:20px;
1.721 harmsja 7535: }
1.795 www 7536:
7537: ul.LC_TabContent li {
1.911 bisitz 7538: vertical-align:middle;
1.959 onken 7539: padding: 0 16px 0 10px;
1.911 bisitz 7540: background-color:$tabbg;
7541: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7542: border-left: solid 1px $font;
1.721 harmsja 7543: }
1.795 www 7544:
1.847 tempelho 7545: ul.LC_TabContent .right {
1.911 bisitz 7546: float:right;
1.847 tempelho 7547: }
7548:
1.911 bisitz 7549: ul.LC_TabContent li a,
7550: ul.LC_TabContent li {
7551: color:rgb(47,47,47);
7552: text-decoration:none;
7553: font-size:95%;
7554: font-weight:bold;
1.952 onken 7555: min-height:20px;
7556: }
7557:
1.959 onken 7558: ul.LC_TabContent li a:hover,
7559: ul.LC_TabContent li a:focus {
1.952 onken 7560: color: $button_hover;
1.959 onken 7561: background:none;
7562: outline:none;
1.952 onken 7563: }
7564:
7565: ul.LC_TabContent li:hover {
7566: color: $button_hover;
7567: cursor:pointer;
1.721 harmsja 7568: }
1.795 www 7569:
1.911 bisitz 7570: ul.LC_TabContent li.active {
1.952 onken 7571: color: $font;
1.911 bisitz 7572: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7573: border-bottom:solid 1px #FFFFFF;
7574: cursor: default;
1.744 ehlerst 7575: }
1.795 www 7576:
1.959 onken 7577: ul.LC_TabContent li.active a {
7578: color:$font;
7579: background:#FFFFFF;
7580: outline: none;
7581: }
1.1047 raeburn 7582:
7583: ul.LC_TabContent li.goback {
7584: float: left;
7585: border-left: none;
7586: }
7587:
1.870 tempelho 7588: #maincoursedoc {
1.911 bisitz 7589: clear:both;
1.870 tempelho 7590: }
7591:
7592: ul.LC_TabContentBigger {
1.911 bisitz 7593: display:block;
7594: list-style:none;
7595: padding: 0;
1.870 tempelho 7596: }
7597:
1.795 www 7598: ul.LC_TabContentBigger li {
1.911 bisitz 7599: vertical-align:bottom;
7600: height: 30px;
7601: font-size:110%;
7602: font-weight:bold;
7603: color: #737373;
1.841 tempelho 7604: }
7605:
1.957 onken 7606: ul.LC_TabContentBigger li.active {
7607: position: relative;
7608: top: 1px;
7609: }
7610:
1.870 tempelho 7611: ul.LC_TabContentBigger li a {
1.911 bisitz 7612: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7613: height: 30px;
7614: line-height: 30px;
7615: text-align: center;
7616: display: block;
7617: text-decoration: none;
1.958 onken 7618: outline: none;
1.741 harmsja 7619: }
1.795 www 7620:
1.870 tempelho 7621: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7622: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7623: color:$font;
1.744 ehlerst 7624: }
1.795 www 7625:
1.870 tempelho 7626: ul.LC_TabContentBigger li b {
1.911 bisitz 7627: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7628: display: block;
7629: float: left;
7630: padding: 0 30px;
1.957 onken 7631: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7632: }
7633:
1.956 onken 7634: ul.LC_TabContentBigger li:hover b {
7635: color:$button_hover;
7636: }
7637:
1.870 tempelho 7638: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7639: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7640: color:$font;
1.957 onken 7641: border: 0;
1.741 harmsja 7642: }
1.693 droeschl 7643:
1.870 tempelho 7644:
1.862 bisitz 7645: ul.LC_CourseBreadcrumbs {
7646: background: $sidebg;
1.1020 raeburn 7647: height: 2em;
1.862 bisitz 7648: padding-left: 10px;
1.1020 raeburn 7649: margin: 0;
1.862 bisitz 7650: list-style-position: inside;
7651: }
7652:
1.911 bisitz 7653: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7654: ol#LC_PathBreadcrumbs {
1.911 bisitz 7655: padding-left: 10px;
7656: margin: 0;
1.933 droeschl 7657: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7658: }
7659:
1.911 bisitz 7660: ol#LC_MenuBreadcrumbs li,
7661: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7662: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7663: display: inline;
1.933 droeschl 7664: white-space: normal;
1.693 droeschl 7665: }
7666:
1.823 bisitz 7667: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7668: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7669: text-decoration: none;
7670: font-size:90%;
1.693 droeschl 7671: }
1.795 www 7672:
1.969 droeschl 7673: ol#LC_MenuBreadcrumbs h1 {
7674: display: inline;
7675: font-size: 90%;
7676: line-height: 2.5em;
7677: margin: 0;
7678: padding: 0;
7679: }
7680:
1.795 www 7681: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7682: text-decoration:none;
7683: font-size:100%;
7684: font-weight:bold;
1.693 droeschl 7685: }
1.795 www 7686:
1.840 bisitz 7687: .LC_Box {
1.911 bisitz 7688: border: solid 1px $lg_border_color;
7689: padding: 0 10px 10px 10px;
1.746 neumanie 7690: }
1.795 www 7691:
1.1020 raeburn 7692: .LC_DocsBox {
7693: border: solid 1px $lg_border_color;
7694: padding: 0 0 10px 10px;
7695: }
7696:
1.795 www 7697: .LC_AboutMe_Image {
1.911 bisitz 7698: float:left;
7699: margin-right:10px;
1.747 neumanie 7700: }
1.795 www 7701:
7702: .LC_Clear_AboutMe_Image {
1.911 bisitz 7703: clear:left;
1.747 neumanie 7704: }
1.795 www 7705:
1.721 harmsja 7706: dl.LC_ListStyleClean dt {
1.911 bisitz 7707: padding-right: 5px;
7708: display: table-header-group;
1.693 droeschl 7709: }
7710:
1.721 harmsja 7711: dl.LC_ListStyleClean dd {
1.911 bisitz 7712: display: table-row;
1.693 droeschl 7713: }
7714:
1.721 harmsja 7715: .LC_ListStyleClean,
7716: .LC_ListStyleSimple,
7717: .LC_ListStyleNormal,
1.795 www 7718: .LC_ListStyleSpecial {
1.911 bisitz 7719: /* display:block; */
7720: list-style-position: inside;
7721: list-style-type: none;
7722: overflow: hidden;
7723: padding: 0;
1.693 droeschl 7724: }
7725:
1.721 harmsja 7726: .LC_ListStyleSimple li,
7727: .LC_ListStyleSimple dd,
7728: .LC_ListStyleNormal li,
7729: .LC_ListStyleNormal dd,
7730: .LC_ListStyleSpecial li,
1.795 www 7731: .LC_ListStyleSpecial dd {
1.911 bisitz 7732: margin: 0;
7733: padding: 5px 5px 5px 10px;
7734: clear: both;
1.693 droeschl 7735: }
7736:
1.721 harmsja 7737: .LC_ListStyleClean li,
7738: .LC_ListStyleClean dd {
1.911 bisitz 7739: padding-top: 0;
7740: padding-bottom: 0;
1.693 droeschl 7741: }
7742:
1.721 harmsja 7743: .LC_ListStyleSimple dd,
1.795 www 7744: .LC_ListStyleSimple li {
1.911 bisitz 7745: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7746: }
7747:
1.721 harmsja 7748: .LC_ListStyleSpecial li,
7749: .LC_ListStyleSpecial dd {
1.911 bisitz 7750: list-style-type: none;
7751: background-color: RGB(220, 220, 220);
7752: margin-bottom: 4px;
1.693 droeschl 7753: }
7754:
1.721 harmsja 7755: table.LC_SimpleTable {
1.911 bisitz 7756: margin:5px;
7757: border:solid 1px $lg_border_color;
1.795 www 7758: }
1.693 droeschl 7759:
1.721 harmsja 7760: table.LC_SimpleTable tr {
1.911 bisitz 7761: padding: 0;
7762: border:solid 1px $lg_border_color;
1.693 droeschl 7763: }
1.795 www 7764:
7765: table.LC_SimpleTable thead {
1.911 bisitz 7766: background:rgb(220,220,220);
1.693 droeschl 7767: }
7768:
1.721 harmsja 7769: div.LC_columnSection {
1.911 bisitz 7770: display: block;
7771: clear: both;
7772: overflow: hidden;
7773: margin: 0;
1.693 droeschl 7774: }
7775:
1.721 harmsja 7776: div.LC_columnSection>* {
1.911 bisitz 7777: float: left;
7778: margin: 10px 20px 10px 0;
7779: overflow:hidden;
1.693 droeschl 7780: }
1.721 harmsja 7781:
1.795 www 7782: table em {
1.911 bisitz 7783: font-weight: bold;
7784: font-style: normal;
1.748 schulted 7785: }
1.795 www 7786:
1.779 bisitz 7787: table.LC_tableBrowseRes,
1.795 www 7788: table.LC_tableOfContent {
1.911 bisitz 7789: border:none;
7790: border-spacing: 1px;
7791: padding: 3px;
7792: background-color: #FFFFFF;
7793: font-size: 90%;
1.753 droeschl 7794: }
1.789 droeschl 7795:
1.911 bisitz 7796: table.LC_tableOfContent {
7797: border-collapse: collapse;
1.789 droeschl 7798: }
7799:
1.771 droeschl 7800: table.LC_tableBrowseRes a,
1.768 schulted 7801: table.LC_tableOfContent a {
1.911 bisitz 7802: background-color: transparent;
7803: text-decoration: none;
1.753 droeschl 7804: }
7805:
1.795 www 7806: table.LC_tableOfContent img {
1.911 bisitz 7807: border: none;
7808: height: 1.3em;
7809: vertical-align: text-bottom;
7810: margin-right: 0.3em;
1.753 droeschl 7811: }
1.757 schulted 7812:
1.795 www 7813: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7814: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7815: }
7816:
1.795 www 7817: a#LC_content_toolbar_everything {
1.911 bisitz 7818: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7819: }
7820:
1.795 www 7821: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7822: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7823: }
7824:
1.795 www 7825: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7826: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7827: }
7828:
1.795 www 7829: a#LC_content_toolbar_changefolder {
1.911 bisitz 7830: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7831: }
7832:
1.795 www 7833: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7834: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7835: }
7836:
1.1043 raeburn 7837: a#LC_content_toolbar_edittoplevel {
7838: background-image:url(/res/adm/pages/edittoplevel.gif);
7839: }
7840:
1.795 www 7841: ul#LC_toolbar li a:hover {
1.911 bisitz 7842: background-position: bottom center;
1.757 schulted 7843: }
7844:
1.795 www 7845: ul#LC_toolbar {
1.911 bisitz 7846: padding: 0;
7847: margin: 2px;
7848: list-style:none;
7849: position:relative;
7850: background-color:white;
1.1075.2.9 raeburn 7851: overflow: auto;
1.757 schulted 7852: }
7853:
1.795 www 7854: ul#LC_toolbar li {
1.911 bisitz 7855: border:1px solid white;
7856: padding: 0;
7857: margin: 0;
7858: float: left;
7859: display:inline;
7860: vertical-align:middle;
1.1075.2.9 raeburn 7861: white-space: nowrap;
1.911 bisitz 7862: }
1.757 schulted 7863:
1.783 amueller 7864:
1.795 www 7865: a.LC_toolbarItem {
1.911 bisitz 7866: display:block;
7867: padding: 0;
7868: margin: 0;
7869: height: 32px;
7870: width: 32px;
7871: color:white;
7872: border: none;
7873: background-repeat:no-repeat;
7874: background-color:transparent;
1.757 schulted 7875: }
7876:
1.915 droeschl 7877: ul.LC_funclist {
7878: margin: 0;
7879: padding: 0.5em 1em 0.5em 0;
7880: }
7881:
1.933 droeschl 7882: ul.LC_funclist > li:first-child {
7883: font-weight:bold;
7884: margin-left:0.8em;
7885: }
7886:
1.915 droeschl 7887: ul.LC_funclist + ul.LC_funclist {
7888: /*
7889: left border as a seperator if we have more than
7890: one list
7891: */
7892: border-left: 1px solid $sidebg;
7893: /*
7894: this hides the left border behind the border of the
7895: outer box if element is wrapped to the next 'line'
7896: */
7897: margin-left: -1px;
7898: }
7899:
1.843 bisitz 7900: ul.LC_funclist li {
1.915 droeschl 7901: display: inline;
1.782 bisitz 7902: white-space: nowrap;
1.915 droeschl 7903: margin: 0 0 0 25px;
7904: line-height: 150%;
1.782 bisitz 7905: }
7906:
1.974 wenzelju 7907: .LC_hidden {
7908: display: none;
7909: }
7910:
1.1030 www 7911: .LCmodal-overlay {
7912: position:fixed;
7913: top:0;
7914: right:0;
7915: bottom:0;
7916: left:0;
7917: height:100%;
7918: width:100%;
7919: margin:0;
7920: padding:0;
7921: background:#999;
7922: opacity:.75;
7923: filter: alpha(opacity=75);
7924: -moz-opacity: 0.75;
7925: z-index:101;
7926: }
7927:
7928: * html .LCmodal-overlay {
7929: position: absolute;
7930: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7931: }
7932:
7933: .LCmodal-window {
7934: position:fixed;
7935: top:50%;
7936: left:50%;
7937: margin:0;
7938: padding:0;
7939: z-index:102;
7940: }
7941:
7942: * html .LCmodal-window {
7943: position:absolute;
7944: }
7945:
7946: .LCclose-window {
7947: position:absolute;
7948: width:32px;
7949: height:32px;
7950: right:8px;
7951: top:8px;
7952: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7953: text-indent:-99999px;
7954: overflow:hidden;
7955: cursor:pointer;
7956: }
7957:
1.1075.2.158 raeburn 7958: .LCisDisabled {
7959: cursor: not-allowed;
7960: opacity: 0.5;
7961: }
7962:
7963: a[aria-disabled="true"] {
7964: color: currentColor;
7965: display: inline-block; /* For IE11/ MS Edge bug */
7966: pointer-events: none;
7967: text-decoration: none;
7968: }
7969:
1.1075.2.141 raeburn 7970: pre.LC_wordwrap {
7971: white-space: pre-wrap;
7972: white-space: -moz-pre-wrap;
7973: white-space: -pre-wrap;
7974: white-space: -o-pre-wrap;
7975: word-wrap: break-word;
7976: }
7977:
1.1075.2.17 raeburn 7978: /*
7979: styles used by TTH when "Default set of options to pass to tth/m
7980: when converting TeX" in course settings has been set
7981:
7982: option passed: -t
7983:
7984: */
7985:
7986: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7987: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7988: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7989: td div.norm {line-height:normal;}
7990:
7991: /*
7992: option passed -y3
7993: */
7994:
7995: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7996: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7997: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7998:
1.1075.2.121 raeburn 7999: #LC_minitab_header {
8000: float:left;
8001: width:100%;
8002: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8003: font-size:93%;
8004: line-height:normal;
8005: margin: 0.5em 0 0.5em 0;
8006: }
8007: #LC_minitab_header ul {
8008: margin:0;
8009: padding:10px 10px 0;
8010: list-style:none;
8011: }
8012: #LC_minitab_header li {
8013: float:left;
8014: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8015: margin:0;
8016: padding:0 0 0 9px;
8017: }
8018: #LC_minitab_header a {
8019: display:block;
8020: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8021: padding:5px 15px 4px 6px;
8022: }
8023: #LC_minitab_header #LC_current_minitab {
8024: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8025: }
8026: #LC_minitab_header #LC_current_minitab a {
8027: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8028: padding-bottom:5px;
8029: }
8030:
8031:
1.343 albertel 8032: END
8033: }
8034:
1.306 albertel 8035: =pod
8036:
8037: =item * &headtag()
8038:
8039: Returns a uniform footer for LON-CAPA web pages.
8040:
1.307 albertel 8041: Inputs: $title - optional title for the head
8042: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8043: $args - optional arguments
1.319 albertel 8044: force_register - if is true call registerurl so the remote is
8045: informed
1.415 albertel 8046: redirect -> array ref of
8047: 1- seconds before redirect occurs
8048: 2- url to redirect to
8049: 3- whether the side effect should occur
1.315 albertel 8050: (side effect of setting
8051: $env{'internal.head.redirect'} to the url
8052: redirected too)
1.1075.2.166! raeburn 8053: 4- whether encrypt check should be skipped
1.352 albertel 8054: domain -> force to color decorate a page for a specific
8055: domain
8056: function -> force usage of a specific rolish color scheme
8057: bgcolor -> override the default page bgcolor
1.460 albertel 8058: no_auto_mt_title
8059: -> prevent &mt()ing the title arg
1.464 albertel 8060:
1.306 albertel 8061: =cut
8062:
8063: sub headtag {
1.313 albertel 8064: my ($title,$head_extra,$args) = @_;
1.306 albertel 8065:
1.363 albertel 8066: my $function = $args->{'function'} || &get_users_function();
8067: my $domain = $args->{'domain'} || &determinedomain();
8068: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 8069: my $httphost = $args->{'use_absolute'};
1.418 albertel 8070: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8071: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8072: #time(),
1.418 albertel 8073: $env{'environment.color.timestamp'},
1.363 albertel 8074: $function,$domain,$bgcolor);
8075:
1.369 www 8076: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8077:
1.308 albertel 8078: my $result =
8079: '<head>'.
1.1075.2.56 raeburn 8080: &font_settings($args);
1.319 albertel 8081:
1.1075.2.72 raeburn 8082: my $inhibitprint;
8083: if ($args->{'print_suppress'}) {
8084: $inhibitprint = &print_suppression();
8085: }
1.1064 raeburn 8086:
1.461 albertel 8087: if (!$args->{'frameset'}) {
8088: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8089: }
1.1075.2.12 raeburn 8090: if ($args->{'force_register'}) {
8091: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 8092: }
1.436 albertel 8093: if (!$args->{'no_nav_bar'}
8094: && !$args->{'only_body'}
8095: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 8096: $result .= &help_menu_js($httphost);
1.1032 www 8097: $result.=&modal_window();
1.1038 www 8098: $result.=&togglebox_script();
1.1034 www 8099: $result.=&wishlist_window();
1.1041 www 8100: $result.=&LCprogressbarUpdate_script();
1.1034 www 8101: } else {
8102: if ($args->{'add_modal'}) {
8103: $result.=&modal_window();
8104: }
8105: if ($args->{'add_wishlist'}) {
8106: $result.=&wishlist_window();
8107: }
1.1038 www 8108: if ($args->{'add_togglebox'}) {
8109: $result.=&togglebox_script();
8110: }
1.1041 www 8111: if ($args->{'add_progressbar'}) {
8112: $result.=&LCprogressbarUpdate_script();
8113: }
1.436 albertel 8114: }
1.314 albertel 8115: if (ref($args->{'redirect'})) {
1.1075.2.166! raeburn 8116: my ($time,$url,$inhibit_continue,$skip_enc_check) = @{$args->{'redirect'}};
! 8117: if (!$skip_enc_check) {
! 8118: $url = &Apache::lonenc::check_encrypt($url);
! 8119: }
1.414 albertel 8120: if (!$inhibit_continue) {
8121: $env{'internal.head.redirect'} = $url;
8122: }
1.313 albertel 8123: $result.=<<ADDMETA
8124: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8125: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8126: ADDMETA
1.1075.2.89 raeburn 8127: } else {
8128: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8129: my $requrl = $env{'request.uri'};
8130: if ($requrl eq '') {
8131: $requrl = $ENV{'REQUEST_URI'};
8132: $requrl =~ s/\?.+$//;
8133: }
8134: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8135: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8136: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8137: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8138: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8139: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 8140: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1075.2.151 raeburn 8141: my ($offload,$offloadoth);
1.1075.2.89 raeburn 8142: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8143: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 8144: $offload = 1;
1.1075.2.151 raeburn 8145: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8146: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8147: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8148: $offloadoth = 1;
8149: $dom_in_use = $env{'user.domain'};
8150: }
8151: }
1.1075.2.145 raeburn 8152: }
8153: }
8154: unless ($offload) {
8155: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8156: if ($domdefs{'offloadoth'}{$lonhost}) {
8157: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8158: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8159: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8160: $offload = 1;
1.1075.2.151 raeburn 8161: $offloadoth = 1;
1.1075.2.145 raeburn 8162: $dom_in_use = $env{'user.domain'};
8163: }
1.1075.2.89 raeburn 8164: }
1.1075.2.145 raeburn 8165: }
8166: }
8167: }
8168: if ($offload) {
1.1075.2.158 raeburn 8169: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1075.2.151 raeburn 8170: if (($newserver eq '') && ($offloadoth)) {
8171: my @domains = &Apache::lonnet::current_machine_domains();
8172: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
8173: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8174: }
8175: }
1.1075.2.145 raeburn 8176: if (($newserver) && ($newserver ne $lonhost)) {
8177: my $numsec = 5;
8178: my $timeout = $numsec * 1000;
8179: my ($newurl,$locknum,%locks,$msg);
8180: if ($env{'request.role.adv'}) {
8181: ($locknum,%locks) = &Apache::lonnet::get_locks();
8182: }
8183: my $disable_submit = 0;
8184: if ($requrl =~ /$LONCAPA::assess_re/) {
8185: $disable_submit = 1;
8186: }
8187: if ($locknum) {
8188: my @lockinfo = sort(values(%locks));
1.1075.2.153 raeburn 8189: $msg = &mt('Once the following tasks are complete:')." \n".
1.1075.2.145 raeburn 8190: join(", ",sort(values(%locks)))."\n";
8191: if (&show_course()) {
8192: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 8193: } else {
1.1075.2.145 raeburn 8194: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
8195: }
8196: } else {
8197: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8198: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8199: }
8200: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8201: $newurl = '/adm/switchserver?otherserver='.$newserver;
8202: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8203: $newurl .= '&role='.$env{'request.role'};
8204: }
8205: if ($env{'request.symb'}) {
8206: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8207: if ($shownsymb =~ m{^/enc/}) {
8208: my $reqdmajor = 2;
8209: my $reqdminor = 11;
8210: my $reqdsubminor = 3;
8211: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8212: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8213: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8214: if (($major eq '' && $minor eq '') ||
8215: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8216: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8217: ($reqdsubminor > $subminor))))) {
8218: undef($shownsymb);
8219: }
1.1075.2.89 raeburn 8220: }
1.1075.2.145 raeburn 8221: if ($shownsymb) {
8222: &js_escape(\$shownsymb);
8223: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 8224: }
1.1075.2.145 raeburn 8225: } else {
8226: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8227: &js_escape(\$shownurl);
8228: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 8229: }
1.1075.2.145 raeburn 8230: }
8231: &js_escape(\$msg);
8232: $result.=<<OFFLOAD
1.1075.2.89 raeburn 8233: <meta http-equiv="pragma" content="no-cache" />
8234: <script type="text/javascript">
1.1075.2.92 raeburn 8235: // <![CDATA[
1.1075.2.89 raeburn 8236: function LC_Offload_Now() {
8237: var dest = "$newurl";
8238: if (dest != '') {
8239: window.location.href="$newurl";
8240: }
8241: }
1.1075.2.92 raeburn 8242: \$(document).ready(function () {
8243: window.alert('$msg');
8244: if ($disable_submit) {
1.1075.2.89 raeburn 8245: \$(".LC_hwk_submit").prop("disabled", true);
8246: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 8247: }
8248: setTimeout('LC_Offload_Now()', $timeout);
8249: });
8250: // ]]>
1.1075.2.89 raeburn 8251: </script>
8252: OFFLOAD
8253: }
8254: }
8255: }
8256: }
8257: }
1.313 albertel 8258: }
1.306 albertel 8259: if (!defined($title)) {
8260: $title = 'The LearningOnline Network with CAPA';
8261: }
1.460 albertel 8262: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8263: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 8264: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8265: if (!$args->{'frameset'}) {
8266: $result .= ' /';
8267: }
8268: $result .= '>'
1.1064 raeburn 8269: .$inhibitprint
1.414 albertel 8270: .$head_extra;
1.1075.2.108 raeburn 8271: my $clientmobile;
8272: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8273: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8274: } else {
8275: $clientmobile = $env{'browser.mobile'};
8276: }
8277: if ($clientmobile) {
1.1075.2.42 raeburn 8278: $result .= '
8279: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8280: <meta name="apple-mobile-web-app-capable" content="yes" />';
8281: }
1.1075.2.126 raeburn 8282: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8283: return $result.'</head>';
1.306 albertel 8284: }
8285:
8286: =pod
8287:
1.340 albertel 8288: =item * &font_settings()
8289:
8290: Returns neccessary <meta> to set the proper encoding
8291:
1.1075.2.56 raeburn 8292: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8293:
8294: =cut
8295:
8296: sub font_settings {
1.1075.2.56 raeburn 8297: my ($args) = @_;
1.340 albertel 8298: my $headerstring='';
1.1075.2.56 raeburn 8299: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8300: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8301: $headerstring.=
1.1075.2.61 raeburn 8302: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8303: if (!$args->{'frameset'}) {
8304: $headerstring.= ' /';
8305: }
8306: $headerstring .= '>'."\n";
1.340 albertel 8307: }
8308: return $headerstring;
8309: }
8310:
1.341 albertel 8311: =pod
8312:
1.1064 raeburn 8313: =item * &print_suppression()
8314:
8315: In course context returns css which causes the body to be blank when media="print",
8316: if printout generation is unavailable for the current resource.
8317:
8318: This could be because:
8319:
8320: (a) printstartdate is in the future
8321:
8322: (b) printenddate is in the past
8323:
8324: (c) there is an active exam block with "printout"
8325: functionality blocked
8326:
8327: Users with pav, pfo or evb privileges are exempt.
8328:
8329: Inputs: none
8330:
8331: =cut
8332:
8333:
8334: sub print_suppression {
8335: my $noprint;
8336: if ($env{'request.course.id'}) {
8337: my $scope = $env{'request.course.id'};
8338: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8339: (&Apache::lonnet::allowed('pfo',$scope))) {
8340: return;
8341: }
8342: if ($env{'request.course.sec'} ne '') {
8343: $scope .= "/$env{'request.course.sec'}";
8344: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8345: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8346: return;
1.1064 raeburn 8347: }
8348: }
8349: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8350: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.158 raeburn 8351: my $clientip = &Apache::lonnet::get_requestor_ip();
8352: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 8353: if ($blocked) {
8354: my $checkrole = "cm./$cdom/$cnum";
8355: if ($env{'request.course.sec'} ne '') {
8356: $checkrole .= "/$env{'request.course.sec'}";
8357: }
8358: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8359: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8360: $noprint = 1;
8361: }
8362: }
8363: unless ($noprint) {
8364: my $symb = &Apache::lonnet::symbread();
8365: if ($symb ne '') {
8366: my $navmap = Apache::lonnavmaps::navmap->new();
8367: if (ref($navmap)) {
8368: my $res = $navmap->getBySymb($symb);
8369: if (ref($res)) {
8370: if (!$res->resprintable()) {
8371: $noprint = 1;
8372: }
8373: }
8374: }
8375: }
8376: }
8377: if ($noprint) {
8378: return <<"ENDSTYLE";
8379: <style type="text/css" media="print">
8380: body { display:none }
8381: </style>
8382: ENDSTYLE
8383: }
8384: }
8385: return;
8386: }
8387:
8388: =pod
8389:
1.341 albertel 8390: =item * &xml_begin()
8391:
8392: Returns the needed doctype and <html>
8393:
8394: Inputs: none
8395:
8396: =cut
8397:
8398: sub xml_begin {
1.1075.2.61 raeburn 8399: my ($is_frameset) = @_;
1.341 albertel 8400: my $output='';
8401:
8402: if ($env{'browser.mathml'}) {
8403: $output='<?xml version="1.0"?>'
8404: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8405: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8406:
8407: # .'<!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">] >'
8408: .'<!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">'
8409: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8410: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8411: } elsif ($is_frameset) {
8412: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8413: '<html>'."\n";
1.341 albertel 8414: } else {
1.1075.2.61 raeburn 8415: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8416: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8417: }
8418: return $output;
8419: }
1.340 albertel 8420:
8421: =pod
8422:
1.306 albertel 8423: =item * &start_page()
8424:
8425: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8426:
1.648 raeburn 8427: Inputs:
8428:
8429: =over 4
8430:
8431: $title - optional title for the page
8432:
8433: $head_extra - optional extra HTML to incude inside the <head>
8434:
8435: $args - additional optional args supported are:
8436:
8437: =over 8
8438:
8439: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8440: arg on
1.814 bisitz 8441: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8442: add_entries -> additional attributes to add to the <body>
8443: domain -> force to color decorate a page for a
1.317 albertel 8444: specific domain
1.648 raeburn 8445: function -> force usage of a specific rolish color
1.317 albertel 8446: scheme
1.648 raeburn 8447: redirect -> see &headtag()
8448: bgcolor -> override the default page bg color
8449: js_ready -> return a string ready for being used in
1.317 albertel 8450: a javascript writeln
1.648 raeburn 8451: html_encode -> return a string ready for being used in
1.320 albertel 8452: a html attribute
1.648 raeburn 8453: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8454: $forcereg arg
1.648 raeburn 8455: frameset -> if true will start with a <frameset>
1.330 albertel 8456: rather than <body>
1.648 raeburn 8457: skip_phases -> hash ref of
1.338 albertel 8458: head -> skip the <html><head> generation
8459: body -> skip all <body> generation
1.1075.2.12 raeburn 8460: no_inline_link -> if true and in remote mode, don't show the
8461: 'Switch To Inline Menu' link
1.648 raeburn 8462: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8463: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8464: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8465: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8466: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8467: group -> includes the current group, if page is for a
8468: specific group
1.1075.2.133 raeburn 8469: use_absolute -> for request for external resource or syllabus, this
8470: will contain https://<hostname> if server uses
8471: https (as per hosts.tab), but request is for http
8472: hostname -> hostname, originally from $r->hostname(), (optional).
1.1075.2.158 raeburn 8473: links_disabled -> Links in primary and secondary menus are disabled
8474: (Can enable them once page has loaded - see lonroles.pm
8475: for an example).
1.361 albertel 8476:
1.648 raeburn 8477: =back
1.460 albertel 8478:
1.648 raeburn 8479: =back
1.562 albertel 8480:
1.306 albertel 8481: =cut
8482:
8483: sub start_page {
1.309 albertel 8484: my ($title,$head_extra,$args) = @_;
1.318 albertel 8485: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8486:
1.315 albertel 8487: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8488: my ($result,@advtools);
1.964 droeschl 8489:
1.338 albertel 8490: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8491: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8492: }
8493:
8494: if (! exists($args->{'skip_phases'}{'body'}) ) {
8495: if ($args->{'frameset'}) {
8496: my $attr_string = &make_attr_string($args->{'force_register'},
8497: $args->{'add_entries'});
8498: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8499: } else {
8500: $result .=
8501: &bodytag($title,
8502: $args->{'function'}, $args->{'add_entries'},
8503: $args->{'only_body'}, $args->{'domain'},
8504: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8505: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8506: $args, \@advtools);
1.831 bisitz 8507: }
1.330 albertel 8508: }
1.338 albertel 8509:
1.315 albertel 8510: if ($args->{'js_ready'}) {
1.713 kaisler 8511: $result = &js_ready($result);
1.315 albertel 8512: }
1.320 albertel 8513: if ($args->{'html_encode'}) {
1.713 kaisler 8514: $result = &html_encode($result);
8515: }
8516:
1.813 bisitz 8517: # Preparation for new and consistent functionlist at top of screen
8518: # if ($args->{'functionlist'}) {
8519: # $result .= &build_functionlist();
8520: #}
8521:
1.964 droeschl 8522: # Don't add anything more if only_body wanted or in const space
8523: return $result if $args->{'only_body'}
8524: || $env{'request.state'} eq 'construct';
1.813 bisitz 8525:
8526: #Breadcrumbs
1.758 kaisler 8527: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8528: &Apache::lonhtmlcommon::clear_breadcrumbs();
8529: #if any br links exists, add them to the breadcrumbs
8530: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8531: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8532: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8533: }
8534: }
1.1075.2.19 raeburn 8535: # if @advtools array contains items add then to the breadcrumbs
8536: if (@advtools > 0) {
8537: &Apache::lonmenu::advtools_crumbs(@advtools);
8538: }
1.1075.2.123 raeburn 8539: my $menulink;
8540: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8541: if (exists($args->{'bread_crumbs_nomenu'})) {
8542: $menulink = 0;
8543: } else {
8544: undef($menulink);
8545: }
1.758 kaisler 8546: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8547: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8548: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8549: }else{
1.1075.2.123 raeburn 8550: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8551: }
1.1075.2.24 raeburn 8552: } elsif (($env{'environment.remote'} eq 'on') &&
8553: ($env{'form.inhibitmenu'} ne 'yes') &&
8554: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8555: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8556: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8557: }
1.315 albertel 8558: return $result;
1.306 albertel 8559: }
8560:
8561: sub end_page {
1.315 albertel 8562: my ($args) = @_;
8563: $env{'internal.end_page'}++;
1.330 albertel 8564: my $result;
1.335 albertel 8565: if ($args->{'discussion'}) {
8566: my ($target,$parser);
8567: if (ref($args->{'discussion'})) {
8568: ($target,$parser) =($args->{'discussion'}{'target'},
8569: $args->{'discussion'}{'parser'});
8570: }
8571: $result .= &Apache::lonxml::xmlend($target,$parser);
8572: }
1.330 albertel 8573: if ($args->{'frameset'}) {
8574: $result .= '</frameset>';
8575: } else {
1.635 raeburn 8576: $result .= &endbodytag($args);
1.330 albertel 8577: }
1.1075.2.6 raeburn 8578: unless ($args->{'notbody'}) {
8579: $result .= "\n</html>";
8580: }
1.330 albertel 8581:
1.315 albertel 8582: if ($args->{'js_ready'}) {
1.317 albertel 8583: $result = &js_ready($result);
1.315 albertel 8584: }
1.335 albertel 8585:
1.320 albertel 8586: if ($args->{'html_encode'}) {
8587: $result = &html_encode($result);
8588: }
1.335 albertel 8589:
1.315 albertel 8590: return $result;
8591: }
8592:
1.1034 www 8593: sub wishlist_window {
8594: return(<<'ENDWISHLIST');
1.1046 raeburn 8595: <script type="text/javascript">
1.1034 www 8596: // <![CDATA[
8597: // <!-- BEGIN LON-CAPA Internal
8598: function set_wishlistlink(title, path) {
8599: if (!title) {
8600: title = document.title;
8601: title = title.replace(/^LON-CAPA /,'');
8602: }
1.1075.2.65 raeburn 8603: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8604: title = title.replace("'","\\\'");
1.1034 www 8605: if (!path) {
8606: path = location.pathname;
8607: }
1.1075.2.65 raeburn 8608: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8609: path = path.replace("'","\\\'");
1.1034 www 8610: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8611: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8612: }
8613: // END LON-CAPA Internal -->
8614: // ]]>
8615: </script>
8616: ENDWISHLIST
8617: }
8618:
1.1030 www 8619: sub modal_window {
8620: return(<<'ENDMODAL');
1.1046 raeburn 8621: <script type="text/javascript">
1.1030 www 8622: // <![CDATA[
8623: // <!-- BEGIN LON-CAPA Internal
8624: var modalWindow = {
8625: parent:"body",
8626: windowId:null,
8627: content:null,
8628: width:null,
8629: height:null,
8630: close:function()
8631: {
8632: $(".LCmodal-window").remove();
8633: $(".LCmodal-overlay").remove();
8634: },
8635: open:function()
8636: {
8637: var modal = "";
8638: modal += "<div class=\"LCmodal-overlay\"></div>";
8639: 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;\">";
8640: modal += this.content;
8641: modal += "</div>";
8642:
8643: $(this.parent).append(modal);
8644:
8645: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8646: $(".LCclose-window").click(function(){modalWindow.close();});
8647: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8648: }
8649: };
1.1075.2.42 raeburn 8650: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8651: {
1.1075.2.119 raeburn 8652: source = source.replace(/'/g,"'");
1.1030 www 8653: modalWindow.windowId = "myModal";
8654: modalWindow.width = width;
8655: modalWindow.height = height;
1.1075.2.80 raeburn 8656: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8657: modalWindow.open();
1.1075.2.87 raeburn 8658: };
1.1030 www 8659: // END LON-CAPA Internal -->
8660: // ]]>
8661: </script>
8662: ENDMODAL
8663: }
8664:
8665: sub modal_link {
1.1075.2.42 raeburn 8666: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8667: unless ($width) { $width=480; }
8668: unless ($height) { $height=400; }
1.1031 www 8669: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8670: unless ($transparency) { $transparency='true'; }
8671:
1.1074 raeburn 8672: my $target_attr;
8673: if (defined($target)) {
8674: $target_attr = 'target="'.$target.'"';
8675: }
8676: return <<"ENDLINK";
1.1075.2.143 raeburn 8677: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 8678: ENDLINK
1.1030 www 8679: }
8680:
1.1032 www 8681: sub modal_adhoc_script {
1.1075.2.155 raeburn 8682: my ($funcname,$width,$height,$content,$possmathjax)=@_;
8683: my $mathjax;
8684: if ($possmathjax) {
8685: $mathjax = <<'ENDJAX';
8686: if (typeof MathJax == 'object') {
8687: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
8688: }
8689: ENDJAX
8690: }
1.1032 www 8691: return (<<ENDADHOC);
1.1046 raeburn 8692: <script type="text/javascript">
1.1032 www 8693: // <![CDATA[
8694: var $funcname = function()
8695: {
8696: modalWindow.windowId = "myModal";
8697: modalWindow.width = $width;
8698: modalWindow.height = $height;
8699: modalWindow.content = '$content';
8700: modalWindow.open();
1.1075.2.155 raeburn 8701: $mathjax
1.1032 www 8702: };
8703: // ]]>
8704: </script>
8705: ENDADHOC
8706: }
8707:
1.1041 www 8708: sub modal_adhoc_inner {
1.1075.2.155 raeburn 8709: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 8710: my $innerwidth=$width-20;
8711: $content=&js_ready(
1.1042 www 8712: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8713: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8714: $content.
1.1041 www 8715: &end_scrollbox().
1.1075.2.42 raeburn 8716: &end_page()
1.1041 www 8717: );
1.1075.2.155 raeburn 8718: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 8719: }
8720:
8721: sub modal_adhoc_window {
1.1075.2.155 raeburn 8722: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
8723: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 8724: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8725: }
8726:
8727: sub modal_adhoc_launch {
8728: my ($funcname,$width,$height,$content)=@_;
8729: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8730: <script type="text/javascript">
8731: // <![CDATA[
8732: $funcname();
8733: // ]]>
8734: </script>
8735: ENDLAUNCH
8736: }
8737:
8738: sub modal_adhoc_close {
8739: return (<<ENDCLOSE);
8740: <script type="text/javascript">
8741: // <![CDATA[
8742: modalWindow.close();
8743: // ]]>
8744: </script>
8745: ENDCLOSE
8746: }
8747:
1.1038 www 8748: sub togglebox_script {
8749: return(<<ENDTOGGLE);
8750: <script type="text/javascript">
8751: // <![CDATA[
8752: function LCtoggleDisplay(id,hidetext,showtext) {
8753: link = document.getElementById(id + "link").childNodes[0];
8754: with (document.getElementById(id).style) {
8755: if (display == "none" ) {
8756: display = "inline";
8757: link.nodeValue = hidetext;
8758: } else {
8759: display = "none";
8760: link.nodeValue = showtext;
8761: }
8762: }
8763: }
8764: // ]]>
8765: </script>
8766: ENDTOGGLE
8767: }
8768:
1.1039 www 8769: sub start_togglebox {
8770: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8771: unless ($heading) { $heading=''; } else { $heading.=' '; }
8772: unless ($showtext) { $showtext=&mt('show'); }
8773: unless ($hidetext) { $hidetext=&mt('hide'); }
8774: unless ($headerbg) { $headerbg='#FFFFFF'; }
8775: return &start_data_table().
8776: &start_data_table_header_row().
8777: '<td bgcolor="'.$headerbg.'">'.$heading.
8778: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8779: $showtext.'\')">'.$showtext.'</a>]</td>'.
8780: &end_data_table_header_row().
8781: '<tr id="'.$id.'" style="display:none""><td>';
8782: }
8783:
8784: sub end_togglebox {
8785: return '</td></tr>'.&end_data_table();
8786: }
8787:
1.1041 www 8788: sub LCprogressbar_script {
1.1075.2.130 raeburn 8789: my ($id,$number_to_do)=@_;
8790: if ($number_to_do) {
8791: return(<<ENDPROGRESS);
1.1041 www 8792: <script type="text/javascript">
8793: // <![CDATA[
1.1045 www 8794: \$('#progressbar$id').progressbar({
1.1041 www 8795: value: 0,
8796: change: function(event, ui) {
8797: var newVal = \$(this).progressbar('option', 'value');
8798: \$('.pblabel', this).text(LCprogressTxt);
8799: }
8800: });
8801: // ]]>
8802: </script>
8803: ENDPROGRESS
1.1075.2.130 raeburn 8804: } else {
8805: return(<<ENDPROGRESS);
8806: <script type="text/javascript">
8807: // <![CDATA[
8808: \$('#progressbar$id').progressbar({
8809: value: false,
8810: create: function(event, ui) {
8811: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8812: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8813: }
8814: });
8815: // ]]>
8816: </script>
8817: ENDPROGRESS
8818: }
1.1041 www 8819: }
8820:
8821: sub LCprogressbarUpdate_script {
8822: return(<<ENDPROGRESSUPDATE);
8823: <style type="text/css">
8824: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8825: .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 8826: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8827: </style>
8828: <script type="text/javascript">
8829: // <![CDATA[
1.1045 www 8830: var LCprogressTxt='---';
8831:
1.1075.2.130 raeburn 8832: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8833: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8834: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8835: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8836: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8837: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8838: } else {
8839: \$('#progressbar'+id).progressbar('value',percent);
8840: }
1.1041 www 8841: }
8842: // ]]>
8843: </script>
8844: ENDPROGRESSUPDATE
8845: }
8846:
1.1042 www 8847: my $LClastpercent;
1.1045 www 8848: my $LCidcnt;
8849: my $LCcurrentid;
1.1042 www 8850:
1.1041 www 8851: sub LCprogressbar {
1.1075.2.130 raeburn 8852: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8853: $LClastpercent=0;
1.1045 www 8854: $LCidcnt++;
8855: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8856: my ($starting,$content);
8857: if ($number_to_do) {
8858: $starting=&mt('Starting');
8859: $content=(<<ENDPROGBAR);
8860: $preamble
1.1045 www 8861: <div id="progressbar$LCcurrentid">
1.1041 www 8862: <span class="pblabel">$starting</span>
8863: </div>
8864: ENDPROGBAR
1.1075.2.130 raeburn 8865: } else {
8866: $starting=&mt('Loading...');
8867: $LClastpercent='false';
8868: $content=(<<ENDPROGBAR);
8869: $preamble
8870: <div id="progressbar$LCcurrentid">
8871: <div class="progress-label">$starting</div>
8872: </div>
8873: ENDPROGBAR
8874: }
8875: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8876: }
8877:
8878: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8879: my ($r,$val,$text,$number_to_do)=@_;
8880: if ($number_to_do) {
8881: unless ($val) {
8882: if ($LClastpercent) {
8883: $val=$LClastpercent;
8884: } else {
8885: $val=0;
8886: }
8887: }
8888: if ($val<0) { $val=0; }
8889: if ($val>100) { $val=0; }
8890: $LClastpercent=$val;
8891: unless ($text) { $text=$val.'%'; }
8892: } else {
8893: $val = 'false';
1.1042 www 8894: }
1.1041 www 8895: $text=&js_ready($text);
1.1044 www 8896: &r_print($r,<<ENDUPDATE);
1.1041 www 8897: <script type="text/javascript">
8898: // <![CDATA[
1.1075.2.130 raeburn 8899: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8900: // ]]>
8901: </script>
8902: ENDUPDATE
1.1035 www 8903: }
8904:
1.1042 www 8905: sub LCprogressbarClose {
8906: my ($r)=@_;
8907: $LClastpercent=0;
1.1044 www 8908: &r_print($r,<<ENDCLOSE);
1.1042 www 8909: <script type="text/javascript">
8910: // <![CDATA[
1.1045 www 8911: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8912: // ]]>
8913: </script>
8914: ENDCLOSE
1.1044 www 8915: }
8916:
8917: sub r_print {
8918: my ($r,$to_print)=@_;
8919: if ($r) {
8920: $r->print($to_print);
8921: $r->rflush();
8922: } else {
8923: print($to_print);
8924: }
1.1042 www 8925: }
8926:
1.320 albertel 8927: sub html_encode {
8928: my ($result) = @_;
8929:
1.322 albertel 8930: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8931:
8932: return $result;
8933: }
1.1044 www 8934:
1.317 albertel 8935: sub js_ready {
8936: my ($result) = @_;
8937:
1.323 albertel 8938: $result =~ s/[\n\r]/ /xmsg;
8939: $result =~ s/\\/\\\\/xmsg;
8940: $result =~ s/'/\\'/xmsg;
1.372 albertel 8941: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8942:
8943: return $result;
8944: }
8945:
1.315 albertel 8946: sub validate_page {
8947: if ( exists($env{'internal.start_page'})
1.316 albertel 8948: && $env{'internal.start_page'} > 1) {
8949: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8950: $env{'internal.start_page'}.' '.
1.316 albertel 8951: $ENV{'request.filename'});
1.315 albertel 8952: }
8953: if ( exists($env{'internal.end_page'})
1.316 albertel 8954: && $env{'internal.end_page'} > 1) {
8955: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8956: $env{'internal.end_page'}.' '.
1.316 albertel 8957: $env{'request.filename'});
1.315 albertel 8958: }
8959: if ( exists($env{'internal.start_page'})
8960: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8961: &Apache::lonnet::logthis('start_page called without end_page '.
8962: $env{'request.filename'});
1.315 albertel 8963: }
8964: if ( ! exists($env{'internal.start_page'})
8965: && exists($env{'internal.end_page'})) {
1.316 albertel 8966: &Apache::lonnet::logthis('end_page called without start_page'.
8967: $env{'request.filename'});
1.315 albertel 8968: }
1.306 albertel 8969: }
1.315 albertel 8970:
1.996 www 8971:
8972: sub start_scrollbox {
1.1075.2.56 raeburn 8973: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8974: unless ($outerwidth) { $outerwidth='520px'; }
8975: unless ($width) { $width='500px'; }
8976: unless ($height) { $height='200px'; }
1.1075 raeburn 8977: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8978: if ($id ne '') {
1.1075.2.42 raeburn 8979: $table_id = ' id="table_'.$id.'"';
8980: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8981: }
1.1075 raeburn 8982: if ($bgcolor ne '') {
8983: $tdcol = "background-color: $bgcolor;";
8984: }
1.1075.2.42 raeburn 8985: my $nicescroll_js;
8986: if ($env{'browser.mobile'}) {
8987: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8988: }
1.1075 raeburn 8989: return <<"END";
1.1075.2.42 raeburn 8990: $nicescroll_js
8991:
8992: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8993: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8994: END
1.996 www 8995: }
8996:
8997: sub end_scrollbox {
1.1036 www 8998: return '</div></td></tr></table>';
1.996 www 8999: }
9000:
1.1075.2.42 raeburn 9001: sub nicescroll_javascript {
9002: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9003: my %options;
9004: if (ref($cursor) eq 'HASH') {
9005: %options = %{$cursor};
9006: }
9007: unless ($options{'railalign'} =~ /^left|right$/) {
9008: $options{'railalign'} = 'left';
9009: }
9010: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9011: my $function = &get_users_function();
9012: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
9013: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9014: $options{'cursorcolor'} = '#00F';
9015: }
9016: }
9017: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9018: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
9019: $options{'cursoropacity'}='1.0';
9020: }
9021: } else {
9022: $options{'cursoropacity'}='1.0';
9023: }
9024: if ($options{'cursorfixedheight'} eq 'none') {
9025: delete($options{'cursorfixedheight'});
9026: } else {
9027: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9028: }
9029: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9030: delete($options{'railoffset'});
9031: }
9032: my @niceoptions;
9033: while (my($key,$value) = each(%options)) {
9034: if ($value =~ /^\{.+\}$/) {
9035: push(@niceoptions,$key.':'.$value);
9036: } else {
9037: push(@niceoptions,$key.':"'.$value.'"');
9038: }
9039: }
9040: my $nicescroll_js = '
9041: $(document).ready(
9042: function() {
9043: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9044: }
9045: );
9046: ';
9047: if ($framecheck) {
9048: $nicescroll_js .= '
9049: function expand_div(caller) {
9050: if (top === self) {
9051: document.getElementById("'.$id.'").style.width = "auto";
9052: document.getElementById("'.$id.'").style.height = "auto";
9053: } else {
9054: try {
9055: if (parent.frames) {
9056: if (parent.frames.length > 1) {
9057: var framesrc = parent.frames[1].location.href;
9058: var currsrc = framesrc.replace(/\#.*$/,"");
9059: if ((caller == "search") || (currsrc == "'.$location.'")) {
9060: document.getElementById("'.$id.'").style.width = "auto";
9061: document.getElementById("'.$id.'").style.height = "auto";
9062: }
9063: }
9064: }
9065: } catch (e) {
9066: return;
9067: }
9068: }
9069: return;
9070: }
9071: ';
9072: }
9073: if ($needjsready) {
9074: $nicescroll_js = '
9075: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9076: } else {
9077: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9078: }
9079: return $nicescroll_js;
9080: }
9081:
1.318 albertel 9082: sub simple_error_page {
1.1075.2.49 raeburn 9083: my ($r,$title,$msg,$args) = @_;
9084: if (ref($args) eq 'HASH') {
9085: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9086: } else {
9087: $msg = &mt($msg);
9088: }
9089:
1.318 albertel 9090: my $page =
9091: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 9092: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9093: &Apache::loncommon::end_page();
9094: if (ref($r)) {
9095: $r->print($page);
1.327 albertel 9096: return;
1.318 albertel 9097: }
9098: return $page;
9099: }
1.347 albertel 9100:
9101: {
1.610 albertel 9102: my @row_count;
1.961 onken 9103:
9104: sub start_data_table_count {
9105: unshift(@row_count, 0);
9106: return;
9107: }
9108:
9109: sub end_data_table_count {
9110: shift(@row_count);
9111: return;
9112: }
9113:
1.347 albertel 9114: sub start_data_table {
1.1018 raeburn 9115: my ($add_class,$id) = @_;
1.422 albertel 9116: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9117: my $table_id;
9118: if (defined($id)) {
9119: $table_id = ' id="'.$id.'"';
9120: }
1.961 onken 9121: &start_data_table_count();
1.1018 raeburn 9122: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9123: }
9124:
9125: sub end_data_table {
1.961 onken 9126: &end_data_table_count();
1.389 albertel 9127: return '</table>'."\n";;
1.347 albertel 9128: }
9129:
9130: sub start_data_table_row {
1.974 wenzelju 9131: my ($add_class, $id) = @_;
1.610 albertel 9132: $row_count[0]++;
9133: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9134: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9135: $id = (' id="'.$id.'"') unless ($id eq '');
9136: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9137: }
1.471 banghart 9138:
9139: sub continue_data_table_row {
1.974 wenzelju 9140: my ($add_class, $id) = @_;
1.610 albertel 9141: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9142: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9143: $id = (' id="'.$id.'"') unless ($id eq '');
9144: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9145: }
1.347 albertel 9146:
9147: sub end_data_table_row {
1.389 albertel 9148: return '</tr>'."\n";;
1.347 albertel 9149: }
1.367 www 9150:
1.421 albertel 9151: sub start_data_table_empty_row {
1.707 bisitz 9152: # $row_count[0]++;
1.421 albertel 9153: return '<tr class="LC_empty_row" >'."\n";;
9154: }
9155:
9156: sub end_data_table_empty_row {
9157: return '</tr>'."\n";;
9158: }
9159:
1.367 www 9160: sub start_data_table_header_row {
1.389 albertel 9161: return '<tr class="LC_header_row">'."\n";;
1.367 www 9162: }
9163:
9164: sub end_data_table_header_row {
1.389 albertel 9165: return '</tr>'."\n";;
1.367 www 9166: }
1.890 droeschl 9167:
9168: sub data_table_caption {
9169: my $caption = shift;
9170: return "<caption class=\"LC_caption\">$caption</caption>";
9171: }
1.347 albertel 9172: }
9173:
1.548 albertel 9174: =pod
9175:
9176: =item * &inhibit_menu_check($arg)
9177:
9178: Checks for a inhibitmenu state and generates output to preserve it
9179:
9180: Inputs: $arg - can be any of
9181: - undef - in which case the return value is a string
9182: to add into arguments list of a uri
9183: - 'input' - in which case the return value is a HTML
9184: <form> <input> field of type hidden to
9185: preserve the value
9186: - a url - in which case the return value is the url with
9187: the neccesary cgi args added to preserve the
9188: inhibitmenu state
9189: - a ref to a url - no return value, but the string is
9190: updated to include the neccessary cgi
9191: args to preserve the inhibitmenu state
9192:
9193: =cut
9194:
9195: sub inhibit_menu_check {
9196: my ($arg) = @_;
9197: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9198: if ($arg eq 'input') {
9199: if ($env{'form.inhibitmenu'}) {
9200: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9201: } else {
9202: return
9203: }
9204: }
9205: if ($env{'form.inhibitmenu'}) {
9206: if (ref($arg)) {
9207: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9208: } elsif ($arg eq '') {
9209: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9210: } else {
9211: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9212: }
9213: }
9214: if (!ref($arg)) {
9215: return $arg;
9216: }
9217: }
9218:
1.251 albertel 9219: ###############################################
1.182 matthew 9220:
9221: =pod
9222:
1.549 albertel 9223: =back
9224:
9225: =head1 User Information Routines
9226:
9227: =over 4
9228:
1.405 albertel 9229: =item * &get_users_function()
1.182 matthew 9230:
9231: Used by &bodytag to determine the current users primary role.
9232: Returns either 'student','coordinator','admin', or 'author'.
9233:
9234: =cut
9235:
9236: ###############################################
9237: sub get_users_function {
1.815 tempelho 9238: my $function = 'norole';
1.818 tempelho 9239: if ($env{'request.role'}=~/^(st)/) {
9240: $function='student';
9241: }
1.907 raeburn 9242: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9243: $function='coordinator';
9244: }
1.258 albertel 9245: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9246: $function='admin';
9247: }
1.826 bisitz 9248: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9249: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9250: $function='author';
9251: }
9252: return $function;
1.54 www 9253: }
1.99 www 9254:
9255: ###############################################
9256:
1.233 raeburn 9257: =pod
9258:
1.821 raeburn 9259: =item * &show_course()
9260:
9261: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9262: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9263:
9264: Inputs:
9265: None
9266:
9267: Outputs:
9268: Scalar: 1 if 'Course' to be used, 0 otherwise.
9269:
9270: =cut
9271:
9272: ###############################################
9273: sub show_course {
9274: my $course = !$env{'user.adv'};
9275: if (!$env{'user.adv'}) {
9276: foreach my $env (keys(%env)) {
9277: next if ($env !~ m/^user\.priv\./);
9278: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9279: $course = 0;
9280: last;
9281: }
9282: }
9283: }
9284: return $course;
9285: }
9286:
9287: ###############################################
9288:
9289: =pod
9290:
1.542 raeburn 9291: =item * &check_user_status()
1.274 raeburn 9292:
9293: Determines current status of supplied role for a
9294: specific user. Roles can be active, previous or future.
9295:
9296: Inputs:
9297: user's domain, user's username, course's domain,
1.375 raeburn 9298: course's number, optional section ID.
1.274 raeburn 9299:
9300: Outputs:
9301: role status: active, previous or future.
9302:
9303: =cut
9304:
9305: sub check_user_status {
1.412 raeburn 9306: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9307: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9308: my @uroles = keys(%userinfo);
1.274 raeburn 9309: my $srchstr;
9310: my $active_chk = 'none';
1.412 raeburn 9311: my $now = time;
1.274 raeburn 9312: if (@uroles > 0) {
1.908 raeburn 9313: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9314: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9315: } else {
1.412 raeburn 9316: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9317: }
9318: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9319: my $role_end = 0;
9320: my $role_start = 0;
9321: $active_chk = 'active';
1.412 raeburn 9322: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9323: $role_end = $1;
9324: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9325: $role_start = $1;
1.274 raeburn 9326: }
9327: }
9328: if ($role_start > 0) {
1.412 raeburn 9329: if ($now < $role_start) {
1.274 raeburn 9330: $active_chk = 'future';
9331: }
9332: }
9333: if ($role_end > 0) {
1.412 raeburn 9334: if ($now > $role_end) {
1.274 raeburn 9335: $active_chk = 'previous';
9336: }
9337: }
9338: }
9339: }
9340: return $active_chk;
9341: }
9342:
9343: ###############################################
9344:
9345: =pod
9346:
1.405 albertel 9347: =item * &get_sections()
1.233 raeburn 9348:
9349: Determines all the sections for a course including
9350: sections with students and sections containing other roles.
1.419 raeburn 9351: Incoming parameters:
9352:
9353: 1. domain
9354: 2. course number
9355: 3. reference to array containing roles for which sections should
9356: be gathered (optional).
9357: 4. reference to array containing status types for which sections
9358: should be gathered (optional).
9359:
9360: If the third argument is undefined, sections are gathered for any role.
9361: If the fourth argument is undefined, sections are gathered for any status.
9362: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9363:
1.374 raeburn 9364: Returns section hash (keys are section IDs, values are
9365: number of users in each section), subject to the
1.419 raeburn 9366: optional roles filter, optional status filter
1.233 raeburn 9367:
9368: =cut
9369:
9370: ###############################################
9371: sub get_sections {
1.419 raeburn 9372: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9373: if (!defined($cdom) || !defined($cnum)) {
9374: my $cid = $env{'request.course.id'};
9375:
9376: return if (!defined($cid));
9377:
9378: $cdom = $env{'course.'.$cid.'.domain'};
9379: $cnum = $env{'course.'.$cid.'.num'};
9380: }
9381:
9382: my %sectioncount;
1.419 raeburn 9383: my $now = time;
1.240 albertel 9384:
1.1075.2.33 raeburn 9385: my $check_students = 1;
9386: my $only_students = 0;
9387: if (ref($possible_roles) eq 'ARRAY') {
9388: if (grep(/^st$/,@{$possible_roles})) {
9389: if (@{$possible_roles} == 1) {
9390: $only_students = 1;
9391: }
9392: } else {
9393: $check_students = 0;
9394: }
9395: }
9396:
9397: if ($check_students) {
1.276 albertel 9398: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9399: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9400: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9401: my $start_index = &Apache::loncoursedata::CL_START();
9402: my $end_index = &Apache::loncoursedata::CL_END();
9403: my $status;
1.366 albertel 9404: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9405: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9406: $data->[$status_index],
9407: $data->[$start_index],
9408: $data->[$end_index]);
9409: if ($stu_status eq 'Active') {
9410: $status = 'active';
9411: } elsif ($end < $now) {
9412: $status = 'previous';
9413: } elsif ($start > $now) {
9414: $status = 'future';
9415: }
9416: if ($section ne '-1' && $section !~ /^\s*$/) {
9417: if ((!defined($possible_status)) || (($status ne '') &&
9418: (grep/^\Q$status\E$/,@{$possible_status}))) {
9419: $sectioncount{$section}++;
9420: }
1.240 albertel 9421: }
9422: }
9423: }
1.1075.2.33 raeburn 9424: if ($only_students) {
9425: return %sectioncount;
9426: }
1.240 albertel 9427: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9428: foreach my $user (sort(keys(%courseroles))) {
9429: if ($user !~ /^(\w{2})/) { next; }
9430: my ($role) = ($user =~ /^(\w{2})/);
9431: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9432: my ($section,$status);
1.240 albertel 9433: if ($role eq 'cr' &&
9434: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9435: $section=$1;
9436: }
9437: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9438: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9439: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9440: if ($end == -1 && $start == -1) {
9441: next; #deleted role
9442: }
9443: if (!defined($possible_status)) {
9444: $sectioncount{$section}++;
9445: } else {
9446: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9447: $status = 'active';
9448: } elsif ($end < $now) {
9449: $status = 'future';
9450: } elsif ($start > $now) {
9451: $status = 'previous';
9452: }
9453: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9454: $sectioncount{$section}++;
9455: }
9456: }
1.233 raeburn 9457: }
1.366 albertel 9458: return %sectioncount;
1.233 raeburn 9459: }
9460:
1.274 raeburn 9461: ###############################################
1.294 raeburn 9462:
9463: =pod
1.405 albertel 9464:
9465: =item * &get_course_users()
9466:
1.275 raeburn 9467: Retrieves usernames:domains for users in the specified course
9468: with specific role(s), and access status.
9469:
9470: Incoming parameters:
1.277 albertel 9471: 1. course domain
9472: 2. course number
9473: 3. access status: users must have - either active,
1.275 raeburn 9474: previous, future, or all.
1.277 albertel 9475: 4. reference to array of permissible roles
1.288 raeburn 9476: 5. reference to array of section restrictions (optional)
9477: 6. reference to results object (hash of hashes).
9478: 7. reference to optional userdata hash
1.609 raeburn 9479: 8. reference to optional statushash
1.630 raeburn 9480: 9. flag if privileged users (except those set to unhide in
9481: course settings) should be excluded
1.609 raeburn 9482: Keys of top level results hash are roles.
1.275 raeburn 9483: Keys of inner hashes are username:domain, with
9484: values set to access type.
1.288 raeburn 9485: Optional userdata hash returns an array with arguments in the
9486: same order as loncoursedata::get_classlist() for student data.
9487:
1.609 raeburn 9488: Optional statushash returns
9489:
1.288 raeburn 9490: Entries for end, start, section and status are blank because
9491: of the possibility of multiple values for non-student roles.
9492:
1.275 raeburn 9493: =cut
1.405 albertel 9494:
1.275 raeburn 9495: ###############################################
1.405 albertel 9496:
1.275 raeburn 9497: sub get_course_users {
1.630 raeburn 9498: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9499: my %idx = ();
1.419 raeburn 9500: my %seclists;
1.288 raeburn 9501:
9502: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9503: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9504: $idx{end} = &Apache::loncoursedata::CL_END();
9505: $idx{start} = &Apache::loncoursedata::CL_START();
9506: $idx{id} = &Apache::loncoursedata::CL_ID();
9507: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9508: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9509: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9510:
1.290 albertel 9511: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9512: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9513: my $now = time;
1.277 albertel 9514: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9515: my $match = 0;
1.412 raeburn 9516: my $secmatch = 0;
1.419 raeburn 9517: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9518: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9519: if ($section eq '') {
9520: $section = 'none';
9521: }
1.291 albertel 9522: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9523: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9524: $secmatch = 1;
9525: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9526: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9527: $secmatch = 1;
9528: }
9529: } else {
1.419 raeburn 9530: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9531: $secmatch = 1;
9532: }
1.290 albertel 9533: }
1.412 raeburn 9534: if (!$secmatch) {
9535: next;
9536: }
1.419 raeburn 9537: }
1.275 raeburn 9538: if (defined($$types{'active'})) {
1.288 raeburn 9539: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9540: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9541: $match = 1;
1.275 raeburn 9542: }
9543: }
9544: if (defined($$types{'previous'})) {
1.609 raeburn 9545: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9546: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9547: $match = 1;
1.275 raeburn 9548: }
9549: }
9550: if (defined($$types{'future'})) {
1.609 raeburn 9551: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9552: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9553: $match = 1;
1.275 raeburn 9554: }
9555: }
1.609 raeburn 9556: if ($match) {
9557: push(@{$seclists{$student}},$section);
9558: if (ref($userdata) eq 'HASH') {
9559: $$userdata{$student} = $$classlist{$student};
9560: }
9561: if (ref($statushash) eq 'HASH') {
9562: $statushash->{$student}{'st'}{$section} = $status;
9563: }
1.288 raeburn 9564: }
1.275 raeburn 9565: }
9566: }
1.412 raeburn 9567: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9568: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9569: my $now = time;
1.609 raeburn 9570: my %displaystatus = ( previous => 'Expired',
9571: active => 'Active',
9572: future => 'Future',
9573: );
1.1075.2.36 raeburn 9574: my (%nothide,@possdoms);
1.630 raeburn 9575: if ($hidepriv) {
9576: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9577: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9578: if ($user !~ /:/) {
9579: $nothide{join(':',split(/[\@]/,$user))}=1;
9580: } else {
9581: $nothide{$user} = 1;
9582: }
9583: }
1.1075.2.36 raeburn 9584: my @possdoms = ($cdom);
9585: if ($coursehash{'checkforpriv'}) {
9586: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9587: }
1.630 raeburn 9588: }
1.439 raeburn 9589: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9590: my $match = 0;
1.412 raeburn 9591: my $secmatch = 0;
1.439 raeburn 9592: my $status;
1.412 raeburn 9593: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9594: $user =~ s/:$//;
1.439 raeburn 9595: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9596: if ($end == -1 || $start == -1) {
9597: next;
9598: }
9599: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9600: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9601: my ($uname,$udom) = split(/:/,$user);
9602: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9603: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9604: $secmatch = 1;
9605: } elsif ($usec eq '') {
1.420 albertel 9606: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9607: $secmatch = 1;
9608: }
9609: } else {
9610: if (grep(/^\Q$usec\E$/,@{$sections})) {
9611: $secmatch = 1;
9612: }
9613: }
9614: if (!$secmatch) {
9615: next;
9616: }
1.288 raeburn 9617: }
1.419 raeburn 9618: if ($usec eq '') {
9619: $usec = 'none';
9620: }
1.275 raeburn 9621: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9622: if ($hidepriv) {
1.1075.2.36 raeburn 9623: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9624: (!$nothide{$uname.':'.$udom})) {
9625: next;
9626: }
9627: }
1.503 raeburn 9628: if ($end > 0 && $end < $now) {
1.439 raeburn 9629: $status = 'previous';
9630: } elsif ($start > $now) {
9631: $status = 'future';
9632: } else {
9633: $status = 'active';
9634: }
1.277 albertel 9635: foreach my $type (keys(%{$types})) {
1.275 raeburn 9636: if ($status eq $type) {
1.420 albertel 9637: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9638: push(@{$$users{$role}{$user}},$type);
9639: }
1.288 raeburn 9640: $match = 1;
9641: }
9642: }
1.419 raeburn 9643: if (($match) && (ref($userdata) eq 'HASH')) {
9644: if (!exists($$userdata{$uname.':'.$udom})) {
9645: &get_user_info($udom,$uname,\%idx,$userdata);
9646: }
1.420 albertel 9647: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9648: push(@{$seclists{$uname.':'.$udom}},$usec);
9649: }
1.609 raeburn 9650: if (ref($statushash) eq 'HASH') {
9651: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9652: }
1.275 raeburn 9653: }
9654: }
9655: }
9656: }
1.290 albertel 9657: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9658: if ((defined($cdom)) && (defined($cnum))) {
9659: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9660: if ( defined($csettings{'internal.courseowner'}) ) {
9661: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9662: next if ($owner eq '');
9663: my ($ownername,$ownerdom);
9664: if ($owner =~ /^([^:]+):([^:]+)$/) {
9665: $ownername = $1;
9666: $ownerdom = $2;
9667: } else {
9668: $ownername = $owner;
9669: $ownerdom = $cdom;
9670: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9671: }
9672: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9673: if (defined($userdata) &&
1.609 raeburn 9674: !exists($$userdata{$owner})) {
9675: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9676: if (!grep(/^none$/,@{$seclists{$owner}})) {
9677: push(@{$seclists{$owner}},'none');
9678: }
9679: if (ref($statushash) eq 'HASH') {
9680: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9681: }
1.290 albertel 9682: }
1.279 raeburn 9683: }
9684: }
9685: }
1.419 raeburn 9686: foreach my $user (keys(%seclists)) {
9687: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9688: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9689: }
1.275 raeburn 9690: }
9691: return;
9692: }
9693:
1.288 raeburn 9694: sub get_user_info {
9695: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9696: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9697: &plainname($uname,$udom,'lastname');
1.291 albertel 9698: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9699: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9700: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9701: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9702: return;
9703: }
1.275 raeburn 9704:
1.472 raeburn 9705: ###############################################
9706:
9707: =pod
9708:
9709: =item * &get_user_quota()
9710:
1.1075.2.41 raeburn 9711: Retrieves quota assigned for storage of user files.
9712: Default is to report quota for portfolio files.
1.472 raeburn 9713:
9714: Incoming parameters:
9715: 1. user's username
9716: 2. user's domain
1.1075.2.41 raeburn 9717: 3. quota name - portfolio, author, or course
9718: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9719: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9720: course
1.472 raeburn 9721:
9722: Returns:
1.1075.2.58 raeburn 9723: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9724: 2. (Optional) Type of setting: custom or default
9725: (individually assigned or default for user's
9726: institutional status).
9727: 3. (Optional) - User's institutional status (e.g., faculty, staff
9728: or student - types as defined in localenroll::inst_usertypes
9729: for user's domain, which determines default quota for user.
9730: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9731:
9732: If a value has been stored in the user's environment,
1.536 raeburn 9733: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9734: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9735:
9736: =cut
9737:
9738: ###############################################
9739:
9740:
9741: sub get_user_quota {
1.1075.2.42 raeburn 9742: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9743: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9744: if (!defined($udom)) {
9745: $udom = $env{'user.domain'};
9746: }
9747: if (!defined($uname)) {
9748: $uname = $env{'user.name'};
9749: }
9750: if (($udom eq '' || $uname eq '') ||
9751: ($udom eq 'public') && ($uname eq 'public')) {
9752: $quota = 0;
1.536 raeburn 9753: $quotatype = 'default';
9754: $defquota = 0;
1.472 raeburn 9755: } else {
1.536 raeburn 9756: my $inststatus;
1.1075.2.41 raeburn 9757: if ($quotaname eq 'course') {
9758: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9759: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9760: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9761: } else {
9762: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9763: $quota = $cenv{'internal.uploadquota'};
9764: }
1.536 raeburn 9765: } else {
1.1075.2.41 raeburn 9766: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9767: if ($quotaname eq 'author') {
9768: $quota = $env{'environment.authorquota'};
9769: } else {
9770: $quota = $env{'environment.portfolioquota'};
9771: }
9772: $inststatus = $env{'environment.inststatus'};
9773: } else {
9774: my %userenv =
9775: &Apache::lonnet::get('environment',['portfolioquota',
9776: 'authorquota','inststatus'],$udom,$uname);
9777: my ($tmp) = keys(%userenv);
9778: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9779: if ($quotaname eq 'author') {
9780: $quota = $userenv{'authorquota'};
9781: } else {
9782: $quota = $userenv{'portfolioquota'};
9783: }
9784: $inststatus = $userenv{'inststatus'};
9785: } else {
9786: undef(%userenv);
9787: }
9788: }
9789: }
9790: if ($quota eq '' || wantarray) {
9791: if ($quotaname eq 'course') {
9792: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9793: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9794: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9795: $defquota = $domdefs{$crstype.'quota'};
9796: }
9797: if ($defquota eq '') {
9798: $defquota = 500;
9799: }
1.1075.2.41 raeburn 9800: } else {
9801: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9802: }
9803: if ($quota eq '') {
9804: $quota = $defquota;
9805: $quotatype = 'default';
9806: } else {
9807: $quotatype = 'custom';
9808: }
1.472 raeburn 9809: }
9810: }
1.536 raeburn 9811: if (wantarray) {
9812: return ($quota,$quotatype,$settingstatus,$defquota);
9813: } else {
9814: return $quota;
9815: }
1.472 raeburn 9816: }
9817:
9818: ###############################################
9819:
9820: =pod
9821:
9822: =item * &default_quota()
9823:
1.536 raeburn 9824: Retrieves default quota assigned for storage of user portfolio files,
9825: given an (optional) user's institutional status.
1.472 raeburn 9826:
9827: Incoming parameters:
1.1075.2.42 raeburn 9828:
1.472 raeburn 9829: 1. domain
1.536 raeburn 9830: 2. (Optional) institutional status(es). This is a : separated list of
9831: status types (e.g., faculty, staff, student etc.)
9832: which apply to the user for whom the default is being retrieved.
9833: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9834: default quota will be returned.
9835: 3. quota name - portfolio, author, or course
9836: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9837:
9838: Returns:
1.1075.2.42 raeburn 9839:
1.1075.2.58 raeburn 9840: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9841: 2. (Optional) institutional type which determined the value of the
9842: default quota.
1.472 raeburn 9843:
9844: If a value has been stored in the domain's configuration db,
9845: it will return that, otherwise it returns 20 (for backwards
9846: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9847: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9848:
1.536 raeburn 9849: If the user's status includes multiple types (e.g., staff and student),
9850: the largest default quota which applies to the user determines the
9851: default quota returned.
9852:
1.472 raeburn 9853: =cut
9854:
9855: ###############################################
9856:
9857:
9858: sub default_quota {
1.1075.2.41 raeburn 9859: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9860: my ($defquota,$settingstatus);
9861: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9862: ['quotas'],$udom);
1.1075.2.41 raeburn 9863: my $key = 'defaultquota';
9864: if ($quotaname eq 'author') {
9865: $key = 'authorquota';
9866: }
1.622 raeburn 9867: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9868: if ($inststatus ne '') {
1.765 raeburn 9869: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9870: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9871: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9872: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9873: if ($defquota eq '') {
1.1075.2.41 raeburn 9874: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9875: $settingstatus = $item;
1.1075.2.41 raeburn 9876: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9877: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9878: $settingstatus = $item;
9879: }
9880: }
1.1075.2.41 raeburn 9881: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9882: if ($quotahash{'quotas'}{$item} ne '') {
9883: if ($defquota eq '') {
9884: $defquota = $quotahash{'quotas'}{$item};
9885: $settingstatus = $item;
9886: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9887: $defquota = $quotahash{'quotas'}{$item};
9888: $settingstatus = $item;
9889: }
1.536 raeburn 9890: }
9891: }
9892: }
9893: }
9894: if ($defquota eq '') {
1.1075.2.41 raeburn 9895: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9896: $defquota = $quotahash{'quotas'}{$key}{'default'};
9897: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9898: $defquota = $quotahash{'quotas'}{'default'};
9899: }
1.536 raeburn 9900: $settingstatus = 'default';
1.1075.2.42 raeburn 9901: if ($defquota eq '') {
9902: if ($quotaname eq 'author') {
9903: $defquota = 500;
9904: }
9905: }
1.536 raeburn 9906: }
9907: } else {
9908: $settingstatus = 'default';
1.1075.2.41 raeburn 9909: if ($quotaname eq 'author') {
9910: $defquota = 500;
9911: } else {
9912: $defquota = 20;
9913: }
1.536 raeburn 9914: }
9915: if (wantarray) {
9916: return ($defquota,$settingstatus);
1.472 raeburn 9917: } else {
1.536 raeburn 9918: return $defquota;
1.472 raeburn 9919: }
9920: }
9921:
1.1075.2.41 raeburn 9922: ###############################################
9923:
9924: =pod
9925:
1.1075.2.42 raeburn 9926: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9927:
9928: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9929: of existing file within authoring space will cause quota for the authoring
9930: space to be exceeded.
9931:
9932: Same, if upload of a file directly to a course/community via Course Editor
9933: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9934:
1.1075.2.61 raeburn 9935: Inputs: 7
1.1075.2.42 raeburn 9936: 1. username or coursenum
1.1075.2.41 raeburn 9937: 2. domain
1.1075.2.42 raeburn 9938: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9939: 4. filename of file for which action is being requested
9940: 5. filesize (kB) of file
9941: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9942: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9943:
9944: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9945: otherwise return null.
9946:
1.1075.2.42 raeburn 9947: =back
9948:
1.1075.2.41 raeburn 9949: =cut
9950:
1.1075.2.42 raeburn 9951: sub excess_filesize_warning {
1.1075.2.59 raeburn 9952: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9953: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9954: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9955: if ($context eq 'author') {
9956: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9957: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9958: } else {
9959: foreach my $subdir ('docs','supplemental') {
9960: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9961: }
9962: }
1.1075.2.41 raeburn 9963: $disk_quota = int($disk_quota * 1000);
9964: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9965: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9966: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9967: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9968: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9969: $disk_quota,$current_disk_usage).
9970: '</p>';
9971: }
9972: return;
9973: }
9974:
9975: ###############################################
9976:
9977:
1.384 raeburn 9978: sub get_secgrprole_info {
9979: my ($cdom,$cnum,$needroles,$type) = @_;
9980: my %sections_count = &get_sections($cdom,$cnum);
9981: my @sections = (sort {$a <=> $b} keys(%sections_count));
9982: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9983: my @groups = sort(keys(%curr_groups));
9984: my $allroles = [];
9985: my $rolehash;
9986: my $accesshash = {
9987: active => 'Currently has access',
9988: future => 'Will have future access',
9989: previous => 'Previously had access',
9990: };
9991: if ($needroles) {
9992: $rolehash = {'all' => 'all'};
1.385 albertel 9993: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9994: if (&Apache::lonnet::error(%user_roles)) {
9995: undef(%user_roles);
9996: }
9997: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9998: my ($role)=split(/\:/,$item,2);
9999: if ($role eq 'cr') { next; }
10000: if ($role =~ /^cr/) {
10001: $$rolehash{$role} = (split('/',$role))[3];
10002: } else {
10003: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10004: }
10005: }
10006: foreach my $key (sort(keys(%{$rolehash}))) {
10007: push(@{$allroles},$key);
10008: }
10009: push (@{$allroles},'st');
10010: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10011: }
10012: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10013: }
10014:
1.555 raeburn 10015: sub user_picker {
1.1075.2.127 raeburn 10016: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10017: my $currdom = $dom;
1.1075.2.114 raeburn 10018: my @alldoms = &Apache::lonnet::all_domains();
10019: if (@alldoms == 1) {
10020: my %domsrch = &Apache::lonnet::get_dom('configuration',
10021: ['directorysrch'],$alldoms[0]);
10022: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10023: my $showdom = $domdesc;
10024: if ($showdom eq '') {
10025: $showdom = $dom;
10026: }
10027: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10028: if ((!$domsrch{'directorysrch'}{'available'}) &&
10029: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10030: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10031: }
10032: }
10033: }
1.555 raeburn 10034: my %curr_selected = (
10035: srchin => 'dom',
1.580 raeburn 10036: srchby => 'lastname',
1.555 raeburn 10037: );
10038: my $srchterm;
1.625 raeburn 10039: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10040: if ($srch->{'srchby'} ne '') {
10041: $curr_selected{'srchby'} = $srch->{'srchby'};
10042: }
10043: if ($srch->{'srchin'} ne '') {
10044: $curr_selected{'srchin'} = $srch->{'srchin'};
10045: }
10046: if ($srch->{'srchtype'} ne '') {
10047: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10048: }
10049: if ($srch->{'srchdomain'} ne '') {
10050: $currdom = $srch->{'srchdomain'};
10051: }
10052: $srchterm = $srch->{'srchterm'};
10053: }
1.1075.2.98 raeburn 10054: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10055: 'usr' => 'Search criteria',
1.563 raeburn 10056: 'doma' => 'Domain/institution to search',
1.558 albertel 10057: 'uname' => 'username',
10058: 'lastname' => 'last name',
1.555 raeburn 10059: 'lastfirst' => 'last name, first name',
1.558 albertel 10060: 'crs' => 'in this course',
1.576 raeburn 10061: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10062: 'alc' => 'all LON-CAPA',
1.573 raeburn 10063: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10064: 'exact' => 'is',
10065: 'contains' => 'contains',
1.569 raeburn 10066: 'begins' => 'begins with',
1.1075.2.98 raeburn 10067: );
10068: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10069: 'youm' => "You must include some text to search for.",
10070: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10071: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10072: 'yomc' => "You must choose a domain when using an institutional directory search.",
10073: 'ymcd' => "You must choose a domain when using a domain search.",
10074: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10075: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10076: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10077: );
1.1075.2.98 raeburn 10078: &html_escape(\%html_lt);
10079: &js_escape(\%js_lt);
1.1075.2.115 raeburn 10080: my $domform;
1.1075.2.126 raeburn 10081: my $allow_blank = 1;
1.1075.2.115 raeburn 10082: if ($fixeddom) {
1.1075.2.126 raeburn 10083: $allow_blank = 0;
10084: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 10085: } else {
1.1075.2.126 raeburn 10086: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 10087: }
1.563 raeburn 10088: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10089:
10090: my @srchins = ('crs','dom','alc','instd');
10091:
10092: foreach my $option (@srchins) {
10093: # FIXME 'alc' option unavailable until
10094: # loncreateuser::print_user_query_page()
10095: # has been completed.
10096: next if ($option eq 'alc');
1.880 raeburn 10097: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10098: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 10099: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10100: if ($curr_selected{'srchin'} eq $option) {
10101: $srchinsel .= '
1.1075.2.98 raeburn 10102: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10103: } else {
10104: $srchinsel .= '
1.1075.2.98 raeburn 10105: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10106: }
1.555 raeburn 10107: }
1.563 raeburn 10108: $srchinsel .= "\n </select>\n";
1.555 raeburn 10109:
10110: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10111: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10112: if ($curr_selected{'srchby'} eq $option) {
10113: $srchbysel .= '
1.1075.2.98 raeburn 10114: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10115: } else {
10116: $srchbysel .= '
1.1075.2.98 raeburn 10117: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10118: }
10119: }
10120: $srchbysel .= "\n </select>\n";
10121:
10122: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10123: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10124: if ($curr_selected{'srchtype'} eq $option) {
10125: $srchtypesel .= '
1.1075.2.98 raeburn 10126: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10127: } else {
10128: $srchtypesel .= '
1.1075.2.98 raeburn 10129: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10130: }
10131: }
10132: $srchtypesel .= "\n </select>\n";
10133:
1.558 albertel 10134: my ($newuserscript,$new_user_create);
1.994 raeburn 10135: my $context_dom = $env{'request.role.domain'};
10136: if ($context eq 'requestcrs') {
10137: if ($env{'form.coursedom'} ne '') {
10138: $context_dom = $env{'form.coursedom'};
10139: }
10140: }
1.556 raeburn 10141: if ($forcenewuser) {
1.576 raeburn 10142: if (ref($srch) eq 'HASH') {
1.994 raeburn 10143: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10144: if ($cancreate) {
10145: $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>';
10146: } else {
1.799 bisitz 10147: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10148: my %usertypetext = (
10149: official => 'institutional',
10150: unofficial => 'non-institutional',
10151: );
1.799 bisitz 10152: $new_user_create = '<p class="LC_warning">'
10153: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10154: .' '
10155: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10156: ,'<a href="'.$helplink.'">','</a>')
10157: .'</p><br />';
1.627 raeburn 10158: }
1.576 raeburn 10159: }
10160: }
10161:
1.556 raeburn 10162: $newuserscript = <<"ENDSCRIPT";
10163:
1.570 raeburn 10164: function setSearch(createnew,callingForm) {
1.556 raeburn 10165: if (createnew == 1) {
1.570 raeburn 10166: for (var i=0; i<callingForm.srchby.length; i++) {
10167: if (callingForm.srchby.options[i].value == 'uname') {
10168: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10169: }
10170: }
1.570 raeburn 10171: for (var i=0; i<callingForm.srchin.length; i++) {
10172: if ( callingForm.srchin.options[i].value == 'dom') {
10173: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10174: }
10175: }
1.570 raeburn 10176: for (var i=0; i<callingForm.srchtype.length; i++) {
10177: if (callingForm.srchtype.options[i].value == 'exact') {
10178: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10179: }
10180: }
1.570 raeburn 10181: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10182: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10183: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10184: }
10185: }
10186: }
10187: }
10188: ENDSCRIPT
1.558 albertel 10189:
1.556 raeburn 10190: }
10191:
1.555 raeburn 10192: my $output = <<"END_BLOCK";
1.556 raeburn 10193: <script type="text/javascript">
1.824 bisitz 10194: // <![CDATA[
1.570 raeburn 10195: function validateEntry(callingForm) {
1.558 albertel 10196:
1.556 raeburn 10197: var checkok = 1;
1.558 albertel 10198: var srchin;
1.570 raeburn 10199: for (var i=0; i<callingForm.srchin.length; i++) {
10200: if ( callingForm.srchin[i].checked ) {
10201: srchin = callingForm.srchin[i].value;
1.558 albertel 10202: }
10203: }
10204:
1.570 raeburn 10205: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10206: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10207: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10208: var srchterm = callingForm.srchterm.value;
10209: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10210: var msg = "";
10211:
10212: if (srchterm == "") {
10213: checkok = 0;
1.1075.2.98 raeburn 10214: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10215: }
10216:
1.569 raeburn 10217: if (srchtype== 'begins') {
10218: if (srchterm.length < 2) {
10219: checkok = 0;
1.1075.2.98 raeburn 10220: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10221: }
10222: }
10223:
1.556 raeburn 10224: if (srchtype== 'contains') {
10225: if (srchterm.length < 3) {
10226: checkok = 0;
1.1075.2.98 raeburn 10227: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10228: }
10229: }
10230: if (srchin == 'instd') {
10231: if (srchdomain == '') {
10232: checkok = 0;
1.1075.2.98 raeburn 10233: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10234: }
10235: }
10236: if (srchin == 'dom') {
10237: if (srchdomain == '') {
10238: checkok = 0;
1.1075.2.98 raeburn 10239: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10240: }
10241: }
10242: if (srchby == 'lastfirst') {
10243: if (srchterm.indexOf(",") == -1) {
10244: checkok = 0;
1.1075.2.98 raeburn 10245: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10246: }
10247: if (srchterm.indexOf(",") == srchterm.length -1) {
10248: checkok = 0;
1.1075.2.98 raeburn 10249: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10250: }
10251: }
10252: if (checkok == 0) {
1.1075.2.98 raeburn 10253: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10254: return;
10255: }
10256: if (checkok == 1) {
1.570 raeburn 10257: callingForm.submit();
1.556 raeburn 10258: }
10259: }
10260:
10261: $newuserscript
10262:
1.824 bisitz 10263: // ]]>
1.556 raeburn 10264: </script>
1.558 albertel 10265:
10266: $new_user_create
10267:
1.555 raeburn 10268: END_BLOCK
1.558 albertel 10269:
1.876 raeburn 10270: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 10271: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10272: $domform.
10273: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 10274: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10275: $srchbysel.
10276: $srchtypesel.
10277: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10278: $srchinsel.
10279: &Apache::lonhtmlcommon::row_closure(1).
10280: &Apache::lonhtmlcommon::end_pick_box().
10281: '<br />';
1.1075.2.114 raeburn 10282: return ($output,1);
1.555 raeburn 10283: }
10284:
1.612 raeburn 10285: sub user_rule_check {
1.615 raeburn 10286: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10287: my ($response,%inst_response);
1.612 raeburn 10288: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10289: if (keys(%{$usershash}) > 1) {
10290: my (%by_username,%by_id,%userdoms);
10291: my $checkid;
1.612 raeburn 10292: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10293: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10294: $checkid = 1;
10295: }
10296: }
10297: foreach my $user (keys(%{$usershash})) {
10298: my ($uname,$udom) = split(/:/,$user);
10299: if ($checkid) {
10300: if (ref($usershash->{$user}) eq 'HASH') {
10301: if ($usershash->{$user}->{'id'} ne '') {
10302: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10303: $userdoms{$udom} = 1;
10304: if (ref($inst_results) eq 'HASH') {
10305: $inst_results->{$uname.':'.$udom} = {};
10306: }
10307: }
10308: }
10309: } else {
10310: $by_username{$udom}{$uname} = 1;
10311: $userdoms{$udom} = 1;
10312: if (ref($inst_results) eq 'HASH') {
10313: $inst_results->{$uname.':'.$udom} = {};
10314: }
10315: }
10316: }
10317: foreach my $udom (keys(%userdoms)) {
10318: if (!$got_rules->{$udom}) {
10319: my %domconfig = &Apache::lonnet::get_dom('configuration',
10320: ['usercreation'],$udom);
10321: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10322: foreach my $item ('username','id') {
10323: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10324: $$curr_rules{$udom}{$item} =
10325: $domconfig{'usercreation'}{$item.'_rule'};
10326: }
10327: }
10328: }
10329: $got_rules->{$udom} = 1;
10330: }
10331: }
10332: if ($checkid) {
10333: foreach my $udom (keys(%by_id)) {
10334: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10335: if ($outcome eq 'ok') {
10336: foreach my $id (keys(%{$by_id{$udom}})) {
10337: my $uname = $by_id{$udom}{$id};
10338: $inst_response{$uname.':'.$udom} = $outcome;
10339: }
10340: if (ref($results) eq 'HASH') {
10341: foreach my $uname (keys(%{$results})) {
10342: if (exists($inst_response{$uname.':'.$udom})) {
10343: $inst_response{$uname.':'.$udom} = $outcome;
10344: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10345: }
10346: }
10347: }
10348: }
1.612 raeburn 10349: }
1.615 raeburn 10350: } else {
1.1075.2.99 raeburn 10351: foreach my $udom (keys(%by_username)) {
10352: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10353: if ($outcome eq 'ok') {
10354: foreach my $uname (keys(%{$by_username{$udom}})) {
10355: $inst_response{$uname.':'.$udom} = $outcome;
10356: }
10357: if (ref($results) eq 'HASH') {
10358: foreach my $uname (keys(%{$results})) {
10359: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10360: }
10361: }
10362: }
10363: }
1.612 raeburn 10364: }
1.1075.2.99 raeburn 10365: } elsif (keys(%{$usershash}) == 1) {
10366: my $user = (keys(%{$usershash}))[0];
10367: my ($uname,$udom) = split(/:/,$user);
10368: if (($udom ne '') && ($uname ne '')) {
10369: if (ref($usershash->{$user}) eq 'HASH') {
10370: if (ref($checks) eq 'HASH') {
10371: if (defined($checks->{'username'})) {
10372: ($inst_response{$user},%{$inst_results->{$user}}) =
10373: &Apache::lonnet::get_instuser($udom,$uname);
10374: } elsif (defined($checks->{'id'})) {
10375: if ($usershash->{$user}->{'id'} ne '') {
10376: ($inst_response{$user},%{$inst_results->{$user}}) =
10377: &Apache::lonnet::get_instuser($udom,undef,
10378: $usershash->{$user}->{'id'});
10379: } else {
10380: ($inst_response{$user},%{$inst_results->{$user}}) =
10381: &Apache::lonnet::get_instuser($udom,$uname);
10382: }
10383: }
10384: } else {
10385: ($inst_response{$user},%{$inst_results->{$user}}) =
10386: &Apache::lonnet::get_instuser($udom,$uname);
10387: return;
10388: }
10389: if (!$got_rules->{$udom}) {
10390: my %domconfig = &Apache::lonnet::get_dom('configuration',
10391: ['usercreation'],$udom);
10392: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10393: foreach my $item ('username','id') {
10394: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10395: $$curr_rules{$udom}{$item} =
10396: $domconfig{'usercreation'}{$item.'_rule'};
10397: }
10398: }
1.585 raeburn 10399: }
1.1075.2.99 raeburn 10400: $got_rules->{$udom} = 1;
1.585 raeburn 10401: }
10402: }
1.1075.2.99 raeburn 10403: } else {
10404: return;
10405: }
10406: } else {
10407: return;
10408: }
10409: foreach my $user (keys(%{$usershash})) {
10410: my ($uname,$udom) = split(/:/,$user);
10411: next if (($udom eq '') || ($uname eq ''));
10412: my $id;
10413: if (ref($inst_results) eq 'HASH') {
10414: if (ref($inst_results->{$user}) eq 'HASH') {
10415: $id = $inst_results->{$user}->{'id'};
10416: }
10417: }
10418: if ($id eq '') {
10419: if (ref($usershash->{$user})) {
10420: $id = $usershash->{$user}->{'id'};
10421: }
1.585 raeburn 10422: }
1.612 raeburn 10423: foreach my $item (keys(%{$checks})) {
10424: if (ref($$curr_rules{$udom}) eq 'HASH') {
10425: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10426: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10427: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10428: $$curr_rules{$udom}{$item});
1.612 raeburn 10429: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10430: if ($rule_check{$rule}) {
10431: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10432: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10433: if (ref($inst_results) eq 'HASH') {
10434: if (ref($inst_results->{$user}) eq 'HASH') {
10435: if (keys(%{$inst_results->{$user}}) == 0) {
10436: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10437: } elsif ($item eq 'id') {
10438: if ($inst_results->{$user}->{'id'} eq '') {
10439: $$alerts{$item}{$udom}{$uname} = 1;
10440: }
1.615 raeburn 10441: }
1.612 raeburn 10442: }
10443: }
1.615 raeburn 10444: }
10445: last;
1.585 raeburn 10446: }
10447: }
10448: }
10449: }
10450: }
10451: }
10452: }
10453: }
1.612 raeburn 10454: return;
10455: }
10456:
10457: sub user_rule_formats {
10458: my ($domain,$domdesc,$curr_rules,$check) = @_;
10459: my %text = (
10460: 'username' => 'Usernames',
10461: 'id' => 'IDs',
10462: );
10463: my $output;
10464: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10465: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10466: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10467: $output = '<br />'.
10468: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10469: '<span class="LC_cusr_emph">','</span>',$domdesc).
10470: ' <ul>';
1.612 raeburn 10471: foreach my $rule (@{$ruleorder}) {
10472: if (ref($curr_rules) eq 'ARRAY') {
10473: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10474: if (ref($rules->{$rule}) eq 'HASH') {
10475: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10476: $rules->{$rule}{'desc'}.'</li>';
10477: }
10478: }
10479: }
10480: }
10481: $output .= '</ul>';
10482: }
10483: }
10484: return $output;
10485: }
10486:
10487: sub instrule_disallow_msg {
1.615 raeburn 10488: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10489: my $response;
10490: my %text = (
10491: item => 'username',
10492: items => 'usernames',
10493: match => 'matches',
10494: do => 'does',
10495: action => 'a username',
10496: one => 'one',
10497: );
10498: if ($count > 1) {
10499: $text{'item'} = 'usernames';
10500: $text{'match'} ='match';
10501: $text{'do'} = 'do';
10502: $text{'action'} = 'usernames',
10503: $text{'one'} = 'ones';
10504: }
10505: if ($checkitem eq 'id') {
10506: $text{'items'} = 'IDs';
10507: $text{'item'} = 'ID';
10508: $text{'action'} = 'an ID';
1.615 raeburn 10509: if ($count > 1) {
10510: $text{'item'} = 'IDs';
10511: $text{'action'} = 'IDs';
10512: }
1.612 raeburn 10513: }
1.674 bisitz 10514: $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 10515: if ($mode eq 'upload') {
10516: if ($checkitem eq 'username') {
10517: $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'}.");
10518: } elsif ($checkitem eq 'id') {
1.674 bisitz 10519: $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 10520: }
1.669 raeburn 10521: } elsif ($mode eq 'selfcreate') {
10522: if ($checkitem eq 'id') {
10523: $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.");
10524: }
1.615 raeburn 10525: } else {
10526: if ($checkitem eq 'username') {
10527: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10528: } elsif ($checkitem eq 'id') {
10529: $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.");
10530: }
1.612 raeburn 10531: }
10532: return $response;
1.585 raeburn 10533: }
10534:
1.624 raeburn 10535: sub personal_data_fieldtitles {
10536: my %fieldtitles = &Apache::lonlocal::texthash (
10537: id => 'Student/Employee ID',
10538: permanentemail => 'E-mail address',
10539: lastname => 'Last Name',
10540: firstname => 'First Name',
10541: middlename => 'Middle Name',
10542: generation => 'Generation',
10543: gen => 'Generation',
1.765 raeburn 10544: inststatus => 'Affiliation',
1.624 raeburn 10545: );
10546: return %fieldtitles;
10547: }
10548:
1.642 raeburn 10549: sub sorted_inst_types {
10550: my ($dom) = @_;
1.1075.2.70 raeburn 10551: my ($usertypes,$order);
10552: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10553: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10554: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10555: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10556: } else {
10557: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10558: }
1.642 raeburn 10559: my $othertitle = &mt('All users');
10560: if ($env{'request.course.id'}) {
1.668 raeburn 10561: $othertitle = &mt('Any users');
1.642 raeburn 10562: }
10563: my @types;
10564: if (ref($order) eq 'ARRAY') {
10565: @types = @{$order};
10566: }
10567: if (@types == 0) {
10568: if (ref($usertypes) eq 'HASH') {
10569: @types = sort(keys(%{$usertypes}));
10570: }
10571: }
10572: if (keys(%{$usertypes}) > 0) {
10573: $othertitle = &mt('Other users');
10574: }
10575: return ($othertitle,$usertypes,\@types);
10576: }
10577:
1.645 raeburn 10578: sub get_institutional_codes {
1.1075.2.157 raeburn 10579: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 10580: # Get complete list of course sections to update
10581: my @currsections = ();
10582: my @currxlists = ();
1.1075.2.157 raeburn 10583: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 10584: my $coursecode = $$settings{'internal.coursecode'};
1.1075.2.157 raeburn 10585: my $crskey = $crs.':'.$coursecode;
10586: @{$unclutteredsec{$crskey}} = ();
10587: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 10588:
10589: if ($$settings{'internal.sectionnums'} ne '') {
10590: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10591: }
10592:
10593: if ($$settings{'internal.crosslistings'} ne '') {
10594: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10595: }
10596:
10597: if (@currxlists > 0) {
1.1075.2.157 raeburn 10598: foreach my $xl (@currxlists) {
10599: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 10600: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10601: push(@{$allcourses},$1);
1.645 raeburn 10602: $$LC_code{$1} = $2;
10603: }
10604: }
10605: }
10606: }
1.1075.2.157 raeburn 10607:
1.645 raeburn 10608: if (@currsections > 0) {
1.1075.2.157 raeburn 10609: foreach my $sec (@currsections) {
10610: if ($sec =~ m/^(\w+):(\w*)$/ ) {
10611: my $instsec = $1;
1.645 raeburn 10612: my $lc_sec = $2;
1.1075.2.157 raeburn 10613: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
10614: push(@{$unclutteredsec{$crskey}},$instsec);
10615: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
10616: }
10617: }
10618: }
10619: }
10620:
10621: if (@{$unclutteredsec{$crskey}} > 0) {
10622: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
10623: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
10624: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
10625: my $sec = $coursecode.$formattedsec{$crskey}[$i];
10626: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1075.2.119 raeburn 10627: push(@{$allcourses},$sec);
1.1075.2.157 raeburn 10628: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 10629: }
10630: }
10631: }
10632: }
10633: return;
10634: }
10635:
1.971 raeburn 10636: sub get_standard_codeitems {
10637: return ('Year','Semester','Department','Number','Section');
10638: }
10639:
1.112 bowersj2 10640: =pod
10641:
1.780 raeburn 10642: =head1 Slot Helpers
10643:
10644: =over 4
10645:
10646: =item * sorted_slots()
10647:
1.1040 raeburn 10648: Sorts an array of slot names in order of an optional sort key,
10649: default sort is by slot start time (earliest first).
1.780 raeburn 10650:
10651: Inputs:
10652:
10653: =over 4
10654:
10655: slotsarr - Reference to array of unsorted slot names.
10656:
10657: slots - Reference to hash of hash, where outer hash keys are slot names.
10658:
1.1040 raeburn 10659: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10660:
1.549 albertel 10661: =back
10662:
1.780 raeburn 10663: Returns:
10664:
10665: =over 4
10666:
1.1040 raeburn 10667: sorted - An array of slot names sorted by a specified sort key
10668: (default sort key is start time of the slot).
1.780 raeburn 10669:
10670: =back
10671:
10672: =cut
10673:
10674:
10675: sub sorted_slots {
1.1040 raeburn 10676: my ($slotsarr,$slots,$sortkey) = @_;
10677: if ($sortkey eq '') {
10678: $sortkey = 'starttime';
10679: }
1.780 raeburn 10680: my @sorted;
10681: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10682: @sorted =
10683: sort {
10684: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10685: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10686: }
10687: if (ref($slots->{$a})) { return -1;}
10688: if (ref($slots->{$b})) { return 1;}
10689: return 0;
10690: } @{$slotsarr};
10691: }
10692: return @sorted;
10693: }
10694:
1.1040 raeburn 10695: =pod
10696:
10697: =item * get_future_slots()
10698:
10699: Inputs:
10700:
10701: =over 4
10702:
10703: cnum - course number
10704:
10705: cdom - course domain
10706:
10707: now - current UNIX time
10708:
10709: symb - optional symb
10710:
10711: =back
10712:
10713: Returns:
10714:
10715: =over 4
10716:
10717: sorted_reservable - ref to array of student_schedulable slots currently
10718: reservable, ordered by end date of reservation period.
10719:
10720: reservable_now - ref to hash of student_schedulable slots currently
10721: reservable.
10722:
10723: Keys in inner hash are:
10724: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10725: (b) endreserve: end date of reservation period.
10726: (c) uniqueperiod: start,end dates when slot is to be uniquely
10727: selected.
1.1040 raeburn 10728:
10729: sorted_future - ref to array of student_schedulable slots reservable in
10730: the future, ordered by start date of reservation period.
10731:
10732: future_reservable - ref to hash of student_schedulable slots reservable
10733: in the future.
10734:
10735: Keys in inner hash are:
10736: (a) symb: either blank or symb to which slot use is restricted.
10737: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10738: (c) uniqueperiod: start,end dates when slot is to be uniquely
10739: selected.
1.1040 raeburn 10740:
10741: =back
10742:
10743: =cut
10744:
10745: sub get_future_slots {
10746: my ($cnum,$cdom,$now,$symb) = @_;
10747: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10748: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10749: foreach my $slot (keys(%slots)) {
10750: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10751: if ($symb) {
10752: next if (($slots{$slot}->{'symb'} ne '') &&
10753: ($slots{$slot}->{'symb'} ne $symb));
10754: }
10755: if (($slots{$slot}->{'starttime'} > $now) &&
10756: ($slots{$slot}->{'endtime'} > $now)) {
10757: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10758: my $userallowed = 0;
10759: if ($slots{$slot}->{'allowedsections'}) {
10760: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10761: if (!defined($env{'request.role.sec'})
10762: && grep(/^No section assigned$/,@allowed_sec)) {
10763: $userallowed=1;
10764: } else {
10765: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10766: $userallowed=1;
10767: }
10768: }
10769: unless ($userallowed) {
10770: if (defined($env{'request.course.groups'})) {
10771: my @groups = split(/:/,$env{'request.course.groups'});
10772: foreach my $group (@groups) {
10773: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10774: $userallowed=1;
10775: last;
10776: }
10777: }
10778: }
10779: }
10780: }
10781: if ($slots{$slot}->{'allowedusers'}) {
10782: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10783: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10784: if (grep(/^\Q$user\E$/,@allowed_users)) {
10785: $userallowed = 1;
10786: }
10787: }
10788: next unless($userallowed);
10789: }
10790: my $startreserve = $slots{$slot}->{'startreserve'};
10791: my $endreserve = $slots{$slot}->{'endreserve'};
10792: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10793: my $uniqueperiod;
10794: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10795: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10796: }
1.1040 raeburn 10797: if (($startreserve < $now) &&
10798: (!$endreserve || $endreserve > $now)) {
10799: my $lastres = $endreserve;
10800: if (!$lastres) {
10801: $lastres = $slots{$slot}->{'starttime'};
10802: }
10803: $reservable_now{$slot} = {
10804: symb => $symb,
1.1075.2.104 raeburn 10805: endreserve => $lastres,
10806: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10807: };
10808: } elsif (($startreserve > $now) &&
10809: (!$endreserve || $endreserve > $startreserve)) {
10810: $future_reservable{$slot} = {
10811: symb => $symb,
1.1075.2.104 raeburn 10812: startreserve => $startreserve,
10813: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10814: };
10815: }
10816: }
10817: }
10818: my @unsorted_reservable = keys(%reservable_now);
10819: if (@unsorted_reservable > 0) {
10820: @sorted_reservable =
10821: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10822: }
10823: my @unsorted_future = keys(%future_reservable);
10824: if (@unsorted_future > 0) {
10825: @sorted_future =
10826: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10827: }
10828: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10829: }
1.780 raeburn 10830:
10831: =pod
10832:
1.1057 foxr 10833: =back
10834:
1.549 albertel 10835: =head1 HTTP Helpers
10836:
10837: =over 4
10838:
1.648 raeburn 10839: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10840:
1.258 albertel 10841: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10842: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10843: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10844:
10845: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10846: $possible_names is an ref to an array of form element names. As an example:
10847: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10848: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10849:
10850: =cut
1.1 albertel 10851:
1.6 albertel 10852: sub get_unprocessed_cgi {
1.25 albertel 10853: my ($query,$possible_names)= @_;
1.26 matthew 10854: # $Apache::lonxml::debug=1;
1.356 albertel 10855: foreach my $pair (split(/&/,$query)) {
10856: my ($name, $value) = split(/=/,$pair);
1.369 www 10857: $name = &unescape($name);
1.25 albertel 10858: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10859: $value =~ tr/+/ /;
10860: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10861: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10862: }
1.16 harris41 10863: }
1.6 albertel 10864: }
10865:
1.112 bowersj2 10866: =pod
10867:
1.648 raeburn 10868: =item * &cacheheader()
1.112 bowersj2 10869:
10870: returns cache-controlling header code
10871:
10872: =cut
10873:
1.7 albertel 10874: sub cacheheader {
1.258 albertel 10875: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10876: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10877: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10878: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10879: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10880: return $output;
1.7 albertel 10881: }
10882:
1.112 bowersj2 10883: =pod
10884:
1.648 raeburn 10885: =item * &no_cache($r)
1.112 bowersj2 10886:
10887: specifies header code to not have cache
10888:
10889: =cut
10890:
1.9 albertel 10891: sub no_cache {
1.216 albertel 10892: my ($r) = @_;
10893: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10894: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10895: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10896: $r->no_cache(1);
10897: $r->header_out("Expires" => $date);
10898: $r->header_out("Pragma" => "no-cache");
1.123 www 10899: }
10900:
10901: sub content_type {
1.181 albertel 10902: my ($r,$type,$charset) = @_;
1.299 foxr 10903: if ($r) {
10904: # Note that printout.pl calls this with undef for $r.
10905: &no_cache($r);
10906: }
1.258 albertel 10907: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10908: unless ($charset) {
10909: $charset=&Apache::lonlocal::current_encoding;
10910: }
10911: if ($charset) { $type.='; charset='.$charset; }
10912: if ($r) {
10913: $r->content_type($type);
10914: } else {
10915: print("Content-type: $type\n\n");
10916: }
1.9 albertel 10917: }
1.25 albertel 10918:
1.112 bowersj2 10919: =pod
10920:
1.648 raeburn 10921: =item * &add_to_env($name,$value)
1.112 bowersj2 10922:
1.258 albertel 10923: adds $name to the %env hash with value
1.112 bowersj2 10924: $value, if $name already exists, the entry is converted to an array
10925: reference and $value is added to the array.
10926:
10927: =cut
10928:
1.25 albertel 10929: sub add_to_env {
10930: my ($name,$value)=@_;
1.258 albertel 10931: if (defined($env{$name})) {
10932: if (ref($env{$name})) {
1.25 albertel 10933: #already have multiple values
1.258 albertel 10934: push(@{ $env{$name} },$value);
1.25 albertel 10935: } else {
10936: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10937: my $first=$env{$name};
10938: undef($env{$name});
10939: push(@{ $env{$name} },$first,$value);
1.25 albertel 10940: }
10941: } else {
1.258 albertel 10942: $env{$name}=$value;
1.25 albertel 10943: }
1.31 albertel 10944: }
1.149 albertel 10945:
10946: =pod
10947:
1.648 raeburn 10948: =item * &get_env_multiple($name)
1.149 albertel 10949:
1.258 albertel 10950: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10951: values may be defined and end up as an array ref.
10952:
10953: returns an array of values
10954:
10955: =cut
10956:
10957: sub get_env_multiple {
10958: my ($name) = @_;
10959: my @values;
1.258 albertel 10960: if (defined($env{$name})) {
1.149 albertel 10961: # exists is it an array
1.258 albertel 10962: if (ref($env{$name})) {
10963: @values=@{ $env{$name} };
1.149 albertel 10964: } else {
1.258 albertel 10965: $values[0]=$env{$name};
1.149 albertel 10966: }
10967: }
10968: return(@values);
10969: }
10970:
1.660 raeburn 10971: sub ask_for_embedded_content {
10972: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10973: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10974: %currsubfile,%unused,$rem);
1.1071 raeburn 10975: my $counter = 0;
10976: my $numnew = 0;
1.987 raeburn 10977: my $numremref = 0;
10978: my $numinvalid = 0;
10979: my $numpathchg = 0;
10980: my $numexisting = 0;
1.1071 raeburn 10981: my $numunused = 0;
10982: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10983: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10984: my $heading = &mt('Upload embedded files');
10985: my $buttontext = &mt('Upload');
10986:
1.1075.2.11 raeburn 10987: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10988: if ($actionurl eq '/adm/dependencies') {
10989: $navmap = Apache::lonnavmaps::navmap->new();
10990: }
10991: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10992: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10993: }
1.1075.2.35 raeburn 10994: if (($actionurl eq '/adm/portfolio') ||
10995: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10996: my $current_path='/';
10997: if ($env{'form.currentpath'}) {
10998: $current_path = $env{'form.currentpath'};
10999: }
11000: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 11001: $udom = $cdom;
11002: $uname = $cnum;
1.984 raeburn 11003: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11004: } else {
11005: $udom = $env{'user.domain'};
11006: $uname = $env{'user.name'};
11007: $url = '/userfiles/portfolio';
11008: }
1.987 raeburn 11009: $toplevel = $url.'/';
1.984 raeburn 11010: $url .= $current_path;
11011: $getpropath = 1;
1.987 raeburn 11012: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11013: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11014: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11015: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11016: $toplevel = $url;
1.984 raeburn 11017: if ($rest ne '') {
1.987 raeburn 11018: $url .= $rest;
11019: }
11020: } elsif ($actionurl eq '/adm/coursedocs') {
11021: if (ref($args) eq 'HASH') {
1.1071 raeburn 11022: $url = $args->{'docs_url'};
11023: $toplevel = $url;
1.1075.2.11 raeburn 11024: if ($args->{'context'} eq 'paste') {
11025: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11026: ($path) =
11027: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11028: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11029: $fileloc =~ s{^/}{};
11030: }
1.1071 raeburn 11031: }
11032: } elsif ($actionurl eq '/adm/dependencies') {
11033: if ($env{'request.course.id'} ne '') {
11034: if (ref($args) eq 'HASH') {
11035: $url = $args->{'docs_url'};
11036: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 11037: $toplevel = $url;
11038: unless ($toplevel =~ m{^/}) {
11039: $toplevel = "/$url";
11040: }
1.1075.2.11 raeburn 11041: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 11042: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11043: $path = $1;
11044: } else {
11045: ($path) =
11046: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11047: }
1.1075.2.79 raeburn 11048: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11049: $fileloc = $toplevel;
11050: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11051: my ($udom,$uname,$fname) =
11052: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11053: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11054: } else {
11055: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11056: }
1.1071 raeburn 11057: $fileloc =~ s{^/}{};
11058: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11059: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11060: }
1.987 raeburn 11061: }
1.1075.2.35 raeburn 11062: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11063: $udom = $cdom;
11064: $uname = $cnum;
11065: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11066: $toplevel = $url;
11067: $path = $url;
11068: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11069: $fileloc =~ s{^/}{};
11070: }
11071: foreach my $file (keys(%{$allfiles})) {
11072: my $embed_file;
11073: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11074: $embed_file = $1;
11075: } else {
11076: $embed_file = $file;
11077: }
1.1075.2.55 raeburn 11078: my ($absolutepath,$cleaned_file);
11079: if ($embed_file =~ m{^\w+://}) {
11080: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 11081: $newfiles{$cleaned_file} = 1;
11082: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11083: } else {
1.1075.2.55 raeburn 11084: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11085: if ($embed_file =~ m{^/}) {
11086: $absolutepath = $embed_file;
11087: }
1.1075.2.47 raeburn 11088: if ($cleaned_file =~ m{/}) {
11089: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11090: $path = &check_for_traversal($path,$url,$toplevel);
11091: my $item = $fname;
11092: if ($path ne '') {
11093: $item = $path.'/'.$fname;
11094: $subdependencies{$path}{$fname} = 1;
11095: } else {
11096: $dependencies{$item} = 1;
11097: }
11098: if ($absolutepath) {
11099: $mapping{$item} = $absolutepath;
11100: } else {
11101: $mapping{$item} = $embed_file;
11102: }
11103: } else {
11104: $dependencies{$embed_file} = 1;
11105: if ($absolutepath) {
1.1075.2.47 raeburn 11106: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11107: } else {
1.1075.2.47 raeburn 11108: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11109: }
11110: }
1.984 raeburn 11111: }
11112: }
1.1071 raeburn 11113: my $dirptr = 16384;
1.984 raeburn 11114: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11115: $currsubfile{$path} = {};
1.1075.2.35 raeburn 11116: if (($actionurl eq '/adm/portfolio') ||
11117: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11118: my ($sublistref,$listerror) =
11119: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11120: if (ref($sublistref) eq 'ARRAY') {
11121: foreach my $line (@{$sublistref}) {
11122: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11123: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11124: }
1.984 raeburn 11125: }
1.987 raeburn 11126: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11127: if (opendir(my $dir,$url.'/'.$path)) {
11128: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11129: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11130: }
1.1075.2.11 raeburn 11131: } elsif (($actionurl eq '/adm/dependencies') ||
11132: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11133: ($args->{'context'} eq 'paste')) ||
11134: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11135: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 11136: my $dir;
11137: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11138: $dir = $fileloc;
11139: } else {
11140: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11141: }
1.1071 raeburn 11142: if ($dir ne '') {
11143: my ($sublistref,$listerror) =
11144: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11145: if (ref($sublistref) eq 'ARRAY') {
11146: foreach my $line (@{$sublistref}) {
11147: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11148: undef,$mtime)=split(/\&/,$line,12);
11149: unless (($testdir&$dirptr) ||
11150: ($file_name =~ /^\.\.?$/)) {
11151: $currsubfile{$path}{$file_name} = [$size,$mtime];
11152: }
11153: }
11154: }
11155: }
1.984 raeburn 11156: }
11157: }
11158: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11159: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11160: my $item = $path.'/'.$file;
11161: unless ($mapping{$item} eq $item) {
11162: $pathchanges{$item} = 1;
11163: }
11164: $existing{$item} = 1;
11165: $numexisting ++;
11166: } else {
11167: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11168: }
11169: }
1.1071 raeburn 11170: if ($actionurl eq '/adm/dependencies') {
11171: foreach my $path (keys(%currsubfile)) {
11172: if (ref($currsubfile{$path}) eq 'HASH') {
11173: foreach my $file (keys(%{$currsubfile{$path}})) {
11174: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 11175: next if (($rem ne '') &&
11176: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11177: (ref($navmap) &&
11178: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11179: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11180: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11181: $unused{$path.'/'.$file} = 1;
11182: }
11183: }
11184: }
11185: }
11186: }
1.984 raeburn 11187: }
1.987 raeburn 11188: my %currfile;
1.1075.2.35 raeburn 11189: if (($actionurl eq '/adm/portfolio') ||
11190: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11191: my ($dirlistref,$listerror) =
11192: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11193: if (ref($dirlistref) eq 'ARRAY') {
11194: foreach my $line (@{$dirlistref}) {
11195: my ($file_name,$rest) = split(/\&/,$line,2);
11196: $currfile{$file_name} = 1;
11197: }
1.984 raeburn 11198: }
1.987 raeburn 11199: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11200: if (opendir(my $dir,$url)) {
1.987 raeburn 11201: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11202: map {$currfile{$_} = 1;} @dir_list;
11203: }
1.1075.2.11 raeburn 11204: } elsif (($actionurl eq '/adm/dependencies') ||
11205: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11206: ($args->{'context'} eq 'paste')) ||
11207: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11208: if ($env{'request.course.id'} ne '') {
11209: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11210: if ($dir ne '') {
11211: my ($dirlistref,$listerror) =
11212: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11213: if (ref($dirlistref) eq 'ARRAY') {
11214: foreach my $line (@{$dirlistref}) {
11215: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11216: $size,undef,$mtime)=split(/\&/,$line,12);
11217: unless (($testdir&$dirptr) ||
11218: ($file_name =~ /^\.\.?$/)) {
11219: $currfile{$file_name} = [$size,$mtime];
11220: }
11221: }
11222: }
11223: }
11224: }
1.984 raeburn 11225: }
11226: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11227: if (exists($currfile{$file})) {
1.987 raeburn 11228: unless ($mapping{$file} eq $file) {
11229: $pathchanges{$file} = 1;
11230: }
11231: $existing{$file} = 1;
11232: $numexisting ++;
11233: } else {
1.984 raeburn 11234: $newfiles{$file} = 1;
11235: }
11236: }
1.1071 raeburn 11237: foreach my $file (keys(%currfile)) {
11238: unless (($file eq $filename) ||
11239: ($file eq $filename.'.bak') ||
11240: ($dependencies{$file})) {
1.1075.2.11 raeburn 11241: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 11242: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11243: next if (($rem ne '') &&
11244: (($env{"httpref.$rem".$file} ne '') ||
11245: (ref($navmap) &&
11246: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11247: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11248: ($navmap->getResourceByUrl($rem.$1)))))));
11249: }
1.1075.2.11 raeburn 11250: }
1.1071 raeburn 11251: $unused{$file} = 1;
11252: }
11253: }
1.1075.2.11 raeburn 11254: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11255: ($args->{'context'} eq 'paste')) {
11256: $counter = scalar(keys(%existing));
11257: $numpathchg = scalar(keys(%pathchanges));
11258: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 11259: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11260: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11261: $counter = scalar(keys(%existing));
11262: $numpathchg = scalar(keys(%pathchanges));
11263: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 11264: }
1.984 raeburn 11265: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11266: if ($actionurl eq '/adm/dependencies') {
11267: next if ($embed_file =~ m{^\w+://});
11268: }
1.660 raeburn 11269: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11270: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11271: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11272: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 11273: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11274: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11275: }
1.1075.2.35 raeburn 11276: $upload_output .= '</td>';
1.1071 raeburn 11277: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 11278: $upload_output.='<td align="right">'.
11279: '<span class="LC_info LC_fontsize_medium">'.
11280: &mt("URL points to web address").'</span>';
1.987 raeburn 11281: $numremref++;
1.660 raeburn 11282: } elsif ($args->{'error_on_invalid_names'}
11283: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 11284: $upload_output.='<td align="right"><span class="LC_warning">'.
11285: &mt('Invalid characters').'</span>';
1.987 raeburn 11286: $numinvalid++;
1.660 raeburn 11287: } else {
1.1075.2.35 raeburn 11288: $upload_output .= '<td>'.
11289: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11290: $embed_file,\%mapping,
1.1071 raeburn 11291: $allfiles,$codebase,'upload');
11292: $counter ++;
11293: $numnew ++;
1.987 raeburn 11294: }
11295: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11296: }
11297: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11298: if ($actionurl eq '/adm/dependencies') {
11299: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11300: $modify_output .= &start_data_table_row().
11301: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11302: '<img src="'.&icon($embed_file).'" border="0" />'.
11303: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11304: '<td>'.$size.'</td>'.
11305: '<td>'.$mtime.'</td>'.
11306: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11307: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11308: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11309: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11310: &embedded_file_element('upload_embedded',$counter,
11311: $embed_file,\%mapping,
11312: $allfiles,$codebase,'modify').
11313: '</div></td>'.
11314: &end_data_table_row()."\n";
11315: $counter ++;
11316: } else {
11317: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11318: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11319: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11320: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11321: &Apache::loncommon::end_data_table_row()."\n";
11322: }
11323: }
11324: my $delidx = $counter;
11325: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11326: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11327: $delete_output .= &start_data_table_row().
11328: '<td><img src="'.&icon($oldfile).'" />'.
11329: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11330: '<td>'.$size.'</td>'.
11331: '<td>'.$mtime.'</td>'.
11332: '<td><label><input type="checkbox" name="del_upload_dep" '.
11333: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11334: &embedded_file_element('upload_embedded',$delidx,
11335: $oldfile,\%mapping,$allfiles,
11336: $codebase,'delete').'</td>'.
11337: &end_data_table_row()."\n";
11338: $numunused ++;
11339: $delidx ++;
1.987 raeburn 11340: }
11341: if ($upload_output) {
11342: $upload_output = &start_data_table().
11343: $upload_output.
11344: &end_data_table()."\n";
11345: }
1.1071 raeburn 11346: if ($modify_output) {
11347: $modify_output = &start_data_table().
11348: &start_data_table_header_row().
11349: '<th>'.&mt('File').'</th>'.
11350: '<th>'.&mt('Size (KB)').'</th>'.
11351: '<th>'.&mt('Modified').'</th>'.
11352: '<th>'.&mt('Upload replacement?').'</th>'.
11353: &end_data_table_header_row().
11354: $modify_output.
11355: &end_data_table()."\n";
11356: }
11357: if ($delete_output) {
11358: $delete_output = &start_data_table().
11359: &start_data_table_header_row().
11360: '<th>'.&mt('File').'</th>'.
11361: '<th>'.&mt('Size (KB)').'</th>'.
11362: '<th>'.&mt('Modified').'</th>'.
11363: '<th>'.&mt('Delete?').'</th>'.
11364: &end_data_table_header_row().
11365: $delete_output.
11366: &end_data_table()."\n";
11367: }
1.987 raeburn 11368: my $applies = 0;
11369: if ($numremref) {
11370: $applies ++;
11371: }
11372: if ($numinvalid) {
11373: $applies ++;
11374: }
11375: if ($numexisting) {
11376: $applies ++;
11377: }
1.1071 raeburn 11378: if ($counter || $numunused) {
1.987 raeburn 11379: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11380: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11381: $state.'<h3>'.$heading.'</h3>';
11382: if ($actionurl eq '/adm/dependencies') {
11383: if ($numnew) {
11384: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11385: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11386: $upload_output.'<br />'."\n";
11387: }
11388: if ($numexisting) {
11389: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11390: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11391: $modify_output.'<br />'."\n";
11392: $buttontext = &mt('Save changes');
11393: }
11394: if ($numunused) {
11395: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11396: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11397: $delete_output.'<br />'."\n";
11398: $buttontext = &mt('Save changes');
11399: }
11400: } else {
11401: $output .= $upload_output.'<br />'."\n";
11402: }
11403: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11404: $counter.'" />'."\n";
11405: if ($actionurl eq '/adm/dependencies') {
11406: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11407: $numnew.'" />'."\n";
11408: } elsif ($actionurl eq '') {
1.987 raeburn 11409: $output .= '<input type="hidden" name="phase" value="three" />';
11410: }
11411: } elsif ($applies) {
11412: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11413: if ($applies > 1) {
11414: $output .=
1.1075.2.35 raeburn 11415: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11416: if ($numremref) {
11417: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11418: }
11419: if ($numinvalid) {
11420: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11421: }
11422: if ($numexisting) {
11423: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11424: }
11425: $output .= '</ul><br />';
11426: } elsif ($numremref) {
11427: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11428: } elsif ($numinvalid) {
11429: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11430: } elsif ($numexisting) {
11431: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11432: }
11433: $output .= $upload_output.'<br />';
11434: }
11435: my ($pathchange_output,$chgcount);
1.1071 raeburn 11436: $chgcount = $counter;
1.987 raeburn 11437: if (keys(%pathchanges) > 0) {
11438: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11439: if ($counter) {
1.987 raeburn 11440: $output .= &embedded_file_element('pathchange',$chgcount,
11441: $embed_file,\%mapping,
1.1071 raeburn 11442: $allfiles,$codebase,'change');
1.987 raeburn 11443: } else {
11444: $pathchange_output .=
11445: &start_data_table_row().
11446: '<td><input type ="checkbox" name="namechange" value="'.
11447: $chgcount.'" checked="checked" /></td>'.
11448: '<td>'.$mapping{$embed_file}.'</td>'.
11449: '<td>'.$embed_file.
11450: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11451: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11452: '</td>'.&end_data_table_row();
1.660 raeburn 11453: }
1.987 raeburn 11454: $numpathchg ++;
11455: $chgcount ++;
1.660 raeburn 11456: }
11457: }
1.1075.2.35 raeburn 11458: if (($counter) || ($numunused)) {
1.987 raeburn 11459: if ($numpathchg) {
11460: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11461: $numpathchg.'" />'."\n";
11462: }
11463: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11464: ($actionurl eq '/adm/imsimport')) {
11465: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11466: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11467: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11468: } elsif ($actionurl eq '/adm/dependencies') {
11469: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11470: }
1.1075.2.35 raeburn 11471: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11472: } elsif ($numpathchg) {
11473: my %pathchange = ();
11474: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11475: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11476: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11477: }
1.987 raeburn 11478: }
1.1071 raeburn 11479: return ($output,$counter,$numpathchg);
1.987 raeburn 11480: }
11481:
1.1075.2.47 raeburn 11482: =pod
11483:
11484: =item * clean_path($name)
11485:
11486: Performs clean-up of directories, subdirectories and filename in an
11487: embedded object, referenced in an HTML file which is being uploaded
11488: to a course or portfolio, where
11489: "Upload embedded images/multimedia files if HTML file" checkbox was
11490: checked.
11491:
11492: Clean-up is similar to replacements in lonnet::clean_filename()
11493: except each / between sub-directory and next level is preserved.
11494:
11495: =cut
11496:
11497: sub clean_path {
11498: my ($embed_file) = @_;
11499: $embed_file =~s{^/+}{};
11500: my @contents;
11501: if ($embed_file =~ m{/}) {
11502: @contents = split(/\//,$embed_file);
11503: } else {
11504: @contents = ($embed_file);
11505: }
11506: my $lastidx = scalar(@contents)-1;
11507: for (my $i=0; $i<=$lastidx; $i++) {
11508: $contents[$i]=~s{\\}{/}g;
11509: $contents[$i]=~s/\s+/\_/g;
11510: $contents[$i]=~s{[^/\w\.\-]}{}g;
11511: if ($i == $lastidx) {
11512: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11513: }
11514: }
11515: if ($lastidx > 0) {
11516: return join('/',@contents);
11517: } else {
11518: return $contents[0];
11519: }
11520: }
11521:
1.987 raeburn 11522: sub embedded_file_element {
1.1071 raeburn 11523: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11524: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11525: (ref($codebase) eq 'HASH'));
11526: my $output;
1.1071 raeburn 11527: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11528: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11529: }
11530: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11531: &escape($embed_file).'" />';
11532: unless (($context eq 'upload_embedded') &&
11533: ($mapping->{$embed_file} eq $embed_file)) {
11534: $output .='
11535: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11536: }
11537: my $attrib;
11538: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11539: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11540: }
11541: $output .=
11542: "\n\t\t".
11543: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11544: $attrib.'" />';
11545: if (exists($codebase->{$mapping->{$embed_file}})) {
11546: $output .=
11547: "\n\t\t".
11548: '<input name="codebase_'.$num.'" type="hidden" value="'.
11549: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11550: }
1.987 raeburn 11551: return $output;
1.660 raeburn 11552: }
11553:
1.1071 raeburn 11554: sub get_dependency_details {
11555: my ($currfile,$currsubfile,$embed_file) = @_;
11556: my ($size,$mtime,$showsize,$showmtime);
11557: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11558: if ($embed_file =~ m{/}) {
11559: my ($path,$fname) = split(/\//,$embed_file);
11560: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11561: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11562: }
11563: } else {
11564: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11565: ($size,$mtime) = @{$currfile->{$embed_file}};
11566: }
11567: }
11568: $showsize = $size/1024.0;
11569: $showsize = sprintf("%.1f",$showsize);
11570: if ($mtime > 0) {
11571: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11572: }
11573: }
11574: return ($showsize,$showmtime);
11575: }
11576:
11577: sub ask_embedded_js {
11578: return <<"END";
11579: <script type="text/javascript"">
11580: // <![CDATA[
11581: function toggleBrowse(counter) {
11582: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11583: var fileid = document.getElementById('embedded_item_'+counter);
11584: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11585: if (chkboxid.checked == true) {
11586: uploaddivid.style.display='block';
11587: } else {
11588: uploaddivid.style.display='none';
11589: fileid.value = '';
11590: }
11591: }
11592: // ]]>
11593: </script>
11594:
11595: END
11596: }
11597:
1.661 raeburn 11598: sub upload_embedded {
11599: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11600: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11601: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11602: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11603: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11604: my $orig_uploaded_filename =
11605: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11606: foreach my $type ('orig','ref','attrib','codebase') {
11607: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11608: $env{'form.embedded_'.$type.'_'.$i} =
11609: &unescape($env{'form.embedded_'.$type.'_'.$i});
11610: }
11611: }
1.661 raeburn 11612: my ($path,$fname) =
11613: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11614: # no path, whole string is fname
11615: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11616: $fname = &Apache::lonnet::clean_filename($fname);
11617: # See if there is anything left
11618: next if ($fname eq '');
11619:
11620: # Check if file already exists as a file or directory.
11621: my ($state,$msg);
11622: if ($context eq 'portfolio') {
11623: my $port_path = $dirpath;
11624: if ($group ne '') {
11625: $port_path = "groups/$group/$port_path";
11626: }
1.987 raeburn 11627: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11628: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11629: $dir_root,$port_path,$disk_quota,
11630: $current_disk_usage,$uname,$udom);
11631: if ($state eq 'will_exceed_quota'
1.984 raeburn 11632: || $state eq 'file_locked') {
1.661 raeburn 11633: $output .= $msg;
11634: next;
11635: }
11636: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11637: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11638: if ($state eq 'exists') {
11639: $output .= $msg;
11640: next;
11641: }
11642: }
11643: # Check if extension is valid
11644: if (($fname =~ /\.(\w+)$/) &&
11645: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11646: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11647: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11648: next;
11649: } elsif (($fname =~ /\.(\w+)$/) &&
11650: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11651: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11652: next;
11653: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11654: $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 11655: next;
11656: }
11657: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11658: my $subdir = $path;
11659: $subdir =~ s{/+$}{};
1.661 raeburn 11660: if ($context eq 'portfolio') {
1.984 raeburn 11661: my $result;
11662: if ($state eq 'existingfile') {
11663: $result=
11664: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11665: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11666: } else {
1.984 raeburn 11667: $result=
11668: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11669: $dirpath.
1.1075.2.35 raeburn 11670: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11671: if ($result !~ m|^/uploaded/|) {
11672: $output .= '<span class="LC_error">'
11673: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11674: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11675: .'</span><br />';
11676: next;
11677: } else {
1.987 raeburn 11678: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11679: $path.$fname.'</span>').'<br />';
1.984 raeburn 11680: }
1.661 raeburn 11681: }
1.1075.2.35 raeburn 11682: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11683: my $extendedsubdir = $dirpath.'/'.$subdir;
11684: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11685: my $result =
1.1075.2.35 raeburn 11686: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11687: if ($result !~ m|^/uploaded/|) {
11688: $output .= '<span class="LC_error">'
11689: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11690: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11691: .'</span><br />';
11692: next;
11693: } else {
11694: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11695: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11696: if ($context eq 'syllabus') {
11697: &Apache::lonnet::make_public_indefinitely($result);
11698: }
1.987 raeburn 11699: }
1.661 raeburn 11700: } else {
11701: # Save the file
11702: my $target = $env{'form.embedded_item_'.$i};
11703: my $fullpath = $dir_root.$dirpath.'/'.$path;
11704: my $dest = $fullpath.$fname;
11705: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11706: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11707: my $count;
11708: my $filepath = $dir_root;
1.1027 raeburn 11709: foreach my $subdir (@parts) {
11710: $filepath .= "/$subdir";
11711: if (!-e $filepath) {
1.661 raeburn 11712: mkdir($filepath,0770);
11713: }
11714: }
11715: my $fh;
11716: if (!open($fh,'>'.$dest)) {
11717: &Apache::lonnet::logthis('Failed to create '.$dest);
11718: $output .= '<span class="LC_error">'.
1.1071 raeburn 11719: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11720: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11721: '</span><br />';
11722: } else {
11723: if (!print $fh $env{'form.embedded_item_'.$i}) {
11724: &Apache::lonnet::logthis('Failed to write to '.$dest);
11725: $output .= '<span class="LC_error">'.
1.1071 raeburn 11726: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11727: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11728: '</span><br />';
11729: } else {
1.987 raeburn 11730: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11731: $url.'</span>').'<br />';
11732: unless ($context eq 'testbank') {
11733: $footer .= &mt('View embedded file: [_1]',
11734: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11735: }
11736: }
11737: close($fh);
11738: }
11739: }
11740: if ($env{'form.embedded_ref_'.$i}) {
11741: $pathchange{$i} = 1;
11742: }
11743: }
11744: if ($output) {
11745: $output = '<p>'.$output.'</p>';
11746: }
11747: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11748: $returnflag = 'ok';
1.1071 raeburn 11749: my $numpathchgs = scalar(keys(%pathchange));
11750: if ($numpathchgs > 0) {
1.987 raeburn 11751: if ($context eq 'portfolio') {
11752: $output .= '<p>'.&mt('or').'</p>';
11753: } elsif ($context eq 'testbank') {
1.1071 raeburn 11754: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11755: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11756: $returnflag = 'modify_orightml';
11757: }
11758: }
1.1071 raeburn 11759: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11760: }
11761:
11762: sub modify_html_form {
11763: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11764: my $end = 0;
11765: my $modifyform;
11766: if ($context eq 'upload_embedded') {
11767: return unless (ref($pathchange) eq 'HASH');
11768: if ($env{'form.number_embedded_items'}) {
11769: $end += $env{'form.number_embedded_items'};
11770: }
11771: if ($env{'form.number_pathchange_items'}) {
11772: $end += $env{'form.number_pathchange_items'};
11773: }
11774: if ($end) {
11775: for (my $i=0; $i<$end; $i++) {
11776: if ($i < $env{'form.number_embedded_items'}) {
11777: next unless($pathchange->{$i});
11778: }
11779: $modifyform .=
11780: &start_data_table_row().
11781: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11782: 'checked="checked" /></td>'.
11783: '<td>'.$env{'form.embedded_ref_'.$i}.
11784: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11785: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11786: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11787: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11788: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11789: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11790: '<td>'.$env{'form.embedded_orig_'.$i}.
11791: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11792: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11793: &end_data_table_row();
1.1071 raeburn 11794: }
1.987 raeburn 11795: }
11796: } else {
11797: $modifyform = $pathchgtable;
11798: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11799: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11800: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11801: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11802: }
11803: }
11804: if ($modifyform) {
1.1071 raeburn 11805: if ($actionurl eq '/adm/dependencies') {
11806: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11807: }
1.987 raeburn 11808: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11809: '<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".
11810: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11811: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11812: '</ol></p>'."\n".'<p>'.
11813: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11814: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11815: &start_data_table()."\n".
11816: &start_data_table_header_row().
11817: '<th>'.&mt('Change?').'</th>'.
11818: '<th>'.&mt('Current reference').'</th>'.
11819: '<th>'.&mt('Required reference').'</th>'.
11820: &end_data_table_header_row()."\n".
11821: $modifyform.
11822: &end_data_table().'<br />'."\n".$hiddenstate.
11823: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11824: '</form>'."\n";
11825: }
11826: return;
11827: }
11828:
11829: sub modify_html_refs {
1.1075.2.35 raeburn 11830: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11831: my $container;
11832: if ($context eq 'portfolio') {
11833: $container = $env{'form.container'};
11834: } elsif ($context eq 'coursedoc') {
11835: $container = $env{'form.primaryurl'};
1.1071 raeburn 11836: } elsif ($context eq 'manage_dependencies') {
11837: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11838: $container = "/$container";
1.1075.2.35 raeburn 11839: } elsif ($context eq 'syllabus') {
11840: $container = $url;
1.987 raeburn 11841: } else {
1.1027 raeburn 11842: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11843: }
11844: my (%allfiles,%codebase,$output,$content);
11845: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11846: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11847: if (wantarray) {
11848: return ('',0,0);
11849: } else {
11850: return;
11851: }
11852: }
11853: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11854: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11855: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11856: if (wantarray) {
11857: return ('',0,0);
11858: } else {
11859: return;
11860: }
11861: }
1.987 raeburn 11862: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11863: if ($content eq '-1') {
11864: if (wantarray) {
11865: return ('',0,0);
11866: } else {
11867: return;
11868: }
11869: }
1.987 raeburn 11870: } else {
1.1071 raeburn 11871: unless ($container =~ /^\Q$dir_root\E/) {
11872: if (wantarray) {
11873: return ('',0,0);
11874: } else {
11875: return;
11876: }
11877: }
1.1075.2.128 raeburn 11878: if (open(my $fh,'<',$container)) {
1.987 raeburn 11879: $content = join('', <$fh>);
11880: close($fh);
11881: } else {
1.1071 raeburn 11882: if (wantarray) {
11883: return ('',0,0);
11884: } else {
11885: return;
11886: }
1.987 raeburn 11887: }
11888: }
11889: my ($count,$codebasecount) = (0,0);
11890: my $mm = new File::MMagic;
11891: my $mime_type = $mm->checktype_contents($content);
11892: if ($mime_type eq 'text/html') {
11893: my $parse_result =
11894: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11895: \%codebase,\$content);
11896: if ($parse_result eq 'ok') {
11897: foreach my $i (@changes) {
11898: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11899: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11900: if ($allfiles{$ref}) {
11901: my $newname = $orig;
11902: my ($attrib_regexp,$codebase);
1.1006 raeburn 11903: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11904: if ($attrib_regexp =~ /:/) {
11905: $attrib_regexp =~ s/\:/|/g;
11906: }
11907: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11908: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11909: $count += $numchg;
1.1075.2.35 raeburn 11910: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11911: delete($allfiles{$ref});
1.987 raeburn 11912: }
11913: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11914: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11915: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11916: $codebasecount ++;
11917: }
11918: }
11919: }
1.1075.2.35 raeburn 11920: my $skiprewrites;
1.987 raeburn 11921: if ($count || $codebasecount) {
11922: my $saveresult;
1.1071 raeburn 11923: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11924: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11925: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11926: if ($url eq $container) {
11927: my ($fname) = ($container =~ m{/([^/]+)$});
11928: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11929: $count,'<span class="LC_filename">'.
1.1071 raeburn 11930: $fname.'</span>').'</p>';
1.987 raeburn 11931: } else {
11932: $output = '<p class="LC_error">'.
11933: &mt('Error: update failed for: [_1].',
11934: '<span class="LC_filename">'.
11935: $container.'</span>').'</p>';
11936: }
1.1075.2.35 raeburn 11937: if ($context eq 'syllabus') {
11938: unless ($saveresult eq 'ok') {
11939: $skiprewrites = 1;
11940: }
11941: }
1.987 raeburn 11942: } else {
1.1075.2.128 raeburn 11943: if (open(my $fh,'>',$container)) {
1.987 raeburn 11944: print $fh $content;
11945: close($fh);
11946: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11947: $count,'<span class="LC_filename">'.
11948: $container.'</span>').'</p>';
1.661 raeburn 11949: } else {
1.987 raeburn 11950: $output = '<p class="LC_error">'.
11951: &mt('Error: could not update [_1].',
11952: '<span class="LC_filename">'.
11953: $container.'</span>').'</p>';
1.661 raeburn 11954: }
11955: }
11956: }
1.1075.2.35 raeburn 11957: if (($context eq 'syllabus') && (!$skiprewrites)) {
11958: my ($actionurl,$state);
11959: $actionurl = "/public/$udom/$uname/syllabus";
11960: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11961: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11962: \%codebase,
11963: {'context' => 'rewrites',
11964: 'ignore_remote_references' => 1,});
11965: if (ref($mapping) eq 'HASH') {
11966: my $rewrites = 0;
11967: foreach my $key (keys(%{$mapping})) {
11968: next if ($key =~ m{^https?://});
11969: my $ref = $mapping->{$key};
11970: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11971: my $attrib;
11972: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11973: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11974: }
11975: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11976: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11977: $rewrites += $numchg;
11978: }
11979: }
11980: if ($rewrites) {
11981: my $saveresult;
11982: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11983: if ($url eq $container) {
11984: my ($fname) = ($container =~ m{/([^/]+)$});
11985: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11986: $count,'<span class="LC_filename">'.
11987: $fname.'</span>').'</p>';
11988: } else {
11989: $output .= '<p class="LC_error">'.
11990: &mt('Error: could not update links in [_1].',
11991: '<span class="LC_filename">'.
11992: $container.'</span>').'</p>';
11993:
11994: }
11995: }
11996: }
11997: }
1.987 raeburn 11998: } else {
11999: &logthis('Failed to parse '.$container.
12000: ' to modify references: '.$parse_result);
1.661 raeburn 12001: }
12002: }
1.1071 raeburn 12003: if (wantarray) {
12004: return ($output,$count,$codebasecount);
12005: } else {
12006: return $output;
12007: }
1.661 raeburn 12008: }
12009:
12010: sub check_for_existing {
12011: my ($path,$fname,$element) = @_;
12012: my ($state,$msg);
12013: if (-d $path.'/'.$fname) {
12014: $state = 'exists';
12015: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12016: } elsif (-e $path.'/'.$fname) {
12017: $state = 'exists';
12018: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12019: }
12020: if ($state eq 'exists') {
12021: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12022: }
12023: return ($state,$msg);
12024: }
12025:
12026: sub check_for_upload {
12027: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12028: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12029: my $filesize = length($env{'form.'.$element});
12030: if (!$filesize) {
12031: my $msg = '<span class="LC_error">'.
12032: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12033: '<span class="LC_filename">'.$fname.'</span>',
12034: $filesize).'<br />'.
1.1007 raeburn 12035: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12036: '</span>';
12037: return ('zero_bytes',$msg);
12038: }
12039: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12040: my $getpropath = 1;
1.1021 raeburn 12041: my ($dirlistref,$listerror) =
12042: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12043: my $found_file = 0;
12044: my $locked_file = 0;
1.991 raeburn 12045: my @lockers;
12046: my $navmap;
12047: if ($env{'request.course.id'}) {
12048: $navmap = Apache::lonnavmaps::navmap->new();
12049: }
1.1021 raeburn 12050: if (ref($dirlistref) eq 'ARRAY') {
12051: foreach my $line (@{$dirlistref}) {
12052: my ($file_name,$rest)=split(/\&/,$line,2);
12053: if ($file_name eq $fname){
12054: $file_name = $path.$file_name;
12055: if ($group ne '') {
12056: $file_name = $group.$file_name;
12057: }
12058: $found_file = 1;
12059: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12060: foreach my $lock (@lockers) {
12061: if (ref($lock) eq 'ARRAY') {
12062: my ($symb,$crsid) = @{$lock};
12063: if ($crsid eq $env{'request.course.id'}) {
12064: if (ref($navmap)) {
12065: my $res = $navmap->getBySymb($symb);
12066: foreach my $part (@{$res->parts()}) {
12067: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12068: unless (($slot_status == $res->RESERVED) ||
12069: ($slot_status == $res->RESERVED_LOCATION)) {
12070: $locked_file = 1;
12071: }
1.991 raeburn 12072: }
1.1021 raeburn 12073: } else {
12074: $locked_file = 1;
1.991 raeburn 12075: }
12076: } else {
12077: $locked_file = 1;
12078: }
12079: }
1.1021 raeburn 12080: }
12081: } else {
12082: my @info = split(/\&/,$rest);
12083: my $currsize = $info[6]/1000;
12084: if ($currsize < $filesize) {
12085: my $extra = $filesize - $currsize;
12086: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 12087: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12088: &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 12089: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12090: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12091: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12092: return ('will_exceed_quota',$msg);
12093: }
1.984 raeburn 12094: }
12095: }
1.661 raeburn 12096: }
12097: }
12098: }
12099: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 12100: my $msg = '<p class="LC_warning">'.
12101: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
12102: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12103: return ('will_exceed_quota',$msg);
12104: } elsif ($found_file) {
12105: if ($locked_file) {
1.1075.2.69 raeburn 12106: my $msg = '<p class="LC_warning">';
1.661 raeburn 12107: $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 12108: $msg .= '</p>';
1.661 raeburn 12109: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12110: return ('file_locked',$msg);
12111: } else {
1.1075.2.69 raeburn 12112: my $msg = '<p class="LC_error">';
1.984 raeburn 12113: $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 12114: $msg .= '</p>';
1.984 raeburn 12115: return ('existingfile',$msg);
1.661 raeburn 12116: }
12117: }
12118: }
12119:
1.987 raeburn 12120: sub check_for_traversal {
12121: my ($path,$url,$toplevel) = @_;
12122: my @parts=split(/\//,$path);
12123: my $cleanpath;
12124: my $fullpath = $url;
12125: for (my $i=0;$i<@parts;$i++) {
12126: next if ($parts[$i] eq '.');
12127: if ($parts[$i] eq '..') {
12128: $fullpath =~ s{([^/]+/)$}{};
12129: } else {
12130: $fullpath .= $parts[$i].'/';
12131: }
12132: }
12133: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12134: $cleanpath = $1;
12135: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12136: my $curr_toprel = $1;
12137: my @parts = split(/\//,$curr_toprel);
12138: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12139: my @urlparts = split(/\//,$url_toprel);
12140: my $doubledots;
12141: my $startdiff = -1;
12142: for (my $i=0; $i<@urlparts; $i++) {
12143: if ($startdiff == -1) {
12144: unless ($urlparts[$i] eq $parts[$i]) {
12145: $startdiff = $i;
12146: $doubledots .= '../';
12147: }
12148: } else {
12149: $doubledots .= '../';
12150: }
12151: }
12152: if ($startdiff > -1) {
12153: $cleanpath = $doubledots;
12154: for (my $i=$startdiff; $i<@parts; $i++) {
12155: $cleanpath .= $parts[$i].'/';
12156: }
12157: }
12158: }
12159: $cleanpath =~ s{(/)$}{};
12160: return $cleanpath;
12161: }
1.31 albertel 12162:
1.1053 raeburn 12163: sub is_archive_file {
12164: my ($mimetype) = @_;
12165: if (($mimetype eq 'application/octet-stream') ||
12166: ($mimetype eq 'application/x-stuffit') ||
12167: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12168: return 1;
12169: }
12170: return;
12171: }
12172:
12173: sub decompress_form {
1.1065 raeburn 12174: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12175: my %lt = &Apache::lonlocal::texthash (
12176: this => 'This file is an archive file.',
1.1067 raeburn 12177: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12178: itsc => 'Its contents are as follows:',
1.1053 raeburn 12179: youm => 'You may wish to extract its contents.',
12180: extr => 'Extract contents',
1.1067 raeburn 12181: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12182: proa => 'Process automatically?',
1.1053 raeburn 12183: yes => 'Yes',
12184: no => 'No',
1.1067 raeburn 12185: fold => 'Title for folder containing movie',
12186: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12187: );
1.1065 raeburn 12188: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12189: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12190: my $info = &list_archive_contents($fileloc,\@paths);
12191: if (@paths) {
12192: foreach my $path (@paths) {
12193: $path =~ s{^/}{};
1.1067 raeburn 12194: if ($path =~ m{^([^/]+)/$}) {
12195: $topdir = $1;
12196: }
1.1065 raeburn 12197: if ($path =~ m{^([^/]+)/}) {
12198: $toplevel{$1} = $path;
12199: } else {
12200: $toplevel{$path} = $path;
12201: }
12202: }
12203: }
1.1067 raeburn 12204: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 12205: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12206: "$topdir/media/",
12207: "$topdir/media/$topdir.mp4",
12208: "$topdir/media/FirstFrame.png",
12209: "$topdir/media/player.swf",
12210: "$topdir/media/swfobject.js",
12211: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 12212: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 12213: "$topdir/$topdir.mp4",
12214: "$topdir/$topdir\_config.xml",
12215: "$topdir/$topdir\_controller.swf",
12216: "$topdir/$topdir\_embed.css",
12217: "$topdir/$topdir\_First_Frame.png",
12218: "$topdir/$topdir\_player.html",
12219: "$topdir/$topdir\_Thumbnails.png",
12220: "$topdir/playerProductInstall.swf",
12221: "$topdir/scripts/",
12222: "$topdir/scripts/config_xml.js",
12223: "$topdir/scripts/handlebars.js",
12224: "$topdir/scripts/jquery-1.7.1.min.js",
12225: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12226: "$topdir/scripts/modernizr.js",
12227: "$topdir/scripts/player-min.js",
12228: "$topdir/scripts/swfobject.js",
12229: "$topdir/skins/",
12230: "$topdir/skins/configuration_express.xml",
12231: "$topdir/skins/express_show/",
12232: "$topdir/skins/express_show/player-min.css",
12233: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 12234: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12235: "$topdir/$topdir.mp4",
12236: "$topdir/$topdir\_config.xml",
12237: "$topdir/$topdir\_controller.swf",
12238: "$topdir/$topdir\_embed.css",
12239: "$topdir/$topdir\_First_Frame.png",
12240: "$topdir/$topdir\_player.html",
12241: "$topdir/$topdir\_Thumbnails.png",
12242: "$topdir/playerProductInstall.swf",
12243: "$topdir/scripts/",
12244: "$topdir/scripts/config_xml.js",
12245: "$topdir/scripts/techsmith-smart-player.min.js",
12246: "$topdir/skins/",
12247: "$topdir/skins/configuration_express.xml",
12248: "$topdir/skins/express_show/",
12249: "$topdir/skins/express_show/spritesheet.min.css",
12250: "$topdir/skins/express_show/spritesheet.png",
12251: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 12252: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12253: if (@diffs == 0) {
1.1075.2.59 raeburn 12254: $is_camtasia = 6;
12255: } else {
1.1075.2.81 raeburn 12256: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 12257: if (@diffs == 0) {
12258: $is_camtasia = 8;
1.1075.2.81 raeburn 12259: } else {
12260: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12261: if (@diffs == 0) {
12262: $is_camtasia = 8;
12263: }
1.1075.2.59 raeburn 12264: }
1.1067 raeburn 12265: }
12266: }
12267: my $output;
12268: if ($is_camtasia) {
12269: $output = <<"ENDCAM";
12270: <script type="text/javascript" language="Javascript">
12271: // <![CDATA[
12272:
12273: function camtasiaToggle() {
12274: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12275: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 12276: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12277: document.getElementById('camtasia_titles').style.display='block';
12278: } else {
12279: document.getElementById('camtasia_titles').style.display='none';
12280: }
12281: }
12282: }
12283: return;
12284: }
12285:
12286: // ]]>
12287: </script>
12288: <p>$lt{'camt'}</p>
12289: ENDCAM
1.1065 raeburn 12290: } else {
1.1067 raeburn 12291: $output = '<p>'.$lt{'this'};
12292: if ($info eq '') {
12293: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12294: } else {
12295: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12296: '<div><pre>'.$info.'</pre></div>';
12297: }
1.1065 raeburn 12298: }
1.1067 raeburn 12299: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12300: my $duplicates;
12301: my $num = 0;
12302: if (ref($dirlist) eq 'ARRAY') {
12303: foreach my $item (@{$dirlist}) {
12304: if (ref($item) eq 'ARRAY') {
12305: if (exists($toplevel{$item->[0]})) {
12306: $duplicates .=
12307: &start_data_table_row().
12308: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12309: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12310: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12311: 'value="1" />'.&mt('Yes').'</label>'.
12312: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12313: '<td>'.$item->[0].'</td>';
12314: if ($item->[2]) {
12315: $duplicates .= '<td>'.&mt('Directory').'</td>';
12316: } else {
12317: $duplicates .= '<td>'.&mt('File').'</td>';
12318: }
12319: $duplicates .= '<td>'.$item->[3].'</td>'.
12320: '<td>'.
12321: &Apache::lonlocal::locallocaltime($item->[4]).
12322: '</td>'.
12323: &end_data_table_row();
12324: $num ++;
12325: }
12326: }
12327: }
12328: }
12329: my $itemcount;
12330: if (@paths > 0) {
12331: $itemcount = scalar(@paths);
12332: } else {
12333: $itemcount = 1;
12334: }
1.1067 raeburn 12335: if ($is_camtasia) {
12336: $output .= $lt{'auto'}.'<br />'.
12337: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12338: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12339: $lt{'yes'}.'</label> <label>'.
12340: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12341: $lt{'no'}.'</label></span><br />'.
12342: '<div id="camtasia_titles" style="display:block">'.
12343: &Apache::lonhtmlcommon::start_pick_box().
12344: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12345: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12346: &Apache::lonhtmlcommon::row_closure().
12347: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12348: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12349: &Apache::lonhtmlcommon::row_closure(1).
12350: &Apache::lonhtmlcommon::end_pick_box().
12351: '</div>';
12352: }
1.1065 raeburn 12353: $output .=
12354: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12355: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12356: "\n";
1.1065 raeburn 12357: if ($duplicates ne '') {
12358: $output .= '<p><span class="LC_warning">'.
12359: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12360: &start_data_table().
12361: &start_data_table_header_row().
12362: '<th>'.&mt('Overwrite?').'</th>'.
12363: '<th>'.&mt('Name').'</th>'.
12364: '<th>'.&mt('Type').'</th>'.
12365: '<th>'.&mt('Size').'</th>'.
12366: '<th>'.&mt('Last modified').'</th>'.
12367: &end_data_table_header_row().
12368: $duplicates.
12369: &end_data_table().
12370: '</p>';
12371: }
1.1067 raeburn 12372: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12373: if (ref($hiddenelements) eq 'HASH') {
12374: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12375: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12376: }
12377: }
12378: $output .= <<"END";
1.1067 raeburn 12379: <br />
1.1053 raeburn 12380: <input type="submit" name="decompress" value="$lt{'extr'}" />
12381: </form>
12382: $noextract
12383: END
12384: return $output;
12385: }
12386:
1.1065 raeburn 12387: sub decompression_utility {
12388: my ($program) = @_;
12389: my @utilities = ('tar','gunzip','bunzip2','unzip');
12390: my $location;
12391: if (grep(/^\Q$program\E$/,@utilities)) {
12392: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12393: '/usr/sbin/') {
12394: if (-x $dir.$program) {
12395: $location = $dir.$program;
12396: last;
12397: }
12398: }
12399: }
12400: return $location;
12401: }
12402:
12403: sub list_archive_contents {
12404: my ($file,$pathsref) = @_;
12405: my (@cmd,$output);
12406: my $needsregexp;
12407: if ($file =~ /\.zip$/) {
12408: @cmd = (&decompression_utility('unzip'),"-l");
12409: $needsregexp = 1;
12410: } elsif (($file =~ m/\.tar\.gz$/) ||
12411: ($file =~ /\.tgz$/)) {
12412: @cmd = (&decompression_utility('tar'),"-ztf");
12413: } elsif ($file =~ /\.tar\.bz2$/) {
12414: @cmd = (&decompression_utility('tar'),"-jtf");
12415: } elsif ($file =~ m|\.tar$|) {
12416: @cmd = (&decompression_utility('tar'),"-tf");
12417: }
12418: if (@cmd) {
12419: undef($!);
12420: undef($@);
12421: if (open(my $fh,"-|", @cmd, $file)) {
12422: while (my $line = <$fh>) {
12423: $output .= $line;
12424: chomp($line);
12425: my $item;
12426: if ($needsregexp) {
12427: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12428: } else {
12429: $item = $line;
12430: }
12431: if ($item ne '') {
12432: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12433: push(@{$pathsref},$item);
12434: }
12435: }
12436: }
12437: close($fh);
12438: }
12439: }
12440: return $output;
12441: }
12442:
1.1053 raeburn 12443: sub decompress_uploaded_file {
12444: my ($file,$dir) = @_;
12445: &Apache::lonnet::appenv({'cgi.file' => $file});
12446: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12447: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12448: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12449: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12450: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12451: my $decompressed = $env{'cgi.decompressed'};
12452: &Apache::lonnet::delenv('cgi.file');
12453: &Apache::lonnet::delenv('cgi.dir');
12454: &Apache::lonnet::delenv('cgi.decompressed');
12455: return ($decompressed,$result);
12456: }
12457:
1.1055 raeburn 12458: sub process_decompression {
12459: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12460: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12461: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12462: &mt('Unexpected file path.').'</p>'."\n";
12463: }
12464: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12465: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12466: &mt('Unexpected course context.').'</p>'."\n";
12467: }
12468: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12469: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12470: &mt('Filename contained unexpected characters.').'</p>'."\n";
12471: }
1.1055 raeburn 12472: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12473: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12474: $error = &mt('Filename not a supported archive file type.').
12475: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12476: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12477: } else {
12478: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12479: if ($docuhome eq 'no_host') {
12480: $error = &mt('Could not determine home server for course.');
12481: } else {
12482: my @ids=&Apache::lonnet::current_machine_ids();
12483: my $currdir = "$dir_root/$destination";
12484: if (grep(/^\Q$docuhome\E$/,@ids)) {
12485: $dir = &LONCAPA::propath($docudom,$docuname).
12486: "$dir_root/$destination";
12487: } else {
12488: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12489: "$dir_root/$docudom/$docuname/$destination";
12490: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12491: $error = &mt('Archive file not found.');
12492: }
12493: }
1.1065 raeburn 12494: my (@to_overwrite,@to_skip);
12495: if ($env{'form.archive_overwrite_total'} > 0) {
12496: my $total = $env{'form.archive_overwrite_total'};
12497: for (my $i=0; $i<$total; $i++) {
12498: if ($env{'form.archive_overwrite_'.$i} == 1) {
12499: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12500: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12501: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12502: }
12503: }
12504: }
12505: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12506: my $numoverwrite = scalar(@to_overwrite);
12507: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12508: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12509: } elsif ($dir eq '') {
1.1055 raeburn 12510: $error = &mt('Directory containing archive file unavailable.');
12511: } elsif (!$error) {
1.1065 raeburn 12512: my ($decompressed,$display);
1.1075.2.128 raeburn 12513: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12514: my $tempdir = time.'_'.$$.int(rand(10000));
12515: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12516: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12517: ($decompressed,$display) =
12518: &decompress_uploaded_file($file,"$dir/$tempdir");
12519: foreach my $item (@to_skip) {
12520: if (($item ne '') && ($item !~ /\.\./)) {
12521: if (-f "$dir/$tempdir/$item") {
12522: unlink("$dir/$tempdir/$item");
12523: } elsif (-d "$dir/$tempdir/$item") {
12524: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12525: }
12526: }
12527: }
12528: foreach my $item (@to_overwrite) {
12529: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12530: if (($item ne '') && ($item !~ /\.\./)) {
12531: if (-f "$dir/$item") {
12532: unlink("$dir/$item");
12533: } elsif (-d "$dir/$item") {
12534: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12535: }
12536: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12537: }
1.1065 raeburn 12538: }
12539: }
1.1075.2.128 raeburn 12540: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12541: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12542: }
1.1065 raeburn 12543: }
12544: } else {
12545: ($decompressed,$display) =
12546: &decompress_uploaded_file($file,$dir);
12547: }
1.1055 raeburn 12548: if ($decompressed eq 'ok') {
1.1065 raeburn 12549: $output = '<p class="LC_info">'.
12550: &mt('Files extracted successfully from archive.').
12551: '</p>'."\n";
1.1055 raeburn 12552: my ($warning,$result,@contents);
12553: my ($newdirlistref,$newlisterror) =
12554: &Apache::lonnet::dirlist($currdir,$docudom,
12555: $docuname,1);
12556: my (%is_dir,%changes,@newitems);
12557: my $dirptr = 16384;
1.1065 raeburn 12558: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12559: foreach my $dir_line (@{$newdirlistref}) {
12560: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12561: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12562: push(@newitems,$item);
12563: if ($dirptr&$testdir) {
12564: $is_dir{$item} = 1;
12565: }
12566: $changes{$item} = 1;
12567: }
12568: }
12569: }
12570: if (keys(%changes) > 0) {
12571: foreach my $item (sort(@newitems)) {
12572: if ($changes{$item}) {
12573: push(@contents,$item);
12574: }
12575: }
12576: }
12577: if (@contents > 0) {
1.1067 raeburn 12578: my $wantform;
12579: unless ($env{'form.autoextract_camtasia'}) {
12580: $wantform = 1;
12581: }
1.1056 raeburn 12582: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12583: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12584: $currdir,\%is_dir,
12585: \%children,\%parent,
1.1056 raeburn 12586: \@contents,\%dirorder,
12587: \%titles,$wantform);
1.1055 raeburn 12588: if ($datatable ne '') {
12589: $output .= &archive_options_form('decompressed',$datatable,
12590: $count,$hiddenelem);
1.1065 raeburn 12591: my $startcount = 6;
1.1055 raeburn 12592: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12593: \%titles,\%children);
1.1055 raeburn 12594: }
1.1067 raeburn 12595: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12596: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12597: my %displayed;
12598: my $total = 1;
12599: $env{'form.archive_directory'} = [];
12600: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12601: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12602: $path =~ s{/$}{};
12603: my $item;
12604: if ($path ne '') {
12605: $item = "$path/$titles{$i}";
12606: } else {
12607: $item = $titles{$i};
12608: }
12609: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12610: if ($item eq $contents[0]) {
12611: push(@{$env{'form.archive_directory'}},$i);
12612: $env{'form.archive_'.$i} = 'display';
12613: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12614: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12615: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12616: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12617: $env{'form.archive_'.$i} = 'display';
12618: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12619: $displayed{'web'} = $i;
12620: } else {
1.1075.2.59 raeburn 12621: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12622: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12623: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12624: push(@{$env{'form.archive_directory'}},$i);
12625: }
12626: $env{'form.archive_'.$i} = 'dependency';
12627: }
12628: $total ++;
12629: }
12630: for (my $i=1; $i<$total; $i++) {
12631: next if ($i == $displayed{'web'});
12632: next if ($i == $displayed{'folder'});
12633: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12634: }
12635: $env{'form.phase'} = 'decompress_cleanup';
12636: $env{'form.archivedelete'} = 1;
12637: $env{'form.archive_count'} = $total-1;
12638: $output .=
12639: &process_extracted_files('coursedocs',$docudom,
12640: $docuname,$destination,
12641: $dir_root,$hiddenelem);
12642: }
1.1055 raeburn 12643: } else {
12644: $warning = &mt('No new items extracted from archive file.');
12645: }
12646: } else {
12647: $output = $display;
12648: $error = &mt('An error occurred during extraction from the archive file.');
12649: }
12650: }
12651: }
12652: }
12653: if ($error) {
12654: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12655: $error.'</p>'."\n";
12656: }
12657: if ($warning) {
12658: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12659: }
12660: return $output;
12661: }
12662:
12663: sub get_extracted {
1.1056 raeburn 12664: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12665: $titles,$wantform) = @_;
1.1055 raeburn 12666: my $count = 0;
12667: my $depth = 0;
12668: my $datatable;
1.1056 raeburn 12669: my @hierarchy;
1.1055 raeburn 12670: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12671: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12672: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12673: foreach my $item (@{$contents}) {
12674: $count ++;
1.1056 raeburn 12675: @{$dirorder->{$count}} = @hierarchy;
12676: $titles->{$count} = $item;
1.1055 raeburn 12677: &archive_hierarchy($depth,$count,$parent,$children);
12678: if ($wantform) {
12679: $datatable .= &archive_row($is_dir->{$item},$item,
12680: $currdir,$depth,$count);
12681: }
12682: if ($is_dir->{$item}) {
12683: $depth ++;
1.1056 raeburn 12684: push(@hierarchy,$count);
12685: $parent->{$depth} = $count;
1.1055 raeburn 12686: $datatable .=
12687: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12688: \$depth,\$count,\@hierarchy,$dirorder,
12689: $children,$parent,$titles,$wantform);
1.1055 raeburn 12690: $depth --;
1.1056 raeburn 12691: pop(@hierarchy);
1.1055 raeburn 12692: }
12693: }
12694: return ($count,$datatable);
12695: }
12696:
12697: sub recurse_extracted_archive {
1.1056 raeburn 12698: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12699: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12700: my $result='';
1.1056 raeburn 12701: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12702: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12703: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12704: return $result;
12705: }
12706: my $dirptr = 16384;
12707: my ($newdirlistref,$newlisterror) =
12708: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12709: if (ref($newdirlistref) eq 'ARRAY') {
12710: foreach my $dir_line (@{$newdirlistref}) {
12711: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12712: unless ($item =~ /^\.+$/) {
12713: $$count ++;
1.1056 raeburn 12714: @{$dirorder->{$$count}} = @{$hierarchy};
12715: $titles->{$$count} = $item;
1.1055 raeburn 12716: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12717:
1.1055 raeburn 12718: my $is_dir;
12719: if ($dirptr&$testdir) {
12720: $is_dir = 1;
12721: }
12722: if ($wantform) {
12723: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12724: }
12725: if ($is_dir) {
12726: $$depth ++;
1.1056 raeburn 12727: push(@{$hierarchy},$$count);
12728: $parent->{$$depth} = $$count;
1.1055 raeburn 12729: $result .=
12730: &recurse_extracted_archive("$currdir/$item",$docudom,
12731: $docuname,$depth,$count,
1.1056 raeburn 12732: $hierarchy,$dirorder,$children,
12733: $parent,$titles,$wantform);
1.1055 raeburn 12734: $$depth --;
1.1056 raeburn 12735: pop(@{$hierarchy});
1.1055 raeburn 12736: }
12737: }
12738: }
12739: }
12740: return $result;
12741: }
12742:
12743: sub archive_hierarchy {
12744: my ($depth,$count,$parent,$children) =@_;
12745: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12746: if (exists($parent->{$depth})) {
12747: $children->{$parent->{$depth}} .= $count.':';
12748: }
12749: }
12750: return;
12751: }
12752:
12753: sub archive_row {
12754: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12755: my ($name) = ($item =~ m{([^/]+)$});
12756: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12757: 'display' => 'Add as file',
1.1055 raeburn 12758: 'dependency' => 'Include as dependency',
12759: 'discard' => 'Discard',
12760: );
12761: if ($is_dir) {
1.1059 raeburn 12762: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12763: }
1.1056 raeburn 12764: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12765: my $offset = 0;
1.1055 raeburn 12766: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12767: $offset ++;
1.1065 raeburn 12768: if ($action ne 'display') {
12769: $offset ++;
12770: }
1.1055 raeburn 12771: $output .= '<td><span class="LC_nobreak">'.
12772: '<label><input type="radio" name="archive_'.$count.
12773: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12774: my $text = $choices{$action};
12775: if ($is_dir) {
12776: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12777: if ($action eq 'display') {
1.1059 raeburn 12778: $text = &mt('Add as folder');
1.1055 raeburn 12779: }
1.1056 raeburn 12780: } else {
12781: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12782:
12783: }
12784: $output .= ' /> '.$choices{$action}.'</label></span>';
12785: if ($action eq 'dependency') {
12786: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12787: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12788: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12789: '<option value=""></option>'."\n".
12790: '</select>'."\n".
12791: '</div>';
1.1059 raeburn 12792: } elsif ($action eq 'display') {
12793: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12794: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12795: '</div>';
1.1055 raeburn 12796: }
1.1056 raeburn 12797: $output .= '</td>';
1.1055 raeburn 12798: }
12799: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12800: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12801: for (my $i=0; $i<$depth; $i++) {
12802: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12803: }
12804: if ($is_dir) {
12805: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12806: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12807: } else {
12808: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12809: }
12810: $output .= ' '.$name.'</td>'."\n".
12811: &end_data_table_row();
12812: return $output;
12813: }
12814:
12815: sub archive_options_form {
1.1065 raeburn 12816: my ($form,$display,$count,$hiddenelem) = @_;
12817: my %lt = &Apache::lonlocal::texthash(
12818: perm => 'Permanently remove archive file?',
12819: hows => 'How should each extracted item be incorporated in the course?',
12820: cont => 'Content actions for all',
12821: addf => 'Add as folder/file',
12822: incd => 'Include as dependency for a displayed file',
12823: disc => 'Discard',
12824: no => 'No',
12825: yes => 'Yes',
12826: save => 'Save',
12827: );
12828: my $output = <<"END";
12829: <form name="$form" method="post" action="">
12830: <p><span class="LC_nobreak">$lt{'perm'}
12831: <label>
12832: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12833: </label>
12834:
12835: <label>
12836: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12837: </span>
12838: </p>
12839: <input type="hidden" name="phase" value="decompress_cleanup" />
12840: <br />$lt{'hows'}
12841: <div class="LC_columnSection">
12842: <fieldset>
12843: <legend>$lt{'cont'}</legend>
12844: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12845: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12846: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12847: </fieldset>
12848: </div>
12849: END
12850: return $output.
1.1055 raeburn 12851: &start_data_table()."\n".
1.1065 raeburn 12852: $display."\n".
1.1055 raeburn 12853: &end_data_table()."\n".
12854: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12855: $hiddenelem.
1.1065 raeburn 12856: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12857: '</form>';
12858: }
12859:
12860: sub archive_javascript {
1.1056 raeburn 12861: my ($startcount,$numitems,$titles,$children) = @_;
12862: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12863: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12864: my $scripttag = <<START;
12865: <script type="text/javascript">
12866: // <![CDATA[
12867:
12868: function checkAll(form,prefix) {
12869: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12870: for (var i=0; i < form.elements.length; i++) {
12871: var id = form.elements[i].id;
12872: if ((id != '') && (id != undefined)) {
12873: if (idstr.test(id)) {
12874: if (form.elements[i].type == 'radio') {
12875: form.elements[i].checked = true;
1.1056 raeburn 12876: var nostart = i-$startcount;
1.1059 raeburn 12877: var offset = nostart%7;
12878: var count = (nostart-offset)/7;
1.1056 raeburn 12879: dependencyCheck(form,count,offset);
1.1055 raeburn 12880: }
12881: }
12882: }
12883: }
12884: }
12885:
12886: function propagateCheck(form,count) {
12887: if (count > 0) {
1.1059 raeburn 12888: var startelement = $startcount + ((count-1) * 7);
12889: for (var j=1; j<6; j++) {
12890: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12891: var item = startelement + j;
12892: if (form.elements[item].type == 'radio') {
12893: if (form.elements[item].checked) {
12894: containerCheck(form,count,j);
12895: break;
12896: }
1.1055 raeburn 12897: }
12898: }
12899: }
12900: }
12901: }
12902:
12903: numitems = $numitems
1.1056 raeburn 12904: var titles = new Array(numitems);
12905: var parents = new Array(numitems);
1.1055 raeburn 12906: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12907: parents[i] = new Array;
1.1055 raeburn 12908: }
1.1059 raeburn 12909: var maintitle = '$maintitle';
1.1055 raeburn 12910:
12911: START
12912:
1.1056 raeburn 12913: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12914: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12915: for (my $i=0; $i<@contents; $i ++) {
12916: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12917: }
12918: }
12919:
1.1056 raeburn 12920: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12921: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12922: }
12923:
1.1055 raeburn 12924: $scripttag .= <<END;
12925:
12926: function containerCheck(form,count,offset) {
12927: if (count > 0) {
1.1056 raeburn 12928: dependencyCheck(form,count,offset);
1.1059 raeburn 12929: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12930: form.elements[item].checked = true;
12931: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12932: if (parents[count].length > 0) {
12933: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12934: containerCheck(form,parents[count][j],offset);
12935: }
12936: }
12937: }
12938: }
12939: }
12940:
12941: function dependencyCheck(form,count,offset) {
12942: if (count > 0) {
1.1059 raeburn 12943: var chosen = (offset+$startcount)+7*(count-1);
12944: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12945: var currtype = form.elements[depitem].type;
12946: if (form.elements[chosen].value == 'dependency') {
12947: document.getElementById('arc_depon_'+count).style.display='block';
12948: form.elements[depitem].options.length = 0;
12949: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12950: for (var i=1; i<=numitems; i++) {
12951: if (i == count) {
12952: continue;
12953: }
1.1059 raeburn 12954: var startelement = $startcount + (i-1) * 7;
12955: for (var j=1; j<6; j++) {
12956: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12957: var item = startelement + j;
12958: if (form.elements[item].type == 'radio') {
12959: if (form.elements[item].checked) {
12960: if (form.elements[item].value == 'display') {
12961: var n = form.elements[depitem].options.length;
12962: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12963: }
12964: }
12965: }
12966: }
12967: }
12968: }
12969: } else {
12970: document.getElementById('arc_depon_'+count).style.display='none';
12971: form.elements[depitem].options.length = 0;
12972: form.elements[depitem].options[0] = new Option('Select','',true,true);
12973: }
1.1059 raeburn 12974: titleCheck(form,count,offset);
1.1056 raeburn 12975: }
12976: }
12977:
12978: function propagateSelect(form,count,offset) {
12979: if (count > 0) {
1.1065 raeburn 12980: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12981: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12982: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12983: if (parents[count].length > 0) {
12984: for (var j=0; j<parents[count].length; j++) {
12985: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12986: }
12987: }
12988: }
12989: }
12990: }
1.1056 raeburn 12991:
12992: function containerSelect(form,count,offset,picked) {
12993: if (count > 0) {
1.1065 raeburn 12994: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12995: if (form.elements[item].type == 'radio') {
12996: if (form.elements[item].value == 'dependency') {
12997: if (form.elements[item+1].type == 'select-one') {
12998: for (var i=0; i<form.elements[item+1].options.length; i++) {
12999: if (form.elements[item+1].options[i].value == picked) {
13000: form.elements[item+1].selectedIndex = i;
13001: break;
13002: }
13003: }
13004: }
13005: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13006: if (parents[count].length > 0) {
13007: for (var j=0; j<parents[count].length; j++) {
13008: containerSelect(form,parents[count][j],offset,picked);
13009: }
13010: }
13011: }
13012: }
13013: }
13014: }
13015: }
13016:
1.1059 raeburn 13017: function titleCheck(form,count,offset) {
13018: if (count > 0) {
13019: var chosen = (offset+$startcount)+7*(count-1);
13020: var depitem = $startcount + ((count-1) * 7) + 2;
13021: var currtype = form.elements[depitem].type;
13022: if (form.elements[chosen].value == 'display') {
13023: document.getElementById('arc_title_'+count).style.display='block';
13024: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13025: document.getElementById('archive_title_'+count).value=maintitle;
13026: }
13027: } else {
13028: document.getElementById('arc_title_'+count).style.display='none';
13029: if (currtype == 'text') {
13030: document.getElementById('archive_title_'+count).value='';
13031: }
13032: }
13033: }
13034: return;
13035: }
13036:
1.1055 raeburn 13037: // ]]>
13038: </script>
13039: END
13040: return $scripttag;
13041: }
13042:
13043: sub process_extracted_files {
1.1067 raeburn 13044: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13045: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 13046: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13047: my @ids=&Apache::lonnet::current_machine_ids();
13048: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13049: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13050: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13051: if (grep(/^\Q$docuhome\E$/,@ids)) {
13052: $prefix = &LONCAPA::propath($docudom,$docuname);
13053: $pathtocheck = "$dir_root/$destination";
13054: $dir = $dir_root;
13055: $ishome = 1;
13056: } else {
13057: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13058: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 13059: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13060: }
13061: my $currdir = "$dir_root/$destination";
13062: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13063: if ($env{'form.folderpath'}) {
13064: my @items = split('&',$env{'form.folderpath'});
13065: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 13066: if ($env{'form.folderpath'} =~ /\:1$/) {
13067: $containers{'0'}='page';
13068: } else {
13069: $containers{'0'}='sequence';
13070: }
1.1055 raeburn 13071: }
13072: my @archdirs = &get_env_multiple('form.archive_directory');
13073: if ($numitems) {
13074: for (my $i=1; $i<=$numitems; $i++) {
13075: my $path = $env{'form.archive_content_'.$i};
13076: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13077: my $item = $1;
13078: $toplevelitems{$item} = $i;
13079: if (grep(/^\Q$i\E$/,@archdirs)) {
13080: $is_dir{$item} = 1;
13081: }
13082: }
13083: }
13084: }
1.1067 raeburn 13085: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13086: if (keys(%toplevelitems) > 0) {
13087: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13088: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13089: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13090: }
1.1066 raeburn 13091: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13092: if ($numitems) {
13093: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 13094: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13095: my $path = $env{'form.archive_content_'.$i};
13096: if ($path =~ /^\Q$pathtocheck\E/) {
13097: if ($env{'form.archive_'.$i} eq 'discard') {
13098: if ($prefix ne '' && $path ne '') {
13099: if (-e $prefix.$path) {
1.1066 raeburn 13100: if ((@archdirs > 0) &&
13101: (grep(/^\Q$i\E$/,@archdirs))) {
13102: $todeletedir{$prefix.$path} = 1;
13103: } else {
13104: $todelete{$prefix.$path} = 1;
13105: }
1.1055 raeburn 13106: }
13107: }
13108: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13109: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13110: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13111: $docstitle = $env{'form.archive_title_'.$i};
13112: if ($docstitle eq '') {
13113: $docstitle = $title;
13114: }
1.1055 raeburn 13115: $outer = 0;
1.1056 raeburn 13116: if (ref($dirorder{$i}) eq 'ARRAY') {
13117: if (@{$dirorder{$i}} > 0) {
13118: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13119: if ($env{'form.archive_'.$item} eq 'display') {
13120: $outer = $item;
13121: last;
13122: }
13123: }
13124: }
13125: }
13126: my ($errtext,$fatal) =
13127: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13128: '/'.$folders{$outer}.'.'.
13129: $containers{$outer});
13130: next if ($fatal);
13131: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13132: if ($context eq 'coursedocs') {
1.1056 raeburn 13133: $mapinner{$i} = time;
1.1055 raeburn 13134: $folders{$i} = 'default_'.$mapinner{$i};
13135: $containers{$i} = 'sequence';
13136: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13137: $folders{$i}.'.'.$containers{$i};
13138: my $newidx = &LONCAPA::map::getresidx();
13139: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13140: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13141: push(@LONCAPA::map::order,$newidx);
13142: my ($outtext,$errtext) =
13143: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13144: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 13145: '.'.$containers{$outer},1,1);
1.1056 raeburn 13146: $newseqid{$i} = $newidx;
1.1067 raeburn 13147: unless ($errtext) {
1.1075.2.128 raeburn 13148: $result .= '<li>'.&mt('Folder: [_1] added to course',
13149: &HTML::Entities::encode($docstitle,'<>&"'))..
13150: '</li>'."\n";
1.1067 raeburn 13151: }
1.1055 raeburn 13152: }
13153: } else {
13154: if ($context eq 'coursedocs') {
13155: my $newidx=&LONCAPA::map::getresidx();
13156: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13157: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13158: $title;
1.1075.2.128 raeburn 13159: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13160: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13161: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 13162: }
1.1075.2.128 raeburn 13163: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13164: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13165: }
13166: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13167: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13168: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13169: unless ($ishome) {
13170: my $fetch = "$newdest{$i}/$title";
13171: $fetch =~ s/^\Q$prefix$dir\E//;
13172: $prompttofetch{$fetch} = 1;
13173: }
13174: }
13175: }
13176: $LONCAPA::map::resources[$newidx]=
13177: $docstitle.':'.$url.':false:normal:res';
13178: push(@LONCAPA::map::order, $newidx);
13179: my ($outtext,$errtext)=
13180: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13181: $docuname.'/'.$folders{$outer}.
13182: '.'.$containers{$outer},1,1);
13183: unless ($errtext) {
13184: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13185: $result .= '<li>'.&mt('File: [_1] added to course',
13186: &HTML::Entities::encode($docstitle,'<>&"')).
13187: '</li>'."\n";
13188: }
1.1067 raeburn 13189: }
1.1075.2.128 raeburn 13190: } else {
13191: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13192: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 13193: }
1.1055 raeburn 13194: }
13195: }
1.1075.2.11 raeburn 13196: }
13197: } else {
1.1075.2.128 raeburn 13198: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13199: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 13200: }
13201: }
13202: for (my $i=1; $i<=$numitems; $i++) {
13203: next unless ($env{'form.archive_'.$i} eq 'dependency');
13204: my $path = $env{'form.archive_content_'.$i};
13205: if ($path =~ /^\Q$pathtocheck\E/) {
13206: my ($title) = ($path =~ m{/([^/]+)$});
13207: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13208: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13209: if (ref($dirorder{$i}) eq 'ARRAY') {
13210: my ($itemidx,$fullpath,$relpath);
13211: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13212: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13213: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 13214: if ($dirorder{$i}->[$j] eq $container) {
13215: $itemidx = $j;
1.1056 raeburn 13216: }
13217: }
1.1075.2.11 raeburn 13218: }
13219: if ($itemidx eq '') {
13220: $itemidx = 0;
13221: }
13222: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13223: if ($mapinner{$referrer{$i}}) {
13224: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13225: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13226: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13227: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13228: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13229: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13230: if (!-e $fullpath) {
13231: mkdir($fullpath,0755);
1.1056 raeburn 13232: }
13233: }
1.1075.2.11 raeburn 13234: } else {
13235: last;
1.1056 raeburn 13236: }
1.1075.2.11 raeburn 13237: }
13238: }
13239: } elsif ($newdest{$referrer{$i}}) {
13240: $fullpath = $newdest{$referrer{$i}};
13241: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13242: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13243: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13244: last;
13245: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13246: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13247: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13248: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13249: if (!-e $fullpath) {
13250: mkdir($fullpath,0755);
1.1056 raeburn 13251: }
13252: }
1.1075.2.11 raeburn 13253: } else {
13254: last;
1.1056 raeburn 13255: }
1.1075.2.11 raeburn 13256: }
13257: }
13258: if ($fullpath ne '') {
13259: if (-e "$prefix$path") {
1.1075.2.128 raeburn 13260: unless (rename("$prefix$path","$fullpath/$title")) {
13261: $warning .= &mt('Failed to rename dependency').'<br />';
13262: }
1.1075.2.11 raeburn 13263: }
13264: if (-e "$fullpath/$title") {
13265: my $showpath;
13266: if ($relpath ne '') {
13267: $showpath = "$relpath/$title";
13268: } else {
13269: $showpath = "/$title";
1.1056 raeburn 13270: }
1.1075.2.128 raeburn 13271: $result .= '<li>'.&mt('[_1] included as a dependency',
13272: &HTML::Entities::encode($showpath,'<>&"')).
13273: '</li>'."\n";
13274: unless ($ishome) {
13275: my $fetch = "$fullpath/$title";
13276: $fetch =~ s/^\Q$prefix$dir\E//;
13277: $prompttofetch{$fetch} = 1;
13278: }
1.1055 raeburn 13279: }
13280: }
13281: }
1.1075.2.11 raeburn 13282: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13283: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 13284: &HTML::Entities::encode($path,'<>&"'),
13285: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13286: '<br />';
1.1055 raeburn 13287: }
13288: } else {
1.1075.2.128 raeburn 13289: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13290: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13291: }
13292: }
13293: if (keys(%todelete)) {
13294: foreach my $key (keys(%todelete)) {
13295: unlink($key);
1.1066 raeburn 13296: }
13297: }
13298: if (keys(%todeletedir)) {
13299: foreach my $key (keys(%todeletedir)) {
13300: rmdir($key);
13301: }
13302: }
13303: foreach my $dir (sort(keys(%is_dir))) {
13304: if (($pathtocheck ne '') && ($dir ne '')) {
13305: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13306: }
13307: }
1.1067 raeburn 13308: if ($result ne '') {
13309: $output .= '<ul>'."\n".
13310: $result."\n".
13311: '</ul>';
13312: }
13313: unless ($ishome) {
13314: my $replicationfail;
13315: foreach my $item (keys(%prompttofetch)) {
13316: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13317: unless ($fetchresult eq 'ok') {
13318: $replicationfail .= '<li>'.$item.'</li>'."\n";
13319: }
13320: }
13321: if ($replicationfail) {
13322: $output .= '<p class="LC_error">'.
13323: &mt('Course home server failed to retrieve:').'<ul>'.
13324: $replicationfail.
13325: '</ul></p>';
13326: }
13327: }
1.1055 raeburn 13328: } else {
13329: $warning = &mt('No items found in archive.');
13330: }
13331: if ($error) {
13332: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13333: $error.'</p>'."\n";
13334: }
13335: if ($warning) {
13336: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13337: }
13338: return $output;
13339: }
13340:
1.1066 raeburn 13341: sub cleanup_empty_dirs {
13342: my ($path) = @_;
13343: if (($path ne '') && (-d $path)) {
13344: if (opendir(my $dirh,$path)) {
13345: my @dircontents = grep(!/^\./,readdir($dirh));
13346: my $numitems = 0;
13347: foreach my $item (@dircontents) {
13348: if (-d "$path/$item") {
1.1075.2.28 raeburn 13349: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13350: if (-e "$path/$item") {
13351: $numitems ++;
13352: }
13353: } else {
13354: $numitems ++;
13355: }
13356: }
13357: if ($numitems == 0) {
13358: rmdir($path);
13359: }
13360: closedir($dirh);
13361: }
13362: }
13363: return;
13364: }
13365:
1.41 ng 13366: =pod
1.45 matthew 13367:
1.1075.2.56 raeburn 13368: =item * &get_folder_hierarchy()
1.1068 raeburn 13369:
13370: Provides hierarchy of names of folders/sub-folders containing the current
13371: item,
13372:
13373: Inputs: 3
13374: - $navmap - navmaps object
13375:
13376: - $map - url for map (either the trigger itself, or map containing
13377: the resource, which is the trigger).
13378:
13379: - $showitem - 1 => show title for map itself; 0 => do not show.
13380:
13381: Outputs: 1 @pathitems - array of folder/subfolder names.
13382:
13383: =cut
13384:
13385: sub get_folder_hierarchy {
13386: my ($navmap,$map,$showitem) = @_;
13387: my @pathitems;
13388: if (ref($navmap)) {
13389: my $mapres = $navmap->getResourceByUrl($map);
13390: if (ref($mapres)) {
13391: my $pcslist = $mapres->map_hierarchy();
13392: if ($pcslist ne '') {
13393: my @pcs = split(/,/,$pcslist);
13394: foreach my $pc (@pcs) {
13395: if ($pc == 1) {
1.1075.2.38 raeburn 13396: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13397: } else {
13398: my $res = $navmap->getByMapPc($pc);
13399: if (ref($res)) {
13400: my $title = $res->compTitle();
13401: $title =~ s/\W+/_/g;
13402: if ($title ne '') {
13403: push(@pathitems,$title);
13404: }
13405: }
13406: }
13407: }
13408: }
1.1071 raeburn 13409: if ($showitem) {
13410: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13411: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13412: } else {
13413: my $maptitle = $mapres->compTitle();
13414: $maptitle =~ s/\W+/_/g;
13415: if ($maptitle ne '') {
13416: push(@pathitems,$maptitle);
13417: }
1.1068 raeburn 13418: }
13419: }
13420: }
13421: }
13422: return @pathitems;
13423: }
13424:
13425: =pod
13426:
1.1015 raeburn 13427: =item * &get_turnedin_filepath()
13428:
13429: Determines path in a user's portfolio file for storage of files uploaded
13430: to a specific essayresponse or dropbox item.
13431:
13432: Inputs: 3 required + 1 optional.
13433: $symb is symb for resource, $uname and $udom are for current user (required).
13434: $caller is optional (can be "submission", if routine is called when storing
13435: an upoaded file when "Submit Answer" button was pressed).
13436:
13437: Returns array containing $path and $multiresp.
13438: $path is path in portfolio. $multiresp is 1 if this resource contains more
13439: than one file upload item. Callers of routine should append partid as a
13440: subdirectory to $path in cases where $multiresp is 1.
13441:
13442: Called by: homework/essayresponse.pm and homework/structuretags.pm
13443:
13444: =cut
13445:
13446: sub get_turnedin_filepath {
13447: my ($symb,$uname,$udom,$caller) = @_;
13448: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13449: my $turnindir;
13450: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13451: $turnindir = $userhash{'turnindir'};
13452: my ($path,$multiresp);
13453: if ($turnindir eq '') {
13454: if ($caller eq 'submission') {
13455: $turnindir = &mt('turned in');
13456: $turnindir =~ s/\W+/_/g;
13457: my %newhash = (
13458: 'turnindir' => $turnindir,
13459: );
13460: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13461: }
13462: }
13463: if ($turnindir ne '') {
13464: $path = '/'.$turnindir.'/';
13465: my ($multipart,$turnin,@pathitems);
13466: my $navmap = Apache::lonnavmaps::navmap->new();
13467: if (defined($navmap)) {
13468: my $mapres = $navmap->getResourceByUrl($map);
13469: if (ref($mapres)) {
13470: my $pcslist = $mapres->map_hierarchy();
13471: if ($pcslist ne '') {
13472: foreach my $pc (split(/,/,$pcslist)) {
13473: my $res = $navmap->getByMapPc($pc);
13474: if (ref($res)) {
13475: my $title = $res->compTitle();
13476: $title =~ s/\W+/_/g;
13477: if ($title ne '') {
1.1075.2.48 raeburn 13478: if (($pc > 1) && (length($title) > 12)) {
13479: $title = substr($title,0,12);
13480: }
1.1015 raeburn 13481: push(@pathitems,$title);
13482: }
13483: }
13484: }
13485: }
13486: my $maptitle = $mapres->compTitle();
13487: $maptitle =~ s/\W+/_/g;
13488: if ($maptitle ne '') {
1.1075.2.48 raeburn 13489: if (length($maptitle) > 12) {
13490: $maptitle = substr($maptitle,0,12);
13491: }
1.1015 raeburn 13492: push(@pathitems,$maptitle);
13493: }
13494: unless ($env{'request.state'} eq 'construct') {
13495: my $res = $navmap->getBySymb($symb);
13496: if (ref($res)) {
13497: my $partlist = $res->parts();
13498: my $totaluploads = 0;
13499: if (ref($partlist) eq 'ARRAY') {
13500: foreach my $part (@{$partlist}) {
13501: my @types = $res->responseType($part);
13502: my @ids = $res->responseIds($part);
13503: for (my $i=0; $i < scalar(@ids); $i++) {
13504: if ($types[$i] eq 'essay') {
13505: my $partid = $part.'_'.$ids[$i];
13506: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13507: $totaluploads ++;
13508: }
13509: }
13510: }
13511: }
13512: if ($totaluploads > 1) {
13513: $multiresp = 1;
13514: }
13515: }
13516: }
13517: }
13518: } else {
13519: return;
13520: }
13521: } else {
13522: return;
13523: }
13524: my $restitle=&Apache::lonnet::gettitle($symb);
13525: $restitle =~ s/\W+/_/g;
13526: if ($restitle eq '') {
13527: $restitle = ($resurl =~ m{/[^/]+$});
13528: if ($restitle eq '') {
13529: $restitle = time;
13530: }
13531: }
1.1075.2.48 raeburn 13532: if (length($restitle) > 12) {
13533: $restitle = substr($restitle,0,12);
13534: }
1.1015 raeburn 13535: push(@pathitems,$restitle);
13536: $path .= join('/',@pathitems);
13537: }
13538: return ($path,$multiresp);
13539: }
13540:
13541: =pod
13542:
1.464 albertel 13543: =back
1.41 ng 13544:
1.112 bowersj2 13545: =head1 CSV Upload/Handling functions
1.38 albertel 13546:
1.41 ng 13547: =over 4
13548:
1.648 raeburn 13549: =item * &upfile_store($r)
1.41 ng 13550:
13551: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13552: needs $env{'form.upfile'}
1.41 ng 13553: returns $datatoken to be put into hidden field
13554:
13555: =cut
1.31 albertel 13556:
13557: sub upfile_store {
13558: my $r=shift;
1.258 albertel 13559: $env{'form.upfile'}=~s/\r/\n/gs;
13560: $env{'form.upfile'}=~s/\f/\n/gs;
13561: $env{'form.upfile'}=~s/\n+/\n/gs;
13562: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13563:
1.1075.2.128 raeburn 13564: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13565: '_enroll_'.$env{'request.course.id'}.'_'.
13566: time.'_'.$$);
13567: return if ($datatoken eq '');
13568:
1.31 albertel 13569: {
1.158 raeburn 13570: my $datafile = $r->dir_config('lonDaemons').
13571: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13572: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13573: print $fh $env{'form.upfile'};
1.158 raeburn 13574: close($fh);
13575: }
1.31 albertel 13576: }
13577: return $datatoken;
13578: }
13579:
1.56 matthew 13580: =pod
13581:
1.1075.2.128 raeburn 13582: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13583:
13584: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13585: $datatoken is the name to assign to the temporary file.
1.258 albertel 13586: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13587:
13588: =cut
1.31 albertel 13589:
13590: sub load_tmp_file {
1.1075.2.128 raeburn 13591: my ($r,$datatoken) = @_;
13592: return if ($datatoken eq '');
1.31 albertel 13593: my @studentdata=();
13594: {
1.158 raeburn 13595: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13596: '/tmp/'.$datatoken.'.tmp';
13597: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13598: @studentdata=<$fh>;
13599: close($fh);
13600: }
1.31 albertel 13601: }
1.258 albertel 13602: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13603: }
13604:
1.1075.2.128 raeburn 13605: sub valid_datatoken {
13606: my ($datatoken) = @_;
1.1075.2.131 raeburn 13607: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13608: return $datatoken;
13609: }
13610: return;
13611: }
13612:
1.56 matthew 13613: =pod
13614:
1.648 raeburn 13615: =item * &upfile_record_sep()
1.41 ng 13616:
13617: Separate uploaded file into records
13618: returns array of records,
1.258 albertel 13619: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13620:
13621: =cut
1.31 albertel 13622:
13623: sub upfile_record_sep {
1.258 albertel 13624: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13625: } else {
1.248 albertel 13626: my @records;
1.258 albertel 13627: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13628: if ($line=~/^\s*$/) { next; }
13629: push(@records,$line);
13630: }
13631: return @records;
1.31 albertel 13632: }
13633: }
13634:
1.56 matthew 13635: =pod
13636:
1.648 raeburn 13637: =item * &record_sep($record)
1.41 ng 13638:
1.258 albertel 13639: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13640:
13641: =cut
13642:
1.263 www 13643: sub takeleft {
13644: my $index=shift;
13645: return substr('0000'.$index,-4,4);
13646: }
13647:
1.31 albertel 13648: sub record_sep {
13649: my $record=shift;
13650: my %components=();
1.258 albertel 13651: if ($env{'form.upfiletype'} eq 'xml') {
13652: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13653: my $i=0;
1.356 albertel 13654: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13655: $field=~s/^(\"|\')//;
13656: $field=~s/(\"|\')$//;
1.263 www 13657: $components{&takeleft($i)}=$field;
1.31 albertel 13658: $i++;
13659: }
1.258 albertel 13660: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13661: my $i=0;
1.356 albertel 13662: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13663: $field=~s/^(\"|\')//;
13664: $field=~s/(\"|\')$//;
1.263 www 13665: $components{&takeleft($i)}=$field;
1.31 albertel 13666: $i++;
13667: }
13668: } else {
1.561 www 13669: my $separator=',';
1.480 banghart 13670: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13671: $separator=';';
1.480 banghart 13672: }
1.31 albertel 13673: my $i=0;
1.561 www 13674: # the character we are looking for to indicate the end of a quote or a record
13675: my $looking_for=$separator;
13676: # do not add the characters to the fields
13677: my $ignore=0;
13678: # we just encountered a separator (or the beginning of the record)
13679: my $just_found_separator=1;
13680: # store the field we are working on here
13681: my $field='';
13682: # work our way through all characters in record
13683: foreach my $character ($record=~/(.)/g) {
13684: if ($character eq $looking_for) {
13685: if ($character ne $separator) {
13686: # Found the end of a quote, again looking for separator
13687: $looking_for=$separator;
13688: $ignore=1;
13689: } else {
13690: # Found a separator, store away what we got
13691: $components{&takeleft($i)}=$field;
13692: $i++;
13693: $just_found_separator=1;
13694: $ignore=0;
13695: $field='';
13696: }
13697: next;
13698: }
13699: # single or double quotation marks after a separator indicate beginning of a quote
13700: # we are now looking for the end of the quote and need to ignore separators
13701: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13702: $looking_for=$character;
13703: next;
13704: }
13705: # ignore would be true after we reached the end of a quote
13706: if ($ignore) { next; }
13707: if (($just_found_separator) && ($character=~/\s/)) { next; }
13708: $field.=$character;
13709: $just_found_separator=0;
1.31 albertel 13710: }
1.561 www 13711: # catch the very last entry, since we never encountered the separator
13712: $components{&takeleft($i)}=$field;
1.31 albertel 13713: }
13714: return %components;
13715: }
13716:
1.144 matthew 13717: ######################################################
13718: ######################################################
13719:
1.56 matthew 13720: =pod
13721:
1.648 raeburn 13722: =item * &upfile_select_html()
1.41 ng 13723:
1.144 matthew 13724: Return HTML code to select a file from the users machine and specify
13725: the file type.
1.41 ng 13726:
13727: =cut
13728:
1.144 matthew 13729: ######################################################
13730: ######################################################
1.31 albertel 13731: sub upfile_select_html {
1.144 matthew 13732: my %Types = (
13733: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13734: semisv => &mt('Semicolon separated values'),
1.144 matthew 13735: space => &mt('Space separated'),
13736: tab => &mt('Tabulator separated'),
13737: # xml => &mt('HTML/XML'),
13738: );
13739: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13740: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13741: foreach my $type (sort(keys(%Types))) {
13742: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13743: }
13744: $Str .= "</select>\n";
13745: return $Str;
1.31 albertel 13746: }
13747:
1.301 albertel 13748: sub get_samples {
13749: my ($records,$toget) = @_;
13750: my @samples=({});
13751: my $got=0;
13752: foreach my $rec (@$records) {
13753: my %temp = &record_sep($rec);
13754: if (! grep(/\S/, values(%temp))) { next; }
13755: if (%temp) {
13756: $samples[$got]=\%temp;
13757: $got++;
13758: if ($got == $toget) { last; }
13759: }
13760: }
13761: return \@samples;
13762: }
13763:
1.144 matthew 13764: ######################################################
13765: ######################################################
13766:
1.56 matthew 13767: =pod
13768:
1.648 raeburn 13769: =item * &csv_print_samples($r,$records)
1.41 ng 13770:
13771: Prints a table of sample values from each column uploaded $r is an
13772: Apache Request ref, $records is an arrayref from
13773: &Apache::loncommon::upfile_record_sep
13774:
13775: =cut
13776:
1.144 matthew 13777: ######################################################
13778: ######################################################
1.31 albertel 13779: sub csv_print_samples {
13780: my ($r,$records) = @_;
1.662 bisitz 13781: my $samples = &get_samples($records,5);
1.301 albertel 13782:
1.594 raeburn 13783: $r->print(&mt('Samples').'<br />'.&start_data_table().
13784: &start_data_table_header_row());
1.356 albertel 13785: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13786: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13787: $r->print(&end_data_table_header_row());
1.301 albertel 13788: foreach my $hash (@$samples) {
1.594 raeburn 13789: $r->print(&start_data_table_row());
1.356 albertel 13790: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13791: $r->print('<td>');
1.356 albertel 13792: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13793: $r->print('</td>');
13794: }
1.594 raeburn 13795: $r->print(&end_data_table_row());
1.31 albertel 13796: }
1.594 raeburn 13797: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13798: }
13799:
1.144 matthew 13800: ######################################################
13801: ######################################################
13802:
1.56 matthew 13803: =pod
13804:
1.648 raeburn 13805: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13806:
13807: Prints a table to create associations between values and table columns.
1.144 matthew 13808:
1.41 ng 13809: $r is an Apache Request ref,
13810: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13811: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13812:
13813: =cut
13814:
1.144 matthew 13815: ######################################################
13816: ######################################################
1.31 albertel 13817: sub csv_print_select_table {
13818: my ($r,$records,$d) = @_;
1.301 albertel 13819: my $i=0;
13820: my $samples = &get_samples($records,1);
1.144 matthew 13821: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13822: &start_data_table().&start_data_table_header_row().
1.144 matthew 13823: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13824: '<th>'.&mt('Column').'</th>'.
13825: &end_data_table_header_row()."\n");
1.356 albertel 13826: foreach my $array_ref (@$d) {
13827: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13828: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13829:
1.875 bisitz 13830: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13831: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13832: $r->print('<option value="none"></option>');
1.356 albertel 13833: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13834: $r->print('<option value="'.$sample.'"'.
13835: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13836: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13837: }
1.594 raeburn 13838: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13839: $i++;
13840: }
1.594 raeburn 13841: $r->print(&end_data_table());
1.31 albertel 13842: $i--;
13843: return $i;
13844: }
1.56 matthew 13845:
1.144 matthew 13846: ######################################################
13847: ######################################################
13848:
1.56 matthew 13849: =pod
1.31 albertel 13850:
1.648 raeburn 13851: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13852:
13853: Prints a table of sample values from the upload and can make associate samples to internal names.
13854:
13855: $r is an Apache Request ref,
13856: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13857: $d is an array of 2 element arrays (internal name, displayed name)
13858:
13859: =cut
13860:
1.144 matthew 13861: ######################################################
13862: ######################################################
1.31 albertel 13863: sub csv_samples_select_table {
13864: my ($r,$records,$d) = @_;
13865: my $i=0;
1.144 matthew 13866: #
1.662 bisitz 13867: my $max_samples = 5;
13868: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13869: $r->print(&start_data_table().
13870: &start_data_table_header_row().'<th>'.
13871: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13872: &end_data_table_header_row());
1.301 albertel 13873:
13874: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13875: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13876: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13877: foreach my $option (@$d) {
13878: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13879: $r->print('<option value="'.$value.'"'.
1.253 albertel 13880: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13881: $display.'</option>');
1.31 albertel 13882: }
13883: $r->print('</select></td><td>');
1.662 bisitz 13884: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13885: if (defined($samples->[$line]{$key})) {
13886: $r->print($samples->[$line]{$key}."<br />\n");
13887: }
13888: }
1.594 raeburn 13889: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13890: $i++;
13891: }
1.594 raeburn 13892: $r->print(&end_data_table());
1.31 albertel 13893: $i--;
13894: return($i);
1.115 matthew 13895: }
13896:
1.144 matthew 13897: ######################################################
13898: ######################################################
13899:
1.115 matthew 13900: =pod
13901:
1.648 raeburn 13902: =item * &clean_excel_name($name)
1.115 matthew 13903:
13904: Returns a replacement for $name which does not contain any illegal characters.
13905:
13906: =cut
13907:
1.144 matthew 13908: ######################################################
13909: ######################################################
1.115 matthew 13910: sub clean_excel_name {
13911: my ($name) = @_;
13912: $name =~ s/[:\*\?\/\\]//g;
13913: if (length($name) > 31) {
13914: $name = substr($name,0,31);
13915: }
13916: return $name;
1.25 albertel 13917: }
1.84 albertel 13918:
1.85 albertel 13919: =pod
13920:
1.648 raeburn 13921: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13922:
13923: Returns either 1 or undef
13924:
13925: 1 if the part is to be hidden, undef if it is to be shown
13926:
13927: Arguments are:
13928:
13929: $id the id of the part to be checked
13930: $symb, optional the symb of the resource to check
13931: $udom, optional the domain of the user to check for
13932: $uname, optional the username of the user to check for
13933:
13934: =cut
1.84 albertel 13935:
13936: sub check_if_partid_hidden {
13937: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13938: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13939: $symb,$udom,$uname);
1.141 albertel 13940: my $truth=1;
13941: #if the string starts with !, then the list is the list to show not hide
13942: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13943: my @hiddenlist=split(/,/,$hiddenparts);
13944: foreach my $checkid (@hiddenlist) {
1.141 albertel 13945: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13946: }
1.141 albertel 13947: return !$truth;
1.84 albertel 13948: }
1.127 matthew 13949:
1.138 matthew 13950:
13951: ############################################################
13952: ############################################################
13953:
13954: =pod
13955:
1.157 matthew 13956: =back
13957:
1.138 matthew 13958: =head1 cgi-bin script and graphing routines
13959:
1.157 matthew 13960: =over 4
13961:
1.648 raeburn 13962: =item * &get_cgi_id()
1.138 matthew 13963:
13964: Inputs: none
13965:
13966: Returns an id which can be used to pass environment variables
13967: to various cgi-bin scripts. These environment variables will
13968: be removed from the users environment after a given time by
13969: the routine &Apache::lonnet::transfer_profile_to_env.
13970:
13971: =cut
13972:
13973: ############################################################
13974: ############################################################
1.152 albertel 13975: my $uniq=0;
1.136 matthew 13976: sub get_cgi_id {
1.154 albertel 13977: $uniq=($uniq+1)%100000;
1.280 albertel 13978: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13979: }
13980:
1.127 matthew 13981: ############################################################
13982: ############################################################
13983:
13984: =pod
13985:
1.648 raeburn 13986: =item * &DrawBarGraph()
1.127 matthew 13987:
1.138 matthew 13988: Facilitates the plotting of data in a (stacked) bar graph.
13989: Puts plot definition data into the users environment in order for
13990: graph.png to plot it. Returns an <img> tag for the plot.
13991: The bars on the plot are labeled '1','2',...,'n'.
13992:
13993: Inputs:
13994:
13995: =over 4
13996:
13997: =item $Title: string, the title of the plot
13998:
13999: =item $xlabel: string, text describing the X-axis of the plot
14000:
14001: =item $ylabel: string, text describing the Y-axis of the plot
14002:
14003: =item $Max: scalar, the maximum Y value to use in the plot
14004: If $Max is < any data point, the graph will not be rendered.
14005:
1.140 matthew 14006: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14007: they are plotted. If undefined, default values will be used.
14008:
1.178 matthew 14009: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14010:
1.138 matthew 14011: =item @Values: An array of array references. Each array reference holds data
14012: to be plotted in a stacked bar chart.
14013:
1.239 matthew 14014: =item If the final element of @Values is a hash reference the key/value
14015: pairs will be added to the graph definition.
14016:
1.138 matthew 14017: =back
14018:
14019: Returns:
14020:
14021: An <img> tag which references graph.png and the appropriate identifying
14022: information for the plot.
14023:
1.127 matthew 14024: =cut
14025:
14026: ############################################################
14027: ############################################################
1.134 matthew 14028: sub DrawBarGraph {
1.178 matthew 14029: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14030: #
14031: if (! defined($colors)) {
14032: $colors = ['#33ff00',
14033: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14034: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14035: ];
14036: }
1.228 matthew 14037: my $extra_settings = {};
14038: if (ref($Values[-1]) eq 'HASH') {
14039: $extra_settings = pop(@Values);
14040: }
1.127 matthew 14041: #
1.136 matthew 14042: my $identifier = &get_cgi_id();
14043: my $id = 'cgi.'.$identifier;
1.129 matthew 14044: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14045: return '';
14046: }
1.225 matthew 14047: #
14048: my @Labels;
14049: if (defined($labels)) {
14050: @Labels = @$labels;
14051: } else {
14052: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 14053: push(@Labels,$i+1);
1.225 matthew 14054: }
14055: }
14056: #
1.129 matthew 14057: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14058: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14059: my %ValuesHash;
14060: my $NumSets=1;
14061: foreach my $array (@Values) {
14062: next if (! ref($array));
1.136 matthew 14063: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14064: join(',',@$array);
1.129 matthew 14065: }
1.127 matthew 14066: #
1.136 matthew 14067: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14068: if ($NumBars < 3) {
14069: $width = 120+$NumBars*32;
1.220 matthew 14070: $xskip = 1;
1.225 matthew 14071: $bar_width = 30;
14072: } elsif ($NumBars < 5) {
14073: $width = 120+$NumBars*20;
14074: $xskip = 1;
14075: $bar_width = 20;
1.220 matthew 14076: } elsif ($NumBars < 10) {
1.136 matthew 14077: $width = 120+$NumBars*15;
14078: $xskip = 1;
14079: $bar_width = 15;
14080: } elsif ($NumBars <= 25) {
14081: $width = 120+$NumBars*11;
14082: $xskip = 5;
14083: $bar_width = 8;
14084: } elsif ($NumBars <= 50) {
14085: $width = 120+$NumBars*8;
14086: $xskip = 5;
14087: $bar_width = 4;
14088: } else {
14089: $width = 120+$NumBars*8;
14090: $xskip = 5;
14091: $bar_width = 4;
14092: }
14093: #
1.137 matthew 14094: $Max = 1 if ($Max < 1);
14095: if ( int($Max) < $Max ) {
14096: $Max++;
14097: $Max = int($Max);
14098: }
1.127 matthew 14099: $Title = '' if (! defined($Title));
14100: $xlabel = '' if (! defined($xlabel));
14101: $ylabel = '' if (! defined($ylabel));
1.369 www 14102: $ValuesHash{$id.'.title'} = &escape($Title);
14103: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14104: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14105: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14106: $ValuesHash{$id.'.NumBars'} = $NumBars;
14107: $ValuesHash{$id.'.NumSets'} = $NumSets;
14108: $ValuesHash{$id.'.PlotType'} = 'bar';
14109: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14110: $ValuesHash{$id.'.height'} = $height;
14111: $ValuesHash{$id.'.width'} = $width;
14112: $ValuesHash{$id.'.xskip'} = $xskip;
14113: $ValuesHash{$id.'.bar_width'} = $bar_width;
14114: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14115: #
1.228 matthew 14116: # Deal with other parameters
14117: while (my ($key,$value) = each(%$extra_settings)) {
14118: $ValuesHash{$id.'.'.$key} = $value;
14119: }
14120: #
1.646 raeburn 14121: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14122: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14123: }
14124:
14125: ############################################################
14126: ############################################################
14127:
14128: =pod
14129:
1.648 raeburn 14130: =item * &DrawXYGraph()
1.137 matthew 14131:
1.138 matthew 14132: Facilitates the plotting of data in an XY graph.
14133: Puts plot definition data into the users environment in order for
14134: graph.png to plot it. Returns an <img> tag for the plot.
14135:
14136: Inputs:
14137:
14138: =over 4
14139:
14140: =item $Title: string, the title of the plot
14141:
14142: =item $xlabel: string, text describing the X-axis of the plot
14143:
14144: =item $ylabel: string, text describing the Y-axis of the plot
14145:
14146: =item $Max: scalar, the maximum Y value to use in the plot
14147: If $Max is < any data point, the graph will not be rendered.
14148:
14149: =item $colors: Array ref containing the hex color codes for the data to be
14150: plotted in. If undefined, default values will be used.
14151:
14152: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14153:
14154: =item $Ydata: Array ref containing Array refs.
1.185 www 14155: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14156:
14157: =item %Values: hash indicating or overriding any default values which are
14158: passed to graph.png.
14159: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14160:
14161: =back
14162:
14163: Returns:
14164:
14165: An <img> tag which references graph.png and the appropriate identifying
14166: information for the plot.
14167:
1.137 matthew 14168: =cut
14169:
14170: ############################################################
14171: ############################################################
14172: sub DrawXYGraph {
14173: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14174: #
14175: # Create the identifier for the graph
14176: my $identifier = &get_cgi_id();
14177: my $id = 'cgi.'.$identifier;
14178: #
14179: $Title = '' if (! defined($Title));
14180: $xlabel = '' if (! defined($xlabel));
14181: $ylabel = '' if (! defined($ylabel));
14182: my %ValuesHash =
14183: (
1.369 www 14184: $id.'.title' => &escape($Title),
14185: $id.'.xlabel' => &escape($xlabel),
14186: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14187: $id.'.y_max_value'=> $Max,
14188: $id.'.labels' => join(',',@$Xlabels),
14189: $id.'.PlotType' => 'XY',
14190: );
14191: #
14192: if (defined($colors) && ref($colors) eq 'ARRAY') {
14193: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14194: }
14195: #
14196: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14197: return '';
14198: }
14199: my $NumSets=1;
1.138 matthew 14200: foreach my $array (@{$Ydata}){
1.137 matthew 14201: next if (! ref($array));
14202: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14203: }
1.138 matthew 14204: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14205: #
14206: # Deal with other parameters
14207: while (my ($key,$value) = each(%Values)) {
14208: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14209: }
14210: #
1.646 raeburn 14211: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14212: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14213: }
14214:
14215: ############################################################
14216: ############################################################
14217:
14218: =pod
14219:
1.648 raeburn 14220: =item * &DrawXYYGraph()
1.138 matthew 14221:
14222: Facilitates the plotting of data in an XY graph with two Y axes.
14223: Puts plot definition data into the users environment in order for
14224: graph.png to plot it. Returns an <img> tag for the plot.
14225:
14226: Inputs:
14227:
14228: =over 4
14229:
14230: =item $Title: string, the title of the plot
14231:
14232: =item $xlabel: string, text describing the X-axis of the plot
14233:
14234: =item $ylabel: string, text describing the Y-axis of the plot
14235:
14236: =item $colors: Array ref containing the hex color codes for the data to be
14237: plotted in. If undefined, default values will be used.
14238:
14239: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14240:
14241: =item $Ydata1: The first data set
14242:
14243: =item $Min1: The minimum value of the left Y-axis
14244:
14245: =item $Max1: The maximum value of the left Y-axis
14246:
14247: =item $Ydata2: The second data set
14248:
14249: =item $Min2: The minimum value of the right Y-axis
14250:
14251: =item $Max2: The maximum value of the left Y-axis
14252:
14253: =item %Values: hash indicating or overriding any default values which are
14254: passed to graph.png.
14255: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14256:
14257: =back
14258:
14259: Returns:
14260:
14261: An <img> tag which references graph.png and the appropriate identifying
14262: information for the plot.
1.136 matthew 14263:
14264: =cut
14265:
14266: ############################################################
14267: ############################################################
1.137 matthew 14268: sub DrawXYYGraph {
14269: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14270: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14271: #
14272: # Create the identifier for the graph
14273: my $identifier = &get_cgi_id();
14274: my $id = 'cgi.'.$identifier;
14275: #
14276: $Title = '' if (! defined($Title));
14277: $xlabel = '' if (! defined($xlabel));
14278: $ylabel = '' if (! defined($ylabel));
14279: my %ValuesHash =
14280: (
1.369 www 14281: $id.'.title' => &escape($Title),
14282: $id.'.xlabel' => &escape($xlabel),
14283: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14284: $id.'.labels' => join(',',@$Xlabels),
14285: $id.'.PlotType' => 'XY',
14286: $id.'.NumSets' => 2,
1.137 matthew 14287: $id.'.two_axes' => 1,
14288: $id.'.y1_max_value' => $Max1,
14289: $id.'.y1_min_value' => $Min1,
14290: $id.'.y2_max_value' => $Max2,
14291: $id.'.y2_min_value' => $Min2,
1.136 matthew 14292: );
14293: #
1.137 matthew 14294: if (defined($colors) && ref($colors) eq 'ARRAY') {
14295: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14296: }
14297: #
14298: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14299: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14300: return '';
14301: }
14302: my $NumSets=1;
1.137 matthew 14303: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14304: next if (! ref($array));
14305: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14306: }
14307: #
14308: # Deal with other parameters
14309: while (my ($key,$value) = each(%Values)) {
14310: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14311: }
14312: #
1.646 raeburn 14313: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14314: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14315: }
14316:
14317: ############################################################
14318: ############################################################
14319:
14320: =pod
14321:
1.157 matthew 14322: =back
14323:
1.139 matthew 14324: =head1 Statistics helper routines?
14325:
14326: Bad place for them but what the hell.
14327:
1.157 matthew 14328: =over 4
14329:
1.648 raeburn 14330: =item * &chartlink()
1.139 matthew 14331:
14332: Returns a link to the chart for a specific student.
14333:
14334: Inputs:
14335:
14336: =over 4
14337:
14338: =item $linktext: The text of the link
14339:
14340: =item $sname: The students username
14341:
14342: =item $sdomain: The students domain
14343:
14344: =back
14345:
1.157 matthew 14346: =back
14347:
1.139 matthew 14348: =cut
14349:
14350: ############################################################
14351: ############################################################
14352: sub chartlink {
14353: my ($linktext, $sname, $sdomain) = @_;
14354: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14355: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14356: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14357: '">'.$linktext.'</a>';
1.153 matthew 14358: }
14359:
14360: #######################################################
14361: #######################################################
14362:
14363: =pod
14364:
14365: =head1 Course Environment Routines
1.157 matthew 14366:
14367: =over 4
1.153 matthew 14368:
1.648 raeburn 14369: =item * &restore_course_settings()
1.153 matthew 14370:
1.648 raeburn 14371: =item * &store_course_settings()
1.153 matthew 14372:
14373: Restores/Store indicated form parameters from the course environment.
14374: Will not overwrite existing values of the form parameters.
14375:
14376: Inputs:
14377: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14378:
14379: a hash ref describing the data to be stored. For example:
14380:
14381: %Save_Parameters = ('Status' => 'scalar',
14382: 'chartoutputmode' => 'scalar',
14383: 'chartoutputdata' => 'scalar',
14384: 'Section' => 'array',
1.373 raeburn 14385: 'Group' => 'array',
1.153 matthew 14386: 'StudentData' => 'array',
14387: 'Maps' => 'array');
14388:
14389: Returns: both routines return nothing
14390:
1.631 raeburn 14391: =back
14392:
1.153 matthew 14393: =cut
14394:
14395: #######################################################
14396: #######################################################
14397: sub store_course_settings {
1.496 albertel 14398: return &store_settings($env{'request.course.id'},@_);
14399: }
14400:
14401: sub store_settings {
1.153 matthew 14402: # save to the environment
14403: # appenv the same items, just to be safe
1.300 albertel 14404: my $udom = $env{'user.domain'};
14405: my $uname = $env{'user.name'};
1.496 albertel 14406: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14407: my %SaveHash;
14408: my %AppHash;
14409: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14410: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14411: my $envname = 'environment.'.$basename;
1.258 albertel 14412: if (exists($env{'form.'.$setting})) {
1.153 matthew 14413: # Save this value away
14414: if ($type eq 'scalar' &&
1.258 albertel 14415: (! exists($env{$envname}) ||
14416: $env{$envname} ne $env{'form.'.$setting})) {
14417: $SaveHash{$basename} = $env{'form.'.$setting};
14418: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14419: } elsif ($type eq 'array') {
14420: my $stored_form;
1.258 albertel 14421: if (ref($env{'form.'.$setting})) {
1.153 matthew 14422: $stored_form = join(',',
14423: map {
1.369 www 14424: &escape($_);
1.258 albertel 14425: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14426: } else {
14427: $stored_form =
1.369 www 14428: &escape($env{'form.'.$setting});
1.153 matthew 14429: }
14430: # Determine if the array contents are the same.
1.258 albertel 14431: if ($stored_form ne $env{$envname}) {
1.153 matthew 14432: $SaveHash{$basename} = $stored_form;
14433: $AppHash{$envname} = $stored_form;
14434: }
14435: }
14436: }
14437: }
14438: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14439: $udom,$uname);
1.153 matthew 14440: if ($put_result !~ /^(ok|delayed)/) {
14441: &Apache::lonnet::logthis('unable to save form parameters, '.
14442: 'got error:'.$put_result);
14443: }
14444: # Make sure these settings stick around in this session, too
1.646 raeburn 14445: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14446: return;
14447: }
14448:
14449: sub restore_course_settings {
1.499 albertel 14450: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14451: }
14452:
14453: sub restore_settings {
14454: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14455: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14456: next if (exists($env{'form.'.$setting}));
1.496 albertel 14457: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14458: '.'.$setting;
1.258 albertel 14459: if (exists($env{$envname})) {
1.153 matthew 14460: if ($type eq 'scalar') {
1.258 albertel 14461: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14462: } elsif ($type eq 'array') {
1.258 albertel 14463: $env{'form.'.$setting} = [
1.153 matthew 14464: map {
1.369 www 14465: &unescape($_);
1.258 albertel 14466: } split(',',$env{$envname})
1.153 matthew 14467: ];
14468: }
14469: }
14470: }
1.127 matthew 14471: }
14472:
1.618 raeburn 14473: #######################################################
14474: #######################################################
14475:
14476: =pod
14477:
14478: =head1 Domain E-mail Routines
14479:
14480: =over 4
14481:
1.648 raeburn 14482: =item * &build_recipient_list()
1.618 raeburn 14483:
1.1075.2.44 raeburn 14484: Build recipient lists for following types of e-mail:
1.766 raeburn 14485: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14486: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14487: module change checking, student/employee ID conflict checks, as
14488: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14489: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14490:
14491: Inputs:
1.1075.2.44 raeburn 14492: defmail (scalar - email address of default recipient),
14493: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14494: requestsmail, updatesmail, or idconflictsmail).
14495:
1.619 raeburn 14496: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14497:
14498: origmail (scalar - email address of recipient from loncapa.conf,
14499: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14500:
1.1075.2.139 raeburn 14501: $requname username of requester (if mailing type is helpdeskmail)
14502:
14503: $requdom domain of requester (if mailing type is helpdeskmail)
14504:
14505: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14506:
1.655 raeburn 14507: Returns: comma separated list of addresses to which to send e-mail.
14508:
14509: =back
1.618 raeburn 14510:
14511: =cut
14512:
14513: ############################################################
14514: ############################################################
14515: sub build_recipient_list {
1.1075.2.139 raeburn 14516: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14517: my @recipients;
1.1075.2.122 raeburn 14518: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14519: my %domconfig =
1.1075.2.122 raeburn 14520: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14521: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14522: if (exists($domconfig{'contacts'}{$mailing})) {
14523: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14524: my @contacts = ('adminemail','supportemail');
14525: foreach my $item (@contacts) {
14526: if ($domconfig{'contacts'}{$mailing}{$item}) {
14527: my $addr = $domconfig{'contacts'}{$item};
14528: if (!grep(/^\Q$addr\E$/,@recipients)) {
14529: push(@recipients,$addr);
14530: }
1.619 raeburn 14531: }
1.1075.2.122 raeburn 14532: }
14533: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14534: if ($mailing eq 'helpdeskmail') {
14535: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14536: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14537: my @ok_bccs;
14538: foreach my $bcc (@bccs) {
14539: $bcc =~ s/^\s+//g;
14540: $bcc =~ s/\s+$//g;
14541: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14542: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14543: push(@ok_bccs,$bcc);
14544: }
14545: }
14546: }
14547: if (@ok_bccs > 0) {
14548: $allbcc = join(', ',@ok_bccs);
14549: }
14550: }
14551: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14552: }
14553: }
1.766 raeburn 14554: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14555: $lastresort = $origmail;
1.618 raeburn 14556: }
1.1075.2.139 raeburn 14557: if ($mailing eq 'helpdeskmail') {
14558: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14559: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14560: my ($inststatus,$inststatus_checked);
14561: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14562: ($env{'user.domain'} ne 'public')) {
14563: $inststatus_checked = 1;
14564: $inststatus = $env{'environment.inststatus'};
14565: }
14566: unless ($inststatus_checked) {
14567: if (($requname ne '') && ($requdom ne '')) {
14568: if (($requname =~ /^$match_username$/) &&
14569: ($requdom =~ /^$match_domain$/) &&
14570: (&Apache::lonnet::domain($requdom))) {
14571: my $requhome = &Apache::lonnet::homeserver($requname,
14572: $requdom);
14573: unless ($requhome eq 'no_host') {
14574: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14575: $inststatus = $userenv{'inststatus'};
14576: $inststatus_checked = 1;
14577: }
14578: }
14579: }
14580: }
14581: unless ($inststatus_checked) {
14582: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14583: my %srch = (srchby => 'email',
14584: srchdomain => $defdom,
14585: srchterm => $reqemail,
14586: srchtype => 'exact');
14587: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14588: foreach my $uname (keys(%srch_results)) {
14589: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14590: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14591: $inststatus_checked = 1;
14592: last;
14593: }
14594: }
14595: unless ($inststatus_checked) {
14596: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14597: if ($dirsrchres eq 'ok') {
14598: foreach my $uname (keys(%srch_results)) {
14599: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14600: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14601: $inststatus_checked = 1;
14602: last;
14603: }
14604: }
14605: }
14606: }
14607: }
14608: }
14609: if ($inststatus ne '') {
14610: foreach my $status (split(/\:/,$inststatus)) {
14611: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14612: my @contacts = ('adminemail','supportemail');
14613: foreach my $item (@contacts) {
14614: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14615: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14616: if (!grep(/^\Q$addr\E$/,@recipients)) {
14617: push(@recipients,$addr);
14618: }
14619: }
14620: }
14621: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14622: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14623: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14624: my @ok_bccs;
14625: foreach my $bcc (@bccs) {
14626: $bcc =~ s/^\s+//g;
14627: $bcc =~ s/\s+$//g;
14628: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14629: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14630: push(@ok_bccs,$bcc);
14631: }
14632: }
14633: }
14634: if (@ok_bccs > 0) {
14635: $allbcc = join(', ',@ok_bccs);
14636: }
14637: }
14638: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14639: last;
14640: }
14641: }
14642: }
14643: }
14644: }
1.619 raeburn 14645: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14646: $lastresort = $origmail;
14647: }
1.1075.2.128 raeburn 14648: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14649: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14650: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14651: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14652: my %what = (
14653: perlvar => 1,
14654: );
14655: my $primary = &Apache::lonnet::domain($defdom,'primary');
14656: if ($primary) {
14657: my $gotaddr;
14658: my ($result,$returnhash) =
14659: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14660: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14661: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14662: $lastresort = $returnhash->{'lonSupportEMail'};
14663: $gotaddr = 1;
14664: }
14665: }
14666: unless ($gotaddr) {
14667: my $uintdom = &Apache::lonnet::internet_dom($primary);
14668: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14669: unless ($uintdom eq $intdom) {
14670: my %domconfig =
14671: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14672: if (ref($domconfig{'contacts'}) eq 'HASH') {
14673: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14674: my @contacts = ('adminemail','supportemail');
14675: foreach my $item (@contacts) {
14676: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14677: my $addr = $domconfig{'contacts'}{$item};
14678: if (!grep(/^\Q$addr\E$/,@recipients)) {
14679: push(@recipients,$addr);
14680: }
14681: }
14682: }
14683: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14684: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14685: }
14686: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14687: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14688: my @ok_bccs;
14689: foreach my $bcc (@bccs) {
14690: $bcc =~ s/^\s+//g;
14691: $bcc =~ s/\s+$//g;
14692: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14693: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14694: push(@ok_bccs,$bcc);
14695: }
14696: }
14697: }
14698: if (@ok_bccs > 0) {
14699: $allbcc = join(', ',@ok_bccs);
14700: }
14701: }
14702: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14703: }
14704: }
14705: }
14706: }
14707: }
14708: }
1.618 raeburn 14709: }
1.688 raeburn 14710: if (defined($defmail)) {
14711: if ($defmail ne '') {
14712: push(@recipients,$defmail);
14713: }
1.618 raeburn 14714: }
14715: if ($otheremails) {
1.619 raeburn 14716: my @others;
14717: if ($otheremails =~ /,/) {
14718: @others = split(/,/,$otheremails);
1.618 raeburn 14719: } else {
1.619 raeburn 14720: push(@others,$otheremails);
14721: }
14722: foreach my $addr (@others) {
14723: if (!grep(/^\Q$addr\E$/,@recipients)) {
14724: push(@recipients,$addr);
14725: }
1.618 raeburn 14726: }
14727: }
1.1075.2.128 raeburn 14728: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14729: if ((!@recipients) && ($lastresort ne '')) {
14730: push(@recipients,$lastresort);
14731: }
14732: } elsif ($lastresort ne '') {
14733: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14734: push(@recipients,$lastresort);
14735: }
14736: }
14737: my $recipientlist = join(',',@recipients);
14738: if (wantarray) {
14739: return ($recipientlist,$allbcc,$addtext);
14740: } else {
14741: return $recipientlist;
14742: }
1.618 raeburn 14743: }
14744:
1.127 matthew 14745: ############################################################
14746: ############################################################
1.154 albertel 14747:
1.655 raeburn 14748: =pod
14749:
14750: =head1 Course Catalog Routines
14751:
14752: =over 4
14753:
14754: =item * &gather_categories()
14755:
14756: Converts category definitions - keys of categories hash stored in
14757: coursecategories in configuration.db on the primary library server in a
14758: domain - to an array. Also generates javascript and idx hash used to
14759: generate Domain Coordinator interface for editing Course Categories.
14760:
14761: Inputs:
1.663 raeburn 14762:
1.655 raeburn 14763: categories (reference to hash of category definitions).
1.663 raeburn 14764:
1.655 raeburn 14765: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14766: categories and subcategories).
1.663 raeburn 14767:
1.655 raeburn 14768: idx (reference to hash of counters used in Domain Coordinator interface for
14769: editing Course Categories).
1.663 raeburn 14770:
1.655 raeburn 14771: jsarray (reference to array of categories used to create Javascript arrays for
14772: Domain Coordinator interface for editing Course Categories).
14773:
14774: Returns: nothing
14775:
14776: Side effects: populates cats, idx and jsarray.
14777:
14778: =cut
14779:
14780: sub gather_categories {
14781: my ($categories,$cats,$idx,$jsarray) = @_;
14782: my %counters;
14783: my $num = 0;
14784: foreach my $item (keys(%{$categories})) {
14785: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14786: if ($container eq '' && $depth == 0) {
14787: $cats->[$depth][$categories->{$item}] = $cat;
14788: } else {
14789: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14790: }
14791: my ($escitem,$tail) = split(/:/,$item,2);
14792: if ($counters{$tail} eq '') {
14793: $counters{$tail} = $num;
14794: $num ++;
14795: }
14796: if (ref($idx) eq 'HASH') {
14797: $idx->{$item} = $counters{$tail};
14798: }
14799: if (ref($jsarray) eq 'ARRAY') {
14800: push(@{$jsarray->[$counters{$tail}]},$item);
14801: }
14802: }
14803: return;
14804: }
14805:
14806: =pod
14807:
14808: =item * &extract_categories()
14809:
14810: Used to generate breadcrumb trails for course categories.
14811:
14812: Inputs:
1.663 raeburn 14813:
1.655 raeburn 14814: categories (reference to hash of category definitions).
1.663 raeburn 14815:
1.655 raeburn 14816: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14817: categories and subcategories).
1.663 raeburn 14818:
1.655 raeburn 14819: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14820:
1.655 raeburn 14821: allitems (reference to hash - key is category key
14822: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14823:
1.655 raeburn 14824: idx (reference to hash of counters used in Domain Coordinator interface for
14825: editing Course Categories).
1.663 raeburn 14826:
1.655 raeburn 14827: jsarray (reference to array of categories used to create Javascript arrays for
14828: Domain Coordinator interface for editing Course Categories).
14829:
1.665 raeburn 14830: subcats (reference to hash of arrays containing all subcategories within each
14831: category, -recursive)
14832:
1.1075.2.132 raeburn 14833: maxd (reference to hash used to hold max depth for all top-level categories).
14834:
1.655 raeburn 14835: Returns: nothing
14836:
14837: Side effects: populates trails and allitems hash references.
14838:
14839: =cut
14840:
14841: sub extract_categories {
1.1075.2.132 raeburn 14842: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14843: if (ref($categories) eq 'HASH') {
14844: &gather_categories($categories,$cats,$idx,$jsarray);
14845: if (ref($cats->[0]) eq 'ARRAY') {
14846: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14847: my $name = $cats->[0][$i];
14848: my $item = &escape($name).'::0';
14849: my $trailstr;
14850: if ($name eq 'instcode') {
14851: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14852: } elsif ($name eq 'communities') {
14853: $trailstr = &mt('Communities');
1.655 raeburn 14854: } else {
14855: $trailstr = $name;
14856: }
14857: if ($allitems->{$item} eq '') {
14858: push(@{$trails},$trailstr);
14859: $allitems->{$item} = scalar(@{$trails})-1;
14860: }
14861: my @parents = ($name);
14862: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14863: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14864: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14865: if (ref($subcats) eq 'HASH') {
14866: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14867: }
1.1075.2.132 raeburn 14868: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14869: }
14870: } else {
14871: if (ref($subcats) eq 'HASH') {
14872: $subcats->{$item} = [];
1.655 raeburn 14873: }
1.1075.2.132 raeburn 14874: if (ref($maxd) eq 'HASH') {
14875: $maxd->{$name} = 1;
14876: }
1.655 raeburn 14877: }
14878: }
14879: }
14880: }
14881: return;
14882: }
14883:
14884: =pod
14885:
1.1075.2.56 raeburn 14886: =item * &recurse_categories()
1.655 raeburn 14887:
14888: Recursively used to generate breadcrumb trails for course categories.
14889:
14890: Inputs:
1.663 raeburn 14891:
1.655 raeburn 14892: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14893: categories and subcategories).
1.663 raeburn 14894:
1.655 raeburn 14895: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14896:
14897: category (current course category, for which breadcrumb trail is being generated).
14898:
14899: trails (reference to array of breadcrumb trails for each category).
14900:
1.655 raeburn 14901: allitems (reference to hash - key is category key
14902: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14903:
1.655 raeburn 14904: parents (array containing containers directories for current category,
14905: back to top level).
14906:
14907: Returns: nothing
14908:
14909: Side effects: populates trails and allitems hash references
14910:
14911: =cut
14912:
14913: sub recurse_categories {
1.1075.2.132 raeburn 14914: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14915: my $shallower = $depth - 1;
14916: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14917: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14918: my $name = $cats->[$depth]{$category}[$k];
14919: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.164 raeburn 14920: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14921: if ($allitems->{$item} eq '') {
14922: push(@{$trails},$trailstr);
14923: $allitems->{$item} = scalar(@{$trails})-1;
14924: }
14925: my $deeper = $depth+1;
14926: push(@{$parents},$category);
1.665 raeburn 14927: if (ref($subcats) eq 'HASH') {
14928: my $subcat = &escape($name).':'.$category.':'.$depth;
14929: for (my $j=@{$parents}; $j>=0; $j--) {
14930: my $higher;
14931: if ($j > 0) {
14932: $higher = &escape($parents->[$j]).':'.
14933: &escape($parents->[$j-1]).':'.$j;
14934: } else {
14935: $higher = &escape($parents->[$j]).'::'.$j;
14936: }
14937: push(@{$subcats->{$higher}},$subcat);
14938: }
14939: }
14940: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 14941: $subcats,$maxd);
1.655 raeburn 14942: pop(@{$parents});
14943: }
14944: } else {
14945: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 14946: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14947: if ($allitems->{$item} eq '') {
14948: push(@{$trails},$trailstr);
14949: $allitems->{$item} = scalar(@{$trails})-1;
14950: }
1.1075.2.132 raeburn 14951: if (ref($maxd) eq 'HASH') {
14952: if ($depth > $maxd->{$parents->[0]}) {
14953: $maxd->{$parents->[0]} = $depth;
14954: }
14955: }
1.655 raeburn 14956: }
14957: return;
14958: }
14959:
1.663 raeburn 14960: =pod
14961:
1.1075.2.56 raeburn 14962: =item * &assign_categories_table()
1.663 raeburn 14963:
14964: Create a datatable for display of hierarchical categories in a domain,
14965: with checkboxes to allow a course to be categorized.
14966:
14967: Inputs:
14968:
14969: cathash - reference to hash of categories defined for the domain (from
14970: configuration.db)
14971:
14972: currcat - scalar with an & separated list of categories assigned to a course.
14973:
1.919 raeburn 14974: type - scalar contains course type (Course or Community).
14975:
1.1075.2.117 raeburn 14976: disabled - scalar (optional) contains disabled="disabled" if input elements are
14977: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14978:
1.663 raeburn 14979: Returns: $output (markup to be displayed)
14980:
14981: =cut
14982:
14983: sub assign_categories_table {
1.1075.2.117 raeburn 14984: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14985: my $output;
14986: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 14987: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
14988: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 14989: $maxdepth = scalar(@cats);
14990: if (@cats > 0) {
14991: my $itemcount = 0;
14992: if (ref($cats[0]) eq 'ARRAY') {
14993: my @currcategories;
14994: if ($currcat ne '') {
14995: @currcategories = split('&',$currcat);
14996: }
1.919 raeburn 14997: my $table;
1.663 raeburn 14998: for (my $i=0; $i<@{$cats[0]}; $i++) {
14999: my $parent = $cats[0][$i];
1.919 raeburn 15000: next if ($parent eq 'instcode');
15001: if ($type eq 'Community') {
15002: next unless ($parent eq 'communities');
15003: } else {
15004: next if ($parent eq 'communities');
15005: }
1.663 raeburn 15006: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15007: my $item = &escape($parent).'::0';
15008: my $checked = '';
15009: if (@currcategories > 0) {
15010: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15011: $checked = ' checked="checked"';
1.663 raeburn 15012: }
15013: }
1.919 raeburn 15014: my $parent_title = $parent;
15015: if ($parent eq 'communities') {
15016: $parent_title = &mt('Communities');
15017: }
15018: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15019: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15020: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15021: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15022: my $depth = 1;
15023: push(@path,$parent);
1.1075.2.117 raeburn 15024: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15025: pop(@path);
1.919 raeburn 15026: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15027: $itemcount ++;
15028: }
1.919 raeburn 15029: if ($itemcount) {
15030: $output = &Apache::loncommon::start_data_table().
15031: $table.
15032: &Apache::loncommon::end_data_table();
15033: }
1.663 raeburn 15034: }
15035: }
15036: }
15037: return $output;
15038: }
15039:
15040: =pod
15041:
1.1075.2.56 raeburn 15042: =item * &assign_category_rows()
1.663 raeburn 15043:
15044: Create a datatable row for display of nested categories in a domain,
15045: with checkboxes to allow a course to be categorized,called recursively.
15046:
15047: Inputs:
15048:
15049: itemcount - track row number for alternating colors
15050:
15051: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15052: categories and subcategories.
15053:
15054: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15055:
15056: parent - parent of current category item
15057:
15058: path - Array containing all categories back up through the hierarchy from the
15059: current category to the top level.
15060:
15061: currcategories - reference to array of current categories assigned to the course
15062:
1.1075.2.117 raeburn 15063: disabled - scalar (optional) contains disabled="disabled" if input elements are
15064: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15065:
1.663 raeburn 15066: Returns: $output (markup to be displayed).
15067:
15068: =cut
15069:
15070: sub assign_category_rows {
1.1075.2.117 raeburn 15071: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15072: my ($text,$name,$item,$chgstr);
15073: if (ref($cats) eq 'ARRAY') {
15074: my $maxdepth = scalar(@{$cats});
15075: if (ref($cats->[$depth]) eq 'HASH') {
15076: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15077: my $numchildren = @{$cats->[$depth]{$parent}};
15078: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 15079: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15080: for (my $j=0; $j<$numchildren; $j++) {
15081: $name = $cats->[$depth]{$parent}[$j];
15082: $item = &escape($name).':'.&escape($parent).':'.$depth;
15083: my $deeper = $depth+1;
15084: my $checked = '';
15085: if (ref($currcategories) eq 'ARRAY') {
15086: if (@{$currcategories} > 0) {
15087: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15088: $checked = ' checked="checked"';
1.663 raeburn 15089: }
15090: }
15091: }
1.664 raeburn 15092: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15093: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15094: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15095: '<input type="hidden" name="catname" value="'.$name.'" />'.
15096: '</td><td>';
1.663 raeburn 15097: if (ref($path) eq 'ARRAY') {
15098: push(@{$path},$name);
1.1075.2.117 raeburn 15099: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15100: pop(@{$path});
15101: }
15102: $text .= '</td></tr>';
15103: }
15104: $text .= '</table></td>';
15105: }
15106: }
15107: }
15108: return $text;
15109: }
15110:
1.1075.2.69 raeburn 15111: =pod
15112:
15113: =back
15114:
15115: =cut
15116:
1.655 raeburn 15117: ############################################################
15118: ############################################################
15119:
15120:
1.443 albertel 15121: sub commit_customrole {
1.664 raeburn 15122: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15123: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15124: ($start?', '.&mt('starting').' '.localtime($start):'').
15125: ($end?', ending '.localtime($end):'').': <b>'.
15126: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15127: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15128: '</b><br />';
15129: return $output;
15130: }
15131:
15132: sub commit_standardrole {
1.1075.2.31 raeburn 15133: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15134: my ($output,$logmsg,$linefeed);
15135: if ($context eq 'auto') {
15136: $linefeed = "\n";
15137: } else {
15138: $linefeed = "<br />\n";
15139: }
1.443 albertel 15140: if ($three eq 'st') {
1.541 raeburn 15141: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 15142: $one,$two,$sec,$context,$credits);
1.541 raeburn 15143: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15144: ($result eq 'unknown_course') || ($result eq 'refused')) {
15145: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15146: } else {
1.541 raeburn 15147: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15148: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15149: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15150: if ($context eq 'auto') {
15151: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15152: } else {
15153: $output .= '<b>'.$result.'</b>'.$linefeed.
15154: &mt('Add to classlist').': <b>ok</b>';
15155: }
15156: $output .= $linefeed;
1.443 albertel 15157: }
15158: } else {
15159: $output = &mt('Assigning').' '.$three.' in '.$url.
15160: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15161: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15162: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15163: if ($context eq 'auto') {
15164: $output .= $result.$linefeed;
15165: } else {
15166: $output .= '<b>'.$result.'</b>'.$linefeed;
15167: }
1.443 albertel 15168: }
15169: return $output;
15170: }
15171:
15172: sub commit_studentrole {
1.1075.2.31 raeburn 15173: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15174: $credits) = @_;
1.626 raeburn 15175: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15176: if ($context eq 'auto') {
15177: $linefeed = "\n";
15178: } else {
15179: $linefeed = '<br />'."\n";
15180: }
1.443 albertel 15181: if (defined($one) && defined($two)) {
15182: my $cid=$one.'_'.$two;
15183: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15184: my $secchange = 0;
15185: my $expire_role_result;
15186: my $modify_section_result;
1.628 raeburn 15187: if ($oldsec ne '-1') {
15188: if ($oldsec ne $sec) {
1.443 albertel 15189: $secchange = 1;
1.628 raeburn 15190: my $now = time;
1.443 albertel 15191: my $uurl='/'.$cid;
15192: $uurl=~s/\_/\//g;
15193: if ($oldsec) {
15194: $uurl.='/'.$oldsec;
15195: }
1.626 raeburn 15196: $oldsecurl = $uurl;
1.628 raeburn 15197: $expire_role_result =
1.652 raeburn 15198: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15199: if ($env{'request.course.sec'} ne '') {
15200: if ($expire_role_result eq 'refused') {
15201: my @roles = ('st');
15202: my @statuses = ('previous');
15203: my @roledoms = ($one);
15204: my $withsec = 1;
15205: my %roleshash =
15206: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15207: \@statuses,\@roles,\@roledoms,$withsec);
15208: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15209: my ($oldstart,$oldend) =
15210: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15211: if ($oldend > 0 && $oldend <= $now) {
15212: $expire_role_result = 'ok';
15213: }
15214: }
15215: }
15216: }
1.443 albertel 15217: $result = $expire_role_result;
15218: }
15219: }
15220: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 15221: $modify_section_result =
15222: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15223: undef,undef,undef,$sec,
15224: $end,$start,'','',$cid,
15225: '',$context,$credits);
1.443 albertel 15226: if ($modify_section_result =~ /^ok/) {
15227: if ($secchange == 1) {
1.628 raeburn 15228: if ($sec eq '') {
15229: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15230: } else {
15231: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15232: }
1.443 albertel 15233: } elsif ($oldsec eq '-1') {
1.628 raeburn 15234: if ($sec eq '') {
15235: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15236: } else {
15237: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15238: }
1.443 albertel 15239: } else {
1.628 raeburn 15240: if ($sec eq '') {
15241: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15242: } else {
15243: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15244: }
1.443 albertel 15245: }
15246: } else {
1.628 raeburn 15247: if ($secchange) {
15248: $$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;
15249: } else {
15250: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15251: }
1.443 albertel 15252: }
15253: $result = $modify_section_result;
15254: } elsif ($secchange == 1) {
1.628 raeburn 15255: if ($oldsec eq '') {
1.1075.2.20 raeburn 15256: $$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 15257: } else {
15258: $$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;
15259: }
1.626 raeburn 15260: if ($expire_role_result eq 'refused') {
15261: my $newsecurl = '/'.$cid;
15262: $newsecurl =~ s/\_/\//g;
15263: if ($sec ne '') {
15264: $newsecurl.='/'.$sec;
15265: }
15266: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15267: if ($sec eq '') {
15268: $$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;
15269: } else {
15270: $$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;
15271: }
15272: }
15273: }
1.443 albertel 15274: }
15275: } else {
1.626 raeburn 15276: $$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 15277: $result = "error: incomplete course id\n";
15278: }
15279: return $result;
15280: }
15281:
1.1075.2.25 raeburn 15282: sub show_role_extent {
15283: my ($scope,$context,$role) = @_;
15284: $scope =~ s{^/}{};
15285: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15286: push(@courseroles,'co');
15287: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15288: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15289: $scope =~ s{/}{_};
15290: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15291: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15292: my ($audom,$auname) = split(/\//,$scope);
15293: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15294: &Apache::loncommon::plainname($auname,$audom).'</span>');
15295: } else {
15296: $scope =~ s{/$}{};
15297: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15298: &Apache::lonnet::domain($scope,'description').'</span>');
15299: }
15300: }
15301:
1.443 albertel 15302: ############################################################
15303: ############################################################
15304:
1.566 albertel 15305: sub check_clone {
1.578 raeburn 15306: my ($args,$linefeed) = @_;
1.566 albertel 15307: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15308: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15309: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15310: my $clonemsg;
15311: my $can_clone = 0;
1.944 raeburn 15312: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15313: if ($lctype ne 'community') {
15314: $lctype = 'course';
15315: }
1.566 albertel 15316: if ($clonehome eq 'no_host') {
1.944 raeburn 15317: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15318: $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'});
15319: } else {
15320: $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'});
15321: }
1.566 albertel 15322: } else {
15323: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15324: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15325: if ($clonedesc{'type'} ne 'Community') {
15326: $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'});
15327: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15328: }
15329: }
1.1075.2.119 raeburn 15330: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15331: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15332: $can_clone = 1;
15333: } else {
1.1075.2.95 raeburn 15334: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15335: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 15336: if ($clonehash{'cloners'} eq '') {
15337: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15338: if ($domdefs{'canclone'}) {
15339: unless ($domdefs{'canclone'} eq 'none') {
15340: if ($domdefs{'canclone'} eq 'domain') {
15341: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15342: $can_clone = 1;
15343: }
15344: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15345: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15346: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15347: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15348: $can_clone = 1;
15349: }
15350: }
15351: }
1.908 raeburn 15352: }
1.1075.2.95 raeburn 15353: } else {
15354: my @cloners = split(/,/,$clonehash{'cloners'});
15355: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15356: $can_clone = 1;
1.1075.2.95 raeburn 15357: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15358: $can_clone = 1;
1.1075.2.96 raeburn 15359: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15360: $can_clone = 1;
1.1075.2.95 raeburn 15361: }
15362: unless ($can_clone) {
1.1075.2.96 raeburn 15363: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15364: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 15365: my (%gotdomdefaults,%gotcodedefaults);
15366: foreach my $cloner (@cloners) {
15367: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15368: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15369: my (%codedefaults,@code_order);
15370: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15371: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15372: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15373: }
15374: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15375: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15376: }
15377: } else {
15378: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15379: \%codedefaults,
15380: \@code_order);
15381: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15382: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15383: }
15384: if (@code_order > 0) {
15385: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15386: $cloner,$clonehash{'internal.coursecode'},
15387: $args->{'crscode'})) {
15388: $can_clone = 1;
15389: last;
15390: }
15391: }
15392: }
15393: }
15394: }
1.1075.2.96 raeburn 15395: }
15396: }
15397: unless ($can_clone) {
15398: my $ccrole = 'cc';
15399: if ($args->{'crstype'} eq 'Community') {
15400: $ccrole = 'co';
15401: }
15402: my %roleshash =
15403: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15404: $args->{'ccdomain'},
15405: 'userroles',['active'],[$ccrole],
15406: [$args->{'clonedomain'}]);
15407: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15408: $can_clone = 1;
15409: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15410: $args->{'ccuname'},$args->{'ccdomain'})) {
15411: $can_clone = 1;
1.1075.2.95 raeburn 15412: }
15413: }
15414: unless ($can_clone) {
15415: if ($args->{'crstype'} eq 'Community') {
15416: $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'});
15417: } else {
15418: $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 15419: }
1.566 albertel 15420: }
1.578 raeburn 15421: }
1.566 albertel 15422: }
15423: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15424: }
15425:
1.444 albertel 15426: sub construct_course {
1.1075.2.119 raeburn 15427: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15428: $cnum,$category,$coderef) = @_;
1.444 albertel 15429: my $outcome;
1.541 raeburn 15430: my $linefeed = '<br />'."\n";
15431: if ($context eq 'auto') {
15432: $linefeed = "\n";
15433: }
1.566 albertel 15434:
15435: #
15436: # Are we cloning?
15437: #
15438: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15439: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15440: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15441: if ($context ne 'auto') {
1.578 raeburn 15442: if ($clonemsg ne '') {
15443: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15444: }
1.566 albertel 15445: }
15446: $outcome .= $clonemsg.$linefeed;
15447:
15448: if (!$can_clone) {
15449: return (0,$outcome);
15450: }
15451: }
15452:
1.444 albertel 15453: #
15454: # Open course
15455: #
15456: my $crstype = lc($args->{'crstype'});
15457: my %cenv=();
15458: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15459: $args->{'cdescr'},
15460: $args->{'curl'},
15461: $args->{'course_home'},
15462: $args->{'nonstandard'},
15463: $args->{'crscode'},
15464: $args->{'ccuname'}.':'.
15465: $args->{'ccdomain'},
1.882 raeburn 15466: $args->{'crstype'},
1.885 raeburn 15467: $cnum,$context,$category);
1.444 albertel 15468:
15469: # Note: The testing routines depend on this being output; see
15470: # Utils::Course. This needs to at least be output as a comment
15471: # if anyone ever decides to not show this, and Utils::Course::new
15472: # will need to be suitably modified.
1.541 raeburn 15473: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 15474: if ($$courseid =~ /^error:/) {
15475: return (0,$outcome);
15476: }
15477:
1.444 albertel 15478: #
15479: # Check if created correctly
15480: #
1.479 albertel 15481: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15482: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15483: if ($crsuhome eq 'no_host') {
15484: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15485: return (0,$outcome);
15486: }
1.541 raeburn 15487: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15488:
1.444 albertel 15489: #
1.566 albertel 15490: # Do the cloning
15491: #
15492: if ($can_clone && $cloneid) {
15493: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
15494: if ($context ne 'auto') {
15495: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15496: }
15497: $outcome .= $clonemsg.$linefeed;
15498: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15499: # Copy all files
1.637 www 15500: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15501: # Restore URL
1.566 albertel 15502: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15503: # Restore title
1.566 albertel 15504: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15505: # Restore creation date, creator and creation context.
15506: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15507: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15508: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15509: # Mark as cloned
1.566 albertel 15510: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15511: # Need to clone grading mode
15512: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15513: $cenv{'grading'}=$newenv{'grading'};
15514: # Do not clone these environment entries
15515: &Apache::lonnet::del('environment',
15516: ['default_enrollment_start_date',
15517: 'default_enrollment_end_date',
15518: 'question.email',
15519: 'policy.email',
15520: 'comment.email',
15521: 'pch.users.denied',
1.725 raeburn 15522: 'plc.users.denied',
15523: 'hidefromcat',
1.1075.2.36 raeburn 15524: 'checkforpriv',
1.1075.2.158 raeburn 15525: 'categories'],
1.638 www 15526: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15527: if ($args->{'textbook'}) {
15528: $cenv{'internal.textbook'} = $args->{'textbook'};
15529: }
1.444 albertel 15530: }
1.566 albertel 15531:
1.444 albertel 15532: #
15533: # Set environment (will override cloned, if existing)
15534: #
15535: my @sections = ();
15536: my @xlists = ();
15537: if ($args->{'crstype'}) {
15538: $cenv{'type'}=$args->{'crstype'};
15539: }
15540: if ($args->{'crsid'}) {
15541: $cenv{'courseid'}=$args->{'crsid'};
15542: }
15543: if ($args->{'crscode'}) {
15544: $cenv{'internal.coursecode'}=$args->{'crscode'};
15545: }
15546: if ($args->{'crsquota'} ne '') {
15547: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15548: } else {
15549: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15550: }
15551: if ($args->{'ccuname'}) {
15552: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15553: ':'.$args->{'ccdomain'};
15554: } else {
15555: $cenv{'internal.courseowner'} = $args->{'curruser'};
15556: }
1.1075.2.31 raeburn 15557: if ($args->{'defaultcredits'}) {
15558: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15559: }
1.444 albertel 15560: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
1.1075.2.166! raeburn 15561: my @oklcsecs = (); # Used to accumulate LON-CAPA sections for validated institutional sections.
1.444 albertel 15562: if ($args->{'crssections'}) {
15563: $cenv{'internal.sectionnums'} = '';
15564: if ($args->{'crssections'} =~ m/,/) {
15565: @sections = split/,/,$args->{'crssections'};
15566: } else {
15567: $sections[0] = $args->{'crssections'};
15568: }
15569: if (@sections > 0) {
15570: foreach my $item (@sections) {
15571: my ($sec,$gp) = split/:/,$item;
15572: my $class = $args->{'crscode'}.$sec;
15573: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15574: $cenv{'internal.sectionnums'} .= $item.',';
1.1075.2.166! raeburn 15575: if ($addcheck eq 'ok') {
! 15576: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
! 15577: push(@oklcsecs,$gp);
! 15578: }
! 15579: } else {
1.1075.2.119 raeburn 15580: push(@badclasses,$class);
1.444 albertel 15581: }
15582: }
15583: $cenv{'internal.sectionnums'} =~ s/,$//;
15584: }
15585: }
15586: # do not hide course coordinator from staff listing,
15587: # even if privileged
15588: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15589: # add course coordinator's domain to domains to check for privileged users
15590: # if different to course domain
15591: if ($$crsudom ne $args->{'ccdomain'}) {
15592: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15593: }
1.444 albertel 15594: # add crosslistings
15595: if ($args->{'crsxlist'}) {
15596: $cenv{'internal.crosslistings'}='';
15597: if ($args->{'crsxlist'} =~ m/,/) {
15598: @xlists = split/,/,$args->{'crsxlist'};
15599: } else {
15600: $xlists[0] = $args->{'crsxlist'};
15601: }
15602: if (@xlists > 0) {
15603: foreach my $item (@xlists) {
15604: my ($xl,$gp) = split/:/,$item;
15605: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15606: $cenv{'internal.crosslistings'} .= $item.',';
1.1075.2.166! raeburn 15607: if ($addcheck eq 'ok') {
! 15608: unless (grep(/^\Q$gp\E$/,@oklcsecs)) {
! 15609: push(@oklcsecs,$gp);
! 15610: }
! 15611: } else {
1.1075.2.119 raeburn 15612: push(@badclasses,$xl);
1.444 albertel 15613: }
15614: }
15615: $cenv{'internal.crosslistings'} =~ s/,$//;
15616: }
15617: }
15618: if ($args->{'autoadds'}) {
15619: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15620: }
15621: if ($args->{'autodrops'}) {
15622: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15623: }
15624: # check for notification of enrollment changes
15625: my @notified = ();
15626: if ($args->{'notify_owner'}) {
15627: if ($args->{'ccuname'} ne '') {
15628: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15629: }
15630: }
15631: if ($args->{'notify_dc'}) {
15632: if ($uname ne '') {
1.630 raeburn 15633: push(@notified,$uname.':'.$udom);
1.444 albertel 15634: }
15635: }
15636: if (@notified > 0) {
15637: my $notifylist;
15638: if (@notified > 1) {
15639: $notifylist = join(',',@notified);
15640: } else {
15641: $notifylist = $notified[0];
15642: }
15643: $cenv{'internal.notifylist'} = $notifylist;
15644: }
15645: if (@badclasses > 0) {
15646: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15647: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15648: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15649: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15650: );
1.1075.2.119 raeburn 15651: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15652: &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 15653: if ($context eq 'auto') {
15654: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15655: } else {
1.566 albertel 15656: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15657: }
15658: foreach my $item (@badclasses) {
1.541 raeburn 15659: if ($context eq 'auto') {
1.1075.2.119 raeburn 15660: $outcome .= " - $item\n";
1.541 raeburn 15661: } else {
1.1075.2.119 raeburn 15662: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15663: }
1.1075.2.119 raeburn 15664: }
15665: if ($context eq 'auto') {
15666: $outcome .= $linefeed;
15667: } else {
15668: $outcome .= "</ul><br /><br /></div>\n";
15669: }
1.444 albertel 15670: }
15671: if ($args->{'no_end_date'}) {
15672: $args->{'endaccess'} = 0;
15673: }
1.1075.2.166! raeburn 15674: # If an official course with institutional sections is created by cloning
! 15675: # an existing course, section-specific hiding of course totals in student's
! 15676: # view of grades as copied from cloned course, will be checked for valid
! 15677: # sections.
! 15678: if (($can_clone && $cloneid) &&
! 15679: ($cenv{'internal.coursecode'} ne '') &&
! 15680: ($cenv{'grading'} eq 'standard') &&
! 15681: ($cenv{'hidetotals'} ne '') &&
! 15682: ($cenv{'hidetotals'} ne 'all')) {
! 15683: my @hidesecs;
! 15684: my $deletehidetotals;
! 15685: if (@oklcsecs) {
! 15686: foreach my $sec (split(/,/,$cenv{'hidetotals'})) {
! 15687: if (grep(/^\Q$sec$/,@oklcsecs)) {
! 15688: push(@hidesecs,$sec);
! 15689: }
! 15690: }
! 15691: if (@hidesecs) {
! 15692: $cenv{'hidetotals'} = join(',',@hidesecs);
! 15693: } else {
! 15694: $deletehidetotals = 1;
! 15695: }
! 15696: } else {
! 15697: $deletehidetotals = 1;
! 15698: }
! 15699: if ($deletehidetotals) {
! 15700: delete($cenv{'hidetotals'});
! 15701: &Apache::lonnet::del('environment',['hidetotals'],$$crsudom,$$crsunum);
! 15702: }
! 15703: }
1.444 albertel 15704: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15705: $cenv{'internal.autoend'}=$args->{'enrollend'};
15706: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15707: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15708: if ($args->{'showphotos'}) {
15709: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15710: }
15711: $cenv{'internal.authtype'} = $args->{'authtype'};
15712: $cenv{'internal.autharg'} = $args->{'autharg'};
15713: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15714: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15715: 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');
15716: if ($context eq 'auto') {
15717: $outcome .= $krb_msg;
15718: } else {
1.566 albertel 15719: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15720: }
15721: $outcome .= $linefeed;
1.444 albertel 15722: }
15723: }
15724: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15725: if ($args->{'setpolicy'}) {
15726: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15727: }
15728: if ($args->{'setcontent'}) {
15729: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15730: }
1.1075.2.110 raeburn 15731: if ($args->{'setcomment'}) {
15732: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15733: }
1.444 albertel 15734: }
15735: if ($args->{'reshome'}) {
15736: $cenv{'reshome'}=$args->{'reshome'}.'/';
15737: $cenv{'reshome'}=~s/\/+$/\//;
15738: }
15739: #
15740: # course has keyed access
15741: #
15742: if ($args->{'setkeys'}) {
15743: $cenv{'keyaccess'}='yes';
15744: }
15745: # if specified, key authority is not course, but user
15746: # only active if keyaccess is yes
15747: if ($args->{'keyauth'}) {
1.487 albertel 15748: my ($user,$domain) = split(':',$args->{'keyauth'});
15749: $user = &LONCAPA::clean_username($user);
15750: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15751: if ($user ne '' && $domain ne '') {
1.487 albertel 15752: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15753: }
15754: }
15755:
1.1075.2.59 raeburn 15756: #
15757: # generate and store uniquecode (available to course requester), if course should have one.
15758: #
15759: if ($args->{'uniquecode'}) {
15760: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15761: if ($code) {
15762: $cenv{'internal.uniquecode'} = $code;
15763: my %crsinfo =
15764: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15765: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15766: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15767: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15768: }
15769: if (ref($coderef)) {
15770: $$coderef = $code;
15771: }
15772: }
15773: }
15774:
1.444 albertel 15775: if ($args->{'disresdis'}) {
15776: $cenv{'pch.roles.denied'}='st';
15777: }
15778: if ($args->{'disablechat'}) {
15779: $cenv{'plc.roles.denied'}='st';
15780: }
15781:
15782: # Record we've not yet viewed the Course Initialization Helper for this
15783: # course
15784: $cenv{'course.helper.not.run'} = 1;
15785: #
15786: # Use new Randomseed
15787: #
15788: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15789: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15790: #
15791: # The encryption code and receipt prefix for this course
15792: #
15793: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15794: $cenv{'internal.encpref'}=100+int(9*rand(99));
15795: #
15796: # By default, use standard grading
15797: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15798:
1.541 raeburn 15799: $outcome .= $linefeed.&mt('Setting environment').': '.
15800: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15801: #
15802: # Open all assignments
15803: #
15804: if ($args->{'openall'}) {
1.1075.2.146 raeburn 15805: my $opendate = time;
15806: if ($args->{'openallfrom'} =~ /^\d+$/) {
15807: $opendate = $args->{'openallfrom'};
15808: }
1.444 albertel 15809: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 15810: my %storecontent = ($storeunder => $opendate,
1.444 albertel 15811: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 15812: $outcome .= &mt('All assignments open starting [_1]',
15813: &Apache::lonlocal::locallocaltime($opendate)).': '.
15814: &Apache::lonnet::cput
15815: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15816: }
15817: #
15818: # Set first page
15819: #
15820: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15821: || ($cloneid)) {
1.445 albertel 15822: use LONCAPA::map;
1.444 albertel 15823: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15824:
15825: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15826: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15827:
1.444 albertel 15828: $outcome .= ($fatal?$errtext:'read ok').' - ';
15829: my $title; my $url;
15830: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15831: $title=&mt('Syllabus');
1.444 albertel 15832: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15833: } else {
1.963 raeburn 15834: $title=&mt('Table of Contents');
1.444 albertel 15835: $url='/adm/navmaps';
15836: }
1.445 albertel 15837:
15838: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15839: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15840:
15841: if ($errtext) { $fatal=2; }
1.541 raeburn 15842: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15843: }
1.566 albertel 15844:
15845: return (1,$outcome);
1.444 albertel 15846: }
15847:
1.1075.2.59 raeburn 15848: sub make_unique_code {
15849: my ($cdom,$cnum) = @_;
15850: # get lock on uniquecodes db
15851: my $lockhash = {
15852: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15853: ':'.$env{'user.domain'},
15854: };
15855: my $tries = 0;
15856: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15857: my ($code,$error);
15858:
15859: while (($gotlock ne 'ok') && ($tries<3)) {
15860: $tries ++;
15861: sleep 1;
15862: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15863: }
15864: if ($gotlock eq 'ok') {
15865: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15866: my $gotcode;
15867: my $attempts = 0;
15868: while ((!$gotcode) && ($attempts < 100)) {
15869: $code = &generate_code();
15870: if (!exists($currcodes{$code})) {
15871: $gotcode = 1;
15872: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15873: $error = 'nostore';
15874: }
15875: }
15876: $attempts ++;
15877: }
15878: my @del_lock = ($cnum."\0".'uniquecodes');
15879: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15880: } else {
15881: $error = 'nolock';
15882: }
15883: return ($code,$error);
15884: }
15885:
15886: sub generate_code {
15887: my $code;
15888: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15889: for (my $i=0; $i<6; $i++) {
15890: my $lettnum = int (rand 2);
15891: my $item = '';
15892: if ($lettnum) {
15893: $item = $letts[int( rand(18) )];
15894: } else {
15895: $item = 1+int( rand(8) );
15896: }
15897: $code .= $item;
15898: }
15899: return $code;
15900: }
15901:
1.444 albertel 15902: ############################################################
15903: ############################################################
15904:
1.953 droeschl 15905: #SD
15906: # only Community and Course, or anything else?
1.378 raeburn 15907: sub course_type {
15908: my ($cid) = @_;
15909: if (!defined($cid)) {
15910: $cid = $env{'request.course.id'};
15911: }
1.404 albertel 15912: if (defined($env{'course.'.$cid.'.type'})) {
15913: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15914: } else {
15915: return 'Course';
1.377 raeburn 15916: }
15917: }
1.156 albertel 15918:
1.406 raeburn 15919: sub group_term {
15920: my $crstype = &course_type();
15921: my %names = (
15922: 'Course' => 'group',
1.865 raeburn 15923: 'Community' => 'group',
1.406 raeburn 15924: );
15925: return $names{$crstype};
15926: }
15927:
1.902 raeburn 15928: sub course_types {
1.1075.2.59 raeburn 15929: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15930: my %typename = (
15931: official => 'Official course',
15932: unofficial => 'Unofficial course',
15933: community => 'Community',
1.1075.2.59 raeburn 15934: textbook => 'Textbook course',
1.902 raeburn 15935: );
15936: return (\@types,\%typename);
15937: }
15938:
1.156 albertel 15939: sub icon {
15940: my ($file)=@_;
1.505 albertel 15941: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15942: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15943: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15944: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15945: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15946: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15947: $curfext.".gif") {
15948: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15949: $curfext.".gif";
15950: }
15951: }
1.249 albertel 15952: return &lonhttpdurl($iconname);
1.154 albertel 15953: }
1.84 albertel 15954:
1.575 albertel 15955: sub lonhttpdurl {
1.692 www 15956: #
15957: # Had been used for "small fry" static images on separate port 8080.
15958: # Modify here if lightweight http functionality desired again.
15959: # Currently eliminated due to increasing firewall issues.
15960: #
1.575 albertel 15961: my ($url)=@_;
1.692 www 15962: return $url;
1.215 albertel 15963: }
15964:
1.213 albertel 15965: sub connection_aborted {
15966: my ($r)=@_;
15967: $r->print(" ");$r->rflush();
15968: my $c = $r->connection;
15969: return $c->aborted();
15970: }
15971:
1.221 foxr 15972: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15973: # strings as 'strings'.
15974: sub escape_single {
1.221 foxr 15975: my ($input) = @_;
1.223 albertel 15976: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15977: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15978: return $input;
15979: }
1.223 albertel 15980:
1.222 foxr 15981: # Same as escape_single, but escape's "'s This
15982: # can be used for "strings"
15983: sub escape_double {
15984: my ($input) = @_;
15985: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15986: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15987: return $input;
15988: }
1.223 albertel 15989:
1.222 foxr 15990: # Escapes the last element of a full URL.
15991: sub escape_url {
15992: my ($url) = @_;
1.238 raeburn 15993: my @urlslices = split(/\//, $url,-1);
1.369 www 15994: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15995: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15996: }
1.462 albertel 15997:
1.820 raeburn 15998: sub compare_arrays {
15999: my ($arrayref1,$arrayref2) = @_;
16000: my (@difference,%count);
16001: @difference = ();
16002: %count = ();
16003: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16004: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16005: foreach my $element (keys(%count)) {
16006: if ($count{$element} == 1) {
16007: push(@difference,$element);
16008: }
16009: }
16010: }
16011: return @difference;
16012: }
16013:
1.1075.2.152 raeburn 16014: sub lon_status_items {
16015: my %defaults = (
16016: E => 100,
16017: W => 4,
16018: N => 1,
16019: U => 5,
16020: threshold => 200,
16021: sysmail => 2500,
16022: );
16023: my %names = (
16024: E => 'Errors',
16025: W => 'Warnings',
16026: N => 'Notices',
16027: U => 'Unsent',
16028: );
16029: return (\%defaults,\%names);
16030: }
16031:
1.817 bisitz 16032: # -------------------------------------------------------- Initialize user login
1.462 albertel 16033: sub init_user_environment {
1.463 albertel 16034: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16035: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16036:
16037: my $public=($username eq 'public' && $domain eq 'public');
16038:
16039: # See if old ID present, if so, remove
16040:
1.1062 raeburn 16041: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16042: my $now=time;
16043:
16044: if ($public) {
16045: my $max_public=100;
16046: my $oldest;
16047: my $oldest_time=0;
16048: for(my $next=1;$next<=$max_public;$next++) {
16049: if (-e $lonids."/publicuser_$next.id") {
16050: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16051: if ($mtime<$oldest_time || !$oldest_time) {
16052: $oldest_time=$mtime;
16053: $oldest=$next;
16054: }
16055: } else {
16056: $cookie="publicuser_$next";
16057: last;
16058: }
16059: }
16060: if (!$cookie) { $cookie="publicuser_$oldest"; }
16061: } else {
1.463 albertel 16062: # if this isn't a robot, kill any existing non-robot sessions
16063: if (!$args->{'robot'}) {
16064: opendir(DIR,$lonids);
16065: while ($filename=readdir(DIR)) {
16066: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 16067: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16068: &GDBM_READER(),0640)) {
16069: my $linkedfile;
16070: if (exists($oldenv{'user.linkedenv'})) {
16071: $linkedfile = $oldenv{'user.linkedenv'};
16072: }
16073: untie(%oldenv);
16074: if (unlink("$lonids/$filename")) {
16075: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16076: if (-l "$lonids/$linkedfile.id") {
16077: unlink("$lonids/$linkedfile.id");
16078: }
16079: }
16080: }
16081: } else {
16082: unlink($lonids.'/'.$filename);
16083: }
1.463 albertel 16084: }
1.462 albertel 16085: }
1.463 albertel 16086: closedir(DIR);
1.1075.2.84 raeburn 16087: # If there is a undeleted lockfile for the user's paste buffer remove it.
16088: my $namespace = 'nohist_courseeditor';
16089: my $lockingkey = 'paste'."\0".'locked_num';
16090: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16091: $domain,$username);
16092: if (exists($lockhash{$lockingkey})) {
16093: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16094: unless ($delresult eq 'ok') {
16095: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16096: }
16097: }
1.462 albertel 16098: }
16099: # Give them a new cookie
1.463 albertel 16100: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16101: : $now.$$.int(rand(10000)));
1.463 albertel 16102: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16103:
16104: # Initialize roles
16105:
1.1062 raeburn 16106: ($userroles,$firstaccenv,$timerintenv) =
16107: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16108: }
16109: # ------------------------------------ Check browser type and MathML capability
16110:
1.1075.2.77 raeburn 16111: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16112: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16113:
16114: # ------------------------------------------------------------- Get environment
16115:
16116: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16117: my ($tmp) = keys(%userenv);
16118: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
16119: } else {
16120: undef(%userenv);
16121: }
16122: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16123: $form->{'interface'}=$userenv{'interface'};
16124: }
16125: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16126:
16127: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16128: foreach my $option ('interface','localpath','localres') {
16129: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16130: }
16131: # --------------------------------------------------------- Write first profile
16132:
16133: {
1.1075.2.150 raeburn 16134: my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 16135: my %initial_env =
16136: ("user.name" => $username,
16137: "user.domain" => $domain,
16138: "user.home" => $authhost,
16139: "browser.type" => $clientbrowser,
16140: "browser.version" => $clientversion,
16141: "browser.mathml" => $clientmathml,
16142: "browser.unicode" => $clientunicode,
16143: "browser.os" => $clientos,
1.1075.2.42 raeburn 16144: "browser.mobile" => $clientmobile,
16145: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 16146: "browser.osversion" => $clientosversion,
1.462 albertel 16147: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16148: "request.course.fn" => '',
16149: "request.course.uri" => '',
16150: "request.course.sec" => '',
16151: "request.role" => 'cm',
16152: "request.role.adv" => $env{'user.adv'},
1.1075.2.150 raeburn 16153: "request.host" => $ip,);
1.462 albertel 16154:
16155: if ($form->{'localpath'}) {
16156: $initial_env{"browser.localpath"} = $form->{'localpath'};
16157: $initial_env{"browser.localres"} = $form->{'localres'};
16158: }
16159:
16160: if ($form->{'interface'}) {
16161: $form->{'interface'}=~s/\W//gs;
16162: $initial_env{"browser.interface"} = $form->{'interface'};
16163: $env{'browser.interface'}=$form->{'interface'};
16164: }
16165:
1.1075.2.54 raeburn 16166: if ($form->{'iptoken'}) {
16167: my $lonhost = $r->dir_config('lonHostID');
16168: $initial_env{"user.noloadbalance"} = $lonhost;
16169: $env{'user.noloadbalance'} = $lonhost;
16170: }
16171:
1.1075.2.120 raeburn 16172: if ($form->{'noloadbalance'}) {
16173: my @hosts = &Apache::lonnet::current_machine_ids();
16174: my $hosthere = $form->{'noloadbalance'};
16175: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16176: $initial_env{"user.noloadbalance"} = $hosthere;
16177: $env{'user.noloadbalance'} = $hosthere;
16178: }
16179: }
16180:
1.1016 raeburn 16181: unless ($domain eq 'public') {
1.1075.2.125 raeburn 16182: my %is_adv = ( is_adv => $env{'user.adv'} );
16183: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 16184:
1.1075.2.125 raeburn 16185: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16186: $userenv{'availabletools.'.$tool} =
16187: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16188: undef,\%userenv,\%domdef,\%is_adv);
16189: }
1.724 raeburn 16190:
1.1075.2.125 raeburn 16191: foreach my $crstype ('official','unofficial','community','textbook') {
16192: $userenv{'canrequest.'.$crstype} =
16193: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16194: 'reload','requestcourses',
16195: \%userenv,\%domdef,\%is_adv);
16196: }
1.765 raeburn 16197:
1.1075.2.125 raeburn 16198: $userenv{'canrequest.author'} =
16199: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16200: 'reload','requestauthor',
16201: \%userenv,\%domdef,\%is_adv);
16202: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16203: $domain,$username);
16204: my $reqstatus = $reqauthor{'author_status'};
16205: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16206: if (ref($reqauthor{'author'}) eq 'HASH') {
16207: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16208: $reqauthor{'author'}{'timestamp'};
16209: }
1.1075.2.14 raeburn 16210: }
16211: }
16212:
1.462 albertel 16213: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16214:
1.462 albertel 16215: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16216: &GDBM_WRCREAT(),0640)) {
16217: &_add_to_env(\%disk_env,\%initial_env);
16218: &_add_to_env(\%disk_env,\%userenv,'environment.');
16219: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16220: if (ref($firstaccenv) eq 'HASH') {
16221: &_add_to_env(\%disk_env,$firstaccenv);
16222: }
16223: if (ref($timerintenv) eq 'HASH') {
16224: &_add_to_env(\%disk_env,$timerintenv);
16225: }
1.463 albertel 16226: if (ref($args->{'extra_env'})) {
16227: &_add_to_env(\%disk_env,$args->{'extra_env'});
16228: }
1.462 albertel 16229: untie(%disk_env);
16230: } else {
1.705 tempelho 16231: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16232: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16233: return 'error: '.$!;
16234: }
16235: }
16236: $env{'request.role'}='cm';
16237: $env{'request.role.adv'}=$env{'user.adv'};
16238: $env{'browser.type'}=$clientbrowser;
16239:
16240: return $cookie;
16241:
16242: }
16243:
16244: sub _add_to_env {
16245: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16246: if (ref($env_data) eq 'HASH') {
16247: while (my ($key,$value) = each(%$env_data)) {
16248: $idf->{$prefix.$key} = $value;
16249: $env{$prefix.$key} = $value;
16250: }
1.462 albertel 16251: }
16252: }
16253:
1.685 tempelho 16254: # --- Get the symbolic name of a problem and the url
16255: sub get_symb {
16256: my ($request,$silent) = @_;
1.726 raeburn 16257: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16258: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16259: if ($symb eq '') {
16260: if (!$silent) {
1.1071 raeburn 16261: if (ref($request)) {
16262: $request->print("Unable to handle ambiguous references:$url:.");
16263: }
1.685 tempelho 16264: return ();
16265: }
16266: }
16267: &Apache::lonenc::check_decrypt(\$symb);
16268: return ($symb);
16269: }
16270:
16271: # --------------------------------------------------------------Get annotation
16272:
16273: sub get_annotation {
16274: my ($symb,$enc) = @_;
16275:
16276: my $key = $symb;
16277: if (!$enc) {
16278: $key =
16279: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16280: }
16281: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16282: return $annotation{$key};
16283: }
16284:
16285: sub clean_symb {
1.731 raeburn 16286: my ($symb,$delete_enc) = @_;
1.685 tempelho 16287:
16288: &Apache::lonenc::check_decrypt(\$symb);
16289: my $enc = $env{'request.enc'};
1.731 raeburn 16290: if ($delete_enc) {
1.730 raeburn 16291: delete($env{'request.enc'});
16292: }
1.685 tempelho 16293:
16294: return ($symb,$enc);
16295: }
1.462 albertel 16296:
1.1075.2.69 raeburn 16297: ############################################################
16298: ############################################################
16299:
16300: =pod
16301:
16302: =head1 Routines for building display used to search for courses
16303:
16304:
16305: =over 4
16306:
16307: =item * &build_filters()
16308:
16309: Create markup for a table used to set filters to use when selecting
16310: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16311: and quotacheck.pl
16312:
16313:
16314: Inputs:
16315:
16316: filterlist - anonymous array of fields to include as potential filters
16317:
16318: crstype - course type
16319:
16320: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16321: to pop-open a course selector (will contain "extra element").
16322:
16323: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16324:
16325: filter - anonymous hash of criteria and their values
16326:
16327: action - form action
16328:
16329: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16330:
16331: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
16332:
16333: cloneruname - username of owner of new course who wants to clone
16334:
16335: clonerudom - domain of owner of new course who wants to clone
16336:
16337: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16338:
16339: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16340:
16341: codedom - domain
16342:
16343: formname - value of form element named "form".
16344:
16345: fixeddom - domain, if fixed.
16346:
16347: prevphase - value to assign to form element named "phase" when going back to the previous screen
16348:
16349: cnameelement - name of form element in form on opener page which will receive title of selected course
16350:
16351: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16352:
16353: cdomelement - name of form element in form on opener page which will receive domain of selected course
16354:
16355: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16356:
16357: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16358:
16359: clonewarning - warning message about missing information for intended course owner when DC creates a course
16360:
16361:
16362: Returns: $output - HTML for display of search criteria, and hidden form elements.
16363:
16364:
16365: Side Effects: None
16366:
16367: =cut
16368:
16369: # ---------------------------------------------- search for courses based on last activity etc.
16370:
16371: sub build_filters {
16372: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16373: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16374: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16375: $cnameelement,$cnumelement,$cdomelement,$setroles,
16376: $clonetext,$clonewarning) = @_;
16377: my ($list,$jscript);
16378: my $onchange = 'javascript:updateFilters(this)';
16379: my ($domainselectform,$sincefilterform,$createdfilterform,
16380: $ownerdomselectform,$persondomselectform,$instcodeform,
16381: $typeselectform,$instcodetitle);
16382: if ($formname eq '') {
16383: $formname = $caller;
16384: }
16385: foreach my $item (@{$filterlist}) {
16386: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16387: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16388: if ($item eq 'domainfilter') {
16389: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16390: } elsif ($item eq 'coursefilter') {
16391: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16392: } elsif ($item eq 'ownerfilter') {
16393: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16394: } elsif ($item eq 'ownerdomfilter') {
16395: $filter->{'ownerdomfilter'} =
16396: &LONCAPA::clean_domain($filter->{$item});
16397: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16398: 'ownerdomfilter',1);
16399: } elsif ($item eq 'personfilter') {
16400: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16401: } elsif ($item eq 'persondomfilter') {
16402: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16403: 'persondomfilter',1);
16404: } else {
16405: $filter->{$item} =~ s/\W//g;
16406: }
16407: if (!$filter->{$item}) {
16408: $filter->{$item} = '';
16409: }
16410: }
16411: if ($item eq 'domainfilter') {
16412: my $allow_blank = 1;
16413: if ($formname eq 'portform') {
16414: $allow_blank=0;
16415: } elsif ($formname eq 'studentform') {
16416: $allow_blank=0;
16417: }
16418: if ($fixeddom) {
16419: $domainselectform = '<input type="hidden" name="domainfilter"'.
16420: ' value="'.$codedom.'" />'.
16421: &Apache::lonnet::domain($codedom,'description');
16422: } else {
16423: $domainselectform = &select_dom_form($filter->{$item},
16424: 'domainfilter',
16425: $allow_blank,'',$onchange);
16426: }
16427: } else {
16428: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16429: }
16430: }
16431:
16432: # last course activity filter and selection
16433: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16434:
16435: # course created filter and selection
16436: if (exists($filter->{'createdfilter'})) {
16437: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16438: }
16439:
16440: my %lt = &Apache::lonlocal::texthash(
16441: 'cac' => "$crstype Activity",
16442: 'ccr' => "$crstype Created",
16443: 'cde' => "$crstype Title",
16444: 'cdo' => "$crstype Domain",
16445: 'ins' => 'Institutional Code',
16446: 'inc' => 'Institutional Categorization',
16447: 'cow' => "$crstype Owner/Co-owner",
16448: 'cop' => "$crstype Personnel Includes",
16449: 'cog' => 'Type',
16450: );
16451:
16452: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16453: my $typeval = 'Course';
16454: if ($crstype eq 'Community') {
16455: $typeval = 'Community';
16456: }
16457: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16458: } else {
16459: $typeselectform = '<select name="type" size="1"';
16460: if ($onchange) {
16461: $typeselectform .= ' onchange="'.$onchange.'"';
16462: }
16463: $typeselectform .= '>'."\n";
16464: foreach my $posstype ('Course','Community') {
16465: $typeselectform.='<option value="'.$posstype.'"'.
16466: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16467: }
16468: $typeselectform.="</select>";
16469: }
16470:
16471: my ($cloneableonlyform,$cloneabletitle);
16472: if (exists($filter->{'cloneableonly'})) {
16473: my $cloneableon = '';
16474: my $cloneableoff = ' checked="checked"';
16475: if ($filter->{'cloneableonly'}) {
16476: $cloneableon = $cloneableoff;
16477: $cloneableoff = '';
16478: }
16479: $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>';
16480: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16481: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16482: } else {
16483: $cloneabletitle = &mt('Cloneable by you');
16484: }
16485: }
16486: my $officialjs;
16487: if ($crstype eq 'Course') {
16488: if (exists($filter->{'instcodefilter'})) {
16489: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16490: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16491: if ($codedom) {
16492: $officialjs = 1;
16493: ($instcodeform,$jscript,$$numtitlesref) =
16494: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16495: $officialjs,$codetitlesref);
16496: if ($jscript) {
16497: $jscript = '<script type="text/javascript">'."\n".
16498: '// <![CDATA['."\n".
16499: $jscript."\n".
16500: '// ]]>'."\n".
16501: '</script>'."\n";
16502: }
16503: }
16504: if ($instcodeform eq '') {
16505: $instcodeform =
16506: '<input type="text" name="instcodefilter" size="10" value="'.
16507: $list->{'instcodefilter'}.'" />';
16508: $instcodetitle = $lt{'ins'};
16509: } else {
16510: $instcodetitle = $lt{'inc'};
16511: }
16512: if ($fixeddom) {
16513: $instcodetitle .= '<br />('.$codedom.')';
16514: }
16515: }
16516: }
16517: my $output = qq|
16518: <form method="post" name="filterpicker" action="$action">
16519: <input type="hidden" name="form" value="$formname" />
16520: |;
16521: if ($formname eq 'modifycourse') {
16522: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16523: '<input type="hidden" name="prevphase" value="'.
16524: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16525: } elsif ($formname eq 'quotacheck') {
16526: $output .= qq|
16527: <input type="hidden" name="sortby" value="" />
16528: <input type="hidden" name="sortorder" value="" />
16529: |;
16530: } else {
1.1075.2.69 raeburn 16531: my $name_input;
16532: if ($cnameelement ne '') {
16533: $name_input = '<input type="hidden" name="cnameelement" value="'.
16534: $cnameelement.'" />';
16535: }
16536: $output .= qq|
16537: <input type="hidden" name="cnumelement" value="$cnumelement" />
16538: <input type="hidden" name="cdomelement" value="$cdomelement" />
16539: $name_input
16540: $roleelement
16541: $multelement
16542: $typeelement
16543: |;
16544: if ($formname eq 'portform') {
16545: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16546: }
16547: }
16548: if ($fixeddom) {
16549: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16550: }
16551: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16552: if ($sincefilterform) {
16553: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16554: .$sincefilterform
16555: .&Apache::lonhtmlcommon::row_closure();
16556: }
16557: if ($createdfilterform) {
16558: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16559: .$createdfilterform
16560: .&Apache::lonhtmlcommon::row_closure();
16561: }
16562: if ($domainselectform) {
16563: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16564: .$domainselectform
16565: .&Apache::lonhtmlcommon::row_closure();
16566: }
16567: if ($typeselectform) {
16568: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16569: $output .= $typeselectform;
16570: } else {
16571: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16572: .$typeselectform
16573: .&Apache::lonhtmlcommon::row_closure();
16574: }
16575: }
16576: if ($instcodeform) {
16577: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16578: .$instcodeform
16579: .&Apache::lonhtmlcommon::row_closure();
16580: }
16581: if (exists($filter->{'ownerfilter'})) {
16582: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16583: '<table><tr><td>'.&mt('Username').'<br />'.
16584: '<input type="text" name="ownerfilter" size="20" value="'.
16585: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16586: $ownerdomselectform.'</td></tr></table>'.
16587: &Apache::lonhtmlcommon::row_closure();
16588: }
16589: if (exists($filter->{'personfilter'})) {
16590: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16591: '<table><tr><td>'.&mt('Username').'<br />'.
16592: '<input type="text" name="personfilter" size="20" value="'.
16593: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16594: $persondomselectform.'</td></tr></table>'.
16595: &Apache::lonhtmlcommon::row_closure();
16596: }
16597: if (exists($filter->{'coursefilter'})) {
16598: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16599: .'<input type="text" name="coursefilter" size="25" value="'
16600: .$list->{'coursefilter'}.'" />'
16601: .&Apache::lonhtmlcommon::row_closure();
16602: }
16603: if ($cloneableonlyform) {
16604: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16605: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16606: }
16607: if (exists($filter->{'descriptfilter'})) {
16608: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16609: .'<input type="text" name="descriptfilter" size="40" value="'
16610: .$list->{'descriptfilter'}.'" />'
16611: .&Apache::lonhtmlcommon::row_closure(1);
16612: }
16613: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16614: '<input type="hidden" name="updater" value="" />'."\n".
16615: '<input type="submit" name="gosearch" value="'.
16616: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16617: return $jscript.$clonewarning.$output;
16618: }
16619:
16620: =pod
16621:
16622: =item * &timebased_select_form()
16623:
16624: Create markup for a dropdown list used to select a time-based
16625: filter e.g., Course Activity, Course Created, when searching for courses
16626: or communities
16627:
16628: Inputs:
16629:
16630: item - name of form element (sincefilter or createdfilter)
16631:
16632: filter - anonymous hash of criteria and their values
16633:
16634: Returns: HTML for a select box contained a blank, then six time selections,
16635: with value set in incoming form variables currently selected.
16636:
16637: Side Effects: None
16638:
16639: =cut
16640:
16641: sub timebased_select_form {
16642: my ($item,$filter) = @_;
16643: if (ref($filter) eq 'HASH') {
16644: $filter->{$item} =~ s/[^\d-]//g;
16645: if (!$filter->{$item}) { $filter->{$item}=-1; }
16646: return &select_form(
16647: $filter->{$item},
16648: $item,
16649: { '-1' => '',
16650: '86400' => &mt('today'),
16651: '604800' => &mt('last week'),
16652: '2592000' => &mt('last month'),
16653: '7776000' => &mt('last three months'),
16654: '15552000' => &mt('last six months'),
16655: '31104000' => &mt('last year'),
16656: 'select_form_order' =>
16657: ['-1','86400','604800','2592000','7776000',
16658: '15552000','31104000']});
16659: }
16660: }
16661:
16662: =pod
16663:
16664: =item * &js_changer()
16665:
16666: Create script tag containing Javascript used to submit course search form
16667: when course type or domain is changed, and also to hide 'Searching ...' on
16668: page load completion for page showing search result.
16669:
16670: Inputs: None
16671:
16672: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16673:
16674: Side Effects: None
16675:
16676: =cut
16677:
16678: sub js_changer {
16679: return <<ENDJS;
16680: <script type="text/javascript">
16681: // <![CDATA[
16682: function updateFilters(caller) {
16683: if (typeof(caller) != "undefined") {
16684: document.filterpicker.updater.value = caller.name;
16685: }
16686: document.filterpicker.submit();
16687: }
16688:
16689: function hideSearching() {
16690: if (document.getElementById('searching')) {
16691: document.getElementById('searching').style.display = 'none';
16692: }
16693: return;
16694: }
16695:
16696: // ]]>
16697: </script>
16698:
16699: ENDJS
16700: }
16701:
16702: =pod
16703:
16704: =item * &search_courses()
16705:
16706: Process selected filters form course search form and pass to lonnet::courseiddump
16707: to retrieve a hash for which keys are courseIDs which match the selected filters.
16708:
16709: Inputs:
16710:
16711: dom - domain being searched
16712:
16713: type - course type ('Course' or 'Community' or '.' if any).
16714:
16715: filter - anonymous hash of criteria and their values
16716:
16717: numtitles - for institutional codes - number of categories
16718:
16719: cloneruname - optional username of new course owner
16720:
16721: clonerudom - optional domain of new course owner
16722:
1.1075.2.95 raeburn 16723: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16724: (used when DC is using course creation form)
16725:
16726: codetitles - reference to array of titles of components in institutional codes (official courses).
16727:
1.1075.2.95 raeburn 16728: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16729: (and so can clone automatically)
16730:
16731: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16732:
16733: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16734: courses to clone
1.1075.2.69 raeburn 16735:
16736: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16737:
16738:
16739: Side Effects: None
16740:
16741: =cut
16742:
16743:
16744: sub search_courses {
1.1075.2.95 raeburn 16745: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16746: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16747: my (%courses,%showcourses,$cloner);
16748: if (($filter->{'ownerfilter'} ne '') ||
16749: ($filter->{'ownerdomfilter'} ne '')) {
16750: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16751: $filter->{'ownerdomfilter'};
16752: }
16753: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16754: if (!$filter->{$item}) {
16755: $filter->{$item}='.';
16756: }
16757: }
16758: my $now = time;
16759: my $timefilter =
16760: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16761: my ($createdbefore,$createdafter);
16762: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16763: $createdbefore = $now;
16764: $createdafter = $now-$filter->{'createdfilter'};
16765: }
16766: my ($instcodefilter,$regexpok);
16767: if ($numtitles) {
16768: if ($env{'form.official'} eq 'on') {
16769: $instcodefilter =
16770: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16771: $regexpok = 1;
16772: } elsif ($env{'form.official'} eq 'off') {
16773: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16774: unless ($instcodefilter eq '') {
16775: $regexpok = -1;
16776: }
16777: }
16778: } else {
16779: $instcodefilter = $filter->{'instcodefilter'};
16780: }
16781: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16782: if ($type eq '') { $type = '.'; }
16783:
16784: if (($clonerudom ne '') && ($cloneruname ne '')) {
16785: $cloner = $cloneruname.':'.$clonerudom;
16786: }
16787: %courses = &Apache::lonnet::courseiddump($dom,
16788: $filter->{'descriptfilter'},
16789: $timefilter,
16790: $instcodefilter,
16791: $filter->{'combownerfilter'},
16792: $filter->{'coursefilter'},
16793: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16794: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16795: $filter->{'cloneableonly'},
16796: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16797: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16798: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16799: my $ccrole;
16800: if ($type eq 'Community') {
16801: $ccrole = 'co';
16802: } else {
16803: $ccrole = 'cc';
16804: }
16805: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16806: $filter->{'persondomfilter'},
16807: 'userroles',undef,
16808: [$ccrole,'in','ad','ep','ta','cr'],
16809: $dom);
16810: foreach my $role (keys(%rolehash)) {
16811: my ($cnum,$cdom,$courserole) = split(':',$role);
16812: my $cid = $cdom.'_'.$cnum;
16813: if (exists($courses{$cid})) {
16814: if (ref($courses{$cid}) eq 'HASH') {
16815: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16816: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16817: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16818: }
16819: } else {
16820: $courses{$cid}{roles} = [$courserole];
16821: }
16822: $showcourses{$cid} = $courses{$cid};
16823: }
16824: }
16825: }
16826: %courses = %showcourses;
16827: }
16828: return %courses;
16829: }
16830:
16831: =pod
16832:
16833: =back
16834:
1.1075.2.88 raeburn 16835: =head1 Routines for version requirements for current course.
16836:
16837: =over 4
16838:
16839: =item * &check_release_required()
16840:
16841: Compares required LON-CAPA version with version on server, and
16842: if required version is newer looks for a server with the required version.
16843:
16844: Looks first at servers in user's owen domain; if none suitable, looks at
16845: servers in course's domain are permitted to host sessions for user's domain.
16846:
16847: Inputs:
16848:
16849: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16850:
16851: $courseid - Course ID of current course
16852:
16853: $rolecode - User's current role in course (for switchserver query string).
16854:
16855: $required - LON-CAPA version needed by course (format: Major.Minor).
16856:
16857:
16858: Returns:
16859:
16860: $switchserver - query string tp append to /adm/switchserver call (if
16861: current server's LON-CAPA version is too old.
16862:
16863: $warning - Message is displayed if no suitable server could be found.
16864:
16865: =cut
16866:
16867: sub check_release_required {
16868: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16869: my ($switchserver,$warning);
16870: if ($required ne '') {
16871: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16872: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16873: if ($reqdmajor ne '' && $reqdminor ne '') {
16874: my $otherserver;
16875: if (($major eq '' && $minor eq '') ||
16876: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16877: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16878: my $switchlcrev =
16879: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16880: $userdomserver);
16881: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16882: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16883: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16884: my $cdom = $env{'course.'.$courseid.'.domain'};
16885: if ($cdom ne $env{'user.domain'}) {
16886: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16887: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16888: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16889: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16890: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16891: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16892: my $canhost =
16893: &Apache::lonnet::can_host_session($env{'user.domain'},
16894: $coursedomserver,
16895: $remoterev,
16896: $udomdefaults{'remotesessions'},
16897: $defdomdefaults{'hostedsessions'});
16898:
16899: if ($canhost) {
16900: $otherserver = $coursedomserver;
16901: } else {
16902: $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.");
16903: }
16904: } else {
16905: $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).");
16906: }
16907: } else {
16908: $otherserver = $userdomserver;
16909: }
16910: }
16911: if ($otherserver ne '') {
16912: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16913: }
16914: }
16915: }
16916: return ($switchserver,$warning);
16917: }
16918:
16919: =pod
16920:
16921: =item * &check_release_result()
16922:
16923: Inputs:
16924:
16925: $switchwarning - Warning message if no suitable server found to host session.
16926:
16927: $switchserver - query string to append to /adm/switchserver containing lonHostID
16928: and current role.
16929:
16930: Returns: HTML to display with information about requirement to switch server.
16931: Either displaying warning with link to Roles/Courses screen or
16932: display link to switchserver.
16933:
1.1075.2.69 raeburn 16934: =cut
16935:
1.1075.2.88 raeburn 16936: sub check_release_result {
16937: my ($switchwarning,$switchserver) = @_;
16938: my $output = &start_page('Selected course unavailable on this server').
16939: '<p class="LC_warning">';
16940: if ($switchwarning) {
16941: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16942: if (&show_course()) {
16943: $output .= &mt('Display courses');
16944: } else {
16945: $output .= &mt('Display roles');
16946: }
16947: $output .= '</a>';
16948: } elsif ($switchserver) {
16949: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16950: '<br />'.
16951: '<a href="/adm/switchserver?'.$switchserver.'">'.
16952: &mt('Switch Server').
16953: '</a>';
16954: }
16955: $output .= '</p>'.&end_page();
16956: return $output;
16957: }
16958:
16959: =pod
16960:
16961: =item * &needs_coursereinit()
16962:
16963: Determine if course contents stored for user's session needs to be
16964: refreshed, because content has changed since "Big Hash" last tied.
16965:
16966: Check for change is made if time last checked is more than 10 minutes ago
16967: (by default).
16968:
16969: Inputs:
16970:
16971: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16972:
16973: $interval (optional) - Time which may elapse (in s) between last check for content
16974: change in current course. (default: 600 s).
16975:
16976: Returns: an array; first element is:
16977:
16978: =over 4
16979:
16980: 'switch' - if content updates mean user's session
16981: needs to be switched to a server running a newer LON-CAPA version
16982:
16983: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16984: on current server hosting user's session
16985:
16986: '' - if no action required.
16987:
16988: =back
16989:
16990: If first item element is 'switch':
16991:
16992: second item is $switchwarning - Warning message if no suitable server found to host session.
16993:
16994: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16995: and current role.
16996:
16997: otherwise: no other elements returned.
16998:
16999: =back
17000:
17001: =cut
17002:
17003: sub needs_coursereinit {
17004: my ($loncaparev,$interval) = @_;
17005: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17006: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17007: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17008: my $now = time;
17009: if ($interval eq '') {
17010: $interval = 600;
17011: }
17012: if (($now-$env{'request.course.timechecked'})>$interval) {
17013: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17014: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
17015: if ($lastchange > $env{'request.course.tied'}) {
17016: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17017: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17018: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17019: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17020: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17021: $curr_reqd_hash{'internal.releaserequired'}});
17022: my ($switchserver,$switchwarning) =
17023: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17024: $curr_reqd_hash{'internal.releaserequired'});
17025: if ($switchwarning ne '' || $switchserver ne '') {
17026: return ('switch',$switchwarning,$switchserver);
17027: }
17028: }
17029: }
17030: return ('update');
17031: }
17032: }
17033: return ();
17034: }
1.1075.2.69 raeburn 17035:
1.1075.2.11 raeburn 17036: sub update_content_constraints {
17037: my ($cdom,$cnum,$chome,$cid) = @_;
17038: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17039: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
17040: my %checkresponsetypes;
17041: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
17042: my ($item,$name,$value) = split(/:/,$key);
17043: if ($item eq 'resourcetag') {
17044: if ($name eq 'responsetype') {
17045: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17046: }
17047: }
17048: }
17049: my $navmap = Apache::lonnavmaps::navmap->new();
17050: if (defined($navmap)) {
17051: my %allresponses;
17052: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17053: my %responses = $res->responseTypes();
17054: foreach my $key (keys(%responses)) {
17055: next unless(exists($checkresponsetypes{$key}));
17056: $allresponses{$key} += $responses{$key};
17057: }
17058: }
17059: foreach my $key (keys(%allresponses)) {
17060: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17061: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17062: ($reqdmajor,$reqdminor) = ($major,$minor);
17063: }
17064: }
17065: undef($navmap);
17066: }
17067: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17068: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17069: }
17070: return;
17071: }
17072:
1.1075.2.27 raeburn 17073: sub allmaps_incourse {
17074: my ($cdom,$cnum,$chome,$cid) = @_;
17075: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17076: $cid = $env{'request.course.id'};
17077: $cdom = $env{'course.'.$cid.'.domain'};
17078: $cnum = $env{'course.'.$cid.'.num'};
17079: $chome = $env{'course.'.$cid.'.home'};
17080: }
17081: my %allmaps = ();
17082: my $lastchange =
17083: &Apache::lonnet::get_coursechange($cdom,$cnum);
17084: if ($lastchange > $env{'request.course.tied'}) {
17085: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17086: unless ($ferr) {
17087: &update_content_constraints($cdom,$cnum,$chome,$cid);
17088: }
17089: }
17090: my $navmap = Apache::lonnavmaps::navmap->new();
17091: if (defined($navmap)) {
17092: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17093: $allmaps{$res->src()} = 1;
17094: }
17095: }
17096: return \%allmaps;
17097: }
17098:
1.1075.2.11 raeburn 17099: sub parse_supplemental_title {
17100: my ($title) = @_;
17101:
17102: my ($foldertitle,$renametitle);
17103: if ($title =~ /&&&/) {
17104: $title = &HTML::Entites::decode($title);
17105: }
17106: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17107: $renametitle=$4;
17108: my ($time,$uname,$udom) = ($1,$2,$3);
17109: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17110: my $name = &plainname($uname,$udom);
17111: $name = &HTML::Entities::encode($name,'"<>&\'');
17112: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17113: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17114: $name.': <br />'.$foldertitle;
17115: }
17116: if (wantarray) {
17117: return ($title,$foldertitle,$renametitle);
17118: }
17119: return $title;
17120: }
17121:
1.1075.2.43 raeburn 17122: sub recurse_supplemental {
17123: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
17124: if ($suppmap) {
17125: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17126: if ($fatal) {
17127: $errors ++;
17128: } else {
17129: if ($#LONCAPA::map::resources > 0) {
17130: foreach my $res (@LONCAPA::map::resources) {
17131: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17132: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 17133: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
17134: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 17135: } else {
17136: $numfiles ++;
17137: }
17138: }
17139: }
17140: }
17141: }
17142: }
17143: return ($numfiles,$errors);
17144: }
17145:
1.1075.2.18 raeburn 17146: sub symb_to_docspath {
1.1075.2.119 raeburn 17147: my ($symb,$navmapref) = @_;
17148: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 17149: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17150: if ($resurl=~/\.(sequence|page)$/) {
17151: $mapurl=$resurl;
17152: } elsif ($resurl eq 'adm/navmaps') {
17153: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17154: }
17155: my $mapresobj;
1.1075.2.119 raeburn 17156: unless (ref($$navmapref)) {
17157: $$navmapref = Apache::lonnavmaps::navmap->new();
17158: }
17159: if (ref($$navmapref)) {
17160: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 17161: }
17162: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17163: my $type=$2;
17164: my $path;
17165: if (ref($mapresobj)) {
17166: my $pcslist = $mapresobj->map_hierarchy();
17167: if ($pcslist ne '') {
17168: foreach my $pc (split(/,/,$pcslist)) {
17169: next if ($pc <= 1);
1.1075.2.119 raeburn 17170: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 17171: if (ref($res)) {
17172: my $thisurl = $res->src();
17173: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17174: my $thistitle = $res->title();
17175: $path .= '&'.
17176: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 17177: &escape($thistitle).
1.1075.2.18 raeburn 17178: ':'.$res->randompick().
17179: ':'.$res->randomout().
17180: ':'.$res->encrypted().
17181: ':'.$res->randomorder().
17182: ':'.$res->is_page();
17183: }
17184: }
17185: }
17186: $path =~ s/^\&//;
17187: my $maptitle = $mapresobj->title();
17188: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17189: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17190: }
17191: $path .= (($path ne '')? '&' : '').
17192: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17193: &escape($maptitle).
1.1075.2.18 raeburn 17194: ':'.$mapresobj->randompick().
17195: ':'.$mapresobj->randomout().
17196: ':'.$mapresobj->encrypted().
17197: ':'.$mapresobj->randomorder().
17198: ':'.$mapresobj->is_page();
17199: } else {
17200: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17201: my $ispage = (($type eq 'page')? 1 : '');
17202: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17203: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17204: }
17205: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17206: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 17207: }
17208: unless ($mapurl eq 'default') {
17209: $path = 'default&'.
1.1075.2.46 raeburn 17210: &escape('Main Content').
1.1075.2.18 raeburn 17211: ':::::&'.$path;
17212: }
17213: return $path;
17214: }
17215:
1.1075.2.14 raeburn 17216: sub captcha_display {
1.1075.2.137 raeburn 17217: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17218: my ($output,$error);
1.1075.2.107 raeburn 17219: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 17220: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17221: if ($captcha eq 'original') {
17222: $output = &create_captcha();
17223: unless ($output) {
17224: $error = 'captcha';
17225: }
17226: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17227: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 17228: unless ($output) {
17229: $error = 'recaptcha';
17230: }
17231: }
1.1075.2.107 raeburn 17232: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 17233: }
17234:
17235: sub captcha_response {
1.1075.2.137 raeburn 17236: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17237: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 17238: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17239: if ($captcha eq 'original') {
17240: ($captcha_chk,$captcha_error) = &check_captcha();
17241: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17242: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 17243: } else {
17244: $captcha_chk = 1;
17245: }
17246: return ($captcha_chk,$captcha_error);
17247: }
17248:
17249: sub get_captcha_config {
1.1075.2.137 raeburn 17250: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 17251: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 17252: my $hostname = &Apache::lonnet::hostname($lonhost);
17253: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17254: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17255: if ($context eq 'usercreation') {
17256: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17257: if (ref($domconfig{$context}) eq 'HASH') {
17258: $hashtocheck = $domconfig{$context}{'cancreate'};
17259: if (ref($hashtocheck) eq 'HASH') {
17260: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17261: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17262: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17263: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17264: }
17265: if ($privkey && $pubkey) {
17266: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17267: $version = $hashtocheck->{'recaptchaversion'};
17268: if ($version ne '2') {
17269: $version = 1;
17270: }
1.1075.2.14 raeburn 17271: } else {
17272: $captcha = 'original';
17273: }
17274: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17275: $captcha = 'original';
17276: }
17277: }
17278: } else {
17279: $captcha = 'captcha';
17280: }
17281: } elsif ($context eq 'login') {
17282: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17283: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17284: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17285: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
17286: if ($privkey && $pubkey) {
17287: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17288: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17289: if ($version ne '2') {
17290: $version = 1;
17291: }
1.1075.2.14 raeburn 17292: } else {
17293: $captcha = 'original';
17294: }
17295: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17296: $captcha = 'original';
17297: }
1.1075.2.137 raeburn 17298: } elsif ($context eq 'passwords') {
17299: if ($dom_in_effect) {
17300: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17301: if ($passwdconf{'captcha'} eq 'recaptcha') {
17302: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17303: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17304: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17305: }
17306: if ($privkey && $pubkey) {
17307: $captcha = 'recaptcha';
17308: $version = $passwdconf{'recaptchaversion'};
17309: if ($version ne '2') {
17310: $version = 1;
17311: }
17312: } else {
17313: $captcha = 'original';
17314: }
17315: } elsif ($passwdconf{'captcha'} ne 'notused') {
17316: $captcha = 'original';
17317: }
17318: }
1.1075.2.14 raeburn 17319: }
1.1075.2.107 raeburn 17320: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 17321: }
17322:
17323: sub create_captcha {
17324: my %captcha_params = &captcha_settings();
17325: my ($output,$maxtries,$tries) = ('',10,0);
17326: while ($tries < $maxtries) {
17327: $tries ++;
17328: my $captcha = Authen::Captcha->new (
17329: output_folder => $captcha_params{'output_dir'},
17330: data_folder => $captcha_params{'db_dir'},
17331: );
17332: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17333:
17334: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17335: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1075.2.158 raeburn 17336: '<span class="LC_nobreak">'.
1.1075.2.14 raeburn 17337: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 17338: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
1.1075.2.158 raeburn 17339: '</span><br />'.
1.1075.2.66 raeburn 17340: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 17341: last;
17342: }
17343: }
1.1075.2.158 raeburn 17344: if ($output eq '') {
17345: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
17346: }
1.1075.2.14 raeburn 17347: return $output;
17348: }
17349:
17350: sub captcha_settings {
17351: my %captcha_params = (
17352: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17353: www_output_dir => "/captchaspool",
17354: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17355: numchars => '5',
17356: );
17357: return %captcha_params;
17358: }
17359:
17360: sub check_captcha {
17361: my ($captcha_chk,$captcha_error);
17362: my $code = $env{'form.code'};
17363: my $md5sum = $env{'form.crypt'};
17364: my %captcha_params = &captcha_settings();
17365: my $captcha = Authen::Captcha->new(
17366: output_folder => $captcha_params{'output_dir'},
17367: data_folder => $captcha_params{'db_dir'},
17368: );
1.1075.2.26 raeburn 17369: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 17370: my %captcha_hash = (
17371: 0 => 'Code not checked (file error)',
17372: -1 => 'Failed: code expired',
17373: -2 => 'Failed: invalid code (not in database)',
17374: -3 => 'Failed: invalid code (code does not match crypt)',
17375: );
17376: if ($captcha_chk != 1) {
17377: $captcha_error = $captcha_hash{$captcha_chk}
17378: }
17379: return ($captcha_chk,$captcha_error);
17380: }
17381:
17382: sub create_recaptcha {
1.1075.2.107 raeburn 17383: my ($pubkey,$version) = @_;
17384: if ($version >= 2) {
1.1075.2.158 raeburn 17385: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
17386: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1075.2.107 raeburn 17387: } else {
17388: my $use_ssl;
17389: if ($ENV{'SERVER_PORT'} == 443) {
17390: $use_ssl = 1;
17391: }
17392: my $captcha = Captcha::reCAPTCHA->new;
17393: return $captcha->get_options_setter({theme => 'white'})."\n".
17394: $captcha->get_html($pubkey,undef,$use_ssl).
17395: &mt('If the text is hard to read, [_1] will replace them.',
17396: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17397: '<br /><br />';
17398: }
1.1075.2.14 raeburn 17399: }
17400:
17401: sub check_recaptcha {
1.1075.2.107 raeburn 17402: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 17403: my $captcha_chk;
1.1075.2.150 raeburn 17404: my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 17405: if ($version >= 2) {
17406: my $ua = LWP::UserAgent->new;
17407: $ua->timeout(10);
17408: my %info = (
17409: secret => $privkey,
17410: response => $env{'form.g-recaptcha-response'},
1.1075.2.150 raeburn 17411: remoteip => $ip,
1.1075.2.107 raeburn 17412: );
17413: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17414: if ($response->is_success) {
17415: my $data = JSON::DWIW->from_json($response->decoded_content);
17416: if (ref($data) eq 'HASH') {
17417: if ($data->{'success'}) {
17418: $captcha_chk = 1;
17419: }
17420: }
17421: }
17422: } else {
17423: my $captcha = Captcha::reCAPTCHA->new;
17424: my $captcha_result =
17425: $captcha->check_answer(
17426: $privkey,
1.1075.2.150 raeburn 17427: $ip,
1.1075.2.107 raeburn 17428: $env{'form.recaptcha_challenge_field'},
17429: $env{'form.recaptcha_response_field'},
17430: );
17431: if ($captcha_result->{is_valid}) {
17432: $captcha_chk = 1;
17433: }
1.1075.2.14 raeburn 17434: }
17435: return $captcha_chk;
17436: }
17437:
1.1075.2.64 raeburn 17438: sub emailusername_info {
1.1075.2.103 raeburn 17439: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 17440: my %titles = &Apache::lonlocal::texthash (
17441: lastname => 'Last Name',
17442: firstname => 'First Name',
17443: institution => 'School/college/university',
17444: location => "School's city, state/province, country",
17445: web => "School's web address",
17446: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 17447: id => 'Student/Employee ID',
1.1075.2.64 raeburn 17448: );
17449: return (\@fields,\%titles);
17450: }
17451:
1.1075.2.56 raeburn 17452: sub cleanup_html {
17453: my ($incoming) = @_;
17454: my $outgoing;
17455: if ($incoming ne '') {
17456: $outgoing = $incoming;
17457: $outgoing =~ s/;/;/g;
17458: $outgoing =~ s/\#/#/g;
17459: $outgoing =~ s/\&/&/g;
17460: $outgoing =~ s/</</g;
17461: $outgoing =~ s/>/>/g;
17462: $outgoing =~ s/\(/(/g;
17463: $outgoing =~ s/\)/)/g;
17464: $outgoing =~ s/"/"/g;
17465: $outgoing =~ s/'/'/g;
17466: $outgoing =~ s/\$/$/g;
17467: $outgoing =~ s{/}{/}g;
17468: $outgoing =~ s/=/=/g;
17469: $outgoing =~ s/\\/\/g
17470: }
17471: return $outgoing;
17472: }
17473:
1.1075.2.74 raeburn 17474: # Checks for critical messages and returns a redirect url if one exists.
17475: # $interval indicates how often to check for messages.
17476: sub critical_redirect {
17477: my ($interval) = @_;
1.1075.2.158 raeburn 17478: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
17479: return ();
17480: }
1.1075.2.74 raeburn 17481: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17482: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17483: $env{'user.name'});
17484: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17485: my $redirecturl;
17486: if ($what[0]) {
1.1075.2.158 raeburn 17487: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1075.2.74 raeburn 17488: $redirecturl='/adm/email?critical=display';
17489: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17490: return (1, $url);
17491: }
17492: }
17493: }
17494: return ();
17495: }
17496:
1.1075.2.64 raeburn 17497: # Use:
17498: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17499: #
17500: ##################################################
17501: # password associated functions #
17502: ##################################################
17503: sub des_keys {
17504: # Make a new key for DES encryption.
17505: # Each key has two parts which are returned separately.
17506: # Please note: Each key must be passed through the &hex function
17507: # before it is output to the web browser. The hex versions cannot
17508: # be used to decrypt.
17509: my @hexstr=('0','1','2','3','4','5','6','7',
17510: '8','9','a','b','c','d','e','f');
17511: my $lkey='';
17512: for (0..7) {
17513: $lkey.=$hexstr[rand(15)];
17514: }
17515: my $ukey='';
17516: for (0..7) {
17517: $ukey.=$hexstr[rand(15)];
17518: }
17519: return ($lkey,$ukey);
17520: }
17521:
17522: sub des_decrypt {
17523: my ($key,$cyphertext) = @_;
17524: my $keybin=pack("H16",$key);
17525: my $cypher;
17526: if ($Crypt::DES::VERSION>=2.03) {
17527: $cypher=new Crypt::DES $keybin;
17528: } else {
17529: $cypher=new DES $keybin;
17530: }
1.1075.2.106 raeburn 17531: my $plaintext='';
17532: my $cypherlength = length($cyphertext);
17533: my $numchunks = int($cypherlength/32);
17534: for (my $j=0; $j<$numchunks; $j++) {
17535: my $start = $j*32;
17536: my $cypherblock = substr($cyphertext,$start,32);
17537: my $chunk =
17538: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17539: $chunk .=
17540: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17541: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17542: $plaintext .= $chunk;
17543: }
1.1075.2.64 raeburn 17544: return $plaintext;
17545: }
17546:
1.1075.2.135 raeburn 17547: sub is_nonframeable {
17548: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
17549: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
17550: return if (($remprotocol eq '') || ($remhost eq ''));
17551:
17552: $remprotocol = lc($remprotocol);
17553: $remhost = lc($remhost);
17554: my $remport = 80;
17555: if ($remprotocol eq 'https') {
17556: $remport = 443;
17557: }
17558: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
17559: if ($cached) {
17560: unless ($nocache) {
17561: if ($result) {
17562: return 1;
17563: } else {
17564: return 0;
17565: }
17566: }
17567: }
17568: my $uselink;
17569: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 17570: my $ua = LWP::UserAgent->new;
17571: $ua->timeout(5);
17572: my $response=$ua->request($request);
1.1075.2.135 raeburn 17573: if ($response->is_success()) {
17574: my $secpolicy = lc($response->header('content-security-policy'));
17575: my $xframeop = lc($response->header('x-frame-options'));
17576: $secpolicy =~ s/^\s+|\s+$//g;
17577: $xframeop =~ s/^\s+|\s+$//g;
17578: if (($secpolicy ne '') || ($xframeop ne '')) {
17579: my $remotehost = $remprotocol.'://'.$remhost;
17580: my ($origin,$protocol,$port);
17581: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17582: $port = $ENV{'SERVER_PORT'};
17583: } else {
17584: $port = 80;
17585: }
17586: if ($absolute eq '') {
17587: $protocol = 'http:';
17588: if ($port == 443) {
17589: $protocol = 'https:';
17590: }
17591: $origin = $protocol.'//'.lc($hostname);
17592: } else {
17593: $origin = lc($absolute);
17594: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17595: }
17596: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17597: my $framepolicy = $1;
17598: $framepolicy =~ s/^\s+|\s+$//g;
17599: my @policies = split(/\s+/,$framepolicy);
17600: if (@policies) {
17601: if (grep(/^\Q'none'\E$/,@policies)) {
17602: $uselink = 1;
17603: } else {
17604: $uselink = 1;
17605: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17606: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17607: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17608: undef($uselink);
17609: }
17610: if ($uselink) {
17611: if (grep(/^\Q'self'\E$/,@policies)) {
17612: if (($origin ne '') && ($remotehost eq $origin)) {
17613: undef($uselink);
17614: }
17615: }
17616: }
17617: if ($uselink) {
17618: my @possok;
17619: if ($ip ne '') {
17620: push(@possok,$ip);
17621: }
17622: my $hoststr = '';
17623: foreach my $part (reverse(split(/\./,$hostname))) {
17624: if ($hoststr eq '') {
17625: $hoststr = $part;
17626: } else {
17627: $hoststr = "$part.$hoststr";
17628: }
17629: if ($hoststr eq $hostname) {
17630: push(@possok,$hostname);
17631: } else {
17632: push(@possok,"*.$hoststr");
17633: }
17634: }
17635: if (@possok) {
17636: foreach my $poss (@possok) {
17637: last if (!$uselink);
17638: foreach my $policy (@policies) {
17639: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17640: undef($uselink);
17641: last;
17642: }
17643: }
17644: }
17645: }
17646: }
17647: }
17648: }
17649: } elsif ($xframeop ne '') {
17650: $uselink = 1;
17651: my @policies = split(/\s*,\s*/,$xframeop);
17652: if (@policies) {
17653: unless (grep(/^deny$/,@policies)) {
17654: if ($origin ne '') {
17655: if (grep(/^sameorigin$/,@policies)) {
17656: if ($remotehost eq $origin) {
17657: undef($uselink);
17658: }
17659: }
17660: if ($uselink) {
17661: foreach my $policy (@policies) {
17662: if ($policy =~ /^allow-from\s*(.+)$/) {
17663: my $allowfrom = $1;
17664: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17665: undef($uselink);
17666: last;
17667: }
17668: }
17669: }
17670: }
17671: }
17672: }
17673: }
17674: }
17675: }
17676: }
17677: if ($nocache) {
17678: if ($cached) {
17679: my $devalidate;
17680: if ($uselink && !$result) {
17681: $devalidate = 1;
17682: } elsif (!$uselink && $result) {
17683: $devalidate = 1;
17684: }
17685: if ($devalidate) {
17686: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17687: }
17688: }
17689: } else {
17690: if ($uselink) {
17691: $result = 1;
17692: } else {
17693: $result = 0;
17694: }
17695: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17696: }
17697: return $uselink;
17698: }
17699:
1.112 bowersj2 17700: 1;
17701: __END__;
1.41 ng 17702:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>