Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.165
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.165! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.164 2022/01/23 00:53:02 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.352 albertel 8053: domain -> force to color decorate a page for a specific
8054: domain
8055: function -> force usage of a specific rolish color scheme
8056: bgcolor -> override the default page bgcolor
1.460 albertel 8057: no_auto_mt_title
8058: -> prevent &mt()ing the title arg
1.464 albertel 8059:
1.306 albertel 8060: =cut
8061:
8062: sub headtag {
1.313 albertel 8063: my ($title,$head_extra,$args) = @_;
1.306 albertel 8064:
1.363 albertel 8065: my $function = $args->{'function'} || &get_users_function();
8066: my $domain = $args->{'domain'} || &determinedomain();
8067: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 8068: my $httphost = $args->{'use_absolute'};
1.418 albertel 8069: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8070: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8071: #time(),
1.418 albertel 8072: $env{'environment.color.timestamp'},
1.363 albertel 8073: $function,$domain,$bgcolor);
8074:
1.369 www 8075: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8076:
1.308 albertel 8077: my $result =
8078: '<head>'.
1.1075.2.56 raeburn 8079: &font_settings($args);
1.319 albertel 8080:
1.1075.2.72 raeburn 8081: my $inhibitprint;
8082: if ($args->{'print_suppress'}) {
8083: $inhibitprint = &print_suppression();
8084: }
1.1064 raeburn 8085:
1.461 albertel 8086: if (!$args->{'frameset'}) {
8087: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8088: }
1.1075.2.12 raeburn 8089: if ($args->{'force_register'}) {
8090: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 8091: }
1.436 albertel 8092: if (!$args->{'no_nav_bar'}
8093: && !$args->{'only_body'}
8094: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 8095: $result .= &help_menu_js($httphost);
1.1032 www 8096: $result.=&modal_window();
1.1038 www 8097: $result.=&togglebox_script();
1.1034 www 8098: $result.=&wishlist_window();
1.1041 www 8099: $result.=&LCprogressbarUpdate_script();
1.1034 www 8100: } else {
8101: if ($args->{'add_modal'}) {
8102: $result.=&modal_window();
8103: }
8104: if ($args->{'add_wishlist'}) {
8105: $result.=&wishlist_window();
8106: }
1.1038 www 8107: if ($args->{'add_togglebox'}) {
8108: $result.=&togglebox_script();
8109: }
1.1041 www 8110: if ($args->{'add_progressbar'}) {
8111: $result.=&LCprogressbarUpdate_script();
8112: }
1.436 albertel 8113: }
1.314 albertel 8114: if (ref($args->{'redirect'})) {
1.414 albertel 8115: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8116: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8117: if (!$inhibit_continue) {
8118: $env{'internal.head.redirect'} = $url;
8119: }
1.313 albertel 8120: $result.=<<ADDMETA
8121: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8122: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8123: ADDMETA
1.1075.2.89 raeburn 8124: } else {
8125: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8126: my $requrl = $env{'request.uri'};
8127: if ($requrl eq '') {
8128: $requrl = $ENV{'REQUEST_URI'};
8129: $requrl =~ s/\?.+$//;
8130: }
8131: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8132: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8133: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8134: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8135: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8136: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 8137: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1075.2.151 raeburn 8138: my ($offload,$offloadoth);
1.1075.2.89 raeburn 8139: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8140: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 8141: $offload = 1;
1.1075.2.151 raeburn 8142: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8143: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8144: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8145: $offloadoth = 1;
8146: $dom_in_use = $env{'user.domain'};
8147: }
8148: }
1.1075.2.145 raeburn 8149: }
8150: }
8151: unless ($offload) {
8152: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8153: if ($domdefs{'offloadoth'}{$lonhost}) {
8154: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8155: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8156: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8157: $offload = 1;
1.1075.2.151 raeburn 8158: $offloadoth = 1;
1.1075.2.145 raeburn 8159: $dom_in_use = $env{'user.domain'};
8160: }
1.1075.2.89 raeburn 8161: }
1.1075.2.145 raeburn 8162: }
8163: }
8164: }
8165: if ($offload) {
1.1075.2.158 raeburn 8166: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1075.2.151 raeburn 8167: if (($newserver eq '') && ($offloadoth)) {
8168: my @domains = &Apache::lonnet::current_machine_domains();
8169: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
8170: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8171: }
8172: }
1.1075.2.145 raeburn 8173: if (($newserver) && ($newserver ne $lonhost)) {
8174: my $numsec = 5;
8175: my $timeout = $numsec * 1000;
8176: my ($newurl,$locknum,%locks,$msg);
8177: if ($env{'request.role.adv'}) {
8178: ($locknum,%locks) = &Apache::lonnet::get_locks();
8179: }
8180: my $disable_submit = 0;
8181: if ($requrl =~ /$LONCAPA::assess_re/) {
8182: $disable_submit = 1;
8183: }
8184: if ($locknum) {
8185: my @lockinfo = sort(values(%locks));
1.1075.2.153 raeburn 8186: $msg = &mt('Once the following tasks are complete:')." \n".
1.1075.2.145 raeburn 8187: join(", ",sort(values(%locks)))."\n";
8188: if (&show_course()) {
8189: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 8190: } else {
1.1075.2.145 raeburn 8191: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
8192: }
8193: } else {
8194: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8195: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8196: }
8197: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8198: $newurl = '/adm/switchserver?otherserver='.$newserver;
8199: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8200: $newurl .= '&role='.$env{'request.role'};
8201: }
8202: if ($env{'request.symb'}) {
8203: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8204: if ($shownsymb =~ m{^/enc/}) {
8205: my $reqdmajor = 2;
8206: my $reqdminor = 11;
8207: my $reqdsubminor = 3;
8208: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8209: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8210: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8211: if (($major eq '' && $minor eq '') ||
8212: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8213: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8214: ($reqdsubminor > $subminor))))) {
8215: undef($shownsymb);
8216: }
1.1075.2.89 raeburn 8217: }
1.1075.2.145 raeburn 8218: if ($shownsymb) {
8219: &js_escape(\$shownsymb);
8220: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 8221: }
1.1075.2.145 raeburn 8222: } else {
8223: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8224: &js_escape(\$shownurl);
8225: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 8226: }
1.1075.2.145 raeburn 8227: }
8228: &js_escape(\$msg);
8229: $result.=<<OFFLOAD
1.1075.2.89 raeburn 8230: <meta http-equiv="pragma" content="no-cache" />
8231: <script type="text/javascript">
1.1075.2.92 raeburn 8232: // <![CDATA[
1.1075.2.89 raeburn 8233: function LC_Offload_Now() {
8234: var dest = "$newurl";
8235: if (dest != '') {
8236: window.location.href="$newurl";
8237: }
8238: }
1.1075.2.92 raeburn 8239: \$(document).ready(function () {
8240: window.alert('$msg');
8241: if ($disable_submit) {
1.1075.2.89 raeburn 8242: \$(".LC_hwk_submit").prop("disabled", true);
8243: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 8244: }
8245: setTimeout('LC_Offload_Now()', $timeout);
8246: });
8247: // ]]>
1.1075.2.89 raeburn 8248: </script>
8249: OFFLOAD
8250: }
8251: }
8252: }
8253: }
8254: }
1.313 albertel 8255: }
1.306 albertel 8256: if (!defined($title)) {
8257: $title = 'The LearningOnline Network with CAPA';
8258: }
1.460 albertel 8259: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8260: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 8261: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8262: if (!$args->{'frameset'}) {
8263: $result .= ' /';
8264: }
8265: $result .= '>'
1.1064 raeburn 8266: .$inhibitprint
1.414 albertel 8267: .$head_extra;
1.1075.2.108 raeburn 8268: my $clientmobile;
8269: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8270: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8271: } else {
8272: $clientmobile = $env{'browser.mobile'};
8273: }
8274: if ($clientmobile) {
1.1075.2.42 raeburn 8275: $result .= '
8276: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8277: <meta name="apple-mobile-web-app-capable" content="yes" />';
8278: }
1.1075.2.126 raeburn 8279: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8280: return $result.'</head>';
1.306 albertel 8281: }
8282:
8283: =pod
8284:
1.340 albertel 8285: =item * &font_settings()
8286:
8287: Returns neccessary <meta> to set the proper encoding
8288:
1.1075.2.56 raeburn 8289: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8290:
8291: =cut
8292:
8293: sub font_settings {
1.1075.2.56 raeburn 8294: my ($args) = @_;
1.340 albertel 8295: my $headerstring='';
1.1075.2.56 raeburn 8296: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8297: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8298: $headerstring.=
1.1075.2.61 raeburn 8299: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8300: if (!$args->{'frameset'}) {
8301: $headerstring.= ' /';
8302: }
8303: $headerstring .= '>'."\n";
1.340 albertel 8304: }
8305: return $headerstring;
8306: }
8307:
1.341 albertel 8308: =pod
8309:
1.1064 raeburn 8310: =item * &print_suppression()
8311:
8312: In course context returns css which causes the body to be blank when media="print",
8313: if printout generation is unavailable for the current resource.
8314:
8315: This could be because:
8316:
8317: (a) printstartdate is in the future
8318:
8319: (b) printenddate is in the past
8320:
8321: (c) there is an active exam block with "printout"
8322: functionality blocked
8323:
8324: Users with pav, pfo or evb privileges are exempt.
8325:
8326: Inputs: none
8327:
8328: =cut
8329:
8330:
8331: sub print_suppression {
8332: my $noprint;
8333: if ($env{'request.course.id'}) {
8334: my $scope = $env{'request.course.id'};
8335: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8336: (&Apache::lonnet::allowed('pfo',$scope))) {
8337: return;
8338: }
8339: if ($env{'request.course.sec'} ne '') {
8340: $scope .= "/$env{'request.course.sec'}";
8341: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8342: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8343: return;
1.1064 raeburn 8344: }
8345: }
8346: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8347: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.158 raeburn 8348: my $clientip = &Apache::lonnet::get_requestor_ip();
8349: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 8350: if ($blocked) {
8351: my $checkrole = "cm./$cdom/$cnum";
8352: if ($env{'request.course.sec'} ne '') {
8353: $checkrole .= "/$env{'request.course.sec'}";
8354: }
8355: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8356: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8357: $noprint = 1;
8358: }
8359: }
8360: unless ($noprint) {
8361: my $symb = &Apache::lonnet::symbread();
8362: if ($symb ne '') {
8363: my $navmap = Apache::lonnavmaps::navmap->new();
8364: if (ref($navmap)) {
8365: my $res = $navmap->getBySymb($symb);
8366: if (ref($res)) {
8367: if (!$res->resprintable()) {
8368: $noprint = 1;
8369: }
8370: }
8371: }
8372: }
8373: }
8374: if ($noprint) {
8375: return <<"ENDSTYLE";
8376: <style type="text/css" media="print">
8377: body { display:none }
8378: </style>
8379: ENDSTYLE
8380: }
8381: }
8382: return;
8383: }
8384:
8385: =pod
8386:
1.341 albertel 8387: =item * &xml_begin()
8388:
8389: Returns the needed doctype and <html>
8390:
8391: Inputs: none
8392:
8393: =cut
8394:
8395: sub xml_begin {
1.1075.2.61 raeburn 8396: my ($is_frameset) = @_;
1.341 albertel 8397: my $output='';
8398:
8399: if ($env{'browser.mathml'}) {
8400: $output='<?xml version="1.0"?>'
8401: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8402: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8403:
8404: # .'<!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">] >'
8405: .'<!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">'
8406: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8407: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8408: } elsif ($is_frameset) {
8409: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8410: '<html>'."\n";
1.341 albertel 8411: } else {
1.1075.2.61 raeburn 8412: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8413: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8414: }
8415: return $output;
8416: }
1.340 albertel 8417:
8418: =pod
8419:
1.306 albertel 8420: =item * &start_page()
8421:
8422: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8423:
1.648 raeburn 8424: Inputs:
8425:
8426: =over 4
8427:
8428: $title - optional title for the page
8429:
8430: $head_extra - optional extra HTML to incude inside the <head>
8431:
8432: $args - additional optional args supported are:
8433:
8434: =over 8
8435:
8436: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8437: arg on
1.814 bisitz 8438: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8439: add_entries -> additional attributes to add to the <body>
8440: domain -> force to color decorate a page for a
1.317 albertel 8441: specific domain
1.648 raeburn 8442: function -> force usage of a specific rolish color
1.317 albertel 8443: scheme
1.648 raeburn 8444: redirect -> see &headtag()
8445: bgcolor -> override the default page bg color
8446: js_ready -> return a string ready for being used in
1.317 albertel 8447: a javascript writeln
1.648 raeburn 8448: html_encode -> return a string ready for being used in
1.320 albertel 8449: a html attribute
1.648 raeburn 8450: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8451: $forcereg arg
1.648 raeburn 8452: frameset -> if true will start with a <frameset>
1.330 albertel 8453: rather than <body>
1.648 raeburn 8454: skip_phases -> hash ref of
1.338 albertel 8455: head -> skip the <html><head> generation
8456: body -> skip all <body> generation
1.1075.2.12 raeburn 8457: no_inline_link -> if true and in remote mode, don't show the
8458: 'Switch To Inline Menu' link
1.648 raeburn 8459: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8460: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8461: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8462: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8463: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8464: group -> includes the current group, if page is for a
8465: specific group
1.1075.2.133 raeburn 8466: use_absolute -> for request for external resource or syllabus, this
8467: will contain https://<hostname> if server uses
8468: https (as per hosts.tab), but request is for http
8469: hostname -> hostname, originally from $r->hostname(), (optional).
1.1075.2.158 raeburn 8470: links_disabled -> Links in primary and secondary menus are disabled
8471: (Can enable them once page has loaded - see lonroles.pm
8472: for an example).
1.361 albertel 8473:
1.648 raeburn 8474: =back
1.460 albertel 8475:
1.648 raeburn 8476: =back
1.562 albertel 8477:
1.306 albertel 8478: =cut
8479:
8480: sub start_page {
1.309 albertel 8481: my ($title,$head_extra,$args) = @_;
1.318 albertel 8482: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8483:
1.315 albertel 8484: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8485: my ($result,@advtools);
1.964 droeschl 8486:
1.338 albertel 8487: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8488: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8489: }
8490:
8491: if (! exists($args->{'skip_phases'}{'body'}) ) {
8492: if ($args->{'frameset'}) {
8493: my $attr_string = &make_attr_string($args->{'force_register'},
8494: $args->{'add_entries'});
8495: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8496: } else {
8497: $result .=
8498: &bodytag($title,
8499: $args->{'function'}, $args->{'add_entries'},
8500: $args->{'only_body'}, $args->{'domain'},
8501: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8502: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8503: $args, \@advtools);
1.831 bisitz 8504: }
1.330 albertel 8505: }
1.338 albertel 8506:
1.315 albertel 8507: if ($args->{'js_ready'}) {
1.713 kaisler 8508: $result = &js_ready($result);
1.315 albertel 8509: }
1.320 albertel 8510: if ($args->{'html_encode'}) {
1.713 kaisler 8511: $result = &html_encode($result);
8512: }
8513:
1.813 bisitz 8514: # Preparation for new and consistent functionlist at top of screen
8515: # if ($args->{'functionlist'}) {
8516: # $result .= &build_functionlist();
8517: #}
8518:
1.964 droeschl 8519: # Don't add anything more if only_body wanted or in const space
8520: return $result if $args->{'only_body'}
8521: || $env{'request.state'} eq 'construct';
1.813 bisitz 8522:
8523: #Breadcrumbs
1.758 kaisler 8524: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8525: &Apache::lonhtmlcommon::clear_breadcrumbs();
8526: #if any br links exists, add them to the breadcrumbs
8527: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8528: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8529: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8530: }
8531: }
1.1075.2.19 raeburn 8532: # if @advtools array contains items add then to the breadcrumbs
8533: if (@advtools > 0) {
8534: &Apache::lonmenu::advtools_crumbs(@advtools);
8535: }
1.1075.2.123 raeburn 8536: my $menulink;
8537: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8538: if (exists($args->{'bread_crumbs_nomenu'})) {
8539: $menulink = 0;
8540: } else {
8541: undef($menulink);
8542: }
1.758 kaisler 8543: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8544: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8545: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8546: }else{
1.1075.2.123 raeburn 8547: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8548: }
1.1075.2.24 raeburn 8549: } elsif (($env{'environment.remote'} eq 'on') &&
8550: ($env{'form.inhibitmenu'} ne 'yes') &&
8551: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8552: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8553: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8554: }
1.315 albertel 8555: return $result;
1.306 albertel 8556: }
8557:
8558: sub end_page {
1.315 albertel 8559: my ($args) = @_;
8560: $env{'internal.end_page'}++;
1.330 albertel 8561: my $result;
1.335 albertel 8562: if ($args->{'discussion'}) {
8563: my ($target,$parser);
8564: if (ref($args->{'discussion'})) {
8565: ($target,$parser) =($args->{'discussion'}{'target'},
8566: $args->{'discussion'}{'parser'});
8567: }
8568: $result .= &Apache::lonxml::xmlend($target,$parser);
8569: }
1.330 albertel 8570: if ($args->{'frameset'}) {
8571: $result .= '</frameset>';
8572: } else {
1.635 raeburn 8573: $result .= &endbodytag($args);
1.330 albertel 8574: }
1.1075.2.6 raeburn 8575: unless ($args->{'notbody'}) {
8576: $result .= "\n</html>";
8577: }
1.330 albertel 8578:
1.315 albertel 8579: if ($args->{'js_ready'}) {
1.317 albertel 8580: $result = &js_ready($result);
1.315 albertel 8581: }
1.335 albertel 8582:
1.320 albertel 8583: if ($args->{'html_encode'}) {
8584: $result = &html_encode($result);
8585: }
1.335 albertel 8586:
1.315 albertel 8587: return $result;
8588: }
8589:
1.1034 www 8590: sub wishlist_window {
8591: return(<<'ENDWISHLIST');
1.1046 raeburn 8592: <script type="text/javascript">
1.1034 www 8593: // <![CDATA[
8594: // <!-- BEGIN LON-CAPA Internal
8595: function set_wishlistlink(title, path) {
8596: if (!title) {
8597: title = document.title;
8598: title = title.replace(/^LON-CAPA /,'');
8599: }
1.1075.2.65 raeburn 8600: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8601: title = title.replace("'","\\\'");
1.1034 www 8602: if (!path) {
8603: path = location.pathname;
8604: }
1.1075.2.65 raeburn 8605: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8606: path = path.replace("'","\\\'");
1.1034 www 8607: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8608: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8609: }
8610: // END LON-CAPA Internal -->
8611: // ]]>
8612: </script>
8613: ENDWISHLIST
8614: }
8615:
1.1030 www 8616: sub modal_window {
8617: return(<<'ENDMODAL');
1.1046 raeburn 8618: <script type="text/javascript">
1.1030 www 8619: // <![CDATA[
8620: // <!-- BEGIN LON-CAPA Internal
8621: var modalWindow = {
8622: parent:"body",
8623: windowId:null,
8624: content:null,
8625: width:null,
8626: height:null,
8627: close:function()
8628: {
8629: $(".LCmodal-window").remove();
8630: $(".LCmodal-overlay").remove();
8631: },
8632: open:function()
8633: {
8634: var modal = "";
8635: modal += "<div class=\"LCmodal-overlay\"></div>";
8636: 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;\">";
8637: modal += this.content;
8638: modal += "</div>";
8639:
8640: $(this.parent).append(modal);
8641:
8642: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8643: $(".LCclose-window").click(function(){modalWindow.close();});
8644: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8645: }
8646: };
1.1075.2.42 raeburn 8647: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8648: {
1.1075.2.119 raeburn 8649: source = source.replace(/'/g,"'");
1.1030 www 8650: modalWindow.windowId = "myModal";
8651: modalWindow.width = width;
8652: modalWindow.height = height;
1.1075.2.80 raeburn 8653: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8654: modalWindow.open();
1.1075.2.87 raeburn 8655: };
1.1030 www 8656: // END LON-CAPA Internal -->
8657: // ]]>
8658: </script>
8659: ENDMODAL
8660: }
8661:
8662: sub modal_link {
1.1075.2.42 raeburn 8663: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8664: unless ($width) { $width=480; }
8665: unless ($height) { $height=400; }
1.1031 www 8666: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8667: unless ($transparency) { $transparency='true'; }
8668:
1.1074 raeburn 8669: my $target_attr;
8670: if (defined($target)) {
8671: $target_attr = 'target="'.$target.'"';
8672: }
8673: return <<"ENDLINK";
1.1075.2.143 raeburn 8674: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 8675: ENDLINK
1.1030 www 8676: }
8677:
1.1032 www 8678: sub modal_adhoc_script {
1.1075.2.155 raeburn 8679: my ($funcname,$width,$height,$content,$possmathjax)=@_;
8680: my $mathjax;
8681: if ($possmathjax) {
8682: $mathjax = <<'ENDJAX';
8683: if (typeof MathJax == 'object') {
8684: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
8685: }
8686: ENDJAX
8687: }
1.1032 www 8688: return (<<ENDADHOC);
1.1046 raeburn 8689: <script type="text/javascript">
1.1032 www 8690: // <![CDATA[
8691: var $funcname = function()
8692: {
8693: modalWindow.windowId = "myModal";
8694: modalWindow.width = $width;
8695: modalWindow.height = $height;
8696: modalWindow.content = '$content';
8697: modalWindow.open();
1.1075.2.155 raeburn 8698: $mathjax
1.1032 www 8699: };
8700: // ]]>
8701: </script>
8702: ENDADHOC
8703: }
8704:
1.1041 www 8705: sub modal_adhoc_inner {
1.1075.2.155 raeburn 8706: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 8707: my $innerwidth=$width-20;
8708: $content=&js_ready(
1.1042 www 8709: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8710: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8711: $content.
1.1041 www 8712: &end_scrollbox().
1.1075.2.42 raeburn 8713: &end_page()
1.1041 www 8714: );
1.1075.2.155 raeburn 8715: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 8716: }
8717:
8718: sub modal_adhoc_window {
1.1075.2.155 raeburn 8719: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
8720: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 8721: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8722: }
8723:
8724: sub modal_adhoc_launch {
8725: my ($funcname,$width,$height,$content)=@_;
8726: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8727: <script type="text/javascript">
8728: // <![CDATA[
8729: $funcname();
8730: // ]]>
8731: </script>
8732: ENDLAUNCH
8733: }
8734:
8735: sub modal_adhoc_close {
8736: return (<<ENDCLOSE);
8737: <script type="text/javascript">
8738: // <![CDATA[
8739: modalWindow.close();
8740: // ]]>
8741: </script>
8742: ENDCLOSE
8743: }
8744:
1.1038 www 8745: sub togglebox_script {
8746: return(<<ENDTOGGLE);
8747: <script type="text/javascript">
8748: // <![CDATA[
8749: function LCtoggleDisplay(id,hidetext,showtext) {
8750: link = document.getElementById(id + "link").childNodes[0];
8751: with (document.getElementById(id).style) {
8752: if (display == "none" ) {
8753: display = "inline";
8754: link.nodeValue = hidetext;
8755: } else {
8756: display = "none";
8757: link.nodeValue = showtext;
8758: }
8759: }
8760: }
8761: // ]]>
8762: </script>
8763: ENDTOGGLE
8764: }
8765:
1.1039 www 8766: sub start_togglebox {
8767: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8768: unless ($heading) { $heading=''; } else { $heading.=' '; }
8769: unless ($showtext) { $showtext=&mt('show'); }
8770: unless ($hidetext) { $hidetext=&mt('hide'); }
8771: unless ($headerbg) { $headerbg='#FFFFFF'; }
8772: return &start_data_table().
8773: &start_data_table_header_row().
8774: '<td bgcolor="'.$headerbg.'">'.$heading.
8775: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8776: $showtext.'\')">'.$showtext.'</a>]</td>'.
8777: &end_data_table_header_row().
8778: '<tr id="'.$id.'" style="display:none""><td>';
8779: }
8780:
8781: sub end_togglebox {
8782: return '</td></tr>'.&end_data_table();
8783: }
8784:
1.1041 www 8785: sub LCprogressbar_script {
1.1075.2.130 raeburn 8786: my ($id,$number_to_do)=@_;
8787: if ($number_to_do) {
8788: return(<<ENDPROGRESS);
1.1041 www 8789: <script type="text/javascript">
8790: // <![CDATA[
1.1045 www 8791: \$('#progressbar$id').progressbar({
1.1041 www 8792: value: 0,
8793: change: function(event, ui) {
8794: var newVal = \$(this).progressbar('option', 'value');
8795: \$('.pblabel', this).text(LCprogressTxt);
8796: }
8797: });
8798: // ]]>
8799: </script>
8800: ENDPROGRESS
1.1075.2.130 raeburn 8801: } else {
8802: return(<<ENDPROGRESS);
8803: <script type="text/javascript">
8804: // <![CDATA[
8805: \$('#progressbar$id').progressbar({
8806: value: false,
8807: create: function(event, ui) {
8808: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8809: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8810: }
8811: });
8812: // ]]>
8813: </script>
8814: ENDPROGRESS
8815: }
1.1041 www 8816: }
8817:
8818: sub LCprogressbarUpdate_script {
8819: return(<<ENDPROGRESSUPDATE);
8820: <style type="text/css">
8821: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8822: .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 8823: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8824: </style>
8825: <script type="text/javascript">
8826: // <![CDATA[
1.1045 www 8827: var LCprogressTxt='---';
8828:
1.1075.2.130 raeburn 8829: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8830: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8831: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8832: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8833: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8834: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8835: } else {
8836: \$('#progressbar'+id).progressbar('value',percent);
8837: }
1.1041 www 8838: }
8839: // ]]>
8840: </script>
8841: ENDPROGRESSUPDATE
8842: }
8843:
1.1042 www 8844: my $LClastpercent;
1.1045 www 8845: my $LCidcnt;
8846: my $LCcurrentid;
1.1042 www 8847:
1.1041 www 8848: sub LCprogressbar {
1.1075.2.130 raeburn 8849: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8850: $LClastpercent=0;
1.1045 www 8851: $LCidcnt++;
8852: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8853: my ($starting,$content);
8854: if ($number_to_do) {
8855: $starting=&mt('Starting');
8856: $content=(<<ENDPROGBAR);
8857: $preamble
1.1045 www 8858: <div id="progressbar$LCcurrentid">
1.1041 www 8859: <span class="pblabel">$starting</span>
8860: </div>
8861: ENDPROGBAR
1.1075.2.130 raeburn 8862: } else {
8863: $starting=&mt('Loading...');
8864: $LClastpercent='false';
8865: $content=(<<ENDPROGBAR);
8866: $preamble
8867: <div id="progressbar$LCcurrentid">
8868: <div class="progress-label">$starting</div>
8869: </div>
8870: ENDPROGBAR
8871: }
8872: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8873: }
8874:
8875: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8876: my ($r,$val,$text,$number_to_do)=@_;
8877: if ($number_to_do) {
8878: unless ($val) {
8879: if ($LClastpercent) {
8880: $val=$LClastpercent;
8881: } else {
8882: $val=0;
8883: }
8884: }
8885: if ($val<0) { $val=0; }
8886: if ($val>100) { $val=0; }
8887: $LClastpercent=$val;
8888: unless ($text) { $text=$val.'%'; }
8889: } else {
8890: $val = 'false';
1.1042 www 8891: }
1.1041 www 8892: $text=&js_ready($text);
1.1044 www 8893: &r_print($r,<<ENDUPDATE);
1.1041 www 8894: <script type="text/javascript">
8895: // <![CDATA[
1.1075.2.130 raeburn 8896: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8897: // ]]>
8898: </script>
8899: ENDUPDATE
1.1035 www 8900: }
8901:
1.1042 www 8902: sub LCprogressbarClose {
8903: my ($r)=@_;
8904: $LClastpercent=0;
1.1044 www 8905: &r_print($r,<<ENDCLOSE);
1.1042 www 8906: <script type="text/javascript">
8907: // <![CDATA[
1.1045 www 8908: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8909: // ]]>
8910: </script>
8911: ENDCLOSE
1.1044 www 8912: }
8913:
8914: sub r_print {
8915: my ($r,$to_print)=@_;
8916: if ($r) {
8917: $r->print($to_print);
8918: $r->rflush();
8919: } else {
8920: print($to_print);
8921: }
1.1042 www 8922: }
8923:
1.320 albertel 8924: sub html_encode {
8925: my ($result) = @_;
8926:
1.322 albertel 8927: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8928:
8929: return $result;
8930: }
1.1044 www 8931:
1.317 albertel 8932: sub js_ready {
8933: my ($result) = @_;
8934:
1.323 albertel 8935: $result =~ s/[\n\r]/ /xmsg;
8936: $result =~ s/\\/\\\\/xmsg;
8937: $result =~ s/'/\\'/xmsg;
1.372 albertel 8938: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8939:
8940: return $result;
8941: }
8942:
1.315 albertel 8943: sub validate_page {
8944: if ( exists($env{'internal.start_page'})
1.316 albertel 8945: && $env{'internal.start_page'} > 1) {
8946: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8947: $env{'internal.start_page'}.' '.
1.316 albertel 8948: $ENV{'request.filename'});
1.315 albertel 8949: }
8950: if ( exists($env{'internal.end_page'})
1.316 albertel 8951: && $env{'internal.end_page'} > 1) {
8952: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8953: $env{'internal.end_page'}.' '.
1.316 albertel 8954: $env{'request.filename'});
1.315 albertel 8955: }
8956: if ( exists($env{'internal.start_page'})
8957: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8958: &Apache::lonnet::logthis('start_page called without end_page '.
8959: $env{'request.filename'});
1.315 albertel 8960: }
8961: if ( ! exists($env{'internal.start_page'})
8962: && exists($env{'internal.end_page'})) {
1.316 albertel 8963: &Apache::lonnet::logthis('end_page called without start_page'.
8964: $env{'request.filename'});
1.315 albertel 8965: }
1.306 albertel 8966: }
1.315 albertel 8967:
1.996 www 8968:
8969: sub start_scrollbox {
1.1075.2.56 raeburn 8970: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8971: unless ($outerwidth) { $outerwidth='520px'; }
8972: unless ($width) { $width='500px'; }
8973: unless ($height) { $height='200px'; }
1.1075 raeburn 8974: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8975: if ($id ne '') {
1.1075.2.42 raeburn 8976: $table_id = ' id="table_'.$id.'"';
8977: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8978: }
1.1075 raeburn 8979: if ($bgcolor ne '') {
8980: $tdcol = "background-color: $bgcolor;";
8981: }
1.1075.2.42 raeburn 8982: my $nicescroll_js;
8983: if ($env{'browser.mobile'}) {
8984: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8985: }
1.1075 raeburn 8986: return <<"END";
1.1075.2.42 raeburn 8987: $nicescroll_js
8988:
8989: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8990: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8991: END
1.996 www 8992: }
8993:
8994: sub end_scrollbox {
1.1036 www 8995: return '</div></td></tr></table>';
1.996 www 8996: }
8997:
1.1075.2.42 raeburn 8998: sub nicescroll_javascript {
8999: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9000: my %options;
9001: if (ref($cursor) eq 'HASH') {
9002: %options = %{$cursor};
9003: }
9004: unless ($options{'railalign'} =~ /^left|right$/) {
9005: $options{'railalign'} = 'left';
9006: }
9007: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9008: my $function = &get_users_function();
9009: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
9010: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9011: $options{'cursorcolor'} = '#00F';
9012: }
9013: }
9014: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9015: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
9016: $options{'cursoropacity'}='1.0';
9017: }
9018: } else {
9019: $options{'cursoropacity'}='1.0';
9020: }
9021: if ($options{'cursorfixedheight'} eq 'none') {
9022: delete($options{'cursorfixedheight'});
9023: } else {
9024: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9025: }
9026: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9027: delete($options{'railoffset'});
9028: }
9029: my @niceoptions;
9030: while (my($key,$value) = each(%options)) {
9031: if ($value =~ /^\{.+\}$/) {
9032: push(@niceoptions,$key.':'.$value);
9033: } else {
9034: push(@niceoptions,$key.':"'.$value.'"');
9035: }
9036: }
9037: my $nicescroll_js = '
9038: $(document).ready(
9039: function() {
9040: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9041: }
9042: );
9043: ';
9044: if ($framecheck) {
9045: $nicescroll_js .= '
9046: function expand_div(caller) {
9047: if (top === self) {
9048: document.getElementById("'.$id.'").style.width = "auto";
9049: document.getElementById("'.$id.'").style.height = "auto";
9050: } else {
9051: try {
9052: if (parent.frames) {
9053: if (parent.frames.length > 1) {
9054: var framesrc = parent.frames[1].location.href;
9055: var currsrc = framesrc.replace(/\#.*$/,"");
9056: if ((caller == "search") || (currsrc == "'.$location.'")) {
9057: document.getElementById("'.$id.'").style.width = "auto";
9058: document.getElementById("'.$id.'").style.height = "auto";
9059: }
9060: }
9061: }
9062: } catch (e) {
9063: return;
9064: }
9065: }
9066: return;
9067: }
9068: ';
9069: }
9070: if ($needjsready) {
9071: $nicescroll_js = '
9072: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9073: } else {
9074: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9075: }
9076: return $nicescroll_js;
9077: }
9078:
1.318 albertel 9079: sub simple_error_page {
1.1075.2.49 raeburn 9080: my ($r,$title,$msg,$args) = @_;
9081: if (ref($args) eq 'HASH') {
9082: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9083: } else {
9084: $msg = &mt($msg);
9085: }
9086:
1.318 albertel 9087: my $page =
9088: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 9089: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9090: &Apache::loncommon::end_page();
9091: if (ref($r)) {
9092: $r->print($page);
1.327 albertel 9093: return;
1.318 albertel 9094: }
9095: return $page;
9096: }
1.347 albertel 9097:
9098: {
1.610 albertel 9099: my @row_count;
1.961 onken 9100:
9101: sub start_data_table_count {
9102: unshift(@row_count, 0);
9103: return;
9104: }
9105:
9106: sub end_data_table_count {
9107: shift(@row_count);
9108: return;
9109: }
9110:
1.347 albertel 9111: sub start_data_table {
1.1018 raeburn 9112: my ($add_class,$id) = @_;
1.422 albertel 9113: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9114: my $table_id;
9115: if (defined($id)) {
9116: $table_id = ' id="'.$id.'"';
9117: }
1.961 onken 9118: &start_data_table_count();
1.1018 raeburn 9119: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9120: }
9121:
9122: sub end_data_table {
1.961 onken 9123: &end_data_table_count();
1.389 albertel 9124: return '</table>'."\n";;
1.347 albertel 9125: }
9126:
9127: sub start_data_table_row {
1.974 wenzelju 9128: my ($add_class, $id) = @_;
1.610 albertel 9129: $row_count[0]++;
9130: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9131: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9132: $id = (' id="'.$id.'"') unless ($id eq '');
9133: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9134: }
1.471 banghart 9135:
9136: sub continue_data_table_row {
1.974 wenzelju 9137: my ($add_class, $id) = @_;
1.610 albertel 9138: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9139: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9140: $id = (' id="'.$id.'"') unless ($id eq '');
9141: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9142: }
1.347 albertel 9143:
9144: sub end_data_table_row {
1.389 albertel 9145: return '</tr>'."\n";;
1.347 albertel 9146: }
1.367 www 9147:
1.421 albertel 9148: sub start_data_table_empty_row {
1.707 bisitz 9149: # $row_count[0]++;
1.421 albertel 9150: return '<tr class="LC_empty_row" >'."\n";;
9151: }
9152:
9153: sub end_data_table_empty_row {
9154: return '</tr>'."\n";;
9155: }
9156:
1.367 www 9157: sub start_data_table_header_row {
1.389 albertel 9158: return '<tr class="LC_header_row">'."\n";;
1.367 www 9159: }
9160:
9161: sub end_data_table_header_row {
1.389 albertel 9162: return '</tr>'."\n";;
1.367 www 9163: }
1.890 droeschl 9164:
9165: sub data_table_caption {
9166: my $caption = shift;
9167: return "<caption class=\"LC_caption\">$caption</caption>";
9168: }
1.347 albertel 9169: }
9170:
1.548 albertel 9171: =pod
9172:
9173: =item * &inhibit_menu_check($arg)
9174:
9175: Checks for a inhibitmenu state and generates output to preserve it
9176:
9177: Inputs: $arg - can be any of
9178: - undef - in which case the return value is a string
9179: to add into arguments list of a uri
9180: - 'input' - in which case the return value is a HTML
9181: <form> <input> field of type hidden to
9182: preserve the value
9183: - a url - in which case the return value is the url with
9184: the neccesary cgi args added to preserve the
9185: inhibitmenu state
9186: - a ref to a url - no return value, but the string is
9187: updated to include the neccessary cgi
9188: args to preserve the inhibitmenu state
9189:
9190: =cut
9191:
9192: sub inhibit_menu_check {
9193: my ($arg) = @_;
9194: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9195: if ($arg eq 'input') {
9196: if ($env{'form.inhibitmenu'}) {
9197: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9198: } else {
9199: return
9200: }
9201: }
9202: if ($env{'form.inhibitmenu'}) {
9203: if (ref($arg)) {
9204: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9205: } elsif ($arg eq '') {
9206: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9207: } else {
9208: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9209: }
9210: }
9211: if (!ref($arg)) {
9212: return $arg;
9213: }
9214: }
9215:
1.251 albertel 9216: ###############################################
1.182 matthew 9217:
9218: =pod
9219:
1.549 albertel 9220: =back
9221:
9222: =head1 User Information Routines
9223:
9224: =over 4
9225:
1.405 albertel 9226: =item * &get_users_function()
1.182 matthew 9227:
9228: Used by &bodytag to determine the current users primary role.
9229: Returns either 'student','coordinator','admin', or 'author'.
9230:
9231: =cut
9232:
9233: ###############################################
9234: sub get_users_function {
1.815 tempelho 9235: my $function = 'norole';
1.818 tempelho 9236: if ($env{'request.role'}=~/^(st)/) {
9237: $function='student';
9238: }
1.907 raeburn 9239: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9240: $function='coordinator';
9241: }
1.258 albertel 9242: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9243: $function='admin';
9244: }
1.826 bisitz 9245: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9246: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9247: $function='author';
9248: }
9249: return $function;
1.54 www 9250: }
1.99 www 9251:
9252: ###############################################
9253:
1.233 raeburn 9254: =pod
9255:
1.821 raeburn 9256: =item * &show_course()
9257:
9258: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9259: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9260:
9261: Inputs:
9262: None
9263:
9264: Outputs:
9265: Scalar: 1 if 'Course' to be used, 0 otherwise.
9266:
9267: =cut
9268:
9269: ###############################################
9270: sub show_course {
9271: my $course = !$env{'user.adv'};
9272: if (!$env{'user.adv'}) {
9273: foreach my $env (keys(%env)) {
9274: next if ($env !~ m/^user\.priv\./);
9275: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9276: $course = 0;
9277: last;
9278: }
9279: }
9280: }
9281: return $course;
9282: }
9283:
9284: ###############################################
9285:
9286: =pod
9287:
1.542 raeburn 9288: =item * &check_user_status()
1.274 raeburn 9289:
9290: Determines current status of supplied role for a
9291: specific user. Roles can be active, previous or future.
9292:
9293: Inputs:
9294: user's domain, user's username, course's domain,
1.375 raeburn 9295: course's number, optional section ID.
1.274 raeburn 9296:
9297: Outputs:
9298: role status: active, previous or future.
9299:
9300: =cut
9301:
9302: sub check_user_status {
1.412 raeburn 9303: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9304: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9305: my @uroles = keys(%userinfo);
1.274 raeburn 9306: my $srchstr;
9307: my $active_chk = 'none';
1.412 raeburn 9308: my $now = time;
1.274 raeburn 9309: if (@uroles > 0) {
1.908 raeburn 9310: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9311: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9312: } else {
1.412 raeburn 9313: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9314: }
9315: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9316: my $role_end = 0;
9317: my $role_start = 0;
9318: $active_chk = 'active';
1.412 raeburn 9319: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9320: $role_end = $1;
9321: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9322: $role_start = $1;
1.274 raeburn 9323: }
9324: }
9325: if ($role_start > 0) {
1.412 raeburn 9326: if ($now < $role_start) {
1.274 raeburn 9327: $active_chk = 'future';
9328: }
9329: }
9330: if ($role_end > 0) {
1.412 raeburn 9331: if ($now > $role_end) {
1.274 raeburn 9332: $active_chk = 'previous';
9333: }
9334: }
9335: }
9336: }
9337: return $active_chk;
9338: }
9339:
9340: ###############################################
9341:
9342: =pod
9343:
1.405 albertel 9344: =item * &get_sections()
1.233 raeburn 9345:
9346: Determines all the sections for a course including
9347: sections with students and sections containing other roles.
1.419 raeburn 9348: Incoming parameters:
9349:
9350: 1. domain
9351: 2. course number
9352: 3. reference to array containing roles for which sections should
9353: be gathered (optional).
9354: 4. reference to array containing status types for which sections
9355: should be gathered (optional).
9356:
9357: If the third argument is undefined, sections are gathered for any role.
9358: If the fourth argument is undefined, sections are gathered for any status.
9359: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9360:
1.374 raeburn 9361: Returns section hash (keys are section IDs, values are
9362: number of users in each section), subject to the
1.419 raeburn 9363: optional roles filter, optional status filter
1.233 raeburn 9364:
9365: =cut
9366:
9367: ###############################################
9368: sub get_sections {
1.419 raeburn 9369: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9370: if (!defined($cdom) || !defined($cnum)) {
9371: my $cid = $env{'request.course.id'};
9372:
9373: return if (!defined($cid));
9374:
9375: $cdom = $env{'course.'.$cid.'.domain'};
9376: $cnum = $env{'course.'.$cid.'.num'};
9377: }
9378:
9379: my %sectioncount;
1.419 raeburn 9380: my $now = time;
1.240 albertel 9381:
1.1075.2.33 raeburn 9382: my $check_students = 1;
9383: my $only_students = 0;
9384: if (ref($possible_roles) eq 'ARRAY') {
9385: if (grep(/^st$/,@{$possible_roles})) {
9386: if (@{$possible_roles} == 1) {
9387: $only_students = 1;
9388: }
9389: } else {
9390: $check_students = 0;
9391: }
9392: }
9393:
9394: if ($check_students) {
1.276 albertel 9395: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9396: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9397: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9398: my $start_index = &Apache::loncoursedata::CL_START();
9399: my $end_index = &Apache::loncoursedata::CL_END();
9400: my $status;
1.366 albertel 9401: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9402: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9403: $data->[$status_index],
9404: $data->[$start_index],
9405: $data->[$end_index]);
9406: if ($stu_status eq 'Active') {
9407: $status = 'active';
9408: } elsif ($end < $now) {
9409: $status = 'previous';
9410: } elsif ($start > $now) {
9411: $status = 'future';
9412: }
9413: if ($section ne '-1' && $section !~ /^\s*$/) {
9414: if ((!defined($possible_status)) || (($status ne '') &&
9415: (grep/^\Q$status\E$/,@{$possible_status}))) {
9416: $sectioncount{$section}++;
9417: }
1.240 albertel 9418: }
9419: }
9420: }
1.1075.2.33 raeburn 9421: if ($only_students) {
9422: return %sectioncount;
9423: }
1.240 albertel 9424: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9425: foreach my $user (sort(keys(%courseroles))) {
9426: if ($user !~ /^(\w{2})/) { next; }
9427: my ($role) = ($user =~ /^(\w{2})/);
9428: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9429: my ($section,$status);
1.240 albertel 9430: if ($role eq 'cr' &&
9431: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9432: $section=$1;
9433: }
9434: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9435: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9436: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9437: if ($end == -1 && $start == -1) {
9438: next; #deleted role
9439: }
9440: if (!defined($possible_status)) {
9441: $sectioncount{$section}++;
9442: } else {
9443: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9444: $status = 'active';
9445: } elsif ($end < $now) {
9446: $status = 'future';
9447: } elsif ($start > $now) {
9448: $status = 'previous';
9449: }
9450: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9451: $sectioncount{$section}++;
9452: }
9453: }
1.233 raeburn 9454: }
1.366 albertel 9455: return %sectioncount;
1.233 raeburn 9456: }
9457:
1.274 raeburn 9458: ###############################################
1.294 raeburn 9459:
9460: =pod
1.405 albertel 9461:
9462: =item * &get_course_users()
9463:
1.275 raeburn 9464: Retrieves usernames:domains for users in the specified course
9465: with specific role(s), and access status.
9466:
9467: Incoming parameters:
1.277 albertel 9468: 1. course domain
9469: 2. course number
9470: 3. access status: users must have - either active,
1.275 raeburn 9471: previous, future, or all.
1.277 albertel 9472: 4. reference to array of permissible roles
1.288 raeburn 9473: 5. reference to array of section restrictions (optional)
9474: 6. reference to results object (hash of hashes).
9475: 7. reference to optional userdata hash
1.609 raeburn 9476: 8. reference to optional statushash
1.630 raeburn 9477: 9. flag if privileged users (except those set to unhide in
9478: course settings) should be excluded
1.609 raeburn 9479: Keys of top level results hash are roles.
1.275 raeburn 9480: Keys of inner hashes are username:domain, with
9481: values set to access type.
1.288 raeburn 9482: Optional userdata hash returns an array with arguments in the
9483: same order as loncoursedata::get_classlist() for student data.
9484:
1.609 raeburn 9485: Optional statushash returns
9486:
1.288 raeburn 9487: Entries for end, start, section and status are blank because
9488: of the possibility of multiple values for non-student roles.
9489:
1.275 raeburn 9490: =cut
1.405 albertel 9491:
1.275 raeburn 9492: ###############################################
1.405 albertel 9493:
1.275 raeburn 9494: sub get_course_users {
1.630 raeburn 9495: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9496: my %idx = ();
1.419 raeburn 9497: my %seclists;
1.288 raeburn 9498:
9499: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9500: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9501: $idx{end} = &Apache::loncoursedata::CL_END();
9502: $idx{start} = &Apache::loncoursedata::CL_START();
9503: $idx{id} = &Apache::loncoursedata::CL_ID();
9504: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9505: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9506: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9507:
1.290 albertel 9508: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9509: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9510: my $now = time;
1.277 albertel 9511: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9512: my $match = 0;
1.412 raeburn 9513: my $secmatch = 0;
1.419 raeburn 9514: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9515: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9516: if ($section eq '') {
9517: $section = 'none';
9518: }
1.291 albertel 9519: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9520: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9521: $secmatch = 1;
9522: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9523: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9524: $secmatch = 1;
9525: }
9526: } else {
1.419 raeburn 9527: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9528: $secmatch = 1;
9529: }
1.290 albertel 9530: }
1.412 raeburn 9531: if (!$secmatch) {
9532: next;
9533: }
1.419 raeburn 9534: }
1.275 raeburn 9535: if (defined($$types{'active'})) {
1.288 raeburn 9536: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9537: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9538: $match = 1;
1.275 raeburn 9539: }
9540: }
9541: if (defined($$types{'previous'})) {
1.609 raeburn 9542: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9543: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9544: $match = 1;
1.275 raeburn 9545: }
9546: }
9547: if (defined($$types{'future'})) {
1.609 raeburn 9548: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9549: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9550: $match = 1;
1.275 raeburn 9551: }
9552: }
1.609 raeburn 9553: if ($match) {
9554: push(@{$seclists{$student}},$section);
9555: if (ref($userdata) eq 'HASH') {
9556: $$userdata{$student} = $$classlist{$student};
9557: }
9558: if (ref($statushash) eq 'HASH') {
9559: $statushash->{$student}{'st'}{$section} = $status;
9560: }
1.288 raeburn 9561: }
1.275 raeburn 9562: }
9563: }
1.412 raeburn 9564: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9565: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9566: my $now = time;
1.609 raeburn 9567: my %displaystatus = ( previous => 'Expired',
9568: active => 'Active',
9569: future => 'Future',
9570: );
1.1075.2.36 raeburn 9571: my (%nothide,@possdoms);
1.630 raeburn 9572: if ($hidepriv) {
9573: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9574: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9575: if ($user !~ /:/) {
9576: $nothide{join(':',split(/[\@]/,$user))}=1;
9577: } else {
9578: $nothide{$user} = 1;
9579: }
9580: }
1.1075.2.36 raeburn 9581: my @possdoms = ($cdom);
9582: if ($coursehash{'checkforpriv'}) {
9583: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9584: }
1.630 raeburn 9585: }
1.439 raeburn 9586: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9587: my $match = 0;
1.412 raeburn 9588: my $secmatch = 0;
1.439 raeburn 9589: my $status;
1.412 raeburn 9590: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9591: $user =~ s/:$//;
1.439 raeburn 9592: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9593: if ($end == -1 || $start == -1) {
9594: next;
9595: }
9596: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9597: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9598: my ($uname,$udom) = split(/:/,$user);
9599: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9600: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9601: $secmatch = 1;
9602: } elsif ($usec eq '') {
1.420 albertel 9603: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9604: $secmatch = 1;
9605: }
9606: } else {
9607: if (grep(/^\Q$usec\E$/,@{$sections})) {
9608: $secmatch = 1;
9609: }
9610: }
9611: if (!$secmatch) {
9612: next;
9613: }
1.288 raeburn 9614: }
1.419 raeburn 9615: if ($usec eq '') {
9616: $usec = 'none';
9617: }
1.275 raeburn 9618: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9619: if ($hidepriv) {
1.1075.2.36 raeburn 9620: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9621: (!$nothide{$uname.':'.$udom})) {
9622: next;
9623: }
9624: }
1.503 raeburn 9625: if ($end > 0 && $end < $now) {
1.439 raeburn 9626: $status = 'previous';
9627: } elsif ($start > $now) {
9628: $status = 'future';
9629: } else {
9630: $status = 'active';
9631: }
1.277 albertel 9632: foreach my $type (keys(%{$types})) {
1.275 raeburn 9633: if ($status eq $type) {
1.420 albertel 9634: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9635: push(@{$$users{$role}{$user}},$type);
9636: }
1.288 raeburn 9637: $match = 1;
9638: }
9639: }
1.419 raeburn 9640: if (($match) && (ref($userdata) eq 'HASH')) {
9641: if (!exists($$userdata{$uname.':'.$udom})) {
9642: &get_user_info($udom,$uname,\%idx,$userdata);
9643: }
1.420 albertel 9644: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9645: push(@{$seclists{$uname.':'.$udom}},$usec);
9646: }
1.609 raeburn 9647: if (ref($statushash) eq 'HASH') {
9648: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9649: }
1.275 raeburn 9650: }
9651: }
9652: }
9653: }
1.290 albertel 9654: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9655: if ((defined($cdom)) && (defined($cnum))) {
9656: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9657: if ( defined($csettings{'internal.courseowner'}) ) {
9658: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9659: next if ($owner eq '');
9660: my ($ownername,$ownerdom);
9661: if ($owner =~ /^([^:]+):([^:]+)$/) {
9662: $ownername = $1;
9663: $ownerdom = $2;
9664: } else {
9665: $ownername = $owner;
9666: $ownerdom = $cdom;
9667: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9668: }
9669: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9670: if (defined($userdata) &&
1.609 raeburn 9671: !exists($$userdata{$owner})) {
9672: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9673: if (!grep(/^none$/,@{$seclists{$owner}})) {
9674: push(@{$seclists{$owner}},'none');
9675: }
9676: if (ref($statushash) eq 'HASH') {
9677: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9678: }
1.290 albertel 9679: }
1.279 raeburn 9680: }
9681: }
9682: }
1.419 raeburn 9683: foreach my $user (keys(%seclists)) {
9684: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9685: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9686: }
1.275 raeburn 9687: }
9688: return;
9689: }
9690:
1.288 raeburn 9691: sub get_user_info {
9692: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9693: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9694: &plainname($uname,$udom,'lastname');
1.291 albertel 9695: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9696: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9697: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9698: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9699: return;
9700: }
1.275 raeburn 9701:
1.472 raeburn 9702: ###############################################
9703:
9704: =pod
9705:
9706: =item * &get_user_quota()
9707:
1.1075.2.41 raeburn 9708: Retrieves quota assigned for storage of user files.
9709: Default is to report quota for portfolio files.
1.472 raeburn 9710:
9711: Incoming parameters:
9712: 1. user's username
9713: 2. user's domain
1.1075.2.41 raeburn 9714: 3. quota name - portfolio, author, or course
9715: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9716: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9717: course
1.472 raeburn 9718:
9719: Returns:
1.1075.2.58 raeburn 9720: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9721: 2. (Optional) Type of setting: custom or default
9722: (individually assigned or default for user's
9723: institutional status).
9724: 3. (Optional) - User's institutional status (e.g., faculty, staff
9725: or student - types as defined in localenroll::inst_usertypes
9726: for user's domain, which determines default quota for user.
9727: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9728:
9729: If a value has been stored in the user's environment,
1.536 raeburn 9730: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9731: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9732:
9733: =cut
9734:
9735: ###############################################
9736:
9737:
9738: sub get_user_quota {
1.1075.2.42 raeburn 9739: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9740: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9741: if (!defined($udom)) {
9742: $udom = $env{'user.domain'};
9743: }
9744: if (!defined($uname)) {
9745: $uname = $env{'user.name'};
9746: }
9747: if (($udom eq '' || $uname eq '') ||
9748: ($udom eq 'public') && ($uname eq 'public')) {
9749: $quota = 0;
1.536 raeburn 9750: $quotatype = 'default';
9751: $defquota = 0;
1.472 raeburn 9752: } else {
1.536 raeburn 9753: my $inststatus;
1.1075.2.41 raeburn 9754: if ($quotaname eq 'course') {
9755: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9756: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9757: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9758: } else {
9759: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9760: $quota = $cenv{'internal.uploadquota'};
9761: }
1.536 raeburn 9762: } else {
1.1075.2.41 raeburn 9763: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9764: if ($quotaname eq 'author') {
9765: $quota = $env{'environment.authorquota'};
9766: } else {
9767: $quota = $env{'environment.portfolioquota'};
9768: }
9769: $inststatus = $env{'environment.inststatus'};
9770: } else {
9771: my %userenv =
9772: &Apache::lonnet::get('environment',['portfolioquota',
9773: 'authorquota','inststatus'],$udom,$uname);
9774: my ($tmp) = keys(%userenv);
9775: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9776: if ($quotaname eq 'author') {
9777: $quota = $userenv{'authorquota'};
9778: } else {
9779: $quota = $userenv{'portfolioquota'};
9780: }
9781: $inststatus = $userenv{'inststatus'};
9782: } else {
9783: undef(%userenv);
9784: }
9785: }
9786: }
9787: if ($quota eq '' || wantarray) {
9788: if ($quotaname eq 'course') {
9789: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9790: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9791: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9792: $defquota = $domdefs{$crstype.'quota'};
9793: }
9794: if ($defquota eq '') {
9795: $defquota = 500;
9796: }
1.1075.2.41 raeburn 9797: } else {
9798: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9799: }
9800: if ($quota eq '') {
9801: $quota = $defquota;
9802: $quotatype = 'default';
9803: } else {
9804: $quotatype = 'custom';
9805: }
1.472 raeburn 9806: }
9807: }
1.536 raeburn 9808: if (wantarray) {
9809: return ($quota,$quotatype,$settingstatus,$defquota);
9810: } else {
9811: return $quota;
9812: }
1.472 raeburn 9813: }
9814:
9815: ###############################################
9816:
9817: =pod
9818:
9819: =item * &default_quota()
9820:
1.536 raeburn 9821: Retrieves default quota assigned for storage of user portfolio files,
9822: given an (optional) user's institutional status.
1.472 raeburn 9823:
9824: Incoming parameters:
1.1075.2.42 raeburn 9825:
1.472 raeburn 9826: 1. domain
1.536 raeburn 9827: 2. (Optional) institutional status(es). This is a : separated list of
9828: status types (e.g., faculty, staff, student etc.)
9829: which apply to the user for whom the default is being retrieved.
9830: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9831: default quota will be returned.
9832: 3. quota name - portfolio, author, or course
9833: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9834:
9835: Returns:
1.1075.2.42 raeburn 9836:
1.1075.2.58 raeburn 9837: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9838: 2. (Optional) institutional type which determined the value of the
9839: default quota.
1.472 raeburn 9840:
9841: If a value has been stored in the domain's configuration db,
9842: it will return that, otherwise it returns 20 (for backwards
9843: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9844: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9845:
1.536 raeburn 9846: If the user's status includes multiple types (e.g., staff and student),
9847: the largest default quota which applies to the user determines the
9848: default quota returned.
9849:
1.472 raeburn 9850: =cut
9851:
9852: ###############################################
9853:
9854:
9855: sub default_quota {
1.1075.2.41 raeburn 9856: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9857: my ($defquota,$settingstatus);
9858: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9859: ['quotas'],$udom);
1.1075.2.41 raeburn 9860: my $key = 'defaultquota';
9861: if ($quotaname eq 'author') {
9862: $key = 'authorquota';
9863: }
1.622 raeburn 9864: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9865: if ($inststatus ne '') {
1.765 raeburn 9866: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9867: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9868: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9869: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9870: if ($defquota eq '') {
1.1075.2.41 raeburn 9871: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9872: $settingstatus = $item;
1.1075.2.41 raeburn 9873: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9874: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9875: $settingstatus = $item;
9876: }
9877: }
1.1075.2.41 raeburn 9878: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9879: if ($quotahash{'quotas'}{$item} ne '') {
9880: if ($defquota eq '') {
9881: $defquota = $quotahash{'quotas'}{$item};
9882: $settingstatus = $item;
9883: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9884: $defquota = $quotahash{'quotas'}{$item};
9885: $settingstatus = $item;
9886: }
1.536 raeburn 9887: }
9888: }
9889: }
9890: }
9891: if ($defquota eq '') {
1.1075.2.41 raeburn 9892: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9893: $defquota = $quotahash{'quotas'}{$key}{'default'};
9894: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9895: $defquota = $quotahash{'quotas'}{'default'};
9896: }
1.536 raeburn 9897: $settingstatus = 'default';
1.1075.2.42 raeburn 9898: if ($defquota eq '') {
9899: if ($quotaname eq 'author') {
9900: $defquota = 500;
9901: }
9902: }
1.536 raeburn 9903: }
9904: } else {
9905: $settingstatus = 'default';
1.1075.2.41 raeburn 9906: if ($quotaname eq 'author') {
9907: $defquota = 500;
9908: } else {
9909: $defquota = 20;
9910: }
1.536 raeburn 9911: }
9912: if (wantarray) {
9913: return ($defquota,$settingstatus);
1.472 raeburn 9914: } else {
1.536 raeburn 9915: return $defquota;
1.472 raeburn 9916: }
9917: }
9918:
1.1075.2.41 raeburn 9919: ###############################################
9920:
9921: =pod
9922:
1.1075.2.42 raeburn 9923: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9924:
9925: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9926: of existing file within authoring space will cause quota for the authoring
9927: space to be exceeded.
9928:
9929: Same, if upload of a file directly to a course/community via Course Editor
9930: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9931:
1.1075.2.61 raeburn 9932: Inputs: 7
1.1075.2.42 raeburn 9933: 1. username or coursenum
1.1075.2.41 raeburn 9934: 2. domain
1.1075.2.42 raeburn 9935: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9936: 4. filename of file for which action is being requested
9937: 5. filesize (kB) of file
9938: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9939: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9940:
9941: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9942: otherwise return null.
9943:
1.1075.2.42 raeburn 9944: =back
9945:
1.1075.2.41 raeburn 9946: =cut
9947:
1.1075.2.42 raeburn 9948: sub excess_filesize_warning {
1.1075.2.59 raeburn 9949: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9950: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9951: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9952: if ($context eq 'author') {
9953: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9954: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9955: } else {
9956: foreach my $subdir ('docs','supplemental') {
9957: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9958: }
9959: }
1.1075.2.41 raeburn 9960: $disk_quota = int($disk_quota * 1000);
9961: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9962: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9963: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9964: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9965: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9966: $disk_quota,$current_disk_usage).
9967: '</p>';
9968: }
9969: return;
9970: }
9971:
9972: ###############################################
9973:
9974:
1.384 raeburn 9975: sub get_secgrprole_info {
9976: my ($cdom,$cnum,$needroles,$type) = @_;
9977: my %sections_count = &get_sections($cdom,$cnum);
9978: my @sections = (sort {$a <=> $b} keys(%sections_count));
9979: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9980: my @groups = sort(keys(%curr_groups));
9981: my $allroles = [];
9982: my $rolehash;
9983: my $accesshash = {
9984: active => 'Currently has access',
9985: future => 'Will have future access',
9986: previous => 'Previously had access',
9987: };
9988: if ($needroles) {
9989: $rolehash = {'all' => 'all'};
1.385 albertel 9990: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9991: if (&Apache::lonnet::error(%user_roles)) {
9992: undef(%user_roles);
9993: }
9994: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9995: my ($role)=split(/\:/,$item,2);
9996: if ($role eq 'cr') { next; }
9997: if ($role =~ /^cr/) {
9998: $$rolehash{$role} = (split('/',$role))[3];
9999: } else {
10000: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10001: }
10002: }
10003: foreach my $key (sort(keys(%{$rolehash}))) {
10004: push(@{$allroles},$key);
10005: }
10006: push (@{$allroles},'st');
10007: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10008: }
10009: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10010: }
10011:
1.555 raeburn 10012: sub user_picker {
1.1075.2.127 raeburn 10013: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10014: my $currdom = $dom;
1.1075.2.114 raeburn 10015: my @alldoms = &Apache::lonnet::all_domains();
10016: if (@alldoms == 1) {
10017: my %domsrch = &Apache::lonnet::get_dom('configuration',
10018: ['directorysrch'],$alldoms[0]);
10019: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10020: my $showdom = $domdesc;
10021: if ($showdom eq '') {
10022: $showdom = $dom;
10023: }
10024: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10025: if ((!$domsrch{'directorysrch'}{'available'}) &&
10026: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10027: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10028: }
10029: }
10030: }
1.555 raeburn 10031: my %curr_selected = (
10032: srchin => 'dom',
1.580 raeburn 10033: srchby => 'lastname',
1.555 raeburn 10034: );
10035: my $srchterm;
1.625 raeburn 10036: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10037: if ($srch->{'srchby'} ne '') {
10038: $curr_selected{'srchby'} = $srch->{'srchby'};
10039: }
10040: if ($srch->{'srchin'} ne '') {
10041: $curr_selected{'srchin'} = $srch->{'srchin'};
10042: }
10043: if ($srch->{'srchtype'} ne '') {
10044: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10045: }
10046: if ($srch->{'srchdomain'} ne '') {
10047: $currdom = $srch->{'srchdomain'};
10048: }
10049: $srchterm = $srch->{'srchterm'};
10050: }
1.1075.2.98 raeburn 10051: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10052: 'usr' => 'Search criteria',
1.563 raeburn 10053: 'doma' => 'Domain/institution to search',
1.558 albertel 10054: 'uname' => 'username',
10055: 'lastname' => 'last name',
1.555 raeburn 10056: 'lastfirst' => 'last name, first name',
1.558 albertel 10057: 'crs' => 'in this course',
1.576 raeburn 10058: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10059: 'alc' => 'all LON-CAPA',
1.573 raeburn 10060: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10061: 'exact' => 'is',
10062: 'contains' => 'contains',
1.569 raeburn 10063: 'begins' => 'begins with',
1.1075.2.98 raeburn 10064: );
10065: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10066: 'youm' => "You must include some text to search for.",
10067: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10068: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10069: 'yomc' => "You must choose a domain when using an institutional directory search.",
10070: 'ymcd' => "You must choose a domain when using a domain search.",
10071: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10072: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10073: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10074: );
1.1075.2.98 raeburn 10075: &html_escape(\%html_lt);
10076: &js_escape(\%js_lt);
1.1075.2.115 raeburn 10077: my $domform;
1.1075.2.126 raeburn 10078: my $allow_blank = 1;
1.1075.2.115 raeburn 10079: if ($fixeddom) {
1.1075.2.126 raeburn 10080: $allow_blank = 0;
10081: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 10082: } else {
1.1075.2.126 raeburn 10083: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 10084: }
1.563 raeburn 10085: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10086:
10087: my @srchins = ('crs','dom','alc','instd');
10088:
10089: foreach my $option (@srchins) {
10090: # FIXME 'alc' option unavailable until
10091: # loncreateuser::print_user_query_page()
10092: # has been completed.
10093: next if ($option eq 'alc');
1.880 raeburn 10094: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10095: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 10096: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10097: if ($curr_selected{'srchin'} eq $option) {
10098: $srchinsel .= '
1.1075.2.98 raeburn 10099: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10100: } else {
10101: $srchinsel .= '
1.1075.2.98 raeburn 10102: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10103: }
1.555 raeburn 10104: }
1.563 raeburn 10105: $srchinsel .= "\n </select>\n";
1.555 raeburn 10106:
10107: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10108: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10109: if ($curr_selected{'srchby'} eq $option) {
10110: $srchbysel .= '
1.1075.2.98 raeburn 10111: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10112: } else {
10113: $srchbysel .= '
1.1075.2.98 raeburn 10114: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10115: }
10116: }
10117: $srchbysel .= "\n </select>\n";
10118:
10119: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10120: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10121: if ($curr_selected{'srchtype'} eq $option) {
10122: $srchtypesel .= '
1.1075.2.98 raeburn 10123: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10124: } else {
10125: $srchtypesel .= '
1.1075.2.98 raeburn 10126: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10127: }
10128: }
10129: $srchtypesel .= "\n </select>\n";
10130:
1.558 albertel 10131: my ($newuserscript,$new_user_create);
1.994 raeburn 10132: my $context_dom = $env{'request.role.domain'};
10133: if ($context eq 'requestcrs') {
10134: if ($env{'form.coursedom'} ne '') {
10135: $context_dom = $env{'form.coursedom'};
10136: }
10137: }
1.556 raeburn 10138: if ($forcenewuser) {
1.576 raeburn 10139: if (ref($srch) eq 'HASH') {
1.994 raeburn 10140: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10141: if ($cancreate) {
10142: $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>';
10143: } else {
1.799 bisitz 10144: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10145: my %usertypetext = (
10146: official => 'institutional',
10147: unofficial => 'non-institutional',
10148: );
1.799 bisitz 10149: $new_user_create = '<p class="LC_warning">'
10150: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10151: .' '
10152: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10153: ,'<a href="'.$helplink.'">','</a>')
10154: .'</p><br />';
1.627 raeburn 10155: }
1.576 raeburn 10156: }
10157: }
10158:
1.556 raeburn 10159: $newuserscript = <<"ENDSCRIPT";
10160:
1.570 raeburn 10161: function setSearch(createnew,callingForm) {
1.556 raeburn 10162: if (createnew == 1) {
1.570 raeburn 10163: for (var i=0; i<callingForm.srchby.length; i++) {
10164: if (callingForm.srchby.options[i].value == 'uname') {
10165: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10166: }
10167: }
1.570 raeburn 10168: for (var i=0; i<callingForm.srchin.length; i++) {
10169: if ( callingForm.srchin.options[i].value == 'dom') {
10170: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10171: }
10172: }
1.570 raeburn 10173: for (var i=0; i<callingForm.srchtype.length; i++) {
10174: if (callingForm.srchtype.options[i].value == 'exact') {
10175: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10176: }
10177: }
1.570 raeburn 10178: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10179: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10180: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10181: }
10182: }
10183: }
10184: }
10185: ENDSCRIPT
1.558 albertel 10186:
1.556 raeburn 10187: }
10188:
1.555 raeburn 10189: my $output = <<"END_BLOCK";
1.556 raeburn 10190: <script type="text/javascript">
1.824 bisitz 10191: // <![CDATA[
1.570 raeburn 10192: function validateEntry(callingForm) {
1.558 albertel 10193:
1.556 raeburn 10194: var checkok = 1;
1.558 albertel 10195: var srchin;
1.570 raeburn 10196: for (var i=0; i<callingForm.srchin.length; i++) {
10197: if ( callingForm.srchin[i].checked ) {
10198: srchin = callingForm.srchin[i].value;
1.558 albertel 10199: }
10200: }
10201:
1.570 raeburn 10202: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10203: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10204: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10205: var srchterm = callingForm.srchterm.value;
10206: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10207: var msg = "";
10208:
10209: if (srchterm == "") {
10210: checkok = 0;
1.1075.2.98 raeburn 10211: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10212: }
10213:
1.569 raeburn 10214: if (srchtype== 'begins') {
10215: if (srchterm.length < 2) {
10216: checkok = 0;
1.1075.2.98 raeburn 10217: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10218: }
10219: }
10220:
1.556 raeburn 10221: if (srchtype== 'contains') {
10222: if (srchterm.length < 3) {
10223: checkok = 0;
1.1075.2.98 raeburn 10224: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10225: }
10226: }
10227: if (srchin == 'instd') {
10228: if (srchdomain == '') {
10229: checkok = 0;
1.1075.2.98 raeburn 10230: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10231: }
10232: }
10233: if (srchin == 'dom') {
10234: if (srchdomain == '') {
10235: checkok = 0;
1.1075.2.98 raeburn 10236: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10237: }
10238: }
10239: if (srchby == 'lastfirst') {
10240: if (srchterm.indexOf(",") == -1) {
10241: checkok = 0;
1.1075.2.98 raeburn 10242: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10243: }
10244: if (srchterm.indexOf(",") == srchterm.length -1) {
10245: checkok = 0;
1.1075.2.98 raeburn 10246: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10247: }
10248: }
10249: if (checkok == 0) {
1.1075.2.98 raeburn 10250: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10251: return;
10252: }
10253: if (checkok == 1) {
1.570 raeburn 10254: callingForm.submit();
1.556 raeburn 10255: }
10256: }
10257:
10258: $newuserscript
10259:
1.824 bisitz 10260: // ]]>
1.556 raeburn 10261: </script>
1.558 albertel 10262:
10263: $new_user_create
10264:
1.555 raeburn 10265: END_BLOCK
1.558 albertel 10266:
1.876 raeburn 10267: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 10268: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10269: $domform.
10270: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 10271: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10272: $srchbysel.
10273: $srchtypesel.
10274: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10275: $srchinsel.
10276: &Apache::lonhtmlcommon::row_closure(1).
10277: &Apache::lonhtmlcommon::end_pick_box().
10278: '<br />';
1.1075.2.114 raeburn 10279: return ($output,1);
1.555 raeburn 10280: }
10281:
1.612 raeburn 10282: sub user_rule_check {
1.615 raeburn 10283: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10284: my ($response,%inst_response);
1.612 raeburn 10285: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10286: if (keys(%{$usershash}) > 1) {
10287: my (%by_username,%by_id,%userdoms);
10288: my $checkid;
1.612 raeburn 10289: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10290: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10291: $checkid = 1;
10292: }
10293: }
10294: foreach my $user (keys(%{$usershash})) {
10295: my ($uname,$udom) = split(/:/,$user);
10296: if ($checkid) {
10297: if (ref($usershash->{$user}) eq 'HASH') {
10298: if ($usershash->{$user}->{'id'} ne '') {
10299: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10300: $userdoms{$udom} = 1;
10301: if (ref($inst_results) eq 'HASH') {
10302: $inst_results->{$uname.':'.$udom} = {};
10303: }
10304: }
10305: }
10306: } else {
10307: $by_username{$udom}{$uname} = 1;
10308: $userdoms{$udom} = 1;
10309: if (ref($inst_results) eq 'HASH') {
10310: $inst_results->{$uname.':'.$udom} = {};
10311: }
10312: }
10313: }
10314: foreach my $udom (keys(%userdoms)) {
10315: if (!$got_rules->{$udom}) {
10316: my %domconfig = &Apache::lonnet::get_dom('configuration',
10317: ['usercreation'],$udom);
10318: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10319: foreach my $item ('username','id') {
10320: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10321: $$curr_rules{$udom}{$item} =
10322: $domconfig{'usercreation'}{$item.'_rule'};
10323: }
10324: }
10325: }
10326: $got_rules->{$udom} = 1;
10327: }
10328: }
10329: if ($checkid) {
10330: foreach my $udom (keys(%by_id)) {
10331: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10332: if ($outcome eq 'ok') {
10333: foreach my $id (keys(%{$by_id{$udom}})) {
10334: my $uname = $by_id{$udom}{$id};
10335: $inst_response{$uname.':'.$udom} = $outcome;
10336: }
10337: if (ref($results) eq 'HASH') {
10338: foreach my $uname (keys(%{$results})) {
10339: if (exists($inst_response{$uname.':'.$udom})) {
10340: $inst_response{$uname.':'.$udom} = $outcome;
10341: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10342: }
10343: }
10344: }
10345: }
1.612 raeburn 10346: }
1.615 raeburn 10347: } else {
1.1075.2.99 raeburn 10348: foreach my $udom (keys(%by_username)) {
10349: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10350: if ($outcome eq 'ok') {
10351: foreach my $uname (keys(%{$by_username{$udom}})) {
10352: $inst_response{$uname.':'.$udom} = $outcome;
10353: }
10354: if (ref($results) eq 'HASH') {
10355: foreach my $uname (keys(%{$results})) {
10356: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10357: }
10358: }
10359: }
10360: }
1.612 raeburn 10361: }
1.1075.2.99 raeburn 10362: } elsif (keys(%{$usershash}) == 1) {
10363: my $user = (keys(%{$usershash}))[0];
10364: my ($uname,$udom) = split(/:/,$user);
10365: if (($udom ne '') && ($uname ne '')) {
10366: if (ref($usershash->{$user}) eq 'HASH') {
10367: if (ref($checks) eq 'HASH') {
10368: if (defined($checks->{'username'})) {
10369: ($inst_response{$user},%{$inst_results->{$user}}) =
10370: &Apache::lonnet::get_instuser($udom,$uname);
10371: } elsif (defined($checks->{'id'})) {
10372: if ($usershash->{$user}->{'id'} ne '') {
10373: ($inst_response{$user},%{$inst_results->{$user}}) =
10374: &Apache::lonnet::get_instuser($udom,undef,
10375: $usershash->{$user}->{'id'});
10376: } else {
10377: ($inst_response{$user},%{$inst_results->{$user}}) =
10378: &Apache::lonnet::get_instuser($udom,$uname);
10379: }
10380: }
10381: } else {
10382: ($inst_response{$user},%{$inst_results->{$user}}) =
10383: &Apache::lonnet::get_instuser($udom,$uname);
10384: return;
10385: }
10386: if (!$got_rules->{$udom}) {
10387: my %domconfig = &Apache::lonnet::get_dom('configuration',
10388: ['usercreation'],$udom);
10389: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10390: foreach my $item ('username','id') {
10391: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10392: $$curr_rules{$udom}{$item} =
10393: $domconfig{'usercreation'}{$item.'_rule'};
10394: }
10395: }
1.585 raeburn 10396: }
1.1075.2.99 raeburn 10397: $got_rules->{$udom} = 1;
1.585 raeburn 10398: }
10399: }
1.1075.2.99 raeburn 10400: } else {
10401: return;
10402: }
10403: } else {
10404: return;
10405: }
10406: foreach my $user (keys(%{$usershash})) {
10407: my ($uname,$udom) = split(/:/,$user);
10408: next if (($udom eq '') || ($uname eq ''));
10409: my $id;
10410: if (ref($inst_results) eq 'HASH') {
10411: if (ref($inst_results->{$user}) eq 'HASH') {
10412: $id = $inst_results->{$user}->{'id'};
10413: }
10414: }
10415: if ($id eq '') {
10416: if (ref($usershash->{$user})) {
10417: $id = $usershash->{$user}->{'id'};
10418: }
1.585 raeburn 10419: }
1.612 raeburn 10420: foreach my $item (keys(%{$checks})) {
10421: if (ref($$curr_rules{$udom}) eq 'HASH') {
10422: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10423: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10424: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10425: $$curr_rules{$udom}{$item});
1.612 raeburn 10426: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10427: if ($rule_check{$rule}) {
10428: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10429: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10430: if (ref($inst_results) eq 'HASH') {
10431: if (ref($inst_results->{$user}) eq 'HASH') {
10432: if (keys(%{$inst_results->{$user}}) == 0) {
10433: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10434: } elsif ($item eq 'id') {
10435: if ($inst_results->{$user}->{'id'} eq '') {
10436: $$alerts{$item}{$udom}{$uname} = 1;
10437: }
1.615 raeburn 10438: }
1.612 raeburn 10439: }
10440: }
1.615 raeburn 10441: }
10442: last;
1.585 raeburn 10443: }
10444: }
10445: }
10446: }
10447: }
10448: }
10449: }
10450: }
1.612 raeburn 10451: return;
10452: }
10453:
10454: sub user_rule_formats {
10455: my ($domain,$domdesc,$curr_rules,$check) = @_;
10456: my %text = (
10457: 'username' => 'Usernames',
10458: 'id' => 'IDs',
10459: );
10460: my $output;
10461: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10462: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10463: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10464: $output = '<br />'.
10465: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10466: '<span class="LC_cusr_emph">','</span>',$domdesc).
10467: ' <ul>';
1.612 raeburn 10468: foreach my $rule (@{$ruleorder}) {
10469: if (ref($curr_rules) eq 'ARRAY') {
10470: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10471: if (ref($rules->{$rule}) eq 'HASH') {
10472: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10473: $rules->{$rule}{'desc'}.'</li>';
10474: }
10475: }
10476: }
10477: }
10478: $output .= '</ul>';
10479: }
10480: }
10481: return $output;
10482: }
10483:
10484: sub instrule_disallow_msg {
1.615 raeburn 10485: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10486: my $response;
10487: my %text = (
10488: item => 'username',
10489: items => 'usernames',
10490: match => 'matches',
10491: do => 'does',
10492: action => 'a username',
10493: one => 'one',
10494: );
10495: if ($count > 1) {
10496: $text{'item'} = 'usernames';
10497: $text{'match'} ='match';
10498: $text{'do'} = 'do';
10499: $text{'action'} = 'usernames',
10500: $text{'one'} = 'ones';
10501: }
10502: if ($checkitem eq 'id') {
10503: $text{'items'} = 'IDs';
10504: $text{'item'} = 'ID';
10505: $text{'action'} = 'an ID';
1.615 raeburn 10506: if ($count > 1) {
10507: $text{'item'} = 'IDs';
10508: $text{'action'} = 'IDs';
10509: }
1.612 raeburn 10510: }
1.674 bisitz 10511: $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 10512: if ($mode eq 'upload') {
10513: if ($checkitem eq 'username') {
10514: $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'}.");
10515: } elsif ($checkitem eq 'id') {
1.674 bisitz 10516: $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 10517: }
1.669 raeburn 10518: } elsif ($mode eq 'selfcreate') {
10519: if ($checkitem eq 'id') {
10520: $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.");
10521: }
1.615 raeburn 10522: } else {
10523: if ($checkitem eq 'username') {
10524: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10525: } elsif ($checkitem eq 'id') {
10526: $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.");
10527: }
1.612 raeburn 10528: }
10529: return $response;
1.585 raeburn 10530: }
10531:
1.624 raeburn 10532: sub personal_data_fieldtitles {
10533: my %fieldtitles = &Apache::lonlocal::texthash (
10534: id => 'Student/Employee ID',
10535: permanentemail => 'E-mail address',
10536: lastname => 'Last Name',
10537: firstname => 'First Name',
10538: middlename => 'Middle Name',
10539: generation => 'Generation',
10540: gen => 'Generation',
1.765 raeburn 10541: inststatus => 'Affiliation',
1.624 raeburn 10542: );
10543: return %fieldtitles;
10544: }
10545:
1.642 raeburn 10546: sub sorted_inst_types {
10547: my ($dom) = @_;
1.1075.2.70 raeburn 10548: my ($usertypes,$order);
10549: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10550: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10551: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10552: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10553: } else {
10554: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10555: }
1.642 raeburn 10556: my $othertitle = &mt('All users');
10557: if ($env{'request.course.id'}) {
1.668 raeburn 10558: $othertitle = &mt('Any users');
1.642 raeburn 10559: }
10560: my @types;
10561: if (ref($order) eq 'ARRAY') {
10562: @types = @{$order};
10563: }
10564: if (@types == 0) {
10565: if (ref($usertypes) eq 'HASH') {
10566: @types = sort(keys(%{$usertypes}));
10567: }
10568: }
10569: if (keys(%{$usertypes}) > 0) {
10570: $othertitle = &mt('Other users');
10571: }
10572: return ($othertitle,$usertypes,\@types);
10573: }
10574:
1.645 raeburn 10575: sub get_institutional_codes {
1.1075.2.157 raeburn 10576: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 10577: # Get complete list of course sections to update
10578: my @currsections = ();
10579: my @currxlists = ();
1.1075.2.157 raeburn 10580: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 10581: my $coursecode = $$settings{'internal.coursecode'};
1.1075.2.157 raeburn 10582: my $crskey = $crs.':'.$coursecode;
10583: @{$unclutteredsec{$crskey}} = ();
10584: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 10585:
10586: if ($$settings{'internal.sectionnums'} ne '') {
10587: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10588: }
10589:
10590: if ($$settings{'internal.crosslistings'} ne '') {
10591: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10592: }
10593:
10594: if (@currxlists > 0) {
1.1075.2.157 raeburn 10595: foreach my $xl (@currxlists) {
10596: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 10597: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10598: push(@{$allcourses},$1);
1.645 raeburn 10599: $$LC_code{$1} = $2;
10600: }
10601: }
10602: }
10603: }
1.1075.2.157 raeburn 10604:
1.645 raeburn 10605: if (@currsections > 0) {
1.1075.2.157 raeburn 10606: foreach my $sec (@currsections) {
10607: if ($sec =~ m/^(\w+):(\w*)$/ ) {
10608: my $instsec = $1;
1.645 raeburn 10609: my $lc_sec = $2;
1.1075.2.157 raeburn 10610: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
10611: push(@{$unclutteredsec{$crskey}},$instsec);
10612: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
10613: }
10614: }
10615: }
10616: }
10617:
10618: if (@{$unclutteredsec{$crskey}} > 0) {
10619: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
10620: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
10621: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
10622: my $sec = $coursecode.$formattedsec{$crskey}[$i];
10623: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1075.2.119 raeburn 10624: push(@{$allcourses},$sec);
1.1075.2.157 raeburn 10625: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 10626: }
10627: }
10628: }
10629: }
10630: return;
10631: }
10632:
1.971 raeburn 10633: sub get_standard_codeitems {
10634: return ('Year','Semester','Department','Number','Section');
10635: }
10636:
1.112 bowersj2 10637: =pod
10638:
1.780 raeburn 10639: =head1 Slot Helpers
10640:
10641: =over 4
10642:
10643: =item * sorted_slots()
10644:
1.1040 raeburn 10645: Sorts an array of slot names in order of an optional sort key,
10646: default sort is by slot start time (earliest first).
1.780 raeburn 10647:
10648: Inputs:
10649:
10650: =over 4
10651:
10652: slotsarr - Reference to array of unsorted slot names.
10653:
10654: slots - Reference to hash of hash, where outer hash keys are slot names.
10655:
1.1040 raeburn 10656: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10657:
1.549 albertel 10658: =back
10659:
1.780 raeburn 10660: Returns:
10661:
10662: =over 4
10663:
1.1040 raeburn 10664: sorted - An array of slot names sorted by a specified sort key
10665: (default sort key is start time of the slot).
1.780 raeburn 10666:
10667: =back
10668:
10669: =cut
10670:
10671:
10672: sub sorted_slots {
1.1040 raeburn 10673: my ($slotsarr,$slots,$sortkey) = @_;
10674: if ($sortkey eq '') {
10675: $sortkey = 'starttime';
10676: }
1.780 raeburn 10677: my @sorted;
10678: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10679: @sorted =
10680: sort {
10681: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10682: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10683: }
10684: if (ref($slots->{$a})) { return -1;}
10685: if (ref($slots->{$b})) { return 1;}
10686: return 0;
10687: } @{$slotsarr};
10688: }
10689: return @sorted;
10690: }
10691:
1.1040 raeburn 10692: =pod
10693:
10694: =item * get_future_slots()
10695:
10696: Inputs:
10697:
10698: =over 4
10699:
10700: cnum - course number
10701:
10702: cdom - course domain
10703:
10704: now - current UNIX time
10705:
10706: symb - optional symb
10707:
10708: =back
10709:
10710: Returns:
10711:
10712: =over 4
10713:
10714: sorted_reservable - ref to array of student_schedulable slots currently
10715: reservable, ordered by end date of reservation period.
10716:
10717: reservable_now - ref to hash of student_schedulable slots currently
10718: reservable.
10719:
10720: Keys in inner hash are:
10721: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10722: (b) endreserve: end date of reservation period.
10723: (c) uniqueperiod: start,end dates when slot is to be uniquely
10724: selected.
1.1040 raeburn 10725:
10726: sorted_future - ref to array of student_schedulable slots reservable in
10727: the future, ordered by start date of reservation period.
10728:
10729: future_reservable - ref to hash of student_schedulable slots reservable
10730: in the future.
10731:
10732: Keys in inner hash are:
10733: (a) symb: either blank or symb to which slot use is restricted.
10734: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10735: (c) uniqueperiod: start,end dates when slot is to be uniquely
10736: selected.
1.1040 raeburn 10737:
10738: =back
10739:
10740: =cut
10741:
10742: sub get_future_slots {
10743: my ($cnum,$cdom,$now,$symb) = @_;
10744: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10745: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10746: foreach my $slot (keys(%slots)) {
10747: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10748: if ($symb) {
10749: next if (($slots{$slot}->{'symb'} ne '') &&
10750: ($slots{$slot}->{'symb'} ne $symb));
10751: }
10752: if (($slots{$slot}->{'starttime'} > $now) &&
10753: ($slots{$slot}->{'endtime'} > $now)) {
10754: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10755: my $userallowed = 0;
10756: if ($slots{$slot}->{'allowedsections'}) {
10757: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10758: if (!defined($env{'request.role.sec'})
10759: && grep(/^No section assigned$/,@allowed_sec)) {
10760: $userallowed=1;
10761: } else {
10762: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10763: $userallowed=1;
10764: }
10765: }
10766: unless ($userallowed) {
10767: if (defined($env{'request.course.groups'})) {
10768: my @groups = split(/:/,$env{'request.course.groups'});
10769: foreach my $group (@groups) {
10770: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10771: $userallowed=1;
10772: last;
10773: }
10774: }
10775: }
10776: }
10777: }
10778: if ($slots{$slot}->{'allowedusers'}) {
10779: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10780: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10781: if (grep(/^\Q$user\E$/,@allowed_users)) {
10782: $userallowed = 1;
10783: }
10784: }
10785: next unless($userallowed);
10786: }
10787: my $startreserve = $slots{$slot}->{'startreserve'};
10788: my $endreserve = $slots{$slot}->{'endreserve'};
10789: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10790: my $uniqueperiod;
10791: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10792: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10793: }
1.1040 raeburn 10794: if (($startreserve < $now) &&
10795: (!$endreserve || $endreserve > $now)) {
10796: my $lastres = $endreserve;
10797: if (!$lastres) {
10798: $lastres = $slots{$slot}->{'starttime'};
10799: }
10800: $reservable_now{$slot} = {
10801: symb => $symb,
1.1075.2.104 raeburn 10802: endreserve => $lastres,
10803: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10804: };
10805: } elsif (($startreserve > $now) &&
10806: (!$endreserve || $endreserve > $startreserve)) {
10807: $future_reservable{$slot} = {
10808: symb => $symb,
1.1075.2.104 raeburn 10809: startreserve => $startreserve,
10810: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10811: };
10812: }
10813: }
10814: }
10815: my @unsorted_reservable = keys(%reservable_now);
10816: if (@unsorted_reservable > 0) {
10817: @sorted_reservable =
10818: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10819: }
10820: my @unsorted_future = keys(%future_reservable);
10821: if (@unsorted_future > 0) {
10822: @sorted_future =
10823: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10824: }
10825: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10826: }
1.780 raeburn 10827:
10828: =pod
10829:
1.1057 foxr 10830: =back
10831:
1.549 albertel 10832: =head1 HTTP Helpers
10833:
10834: =over 4
10835:
1.648 raeburn 10836: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10837:
1.258 albertel 10838: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10839: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10840: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10841:
10842: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10843: $possible_names is an ref to an array of form element names. As an example:
10844: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10845: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10846:
10847: =cut
1.1 albertel 10848:
1.6 albertel 10849: sub get_unprocessed_cgi {
1.25 albertel 10850: my ($query,$possible_names)= @_;
1.26 matthew 10851: # $Apache::lonxml::debug=1;
1.356 albertel 10852: foreach my $pair (split(/&/,$query)) {
10853: my ($name, $value) = split(/=/,$pair);
1.369 www 10854: $name = &unescape($name);
1.25 albertel 10855: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10856: $value =~ tr/+/ /;
10857: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10858: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10859: }
1.16 harris41 10860: }
1.6 albertel 10861: }
10862:
1.112 bowersj2 10863: =pod
10864:
1.648 raeburn 10865: =item * &cacheheader()
1.112 bowersj2 10866:
10867: returns cache-controlling header code
10868:
10869: =cut
10870:
1.7 albertel 10871: sub cacheheader {
1.258 albertel 10872: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10873: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10874: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10875: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10876: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10877: return $output;
1.7 albertel 10878: }
10879:
1.112 bowersj2 10880: =pod
10881:
1.648 raeburn 10882: =item * &no_cache($r)
1.112 bowersj2 10883:
10884: specifies header code to not have cache
10885:
10886: =cut
10887:
1.9 albertel 10888: sub no_cache {
1.216 albertel 10889: my ($r) = @_;
10890: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10891: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10892: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10893: $r->no_cache(1);
10894: $r->header_out("Expires" => $date);
10895: $r->header_out("Pragma" => "no-cache");
1.123 www 10896: }
10897:
10898: sub content_type {
1.181 albertel 10899: my ($r,$type,$charset) = @_;
1.299 foxr 10900: if ($r) {
10901: # Note that printout.pl calls this with undef for $r.
10902: &no_cache($r);
10903: }
1.258 albertel 10904: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10905: unless ($charset) {
10906: $charset=&Apache::lonlocal::current_encoding;
10907: }
10908: if ($charset) { $type.='; charset='.$charset; }
10909: if ($r) {
10910: $r->content_type($type);
10911: } else {
10912: print("Content-type: $type\n\n");
10913: }
1.9 albertel 10914: }
1.25 albertel 10915:
1.112 bowersj2 10916: =pod
10917:
1.648 raeburn 10918: =item * &add_to_env($name,$value)
1.112 bowersj2 10919:
1.258 albertel 10920: adds $name to the %env hash with value
1.112 bowersj2 10921: $value, if $name already exists, the entry is converted to an array
10922: reference and $value is added to the array.
10923:
10924: =cut
10925:
1.25 albertel 10926: sub add_to_env {
10927: my ($name,$value)=@_;
1.258 albertel 10928: if (defined($env{$name})) {
10929: if (ref($env{$name})) {
1.25 albertel 10930: #already have multiple values
1.258 albertel 10931: push(@{ $env{$name} },$value);
1.25 albertel 10932: } else {
10933: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10934: my $first=$env{$name};
10935: undef($env{$name});
10936: push(@{ $env{$name} },$first,$value);
1.25 albertel 10937: }
10938: } else {
1.258 albertel 10939: $env{$name}=$value;
1.25 albertel 10940: }
1.31 albertel 10941: }
1.149 albertel 10942:
10943: =pod
10944:
1.648 raeburn 10945: =item * &get_env_multiple($name)
1.149 albertel 10946:
1.258 albertel 10947: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10948: values may be defined and end up as an array ref.
10949:
10950: returns an array of values
10951:
10952: =cut
10953:
10954: sub get_env_multiple {
10955: my ($name) = @_;
10956: my @values;
1.258 albertel 10957: if (defined($env{$name})) {
1.149 albertel 10958: # exists is it an array
1.258 albertel 10959: if (ref($env{$name})) {
10960: @values=@{ $env{$name} };
1.149 albertel 10961: } else {
1.258 albertel 10962: $values[0]=$env{$name};
1.149 albertel 10963: }
10964: }
10965: return(@values);
10966: }
10967:
1.660 raeburn 10968: sub ask_for_embedded_content {
10969: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10970: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10971: %currsubfile,%unused,$rem);
1.1071 raeburn 10972: my $counter = 0;
10973: my $numnew = 0;
1.987 raeburn 10974: my $numremref = 0;
10975: my $numinvalid = 0;
10976: my $numpathchg = 0;
10977: my $numexisting = 0;
1.1071 raeburn 10978: my $numunused = 0;
10979: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10980: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10981: my $heading = &mt('Upload embedded files');
10982: my $buttontext = &mt('Upload');
10983:
1.1075.2.11 raeburn 10984: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10985: if ($actionurl eq '/adm/dependencies') {
10986: $navmap = Apache::lonnavmaps::navmap->new();
10987: }
10988: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10989: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10990: }
1.1075.2.35 raeburn 10991: if (($actionurl eq '/adm/portfolio') ||
10992: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10993: my $current_path='/';
10994: if ($env{'form.currentpath'}) {
10995: $current_path = $env{'form.currentpath'};
10996: }
10997: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10998: $udom = $cdom;
10999: $uname = $cnum;
1.984 raeburn 11000: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11001: } else {
11002: $udom = $env{'user.domain'};
11003: $uname = $env{'user.name'};
11004: $url = '/userfiles/portfolio';
11005: }
1.987 raeburn 11006: $toplevel = $url.'/';
1.984 raeburn 11007: $url .= $current_path;
11008: $getpropath = 1;
1.987 raeburn 11009: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11010: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11011: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11012: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11013: $toplevel = $url;
1.984 raeburn 11014: if ($rest ne '') {
1.987 raeburn 11015: $url .= $rest;
11016: }
11017: } elsif ($actionurl eq '/adm/coursedocs') {
11018: if (ref($args) eq 'HASH') {
1.1071 raeburn 11019: $url = $args->{'docs_url'};
11020: $toplevel = $url;
1.1075.2.11 raeburn 11021: if ($args->{'context'} eq 'paste') {
11022: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11023: ($path) =
11024: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11025: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11026: $fileloc =~ s{^/}{};
11027: }
1.1071 raeburn 11028: }
11029: } elsif ($actionurl eq '/adm/dependencies') {
11030: if ($env{'request.course.id'} ne '') {
11031: if (ref($args) eq 'HASH') {
11032: $url = $args->{'docs_url'};
11033: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 11034: $toplevel = $url;
11035: unless ($toplevel =~ m{^/}) {
11036: $toplevel = "/$url";
11037: }
1.1075.2.11 raeburn 11038: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 11039: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11040: $path = $1;
11041: } else {
11042: ($path) =
11043: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11044: }
1.1075.2.79 raeburn 11045: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11046: $fileloc = $toplevel;
11047: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11048: my ($udom,$uname,$fname) =
11049: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11050: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11051: } else {
11052: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11053: }
1.1071 raeburn 11054: $fileloc =~ s{^/}{};
11055: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11056: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11057: }
1.987 raeburn 11058: }
1.1075.2.35 raeburn 11059: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11060: $udom = $cdom;
11061: $uname = $cnum;
11062: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11063: $toplevel = $url;
11064: $path = $url;
11065: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11066: $fileloc =~ s{^/}{};
11067: }
11068: foreach my $file (keys(%{$allfiles})) {
11069: my $embed_file;
11070: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11071: $embed_file = $1;
11072: } else {
11073: $embed_file = $file;
11074: }
1.1075.2.55 raeburn 11075: my ($absolutepath,$cleaned_file);
11076: if ($embed_file =~ m{^\w+://}) {
11077: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 11078: $newfiles{$cleaned_file} = 1;
11079: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11080: } else {
1.1075.2.55 raeburn 11081: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11082: if ($embed_file =~ m{^/}) {
11083: $absolutepath = $embed_file;
11084: }
1.1075.2.47 raeburn 11085: if ($cleaned_file =~ m{/}) {
11086: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11087: $path = &check_for_traversal($path,$url,$toplevel);
11088: my $item = $fname;
11089: if ($path ne '') {
11090: $item = $path.'/'.$fname;
11091: $subdependencies{$path}{$fname} = 1;
11092: } else {
11093: $dependencies{$item} = 1;
11094: }
11095: if ($absolutepath) {
11096: $mapping{$item} = $absolutepath;
11097: } else {
11098: $mapping{$item} = $embed_file;
11099: }
11100: } else {
11101: $dependencies{$embed_file} = 1;
11102: if ($absolutepath) {
1.1075.2.47 raeburn 11103: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11104: } else {
1.1075.2.47 raeburn 11105: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11106: }
11107: }
1.984 raeburn 11108: }
11109: }
1.1071 raeburn 11110: my $dirptr = 16384;
1.984 raeburn 11111: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11112: $currsubfile{$path} = {};
1.1075.2.35 raeburn 11113: if (($actionurl eq '/adm/portfolio') ||
11114: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11115: my ($sublistref,$listerror) =
11116: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11117: if (ref($sublistref) eq 'ARRAY') {
11118: foreach my $line (@{$sublistref}) {
11119: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11120: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11121: }
1.984 raeburn 11122: }
1.987 raeburn 11123: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11124: if (opendir(my $dir,$url.'/'.$path)) {
11125: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11126: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11127: }
1.1075.2.11 raeburn 11128: } elsif (($actionurl eq '/adm/dependencies') ||
11129: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11130: ($args->{'context'} eq 'paste')) ||
11131: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11132: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 11133: my $dir;
11134: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11135: $dir = $fileloc;
11136: } else {
11137: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11138: }
1.1071 raeburn 11139: if ($dir ne '') {
11140: my ($sublistref,$listerror) =
11141: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11142: if (ref($sublistref) eq 'ARRAY') {
11143: foreach my $line (@{$sublistref}) {
11144: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11145: undef,$mtime)=split(/\&/,$line,12);
11146: unless (($testdir&$dirptr) ||
11147: ($file_name =~ /^\.\.?$/)) {
11148: $currsubfile{$path}{$file_name} = [$size,$mtime];
11149: }
11150: }
11151: }
11152: }
1.984 raeburn 11153: }
11154: }
11155: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11156: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11157: my $item = $path.'/'.$file;
11158: unless ($mapping{$item} eq $item) {
11159: $pathchanges{$item} = 1;
11160: }
11161: $existing{$item} = 1;
11162: $numexisting ++;
11163: } else {
11164: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11165: }
11166: }
1.1071 raeburn 11167: if ($actionurl eq '/adm/dependencies') {
11168: foreach my $path (keys(%currsubfile)) {
11169: if (ref($currsubfile{$path}) eq 'HASH') {
11170: foreach my $file (keys(%{$currsubfile{$path}})) {
11171: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 11172: next if (($rem ne '') &&
11173: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11174: (ref($navmap) &&
11175: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11176: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11177: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11178: $unused{$path.'/'.$file} = 1;
11179: }
11180: }
11181: }
11182: }
11183: }
1.984 raeburn 11184: }
1.987 raeburn 11185: my %currfile;
1.1075.2.35 raeburn 11186: if (($actionurl eq '/adm/portfolio') ||
11187: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11188: my ($dirlistref,$listerror) =
11189: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11190: if (ref($dirlistref) eq 'ARRAY') {
11191: foreach my $line (@{$dirlistref}) {
11192: my ($file_name,$rest) = split(/\&/,$line,2);
11193: $currfile{$file_name} = 1;
11194: }
1.984 raeburn 11195: }
1.987 raeburn 11196: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11197: if (opendir(my $dir,$url)) {
1.987 raeburn 11198: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11199: map {$currfile{$_} = 1;} @dir_list;
11200: }
1.1075.2.11 raeburn 11201: } elsif (($actionurl eq '/adm/dependencies') ||
11202: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11203: ($args->{'context'} eq 'paste')) ||
11204: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11205: if ($env{'request.course.id'} ne '') {
11206: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11207: if ($dir ne '') {
11208: my ($dirlistref,$listerror) =
11209: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11210: if (ref($dirlistref) eq 'ARRAY') {
11211: foreach my $line (@{$dirlistref}) {
11212: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11213: $size,undef,$mtime)=split(/\&/,$line,12);
11214: unless (($testdir&$dirptr) ||
11215: ($file_name =~ /^\.\.?$/)) {
11216: $currfile{$file_name} = [$size,$mtime];
11217: }
11218: }
11219: }
11220: }
11221: }
1.984 raeburn 11222: }
11223: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11224: if (exists($currfile{$file})) {
1.987 raeburn 11225: unless ($mapping{$file} eq $file) {
11226: $pathchanges{$file} = 1;
11227: }
11228: $existing{$file} = 1;
11229: $numexisting ++;
11230: } else {
1.984 raeburn 11231: $newfiles{$file} = 1;
11232: }
11233: }
1.1071 raeburn 11234: foreach my $file (keys(%currfile)) {
11235: unless (($file eq $filename) ||
11236: ($file eq $filename.'.bak') ||
11237: ($dependencies{$file})) {
1.1075.2.11 raeburn 11238: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 11239: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11240: next if (($rem ne '') &&
11241: (($env{"httpref.$rem".$file} ne '') ||
11242: (ref($navmap) &&
11243: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11244: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11245: ($navmap->getResourceByUrl($rem.$1)))))));
11246: }
1.1075.2.11 raeburn 11247: }
1.1071 raeburn 11248: $unused{$file} = 1;
11249: }
11250: }
1.1075.2.11 raeburn 11251: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11252: ($args->{'context'} eq 'paste')) {
11253: $counter = scalar(keys(%existing));
11254: $numpathchg = scalar(keys(%pathchanges));
11255: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 11256: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11257: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11258: $counter = scalar(keys(%existing));
11259: $numpathchg = scalar(keys(%pathchanges));
11260: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 11261: }
1.984 raeburn 11262: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11263: if ($actionurl eq '/adm/dependencies') {
11264: next if ($embed_file =~ m{^\w+://});
11265: }
1.660 raeburn 11266: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11267: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11268: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11269: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 11270: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11271: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11272: }
1.1075.2.35 raeburn 11273: $upload_output .= '</td>';
1.1071 raeburn 11274: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 11275: $upload_output.='<td align="right">'.
11276: '<span class="LC_info LC_fontsize_medium">'.
11277: &mt("URL points to web address").'</span>';
1.987 raeburn 11278: $numremref++;
1.660 raeburn 11279: } elsif ($args->{'error_on_invalid_names'}
11280: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 11281: $upload_output.='<td align="right"><span class="LC_warning">'.
11282: &mt('Invalid characters').'</span>';
1.987 raeburn 11283: $numinvalid++;
1.660 raeburn 11284: } else {
1.1075.2.35 raeburn 11285: $upload_output .= '<td>'.
11286: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11287: $embed_file,\%mapping,
1.1071 raeburn 11288: $allfiles,$codebase,'upload');
11289: $counter ++;
11290: $numnew ++;
1.987 raeburn 11291: }
11292: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11293: }
11294: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11295: if ($actionurl eq '/adm/dependencies') {
11296: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11297: $modify_output .= &start_data_table_row().
11298: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11299: '<img src="'.&icon($embed_file).'" border="0" />'.
11300: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11301: '<td>'.$size.'</td>'.
11302: '<td>'.$mtime.'</td>'.
11303: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11304: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11305: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11306: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11307: &embedded_file_element('upload_embedded',$counter,
11308: $embed_file,\%mapping,
11309: $allfiles,$codebase,'modify').
11310: '</div></td>'.
11311: &end_data_table_row()."\n";
11312: $counter ++;
11313: } else {
11314: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11315: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11316: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11317: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11318: &Apache::loncommon::end_data_table_row()."\n";
11319: }
11320: }
11321: my $delidx = $counter;
11322: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11323: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11324: $delete_output .= &start_data_table_row().
11325: '<td><img src="'.&icon($oldfile).'" />'.
11326: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11327: '<td>'.$size.'</td>'.
11328: '<td>'.$mtime.'</td>'.
11329: '<td><label><input type="checkbox" name="del_upload_dep" '.
11330: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11331: &embedded_file_element('upload_embedded',$delidx,
11332: $oldfile,\%mapping,$allfiles,
11333: $codebase,'delete').'</td>'.
11334: &end_data_table_row()."\n";
11335: $numunused ++;
11336: $delidx ++;
1.987 raeburn 11337: }
11338: if ($upload_output) {
11339: $upload_output = &start_data_table().
11340: $upload_output.
11341: &end_data_table()."\n";
11342: }
1.1071 raeburn 11343: if ($modify_output) {
11344: $modify_output = &start_data_table().
11345: &start_data_table_header_row().
11346: '<th>'.&mt('File').'</th>'.
11347: '<th>'.&mt('Size (KB)').'</th>'.
11348: '<th>'.&mt('Modified').'</th>'.
11349: '<th>'.&mt('Upload replacement?').'</th>'.
11350: &end_data_table_header_row().
11351: $modify_output.
11352: &end_data_table()."\n";
11353: }
11354: if ($delete_output) {
11355: $delete_output = &start_data_table().
11356: &start_data_table_header_row().
11357: '<th>'.&mt('File').'</th>'.
11358: '<th>'.&mt('Size (KB)').'</th>'.
11359: '<th>'.&mt('Modified').'</th>'.
11360: '<th>'.&mt('Delete?').'</th>'.
11361: &end_data_table_header_row().
11362: $delete_output.
11363: &end_data_table()."\n";
11364: }
1.987 raeburn 11365: my $applies = 0;
11366: if ($numremref) {
11367: $applies ++;
11368: }
11369: if ($numinvalid) {
11370: $applies ++;
11371: }
11372: if ($numexisting) {
11373: $applies ++;
11374: }
1.1071 raeburn 11375: if ($counter || $numunused) {
1.987 raeburn 11376: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11377: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11378: $state.'<h3>'.$heading.'</h3>';
11379: if ($actionurl eq '/adm/dependencies') {
11380: if ($numnew) {
11381: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11382: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11383: $upload_output.'<br />'."\n";
11384: }
11385: if ($numexisting) {
11386: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11387: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11388: $modify_output.'<br />'."\n";
11389: $buttontext = &mt('Save changes');
11390: }
11391: if ($numunused) {
11392: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11393: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11394: $delete_output.'<br />'."\n";
11395: $buttontext = &mt('Save changes');
11396: }
11397: } else {
11398: $output .= $upload_output.'<br />'."\n";
11399: }
11400: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11401: $counter.'" />'."\n";
11402: if ($actionurl eq '/adm/dependencies') {
11403: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11404: $numnew.'" />'."\n";
11405: } elsif ($actionurl eq '') {
1.987 raeburn 11406: $output .= '<input type="hidden" name="phase" value="three" />';
11407: }
11408: } elsif ($applies) {
11409: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11410: if ($applies > 1) {
11411: $output .=
1.1075.2.35 raeburn 11412: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11413: if ($numremref) {
11414: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11415: }
11416: if ($numinvalid) {
11417: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11418: }
11419: if ($numexisting) {
11420: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11421: }
11422: $output .= '</ul><br />';
11423: } elsif ($numremref) {
11424: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11425: } elsif ($numinvalid) {
11426: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11427: } elsif ($numexisting) {
11428: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11429: }
11430: $output .= $upload_output.'<br />';
11431: }
11432: my ($pathchange_output,$chgcount);
1.1071 raeburn 11433: $chgcount = $counter;
1.987 raeburn 11434: if (keys(%pathchanges) > 0) {
11435: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11436: if ($counter) {
1.987 raeburn 11437: $output .= &embedded_file_element('pathchange',$chgcount,
11438: $embed_file,\%mapping,
1.1071 raeburn 11439: $allfiles,$codebase,'change');
1.987 raeburn 11440: } else {
11441: $pathchange_output .=
11442: &start_data_table_row().
11443: '<td><input type ="checkbox" name="namechange" value="'.
11444: $chgcount.'" checked="checked" /></td>'.
11445: '<td>'.$mapping{$embed_file}.'</td>'.
11446: '<td>'.$embed_file.
11447: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11448: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11449: '</td>'.&end_data_table_row();
1.660 raeburn 11450: }
1.987 raeburn 11451: $numpathchg ++;
11452: $chgcount ++;
1.660 raeburn 11453: }
11454: }
1.1075.2.35 raeburn 11455: if (($counter) || ($numunused)) {
1.987 raeburn 11456: if ($numpathchg) {
11457: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11458: $numpathchg.'" />'."\n";
11459: }
11460: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11461: ($actionurl eq '/adm/imsimport')) {
11462: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11463: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11464: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11465: } elsif ($actionurl eq '/adm/dependencies') {
11466: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11467: }
1.1075.2.35 raeburn 11468: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11469: } elsif ($numpathchg) {
11470: my %pathchange = ();
11471: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11472: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11473: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11474: }
1.987 raeburn 11475: }
1.1071 raeburn 11476: return ($output,$counter,$numpathchg);
1.987 raeburn 11477: }
11478:
1.1075.2.47 raeburn 11479: =pod
11480:
11481: =item * clean_path($name)
11482:
11483: Performs clean-up of directories, subdirectories and filename in an
11484: embedded object, referenced in an HTML file which is being uploaded
11485: to a course or portfolio, where
11486: "Upload embedded images/multimedia files if HTML file" checkbox was
11487: checked.
11488:
11489: Clean-up is similar to replacements in lonnet::clean_filename()
11490: except each / between sub-directory and next level is preserved.
11491:
11492: =cut
11493:
11494: sub clean_path {
11495: my ($embed_file) = @_;
11496: $embed_file =~s{^/+}{};
11497: my @contents;
11498: if ($embed_file =~ m{/}) {
11499: @contents = split(/\//,$embed_file);
11500: } else {
11501: @contents = ($embed_file);
11502: }
11503: my $lastidx = scalar(@contents)-1;
11504: for (my $i=0; $i<=$lastidx; $i++) {
11505: $contents[$i]=~s{\\}{/}g;
11506: $contents[$i]=~s/\s+/\_/g;
11507: $contents[$i]=~s{[^/\w\.\-]}{}g;
11508: if ($i == $lastidx) {
11509: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11510: }
11511: }
11512: if ($lastidx > 0) {
11513: return join('/',@contents);
11514: } else {
11515: return $contents[0];
11516: }
11517: }
11518:
1.987 raeburn 11519: sub embedded_file_element {
1.1071 raeburn 11520: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11521: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11522: (ref($codebase) eq 'HASH'));
11523: my $output;
1.1071 raeburn 11524: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11525: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11526: }
11527: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11528: &escape($embed_file).'" />';
11529: unless (($context eq 'upload_embedded') &&
11530: ($mapping->{$embed_file} eq $embed_file)) {
11531: $output .='
11532: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11533: }
11534: my $attrib;
11535: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11536: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11537: }
11538: $output .=
11539: "\n\t\t".
11540: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11541: $attrib.'" />';
11542: if (exists($codebase->{$mapping->{$embed_file}})) {
11543: $output .=
11544: "\n\t\t".
11545: '<input name="codebase_'.$num.'" type="hidden" value="'.
11546: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11547: }
1.987 raeburn 11548: return $output;
1.660 raeburn 11549: }
11550:
1.1071 raeburn 11551: sub get_dependency_details {
11552: my ($currfile,$currsubfile,$embed_file) = @_;
11553: my ($size,$mtime,$showsize,$showmtime);
11554: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11555: if ($embed_file =~ m{/}) {
11556: my ($path,$fname) = split(/\//,$embed_file);
11557: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11558: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11559: }
11560: } else {
11561: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11562: ($size,$mtime) = @{$currfile->{$embed_file}};
11563: }
11564: }
11565: $showsize = $size/1024.0;
11566: $showsize = sprintf("%.1f",$showsize);
11567: if ($mtime > 0) {
11568: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11569: }
11570: }
11571: return ($showsize,$showmtime);
11572: }
11573:
11574: sub ask_embedded_js {
11575: return <<"END";
11576: <script type="text/javascript"">
11577: // <![CDATA[
11578: function toggleBrowse(counter) {
11579: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11580: var fileid = document.getElementById('embedded_item_'+counter);
11581: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11582: if (chkboxid.checked == true) {
11583: uploaddivid.style.display='block';
11584: } else {
11585: uploaddivid.style.display='none';
11586: fileid.value = '';
11587: }
11588: }
11589: // ]]>
11590: </script>
11591:
11592: END
11593: }
11594:
1.661 raeburn 11595: sub upload_embedded {
11596: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11597: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11598: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11599: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11600: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11601: my $orig_uploaded_filename =
11602: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11603: foreach my $type ('orig','ref','attrib','codebase') {
11604: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11605: $env{'form.embedded_'.$type.'_'.$i} =
11606: &unescape($env{'form.embedded_'.$type.'_'.$i});
11607: }
11608: }
1.661 raeburn 11609: my ($path,$fname) =
11610: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11611: # no path, whole string is fname
11612: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11613: $fname = &Apache::lonnet::clean_filename($fname);
11614: # See if there is anything left
11615: next if ($fname eq '');
11616:
11617: # Check if file already exists as a file or directory.
11618: my ($state,$msg);
11619: if ($context eq 'portfolio') {
11620: my $port_path = $dirpath;
11621: if ($group ne '') {
11622: $port_path = "groups/$group/$port_path";
11623: }
1.987 raeburn 11624: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11625: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11626: $dir_root,$port_path,$disk_quota,
11627: $current_disk_usage,$uname,$udom);
11628: if ($state eq 'will_exceed_quota'
1.984 raeburn 11629: || $state eq 'file_locked') {
1.661 raeburn 11630: $output .= $msg;
11631: next;
11632: }
11633: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11634: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11635: if ($state eq 'exists') {
11636: $output .= $msg;
11637: next;
11638: }
11639: }
11640: # Check if extension is valid
11641: if (($fname =~ /\.(\w+)$/) &&
11642: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11643: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11644: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11645: next;
11646: } elsif (($fname =~ /\.(\w+)$/) &&
11647: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11648: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11649: next;
11650: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11651: $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 11652: next;
11653: }
11654: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11655: my $subdir = $path;
11656: $subdir =~ s{/+$}{};
1.661 raeburn 11657: if ($context eq 'portfolio') {
1.984 raeburn 11658: my $result;
11659: if ($state eq 'existingfile') {
11660: $result=
11661: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11662: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11663: } else {
1.984 raeburn 11664: $result=
11665: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11666: $dirpath.
1.1075.2.35 raeburn 11667: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11668: if ($result !~ m|^/uploaded/|) {
11669: $output .= '<span class="LC_error">'
11670: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11671: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11672: .'</span><br />';
11673: next;
11674: } else {
1.987 raeburn 11675: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11676: $path.$fname.'</span>').'<br />';
1.984 raeburn 11677: }
1.661 raeburn 11678: }
1.1075.2.35 raeburn 11679: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11680: my $extendedsubdir = $dirpath.'/'.$subdir;
11681: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11682: my $result =
1.1075.2.35 raeburn 11683: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11684: if ($result !~ m|^/uploaded/|) {
11685: $output .= '<span class="LC_error">'
11686: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11687: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11688: .'</span><br />';
11689: next;
11690: } else {
11691: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11692: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11693: if ($context eq 'syllabus') {
11694: &Apache::lonnet::make_public_indefinitely($result);
11695: }
1.987 raeburn 11696: }
1.661 raeburn 11697: } else {
11698: # Save the file
11699: my $target = $env{'form.embedded_item_'.$i};
11700: my $fullpath = $dir_root.$dirpath.'/'.$path;
11701: my $dest = $fullpath.$fname;
11702: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11703: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11704: my $count;
11705: my $filepath = $dir_root;
1.1027 raeburn 11706: foreach my $subdir (@parts) {
11707: $filepath .= "/$subdir";
11708: if (!-e $filepath) {
1.661 raeburn 11709: mkdir($filepath,0770);
11710: }
11711: }
11712: my $fh;
11713: if (!open($fh,'>'.$dest)) {
11714: &Apache::lonnet::logthis('Failed to create '.$dest);
11715: $output .= '<span class="LC_error">'.
1.1071 raeburn 11716: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11717: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11718: '</span><br />';
11719: } else {
11720: if (!print $fh $env{'form.embedded_item_'.$i}) {
11721: &Apache::lonnet::logthis('Failed to write to '.$dest);
11722: $output .= '<span class="LC_error">'.
1.1071 raeburn 11723: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11724: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11725: '</span><br />';
11726: } else {
1.987 raeburn 11727: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11728: $url.'</span>').'<br />';
11729: unless ($context eq 'testbank') {
11730: $footer .= &mt('View embedded file: [_1]',
11731: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11732: }
11733: }
11734: close($fh);
11735: }
11736: }
11737: if ($env{'form.embedded_ref_'.$i}) {
11738: $pathchange{$i} = 1;
11739: }
11740: }
11741: if ($output) {
11742: $output = '<p>'.$output.'</p>';
11743: }
11744: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11745: $returnflag = 'ok';
1.1071 raeburn 11746: my $numpathchgs = scalar(keys(%pathchange));
11747: if ($numpathchgs > 0) {
1.987 raeburn 11748: if ($context eq 'portfolio') {
11749: $output .= '<p>'.&mt('or').'</p>';
11750: } elsif ($context eq 'testbank') {
1.1071 raeburn 11751: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11752: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11753: $returnflag = 'modify_orightml';
11754: }
11755: }
1.1071 raeburn 11756: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11757: }
11758:
11759: sub modify_html_form {
11760: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11761: my $end = 0;
11762: my $modifyform;
11763: if ($context eq 'upload_embedded') {
11764: return unless (ref($pathchange) eq 'HASH');
11765: if ($env{'form.number_embedded_items'}) {
11766: $end += $env{'form.number_embedded_items'};
11767: }
11768: if ($env{'form.number_pathchange_items'}) {
11769: $end += $env{'form.number_pathchange_items'};
11770: }
11771: if ($end) {
11772: for (my $i=0; $i<$end; $i++) {
11773: if ($i < $env{'form.number_embedded_items'}) {
11774: next unless($pathchange->{$i});
11775: }
11776: $modifyform .=
11777: &start_data_table_row().
11778: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11779: 'checked="checked" /></td>'.
11780: '<td>'.$env{'form.embedded_ref_'.$i}.
11781: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11782: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11783: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11784: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11785: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11786: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11787: '<td>'.$env{'form.embedded_orig_'.$i}.
11788: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11789: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11790: &end_data_table_row();
1.1071 raeburn 11791: }
1.987 raeburn 11792: }
11793: } else {
11794: $modifyform = $pathchgtable;
11795: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11796: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11797: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11798: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11799: }
11800: }
11801: if ($modifyform) {
1.1071 raeburn 11802: if ($actionurl eq '/adm/dependencies') {
11803: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11804: }
1.987 raeburn 11805: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11806: '<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".
11807: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11808: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11809: '</ol></p>'."\n".'<p>'.
11810: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11811: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11812: &start_data_table()."\n".
11813: &start_data_table_header_row().
11814: '<th>'.&mt('Change?').'</th>'.
11815: '<th>'.&mt('Current reference').'</th>'.
11816: '<th>'.&mt('Required reference').'</th>'.
11817: &end_data_table_header_row()."\n".
11818: $modifyform.
11819: &end_data_table().'<br />'."\n".$hiddenstate.
11820: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11821: '</form>'."\n";
11822: }
11823: return;
11824: }
11825:
11826: sub modify_html_refs {
1.1075.2.35 raeburn 11827: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11828: my $container;
11829: if ($context eq 'portfolio') {
11830: $container = $env{'form.container'};
11831: } elsif ($context eq 'coursedoc') {
11832: $container = $env{'form.primaryurl'};
1.1071 raeburn 11833: } elsif ($context eq 'manage_dependencies') {
11834: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11835: $container = "/$container";
1.1075.2.35 raeburn 11836: } elsif ($context eq 'syllabus') {
11837: $container = $url;
1.987 raeburn 11838: } else {
1.1027 raeburn 11839: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11840: }
11841: my (%allfiles,%codebase,$output,$content);
11842: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11843: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11844: if (wantarray) {
11845: return ('',0,0);
11846: } else {
11847: return;
11848: }
11849: }
11850: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11851: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11852: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11853: if (wantarray) {
11854: return ('',0,0);
11855: } else {
11856: return;
11857: }
11858: }
1.987 raeburn 11859: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11860: if ($content eq '-1') {
11861: if (wantarray) {
11862: return ('',0,0);
11863: } else {
11864: return;
11865: }
11866: }
1.987 raeburn 11867: } else {
1.1071 raeburn 11868: unless ($container =~ /^\Q$dir_root\E/) {
11869: if (wantarray) {
11870: return ('',0,0);
11871: } else {
11872: return;
11873: }
11874: }
1.1075.2.128 raeburn 11875: if (open(my $fh,'<',$container)) {
1.987 raeburn 11876: $content = join('', <$fh>);
11877: close($fh);
11878: } else {
1.1071 raeburn 11879: if (wantarray) {
11880: return ('',0,0);
11881: } else {
11882: return;
11883: }
1.987 raeburn 11884: }
11885: }
11886: my ($count,$codebasecount) = (0,0);
11887: my $mm = new File::MMagic;
11888: my $mime_type = $mm->checktype_contents($content);
11889: if ($mime_type eq 'text/html') {
11890: my $parse_result =
11891: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11892: \%codebase,\$content);
11893: if ($parse_result eq 'ok') {
11894: foreach my $i (@changes) {
11895: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11896: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11897: if ($allfiles{$ref}) {
11898: my $newname = $orig;
11899: my ($attrib_regexp,$codebase);
1.1006 raeburn 11900: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11901: if ($attrib_regexp =~ /:/) {
11902: $attrib_regexp =~ s/\:/|/g;
11903: }
11904: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11905: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11906: $count += $numchg;
1.1075.2.35 raeburn 11907: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11908: delete($allfiles{$ref});
1.987 raeburn 11909: }
11910: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11911: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11912: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11913: $codebasecount ++;
11914: }
11915: }
11916: }
1.1075.2.35 raeburn 11917: my $skiprewrites;
1.987 raeburn 11918: if ($count || $codebasecount) {
11919: my $saveresult;
1.1071 raeburn 11920: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11921: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11922: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11923: if ($url eq $container) {
11924: my ($fname) = ($container =~ m{/([^/]+)$});
11925: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11926: $count,'<span class="LC_filename">'.
1.1071 raeburn 11927: $fname.'</span>').'</p>';
1.987 raeburn 11928: } else {
11929: $output = '<p class="LC_error">'.
11930: &mt('Error: update failed for: [_1].',
11931: '<span class="LC_filename">'.
11932: $container.'</span>').'</p>';
11933: }
1.1075.2.35 raeburn 11934: if ($context eq 'syllabus') {
11935: unless ($saveresult eq 'ok') {
11936: $skiprewrites = 1;
11937: }
11938: }
1.987 raeburn 11939: } else {
1.1075.2.128 raeburn 11940: if (open(my $fh,'>',$container)) {
1.987 raeburn 11941: print $fh $content;
11942: close($fh);
11943: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11944: $count,'<span class="LC_filename">'.
11945: $container.'</span>').'</p>';
1.661 raeburn 11946: } else {
1.987 raeburn 11947: $output = '<p class="LC_error">'.
11948: &mt('Error: could not update [_1].',
11949: '<span class="LC_filename">'.
11950: $container.'</span>').'</p>';
1.661 raeburn 11951: }
11952: }
11953: }
1.1075.2.35 raeburn 11954: if (($context eq 'syllabus') && (!$skiprewrites)) {
11955: my ($actionurl,$state);
11956: $actionurl = "/public/$udom/$uname/syllabus";
11957: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11958: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11959: \%codebase,
11960: {'context' => 'rewrites',
11961: 'ignore_remote_references' => 1,});
11962: if (ref($mapping) eq 'HASH') {
11963: my $rewrites = 0;
11964: foreach my $key (keys(%{$mapping})) {
11965: next if ($key =~ m{^https?://});
11966: my $ref = $mapping->{$key};
11967: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11968: my $attrib;
11969: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11970: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11971: }
11972: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11973: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11974: $rewrites += $numchg;
11975: }
11976: }
11977: if ($rewrites) {
11978: my $saveresult;
11979: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11980: if ($url eq $container) {
11981: my ($fname) = ($container =~ m{/([^/]+)$});
11982: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11983: $count,'<span class="LC_filename">'.
11984: $fname.'</span>').'</p>';
11985: } else {
11986: $output .= '<p class="LC_error">'.
11987: &mt('Error: could not update links in [_1].',
11988: '<span class="LC_filename">'.
11989: $container.'</span>').'</p>';
11990:
11991: }
11992: }
11993: }
11994: }
1.987 raeburn 11995: } else {
11996: &logthis('Failed to parse '.$container.
11997: ' to modify references: '.$parse_result);
1.661 raeburn 11998: }
11999: }
1.1071 raeburn 12000: if (wantarray) {
12001: return ($output,$count,$codebasecount);
12002: } else {
12003: return $output;
12004: }
1.661 raeburn 12005: }
12006:
12007: sub check_for_existing {
12008: my ($path,$fname,$element) = @_;
12009: my ($state,$msg);
12010: if (-d $path.'/'.$fname) {
12011: $state = 'exists';
12012: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12013: } elsif (-e $path.'/'.$fname) {
12014: $state = 'exists';
12015: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12016: }
12017: if ($state eq 'exists') {
12018: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12019: }
12020: return ($state,$msg);
12021: }
12022:
12023: sub check_for_upload {
12024: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12025: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12026: my $filesize = length($env{'form.'.$element});
12027: if (!$filesize) {
12028: my $msg = '<span class="LC_error">'.
12029: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12030: '<span class="LC_filename">'.$fname.'</span>',
12031: $filesize).'<br />'.
1.1007 raeburn 12032: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12033: '</span>';
12034: return ('zero_bytes',$msg);
12035: }
12036: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12037: my $getpropath = 1;
1.1021 raeburn 12038: my ($dirlistref,$listerror) =
12039: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12040: my $found_file = 0;
12041: my $locked_file = 0;
1.991 raeburn 12042: my @lockers;
12043: my $navmap;
12044: if ($env{'request.course.id'}) {
12045: $navmap = Apache::lonnavmaps::navmap->new();
12046: }
1.1021 raeburn 12047: if (ref($dirlistref) eq 'ARRAY') {
12048: foreach my $line (@{$dirlistref}) {
12049: my ($file_name,$rest)=split(/\&/,$line,2);
12050: if ($file_name eq $fname){
12051: $file_name = $path.$file_name;
12052: if ($group ne '') {
12053: $file_name = $group.$file_name;
12054: }
12055: $found_file = 1;
12056: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12057: foreach my $lock (@lockers) {
12058: if (ref($lock) eq 'ARRAY') {
12059: my ($symb,$crsid) = @{$lock};
12060: if ($crsid eq $env{'request.course.id'}) {
12061: if (ref($navmap)) {
12062: my $res = $navmap->getBySymb($symb);
12063: foreach my $part (@{$res->parts()}) {
12064: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12065: unless (($slot_status == $res->RESERVED) ||
12066: ($slot_status == $res->RESERVED_LOCATION)) {
12067: $locked_file = 1;
12068: }
1.991 raeburn 12069: }
1.1021 raeburn 12070: } else {
12071: $locked_file = 1;
1.991 raeburn 12072: }
12073: } else {
12074: $locked_file = 1;
12075: }
12076: }
1.1021 raeburn 12077: }
12078: } else {
12079: my @info = split(/\&/,$rest);
12080: my $currsize = $info[6]/1000;
12081: if ($currsize < $filesize) {
12082: my $extra = $filesize - $currsize;
12083: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 12084: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12085: &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 12086: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12087: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12088: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12089: return ('will_exceed_quota',$msg);
12090: }
1.984 raeburn 12091: }
12092: }
1.661 raeburn 12093: }
12094: }
12095: }
12096: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 12097: my $msg = '<p class="LC_warning">'.
12098: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
12099: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12100: return ('will_exceed_quota',$msg);
12101: } elsif ($found_file) {
12102: if ($locked_file) {
1.1075.2.69 raeburn 12103: my $msg = '<p class="LC_warning">';
1.661 raeburn 12104: $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 12105: $msg .= '</p>';
1.661 raeburn 12106: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12107: return ('file_locked',$msg);
12108: } else {
1.1075.2.69 raeburn 12109: my $msg = '<p class="LC_error">';
1.984 raeburn 12110: $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 12111: $msg .= '</p>';
1.984 raeburn 12112: return ('existingfile',$msg);
1.661 raeburn 12113: }
12114: }
12115: }
12116:
1.987 raeburn 12117: sub check_for_traversal {
12118: my ($path,$url,$toplevel) = @_;
12119: my @parts=split(/\//,$path);
12120: my $cleanpath;
12121: my $fullpath = $url;
12122: for (my $i=0;$i<@parts;$i++) {
12123: next if ($parts[$i] eq '.');
12124: if ($parts[$i] eq '..') {
12125: $fullpath =~ s{([^/]+/)$}{};
12126: } else {
12127: $fullpath .= $parts[$i].'/';
12128: }
12129: }
12130: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12131: $cleanpath = $1;
12132: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12133: my $curr_toprel = $1;
12134: my @parts = split(/\//,$curr_toprel);
12135: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12136: my @urlparts = split(/\//,$url_toprel);
12137: my $doubledots;
12138: my $startdiff = -1;
12139: for (my $i=0; $i<@urlparts; $i++) {
12140: if ($startdiff == -1) {
12141: unless ($urlparts[$i] eq $parts[$i]) {
12142: $startdiff = $i;
12143: $doubledots .= '../';
12144: }
12145: } else {
12146: $doubledots .= '../';
12147: }
12148: }
12149: if ($startdiff > -1) {
12150: $cleanpath = $doubledots;
12151: for (my $i=$startdiff; $i<@parts; $i++) {
12152: $cleanpath .= $parts[$i].'/';
12153: }
12154: }
12155: }
12156: $cleanpath =~ s{(/)$}{};
12157: return $cleanpath;
12158: }
1.31 albertel 12159:
1.1053 raeburn 12160: sub is_archive_file {
12161: my ($mimetype) = @_;
12162: if (($mimetype eq 'application/octet-stream') ||
12163: ($mimetype eq 'application/x-stuffit') ||
12164: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12165: return 1;
12166: }
12167: return;
12168: }
12169:
12170: sub decompress_form {
1.1065 raeburn 12171: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12172: my %lt = &Apache::lonlocal::texthash (
12173: this => 'This file is an archive file.',
1.1067 raeburn 12174: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12175: itsc => 'Its contents are as follows:',
1.1053 raeburn 12176: youm => 'You may wish to extract its contents.',
12177: extr => 'Extract contents',
1.1067 raeburn 12178: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12179: proa => 'Process automatically?',
1.1053 raeburn 12180: yes => 'Yes',
12181: no => 'No',
1.1067 raeburn 12182: fold => 'Title for folder containing movie',
12183: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12184: );
1.1065 raeburn 12185: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12186: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12187: my $info = &list_archive_contents($fileloc,\@paths);
12188: if (@paths) {
12189: foreach my $path (@paths) {
12190: $path =~ s{^/}{};
1.1067 raeburn 12191: if ($path =~ m{^([^/]+)/$}) {
12192: $topdir = $1;
12193: }
1.1065 raeburn 12194: if ($path =~ m{^([^/]+)/}) {
12195: $toplevel{$1} = $path;
12196: } else {
12197: $toplevel{$path} = $path;
12198: }
12199: }
12200: }
1.1067 raeburn 12201: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 12202: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12203: "$topdir/media/",
12204: "$topdir/media/$topdir.mp4",
12205: "$topdir/media/FirstFrame.png",
12206: "$topdir/media/player.swf",
12207: "$topdir/media/swfobject.js",
12208: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 12209: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 12210: "$topdir/$topdir.mp4",
12211: "$topdir/$topdir\_config.xml",
12212: "$topdir/$topdir\_controller.swf",
12213: "$topdir/$topdir\_embed.css",
12214: "$topdir/$topdir\_First_Frame.png",
12215: "$topdir/$topdir\_player.html",
12216: "$topdir/$topdir\_Thumbnails.png",
12217: "$topdir/playerProductInstall.swf",
12218: "$topdir/scripts/",
12219: "$topdir/scripts/config_xml.js",
12220: "$topdir/scripts/handlebars.js",
12221: "$topdir/scripts/jquery-1.7.1.min.js",
12222: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12223: "$topdir/scripts/modernizr.js",
12224: "$topdir/scripts/player-min.js",
12225: "$topdir/scripts/swfobject.js",
12226: "$topdir/skins/",
12227: "$topdir/skins/configuration_express.xml",
12228: "$topdir/skins/express_show/",
12229: "$topdir/skins/express_show/player-min.css",
12230: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 12231: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12232: "$topdir/$topdir.mp4",
12233: "$topdir/$topdir\_config.xml",
12234: "$topdir/$topdir\_controller.swf",
12235: "$topdir/$topdir\_embed.css",
12236: "$topdir/$topdir\_First_Frame.png",
12237: "$topdir/$topdir\_player.html",
12238: "$topdir/$topdir\_Thumbnails.png",
12239: "$topdir/playerProductInstall.swf",
12240: "$topdir/scripts/",
12241: "$topdir/scripts/config_xml.js",
12242: "$topdir/scripts/techsmith-smart-player.min.js",
12243: "$topdir/skins/",
12244: "$topdir/skins/configuration_express.xml",
12245: "$topdir/skins/express_show/",
12246: "$topdir/skins/express_show/spritesheet.min.css",
12247: "$topdir/skins/express_show/spritesheet.png",
12248: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 12249: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12250: if (@diffs == 0) {
1.1075.2.59 raeburn 12251: $is_camtasia = 6;
12252: } else {
1.1075.2.81 raeburn 12253: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 12254: if (@diffs == 0) {
12255: $is_camtasia = 8;
1.1075.2.81 raeburn 12256: } else {
12257: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12258: if (@diffs == 0) {
12259: $is_camtasia = 8;
12260: }
1.1075.2.59 raeburn 12261: }
1.1067 raeburn 12262: }
12263: }
12264: my $output;
12265: if ($is_camtasia) {
12266: $output = <<"ENDCAM";
12267: <script type="text/javascript" language="Javascript">
12268: // <![CDATA[
12269:
12270: function camtasiaToggle() {
12271: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12272: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 12273: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12274: document.getElementById('camtasia_titles').style.display='block';
12275: } else {
12276: document.getElementById('camtasia_titles').style.display='none';
12277: }
12278: }
12279: }
12280: return;
12281: }
12282:
12283: // ]]>
12284: </script>
12285: <p>$lt{'camt'}</p>
12286: ENDCAM
1.1065 raeburn 12287: } else {
1.1067 raeburn 12288: $output = '<p>'.$lt{'this'};
12289: if ($info eq '') {
12290: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12291: } else {
12292: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12293: '<div><pre>'.$info.'</pre></div>';
12294: }
1.1065 raeburn 12295: }
1.1067 raeburn 12296: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12297: my $duplicates;
12298: my $num = 0;
12299: if (ref($dirlist) eq 'ARRAY') {
12300: foreach my $item (@{$dirlist}) {
12301: if (ref($item) eq 'ARRAY') {
12302: if (exists($toplevel{$item->[0]})) {
12303: $duplicates .=
12304: &start_data_table_row().
12305: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12306: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12307: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12308: 'value="1" />'.&mt('Yes').'</label>'.
12309: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12310: '<td>'.$item->[0].'</td>';
12311: if ($item->[2]) {
12312: $duplicates .= '<td>'.&mt('Directory').'</td>';
12313: } else {
12314: $duplicates .= '<td>'.&mt('File').'</td>';
12315: }
12316: $duplicates .= '<td>'.$item->[3].'</td>'.
12317: '<td>'.
12318: &Apache::lonlocal::locallocaltime($item->[4]).
12319: '</td>'.
12320: &end_data_table_row();
12321: $num ++;
12322: }
12323: }
12324: }
12325: }
12326: my $itemcount;
12327: if (@paths > 0) {
12328: $itemcount = scalar(@paths);
12329: } else {
12330: $itemcount = 1;
12331: }
1.1067 raeburn 12332: if ($is_camtasia) {
12333: $output .= $lt{'auto'}.'<br />'.
12334: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12335: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12336: $lt{'yes'}.'</label> <label>'.
12337: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12338: $lt{'no'}.'</label></span><br />'.
12339: '<div id="camtasia_titles" style="display:block">'.
12340: &Apache::lonhtmlcommon::start_pick_box().
12341: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12342: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12343: &Apache::lonhtmlcommon::row_closure().
12344: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12345: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12346: &Apache::lonhtmlcommon::row_closure(1).
12347: &Apache::lonhtmlcommon::end_pick_box().
12348: '</div>';
12349: }
1.1065 raeburn 12350: $output .=
12351: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12352: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12353: "\n";
1.1065 raeburn 12354: if ($duplicates ne '') {
12355: $output .= '<p><span class="LC_warning">'.
12356: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12357: &start_data_table().
12358: &start_data_table_header_row().
12359: '<th>'.&mt('Overwrite?').'</th>'.
12360: '<th>'.&mt('Name').'</th>'.
12361: '<th>'.&mt('Type').'</th>'.
12362: '<th>'.&mt('Size').'</th>'.
12363: '<th>'.&mt('Last modified').'</th>'.
12364: &end_data_table_header_row().
12365: $duplicates.
12366: &end_data_table().
12367: '</p>';
12368: }
1.1067 raeburn 12369: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12370: if (ref($hiddenelements) eq 'HASH') {
12371: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12372: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12373: }
12374: }
12375: $output .= <<"END";
1.1067 raeburn 12376: <br />
1.1053 raeburn 12377: <input type="submit" name="decompress" value="$lt{'extr'}" />
12378: </form>
12379: $noextract
12380: END
12381: return $output;
12382: }
12383:
1.1065 raeburn 12384: sub decompression_utility {
12385: my ($program) = @_;
12386: my @utilities = ('tar','gunzip','bunzip2','unzip');
12387: my $location;
12388: if (grep(/^\Q$program\E$/,@utilities)) {
12389: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12390: '/usr/sbin/') {
12391: if (-x $dir.$program) {
12392: $location = $dir.$program;
12393: last;
12394: }
12395: }
12396: }
12397: return $location;
12398: }
12399:
12400: sub list_archive_contents {
12401: my ($file,$pathsref) = @_;
12402: my (@cmd,$output);
12403: my $needsregexp;
12404: if ($file =~ /\.zip$/) {
12405: @cmd = (&decompression_utility('unzip'),"-l");
12406: $needsregexp = 1;
12407: } elsif (($file =~ m/\.tar\.gz$/) ||
12408: ($file =~ /\.tgz$/)) {
12409: @cmd = (&decompression_utility('tar'),"-ztf");
12410: } elsif ($file =~ /\.tar\.bz2$/) {
12411: @cmd = (&decompression_utility('tar'),"-jtf");
12412: } elsif ($file =~ m|\.tar$|) {
12413: @cmd = (&decompression_utility('tar'),"-tf");
12414: }
12415: if (@cmd) {
12416: undef($!);
12417: undef($@);
12418: if (open(my $fh,"-|", @cmd, $file)) {
12419: while (my $line = <$fh>) {
12420: $output .= $line;
12421: chomp($line);
12422: my $item;
12423: if ($needsregexp) {
12424: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12425: } else {
12426: $item = $line;
12427: }
12428: if ($item ne '') {
12429: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12430: push(@{$pathsref},$item);
12431: }
12432: }
12433: }
12434: close($fh);
12435: }
12436: }
12437: return $output;
12438: }
12439:
1.1053 raeburn 12440: sub decompress_uploaded_file {
12441: my ($file,$dir) = @_;
12442: &Apache::lonnet::appenv({'cgi.file' => $file});
12443: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12444: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12445: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12446: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12447: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12448: my $decompressed = $env{'cgi.decompressed'};
12449: &Apache::lonnet::delenv('cgi.file');
12450: &Apache::lonnet::delenv('cgi.dir');
12451: &Apache::lonnet::delenv('cgi.decompressed');
12452: return ($decompressed,$result);
12453: }
12454:
1.1055 raeburn 12455: sub process_decompression {
12456: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12457: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12458: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12459: &mt('Unexpected file path.').'</p>'."\n";
12460: }
12461: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12462: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12463: &mt('Unexpected course context.').'</p>'."\n";
12464: }
12465: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12466: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12467: &mt('Filename contained unexpected characters.').'</p>'."\n";
12468: }
1.1055 raeburn 12469: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12470: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12471: $error = &mt('Filename not a supported archive file type.').
12472: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12473: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12474: } else {
12475: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12476: if ($docuhome eq 'no_host') {
12477: $error = &mt('Could not determine home server for course.');
12478: } else {
12479: my @ids=&Apache::lonnet::current_machine_ids();
12480: my $currdir = "$dir_root/$destination";
12481: if (grep(/^\Q$docuhome\E$/,@ids)) {
12482: $dir = &LONCAPA::propath($docudom,$docuname).
12483: "$dir_root/$destination";
12484: } else {
12485: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12486: "$dir_root/$docudom/$docuname/$destination";
12487: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12488: $error = &mt('Archive file not found.');
12489: }
12490: }
1.1065 raeburn 12491: my (@to_overwrite,@to_skip);
12492: if ($env{'form.archive_overwrite_total'} > 0) {
12493: my $total = $env{'form.archive_overwrite_total'};
12494: for (my $i=0; $i<$total; $i++) {
12495: if ($env{'form.archive_overwrite_'.$i} == 1) {
12496: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12497: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12498: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12499: }
12500: }
12501: }
12502: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12503: my $numoverwrite = scalar(@to_overwrite);
12504: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12505: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12506: } elsif ($dir eq '') {
1.1055 raeburn 12507: $error = &mt('Directory containing archive file unavailable.');
12508: } elsif (!$error) {
1.1065 raeburn 12509: my ($decompressed,$display);
1.1075.2.128 raeburn 12510: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12511: my $tempdir = time.'_'.$$.int(rand(10000));
12512: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12513: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12514: ($decompressed,$display) =
12515: &decompress_uploaded_file($file,"$dir/$tempdir");
12516: foreach my $item (@to_skip) {
12517: if (($item ne '') && ($item !~ /\.\./)) {
12518: if (-f "$dir/$tempdir/$item") {
12519: unlink("$dir/$tempdir/$item");
12520: } elsif (-d "$dir/$tempdir/$item") {
12521: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12522: }
12523: }
12524: }
12525: foreach my $item (@to_overwrite) {
12526: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12527: if (($item ne '') && ($item !~ /\.\./)) {
12528: if (-f "$dir/$item") {
12529: unlink("$dir/$item");
12530: } elsif (-d "$dir/$item") {
12531: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12532: }
12533: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12534: }
1.1065 raeburn 12535: }
12536: }
1.1075.2.128 raeburn 12537: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12538: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12539: }
1.1065 raeburn 12540: }
12541: } else {
12542: ($decompressed,$display) =
12543: &decompress_uploaded_file($file,$dir);
12544: }
1.1055 raeburn 12545: if ($decompressed eq 'ok') {
1.1065 raeburn 12546: $output = '<p class="LC_info">'.
12547: &mt('Files extracted successfully from archive.').
12548: '</p>'."\n";
1.1055 raeburn 12549: my ($warning,$result,@contents);
12550: my ($newdirlistref,$newlisterror) =
12551: &Apache::lonnet::dirlist($currdir,$docudom,
12552: $docuname,1);
12553: my (%is_dir,%changes,@newitems);
12554: my $dirptr = 16384;
1.1065 raeburn 12555: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12556: foreach my $dir_line (@{$newdirlistref}) {
12557: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12558: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12559: push(@newitems,$item);
12560: if ($dirptr&$testdir) {
12561: $is_dir{$item} = 1;
12562: }
12563: $changes{$item} = 1;
12564: }
12565: }
12566: }
12567: if (keys(%changes) > 0) {
12568: foreach my $item (sort(@newitems)) {
12569: if ($changes{$item}) {
12570: push(@contents,$item);
12571: }
12572: }
12573: }
12574: if (@contents > 0) {
1.1067 raeburn 12575: my $wantform;
12576: unless ($env{'form.autoextract_camtasia'}) {
12577: $wantform = 1;
12578: }
1.1056 raeburn 12579: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12580: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12581: $currdir,\%is_dir,
12582: \%children,\%parent,
1.1056 raeburn 12583: \@contents,\%dirorder,
12584: \%titles,$wantform);
1.1055 raeburn 12585: if ($datatable ne '') {
12586: $output .= &archive_options_form('decompressed',$datatable,
12587: $count,$hiddenelem);
1.1065 raeburn 12588: my $startcount = 6;
1.1055 raeburn 12589: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12590: \%titles,\%children);
1.1055 raeburn 12591: }
1.1067 raeburn 12592: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12593: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12594: my %displayed;
12595: my $total = 1;
12596: $env{'form.archive_directory'} = [];
12597: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12598: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12599: $path =~ s{/$}{};
12600: my $item;
12601: if ($path ne '') {
12602: $item = "$path/$titles{$i}";
12603: } else {
12604: $item = $titles{$i};
12605: }
12606: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12607: if ($item eq $contents[0]) {
12608: push(@{$env{'form.archive_directory'}},$i);
12609: $env{'form.archive_'.$i} = 'display';
12610: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12611: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12612: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12613: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12614: $env{'form.archive_'.$i} = 'display';
12615: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12616: $displayed{'web'} = $i;
12617: } else {
1.1075.2.59 raeburn 12618: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12619: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12620: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12621: push(@{$env{'form.archive_directory'}},$i);
12622: }
12623: $env{'form.archive_'.$i} = 'dependency';
12624: }
12625: $total ++;
12626: }
12627: for (my $i=1; $i<$total; $i++) {
12628: next if ($i == $displayed{'web'});
12629: next if ($i == $displayed{'folder'});
12630: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12631: }
12632: $env{'form.phase'} = 'decompress_cleanup';
12633: $env{'form.archivedelete'} = 1;
12634: $env{'form.archive_count'} = $total-1;
12635: $output .=
12636: &process_extracted_files('coursedocs',$docudom,
12637: $docuname,$destination,
12638: $dir_root,$hiddenelem);
12639: }
1.1055 raeburn 12640: } else {
12641: $warning = &mt('No new items extracted from archive file.');
12642: }
12643: } else {
12644: $output = $display;
12645: $error = &mt('An error occurred during extraction from the archive file.');
12646: }
12647: }
12648: }
12649: }
12650: if ($error) {
12651: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12652: $error.'</p>'."\n";
12653: }
12654: if ($warning) {
12655: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12656: }
12657: return $output;
12658: }
12659:
12660: sub get_extracted {
1.1056 raeburn 12661: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12662: $titles,$wantform) = @_;
1.1055 raeburn 12663: my $count = 0;
12664: my $depth = 0;
12665: my $datatable;
1.1056 raeburn 12666: my @hierarchy;
1.1055 raeburn 12667: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12668: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12669: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12670: foreach my $item (@{$contents}) {
12671: $count ++;
1.1056 raeburn 12672: @{$dirorder->{$count}} = @hierarchy;
12673: $titles->{$count} = $item;
1.1055 raeburn 12674: &archive_hierarchy($depth,$count,$parent,$children);
12675: if ($wantform) {
12676: $datatable .= &archive_row($is_dir->{$item},$item,
12677: $currdir,$depth,$count);
12678: }
12679: if ($is_dir->{$item}) {
12680: $depth ++;
1.1056 raeburn 12681: push(@hierarchy,$count);
12682: $parent->{$depth} = $count;
1.1055 raeburn 12683: $datatable .=
12684: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12685: \$depth,\$count,\@hierarchy,$dirorder,
12686: $children,$parent,$titles,$wantform);
1.1055 raeburn 12687: $depth --;
1.1056 raeburn 12688: pop(@hierarchy);
1.1055 raeburn 12689: }
12690: }
12691: return ($count,$datatable);
12692: }
12693:
12694: sub recurse_extracted_archive {
1.1056 raeburn 12695: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12696: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12697: my $result='';
1.1056 raeburn 12698: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12699: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12700: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12701: return $result;
12702: }
12703: my $dirptr = 16384;
12704: my ($newdirlistref,$newlisterror) =
12705: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12706: if (ref($newdirlistref) eq 'ARRAY') {
12707: foreach my $dir_line (@{$newdirlistref}) {
12708: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12709: unless ($item =~ /^\.+$/) {
12710: $$count ++;
1.1056 raeburn 12711: @{$dirorder->{$$count}} = @{$hierarchy};
12712: $titles->{$$count} = $item;
1.1055 raeburn 12713: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12714:
1.1055 raeburn 12715: my $is_dir;
12716: if ($dirptr&$testdir) {
12717: $is_dir = 1;
12718: }
12719: if ($wantform) {
12720: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12721: }
12722: if ($is_dir) {
12723: $$depth ++;
1.1056 raeburn 12724: push(@{$hierarchy},$$count);
12725: $parent->{$$depth} = $$count;
1.1055 raeburn 12726: $result .=
12727: &recurse_extracted_archive("$currdir/$item",$docudom,
12728: $docuname,$depth,$count,
1.1056 raeburn 12729: $hierarchy,$dirorder,$children,
12730: $parent,$titles,$wantform);
1.1055 raeburn 12731: $$depth --;
1.1056 raeburn 12732: pop(@{$hierarchy});
1.1055 raeburn 12733: }
12734: }
12735: }
12736: }
12737: return $result;
12738: }
12739:
12740: sub archive_hierarchy {
12741: my ($depth,$count,$parent,$children) =@_;
12742: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12743: if (exists($parent->{$depth})) {
12744: $children->{$parent->{$depth}} .= $count.':';
12745: }
12746: }
12747: return;
12748: }
12749:
12750: sub archive_row {
12751: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12752: my ($name) = ($item =~ m{([^/]+)$});
12753: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12754: 'display' => 'Add as file',
1.1055 raeburn 12755: 'dependency' => 'Include as dependency',
12756: 'discard' => 'Discard',
12757: );
12758: if ($is_dir) {
1.1059 raeburn 12759: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12760: }
1.1056 raeburn 12761: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12762: my $offset = 0;
1.1055 raeburn 12763: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12764: $offset ++;
1.1065 raeburn 12765: if ($action ne 'display') {
12766: $offset ++;
12767: }
1.1055 raeburn 12768: $output .= '<td><span class="LC_nobreak">'.
12769: '<label><input type="radio" name="archive_'.$count.
12770: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12771: my $text = $choices{$action};
12772: if ($is_dir) {
12773: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12774: if ($action eq 'display') {
1.1059 raeburn 12775: $text = &mt('Add as folder');
1.1055 raeburn 12776: }
1.1056 raeburn 12777: } else {
12778: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12779:
12780: }
12781: $output .= ' /> '.$choices{$action}.'</label></span>';
12782: if ($action eq 'dependency') {
12783: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12784: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12785: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12786: '<option value=""></option>'."\n".
12787: '</select>'."\n".
12788: '</div>';
1.1059 raeburn 12789: } elsif ($action eq 'display') {
12790: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12791: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12792: '</div>';
1.1055 raeburn 12793: }
1.1056 raeburn 12794: $output .= '</td>';
1.1055 raeburn 12795: }
12796: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12797: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12798: for (my $i=0; $i<$depth; $i++) {
12799: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12800: }
12801: if ($is_dir) {
12802: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12803: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12804: } else {
12805: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12806: }
12807: $output .= ' '.$name.'</td>'."\n".
12808: &end_data_table_row();
12809: return $output;
12810: }
12811:
12812: sub archive_options_form {
1.1065 raeburn 12813: my ($form,$display,$count,$hiddenelem) = @_;
12814: my %lt = &Apache::lonlocal::texthash(
12815: perm => 'Permanently remove archive file?',
12816: hows => 'How should each extracted item be incorporated in the course?',
12817: cont => 'Content actions for all',
12818: addf => 'Add as folder/file',
12819: incd => 'Include as dependency for a displayed file',
12820: disc => 'Discard',
12821: no => 'No',
12822: yes => 'Yes',
12823: save => 'Save',
12824: );
12825: my $output = <<"END";
12826: <form name="$form" method="post" action="">
12827: <p><span class="LC_nobreak">$lt{'perm'}
12828: <label>
12829: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12830: </label>
12831:
12832: <label>
12833: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12834: </span>
12835: </p>
12836: <input type="hidden" name="phase" value="decompress_cleanup" />
12837: <br />$lt{'hows'}
12838: <div class="LC_columnSection">
12839: <fieldset>
12840: <legend>$lt{'cont'}</legend>
12841: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12842: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12843: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12844: </fieldset>
12845: </div>
12846: END
12847: return $output.
1.1055 raeburn 12848: &start_data_table()."\n".
1.1065 raeburn 12849: $display."\n".
1.1055 raeburn 12850: &end_data_table()."\n".
12851: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12852: $hiddenelem.
1.1065 raeburn 12853: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12854: '</form>';
12855: }
12856:
12857: sub archive_javascript {
1.1056 raeburn 12858: my ($startcount,$numitems,$titles,$children) = @_;
12859: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12860: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12861: my $scripttag = <<START;
12862: <script type="text/javascript">
12863: // <![CDATA[
12864:
12865: function checkAll(form,prefix) {
12866: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12867: for (var i=0; i < form.elements.length; i++) {
12868: var id = form.elements[i].id;
12869: if ((id != '') && (id != undefined)) {
12870: if (idstr.test(id)) {
12871: if (form.elements[i].type == 'radio') {
12872: form.elements[i].checked = true;
1.1056 raeburn 12873: var nostart = i-$startcount;
1.1059 raeburn 12874: var offset = nostart%7;
12875: var count = (nostart-offset)/7;
1.1056 raeburn 12876: dependencyCheck(form,count,offset);
1.1055 raeburn 12877: }
12878: }
12879: }
12880: }
12881: }
12882:
12883: function propagateCheck(form,count) {
12884: if (count > 0) {
1.1059 raeburn 12885: var startelement = $startcount + ((count-1) * 7);
12886: for (var j=1; j<6; j++) {
12887: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12888: var item = startelement + j;
12889: if (form.elements[item].type == 'radio') {
12890: if (form.elements[item].checked) {
12891: containerCheck(form,count,j);
12892: break;
12893: }
1.1055 raeburn 12894: }
12895: }
12896: }
12897: }
12898: }
12899:
12900: numitems = $numitems
1.1056 raeburn 12901: var titles = new Array(numitems);
12902: var parents = new Array(numitems);
1.1055 raeburn 12903: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12904: parents[i] = new Array;
1.1055 raeburn 12905: }
1.1059 raeburn 12906: var maintitle = '$maintitle';
1.1055 raeburn 12907:
12908: START
12909:
1.1056 raeburn 12910: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12911: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12912: for (my $i=0; $i<@contents; $i ++) {
12913: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12914: }
12915: }
12916:
1.1056 raeburn 12917: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12918: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12919: }
12920:
1.1055 raeburn 12921: $scripttag .= <<END;
12922:
12923: function containerCheck(form,count,offset) {
12924: if (count > 0) {
1.1056 raeburn 12925: dependencyCheck(form,count,offset);
1.1059 raeburn 12926: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12927: form.elements[item].checked = true;
12928: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12929: if (parents[count].length > 0) {
12930: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12931: containerCheck(form,parents[count][j],offset);
12932: }
12933: }
12934: }
12935: }
12936: }
12937:
12938: function dependencyCheck(form,count,offset) {
12939: if (count > 0) {
1.1059 raeburn 12940: var chosen = (offset+$startcount)+7*(count-1);
12941: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12942: var currtype = form.elements[depitem].type;
12943: if (form.elements[chosen].value == 'dependency') {
12944: document.getElementById('arc_depon_'+count).style.display='block';
12945: form.elements[depitem].options.length = 0;
12946: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12947: for (var i=1; i<=numitems; i++) {
12948: if (i == count) {
12949: continue;
12950: }
1.1059 raeburn 12951: var startelement = $startcount + (i-1) * 7;
12952: for (var j=1; j<6; j++) {
12953: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12954: var item = startelement + j;
12955: if (form.elements[item].type == 'radio') {
12956: if (form.elements[item].checked) {
12957: if (form.elements[item].value == 'display') {
12958: var n = form.elements[depitem].options.length;
12959: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12960: }
12961: }
12962: }
12963: }
12964: }
12965: }
12966: } else {
12967: document.getElementById('arc_depon_'+count).style.display='none';
12968: form.elements[depitem].options.length = 0;
12969: form.elements[depitem].options[0] = new Option('Select','',true,true);
12970: }
1.1059 raeburn 12971: titleCheck(form,count,offset);
1.1056 raeburn 12972: }
12973: }
12974:
12975: function propagateSelect(form,count,offset) {
12976: if (count > 0) {
1.1065 raeburn 12977: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12978: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12979: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12980: if (parents[count].length > 0) {
12981: for (var j=0; j<parents[count].length; j++) {
12982: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12983: }
12984: }
12985: }
12986: }
12987: }
1.1056 raeburn 12988:
12989: function containerSelect(form,count,offset,picked) {
12990: if (count > 0) {
1.1065 raeburn 12991: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12992: if (form.elements[item].type == 'radio') {
12993: if (form.elements[item].value == 'dependency') {
12994: if (form.elements[item+1].type == 'select-one') {
12995: for (var i=0; i<form.elements[item+1].options.length; i++) {
12996: if (form.elements[item+1].options[i].value == picked) {
12997: form.elements[item+1].selectedIndex = i;
12998: break;
12999: }
13000: }
13001: }
13002: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13003: if (parents[count].length > 0) {
13004: for (var j=0; j<parents[count].length; j++) {
13005: containerSelect(form,parents[count][j],offset,picked);
13006: }
13007: }
13008: }
13009: }
13010: }
13011: }
13012: }
13013:
1.1059 raeburn 13014: function titleCheck(form,count,offset) {
13015: if (count > 0) {
13016: var chosen = (offset+$startcount)+7*(count-1);
13017: var depitem = $startcount + ((count-1) * 7) + 2;
13018: var currtype = form.elements[depitem].type;
13019: if (form.elements[chosen].value == 'display') {
13020: document.getElementById('arc_title_'+count).style.display='block';
13021: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13022: document.getElementById('archive_title_'+count).value=maintitle;
13023: }
13024: } else {
13025: document.getElementById('arc_title_'+count).style.display='none';
13026: if (currtype == 'text') {
13027: document.getElementById('archive_title_'+count).value='';
13028: }
13029: }
13030: }
13031: return;
13032: }
13033:
1.1055 raeburn 13034: // ]]>
13035: </script>
13036: END
13037: return $scripttag;
13038: }
13039:
13040: sub process_extracted_files {
1.1067 raeburn 13041: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13042: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 13043: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13044: my @ids=&Apache::lonnet::current_machine_ids();
13045: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13046: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13047: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13048: if (grep(/^\Q$docuhome\E$/,@ids)) {
13049: $prefix = &LONCAPA::propath($docudom,$docuname);
13050: $pathtocheck = "$dir_root/$destination";
13051: $dir = $dir_root;
13052: $ishome = 1;
13053: } else {
13054: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13055: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 13056: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13057: }
13058: my $currdir = "$dir_root/$destination";
13059: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13060: if ($env{'form.folderpath'}) {
13061: my @items = split('&',$env{'form.folderpath'});
13062: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 13063: if ($env{'form.folderpath'} =~ /\:1$/) {
13064: $containers{'0'}='page';
13065: } else {
13066: $containers{'0'}='sequence';
13067: }
1.1055 raeburn 13068: }
13069: my @archdirs = &get_env_multiple('form.archive_directory');
13070: if ($numitems) {
13071: for (my $i=1; $i<=$numitems; $i++) {
13072: my $path = $env{'form.archive_content_'.$i};
13073: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13074: my $item = $1;
13075: $toplevelitems{$item} = $i;
13076: if (grep(/^\Q$i\E$/,@archdirs)) {
13077: $is_dir{$item} = 1;
13078: }
13079: }
13080: }
13081: }
1.1067 raeburn 13082: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13083: if (keys(%toplevelitems) > 0) {
13084: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13085: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13086: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13087: }
1.1066 raeburn 13088: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13089: if ($numitems) {
13090: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 13091: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13092: my $path = $env{'form.archive_content_'.$i};
13093: if ($path =~ /^\Q$pathtocheck\E/) {
13094: if ($env{'form.archive_'.$i} eq 'discard') {
13095: if ($prefix ne '' && $path ne '') {
13096: if (-e $prefix.$path) {
1.1066 raeburn 13097: if ((@archdirs > 0) &&
13098: (grep(/^\Q$i\E$/,@archdirs))) {
13099: $todeletedir{$prefix.$path} = 1;
13100: } else {
13101: $todelete{$prefix.$path} = 1;
13102: }
1.1055 raeburn 13103: }
13104: }
13105: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13106: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13107: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13108: $docstitle = $env{'form.archive_title_'.$i};
13109: if ($docstitle eq '') {
13110: $docstitle = $title;
13111: }
1.1055 raeburn 13112: $outer = 0;
1.1056 raeburn 13113: if (ref($dirorder{$i}) eq 'ARRAY') {
13114: if (@{$dirorder{$i}} > 0) {
13115: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13116: if ($env{'form.archive_'.$item} eq 'display') {
13117: $outer = $item;
13118: last;
13119: }
13120: }
13121: }
13122: }
13123: my ($errtext,$fatal) =
13124: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13125: '/'.$folders{$outer}.'.'.
13126: $containers{$outer});
13127: next if ($fatal);
13128: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13129: if ($context eq 'coursedocs') {
1.1056 raeburn 13130: $mapinner{$i} = time;
1.1055 raeburn 13131: $folders{$i} = 'default_'.$mapinner{$i};
13132: $containers{$i} = 'sequence';
13133: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13134: $folders{$i}.'.'.$containers{$i};
13135: my $newidx = &LONCAPA::map::getresidx();
13136: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13137: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13138: push(@LONCAPA::map::order,$newidx);
13139: my ($outtext,$errtext) =
13140: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13141: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 13142: '.'.$containers{$outer},1,1);
1.1056 raeburn 13143: $newseqid{$i} = $newidx;
1.1067 raeburn 13144: unless ($errtext) {
1.1075.2.128 raeburn 13145: $result .= '<li>'.&mt('Folder: [_1] added to course',
13146: &HTML::Entities::encode($docstitle,'<>&"'))..
13147: '</li>'."\n";
1.1067 raeburn 13148: }
1.1055 raeburn 13149: }
13150: } else {
13151: if ($context eq 'coursedocs') {
13152: my $newidx=&LONCAPA::map::getresidx();
13153: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13154: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13155: $title;
1.1075.2.128 raeburn 13156: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13157: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13158: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 13159: }
1.1075.2.128 raeburn 13160: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13161: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13162: }
13163: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13164: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13165: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13166: unless ($ishome) {
13167: my $fetch = "$newdest{$i}/$title";
13168: $fetch =~ s/^\Q$prefix$dir\E//;
13169: $prompttofetch{$fetch} = 1;
13170: }
13171: }
13172: }
13173: $LONCAPA::map::resources[$newidx]=
13174: $docstitle.':'.$url.':false:normal:res';
13175: push(@LONCAPA::map::order, $newidx);
13176: my ($outtext,$errtext)=
13177: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13178: $docuname.'/'.$folders{$outer}.
13179: '.'.$containers{$outer},1,1);
13180: unless ($errtext) {
13181: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13182: $result .= '<li>'.&mt('File: [_1] added to course',
13183: &HTML::Entities::encode($docstitle,'<>&"')).
13184: '</li>'."\n";
13185: }
1.1067 raeburn 13186: }
1.1075.2.128 raeburn 13187: } else {
13188: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13189: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 13190: }
1.1055 raeburn 13191: }
13192: }
1.1075.2.11 raeburn 13193: }
13194: } else {
1.1075.2.128 raeburn 13195: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13196: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 13197: }
13198: }
13199: for (my $i=1; $i<=$numitems; $i++) {
13200: next unless ($env{'form.archive_'.$i} eq 'dependency');
13201: my $path = $env{'form.archive_content_'.$i};
13202: if ($path =~ /^\Q$pathtocheck\E/) {
13203: my ($title) = ($path =~ m{/([^/]+)$});
13204: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13205: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13206: if (ref($dirorder{$i}) eq 'ARRAY') {
13207: my ($itemidx,$fullpath,$relpath);
13208: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13209: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13210: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 13211: if ($dirorder{$i}->[$j] eq $container) {
13212: $itemidx = $j;
1.1056 raeburn 13213: }
13214: }
1.1075.2.11 raeburn 13215: }
13216: if ($itemidx eq '') {
13217: $itemidx = 0;
13218: }
13219: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13220: if ($mapinner{$referrer{$i}}) {
13221: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13222: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13223: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13224: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13225: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13226: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13227: if (!-e $fullpath) {
13228: mkdir($fullpath,0755);
1.1056 raeburn 13229: }
13230: }
1.1075.2.11 raeburn 13231: } else {
13232: last;
1.1056 raeburn 13233: }
1.1075.2.11 raeburn 13234: }
13235: }
13236: } elsif ($newdest{$referrer{$i}}) {
13237: $fullpath = $newdest{$referrer{$i}};
13238: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13239: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13240: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13241: last;
13242: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13243: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13244: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13245: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13246: if (!-e $fullpath) {
13247: mkdir($fullpath,0755);
1.1056 raeburn 13248: }
13249: }
1.1075.2.11 raeburn 13250: } else {
13251: last;
1.1056 raeburn 13252: }
1.1075.2.11 raeburn 13253: }
13254: }
13255: if ($fullpath ne '') {
13256: if (-e "$prefix$path") {
1.1075.2.128 raeburn 13257: unless (rename("$prefix$path","$fullpath/$title")) {
13258: $warning .= &mt('Failed to rename dependency').'<br />';
13259: }
1.1075.2.11 raeburn 13260: }
13261: if (-e "$fullpath/$title") {
13262: my $showpath;
13263: if ($relpath ne '') {
13264: $showpath = "$relpath/$title";
13265: } else {
13266: $showpath = "/$title";
1.1056 raeburn 13267: }
1.1075.2.128 raeburn 13268: $result .= '<li>'.&mt('[_1] included as a dependency',
13269: &HTML::Entities::encode($showpath,'<>&"')).
13270: '</li>'."\n";
13271: unless ($ishome) {
13272: my $fetch = "$fullpath/$title";
13273: $fetch =~ s/^\Q$prefix$dir\E//;
13274: $prompttofetch{$fetch} = 1;
13275: }
1.1055 raeburn 13276: }
13277: }
13278: }
1.1075.2.11 raeburn 13279: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13280: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 13281: &HTML::Entities::encode($path,'<>&"'),
13282: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13283: '<br />';
1.1055 raeburn 13284: }
13285: } else {
1.1075.2.128 raeburn 13286: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13287: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13288: }
13289: }
13290: if (keys(%todelete)) {
13291: foreach my $key (keys(%todelete)) {
13292: unlink($key);
1.1066 raeburn 13293: }
13294: }
13295: if (keys(%todeletedir)) {
13296: foreach my $key (keys(%todeletedir)) {
13297: rmdir($key);
13298: }
13299: }
13300: foreach my $dir (sort(keys(%is_dir))) {
13301: if (($pathtocheck ne '') && ($dir ne '')) {
13302: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13303: }
13304: }
1.1067 raeburn 13305: if ($result ne '') {
13306: $output .= '<ul>'."\n".
13307: $result."\n".
13308: '</ul>';
13309: }
13310: unless ($ishome) {
13311: my $replicationfail;
13312: foreach my $item (keys(%prompttofetch)) {
13313: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13314: unless ($fetchresult eq 'ok') {
13315: $replicationfail .= '<li>'.$item.'</li>'."\n";
13316: }
13317: }
13318: if ($replicationfail) {
13319: $output .= '<p class="LC_error">'.
13320: &mt('Course home server failed to retrieve:').'<ul>'.
13321: $replicationfail.
13322: '</ul></p>';
13323: }
13324: }
1.1055 raeburn 13325: } else {
13326: $warning = &mt('No items found in archive.');
13327: }
13328: if ($error) {
13329: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13330: $error.'</p>'."\n";
13331: }
13332: if ($warning) {
13333: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13334: }
13335: return $output;
13336: }
13337:
1.1066 raeburn 13338: sub cleanup_empty_dirs {
13339: my ($path) = @_;
13340: if (($path ne '') && (-d $path)) {
13341: if (opendir(my $dirh,$path)) {
13342: my @dircontents = grep(!/^\./,readdir($dirh));
13343: my $numitems = 0;
13344: foreach my $item (@dircontents) {
13345: if (-d "$path/$item") {
1.1075.2.28 raeburn 13346: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13347: if (-e "$path/$item") {
13348: $numitems ++;
13349: }
13350: } else {
13351: $numitems ++;
13352: }
13353: }
13354: if ($numitems == 0) {
13355: rmdir($path);
13356: }
13357: closedir($dirh);
13358: }
13359: }
13360: return;
13361: }
13362:
1.41 ng 13363: =pod
1.45 matthew 13364:
1.1075.2.56 raeburn 13365: =item * &get_folder_hierarchy()
1.1068 raeburn 13366:
13367: Provides hierarchy of names of folders/sub-folders containing the current
13368: item,
13369:
13370: Inputs: 3
13371: - $navmap - navmaps object
13372:
13373: - $map - url for map (either the trigger itself, or map containing
13374: the resource, which is the trigger).
13375:
13376: - $showitem - 1 => show title for map itself; 0 => do not show.
13377:
13378: Outputs: 1 @pathitems - array of folder/subfolder names.
13379:
13380: =cut
13381:
13382: sub get_folder_hierarchy {
13383: my ($navmap,$map,$showitem) = @_;
13384: my @pathitems;
13385: if (ref($navmap)) {
13386: my $mapres = $navmap->getResourceByUrl($map);
13387: if (ref($mapres)) {
13388: my $pcslist = $mapres->map_hierarchy();
13389: if ($pcslist ne '') {
13390: my @pcs = split(/,/,$pcslist);
13391: foreach my $pc (@pcs) {
13392: if ($pc == 1) {
1.1075.2.38 raeburn 13393: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13394: } else {
13395: my $res = $navmap->getByMapPc($pc);
13396: if (ref($res)) {
13397: my $title = $res->compTitle();
13398: $title =~ s/\W+/_/g;
13399: if ($title ne '') {
13400: push(@pathitems,$title);
13401: }
13402: }
13403: }
13404: }
13405: }
1.1071 raeburn 13406: if ($showitem) {
13407: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13408: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13409: } else {
13410: my $maptitle = $mapres->compTitle();
13411: $maptitle =~ s/\W+/_/g;
13412: if ($maptitle ne '') {
13413: push(@pathitems,$maptitle);
13414: }
1.1068 raeburn 13415: }
13416: }
13417: }
13418: }
13419: return @pathitems;
13420: }
13421:
13422: =pod
13423:
1.1015 raeburn 13424: =item * &get_turnedin_filepath()
13425:
13426: Determines path in a user's portfolio file for storage of files uploaded
13427: to a specific essayresponse or dropbox item.
13428:
13429: Inputs: 3 required + 1 optional.
13430: $symb is symb for resource, $uname and $udom are for current user (required).
13431: $caller is optional (can be "submission", if routine is called when storing
13432: an upoaded file when "Submit Answer" button was pressed).
13433:
13434: Returns array containing $path and $multiresp.
13435: $path is path in portfolio. $multiresp is 1 if this resource contains more
13436: than one file upload item. Callers of routine should append partid as a
13437: subdirectory to $path in cases where $multiresp is 1.
13438:
13439: Called by: homework/essayresponse.pm and homework/structuretags.pm
13440:
13441: =cut
13442:
13443: sub get_turnedin_filepath {
13444: my ($symb,$uname,$udom,$caller) = @_;
13445: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13446: my $turnindir;
13447: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13448: $turnindir = $userhash{'turnindir'};
13449: my ($path,$multiresp);
13450: if ($turnindir eq '') {
13451: if ($caller eq 'submission') {
13452: $turnindir = &mt('turned in');
13453: $turnindir =~ s/\W+/_/g;
13454: my %newhash = (
13455: 'turnindir' => $turnindir,
13456: );
13457: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13458: }
13459: }
13460: if ($turnindir ne '') {
13461: $path = '/'.$turnindir.'/';
13462: my ($multipart,$turnin,@pathitems);
13463: my $navmap = Apache::lonnavmaps::navmap->new();
13464: if (defined($navmap)) {
13465: my $mapres = $navmap->getResourceByUrl($map);
13466: if (ref($mapres)) {
13467: my $pcslist = $mapres->map_hierarchy();
13468: if ($pcslist ne '') {
13469: foreach my $pc (split(/,/,$pcslist)) {
13470: my $res = $navmap->getByMapPc($pc);
13471: if (ref($res)) {
13472: my $title = $res->compTitle();
13473: $title =~ s/\W+/_/g;
13474: if ($title ne '') {
1.1075.2.48 raeburn 13475: if (($pc > 1) && (length($title) > 12)) {
13476: $title = substr($title,0,12);
13477: }
1.1015 raeburn 13478: push(@pathitems,$title);
13479: }
13480: }
13481: }
13482: }
13483: my $maptitle = $mapres->compTitle();
13484: $maptitle =~ s/\W+/_/g;
13485: if ($maptitle ne '') {
1.1075.2.48 raeburn 13486: if (length($maptitle) > 12) {
13487: $maptitle = substr($maptitle,0,12);
13488: }
1.1015 raeburn 13489: push(@pathitems,$maptitle);
13490: }
13491: unless ($env{'request.state'} eq 'construct') {
13492: my $res = $navmap->getBySymb($symb);
13493: if (ref($res)) {
13494: my $partlist = $res->parts();
13495: my $totaluploads = 0;
13496: if (ref($partlist) eq 'ARRAY') {
13497: foreach my $part (@{$partlist}) {
13498: my @types = $res->responseType($part);
13499: my @ids = $res->responseIds($part);
13500: for (my $i=0; $i < scalar(@ids); $i++) {
13501: if ($types[$i] eq 'essay') {
13502: my $partid = $part.'_'.$ids[$i];
13503: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13504: $totaluploads ++;
13505: }
13506: }
13507: }
13508: }
13509: if ($totaluploads > 1) {
13510: $multiresp = 1;
13511: }
13512: }
13513: }
13514: }
13515: } else {
13516: return;
13517: }
13518: } else {
13519: return;
13520: }
13521: my $restitle=&Apache::lonnet::gettitle($symb);
13522: $restitle =~ s/\W+/_/g;
13523: if ($restitle eq '') {
13524: $restitle = ($resurl =~ m{/[^/]+$});
13525: if ($restitle eq '') {
13526: $restitle = time;
13527: }
13528: }
1.1075.2.48 raeburn 13529: if (length($restitle) > 12) {
13530: $restitle = substr($restitle,0,12);
13531: }
1.1015 raeburn 13532: push(@pathitems,$restitle);
13533: $path .= join('/',@pathitems);
13534: }
13535: return ($path,$multiresp);
13536: }
13537:
13538: =pod
13539:
1.464 albertel 13540: =back
1.41 ng 13541:
1.112 bowersj2 13542: =head1 CSV Upload/Handling functions
1.38 albertel 13543:
1.41 ng 13544: =over 4
13545:
1.648 raeburn 13546: =item * &upfile_store($r)
1.41 ng 13547:
13548: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13549: needs $env{'form.upfile'}
1.41 ng 13550: returns $datatoken to be put into hidden field
13551:
13552: =cut
1.31 albertel 13553:
13554: sub upfile_store {
13555: my $r=shift;
1.258 albertel 13556: $env{'form.upfile'}=~s/\r/\n/gs;
13557: $env{'form.upfile'}=~s/\f/\n/gs;
13558: $env{'form.upfile'}=~s/\n+/\n/gs;
13559: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13560:
1.1075.2.128 raeburn 13561: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13562: '_enroll_'.$env{'request.course.id'}.'_'.
13563: time.'_'.$$);
13564: return if ($datatoken eq '');
13565:
1.31 albertel 13566: {
1.158 raeburn 13567: my $datafile = $r->dir_config('lonDaemons').
13568: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13569: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13570: print $fh $env{'form.upfile'};
1.158 raeburn 13571: close($fh);
13572: }
1.31 albertel 13573: }
13574: return $datatoken;
13575: }
13576:
1.56 matthew 13577: =pod
13578:
1.1075.2.128 raeburn 13579: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13580:
13581: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13582: $datatoken is the name to assign to the temporary file.
1.258 albertel 13583: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13584:
13585: =cut
1.31 albertel 13586:
13587: sub load_tmp_file {
1.1075.2.128 raeburn 13588: my ($r,$datatoken) = @_;
13589: return if ($datatoken eq '');
1.31 albertel 13590: my @studentdata=();
13591: {
1.158 raeburn 13592: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13593: '/tmp/'.$datatoken.'.tmp';
13594: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13595: @studentdata=<$fh>;
13596: close($fh);
13597: }
1.31 albertel 13598: }
1.258 albertel 13599: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13600: }
13601:
1.1075.2.128 raeburn 13602: sub valid_datatoken {
13603: my ($datatoken) = @_;
1.1075.2.131 raeburn 13604: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13605: return $datatoken;
13606: }
13607: return;
13608: }
13609:
1.56 matthew 13610: =pod
13611:
1.648 raeburn 13612: =item * &upfile_record_sep()
1.41 ng 13613:
13614: Separate uploaded file into records
13615: returns array of records,
1.258 albertel 13616: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13617:
13618: =cut
1.31 albertel 13619:
13620: sub upfile_record_sep {
1.258 albertel 13621: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13622: } else {
1.248 albertel 13623: my @records;
1.258 albertel 13624: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13625: if ($line=~/^\s*$/) { next; }
13626: push(@records,$line);
13627: }
13628: return @records;
1.31 albertel 13629: }
13630: }
13631:
1.56 matthew 13632: =pod
13633:
1.648 raeburn 13634: =item * &record_sep($record)
1.41 ng 13635:
1.258 albertel 13636: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13637:
13638: =cut
13639:
1.263 www 13640: sub takeleft {
13641: my $index=shift;
13642: return substr('0000'.$index,-4,4);
13643: }
13644:
1.31 albertel 13645: sub record_sep {
13646: my $record=shift;
13647: my %components=();
1.258 albertel 13648: if ($env{'form.upfiletype'} eq 'xml') {
13649: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13650: my $i=0;
1.356 albertel 13651: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13652: $field=~s/^(\"|\')//;
13653: $field=~s/(\"|\')$//;
1.263 www 13654: $components{&takeleft($i)}=$field;
1.31 albertel 13655: $i++;
13656: }
1.258 albertel 13657: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13658: my $i=0;
1.356 albertel 13659: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13660: $field=~s/^(\"|\')//;
13661: $field=~s/(\"|\')$//;
1.263 www 13662: $components{&takeleft($i)}=$field;
1.31 albertel 13663: $i++;
13664: }
13665: } else {
1.561 www 13666: my $separator=',';
1.480 banghart 13667: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13668: $separator=';';
1.480 banghart 13669: }
1.31 albertel 13670: my $i=0;
1.561 www 13671: # the character we are looking for to indicate the end of a quote or a record
13672: my $looking_for=$separator;
13673: # do not add the characters to the fields
13674: my $ignore=0;
13675: # we just encountered a separator (or the beginning of the record)
13676: my $just_found_separator=1;
13677: # store the field we are working on here
13678: my $field='';
13679: # work our way through all characters in record
13680: foreach my $character ($record=~/(.)/g) {
13681: if ($character eq $looking_for) {
13682: if ($character ne $separator) {
13683: # Found the end of a quote, again looking for separator
13684: $looking_for=$separator;
13685: $ignore=1;
13686: } else {
13687: # Found a separator, store away what we got
13688: $components{&takeleft($i)}=$field;
13689: $i++;
13690: $just_found_separator=1;
13691: $ignore=0;
13692: $field='';
13693: }
13694: next;
13695: }
13696: # single or double quotation marks after a separator indicate beginning of a quote
13697: # we are now looking for the end of the quote and need to ignore separators
13698: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13699: $looking_for=$character;
13700: next;
13701: }
13702: # ignore would be true after we reached the end of a quote
13703: if ($ignore) { next; }
13704: if (($just_found_separator) && ($character=~/\s/)) { next; }
13705: $field.=$character;
13706: $just_found_separator=0;
1.31 albertel 13707: }
1.561 www 13708: # catch the very last entry, since we never encountered the separator
13709: $components{&takeleft($i)}=$field;
1.31 albertel 13710: }
13711: return %components;
13712: }
13713:
1.144 matthew 13714: ######################################################
13715: ######################################################
13716:
1.56 matthew 13717: =pod
13718:
1.648 raeburn 13719: =item * &upfile_select_html()
1.41 ng 13720:
1.144 matthew 13721: Return HTML code to select a file from the users machine and specify
13722: the file type.
1.41 ng 13723:
13724: =cut
13725:
1.144 matthew 13726: ######################################################
13727: ######################################################
1.31 albertel 13728: sub upfile_select_html {
1.144 matthew 13729: my %Types = (
13730: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13731: semisv => &mt('Semicolon separated values'),
1.144 matthew 13732: space => &mt('Space separated'),
13733: tab => &mt('Tabulator separated'),
13734: # xml => &mt('HTML/XML'),
13735: );
13736: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13737: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13738: foreach my $type (sort(keys(%Types))) {
13739: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13740: }
13741: $Str .= "</select>\n";
13742: return $Str;
1.31 albertel 13743: }
13744:
1.301 albertel 13745: sub get_samples {
13746: my ($records,$toget) = @_;
13747: my @samples=({});
13748: my $got=0;
13749: foreach my $rec (@$records) {
13750: my %temp = &record_sep($rec);
13751: if (! grep(/\S/, values(%temp))) { next; }
13752: if (%temp) {
13753: $samples[$got]=\%temp;
13754: $got++;
13755: if ($got == $toget) { last; }
13756: }
13757: }
13758: return \@samples;
13759: }
13760:
1.144 matthew 13761: ######################################################
13762: ######################################################
13763:
1.56 matthew 13764: =pod
13765:
1.648 raeburn 13766: =item * &csv_print_samples($r,$records)
1.41 ng 13767:
13768: Prints a table of sample values from each column uploaded $r is an
13769: Apache Request ref, $records is an arrayref from
13770: &Apache::loncommon::upfile_record_sep
13771:
13772: =cut
13773:
1.144 matthew 13774: ######################################################
13775: ######################################################
1.31 albertel 13776: sub csv_print_samples {
13777: my ($r,$records) = @_;
1.662 bisitz 13778: my $samples = &get_samples($records,5);
1.301 albertel 13779:
1.594 raeburn 13780: $r->print(&mt('Samples').'<br />'.&start_data_table().
13781: &start_data_table_header_row());
1.356 albertel 13782: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13783: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13784: $r->print(&end_data_table_header_row());
1.301 albertel 13785: foreach my $hash (@$samples) {
1.594 raeburn 13786: $r->print(&start_data_table_row());
1.356 albertel 13787: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13788: $r->print('<td>');
1.356 albertel 13789: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13790: $r->print('</td>');
13791: }
1.594 raeburn 13792: $r->print(&end_data_table_row());
1.31 albertel 13793: }
1.594 raeburn 13794: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13795: }
13796:
1.144 matthew 13797: ######################################################
13798: ######################################################
13799:
1.56 matthew 13800: =pod
13801:
1.648 raeburn 13802: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13803:
13804: Prints a table to create associations between values and table columns.
1.144 matthew 13805:
1.41 ng 13806: $r is an Apache Request ref,
13807: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13808: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13809:
13810: =cut
13811:
1.144 matthew 13812: ######################################################
13813: ######################################################
1.31 albertel 13814: sub csv_print_select_table {
13815: my ($r,$records,$d) = @_;
1.301 albertel 13816: my $i=0;
13817: my $samples = &get_samples($records,1);
1.144 matthew 13818: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13819: &start_data_table().&start_data_table_header_row().
1.144 matthew 13820: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13821: '<th>'.&mt('Column').'</th>'.
13822: &end_data_table_header_row()."\n");
1.356 albertel 13823: foreach my $array_ref (@$d) {
13824: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13825: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13826:
1.875 bisitz 13827: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13828: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13829: $r->print('<option value="none"></option>');
1.356 albertel 13830: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13831: $r->print('<option value="'.$sample.'"'.
13832: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13833: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13834: }
1.594 raeburn 13835: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13836: $i++;
13837: }
1.594 raeburn 13838: $r->print(&end_data_table());
1.31 albertel 13839: $i--;
13840: return $i;
13841: }
1.56 matthew 13842:
1.144 matthew 13843: ######################################################
13844: ######################################################
13845:
1.56 matthew 13846: =pod
1.31 albertel 13847:
1.648 raeburn 13848: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13849:
13850: Prints a table of sample values from the upload and can make associate samples to internal names.
13851:
13852: $r is an Apache Request ref,
13853: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13854: $d is an array of 2 element arrays (internal name, displayed name)
13855:
13856: =cut
13857:
1.144 matthew 13858: ######################################################
13859: ######################################################
1.31 albertel 13860: sub csv_samples_select_table {
13861: my ($r,$records,$d) = @_;
13862: my $i=0;
1.144 matthew 13863: #
1.662 bisitz 13864: my $max_samples = 5;
13865: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13866: $r->print(&start_data_table().
13867: &start_data_table_header_row().'<th>'.
13868: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13869: &end_data_table_header_row());
1.301 albertel 13870:
13871: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13872: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13873: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13874: foreach my $option (@$d) {
13875: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13876: $r->print('<option value="'.$value.'"'.
1.253 albertel 13877: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13878: $display.'</option>');
1.31 albertel 13879: }
13880: $r->print('</select></td><td>');
1.662 bisitz 13881: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13882: if (defined($samples->[$line]{$key})) {
13883: $r->print($samples->[$line]{$key}."<br />\n");
13884: }
13885: }
1.594 raeburn 13886: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13887: $i++;
13888: }
1.594 raeburn 13889: $r->print(&end_data_table());
1.31 albertel 13890: $i--;
13891: return($i);
1.115 matthew 13892: }
13893:
1.144 matthew 13894: ######################################################
13895: ######################################################
13896:
1.115 matthew 13897: =pod
13898:
1.648 raeburn 13899: =item * &clean_excel_name($name)
1.115 matthew 13900:
13901: Returns a replacement for $name which does not contain any illegal characters.
13902:
13903: =cut
13904:
1.144 matthew 13905: ######################################################
13906: ######################################################
1.115 matthew 13907: sub clean_excel_name {
13908: my ($name) = @_;
13909: $name =~ s/[:\*\?\/\\]//g;
13910: if (length($name) > 31) {
13911: $name = substr($name,0,31);
13912: }
13913: return $name;
1.25 albertel 13914: }
1.84 albertel 13915:
1.85 albertel 13916: =pod
13917:
1.648 raeburn 13918: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13919:
13920: Returns either 1 or undef
13921:
13922: 1 if the part is to be hidden, undef if it is to be shown
13923:
13924: Arguments are:
13925:
13926: $id the id of the part to be checked
13927: $symb, optional the symb of the resource to check
13928: $udom, optional the domain of the user to check for
13929: $uname, optional the username of the user to check for
13930:
13931: =cut
1.84 albertel 13932:
13933: sub check_if_partid_hidden {
13934: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13935: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13936: $symb,$udom,$uname);
1.141 albertel 13937: my $truth=1;
13938: #if the string starts with !, then the list is the list to show not hide
13939: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13940: my @hiddenlist=split(/,/,$hiddenparts);
13941: foreach my $checkid (@hiddenlist) {
1.141 albertel 13942: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13943: }
1.141 albertel 13944: return !$truth;
1.84 albertel 13945: }
1.127 matthew 13946:
1.138 matthew 13947:
13948: ############################################################
13949: ############################################################
13950:
13951: =pod
13952:
1.157 matthew 13953: =back
13954:
1.138 matthew 13955: =head1 cgi-bin script and graphing routines
13956:
1.157 matthew 13957: =over 4
13958:
1.648 raeburn 13959: =item * &get_cgi_id()
1.138 matthew 13960:
13961: Inputs: none
13962:
13963: Returns an id which can be used to pass environment variables
13964: to various cgi-bin scripts. These environment variables will
13965: be removed from the users environment after a given time by
13966: the routine &Apache::lonnet::transfer_profile_to_env.
13967:
13968: =cut
13969:
13970: ############################################################
13971: ############################################################
1.152 albertel 13972: my $uniq=0;
1.136 matthew 13973: sub get_cgi_id {
1.154 albertel 13974: $uniq=($uniq+1)%100000;
1.280 albertel 13975: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13976: }
13977:
1.127 matthew 13978: ############################################################
13979: ############################################################
13980:
13981: =pod
13982:
1.648 raeburn 13983: =item * &DrawBarGraph()
1.127 matthew 13984:
1.138 matthew 13985: Facilitates the plotting of data in a (stacked) bar graph.
13986: Puts plot definition data into the users environment in order for
13987: graph.png to plot it. Returns an <img> tag for the plot.
13988: The bars on the plot are labeled '1','2',...,'n'.
13989:
13990: Inputs:
13991:
13992: =over 4
13993:
13994: =item $Title: string, the title of the plot
13995:
13996: =item $xlabel: string, text describing the X-axis of the plot
13997:
13998: =item $ylabel: string, text describing the Y-axis of the plot
13999:
14000: =item $Max: scalar, the maximum Y value to use in the plot
14001: If $Max is < any data point, the graph will not be rendered.
14002:
1.140 matthew 14003: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14004: they are plotted. If undefined, default values will be used.
14005:
1.178 matthew 14006: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14007:
1.138 matthew 14008: =item @Values: An array of array references. Each array reference holds data
14009: to be plotted in a stacked bar chart.
14010:
1.239 matthew 14011: =item If the final element of @Values is a hash reference the key/value
14012: pairs will be added to the graph definition.
14013:
1.138 matthew 14014: =back
14015:
14016: Returns:
14017:
14018: An <img> tag which references graph.png and the appropriate identifying
14019: information for the plot.
14020:
1.127 matthew 14021: =cut
14022:
14023: ############################################################
14024: ############################################################
1.134 matthew 14025: sub DrawBarGraph {
1.178 matthew 14026: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14027: #
14028: if (! defined($colors)) {
14029: $colors = ['#33ff00',
14030: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14031: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14032: ];
14033: }
1.228 matthew 14034: my $extra_settings = {};
14035: if (ref($Values[-1]) eq 'HASH') {
14036: $extra_settings = pop(@Values);
14037: }
1.127 matthew 14038: #
1.136 matthew 14039: my $identifier = &get_cgi_id();
14040: my $id = 'cgi.'.$identifier;
1.129 matthew 14041: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14042: return '';
14043: }
1.225 matthew 14044: #
14045: my @Labels;
14046: if (defined($labels)) {
14047: @Labels = @$labels;
14048: } else {
14049: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 14050: push(@Labels,$i+1);
1.225 matthew 14051: }
14052: }
14053: #
1.129 matthew 14054: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14055: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14056: my %ValuesHash;
14057: my $NumSets=1;
14058: foreach my $array (@Values) {
14059: next if (! ref($array));
1.136 matthew 14060: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14061: join(',',@$array);
1.129 matthew 14062: }
1.127 matthew 14063: #
1.136 matthew 14064: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14065: if ($NumBars < 3) {
14066: $width = 120+$NumBars*32;
1.220 matthew 14067: $xskip = 1;
1.225 matthew 14068: $bar_width = 30;
14069: } elsif ($NumBars < 5) {
14070: $width = 120+$NumBars*20;
14071: $xskip = 1;
14072: $bar_width = 20;
1.220 matthew 14073: } elsif ($NumBars < 10) {
1.136 matthew 14074: $width = 120+$NumBars*15;
14075: $xskip = 1;
14076: $bar_width = 15;
14077: } elsif ($NumBars <= 25) {
14078: $width = 120+$NumBars*11;
14079: $xskip = 5;
14080: $bar_width = 8;
14081: } elsif ($NumBars <= 50) {
14082: $width = 120+$NumBars*8;
14083: $xskip = 5;
14084: $bar_width = 4;
14085: } else {
14086: $width = 120+$NumBars*8;
14087: $xskip = 5;
14088: $bar_width = 4;
14089: }
14090: #
1.137 matthew 14091: $Max = 1 if ($Max < 1);
14092: if ( int($Max) < $Max ) {
14093: $Max++;
14094: $Max = int($Max);
14095: }
1.127 matthew 14096: $Title = '' if (! defined($Title));
14097: $xlabel = '' if (! defined($xlabel));
14098: $ylabel = '' if (! defined($ylabel));
1.369 www 14099: $ValuesHash{$id.'.title'} = &escape($Title);
14100: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14101: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14102: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14103: $ValuesHash{$id.'.NumBars'} = $NumBars;
14104: $ValuesHash{$id.'.NumSets'} = $NumSets;
14105: $ValuesHash{$id.'.PlotType'} = 'bar';
14106: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14107: $ValuesHash{$id.'.height'} = $height;
14108: $ValuesHash{$id.'.width'} = $width;
14109: $ValuesHash{$id.'.xskip'} = $xskip;
14110: $ValuesHash{$id.'.bar_width'} = $bar_width;
14111: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14112: #
1.228 matthew 14113: # Deal with other parameters
14114: while (my ($key,$value) = each(%$extra_settings)) {
14115: $ValuesHash{$id.'.'.$key} = $value;
14116: }
14117: #
1.646 raeburn 14118: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14119: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14120: }
14121:
14122: ############################################################
14123: ############################################################
14124:
14125: =pod
14126:
1.648 raeburn 14127: =item * &DrawXYGraph()
1.137 matthew 14128:
1.138 matthew 14129: Facilitates the plotting of data in an XY graph.
14130: Puts plot definition data into the users environment in order for
14131: graph.png to plot it. Returns an <img> tag for the plot.
14132:
14133: Inputs:
14134:
14135: =over 4
14136:
14137: =item $Title: string, the title of the plot
14138:
14139: =item $xlabel: string, text describing the X-axis of the plot
14140:
14141: =item $ylabel: string, text describing the Y-axis of the plot
14142:
14143: =item $Max: scalar, the maximum Y value to use in the plot
14144: If $Max is < any data point, the graph will not be rendered.
14145:
14146: =item $colors: Array ref containing the hex color codes for the data to be
14147: plotted in. If undefined, default values will be used.
14148:
14149: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14150:
14151: =item $Ydata: Array ref containing Array refs.
1.185 www 14152: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14153:
14154: =item %Values: hash indicating or overriding any default values which are
14155: passed to graph.png.
14156: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14157:
14158: =back
14159:
14160: Returns:
14161:
14162: An <img> tag which references graph.png and the appropriate identifying
14163: information for the plot.
14164:
1.137 matthew 14165: =cut
14166:
14167: ############################################################
14168: ############################################################
14169: sub DrawXYGraph {
14170: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14171: #
14172: # Create the identifier for the graph
14173: my $identifier = &get_cgi_id();
14174: my $id = 'cgi.'.$identifier;
14175: #
14176: $Title = '' if (! defined($Title));
14177: $xlabel = '' if (! defined($xlabel));
14178: $ylabel = '' if (! defined($ylabel));
14179: my %ValuesHash =
14180: (
1.369 www 14181: $id.'.title' => &escape($Title),
14182: $id.'.xlabel' => &escape($xlabel),
14183: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14184: $id.'.y_max_value'=> $Max,
14185: $id.'.labels' => join(',',@$Xlabels),
14186: $id.'.PlotType' => 'XY',
14187: );
14188: #
14189: if (defined($colors) && ref($colors) eq 'ARRAY') {
14190: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14191: }
14192: #
14193: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14194: return '';
14195: }
14196: my $NumSets=1;
1.138 matthew 14197: foreach my $array (@{$Ydata}){
1.137 matthew 14198: next if (! ref($array));
14199: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14200: }
1.138 matthew 14201: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14202: #
14203: # Deal with other parameters
14204: while (my ($key,$value) = each(%Values)) {
14205: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14206: }
14207: #
1.646 raeburn 14208: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14209: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14210: }
14211:
14212: ############################################################
14213: ############################################################
14214:
14215: =pod
14216:
1.648 raeburn 14217: =item * &DrawXYYGraph()
1.138 matthew 14218:
14219: Facilitates the plotting of data in an XY graph with two Y axes.
14220: Puts plot definition data into the users environment in order for
14221: graph.png to plot it. Returns an <img> tag for the plot.
14222:
14223: Inputs:
14224:
14225: =over 4
14226:
14227: =item $Title: string, the title of the plot
14228:
14229: =item $xlabel: string, text describing the X-axis of the plot
14230:
14231: =item $ylabel: string, text describing the Y-axis of the plot
14232:
14233: =item $colors: Array ref containing the hex color codes for the data to be
14234: plotted in. If undefined, default values will be used.
14235:
14236: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14237:
14238: =item $Ydata1: The first data set
14239:
14240: =item $Min1: The minimum value of the left Y-axis
14241:
14242: =item $Max1: The maximum value of the left Y-axis
14243:
14244: =item $Ydata2: The second data set
14245:
14246: =item $Min2: The minimum value of the right Y-axis
14247:
14248: =item $Max2: The maximum value of the left Y-axis
14249:
14250: =item %Values: hash indicating or overriding any default values which are
14251: passed to graph.png.
14252: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14253:
14254: =back
14255:
14256: Returns:
14257:
14258: An <img> tag which references graph.png and the appropriate identifying
14259: information for the plot.
1.136 matthew 14260:
14261: =cut
14262:
14263: ############################################################
14264: ############################################################
1.137 matthew 14265: sub DrawXYYGraph {
14266: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14267: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14268: #
14269: # Create the identifier for the graph
14270: my $identifier = &get_cgi_id();
14271: my $id = 'cgi.'.$identifier;
14272: #
14273: $Title = '' if (! defined($Title));
14274: $xlabel = '' if (! defined($xlabel));
14275: $ylabel = '' if (! defined($ylabel));
14276: my %ValuesHash =
14277: (
1.369 www 14278: $id.'.title' => &escape($Title),
14279: $id.'.xlabel' => &escape($xlabel),
14280: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14281: $id.'.labels' => join(',',@$Xlabels),
14282: $id.'.PlotType' => 'XY',
14283: $id.'.NumSets' => 2,
1.137 matthew 14284: $id.'.two_axes' => 1,
14285: $id.'.y1_max_value' => $Max1,
14286: $id.'.y1_min_value' => $Min1,
14287: $id.'.y2_max_value' => $Max2,
14288: $id.'.y2_min_value' => $Min2,
1.136 matthew 14289: );
14290: #
1.137 matthew 14291: if (defined($colors) && ref($colors) eq 'ARRAY') {
14292: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14293: }
14294: #
14295: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14296: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14297: return '';
14298: }
14299: my $NumSets=1;
1.137 matthew 14300: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14301: next if (! ref($array));
14302: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14303: }
14304: #
14305: # Deal with other parameters
14306: while (my ($key,$value) = each(%Values)) {
14307: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14308: }
14309: #
1.646 raeburn 14310: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14311: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14312: }
14313:
14314: ############################################################
14315: ############################################################
14316:
14317: =pod
14318:
1.157 matthew 14319: =back
14320:
1.139 matthew 14321: =head1 Statistics helper routines?
14322:
14323: Bad place for them but what the hell.
14324:
1.157 matthew 14325: =over 4
14326:
1.648 raeburn 14327: =item * &chartlink()
1.139 matthew 14328:
14329: Returns a link to the chart for a specific student.
14330:
14331: Inputs:
14332:
14333: =over 4
14334:
14335: =item $linktext: The text of the link
14336:
14337: =item $sname: The students username
14338:
14339: =item $sdomain: The students domain
14340:
14341: =back
14342:
1.157 matthew 14343: =back
14344:
1.139 matthew 14345: =cut
14346:
14347: ############################################################
14348: ############################################################
14349: sub chartlink {
14350: my ($linktext, $sname, $sdomain) = @_;
14351: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14352: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14353: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14354: '">'.$linktext.'</a>';
1.153 matthew 14355: }
14356:
14357: #######################################################
14358: #######################################################
14359:
14360: =pod
14361:
14362: =head1 Course Environment Routines
1.157 matthew 14363:
14364: =over 4
1.153 matthew 14365:
1.648 raeburn 14366: =item * &restore_course_settings()
1.153 matthew 14367:
1.648 raeburn 14368: =item * &store_course_settings()
1.153 matthew 14369:
14370: Restores/Store indicated form parameters from the course environment.
14371: Will not overwrite existing values of the form parameters.
14372:
14373: Inputs:
14374: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14375:
14376: a hash ref describing the data to be stored. For example:
14377:
14378: %Save_Parameters = ('Status' => 'scalar',
14379: 'chartoutputmode' => 'scalar',
14380: 'chartoutputdata' => 'scalar',
14381: 'Section' => 'array',
1.373 raeburn 14382: 'Group' => 'array',
1.153 matthew 14383: 'StudentData' => 'array',
14384: 'Maps' => 'array');
14385:
14386: Returns: both routines return nothing
14387:
1.631 raeburn 14388: =back
14389:
1.153 matthew 14390: =cut
14391:
14392: #######################################################
14393: #######################################################
14394: sub store_course_settings {
1.496 albertel 14395: return &store_settings($env{'request.course.id'},@_);
14396: }
14397:
14398: sub store_settings {
1.153 matthew 14399: # save to the environment
14400: # appenv the same items, just to be safe
1.300 albertel 14401: my $udom = $env{'user.domain'};
14402: my $uname = $env{'user.name'};
1.496 albertel 14403: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14404: my %SaveHash;
14405: my %AppHash;
14406: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14407: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14408: my $envname = 'environment.'.$basename;
1.258 albertel 14409: if (exists($env{'form.'.$setting})) {
1.153 matthew 14410: # Save this value away
14411: if ($type eq 'scalar' &&
1.258 albertel 14412: (! exists($env{$envname}) ||
14413: $env{$envname} ne $env{'form.'.$setting})) {
14414: $SaveHash{$basename} = $env{'form.'.$setting};
14415: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14416: } elsif ($type eq 'array') {
14417: my $stored_form;
1.258 albertel 14418: if (ref($env{'form.'.$setting})) {
1.153 matthew 14419: $stored_form = join(',',
14420: map {
1.369 www 14421: &escape($_);
1.258 albertel 14422: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14423: } else {
14424: $stored_form =
1.369 www 14425: &escape($env{'form.'.$setting});
1.153 matthew 14426: }
14427: # Determine if the array contents are the same.
1.258 albertel 14428: if ($stored_form ne $env{$envname}) {
1.153 matthew 14429: $SaveHash{$basename} = $stored_form;
14430: $AppHash{$envname} = $stored_form;
14431: }
14432: }
14433: }
14434: }
14435: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14436: $udom,$uname);
1.153 matthew 14437: if ($put_result !~ /^(ok|delayed)/) {
14438: &Apache::lonnet::logthis('unable to save form parameters, '.
14439: 'got error:'.$put_result);
14440: }
14441: # Make sure these settings stick around in this session, too
1.646 raeburn 14442: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14443: return;
14444: }
14445:
14446: sub restore_course_settings {
1.499 albertel 14447: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14448: }
14449:
14450: sub restore_settings {
14451: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14452: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14453: next if (exists($env{'form.'.$setting}));
1.496 albertel 14454: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14455: '.'.$setting;
1.258 albertel 14456: if (exists($env{$envname})) {
1.153 matthew 14457: if ($type eq 'scalar') {
1.258 albertel 14458: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14459: } elsif ($type eq 'array') {
1.258 albertel 14460: $env{'form.'.$setting} = [
1.153 matthew 14461: map {
1.369 www 14462: &unescape($_);
1.258 albertel 14463: } split(',',$env{$envname})
1.153 matthew 14464: ];
14465: }
14466: }
14467: }
1.127 matthew 14468: }
14469:
1.618 raeburn 14470: #######################################################
14471: #######################################################
14472:
14473: =pod
14474:
14475: =head1 Domain E-mail Routines
14476:
14477: =over 4
14478:
1.648 raeburn 14479: =item * &build_recipient_list()
1.618 raeburn 14480:
1.1075.2.44 raeburn 14481: Build recipient lists for following types of e-mail:
1.766 raeburn 14482: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14483: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14484: module change checking, student/employee ID conflict checks, as
14485: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14486: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14487:
14488: Inputs:
1.1075.2.44 raeburn 14489: defmail (scalar - email address of default recipient),
14490: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14491: requestsmail, updatesmail, or idconflictsmail).
14492:
1.619 raeburn 14493: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14494:
14495: origmail (scalar - email address of recipient from loncapa.conf,
14496: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14497:
1.1075.2.139 raeburn 14498: $requname username of requester (if mailing type is helpdeskmail)
14499:
14500: $requdom domain of requester (if mailing type is helpdeskmail)
14501:
14502: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14503:
1.655 raeburn 14504: Returns: comma separated list of addresses to which to send e-mail.
14505:
14506: =back
1.618 raeburn 14507:
14508: =cut
14509:
14510: ############################################################
14511: ############################################################
14512: sub build_recipient_list {
1.1075.2.139 raeburn 14513: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14514: my @recipients;
1.1075.2.122 raeburn 14515: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14516: my %domconfig =
1.1075.2.122 raeburn 14517: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14518: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14519: if (exists($domconfig{'contacts'}{$mailing})) {
14520: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14521: my @contacts = ('adminemail','supportemail');
14522: foreach my $item (@contacts) {
14523: if ($domconfig{'contacts'}{$mailing}{$item}) {
14524: my $addr = $domconfig{'contacts'}{$item};
14525: if (!grep(/^\Q$addr\E$/,@recipients)) {
14526: push(@recipients,$addr);
14527: }
1.619 raeburn 14528: }
1.1075.2.122 raeburn 14529: }
14530: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14531: if ($mailing eq 'helpdeskmail') {
14532: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14533: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14534: my @ok_bccs;
14535: foreach my $bcc (@bccs) {
14536: $bcc =~ s/^\s+//g;
14537: $bcc =~ s/\s+$//g;
14538: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14539: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14540: push(@ok_bccs,$bcc);
14541: }
14542: }
14543: }
14544: if (@ok_bccs > 0) {
14545: $allbcc = join(', ',@ok_bccs);
14546: }
14547: }
14548: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14549: }
14550: }
1.766 raeburn 14551: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14552: $lastresort = $origmail;
1.618 raeburn 14553: }
1.1075.2.139 raeburn 14554: if ($mailing eq 'helpdeskmail') {
14555: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14556: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14557: my ($inststatus,$inststatus_checked);
14558: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14559: ($env{'user.domain'} ne 'public')) {
14560: $inststatus_checked = 1;
14561: $inststatus = $env{'environment.inststatus'};
14562: }
14563: unless ($inststatus_checked) {
14564: if (($requname ne '') && ($requdom ne '')) {
14565: if (($requname =~ /^$match_username$/) &&
14566: ($requdom =~ /^$match_domain$/) &&
14567: (&Apache::lonnet::domain($requdom))) {
14568: my $requhome = &Apache::lonnet::homeserver($requname,
14569: $requdom);
14570: unless ($requhome eq 'no_host') {
14571: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14572: $inststatus = $userenv{'inststatus'};
14573: $inststatus_checked = 1;
14574: }
14575: }
14576: }
14577: }
14578: unless ($inststatus_checked) {
14579: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14580: my %srch = (srchby => 'email',
14581: srchdomain => $defdom,
14582: srchterm => $reqemail,
14583: srchtype => 'exact');
14584: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14585: foreach my $uname (keys(%srch_results)) {
14586: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14587: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14588: $inststatus_checked = 1;
14589: last;
14590: }
14591: }
14592: unless ($inststatus_checked) {
14593: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14594: if ($dirsrchres eq 'ok') {
14595: foreach my $uname (keys(%srch_results)) {
14596: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14597: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14598: $inststatus_checked = 1;
14599: last;
14600: }
14601: }
14602: }
14603: }
14604: }
14605: }
14606: if ($inststatus ne '') {
14607: foreach my $status (split(/\:/,$inststatus)) {
14608: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14609: my @contacts = ('adminemail','supportemail');
14610: foreach my $item (@contacts) {
14611: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14612: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14613: if (!grep(/^\Q$addr\E$/,@recipients)) {
14614: push(@recipients,$addr);
14615: }
14616: }
14617: }
14618: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14619: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14620: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14621: my @ok_bccs;
14622: foreach my $bcc (@bccs) {
14623: $bcc =~ s/^\s+//g;
14624: $bcc =~ s/\s+$//g;
14625: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14626: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14627: push(@ok_bccs,$bcc);
14628: }
14629: }
14630: }
14631: if (@ok_bccs > 0) {
14632: $allbcc = join(', ',@ok_bccs);
14633: }
14634: }
14635: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14636: last;
14637: }
14638: }
14639: }
14640: }
14641: }
1.619 raeburn 14642: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14643: $lastresort = $origmail;
14644: }
1.1075.2.128 raeburn 14645: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14646: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14647: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14648: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14649: my %what = (
14650: perlvar => 1,
14651: );
14652: my $primary = &Apache::lonnet::domain($defdom,'primary');
14653: if ($primary) {
14654: my $gotaddr;
14655: my ($result,$returnhash) =
14656: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14657: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14658: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14659: $lastresort = $returnhash->{'lonSupportEMail'};
14660: $gotaddr = 1;
14661: }
14662: }
14663: unless ($gotaddr) {
14664: my $uintdom = &Apache::lonnet::internet_dom($primary);
14665: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14666: unless ($uintdom eq $intdom) {
14667: my %domconfig =
14668: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14669: if (ref($domconfig{'contacts'}) eq 'HASH') {
14670: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14671: my @contacts = ('adminemail','supportemail');
14672: foreach my $item (@contacts) {
14673: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14674: my $addr = $domconfig{'contacts'}{$item};
14675: if (!grep(/^\Q$addr\E$/,@recipients)) {
14676: push(@recipients,$addr);
14677: }
14678: }
14679: }
14680: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14681: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14682: }
14683: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14684: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14685: my @ok_bccs;
14686: foreach my $bcc (@bccs) {
14687: $bcc =~ s/^\s+//g;
14688: $bcc =~ s/\s+$//g;
14689: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14690: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14691: push(@ok_bccs,$bcc);
14692: }
14693: }
14694: }
14695: if (@ok_bccs > 0) {
14696: $allbcc = join(', ',@ok_bccs);
14697: }
14698: }
14699: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14700: }
14701: }
14702: }
14703: }
14704: }
14705: }
1.618 raeburn 14706: }
1.688 raeburn 14707: if (defined($defmail)) {
14708: if ($defmail ne '') {
14709: push(@recipients,$defmail);
14710: }
1.618 raeburn 14711: }
14712: if ($otheremails) {
1.619 raeburn 14713: my @others;
14714: if ($otheremails =~ /,/) {
14715: @others = split(/,/,$otheremails);
1.618 raeburn 14716: } else {
1.619 raeburn 14717: push(@others,$otheremails);
14718: }
14719: foreach my $addr (@others) {
14720: if (!grep(/^\Q$addr\E$/,@recipients)) {
14721: push(@recipients,$addr);
14722: }
1.618 raeburn 14723: }
14724: }
1.1075.2.128 raeburn 14725: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14726: if ((!@recipients) && ($lastresort ne '')) {
14727: push(@recipients,$lastresort);
14728: }
14729: } elsif ($lastresort ne '') {
14730: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14731: push(@recipients,$lastresort);
14732: }
14733: }
14734: my $recipientlist = join(',',@recipients);
14735: if (wantarray) {
14736: return ($recipientlist,$allbcc,$addtext);
14737: } else {
14738: return $recipientlist;
14739: }
1.618 raeburn 14740: }
14741:
1.127 matthew 14742: ############################################################
14743: ############################################################
1.154 albertel 14744:
1.655 raeburn 14745: =pod
14746:
14747: =head1 Course Catalog Routines
14748:
14749: =over 4
14750:
14751: =item * &gather_categories()
14752:
14753: Converts category definitions - keys of categories hash stored in
14754: coursecategories in configuration.db on the primary library server in a
14755: domain - to an array. Also generates javascript and idx hash used to
14756: generate Domain Coordinator interface for editing Course Categories.
14757:
14758: Inputs:
1.663 raeburn 14759:
1.655 raeburn 14760: categories (reference to hash of category definitions).
1.663 raeburn 14761:
1.655 raeburn 14762: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14763: categories and subcategories).
1.663 raeburn 14764:
1.655 raeburn 14765: idx (reference to hash of counters used in Domain Coordinator interface for
14766: editing Course Categories).
1.663 raeburn 14767:
1.655 raeburn 14768: jsarray (reference to array of categories used to create Javascript arrays for
14769: Domain Coordinator interface for editing Course Categories).
14770:
14771: Returns: nothing
14772:
14773: Side effects: populates cats, idx and jsarray.
14774:
14775: =cut
14776:
14777: sub gather_categories {
14778: my ($categories,$cats,$idx,$jsarray) = @_;
14779: my %counters;
14780: my $num = 0;
14781: foreach my $item (keys(%{$categories})) {
14782: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14783: if ($container eq '' && $depth == 0) {
14784: $cats->[$depth][$categories->{$item}] = $cat;
14785: } else {
14786: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14787: }
14788: my ($escitem,$tail) = split(/:/,$item,2);
14789: if ($counters{$tail} eq '') {
14790: $counters{$tail} = $num;
14791: $num ++;
14792: }
14793: if (ref($idx) eq 'HASH') {
14794: $idx->{$item} = $counters{$tail};
14795: }
14796: if (ref($jsarray) eq 'ARRAY') {
14797: push(@{$jsarray->[$counters{$tail}]},$item);
14798: }
14799: }
14800: return;
14801: }
14802:
14803: =pod
14804:
14805: =item * &extract_categories()
14806:
14807: Used to generate breadcrumb trails for course categories.
14808:
14809: Inputs:
1.663 raeburn 14810:
1.655 raeburn 14811: categories (reference to hash of category definitions).
1.663 raeburn 14812:
1.655 raeburn 14813: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14814: categories and subcategories).
1.663 raeburn 14815:
1.655 raeburn 14816: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14817:
1.655 raeburn 14818: allitems (reference to hash - key is category key
14819: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14820:
1.655 raeburn 14821: idx (reference to hash of counters used in Domain Coordinator interface for
14822: editing Course Categories).
1.663 raeburn 14823:
1.655 raeburn 14824: jsarray (reference to array of categories used to create Javascript arrays for
14825: Domain Coordinator interface for editing Course Categories).
14826:
1.665 raeburn 14827: subcats (reference to hash of arrays containing all subcategories within each
14828: category, -recursive)
14829:
1.1075.2.132 raeburn 14830: maxd (reference to hash used to hold max depth for all top-level categories).
14831:
1.655 raeburn 14832: Returns: nothing
14833:
14834: Side effects: populates trails and allitems hash references.
14835:
14836: =cut
14837:
14838: sub extract_categories {
1.1075.2.132 raeburn 14839: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14840: if (ref($categories) eq 'HASH') {
14841: &gather_categories($categories,$cats,$idx,$jsarray);
14842: if (ref($cats->[0]) eq 'ARRAY') {
14843: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14844: my $name = $cats->[0][$i];
14845: my $item = &escape($name).'::0';
14846: my $trailstr;
14847: if ($name eq 'instcode') {
14848: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14849: } elsif ($name eq 'communities') {
14850: $trailstr = &mt('Communities');
1.655 raeburn 14851: } else {
14852: $trailstr = $name;
14853: }
14854: if ($allitems->{$item} eq '') {
14855: push(@{$trails},$trailstr);
14856: $allitems->{$item} = scalar(@{$trails})-1;
14857: }
14858: my @parents = ($name);
14859: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14860: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14861: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14862: if (ref($subcats) eq 'HASH') {
14863: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14864: }
1.1075.2.132 raeburn 14865: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14866: }
14867: } else {
14868: if (ref($subcats) eq 'HASH') {
14869: $subcats->{$item} = [];
1.655 raeburn 14870: }
1.1075.2.132 raeburn 14871: if (ref($maxd) eq 'HASH') {
14872: $maxd->{$name} = 1;
14873: }
1.655 raeburn 14874: }
14875: }
14876: }
14877: }
14878: return;
14879: }
14880:
14881: =pod
14882:
1.1075.2.56 raeburn 14883: =item * &recurse_categories()
1.655 raeburn 14884:
14885: Recursively used to generate breadcrumb trails for course categories.
14886:
14887: Inputs:
1.663 raeburn 14888:
1.655 raeburn 14889: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14890: categories and subcategories).
1.663 raeburn 14891:
1.655 raeburn 14892: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14893:
14894: category (current course category, for which breadcrumb trail is being generated).
14895:
14896: trails (reference to array of breadcrumb trails for each category).
14897:
1.655 raeburn 14898: allitems (reference to hash - key is category key
14899: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14900:
1.655 raeburn 14901: parents (array containing containers directories for current category,
14902: back to top level).
14903:
14904: Returns: nothing
14905:
14906: Side effects: populates trails and allitems hash references
14907:
14908: =cut
14909:
14910: sub recurse_categories {
1.1075.2.132 raeburn 14911: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14912: my $shallower = $depth - 1;
14913: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14914: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14915: my $name = $cats->[$depth]{$category}[$k];
14916: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.164 raeburn 14917: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14918: if ($allitems->{$item} eq '') {
14919: push(@{$trails},$trailstr);
14920: $allitems->{$item} = scalar(@{$trails})-1;
14921: }
14922: my $deeper = $depth+1;
14923: push(@{$parents},$category);
1.665 raeburn 14924: if (ref($subcats) eq 'HASH') {
14925: my $subcat = &escape($name).':'.$category.':'.$depth;
14926: for (my $j=@{$parents}; $j>=0; $j--) {
14927: my $higher;
14928: if ($j > 0) {
14929: $higher = &escape($parents->[$j]).':'.
14930: &escape($parents->[$j-1]).':'.$j;
14931: } else {
14932: $higher = &escape($parents->[$j]).'::'.$j;
14933: }
14934: push(@{$subcats->{$higher}},$subcat);
14935: }
14936: }
14937: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 14938: $subcats,$maxd);
1.655 raeburn 14939: pop(@{$parents});
14940: }
14941: } else {
14942: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 14943: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14944: if ($allitems->{$item} eq '') {
14945: push(@{$trails},$trailstr);
14946: $allitems->{$item} = scalar(@{$trails})-1;
14947: }
1.1075.2.132 raeburn 14948: if (ref($maxd) eq 'HASH') {
14949: if ($depth > $maxd->{$parents->[0]}) {
14950: $maxd->{$parents->[0]} = $depth;
14951: }
14952: }
1.655 raeburn 14953: }
14954: return;
14955: }
14956:
1.663 raeburn 14957: =pod
14958:
1.1075.2.56 raeburn 14959: =item * &assign_categories_table()
1.663 raeburn 14960:
14961: Create a datatable for display of hierarchical categories in a domain,
14962: with checkboxes to allow a course to be categorized.
14963:
14964: Inputs:
14965:
14966: cathash - reference to hash of categories defined for the domain (from
14967: configuration.db)
14968:
14969: currcat - scalar with an & separated list of categories assigned to a course.
14970:
1.919 raeburn 14971: type - scalar contains course type (Course or Community).
14972:
1.1075.2.117 raeburn 14973: disabled - scalar (optional) contains disabled="disabled" if input elements are
14974: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14975:
1.663 raeburn 14976: Returns: $output (markup to be displayed)
14977:
14978: =cut
14979:
14980: sub assign_categories_table {
1.1075.2.117 raeburn 14981: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14982: my $output;
14983: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 14984: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
14985: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 14986: $maxdepth = scalar(@cats);
14987: if (@cats > 0) {
14988: my $itemcount = 0;
14989: if (ref($cats[0]) eq 'ARRAY') {
14990: my @currcategories;
14991: if ($currcat ne '') {
14992: @currcategories = split('&',$currcat);
14993: }
1.919 raeburn 14994: my $table;
1.663 raeburn 14995: for (my $i=0; $i<@{$cats[0]}; $i++) {
14996: my $parent = $cats[0][$i];
1.919 raeburn 14997: next if ($parent eq 'instcode');
14998: if ($type eq 'Community') {
14999: next unless ($parent eq 'communities');
15000: } else {
15001: next if ($parent eq 'communities');
15002: }
1.663 raeburn 15003: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15004: my $item = &escape($parent).'::0';
15005: my $checked = '';
15006: if (@currcategories > 0) {
15007: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15008: $checked = ' checked="checked"';
1.663 raeburn 15009: }
15010: }
1.919 raeburn 15011: my $parent_title = $parent;
15012: if ($parent eq 'communities') {
15013: $parent_title = &mt('Communities');
15014: }
15015: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15016: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15017: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15018: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15019: my $depth = 1;
15020: push(@path,$parent);
1.1075.2.117 raeburn 15021: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15022: pop(@path);
1.919 raeburn 15023: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15024: $itemcount ++;
15025: }
1.919 raeburn 15026: if ($itemcount) {
15027: $output = &Apache::loncommon::start_data_table().
15028: $table.
15029: &Apache::loncommon::end_data_table();
15030: }
1.663 raeburn 15031: }
15032: }
15033: }
15034: return $output;
15035: }
15036:
15037: =pod
15038:
1.1075.2.56 raeburn 15039: =item * &assign_category_rows()
1.663 raeburn 15040:
15041: Create a datatable row for display of nested categories in a domain,
15042: with checkboxes to allow a course to be categorized,called recursively.
15043:
15044: Inputs:
15045:
15046: itemcount - track row number for alternating colors
15047:
15048: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15049: categories and subcategories.
15050:
15051: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15052:
15053: parent - parent of current category item
15054:
15055: path - Array containing all categories back up through the hierarchy from the
15056: current category to the top level.
15057:
15058: currcategories - reference to array of current categories assigned to the course
15059:
1.1075.2.117 raeburn 15060: disabled - scalar (optional) contains disabled="disabled" if input elements are
15061: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15062:
1.663 raeburn 15063: Returns: $output (markup to be displayed).
15064:
15065: =cut
15066:
15067: sub assign_category_rows {
1.1075.2.117 raeburn 15068: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15069: my ($text,$name,$item,$chgstr);
15070: if (ref($cats) eq 'ARRAY') {
15071: my $maxdepth = scalar(@{$cats});
15072: if (ref($cats->[$depth]) eq 'HASH') {
15073: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15074: my $numchildren = @{$cats->[$depth]{$parent}};
15075: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 15076: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15077: for (my $j=0; $j<$numchildren; $j++) {
15078: $name = $cats->[$depth]{$parent}[$j];
15079: $item = &escape($name).':'.&escape($parent).':'.$depth;
15080: my $deeper = $depth+1;
15081: my $checked = '';
15082: if (ref($currcategories) eq 'ARRAY') {
15083: if (@{$currcategories} > 0) {
15084: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15085: $checked = ' checked="checked"';
1.663 raeburn 15086: }
15087: }
15088: }
1.664 raeburn 15089: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15090: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15091: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15092: '<input type="hidden" name="catname" value="'.$name.'" />'.
15093: '</td><td>';
1.663 raeburn 15094: if (ref($path) eq 'ARRAY') {
15095: push(@{$path},$name);
1.1075.2.117 raeburn 15096: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15097: pop(@{$path});
15098: }
15099: $text .= '</td></tr>';
15100: }
15101: $text .= '</table></td>';
15102: }
15103: }
15104: }
15105: return $text;
15106: }
15107:
1.1075.2.69 raeburn 15108: =pod
15109:
15110: =back
15111:
15112: =cut
15113:
1.655 raeburn 15114: ############################################################
15115: ############################################################
15116:
15117:
1.443 albertel 15118: sub commit_customrole {
1.664 raeburn 15119: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15120: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15121: ($start?', '.&mt('starting').' '.localtime($start):'').
15122: ($end?', ending '.localtime($end):'').': <b>'.
15123: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15124: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15125: '</b><br />';
15126: return $output;
15127: }
15128:
15129: sub commit_standardrole {
1.1075.2.31 raeburn 15130: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15131: my ($output,$logmsg,$linefeed);
15132: if ($context eq 'auto') {
15133: $linefeed = "\n";
15134: } else {
15135: $linefeed = "<br />\n";
15136: }
1.443 albertel 15137: if ($three eq 'st') {
1.541 raeburn 15138: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 15139: $one,$two,$sec,$context,$credits);
1.541 raeburn 15140: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15141: ($result eq 'unknown_course') || ($result eq 'refused')) {
15142: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15143: } else {
1.541 raeburn 15144: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15145: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15146: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15147: if ($context eq 'auto') {
15148: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15149: } else {
15150: $output .= '<b>'.$result.'</b>'.$linefeed.
15151: &mt('Add to classlist').': <b>ok</b>';
15152: }
15153: $output .= $linefeed;
1.443 albertel 15154: }
15155: } else {
15156: $output = &mt('Assigning').' '.$three.' in '.$url.
15157: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15158: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15159: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15160: if ($context eq 'auto') {
15161: $output .= $result.$linefeed;
15162: } else {
15163: $output .= '<b>'.$result.'</b>'.$linefeed;
15164: }
1.443 albertel 15165: }
15166: return $output;
15167: }
15168:
15169: sub commit_studentrole {
1.1075.2.31 raeburn 15170: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15171: $credits) = @_;
1.626 raeburn 15172: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15173: if ($context eq 'auto') {
15174: $linefeed = "\n";
15175: } else {
15176: $linefeed = '<br />'."\n";
15177: }
1.443 albertel 15178: if (defined($one) && defined($two)) {
15179: my $cid=$one.'_'.$two;
15180: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15181: my $secchange = 0;
15182: my $expire_role_result;
15183: my $modify_section_result;
1.628 raeburn 15184: if ($oldsec ne '-1') {
15185: if ($oldsec ne $sec) {
1.443 albertel 15186: $secchange = 1;
1.628 raeburn 15187: my $now = time;
1.443 albertel 15188: my $uurl='/'.$cid;
15189: $uurl=~s/\_/\//g;
15190: if ($oldsec) {
15191: $uurl.='/'.$oldsec;
15192: }
1.626 raeburn 15193: $oldsecurl = $uurl;
1.628 raeburn 15194: $expire_role_result =
1.652 raeburn 15195: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15196: if ($env{'request.course.sec'} ne '') {
15197: if ($expire_role_result eq 'refused') {
15198: my @roles = ('st');
15199: my @statuses = ('previous');
15200: my @roledoms = ($one);
15201: my $withsec = 1;
15202: my %roleshash =
15203: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15204: \@statuses,\@roles,\@roledoms,$withsec);
15205: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15206: my ($oldstart,$oldend) =
15207: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15208: if ($oldend > 0 && $oldend <= $now) {
15209: $expire_role_result = 'ok';
15210: }
15211: }
15212: }
15213: }
1.443 albertel 15214: $result = $expire_role_result;
15215: }
15216: }
15217: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 15218: $modify_section_result =
15219: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15220: undef,undef,undef,$sec,
15221: $end,$start,'','',$cid,
15222: '',$context,$credits);
1.443 albertel 15223: if ($modify_section_result =~ /^ok/) {
15224: if ($secchange == 1) {
1.628 raeburn 15225: if ($sec eq '') {
15226: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15227: } else {
15228: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15229: }
1.443 albertel 15230: } elsif ($oldsec eq '-1') {
1.628 raeburn 15231: if ($sec eq '') {
15232: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15233: } else {
15234: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15235: }
1.443 albertel 15236: } else {
1.628 raeburn 15237: if ($sec eq '') {
15238: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15239: } else {
15240: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15241: }
1.443 albertel 15242: }
15243: } else {
1.628 raeburn 15244: if ($secchange) {
15245: $$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;
15246: } else {
15247: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15248: }
1.443 albertel 15249: }
15250: $result = $modify_section_result;
15251: } elsif ($secchange == 1) {
1.628 raeburn 15252: if ($oldsec eq '') {
1.1075.2.20 raeburn 15253: $$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 15254: } else {
15255: $$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;
15256: }
1.626 raeburn 15257: if ($expire_role_result eq 'refused') {
15258: my $newsecurl = '/'.$cid;
15259: $newsecurl =~ s/\_/\//g;
15260: if ($sec ne '') {
15261: $newsecurl.='/'.$sec;
15262: }
15263: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15264: if ($sec eq '') {
15265: $$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;
15266: } else {
15267: $$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;
15268: }
15269: }
15270: }
1.443 albertel 15271: }
15272: } else {
1.626 raeburn 15273: $$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 15274: $result = "error: incomplete course id\n";
15275: }
15276: return $result;
15277: }
15278:
1.1075.2.25 raeburn 15279: sub show_role_extent {
15280: my ($scope,$context,$role) = @_;
15281: $scope =~ s{^/}{};
15282: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15283: push(@courseroles,'co');
15284: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15285: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15286: $scope =~ s{/}{_};
15287: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15288: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15289: my ($audom,$auname) = split(/\//,$scope);
15290: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15291: &Apache::loncommon::plainname($auname,$audom).'</span>');
15292: } else {
15293: $scope =~ s{/$}{};
15294: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15295: &Apache::lonnet::domain($scope,'description').'</span>');
15296: }
15297: }
15298:
1.443 albertel 15299: ############################################################
15300: ############################################################
15301:
1.566 albertel 15302: sub check_clone {
1.578 raeburn 15303: my ($args,$linefeed) = @_;
1.566 albertel 15304: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15305: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15306: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15307: my $clonemsg;
15308: my $can_clone = 0;
1.944 raeburn 15309: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15310: if ($lctype ne 'community') {
15311: $lctype = 'course';
15312: }
1.566 albertel 15313: if ($clonehome eq 'no_host') {
1.944 raeburn 15314: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15315: $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'});
15316: } else {
15317: $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'});
15318: }
1.566 albertel 15319: } else {
15320: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15321: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15322: if ($clonedesc{'type'} ne 'Community') {
15323: $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'});
15324: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15325: }
15326: }
1.1075.2.119 raeburn 15327: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15328: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15329: $can_clone = 1;
15330: } else {
1.1075.2.95 raeburn 15331: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15332: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 15333: if ($clonehash{'cloners'} eq '') {
15334: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15335: if ($domdefs{'canclone'}) {
15336: unless ($domdefs{'canclone'} eq 'none') {
15337: if ($domdefs{'canclone'} eq 'domain') {
15338: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15339: $can_clone = 1;
15340: }
15341: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15342: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15343: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15344: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15345: $can_clone = 1;
15346: }
15347: }
15348: }
1.908 raeburn 15349: }
1.1075.2.95 raeburn 15350: } else {
15351: my @cloners = split(/,/,$clonehash{'cloners'});
15352: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15353: $can_clone = 1;
1.1075.2.95 raeburn 15354: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15355: $can_clone = 1;
1.1075.2.96 raeburn 15356: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15357: $can_clone = 1;
1.1075.2.95 raeburn 15358: }
15359: unless ($can_clone) {
1.1075.2.96 raeburn 15360: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15361: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 15362: my (%gotdomdefaults,%gotcodedefaults);
15363: foreach my $cloner (@cloners) {
15364: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15365: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15366: my (%codedefaults,@code_order);
15367: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15368: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15369: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15370: }
15371: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15372: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15373: }
15374: } else {
15375: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15376: \%codedefaults,
15377: \@code_order);
15378: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15379: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15380: }
15381: if (@code_order > 0) {
15382: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15383: $cloner,$clonehash{'internal.coursecode'},
15384: $args->{'crscode'})) {
15385: $can_clone = 1;
15386: last;
15387: }
15388: }
15389: }
15390: }
15391: }
1.1075.2.96 raeburn 15392: }
15393: }
15394: unless ($can_clone) {
15395: my $ccrole = 'cc';
15396: if ($args->{'crstype'} eq 'Community') {
15397: $ccrole = 'co';
15398: }
15399: my %roleshash =
15400: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15401: $args->{'ccdomain'},
15402: 'userroles',['active'],[$ccrole],
15403: [$args->{'clonedomain'}]);
15404: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15405: $can_clone = 1;
15406: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15407: $args->{'ccuname'},$args->{'ccdomain'})) {
15408: $can_clone = 1;
1.1075.2.95 raeburn 15409: }
15410: }
15411: unless ($can_clone) {
15412: if ($args->{'crstype'} eq 'Community') {
15413: $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'});
15414: } else {
15415: $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 15416: }
1.566 albertel 15417: }
1.578 raeburn 15418: }
1.566 albertel 15419: }
15420: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15421: }
15422:
1.444 albertel 15423: sub construct_course {
1.1075.2.119 raeburn 15424: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15425: $cnum,$category,$coderef) = @_;
1.444 albertel 15426: my $outcome;
1.541 raeburn 15427: my $linefeed = '<br />'."\n";
15428: if ($context eq 'auto') {
15429: $linefeed = "\n";
15430: }
1.566 albertel 15431:
15432: #
15433: # Are we cloning?
15434: #
15435: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15436: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15437: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15438: if ($context ne 'auto') {
1.578 raeburn 15439: if ($clonemsg ne '') {
15440: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15441: }
1.566 albertel 15442: }
15443: $outcome .= $clonemsg.$linefeed;
15444:
15445: if (!$can_clone) {
15446: return (0,$outcome);
15447: }
15448: }
15449:
1.444 albertel 15450: #
15451: # Open course
15452: #
15453: my $crstype = lc($args->{'crstype'});
15454: my %cenv=();
15455: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15456: $args->{'cdescr'},
15457: $args->{'curl'},
15458: $args->{'course_home'},
15459: $args->{'nonstandard'},
15460: $args->{'crscode'},
15461: $args->{'ccuname'}.':'.
15462: $args->{'ccdomain'},
1.882 raeburn 15463: $args->{'crstype'},
1.885 raeburn 15464: $cnum,$context,$category);
1.444 albertel 15465:
15466: # Note: The testing routines depend on this being output; see
15467: # Utils::Course. This needs to at least be output as a comment
15468: # if anyone ever decides to not show this, and Utils::Course::new
15469: # will need to be suitably modified.
1.541 raeburn 15470: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 15471: if ($$courseid =~ /^error:/) {
15472: return (0,$outcome);
15473: }
15474:
1.444 albertel 15475: #
15476: # Check if created correctly
15477: #
1.479 albertel 15478: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15479: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15480: if ($crsuhome eq 'no_host') {
15481: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15482: return (0,$outcome);
15483: }
1.541 raeburn 15484: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15485:
1.444 albertel 15486: #
1.566 albertel 15487: # Do the cloning
15488: #
15489: if ($can_clone && $cloneid) {
15490: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
15491: if ($context ne 'auto') {
15492: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15493: }
15494: $outcome .= $clonemsg.$linefeed;
15495: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15496: # Copy all files
1.637 www 15497: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15498: # Restore URL
1.566 albertel 15499: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15500: # Restore title
1.566 albertel 15501: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15502: # Restore creation date, creator and creation context.
15503: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15504: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15505: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15506: # Mark as cloned
1.566 albertel 15507: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15508: # Need to clone grading mode
15509: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15510: $cenv{'grading'}=$newenv{'grading'};
15511: # Do not clone these environment entries
15512: &Apache::lonnet::del('environment',
15513: ['default_enrollment_start_date',
15514: 'default_enrollment_end_date',
15515: 'question.email',
15516: 'policy.email',
15517: 'comment.email',
15518: 'pch.users.denied',
1.725 raeburn 15519: 'plc.users.denied',
15520: 'hidefromcat',
1.1075.2.36 raeburn 15521: 'checkforpriv',
1.1075.2.158 raeburn 15522: 'categories'],
1.638 www 15523: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15524: if ($args->{'textbook'}) {
15525: $cenv{'internal.textbook'} = $args->{'textbook'};
15526: }
1.444 albertel 15527: }
1.566 albertel 15528:
1.444 albertel 15529: #
15530: # Set environment (will override cloned, if existing)
15531: #
15532: my @sections = ();
15533: my @xlists = ();
15534: if ($args->{'crstype'}) {
15535: $cenv{'type'}=$args->{'crstype'};
15536: }
15537: if ($args->{'crsid'}) {
15538: $cenv{'courseid'}=$args->{'crsid'};
15539: }
15540: if ($args->{'crscode'}) {
15541: $cenv{'internal.coursecode'}=$args->{'crscode'};
15542: }
15543: if ($args->{'crsquota'} ne '') {
15544: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15545: } else {
15546: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15547: }
15548: if ($args->{'ccuname'}) {
15549: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15550: ':'.$args->{'ccdomain'};
15551: } else {
15552: $cenv{'internal.courseowner'} = $args->{'curruser'};
15553: }
1.1075.2.31 raeburn 15554: if ($args->{'defaultcredits'}) {
15555: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15556: }
1.444 albertel 15557: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15558: if ($args->{'crssections'}) {
15559: $cenv{'internal.sectionnums'} = '';
15560: if ($args->{'crssections'} =~ m/,/) {
15561: @sections = split/,/,$args->{'crssections'};
15562: } else {
15563: $sections[0] = $args->{'crssections'};
15564: }
15565: if (@sections > 0) {
15566: foreach my $item (@sections) {
15567: my ($sec,$gp) = split/:/,$item;
15568: my $class = $args->{'crscode'}.$sec;
15569: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15570: $cenv{'internal.sectionnums'} .= $item.',';
15571: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15572: push(@badclasses,$class);
1.444 albertel 15573: }
15574: }
15575: $cenv{'internal.sectionnums'} =~ s/,$//;
15576: }
15577: }
15578: # do not hide course coordinator from staff listing,
15579: # even if privileged
15580: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15581: # add course coordinator's domain to domains to check for privileged users
15582: # if different to course domain
15583: if ($$crsudom ne $args->{'ccdomain'}) {
15584: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15585: }
1.444 albertel 15586: # add crosslistings
15587: if ($args->{'crsxlist'}) {
15588: $cenv{'internal.crosslistings'}='';
15589: if ($args->{'crsxlist'} =~ m/,/) {
15590: @xlists = split/,/,$args->{'crsxlist'};
15591: } else {
15592: $xlists[0] = $args->{'crsxlist'};
15593: }
15594: if (@xlists > 0) {
15595: foreach my $item (@xlists) {
15596: my ($xl,$gp) = split/:/,$item;
15597: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15598: $cenv{'internal.crosslistings'} .= $item.',';
15599: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15600: push(@badclasses,$xl);
1.444 albertel 15601: }
15602: }
15603: $cenv{'internal.crosslistings'} =~ s/,$//;
15604: }
15605: }
15606: if ($args->{'autoadds'}) {
15607: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15608: }
15609: if ($args->{'autodrops'}) {
15610: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15611: }
15612: # check for notification of enrollment changes
15613: my @notified = ();
15614: if ($args->{'notify_owner'}) {
15615: if ($args->{'ccuname'} ne '') {
15616: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15617: }
15618: }
15619: if ($args->{'notify_dc'}) {
15620: if ($uname ne '') {
1.630 raeburn 15621: push(@notified,$uname.':'.$udom);
1.444 albertel 15622: }
15623: }
15624: if (@notified > 0) {
15625: my $notifylist;
15626: if (@notified > 1) {
15627: $notifylist = join(',',@notified);
15628: } else {
15629: $notifylist = $notified[0];
15630: }
15631: $cenv{'internal.notifylist'} = $notifylist;
15632: }
15633: if (@badclasses > 0) {
15634: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15635: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15636: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15637: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15638: );
1.1075.2.119 raeburn 15639: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15640: &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 15641: if ($context eq 'auto') {
15642: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15643: } else {
1.566 albertel 15644: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15645: }
15646: foreach my $item (@badclasses) {
1.541 raeburn 15647: if ($context eq 'auto') {
1.1075.2.119 raeburn 15648: $outcome .= " - $item\n";
1.541 raeburn 15649: } else {
1.1075.2.119 raeburn 15650: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15651: }
1.1075.2.119 raeburn 15652: }
15653: if ($context eq 'auto') {
15654: $outcome .= $linefeed;
15655: } else {
15656: $outcome .= "</ul><br /><br /></div>\n";
15657: }
1.444 albertel 15658: }
15659: if ($args->{'no_end_date'}) {
15660: $args->{'endaccess'} = 0;
15661: }
15662: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15663: $cenv{'internal.autoend'}=$args->{'enrollend'};
15664: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15665: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15666: if ($args->{'showphotos'}) {
15667: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15668: }
15669: $cenv{'internal.authtype'} = $args->{'authtype'};
15670: $cenv{'internal.autharg'} = $args->{'autharg'};
15671: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15672: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15673: 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');
15674: if ($context eq 'auto') {
15675: $outcome .= $krb_msg;
15676: } else {
1.566 albertel 15677: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15678: }
15679: $outcome .= $linefeed;
1.444 albertel 15680: }
15681: }
15682: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15683: if ($args->{'setpolicy'}) {
15684: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15685: }
15686: if ($args->{'setcontent'}) {
15687: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15688: }
1.1075.2.110 raeburn 15689: if ($args->{'setcomment'}) {
15690: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15691: }
1.444 albertel 15692: }
15693: if ($args->{'reshome'}) {
15694: $cenv{'reshome'}=$args->{'reshome'}.'/';
15695: $cenv{'reshome'}=~s/\/+$/\//;
15696: }
15697: #
15698: # course has keyed access
15699: #
15700: if ($args->{'setkeys'}) {
15701: $cenv{'keyaccess'}='yes';
15702: }
15703: # if specified, key authority is not course, but user
15704: # only active if keyaccess is yes
15705: if ($args->{'keyauth'}) {
1.487 albertel 15706: my ($user,$domain) = split(':',$args->{'keyauth'});
15707: $user = &LONCAPA::clean_username($user);
15708: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15709: if ($user ne '' && $domain ne '') {
1.487 albertel 15710: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15711: }
15712: }
15713:
1.1075.2.59 raeburn 15714: #
15715: # generate and store uniquecode (available to course requester), if course should have one.
15716: #
15717: if ($args->{'uniquecode'}) {
15718: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15719: if ($code) {
15720: $cenv{'internal.uniquecode'} = $code;
15721: my %crsinfo =
15722: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15723: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15724: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15725: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15726: }
15727: if (ref($coderef)) {
15728: $$coderef = $code;
15729: }
15730: }
15731: }
15732:
1.444 albertel 15733: if ($args->{'disresdis'}) {
15734: $cenv{'pch.roles.denied'}='st';
15735: }
15736: if ($args->{'disablechat'}) {
15737: $cenv{'plc.roles.denied'}='st';
15738: }
15739:
15740: # Record we've not yet viewed the Course Initialization Helper for this
15741: # course
15742: $cenv{'course.helper.not.run'} = 1;
15743: #
15744: # Use new Randomseed
15745: #
15746: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15747: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15748: #
15749: # The encryption code and receipt prefix for this course
15750: #
15751: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15752: $cenv{'internal.encpref'}=100+int(9*rand(99));
15753: #
15754: # By default, use standard grading
15755: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15756:
1.541 raeburn 15757: $outcome .= $linefeed.&mt('Setting environment').': '.
15758: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15759: #
15760: # Open all assignments
15761: #
15762: if ($args->{'openall'}) {
1.1075.2.146 raeburn 15763: my $opendate = time;
15764: if ($args->{'openallfrom'} =~ /^\d+$/) {
15765: $opendate = $args->{'openallfrom'};
15766: }
1.444 albertel 15767: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 15768: my %storecontent = ($storeunder => $opendate,
1.444 albertel 15769: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 15770: $outcome .= &mt('All assignments open starting [_1]',
15771: &Apache::lonlocal::locallocaltime($opendate)).': '.
15772: &Apache::lonnet::cput
15773: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15774: }
15775: #
15776: # Set first page
15777: #
15778: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15779: || ($cloneid)) {
1.445 albertel 15780: use LONCAPA::map;
1.444 albertel 15781: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15782:
15783: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15784: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15785:
1.444 albertel 15786: $outcome .= ($fatal?$errtext:'read ok').' - ';
15787: my $title; my $url;
15788: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15789: $title=&mt('Syllabus');
1.444 albertel 15790: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15791: } else {
1.963 raeburn 15792: $title=&mt('Table of Contents');
1.444 albertel 15793: $url='/adm/navmaps';
15794: }
1.445 albertel 15795:
15796: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15797: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15798:
15799: if ($errtext) { $fatal=2; }
1.541 raeburn 15800: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15801: }
1.566 albertel 15802:
15803: return (1,$outcome);
1.444 albertel 15804: }
15805:
1.1075.2.59 raeburn 15806: sub make_unique_code {
15807: my ($cdom,$cnum) = @_;
15808: # get lock on uniquecodes db
15809: my $lockhash = {
15810: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15811: ':'.$env{'user.domain'},
15812: };
15813: my $tries = 0;
15814: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15815: my ($code,$error);
15816:
15817: while (($gotlock ne 'ok') && ($tries<3)) {
15818: $tries ++;
15819: sleep 1;
15820: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15821: }
15822: if ($gotlock eq 'ok') {
15823: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15824: my $gotcode;
15825: my $attempts = 0;
15826: while ((!$gotcode) && ($attempts < 100)) {
15827: $code = &generate_code();
15828: if (!exists($currcodes{$code})) {
15829: $gotcode = 1;
15830: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15831: $error = 'nostore';
15832: }
15833: }
15834: $attempts ++;
15835: }
15836: my @del_lock = ($cnum."\0".'uniquecodes');
15837: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15838: } else {
15839: $error = 'nolock';
15840: }
15841: return ($code,$error);
15842: }
15843:
15844: sub generate_code {
15845: my $code;
15846: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15847: for (my $i=0; $i<6; $i++) {
15848: my $lettnum = int (rand 2);
15849: my $item = '';
15850: if ($lettnum) {
15851: $item = $letts[int( rand(18) )];
15852: } else {
15853: $item = 1+int( rand(8) );
15854: }
15855: $code .= $item;
15856: }
15857: return $code;
15858: }
15859:
1.444 albertel 15860: ############################################################
15861: ############################################################
15862:
1.953 droeschl 15863: #SD
15864: # only Community and Course, or anything else?
1.378 raeburn 15865: sub course_type {
15866: my ($cid) = @_;
15867: if (!defined($cid)) {
15868: $cid = $env{'request.course.id'};
15869: }
1.404 albertel 15870: if (defined($env{'course.'.$cid.'.type'})) {
15871: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15872: } else {
15873: return 'Course';
1.377 raeburn 15874: }
15875: }
1.156 albertel 15876:
1.406 raeburn 15877: sub group_term {
15878: my $crstype = &course_type();
15879: my %names = (
15880: 'Course' => 'group',
1.865 raeburn 15881: 'Community' => 'group',
1.406 raeburn 15882: );
15883: return $names{$crstype};
15884: }
15885:
1.902 raeburn 15886: sub course_types {
1.1075.2.59 raeburn 15887: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15888: my %typename = (
15889: official => 'Official course',
15890: unofficial => 'Unofficial course',
15891: community => 'Community',
1.1075.2.59 raeburn 15892: textbook => 'Textbook course',
1.902 raeburn 15893: );
15894: return (\@types,\%typename);
15895: }
15896:
1.156 albertel 15897: sub icon {
15898: my ($file)=@_;
1.505 albertel 15899: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15900: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15901: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15902: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15903: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15904: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15905: $curfext.".gif") {
15906: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15907: $curfext.".gif";
15908: }
15909: }
1.249 albertel 15910: return &lonhttpdurl($iconname);
1.154 albertel 15911: }
1.84 albertel 15912:
1.575 albertel 15913: sub lonhttpdurl {
1.692 www 15914: #
15915: # Had been used for "small fry" static images on separate port 8080.
15916: # Modify here if lightweight http functionality desired again.
15917: # Currently eliminated due to increasing firewall issues.
15918: #
1.575 albertel 15919: my ($url)=@_;
1.692 www 15920: return $url;
1.215 albertel 15921: }
15922:
1.213 albertel 15923: sub connection_aborted {
15924: my ($r)=@_;
15925: $r->print(" ");$r->rflush();
15926: my $c = $r->connection;
15927: return $c->aborted();
15928: }
15929:
1.221 foxr 15930: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15931: # strings as 'strings'.
15932: sub escape_single {
1.221 foxr 15933: my ($input) = @_;
1.223 albertel 15934: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15935: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15936: return $input;
15937: }
1.223 albertel 15938:
1.222 foxr 15939: # Same as escape_single, but escape's "'s This
15940: # can be used for "strings"
15941: sub escape_double {
15942: my ($input) = @_;
15943: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15944: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15945: return $input;
15946: }
1.223 albertel 15947:
1.222 foxr 15948: # Escapes the last element of a full URL.
15949: sub escape_url {
15950: my ($url) = @_;
1.238 raeburn 15951: my @urlslices = split(/\//, $url,-1);
1.369 www 15952: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15953: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15954: }
1.462 albertel 15955:
1.820 raeburn 15956: sub compare_arrays {
15957: my ($arrayref1,$arrayref2) = @_;
15958: my (@difference,%count);
15959: @difference = ();
15960: %count = ();
15961: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15962: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15963: foreach my $element (keys(%count)) {
15964: if ($count{$element} == 1) {
15965: push(@difference,$element);
15966: }
15967: }
15968: }
15969: return @difference;
15970: }
15971:
1.1075.2.152 raeburn 15972: sub lon_status_items {
15973: my %defaults = (
15974: E => 100,
15975: W => 4,
15976: N => 1,
15977: U => 5,
15978: threshold => 200,
15979: sysmail => 2500,
15980: );
15981: my %names = (
15982: E => 'Errors',
15983: W => 'Warnings',
15984: N => 'Notices',
15985: U => 'Unsent',
15986: );
15987: return (\%defaults,\%names);
15988: }
15989:
1.817 bisitz 15990: # -------------------------------------------------------- Initialize user login
1.462 albertel 15991: sub init_user_environment {
1.463 albertel 15992: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15993: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15994:
15995: my $public=($username eq 'public' && $domain eq 'public');
15996:
15997: # See if old ID present, if so, remove
15998:
1.1062 raeburn 15999: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16000: my $now=time;
16001:
16002: if ($public) {
16003: my $max_public=100;
16004: my $oldest;
16005: my $oldest_time=0;
16006: for(my $next=1;$next<=$max_public;$next++) {
16007: if (-e $lonids."/publicuser_$next.id") {
16008: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16009: if ($mtime<$oldest_time || !$oldest_time) {
16010: $oldest_time=$mtime;
16011: $oldest=$next;
16012: }
16013: } else {
16014: $cookie="publicuser_$next";
16015: last;
16016: }
16017: }
16018: if (!$cookie) { $cookie="publicuser_$oldest"; }
16019: } else {
1.463 albertel 16020: # if this isn't a robot, kill any existing non-robot sessions
16021: if (!$args->{'robot'}) {
16022: opendir(DIR,$lonids);
16023: while ($filename=readdir(DIR)) {
16024: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 16025: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16026: &GDBM_READER(),0640)) {
16027: my $linkedfile;
16028: if (exists($oldenv{'user.linkedenv'})) {
16029: $linkedfile = $oldenv{'user.linkedenv'};
16030: }
16031: untie(%oldenv);
16032: if (unlink("$lonids/$filename")) {
16033: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16034: if (-l "$lonids/$linkedfile.id") {
16035: unlink("$lonids/$linkedfile.id");
16036: }
16037: }
16038: }
16039: } else {
16040: unlink($lonids.'/'.$filename);
16041: }
1.463 albertel 16042: }
1.462 albertel 16043: }
1.463 albertel 16044: closedir(DIR);
1.1075.2.84 raeburn 16045: # If there is a undeleted lockfile for the user's paste buffer remove it.
16046: my $namespace = 'nohist_courseeditor';
16047: my $lockingkey = 'paste'."\0".'locked_num';
16048: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16049: $domain,$username);
16050: if (exists($lockhash{$lockingkey})) {
16051: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16052: unless ($delresult eq 'ok') {
16053: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16054: }
16055: }
1.462 albertel 16056: }
16057: # Give them a new cookie
1.463 albertel 16058: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16059: : $now.$$.int(rand(10000)));
1.463 albertel 16060: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16061:
16062: # Initialize roles
16063:
1.1062 raeburn 16064: ($userroles,$firstaccenv,$timerintenv) =
16065: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16066: }
16067: # ------------------------------------ Check browser type and MathML capability
16068:
1.1075.2.77 raeburn 16069: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16070: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16071:
16072: # ------------------------------------------------------------- Get environment
16073:
16074: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16075: my ($tmp) = keys(%userenv);
16076: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
16077: } else {
16078: undef(%userenv);
16079: }
16080: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16081: $form->{'interface'}=$userenv{'interface'};
16082: }
16083: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16084:
16085: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16086: foreach my $option ('interface','localpath','localres') {
16087: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16088: }
16089: # --------------------------------------------------------- Write first profile
16090:
16091: {
1.1075.2.150 raeburn 16092: my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 16093: my %initial_env =
16094: ("user.name" => $username,
16095: "user.domain" => $domain,
16096: "user.home" => $authhost,
16097: "browser.type" => $clientbrowser,
16098: "browser.version" => $clientversion,
16099: "browser.mathml" => $clientmathml,
16100: "browser.unicode" => $clientunicode,
16101: "browser.os" => $clientos,
1.1075.2.42 raeburn 16102: "browser.mobile" => $clientmobile,
16103: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 16104: "browser.osversion" => $clientosversion,
1.462 albertel 16105: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16106: "request.course.fn" => '',
16107: "request.course.uri" => '',
16108: "request.course.sec" => '',
16109: "request.role" => 'cm',
16110: "request.role.adv" => $env{'user.adv'},
1.1075.2.150 raeburn 16111: "request.host" => $ip,);
1.462 albertel 16112:
16113: if ($form->{'localpath'}) {
16114: $initial_env{"browser.localpath"} = $form->{'localpath'};
16115: $initial_env{"browser.localres"} = $form->{'localres'};
16116: }
16117:
16118: if ($form->{'interface'}) {
16119: $form->{'interface'}=~s/\W//gs;
16120: $initial_env{"browser.interface"} = $form->{'interface'};
16121: $env{'browser.interface'}=$form->{'interface'};
16122: }
16123:
1.1075.2.54 raeburn 16124: if ($form->{'iptoken'}) {
16125: my $lonhost = $r->dir_config('lonHostID');
16126: $initial_env{"user.noloadbalance"} = $lonhost;
16127: $env{'user.noloadbalance'} = $lonhost;
16128: }
16129:
1.1075.2.120 raeburn 16130: if ($form->{'noloadbalance'}) {
16131: my @hosts = &Apache::lonnet::current_machine_ids();
16132: my $hosthere = $form->{'noloadbalance'};
16133: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16134: $initial_env{"user.noloadbalance"} = $hosthere;
16135: $env{'user.noloadbalance'} = $hosthere;
16136: }
16137: }
16138:
1.1016 raeburn 16139: unless ($domain eq 'public') {
1.1075.2.125 raeburn 16140: my %is_adv = ( is_adv => $env{'user.adv'} );
16141: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 16142:
1.1075.2.125 raeburn 16143: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16144: $userenv{'availabletools.'.$tool} =
16145: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16146: undef,\%userenv,\%domdef,\%is_adv);
16147: }
1.724 raeburn 16148:
1.1075.2.125 raeburn 16149: foreach my $crstype ('official','unofficial','community','textbook') {
16150: $userenv{'canrequest.'.$crstype} =
16151: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16152: 'reload','requestcourses',
16153: \%userenv,\%domdef,\%is_adv);
16154: }
1.765 raeburn 16155:
1.1075.2.125 raeburn 16156: $userenv{'canrequest.author'} =
16157: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16158: 'reload','requestauthor',
16159: \%userenv,\%domdef,\%is_adv);
16160: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16161: $domain,$username);
16162: my $reqstatus = $reqauthor{'author_status'};
16163: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16164: if (ref($reqauthor{'author'}) eq 'HASH') {
16165: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16166: $reqauthor{'author'}{'timestamp'};
16167: }
1.1075.2.14 raeburn 16168: }
16169: }
16170:
1.462 albertel 16171: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16172:
1.462 albertel 16173: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16174: &GDBM_WRCREAT(),0640)) {
16175: &_add_to_env(\%disk_env,\%initial_env);
16176: &_add_to_env(\%disk_env,\%userenv,'environment.');
16177: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16178: if (ref($firstaccenv) eq 'HASH') {
16179: &_add_to_env(\%disk_env,$firstaccenv);
16180: }
16181: if (ref($timerintenv) eq 'HASH') {
16182: &_add_to_env(\%disk_env,$timerintenv);
16183: }
1.463 albertel 16184: if (ref($args->{'extra_env'})) {
16185: &_add_to_env(\%disk_env,$args->{'extra_env'});
16186: }
1.462 albertel 16187: untie(%disk_env);
16188: } else {
1.705 tempelho 16189: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16190: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16191: return 'error: '.$!;
16192: }
16193: }
16194: $env{'request.role'}='cm';
16195: $env{'request.role.adv'}=$env{'user.adv'};
16196: $env{'browser.type'}=$clientbrowser;
16197:
16198: return $cookie;
16199:
16200: }
16201:
16202: sub _add_to_env {
16203: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16204: if (ref($env_data) eq 'HASH') {
16205: while (my ($key,$value) = each(%$env_data)) {
16206: $idf->{$prefix.$key} = $value;
16207: $env{$prefix.$key} = $value;
16208: }
1.462 albertel 16209: }
16210: }
16211:
1.685 tempelho 16212: # --- Get the symbolic name of a problem and the url
16213: sub get_symb {
16214: my ($request,$silent) = @_;
1.726 raeburn 16215: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16216: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16217: if ($symb eq '') {
16218: if (!$silent) {
1.1071 raeburn 16219: if (ref($request)) {
16220: $request->print("Unable to handle ambiguous references:$url:.");
16221: }
1.685 tempelho 16222: return ();
16223: }
16224: }
16225: &Apache::lonenc::check_decrypt(\$symb);
16226: return ($symb);
16227: }
16228:
16229: # --------------------------------------------------------------Get annotation
16230:
16231: sub get_annotation {
16232: my ($symb,$enc) = @_;
16233:
16234: my $key = $symb;
16235: if (!$enc) {
16236: $key =
16237: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16238: }
16239: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16240: return $annotation{$key};
16241: }
16242:
16243: sub clean_symb {
1.731 raeburn 16244: my ($symb,$delete_enc) = @_;
1.685 tempelho 16245:
16246: &Apache::lonenc::check_decrypt(\$symb);
16247: my $enc = $env{'request.enc'};
1.731 raeburn 16248: if ($delete_enc) {
1.730 raeburn 16249: delete($env{'request.enc'});
16250: }
1.685 tempelho 16251:
16252: return ($symb,$enc);
16253: }
1.462 albertel 16254:
1.1075.2.69 raeburn 16255: ############################################################
16256: ############################################################
16257:
16258: =pod
16259:
16260: =head1 Routines for building display used to search for courses
16261:
16262:
16263: =over 4
16264:
16265: =item * &build_filters()
16266:
16267: Create markup for a table used to set filters to use when selecting
16268: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16269: and quotacheck.pl
16270:
16271:
16272: Inputs:
16273:
16274: filterlist - anonymous array of fields to include as potential filters
16275:
16276: crstype - course type
16277:
16278: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16279: to pop-open a course selector (will contain "extra element").
16280:
16281: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16282:
16283: filter - anonymous hash of criteria and their values
16284:
16285: action - form action
16286:
16287: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16288:
16289: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
16290:
16291: cloneruname - username of owner of new course who wants to clone
16292:
16293: clonerudom - domain of owner of new course who wants to clone
16294:
16295: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16296:
16297: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16298:
16299: codedom - domain
16300:
16301: formname - value of form element named "form".
16302:
16303: fixeddom - domain, if fixed.
16304:
16305: prevphase - value to assign to form element named "phase" when going back to the previous screen
16306:
16307: cnameelement - name of form element in form on opener page which will receive title of selected course
16308:
16309: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16310:
16311: cdomelement - name of form element in form on opener page which will receive domain of selected course
16312:
16313: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16314:
16315: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16316:
16317: clonewarning - warning message about missing information for intended course owner when DC creates a course
16318:
16319:
16320: Returns: $output - HTML for display of search criteria, and hidden form elements.
16321:
16322:
16323: Side Effects: None
16324:
16325: =cut
16326:
16327: # ---------------------------------------------- search for courses based on last activity etc.
16328:
16329: sub build_filters {
16330: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16331: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16332: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16333: $cnameelement,$cnumelement,$cdomelement,$setroles,
16334: $clonetext,$clonewarning) = @_;
16335: my ($list,$jscript);
16336: my $onchange = 'javascript:updateFilters(this)';
16337: my ($domainselectform,$sincefilterform,$createdfilterform,
16338: $ownerdomselectform,$persondomselectform,$instcodeform,
16339: $typeselectform,$instcodetitle);
16340: if ($formname eq '') {
16341: $formname = $caller;
16342: }
16343: foreach my $item (@{$filterlist}) {
16344: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16345: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16346: if ($item eq 'domainfilter') {
16347: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16348: } elsif ($item eq 'coursefilter') {
16349: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16350: } elsif ($item eq 'ownerfilter') {
16351: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16352: } elsif ($item eq 'ownerdomfilter') {
16353: $filter->{'ownerdomfilter'} =
16354: &LONCAPA::clean_domain($filter->{$item});
16355: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16356: 'ownerdomfilter',1);
16357: } elsif ($item eq 'personfilter') {
16358: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16359: } elsif ($item eq 'persondomfilter') {
16360: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16361: 'persondomfilter',1);
16362: } else {
16363: $filter->{$item} =~ s/\W//g;
16364: }
16365: if (!$filter->{$item}) {
16366: $filter->{$item} = '';
16367: }
16368: }
16369: if ($item eq 'domainfilter') {
16370: my $allow_blank = 1;
16371: if ($formname eq 'portform') {
16372: $allow_blank=0;
16373: } elsif ($formname eq 'studentform') {
16374: $allow_blank=0;
16375: }
16376: if ($fixeddom) {
16377: $domainselectform = '<input type="hidden" name="domainfilter"'.
16378: ' value="'.$codedom.'" />'.
16379: &Apache::lonnet::domain($codedom,'description');
16380: } else {
16381: $domainselectform = &select_dom_form($filter->{$item},
16382: 'domainfilter',
16383: $allow_blank,'',$onchange);
16384: }
16385: } else {
16386: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16387: }
16388: }
16389:
16390: # last course activity filter and selection
16391: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16392:
16393: # course created filter and selection
16394: if (exists($filter->{'createdfilter'})) {
16395: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16396: }
16397:
16398: my %lt = &Apache::lonlocal::texthash(
16399: 'cac' => "$crstype Activity",
16400: 'ccr' => "$crstype Created",
16401: 'cde' => "$crstype Title",
16402: 'cdo' => "$crstype Domain",
16403: 'ins' => 'Institutional Code',
16404: 'inc' => 'Institutional Categorization',
16405: 'cow' => "$crstype Owner/Co-owner",
16406: 'cop' => "$crstype Personnel Includes",
16407: 'cog' => 'Type',
16408: );
16409:
16410: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16411: my $typeval = 'Course';
16412: if ($crstype eq 'Community') {
16413: $typeval = 'Community';
16414: }
16415: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16416: } else {
16417: $typeselectform = '<select name="type" size="1"';
16418: if ($onchange) {
16419: $typeselectform .= ' onchange="'.$onchange.'"';
16420: }
16421: $typeselectform .= '>'."\n";
16422: foreach my $posstype ('Course','Community') {
16423: $typeselectform.='<option value="'.$posstype.'"'.
16424: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16425: }
16426: $typeselectform.="</select>";
16427: }
16428:
16429: my ($cloneableonlyform,$cloneabletitle);
16430: if (exists($filter->{'cloneableonly'})) {
16431: my $cloneableon = '';
16432: my $cloneableoff = ' checked="checked"';
16433: if ($filter->{'cloneableonly'}) {
16434: $cloneableon = $cloneableoff;
16435: $cloneableoff = '';
16436: }
16437: $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>';
16438: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16439: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16440: } else {
16441: $cloneabletitle = &mt('Cloneable by you');
16442: }
16443: }
16444: my $officialjs;
16445: if ($crstype eq 'Course') {
16446: if (exists($filter->{'instcodefilter'})) {
16447: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16448: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16449: if ($codedom) {
16450: $officialjs = 1;
16451: ($instcodeform,$jscript,$$numtitlesref) =
16452: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16453: $officialjs,$codetitlesref);
16454: if ($jscript) {
16455: $jscript = '<script type="text/javascript">'."\n".
16456: '// <![CDATA['."\n".
16457: $jscript."\n".
16458: '// ]]>'."\n".
16459: '</script>'."\n";
16460: }
16461: }
16462: if ($instcodeform eq '') {
16463: $instcodeform =
16464: '<input type="text" name="instcodefilter" size="10" value="'.
16465: $list->{'instcodefilter'}.'" />';
16466: $instcodetitle = $lt{'ins'};
16467: } else {
16468: $instcodetitle = $lt{'inc'};
16469: }
16470: if ($fixeddom) {
16471: $instcodetitle .= '<br />('.$codedom.')';
16472: }
16473: }
16474: }
16475: my $output = qq|
16476: <form method="post" name="filterpicker" action="$action">
16477: <input type="hidden" name="form" value="$formname" />
16478: |;
16479: if ($formname eq 'modifycourse') {
16480: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16481: '<input type="hidden" name="prevphase" value="'.
16482: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16483: } elsif ($formname eq 'quotacheck') {
16484: $output .= qq|
16485: <input type="hidden" name="sortby" value="" />
16486: <input type="hidden" name="sortorder" value="" />
16487: |;
16488: } else {
1.1075.2.69 raeburn 16489: my $name_input;
16490: if ($cnameelement ne '') {
16491: $name_input = '<input type="hidden" name="cnameelement" value="'.
16492: $cnameelement.'" />';
16493: }
16494: $output .= qq|
16495: <input type="hidden" name="cnumelement" value="$cnumelement" />
16496: <input type="hidden" name="cdomelement" value="$cdomelement" />
16497: $name_input
16498: $roleelement
16499: $multelement
16500: $typeelement
16501: |;
16502: if ($formname eq 'portform') {
16503: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16504: }
16505: }
16506: if ($fixeddom) {
16507: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16508: }
16509: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16510: if ($sincefilterform) {
16511: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16512: .$sincefilterform
16513: .&Apache::lonhtmlcommon::row_closure();
16514: }
16515: if ($createdfilterform) {
16516: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16517: .$createdfilterform
16518: .&Apache::lonhtmlcommon::row_closure();
16519: }
16520: if ($domainselectform) {
16521: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16522: .$domainselectform
16523: .&Apache::lonhtmlcommon::row_closure();
16524: }
16525: if ($typeselectform) {
16526: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16527: $output .= $typeselectform;
16528: } else {
16529: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16530: .$typeselectform
16531: .&Apache::lonhtmlcommon::row_closure();
16532: }
16533: }
16534: if ($instcodeform) {
16535: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16536: .$instcodeform
16537: .&Apache::lonhtmlcommon::row_closure();
16538: }
16539: if (exists($filter->{'ownerfilter'})) {
16540: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16541: '<table><tr><td>'.&mt('Username').'<br />'.
16542: '<input type="text" name="ownerfilter" size="20" value="'.
16543: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16544: $ownerdomselectform.'</td></tr></table>'.
16545: &Apache::lonhtmlcommon::row_closure();
16546: }
16547: if (exists($filter->{'personfilter'})) {
16548: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16549: '<table><tr><td>'.&mt('Username').'<br />'.
16550: '<input type="text" name="personfilter" size="20" value="'.
16551: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16552: $persondomselectform.'</td></tr></table>'.
16553: &Apache::lonhtmlcommon::row_closure();
16554: }
16555: if (exists($filter->{'coursefilter'})) {
16556: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16557: .'<input type="text" name="coursefilter" size="25" value="'
16558: .$list->{'coursefilter'}.'" />'
16559: .&Apache::lonhtmlcommon::row_closure();
16560: }
16561: if ($cloneableonlyform) {
16562: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16563: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16564: }
16565: if (exists($filter->{'descriptfilter'})) {
16566: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16567: .'<input type="text" name="descriptfilter" size="40" value="'
16568: .$list->{'descriptfilter'}.'" />'
16569: .&Apache::lonhtmlcommon::row_closure(1);
16570: }
16571: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16572: '<input type="hidden" name="updater" value="" />'."\n".
16573: '<input type="submit" name="gosearch" value="'.
16574: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16575: return $jscript.$clonewarning.$output;
16576: }
16577:
16578: =pod
16579:
16580: =item * &timebased_select_form()
16581:
16582: Create markup for a dropdown list used to select a time-based
16583: filter e.g., Course Activity, Course Created, when searching for courses
16584: or communities
16585:
16586: Inputs:
16587:
16588: item - name of form element (sincefilter or createdfilter)
16589:
16590: filter - anonymous hash of criteria and their values
16591:
16592: Returns: HTML for a select box contained a blank, then six time selections,
16593: with value set in incoming form variables currently selected.
16594:
16595: Side Effects: None
16596:
16597: =cut
16598:
16599: sub timebased_select_form {
16600: my ($item,$filter) = @_;
16601: if (ref($filter) eq 'HASH') {
16602: $filter->{$item} =~ s/[^\d-]//g;
16603: if (!$filter->{$item}) { $filter->{$item}=-1; }
16604: return &select_form(
16605: $filter->{$item},
16606: $item,
16607: { '-1' => '',
16608: '86400' => &mt('today'),
16609: '604800' => &mt('last week'),
16610: '2592000' => &mt('last month'),
16611: '7776000' => &mt('last three months'),
16612: '15552000' => &mt('last six months'),
16613: '31104000' => &mt('last year'),
16614: 'select_form_order' =>
16615: ['-1','86400','604800','2592000','7776000',
16616: '15552000','31104000']});
16617: }
16618: }
16619:
16620: =pod
16621:
16622: =item * &js_changer()
16623:
16624: Create script tag containing Javascript used to submit course search form
16625: when course type or domain is changed, and also to hide 'Searching ...' on
16626: page load completion for page showing search result.
16627:
16628: Inputs: None
16629:
16630: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16631:
16632: Side Effects: None
16633:
16634: =cut
16635:
16636: sub js_changer {
16637: return <<ENDJS;
16638: <script type="text/javascript">
16639: // <![CDATA[
16640: function updateFilters(caller) {
16641: if (typeof(caller) != "undefined") {
16642: document.filterpicker.updater.value = caller.name;
16643: }
16644: document.filterpicker.submit();
16645: }
16646:
16647: function hideSearching() {
16648: if (document.getElementById('searching')) {
16649: document.getElementById('searching').style.display = 'none';
16650: }
16651: return;
16652: }
16653:
16654: // ]]>
16655: </script>
16656:
16657: ENDJS
16658: }
16659:
16660: =pod
16661:
16662: =item * &search_courses()
16663:
16664: Process selected filters form course search form and pass to lonnet::courseiddump
16665: to retrieve a hash for which keys are courseIDs which match the selected filters.
16666:
16667: Inputs:
16668:
16669: dom - domain being searched
16670:
16671: type - course type ('Course' or 'Community' or '.' if any).
16672:
16673: filter - anonymous hash of criteria and their values
16674:
16675: numtitles - for institutional codes - number of categories
16676:
16677: cloneruname - optional username of new course owner
16678:
16679: clonerudom - optional domain of new course owner
16680:
1.1075.2.95 raeburn 16681: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16682: (used when DC is using course creation form)
16683:
16684: codetitles - reference to array of titles of components in institutional codes (official courses).
16685:
1.1075.2.95 raeburn 16686: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16687: (and so can clone automatically)
16688:
16689: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16690:
16691: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16692: courses to clone
1.1075.2.69 raeburn 16693:
16694: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16695:
16696:
16697: Side Effects: None
16698:
16699: =cut
16700:
16701:
16702: sub search_courses {
1.1075.2.95 raeburn 16703: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16704: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16705: my (%courses,%showcourses,$cloner);
16706: if (($filter->{'ownerfilter'} ne '') ||
16707: ($filter->{'ownerdomfilter'} ne '')) {
16708: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16709: $filter->{'ownerdomfilter'};
16710: }
16711: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16712: if (!$filter->{$item}) {
16713: $filter->{$item}='.';
16714: }
16715: }
16716: my $now = time;
16717: my $timefilter =
16718: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16719: my ($createdbefore,$createdafter);
16720: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16721: $createdbefore = $now;
16722: $createdafter = $now-$filter->{'createdfilter'};
16723: }
16724: my ($instcodefilter,$regexpok);
16725: if ($numtitles) {
16726: if ($env{'form.official'} eq 'on') {
16727: $instcodefilter =
16728: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16729: $regexpok = 1;
16730: } elsif ($env{'form.official'} eq 'off') {
16731: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16732: unless ($instcodefilter eq '') {
16733: $regexpok = -1;
16734: }
16735: }
16736: } else {
16737: $instcodefilter = $filter->{'instcodefilter'};
16738: }
16739: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16740: if ($type eq '') { $type = '.'; }
16741:
16742: if (($clonerudom ne '') && ($cloneruname ne '')) {
16743: $cloner = $cloneruname.':'.$clonerudom;
16744: }
16745: %courses = &Apache::lonnet::courseiddump($dom,
16746: $filter->{'descriptfilter'},
16747: $timefilter,
16748: $instcodefilter,
16749: $filter->{'combownerfilter'},
16750: $filter->{'coursefilter'},
16751: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16752: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16753: $filter->{'cloneableonly'},
16754: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16755: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16756: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16757: my $ccrole;
16758: if ($type eq 'Community') {
16759: $ccrole = 'co';
16760: } else {
16761: $ccrole = 'cc';
16762: }
16763: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16764: $filter->{'persondomfilter'},
16765: 'userroles',undef,
16766: [$ccrole,'in','ad','ep','ta','cr'],
16767: $dom);
16768: foreach my $role (keys(%rolehash)) {
16769: my ($cnum,$cdom,$courserole) = split(':',$role);
16770: my $cid = $cdom.'_'.$cnum;
16771: if (exists($courses{$cid})) {
16772: if (ref($courses{$cid}) eq 'HASH') {
16773: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16774: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16775: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16776: }
16777: } else {
16778: $courses{$cid}{roles} = [$courserole];
16779: }
16780: $showcourses{$cid} = $courses{$cid};
16781: }
16782: }
16783: }
16784: %courses = %showcourses;
16785: }
16786: return %courses;
16787: }
16788:
16789: =pod
16790:
16791: =back
16792:
1.1075.2.88 raeburn 16793: =head1 Routines for version requirements for current course.
16794:
16795: =over 4
16796:
16797: =item * &check_release_required()
16798:
16799: Compares required LON-CAPA version with version on server, and
16800: if required version is newer looks for a server with the required version.
16801:
16802: Looks first at servers in user's owen domain; if none suitable, looks at
16803: servers in course's domain are permitted to host sessions for user's domain.
16804:
16805: Inputs:
16806:
16807: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16808:
16809: $courseid - Course ID of current course
16810:
16811: $rolecode - User's current role in course (for switchserver query string).
16812:
16813: $required - LON-CAPA version needed by course (format: Major.Minor).
16814:
16815:
16816: Returns:
16817:
16818: $switchserver - query string tp append to /adm/switchserver call (if
16819: current server's LON-CAPA version is too old.
16820:
16821: $warning - Message is displayed if no suitable server could be found.
16822:
16823: =cut
16824:
16825: sub check_release_required {
16826: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16827: my ($switchserver,$warning);
16828: if ($required ne '') {
16829: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16830: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16831: if ($reqdmajor ne '' && $reqdminor ne '') {
16832: my $otherserver;
16833: if (($major eq '' && $minor eq '') ||
16834: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16835: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16836: my $switchlcrev =
16837: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16838: $userdomserver);
16839: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16840: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16841: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16842: my $cdom = $env{'course.'.$courseid.'.domain'};
16843: if ($cdom ne $env{'user.domain'}) {
16844: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16845: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16846: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16847: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16848: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16849: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16850: my $canhost =
16851: &Apache::lonnet::can_host_session($env{'user.domain'},
16852: $coursedomserver,
16853: $remoterev,
16854: $udomdefaults{'remotesessions'},
16855: $defdomdefaults{'hostedsessions'});
16856:
16857: if ($canhost) {
16858: $otherserver = $coursedomserver;
16859: } else {
16860: $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.");
16861: }
16862: } else {
16863: $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).");
16864: }
16865: } else {
16866: $otherserver = $userdomserver;
16867: }
16868: }
16869: if ($otherserver ne '') {
16870: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16871: }
16872: }
16873: }
16874: return ($switchserver,$warning);
16875: }
16876:
16877: =pod
16878:
16879: =item * &check_release_result()
16880:
16881: Inputs:
16882:
16883: $switchwarning - Warning message if no suitable server found to host session.
16884:
16885: $switchserver - query string to append to /adm/switchserver containing lonHostID
16886: and current role.
16887:
16888: Returns: HTML to display with information about requirement to switch server.
16889: Either displaying warning with link to Roles/Courses screen or
16890: display link to switchserver.
16891:
1.1075.2.69 raeburn 16892: =cut
16893:
1.1075.2.88 raeburn 16894: sub check_release_result {
16895: my ($switchwarning,$switchserver) = @_;
16896: my $output = &start_page('Selected course unavailable on this server').
16897: '<p class="LC_warning">';
16898: if ($switchwarning) {
16899: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16900: if (&show_course()) {
16901: $output .= &mt('Display courses');
16902: } else {
16903: $output .= &mt('Display roles');
16904: }
16905: $output .= '</a>';
16906: } elsif ($switchserver) {
16907: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16908: '<br />'.
16909: '<a href="/adm/switchserver?'.$switchserver.'">'.
16910: &mt('Switch Server').
16911: '</a>';
16912: }
16913: $output .= '</p>'.&end_page();
16914: return $output;
16915: }
16916:
16917: =pod
16918:
16919: =item * &needs_coursereinit()
16920:
16921: Determine if course contents stored for user's session needs to be
16922: refreshed, because content has changed since "Big Hash" last tied.
16923:
16924: Check for change is made if time last checked is more than 10 minutes ago
16925: (by default).
16926:
16927: Inputs:
16928:
16929: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16930:
16931: $interval (optional) - Time which may elapse (in s) between last check for content
16932: change in current course. (default: 600 s).
16933:
16934: Returns: an array; first element is:
16935:
16936: =over 4
16937:
16938: 'switch' - if content updates mean user's session
16939: needs to be switched to a server running a newer LON-CAPA version
16940:
16941: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16942: on current server hosting user's session
16943:
16944: '' - if no action required.
16945:
16946: =back
16947:
16948: If first item element is 'switch':
16949:
16950: second item is $switchwarning - Warning message if no suitable server found to host session.
16951:
16952: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16953: and current role.
16954:
16955: otherwise: no other elements returned.
16956:
16957: =back
16958:
16959: =cut
16960:
16961: sub needs_coursereinit {
16962: my ($loncaparev,$interval) = @_;
16963: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16964: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16965: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16966: my $now = time;
16967: if ($interval eq '') {
16968: $interval = 600;
16969: }
16970: if (($now-$env{'request.course.timechecked'})>$interval) {
16971: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16972: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16973: if ($lastchange > $env{'request.course.tied'}) {
16974: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16975: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16976: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16977: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16978: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16979: $curr_reqd_hash{'internal.releaserequired'}});
16980: my ($switchserver,$switchwarning) =
16981: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16982: $curr_reqd_hash{'internal.releaserequired'});
16983: if ($switchwarning ne '' || $switchserver ne '') {
16984: return ('switch',$switchwarning,$switchserver);
16985: }
16986: }
16987: }
16988: return ('update');
16989: }
16990: }
16991: return ();
16992: }
1.1075.2.69 raeburn 16993:
1.1075.2.11 raeburn 16994: sub update_content_constraints {
16995: my ($cdom,$cnum,$chome,$cid) = @_;
16996: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16997: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16998: my %checkresponsetypes;
16999: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
17000: my ($item,$name,$value) = split(/:/,$key);
17001: if ($item eq 'resourcetag') {
17002: if ($name eq 'responsetype') {
17003: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17004: }
17005: }
17006: }
17007: my $navmap = Apache::lonnavmaps::navmap->new();
17008: if (defined($navmap)) {
17009: my %allresponses;
17010: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17011: my %responses = $res->responseTypes();
17012: foreach my $key (keys(%responses)) {
17013: next unless(exists($checkresponsetypes{$key}));
17014: $allresponses{$key} += $responses{$key};
17015: }
17016: }
17017: foreach my $key (keys(%allresponses)) {
17018: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17019: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17020: ($reqdmajor,$reqdminor) = ($major,$minor);
17021: }
17022: }
17023: undef($navmap);
17024: }
17025: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17026: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17027: }
17028: return;
17029: }
17030:
1.1075.2.27 raeburn 17031: sub allmaps_incourse {
17032: my ($cdom,$cnum,$chome,$cid) = @_;
17033: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17034: $cid = $env{'request.course.id'};
17035: $cdom = $env{'course.'.$cid.'.domain'};
17036: $cnum = $env{'course.'.$cid.'.num'};
17037: $chome = $env{'course.'.$cid.'.home'};
17038: }
17039: my %allmaps = ();
17040: my $lastchange =
17041: &Apache::lonnet::get_coursechange($cdom,$cnum);
17042: if ($lastchange > $env{'request.course.tied'}) {
17043: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17044: unless ($ferr) {
17045: &update_content_constraints($cdom,$cnum,$chome,$cid);
17046: }
17047: }
17048: my $navmap = Apache::lonnavmaps::navmap->new();
17049: if (defined($navmap)) {
17050: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17051: $allmaps{$res->src()} = 1;
17052: }
17053: }
17054: return \%allmaps;
17055: }
17056:
1.1075.2.11 raeburn 17057: sub parse_supplemental_title {
17058: my ($title) = @_;
17059:
17060: my ($foldertitle,$renametitle);
17061: if ($title =~ /&&&/) {
17062: $title = &HTML::Entites::decode($title);
17063: }
17064: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17065: $renametitle=$4;
17066: my ($time,$uname,$udom) = ($1,$2,$3);
17067: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17068: my $name = &plainname($uname,$udom);
17069: $name = &HTML::Entities::encode($name,'"<>&\'');
17070: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17071: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17072: $name.': <br />'.$foldertitle;
17073: }
17074: if (wantarray) {
17075: return ($title,$foldertitle,$renametitle);
17076: }
17077: return $title;
17078: }
17079:
1.1075.2.43 raeburn 17080: sub recurse_supplemental {
17081: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
17082: if ($suppmap) {
17083: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17084: if ($fatal) {
17085: $errors ++;
17086: } else {
17087: if ($#LONCAPA::map::resources > 0) {
17088: foreach my $res (@LONCAPA::map::resources) {
17089: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17090: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 17091: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
17092: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 17093: } else {
17094: $numfiles ++;
17095: }
17096: }
17097: }
17098: }
17099: }
17100: }
17101: return ($numfiles,$errors);
17102: }
17103:
1.1075.2.18 raeburn 17104: sub symb_to_docspath {
1.1075.2.119 raeburn 17105: my ($symb,$navmapref) = @_;
17106: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 17107: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17108: if ($resurl=~/\.(sequence|page)$/) {
17109: $mapurl=$resurl;
17110: } elsif ($resurl eq 'adm/navmaps') {
17111: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17112: }
17113: my $mapresobj;
1.1075.2.119 raeburn 17114: unless (ref($$navmapref)) {
17115: $$navmapref = Apache::lonnavmaps::navmap->new();
17116: }
17117: if (ref($$navmapref)) {
17118: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 17119: }
17120: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17121: my $type=$2;
17122: my $path;
17123: if (ref($mapresobj)) {
17124: my $pcslist = $mapresobj->map_hierarchy();
17125: if ($pcslist ne '') {
17126: foreach my $pc (split(/,/,$pcslist)) {
17127: next if ($pc <= 1);
1.1075.2.119 raeburn 17128: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 17129: if (ref($res)) {
17130: my $thisurl = $res->src();
17131: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17132: my $thistitle = $res->title();
17133: $path .= '&'.
17134: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 17135: &escape($thistitle).
1.1075.2.18 raeburn 17136: ':'.$res->randompick().
17137: ':'.$res->randomout().
17138: ':'.$res->encrypted().
17139: ':'.$res->randomorder().
17140: ':'.$res->is_page();
17141: }
17142: }
17143: }
17144: $path =~ s/^\&//;
17145: my $maptitle = $mapresobj->title();
17146: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17147: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17148: }
17149: $path .= (($path ne '')? '&' : '').
17150: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17151: &escape($maptitle).
1.1075.2.18 raeburn 17152: ':'.$mapresobj->randompick().
17153: ':'.$mapresobj->randomout().
17154: ':'.$mapresobj->encrypted().
17155: ':'.$mapresobj->randomorder().
17156: ':'.$mapresobj->is_page();
17157: } else {
17158: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17159: my $ispage = (($type eq 'page')? 1 : '');
17160: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17161: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17162: }
17163: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17164: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 17165: }
17166: unless ($mapurl eq 'default') {
17167: $path = 'default&'.
1.1075.2.46 raeburn 17168: &escape('Main Content').
1.1075.2.18 raeburn 17169: ':::::&'.$path;
17170: }
17171: return $path;
17172: }
17173:
1.1075.2.14 raeburn 17174: sub captcha_display {
1.1075.2.137 raeburn 17175: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17176: my ($output,$error);
1.1075.2.107 raeburn 17177: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 17178: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17179: if ($captcha eq 'original') {
17180: $output = &create_captcha();
17181: unless ($output) {
17182: $error = 'captcha';
17183: }
17184: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17185: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 17186: unless ($output) {
17187: $error = 'recaptcha';
17188: }
17189: }
1.1075.2.107 raeburn 17190: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 17191: }
17192:
17193: sub captcha_response {
1.1075.2.137 raeburn 17194: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17195: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 17196: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17197: if ($captcha eq 'original') {
17198: ($captcha_chk,$captcha_error) = &check_captcha();
17199: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17200: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 17201: } else {
17202: $captcha_chk = 1;
17203: }
17204: return ($captcha_chk,$captcha_error);
17205: }
17206:
17207: sub get_captcha_config {
1.1075.2.137 raeburn 17208: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 17209: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 17210: my $hostname = &Apache::lonnet::hostname($lonhost);
17211: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17212: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17213: if ($context eq 'usercreation') {
17214: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17215: if (ref($domconfig{$context}) eq 'HASH') {
17216: $hashtocheck = $domconfig{$context}{'cancreate'};
17217: if (ref($hashtocheck) eq 'HASH') {
17218: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17219: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17220: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17221: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17222: }
17223: if ($privkey && $pubkey) {
17224: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17225: $version = $hashtocheck->{'recaptchaversion'};
17226: if ($version ne '2') {
17227: $version = 1;
17228: }
1.1075.2.14 raeburn 17229: } else {
17230: $captcha = 'original';
17231: }
17232: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17233: $captcha = 'original';
17234: }
17235: }
17236: } else {
17237: $captcha = 'captcha';
17238: }
17239: } elsif ($context eq 'login') {
17240: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17241: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17242: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17243: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
17244: if ($privkey && $pubkey) {
17245: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17246: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17247: if ($version ne '2') {
17248: $version = 1;
17249: }
1.1075.2.14 raeburn 17250: } else {
17251: $captcha = 'original';
17252: }
17253: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17254: $captcha = 'original';
17255: }
1.1075.2.137 raeburn 17256: } elsif ($context eq 'passwords') {
17257: if ($dom_in_effect) {
17258: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17259: if ($passwdconf{'captcha'} eq 'recaptcha') {
17260: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17261: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17262: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17263: }
17264: if ($privkey && $pubkey) {
17265: $captcha = 'recaptcha';
17266: $version = $passwdconf{'recaptchaversion'};
17267: if ($version ne '2') {
17268: $version = 1;
17269: }
17270: } else {
17271: $captcha = 'original';
17272: }
17273: } elsif ($passwdconf{'captcha'} ne 'notused') {
17274: $captcha = 'original';
17275: }
17276: }
1.1075.2.14 raeburn 17277: }
1.1075.2.107 raeburn 17278: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 17279: }
17280:
17281: sub create_captcha {
17282: my %captcha_params = &captcha_settings();
17283: my ($output,$maxtries,$tries) = ('',10,0);
17284: while ($tries < $maxtries) {
17285: $tries ++;
17286: my $captcha = Authen::Captcha->new (
17287: output_folder => $captcha_params{'output_dir'},
17288: data_folder => $captcha_params{'db_dir'},
17289: );
17290: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17291:
17292: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17293: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1075.2.158 raeburn 17294: '<span class="LC_nobreak">'.
1.1075.2.14 raeburn 17295: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 17296: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
1.1075.2.158 raeburn 17297: '</span><br />'.
1.1075.2.66 raeburn 17298: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 17299: last;
17300: }
17301: }
1.1075.2.158 raeburn 17302: if ($output eq '') {
17303: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
17304: }
1.1075.2.14 raeburn 17305: return $output;
17306: }
17307:
17308: sub captcha_settings {
17309: my %captcha_params = (
17310: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17311: www_output_dir => "/captchaspool",
17312: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17313: numchars => '5',
17314: );
17315: return %captcha_params;
17316: }
17317:
17318: sub check_captcha {
17319: my ($captcha_chk,$captcha_error);
17320: my $code = $env{'form.code'};
17321: my $md5sum = $env{'form.crypt'};
17322: my %captcha_params = &captcha_settings();
17323: my $captcha = Authen::Captcha->new(
17324: output_folder => $captcha_params{'output_dir'},
17325: data_folder => $captcha_params{'db_dir'},
17326: );
1.1075.2.26 raeburn 17327: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 17328: my %captcha_hash = (
17329: 0 => 'Code not checked (file error)',
17330: -1 => 'Failed: code expired',
17331: -2 => 'Failed: invalid code (not in database)',
17332: -3 => 'Failed: invalid code (code does not match crypt)',
17333: );
17334: if ($captcha_chk != 1) {
17335: $captcha_error = $captcha_hash{$captcha_chk}
17336: }
17337: return ($captcha_chk,$captcha_error);
17338: }
17339:
17340: sub create_recaptcha {
1.1075.2.107 raeburn 17341: my ($pubkey,$version) = @_;
17342: if ($version >= 2) {
1.1075.2.158 raeburn 17343: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
17344: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1075.2.107 raeburn 17345: } else {
17346: my $use_ssl;
17347: if ($ENV{'SERVER_PORT'} == 443) {
17348: $use_ssl = 1;
17349: }
17350: my $captcha = Captcha::reCAPTCHA->new;
17351: return $captcha->get_options_setter({theme => 'white'})."\n".
17352: $captcha->get_html($pubkey,undef,$use_ssl).
17353: &mt('If the text is hard to read, [_1] will replace them.',
17354: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17355: '<br /><br />';
17356: }
1.1075.2.14 raeburn 17357: }
17358:
17359: sub check_recaptcha {
1.1075.2.107 raeburn 17360: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 17361: my $captcha_chk;
1.1075.2.150 raeburn 17362: my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 17363: if ($version >= 2) {
17364: my $ua = LWP::UserAgent->new;
17365: $ua->timeout(10);
17366: my %info = (
17367: secret => $privkey,
17368: response => $env{'form.g-recaptcha-response'},
1.1075.2.150 raeburn 17369: remoteip => $ip,
1.1075.2.107 raeburn 17370: );
17371: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17372: if ($response->is_success) {
17373: my $data = JSON::DWIW->from_json($response->decoded_content);
17374: if (ref($data) eq 'HASH') {
17375: if ($data->{'success'}) {
17376: $captcha_chk = 1;
17377: }
17378: }
17379: }
17380: } else {
17381: my $captcha = Captcha::reCAPTCHA->new;
17382: my $captcha_result =
17383: $captcha->check_answer(
17384: $privkey,
1.1075.2.150 raeburn 17385: $ip,
1.1075.2.107 raeburn 17386: $env{'form.recaptcha_challenge_field'},
17387: $env{'form.recaptcha_response_field'},
17388: );
17389: if ($captcha_result->{is_valid}) {
17390: $captcha_chk = 1;
17391: }
1.1075.2.14 raeburn 17392: }
17393: return $captcha_chk;
17394: }
17395:
1.1075.2.64 raeburn 17396: sub emailusername_info {
1.1075.2.103 raeburn 17397: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 17398: my %titles = &Apache::lonlocal::texthash (
17399: lastname => 'Last Name',
17400: firstname => 'First Name',
17401: institution => 'School/college/university',
17402: location => "School's city, state/province, country",
17403: web => "School's web address",
17404: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 17405: id => 'Student/Employee ID',
1.1075.2.64 raeburn 17406: );
17407: return (\@fields,\%titles);
17408: }
17409:
1.1075.2.56 raeburn 17410: sub cleanup_html {
17411: my ($incoming) = @_;
17412: my $outgoing;
17413: if ($incoming ne '') {
17414: $outgoing = $incoming;
17415: $outgoing =~ s/;/;/g;
17416: $outgoing =~ s/\#/#/g;
17417: $outgoing =~ s/\&/&/g;
17418: $outgoing =~ s/</</g;
17419: $outgoing =~ s/>/>/g;
17420: $outgoing =~ s/\(/(/g;
17421: $outgoing =~ s/\)/)/g;
17422: $outgoing =~ s/"/"/g;
17423: $outgoing =~ s/'/'/g;
17424: $outgoing =~ s/\$/$/g;
17425: $outgoing =~ s{/}{/}g;
17426: $outgoing =~ s/=/=/g;
17427: $outgoing =~ s/\\/\/g
17428: }
17429: return $outgoing;
17430: }
17431:
1.1075.2.74 raeburn 17432: # Checks for critical messages and returns a redirect url if one exists.
17433: # $interval indicates how often to check for messages.
17434: sub critical_redirect {
17435: my ($interval) = @_;
1.1075.2.158 raeburn 17436: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
17437: return ();
17438: }
1.1075.2.74 raeburn 17439: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17440: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17441: $env{'user.name'});
17442: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17443: my $redirecturl;
17444: if ($what[0]) {
1.1075.2.158 raeburn 17445: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1075.2.74 raeburn 17446: $redirecturl='/adm/email?critical=display';
17447: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17448: return (1, $url);
17449: }
17450: }
17451: }
17452: return ();
17453: }
17454:
1.1075.2.64 raeburn 17455: # Use:
17456: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17457: #
17458: ##################################################
17459: # password associated functions #
17460: ##################################################
17461: sub des_keys {
17462: # Make a new key for DES encryption.
17463: # Each key has two parts which are returned separately.
17464: # Please note: Each key must be passed through the &hex function
17465: # before it is output to the web browser. The hex versions cannot
17466: # be used to decrypt.
17467: my @hexstr=('0','1','2','3','4','5','6','7',
17468: '8','9','a','b','c','d','e','f');
17469: my $lkey='';
17470: for (0..7) {
17471: $lkey.=$hexstr[rand(15)];
17472: }
17473: my $ukey='';
17474: for (0..7) {
17475: $ukey.=$hexstr[rand(15)];
17476: }
17477: return ($lkey,$ukey);
17478: }
17479:
17480: sub des_decrypt {
17481: my ($key,$cyphertext) = @_;
17482: my $keybin=pack("H16",$key);
17483: my $cypher;
17484: if ($Crypt::DES::VERSION>=2.03) {
17485: $cypher=new Crypt::DES $keybin;
17486: } else {
17487: $cypher=new DES $keybin;
17488: }
1.1075.2.106 raeburn 17489: my $plaintext='';
17490: my $cypherlength = length($cyphertext);
17491: my $numchunks = int($cypherlength/32);
17492: for (my $j=0; $j<$numchunks; $j++) {
17493: my $start = $j*32;
17494: my $cypherblock = substr($cyphertext,$start,32);
17495: my $chunk =
17496: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17497: $chunk .=
17498: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17499: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17500: $plaintext .= $chunk;
17501: }
1.1075.2.64 raeburn 17502: return $plaintext;
17503: }
17504:
1.1075.2.135 raeburn 17505: sub is_nonframeable {
17506: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
17507: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
17508: return if (($remprotocol eq '') || ($remhost eq ''));
17509:
17510: $remprotocol = lc($remprotocol);
17511: $remhost = lc($remhost);
17512: my $remport = 80;
17513: if ($remprotocol eq 'https') {
17514: $remport = 443;
17515: }
17516: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
17517: if ($cached) {
17518: unless ($nocache) {
17519: if ($result) {
17520: return 1;
17521: } else {
17522: return 0;
17523: }
17524: }
17525: }
17526: my $uselink;
17527: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 17528: my $ua = LWP::UserAgent->new;
17529: $ua->timeout(5);
17530: my $response=$ua->request($request);
1.1075.2.135 raeburn 17531: if ($response->is_success()) {
17532: my $secpolicy = lc($response->header('content-security-policy'));
17533: my $xframeop = lc($response->header('x-frame-options'));
17534: $secpolicy =~ s/^\s+|\s+$//g;
17535: $xframeop =~ s/^\s+|\s+$//g;
17536: if (($secpolicy ne '') || ($xframeop ne '')) {
17537: my $remotehost = $remprotocol.'://'.$remhost;
17538: my ($origin,$protocol,$port);
17539: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17540: $port = $ENV{'SERVER_PORT'};
17541: } else {
17542: $port = 80;
17543: }
17544: if ($absolute eq '') {
17545: $protocol = 'http:';
17546: if ($port == 443) {
17547: $protocol = 'https:';
17548: }
17549: $origin = $protocol.'//'.lc($hostname);
17550: } else {
17551: $origin = lc($absolute);
17552: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17553: }
17554: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17555: my $framepolicy = $1;
17556: $framepolicy =~ s/^\s+|\s+$//g;
17557: my @policies = split(/\s+/,$framepolicy);
17558: if (@policies) {
17559: if (grep(/^\Q'none'\E$/,@policies)) {
17560: $uselink = 1;
17561: } else {
17562: $uselink = 1;
17563: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17564: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17565: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17566: undef($uselink);
17567: }
17568: if ($uselink) {
17569: if (grep(/^\Q'self'\E$/,@policies)) {
17570: if (($origin ne '') && ($remotehost eq $origin)) {
17571: undef($uselink);
17572: }
17573: }
17574: }
17575: if ($uselink) {
17576: my @possok;
17577: if ($ip ne '') {
17578: push(@possok,$ip);
17579: }
17580: my $hoststr = '';
17581: foreach my $part (reverse(split(/\./,$hostname))) {
17582: if ($hoststr eq '') {
17583: $hoststr = $part;
17584: } else {
17585: $hoststr = "$part.$hoststr";
17586: }
17587: if ($hoststr eq $hostname) {
17588: push(@possok,$hostname);
17589: } else {
17590: push(@possok,"*.$hoststr");
17591: }
17592: }
17593: if (@possok) {
17594: foreach my $poss (@possok) {
17595: last if (!$uselink);
17596: foreach my $policy (@policies) {
17597: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17598: undef($uselink);
17599: last;
17600: }
17601: }
17602: }
17603: }
17604: }
17605: }
17606: }
17607: } elsif ($xframeop ne '') {
17608: $uselink = 1;
17609: my @policies = split(/\s*,\s*/,$xframeop);
17610: if (@policies) {
17611: unless (grep(/^deny$/,@policies)) {
17612: if ($origin ne '') {
17613: if (grep(/^sameorigin$/,@policies)) {
17614: if ($remotehost eq $origin) {
17615: undef($uselink);
17616: }
17617: }
17618: if ($uselink) {
17619: foreach my $policy (@policies) {
17620: if ($policy =~ /^allow-from\s*(.+)$/) {
17621: my $allowfrom = $1;
17622: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17623: undef($uselink);
17624: last;
17625: }
17626: }
17627: }
17628: }
17629: }
17630: }
17631: }
17632: }
17633: }
17634: }
17635: if ($nocache) {
17636: if ($cached) {
17637: my $devalidate;
17638: if ($uselink && !$result) {
17639: $devalidate = 1;
17640: } elsif (!$uselink && $result) {
17641: $devalidate = 1;
17642: }
17643: if ($devalidate) {
17644: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17645: }
17646: }
17647: } else {
17648: if ($uselink) {
17649: $result = 1;
17650: } else {
17651: $result = 0;
17652: }
17653: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17654: }
17655: return $uselink;
17656: }
17657:
1.112 bowersj2 17658: 1;
17659: __END__;
1.41 ng 17660:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>