Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.164
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.164! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.163 2022/01/19 00:39:01 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.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.251 albertel 5996: return $endbodytag;
5997: }
5998:
1.352 albertel 5999: =pod
6000:
6001: =item * &standard_css()
6002:
6003: Returns a style sheet
6004:
6005: Inputs: (all optional)
6006: domain -> force to color decorate a page for a specific
6007: domain
6008: function -> force usage of a specific rolish color scheme
6009: bgcolor -> override the default page bgcolor
6010:
6011: =cut
6012:
1.343 albertel 6013: sub standard_css {
1.345 albertel 6014: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6015: $function = &get_users_function() if (!$function);
6016: my $img = &designparm($function.'.img', $domain);
6017: my $tabbg = &designparm($function.'.tabbg', $domain);
6018: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6019: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6020: #second colour for later usage
1.345 albertel 6021: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6022: my $pgbg_or_bgcolor =
6023: $bgcolor ||
1.352 albertel 6024: &designparm($function.'.pgbg', $domain);
1.382 albertel 6025: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6026: my $alink = &designparm($function.'.alink', $domain);
6027: my $vlink = &designparm($function.'.vlink', $domain);
6028: my $link = &designparm($function.'.link', $domain);
6029:
1.602 albertel 6030: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6031: my $mono = 'monospace';
1.850 bisitz 6032: my $data_table_head = $sidebg;
6033: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6034: my $data_table_dark = '#E0E0E0';
1.470 banghart 6035: my $data_table_darker = '#CCCCCC';
1.349 albertel 6036: my $data_table_highlight = '#FFFF00';
1.352 albertel 6037: my $mail_new = '#FFBB77';
6038: my $mail_new_hover = '#DD9955';
6039: my $mail_read = '#BBBB77';
6040: my $mail_read_hover = '#999944';
6041: my $mail_replied = '#AAAA88';
6042: my $mail_replied_hover = '#888855';
6043: my $mail_other = '#99BBBB';
6044: my $mail_other_hover = '#669999';
1.391 albertel 6045: my $table_header = '#DDDDDD';
1.489 raeburn 6046: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6047: my $lg_border_color = '#C8C8C8';
1.952 onken 6048: my $button_hover = '#BF2317';
1.392 albertel 6049:
1.608 albertel 6050: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6051: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6052: : '0 3px 0 4px';
1.448 albertel 6053:
1.523 albertel 6054:
1.343 albertel 6055: return <<END;
1.947 droeschl 6056:
6057: /* needed for iframe to allow 100% height in FF */
6058: body, html {
6059: margin: 0;
6060: padding: 0 0.5%;
6061: height: 99%; /* to avoid scrollbars */
6062: }
6063:
1.795 www 6064: body {
1.911 bisitz 6065: font-family: $sans;
6066: line-height:130%;
6067: font-size:0.83em;
6068: color:$font;
1.795 www 6069: }
6070:
1.959 onken 6071: a:focus,
6072: a:focus img {
1.795 www 6073: color: red;
6074: }
1.698 harmsja 6075:
1.911 bisitz 6076: form, .inline {
6077: display: inline;
1.795 www 6078: }
1.721 harmsja 6079:
1.795 www 6080: .LC_right {
1.911 bisitz 6081: text-align:right;
1.795 www 6082: }
6083:
6084: .LC_middle {
1.911 bisitz 6085: vertical-align:middle;
1.795 www 6086: }
1.721 harmsja 6087:
1.1075.2.38 raeburn 6088: .LC_floatleft {
6089: float: left;
6090: }
6091:
6092: .LC_floatright {
6093: float: right;
6094: }
6095:
1.911 bisitz 6096: .LC_400Box {
6097: width:400px;
6098: }
1.721 harmsja 6099:
1.947 droeschl 6100: .LC_iframecontainer {
6101: width: 98%;
6102: margin: 0;
6103: position: fixed;
6104: top: 8.5em;
6105: bottom: 0;
6106: }
6107:
6108: .LC_iframecontainer iframe{
6109: border: none;
6110: width: 100%;
6111: height: 100%;
6112: }
6113:
1.778 bisitz 6114: .LC_filename {
6115: font-family: $mono;
6116: white-space:pre;
1.921 bisitz 6117: font-size: 120%;
1.778 bisitz 6118: }
6119:
6120: .LC_fileicon {
6121: border: none;
6122: height: 1.3em;
6123: vertical-align: text-bottom;
6124: margin-right: 0.3em;
6125: text-decoration:none;
6126: }
6127:
1.1008 www 6128: .LC_setting {
6129: text-decoration:underline;
6130: }
6131:
1.350 albertel 6132: .LC_error {
6133: color: red;
6134: }
1.795 www 6135:
1.1075.2.15 raeburn 6136: .LC_warning {
6137: color: darkorange;
6138: }
6139:
1.457 albertel 6140: .LC_diff_removed {
1.733 bisitz 6141: color: red;
1.394 albertel 6142: }
1.532 albertel 6143:
6144: .LC_info,
1.457 albertel 6145: .LC_success,
6146: .LC_diff_added {
1.350 albertel 6147: color: green;
6148: }
1.795 www 6149:
1.802 bisitz 6150: div.LC_confirm_box {
6151: background-color: #FAFAFA;
6152: border: 1px solid $lg_border_color;
6153: margin-right: 0;
6154: padding: 5px;
6155: }
6156:
6157: div.LC_confirm_box .LC_error img,
6158: div.LC_confirm_box .LC_success img {
6159: vertical-align: middle;
6160: }
6161:
1.1075.2.108 raeburn 6162: .LC_maxwidth {
6163: max-width: 100%;
6164: height: auto;
6165: }
6166:
6167: .LC_textsize_mobile {
6168: \@media only screen and (max-device-width: 480px) {
6169: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6170: }
6171: }
6172:
1.440 albertel 6173: .LC_icon {
1.771 droeschl 6174: border: none;
1.790 droeschl 6175: vertical-align: middle;
1.771 droeschl 6176: }
6177:
1.543 albertel 6178: .LC_docs_spacer {
6179: width: 25px;
6180: height: 1px;
1.771 droeschl 6181: border: none;
1.543 albertel 6182: }
1.346 albertel 6183:
1.532 albertel 6184: .LC_internal_info {
1.735 bisitz 6185: color: #999999;
1.532 albertel 6186: }
6187:
1.794 www 6188: .LC_discussion {
1.1050 www 6189: background: $data_table_dark;
1.911 bisitz 6190: border: 1px solid black;
6191: margin: 2px;
1.794 www 6192: }
6193:
6194: .LC_disc_action_left {
1.1050 www 6195: background: $sidebg;
1.911 bisitz 6196: text-align: left;
1.1050 www 6197: padding: 4px;
6198: margin: 2px;
1.794 www 6199: }
6200:
6201: .LC_disc_action_right {
1.1050 www 6202: background: $sidebg;
1.911 bisitz 6203: text-align: right;
1.1050 www 6204: padding: 4px;
6205: margin: 2px;
1.794 www 6206: }
6207:
6208: .LC_disc_new_item {
1.911 bisitz 6209: background: white;
6210: border: 2px solid red;
1.1050 www 6211: margin: 4px;
6212: padding: 4px;
1.794 www 6213: }
6214:
6215: .LC_disc_old_item {
1.911 bisitz 6216: background: white;
1.1050 www 6217: margin: 4px;
6218: padding: 4px;
1.794 www 6219: }
6220:
1.458 albertel 6221: table.LC_pastsubmission {
6222: border: 1px solid black;
6223: margin: 2px;
6224: }
6225:
1.924 bisitz 6226: table#LC_menubuttons {
1.345 albertel 6227: width: 100%;
6228: background: $pgbg;
1.392 albertel 6229: border: 2px;
1.402 albertel 6230: border-collapse: separate;
1.803 bisitz 6231: padding: 0;
1.345 albertel 6232: }
1.392 albertel 6233:
1.801 tempelho 6234: table#LC_title_bar a {
6235: color: $fontmenu;
6236: }
1.836 bisitz 6237:
1.807 droeschl 6238: table#LC_title_bar {
1.819 tempelho 6239: clear: both;
1.836 bisitz 6240: display: none;
1.807 droeschl 6241: }
6242:
1.795 www 6243: table#LC_title_bar,
1.933 droeschl 6244: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6245: table#LC_title_bar.LC_with_remote {
1.359 albertel 6246: width: 100%;
1.392 albertel 6247: border-color: $pgbg;
6248: border-style: solid;
6249: border-width: $border;
1.379 albertel 6250: background: $pgbg;
1.801 tempelho 6251: color: $fontmenu;
1.392 albertel 6252: border-collapse: collapse;
1.803 bisitz 6253: padding: 0;
1.819 tempelho 6254: margin: 0;
1.359 albertel 6255: }
1.795 www 6256:
1.933 droeschl 6257: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6258: margin: 0;
6259: padding: 0;
1.933 droeschl 6260: position: relative;
6261: list-style: none;
1.913 droeschl 6262: }
1.933 droeschl 6263: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6264: display: inline;
6265: }
1.933 droeschl 6266:
6267: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6268: padding: 0;
1.933 droeschl 6269: margin: 0;
6270: float: left;
1.913 droeschl 6271: }
1.933 droeschl 6272: .LC_breadcrumb_tools_tools {
6273: padding: 0;
6274: margin: 0;
1.913 droeschl 6275: float: right;
6276: }
6277:
1.359 albertel 6278: table#LC_title_bar td {
6279: background: $tabbg;
6280: }
1.795 www 6281:
1.911 bisitz 6282: table#LC_menubuttons img {
1.803 bisitz 6283: border: none;
1.346 albertel 6284: }
1.795 www 6285:
1.842 droeschl 6286: .LC_breadcrumbs_component {
1.911 bisitz 6287: float: right;
6288: margin: 0 1em;
1.357 albertel 6289: }
1.842 droeschl 6290: .LC_breadcrumbs_component img {
1.911 bisitz 6291: vertical-align: middle;
1.777 tempelho 6292: }
1.795 www 6293:
1.1075.2.108 raeburn 6294: .LC_breadcrumbs_hoverable {
6295: background: $sidebg;
6296: }
6297:
1.383 albertel 6298: td.LC_table_cell_checkbox {
6299: text-align: center;
6300: }
1.795 www 6301:
6302: .LC_fontsize_small {
1.911 bisitz 6303: font-size: 70%;
1.705 tempelho 6304: }
6305:
1.844 bisitz 6306: #LC_breadcrumbs {
1.911 bisitz 6307: clear:both;
6308: background: $sidebg;
6309: border-bottom: 1px solid $lg_border_color;
6310: line-height: 2.5em;
1.933 droeschl 6311: overflow: hidden;
1.911 bisitz 6312: margin: 0;
6313: padding: 0;
1.995 raeburn 6314: text-align: left;
1.819 tempelho 6315: }
1.862 bisitz 6316:
1.1075.2.16 raeburn 6317: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6318: clear:both;
6319: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6320: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6321: margin: 0 0 10px 0;
1.966 bisitz 6322: padding: 3px;
1.995 raeburn 6323: text-align: left;
1.822 bisitz 6324: }
6325:
1.795 www 6326: .LC_fontsize_medium {
1.911 bisitz 6327: font-size: 85%;
1.705 tempelho 6328: }
6329:
1.795 www 6330: .LC_fontsize_large {
1.911 bisitz 6331: font-size: 120%;
1.705 tempelho 6332: }
6333:
1.346 albertel 6334: .LC_menubuttons_inline_text {
6335: color: $font;
1.698 harmsja 6336: font-size: 90%;
1.701 harmsja 6337: padding-left:3px;
1.346 albertel 6338: }
6339:
1.934 droeschl 6340: .LC_menubuttons_inline_text img{
6341: vertical-align: middle;
6342: }
6343:
1.1051 www 6344: li.LC_menubuttons_inline_text img {
1.951 onken 6345: cursor:pointer;
1.1002 droeschl 6346: text-decoration: none;
1.951 onken 6347: }
6348:
1.526 www 6349: .LC_menubuttons_link {
6350: text-decoration: none;
6351: }
1.795 www 6352:
1.522 albertel 6353: .LC_menubuttons_category {
1.521 www 6354: color: $font;
1.526 www 6355: background: $pgbg;
1.521 www 6356: font-size: larger;
6357: font-weight: bold;
6358: }
6359:
1.346 albertel 6360: td.LC_menubuttons_text {
1.911 bisitz 6361: color: $font;
1.346 albertel 6362: }
1.706 harmsja 6363:
1.346 albertel 6364: .LC_current_location {
6365: background: $tabbg;
6366: }
1.795 www 6367:
1.1075.2.134 raeburn 6368: td.LC_zero_height {
6369: line-height: 0;
6370: cellpadding: 0;
6371: }
6372:
1.938 bisitz 6373: table.LC_data_table {
1.347 albertel 6374: border: 1px solid #000000;
1.402 albertel 6375: border-collapse: separate;
1.426 albertel 6376: border-spacing: 1px;
1.610 albertel 6377: background: $pgbg;
1.347 albertel 6378: }
1.795 www 6379:
1.422 albertel 6380: .LC_data_table_dense {
6381: font-size: small;
6382: }
1.795 www 6383:
1.507 raeburn 6384: table.LC_nested_outer {
6385: border: 1px solid #000000;
1.589 raeburn 6386: border-collapse: collapse;
1.803 bisitz 6387: border-spacing: 0;
1.507 raeburn 6388: width: 100%;
6389: }
1.795 www 6390:
1.879 raeburn 6391: table.LC_innerpickbox,
1.507 raeburn 6392: table.LC_nested {
1.803 bisitz 6393: border: none;
1.589 raeburn 6394: border-collapse: collapse;
1.803 bisitz 6395: border-spacing: 0;
1.507 raeburn 6396: width: 100%;
6397: }
1.795 www 6398:
1.911 bisitz 6399: table.LC_data_table tr th,
6400: table.LC_calendar tr th,
1.879 raeburn 6401: table.LC_prior_tries tr th,
6402: table.LC_innerpickbox tr th {
1.349 albertel 6403: font-weight: bold;
6404: background-color: $data_table_head;
1.801 tempelho 6405: color:$fontmenu;
1.701 harmsja 6406: font-size:90%;
1.347 albertel 6407: }
1.795 www 6408:
1.879 raeburn 6409: table.LC_innerpickbox tr th,
6410: table.LC_innerpickbox tr td {
6411: vertical-align: top;
6412: }
6413:
1.711 raeburn 6414: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6415: background-color: #CCCCCC;
1.711 raeburn 6416: font-weight: bold;
6417: text-align: left;
6418: }
1.795 www 6419:
1.912 bisitz 6420: table.LC_data_table tr.LC_odd_row > td {
6421: background-color: $data_table_light;
6422: padding: 2px;
6423: vertical-align: top;
6424: }
6425:
1.809 bisitz 6426: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6427: background-color: $data_table_light;
1.912 bisitz 6428: vertical-align: top;
6429: }
6430:
6431: table.LC_data_table tr.LC_even_row > td {
6432: background-color: $data_table_dark;
1.425 albertel 6433: padding: 2px;
1.900 bisitz 6434: vertical-align: top;
1.347 albertel 6435: }
1.795 www 6436:
1.809 bisitz 6437: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6438: background-color: $data_table_dark;
1.900 bisitz 6439: vertical-align: top;
1.347 albertel 6440: }
1.795 www 6441:
1.425 albertel 6442: table.LC_data_table tr.LC_data_table_highlight td {
6443: background-color: $data_table_darker;
6444: }
1.795 www 6445:
1.639 raeburn 6446: table.LC_data_table tr td.LC_leftcol_header {
6447: background-color: $data_table_head;
6448: font-weight: bold;
6449: }
1.795 www 6450:
1.451 albertel 6451: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6452: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6453: font-weight: bold;
6454: font-style: italic;
6455: text-align: center;
6456: padding: 8px;
1.347 albertel 6457: }
1.795 www 6458:
1.1075.2.30 raeburn 6459: table.LC_data_table tr.LC_empty_row td,
6460: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6461: background-color: $sidebg;
6462: }
6463:
6464: table.LC_nested tr.LC_empty_row td {
6465: background-color: #FFFFFF;
6466: }
6467:
1.890 droeschl 6468: table.LC_caption {
6469: }
6470:
1.507 raeburn 6471: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6472: padding: 4ex
6473: }
1.795 www 6474:
1.507 raeburn 6475: table.LC_nested_outer tr th {
6476: font-weight: bold;
1.801 tempelho 6477: color:$fontmenu;
1.507 raeburn 6478: background-color: $data_table_head;
1.701 harmsja 6479: font-size: small;
1.507 raeburn 6480: border-bottom: 1px solid #000000;
6481: }
1.795 www 6482:
1.507 raeburn 6483: table.LC_nested_outer tr td.LC_subheader {
6484: background-color: $data_table_head;
6485: font-weight: bold;
6486: font-size: small;
6487: border-bottom: 1px solid #000000;
6488: text-align: right;
1.451 albertel 6489: }
1.795 www 6490:
1.507 raeburn 6491: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6492: background-color: #CCCCCC;
1.451 albertel 6493: font-weight: bold;
6494: font-size: small;
1.507 raeburn 6495: text-align: center;
6496: }
1.795 www 6497:
1.589 raeburn 6498: table.LC_nested tr.LC_info_row td.LC_left_item,
6499: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6500: text-align: left;
1.451 albertel 6501: }
1.795 www 6502:
1.507 raeburn 6503: table.LC_nested td {
1.735 bisitz 6504: background-color: #FFFFFF;
1.451 albertel 6505: font-size: small;
1.507 raeburn 6506: }
1.795 www 6507:
1.507 raeburn 6508: table.LC_nested_outer tr th.LC_right_item,
6509: table.LC_nested tr.LC_info_row td.LC_right_item,
6510: table.LC_nested tr.LC_odd_row td.LC_right_item,
6511: table.LC_nested tr td.LC_right_item {
1.451 albertel 6512: text-align: right;
6513: }
6514:
1.507 raeburn 6515: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6516: background-color: #EEEEEE;
1.451 albertel 6517: }
6518:
1.473 raeburn 6519: table.LC_createuser {
6520: }
6521:
6522: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6523: font-size: small;
1.473 raeburn 6524: }
6525:
6526: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6527: background-color: #CCCCCC;
1.473 raeburn 6528: font-weight: bold;
6529: text-align: center;
6530: }
6531:
1.349 albertel 6532: table.LC_calendar {
6533: border: 1px solid #000000;
6534: border-collapse: collapse;
1.917 raeburn 6535: width: 98%;
1.349 albertel 6536: }
1.795 www 6537:
1.349 albertel 6538: table.LC_calendar_pickdate {
6539: font-size: xx-small;
6540: }
1.795 www 6541:
1.349 albertel 6542: table.LC_calendar tr td {
6543: border: 1px solid #000000;
6544: vertical-align: top;
1.917 raeburn 6545: width: 14%;
1.349 albertel 6546: }
1.795 www 6547:
1.349 albertel 6548: table.LC_calendar tr td.LC_calendar_day_empty {
6549: background-color: $data_table_dark;
6550: }
1.795 www 6551:
1.779 bisitz 6552: table.LC_calendar tr td.LC_calendar_day_current {
6553: background-color: $data_table_highlight;
1.777 tempelho 6554: }
1.795 www 6555:
1.938 bisitz 6556: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6557: background-color: $mail_new;
6558: }
1.795 www 6559:
1.938 bisitz 6560: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6561: background-color: $mail_new_hover;
6562: }
1.795 www 6563:
1.938 bisitz 6564: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6565: background-color: $mail_read;
6566: }
1.795 www 6567:
1.938 bisitz 6568: /*
6569: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6570: background-color: $mail_read_hover;
6571: }
1.938 bisitz 6572: */
1.795 www 6573:
1.938 bisitz 6574: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6575: background-color: $mail_replied;
6576: }
1.795 www 6577:
1.938 bisitz 6578: /*
6579: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6580: background-color: $mail_replied_hover;
6581: }
1.938 bisitz 6582: */
1.795 www 6583:
1.938 bisitz 6584: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6585: background-color: $mail_other;
6586: }
1.795 www 6587:
1.938 bisitz 6588: /*
6589: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6590: background-color: $mail_other_hover;
6591: }
1.938 bisitz 6592: */
1.494 raeburn 6593:
1.777 tempelho 6594: table.LC_data_table tr > td.LC_browser_file,
6595: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6596: background: #AAEE77;
1.389 albertel 6597: }
1.795 www 6598:
1.777 tempelho 6599: table.LC_data_table tr > td.LC_browser_file_locked,
6600: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6601: background: #FFAA99;
1.387 albertel 6602: }
1.795 www 6603:
1.777 tempelho 6604: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6605: background: #888888;
1.779 bisitz 6606: }
1.795 www 6607:
1.777 tempelho 6608: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6609: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6610: background: #F8F866;
1.777 tempelho 6611: }
1.795 www 6612:
1.696 bisitz 6613: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6614: background: #E0E8FF;
1.387 albertel 6615: }
1.696 bisitz 6616:
1.707 bisitz 6617: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6618: /* background: #77FF77; */
1.707 bisitz 6619: }
1.795 www 6620:
1.707 bisitz 6621: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6622: border-right: 8px solid #FFFF77;
1.707 bisitz 6623: }
1.795 www 6624:
1.707 bisitz 6625: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6626: border-right: 8px solid #FFAA77;
1.707 bisitz 6627: }
1.795 www 6628:
1.707 bisitz 6629: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6630: border-right: 8px solid #FF7777;
1.707 bisitz 6631: }
1.795 www 6632:
1.707 bisitz 6633: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6634: border-right: 8px solid #AAFF77;
1.707 bisitz 6635: }
1.795 www 6636:
1.707 bisitz 6637: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6638: border-right: 8px solid #11CC55;
1.707 bisitz 6639: }
6640:
1.388 albertel 6641: span.LC_current_location {
1.701 harmsja 6642: font-size:larger;
1.388 albertel 6643: background: $pgbg;
6644: }
1.387 albertel 6645:
1.1029 www 6646: span.LC_current_nav_location {
6647: font-weight:bold;
6648: background: $sidebg;
6649: }
6650:
1.395 albertel 6651: span.LC_parm_menu_item {
6652: font-size: larger;
6653: }
1.795 www 6654:
1.395 albertel 6655: span.LC_parm_scope_all {
6656: color: red;
6657: }
1.795 www 6658:
1.395 albertel 6659: span.LC_parm_scope_folder {
6660: color: green;
6661: }
1.795 www 6662:
1.395 albertel 6663: span.LC_parm_scope_resource {
6664: color: orange;
6665: }
1.795 www 6666:
1.395 albertel 6667: span.LC_parm_part {
6668: color: blue;
6669: }
1.795 www 6670:
1.911 bisitz 6671: span.LC_parm_folder,
6672: span.LC_parm_symb {
1.395 albertel 6673: font-size: x-small;
6674: font-family: $mono;
6675: color: #AAAAAA;
6676: }
6677:
1.977 bisitz 6678: ul.LC_parm_parmlist li {
6679: display: inline-block;
6680: padding: 0.3em 0.8em;
6681: vertical-align: top;
6682: width: 150px;
6683: border-top:1px solid $lg_border_color;
6684: }
6685:
1.795 www 6686: td.LC_parm_overview_level_menu,
6687: td.LC_parm_overview_map_menu,
6688: td.LC_parm_overview_parm_selectors,
6689: td.LC_parm_overview_restrictions {
1.396 albertel 6690: border: 1px solid black;
6691: border-collapse: collapse;
6692: }
1.795 www 6693:
1.396 albertel 6694: table.LC_parm_overview_restrictions td {
6695: border-width: 1px 4px 1px 4px;
6696: border-style: solid;
6697: border-color: $pgbg;
6698: text-align: center;
6699: }
1.795 www 6700:
1.396 albertel 6701: table.LC_parm_overview_restrictions th {
6702: background: $tabbg;
6703: border-width: 1px 4px 1px 4px;
6704: border-style: solid;
6705: border-color: $pgbg;
6706: }
1.795 www 6707:
1.398 albertel 6708: table#LC_helpmenu {
1.803 bisitz 6709: border: none;
1.398 albertel 6710: height: 55px;
1.803 bisitz 6711: border-spacing: 0;
1.398 albertel 6712: }
6713:
6714: table#LC_helpmenu fieldset legend {
6715: font-size: larger;
6716: }
1.795 www 6717:
1.397 albertel 6718: table#LC_helpmenu_links {
6719: width: 100%;
6720: border: 1px solid black;
6721: background: $pgbg;
1.803 bisitz 6722: padding: 0;
1.397 albertel 6723: border-spacing: 1px;
6724: }
1.795 www 6725:
1.397 albertel 6726: table#LC_helpmenu_links tr td {
6727: padding: 1px;
6728: background: $tabbg;
1.399 albertel 6729: text-align: center;
6730: font-weight: bold;
1.397 albertel 6731: }
1.396 albertel 6732:
1.795 www 6733: table#LC_helpmenu_links a:link,
6734: table#LC_helpmenu_links a:visited,
1.397 albertel 6735: table#LC_helpmenu_links a:active {
6736: text-decoration: none;
6737: color: $font;
6738: }
1.795 www 6739:
1.397 albertel 6740: table#LC_helpmenu_links a:hover {
6741: text-decoration: underline;
6742: color: $vlink;
6743: }
1.396 albertel 6744:
1.417 albertel 6745: .LC_chrt_popup_exists {
6746: border: 1px solid #339933;
6747: margin: -1px;
6748: }
1.795 www 6749:
1.417 albertel 6750: .LC_chrt_popup_up {
6751: border: 1px solid yellow;
6752: margin: -1px;
6753: }
1.795 www 6754:
1.417 albertel 6755: .LC_chrt_popup {
6756: border: 1px solid #8888FF;
6757: background: #CCCCFF;
6758: }
1.795 www 6759:
1.421 albertel 6760: table.LC_pick_box {
6761: border-collapse: separate;
6762: background: white;
6763: border: 1px solid black;
6764: border-spacing: 1px;
6765: }
1.795 www 6766:
1.421 albertel 6767: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6768: background: $sidebg;
1.421 albertel 6769: font-weight: bold;
1.900 bisitz 6770: text-align: left;
1.740 bisitz 6771: vertical-align: top;
1.421 albertel 6772: width: 184px;
6773: padding: 8px;
6774: }
1.795 www 6775:
1.579 raeburn 6776: table.LC_pick_box td.LC_pick_box_value {
6777: text-align: left;
6778: padding: 8px;
6779: }
1.795 www 6780:
1.579 raeburn 6781: table.LC_pick_box td.LC_pick_box_select {
6782: text-align: left;
6783: padding: 8px;
6784: }
1.795 www 6785:
1.424 albertel 6786: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6787: padding: 0;
1.421 albertel 6788: height: 1px;
6789: background: black;
6790: }
1.795 www 6791:
1.421 albertel 6792: table.LC_pick_box td.LC_pick_box_submit {
6793: text-align: right;
6794: }
1.795 www 6795:
1.579 raeburn 6796: table.LC_pick_box td.LC_evenrow_value {
6797: text-align: left;
6798: padding: 8px;
6799: background-color: $data_table_light;
6800: }
1.795 www 6801:
1.579 raeburn 6802: table.LC_pick_box td.LC_oddrow_value {
6803: text-align: left;
6804: padding: 8px;
6805: background-color: $data_table_light;
6806: }
1.795 www 6807:
1.579 raeburn 6808: span.LC_helpform_receipt_cat {
6809: font-weight: bold;
6810: }
1.795 www 6811:
1.424 albertel 6812: table.LC_group_priv_box {
6813: background: white;
6814: border: 1px solid black;
6815: border-spacing: 1px;
6816: }
1.795 www 6817:
1.424 albertel 6818: table.LC_group_priv_box td.LC_pick_box_title {
6819: background: $tabbg;
6820: font-weight: bold;
6821: text-align: right;
6822: width: 184px;
6823: }
1.795 www 6824:
1.424 albertel 6825: table.LC_group_priv_box td.LC_groups_fixed {
6826: background: $data_table_light;
6827: text-align: center;
6828: }
1.795 www 6829:
1.424 albertel 6830: table.LC_group_priv_box td.LC_groups_optional {
6831: background: $data_table_dark;
6832: text-align: center;
6833: }
1.795 www 6834:
1.424 albertel 6835: table.LC_group_priv_box td.LC_groups_functionality {
6836: background: $data_table_darker;
6837: text-align: center;
6838: font-weight: bold;
6839: }
1.795 www 6840:
1.424 albertel 6841: table.LC_group_priv td {
6842: text-align: left;
1.803 bisitz 6843: padding: 0;
1.424 albertel 6844: }
6845:
6846: .LC_navbuttons {
6847: margin: 2ex 0ex 2ex 0ex;
6848: }
1.795 www 6849:
1.423 albertel 6850: .LC_topic_bar {
6851: font-weight: bold;
6852: background: $tabbg;
1.918 wenzelju 6853: margin: 1em 0em 1em 2em;
1.805 bisitz 6854: padding: 3px;
1.918 wenzelju 6855: font-size: 1.2em;
1.423 albertel 6856: }
1.795 www 6857:
1.423 albertel 6858: .LC_topic_bar span {
1.918 wenzelju 6859: left: 0.5em;
6860: position: absolute;
1.423 albertel 6861: vertical-align: middle;
1.918 wenzelju 6862: font-size: 1.2em;
1.423 albertel 6863: }
1.795 www 6864:
1.423 albertel 6865: table.LC_course_group_status {
6866: margin: 20px;
6867: }
1.795 www 6868:
1.423 albertel 6869: table.LC_status_selector td {
6870: vertical-align: top;
6871: text-align: center;
1.424 albertel 6872: padding: 4px;
6873: }
1.795 www 6874:
1.599 albertel 6875: div.LC_feedback_link {
1.616 albertel 6876: clear: both;
1.829 kalberla 6877: background: $sidebg;
1.779 bisitz 6878: width: 100%;
1.829 kalberla 6879: padding-bottom: 10px;
6880: border: 1px $tabbg solid;
1.833 kalberla 6881: height: 22px;
6882: line-height: 22px;
6883: padding-top: 5px;
6884: }
6885:
6886: div.LC_feedback_link img {
6887: height: 22px;
1.867 kalberla 6888: vertical-align:middle;
1.829 kalberla 6889: }
6890:
1.911 bisitz 6891: div.LC_feedback_link a {
1.829 kalberla 6892: text-decoration: none;
1.489 raeburn 6893: }
1.795 www 6894:
1.867 kalberla 6895: div.LC_comblock {
1.911 bisitz 6896: display:inline;
1.867 kalberla 6897: color:$font;
6898: font-size:90%;
6899: }
6900:
6901: div.LC_feedback_link div.LC_comblock {
6902: padding-left:5px;
6903: }
6904:
6905: div.LC_feedback_link div.LC_comblock a {
6906: color:$font;
6907: }
6908:
1.489 raeburn 6909: span.LC_feedback_link {
1.858 bisitz 6910: /* background: $feedback_link_bg; */
1.599 albertel 6911: font-size: larger;
6912: }
1.795 www 6913:
1.599 albertel 6914: span.LC_message_link {
1.858 bisitz 6915: /* background: $feedback_link_bg; */
1.599 albertel 6916: font-size: larger;
6917: position: absolute;
6918: right: 1em;
1.489 raeburn 6919: }
1.421 albertel 6920:
1.515 albertel 6921: table.LC_prior_tries {
1.524 albertel 6922: border: 1px solid #000000;
6923: border-collapse: separate;
6924: border-spacing: 1px;
1.515 albertel 6925: }
1.523 albertel 6926:
1.515 albertel 6927: table.LC_prior_tries td {
1.524 albertel 6928: padding: 2px;
1.515 albertel 6929: }
1.523 albertel 6930:
6931: .LC_answer_correct {
1.795 www 6932: background: lightgreen;
6933: color: darkgreen;
6934: padding: 6px;
1.523 albertel 6935: }
1.795 www 6936:
1.523 albertel 6937: .LC_answer_charged_try {
1.797 www 6938: background: #FFAAAA;
1.795 www 6939: color: darkred;
6940: padding: 6px;
1.523 albertel 6941: }
1.795 www 6942:
1.779 bisitz 6943: .LC_answer_not_charged_try,
1.523 albertel 6944: .LC_answer_no_grade,
6945: .LC_answer_late {
1.795 www 6946: background: lightyellow;
1.523 albertel 6947: color: black;
1.795 www 6948: padding: 6px;
1.523 albertel 6949: }
1.795 www 6950:
1.523 albertel 6951: .LC_answer_previous {
1.795 www 6952: background: lightblue;
6953: color: darkblue;
6954: padding: 6px;
1.523 albertel 6955: }
1.795 www 6956:
1.779 bisitz 6957: .LC_answer_no_message {
1.777 tempelho 6958: background: #FFFFFF;
6959: color: black;
1.795 www 6960: padding: 6px;
1.779 bisitz 6961: }
1.795 www 6962:
1.1075.2.140 raeburn 6963: .LC_answer_unknown,
6964: .LC_answer_warning {
1.779 bisitz 6965: background: orange;
6966: color: black;
1.795 www 6967: padding: 6px;
1.777 tempelho 6968: }
1.795 www 6969:
1.529 albertel 6970: span.LC_prior_numerical,
6971: span.LC_prior_string,
6972: span.LC_prior_custom,
6973: span.LC_prior_reaction,
6974: span.LC_prior_math {
1.925 bisitz 6975: font-family: $mono;
1.523 albertel 6976: white-space: pre;
6977: }
6978:
1.525 albertel 6979: span.LC_prior_string {
1.925 bisitz 6980: font-family: $mono;
1.525 albertel 6981: white-space: pre;
6982: }
6983:
1.523 albertel 6984: table.LC_prior_option {
6985: width: 100%;
6986: border-collapse: collapse;
6987: }
1.795 www 6988:
1.911 bisitz 6989: table.LC_prior_rank,
1.795 www 6990: table.LC_prior_match {
1.528 albertel 6991: border-collapse: collapse;
6992: }
1.795 www 6993:
1.528 albertel 6994: table.LC_prior_option tr td,
6995: table.LC_prior_rank tr td,
6996: table.LC_prior_match tr td {
1.524 albertel 6997: border: 1px solid #000000;
1.515 albertel 6998: }
6999:
1.855 bisitz 7000: .LC_nobreak {
1.544 albertel 7001: white-space: nowrap;
1.519 raeburn 7002: }
7003:
1.576 raeburn 7004: span.LC_cusr_emph {
7005: font-style: italic;
7006: }
7007:
1.633 raeburn 7008: span.LC_cusr_subheading {
7009: font-weight: normal;
7010: font-size: 85%;
7011: }
7012:
1.861 bisitz 7013: div.LC_docs_entry_move {
1.859 bisitz 7014: border: 1px solid #BBBBBB;
1.545 albertel 7015: background: #DDDDDD;
1.861 bisitz 7016: width: 22px;
1.859 bisitz 7017: padding: 1px;
7018: margin: 0;
1.545 albertel 7019: }
7020:
1.861 bisitz 7021: table.LC_data_table tr > td.LC_docs_entry_commands,
7022: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7023: font-size: x-small;
7024: }
1.795 www 7025:
1.861 bisitz 7026: .LC_docs_entry_parameter {
7027: white-space: nowrap;
7028: }
7029:
1.544 albertel 7030: .LC_docs_copy {
1.545 albertel 7031: color: #000099;
1.544 albertel 7032: }
1.795 www 7033:
1.544 albertel 7034: .LC_docs_cut {
1.545 albertel 7035: color: #550044;
1.544 albertel 7036: }
1.795 www 7037:
1.544 albertel 7038: .LC_docs_rename {
1.545 albertel 7039: color: #009900;
1.544 albertel 7040: }
1.795 www 7041:
1.544 albertel 7042: .LC_docs_remove {
1.545 albertel 7043: color: #990000;
7044: }
7045:
1.1075.2.134 raeburn 7046: .LC_domprefs_email,
1.547 albertel 7047: .LC_docs_reinit_warn,
7048: .LC_docs_ext_edit {
7049: font-size: x-small;
7050: }
7051:
1.545 albertel 7052: table.LC_docs_adddocs td,
7053: table.LC_docs_adddocs th {
7054: border: 1px solid #BBBBBB;
7055: padding: 4px;
7056: background: #DDDDDD;
1.543 albertel 7057: }
7058:
1.584 albertel 7059: table.LC_sty_begin {
7060: background: #BBFFBB;
7061: }
1.795 www 7062:
1.584 albertel 7063: table.LC_sty_end {
7064: background: #FFBBBB;
7065: }
7066:
1.589 raeburn 7067: table.LC_double_column {
1.803 bisitz 7068: border-width: 0;
1.589 raeburn 7069: border-collapse: collapse;
7070: width: 100%;
7071: padding: 2px;
7072: }
7073:
7074: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7075: top: 2px;
1.589 raeburn 7076: left: 2px;
7077: width: 47%;
7078: vertical-align: top;
7079: }
7080:
7081: table.LC_double_column tr td.LC_right_col {
7082: top: 2px;
1.779 bisitz 7083: right: 2px;
1.589 raeburn 7084: width: 47%;
7085: vertical-align: top;
7086: }
7087:
1.591 raeburn 7088: div.LC_left_float {
7089: float: left;
7090: padding-right: 5%;
1.597 albertel 7091: padding-bottom: 4px;
1.591 raeburn 7092: }
7093:
7094: div.LC_clear_float_header {
1.597 albertel 7095: padding-bottom: 2px;
1.591 raeburn 7096: }
7097:
7098: div.LC_clear_float_footer {
1.597 albertel 7099: padding-top: 10px;
1.591 raeburn 7100: clear: both;
7101: }
7102:
1.597 albertel 7103: div.LC_grade_show_user {
1.941 bisitz 7104: /* border-left: 5px solid $sidebg; */
7105: border-top: 5px solid #000000;
7106: margin: 50px 0 0 0;
1.936 bisitz 7107: padding: 15px 0 5px 10px;
1.597 albertel 7108: }
1.795 www 7109:
1.936 bisitz 7110: div.LC_grade_show_user_odd_row {
1.941 bisitz 7111: /* border-left: 5px solid #000000; */
7112: }
7113:
7114: div.LC_grade_show_user div.LC_Box {
7115: margin-right: 50px;
1.597 albertel 7116: }
7117:
7118: div.LC_grade_submissions,
7119: div.LC_grade_message_center,
1.936 bisitz 7120: div.LC_grade_info_links {
1.597 albertel 7121: margin: 5px;
7122: width: 99%;
7123: background: #FFFFFF;
7124: }
1.795 www 7125:
1.597 albertel 7126: div.LC_grade_submissions_header,
1.936 bisitz 7127: div.LC_grade_message_center_header {
1.705 tempelho 7128: font-weight: bold;
7129: font-size: large;
1.597 albertel 7130: }
1.795 www 7131:
1.597 albertel 7132: div.LC_grade_submissions_body,
1.936 bisitz 7133: div.LC_grade_message_center_body {
1.597 albertel 7134: border: 1px solid black;
7135: width: 99%;
7136: background: #FFFFFF;
7137: }
1.795 www 7138:
1.613 albertel 7139: table.LC_scantron_action {
7140: width: 100%;
7141: }
1.795 www 7142:
1.613 albertel 7143: table.LC_scantron_action tr th {
1.698 harmsja 7144: font-weight:bold;
7145: font-style:normal;
1.613 albertel 7146: }
1.795 www 7147:
1.779 bisitz 7148: .LC_edit_problem_header,
1.614 albertel 7149: div.LC_edit_problem_footer {
1.705 tempelho 7150: font-weight: normal;
7151: font-size: medium;
1.602 albertel 7152: margin: 2px;
1.1060 bisitz 7153: background-color: $sidebg;
1.600 albertel 7154: }
1.795 www 7155:
1.600 albertel 7156: div.LC_edit_problem_header,
1.602 albertel 7157: div.LC_edit_problem_header div,
1.614 albertel 7158: div.LC_edit_problem_footer,
7159: div.LC_edit_problem_footer div,
1.602 albertel 7160: div.LC_edit_problem_editxml_header,
7161: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 7162: z-index: 100;
1.600 albertel 7163: }
1.795 www 7164:
1.600 albertel 7165: div.LC_edit_problem_header_title {
1.705 tempelho 7166: font-weight: bold;
7167: font-size: larger;
1.602 albertel 7168: background: $tabbg;
7169: padding: 3px;
1.1060 bisitz 7170: margin: 0 0 5px 0;
1.602 albertel 7171: }
1.795 www 7172:
1.602 albertel 7173: table.LC_edit_problem_header_title {
7174: width: 100%;
1.600 albertel 7175: background: $tabbg;
1.602 albertel 7176: }
7177:
1.1075.2.112 raeburn 7178: div.LC_edit_actionbar {
7179: background-color: $sidebg;
7180: margin: 0;
7181: padding: 0;
7182: line-height: 200%;
1.602 albertel 7183: }
1.795 www 7184:
1.1075.2.112 raeburn 7185: div.LC_edit_actionbar div{
7186: padding: 0;
7187: margin: 0;
7188: display: inline-block;
1.600 albertel 7189: }
1.795 www 7190:
1.1075.2.34 raeburn 7191: .LC_edit_opt {
7192: padding-left: 1em;
7193: white-space: nowrap;
7194: }
7195:
1.1075.2.57 raeburn 7196: .LC_edit_problem_latexhelper{
7197: text-align: right;
7198: }
7199:
7200: #LC_edit_problem_colorful div{
7201: margin-left: 40px;
7202: }
7203:
1.1075.2.112 raeburn 7204: #LC_edit_problem_codemirror div{
7205: margin-left: 0px;
7206: }
7207:
1.911 bisitz 7208: img.stift {
1.803 bisitz 7209: border-width: 0;
7210: vertical-align: middle;
1.677 riegler 7211: }
1.680 riegler 7212:
1.923 bisitz 7213: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7214: vertical-align: top;
1.777 tempelho 7215: }
1.795 www 7216:
1.716 raeburn 7217: div.LC_createcourse {
1.911 bisitz 7218: margin: 10px 10px 10px 10px;
1.716 raeburn 7219: }
7220:
1.917 raeburn 7221: .LC_dccid {
1.1075.2.38 raeburn 7222: float: right;
1.917 raeburn 7223: margin: 0.2em 0 0 0;
7224: padding: 0;
7225: font-size: 90%;
7226: display:none;
7227: }
7228:
1.897 wenzelju 7229: ol.LC_primary_menu a:hover,
1.721 harmsja 7230: ol#LC_MenuBreadcrumbs a:hover,
7231: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7232: ul#LC_secondary_menu a:hover,
1.721 harmsja 7233: .LC_FormSectionClearButton input:hover
1.795 www 7234: ul.LC_TabContent li:hover a {
1.952 onken 7235: color:$button_hover;
1.911 bisitz 7236: text-decoration:none;
1.693 droeschl 7237: }
7238:
1.779 bisitz 7239: h1 {
1.911 bisitz 7240: padding: 0;
7241: line-height:130%;
1.693 droeschl 7242: }
1.698 harmsja 7243:
1.911 bisitz 7244: h2,
7245: h3,
7246: h4,
7247: h5,
7248: h6 {
7249: margin: 5px 0 5px 0;
7250: padding: 0;
7251: line-height:130%;
1.693 droeschl 7252: }
1.795 www 7253:
7254: .LC_hcell {
1.911 bisitz 7255: padding:3px 15px 3px 15px;
7256: margin: 0;
7257: background-color:$tabbg;
7258: color:$fontmenu;
7259: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7260: }
1.795 www 7261:
1.840 bisitz 7262: .LC_Box > .LC_hcell {
1.911 bisitz 7263: margin: 0 -10px 10px -10px;
1.835 bisitz 7264: }
7265:
1.721 harmsja 7266: .LC_noBorder {
1.911 bisitz 7267: border: 0;
1.698 harmsja 7268: }
1.693 droeschl 7269:
1.721 harmsja 7270: .LC_FormSectionClearButton input {
1.911 bisitz 7271: background-color:transparent;
7272: border: none;
7273: cursor:pointer;
7274: text-decoration:underline;
1.693 droeschl 7275: }
1.763 bisitz 7276:
7277: .LC_help_open_topic {
1.911 bisitz 7278: color: #FFFFFF;
7279: background-color: #EEEEFF;
7280: margin: 1px;
7281: padding: 4px;
7282: border: 1px solid #000033;
7283: white-space: nowrap;
7284: /* vertical-align: middle; */
1.759 neumanie 7285: }
1.693 droeschl 7286:
1.911 bisitz 7287: dl,
7288: ul,
7289: div,
7290: fieldset {
7291: margin: 10px 10px 10px 0;
7292: /* overflow: hidden; */
1.693 droeschl 7293: }
1.795 www 7294:
1.1075.2.90 raeburn 7295: article.geogebraweb div {
7296: margin: 0;
7297: }
7298:
1.838 bisitz 7299: fieldset > legend {
1.911 bisitz 7300: font-weight: bold;
7301: padding: 0 5px 0 5px;
1.838 bisitz 7302: }
7303:
1.813 bisitz 7304: #LC_nav_bar {
1.911 bisitz 7305: float: left;
1.995 raeburn 7306: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7307: margin: 0 0 2px 0;
1.807 droeschl 7308: }
7309:
1.916 droeschl 7310: #LC_realm {
7311: margin: 0.2em 0 0 0;
7312: padding: 0;
7313: font-weight: bold;
7314: text-align: center;
1.995 raeburn 7315: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7316: }
7317:
1.911 bisitz 7318: #LC_nav_bar em {
7319: font-weight: bold;
7320: font-style: normal;
1.807 droeschl 7321: }
7322:
1.897 wenzelju 7323: ol.LC_primary_menu {
1.934 droeschl 7324: margin: 0;
1.1075.2.2 raeburn 7325: padding: 0;
1.807 droeschl 7326: }
7327:
1.852 droeschl 7328: ol#LC_PathBreadcrumbs {
1.911 bisitz 7329: margin: 0;
1.693 droeschl 7330: }
7331:
1.897 wenzelju 7332: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7333: color: RGB(80, 80, 80);
7334: vertical-align: middle;
7335: text-align: left;
7336: list-style: none;
1.1075.2.112 raeburn 7337: position: relative;
1.1075.2.2 raeburn 7338: float: left;
1.1075.2.112 raeburn 7339: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7340: line-height: 1.5em;
1.1075.2.2 raeburn 7341: }
7342:
1.1075.2.113 raeburn 7343: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7344: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7345: display: block;
7346: margin: 0;
7347: padding: 0 5px 0 10px;
7348: text-decoration: none;
7349: }
7350:
1.1075.2.112 raeburn 7351: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7352: display: inline-block;
7353: width: 95%;
7354: text-align: left;
7355: }
7356:
7357: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7358: display: inline-block;
7359: width: 5%;
7360: float: right;
7361: text-align: right;
7362: font-size: 70%;
7363: }
7364:
7365: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7366: display: none;
1.1075.2.112 raeburn 7367: width: 15em;
1.1075.2.2 raeburn 7368: background-color: $data_table_light;
1.1075.2.112 raeburn 7369: position: absolute;
7370: top: 100%;
7371: }
7372:
7373: ol.LC_primary_menu ul ul {
7374: left: 100%;
7375: top: 0;
1.1075.2.2 raeburn 7376: }
7377:
1.1075.2.112 raeburn 7378: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7379: display: block;
7380: position: absolute;
7381: margin: 0;
7382: padding: 0;
1.1075.2.5 raeburn 7383: z-index: 2;
1.1075.2.2 raeburn 7384: }
7385:
7386: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7387: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7388: font-size: 90%;
1.911 bisitz 7389: vertical-align: top;
1.1075.2.2 raeburn 7390: float: none;
1.1075.2.5 raeburn 7391: border-left: 1px solid black;
7392: border-right: 1px solid black;
1.1075.2.112 raeburn 7393: /* A dark bottom border to visualize different menu options;
7394: overwritten in the create_submenu routine for the last border-bottom of the menu */
7395: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7396: }
7397:
1.1075.2.112 raeburn 7398: ol.LC_primary_menu li li p:hover {
7399: color:$button_hover;
7400: text-decoration:none;
7401: background-color:$data_table_dark;
1.1075.2.2 raeburn 7402: }
7403:
7404: ol.LC_primary_menu li li a:hover {
7405: color:$button_hover;
7406: background-color:$data_table_dark;
1.693 droeschl 7407: }
7408:
1.1075.2.112 raeburn 7409: /* Font-size equal to the size of the predecessors*/
7410: ol.LC_primary_menu li:hover li li {
7411: font-size: 100%;
7412: }
7413:
1.897 wenzelju 7414: ol.LC_primary_menu li img {
1.911 bisitz 7415: vertical-align: bottom;
1.934 droeschl 7416: height: 1.1em;
1.1075.2.3 raeburn 7417: margin: 0.2em 0 0 0;
1.693 droeschl 7418: }
7419:
1.897 wenzelju 7420: ol.LC_primary_menu a {
1.911 bisitz 7421: color: RGB(80, 80, 80);
7422: text-decoration: none;
1.693 droeschl 7423: }
1.795 www 7424:
1.949 droeschl 7425: ol.LC_primary_menu a.LC_new_message {
7426: font-weight:bold;
7427: color: darkred;
7428: }
7429:
1.975 raeburn 7430: ol.LC_docs_parameters {
7431: margin-left: 0;
7432: padding: 0;
7433: list-style: none;
7434: }
7435:
7436: ol.LC_docs_parameters li {
7437: margin: 0;
7438: padding-right: 20px;
7439: display: inline;
7440: }
7441:
1.976 raeburn 7442: ol.LC_docs_parameters li:before {
7443: content: "\\002022 \\0020";
7444: }
7445:
7446: li.LC_docs_parameters_title {
7447: font-weight: bold;
7448: }
7449:
7450: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7451: content: "";
7452: }
7453:
1.897 wenzelju 7454: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7455: clear: right;
1.911 bisitz 7456: color: $fontmenu;
7457: background: $tabbg;
7458: list-style: none;
7459: padding: 0;
7460: margin: 0;
7461: width: 100%;
1.995 raeburn 7462: text-align: left;
1.1075.2.4 raeburn 7463: float: left;
1.808 droeschl 7464: }
7465:
1.897 wenzelju 7466: ul#LC_secondary_menu li {
1.911 bisitz 7467: font-weight: bold;
7468: line-height: 1.8em;
7469: border-right: 1px solid black;
1.1075.2.4 raeburn 7470: float: left;
7471: }
7472:
7473: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7474: background-color: $data_table_light;
7475: }
7476:
7477: ul#LC_secondary_menu li a {
7478: padding: 0 0.8em;
7479: }
7480:
7481: ul#LC_secondary_menu li ul {
7482: display: none;
7483: }
7484:
7485: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7486: display: block;
7487: position: absolute;
7488: margin: 0;
7489: padding: 0;
7490: list-style:none;
7491: float: none;
7492: background-color: $data_table_light;
1.1075.2.5 raeburn 7493: z-index: 2;
1.1075.2.10 raeburn 7494: margin-left: -1px;
1.1075.2.4 raeburn 7495: }
7496:
7497: ul#LC_secondary_menu li ul li {
7498: font-size: 90%;
7499: vertical-align: top;
7500: border-left: 1px solid black;
7501: border-right: 1px solid black;
1.1075.2.33 raeburn 7502: background-color: $data_table_light;
1.1075.2.4 raeburn 7503: list-style:none;
7504: float: none;
7505: }
7506:
7507: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7508: background-color: $data_table_dark;
1.807 droeschl 7509: }
7510:
1.847 tempelho 7511: ul.LC_TabContent {
1.911 bisitz 7512: display:block;
7513: background: $sidebg;
7514: border-bottom: solid 1px $lg_border_color;
7515: list-style:none;
1.1020 raeburn 7516: margin: -1px -10px 0 -10px;
1.911 bisitz 7517: padding: 0;
1.693 droeschl 7518: }
7519:
1.795 www 7520: ul.LC_TabContent li,
7521: ul.LC_TabContentBigger li {
1.911 bisitz 7522: float:left;
1.741 harmsja 7523: }
1.795 www 7524:
1.897 wenzelju 7525: ul#LC_secondary_menu li a {
1.911 bisitz 7526: color: $fontmenu;
7527: text-decoration: none;
1.693 droeschl 7528: }
1.795 www 7529:
1.721 harmsja 7530: ul.LC_TabContent {
1.952 onken 7531: min-height:20px;
1.721 harmsja 7532: }
1.795 www 7533:
7534: ul.LC_TabContent li {
1.911 bisitz 7535: vertical-align:middle;
1.959 onken 7536: padding: 0 16px 0 10px;
1.911 bisitz 7537: background-color:$tabbg;
7538: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7539: border-left: solid 1px $font;
1.721 harmsja 7540: }
1.795 www 7541:
1.847 tempelho 7542: ul.LC_TabContent .right {
1.911 bisitz 7543: float:right;
1.847 tempelho 7544: }
7545:
1.911 bisitz 7546: ul.LC_TabContent li a,
7547: ul.LC_TabContent li {
7548: color:rgb(47,47,47);
7549: text-decoration:none;
7550: font-size:95%;
7551: font-weight:bold;
1.952 onken 7552: min-height:20px;
7553: }
7554:
1.959 onken 7555: ul.LC_TabContent li a:hover,
7556: ul.LC_TabContent li a:focus {
1.952 onken 7557: color: $button_hover;
1.959 onken 7558: background:none;
7559: outline:none;
1.952 onken 7560: }
7561:
7562: ul.LC_TabContent li:hover {
7563: color: $button_hover;
7564: cursor:pointer;
1.721 harmsja 7565: }
1.795 www 7566:
1.911 bisitz 7567: ul.LC_TabContent li.active {
1.952 onken 7568: color: $font;
1.911 bisitz 7569: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7570: border-bottom:solid 1px #FFFFFF;
7571: cursor: default;
1.744 ehlerst 7572: }
1.795 www 7573:
1.959 onken 7574: ul.LC_TabContent li.active a {
7575: color:$font;
7576: background:#FFFFFF;
7577: outline: none;
7578: }
1.1047 raeburn 7579:
7580: ul.LC_TabContent li.goback {
7581: float: left;
7582: border-left: none;
7583: }
7584:
1.870 tempelho 7585: #maincoursedoc {
1.911 bisitz 7586: clear:both;
1.870 tempelho 7587: }
7588:
7589: ul.LC_TabContentBigger {
1.911 bisitz 7590: display:block;
7591: list-style:none;
7592: padding: 0;
1.870 tempelho 7593: }
7594:
1.795 www 7595: ul.LC_TabContentBigger li {
1.911 bisitz 7596: vertical-align:bottom;
7597: height: 30px;
7598: font-size:110%;
7599: font-weight:bold;
7600: color: #737373;
1.841 tempelho 7601: }
7602:
1.957 onken 7603: ul.LC_TabContentBigger li.active {
7604: position: relative;
7605: top: 1px;
7606: }
7607:
1.870 tempelho 7608: ul.LC_TabContentBigger li a {
1.911 bisitz 7609: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7610: height: 30px;
7611: line-height: 30px;
7612: text-align: center;
7613: display: block;
7614: text-decoration: none;
1.958 onken 7615: outline: none;
1.741 harmsja 7616: }
1.795 www 7617:
1.870 tempelho 7618: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7619: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7620: color:$font;
1.744 ehlerst 7621: }
1.795 www 7622:
1.870 tempelho 7623: ul.LC_TabContentBigger li b {
1.911 bisitz 7624: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7625: display: block;
7626: float: left;
7627: padding: 0 30px;
1.957 onken 7628: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7629: }
7630:
1.956 onken 7631: ul.LC_TabContentBigger li:hover b {
7632: color:$button_hover;
7633: }
7634:
1.870 tempelho 7635: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7636: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7637: color:$font;
1.957 onken 7638: border: 0;
1.741 harmsja 7639: }
1.693 droeschl 7640:
1.870 tempelho 7641:
1.862 bisitz 7642: ul.LC_CourseBreadcrumbs {
7643: background: $sidebg;
1.1020 raeburn 7644: height: 2em;
1.862 bisitz 7645: padding-left: 10px;
1.1020 raeburn 7646: margin: 0;
1.862 bisitz 7647: list-style-position: inside;
7648: }
7649:
1.911 bisitz 7650: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7651: ol#LC_PathBreadcrumbs {
1.911 bisitz 7652: padding-left: 10px;
7653: margin: 0;
1.933 droeschl 7654: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7655: }
7656:
1.911 bisitz 7657: ol#LC_MenuBreadcrumbs li,
7658: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7659: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7660: display: inline;
1.933 droeschl 7661: white-space: normal;
1.693 droeschl 7662: }
7663:
1.823 bisitz 7664: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7665: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7666: text-decoration: none;
7667: font-size:90%;
1.693 droeschl 7668: }
1.795 www 7669:
1.969 droeschl 7670: ol#LC_MenuBreadcrumbs h1 {
7671: display: inline;
7672: font-size: 90%;
7673: line-height: 2.5em;
7674: margin: 0;
7675: padding: 0;
7676: }
7677:
1.795 www 7678: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7679: text-decoration:none;
7680: font-size:100%;
7681: font-weight:bold;
1.693 droeschl 7682: }
1.795 www 7683:
1.840 bisitz 7684: .LC_Box {
1.911 bisitz 7685: border: solid 1px $lg_border_color;
7686: padding: 0 10px 10px 10px;
1.746 neumanie 7687: }
1.795 www 7688:
1.1020 raeburn 7689: .LC_DocsBox {
7690: border: solid 1px $lg_border_color;
7691: padding: 0 0 10px 10px;
7692: }
7693:
1.795 www 7694: .LC_AboutMe_Image {
1.911 bisitz 7695: float:left;
7696: margin-right:10px;
1.747 neumanie 7697: }
1.795 www 7698:
7699: .LC_Clear_AboutMe_Image {
1.911 bisitz 7700: clear:left;
1.747 neumanie 7701: }
1.795 www 7702:
1.721 harmsja 7703: dl.LC_ListStyleClean dt {
1.911 bisitz 7704: padding-right: 5px;
7705: display: table-header-group;
1.693 droeschl 7706: }
7707:
1.721 harmsja 7708: dl.LC_ListStyleClean dd {
1.911 bisitz 7709: display: table-row;
1.693 droeschl 7710: }
7711:
1.721 harmsja 7712: .LC_ListStyleClean,
7713: .LC_ListStyleSimple,
7714: .LC_ListStyleNormal,
1.795 www 7715: .LC_ListStyleSpecial {
1.911 bisitz 7716: /* display:block; */
7717: list-style-position: inside;
7718: list-style-type: none;
7719: overflow: hidden;
7720: padding: 0;
1.693 droeschl 7721: }
7722:
1.721 harmsja 7723: .LC_ListStyleSimple li,
7724: .LC_ListStyleSimple dd,
7725: .LC_ListStyleNormal li,
7726: .LC_ListStyleNormal dd,
7727: .LC_ListStyleSpecial li,
1.795 www 7728: .LC_ListStyleSpecial dd {
1.911 bisitz 7729: margin: 0;
7730: padding: 5px 5px 5px 10px;
7731: clear: both;
1.693 droeschl 7732: }
7733:
1.721 harmsja 7734: .LC_ListStyleClean li,
7735: .LC_ListStyleClean dd {
1.911 bisitz 7736: padding-top: 0;
7737: padding-bottom: 0;
1.693 droeschl 7738: }
7739:
1.721 harmsja 7740: .LC_ListStyleSimple dd,
1.795 www 7741: .LC_ListStyleSimple li {
1.911 bisitz 7742: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7743: }
7744:
1.721 harmsja 7745: .LC_ListStyleSpecial li,
7746: .LC_ListStyleSpecial dd {
1.911 bisitz 7747: list-style-type: none;
7748: background-color: RGB(220, 220, 220);
7749: margin-bottom: 4px;
1.693 droeschl 7750: }
7751:
1.721 harmsja 7752: table.LC_SimpleTable {
1.911 bisitz 7753: margin:5px;
7754: border:solid 1px $lg_border_color;
1.795 www 7755: }
1.693 droeschl 7756:
1.721 harmsja 7757: table.LC_SimpleTable tr {
1.911 bisitz 7758: padding: 0;
7759: border:solid 1px $lg_border_color;
1.693 droeschl 7760: }
1.795 www 7761:
7762: table.LC_SimpleTable thead {
1.911 bisitz 7763: background:rgb(220,220,220);
1.693 droeschl 7764: }
7765:
1.721 harmsja 7766: div.LC_columnSection {
1.911 bisitz 7767: display: block;
7768: clear: both;
7769: overflow: hidden;
7770: margin: 0;
1.693 droeschl 7771: }
7772:
1.721 harmsja 7773: div.LC_columnSection>* {
1.911 bisitz 7774: float: left;
7775: margin: 10px 20px 10px 0;
7776: overflow:hidden;
1.693 droeschl 7777: }
1.721 harmsja 7778:
1.795 www 7779: table em {
1.911 bisitz 7780: font-weight: bold;
7781: font-style: normal;
1.748 schulted 7782: }
1.795 www 7783:
1.779 bisitz 7784: table.LC_tableBrowseRes,
1.795 www 7785: table.LC_tableOfContent {
1.911 bisitz 7786: border:none;
7787: border-spacing: 1px;
7788: padding: 3px;
7789: background-color: #FFFFFF;
7790: font-size: 90%;
1.753 droeschl 7791: }
1.789 droeschl 7792:
1.911 bisitz 7793: table.LC_tableOfContent {
7794: border-collapse: collapse;
1.789 droeschl 7795: }
7796:
1.771 droeschl 7797: table.LC_tableBrowseRes a,
1.768 schulted 7798: table.LC_tableOfContent a {
1.911 bisitz 7799: background-color: transparent;
7800: text-decoration: none;
1.753 droeschl 7801: }
7802:
1.795 www 7803: table.LC_tableOfContent img {
1.911 bisitz 7804: border: none;
7805: height: 1.3em;
7806: vertical-align: text-bottom;
7807: margin-right: 0.3em;
1.753 droeschl 7808: }
1.757 schulted 7809:
1.795 www 7810: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7811: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7812: }
7813:
1.795 www 7814: a#LC_content_toolbar_everything {
1.911 bisitz 7815: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7816: }
7817:
1.795 www 7818: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7819: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7820: }
7821:
1.795 www 7822: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7823: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7824: }
7825:
1.795 www 7826: a#LC_content_toolbar_changefolder {
1.911 bisitz 7827: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7828: }
7829:
1.795 www 7830: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7831: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7832: }
7833:
1.1043 raeburn 7834: a#LC_content_toolbar_edittoplevel {
7835: background-image:url(/res/adm/pages/edittoplevel.gif);
7836: }
7837:
1.795 www 7838: ul#LC_toolbar li a:hover {
1.911 bisitz 7839: background-position: bottom center;
1.757 schulted 7840: }
7841:
1.795 www 7842: ul#LC_toolbar {
1.911 bisitz 7843: padding: 0;
7844: margin: 2px;
7845: list-style:none;
7846: position:relative;
7847: background-color:white;
1.1075.2.9 raeburn 7848: overflow: auto;
1.757 schulted 7849: }
7850:
1.795 www 7851: ul#LC_toolbar li {
1.911 bisitz 7852: border:1px solid white;
7853: padding: 0;
7854: margin: 0;
7855: float: left;
7856: display:inline;
7857: vertical-align:middle;
1.1075.2.9 raeburn 7858: white-space: nowrap;
1.911 bisitz 7859: }
1.757 schulted 7860:
1.783 amueller 7861:
1.795 www 7862: a.LC_toolbarItem {
1.911 bisitz 7863: display:block;
7864: padding: 0;
7865: margin: 0;
7866: height: 32px;
7867: width: 32px;
7868: color:white;
7869: border: none;
7870: background-repeat:no-repeat;
7871: background-color:transparent;
1.757 schulted 7872: }
7873:
1.915 droeschl 7874: ul.LC_funclist {
7875: margin: 0;
7876: padding: 0.5em 1em 0.5em 0;
7877: }
7878:
1.933 droeschl 7879: ul.LC_funclist > li:first-child {
7880: font-weight:bold;
7881: margin-left:0.8em;
7882: }
7883:
1.915 droeschl 7884: ul.LC_funclist + ul.LC_funclist {
7885: /*
7886: left border as a seperator if we have more than
7887: one list
7888: */
7889: border-left: 1px solid $sidebg;
7890: /*
7891: this hides the left border behind the border of the
7892: outer box if element is wrapped to the next 'line'
7893: */
7894: margin-left: -1px;
7895: }
7896:
1.843 bisitz 7897: ul.LC_funclist li {
1.915 droeschl 7898: display: inline;
1.782 bisitz 7899: white-space: nowrap;
1.915 droeschl 7900: margin: 0 0 0 25px;
7901: line-height: 150%;
1.782 bisitz 7902: }
7903:
1.974 wenzelju 7904: .LC_hidden {
7905: display: none;
7906: }
7907:
1.1030 www 7908: .LCmodal-overlay {
7909: position:fixed;
7910: top:0;
7911: right:0;
7912: bottom:0;
7913: left:0;
7914: height:100%;
7915: width:100%;
7916: margin:0;
7917: padding:0;
7918: background:#999;
7919: opacity:.75;
7920: filter: alpha(opacity=75);
7921: -moz-opacity: 0.75;
7922: z-index:101;
7923: }
7924:
7925: * html .LCmodal-overlay {
7926: position: absolute;
7927: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7928: }
7929:
7930: .LCmodal-window {
7931: position:fixed;
7932: top:50%;
7933: left:50%;
7934: margin:0;
7935: padding:0;
7936: z-index:102;
7937: }
7938:
7939: * html .LCmodal-window {
7940: position:absolute;
7941: }
7942:
7943: .LCclose-window {
7944: position:absolute;
7945: width:32px;
7946: height:32px;
7947: right:8px;
7948: top:8px;
7949: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7950: text-indent:-99999px;
7951: overflow:hidden;
7952: cursor:pointer;
7953: }
7954:
1.1075.2.158 raeburn 7955: .LCisDisabled {
7956: cursor: not-allowed;
7957: opacity: 0.5;
7958: }
7959:
7960: a[aria-disabled="true"] {
7961: color: currentColor;
7962: display: inline-block; /* For IE11/ MS Edge bug */
7963: pointer-events: none;
7964: text-decoration: none;
7965: }
7966:
1.1075.2.141 raeburn 7967: pre.LC_wordwrap {
7968: white-space: pre-wrap;
7969: white-space: -moz-pre-wrap;
7970: white-space: -pre-wrap;
7971: white-space: -o-pre-wrap;
7972: word-wrap: break-word;
7973: }
7974:
1.1075.2.17 raeburn 7975: /*
7976: styles used by TTH when "Default set of options to pass to tth/m
7977: when converting TeX" in course settings has been set
7978:
7979: option passed: -t
7980:
7981: */
7982:
7983: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7984: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7985: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7986: td div.norm {line-height:normal;}
7987:
7988: /*
7989: option passed -y3
7990: */
7991:
7992: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7993: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7994: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7995:
1.1075.2.121 raeburn 7996: #LC_minitab_header {
7997: float:left;
7998: width:100%;
7999: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8000: font-size:93%;
8001: line-height:normal;
8002: margin: 0.5em 0 0.5em 0;
8003: }
8004: #LC_minitab_header ul {
8005: margin:0;
8006: padding:10px 10px 0;
8007: list-style:none;
8008: }
8009: #LC_minitab_header li {
8010: float:left;
8011: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8012: margin:0;
8013: padding:0 0 0 9px;
8014: }
8015: #LC_minitab_header a {
8016: display:block;
8017: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8018: padding:5px 15px 4px 6px;
8019: }
8020: #LC_minitab_header #LC_current_minitab {
8021: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8022: }
8023: #LC_minitab_header #LC_current_minitab a {
8024: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8025: padding-bottom:5px;
8026: }
8027:
8028:
1.343 albertel 8029: END
8030: }
8031:
1.306 albertel 8032: =pod
8033:
8034: =item * &headtag()
8035:
8036: Returns a uniform footer for LON-CAPA web pages.
8037:
1.307 albertel 8038: Inputs: $title - optional title for the head
8039: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8040: $args - optional arguments
1.319 albertel 8041: force_register - if is true call registerurl so the remote is
8042: informed
1.415 albertel 8043: redirect -> array ref of
8044: 1- seconds before redirect occurs
8045: 2- url to redirect to
8046: 3- whether the side effect should occur
1.315 albertel 8047: (side effect of setting
8048: $env{'internal.head.redirect'} to the url
8049: redirected too)
1.352 albertel 8050: domain -> force to color decorate a page for a specific
8051: domain
8052: function -> force usage of a specific rolish color scheme
8053: bgcolor -> override the default page bgcolor
1.460 albertel 8054: no_auto_mt_title
8055: -> prevent &mt()ing the title arg
1.464 albertel 8056:
1.306 albertel 8057: =cut
8058:
8059: sub headtag {
1.313 albertel 8060: my ($title,$head_extra,$args) = @_;
1.306 albertel 8061:
1.363 albertel 8062: my $function = $args->{'function'} || &get_users_function();
8063: my $domain = $args->{'domain'} || &determinedomain();
8064: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 8065: my $httphost = $args->{'use_absolute'};
1.418 albertel 8066: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8067: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8068: #time(),
1.418 albertel 8069: $env{'environment.color.timestamp'},
1.363 albertel 8070: $function,$domain,$bgcolor);
8071:
1.369 www 8072: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8073:
1.308 albertel 8074: my $result =
8075: '<head>'.
1.1075.2.56 raeburn 8076: &font_settings($args);
1.319 albertel 8077:
1.1075.2.72 raeburn 8078: my $inhibitprint;
8079: if ($args->{'print_suppress'}) {
8080: $inhibitprint = &print_suppression();
8081: }
1.1064 raeburn 8082:
1.461 albertel 8083: if (!$args->{'frameset'}) {
8084: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8085: }
1.1075.2.12 raeburn 8086: if ($args->{'force_register'}) {
8087: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 8088: }
1.436 albertel 8089: if (!$args->{'no_nav_bar'}
8090: && !$args->{'only_body'}
8091: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 8092: $result .= &help_menu_js($httphost);
1.1032 www 8093: $result.=&modal_window();
1.1038 www 8094: $result.=&togglebox_script();
1.1034 www 8095: $result.=&wishlist_window();
1.1041 www 8096: $result.=&LCprogressbarUpdate_script();
1.1034 www 8097: } else {
8098: if ($args->{'add_modal'}) {
8099: $result.=&modal_window();
8100: }
8101: if ($args->{'add_wishlist'}) {
8102: $result.=&wishlist_window();
8103: }
1.1038 www 8104: if ($args->{'add_togglebox'}) {
8105: $result.=&togglebox_script();
8106: }
1.1041 www 8107: if ($args->{'add_progressbar'}) {
8108: $result.=&LCprogressbarUpdate_script();
8109: }
1.436 albertel 8110: }
1.314 albertel 8111: if (ref($args->{'redirect'})) {
1.414 albertel 8112: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8113: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8114: if (!$inhibit_continue) {
8115: $env{'internal.head.redirect'} = $url;
8116: }
1.313 albertel 8117: $result.=<<ADDMETA
8118: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8119: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8120: ADDMETA
1.1075.2.89 raeburn 8121: } else {
8122: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8123: my $requrl = $env{'request.uri'};
8124: if ($requrl eq '') {
8125: $requrl = $ENV{'REQUEST_URI'};
8126: $requrl =~ s/\?.+$//;
8127: }
8128: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8129: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8130: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8131: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8132: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8133: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1075.2.145 raeburn 8134: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1075.2.151 raeburn 8135: my ($offload,$offloadoth);
1.1075.2.89 raeburn 8136: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8137: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1075.2.145 raeburn 8138: $offload = 1;
1.1075.2.151 raeburn 8139: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8140: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8141: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8142: $offloadoth = 1;
8143: $dom_in_use = $env{'user.domain'};
8144: }
8145: }
1.1075.2.145 raeburn 8146: }
8147: }
8148: unless ($offload) {
8149: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8150: if ($domdefs{'offloadoth'}{$lonhost}) {
8151: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8152: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8153: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8154: $offload = 1;
1.1075.2.151 raeburn 8155: $offloadoth = 1;
1.1075.2.145 raeburn 8156: $dom_in_use = $env{'user.domain'};
8157: }
1.1075.2.89 raeburn 8158: }
1.1075.2.145 raeburn 8159: }
8160: }
8161: }
8162: if ($offload) {
1.1075.2.158 raeburn 8163: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1075.2.151 raeburn 8164: if (($newserver eq '') && ($offloadoth)) {
8165: my @domains = &Apache::lonnet::current_machine_domains();
8166: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
8167: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8168: }
8169: }
1.1075.2.145 raeburn 8170: if (($newserver) && ($newserver ne $lonhost)) {
8171: my $numsec = 5;
8172: my $timeout = $numsec * 1000;
8173: my ($newurl,$locknum,%locks,$msg);
8174: if ($env{'request.role.adv'}) {
8175: ($locknum,%locks) = &Apache::lonnet::get_locks();
8176: }
8177: my $disable_submit = 0;
8178: if ($requrl =~ /$LONCAPA::assess_re/) {
8179: $disable_submit = 1;
8180: }
8181: if ($locknum) {
8182: my @lockinfo = sort(values(%locks));
1.1075.2.153 raeburn 8183: $msg = &mt('Once the following tasks are complete:')." \n".
1.1075.2.145 raeburn 8184: join(", ",sort(values(%locks)))."\n";
8185: if (&show_course()) {
8186: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
1.1075.2.89 raeburn 8187: } else {
1.1075.2.145 raeburn 8188: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
8189: }
8190: } else {
8191: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8192: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8193: }
8194: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8195: $newurl = '/adm/switchserver?otherserver='.$newserver;
8196: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8197: $newurl .= '&role='.$env{'request.role'};
8198: }
8199: if ($env{'request.symb'}) {
8200: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8201: if ($shownsymb =~ m{^/enc/}) {
8202: my $reqdmajor = 2;
8203: my $reqdminor = 11;
8204: my $reqdsubminor = 3;
8205: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8206: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8207: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8208: if (($major eq '' && $minor eq '') ||
8209: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8210: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8211: ($reqdsubminor > $subminor))))) {
8212: undef($shownsymb);
8213: }
1.1075.2.89 raeburn 8214: }
1.1075.2.145 raeburn 8215: if ($shownsymb) {
8216: &js_escape(\$shownsymb);
8217: $newurl .= '&symb='.$shownsymb;
1.1075.2.89 raeburn 8218: }
1.1075.2.145 raeburn 8219: } else {
8220: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8221: &js_escape(\$shownurl);
8222: $newurl .= '&origurl='.$shownurl;
1.1075.2.89 raeburn 8223: }
1.1075.2.145 raeburn 8224: }
8225: &js_escape(\$msg);
8226: $result.=<<OFFLOAD
1.1075.2.89 raeburn 8227: <meta http-equiv="pragma" content="no-cache" />
8228: <script type="text/javascript">
1.1075.2.92 raeburn 8229: // <![CDATA[
1.1075.2.89 raeburn 8230: function LC_Offload_Now() {
8231: var dest = "$newurl";
8232: if (dest != '') {
8233: window.location.href="$newurl";
8234: }
8235: }
1.1075.2.92 raeburn 8236: \$(document).ready(function () {
8237: window.alert('$msg');
8238: if ($disable_submit) {
1.1075.2.89 raeburn 8239: \$(".LC_hwk_submit").prop("disabled", true);
8240: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 8241: }
8242: setTimeout('LC_Offload_Now()', $timeout);
8243: });
8244: // ]]>
1.1075.2.89 raeburn 8245: </script>
8246: OFFLOAD
8247: }
8248: }
8249: }
8250: }
8251: }
1.313 albertel 8252: }
1.306 albertel 8253: if (!defined($title)) {
8254: $title = 'The LearningOnline Network with CAPA';
8255: }
1.460 albertel 8256: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8257: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 8258: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8259: if (!$args->{'frameset'}) {
8260: $result .= ' /';
8261: }
8262: $result .= '>'
1.1064 raeburn 8263: .$inhibitprint
1.414 albertel 8264: .$head_extra;
1.1075.2.108 raeburn 8265: my $clientmobile;
8266: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8267: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8268: } else {
8269: $clientmobile = $env{'browser.mobile'};
8270: }
8271: if ($clientmobile) {
1.1075.2.42 raeburn 8272: $result .= '
8273: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8274: <meta name="apple-mobile-web-app-capable" content="yes" />';
8275: }
1.1075.2.126 raeburn 8276: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8277: return $result.'</head>';
1.306 albertel 8278: }
8279:
8280: =pod
8281:
1.340 albertel 8282: =item * &font_settings()
8283:
8284: Returns neccessary <meta> to set the proper encoding
8285:
1.1075.2.56 raeburn 8286: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8287:
8288: =cut
8289:
8290: sub font_settings {
1.1075.2.56 raeburn 8291: my ($args) = @_;
1.340 albertel 8292: my $headerstring='';
1.1075.2.56 raeburn 8293: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8294: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8295: $headerstring.=
1.1075.2.61 raeburn 8296: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8297: if (!$args->{'frameset'}) {
8298: $headerstring.= ' /';
8299: }
8300: $headerstring .= '>'."\n";
1.340 albertel 8301: }
8302: return $headerstring;
8303: }
8304:
1.341 albertel 8305: =pod
8306:
1.1064 raeburn 8307: =item * &print_suppression()
8308:
8309: In course context returns css which causes the body to be blank when media="print",
8310: if printout generation is unavailable for the current resource.
8311:
8312: This could be because:
8313:
8314: (a) printstartdate is in the future
8315:
8316: (b) printenddate is in the past
8317:
8318: (c) there is an active exam block with "printout"
8319: functionality blocked
8320:
8321: Users with pav, pfo or evb privileges are exempt.
8322:
8323: Inputs: none
8324:
8325: =cut
8326:
8327:
8328: sub print_suppression {
8329: my $noprint;
8330: if ($env{'request.course.id'}) {
8331: my $scope = $env{'request.course.id'};
8332: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8333: (&Apache::lonnet::allowed('pfo',$scope))) {
8334: return;
8335: }
8336: if ($env{'request.course.sec'} ne '') {
8337: $scope .= "/$env{'request.course.sec'}";
8338: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8339: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8340: return;
1.1064 raeburn 8341: }
8342: }
8343: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8344: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.158 raeburn 8345: my $clientip = &Apache::lonnet::get_requestor_ip();
8346: my $blocked = &blocking_status('printout',$clientip,$cnum,$cdom,undef,1);
1.1064 raeburn 8347: if ($blocked) {
8348: my $checkrole = "cm./$cdom/$cnum";
8349: if ($env{'request.course.sec'} ne '') {
8350: $checkrole .= "/$env{'request.course.sec'}";
8351: }
8352: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8353: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8354: $noprint = 1;
8355: }
8356: }
8357: unless ($noprint) {
8358: my $symb = &Apache::lonnet::symbread();
8359: if ($symb ne '') {
8360: my $navmap = Apache::lonnavmaps::navmap->new();
8361: if (ref($navmap)) {
8362: my $res = $navmap->getBySymb($symb);
8363: if (ref($res)) {
8364: if (!$res->resprintable()) {
8365: $noprint = 1;
8366: }
8367: }
8368: }
8369: }
8370: }
8371: if ($noprint) {
8372: return <<"ENDSTYLE";
8373: <style type="text/css" media="print">
8374: body { display:none }
8375: </style>
8376: ENDSTYLE
8377: }
8378: }
8379: return;
8380: }
8381:
8382: =pod
8383:
1.341 albertel 8384: =item * &xml_begin()
8385:
8386: Returns the needed doctype and <html>
8387:
8388: Inputs: none
8389:
8390: =cut
8391:
8392: sub xml_begin {
1.1075.2.61 raeburn 8393: my ($is_frameset) = @_;
1.341 albertel 8394: my $output='';
8395:
8396: if ($env{'browser.mathml'}) {
8397: $output='<?xml version="1.0"?>'
8398: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8399: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8400:
8401: # .'<!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">] >'
8402: .'<!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">'
8403: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8404: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8405: } elsif ($is_frameset) {
8406: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8407: '<html>'."\n";
1.341 albertel 8408: } else {
1.1075.2.61 raeburn 8409: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8410: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8411: }
8412: return $output;
8413: }
1.340 albertel 8414:
8415: =pod
8416:
1.306 albertel 8417: =item * &start_page()
8418:
8419: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8420:
1.648 raeburn 8421: Inputs:
8422:
8423: =over 4
8424:
8425: $title - optional title for the page
8426:
8427: $head_extra - optional extra HTML to incude inside the <head>
8428:
8429: $args - additional optional args supported are:
8430:
8431: =over 8
8432:
8433: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8434: arg on
1.814 bisitz 8435: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8436: add_entries -> additional attributes to add to the <body>
8437: domain -> force to color decorate a page for a
1.317 albertel 8438: specific domain
1.648 raeburn 8439: function -> force usage of a specific rolish color
1.317 albertel 8440: scheme
1.648 raeburn 8441: redirect -> see &headtag()
8442: bgcolor -> override the default page bg color
8443: js_ready -> return a string ready for being used in
1.317 albertel 8444: a javascript writeln
1.648 raeburn 8445: html_encode -> return a string ready for being used in
1.320 albertel 8446: a html attribute
1.648 raeburn 8447: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8448: $forcereg arg
1.648 raeburn 8449: frameset -> if true will start with a <frameset>
1.330 albertel 8450: rather than <body>
1.648 raeburn 8451: skip_phases -> hash ref of
1.338 albertel 8452: head -> skip the <html><head> generation
8453: body -> skip all <body> generation
1.1075.2.12 raeburn 8454: no_inline_link -> if true and in remote mode, don't show the
8455: 'Switch To Inline Menu' link
1.648 raeburn 8456: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8457: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8458: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8459: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8460: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8461: group -> includes the current group, if page is for a
8462: specific group
1.1075.2.133 raeburn 8463: use_absolute -> for request for external resource or syllabus, this
8464: will contain https://<hostname> if server uses
8465: https (as per hosts.tab), but request is for http
8466: hostname -> hostname, originally from $r->hostname(), (optional).
1.1075.2.158 raeburn 8467: links_disabled -> Links in primary and secondary menus are disabled
8468: (Can enable them once page has loaded - see lonroles.pm
8469: for an example).
1.361 albertel 8470:
1.648 raeburn 8471: =back
1.460 albertel 8472:
1.648 raeburn 8473: =back
1.562 albertel 8474:
1.306 albertel 8475: =cut
8476:
8477: sub start_page {
1.309 albertel 8478: my ($title,$head_extra,$args) = @_;
1.318 albertel 8479: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8480:
1.315 albertel 8481: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8482: my ($result,@advtools);
1.964 droeschl 8483:
1.338 albertel 8484: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8485: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8486: }
8487:
8488: if (! exists($args->{'skip_phases'}{'body'}) ) {
8489: if ($args->{'frameset'}) {
8490: my $attr_string = &make_attr_string($args->{'force_register'},
8491: $args->{'add_entries'});
8492: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8493: } else {
8494: $result .=
8495: &bodytag($title,
8496: $args->{'function'}, $args->{'add_entries'},
8497: $args->{'only_body'}, $args->{'domain'},
8498: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8499: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8500: $args, \@advtools);
1.831 bisitz 8501: }
1.330 albertel 8502: }
1.338 albertel 8503:
1.315 albertel 8504: if ($args->{'js_ready'}) {
1.713 kaisler 8505: $result = &js_ready($result);
1.315 albertel 8506: }
1.320 albertel 8507: if ($args->{'html_encode'}) {
1.713 kaisler 8508: $result = &html_encode($result);
8509: }
8510:
1.813 bisitz 8511: # Preparation for new and consistent functionlist at top of screen
8512: # if ($args->{'functionlist'}) {
8513: # $result .= &build_functionlist();
8514: #}
8515:
1.964 droeschl 8516: # Don't add anything more if only_body wanted or in const space
8517: return $result if $args->{'only_body'}
8518: || $env{'request.state'} eq 'construct';
1.813 bisitz 8519:
8520: #Breadcrumbs
1.758 kaisler 8521: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8522: &Apache::lonhtmlcommon::clear_breadcrumbs();
8523: #if any br links exists, add them to the breadcrumbs
8524: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8525: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8526: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8527: }
8528: }
1.1075.2.19 raeburn 8529: # if @advtools array contains items add then to the breadcrumbs
8530: if (@advtools > 0) {
8531: &Apache::lonmenu::advtools_crumbs(@advtools);
8532: }
1.1075.2.123 raeburn 8533: my $menulink;
8534: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8535: if (exists($args->{'bread_crumbs_nomenu'})) {
8536: $menulink = 0;
8537: } else {
8538: undef($menulink);
8539: }
1.758 kaisler 8540: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8541: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8542: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8543: }else{
1.1075.2.123 raeburn 8544: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8545: }
1.1075.2.24 raeburn 8546: } elsif (($env{'environment.remote'} eq 'on') &&
8547: ($env{'form.inhibitmenu'} ne 'yes') &&
8548: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8549: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8550: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8551: }
1.315 albertel 8552: return $result;
1.306 albertel 8553: }
8554:
8555: sub end_page {
1.315 albertel 8556: my ($args) = @_;
8557: $env{'internal.end_page'}++;
1.330 albertel 8558: my $result;
1.335 albertel 8559: if ($args->{'discussion'}) {
8560: my ($target,$parser);
8561: if (ref($args->{'discussion'})) {
8562: ($target,$parser) =($args->{'discussion'}{'target'},
8563: $args->{'discussion'}{'parser'});
8564: }
8565: $result .= &Apache::lonxml::xmlend($target,$parser);
8566: }
1.330 albertel 8567: if ($args->{'frameset'}) {
8568: $result .= '</frameset>';
8569: } else {
1.635 raeburn 8570: $result .= &endbodytag($args);
1.330 albertel 8571: }
1.1075.2.6 raeburn 8572: unless ($args->{'notbody'}) {
8573: $result .= "\n</html>";
8574: }
1.330 albertel 8575:
1.315 albertel 8576: if ($args->{'js_ready'}) {
1.317 albertel 8577: $result = &js_ready($result);
1.315 albertel 8578: }
1.335 albertel 8579:
1.320 albertel 8580: if ($args->{'html_encode'}) {
8581: $result = &html_encode($result);
8582: }
1.335 albertel 8583:
1.315 albertel 8584: return $result;
8585: }
8586:
1.1034 www 8587: sub wishlist_window {
8588: return(<<'ENDWISHLIST');
1.1046 raeburn 8589: <script type="text/javascript">
1.1034 www 8590: // <![CDATA[
8591: // <!-- BEGIN LON-CAPA Internal
8592: function set_wishlistlink(title, path) {
8593: if (!title) {
8594: title = document.title;
8595: title = title.replace(/^LON-CAPA /,'');
8596: }
1.1075.2.65 raeburn 8597: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8598: title = title.replace("'","\\\'");
1.1034 www 8599: if (!path) {
8600: path = location.pathname;
8601: }
1.1075.2.65 raeburn 8602: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8603: path = path.replace("'","\\\'");
1.1034 www 8604: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8605: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8606: }
8607: // END LON-CAPA Internal -->
8608: // ]]>
8609: </script>
8610: ENDWISHLIST
8611: }
8612:
1.1030 www 8613: sub modal_window {
8614: return(<<'ENDMODAL');
1.1046 raeburn 8615: <script type="text/javascript">
1.1030 www 8616: // <![CDATA[
8617: // <!-- BEGIN LON-CAPA Internal
8618: var modalWindow = {
8619: parent:"body",
8620: windowId:null,
8621: content:null,
8622: width:null,
8623: height:null,
8624: close:function()
8625: {
8626: $(".LCmodal-window").remove();
8627: $(".LCmodal-overlay").remove();
8628: },
8629: open:function()
8630: {
8631: var modal = "";
8632: modal += "<div class=\"LCmodal-overlay\"></div>";
8633: 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;\">";
8634: modal += this.content;
8635: modal += "</div>";
8636:
8637: $(this.parent).append(modal);
8638:
8639: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8640: $(".LCclose-window").click(function(){modalWindow.close();});
8641: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8642: }
8643: };
1.1075.2.42 raeburn 8644: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8645: {
1.1075.2.119 raeburn 8646: source = source.replace(/'/g,"'");
1.1030 www 8647: modalWindow.windowId = "myModal";
8648: modalWindow.width = width;
8649: modalWindow.height = height;
1.1075.2.80 raeburn 8650: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8651: modalWindow.open();
1.1075.2.87 raeburn 8652: };
1.1030 www 8653: // END LON-CAPA Internal -->
8654: // ]]>
8655: </script>
8656: ENDMODAL
8657: }
8658:
8659: sub modal_link {
1.1075.2.42 raeburn 8660: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8661: unless ($width) { $width=480; }
8662: unless ($height) { $height=400; }
1.1031 www 8663: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8664: unless ($transparency) { $transparency='true'; }
8665:
1.1074 raeburn 8666: my $target_attr;
8667: if (defined($target)) {
8668: $target_attr = 'target="'.$target.'"';
8669: }
8670: return <<"ENDLINK";
1.1075.2.143 raeburn 8671: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 8672: ENDLINK
1.1030 www 8673: }
8674:
1.1032 www 8675: sub modal_adhoc_script {
1.1075.2.155 raeburn 8676: my ($funcname,$width,$height,$content,$possmathjax)=@_;
8677: my $mathjax;
8678: if ($possmathjax) {
8679: $mathjax = <<'ENDJAX';
8680: if (typeof MathJax == 'object') {
8681: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
8682: }
8683: ENDJAX
8684: }
1.1032 www 8685: return (<<ENDADHOC);
1.1046 raeburn 8686: <script type="text/javascript">
1.1032 www 8687: // <![CDATA[
8688: var $funcname = function()
8689: {
8690: modalWindow.windowId = "myModal";
8691: modalWindow.width = $width;
8692: modalWindow.height = $height;
8693: modalWindow.content = '$content';
8694: modalWindow.open();
1.1075.2.155 raeburn 8695: $mathjax
1.1032 www 8696: };
8697: // ]]>
8698: </script>
8699: ENDADHOC
8700: }
8701:
1.1041 www 8702: sub modal_adhoc_inner {
1.1075.2.155 raeburn 8703: my ($funcname,$width,$height,$content,$possmathjax)=@_;
1.1041 www 8704: my $innerwidth=$width-20;
8705: $content=&js_ready(
1.1042 www 8706: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8707: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8708: $content.
1.1041 www 8709: &end_scrollbox().
1.1075.2.42 raeburn 8710: &end_page()
1.1041 www 8711: );
1.1075.2.155 raeburn 8712: return &modal_adhoc_script($funcname,$width,$height,$content,$possmathjax);
1.1041 www 8713: }
8714:
8715: sub modal_adhoc_window {
1.1075.2.155 raeburn 8716: my ($funcname,$width,$height,$content,$linktext,$possmathjax)=@_;
8717: return &modal_adhoc_inner($funcname,$width,$height,$content,$possmathjax).
1.1041 www 8718: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8719: }
8720:
8721: sub modal_adhoc_launch {
8722: my ($funcname,$width,$height,$content)=@_;
8723: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8724: <script type="text/javascript">
8725: // <![CDATA[
8726: $funcname();
8727: // ]]>
8728: </script>
8729: ENDLAUNCH
8730: }
8731:
8732: sub modal_adhoc_close {
8733: return (<<ENDCLOSE);
8734: <script type="text/javascript">
8735: // <![CDATA[
8736: modalWindow.close();
8737: // ]]>
8738: </script>
8739: ENDCLOSE
8740: }
8741:
1.1038 www 8742: sub togglebox_script {
8743: return(<<ENDTOGGLE);
8744: <script type="text/javascript">
8745: // <![CDATA[
8746: function LCtoggleDisplay(id,hidetext,showtext) {
8747: link = document.getElementById(id + "link").childNodes[0];
8748: with (document.getElementById(id).style) {
8749: if (display == "none" ) {
8750: display = "inline";
8751: link.nodeValue = hidetext;
8752: } else {
8753: display = "none";
8754: link.nodeValue = showtext;
8755: }
8756: }
8757: }
8758: // ]]>
8759: </script>
8760: ENDTOGGLE
8761: }
8762:
1.1039 www 8763: sub start_togglebox {
8764: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8765: unless ($heading) { $heading=''; } else { $heading.=' '; }
8766: unless ($showtext) { $showtext=&mt('show'); }
8767: unless ($hidetext) { $hidetext=&mt('hide'); }
8768: unless ($headerbg) { $headerbg='#FFFFFF'; }
8769: return &start_data_table().
8770: &start_data_table_header_row().
8771: '<td bgcolor="'.$headerbg.'">'.$heading.
8772: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8773: $showtext.'\')">'.$showtext.'</a>]</td>'.
8774: &end_data_table_header_row().
8775: '<tr id="'.$id.'" style="display:none""><td>';
8776: }
8777:
8778: sub end_togglebox {
8779: return '</td></tr>'.&end_data_table();
8780: }
8781:
1.1041 www 8782: sub LCprogressbar_script {
1.1075.2.130 raeburn 8783: my ($id,$number_to_do)=@_;
8784: if ($number_to_do) {
8785: return(<<ENDPROGRESS);
1.1041 www 8786: <script type="text/javascript">
8787: // <![CDATA[
1.1045 www 8788: \$('#progressbar$id').progressbar({
1.1041 www 8789: value: 0,
8790: change: function(event, ui) {
8791: var newVal = \$(this).progressbar('option', 'value');
8792: \$('.pblabel', this).text(LCprogressTxt);
8793: }
8794: });
8795: // ]]>
8796: </script>
8797: ENDPROGRESS
1.1075.2.130 raeburn 8798: } else {
8799: return(<<ENDPROGRESS);
8800: <script type="text/javascript">
8801: // <![CDATA[
8802: \$('#progressbar$id').progressbar({
8803: value: false,
8804: create: function(event, ui) {
8805: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8806: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8807: }
8808: });
8809: // ]]>
8810: </script>
8811: ENDPROGRESS
8812: }
1.1041 www 8813: }
8814:
8815: sub LCprogressbarUpdate_script {
8816: return(<<ENDPROGRESSUPDATE);
8817: <style type="text/css">
8818: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8819: .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 8820: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8821: </style>
8822: <script type="text/javascript">
8823: // <![CDATA[
1.1045 www 8824: var LCprogressTxt='---';
8825:
1.1075.2.130 raeburn 8826: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8827: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8828: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8829: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8830: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8831: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8832: } else {
8833: \$('#progressbar'+id).progressbar('value',percent);
8834: }
1.1041 www 8835: }
8836: // ]]>
8837: </script>
8838: ENDPROGRESSUPDATE
8839: }
8840:
1.1042 www 8841: my $LClastpercent;
1.1045 www 8842: my $LCidcnt;
8843: my $LCcurrentid;
1.1042 www 8844:
1.1041 www 8845: sub LCprogressbar {
1.1075.2.130 raeburn 8846: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8847: $LClastpercent=0;
1.1045 www 8848: $LCidcnt++;
8849: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8850: my ($starting,$content);
8851: if ($number_to_do) {
8852: $starting=&mt('Starting');
8853: $content=(<<ENDPROGBAR);
8854: $preamble
1.1045 www 8855: <div id="progressbar$LCcurrentid">
1.1041 www 8856: <span class="pblabel">$starting</span>
8857: </div>
8858: ENDPROGBAR
1.1075.2.130 raeburn 8859: } else {
8860: $starting=&mt('Loading...');
8861: $LClastpercent='false';
8862: $content=(<<ENDPROGBAR);
8863: $preamble
8864: <div id="progressbar$LCcurrentid">
8865: <div class="progress-label">$starting</div>
8866: </div>
8867: ENDPROGBAR
8868: }
8869: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8870: }
8871:
8872: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8873: my ($r,$val,$text,$number_to_do)=@_;
8874: if ($number_to_do) {
8875: unless ($val) {
8876: if ($LClastpercent) {
8877: $val=$LClastpercent;
8878: } else {
8879: $val=0;
8880: }
8881: }
8882: if ($val<0) { $val=0; }
8883: if ($val>100) { $val=0; }
8884: $LClastpercent=$val;
8885: unless ($text) { $text=$val.'%'; }
8886: } else {
8887: $val = 'false';
1.1042 www 8888: }
1.1041 www 8889: $text=&js_ready($text);
1.1044 www 8890: &r_print($r,<<ENDUPDATE);
1.1041 www 8891: <script type="text/javascript">
8892: // <![CDATA[
1.1075.2.130 raeburn 8893: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8894: // ]]>
8895: </script>
8896: ENDUPDATE
1.1035 www 8897: }
8898:
1.1042 www 8899: sub LCprogressbarClose {
8900: my ($r)=@_;
8901: $LClastpercent=0;
1.1044 www 8902: &r_print($r,<<ENDCLOSE);
1.1042 www 8903: <script type="text/javascript">
8904: // <![CDATA[
1.1045 www 8905: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8906: // ]]>
8907: </script>
8908: ENDCLOSE
1.1044 www 8909: }
8910:
8911: sub r_print {
8912: my ($r,$to_print)=@_;
8913: if ($r) {
8914: $r->print($to_print);
8915: $r->rflush();
8916: } else {
8917: print($to_print);
8918: }
1.1042 www 8919: }
8920:
1.320 albertel 8921: sub html_encode {
8922: my ($result) = @_;
8923:
1.322 albertel 8924: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8925:
8926: return $result;
8927: }
1.1044 www 8928:
1.317 albertel 8929: sub js_ready {
8930: my ($result) = @_;
8931:
1.323 albertel 8932: $result =~ s/[\n\r]/ /xmsg;
8933: $result =~ s/\\/\\\\/xmsg;
8934: $result =~ s/'/\\'/xmsg;
1.372 albertel 8935: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8936:
8937: return $result;
8938: }
8939:
1.315 albertel 8940: sub validate_page {
8941: if ( exists($env{'internal.start_page'})
1.316 albertel 8942: && $env{'internal.start_page'} > 1) {
8943: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8944: $env{'internal.start_page'}.' '.
1.316 albertel 8945: $ENV{'request.filename'});
1.315 albertel 8946: }
8947: if ( exists($env{'internal.end_page'})
1.316 albertel 8948: && $env{'internal.end_page'} > 1) {
8949: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8950: $env{'internal.end_page'}.' '.
1.316 albertel 8951: $env{'request.filename'});
1.315 albertel 8952: }
8953: if ( exists($env{'internal.start_page'})
8954: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8955: &Apache::lonnet::logthis('start_page called without end_page '.
8956: $env{'request.filename'});
1.315 albertel 8957: }
8958: if ( ! exists($env{'internal.start_page'})
8959: && exists($env{'internal.end_page'})) {
1.316 albertel 8960: &Apache::lonnet::logthis('end_page called without start_page'.
8961: $env{'request.filename'});
1.315 albertel 8962: }
1.306 albertel 8963: }
1.315 albertel 8964:
1.996 www 8965:
8966: sub start_scrollbox {
1.1075.2.56 raeburn 8967: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8968: unless ($outerwidth) { $outerwidth='520px'; }
8969: unless ($width) { $width='500px'; }
8970: unless ($height) { $height='200px'; }
1.1075 raeburn 8971: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8972: if ($id ne '') {
1.1075.2.42 raeburn 8973: $table_id = ' id="table_'.$id.'"';
8974: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8975: }
1.1075 raeburn 8976: if ($bgcolor ne '') {
8977: $tdcol = "background-color: $bgcolor;";
8978: }
1.1075.2.42 raeburn 8979: my $nicescroll_js;
8980: if ($env{'browser.mobile'}) {
8981: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8982: }
1.1075 raeburn 8983: return <<"END";
1.1075.2.42 raeburn 8984: $nicescroll_js
8985:
8986: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8987: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8988: END
1.996 www 8989: }
8990:
8991: sub end_scrollbox {
1.1036 www 8992: return '</div></td></tr></table>';
1.996 www 8993: }
8994:
1.1075.2.42 raeburn 8995: sub nicescroll_javascript {
8996: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8997: my %options;
8998: if (ref($cursor) eq 'HASH') {
8999: %options = %{$cursor};
9000: }
9001: unless ($options{'railalign'} =~ /^left|right$/) {
9002: $options{'railalign'} = 'left';
9003: }
9004: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9005: my $function = &get_users_function();
9006: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
9007: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9008: $options{'cursorcolor'} = '#00F';
9009: }
9010: }
9011: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9012: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
9013: $options{'cursoropacity'}='1.0';
9014: }
9015: } else {
9016: $options{'cursoropacity'}='1.0';
9017: }
9018: if ($options{'cursorfixedheight'} eq 'none') {
9019: delete($options{'cursorfixedheight'});
9020: } else {
9021: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9022: }
9023: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9024: delete($options{'railoffset'});
9025: }
9026: my @niceoptions;
9027: while (my($key,$value) = each(%options)) {
9028: if ($value =~ /^\{.+\}$/) {
9029: push(@niceoptions,$key.':'.$value);
9030: } else {
9031: push(@niceoptions,$key.':"'.$value.'"');
9032: }
9033: }
9034: my $nicescroll_js = '
9035: $(document).ready(
9036: function() {
9037: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9038: }
9039: );
9040: ';
9041: if ($framecheck) {
9042: $nicescroll_js .= '
9043: function expand_div(caller) {
9044: if (top === self) {
9045: document.getElementById("'.$id.'").style.width = "auto";
9046: document.getElementById("'.$id.'").style.height = "auto";
9047: } else {
9048: try {
9049: if (parent.frames) {
9050: if (parent.frames.length > 1) {
9051: var framesrc = parent.frames[1].location.href;
9052: var currsrc = framesrc.replace(/\#.*$/,"");
9053: if ((caller == "search") || (currsrc == "'.$location.'")) {
9054: document.getElementById("'.$id.'").style.width = "auto";
9055: document.getElementById("'.$id.'").style.height = "auto";
9056: }
9057: }
9058: }
9059: } catch (e) {
9060: return;
9061: }
9062: }
9063: return;
9064: }
9065: ';
9066: }
9067: if ($needjsready) {
9068: $nicescroll_js = '
9069: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9070: } else {
9071: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9072: }
9073: return $nicescroll_js;
9074: }
9075:
1.318 albertel 9076: sub simple_error_page {
1.1075.2.49 raeburn 9077: my ($r,$title,$msg,$args) = @_;
9078: if (ref($args) eq 'HASH') {
9079: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9080: } else {
9081: $msg = &mt($msg);
9082: }
9083:
1.318 albertel 9084: my $page =
9085: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 9086: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9087: &Apache::loncommon::end_page();
9088: if (ref($r)) {
9089: $r->print($page);
1.327 albertel 9090: return;
1.318 albertel 9091: }
9092: return $page;
9093: }
1.347 albertel 9094:
9095: {
1.610 albertel 9096: my @row_count;
1.961 onken 9097:
9098: sub start_data_table_count {
9099: unshift(@row_count, 0);
9100: return;
9101: }
9102:
9103: sub end_data_table_count {
9104: shift(@row_count);
9105: return;
9106: }
9107:
1.347 albertel 9108: sub start_data_table {
1.1018 raeburn 9109: my ($add_class,$id) = @_;
1.422 albertel 9110: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9111: my $table_id;
9112: if (defined($id)) {
9113: $table_id = ' id="'.$id.'"';
9114: }
1.961 onken 9115: &start_data_table_count();
1.1018 raeburn 9116: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9117: }
9118:
9119: sub end_data_table {
1.961 onken 9120: &end_data_table_count();
1.389 albertel 9121: return '</table>'."\n";;
1.347 albertel 9122: }
9123:
9124: sub start_data_table_row {
1.974 wenzelju 9125: my ($add_class, $id) = @_;
1.610 albertel 9126: $row_count[0]++;
9127: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9128: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9129: $id = (' id="'.$id.'"') unless ($id eq '');
9130: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9131: }
1.471 banghart 9132:
9133: sub continue_data_table_row {
1.974 wenzelju 9134: my ($add_class, $id) = @_;
1.610 albertel 9135: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9136: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9137: $id = (' id="'.$id.'"') unless ($id eq '');
9138: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9139: }
1.347 albertel 9140:
9141: sub end_data_table_row {
1.389 albertel 9142: return '</tr>'."\n";;
1.347 albertel 9143: }
1.367 www 9144:
1.421 albertel 9145: sub start_data_table_empty_row {
1.707 bisitz 9146: # $row_count[0]++;
1.421 albertel 9147: return '<tr class="LC_empty_row" >'."\n";;
9148: }
9149:
9150: sub end_data_table_empty_row {
9151: return '</tr>'."\n";;
9152: }
9153:
1.367 www 9154: sub start_data_table_header_row {
1.389 albertel 9155: return '<tr class="LC_header_row">'."\n";;
1.367 www 9156: }
9157:
9158: sub end_data_table_header_row {
1.389 albertel 9159: return '</tr>'."\n";;
1.367 www 9160: }
1.890 droeschl 9161:
9162: sub data_table_caption {
9163: my $caption = shift;
9164: return "<caption class=\"LC_caption\">$caption</caption>";
9165: }
1.347 albertel 9166: }
9167:
1.548 albertel 9168: =pod
9169:
9170: =item * &inhibit_menu_check($arg)
9171:
9172: Checks for a inhibitmenu state and generates output to preserve it
9173:
9174: Inputs: $arg - can be any of
9175: - undef - in which case the return value is a string
9176: to add into arguments list of a uri
9177: - 'input' - in which case the return value is a HTML
9178: <form> <input> field of type hidden to
9179: preserve the value
9180: - a url - in which case the return value is the url with
9181: the neccesary cgi args added to preserve the
9182: inhibitmenu state
9183: - a ref to a url - no return value, but the string is
9184: updated to include the neccessary cgi
9185: args to preserve the inhibitmenu state
9186:
9187: =cut
9188:
9189: sub inhibit_menu_check {
9190: my ($arg) = @_;
9191: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9192: if ($arg eq 'input') {
9193: if ($env{'form.inhibitmenu'}) {
9194: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9195: } else {
9196: return
9197: }
9198: }
9199: if ($env{'form.inhibitmenu'}) {
9200: if (ref($arg)) {
9201: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9202: } elsif ($arg eq '') {
9203: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9204: } else {
9205: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9206: }
9207: }
9208: if (!ref($arg)) {
9209: return $arg;
9210: }
9211: }
9212:
1.251 albertel 9213: ###############################################
1.182 matthew 9214:
9215: =pod
9216:
1.549 albertel 9217: =back
9218:
9219: =head1 User Information Routines
9220:
9221: =over 4
9222:
1.405 albertel 9223: =item * &get_users_function()
1.182 matthew 9224:
9225: Used by &bodytag to determine the current users primary role.
9226: Returns either 'student','coordinator','admin', or 'author'.
9227:
9228: =cut
9229:
9230: ###############################################
9231: sub get_users_function {
1.815 tempelho 9232: my $function = 'norole';
1.818 tempelho 9233: if ($env{'request.role'}=~/^(st)/) {
9234: $function='student';
9235: }
1.907 raeburn 9236: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9237: $function='coordinator';
9238: }
1.258 albertel 9239: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9240: $function='admin';
9241: }
1.826 bisitz 9242: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9243: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9244: $function='author';
9245: }
9246: return $function;
1.54 www 9247: }
1.99 www 9248:
9249: ###############################################
9250:
1.233 raeburn 9251: =pod
9252:
1.821 raeburn 9253: =item * &show_course()
9254:
9255: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9256: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9257:
9258: Inputs:
9259: None
9260:
9261: Outputs:
9262: Scalar: 1 if 'Course' to be used, 0 otherwise.
9263:
9264: =cut
9265:
9266: ###############################################
9267: sub show_course {
9268: my $course = !$env{'user.adv'};
9269: if (!$env{'user.adv'}) {
9270: foreach my $env (keys(%env)) {
9271: next if ($env !~ m/^user\.priv\./);
9272: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9273: $course = 0;
9274: last;
9275: }
9276: }
9277: }
9278: return $course;
9279: }
9280:
9281: ###############################################
9282:
9283: =pod
9284:
1.542 raeburn 9285: =item * &check_user_status()
1.274 raeburn 9286:
9287: Determines current status of supplied role for a
9288: specific user. Roles can be active, previous or future.
9289:
9290: Inputs:
9291: user's domain, user's username, course's domain,
1.375 raeburn 9292: course's number, optional section ID.
1.274 raeburn 9293:
9294: Outputs:
9295: role status: active, previous or future.
9296:
9297: =cut
9298:
9299: sub check_user_status {
1.412 raeburn 9300: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9301: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9302: my @uroles = keys(%userinfo);
1.274 raeburn 9303: my $srchstr;
9304: my $active_chk = 'none';
1.412 raeburn 9305: my $now = time;
1.274 raeburn 9306: if (@uroles > 0) {
1.908 raeburn 9307: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9308: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9309: } else {
1.412 raeburn 9310: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9311: }
9312: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9313: my $role_end = 0;
9314: my $role_start = 0;
9315: $active_chk = 'active';
1.412 raeburn 9316: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9317: $role_end = $1;
9318: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9319: $role_start = $1;
1.274 raeburn 9320: }
9321: }
9322: if ($role_start > 0) {
1.412 raeburn 9323: if ($now < $role_start) {
1.274 raeburn 9324: $active_chk = 'future';
9325: }
9326: }
9327: if ($role_end > 0) {
1.412 raeburn 9328: if ($now > $role_end) {
1.274 raeburn 9329: $active_chk = 'previous';
9330: }
9331: }
9332: }
9333: }
9334: return $active_chk;
9335: }
9336:
9337: ###############################################
9338:
9339: =pod
9340:
1.405 albertel 9341: =item * &get_sections()
1.233 raeburn 9342:
9343: Determines all the sections for a course including
9344: sections with students and sections containing other roles.
1.419 raeburn 9345: Incoming parameters:
9346:
9347: 1. domain
9348: 2. course number
9349: 3. reference to array containing roles for which sections should
9350: be gathered (optional).
9351: 4. reference to array containing status types for which sections
9352: should be gathered (optional).
9353:
9354: If the third argument is undefined, sections are gathered for any role.
9355: If the fourth argument is undefined, sections are gathered for any status.
9356: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9357:
1.374 raeburn 9358: Returns section hash (keys are section IDs, values are
9359: number of users in each section), subject to the
1.419 raeburn 9360: optional roles filter, optional status filter
1.233 raeburn 9361:
9362: =cut
9363:
9364: ###############################################
9365: sub get_sections {
1.419 raeburn 9366: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9367: if (!defined($cdom) || !defined($cnum)) {
9368: my $cid = $env{'request.course.id'};
9369:
9370: return if (!defined($cid));
9371:
9372: $cdom = $env{'course.'.$cid.'.domain'};
9373: $cnum = $env{'course.'.$cid.'.num'};
9374: }
9375:
9376: my %sectioncount;
1.419 raeburn 9377: my $now = time;
1.240 albertel 9378:
1.1075.2.33 raeburn 9379: my $check_students = 1;
9380: my $only_students = 0;
9381: if (ref($possible_roles) eq 'ARRAY') {
9382: if (grep(/^st$/,@{$possible_roles})) {
9383: if (@{$possible_roles} == 1) {
9384: $only_students = 1;
9385: }
9386: } else {
9387: $check_students = 0;
9388: }
9389: }
9390:
9391: if ($check_students) {
1.276 albertel 9392: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9393: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9394: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9395: my $start_index = &Apache::loncoursedata::CL_START();
9396: my $end_index = &Apache::loncoursedata::CL_END();
9397: my $status;
1.366 albertel 9398: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9399: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9400: $data->[$status_index],
9401: $data->[$start_index],
9402: $data->[$end_index]);
9403: if ($stu_status eq 'Active') {
9404: $status = 'active';
9405: } elsif ($end < $now) {
9406: $status = 'previous';
9407: } elsif ($start > $now) {
9408: $status = 'future';
9409: }
9410: if ($section ne '-1' && $section !~ /^\s*$/) {
9411: if ((!defined($possible_status)) || (($status ne '') &&
9412: (grep/^\Q$status\E$/,@{$possible_status}))) {
9413: $sectioncount{$section}++;
9414: }
1.240 albertel 9415: }
9416: }
9417: }
1.1075.2.33 raeburn 9418: if ($only_students) {
9419: return %sectioncount;
9420: }
1.240 albertel 9421: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9422: foreach my $user (sort(keys(%courseroles))) {
9423: if ($user !~ /^(\w{2})/) { next; }
9424: my ($role) = ($user =~ /^(\w{2})/);
9425: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9426: my ($section,$status);
1.240 albertel 9427: if ($role eq 'cr' &&
9428: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9429: $section=$1;
9430: }
9431: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9432: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9433: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9434: if ($end == -1 && $start == -1) {
9435: next; #deleted role
9436: }
9437: if (!defined($possible_status)) {
9438: $sectioncount{$section}++;
9439: } else {
9440: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9441: $status = 'active';
9442: } elsif ($end < $now) {
9443: $status = 'future';
9444: } elsif ($start > $now) {
9445: $status = 'previous';
9446: }
9447: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9448: $sectioncount{$section}++;
9449: }
9450: }
1.233 raeburn 9451: }
1.366 albertel 9452: return %sectioncount;
1.233 raeburn 9453: }
9454:
1.274 raeburn 9455: ###############################################
1.294 raeburn 9456:
9457: =pod
1.405 albertel 9458:
9459: =item * &get_course_users()
9460:
1.275 raeburn 9461: Retrieves usernames:domains for users in the specified course
9462: with specific role(s), and access status.
9463:
9464: Incoming parameters:
1.277 albertel 9465: 1. course domain
9466: 2. course number
9467: 3. access status: users must have - either active,
1.275 raeburn 9468: previous, future, or all.
1.277 albertel 9469: 4. reference to array of permissible roles
1.288 raeburn 9470: 5. reference to array of section restrictions (optional)
9471: 6. reference to results object (hash of hashes).
9472: 7. reference to optional userdata hash
1.609 raeburn 9473: 8. reference to optional statushash
1.630 raeburn 9474: 9. flag if privileged users (except those set to unhide in
9475: course settings) should be excluded
1.609 raeburn 9476: Keys of top level results hash are roles.
1.275 raeburn 9477: Keys of inner hashes are username:domain, with
9478: values set to access type.
1.288 raeburn 9479: Optional userdata hash returns an array with arguments in the
9480: same order as loncoursedata::get_classlist() for student data.
9481:
1.609 raeburn 9482: Optional statushash returns
9483:
1.288 raeburn 9484: Entries for end, start, section and status are blank because
9485: of the possibility of multiple values for non-student roles.
9486:
1.275 raeburn 9487: =cut
1.405 albertel 9488:
1.275 raeburn 9489: ###############################################
1.405 albertel 9490:
1.275 raeburn 9491: sub get_course_users {
1.630 raeburn 9492: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9493: my %idx = ();
1.419 raeburn 9494: my %seclists;
1.288 raeburn 9495:
9496: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9497: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9498: $idx{end} = &Apache::loncoursedata::CL_END();
9499: $idx{start} = &Apache::loncoursedata::CL_START();
9500: $idx{id} = &Apache::loncoursedata::CL_ID();
9501: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9502: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9503: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9504:
1.290 albertel 9505: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9506: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9507: my $now = time;
1.277 albertel 9508: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9509: my $match = 0;
1.412 raeburn 9510: my $secmatch = 0;
1.419 raeburn 9511: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9512: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9513: if ($section eq '') {
9514: $section = 'none';
9515: }
1.291 albertel 9516: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9517: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9518: $secmatch = 1;
9519: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9520: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9521: $secmatch = 1;
9522: }
9523: } else {
1.419 raeburn 9524: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9525: $secmatch = 1;
9526: }
1.290 albertel 9527: }
1.412 raeburn 9528: if (!$secmatch) {
9529: next;
9530: }
1.419 raeburn 9531: }
1.275 raeburn 9532: if (defined($$types{'active'})) {
1.288 raeburn 9533: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9534: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9535: $match = 1;
1.275 raeburn 9536: }
9537: }
9538: if (defined($$types{'previous'})) {
1.609 raeburn 9539: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9540: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9541: $match = 1;
1.275 raeburn 9542: }
9543: }
9544: if (defined($$types{'future'})) {
1.609 raeburn 9545: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9546: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9547: $match = 1;
1.275 raeburn 9548: }
9549: }
1.609 raeburn 9550: if ($match) {
9551: push(@{$seclists{$student}},$section);
9552: if (ref($userdata) eq 'HASH') {
9553: $$userdata{$student} = $$classlist{$student};
9554: }
9555: if (ref($statushash) eq 'HASH') {
9556: $statushash->{$student}{'st'}{$section} = $status;
9557: }
1.288 raeburn 9558: }
1.275 raeburn 9559: }
9560: }
1.412 raeburn 9561: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9562: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9563: my $now = time;
1.609 raeburn 9564: my %displaystatus = ( previous => 'Expired',
9565: active => 'Active',
9566: future => 'Future',
9567: );
1.1075.2.36 raeburn 9568: my (%nothide,@possdoms);
1.630 raeburn 9569: if ($hidepriv) {
9570: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9571: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9572: if ($user !~ /:/) {
9573: $nothide{join(':',split(/[\@]/,$user))}=1;
9574: } else {
9575: $nothide{$user} = 1;
9576: }
9577: }
1.1075.2.36 raeburn 9578: my @possdoms = ($cdom);
9579: if ($coursehash{'checkforpriv'}) {
9580: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9581: }
1.630 raeburn 9582: }
1.439 raeburn 9583: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9584: my $match = 0;
1.412 raeburn 9585: my $secmatch = 0;
1.439 raeburn 9586: my $status;
1.412 raeburn 9587: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9588: $user =~ s/:$//;
1.439 raeburn 9589: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9590: if ($end == -1 || $start == -1) {
9591: next;
9592: }
9593: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9594: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9595: my ($uname,$udom) = split(/:/,$user);
9596: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9597: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9598: $secmatch = 1;
9599: } elsif ($usec eq '') {
1.420 albertel 9600: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9601: $secmatch = 1;
9602: }
9603: } else {
9604: if (grep(/^\Q$usec\E$/,@{$sections})) {
9605: $secmatch = 1;
9606: }
9607: }
9608: if (!$secmatch) {
9609: next;
9610: }
1.288 raeburn 9611: }
1.419 raeburn 9612: if ($usec eq '') {
9613: $usec = 'none';
9614: }
1.275 raeburn 9615: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9616: if ($hidepriv) {
1.1075.2.36 raeburn 9617: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9618: (!$nothide{$uname.':'.$udom})) {
9619: next;
9620: }
9621: }
1.503 raeburn 9622: if ($end > 0 && $end < $now) {
1.439 raeburn 9623: $status = 'previous';
9624: } elsif ($start > $now) {
9625: $status = 'future';
9626: } else {
9627: $status = 'active';
9628: }
1.277 albertel 9629: foreach my $type (keys(%{$types})) {
1.275 raeburn 9630: if ($status eq $type) {
1.420 albertel 9631: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9632: push(@{$$users{$role}{$user}},$type);
9633: }
1.288 raeburn 9634: $match = 1;
9635: }
9636: }
1.419 raeburn 9637: if (($match) && (ref($userdata) eq 'HASH')) {
9638: if (!exists($$userdata{$uname.':'.$udom})) {
9639: &get_user_info($udom,$uname,\%idx,$userdata);
9640: }
1.420 albertel 9641: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9642: push(@{$seclists{$uname.':'.$udom}},$usec);
9643: }
1.609 raeburn 9644: if (ref($statushash) eq 'HASH') {
9645: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9646: }
1.275 raeburn 9647: }
9648: }
9649: }
9650: }
1.290 albertel 9651: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9652: if ((defined($cdom)) && (defined($cnum))) {
9653: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9654: if ( defined($csettings{'internal.courseowner'}) ) {
9655: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9656: next if ($owner eq '');
9657: my ($ownername,$ownerdom);
9658: if ($owner =~ /^([^:]+):([^:]+)$/) {
9659: $ownername = $1;
9660: $ownerdom = $2;
9661: } else {
9662: $ownername = $owner;
9663: $ownerdom = $cdom;
9664: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9665: }
9666: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9667: if (defined($userdata) &&
1.609 raeburn 9668: !exists($$userdata{$owner})) {
9669: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9670: if (!grep(/^none$/,@{$seclists{$owner}})) {
9671: push(@{$seclists{$owner}},'none');
9672: }
9673: if (ref($statushash) eq 'HASH') {
9674: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9675: }
1.290 albertel 9676: }
1.279 raeburn 9677: }
9678: }
9679: }
1.419 raeburn 9680: foreach my $user (keys(%seclists)) {
9681: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9682: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9683: }
1.275 raeburn 9684: }
9685: return;
9686: }
9687:
1.288 raeburn 9688: sub get_user_info {
9689: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9690: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9691: &plainname($uname,$udom,'lastname');
1.291 albertel 9692: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9693: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9694: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9695: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9696: return;
9697: }
1.275 raeburn 9698:
1.472 raeburn 9699: ###############################################
9700:
9701: =pod
9702:
9703: =item * &get_user_quota()
9704:
1.1075.2.41 raeburn 9705: Retrieves quota assigned for storage of user files.
9706: Default is to report quota for portfolio files.
1.472 raeburn 9707:
9708: Incoming parameters:
9709: 1. user's username
9710: 2. user's domain
1.1075.2.41 raeburn 9711: 3. quota name - portfolio, author, or course
9712: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9713: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9714: course
1.472 raeburn 9715:
9716: Returns:
1.1075.2.58 raeburn 9717: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9718: 2. (Optional) Type of setting: custom or default
9719: (individually assigned or default for user's
9720: institutional status).
9721: 3. (Optional) - User's institutional status (e.g., faculty, staff
9722: or student - types as defined in localenroll::inst_usertypes
9723: for user's domain, which determines default quota for user.
9724: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9725:
9726: If a value has been stored in the user's environment,
1.536 raeburn 9727: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9728: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9729:
9730: =cut
9731:
9732: ###############################################
9733:
9734:
9735: sub get_user_quota {
1.1075.2.42 raeburn 9736: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9737: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9738: if (!defined($udom)) {
9739: $udom = $env{'user.domain'};
9740: }
9741: if (!defined($uname)) {
9742: $uname = $env{'user.name'};
9743: }
9744: if (($udom eq '' || $uname eq '') ||
9745: ($udom eq 'public') && ($uname eq 'public')) {
9746: $quota = 0;
1.536 raeburn 9747: $quotatype = 'default';
9748: $defquota = 0;
1.472 raeburn 9749: } else {
1.536 raeburn 9750: my $inststatus;
1.1075.2.41 raeburn 9751: if ($quotaname eq 'course') {
9752: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9753: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9754: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9755: } else {
9756: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9757: $quota = $cenv{'internal.uploadquota'};
9758: }
1.536 raeburn 9759: } else {
1.1075.2.41 raeburn 9760: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9761: if ($quotaname eq 'author') {
9762: $quota = $env{'environment.authorquota'};
9763: } else {
9764: $quota = $env{'environment.portfolioquota'};
9765: }
9766: $inststatus = $env{'environment.inststatus'};
9767: } else {
9768: my %userenv =
9769: &Apache::lonnet::get('environment',['portfolioquota',
9770: 'authorquota','inststatus'],$udom,$uname);
9771: my ($tmp) = keys(%userenv);
9772: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9773: if ($quotaname eq 'author') {
9774: $quota = $userenv{'authorquota'};
9775: } else {
9776: $quota = $userenv{'portfolioquota'};
9777: }
9778: $inststatus = $userenv{'inststatus'};
9779: } else {
9780: undef(%userenv);
9781: }
9782: }
9783: }
9784: if ($quota eq '' || wantarray) {
9785: if ($quotaname eq 'course') {
9786: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9787: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9788: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9789: $defquota = $domdefs{$crstype.'quota'};
9790: }
9791: if ($defquota eq '') {
9792: $defquota = 500;
9793: }
1.1075.2.41 raeburn 9794: } else {
9795: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9796: }
9797: if ($quota eq '') {
9798: $quota = $defquota;
9799: $quotatype = 'default';
9800: } else {
9801: $quotatype = 'custom';
9802: }
1.472 raeburn 9803: }
9804: }
1.536 raeburn 9805: if (wantarray) {
9806: return ($quota,$quotatype,$settingstatus,$defquota);
9807: } else {
9808: return $quota;
9809: }
1.472 raeburn 9810: }
9811:
9812: ###############################################
9813:
9814: =pod
9815:
9816: =item * &default_quota()
9817:
1.536 raeburn 9818: Retrieves default quota assigned for storage of user portfolio files,
9819: given an (optional) user's institutional status.
1.472 raeburn 9820:
9821: Incoming parameters:
1.1075.2.42 raeburn 9822:
1.472 raeburn 9823: 1. domain
1.536 raeburn 9824: 2. (Optional) institutional status(es). This is a : separated list of
9825: status types (e.g., faculty, staff, student etc.)
9826: which apply to the user for whom the default is being retrieved.
9827: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9828: default quota will be returned.
9829: 3. quota name - portfolio, author, or course
9830: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9831:
9832: Returns:
1.1075.2.42 raeburn 9833:
1.1075.2.58 raeburn 9834: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9835: 2. (Optional) institutional type which determined the value of the
9836: default quota.
1.472 raeburn 9837:
9838: If a value has been stored in the domain's configuration db,
9839: it will return that, otherwise it returns 20 (for backwards
9840: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9841: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9842:
1.536 raeburn 9843: If the user's status includes multiple types (e.g., staff and student),
9844: the largest default quota which applies to the user determines the
9845: default quota returned.
9846:
1.472 raeburn 9847: =cut
9848:
9849: ###############################################
9850:
9851:
9852: sub default_quota {
1.1075.2.41 raeburn 9853: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9854: my ($defquota,$settingstatus);
9855: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9856: ['quotas'],$udom);
1.1075.2.41 raeburn 9857: my $key = 'defaultquota';
9858: if ($quotaname eq 'author') {
9859: $key = 'authorquota';
9860: }
1.622 raeburn 9861: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9862: if ($inststatus ne '') {
1.765 raeburn 9863: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9864: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9865: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9866: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9867: if ($defquota eq '') {
1.1075.2.41 raeburn 9868: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9869: $settingstatus = $item;
1.1075.2.41 raeburn 9870: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9871: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9872: $settingstatus = $item;
9873: }
9874: }
1.1075.2.41 raeburn 9875: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9876: if ($quotahash{'quotas'}{$item} ne '') {
9877: if ($defquota eq '') {
9878: $defquota = $quotahash{'quotas'}{$item};
9879: $settingstatus = $item;
9880: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9881: $defquota = $quotahash{'quotas'}{$item};
9882: $settingstatus = $item;
9883: }
1.536 raeburn 9884: }
9885: }
9886: }
9887: }
9888: if ($defquota eq '') {
1.1075.2.41 raeburn 9889: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9890: $defquota = $quotahash{'quotas'}{$key}{'default'};
9891: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9892: $defquota = $quotahash{'quotas'}{'default'};
9893: }
1.536 raeburn 9894: $settingstatus = 'default';
1.1075.2.42 raeburn 9895: if ($defquota eq '') {
9896: if ($quotaname eq 'author') {
9897: $defquota = 500;
9898: }
9899: }
1.536 raeburn 9900: }
9901: } else {
9902: $settingstatus = 'default';
1.1075.2.41 raeburn 9903: if ($quotaname eq 'author') {
9904: $defquota = 500;
9905: } else {
9906: $defquota = 20;
9907: }
1.536 raeburn 9908: }
9909: if (wantarray) {
9910: return ($defquota,$settingstatus);
1.472 raeburn 9911: } else {
1.536 raeburn 9912: return $defquota;
1.472 raeburn 9913: }
9914: }
9915:
1.1075.2.41 raeburn 9916: ###############################################
9917:
9918: =pod
9919:
1.1075.2.42 raeburn 9920: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9921:
9922: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9923: of existing file within authoring space will cause quota for the authoring
9924: space to be exceeded.
9925:
9926: Same, if upload of a file directly to a course/community via Course Editor
9927: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9928:
1.1075.2.61 raeburn 9929: Inputs: 7
1.1075.2.42 raeburn 9930: 1. username or coursenum
1.1075.2.41 raeburn 9931: 2. domain
1.1075.2.42 raeburn 9932: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9933: 4. filename of file for which action is being requested
9934: 5. filesize (kB) of file
9935: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9936: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9937:
9938: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9939: otherwise return null.
9940:
1.1075.2.42 raeburn 9941: =back
9942:
1.1075.2.41 raeburn 9943: =cut
9944:
1.1075.2.42 raeburn 9945: sub excess_filesize_warning {
1.1075.2.59 raeburn 9946: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9947: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9948: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9949: if ($context eq 'author') {
9950: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9951: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9952: } else {
9953: foreach my $subdir ('docs','supplemental') {
9954: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9955: }
9956: }
1.1075.2.41 raeburn 9957: $disk_quota = int($disk_quota * 1000);
9958: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9959: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9960: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9961: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9962: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9963: $disk_quota,$current_disk_usage).
9964: '</p>';
9965: }
9966: return;
9967: }
9968:
9969: ###############################################
9970:
9971:
1.384 raeburn 9972: sub get_secgrprole_info {
9973: my ($cdom,$cnum,$needroles,$type) = @_;
9974: my %sections_count = &get_sections($cdom,$cnum);
9975: my @sections = (sort {$a <=> $b} keys(%sections_count));
9976: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9977: my @groups = sort(keys(%curr_groups));
9978: my $allroles = [];
9979: my $rolehash;
9980: my $accesshash = {
9981: active => 'Currently has access',
9982: future => 'Will have future access',
9983: previous => 'Previously had access',
9984: };
9985: if ($needroles) {
9986: $rolehash = {'all' => 'all'};
1.385 albertel 9987: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9988: if (&Apache::lonnet::error(%user_roles)) {
9989: undef(%user_roles);
9990: }
9991: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9992: my ($role)=split(/\:/,$item,2);
9993: if ($role eq 'cr') { next; }
9994: if ($role =~ /^cr/) {
9995: $$rolehash{$role} = (split('/',$role))[3];
9996: } else {
9997: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9998: }
9999: }
10000: foreach my $key (sort(keys(%{$rolehash}))) {
10001: push(@{$allroles},$key);
10002: }
10003: push (@{$allroles},'st');
10004: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10005: }
10006: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10007: }
10008:
1.555 raeburn 10009: sub user_picker {
1.1075.2.127 raeburn 10010: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10011: my $currdom = $dom;
1.1075.2.114 raeburn 10012: my @alldoms = &Apache::lonnet::all_domains();
10013: if (@alldoms == 1) {
10014: my %domsrch = &Apache::lonnet::get_dom('configuration',
10015: ['directorysrch'],$alldoms[0]);
10016: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10017: my $showdom = $domdesc;
10018: if ($showdom eq '') {
10019: $showdom = $dom;
10020: }
10021: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10022: if ((!$domsrch{'directorysrch'}{'available'}) &&
10023: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10024: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10025: }
10026: }
10027: }
1.555 raeburn 10028: my %curr_selected = (
10029: srchin => 'dom',
1.580 raeburn 10030: srchby => 'lastname',
1.555 raeburn 10031: );
10032: my $srchterm;
1.625 raeburn 10033: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10034: if ($srch->{'srchby'} ne '') {
10035: $curr_selected{'srchby'} = $srch->{'srchby'};
10036: }
10037: if ($srch->{'srchin'} ne '') {
10038: $curr_selected{'srchin'} = $srch->{'srchin'};
10039: }
10040: if ($srch->{'srchtype'} ne '') {
10041: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10042: }
10043: if ($srch->{'srchdomain'} ne '') {
10044: $currdom = $srch->{'srchdomain'};
10045: }
10046: $srchterm = $srch->{'srchterm'};
10047: }
1.1075.2.98 raeburn 10048: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10049: 'usr' => 'Search criteria',
1.563 raeburn 10050: 'doma' => 'Domain/institution to search',
1.558 albertel 10051: 'uname' => 'username',
10052: 'lastname' => 'last name',
1.555 raeburn 10053: 'lastfirst' => 'last name, first name',
1.558 albertel 10054: 'crs' => 'in this course',
1.576 raeburn 10055: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10056: 'alc' => 'all LON-CAPA',
1.573 raeburn 10057: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10058: 'exact' => 'is',
10059: 'contains' => 'contains',
1.569 raeburn 10060: 'begins' => 'begins with',
1.1075.2.98 raeburn 10061: );
10062: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10063: 'youm' => "You must include some text to search for.",
10064: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10065: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10066: 'yomc' => "You must choose a domain when using an institutional directory search.",
10067: 'ymcd' => "You must choose a domain when using a domain search.",
10068: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10069: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10070: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10071: );
1.1075.2.98 raeburn 10072: &html_escape(\%html_lt);
10073: &js_escape(\%js_lt);
1.1075.2.115 raeburn 10074: my $domform;
1.1075.2.126 raeburn 10075: my $allow_blank = 1;
1.1075.2.115 raeburn 10076: if ($fixeddom) {
1.1075.2.126 raeburn 10077: $allow_blank = 0;
10078: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 10079: } else {
1.1075.2.126 raeburn 10080: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 10081: }
1.563 raeburn 10082: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10083:
10084: my @srchins = ('crs','dom','alc','instd');
10085:
10086: foreach my $option (@srchins) {
10087: # FIXME 'alc' option unavailable until
10088: # loncreateuser::print_user_query_page()
10089: # has been completed.
10090: next if ($option eq 'alc');
1.880 raeburn 10091: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10092: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 10093: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10094: if ($curr_selected{'srchin'} eq $option) {
10095: $srchinsel .= '
1.1075.2.98 raeburn 10096: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10097: } else {
10098: $srchinsel .= '
1.1075.2.98 raeburn 10099: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10100: }
1.555 raeburn 10101: }
1.563 raeburn 10102: $srchinsel .= "\n </select>\n";
1.555 raeburn 10103:
10104: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10105: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10106: if ($curr_selected{'srchby'} eq $option) {
10107: $srchbysel .= '
1.1075.2.98 raeburn 10108: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10109: } else {
10110: $srchbysel .= '
1.1075.2.98 raeburn 10111: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10112: }
10113: }
10114: $srchbysel .= "\n </select>\n";
10115:
10116: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10117: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10118: if ($curr_selected{'srchtype'} eq $option) {
10119: $srchtypesel .= '
1.1075.2.98 raeburn 10120: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10121: } else {
10122: $srchtypesel .= '
1.1075.2.98 raeburn 10123: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10124: }
10125: }
10126: $srchtypesel .= "\n </select>\n";
10127:
1.558 albertel 10128: my ($newuserscript,$new_user_create);
1.994 raeburn 10129: my $context_dom = $env{'request.role.domain'};
10130: if ($context eq 'requestcrs') {
10131: if ($env{'form.coursedom'} ne '') {
10132: $context_dom = $env{'form.coursedom'};
10133: }
10134: }
1.556 raeburn 10135: if ($forcenewuser) {
1.576 raeburn 10136: if (ref($srch) eq 'HASH') {
1.994 raeburn 10137: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10138: if ($cancreate) {
10139: $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>';
10140: } else {
1.799 bisitz 10141: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10142: my %usertypetext = (
10143: official => 'institutional',
10144: unofficial => 'non-institutional',
10145: );
1.799 bisitz 10146: $new_user_create = '<p class="LC_warning">'
10147: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10148: .' '
10149: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10150: ,'<a href="'.$helplink.'">','</a>')
10151: .'</p><br />';
1.627 raeburn 10152: }
1.576 raeburn 10153: }
10154: }
10155:
1.556 raeburn 10156: $newuserscript = <<"ENDSCRIPT";
10157:
1.570 raeburn 10158: function setSearch(createnew,callingForm) {
1.556 raeburn 10159: if (createnew == 1) {
1.570 raeburn 10160: for (var i=0; i<callingForm.srchby.length; i++) {
10161: if (callingForm.srchby.options[i].value == 'uname') {
10162: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10163: }
10164: }
1.570 raeburn 10165: for (var i=0; i<callingForm.srchin.length; i++) {
10166: if ( callingForm.srchin.options[i].value == 'dom') {
10167: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10168: }
10169: }
1.570 raeburn 10170: for (var i=0; i<callingForm.srchtype.length; i++) {
10171: if (callingForm.srchtype.options[i].value == 'exact') {
10172: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10173: }
10174: }
1.570 raeburn 10175: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10176: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10177: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10178: }
10179: }
10180: }
10181: }
10182: ENDSCRIPT
1.558 albertel 10183:
1.556 raeburn 10184: }
10185:
1.555 raeburn 10186: my $output = <<"END_BLOCK";
1.556 raeburn 10187: <script type="text/javascript">
1.824 bisitz 10188: // <![CDATA[
1.570 raeburn 10189: function validateEntry(callingForm) {
1.558 albertel 10190:
1.556 raeburn 10191: var checkok = 1;
1.558 albertel 10192: var srchin;
1.570 raeburn 10193: for (var i=0; i<callingForm.srchin.length; i++) {
10194: if ( callingForm.srchin[i].checked ) {
10195: srchin = callingForm.srchin[i].value;
1.558 albertel 10196: }
10197: }
10198:
1.570 raeburn 10199: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10200: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10201: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10202: var srchterm = callingForm.srchterm.value;
10203: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10204: var msg = "";
10205:
10206: if (srchterm == "") {
10207: checkok = 0;
1.1075.2.98 raeburn 10208: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10209: }
10210:
1.569 raeburn 10211: if (srchtype== 'begins') {
10212: if (srchterm.length < 2) {
10213: checkok = 0;
1.1075.2.98 raeburn 10214: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10215: }
10216: }
10217:
1.556 raeburn 10218: if (srchtype== 'contains') {
10219: if (srchterm.length < 3) {
10220: checkok = 0;
1.1075.2.98 raeburn 10221: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10222: }
10223: }
10224: if (srchin == 'instd') {
10225: if (srchdomain == '') {
10226: checkok = 0;
1.1075.2.98 raeburn 10227: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10228: }
10229: }
10230: if (srchin == 'dom') {
10231: if (srchdomain == '') {
10232: checkok = 0;
1.1075.2.98 raeburn 10233: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10234: }
10235: }
10236: if (srchby == 'lastfirst') {
10237: if (srchterm.indexOf(",") == -1) {
10238: checkok = 0;
1.1075.2.98 raeburn 10239: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10240: }
10241: if (srchterm.indexOf(",") == srchterm.length -1) {
10242: checkok = 0;
1.1075.2.98 raeburn 10243: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10244: }
10245: }
10246: if (checkok == 0) {
1.1075.2.98 raeburn 10247: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10248: return;
10249: }
10250: if (checkok == 1) {
1.570 raeburn 10251: callingForm.submit();
1.556 raeburn 10252: }
10253: }
10254:
10255: $newuserscript
10256:
1.824 bisitz 10257: // ]]>
1.556 raeburn 10258: </script>
1.558 albertel 10259:
10260: $new_user_create
10261:
1.555 raeburn 10262: END_BLOCK
1.558 albertel 10263:
1.876 raeburn 10264: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 10265: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10266: $domform.
10267: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 10268: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10269: $srchbysel.
10270: $srchtypesel.
10271: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10272: $srchinsel.
10273: &Apache::lonhtmlcommon::row_closure(1).
10274: &Apache::lonhtmlcommon::end_pick_box().
10275: '<br />';
1.1075.2.114 raeburn 10276: return ($output,1);
1.555 raeburn 10277: }
10278:
1.612 raeburn 10279: sub user_rule_check {
1.615 raeburn 10280: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10281: my ($response,%inst_response);
1.612 raeburn 10282: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10283: if (keys(%{$usershash}) > 1) {
10284: my (%by_username,%by_id,%userdoms);
10285: my $checkid;
1.612 raeburn 10286: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10287: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10288: $checkid = 1;
10289: }
10290: }
10291: foreach my $user (keys(%{$usershash})) {
10292: my ($uname,$udom) = split(/:/,$user);
10293: if ($checkid) {
10294: if (ref($usershash->{$user}) eq 'HASH') {
10295: if ($usershash->{$user}->{'id'} ne '') {
10296: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10297: $userdoms{$udom} = 1;
10298: if (ref($inst_results) eq 'HASH') {
10299: $inst_results->{$uname.':'.$udom} = {};
10300: }
10301: }
10302: }
10303: } else {
10304: $by_username{$udom}{$uname} = 1;
10305: $userdoms{$udom} = 1;
10306: if (ref($inst_results) eq 'HASH') {
10307: $inst_results->{$uname.':'.$udom} = {};
10308: }
10309: }
10310: }
10311: foreach my $udom (keys(%userdoms)) {
10312: if (!$got_rules->{$udom}) {
10313: my %domconfig = &Apache::lonnet::get_dom('configuration',
10314: ['usercreation'],$udom);
10315: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10316: foreach my $item ('username','id') {
10317: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10318: $$curr_rules{$udom}{$item} =
10319: $domconfig{'usercreation'}{$item.'_rule'};
10320: }
10321: }
10322: }
10323: $got_rules->{$udom} = 1;
10324: }
10325: }
10326: if ($checkid) {
10327: foreach my $udom (keys(%by_id)) {
10328: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10329: if ($outcome eq 'ok') {
10330: foreach my $id (keys(%{$by_id{$udom}})) {
10331: my $uname = $by_id{$udom}{$id};
10332: $inst_response{$uname.':'.$udom} = $outcome;
10333: }
10334: if (ref($results) eq 'HASH') {
10335: foreach my $uname (keys(%{$results})) {
10336: if (exists($inst_response{$uname.':'.$udom})) {
10337: $inst_response{$uname.':'.$udom} = $outcome;
10338: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10339: }
10340: }
10341: }
10342: }
1.612 raeburn 10343: }
1.615 raeburn 10344: } else {
1.1075.2.99 raeburn 10345: foreach my $udom (keys(%by_username)) {
10346: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10347: if ($outcome eq 'ok') {
10348: foreach my $uname (keys(%{$by_username{$udom}})) {
10349: $inst_response{$uname.':'.$udom} = $outcome;
10350: }
10351: if (ref($results) eq 'HASH') {
10352: foreach my $uname (keys(%{$results})) {
10353: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10354: }
10355: }
10356: }
10357: }
1.612 raeburn 10358: }
1.1075.2.99 raeburn 10359: } elsif (keys(%{$usershash}) == 1) {
10360: my $user = (keys(%{$usershash}))[0];
10361: my ($uname,$udom) = split(/:/,$user);
10362: if (($udom ne '') && ($uname ne '')) {
10363: if (ref($usershash->{$user}) eq 'HASH') {
10364: if (ref($checks) eq 'HASH') {
10365: if (defined($checks->{'username'})) {
10366: ($inst_response{$user},%{$inst_results->{$user}}) =
10367: &Apache::lonnet::get_instuser($udom,$uname);
10368: } elsif (defined($checks->{'id'})) {
10369: if ($usershash->{$user}->{'id'} ne '') {
10370: ($inst_response{$user},%{$inst_results->{$user}}) =
10371: &Apache::lonnet::get_instuser($udom,undef,
10372: $usershash->{$user}->{'id'});
10373: } else {
10374: ($inst_response{$user},%{$inst_results->{$user}}) =
10375: &Apache::lonnet::get_instuser($udom,$uname);
10376: }
10377: }
10378: } else {
10379: ($inst_response{$user},%{$inst_results->{$user}}) =
10380: &Apache::lonnet::get_instuser($udom,$uname);
10381: return;
10382: }
10383: if (!$got_rules->{$udom}) {
10384: my %domconfig = &Apache::lonnet::get_dom('configuration',
10385: ['usercreation'],$udom);
10386: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10387: foreach my $item ('username','id') {
10388: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10389: $$curr_rules{$udom}{$item} =
10390: $domconfig{'usercreation'}{$item.'_rule'};
10391: }
10392: }
1.585 raeburn 10393: }
1.1075.2.99 raeburn 10394: $got_rules->{$udom} = 1;
1.585 raeburn 10395: }
10396: }
1.1075.2.99 raeburn 10397: } else {
10398: return;
10399: }
10400: } else {
10401: return;
10402: }
10403: foreach my $user (keys(%{$usershash})) {
10404: my ($uname,$udom) = split(/:/,$user);
10405: next if (($udom eq '') || ($uname eq ''));
10406: my $id;
10407: if (ref($inst_results) eq 'HASH') {
10408: if (ref($inst_results->{$user}) eq 'HASH') {
10409: $id = $inst_results->{$user}->{'id'};
10410: }
10411: }
10412: if ($id eq '') {
10413: if (ref($usershash->{$user})) {
10414: $id = $usershash->{$user}->{'id'};
10415: }
1.585 raeburn 10416: }
1.612 raeburn 10417: foreach my $item (keys(%{$checks})) {
10418: if (ref($$curr_rules{$udom}) eq 'HASH') {
10419: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10420: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10421: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10422: $$curr_rules{$udom}{$item});
1.612 raeburn 10423: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10424: if ($rule_check{$rule}) {
10425: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10426: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10427: if (ref($inst_results) eq 'HASH') {
10428: if (ref($inst_results->{$user}) eq 'HASH') {
10429: if (keys(%{$inst_results->{$user}}) == 0) {
10430: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10431: } elsif ($item eq 'id') {
10432: if ($inst_results->{$user}->{'id'} eq '') {
10433: $$alerts{$item}{$udom}{$uname} = 1;
10434: }
1.615 raeburn 10435: }
1.612 raeburn 10436: }
10437: }
1.615 raeburn 10438: }
10439: last;
1.585 raeburn 10440: }
10441: }
10442: }
10443: }
10444: }
10445: }
10446: }
10447: }
1.612 raeburn 10448: return;
10449: }
10450:
10451: sub user_rule_formats {
10452: my ($domain,$domdesc,$curr_rules,$check) = @_;
10453: my %text = (
10454: 'username' => 'Usernames',
10455: 'id' => 'IDs',
10456: );
10457: my $output;
10458: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10459: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10460: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10461: $output = '<br />'.
10462: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10463: '<span class="LC_cusr_emph">','</span>',$domdesc).
10464: ' <ul>';
1.612 raeburn 10465: foreach my $rule (@{$ruleorder}) {
10466: if (ref($curr_rules) eq 'ARRAY') {
10467: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10468: if (ref($rules->{$rule}) eq 'HASH') {
10469: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10470: $rules->{$rule}{'desc'}.'</li>';
10471: }
10472: }
10473: }
10474: }
10475: $output .= '</ul>';
10476: }
10477: }
10478: return $output;
10479: }
10480:
10481: sub instrule_disallow_msg {
1.615 raeburn 10482: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10483: my $response;
10484: my %text = (
10485: item => 'username',
10486: items => 'usernames',
10487: match => 'matches',
10488: do => 'does',
10489: action => 'a username',
10490: one => 'one',
10491: );
10492: if ($count > 1) {
10493: $text{'item'} = 'usernames';
10494: $text{'match'} ='match';
10495: $text{'do'} = 'do';
10496: $text{'action'} = 'usernames',
10497: $text{'one'} = 'ones';
10498: }
10499: if ($checkitem eq 'id') {
10500: $text{'items'} = 'IDs';
10501: $text{'item'} = 'ID';
10502: $text{'action'} = 'an ID';
1.615 raeburn 10503: if ($count > 1) {
10504: $text{'item'} = 'IDs';
10505: $text{'action'} = 'IDs';
10506: }
1.612 raeburn 10507: }
1.674 bisitz 10508: $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 10509: if ($mode eq 'upload') {
10510: if ($checkitem eq 'username') {
10511: $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'}.");
10512: } elsif ($checkitem eq 'id') {
1.674 bisitz 10513: $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 10514: }
1.669 raeburn 10515: } elsif ($mode eq 'selfcreate') {
10516: if ($checkitem eq 'id') {
10517: $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.");
10518: }
1.615 raeburn 10519: } else {
10520: if ($checkitem eq 'username') {
10521: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10522: } elsif ($checkitem eq 'id') {
10523: $response .= &mt("You must either choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or leave the ID field blank.");
10524: }
1.612 raeburn 10525: }
10526: return $response;
1.585 raeburn 10527: }
10528:
1.624 raeburn 10529: sub personal_data_fieldtitles {
10530: my %fieldtitles = &Apache::lonlocal::texthash (
10531: id => 'Student/Employee ID',
10532: permanentemail => 'E-mail address',
10533: lastname => 'Last Name',
10534: firstname => 'First Name',
10535: middlename => 'Middle Name',
10536: generation => 'Generation',
10537: gen => 'Generation',
1.765 raeburn 10538: inststatus => 'Affiliation',
1.624 raeburn 10539: );
10540: return %fieldtitles;
10541: }
10542:
1.642 raeburn 10543: sub sorted_inst_types {
10544: my ($dom) = @_;
1.1075.2.70 raeburn 10545: my ($usertypes,$order);
10546: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10547: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10548: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10549: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10550: } else {
10551: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10552: }
1.642 raeburn 10553: my $othertitle = &mt('All users');
10554: if ($env{'request.course.id'}) {
1.668 raeburn 10555: $othertitle = &mt('Any users');
1.642 raeburn 10556: }
10557: my @types;
10558: if (ref($order) eq 'ARRAY') {
10559: @types = @{$order};
10560: }
10561: if (@types == 0) {
10562: if (ref($usertypes) eq 'HASH') {
10563: @types = sort(keys(%{$usertypes}));
10564: }
10565: }
10566: if (keys(%{$usertypes}) > 0) {
10567: $othertitle = &mt('Other users');
10568: }
10569: return ($othertitle,$usertypes,\@types);
10570: }
10571:
1.645 raeburn 10572: sub get_institutional_codes {
1.1075.2.157 raeburn 10573: my ($cdom,$crs,$settings,$allcourses,$LC_code) = @_;
1.645 raeburn 10574: # Get complete list of course sections to update
10575: my @currsections = ();
10576: my @currxlists = ();
1.1075.2.157 raeburn 10577: my (%unclutteredsec,%unclutteredlcsec);
1.645 raeburn 10578: my $coursecode = $$settings{'internal.coursecode'};
1.1075.2.157 raeburn 10579: my $crskey = $crs.':'.$coursecode;
10580: @{$unclutteredsec{$crskey}} = ();
10581: @{$unclutteredlcsec{$crskey}} = ();
1.645 raeburn 10582:
10583: if ($$settings{'internal.sectionnums'} ne '') {
10584: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10585: }
10586:
10587: if ($$settings{'internal.crosslistings'} ne '') {
10588: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10589: }
10590:
10591: if (@currxlists > 0) {
1.1075.2.157 raeburn 10592: foreach my $xl (@currxlists) {
10593: if ($xl =~ /^([^:]+):(\w*)$/) {
1.645 raeburn 10594: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10595: push(@{$allcourses},$1);
1.645 raeburn 10596: $$LC_code{$1} = $2;
10597: }
10598: }
10599: }
10600: }
1.1075.2.157 raeburn 10601:
1.645 raeburn 10602: if (@currsections > 0) {
1.1075.2.157 raeburn 10603: foreach my $sec (@currsections) {
10604: if ($sec =~ m/^(\w+):(\w*)$/ ) {
10605: my $instsec = $1;
1.645 raeburn 10606: my $lc_sec = $2;
1.1075.2.157 raeburn 10607: unless (grep/^\Q$instsec\E$/,@{$unclutteredsec{$crskey}}) {
10608: push(@{$unclutteredsec{$crskey}},$instsec);
10609: push(@{$unclutteredlcsec{$crskey}},$lc_sec);
10610: }
10611: }
10612: }
10613: }
10614:
10615: if (@{$unclutteredsec{$crskey}} > 0) {
10616: my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',\%unclutteredsec);
10617: if ((ref($formattedsec{$crskey}) eq 'ARRAY') && (ref($unclutteredlcsec{$crskey}) eq 'ARRAY')) {
10618: for (my $i=0; $i<@{$formattedsec{$crskey}}; $i++) {
10619: my $sec = $coursecode.$formattedsec{$crskey}[$i];
10620: unless (grep/^\Q$sec\E$/,@{$allcourses}) {
1.1075.2.119 raeburn 10621: push(@{$allcourses},$sec);
1.1075.2.157 raeburn 10622: $$LC_code{$sec} = $unclutteredlcsec{$crskey}[$i];
1.645 raeburn 10623: }
10624: }
10625: }
10626: }
10627: return;
10628: }
10629:
1.971 raeburn 10630: sub get_standard_codeitems {
10631: return ('Year','Semester','Department','Number','Section');
10632: }
10633:
1.112 bowersj2 10634: =pod
10635:
1.780 raeburn 10636: =head1 Slot Helpers
10637:
10638: =over 4
10639:
10640: =item * sorted_slots()
10641:
1.1040 raeburn 10642: Sorts an array of slot names in order of an optional sort key,
10643: default sort is by slot start time (earliest first).
1.780 raeburn 10644:
10645: Inputs:
10646:
10647: =over 4
10648:
10649: slotsarr - Reference to array of unsorted slot names.
10650:
10651: slots - Reference to hash of hash, where outer hash keys are slot names.
10652:
1.1040 raeburn 10653: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10654:
1.549 albertel 10655: =back
10656:
1.780 raeburn 10657: Returns:
10658:
10659: =over 4
10660:
1.1040 raeburn 10661: sorted - An array of slot names sorted by a specified sort key
10662: (default sort key is start time of the slot).
1.780 raeburn 10663:
10664: =back
10665:
10666: =cut
10667:
10668:
10669: sub sorted_slots {
1.1040 raeburn 10670: my ($slotsarr,$slots,$sortkey) = @_;
10671: if ($sortkey eq '') {
10672: $sortkey = 'starttime';
10673: }
1.780 raeburn 10674: my @sorted;
10675: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10676: @sorted =
10677: sort {
10678: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10679: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10680: }
10681: if (ref($slots->{$a})) { return -1;}
10682: if (ref($slots->{$b})) { return 1;}
10683: return 0;
10684: } @{$slotsarr};
10685: }
10686: return @sorted;
10687: }
10688:
1.1040 raeburn 10689: =pod
10690:
10691: =item * get_future_slots()
10692:
10693: Inputs:
10694:
10695: =over 4
10696:
10697: cnum - course number
10698:
10699: cdom - course domain
10700:
10701: now - current UNIX time
10702:
10703: symb - optional symb
10704:
10705: =back
10706:
10707: Returns:
10708:
10709: =over 4
10710:
10711: sorted_reservable - ref to array of student_schedulable slots currently
10712: reservable, ordered by end date of reservation period.
10713:
10714: reservable_now - ref to hash of student_schedulable slots currently
10715: reservable.
10716:
10717: Keys in inner hash are:
10718: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10719: (b) endreserve: end date of reservation period.
10720: (c) uniqueperiod: start,end dates when slot is to be uniquely
10721: selected.
1.1040 raeburn 10722:
10723: sorted_future - ref to array of student_schedulable slots reservable in
10724: the future, ordered by start date of reservation period.
10725:
10726: future_reservable - ref to hash of student_schedulable slots reservable
10727: in the future.
10728:
10729: Keys in inner hash are:
10730: (a) symb: either blank or symb to which slot use is restricted.
10731: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10732: (c) uniqueperiod: start,end dates when slot is to be uniquely
10733: selected.
1.1040 raeburn 10734:
10735: =back
10736:
10737: =cut
10738:
10739: sub get_future_slots {
10740: my ($cnum,$cdom,$now,$symb) = @_;
10741: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10742: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10743: foreach my $slot (keys(%slots)) {
10744: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10745: if ($symb) {
10746: next if (($slots{$slot}->{'symb'} ne '') &&
10747: ($slots{$slot}->{'symb'} ne $symb));
10748: }
10749: if (($slots{$slot}->{'starttime'} > $now) &&
10750: ($slots{$slot}->{'endtime'} > $now)) {
10751: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10752: my $userallowed = 0;
10753: if ($slots{$slot}->{'allowedsections'}) {
10754: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10755: if (!defined($env{'request.role.sec'})
10756: && grep(/^No section assigned$/,@allowed_sec)) {
10757: $userallowed=1;
10758: } else {
10759: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10760: $userallowed=1;
10761: }
10762: }
10763: unless ($userallowed) {
10764: if (defined($env{'request.course.groups'})) {
10765: my @groups = split(/:/,$env{'request.course.groups'});
10766: foreach my $group (@groups) {
10767: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10768: $userallowed=1;
10769: last;
10770: }
10771: }
10772: }
10773: }
10774: }
10775: if ($slots{$slot}->{'allowedusers'}) {
10776: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10777: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10778: if (grep(/^\Q$user\E$/,@allowed_users)) {
10779: $userallowed = 1;
10780: }
10781: }
10782: next unless($userallowed);
10783: }
10784: my $startreserve = $slots{$slot}->{'startreserve'};
10785: my $endreserve = $slots{$slot}->{'endreserve'};
10786: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10787: my $uniqueperiod;
10788: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10789: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10790: }
1.1040 raeburn 10791: if (($startreserve < $now) &&
10792: (!$endreserve || $endreserve > $now)) {
10793: my $lastres = $endreserve;
10794: if (!$lastres) {
10795: $lastres = $slots{$slot}->{'starttime'};
10796: }
10797: $reservable_now{$slot} = {
10798: symb => $symb,
1.1075.2.104 raeburn 10799: endreserve => $lastres,
10800: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10801: };
10802: } elsif (($startreserve > $now) &&
10803: (!$endreserve || $endreserve > $startreserve)) {
10804: $future_reservable{$slot} = {
10805: symb => $symb,
1.1075.2.104 raeburn 10806: startreserve => $startreserve,
10807: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10808: };
10809: }
10810: }
10811: }
10812: my @unsorted_reservable = keys(%reservable_now);
10813: if (@unsorted_reservable > 0) {
10814: @sorted_reservable =
10815: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10816: }
10817: my @unsorted_future = keys(%future_reservable);
10818: if (@unsorted_future > 0) {
10819: @sorted_future =
10820: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10821: }
10822: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10823: }
1.780 raeburn 10824:
10825: =pod
10826:
1.1057 foxr 10827: =back
10828:
1.549 albertel 10829: =head1 HTTP Helpers
10830:
10831: =over 4
10832:
1.648 raeburn 10833: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10834:
1.258 albertel 10835: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10836: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10837: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10838:
10839: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10840: $possible_names is an ref to an array of form element names. As an example:
10841: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10842: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10843:
10844: =cut
1.1 albertel 10845:
1.6 albertel 10846: sub get_unprocessed_cgi {
1.25 albertel 10847: my ($query,$possible_names)= @_;
1.26 matthew 10848: # $Apache::lonxml::debug=1;
1.356 albertel 10849: foreach my $pair (split(/&/,$query)) {
10850: my ($name, $value) = split(/=/,$pair);
1.369 www 10851: $name = &unescape($name);
1.25 albertel 10852: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10853: $value =~ tr/+/ /;
10854: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10855: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10856: }
1.16 harris41 10857: }
1.6 albertel 10858: }
10859:
1.112 bowersj2 10860: =pod
10861:
1.648 raeburn 10862: =item * &cacheheader()
1.112 bowersj2 10863:
10864: returns cache-controlling header code
10865:
10866: =cut
10867:
1.7 albertel 10868: sub cacheheader {
1.258 albertel 10869: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10870: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10871: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10872: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10873: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10874: return $output;
1.7 albertel 10875: }
10876:
1.112 bowersj2 10877: =pod
10878:
1.648 raeburn 10879: =item * &no_cache($r)
1.112 bowersj2 10880:
10881: specifies header code to not have cache
10882:
10883: =cut
10884:
1.9 albertel 10885: sub no_cache {
1.216 albertel 10886: my ($r) = @_;
10887: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10888: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10889: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10890: $r->no_cache(1);
10891: $r->header_out("Expires" => $date);
10892: $r->header_out("Pragma" => "no-cache");
1.123 www 10893: }
10894:
10895: sub content_type {
1.181 albertel 10896: my ($r,$type,$charset) = @_;
1.299 foxr 10897: if ($r) {
10898: # Note that printout.pl calls this with undef for $r.
10899: &no_cache($r);
10900: }
1.258 albertel 10901: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10902: unless ($charset) {
10903: $charset=&Apache::lonlocal::current_encoding;
10904: }
10905: if ($charset) { $type.='; charset='.$charset; }
10906: if ($r) {
10907: $r->content_type($type);
10908: } else {
10909: print("Content-type: $type\n\n");
10910: }
1.9 albertel 10911: }
1.25 albertel 10912:
1.112 bowersj2 10913: =pod
10914:
1.648 raeburn 10915: =item * &add_to_env($name,$value)
1.112 bowersj2 10916:
1.258 albertel 10917: adds $name to the %env hash with value
1.112 bowersj2 10918: $value, if $name already exists, the entry is converted to an array
10919: reference and $value is added to the array.
10920:
10921: =cut
10922:
1.25 albertel 10923: sub add_to_env {
10924: my ($name,$value)=@_;
1.258 albertel 10925: if (defined($env{$name})) {
10926: if (ref($env{$name})) {
1.25 albertel 10927: #already have multiple values
1.258 albertel 10928: push(@{ $env{$name} },$value);
1.25 albertel 10929: } else {
10930: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10931: my $first=$env{$name};
10932: undef($env{$name});
10933: push(@{ $env{$name} },$first,$value);
1.25 albertel 10934: }
10935: } else {
1.258 albertel 10936: $env{$name}=$value;
1.25 albertel 10937: }
1.31 albertel 10938: }
1.149 albertel 10939:
10940: =pod
10941:
1.648 raeburn 10942: =item * &get_env_multiple($name)
1.149 albertel 10943:
1.258 albertel 10944: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10945: values may be defined and end up as an array ref.
10946:
10947: returns an array of values
10948:
10949: =cut
10950:
10951: sub get_env_multiple {
10952: my ($name) = @_;
10953: my @values;
1.258 albertel 10954: if (defined($env{$name})) {
1.149 albertel 10955: # exists is it an array
1.258 albertel 10956: if (ref($env{$name})) {
10957: @values=@{ $env{$name} };
1.149 albertel 10958: } else {
1.258 albertel 10959: $values[0]=$env{$name};
1.149 albertel 10960: }
10961: }
10962: return(@values);
10963: }
10964:
1.660 raeburn 10965: sub ask_for_embedded_content {
10966: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10967: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10968: %currsubfile,%unused,$rem);
1.1071 raeburn 10969: my $counter = 0;
10970: my $numnew = 0;
1.987 raeburn 10971: my $numremref = 0;
10972: my $numinvalid = 0;
10973: my $numpathchg = 0;
10974: my $numexisting = 0;
1.1071 raeburn 10975: my $numunused = 0;
10976: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10977: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10978: my $heading = &mt('Upload embedded files');
10979: my $buttontext = &mt('Upload');
10980:
1.1075.2.11 raeburn 10981: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10982: if ($actionurl eq '/adm/dependencies') {
10983: $navmap = Apache::lonnavmaps::navmap->new();
10984: }
10985: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10986: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10987: }
1.1075.2.35 raeburn 10988: if (($actionurl eq '/adm/portfolio') ||
10989: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10990: my $current_path='/';
10991: if ($env{'form.currentpath'}) {
10992: $current_path = $env{'form.currentpath'};
10993: }
10994: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10995: $udom = $cdom;
10996: $uname = $cnum;
1.984 raeburn 10997: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10998: } else {
10999: $udom = $env{'user.domain'};
11000: $uname = $env{'user.name'};
11001: $url = '/userfiles/portfolio';
11002: }
1.987 raeburn 11003: $toplevel = $url.'/';
1.984 raeburn 11004: $url .= $current_path;
11005: $getpropath = 1;
1.987 raeburn 11006: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11007: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11008: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11009: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11010: $toplevel = $url;
1.984 raeburn 11011: if ($rest ne '') {
1.987 raeburn 11012: $url .= $rest;
11013: }
11014: } elsif ($actionurl eq '/adm/coursedocs') {
11015: if (ref($args) eq 'HASH') {
1.1071 raeburn 11016: $url = $args->{'docs_url'};
11017: $toplevel = $url;
1.1075.2.11 raeburn 11018: if ($args->{'context'} eq 'paste') {
11019: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11020: ($path) =
11021: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11022: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11023: $fileloc =~ s{^/}{};
11024: }
1.1071 raeburn 11025: }
11026: } elsif ($actionurl eq '/adm/dependencies') {
11027: if ($env{'request.course.id'} ne '') {
11028: if (ref($args) eq 'HASH') {
11029: $url = $args->{'docs_url'};
11030: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 11031: $toplevel = $url;
11032: unless ($toplevel =~ m{^/}) {
11033: $toplevel = "/$url";
11034: }
1.1075.2.11 raeburn 11035: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 11036: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11037: $path = $1;
11038: } else {
11039: ($path) =
11040: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11041: }
1.1075.2.79 raeburn 11042: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11043: $fileloc = $toplevel;
11044: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11045: my ($udom,$uname,$fname) =
11046: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11047: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11048: } else {
11049: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11050: }
1.1071 raeburn 11051: $fileloc =~ s{^/}{};
11052: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11053: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11054: }
1.987 raeburn 11055: }
1.1075.2.35 raeburn 11056: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11057: $udom = $cdom;
11058: $uname = $cnum;
11059: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11060: $toplevel = $url;
11061: $path = $url;
11062: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11063: $fileloc =~ s{^/}{};
11064: }
11065: foreach my $file (keys(%{$allfiles})) {
11066: my $embed_file;
11067: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11068: $embed_file = $1;
11069: } else {
11070: $embed_file = $file;
11071: }
1.1075.2.55 raeburn 11072: my ($absolutepath,$cleaned_file);
11073: if ($embed_file =~ m{^\w+://}) {
11074: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 11075: $newfiles{$cleaned_file} = 1;
11076: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11077: } else {
1.1075.2.55 raeburn 11078: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11079: if ($embed_file =~ m{^/}) {
11080: $absolutepath = $embed_file;
11081: }
1.1075.2.47 raeburn 11082: if ($cleaned_file =~ m{/}) {
11083: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11084: $path = &check_for_traversal($path,$url,$toplevel);
11085: my $item = $fname;
11086: if ($path ne '') {
11087: $item = $path.'/'.$fname;
11088: $subdependencies{$path}{$fname} = 1;
11089: } else {
11090: $dependencies{$item} = 1;
11091: }
11092: if ($absolutepath) {
11093: $mapping{$item} = $absolutepath;
11094: } else {
11095: $mapping{$item} = $embed_file;
11096: }
11097: } else {
11098: $dependencies{$embed_file} = 1;
11099: if ($absolutepath) {
1.1075.2.47 raeburn 11100: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11101: } else {
1.1075.2.47 raeburn 11102: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11103: }
11104: }
1.984 raeburn 11105: }
11106: }
1.1071 raeburn 11107: my $dirptr = 16384;
1.984 raeburn 11108: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11109: $currsubfile{$path} = {};
1.1075.2.35 raeburn 11110: if (($actionurl eq '/adm/portfolio') ||
11111: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11112: my ($sublistref,$listerror) =
11113: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11114: if (ref($sublistref) eq 'ARRAY') {
11115: foreach my $line (@{$sublistref}) {
11116: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11117: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11118: }
1.984 raeburn 11119: }
1.987 raeburn 11120: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11121: if (opendir(my $dir,$url.'/'.$path)) {
11122: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11123: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11124: }
1.1075.2.11 raeburn 11125: } elsif (($actionurl eq '/adm/dependencies') ||
11126: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11127: ($args->{'context'} eq 'paste')) ||
11128: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11129: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 11130: my $dir;
11131: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11132: $dir = $fileloc;
11133: } else {
11134: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11135: }
1.1071 raeburn 11136: if ($dir ne '') {
11137: my ($sublistref,$listerror) =
11138: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11139: if (ref($sublistref) eq 'ARRAY') {
11140: foreach my $line (@{$sublistref}) {
11141: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11142: undef,$mtime)=split(/\&/,$line,12);
11143: unless (($testdir&$dirptr) ||
11144: ($file_name =~ /^\.\.?$/)) {
11145: $currsubfile{$path}{$file_name} = [$size,$mtime];
11146: }
11147: }
11148: }
11149: }
1.984 raeburn 11150: }
11151: }
11152: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11153: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11154: my $item = $path.'/'.$file;
11155: unless ($mapping{$item} eq $item) {
11156: $pathchanges{$item} = 1;
11157: }
11158: $existing{$item} = 1;
11159: $numexisting ++;
11160: } else {
11161: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11162: }
11163: }
1.1071 raeburn 11164: if ($actionurl eq '/adm/dependencies') {
11165: foreach my $path (keys(%currsubfile)) {
11166: if (ref($currsubfile{$path}) eq 'HASH') {
11167: foreach my $file (keys(%{$currsubfile{$path}})) {
11168: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 11169: next if (($rem ne '') &&
11170: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11171: (ref($navmap) &&
11172: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11173: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11174: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11175: $unused{$path.'/'.$file} = 1;
11176: }
11177: }
11178: }
11179: }
11180: }
1.984 raeburn 11181: }
1.987 raeburn 11182: my %currfile;
1.1075.2.35 raeburn 11183: if (($actionurl eq '/adm/portfolio') ||
11184: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11185: my ($dirlistref,$listerror) =
11186: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11187: if (ref($dirlistref) eq 'ARRAY') {
11188: foreach my $line (@{$dirlistref}) {
11189: my ($file_name,$rest) = split(/\&/,$line,2);
11190: $currfile{$file_name} = 1;
11191: }
1.984 raeburn 11192: }
1.987 raeburn 11193: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11194: if (opendir(my $dir,$url)) {
1.987 raeburn 11195: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11196: map {$currfile{$_} = 1;} @dir_list;
11197: }
1.1075.2.11 raeburn 11198: } elsif (($actionurl eq '/adm/dependencies') ||
11199: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 11200: ($args->{'context'} eq 'paste')) ||
11201: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11202: if ($env{'request.course.id'} ne '') {
11203: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11204: if ($dir ne '') {
11205: my ($dirlistref,$listerror) =
11206: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11207: if (ref($dirlistref) eq 'ARRAY') {
11208: foreach my $line (@{$dirlistref}) {
11209: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11210: $size,undef,$mtime)=split(/\&/,$line,12);
11211: unless (($testdir&$dirptr) ||
11212: ($file_name =~ /^\.\.?$/)) {
11213: $currfile{$file_name} = [$size,$mtime];
11214: }
11215: }
11216: }
11217: }
11218: }
1.984 raeburn 11219: }
11220: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11221: if (exists($currfile{$file})) {
1.987 raeburn 11222: unless ($mapping{$file} eq $file) {
11223: $pathchanges{$file} = 1;
11224: }
11225: $existing{$file} = 1;
11226: $numexisting ++;
11227: } else {
1.984 raeburn 11228: $newfiles{$file} = 1;
11229: }
11230: }
1.1071 raeburn 11231: foreach my $file (keys(%currfile)) {
11232: unless (($file eq $filename) ||
11233: ($file eq $filename.'.bak') ||
11234: ($dependencies{$file})) {
1.1075.2.11 raeburn 11235: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 11236: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11237: next if (($rem ne '') &&
11238: (($env{"httpref.$rem".$file} ne '') ||
11239: (ref($navmap) &&
11240: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11241: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11242: ($navmap->getResourceByUrl($rem.$1)))))));
11243: }
1.1075.2.11 raeburn 11244: }
1.1071 raeburn 11245: $unused{$file} = 1;
11246: }
11247: }
1.1075.2.11 raeburn 11248: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11249: ($args->{'context'} eq 'paste')) {
11250: $counter = scalar(keys(%existing));
11251: $numpathchg = scalar(keys(%pathchanges));
11252: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 11253: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11254: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11255: $counter = scalar(keys(%existing));
11256: $numpathchg = scalar(keys(%pathchanges));
11257: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 11258: }
1.984 raeburn 11259: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11260: if ($actionurl eq '/adm/dependencies') {
11261: next if ($embed_file =~ m{^\w+://});
11262: }
1.660 raeburn 11263: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11264: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11265: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11266: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 11267: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11268: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11269: }
1.1075.2.35 raeburn 11270: $upload_output .= '</td>';
1.1071 raeburn 11271: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 11272: $upload_output.='<td align="right">'.
11273: '<span class="LC_info LC_fontsize_medium">'.
11274: &mt("URL points to web address").'</span>';
1.987 raeburn 11275: $numremref++;
1.660 raeburn 11276: } elsif ($args->{'error_on_invalid_names'}
11277: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 11278: $upload_output.='<td align="right"><span class="LC_warning">'.
11279: &mt('Invalid characters').'</span>';
1.987 raeburn 11280: $numinvalid++;
1.660 raeburn 11281: } else {
1.1075.2.35 raeburn 11282: $upload_output .= '<td>'.
11283: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11284: $embed_file,\%mapping,
1.1071 raeburn 11285: $allfiles,$codebase,'upload');
11286: $counter ++;
11287: $numnew ++;
1.987 raeburn 11288: }
11289: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11290: }
11291: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11292: if ($actionurl eq '/adm/dependencies') {
11293: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11294: $modify_output .= &start_data_table_row().
11295: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11296: '<img src="'.&icon($embed_file).'" border="0" />'.
11297: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11298: '<td>'.$size.'</td>'.
11299: '<td>'.$mtime.'</td>'.
11300: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11301: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11302: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11303: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11304: &embedded_file_element('upload_embedded',$counter,
11305: $embed_file,\%mapping,
11306: $allfiles,$codebase,'modify').
11307: '</div></td>'.
11308: &end_data_table_row()."\n";
11309: $counter ++;
11310: } else {
11311: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11312: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11313: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11314: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11315: &Apache::loncommon::end_data_table_row()."\n";
11316: }
11317: }
11318: my $delidx = $counter;
11319: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11320: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11321: $delete_output .= &start_data_table_row().
11322: '<td><img src="'.&icon($oldfile).'" />'.
11323: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11324: '<td>'.$size.'</td>'.
11325: '<td>'.$mtime.'</td>'.
11326: '<td><label><input type="checkbox" name="del_upload_dep" '.
11327: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11328: &embedded_file_element('upload_embedded',$delidx,
11329: $oldfile,\%mapping,$allfiles,
11330: $codebase,'delete').'</td>'.
11331: &end_data_table_row()."\n";
11332: $numunused ++;
11333: $delidx ++;
1.987 raeburn 11334: }
11335: if ($upload_output) {
11336: $upload_output = &start_data_table().
11337: $upload_output.
11338: &end_data_table()."\n";
11339: }
1.1071 raeburn 11340: if ($modify_output) {
11341: $modify_output = &start_data_table().
11342: &start_data_table_header_row().
11343: '<th>'.&mt('File').'</th>'.
11344: '<th>'.&mt('Size (KB)').'</th>'.
11345: '<th>'.&mt('Modified').'</th>'.
11346: '<th>'.&mt('Upload replacement?').'</th>'.
11347: &end_data_table_header_row().
11348: $modify_output.
11349: &end_data_table()."\n";
11350: }
11351: if ($delete_output) {
11352: $delete_output = &start_data_table().
11353: &start_data_table_header_row().
11354: '<th>'.&mt('File').'</th>'.
11355: '<th>'.&mt('Size (KB)').'</th>'.
11356: '<th>'.&mt('Modified').'</th>'.
11357: '<th>'.&mt('Delete?').'</th>'.
11358: &end_data_table_header_row().
11359: $delete_output.
11360: &end_data_table()."\n";
11361: }
1.987 raeburn 11362: my $applies = 0;
11363: if ($numremref) {
11364: $applies ++;
11365: }
11366: if ($numinvalid) {
11367: $applies ++;
11368: }
11369: if ($numexisting) {
11370: $applies ++;
11371: }
1.1071 raeburn 11372: if ($counter || $numunused) {
1.987 raeburn 11373: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11374: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11375: $state.'<h3>'.$heading.'</h3>';
11376: if ($actionurl eq '/adm/dependencies') {
11377: if ($numnew) {
11378: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11379: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11380: $upload_output.'<br />'."\n";
11381: }
11382: if ($numexisting) {
11383: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11384: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11385: $modify_output.'<br />'."\n";
11386: $buttontext = &mt('Save changes');
11387: }
11388: if ($numunused) {
11389: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11390: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11391: $delete_output.'<br />'."\n";
11392: $buttontext = &mt('Save changes');
11393: }
11394: } else {
11395: $output .= $upload_output.'<br />'."\n";
11396: }
11397: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11398: $counter.'" />'."\n";
11399: if ($actionurl eq '/adm/dependencies') {
11400: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11401: $numnew.'" />'."\n";
11402: } elsif ($actionurl eq '') {
1.987 raeburn 11403: $output .= '<input type="hidden" name="phase" value="three" />';
11404: }
11405: } elsif ($applies) {
11406: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11407: if ($applies > 1) {
11408: $output .=
1.1075.2.35 raeburn 11409: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11410: if ($numremref) {
11411: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11412: }
11413: if ($numinvalid) {
11414: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11415: }
11416: if ($numexisting) {
11417: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11418: }
11419: $output .= '</ul><br />';
11420: } elsif ($numremref) {
11421: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11422: } elsif ($numinvalid) {
11423: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11424: } elsif ($numexisting) {
11425: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11426: }
11427: $output .= $upload_output.'<br />';
11428: }
11429: my ($pathchange_output,$chgcount);
1.1071 raeburn 11430: $chgcount = $counter;
1.987 raeburn 11431: if (keys(%pathchanges) > 0) {
11432: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11433: if ($counter) {
1.987 raeburn 11434: $output .= &embedded_file_element('pathchange',$chgcount,
11435: $embed_file,\%mapping,
1.1071 raeburn 11436: $allfiles,$codebase,'change');
1.987 raeburn 11437: } else {
11438: $pathchange_output .=
11439: &start_data_table_row().
11440: '<td><input type ="checkbox" name="namechange" value="'.
11441: $chgcount.'" checked="checked" /></td>'.
11442: '<td>'.$mapping{$embed_file}.'</td>'.
11443: '<td>'.$embed_file.
11444: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11445: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11446: '</td>'.&end_data_table_row();
1.660 raeburn 11447: }
1.987 raeburn 11448: $numpathchg ++;
11449: $chgcount ++;
1.660 raeburn 11450: }
11451: }
1.1075.2.35 raeburn 11452: if (($counter) || ($numunused)) {
1.987 raeburn 11453: if ($numpathchg) {
11454: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11455: $numpathchg.'" />'."\n";
11456: }
11457: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11458: ($actionurl eq '/adm/imsimport')) {
11459: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11460: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11461: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11462: } elsif ($actionurl eq '/adm/dependencies') {
11463: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11464: }
1.1075.2.35 raeburn 11465: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11466: } elsif ($numpathchg) {
11467: my %pathchange = ();
11468: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11469: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11470: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11471: }
1.987 raeburn 11472: }
1.1071 raeburn 11473: return ($output,$counter,$numpathchg);
1.987 raeburn 11474: }
11475:
1.1075.2.47 raeburn 11476: =pod
11477:
11478: =item * clean_path($name)
11479:
11480: Performs clean-up of directories, subdirectories and filename in an
11481: embedded object, referenced in an HTML file which is being uploaded
11482: to a course or portfolio, where
11483: "Upload embedded images/multimedia files if HTML file" checkbox was
11484: checked.
11485:
11486: Clean-up is similar to replacements in lonnet::clean_filename()
11487: except each / between sub-directory and next level is preserved.
11488:
11489: =cut
11490:
11491: sub clean_path {
11492: my ($embed_file) = @_;
11493: $embed_file =~s{^/+}{};
11494: my @contents;
11495: if ($embed_file =~ m{/}) {
11496: @contents = split(/\//,$embed_file);
11497: } else {
11498: @contents = ($embed_file);
11499: }
11500: my $lastidx = scalar(@contents)-1;
11501: for (my $i=0; $i<=$lastidx; $i++) {
11502: $contents[$i]=~s{\\}{/}g;
11503: $contents[$i]=~s/\s+/\_/g;
11504: $contents[$i]=~s{[^/\w\.\-]}{}g;
11505: if ($i == $lastidx) {
11506: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11507: }
11508: }
11509: if ($lastidx > 0) {
11510: return join('/',@contents);
11511: } else {
11512: return $contents[0];
11513: }
11514: }
11515:
1.987 raeburn 11516: sub embedded_file_element {
1.1071 raeburn 11517: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11518: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11519: (ref($codebase) eq 'HASH'));
11520: my $output;
1.1071 raeburn 11521: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11522: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11523: }
11524: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11525: &escape($embed_file).'" />';
11526: unless (($context eq 'upload_embedded') &&
11527: ($mapping->{$embed_file} eq $embed_file)) {
11528: $output .='
11529: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11530: }
11531: my $attrib;
11532: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11533: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11534: }
11535: $output .=
11536: "\n\t\t".
11537: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11538: $attrib.'" />';
11539: if (exists($codebase->{$mapping->{$embed_file}})) {
11540: $output .=
11541: "\n\t\t".
11542: '<input name="codebase_'.$num.'" type="hidden" value="'.
11543: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11544: }
1.987 raeburn 11545: return $output;
1.660 raeburn 11546: }
11547:
1.1071 raeburn 11548: sub get_dependency_details {
11549: my ($currfile,$currsubfile,$embed_file) = @_;
11550: my ($size,$mtime,$showsize,$showmtime);
11551: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11552: if ($embed_file =~ m{/}) {
11553: my ($path,$fname) = split(/\//,$embed_file);
11554: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11555: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11556: }
11557: } else {
11558: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11559: ($size,$mtime) = @{$currfile->{$embed_file}};
11560: }
11561: }
11562: $showsize = $size/1024.0;
11563: $showsize = sprintf("%.1f",$showsize);
11564: if ($mtime > 0) {
11565: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11566: }
11567: }
11568: return ($showsize,$showmtime);
11569: }
11570:
11571: sub ask_embedded_js {
11572: return <<"END";
11573: <script type="text/javascript"">
11574: // <![CDATA[
11575: function toggleBrowse(counter) {
11576: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11577: var fileid = document.getElementById('embedded_item_'+counter);
11578: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11579: if (chkboxid.checked == true) {
11580: uploaddivid.style.display='block';
11581: } else {
11582: uploaddivid.style.display='none';
11583: fileid.value = '';
11584: }
11585: }
11586: // ]]>
11587: </script>
11588:
11589: END
11590: }
11591:
1.661 raeburn 11592: sub upload_embedded {
11593: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11594: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11595: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11596: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11597: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11598: my $orig_uploaded_filename =
11599: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11600: foreach my $type ('orig','ref','attrib','codebase') {
11601: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11602: $env{'form.embedded_'.$type.'_'.$i} =
11603: &unescape($env{'form.embedded_'.$type.'_'.$i});
11604: }
11605: }
1.661 raeburn 11606: my ($path,$fname) =
11607: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11608: # no path, whole string is fname
11609: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11610: $fname = &Apache::lonnet::clean_filename($fname);
11611: # See if there is anything left
11612: next if ($fname eq '');
11613:
11614: # Check if file already exists as a file or directory.
11615: my ($state,$msg);
11616: if ($context eq 'portfolio') {
11617: my $port_path = $dirpath;
11618: if ($group ne '') {
11619: $port_path = "groups/$group/$port_path";
11620: }
1.987 raeburn 11621: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11622: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11623: $dir_root,$port_path,$disk_quota,
11624: $current_disk_usage,$uname,$udom);
11625: if ($state eq 'will_exceed_quota'
1.984 raeburn 11626: || $state eq 'file_locked') {
1.661 raeburn 11627: $output .= $msg;
11628: next;
11629: }
11630: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11631: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11632: if ($state eq 'exists') {
11633: $output .= $msg;
11634: next;
11635: }
11636: }
11637: # Check if extension is valid
11638: if (($fname =~ /\.(\w+)$/) &&
11639: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11640: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11641: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11642: next;
11643: } elsif (($fname =~ /\.(\w+)$/) &&
11644: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11645: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11646: next;
11647: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11648: $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 11649: next;
11650: }
11651: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11652: my $subdir = $path;
11653: $subdir =~ s{/+$}{};
1.661 raeburn 11654: if ($context eq 'portfolio') {
1.984 raeburn 11655: my $result;
11656: if ($state eq 'existingfile') {
11657: $result=
11658: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11659: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11660: } else {
1.984 raeburn 11661: $result=
11662: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11663: $dirpath.
1.1075.2.35 raeburn 11664: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11665: if ($result !~ m|^/uploaded/|) {
11666: $output .= '<span class="LC_error">'
11667: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11668: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11669: .'</span><br />';
11670: next;
11671: } else {
1.987 raeburn 11672: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11673: $path.$fname.'</span>').'<br />';
1.984 raeburn 11674: }
1.661 raeburn 11675: }
1.1075.2.35 raeburn 11676: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11677: my $extendedsubdir = $dirpath.'/'.$subdir;
11678: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11679: my $result =
1.1075.2.35 raeburn 11680: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11681: if ($result !~ m|^/uploaded/|) {
11682: $output .= '<span class="LC_error">'
11683: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11684: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11685: .'</span><br />';
11686: next;
11687: } else {
11688: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11689: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11690: if ($context eq 'syllabus') {
11691: &Apache::lonnet::make_public_indefinitely($result);
11692: }
1.987 raeburn 11693: }
1.661 raeburn 11694: } else {
11695: # Save the file
11696: my $target = $env{'form.embedded_item_'.$i};
11697: my $fullpath = $dir_root.$dirpath.'/'.$path;
11698: my $dest = $fullpath.$fname;
11699: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11700: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11701: my $count;
11702: my $filepath = $dir_root;
1.1027 raeburn 11703: foreach my $subdir (@parts) {
11704: $filepath .= "/$subdir";
11705: if (!-e $filepath) {
1.661 raeburn 11706: mkdir($filepath,0770);
11707: }
11708: }
11709: my $fh;
11710: if (!open($fh,'>'.$dest)) {
11711: &Apache::lonnet::logthis('Failed to create '.$dest);
11712: $output .= '<span class="LC_error">'.
1.1071 raeburn 11713: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11714: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11715: '</span><br />';
11716: } else {
11717: if (!print $fh $env{'form.embedded_item_'.$i}) {
11718: &Apache::lonnet::logthis('Failed to write to '.$dest);
11719: $output .= '<span class="LC_error">'.
1.1071 raeburn 11720: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11721: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11722: '</span><br />';
11723: } else {
1.987 raeburn 11724: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11725: $url.'</span>').'<br />';
11726: unless ($context eq 'testbank') {
11727: $footer .= &mt('View embedded file: [_1]',
11728: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11729: }
11730: }
11731: close($fh);
11732: }
11733: }
11734: if ($env{'form.embedded_ref_'.$i}) {
11735: $pathchange{$i} = 1;
11736: }
11737: }
11738: if ($output) {
11739: $output = '<p>'.$output.'</p>';
11740: }
11741: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11742: $returnflag = 'ok';
1.1071 raeburn 11743: my $numpathchgs = scalar(keys(%pathchange));
11744: if ($numpathchgs > 0) {
1.987 raeburn 11745: if ($context eq 'portfolio') {
11746: $output .= '<p>'.&mt('or').'</p>';
11747: } elsif ($context eq 'testbank') {
1.1071 raeburn 11748: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11749: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11750: $returnflag = 'modify_orightml';
11751: }
11752: }
1.1071 raeburn 11753: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11754: }
11755:
11756: sub modify_html_form {
11757: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11758: my $end = 0;
11759: my $modifyform;
11760: if ($context eq 'upload_embedded') {
11761: return unless (ref($pathchange) eq 'HASH');
11762: if ($env{'form.number_embedded_items'}) {
11763: $end += $env{'form.number_embedded_items'};
11764: }
11765: if ($env{'form.number_pathchange_items'}) {
11766: $end += $env{'form.number_pathchange_items'};
11767: }
11768: if ($end) {
11769: for (my $i=0; $i<$end; $i++) {
11770: if ($i < $env{'form.number_embedded_items'}) {
11771: next unless($pathchange->{$i});
11772: }
11773: $modifyform .=
11774: &start_data_table_row().
11775: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11776: 'checked="checked" /></td>'.
11777: '<td>'.$env{'form.embedded_ref_'.$i}.
11778: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11779: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11780: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11781: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11782: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11783: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11784: '<td>'.$env{'form.embedded_orig_'.$i}.
11785: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11786: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11787: &end_data_table_row();
1.1071 raeburn 11788: }
1.987 raeburn 11789: }
11790: } else {
11791: $modifyform = $pathchgtable;
11792: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11793: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11794: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11795: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11796: }
11797: }
11798: if ($modifyform) {
1.1071 raeburn 11799: if ($actionurl eq '/adm/dependencies') {
11800: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11801: }
1.987 raeburn 11802: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11803: '<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".
11804: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11805: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11806: '</ol></p>'."\n".'<p>'.
11807: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11808: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11809: &start_data_table()."\n".
11810: &start_data_table_header_row().
11811: '<th>'.&mt('Change?').'</th>'.
11812: '<th>'.&mt('Current reference').'</th>'.
11813: '<th>'.&mt('Required reference').'</th>'.
11814: &end_data_table_header_row()."\n".
11815: $modifyform.
11816: &end_data_table().'<br />'."\n".$hiddenstate.
11817: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11818: '</form>'."\n";
11819: }
11820: return;
11821: }
11822:
11823: sub modify_html_refs {
1.1075.2.35 raeburn 11824: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11825: my $container;
11826: if ($context eq 'portfolio') {
11827: $container = $env{'form.container'};
11828: } elsif ($context eq 'coursedoc') {
11829: $container = $env{'form.primaryurl'};
1.1071 raeburn 11830: } elsif ($context eq 'manage_dependencies') {
11831: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11832: $container = "/$container";
1.1075.2.35 raeburn 11833: } elsif ($context eq 'syllabus') {
11834: $container = $url;
1.987 raeburn 11835: } else {
1.1027 raeburn 11836: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11837: }
11838: my (%allfiles,%codebase,$output,$content);
11839: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11840: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11841: if (wantarray) {
11842: return ('',0,0);
11843: } else {
11844: return;
11845: }
11846: }
11847: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11848: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11849: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11850: if (wantarray) {
11851: return ('',0,0);
11852: } else {
11853: return;
11854: }
11855: }
1.987 raeburn 11856: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11857: if ($content eq '-1') {
11858: if (wantarray) {
11859: return ('',0,0);
11860: } else {
11861: return;
11862: }
11863: }
1.987 raeburn 11864: } else {
1.1071 raeburn 11865: unless ($container =~ /^\Q$dir_root\E/) {
11866: if (wantarray) {
11867: return ('',0,0);
11868: } else {
11869: return;
11870: }
11871: }
1.1075.2.128 raeburn 11872: if (open(my $fh,'<',$container)) {
1.987 raeburn 11873: $content = join('', <$fh>);
11874: close($fh);
11875: } else {
1.1071 raeburn 11876: if (wantarray) {
11877: return ('',0,0);
11878: } else {
11879: return;
11880: }
1.987 raeburn 11881: }
11882: }
11883: my ($count,$codebasecount) = (0,0);
11884: my $mm = new File::MMagic;
11885: my $mime_type = $mm->checktype_contents($content);
11886: if ($mime_type eq 'text/html') {
11887: my $parse_result =
11888: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11889: \%codebase,\$content);
11890: if ($parse_result eq 'ok') {
11891: foreach my $i (@changes) {
11892: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11893: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11894: if ($allfiles{$ref}) {
11895: my $newname = $orig;
11896: my ($attrib_regexp,$codebase);
1.1006 raeburn 11897: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11898: if ($attrib_regexp =~ /:/) {
11899: $attrib_regexp =~ s/\:/|/g;
11900: }
11901: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11902: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11903: $count += $numchg;
1.1075.2.35 raeburn 11904: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11905: delete($allfiles{$ref});
1.987 raeburn 11906: }
11907: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11908: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11909: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11910: $codebasecount ++;
11911: }
11912: }
11913: }
1.1075.2.35 raeburn 11914: my $skiprewrites;
1.987 raeburn 11915: if ($count || $codebasecount) {
11916: my $saveresult;
1.1071 raeburn 11917: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11918: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11919: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11920: if ($url eq $container) {
11921: my ($fname) = ($container =~ m{/([^/]+)$});
11922: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11923: $count,'<span class="LC_filename">'.
1.1071 raeburn 11924: $fname.'</span>').'</p>';
1.987 raeburn 11925: } else {
11926: $output = '<p class="LC_error">'.
11927: &mt('Error: update failed for: [_1].',
11928: '<span class="LC_filename">'.
11929: $container.'</span>').'</p>';
11930: }
1.1075.2.35 raeburn 11931: if ($context eq 'syllabus') {
11932: unless ($saveresult eq 'ok') {
11933: $skiprewrites = 1;
11934: }
11935: }
1.987 raeburn 11936: } else {
1.1075.2.128 raeburn 11937: if (open(my $fh,'>',$container)) {
1.987 raeburn 11938: print $fh $content;
11939: close($fh);
11940: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11941: $count,'<span class="LC_filename">'.
11942: $container.'</span>').'</p>';
1.661 raeburn 11943: } else {
1.987 raeburn 11944: $output = '<p class="LC_error">'.
11945: &mt('Error: could not update [_1].',
11946: '<span class="LC_filename">'.
11947: $container.'</span>').'</p>';
1.661 raeburn 11948: }
11949: }
11950: }
1.1075.2.35 raeburn 11951: if (($context eq 'syllabus') && (!$skiprewrites)) {
11952: my ($actionurl,$state);
11953: $actionurl = "/public/$udom/$uname/syllabus";
11954: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11955: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11956: \%codebase,
11957: {'context' => 'rewrites',
11958: 'ignore_remote_references' => 1,});
11959: if (ref($mapping) eq 'HASH') {
11960: my $rewrites = 0;
11961: foreach my $key (keys(%{$mapping})) {
11962: next if ($key =~ m{^https?://});
11963: my $ref = $mapping->{$key};
11964: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11965: my $attrib;
11966: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11967: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11968: }
11969: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11970: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11971: $rewrites += $numchg;
11972: }
11973: }
11974: if ($rewrites) {
11975: my $saveresult;
11976: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11977: if ($url eq $container) {
11978: my ($fname) = ($container =~ m{/([^/]+)$});
11979: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11980: $count,'<span class="LC_filename">'.
11981: $fname.'</span>').'</p>';
11982: } else {
11983: $output .= '<p class="LC_error">'.
11984: &mt('Error: could not update links in [_1].',
11985: '<span class="LC_filename">'.
11986: $container.'</span>').'</p>';
11987:
11988: }
11989: }
11990: }
11991: }
1.987 raeburn 11992: } else {
11993: &logthis('Failed to parse '.$container.
11994: ' to modify references: '.$parse_result);
1.661 raeburn 11995: }
11996: }
1.1071 raeburn 11997: if (wantarray) {
11998: return ($output,$count,$codebasecount);
11999: } else {
12000: return $output;
12001: }
1.661 raeburn 12002: }
12003:
12004: sub check_for_existing {
12005: my ($path,$fname,$element) = @_;
12006: my ($state,$msg);
12007: if (-d $path.'/'.$fname) {
12008: $state = 'exists';
12009: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12010: } elsif (-e $path.'/'.$fname) {
12011: $state = 'exists';
12012: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12013: }
12014: if ($state eq 'exists') {
12015: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12016: }
12017: return ($state,$msg);
12018: }
12019:
12020: sub check_for_upload {
12021: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12022: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12023: my $filesize = length($env{'form.'.$element});
12024: if (!$filesize) {
12025: my $msg = '<span class="LC_error">'.
12026: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12027: '<span class="LC_filename">'.$fname.'</span>',
12028: $filesize).'<br />'.
1.1007 raeburn 12029: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12030: '</span>';
12031: return ('zero_bytes',$msg);
12032: }
12033: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12034: my $getpropath = 1;
1.1021 raeburn 12035: my ($dirlistref,$listerror) =
12036: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12037: my $found_file = 0;
12038: my $locked_file = 0;
1.991 raeburn 12039: my @lockers;
12040: my $navmap;
12041: if ($env{'request.course.id'}) {
12042: $navmap = Apache::lonnavmaps::navmap->new();
12043: }
1.1021 raeburn 12044: if (ref($dirlistref) eq 'ARRAY') {
12045: foreach my $line (@{$dirlistref}) {
12046: my ($file_name,$rest)=split(/\&/,$line,2);
12047: if ($file_name eq $fname){
12048: $file_name = $path.$file_name;
12049: if ($group ne '') {
12050: $file_name = $group.$file_name;
12051: }
12052: $found_file = 1;
12053: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12054: foreach my $lock (@lockers) {
12055: if (ref($lock) eq 'ARRAY') {
12056: my ($symb,$crsid) = @{$lock};
12057: if ($crsid eq $env{'request.course.id'}) {
12058: if (ref($navmap)) {
12059: my $res = $navmap->getBySymb($symb);
12060: foreach my $part (@{$res->parts()}) {
12061: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12062: unless (($slot_status == $res->RESERVED) ||
12063: ($slot_status == $res->RESERVED_LOCATION)) {
12064: $locked_file = 1;
12065: }
1.991 raeburn 12066: }
1.1021 raeburn 12067: } else {
12068: $locked_file = 1;
1.991 raeburn 12069: }
12070: } else {
12071: $locked_file = 1;
12072: }
12073: }
1.1021 raeburn 12074: }
12075: } else {
12076: my @info = split(/\&/,$rest);
12077: my $currsize = $info[6]/1000;
12078: if ($currsize < $filesize) {
12079: my $extra = $filesize - $currsize;
12080: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 12081: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12082: &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 12083: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12084: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12085: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12086: return ('will_exceed_quota',$msg);
12087: }
1.984 raeburn 12088: }
12089: }
1.661 raeburn 12090: }
12091: }
12092: }
12093: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 12094: my $msg = '<p class="LC_warning">'.
12095: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
12096: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12097: return ('will_exceed_quota',$msg);
12098: } elsif ($found_file) {
12099: if ($locked_file) {
1.1075.2.69 raeburn 12100: my $msg = '<p class="LC_warning">';
1.661 raeburn 12101: $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 12102: $msg .= '</p>';
1.661 raeburn 12103: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12104: return ('file_locked',$msg);
12105: } else {
1.1075.2.69 raeburn 12106: my $msg = '<p class="LC_error">';
1.984 raeburn 12107: $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 12108: $msg .= '</p>';
1.984 raeburn 12109: return ('existingfile',$msg);
1.661 raeburn 12110: }
12111: }
12112: }
12113:
1.987 raeburn 12114: sub check_for_traversal {
12115: my ($path,$url,$toplevel) = @_;
12116: my @parts=split(/\//,$path);
12117: my $cleanpath;
12118: my $fullpath = $url;
12119: for (my $i=0;$i<@parts;$i++) {
12120: next if ($parts[$i] eq '.');
12121: if ($parts[$i] eq '..') {
12122: $fullpath =~ s{([^/]+/)$}{};
12123: } else {
12124: $fullpath .= $parts[$i].'/';
12125: }
12126: }
12127: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12128: $cleanpath = $1;
12129: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12130: my $curr_toprel = $1;
12131: my @parts = split(/\//,$curr_toprel);
12132: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12133: my @urlparts = split(/\//,$url_toprel);
12134: my $doubledots;
12135: my $startdiff = -1;
12136: for (my $i=0; $i<@urlparts; $i++) {
12137: if ($startdiff == -1) {
12138: unless ($urlparts[$i] eq $parts[$i]) {
12139: $startdiff = $i;
12140: $doubledots .= '../';
12141: }
12142: } else {
12143: $doubledots .= '../';
12144: }
12145: }
12146: if ($startdiff > -1) {
12147: $cleanpath = $doubledots;
12148: for (my $i=$startdiff; $i<@parts; $i++) {
12149: $cleanpath .= $parts[$i].'/';
12150: }
12151: }
12152: }
12153: $cleanpath =~ s{(/)$}{};
12154: return $cleanpath;
12155: }
1.31 albertel 12156:
1.1053 raeburn 12157: sub is_archive_file {
12158: my ($mimetype) = @_;
12159: if (($mimetype eq 'application/octet-stream') ||
12160: ($mimetype eq 'application/x-stuffit') ||
12161: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12162: return 1;
12163: }
12164: return;
12165: }
12166:
12167: sub decompress_form {
1.1065 raeburn 12168: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12169: my %lt = &Apache::lonlocal::texthash (
12170: this => 'This file is an archive file.',
1.1067 raeburn 12171: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12172: itsc => 'Its contents are as follows:',
1.1053 raeburn 12173: youm => 'You may wish to extract its contents.',
12174: extr => 'Extract contents',
1.1067 raeburn 12175: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12176: proa => 'Process automatically?',
1.1053 raeburn 12177: yes => 'Yes',
12178: no => 'No',
1.1067 raeburn 12179: fold => 'Title for folder containing movie',
12180: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12181: );
1.1065 raeburn 12182: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12183: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12184: my $info = &list_archive_contents($fileloc,\@paths);
12185: if (@paths) {
12186: foreach my $path (@paths) {
12187: $path =~ s{^/}{};
1.1067 raeburn 12188: if ($path =~ m{^([^/]+)/$}) {
12189: $topdir = $1;
12190: }
1.1065 raeburn 12191: if ($path =~ m{^([^/]+)/}) {
12192: $toplevel{$1} = $path;
12193: } else {
12194: $toplevel{$path} = $path;
12195: }
12196: }
12197: }
1.1067 raeburn 12198: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 12199: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12200: "$topdir/media/",
12201: "$topdir/media/$topdir.mp4",
12202: "$topdir/media/FirstFrame.png",
12203: "$topdir/media/player.swf",
12204: "$topdir/media/swfobject.js",
12205: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 12206: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 12207: "$topdir/$topdir.mp4",
12208: "$topdir/$topdir\_config.xml",
12209: "$topdir/$topdir\_controller.swf",
12210: "$topdir/$topdir\_embed.css",
12211: "$topdir/$topdir\_First_Frame.png",
12212: "$topdir/$topdir\_player.html",
12213: "$topdir/$topdir\_Thumbnails.png",
12214: "$topdir/playerProductInstall.swf",
12215: "$topdir/scripts/",
12216: "$topdir/scripts/config_xml.js",
12217: "$topdir/scripts/handlebars.js",
12218: "$topdir/scripts/jquery-1.7.1.min.js",
12219: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12220: "$topdir/scripts/modernizr.js",
12221: "$topdir/scripts/player-min.js",
12222: "$topdir/scripts/swfobject.js",
12223: "$topdir/skins/",
12224: "$topdir/skins/configuration_express.xml",
12225: "$topdir/skins/express_show/",
12226: "$topdir/skins/express_show/player-min.css",
12227: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 12228: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12229: "$topdir/$topdir.mp4",
12230: "$topdir/$topdir\_config.xml",
12231: "$topdir/$topdir\_controller.swf",
12232: "$topdir/$topdir\_embed.css",
12233: "$topdir/$topdir\_First_Frame.png",
12234: "$topdir/$topdir\_player.html",
12235: "$topdir/$topdir\_Thumbnails.png",
12236: "$topdir/playerProductInstall.swf",
12237: "$topdir/scripts/",
12238: "$topdir/scripts/config_xml.js",
12239: "$topdir/scripts/techsmith-smart-player.min.js",
12240: "$topdir/skins/",
12241: "$topdir/skins/configuration_express.xml",
12242: "$topdir/skins/express_show/",
12243: "$topdir/skins/express_show/spritesheet.min.css",
12244: "$topdir/skins/express_show/spritesheet.png",
12245: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 12246: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12247: if (@diffs == 0) {
1.1075.2.59 raeburn 12248: $is_camtasia = 6;
12249: } else {
1.1075.2.81 raeburn 12250: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 12251: if (@diffs == 0) {
12252: $is_camtasia = 8;
1.1075.2.81 raeburn 12253: } else {
12254: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12255: if (@diffs == 0) {
12256: $is_camtasia = 8;
12257: }
1.1075.2.59 raeburn 12258: }
1.1067 raeburn 12259: }
12260: }
12261: my $output;
12262: if ($is_camtasia) {
12263: $output = <<"ENDCAM";
12264: <script type="text/javascript" language="Javascript">
12265: // <![CDATA[
12266:
12267: function camtasiaToggle() {
12268: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12269: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 12270: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12271: document.getElementById('camtasia_titles').style.display='block';
12272: } else {
12273: document.getElementById('camtasia_titles').style.display='none';
12274: }
12275: }
12276: }
12277: return;
12278: }
12279:
12280: // ]]>
12281: </script>
12282: <p>$lt{'camt'}</p>
12283: ENDCAM
1.1065 raeburn 12284: } else {
1.1067 raeburn 12285: $output = '<p>'.$lt{'this'};
12286: if ($info eq '') {
12287: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12288: } else {
12289: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12290: '<div><pre>'.$info.'</pre></div>';
12291: }
1.1065 raeburn 12292: }
1.1067 raeburn 12293: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12294: my $duplicates;
12295: my $num = 0;
12296: if (ref($dirlist) eq 'ARRAY') {
12297: foreach my $item (@{$dirlist}) {
12298: if (ref($item) eq 'ARRAY') {
12299: if (exists($toplevel{$item->[0]})) {
12300: $duplicates .=
12301: &start_data_table_row().
12302: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12303: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12304: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12305: 'value="1" />'.&mt('Yes').'</label>'.
12306: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12307: '<td>'.$item->[0].'</td>';
12308: if ($item->[2]) {
12309: $duplicates .= '<td>'.&mt('Directory').'</td>';
12310: } else {
12311: $duplicates .= '<td>'.&mt('File').'</td>';
12312: }
12313: $duplicates .= '<td>'.$item->[3].'</td>'.
12314: '<td>'.
12315: &Apache::lonlocal::locallocaltime($item->[4]).
12316: '</td>'.
12317: &end_data_table_row();
12318: $num ++;
12319: }
12320: }
12321: }
12322: }
12323: my $itemcount;
12324: if (@paths > 0) {
12325: $itemcount = scalar(@paths);
12326: } else {
12327: $itemcount = 1;
12328: }
1.1067 raeburn 12329: if ($is_camtasia) {
12330: $output .= $lt{'auto'}.'<br />'.
12331: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12332: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12333: $lt{'yes'}.'</label> <label>'.
12334: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12335: $lt{'no'}.'</label></span><br />'.
12336: '<div id="camtasia_titles" style="display:block">'.
12337: &Apache::lonhtmlcommon::start_pick_box().
12338: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12339: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12340: &Apache::lonhtmlcommon::row_closure().
12341: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12342: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12343: &Apache::lonhtmlcommon::row_closure(1).
12344: &Apache::lonhtmlcommon::end_pick_box().
12345: '</div>';
12346: }
1.1065 raeburn 12347: $output .=
12348: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12349: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12350: "\n";
1.1065 raeburn 12351: if ($duplicates ne '') {
12352: $output .= '<p><span class="LC_warning">'.
12353: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12354: &start_data_table().
12355: &start_data_table_header_row().
12356: '<th>'.&mt('Overwrite?').'</th>'.
12357: '<th>'.&mt('Name').'</th>'.
12358: '<th>'.&mt('Type').'</th>'.
12359: '<th>'.&mt('Size').'</th>'.
12360: '<th>'.&mt('Last modified').'</th>'.
12361: &end_data_table_header_row().
12362: $duplicates.
12363: &end_data_table().
12364: '</p>';
12365: }
1.1067 raeburn 12366: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12367: if (ref($hiddenelements) eq 'HASH') {
12368: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12369: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12370: }
12371: }
12372: $output .= <<"END";
1.1067 raeburn 12373: <br />
1.1053 raeburn 12374: <input type="submit" name="decompress" value="$lt{'extr'}" />
12375: </form>
12376: $noextract
12377: END
12378: return $output;
12379: }
12380:
1.1065 raeburn 12381: sub decompression_utility {
12382: my ($program) = @_;
12383: my @utilities = ('tar','gunzip','bunzip2','unzip');
12384: my $location;
12385: if (grep(/^\Q$program\E$/,@utilities)) {
12386: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12387: '/usr/sbin/') {
12388: if (-x $dir.$program) {
12389: $location = $dir.$program;
12390: last;
12391: }
12392: }
12393: }
12394: return $location;
12395: }
12396:
12397: sub list_archive_contents {
12398: my ($file,$pathsref) = @_;
12399: my (@cmd,$output);
12400: my $needsregexp;
12401: if ($file =~ /\.zip$/) {
12402: @cmd = (&decompression_utility('unzip'),"-l");
12403: $needsregexp = 1;
12404: } elsif (($file =~ m/\.tar\.gz$/) ||
12405: ($file =~ /\.tgz$/)) {
12406: @cmd = (&decompression_utility('tar'),"-ztf");
12407: } elsif ($file =~ /\.tar\.bz2$/) {
12408: @cmd = (&decompression_utility('tar'),"-jtf");
12409: } elsif ($file =~ m|\.tar$|) {
12410: @cmd = (&decompression_utility('tar'),"-tf");
12411: }
12412: if (@cmd) {
12413: undef($!);
12414: undef($@);
12415: if (open(my $fh,"-|", @cmd, $file)) {
12416: while (my $line = <$fh>) {
12417: $output .= $line;
12418: chomp($line);
12419: my $item;
12420: if ($needsregexp) {
12421: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12422: } else {
12423: $item = $line;
12424: }
12425: if ($item ne '') {
12426: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12427: push(@{$pathsref},$item);
12428: }
12429: }
12430: }
12431: close($fh);
12432: }
12433: }
12434: return $output;
12435: }
12436:
1.1053 raeburn 12437: sub decompress_uploaded_file {
12438: my ($file,$dir) = @_;
12439: &Apache::lonnet::appenv({'cgi.file' => $file});
12440: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12441: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12442: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12443: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12444: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12445: my $decompressed = $env{'cgi.decompressed'};
12446: &Apache::lonnet::delenv('cgi.file');
12447: &Apache::lonnet::delenv('cgi.dir');
12448: &Apache::lonnet::delenv('cgi.decompressed');
12449: return ($decompressed,$result);
12450: }
12451:
1.1055 raeburn 12452: sub process_decompression {
12453: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12454: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12455: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12456: &mt('Unexpected file path.').'</p>'."\n";
12457: }
12458: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12459: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12460: &mt('Unexpected course context.').'</p>'."\n";
12461: }
12462: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12463: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12464: &mt('Filename contained unexpected characters.').'</p>'."\n";
12465: }
1.1055 raeburn 12466: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12467: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12468: $error = &mt('Filename not a supported archive file type.').
12469: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12470: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12471: } else {
12472: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12473: if ($docuhome eq 'no_host') {
12474: $error = &mt('Could not determine home server for course.');
12475: } else {
12476: my @ids=&Apache::lonnet::current_machine_ids();
12477: my $currdir = "$dir_root/$destination";
12478: if (grep(/^\Q$docuhome\E$/,@ids)) {
12479: $dir = &LONCAPA::propath($docudom,$docuname).
12480: "$dir_root/$destination";
12481: } else {
12482: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12483: "$dir_root/$docudom/$docuname/$destination";
12484: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12485: $error = &mt('Archive file not found.');
12486: }
12487: }
1.1065 raeburn 12488: my (@to_overwrite,@to_skip);
12489: if ($env{'form.archive_overwrite_total'} > 0) {
12490: my $total = $env{'form.archive_overwrite_total'};
12491: for (my $i=0; $i<$total; $i++) {
12492: if ($env{'form.archive_overwrite_'.$i} == 1) {
12493: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12494: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12495: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12496: }
12497: }
12498: }
12499: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12500: my $numoverwrite = scalar(@to_overwrite);
12501: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12502: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12503: } elsif ($dir eq '') {
1.1055 raeburn 12504: $error = &mt('Directory containing archive file unavailable.');
12505: } elsif (!$error) {
1.1065 raeburn 12506: my ($decompressed,$display);
1.1075.2.128 raeburn 12507: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12508: my $tempdir = time.'_'.$$.int(rand(10000));
12509: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12510: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12511: ($decompressed,$display) =
12512: &decompress_uploaded_file($file,"$dir/$tempdir");
12513: foreach my $item (@to_skip) {
12514: if (($item ne '') && ($item !~ /\.\./)) {
12515: if (-f "$dir/$tempdir/$item") {
12516: unlink("$dir/$tempdir/$item");
12517: } elsif (-d "$dir/$tempdir/$item") {
12518: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12519: }
12520: }
12521: }
12522: foreach my $item (@to_overwrite) {
12523: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12524: if (($item ne '') && ($item !~ /\.\./)) {
12525: if (-f "$dir/$item") {
12526: unlink("$dir/$item");
12527: } elsif (-d "$dir/$item") {
12528: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12529: }
12530: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12531: }
1.1065 raeburn 12532: }
12533: }
1.1075.2.128 raeburn 12534: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12535: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12536: }
1.1065 raeburn 12537: }
12538: } else {
12539: ($decompressed,$display) =
12540: &decompress_uploaded_file($file,$dir);
12541: }
1.1055 raeburn 12542: if ($decompressed eq 'ok') {
1.1065 raeburn 12543: $output = '<p class="LC_info">'.
12544: &mt('Files extracted successfully from archive.').
12545: '</p>'."\n";
1.1055 raeburn 12546: my ($warning,$result,@contents);
12547: my ($newdirlistref,$newlisterror) =
12548: &Apache::lonnet::dirlist($currdir,$docudom,
12549: $docuname,1);
12550: my (%is_dir,%changes,@newitems);
12551: my $dirptr = 16384;
1.1065 raeburn 12552: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12553: foreach my $dir_line (@{$newdirlistref}) {
12554: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12555: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12556: push(@newitems,$item);
12557: if ($dirptr&$testdir) {
12558: $is_dir{$item} = 1;
12559: }
12560: $changes{$item} = 1;
12561: }
12562: }
12563: }
12564: if (keys(%changes) > 0) {
12565: foreach my $item (sort(@newitems)) {
12566: if ($changes{$item}) {
12567: push(@contents,$item);
12568: }
12569: }
12570: }
12571: if (@contents > 0) {
1.1067 raeburn 12572: my $wantform;
12573: unless ($env{'form.autoextract_camtasia'}) {
12574: $wantform = 1;
12575: }
1.1056 raeburn 12576: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12577: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12578: $currdir,\%is_dir,
12579: \%children,\%parent,
1.1056 raeburn 12580: \@contents,\%dirorder,
12581: \%titles,$wantform);
1.1055 raeburn 12582: if ($datatable ne '') {
12583: $output .= &archive_options_form('decompressed',$datatable,
12584: $count,$hiddenelem);
1.1065 raeburn 12585: my $startcount = 6;
1.1055 raeburn 12586: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12587: \%titles,\%children);
1.1055 raeburn 12588: }
1.1067 raeburn 12589: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12590: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12591: my %displayed;
12592: my $total = 1;
12593: $env{'form.archive_directory'} = [];
12594: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12595: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12596: $path =~ s{/$}{};
12597: my $item;
12598: if ($path ne '') {
12599: $item = "$path/$titles{$i}";
12600: } else {
12601: $item = $titles{$i};
12602: }
12603: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12604: if ($item eq $contents[0]) {
12605: push(@{$env{'form.archive_directory'}},$i);
12606: $env{'form.archive_'.$i} = 'display';
12607: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12608: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12609: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12610: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12611: $env{'form.archive_'.$i} = 'display';
12612: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12613: $displayed{'web'} = $i;
12614: } else {
1.1075.2.59 raeburn 12615: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12616: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12617: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12618: push(@{$env{'form.archive_directory'}},$i);
12619: }
12620: $env{'form.archive_'.$i} = 'dependency';
12621: }
12622: $total ++;
12623: }
12624: for (my $i=1; $i<$total; $i++) {
12625: next if ($i == $displayed{'web'});
12626: next if ($i == $displayed{'folder'});
12627: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12628: }
12629: $env{'form.phase'} = 'decompress_cleanup';
12630: $env{'form.archivedelete'} = 1;
12631: $env{'form.archive_count'} = $total-1;
12632: $output .=
12633: &process_extracted_files('coursedocs',$docudom,
12634: $docuname,$destination,
12635: $dir_root,$hiddenelem);
12636: }
1.1055 raeburn 12637: } else {
12638: $warning = &mt('No new items extracted from archive file.');
12639: }
12640: } else {
12641: $output = $display;
12642: $error = &mt('An error occurred during extraction from the archive file.');
12643: }
12644: }
12645: }
12646: }
12647: if ($error) {
12648: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12649: $error.'</p>'."\n";
12650: }
12651: if ($warning) {
12652: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12653: }
12654: return $output;
12655: }
12656:
12657: sub get_extracted {
1.1056 raeburn 12658: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12659: $titles,$wantform) = @_;
1.1055 raeburn 12660: my $count = 0;
12661: my $depth = 0;
12662: my $datatable;
1.1056 raeburn 12663: my @hierarchy;
1.1055 raeburn 12664: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12665: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12666: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12667: foreach my $item (@{$contents}) {
12668: $count ++;
1.1056 raeburn 12669: @{$dirorder->{$count}} = @hierarchy;
12670: $titles->{$count} = $item;
1.1055 raeburn 12671: &archive_hierarchy($depth,$count,$parent,$children);
12672: if ($wantform) {
12673: $datatable .= &archive_row($is_dir->{$item},$item,
12674: $currdir,$depth,$count);
12675: }
12676: if ($is_dir->{$item}) {
12677: $depth ++;
1.1056 raeburn 12678: push(@hierarchy,$count);
12679: $parent->{$depth} = $count;
1.1055 raeburn 12680: $datatable .=
12681: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12682: \$depth,\$count,\@hierarchy,$dirorder,
12683: $children,$parent,$titles,$wantform);
1.1055 raeburn 12684: $depth --;
1.1056 raeburn 12685: pop(@hierarchy);
1.1055 raeburn 12686: }
12687: }
12688: return ($count,$datatable);
12689: }
12690:
12691: sub recurse_extracted_archive {
1.1056 raeburn 12692: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12693: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12694: my $result='';
1.1056 raeburn 12695: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12696: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12697: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12698: return $result;
12699: }
12700: my $dirptr = 16384;
12701: my ($newdirlistref,$newlisterror) =
12702: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12703: if (ref($newdirlistref) eq 'ARRAY') {
12704: foreach my $dir_line (@{$newdirlistref}) {
12705: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12706: unless ($item =~ /^\.+$/) {
12707: $$count ++;
1.1056 raeburn 12708: @{$dirorder->{$$count}} = @{$hierarchy};
12709: $titles->{$$count} = $item;
1.1055 raeburn 12710: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12711:
1.1055 raeburn 12712: my $is_dir;
12713: if ($dirptr&$testdir) {
12714: $is_dir = 1;
12715: }
12716: if ($wantform) {
12717: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12718: }
12719: if ($is_dir) {
12720: $$depth ++;
1.1056 raeburn 12721: push(@{$hierarchy},$$count);
12722: $parent->{$$depth} = $$count;
1.1055 raeburn 12723: $result .=
12724: &recurse_extracted_archive("$currdir/$item",$docudom,
12725: $docuname,$depth,$count,
1.1056 raeburn 12726: $hierarchy,$dirorder,$children,
12727: $parent,$titles,$wantform);
1.1055 raeburn 12728: $$depth --;
1.1056 raeburn 12729: pop(@{$hierarchy});
1.1055 raeburn 12730: }
12731: }
12732: }
12733: }
12734: return $result;
12735: }
12736:
12737: sub archive_hierarchy {
12738: my ($depth,$count,$parent,$children) =@_;
12739: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12740: if (exists($parent->{$depth})) {
12741: $children->{$parent->{$depth}} .= $count.':';
12742: }
12743: }
12744: return;
12745: }
12746:
12747: sub archive_row {
12748: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12749: my ($name) = ($item =~ m{([^/]+)$});
12750: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12751: 'display' => 'Add as file',
1.1055 raeburn 12752: 'dependency' => 'Include as dependency',
12753: 'discard' => 'Discard',
12754: );
12755: if ($is_dir) {
1.1059 raeburn 12756: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12757: }
1.1056 raeburn 12758: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12759: my $offset = 0;
1.1055 raeburn 12760: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12761: $offset ++;
1.1065 raeburn 12762: if ($action ne 'display') {
12763: $offset ++;
12764: }
1.1055 raeburn 12765: $output .= '<td><span class="LC_nobreak">'.
12766: '<label><input type="radio" name="archive_'.$count.
12767: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12768: my $text = $choices{$action};
12769: if ($is_dir) {
12770: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12771: if ($action eq 'display') {
1.1059 raeburn 12772: $text = &mt('Add as folder');
1.1055 raeburn 12773: }
1.1056 raeburn 12774: } else {
12775: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12776:
12777: }
12778: $output .= ' /> '.$choices{$action}.'</label></span>';
12779: if ($action eq 'dependency') {
12780: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12781: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12782: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12783: '<option value=""></option>'."\n".
12784: '</select>'."\n".
12785: '</div>';
1.1059 raeburn 12786: } elsif ($action eq 'display') {
12787: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12788: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12789: '</div>';
1.1055 raeburn 12790: }
1.1056 raeburn 12791: $output .= '</td>';
1.1055 raeburn 12792: }
12793: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12794: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12795: for (my $i=0; $i<$depth; $i++) {
12796: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12797: }
12798: if ($is_dir) {
12799: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12800: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12801: } else {
12802: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12803: }
12804: $output .= ' '.$name.'</td>'."\n".
12805: &end_data_table_row();
12806: return $output;
12807: }
12808:
12809: sub archive_options_form {
1.1065 raeburn 12810: my ($form,$display,$count,$hiddenelem) = @_;
12811: my %lt = &Apache::lonlocal::texthash(
12812: perm => 'Permanently remove archive file?',
12813: hows => 'How should each extracted item be incorporated in the course?',
12814: cont => 'Content actions for all',
12815: addf => 'Add as folder/file',
12816: incd => 'Include as dependency for a displayed file',
12817: disc => 'Discard',
12818: no => 'No',
12819: yes => 'Yes',
12820: save => 'Save',
12821: );
12822: my $output = <<"END";
12823: <form name="$form" method="post" action="">
12824: <p><span class="LC_nobreak">$lt{'perm'}
12825: <label>
12826: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12827: </label>
12828:
12829: <label>
12830: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12831: </span>
12832: </p>
12833: <input type="hidden" name="phase" value="decompress_cleanup" />
12834: <br />$lt{'hows'}
12835: <div class="LC_columnSection">
12836: <fieldset>
12837: <legend>$lt{'cont'}</legend>
12838: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12839: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12840: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12841: </fieldset>
12842: </div>
12843: END
12844: return $output.
1.1055 raeburn 12845: &start_data_table()."\n".
1.1065 raeburn 12846: $display."\n".
1.1055 raeburn 12847: &end_data_table()."\n".
12848: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12849: $hiddenelem.
1.1065 raeburn 12850: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12851: '</form>';
12852: }
12853:
12854: sub archive_javascript {
1.1056 raeburn 12855: my ($startcount,$numitems,$titles,$children) = @_;
12856: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12857: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12858: my $scripttag = <<START;
12859: <script type="text/javascript">
12860: // <![CDATA[
12861:
12862: function checkAll(form,prefix) {
12863: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12864: for (var i=0; i < form.elements.length; i++) {
12865: var id = form.elements[i].id;
12866: if ((id != '') && (id != undefined)) {
12867: if (idstr.test(id)) {
12868: if (form.elements[i].type == 'radio') {
12869: form.elements[i].checked = true;
1.1056 raeburn 12870: var nostart = i-$startcount;
1.1059 raeburn 12871: var offset = nostart%7;
12872: var count = (nostart-offset)/7;
1.1056 raeburn 12873: dependencyCheck(form,count,offset);
1.1055 raeburn 12874: }
12875: }
12876: }
12877: }
12878: }
12879:
12880: function propagateCheck(form,count) {
12881: if (count > 0) {
1.1059 raeburn 12882: var startelement = $startcount + ((count-1) * 7);
12883: for (var j=1; j<6; j++) {
12884: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12885: var item = startelement + j;
12886: if (form.elements[item].type == 'radio') {
12887: if (form.elements[item].checked) {
12888: containerCheck(form,count,j);
12889: break;
12890: }
1.1055 raeburn 12891: }
12892: }
12893: }
12894: }
12895: }
12896:
12897: numitems = $numitems
1.1056 raeburn 12898: var titles = new Array(numitems);
12899: var parents = new Array(numitems);
1.1055 raeburn 12900: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12901: parents[i] = new Array;
1.1055 raeburn 12902: }
1.1059 raeburn 12903: var maintitle = '$maintitle';
1.1055 raeburn 12904:
12905: START
12906:
1.1056 raeburn 12907: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12908: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12909: for (my $i=0; $i<@contents; $i ++) {
12910: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12911: }
12912: }
12913:
1.1056 raeburn 12914: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12915: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12916: }
12917:
1.1055 raeburn 12918: $scripttag .= <<END;
12919:
12920: function containerCheck(form,count,offset) {
12921: if (count > 0) {
1.1056 raeburn 12922: dependencyCheck(form,count,offset);
1.1059 raeburn 12923: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12924: form.elements[item].checked = true;
12925: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12926: if (parents[count].length > 0) {
12927: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12928: containerCheck(form,parents[count][j],offset);
12929: }
12930: }
12931: }
12932: }
12933: }
12934:
12935: function dependencyCheck(form,count,offset) {
12936: if (count > 0) {
1.1059 raeburn 12937: var chosen = (offset+$startcount)+7*(count-1);
12938: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12939: var currtype = form.elements[depitem].type;
12940: if (form.elements[chosen].value == 'dependency') {
12941: document.getElementById('arc_depon_'+count).style.display='block';
12942: form.elements[depitem].options.length = 0;
12943: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12944: for (var i=1; i<=numitems; i++) {
12945: if (i == count) {
12946: continue;
12947: }
1.1059 raeburn 12948: var startelement = $startcount + (i-1) * 7;
12949: for (var j=1; j<6; j++) {
12950: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12951: var item = startelement + j;
12952: if (form.elements[item].type == 'radio') {
12953: if (form.elements[item].checked) {
12954: if (form.elements[item].value == 'display') {
12955: var n = form.elements[depitem].options.length;
12956: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12957: }
12958: }
12959: }
12960: }
12961: }
12962: }
12963: } else {
12964: document.getElementById('arc_depon_'+count).style.display='none';
12965: form.elements[depitem].options.length = 0;
12966: form.elements[depitem].options[0] = new Option('Select','',true,true);
12967: }
1.1059 raeburn 12968: titleCheck(form,count,offset);
1.1056 raeburn 12969: }
12970: }
12971:
12972: function propagateSelect(form,count,offset) {
12973: if (count > 0) {
1.1065 raeburn 12974: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12975: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12976: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12977: if (parents[count].length > 0) {
12978: for (var j=0; j<parents[count].length; j++) {
12979: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12980: }
12981: }
12982: }
12983: }
12984: }
1.1056 raeburn 12985:
12986: function containerSelect(form,count,offset,picked) {
12987: if (count > 0) {
1.1065 raeburn 12988: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12989: if (form.elements[item].type == 'radio') {
12990: if (form.elements[item].value == 'dependency') {
12991: if (form.elements[item+1].type == 'select-one') {
12992: for (var i=0; i<form.elements[item+1].options.length; i++) {
12993: if (form.elements[item+1].options[i].value == picked) {
12994: form.elements[item+1].selectedIndex = i;
12995: break;
12996: }
12997: }
12998: }
12999: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13000: if (parents[count].length > 0) {
13001: for (var j=0; j<parents[count].length; j++) {
13002: containerSelect(form,parents[count][j],offset,picked);
13003: }
13004: }
13005: }
13006: }
13007: }
13008: }
13009: }
13010:
1.1059 raeburn 13011: function titleCheck(form,count,offset) {
13012: if (count > 0) {
13013: var chosen = (offset+$startcount)+7*(count-1);
13014: var depitem = $startcount + ((count-1) * 7) + 2;
13015: var currtype = form.elements[depitem].type;
13016: if (form.elements[chosen].value == 'display') {
13017: document.getElementById('arc_title_'+count).style.display='block';
13018: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13019: document.getElementById('archive_title_'+count).value=maintitle;
13020: }
13021: } else {
13022: document.getElementById('arc_title_'+count).style.display='none';
13023: if (currtype == 'text') {
13024: document.getElementById('archive_title_'+count).value='';
13025: }
13026: }
13027: }
13028: return;
13029: }
13030:
1.1055 raeburn 13031: // ]]>
13032: </script>
13033: END
13034: return $scripttag;
13035: }
13036:
13037: sub process_extracted_files {
1.1067 raeburn 13038: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13039: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 13040: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13041: my @ids=&Apache::lonnet::current_machine_ids();
13042: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13043: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13044: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13045: if (grep(/^\Q$docuhome\E$/,@ids)) {
13046: $prefix = &LONCAPA::propath($docudom,$docuname);
13047: $pathtocheck = "$dir_root/$destination";
13048: $dir = $dir_root;
13049: $ishome = 1;
13050: } else {
13051: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13052: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 13053: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13054: }
13055: my $currdir = "$dir_root/$destination";
13056: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13057: if ($env{'form.folderpath'}) {
13058: my @items = split('&',$env{'form.folderpath'});
13059: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 13060: if ($env{'form.folderpath'} =~ /\:1$/) {
13061: $containers{'0'}='page';
13062: } else {
13063: $containers{'0'}='sequence';
13064: }
1.1055 raeburn 13065: }
13066: my @archdirs = &get_env_multiple('form.archive_directory');
13067: if ($numitems) {
13068: for (my $i=1; $i<=$numitems; $i++) {
13069: my $path = $env{'form.archive_content_'.$i};
13070: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13071: my $item = $1;
13072: $toplevelitems{$item} = $i;
13073: if (grep(/^\Q$i\E$/,@archdirs)) {
13074: $is_dir{$item} = 1;
13075: }
13076: }
13077: }
13078: }
1.1067 raeburn 13079: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13080: if (keys(%toplevelitems) > 0) {
13081: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13082: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13083: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13084: }
1.1066 raeburn 13085: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13086: if ($numitems) {
13087: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 13088: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13089: my $path = $env{'form.archive_content_'.$i};
13090: if ($path =~ /^\Q$pathtocheck\E/) {
13091: if ($env{'form.archive_'.$i} eq 'discard') {
13092: if ($prefix ne '' && $path ne '') {
13093: if (-e $prefix.$path) {
1.1066 raeburn 13094: if ((@archdirs > 0) &&
13095: (grep(/^\Q$i\E$/,@archdirs))) {
13096: $todeletedir{$prefix.$path} = 1;
13097: } else {
13098: $todelete{$prefix.$path} = 1;
13099: }
1.1055 raeburn 13100: }
13101: }
13102: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13103: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13104: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13105: $docstitle = $env{'form.archive_title_'.$i};
13106: if ($docstitle eq '') {
13107: $docstitle = $title;
13108: }
1.1055 raeburn 13109: $outer = 0;
1.1056 raeburn 13110: if (ref($dirorder{$i}) eq 'ARRAY') {
13111: if (@{$dirorder{$i}} > 0) {
13112: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13113: if ($env{'form.archive_'.$item} eq 'display') {
13114: $outer = $item;
13115: last;
13116: }
13117: }
13118: }
13119: }
13120: my ($errtext,$fatal) =
13121: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13122: '/'.$folders{$outer}.'.'.
13123: $containers{$outer});
13124: next if ($fatal);
13125: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13126: if ($context eq 'coursedocs') {
1.1056 raeburn 13127: $mapinner{$i} = time;
1.1055 raeburn 13128: $folders{$i} = 'default_'.$mapinner{$i};
13129: $containers{$i} = 'sequence';
13130: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13131: $folders{$i}.'.'.$containers{$i};
13132: my $newidx = &LONCAPA::map::getresidx();
13133: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13134: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13135: push(@LONCAPA::map::order,$newidx);
13136: my ($outtext,$errtext) =
13137: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13138: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 13139: '.'.$containers{$outer},1,1);
1.1056 raeburn 13140: $newseqid{$i} = $newidx;
1.1067 raeburn 13141: unless ($errtext) {
1.1075.2.128 raeburn 13142: $result .= '<li>'.&mt('Folder: [_1] added to course',
13143: &HTML::Entities::encode($docstitle,'<>&"'))..
13144: '</li>'."\n";
1.1067 raeburn 13145: }
1.1055 raeburn 13146: }
13147: } else {
13148: if ($context eq 'coursedocs') {
13149: my $newidx=&LONCAPA::map::getresidx();
13150: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13151: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13152: $title;
1.1075.2.128 raeburn 13153: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13154: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13155: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 13156: }
1.1075.2.128 raeburn 13157: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13158: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13159: }
13160: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13161: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13162: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13163: unless ($ishome) {
13164: my $fetch = "$newdest{$i}/$title";
13165: $fetch =~ s/^\Q$prefix$dir\E//;
13166: $prompttofetch{$fetch} = 1;
13167: }
13168: }
13169: }
13170: $LONCAPA::map::resources[$newidx]=
13171: $docstitle.':'.$url.':false:normal:res';
13172: push(@LONCAPA::map::order, $newidx);
13173: my ($outtext,$errtext)=
13174: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13175: $docuname.'/'.$folders{$outer}.
13176: '.'.$containers{$outer},1,1);
13177: unless ($errtext) {
13178: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13179: $result .= '<li>'.&mt('File: [_1] added to course',
13180: &HTML::Entities::encode($docstitle,'<>&"')).
13181: '</li>'."\n";
13182: }
1.1067 raeburn 13183: }
1.1075.2.128 raeburn 13184: } else {
13185: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13186: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 13187: }
1.1055 raeburn 13188: }
13189: }
1.1075.2.11 raeburn 13190: }
13191: } else {
1.1075.2.128 raeburn 13192: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13193: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 13194: }
13195: }
13196: for (my $i=1; $i<=$numitems; $i++) {
13197: next unless ($env{'form.archive_'.$i} eq 'dependency');
13198: my $path = $env{'form.archive_content_'.$i};
13199: if ($path =~ /^\Q$pathtocheck\E/) {
13200: my ($title) = ($path =~ m{/([^/]+)$});
13201: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13202: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13203: if (ref($dirorder{$i}) eq 'ARRAY') {
13204: my ($itemidx,$fullpath,$relpath);
13205: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13206: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13207: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 13208: if ($dirorder{$i}->[$j] eq $container) {
13209: $itemidx = $j;
1.1056 raeburn 13210: }
13211: }
1.1075.2.11 raeburn 13212: }
13213: if ($itemidx eq '') {
13214: $itemidx = 0;
13215: }
13216: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13217: if ($mapinner{$referrer{$i}}) {
13218: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13219: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13220: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13221: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13222: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13223: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13224: if (!-e $fullpath) {
13225: mkdir($fullpath,0755);
1.1056 raeburn 13226: }
13227: }
1.1075.2.11 raeburn 13228: } else {
13229: last;
1.1056 raeburn 13230: }
1.1075.2.11 raeburn 13231: }
13232: }
13233: } elsif ($newdest{$referrer{$i}}) {
13234: $fullpath = $newdest{$referrer{$i}};
13235: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13236: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13237: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13238: last;
13239: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13240: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13241: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13242: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13243: if (!-e $fullpath) {
13244: mkdir($fullpath,0755);
1.1056 raeburn 13245: }
13246: }
1.1075.2.11 raeburn 13247: } else {
13248: last;
1.1056 raeburn 13249: }
1.1075.2.11 raeburn 13250: }
13251: }
13252: if ($fullpath ne '') {
13253: if (-e "$prefix$path") {
1.1075.2.128 raeburn 13254: unless (rename("$prefix$path","$fullpath/$title")) {
13255: $warning .= &mt('Failed to rename dependency').'<br />';
13256: }
1.1075.2.11 raeburn 13257: }
13258: if (-e "$fullpath/$title") {
13259: my $showpath;
13260: if ($relpath ne '') {
13261: $showpath = "$relpath/$title";
13262: } else {
13263: $showpath = "/$title";
1.1056 raeburn 13264: }
1.1075.2.128 raeburn 13265: $result .= '<li>'.&mt('[_1] included as a dependency',
13266: &HTML::Entities::encode($showpath,'<>&"')).
13267: '</li>'."\n";
13268: unless ($ishome) {
13269: my $fetch = "$fullpath/$title";
13270: $fetch =~ s/^\Q$prefix$dir\E//;
13271: $prompttofetch{$fetch} = 1;
13272: }
1.1055 raeburn 13273: }
13274: }
13275: }
1.1075.2.11 raeburn 13276: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13277: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 13278: &HTML::Entities::encode($path,'<>&"'),
13279: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13280: '<br />';
1.1055 raeburn 13281: }
13282: } else {
1.1075.2.128 raeburn 13283: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13284: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13285: }
13286: }
13287: if (keys(%todelete)) {
13288: foreach my $key (keys(%todelete)) {
13289: unlink($key);
1.1066 raeburn 13290: }
13291: }
13292: if (keys(%todeletedir)) {
13293: foreach my $key (keys(%todeletedir)) {
13294: rmdir($key);
13295: }
13296: }
13297: foreach my $dir (sort(keys(%is_dir))) {
13298: if (($pathtocheck ne '') && ($dir ne '')) {
13299: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13300: }
13301: }
1.1067 raeburn 13302: if ($result ne '') {
13303: $output .= '<ul>'."\n".
13304: $result."\n".
13305: '</ul>';
13306: }
13307: unless ($ishome) {
13308: my $replicationfail;
13309: foreach my $item (keys(%prompttofetch)) {
13310: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13311: unless ($fetchresult eq 'ok') {
13312: $replicationfail .= '<li>'.$item.'</li>'."\n";
13313: }
13314: }
13315: if ($replicationfail) {
13316: $output .= '<p class="LC_error">'.
13317: &mt('Course home server failed to retrieve:').'<ul>'.
13318: $replicationfail.
13319: '</ul></p>';
13320: }
13321: }
1.1055 raeburn 13322: } else {
13323: $warning = &mt('No items found in archive.');
13324: }
13325: if ($error) {
13326: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13327: $error.'</p>'."\n";
13328: }
13329: if ($warning) {
13330: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13331: }
13332: return $output;
13333: }
13334:
1.1066 raeburn 13335: sub cleanup_empty_dirs {
13336: my ($path) = @_;
13337: if (($path ne '') && (-d $path)) {
13338: if (opendir(my $dirh,$path)) {
13339: my @dircontents = grep(!/^\./,readdir($dirh));
13340: my $numitems = 0;
13341: foreach my $item (@dircontents) {
13342: if (-d "$path/$item") {
1.1075.2.28 raeburn 13343: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13344: if (-e "$path/$item") {
13345: $numitems ++;
13346: }
13347: } else {
13348: $numitems ++;
13349: }
13350: }
13351: if ($numitems == 0) {
13352: rmdir($path);
13353: }
13354: closedir($dirh);
13355: }
13356: }
13357: return;
13358: }
13359:
1.41 ng 13360: =pod
1.45 matthew 13361:
1.1075.2.56 raeburn 13362: =item * &get_folder_hierarchy()
1.1068 raeburn 13363:
13364: Provides hierarchy of names of folders/sub-folders containing the current
13365: item,
13366:
13367: Inputs: 3
13368: - $navmap - navmaps object
13369:
13370: - $map - url for map (either the trigger itself, or map containing
13371: the resource, which is the trigger).
13372:
13373: - $showitem - 1 => show title for map itself; 0 => do not show.
13374:
13375: Outputs: 1 @pathitems - array of folder/subfolder names.
13376:
13377: =cut
13378:
13379: sub get_folder_hierarchy {
13380: my ($navmap,$map,$showitem) = @_;
13381: my @pathitems;
13382: if (ref($navmap)) {
13383: my $mapres = $navmap->getResourceByUrl($map);
13384: if (ref($mapres)) {
13385: my $pcslist = $mapres->map_hierarchy();
13386: if ($pcslist ne '') {
13387: my @pcs = split(/,/,$pcslist);
13388: foreach my $pc (@pcs) {
13389: if ($pc == 1) {
1.1075.2.38 raeburn 13390: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13391: } else {
13392: my $res = $navmap->getByMapPc($pc);
13393: if (ref($res)) {
13394: my $title = $res->compTitle();
13395: $title =~ s/\W+/_/g;
13396: if ($title ne '') {
13397: push(@pathitems,$title);
13398: }
13399: }
13400: }
13401: }
13402: }
1.1071 raeburn 13403: if ($showitem) {
13404: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13405: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13406: } else {
13407: my $maptitle = $mapres->compTitle();
13408: $maptitle =~ s/\W+/_/g;
13409: if ($maptitle ne '') {
13410: push(@pathitems,$maptitle);
13411: }
1.1068 raeburn 13412: }
13413: }
13414: }
13415: }
13416: return @pathitems;
13417: }
13418:
13419: =pod
13420:
1.1015 raeburn 13421: =item * &get_turnedin_filepath()
13422:
13423: Determines path in a user's portfolio file for storage of files uploaded
13424: to a specific essayresponse or dropbox item.
13425:
13426: Inputs: 3 required + 1 optional.
13427: $symb is symb for resource, $uname and $udom are for current user (required).
13428: $caller is optional (can be "submission", if routine is called when storing
13429: an upoaded file when "Submit Answer" button was pressed).
13430:
13431: Returns array containing $path and $multiresp.
13432: $path is path in portfolio. $multiresp is 1 if this resource contains more
13433: than one file upload item. Callers of routine should append partid as a
13434: subdirectory to $path in cases where $multiresp is 1.
13435:
13436: Called by: homework/essayresponse.pm and homework/structuretags.pm
13437:
13438: =cut
13439:
13440: sub get_turnedin_filepath {
13441: my ($symb,$uname,$udom,$caller) = @_;
13442: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13443: my $turnindir;
13444: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13445: $turnindir = $userhash{'turnindir'};
13446: my ($path,$multiresp);
13447: if ($turnindir eq '') {
13448: if ($caller eq 'submission') {
13449: $turnindir = &mt('turned in');
13450: $turnindir =~ s/\W+/_/g;
13451: my %newhash = (
13452: 'turnindir' => $turnindir,
13453: );
13454: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13455: }
13456: }
13457: if ($turnindir ne '') {
13458: $path = '/'.$turnindir.'/';
13459: my ($multipart,$turnin,@pathitems);
13460: my $navmap = Apache::lonnavmaps::navmap->new();
13461: if (defined($navmap)) {
13462: my $mapres = $navmap->getResourceByUrl($map);
13463: if (ref($mapres)) {
13464: my $pcslist = $mapres->map_hierarchy();
13465: if ($pcslist ne '') {
13466: foreach my $pc (split(/,/,$pcslist)) {
13467: my $res = $navmap->getByMapPc($pc);
13468: if (ref($res)) {
13469: my $title = $res->compTitle();
13470: $title =~ s/\W+/_/g;
13471: if ($title ne '') {
1.1075.2.48 raeburn 13472: if (($pc > 1) && (length($title) > 12)) {
13473: $title = substr($title,0,12);
13474: }
1.1015 raeburn 13475: push(@pathitems,$title);
13476: }
13477: }
13478: }
13479: }
13480: my $maptitle = $mapres->compTitle();
13481: $maptitle =~ s/\W+/_/g;
13482: if ($maptitle ne '') {
1.1075.2.48 raeburn 13483: if (length($maptitle) > 12) {
13484: $maptitle = substr($maptitle,0,12);
13485: }
1.1015 raeburn 13486: push(@pathitems,$maptitle);
13487: }
13488: unless ($env{'request.state'} eq 'construct') {
13489: my $res = $navmap->getBySymb($symb);
13490: if (ref($res)) {
13491: my $partlist = $res->parts();
13492: my $totaluploads = 0;
13493: if (ref($partlist) eq 'ARRAY') {
13494: foreach my $part (@{$partlist}) {
13495: my @types = $res->responseType($part);
13496: my @ids = $res->responseIds($part);
13497: for (my $i=0; $i < scalar(@ids); $i++) {
13498: if ($types[$i] eq 'essay') {
13499: my $partid = $part.'_'.$ids[$i];
13500: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13501: $totaluploads ++;
13502: }
13503: }
13504: }
13505: }
13506: if ($totaluploads > 1) {
13507: $multiresp = 1;
13508: }
13509: }
13510: }
13511: }
13512: } else {
13513: return;
13514: }
13515: } else {
13516: return;
13517: }
13518: my $restitle=&Apache::lonnet::gettitle($symb);
13519: $restitle =~ s/\W+/_/g;
13520: if ($restitle eq '') {
13521: $restitle = ($resurl =~ m{/[^/]+$});
13522: if ($restitle eq '') {
13523: $restitle = time;
13524: }
13525: }
1.1075.2.48 raeburn 13526: if (length($restitle) > 12) {
13527: $restitle = substr($restitle,0,12);
13528: }
1.1015 raeburn 13529: push(@pathitems,$restitle);
13530: $path .= join('/',@pathitems);
13531: }
13532: return ($path,$multiresp);
13533: }
13534:
13535: =pod
13536:
1.464 albertel 13537: =back
1.41 ng 13538:
1.112 bowersj2 13539: =head1 CSV Upload/Handling functions
1.38 albertel 13540:
1.41 ng 13541: =over 4
13542:
1.648 raeburn 13543: =item * &upfile_store($r)
1.41 ng 13544:
13545: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13546: needs $env{'form.upfile'}
1.41 ng 13547: returns $datatoken to be put into hidden field
13548:
13549: =cut
1.31 albertel 13550:
13551: sub upfile_store {
13552: my $r=shift;
1.258 albertel 13553: $env{'form.upfile'}=~s/\r/\n/gs;
13554: $env{'form.upfile'}=~s/\f/\n/gs;
13555: $env{'form.upfile'}=~s/\n+/\n/gs;
13556: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13557:
1.1075.2.128 raeburn 13558: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13559: '_enroll_'.$env{'request.course.id'}.'_'.
13560: time.'_'.$$);
13561: return if ($datatoken eq '');
13562:
1.31 albertel 13563: {
1.158 raeburn 13564: my $datafile = $r->dir_config('lonDaemons').
13565: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13566: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13567: print $fh $env{'form.upfile'};
1.158 raeburn 13568: close($fh);
13569: }
1.31 albertel 13570: }
13571: return $datatoken;
13572: }
13573:
1.56 matthew 13574: =pod
13575:
1.1075.2.128 raeburn 13576: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13577:
13578: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13579: $datatoken is the name to assign to the temporary file.
1.258 albertel 13580: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13581:
13582: =cut
1.31 albertel 13583:
13584: sub load_tmp_file {
1.1075.2.128 raeburn 13585: my ($r,$datatoken) = @_;
13586: return if ($datatoken eq '');
1.31 albertel 13587: my @studentdata=();
13588: {
1.158 raeburn 13589: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13590: '/tmp/'.$datatoken.'.tmp';
13591: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13592: @studentdata=<$fh>;
13593: close($fh);
13594: }
1.31 albertel 13595: }
1.258 albertel 13596: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13597: }
13598:
1.1075.2.128 raeburn 13599: sub valid_datatoken {
13600: my ($datatoken) = @_;
1.1075.2.131 raeburn 13601: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13602: return $datatoken;
13603: }
13604: return;
13605: }
13606:
1.56 matthew 13607: =pod
13608:
1.648 raeburn 13609: =item * &upfile_record_sep()
1.41 ng 13610:
13611: Separate uploaded file into records
13612: returns array of records,
1.258 albertel 13613: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13614:
13615: =cut
1.31 albertel 13616:
13617: sub upfile_record_sep {
1.258 albertel 13618: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13619: } else {
1.248 albertel 13620: my @records;
1.258 albertel 13621: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13622: if ($line=~/^\s*$/) { next; }
13623: push(@records,$line);
13624: }
13625: return @records;
1.31 albertel 13626: }
13627: }
13628:
1.56 matthew 13629: =pod
13630:
1.648 raeburn 13631: =item * &record_sep($record)
1.41 ng 13632:
1.258 albertel 13633: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13634:
13635: =cut
13636:
1.263 www 13637: sub takeleft {
13638: my $index=shift;
13639: return substr('0000'.$index,-4,4);
13640: }
13641:
1.31 albertel 13642: sub record_sep {
13643: my $record=shift;
13644: my %components=();
1.258 albertel 13645: if ($env{'form.upfiletype'} eq 'xml') {
13646: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13647: my $i=0;
1.356 albertel 13648: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13649: $field=~s/^(\"|\')//;
13650: $field=~s/(\"|\')$//;
1.263 www 13651: $components{&takeleft($i)}=$field;
1.31 albertel 13652: $i++;
13653: }
1.258 albertel 13654: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13655: my $i=0;
1.356 albertel 13656: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13657: $field=~s/^(\"|\')//;
13658: $field=~s/(\"|\')$//;
1.263 www 13659: $components{&takeleft($i)}=$field;
1.31 albertel 13660: $i++;
13661: }
13662: } else {
1.561 www 13663: my $separator=',';
1.480 banghart 13664: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13665: $separator=';';
1.480 banghart 13666: }
1.31 albertel 13667: my $i=0;
1.561 www 13668: # the character we are looking for to indicate the end of a quote or a record
13669: my $looking_for=$separator;
13670: # do not add the characters to the fields
13671: my $ignore=0;
13672: # we just encountered a separator (or the beginning of the record)
13673: my $just_found_separator=1;
13674: # store the field we are working on here
13675: my $field='';
13676: # work our way through all characters in record
13677: foreach my $character ($record=~/(.)/g) {
13678: if ($character eq $looking_for) {
13679: if ($character ne $separator) {
13680: # Found the end of a quote, again looking for separator
13681: $looking_for=$separator;
13682: $ignore=1;
13683: } else {
13684: # Found a separator, store away what we got
13685: $components{&takeleft($i)}=$field;
13686: $i++;
13687: $just_found_separator=1;
13688: $ignore=0;
13689: $field='';
13690: }
13691: next;
13692: }
13693: # single or double quotation marks after a separator indicate beginning of a quote
13694: # we are now looking for the end of the quote and need to ignore separators
13695: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13696: $looking_for=$character;
13697: next;
13698: }
13699: # ignore would be true after we reached the end of a quote
13700: if ($ignore) { next; }
13701: if (($just_found_separator) && ($character=~/\s/)) { next; }
13702: $field.=$character;
13703: $just_found_separator=0;
1.31 albertel 13704: }
1.561 www 13705: # catch the very last entry, since we never encountered the separator
13706: $components{&takeleft($i)}=$field;
1.31 albertel 13707: }
13708: return %components;
13709: }
13710:
1.144 matthew 13711: ######################################################
13712: ######################################################
13713:
1.56 matthew 13714: =pod
13715:
1.648 raeburn 13716: =item * &upfile_select_html()
1.41 ng 13717:
1.144 matthew 13718: Return HTML code to select a file from the users machine and specify
13719: the file type.
1.41 ng 13720:
13721: =cut
13722:
1.144 matthew 13723: ######################################################
13724: ######################################################
1.31 albertel 13725: sub upfile_select_html {
1.144 matthew 13726: my %Types = (
13727: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13728: semisv => &mt('Semicolon separated values'),
1.144 matthew 13729: space => &mt('Space separated'),
13730: tab => &mt('Tabulator separated'),
13731: # xml => &mt('HTML/XML'),
13732: );
13733: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13734: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13735: foreach my $type (sort(keys(%Types))) {
13736: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13737: }
13738: $Str .= "</select>\n";
13739: return $Str;
1.31 albertel 13740: }
13741:
1.301 albertel 13742: sub get_samples {
13743: my ($records,$toget) = @_;
13744: my @samples=({});
13745: my $got=0;
13746: foreach my $rec (@$records) {
13747: my %temp = &record_sep($rec);
13748: if (! grep(/\S/, values(%temp))) { next; }
13749: if (%temp) {
13750: $samples[$got]=\%temp;
13751: $got++;
13752: if ($got == $toget) { last; }
13753: }
13754: }
13755: return \@samples;
13756: }
13757:
1.144 matthew 13758: ######################################################
13759: ######################################################
13760:
1.56 matthew 13761: =pod
13762:
1.648 raeburn 13763: =item * &csv_print_samples($r,$records)
1.41 ng 13764:
13765: Prints a table of sample values from each column uploaded $r is an
13766: Apache Request ref, $records is an arrayref from
13767: &Apache::loncommon::upfile_record_sep
13768:
13769: =cut
13770:
1.144 matthew 13771: ######################################################
13772: ######################################################
1.31 albertel 13773: sub csv_print_samples {
13774: my ($r,$records) = @_;
1.662 bisitz 13775: my $samples = &get_samples($records,5);
1.301 albertel 13776:
1.594 raeburn 13777: $r->print(&mt('Samples').'<br />'.&start_data_table().
13778: &start_data_table_header_row());
1.356 albertel 13779: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13780: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13781: $r->print(&end_data_table_header_row());
1.301 albertel 13782: foreach my $hash (@$samples) {
1.594 raeburn 13783: $r->print(&start_data_table_row());
1.356 albertel 13784: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13785: $r->print('<td>');
1.356 albertel 13786: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13787: $r->print('</td>');
13788: }
1.594 raeburn 13789: $r->print(&end_data_table_row());
1.31 albertel 13790: }
1.594 raeburn 13791: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13792: }
13793:
1.144 matthew 13794: ######################################################
13795: ######################################################
13796:
1.56 matthew 13797: =pod
13798:
1.648 raeburn 13799: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13800:
13801: Prints a table to create associations between values and table columns.
1.144 matthew 13802:
1.41 ng 13803: $r is an Apache Request ref,
13804: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13805: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13806:
13807: =cut
13808:
1.144 matthew 13809: ######################################################
13810: ######################################################
1.31 albertel 13811: sub csv_print_select_table {
13812: my ($r,$records,$d) = @_;
1.301 albertel 13813: my $i=0;
13814: my $samples = &get_samples($records,1);
1.144 matthew 13815: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13816: &start_data_table().&start_data_table_header_row().
1.144 matthew 13817: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13818: '<th>'.&mt('Column').'</th>'.
13819: &end_data_table_header_row()."\n");
1.356 albertel 13820: foreach my $array_ref (@$d) {
13821: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13822: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13823:
1.875 bisitz 13824: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13825: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13826: $r->print('<option value="none"></option>');
1.356 albertel 13827: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13828: $r->print('<option value="'.$sample.'"'.
13829: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13830: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13831: }
1.594 raeburn 13832: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13833: $i++;
13834: }
1.594 raeburn 13835: $r->print(&end_data_table());
1.31 albertel 13836: $i--;
13837: return $i;
13838: }
1.56 matthew 13839:
1.144 matthew 13840: ######################################################
13841: ######################################################
13842:
1.56 matthew 13843: =pod
1.31 albertel 13844:
1.648 raeburn 13845: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13846:
13847: Prints a table of sample values from the upload and can make associate samples to internal names.
13848:
13849: $r is an Apache Request ref,
13850: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13851: $d is an array of 2 element arrays (internal name, displayed name)
13852:
13853: =cut
13854:
1.144 matthew 13855: ######################################################
13856: ######################################################
1.31 albertel 13857: sub csv_samples_select_table {
13858: my ($r,$records,$d) = @_;
13859: my $i=0;
1.144 matthew 13860: #
1.662 bisitz 13861: my $max_samples = 5;
13862: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13863: $r->print(&start_data_table().
13864: &start_data_table_header_row().'<th>'.
13865: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13866: &end_data_table_header_row());
1.301 albertel 13867:
13868: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13869: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13870: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13871: foreach my $option (@$d) {
13872: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13873: $r->print('<option value="'.$value.'"'.
1.253 albertel 13874: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13875: $display.'</option>');
1.31 albertel 13876: }
13877: $r->print('</select></td><td>');
1.662 bisitz 13878: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13879: if (defined($samples->[$line]{$key})) {
13880: $r->print($samples->[$line]{$key}."<br />\n");
13881: }
13882: }
1.594 raeburn 13883: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13884: $i++;
13885: }
1.594 raeburn 13886: $r->print(&end_data_table());
1.31 albertel 13887: $i--;
13888: return($i);
1.115 matthew 13889: }
13890:
1.144 matthew 13891: ######################################################
13892: ######################################################
13893:
1.115 matthew 13894: =pod
13895:
1.648 raeburn 13896: =item * &clean_excel_name($name)
1.115 matthew 13897:
13898: Returns a replacement for $name which does not contain any illegal characters.
13899:
13900: =cut
13901:
1.144 matthew 13902: ######################################################
13903: ######################################################
1.115 matthew 13904: sub clean_excel_name {
13905: my ($name) = @_;
13906: $name =~ s/[:\*\?\/\\]//g;
13907: if (length($name) > 31) {
13908: $name = substr($name,0,31);
13909: }
13910: return $name;
1.25 albertel 13911: }
1.84 albertel 13912:
1.85 albertel 13913: =pod
13914:
1.648 raeburn 13915: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13916:
13917: Returns either 1 or undef
13918:
13919: 1 if the part is to be hidden, undef if it is to be shown
13920:
13921: Arguments are:
13922:
13923: $id the id of the part to be checked
13924: $symb, optional the symb of the resource to check
13925: $udom, optional the domain of the user to check for
13926: $uname, optional the username of the user to check for
13927:
13928: =cut
1.84 albertel 13929:
13930: sub check_if_partid_hidden {
13931: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13932: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13933: $symb,$udom,$uname);
1.141 albertel 13934: my $truth=1;
13935: #if the string starts with !, then the list is the list to show not hide
13936: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13937: my @hiddenlist=split(/,/,$hiddenparts);
13938: foreach my $checkid (@hiddenlist) {
1.141 albertel 13939: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13940: }
1.141 albertel 13941: return !$truth;
1.84 albertel 13942: }
1.127 matthew 13943:
1.138 matthew 13944:
13945: ############################################################
13946: ############################################################
13947:
13948: =pod
13949:
1.157 matthew 13950: =back
13951:
1.138 matthew 13952: =head1 cgi-bin script and graphing routines
13953:
1.157 matthew 13954: =over 4
13955:
1.648 raeburn 13956: =item * &get_cgi_id()
1.138 matthew 13957:
13958: Inputs: none
13959:
13960: Returns an id which can be used to pass environment variables
13961: to various cgi-bin scripts. These environment variables will
13962: be removed from the users environment after a given time by
13963: the routine &Apache::lonnet::transfer_profile_to_env.
13964:
13965: =cut
13966:
13967: ############################################################
13968: ############################################################
1.152 albertel 13969: my $uniq=0;
1.136 matthew 13970: sub get_cgi_id {
1.154 albertel 13971: $uniq=($uniq+1)%100000;
1.280 albertel 13972: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13973: }
13974:
1.127 matthew 13975: ############################################################
13976: ############################################################
13977:
13978: =pod
13979:
1.648 raeburn 13980: =item * &DrawBarGraph()
1.127 matthew 13981:
1.138 matthew 13982: Facilitates the plotting of data in a (stacked) bar graph.
13983: Puts plot definition data into the users environment in order for
13984: graph.png to plot it. Returns an <img> tag for the plot.
13985: The bars on the plot are labeled '1','2',...,'n'.
13986:
13987: Inputs:
13988:
13989: =over 4
13990:
13991: =item $Title: string, the title of the plot
13992:
13993: =item $xlabel: string, text describing the X-axis of the plot
13994:
13995: =item $ylabel: string, text describing the Y-axis of the plot
13996:
13997: =item $Max: scalar, the maximum Y value to use in the plot
13998: If $Max is < any data point, the graph will not be rendered.
13999:
1.140 matthew 14000: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14001: they are plotted. If undefined, default values will be used.
14002:
1.178 matthew 14003: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14004:
1.138 matthew 14005: =item @Values: An array of array references. Each array reference holds data
14006: to be plotted in a stacked bar chart.
14007:
1.239 matthew 14008: =item If the final element of @Values is a hash reference the key/value
14009: pairs will be added to the graph definition.
14010:
1.138 matthew 14011: =back
14012:
14013: Returns:
14014:
14015: An <img> tag which references graph.png and the appropriate identifying
14016: information for the plot.
14017:
1.127 matthew 14018: =cut
14019:
14020: ############################################################
14021: ############################################################
1.134 matthew 14022: sub DrawBarGraph {
1.178 matthew 14023: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14024: #
14025: if (! defined($colors)) {
14026: $colors = ['#33ff00',
14027: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14028: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14029: ];
14030: }
1.228 matthew 14031: my $extra_settings = {};
14032: if (ref($Values[-1]) eq 'HASH') {
14033: $extra_settings = pop(@Values);
14034: }
1.127 matthew 14035: #
1.136 matthew 14036: my $identifier = &get_cgi_id();
14037: my $id = 'cgi.'.$identifier;
1.129 matthew 14038: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14039: return '';
14040: }
1.225 matthew 14041: #
14042: my @Labels;
14043: if (defined($labels)) {
14044: @Labels = @$labels;
14045: } else {
14046: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 14047: push(@Labels,$i+1);
1.225 matthew 14048: }
14049: }
14050: #
1.129 matthew 14051: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14052: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14053: my %ValuesHash;
14054: my $NumSets=1;
14055: foreach my $array (@Values) {
14056: next if (! ref($array));
1.136 matthew 14057: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14058: join(',',@$array);
1.129 matthew 14059: }
1.127 matthew 14060: #
1.136 matthew 14061: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14062: if ($NumBars < 3) {
14063: $width = 120+$NumBars*32;
1.220 matthew 14064: $xskip = 1;
1.225 matthew 14065: $bar_width = 30;
14066: } elsif ($NumBars < 5) {
14067: $width = 120+$NumBars*20;
14068: $xskip = 1;
14069: $bar_width = 20;
1.220 matthew 14070: } elsif ($NumBars < 10) {
1.136 matthew 14071: $width = 120+$NumBars*15;
14072: $xskip = 1;
14073: $bar_width = 15;
14074: } elsif ($NumBars <= 25) {
14075: $width = 120+$NumBars*11;
14076: $xskip = 5;
14077: $bar_width = 8;
14078: } elsif ($NumBars <= 50) {
14079: $width = 120+$NumBars*8;
14080: $xskip = 5;
14081: $bar_width = 4;
14082: } else {
14083: $width = 120+$NumBars*8;
14084: $xskip = 5;
14085: $bar_width = 4;
14086: }
14087: #
1.137 matthew 14088: $Max = 1 if ($Max < 1);
14089: if ( int($Max) < $Max ) {
14090: $Max++;
14091: $Max = int($Max);
14092: }
1.127 matthew 14093: $Title = '' if (! defined($Title));
14094: $xlabel = '' if (! defined($xlabel));
14095: $ylabel = '' if (! defined($ylabel));
1.369 www 14096: $ValuesHash{$id.'.title'} = &escape($Title);
14097: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14098: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14099: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14100: $ValuesHash{$id.'.NumBars'} = $NumBars;
14101: $ValuesHash{$id.'.NumSets'} = $NumSets;
14102: $ValuesHash{$id.'.PlotType'} = 'bar';
14103: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14104: $ValuesHash{$id.'.height'} = $height;
14105: $ValuesHash{$id.'.width'} = $width;
14106: $ValuesHash{$id.'.xskip'} = $xskip;
14107: $ValuesHash{$id.'.bar_width'} = $bar_width;
14108: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14109: #
1.228 matthew 14110: # Deal with other parameters
14111: while (my ($key,$value) = each(%$extra_settings)) {
14112: $ValuesHash{$id.'.'.$key} = $value;
14113: }
14114: #
1.646 raeburn 14115: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14116: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14117: }
14118:
14119: ############################################################
14120: ############################################################
14121:
14122: =pod
14123:
1.648 raeburn 14124: =item * &DrawXYGraph()
1.137 matthew 14125:
1.138 matthew 14126: Facilitates the plotting of data in an XY graph.
14127: Puts plot definition data into the users environment in order for
14128: graph.png to plot it. Returns an <img> tag for the plot.
14129:
14130: Inputs:
14131:
14132: =over 4
14133:
14134: =item $Title: string, the title of the plot
14135:
14136: =item $xlabel: string, text describing the X-axis of the plot
14137:
14138: =item $ylabel: string, text describing the Y-axis of the plot
14139:
14140: =item $Max: scalar, the maximum Y value to use in the plot
14141: If $Max is < any data point, the graph will not be rendered.
14142:
14143: =item $colors: Array ref containing the hex color codes for the data to be
14144: plotted in. If undefined, default values will be used.
14145:
14146: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14147:
14148: =item $Ydata: Array ref containing Array refs.
1.185 www 14149: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14150:
14151: =item %Values: hash indicating or overriding any default values which are
14152: passed to graph.png.
14153: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14154:
14155: =back
14156:
14157: Returns:
14158:
14159: An <img> tag which references graph.png and the appropriate identifying
14160: information for the plot.
14161:
1.137 matthew 14162: =cut
14163:
14164: ############################################################
14165: ############################################################
14166: sub DrawXYGraph {
14167: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14168: #
14169: # Create the identifier for the graph
14170: my $identifier = &get_cgi_id();
14171: my $id = 'cgi.'.$identifier;
14172: #
14173: $Title = '' if (! defined($Title));
14174: $xlabel = '' if (! defined($xlabel));
14175: $ylabel = '' if (! defined($ylabel));
14176: my %ValuesHash =
14177: (
1.369 www 14178: $id.'.title' => &escape($Title),
14179: $id.'.xlabel' => &escape($xlabel),
14180: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14181: $id.'.y_max_value'=> $Max,
14182: $id.'.labels' => join(',',@$Xlabels),
14183: $id.'.PlotType' => 'XY',
14184: );
14185: #
14186: if (defined($colors) && ref($colors) eq 'ARRAY') {
14187: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14188: }
14189: #
14190: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14191: return '';
14192: }
14193: my $NumSets=1;
1.138 matthew 14194: foreach my $array (@{$Ydata}){
1.137 matthew 14195: next if (! ref($array));
14196: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14197: }
1.138 matthew 14198: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14199: #
14200: # Deal with other parameters
14201: while (my ($key,$value) = each(%Values)) {
14202: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14203: }
14204: #
1.646 raeburn 14205: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14206: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14207: }
14208:
14209: ############################################################
14210: ############################################################
14211:
14212: =pod
14213:
1.648 raeburn 14214: =item * &DrawXYYGraph()
1.138 matthew 14215:
14216: Facilitates the plotting of data in an XY graph with two Y axes.
14217: Puts plot definition data into the users environment in order for
14218: graph.png to plot it. Returns an <img> tag for the plot.
14219:
14220: Inputs:
14221:
14222: =over 4
14223:
14224: =item $Title: string, the title of the plot
14225:
14226: =item $xlabel: string, text describing the X-axis of the plot
14227:
14228: =item $ylabel: string, text describing the Y-axis of the plot
14229:
14230: =item $colors: Array ref containing the hex color codes for the data to be
14231: plotted in. If undefined, default values will be used.
14232:
14233: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14234:
14235: =item $Ydata1: The first data set
14236:
14237: =item $Min1: The minimum value of the left Y-axis
14238:
14239: =item $Max1: The maximum value of the left Y-axis
14240:
14241: =item $Ydata2: The second data set
14242:
14243: =item $Min2: The minimum value of the right Y-axis
14244:
14245: =item $Max2: The maximum value of the left Y-axis
14246:
14247: =item %Values: hash indicating or overriding any default values which are
14248: passed to graph.png.
14249: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14250:
14251: =back
14252:
14253: Returns:
14254:
14255: An <img> tag which references graph.png and the appropriate identifying
14256: information for the plot.
1.136 matthew 14257:
14258: =cut
14259:
14260: ############################################################
14261: ############################################################
1.137 matthew 14262: sub DrawXYYGraph {
14263: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14264: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14265: #
14266: # Create the identifier for the graph
14267: my $identifier = &get_cgi_id();
14268: my $id = 'cgi.'.$identifier;
14269: #
14270: $Title = '' if (! defined($Title));
14271: $xlabel = '' if (! defined($xlabel));
14272: $ylabel = '' if (! defined($ylabel));
14273: my %ValuesHash =
14274: (
1.369 www 14275: $id.'.title' => &escape($Title),
14276: $id.'.xlabel' => &escape($xlabel),
14277: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14278: $id.'.labels' => join(',',@$Xlabels),
14279: $id.'.PlotType' => 'XY',
14280: $id.'.NumSets' => 2,
1.137 matthew 14281: $id.'.two_axes' => 1,
14282: $id.'.y1_max_value' => $Max1,
14283: $id.'.y1_min_value' => $Min1,
14284: $id.'.y2_max_value' => $Max2,
14285: $id.'.y2_min_value' => $Min2,
1.136 matthew 14286: );
14287: #
1.137 matthew 14288: if (defined($colors) && ref($colors) eq 'ARRAY') {
14289: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14290: }
14291: #
14292: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14293: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14294: return '';
14295: }
14296: my $NumSets=1;
1.137 matthew 14297: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14298: next if (! ref($array));
14299: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14300: }
14301: #
14302: # Deal with other parameters
14303: while (my ($key,$value) = each(%Values)) {
14304: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14305: }
14306: #
1.646 raeburn 14307: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14308: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14309: }
14310:
14311: ############################################################
14312: ############################################################
14313:
14314: =pod
14315:
1.157 matthew 14316: =back
14317:
1.139 matthew 14318: =head1 Statistics helper routines?
14319:
14320: Bad place for them but what the hell.
14321:
1.157 matthew 14322: =over 4
14323:
1.648 raeburn 14324: =item * &chartlink()
1.139 matthew 14325:
14326: Returns a link to the chart for a specific student.
14327:
14328: Inputs:
14329:
14330: =over 4
14331:
14332: =item $linktext: The text of the link
14333:
14334: =item $sname: The students username
14335:
14336: =item $sdomain: The students domain
14337:
14338: =back
14339:
1.157 matthew 14340: =back
14341:
1.139 matthew 14342: =cut
14343:
14344: ############################################################
14345: ############################################################
14346: sub chartlink {
14347: my ($linktext, $sname, $sdomain) = @_;
14348: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14349: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14350: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14351: '">'.$linktext.'</a>';
1.153 matthew 14352: }
14353:
14354: #######################################################
14355: #######################################################
14356:
14357: =pod
14358:
14359: =head1 Course Environment Routines
1.157 matthew 14360:
14361: =over 4
1.153 matthew 14362:
1.648 raeburn 14363: =item * &restore_course_settings()
1.153 matthew 14364:
1.648 raeburn 14365: =item * &store_course_settings()
1.153 matthew 14366:
14367: Restores/Store indicated form parameters from the course environment.
14368: Will not overwrite existing values of the form parameters.
14369:
14370: Inputs:
14371: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14372:
14373: a hash ref describing the data to be stored. For example:
14374:
14375: %Save_Parameters = ('Status' => 'scalar',
14376: 'chartoutputmode' => 'scalar',
14377: 'chartoutputdata' => 'scalar',
14378: 'Section' => 'array',
1.373 raeburn 14379: 'Group' => 'array',
1.153 matthew 14380: 'StudentData' => 'array',
14381: 'Maps' => 'array');
14382:
14383: Returns: both routines return nothing
14384:
1.631 raeburn 14385: =back
14386:
1.153 matthew 14387: =cut
14388:
14389: #######################################################
14390: #######################################################
14391: sub store_course_settings {
1.496 albertel 14392: return &store_settings($env{'request.course.id'},@_);
14393: }
14394:
14395: sub store_settings {
1.153 matthew 14396: # save to the environment
14397: # appenv the same items, just to be safe
1.300 albertel 14398: my $udom = $env{'user.domain'};
14399: my $uname = $env{'user.name'};
1.496 albertel 14400: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14401: my %SaveHash;
14402: my %AppHash;
14403: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14404: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14405: my $envname = 'environment.'.$basename;
1.258 albertel 14406: if (exists($env{'form.'.$setting})) {
1.153 matthew 14407: # Save this value away
14408: if ($type eq 'scalar' &&
1.258 albertel 14409: (! exists($env{$envname}) ||
14410: $env{$envname} ne $env{'form.'.$setting})) {
14411: $SaveHash{$basename} = $env{'form.'.$setting};
14412: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14413: } elsif ($type eq 'array') {
14414: my $stored_form;
1.258 albertel 14415: if (ref($env{'form.'.$setting})) {
1.153 matthew 14416: $stored_form = join(',',
14417: map {
1.369 www 14418: &escape($_);
1.258 albertel 14419: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14420: } else {
14421: $stored_form =
1.369 www 14422: &escape($env{'form.'.$setting});
1.153 matthew 14423: }
14424: # Determine if the array contents are the same.
1.258 albertel 14425: if ($stored_form ne $env{$envname}) {
1.153 matthew 14426: $SaveHash{$basename} = $stored_form;
14427: $AppHash{$envname} = $stored_form;
14428: }
14429: }
14430: }
14431: }
14432: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14433: $udom,$uname);
1.153 matthew 14434: if ($put_result !~ /^(ok|delayed)/) {
14435: &Apache::lonnet::logthis('unable to save form parameters, '.
14436: 'got error:'.$put_result);
14437: }
14438: # Make sure these settings stick around in this session, too
1.646 raeburn 14439: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14440: return;
14441: }
14442:
14443: sub restore_course_settings {
1.499 albertel 14444: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14445: }
14446:
14447: sub restore_settings {
14448: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14449: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14450: next if (exists($env{'form.'.$setting}));
1.496 albertel 14451: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14452: '.'.$setting;
1.258 albertel 14453: if (exists($env{$envname})) {
1.153 matthew 14454: if ($type eq 'scalar') {
1.258 albertel 14455: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14456: } elsif ($type eq 'array') {
1.258 albertel 14457: $env{'form.'.$setting} = [
1.153 matthew 14458: map {
1.369 www 14459: &unescape($_);
1.258 albertel 14460: } split(',',$env{$envname})
1.153 matthew 14461: ];
14462: }
14463: }
14464: }
1.127 matthew 14465: }
14466:
1.618 raeburn 14467: #######################################################
14468: #######################################################
14469:
14470: =pod
14471:
14472: =head1 Domain E-mail Routines
14473:
14474: =over 4
14475:
1.648 raeburn 14476: =item * &build_recipient_list()
1.618 raeburn 14477:
1.1075.2.44 raeburn 14478: Build recipient lists for following types of e-mail:
1.766 raeburn 14479: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14480: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14481: module change checking, student/employee ID conflict checks, as
14482: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14483: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14484:
14485: Inputs:
1.1075.2.44 raeburn 14486: defmail (scalar - email address of default recipient),
14487: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14488: requestsmail, updatesmail, or idconflictsmail).
14489:
1.619 raeburn 14490: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14491:
14492: origmail (scalar - email address of recipient from loncapa.conf,
14493: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14494:
1.1075.2.139 raeburn 14495: $requname username of requester (if mailing type is helpdeskmail)
14496:
14497: $requdom domain of requester (if mailing type is helpdeskmail)
14498:
14499: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14500:
1.655 raeburn 14501: Returns: comma separated list of addresses to which to send e-mail.
14502:
14503: =back
1.618 raeburn 14504:
14505: =cut
14506:
14507: ############################################################
14508: ############################################################
14509: sub build_recipient_list {
1.1075.2.139 raeburn 14510: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14511: my @recipients;
1.1075.2.122 raeburn 14512: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14513: my %domconfig =
1.1075.2.122 raeburn 14514: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14515: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14516: if (exists($domconfig{'contacts'}{$mailing})) {
14517: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14518: my @contacts = ('adminemail','supportemail');
14519: foreach my $item (@contacts) {
14520: if ($domconfig{'contacts'}{$mailing}{$item}) {
14521: my $addr = $domconfig{'contacts'}{$item};
14522: if (!grep(/^\Q$addr\E$/,@recipients)) {
14523: push(@recipients,$addr);
14524: }
1.619 raeburn 14525: }
1.1075.2.122 raeburn 14526: }
14527: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14528: if ($mailing eq 'helpdeskmail') {
14529: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14530: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14531: my @ok_bccs;
14532: foreach my $bcc (@bccs) {
14533: $bcc =~ s/^\s+//g;
14534: $bcc =~ s/\s+$//g;
14535: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14536: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14537: push(@ok_bccs,$bcc);
14538: }
14539: }
14540: }
14541: if (@ok_bccs > 0) {
14542: $allbcc = join(', ',@ok_bccs);
14543: }
14544: }
14545: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14546: }
14547: }
1.766 raeburn 14548: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14549: $lastresort = $origmail;
1.618 raeburn 14550: }
1.1075.2.139 raeburn 14551: if ($mailing eq 'helpdeskmail') {
14552: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14553: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14554: my ($inststatus,$inststatus_checked);
14555: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14556: ($env{'user.domain'} ne 'public')) {
14557: $inststatus_checked = 1;
14558: $inststatus = $env{'environment.inststatus'};
14559: }
14560: unless ($inststatus_checked) {
14561: if (($requname ne '') && ($requdom ne '')) {
14562: if (($requname =~ /^$match_username$/) &&
14563: ($requdom =~ /^$match_domain$/) &&
14564: (&Apache::lonnet::domain($requdom))) {
14565: my $requhome = &Apache::lonnet::homeserver($requname,
14566: $requdom);
14567: unless ($requhome eq 'no_host') {
14568: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14569: $inststatus = $userenv{'inststatus'};
14570: $inststatus_checked = 1;
14571: }
14572: }
14573: }
14574: }
14575: unless ($inststatus_checked) {
14576: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14577: my %srch = (srchby => 'email',
14578: srchdomain => $defdom,
14579: srchterm => $reqemail,
14580: srchtype => 'exact');
14581: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14582: foreach my $uname (keys(%srch_results)) {
14583: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14584: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14585: $inststatus_checked = 1;
14586: last;
14587: }
14588: }
14589: unless ($inststatus_checked) {
14590: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14591: if ($dirsrchres eq 'ok') {
14592: foreach my $uname (keys(%srch_results)) {
14593: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14594: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14595: $inststatus_checked = 1;
14596: last;
14597: }
14598: }
14599: }
14600: }
14601: }
14602: }
14603: if ($inststatus ne '') {
14604: foreach my $status (split(/\:/,$inststatus)) {
14605: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14606: my @contacts = ('adminemail','supportemail');
14607: foreach my $item (@contacts) {
14608: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14609: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14610: if (!grep(/^\Q$addr\E$/,@recipients)) {
14611: push(@recipients,$addr);
14612: }
14613: }
14614: }
14615: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14616: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14617: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14618: my @ok_bccs;
14619: foreach my $bcc (@bccs) {
14620: $bcc =~ s/^\s+//g;
14621: $bcc =~ s/\s+$//g;
14622: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14623: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14624: push(@ok_bccs,$bcc);
14625: }
14626: }
14627: }
14628: if (@ok_bccs > 0) {
14629: $allbcc = join(', ',@ok_bccs);
14630: }
14631: }
14632: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14633: last;
14634: }
14635: }
14636: }
14637: }
14638: }
1.619 raeburn 14639: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14640: $lastresort = $origmail;
14641: }
1.1075.2.128 raeburn 14642: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14643: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14644: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14645: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14646: my %what = (
14647: perlvar => 1,
14648: );
14649: my $primary = &Apache::lonnet::domain($defdom,'primary');
14650: if ($primary) {
14651: my $gotaddr;
14652: my ($result,$returnhash) =
14653: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14654: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14655: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14656: $lastresort = $returnhash->{'lonSupportEMail'};
14657: $gotaddr = 1;
14658: }
14659: }
14660: unless ($gotaddr) {
14661: my $uintdom = &Apache::lonnet::internet_dom($primary);
14662: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14663: unless ($uintdom eq $intdom) {
14664: my %domconfig =
14665: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14666: if (ref($domconfig{'contacts'}) eq 'HASH') {
14667: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14668: my @contacts = ('adminemail','supportemail');
14669: foreach my $item (@contacts) {
14670: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14671: my $addr = $domconfig{'contacts'}{$item};
14672: if (!grep(/^\Q$addr\E$/,@recipients)) {
14673: push(@recipients,$addr);
14674: }
14675: }
14676: }
14677: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14678: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14679: }
14680: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14681: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14682: my @ok_bccs;
14683: foreach my $bcc (@bccs) {
14684: $bcc =~ s/^\s+//g;
14685: $bcc =~ s/\s+$//g;
14686: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14687: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14688: push(@ok_bccs,$bcc);
14689: }
14690: }
14691: }
14692: if (@ok_bccs > 0) {
14693: $allbcc = join(', ',@ok_bccs);
14694: }
14695: }
14696: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14697: }
14698: }
14699: }
14700: }
14701: }
14702: }
1.618 raeburn 14703: }
1.688 raeburn 14704: if (defined($defmail)) {
14705: if ($defmail ne '') {
14706: push(@recipients,$defmail);
14707: }
1.618 raeburn 14708: }
14709: if ($otheremails) {
1.619 raeburn 14710: my @others;
14711: if ($otheremails =~ /,/) {
14712: @others = split(/,/,$otheremails);
1.618 raeburn 14713: } else {
1.619 raeburn 14714: push(@others,$otheremails);
14715: }
14716: foreach my $addr (@others) {
14717: if (!grep(/^\Q$addr\E$/,@recipients)) {
14718: push(@recipients,$addr);
14719: }
1.618 raeburn 14720: }
14721: }
1.1075.2.128 raeburn 14722: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14723: if ((!@recipients) && ($lastresort ne '')) {
14724: push(@recipients,$lastresort);
14725: }
14726: } elsif ($lastresort ne '') {
14727: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14728: push(@recipients,$lastresort);
14729: }
14730: }
14731: my $recipientlist = join(',',@recipients);
14732: if (wantarray) {
14733: return ($recipientlist,$allbcc,$addtext);
14734: } else {
14735: return $recipientlist;
14736: }
1.618 raeburn 14737: }
14738:
1.127 matthew 14739: ############################################################
14740: ############################################################
1.154 albertel 14741:
1.655 raeburn 14742: =pod
14743:
14744: =head1 Course Catalog Routines
14745:
14746: =over 4
14747:
14748: =item * &gather_categories()
14749:
14750: Converts category definitions - keys of categories hash stored in
14751: coursecategories in configuration.db on the primary library server in a
14752: domain - to an array. Also generates javascript and idx hash used to
14753: generate Domain Coordinator interface for editing Course Categories.
14754:
14755: Inputs:
1.663 raeburn 14756:
1.655 raeburn 14757: categories (reference to hash of category definitions).
1.663 raeburn 14758:
1.655 raeburn 14759: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14760: categories and subcategories).
1.663 raeburn 14761:
1.655 raeburn 14762: idx (reference to hash of counters used in Domain Coordinator interface for
14763: editing Course Categories).
1.663 raeburn 14764:
1.655 raeburn 14765: jsarray (reference to array of categories used to create Javascript arrays for
14766: Domain Coordinator interface for editing Course Categories).
14767:
14768: Returns: nothing
14769:
14770: Side effects: populates cats, idx and jsarray.
14771:
14772: =cut
14773:
14774: sub gather_categories {
14775: my ($categories,$cats,$idx,$jsarray) = @_;
14776: my %counters;
14777: my $num = 0;
14778: foreach my $item (keys(%{$categories})) {
14779: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14780: if ($container eq '' && $depth == 0) {
14781: $cats->[$depth][$categories->{$item}] = $cat;
14782: } else {
14783: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14784: }
14785: my ($escitem,$tail) = split(/:/,$item,2);
14786: if ($counters{$tail} eq '') {
14787: $counters{$tail} = $num;
14788: $num ++;
14789: }
14790: if (ref($idx) eq 'HASH') {
14791: $idx->{$item} = $counters{$tail};
14792: }
14793: if (ref($jsarray) eq 'ARRAY') {
14794: push(@{$jsarray->[$counters{$tail}]},$item);
14795: }
14796: }
14797: return;
14798: }
14799:
14800: =pod
14801:
14802: =item * &extract_categories()
14803:
14804: Used to generate breadcrumb trails for course categories.
14805:
14806: Inputs:
1.663 raeburn 14807:
1.655 raeburn 14808: categories (reference to hash of category definitions).
1.663 raeburn 14809:
1.655 raeburn 14810: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14811: categories and subcategories).
1.663 raeburn 14812:
1.655 raeburn 14813: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14814:
1.655 raeburn 14815: allitems (reference to hash - key is category key
14816: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14817:
1.655 raeburn 14818: idx (reference to hash of counters used in Domain Coordinator interface for
14819: editing Course Categories).
1.663 raeburn 14820:
1.655 raeburn 14821: jsarray (reference to array of categories used to create Javascript arrays for
14822: Domain Coordinator interface for editing Course Categories).
14823:
1.665 raeburn 14824: subcats (reference to hash of arrays containing all subcategories within each
14825: category, -recursive)
14826:
1.1075.2.132 raeburn 14827: maxd (reference to hash used to hold max depth for all top-level categories).
14828:
1.655 raeburn 14829: Returns: nothing
14830:
14831: Side effects: populates trails and allitems hash references.
14832:
14833: =cut
14834:
14835: sub extract_categories {
1.1075.2.132 raeburn 14836: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14837: if (ref($categories) eq 'HASH') {
14838: &gather_categories($categories,$cats,$idx,$jsarray);
14839: if (ref($cats->[0]) eq 'ARRAY') {
14840: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14841: my $name = $cats->[0][$i];
14842: my $item = &escape($name).'::0';
14843: my $trailstr;
14844: if ($name eq 'instcode') {
14845: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14846: } elsif ($name eq 'communities') {
14847: $trailstr = &mt('Communities');
1.655 raeburn 14848: } else {
14849: $trailstr = $name;
14850: }
14851: if ($allitems->{$item} eq '') {
14852: push(@{$trails},$trailstr);
14853: $allitems->{$item} = scalar(@{$trails})-1;
14854: }
14855: my @parents = ($name);
14856: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14857: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14858: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14859: if (ref($subcats) eq 'HASH') {
14860: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14861: }
1.1075.2.132 raeburn 14862: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14863: }
14864: } else {
14865: if (ref($subcats) eq 'HASH') {
14866: $subcats->{$item} = [];
1.655 raeburn 14867: }
1.1075.2.132 raeburn 14868: if (ref($maxd) eq 'HASH') {
14869: $maxd->{$name} = 1;
14870: }
1.655 raeburn 14871: }
14872: }
14873: }
14874: }
14875: return;
14876: }
14877:
14878: =pod
14879:
1.1075.2.56 raeburn 14880: =item * &recurse_categories()
1.655 raeburn 14881:
14882: Recursively used to generate breadcrumb trails for course categories.
14883:
14884: Inputs:
1.663 raeburn 14885:
1.655 raeburn 14886: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14887: categories and subcategories).
1.663 raeburn 14888:
1.655 raeburn 14889: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14890:
14891: category (current course category, for which breadcrumb trail is being generated).
14892:
14893: trails (reference to array of breadcrumb trails for each category).
14894:
1.655 raeburn 14895: allitems (reference to hash - key is category key
14896: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14897:
1.655 raeburn 14898: parents (array containing containers directories for current category,
14899: back to top level).
14900:
14901: Returns: nothing
14902:
14903: Side effects: populates trails and allitems hash references
14904:
14905: =cut
14906:
14907: sub recurse_categories {
1.1075.2.132 raeburn 14908: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14909: my $shallower = $depth - 1;
14910: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14911: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14912: my $name = $cats->[$depth]{$category}[$k];
14913: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.164! raeburn 14914: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14915: if ($allitems->{$item} eq '') {
14916: push(@{$trails},$trailstr);
14917: $allitems->{$item} = scalar(@{$trails})-1;
14918: }
14919: my $deeper = $depth+1;
14920: push(@{$parents},$category);
1.665 raeburn 14921: if (ref($subcats) eq 'HASH') {
14922: my $subcat = &escape($name).':'.$category.':'.$depth;
14923: for (my $j=@{$parents}; $j>=0; $j--) {
14924: my $higher;
14925: if ($j > 0) {
14926: $higher = &escape($parents->[$j]).':'.
14927: &escape($parents->[$j-1]).':'.$j;
14928: } else {
14929: $higher = &escape($parents->[$j]).'::'.$j;
14930: }
14931: push(@{$subcats->{$higher}},$subcat);
14932: }
14933: }
14934: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 14935: $subcats,$maxd);
1.655 raeburn 14936: pop(@{$parents});
14937: }
14938: } else {
14939: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 14940: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14941: if ($allitems->{$item} eq '') {
14942: push(@{$trails},$trailstr);
14943: $allitems->{$item} = scalar(@{$trails})-1;
14944: }
1.1075.2.132 raeburn 14945: if (ref($maxd) eq 'HASH') {
14946: if ($depth > $maxd->{$parents->[0]}) {
14947: $maxd->{$parents->[0]} = $depth;
14948: }
14949: }
1.655 raeburn 14950: }
14951: return;
14952: }
14953:
1.663 raeburn 14954: =pod
14955:
1.1075.2.56 raeburn 14956: =item * &assign_categories_table()
1.663 raeburn 14957:
14958: Create a datatable for display of hierarchical categories in a domain,
14959: with checkboxes to allow a course to be categorized.
14960:
14961: Inputs:
14962:
14963: cathash - reference to hash of categories defined for the domain (from
14964: configuration.db)
14965:
14966: currcat - scalar with an & separated list of categories assigned to a course.
14967:
1.919 raeburn 14968: type - scalar contains course type (Course or Community).
14969:
1.1075.2.117 raeburn 14970: disabled - scalar (optional) contains disabled="disabled" if input elements are
14971: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14972:
1.663 raeburn 14973: Returns: $output (markup to be displayed)
14974:
14975: =cut
14976:
14977: sub assign_categories_table {
1.1075.2.117 raeburn 14978: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14979: my $output;
14980: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 14981: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
14982: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 14983: $maxdepth = scalar(@cats);
14984: if (@cats > 0) {
14985: my $itemcount = 0;
14986: if (ref($cats[0]) eq 'ARRAY') {
14987: my @currcategories;
14988: if ($currcat ne '') {
14989: @currcategories = split('&',$currcat);
14990: }
1.919 raeburn 14991: my $table;
1.663 raeburn 14992: for (my $i=0; $i<@{$cats[0]}; $i++) {
14993: my $parent = $cats[0][$i];
1.919 raeburn 14994: next if ($parent eq 'instcode');
14995: if ($type eq 'Community') {
14996: next unless ($parent eq 'communities');
14997: } else {
14998: next if ($parent eq 'communities');
14999: }
1.663 raeburn 15000: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15001: my $item = &escape($parent).'::0';
15002: my $checked = '';
15003: if (@currcategories > 0) {
15004: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15005: $checked = ' checked="checked"';
1.663 raeburn 15006: }
15007: }
1.919 raeburn 15008: my $parent_title = $parent;
15009: if ($parent eq 'communities') {
15010: $parent_title = &mt('Communities');
15011: }
15012: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15013: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15014: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15015: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15016: my $depth = 1;
15017: push(@path,$parent);
1.1075.2.117 raeburn 15018: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15019: pop(@path);
1.919 raeburn 15020: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15021: $itemcount ++;
15022: }
1.919 raeburn 15023: if ($itemcount) {
15024: $output = &Apache::loncommon::start_data_table().
15025: $table.
15026: &Apache::loncommon::end_data_table();
15027: }
1.663 raeburn 15028: }
15029: }
15030: }
15031: return $output;
15032: }
15033:
15034: =pod
15035:
1.1075.2.56 raeburn 15036: =item * &assign_category_rows()
1.663 raeburn 15037:
15038: Create a datatable row for display of nested categories in a domain,
15039: with checkboxes to allow a course to be categorized,called recursively.
15040:
15041: Inputs:
15042:
15043: itemcount - track row number for alternating colors
15044:
15045: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15046: categories and subcategories.
15047:
15048: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15049:
15050: parent - parent of current category item
15051:
15052: path - Array containing all categories back up through the hierarchy from the
15053: current category to the top level.
15054:
15055: currcategories - reference to array of current categories assigned to the course
15056:
1.1075.2.117 raeburn 15057: disabled - scalar (optional) contains disabled="disabled" if input elements are
15058: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15059:
1.663 raeburn 15060: Returns: $output (markup to be displayed).
15061:
15062: =cut
15063:
15064: sub assign_category_rows {
1.1075.2.117 raeburn 15065: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15066: my ($text,$name,$item,$chgstr);
15067: if (ref($cats) eq 'ARRAY') {
15068: my $maxdepth = scalar(@{$cats});
15069: if (ref($cats->[$depth]) eq 'HASH') {
15070: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15071: my $numchildren = @{$cats->[$depth]{$parent}};
15072: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 15073: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15074: for (my $j=0; $j<$numchildren; $j++) {
15075: $name = $cats->[$depth]{$parent}[$j];
15076: $item = &escape($name).':'.&escape($parent).':'.$depth;
15077: my $deeper = $depth+1;
15078: my $checked = '';
15079: if (ref($currcategories) eq 'ARRAY') {
15080: if (@{$currcategories} > 0) {
15081: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15082: $checked = ' checked="checked"';
1.663 raeburn 15083: }
15084: }
15085: }
1.664 raeburn 15086: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15087: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 15088: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15089: '<input type="hidden" name="catname" value="'.$name.'" />'.
15090: '</td><td>';
1.663 raeburn 15091: if (ref($path) eq 'ARRAY') {
15092: push(@{$path},$name);
1.1075.2.117 raeburn 15093: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15094: pop(@{$path});
15095: }
15096: $text .= '</td></tr>';
15097: }
15098: $text .= '</table></td>';
15099: }
15100: }
15101: }
15102: return $text;
15103: }
15104:
1.1075.2.69 raeburn 15105: =pod
15106:
15107: =back
15108:
15109: =cut
15110:
1.655 raeburn 15111: ############################################################
15112: ############################################################
15113:
15114:
1.443 albertel 15115: sub commit_customrole {
1.664 raeburn 15116: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15117: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15118: ($start?', '.&mt('starting').' '.localtime($start):'').
15119: ($end?', ending '.localtime($end):'').': <b>'.
15120: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15121: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15122: '</b><br />';
15123: return $output;
15124: }
15125:
15126: sub commit_standardrole {
1.1075.2.31 raeburn 15127: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15128: my ($output,$logmsg,$linefeed);
15129: if ($context eq 'auto') {
15130: $linefeed = "\n";
15131: } else {
15132: $linefeed = "<br />\n";
15133: }
1.443 albertel 15134: if ($three eq 'st') {
1.541 raeburn 15135: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 15136: $one,$two,$sec,$context,$credits);
1.541 raeburn 15137: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15138: ($result eq 'unknown_course') || ($result eq 'refused')) {
15139: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15140: } else {
1.541 raeburn 15141: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15142: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15143: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15144: if ($context eq 'auto') {
15145: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15146: } else {
15147: $output .= '<b>'.$result.'</b>'.$linefeed.
15148: &mt('Add to classlist').': <b>ok</b>';
15149: }
15150: $output .= $linefeed;
1.443 albertel 15151: }
15152: } else {
15153: $output = &mt('Assigning').' '.$three.' in '.$url.
15154: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15155: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15156: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15157: if ($context eq 'auto') {
15158: $output .= $result.$linefeed;
15159: } else {
15160: $output .= '<b>'.$result.'</b>'.$linefeed;
15161: }
1.443 albertel 15162: }
15163: return $output;
15164: }
15165:
15166: sub commit_studentrole {
1.1075.2.31 raeburn 15167: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15168: $credits) = @_;
1.626 raeburn 15169: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15170: if ($context eq 'auto') {
15171: $linefeed = "\n";
15172: } else {
15173: $linefeed = '<br />'."\n";
15174: }
1.443 albertel 15175: if (defined($one) && defined($two)) {
15176: my $cid=$one.'_'.$two;
15177: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15178: my $secchange = 0;
15179: my $expire_role_result;
15180: my $modify_section_result;
1.628 raeburn 15181: if ($oldsec ne '-1') {
15182: if ($oldsec ne $sec) {
1.443 albertel 15183: $secchange = 1;
1.628 raeburn 15184: my $now = time;
1.443 albertel 15185: my $uurl='/'.$cid;
15186: $uurl=~s/\_/\//g;
15187: if ($oldsec) {
15188: $uurl.='/'.$oldsec;
15189: }
1.626 raeburn 15190: $oldsecurl = $uurl;
1.628 raeburn 15191: $expire_role_result =
1.652 raeburn 15192: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15193: if ($env{'request.course.sec'} ne '') {
15194: if ($expire_role_result eq 'refused') {
15195: my @roles = ('st');
15196: my @statuses = ('previous');
15197: my @roledoms = ($one);
15198: my $withsec = 1;
15199: my %roleshash =
15200: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15201: \@statuses,\@roles,\@roledoms,$withsec);
15202: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15203: my ($oldstart,$oldend) =
15204: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15205: if ($oldend > 0 && $oldend <= $now) {
15206: $expire_role_result = 'ok';
15207: }
15208: }
15209: }
15210: }
1.443 albertel 15211: $result = $expire_role_result;
15212: }
15213: }
15214: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 15215: $modify_section_result =
15216: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15217: undef,undef,undef,$sec,
15218: $end,$start,'','',$cid,
15219: '',$context,$credits);
1.443 albertel 15220: if ($modify_section_result =~ /^ok/) {
15221: if ($secchange == 1) {
1.628 raeburn 15222: if ($sec eq '') {
15223: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15224: } else {
15225: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15226: }
1.443 albertel 15227: } elsif ($oldsec eq '-1') {
1.628 raeburn 15228: if ($sec eq '') {
15229: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15230: } else {
15231: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15232: }
1.443 albertel 15233: } else {
1.628 raeburn 15234: if ($sec eq '') {
15235: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15236: } else {
15237: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15238: }
1.443 albertel 15239: }
15240: } else {
1.628 raeburn 15241: if ($secchange) {
15242: $$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;
15243: } else {
15244: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15245: }
1.443 albertel 15246: }
15247: $result = $modify_section_result;
15248: } elsif ($secchange == 1) {
1.628 raeburn 15249: if ($oldsec eq '') {
1.1075.2.20 raeburn 15250: $$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 15251: } else {
15252: $$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;
15253: }
1.626 raeburn 15254: if ($expire_role_result eq 'refused') {
15255: my $newsecurl = '/'.$cid;
15256: $newsecurl =~ s/\_/\//g;
15257: if ($sec ne '') {
15258: $newsecurl.='/'.$sec;
15259: }
15260: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15261: if ($sec eq '') {
15262: $$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;
15263: } else {
15264: $$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;
15265: }
15266: }
15267: }
1.443 albertel 15268: }
15269: } else {
1.626 raeburn 15270: $$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 15271: $result = "error: incomplete course id\n";
15272: }
15273: return $result;
15274: }
15275:
1.1075.2.25 raeburn 15276: sub show_role_extent {
15277: my ($scope,$context,$role) = @_;
15278: $scope =~ s{^/}{};
15279: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15280: push(@courseroles,'co');
15281: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15282: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15283: $scope =~ s{/}{_};
15284: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15285: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15286: my ($audom,$auname) = split(/\//,$scope);
15287: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15288: &Apache::loncommon::plainname($auname,$audom).'</span>');
15289: } else {
15290: $scope =~ s{/$}{};
15291: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15292: &Apache::lonnet::domain($scope,'description').'</span>');
15293: }
15294: }
15295:
1.443 albertel 15296: ############################################################
15297: ############################################################
15298:
1.566 albertel 15299: sub check_clone {
1.578 raeburn 15300: my ($args,$linefeed) = @_;
1.566 albertel 15301: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15302: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15303: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15304: my $clonemsg;
15305: my $can_clone = 0;
1.944 raeburn 15306: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15307: if ($lctype ne 'community') {
15308: $lctype = 'course';
15309: }
1.566 albertel 15310: if ($clonehome eq 'no_host') {
1.944 raeburn 15311: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15312: $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'});
15313: } else {
15314: $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'});
15315: }
1.566 albertel 15316: } else {
15317: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15318: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15319: if ($clonedesc{'type'} ne 'Community') {
15320: $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'});
15321: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15322: }
15323: }
1.1075.2.119 raeburn 15324: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15325: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15326: $can_clone = 1;
15327: } else {
1.1075.2.95 raeburn 15328: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15329: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 15330: if ($clonehash{'cloners'} eq '') {
15331: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15332: if ($domdefs{'canclone'}) {
15333: unless ($domdefs{'canclone'} eq 'none') {
15334: if ($domdefs{'canclone'} eq 'domain') {
15335: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15336: $can_clone = 1;
15337: }
15338: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15339: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15340: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15341: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15342: $can_clone = 1;
15343: }
15344: }
15345: }
1.908 raeburn 15346: }
1.1075.2.95 raeburn 15347: } else {
15348: my @cloners = split(/,/,$clonehash{'cloners'});
15349: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15350: $can_clone = 1;
1.1075.2.95 raeburn 15351: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15352: $can_clone = 1;
1.1075.2.96 raeburn 15353: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15354: $can_clone = 1;
1.1075.2.95 raeburn 15355: }
15356: unless ($can_clone) {
1.1075.2.96 raeburn 15357: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15358: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 15359: my (%gotdomdefaults,%gotcodedefaults);
15360: foreach my $cloner (@cloners) {
15361: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15362: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15363: my (%codedefaults,@code_order);
15364: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15365: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15366: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15367: }
15368: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15369: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15370: }
15371: } else {
15372: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15373: \%codedefaults,
15374: \@code_order);
15375: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15376: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15377: }
15378: if (@code_order > 0) {
15379: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15380: $cloner,$clonehash{'internal.coursecode'},
15381: $args->{'crscode'})) {
15382: $can_clone = 1;
15383: last;
15384: }
15385: }
15386: }
15387: }
15388: }
1.1075.2.96 raeburn 15389: }
15390: }
15391: unless ($can_clone) {
15392: my $ccrole = 'cc';
15393: if ($args->{'crstype'} eq 'Community') {
15394: $ccrole = 'co';
15395: }
15396: my %roleshash =
15397: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15398: $args->{'ccdomain'},
15399: 'userroles',['active'],[$ccrole],
15400: [$args->{'clonedomain'}]);
15401: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15402: $can_clone = 1;
15403: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15404: $args->{'ccuname'},$args->{'ccdomain'})) {
15405: $can_clone = 1;
1.1075.2.95 raeburn 15406: }
15407: }
15408: unless ($can_clone) {
15409: if ($args->{'crstype'} eq 'Community') {
15410: $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'});
15411: } else {
15412: $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 15413: }
1.566 albertel 15414: }
1.578 raeburn 15415: }
1.566 albertel 15416: }
15417: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15418: }
15419:
1.444 albertel 15420: sub construct_course {
1.1075.2.119 raeburn 15421: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15422: $cnum,$category,$coderef) = @_;
1.444 albertel 15423: my $outcome;
1.541 raeburn 15424: my $linefeed = '<br />'."\n";
15425: if ($context eq 'auto') {
15426: $linefeed = "\n";
15427: }
1.566 albertel 15428:
15429: #
15430: # Are we cloning?
15431: #
15432: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15433: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15434: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15435: if ($context ne 'auto') {
1.578 raeburn 15436: if ($clonemsg ne '') {
15437: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15438: }
1.566 albertel 15439: }
15440: $outcome .= $clonemsg.$linefeed;
15441:
15442: if (!$can_clone) {
15443: return (0,$outcome);
15444: }
15445: }
15446:
1.444 albertel 15447: #
15448: # Open course
15449: #
15450: my $crstype = lc($args->{'crstype'});
15451: my %cenv=();
15452: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15453: $args->{'cdescr'},
15454: $args->{'curl'},
15455: $args->{'course_home'},
15456: $args->{'nonstandard'},
15457: $args->{'crscode'},
15458: $args->{'ccuname'}.':'.
15459: $args->{'ccdomain'},
1.882 raeburn 15460: $args->{'crstype'},
1.885 raeburn 15461: $cnum,$context,$category);
1.444 albertel 15462:
15463: # Note: The testing routines depend on this being output; see
15464: # Utils::Course. This needs to at least be output as a comment
15465: # if anyone ever decides to not show this, and Utils::Course::new
15466: # will need to be suitably modified.
1.541 raeburn 15467: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 15468: if ($$courseid =~ /^error:/) {
15469: return (0,$outcome);
15470: }
15471:
1.444 albertel 15472: #
15473: # Check if created correctly
15474: #
1.479 albertel 15475: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15476: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15477: if ($crsuhome eq 'no_host') {
15478: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15479: return (0,$outcome);
15480: }
1.541 raeburn 15481: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15482:
1.444 albertel 15483: #
1.566 albertel 15484: # Do the cloning
15485: #
15486: if ($can_clone && $cloneid) {
15487: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
15488: if ($context ne 'auto') {
15489: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15490: }
15491: $outcome .= $clonemsg.$linefeed;
15492: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15493: # Copy all files
1.637 www 15494: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15495: # Restore URL
1.566 albertel 15496: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15497: # Restore title
1.566 albertel 15498: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15499: # Restore creation date, creator and creation context.
15500: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15501: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15502: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15503: # Mark as cloned
1.566 albertel 15504: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15505: # Need to clone grading mode
15506: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15507: $cenv{'grading'}=$newenv{'grading'};
15508: # Do not clone these environment entries
15509: &Apache::lonnet::del('environment',
15510: ['default_enrollment_start_date',
15511: 'default_enrollment_end_date',
15512: 'question.email',
15513: 'policy.email',
15514: 'comment.email',
15515: 'pch.users.denied',
1.725 raeburn 15516: 'plc.users.denied',
15517: 'hidefromcat',
1.1075.2.36 raeburn 15518: 'checkforpriv',
1.1075.2.158 raeburn 15519: 'categories'],
1.638 www 15520: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15521: if ($args->{'textbook'}) {
15522: $cenv{'internal.textbook'} = $args->{'textbook'};
15523: }
1.444 albertel 15524: }
1.566 albertel 15525:
1.444 albertel 15526: #
15527: # Set environment (will override cloned, if existing)
15528: #
15529: my @sections = ();
15530: my @xlists = ();
15531: if ($args->{'crstype'}) {
15532: $cenv{'type'}=$args->{'crstype'};
15533: }
15534: if ($args->{'crsid'}) {
15535: $cenv{'courseid'}=$args->{'crsid'};
15536: }
15537: if ($args->{'crscode'}) {
15538: $cenv{'internal.coursecode'}=$args->{'crscode'};
15539: }
15540: if ($args->{'crsquota'} ne '') {
15541: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15542: } else {
15543: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15544: }
15545: if ($args->{'ccuname'}) {
15546: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15547: ':'.$args->{'ccdomain'};
15548: } else {
15549: $cenv{'internal.courseowner'} = $args->{'curruser'};
15550: }
1.1075.2.31 raeburn 15551: if ($args->{'defaultcredits'}) {
15552: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15553: }
1.444 albertel 15554: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15555: if ($args->{'crssections'}) {
15556: $cenv{'internal.sectionnums'} = '';
15557: if ($args->{'crssections'} =~ m/,/) {
15558: @sections = split/,/,$args->{'crssections'};
15559: } else {
15560: $sections[0] = $args->{'crssections'};
15561: }
15562: if (@sections > 0) {
15563: foreach my $item (@sections) {
15564: my ($sec,$gp) = split/:/,$item;
15565: my $class = $args->{'crscode'}.$sec;
15566: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15567: $cenv{'internal.sectionnums'} .= $item.',';
15568: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15569: push(@badclasses,$class);
1.444 albertel 15570: }
15571: }
15572: $cenv{'internal.sectionnums'} =~ s/,$//;
15573: }
15574: }
15575: # do not hide course coordinator from staff listing,
15576: # even if privileged
15577: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15578: # add course coordinator's domain to domains to check for privileged users
15579: # if different to course domain
15580: if ($$crsudom ne $args->{'ccdomain'}) {
15581: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15582: }
1.444 albertel 15583: # add crosslistings
15584: if ($args->{'crsxlist'}) {
15585: $cenv{'internal.crosslistings'}='';
15586: if ($args->{'crsxlist'} =~ m/,/) {
15587: @xlists = split/,/,$args->{'crsxlist'};
15588: } else {
15589: $xlists[0] = $args->{'crsxlist'};
15590: }
15591: if (@xlists > 0) {
15592: foreach my $item (@xlists) {
15593: my ($xl,$gp) = split/:/,$item;
15594: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15595: $cenv{'internal.crosslistings'} .= $item.',';
15596: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15597: push(@badclasses,$xl);
1.444 albertel 15598: }
15599: }
15600: $cenv{'internal.crosslistings'} =~ s/,$//;
15601: }
15602: }
15603: if ($args->{'autoadds'}) {
15604: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15605: }
15606: if ($args->{'autodrops'}) {
15607: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15608: }
15609: # check for notification of enrollment changes
15610: my @notified = ();
15611: if ($args->{'notify_owner'}) {
15612: if ($args->{'ccuname'} ne '') {
15613: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15614: }
15615: }
15616: if ($args->{'notify_dc'}) {
15617: if ($uname ne '') {
1.630 raeburn 15618: push(@notified,$uname.':'.$udom);
1.444 albertel 15619: }
15620: }
15621: if (@notified > 0) {
15622: my $notifylist;
15623: if (@notified > 1) {
15624: $notifylist = join(',',@notified);
15625: } else {
15626: $notifylist = $notified[0];
15627: }
15628: $cenv{'internal.notifylist'} = $notifylist;
15629: }
15630: if (@badclasses > 0) {
15631: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15632: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15633: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15634: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15635: );
1.1075.2.119 raeburn 15636: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15637: &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 15638: if ($context eq 'auto') {
15639: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15640: } else {
1.566 albertel 15641: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15642: }
15643: foreach my $item (@badclasses) {
1.541 raeburn 15644: if ($context eq 'auto') {
1.1075.2.119 raeburn 15645: $outcome .= " - $item\n";
1.541 raeburn 15646: } else {
1.1075.2.119 raeburn 15647: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15648: }
1.1075.2.119 raeburn 15649: }
15650: if ($context eq 'auto') {
15651: $outcome .= $linefeed;
15652: } else {
15653: $outcome .= "</ul><br /><br /></div>\n";
15654: }
1.444 albertel 15655: }
15656: if ($args->{'no_end_date'}) {
15657: $args->{'endaccess'} = 0;
15658: }
15659: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15660: $cenv{'internal.autoend'}=$args->{'enrollend'};
15661: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15662: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15663: if ($args->{'showphotos'}) {
15664: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15665: }
15666: $cenv{'internal.authtype'} = $args->{'authtype'};
15667: $cenv{'internal.autharg'} = $args->{'autharg'};
15668: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15669: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15670: 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');
15671: if ($context eq 'auto') {
15672: $outcome .= $krb_msg;
15673: } else {
1.566 albertel 15674: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15675: }
15676: $outcome .= $linefeed;
1.444 albertel 15677: }
15678: }
15679: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15680: if ($args->{'setpolicy'}) {
15681: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15682: }
15683: if ($args->{'setcontent'}) {
15684: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15685: }
1.1075.2.110 raeburn 15686: if ($args->{'setcomment'}) {
15687: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15688: }
1.444 albertel 15689: }
15690: if ($args->{'reshome'}) {
15691: $cenv{'reshome'}=$args->{'reshome'}.'/';
15692: $cenv{'reshome'}=~s/\/+$/\//;
15693: }
15694: #
15695: # course has keyed access
15696: #
15697: if ($args->{'setkeys'}) {
15698: $cenv{'keyaccess'}='yes';
15699: }
15700: # if specified, key authority is not course, but user
15701: # only active if keyaccess is yes
15702: if ($args->{'keyauth'}) {
1.487 albertel 15703: my ($user,$domain) = split(':',$args->{'keyauth'});
15704: $user = &LONCAPA::clean_username($user);
15705: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15706: if ($user ne '' && $domain ne '') {
1.487 albertel 15707: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15708: }
15709: }
15710:
1.1075.2.59 raeburn 15711: #
15712: # generate and store uniquecode (available to course requester), if course should have one.
15713: #
15714: if ($args->{'uniquecode'}) {
15715: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15716: if ($code) {
15717: $cenv{'internal.uniquecode'} = $code;
15718: my %crsinfo =
15719: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15720: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15721: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15722: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15723: }
15724: if (ref($coderef)) {
15725: $$coderef = $code;
15726: }
15727: }
15728: }
15729:
1.444 albertel 15730: if ($args->{'disresdis'}) {
15731: $cenv{'pch.roles.denied'}='st';
15732: }
15733: if ($args->{'disablechat'}) {
15734: $cenv{'plc.roles.denied'}='st';
15735: }
15736:
15737: # Record we've not yet viewed the Course Initialization Helper for this
15738: # course
15739: $cenv{'course.helper.not.run'} = 1;
15740: #
15741: # Use new Randomseed
15742: #
15743: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15744: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15745: #
15746: # The encryption code and receipt prefix for this course
15747: #
15748: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15749: $cenv{'internal.encpref'}=100+int(9*rand(99));
15750: #
15751: # By default, use standard grading
15752: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15753:
1.541 raeburn 15754: $outcome .= $linefeed.&mt('Setting environment').': '.
15755: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15756: #
15757: # Open all assignments
15758: #
15759: if ($args->{'openall'}) {
1.1075.2.146 raeburn 15760: my $opendate = time;
15761: if ($args->{'openallfrom'} =~ /^\d+$/) {
15762: $opendate = $args->{'openallfrom'};
15763: }
1.444 albertel 15764: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1075.2.146 raeburn 15765: my %storecontent = ($storeunder => $opendate,
1.444 albertel 15766: $storeunder.'.type' => 'date_start');
1.1075.2.146 raeburn 15767: $outcome .= &mt('All assignments open starting [_1]',
15768: &Apache::lonlocal::locallocaltime($opendate)).': '.
15769: &Apache::lonnet::cput
15770: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15771: }
15772: #
15773: # Set first page
15774: #
15775: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15776: || ($cloneid)) {
1.445 albertel 15777: use LONCAPA::map;
1.444 albertel 15778: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15779:
15780: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15781: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15782:
1.444 albertel 15783: $outcome .= ($fatal?$errtext:'read ok').' - ';
15784: my $title; my $url;
15785: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15786: $title=&mt('Syllabus');
1.444 albertel 15787: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15788: } else {
1.963 raeburn 15789: $title=&mt('Table of Contents');
1.444 albertel 15790: $url='/adm/navmaps';
15791: }
1.445 albertel 15792:
15793: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15794: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15795:
15796: if ($errtext) { $fatal=2; }
1.541 raeburn 15797: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15798: }
1.566 albertel 15799:
15800: return (1,$outcome);
1.444 albertel 15801: }
15802:
1.1075.2.59 raeburn 15803: sub make_unique_code {
15804: my ($cdom,$cnum) = @_;
15805: # get lock on uniquecodes db
15806: my $lockhash = {
15807: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15808: ':'.$env{'user.domain'},
15809: };
15810: my $tries = 0;
15811: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15812: my ($code,$error);
15813:
15814: while (($gotlock ne 'ok') && ($tries<3)) {
15815: $tries ++;
15816: sleep 1;
15817: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15818: }
15819: if ($gotlock eq 'ok') {
15820: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15821: my $gotcode;
15822: my $attempts = 0;
15823: while ((!$gotcode) && ($attempts < 100)) {
15824: $code = &generate_code();
15825: if (!exists($currcodes{$code})) {
15826: $gotcode = 1;
15827: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15828: $error = 'nostore';
15829: }
15830: }
15831: $attempts ++;
15832: }
15833: my @del_lock = ($cnum."\0".'uniquecodes');
15834: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15835: } else {
15836: $error = 'nolock';
15837: }
15838: return ($code,$error);
15839: }
15840:
15841: sub generate_code {
15842: my $code;
15843: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15844: for (my $i=0; $i<6; $i++) {
15845: my $lettnum = int (rand 2);
15846: my $item = '';
15847: if ($lettnum) {
15848: $item = $letts[int( rand(18) )];
15849: } else {
15850: $item = 1+int( rand(8) );
15851: }
15852: $code .= $item;
15853: }
15854: return $code;
15855: }
15856:
1.444 albertel 15857: ############################################################
15858: ############################################################
15859:
1.953 droeschl 15860: #SD
15861: # only Community and Course, or anything else?
1.378 raeburn 15862: sub course_type {
15863: my ($cid) = @_;
15864: if (!defined($cid)) {
15865: $cid = $env{'request.course.id'};
15866: }
1.404 albertel 15867: if (defined($env{'course.'.$cid.'.type'})) {
15868: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15869: } else {
15870: return 'Course';
1.377 raeburn 15871: }
15872: }
1.156 albertel 15873:
1.406 raeburn 15874: sub group_term {
15875: my $crstype = &course_type();
15876: my %names = (
15877: 'Course' => 'group',
1.865 raeburn 15878: 'Community' => 'group',
1.406 raeburn 15879: );
15880: return $names{$crstype};
15881: }
15882:
1.902 raeburn 15883: sub course_types {
1.1075.2.59 raeburn 15884: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15885: my %typename = (
15886: official => 'Official course',
15887: unofficial => 'Unofficial course',
15888: community => 'Community',
1.1075.2.59 raeburn 15889: textbook => 'Textbook course',
1.902 raeburn 15890: );
15891: return (\@types,\%typename);
15892: }
15893:
1.156 albertel 15894: sub icon {
15895: my ($file)=@_;
1.505 albertel 15896: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15897: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15898: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15899: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15900: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15901: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15902: $curfext.".gif") {
15903: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15904: $curfext.".gif";
15905: }
15906: }
1.249 albertel 15907: return &lonhttpdurl($iconname);
1.154 albertel 15908: }
1.84 albertel 15909:
1.575 albertel 15910: sub lonhttpdurl {
1.692 www 15911: #
15912: # Had been used for "small fry" static images on separate port 8080.
15913: # Modify here if lightweight http functionality desired again.
15914: # Currently eliminated due to increasing firewall issues.
15915: #
1.575 albertel 15916: my ($url)=@_;
1.692 www 15917: return $url;
1.215 albertel 15918: }
15919:
1.213 albertel 15920: sub connection_aborted {
15921: my ($r)=@_;
15922: $r->print(" ");$r->rflush();
15923: my $c = $r->connection;
15924: return $c->aborted();
15925: }
15926:
1.221 foxr 15927: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15928: # strings as 'strings'.
15929: sub escape_single {
1.221 foxr 15930: my ($input) = @_;
1.223 albertel 15931: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15932: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15933: return $input;
15934: }
1.223 albertel 15935:
1.222 foxr 15936: # Same as escape_single, but escape's "'s This
15937: # can be used for "strings"
15938: sub escape_double {
15939: my ($input) = @_;
15940: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15941: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15942: return $input;
15943: }
1.223 albertel 15944:
1.222 foxr 15945: # Escapes the last element of a full URL.
15946: sub escape_url {
15947: my ($url) = @_;
1.238 raeburn 15948: my @urlslices = split(/\//, $url,-1);
1.369 www 15949: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15950: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15951: }
1.462 albertel 15952:
1.820 raeburn 15953: sub compare_arrays {
15954: my ($arrayref1,$arrayref2) = @_;
15955: my (@difference,%count);
15956: @difference = ();
15957: %count = ();
15958: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15959: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15960: foreach my $element (keys(%count)) {
15961: if ($count{$element} == 1) {
15962: push(@difference,$element);
15963: }
15964: }
15965: }
15966: return @difference;
15967: }
15968:
1.1075.2.152 raeburn 15969: sub lon_status_items {
15970: my %defaults = (
15971: E => 100,
15972: W => 4,
15973: N => 1,
15974: U => 5,
15975: threshold => 200,
15976: sysmail => 2500,
15977: );
15978: my %names = (
15979: E => 'Errors',
15980: W => 'Warnings',
15981: N => 'Notices',
15982: U => 'Unsent',
15983: );
15984: return (\%defaults,\%names);
15985: }
15986:
1.817 bisitz 15987: # -------------------------------------------------------- Initialize user login
1.462 albertel 15988: sub init_user_environment {
1.463 albertel 15989: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15990: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15991:
15992: my $public=($username eq 'public' && $domain eq 'public');
15993:
15994: # See if old ID present, if so, remove
15995:
1.1062 raeburn 15996: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15997: my $now=time;
15998:
15999: if ($public) {
16000: my $max_public=100;
16001: my $oldest;
16002: my $oldest_time=0;
16003: for(my $next=1;$next<=$max_public;$next++) {
16004: if (-e $lonids."/publicuser_$next.id") {
16005: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16006: if ($mtime<$oldest_time || !$oldest_time) {
16007: $oldest_time=$mtime;
16008: $oldest=$next;
16009: }
16010: } else {
16011: $cookie="publicuser_$next";
16012: last;
16013: }
16014: }
16015: if (!$cookie) { $cookie="publicuser_$oldest"; }
16016: } else {
1.463 albertel 16017: # if this isn't a robot, kill any existing non-robot sessions
16018: if (!$args->{'robot'}) {
16019: opendir(DIR,$lonids);
16020: while ($filename=readdir(DIR)) {
16021: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 16022: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16023: &GDBM_READER(),0640)) {
16024: my $linkedfile;
16025: if (exists($oldenv{'user.linkedenv'})) {
16026: $linkedfile = $oldenv{'user.linkedenv'};
16027: }
16028: untie(%oldenv);
16029: if (unlink("$lonids/$filename")) {
16030: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16031: if (-l "$lonids/$linkedfile.id") {
16032: unlink("$lonids/$linkedfile.id");
16033: }
16034: }
16035: }
16036: } else {
16037: unlink($lonids.'/'.$filename);
16038: }
1.463 albertel 16039: }
1.462 albertel 16040: }
1.463 albertel 16041: closedir(DIR);
1.1075.2.84 raeburn 16042: # If there is a undeleted lockfile for the user's paste buffer remove it.
16043: my $namespace = 'nohist_courseeditor';
16044: my $lockingkey = 'paste'."\0".'locked_num';
16045: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16046: $domain,$username);
16047: if (exists($lockhash{$lockingkey})) {
16048: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16049: unless ($delresult eq 'ok') {
16050: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16051: }
16052: }
1.462 albertel 16053: }
16054: # Give them a new cookie
1.463 albertel 16055: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16056: : $now.$$.int(rand(10000)));
1.463 albertel 16057: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16058:
16059: # Initialize roles
16060:
1.1062 raeburn 16061: ($userroles,$firstaccenv,$timerintenv) =
16062: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16063: }
16064: # ------------------------------------ Check browser type and MathML capability
16065:
1.1075.2.77 raeburn 16066: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16067: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16068:
16069: # ------------------------------------------------------------- Get environment
16070:
16071: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16072: my ($tmp) = keys(%userenv);
16073: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
16074: } else {
16075: undef(%userenv);
16076: }
16077: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16078: $form->{'interface'}=$userenv{'interface'};
16079: }
16080: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16081:
16082: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16083: foreach my $option ('interface','localpath','localres') {
16084: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16085: }
16086: # --------------------------------------------------------- Write first profile
16087:
16088: {
1.1075.2.150 raeburn 16089: my $ip = &Apache::lonnet::get_requestor_ip();
1.462 albertel 16090: my %initial_env =
16091: ("user.name" => $username,
16092: "user.domain" => $domain,
16093: "user.home" => $authhost,
16094: "browser.type" => $clientbrowser,
16095: "browser.version" => $clientversion,
16096: "browser.mathml" => $clientmathml,
16097: "browser.unicode" => $clientunicode,
16098: "browser.os" => $clientos,
1.1075.2.42 raeburn 16099: "browser.mobile" => $clientmobile,
16100: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 16101: "browser.osversion" => $clientosversion,
1.462 albertel 16102: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16103: "request.course.fn" => '',
16104: "request.course.uri" => '',
16105: "request.course.sec" => '',
16106: "request.role" => 'cm',
16107: "request.role.adv" => $env{'user.adv'},
1.1075.2.150 raeburn 16108: "request.host" => $ip,);
1.462 albertel 16109:
16110: if ($form->{'localpath'}) {
16111: $initial_env{"browser.localpath"} = $form->{'localpath'};
16112: $initial_env{"browser.localres"} = $form->{'localres'};
16113: }
16114:
16115: if ($form->{'interface'}) {
16116: $form->{'interface'}=~s/\W//gs;
16117: $initial_env{"browser.interface"} = $form->{'interface'};
16118: $env{'browser.interface'}=$form->{'interface'};
16119: }
16120:
1.1075.2.54 raeburn 16121: if ($form->{'iptoken'}) {
16122: my $lonhost = $r->dir_config('lonHostID');
16123: $initial_env{"user.noloadbalance"} = $lonhost;
16124: $env{'user.noloadbalance'} = $lonhost;
16125: }
16126:
1.1075.2.120 raeburn 16127: if ($form->{'noloadbalance'}) {
16128: my @hosts = &Apache::lonnet::current_machine_ids();
16129: my $hosthere = $form->{'noloadbalance'};
16130: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16131: $initial_env{"user.noloadbalance"} = $hosthere;
16132: $env{'user.noloadbalance'} = $hosthere;
16133: }
16134: }
16135:
1.1016 raeburn 16136: unless ($domain eq 'public') {
1.1075.2.125 raeburn 16137: my %is_adv = ( is_adv => $env{'user.adv'} );
16138: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 16139:
1.1075.2.125 raeburn 16140: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16141: $userenv{'availabletools.'.$tool} =
16142: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16143: undef,\%userenv,\%domdef,\%is_adv);
16144: }
1.724 raeburn 16145:
1.1075.2.125 raeburn 16146: foreach my $crstype ('official','unofficial','community','textbook') {
16147: $userenv{'canrequest.'.$crstype} =
16148: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16149: 'reload','requestcourses',
16150: \%userenv,\%domdef,\%is_adv);
16151: }
1.765 raeburn 16152:
1.1075.2.125 raeburn 16153: $userenv{'canrequest.author'} =
16154: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16155: 'reload','requestauthor',
16156: \%userenv,\%domdef,\%is_adv);
16157: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16158: $domain,$username);
16159: my $reqstatus = $reqauthor{'author_status'};
16160: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16161: if (ref($reqauthor{'author'}) eq 'HASH') {
16162: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16163: $reqauthor{'author'}{'timestamp'};
16164: }
1.1075.2.14 raeburn 16165: }
16166: }
16167:
1.462 albertel 16168: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16169:
1.462 albertel 16170: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16171: &GDBM_WRCREAT(),0640)) {
16172: &_add_to_env(\%disk_env,\%initial_env);
16173: &_add_to_env(\%disk_env,\%userenv,'environment.');
16174: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16175: if (ref($firstaccenv) eq 'HASH') {
16176: &_add_to_env(\%disk_env,$firstaccenv);
16177: }
16178: if (ref($timerintenv) eq 'HASH') {
16179: &_add_to_env(\%disk_env,$timerintenv);
16180: }
1.463 albertel 16181: if (ref($args->{'extra_env'})) {
16182: &_add_to_env(\%disk_env,$args->{'extra_env'});
16183: }
1.462 albertel 16184: untie(%disk_env);
16185: } else {
1.705 tempelho 16186: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16187: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16188: return 'error: '.$!;
16189: }
16190: }
16191: $env{'request.role'}='cm';
16192: $env{'request.role.adv'}=$env{'user.adv'};
16193: $env{'browser.type'}=$clientbrowser;
16194:
16195: return $cookie;
16196:
16197: }
16198:
16199: sub _add_to_env {
16200: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16201: if (ref($env_data) eq 'HASH') {
16202: while (my ($key,$value) = each(%$env_data)) {
16203: $idf->{$prefix.$key} = $value;
16204: $env{$prefix.$key} = $value;
16205: }
1.462 albertel 16206: }
16207: }
16208:
1.685 tempelho 16209: # --- Get the symbolic name of a problem and the url
16210: sub get_symb {
16211: my ($request,$silent) = @_;
1.726 raeburn 16212: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16213: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16214: if ($symb eq '') {
16215: if (!$silent) {
1.1071 raeburn 16216: if (ref($request)) {
16217: $request->print("Unable to handle ambiguous references:$url:.");
16218: }
1.685 tempelho 16219: return ();
16220: }
16221: }
16222: &Apache::lonenc::check_decrypt(\$symb);
16223: return ($symb);
16224: }
16225:
16226: # --------------------------------------------------------------Get annotation
16227:
16228: sub get_annotation {
16229: my ($symb,$enc) = @_;
16230:
16231: my $key = $symb;
16232: if (!$enc) {
16233: $key =
16234: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16235: }
16236: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16237: return $annotation{$key};
16238: }
16239:
16240: sub clean_symb {
1.731 raeburn 16241: my ($symb,$delete_enc) = @_;
1.685 tempelho 16242:
16243: &Apache::lonenc::check_decrypt(\$symb);
16244: my $enc = $env{'request.enc'};
1.731 raeburn 16245: if ($delete_enc) {
1.730 raeburn 16246: delete($env{'request.enc'});
16247: }
1.685 tempelho 16248:
16249: return ($symb,$enc);
16250: }
1.462 albertel 16251:
1.1075.2.69 raeburn 16252: ############################################################
16253: ############################################################
16254:
16255: =pod
16256:
16257: =head1 Routines for building display used to search for courses
16258:
16259:
16260: =over 4
16261:
16262: =item * &build_filters()
16263:
16264: Create markup for a table used to set filters to use when selecting
16265: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16266: and quotacheck.pl
16267:
16268:
16269: Inputs:
16270:
16271: filterlist - anonymous array of fields to include as potential filters
16272:
16273: crstype - course type
16274:
16275: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16276: to pop-open a course selector (will contain "extra element").
16277:
16278: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16279:
16280: filter - anonymous hash of criteria and their values
16281:
16282: action - form action
16283:
16284: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16285:
16286: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
16287:
16288: cloneruname - username of owner of new course who wants to clone
16289:
16290: clonerudom - domain of owner of new course who wants to clone
16291:
16292: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16293:
16294: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16295:
16296: codedom - domain
16297:
16298: formname - value of form element named "form".
16299:
16300: fixeddom - domain, if fixed.
16301:
16302: prevphase - value to assign to form element named "phase" when going back to the previous screen
16303:
16304: cnameelement - name of form element in form on opener page which will receive title of selected course
16305:
16306: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16307:
16308: cdomelement - name of form element in form on opener page which will receive domain of selected course
16309:
16310: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16311:
16312: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16313:
16314: clonewarning - warning message about missing information for intended course owner when DC creates a course
16315:
16316:
16317: Returns: $output - HTML for display of search criteria, and hidden form elements.
16318:
16319:
16320: Side Effects: None
16321:
16322: =cut
16323:
16324: # ---------------------------------------------- search for courses based on last activity etc.
16325:
16326: sub build_filters {
16327: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16328: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16329: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16330: $cnameelement,$cnumelement,$cdomelement,$setroles,
16331: $clonetext,$clonewarning) = @_;
16332: my ($list,$jscript);
16333: my $onchange = 'javascript:updateFilters(this)';
16334: my ($domainselectform,$sincefilterform,$createdfilterform,
16335: $ownerdomselectform,$persondomselectform,$instcodeform,
16336: $typeselectform,$instcodetitle);
16337: if ($formname eq '') {
16338: $formname = $caller;
16339: }
16340: foreach my $item (@{$filterlist}) {
16341: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16342: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16343: if ($item eq 'domainfilter') {
16344: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16345: } elsif ($item eq 'coursefilter') {
16346: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16347: } elsif ($item eq 'ownerfilter') {
16348: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16349: } elsif ($item eq 'ownerdomfilter') {
16350: $filter->{'ownerdomfilter'} =
16351: &LONCAPA::clean_domain($filter->{$item});
16352: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16353: 'ownerdomfilter',1);
16354: } elsif ($item eq 'personfilter') {
16355: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16356: } elsif ($item eq 'persondomfilter') {
16357: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16358: 'persondomfilter',1);
16359: } else {
16360: $filter->{$item} =~ s/\W//g;
16361: }
16362: if (!$filter->{$item}) {
16363: $filter->{$item} = '';
16364: }
16365: }
16366: if ($item eq 'domainfilter') {
16367: my $allow_blank = 1;
16368: if ($formname eq 'portform') {
16369: $allow_blank=0;
16370: } elsif ($formname eq 'studentform') {
16371: $allow_blank=0;
16372: }
16373: if ($fixeddom) {
16374: $domainselectform = '<input type="hidden" name="domainfilter"'.
16375: ' value="'.$codedom.'" />'.
16376: &Apache::lonnet::domain($codedom,'description');
16377: } else {
16378: $domainselectform = &select_dom_form($filter->{$item},
16379: 'domainfilter',
16380: $allow_blank,'',$onchange);
16381: }
16382: } else {
16383: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16384: }
16385: }
16386:
16387: # last course activity filter and selection
16388: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16389:
16390: # course created filter and selection
16391: if (exists($filter->{'createdfilter'})) {
16392: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16393: }
16394:
16395: my %lt = &Apache::lonlocal::texthash(
16396: 'cac' => "$crstype Activity",
16397: 'ccr' => "$crstype Created",
16398: 'cde' => "$crstype Title",
16399: 'cdo' => "$crstype Domain",
16400: 'ins' => 'Institutional Code',
16401: 'inc' => 'Institutional Categorization',
16402: 'cow' => "$crstype Owner/Co-owner",
16403: 'cop' => "$crstype Personnel Includes",
16404: 'cog' => 'Type',
16405: );
16406:
16407: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16408: my $typeval = 'Course';
16409: if ($crstype eq 'Community') {
16410: $typeval = 'Community';
16411: }
16412: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16413: } else {
16414: $typeselectform = '<select name="type" size="1"';
16415: if ($onchange) {
16416: $typeselectform .= ' onchange="'.$onchange.'"';
16417: }
16418: $typeselectform .= '>'."\n";
16419: foreach my $posstype ('Course','Community') {
16420: $typeselectform.='<option value="'.$posstype.'"'.
16421: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16422: }
16423: $typeselectform.="</select>";
16424: }
16425:
16426: my ($cloneableonlyform,$cloneabletitle);
16427: if (exists($filter->{'cloneableonly'})) {
16428: my $cloneableon = '';
16429: my $cloneableoff = ' checked="checked"';
16430: if ($filter->{'cloneableonly'}) {
16431: $cloneableon = $cloneableoff;
16432: $cloneableoff = '';
16433: }
16434: $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>';
16435: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16436: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16437: } else {
16438: $cloneabletitle = &mt('Cloneable by you');
16439: }
16440: }
16441: my $officialjs;
16442: if ($crstype eq 'Course') {
16443: if (exists($filter->{'instcodefilter'})) {
16444: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16445: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16446: if ($codedom) {
16447: $officialjs = 1;
16448: ($instcodeform,$jscript,$$numtitlesref) =
16449: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16450: $officialjs,$codetitlesref);
16451: if ($jscript) {
16452: $jscript = '<script type="text/javascript">'."\n".
16453: '// <![CDATA['."\n".
16454: $jscript."\n".
16455: '// ]]>'."\n".
16456: '</script>'."\n";
16457: }
16458: }
16459: if ($instcodeform eq '') {
16460: $instcodeform =
16461: '<input type="text" name="instcodefilter" size="10" value="'.
16462: $list->{'instcodefilter'}.'" />';
16463: $instcodetitle = $lt{'ins'};
16464: } else {
16465: $instcodetitle = $lt{'inc'};
16466: }
16467: if ($fixeddom) {
16468: $instcodetitle .= '<br />('.$codedom.')';
16469: }
16470: }
16471: }
16472: my $output = qq|
16473: <form method="post" name="filterpicker" action="$action">
16474: <input type="hidden" name="form" value="$formname" />
16475: |;
16476: if ($formname eq 'modifycourse') {
16477: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16478: '<input type="hidden" name="prevphase" value="'.
16479: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16480: } elsif ($formname eq 'quotacheck') {
16481: $output .= qq|
16482: <input type="hidden" name="sortby" value="" />
16483: <input type="hidden" name="sortorder" value="" />
16484: |;
16485: } else {
1.1075.2.69 raeburn 16486: my $name_input;
16487: if ($cnameelement ne '') {
16488: $name_input = '<input type="hidden" name="cnameelement" value="'.
16489: $cnameelement.'" />';
16490: }
16491: $output .= qq|
16492: <input type="hidden" name="cnumelement" value="$cnumelement" />
16493: <input type="hidden" name="cdomelement" value="$cdomelement" />
16494: $name_input
16495: $roleelement
16496: $multelement
16497: $typeelement
16498: |;
16499: if ($formname eq 'portform') {
16500: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16501: }
16502: }
16503: if ($fixeddom) {
16504: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16505: }
16506: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16507: if ($sincefilterform) {
16508: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16509: .$sincefilterform
16510: .&Apache::lonhtmlcommon::row_closure();
16511: }
16512: if ($createdfilterform) {
16513: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16514: .$createdfilterform
16515: .&Apache::lonhtmlcommon::row_closure();
16516: }
16517: if ($domainselectform) {
16518: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16519: .$domainselectform
16520: .&Apache::lonhtmlcommon::row_closure();
16521: }
16522: if ($typeselectform) {
16523: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16524: $output .= $typeselectform;
16525: } else {
16526: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16527: .$typeselectform
16528: .&Apache::lonhtmlcommon::row_closure();
16529: }
16530: }
16531: if ($instcodeform) {
16532: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16533: .$instcodeform
16534: .&Apache::lonhtmlcommon::row_closure();
16535: }
16536: if (exists($filter->{'ownerfilter'})) {
16537: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16538: '<table><tr><td>'.&mt('Username').'<br />'.
16539: '<input type="text" name="ownerfilter" size="20" value="'.
16540: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16541: $ownerdomselectform.'</td></tr></table>'.
16542: &Apache::lonhtmlcommon::row_closure();
16543: }
16544: if (exists($filter->{'personfilter'})) {
16545: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16546: '<table><tr><td>'.&mt('Username').'<br />'.
16547: '<input type="text" name="personfilter" size="20" value="'.
16548: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16549: $persondomselectform.'</td></tr></table>'.
16550: &Apache::lonhtmlcommon::row_closure();
16551: }
16552: if (exists($filter->{'coursefilter'})) {
16553: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16554: .'<input type="text" name="coursefilter" size="25" value="'
16555: .$list->{'coursefilter'}.'" />'
16556: .&Apache::lonhtmlcommon::row_closure();
16557: }
16558: if ($cloneableonlyform) {
16559: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16560: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16561: }
16562: if (exists($filter->{'descriptfilter'})) {
16563: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16564: .'<input type="text" name="descriptfilter" size="40" value="'
16565: .$list->{'descriptfilter'}.'" />'
16566: .&Apache::lonhtmlcommon::row_closure(1);
16567: }
16568: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16569: '<input type="hidden" name="updater" value="" />'."\n".
16570: '<input type="submit" name="gosearch" value="'.
16571: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16572: return $jscript.$clonewarning.$output;
16573: }
16574:
16575: =pod
16576:
16577: =item * &timebased_select_form()
16578:
16579: Create markup for a dropdown list used to select a time-based
16580: filter e.g., Course Activity, Course Created, when searching for courses
16581: or communities
16582:
16583: Inputs:
16584:
16585: item - name of form element (sincefilter or createdfilter)
16586:
16587: filter - anonymous hash of criteria and their values
16588:
16589: Returns: HTML for a select box contained a blank, then six time selections,
16590: with value set in incoming form variables currently selected.
16591:
16592: Side Effects: None
16593:
16594: =cut
16595:
16596: sub timebased_select_form {
16597: my ($item,$filter) = @_;
16598: if (ref($filter) eq 'HASH') {
16599: $filter->{$item} =~ s/[^\d-]//g;
16600: if (!$filter->{$item}) { $filter->{$item}=-1; }
16601: return &select_form(
16602: $filter->{$item},
16603: $item,
16604: { '-1' => '',
16605: '86400' => &mt('today'),
16606: '604800' => &mt('last week'),
16607: '2592000' => &mt('last month'),
16608: '7776000' => &mt('last three months'),
16609: '15552000' => &mt('last six months'),
16610: '31104000' => &mt('last year'),
16611: 'select_form_order' =>
16612: ['-1','86400','604800','2592000','7776000',
16613: '15552000','31104000']});
16614: }
16615: }
16616:
16617: =pod
16618:
16619: =item * &js_changer()
16620:
16621: Create script tag containing Javascript used to submit course search form
16622: when course type or domain is changed, and also to hide 'Searching ...' on
16623: page load completion for page showing search result.
16624:
16625: Inputs: None
16626:
16627: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16628:
16629: Side Effects: None
16630:
16631: =cut
16632:
16633: sub js_changer {
16634: return <<ENDJS;
16635: <script type="text/javascript">
16636: // <![CDATA[
16637: function updateFilters(caller) {
16638: if (typeof(caller) != "undefined") {
16639: document.filterpicker.updater.value = caller.name;
16640: }
16641: document.filterpicker.submit();
16642: }
16643:
16644: function hideSearching() {
16645: if (document.getElementById('searching')) {
16646: document.getElementById('searching').style.display = 'none';
16647: }
16648: return;
16649: }
16650:
16651: // ]]>
16652: </script>
16653:
16654: ENDJS
16655: }
16656:
16657: =pod
16658:
16659: =item * &search_courses()
16660:
16661: Process selected filters form course search form and pass to lonnet::courseiddump
16662: to retrieve a hash for which keys are courseIDs which match the selected filters.
16663:
16664: Inputs:
16665:
16666: dom - domain being searched
16667:
16668: type - course type ('Course' or 'Community' or '.' if any).
16669:
16670: filter - anonymous hash of criteria and their values
16671:
16672: numtitles - for institutional codes - number of categories
16673:
16674: cloneruname - optional username of new course owner
16675:
16676: clonerudom - optional domain of new course owner
16677:
1.1075.2.95 raeburn 16678: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16679: (used when DC is using course creation form)
16680:
16681: codetitles - reference to array of titles of components in institutional codes (official courses).
16682:
1.1075.2.95 raeburn 16683: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16684: (and so can clone automatically)
16685:
16686: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16687:
16688: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16689: courses to clone
1.1075.2.69 raeburn 16690:
16691: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16692:
16693:
16694: Side Effects: None
16695:
16696: =cut
16697:
16698:
16699: sub search_courses {
1.1075.2.95 raeburn 16700: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16701: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16702: my (%courses,%showcourses,$cloner);
16703: if (($filter->{'ownerfilter'} ne '') ||
16704: ($filter->{'ownerdomfilter'} ne '')) {
16705: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16706: $filter->{'ownerdomfilter'};
16707: }
16708: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16709: if (!$filter->{$item}) {
16710: $filter->{$item}='.';
16711: }
16712: }
16713: my $now = time;
16714: my $timefilter =
16715: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16716: my ($createdbefore,$createdafter);
16717: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16718: $createdbefore = $now;
16719: $createdafter = $now-$filter->{'createdfilter'};
16720: }
16721: my ($instcodefilter,$regexpok);
16722: if ($numtitles) {
16723: if ($env{'form.official'} eq 'on') {
16724: $instcodefilter =
16725: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16726: $regexpok = 1;
16727: } elsif ($env{'form.official'} eq 'off') {
16728: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16729: unless ($instcodefilter eq '') {
16730: $regexpok = -1;
16731: }
16732: }
16733: } else {
16734: $instcodefilter = $filter->{'instcodefilter'};
16735: }
16736: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16737: if ($type eq '') { $type = '.'; }
16738:
16739: if (($clonerudom ne '') && ($cloneruname ne '')) {
16740: $cloner = $cloneruname.':'.$clonerudom;
16741: }
16742: %courses = &Apache::lonnet::courseiddump($dom,
16743: $filter->{'descriptfilter'},
16744: $timefilter,
16745: $instcodefilter,
16746: $filter->{'combownerfilter'},
16747: $filter->{'coursefilter'},
16748: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16749: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16750: $filter->{'cloneableonly'},
16751: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16752: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16753: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16754: my $ccrole;
16755: if ($type eq 'Community') {
16756: $ccrole = 'co';
16757: } else {
16758: $ccrole = 'cc';
16759: }
16760: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16761: $filter->{'persondomfilter'},
16762: 'userroles',undef,
16763: [$ccrole,'in','ad','ep','ta','cr'],
16764: $dom);
16765: foreach my $role (keys(%rolehash)) {
16766: my ($cnum,$cdom,$courserole) = split(':',$role);
16767: my $cid = $cdom.'_'.$cnum;
16768: if (exists($courses{$cid})) {
16769: if (ref($courses{$cid}) eq 'HASH') {
16770: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16771: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16772: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16773: }
16774: } else {
16775: $courses{$cid}{roles} = [$courserole];
16776: }
16777: $showcourses{$cid} = $courses{$cid};
16778: }
16779: }
16780: }
16781: %courses = %showcourses;
16782: }
16783: return %courses;
16784: }
16785:
16786: =pod
16787:
16788: =back
16789:
1.1075.2.88 raeburn 16790: =head1 Routines for version requirements for current course.
16791:
16792: =over 4
16793:
16794: =item * &check_release_required()
16795:
16796: Compares required LON-CAPA version with version on server, and
16797: if required version is newer looks for a server with the required version.
16798:
16799: Looks first at servers in user's owen domain; if none suitable, looks at
16800: servers in course's domain are permitted to host sessions for user's domain.
16801:
16802: Inputs:
16803:
16804: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16805:
16806: $courseid - Course ID of current course
16807:
16808: $rolecode - User's current role in course (for switchserver query string).
16809:
16810: $required - LON-CAPA version needed by course (format: Major.Minor).
16811:
16812:
16813: Returns:
16814:
16815: $switchserver - query string tp append to /adm/switchserver call (if
16816: current server's LON-CAPA version is too old.
16817:
16818: $warning - Message is displayed if no suitable server could be found.
16819:
16820: =cut
16821:
16822: sub check_release_required {
16823: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16824: my ($switchserver,$warning);
16825: if ($required ne '') {
16826: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16827: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16828: if ($reqdmajor ne '' && $reqdminor ne '') {
16829: my $otherserver;
16830: if (($major eq '' && $minor eq '') ||
16831: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16832: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16833: my $switchlcrev =
16834: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16835: $userdomserver);
16836: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16837: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16838: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16839: my $cdom = $env{'course.'.$courseid.'.domain'};
16840: if ($cdom ne $env{'user.domain'}) {
16841: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16842: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16843: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16844: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16845: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16846: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16847: my $canhost =
16848: &Apache::lonnet::can_host_session($env{'user.domain'},
16849: $coursedomserver,
16850: $remoterev,
16851: $udomdefaults{'remotesessions'},
16852: $defdomdefaults{'hostedsessions'});
16853:
16854: if ($canhost) {
16855: $otherserver = $coursedomserver;
16856: } else {
16857: $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.");
16858: }
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 your own domain (which is also the course's domain).");
16861: }
16862: } else {
16863: $otherserver = $userdomserver;
16864: }
16865: }
16866: if ($otherserver ne '') {
16867: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16868: }
16869: }
16870: }
16871: return ($switchserver,$warning);
16872: }
16873:
16874: =pod
16875:
16876: =item * &check_release_result()
16877:
16878: Inputs:
16879:
16880: $switchwarning - Warning message if no suitable server found to host session.
16881:
16882: $switchserver - query string to append to /adm/switchserver containing lonHostID
16883: and current role.
16884:
16885: Returns: HTML to display with information about requirement to switch server.
16886: Either displaying warning with link to Roles/Courses screen or
16887: display link to switchserver.
16888:
1.1075.2.69 raeburn 16889: =cut
16890:
1.1075.2.88 raeburn 16891: sub check_release_result {
16892: my ($switchwarning,$switchserver) = @_;
16893: my $output = &start_page('Selected course unavailable on this server').
16894: '<p class="LC_warning">';
16895: if ($switchwarning) {
16896: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16897: if (&show_course()) {
16898: $output .= &mt('Display courses');
16899: } else {
16900: $output .= &mt('Display roles');
16901: }
16902: $output .= '</a>';
16903: } elsif ($switchserver) {
16904: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16905: '<br />'.
16906: '<a href="/adm/switchserver?'.$switchserver.'">'.
16907: &mt('Switch Server').
16908: '</a>';
16909: }
16910: $output .= '</p>'.&end_page();
16911: return $output;
16912: }
16913:
16914: =pod
16915:
16916: =item * &needs_coursereinit()
16917:
16918: Determine if course contents stored for user's session needs to be
16919: refreshed, because content has changed since "Big Hash" last tied.
16920:
16921: Check for change is made if time last checked is more than 10 minutes ago
16922: (by default).
16923:
16924: Inputs:
16925:
16926: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16927:
16928: $interval (optional) - Time which may elapse (in s) between last check for content
16929: change in current course. (default: 600 s).
16930:
16931: Returns: an array; first element is:
16932:
16933: =over 4
16934:
16935: 'switch' - if content updates mean user's session
16936: needs to be switched to a server running a newer LON-CAPA version
16937:
16938: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16939: on current server hosting user's session
16940:
16941: '' - if no action required.
16942:
16943: =back
16944:
16945: If first item element is 'switch':
16946:
16947: second item is $switchwarning - Warning message if no suitable server found to host session.
16948:
16949: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16950: and current role.
16951:
16952: otherwise: no other elements returned.
16953:
16954: =back
16955:
16956: =cut
16957:
16958: sub needs_coursereinit {
16959: my ($loncaparev,$interval) = @_;
16960: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16961: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16962: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16963: my $now = time;
16964: if ($interval eq '') {
16965: $interval = 600;
16966: }
16967: if (($now-$env{'request.course.timechecked'})>$interval) {
16968: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16969: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16970: if ($lastchange > $env{'request.course.tied'}) {
16971: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16972: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16973: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16974: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16975: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16976: $curr_reqd_hash{'internal.releaserequired'}});
16977: my ($switchserver,$switchwarning) =
16978: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16979: $curr_reqd_hash{'internal.releaserequired'});
16980: if ($switchwarning ne '' || $switchserver ne '') {
16981: return ('switch',$switchwarning,$switchserver);
16982: }
16983: }
16984: }
16985: return ('update');
16986: }
16987: }
16988: return ();
16989: }
1.1075.2.69 raeburn 16990:
1.1075.2.11 raeburn 16991: sub update_content_constraints {
16992: my ($cdom,$cnum,$chome,$cid) = @_;
16993: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16994: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16995: my %checkresponsetypes;
16996: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16997: my ($item,$name,$value) = split(/:/,$key);
16998: if ($item eq 'resourcetag') {
16999: if ($name eq 'responsetype') {
17000: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17001: }
17002: }
17003: }
17004: my $navmap = Apache::lonnavmaps::navmap->new();
17005: if (defined($navmap)) {
17006: my %allresponses;
17007: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17008: my %responses = $res->responseTypes();
17009: foreach my $key (keys(%responses)) {
17010: next unless(exists($checkresponsetypes{$key}));
17011: $allresponses{$key} += $responses{$key};
17012: }
17013: }
17014: foreach my $key (keys(%allresponses)) {
17015: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17016: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17017: ($reqdmajor,$reqdminor) = ($major,$minor);
17018: }
17019: }
17020: undef($navmap);
17021: }
17022: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17023: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17024: }
17025: return;
17026: }
17027:
1.1075.2.27 raeburn 17028: sub allmaps_incourse {
17029: my ($cdom,$cnum,$chome,$cid) = @_;
17030: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17031: $cid = $env{'request.course.id'};
17032: $cdom = $env{'course.'.$cid.'.domain'};
17033: $cnum = $env{'course.'.$cid.'.num'};
17034: $chome = $env{'course.'.$cid.'.home'};
17035: }
17036: my %allmaps = ();
17037: my $lastchange =
17038: &Apache::lonnet::get_coursechange($cdom,$cnum);
17039: if ($lastchange > $env{'request.course.tied'}) {
17040: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17041: unless ($ferr) {
17042: &update_content_constraints($cdom,$cnum,$chome,$cid);
17043: }
17044: }
17045: my $navmap = Apache::lonnavmaps::navmap->new();
17046: if (defined($navmap)) {
17047: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17048: $allmaps{$res->src()} = 1;
17049: }
17050: }
17051: return \%allmaps;
17052: }
17053:
1.1075.2.11 raeburn 17054: sub parse_supplemental_title {
17055: my ($title) = @_;
17056:
17057: my ($foldertitle,$renametitle);
17058: if ($title =~ /&&&/) {
17059: $title = &HTML::Entites::decode($title);
17060: }
17061: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17062: $renametitle=$4;
17063: my ($time,$uname,$udom) = ($1,$2,$3);
17064: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17065: my $name = &plainname($uname,$udom);
17066: $name = &HTML::Entities::encode($name,'"<>&\'');
17067: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17068: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17069: $name.': <br />'.$foldertitle;
17070: }
17071: if (wantarray) {
17072: return ($title,$foldertitle,$renametitle);
17073: }
17074: return $title;
17075: }
17076:
1.1075.2.43 raeburn 17077: sub recurse_supplemental {
17078: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
17079: if ($suppmap) {
17080: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17081: if ($fatal) {
17082: $errors ++;
17083: } else {
17084: if ($#LONCAPA::map::resources > 0) {
17085: foreach my $res (@LONCAPA::map::resources) {
17086: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17087: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 17088: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
17089: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 17090: } else {
17091: $numfiles ++;
17092: }
17093: }
17094: }
17095: }
17096: }
17097: }
17098: return ($numfiles,$errors);
17099: }
17100:
1.1075.2.18 raeburn 17101: sub symb_to_docspath {
1.1075.2.119 raeburn 17102: my ($symb,$navmapref) = @_;
17103: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 17104: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17105: if ($resurl=~/\.(sequence|page)$/) {
17106: $mapurl=$resurl;
17107: } elsif ($resurl eq 'adm/navmaps') {
17108: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17109: }
17110: my $mapresobj;
1.1075.2.119 raeburn 17111: unless (ref($$navmapref)) {
17112: $$navmapref = Apache::lonnavmaps::navmap->new();
17113: }
17114: if (ref($$navmapref)) {
17115: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 17116: }
17117: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17118: my $type=$2;
17119: my $path;
17120: if (ref($mapresobj)) {
17121: my $pcslist = $mapresobj->map_hierarchy();
17122: if ($pcslist ne '') {
17123: foreach my $pc (split(/,/,$pcslist)) {
17124: next if ($pc <= 1);
1.1075.2.119 raeburn 17125: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 17126: if (ref($res)) {
17127: my $thisurl = $res->src();
17128: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17129: my $thistitle = $res->title();
17130: $path .= '&'.
17131: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 17132: &escape($thistitle).
1.1075.2.18 raeburn 17133: ':'.$res->randompick().
17134: ':'.$res->randomout().
17135: ':'.$res->encrypted().
17136: ':'.$res->randomorder().
17137: ':'.$res->is_page();
17138: }
17139: }
17140: }
17141: $path =~ s/^\&//;
17142: my $maptitle = $mapresobj->title();
17143: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17144: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17145: }
17146: $path .= (($path ne '')? '&' : '').
17147: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17148: &escape($maptitle).
1.1075.2.18 raeburn 17149: ':'.$mapresobj->randompick().
17150: ':'.$mapresobj->randomout().
17151: ':'.$mapresobj->encrypted().
17152: ':'.$mapresobj->randomorder().
17153: ':'.$mapresobj->is_page();
17154: } else {
17155: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17156: my $ispage = (($type eq 'page')? 1 : '');
17157: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 17158: $maptitle = 'Main Content';
1.1075.2.18 raeburn 17159: }
17160: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 17161: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 17162: }
17163: unless ($mapurl eq 'default') {
17164: $path = 'default&'.
1.1075.2.46 raeburn 17165: &escape('Main Content').
1.1075.2.18 raeburn 17166: ':::::&'.$path;
17167: }
17168: return $path;
17169: }
17170:
1.1075.2.14 raeburn 17171: sub captcha_display {
1.1075.2.137 raeburn 17172: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17173: my ($output,$error);
1.1075.2.107 raeburn 17174: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 17175: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17176: if ($captcha eq 'original') {
17177: $output = &create_captcha();
17178: unless ($output) {
17179: $error = 'captcha';
17180: }
17181: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17182: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 17183: unless ($output) {
17184: $error = 'recaptcha';
17185: }
17186: }
1.1075.2.107 raeburn 17187: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 17188: }
17189:
17190: sub captcha_response {
1.1075.2.137 raeburn 17191: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 17192: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 17193: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 17194: if ($captcha eq 'original') {
17195: ($captcha_chk,$captcha_error) = &check_captcha();
17196: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 17197: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 17198: } else {
17199: $captcha_chk = 1;
17200: }
17201: return ($captcha_chk,$captcha_error);
17202: }
17203:
17204: sub get_captcha_config {
1.1075.2.137 raeburn 17205: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 17206: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 17207: my $hostname = &Apache::lonnet::hostname($lonhost);
17208: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17209: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17210: if ($context eq 'usercreation') {
17211: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17212: if (ref($domconfig{$context}) eq 'HASH') {
17213: $hashtocheck = $domconfig{$context}{'cancreate'};
17214: if (ref($hashtocheck) eq 'HASH') {
17215: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17216: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17217: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17218: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17219: }
17220: if ($privkey && $pubkey) {
17221: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17222: $version = $hashtocheck->{'recaptchaversion'};
17223: if ($version ne '2') {
17224: $version = 1;
17225: }
1.1075.2.14 raeburn 17226: } else {
17227: $captcha = 'original';
17228: }
17229: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17230: $captcha = 'original';
17231: }
17232: }
17233: } else {
17234: $captcha = 'captcha';
17235: }
17236: } elsif ($context eq 'login') {
17237: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17238: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17239: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17240: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
17241: if ($privkey && $pubkey) {
17242: $captcha = 'recaptcha';
1.1075.2.107 raeburn 17243: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17244: if ($version ne '2') {
17245: $version = 1;
17246: }
1.1075.2.14 raeburn 17247: } else {
17248: $captcha = 'original';
17249: }
17250: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17251: $captcha = 'original';
17252: }
1.1075.2.137 raeburn 17253: } elsif ($context eq 'passwords') {
17254: if ($dom_in_effect) {
17255: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
17256: if ($passwdconf{'captcha'} eq 'recaptcha') {
17257: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
17258: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
17259: $privkey = $passwdconf{'recaptchakeys'}{'private'};
17260: }
17261: if ($privkey && $pubkey) {
17262: $captcha = 'recaptcha';
17263: $version = $passwdconf{'recaptchaversion'};
17264: if ($version ne '2') {
17265: $version = 1;
17266: }
17267: } else {
17268: $captcha = 'original';
17269: }
17270: } elsif ($passwdconf{'captcha'} ne 'notused') {
17271: $captcha = 'original';
17272: }
17273: }
1.1075.2.14 raeburn 17274: }
1.1075.2.107 raeburn 17275: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 17276: }
17277:
17278: sub create_captcha {
17279: my %captcha_params = &captcha_settings();
17280: my ($output,$maxtries,$tries) = ('',10,0);
17281: while ($tries < $maxtries) {
17282: $tries ++;
17283: my $captcha = Authen::Captcha->new (
17284: output_folder => $captcha_params{'output_dir'},
17285: data_folder => $captcha_params{'db_dir'},
17286: );
17287: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17288:
17289: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17290: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
1.1075.2.158 raeburn 17291: '<span class="LC_nobreak">'.
1.1075.2.14 raeburn 17292: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 17293: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
1.1075.2.158 raeburn 17294: '</span><br />'.
1.1075.2.66 raeburn 17295: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 17296: last;
17297: }
17298: }
1.1075.2.158 raeburn 17299: if ($output eq '') {
17300: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
17301: }
1.1075.2.14 raeburn 17302: return $output;
17303: }
17304:
17305: sub captcha_settings {
17306: my %captcha_params = (
17307: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17308: www_output_dir => "/captchaspool",
17309: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17310: numchars => '5',
17311: );
17312: return %captcha_params;
17313: }
17314:
17315: sub check_captcha {
17316: my ($captcha_chk,$captcha_error);
17317: my $code = $env{'form.code'};
17318: my $md5sum = $env{'form.crypt'};
17319: my %captcha_params = &captcha_settings();
17320: my $captcha = Authen::Captcha->new(
17321: output_folder => $captcha_params{'output_dir'},
17322: data_folder => $captcha_params{'db_dir'},
17323: );
1.1075.2.26 raeburn 17324: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 17325: my %captcha_hash = (
17326: 0 => 'Code not checked (file error)',
17327: -1 => 'Failed: code expired',
17328: -2 => 'Failed: invalid code (not in database)',
17329: -3 => 'Failed: invalid code (code does not match crypt)',
17330: );
17331: if ($captcha_chk != 1) {
17332: $captcha_error = $captcha_hash{$captcha_chk}
17333: }
17334: return ($captcha_chk,$captcha_error);
17335: }
17336:
17337: sub create_recaptcha {
1.1075.2.107 raeburn 17338: my ($pubkey,$version) = @_;
17339: if ($version >= 2) {
1.1075.2.158 raeburn 17340: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>'.
17341: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.1075.2.107 raeburn 17342: } else {
17343: my $use_ssl;
17344: if ($ENV{'SERVER_PORT'} == 443) {
17345: $use_ssl = 1;
17346: }
17347: my $captcha = Captcha::reCAPTCHA->new;
17348: return $captcha->get_options_setter({theme => 'white'})."\n".
17349: $captcha->get_html($pubkey,undef,$use_ssl).
17350: &mt('If the text is hard to read, [_1] will replace them.',
17351: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17352: '<br /><br />';
17353: }
1.1075.2.14 raeburn 17354: }
17355:
17356: sub check_recaptcha {
1.1075.2.107 raeburn 17357: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 17358: my $captcha_chk;
1.1075.2.150 raeburn 17359: my $ip = &Apache::lonnet::get_requestor_ip();
1.1075.2.107 raeburn 17360: if ($version >= 2) {
17361: my $ua = LWP::UserAgent->new;
17362: $ua->timeout(10);
17363: my %info = (
17364: secret => $privkey,
17365: response => $env{'form.g-recaptcha-response'},
1.1075.2.150 raeburn 17366: remoteip => $ip,
1.1075.2.107 raeburn 17367: );
17368: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17369: if ($response->is_success) {
17370: my $data = JSON::DWIW->from_json($response->decoded_content);
17371: if (ref($data) eq 'HASH') {
17372: if ($data->{'success'}) {
17373: $captcha_chk = 1;
17374: }
17375: }
17376: }
17377: } else {
17378: my $captcha = Captcha::reCAPTCHA->new;
17379: my $captcha_result =
17380: $captcha->check_answer(
17381: $privkey,
1.1075.2.150 raeburn 17382: $ip,
1.1075.2.107 raeburn 17383: $env{'form.recaptcha_challenge_field'},
17384: $env{'form.recaptcha_response_field'},
17385: );
17386: if ($captcha_result->{is_valid}) {
17387: $captcha_chk = 1;
17388: }
1.1075.2.14 raeburn 17389: }
17390: return $captcha_chk;
17391: }
17392:
1.1075.2.64 raeburn 17393: sub emailusername_info {
1.1075.2.103 raeburn 17394: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 17395: my %titles = &Apache::lonlocal::texthash (
17396: lastname => 'Last Name',
17397: firstname => 'First Name',
17398: institution => 'School/college/university',
17399: location => "School's city, state/province, country",
17400: web => "School's web address",
17401: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 17402: id => 'Student/Employee ID',
1.1075.2.64 raeburn 17403: );
17404: return (\@fields,\%titles);
17405: }
17406:
1.1075.2.56 raeburn 17407: sub cleanup_html {
17408: my ($incoming) = @_;
17409: my $outgoing;
17410: if ($incoming ne '') {
17411: $outgoing = $incoming;
17412: $outgoing =~ s/;/;/g;
17413: $outgoing =~ s/\#/#/g;
17414: $outgoing =~ s/\&/&/g;
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: }
17426: return $outgoing;
17427: }
17428:
1.1075.2.74 raeburn 17429: # Checks for critical messages and returns a redirect url if one exists.
17430: # $interval indicates how often to check for messages.
17431: sub critical_redirect {
17432: my ($interval) = @_;
1.1075.2.158 raeburn 17433: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
17434: return ();
17435: }
1.1075.2.74 raeburn 17436: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17437: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17438: $env{'user.name'});
17439: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17440: my $redirecturl;
17441: if ($what[0]) {
1.1075.2.158 raeburn 17442: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1075.2.74 raeburn 17443: $redirecturl='/adm/email?critical=display';
17444: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17445: return (1, $url);
17446: }
17447: }
17448: }
17449: return ();
17450: }
17451:
1.1075.2.64 raeburn 17452: # Use:
17453: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17454: #
17455: ##################################################
17456: # password associated functions #
17457: ##################################################
17458: sub des_keys {
17459: # Make a new key for DES encryption.
17460: # Each key has two parts which are returned separately.
17461: # Please note: Each key must be passed through the &hex function
17462: # before it is output to the web browser. The hex versions cannot
17463: # be used to decrypt.
17464: my @hexstr=('0','1','2','3','4','5','6','7',
17465: '8','9','a','b','c','d','e','f');
17466: my $lkey='';
17467: for (0..7) {
17468: $lkey.=$hexstr[rand(15)];
17469: }
17470: my $ukey='';
17471: for (0..7) {
17472: $ukey.=$hexstr[rand(15)];
17473: }
17474: return ($lkey,$ukey);
17475: }
17476:
17477: sub des_decrypt {
17478: my ($key,$cyphertext) = @_;
17479: my $keybin=pack("H16",$key);
17480: my $cypher;
17481: if ($Crypt::DES::VERSION>=2.03) {
17482: $cypher=new Crypt::DES $keybin;
17483: } else {
17484: $cypher=new DES $keybin;
17485: }
1.1075.2.106 raeburn 17486: my $plaintext='';
17487: my $cypherlength = length($cyphertext);
17488: my $numchunks = int($cypherlength/32);
17489: for (my $j=0; $j<$numchunks; $j++) {
17490: my $start = $j*32;
17491: my $cypherblock = substr($cyphertext,$start,32);
17492: my $chunk =
17493: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17494: $chunk .=
17495: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17496: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17497: $plaintext .= $chunk;
17498: }
1.1075.2.64 raeburn 17499: return $plaintext;
17500: }
17501:
1.1075.2.135 raeburn 17502: sub is_nonframeable {
17503: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
17504: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
17505: return if (($remprotocol eq '') || ($remhost eq ''));
17506:
17507: $remprotocol = lc($remprotocol);
17508: $remhost = lc($remhost);
17509: my $remport = 80;
17510: if ($remprotocol eq 'https') {
17511: $remport = 443;
17512: }
17513: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
17514: if ($cached) {
17515: unless ($nocache) {
17516: if ($result) {
17517: return 1;
17518: } else {
17519: return 0;
17520: }
17521: }
17522: }
17523: my $uselink;
17524: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 17525: my $ua = LWP::UserAgent->new;
17526: $ua->timeout(5);
17527: my $response=$ua->request($request);
1.1075.2.135 raeburn 17528: if ($response->is_success()) {
17529: my $secpolicy = lc($response->header('content-security-policy'));
17530: my $xframeop = lc($response->header('x-frame-options'));
17531: $secpolicy =~ s/^\s+|\s+$//g;
17532: $xframeop =~ s/^\s+|\s+$//g;
17533: if (($secpolicy ne '') || ($xframeop ne '')) {
17534: my $remotehost = $remprotocol.'://'.$remhost;
17535: my ($origin,$protocol,$port);
17536: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17537: $port = $ENV{'SERVER_PORT'};
17538: } else {
17539: $port = 80;
17540: }
17541: if ($absolute eq '') {
17542: $protocol = 'http:';
17543: if ($port == 443) {
17544: $protocol = 'https:';
17545: }
17546: $origin = $protocol.'//'.lc($hostname);
17547: } else {
17548: $origin = lc($absolute);
17549: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17550: }
17551: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17552: my $framepolicy = $1;
17553: $framepolicy =~ s/^\s+|\s+$//g;
17554: my @policies = split(/\s+/,$framepolicy);
17555: if (@policies) {
17556: if (grep(/^\Q'none'\E$/,@policies)) {
17557: $uselink = 1;
17558: } else {
17559: $uselink = 1;
17560: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17561: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17562: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17563: undef($uselink);
17564: }
17565: if ($uselink) {
17566: if (grep(/^\Q'self'\E$/,@policies)) {
17567: if (($origin ne '') && ($remotehost eq $origin)) {
17568: undef($uselink);
17569: }
17570: }
17571: }
17572: if ($uselink) {
17573: my @possok;
17574: if ($ip ne '') {
17575: push(@possok,$ip);
17576: }
17577: my $hoststr = '';
17578: foreach my $part (reverse(split(/\./,$hostname))) {
17579: if ($hoststr eq '') {
17580: $hoststr = $part;
17581: } else {
17582: $hoststr = "$part.$hoststr";
17583: }
17584: if ($hoststr eq $hostname) {
17585: push(@possok,$hostname);
17586: } else {
17587: push(@possok,"*.$hoststr");
17588: }
17589: }
17590: if (@possok) {
17591: foreach my $poss (@possok) {
17592: last if (!$uselink);
17593: foreach my $policy (@policies) {
17594: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17595: undef($uselink);
17596: last;
17597: }
17598: }
17599: }
17600: }
17601: }
17602: }
17603: }
17604: } elsif ($xframeop ne '') {
17605: $uselink = 1;
17606: my @policies = split(/\s*,\s*/,$xframeop);
17607: if (@policies) {
17608: unless (grep(/^deny$/,@policies)) {
17609: if ($origin ne '') {
17610: if (grep(/^sameorigin$/,@policies)) {
17611: if ($remotehost eq $origin) {
17612: undef($uselink);
17613: }
17614: }
17615: if ($uselink) {
17616: foreach my $policy (@policies) {
17617: if ($policy =~ /^allow-from\s*(.+)$/) {
17618: my $allowfrom = $1;
17619: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17620: undef($uselink);
17621: last;
17622: }
17623: }
17624: }
17625: }
17626: }
17627: }
17628: }
17629: }
17630: }
17631: }
17632: if ($nocache) {
17633: if ($cached) {
17634: my $devalidate;
17635: if ($uselink && !$result) {
17636: $devalidate = 1;
17637: } elsif (!$uselink && $result) {
17638: $devalidate = 1;
17639: }
17640: if ($devalidate) {
17641: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17642: }
17643: }
17644: } else {
17645: if ($uselink) {
17646: $result = 1;
17647: } else {
17648: $result = 0;
17649: }
17650: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17651: }
17652: return $uselink;
17653: }
17654:
1.112 bowersj2 17655: 1;
17656: __END__;
1.41 ng 17657:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>