Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.144
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.144! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.143 2020/02/12 17:22:55 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 {
1381: my ($text) = @_;
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.56 raeburn 1397: <a href="$link" title="$title">$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: }
3130: $autharg = '<input type="text" 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.281 albertel 3134: '<label><input type="radio" name="login" value="fsys" '.
1.1075.2.117 raeburn 3135: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />',
1.605 bisitz 3136: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.1075.2.117 raeburn 3137: 'onchange="'.$jscall.'"'.$disabled.' />');
1.32 matthew 3138: return $result;
3139: }
3140:
1.586 raeburn 3141: sub get_assignable_auth {
3142: my ($dom) = @_;
3143: if ($dom eq '') {
3144: $dom = $env{'request.role.domain'};
3145: }
3146: my %can_assign = (
3147: krb4 => 1,
3148: krb5 => 1,
3149: int => 1,
3150: loc => 1,
3151: );
3152: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3153: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3154: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3155: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3156: my $context;
3157: if ($env{'request.role'} =~ /^au/) {
3158: $context = 'author';
1.1075.2.117 raeburn 3159: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3160: $context = 'domain';
3161: } elsif ($env{'request.course.id'}) {
3162: $context = 'course';
3163: }
3164: if ($context) {
3165: if (ref($authhash->{$context}) eq 'HASH') {
3166: %can_assign = %{$authhash->{$context}};
3167: }
3168: }
3169: }
3170: }
3171: my $authnum = 0;
3172: foreach my $key (keys(%can_assign)) {
3173: if ($can_assign{$key}) {
3174: $authnum ++;
3175: }
3176: }
3177: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3178: $authnum --;
3179: }
3180: return ($authnum,%can_assign);
3181: }
3182:
1.1075.2.137 raeburn 3183: sub check_passwd_rules {
3184: my ($domain,$plainpass) = @_;
3185: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3186: my ($min,$max,@chars,@brokerule,$warning);
1.1075.2.138 raeburn 3187: $min = $Apache::lonnet::passwdmin;
1.1075.2.137 raeburn 3188: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3189: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1075.2.138 raeburn 3190: if ($passwdconf{'min'} > $min) {
3191: $min = $passwdconf{'min'};
3192: }
1.1075.2.137 raeburn 3193: }
3194: if ($passwdconf{'max'} =~ /^\d+$/) {
3195: $max = $passwdconf{'max'};
3196: }
3197: @chars = @{$passwdconf{'chars'}};
3198: }
3199: if (($min) && (length($plainpass) < $min)) {
3200: push(@brokerule,'min');
3201: }
3202: if (($max) && (length($plainpass) > $max)) {
3203: push(@brokerule,'max');
3204: }
3205: if (@chars) {
3206: my %rules;
3207: map { $rules{$_} = 1; } @chars;
3208: if ($rules{'uc'}) {
3209: unless ($plainpass =~ /[A-Z]/) {
3210: push(@brokerule,'uc');
3211: }
3212: }
3213: if ($rules{'lc'}) {
3214: unless ($plainpass =~ /[a-z]/) {
3215: push(@brokerule,'lc');
3216: }
3217: }
3218: if ($rules{'num'}) {
3219: unless ($plainpass =~ /\d/) {
3220: push(@brokerule,'num');
3221: }
3222: }
3223: if ($rules{'spec'}) {
3224: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3225: push(@brokerule,'spec');
3226: }
3227: }
3228: }
3229: if (@brokerule) {
3230: my %rulenames = &Apache::lonlocal::texthash(
3231: uc => 'At least one upper case letter',
3232: lc => 'At least one lower case letter',
3233: num => 'At least one number',
3234: spec => 'At least one non-alphanumeric',
3235: );
3236: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3237: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3238: $rulenames{'num'} .= ': 0123456789';
3239: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3240: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3241: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3242: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1075.2.143 raeburn 3243: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1075.2.137 raeburn 3244: if (grep(/^$rule$/,@brokerule)) {
3245: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3246: }
3247: }
3248: $warning .= '</ul>';
3249: }
3250: if (wantarray) {
3251: return @brokerule;
3252: }
3253: return $warning;
3254: }
3255:
1.80 albertel 3256: ###############################################################
3257: ## Get Kerberos Defaults for Domain ##
3258: ###############################################################
3259: ##
3260: ## Returns default kerberos version and an associated argument
3261: ## as listed in file domain.tab. If not listed, provides
3262: ## appropriate default domain and kerberos version.
3263: ##
3264: #-------------------------------------------
3265:
3266: =pod
3267:
1.648 raeburn 3268: =item * &get_kerberos_defaults()
1.80 albertel 3269:
3270: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3271: version and domain. If not found, it defaults to version 4 and the
3272: domain of the server.
1.80 albertel 3273:
1.648 raeburn 3274: =over 4
3275:
1.80 albertel 3276: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3277:
1.648 raeburn 3278: =back
3279:
3280: =back
3281:
1.80 albertel 3282: =cut
3283:
3284: #-------------------------------------------
3285: sub get_kerberos_defaults {
3286: my $domain=shift;
1.641 raeburn 3287: my ($krbdef,$krbdefdom);
3288: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3289: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3290: $krbdef = $domdefaults{'auth_def'};
3291: $krbdefdom = $domdefaults{'auth_arg_def'};
3292: } else {
1.80 albertel 3293: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3294: my $krbdefdom=$1;
3295: $krbdefdom=~tr/a-z/A-Z/;
3296: $krbdef = "krb4";
3297: }
3298: return ($krbdef,$krbdefdom);
3299: }
1.112 bowersj2 3300:
1.32 matthew 3301:
1.46 matthew 3302: ###############################################################
3303: ## Thesaurus Functions ##
3304: ###############################################################
1.20 www 3305:
1.46 matthew 3306: =pod
1.20 www 3307:
1.112 bowersj2 3308: =head1 Thesaurus Functions
3309:
3310: =over 4
3311:
1.648 raeburn 3312: =item * &initialize_keywords()
1.46 matthew 3313:
3314: Initializes the package variable %Keywords if it is empty. Uses the
3315: package variable $thesaurus_db_file.
3316:
3317: =cut
3318:
3319: ###################################################
3320:
3321: sub initialize_keywords {
3322: return 1 if (scalar keys(%Keywords));
3323: # If we are here, %Keywords is empty, so fill it up
3324: # Make sure the file we need exists...
3325: if (! -e $thesaurus_db_file) {
3326: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3327: " failed because it does not exist");
3328: return 0;
3329: }
3330: # Set up the hash as a database
3331: my %thesaurus_db;
3332: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3333: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3334: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3335: $thesaurus_db_file);
3336: return 0;
3337: }
3338: # Get the average number of appearances of a word.
3339: my $avecount = $thesaurus_db{'average.count'};
3340: # Put keywords (those that appear > average) into %Keywords
3341: while (my ($word,$data)=each (%thesaurus_db)) {
3342: my ($count,undef) = split /:/,$data;
3343: $Keywords{$word}++ if ($count > $avecount);
3344: }
3345: untie %thesaurus_db;
3346: # Remove special values from %Keywords.
1.356 albertel 3347: foreach my $value ('total.count','average.count') {
3348: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3349: }
1.46 matthew 3350: return 1;
3351: }
3352:
3353: ###################################################
3354:
3355: =pod
3356:
1.648 raeburn 3357: =item * &keyword($word)
1.46 matthew 3358:
3359: Returns true if $word is a keyword. A keyword is a word that appears more
3360: than the average number of times in the thesaurus database. Calls
3361: &initialize_keywords
3362:
3363: =cut
3364:
3365: ###################################################
1.20 www 3366:
3367: sub keyword {
1.46 matthew 3368: return if (!&initialize_keywords());
3369: my $word=lc(shift());
3370: $word=~s/\W//g;
3371: return exists($Keywords{$word});
1.20 www 3372: }
1.46 matthew 3373:
3374: ###############################################################
3375:
3376: =pod
1.20 www 3377:
1.648 raeburn 3378: =item * &get_related_words()
1.46 matthew 3379:
1.160 matthew 3380: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3381: an array of words. If the keyword is not in the thesaurus, an empty array
3382: will be returned. The order of the words returned is determined by the
3383: database which holds them.
3384:
3385: Uses global $thesaurus_db_file.
3386:
1.1057 foxr 3387:
1.46 matthew 3388: =cut
3389:
3390: ###############################################################
3391: sub get_related_words {
3392: my $keyword = shift;
3393: my %thesaurus_db;
3394: if (! -e $thesaurus_db_file) {
3395: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3396: "failed because the file does not exist");
3397: return ();
3398: }
3399: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3400: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3401: return ();
3402: }
3403: my @Words=();
1.429 www 3404: my $count=0;
1.46 matthew 3405: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3406: # The first element is the number of times
3407: # the word appears. We do not need it now.
1.429 www 3408: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3409: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3410: my $threshold=$mostfrequentcount/10;
3411: foreach my $possibleword (@RelatedWords) {
3412: my ($word,$wordcount)=split(/\,/,$possibleword);
3413: if ($wordcount>$threshold) {
3414: push(@Words,$word);
3415: $count++;
3416: if ($count>10) { last; }
3417: }
1.20 www 3418: }
3419: }
1.46 matthew 3420: untie %thesaurus_db;
3421: return @Words;
1.14 harris41 3422: }
1.46 matthew 3423:
1.112 bowersj2 3424: =pod
3425:
3426: =back
3427:
3428: =cut
1.61 www 3429:
3430: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3431: =pod
3432:
1.112 bowersj2 3433: =head1 User Name Functions
3434:
3435: =over 4
3436:
1.648 raeburn 3437: =item * &plainname($uname,$udom,$first)
1.81 albertel 3438:
1.112 bowersj2 3439: Takes a users logon name and returns it as a string in
1.226 albertel 3440: "first middle last generation" form
3441: if $first is set to 'lastname' then it returns it as
3442: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3443:
3444: =cut
1.61 www 3445:
1.295 www 3446:
1.81 albertel 3447: ###############################################################
1.61 www 3448: sub plainname {
1.226 albertel 3449: my ($uname,$udom,$first)=@_;
1.537 albertel 3450: return if (!defined($uname) || !defined($udom));
1.295 www 3451: my %names=&getnames($uname,$udom);
1.226 albertel 3452: my $name=&Apache::lonnet::format_name($names{'firstname'},
3453: $names{'middlename'},
3454: $names{'lastname'},
3455: $names{'generation'},$first);
3456: $name=~s/^\s+//;
1.62 www 3457: $name=~s/\s+$//;
3458: $name=~s/\s+/ /g;
1.353 albertel 3459: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3460: return $name;
1.61 www 3461: }
1.66 www 3462:
3463: # -------------------------------------------------------------------- Nickname
1.81 albertel 3464: =pod
3465:
1.648 raeburn 3466: =item * &nickname($uname,$udom)
1.81 albertel 3467:
3468: Gets a users name and returns it as a string as
3469:
3470: ""nickname""
1.66 www 3471:
1.81 albertel 3472: if the user has a nickname or
3473:
3474: "first middle last generation"
3475:
3476: if the user does not
3477:
3478: =cut
1.66 www 3479:
3480: sub nickname {
3481: my ($uname,$udom)=@_;
1.537 albertel 3482: return if (!defined($uname) || !defined($udom));
1.295 www 3483: my %names=&getnames($uname,$udom);
1.68 albertel 3484: my $name=$names{'nickname'};
1.66 www 3485: if ($name) {
3486: $name='"'.$name.'"';
3487: } else {
3488: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3489: $names{'lastname'}.' '.$names{'generation'};
3490: $name=~s/\s+$//;
3491: $name=~s/\s+/ /g;
3492: }
3493: return $name;
3494: }
3495:
1.295 www 3496: sub getnames {
3497: my ($uname,$udom)=@_;
1.537 albertel 3498: return if (!defined($uname) || !defined($udom));
1.433 albertel 3499: if ($udom eq 'public' && $uname eq 'public') {
3500: return ('lastname' => &mt('Public'));
3501: }
1.295 www 3502: my $id=$uname.':'.$udom;
3503: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3504: if ($cached) {
3505: return %{$names};
3506: } else {
3507: my %loadnames=&Apache::lonnet::get('environment',
3508: ['firstname','middlename','lastname','generation','nickname'],
3509: $udom,$uname);
3510: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3511: return %loadnames;
3512: }
3513: }
1.61 www 3514:
1.542 raeburn 3515: # -------------------------------------------------------------------- getemails
1.648 raeburn 3516:
1.542 raeburn 3517: =pod
3518:
1.648 raeburn 3519: =item * &getemails($uname,$udom)
1.542 raeburn 3520:
3521: Gets a user's email information and returns it as a hash with keys:
3522: notification, critnotification, permanentemail
3523:
3524: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3525: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3526:
1.648 raeburn 3527:
1.542 raeburn 3528: =cut
3529:
1.648 raeburn 3530:
1.466 albertel 3531: sub getemails {
3532: my ($uname,$udom)=@_;
3533: if ($udom eq 'public' && $uname eq 'public') {
3534: return;
3535: }
1.467 www 3536: if (!$udom) { $udom=$env{'user.domain'}; }
3537: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3538: my $id=$uname.':'.$udom;
3539: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3540: if ($cached) {
3541: return %{$names};
3542: } else {
3543: my %loadnames=&Apache::lonnet::get('environment',
3544: ['notification','critnotification',
3545: 'permanentemail'],
3546: $udom,$uname);
3547: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3548: return %loadnames;
3549: }
3550: }
3551:
1.551 albertel 3552: sub flush_email_cache {
3553: my ($uname,$udom)=@_;
3554: if (!$udom) { $udom =$env{'user.domain'}; }
3555: if (!$uname) { $uname=$env{'user.name'}; }
3556: return if ($udom eq 'public' && $uname eq 'public');
3557: my $id=$uname.':'.$udom;
3558: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3559: }
3560:
1.728 raeburn 3561: # -------------------------------------------------------------------- getlangs
3562:
3563: =pod
3564:
3565: =item * &getlangs($uname,$udom)
3566:
3567: Gets a user's language preference and returns it as a hash with key:
3568: language.
3569:
3570: =cut
3571:
3572:
3573: sub getlangs {
3574: my ($uname,$udom) = @_;
3575: if (!$udom) { $udom =$env{'user.domain'}; }
3576: if (!$uname) { $uname=$env{'user.name'}; }
3577: my $id=$uname.':'.$udom;
3578: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3579: if ($cached) {
3580: return %{$langs};
3581: } else {
3582: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3583: $udom,$uname);
3584: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3585: return %loadlangs;
3586: }
3587: }
3588:
3589: sub flush_langs_cache {
3590: my ($uname,$udom)=@_;
3591: if (!$udom) { $udom =$env{'user.domain'}; }
3592: if (!$uname) { $uname=$env{'user.name'}; }
3593: return if ($udom eq 'public' && $uname eq 'public');
3594: my $id=$uname.':'.$udom;
3595: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3596: }
3597:
1.61 www 3598: # ------------------------------------------------------------------ Screenname
1.81 albertel 3599:
3600: =pod
3601:
1.648 raeburn 3602: =item * &screenname($uname,$udom)
1.81 albertel 3603:
3604: Gets a users screenname and returns it as a string
3605:
3606: =cut
1.61 www 3607:
3608: sub screenname {
3609: my ($uname,$udom)=@_;
1.258 albertel 3610: if ($uname eq $env{'user.name'} &&
3611: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3612: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3613: return $names{'screenname'};
1.62 www 3614: }
3615:
1.212 albertel 3616:
1.802 bisitz 3617: # ------------------------------------------------------------- Confirm Wrapper
3618: =pod
3619:
1.1075.2.42 raeburn 3620: =item * &confirmwrapper($message)
1.802 bisitz 3621:
3622: Wrap messages about completion of operation in box
3623:
3624: =cut
3625:
3626: sub confirmwrapper {
3627: my ($message)=@_;
3628: if ($message) {
3629: return "\n".'<div class="LC_confirm_box">'."\n"
3630: .$message."\n"
3631: .'</div>'."\n";
3632: } else {
3633: return $message;
3634: }
3635: }
3636:
1.62 www 3637: # ------------------------------------------------------------- Message Wrapper
3638:
3639: sub messagewrapper {
1.369 www 3640: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3641: return
1.441 albertel 3642: '<a href="/adm/email?compose=individual&'.
3643: 'recname='.$username.'&recdom='.$domain.
3644: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3645: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3646: }
1.802 bisitz 3647:
1.74 www 3648: # --------------------------------------------------------------- Notes Wrapper
3649:
3650: sub noteswrapper {
3651: my ($link,$un,$do)=@_;
3652: return
1.896 amueller 3653: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3654: }
1.802 bisitz 3655:
1.62 www 3656: # ------------------------------------------------------------- Aboutme Wrapper
3657:
3658: sub aboutmewrapper {
1.1070 raeburn 3659: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3660: if (!defined($username) && !defined($domain)) {
3661: return;
3662: }
1.1075.2.15 raeburn 3663: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3664: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3665: }
3666:
3667: # ------------------------------------------------------------ Syllabus Wrapper
3668:
3669: sub syllabuswrapper {
1.707 bisitz 3670: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3671: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3672: }
1.14 harris41 3673:
1.802 bisitz 3674: # -----------------------------------------------------------------------------
3675:
1.208 matthew 3676: sub track_student_link {
1.887 raeburn 3677: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3678: my $link ="/adm/trackstudent?";
1.208 matthew 3679: my $title = 'View recent activity';
3680: if (defined($sname) && $sname !~ /^\s*$/ &&
3681: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3682: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3683: $title .= ' of this student';
1.268 albertel 3684: }
1.208 matthew 3685: if (defined($target) && $target !~ /^\s*$/) {
3686: $target = qq{target="$target"};
3687: } else {
3688: $target = '';
3689: }
1.268 albertel 3690: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3691: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3692: $title = &mt($title);
3693: $linktext = &mt($linktext);
1.448 albertel 3694: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3695: &help_open_topic('View_recent_activity');
1.208 matthew 3696: }
3697:
1.781 raeburn 3698: sub slot_reservations_link {
3699: my ($linktext,$sname,$sdom,$target) = @_;
3700: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3701: my $title = 'View slot reservation history';
3702: if (defined($sname) && $sname !~ /^\s*$/ &&
3703: defined($sdom) && $sdom !~ /^\s*$/) {
3704: $link .= "&uname=$sname&udom=$sdom";
3705: $title .= ' of this student';
3706: }
3707: if (defined($target) && $target !~ /^\s*$/) {
3708: $target = qq{target="$target"};
3709: } else {
3710: $target = '';
3711: }
3712: $title = &mt($title);
3713: $linktext = &mt($linktext);
3714: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3715: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3716:
3717: }
3718:
1.508 www 3719: # ===================================================== Display a student photo
3720:
3721:
1.509 albertel 3722: sub student_image_tag {
1.508 www 3723: my ($domain,$user)=@_;
3724: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3725: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3726: return '<img src="'.$imgsrc.'" align="right" />';
3727: } else {
3728: return '';
3729: }
3730: }
3731:
1.112 bowersj2 3732: =pod
3733:
3734: =back
3735:
3736: =head1 Access .tab File Data
3737:
3738: =over 4
3739:
1.648 raeburn 3740: =item * &languageids()
1.112 bowersj2 3741:
3742: returns list of all language ids
3743:
3744: =cut
3745:
1.14 harris41 3746: sub languageids {
1.16 harris41 3747: return sort(keys(%language));
1.14 harris41 3748: }
3749:
1.112 bowersj2 3750: =pod
3751:
1.648 raeburn 3752: =item * &languagedescription()
1.112 bowersj2 3753:
3754: returns description of a specified language id
3755:
3756: =cut
3757:
1.14 harris41 3758: sub languagedescription {
1.125 www 3759: my $code=shift;
3760: return ($supported_language{$code}?'* ':'').
3761: $language{$code}.
1.126 www 3762: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3763: }
3764:
1.1048 foxr 3765: =pod
3766:
3767: =item * &plainlanguagedescription
3768:
3769: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3770: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3771:
3772: =cut
3773:
1.145 www 3774: sub plainlanguagedescription {
3775: my $code=shift;
3776: return $language{$code};
3777: }
3778:
1.1048 foxr 3779: =pod
3780:
3781: =item * &supportedlanguagecode
3782:
3783: Returns the supported language code (e.g. sptutf maps to pt) given a language
3784: code.
3785:
3786: =cut
3787:
1.145 www 3788: sub supportedlanguagecode {
3789: my $code=shift;
3790: return $supported_language{$code};
1.97 www 3791: }
3792:
1.112 bowersj2 3793: =pod
3794:
1.1048 foxr 3795: =item * &latexlanguage()
3796:
3797: Given a language key code returns the correspondnig language to use
3798: to select the correct hyphenation on LaTeX printouts. This is undef if there
3799: is no supported hyphenation for the language code.
3800:
3801: =cut
3802:
3803: sub latexlanguage {
3804: my $code = shift;
3805: return $latex_language{$code};
3806: }
3807:
3808: =pod
3809:
3810: =item * &latexhyphenation()
3811:
3812: Same as above but what's supplied is the language as it might be stored
3813: in the metadata.
3814:
3815: =cut
3816:
3817: sub latexhyphenation {
3818: my $key = shift;
3819: return $latex_language_bykey{$key};
3820: }
3821:
3822: =pod
3823:
1.648 raeburn 3824: =item * ©rightids()
1.112 bowersj2 3825:
3826: returns list of all copyrights
3827:
3828: =cut
3829:
3830: sub copyrightids {
3831: return sort(keys(%cprtag));
3832: }
3833:
3834: =pod
3835:
1.648 raeburn 3836: =item * ©rightdescription()
1.112 bowersj2 3837:
3838: returns description of a specified copyright id
3839:
3840: =cut
3841:
3842: sub copyrightdescription {
1.166 www 3843: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3844: }
1.197 matthew 3845:
3846: =pod
3847:
1.648 raeburn 3848: =item * &source_copyrightids()
1.192 taceyjo1 3849:
3850: returns list of all source copyrights
3851:
3852: =cut
3853:
3854: sub source_copyrightids {
3855: return sort(keys(%scprtag));
3856: }
3857:
3858: =pod
3859:
1.648 raeburn 3860: =item * &source_copyrightdescription()
1.192 taceyjo1 3861:
3862: returns description of a specified source copyright id
3863:
3864: =cut
3865:
3866: sub source_copyrightdescription {
3867: return &mt($scprtag{shift(@_)});
3868: }
1.112 bowersj2 3869:
3870: =pod
3871:
1.648 raeburn 3872: =item * &filecategories()
1.112 bowersj2 3873:
3874: returns list of all file categories
3875:
3876: =cut
3877:
3878: sub filecategories {
3879: return sort(keys(%category_extensions));
3880: }
3881:
3882: =pod
3883:
1.648 raeburn 3884: =item * &filecategorytypes()
1.112 bowersj2 3885:
3886: returns list of file types belonging to a given file
3887: category
3888:
3889: =cut
3890:
3891: sub filecategorytypes {
1.356 albertel 3892: my ($cat) = @_;
3893: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3894: }
3895:
3896: =pod
3897:
1.648 raeburn 3898: =item * &fileembstyle()
1.112 bowersj2 3899:
3900: returns embedding style for a specified file type
3901:
3902: =cut
3903:
3904: sub fileembstyle {
3905: return $fe{lc(shift(@_))};
1.169 www 3906: }
3907:
1.351 www 3908: sub filemimetype {
3909: return $fm{lc(shift(@_))};
3910: }
3911:
1.169 www 3912:
3913: sub filecategoryselect {
3914: my ($name,$value)=@_;
1.189 matthew 3915: return &select_form($value,$name,
1.970 raeburn 3916: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3917: }
3918:
3919: =pod
3920:
1.648 raeburn 3921: =item * &filedescription()
1.112 bowersj2 3922:
3923: returns description for a specified file type
3924:
3925: =cut
3926:
3927: sub filedescription {
1.188 matthew 3928: my $file_description = $fd{lc(shift())};
3929: $file_description =~ s:([\[\]]):~$1:g;
3930: return &mt($file_description);
1.112 bowersj2 3931: }
3932:
3933: =pod
3934:
1.648 raeburn 3935: =item * &filedescriptionex()
1.112 bowersj2 3936:
3937: returns description for a specified file type with
3938: extra formatting
3939:
3940: =cut
3941:
3942: sub filedescriptionex {
3943: my $ex=shift;
1.188 matthew 3944: my $file_description = $fd{lc($ex)};
3945: $file_description =~ s:([\[\]]):~$1:g;
3946: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3947: }
3948:
3949: # End of .tab access
3950: =pod
3951:
3952: =back
3953:
3954: =cut
3955:
3956: # ------------------------------------------------------------------ File Types
3957: sub fileextensions {
3958: return sort(keys(%fe));
3959: }
3960:
1.97 www 3961: # ----------------------------------------------------------- Display Languages
3962: # returns a hash with all desired display languages
3963: #
3964:
3965: sub display_languages {
3966: my %languages=();
1.695 raeburn 3967: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3968: $languages{$lang}=1;
1.97 www 3969: }
3970: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3971: if ($env{'form.displaylanguage'}) {
1.356 albertel 3972: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3973: $languages{$lang}=1;
1.97 www 3974: }
3975: }
3976: return %languages;
1.14 harris41 3977: }
3978:
1.582 albertel 3979: sub languages {
3980: my ($possible_langs) = @_;
1.695 raeburn 3981: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3982: if (!ref($possible_langs)) {
3983: if( wantarray ) {
3984: return @preferred_langs;
3985: } else {
3986: return $preferred_langs[0];
3987: }
3988: }
3989: my %possibilities = map { $_ => 1 } (@$possible_langs);
3990: my @preferred_possibilities;
3991: foreach my $preferred_lang (@preferred_langs) {
3992: if (exists($possibilities{$preferred_lang})) {
3993: push(@preferred_possibilities, $preferred_lang);
3994: }
3995: }
3996: if( wantarray ) {
3997: return @preferred_possibilities;
3998: }
3999: return $preferred_possibilities[0];
4000: }
4001:
1.742 raeburn 4002: sub user_lang {
4003: my ($touname,$toudom,$fromcid) = @_;
4004: my @userlangs;
4005: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4006: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4007: $env{'course.'.$fromcid.'.languages'}));
4008: } else {
4009: my %langhash = &getlangs($touname,$toudom);
4010: if ($langhash{'languages'} ne '') {
4011: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4012: } else {
4013: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4014: if ($domdefs{'lang_def'} ne '') {
4015: @userlangs = ($domdefs{'lang_def'});
4016: }
4017: }
4018: }
4019: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4020: my $user_lh = Apache::localize->get_handle(@languages);
4021: return $user_lh;
4022: }
4023:
4024:
1.112 bowersj2 4025: ###############################################################
4026: ## Student Answer Attempts ##
4027: ###############################################################
4028:
4029: =pod
4030:
4031: =head1 Alternate Problem Views
4032:
4033: =over 4
4034:
1.648 raeburn 4035: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 4036: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4037:
4038: Return string with previous attempt on problem. Arguments:
4039:
4040: =over 4
4041:
4042: =item * $symb: Problem, including path
4043:
4044: =item * $username: username of the desired student
4045:
4046: =item * $domain: domain of the desired student
1.14 harris41 4047:
1.112 bowersj2 4048: =item * $course: Course ID
1.14 harris41 4049:
1.112 bowersj2 4050: =item * $getattempt: Leave blank for all attempts, otherwise put
4051: something
1.14 harris41 4052:
1.112 bowersj2 4053: =item * $regexp: if string matches this regexp, the string will be
4054: sent to $gradesub
1.14 harris41 4055:
1.112 bowersj2 4056: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4057:
1.1075.2.86 raeburn 4058: =item * $usec: section of the desired student
4059:
4060: =item * $identifier: counter for student (multiple students one problem) or
4061: problem (one student; whole sequence).
4062:
1.112 bowersj2 4063: =back
1.14 harris41 4064:
1.112 bowersj2 4065: The output string is a table containing all desired attempts, if any.
1.16 harris41 4066:
1.112 bowersj2 4067: =cut
1.1 albertel 4068:
4069: sub get_previous_attempt {
1.1075.2.86 raeburn 4070: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4071: my $prevattempts='';
1.43 ng 4072: no strict 'refs';
1.1 albertel 4073: if ($symb) {
1.3 albertel 4074: my (%returnhash)=
4075: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4076: if ($returnhash{'version'}) {
4077: my %lasthash=();
4078: my $version;
4079: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 4080: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4081: if ($key =~ /\.rawrndseed$/) {
4082: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4083: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4084: } else {
4085: $lasthash{$key}=$returnhash{$version.':'.$key};
4086: }
1.19 harris41 4087: }
1.1 albertel 4088: }
1.596 albertel 4089: $prevattempts=&start_data_table().&start_data_table_header_row();
4090: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4091: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4092: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4093: foreach my $key (sort(keys(%lasthash))) {
4094: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4095: if ($#parts > 0) {
1.31 albertel 4096: my $data=$parts[-1];
1.989 raeburn 4097: next if ($data eq 'foilorder');
1.31 albertel 4098: pop(@parts);
1.1010 www 4099: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4100: if ($data eq 'type') {
4101: unless ($showsurv) {
4102: my $id = join(',',@parts);
4103: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4104: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4105: $lasthidden{$ign.'.'.$id} = 1;
4106: }
1.945 raeburn 4107: }
1.1075.2.86 raeburn 4108: if ($identifier ne '') {
4109: my $id = join(',',@parts);
4110: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4111: $domain,$username,$usec,undef,$course) =~ /^no/) {
4112: $hidestatus{$ign.'.'.$id} = 1;
4113: }
4114: }
4115: } elsif ($data eq 'regrader') {
4116: if (($identifier ne '') && (@parts)) {
4117: my $id = join(',',@parts);
4118: $regraded{$ign.'.'.$id} = 1;
4119: }
1.1010 www 4120: }
1.31 albertel 4121: } else {
1.41 ng 4122: if ($#parts == 0) {
4123: $prevattempts.='<th>'.$parts[0].'</th>';
4124: } else {
4125: $prevattempts.='<th>'.$ign.'</th>';
4126: }
1.31 albertel 4127: }
1.16 harris41 4128: }
1.596 albertel 4129: $prevattempts.=&end_data_table_header_row();
1.40 ng 4130: if ($getattempt eq '') {
1.1075.2.86 raeburn 4131: my (%solved,%resets,%probstatus);
4132: if (($identifier ne '') && (keys(%regraded) > 0)) {
4133: for ($version=1;$version<=$returnhash{'version'};$version++) {
4134: foreach my $id (keys(%regraded)) {
4135: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4136: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4137: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4138: push(@{$resets{$id}},$version);
4139: }
4140: }
4141: }
4142: }
1.40 ng 4143: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4144: my (@hidden,@unsolved);
1.945 raeburn 4145: if (%typeparts) {
4146: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4147: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4148: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4149: push(@hidden,$id);
1.1075.2.86 raeburn 4150: } elsif ($identifier ne '') {
4151: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4152: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4153: ($hidestatus{$id})) {
4154: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4155: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4156: push(@{$solved{$id}},$version);
4157: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4158: (ref($solved{$id}) eq 'ARRAY')) {
4159: my $skip;
4160: if (ref($resets{$id}) eq 'ARRAY') {
4161: foreach my $reset (@{$resets{$id}}) {
4162: if ($reset > $solved{$id}[-1]) {
4163: $skip=1;
4164: last;
4165: }
4166: }
4167: }
4168: unless ($skip) {
4169: my ($ign,$partslist) = split(/\./,$id,2);
4170: push(@unsolved,$partslist);
4171: }
4172: }
4173: }
1.945 raeburn 4174: }
4175: }
4176: }
4177: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4178: '<td>'.&mt('Transaction [_1]',$version);
4179: if (@unsolved) {
4180: $prevattempts .= '<span class="LC_nobreak"><label>'.
4181: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4182: &mt('Hide').'</label></span>';
4183: }
4184: $prevattempts .= '</td>';
1.945 raeburn 4185: if (@hidden) {
4186: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4187: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4188: my $hide;
4189: foreach my $id (@hidden) {
4190: if ($key =~ /^\Q$id\E/) {
4191: $hide = 1;
4192: last;
4193: }
4194: }
4195: if ($hide) {
4196: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4197: if (($data eq 'award') || ($data eq 'awarddetail')) {
4198: my $value = &format_previous_attempt_value($key,
4199: $returnhash{$version.':'.$key});
4200: $prevattempts.='<td>'.$value.' </td>';
4201: } else {
4202: $prevattempts.='<td> </td>';
4203: }
4204: } else {
4205: if ($key =~ /\./) {
1.1075.2.91 raeburn 4206: my $value = $returnhash{$version.':'.$key};
4207: if ($key =~ /\.rndseed$/) {
4208: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4209: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4210: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4211: }
4212: }
4213: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4214: ' </td>';
1.945 raeburn 4215: } else {
4216: $prevattempts.='<td> </td>';
4217: }
4218: }
4219: }
4220: } else {
4221: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4222: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4223: my $value = $returnhash{$version.':'.$key};
4224: if ($key =~ /\.rndseed$/) {
4225: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4226: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4227: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4228: }
4229: }
4230: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4231: ' </td>';
1.945 raeburn 4232: }
4233: }
4234: $prevattempts.=&end_data_table_row();
1.40 ng 4235: }
1.1 albertel 4236: }
1.945 raeburn 4237: my @currhidden = keys(%lasthidden);
1.596 albertel 4238: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4239: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4240: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4241: if (%typeparts) {
4242: my $hidden;
4243: foreach my $id (@currhidden) {
4244: if ($key =~ /^\Q$id\E/) {
4245: $hidden = 1;
4246: last;
4247: }
4248: }
4249: if ($hidden) {
4250: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4251: if (($data eq 'award') || ($data eq 'awarddetail')) {
4252: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4253: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4254: $value = &$gradesub($value);
4255: }
4256: $prevattempts.='<td>'.$value.' </td>';
4257: } else {
4258: $prevattempts.='<td> </td>';
4259: }
4260: } else {
4261: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4262: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4263: $value = &$gradesub($value);
4264: }
4265: $prevattempts.='<td>'.$value.' </td>';
4266: }
4267: } else {
4268: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4269: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4270: $value = &$gradesub($value);
4271: }
4272: $prevattempts.='<td>'.$value.' </td>';
4273: }
1.16 harris41 4274: }
1.596 albertel 4275: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4276: } else {
1.596 albertel 4277: $prevattempts=
4278: &start_data_table().&start_data_table_row().
4279: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4280: &end_data_table_row().&end_data_table();
1.1 albertel 4281: }
4282: } else {
1.596 albertel 4283: $prevattempts=
4284: &start_data_table().&start_data_table_row().
4285: '<td>'.&mt('No data.').'</td>'.
4286: &end_data_table_row().&end_data_table();
1.1 albertel 4287: }
1.10 albertel 4288: }
4289:
1.581 albertel 4290: sub format_previous_attempt_value {
4291: my ($key,$value) = @_;
1.1011 www 4292: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4293: $value = &Apache::lonlocal::locallocaltime($value);
4294: } elsif (ref($value) eq 'ARRAY') {
4295: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4296: } elsif ($key =~ /answerstring$/) {
4297: my %answers = &Apache::lonnet::str2hash($value);
4298: my @anskeys = sort(keys(%answers));
4299: if (@anskeys == 1) {
4300: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4301: if ($answer =~ m{\0}) {
4302: $answer =~ s{\0}{,}g;
1.988 raeburn 4303: }
4304: my $tag_internal_answer_name = 'INTERNAL';
4305: if ($anskeys[0] eq $tag_internal_answer_name) {
4306: $value = $answer;
4307: } else {
4308: $value = $anskeys[0].'='.$answer;
4309: }
4310: } else {
4311: foreach my $ans (@anskeys) {
4312: my $answer = $answers{$ans};
1.1001 raeburn 4313: if ($answer =~ m{\0}) {
4314: $answer =~ s{\0}{,}g;
1.988 raeburn 4315: }
4316: $value .= $ans.'='.$answer.'<br />';;
4317: }
4318: }
1.581 albertel 4319: } else {
4320: $value = &unescape($value);
4321: }
4322: return $value;
4323: }
4324:
4325:
1.107 albertel 4326: sub relative_to_absolute {
4327: my ($url,$output)=@_;
4328: my $parser=HTML::TokeParser->new(\$output);
4329: my $token;
4330: my $thisdir=$url;
4331: my @rlinks=();
4332: while ($token=$parser->get_token) {
4333: if ($token->[0] eq 'S') {
4334: if ($token->[1] eq 'a') {
4335: if ($token->[2]->{'href'}) {
4336: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4337: }
4338: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4339: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4340: } elsif ($token->[1] eq 'base') {
4341: $thisdir=$token->[2]->{'href'};
4342: }
4343: }
4344: }
4345: $thisdir=~s-/[^/]*$--;
1.356 albertel 4346: foreach my $link (@rlinks) {
1.726 raeburn 4347: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4348: ($link=~/^\//) ||
4349: ($link=~/^javascript:/i) ||
4350: ($link=~/^mailto:/i) ||
4351: ($link=~/^\#/)) {
4352: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4353: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4354: }
4355: }
4356: # -------------------------------------------------- Deal with Applet codebases
4357: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4358: return $output;
4359: }
4360:
1.112 bowersj2 4361: =pod
4362:
1.648 raeburn 4363: =item * &get_student_view()
1.112 bowersj2 4364:
4365: show a snapshot of what student was looking at
4366:
4367: =cut
4368:
1.10 albertel 4369: sub get_student_view {
1.186 albertel 4370: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4371: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4372: my (%form);
1.10 albertel 4373: my @elements=('symb','courseid','domain','username');
4374: foreach my $element (@elements) {
1.186 albertel 4375: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4376: }
1.186 albertel 4377: if (defined($moreenv)) {
4378: %form=(%form,%{$moreenv});
4379: }
1.236 albertel 4380: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4381: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4382: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4383: $userview=~s/\<body[^\>]*\>//gi;
4384: $userview=~s/\<\/body\>//gi;
4385: $userview=~s/\<html\>//gi;
4386: $userview=~s/\<\/html\>//gi;
4387: $userview=~s/\<head\>//gi;
4388: $userview=~s/\<\/head\>//gi;
4389: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4390: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4391: if (wantarray) {
4392: return ($userview,$response);
4393: } else {
4394: return $userview;
4395: }
4396: }
4397:
4398: sub get_student_view_with_retries {
4399: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4400:
4401: my $ok = 0; # True if we got a good response.
4402: my $content;
4403: my $response;
4404:
4405: # Try to get the student_view done. within the retries count:
4406:
4407: do {
4408: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4409: $ok = $response->is_success;
4410: if (!$ok) {
4411: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4412: }
4413: $retries--;
4414: } while (!$ok && ($retries > 0));
4415:
4416: if (!$ok) {
4417: $content = ''; # On error return an empty content.
4418: }
1.651 www 4419: if (wantarray) {
4420: return ($content, $response);
4421: } else {
4422: return $content;
4423: }
1.11 albertel 4424: }
4425:
1.112 bowersj2 4426: =pod
4427:
1.648 raeburn 4428: =item * &get_student_answers()
1.112 bowersj2 4429:
4430: show a snapshot of how student was answering problem
4431:
4432: =cut
4433:
1.11 albertel 4434: sub get_student_answers {
1.100 sakharuk 4435: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4436: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4437: my (%moreenv);
1.11 albertel 4438: my @elements=('symb','courseid','domain','username');
4439: foreach my $element (@elements) {
1.186 albertel 4440: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4441: }
1.186 albertel 4442: $moreenv{'grade_target'}='answer';
4443: %moreenv=(%form,%moreenv);
1.497 raeburn 4444: $feedurl = &Apache::lonnet::clutter($feedurl);
4445: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4446: return $userview;
1.1 albertel 4447: }
1.116 albertel 4448:
4449: =pod
4450:
4451: =item * &submlink()
4452:
1.242 albertel 4453: Inputs: $text $uname $udom $symb $target
1.116 albertel 4454:
4455: Returns: A link to grades.pm such as to see the SUBM view of a student
4456:
4457: =cut
4458:
4459: ###############################################
4460: sub submlink {
1.242 albertel 4461: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4462: if (!($uname && $udom)) {
4463: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4464: &Apache::lonnet::whichuser($symb);
1.116 albertel 4465: if (!$symb) { $symb=$cursymb; }
4466: }
1.254 matthew 4467: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4468: $symb=&escape($symb);
1.960 bisitz 4469: if ($target) { $target=" target=\"$target\""; }
4470: return
4471: '<a href="/adm/grades?command=submission'.
4472: '&symb='.$symb.
4473: '&student='.$uname.
4474: '&userdom='.$udom.'"'.
4475: $target.'>'.$text.'</a>';
1.242 albertel 4476: }
4477: ##############################################
4478:
4479: =pod
4480:
4481: =item * &pgrdlink()
4482:
4483: Inputs: $text $uname $udom $symb $target
4484:
4485: Returns: A link to grades.pm such as to see the PGRD view of a student
4486:
4487: =cut
4488:
4489: ###############################################
4490: sub pgrdlink {
4491: my $link=&submlink(@_);
4492: $link=~s/(&command=submission)/$1&showgrading=yes/;
4493: return $link;
4494: }
4495: ##############################################
4496:
4497: =pod
4498:
4499: =item * &pprmlink()
4500:
4501: Inputs: $text $uname $udom $symb $target
4502:
4503: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4504: student and a specific resource
1.242 albertel 4505:
4506: =cut
4507:
4508: ###############################################
4509: sub pprmlink {
4510: my ($text,$uname,$udom,$symb,$target)=@_;
4511: if (!($uname && $udom)) {
4512: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4513: &Apache::lonnet::whichuser($symb);
1.242 albertel 4514: if (!$symb) { $symb=$cursymb; }
4515: }
1.254 matthew 4516: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4517: $symb=&escape($symb);
1.242 albertel 4518: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4519: return '<a href="/adm/parmset?command=set&'.
4520: 'symb='.$symb.'&uname='.$uname.
4521: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4522: }
4523: ##############################################
1.37 matthew 4524:
1.112 bowersj2 4525: =pod
4526:
4527: =back
4528:
4529: =cut
4530:
1.37 matthew 4531: ###############################################
1.51 www 4532:
4533:
4534: sub timehash {
1.687 raeburn 4535: my ($thistime) = @_;
4536: my $timezone = &Apache::lonlocal::gettimezone();
4537: my $dt = DateTime->from_epoch(epoch => $thistime)
4538: ->set_time_zone($timezone);
4539: my $wday = $dt->day_of_week();
4540: if ($wday == 7) { $wday = 0; }
4541: return ( 'second' => $dt->second(),
4542: 'minute' => $dt->minute(),
4543: 'hour' => $dt->hour(),
4544: 'day' => $dt->day_of_month(),
4545: 'month' => $dt->month(),
4546: 'year' => $dt->year(),
4547: 'weekday' => $wday,
4548: 'dayyear' => $dt->day_of_year(),
4549: 'dlsav' => $dt->is_dst() );
1.51 www 4550: }
4551:
1.370 www 4552: sub utc_string {
4553: my ($date)=@_;
1.371 www 4554: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4555: }
4556:
1.51 www 4557: sub maketime {
4558: my %th=@_;
1.687 raeburn 4559: my ($epoch_time,$timezone,$dt);
4560: $timezone = &Apache::lonlocal::gettimezone();
4561: eval {
4562: $dt = DateTime->new( year => $th{'year'},
4563: month => $th{'month'},
4564: day => $th{'day'},
4565: hour => $th{'hour'},
4566: minute => $th{'minute'},
4567: second => $th{'second'},
4568: time_zone => $timezone,
4569: );
4570: };
4571: if (!$@) {
4572: $epoch_time = $dt->epoch;
4573: if ($epoch_time) {
4574: return $epoch_time;
4575: }
4576: }
1.51 www 4577: return POSIX::mktime(
4578: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4579: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4580: }
4581:
4582: #########################################
1.51 www 4583:
4584: sub findallcourses {
1.482 raeburn 4585: my ($roles,$uname,$udom) = @_;
1.355 albertel 4586: my %roles;
4587: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4588: my %courses;
1.51 www 4589: my $now=time;
1.482 raeburn 4590: if (!defined($uname)) {
4591: $uname = $env{'user.name'};
4592: }
4593: if (!defined($udom)) {
4594: $udom = $env{'user.domain'};
4595: }
4596: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4597: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4598: if (!%roles) {
4599: %roles = (
4600: cc => 1,
1.907 raeburn 4601: co => 1,
1.482 raeburn 4602: in => 1,
4603: ep => 1,
4604: ta => 1,
4605: cr => 1,
4606: st => 1,
4607: );
4608: }
4609: foreach my $entry (keys(%roleshash)) {
4610: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4611: if ($trole =~ /^cr/) {
4612: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4613: } else {
4614: next if (!exists($roles{$trole}));
4615: }
4616: if ($tend) {
4617: next if ($tend < $now);
4618: }
4619: if ($tstart) {
4620: next if ($tstart > $now);
4621: }
1.1058 raeburn 4622: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4623: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4624: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4625: if ($secpart eq '') {
4626: ($cnum,$role) = split(/_/,$cnumpart);
4627: $sec = 'none';
1.1058 raeburn 4628: $value .= $cnum.'/';
1.482 raeburn 4629: } else {
4630: $cnum = $cnumpart;
4631: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4632: $value .= $cnum.'/'.$sec;
4633: }
4634: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4635: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4636: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4637: }
4638: } else {
4639: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4640: }
1.482 raeburn 4641: }
4642: } else {
4643: foreach my $key (keys(%env)) {
1.483 albertel 4644: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4645: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4646: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4647: next if ($role eq 'ca' || $role eq 'aa');
4648: next if (%roles && !exists($roles{$role}));
4649: my ($starttime,$endtime)=split(/\./,$env{$key});
4650: my $active=1;
4651: if ($starttime) {
4652: if ($now<$starttime) { $active=0; }
4653: }
4654: if ($endtime) {
4655: if ($now>$endtime) { $active=0; }
4656: }
4657: if ($active) {
1.1058 raeburn 4658: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4659: if ($sec eq '') {
4660: $sec = 'none';
1.1058 raeburn 4661: } else {
4662: $value .= $sec;
4663: }
4664: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4665: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4666: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4667: }
4668: } else {
4669: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4670: }
1.474 raeburn 4671: }
4672: }
1.51 www 4673: }
4674: }
1.474 raeburn 4675: return %courses;
1.51 www 4676: }
1.37 matthew 4677:
1.54 www 4678: ###############################################
1.474 raeburn 4679:
4680: sub blockcheck {
1.1075.2.73 raeburn 4681: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4682:
1.1075.2.73 raeburn 4683: if (defined($udom) && defined($uname)) {
4684: # If uname and udom are for a course, check for blocks in the course.
4685: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4686: my ($startblock,$endblock,$triggerblock) =
4687: &get_blocks($setters,$activity,$udom,$uname,$url);
4688: return ($startblock,$endblock,$triggerblock);
4689: }
4690: } else {
1.490 raeburn 4691: $udom = $env{'user.domain'};
4692: $uname = $env{'user.name'};
4693: }
4694:
1.502 raeburn 4695: my $startblock = 0;
4696: my $endblock = 0;
1.1062 raeburn 4697: my $triggerblock = '';
1.482 raeburn 4698: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4699:
1.490 raeburn 4700: # If uname is for a user, and activity is course-specific, i.e.,
4701: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4702:
1.490 raeburn 4703: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4704: $activity eq 'groups' || $activity eq 'printout') &&
4705: ($env{'request.course.id'})) {
1.490 raeburn 4706: foreach my $key (keys(%live_courses)) {
4707: if ($key ne $env{'request.course.id'}) {
4708: delete($live_courses{$key});
4709: }
4710: }
4711: }
4712:
4713: my $otheruser = 0;
4714: my %own_courses;
4715: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4716: # Resource belongs to user other than current user.
4717: $otheruser = 1;
4718: # Gather courses for current user
4719: %own_courses =
4720: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4721: }
4722:
4723: # Gather active course roles - course coordinator, instructor,
4724: # exam proctor, ta, student, or custom role.
1.474 raeburn 4725:
4726: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4727: my ($cdom,$cnum);
4728: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4729: $cdom = $env{'course.'.$course.'.domain'};
4730: $cnum = $env{'course.'.$course.'.num'};
4731: } else {
1.490 raeburn 4732: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4733: }
4734: my $no_ownblock = 0;
4735: my $no_userblock = 0;
1.533 raeburn 4736: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4737: # Check if current user has 'evb' priv for this
4738: if (defined($own_courses{$course})) {
4739: foreach my $sec (keys(%{$own_courses{$course}})) {
4740: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4741: if ($sec ne 'none') {
4742: $checkrole .= '/'.$sec;
4743: }
4744: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4745: $no_ownblock = 1;
4746: last;
4747: }
4748: }
4749: }
4750: # if they have 'evb' priv and are currently not playing student
4751: next if (($no_ownblock) &&
4752: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4753: }
1.474 raeburn 4754: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4755: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4756: if ($sec ne 'none') {
1.482 raeburn 4757: $checkrole .= '/'.$sec;
1.474 raeburn 4758: }
1.490 raeburn 4759: if ($otheruser) {
4760: # Resource belongs to user other than current user.
4761: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4762: my (%allroles,%userroles);
4763: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4764: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4765: my ($trole,$tdom,$tnum,$tsec);
4766: if ($entry =~ /^cr/) {
4767: ($trole,$tdom,$tnum,$tsec) =
4768: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4769: } else {
4770: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4771: }
4772: my ($spec,$area,$trest);
4773: $area = '/'.$tdom.'/'.$tnum;
4774: $trest = $tnum;
4775: if ($tsec ne '') {
4776: $area .= '/'.$tsec;
4777: $trest .= '/'.$tsec;
4778: }
4779: $spec = $trole.'.'.$area;
4780: if ($trole =~ /^cr/) {
4781: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4782: $tdom,$spec,$trest,$area);
4783: } else {
4784: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4785: $tdom,$spec,$trest,$area);
4786: }
4787: }
1.1075.2.124 raeburn 4788: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 4789: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4790: if ($1) {
4791: $no_userblock = 1;
4792: last;
4793: }
1.486 raeburn 4794: }
4795: }
1.490 raeburn 4796: } else {
4797: # Resource belongs to current user
4798: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4799: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4800: $no_ownblock = 1;
4801: last;
4802: }
1.474 raeburn 4803: }
4804: }
4805: # if they have the evb priv and are currently not playing student
1.482 raeburn 4806: next if (($no_ownblock) &&
1.491 albertel 4807: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4808: next if ($no_userblock);
1.474 raeburn 4809:
1.1075.2.128 raeburn 4810: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 4811: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4812:
1.1062 raeburn 4813: my ($start,$end,$trigger) =
4814: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4815: if (($start != 0) &&
4816: (($startblock == 0) || ($startblock > $start))) {
4817: $startblock = $start;
1.1062 raeburn 4818: if ($trigger ne '') {
4819: $triggerblock = $trigger;
4820: }
1.502 raeburn 4821: }
4822: if (($end != 0) &&
4823: (($endblock == 0) || ($endblock < $end))) {
4824: $endblock = $end;
1.1062 raeburn 4825: if ($trigger ne '') {
4826: $triggerblock = $trigger;
4827: }
1.502 raeburn 4828: }
1.490 raeburn 4829: }
1.1062 raeburn 4830: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4831: }
4832:
4833: sub get_blocks {
1.1062 raeburn 4834: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4835: my $startblock = 0;
4836: my $endblock = 0;
1.1062 raeburn 4837: my $triggerblock = '';
1.490 raeburn 4838: my $course = $cdom.'_'.$cnum;
4839: $setters->{$course} = {};
4840: $setters->{$course}{'staff'} = [];
4841: $setters->{$course}{'times'} = [];
1.1062 raeburn 4842: $setters->{$course}{'triggers'} = [];
4843: my (@blockers,%triggered);
4844: my $now = time;
4845: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4846: if ($activity eq 'docs') {
4847: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4848: foreach my $block (@blockers) {
4849: if ($block =~ /^firstaccess____(.+)$/) {
4850: my $item = $1;
4851: my $type = 'map';
4852: my $timersymb = $item;
4853: if ($item eq 'course') {
4854: $type = 'course';
4855: } elsif ($item =~ /___\d+___/) {
4856: $type = 'resource';
4857: } else {
4858: $timersymb = &Apache::lonnet::symbread($item);
4859: }
4860: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4861: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4862: $triggered{$block} = {
4863: start => $start,
4864: end => $end,
4865: type => $type,
4866: };
4867: }
4868: }
4869: } else {
4870: foreach my $block (keys(%commblocks)) {
4871: if ($block =~ m/^(\d+)____(\d+)$/) {
4872: my ($start,$end) = ($1,$2);
4873: if ($start <= time && $end >= time) {
4874: if (ref($commblocks{$block}) eq 'HASH') {
4875: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4876: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4877: unless(grep(/^\Q$block\E$/,@blockers)) {
4878: push(@blockers,$block);
4879: }
4880: }
4881: }
4882: }
4883: }
4884: } elsif ($block =~ /^firstaccess____(.+)$/) {
4885: my $item = $1;
4886: my $timersymb = $item;
4887: my $type = 'map';
4888: if ($item eq 'course') {
4889: $type = 'course';
4890: } elsif ($item =~ /___\d+___/) {
4891: $type = 'resource';
4892: } else {
4893: $timersymb = &Apache::lonnet::symbread($item);
4894: }
4895: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4896: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4897: if ($start && $end) {
4898: if (($start <= time) && ($end >= time)) {
4899: unless (grep(/^\Q$block\E$/,@blockers)) {
4900: push(@blockers,$block);
4901: $triggered{$block} = {
4902: start => $start,
4903: end => $end,
4904: type => $type,
4905: };
4906: }
4907: }
1.490 raeburn 4908: }
1.1062 raeburn 4909: }
4910: }
4911: }
4912: foreach my $blocker (@blockers) {
4913: my ($staff_name,$staff_dom,$title,$blocks) =
4914: &parse_block_record($commblocks{$blocker});
4915: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4916: my ($start,$end,$triggertype);
4917: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4918: ($start,$end) = ($1,$2);
4919: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4920: $start = $triggered{$blocker}{'start'};
4921: $end = $triggered{$blocker}{'end'};
4922: $triggertype = $triggered{$blocker}{'type'};
4923: }
4924: if ($start) {
4925: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4926: if ($triggertype) {
4927: push(@{$$setters{$course}{'triggers'}},$triggertype);
4928: } else {
4929: push(@{$$setters{$course}{'triggers'}},0);
4930: }
4931: if ( ($startblock == 0) || ($startblock > $start) ) {
4932: $startblock = $start;
4933: if ($triggertype) {
4934: $triggerblock = $blocker;
1.474 raeburn 4935: }
4936: }
1.1062 raeburn 4937: if ( ($endblock == 0) || ($endblock < $end) ) {
4938: $endblock = $end;
4939: if ($triggertype) {
4940: $triggerblock = $blocker;
4941: }
4942: }
1.474 raeburn 4943: }
4944: }
1.1062 raeburn 4945: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4946: }
4947:
4948: sub parse_block_record {
4949: my ($record) = @_;
4950: my ($setuname,$setudom,$title,$blocks);
4951: if (ref($record) eq 'HASH') {
4952: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4953: $title = &unescape($record->{'event'});
4954: $blocks = $record->{'blocks'};
4955: } else {
4956: my @data = split(/:/,$record,3);
4957: if (scalar(@data) eq 2) {
4958: $title = $data[1];
4959: ($setuname,$setudom) = split(/@/,$data[0]);
4960: } else {
4961: ($setuname,$setudom,$title) = @data;
4962: }
4963: $blocks = { 'com' => 'on' };
4964: }
4965: return ($setuname,$setudom,$title,$blocks);
4966: }
4967:
1.854 kalberla 4968: sub blocking_status {
1.1075.2.73 raeburn 4969: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4970: my %setters;
1.890 droeschl 4971:
1.1061 raeburn 4972: # check for active blocking
1.1062 raeburn 4973: my ($startblock,$endblock,$triggerblock) =
1.1075.2.73 raeburn 4974: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4975: my $blocked = 0;
4976: if ($startblock && $endblock) {
4977: $blocked = 1;
4978: }
1.890 droeschl 4979:
1.1061 raeburn 4980: # caller just wants to know whether a block is active
4981: if (!wantarray) { return $blocked; }
4982:
4983: # build a link to a popup window containing the details
4984: my $querystring = "?activity=$activity";
4985: # $uname and $udom decide whose portfolio the user is trying to look at
1.1075.2.97 raeburn 4986: if (($activity eq 'port') || ($activity eq 'passwd')) {
4987: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
4988: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 4989: } elsif ($activity eq 'docs') {
4990: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4991: }
1.1061 raeburn 4992:
4993: my $output .= <<'END_MYBLOCK';
4994: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4995: var options = "width=" + w + ",height=" + h + ",";
4996: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4997: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4998: var newWin = window.open(url, wdwName, options);
4999: newWin.focus();
5000: }
1.890 droeschl 5001: END_MYBLOCK
1.854 kalberla 5002:
1.1061 raeburn 5003: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5004:
1.1061 raeburn 5005: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5006: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 5007: my $class = 'LC_comblock';
1.1062 raeburn 5008: if ($activity eq 'docs') {
5009: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 5010: $class = '';
1.1063 raeburn 5011: } elsif ($activity eq 'printout') {
5012: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 5013: } elsif ($activity eq 'passwd') {
5014: $text = &mt('Password Changing Blocked');
1.1062 raeburn 5015: }
1.1061 raeburn 5016: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 5017: <div class='$class'>
1.869 kalberla 5018: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5019: title='$text'>
5020: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5021: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5022: title='$text'>$text</a>
1.867 kalberla 5023: </div>
5024:
5025: END_BLOCK
1.474 raeburn 5026:
1.1061 raeburn 5027: return ($blocked, $output);
1.854 kalberla 5028: }
1.490 raeburn 5029:
1.60 matthew 5030: ###############################################
5031:
1.682 raeburn 5032: sub check_ip_acc {
1.1075.2.105 raeburn 5033: my ($acc,$clientip)=@_;
1.682 raeburn 5034: &Apache::lonxml::debug("acc is $acc");
5035: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5036: return 1;
5037: }
5038: my $allowed=0;
1.1075.2.144! raeburn 5039: my $ip;
! 5040: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
! 5041: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
! 5042: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
! 5043: } else {
! 5044: $ip = $ENV{'REMOTE_ADDR'} || $env{'request.host'} || $clientip;
! 5045: }
1.682 raeburn 5046:
5047: my $name;
5048: foreach my $pattern (split(',',$acc)) {
5049: $pattern =~ s/^\s*//;
5050: $pattern =~ s/\s*$//;
5051: if ($pattern =~ /\*$/) {
5052: #35.8.*
5053: $pattern=~s/\*//;
5054: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5055: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5056: #35.8.3.[34-56]
5057: my $low=$2;
5058: my $high=$3;
5059: $pattern=$1;
5060: if ($ip =~ /^\Q$pattern\E/) {
5061: my $last=(split(/\./,$ip))[3];
5062: if ($last <=$high && $last >=$low) { $allowed=1; }
5063: }
5064: } elsif ($pattern =~ /^\*/) {
5065: #*.msu.edu
5066: $pattern=~s/\*//;
5067: if (!defined($name)) {
5068: use Socket;
5069: my $netaddr=inet_aton($ip);
5070: ($name)=gethostbyaddr($netaddr,AF_INET);
5071: }
5072: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5073: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5074: #127.0.0.1
5075: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
5076: } else {
5077: #some.name.com
5078: if (!defined($name)) {
5079: use Socket;
5080: my $netaddr=inet_aton($ip);
5081: ($name)=gethostbyaddr($netaddr,AF_INET);
5082: }
5083: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
5084: }
5085: if ($allowed) { last; }
5086: }
5087: return $allowed;
5088: }
5089:
5090: ###############################################
5091:
1.60 matthew 5092: =pod
5093:
1.112 bowersj2 5094: =head1 Domain Template Functions
5095:
5096: =over 4
5097:
5098: =item * &determinedomain()
1.60 matthew 5099:
5100: Inputs: $domain (usually will be undef)
5101:
1.63 www 5102: Returns: Determines which domain should be used for designs
1.60 matthew 5103:
5104: =cut
1.54 www 5105:
1.60 matthew 5106: ###############################################
1.63 www 5107: sub determinedomain {
5108: my $domain=shift;
1.531 albertel 5109: if (! $domain) {
1.60 matthew 5110: # Determine domain if we have not been given one
1.893 raeburn 5111: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5112: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5113: if ($env{'request.role.domain'}) {
5114: $domain=$env{'request.role.domain'};
1.60 matthew 5115: }
5116: }
1.63 www 5117: return $domain;
5118: }
5119: ###############################################
1.517 raeburn 5120:
1.518 albertel 5121: sub devalidate_domconfig_cache {
5122: my ($udom)=@_;
5123: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5124: }
5125:
5126: # ---------------------- Get domain configuration for a domain
5127: sub get_domainconf {
5128: my ($udom) = @_;
5129: my $cachetime=1800;
5130: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5131: if (defined($cached)) { return %{$result}; }
5132:
5133: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5134: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5135: my (%designhash,%legacy);
1.518 albertel 5136: if (keys(%domconfig) > 0) {
5137: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5138: if (keys(%{$domconfig{'login'}})) {
5139: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5140: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5141: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5142: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5143: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5144: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5145: if ($key eq 'loginvia') {
5146: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5147: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5148: $designhash{$udom.'.login.loginvia'} = $server;
5149: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5150: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5151: } else {
5152: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5153: }
1.948 raeburn 5154: }
1.1075.2.87 raeburn 5155: } elsif ($key eq 'headtag') {
5156: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5157: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5158: }
1.946 raeburn 5159: }
1.1075.2.87 raeburn 5160: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5161: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5162: }
1.946 raeburn 5163: }
5164: }
5165: }
5166: } else {
5167: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5168: $designhash{$udom.'.login.'.$key.'_'.$img} =
5169: $domconfig{'login'}{$key}{$img};
5170: }
1.699 raeburn 5171: }
5172: } else {
5173: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5174: }
1.632 raeburn 5175: }
5176: } else {
5177: $legacy{'login'} = 1;
1.518 albertel 5178: }
1.632 raeburn 5179: } else {
5180: $legacy{'login'} = 1;
1.518 albertel 5181: }
5182: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5183: if (keys(%{$domconfig{'rolecolors'}})) {
5184: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5185: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5186: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5187: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5188: }
1.518 albertel 5189: }
5190: }
1.632 raeburn 5191: } else {
5192: $legacy{'rolecolors'} = 1;
1.518 albertel 5193: }
1.632 raeburn 5194: } else {
5195: $legacy{'rolecolors'} = 1;
1.518 albertel 5196: }
1.948 raeburn 5197: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5198: if ($domconfig{'autoenroll'}{'co-owners'}) {
5199: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5200: }
5201: }
1.632 raeburn 5202: if (keys(%legacy) > 0) {
5203: my %legacyhash = &get_legacy_domconf($udom);
5204: foreach my $item (keys(%legacyhash)) {
5205: if ($item =~ /^\Q$udom\E\.login/) {
5206: if ($legacy{'login'}) {
5207: $designhash{$item} = $legacyhash{$item};
5208: }
5209: } else {
5210: if ($legacy{'rolecolors'}) {
5211: $designhash{$item} = $legacyhash{$item};
5212: }
1.518 albertel 5213: }
5214: }
5215: }
1.632 raeburn 5216: } else {
5217: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5218: }
5219: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5220: $cachetime);
5221: return %designhash;
5222: }
5223:
1.632 raeburn 5224: sub get_legacy_domconf {
5225: my ($udom) = @_;
5226: my %legacyhash;
5227: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5228: my $designfile = $designdir.'/'.$udom.'.tab';
5229: if (-e $designfile) {
1.1075.2.128 raeburn 5230: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5231: while (my $line = <$fh>) {
5232: next if ($line =~ /^\#/);
5233: chomp($line);
5234: my ($key,$val)=(split(/\=/,$line));
5235: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5236: }
5237: close($fh);
5238: }
5239: }
1.1026 raeburn 5240: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5241: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5242: }
5243: return %legacyhash;
5244: }
5245:
1.63 www 5246: =pod
5247:
1.112 bowersj2 5248: =item * &domainlogo()
1.63 www 5249:
5250: Inputs: $domain (usually will be undef)
5251:
5252: Returns: A link to a domain logo, if the domain logo exists.
5253: If the domain logo does not exist, a description of the domain.
5254:
5255: =cut
1.112 bowersj2 5256:
1.63 www 5257: ###############################################
5258: sub domainlogo {
1.517 raeburn 5259: my $domain = &determinedomain(shift);
1.518 albertel 5260: my %designhash = &get_domainconf($domain);
1.517 raeburn 5261: # See if there is a logo
5262: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5263: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5264: if ($imgsrc =~ m{^/(adm|res)/}) {
5265: if ($imgsrc =~ m{^/res/}) {
5266: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5267: &Apache::lonnet::repcopy($local_name);
5268: }
5269: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5270: }
5271: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5272: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5273: return &Apache::lonnet::domain($domain,'description');
1.59 www 5274: } else {
1.60 matthew 5275: return '';
1.59 www 5276: }
5277: }
1.63 www 5278: ##############################################
5279:
5280: =pod
5281:
1.112 bowersj2 5282: =item * &designparm()
1.63 www 5283:
5284: Inputs: $which parameter; $domain (usually will be undef)
5285:
5286: Returns: value of designparamter $which
5287:
5288: =cut
1.112 bowersj2 5289:
1.397 albertel 5290:
1.400 albertel 5291: ##############################################
1.397 albertel 5292: sub designparm {
5293: my ($which,$domain)=@_;
5294: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5295: return $env{'environment.color.'.$which};
1.96 www 5296: }
1.63 www 5297: $domain=&determinedomain($domain);
1.1016 raeburn 5298: my %domdesign;
5299: unless ($domain eq 'public') {
5300: %domdesign = &get_domainconf($domain);
5301: }
1.520 raeburn 5302: my $output;
1.517 raeburn 5303: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5304: $output = $domdesign{$domain.'.'.$which};
1.63 www 5305: } else {
1.520 raeburn 5306: $output = $defaultdesign{$which};
5307: }
5308: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5309: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5310: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5311: if ($output =~ m{^/res/}) {
5312: my $local_name = &Apache::lonnet::filelocation('',$output);
5313: &Apache::lonnet::repcopy($local_name);
5314: }
1.520 raeburn 5315: $output = &lonhttpdurl($output);
5316: }
1.63 www 5317: }
1.520 raeburn 5318: return $output;
1.63 www 5319: }
1.59 www 5320:
1.822 bisitz 5321: ##############################################
5322: =pod
5323:
1.832 bisitz 5324: =item * &authorspace()
5325:
1.1028 raeburn 5326: Inputs: $url (usually will be undef).
1.832 bisitz 5327:
1.1075.2.40 raeburn 5328: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5329: directory being viewed (or for which action is being taken).
5330: If $url is provided, and begins /priv/<domain>/<uname>
5331: the path will be that portion of the $context argument.
5332: Otherwise the path will be for the author space of the current
5333: user when the current role is author, or for that of the
5334: co-author/assistant co-author space when the current role
5335: is co-author or assistant co-author.
1.832 bisitz 5336:
5337: =cut
5338:
5339: sub authorspace {
1.1028 raeburn 5340: my ($url) = @_;
5341: if ($url ne '') {
5342: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5343: return $1;
5344: }
5345: }
1.832 bisitz 5346: my $caname = '';
1.1024 www 5347: my $cadom = '';
1.1028 raeburn 5348: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5349: ($cadom,$caname) =
1.832 bisitz 5350: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5351: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5352: $caname = $env{'user.name'};
1.1024 www 5353: $cadom = $env{'user.domain'};
1.832 bisitz 5354: }
1.1028 raeburn 5355: if (($caname ne '') && ($cadom ne '')) {
5356: return "/priv/$cadom/$caname/";
5357: }
5358: return;
1.832 bisitz 5359: }
5360:
5361: ##############################################
5362: =pod
5363:
1.822 bisitz 5364: =item * &head_subbox()
5365:
5366: Inputs: $content (contains HTML code with page functions, etc.)
5367:
5368: Returns: HTML div with $content
5369: To be included in page header
5370:
5371: =cut
5372:
5373: sub head_subbox {
5374: my ($content)=@_;
5375: my $output =
1.993 raeburn 5376: '<div class="LC_head_subbox">'
1.822 bisitz 5377: .$content
5378: .'</div>'
5379: }
5380:
5381: ##############################################
5382: =pod
5383:
5384: =item * &CSTR_pageheader()
5385:
1.1026 raeburn 5386: Input: (optional) filename from which breadcrumb trail is built.
5387: In most cases no input as needed, as $env{'request.filename'}
5388: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5389:
5390: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5391: To be included on Authoring Space pages
1.822 bisitz 5392:
5393: =cut
5394:
5395: sub CSTR_pageheader {
1.1026 raeburn 5396: my ($trailfile) = @_;
5397: if ($trailfile eq '') {
5398: $trailfile = $env{'request.filename'};
5399: }
5400:
5401: # this is for resources; directories have customtitle, and crumbs
5402: # and select recent are created in lonpubdir.pm
5403:
5404: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5405: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5406: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5407: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5408: $formaction =~ s{/+}{/}g;
1.822 bisitz 5409:
5410: my $parentpath = '';
5411: my $lastitem = '';
5412: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5413: $parentpath = $1;
5414: $lastitem = $2;
5415: } else {
5416: $lastitem = $thisdisfn;
5417: }
1.921 bisitz 5418:
5419: my $output =
1.822 bisitz 5420: '<div>'
5421: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5422: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5423: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5424: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5425: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5426:
5427: if ($lastitem) {
5428: $output .=
5429: '<span class="LC_filename">'
5430: .$lastitem
5431: .'</span>';
5432: }
5433: $output .=
5434: '<br />'
1.822 bisitz 5435: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5436: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5437: .'</form>'
5438: .&Apache::lonmenu::constspaceform()
5439: .'</div>';
1.921 bisitz 5440:
5441: return $output;
1.822 bisitz 5442: }
5443:
1.60 matthew 5444: ###############################################
5445: ###############################################
5446:
5447: =pod
5448:
1.112 bowersj2 5449: =back
5450:
1.549 albertel 5451: =head1 HTML Helpers
1.112 bowersj2 5452:
5453: =over 4
5454:
5455: =item * &bodytag()
1.60 matthew 5456:
5457: Returns a uniform header for LON-CAPA web pages.
5458:
5459: Inputs:
5460:
1.112 bowersj2 5461: =over 4
5462:
5463: =item * $title, A title to be displayed on the page.
5464:
5465: =item * $function, the current role (can be undef).
5466:
5467: =item * $addentries, extra parameters for the <body> tag.
5468:
5469: =item * $bodyonly, if defined, only return the <body> tag.
5470:
5471: =item * $domain, if defined, force a given domain.
5472:
5473: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5474: text interface only)
1.60 matthew 5475:
1.814 bisitz 5476: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5477: navigational links
1.317 albertel 5478:
1.338 albertel 5479: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5480:
1.1075.2.12 raeburn 5481: =item * $no_inline_link, if true and in remote mode, don't show the
5482: 'Switch To Inline Menu' link
5483:
1.460 albertel 5484: =item * $args, optional argument valid values are
5485: no_auto_mt_title -> prevents &mt()ing the title arg
1.1075.2.133 raeburn 5486: use_absolute -> for external resource or syllabus, this will
5487: contain https://<hostname> if server uses
5488: https (as per hosts.tab), but request is for http
5489: hostname -> hostname, from $r->hostname().
1.460 albertel 5490:
1.1075.2.15 raeburn 5491: =item * $advtoolsref, optional argument, ref to an array containing
5492: inlineremote items to be added in "Functions" menu below
5493: breadcrumbs.
5494:
1.112 bowersj2 5495: =back
5496:
1.60 matthew 5497: Returns: A uniform header for LON-CAPA web pages.
5498: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5499: If $bodyonly is undef or zero, an html string containing a <body> tag and
5500: other decorations will be returned.
5501:
5502: =cut
5503:
1.54 www 5504: sub bodytag {
1.831 bisitz 5505: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5506: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5507:
1.954 raeburn 5508: my $public;
5509: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5510: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5511: $public = 1;
5512: }
1.460 albertel 5513: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5514: my $httphost = $args->{'use_absolute'};
1.1075.2.133 raeburn 5515: my $hostname = $args->{'hostname'};
1.339 albertel 5516:
1.183 matthew 5517: $function = &get_users_function() if (!$function);
1.339 albertel 5518: my $img = &designparm($function.'.img',$domain);
5519: my $font = &designparm($function.'.font',$domain);
5520: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5521:
1.803 bisitz 5522: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5523: 'bgcolor' => $pgbg,
1.339 albertel 5524: 'text' => $font,
5525: 'alink' => &designparm($function.'.alink',$domain),
5526: 'vlink' => &designparm($function.'.vlink',$domain),
5527: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5528: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5529:
1.63 www 5530: # role and realm
1.1075.2.68 raeburn 5531: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5532: if ($realm) {
5533: $realm = '/'.$realm;
5534: }
1.378 raeburn 5535: if ($role eq 'ca') {
1.479 albertel 5536: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5537: $realm = &plainname($rname,$rdom);
1.378 raeburn 5538: }
1.55 www 5539: # realm
1.258 albertel 5540: if ($env{'request.course.id'}) {
1.378 raeburn 5541: if ($env{'request.role'} !~ /^cr/) {
5542: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5543: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5544: if ($env{'request.role.desc'}) {
5545: $role = $env{'request.role.desc'};
5546: } else {
5547: $role = &mt('Helpdesk[_1]',' '.$2);
5548: }
1.1075.2.115 raeburn 5549: } else {
5550: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5551: }
1.898 raeburn 5552: if ($env{'request.course.sec'}) {
5553: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5554: }
1.359 albertel 5555: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5556: } else {
5557: $role = &Apache::lonnet::plaintext($role);
1.54 www 5558: }
1.433 albertel 5559:
1.359 albertel 5560: if (!$realm) { $realm=' '; }
1.330 albertel 5561:
1.438 albertel 5562: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5563:
1.101 www 5564: # construct main body tag
1.359 albertel 5565: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5566: &Apache::lontexconvert::init_math_support();
1.252 albertel 5567:
1.1075.2.38 raeburn 5568: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5569:
5570: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5571: return $bodytag;
1.1075.2.38 raeburn 5572: }
1.359 albertel 5573:
1.954 raeburn 5574: if ($public) {
1.433 albertel 5575: undef($role);
5576: }
1.359 albertel 5577:
1.762 bisitz 5578: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5579: #
5580: # Extra info if you are the DC
5581: my $dc_info = '';
5582: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5583: $env{'course.'.$env{'request.course.id'}.
5584: '.domain'}.'/'})) {
5585: my $cid = $env{'request.course.id'};
1.917 raeburn 5586: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5587: $dc_info =~ s/\s+$//;
1.359 albertel 5588: }
5589:
1.1075.2.108 raeburn 5590: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5591:
1.1075.2.13 raeburn 5592: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5593:
1.1075.2.38 raeburn 5594:
5595:
1.1075.2.21 raeburn 5596: my $funclist;
5597: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5598: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5599: Apache::lonmenu::serverform();
5600: my $forbodytag;
5601: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5602: $forcereg,$args->{'group'},
5603: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5604: $advtoolsref,'','',\$forbodytag);
1.1075.2.21 raeburn 5605: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5606: $funclist = $forbodytag;
5607: }
5608: } else {
1.903 droeschl 5609:
5610: # if ($env{'request.state'} eq 'construct') {
5611: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5612: # }
5613:
1.1075.2.38 raeburn 5614: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5615: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5616:
1.1075.2.38 raeburn 5617: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5618:
1.916 droeschl 5619: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5620: if ($dc_info) {
5621: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5622: }
1.1075.2.38 raeburn 5623: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5624: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5625: return $bodytag;
5626: }
1.894 droeschl 5627:
1.927 raeburn 5628: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5629: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5630: }
1.916 droeschl 5631:
1.1075.2.38 raeburn 5632: $bodytag .= $right;
1.852 droeschl 5633:
1.917 raeburn 5634: if ($dc_info) {
5635: $dc_info = &dc_courseid_toggle($dc_info);
5636: }
5637: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5638:
1.1075.2.61 raeburn 5639: #if directed to not display the secondary menu, don't.
5640: if ($args->{'no_secondary_menu'}) {
5641: return $bodytag;
5642: }
1.903 droeschl 5643: #don't show menus for public users
1.954 raeburn 5644: if (!$public){
1.1075.2.52 raeburn 5645: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5646: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5647: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5648: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5649: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1075.2.133 raeburn 5650: $args->{'bread_crumbs'},'','',$hostname);
1.1075.2.116 raeburn 5651: } elsif ($forcereg) {
1.1075.2.22 raeburn 5652: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5653: $args->{'group'},
1.1075.2.133 raeburn 5654: $args->{'hide_buttons',
5655: $hostname});
1.1075.2.15 raeburn 5656: } else {
1.1075.2.21 raeburn 5657: my $forbodytag;
5658: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5659: $forcereg,$args->{'group'},
5660: $args->{'bread_crumbs'},
1.1075.2.133 raeburn 5661: $advtoolsref,'',$hostname,
5662: \$forbodytag);
1.1075.2.21 raeburn 5663: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5664: $bodytag .= $forbodytag;
5665: }
1.920 raeburn 5666: }
1.903 droeschl 5667: }else{
5668: # this is to seperate menu from content when there's no secondary
5669: # menu. Especially needed for public accessible ressources.
5670: $bodytag .= '<hr style="clear:both" />';
5671: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5672: }
1.903 droeschl 5673:
1.235 raeburn 5674: return $bodytag;
1.1075.2.12 raeburn 5675: }
5676:
5677: #
5678: # Top frame rendering, Remote is up
5679: #
5680:
5681: my $imgsrc = $img;
5682: if ($img =~ /^\/adm/) {
5683: $imgsrc = &lonhttpdurl($img);
5684: }
5685: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5686:
1.1075.2.60 raeburn 5687: my $help=($no_inline_link?''
5688: :&Apache::loncommon::top_nav_help('Help'));
5689:
1.1075.2.12 raeburn 5690: # Explicit link to get inline menu
5691: my $menu= ($no_inline_link?''
5692: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5693:
5694: if ($dc_info) {
5695: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5696: }
5697:
1.1075.2.38 raeburn 5698: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5699: unless ($public) {
5700: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5701: undef,'LC_menubuttons_link');
5702: }
5703:
1.1075.2.12 raeburn 5704: unless ($env{'form.inhibitmenu'}) {
5705: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5706: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5707: <li>$help</li>
1.1075.2.12 raeburn 5708: <li>$menu</li>
5709: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5710: }
1.1075.2.13 raeburn 5711: if ($env{'request.state'} eq 'construct') {
5712: if (!$public){
5713: if ($env{'request.state'} eq 'construct') {
5714: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5715: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5716: &Apache::lonhtmlcommon::scripttag('','end').
5717: &Apache::lonmenu::innerregister($forcereg,
5718: $args->{'bread_crumbs'});
5719: }
5720: }
5721: }
1.1075.2.21 raeburn 5722: return $bodytag."\n".$funclist;
1.182 matthew 5723: }
5724:
1.917 raeburn 5725: sub dc_courseid_toggle {
5726: my ($dc_info) = @_;
1.980 raeburn 5727: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5728: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5729: &mt('(More ...)').'</a></span>'.
5730: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5731: }
5732:
1.330 albertel 5733: sub make_attr_string {
5734: my ($register,$attr_ref) = @_;
5735:
5736: if ($attr_ref && !ref($attr_ref)) {
5737: die("addentries Must be a hash ref ".
5738: join(':',caller(1))." ".
5739: join(':',caller(0))." ");
5740: }
5741:
5742: if ($register) {
1.339 albertel 5743: my ($on_load,$on_unload);
5744: foreach my $key (keys(%{$attr_ref})) {
5745: if (lc($key) eq 'onload') {
5746: $on_load.=$attr_ref->{$key}.';';
5747: delete($attr_ref->{$key});
5748:
5749: } elsif (lc($key) eq 'onunload') {
5750: $on_unload.=$attr_ref->{$key}.';';
5751: delete($attr_ref->{$key});
5752: }
5753: }
1.1075.2.12 raeburn 5754: if ($env{'environment.remote'} eq 'on') {
5755: $attr_ref->{'onload'} =
5756: &Apache::lonmenu::loadevents(). $on_load;
5757: $attr_ref->{'onunload'}=
5758: &Apache::lonmenu::unloadevents().$on_unload;
5759: } else {
5760: $attr_ref->{'onload'} = $on_load;
5761: $attr_ref->{'onunload'}= $on_unload;
5762: }
1.330 albertel 5763: }
1.339 albertel 5764:
1.330 albertel 5765: my $attr_string;
1.1075.2.56 raeburn 5766: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5767: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5768: }
5769: return $attr_string;
5770: }
5771:
5772:
1.182 matthew 5773: ###############################################
1.251 albertel 5774: ###############################################
5775:
5776: =pod
5777:
5778: =item * &endbodytag()
5779:
5780: Returns a uniform footer for LON-CAPA web pages.
5781:
1.635 raeburn 5782: Inputs: 1 - optional reference to an args hash
5783: If in the hash, key for noredirectlink has a value which evaluates to true,
5784: a 'Continue' link is not displayed if the page contains an
5785: internal redirect in the <head></head> section,
5786: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5787:
5788: =cut
5789:
5790: sub endbodytag {
1.635 raeburn 5791: my ($args) = @_;
1.1075.2.6 raeburn 5792: my $endbodytag;
5793: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5794: $endbodytag='</body>';
5795: }
1.315 albertel 5796: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5797: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5798: $endbodytag=
5799: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5800: &mt('Continue').'</a>'.
5801: $endbodytag;
5802: }
1.315 albertel 5803: }
1.251 albertel 5804: return $endbodytag;
5805: }
5806:
1.352 albertel 5807: =pod
5808:
5809: =item * &standard_css()
5810:
5811: Returns a style sheet
5812:
5813: Inputs: (all optional)
5814: domain -> force to color decorate a page for a specific
5815: domain
5816: function -> force usage of a specific rolish color scheme
5817: bgcolor -> override the default page bgcolor
5818:
5819: =cut
5820:
1.343 albertel 5821: sub standard_css {
1.345 albertel 5822: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5823: $function = &get_users_function() if (!$function);
5824: my $img = &designparm($function.'.img', $domain);
5825: my $tabbg = &designparm($function.'.tabbg', $domain);
5826: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5827: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5828: #second colour for later usage
1.345 albertel 5829: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5830: my $pgbg_or_bgcolor =
5831: $bgcolor ||
1.352 albertel 5832: &designparm($function.'.pgbg', $domain);
1.382 albertel 5833: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5834: my $alink = &designparm($function.'.alink', $domain);
5835: my $vlink = &designparm($function.'.vlink', $domain);
5836: my $link = &designparm($function.'.link', $domain);
5837:
1.602 albertel 5838: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5839: my $mono = 'monospace';
1.850 bisitz 5840: my $data_table_head = $sidebg;
5841: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5842: my $data_table_dark = '#E0E0E0';
1.470 banghart 5843: my $data_table_darker = '#CCCCCC';
1.349 albertel 5844: my $data_table_highlight = '#FFFF00';
1.352 albertel 5845: my $mail_new = '#FFBB77';
5846: my $mail_new_hover = '#DD9955';
5847: my $mail_read = '#BBBB77';
5848: my $mail_read_hover = '#999944';
5849: my $mail_replied = '#AAAA88';
5850: my $mail_replied_hover = '#888855';
5851: my $mail_other = '#99BBBB';
5852: my $mail_other_hover = '#669999';
1.391 albertel 5853: my $table_header = '#DDDDDD';
1.489 raeburn 5854: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5855: my $lg_border_color = '#C8C8C8';
1.952 onken 5856: my $button_hover = '#BF2317';
1.392 albertel 5857:
1.608 albertel 5858: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5859: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5860: : '0 3px 0 4px';
1.448 albertel 5861:
1.523 albertel 5862:
1.343 albertel 5863: return <<END;
1.947 droeschl 5864:
5865: /* needed for iframe to allow 100% height in FF */
5866: body, html {
5867: margin: 0;
5868: padding: 0 0.5%;
5869: height: 99%; /* to avoid scrollbars */
5870: }
5871:
1.795 www 5872: body {
1.911 bisitz 5873: font-family: $sans;
5874: line-height:130%;
5875: font-size:0.83em;
5876: color:$font;
1.795 www 5877: }
5878:
1.959 onken 5879: a:focus,
5880: a:focus img {
1.795 www 5881: color: red;
5882: }
1.698 harmsja 5883:
1.911 bisitz 5884: form, .inline {
5885: display: inline;
1.795 www 5886: }
1.721 harmsja 5887:
1.795 www 5888: .LC_right {
1.911 bisitz 5889: text-align:right;
1.795 www 5890: }
5891:
5892: .LC_middle {
1.911 bisitz 5893: vertical-align:middle;
1.795 www 5894: }
1.721 harmsja 5895:
1.1075.2.38 raeburn 5896: .LC_floatleft {
5897: float: left;
5898: }
5899:
5900: .LC_floatright {
5901: float: right;
5902: }
5903:
1.911 bisitz 5904: .LC_400Box {
5905: width:400px;
5906: }
1.721 harmsja 5907:
1.947 droeschl 5908: .LC_iframecontainer {
5909: width: 98%;
5910: margin: 0;
5911: position: fixed;
5912: top: 8.5em;
5913: bottom: 0;
5914: }
5915:
5916: .LC_iframecontainer iframe{
5917: border: none;
5918: width: 100%;
5919: height: 100%;
5920: }
5921:
1.778 bisitz 5922: .LC_filename {
5923: font-family: $mono;
5924: white-space:pre;
1.921 bisitz 5925: font-size: 120%;
1.778 bisitz 5926: }
5927:
5928: .LC_fileicon {
5929: border: none;
5930: height: 1.3em;
5931: vertical-align: text-bottom;
5932: margin-right: 0.3em;
5933: text-decoration:none;
5934: }
5935:
1.1008 www 5936: .LC_setting {
5937: text-decoration:underline;
5938: }
5939:
1.350 albertel 5940: .LC_error {
5941: color: red;
5942: }
1.795 www 5943:
1.1075.2.15 raeburn 5944: .LC_warning {
5945: color: darkorange;
5946: }
5947:
1.457 albertel 5948: .LC_diff_removed {
1.733 bisitz 5949: color: red;
1.394 albertel 5950: }
1.532 albertel 5951:
5952: .LC_info,
1.457 albertel 5953: .LC_success,
5954: .LC_diff_added {
1.350 albertel 5955: color: green;
5956: }
1.795 www 5957:
1.802 bisitz 5958: div.LC_confirm_box {
5959: background-color: #FAFAFA;
5960: border: 1px solid $lg_border_color;
5961: margin-right: 0;
5962: padding: 5px;
5963: }
5964:
5965: div.LC_confirm_box .LC_error img,
5966: div.LC_confirm_box .LC_success img {
5967: vertical-align: middle;
5968: }
5969:
1.1075.2.108 raeburn 5970: .LC_maxwidth {
5971: max-width: 100%;
5972: height: auto;
5973: }
5974:
5975: .LC_textsize_mobile {
5976: \@media only screen and (max-device-width: 480px) {
5977: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
5978: }
5979: }
5980:
1.440 albertel 5981: .LC_icon {
1.771 droeschl 5982: border: none;
1.790 droeschl 5983: vertical-align: middle;
1.771 droeschl 5984: }
5985:
1.543 albertel 5986: .LC_docs_spacer {
5987: width: 25px;
5988: height: 1px;
1.771 droeschl 5989: border: none;
1.543 albertel 5990: }
1.346 albertel 5991:
1.532 albertel 5992: .LC_internal_info {
1.735 bisitz 5993: color: #999999;
1.532 albertel 5994: }
5995:
1.794 www 5996: .LC_discussion {
1.1050 www 5997: background: $data_table_dark;
1.911 bisitz 5998: border: 1px solid black;
5999: margin: 2px;
1.794 www 6000: }
6001:
6002: .LC_disc_action_left {
1.1050 www 6003: background: $sidebg;
1.911 bisitz 6004: text-align: left;
1.1050 www 6005: padding: 4px;
6006: margin: 2px;
1.794 www 6007: }
6008:
6009: .LC_disc_action_right {
1.1050 www 6010: background: $sidebg;
1.911 bisitz 6011: text-align: right;
1.1050 www 6012: padding: 4px;
6013: margin: 2px;
1.794 www 6014: }
6015:
6016: .LC_disc_new_item {
1.911 bisitz 6017: background: white;
6018: border: 2px solid red;
1.1050 www 6019: margin: 4px;
6020: padding: 4px;
1.794 www 6021: }
6022:
6023: .LC_disc_old_item {
1.911 bisitz 6024: background: white;
1.1050 www 6025: margin: 4px;
6026: padding: 4px;
1.794 www 6027: }
6028:
1.458 albertel 6029: table.LC_pastsubmission {
6030: border: 1px solid black;
6031: margin: 2px;
6032: }
6033:
1.924 bisitz 6034: table#LC_menubuttons {
1.345 albertel 6035: width: 100%;
6036: background: $pgbg;
1.392 albertel 6037: border: 2px;
1.402 albertel 6038: border-collapse: separate;
1.803 bisitz 6039: padding: 0;
1.345 albertel 6040: }
1.392 albertel 6041:
1.801 tempelho 6042: table#LC_title_bar a {
6043: color: $fontmenu;
6044: }
1.836 bisitz 6045:
1.807 droeschl 6046: table#LC_title_bar {
1.819 tempelho 6047: clear: both;
1.836 bisitz 6048: display: none;
1.807 droeschl 6049: }
6050:
1.795 www 6051: table#LC_title_bar,
1.933 droeschl 6052: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6053: table#LC_title_bar.LC_with_remote {
1.359 albertel 6054: width: 100%;
1.392 albertel 6055: border-color: $pgbg;
6056: border-style: solid;
6057: border-width: $border;
1.379 albertel 6058: background: $pgbg;
1.801 tempelho 6059: color: $fontmenu;
1.392 albertel 6060: border-collapse: collapse;
1.803 bisitz 6061: padding: 0;
1.819 tempelho 6062: margin: 0;
1.359 albertel 6063: }
1.795 www 6064:
1.933 droeschl 6065: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6066: margin: 0;
6067: padding: 0;
1.933 droeschl 6068: position: relative;
6069: list-style: none;
1.913 droeschl 6070: }
1.933 droeschl 6071: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6072: display: inline;
6073: }
1.933 droeschl 6074:
6075: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6076: padding: 0;
1.933 droeschl 6077: margin: 0;
6078: float: left;
1.913 droeschl 6079: }
1.933 droeschl 6080: .LC_breadcrumb_tools_tools {
6081: padding: 0;
6082: margin: 0;
1.913 droeschl 6083: float: right;
6084: }
6085:
1.359 albertel 6086: table#LC_title_bar td {
6087: background: $tabbg;
6088: }
1.795 www 6089:
1.911 bisitz 6090: table#LC_menubuttons img {
1.803 bisitz 6091: border: none;
1.346 albertel 6092: }
1.795 www 6093:
1.842 droeschl 6094: .LC_breadcrumbs_component {
1.911 bisitz 6095: float: right;
6096: margin: 0 1em;
1.357 albertel 6097: }
1.842 droeschl 6098: .LC_breadcrumbs_component img {
1.911 bisitz 6099: vertical-align: middle;
1.777 tempelho 6100: }
1.795 www 6101:
1.1075.2.108 raeburn 6102: .LC_breadcrumbs_hoverable {
6103: background: $sidebg;
6104: }
6105:
1.383 albertel 6106: td.LC_table_cell_checkbox {
6107: text-align: center;
6108: }
1.795 www 6109:
6110: .LC_fontsize_small {
1.911 bisitz 6111: font-size: 70%;
1.705 tempelho 6112: }
6113:
1.844 bisitz 6114: #LC_breadcrumbs {
1.911 bisitz 6115: clear:both;
6116: background: $sidebg;
6117: border-bottom: 1px solid $lg_border_color;
6118: line-height: 2.5em;
1.933 droeschl 6119: overflow: hidden;
1.911 bisitz 6120: margin: 0;
6121: padding: 0;
1.995 raeburn 6122: text-align: left;
1.819 tempelho 6123: }
1.862 bisitz 6124:
1.1075.2.16 raeburn 6125: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6126: clear:both;
6127: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6128: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6129: margin: 0 0 10px 0;
1.966 bisitz 6130: padding: 3px;
1.995 raeburn 6131: text-align: left;
1.822 bisitz 6132: }
6133:
1.795 www 6134: .LC_fontsize_medium {
1.911 bisitz 6135: font-size: 85%;
1.705 tempelho 6136: }
6137:
1.795 www 6138: .LC_fontsize_large {
1.911 bisitz 6139: font-size: 120%;
1.705 tempelho 6140: }
6141:
1.346 albertel 6142: .LC_menubuttons_inline_text {
6143: color: $font;
1.698 harmsja 6144: font-size: 90%;
1.701 harmsja 6145: padding-left:3px;
1.346 albertel 6146: }
6147:
1.934 droeschl 6148: .LC_menubuttons_inline_text img{
6149: vertical-align: middle;
6150: }
6151:
1.1051 www 6152: li.LC_menubuttons_inline_text img {
1.951 onken 6153: cursor:pointer;
1.1002 droeschl 6154: text-decoration: none;
1.951 onken 6155: }
6156:
1.526 www 6157: .LC_menubuttons_link {
6158: text-decoration: none;
6159: }
1.795 www 6160:
1.522 albertel 6161: .LC_menubuttons_category {
1.521 www 6162: color: $font;
1.526 www 6163: background: $pgbg;
1.521 www 6164: font-size: larger;
6165: font-weight: bold;
6166: }
6167:
1.346 albertel 6168: td.LC_menubuttons_text {
1.911 bisitz 6169: color: $font;
1.346 albertel 6170: }
1.706 harmsja 6171:
1.346 albertel 6172: .LC_current_location {
6173: background: $tabbg;
6174: }
1.795 www 6175:
1.1075.2.134 raeburn 6176: td.LC_zero_height {
6177: line-height: 0;
6178: cellpadding: 0;
6179: }
6180:
1.938 bisitz 6181: table.LC_data_table {
1.347 albertel 6182: border: 1px solid #000000;
1.402 albertel 6183: border-collapse: separate;
1.426 albertel 6184: border-spacing: 1px;
1.610 albertel 6185: background: $pgbg;
1.347 albertel 6186: }
1.795 www 6187:
1.422 albertel 6188: .LC_data_table_dense {
6189: font-size: small;
6190: }
1.795 www 6191:
1.507 raeburn 6192: table.LC_nested_outer {
6193: border: 1px solid #000000;
1.589 raeburn 6194: border-collapse: collapse;
1.803 bisitz 6195: border-spacing: 0;
1.507 raeburn 6196: width: 100%;
6197: }
1.795 www 6198:
1.879 raeburn 6199: table.LC_innerpickbox,
1.507 raeburn 6200: table.LC_nested {
1.803 bisitz 6201: border: none;
1.589 raeburn 6202: border-collapse: collapse;
1.803 bisitz 6203: border-spacing: 0;
1.507 raeburn 6204: width: 100%;
6205: }
1.795 www 6206:
1.911 bisitz 6207: table.LC_data_table tr th,
6208: table.LC_calendar tr th,
1.879 raeburn 6209: table.LC_prior_tries tr th,
6210: table.LC_innerpickbox tr th {
1.349 albertel 6211: font-weight: bold;
6212: background-color: $data_table_head;
1.801 tempelho 6213: color:$fontmenu;
1.701 harmsja 6214: font-size:90%;
1.347 albertel 6215: }
1.795 www 6216:
1.879 raeburn 6217: table.LC_innerpickbox tr th,
6218: table.LC_innerpickbox tr td {
6219: vertical-align: top;
6220: }
6221:
1.711 raeburn 6222: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6223: background-color: #CCCCCC;
1.711 raeburn 6224: font-weight: bold;
6225: text-align: left;
6226: }
1.795 www 6227:
1.912 bisitz 6228: table.LC_data_table tr.LC_odd_row > td {
6229: background-color: $data_table_light;
6230: padding: 2px;
6231: vertical-align: top;
6232: }
6233:
1.809 bisitz 6234: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6235: background-color: $data_table_light;
1.912 bisitz 6236: vertical-align: top;
6237: }
6238:
6239: table.LC_data_table tr.LC_even_row > td {
6240: background-color: $data_table_dark;
1.425 albertel 6241: padding: 2px;
1.900 bisitz 6242: vertical-align: top;
1.347 albertel 6243: }
1.795 www 6244:
1.809 bisitz 6245: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6246: background-color: $data_table_dark;
1.900 bisitz 6247: vertical-align: top;
1.347 albertel 6248: }
1.795 www 6249:
1.425 albertel 6250: table.LC_data_table tr.LC_data_table_highlight td {
6251: background-color: $data_table_darker;
6252: }
1.795 www 6253:
1.639 raeburn 6254: table.LC_data_table tr td.LC_leftcol_header {
6255: background-color: $data_table_head;
6256: font-weight: bold;
6257: }
1.795 www 6258:
1.451 albertel 6259: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6260: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6261: font-weight: bold;
6262: font-style: italic;
6263: text-align: center;
6264: padding: 8px;
1.347 albertel 6265: }
1.795 www 6266:
1.1075.2.30 raeburn 6267: table.LC_data_table tr.LC_empty_row td,
6268: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6269: background-color: $sidebg;
6270: }
6271:
6272: table.LC_nested tr.LC_empty_row td {
6273: background-color: #FFFFFF;
6274: }
6275:
1.890 droeschl 6276: table.LC_caption {
6277: }
6278:
1.507 raeburn 6279: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6280: padding: 4ex
6281: }
1.795 www 6282:
1.507 raeburn 6283: table.LC_nested_outer tr th {
6284: font-weight: bold;
1.801 tempelho 6285: color:$fontmenu;
1.507 raeburn 6286: background-color: $data_table_head;
1.701 harmsja 6287: font-size: small;
1.507 raeburn 6288: border-bottom: 1px solid #000000;
6289: }
1.795 www 6290:
1.507 raeburn 6291: table.LC_nested_outer tr td.LC_subheader {
6292: background-color: $data_table_head;
6293: font-weight: bold;
6294: font-size: small;
6295: border-bottom: 1px solid #000000;
6296: text-align: right;
1.451 albertel 6297: }
1.795 www 6298:
1.507 raeburn 6299: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6300: background-color: #CCCCCC;
1.451 albertel 6301: font-weight: bold;
6302: font-size: small;
1.507 raeburn 6303: text-align: center;
6304: }
1.795 www 6305:
1.589 raeburn 6306: table.LC_nested tr.LC_info_row td.LC_left_item,
6307: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6308: text-align: left;
1.451 albertel 6309: }
1.795 www 6310:
1.507 raeburn 6311: table.LC_nested td {
1.735 bisitz 6312: background-color: #FFFFFF;
1.451 albertel 6313: font-size: small;
1.507 raeburn 6314: }
1.795 www 6315:
1.507 raeburn 6316: table.LC_nested_outer tr th.LC_right_item,
6317: table.LC_nested tr.LC_info_row td.LC_right_item,
6318: table.LC_nested tr.LC_odd_row td.LC_right_item,
6319: table.LC_nested tr td.LC_right_item {
1.451 albertel 6320: text-align: right;
6321: }
6322:
1.507 raeburn 6323: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6324: background-color: #EEEEEE;
1.451 albertel 6325: }
6326:
1.473 raeburn 6327: table.LC_createuser {
6328: }
6329:
6330: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6331: font-size: small;
1.473 raeburn 6332: }
6333:
6334: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6335: background-color: #CCCCCC;
1.473 raeburn 6336: font-weight: bold;
6337: text-align: center;
6338: }
6339:
1.349 albertel 6340: table.LC_calendar {
6341: border: 1px solid #000000;
6342: border-collapse: collapse;
1.917 raeburn 6343: width: 98%;
1.349 albertel 6344: }
1.795 www 6345:
1.349 albertel 6346: table.LC_calendar_pickdate {
6347: font-size: xx-small;
6348: }
1.795 www 6349:
1.349 albertel 6350: table.LC_calendar tr td {
6351: border: 1px solid #000000;
6352: vertical-align: top;
1.917 raeburn 6353: width: 14%;
1.349 albertel 6354: }
1.795 www 6355:
1.349 albertel 6356: table.LC_calendar tr td.LC_calendar_day_empty {
6357: background-color: $data_table_dark;
6358: }
1.795 www 6359:
1.779 bisitz 6360: table.LC_calendar tr td.LC_calendar_day_current {
6361: background-color: $data_table_highlight;
1.777 tempelho 6362: }
1.795 www 6363:
1.938 bisitz 6364: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6365: background-color: $mail_new;
6366: }
1.795 www 6367:
1.938 bisitz 6368: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6369: background-color: $mail_new_hover;
6370: }
1.795 www 6371:
1.938 bisitz 6372: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6373: background-color: $mail_read;
6374: }
1.795 www 6375:
1.938 bisitz 6376: /*
6377: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6378: background-color: $mail_read_hover;
6379: }
1.938 bisitz 6380: */
1.795 www 6381:
1.938 bisitz 6382: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6383: background-color: $mail_replied;
6384: }
1.795 www 6385:
1.938 bisitz 6386: /*
6387: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6388: background-color: $mail_replied_hover;
6389: }
1.938 bisitz 6390: */
1.795 www 6391:
1.938 bisitz 6392: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6393: background-color: $mail_other;
6394: }
1.795 www 6395:
1.938 bisitz 6396: /*
6397: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6398: background-color: $mail_other_hover;
6399: }
1.938 bisitz 6400: */
1.494 raeburn 6401:
1.777 tempelho 6402: table.LC_data_table tr > td.LC_browser_file,
6403: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6404: background: #AAEE77;
1.389 albertel 6405: }
1.795 www 6406:
1.777 tempelho 6407: table.LC_data_table tr > td.LC_browser_file_locked,
6408: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6409: background: #FFAA99;
1.387 albertel 6410: }
1.795 www 6411:
1.777 tempelho 6412: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6413: background: #888888;
1.779 bisitz 6414: }
1.795 www 6415:
1.777 tempelho 6416: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6417: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6418: background: #F8F866;
1.777 tempelho 6419: }
1.795 www 6420:
1.696 bisitz 6421: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6422: background: #E0E8FF;
1.387 albertel 6423: }
1.696 bisitz 6424:
1.707 bisitz 6425: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6426: /* background: #77FF77; */
1.707 bisitz 6427: }
1.795 www 6428:
1.707 bisitz 6429: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6430: border-right: 8px solid #FFFF77;
1.707 bisitz 6431: }
1.795 www 6432:
1.707 bisitz 6433: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6434: border-right: 8px solid #FFAA77;
1.707 bisitz 6435: }
1.795 www 6436:
1.707 bisitz 6437: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6438: border-right: 8px solid #FF7777;
1.707 bisitz 6439: }
1.795 www 6440:
1.707 bisitz 6441: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6442: border-right: 8px solid #AAFF77;
1.707 bisitz 6443: }
1.795 www 6444:
1.707 bisitz 6445: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6446: border-right: 8px solid #11CC55;
1.707 bisitz 6447: }
6448:
1.388 albertel 6449: span.LC_current_location {
1.701 harmsja 6450: font-size:larger;
1.388 albertel 6451: background: $pgbg;
6452: }
1.387 albertel 6453:
1.1029 www 6454: span.LC_current_nav_location {
6455: font-weight:bold;
6456: background: $sidebg;
6457: }
6458:
1.395 albertel 6459: span.LC_parm_menu_item {
6460: font-size: larger;
6461: }
1.795 www 6462:
1.395 albertel 6463: span.LC_parm_scope_all {
6464: color: red;
6465: }
1.795 www 6466:
1.395 albertel 6467: span.LC_parm_scope_folder {
6468: color: green;
6469: }
1.795 www 6470:
1.395 albertel 6471: span.LC_parm_scope_resource {
6472: color: orange;
6473: }
1.795 www 6474:
1.395 albertel 6475: span.LC_parm_part {
6476: color: blue;
6477: }
1.795 www 6478:
1.911 bisitz 6479: span.LC_parm_folder,
6480: span.LC_parm_symb {
1.395 albertel 6481: font-size: x-small;
6482: font-family: $mono;
6483: color: #AAAAAA;
6484: }
6485:
1.977 bisitz 6486: ul.LC_parm_parmlist li {
6487: display: inline-block;
6488: padding: 0.3em 0.8em;
6489: vertical-align: top;
6490: width: 150px;
6491: border-top:1px solid $lg_border_color;
6492: }
6493:
1.795 www 6494: td.LC_parm_overview_level_menu,
6495: td.LC_parm_overview_map_menu,
6496: td.LC_parm_overview_parm_selectors,
6497: td.LC_parm_overview_restrictions {
1.396 albertel 6498: border: 1px solid black;
6499: border-collapse: collapse;
6500: }
1.795 www 6501:
1.396 albertel 6502: table.LC_parm_overview_restrictions td {
6503: border-width: 1px 4px 1px 4px;
6504: border-style: solid;
6505: border-color: $pgbg;
6506: text-align: center;
6507: }
1.795 www 6508:
1.396 albertel 6509: table.LC_parm_overview_restrictions th {
6510: background: $tabbg;
6511: border-width: 1px 4px 1px 4px;
6512: border-style: solid;
6513: border-color: $pgbg;
6514: }
1.795 www 6515:
1.398 albertel 6516: table#LC_helpmenu {
1.803 bisitz 6517: border: none;
1.398 albertel 6518: height: 55px;
1.803 bisitz 6519: border-spacing: 0;
1.398 albertel 6520: }
6521:
6522: table#LC_helpmenu fieldset legend {
6523: font-size: larger;
6524: }
1.795 www 6525:
1.397 albertel 6526: table#LC_helpmenu_links {
6527: width: 100%;
6528: border: 1px solid black;
6529: background: $pgbg;
1.803 bisitz 6530: padding: 0;
1.397 albertel 6531: border-spacing: 1px;
6532: }
1.795 www 6533:
1.397 albertel 6534: table#LC_helpmenu_links tr td {
6535: padding: 1px;
6536: background: $tabbg;
1.399 albertel 6537: text-align: center;
6538: font-weight: bold;
1.397 albertel 6539: }
1.396 albertel 6540:
1.795 www 6541: table#LC_helpmenu_links a:link,
6542: table#LC_helpmenu_links a:visited,
1.397 albertel 6543: table#LC_helpmenu_links a:active {
6544: text-decoration: none;
6545: color: $font;
6546: }
1.795 www 6547:
1.397 albertel 6548: table#LC_helpmenu_links a:hover {
6549: text-decoration: underline;
6550: color: $vlink;
6551: }
1.396 albertel 6552:
1.417 albertel 6553: .LC_chrt_popup_exists {
6554: border: 1px solid #339933;
6555: margin: -1px;
6556: }
1.795 www 6557:
1.417 albertel 6558: .LC_chrt_popup_up {
6559: border: 1px solid yellow;
6560: margin: -1px;
6561: }
1.795 www 6562:
1.417 albertel 6563: .LC_chrt_popup {
6564: border: 1px solid #8888FF;
6565: background: #CCCCFF;
6566: }
1.795 www 6567:
1.421 albertel 6568: table.LC_pick_box {
6569: border-collapse: separate;
6570: background: white;
6571: border: 1px solid black;
6572: border-spacing: 1px;
6573: }
1.795 www 6574:
1.421 albertel 6575: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6576: background: $sidebg;
1.421 albertel 6577: font-weight: bold;
1.900 bisitz 6578: text-align: left;
1.740 bisitz 6579: vertical-align: top;
1.421 albertel 6580: width: 184px;
6581: padding: 8px;
6582: }
1.795 www 6583:
1.579 raeburn 6584: table.LC_pick_box td.LC_pick_box_value {
6585: text-align: left;
6586: padding: 8px;
6587: }
1.795 www 6588:
1.579 raeburn 6589: table.LC_pick_box td.LC_pick_box_select {
6590: text-align: left;
6591: padding: 8px;
6592: }
1.795 www 6593:
1.424 albertel 6594: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6595: padding: 0;
1.421 albertel 6596: height: 1px;
6597: background: black;
6598: }
1.795 www 6599:
1.421 albertel 6600: table.LC_pick_box td.LC_pick_box_submit {
6601: text-align: right;
6602: }
1.795 www 6603:
1.579 raeburn 6604: table.LC_pick_box td.LC_evenrow_value {
6605: text-align: left;
6606: padding: 8px;
6607: background-color: $data_table_light;
6608: }
1.795 www 6609:
1.579 raeburn 6610: table.LC_pick_box td.LC_oddrow_value {
6611: text-align: left;
6612: padding: 8px;
6613: background-color: $data_table_light;
6614: }
1.795 www 6615:
1.579 raeburn 6616: span.LC_helpform_receipt_cat {
6617: font-weight: bold;
6618: }
1.795 www 6619:
1.424 albertel 6620: table.LC_group_priv_box {
6621: background: white;
6622: border: 1px solid black;
6623: border-spacing: 1px;
6624: }
1.795 www 6625:
1.424 albertel 6626: table.LC_group_priv_box td.LC_pick_box_title {
6627: background: $tabbg;
6628: font-weight: bold;
6629: text-align: right;
6630: width: 184px;
6631: }
1.795 www 6632:
1.424 albertel 6633: table.LC_group_priv_box td.LC_groups_fixed {
6634: background: $data_table_light;
6635: text-align: center;
6636: }
1.795 www 6637:
1.424 albertel 6638: table.LC_group_priv_box td.LC_groups_optional {
6639: background: $data_table_dark;
6640: text-align: center;
6641: }
1.795 www 6642:
1.424 albertel 6643: table.LC_group_priv_box td.LC_groups_functionality {
6644: background: $data_table_darker;
6645: text-align: center;
6646: font-weight: bold;
6647: }
1.795 www 6648:
1.424 albertel 6649: table.LC_group_priv td {
6650: text-align: left;
1.803 bisitz 6651: padding: 0;
1.424 albertel 6652: }
6653:
6654: .LC_navbuttons {
6655: margin: 2ex 0ex 2ex 0ex;
6656: }
1.795 www 6657:
1.423 albertel 6658: .LC_topic_bar {
6659: font-weight: bold;
6660: background: $tabbg;
1.918 wenzelju 6661: margin: 1em 0em 1em 2em;
1.805 bisitz 6662: padding: 3px;
1.918 wenzelju 6663: font-size: 1.2em;
1.423 albertel 6664: }
1.795 www 6665:
1.423 albertel 6666: .LC_topic_bar span {
1.918 wenzelju 6667: left: 0.5em;
6668: position: absolute;
1.423 albertel 6669: vertical-align: middle;
1.918 wenzelju 6670: font-size: 1.2em;
1.423 albertel 6671: }
1.795 www 6672:
1.423 albertel 6673: table.LC_course_group_status {
6674: margin: 20px;
6675: }
1.795 www 6676:
1.423 albertel 6677: table.LC_status_selector td {
6678: vertical-align: top;
6679: text-align: center;
1.424 albertel 6680: padding: 4px;
6681: }
1.795 www 6682:
1.599 albertel 6683: div.LC_feedback_link {
1.616 albertel 6684: clear: both;
1.829 kalberla 6685: background: $sidebg;
1.779 bisitz 6686: width: 100%;
1.829 kalberla 6687: padding-bottom: 10px;
6688: border: 1px $tabbg solid;
1.833 kalberla 6689: height: 22px;
6690: line-height: 22px;
6691: padding-top: 5px;
6692: }
6693:
6694: div.LC_feedback_link img {
6695: height: 22px;
1.867 kalberla 6696: vertical-align:middle;
1.829 kalberla 6697: }
6698:
1.911 bisitz 6699: div.LC_feedback_link a {
1.829 kalberla 6700: text-decoration: none;
1.489 raeburn 6701: }
1.795 www 6702:
1.867 kalberla 6703: div.LC_comblock {
1.911 bisitz 6704: display:inline;
1.867 kalberla 6705: color:$font;
6706: font-size:90%;
6707: }
6708:
6709: div.LC_feedback_link div.LC_comblock {
6710: padding-left:5px;
6711: }
6712:
6713: div.LC_feedback_link div.LC_comblock a {
6714: color:$font;
6715: }
6716:
1.489 raeburn 6717: span.LC_feedback_link {
1.858 bisitz 6718: /* background: $feedback_link_bg; */
1.599 albertel 6719: font-size: larger;
6720: }
1.795 www 6721:
1.599 albertel 6722: span.LC_message_link {
1.858 bisitz 6723: /* background: $feedback_link_bg; */
1.599 albertel 6724: font-size: larger;
6725: position: absolute;
6726: right: 1em;
1.489 raeburn 6727: }
1.421 albertel 6728:
1.515 albertel 6729: table.LC_prior_tries {
1.524 albertel 6730: border: 1px solid #000000;
6731: border-collapse: separate;
6732: border-spacing: 1px;
1.515 albertel 6733: }
1.523 albertel 6734:
1.515 albertel 6735: table.LC_prior_tries td {
1.524 albertel 6736: padding: 2px;
1.515 albertel 6737: }
1.523 albertel 6738:
6739: .LC_answer_correct {
1.795 www 6740: background: lightgreen;
6741: color: darkgreen;
6742: padding: 6px;
1.523 albertel 6743: }
1.795 www 6744:
1.523 albertel 6745: .LC_answer_charged_try {
1.797 www 6746: background: #FFAAAA;
1.795 www 6747: color: darkred;
6748: padding: 6px;
1.523 albertel 6749: }
1.795 www 6750:
1.779 bisitz 6751: .LC_answer_not_charged_try,
1.523 albertel 6752: .LC_answer_no_grade,
6753: .LC_answer_late {
1.795 www 6754: background: lightyellow;
1.523 albertel 6755: color: black;
1.795 www 6756: padding: 6px;
1.523 albertel 6757: }
1.795 www 6758:
1.523 albertel 6759: .LC_answer_previous {
1.795 www 6760: background: lightblue;
6761: color: darkblue;
6762: padding: 6px;
1.523 albertel 6763: }
1.795 www 6764:
1.779 bisitz 6765: .LC_answer_no_message {
1.777 tempelho 6766: background: #FFFFFF;
6767: color: black;
1.795 www 6768: padding: 6px;
1.779 bisitz 6769: }
1.795 www 6770:
1.1075.2.140 raeburn 6771: .LC_answer_unknown,
6772: .LC_answer_warning {
1.779 bisitz 6773: background: orange;
6774: color: black;
1.795 www 6775: padding: 6px;
1.777 tempelho 6776: }
1.795 www 6777:
1.529 albertel 6778: span.LC_prior_numerical,
6779: span.LC_prior_string,
6780: span.LC_prior_custom,
6781: span.LC_prior_reaction,
6782: span.LC_prior_math {
1.925 bisitz 6783: font-family: $mono;
1.523 albertel 6784: white-space: pre;
6785: }
6786:
1.525 albertel 6787: span.LC_prior_string {
1.925 bisitz 6788: font-family: $mono;
1.525 albertel 6789: white-space: pre;
6790: }
6791:
1.523 albertel 6792: table.LC_prior_option {
6793: width: 100%;
6794: border-collapse: collapse;
6795: }
1.795 www 6796:
1.911 bisitz 6797: table.LC_prior_rank,
1.795 www 6798: table.LC_prior_match {
1.528 albertel 6799: border-collapse: collapse;
6800: }
1.795 www 6801:
1.528 albertel 6802: table.LC_prior_option tr td,
6803: table.LC_prior_rank tr td,
6804: table.LC_prior_match tr td {
1.524 albertel 6805: border: 1px solid #000000;
1.515 albertel 6806: }
6807:
1.855 bisitz 6808: .LC_nobreak {
1.544 albertel 6809: white-space: nowrap;
1.519 raeburn 6810: }
6811:
1.576 raeburn 6812: span.LC_cusr_emph {
6813: font-style: italic;
6814: }
6815:
1.633 raeburn 6816: span.LC_cusr_subheading {
6817: font-weight: normal;
6818: font-size: 85%;
6819: }
6820:
1.861 bisitz 6821: div.LC_docs_entry_move {
1.859 bisitz 6822: border: 1px solid #BBBBBB;
1.545 albertel 6823: background: #DDDDDD;
1.861 bisitz 6824: width: 22px;
1.859 bisitz 6825: padding: 1px;
6826: margin: 0;
1.545 albertel 6827: }
6828:
1.861 bisitz 6829: table.LC_data_table tr > td.LC_docs_entry_commands,
6830: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6831: font-size: x-small;
6832: }
1.795 www 6833:
1.861 bisitz 6834: .LC_docs_entry_parameter {
6835: white-space: nowrap;
6836: }
6837:
1.544 albertel 6838: .LC_docs_copy {
1.545 albertel 6839: color: #000099;
1.544 albertel 6840: }
1.795 www 6841:
1.544 albertel 6842: .LC_docs_cut {
1.545 albertel 6843: color: #550044;
1.544 albertel 6844: }
1.795 www 6845:
1.544 albertel 6846: .LC_docs_rename {
1.545 albertel 6847: color: #009900;
1.544 albertel 6848: }
1.795 www 6849:
1.544 albertel 6850: .LC_docs_remove {
1.545 albertel 6851: color: #990000;
6852: }
6853:
1.1075.2.134 raeburn 6854: .LC_domprefs_email,
1.547 albertel 6855: .LC_docs_reinit_warn,
6856: .LC_docs_ext_edit {
6857: font-size: x-small;
6858: }
6859:
1.545 albertel 6860: table.LC_docs_adddocs td,
6861: table.LC_docs_adddocs th {
6862: border: 1px solid #BBBBBB;
6863: padding: 4px;
6864: background: #DDDDDD;
1.543 albertel 6865: }
6866:
1.584 albertel 6867: table.LC_sty_begin {
6868: background: #BBFFBB;
6869: }
1.795 www 6870:
1.584 albertel 6871: table.LC_sty_end {
6872: background: #FFBBBB;
6873: }
6874:
1.589 raeburn 6875: table.LC_double_column {
1.803 bisitz 6876: border-width: 0;
1.589 raeburn 6877: border-collapse: collapse;
6878: width: 100%;
6879: padding: 2px;
6880: }
6881:
6882: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6883: top: 2px;
1.589 raeburn 6884: left: 2px;
6885: width: 47%;
6886: vertical-align: top;
6887: }
6888:
6889: table.LC_double_column tr td.LC_right_col {
6890: top: 2px;
1.779 bisitz 6891: right: 2px;
1.589 raeburn 6892: width: 47%;
6893: vertical-align: top;
6894: }
6895:
1.591 raeburn 6896: div.LC_left_float {
6897: float: left;
6898: padding-right: 5%;
1.597 albertel 6899: padding-bottom: 4px;
1.591 raeburn 6900: }
6901:
6902: div.LC_clear_float_header {
1.597 albertel 6903: padding-bottom: 2px;
1.591 raeburn 6904: }
6905:
6906: div.LC_clear_float_footer {
1.597 albertel 6907: padding-top: 10px;
1.591 raeburn 6908: clear: both;
6909: }
6910:
1.597 albertel 6911: div.LC_grade_show_user {
1.941 bisitz 6912: /* border-left: 5px solid $sidebg; */
6913: border-top: 5px solid #000000;
6914: margin: 50px 0 0 0;
1.936 bisitz 6915: padding: 15px 0 5px 10px;
1.597 albertel 6916: }
1.795 www 6917:
1.936 bisitz 6918: div.LC_grade_show_user_odd_row {
1.941 bisitz 6919: /* border-left: 5px solid #000000; */
6920: }
6921:
6922: div.LC_grade_show_user div.LC_Box {
6923: margin-right: 50px;
1.597 albertel 6924: }
6925:
6926: div.LC_grade_submissions,
6927: div.LC_grade_message_center,
1.936 bisitz 6928: div.LC_grade_info_links {
1.597 albertel 6929: margin: 5px;
6930: width: 99%;
6931: background: #FFFFFF;
6932: }
1.795 www 6933:
1.597 albertel 6934: div.LC_grade_submissions_header,
1.936 bisitz 6935: div.LC_grade_message_center_header {
1.705 tempelho 6936: font-weight: bold;
6937: font-size: large;
1.597 albertel 6938: }
1.795 www 6939:
1.597 albertel 6940: div.LC_grade_submissions_body,
1.936 bisitz 6941: div.LC_grade_message_center_body {
1.597 albertel 6942: border: 1px solid black;
6943: width: 99%;
6944: background: #FFFFFF;
6945: }
1.795 www 6946:
1.613 albertel 6947: table.LC_scantron_action {
6948: width: 100%;
6949: }
1.795 www 6950:
1.613 albertel 6951: table.LC_scantron_action tr th {
1.698 harmsja 6952: font-weight:bold;
6953: font-style:normal;
1.613 albertel 6954: }
1.795 www 6955:
1.779 bisitz 6956: .LC_edit_problem_header,
1.614 albertel 6957: div.LC_edit_problem_footer {
1.705 tempelho 6958: font-weight: normal;
6959: font-size: medium;
1.602 albertel 6960: margin: 2px;
1.1060 bisitz 6961: background-color: $sidebg;
1.600 albertel 6962: }
1.795 www 6963:
1.600 albertel 6964: div.LC_edit_problem_header,
1.602 albertel 6965: div.LC_edit_problem_header div,
1.614 albertel 6966: div.LC_edit_problem_footer,
6967: div.LC_edit_problem_footer div,
1.602 albertel 6968: div.LC_edit_problem_editxml_header,
6969: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 6970: z-index: 100;
1.600 albertel 6971: }
1.795 www 6972:
1.600 albertel 6973: div.LC_edit_problem_header_title {
1.705 tempelho 6974: font-weight: bold;
6975: font-size: larger;
1.602 albertel 6976: background: $tabbg;
6977: padding: 3px;
1.1060 bisitz 6978: margin: 0 0 5px 0;
1.602 albertel 6979: }
1.795 www 6980:
1.602 albertel 6981: table.LC_edit_problem_header_title {
6982: width: 100%;
1.600 albertel 6983: background: $tabbg;
1.602 albertel 6984: }
6985:
1.1075.2.112 raeburn 6986: div.LC_edit_actionbar {
6987: background-color: $sidebg;
6988: margin: 0;
6989: padding: 0;
6990: line-height: 200%;
1.602 albertel 6991: }
1.795 www 6992:
1.1075.2.112 raeburn 6993: div.LC_edit_actionbar div{
6994: padding: 0;
6995: margin: 0;
6996: display: inline-block;
1.600 albertel 6997: }
1.795 www 6998:
1.1075.2.34 raeburn 6999: .LC_edit_opt {
7000: padding-left: 1em;
7001: white-space: nowrap;
7002: }
7003:
1.1075.2.57 raeburn 7004: .LC_edit_problem_latexhelper{
7005: text-align: right;
7006: }
7007:
7008: #LC_edit_problem_colorful div{
7009: margin-left: 40px;
7010: }
7011:
1.1075.2.112 raeburn 7012: #LC_edit_problem_codemirror div{
7013: margin-left: 0px;
7014: }
7015:
1.911 bisitz 7016: img.stift {
1.803 bisitz 7017: border-width: 0;
7018: vertical-align: middle;
1.677 riegler 7019: }
1.680 riegler 7020:
1.923 bisitz 7021: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7022: vertical-align: top;
1.777 tempelho 7023: }
1.795 www 7024:
1.716 raeburn 7025: div.LC_createcourse {
1.911 bisitz 7026: margin: 10px 10px 10px 10px;
1.716 raeburn 7027: }
7028:
1.917 raeburn 7029: .LC_dccid {
1.1075.2.38 raeburn 7030: float: right;
1.917 raeburn 7031: margin: 0.2em 0 0 0;
7032: padding: 0;
7033: font-size: 90%;
7034: display:none;
7035: }
7036:
1.897 wenzelju 7037: ol.LC_primary_menu a:hover,
1.721 harmsja 7038: ol#LC_MenuBreadcrumbs a:hover,
7039: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7040: ul#LC_secondary_menu a:hover,
1.721 harmsja 7041: .LC_FormSectionClearButton input:hover
1.795 www 7042: ul.LC_TabContent li:hover a {
1.952 onken 7043: color:$button_hover;
1.911 bisitz 7044: text-decoration:none;
1.693 droeschl 7045: }
7046:
1.779 bisitz 7047: h1 {
1.911 bisitz 7048: padding: 0;
7049: line-height:130%;
1.693 droeschl 7050: }
1.698 harmsja 7051:
1.911 bisitz 7052: h2,
7053: h3,
7054: h4,
7055: h5,
7056: h6 {
7057: margin: 5px 0 5px 0;
7058: padding: 0;
7059: line-height:130%;
1.693 droeschl 7060: }
1.795 www 7061:
7062: .LC_hcell {
1.911 bisitz 7063: padding:3px 15px 3px 15px;
7064: margin: 0;
7065: background-color:$tabbg;
7066: color:$fontmenu;
7067: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7068: }
1.795 www 7069:
1.840 bisitz 7070: .LC_Box > .LC_hcell {
1.911 bisitz 7071: margin: 0 -10px 10px -10px;
1.835 bisitz 7072: }
7073:
1.721 harmsja 7074: .LC_noBorder {
1.911 bisitz 7075: border: 0;
1.698 harmsja 7076: }
1.693 droeschl 7077:
1.721 harmsja 7078: .LC_FormSectionClearButton input {
1.911 bisitz 7079: background-color:transparent;
7080: border: none;
7081: cursor:pointer;
7082: text-decoration:underline;
1.693 droeschl 7083: }
1.763 bisitz 7084:
7085: .LC_help_open_topic {
1.911 bisitz 7086: color: #FFFFFF;
7087: background-color: #EEEEFF;
7088: margin: 1px;
7089: padding: 4px;
7090: border: 1px solid #000033;
7091: white-space: nowrap;
7092: /* vertical-align: middle; */
1.759 neumanie 7093: }
1.693 droeschl 7094:
1.911 bisitz 7095: dl,
7096: ul,
7097: div,
7098: fieldset {
7099: margin: 10px 10px 10px 0;
7100: /* overflow: hidden; */
1.693 droeschl 7101: }
1.795 www 7102:
1.1075.2.90 raeburn 7103: article.geogebraweb div {
7104: margin: 0;
7105: }
7106:
1.838 bisitz 7107: fieldset > legend {
1.911 bisitz 7108: font-weight: bold;
7109: padding: 0 5px 0 5px;
1.838 bisitz 7110: }
7111:
1.813 bisitz 7112: #LC_nav_bar {
1.911 bisitz 7113: float: left;
1.995 raeburn 7114: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7115: margin: 0 0 2px 0;
1.807 droeschl 7116: }
7117:
1.916 droeschl 7118: #LC_realm {
7119: margin: 0.2em 0 0 0;
7120: padding: 0;
7121: font-weight: bold;
7122: text-align: center;
1.995 raeburn 7123: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7124: }
7125:
1.911 bisitz 7126: #LC_nav_bar em {
7127: font-weight: bold;
7128: font-style: normal;
1.807 droeschl 7129: }
7130:
1.897 wenzelju 7131: ol.LC_primary_menu {
1.934 droeschl 7132: margin: 0;
1.1075.2.2 raeburn 7133: padding: 0;
1.807 droeschl 7134: }
7135:
1.852 droeschl 7136: ol#LC_PathBreadcrumbs {
1.911 bisitz 7137: margin: 0;
1.693 droeschl 7138: }
7139:
1.897 wenzelju 7140: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7141: color: RGB(80, 80, 80);
7142: vertical-align: middle;
7143: text-align: left;
7144: list-style: none;
1.1075.2.112 raeburn 7145: position: relative;
1.1075.2.2 raeburn 7146: float: left;
1.1075.2.112 raeburn 7147: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7148: line-height: 1.5em;
1.1075.2.2 raeburn 7149: }
7150:
1.1075.2.113 raeburn 7151: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7152: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7153: display: block;
7154: margin: 0;
7155: padding: 0 5px 0 10px;
7156: text-decoration: none;
7157: }
7158:
1.1075.2.112 raeburn 7159: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7160: display: inline-block;
7161: width: 95%;
7162: text-align: left;
7163: }
7164:
7165: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7166: display: inline-block;
7167: width: 5%;
7168: float: right;
7169: text-align: right;
7170: font-size: 70%;
7171: }
7172:
7173: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7174: display: none;
1.1075.2.112 raeburn 7175: width: 15em;
1.1075.2.2 raeburn 7176: background-color: $data_table_light;
1.1075.2.112 raeburn 7177: position: absolute;
7178: top: 100%;
7179: }
7180:
7181: ol.LC_primary_menu ul ul {
7182: left: 100%;
7183: top: 0;
1.1075.2.2 raeburn 7184: }
7185:
1.1075.2.112 raeburn 7186: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7187: display: block;
7188: position: absolute;
7189: margin: 0;
7190: padding: 0;
1.1075.2.5 raeburn 7191: z-index: 2;
1.1075.2.2 raeburn 7192: }
7193:
7194: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7195: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7196: font-size: 90%;
1.911 bisitz 7197: vertical-align: top;
1.1075.2.2 raeburn 7198: float: none;
1.1075.2.5 raeburn 7199: border-left: 1px solid black;
7200: border-right: 1px solid black;
1.1075.2.112 raeburn 7201: /* A dark bottom border to visualize different menu options;
7202: overwritten in the create_submenu routine for the last border-bottom of the menu */
7203: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7204: }
7205:
1.1075.2.112 raeburn 7206: ol.LC_primary_menu li li p:hover {
7207: color:$button_hover;
7208: text-decoration:none;
7209: background-color:$data_table_dark;
1.1075.2.2 raeburn 7210: }
7211:
7212: ol.LC_primary_menu li li a:hover {
7213: color:$button_hover;
7214: background-color:$data_table_dark;
1.693 droeschl 7215: }
7216:
1.1075.2.112 raeburn 7217: /* Font-size equal to the size of the predecessors*/
7218: ol.LC_primary_menu li:hover li li {
7219: font-size: 100%;
7220: }
7221:
1.897 wenzelju 7222: ol.LC_primary_menu li img {
1.911 bisitz 7223: vertical-align: bottom;
1.934 droeschl 7224: height: 1.1em;
1.1075.2.3 raeburn 7225: margin: 0.2em 0 0 0;
1.693 droeschl 7226: }
7227:
1.897 wenzelju 7228: ol.LC_primary_menu a {
1.911 bisitz 7229: color: RGB(80, 80, 80);
7230: text-decoration: none;
1.693 droeschl 7231: }
1.795 www 7232:
1.949 droeschl 7233: ol.LC_primary_menu a.LC_new_message {
7234: font-weight:bold;
7235: color: darkred;
7236: }
7237:
1.975 raeburn 7238: ol.LC_docs_parameters {
7239: margin-left: 0;
7240: padding: 0;
7241: list-style: none;
7242: }
7243:
7244: ol.LC_docs_parameters li {
7245: margin: 0;
7246: padding-right: 20px;
7247: display: inline;
7248: }
7249:
1.976 raeburn 7250: ol.LC_docs_parameters li:before {
7251: content: "\\002022 \\0020";
7252: }
7253:
7254: li.LC_docs_parameters_title {
7255: font-weight: bold;
7256: }
7257:
7258: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7259: content: "";
7260: }
7261:
1.897 wenzelju 7262: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7263: clear: right;
1.911 bisitz 7264: color: $fontmenu;
7265: background: $tabbg;
7266: list-style: none;
7267: padding: 0;
7268: margin: 0;
7269: width: 100%;
1.995 raeburn 7270: text-align: left;
1.1075.2.4 raeburn 7271: float: left;
1.808 droeschl 7272: }
7273:
1.897 wenzelju 7274: ul#LC_secondary_menu li {
1.911 bisitz 7275: font-weight: bold;
7276: line-height: 1.8em;
7277: border-right: 1px solid black;
1.1075.2.4 raeburn 7278: float: left;
7279: }
7280:
7281: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7282: background-color: $data_table_light;
7283: }
7284:
7285: ul#LC_secondary_menu li a {
7286: padding: 0 0.8em;
7287: }
7288:
7289: ul#LC_secondary_menu li ul {
7290: display: none;
7291: }
7292:
7293: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7294: display: block;
7295: position: absolute;
7296: margin: 0;
7297: padding: 0;
7298: list-style:none;
7299: float: none;
7300: background-color: $data_table_light;
1.1075.2.5 raeburn 7301: z-index: 2;
1.1075.2.10 raeburn 7302: margin-left: -1px;
1.1075.2.4 raeburn 7303: }
7304:
7305: ul#LC_secondary_menu li ul li {
7306: font-size: 90%;
7307: vertical-align: top;
7308: border-left: 1px solid black;
7309: border-right: 1px solid black;
1.1075.2.33 raeburn 7310: background-color: $data_table_light;
1.1075.2.4 raeburn 7311: list-style:none;
7312: float: none;
7313: }
7314:
7315: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7316: background-color: $data_table_dark;
1.807 droeschl 7317: }
7318:
1.847 tempelho 7319: ul.LC_TabContent {
1.911 bisitz 7320: display:block;
7321: background: $sidebg;
7322: border-bottom: solid 1px $lg_border_color;
7323: list-style:none;
1.1020 raeburn 7324: margin: -1px -10px 0 -10px;
1.911 bisitz 7325: padding: 0;
1.693 droeschl 7326: }
7327:
1.795 www 7328: ul.LC_TabContent li,
7329: ul.LC_TabContentBigger li {
1.911 bisitz 7330: float:left;
1.741 harmsja 7331: }
1.795 www 7332:
1.897 wenzelju 7333: ul#LC_secondary_menu li a {
1.911 bisitz 7334: color: $fontmenu;
7335: text-decoration: none;
1.693 droeschl 7336: }
1.795 www 7337:
1.721 harmsja 7338: ul.LC_TabContent {
1.952 onken 7339: min-height:20px;
1.721 harmsja 7340: }
1.795 www 7341:
7342: ul.LC_TabContent li {
1.911 bisitz 7343: vertical-align:middle;
1.959 onken 7344: padding: 0 16px 0 10px;
1.911 bisitz 7345: background-color:$tabbg;
7346: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7347: border-left: solid 1px $font;
1.721 harmsja 7348: }
1.795 www 7349:
1.847 tempelho 7350: ul.LC_TabContent .right {
1.911 bisitz 7351: float:right;
1.847 tempelho 7352: }
7353:
1.911 bisitz 7354: ul.LC_TabContent li a,
7355: ul.LC_TabContent li {
7356: color:rgb(47,47,47);
7357: text-decoration:none;
7358: font-size:95%;
7359: font-weight:bold;
1.952 onken 7360: min-height:20px;
7361: }
7362:
1.959 onken 7363: ul.LC_TabContent li a:hover,
7364: ul.LC_TabContent li a:focus {
1.952 onken 7365: color: $button_hover;
1.959 onken 7366: background:none;
7367: outline:none;
1.952 onken 7368: }
7369:
7370: ul.LC_TabContent li:hover {
7371: color: $button_hover;
7372: cursor:pointer;
1.721 harmsja 7373: }
1.795 www 7374:
1.911 bisitz 7375: ul.LC_TabContent li.active {
1.952 onken 7376: color: $font;
1.911 bisitz 7377: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7378: border-bottom:solid 1px #FFFFFF;
7379: cursor: default;
1.744 ehlerst 7380: }
1.795 www 7381:
1.959 onken 7382: ul.LC_TabContent li.active a {
7383: color:$font;
7384: background:#FFFFFF;
7385: outline: none;
7386: }
1.1047 raeburn 7387:
7388: ul.LC_TabContent li.goback {
7389: float: left;
7390: border-left: none;
7391: }
7392:
1.870 tempelho 7393: #maincoursedoc {
1.911 bisitz 7394: clear:both;
1.870 tempelho 7395: }
7396:
7397: ul.LC_TabContentBigger {
1.911 bisitz 7398: display:block;
7399: list-style:none;
7400: padding: 0;
1.870 tempelho 7401: }
7402:
1.795 www 7403: ul.LC_TabContentBigger li {
1.911 bisitz 7404: vertical-align:bottom;
7405: height: 30px;
7406: font-size:110%;
7407: font-weight:bold;
7408: color: #737373;
1.841 tempelho 7409: }
7410:
1.957 onken 7411: ul.LC_TabContentBigger li.active {
7412: position: relative;
7413: top: 1px;
7414: }
7415:
1.870 tempelho 7416: ul.LC_TabContentBigger li a {
1.911 bisitz 7417: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7418: height: 30px;
7419: line-height: 30px;
7420: text-align: center;
7421: display: block;
7422: text-decoration: none;
1.958 onken 7423: outline: none;
1.741 harmsja 7424: }
1.795 www 7425:
1.870 tempelho 7426: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7427: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7428: color:$font;
1.744 ehlerst 7429: }
1.795 www 7430:
1.870 tempelho 7431: ul.LC_TabContentBigger li b {
1.911 bisitz 7432: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7433: display: block;
7434: float: left;
7435: padding: 0 30px;
1.957 onken 7436: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7437: }
7438:
1.956 onken 7439: ul.LC_TabContentBigger li:hover b {
7440: color:$button_hover;
7441: }
7442:
1.870 tempelho 7443: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7444: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7445: color:$font;
1.957 onken 7446: border: 0;
1.741 harmsja 7447: }
1.693 droeschl 7448:
1.870 tempelho 7449:
1.862 bisitz 7450: ul.LC_CourseBreadcrumbs {
7451: background: $sidebg;
1.1020 raeburn 7452: height: 2em;
1.862 bisitz 7453: padding-left: 10px;
1.1020 raeburn 7454: margin: 0;
1.862 bisitz 7455: list-style-position: inside;
7456: }
7457:
1.911 bisitz 7458: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7459: ol#LC_PathBreadcrumbs {
1.911 bisitz 7460: padding-left: 10px;
7461: margin: 0;
1.933 droeschl 7462: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7463: }
7464:
1.911 bisitz 7465: ol#LC_MenuBreadcrumbs li,
7466: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7467: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7468: display: inline;
1.933 droeschl 7469: white-space: normal;
1.693 droeschl 7470: }
7471:
1.823 bisitz 7472: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7473: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7474: text-decoration: none;
7475: font-size:90%;
1.693 droeschl 7476: }
1.795 www 7477:
1.969 droeschl 7478: ol#LC_MenuBreadcrumbs h1 {
7479: display: inline;
7480: font-size: 90%;
7481: line-height: 2.5em;
7482: margin: 0;
7483: padding: 0;
7484: }
7485:
1.795 www 7486: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7487: text-decoration:none;
7488: font-size:100%;
7489: font-weight:bold;
1.693 droeschl 7490: }
1.795 www 7491:
1.840 bisitz 7492: .LC_Box {
1.911 bisitz 7493: border: solid 1px $lg_border_color;
7494: padding: 0 10px 10px 10px;
1.746 neumanie 7495: }
1.795 www 7496:
1.1020 raeburn 7497: .LC_DocsBox {
7498: border: solid 1px $lg_border_color;
7499: padding: 0 0 10px 10px;
7500: }
7501:
1.795 www 7502: .LC_AboutMe_Image {
1.911 bisitz 7503: float:left;
7504: margin-right:10px;
1.747 neumanie 7505: }
1.795 www 7506:
7507: .LC_Clear_AboutMe_Image {
1.911 bisitz 7508: clear:left;
1.747 neumanie 7509: }
1.795 www 7510:
1.721 harmsja 7511: dl.LC_ListStyleClean dt {
1.911 bisitz 7512: padding-right: 5px;
7513: display: table-header-group;
1.693 droeschl 7514: }
7515:
1.721 harmsja 7516: dl.LC_ListStyleClean dd {
1.911 bisitz 7517: display: table-row;
1.693 droeschl 7518: }
7519:
1.721 harmsja 7520: .LC_ListStyleClean,
7521: .LC_ListStyleSimple,
7522: .LC_ListStyleNormal,
1.795 www 7523: .LC_ListStyleSpecial {
1.911 bisitz 7524: /* display:block; */
7525: list-style-position: inside;
7526: list-style-type: none;
7527: overflow: hidden;
7528: padding: 0;
1.693 droeschl 7529: }
7530:
1.721 harmsja 7531: .LC_ListStyleSimple li,
7532: .LC_ListStyleSimple dd,
7533: .LC_ListStyleNormal li,
7534: .LC_ListStyleNormal dd,
7535: .LC_ListStyleSpecial li,
1.795 www 7536: .LC_ListStyleSpecial dd {
1.911 bisitz 7537: margin: 0;
7538: padding: 5px 5px 5px 10px;
7539: clear: both;
1.693 droeschl 7540: }
7541:
1.721 harmsja 7542: .LC_ListStyleClean li,
7543: .LC_ListStyleClean dd {
1.911 bisitz 7544: padding-top: 0;
7545: padding-bottom: 0;
1.693 droeschl 7546: }
7547:
1.721 harmsja 7548: .LC_ListStyleSimple dd,
1.795 www 7549: .LC_ListStyleSimple li {
1.911 bisitz 7550: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7551: }
7552:
1.721 harmsja 7553: .LC_ListStyleSpecial li,
7554: .LC_ListStyleSpecial dd {
1.911 bisitz 7555: list-style-type: none;
7556: background-color: RGB(220, 220, 220);
7557: margin-bottom: 4px;
1.693 droeschl 7558: }
7559:
1.721 harmsja 7560: table.LC_SimpleTable {
1.911 bisitz 7561: margin:5px;
7562: border:solid 1px $lg_border_color;
1.795 www 7563: }
1.693 droeschl 7564:
1.721 harmsja 7565: table.LC_SimpleTable tr {
1.911 bisitz 7566: padding: 0;
7567: border:solid 1px $lg_border_color;
1.693 droeschl 7568: }
1.795 www 7569:
7570: table.LC_SimpleTable thead {
1.911 bisitz 7571: background:rgb(220,220,220);
1.693 droeschl 7572: }
7573:
1.721 harmsja 7574: div.LC_columnSection {
1.911 bisitz 7575: display: block;
7576: clear: both;
7577: overflow: hidden;
7578: margin: 0;
1.693 droeschl 7579: }
7580:
1.721 harmsja 7581: div.LC_columnSection>* {
1.911 bisitz 7582: float: left;
7583: margin: 10px 20px 10px 0;
7584: overflow:hidden;
1.693 droeschl 7585: }
1.721 harmsja 7586:
1.795 www 7587: table em {
1.911 bisitz 7588: font-weight: bold;
7589: font-style: normal;
1.748 schulted 7590: }
1.795 www 7591:
1.779 bisitz 7592: table.LC_tableBrowseRes,
1.795 www 7593: table.LC_tableOfContent {
1.911 bisitz 7594: border:none;
7595: border-spacing: 1px;
7596: padding: 3px;
7597: background-color: #FFFFFF;
7598: font-size: 90%;
1.753 droeschl 7599: }
1.789 droeschl 7600:
1.911 bisitz 7601: table.LC_tableOfContent {
7602: border-collapse: collapse;
1.789 droeschl 7603: }
7604:
1.771 droeschl 7605: table.LC_tableBrowseRes a,
1.768 schulted 7606: table.LC_tableOfContent a {
1.911 bisitz 7607: background-color: transparent;
7608: text-decoration: none;
1.753 droeschl 7609: }
7610:
1.795 www 7611: table.LC_tableOfContent img {
1.911 bisitz 7612: border: none;
7613: height: 1.3em;
7614: vertical-align: text-bottom;
7615: margin-right: 0.3em;
1.753 droeschl 7616: }
1.757 schulted 7617:
1.795 www 7618: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7619: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7620: }
7621:
1.795 www 7622: a#LC_content_toolbar_everything {
1.911 bisitz 7623: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7624: }
7625:
1.795 www 7626: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7627: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7628: }
7629:
1.795 www 7630: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7631: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7632: }
7633:
1.795 www 7634: a#LC_content_toolbar_changefolder {
1.911 bisitz 7635: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7636: }
7637:
1.795 www 7638: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7639: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7640: }
7641:
1.1043 raeburn 7642: a#LC_content_toolbar_edittoplevel {
7643: background-image:url(/res/adm/pages/edittoplevel.gif);
7644: }
7645:
1.795 www 7646: ul#LC_toolbar li a:hover {
1.911 bisitz 7647: background-position: bottom center;
1.757 schulted 7648: }
7649:
1.795 www 7650: ul#LC_toolbar {
1.911 bisitz 7651: padding: 0;
7652: margin: 2px;
7653: list-style:none;
7654: position:relative;
7655: background-color:white;
1.1075.2.9 raeburn 7656: overflow: auto;
1.757 schulted 7657: }
7658:
1.795 www 7659: ul#LC_toolbar li {
1.911 bisitz 7660: border:1px solid white;
7661: padding: 0;
7662: margin: 0;
7663: float: left;
7664: display:inline;
7665: vertical-align:middle;
1.1075.2.9 raeburn 7666: white-space: nowrap;
1.911 bisitz 7667: }
1.757 schulted 7668:
1.783 amueller 7669:
1.795 www 7670: a.LC_toolbarItem {
1.911 bisitz 7671: display:block;
7672: padding: 0;
7673: margin: 0;
7674: height: 32px;
7675: width: 32px;
7676: color:white;
7677: border: none;
7678: background-repeat:no-repeat;
7679: background-color:transparent;
1.757 schulted 7680: }
7681:
1.915 droeschl 7682: ul.LC_funclist {
7683: margin: 0;
7684: padding: 0.5em 1em 0.5em 0;
7685: }
7686:
1.933 droeschl 7687: ul.LC_funclist > li:first-child {
7688: font-weight:bold;
7689: margin-left:0.8em;
7690: }
7691:
1.915 droeschl 7692: ul.LC_funclist + ul.LC_funclist {
7693: /*
7694: left border as a seperator if we have more than
7695: one list
7696: */
7697: border-left: 1px solid $sidebg;
7698: /*
7699: this hides the left border behind the border of the
7700: outer box if element is wrapped to the next 'line'
7701: */
7702: margin-left: -1px;
7703: }
7704:
1.843 bisitz 7705: ul.LC_funclist li {
1.915 droeschl 7706: display: inline;
1.782 bisitz 7707: white-space: nowrap;
1.915 droeschl 7708: margin: 0 0 0 25px;
7709: line-height: 150%;
1.782 bisitz 7710: }
7711:
1.974 wenzelju 7712: .LC_hidden {
7713: display: none;
7714: }
7715:
1.1030 www 7716: .LCmodal-overlay {
7717: position:fixed;
7718: top:0;
7719: right:0;
7720: bottom:0;
7721: left:0;
7722: height:100%;
7723: width:100%;
7724: margin:0;
7725: padding:0;
7726: background:#999;
7727: opacity:.75;
7728: filter: alpha(opacity=75);
7729: -moz-opacity: 0.75;
7730: z-index:101;
7731: }
7732:
7733: * html .LCmodal-overlay {
7734: position: absolute;
7735: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7736: }
7737:
7738: .LCmodal-window {
7739: position:fixed;
7740: top:50%;
7741: left:50%;
7742: margin:0;
7743: padding:0;
7744: z-index:102;
7745: }
7746:
7747: * html .LCmodal-window {
7748: position:absolute;
7749: }
7750:
7751: .LCclose-window {
7752: position:absolute;
7753: width:32px;
7754: height:32px;
7755: right:8px;
7756: top:8px;
7757: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7758: text-indent:-99999px;
7759: overflow:hidden;
7760: cursor:pointer;
7761: }
7762:
1.1075.2.141 raeburn 7763: pre.LC_wordwrap {
7764: white-space: pre-wrap;
7765: white-space: -moz-pre-wrap;
7766: white-space: -pre-wrap;
7767: white-space: -o-pre-wrap;
7768: word-wrap: break-word;
7769: }
7770:
1.1075.2.17 raeburn 7771: /*
7772: styles used by TTH when "Default set of options to pass to tth/m
7773: when converting TeX" in course settings has been set
7774:
7775: option passed: -t
7776:
7777: */
7778:
7779: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7780: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7781: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7782: td div.norm {line-height:normal;}
7783:
7784: /*
7785: option passed -y3
7786: */
7787:
7788: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7789: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7790: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7791:
1.1075.2.121 raeburn 7792: #LC_minitab_header {
7793: float:left;
7794: width:100%;
7795: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
7796: font-size:93%;
7797: line-height:normal;
7798: margin: 0.5em 0 0.5em 0;
7799: }
7800: #LC_minitab_header ul {
7801: margin:0;
7802: padding:10px 10px 0;
7803: list-style:none;
7804: }
7805: #LC_minitab_header li {
7806: float:left;
7807: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
7808: margin:0;
7809: padding:0 0 0 9px;
7810: }
7811: #LC_minitab_header a {
7812: display:block;
7813: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
7814: padding:5px 15px 4px 6px;
7815: }
7816: #LC_minitab_header #LC_current_minitab {
7817: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
7818: }
7819: #LC_minitab_header #LC_current_minitab a {
7820: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
7821: padding-bottom:5px;
7822: }
7823:
7824:
1.343 albertel 7825: END
7826: }
7827:
1.306 albertel 7828: =pod
7829:
7830: =item * &headtag()
7831:
7832: Returns a uniform footer for LON-CAPA web pages.
7833:
1.307 albertel 7834: Inputs: $title - optional title for the head
7835: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7836: $args - optional arguments
1.319 albertel 7837: force_register - if is true call registerurl so the remote is
7838: informed
1.415 albertel 7839: redirect -> array ref of
7840: 1- seconds before redirect occurs
7841: 2- url to redirect to
7842: 3- whether the side effect should occur
1.315 albertel 7843: (side effect of setting
7844: $env{'internal.head.redirect'} to the url
7845: redirected too)
1.352 albertel 7846: domain -> force to color decorate a page for a specific
7847: domain
7848: function -> force usage of a specific rolish color scheme
7849: bgcolor -> override the default page bgcolor
1.460 albertel 7850: no_auto_mt_title
7851: -> prevent &mt()ing the title arg
1.464 albertel 7852:
1.306 albertel 7853: =cut
7854:
7855: sub headtag {
1.313 albertel 7856: my ($title,$head_extra,$args) = @_;
1.306 albertel 7857:
1.363 albertel 7858: my $function = $args->{'function'} || &get_users_function();
7859: my $domain = $args->{'domain'} || &determinedomain();
7860: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7861: my $httphost = $args->{'use_absolute'};
1.418 albertel 7862: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7863: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7864: #time(),
1.418 albertel 7865: $env{'environment.color.timestamp'},
1.363 albertel 7866: $function,$domain,$bgcolor);
7867:
1.369 www 7868: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7869:
1.308 albertel 7870: my $result =
7871: '<head>'.
1.1075.2.56 raeburn 7872: &font_settings($args);
1.319 albertel 7873:
1.1075.2.72 raeburn 7874: my $inhibitprint;
7875: if ($args->{'print_suppress'}) {
7876: $inhibitprint = &print_suppression();
7877: }
1.1064 raeburn 7878:
1.461 albertel 7879: if (!$args->{'frameset'}) {
7880: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7881: }
1.1075.2.12 raeburn 7882: if ($args->{'force_register'}) {
7883: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7884: }
1.436 albertel 7885: if (!$args->{'no_nav_bar'}
7886: && !$args->{'only_body'}
7887: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7888: $result .= &help_menu_js($httphost);
1.1032 www 7889: $result.=&modal_window();
1.1038 www 7890: $result.=&togglebox_script();
1.1034 www 7891: $result.=&wishlist_window();
1.1041 www 7892: $result.=&LCprogressbarUpdate_script();
1.1034 www 7893: } else {
7894: if ($args->{'add_modal'}) {
7895: $result.=&modal_window();
7896: }
7897: if ($args->{'add_wishlist'}) {
7898: $result.=&wishlist_window();
7899: }
1.1038 www 7900: if ($args->{'add_togglebox'}) {
7901: $result.=&togglebox_script();
7902: }
1.1041 www 7903: if ($args->{'add_progressbar'}) {
7904: $result.=&LCprogressbarUpdate_script();
7905: }
1.436 albertel 7906: }
1.314 albertel 7907: if (ref($args->{'redirect'})) {
1.414 albertel 7908: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7909: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7910: if (!$inhibit_continue) {
7911: $env{'internal.head.redirect'} = $url;
7912: }
1.313 albertel 7913: $result.=<<ADDMETA
7914: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7915: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7916: ADDMETA
1.1075.2.89 raeburn 7917: } else {
7918: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7919: my $requrl = $env{'request.uri'};
7920: if ($requrl eq '') {
7921: $requrl = $ENV{'REQUEST_URI'};
7922: $requrl =~ s/\?.+$//;
7923: }
7924: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7925: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7926: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7927: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7928: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7929: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7930: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7931: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7932: if ($domdefs{'offloadnow'}{$lonhost}) {
7933: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7934: if (($newserver) && ($newserver ne $lonhost)) {
7935: my $numsec = 5;
7936: my $timeout = $numsec * 1000;
7937: my ($newurl,$locknum,%locks,$msg);
7938: if ($env{'request.role.adv'}) {
7939: ($locknum,%locks) = &Apache::lonnet::get_locks();
7940: }
7941: my $disable_submit = 0;
7942: if ($requrl =~ /$LONCAPA::assess_re/) {
7943: $disable_submit = 1;
7944: }
7945: if ($locknum) {
7946: my @lockinfo = sort(values(%locks));
7947: $msg = &mt('Once the following tasks are complete: ')."\\n".
7948: join(", ",sort(values(%locks)))."\\n".
7949: &mt('your session will be transferred to a different server, after you click "Roles".');
7950: } else {
7951: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7952: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7953: }
7954: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7955: $newurl = '/adm/switchserver?otherserver='.$newserver;
7956: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7957: $newurl .= '&role='.$env{'request.role'};
7958: }
7959: if ($env{'request.symb'}) {
7960: $newurl .= '&symb='.$env{'request.symb'};
7961: } else {
7962: $newurl .= '&origurl='.$requrl;
7963: }
7964: }
1.1075.2.98 raeburn 7965: &js_escape(\$msg);
1.1075.2.89 raeburn 7966: $result.=<<OFFLOAD
7967: <meta http-equiv="pragma" content="no-cache" />
7968: <script type="text/javascript">
1.1075.2.92 raeburn 7969: // <![CDATA[
1.1075.2.89 raeburn 7970: function LC_Offload_Now() {
7971: var dest = "$newurl";
7972: if (dest != '') {
7973: window.location.href="$newurl";
7974: }
7975: }
1.1075.2.92 raeburn 7976: \$(document).ready(function () {
7977: window.alert('$msg');
7978: if ($disable_submit) {
1.1075.2.89 raeburn 7979: \$(".LC_hwk_submit").prop("disabled", true);
7980: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 7981: }
7982: setTimeout('LC_Offload_Now()', $timeout);
7983: });
7984: // ]]>
1.1075.2.89 raeburn 7985: </script>
7986: OFFLOAD
7987: }
7988: }
7989: }
7990: }
7991: }
7992: }
1.313 albertel 7993: }
1.306 albertel 7994: if (!defined($title)) {
7995: $title = 'The LearningOnline Network with CAPA';
7996: }
1.460 albertel 7997: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7998: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7999: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8000: if (!$args->{'frameset'}) {
8001: $result .= ' /';
8002: }
8003: $result .= '>'
1.1064 raeburn 8004: .$inhibitprint
1.414 albertel 8005: .$head_extra;
1.1075.2.108 raeburn 8006: my $clientmobile;
8007: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8008: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8009: } else {
8010: $clientmobile = $env{'browser.mobile'};
8011: }
8012: if ($clientmobile) {
1.1075.2.42 raeburn 8013: $result .= '
8014: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8015: <meta name="apple-mobile-web-app-capable" content="yes" />';
8016: }
1.1075.2.126 raeburn 8017: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8018: return $result.'</head>';
1.306 albertel 8019: }
8020:
8021: =pod
8022:
1.340 albertel 8023: =item * &font_settings()
8024:
8025: Returns neccessary <meta> to set the proper encoding
8026:
1.1075.2.56 raeburn 8027: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8028:
8029: =cut
8030:
8031: sub font_settings {
1.1075.2.56 raeburn 8032: my ($args) = @_;
1.340 albertel 8033: my $headerstring='';
1.1075.2.56 raeburn 8034: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8035: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 8036: $headerstring.=
1.1075.2.61 raeburn 8037: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8038: if (!$args->{'frameset'}) {
8039: $headerstring.= ' /';
8040: }
8041: $headerstring .= '>'."\n";
1.340 albertel 8042: }
8043: return $headerstring;
8044: }
8045:
1.341 albertel 8046: =pod
8047:
1.1064 raeburn 8048: =item * &print_suppression()
8049:
8050: In course context returns css which causes the body to be blank when media="print",
8051: if printout generation is unavailable for the current resource.
8052:
8053: This could be because:
8054:
8055: (a) printstartdate is in the future
8056:
8057: (b) printenddate is in the past
8058:
8059: (c) there is an active exam block with "printout"
8060: functionality blocked
8061:
8062: Users with pav, pfo or evb privileges are exempt.
8063:
8064: Inputs: none
8065:
8066: =cut
8067:
8068:
8069: sub print_suppression {
8070: my $noprint;
8071: if ($env{'request.course.id'}) {
8072: my $scope = $env{'request.course.id'};
8073: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8074: (&Apache::lonnet::allowed('pfo',$scope))) {
8075: return;
8076: }
8077: if ($env{'request.course.sec'} ne '') {
8078: $scope .= "/$env{'request.course.sec'}";
8079: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8080: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8081: return;
1.1064 raeburn 8082: }
8083: }
8084: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8085: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 8086: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8087: if ($blocked) {
8088: my $checkrole = "cm./$cdom/$cnum";
8089: if ($env{'request.course.sec'} ne '') {
8090: $checkrole .= "/$env{'request.course.sec'}";
8091: }
8092: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8093: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8094: $noprint = 1;
8095: }
8096: }
8097: unless ($noprint) {
8098: my $symb = &Apache::lonnet::symbread();
8099: if ($symb ne '') {
8100: my $navmap = Apache::lonnavmaps::navmap->new();
8101: if (ref($navmap)) {
8102: my $res = $navmap->getBySymb($symb);
8103: if (ref($res)) {
8104: if (!$res->resprintable()) {
8105: $noprint = 1;
8106: }
8107: }
8108: }
8109: }
8110: }
8111: if ($noprint) {
8112: return <<"ENDSTYLE";
8113: <style type="text/css" media="print">
8114: body { display:none }
8115: </style>
8116: ENDSTYLE
8117: }
8118: }
8119: return;
8120: }
8121:
8122: =pod
8123:
1.341 albertel 8124: =item * &xml_begin()
8125:
8126: Returns the needed doctype and <html>
8127:
8128: Inputs: none
8129:
8130: =cut
8131:
8132: sub xml_begin {
1.1075.2.61 raeburn 8133: my ($is_frameset) = @_;
1.341 albertel 8134: my $output='';
8135:
8136: if ($env{'browser.mathml'}) {
8137: $output='<?xml version="1.0"?>'
8138: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8139: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8140:
8141: # .'<!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">] >'
8142: .'<!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">'
8143: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8144: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8145: } elsif ($is_frameset) {
8146: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8147: '<html>'."\n";
1.341 albertel 8148: } else {
1.1075.2.61 raeburn 8149: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8150: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8151: }
8152: return $output;
8153: }
1.340 albertel 8154:
8155: =pod
8156:
1.306 albertel 8157: =item * &start_page()
8158:
8159: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8160:
1.648 raeburn 8161: Inputs:
8162:
8163: =over 4
8164:
8165: $title - optional title for the page
8166:
8167: $head_extra - optional extra HTML to incude inside the <head>
8168:
8169: $args - additional optional args supported are:
8170:
8171: =over 8
8172:
8173: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8174: arg on
1.814 bisitz 8175: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8176: add_entries -> additional attributes to add to the <body>
8177: domain -> force to color decorate a page for a
1.317 albertel 8178: specific domain
1.648 raeburn 8179: function -> force usage of a specific rolish color
1.317 albertel 8180: scheme
1.648 raeburn 8181: redirect -> see &headtag()
8182: bgcolor -> override the default page bg color
8183: js_ready -> return a string ready for being used in
1.317 albertel 8184: a javascript writeln
1.648 raeburn 8185: html_encode -> return a string ready for being used in
1.320 albertel 8186: a html attribute
1.648 raeburn 8187: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8188: $forcereg arg
1.648 raeburn 8189: frameset -> if true will start with a <frameset>
1.330 albertel 8190: rather than <body>
1.648 raeburn 8191: skip_phases -> hash ref of
1.338 albertel 8192: head -> skip the <html><head> generation
8193: body -> skip all <body> generation
1.1075.2.12 raeburn 8194: no_inline_link -> if true and in remote mode, don't show the
8195: 'Switch To Inline Menu' link
1.648 raeburn 8196: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8197: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8198: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8199: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8200: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8201: group -> includes the current group, if page is for a
8202: specific group
1.1075.2.133 raeburn 8203: use_absolute -> for request for external resource or syllabus, this
8204: will contain https://<hostname> if server uses
8205: https (as per hosts.tab), but request is for http
8206: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8207:
1.648 raeburn 8208: =back
1.460 albertel 8209:
1.648 raeburn 8210: =back
1.562 albertel 8211:
1.306 albertel 8212: =cut
8213:
8214: sub start_page {
1.309 albertel 8215: my ($title,$head_extra,$args) = @_;
1.318 albertel 8216: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8217:
1.315 albertel 8218: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8219: my ($result,@advtools);
1.964 droeschl 8220:
1.338 albertel 8221: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8222: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8223: }
8224:
8225: if (! exists($args->{'skip_phases'}{'body'}) ) {
8226: if ($args->{'frameset'}) {
8227: my $attr_string = &make_attr_string($args->{'force_register'},
8228: $args->{'add_entries'});
8229: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8230: } else {
8231: $result .=
8232: &bodytag($title,
8233: $args->{'function'}, $args->{'add_entries'},
8234: $args->{'only_body'}, $args->{'domain'},
8235: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8236: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8237: $args, \@advtools);
1.831 bisitz 8238: }
1.330 albertel 8239: }
1.338 albertel 8240:
1.315 albertel 8241: if ($args->{'js_ready'}) {
1.713 kaisler 8242: $result = &js_ready($result);
1.315 albertel 8243: }
1.320 albertel 8244: if ($args->{'html_encode'}) {
1.713 kaisler 8245: $result = &html_encode($result);
8246: }
8247:
1.813 bisitz 8248: # Preparation for new and consistent functionlist at top of screen
8249: # if ($args->{'functionlist'}) {
8250: # $result .= &build_functionlist();
8251: #}
8252:
1.964 droeschl 8253: # Don't add anything more if only_body wanted or in const space
8254: return $result if $args->{'only_body'}
8255: || $env{'request.state'} eq 'construct';
1.813 bisitz 8256:
8257: #Breadcrumbs
1.758 kaisler 8258: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8259: &Apache::lonhtmlcommon::clear_breadcrumbs();
8260: #if any br links exists, add them to the breadcrumbs
8261: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8262: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8263: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8264: }
8265: }
1.1075.2.19 raeburn 8266: # if @advtools array contains items add then to the breadcrumbs
8267: if (@advtools > 0) {
8268: &Apache::lonmenu::advtools_crumbs(@advtools);
8269: }
1.1075.2.123 raeburn 8270: my $menulink;
8271: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8272: if (exists($args->{'bread_crumbs_nomenu'})) {
8273: $menulink = 0;
8274: } else {
8275: undef($menulink);
8276: }
1.758 kaisler 8277: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8278: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8279: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8280: }else{
1.1075.2.123 raeburn 8281: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8282: }
1.1075.2.24 raeburn 8283: } elsif (($env{'environment.remote'} eq 'on') &&
8284: ($env{'form.inhibitmenu'} ne 'yes') &&
8285: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8286: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8287: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8288: }
1.315 albertel 8289: return $result;
1.306 albertel 8290: }
8291:
8292: sub end_page {
1.315 albertel 8293: my ($args) = @_;
8294: $env{'internal.end_page'}++;
1.330 albertel 8295: my $result;
1.335 albertel 8296: if ($args->{'discussion'}) {
8297: my ($target,$parser);
8298: if (ref($args->{'discussion'})) {
8299: ($target,$parser) =($args->{'discussion'}{'target'},
8300: $args->{'discussion'}{'parser'});
8301: }
8302: $result .= &Apache::lonxml::xmlend($target,$parser);
8303: }
1.330 albertel 8304: if ($args->{'frameset'}) {
8305: $result .= '</frameset>';
8306: } else {
1.635 raeburn 8307: $result .= &endbodytag($args);
1.330 albertel 8308: }
1.1075.2.6 raeburn 8309: unless ($args->{'notbody'}) {
8310: $result .= "\n</html>";
8311: }
1.330 albertel 8312:
1.315 albertel 8313: if ($args->{'js_ready'}) {
1.317 albertel 8314: $result = &js_ready($result);
1.315 albertel 8315: }
1.335 albertel 8316:
1.320 albertel 8317: if ($args->{'html_encode'}) {
8318: $result = &html_encode($result);
8319: }
1.335 albertel 8320:
1.315 albertel 8321: return $result;
8322: }
8323:
1.1034 www 8324: sub wishlist_window {
8325: return(<<'ENDWISHLIST');
1.1046 raeburn 8326: <script type="text/javascript">
1.1034 www 8327: // <![CDATA[
8328: // <!-- BEGIN LON-CAPA Internal
8329: function set_wishlistlink(title, path) {
8330: if (!title) {
8331: title = document.title;
8332: title = title.replace(/^LON-CAPA /,'');
8333: }
1.1075.2.65 raeburn 8334: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8335: title = title.replace("'","\\\'");
1.1034 www 8336: if (!path) {
8337: path = location.pathname;
8338: }
1.1075.2.65 raeburn 8339: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8340: path = path.replace("'","\\\'");
1.1034 www 8341: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8342: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8343: }
8344: // END LON-CAPA Internal -->
8345: // ]]>
8346: </script>
8347: ENDWISHLIST
8348: }
8349:
1.1030 www 8350: sub modal_window {
8351: return(<<'ENDMODAL');
1.1046 raeburn 8352: <script type="text/javascript">
1.1030 www 8353: // <![CDATA[
8354: // <!-- BEGIN LON-CAPA Internal
8355: var modalWindow = {
8356: parent:"body",
8357: windowId:null,
8358: content:null,
8359: width:null,
8360: height:null,
8361: close:function()
8362: {
8363: $(".LCmodal-window").remove();
8364: $(".LCmodal-overlay").remove();
8365: },
8366: open:function()
8367: {
8368: var modal = "";
8369: modal += "<div class=\"LCmodal-overlay\"></div>";
8370: 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;\">";
8371: modal += this.content;
8372: modal += "</div>";
8373:
8374: $(this.parent).append(modal);
8375:
8376: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8377: $(".LCclose-window").click(function(){modalWindow.close();});
8378: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8379: }
8380: };
1.1075.2.42 raeburn 8381: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8382: {
1.1075.2.119 raeburn 8383: source = source.replace(/'/g,"'");
1.1030 www 8384: modalWindow.windowId = "myModal";
8385: modalWindow.width = width;
8386: modalWindow.height = height;
1.1075.2.80 raeburn 8387: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8388: modalWindow.open();
1.1075.2.87 raeburn 8389: };
1.1030 www 8390: // END LON-CAPA Internal -->
8391: // ]]>
8392: </script>
8393: ENDMODAL
8394: }
8395:
8396: sub modal_link {
1.1075.2.42 raeburn 8397: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8398: unless ($width) { $width=480; }
8399: unless ($height) { $height=400; }
1.1031 www 8400: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8401: unless ($transparency) { $transparency='true'; }
8402:
1.1074 raeburn 8403: my $target_attr;
8404: if (defined($target)) {
8405: $target_attr = 'target="'.$target.'"';
8406: }
8407: return <<"ENDLINK";
1.1075.2.143 raeburn 8408: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 8409: ENDLINK
1.1030 www 8410: }
8411:
1.1032 www 8412: sub modal_adhoc_script {
8413: my ($funcname,$width,$height,$content)=@_;
8414: return (<<ENDADHOC);
1.1046 raeburn 8415: <script type="text/javascript">
1.1032 www 8416: // <![CDATA[
8417: var $funcname = function()
8418: {
8419: modalWindow.windowId = "myModal";
8420: modalWindow.width = $width;
8421: modalWindow.height = $height;
8422: modalWindow.content = '$content';
8423: modalWindow.open();
8424: };
8425: // ]]>
8426: </script>
8427: ENDADHOC
8428: }
8429:
1.1041 www 8430: sub modal_adhoc_inner {
8431: my ($funcname,$width,$height,$content)=@_;
8432: my $innerwidth=$width-20;
8433: $content=&js_ready(
1.1042 www 8434: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8435: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8436: $content.
1.1041 www 8437: &end_scrollbox().
1.1075.2.42 raeburn 8438: &end_page()
1.1041 www 8439: );
8440: return &modal_adhoc_script($funcname,$width,$height,$content);
8441: }
8442:
8443: sub modal_adhoc_window {
8444: my ($funcname,$width,$height,$content,$linktext)=@_;
8445: return &modal_adhoc_inner($funcname,$width,$height,$content).
8446: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8447: }
8448:
8449: sub modal_adhoc_launch {
8450: my ($funcname,$width,$height,$content)=@_;
8451: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8452: <script type="text/javascript">
8453: // <![CDATA[
8454: $funcname();
8455: // ]]>
8456: </script>
8457: ENDLAUNCH
8458: }
8459:
8460: sub modal_adhoc_close {
8461: return (<<ENDCLOSE);
8462: <script type="text/javascript">
8463: // <![CDATA[
8464: modalWindow.close();
8465: // ]]>
8466: </script>
8467: ENDCLOSE
8468: }
8469:
1.1038 www 8470: sub togglebox_script {
8471: return(<<ENDTOGGLE);
8472: <script type="text/javascript">
8473: // <![CDATA[
8474: function LCtoggleDisplay(id,hidetext,showtext) {
8475: link = document.getElementById(id + "link").childNodes[0];
8476: with (document.getElementById(id).style) {
8477: if (display == "none" ) {
8478: display = "inline";
8479: link.nodeValue = hidetext;
8480: } else {
8481: display = "none";
8482: link.nodeValue = showtext;
8483: }
8484: }
8485: }
8486: // ]]>
8487: </script>
8488: ENDTOGGLE
8489: }
8490:
1.1039 www 8491: sub start_togglebox {
8492: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8493: unless ($heading) { $heading=''; } else { $heading.=' '; }
8494: unless ($showtext) { $showtext=&mt('show'); }
8495: unless ($hidetext) { $hidetext=&mt('hide'); }
8496: unless ($headerbg) { $headerbg='#FFFFFF'; }
8497: return &start_data_table().
8498: &start_data_table_header_row().
8499: '<td bgcolor="'.$headerbg.'">'.$heading.
8500: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8501: $showtext.'\')">'.$showtext.'</a>]</td>'.
8502: &end_data_table_header_row().
8503: '<tr id="'.$id.'" style="display:none""><td>';
8504: }
8505:
8506: sub end_togglebox {
8507: return '</td></tr>'.&end_data_table();
8508: }
8509:
1.1041 www 8510: sub LCprogressbar_script {
1.1075.2.130 raeburn 8511: my ($id,$number_to_do)=@_;
8512: if ($number_to_do) {
8513: return(<<ENDPROGRESS);
1.1041 www 8514: <script type="text/javascript">
8515: // <![CDATA[
1.1045 www 8516: \$('#progressbar$id').progressbar({
1.1041 www 8517: value: 0,
8518: change: function(event, ui) {
8519: var newVal = \$(this).progressbar('option', 'value');
8520: \$('.pblabel', this).text(LCprogressTxt);
8521: }
8522: });
8523: // ]]>
8524: </script>
8525: ENDPROGRESS
1.1075.2.130 raeburn 8526: } else {
8527: return(<<ENDPROGRESS);
8528: <script type="text/javascript">
8529: // <![CDATA[
8530: \$('#progressbar$id').progressbar({
8531: value: false,
8532: create: function(event, ui) {
8533: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8534: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8535: }
8536: });
8537: // ]]>
8538: </script>
8539: ENDPROGRESS
8540: }
1.1041 www 8541: }
8542:
8543: sub LCprogressbarUpdate_script {
8544: return(<<ENDPROGRESSUPDATE);
8545: <style type="text/css">
8546: .ui-progressbar { position:relative; }
1.1075.2.130 raeburn 8547: .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 8548: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8549: </style>
8550: <script type="text/javascript">
8551: // <![CDATA[
1.1045 www 8552: var LCprogressTxt='---';
8553:
1.1075.2.130 raeburn 8554: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 8555: LCprogressTxt=progresstext;
1.1075.2.130 raeburn 8556: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
8557: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
8558: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
8559: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
8560: } else {
8561: \$('#progressbar'+id).progressbar('value',percent);
8562: }
1.1041 www 8563: }
8564: // ]]>
8565: </script>
8566: ENDPROGRESSUPDATE
8567: }
8568:
1.1042 www 8569: my $LClastpercent;
1.1045 www 8570: my $LCidcnt;
8571: my $LCcurrentid;
1.1042 www 8572:
1.1041 www 8573: sub LCprogressbar {
1.1075.2.130 raeburn 8574: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 8575: $LClastpercent=0;
1.1045 www 8576: $LCidcnt++;
8577: $LCcurrentid=$$.'_'.$LCidcnt;
1.1075.2.130 raeburn 8578: my ($starting,$content);
8579: if ($number_to_do) {
8580: $starting=&mt('Starting');
8581: $content=(<<ENDPROGBAR);
8582: $preamble
1.1045 www 8583: <div id="progressbar$LCcurrentid">
1.1041 www 8584: <span class="pblabel">$starting</span>
8585: </div>
8586: ENDPROGBAR
1.1075.2.130 raeburn 8587: } else {
8588: $starting=&mt('Loading...');
8589: $LClastpercent='false';
8590: $content=(<<ENDPROGBAR);
8591: $preamble
8592: <div id="progressbar$LCcurrentid">
8593: <div class="progress-label">$starting</div>
8594: </div>
8595: ENDPROGBAR
8596: }
8597: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 8598: }
8599:
8600: sub LCprogressbarUpdate {
1.1075.2.130 raeburn 8601: my ($r,$val,$text,$number_to_do)=@_;
8602: if ($number_to_do) {
8603: unless ($val) {
8604: if ($LClastpercent) {
8605: $val=$LClastpercent;
8606: } else {
8607: $val=0;
8608: }
8609: }
8610: if ($val<0) { $val=0; }
8611: if ($val>100) { $val=0; }
8612: $LClastpercent=$val;
8613: unless ($text) { $text=$val.'%'; }
8614: } else {
8615: $val = 'false';
1.1042 www 8616: }
1.1041 www 8617: $text=&js_ready($text);
1.1044 www 8618: &r_print($r,<<ENDUPDATE);
1.1041 www 8619: <script type="text/javascript">
8620: // <![CDATA[
1.1075.2.130 raeburn 8621: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 8622: // ]]>
8623: </script>
8624: ENDUPDATE
1.1035 www 8625: }
8626:
1.1042 www 8627: sub LCprogressbarClose {
8628: my ($r)=@_;
8629: $LClastpercent=0;
1.1044 www 8630: &r_print($r,<<ENDCLOSE);
1.1042 www 8631: <script type="text/javascript">
8632: // <![CDATA[
1.1045 www 8633: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8634: // ]]>
8635: </script>
8636: ENDCLOSE
1.1044 www 8637: }
8638:
8639: sub r_print {
8640: my ($r,$to_print)=@_;
8641: if ($r) {
8642: $r->print($to_print);
8643: $r->rflush();
8644: } else {
8645: print($to_print);
8646: }
1.1042 www 8647: }
8648:
1.320 albertel 8649: sub html_encode {
8650: my ($result) = @_;
8651:
1.322 albertel 8652: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8653:
8654: return $result;
8655: }
1.1044 www 8656:
1.317 albertel 8657: sub js_ready {
8658: my ($result) = @_;
8659:
1.323 albertel 8660: $result =~ s/[\n\r]/ /xmsg;
8661: $result =~ s/\\/\\\\/xmsg;
8662: $result =~ s/'/\\'/xmsg;
1.372 albertel 8663: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8664:
8665: return $result;
8666: }
8667:
1.315 albertel 8668: sub validate_page {
8669: if ( exists($env{'internal.start_page'})
1.316 albertel 8670: && $env{'internal.start_page'} > 1) {
8671: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8672: $env{'internal.start_page'}.' '.
1.316 albertel 8673: $ENV{'request.filename'});
1.315 albertel 8674: }
8675: if ( exists($env{'internal.end_page'})
1.316 albertel 8676: && $env{'internal.end_page'} > 1) {
8677: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8678: $env{'internal.end_page'}.' '.
1.316 albertel 8679: $env{'request.filename'});
1.315 albertel 8680: }
8681: if ( exists($env{'internal.start_page'})
8682: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8683: &Apache::lonnet::logthis('start_page called without end_page '.
8684: $env{'request.filename'});
1.315 albertel 8685: }
8686: if ( ! exists($env{'internal.start_page'})
8687: && exists($env{'internal.end_page'})) {
1.316 albertel 8688: &Apache::lonnet::logthis('end_page called without start_page'.
8689: $env{'request.filename'});
1.315 albertel 8690: }
1.306 albertel 8691: }
1.315 albertel 8692:
1.996 www 8693:
8694: sub start_scrollbox {
1.1075.2.56 raeburn 8695: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8696: unless ($outerwidth) { $outerwidth='520px'; }
8697: unless ($width) { $width='500px'; }
8698: unless ($height) { $height='200px'; }
1.1075 raeburn 8699: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8700: if ($id ne '') {
1.1075.2.42 raeburn 8701: $table_id = ' id="table_'.$id.'"';
8702: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8703: }
1.1075 raeburn 8704: if ($bgcolor ne '') {
8705: $tdcol = "background-color: $bgcolor;";
8706: }
1.1075.2.42 raeburn 8707: my $nicescroll_js;
8708: if ($env{'browser.mobile'}) {
8709: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8710: }
1.1075 raeburn 8711: return <<"END";
1.1075.2.42 raeburn 8712: $nicescroll_js
8713:
8714: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8715: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8716: END
1.996 www 8717: }
8718:
8719: sub end_scrollbox {
1.1036 www 8720: return '</div></td></tr></table>';
1.996 www 8721: }
8722:
1.1075.2.42 raeburn 8723: sub nicescroll_javascript {
8724: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8725: my %options;
8726: if (ref($cursor) eq 'HASH') {
8727: %options = %{$cursor};
8728: }
8729: unless ($options{'railalign'} =~ /^left|right$/) {
8730: $options{'railalign'} = 'left';
8731: }
8732: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8733: my $function = &get_users_function();
8734: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8735: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8736: $options{'cursorcolor'} = '#00F';
8737: }
8738: }
8739: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8740: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8741: $options{'cursoropacity'}='1.0';
8742: }
8743: } else {
8744: $options{'cursoropacity'}='1.0';
8745: }
8746: if ($options{'cursorfixedheight'} eq 'none') {
8747: delete($options{'cursorfixedheight'});
8748: } else {
8749: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8750: }
8751: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8752: delete($options{'railoffset'});
8753: }
8754: my @niceoptions;
8755: while (my($key,$value) = each(%options)) {
8756: if ($value =~ /^\{.+\}$/) {
8757: push(@niceoptions,$key.':'.$value);
8758: } else {
8759: push(@niceoptions,$key.':"'.$value.'"');
8760: }
8761: }
8762: my $nicescroll_js = '
8763: $(document).ready(
8764: function() {
8765: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8766: }
8767: );
8768: ';
8769: if ($framecheck) {
8770: $nicescroll_js .= '
8771: function expand_div(caller) {
8772: if (top === self) {
8773: document.getElementById("'.$id.'").style.width = "auto";
8774: document.getElementById("'.$id.'").style.height = "auto";
8775: } else {
8776: try {
8777: if (parent.frames) {
8778: if (parent.frames.length > 1) {
8779: var framesrc = parent.frames[1].location.href;
8780: var currsrc = framesrc.replace(/\#.*$/,"");
8781: if ((caller == "search") || (currsrc == "'.$location.'")) {
8782: document.getElementById("'.$id.'").style.width = "auto";
8783: document.getElementById("'.$id.'").style.height = "auto";
8784: }
8785: }
8786: }
8787: } catch (e) {
8788: return;
8789: }
8790: }
8791: return;
8792: }
8793: ';
8794: }
8795: if ($needjsready) {
8796: $nicescroll_js = '
8797: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8798: } else {
8799: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8800: }
8801: return $nicescroll_js;
8802: }
8803:
1.318 albertel 8804: sub simple_error_page {
1.1075.2.49 raeburn 8805: my ($r,$title,$msg,$args) = @_;
8806: if (ref($args) eq 'HASH') {
8807: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8808: } else {
8809: $msg = &mt($msg);
8810: }
8811:
1.318 albertel 8812: my $page =
8813: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8814: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8815: &Apache::loncommon::end_page();
8816: if (ref($r)) {
8817: $r->print($page);
1.327 albertel 8818: return;
1.318 albertel 8819: }
8820: return $page;
8821: }
1.347 albertel 8822:
8823: {
1.610 albertel 8824: my @row_count;
1.961 onken 8825:
8826: sub start_data_table_count {
8827: unshift(@row_count, 0);
8828: return;
8829: }
8830:
8831: sub end_data_table_count {
8832: shift(@row_count);
8833: return;
8834: }
8835:
1.347 albertel 8836: sub start_data_table {
1.1018 raeburn 8837: my ($add_class,$id) = @_;
1.422 albertel 8838: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8839: my $table_id;
8840: if (defined($id)) {
8841: $table_id = ' id="'.$id.'"';
8842: }
1.961 onken 8843: &start_data_table_count();
1.1018 raeburn 8844: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8845: }
8846:
8847: sub end_data_table {
1.961 onken 8848: &end_data_table_count();
1.389 albertel 8849: return '</table>'."\n";;
1.347 albertel 8850: }
8851:
8852: sub start_data_table_row {
1.974 wenzelju 8853: my ($add_class, $id) = @_;
1.610 albertel 8854: $row_count[0]++;
8855: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8856: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8857: $id = (' id="'.$id.'"') unless ($id eq '');
8858: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8859: }
1.471 banghart 8860:
8861: sub continue_data_table_row {
1.974 wenzelju 8862: my ($add_class, $id) = @_;
1.610 albertel 8863: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8864: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8865: $id = (' id="'.$id.'"') unless ($id eq '');
8866: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8867: }
1.347 albertel 8868:
8869: sub end_data_table_row {
1.389 albertel 8870: return '</tr>'."\n";;
1.347 albertel 8871: }
1.367 www 8872:
1.421 albertel 8873: sub start_data_table_empty_row {
1.707 bisitz 8874: # $row_count[0]++;
1.421 albertel 8875: return '<tr class="LC_empty_row" >'."\n";;
8876: }
8877:
8878: sub end_data_table_empty_row {
8879: return '</tr>'."\n";;
8880: }
8881:
1.367 www 8882: sub start_data_table_header_row {
1.389 albertel 8883: return '<tr class="LC_header_row">'."\n";;
1.367 www 8884: }
8885:
8886: sub end_data_table_header_row {
1.389 albertel 8887: return '</tr>'."\n";;
1.367 www 8888: }
1.890 droeschl 8889:
8890: sub data_table_caption {
8891: my $caption = shift;
8892: return "<caption class=\"LC_caption\">$caption</caption>";
8893: }
1.347 albertel 8894: }
8895:
1.548 albertel 8896: =pod
8897:
8898: =item * &inhibit_menu_check($arg)
8899:
8900: Checks for a inhibitmenu state and generates output to preserve it
8901:
8902: Inputs: $arg - can be any of
8903: - undef - in which case the return value is a string
8904: to add into arguments list of a uri
8905: - 'input' - in which case the return value is a HTML
8906: <form> <input> field of type hidden to
8907: preserve the value
8908: - a url - in which case the return value is the url with
8909: the neccesary cgi args added to preserve the
8910: inhibitmenu state
8911: - a ref to a url - no return value, but the string is
8912: updated to include the neccessary cgi
8913: args to preserve the inhibitmenu state
8914:
8915: =cut
8916:
8917: sub inhibit_menu_check {
8918: my ($arg) = @_;
8919: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8920: if ($arg eq 'input') {
8921: if ($env{'form.inhibitmenu'}) {
8922: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8923: } else {
8924: return
8925: }
8926: }
8927: if ($env{'form.inhibitmenu'}) {
8928: if (ref($arg)) {
8929: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8930: } elsif ($arg eq '') {
8931: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8932: } else {
8933: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8934: }
8935: }
8936: if (!ref($arg)) {
8937: return $arg;
8938: }
8939: }
8940:
1.251 albertel 8941: ###############################################
1.182 matthew 8942:
8943: =pod
8944:
1.549 albertel 8945: =back
8946:
8947: =head1 User Information Routines
8948:
8949: =over 4
8950:
1.405 albertel 8951: =item * &get_users_function()
1.182 matthew 8952:
8953: Used by &bodytag to determine the current users primary role.
8954: Returns either 'student','coordinator','admin', or 'author'.
8955:
8956: =cut
8957:
8958: ###############################################
8959: sub get_users_function {
1.815 tempelho 8960: my $function = 'norole';
1.818 tempelho 8961: if ($env{'request.role'}=~/^(st)/) {
8962: $function='student';
8963: }
1.907 raeburn 8964: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8965: $function='coordinator';
8966: }
1.258 albertel 8967: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8968: $function='admin';
8969: }
1.826 bisitz 8970: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8971: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8972: $function='author';
8973: }
8974: return $function;
1.54 www 8975: }
1.99 www 8976:
8977: ###############################################
8978:
1.233 raeburn 8979: =pod
8980:
1.821 raeburn 8981: =item * &show_course()
8982:
8983: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8984: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8985:
8986: Inputs:
8987: None
8988:
8989: Outputs:
8990: Scalar: 1 if 'Course' to be used, 0 otherwise.
8991:
8992: =cut
8993:
8994: ###############################################
8995: sub show_course {
8996: my $course = !$env{'user.adv'};
8997: if (!$env{'user.adv'}) {
8998: foreach my $env (keys(%env)) {
8999: next if ($env !~ m/^user\.priv\./);
9000: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9001: $course = 0;
9002: last;
9003: }
9004: }
9005: }
9006: return $course;
9007: }
9008:
9009: ###############################################
9010:
9011: =pod
9012:
1.542 raeburn 9013: =item * &check_user_status()
1.274 raeburn 9014:
9015: Determines current status of supplied role for a
9016: specific user. Roles can be active, previous or future.
9017:
9018: Inputs:
9019: user's domain, user's username, course's domain,
1.375 raeburn 9020: course's number, optional section ID.
1.274 raeburn 9021:
9022: Outputs:
9023: role status: active, previous or future.
9024:
9025: =cut
9026:
9027: sub check_user_status {
1.412 raeburn 9028: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9029: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 9030: my @uroles = keys(%userinfo);
1.274 raeburn 9031: my $srchstr;
9032: my $active_chk = 'none';
1.412 raeburn 9033: my $now = time;
1.274 raeburn 9034: if (@uroles > 0) {
1.908 raeburn 9035: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9036: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9037: } else {
1.412 raeburn 9038: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9039: }
9040: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9041: my $role_end = 0;
9042: my $role_start = 0;
9043: $active_chk = 'active';
1.412 raeburn 9044: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9045: $role_end = $1;
9046: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9047: $role_start = $1;
1.274 raeburn 9048: }
9049: }
9050: if ($role_start > 0) {
1.412 raeburn 9051: if ($now < $role_start) {
1.274 raeburn 9052: $active_chk = 'future';
9053: }
9054: }
9055: if ($role_end > 0) {
1.412 raeburn 9056: if ($now > $role_end) {
1.274 raeburn 9057: $active_chk = 'previous';
9058: }
9059: }
9060: }
9061: }
9062: return $active_chk;
9063: }
9064:
9065: ###############################################
9066:
9067: =pod
9068:
1.405 albertel 9069: =item * &get_sections()
1.233 raeburn 9070:
9071: Determines all the sections for a course including
9072: sections with students and sections containing other roles.
1.419 raeburn 9073: Incoming parameters:
9074:
9075: 1. domain
9076: 2. course number
9077: 3. reference to array containing roles for which sections should
9078: be gathered (optional).
9079: 4. reference to array containing status types for which sections
9080: should be gathered (optional).
9081:
9082: If the third argument is undefined, sections are gathered for any role.
9083: If the fourth argument is undefined, sections are gathered for any status.
9084: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9085:
1.374 raeburn 9086: Returns section hash (keys are section IDs, values are
9087: number of users in each section), subject to the
1.419 raeburn 9088: optional roles filter, optional status filter
1.233 raeburn 9089:
9090: =cut
9091:
9092: ###############################################
9093: sub get_sections {
1.419 raeburn 9094: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9095: if (!defined($cdom) || !defined($cnum)) {
9096: my $cid = $env{'request.course.id'};
9097:
9098: return if (!defined($cid));
9099:
9100: $cdom = $env{'course.'.$cid.'.domain'};
9101: $cnum = $env{'course.'.$cid.'.num'};
9102: }
9103:
9104: my %sectioncount;
1.419 raeburn 9105: my $now = time;
1.240 albertel 9106:
1.1075.2.33 raeburn 9107: my $check_students = 1;
9108: my $only_students = 0;
9109: if (ref($possible_roles) eq 'ARRAY') {
9110: if (grep(/^st$/,@{$possible_roles})) {
9111: if (@{$possible_roles} == 1) {
9112: $only_students = 1;
9113: }
9114: } else {
9115: $check_students = 0;
9116: }
9117: }
9118:
9119: if ($check_students) {
1.276 albertel 9120: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9121: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9122: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9123: my $start_index = &Apache::loncoursedata::CL_START();
9124: my $end_index = &Apache::loncoursedata::CL_END();
9125: my $status;
1.366 albertel 9126: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9127: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9128: $data->[$status_index],
9129: $data->[$start_index],
9130: $data->[$end_index]);
9131: if ($stu_status eq 'Active') {
9132: $status = 'active';
9133: } elsif ($end < $now) {
9134: $status = 'previous';
9135: } elsif ($start > $now) {
9136: $status = 'future';
9137: }
9138: if ($section ne '-1' && $section !~ /^\s*$/) {
9139: if ((!defined($possible_status)) || (($status ne '') &&
9140: (grep/^\Q$status\E$/,@{$possible_status}))) {
9141: $sectioncount{$section}++;
9142: }
1.240 albertel 9143: }
9144: }
9145: }
1.1075.2.33 raeburn 9146: if ($only_students) {
9147: return %sectioncount;
9148: }
1.240 albertel 9149: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9150: foreach my $user (sort(keys(%courseroles))) {
9151: if ($user !~ /^(\w{2})/) { next; }
9152: my ($role) = ($user =~ /^(\w{2})/);
9153: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9154: my ($section,$status);
1.240 albertel 9155: if ($role eq 'cr' &&
9156: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9157: $section=$1;
9158: }
9159: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9160: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9161: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9162: if ($end == -1 && $start == -1) {
9163: next; #deleted role
9164: }
9165: if (!defined($possible_status)) {
9166: $sectioncount{$section}++;
9167: } else {
9168: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9169: $status = 'active';
9170: } elsif ($end < $now) {
9171: $status = 'future';
9172: } elsif ($start > $now) {
9173: $status = 'previous';
9174: }
9175: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9176: $sectioncount{$section}++;
9177: }
9178: }
1.233 raeburn 9179: }
1.366 albertel 9180: return %sectioncount;
1.233 raeburn 9181: }
9182:
1.274 raeburn 9183: ###############################################
1.294 raeburn 9184:
9185: =pod
1.405 albertel 9186:
9187: =item * &get_course_users()
9188:
1.275 raeburn 9189: Retrieves usernames:domains for users in the specified course
9190: with specific role(s), and access status.
9191:
9192: Incoming parameters:
1.277 albertel 9193: 1. course domain
9194: 2. course number
9195: 3. access status: users must have - either active,
1.275 raeburn 9196: previous, future, or all.
1.277 albertel 9197: 4. reference to array of permissible roles
1.288 raeburn 9198: 5. reference to array of section restrictions (optional)
9199: 6. reference to results object (hash of hashes).
9200: 7. reference to optional userdata hash
1.609 raeburn 9201: 8. reference to optional statushash
1.630 raeburn 9202: 9. flag if privileged users (except those set to unhide in
9203: course settings) should be excluded
1.609 raeburn 9204: Keys of top level results hash are roles.
1.275 raeburn 9205: Keys of inner hashes are username:domain, with
9206: values set to access type.
1.288 raeburn 9207: Optional userdata hash returns an array with arguments in the
9208: same order as loncoursedata::get_classlist() for student data.
9209:
1.609 raeburn 9210: Optional statushash returns
9211:
1.288 raeburn 9212: Entries for end, start, section and status are blank because
9213: of the possibility of multiple values for non-student roles.
9214:
1.275 raeburn 9215: =cut
1.405 albertel 9216:
1.275 raeburn 9217: ###############################################
1.405 albertel 9218:
1.275 raeburn 9219: sub get_course_users {
1.630 raeburn 9220: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9221: my %idx = ();
1.419 raeburn 9222: my %seclists;
1.288 raeburn 9223:
9224: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9225: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9226: $idx{end} = &Apache::loncoursedata::CL_END();
9227: $idx{start} = &Apache::loncoursedata::CL_START();
9228: $idx{id} = &Apache::loncoursedata::CL_ID();
9229: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9230: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9231: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9232:
1.290 albertel 9233: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9234: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9235: my $now = time;
1.277 albertel 9236: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9237: my $match = 0;
1.412 raeburn 9238: my $secmatch = 0;
1.419 raeburn 9239: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9240: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9241: if ($section eq '') {
9242: $section = 'none';
9243: }
1.291 albertel 9244: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9245: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9246: $secmatch = 1;
9247: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9248: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9249: $secmatch = 1;
9250: }
9251: } else {
1.419 raeburn 9252: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9253: $secmatch = 1;
9254: }
1.290 albertel 9255: }
1.412 raeburn 9256: if (!$secmatch) {
9257: next;
9258: }
1.419 raeburn 9259: }
1.275 raeburn 9260: if (defined($$types{'active'})) {
1.288 raeburn 9261: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9262: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9263: $match = 1;
1.275 raeburn 9264: }
9265: }
9266: if (defined($$types{'previous'})) {
1.609 raeburn 9267: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9268: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9269: $match = 1;
1.275 raeburn 9270: }
9271: }
9272: if (defined($$types{'future'})) {
1.609 raeburn 9273: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9274: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9275: $match = 1;
1.275 raeburn 9276: }
9277: }
1.609 raeburn 9278: if ($match) {
9279: push(@{$seclists{$student}},$section);
9280: if (ref($userdata) eq 'HASH') {
9281: $$userdata{$student} = $$classlist{$student};
9282: }
9283: if (ref($statushash) eq 'HASH') {
9284: $statushash->{$student}{'st'}{$section} = $status;
9285: }
1.288 raeburn 9286: }
1.275 raeburn 9287: }
9288: }
1.412 raeburn 9289: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9290: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9291: my $now = time;
1.609 raeburn 9292: my %displaystatus = ( previous => 'Expired',
9293: active => 'Active',
9294: future => 'Future',
9295: );
1.1075.2.36 raeburn 9296: my (%nothide,@possdoms);
1.630 raeburn 9297: if ($hidepriv) {
9298: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9299: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9300: if ($user !~ /:/) {
9301: $nothide{join(':',split(/[\@]/,$user))}=1;
9302: } else {
9303: $nothide{$user} = 1;
9304: }
9305: }
1.1075.2.36 raeburn 9306: my @possdoms = ($cdom);
9307: if ($coursehash{'checkforpriv'}) {
9308: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9309: }
1.630 raeburn 9310: }
1.439 raeburn 9311: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9312: my $match = 0;
1.412 raeburn 9313: my $secmatch = 0;
1.439 raeburn 9314: my $status;
1.412 raeburn 9315: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9316: $user =~ s/:$//;
1.439 raeburn 9317: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9318: if ($end == -1 || $start == -1) {
9319: next;
9320: }
9321: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9322: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9323: my ($uname,$udom) = split(/:/,$user);
9324: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9325: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9326: $secmatch = 1;
9327: } elsif ($usec eq '') {
1.420 albertel 9328: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9329: $secmatch = 1;
9330: }
9331: } else {
9332: if (grep(/^\Q$usec\E$/,@{$sections})) {
9333: $secmatch = 1;
9334: }
9335: }
9336: if (!$secmatch) {
9337: next;
9338: }
1.288 raeburn 9339: }
1.419 raeburn 9340: if ($usec eq '') {
9341: $usec = 'none';
9342: }
1.275 raeburn 9343: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9344: if ($hidepriv) {
1.1075.2.36 raeburn 9345: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9346: (!$nothide{$uname.':'.$udom})) {
9347: next;
9348: }
9349: }
1.503 raeburn 9350: if ($end > 0 && $end < $now) {
1.439 raeburn 9351: $status = 'previous';
9352: } elsif ($start > $now) {
9353: $status = 'future';
9354: } else {
9355: $status = 'active';
9356: }
1.277 albertel 9357: foreach my $type (keys(%{$types})) {
1.275 raeburn 9358: if ($status eq $type) {
1.420 albertel 9359: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9360: push(@{$$users{$role}{$user}},$type);
9361: }
1.288 raeburn 9362: $match = 1;
9363: }
9364: }
1.419 raeburn 9365: if (($match) && (ref($userdata) eq 'HASH')) {
9366: if (!exists($$userdata{$uname.':'.$udom})) {
9367: &get_user_info($udom,$uname,\%idx,$userdata);
9368: }
1.420 albertel 9369: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9370: push(@{$seclists{$uname.':'.$udom}},$usec);
9371: }
1.609 raeburn 9372: if (ref($statushash) eq 'HASH') {
9373: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9374: }
1.275 raeburn 9375: }
9376: }
9377: }
9378: }
1.290 albertel 9379: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9380: if ((defined($cdom)) && (defined($cnum))) {
9381: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9382: if ( defined($csettings{'internal.courseowner'}) ) {
9383: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9384: next if ($owner eq '');
9385: my ($ownername,$ownerdom);
9386: if ($owner =~ /^([^:]+):([^:]+)$/) {
9387: $ownername = $1;
9388: $ownerdom = $2;
9389: } else {
9390: $ownername = $owner;
9391: $ownerdom = $cdom;
9392: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9393: }
9394: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9395: if (defined($userdata) &&
1.609 raeburn 9396: !exists($$userdata{$owner})) {
9397: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9398: if (!grep(/^none$/,@{$seclists{$owner}})) {
9399: push(@{$seclists{$owner}},'none');
9400: }
9401: if (ref($statushash) eq 'HASH') {
9402: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9403: }
1.290 albertel 9404: }
1.279 raeburn 9405: }
9406: }
9407: }
1.419 raeburn 9408: foreach my $user (keys(%seclists)) {
9409: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9410: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9411: }
1.275 raeburn 9412: }
9413: return;
9414: }
9415:
1.288 raeburn 9416: sub get_user_info {
9417: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9418: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9419: &plainname($uname,$udom,'lastname');
1.291 albertel 9420: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9421: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9422: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9423: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9424: return;
9425: }
1.275 raeburn 9426:
1.472 raeburn 9427: ###############################################
9428:
9429: =pod
9430:
9431: =item * &get_user_quota()
9432:
1.1075.2.41 raeburn 9433: Retrieves quota assigned for storage of user files.
9434: Default is to report quota for portfolio files.
1.472 raeburn 9435:
9436: Incoming parameters:
9437: 1. user's username
9438: 2. user's domain
1.1075.2.41 raeburn 9439: 3. quota name - portfolio, author, or course
9440: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9441: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9442: course
1.472 raeburn 9443:
9444: Returns:
1.1075.2.58 raeburn 9445: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9446: 2. (Optional) Type of setting: custom or default
9447: (individually assigned or default for user's
9448: institutional status).
9449: 3. (Optional) - User's institutional status (e.g., faculty, staff
9450: or student - types as defined in localenroll::inst_usertypes
9451: for user's domain, which determines default quota for user.
9452: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9453:
9454: If a value has been stored in the user's environment,
1.536 raeburn 9455: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9456: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9457:
9458: =cut
9459:
9460: ###############################################
9461:
9462:
9463: sub get_user_quota {
1.1075.2.42 raeburn 9464: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9465: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9466: if (!defined($udom)) {
9467: $udom = $env{'user.domain'};
9468: }
9469: if (!defined($uname)) {
9470: $uname = $env{'user.name'};
9471: }
9472: if (($udom eq '' || $uname eq '') ||
9473: ($udom eq 'public') && ($uname eq 'public')) {
9474: $quota = 0;
1.536 raeburn 9475: $quotatype = 'default';
9476: $defquota = 0;
1.472 raeburn 9477: } else {
1.536 raeburn 9478: my $inststatus;
1.1075.2.41 raeburn 9479: if ($quotaname eq 'course') {
9480: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9481: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9482: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9483: } else {
9484: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9485: $quota = $cenv{'internal.uploadquota'};
9486: }
1.536 raeburn 9487: } else {
1.1075.2.41 raeburn 9488: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9489: if ($quotaname eq 'author') {
9490: $quota = $env{'environment.authorquota'};
9491: } else {
9492: $quota = $env{'environment.portfolioquota'};
9493: }
9494: $inststatus = $env{'environment.inststatus'};
9495: } else {
9496: my %userenv =
9497: &Apache::lonnet::get('environment',['portfolioquota',
9498: 'authorquota','inststatus'],$udom,$uname);
9499: my ($tmp) = keys(%userenv);
9500: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9501: if ($quotaname eq 'author') {
9502: $quota = $userenv{'authorquota'};
9503: } else {
9504: $quota = $userenv{'portfolioquota'};
9505: }
9506: $inststatus = $userenv{'inststatus'};
9507: } else {
9508: undef(%userenv);
9509: }
9510: }
9511: }
9512: if ($quota eq '' || wantarray) {
9513: if ($quotaname eq 'course') {
9514: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9515: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9516: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9517: $defquota = $domdefs{$crstype.'quota'};
9518: }
9519: if ($defquota eq '') {
9520: $defquota = 500;
9521: }
1.1075.2.41 raeburn 9522: } else {
9523: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9524: }
9525: if ($quota eq '') {
9526: $quota = $defquota;
9527: $quotatype = 'default';
9528: } else {
9529: $quotatype = 'custom';
9530: }
1.472 raeburn 9531: }
9532: }
1.536 raeburn 9533: if (wantarray) {
9534: return ($quota,$quotatype,$settingstatus,$defquota);
9535: } else {
9536: return $quota;
9537: }
1.472 raeburn 9538: }
9539:
9540: ###############################################
9541:
9542: =pod
9543:
9544: =item * &default_quota()
9545:
1.536 raeburn 9546: Retrieves default quota assigned for storage of user portfolio files,
9547: given an (optional) user's institutional status.
1.472 raeburn 9548:
9549: Incoming parameters:
1.1075.2.42 raeburn 9550:
1.472 raeburn 9551: 1. domain
1.536 raeburn 9552: 2. (Optional) institutional status(es). This is a : separated list of
9553: status types (e.g., faculty, staff, student etc.)
9554: which apply to the user for whom the default is being retrieved.
9555: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9556: default quota will be returned.
9557: 3. quota name - portfolio, author, or course
9558: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9559:
9560: Returns:
1.1075.2.42 raeburn 9561:
1.1075.2.58 raeburn 9562: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9563: 2. (Optional) institutional type which determined the value of the
9564: default quota.
1.472 raeburn 9565:
9566: If a value has been stored in the domain's configuration db,
9567: it will return that, otherwise it returns 20 (for backwards
9568: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9569: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9570:
1.536 raeburn 9571: If the user's status includes multiple types (e.g., staff and student),
9572: the largest default quota which applies to the user determines the
9573: default quota returned.
9574:
1.472 raeburn 9575: =cut
9576:
9577: ###############################################
9578:
9579:
9580: sub default_quota {
1.1075.2.41 raeburn 9581: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9582: my ($defquota,$settingstatus);
9583: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9584: ['quotas'],$udom);
1.1075.2.41 raeburn 9585: my $key = 'defaultquota';
9586: if ($quotaname eq 'author') {
9587: $key = 'authorquota';
9588: }
1.622 raeburn 9589: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9590: if ($inststatus ne '') {
1.765 raeburn 9591: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9592: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9593: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9594: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9595: if ($defquota eq '') {
1.1075.2.41 raeburn 9596: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9597: $settingstatus = $item;
1.1075.2.41 raeburn 9598: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9599: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9600: $settingstatus = $item;
9601: }
9602: }
1.1075.2.41 raeburn 9603: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9604: if ($quotahash{'quotas'}{$item} ne '') {
9605: if ($defquota eq '') {
9606: $defquota = $quotahash{'quotas'}{$item};
9607: $settingstatus = $item;
9608: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9609: $defquota = $quotahash{'quotas'}{$item};
9610: $settingstatus = $item;
9611: }
1.536 raeburn 9612: }
9613: }
9614: }
9615: }
9616: if ($defquota eq '') {
1.1075.2.41 raeburn 9617: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9618: $defquota = $quotahash{'quotas'}{$key}{'default'};
9619: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9620: $defquota = $quotahash{'quotas'}{'default'};
9621: }
1.536 raeburn 9622: $settingstatus = 'default';
1.1075.2.42 raeburn 9623: if ($defquota eq '') {
9624: if ($quotaname eq 'author') {
9625: $defquota = 500;
9626: }
9627: }
1.536 raeburn 9628: }
9629: } else {
9630: $settingstatus = 'default';
1.1075.2.41 raeburn 9631: if ($quotaname eq 'author') {
9632: $defquota = 500;
9633: } else {
9634: $defquota = 20;
9635: }
1.536 raeburn 9636: }
9637: if (wantarray) {
9638: return ($defquota,$settingstatus);
1.472 raeburn 9639: } else {
1.536 raeburn 9640: return $defquota;
1.472 raeburn 9641: }
9642: }
9643:
1.1075.2.41 raeburn 9644: ###############################################
9645:
9646: =pod
9647:
1.1075.2.42 raeburn 9648: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9649:
9650: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9651: of existing file within authoring space will cause quota for the authoring
9652: space to be exceeded.
9653:
9654: Same, if upload of a file directly to a course/community via Course Editor
9655: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9656:
1.1075.2.61 raeburn 9657: Inputs: 7
1.1075.2.42 raeburn 9658: 1. username or coursenum
1.1075.2.41 raeburn 9659: 2. domain
1.1075.2.42 raeburn 9660: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9661: 4. filename of file for which action is being requested
9662: 5. filesize (kB) of file
9663: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9664: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9665:
9666: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9667: otherwise return null.
9668:
1.1075.2.42 raeburn 9669: =back
9670:
1.1075.2.41 raeburn 9671: =cut
9672:
1.1075.2.42 raeburn 9673: sub excess_filesize_warning {
1.1075.2.59 raeburn 9674: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9675: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9676: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9677: if ($context eq 'author') {
9678: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9679: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9680: } else {
9681: foreach my $subdir ('docs','supplemental') {
9682: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9683: }
9684: }
1.1075.2.41 raeburn 9685: $disk_quota = int($disk_quota * 1000);
9686: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9687: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9688: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9689: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9690: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9691: $disk_quota,$current_disk_usage).
9692: '</p>';
9693: }
9694: return;
9695: }
9696:
9697: ###############################################
9698:
9699:
1.384 raeburn 9700: sub get_secgrprole_info {
9701: my ($cdom,$cnum,$needroles,$type) = @_;
9702: my %sections_count = &get_sections($cdom,$cnum);
9703: my @sections = (sort {$a <=> $b} keys(%sections_count));
9704: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9705: my @groups = sort(keys(%curr_groups));
9706: my $allroles = [];
9707: my $rolehash;
9708: my $accesshash = {
9709: active => 'Currently has access',
9710: future => 'Will have future access',
9711: previous => 'Previously had access',
9712: };
9713: if ($needroles) {
9714: $rolehash = {'all' => 'all'};
1.385 albertel 9715: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9716: if (&Apache::lonnet::error(%user_roles)) {
9717: undef(%user_roles);
9718: }
9719: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9720: my ($role)=split(/\:/,$item,2);
9721: if ($role eq 'cr') { next; }
9722: if ($role =~ /^cr/) {
9723: $$rolehash{$role} = (split('/',$role))[3];
9724: } else {
9725: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9726: }
9727: }
9728: foreach my $key (sort(keys(%{$rolehash}))) {
9729: push(@{$allroles},$key);
9730: }
9731: push (@{$allroles},'st');
9732: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9733: }
9734: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9735: }
9736:
1.555 raeburn 9737: sub user_picker {
1.1075.2.127 raeburn 9738: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 9739: my $currdom = $dom;
1.1075.2.114 raeburn 9740: my @alldoms = &Apache::lonnet::all_domains();
9741: if (@alldoms == 1) {
9742: my %domsrch = &Apache::lonnet::get_dom('configuration',
9743: ['directorysrch'],$alldoms[0]);
9744: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9745: my $showdom = $domdesc;
9746: if ($showdom eq '') {
9747: $showdom = $dom;
9748: }
9749: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9750: if ((!$domsrch{'directorysrch'}{'available'}) &&
9751: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9752: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9753: }
9754: }
9755: }
1.555 raeburn 9756: my %curr_selected = (
9757: srchin => 'dom',
1.580 raeburn 9758: srchby => 'lastname',
1.555 raeburn 9759: );
9760: my $srchterm;
1.625 raeburn 9761: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9762: if ($srch->{'srchby'} ne '') {
9763: $curr_selected{'srchby'} = $srch->{'srchby'};
9764: }
9765: if ($srch->{'srchin'} ne '') {
9766: $curr_selected{'srchin'} = $srch->{'srchin'};
9767: }
9768: if ($srch->{'srchtype'} ne '') {
9769: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9770: }
9771: if ($srch->{'srchdomain'} ne '') {
9772: $currdom = $srch->{'srchdomain'};
9773: }
9774: $srchterm = $srch->{'srchterm'};
9775: }
1.1075.2.98 raeburn 9776: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9777: 'usr' => 'Search criteria',
1.563 raeburn 9778: 'doma' => 'Domain/institution to search',
1.558 albertel 9779: 'uname' => 'username',
9780: 'lastname' => 'last name',
1.555 raeburn 9781: 'lastfirst' => 'last name, first name',
1.558 albertel 9782: 'crs' => 'in this course',
1.576 raeburn 9783: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9784: 'alc' => 'all LON-CAPA',
1.573 raeburn 9785: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9786: 'exact' => 'is',
9787: 'contains' => 'contains',
1.569 raeburn 9788: 'begins' => 'begins with',
1.1075.2.98 raeburn 9789: );
9790: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9791: 'youm' => "You must include some text to search for.",
9792: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9793: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9794: 'yomc' => "You must choose a domain when using an institutional directory search.",
9795: 'ymcd' => "You must choose a domain when using a domain search.",
9796: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9797: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9798: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9799: );
1.1075.2.98 raeburn 9800: &html_escape(\%html_lt);
9801: &js_escape(\%js_lt);
1.1075.2.115 raeburn 9802: my $domform;
1.1075.2.126 raeburn 9803: my $allow_blank = 1;
1.1075.2.115 raeburn 9804: if ($fixeddom) {
1.1075.2.126 raeburn 9805: $allow_blank = 0;
9806: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 9807: } else {
1.1075.2.126 raeburn 9808: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 9809: }
1.563 raeburn 9810: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9811:
9812: my @srchins = ('crs','dom','alc','instd');
9813:
9814: foreach my $option (@srchins) {
9815: # FIXME 'alc' option unavailable until
9816: # loncreateuser::print_user_query_page()
9817: # has been completed.
9818: next if ($option eq 'alc');
1.880 raeburn 9819: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9820: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 9821: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 9822: if ($curr_selected{'srchin'} eq $option) {
9823: $srchinsel .= '
1.1075.2.98 raeburn 9824: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9825: } else {
9826: $srchinsel .= '
1.1075.2.98 raeburn 9827: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9828: }
1.555 raeburn 9829: }
1.563 raeburn 9830: $srchinsel .= "\n </select>\n";
1.555 raeburn 9831:
9832: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9833: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9834: if ($curr_selected{'srchby'} eq $option) {
9835: $srchbysel .= '
1.1075.2.98 raeburn 9836: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9837: } else {
9838: $srchbysel .= '
1.1075.2.98 raeburn 9839: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9840: }
9841: }
9842: $srchbysel .= "\n </select>\n";
9843:
9844: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9845: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9846: if ($curr_selected{'srchtype'} eq $option) {
9847: $srchtypesel .= '
1.1075.2.98 raeburn 9848: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9849: } else {
9850: $srchtypesel .= '
1.1075.2.98 raeburn 9851: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9852: }
9853: }
9854: $srchtypesel .= "\n </select>\n";
9855:
1.558 albertel 9856: my ($newuserscript,$new_user_create);
1.994 raeburn 9857: my $context_dom = $env{'request.role.domain'};
9858: if ($context eq 'requestcrs') {
9859: if ($env{'form.coursedom'} ne '') {
9860: $context_dom = $env{'form.coursedom'};
9861: }
9862: }
1.556 raeburn 9863: if ($forcenewuser) {
1.576 raeburn 9864: if (ref($srch) eq 'HASH') {
1.994 raeburn 9865: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9866: if ($cancreate) {
9867: $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>';
9868: } else {
1.799 bisitz 9869: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9870: my %usertypetext = (
9871: official => 'institutional',
9872: unofficial => 'non-institutional',
9873: );
1.799 bisitz 9874: $new_user_create = '<p class="LC_warning">'
9875: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9876: .' '
9877: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9878: ,'<a href="'.$helplink.'">','</a>')
9879: .'</p><br />';
1.627 raeburn 9880: }
1.576 raeburn 9881: }
9882: }
9883:
1.556 raeburn 9884: $newuserscript = <<"ENDSCRIPT";
9885:
1.570 raeburn 9886: function setSearch(createnew,callingForm) {
1.556 raeburn 9887: if (createnew == 1) {
1.570 raeburn 9888: for (var i=0; i<callingForm.srchby.length; i++) {
9889: if (callingForm.srchby.options[i].value == 'uname') {
9890: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9891: }
9892: }
1.570 raeburn 9893: for (var i=0; i<callingForm.srchin.length; i++) {
9894: if ( callingForm.srchin.options[i].value == 'dom') {
9895: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9896: }
9897: }
1.570 raeburn 9898: for (var i=0; i<callingForm.srchtype.length; i++) {
9899: if (callingForm.srchtype.options[i].value == 'exact') {
9900: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9901: }
9902: }
1.570 raeburn 9903: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9904: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9905: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9906: }
9907: }
9908: }
9909: }
9910: ENDSCRIPT
1.558 albertel 9911:
1.556 raeburn 9912: }
9913:
1.555 raeburn 9914: my $output = <<"END_BLOCK";
1.556 raeburn 9915: <script type="text/javascript">
1.824 bisitz 9916: // <![CDATA[
1.570 raeburn 9917: function validateEntry(callingForm) {
1.558 albertel 9918:
1.556 raeburn 9919: var checkok = 1;
1.558 albertel 9920: var srchin;
1.570 raeburn 9921: for (var i=0; i<callingForm.srchin.length; i++) {
9922: if ( callingForm.srchin[i].checked ) {
9923: srchin = callingForm.srchin[i].value;
1.558 albertel 9924: }
9925: }
9926:
1.570 raeburn 9927: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9928: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9929: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9930: var srchterm = callingForm.srchterm.value;
9931: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9932: var msg = "";
9933:
9934: if (srchterm == "") {
9935: checkok = 0;
1.1075.2.98 raeburn 9936: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9937: }
9938:
1.569 raeburn 9939: if (srchtype== 'begins') {
9940: if (srchterm.length < 2) {
9941: checkok = 0;
1.1075.2.98 raeburn 9942: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9943: }
9944: }
9945:
1.556 raeburn 9946: if (srchtype== 'contains') {
9947: if (srchterm.length < 3) {
9948: checkok = 0;
1.1075.2.98 raeburn 9949: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9950: }
9951: }
9952: if (srchin == 'instd') {
9953: if (srchdomain == '') {
9954: checkok = 0;
1.1075.2.98 raeburn 9955: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9956: }
9957: }
9958: if (srchin == 'dom') {
9959: if (srchdomain == '') {
9960: checkok = 0;
1.1075.2.98 raeburn 9961: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9962: }
9963: }
9964: if (srchby == 'lastfirst') {
9965: if (srchterm.indexOf(",") == -1) {
9966: checkok = 0;
1.1075.2.98 raeburn 9967: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9968: }
9969: if (srchterm.indexOf(",") == srchterm.length -1) {
9970: checkok = 0;
1.1075.2.98 raeburn 9971: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9972: }
9973: }
9974: if (checkok == 0) {
1.1075.2.98 raeburn 9975: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9976: return;
9977: }
9978: if (checkok == 1) {
1.570 raeburn 9979: callingForm.submit();
1.556 raeburn 9980: }
9981: }
9982:
9983: $newuserscript
9984:
1.824 bisitz 9985: // ]]>
1.556 raeburn 9986: </script>
1.558 albertel 9987:
9988: $new_user_create
9989:
1.555 raeburn 9990: END_BLOCK
1.558 albertel 9991:
1.876 raeburn 9992: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 9993: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9994: $domform.
9995: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 9996: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9997: $srchbysel.
9998: $srchtypesel.
9999: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10000: $srchinsel.
10001: &Apache::lonhtmlcommon::row_closure(1).
10002: &Apache::lonhtmlcommon::end_pick_box().
10003: '<br />';
1.1075.2.114 raeburn 10004: return ($output,1);
1.555 raeburn 10005: }
10006:
1.612 raeburn 10007: sub user_rule_check {
1.615 raeburn 10008: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 10009: my ($response,%inst_response);
1.612 raeburn 10010: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 10011: if (keys(%{$usershash}) > 1) {
10012: my (%by_username,%by_id,%userdoms);
10013: my $checkid;
1.612 raeburn 10014: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 10015: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10016: $checkid = 1;
10017: }
10018: }
10019: foreach my $user (keys(%{$usershash})) {
10020: my ($uname,$udom) = split(/:/,$user);
10021: if ($checkid) {
10022: if (ref($usershash->{$user}) eq 'HASH') {
10023: if ($usershash->{$user}->{'id'} ne '') {
10024: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
10025: $userdoms{$udom} = 1;
10026: if (ref($inst_results) eq 'HASH') {
10027: $inst_results->{$uname.':'.$udom} = {};
10028: }
10029: }
10030: }
10031: } else {
10032: $by_username{$udom}{$uname} = 1;
10033: $userdoms{$udom} = 1;
10034: if (ref($inst_results) eq 'HASH') {
10035: $inst_results->{$uname.':'.$udom} = {};
10036: }
10037: }
10038: }
10039: foreach my $udom (keys(%userdoms)) {
10040: if (!$got_rules->{$udom}) {
10041: my %domconfig = &Apache::lonnet::get_dom('configuration',
10042: ['usercreation'],$udom);
10043: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10044: foreach my $item ('username','id') {
10045: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10046: $$curr_rules{$udom}{$item} =
10047: $domconfig{'usercreation'}{$item.'_rule'};
10048: }
10049: }
10050: }
10051: $got_rules->{$udom} = 1;
10052: }
10053: }
10054: if ($checkid) {
10055: foreach my $udom (keys(%by_id)) {
10056: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10057: if ($outcome eq 'ok') {
10058: foreach my $id (keys(%{$by_id{$udom}})) {
10059: my $uname = $by_id{$udom}{$id};
10060: $inst_response{$uname.':'.$udom} = $outcome;
10061: }
10062: if (ref($results) eq 'HASH') {
10063: foreach my $uname (keys(%{$results})) {
10064: if (exists($inst_response{$uname.':'.$udom})) {
10065: $inst_response{$uname.':'.$udom} = $outcome;
10066: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10067: }
10068: }
10069: }
10070: }
1.612 raeburn 10071: }
1.615 raeburn 10072: } else {
1.1075.2.99 raeburn 10073: foreach my $udom (keys(%by_username)) {
10074: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10075: if ($outcome eq 'ok') {
10076: foreach my $uname (keys(%{$by_username{$udom}})) {
10077: $inst_response{$uname.':'.$udom} = $outcome;
10078: }
10079: if (ref($results) eq 'HASH') {
10080: foreach my $uname (keys(%{$results})) {
10081: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10082: }
10083: }
10084: }
10085: }
1.612 raeburn 10086: }
1.1075.2.99 raeburn 10087: } elsif (keys(%{$usershash}) == 1) {
10088: my $user = (keys(%{$usershash}))[0];
10089: my ($uname,$udom) = split(/:/,$user);
10090: if (($udom ne '') && ($uname ne '')) {
10091: if (ref($usershash->{$user}) eq 'HASH') {
10092: if (ref($checks) eq 'HASH') {
10093: if (defined($checks->{'username'})) {
10094: ($inst_response{$user},%{$inst_results->{$user}}) =
10095: &Apache::lonnet::get_instuser($udom,$uname);
10096: } elsif (defined($checks->{'id'})) {
10097: if ($usershash->{$user}->{'id'} ne '') {
10098: ($inst_response{$user},%{$inst_results->{$user}}) =
10099: &Apache::lonnet::get_instuser($udom,undef,
10100: $usershash->{$user}->{'id'});
10101: } else {
10102: ($inst_response{$user},%{$inst_results->{$user}}) =
10103: &Apache::lonnet::get_instuser($udom,$uname);
10104: }
10105: }
10106: } else {
10107: ($inst_response{$user},%{$inst_results->{$user}}) =
10108: &Apache::lonnet::get_instuser($udom,$uname);
10109: return;
10110: }
10111: if (!$got_rules->{$udom}) {
10112: my %domconfig = &Apache::lonnet::get_dom('configuration',
10113: ['usercreation'],$udom);
10114: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10115: foreach my $item ('username','id') {
10116: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10117: $$curr_rules{$udom}{$item} =
10118: $domconfig{'usercreation'}{$item.'_rule'};
10119: }
10120: }
1.585 raeburn 10121: }
1.1075.2.99 raeburn 10122: $got_rules->{$udom} = 1;
1.585 raeburn 10123: }
10124: }
1.1075.2.99 raeburn 10125: } else {
10126: return;
10127: }
10128: } else {
10129: return;
10130: }
10131: foreach my $user (keys(%{$usershash})) {
10132: my ($uname,$udom) = split(/:/,$user);
10133: next if (($udom eq '') || ($uname eq ''));
10134: my $id;
10135: if (ref($inst_results) eq 'HASH') {
10136: if (ref($inst_results->{$user}) eq 'HASH') {
10137: $id = $inst_results->{$user}->{'id'};
10138: }
10139: }
10140: if ($id eq '') {
10141: if (ref($usershash->{$user})) {
10142: $id = $usershash->{$user}->{'id'};
10143: }
1.585 raeburn 10144: }
1.612 raeburn 10145: foreach my $item (keys(%{$checks})) {
10146: if (ref($$curr_rules{$udom}) eq 'HASH') {
10147: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10148: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10149: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10150: $$curr_rules{$udom}{$item});
1.612 raeburn 10151: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10152: if ($rule_check{$rule}) {
10153: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10154: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10155: if (ref($inst_results) eq 'HASH') {
10156: if (ref($inst_results->{$user}) eq 'HASH') {
10157: if (keys(%{$inst_results->{$user}}) == 0) {
10158: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10159: } elsif ($item eq 'id') {
10160: if ($inst_results->{$user}->{'id'} eq '') {
10161: $$alerts{$item}{$udom}{$uname} = 1;
10162: }
1.615 raeburn 10163: }
1.612 raeburn 10164: }
10165: }
1.615 raeburn 10166: }
10167: last;
1.585 raeburn 10168: }
10169: }
10170: }
10171: }
10172: }
10173: }
10174: }
10175: }
1.612 raeburn 10176: return;
10177: }
10178:
10179: sub user_rule_formats {
10180: my ($domain,$domdesc,$curr_rules,$check) = @_;
10181: my %text = (
10182: 'username' => 'Usernames',
10183: 'id' => 'IDs',
10184: );
10185: my $output;
10186: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10187: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10188: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10189: $output = '<br />'.
10190: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10191: '<span class="LC_cusr_emph">','</span>',$domdesc).
10192: ' <ul>';
1.612 raeburn 10193: foreach my $rule (@{$ruleorder}) {
10194: if (ref($curr_rules) eq 'ARRAY') {
10195: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10196: if (ref($rules->{$rule}) eq 'HASH') {
10197: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10198: $rules->{$rule}{'desc'}.'</li>';
10199: }
10200: }
10201: }
10202: }
10203: $output .= '</ul>';
10204: }
10205: }
10206: return $output;
10207: }
10208:
10209: sub instrule_disallow_msg {
1.615 raeburn 10210: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10211: my $response;
10212: my %text = (
10213: item => 'username',
10214: items => 'usernames',
10215: match => 'matches',
10216: do => 'does',
10217: action => 'a username',
10218: one => 'one',
10219: );
10220: if ($count > 1) {
10221: $text{'item'} = 'usernames';
10222: $text{'match'} ='match';
10223: $text{'do'} = 'do';
10224: $text{'action'} = 'usernames',
10225: $text{'one'} = 'ones';
10226: }
10227: if ($checkitem eq 'id') {
10228: $text{'items'} = 'IDs';
10229: $text{'item'} = 'ID';
10230: $text{'action'} = 'an ID';
1.615 raeburn 10231: if ($count > 1) {
10232: $text{'item'} = 'IDs';
10233: $text{'action'} = 'IDs';
10234: }
1.612 raeburn 10235: }
1.674 bisitz 10236: $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 10237: if ($mode eq 'upload') {
10238: if ($checkitem eq 'username') {
10239: $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'}.");
10240: } elsif ($checkitem eq 'id') {
1.674 bisitz 10241: $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 10242: }
1.669 raeburn 10243: } elsif ($mode eq 'selfcreate') {
10244: if ($checkitem eq 'id') {
10245: $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.");
10246: }
1.615 raeburn 10247: } else {
10248: if ($checkitem eq 'username') {
10249: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10250: } elsif ($checkitem eq 'id') {
10251: $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.");
10252: }
1.612 raeburn 10253: }
10254: return $response;
1.585 raeburn 10255: }
10256:
1.624 raeburn 10257: sub personal_data_fieldtitles {
10258: my %fieldtitles = &Apache::lonlocal::texthash (
10259: id => 'Student/Employee ID',
10260: permanentemail => 'E-mail address',
10261: lastname => 'Last Name',
10262: firstname => 'First Name',
10263: middlename => 'Middle Name',
10264: generation => 'Generation',
10265: gen => 'Generation',
1.765 raeburn 10266: inststatus => 'Affiliation',
1.624 raeburn 10267: );
10268: return %fieldtitles;
10269: }
10270:
1.642 raeburn 10271: sub sorted_inst_types {
10272: my ($dom) = @_;
1.1075.2.70 raeburn 10273: my ($usertypes,$order);
10274: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10275: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10276: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10277: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10278: } else {
10279: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10280: }
1.642 raeburn 10281: my $othertitle = &mt('All users');
10282: if ($env{'request.course.id'}) {
1.668 raeburn 10283: $othertitle = &mt('Any users');
1.642 raeburn 10284: }
10285: my @types;
10286: if (ref($order) eq 'ARRAY') {
10287: @types = @{$order};
10288: }
10289: if (@types == 0) {
10290: if (ref($usertypes) eq 'HASH') {
10291: @types = sort(keys(%{$usertypes}));
10292: }
10293: }
10294: if (keys(%{$usertypes}) > 0) {
10295: $othertitle = &mt('Other users');
10296: }
10297: return ($othertitle,$usertypes,\@types);
10298: }
10299:
1.645 raeburn 10300: sub get_institutional_codes {
10301: my ($settings,$allcourses,$LC_code) = @_;
10302: # Get complete list of course sections to update
10303: my @currsections = ();
10304: my @currxlists = ();
10305: my $coursecode = $$settings{'internal.coursecode'};
10306:
10307: if ($$settings{'internal.sectionnums'} ne '') {
10308: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10309: }
10310:
10311: if ($$settings{'internal.crosslistings'} ne '') {
10312: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10313: }
10314:
10315: if (@currxlists > 0) {
10316: foreach (@currxlists) {
10317: if (m/^([^:]+):(\w*)$/) {
10318: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10319: push(@{$allcourses},$1);
1.645 raeburn 10320: $$LC_code{$1} = $2;
10321: }
10322: }
10323: }
10324: }
10325:
10326: if (@currsections > 0) {
10327: foreach (@currsections) {
10328: if (m/^(\w+):(\w*)$/) {
10329: my $sec = $coursecode.$1;
10330: my $lc_sec = $2;
10331: unless (grep/^$sec$/,@{$allcourses}) {
1.1075.2.119 raeburn 10332: push(@{$allcourses},$sec);
1.645 raeburn 10333: $$LC_code{$sec} = $lc_sec;
10334: }
10335: }
10336: }
10337: }
10338: return;
10339: }
10340:
1.971 raeburn 10341: sub get_standard_codeitems {
10342: return ('Year','Semester','Department','Number','Section');
10343: }
10344:
1.112 bowersj2 10345: =pod
10346:
1.780 raeburn 10347: =head1 Slot Helpers
10348:
10349: =over 4
10350:
10351: =item * sorted_slots()
10352:
1.1040 raeburn 10353: Sorts an array of slot names in order of an optional sort key,
10354: default sort is by slot start time (earliest first).
1.780 raeburn 10355:
10356: Inputs:
10357:
10358: =over 4
10359:
10360: slotsarr - Reference to array of unsorted slot names.
10361:
10362: slots - Reference to hash of hash, where outer hash keys are slot names.
10363:
1.1040 raeburn 10364: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10365:
1.549 albertel 10366: =back
10367:
1.780 raeburn 10368: Returns:
10369:
10370: =over 4
10371:
1.1040 raeburn 10372: sorted - An array of slot names sorted by a specified sort key
10373: (default sort key is start time of the slot).
1.780 raeburn 10374:
10375: =back
10376:
10377: =cut
10378:
10379:
10380: sub sorted_slots {
1.1040 raeburn 10381: my ($slotsarr,$slots,$sortkey) = @_;
10382: if ($sortkey eq '') {
10383: $sortkey = 'starttime';
10384: }
1.780 raeburn 10385: my @sorted;
10386: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10387: @sorted =
10388: sort {
10389: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10390: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10391: }
10392: if (ref($slots->{$a})) { return -1;}
10393: if (ref($slots->{$b})) { return 1;}
10394: return 0;
10395: } @{$slotsarr};
10396: }
10397: return @sorted;
10398: }
10399:
1.1040 raeburn 10400: =pod
10401:
10402: =item * get_future_slots()
10403:
10404: Inputs:
10405:
10406: =over 4
10407:
10408: cnum - course number
10409:
10410: cdom - course domain
10411:
10412: now - current UNIX time
10413:
10414: symb - optional symb
10415:
10416: =back
10417:
10418: Returns:
10419:
10420: =over 4
10421:
10422: sorted_reservable - ref to array of student_schedulable slots currently
10423: reservable, ordered by end date of reservation period.
10424:
10425: reservable_now - ref to hash of student_schedulable slots currently
10426: reservable.
10427:
10428: Keys in inner hash are:
10429: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10430: (b) endreserve: end date of reservation period.
10431: (c) uniqueperiod: start,end dates when slot is to be uniquely
10432: selected.
1.1040 raeburn 10433:
10434: sorted_future - ref to array of student_schedulable slots reservable in
10435: the future, ordered by start date of reservation period.
10436:
10437: future_reservable - ref to hash of student_schedulable slots reservable
10438: in the future.
10439:
10440: Keys in inner hash are:
10441: (a) symb: either blank or symb to which slot use is restricted.
10442: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10443: (c) uniqueperiod: start,end dates when slot is to be uniquely
10444: selected.
1.1040 raeburn 10445:
10446: =back
10447:
10448: =cut
10449:
10450: sub get_future_slots {
10451: my ($cnum,$cdom,$now,$symb) = @_;
10452: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10453: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10454: foreach my $slot (keys(%slots)) {
10455: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10456: if ($symb) {
10457: next if (($slots{$slot}->{'symb'} ne '') &&
10458: ($slots{$slot}->{'symb'} ne $symb));
10459: }
10460: if (($slots{$slot}->{'starttime'} > $now) &&
10461: ($slots{$slot}->{'endtime'} > $now)) {
10462: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10463: my $userallowed = 0;
10464: if ($slots{$slot}->{'allowedsections'}) {
10465: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10466: if (!defined($env{'request.role.sec'})
10467: && grep(/^No section assigned$/,@allowed_sec)) {
10468: $userallowed=1;
10469: } else {
10470: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10471: $userallowed=1;
10472: }
10473: }
10474: unless ($userallowed) {
10475: if (defined($env{'request.course.groups'})) {
10476: my @groups = split(/:/,$env{'request.course.groups'});
10477: foreach my $group (@groups) {
10478: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10479: $userallowed=1;
10480: last;
10481: }
10482: }
10483: }
10484: }
10485: }
10486: if ($slots{$slot}->{'allowedusers'}) {
10487: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10488: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10489: if (grep(/^\Q$user\E$/,@allowed_users)) {
10490: $userallowed = 1;
10491: }
10492: }
10493: next unless($userallowed);
10494: }
10495: my $startreserve = $slots{$slot}->{'startreserve'};
10496: my $endreserve = $slots{$slot}->{'endreserve'};
10497: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10498: my $uniqueperiod;
10499: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10500: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10501: }
1.1040 raeburn 10502: if (($startreserve < $now) &&
10503: (!$endreserve || $endreserve > $now)) {
10504: my $lastres = $endreserve;
10505: if (!$lastres) {
10506: $lastres = $slots{$slot}->{'starttime'};
10507: }
10508: $reservable_now{$slot} = {
10509: symb => $symb,
1.1075.2.104 raeburn 10510: endreserve => $lastres,
10511: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10512: };
10513: } elsif (($startreserve > $now) &&
10514: (!$endreserve || $endreserve > $startreserve)) {
10515: $future_reservable{$slot} = {
10516: symb => $symb,
1.1075.2.104 raeburn 10517: startreserve => $startreserve,
10518: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10519: };
10520: }
10521: }
10522: }
10523: my @unsorted_reservable = keys(%reservable_now);
10524: if (@unsorted_reservable > 0) {
10525: @sorted_reservable =
10526: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10527: }
10528: my @unsorted_future = keys(%future_reservable);
10529: if (@unsorted_future > 0) {
10530: @sorted_future =
10531: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10532: }
10533: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10534: }
1.780 raeburn 10535:
10536: =pod
10537:
1.1057 foxr 10538: =back
10539:
1.549 albertel 10540: =head1 HTTP Helpers
10541:
10542: =over 4
10543:
1.648 raeburn 10544: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10545:
1.258 albertel 10546: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10547: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10548: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10549:
10550: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10551: $possible_names is an ref to an array of form element names. As an example:
10552: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10553: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10554:
10555: =cut
1.1 albertel 10556:
1.6 albertel 10557: sub get_unprocessed_cgi {
1.25 albertel 10558: my ($query,$possible_names)= @_;
1.26 matthew 10559: # $Apache::lonxml::debug=1;
1.356 albertel 10560: foreach my $pair (split(/&/,$query)) {
10561: my ($name, $value) = split(/=/,$pair);
1.369 www 10562: $name = &unescape($name);
1.25 albertel 10563: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10564: $value =~ tr/+/ /;
10565: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10566: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10567: }
1.16 harris41 10568: }
1.6 albertel 10569: }
10570:
1.112 bowersj2 10571: =pod
10572:
1.648 raeburn 10573: =item * &cacheheader()
1.112 bowersj2 10574:
10575: returns cache-controlling header code
10576:
10577: =cut
10578:
1.7 albertel 10579: sub cacheheader {
1.258 albertel 10580: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10581: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10582: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10583: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10584: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10585: return $output;
1.7 albertel 10586: }
10587:
1.112 bowersj2 10588: =pod
10589:
1.648 raeburn 10590: =item * &no_cache($r)
1.112 bowersj2 10591:
10592: specifies header code to not have cache
10593:
10594: =cut
10595:
1.9 albertel 10596: sub no_cache {
1.216 albertel 10597: my ($r) = @_;
10598: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10599: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10600: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10601: $r->no_cache(1);
10602: $r->header_out("Expires" => $date);
10603: $r->header_out("Pragma" => "no-cache");
1.123 www 10604: }
10605:
10606: sub content_type {
1.181 albertel 10607: my ($r,$type,$charset) = @_;
1.299 foxr 10608: if ($r) {
10609: # Note that printout.pl calls this with undef for $r.
10610: &no_cache($r);
10611: }
1.258 albertel 10612: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10613: unless ($charset) {
10614: $charset=&Apache::lonlocal::current_encoding;
10615: }
10616: if ($charset) { $type.='; charset='.$charset; }
10617: if ($r) {
10618: $r->content_type($type);
10619: } else {
10620: print("Content-type: $type\n\n");
10621: }
1.9 albertel 10622: }
1.25 albertel 10623:
1.112 bowersj2 10624: =pod
10625:
1.648 raeburn 10626: =item * &add_to_env($name,$value)
1.112 bowersj2 10627:
1.258 albertel 10628: adds $name to the %env hash with value
1.112 bowersj2 10629: $value, if $name already exists, the entry is converted to an array
10630: reference and $value is added to the array.
10631:
10632: =cut
10633:
1.25 albertel 10634: sub add_to_env {
10635: my ($name,$value)=@_;
1.258 albertel 10636: if (defined($env{$name})) {
10637: if (ref($env{$name})) {
1.25 albertel 10638: #already have multiple values
1.258 albertel 10639: push(@{ $env{$name} },$value);
1.25 albertel 10640: } else {
10641: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10642: my $first=$env{$name};
10643: undef($env{$name});
10644: push(@{ $env{$name} },$first,$value);
1.25 albertel 10645: }
10646: } else {
1.258 albertel 10647: $env{$name}=$value;
1.25 albertel 10648: }
1.31 albertel 10649: }
1.149 albertel 10650:
10651: =pod
10652:
1.648 raeburn 10653: =item * &get_env_multiple($name)
1.149 albertel 10654:
1.258 albertel 10655: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10656: values may be defined and end up as an array ref.
10657:
10658: returns an array of values
10659:
10660: =cut
10661:
10662: sub get_env_multiple {
10663: my ($name) = @_;
10664: my @values;
1.258 albertel 10665: if (defined($env{$name})) {
1.149 albertel 10666: # exists is it an array
1.258 albertel 10667: if (ref($env{$name})) {
10668: @values=@{ $env{$name} };
1.149 albertel 10669: } else {
1.258 albertel 10670: $values[0]=$env{$name};
1.149 albertel 10671: }
10672: }
10673: return(@values);
10674: }
10675:
1.660 raeburn 10676: sub ask_for_embedded_content {
10677: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10678: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10679: %currsubfile,%unused,$rem);
1.1071 raeburn 10680: my $counter = 0;
10681: my $numnew = 0;
1.987 raeburn 10682: my $numremref = 0;
10683: my $numinvalid = 0;
10684: my $numpathchg = 0;
10685: my $numexisting = 0;
1.1071 raeburn 10686: my $numunused = 0;
10687: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10688: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10689: my $heading = &mt('Upload embedded files');
10690: my $buttontext = &mt('Upload');
10691:
1.1075.2.11 raeburn 10692: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10693: if ($actionurl eq '/adm/dependencies') {
10694: $navmap = Apache::lonnavmaps::navmap->new();
10695: }
10696: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10697: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10698: }
1.1075.2.35 raeburn 10699: if (($actionurl eq '/adm/portfolio') ||
10700: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10701: my $current_path='/';
10702: if ($env{'form.currentpath'}) {
10703: $current_path = $env{'form.currentpath'};
10704: }
10705: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10706: $udom = $cdom;
10707: $uname = $cnum;
1.984 raeburn 10708: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10709: } else {
10710: $udom = $env{'user.domain'};
10711: $uname = $env{'user.name'};
10712: $url = '/userfiles/portfolio';
10713: }
1.987 raeburn 10714: $toplevel = $url.'/';
1.984 raeburn 10715: $url .= $current_path;
10716: $getpropath = 1;
1.987 raeburn 10717: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10718: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10719: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10720: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10721: $toplevel = $url;
1.984 raeburn 10722: if ($rest ne '') {
1.987 raeburn 10723: $url .= $rest;
10724: }
10725: } elsif ($actionurl eq '/adm/coursedocs') {
10726: if (ref($args) eq 'HASH') {
1.1071 raeburn 10727: $url = $args->{'docs_url'};
10728: $toplevel = $url;
1.1075.2.11 raeburn 10729: if ($args->{'context'} eq 'paste') {
10730: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10731: ($path) =
10732: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10733: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10734: $fileloc =~ s{^/}{};
10735: }
1.1071 raeburn 10736: }
10737: } elsif ($actionurl eq '/adm/dependencies') {
10738: if ($env{'request.course.id'} ne '') {
10739: if (ref($args) eq 'HASH') {
10740: $url = $args->{'docs_url'};
10741: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10742: $toplevel = $url;
10743: unless ($toplevel =~ m{^/}) {
10744: $toplevel = "/$url";
10745: }
1.1075.2.11 raeburn 10746: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10747: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10748: $path = $1;
10749: } else {
10750: ($path) =
10751: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10752: }
1.1075.2.79 raeburn 10753: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10754: $fileloc = $toplevel;
10755: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10756: my ($udom,$uname,$fname) =
10757: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10758: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10759: } else {
10760: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10761: }
1.1071 raeburn 10762: $fileloc =~ s{^/}{};
10763: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10764: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10765: }
1.987 raeburn 10766: }
1.1075.2.35 raeburn 10767: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10768: $udom = $cdom;
10769: $uname = $cnum;
10770: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10771: $toplevel = $url;
10772: $path = $url;
10773: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10774: $fileloc =~ s{^/}{};
10775: }
10776: foreach my $file (keys(%{$allfiles})) {
10777: my $embed_file;
10778: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10779: $embed_file = $1;
10780: } else {
10781: $embed_file = $file;
10782: }
1.1075.2.55 raeburn 10783: my ($absolutepath,$cleaned_file);
10784: if ($embed_file =~ m{^\w+://}) {
10785: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10786: $newfiles{$cleaned_file} = 1;
10787: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10788: } else {
1.1075.2.55 raeburn 10789: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10790: if ($embed_file =~ m{^/}) {
10791: $absolutepath = $embed_file;
10792: }
1.1075.2.47 raeburn 10793: if ($cleaned_file =~ m{/}) {
10794: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10795: $path = &check_for_traversal($path,$url,$toplevel);
10796: my $item = $fname;
10797: if ($path ne '') {
10798: $item = $path.'/'.$fname;
10799: $subdependencies{$path}{$fname} = 1;
10800: } else {
10801: $dependencies{$item} = 1;
10802: }
10803: if ($absolutepath) {
10804: $mapping{$item} = $absolutepath;
10805: } else {
10806: $mapping{$item} = $embed_file;
10807: }
10808: } else {
10809: $dependencies{$embed_file} = 1;
10810: if ($absolutepath) {
1.1075.2.47 raeburn 10811: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10812: } else {
1.1075.2.47 raeburn 10813: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10814: }
10815: }
1.984 raeburn 10816: }
10817: }
1.1071 raeburn 10818: my $dirptr = 16384;
1.984 raeburn 10819: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10820: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10821: if (($actionurl eq '/adm/portfolio') ||
10822: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10823: my ($sublistref,$listerror) =
10824: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10825: if (ref($sublistref) eq 'ARRAY') {
10826: foreach my $line (@{$sublistref}) {
10827: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10828: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10829: }
1.984 raeburn 10830: }
1.987 raeburn 10831: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10832: if (opendir(my $dir,$url.'/'.$path)) {
10833: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10834: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10835: }
1.1075.2.11 raeburn 10836: } elsif (($actionurl eq '/adm/dependencies') ||
10837: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10838: ($args->{'context'} eq 'paste')) ||
10839: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10840: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10841: my $dir;
10842: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10843: $dir = $fileloc;
10844: } else {
10845: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10846: }
1.1071 raeburn 10847: if ($dir ne '') {
10848: my ($sublistref,$listerror) =
10849: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10850: if (ref($sublistref) eq 'ARRAY') {
10851: foreach my $line (@{$sublistref}) {
10852: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10853: undef,$mtime)=split(/\&/,$line,12);
10854: unless (($testdir&$dirptr) ||
10855: ($file_name =~ /^\.\.?$/)) {
10856: $currsubfile{$path}{$file_name} = [$size,$mtime];
10857: }
10858: }
10859: }
10860: }
1.984 raeburn 10861: }
10862: }
10863: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10864: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10865: my $item = $path.'/'.$file;
10866: unless ($mapping{$item} eq $item) {
10867: $pathchanges{$item} = 1;
10868: }
10869: $existing{$item} = 1;
10870: $numexisting ++;
10871: } else {
10872: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10873: }
10874: }
1.1071 raeburn 10875: if ($actionurl eq '/adm/dependencies') {
10876: foreach my $path (keys(%currsubfile)) {
10877: if (ref($currsubfile{$path}) eq 'HASH') {
10878: foreach my $file (keys(%{$currsubfile{$path}})) {
10879: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10880: next if (($rem ne '') &&
10881: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10882: (ref($navmap) &&
10883: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10884: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10885: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10886: $unused{$path.'/'.$file} = 1;
10887: }
10888: }
10889: }
10890: }
10891: }
1.984 raeburn 10892: }
1.987 raeburn 10893: my %currfile;
1.1075.2.35 raeburn 10894: if (($actionurl eq '/adm/portfolio') ||
10895: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10896: my ($dirlistref,$listerror) =
10897: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10898: if (ref($dirlistref) eq 'ARRAY') {
10899: foreach my $line (@{$dirlistref}) {
10900: my ($file_name,$rest) = split(/\&/,$line,2);
10901: $currfile{$file_name} = 1;
10902: }
1.984 raeburn 10903: }
1.987 raeburn 10904: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10905: if (opendir(my $dir,$url)) {
1.987 raeburn 10906: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10907: map {$currfile{$_} = 1;} @dir_list;
10908: }
1.1075.2.11 raeburn 10909: } elsif (($actionurl eq '/adm/dependencies') ||
10910: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10911: ($args->{'context'} eq 'paste')) ||
10912: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10913: if ($env{'request.course.id'} ne '') {
10914: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10915: if ($dir ne '') {
10916: my ($dirlistref,$listerror) =
10917: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10918: if (ref($dirlistref) eq 'ARRAY') {
10919: foreach my $line (@{$dirlistref}) {
10920: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10921: $size,undef,$mtime)=split(/\&/,$line,12);
10922: unless (($testdir&$dirptr) ||
10923: ($file_name =~ /^\.\.?$/)) {
10924: $currfile{$file_name} = [$size,$mtime];
10925: }
10926: }
10927: }
10928: }
10929: }
1.984 raeburn 10930: }
10931: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10932: if (exists($currfile{$file})) {
1.987 raeburn 10933: unless ($mapping{$file} eq $file) {
10934: $pathchanges{$file} = 1;
10935: }
10936: $existing{$file} = 1;
10937: $numexisting ++;
10938: } else {
1.984 raeburn 10939: $newfiles{$file} = 1;
10940: }
10941: }
1.1071 raeburn 10942: foreach my $file (keys(%currfile)) {
10943: unless (($file eq $filename) ||
10944: ($file eq $filename.'.bak') ||
10945: ($dependencies{$file})) {
1.1075.2.11 raeburn 10946: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10947: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10948: next if (($rem ne '') &&
10949: (($env{"httpref.$rem".$file} ne '') ||
10950: (ref($navmap) &&
10951: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10952: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10953: ($navmap->getResourceByUrl($rem.$1)))))));
10954: }
1.1075.2.11 raeburn 10955: }
1.1071 raeburn 10956: $unused{$file} = 1;
10957: }
10958: }
1.1075.2.11 raeburn 10959: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10960: ($args->{'context'} eq 'paste')) {
10961: $counter = scalar(keys(%existing));
10962: $numpathchg = scalar(keys(%pathchanges));
10963: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10964: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10965: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10966: $counter = scalar(keys(%existing));
10967: $numpathchg = scalar(keys(%pathchanges));
10968: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10969: }
1.984 raeburn 10970: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10971: if ($actionurl eq '/adm/dependencies') {
10972: next if ($embed_file =~ m{^\w+://});
10973: }
1.660 raeburn 10974: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10975: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10976: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10977: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10978: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10979: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10980: }
1.1075.2.35 raeburn 10981: $upload_output .= '</td>';
1.1071 raeburn 10982: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10983: $upload_output.='<td align="right">'.
10984: '<span class="LC_info LC_fontsize_medium">'.
10985: &mt("URL points to web address").'</span>';
1.987 raeburn 10986: $numremref++;
1.660 raeburn 10987: } elsif ($args->{'error_on_invalid_names'}
10988: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10989: $upload_output.='<td align="right"><span class="LC_warning">'.
10990: &mt('Invalid characters').'</span>';
1.987 raeburn 10991: $numinvalid++;
1.660 raeburn 10992: } else {
1.1075.2.35 raeburn 10993: $upload_output .= '<td>'.
10994: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10995: $embed_file,\%mapping,
1.1071 raeburn 10996: $allfiles,$codebase,'upload');
10997: $counter ++;
10998: $numnew ++;
1.987 raeburn 10999: }
11000: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11001: }
11002: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11003: if ($actionurl eq '/adm/dependencies') {
11004: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11005: $modify_output .= &start_data_table_row().
11006: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11007: '<img src="'.&icon($embed_file).'" border="0" />'.
11008: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11009: '<td>'.$size.'</td>'.
11010: '<td>'.$mtime.'</td>'.
11011: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11012: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11013: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11014: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11015: &embedded_file_element('upload_embedded',$counter,
11016: $embed_file,\%mapping,
11017: $allfiles,$codebase,'modify').
11018: '</div></td>'.
11019: &end_data_table_row()."\n";
11020: $counter ++;
11021: } else {
11022: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 11023: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11024: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11025: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11026: &Apache::loncommon::end_data_table_row()."\n";
11027: }
11028: }
11029: my $delidx = $counter;
11030: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11031: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11032: $delete_output .= &start_data_table_row().
11033: '<td><img src="'.&icon($oldfile).'" />'.
11034: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11035: '<td>'.$size.'</td>'.
11036: '<td>'.$mtime.'</td>'.
11037: '<td><label><input type="checkbox" name="del_upload_dep" '.
11038: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11039: &embedded_file_element('upload_embedded',$delidx,
11040: $oldfile,\%mapping,$allfiles,
11041: $codebase,'delete').'</td>'.
11042: &end_data_table_row()."\n";
11043: $numunused ++;
11044: $delidx ++;
1.987 raeburn 11045: }
11046: if ($upload_output) {
11047: $upload_output = &start_data_table().
11048: $upload_output.
11049: &end_data_table()."\n";
11050: }
1.1071 raeburn 11051: if ($modify_output) {
11052: $modify_output = &start_data_table().
11053: &start_data_table_header_row().
11054: '<th>'.&mt('File').'</th>'.
11055: '<th>'.&mt('Size (KB)').'</th>'.
11056: '<th>'.&mt('Modified').'</th>'.
11057: '<th>'.&mt('Upload replacement?').'</th>'.
11058: &end_data_table_header_row().
11059: $modify_output.
11060: &end_data_table()."\n";
11061: }
11062: if ($delete_output) {
11063: $delete_output = &start_data_table().
11064: &start_data_table_header_row().
11065: '<th>'.&mt('File').'</th>'.
11066: '<th>'.&mt('Size (KB)').'</th>'.
11067: '<th>'.&mt('Modified').'</th>'.
11068: '<th>'.&mt('Delete?').'</th>'.
11069: &end_data_table_header_row().
11070: $delete_output.
11071: &end_data_table()."\n";
11072: }
1.987 raeburn 11073: my $applies = 0;
11074: if ($numremref) {
11075: $applies ++;
11076: }
11077: if ($numinvalid) {
11078: $applies ++;
11079: }
11080: if ($numexisting) {
11081: $applies ++;
11082: }
1.1071 raeburn 11083: if ($counter || $numunused) {
1.987 raeburn 11084: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11085: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11086: $state.'<h3>'.$heading.'</h3>';
11087: if ($actionurl eq '/adm/dependencies') {
11088: if ($numnew) {
11089: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11090: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11091: $upload_output.'<br />'."\n";
11092: }
11093: if ($numexisting) {
11094: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11095: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11096: $modify_output.'<br />'."\n";
11097: $buttontext = &mt('Save changes');
11098: }
11099: if ($numunused) {
11100: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11101: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11102: $delete_output.'<br />'."\n";
11103: $buttontext = &mt('Save changes');
11104: }
11105: } else {
11106: $output .= $upload_output.'<br />'."\n";
11107: }
11108: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11109: $counter.'" />'."\n";
11110: if ($actionurl eq '/adm/dependencies') {
11111: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11112: $numnew.'" />'."\n";
11113: } elsif ($actionurl eq '') {
1.987 raeburn 11114: $output .= '<input type="hidden" name="phase" value="three" />';
11115: }
11116: } elsif ($applies) {
11117: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11118: if ($applies > 1) {
11119: $output .=
1.1075.2.35 raeburn 11120: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11121: if ($numremref) {
11122: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11123: }
11124: if ($numinvalid) {
11125: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11126: }
11127: if ($numexisting) {
11128: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11129: }
11130: $output .= '</ul><br />';
11131: } elsif ($numremref) {
11132: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11133: } elsif ($numinvalid) {
11134: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11135: } elsif ($numexisting) {
11136: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11137: }
11138: $output .= $upload_output.'<br />';
11139: }
11140: my ($pathchange_output,$chgcount);
1.1071 raeburn 11141: $chgcount = $counter;
1.987 raeburn 11142: if (keys(%pathchanges) > 0) {
11143: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11144: if ($counter) {
1.987 raeburn 11145: $output .= &embedded_file_element('pathchange',$chgcount,
11146: $embed_file,\%mapping,
1.1071 raeburn 11147: $allfiles,$codebase,'change');
1.987 raeburn 11148: } else {
11149: $pathchange_output .=
11150: &start_data_table_row().
11151: '<td><input type ="checkbox" name="namechange" value="'.
11152: $chgcount.'" checked="checked" /></td>'.
11153: '<td>'.$mapping{$embed_file}.'</td>'.
11154: '<td>'.$embed_file.
11155: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11156: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11157: '</td>'.&end_data_table_row();
1.660 raeburn 11158: }
1.987 raeburn 11159: $numpathchg ++;
11160: $chgcount ++;
1.660 raeburn 11161: }
11162: }
1.1075.2.35 raeburn 11163: if (($counter) || ($numunused)) {
1.987 raeburn 11164: if ($numpathchg) {
11165: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11166: $numpathchg.'" />'."\n";
11167: }
11168: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11169: ($actionurl eq '/adm/imsimport')) {
11170: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11171: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11172: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11173: } elsif ($actionurl eq '/adm/dependencies') {
11174: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11175: }
1.1075.2.35 raeburn 11176: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11177: } elsif ($numpathchg) {
11178: my %pathchange = ();
11179: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11180: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11181: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11182: }
1.987 raeburn 11183: }
1.1071 raeburn 11184: return ($output,$counter,$numpathchg);
1.987 raeburn 11185: }
11186:
1.1075.2.47 raeburn 11187: =pod
11188:
11189: =item * clean_path($name)
11190:
11191: Performs clean-up of directories, subdirectories and filename in an
11192: embedded object, referenced in an HTML file which is being uploaded
11193: to a course or portfolio, where
11194: "Upload embedded images/multimedia files if HTML file" checkbox was
11195: checked.
11196:
11197: Clean-up is similar to replacements in lonnet::clean_filename()
11198: except each / between sub-directory and next level is preserved.
11199:
11200: =cut
11201:
11202: sub clean_path {
11203: my ($embed_file) = @_;
11204: $embed_file =~s{^/+}{};
11205: my @contents;
11206: if ($embed_file =~ m{/}) {
11207: @contents = split(/\//,$embed_file);
11208: } else {
11209: @contents = ($embed_file);
11210: }
11211: my $lastidx = scalar(@contents)-1;
11212: for (my $i=0; $i<=$lastidx; $i++) {
11213: $contents[$i]=~s{\\}{/}g;
11214: $contents[$i]=~s/\s+/\_/g;
11215: $contents[$i]=~s{[^/\w\.\-]}{}g;
11216: if ($i == $lastidx) {
11217: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11218: }
11219: }
11220: if ($lastidx > 0) {
11221: return join('/',@contents);
11222: } else {
11223: return $contents[0];
11224: }
11225: }
11226:
1.987 raeburn 11227: sub embedded_file_element {
1.1071 raeburn 11228: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11229: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11230: (ref($codebase) eq 'HASH'));
11231: my $output;
1.1071 raeburn 11232: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11233: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11234: }
11235: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11236: &escape($embed_file).'" />';
11237: unless (($context eq 'upload_embedded') &&
11238: ($mapping->{$embed_file} eq $embed_file)) {
11239: $output .='
11240: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11241: }
11242: my $attrib;
11243: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11244: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11245: }
11246: $output .=
11247: "\n\t\t".
11248: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11249: $attrib.'" />';
11250: if (exists($codebase->{$mapping->{$embed_file}})) {
11251: $output .=
11252: "\n\t\t".
11253: '<input name="codebase_'.$num.'" type="hidden" value="'.
11254: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11255: }
1.987 raeburn 11256: return $output;
1.660 raeburn 11257: }
11258:
1.1071 raeburn 11259: sub get_dependency_details {
11260: my ($currfile,$currsubfile,$embed_file) = @_;
11261: my ($size,$mtime,$showsize,$showmtime);
11262: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11263: if ($embed_file =~ m{/}) {
11264: my ($path,$fname) = split(/\//,$embed_file);
11265: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11266: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11267: }
11268: } else {
11269: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11270: ($size,$mtime) = @{$currfile->{$embed_file}};
11271: }
11272: }
11273: $showsize = $size/1024.0;
11274: $showsize = sprintf("%.1f",$showsize);
11275: if ($mtime > 0) {
11276: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11277: }
11278: }
11279: return ($showsize,$showmtime);
11280: }
11281:
11282: sub ask_embedded_js {
11283: return <<"END";
11284: <script type="text/javascript"">
11285: // <![CDATA[
11286: function toggleBrowse(counter) {
11287: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11288: var fileid = document.getElementById('embedded_item_'+counter);
11289: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11290: if (chkboxid.checked == true) {
11291: uploaddivid.style.display='block';
11292: } else {
11293: uploaddivid.style.display='none';
11294: fileid.value = '';
11295: }
11296: }
11297: // ]]>
11298: </script>
11299:
11300: END
11301: }
11302:
1.661 raeburn 11303: sub upload_embedded {
11304: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11305: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11306: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11307: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11308: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11309: my $orig_uploaded_filename =
11310: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11311: foreach my $type ('orig','ref','attrib','codebase') {
11312: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11313: $env{'form.embedded_'.$type.'_'.$i} =
11314: &unescape($env{'form.embedded_'.$type.'_'.$i});
11315: }
11316: }
1.661 raeburn 11317: my ($path,$fname) =
11318: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11319: # no path, whole string is fname
11320: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11321: $fname = &Apache::lonnet::clean_filename($fname);
11322: # See if there is anything left
11323: next if ($fname eq '');
11324:
11325: # Check if file already exists as a file or directory.
11326: my ($state,$msg);
11327: if ($context eq 'portfolio') {
11328: my $port_path = $dirpath;
11329: if ($group ne '') {
11330: $port_path = "groups/$group/$port_path";
11331: }
1.987 raeburn 11332: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11333: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11334: $dir_root,$port_path,$disk_quota,
11335: $current_disk_usage,$uname,$udom);
11336: if ($state eq 'will_exceed_quota'
1.984 raeburn 11337: || $state eq 'file_locked') {
1.661 raeburn 11338: $output .= $msg;
11339: next;
11340: }
11341: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11342: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11343: if ($state eq 'exists') {
11344: $output .= $msg;
11345: next;
11346: }
11347: }
11348: # Check if extension is valid
11349: if (($fname =~ /\.(\w+)$/) &&
11350: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11351: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11352: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11353: next;
11354: } elsif (($fname =~ /\.(\w+)$/) &&
11355: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11356: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11357: next;
11358: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11359: $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 11360: next;
11361: }
11362: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11363: my $subdir = $path;
11364: $subdir =~ s{/+$}{};
1.661 raeburn 11365: if ($context eq 'portfolio') {
1.984 raeburn 11366: my $result;
11367: if ($state eq 'existingfile') {
11368: $result=
11369: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11370: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11371: } else {
1.984 raeburn 11372: $result=
11373: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11374: $dirpath.
1.1075.2.35 raeburn 11375: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11376: if ($result !~ m|^/uploaded/|) {
11377: $output .= '<span class="LC_error">'
11378: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11379: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11380: .'</span><br />';
11381: next;
11382: } else {
1.987 raeburn 11383: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11384: $path.$fname.'</span>').'<br />';
1.984 raeburn 11385: }
1.661 raeburn 11386: }
1.1075.2.35 raeburn 11387: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11388: my $extendedsubdir = $dirpath.'/'.$subdir;
11389: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11390: my $result =
1.1075.2.35 raeburn 11391: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11392: if ($result !~ m|^/uploaded/|) {
11393: $output .= '<span class="LC_error">'
11394: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11395: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11396: .'</span><br />';
11397: next;
11398: } else {
11399: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11400: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11401: if ($context eq 'syllabus') {
11402: &Apache::lonnet::make_public_indefinitely($result);
11403: }
1.987 raeburn 11404: }
1.661 raeburn 11405: } else {
11406: # Save the file
11407: my $target = $env{'form.embedded_item_'.$i};
11408: my $fullpath = $dir_root.$dirpath.'/'.$path;
11409: my $dest = $fullpath.$fname;
11410: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11411: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11412: my $count;
11413: my $filepath = $dir_root;
1.1027 raeburn 11414: foreach my $subdir (@parts) {
11415: $filepath .= "/$subdir";
11416: if (!-e $filepath) {
1.661 raeburn 11417: mkdir($filepath,0770);
11418: }
11419: }
11420: my $fh;
11421: if (!open($fh,'>'.$dest)) {
11422: &Apache::lonnet::logthis('Failed to create '.$dest);
11423: $output .= '<span class="LC_error">'.
1.1071 raeburn 11424: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11425: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11426: '</span><br />';
11427: } else {
11428: if (!print $fh $env{'form.embedded_item_'.$i}) {
11429: &Apache::lonnet::logthis('Failed to write to '.$dest);
11430: $output .= '<span class="LC_error">'.
1.1071 raeburn 11431: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11432: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11433: '</span><br />';
11434: } else {
1.987 raeburn 11435: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11436: $url.'</span>').'<br />';
11437: unless ($context eq 'testbank') {
11438: $footer .= &mt('View embedded file: [_1]',
11439: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11440: }
11441: }
11442: close($fh);
11443: }
11444: }
11445: if ($env{'form.embedded_ref_'.$i}) {
11446: $pathchange{$i} = 1;
11447: }
11448: }
11449: if ($output) {
11450: $output = '<p>'.$output.'</p>';
11451: }
11452: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11453: $returnflag = 'ok';
1.1071 raeburn 11454: my $numpathchgs = scalar(keys(%pathchange));
11455: if ($numpathchgs > 0) {
1.987 raeburn 11456: if ($context eq 'portfolio') {
11457: $output .= '<p>'.&mt('or').'</p>';
11458: } elsif ($context eq 'testbank') {
1.1071 raeburn 11459: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11460: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11461: $returnflag = 'modify_orightml';
11462: }
11463: }
1.1071 raeburn 11464: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11465: }
11466:
11467: sub modify_html_form {
11468: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11469: my $end = 0;
11470: my $modifyform;
11471: if ($context eq 'upload_embedded') {
11472: return unless (ref($pathchange) eq 'HASH');
11473: if ($env{'form.number_embedded_items'}) {
11474: $end += $env{'form.number_embedded_items'};
11475: }
11476: if ($env{'form.number_pathchange_items'}) {
11477: $end += $env{'form.number_pathchange_items'};
11478: }
11479: if ($end) {
11480: for (my $i=0; $i<$end; $i++) {
11481: if ($i < $env{'form.number_embedded_items'}) {
11482: next unless($pathchange->{$i});
11483: }
11484: $modifyform .=
11485: &start_data_table_row().
11486: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11487: 'checked="checked" /></td>'.
11488: '<td>'.$env{'form.embedded_ref_'.$i}.
11489: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11490: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11491: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11492: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11493: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11494: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11495: '<td>'.$env{'form.embedded_orig_'.$i}.
11496: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11497: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11498: &end_data_table_row();
1.1071 raeburn 11499: }
1.987 raeburn 11500: }
11501: } else {
11502: $modifyform = $pathchgtable;
11503: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11504: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11505: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11506: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11507: }
11508: }
11509: if ($modifyform) {
1.1071 raeburn 11510: if ($actionurl eq '/adm/dependencies') {
11511: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11512: }
1.987 raeburn 11513: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11514: '<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".
11515: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11516: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11517: '</ol></p>'."\n".'<p>'.
11518: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11519: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11520: &start_data_table()."\n".
11521: &start_data_table_header_row().
11522: '<th>'.&mt('Change?').'</th>'.
11523: '<th>'.&mt('Current reference').'</th>'.
11524: '<th>'.&mt('Required reference').'</th>'.
11525: &end_data_table_header_row()."\n".
11526: $modifyform.
11527: &end_data_table().'<br />'."\n".$hiddenstate.
11528: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11529: '</form>'."\n";
11530: }
11531: return;
11532: }
11533:
11534: sub modify_html_refs {
1.1075.2.35 raeburn 11535: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11536: my $container;
11537: if ($context eq 'portfolio') {
11538: $container = $env{'form.container'};
11539: } elsif ($context eq 'coursedoc') {
11540: $container = $env{'form.primaryurl'};
1.1071 raeburn 11541: } elsif ($context eq 'manage_dependencies') {
11542: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11543: $container = "/$container";
1.1075.2.35 raeburn 11544: } elsif ($context eq 'syllabus') {
11545: $container = $url;
1.987 raeburn 11546: } else {
1.1027 raeburn 11547: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11548: }
11549: my (%allfiles,%codebase,$output,$content);
11550: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11551: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11552: if (wantarray) {
11553: return ('',0,0);
11554: } else {
11555: return;
11556: }
11557: }
11558: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11559: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11560: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11561: if (wantarray) {
11562: return ('',0,0);
11563: } else {
11564: return;
11565: }
11566: }
1.987 raeburn 11567: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11568: if ($content eq '-1') {
11569: if (wantarray) {
11570: return ('',0,0);
11571: } else {
11572: return;
11573: }
11574: }
1.987 raeburn 11575: } else {
1.1071 raeburn 11576: unless ($container =~ /^\Q$dir_root\E/) {
11577: if (wantarray) {
11578: return ('',0,0);
11579: } else {
11580: return;
11581: }
11582: }
1.1075.2.128 raeburn 11583: if (open(my $fh,'<',$container)) {
1.987 raeburn 11584: $content = join('', <$fh>);
11585: close($fh);
11586: } else {
1.1071 raeburn 11587: if (wantarray) {
11588: return ('',0,0);
11589: } else {
11590: return;
11591: }
1.987 raeburn 11592: }
11593: }
11594: my ($count,$codebasecount) = (0,0);
11595: my $mm = new File::MMagic;
11596: my $mime_type = $mm->checktype_contents($content);
11597: if ($mime_type eq 'text/html') {
11598: my $parse_result =
11599: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11600: \%codebase,\$content);
11601: if ($parse_result eq 'ok') {
11602: foreach my $i (@changes) {
11603: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11604: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11605: if ($allfiles{$ref}) {
11606: my $newname = $orig;
11607: my ($attrib_regexp,$codebase);
1.1006 raeburn 11608: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11609: if ($attrib_regexp =~ /:/) {
11610: $attrib_regexp =~ s/\:/|/g;
11611: }
11612: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11613: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11614: $count += $numchg;
1.1075.2.35 raeburn 11615: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11616: delete($allfiles{$ref});
1.987 raeburn 11617: }
11618: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11619: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11620: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11621: $codebasecount ++;
11622: }
11623: }
11624: }
1.1075.2.35 raeburn 11625: my $skiprewrites;
1.987 raeburn 11626: if ($count || $codebasecount) {
11627: my $saveresult;
1.1071 raeburn 11628: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11629: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11630: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11631: if ($url eq $container) {
11632: my ($fname) = ($container =~ m{/([^/]+)$});
11633: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11634: $count,'<span class="LC_filename">'.
1.1071 raeburn 11635: $fname.'</span>').'</p>';
1.987 raeburn 11636: } else {
11637: $output = '<p class="LC_error">'.
11638: &mt('Error: update failed for: [_1].',
11639: '<span class="LC_filename">'.
11640: $container.'</span>').'</p>';
11641: }
1.1075.2.35 raeburn 11642: if ($context eq 'syllabus') {
11643: unless ($saveresult eq 'ok') {
11644: $skiprewrites = 1;
11645: }
11646: }
1.987 raeburn 11647: } else {
1.1075.2.128 raeburn 11648: if (open(my $fh,'>',$container)) {
1.987 raeburn 11649: print $fh $content;
11650: close($fh);
11651: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11652: $count,'<span class="LC_filename">'.
11653: $container.'</span>').'</p>';
1.661 raeburn 11654: } else {
1.987 raeburn 11655: $output = '<p class="LC_error">'.
11656: &mt('Error: could not update [_1].',
11657: '<span class="LC_filename">'.
11658: $container.'</span>').'</p>';
1.661 raeburn 11659: }
11660: }
11661: }
1.1075.2.35 raeburn 11662: if (($context eq 'syllabus') && (!$skiprewrites)) {
11663: my ($actionurl,$state);
11664: $actionurl = "/public/$udom/$uname/syllabus";
11665: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11666: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11667: \%codebase,
11668: {'context' => 'rewrites',
11669: 'ignore_remote_references' => 1,});
11670: if (ref($mapping) eq 'HASH') {
11671: my $rewrites = 0;
11672: foreach my $key (keys(%{$mapping})) {
11673: next if ($key =~ m{^https?://});
11674: my $ref = $mapping->{$key};
11675: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11676: my $attrib;
11677: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11678: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11679: }
11680: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11681: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11682: $rewrites += $numchg;
11683: }
11684: }
11685: if ($rewrites) {
11686: my $saveresult;
11687: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11688: if ($url eq $container) {
11689: my ($fname) = ($container =~ m{/([^/]+)$});
11690: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11691: $count,'<span class="LC_filename">'.
11692: $fname.'</span>').'</p>';
11693: } else {
11694: $output .= '<p class="LC_error">'.
11695: &mt('Error: could not update links in [_1].',
11696: '<span class="LC_filename">'.
11697: $container.'</span>').'</p>';
11698:
11699: }
11700: }
11701: }
11702: }
1.987 raeburn 11703: } else {
11704: &logthis('Failed to parse '.$container.
11705: ' to modify references: '.$parse_result);
1.661 raeburn 11706: }
11707: }
1.1071 raeburn 11708: if (wantarray) {
11709: return ($output,$count,$codebasecount);
11710: } else {
11711: return $output;
11712: }
1.661 raeburn 11713: }
11714:
11715: sub check_for_existing {
11716: my ($path,$fname,$element) = @_;
11717: my ($state,$msg);
11718: if (-d $path.'/'.$fname) {
11719: $state = 'exists';
11720: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11721: } elsif (-e $path.'/'.$fname) {
11722: $state = 'exists';
11723: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11724: }
11725: if ($state eq 'exists') {
11726: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11727: }
11728: return ($state,$msg);
11729: }
11730:
11731: sub check_for_upload {
11732: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11733: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11734: my $filesize = length($env{'form.'.$element});
11735: if (!$filesize) {
11736: my $msg = '<span class="LC_error">'.
11737: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11738: '<span class="LC_filename">'.$fname.'</span>',
11739: $filesize).'<br />'.
1.1007 raeburn 11740: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11741: '</span>';
11742: return ('zero_bytes',$msg);
11743: }
11744: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11745: my $getpropath = 1;
1.1021 raeburn 11746: my ($dirlistref,$listerror) =
11747: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11748: my $found_file = 0;
11749: my $locked_file = 0;
1.991 raeburn 11750: my @lockers;
11751: my $navmap;
11752: if ($env{'request.course.id'}) {
11753: $navmap = Apache::lonnavmaps::navmap->new();
11754: }
1.1021 raeburn 11755: if (ref($dirlistref) eq 'ARRAY') {
11756: foreach my $line (@{$dirlistref}) {
11757: my ($file_name,$rest)=split(/\&/,$line,2);
11758: if ($file_name eq $fname){
11759: $file_name = $path.$file_name;
11760: if ($group ne '') {
11761: $file_name = $group.$file_name;
11762: }
11763: $found_file = 1;
11764: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11765: foreach my $lock (@lockers) {
11766: if (ref($lock) eq 'ARRAY') {
11767: my ($symb,$crsid) = @{$lock};
11768: if ($crsid eq $env{'request.course.id'}) {
11769: if (ref($navmap)) {
11770: my $res = $navmap->getBySymb($symb);
11771: foreach my $part (@{$res->parts()}) {
11772: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11773: unless (($slot_status == $res->RESERVED) ||
11774: ($slot_status == $res->RESERVED_LOCATION)) {
11775: $locked_file = 1;
11776: }
1.991 raeburn 11777: }
1.1021 raeburn 11778: } else {
11779: $locked_file = 1;
1.991 raeburn 11780: }
11781: } else {
11782: $locked_file = 1;
11783: }
11784: }
1.1021 raeburn 11785: }
11786: } else {
11787: my @info = split(/\&/,$rest);
11788: my $currsize = $info[6]/1000;
11789: if ($currsize < $filesize) {
11790: my $extra = $filesize - $currsize;
11791: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11792: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11793: &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 11794: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11795: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11796: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11797: return ('will_exceed_quota',$msg);
11798: }
1.984 raeburn 11799: }
11800: }
1.661 raeburn 11801: }
11802: }
11803: }
11804: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11805: my $msg = '<p class="LC_warning">'.
11806: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11807: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11808: return ('will_exceed_quota',$msg);
11809: } elsif ($found_file) {
11810: if ($locked_file) {
1.1075.2.69 raeburn 11811: my $msg = '<p class="LC_warning">';
1.661 raeburn 11812: $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 11813: $msg .= '</p>';
1.661 raeburn 11814: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11815: return ('file_locked',$msg);
11816: } else {
1.1075.2.69 raeburn 11817: my $msg = '<p class="LC_error">';
1.984 raeburn 11818: $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 11819: $msg .= '</p>';
1.984 raeburn 11820: return ('existingfile',$msg);
1.661 raeburn 11821: }
11822: }
11823: }
11824:
1.987 raeburn 11825: sub check_for_traversal {
11826: my ($path,$url,$toplevel) = @_;
11827: my @parts=split(/\//,$path);
11828: my $cleanpath;
11829: my $fullpath = $url;
11830: for (my $i=0;$i<@parts;$i++) {
11831: next if ($parts[$i] eq '.');
11832: if ($parts[$i] eq '..') {
11833: $fullpath =~ s{([^/]+/)$}{};
11834: } else {
11835: $fullpath .= $parts[$i].'/';
11836: }
11837: }
11838: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11839: $cleanpath = $1;
11840: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11841: my $curr_toprel = $1;
11842: my @parts = split(/\//,$curr_toprel);
11843: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11844: my @urlparts = split(/\//,$url_toprel);
11845: my $doubledots;
11846: my $startdiff = -1;
11847: for (my $i=0; $i<@urlparts; $i++) {
11848: if ($startdiff == -1) {
11849: unless ($urlparts[$i] eq $parts[$i]) {
11850: $startdiff = $i;
11851: $doubledots .= '../';
11852: }
11853: } else {
11854: $doubledots .= '../';
11855: }
11856: }
11857: if ($startdiff > -1) {
11858: $cleanpath = $doubledots;
11859: for (my $i=$startdiff; $i<@parts; $i++) {
11860: $cleanpath .= $parts[$i].'/';
11861: }
11862: }
11863: }
11864: $cleanpath =~ s{(/)$}{};
11865: return $cleanpath;
11866: }
1.31 albertel 11867:
1.1053 raeburn 11868: sub is_archive_file {
11869: my ($mimetype) = @_;
11870: if (($mimetype eq 'application/octet-stream') ||
11871: ($mimetype eq 'application/x-stuffit') ||
11872: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11873: return 1;
11874: }
11875: return;
11876: }
11877:
11878: sub decompress_form {
1.1065 raeburn 11879: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11880: my %lt = &Apache::lonlocal::texthash (
11881: this => 'This file is an archive file.',
1.1067 raeburn 11882: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11883: itsc => 'Its contents are as follows:',
1.1053 raeburn 11884: youm => 'You may wish to extract its contents.',
11885: extr => 'Extract contents',
1.1067 raeburn 11886: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11887: proa => 'Process automatically?',
1.1053 raeburn 11888: yes => 'Yes',
11889: no => 'No',
1.1067 raeburn 11890: fold => 'Title for folder containing movie',
11891: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11892: );
1.1065 raeburn 11893: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11894: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11895: my $info = &list_archive_contents($fileloc,\@paths);
11896: if (@paths) {
11897: foreach my $path (@paths) {
11898: $path =~ s{^/}{};
1.1067 raeburn 11899: if ($path =~ m{^([^/]+)/$}) {
11900: $topdir = $1;
11901: }
1.1065 raeburn 11902: if ($path =~ m{^([^/]+)/}) {
11903: $toplevel{$1} = $path;
11904: } else {
11905: $toplevel{$path} = $path;
11906: }
11907: }
11908: }
1.1067 raeburn 11909: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11910: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11911: "$topdir/media/",
11912: "$topdir/media/$topdir.mp4",
11913: "$topdir/media/FirstFrame.png",
11914: "$topdir/media/player.swf",
11915: "$topdir/media/swfobject.js",
11916: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11917: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11918: "$topdir/$topdir.mp4",
11919: "$topdir/$topdir\_config.xml",
11920: "$topdir/$topdir\_controller.swf",
11921: "$topdir/$topdir\_embed.css",
11922: "$topdir/$topdir\_First_Frame.png",
11923: "$topdir/$topdir\_player.html",
11924: "$topdir/$topdir\_Thumbnails.png",
11925: "$topdir/playerProductInstall.swf",
11926: "$topdir/scripts/",
11927: "$topdir/scripts/config_xml.js",
11928: "$topdir/scripts/handlebars.js",
11929: "$topdir/scripts/jquery-1.7.1.min.js",
11930: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11931: "$topdir/scripts/modernizr.js",
11932: "$topdir/scripts/player-min.js",
11933: "$topdir/scripts/swfobject.js",
11934: "$topdir/skins/",
11935: "$topdir/skins/configuration_express.xml",
11936: "$topdir/skins/express_show/",
11937: "$topdir/skins/express_show/player-min.css",
11938: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11939: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11940: "$topdir/$topdir.mp4",
11941: "$topdir/$topdir\_config.xml",
11942: "$topdir/$topdir\_controller.swf",
11943: "$topdir/$topdir\_embed.css",
11944: "$topdir/$topdir\_First_Frame.png",
11945: "$topdir/$topdir\_player.html",
11946: "$topdir/$topdir\_Thumbnails.png",
11947: "$topdir/playerProductInstall.swf",
11948: "$topdir/scripts/",
11949: "$topdir/scripts/config_xml.js",
11950: "$topdir/scripts/techsmith-smart-player.min.js",
11951: "$topdir/skins/",
11952: "$topdir/skins/configuration_express.xml",
11953: "$topdir/skins/express_show/",
11954: "$topdir/skins/express_show/spritesheet.min.css",
11955: "$topdir/skins/express_show/spritesheet.png",
11956: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 11957: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11958: if (@diffs == 0) {
1.1075.2.59 raeburn 11959: $is_camtasia = 6;
11960: } else {
1.1075.2.81 raeburn 11961: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 11962: if (@diffs == 0) {
11963: $is_camtasia = 8;
1.1075.2.81 raeburn 11964: } else {
11965: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11966: if (@diffs == 0) {
11967: $is_camtasia = 8;
11968: }
1.1075.2.59 raeburn 11969: }
1.1067 raeburn 11970: }
11971: }
11972: my $output;
11973: if ($is_camtasia) {
11974: $output = <<"ENDCAM";
11975: <script type="text/javascript" language="Javascript">
11976: // <![CDATA[
11977:
11978: function camtasiaToggle() {
11979: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11980: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11981: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11982: document.getElementById('camtasia_titles').style.display='block';
11983: } else {
11984: document.getElementById('camtasia_titles').style.display='none';
11985: }
11986: }
11987: }
11988: return;
11989: }
11990:
11991: // ]]>
11992: </script>
11993: <p>$lt{'camt'}</p>
11994: ENDCAM
1.1065 raeburn 11995: } else {
1.1067 raeburn 11996: $output = '<p>'.$lt{'this'};
11997: if ($info eq '') {
11998: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11999: } else {
12000: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12001: '<div><pre>'.$info.'</pre></div>';
12002: }
1.1065 raeburn 12003: }
1.1067 raeburn 12004: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12005: my $duplicates;
12006: my $num = 0;
12007: if (ref($dirlist) eq 'ARRAY') {
12008: foreach my $item (@{$dirlist}) {
12009: if (ref($item) eq 'ARRAY') {
12010: if (exists($toplevel{$item->[0]})) {
12011: $duplicates .=
12012: &start_data_table_row().
12013: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12014: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12015: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12016: 'value="1" />'.&mt('Yes').'</label>'.
12017: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12018: '<td>'.$item->[0].'</td>';
12019: if ($item->[2]) {
12020: $duplicates .= '<td>'.&mt('Directory').'</td>';
12021: } else {
12022: $duplicates .= '<td>'.&mt('File').'</td>';
12023: }
12024: $duplicates .= '<td>'.$item->[3].'</td>'.
12025: '<td>'.
12026: &Apache::lonlocal::locallocaltime($item->[4]).
12027: '</td>'.
12028: &end_data_table_row();
12029: $num ++;
12030: }
12031: }
12032: }
12033: }
12034: my $itemcount;
12035: if (@paths > 0) {
12036: $itemcount = scalar(@paths);
12037: } else {
12038: $itemcount = 1;
12039: }
1.1067 raeburn 12040: if ($is_camtasia) {
12041: $output .= $lt{'auto'}.'<br />'.
12042: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 12043: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12044: $lt{'yes'}.'</label> <label>'.
12045: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12046: $lt{'no'}.'</label></span><br />'.
12047: '<div id="camtasia_titles" style="display:block">'.
12048: &Apache::lonhtmlcommon::start_pick_box().
12049: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12050: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12051: &Apache::lonhtmlcommon::row_closure().
12052: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12053: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12054: &Apache::lonhtmlcommon::row_closure(1).
12055: &Apache::lonhtmlcommon::end_pick_box().
12056: '</div>';
12057: }
1.1065 raeburn 12058: $output .=
12059: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12060: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12061: "\n";
1.1065 raeburn 12062: if ($duplicates ne '') {
12063: $output .= '<p><span class="LC_warning">'.
12064: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12065: &start_data_table().
12066: &start_data_table_header_row().
12067: '<th>'.&mt('Overwrite?').'</th>'.
12068: '<th>'.&mt('Name').'</th>'.
12069: '<th>'.&mt('Type').'</th>'.
12070: '<th>'.&mt('Size').'</th>'.
12071: '<th>'.&mt('Last modified').'</th>'.
12072: &end_data_table_header_row().
12073: $duplicates.
12074: &end_data_table().
12075: '</p>';
12076: }
1.1067 raeburn 12077: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12078: if (ref($hiddenelements) eq 'HASH') {
12079: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12080: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12081: }
12082: }
12083: $output .= <<"END";
1.1067 raeburn 12084: <br />
1.1053 raeburn 12085: <input type="submit" name="decompress" value="$lt{'extr'}" />
12086: </form>
12087: $noextract
12088: END
12089: return $output;
12090: }
12091:
1.1065 raeburn 12092: sub decompression_utility {
12093: my ($program) = @_;
12094: my @utilities = ('tar','gunzip','bunzip2','unzip');
12095: my $location;
12096: if (grep(/^\Q$program\E$/,@utilities)) {
12097: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12098: '/usr/sbin/') {
12099: if (-x $dir.$program) {
12100: $location = $dir.$program;
12101: last;
12102: }
12103: }
12104: }
12105: return $location;
12106: }
12107:
12108: sub list_archive_contents {
12109: my ($file,$pathsref) = @_;
12110: my (@cmd,$output);
12111: my $needsregexp;
12112: if ($file =~ /\.zip$/) {
12113: @cmd = (&decompression_utility('unzip'),"-l");
12114: $needsregexp = 1;
12115: } elsif (($file =~ m/\.tar\.gz$/) ||
12116: ($file =~ /\.tgz$/)) {
12117: @cmd = (&decompression_utility('tar'),"-ztf");
12118: } elsif ($file =~ /\.tar\.bz2$/) {
12119: @cmd = (&decompression_utility('tar'),"-jtf");
12120: } elsif ($file =~ m|\.tar$|) {
12121: @cmd = (&decompression_utility('tar'),"-tf");
12122: }
12123: if (@cmd) {
12124: undef($!);
12125: undef($@);
12126: if (open(my $fh,"-|", @cmd, $file)) {
12127: while (my $line = <$fh>) {
12128: $output .= $line;
12129: chomp($line);
12130: my $item;
12131: if ($needsregexp) {
12132: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12133: } else {
12134: $item = $line;
12135: }
12136: if ($item ne '') {
12137: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12138: push(@{$pathsref},$item);
12139: }
12140: }
12141: }
12142: close($fh);
12143: }
12144: }
12145: return $output;
12146: }
12147:
1.1053 raeburn 12148: sub decompress_uploaded_file {
12149: my ($file,$dir) = @_;
12150: &Apache::lonnet::appenv({'cgi.file' => $file});
12151: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12152: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12153: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12154: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12155: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12156: my $decompressed = $env{'cgi.decompressed'};
12157: &Apache::lonnet::delenv('cgi.file');
12158: &Apache::lonnet::delenv('cgi.dir');
12159: &Apache::lonnet::delenv('cgi.decompressed');
12160: return ($decompressed,$result);
12161: }
12162:
1.1055 raeburn 12163: sub process_decompression {
12164: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128 raeburn 12165: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12166: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12167: &mt('Unexpected file path.').'</p>'."\n";
12168: }
12169: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12170: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12171: &mt('Unexpected course context.').'</p>'."\n";
12172: }
12173: unless ($file eq &Apache::lonnet::clean_filename($file)) {
12174: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12175: &mt('Filename contained unexpected characters.').'</p>'."\n";
12176: }
1.1055 raeburn 12177: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12178: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12179: $error = &mt('Filename not a supported archive file type.').
12180: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12181: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12182: } else {
12183: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12184: if ($docuhome eq 'no_host') {
12185: $error = &mt('Could not determine home server for course.');
12186: } else {
12187: my @ids=&Apache::lonnet::current_machine_ids();
12188: my $currdir = "$dir_root/$destination";
12189: if (grep(/^\Q$docuhome\E$/,@ids)) {
12190: $dir = &LONCAPA::propath($docudom,$docuname).
12191: "$dir_root/$destination";
12192: } else {
12193: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12194: "$dir_root/$docudom/$docuname/$destination";
12195: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12196: $error = &mt('Archive file not found.');
12197: }
12198: }
1.1065 raeburn 12199: my (@to_overwrite,@to_skip);
12200: if ($env{'form.archive_overwrite_total'} > 0) {
12201: my $total = $env{'form.archive_overwrite_total'};
12202: for (my $i=0; $i<$total; $i++) {
12203: if ($env{'form.archive_overwrite_'.$i} == 1) {
12204: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12205: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12206: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12207: }
12208: }
12209: }
12210: my $numskip = scalar(@to_skip);
1.1075.2.128 raeburn 12211: my $numoverwrite = scalar(@to_overwrite);
12212: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12213: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12214: } elsif ($dir eq '') {
1.1055 raeburn 12215: $error = &mt('Directory containing archive file unavailable.');
12216: } elsif (!$error) {
1.1065 raeburn 12217: my ($decompressed,$display);
1.1075.2.128 raeburn 12218: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12219: my $tempdir = time.'_'.$$.int(rand(10000));
12220: mkdir("$dir/$tempdir",0755);
1.1075.2.128 raeburn 12221: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12222: ($decompressed,$display) =
12223: &decompress_uploaded_file($file,"$dir/$tempdir");
12224: foreach my $item (@to_skip) {
12225: if (($item ne '') && ($item !~ /\.\./)) {
12226: if (-f "$dir/$tempdir/$item") {
12227: unlink("$dir/$tempdir/$item");
12228: } elsif (-d "$dir/$tempdir/$item") {
12229: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
12230: }
12231: }
12232: }
12233: foreach my $item (@to_overwrite) {
12234: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12235: if (($item ne '') && ($item !~ /\.\./)) {
12236: if (-f "$dir/$item") {
12237: unlink("$dir/$item");
12238: } elsif (-d "$dir/$item") {
12239: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
12240: }
12241: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12242: }
1.1065 raeburn 12243: }
12244: }
1.1075.2.128 raeburn 12245: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
12246: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
12247: }
1.1065 raeburn 12248: }
12249: } else {
12250: ($decompressed,$display) =
12251: &decompress_uploaded_file($file,$dir);
12252: }
1.1055 raeburn 12253: if ($decompressed eq 'ok') {
1.1065 raeburn 12254: $output = '<p class="LC_info">'.
12255: &mt('Files extracted successfully from archive.').
12256: '</p>'."\n";
1.1055 raeburn 12257: my ($warning,$result,@contents);
12258: my ($newdirlistref,$newlisterror) =
12259: &Apache::lonnet::dirlist($currdir,$docudom,
12260: $docuname,1);
12261: my (%is_dir,%changes,@newitems);
12262: my $dirptr = 16384;
1.1065 raeburn 12263: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12264: foreach my $dir_line (@{$newdirlistref}) {
12265: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128 raeburn 12266: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12267: push(@newitems,$item);
12268: if ($dirptr&$testdir) {
12269: $is_dir{$item} = 1;
12270: }
12271: $changes{$item} = 1;
12272: }
12273: }
12274: }
12275: if (keys(%changes) > 0) {
12276: foreach my $item (sort(@newitems)) {
12277: if ($changes{$item}) {
12278: push(@contents,$item);
12279: }
12280: }
12281: }
12282: if (@contents > 0) {
1.1067 raeburn 12283: my $wantform;
12284: unless ($env{'form.autoextract_camtasia'}) {
12285: $wantform = 1;
12286: }
1.1056 raeburn 12287: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12288: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12289: $currdir,\%is_dir,
12290: \%children,\%parent,
1.1056 raeburn 12291: \@contents,\%dirorder,
12292: \%titles,$wantform);
1.1055 raeburn 12293: if ($datatable ne '') {
12294: $output .= &archive_options_form('decompressed',$datatable,
12295: $count,$hiddenelem);
1.1065 raeburn 12296: my $startcount = 6;
1.1055 raeburn 12297: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12298: \%titles,\%children);
1.1055 raeburn 12299: }
1.1067 raeburn 12300: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12301: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12302: my %displayed;
12303: my $total = 1;
12304: $env{'form.archive_directory'} = [];
12305: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12306: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12307: $path =~ s{/$}{};
12308: my $item;
12309: if ($path ne '') {
12310: $item = "$path/$titles{$i}";
12311: } else {
12312: $item = $titles{$i};
12313: }
12314: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12315: if ($item eq $contents[0]) {
12316: push(@{$env{'form.archive_directory'}},$i);
12317: $env{'form.archive_'.$i} = 'display';
12318: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12319: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12320: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12321: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12322: $env{'form.archive_'.$i} = 'display';
12323: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12324: $displayed{'web'} = $i;
12325: } else {
1.1075.2.59 raeburn 12326: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12327: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12328: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12329: push(@{$env{'form.archive_directory'}},$i);
12330: }
12331: $env{'form.archive_'.$i} = 'dependency';
12332: }
12333: $total ++;
12334: }
12335: for (my $i=1; $i<$total; $i++) {
12336: next if ($i == $displayed{'web'});
12337: next if ($i == $displayed{'folder'});
12338: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12339: }
12340: $env{'form.phase'} = 'decompress_cleanup';
12341: $env{'form.archivedelete'} = 1;
12342: $env{'form.archive_count'} = $total-1;
12343: $output .=
12344: &process_extracted_files('coursedocs',$docudom,
12345: $docuname,$destination,
12346: $dir_root,$hiddenelem);
12347: }
1.1055 raeburn 12348: } else {
12349: $warning = &mt('No new items extracted from archive file.');
12350: }
12351: } else {
12352: $output = $display;
12353: $error = &mt('An error occurred during extraction from the archive file.');
12354: }
12355: }
12356: }
12357: }
12358: if ($error) {
12359: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12360: $error.'</p>'."\n";
12361: }
12362: if ($warning) {
12363: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12364: }
12365: return $output;
12366: }
12367:
12368: sub get_extracted {
1.1056 raeburn 12369: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12370: $titles,$wantform) = @_;
1.1055 raeburn 12371: my $count = 0;
12372: my $depth = 0;
12373: my $datatable;
1.1056 raeburn 12374: my @hierarchy;
1.1055 raeburn 12375: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12376: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12377: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12378: foreach my $item (@{$contents}) {
12379: $count ++;
1.1056 raeburn 12380: @{$dirorder->{$count}} = @hierarchy;
12381: $titles->{$count} = $item;
1.1055 raeburn 12382: &archive_hierarchy($depth,$count,$parent,$children);
12383: if ($wantform) {
12384: $datatable .= &archive_row($is_dir->{$item},$item,
12385: $currdir,$depth,$count);
12386: }
12387: if ($is_dir->{$item}) {
12388: $depth ++;
1.1056 raeburn 12389: push(@hierarchy,$count);
12390: $parent->{$depth} = $count;
1.1055 raeburn 12391: $datatable .=
12392: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12393: \$depth,\$count,\@hierarchy,$dirorder,
12394: $children,$parent,$titles,$wantform);
1.1055 raeburn 12395: $depth --;
1.1056 raeburn 12396: pop(@hierarchy);
1.1055 raeburn 12397: }
12398: }
12399: return ($count,$datatable);
12400: }
12401:
12402: sub recurse_extracted_archive {
1.1056 raeburn 12403: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12404: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12405: my $result='';
1.1056 raeburn 12406: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12407: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12408: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12409: return $result;
12410: }
12411: my $dirptr = 16384;
12412: my ($newdirlistref,$newlisterror) =
12413: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12414: if (ref($newdirlistref) eq 'ARRAY') {
12415: foreach my $dir_line (@{$newdirlistref}) {
12416: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12417: unless ($item =~ /^\.+$/) {
12418: $$count ++;
1.1056 raeburn 12419: @{$dirorder->{$$count}} = @{$hierarchy};
12420: $titles->{$$count} = $item;
1.1055 raeburn 12421: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12422:
1.1055 raeburn 12423: my $is_dir;
12424: if ($dirptr&$testdir) {
12425: $is_dir = 1;
12426: }
12427: if ($wantform) {
12428: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12429: }
12430: if ($is_dir) {
12431: $$depth ++;
1.1056 raeburn 12432: push(@{$hierarchy},$$count);
12433: $parent->{$$depth} = $$count;
1.1055 raeburn 12434: $result .=
12435: &recurse_extracted_archive("$currdir/$item",$docudom,
12436: $docuname,$depth,$count,
1.1056 raeburn 12437: $hierarchy,$dirorder,$children,
12438: $parent,$titles,$wantform);
1.1055 raeburn 12439: $$depth --;
1.1056 raeburn 12440: pop(@{$hierarchy});
1.1055 raeburn 12441: }
12442: }
12443: }
12444: }
12445: return $result;
12446: }
12447:
12448: sub archive_hierarchy {
12449: my ($depth,$count,$parent,$children) =@_;
12450: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12451: if (exists($parent->{$depth})) {
12452: $children->{$parent->{$depth}} .= $count.':';
12453: }
12454: }
12455: return;
12456: }
12457:
12458: sub archive_row {
12459: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12460: my ($name) = ($item =~ m{([^/]+)$});
12461: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12462: 'display' => 'Add as file',
1.1055 raeburn 12463: 'dependency' => 'Include as dependency',
12464: 'discard' => 'Discard',
12465: );
12466: if ($is_dir) {
1.1059 raeburn 12467: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12468: }
1.1056 raeburn 12469: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12470: my $offset = 0;
1.1055 raeburn 12471: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12472: $offset ++;
1.1065 raeburn 12473: if ($action ne 'display') {
12474: $offset ++;
12475: }
1.1055 raeburn 12476: $output .= '<td><span class="LC_nobreak">'.
12477: '<label><input type="radio" name="archive_'.$count.
12478: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12479: my $text = $choices{$action};
12480: if ($is_dir) {
12481: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12482: if ($action eq 'display') {
1.1059 raeburn 12483: $text = &mt('Add as folder');
1.1055 raeburn 12484: }
1.1056 raeburn 12485: } else {
12486: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12487:
12488: }
12489: $output .= ' /> '.$choices{$action}.'</label></span>';
12490: if ($action eq 'dependency') {
12491: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12492: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12493: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12494: '<option value=""></option>'."\n".
12495: '</select>'."\n".
12496: '</div>';
1.1059 raeburn 12497: } elsif ($action eq 'display') {
12498: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12499: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12500: '</div>';
1.1055 raeburn 12501: }
1.1056 raeburn 12502: $output .= '</td>';
1.1055 raeburn 12503: }
12504: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12505: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12506: for (my $i=0; $i<$depth; $i++) {
12507: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12508: }
12509: if ($is_dir) {
12510: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12511: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12512: } else {
12513: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12514: }
12515: $output .= ' '.$name.'</td>'."\n".
12516: &end_data_table_row();
12517: return $output;
12518: }
12519:
12520: sub archive_options_form {
1.1065 raeburn 12521: my ($form,$display,$count,$hiddenelem) = @_;
12522: my %lt = &Apache::lonlocal::texthash(
12523: perm => 'Permanently remove archive file?',
12524: hows => 'How should each extracted item be incorporated in the course?',
12525: cont => 'Content actions for all',
12526: addf => 'Add as folder/file',
12527: incd => 'Include as dependency for a displayed file',
12528: disc => 'Discard',
12529: no => 'No',
12530: yes => 'Yes',
12531: save => 'Save',
12532: );
12533: my $output = <<"END";
12534: <form name="$form" method="post" action="">
12535: <p><span class="LC_nobreak">$lt{'perm'}
12536: <label>
12537: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12538: </label>
12539:
12540: <label>
12541: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12542: </span>
12543: </p>
12544: <input type="hidden" name="phase" value="decompress_cleanup" />
12545: <br />$lt{'hows'}
12546: <div class="LC_columnSection">
12547: <fieldset>
12548: <legend>$lt{'cont'}</legend>
12549: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12550: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12551: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12552: </fieldset>
12553: </div>
12554: END
12555: return $output.
1.1055 raeburn 12556: &start_data_table()."\n".
1.1065 raeburn 12557: $display."\n".
1.1055 raeburn 12558: &end_data_table()."\n".
12559: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12560: $hiddenelem.
1.1065 raeburn 12561: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12562: '</form>';
12563: }
12564:
12565: sub archive_javascript {
1.1056 raeburn 12566: my ($startcount,$numitems,$titles,$children) = @_;
12567: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12568: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12569: my $scripttag = <<START;
12570: <script type="text/javascript">
12571: // <![CDATA[
12572:
12573: function checkAll(form,prefix) {
12574: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12575: for (var i=0; i < form.elements.length; i++) {
12576: var id = form.elements[i].id;
12577: if ((id != '') && (id != undefined)) {
12578: if (idstr.test(id)) {
12579: if (form.elements[i].type == 'radio') {
12580: form.elements[i].checked = true;
1.1056 raeburn 12581: var nostart = i-$startcount;
1.1059 raeburn 12582: var offset = nostart%7;
12583: var count = (nostart-offset)/7;
1.1056 raeburn 12584: dependencyCheck(form,count,offset);
1.1055 raeburn 12585: }
12586: }
12587: }
12588: }
12589: }
12590:
12591: function propagateCheck(form,count) {
12592: if (count > 0) {
1.1059 raeburn 12593: var startelement = $startcount + ((count-1) * 7);
12594: for (var j=1; j<6; j++) {
12595: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12596: var item = startelement + j;
12597: if (form.elements[item].type == 'radio') {
12598: if (form.elements[item].checked) {
12599: containerCheck(form,count,j);
12600: break;
12601: }
1.1055 raeburn 12602: }
12603: }
12604: }
12605: }
12606: }
12607:
12608: numitems = $numitems
1.1056 raeburn 12609: var titles = new Array(numitems);
12610: var parents = new Array(numitems);
1.1055 raeburn 12611: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12612: parents[i] = new Array;
1.1055 raeburn 12613: }
1.1059 raeburn 12614: var maintitle = '$maintitle';
1.1055 raeburn 12615:
12616: START
12617:
1.1056 raeburn 12618: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12619: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12620: for (my $i=0; $i<@contents; $i ++) {
12621: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12622: }
12623: }
12624:
1.1056 raeburn 12625: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12626: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12627: }
12628:
1.1055 raeburn 12629: $scripttag .= <<END;
12630:
12631: function containerCheck(form,count,offset) {
12632: if (count > 0) {
1.1056 raeburn 12633: dependencyCheck(form,count,offset);
1.1059 raeburn 12634: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12635: form.elements[item].checked = true;
12636: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12637: if (parents[count].length > 0) {
12638: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12639: containerCheck(form,parents[count][j],offset);
12640: }
12641: }
12642: }
12643: }
12644: }
12645:
12646: function dependencyCheck(form,count,offset) {
12647: if (count > 0) {
1.1059 raeburn 12648: var chosen = (offset+$startcount)+7*(count-1);
12649: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12650: var currtype = form.elements[depitem].type;
12651: if (form.elements[chosen].value == 'dependency') {
12652: document.getElementById('arc_depon_'+count).style.display='block';
12653: form.elements[depitem].options.length = 0;
12654: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12655: for (var i=1; i<=numitems; i++) {
12656: if (i == count) {
12657: continue;
12658: }
1.1059 raeburn 12659: var startelement = $startcount + (i-1) * 7;
12660: for (var j=1; j<6; j++) {
12661: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12662: var item = startelement + j;
12663: if (form.elements[item].type == 'radio') {
12664: if (form.elements[item].checked) {
12665: if (form.elements[item].value == 'display') {
12666: var n = form.elements[depitem].options.length;
12667: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12668: }
12669: }
12670: }
12671: }
12672: }
12673: }
12674: } else {
12675: document.getElementById('arc_depon_'+count).style.display='none';
12676: form.elements[depitem].options.length = 0;
12677: form.elements[depitem].options[0] = new Option('Select','',true,true);
12678: }
1.1059 raeburn 12679: titleCheck(form,count,offset);
1.1056 raeburn 12680: }
12681: }
12682:
12683: function propagateSelect(form,count,offset) {
12684: if (count > 0) {
1.1065 raeburn 12685: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12686: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12687: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12688: if (parents[count].length > 0) {
12689: for (var j=0; j<parents[count].length; j++) {
12690: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12691: }
12692: }
12693: }
12694: }
12695: }
1.1056 raeburn 12696:
12697: function containerSelect(form,count,offset,picked) {
12698: if (count > 0) {
1.1065 raeburn 12699: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12700: if (form.elements[item].type == 'radio') {
12701: if (form.elements[item].value == 'dependency') {
12702: if (form.elements[item+1].type == 'select-one') {
12703: for (var i=0; i<form.elements[item+1].options.length; i++) {
12704: if (form.elements[item+1].options[i].value == picked) {
12705: form.elements[item+1].selectedIndex = i;
12706: break;
12707: }
12708: }
12709: }
12710: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12711: if (parents[count].length > 0) {
12712: for (var j=0; j<parents[count].length; j++) {
12713: containerSelect(form,parents[count][j],offset,picked);
12714: }
12715: }
12716: }
12717: }
12718: }
12719: }
12720: }
12721:
1.1059 raeburn 12722: function titleCheck(form,count,offset) {
12723: if (count > 0) {
12724: var chosen = (offset+$startcount)+7*(count-1);
12725: var depitem = $startcount + ((count-1) * 7) + 2;
12726: var currtype = form.elements[depitem].type;
12727: if (form.elements[chosen].value == 'display') {
12728: document.getElementById('arc_title_'+count).style.display='block';
12729: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12730: document.getElementById('archive_title_'+count).value=maintitle;
12731: }
12732: } else {
12733: document.getElementById('arc_title_'+count).style.display='none';
12734: if (currtype == 'text') {
12735: document.getElementById('archive_title_'+count).value='';
12736: }
12737: }
12738: }
12739: return;
12740: }
12741:
1.1055 raeburn 12742: // ]]>
12743: </script>
12744: END
12745: return $scripttag;
12746: }
12747:
12748: sub process_extracted_files {
1.1067 raeburn 12749: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12750: my $numitems = $env{'form.archive_count'};
1.1075.2.128 raeburn 12751: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 12752: my @ids=&Apache::lonnet::current_machine_ids();
12753: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12754: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12755: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12756: if (grep(/^\Q$docuhome\E$/,@ids)) {
12757: $prefix = &LONCAPA::propath($docudom,$docuname);
12758: $pathtocheck = "$dir_root/$destination";
12759: $dir = $dir_root;
12760: $ishome = 1;
12761: } else {
12762: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12763: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128 raeburn 12764: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 12765: }
12766: my $currdir = "$dir_root/$destination";
12767: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12768: if ($env{'form.folderpath'}) {
12769: my @items = split('&',$env{'form.folderpath'});
12770: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12771: if ($env{'form.folderpath'} =~ /\:1$/) {
12772: $containers{'0'}='page';
12773: } else {
12774: $containers{'0'}='sequence';
12775: }
1.1055 raeburn 12776: }
12777: my @archdirs = &get_env_multiple('form.archive_directory');
12778: if ($numitems) {
12779: for (my $i=1; $i<=$numitems; $i++) {
12780: my $path = $env{'form.archive_content_'.$i};
12781: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12782: my $item = $1;
12783: $toplevelitems{$item} = $i;
12784: if (grep(/^\Q$i\E$/,@archdirs)) {
12785: $is_dir{$item} = 1;
12786: }
12787: }
12788: }
12789: }
1.1067 raeburn 12790: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12791: if (keys(%toplevelitems) > 0) {
12792: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12793: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12794: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12795: }
1.1066 raeburn 12796: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12797: if ($numitems) {
12798: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12799: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12800: my $path = $env{'form.archive_content_'.$i};
12801: if ($path =~ /^\Q$pathtocheck\E/) {
12802: if ($env{'form.archive_'.$i} eq 'discard') {
12803: if ($prefix ne '' && $path ne '') {
12804: if (-e $prefix.$path) {
1.1066 raeburn 12805: if ((@archdirs > 0) &&
12806: (grep(/^\Q$i\E$/,@archdirs))) {
12807: $todeletedir{$prefix.$path} = 1;
12808: } else {
12809: $todelete{$prefix.$path} = 1;
12810: }
1.1055 raeburn 12811: }
12812: }
12813: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12814: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12815: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12816: $docstitle = $env{'form.archive_title_'.$i};
12817: if ($docstitle eq '') {
12818: $docstitle = $title;
12819: }
1.1055 raeburn 12820: $outer = 0;
1.1056 raeburn 12821: if (ref($dirorder{$i}) eq 'ARRAY') {
12822: if (@{$dirorder{$i}} > 0) {
12823: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12824: if ($env{'form.archive_'.$item} eq 'display') {
12825: $outer = $item;
12826: last;
12827: }
12828: }
12829: }
12830: }
12831: my ($errtext,$fatal) =
12832: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12833: '/'.$folders{$outer}.'.'.
12834: $containers{$outer});
12835: next if ($fatal);
12836: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12837: if ($context eq 'coursedocs') {
1.1056 raeburn 12838: $mapinner{$i} = time;
1.1055 raeburn 12839: $folders{$i} = 'default_'.$mapinner{$i};
12840: $containers{$i} = 'sequence';
12841: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12842: $folders{$i}.'.'.$containers{$i};
12843: my $newidx = &LONCAPA::map::getresidx();
12844: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12845: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12846: push(@LONCAPA::map::order,$newidx);
12847: my ($outtext,$errtext) =
12848: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12849: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12850: '.'.$containers{$outer},1,1);
1.1056 raeburn 12851: $newseqid{$i} = $newidx;
1.1067 raeburn 12852: unless ($errtext) {
1.1075.2.128 raeburn 12853: $result .= '<li>'.&mt('Folder: [_1] added to course',
12854: &HTML::Entities::encode($docstitle,'<>&"'))..
12855: '</li>'."\n";
1.1067 raeburn 12856: }
1.1055 raeburn 12857: }
12858: } else {
12859: if ($context eq 'coursedocs') {
12860: my $newidx=&LONCAPA::map::getresidx();
12861: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12862: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12863: $title;
1.1075.2.128 raeburn 12864: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
12865: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12866: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 12867: }
1.1075.2.128 raeburn 12868: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12869: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12870: }
12871: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12872: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
12873: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
12874: unless ($ishome) {
12875: my $fetch = "$newdest{$i}/$title";
12876: $fetch =~ s/^\Q$prefix$dir\E//;
12877: $prompttofetch{$fetch} = 1;
12878: }
12879: }
12880: }
12881: $LONCAPA::map::resources[$newidx]=
12882: $docstitle.':'.$url.':false:normal:res';
12883: push(@LONCAPA::map::order, $newidx);
12884: my ($outtext,$errtext)=
12885: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12886: $docuname.'/'.$folders{$outer}.
12887: '.'.$containers{$outer},1,1);
12888: unless ($errtext) {
12889: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12890: $result .= '<li>'.&mt('File: [_1] added to course',
12891: &HTML::Entities::encode($docstitle,'<>&"')).
12892: '</li>'."\n";
12893: }
1.1067 raeburn 12894: }
1.1075.2.128 raeburn 12895: } else {
12896: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12897: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 12898: }
1.1055 raeburn 12899: }
12900: }
1.1075.2.11 raeburn 12901: }
12902: } else {
1.1075.2.128 raeburn 12903: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12904: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 12905: }
12906: }
12907: for (my $i=1; $i<=$numitems; $i++) {
12908: next unless ($env{'form.archive_'.$i} eq 'dependency');
12909: my $path = $env{'form.archive_content_'.$i};
12910: if ($path =~ /^\Q$pathtocheck\E/) {
12911: my ($title) = ($path =~ m{/([^/]+)$});
12912: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12913: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12914: if (ref($dirorder{$i}) eq 'ARRAY') {
12915: my ($itemidx,$fullpath,$relpath);
12916: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12917: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12918: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12919: if ($dirorder{$i}->[$j] eq $container) {
12920: $itemidx = $j;
1.1056 raeburn 12921: }
12922: }
1.1075.2.11 raeburn 12923: }
12924: if ($itemidx eq '') {
12925: $itemidx = 0;
12926: }
12927: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12928: if ($mapinner{$referrer{$i}}) {
12929: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12930: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12931: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12932: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12933: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12934: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12935: if (!-e $fullpath) {
12936: mkdir($fullpath,0755);
1.1056 raeburn 12937: }
12938: }
1.1075.2.11 raeburn 12939: } else {
12940: last;
1.1056 raeburn 12941: }
1.1075.2.11 raeburn 12942: }
12943: }
12944: } elsif ($newdest{$referrer{$i}}) {
12945: $fullpath = $newdest{$referrer{$i}};
12946: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12947: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12948: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12949: last;
12950: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12951: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12952: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12953: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12954: if (!-e $fullpath) {
12955: mkdir($fullpath,0755);
1.1056 raeburn 12956: }
12957: }
1.1075.2.11 raeburn 12958: } else {
12959: last;
1.1056 raeburn 12960: }
1.1075.2.11 raeburn 12961: }
12962: }
12963: if ($fullpath ne '') {
12964: if (-e "$prefix$path") {
1.1075.2.128 raeburn 12965: unless (rename("$prefix$path","$fullpath/$title")) {
12966: $warning .= &mt('Failed to rename dependency').'<br />';
12967: }
1.1075.2.11 raeburn 12968: }
12969: if (-e "$fullpath/$title") {
12970: my $showpath;
12971: if ($relpath ne '') {
12972: $showpath = "$relpath/$title";
12973: } else {
12974: $showpath = "/$title";
1.1056 raeburn 12975: }
1.1075.2.128 raeburn 12976: $result .= '<li>'.&mt('[_1] included as a dependency',
12977: &HTML::Entities::encode($showpath,'<>&"')).
12978: '</li>'."\n";
12979: unless ($ishome) {
12980: my $fetch = "$fullpath/$title";
12981: $fetch =~ s/^\Q$prefix$dir\E//;
12982: $prompttofetch{$fetch} = 1;
12983: }
1.1055 raeburn 12984: }
12985: }
12986: }
1.1075.2.11 raeburn 12987: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12988: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128 raeburn 12989: &HTML::Entities::encode($path,'<>&"'),
12990: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
12991: '<br />';
1.1055 raeburn 12992: }
12993: } else {
1.1075.2.128 raeburn 12994: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
12995: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 12996: }
12997: }
12998: if (keys(%todelete)) {
12999: foreach my $key (keys(%todelete)) {
13000: unlink($key);
1.1066 raeburn 13001: }
13002: }
13003: if (keys(%todeletedir)) {
13004: foreach my $key (keys(%todeletedir)) {
13005: rmdir($key);
13006: }
13007: }
13008: foreach my $dir (sort(keys(%is_dir))) {
13009: if (($pathtocheck ne '') && ($dir ne '')) {
13010: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13011: }
13012: }
1.1067 raeburn 13013: if ($result ne '') {
13014: $output .= '<ul>'."\n".
13015: $result."\n".
13016: '</ul>';
13017: }
13018: unless ($ishome) {
13019: my $replicationfail;
13020: foreach my $item (keys(%prompttofetch)) {
13021: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13022: unless ($fetchresult eq 'ok') {
13023: $replicationfail .= '<li>'.$item.'</li>'."\n";
13024: }
13025: }
13026: if ($replicationfail) {
13027: $output .= '<p class="LC_error">'.
13028: &mt('Course home server failed to retrieve:').'<ul>'.
13029: $replicationfail.
13030: '</ul></p>';
13031: }
13032: }
1.1055 raeburn 13033: } else {
13034: $warning = &mt('No items found in archive.');
13035: }
13036: if ($error) {
13037: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13038: $error.'</p>'."\n";
13039: }
13040: if ($warning) {
13041: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13042: }
13043: return $output;
13044: }
13045:
1.1066 raeburn 13046: sub cleanup_empty_dirs {
13047: my ($path) = @_;
13048: if (($path ne '') && (-d $path)) {
13049: if (opendir(my $dirh,$path)) {
13050: my @dircontents = grep(!/^\./,readdir($dirh));
13051: my $numitems = 0;
13052: foreach my $item (@dircontents) {
13053: if (-d "$path/$item") {
1.1075.2.28 raeburn 13054: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13055: if (-e "$path/$item") {
13056: $numitems ++;
13057: }
13058: } else {
13059: $numitems ++;
13060: }
13061: }
13062: if ($numitems == 0) {
13063: rmdir($path);
13064: }
13065: closedir($dirh);
13066: }
13067: }
13068: return;
13069: }
13070:
1.41 ng 13071: =pod
1.45 matthew 13072:
1.1075.2.56 raeburn 13073: =item * &get_folder_hierarchy()
1.1068 raeburn 13074:
13075: Provides hierarchy of names of folders/sub-folders containing the current
13076: item,
13077:
13078: Inputs: 3
13079: - $navmap - navmaps object
13080:
13081: - $map - url for map (either the trigger itself, or map containing
13082: the resource, which is the trigger).
13083:
13084: - $showitem - 1 => show title for map itself; 0 => do not show.
13085:
13086: Outputs: 1 @pathitems - array of folder/subfolder names.
13087:
13088: =cut
13089:
13090: sub get_folder_hierarchy {
13091: my ($navmap,$map,$showitem) = @_;
13092: my @pathitems;
13093: if (ref($navmap)) {
13094: my $mapres = $navmap->getResourceByUrl($map);
13095: if (ref($mapres)) {
13096: my $pcslist = $mapres->map_hierarchy();
13097: if ($pcslist ne '') {
13098: my @pcs = split(/,/,$pcslist);
13099: foreach my $pc (@pcs) {
13100: if ($pc == 1) {
1.1075.2.38 raeburn 13101: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13102: } else {
13103: my $res = $navmap->getByMapPc($pc);
13104: if (ref($res)) {
13105: my $title = $res->compTitle();
13106: $title =~ s/\W+/_/g;
13107: if ($title ne '') {
13108: push(@pathitems,$title);
13109: }
13110: }
13111: }
13112: }
13113: }
1.1071 raeburn 13114: if ($showitem) {
13115: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 13116: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13117: } else {
13118: my $maptitle = $mapres->compTitle();
13119: $maptitle =~ s/\W+/_/g;
13120: if ($maptitle ne '') {
13121: push(@pathitems,$maptitle);
13122: }
1.1068 raeburn 13123: }
13124: }
13125: }
13126: }
13127: return @pathitems;
13128: }
13129:
13130: =pod
13131:
1.1015 raeburn 13132: =item * &get_turnedin_filepath()
13133:
13134: Determines path in a user's portfolio file for storage of files uploaded
13135: to a specific essayresponse or dropbox item.
13136:
13137: Inputs: 3 required + 1 optional.
13138: $symb is symb for resource, $uname and $udom are for current user (required).
13139: $caller is optional (can be "submission", if routine is called when storing
13140: an upoaded file when "Submit Answer" button was pressed).
13141:
13142: Returns array containing $path and $multiresp.
13143: $path is path in portfolio. $multiresp is 1 if this resource contains more
13144: than one file upload item. Callers of routine should append partid as a
13145: subdirectory to $path in cases where $multiresp is 1.
13146:
13147: Called by: homework/essayresponse.pm and homework/structuretags.pm
13148:
13149: =cut
13150:
13151: sub get_turnedin_filepath {
13152: my ($symb,$uname,$udom,$caller) = @_;
13153: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13154: my $turnindir;
13155: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13156: $turnindir = $userhash{'turnindir'};
13157: my ($path,$multiresp);
13158: if ($turnindir eq '') {
13159: if ($caller eq 'submission') {
13160: $turnindir = &mt('turned in');
13161: $turnindir =~ s/\W+/_/g;
13162: my %newhash = (
13163: 'turnindir' => $turnindir,
13164: );
13165: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13166: }
13167: }
13168: if ($turnindir ne '') {
13169: $path = '/'.$turnindir.'/';
13170: my ($multipart,$turnin,@pathitems);
13171: my $navmap = Apache::lonnavmaps::navmap->new();
13172: if (defined($navmap)) {
13173: my $mapres = $navmap->getResourceByUrl($map);
13174: if (ref($mapres)) {
13175: my $pcslist = $mapres->map_hierarchy();
13176: if ($pcslist ne '') {
13177: foreach my $pc (split(/,/,$pcslist)) {
13178: my $res = $navmap->getByMapPc($pc);
13179: if (ref($res)) {
13180: my $title = $res->compTitle();
13181: $title =~ s/\W+/_/g;
13182: if ($title ne '') {
1.1075.2.48 raeburn 13183: if (($pc > 1) && (length($title) > 12)) {
13184: $title = substr($title,0,12);
13185: }
1.1015 raeburn 13186: push(@pathitems,$title);
13187: }
13188: }
13189: }
13190: }
13191: my $maptitle = $mapres->compTitle();
13192: $maptitle =~ s/\W+/_/g;
13193: if ($maptitle ne '') {
1.1075.2.48 raeburn 13194: if (length($maptitle) > 12) {
13195: $maptitle = substr($maptitle,0,12);
13196: }
1.1015 raeburn 13197: push(@pathitems,$maptitle);
13198: }
13199: unless ($env{'request.state'} eq 'construct') {
13200: my $res = $navmap->getBySymb($symb);
13201: if (ref($res)) {
13202: my $partlist = $res->parts();
13203: my $totaluploads = 0;
13204: if (ref($partlist) eq 'ARRAY') {
13205: foreach my $part (@{$partlist}) {
13206: my @types = $res->responseType($part);
13207: my @ids = $res->responseIds($part);
13208: for (my $i=0; $i < scalar(@ids); $i++) {
13209: if ($types[$i] eq 'essay') {
13210: my $partid = $part.'_'.$ids[$i];
13211: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13212: $totaluploads ++;
13213: }
13214: }
13215: }
13216: }
13217: if ($totaluploads > 1) {
13218: $multiresp = 1;
13219: }
13220: }
13221: }
13222: }
13223: } else {
13224: return;
13225: }
13226: } else {
13227: return;
13228: }
13229: my $restitle=&Apache::lonnet::gettitle($symb);
13230: $restitle =~ s/\W+/_/g;
13231: if ($restitle eq '') {
13232: $restitle = ($resurl =~ m{/[^/]+$});
13233: if ($restitle eq '') {
13234: $restitle = time;
13235: }
13236: }
1.1075.2.48 raeburn 13237: if (length($restitle) > 12) {
13238: $restitle = substr($restitle,0,12);
13239: }
1.1015 raeburn 13240: push(@pathitems,$restitle);
13241: $path .= join('/',@pathitems);
13242: }
13243: return ($path,$multiresp);
13244: }
13245:
13246: =pod
13247:
1.464 albertel 13248: =back
1.41 ng 13249:
1.112 bowersj2 13250: =head1 CSV Upload/Handling functions
1.38 albertel 13251:
1.41 ng 13252: =over 4
13253:
1.648 raeburn 13254: =item * &upfile_store($r)
1.41 ng 13255:
13256: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13257: needs $env{'form.upfile'}
1.41 ng 13258: returns $datatoken to be put into hidden field
13259:
13260: =cut
1.31 albertel 13261:
13262: sub upfile_store {
13263: my $r=shift;
1.258 albertel 13264: $env{'form.upfile'}=~s/\r/\n/gs;
13265: $env{'form.upfile'}=~s/\f/\n/gs;
13266: $env{'form.upfile'}=~s/\n+/\n/gs;
13267: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13268:
1.1075.2.128 raeburn 13269: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13270: '_enroll_'.$env{'request.course.id'}.'_'.
13271: time.'_'.$$);
13272: return if ($datatoken eq '');
13273:
1.31 albertel 13274: {
1.158 raeburn 13275: my $datafile = $r->dir_config('lonDaemons').
13276: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128 raeburn 13277: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13278: print $fh $env{'form.upfile'};
1.158 raeburn 13279: close($fh);
13280: }
1.31 albertel 13281: }
13282: return $datatoken;
13283: }
13284:
1.56 matthew 13285: =pod
13286:
1.1075.2.128 raeburn 13287: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13288:
13289: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128 raeburn 13290: $datatoken is the name to assign to the temporary file.
1.258 albertel 13291: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13292:
13293: =cut
1.31 albertel 13294:
13295: sub load_tmp_file {
1.1075.2.128 raeburn 13296: my ($r,$datatoken) = @_;
13297: return if ($datatoken eq '');
1.31 albertel 13298: my @studentdata=();
13299: {
1.158 raeburn 13300: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128 raeburn 13301: '/tmp/'.$datatoken.'.tmp';
13302: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13303: @studentdata=<$fh>;
13304: close($fh);
13305: }
1.31 albertel 13306: }
1.258 albertel 13307: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13308: }
13309:
1.1075.2.128 raeburn 13310: sub valid_datatoken {
13311: my ($datatoken) = @_;
1.1075.2.131 raeburn 13312: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1075.2.128 raeburn 13313: return $datatoken;
13314: }
13315: return;
13316: }
13317:
1.56 matthew 13318: =pod
13319:
1.648 raeburn 13320: =item * &upfile_record_sep()
1.41 ng 13321:
13322: Separate uploaded file into records
13323: returns array of records,
1.258 albertel 13324: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13325:
13326: =cut
1.31 albertel 13327:
13328: sub upfile_record_sep {
1.258 albertel 13329: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13330: } else {
1.248 albertel 13331: my @records;
1.258 albertel 13332: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13333: if ($line=~/^\s*$/) { next; }
13334: push(@records,$line);
13335: }
13336: return @records;
1.31 albertel 13337: }
13338: }
13339:
1.56 matthew 13340: =pod
13341:
1.648 raeburn 13342: =item * &record_sep($record)
1.41 ng 13343:
1.258 albertel 13344: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13345:
13346: =cut
13347:
1.263 www 13348: sub takeleft {
13349: my $index=shift;
13350: return substr('0000'.$index,-4,4);
13351: }
13352:
1.31 albertel 13353: sub record_sep {
13354: my $record=shift;
13355: my %components=();
1.258 albertel 13356: if ($env{'form.upfiletype'} eq 'xml') {
13357: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13358: my $i=0;
1.356 albertel 13359: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13360: $field=~s/^(\"|\')//;
13361: $field=~s/(\"|\')$//;
1.263 www 13362: $components{&takeleft($i)}=$field;
1.31 albertel 13363: $i++;
13364: }
1.258 albertel 13365: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13366: my $i=0;
1.356 albertel 13367: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13368: $field=~s/^(\"|\')//;
13369: $field=~s/(\"|\')$//;
1.263 www 13370: $components{&takeleft($i)}=$field;
1.31 albertel 13371: $i++;
13372: }
13373: } else {
1.561 www 13374: my $separator=',';
1.480 banghart 13375: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13376: $separator=';';
1.480 banghart 13377: }
1.31 albertel 13378: my $i=0;
1.561 www 13379: # the character we are looking for to indicate the end of a quote or a record
13380: my $looking_for=$separator;
13381: # do not add the characters to the fields
13382: my $ignore=0;
13383: # we just encountered a separator (or the beginning of the record)
13384: my $just_found_separator=1;
13385: # store the field we are working on here
13386: my $field='';
13387: # work our way through all characters in record
13388: foreach my $character ($record=~/(.)/g) {
13389: if ($character eq $looking_for) {
13390: if ($character ne $separator) {
13391: # Found the end of a quote, again looking for separator
13392: $looking_for=$separator;
13393: $ignore=1;
13394: } else {
13395: # Found a separator, store away what we got
13396: $components{&takeleft($i)}=$field;
13397: $i++;
13398: $just_found_separator=1;
13399: $ignore=0;
13400: $field='';
13401: }
13402: next;
13403: }
13404: # single or double quotation marks after a separator indicate beginning of a quote
13405: # we are now looking for the end of the quote and need to ignore separators
13406: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13407: $looking_for=$character;
13408: next;
13409: }
13410: # ignore would be true after we reached the end of a quote
13411: if ($ignore) { next; }
13412: if (($just_found_separator) && ($character=~/\s/)) { next; }
13413: $field.=$character;
13414: $just_found_separator=0;
1.31 albertel 13415: }
1.561 www 13416: # catch the very last entry, since we never encountered the separator
13417: $components{&takeleft($i)}=$field;
1.31 albertel 13418: }
13419: return %components;
13420: }
13421:
1.144 matthew 13422: ######################################################
13423: ######################################################
13424:
1.56 matthew 13425: =pod
13426:
1.648 raeburn 13427: =item * &upfile_select_html()
1.41 ng 13428:
1.144 matthew 13429: Return HTML code to select a file from the users machine and specify
13430: the file type.
1.41 ng 13431:
13432: =cut
13433:
1.144 matthew 13434: ######################################################
13435: ######################################################
1.31 albertel 13436: sub upfile_select_html {
1.144 matthew 13437: my %Types = (
13438: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13439: semisv => &mt('Semicolon separated values'),
1.144 matthew 13440: space => &mt('Space separated'),
13441: tab => &mt('Tabulator separated'),
13442: # xml => &mt('HTML/XML'),
13443: );
13444: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13445: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13446: foreach my $type (sort(keys(%Types))) {
13447: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13448: }
13449: $Str .= "</select>\n";
13450: return $Str;
1.31 albertel 13451: }
13452:
1.301 albertel 13453: sub get_samples {
13454: my ($records,$toget) = @_;
13455: my @samples=({});
13456: my $got=0;
13457: foreach my $rec (@$records) {
13458: my %temp = &record_sep($rec);
13459: if (! grep(/\S/, values(%temp))) { next; }
13460: if (%temp) {
13461: $samples[$got]=\%temp;
13462: $got++;
13463: if ($got == $toget) { last; }
13464: }
13465: }
13466: return \@samples;
13467: }
13468:
1.144 matthew 13469: ######################################################
13470: ######################################################
13471:
1.56 matthew 13472: =pod
13473:
1.648 raeburn 13474: =item * &csv_print_samples($r,$records)
1.41 ng 13475:
13476: Prints a table of sample values from each column uploaded $r is an
13477: Apache Request ref, $records is an arrayref from
13478: &Apache::loncommon::upfile_record_sep
13479:
13480: =cut
13481:
1.144 matthew 13482: ######################################################
13483: ######################################################
1.31 albertel 13484: sub csv_print_samples {
13485: my ($r,$records) = @_;
1.662 bisitz 13486: my $samples = &get_samples($records,5);
1.301 albertel 13487:
1.594 raeburn 13488: $r->print(&mt('Samples').'<br />'.&start_data_table().
13489: &start_data_table_header_row());
1.356 albertel 13490: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13491: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13492: $r->print(&end_data_table_header_row());
1.301 albertel 13493: foreach my $hash (@$samples) {
1.594 raeburn 13494: $r->print(&start_data_table_row());
1.356 albertel 13495: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13496: $r->print('<td>');
1.356 albertel 13497: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13498: $r->print('</td>');
13499: }
1.594 raeburn 13500: $r->print(&end_data_table_row());
1.31 albertel 13501: }
1.594 raeburn 13502: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13503: }
13504:
1.144 matthew 13505: ######################################################
13506: ######################################################
13507:
1.56 matthew 13508: =pod
13509:
1.648 raeburn 13510: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13511:
13512: Prints a table to create associations between values and table columns.
1.144 matthew 13513:
1.41 ng 13514: $r is an Apache Request ref,
13515: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13516: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13517:
13518: =cut
13519:
1.144 matthew 13520: ######################################################
13521: ######################################################
1.31 albertel 13522: sub csv_print_select_table {
13523: my ($r,$records,$d) = @_;
1.301 albertel 13524: my $i=0;
13525: my $samples = &get_samples($records,1);
1.144 matthew 13526: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13527: &start_data_table().&start_data_table_header_row().
1.144 matthew 13528: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13529: '<th>'.&mt('Column').'</th>'.
13530: &end_data_table_header_row()."\n");
1.356 albertel 13531: foreach my $array_ref (@$d) {
13532: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13533: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13534:
1.875 bisitz 13535: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13536: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13537: $r->print('<option value="none"></option>');
1.356 albertel 13538: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13539: $r->print('<option value="'.$sample.'"'.
13540: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13541: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13542: }
1.594 raeburn 13543: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13544: $i++;
13545: }
1.594 raeburn 13546: $r->print(&end_data_table());
1.31 albertel 13547: $i--;
13548: return $i;
13549: }
1.56 matthew 13550:
1.144 matthew 13551: ######################################################
13552: ######################################################
13553:
1.56 matthew 13554: =pod
1.31 albertel 13555:
1.648 raeburn 13556: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13557:
13558: Prints a table of sample values from the upload and can make associate samples to internal names.
13559:
13560: $r is an Apache Request ref,
13561: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13562: $d is an array of 2 element arrays (internal name, displayed name)
13563:
13564: =cut
13565:
1.144 matthew 13566: ######################################################
13567: ######################################################
1.31 albertel 13568: sub csv_samples_select_table {
13569: my ($r,$records,$d) = @_;
13570: my $i=0;
1.144 matthew 13571: #
1.662 bisitz 13572: my $max_samples = 5;
13573: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13574: $r->print(&start_data_table().
13575: &start_data_table_header_row().'<th>'.
13576: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13577: &end_data_table_header_row());
1.301 albertel 13578:
13579: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13580: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13581: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13582: foreach my $option (@$d) {
13583: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13584: $r->print('<option value="'.$value.'"'.
1.253 albertel 13585: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13586: $display.'</option>');
1.31 albertel 13587: }
13588: $r->print('</select></td><td>');
1.662 bisitz 13589: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13590: if (defined($samples->[$line]{$key})) {
13591: $r->print($samples->[$line]{$key}."<br />\n");
13592: }
13593: }
1.594 raeburn 13594: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13595: $i++;
13596: }
1.594 raeburn 13597: $r->print(&end_data_table());
1.31 albertel 13598: $i--;
13599: return($i);
1.115 matthew 13600: }
13601:
1.144 matthew 13602: ######################################################
13603: ######################################################
13604:
1.115 matthew 13605: =pod
13606:
1.648 raeburn 13607: =item * &clean_excel_name($name)
1.115 matthew 13608:
13609: Returns a replacement for $name which does not contain any illegal characters.
13610:
13611: =cut
13612:
1.144 matthew 13613: ######################################################
13614: ######################################################
1.115 matthew 13615: sub clean_excel_name {
13616: my ($name) = @_;
13617: $name =~ s/[:\*\?\/\\]//g;
13618: if (length($name) > 31) {
13619: $name = substr($name,0,31);
13620: }
13621: return $name;
1.25 albertel 13622: }
1.84 albertel 13623:
1.85 albertel 13624: =pod
13625:
1.648 raeburn 13626: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13627:
13628: Returns either 1 or undef
13629:
13630: 1 if the part is to be hidden, undef if it is to be shown
13631:
13632: Arguments are:
13633:
13634: $id the id of the part to be checked
13635: $symb, optional the symb of the resource to check
13636: $udom, optional the domain of the user to check for
13637: $uname, optional the username of the user to check for
13638:
13639: =cut
1.84 albertel 13640:
13641: sub check_if_partid_hidden {
13642: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13643: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13644: $symb,$udom,$uname);
1.141 albertel 13645: my $truth=1;
13646: #if the string starts with !, then the list is the list to show not hide
13647: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13648: my @hiddenlist=split(/,/,$hiddenparts);
13649: foreach my $checkid (@hiddenlist) {
1.141 albertel 13650: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13651: }
1.141 albertel 13652: return !$truth;
1.84 albertel 13653: }
1.127 matthew 13654:
1.138 matthew 13655:
13656: ############################################################
13657: ############################################################
13658:
13659: =pod
13660:
1.157 matthew 13661: =back
13662:
1.138 matthew 13663: =head1 cgi-bin script and graphing routines
13664:
1.157 matthew 13665: =over 4
13666:
1.648 raeburn 13667: =item * &get_cgi_id()
1.138 matthew 13668:
13669: Inputs: none
13670:
13671: Returns an id which can be used to pass environment variables
13672: to various cgi-bin scripts. These environment variables will
13673: be removed from the users environment after a given time by
13674: the routine &Apache::lonnet::transfer_profile_to_env.
13675:
13676: =cut
13677:
13678: ############################################################
13679: ############################################################
1.152 albertel 13680: my $uniq=0;
1.136 matthew 13681: sub get_cgi_id {
1.154 albertel 13682: $uniq=($uniq+1)%100000;
1.280 albertel 13683: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13684: }
13685:
1.127 matthew 13686: ############################################################
13687: ############################################################
13688:
13689: =pod
13690:
1.648 raeburn 13691: =item * &DrawBarGraph()
1.127 matthew 13692:
1.138 matthew 13693: Facilitates the plotting of data in a (stacked) bar graph.
13694: Puts plot definition data into the users environment in order for
13695: graph.png to plot it. Returns an <img> tag for the plot.
13696: The bars on the plot are labeled '1','2',...,'n'.
13697:
13698: Inputs:
13699:
13700: =over 4
13701:
13702: =item $Title: string, the title of the plot
13703:
13704: =item $xlabel: string, text describing the X-axis of the plot
13705:
13706: =item $ylabel: string, text describing the Y-axis of the plot
13707:
13708: =item $Max: scalar, the maximum Y value to use in the plot
13709: If $Max is < any data point, the graph will not be rendered.
13710:
1.140 matthew 13711: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13712: they are plotted. If undefined, default values will be used.
13713:
1.178 matthew 13714: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13715:
1.138 matthew 13716: =item @Values: An array of array references. Each array reference holds data
13717: to be plotted in a stacked bar chart.
13718:
1.239 matthew 13719: =item If the final element of @Values is a hash reference the key/value
13720: pairs will be added to the graph definition.
13721:
1.138 matthew 13722: =back
13723:
13724: Returns:
13725:
13726: An <img> tag which references graph.png and the appropriate identifying
13727: information for the plot.
13728:
1.127 matthew 13729: =cut
13730:
13731: ############################################################
13732: ############################################################
1.134 matthew 13733: sub DrawBarGraph {
1.178 matthew 13734: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13735: #
13736: if (! defined($colors)) {
13737: $colors = ['#33ff00',
13738: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13739: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13740: ];
13741: }
1.228 matthew 13742: my $extra_settings = {};
13743: if (ref($Values[-1]) eq 'HASH') {
13744: $extra_settings = pop(@Values);
13745: }
1.127 matthew 13746: #
1.136 matthew 13747: my $identifier = &get_cgi_id();
13748: my $id = 'cgi.'.$identifier;
1.129 matthew 13749: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13750: return '';
13751: }
1.225 matthew 13752: #
13753: my @Labels;
13754: if (defined($labels)) {
13755: @Labels = @$labels;
13756: } else {
13757: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 13758: push(@Labels,$i+1);
1.225 matthew 13759: }
13760: }
13761: #
1.129 matthew 13762: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13763: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13764: my %ValuesHash;
13765: my $NumSets=1;
13766: foreach my $array (@Values) {
13767: next if (! ref($array));
1.136 matthew 13768: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13769: join(',',@$array);
1.129 matthew 13770: }
1.127 matthew 13771: #
1.136 matthew 13772: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13773: if ($NumBars < 3) {
13774: $width = 120+$NumBars*32;
1.220 matthew 13775: $xskip = 1;
1.225 matthew 13776: $bar_width = 30;
13777: } elsif ($NumBars < 5) {
13778: $width = 120+$NumBars*20;
13779: $xskip = 1;
13780: $bar_width = 20;
1.220 matthew 13781: } elsif ($NumBars < 10) {
1.136 matthew 13782: $width = 120+$NumBars*15;
13783: $xskip = 1;
13784: $bar_width = 15;
13785: } elsif ($NumBars <= 25) {
13786: $width = 120+$NumBars*11;
13787: $xskip = 5;
13788: $bar_width = 8;
13789: } elsif ($NumBars <= 50) {
13790: $width = 120+$NumBars*8;
13791: $xskip = 5;
13792: $bar_width = 4;
13793: } else {
13794: $width = 120+$NumBars*8;
13795: $xskip = 5;
13796: $bar_width = 4;
13797: }
13798: #
1.137 matthew 13799: $Max = 1 if ($Max < 1);
13800: if ( int($Max) < $Max ) {
13801: $Max++;
13802: $Max = int($Max);
13803: }
1.127 matthew 13804: $Title = '' if (! defined($Title));
13805: $xlabel = '' if (! defined($xlabel));
13806: $ylabel = '' if (! defined($ylabel));
1.369 www 13807: $ValuesHash{$id.'.title'} = &escape($Title);
13808: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13809: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13810: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13811: $ValuesHash{$id.'.NumBars'} = $NumBars;
13812: $ValuesHash{$id.'.NumSets'} = $NumSets;
13813: $ValuesHash{$id.'.PlotType'} = 'bar';
13814: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13815: $ValuesHash{$id.'.height'} = $height;
13816: $ValuesHash{$id.'.width'} = $width;
13817: $ValuesHash{$id.'.xskip'} = $xskip;
13818: $ValuesHash{$id.'.bar_width'} = $bar_width;
13819: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13820: #
1.228 matthew 13821: # Deal with other parameters
13822: while (my ($key,$value) = each(%$extra_settings)) {
13823: $ValuesHash{$id.'.'.$key} = $value;
13824: }
13825: #
1.646 raeburn 13826: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13827: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13828: }
13829:
13830: ############################################################
13831: ############################################################
13832:
13833: =pod
13834:
1.648 raeburn 13835: =item * &DrawXYGraph()
1.137 matthew 13836:
1.138 matthew 13837: Facilitates the plotting of data in an XY graph.
13838: Puts plot definition data into the users environment in order for
13839: graph.png to plot it. Returns an <img> tag for the plot.
13840:
13841: Inputs:
13842:
13843: =over 4
13844:
13845: =item $Title: string, the title of the plot
13846:
13847: =item $xlabel: string, text describing the X-axis of the plot
13848:
13849: =item $ylabel: string, text describing the Y-axis of the plot
13850:
13851: =item $Max: scalar, the maximum Y value to use in the plot
13852: If $Max is < any data point, the graph will not be rendered.
13853:
13854: =item $colors: Array ref containing the hex color codes for the data to be
13855: plotted in. If undefined, default values will be used.
13856:
13857: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13858:
13859: =item $Ydata: Array ref containing Array refs.
1.185 www 13860: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13861:
13862: =item %Values: hash indicating or overriding any default values which are
13863: passed to graph.png.
13864: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13865:
13866: =back
13867:
13868: Returns:
13869:
13870: An <img> tag which references graph.png and the appropriate identifying
13871: information for the plot.
13872:
1.137 matthew 13873: =cut
13874:
13875: ############################################################
13876: ############################################################
13877: sub DrawXYGraph {
13878: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13879: #
13880: # Create the identifier for the graph
13881: my $identifier = &get_cgi_id();
13882: my $id = 'cgi.'.$identifier;
13883: #
13884: $Title = '' if (! defined($Title));
13885: $xlabel = '' if (! defined($xlabel));
13886: $ylabel = '' if (! defined($ylabel));
13887: my %ValuesHash =
13888: (
1.369 www 13889: $id.'.title' => &escape($Title),
13890: $id.'.xlabel' => &escape($xlabel),
13891: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13892: $id.'.y_max_value'=> $Max,
13893: $id.'.labels' => join(',',@$Xlabels),
13894: $id.'.PlotType' => 'XY',
13895: );
13896: #
13897: if (defined($colors) && ref($colors) eq 'ARRAY') {
13898: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13899: }
13900: #
13901: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13902: return '';
13903: }
13904: my $NumSets=1;
1.138 matthew 13905: foreach my $array (@{$Ydata}){
1.137 matthew 13906: next if (! ref($array));
13907: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13908: }
1.138 matthew 13909: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13910: #
13911: # Deal with other parameters
13912: while (my ($key,$value) = each(%Values)) {
13913: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13914: }
13915: #
1.646 raeburn 13916: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13917: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13918: }
13919:
13920: ############################################################
13921: ############################################################
13922:
13923: =pod
13924:
1.648 raeburn 13925: =item * &DrawXYYGraph()
1.138 matthew 13926:
13927: Facilitates the plotting of data in an XY graph with two Y axes.
13928: Puts plot definition data into the users environment in order for
13929: graph.png to plot it. Returns an <img> tag for the plot.
13930:
13931: Inputs:
13932:
13933: =over 4
13934:
13935: =item $Title: string, the title of the plot
13936:
13937: =item $xlabel: string, text describing the X-axis of the plot
13938:
13939: =item $ylabel: string, text describing the Y-axis of the plot
13940:
13941: =item $colors: Array ref containing the hex color codes for the data to be
13942: plotted in. If undefined, default values will be used.
13943:
13944: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13945:
13946: =item $Ydata1: The first data set
13947:
13948: =item $Min1: The minimum value of the left Y-axis
13949:
13950: =item $Max1: The maximum value of the left Y-axis
13951:
13952: =item $Ydata2: The second data set
13953:
13954: =item $Min2: The minimum value of the right Y-axis
13955:
13956: =item $Max2: The maximum value of the left Y-axis
13957:
13958: =item %Values: hash indicating or overriding any default values which are
13959: passed to graph.png.
13960: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13961:
13962: =back
13963:
13964: Returns:
13965:
13966: An <img> tag which references graph.png and the appropriate identifying
13967: information for the plot.
1.136 matthew 13968:
13969: =cut
13970:
13971: ############################################################
13972: ############################################################
1.137 matthew 13973: sub DrawXYYGraph {
13974: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13975: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13976: #
13977: # Create the identifier for the graph
13978: my $identifier = &get_cgi_id();
13979: my $id = 'cgi.'.$identifier;
13980: #
13981: $Title = '' if (! defined($Title));
13982: $xlabel = '' if (! defined($xlabel));
13983: $ylabel = '' if (! defined($ylabel));
13984: my %ValuesHash =
13985: (
1.369 www 13986: $id.'.title' => &escape($Title),
13987: $id.'.xlabel' => &escape($xlabel),
13988: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13989: $id.'.labels' => join(',',@$Xlabels),
13990: $id.'.PlotType' => 'XY',
13991: $id.'.NumSets' => 2,
1.137 matthew 13992: $id.'.two_axes' => 1,
13993: $id.'.y1_max_value' => $Max1,
13994: $id.'.y1_min_value' => $Min1,
13995: $id.'.y2_max_value' => $Max2,
13996: $id.'.y2_min_value' => $Min2,
1.136 matthew 13997: );
13998: #
1.137 matthew 13999: if (defined($colors) && ref($colors) eq 'ARRAY') {
14000: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14001: }
14002: #
14003: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14004: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14005: return '';
14006: }
14007: my $NumSets=1;
1.137 matthew 14008: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14009: next if (! ref($array));
14010: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14011: }
14012: #
14013: # Deal with other parameters
14014: while (my ($key,$value) = each(%Values)) {
14015: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14016: }
14017: #
1.646 raeburn 14018: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14019: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14020: }
14021:
14022: ############################################################
14023: ############################################################
14024:
14025: =pod
14026:
1.157 matthew 14027: =back
14028:
1.139 matthew 14029: =head1 Statistics helper routines?
14030:
14031: Bad place for them but what the hell.
14032:
1.157 matthew 14033: =over 4
14034:
1.648 raeburn 14035: =item * &chartlink()
1.139 matthew 14036:
14037: Returns a link to the chart for a specific student.
14038:
14039: Inputs:
14040:
14041: =over 4
14042:
14043: =item $linktext: The text of the link
14044:
14045: =item $sname: The students username
14046:
14047: =item $sdomain: The students domain
14048:
14049: =back
14050:
1.157 matthew 14051: =back
14052:
1.139 matthew 14053: =cut
14054:
14055: ############################################################
14056: ############################################################
14057: sub chartlink {
14058: my ($linktext, $sname, $sdomain) = @_;
14059: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14060: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14061: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14062: '">'.$linktext.'</a>';
1.153 matthew 14063: }
14064:
14065: #######################################################
14066: #######################################################
14067:
14068: =pod
14069:
14070: =head1 Course Environment Routines
1.157 matthew 14071:
14072: =over 4
1.153 matthew 14073:
1.648 raeburn 14074: =item * &restore_course_settings()
1.153 matthew 14075:
1.648 raeburn 14076: =item * &store_course_settings()
1.153 matthew 14077:
14078: Restores/Store indicated form parameters from the course environment.
14079: Will not overwrite existing values of the form parameters.
14080:
14081: Inputs:
14082: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14083:
14084: a hash ref describing the data to be stored. For example:
14085:
14086: %Save_Parameters = ('Status' => 'scalar',
14087: 'chartoutputmode' => 'scalar',
14088: 'chartoutputdata' => 'scalar',
14089: 'Section' => 'array',
1.373 raeburn 14090: 'Group' => 'array',
1.153 matthew 14091: 'StudentData' => 'array',
14092: 'Maps' => 'array');
14093:
14094: Returns: both routines return nothing
14095:
1.631 raeburn 14096: =back
14097:
1.153 matthew 14098: =cut
14099:
14100: #######################################################
14101: #######################################################
14102: sub store_course_settings {
1.496 albertel 14103: return &store_settings($env{'request.course.id'},@_);
14104: }
14105:
14106: sub store_settings {
1.153 matthew 14107: # save to the environment
14108: # appenv the same items, just to be safe
1.300 albertel 14109: my $udom = $env{'user.domain'};
14110: my $uname = $env{'user.name'};
1.496 albertel 14111: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14112: my %SaveHash;
14113: my %AppHash;
14114: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14115: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14116: my $envname = 'environment.'.$basename;
1.258 albertel 14117: if (exists($env{'form.'.$setting})) {
1.153 matthew 14118: # Save this value away
14119: if ($type eq 'scalar' &&
1.258 albertel 14120: (! exists($env{$envname}) ||
14121: $env{$envname} ne $env{'form.'.$setting})) {
14122: $SaveHash{$basename} = $env{'form.'.$setting};
14123: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14124: } elsif ($type eq 'array') {
14125: my $stored_form;
1.258 albertel 14126: if (ref($env{'form.'.$setting})) {
1.153 matthew 14127: $stored_form = join(',',
14128: map {
1.369 www 14129: &escape($_);
1.258 albertel 14130: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14131: } else {
14132: $stored_form =
1.369 www 14133: &escape($env{'form.'.$setting});
1.153 matthew 14134: }
14135: # Determine if the array contents are the same.
1.258 albertel 14136: if ($stored_form ne $env{$envname}) {
1.153 matthew 14137: $SaveHash{$basename} = $stored_form;
14138: $AppHash{$envname} = $stored_form;
14139: }
14140: }
14141: }
14142: }
14143: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14144: $udom,$uname);
1.153 matthew 14145: if ($put_result !~ /^(ok|delayed)/) {
14146: &Apache::lonnet::logthis('unable to save form parameters, '.
14147: 'got error:'.$put_result);
14148: }
14149: # Make sure these settings stick around in this session, too
1.646 raeburn 14150: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14151: return;
14152: }
14153:
14154: sub restore_course_settings {
1.499 albertel 14155: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14156: }
14157:
14158: sub restore_settings {
14159: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14160: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14161: next if (exists($env{'form.'.$setting}));
1.496 albertel 14162: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14163: '.'.$setting;
1.258 albertel 14164: if (exists($env{$envname})) {
1.153 matthew 14165: if ($type eq 'scalar') {
1.258 albertel 14166: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14167: } elsif ($type eq 'array') {
1.258 albertel 14168: $env{'form.'.$setting} = [
1.153 matthew 14169: map {
1.369 www 14170: &unescape($_);
1.258 albertel 14171: } split(',',$env{$envname})
1.153 matthew 14172: ];
14173: }
14174: }
14175: }
1.127 matthew 14176: }
14177:
1.618 raeburn 14178: #######################################################
14179: #######################################################
14180:
14181: =pod
14182:
14183: =head1 Domain E-mail Routines
14184:
14185: =over 4
14186:
1.648 raeburn 14187: =item * &build_recipient_list()
1.618 raeburn 14188:
1.1075.2.44 raeburn 14189: Build recipient lists for following types of e-mail:
1.766 raeburn 14190: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14191: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14192: module change checking, student/employee ID conflict checks, as
14193: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14194: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14195:
14196: Inputs:
1.1075.2.44 raeburn 14197: defmail (scalar - email address of default recipient),
14198: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14199: requestsmail, updatesmail, or idconflictsmail).
14200:
1.619 raeburn 14201: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14202:
14203: origmail (scalar - email address of recipient from loncapa.conf,
14204: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14205:
1.1075.2.139 raeburn 14206: $requname username of requester (if mailing type is helpdeskmail)
14207:
14208: $requdom domain of requester (if mailing type is helpdeskmail)
14209:
14210: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14211:
1.655 raeburn 14212: Returns: comma separated list of addresses to which to send e-mail.
14213:
14214: =back
1.618 raeburn 14215:
14216: =cut
14217:
14218: ############################################################
14219: ############################################################
14220: sub build_recipient_list {
1.1075.2.139 raeburn 14221: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14222: my @recipients;
1.1075.2.122 raeburn 14223: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14224: my %domconfig =
1.1075.2.122 raeburn 14225: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14226: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14227: if (exists($domconfig{'contacts'}{$mailing})) {
14228: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14229: my @contacts = ('adminemail','supportemail');
14230: foreach my $item (@contacts) {
14231: if ($domconfig{'contacts'}{$mailing}{$item}) {
14232: my $addr = $domconfig{'contacts'}{$item};
14233: if (!grep(/^\Q$addr\E$/,@recipients)) {
14234: push(@recipients,$addr);
14235: }
1.619 raeburn 14236: }
1.1075.2.122 raeburn 14237: }
14238: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14239: if ($mailing eq 'helpdeskmail') {
14240: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14241: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14242: my @ok_bccs;
14243: foreach my $bcc (@bccs) {
14244: $bcc =~ s/^\s+//g;
14245: $bcc =~ s/\s+$//g;
14246: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14247: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14248: push(@ok_bccs,$bcc);
14249: }
14250: }
14251: }
14252: if (@ok_bccs > 0) {
14253: $allbcc = join(', ',@ok_bccs);
14254: }
14255: }
14256: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14257: }
14258: }
1.766 raeburn 14259: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14260: $lastresort = $origmail;
1.618 raeburn 14261: }
1.1075.2.139 raeburn 14262: if ($mailing eq 'helpdeskmail') {
14263: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14264: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14265: my ($inststatus,$inststatus_checked);
14266: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14267: ($env{'user.domain'} ne 'public')) {
14268: $inststatus_checked = 1;
14269: $inststatus = $env{'environment.inststatus'};
14270: }
14271: unless ($inststatus_checked) {
14272: if (($requname ne '') && ($requdom ne '')) {
14273: if (($requname =~ /^$match_username$/) &&
14274: ($requdom =~ /^$match_domain$/) &&
14275: (&Apache::lonnet::domain($requdom))) {
14276: my $requhome = &Apache::lonnet::homeserver($requname,
14277: $requdom);
14278: unless ($requhome eq 'no_host') {
14279: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14280: $inststatus = $userenv{'inststatus'};
14281: $inststatus_checked = 1;
14282: }
14283: }
14284: }
14285: }
14286: unless ($inststatus_checked) {
14287: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14288: my %srch = (srchby => 'email',
14289: srchdomain => $defdom,
14290: srchterm => $reqemail,
14291: srchtype => 'exact');
14292: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14293: foreach my $uname (keys(%srch_results)) {
14294: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14295: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14296: $inststatus_checked = 1;
14297: last;
14298: }
14299: }
14300: unless ($inststatus_checked) {
14301: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14302: if ($dirsrchres eq 'ok') {
14303: foreach my $uname (keys(%srch_results)) {
14304: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14305: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14306: $inststatus_checked = 1;
14307: last;
14308: }
14309: }
14310: }
14311: }
14312: }
14313: }
14314: if ($inststatus ne '') {
14315: foreach my $status (split(/\:/,$inststatus)) {
14316: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14317: my @contacts = ('adminemail','supportemail');
14318: foreach my $item (@contacts) {
14319: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14320: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14321: if (!grep(/^\Q$addr\E$/,@recipients)) {
14322: push(@recipients,$addr);
14323: }
14324: }
14325: }
14326: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14327: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14328: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14329: my @ok_bccs;
14330: foreach my $bcc (@bccs) {
14331: $bcc =~ s/^\s+//g;
14332: $bcc =~ s/\s+$//g;
14333: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14334: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14335: push(@ok_bccs,$bcc);
14336: }
14337: }
14338: }
14339: if (@ok_bccs > 0) {
14340: $allbcc = join(', ',@ok_bccs);
14341: }
14342: }
14343: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14344: last;
14345: }
14346: }
14347: }
14348: }
14349: }
1.619 raeburn 14350: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14351: $lastresort = $origmail;
14352: }
1.1075.2.128 raeburn 14353: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14354: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14355: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14356: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14357: my %what = (
14358: perlvar => 1,
14359: );
14360: my $primary = &Apache::lonnet::domain($defdom,'primary');
14361: if ($primary) {
14362: my $gotaddr;
14363: my ($result,$returnhash) =
14364: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14365: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14366: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14367: $lastresort = $returnhash->{'lonSupportEMail'};
14368: $gotaddr = 1;
14369: }
14370: }
14371: unless ($gotaddr) {
14372: my $uintdom = &Apache::lonnet::internet_dom($primary);
14373: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14374: unless ($uintdom eq $intdom) {
14375: my %domconfig =
14376: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14377: if (ref($domconfig{'contacts'}) eq 'HASH') {
14378: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14379: my @contacts = ('adminemail','supportemail');
14380: foreach my $item (@contacts) {
14381: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14382: my $addr = $domconfig{'contacts'}{$item};
14383: if (!grep(/^\Q$addr\E$/,@recipients)) {
14384: push(@recipients,$addr);
14385: }
14386: }
14387: }
14388: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14389: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14390: }
14391: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14392: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14393: my @ok_bccs;
14394: foreach my $bcc (@bccs) {
14395: $bcc =~ s/^\s+//g;
14396: $bcc =~ s/\s+$//g;
14397: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14398: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14399: push(@ok_bccs,$bcc);
14400: }
14401: }
14402: }
14403: if (@ok_bccs > 0) {
14404: $allbcc = join(', ',@ok_bccs);
14405: }
14406: }
14407: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14408: }
14409: }
14410: }
14411: }
14412: }
14413: }
1.618 raeburn 14414: }
1.688 raeburn 14415: if (defined($defmail)) {
14416: if ($defmail ne '') {
14417: push(@recipients,$defmail);
14418: }
1.618 raeburn 14419: }
14420: if ($otheremails) {
1.619 raeburn 14421: my @others;
14422: if ($otheremails =~ /,/) {
14423: @others = split(/,/,$otheremails);
1.618 raeburn 14424: } else {
1.619 raeburn 14425: push(@others,$otheremails);
14426: }
14427: foreach my $addr (@others) {
14428: if (!grep(/^\Q$addr\E$/,@recipients)) {
14429: push(@recipients,$addr);
14430: }
1.618 raeburn 14431: }
14432: }
1.1075.2.128 raeburn 14433: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14434: if ((!@recipients) && ($lastresort ne '')) {
14435: push(@recipients,$lastresort);
14436: }
14437: } elsif ($lastresort ne '') {
14438: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14439: push(@recipients,$lastresort);
14440: }
14441: }
14442: my $recipientlist = join(',',@recipients);
14443: if (wantarray) {
14444: return ($recipientlist,$allbcc,$addtext);
14445: } else {
14446: return $recipientlist;
14447: }
1.618 raeburn 14448: }
14449:
1.127 matthew 14450: ############################################################
14451: ############################################################
1.154 albertel 14452:
1.655 raeburn 14453: =pod
14454:
14455: =head1 Course Catalog Routines
14456:
14457: =over 4
14458:
14459: =item * &gather_categories()
14460:
14461: Converts category definitions - keys of categories hash stored in
14462: coursecategories in configuration.db on the primary library server in a
14463: domain - to an array. Also generates javascript and idx hash used to
14464: generate Domain Coordinator interface for editing Course Categories.
14465:
14466: Inputs:
1.663 raeburn 14467:
1.655 raeburn 14468: categories (reference to hash of category definitions).
1.663 raeburn 14469:
1.655 raeburn 14470: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14471: categories and subcategories).
1.663 raeburn 14472:
1.655 raeburn 14473: idx (reference to hash of counters used in Domain Coordinator interface for
14474: editing Course Categories).
1.663 raeburn 14475:
1.655 raeburn 14476: jsarray (reference to array of categories used to create Javascript arrays for
14477: Domain Coordinator interface for editing Course Categories).
14478:
14479: Returns: nothing
14480:
14481: Side effects: populates cats, idx and jsarray.
14482:
14483: =cut
14484:
14485: sub gather_categories {
14486: my ($categories,$cats,$idx,$jsarray) = @_;
14487: my %counters;
14488: my $num = 0;
14489: foreach my $item (keys(%{$categories})) {
14490: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14491: if ($container eq '' && $depth == 0) {
14492: $cats->[$depth][$categories->{$item}] = $cat;
14493: } else {
14494: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14495: }
14496: my ($escitem,$tail) = split(/:/,$item,2);
14497: if ($counters{$tail} eq '') {
14498: $counters{$tail} = $num;
14499: $num ++;
14500: }
14501: if (ref($idx) eq 'HASH') {
14502: $idx->{$item} = $counters{$tail};
14503: }
14504: if (ref($jsarray) eq 'ARRAY') {
14505: push(@{$jsarray->[$counters{$tail}]},$item);
14506: }
14507: }
14508: return;
14509: }
14510:
14511: =pod
14512:
14513: =item * &extract_categories()
14514:
14515: Used to generate breadcrumb trails for course categories.
14516:
14517: Inputs:
1.663 raeburn 14518:
1.655 raeburn 14519: categories (reference to hash of category definitions).
1.663 raeburn 14520:
1.655 raeburn 14521: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14522: categories and subcategories).
1.663 raeburn 14523:
1.655 raeburn 14524: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14525:
1.655 raeburn 14526: allitems (reference to hash - key is category key
14527: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14528:
1.655 raeburn 14529: idx (reference to hash of counters used in Domain Coordinator interface for
14530: editing Course Categories).
1.663 raeburn 14531:
1.655 raeburn 14532: jsarray (reference to array of categories used to create Javascript arrays for
14533: Domain Coordinator interface for editing Course Categories).
14534:
1.665 raeburn 14535: subcats (reference to hash of arrays containing all subcategories within each
14536: category, -recursive)
14537:
1.1075.2.132 raeburn 14538: maxd (reference to hash used to hold max depth for all top-level categories).
14539:
1.655 raeburn 14540: Returns: nothing
14541:
14542: Side effects: populates trails and allitems hash references.
14543:
14544: =cut
14545:
14546: sub extract_categories {
1.1075.2.132 raeburn 14547: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 14548: if (ref($categories) eq 'HASH') {
14549: &gather_categories($categories,$cats,$idx,$jsarray);
14550: if (ref($cats->[0]) eq 'ARRAY') {
14551: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14552: my $name = $cats->[0][$i];
14553: my $item = &escape($name).'::0';
14554: my $trailstr;
14555: if ($name eq 'instcode') {
14556: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14557: } elsif ($name eq 'communities') {
14558: $trailstr = &mt('Communities');
1.655 raeburn 14559: } else {
14560: $trailstr = $name;
14561: }
14562: if ($allitems->{$item} eq '') {
14563: push(@{$trails},$trailstr);
14564: $allitems->{$item} = scalar(@{$trails})-1;
14565: }
14566: my @parents = ($name);
14567: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14568: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14569: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14570: if (ref($subcats) eq 'HASH') {
14571: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14572: }
1.1075.2.132 raeburn 14573: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 14574: }
14575: } else {
14576: if (ref($subcats) eq 'HASH') {
14577: $subcats->{$item} = [];
1.655 raeburn 14578: }
1.1075.2.132 raeburn 14579: if (ref($maxd) eq 'HASH') {
14580: $maxd->{$name} = 1;
14581: }
1.655 raeburn 14582: }
14583: }
14584: }
14585: }
14586: return;
14587: }
14588:
14589: =pod
14590:
1.1075.2.56 raeburn 14591: =item * &recurse_categories()
1.655 raeburn 14592:
14593: Recursively used to generate breadcrumb trails for course categories.
14594:
14595: Inputs:
1.663 raeburn 14596:
1.655 raeburn 14597: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14598: categories and subcategories).
1.663 raeburn 14599:
1.655 raeburn 14600: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14601:
14602: category (current course category, for which breadcrumb trail is being generated).
14603:
14604: trails (reference to array of breadcrumb trails for each category).
14605:
1.655 raeburn 14606: allitems (reference to hash - key is category key
14607: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14608:
1.655 raeburn 14609: parents (array containing containers directories for current category,
14610: back to top level).
14611:
14612: Returns: nothing
14613:
14614: Side effects: populates trails and allitems hash references
14615:
14616: =cut
14617:
14618: sub recurse_categories {
1.1075.2.132 raeburn 14619: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 14620: my $shallower = $depth - 1;
14621: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14622: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14623: my $name = $cats->[$depth]{$category}[$k];
14624: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14625: my $trailstr = join(' -> ',(@{$parents},$category));
14626: if ($allitems->{$item} eq '') {
14627: push(@{$trails},$trailstr);
14628: $allitems->{$item} = scalar(@{$trails})-1;
14629: }
14630: my $deeper = $depth+1;
14631: push(@{$parents},$category);
1.665 raeburn 14632: if (ref($subcats) eq 'HASH') {
14633: my $subcat = &escape($name).':'.$category.':'.$depth;
14634: for (my $j=@{$parents}; $j>=0; $j--) {
14635: my $higher;
14636: if ($j > 0) {
14637: $higher = &escape($parents->[$j]).':'.
14638: &escape($parents->[$j-1]).':'.$j;
14639: } else {
14640: $higher = &escape($parents->[$j]).'::'.$j;
14641: }
14642: push(@{$subcats->{$higher}},$subcat);
14643: }
14644: }
14645: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1075.2.132 raeburn 14646: $subcats,$maxd);
1.655 raeburn 14647: pop(@{$parents});
14648: }
14649: } else {
14650: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1075.2.132 raeburn 14651: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 14652: if ($allitems->{$item} eq '') {
14653: push(@{$trails},$trailstr);
14654: $allitems->{$item} = scalar(@{$trails})-1;
14655: }
1.1075.2.132 raeburn 14656: if (ref($maxd) eq 'HASH') {
14657: if ($depth > $maxd->{$parents->[0]}) {
14658: $maxd->{$parents->[0]} = $depth;
14659: }
14660: }
1.655 raeburn 14661: }
14662: return;
14663: }
14664:
1.663 raeburn 14665: =pod
14666:
1.1075.2.56 raeburn 14667: =item * &assign_categories_table()
1.663 raeburn 14668:
14669: Create a datatable for display of hierarchical categories in a domain,
14670: with checkboxes to allow a course to be categorized.
14671:
14672: Inputs:
14673:
14674: cathash - reference to hash of categories defined for the domain (from
14675: configuration.db)
14676:
14677: currcat - scalar with an & separated list of categories assigned to a course.
14678:
1.919 raeburn 14679: type - scalar contains course type (Course or Community).
14680:
1.1075.2.117 raeburn 14681: disabled - scalar (optional) contains disabled="disabled" if input elements are
14682: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14683:
1.663 raeburn 14684: Returns: $output (markup to be displayed)
14685:
14686: =cut
14687:
14688: sub assign_categories_table {
1.1075.2.117 raeburn 14689: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14690: my $output;
14691: if (ref($cathash) eq 'HASH') {
1.1075.2.132 raeburn 14692: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
14693: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 14694: $maxdepth = scalar(@cats);
14695: if (@cats > 0) {
14696: my $itemcount = 0;
14697: if (ref($cats[0]) eq 'ARRAY') {
14698: my @currcategories;
14699: if ($currcat ne '') {
14700: @currcategories = split('&',$currcat);
14701: }
1.919 raeburn 14702: my $table;
1.663 raeburn 14703: for (my $i=0; $i<@{$cats[0]}; $i++) {
14704: my $parent = $cats[0][$i];
1.919 raeburn 14705: next if ($parent eq 'instcode');
14706: if ($type eq 'Community') {
14707: next unless ($parent eq 'communities');
14708: } else {
14709: next if ($parent eq 'communities');
14710: }
1.663 raeburn 14711: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14712: my $item = &escape($parent).'::0';
14713: my $checked = '';
14714: if (@currcategories > 0) {
14715: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14716: $checked = ' checked="checked"';
1.663 raeburn 14717: }
14718: }
1.919 raeburn 14719: my $parent_title = $parent;
14720: if ($parent eq 'communities') {
14721: $parent_title = &mt('Communities');
14722: }
14723: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14724: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14725: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 14726: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14727: my $depth = 1;
14728: push(@path,$parent);
1.1075.2.117 raeburn 14729: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 14730: pop(@path);
1.919 raeburn 14731: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14732: $itemcount ++;
14733: }
1.919 raeburn 14734: if ($itemcount) {
14735: $output = &Apache::loncommon::start_data_table().
14736: $table.
14737: &Apache::loncommon::end_data_table();
14738: }
1.663 raeburn 14739: }
14740: }
14741: }
14742: return $output;
14743: }
14744:
14745: =pod
14746:
1.1075.2.56 raeburn 14747: =item * &assign_category_rows()
1.663 raeburn 14748:
14749: Create a datatable row for display of nested categories in a domain,
14750: with checkboxes to allow a course to be categorized,called recursively.
14751:
14752: Inputs:
14753:
14754: itemcount - track row number for alternating colors
14755:
14756: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14757: categories and subcategories.
14758:
14759: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14760:
14761: parent - parent of current category item
14762:
14763: path - Array containing all categories back up through the hierarchy from the
14764: current category to the top level.
14765:
14766: currcategories - reference to array of current categories assigned to the course
14767:
1.1075.2.117 raeburn 14768: disabled - scalar (optional) contains disabled="disabled" if input elements are
14769: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14770:
1.663 raeburn 14771: Returns: $output (markup to be displayed).
14772:
14773: =cut
14774:
14775: sub assign_category_rows {
1.1075.2.117 raeburn 14776: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 14777: my ($text,$name,$item,$chgstr);
14778: if (ref($cats) eq 'ARRAY') {
14779: my $maxdepth = scalar(@{$cats});
14780: if (ref($cats->[$depth]) eq 'HASH') {
14781: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14782: my $numchildren = @{$cats->[$depth]{$parent}};
14783: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 14784: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14785: for (my $j=0; $j<$numchildren; $j++) {
14786: $name = $cats->[$depth]{$parent}[$j];
14787: $item = &escape($name).':'.&escape($parent).':'.$depth;
14788: my $deeper = $depth+1;
14789: my $checked = '';
14790: if (ref($currcategories) eq 'ARRAY') {
14791: if (@{$currcategories} > 0) {
14792: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14793: $checked = ' checked="checked"';
1.663 raeburn 14794: }
14795: }
14796: }
1.664 raeburn 14797: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14798: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14799: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 14800: '<input type="hidden" name="catname" value="'.$name.'" />'.
14801: '</td><td>';
1.663 raeburn 14802: if (ref($path) eq 'ARRAY') {
14803: push(@{$path},$name);
1.1075.2.117 raeburn 14804: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 14805: pop(@{$path});
14806: }
14807: $text .= '</td></tr>';
14808: }
14809: $text .= '</table></td>';
14810: }
14811: }
14812: }
14813: return $text;
14814: }
14815:
1.1075.2.69 raeburn 14816: =pod
14817:
14818: =back
14819:
14820: =cut
14821:
1.655 raeburn 14822: ############################################################
14823: ############################################################
14824:
14825:
1.443 albertel 14826: sub commit_customrole {
1.664 raeburn 14827: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14828: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14829: ($start?', '.&mt('starting').' '.localtime($start):'').
14830: ($end?', ending '.localtime($end):'').': <b>'.
14831: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14832: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14833: '</b><br />';
14834: return $output;
14835: }
14836:
14837: sub commit_standardrole {
1.1075.2.31 raeburn 14838: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14839: my ($output,$logmsg,$linefeed);
14840: if ($context eq 'auto') {
14841: $linefeed = "\n";
14842: } else {
14843: $linefeed = "<br />\n";
14844: }
1.443 albertel 14845: if ($three eq 'st') {
1.541 raeburn 14846: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14847: $one,$two,$sec,$context,$credits);
1.541 raeburn 14848: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14849: ($result eq 'unknown_course') || ($result eq 'refused')) {
14850: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14851: } else {
1.541 raeburn 14852: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14853: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14854: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14855: if ($context eq 'auto') {
14856: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14857: } else {
14858: $output .= '<b>'.$result.'</b>'.$linefeed.
14859: &mt('Add to classlist').': <b>ok</b>';
14860: }
14861: $output .= $linefeed;
1.443 albertel 14862: }
14863: } else {
14864: $output = &mt('Assigning').' '.$three.' in '.$url.
14865: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14866: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14867: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14868: if ($context eq 'auto') {
14869: $output .= $result.$linefeed;
14870: } else {
14871: $output .= '<b>'.$result.'</b>'.$linefeed;
14872: }
1.443 albertel 14873: }
14874: return $output;
14875: }
14876:
14877: sub commit_studentrole {
1.1075.2.31 raeburn 14878: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14879: $credits) = @_;
1.626 raeburn 14880: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14881: if ($context eq 'auto') {
14882: $linefeed = "\n";
14883: } else {
14884: $linefeed = '<br />'."\n";
14885: }
1.443 albertel 14886: if (defined($one) && defined($two)) {
14887: my $cid=$one.'_'.$two;
14888: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14889: my $secchange = 0;
14890: my $expire_role_result;
14891: my $modify_section_result;
1.628 raeburn 14892: if ($oldsec ne '-1') {
14893: if ($oldsec ne $sec) {
1.443 albertel 14894: $secchange = 1;
1.628 raeburn 14895: my $now = time;
1.443 albertel 14896: my $uurl='/'.$cid;
14897: $uurl=~s/\_/\//g;
14898: if ($oldsec) {
14899: $uurl.='/'.$oldsec;
14900: }
1.626 raeburn 14901: $oldsecurl = $uurl;
1.628 raeburn 14902: $expire_role_result =
1.652 raeburn 14903: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14904: if ($env{'request.course.sec'} ne '') {
14905: if ($expire_role_result eq 'refused') {
14906: my @roles = ('st');
14907: my @statuses = ('previous');
14908: my @roledoms = ($one);
14909: my $withsec = 1;
14910: my %roleshash =
14911: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14912: \@statuses,\@roles,\@roledoms,$withsec);
14913: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14914: my ($oldstart,$oldend) =
14915: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14916: if ($oldend > 0 && $oldend <= $now) {
14917: $expire_role_result = 'ok';
14918: }
14919: }
14920: }
14921: }
1.443 albertel 14922: $result = $expire_role_result;
14923: }
14924: }
14925: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 14926: $modify_section_result =
14927: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14928: undef,undef,undef,$sec,
14929: $end,$start,'','',$cid,
14930: '',$context,$credits);
1.443 albertel 14931: if ($modify_section_result =~ /^ok/) {
14932: if ($secchange == 1) {
1.628 raeburn 14933: if ($sec eq '') {
14934: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14935: } else {
14936: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14937: }
1.443 albertel 14938: } elsif ($oldsec eq '-1') {
1.628 raeburn 14939: if ($sec eq '') {
14940: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14941: } else {
14942: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14943: }
1.443 albertel 14944: } else {
1.628 raeburn 14945: if ($sec eq '') {
14946: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14947: } else {
14948: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14949: }
1.443 albertel 14950: }
14951: } else {
1.628 raeburn 14952: if ($secchange) {
14953: $$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;
14954: } else {
14955: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14956: }
1.443 albertel 14957: }
14958: $result = $modify_section_result;
14959: } elsif ($secchange == 1) {
1.628 raeburn 14960: if ($oldsec eq '') {
1.1075.2.20 raeburn 14961: $$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 14962: } else {
14963: $$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;
14964: }
1.626 raeburn 14965: if ($expire_role_result eq 'refused') {
14966: my $newsecurl = '/'.$cid;
14967: $newsecurl =~ s/\_/\//g;
14968: if ($sec ne '') {
14969: $newsecurl.='/'.$sec;
14970: }
14971: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14972: if ($sec eq '') {
14973: $$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;
14974: } else {
14975: $$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;
14976: }
14977: }
14978: }
1.443 albertel 14979: }
14980: } else {
1.626 raeburn 14981: $$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 14982: $result = "error: incomplete course id\n";
14983: }
14984: return $result;
14985: }
14986:
1.1075.2.25 raeburn 14987: sub show_role_extent {
14988: my ($scope,$context,$role) = @_;
14989: $scope =~ s{^/}{};
14990: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14991: push(@courseroles,'co');
14992: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14993: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14994: $scope =~ s{/}{_};
14995: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14996: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14997: my ($audom,$auname) = split(/\//,$scope);
14998: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14999: &Apache::loncommon::plainname($auname,$audom).'</span>');
15000: } else {
15001: $scope =~ s{/$}{};
15002: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15003: &Apache::lonnet::domain($scope,'description').'</span>');
15004: }
15005: }
15006:
1.443 albertel 15007: ############################################################
15008: ############################################################
15009:
1.566 albertel 15010: sub check_clone {
1.578 raeburn 15011: my ($args,$linefeed) = @_;
1.566 albertel 15012: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15013: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15014: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15015: my $clonemsg;
15016: my $can_clone = 0;
1.944 raeburn 15017: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15018: if ($lctype ne 'community') {
15019: $lctype = 'course';
15020: }
1.566 albertel 15021: if ($clonehome eq 'no_host') {
1.944 raeburn 15022: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15023: $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'});
15024: } else {
15025: $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'});
15026: }
1.566 albertel 15027: } else {
15028: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15029: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15030: if ($clonedesc{'type'} ne 'Community') {
15031: $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'});
15032: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15033: }
15034: }
1.1075.2.119 raeburn 15035: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15036: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15037: $can_clone = 1;
15038: } else {
1.1075.2.95 raeburn 15039: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15040: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 15041: if ($clonehash{'cloners'} eq '') {
15042: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15043: if ($domdefs{'canclone'}) {
15044: unless ($domdefs{'canclone'} eq 'none') {
15045: if ($domdefs{'canclone'} eq 'domain') {
15046: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15047: $can_clone = 1;
15048: }
15049: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15050: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15051: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15052: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15053: $can_clone = 1;
15054: }
15055: }
15056: }
1.908 raeburn 15057: }
1.1075.2.95 raeburn 15058: } else {
15059: my @cloners = split(/,/,$clonehash{'cloners'});
15060: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15061: $can_clone = 1;
1.1075.2.95 raeburn 15062: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15063: $can_clone = 1;
1.1075.2.96 raeburn 15064: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15065: $can_clone = 1;
1.1075.2.95 raeburn 15066: }
15067: unless ($can_clone) {
1.1075.2.96 raeburn 15068: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15069: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 15070: my (%gotdomdefaults,%gotcodedefaults);
15071: foreach my $cloner (@cloners) {
15072: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15073: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15074: my (%codedefaults,@code_order);
15075: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15076: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15077: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15078: }
15079: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15080: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15081: }
15082: } else {
15083: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15084: \%codedefaults,
15085: \@code_order);
15086: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15087: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15088: }
15089: if (@code_order > 0) {
15090: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15091: $cloner,$clonehash{'internal.coursecode'},
15092: $args->{'crscode'})) {
15093: $can_clone = 1;
15094: last;
15095: }
15096: }
15097: }
15098: }
15099: }
1.1075.2.96 raeburn 15100: }
15101: }
15102: unless ($can_clone) {
15103: my $ccrole = 'cc';
15104: if ($args->{'crstype'} eq 'Community') {
15105: $ccrole = 'co';
15106: }
15107: my %roleshash =
15108: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15109: $args->{'ccdomain'},
15110: 'userroles',['active'],[$ccrole],
15111: [$args->{'clonedomain'}]);
15112: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15113: $can_clone = 1;
15114: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15115: $args->{'ccuname'},$args->{'ccdomain'})) {
15116: $can_clone = 1;
1.1075.2.95 raeburn 15117: }
15118: }
15119: unless ($can_clone) {
15120: if ($args->{'crstype'} eq 'Community') {
15121: $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'});
15122: } else {
15123: $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 15124: }
1.566 albertel 15125: }
1.578 raeburn 15126: }
1.566 albertel 15127: }
15128: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15129: }
15130:
1.444 albertel 15131: sub construct_course {
1.1075.2.119 raeburn 15132: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15133: $cnum,$category,$coderef) = @_;
1.444 albertel 15134: my $outcome;
1.541 raeburn 15135: my $linefeed = '<br />'."\n";
15136: if ($context eq 'auto') {
15137: $linefeed = "\n";
15138: }
1.566 albertel 15139:
15140: #
15141: # Are we cloning?
15142: #
15143: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15144: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15145: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15146: if ($context ne 'auto') {
1.578 raeburn 15147: if ($clonemsg ne '') {
15148: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15149: }
1.566 albertel 15150: }
15151: $outcome .= $clonemsg.$linefeed;
15152:
15153: if (!$can_clone) {
15154: return (0,$outcome);
15155: }
15156: }
15157:
1.444 albertel 15158: #
15159: # Open course
15160: #
15161: my $crstype = lc($args->{'crstype'});
15162: my %cenv=();
15163: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15164: $args->{'cdescr'},
15165: $args->{'curl'},
15166: $args->{'course_home'},
15167: $args->{'nonstandard'},
15168: $args->{'crscode'},
15169: $args->{'ccuname'}.':'.
15170: $args->{'ccdomain'},
1.882 raeburn 15171: $args->{'crstype'},
1.885 raeburn 15172: $cnum,$context,$category);
1.444 albertel 15173:
15174: # Note: The testing routines depend on this being output; see
15175: # Utils::Course. This needs to at least be output as a comment
15176: # if anyone ever decides to not show this, and Utils::Course::new
15177: # will need to be suitably modified.
1.541 raeburn 15178: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 15179: if ($$courseid =~ /^error:/) {
15180: return (0,$outcome);
15181: }
15182:
1.444 albertel 15183: #
15184: # Check if created correctly
15185: #
1.479 albertel 15186: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15187: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15188: if ($crsuhome eq 'no_host') {
15189: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15190: return (0,$outcome);
15191: }
1.541 raeburn 15192: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15193:
1.444 albertel 15194: #
1.566 albertel 15195: # Do the cloning
15196: #
15197: if ($can_clone && $cloneid) {
15198: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
15199: if ($context ne 'auto') {
15200: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15201: }
15202: $outcome .= $clonemsg.$linefeed;
15203: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15204: # Copy all files
1.637 www 15205: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15206: # Restore URL
1.566 albertel 15207: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15208: # Restore title
1.566 albertel 15209: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15210: # Restore creation date, creator and creation context.
15211: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15212: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15213: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15214: # Mark as cloned
1.566 albertel 15215: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15216: # Need to clone grading mode
15217: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15218: $cenv{'grading'}=$newenv{'grading'};
15219: # Do not clone these environment entries
15220: &Apache::lonnet::del('environment',
15221: ['default_enrollment_start_date',
15222: 'default_enrollment_end_date',
15223: 'question.email',
15224: 'policy.email',
15225: 'comment.email',
15226: 'pch.users.denied',
1.725 raeburn 15227: 'plc.users.denied',
15228: 'hidefromcat',
1.1075.2.36 raeburn 15229: 'checkforpriv',
1.1075.2.59 raeburn 15230: 'categories',
15231: 'internal.uniquecode'],
1.638 www 15232: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 15233: if ($args->{'textbook'}) {
15234: $cenv{'internal.textbook'} = $args->{'textbook'};
15235: }
1.444 albertel 15236: }
1.566 albertel 15237:
1.444 albertel 15238: #
15239: # Set environment (will override cloned, if existing)
15240: #
15241: my @sections = ();
15242: my @xlists = ();
15243: if ($args->{'crstype'}) {
15244: $cenv{'type'}=$args->{'crstype'};
15245: }
15246: if ($args->{'crsid'}) {
15247: $cenv{'courseid'}=$args->{'crsid'};
15248: }
15249: if ($args->{'crscode'}) {
15250: $cenv{'internal.coursecode'}=$args->{'crscode'};
15251: }
15252: if ($args->{'crsquota'} ne '') {
15253: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15254: } else {
15255: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15256: }
15257: if ($args->{'ccuname'}) {
15258: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15259: ':'.$args->{'ccdomain'};
15260: } else {
15261: $cenv{'internal.courseowner'} = $args->{'curruser'};
15262: }
1.1075.2.31 raeburn 15263: if ($args->{'defaultcredits'}) {
15264: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15265: }
1.444 albertel 15266: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15267: if ($args->{'crssections'}) {
15268: $cenv{'internal.sectionnums'} = '';
15269: if ($args->{'crssections'} =~ m/,/) {
15270: @sections = split/,/,$args->{'crssections'};
15271: } else {
15272: $sections[0] = $args->{'crssections'};
15273: }
15274: if (@sections > 0) {
15275: foreach my $item (@sections) {
15276: my ($sec,$gp) = split/:/,$item;
15277: my $class = $args->{'crscode'}.$sec;
15278: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15279: $cenv{'internal.sectionnums'} .= $item.',';
15280: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15281: push(@badclasses,$class);
1.444 albertel 15282: }
15283: }
15284: $cenv{'internal.sectionnums'} =~ s/,$//;
15285: }
15286: }
15287: # do not hide course coordinator from staff listing,
15288: # even if privileged
15289: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15290: # add course coordinator's domain to domains to check for privileged users
15291: # if different to course domain
15292: if ($$crsudom ne $args->{'ccdomain'}) {
15293: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15294: }
1.444 albertel 15295: # add crosslistings
15296: if ($args->{'crsxlist'}) {
15297: $cenv{'internal.crosslistings'}='';
15298: if ($args->{'crsxlist'} =~ m/,/) {
15299: @xlists = split/,/,$args->{'crsxlist'};
15300: } else {
15301: $xlists[0] = $args->{'crsxlist'};
15302: }
15303: if (@xlists > 0) {
15304: foreach my $item (@xlists) {
15305: my ($xl,$gp) = split/:/,$item;
15306: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15307: $cenv{'internal.crosslistings'} .= $item.',';
15308: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15309: push(@badclasses,$xl);
1.444 albertel 15310: }
15311: }
15312: $cenv{'internal.crosslistings'} =~ s/,$//;
15313: }
15314: }
15315: if ($args->{'autoadds'}) {
15316: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15317: }
15318: if ($args->{'autodrops'}) {
15319: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15320: }
15321: # check for notification of enrollment changes
15322: my @notified = ();
15323: if ($args->{'notify_owner'}) {
15324: if ($args->{'ccuname'} ne '') {
15325: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15326: }
15327: }
15328: if ($args->{'notify_dc'}) {
15329: if ($uname ne '') {
1.630 raeburn 15330: push(@notified,$uname.':'.$udom);
1.444 albertel 15331: }
15332: }
15333: if (@notified > 0) {
15334: my $notifylist;
15335: if (@notified > 1) {
15336: $notifylist = join(',',@notified);
15337: } else {
15338: $notifylist = $notified[0];
15339: }
15340: $cenv{'internal.notifylist'} = $notifylist;
15341: }
15342: if (@badclasses > 0) {
15343: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15344: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15345: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15346: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15347: );
1.1075.2.119 raeburn 15348: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15349: &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 15350: if ($context eq 'auto') {
15351: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15352: } else {
1.566 albertel 15353: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15354: }
15355: foreach my $item (@badclasses) {
1.541 raeburn 15356: if ($context eq 'auto') {
1.1075.2.119 raeburn 15357: $outcome .= " - $item\n";
1.541 raeburn 15358: } else {
1.1075.2.119 raeburn 15359: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15360: }
1.1075.2.119 raeburn 15361: }
15362: if ($context eq 'auto') {
15363: $outcome .= $linefeed;
15364: } else {
15365: $outcome .= "</ul><br /><br /></div>\n";
15366: }
1.444 albertel 15367: }
15368: if ($args->{'no_end_date'}) {
15369: $args->{'endaccess'} = 0;
15370: }
15371: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15372: $cenv{'internal.autoend'}=$args->{'enrollend'};
15373: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15374: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15375: if ($args->{'showphotos'}) {
15376: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15377: }
15378: $cenv{'internal.authtype'} = $args->{'authtype'};
15379: $cenv{'internal.autharg'} = $args->{'autharg'};
15380: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15381: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15382: 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');
15383: if ($context eq 'auto') {
15384: $outcome .= $krb_msg;
15385: } else {
1.566 albertel 15386: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15387: }
15388: $outcome .= $linefeed;
1.444 albertel 15389: }
15390: }
15391: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15392: if ($args->{'setpolicy'}) {
15393: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15394: }
15395: if ($args->{'setcontent'}) {
15396: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15397: }
1.1075.2.110 raeburn 15398: if ($args->{'setcomment'}) {
15399: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15400: }
1.444 albertel 15401: }
15402: if ($args->{'reshome'}) {
15403: $cenv{'reshome'}=$args->{'reshome'}.'/';
15404: $cenv{'reshome'}=~s/\/+$/\//;
15405: }
15406: #
15407: # course has keyed access
15408: #
15409: if ($args->{'setkeys'}) {
15410: $cenv{'keyaccess'}='yes';
15411: }
15412: # if specified, key authority is not course, but user
15413: # only active if keyaccess is yes
15414: if ($args->{'keyauth'}) {
1.487 albertel 15415: my ($user,$domain) = split(':',$args->{'keyauth'});
15416: $user = &LONCAPA::clean_username($user);
15417: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15418: if ($user ne '' && $domain ne '') {
1.487 albertel 15419: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15420: }
15421: }
15422:
1.1075.2.59 raeburn 15423: #
15424: # generate and store uniquecode (available to course requester), if course should have one.
15425: #
15426: if ($args->{'uniquecode'}) {
15427: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15428: if ($code) {
15429: $cenv{'internal.uniquecode'} = $code;
15430: my %crsinfo =
15431: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15432: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15433: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15434: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15435: }
15436: if (ref($coderef)) {
15437: $$coderef = $code;
15438: }
15439: }
15440: }
15441:
1.444 albertel 15442: if ($args->{'disresdis'}) {
15443: $cenv{'pch.roles.denied'}='st';
15444: }
15445: if ($args->{'disablechat'}) {
15446: $cenv{'plc.roles.denied'}='st';
15447: }
15448:
15449: # Record we've not yet viewed the Course Initialization Helper for this
15450: # course
15451: $cenv{'course.helper.not.run'} = 1;
15452: #
15453: # Use new Randomseed
15454: #
15455: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15456: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15457: #
15458: # The encryption code and receipt prefix for this course
15459: #
15460: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15461: $cenv{'internal.encpref'}=100+int(9*rand(99));
15462: #
15463: # By default, use standard grading
15464: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15465:
1.541 raeburn 15466: $outcome .= $linefeed.&mt('Setting environment').': '.
15467: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15468: #
15469: # Open all assignments
15470: #
15471: if ($args->{'openall'}) {
15472: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15473: my %storecontent = ($storeunder => time,
15474: $storeunder.'.type' => 'date_start');
15475:
15476: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15477: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15478: }
15479: #
15480: # Set first page
15481: #
15482: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15483: || ($cloneid)) {
1.445 albertel 15484: use LONCAPA::map;
1.444 albertel 15485: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15486:
15487: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15488: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15489:
1.444 albertel 15490: $outcome .= ($fatal?$errtext:'read ok').' - ';
15491: my $title; my $url;
15492: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15493: $title=&mt('Syllabus');
1.444 albertel 15494: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15495: } else {
1.963 raeburn 15496: $title=&mt('Table of Contents');
1.444 albertel 15497: $url='/adm/navmaps';
15498: }
1.445 albertel 15499:
15500: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15501: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15502:
15503: if ($errtext) { $fatal=2; }
1.541 raeburn 15504: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15505: }
1.566 albertel 15506:
15507: return (1,$outcome);
1.444 albertel 15508: }
15509:
1.1075.2.59 raeburn 15510: sub make_unique_code {
15511: my ($cdom,$cnum) = @_;
15512: # get lock on uniquecodes db
15513: my $lockhash = {
15514: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15515: ':'.$env{'user.domain'},
15516: };
15517: my $tries = 0;
15518: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15519: my ($code,$error);
15520:
15521: while (($gotlock ne 'ok') && ($tries<3)) {
15522: $tries ++;
15523: sleep 1;
15524: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15525: }
15526: if ($gotlock eq 'ok') {
15527: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15528: my $gotcode;
15529: my $attempts = 0;
15530: while ((!$gotcode) && ($attempts < 100)) {
15531: $code = &generate_code();
15532: if (!exists($currcodes{$code})) {
15533: $gotcode = 1;
15534: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15535: $error = 'nostore';
15536: }
15537: }
15538: $attempts ++;
15539: }
15540: my @del_lock = ($cnum."\0".'uniquecodes');
15541: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15542: } else {
15543: $error = 'nolock';
15544: }
15545: return ($code,$error);
15546: }
15547:
15548: sub generate_code {
15549: my $code;
15550: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15551: for (my $i=0; $i<6; $i++) {
15552: my $lettnum = int (rand 2);
15553: my $item = '';
15554: if ($lettnum) {
15555: $item = $letts[int( rand(18) )];
15556: } else {
15557: $item = 1+int( rand(8) );
15558: }
15559: $code .= $item;
15560: }
15561: return $code;
15562: }
15563:
1.444 albertel 15564: ############################################################
15565: ############################################################
15566:
1.953 droeschl 15567: #SD
15568: # only Community and Course, or anything else?
1.378 raeburn 15569: sub course_type {
15570: my ($cid) = @_;
15571: if (!defined($cid)) {
15572: $cid = $env{'request.course.id'};
15573: }
1.404 albertel 15574: if (defined($env{'course.'.$cid.'.type'})) {
15575: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15576: } else {
15577: return 'Course';
1.377 raeburn 15578: }
15579: }
1.156 albertel 15580:
1.406 raeburn 15581: sub group_term {
15582: my $crstype = &course_type();
15583: my %names = (
15584: 'Course' => 'group',
1.865 raeburn 15585: 'Community' => 'group',
1.406 raeburn 15586: );
15587: return $names{$crstype};
15588: }
15589:
1.902 raeburn 15590: sub course_types {
1.1075.2.59 raeburn 15591: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15592: my %typename = (
15593: official => 'Official course',
15594: unofficial => 'Unofficial course',
15595: community => 'Community',
1.1075.2.59 raeburn 15596: textbook => 'Textbook course',
1.902 raeburn 15597: );
15598: return (\@types,\%typename);
15599: }
15600:
1.156 albertel 15601: sub icon {
15602: my ($file)=@_;
1.505 albertel 15603: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15604: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15605: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15606: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15607: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15608: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15609: $curfext.".gif") {
15610: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15611: $curfext.".gif";
15612: }
15613: }
1.249 albertel 15614: return &lonhttpdurl($iconname);
1.154 albertel 15615: }
1.84 albertel 15616:
1.575 albertel 15617: sub lonhttpdurl {
1.692 www 15618: #
15619: # Had been used for "small fry" static images on separate port 8080.
15620: # Modify here if lightweight http functionality desired again.
15621: # Currently eliminated due to increasing firewall issues.
15622: #
1.575 albertel 15623: my ($url)=@_;
1.692 www 15624: return $url;
1.215 albertel 15625: }
15626:
1.213 albertel 15627: sub connection_aborted {
15628: my ($r)=@_;
15629: $r->print(" ");$r->rflush();
15630: my $c = $r->connection;
15631: return $c->aborted();
15632: }
15633:
1.221 foxr 15634: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15635: # strings as 'strings'.
15636: sub escape_single {
1.221 foxr 15637: my ($input) = @_;
1.223 albertel 15638: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15639: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15640: return $input;
15641: }
1.223 albertel 15642:
1.222 foxr 15643: # Same as escape_single, but escape's "'s This
15644: # can be used for "strings"
15645: sub escape_double {
15646: my ($input) = @_;
15647: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15648: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15649: return $input;
15650: }
1.223 albertel 15651:
1.222 foxr 15652: # Escapes the last element of a full URL.
15653: sub escape_url {
15654: my ($url) = @_;
1.238 raeburn 15655: my @urlslices = split(/\//, $url,-1);
1.369 www 15656: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15657: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15658: }
1.462 albertel 15659:
1.820 raeburn 15660: sub compare_arrays {
15661: my ($arrayref1,$arrayref2) = @_;
15662: my (@difference,%count);
15663: @difference = ();
15664: %count = ();
15665: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15666: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15667: foreach my $element (keys(%count)) {
15668: if ($count{$element} == 1) {
15669: push(@difference,$element);
15670: }
15671: }
15672: }
15673: return @difference;
15674: }
15675:
1.817 bisitz 15676: # -------------------------------------------------------- Initialize user login
1.462 albertel 15677: sub init_user_environment {
1.463 albertel 15678: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15679: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15680:
15681: my $public=($username eq 'public' && $domain eq 'public');
15682:
15683: # See if old ID present, if so, remove
15684:
1.1062 raeburn 15685: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15686: my $now=time;
15687:
15688: if ($public) {
15689: my $max_public=100;
15690: my $oldest;
15691: my $oldest_time=0;
15692: for(my $next=1;$next<=$max_public;$next++) {
15693: if (-e $lonids."/publicuser_$next.id") {
15694: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15695: if ($mtime<$oldest_time || !$oldest_time) {
15696: $oldest_time=$mtime;
15697: $oldest=$next;
15698: }
15699: } else {
15700: $cookie="publicuser_$next";
15701: last;
15702: }
15703: }
15704: if (!$cookie) { $cookie="publicuser_$oldest"; }
15705: } else {
1.463 albertel 15706: # if this isn't a robot, kill any existing non-robot sessions
15707: if (!$args->{'robot'}) {
15708: opendir(DIR,$lonids);
15709: while ($filename=readdir(DIR)) {
15710: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1075.2.136 raeburn 15711: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
15712: &GDBM_READER(),0640)) {
15713: my $linkedfile;
15714: if (exists($oldenv{'user.linkedenv'})) {
15715: $linkedfile = $oldenv{'user.linkedenv'};
15716: }
15717: untie(%oldenv);
15718: if (unlink("$lonids/$filename")) {
15719: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
15720: if (-l "$lonids/$linkedfile.id") {
15721: unlink("$lonids/$linkedfile.id");
15722: }
15723: }
15724: }
15725: } else {
15726: unlink($lonids.'/'.$filename);
15727: }
1.463 albertel 15728: }
1.462 albertel 15729: }
1.463 albertel 15730: closedir(DIR);
1.1075.2.84 raeburn 15731: # If there is a undeleted lockfile for the user's paste buffer remove it.
15732: my $namespace = 'nohist_courseeditor';
15733: my $lockingkey = 'paste'."\0".'locked_num';
15734: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15735: $domain,$username);
15736: if (exists($lockhash{$lockingkey})) {
15737: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15738: unless ($delresult eq 'ok') {
15739: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15740: }
15741: }
1.462 albertel 15742: }
15743: # Give them a new cookie
1.463 albertel 15744: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15745: : $now.$$.int(rand(10000)));
1.463 albertel 15746: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15747:
15748: # Initialize roles
15749:
1.1062 raeburn 15750: ($userroles,$firstaccenv,$timerintenv) =
15751: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15752: }
15753: # ------------------------------------ Check browser type and MathML capability
15754:
1.1075.2.77 raeburn 15755: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15756: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15757:
15758: # ------------------------------------------------------------- Get environment
15759:
15760: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15761: my ($tmp) = keys(%userenv);
15762: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15763: } else {
15764: undef(%userenv);
15765: }
15766: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15767: $form->{'interface'}=$userenv{'interface'};
15768: }
15769: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15770:
15771: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15772: foreach my $option ('interface','localpath','localres') {
15773: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15774: }
15775: # --------------------------------------------------------- Write first profile
15776:
15777: {
15778: my %initial_env =
15779: ("user.name" => $username,
15780: "user.domain" => $domain,
15781: "user.home" => $authhost,
15782: "browser.type" => $clientbrowser,
15783: "browser.version" => $clientversion,
15784: "browser.mathml" => $clientmathml,
15785: "browser.unicode" => $clientunicode,
15786: "browser.os" => $clientos,
1.1075.2.42 raeburn 15787: "browser.mobile" => $clientmobile,
15788: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 15789: "browser.osversion" => $clientosversion,
1.462 albertel 15790: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15791: "request.course.fn" => '',
15792: "request.course.uri" => '',
15793: "request.course.sec" => '',
15794: "request.role" => 'cm',
15795: "request.role.adv" => $env{'user.adv'},
15796: "request.host" => $ENV{'REMOTE_ADDR'},);
15797:
15798: if ($form->{'localpath'}) {
15799: $initial_env{"browser.localpath"} = $form->{'localpath'};
15800: $initial_env{"browser.localres"} = $form->{'localres'};
15801: }
15802:
15803: if ($form->{'interface'}) {
15804: $form->{'interface'}=~s/\W//gs;
15805: $initial_env{"browser.interface"} = $form->{'interface'};
15806: $env{'browser.interface'}=$form->{'interface'};
15807: }
15808:
1.1075.2.54 raeburn 15809: if ($form->{'iptoken'}) {
15810: my $lonhost = $r->dir_config('lonHostID');
15811: $initial_env{"user.noloadbalance"} = $lonhost;
15812: $env{'user.noloadbalance'} = $lonhost;
15813: }
15814:
1.1075.2.120 raeburn 15815: if ($form->{'noloadbalance'}) {
15816: my @hosts = &Apache::lonnet::current_machine_ids();
15817: my $hosthere = $form->{'noloadbalance'};
15818: if (grep(/^\Q$hosthere\E$/,@hosts)) {
15819: $initial_env{"user.noloadbalance"} = $hosthere;
15820: $env{'user.noloadbalance'} = $hosthere;
15821: }
15822: }
15823:
1.1016 raeburn 15824: unless ($domain eq 'public') {
1.1075.2.125 raeburn 15825: my %is_adv = ( is_adv => $env{'user.adv'} );
15826: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 15827:
1.1075.2.125 raeburn 15828: foreach my $tool ('aboutme','blog','webdav','portfolio') {
15829: $userenv{'availabletools.'.$tool} =
15830: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15831: undef,\%userenv,\%domdef,\%is_adv);
15832: }
1.724 raeburn 15833:
1.1075.2.125 raeburn 15834: foreach my $crstype ('official','unofficial','community','textbook') {
15835: $userenv{'canrequest.'.$crstype} =
15836: &Apache::lonnet::usertools_access($username,$domain,$crstype,
15837: 'reload','requestcourses',
15838: \%userenv,\%domdef,\%is_adv);
15839: }
1.765 raeburn 15840:
1.1075.2.125 raeburn 15841: $userenv{'canrequest.author'} =
15842: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15843: 'reload','requestauthor',
15844: \%userenv,\%domdef,\%is_adv);
15845: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15846: $domain,$username);
15847: my $reqstatus = $reqauthor{'author_status'};
15848: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15849: if (ref($reqauthor{'author'}) eq 'HASH') {
15850: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15851: $reqauthor{'author'}{'timestamp'};
15852: }
1.1075.2.14 raeburn 15853: }
15854: }
15855:
1.462 albertel 15856: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15857:
1.462 albertel 15858: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15859: &GDBM_WRCREAT(),0640)) {
15860: &_add_to_env(\%disk_env,\%initial_env);
15861: &_add_to_env(\%disk_env,\%userenv,'environment.');
15862: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15863: if (ref($firstaccenv) eq 'HASH') {
15864: &_add_to_env(\%disk_env,$firstaccenv);
15865: }
15866: if (ref($timerintenv) eq 'HASH') {
15867: &_add_to_env(\%disk_env,$timerintenv);
15868: }
1.463 albertel 15869: if (ref($args->{'extra_env'})) {
15870: &_add_to_env(\%disk_env,$args->{'extra_env'});
15871: }
1.462 albertel 15872: untie(%disk_env);
15873: } else {
1.705 tempelho 15874: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15875: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15876: return 'error: '.$!;
15877: }
15878: }
15879: $env{'request.role'}='cm';
15880: $env{'request.role.adv'}=$env{'user.adv'};
15881: $env{'browser.type'}=$clientbrowser;
15882:
15883: return $cookie;
15884:
15885: }
15886:
15887: sub _add_to_env {
15888: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15889: if (ref($env_data) eq 'HASH') {
15890: while (my ($key,$value) = each(%$env_data)) {
15891: $idf->{$prefix.$key} = $value;
15892: $env{$prefix.$key} = $value;
15893: }
1.462 albertel 15894: }
15895: }
15896:
1.685 tempelho 15897: # --- Get the symbolic name of a problem and the url
15898: sub get_symb {
15899: my ($request,$silent) = @_;
1.726 raeburn 15900: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15901: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15902: if ($symb eq '') {
15903: if (!$silent) {
1.1071 raeburn 15904: if (ref($request)) {
15905: $request->print("Unable to handle ambiguous references:$url:.");
15906: }
1.685 tempelho 15907: return ();
15908: }
15909: }
15910: &Apache::lonenc::check_decrypt(\$symb);
15911: return ($symb);
15912: }
15913:
15914: # --------------------------------------------------------------Get annotation
15915:
15916: sub get_annotation {
15917: my ($symb,$enc) = @_;
15918:
15919: my $key = $symb;
15920: if (!$enc) {
15921: $key =
15922: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15923: }
15924: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15925: return $annotation{$key};
15926: }
15927:
15928: sub clean_symb {
1.731 raeburn 15929: my ($symb,$delete_enc) = @_;
1.685 tempelho 15930:
15931: &Apache::lonenc::check_decrypt(\$symb);
15932: my $enc = $env{'request.enc'};
1.731 raeburn 15933: if ($delete_enc) {
1.730 raeburn 15934: delete($env{'request.enc'});
15935: }
1.685 tempelho 15936:
15937: return ($symb,$enc);
15938: }
1.462 albertel 15939:
1.1075.2.69 raeburn 15940: ############################################################
15941: ############################################################
15942:
15943: =pod
15944:
15945: =head1 Routines for building display used to search for courses
15946:
15947:
15948: =over 4
15949:
15950: =item * &build_filters()
15951:
15952: Create markup for a table used to set filters to use when selecting
15953: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15954: and quotacheck.pl
15955:
15956:
15957: Inputs:
15958:
15959: filterlist - anonymous array of fields to include as potential filters
15960:
15961: crstype - course type
15962:
15963: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15964: to pop-open a course selector (will contain "extra element").
15965:
15966: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15967:
15968: filter - anonymous hash of criteria and their values
15969:
15970: action - form action
15971:
15972: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15973:
15974: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
15975:
15976: cloneruname - username of owner of new course who wants to clone
15977:
15978: clonerudom - domain of owner of new course who wants to clone
15979:
15980: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15981:
15982: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15983:
15984: codedom - domain
15985:
15986: formname - value of form element named "form".
15987:
15988: fixeddom - domain, if fixed.
15989:
15990: prevphase - value to assign to form element named "phase" when going back to the previous screen
15991:
15992: cnameelement - name of form element in form on opener page which will receive title of selected course
15993:
15994: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15995:
15996: cdomelement - name of form element in form on opener page which will receive domain of selected course
15997:
15998: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15999:
16000: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16001:
16002: clonewarning - warning message about missing information for intended course owner when DC creates a course
16003:
16004:
16005: Returns: $output - HTML for display of search criteria, and hidden form elements.
16006:
16007:
16008: Side Effects: None
16009:
16010: =cut
16011:
16012: # ---------------------------------------------- search for courses based on last activity etc.
16013:
16014: sub build_filters {
16015: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16016: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16017: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16018: $cnameelement,$cnumelement,$cdomelement,$setroles,
16019: $clonetext,$clonewarning) = @_;
16020: my ($list,$jscript);
16021: my $onchange = 'javascript:updateFilters(this)';
16022: my ($domainselectform,$sincefilterform,$createdfilterform,
16023: $ownerdomselectform,$persondomselectform,$instcodeform,
16024: $typeselectform,$instcodetitle);
16025: if ($formname eq '') {
16026: $formname = $caller;
16027: }
16028: foreach my $item (@{$filterlist}) {
16029: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16030: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16031: if ($item eq 'domainfilter') {
16032: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16033: } elsif ($item eq 'coursefilter') {
16034: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16035: } elsif ($item eq 'ownerfilter') {
16036: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16037: } elsif ($item eq 'ownerdomfilter') {
16038: $filter->{'ownerdomfilter'} =
16039: &LONCAPA::clean_domain($filter->{$item});
16040: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16041: 'ownerdomfilter',1);
16042: } elsif ($item eq 'personfilter') {
16043: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16044: } elsif ($item eq 'persondomfilter') {
16045: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16046: 'persondomfilter',1);
16047: } else {
16048: $filter->{$item} =~ s/\W//g;
16049: }
16050: if (!$filter->{$item}) {
16051: $filter->{$item} = '';
16052: }
16053: }
16054: if ($item eq 'domainfilter') {
16055: my $allow_blank = 1;
16056: if ($formname eq 'portform') {
16057: $allow_blank=0;
16058: } elsif ($formname eq 'studentform') {
16059: $allow_blank=0;
16060: }
16061: if ($fixeddom) {
16062: $domainselectform = '<input type="hidden" name="domainfilter"'.
16063: ' value="'.$codedom.'" />'.
16064: &Apache::lonnet::domain($codedom,'description');
16065: } else {
16066: $domainselectform = &select_dom_form($filter->{$item},
16067: 'domainfilter',
16068: $allow_blank,'',$onchange);
16069: }
16070: } else {
16071: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16072: }
16073: }
16074:
16075: # last course activity filter and selection
16076: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16077:
16078: # course created filter and selection
16079: if (exists($filter->{'createdfilter'})) {
16080: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16081: }
16082:
16083: my %lt = &Apache::lonlocal::texthash(
16084: 'cac' => "$crstype Activity",
16085: 'ccr' => "$crstype Created",
16086: 'cde' => "$crstype Title",
16087: 'cdo' => "$crstype Domain",
16088: 'ins' => 'Institutional Code',
16089: 'inc' => 'Institutional Categorization',
16090: 'cow' => "$crstype Owner/Co-owner",
16091: 'cop' => "$crstype Personnel Includes",
16092: 'cog' => 'Type',
16093: );
16094:
16095: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16096: my $typeval = 'Course';
16097: if ($crstype eq 'Community') {
16098: $typeval = 'Community';
16099: }
16100: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16101: } else {
16102: $typeselectform = '<select name="type" size="1"';
16103: if ($onchange) {
16104: $typeselectform .= ' onchange="'.$onchange.'"';
16105: }
16106: $typeselectform .= '>'."\n";
16107: foreach my $posstype ('Course','Community') {
16108: $typeselectform.='<option value="'.$posstype.'"'.
16109: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
16110: }
16111: $typeselectform.="</select>";
16112: }
16113:
16114: my ($cloneableonlyform,$cloneabletitle);
16115: if (exists($filter->{'cloneableonly'})) {
16116: my $cloneableon = '';
16117: my $cloneableoff = ' checked="checked"';
16118: if ($filter->{'cloneableonly'}) {
16119: $cloneableon = $cloneableoff;
16120: $cloneableoff = '';
16121: }
16122: $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>';
16123: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 16124: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 16125: } else {
16126: $cloneabletitle = &mt('Cloneable by you');
16127: }
16128: }
16129: my $officialjs;
16130: if ($crstype eq 'Course') {
16131: if (exists($filter->{'instcodefilter'})) {
16132: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16133: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16134: if ($codedom) {
16135: $officialjs = 1;
16136: ($instcodeform,$jscript,$$numtitlesref) =
16137: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16138: $officialjs,$codetitlesref);
16139: if ($jscript) {
16140: $jscript = '<script type="text/javascript">'."\n".
16141: '// <![CDATA['."\n".
16142: $jscript."\n".
16143: '// ]]>'."\n".
16144: '</script>'."\n";
16145: }
16146: }
16147: if ($instcodeform eq '') {
16148: $instcodeform =
16149: '<input type="text" name="instcodefilter" size="10" value="'.
16150: $list->{'instcodefilter'}.'" />';
16151: $instcodetitle = $lt{'ins'};
16152: } else {
16153: $instcodetitle = $lt{'inc'};
16154: }
16155: if ($fixeddom) {
16156: $instcodetitle .= '<br />('.$codedom.')';
16157: }
16158: }
16159: }
16160: my $output = qq|
16161: <form method="post" name="filterpicker" action="$action">
16162: <input type="hidden" name="form" value="$formname" />
16163: |;
16164: if ($formname eq 'modifycourse') {
16165: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16166: '<input type="hidden" name="prevphase" value="'.
16167: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 16168: } elsif ($formname eq 'quotacheck') {
16169: $output .= qq|
16170: <input type="hidden" name="sortby" value="" />
16171: <input type="hidden" name="sortorder" value="" />
16172: |;
16173: } else {
1.1075.2.69 raeburn 16174: my $name_input;
16175: if ($cnameelement ne '') {
16176: $name_input = '<input type="hidden" name="cnameelement" value="'.
16177: $cnameelement.'" />';
16178: }
16179: $output .= qq|
16180: <input type="hidden" name="cnumelement" value="$cnumelement" />
16181: <input type="hidden" name="cdomelement" value="$cdomelement" />
16182: $name_input
16183: $roleelement
16184: $multelement
16185: $typeelement
16186: |;
16187: if ($formname eq 'portform') {
16188: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16189: }
16190: }
16191: if ($fixeddom) {
16192: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16193: }
16194: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16195: if ($sincefilterform) {
16196: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16197: .$sincefilterform
16198: .&Apache::lonhtmlcommon::row_closure();
16199: }
16200: if ($createdfilterform) {
16201: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16202: .$createdfilterform
16203: .&Apache::lonhtmlcommon::row_closure();
16204: }
16205: if ($domainselectform) {
16206: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16207: .$domainselectform
16208: .&Apache::lonhtmlcommon::row_closure();
16209: }
16210: if ($typeselectform) {
16211: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16212: $output .= $typeselectform;
16213: } else {
16214: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16215: .$typeselectform
16216: .&Apache::lonhtmlcommon::row_closure();
16217: }
16218: }
16219: if ($instcodeform) {
16220: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16221: .$instcodeform
16222: .&Apache::lonhtmlcommon::row_closure();
16223: }
16224: if (exists($filter->{'ownerfilter'})) {
16225: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16226: '<table><tr><td>'.&mt('Username').'<br />'.
16227: '<input type="text" name="ownerfilter" size="20" value="'.
16228: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16229: $ownerdomselectform.'</td></tr></table>'.
16230: &Apache::lonhtmlcommon::row_closure();
16231: }
16232: if (exists($filter->{'personfilter'})) {
16233: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16234: '<table><tr><td>'.&mt('Username').'<br />'.
16235: '<input type="text" name="personfilter" size="20" value="'.
16236: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16237: $persondomselectform.'</td></tr></table>'.
16238: &Apache::lonhtmlcommon::row_closure();
16239: }
16240: if (exists($filter->{'coursefilter'})) {
16241: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16242: .'<input type="text" name="coursefilter" size="25" value="'
16243: .$list->{'coursefilter'}.'" />'
16244: .&Apache::lonhtmlcommon::row_closure();
16245: }
16246: if ($cloneableonlyform) {
16247: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16248: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16249: }
16250: if (exists($filter->{'descriptfilter'})) {
16251: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16252: .'<input type="text" name="descriptfilter" size="40" value="'
16253: .$list->{'descriptfilter'}.'" />'
16254: .&Apache::lonhtmlcommon::row_closure(1);
16255: }
16256: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16257: '<input type="hidden" name="updater" value="" />'."\n".
16258: '<input type="submit" name="gosearch" value="'.
16259: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16260: return $jscript.$clonewarning.$output;
16261: }
16262:
16263: =pod
16264:
16265: =item * &timebased_select_form()
16266:
16267: Create markup for a dropdown list used to select a time-based
16268: filter e.g., Course Activity, Course Created, when searching for courses
16269: or communities
16270:
16271: Inputs:
16272:
16273: item - name of form element (sincefilter or createdfilter)
16274:
16275: filter - anonymous hash of criteria and their values
16276:
16277: Returns: HTML for a select box contained a blank, then six time selections,
16278: with value set in incoming form variables currently selected.
16279:
16280: Side Effects: None
16281:
16282: =cut
16283:
16284: sub timebased_select_form {
16285: my ($item,$filter) = @_;
16286: if (ref($filter) eq 'HASH') {
16287: $filter->{$item} =~ s/[^\d-]//g;
16288: if (!$filter->{$item}) { $filter->{$item}=-1; }
16289: return &select_form(
16290: $filter->{$item},
16291: $item,
16292: { '-1' => '',
16293: '86400' => &mt('today'),
16294: '604800' => &mt('last week'),
16295: '2592000' => &mt('last month'),
16296: '7776000' => &mt('last three months'),
16297: '15552000' => &mt('last six months'),
16298: '31104000' => &mt('last year'),
16299: 'select_form_order' =>
16300: ['-1','86400','604800','2592000','7776000',
16301: '15552000','31104000']});
16302: }
16303: }
16304:
16305: =pod
16306:
16307: =item * &js_changer()
16308:
16309: Create script tag containing Javascript used to submit course search form
16310: when course type or domain is changed, and also to hide 'Searching ...' on
16311: page load completion for page showing search result.
16312:
16313: Inputs: None
16314:
16315: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16316:
16317: Side Effects: None
16318:
16319: =cut
16320:
16321: sub js_changer {
16322: return <<ENDJS;
16323: <script type="text/javascript">
16324: // <![CDATA[
16325: function updateFilters(caller) {
16326: if (typeof(caller) != "undefined") {
16327: document.filterpicker.updater.value = caller.name;
16328: }
16329: document.filterpicker.submit();
16330: }
16331:
16332: function hideSearching() {
16333: if (document.getElementById('searching')) {
16334: document.getElementById('searching').style.display = 'none';
16335: }
16336: return;
16337: }
16338:
16339: // ]]>
16340: </script>
16341:
16342: ENDJS
16343: }
16344:
16345: =pod
16346:
16347: =item * &search_courses()
16348:
16349: Process selected filters form course search form and pass to lonnet::courseiddump
16350: to retrieve a hash for which keys are courseIDs which match the selected filters.
16351:
16352: Inputs:
16353:
16354: dom - domain being searched
16355:
16356: type - course type ('Course' or 'Community' or '.' if any).
16357:
16358: filter - anonymous hash of criteria and their values
16359:
16360: numtitles - for institutional codes - number of categories
16361:
16362: cloneruname - optional username of new course owner
16363:
16364: clonerudom - optional domain of new course owner
16365:
1.1075.2.95 raeburn 16366: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16367: (used when DC is using course creation form)
16368:
16369: codetitles - reference to array of titles of components in institutional codes (official courses).
16370:
1.1075.2.95 raeburn 16371: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16372: (and so can clone automatically)
16373:
16374: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16375:
16376: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16377: courses to clone
1.1075.2.69 raeburn 16378:
16379: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16380:
16381:
16382: Side Effects: None
16383:
16384: =cut
16385:
16386:
16387: sub search_courses {
1.1075.2.95 raeburn 16388: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16389: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16390: my (%courses,%showcourses,$cloner);
16391: if (($filter->{'ownerfilter'} ne '') ||
16392: ($filter->{'ownerdomfilter'} ne '')) {
16393: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16394: $filter->{'ownerdomfilter'};
16395: }
16396: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16397: if (!$filter->{$item}) {
16398: $filter->{$item}='.';
16399: }
16400: }
16401: my $now = time;
16402: my $timefilter =
16403: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16404: my ($createdbefore,$createdafter);
16405: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16406: $createdbefore = $now;
16407: $createdafter = $now-$filter->{'createdfilter'};
16408: }
16409: my ($instcodefilter,$regexpok);
16410: if ($numtitles) {
16411: if ($env{'form.official'} eq 'on') {
16412: $instcodefilter =
16413: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16414: $regexpok = 1;
16415: } elsif ($env{'form.official'} eq 'off') {
16416: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16417: unless ($instcodefilter eq '') {
16418: $regexpok = -1;
16419: }
16420: }
16421: } else {
16422: $instcodefilter = $filter->{'instcodefilter'};
16423: }
16424: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16425: if ($type eq '') { $type = '.'; }
16426:
16427: if (($clonerudom ne '') && ($cloneruname ne '')) {
16428: $cloner = $cloneruname.':'.$clonerudom;
16429: }
16430: %courses = &Apache::lonnet::courseiddump($dom,
16431: $filter->{'descriptfilter'},
16432: $timefilter,
16433: $instcodefilter,
16434: $filter->{'combownerfilter'},
16435: $filter->{'coursefilter'},
16436: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16437: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16438: $filter->{'cloneableonly'},
16439: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16440: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16441: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16442: my $ccrole;
16443: if ($type eq 'Community') {
16444: $ccrole = 'co';
16445: } else {
16446: $ccrole = 'cc';
16447: }
16448: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16449: $filter->{'persondomfilter'},
16450: 'userroles',undef,
16451: [$ccrole,'in','ad','ep','ta','cr'],
16452: $dom);
16453: foreach my $role (keys(%rolehash)) {
16454: my ($cnum,$cdom,$courserole) = split(':',$role);
16455: my $cid = $cdom.'_'.$cnum;
16456: if (exists($courses{$cid})) {
16457: if (ref($courses{$cid}) eq 'HASH') {
16458: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16459: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16460: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16461: }
16462: } else {
16463: $courses{$cid}{roles} = [$courserole];
16464: }
16465: $showcourses{$cid} = $courses{$cid};
16466: }
16467: }
16468: }
16469: %courses = %showcourses;
16470: }
16471: return %courses;
16472: }
16473:
16474: =pod
16475:
16476: =back
16477:
1.1075.2.88 raeburn 16478: =head1 Routines for version requirements for current course.
16479:
16480: =over 4
16481:
16482: =item * &check_release_required()
16483:
16484: Compares required LON-CAPA version with version on server, and
16485: if required version is newer looks for a server with the required version.
16486:
16487: Looks first at servers in user's owen domain; if none suitable, looks at
16488: servers in course's domain are permitted to host sessions for user's domain.
16489:
16490: Inputs:
16491:
16492: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16493:
16494: $courseid - Course ID of current course
16495:
16496: $rolecode - User's current role in course (for switchserver query string).
16497:
16498: $required - LON-CAPA version needed by course (format: Major.Minor).
16499:
16500:
16501: Returns:
16502:
16503: $switchserver - query string tp append to /adm/switchserver call (if
16504: current server's LON-CAPA version is too old.
16505:
16506: $warning - Message is displayed if no suitable server could be found.
16507:
16508: =cut
16509:
16510: sub check_release_required {
16511: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16512: my ($switchserver,$warning);
16513: if ($required ne '') {
16514: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16515: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16516: if ($reqdmajor ne '' && $reqdminor ne '') {
16517: my $otherserver;
16518: if (($major eq '' && $minor eq '') ||
16519: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16520: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16521: my $switchlcrev =
16522: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16523: $userdomserver);
16524: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16525: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16526: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16527: my $cdom = $env{'course.'.$courseid.'.domain'};
16528: if ($cdom ne $env{'user.domain'}) {
16529: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16530: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16531: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16532: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16533: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16534: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16535: my $canhost =
16536: &Apache::lonnet::can_host_session($env{'user.domain'},
16537: $coursedomserver,
16538: $remoterev,
16539: $udomdefaults{'remotesessions'},
16540: $defdomdefaults{'hostedsessions'});
16541:
16542: if ($canhost) {
16543: $otherserver = $coursedomserver;
16544: } else {
16545: $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.");
16546: }
16547: } else {
16548: $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).");
16549: }
16550: } else {
16551: $otherserver = $userdomserver;
16552: }
16553: }
16554: if ($otherserver ne '') {
16555: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16556: }
16557: }
16558: }
16559: return ($switchserver,$warning);
16560: }
16561:
16562: =pod
16563:
16564: =item * &check_release_result()
16565:
16566: Inputs:
16567:
16568: $switchwarning - Warning message if no suitable server found to host session.
16569:
16570: $switchserver - query string to append to /adm/switchserver containing lonHostID
16571: and current role.
16572:
16573: Returns: HTML to display with information about requirement to switch server.
16574: Either displaying warning with link to Roles/Courses screen or
16575: display link to switchserver.
16576:
1.1075.2.69 raeburn 16577: =cut
16578:
1.1075.2.88 raeburn 16579: sub check_release_result {
16580: my ($switchwarning,$switchserver) = @_;
16581: my $output = &start_page('Selected course unavailable on this server').
16582: '<p class="LC_warning">';
16583: if ($switchwarning) {
16584: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16585: if (&show_course()) {
16586: $output .= &mt('Display courses');
16587: } else {
16588: $output .= &mt('Display roles');
16589: }
16590: $output .= '</a>';
16591: } elsif ($switchserver) {
16592: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16593: '<br />'.
16594: '<a href="/adm/switchserver?'.$switchserver.'">'.
16595: &mt('Switch Server').
16596: '</a>';
16597: }
16598: $output .= '</p>'.&end_page();
16599: return $output;
16600: }
16601:
16602: =pod
16603:
16604: =item * &needs_coursereinit()
16605:
16606: Determine if course contents stored for user's session needs to be
16607: refreshed, because content has changed since "Big Hash" last tied.
16608:
16609: Check for change is made if time last checked is more than 10 minutes ago
16610: (by default).
16611:
16612: Inputs:
16613:
16614: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16615:
16616: $interval (optional) - Time which may elapse (in s) between last check for content
16617: change in current course. (default: 600 s).
16618:
16619: Returns: an array; first element is:
16620:
16621: =over 4
16622:
16623: 'switch' - if content updates mean user's session
16624: needs to be switched to a server running a newer LON-CAPA version
16625:
16626: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16627: on current server hosting user's session
16628:
16629: '' - if no action required.
16630:
16631: =back
16632:
16633: If first item element is 'switch':
16634:
16635: second item is $switchwarning - Warning message if no suitable server found to host session.
16636:
16637: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16638: and current role.
16639:
16640: otherwise: no other elements returned.
16641:
16642: =back
16643:
16644: =cut
16645:
16646: sub needs_coursereinit {
16647: my ($loncaparev,$interval) = @_;
16648: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16649: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16650: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16651: my $now = time;
16652: if ($interval eq '') {
16653: $interval = 600;
16654: }
16655: if (($now-$env{'request.course.timechecked'})>$interval) {
16656: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16657: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16658: if ($lastchange > $env{'request.course.tied'}) {
16659: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16660: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16661: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16662: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16663: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16664: $curr_reqd_hash{'internal.releaserequired'}});
16665: my ($switchserver,$switchwarning) =
16666: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16667: $curr_reqd_hash{'internal.releaserequired'});
16668: if ($switchwarning ne '' || $switchserver ne '') {
16669: return ('switch',$switchwarning,$switchserver);
16670: }
16671: }
16672: }
16673: return ('update');
16674: }
16675: }
16676: return ();
16677: }
1.1075.2.69 raeburn 16678:
1.1075.2.11 raeburn 16679: sub update_content_constraints {
16680: my ($cdom,$cnum,$chome,$cid) = @_;
16681: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16682: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16683: my %checkresponsetypes;
16684: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16685: my ($item,$name,$value) = split(/:/,$key);
16686: if ($item eq 'resourcetag') {
16687: if ($name eq 'responsetype') {
16688: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16689: }
16690: }
16691: }
16692: my $navmap = Apache::lonnavmaps::navmap->new();
16693: if (defined($navmap)) {
16694: my %allresponses;
16695: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16696: my %responses = $res->responseTypes();
16697: foreach my $key (keys(%responses)) {
16698: next unless(exists($checkresponsetypes{$key}));
16699: $allresponses{$key} += $responses{$key};
16700: }
16701: }
16702: foreach my $key (keys(%allresponses)) {
16703: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16704: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16705: ($reqdmajor,$reqdminor) = ($major,$minor);
16706: }
16707: }
16708: undef($navmap);
16709: }
16710: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16711: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16712: }
16713: return;
16714: }
16715:
1.1075.2.27 raeburn 16716: sub allmaps_incourse {
16717: my ($cdom,$cnum,$chome,$cid) = @_;
16718: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16719: $cid = $env{'request.course.id'};
16720: $cdom = $env{'course.'.$cid.'.domain'};
16721: $cnum = $env{'course.'.$cid.'.num'};
16722: $chome = $env{'course.'.$cid.'.home'};
16723: }
16724: my %allmaps = ();
16725: my $lastchange =
16726: &Apache::lonnet::get_coursechange($cdom,$cnum);
16727: if ($lastchange > $env{'request.course.tied'}) {
16728: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16729: unless ($ferr) {
16730: &update_content_constraints($cdom,$cnum,$chome,$cid);
16731: }
16732: }
16733: my $navmap = Apache::lonnavmaps::navmap->new();
16734: if (defined($navmap)) {
16735: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16736: $allmaps{$res->src()} = 1;
16737: }
16738: }
16739: return \%allmaps;
16740: }
16741:
1.1075.2.11 raeburn 16742: sub parse_supplemental_title {
16743: my ($title) = @_;
16744:
16745: my ($foldertitle,$renametitle);
16746: if ($title =~ /&&&/) {
16747: $title = &HTML::Entites::decode($title);
16748: }
16749: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16750: $renametitle=$4;
16751: my ($time,$uname,$udom) = ($1,$2,$3);
16752: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16753: my $name = &plainname($uname,$udom);
16754: $name = &HTML::Entities::encode($name,'"<>&\'');
16755: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16756: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16757: $name.': <br />'.$foldertitle;
16758: }
16759: if (wantarray) {
16760: return ($title,$foldertitle,$renametitle);
16761: }
16762: return $title;
16763: }
16764:
1.1075.2.43 raeburn 16765: sub recurse_supplemental {
16766: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16767: if ($suppmap) {
16768: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16769: if ($fatal) {
16770: $errors ++;
16771: } else {
16772: if ($#LONCAPA::map::resources > 0) {
16773: foreach my $res (@LONCAPA::map::resources) {
16774: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16775: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 16776: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16777: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 16778: } else {
16779: $numfiles ++;
16780: }
16781: }
16782: }
16783: }
16784: }
16785: }
16786: return ($numfiles,$errors);
16787: }
16788:
1.1075.2.18 raeburn 16789: sub symb_to_docspath {
1.1075.2.119 raeburn 16790: my ($symb,$navmapref) = @_;
16791: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 16792: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16793: if ($resurl=~/\.(sequence|page)$/) {
16794: $mapurl=$resurl;
16795: } elsif ($resurl eq 'adm/navmaps') {
16796: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16797: }
16798: my $mapresobj;
1.1075.2.119 raeburn 16799: unless (ref($$navmapref)) {
16800: $$navmapref = Apache::lonnavmaps::navmap->new();
16801: }
16802: if (ref($$navmapref)) {
16803: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 16804: }
16805: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16806: my $type=$2;
16807: my $path;
16808: if (ref($mapresobj)) {
16809: my $pcslist = $mapresobj->map_hierarchy();
16810: if ($pcslist ne '') {
16811: foreach my $pc (split(/,/,$pcslist)) {
16812: next if ($pc <= 1);
1.1075.2.119 raeburn 16813: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 16814: if (ref($res)) {
16815: my $thisurl = $res->src();
16816: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16817: my $thistitle = $res->title();
16818: $path .= '&'.
16819: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 16820: &escape($thistitle).
1.1075.2.18 raeburn 16821: ':'.$res->randompick().
16822: ':'.$res->randomout().
16823: ':'.$res->encrypted().
16824: ':'.$res->randomorder().
16825: ':'.$res->is_page();
16826: }
16827: }
16828: }
16829: $path =~ s/^\&//;
16830: my $maptitle = $mapresobj->title();
16831: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16832: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16833: }
16834: $path .= (($path ne '')? '&' : '').
16835: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16836: &escape($maptitle).
1.1075.2.18 raeburn 16837: ':'.$mapresobj->randompick().
16838: ':'.$mapresobj->randomout().
16839: ':'.$mapresobj->encrypted().
16840: ':'.$mapresobj->randomorder().
16841: ':'.$mapresobj->is_page();
16842: } else {
16843: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16844: my $ispage = (($type eq 'page')? 1 : '');
16845: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16846: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16847: }
16848: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16849: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 16850: }
16851: unless ($mapurl eq 'default') {
16852: $path = 'default&'.
1.1075.2.46 raeburn 16853: &escape('Main Content').
1.1075.2.18 raeburn 16854: ':::::&'.$path;
16855: }
16856: return $path;
16857: }
16858:
1.1075.2.14 raeburn 16859: sub captcha_display {
1.1075.2.137 raeburn 16860: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 16861: my ($output,$error);
1.1075.2.107 raeburn 16862: my ($captcha,$pubkey,$privkey,$version) =
1.1075.2.137 raeburn 16863: &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 16864: if ($captcha eq 'original') {
16865: $output = &create_captcha();
16866: unless ($output) {
16867: $error = 'captcha';
16868: }
16869: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16870: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 16871: unless ($output) {
16872: $error = 'recaptcha';
16873: }
16874: }
1.1075.2.107 raeburn 16875: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 16876: }
16877:
16878: sub captcha_response {
1.1075.2.137 raeburn 16879: my ($context,$lonhost,$defdom) = @_;
1.1075.2.14 raeburn 16880: my ($captcha_chk,$captcha_error);
1.1075.2.137 raeburn 16881: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1075.2.14 raeburn 16882: if ($captcha eq 'original') {
16883: ($captcha_chk,$captcha_error) = &check_captcha();
16884: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16885: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 16886: } else {
16887: $captcha_chk = 1;
16888: }
16889: return ($captcha_chk,$captcha_error);
16890: }
16891:
16892: sub get_captcha_config {
1.1075.2.137 raeburn 16893: my ($context,$lonhost,$dom_in_effect) = @_;
1.1075.2.107 raeburn 16894: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 16895: my $hostname = &Apache::lonnet::hostname($lonhost);
16896: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16897: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16898: if ($context eq 'usercreation') {
16899: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16900: if (ref($domconfig{$context}) eq 'HASH') {
16901: $hashtocheck = $domconfig{$context}{'cancreate'};
16902: if (ref($hashtocheck) eq 'HASH') {
16903: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16904: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16905: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16906: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16907: }
16908: if ($privkey && $pubkey) {
16909: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16910: $version = $hashtocheck->{'recaptchaversion'};
16911: if ($version ne '2') {
16912: $version = 1;
16913: }
1.1075.2.14 raeburn 16914: } else {
16915: $captcha = 'original';
16916: }
16917: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16918: $captcha = 'original';
16919: }
16920: }
16921: } else {
16922: $captcha = 'captcha';
16923: }
16924: } elsif ($context eq 'login') {
16925: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16926: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16927: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16928: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
16929: if ($privkey && $pubkey) {
16930: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16931: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
16932: if ($version ne '2') {
16933: $version = 1;
16934: }
1.1075.2.14 raeburn 16935: } else {
16936: $captcha = 'original';
16937: }
16938: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16939: $captcha = 'original';
16940: }
1.1075.2.137 raeburn 16941: } elsif ($context eq 'passwords') {
16942: if ($dom_in_effect) {
16943: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
16944: if ($passwdconf{'captcha'} eq 'recaptcha') {
16945: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
16946: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
16947: $privkey = $passwdconf{'recaptchakeys'}{'private'};
16948: }
16949: if ($privkey && $pubkey) {
16950: $captcha = 'recaptcha';
16951: $version = $passwdconf{'recaptchaversion'};
16952: if ($version ne '2') {
16953: $version = 1;
16954: }
16955: } else {
16956: $captcha = 'original';
16957: }
16958: } elsif ($passwdconf{'captcha'} ne 'notused') {
16959: $captcha = 'original';
16960: }
16961: }
1.1075.2.14 raeburn 16962: }
1.1075.2.107 raeburn 16963: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 16964: }
16965:
16966: sub create_captcha {
16967: my %captcha_params = &captcha_settings();
16968: my ($output,$maxtries,$tries) = ('',10,0);
16969: while ($tries < $maxtries) {
16970: $tries ++;
16971: my $captcha = Authen::Captcha->new (
16972: output_folder => $captcha_params{'output_dir'},
16973: data_folder => $captcha_params{'db_dir'},
16974: );
16975: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16976:
16977: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16978: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16979: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 16980: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16981: '<br />'.
16982: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 16983: last;
16984: }
16985: }
16986: return $output;
16987: }
16988:
16989: sub captcha_settings {
16990: my %captcha_params = (
16991: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16992: www_output_dir => "/captchaspool",
16993: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16994: numchars => '5',
16995: );
16996: return %captcha_params;
16997: }
16998:
16999: sub check_captcha {
17000: my ($captcha_chk,$captcha_error);
17001: my $code = $env{'form.code'};
17002: my $md5sum = $env{'form.crypt'};
17003: my %captcha_params = &captcha_settings();
17004: my $captcha = Authen::Captcha->new(
17005: output_folder => $captcha_params{'output_dir'},
17006: data_folder => $captcha_params{'db_dir'},
17007: );
1.1075.2.26 raeburn 17008: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 17009: my %captcha_hash = (
17010: 0 => 'Code not checked (file error)',
17011: -1 => 'Failed: code expired',
17012: -2 => 'Failed: invalid code (not in database)',
17013: -3 => 'Failed: invalid code (code does not match crypt)',
17014: );
17015: if ($captcha_chk != 1) {
17016: $captcha_error = $captcha_hash{$captcha_chk}
17017: }
17018: return ($captcha_chk,$captcha_error);
17019: }
17020:
17021: sub create_recaptcha {
1.1075.2.107 raeburn 17022: my ($pubkey,$version) = @_;
17023: if ($version >= 2) {
17024: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17025: } else {
17026: my $use_ssl;
17027: if ($ENV{'SERVER_PORT'} == 443) {
17028: $use_ssl = 1;
17029: }
17030: my $captcha = Captcha::reCAPTCHA->new;
17031: return $captcha->get_options_setter({theme => 'white'})."\n".
17032: $captcha->get_html($pubkey,undef,$use_ssl).
17033: &mt('If the text is hard to read, [_1] will replace them.',
17034: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17035: '<br /><br />';
17036: }
1.1075.2.14 raeburn 17037: }
17038:
17039: sub check_recaptcha {
1.1075.2.107 raeburn 17040: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 17041: my $captcha_chk;
1.1075.2.107 raeburn 17042: if ($version >= 2) {
17043: my $ua = LWP::UserAgent->new;
17044: $ua->timeout(10);
17045: my %info = (
17046: secret => $privkey,
17047: response => $env{'form.g-recaptcha-response'},
17048: remoteip => $ENV{'REMOTE_ADDR'},
17049: );
17050: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17051: if ($response->is_success) {
17052: my $data = JSON::DWIW->from_json($response->decoded_content);
17053: if (ref($data) eq 'HASH') {
17054: if ($data->{'success'}) {
17055: $captcha_chk = 1;
17056: }
17057: }
17058: }
17059: } else {
17060: my $captcha = Captcha::reCAPTCHA->new;
17061: my $captcha_result =
17062: $captcha->check_answer(
17063: $privkey,
17064: $ENV{'REMOTE_ADDR'},
17065: $env{'form.recaptcha_challenge_field'},
17066: $env{'form.recaptcha_response_field'},
17067: );
17068: if ($captcha_result->{is_valid}) {
17069: $captcha_chk = 1;
17070: }
1.1075.2.14 raeburn 17071: }
17072: return $captcha_chk;
17073: }
17074:
1.1075.2.64 raeburn 17075: sub emailusername_info {
1.1075.2.103 raeburn 17076: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 17077: my %titles = &Apache::lonlocal::texthash (
17078: lastname => 'Last Name',
17079: firstname => 'First Name',
17080: institution => 'School/college/university',
17081: location => "School's city, state/province, country",
17082: web => "School's web address",
17083: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 17084: id => 'Student/Employee ID',
1.1075.2.64 raeburn 17085: );
17086: return (\@fields,\%titles);
17087: }
17088:
1.1075.2.56 raeburn 17089: sub cleanup_html {
17090: my ($incoming) = @_;
17091: my $outgoing;
17092: if ($incoming ne '') {
17093: $outgoing = $incoming;
17094: $outgoing =~ s/;/;/g;
17095: $outgoing =~ s/\#/#/g;
17096: $outgoing =~ s/\&/&/g;
17097: $outgoing =~ s/</</g;
17098: $outgoing =~ s/>/>/g;
17099: $outgoing =~ s/\(/(/g;
17100: $outgoing =~ s/\)/)/g;
17101: $outgoing =~ s/"/"/g;
17102: $outgoing =~ s/'/'/g;
17103: $outgoing =~ s/\$/$/g;
17104: $outgoing =~ s{/}{/}g;
17105: $outgoing =~ s/=/=/g;
17106: $outgoing =~ s/\\/\/g
17107: }
17108: return $outgoing;
17109: }
17110:
1.1075.2.74 raeburn 17111: # Checks for critical messages and returns a redirect url if one exists.
17112: # $interval indicates how often to check for messages.
17113: sub critical_redirect {
17114: my ($interval) = @_;
17115: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17116: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17117: $env{'user.name'});
17118: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
17119: my $redirecturl;
17120: if ($what[0]) {
17121: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17122: $redirecturl='/adm/email?critical=display';
17123: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17124: return (1, $url);
17125: }
17126: }
17127: }
17128: return ();
17129: }
17130:
1.1075.2.64 raeburn 17131: # Use:
17132: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17133: #
17134: ##################################################
17135: # password associated functions #
17136: ##################################################
17137: sub des_keys {
17138: # Make a new key for DES encryption.
17139: # Each key has two parts which are returned separately.
17140: # Please note: Each key must be passed through the &hex function
17141: # before it is output to the web browser. The hex versions cannot
17142: # be used to decrypt.
17143: my @hexstr=('0','1','2','3','4','5','6','7',
17144: '8','9','a','b','c','d','e','f');
17145: my $lkey='';
17146: for (0..7) {
17147: $lkey.=$hexstr[rand(15)];
17148: }
17149: my $ukey='';
17150: for (0..7) {
17151: $ukey.=$hexstr[rand(15)];
17152: }
17153: return ($lkey,$ukey);
17154: }
17155:
17156: sub des_decrypt {
17157: my ($key,$cyphertext) = @_;
17158: my $keybin=pack("H16",$key);
17159: my $cypher;
17160: if ($Crypt::DES::VERSION>=2.03) {
17161: $cypher=new Crypt::DES $keybin;
17162: } else {
17163: $cypher=new DES $keybin;
17164: }
1.1075.2.106 raeburn 17165: my $plaintext='';
17166: my $cypherlength = length($cyphertext);
17167: my $numchunks = int($cypherlength/32);
17168: for (my $j=0; $j<$numchunks; $j++) {
17169: my $start = $j*32;
17170: my $cypherblock = substr($cyphertext,$start,32);
17171: my $chunk =
17172: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17173: $chunk .=
17174: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17175: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17176: $plaintext .= $chunk;
17177: }
1.1075.2.64 raeburn 17178: return $plaintext;
17179: }
17180:
1.1075.2.135 raeburn 17181: sub is_nonframeable {
17182: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
17183: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
17184: return if (($remprotocol eq '') || ($remhost eq ''));
17185:
17186: $remprotocol = lc($remprotocol);
17187: $remhost = lc($remhost);
17188: my $remport = 80;
17189: if ($remprotocol eq 'https') {
17190: $remport = 443;
17191: }
17192: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
17193: if ($cached) {
17194: unless ($nocache) {
17195: if ($result) {
17196: return 1;
17197: } else {
17198: return 0;
17199: }
17200: }
17201: }
17202: my $uselink;
17203: my $request = new HTTP::Request('HEAD',$url);
1.1075.2.142 raeburn 17204: my $ua = LWP::UserAgent->new;
17205: $ua->timeout(5);
17206: my $response=$ua->request($request);
1.1075.2.135 raeburn 17207: if ($response->is_success()) {
17208: my $secpolicy = lc($response->header('content-security-policy'));
17209: my $xframeop = lc($response->header('x-frame-options'));
17210: $secpolicy =~ s/^\s+|\s+$//g;
17211: $xframeop =~ s/^\s+|\s+$//g;
17212: if (($secpolicy ne '') || ($xframeop ne '')) {
17213: my $remotehost = $remprotocol.'://'.$remhost;
17214: my ($origin,$protocol,$port);
17215: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
17216: $port = $ENV{'SERVER_PORT'};
17217: } else {
17218: $port = 80;
17219: }
17220: if ($absolute eq '') {
17221: $protocol = 'http:';
17222: if ($port == 443) {
17223: $protocol = 'https:';
17224: }
17225: $origin = $protocol.'//'.lc($hostname);
17226: } else {
17227: $origin = lc($absolute);
17228: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
17229: }
17230: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
17231: my $framepolicy = $1;
17232: $framepolicy =~ s/^\s+|\s+$//g;
17233: my @policies = split(/\s+/,$framepolicy);
17234: if (@policies) {
17235: if (grep(/^\Q'none'\E$/,@policies)) {
17236: $uselink = 1;
17237: } else {
17238: $uselink = 1;
17239: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
17240: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
17241: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
17242: undef($uselink);
17243: }
17244: if ($uselink) {
17245: if (grep(/^\Q'self'\E$/,@policies)) {
17246: if (($origin ne '') && ($remotehost eq $origin)) {
17247: undef($uselink);
17248: }
17249: }
17250: }
17251: if ($uselink) {
17252: my @possok;
17253: if ($ip ne '') {
17254: push(@possok,$ip);
17255: }
17256: my $hoststr = '';
17257: foreach my $part (reverse(split(/\./,$hostname))) {
17258: if ($hoststr eq '') {
17259: $hoststr = $part;
17260: } else {
17261: $hoststr = "$part.$hoststr";
17262: }
17263: if ($hoststr eq $hostname) {
17264: push(@possok,$hostname);
17265: } else {
17266: push(@possok,"*.$hoststr");
17267: }
17268: }
17269: if (@possok) {
17270: foreach my $poss (@possok) {
17271: last if (!$uselink);
17272: foreach my $policy (@policies) {
17273: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
17274: undef($uselink);
17275: last;
17276: }
17277: }
17278: }
17279: }
17280: }
17281: }
17282: }
17283: } elsif ($xframeop ne '') {
17284: $uselink = 1;
17285: my @policies = split(/\s*,\s*/,$xframeop);
17286: if (@policies) {
17287: unless (grep(/^deny$/,@policies)) {
17288: if ($origin ne '') {
17289: if (grep(/^sameorigin$/,@policies)) {
17290: if ($remotehost eq $origin) {
17291: undef($uselink);
17292: }
17293: }
17294: if ($uselink) {
17295: foreach my $policy (@policies) {
17296: if ($policy =~ /^allow-from\s*(.+)$/) {
17297: my $allowfrom = $1;
17298: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
17299: undef($uselink);
17300: last;
17301: }
17302: }
17303: }
17304: }
17305: }
17306: }
17307: }
17308: }
17309: }
17310: }
17311: if ($nocache) {
17312: if ($cached) {
17313: my $devalidate;
17314: if ($uselink && !$result) {
17315: $devalidate = 1;
17316: } elsif (!$uselink && $result) {
17317: $devalidate = 1;
17318: }
17319: if ($devalidate) {
17320: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
17321: }
17322: }
17323: } else {
17324: if ($uselink) {
17325: $result = 1;
17326: } else {
17327: $result = 0;
17328: }
17329: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
17330: }
17331: return $uselink;
17332: }
17333:
1.112 bowersj2 17334: 1;
17335: __END__;
1.41 ng 17336:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>