Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.128
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.128! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.127 2017/04/02 03:09:27 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.657 raeburn 74: use DateTime::TimeZone;
1.1075.2.102 raeburn 75: use DateTime::Locale;
1.1075.2.94 raeburn 76: use Encode();
1.1075.2.14 raeburn 77: use Authen::Captcha;
78: use Captcha::reCAPTCHA;
1.1075.2.107 raeburn 79: use JSON::DWIW;
80: use LWP::UserAgent;
1.1075.2.64 raeburn 81: use Crypt::DES;
82: use DynaLoader; # for Crypt::DES version
1.1075.2.128! raeburn 83: use File::Copy();
! 84: use File::Path();
1.117 www 85:
1.517 raeburn 86: # ---------------------------------------------- Designs
87: use vars qw(%defaultdesign);
88:
1.22 www 89: my $readit;
90:
1.517 raeburn 91:
1.157 matthew 92: ##
93: ## Global Variables
94: ##
1.46 matthew 95:
1.643 foxr 96:
97: # ----------------------------------------------- SSI with retries:
98: #
99:
100: =pod
101:
1.648 raeburn 102: =head1 Server Side include with retries:
1.643 foxr 103:
104: =over 4
105:
1.648 raeburn 106: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 107:
108: Performs an ssi with some number of retries. Retries continue either
109: until the result is ok or until the retry count supplied by the
110: caller is exhausted.
111:
112: Inputs:
1.648 raeburn 113:
114: =over 4
115:
1.643 foxr 116: resource - Identifies the resource to insert.
1.648 raeburn 117:
1.643 foxr 118: retries - Count of the number of retries allowed.
1.648 raeburn 119:
1.643 foxr 120: form - Hash that identifies the rendering options.
121:
1.648 raeburn 122: =back
123:
124: Returns:
125:
126: =over 4
127:
1.643 foxr 128: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 129:
1.643 foxr 130: response - The response from the last attempt (which may or may not have been successful.
131:
1.648 raeburn 132: =back
133:
134: =back
135:
1.643 foxr 136: =cut
137:
138: sub ssi_with_retries {
139: my ($resource, $retries, %form) = @_;
140:
141:
142: my $ok = 0; # True if we got a good response.
143: my $content;
144: my $response;
145:
146: # Try to get the ssi done. within the retries count:
147:
148: do {
149: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
150: $ok = $response->is_success;
1.650 www 151: if (!$ok) {
152: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
153: }
1.643 foxr 154: $retries--;
155: } while (!$ok && ($retries > 0));
156:
157: if (!$ok) {
158: $content = ''; # On error return an empty content.
159: }
160: return ($content, $response);
161:
162: }
163:
164:
165:
1.20 www 166: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 167: my %language;
1.124 www 168: my %supported_language;
1.1048 foxr 169: my %latex_language; # For choosing hyphenation in <transl..>
170: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 171: my %cprtag;
1.192 taceyjo1 172: my %scprtag;
1.351 www 173: my %fe; my %fd; my %fm;
1.41 ng 174: my %category_extensions;
1.12 harris41 175:
1.46 matthew 176: # ---------------------------------------------- Thesaurus variables
1.144 matthew 177: #
178: # %Keywords:
179: # A hash used by &keyword to determine if a word is considered a keyword.
180: # $thesaurus_db_file
181: # Scalar containing the full path to the thesaurus database.
1.46 matthew 182:
183: my %Keywords;
184: my $thesaurus_db_file;
185:
1.144 matthew 186: #
187: # Initialize values from language.tab, copyright.tab, filetypes.tab,
188: # thesaurus.tab, and filecategories.tab.
189: #
1.18 www 190: BEGIN {
1.46 matthew 191: # Variable initialization
192: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
193: #
1.22 www 194: unless ($readit) {
1.12 harris41 195: # ------------------------------------------------------------------- languages
196: {
1.158 raeburn 197: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
198: '/language.tab';
1.1075.2.128! raeburn 199: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 200: while (my $line = <$fh>) {
201: next if ($line=~/^\#/);
202: chomp($line);
1.1048 foxr 203: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 204: $language{$key}=$val.' - '.$enc;
205: if ($sup) {
206: $supported_language{$key}=$sup;
207: }
1.1048 foxr 208: if ($latex) {
209: $latex_language_bykey{$key} = $latex;
210: $latex_language{$two} = $latex;
211: }
1.158 raeburn 212: }
213: close($fh);
214: }
1.12 harris41 215: }
216: # ------------------------------------------------------------------ copyrights
217: {
1.158 raeburn 218: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
219: '/copyright.tab';
1.1075.2.128! raeburn 220: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 221: while (my $line = <$fh>) {
222: next if ($line=~/^\#/);
223: chomp($line);
224: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 225: $cprtag{$key}=$val;
226: }
227: close($fh);
228: }
1.12 harris41 229: }
1.351 www 230: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 231: {
232: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
233: '/source_copyright.tab';
1.1075.2.128! raeburn 234: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 235: while (my $line = <$fh>) {
236: next if ($line =~ /^\#/);
237: chomp($line);
238: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 239: $scprtag{$key}=$val;
240: }
241: close($fh);
242: }
243: }
1.63 www 244:
1.517 raeburn 245: # -------------------------------------------------------------- default domain designs
1.63 www 246: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 247: my $designfile = $designdir.'/default.tab';
1.1075.2.128! raeburn 248: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 249: while (my $line = <$fh>) {
250: next if ($line =~ /^\#/);
251: chomp($line);
252: my ($key,$val)=(split(/\=/,$line));
253: if ($val) { $defaultdesign{$key}=$val; }
254: }
255: close($fh);
1.63 www 256: }
257:
1.15 harris41 258: # ------------------------------------------------------------- file categories
259: {
1.158 raeburn 260: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
261: '/filecategories.tab';
1.1075.2.128! raeburn 262: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 263: while (my $line = <$fh>) {
264: next if ($line =~ /^\#/);
265: chomp($line);
266: my ($extension,$category)=(split(/\s+/,$line,2));
1.1075.2.119 raeburn 267: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 268: }
269: close($fh);
270: }
271:
1.15 harris41 272: }
1.12 harris41 273: # ------------------------------------------------------------------ file types
274: {
1.158 raeburn 275: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
276: '/filetypes.tab';
1.1075.2.128! raeburn 277: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 278: while (my $line = <$fh>) {
279: next if ($line =~ /^\#/);
280: chomp($line);
281: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 282: if ($descr ne '') {
283: $fe{$ending}=lc($emb);
284: $fd{$ending}=$descr;
1.351 www 285: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 286: }
287: }
288: close($fh);
289: }
1.12 harris41 290: }
1.22 www 291: &Apache::lonnet::logthis(
1.705 tempelho 292: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 293: $readit=1;
1.46 matthew 294: } # end of unless($readit)
1.32 matthew 295:
296: }
1.112 bowersj2 297:
1.42 matthew 298: ###############################################################
299: ## HTML and Javascript Helper Functions ##
300: ###############################################################
301:
302: =pod
303:
1.112 bowersj2 304: =head1 HTML and Javascript Functions
1.42 matthew 305:
1.112 bowersj2 306: =over 4
307:
1.648 raeburn 308: =item * &browser_and_searcher_javascript()
1.112 bowersj2 309:
310: X<browsing, javascript>X<searching, javascript>Returns a string
311: containing javascript with two functions, C<openbrowser> and
312: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
313: tags.
1.42 matthew 314:
1.648 raeburn 315: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 316:
317: inputs: formname, elementname, only, omit
318:
319: formname and elementname indicate the name of the html form and name of
320: the element that the results of the browsing selection are to be placed in.
321:
322: Specifying 'only' will restrict the browser to displaying only files
1.185 www 323: with the given extension. Can be a comma separated list.
1.42 matthew 324:
325: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 326: with the given extension. Can be a comma separated list.
1.42 matthew 327:
1.648 raeburn 328: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 329:
330: Inputs: formname, elementname
331:
332: formname and elementname specify the name of the html form and the name
333: of the element the selection from the search results will be placed in.
1.542 raeburn 334:
1.42 matthew 335: =cut
336:
337: sub browser_and_searcher_javascript {
1.199 albertel 338: my ($mode)=@_;
339: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 340: my $resurl=&escape_single(&lastresurl());
1.42 matthew 341: return <<END;
1.219 albertel 342: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 343: var editbrowser = null;
1.135 albertel 344: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 345: var url = '$resurl/?';
1.42 matthew 346: if (editbrowser == null) {
347: url += 'launch=1&';
348: }
349: url += 'catalogmode=interactive&';
1.199 albertel 350: url += 'mode=$mode&';
1.611 albertel 351: url += 'inhibitmenu=yes&';
1.42 matthew 352: url += 'form=' + formname + '&';
353: if (only != null) {
354: url += 'only=' + only + '&';
1.217 albertel 355: } else {
356: url += 'only=&';
357: }
1.42 matthew 358: if (omit != null) {
359: url += 'omit=' + omit + '&';
1.217 albertel 360: } else {
361: url += 'omit=&';
362: }
1.135 albertel 363: if (titleelement != null) {
364: url += 'titleelement=' + titleelement + '&';
1.217 albertel 365: } else {
366: url += 'titleelement=&';
367: }
1.42 matthew 368: url += 'element=' + elementname + '';
369: var title = 'Browser';
1.435 albertel 370: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 371: options += ',width=700,height=600';
372: editbrowser = open(url,title,options,'1');
373: editbrowser.focus();
374: }
375: var editsearcher;
1.135 albertel 376: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 377: var url = '/adm/searchcat?';
378: if (editsearcher == null) {
379: url += 'launch=1&';
380: }
381: url += 'catalogmode=interactive&';
1.199 albertel 382: url += 'mode=$mode&';
1.42 matthew 383: url += 'form=' + formname + '&';
1.135 albertel 384: if (titleelement != null) {
385: url += 'titleelement=' + titleelement + '&';
1.217 albertel 386: } else {
387: url += 'titleelement=&';
388: }
1.42 matthew 389: url += 'element=' + elementname + '';
390: var title = 'Search';
1.435 albertel 391: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 392: options += ',width=700,height=600';
393: editsearcher = open(url,title,options,'1');
394: editsearcher.focus();
395: }
1.219 albertel 396: // END LON-CAPA Internal -->
1.42 matthew 397: END
1.170 www 398: }
399:
400: sub lastresurl {
1.258 albertel 401: if ($env{'environment.lastresurl'}) {
402: return $env{'environment.lastresurl'}
1.170 www 403: } else {
404: return '/res';
405: }
406: }
407:
408: sub storeresurl {
409: my $resurl=&Apache::lonnet::clutter(shift);
410: unless ($resurl=~/^\/res/) { return 0; }
411: $resurl=~s/\/$//;
412: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 413: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 414: return 1;
1.42 matthew 415: }
416:
1.74 www 417: sub studentbrowser_javascript {
1.111 www 418: unless (
1.258 albertel 419: (($env{'request.course.id'}) &&
1.302 albertel 420: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
421: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
422: '/'.$env{'request.course.sec'})
423: ))
1.258 albertel 424: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 425: ) { return ''; }
1.74 www 426: return (<<'ENDSTDBRW');
1.776 bisitz 427: <script type="text/javascript" language="Javascript">
1.824 bisitz 428: // <![CDATA[
1.74 www 429: var stdeditbrowser;
1.999 www 430: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 431: var url = '/adm/pickstudent?';
432: var filter;
1.558 albertel 433: if (!ignorefilter) {
434: eval('filter=document.'+formname+'.'+uname+'.value;');
435: }
1.74 www 436: if (filter != null) {
437: if (filter != '') {
438: url += 'filter='+filter+'&';
439: }
440: }
441: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 442: '&udomelement='+udom+
443: '&clicker='+clicker;
1.111 www 444: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 445: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 446: var title = 'Student_Browser';
1.74 www 447: var options = 'scrollbars=1,resizable=1,menubar=0';
448: options += ',width=700,height=600';
449: stdeditbrowser = open(url,title,options,'1');
450: stdeditbrowser.focus();
451: }
1.824 bisitz 452: // ]]>
1.74 www 453: </script>
454: ENDSTDBRW
455: }
1.42 matthew 456:
1.1003 www 457: sub resourcebrowser_javascript {
458: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 459: return (<<'ENDRESBRW');
1.1003 www 460: <script type="text/javascript" language="Javascript">
461: // <![CDATA[
462: var reseditbrowser;
1.1004 www 463: function openresbrowser(formname,reslink) {
1.1005 www 464: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 465: var title = 'Resource_Browser';
466: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 467: options += ',width=700,height=500';
1.1004 www 468: reseditbrowser = open(url,title,options,'1');
469: reseditbrowser.focus();
1.1003 www 470: }
471: // ]]>
472: </script>
1.1004 www 473: ENDRESBRW
1.1003 www 474: }
475:
1.74 www 476: sub selectstudent_link {
1.999 www 477: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
478: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
479: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
480: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 481: if ($env{'request.course.id'}) {
1.302 albertel 482: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
483: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
484: '/'.$env{'request.course.sec'})) {
1.111 www 485: return '';
486: }
1.999 www 487: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 488: if ($courseadvonly) {
489: $callargs .= ",'',1,1";
490: }
491: return '<span class="LC_nobreak">'.
492: '<a href="javascript:openstdbrowser('.$callargs.');">'.
493: &mt('Select User').'</a></span>';
1.74 www 494: }
1.258 albertel 495: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 496: $callargs .= ",'',1";
1.793 raeburn 497: return '<span class="LC_nobreak">'.
498: '<a href="javascript:openstdbrowser('.$callargs.');">'.
499: &mt('Select User').'</a></span>';
1.111 www 500: }
501: return '';
1.91 www 502: }
503:
1.1004 www 504: sub selectresource_link {
505: my ($form,$reslink,$arg)=@_;
506:
507: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
508: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
509: unless ($env{'request.course.id'}) { return $arg; }
510: return '<span class="LC_nobreak">'.
511: '<a href="javascript:openresbrowser('.$callargs.');">'.
512: $arg.'</a></span>';
513: }
514:
515:
516:
1.653 raeburn 517: sub authorbrowser_javascript {
518: return <<"ENDAUTHORBRW";
1.776 bisitz 519: <script type="text/javascript" language="JavaScript">
1.824 bisitz 520: // <![CDATA[
1.653 raeburn 521: var stdeditbrowser;
522:
523: function openauthorbrowser(formname,udom) {
524: var url = '/adm/pickauthor?';
525: url += 'form='+formname+'&roledom='+udom;
526: var title = 'Author_Browser';
527: var options = 'scrollbars=1,resizable=1,menubar=0';
528: options += ',width=700,height=600';
529: stdeditbrowser = open(url,title,options,'1');
530: stdeditbrowser.focus();
531: }
532:
1.824 bisitz 533: // ]]>
1.653 raeburn 534: </script>
535: ENDAUTHORBRW
536: }
537:
1.91 www 538: sub coursebrowser_javascript {
1.1075.2.31 raeburn 539: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1075.2.95 raeburn 540: $credits_element,$instcode) = @_;
1.932 raeburn 541: my $wintitle = 'Course_Browser';
1.931 raeburn 542: if ($crstype eq 'Community') {
1.932 raeburn 543: $wintitle = 'Community_Browser';
1.909 raeburn 544: }
1.876 raeburn 545: my $id_functions = &javascript_index_functions();
546: my $output = '
1.776 bisitz 547: <script type="text/javascript" language="JavaScript">
1.824 bisitz 548: // <![CDATA[
1.468 raeburn 549: var stdeditbrowser;'."\n";
1.876 raeburn 550:
551: $output .= <<"ENDSTDBRW";
1.909 raeburn 552: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 553: var url = '/adm/pickcourse?';
1.895 raeburn 554: var formid = getFormIdByName(formname);
1.876 raeburn 555: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 556: if (domainfilter != null) {
557: if (domainfilter != '') {
558: url += 'domainfilter='+domainfilter+'&';
559: }
560: }
1.91 www 561: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 562: '&cdomelement='+udom+
563: '&cnameelement='+desc;
1.468 raeburn 564: if (extra_element !=null && extra_element != '') {
1.594 raeburn 565: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 566: url += '&roleelement='+extra_element;
567: if (domainfilter == null || domainfilter == '') {
568: url += '&domainfilter='+extra_element;
569: }
1.234 raeburn 570: }
1.468 raeburn 571: else {
572: if (formname == 'portform') {
573: url += '&setroles='+extra_element;
1.800 raeburn 574: } else {
575: if (formname == 'rules') {
576: url += '&fixeddom='+extra_element;
577: }
1.468 raeburn 578: }
579: }
1.230 raeburn 580: }
1.909 raeburn 581: if (type != null && type != '') {
582: url += '&type='+type;
583: }
584: if (type_elem != null && type_elem != '') {
585: url += '&typeelement='+type_elem;
586: }
1.872 raeburn 587: if (formname == 'ccrs') {
588: var ownername = document.forms[formid].ccuname.value;
589: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1075.2.101 raeburn 590: url += '&cloner='+ownername+':'+ownerdom;
591: if (type == 'Course') {
592: url += '&crscode='+document.forms[formid].crscode.value;
593: }
1.1075.2.95 raeburn 594: }
595: if (formname == 'requestcrs') {
596: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 597: }
1.293 raeburn 598: if (multflag !=null && multflag != '') {
599: url += '&multiple='+multflag;
600: }
1.909 raeburn 601: var title = '$wintitle';
1.91 www 602: var options = 'scrollbars=1,resizable=1,menubar=0';
603: options += ',width=700,height=600';
604: stdeditbrowser = open(url,title,options,'1');
605: stdeditbrowser.focus();
606: }
1.876 raeburn 607: $id_functions
608: ENDSTDBRW
1.1075.2.31 raeburn 609: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
610: $output .= &setsec_javascript($sec_element,$formname,$role_element,
611: $credits_element);
1.876 raeburn 612: }
613: $output .= '
614: // ]]>
615: </script>';
616: return $output;
617: }
618:
619: sub javascript_index_functions {
620: return <<"ENDJS";
621:
622: function getFormIdByName(formname) {
623: for (var i=0;i<document.forms.length;i++) {
624: if (document.forms[i].name == formname) {
625: return i;
626: }
627: }
628: return -1;
629: }
630:
631: function getIndexByName(formid,item) {
632: for (var i=0;i<document.forms[formid].elements.length;i++) {
633: if (document.forms[formid].elements[i].name == item) {
634: return i;
635: }
636: }
637: return -1;
638: }
1.468 raeburn 639:
1.876 raeburn 640: function getDomainFromSelectbox(formname,udom) {
641: var userdom;
642: var formid = getFormIdByName(formname);
643: if (formid > -1) {
644: var domid = getIndexByName(formid,udom);
645: if (domid > -1) {
646: if (document.forms[formid].elements[domid].type == 'select-one') {
647: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
648: }
649: if (document.forms[formid].elements[domid].type == 'hidden') {
650: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 651: }
652: }
653: }
1.876 raeburn 654: return userdom;
655: }
656:
657: ENDJS
1.468 raeburn 658:
1.876 raeburn 659: }
660:
1.1017 raeburn 661: sub javascript_array_indexof {
1.1018 raeburn 662: return <<ENDJS;
1.1017 raeburn 663: <script type="text/javascript" language="JavaScript">
664: // <![CDATA[
665:
666: if (!Array.prototype.indexOf) {
667: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
668: "use strict";
669: if (this === void 0 || this === null) {
670: throw new TypeError();
671: }
672: var t = Object(this);
673: var len = t.length >>> 0;
674: if (len === 0) {
675: return -1;
676: }
677: var n = 0;
678: if (arguments.length > 0) {
679: n = Number(arguments[1]);
680: if (n !== n) { // shortcut for verifying if it's NaN
681: n = 0;
682: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
683: n = (n > 0 || -1) * Math.floor(Math.abs(n));
684: }
685: }
686: if (n >= len) {
687: return -1;
688: }
689: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
690: for (; k < len; k++) {
691: if (k in t && t[k] === searchElement) {
692: return k;
693: }
694: }
695: return -1;
696: }
697: }
698:
699: // ]]>
700: </script>
701:
702: ENDJS
703:
704: }
705:
1.876 raeburn 706: sub userbrowser_javascript {
707: my $id_functions = &javascript_index_functions();
708: return <<"ENDUSERBRW";
709:
1.888 raeburn 710: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 711: var url = '/adm/pickuser?';
712: var userdom = getDomainFromSelectbox(formname,udom);
713: if (userdom != null) {
714: if (userdom != '') {
715: url += 'srchdom='+userdom+'&';
716: }
717: }
718: url += 'form=' + formname + '&unameelement='+uname+
719: '&udomelement='+udom+
720: '&ulastelement='+ulast+
721: '&ufirstelement='+ufirst+
722: '&uemailelement='+uemail+
1.881 raeburn 723: '&hideudomelement='+hideudom+
724: '&coursedom='+crsdom;
1.888 raeburn 725: if ((caller != null) && (caller != undefined)) {
726: url += '&caller='+caller;
727: }
1.876 raeburn 728: var title = 'User_Browser';
729: var options = 'scrollbars=1,resizable=1,menubar=0';
730: options += ',width=700,height=600';
731: var stdeditbrowser = open(url,title,options,'1');
732: stdeditbrowser.focus();
733: }
734:
1.888 raeburn 735: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 736: var formid = getFormIdByName(formname);
737: if (formid > -1) {
1.888 raeburn 738: var unameid = getIndexByName(formid,uname);
1.876 raeburn 739: var domid = getIndexByName(formid,udom);
740: var hidedomid = getIndexByName(formid,origdom);
741: if (hidedomid > -1) {
742: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 743: var unameval = document.forms[formid].elements[unameid].value;
744: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
745: if (domid > -1) {
746: var slct = document.forms[formid].elements[domid];
747: if (slct.type == 'select-one') {
748: var i;
749: for (i=0;i<slct.length;i++) {
750: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
751: }
752: }
753: if (slct.type == 'hidden') {
754: slct.value = fixeddom;
1.876 raeburn 755: }
756: }
1.468 raeburn 757: }
758: }
759: }
1.876 raeburn 760: return;
761: }
762:
763: $id_functions
764: ENDUSERBRW
1.468 raeburn 765: }
766:
767: sub setsec_javascript {
1.1075.2.31 raeburn 768: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 769: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
770: $communityrolestr);
771: if ($role_element ne '') {
772: my @allroles = ('st','ta','ep','in','ad');
773: foreach my $crstype ('Course','Community') {
774: if ($crstype eq 'Community') {
775: foreach my $role (@allroles) {
776: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
777: }
778: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
779: } else {
780: foreach my $role (@allroles) {
781: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
782: }
783: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
784: }
785: }
786: $rolestr = '"'.join('","',@allroles).'"';
787: $courserolestr = '"'.join('","',@courserolenames).'"';
788: $communityrolestr = '"'.join('","',@communityrolenames).'"';
789: }
1.468 raeburn 790: my $setsections = qq|
791: function setSect(sectionlist) {
1.629 raeburn 792: var sectionsArray = new Array();
793: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
794: sectionsArray = sectionlist.split(",");
795: }
1.468 raeburn 796: var numSections = sectionsArray.length;
797: document.$formname.$sec_element.length = 0;
798: if (numSections == 0) {
799: document.$formname.$sec_element.multiple=false;
800: document.$formname.$sec_element.size=1;
801: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
802: } else {
803: if (numSections == 1) {
804: document.$formname.$sec_element.multiple=false;
805: document.$formname.$sec_element.size=1;
806: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
807: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
808: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
809: } else {
810: for (var i=0; i<numSections; i++) {
811: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
812: }
813: document.$formname.$sec_element.multiple=true
814: if (numSections < 3) {
815: document.$formname.$sec_element.size=numSections;
816: } else {
817: document.$formname.$sec_element.size=3;
818: }
819: document.$formname.$sec_element.options[0].selected = false
820: }
821: }
1.91 www 822: }
1.905 raeburn 823:
824: function setRole(crstype) {
1.468 raeburn 825: |;
1.905 raeburn 826: if ($role_element eq '') {
827: $setsections .= ' return;
828: }
829: ';
830: } else {
831: $setsections .= qq|
832: var elementLength = document.$formname.$role_element.length;
833: var allroles = Array($rolestr);
834: var courserolenames = Array($courserolestr);
835: var communityrolenames = Array($communityrolestr);
836: if (elementLength != undefined) {
837: if (document.$formname.$role_element.options[5].value == 'cc') {
838: if (crstype == 'Course') {
839: return;
840: } else {
841: allroles[5] = 'co';
842: for (var i=0; i<6; i++) {
843: document.$formname.$role_element.options[i].value = allroles[i];
844: document.$formname.$role_element.options[i].text = communityrolenames[i];
845: }
846: }
847: } else {
848: if (crstype == 'Community') {
849: return;
850: } else {
851: allroles[5] = 'cc';
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 = courserolenames[i];
855: }
856: }
857: }
858: }
859: return;
860: }
861: |;
862: }
1.1075.2.31 raeburn 863: if ($credits_element) {
864: $setsections .= qq|
865: function setCredits(defaultcredits) {
866: document.$formname.$credits_element.value = defaultcredits;
867: return;
868: }
869: |;
870: }
1.468 raeburn 871: return $setsections;
872: }
873:
1.91 www 874: sub selectcourse_link {
1.909 raeburn 875: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
876: $typeelement) = @_;
877: my $type = $selecttype;
1.871 raeburn 878: my $linktext = &mt('Select Course');
879: if ($selecttype eq 'Community') {
1.909 raeburn 880: $linktext = &mt('Select Community');
1.906 raeburn 881: } elsif ($selecttype eq 'Course/Community') {
882: $linktext = &mt('Select Course/Community');
1.909 raeburn 883: $type = '';
1.1019 raeburn 884: } elsif ($selecttype eq 'Select') {
885: $linktext = &mt('Select');
886: $type = '';
1.871 raeburn 887: }
1.787 bisitz 888: return '<span class="LC_nobreak">'
889: ."<a href='"
890: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
891: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 892: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 893: ."'>".$linktext.'</a>'
1.787 bisitz 894: .'</span>';
1.74 www 895: }
1.42 matthew 896:
1.653 raeburn 897: sub selectauthor_link {
898: my ($form,$udom)=@_;
899: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
900: &mt('Select Author').'</a>';
901: }
902:
1.876 raeburn 903: sub selectuser_link {
1.881 raeburn 904: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 905: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 906: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 907: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 908: ');">'.$linktext.'</a>';
1.876 raeburn 909: }
910:
1.273 raeburn 911: sub check_uncheck_jscript {
912: my $jscript = <<"ENDSCRT";
913: function checkAll(field) {
914: if (field.length > 0) {
915: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 916: if (!field[i].disabled) {
917: field[i].checked = true;
918: }
1.273 raeburn 919: }
920: } else {
1.1075.2.14 raeburn 921: if (!field.disabled) {
922: field.checked = true;
923: }
1.273 raeburn 924: }
925: }
926:
927: function uncheckAll(field) {
928: if (field.length > 0) {
929: for (i = 0; i < field.length; i++) {
930: field[i].checked = false ;
1.543 albertel 931: }
932: } else {
1.273 raeburn 933: field.checked = false ;
934: }
935: }
936: ENDSCRT
937: return $jscript;
938: }
939:
1.656 www 940: sub select_timezone {
1.1075.2.115 raeburn 941: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
942: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 943: if ($includeempty) {
944: $output .= '<option value=""';
945: if (($selected eq '') || ($selected eq 'local')) {
946: $output .= ' selected="selected" ';
947: }
948: $output .= '> </option>';
949: }
1.657 raeburn 950: my @timezones = DateTime::TimeZone->all_names;
951: foreach my $tzone (@timezones) {
952: $output.= '<option value="'.$tzone.'"';
953: if ($tzone eq $selected) {
954: $output.=' selected="selected"';
955: }
956: $output.=">$tzone</option>\n";
1.656 www 957: }
958: $output.="</select>";
959: return $output;
960: }
1.273 raeburn 961:
1.687 raeburn 962: sub select_datelocale {
1.1075.2.115 raeburn 963: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
964: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 965: if ($includeempty) {
966: $output .= '<option value=""';
967: if ($selected eq '') {
968: $output .= ' selected="selected" ';
969: }
970: $output .= '> </option>';
971: }
1.1075.2.102 raeburn 972: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 973: my (@possibles,%locale_names);
1.1075.2.102 raeburn 974: my @locales = DateTime::Locale->ids();
975: foreach my $id (@locales) {
976: if ($id ne '') {
977: my ($en_terr,$native_terr);
978: my $loc = DateTime::Locale->load($id);
979: if (ref($loc)) {
980: $en_terr = $loc->name();
981: $native_terr = $loc->native_name();
1.687 raeburn 982: if (grep(/^en$/,@languages) || !@languages) {
983: if ($en_terr ne '') {
984: $locale_names{$id} = '('.$en_terr.')';
985: } elsif ($native_terr ne '') {
986: $locale_names{$id} = $native_terr;
987: }
988: } else {
989: if ($native_terr ne '') {
990: $locale_names{$id} = $native_terr.' ';
991: } elsif ($en_terr ne '') {
992: $locale_names{$id} = '('.$en_terr.')';
993: }
994: }
1.1075.2.94 raeburn 995: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1075.2.102 raeburn 996: push(@possibles,$id);
1.687 raeburn 997: }
998: }
999: }
1000: foreach my $item (sort(@possibles)) {
1001: $output.= '<option value="'.$item.'"';
1002: if ($item eq $selected) {
1003: $output.=' selected="selected"';
1004: }
1005: $output.=">$item";
1006: if ($locale_names{$item} ne '') {
1.1075.2.94 raeburn 1007: $output.=' '.$locale_names{$item};
1.687 raeburn 1008: }
1009: $output.="</option>\n";
1010: }
1011: $output.="</select>";
1012: return $output;
1013: }
1014:
1.792 raeburn 1015: sub select_language {
1.1075.2.115 raeburn 1016: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1017: my %langchoices;
1018: if ($includeempty) {
1.1075.2.32 raeburn 1019: %langchoices = ('' => 'No language preference');
1.792 raeburn 1020: }
1021: foreach my $id (&languageids()) {
1022: my $code = &supportedlanguagecode($id);
1023: if ($code) {
1024: $langchoices{$code} = &plainlanguagedescription($id);
1025: }
1026: }
1.1075.2.32 raeburn 1027: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1075.2.115 raeburn 1028: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1029: }
1030:
1.42 matthew 1031: =pod
1.36 matthew 1032:
1.648 raeburn 1033: =item * &linked_select_forms(...)
1.36 matthew 1034:
1035: linked_select_forms returns a string containing a <script></script> block
1036: and html for two <select> menus. The select menus will be linked in that
1037: changing the value of the first menu will result in new values being placed
1038: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1039: order unless a defined order is provided.
1.36 matthew 1040:
1041: linked_select_forms takes the following ordered inputs:
1042:
1043: =over 4
1044:
1.112 bowersj2 1045: =item * $formname, the name of the <form> tag
1.36 matthew 1046:
1.112 bowersj2 1047: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1048:
1.112 bowersj2 1049: =item * $firstdefault, the default value for the first menu
1.36 matthew 1050:
1.112 bowersj2 1051: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1052:
1.112 bowersj2 1053: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1054:
1.112 bowersj2 1055: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1056:
1.609 raeburn 1057: =item * $menuorder, the order of values in the first menu
1058:
1.1075.2.31 raeburn 1059: =item * $onchangefirst, additional javascript call to execute for an onchange
1060: event for the first <select> tag
1061:
1062: =item * $onchangesecond, additional javascript call to execute for an onchange
1063: event for the second <select> tag
1064:
1.41 ng 1065: =back
1066:
1.36 matthew 1067: Below is an example of such a hash. Only the 'text', 'default', and
1068: 'select2' keys must appear as stated. keys(%menu) are the possible
1069: values for the first select menu. The text that coincides with the
1.41 ng 1070: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1071: and text for the second menu are given in the hash pointed to by
1072: $menu{$choice1}->{'select2'}.
1073:
1.112 bowersj2 1074: my %menu = ( A1 => { text =>"Choice A1" ,
1075: default => "B3",
1076: select2 => {
1077: B1 => "Choice B1",
1078: B2 => "Choice B2",
1079: B3 => "Choice B3",
1080: B4 => "Choice B4"
1.609 raeburn 1081: },
1082: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1083: },
1084: A2 => { text =>"Choice A2" ,
1085: default => "C2",
1086: select2 => {
1087: C1 => "Choice C1",
1088: C2 => "Choice C2",
1089: C3 => "Choice C3"
1.609 raeburn 1090: },
1091: order => ['C2','C1','C3'],
1.112 bowersj2 1092: },
1093: A3 => { text =>"Choice A3" ,
1094: default => "D6",
1095: select2 => {
1096: D1 => "Choice D1",
1097: D2 => "Choice D2",
1098: D3 => "Choice D3",
1099: D4 => "Choice D4",
1100: D5 => "Choice D5",
1101: D6 => "Choice D6",
1102: D7 => "Choice D7"
1.609 raeburn 1103: },
1104: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1105: }
1106: );
1.36 matthew 1107:
1108: =cut
1109:
1110: sub linked_select_forms {
1111: my ($formname,
1112: $middletext,
1113: $firstdefault,
1114: $firstselectname,
1115: $secondselectname,
1.609 raeburn 1116: $hashref,
1117: $menuorder,
1.1075.2.31 raeburn 1118: $onchangefirst,
1119: $onchangesecond
1.36 matthew 1120: ) = @_;
1121: my $second = "document.$formname.$secondselectname";
1122: my $first = "document.$formname.$firstselectname";
1123: # output the javascript to do the changing
1124: my $result = '';
1.776 bisitz 1125: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1126: $result.="// <![CDATA[\n";
1.36 matthew 1127: $result.="var select2data = new Object();\n";
1128: $" = '","';
1129: my $debug = '';
1130: foreach my $s1 (sort(keys(%$hashref))) {
1131: $result.="select2data.d_$s1 = new Object();\n";
1132: $result.="select2data.d_$s1.def = new String('".
1133: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1134: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1135: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1136: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1137: @s2values = @{$hashref->{$s1}->{'order'}};
1138: }
1.36 matthew 1139: $result.="\"@s2values\");\n";
1140: $result.="select2data.d_$s1.texts = new Array(";
1141: my @s2texts;
1142: foreach my $value (@s2values) {
1.1075.2.119 raeburn 1143: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1144: }
1145: $result.="\"@s2texts\");\n";
1146: }
1147: $"=' ';
1148: $result.= <<"END";
1149:
1150: function select1_changed() {
1151: // Determine new choice
1152: var newvalue = "d_" + $first.value;
1153: // update select2
1154: var values = select2data[newvalue].values;
1155: var texts = select2data[newvalue].texts;
1156: var select2def = select2data[newvalue].def;
1157: var i;
1158: // out with the old
1159: for (i = 0; i < $second.options.length; i++) {
1160: $second.options[i] = null;
1161: }
1162: // in with the nuclear
1163: for (i=0;i<values.length; i++) {
1164: $second.options[i] = new Option(values[i]);
1.143 matthew 1165: $second.options[i].value = values[i];
1.36 matthew 1166: $second.options[i].text = texts[i];
1167: if (values[i] == select2def) {
1168: $second.options[i].selected = true;
1169: }
1170: }
1171: }
1.824 bisitz 1172: // ]]>
1.36 matthew 1173: </script>
1174: END
1175: # output the initial values for the selection lists
1.1075.2.31 raeburn 1176: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1177: my @order = sort(keys(%{$hashref}));
1178: if (ref($menuorder) eq 'ARRAY') {
1179: @order = @{$menuorder};
1180: }
1181: foreach my $value (@order) {
1.36 matthew 1182: $result.=" <option value=\"$value\" ";
1.253 albertel 1183: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1184: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1185: }
1186: $result .= "</select>\n";
1187: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1188: $result .= $middletext;
1.1075.2.31 raeburn 1189: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1190: if ($onchangesecond) {
1191: $result .= ' onchange="'.$onchangesecond.'"';
1192: }
1193: $result .= ">\n";
1.36 matthew 1194: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1195:
1196: my @secondorder = sort(keys(%select2));
1197: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1198: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1199: }
1200: foreach my $value (@secondorder) {
1.36 matthew 1201: $result.=" <option value=\"$value\" ";
1.253 albertel 1202: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1203: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1204: }
1205: $result .= "</select>\n";
1206: # return $debug;
1207: return $result;
1208: } # end of sub linked_select_forms {
1209:
1.45 matthew 1210: =pod
1.44 bowersj2 1211:
1.973 raeburn 1212: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1213:
1.112 bowersj2 1214: Returns a string corresponding to an HTML link to the given help
1215: $topic, where $topic corresponds to the name of a .tex file in
1216: /home/httpd/html/adm/help/tex, with underscores replaced by
1217: spaces.
1218:
1219: $text will optionally be linked to the same topic, allowing you to
1220: link text in addition to the graphic. If you do not want to link
1221: text, but wish to specify one of the later parameters, pass an
1222: empty string.
1223:
1224: $stayOnPage is a value that will be interpreted as a boolean. If true,
1225: the link will not open a new window. If false, the link will open
1226: a new window using Javascript. (Default is false.)
1227:
1228: $width and $height are optional numerical parameters that will
1229: override the width and height of the popped up window, which may
1.973 raeburn 1230: be useful for certain help topics with big pictures included.
1231:
1232: $imgid is the id of the img tag used for the help icon. This may be
1233: used in a javascript call to switch the image src. See
1234: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1235:
1236: =cut
1237:
1238: sub help_open_topic {
1.973 raeburn 1239: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1240: $text = "" if (not defined $text);
1.44 bowersj2 1241: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1242: $width = 500 if (not defined $width);
1.44 bowersj2 1243: $height = 400 if (not defined $height);
1244: my $filename = $topic;
1245: $filename =~ s/ /_/g;
1246:
1.48 bowersj2 1247: my $template = "";
1248: my $link;
1.572 banghart 1249:
1.159 www 1250: $topic=~s/\W/\_/g;
1.44 bowersj2 1251:
1.572 banghart 1252: if (!$stayOnPage) {
1.1075.2.50 raeburn 1253: if ($env{'browser.mobile'}) {
1254: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1255: } else {
1256: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1257: }
1.1037 www 1258: } elsif ($stayOnPage eq 'popup') {
1259: $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 1260: } else {
1.48 bowersj2 1261: $link = "/adm/help/${filename}.hlp";
1262: }
1263:
1264: # Add the text
1.755 neumanie 1265: if ($text ne "") {
1.763 bisitz 1266: $template.='<span class="LC_help_open_topic">'
1267: .'<a target="_top" href="'.$link.'">'
1268: .$text.'</a>';
1.48 bowersj2 1269: }
1270:
1.763 bisitz 1271: # (Always) Add the graphic
1.179 matthew 1272: my $title = &mt('Online Help');
1.667 raeburn 1273: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1274: if ($imgid ne '') {
1275: $imgid = ' id="'.$imgid.'"';
1276: }
1.763 bisitz 1277: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1278: .'<img src="'.$helpicon.'" border="0"'
1279: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1280: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1281: .' /></a>';
1282: if ($text ne "") {
1283: $template.='</span>';
1284: }
1.44 bowersj2 1285: return $template;
1286:
1.106 bowersj2 1287: }
1288:
1289: # This is a quicky function for Latex cheatsheet editing, since it
1290: # appears in at least four places
1291: sub helpLatexCheatsheet {
1.1037 www 1292: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1293: my $out;
1.106 bowersj2 1294: my $addOther = '';
1.732 raeburn 1295: if ($topic) {
1.1037 www 1296: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1297: }
1298: $out = '<span>' # Start cheatsheet
1299: .$addOther
1300: .'<span>'
1.1037 www 1301: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1302: .'</span> <span>'
1.1037 www 1303: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1304: .'</span>';
1.732 raeburn 1305: unless ($not_author) {
1.763 bisitz 1306: $out .= ' <span>'
1.1037 www 1307: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1308: .'</span> <span>'
1.1075.2.78 raeburn 1309: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1310: .'</span>';
1.732 raeburn 1311: }
1.763 bisitz 1312: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1313: return $out;
1.172 www 1314: }
1315:
1.430 albertel 1316: sub general_help {
1317: my $helptopic='Student_Intro';
1318: if ($env{'request.role'}=~/^(ca|au)/) {
1319: $helptopic='Authoring_Intro';
1.907 raeburn 1320: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1321: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1322: } elsif ($env{'request.role'}=~/^dc/) {
1323: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1324: }
1325: return $helptopic;
1326: }
1327:
1328: sub update_help_link {
1329: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1330: my $origurl = $ENV{'REQUEST_URI'};
1331: $origurl=~s|^/~|/priv/|;
1332: my $timestamp = time;
1333: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1334: $$datum = &escape($$datum);
1335: }
1336:
1337: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1338: my $output .= <<"ENDOUTPUT";
1339: <script type="text/javascript">
1.824 bisitz 1340: // <![CDATA[
1.430 albertel 1341: banner_link = '$banner_link';
1.824 bisitz 1342: // ]]>
1.430 albertel 1343: </script>
1344: ENDOUTPUT
1345: return $output;
1346: }
1347:
1348: # now just updates the help link and generates a blue icon
1.193 raeburn 1349: sub help_open_menu {
1.430 albertel 1350: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1351: = @_;
1.949 droeschl 1352: $stayOnPage = 1;
1.430 albertel 1353: my $output;
1354: if ($component_help) {
1355: if (!$text) {
1356: $output=&help_open_topic($component_help,undef,$stayOnPage,
1357: $width,$height);
1358: } else {
1359: my $help_text;
1360: $help_text=&unescape($topic);
1361: $output='<table><tr><td>'.
1362: &help_open_topic($component_help,$help_text,$stayOnPage,
1363: $width,$height).'</td></tr></table>';
1364: }
1365: }
1366: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1367: return $output.$banner_link;
1368: }
1369:
1370: sub top_nav_help {
1371: my ($text) = @_;
1.436 albertel 1372: $text = &mt($text);
1.1075.2.60 raeburn 1373: my $stay_on_page;
1374: unless ($env{'environment.remote'} eq 'on') {
1375: $stay_on_page = 1;
1376: }
1.1075.2.61 raeburn 1377: my ($link,$banner_link);
1378: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1379: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1380: : "javascript:helpMenu('open')";
1381: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1382: }
1.201 raeburn 1383: my $title = &mt('Get help');
1.1075.2.61 raeburn 1384: if ($link) {
1385: return <<"END";
1.436 albertel 1386: $banner_link
1.1075.2.56 raeburn 1387: <a href="$link" title="$title">$text</a>
1.436 albertel 1388: END
1.1075.2.61 raeburn 1389: } else {
1390: return ' '.$text.' ';
1391: }
1.436 albertel 1392: }
1393:
1394: sub help_menu_js {
1.1075.2.52 raeburn 1395: my ($httphost) = @_;
1.949 droeschl 1396: my $stayOnPage = 1;
1.436 albertel 1397: my $width = 620;
1398: my $height = 600;
1.430 albertel 1399: my $helptopic=&general_help();
1.1075.2.52 raeburn 1400: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1401: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1402: my $start_page =
1403: &Apache::loncommon::start_page('Help Menu', undef,
1404: {'frameset' => 1,
1405: 'js_ready' => 1,
1.1075.2.52 raeburn 1406: 'use_absolute' => $httphost,
1.331 albertel 1407: 'add_entries' => {
1408: 'border' => '0',
1.579 raeburn 1409: 'rows' => "110,*",},});
1.331 albertel 1410: my $end_page =
1411: &Apache::loncommon::end_page({'frameset' => 1,
1412: 'js_ready' => 1,});
1413:
1.436 albertel 1414: my $template .= <<"ENDTEMPLATE";
1415: <script type="text/javascript">
1.877 bisitz 1416: // <![CDATA[
1.253 albertel 1417: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1418: var banner_link = '';
1.243 raeburn 1419: function helpMenu(target) {
1420: var caller = this;
1421: if (target == 'open') {
1422: var newWindow = null;
1423: try {
1.262 albertel 1424: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1425: }
1426: catch(error) {
1427: writeHelp(caller);
1428: return;
1429: }
1430: if (newWindow) {
1431: caller = newWindow;
1432: }
1.193 raeburn 1433: }
1.243 raeburn 1434: writeHelp(caller);
1435: return;
1436: }
1437: function writeHelp(caller) {
1.1075.2.61 raeburn 1438: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1439: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1440: caller.document.close();
1441: caller.focus();
1.193 raeburn 1442: }
1.877 bisitz 1443: // END LON-CAPA Internal -->
1.253 albertel 1444: // ]]>
1.436 albertel 1445: </script>
1.193 raeburn 1446: ENDTEMPLATE
1447: return $template;
1448: }
1449:
1.172 www 1450: sub help_open_bug {
1451: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1452: unless ($env{'user.adv'}) { return ''; }
1.172 www 1453: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1454: $text = "" if (not defined $text);
1455: $stayOnPage=1;
1.184 albertel 1456: $width = 600 if (not defined $width);
1457: $height = 600 if (not defined $height);
1.172 www 1458:
1459: $topic=~s/\W+/\+/g;
1460: my $link='';
1461: my $template='';
1.379 albertel 1462: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1463: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1464: if (!$stayOnPage)
1465: {
1466: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1467: }
1468: else
1469: {
1470: $link = $url;
1471: }
1472: # Add the text
1473: if ($text ne "")
1474: {
1475: $template .=
1476: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1477: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1478: }
1479:
1480: # Add the graphic
1.179 matthew 1481: my $title = &mt('Report a Bug');
1.215 albertel 1482: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1483: $template .= <<"ENDTEMPLATE";
1.436 albertel 1484: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1485: ENDTEMPLATE
1486: if ($text ne '') { $template.='</td></tr></table>' };
1487: return $template;
1488:
1489: }
1490:
1491: sub help_open_faq {
1492: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1493: unless ($env{'user.adv'}) { return ''; }
1.172 www 1494: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1495: $text = "" if (not defined $text);
1496: $stayOnPage=1;
1497: $width = 350 if (not defined $width);
1498: $height = 400 if (not defined $height);
1499:
1500: $topic=~s/\W+/\+/g;
1501: my $link='';
1502: my $template='';
1503: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1504: if (!$stayOnPage)
1505: {
1506: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1507: }
1508: else
1509: {
1510: $link = $url;
1511: }
1512:
1513: # Add the text
1514: if ($text ne "")
1515: {
1516: $template .=
1.173 www 1517: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1518: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1519: }
1520:
1521: # Add the graphic
1.179 matthew 1522: my $title = &mt('View the FAQ');
1.215 albertel 1523: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1524: $template .= <<"ENDTEMPLATE";
1.436 albertel 1525: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1526: ENDTEMPLATE
1527: if ($text ne '') { $template.='</td></tr></table>' };
1528: return $template;
1529:
1.44 bowersj2 1530: }
1.37 matthew 1531:
1.180 matthew 1532: ###############################################################
1533: ###############################################################
1534:
1.45 matthew 1535: =pod
1536:
1.648 raeburn 1537: =item * &change_content_javascript():
1.256 matthew 1538:
1539: This and the next function allow you to create small sections of an
1540: otherwise static HTML page that you can update on the fly with
1541: Javascript, even in Netscape 4.
1542:
1543: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1544: must be written to the HTML page once. It will prove the Javascript
1545: function "change(name, content)". Calling the change function with the
1546: name of the section
1547: you want to update, matching the name passed to C<changable_area>, and
1548: the new content you want to put in there, will put the content into
1549: that area.
1550:
1551: B<Note>: Netscape 4 only reserves enough space for the changable area
1552: to contain room for the original contents. You need to "make space"
1553: for whatever changes you wish to make, and be B<sure> to check your
1554: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1555: it's adequate for updating a one-line status display, but little more.
1556: This script will set the space to 100% width, so you only need to
1557: worry about height in Netscape 4.
1558:
1559: Modern browsers are much less limiting, and if you can commit to the
1560: user not using Netscape 4, this feature may be used freely with
1561: pretty much any HTML.
1562:
1563: =cut
1564:
1565: sub change_content_javascript {
1566: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1567: if ($env{'browser.type'} eq 'netscape' &&
1568: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1569: return (<<NETSCAPE4);
1570: function change(name, content) {
1571: doc = document.layers[name+"___escape"].layers[0].document;
1572: doc.open();
1573: doc.write(content);
1574: doc.close();
1575: }
1576: NETSCAPE4
1577: } else {
1578: # Otherwise, we need to use semi-standards-compliant code
1579: # (technically, "innerHTML" isn't standard but the equivalent
1580: # is really scary, and every useful browser supports it
1581: return (<<DOMBASED);
1582: function change(name, content) {
1583: element = document.getElementById(name);
1584: element.innerHTML = content;
1585: }
1586: DOMBASED
1587: }
1588: }
1589:
1590: =pod
1591:
1.648 raeburn 1592: =item * &changable_area($name,$origContent):
1.256 matthew 1593:
1594: This provides a "changable area" that can be modified on the fly via
1595: the Javascript code provided in C<change_content_javascript>. $name is
1596: the name you will use to reference the area later; do not repeat the
1597: same name on a given HTML page more then once. $origContent is what
1598: the area will originally contain, which can be left blank.
1599:
1600: =cut
1601:
1602: sub changable_area {
1603: my ($name, $origContent) = @_;
1604:
1.258 albertel 1605: if ($env{'browser.type'} eq 'netscape' &&
1606: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1607: # If this is netscape 4, we need to use the Layer tag
1608: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1609: } else {
1610: return "<span id='$name'>$origContent</span>";
1611: }
1612: }
1613:
1614: =pod
1615:
1.648 raeburn 1616: =item * &viewport_geometry_js
1.590 raeburn 1617:
1618: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1619:
1620: =cut
1621:
1622:
1623: sub viewport_geometry_js {
1624: return <<"GEOMETRY";
1625: var Geometry = {};
1626: function init_geometry() {
1627: if (Geometry.init) { return };
1628: Geometry.init=1;
1629: if (window.innerHeight) {
1630: Geometry.getViewportHeight = function() { return window.innerHeight; };
1631: Geometry.getViewportWidth = function() { return window.innerWidth; };
1632: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1633: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1634: }
1635: else if (document.documentElement && document.documentElement.clientHeight) {
1636: Geometry.getViewportHeight =
1637: function() { return document.documentElement.clientHeight; };
1638: Geometry.getViewportWidth =
1639: function() { return document.documentElement.clientWidth; };
1640:
1641: Geometry.getHorizontalScroll =
1642: function() { return document.documentElement.scrollLeft; };
1643: Geometry.getVerticalScroll =
1644: function() { return document.documentElement.scrollTop; };
1645: }
1646: else if (document.body.clientHeight) {
1647: Geometry.getViewportHeight =
1648: function() { return document.body.clientHeight; };
1649: Geometry.getViewportWidth =
1650: function() { return document.body.clientWidth; };
1651: Geometry.getHorizontalScroll =
1652: function() { return document.body.scrollLeft; };
1653: Geometry.getVerticalScroll =
1654: function() { return document.body.scrollTop; };
1655: }
1656: }
1657:
1658: GEOMETRY
1659: }
1660:
1661: =pod
1662:
1.648 raeburn 1663: =item * &viewport_size_js()
1.590 raeburn 1664:
1665: 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.
1666:
1667: =cut
1668:
1669: sub viewport_size_js {
1670: my $geometry = &viewport_geometry_js();
1671: return <<"DIMS";
1672:
1673: $geometry
1674:
1675: function getViewportDims(width,height) {
1676: init_geometry();
1677: width.value = Geometry.getViewportWidth();
1678: height.value = Geometry.getViewportHeight();
1679: return;
1680: }
1681:
1682: DIMS
1683: }
1684:
1685: =pod
1686:
1.648 raeburn 1687: =item * &resize_textarea_js()
1.565 albertel 1688:
1689: emits the needed javascript to resize a textarea to be as big as possible
1690:
1691: creates a function resize_textrea that takes two IDs first should be
1692: the id of the element to resize, second should be the id of a div that
1693: surrounds everything that comes after the textarea, this routine needs
1694: to be attached to the <body> for the onload and onresize events.
1695:
1.648 raeburn 1696: =back
1.565 albertel 1697:
1698: =cut
1699:
1700: sub resize_textarea_js {
1.590 raeburn 1701: my $geometry = &viewport_geometry_js();
1.565 albertel 1702: return <<"RESIZE";
1703: <script type="text/javascript">
1.824 bisitz 1704: // <![CDATA[
1.590 raeburn 1705: $geometry
1.565 albertel 1706:
1.588 albertel 1707: function getX(element) {
1708: var x = 0;
1709: while (element) {
1710: x += element.offsetLeft;
1711: element = element.offsetParent;
1712: }
1713: return x;
1714: }
1715: function getY(element) {
1716: var y = 0;
1717: while (element) {
1718: y += element.offsetTop;
1719: element = element.offsetParent;
1720: }
1721: return y;
1722: }
1723:
1724:
1.565 albertel 1725: function resize_textarea(textarea_id,bottom_id) {
1726: init_geometry();
1727: var textarea = document.getElementById(textarea_id);
1728: //alert(textarea);
1729:
1.588 albertel 1730: var textarea_top = getY(textarea);
1.565 albertel 1731: var textarea_height = textarea.offsetHeight;
1732: var bottom = document.getElementById(bottom_id);
1.588 albertel 1733: var bottom_top = getY(bottom);
1.565 albertel 1734: var bottom_height = bottom.offsetHeight;
1735: var window_height = Geometry.getViewportHeight();
1.588 albertel 1736: var fudge = 23;
1.565 albertel 1737: var new_height = window_height-fudge-textarea_top-bottom_height;
1738: if (new_height < 300) {
1739: new_height = 300;
1740: }
1741: textarea.style.height=new_height+'px';
1742: }
1.824 bisitz 1743: // ]]>
1.565 albertel 1744: </script>
1745: RESIZE
1746:
1747: }
1748:
1.1075.2.112 raeburn 1749: sub colorfuleditor_js {
1750: return <<"COLORFULEDIT"
1751: <script type="text/javascript">
1752: // <![CDATA[>
1753: function fold_box(curDepth, lastresource){
1754:
1755: // we need a list because there can be several blocks you need to fold in one tag
1756: var block = document.getElementsByName('foldblock_'+curDepth);
1757: // but there is only one folding button per tag
1758: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1759:
1760: if(block.item(0).style.display == 'none'){
1761:
1762: foldbutton.value = '@{[&mt("Hide")]}';
1763: for (i = 0; i < block.length; i++){
1764: block.item(i).style.display = '';
1765: }
1766: }else{
1767:
1768: foldbutton.value = '@{[&mt("Show")]}';
1769: for (i = 0; i < block.length; i++){
1770: // block.item(i).style.visibility = 'collapse';
1771: block.item(i).style.display = 'none';
1772: }
1773: };
1774: saveState(lastresource);
1775: }
1776:
1777: function saveState (lastresource) {
1778:
1779: var tag_list = getTagList();
1780: if(tag_list != null){
1781: var timestamp = new Date().getTime();
1782: var key = lastresource;
1783:
1784: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1785: // starting with timestamp
1786: var value = timestamp+';';
1787:
1788: // building the list of key-value pairs
1789: for(var i = 0; i < tag_list.length; i++){
1790: value += tag_list[i]+',';
1791: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1792: }
1793:
1794: // only iterate whole storage if nothing to override
1795: if(localStorage.getItem(key) == null){
1796:
1797: // prevent storage from growing large
1798: if(localStorage.length > 50){
1799: var regex_getTimestamp = /^(?:\d)+;/;
1800: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1801: var oldest_key;
1802:
1803: for(var i = 1; i < localStorage.length; i++){
1804: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1805: oldest_key = localStorage.key(i);
1806: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1807: }
1808: }
1809: localStorage.removeItem(oldest_key);
1810: }
1811: }
1812: localStorage.setItem(key,value);
1813: }
1814: }
1815:
1816: // restore folding status of blocks (on page load)
1817: function restoreState (lastresource) {
1818: if(localStorage.getItem(lastresource) != null){
1819: var key = lastresource;
1820: var value = localStorage.getItem(key);
1821: var regex_delTimestamp = /^\d+;/;
1822:
1823: value.replace(regex_delTimestamp, '');
1824:
1825: var valueArr = value.split(';');
1826: var pairs;
1827: var elements;
1828: for (var i = 0; i < valueArr.length; i++){
1829: pairs = valueArr[i].split(',');
1830: elements = document.getElementsByName(pairs[0]);
1831:
1832: for (var j = 0; j < elements.length; j++){
1833: elements[j].style.display = pairs[1];
1834: if (pairs[1] == "none"){
1835: var regex_id = /([_\\d]+)\$/;
1836: regex_id.exec(pairs[0]);
1837: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1838: }
1839: }
1840: }
1841: }
1842: }
1843:
1844: function getTagList () {
1845:
1846: var stringToSearch = document.lonhomework.innerHTML;
1847:
1848: var ret = new Array();
1849: var regex_findBlock = /(foldblock_.*?)"/g;
1850: var tag_list = stringToSearch.match(regex_findBlock);
1851:
1852: if(tag_list != null){
1853: for(var i = 0; i < tag_list.length; i++){
1854: ret.push(tag_list[i].replace(/"/, ''));
1855: }
1856: }
1857: return ret;
1858: }
1859:
1860: function saveScrollPosition (resource) {
1861: var tag_list = getTagList();
1862:
1863: // we dont always want to jump to the first block
1864: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1865: if(\$(window).scrollTop() > 170){
1866: if(tag_list != null){
1867: var result;
1868: for(var i = 0; i < tag_list.length; i++){
1869: if(isElementInViewport(tag_list[i])){
1870: result += tag_list[i]+';';
1871: }
1872: }
1873: sessionStorage.setItem('anchor_'+resource, result);
1874: }
1875: } else {
1876: // we dont need to save zero, just delete the item to leave everything tidy
1877: sessionStorage.removeItem('anchor_'+resource);
1878: }
1879: }
1880:
1881: function restoreScrollPosition(resource){
1882:
1883: var elem = sessionStorage.getItem('anchor_'+resource);
1884: if(elem != null){
1885: var tag_list = elem.split(';');
1886: var elem_list;
1887:
1888: for(var i = 0; i < tag_list.length; i++){
1889: elem_list = document.getElementsByName(tag_list[i]);
1890:
1891: if(elem_list.length > 0){
1892: elem = elem_list[0];
1893: break;
1894: }
1895: }
1896: elem.scrollIntoView();
1897: }
1898: }
1899:
1900: function isElementInViewport(el) {
1901:
1902: // change to last element instead of first
1903: var elem = document.getElementsByName(el);
1904: var rect = elem[0].getBoundingClientRect();
1905:
1906: return (
1907: rect.top >= 0 &&
1908: rect.left >= 0 &&
1909: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1910: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1911: );
1912: }
1913:
1914: function autosize(depth){
1915: var cmInst = window['cm'+depth];
1916: var fitsizeButton = document.getElementById('fitsize'+depth);
1917:
1918: // is fixed size, switching to dynamic
1919: if (sessionStorage.getItem("autosized_"+depth) == null) {
1920: cmInst.setSize("","auto");
1921: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1922: sessionStorage.setItem("autosized_"+depth, "yes");
1923:
1924: // is dynamic size, switching to fixed
1925: } else {
1926: cmInst.setSize("","300px");
1927: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1928: sessionStorage.removeItem("autosized_"+depth);
1929: }
1930: }
1931:
1932:
1933:
1934: // ]]>
1935: </script>
1936: COLORFULEDIT
1937: }
1938:
1939: sub xmleditor_js {
1940: return <<XMLEDIT
1941: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1942: <script type="text/javascript">
1943: // <![CDATA[>
1944:
1945: function saveScrollPosition (resource) {
1946:
1947: var scrollPos = \$(window).scrollTop();
1948: sessionStorage.setItem(resource,scrollPos);
1949: }
1950:
1951: function restoreScrollPosition(resource){
1952:
1953: var scrollPos = sessionStorage.getItem(resource);
1954: \$(window).scrollTop(scrollPos);
1955: }
1956:
1957: // unless internet explorer
1958: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1959:
1960: \$(document).ready(function() {
1961: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1962: });
1963: }
1964:
1965: // inserts text at cursor position into codemirror (xml editor only)
1966: function insertText(text){
1967: cm.focus();
1968: var curPos = cm.getCursor();
1969: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1970: }
1971: // ]]>
1972: </script>
1973: XMLEDIT
1974: }
1975:
1976: sub insert_folding_button {
1977: my $curDepth = $Apache::lonxml::curdepth;
1978: my $lastresource = $env{'request.ambiguous'};
1979:
1980: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
1981: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
1982: }
1983:
1984:
1.565 albertel 1985: =pod
1986:
1.256 matthew 1987: =head1 Excel and CSV file utility routines
1988:
1989: =cut
1990:
1991: ###############################################################
1992: ###############################################################
1993:
1994: =pod
1995:
1.1075.2.56 raeburn 1996: =over 4
1997:
1.648 raeburn 1998: =item * &csv_translate($text)
1.37 matthew 1999:
1.185 www 2000: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2001: format.
2002:
2003: =cut
2004:
1.180 matthew 2005: ###############################################################
2006: ###############################################################
1.37 matthew 2007: sub csv_translate {
2008: my $text = shift;
2009: $text =~ s/\"/\"\"/g;
1.209 albertel 2010: $text =~ s/\n/ /g;
1.37 matthew 2011: return $text;
2012: }
1.180 matthew 2013:
2014: ###############################################################
2015: ###############################################################
2016:
2017: =pod
2018:
1.648 raeburn 2019: =item * &define_excel_formats()
1.180 matthew 2020:
2021: Define some commonly used Excel cell formats.
2022:
2023: Currently supported formats:
2024:
2025: =over 4
2026:
2027: =item header
2028:
2029: =item bold
2030:
2031: =item h1
2032:
2033: =item h2
2034:
2035: =item h3
2036:
1.256 matthew 2037: =item h4
2038:
2039: =item i
2040:
1.180 matthew 2041: =item date
2042:
2043: =back
2044:
2045: Inputs: $workbook
2046:
2047: Returns: $format, a hash reference.
2048:
1.1057 foxr 2049:
1.180 matthew 2050: =cut
2051:
2052: ###############################################################
2053: ###############################################################
2054: sub define_excel_formats {
2055: my ($workbook) = @_;
2056: my $format;
2057: $format->{'header'} = $workbook->add_format(bold => 1,
2058: bottom => 1,
2059: align => 'center');
2060: $format->{'bold'} = $workbook->add_format(bold=>1);
2061: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2062: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2063: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2064: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2065: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2066: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2067: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2068: return $format;
2069: }
2070:
2071: ###############################################################
2072: ###############################################################
1.113 bowersj2 2073:
2074: =pod
2075:
1.648 raeburn 2076: =item * &create_workbook()
1.255 matthew 2077:
2078: Create an Excel worksheet. If it fails, output message on the
2079: request object and return undefs.
2080:
2081: Inputs: Apache request object
2082:
2083: Returns (undef) on failure,
2084: Excel worksheet object, scalar with filename, and formats
2085: from &Apache::loncommon::define_excel_formats on success
2086:
2087: =cut
2088:
2089: ###############################################################
2090: ###############################################################
2091: sub create_workbook {
2092: my ($r) = @_;
2093: #
2094: # Create the excel spreadsheet
2095: my $filename = '/prtspool/'.
1.258 albertel 2096: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2097: time.'_'.rand(1000000000).'.xls';
2098: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2099: if (! defined($workbook)) {
2100: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2101: $r->print(
2102: '<p class="LC_error">'
2103: .&mt('Problems occurred in creating the new Excel file.')
2104: .' '.&mt('This error has been logged.')
2105: .' '.&mt('Please alert your LON-CAPA administrator.')
2106: .'</p>'
2107: );
1.255 matthew 2108: return (undef);
2109: }
2110: #
1.1014 foxr 2111: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2112: #
2113: my $format = &Apache::loncommon::define_excel_formats($workbook);
2114: return ($workbook,$filename,$format);
2115: }
2116:
2117: ###############################################################
2118: ###############################################################
2119:
2120: =pod
2121:
1.648 raeburn 2122: =item * &create_text_file()
1.113 bowersj2 2123:
1.542 raeburn 2124: Create a file to write to and eventually make available to the user.
1.256 matthew 2125: If file creation fails, outputs an error message on the request object and
2126: return undefs.
1.113 bowersj2 2127:
1.256 matthew 2128: Inputs: Apache request object, and file suffix
1.113 bowersj2 2129:
1.256 matthew 2130: Returns (undef) on failure,
2131: Filehandle and filename on success.
1.113 bowersj2 2132:
2133: =cut
2134:
1.256 matthew 2135: ###############################################################
2136: ###############################################################
2137: sub create_text_file {
2138: my ($r,$suffix) = @_;
2139: if (! defined($suffix)) { $suffix = 'txt'; };
2140: my $fh;
2141: my $filename = '/prtspool/'.
1.258 albertel 2142: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2143: time.'_'.rand(1000000000).'.'.$suffix;
2144: $fh = Apache::File->new('>/home/httpd'.$filename);
2145: if (! defined($fh)) {
2146: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2147: $r->print(
2148: '<p class="LC_error">'
2149: .&mt('Problems occurred in creating the output file.')
2150: .' '.&mt('This error has been logged.')
2151: .' '.&mt('Please alert your LON-CAPA administrator.')
2152: .'</p>'
2153: );
1.113 bowersj2 2154: }
1.256 matthew 2155: return ($fh,$filename)
1.113 bowersj2 2156: }
2157:
2158:
1.256 matthew 2159: =pod
1.113 bowersj2 2160:
2161: =back
2162:
2163: =cut
1.37 matthew 2164:
2165: ###############################################################
1.33 matthew 2166: ## Home server <option> list generating code ##
2167: ###############################################################
1.35 matthew 2168:
1.169 www 2169: # ------------------------------------------
2170:
2171: sub domain_select {
2172: my ($name,$value,$multiple)=@_;
2173: my %domains=map {
1.514 albertel 2174: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2175: } &Apache::lonnet::all_domains();
1.169 www 2176: if ($multiple) {
2177: $domains{''}=&mt('Any domain');
1.550 albertel 2178: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2179: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2180: } else {
1.550 albertel 2181: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2182: return &select_form($name,$value,\%domains);
1.169 www 2183: }
2184: }
2185:
1.282 albertel 2186: #-------------------------------------------
2187:
2188: =pod
2189:
1.519 raeburn 2190: =head1 Routines for form select boxes
2191:
2192: =over 4
2193:
1.648 raeburn 2194: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2195:
2196: Returns a string containing a <select> element int multiple mode
2197:
2198:
2199: Args:
2200: $name - name of the <select> element
1.506 raeburn 2201: $value - scalar or array ref of values that should already be selected
1.282 albertel 2202: $size - number of rows long the select element is
1.283 albertel 2203: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2204: (shown text should already have been &mt())
1.506 raeburn 2205: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2206:
1.282 albertel 2207: =cut
2208:
2209: #-------------------------------------------
1.169 www 2210: sub multiple_select_form {
1.284 albertel 2211: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2212: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2213: my $output='';
1.191 matthew 2214: if (! defined($size)) {
2215: $size = 4;
1.283 albertel 2216: if (scalar(keys(%$hash))<4) {
2217: $size = scalar(keys(%$hash));
1.191 matthew 2218: }
2219: }
1.734 bisitz 2220: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2221: my @order;
1.506 raeburn 2222: if (ref($order) eq 'ARRAY') {
2223: @order = @{$order};
2224: } else {
2225: @order = sort(keys(%$hash));
1.501 banghart 2226: }
2227: if (exists($$hash{'select_form_order'})) {
2228: @order = @{$$hash{'select_form_order'}};
2229: }
2230:
1.284 albertel 2231: foreach my $key (@order) {
1.356 albertel 2232: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2233: $output.='selected="selected" ' if ($selected{$key});
2234: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2235: }
2236: $output.="</select>\n";
2237: return $output;
2238: }
2239:
1.88 www 2240: #-------------------------------------------
2241:
2242: =pod
2243:
1.1075.2.115 raeburn 2244: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2245:
2246: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2247: allow a user to select options from a ref to a hash containing:
2248: option_name => displayed text. An optional $onchange can include
1.1075.2.115 raeburn 2249: a javascript onchange item, e.g., onchange="this.form.submit();".
2250: An optional arg -- $readonly -- if true will cause the select form
2251: to be disabled, e.g., for the case where an instructor has a section-
2252: specific role, and is viewing/modifying parameters.
1.970 raeburn 2253:
1.88 www 2254: See lonrights.pm for an example invocation and use.
2255:
2256: =cut
2257:
2258: #-------------------------------------------
2259: sub select_form {
1.1075.2.115 raeburn 2260: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2261: return unless (ref($hashref) eq 'HASH');
2262: if ($onchange) {
2263: $onchange = ' onchange="'.$onchange.'"';
2264: }
2265: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2266: my @keys;
1.970 raeburn 2267: if (exists($hashref->{'select_form_order'})) {
2268: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2269: } else {
1.970 raeburn 2270: @keys=sort(keys(%{$hashref}));
1.128 albertel 2271: }
1.356 albertel 2272: foreach my $key (@keys) {
2273: $selectform.=
2274: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2275: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2276: ">".$hashref->{$key}."</option>\n";
1.88 www 2277: }
2278: $selectform.="</select>";
2279: return $selectform;
2280: }
2281:
1.475 www 2282: # For display filters
2283:
2284: sub display_filter {
1.1074 raeburn 2285: my ($context) = @_;
1.475 www 2286: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2287: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2288: my $phraseinput = 'hidden';
2289: my $includeinput = 'hidden';
2290: my ($checked,$includetypestext);
2291: if ($env{'form.displayfilter'} eq 'containing') {
2292: $phraseinput = 'text';
2293: if ($context eq 'parmslog') {
2294: $includeinput = 'checkbox';
2295: if ($env{'form.includetypes'}) {
2296: $checked = ' checked="checked"';
2297: }
2298: $includetypestext = &mt('Include parameter types');
2299: }
2300: } else {
2301: $includetypestext = ' ';
2302: }
2303: my ($additional,$secondid,$thirdid);
2304: if ($context eq 'parmslog') {
2305: $additional =
2306: '<label><input type="'.$includeinput.'" name="includetypes"'.
2307: $checked.' name="includetypes" value="1" id="includetypes" />'.
2308: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2309: '</label>';
2310: $secondid = 'includetypes';
2311: $thirdid = 'includetypestext';
2312: }
2313: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2314: '$secondid','$thirdid')";
2315: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2316: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2317: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2318: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2319: &mt('Filter: [_1]',
1.477 www 2320: &select_form($env{'form.displayfilter'},
2321: 'displayfilter',
1.970 raeburn 2322: {'currentfolder' => 'Current folder/page',
1.477 www 2323: 'containing' => 'Containing phrase',
1.1074 raeburn 2324: 'none' => 'None'},$onchange)).' '.
2325: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2326: &HTML::Entities::encode($env{'form.containingphrase'}).
2327: '" />'.$additional;
2328: }
2329:
2330: sub display_filter_js {
2331: my $includetext = &mt('Include parameter types');
2332: return <<"ENDJS";
2333:
2334: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2335: var firstType = 'hidden';
2336: if (setter.options[setter.selectedIndex].value == 'containing') {
2337: firstType = 'text';
2338: }
2339: firstObject = document.getElementById(firstid);
2340: if (typeof(firstObject) == 'object') {
2341: if (firstObject.type != firstType) {
2342: changeInputType(firstObject,firstType);
2343: }
2344: }
2345: if (context == 'parmslog') {
2346: var secondType = 'hidden';
2347: if (firstType == 'text') {
2348: secondType = 'checkbox';
2349: }
2350: secondObject = document.getElementById(secondid);
2351: if (typeof(secondObject) == 'object') {
2352: if (secondObject.type != secondType) {
2353: changeInputType(secondObject,secondType);
2354: }
2355: }
2356: var textItem = document.getElementById(thirdid);
2357: var currtext = textItem.innerHTML;
2358: var newtext;
2359: if (firstType == 'text') {
2360: newtext = '$includetext';
2361: } else {
2362: newtext = ' ';
2363: }
2364: if (currtext != newtext) {
2365: textItem.innerHTML = newtext;
2366: }
2367: }
2368: return;
2369: }
2370:
2371: function changeInputType(oldObject,newType) {
2372: var newObject = document.createElement('input');
2373: newObject.type = newType;
2374: if (oldObject.size) {
2375: newObject.size = oldObject.size;
2376: }
2377: if (oldObject.value) {
2378: newObject.value = oldObject.value;
2379: }
2380: if (oldObject.name) {
2381: newObject.name = oldObject.name;
2382: }
2383: if (oldObject.id) {
2384: newObject.id = oldObject.id;
2385: }
2386: oldObject.parentNode.replaceChild(newObject,oldObject);
2387: return;
2388: }
2389:
2390: ENDJS
1.475 www 2391: }
2392:
1.167 www 2393: sub gradeleveldescription {
2394: my $gradelevel=shift;
2395: my %gradelevels=(0 => 'Not specified',
2396: 1 => 'Grade 1',
2397: 2 => 'Grade 2',
2398: 3 => 'Grade 3',
2399: 4 => 'Grade 4',
2400: 5 => 'Grade 5',
2401: 6 => 'Grade 6',
2402: 7 => 'Grade 7',
2403: 8 => 'Grade 8',
2404: 9 => 'Grade 9',
2405: 10 => 'Grade 10',
2406: 11 => 'Grade 11',
2407: 12 => 'Grade 12',
2408: 13 => 'Grade 13',
2409: 14 => '100 Level',
2410: 15 => '200 Level',
2411: 16 => '300 Level',
2412: 17 => '400 Level',
2413: 18 => 'Graduate Level');
2414: return &mt($gradelevels{$gradelevel});
2415: }
2416:
1.163 www 2417: sub select_level_form {
2418: my ($deflevel,$name)=@_;
2419: unless ($deflevel) { $deflevel=0; }
1.167 www 2420: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2421: for (my $i=0; $i<=18; $i++) {
2422: $selectform.="<option value=\"$i\" ".
1.253 albertel 2423: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2424: ">".&gradeleveldescription($i)."</option>\n";
2425: }
2426: $selectform.="</select>";
2427: return $selectform;
1.163 www 2428: }
1.167 www 2429:
1.35 matthew 2430: #-------------------------------------------
2431:
1.45 matthew 2432: =pod
2433:
1.1075.2.115 raeburn 2434: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2435:
2436: Returns a string containing a <select name='$name' size='1'> form to
2437: allow a user to select the domain to preform an operation in.
2438: See loncreateuser.pm for an example invocation and use.
2439:
1.90 www 2440: If the $includeempty flag is set, it also includes an empty choice ("no domain
2441: selected");
2442:
1.743 raeburn 2443: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2444:
1.910 raeburn 2445: 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.
2446:
1.1075.2.36 raeburn 2447: The optional $incdoms is a reference to an array of domains which will be the only available options.
2448:
1.1075.2.115 raeburn 2449: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
2450:
2451: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
1.563 raeburn 2452:
1.35 matthew 2453: =cut
2454:
2455: #-------------------------------------------
1.34 matthew 2456: sub select_dom_form {
1.1075.2.115 raeburn 2457: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2458: if ($onchange) {
1.874 raeburn 2459: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2460: }
1.1075.2.115 raeburn 2461: if ($disabled) {
2462: $disabled = ' disabled="disabled"';
2463: }
1.1075.2.36 raeburn 2464: my (@domains,%exclude);
1.910 raeburn 2465: if (ref($incdoms) eq 'ARRAY') {
2466: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2467: } else {
2468: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2469: }
1.90 www 2470: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2471: if (ref($excdoms) eq 'ARRAY') {
2472: map { $exclude{$_} = 1; } @{$excdoms};
2473: }
1.1075.2.115 raeburn 2474: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2475: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2476: next if ($exclude{$dom});
1.356 albertel 2477: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2478: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2479: if ($showdomdesc) {
2480: if ($dom ne '') {
2481: my $domdesc = &Apache::lonnet::domain($dom,'description');
2482: if ($domdesc ne '') {
2483: $selectdomain .= ' ('.$domdesc.')';
2484: }
2485: }
2486: }
2487: $selectdomain .= "</option>\n";
1.34 matthew 2488: }
2489: $selectdomain.="</select>";
2490: return $selectdomain;
2491: }
2492:
1.35 matthew 2493: #-------------------------------------------
2494:
1.45 matthew 2495: =pod
2496:
1.648 raeburn 2497: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2498:
1.586 raeburn 2499: input: 4 arguments (two required, two optional) -
2500: $domain - domain of new user
2501: $name - name of form element
2502: $default - Value of 'default' causes a default item to be first
2503: option, and selected by default.
2504: $hide - Value of 'hide' causes hiding of the name of the server,
2505: if 1 server found, or default, if 0 found.
1.594 raeburn 2506: output: returns 2 items:
1.586 raeburn 2507: (a) form element which contains either:
2508: (i) <select name="$name">
2509: <option value="$hostid1">$hostid $servers{$hostid}</option>
2510: <option value="$hostid2">$hostid $servers{$hostid}</option>
2511: </select>
2512: form item if there are multiple library servers in $domain, or
2513: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2514: if there is only one library server in $domain.
2515:
2516: (b) number of library servers found.
2517:
2518: See loncreateuser.pm for example of use.
1.35 matthew 2519:
2520: =cut
2521:
2522: #-------------------------------------------
1.586 raeburn 2523: sub home_server_form_item {
2524: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2525: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2526: my $result;
2527: my $numlib = keys(%servers);
2528: if ($numlib > 1) {
2529: $result .= '<select name="'.$name.'" />'."\n";
2530: if ($default) {
1.804 bisitz 2531: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2532: '</option>'."\n";
2533: }
2534: foreach my $hostid (sort(keys(%servers))) {
2535: $result.= '<option value="'.$hostid.'">'.
2536: $hostid.' '.$servers{$hostid}."</option>\n";
2537: }
2538: $result .= '</select>'."\n";
2539: } elsif ($numlib == 1) {
2540: my $hostid;
2541: foreach my $item (keys(%servers)) {
2542: $hostid = $item;
2543: }
2544: $result .= '<input type="hidden" name="'.$name.'" value="'.
2545: $hostid.'" />';
2546: if (!$hide) {
2547: $result .= $hostid.' '.$servers{$hostid};
2548: }
2549: $result .= "\n";
2550: } elsif ($default) {
2551: $result .= '<input type="hidden" name="'.$name.
2552: '" value="default" />';
2553: if (!$hide) {
2554: $result .= &mt('default');
2555: }
2556: $result .= "\n";
1.33 matthew 2557: }
1.586 raeburn 2558: return ($result,$numlib);
1.33 matthew 2559: }
1.112 bowersj2 2560:
2561: =pod
2562:
1.534 albertel 2563: =back
2564:
1.112 bowersj2 2565: =cut
1.87 matthew 2566:
2567: ###############################################################
1.112 bowersj2 2568: ## Decoding User Agent ##
1.87 matthew 2569: ###############################################################
2570:
2571: =pod
2572:
1.112 bowersj2 2573: =head1 Decoding the User Agent
2574:
2575: =over 4
2576:
2577: =item * &decode_user_agent()
1.87 matthew 2578:
2579: Inputs: $r
2580:
2581: Outputs:
2582:
2583: =over 4
2584:
1.112 bowersj2 2585: =item * $httpbrowser
1.87 matthew 2586:
1.112 bowersj2 2587: =item * $clientbrowser
1.87 matthew 2588:
1.112 bowersj2 2589: =item * $clientversion
1.87 matthew 2590:
1.112 bowersj2 2591: =item * $clientmathml
1.87 matthew 2592:
1.112 bowersj2 2593: =item * $clientunicode
1.87 matthew 2594:
1.112 bowersj2 2595: =item * $clientos
1.87 matthew 2596:
1.1075.2.42 raeburn 2597: =item * $clientmobile
2598:
2599: =item * $clientinfo
2600:
1.1075.2.77 raeburn 2601: =item * $clientosversion
2602:
1.87 matthew 2603: =back
2604:
1.157 matthew 2605: =back
2606:
1.87 matthew 2607: =cut
2608:
2609: ###############################################################
2610: ###############################################################
2611: sub decode_user_agent {
1.247 albertel 2612: my ($r)=@_;
1.87 matthew 2613: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2614: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2615: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2616: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2617: my $clientbrowser='unknown';
2618: my $clientversion='0';
2619: my $clientmathml='';
2620: my $clientunicode='0';
1.1075.2.42 raeburn 2621: my $clientmobile=0;
1.1075.2.77 raeburn 2622: my $clientosversion='';
1.87 matthew 2623: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2624: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2625: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2626: $clientbrowser=$bname;
2627: $httpbrowser=~/$vreg/i;
2628: $clientversion=$1;
2629: $clientmathml=($clientversion>=$minv);
2630: $clientunicode=($clientversion>=$univ);
2631: }
2632: }
2633: my $clientos='unknown';
1.1075.2.42 raeburn 2634: my $clientinfo;
1.87 matthew 2635: if (($httpbrowser=~/linux/i) ||
2636: ($httpbrowser=~/unix/i) ||
2637: ($httpbrowser=~/ux/i) ||
2638: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2639: if (($httpbrowser=~/vax/i) ||
2640: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2641: if ($httpbrowser=~/next/i) { $clientos='next'; }
2642: if (($httpbrowser=~/mac/i) ||
2643: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2644: if ($httpbrowser=~/win/i) {
2645: $clientos='win';
2646: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2647: $clientosversion = $1;
2648: }
2649: }
1.87 matthew 2650: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2651: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2652: $clientmobile=lc($1);
2653: }
2654: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2655: $clientinfo = 'firefox-'.$1;
2656: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2657: $clientinfo = 'chromeframe-'.$1;
2658: }
1.87 matthew 2659: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2660: $clientunicode,$clientos,$clientmobile,$clientinfo,
2661: $clientosversion);
1.87 matthew 2662: }
2663:
1.32 matthew 2664: ###############################################################
2665: ## Authentication changing form generation subroutines ##
2666: ###############################################################
2667: ##
2668: ## All of the authform_xxxxxxx subroutines take their inputs in a
2669: ## hash, and have reasonable default values.
2670: ##
2671: ## formname = the name given in the <form> tag.
1.35 matthew 2672: #-------------------------------------------
2673:
1.45 matthew 2674: =pod
2675:
1.112 bowersj2 2676: =head1 Authentication Routines
2677:
2678: =over 4
2679:
1.648 raeburn 2680: =item * &authform_xxxxxx()
1.35 matthew 2681:
2682: The authform_xxxxxx subroutines provide javascript and html forms which
2683: handle some of the conveniences required for authentication forms.
2684: This is not an optimal method, but it works.
2685:
2686: =over 4
2687:
1.112 bowersj2 2688: =item * authform_header
1.35 matthew 2689:
1.112 bowersj2 2690: =item * authform_authorwarning
1.35 matthew 2691:
1.112 bowersj2 2692: =item * authform_nochange
1.35 matthew 2693:
1.112 bowersj2 2694: =item * authform_kerberos
1.35 matthew 2695:
1.112 bowersj2 2696: =item * authform_internal
1.35 matthew 2697:
1.112 bowersj2 2698: =item * authform_filesystem
1.35 matthew 2699:
2700: =back
2701:
1.648 raeburn 2702: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2703:
1.35 matthew 2704: =cut
2705:
2706: #-------------------------------------------
1.32 matthew 2707: sub authform_header{
2708: my %in = (
2709: formname => 'cu',
1.80 albertel 2710: kerb_def_dom => '',
1.32 matthew 2711: @_,
2712: );
2713: $in{'formname'} = 'document.' . $in{'formname'};
2714: my $result='';
1.80 albertel 2715:
2716: #---------------------------------------------- Code for upper case translation
2717: my $Javascript_toUpperCase;
2718: unless ($in{kerb_def_dom}) {
2719: $Javascript_toUpperCase =<<"END";
2720: switch (choice) {
2721: case 'krb': currentform.elements[choicearg].value =
2722: currentform.elements[choicearg].value.toUpperCase();
2723: break;
2724: default:
2725: }
2726: END
2727: } else {
2728: $Javascript_toUpperCase = "";
2729: }
2730:
1.165 raeburn 2731: my $radioval = "'nochange'";
1.591 raeburn 2732: if (defined($in{'curr_authtype'})) {
2733: if ($in{'curr_authtype'} ne '') {
2734: $radioval = "'".$in{'curr_authtype'}."arg'";
2735: }
1.174 matthew 2736: }
1.165 raeburn 2737: my $argfield = 'null';
1.591 raeburn 2738: if (defined($in{'mode'})) {
1.165 raeburn 2739: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2740: if (defined($in{'curr_autharg'})) {
2741: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2742: $argfield = "'$in{'curr_autharg'}'";
2743: }
2744: }
2745: }
2746: }
2747:
1.32 matthew 2748: $result.=<<"END";
2749: var current = new Object();
1.165 raeburn 2750: current.radiovalue = $radioval;
2751: current.argfield = $argfield;
1.32 matthew 2752:
2753: function changed_radio(choice,currentform) {
2754: var choicearg = choice + 'arg';
2755: // If a radio button in changed, we need to change the argfield
2756: if (current.radiovalue != choice) {
2757: current.radiovalue = choice;
2758: if (current.argfield != null) {
2759: currentform.elements[current.argfield].value = '';
2760: }
2761: if (choice == 'nochange') {
2762: current.argfield = null;
2763: } else {
2764: current.argfield = choicearg;
2765: switch(choice) {
2766: case 'krb':
2767: currentform.elements[current.argfield].value =
2768: "$in{'kerb_def_dom'}";
2769: break;
2770: default:
2771: break;
2772: }
2773: }
2774: }
2775: return;
2776: }
1.22 www 2777:
1.32 matthew 2778: function changed_text(choice,currentform) {
2779: var choicearg = choice + 'arg';
2780: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2781: $Javascript_toUpperCase
1.32 matthew 2782: // clear old field
2783: if ((current.argfield != choicearg) && (current.argfield != null)) {
2784: currentform.elements[current.argfield].value = '';
2785: }
2786: current.argfield = choicearg;
2787: }
2788: set_auth_radio_buttons(choice,currentform);
2789: return;
1.20 www 2790: }
1.32 matthew 2791:
2792: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2793: var numauthchoices = currentform.login.length;
2794: if (typeof numauthchoices == "undefined") {
2795: return;
2796: }
1.32 matthew 2797: var i=0;
1.986 raeburn 2798: while (i < numauthchoices) {
1.32 matthew 2799: if (currentform.login[i].value == newvalue) { break; }
2800: i++;
2801: }
1.986 raeburn 2802: if (i == numauthchoices) {
1.32 matthew 2803: return;
2804: }
2805: current.radiovalue = newvalue;
2806: currentform.login[i].checked = true;
2807: return;
2808: }
2809: END
2810: return $result;
2811: }
2812:
1.1075.2.20 raeburn 2813: sub authform_authorwarning {
1.32 matthew 2814: my $result='';
1.144 matthew 2815: $result='<i>'.
2816: &mt('As a general rule, only authors or co-authors should be '.
2817: 'filesystem authenticated '.
2818: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2819: return $result;
2820: }
2821:
1.1075.2.20 raeburn 2822: sub authform_nochange {
1.32 matthew 2823: my %in = (
2824: formname => 'document.cu',
2825: kerb_def_dom => 'MSU.EDU',
2826: @_,
2827: );
1.1075.2.20 raeburn 2828: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2829: my $result;
1.1075.2.20 raeburn 2830: if (!$authnum) {
2831: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2832: } else {
2833: $result = '<label>'.&mt('[_1] Do not change login data',
2834: '<input type="radio" name="login" value="nochange" '.
2835: 'checked="checked" onclick="'.
1.281 albertel 2836: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2837: '</label>';
1.586 raeburn 2838: }
1.32 matthew 2839: return $result;
2840: }
2841:
1.591 raeburn 2842: sub authform_kerberos {
1.32 matthew 2843: my %in = (
2844: formname => 'document.cu',
2845: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2846: kerb_def_auth => 'krb4',
1.32 matthew 2847: @_,
2848: );
1.586 raeburn 2849: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1075.2.117 raeburn 2850: $autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2851: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2852: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2853: $check5 = ' checked="checked"';
1.80 albertel 2854: } else {
1.772 bisitz 2855: $check4 = ' checked="checked"';
1.80 albertel 2856: }
1.1075.2.117 raeburn 2857: if ($in{'readonly'}) {
2858: $disabled = ' disabled="disabled"';
2859: }
1.165 raeburn 2860: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2861: if (defined($in{'curr_authtype'})) {
2862: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2863: $krbcheck = ' checked="checked"';
1.623 raeburn 2864: if (defined($in{'mode'})) {
2865: if ($in{'mode'} eq 'modifyuser') {
2866: $krbcheck = '';
2867: }
2868: }
1.591 raeburn 2869: if (defined($in{'curr_kerb_ver'})) {
2870: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2871: $check5 = ' checked="checked"';
1.591 raeburn 2872: $check4 = '';
2873: } else {
1.772 bisitz 2874: $check4 = ' checked="checked"';
1.591 raeburn 2875: $check5 = '';
2876: }
1.586 raeburn 2877: }
1.591 raeburn 2878: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2879: $krbarg = $in{'curr_autharg'};
2880: }
1.586 raeburn 2881: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2882: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2883: $result =
2884: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2885: $in{'curr_autharg'},$krbver);
2886: } else {
2887: $result =
2888: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2889: }
2890: return $result;
2891: }
2892: }
2893: } else {
2894: if ($authnum == 1) {
1.784 bisitz 2895: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2896: }
2897: }
1.586 raeburn 2898: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2899: return;
1.587 raeburn 2900: } elsif ($authtype eq '') {
1.591 raeburn 2901: if (defined($in{'mode'})) {
1.587 raeburn 2902: if ($in{'mode'} eq 'modifycourse') {
2903: if ($authnum == 1) {
1.1075.2.117 raeburn 2904: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 2905: }
2906: }
2907: }
1.586 raeburn 2908: }
2909: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2910: if ($authtype eq '') {
2911: $authtype = '<input type="radio" name="login" value="krb" '.
2912: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1075.2.117 raeburn 2913: $krbcheck.$disabled.' />';
1.586 raeburn 2914: }
2915: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2916: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2917: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2918: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2919: $in{'curr_authtype'} eq 'krb4')) {
2920: $result .= &mt
1.144 matthew 2921: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2922: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2923: '<label>'.$authtype,
1.281 albertel 2924: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2925: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2926: 'onchange="'.$jscall.'"'.$disabled.' />',
2927: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
2928: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 2929: '</label>');
1.586 raeburn 2930: } elsif ($can_assign{'krb4'}) {
2931: $result .= &mt
2932: ('[_1] Kerberos authenticated with domain [_2] '.
2933: '[_3] Version 4 [_4]',
2934: '<label>'.$authtype,
2935: '</label><input type="text" size="10" name="krbarg" '.
2936: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2937: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2938: '<label><input type="hidden" name="krbver" value="4" />',
2939: '</label>');
2940: } elsif ($can_assign{'krb5'}) {
2941: $result .= &mt
2942: ('[_1] Kerberos authenticated with domain [_2] '.
2943: '[_3] Version 5 [_4]',
2944: '<label>'.$authtype,
2945: '</label><input type="text" size="10" name="krbarg" '.
2946: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2947: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2948: '<label><input type="hidden" name="krbver" value="5" />',
2949: '</label>');
2950: }
1.32 matthew 2951: return $result;
2952: }
2953:
1.1075.2.20 raeburn 2954: sub authform_internal {
1.586 raeburn 2955: my %in = (
1.32 matthew 2956: formname => 'document.cu',
2957: kerb_def_dom => 'MSU.EDU',
2958: @_,
2959: );
1.1075.2.117 raeburn 2960: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2961: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 2962: if ($in{'readonly'}) {
2963: $disabled = ' disabled="disabled"';
2964: }
1.591 raeburn 2965: if (defined($in{'curr_authtype'})) {
2966: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2967: if ($can_assign{'int'}) {
1.772 bisitz 2968: $intcheck = 'checked="checked" ';
1.623 raeburn 2969: if (defined($in{'mode'})) {
2970: if ($in{'mode'} eq 'modifyuser') {
2971: $intcheck = '';
2972: }
2973: }
1.591 raeburn 2974: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2975: $intarg = $in{'curr_autharg'};
2976: }
2977: } else {
2978: $result = &mt('Currently internally authenticated.');
2979: return $result;
1.165 raeburn 2980: }
2981: }
1.586 raeburn 2982: } else {
2983: if ($authnum == 1) {
1.784 bisitz 2984: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2985: }
2986: }
2987: if (!$can_assign{'int'}) {
2988: return;
1.587 raeburn 2989: } elsif ($authtype eq '') {
1.591 raeburn 2990: if (defined($in{'mode'})) {
1.587 raeburn 2991: if ($in{'mode'} eq 'modifycourse') {
2992: if ($authnum == 1) {
1.1075.2.117 raeburn 2993: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 2994: }
2995: }
2996: }
1.165 raeburn 2997: }
1.586 raeburn 2998: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2999: if ($authtype eq '') {
3000: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1075.2.117 raeburn 3001: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3002: }
1.605 bisitz 3003: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1075.2.117 raeburn 3004: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3005: $result = &mt
1.144 matthew 3006: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3007: '<label>'.$authtype,'</label>'.$autharg);
1.1075.2.118 raeburn 3008: $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 3009: return $result;
3010: }
3011:
1.1075.2.20 raeburn 3012: sub authform_local {
1.32 matthew 3013: my %in = (
3014: formname => 'document.cu',
3015: kerb_def_dom => 'MSU.EDU',
3016: @_,
3017: );
1.1075.2.117 raeburn 3018: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3019: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3020: if ($in{'readonly'}) {
3021: $disabled = ' disabled="disabled"';
3022: }
1.591 raeburn 3023: if (defined($in{'curr_authtype'})) {
3024: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3025: if ($can_assign{'loc'}) {
1.772 bisitz 3026: $loccheck = 'checked="checked" ';
1.623 raeburn 3027: if (defined($in{'mode'})) {
3028: if ($in{'mode'} eq 'modifyuser') {
3029: $loccheck = '';
3030: }
3031: }
1.591 raeburn 3032: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3033: $locarg = $in{'curr_autharg'};
3034: }
3035: } else {
3036: $result = &mt('Currently using local (institutional) authentication.');
3037: return $result;
1.165 raeburn 3038: }
3039: }
1.586 raeburn 3040: } else {
3041: if ($authnum == 1) {
1.784 bisitz 3042: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3043: }
3044: }
3045: if (!$can_assign{'loc'}) {
3046: return;
1.587 raeburn 3047: } elsif ($authtype eq '') {
1.591 raeburn 3048: if (defined($in{'mode'})) {
1.587 raeburn 3049: if ($in{'mode'} eq 'modifycourse') {
3050: if ($authnum == 1) {
1.1075.2.117 raeburn 3051: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3052: }
3053: }
3054: }
1.165 raeburn 3055: }
1.586 raeburn 3056: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3057: if ($authtype eq '') {
3058: $authtype = '<input type="radio" name="login" value="loc" '.
3059: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3060: $jscall.'"'.$disabled.' />';
1.586 raeburn 3061: }
3062: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1075.2.117 raeburn 3063: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3064: $result = &mt('[_1] Local Authentication with argument [_2]',
3065: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3066: return $result;
3067: }
3068:
1.1075.2.20 raeburn 3069: sub authform_filesystem {
1.32 matthew 3070: my %in = (
3071: formname => 'document.cu',
3072: kerb_def_dom => 'MSU.EDU',
3073: @_,
3074: );
1.1075.2.117 raeburn 3075: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3076: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3077: if ($in{'readonly'}) {
3078: $disabled = ' disabled="disabled"';
3079: }
1.591 raeburn 3080: if (defined($in{'curr_authtype'})) {
3081: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3082: if ($can_assign{'fsys'}) {
1.772 bisitz 3083: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3084: if (defined($in{'mode'})) {
3085: if ($in{'mode'} eq 'modifyuser') {
3086: $fsyscheck = '';
3087: }
3088: }
1.586 raeburn 3089: } else {
3090: $result = &mt('Currently Filesystem Authenticated.');
3091: return $result;
3092: }
3093: }
3094: } else {
3095: if ($authnum == 1) {
1.784 bisitz 3096: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3097: }
3098: }
3099: if (!$can_assign{'fsys'}) {
3100: return;
1.587 raeburn 3101: } elsif ($authtype eq '') {
1.591 raeburn 3102: if (defined($in{'mode'})) {
1.587 raeburn 3103: if ($in{'mode'} eq 'modifycourse') {
3104: if ($authnum == 1) {
1.1075.2.117 raeburn 3105: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3106: }
3107: }
3108: }
1.586 raeburn 3109: }
3110: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3111: if ($authtype eq '') {
3112: $authtype = '<input type="radio" name="login" value="fsys" '.
3113: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3114: $jscall.'"'.$disabled.' />';
1.586 raeburn 3115: }
3116: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
1.1075.2.117 raeburn 3117: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3118: $result = &mt
1.144 matthew 3119: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3120: '<label><input type="radio" name="login" value="fsys" '.
1.1075.2.117 raeburn 3121: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />',
1.605 bisitz 3122: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.1075.2.117 raeburn 3123: 'onchange="'.$jscall.'"'.$disabled.' />');
1.32 matthew 3124: return $result;
3125: }
3126:
1.586 raeburn 3127: sub get_assignable_auth {
3128: my ($dom) = @_;
3129: if ($dom eq '') {
3130: $dom = $env{'request.role.domain'};
3131: }
3132: my %can_assign = (
3133: krb4 => 1,
3134: krb5 => 1,
3135: int => 1,
3136: loc => 1,
3137: );
3138: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3139: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3140: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3141: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3142: my $context;
3143: if ($env{'request.role'} =~ /^au/) {
3144: $context = 'author';
1.1075.2.117 raeburn 3145: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3146: $context = 'domain';
3147: } elsif ($env{'request.course.id'}) {
3148: $context = 'course';
3149: }
3150: if ($context) {
3151: if (ref($authhash->{$context}) eq 'HASH') {
3152: %can_assign = %{$authhash->{$context}};
3153: }
3154: }
3155: }
3156: }
3157: my $authnum = 0;
3158: foreach my $key (keys(%can_assign)) {
3159: if ($can_assign{$key}) {
3160: $authnum ++;
3161: }
3162: }
3163: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3164: $authnum --;
3165: }
3166: return ($authnum,%can_assign);
3167: }
3168:
1.80 albertel 3169: ###############################################################
3170: ## Get Kerberos Defaults for Domain ##
3171: ###############################################################
3172: ##
3173: ## Returns default kerberos version and an associated argument
3174: ## as listed in file domain.tab. If not listed, provides
3175: ## appropriate default domain and kerberos version.
3176: ##
3177: #-------------------------------------------
3178:
3179: =pod
3180:
1.648 raeburn 3181: =item * &get_kerberos_defaults()
1.80 albertel 3182:
3183: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3184: version and domain. If not found, it defaults to version 4 and the
3185: domain of the server.
1.80 albertel 3186:
1.648 raeburn 3187: =over 4
3188:
1.80 albertel 3189: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3190:
1.648 raeburn 3191: =back
3192:
3193: =back
3194:
1.80 albertel 3195: =cut
3196:
3197: #-------------------------------------------
3198: sub get_kerberos_defaults {
3199: my $domain=shift;
1.641 raeburn 3200: my ($krbdef,$krbdefdom);
3201: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3202: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3203: $krbdef = $domdefaults{'auth_def'};
3204: $krbdefdom = $domdefaults{'auth_arg_def'};
3205: } else {
1.80 albertel 3206: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3207: my $krbdefdom=$1;
3208: $krbdefdom=~tr/a-z/A-Z/;
3209: $krbdef = "krb4";
3210: }
3211: return ($krbdef,$krbdefdom);
3212: }
1.112 bowersj2 3213:
1.32 matthew 3214:
1.46 matthew 3215: ###############################################################
3216: ## Thesaurus Functions ##
3217: ###############################################################
1.20 www 3218:
1.46 matthew 3219: =pod
1.20 www 3220:
1.112 bowersj2 3221: =head1 Thesaurus Functions
3222:
3223: =over 4
3224:
1.648 raeburn 3225: =item * &initialize_keywords()
1.46 matthew 3226:
3227: Initializes the package variable %Keywords if it is empty. Uses the
3228: package variable $thesaurus_db_file.
3229:
3230: =cut
3231:
3232: ###################################################
3233:
3234: sub initialize_keywords {
3235: return 1 if (scalar keys(%Keywords));
3236: # If we are here, %Keywords is empty, so fill it up
3237: # Make sure the file we need exists...
3238: if (! -e $thesaurus_db_file) {
3239: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3240: " failed because it does not exist");
3241: return 0;
3242: }
3243: # Set up the hash as a database
3244: my %thesaurus_db;
3245: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3246: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3247: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3248: $thesaurus_db_file);
3249: return 0;
3250: }
3251: # Get the average number of appearances of a word.
3252: my $avecount = $thesaurus_db{'average.count'};
3253: # Put keywords (those that appear > average) into %Keywords
3254: while (my ($word,$data)=each (%thesaurus_db)) {
3255: my ($count,undef) = split /:/,$data;
3256: $Keywords{$word}++ if ($count > $avecount);
3257: }
3258: untie %thesaurus_db;
3259: # Remove special values from %Keywords.
1.356 albertel 3260: foreach my $value ('total.count','average.count') {
3261: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3262: }
1.46 matthew 3263: return 1;
3264: }
3265:
3266: ###################################################
3267:
3268: =pod
3269:
1.648 raeburn 3270: =item * &keyword($word)
1.46 matthew 3271:
3272: Returns true if $word is a keyword. A keyword is a word that appears more
3273: than the average number of times in the thesaurus database. Calls
3274: &initialize_keywords
3275:
3276: =cut
3277:
3278: ###################################################
1.20 www 3279:
3280: sub keyword {
1.46 matthew 3281: return if (!&initialize_keywords());
3282: my $word=lc(shift());
3283: $word=~s/\W//g;
3284: return exists($Keywords{$word});
1.20 www 3285: }
1.46 matthew 3286:
3287: ###############################################################
3288:
3289: =pod
1.20 www 3290:
1.648 raeburn 3291: =item * &get_related_words()
1.46 matthew 3292:
1.160 matthew 3293: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3294: an array of words. If the keyword is not in the thesaurus, an empty array
3295: will be returned. The order of the words returned is determined by the
3296: database which holds them.
3297:
3298: Uses global $thesaurus_db_file.
3299:
1.1057 foxr 3300:
1.46 matthew 3301: =cut
3302:
3303: ###############################################################
3304: sub get_related_words {
3305: my $keyword = shift;
3306: my %thesaurus_db;
3307: if (! -e $thesaurus_db_file) {
3308: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3309: "failed because the file does not exist");
3310: return ();
3311: }
3312: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3313: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3314: return ();
3315: }
3316: my @Words=();
1.429 www 3317: my $count=0;
1.46 matthew 3318: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3319: # The first element is the number of times
3320: # the word appears. We do not need it now.
1.429 www 3321: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3322: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3323: my $threshold=$mostfrequentcount/10;
3324: foreach my $possibleword (@RelatedWords) {
3325: my ($word,$wordcount)=split(/\,/,$possibleword);
3326: if ($wordcount>$threshold) {
3327: push(@Words,$word);
3328: $count++;
3329: if ($count>10) { last; }
3330: }
1.20 www 3331: }
3332: }
1.46 matthew 3333: untie %thesaurus_db;
3334: return @Words;
1.14 harris41 3335: }
1.46 matthew 3336:
1.112 bowersj2 3337: =pod
3338:
3339: =back
3340:
3341: =cut
1.61 www 3342:
3343: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3344: =pod
3345:
1.112 bowersj2 3346: =head1 User Name Functions
3347:
3348: =over 4
3349:
1.648 raeburn 3350: =item * &plainname($uname,$udom,$first)
1.81 albertel 3351:
1.112 bowersj2 3352: Takes a users logon name and returns it as a string in
1.226 albertel 3353: "first middle last generation" form
3354: if $first is set to 'lastname' then it returns it as
3355: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3356:
3357: =cut
1.61 www 3358:
1.295 www 3359:
1.81 albertel 3360: ###############################################################
1.61 www 3361: sub plainname {
1.226 albertel 3362: my ($uname,$udom,$first)=@_;
1.537 albertel 3363: return if (!defined($uname) || !defined($udom));
1.295 www 3364: my %names=&getnames($uname,$udom);
1.226 albertel 3365: my $name=&Apache::lonnet::format_name($names{'firstname'},
3366: $names{'middlename'},
3367: $names{'lastname'},
3368: $names{'generation'},$first);
3369: $name=~s/^\s+//;
1.62 www 3370: $name=~s/\s+$//;
3371: $name=~s/\s+/ /g;
1.353 albertel 3372: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3373: return $name;
1.61 www 3374: }
1.66 www 3375:
3376: # -------------------------------------------------------------------- Nickname
1.81 albertel 3377: =pod
3378:
1.648 raeburn 3379: =item * &nickname($uname,$udom)
1.81 albertel 3380:
3381: Gets a users name and returns it as a string as
3382:
3383: ""nickname""
1.66 www 3384:
1.81 albertel 3385: if the user has a nickname or
3386:
3387: "first middle last generation"
3388:
3389: if the user does not
3390:
3391: =cut
1.66 www 3392:
3393: sub nickname {
3394: my ($uname,$udom)=@_;
1.537 albertel 3395: return if (!defined($uname) || !defined($udom));
1.295 www 3396: my %names=&getnames($uname,$udom);
1.68 albertel 3397: my $name=$names{'nickname'};
1.66 www 3398: if ($name) {
3399: $name='"'.$name.'"';
3400: } else {
3401: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3402: $names{'lastname'}.' '.$names{'generation'};
3403: $name=~s/\s+$//;
3404: $name=~s/\s+/ /g;
3405: }
3406: return $name;
3407: }
3408:
1.295 www 3409: sub getnames {
3410: my ($uname,$udom)=@_;
1.537 albertel 3411: return if (!defined($uname) || !defined($udom));
1.433 albertel 3412: if ($udom eq 'public' && $uname eq 'public') {
3413: return ('lastname' => &mt('Public'));
3414: }
1.295 www 3415: my $id=$uname.':'.$udom;
3416: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3417: if ($cached) {
3418: return %{$names};
3419: } else {
3420: my %loadnames=&Apache::lonnet::get('environment',
3421: ['firstname','middlename','lastname','generation','nickname'],
3422: $udom,$uname);
3423: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3424: return %loadnames;
3425: }
3426: }
1.61 www 3427:
1.542 raeburn 3428: # -------------------------------------------------------------------- getemails
1.648 raeburn 3429:
1.542 raeburn 3430: =pod
3431:
1.648 raeburn 3432: =item * &getemails($uname,$udom)
1.542 raeburn 3433:
3434: Gets a user's email information and returns it as a hash with keys:
3435: notification, critnotification, permanentemail
3436:
3437: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3438: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3439:
1.648 raeburn 3440:
1.542 raeburn 3441: =cut
3442:
1.648 raeburn 3443:
1.466 albertel 3444: sub getemails {
3445: my ($uname,$udom)=@_;
3446: if ($udom eq 'public' && $uname eq 'public') {
3447: return;
3448: }
1.467 www 3449: if (!$udom) { $udom=$env{'user.domain'}; }
3450: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3451: my $id=$uname.':'.$udom;
3452: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3453: if ($cached) {
3454: return %{$names};
3455: } else {
3456: my %loadnames=&Apache::lonnet::get('environment',
3457: ['notification','critnotification',
3458: 'permanentemail'],
3459: $udom,$uname);
3460: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3461: return %loadnames;
3462: }
3463: }
3464:
1.551 albertel 3465: sub flush_email_cache {
3466: my ($uname,$udom)=@_;
3467: if (!$udom) { $udom =$env{'user.domain'}; }
3468: if (!$uname) { $uname=$env{'user.name'}; }
3469: return if ($udom eq 'public' && $uname eq 'public');
3470: my $id=$uname.':'.$udom;
3471: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3472: }
3473:
1.728 raeburn 3474: # -------------------------------------------------------------------- getlangs
3475:
3476: =pod
3477:
3478: =item * &getlangs($uname,$udom)
3479:
3480: Gets a user's language preference and returns it as a hash with key:
3481: language.
3482:
3483: =cut
3484:
3485:
3486: sub getlangs {
3487: my ($uname,$udom) = @_;
3488: if (!$udom) { $udom =$env{'user.domain'}; }
3489: if (!$uname) { $uname=$env{'user.name'}; }
3490: my $id=$uname.':'.$udom;
3491: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3492: if ($cached) {
3493: return %{$langs};
3494: } else {
3495: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3496: $udom,$uname);
3497: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3498: return %loadlangs;
3499: }
3500: }
3501:
3502: sub flush_langs_cache {
3503: my ($uname,$udom)=@_;
3504: if (!$udom) { $udom =$env{'user.domain'}; }
3505: if (!$uname) { $uname=$env{'user.name'}; }
3506: return if ($udom eq 'public' && $uname eq 'public');
3507: my $id=$uname.':'.$udom;
3508: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3509: }
3510:
1.61 www 3511: # ------------------------------------------------------------------ Screenname
1.81 albertel 3512:
3513: =pod
3514:
1.648 raeburn 3515: =item * &screenname($uname,$udom)
1.81 albertel 3516:
3517: Gets a users screenname and returns it as a string
3518:
3519: =cut
1.61 www 3520:
3521: sub screenname {
3522: my ($uname,$udom)=@_;
1.258 albertel 3523: if ($uname eq $env{'user.name'} &&
3524: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3525: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3526: return $names{'screenname'};
1.62 www 3527: }
3528:
1.212 albertel 3529:
1.802 bisitz 3530: # ------------------------------------------------------------- Confirm Wrapper
3531: =pod
3532:
1.1075.2.42 raeburn 3533: =item * &confirmwrapper($message)
1.802 bisitz 3534:
3535: Wrap messages about completion of operation in box
3536:
3537: =cut
3538:
3539: sub confirmwrapper {
3540: my ($message)=@_;
3541: if ($message) {
3542: return "\n".'<div class="LC_confirm_box">'."\n"
3543: .$message."\n"
3544: .'</div>'."\n";
3545: } else {
3546: return $message;
3547: }
3548: }
3549:
1.62 www 3550: # ------------------------------------------------------------- Message Wrapper
3551:
3552: sub messagewrapper {
1.369 www 3553: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3554: return
1.441 albertel 3555: '<a href="/adm/email?compose=individual&'.
3556: 'recname='.$username.'&recdom='.$domain.
3557: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3558: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3559: }
1.802 bisitz 3560:
1.74 www 3561: # --------------------------------------------------------------- Notes Wrapper
3562:
3563: sub noteswrapper {
3564: my ($link,$un,$do)=@_;
3565: return
1.896 amueller 3566: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3567: }
1.802 bisitz 3568:
1.62 www 3569: # ------------------------------------------------------------- Aboutme Wrapper
3570:
3571: sub aboutmewrapper {
1.1070 raeburn 3572: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3573: if (!defined($username) && !defined($domain)) {
3574: return;
3575: }
1.1075.2.15 raeburn 3576: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3577: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3578: }
3579:
3580: # ------------------------------------------------------------ Syllabus Wrapper
3581:
3582: sub syllabuswrapper {
1.707 bisitz 3583: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3584: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3585: }
1.14 harris41 3586:
1.802 bisitz 3587: # -----------------------------------------------------------------------------
3588:
1.208 matthew 3589: sub track_student_link {
1.887 raeburn 3590: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3591: my $link ="/adm/trackstudent?";
1.208 matthew 3592: my $title = 'View recent activity';
3593: if (defined($sname) && $sname !~ /^\s*$/ &&
3594: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3595: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3596: $title .= ' of this student';
1.268 albertel 3597: }
1.208 matthew 3598: if (defined($target) && $target !~ /^\s*$/) {
3599: $target = qq{target="$target"};
3600: } else {
3601: $target = '';
3602: }
1.268 albertel 3603: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3604: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3605: $title = &mt($title);
3606: $linktext = &mt($linktext);
1.448 albertel 3607: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3608: &help_open_topic('View_recent_activity');
1.208 matthew 3609: }
3610:
1.781 raeburn 3611: sub slot_reservations_link {
3612: my ($linktext,$sname,$sdom,$target) = @_;
3613: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3614: my $title = 'View slot reservation history';
3615: if (defined($sname) && $sname !~ /^\s*$/ &&
3616: defined($sdom) && $sdom !~ /^\s*$/) {
3617: $link .= "&uname=$sname&udom=$sdom";
3618: $title .= ' of this student';
3619: }
3620: if (defined($target) && $target !~ /^\s*$/) {
3621: $target = qq{target="$target"};
3622: } else {
3623: $target = '';
3624: }
3625: $title = &mt($title);
3626: $linktext = &mt($linktext);
3627: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3628: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3629:
3630: }
3631:
1.508 www 3632: # ===================================================== Display a student photo
3633:
3634:
1.509 albertel 3635: sub student_image_tag {
1.508 www 3636: my ($domain,$user)=@_;
3637: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3638: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3639: return '<img src="'.$imgsrc.'" align="right" />';
3640: } else {
3641: return '';
3642: }
3643: }
3644:
1.112 bowersj2 3645: =pod
3646:
3647: =back
3648:
3649: =head1 Access .tab File Data
3650:
3651: =over 4
3652:
1.648 raeburn 3653: =item * &languageids()
1.112 bowersj2 3654:
3655: returns list of all language ids
3656:
3657: =cut
3658:
1.14 harris41 3659: sub languageids {
1.16 harris41 3660: return sort(keys(%language));
1.14 harris41 3661: }
3662:
1.112 bowersj2 3663: =pod
3664:
1.648 raeburn 3665: =item * &languagedescription()
1.112 bowersj2 3666:
3667: returns description of a specified language id
3668:
3669: =cut
3670:
1.14 harris41 3671: sub languagedescription {
1.125 www 3672: my $code=shift;
3673: return ($supported_language{$code}?'* ':'').
3674: $language{$code}.
1.126 www 3675: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3676: }
3677:
1.1048 foxr 3678: =pod
3679:
3680: =item * &plainlanguagedescription
3681:
3682: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3683: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3684:
3685: =cut
3686:
1.145 www 3687: sub plainlanguagedescription {
3688: my $code=shift;
3689: return $language{$code};
3690: }
3691:
1.1048 foxr 3692: =pod
3693:
3694: =item * &supportedlanguagecode
3695:
3696: Returns the supported language code (e.g. sptutf maps to pt) given a language
3697: code.
3698:
3699: =cut
3700:
1.145 www 3701: sub supportedlanguagecode {
3702: my $code=shift;
3703: return $supported_language{$code};
1.97 www 3704: }
3705:
1.112 bowersj2 3706: =pod
3707:
1.1048 foxr 3708: =item * &latexlanguage()
3709:
3710: Given a language key code returns the correspondnig language to use
3711: to select the correct hyphenation on LaTeX printouts. This is undef if there
3712: is no supported hyphenation for the language code.
3713:
3714: =cut
3715:
3716: sub latexlanguage {
3717: my $code = shift;
3718: return $latex_language{$code};
3719: }
3720:
3721: =pod
3722:
3723: =item * &latexhyphenation()
3724:
3725: Same as above but what's supplied is the language as it might be stored
3726: in the metadata.
3727:
3728: =cut
3729:
3730: sub latexhyphenation {
3731: my $key = shift;
3732: return $latex_language_bykey{$key};
3733: }
3734:
3735: =pod
3736:
1.648 raeburn 3737: =item * ©rightids()
1.112 bowersj2 3738:
3739: returns list of all copyrights
3740:
3741: =cut
3742:
3743: sub copyrightids {
3744: return sort(keys(%cprtag));
3745: }
3746:
3747: =pod
3748:
1.648 raeburn 3749: =item * ©rightdescription()
1.112 bowersj2 3750:
3751: returns description of a specified copyright id
3752:
3753: =cut
3754:
3755: sub copyrightdescription {
1.166 www 3756: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3757: }
1.197 matthew 3758:
3759: =pod
3760:
1.648 raeburn 3761: =item * &source_copyrightids()
1.192 taceyjo1 3762:
3763: returns list of all source copyrights
3764:
3765: =cut
3766:
3767: sub source_copyrightids {
3768: return sort(keys(%scprtag));
3769: }
3770:
3771: =pod
3772:
1.648 raeburn 3773: =item * &source_copyrightdescription()
1.192 taceyjo1 3774:
3775: returns description of a specified source copyright id
3776:
3777: =cut
3778:
3779: sub source_copyrightdescription {
3780: return &mt($scprtag{shift(@_)});
3781: }
1.112 bowersj2 3782:
3783: =pod
3784:
1.648 raeburn 3785: =item * &filecategories()
1.112 bowersj2 3786:
3787: returns list of all file categories
3788:
3789: =cut
3790:
3791: sub filecategories {
3792: return sort(keys(%category_extensions));
3793: }
3794:
3795: =pod
3796:
1.648 raeburn 3797: =item * &filecategorytypes()
1.112 bowersj2 3798:
3799: returns list of file types belonging to a given file
3800: category
3801:
3802: =cut
3803:
3804: sub filecategorytypes {
1.356 albertel 3805: my ($cat) = @_;
3806: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3807: }
3808:
3809: =pod
3810:
1.648 raeburn 3811: =item * &fileembstyle()
1.112 bowersj2 3812:
3813: returns embedding style for a specified file type
3814:
3815: =cut
3816:
3817: sub fileembstyle {
3818: return $fe{lc(shift(@_))};
1.169 www 3819: }
3820:
1.351 www 3821: sub filemimetype {
3822: return $fm{lc(shift(@_))};
3823: }
3824:
1.169 www 3825:
3826: sub filecategoryselect {
3827: my ($name,$value)=@_;
1.189 matthew 3828: return &select_form($value,$name,
1.970 raeburn 3829: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3830: }
3831:
3832: =pod
3833:
1.648 raeburn 3834: =item * &filedescription()
1.112 bowersj2 3835:
3836: returns description for a specified file type
3837:
3838: =cut
3839:
3840: sub filedescription {
1.188 matthew 3841: my $file_description = $fd{lc(shift())};
3842: $file_description =~ s:([\[\]]):~$1:g;
3843: return &mt($file_description);
1.112 bowersj2 3844: }
3845:
3846: =pod
3847:
1.648 raeburn 3848: =item * &filedescriptionex()
1.112 bowersj2 3849:
3850: returns description for a specified file type with
3851: extra formatting
3852:
3853: =cut
3854:
3855: sub filedescriptionex {
3856: my $ex=shift;
1.188 matthew 3857: my $file_description = $fd{lc($ex)};
3858: $file_description =~ s:([\[\]]):~$1:g;
3859: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3860: }
3861:
3862: # End of .tab access
3863: =pod
3864:
3865: =back
3866:
3867: =cut
3868:
3869: # ------------------------------------------------------------------ File Types
3870: sub fileextensions {
3871: return sort(keys(%fe));
3872: }
3873:
1.97 www 3874: # ----------------------------------------------------------- Display Languages
3875: # returns a hash with all desired display languages
3876: #
3877:
3878: sub display_languages {
3879: my %languages=();
1.695 raeburn 3880: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3881: $languages{$lang}=1;
1.97 www 3882: }
3883: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3884: if ($env{'form.displaylanguage'}) {
1.356 albertel 3885: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3886: $languages{$lang}=1;
1.97 www 3887: }
3888: }
3889: return %languages;
1.14 harris41 3890: }
3891:
1.582 albertel 3892: sub languages {
3893: my ($possible_langs) = @_;
1.695 raeburn 3894: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3895: if (!ref($possible_langs)) {
3896: if( wantarray ) {
3897: return @preferred_langs;
3898: } else {
3899: return $preferred_langs[0];
3900: }
3901: }
3902: my %possibilities = map { $_ => 1 } (@$possible_langs);
3903: my @preferred_possibilities;
3904: foreach my $preferred_lang (@preferred_langs) {
3905: if (exists($possibilities{$preferred_lang})) {
3906: push(@preferred_possibilities, $preferred_lang);
3907: }
3908: }
3909: if( wantarray ) {
3910: return @preferred_possibilities;
3911: }
3912: return $preferred_possibilities[0];
3913: }
3914:
1.742 raeburn 3915: sub user_lang {
3916: my ($touname,$toudom,$fromcid) = @_;
3917: my @userlangs;
3918: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3919: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3920: $env{'course.'.$fromcid.'.languages'}));
3921: } else {
3922: my %langhash = &getlangs($touname,$toudom);
3923: if ($langhash{'languages'} ne '') {
3924: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3925: } else {
3926: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3927: if ($domdefs{'lang_def'} ne '') {
3928: @userlangs = ($domdefs{'lang_def'});
3929: }
3930: }
3931: }
3932: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3933: my $user_lh = Apache::localize->get_handle(@languages);
3934: return $user_lh;
3935: }
3936:
3937:
1.112 bowersj2 3938: ###############################################################
3939: ## Student Answer Attempts ##
3940: ###############################################################
3941:
3942: =pod
3943:
3944: =head1 Alternate Problem Views
3945:
3946: =over 4
3947:
1.648 raeburn 3948: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 3949: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 3950:
3951: Return string with previous attempt on problem. Arguments:
3952:
3953: =over 4
3954:
3955: =item * $symb: Problem, including path
3956:
3957: =item * $username: username of the desired student
3958:
3959: =item * $domain: domain of the desired student
1.14 harris41 3960:
1.112 bowersj2 3961: =item * $course: Course ID
1.14 harris41 3962:
1.112 bowersj2 3963: =item * $getattempt: Leave blank for all attempts, otherwise put
3964: something
1.14 harris41 3965:
1.112 bowersj2 3966: =item * $regexp: if string matches this regexp, the string will be
3967: sent to $gradesub
1.14 harris41 3968:
1.112 bowersj2 3969: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3970:
1.1075.2.86 raeburn 3971: =item * $usec: section of the desired student
3972:
3973: =item * $identifier: counter for student (multiple students one problem) or
3974: problem (one student; whole sequence).
3975:
1.112 bowersj2 3976: =back
1.14 harris41 3977:
1.112 bowersj2 3978: The output string is a table containing all desired attempts, if any.
1.16 harris41 3979:
1.112 bowersj2 3980: =cut
1.1 albertel 3981:
3982: sub get_previous_attempt {
1.1075.2.86 raeburn 3983: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 3984: my $prevattempts='';
1.43 ng 3985: no strict 'refs';
1.1 albertel 3986: if ($symb) {
1.3 albertel 3987: my (%returnhash)=
3988: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3989: if ($returnhash{'version'}) {
3990: my %lasthash=();
3991: my $version;
3992: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 3993: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
3994: if ($key =~ /\.rawrndseed$/) {
3995: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
3996: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
3997: } else {
3998: $lasthash{$key}=$returnhash{$version.':'.$key};
3999: }
1.19 harris41 4000: }
1.1 albertel 4001: }
1.596 albertel 4002: $prevattempts=&start_data_table().&start_data_table_header_row();
4003: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4004: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4005: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4006: foreach my $key (sort(keys(%lasthash))) {
4007: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4008: if ($#parts > 0) {
1.31 albertel 4009: my $data=$parts[-1];
1.989 raeburn 4010: next if ($data eq 'foilorder');
1.31 albertel 4011: pop(@parts);
1.1010 www 4012: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4013: if ($data eq 'type') {
4014: unless ($showsurv) {
4015: my $id = join(',',@parts);
4016: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4017: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4018: $lasthidden{$ign.'.'.$id} = 1;
4019: }
1.945 raeburn 4020: }
1.1075.2.86 raeburn 4021: if ($identifier ne '') {
4022: my $id = join(',',@parts);
4023: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4024: $domain,$username,$usec,undef,$course) =~ /^no/) {
4025: $hidestatus{$ign.'.'.$id} = 1;
4026: }
4027: }
4028: } elsif ($data eq 'regrader') {
4029: if (($identifier ne '') && (@parts)) {
4030: my $id = join(',',@parts);
4031: $regraded{$ign.'.'.$id} = 1;
4032: }
1.1010 www 4033: }
1.31 albertel 4034: } else {
1.41 ng 4035: if ($#parts == 0) {
4036: $prevattempts.='<th>'.$parts[0].'</th>';
4037: } else {
4038: $prevattempts.='<th>'.$ign.'</th>';
4039: }
1.31 albertel 4040: }
1.16 harris41 4041: }
1.596 albertel 4042: $prevattempts.=&end_data_table_header_row();
1.40 ng 4043: if ($getattempt eq '') {
1.1075.2.86 raeburn 4044: my (%solved,%resets,%probstatus);
4045: if (($identifier ne '') && (keys(%regraded) > 0)) {
4046: for ($version=1;$version<=$returnhash{'version'};$version++) {
4047: foreach my $id (keys(%regraded)) {
4048: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4049: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4050: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4051: push(@{$resets{$id}},$version);
4052: }
4053: }
4054: }
4055: }
1.40 ng 4056: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4057: my (@hidden,@unsolved);
1.945 raeburn 4058: if (%typeparts) {
4059: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4060: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4061: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4062: push(@hidden,$id);
1.1075.2.86 raeburn 4063: } elsif ($identifier ne '') {
4064: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4065: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4066: ($hidestatus{$id})) {
4067: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4068: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4069: push(@{$solved{$id}},$version);
4070: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4071: (ref($solved{$id}) eq 'ARRAY')) {
4072: my $skip;
4073: if (ref($resets{$id}) eq 'ARRAY') {
4074: foreach my $reset (@{$resets{$id}}) {
4075: if ($reset > $solved{$id}[-1]) {
4076: $skip=1;
4077: last;
4078: }
4079: }
4080: }
4081: unless ($skip) {
4082: my ($ign,$partslist) = split(/\./,$id,2);
4083: push(@unsolved,$partslist);
4084: }
4085: }
4086: }
1.945 raeburn 4087: }
4088: }
4089: }
4090: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4091: '<td>'.&mt('Transaction [_1]',$version);
4092: if (@unsolved) {
4093: $prevattempts .= '<span class="LC_nobreak"><label>'.
4094: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4095: &mt('Hide').'</label></span>';
4096: }
4097: $prevattempts .= '</td>';
1.945 raeburn 4098: if (@hidden) {
4099: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4100: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4101: my $hide;
4102: foreach my $id (@hidden) {
4103: if ($key =~ /^\Q$id\E/) {
4104: $hide = 1;
4105: last;
4106: }
4107: }
4108: if ($hide) {
4109: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4110: if (($data eq 'award') || ($data eq 'awarddetail')) {
4111: my $value = &format_previous_attempt_value($key,
4112: $returnhash{$version.':'.$key});
4113: $prevattempts.='<td>'.$value.' </td>';
4114: } else {
4115: $prevattempts.='<td> </td>';
4116: }
4117: } else {
4118: if ($key =~ /\./) {
1.1075.2.91 raeburn 4119: my $value = $returnhash{$version.':'.$key};
4120: if ($key =~ /\.rndseed$/) {
4121: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4122: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4123: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4124: }
4125: }
4126: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4127: ' </td>';
1.945 raeburn 4128: } else {
4129: $prevattempts.='<td> </td>';
4130: }
4131: }
4132: }
4133: } else {
4134: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4135: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4136: my $value = $returnhash{$version.':'.$key};
4137: if ($key =~ /\.rndseed$/) {
4138: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4139: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4140: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4141: }
4142: }
4143: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4144: ' </td>';
1.945 raeburn 4145: }
4146: }
4147: $prevattempts.=&end_data_table_row();
1.40 ng 4148: }
1.1 albertel 4149: }
1.945 raeburn 4150: my @currhidden = keys(%lasthidden);
1.596 albertel 4151: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4152: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4153: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4154: if (%typeparts) {
4155: my $hidden;
4156: foreach my $id (@currhidden) {
4157: if ($key =~ /^\Q$id\E/) {
4158: $hidden = 1;
4159: last;
4160: }
4161: }
4162: if ($hidden) {
4163: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4164: if (($data eq 'award') || ($data eq 'awarddetail')) {
4165: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4166: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4167: $value = &$gradesub($value);
4168: }
4169: $prevattempts.='<td>'.$value.' </td>';
4170: } else {
4171: $prevattempts.='<td> </td>';
4172: }
4173: } else {
4174: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4175: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4176: $value = &$gradesub($value);
4177: }
4178: $prevattempts.='<td>'.$value.' </td>';
4179: }
4180: } else {
4181: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4182: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4183: $value = &$gradesub($value);
4184: }
4185: $prevattempts.='<td>'.$value.' </td>';
4186: }
1.16 harris41 4187: }
1.596 albertel 4188: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4189: } else {
1.596 albertel 4190: $prevattempts=
4191: &start_data_table().&start_data_table_row().
4192: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4193: &end_data_table_row().&end_data_table();
1.1 albertel 4194: }
4195: } else {
1.596 albertel 4196: $prevattempts=
4197: &start_data_table().&start_data_table_row().
4198: '<td>'.&mt('No data.').'</td>'.
4199: &end_data_table_row().&end_data_table();
1.1 albertel 4200: }
1.10 albertel 4201: }
4202:
1.581 albertel 4203: sub format_previous_attempt_value {
4204: my ($key,$value) = @_;
1.1011 www 4205: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4206: $value = &Apache::lonlocal::locallocaltime($value);
4207: } elsif (ref($value) eq 'ARRAY') {
4208: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4209: } elsif ($key =~ /answerstring$/) {
4210: my %answers = &Apache::lonnet::str2hash($value);
4211: my @anskeys = sort(keys(%answers));
4212: if (@anskeys == 1) {
4213: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4214: if ($answer =~ m{\0}) {
4215: $answer =~ s{\0}{,}g;
1.988 raeburn 4216: }
4217: my $tag_internal_answer_name = 'INTERNAL';
4218: if ($anskeys[0] eq $tag_internal_answer_name) {
4219: $value = $answer;
4220: } else {
4221: $value = $anskeys[0].'='.$answer;
4222: }
4223: } else {
4224: foreach my $ans (@anskeys) {
4225: my $answer = $answers{$ans};
1.1001 raeburn 4226: if ($answer =~ m{\0}) {
4227: $answer =~ s{\0}{,}g;
1.988 raeburn 4228: }
4229: $value .= $ans.'='.$answer.'<br />';;
4230: }
4231: }
1.581 albertel 4232: } else {
4233: $value = &unescape($value);
4234: }
4235: return $value;
4236: }
4237:
4238:
1.107 albertel 4239: sub relative_to_absolute {
4240: my ($url,$output)=@_;
4241: my $parser=HTML::TokeParser->new(\$output);
4242: my $token;
4243: my $thisdir=$url;
4244: my @rlinks=();
4245: while ($token=$parser->get_token) {
4246: if ($token->[0] eq 'S') {
4247: if ($token->[1] eq 'a') {
4248: if ($token->[2]->{'href'}) {
4249: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4250: }
4251: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4252: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4253: } elsif ($token->[1] eq 'base') {
4254: $thisdir=$token->[2]->{'href'};
4255: }
4256: }
4257: }
4258: $thisdir=~s-/[^/]*$--;
1.356 albertel 4259: foreach my $link (@rlinks) {
1.726 raeburn 4260: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4261: ($link=~/^\//) ||
4262: ($link=~/^javascript:/i) ||
4263: ($link=~/^mailto:/i) ||
4264: ($link=~/^\#/)) {
4265: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4266: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4267: }
4268: }
4269: # -------------------------------------------------- Deal with Applet codebases
4270: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4271: return $output;
4272: }
4273:
1.112 bowersj2 4274: =pod
4275:
1.648 raeburn 4276: =item * &get_student_view()
1.112 bowersj2 4277:
4278: show a snapshot of what student was looking at
4279:
4280: =cut
4281:
1.10 albertel 4282: sub get_student_view {
1.186 albertel 4283: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4284: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4285: my (%form);
1.10 albertel 4286: my @elements=('symb','courseid','domain','username');
4287: foreach my $element (@elements) {
1.186 albertel 4288: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4289: }
1.186 albertel 4290: if (defined($moreenv)) {
4291: %form=(%form,%{$moreenv});
4292: }
1.236 albertel 4293: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4294: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4295: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4296: $userview=~s/\<body[^\>]*\>//gi;
4297: $userview=~s/\<\/body\>//gi;
4298: $userview=~s/\<html\>//gi;
4299: $userview=~s/\<\/html\>//gi;
4300: $userview=~s/\<head\>//gi;
4301: $userview=~s/\<\/head\>//gi;
4302: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4303: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4304: if (wantarray) {
4305: return ($userview,$response);
4306: } else {
4307: return $userview;
4308: }
4309: }
4310:
4311: sub get_student_view_with_retries {
4312: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4313:
4314: my $ok = 0; # True if we got a good response.
4315: my $content;
4316: my $response;
4317:
4318: # Try to get the student_view done. within the retries count:
4319:
4320: do {
4321: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4322: $ok = $response->is_success;
4323: if (!$ok) {
4324: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4325: }
4326: $retries--;
4327: } while (!$ok && ($retries > 0));
4328:
4329: if (!$ok) {
4330: $content = ''; # On error return an empty content.
4331: }
1.651 www 4332: if (wantarray) {
4333: return ($content, $response);
4334: } else {
4335: return $content;
4336: }
1.11 albertel 4337: }
4338:
1.112 bowersj2 4339: =pod
4340:
1.648 raeburn 4341: =item * &get_student_answers()
1.112 bowersj2 4342:
4343: show a snapshot of how student was answering problem
4344:
4345: =cut
4346:
1.11 albertel 4347: sub get_student_answers {
1.100 sakharuk 4348: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4349: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4350: my (%moreenv);
1.11 albertel 4351: my @elements=('symb','courseid','domain','username');
4352: foreach my $element (@elements) {
1.186 albertel 4353: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4354: }
1.186 albertel 4355: $moreenv{'grade_target'}='answer';
4356: %moreenv=(%form,%moreenv);
1.497 raeburn 4357: $feedurl = &Apache::lonnet::clutter($feedurl);
4358: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4359: return $userview;
1.1 albertel 4360: }
1.116 albertel 4361:
4362: =pod
4363:
4364: =item * &submlink()
4365:
1.242 albertel 4366: Inputs: $text $uname $udom $symb $target
1.116 albertel 4367:
4368: Returns: A link to grades.pm such as to see the SUBM view of a student
4369:
4370: =cut
4371:
4372: ###############################################
4373: sub submlink {
1.242 albertel 4374: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4375: if (!($uname && $udom)) {
4376: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4377: &Apache::lonnet::whichuser($symb);
1.116 albertel 4378: if (!$symb) { $symb=$cursymb; }
4379: }
1.254 matthew 4380: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4381: $symb=&escape($symb);
1.960 bisitz 4382: if ($target) { $target=" target=\"$target\""; }
4383: return
4384: '<a href="/adm/grades?command=submission'.
4385: '&symb='.$symb.
4386: '&student='.$uname.
4387: '&userdom='.$udom.'"'.
4388: $target.'>'.$text.'</a>';
1.242 albertel 4389: }
4390: ##############################################
4391:
4392: =pod
4393:
4394: =item * &pgrdlink()
4395:
4396: Inputs: $text $uname $udom $symb $target
4397:
4398: Returns: A link to grades.pm such as to see the PGRD view of a student
4399:
4400: =cut
4401:
4402: ###############################################
4403: sub pgrdlink {
4404: my $link=&submlink(@_);
4405: $link=~s/(&command=submission)/$1&showgrading=yes/;
4406: return $link;
4407: }
4408: ##############################################
4409:
4410: =pod
4411:
4412: =item * &pprmlink()
4413:
4414: Inputs: $text $uname $udom $symb $target
4415:
4416: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4417: student and a specific resource
1.242 albertel 4418:
4419: =cut
4420:
4421: ###############################################
4422: sub pprmlink {
4423: my ($text,$uname,$udom,$symb,$target)=@_;
4424: if (!($uname && $udom)) {
4425: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4426: &Apache::lonnet::whichuser($symb);
1.242 albertel 4427: if (!$symb) { $symb=$cursymb; }
4428: }
1.254 matthew 4429: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4430: $symb=&escape($symb);
1.242 albertel 4431: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4432: return '<a href="/adm/parmset?command=set&'.
4433: 'symb='.$symb.'&uname='.$uname.
4434: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4435: }
4436: ##############################################
1.37 matthew 4437:
1.112 bowersj2 4438: =pod
4439:
4440: =back
4441:
4442: =cut
4443:
1.37 matthew 4444: ###############################################
1.51 www 4445:
4446:
4447: sub timehash {
1.687 raeburn 4448: my ($thistime) = @_;
4449: my $timezone = &Apache::lonlocal::gettimezone();
4450: my $dt = DateTime->from_epoch(epoch => $thistime)
4451: ->set_time_zone($timezone);
4452: my $wday = $dt->day_of_week();
4453: if ($wday == 7) { $wday = 0; }
4454: return ( 'second' => $dt->second(),
4455: 'minute' => $dt->minute(),
4456: 'hour' => $dt->hour(),
4457: 'day' => $dt->day_of_month(),
4458: 'month' => $dt->month(),
4459: 'year' => $dt->year(),
4460: 'weekday' => $wday,
4461: 'dayyear' => $dt->day_of_year(),
4462: 'dlsav' => $dt->is_dst() );
1.51 www 4463: }
4464:
1.370 www 4465: sub utc_string {
4466: my ($date)=@_;
1.371 www 4467: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4468: }
4469:
1.51 www 4470: sub maketime {
4471: my %th=@_;
1.687 raeburn 4472: my ($epoch_time,$timezone,$dt);
4473: $timezone = &Apache::lonlocal::gettimezone();
4474: eval {
4475: $dt = DateTime->new( year => $th{'year'},
4476: month => $th{'month'},
4477: day => $th{'day'},
4478: hour => $th{'hour'},
4479: minute => $th{'minute'},
4480: second => $th{'second'},
4481: time_zone => $timezone,
4482: );
4483: };
4484: if (!$@) {
4485: $epoch_time = $dt->epoch;
4486: if ($epoch_time) {
4487: return $epoch_time;
4488: }
4489: }
1.51 www 4490: return POSIX::mktime(
4491: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4492: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4493: }
4494:
4495: #########################################
1.51 www 4496:
4497: sub findallcourses {
1.482 raeburn 4498: my ($roles,$uname,$udom) = @_;
1.355 albertel 4499: my %roles;
4500: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4501: my %courses;
1.51 www 4502: my $now=time;
1.482 raeburn 4503: if (!defined($uname)) {
4504: $uname = $env{'user.name'};
4505: }
4506: if (!defined($udom)) {
4507: $udom = $env{'user.domain'};
4508: }
4509: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4510: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4511: if (!%roles) {
4512: %roles = (
4513: cc => 1,
1.907 raeburn 4514: co => 1,
1.482 raeburn 4515: in => 1,
4516: ep => 1,
4517: ta => 1,
4518: cr => 1,
4519: st => 1,
4520: );
4521: }
4522: foreach my $entry (keys(%roleshash)) {
4523: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4524: if ($trole =~ /^cr/) {
4525: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4526: } else {
4527: next if (!exists($roles{$trole}));
4528: }
4529: if ($tend) {
4530: next if ($tend < $now);
4531: }
4532: if ($tstart) {
4533: next if ($tstart > $now);
4534: }
1.1058 raeburn 4535: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4536: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4537: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4538: if ($secpart eq '') {
4539: ($cnum,$role) = split(/_/,$cnumpart);
4540: $sec = 'none';
1.1058 raeburn 4541: $value .= $cnum.'/';
1.482 raeburn 4542: } else {
4543: $cnum = $cnumpart;
4544: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4545: $value .= $cnum.'/'.$sec;
4546: }
4547: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4548: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4549: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4550: }
4551: } else {
4552: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4553: }
1.482 raeburn 4554: }
4555: } else {
4556: foreach my $key (keys(%env)) {
1.483 albertel 4557: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4558: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4559: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4560: next if ($role eq 'ca' || $role eq 'aa');
4561: next if (%roles && !exists($roles{$role}));
4562: my ($starttime,$endtime)=split(/\./,$env{$key});
4563: my $active=1;
4564: if ($starttime) {
4565: if ($now<$starttime) { $active=0; }
4566: }
4567: if ($endtime) {
4568: if ($now>$endtime) { $active=0; }
4569: }
4570: if ($active) {
1.1058 raeburn 4571: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4572: if ($sec eq '') {
4573: $sec = 'none';
1.1058 raeburn 4574: } else {
4575: $value .= $sec;
4576: }
4577: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4578: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4579: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4580: }
4581: } else {
4582: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4583: }
1.474 raeburn 4584: }
4585: }
1.51 www 4586: }
4587: }
1.474 raeburn 4588: return %courses;
1.51 www 4589: }
1.37 matthew 4590:
1.54 www 4591: ###############################################
1.474 raeburn 4592:
4593: sub blockcheck {
1.1075.2.73 raeburn 4594: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4595:
1.1075.2.73 raeburn 4596: if (defined($udom) && defined($uname)) {
4597: # If uname and udom are for a course, check for blocks in the course.
4598: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4599: my ($startblock,$endblock,$triggerblock) =
4600: &get_blocks($setters,$activity,$udom,$uname,$url);
4601: return ($startblock,$endblock,$triggerblock);
4602: }
4603: } else {
1.490 raeburn 4604: $udom = $env{'user.domain'};
4605: $uname = $env{'user.name'};
4606: }
4607:
1.502 raeburn 4608: my $startblock = 0;
4609: my $endblock = 0;
1.1062 raeburn 4610: my $triggerblock = '';
1.482 raeburn 4611: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4612:
1.490 raeburn 4613: # If uname is for a user, and activity is course-specific, i.e.,
4614: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4615:
1.490 raeburn 4616: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4617: $activity eq 'groups' || $activity eq 'printout') &&
4618: ($env{'request.course.id'})) {
1.490 raeburn 4619: foreach my $key (keys(%live_courses)) {
4620: if ($key ne $env{'request.course.id'}) {
4621: delete($live_courses{$key});
4622: }
4623: }
4624: }
4625:
4626: my $otheruser = 0;
4627: my %own_courses;
4628: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4629: # Resource belongs to user other than current user.
4630: $otheruser = 1;
4631: # Gather courses for current user
4632: %own_courses =
4633: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4634: }
4635:
4636: # Gather active course roles - course coordinator, instructor,
4637: # exam proctor, ta, student, or custom role.
1.474 raeburn 4638:
4639: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4640: my ($cdom,$cnum);
4641: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4642: $cdom = $env{'course.'.$course.'.domain'};
4643: $cnum = $env{'course.'.$course.'.num'};
4644: } else {
1.490 raeburn 4645: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4646: }
4647: my $no_ownblock = 0;
4648: my $no_userblock = 0;
1.533 raeburn 4649: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4650: # Check if current user has 'evb' priv for this
4651: if (defined($own_courses{$course})) {
4652: foreach my $sec (keys(%{$own_courses{$course}})) {
4653: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4654: if ($sec ne 'none') {
4655: $checkrole .= '/'.$sec;
4656: }
4657: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4658: $no_ownblock = 1;
4659: last;
4660: }
4661: }
4662: }
4663: # if they have 'evb' priv and are currently not playing student
4664: next if (($no_ownblock) &&
4665: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4666: }
1.474 raeburn 4667: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4668: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4669: if ($sec ne 'none') {
1.482 raeburn 4670: $checkrole .= '/'.$sec;
1.474 raeburn 4671: }
1.490 raeburn 4672: if ($otheruser) {
4673: # Resource belongs to user other than current user.
4674: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4675: my (%allroles,%userroles);
4676: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4677: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4678: my ($trole,$tdom,$tnum,$tsec);
4679: if ($entry =~ /^cr/) {
4680: ($trole,$tdom,$tnum,$tsec) =
4681: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4682: } else {
4683: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4684: }
4685: my ($spec,$area,$trest);
4686: $area = '/'.$tdom.'/'.$tnum;
4687: $trest = $tnum;
4688: if ($tsec ne '') {
4689: $area .= '/'.$tsec;
4690: $trest .= '/'.$tsec;
4691: }
4692: $spec = $trole.'.'.$area;
4693: if ($trole =~ /^cr/) {
4694: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4695: $tdom,$spec,$trest,$area);
4696: } else {
4697: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4698: $tdom,$spec,$trest,$area);
4699: }
4700: }
1.1075.2.124 raeburn 4701: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 4702: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4703: if ($1) {
4704: $no_userblock = 1;
4705: last;
4706: }
1.486 raeburn 4707: }
4708: }
1.490 raeburn 4709: } else {
4710: # Resource belongs to current user
4711: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4712: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4713: $no_ownblock = 1;
4714: last;
4715: }
1.474 raeburn 4716: }
4717: }
4718: # if they have the evb priv and are currently not playing student
1.482 raeburn 4719: next if (($no_ownblock) &&
1.491 albertel 4720: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4721: next if ($no_userblock);
1.474 raeburn 4722:
1.1075.2.128! raeburn 4723: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 4724: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4725:
1.1062 raeburn 4726: my ($start,$end,$trigger) =
4727: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4728: if (($start != 0) &&
4729: (($startblock == 0) || ($startblock > $start))) {
4730: $startblock = $start;
1.1062 raeburn 4731: if ($trigger ne '') {
4732: $triggerblock = $trigger;
4733: }
1.502 raeburn 4734: }
4735: if (($end != 0) &&
4736: (($endblock == 0) || ($endblock < $end))) {
4737: $endblock = $end;
1.1062 raeburn 4738: if ($trigger ne '') {
4739: $triggerblock = $trigger;
4740: }
1.502 raeburn 4741: }
1.490 raeburn 4742: }
1.1062 raeburn 4743: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4744: }
4745:
4746: sub get_blocks {
1.1062 raeburn 4747: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4748: my $startblock = 0;
4749: my $endblock = 0;
1.1062 raeburn 4750: my $triggerblock = '';
1.490 raeburn 4751: my $course = $cdom.'_'.$cnum;
4752: $setters->{$course} = {};
4753: $setters->{$course}{'staff'} = [];
4754: $setters->{$course}{'times'} = [];
1.1062 raeburn 4755: $setters->{$course}{'triggers'} = [];
4756: my (@blockers,%triggered);
4757: my $now = time;
4758: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4759: if ($activity eq 'docs') {
4760: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4761: foreach my $block (@blockers) {
4762: if ($block =~ /^firstaccess____(.+)$/) {
4763: my $item = $1;
4764: my $type = 'map';
4765: my $timersymb = $item;
4766: if ($item eq 'course') {
4767: $type = 'course';
4768: } elsif ($item =~ /___\d+___/) {
4769: $type = 'resource';
4770: } else {
4771: $timersymb = &Apache::lonnet::symbread($item);
4772: }
4773: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4774: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4775: $triggered{$block} = {
4776: start => $start,
4777: end => $end,
4778: type => $type,
4779: };
4780: }
4781: }
4782: } else {
4783: foreach my $block (keys(%commblocks)) {
4784: if ($block =~ m/^(\d+)____(\d+)$/) {
4785: my ($start,$end) = ($1,$2);
4786: if ($start <= time && $end >= time) {
4787: if (ref($commblocks{$block}) eq 'HASH') {
4788: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4789: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4790: unless(grep(/^\Q$block\E$/,@blockers)) {
4791: push(@blockers,$block);
4792: }
4793: }
4794: }
4795: }
4796: }
4797: } elsif ($block =~ /^firstaccess____(.+)$/) {
4798: my $item = $1;
4799: my $timersymb = $item;
4800: my $type = 'map';
4801: if ($item eq 'course') {
4802: $type = 'course';
4803: } elsif ($item =~ /___\d+___/) {
4804: $type = 'resource';
4805: } else {
4806: $timersymb = &Apache::lonnet::symbread($item);
4807: }
4808: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4809: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4810: if ($start && $end) {
4811: if (($start <= time) && ($end >= time)) {
4812: unless (grep(/^\Q$block\E$/,@blockers)) {
4813: push(@blockers,$block);
4814: $triggered{$block} = {
4815: start => $start,
4816: end => $end,
4817: type => $type,
4818: };
4819: }
4820: }
1.490 raeburn 4821: }
1.1062 raeburn 4822: }
4823: }
4824: }
4825: foreach my $blocker (@blockers) {
4826: my ($staff_name,$staff_dom,$title,$blocks) =
4827: &parse_block_record($commblocks{$blocker});
4828: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4829: my ($start,$end,$triggertype);
4830: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4831: ($start,$end) = ($1,$2);
4832: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4833: $start = $triggered{$blocker}{'start'};
4834: $end = $triggered{$blocker}{'end'};
4835: $triggertype = $triggered{$blocker}{'type'};
4836: }
4837: if ($start) {
4838: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4839: if ($triggertype) {
4840: push(@{$$setters{$course}{'triggers'}},$triggertype);
4841: } else {
4842: push(@{$$setters{$course}{'triggers'}},0);
4843: }
4844: if ( ($startblock == 0) || ($startblock > $start) ) {
4845: $startblock = $start;
4846: if ($triggertype) {
4847: $triggerblock = $blocker;
1.474 raeburn 4848: }
4849: }
1.1062 raeburn 4850: if ( ($endblock == 0) || ($endblock < $end) ) {
4851: $endblock = $end;
4852: if ($triggertype) {
4853: $triggerblock = $blocker;
4854: }
4855: }
1.474 raeburn 4856: }
4857: }
1.1062 raeburn 4858: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4859: }
4860:
4861: sub parse_block_record {
4862: my ($record) = @_;
4863: my ($setuname,$setudom,$title,$blocks);
4864: if (ref($record) eq 'HASH') {
4865: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4866: $title = &unescape($record->{'event'});
4867: $blocks = $record->{'blocks'};
4868: } else {
4869: my @data = split(/:/,$record,3);
4870: if (scalar(@data) eq 2) {
4871: $title = $data[1];
4872: ($setuname,$setudom) = split(/@/,$data[0]);
4873: } else {
4874: ($setuname,$setudom,$title) = @data;
4875: }
4876: $blocks = { 'com' => 'on' };
4877: }
4878: return ($setuname,$setudom,$title,$blocks);
4879: }
4880:
1.854 kalberla 4881: sub blocking_status {
1.1075.2.73 raeburn 4882: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4883: my %setters;
1.890 droeschl 4884:
1.1061 raeburn 4885: # check for active blocking
1.1062 raeburn 4886: my ($startblock,$endblock,$triggerblock) =
1.1075.2.73 raeburn 4887: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4888: my $blocked = 0;
4889: if ($startblock && $endblock) {
4890: $blocked = 1;
4891: }
1.890 droeschl 4892:
1.1061 raeburn 4893: # caller just wants to know whether a block is active
4894: if (!wantarray) { return $blocked; }
4895:
4896: # build a link to a popup window containing the details
4897: my $querystring = "?activity=$activity";
4898: # $uname and $udom decide whose portfolio the user is trying to look at
1.1075.2.97 raeburn 4899: if (($activity eq 'port') || ($activity eq 'passwd')) {
4900: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
4901: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 4902: } elsif ($activity eq 'docs') {
4903: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4904: }
1.1061 raeburn 4905:
4906: my $output .= <<'END_MYBLOCK';
4907: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4908: var options = "width=" + w + ",height=" + h + ",";
4909: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4910: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4911: var newWin = window.open(url, wdwName, options);
4912: newWin.focus();
4913: }
1.890 droeschl 4914: END_MYBLOCK
1.854 kalberla 4915:
1.1061 raeburn 4916: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4917:
1.1061 raeburn 4918: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4919: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 4920: my $class = 'LC_comblock';
1.1062 raeburn 4921: if ($activity eq 'docs') {
4922: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 4923: $class = '';
1.1063 raeburn 4924: } elsif ($activity eq 'printout') {
4925: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 4926: } elsif ($activity eq 'passwd') {
4927: $text = &mt('Password Changing Blocked');
1.1062 raeburn 4928: }
1.1061 raeburn 4929: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 4930: <div class='$class'>
1.869 kalberla 4931: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4932: title='$text'>
4933: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4934: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4935: title='$text'>$text</a>
1.867 kalberla 4936: </div>
4937:
4938: END_BLOCK
1.474 raeburn 4939:
1.1061 raeburn 4940: return ($blocked, $output);
1.854 kalberla 4941: }
1.490 raeburn 4942:
1.60 matthew 4943: ###############################################
4944:
1.682 raeburn 4945: sub check_ip_acc {
1.1075.2.105 raeburn 4946: my ($acc,$clientip)=@_;
1.682 raeburn 4947: &Apache::lonxml::debug("acc is $acc");
4948: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4949: return 1;
4950: }
4951: my $allowed=0;
1.1075.2.111 raeburn 4952: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 4953:
4954: my $name;
4955: foreach my $pattern (split(',',$acc)) {
4956: $pattern =~ s/^\s*//;
4957: $pattern =~ s/\s*$//;
4958: if ($pattern =~ /\*$/) {
4959: #35.8.*
4960: $pattern=~s/\*//;
4961: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4962: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4963: #35.8.3.[34-56]
4964: my $low=$2;
4965: my $high=$3;
4966: $pattern=$1;
4967: if ($ip =~ /^\Q$pattern\E/) {
4968: my $last=(split(/\./,$ip))[3];
4969: if ($last <=$high && $last >=$low) { $allowed=1; }
4970: }
4971: } elsif ($pattern =~ /^\*/) {
4972: #*.msu.edu
4973: $pattern=~s/\*//;
4974: if (!defined($name)) {
4975: use Socket;
4976: my $netaddr=inet_aton($ip);
4977: ($name)=gethostbyaddr($netaddr,AF_INET);
4978: }
4979: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4980: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4981: #127.0.0.1
4982: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4983: } else {
4984: #some.name.com
4985: if (!defined($name)) {
4986: use Socket;
4987: my $netaddr=inet_aton($ip);
4988: ($name)=gethostbyaddr($netaddr,AF_INET);
4989: }
4990: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4991: }
4992: if ($allowed) { last; }
4993: }
4994: return $allowed;
4995: }
4996:
4997: ###############################################
4998:
1.60 matthew 4999: =pod
5000:
1.112 bowersj2 5001: =head1 Domain Template Functions
5002:
5003: =over 4
5004:
5005: =item * &determinedomain()
1.60 matthew 5006:
5007: Inputs: $domain (usually will be undef)
5008:
1.63 www 5009: Returns: Determines which domain should be used for designs
1.60 matthew 5010:
5011: =cut
1.54 www 5012:
1.60 matthew 5013: ###############################################
1.63 www 5014: sub determinedomain {
5015: my $domain=shift;
1.531 albertel 5016: if (! $domain) {
1.60 matthew 5017: # Determine domain if we have not been given one
1.893 raeburn 5018: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5019: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5020: if ($env{'request.role.domain'}) {
5021: $domain=$env{'request.role.domain'};
1.60 matthew 5022: }
5023: }
1.63 www 5024: return $domain;
5025: }
5026: ###############################################
1.517 raeburn 5027:
1.518 albertel 5028: sub devalidate_domconfig_cache {
5029: my ($udom)=@_;
5030: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5031: }
5032:
5033: # ---------------------- Get domain configuration for a domain
5034: sub get_domainconf {
5035: my ($udom) = @_;
5036: my $cachetime=1800;
5037: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5038: if (defined($cached)) { return %{$result}; }
5039:
5040: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5041: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5042: my (%designhash,%legacy);
1.518 albertel 5043: if (keys(%domconfig) > 0) {
5044: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5045: if (keys(%{$domconfig{'login'}})) {
5046: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5047: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5048: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5049: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5050: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5051: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5052: if ($key eq 'loginvia') {
5053: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5054: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5055: $designhash{$udom.'.login.loginvia'} = $server;
5056: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5057: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5058: } else {
5059: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5060: }
1.948 raeburn 5061: }
1.1075.2.87 raeburn 5062: } elsif ($key eq 'headtag') {
5063: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5064: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5065: }
1.946 raeburn 5066: }
1.1075.2.87 raeburn 5067: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5068: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5069: }
1.946 raeburn 5070: }
5071: }
5072: }
5073: } else {
5074: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5075: $designhash{$udom.'.login.'.$key.'_'.$img} =
5076: $domconfig{'login'}{$key}{$img};
5077: }
1.699 raeburn 5078: }
5079: } else {
5080: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5081: }
1.632 raeburn 5082: }
5083: } else {
5084: $legacy{'login'} = 1;
1.518 albertel 5085: }
1.632 raeburn 5086: } else {
5087: $legacy{'login'} = 1;
1.518 albertel 5088: }
5089: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5090: if (keys(%{$domconfig{'rolecolors'}})) {
5091: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5092: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5093: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5094: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5095: }
1.518 albertel 5096: }
5097: }
1.632 raeburn 5098: } else {
5099: $legacy{'rolecolors'} = 1;
1.518 albertel 5100: }
1.632 raeburn 5101: } else {
5102: $legacy{'rolecolors'} = 1;
1.518 albertel 5103: }
1.948 raeburn 5104: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5105: if ($domconfig{'autoenroll'}{'co-owners'}) {
5106: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5107: }
5108: }
1.632 raeburn 5109: if (keys(%legacy) > 0) {
5110: my %legacyhash = &get_legacy_domconf($udom);
5111: foreach my $item (keys(%legacyhash)) {
5112: if ($item =~ /^\Q$udom\E\.login/) {
5113: if ($legacy{'login'}) {
5114: $designhash{$item} = $legacyhash{$item};
5115: }
5116: } else {
5117: if ($legacy{'rolecolors'}) {
5118: $designhash{$item} = $legacyhash{$item};
5119: }
1.518 albertel 5120: }
5121: }
5122: }
1.632 raeburn 5123: } else {
5124: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5125: }
5126: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5127: $cachetime);
5128: return %designhash;
5129: }
5130:
1.632 raeburn 5131: sub get_legacy_domconf {
5132: my ($udom) = @_;
5133: my %legacyhash;
5134: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5135: my $designfile = $designdir.'/'.$udom.'.tab';
5136: if (-e $designfile) {
1.1075.2.128! raeburn 5137: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5138: while (my $line = <$fh>) {
5139: next if ($line =~ /^\#/);
5140: chomp($line);
5141: my ($key,$val)=(split(/\=/,$line));
5142: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5143: }
5144: close($fh);
5145: }
5146: }
1.1026 raeburn 5147: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5148: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5149: }
5150: return %legacyhash;
5151: }
5152:
1.63 www 5153: =pod
5154:
1.112 bowersj2 5155: =item * &domainlogo()
1.63 www 5156:
5157: Inputs: $domain (usually will be undef)
5158:
5159: Returns: A link to a domain logo, if the domain logo exists.
5160: If the domain logo does not exist, a description of the domain.
5161:
5162: =cut
1.112 bowersj2 5163:
1.63 www 5164: ###############################################
5165: sub domainlogo {
1.517 raeburn 5166: my $domain = &determinedomain(shift);
1.518 albertel 5167: my %designhash = &get_domainconf($domain);
1.517 raeburn 5168: # See if there is a logo
5169: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5170: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5171: if ($imgsrc =~ m{^/(adm|res)/}) {
5172: if ($imgsrc =~ m{^/res/}) {
5173: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5174: &Apache::lonnet::repcopy($local_name);
5175: }
5176: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5177: }
5178: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5179: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5180: return &Apache::lonnet::domain($domain,'description');
1.59 www 5181: } else {
1.60 matthew 5182: return '';
1.59 www 5183: }
5184: }
1.63 www 5185: ##############################################
5186:
5187: =pod
5188:
1.112 bowersj2 5189: =item * &designparm()
1.63 www 5190:
5191: Inputs: $which parameter; $domain (usually will be undef)
5192:
5193: Returns: value of designparamter $which
5194:
5195: =cut
1.112 bowersj2 5196:
1.397 albertel 5197:
1.400 albertel 5198: ##############################################
1.397 albertel 5199: sub designparm {
5200: my ($which,$domain)=@_;
5201: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5202: return $env{'environment.color.'.$which};
1.96 www 5203: }
1.63 www 5204: $domain=&determinedomain($domain);
1.1016 raeburn 5205: my %domdesign;
5206: unless ($domain eq 'public') {
5207: %domdesign = &get_domainconf($domain);
5208: }
1.520 raeburn 5209: my $output;
1.517 raeburn 5210: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5211: $output = $domdesign{$domain.'.'.$which};
1.63 www 5212: } else {
1.520 raeburn 5213: $output = $defaultdesign{$which};
5214: }
5215: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5216: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5217: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5218: if ($output =~ m{^/res/}) {
5219: my $local_name = &Apache::lonnet::filelocation('',$output);
5220: &Apache::lonnet::repcopy($local_name);
5221: }
1.520 raeburn 5222: $output = &lonhttpdurl($output);
5223: }
1.63 www 5224: }
1.520 raeburn 5225: return $output;
1.63 www 5226: }
1.59 www 5227:
1.822 bisitz 5228: ##############################################
5229: =pod
5230:
1.832 bisitz 5231: =item * &authorspace()
5232:
1.1028 raeburn 5233: Inputs: $url (usually will be undef).
1.832 bisitz 5234:
1.1075.2.40 raeburn 5235: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5236: directory being viewed (or for which action is being taken).
5237: If $url is provided, and begins /priv/<domain>/<uname>
5238: the path will be that portion of the $context argument.
5239: Otherwise the path will be for the author space of the current
5240: user when the current role is author, or for that of the
5241: co-author/assistant co-author space when the current role
5242: is co-author or assistant co-author.
1.832 bisitz 5243:
5244: =cut
5245:
5246: sub authorspace {
1.1028 raeburn 5247: my ($url) = @_;
5248: if ($url ne '') {
5249: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5250: return $1;
5251: }
5252: }
1.832 bisitz 5253: my $caname = '';
1.1024 www 5254: my $cadom = '';
1.1028 raeburn 5255: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5256: ($cadom,$caname) =
1.832 bisitz 5257: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5258: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5259: $caname = $env{'user.name'};
1.1024 www 5260: $cadom = $env{'user.domain'};
1.832 bisitz 5261: }
1.1028 raeburn 5262: if (($caname ne '') && ($cadom ne '')) {
5263: return "/priv/$cadom/$caname/";
5264: }
5265: return;
1.832 bisitz 5266: }
5267:
5268: ##############################################
5269: =pod
5270:
1.822 bisitz 5271: =item * &head_subbox()
5272:
5273: Inputs: $content (contains HTML code with page functions, etc.)
5274:
5275: Returns: HTML div with $content
5276: To be included in page header
5277:
5278: =cut
5279:
5280: sub head_subbox {
5281: my ($content)=@_;
5282: my $output =
1.993 raeburn 5283: '<div class="LC_head_subbox">'
1.822 bisitz 5284: .$content
5285: .'</div>'
5286: }
5287:
5288: ##############################################
5289: =pod
5290:
5291: =item * &CSTR_pageheader()
5292:
1.1026 raeburn 5293: Input: (optional) filename from which breadcrumb trail is built.
5294: In most cases no input as needed, as $env{'request.filename'}
5295: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5296:
5297: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5298: To be included on Authoring Space pages
1.822 bisitz 5299:
5300: =cut
5301:
5302: sub CSTR_pageheader {
1.1026 raeburn 5303: my ($trailfile) = @_;
5304: if ($trailfile eq '') {
5305: $trailfile = $env{'request.filename'};
5306: }
5307:
5308: # this is for resources; directories have customtitle, and crumbs
5309: # and select recent are created in lonpubdir.pm
5310:
5311: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5312: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5313: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5314: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5315: $formaction =~ s{/+}{/}g;
1.822 bisitz 5316:
5317: my $parentpath = '';
5318: my $lastitem = '';
5319: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5320: $parentpath = $1;
5321: $lastitem = $2;
5322: } else {
5323: $lastitem = $thisdisfn;
5324: }
1.921 bisitz 5325:
5326: my $output =
1.822 bisitz 5327: '<div>'
5328: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5329: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5330: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5331: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5332: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5333:
5334: if ($lastitem) {
5335: $output .=
5336: '<span class="LC_filename">'
5337: .$lastitem
5338: .'</span>';
5339: }
5340: $output .=
5341: '<br />'
1.822 bisitz 5342: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5343: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5344: .'</form>'
5345: .&Apache::lonmenu::constspaceform()
5346: .'</div>';
1.921 bisitz 5347:
5348: return $output;
1.822 bisitz 5349: }
5350:
1.60 matthew 5351: ###############################################
5352: ###############################################
5353:
5354: =pod
5355:
1.112 bowersj2 5356: =back
5357:
1.549 albertel 5358: =head1 HTML Helpers
1.112 bowersj2 5359:
5360: =over 4
5361:
5362: =item * &bodytag()
1.60 matthew 5363:
5364: Returns a uniform header for LON-CAPA web pages.
5365:
5366: Inputs:
5367:
1.112 bowersj2 5368: =over 4
5369:
5370: =item * $title, A title to be displayed on the page.
5371:
5372: =item * $function, the current role (can be undef).
5373:
5374: =item * $addentries, extra parameters for the <body> tag.
5375:
5376: =item * $bodyonly, if defined, only return the <body> tag.
5377:
5378: =item * $domain, if defined, force a given domain.
5379:
5380: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5381: text interface only)
1.60 matthew 5382:
1.814 bisitz 5383: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5384: navigational links
1.317 albertel 5385:
1.338 albertel 5386: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5387:
1.1075.2.12 raeburn 5388: =item * $no_inline_link, if true and in remote mode, don't show the
5389: 'Switch To Inline Menu' link
5390:
1.460 albertel 5391: =item * $args, optional argument valid values are
5392: no_auto_mt_title -> prevents &mt()ing the title arg
5393:
1.1075.2.15 raeburn 5394: =item * $advtoolsref, optional argument, ref to an array containing
5395: inlineremote items to be added in "Functions" menu below
5396: breadcrumbs.
5397:
1.112 bowersj2 5398: =back
5399:
1.60 matthew 5400: Returns: A uniform header for LON-CAPA web pages.
5401: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5402: If $bodyonly is undef or zero, an html string containing a <body> tag and
5403: other decorations will be returned.
5404:
5405: =cut
5406:
1.54 www 5407: sub bodytag {
1.831 bisitz 5408: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5409: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5410:
1.954 raeburn 5411: my $public;
5412: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5413: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5414: $public = 1;
5415: }
1.460 albertel 5416: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5417: my $httphost = $args->{'use_absolute'};
1.339 albertel 5418:
1.183 matthew 5419: $function = &get_users_function() if (!$function);
1.339 albertel 5420: my $img = &designparm($function.'.img',$domain);
5421: my $font = &designparm($function.'.font',$domain);
5422: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5423:
1.803 bisitz 5424: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5425: 'bgcolor' => $pgbg,
1.339 albertel 5426: 'text' => $font,
5427: 'alink' => &designparm($function.'.alink',$domain),
5428: 'vlink' => &designparm($function.'.vlink',$domain),
5429: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5430: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5431:
1.63 www 5432: # role and realm
1.1075.2.68 raeburn 5433: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5434: if ($realm) {
5435: $realm = '/'.$realm;
5436: }
1.378 raeburn 5437: if ($role eq 'ca') {
1.479 albertel 5438: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5439: $realm = &plainname($rname,$rdom);
1.378 raeburn 5440: }
1.55 www 5441: # realm
1.258 albertel 5442: if ($env{'request.course.id'}) {
1.378 raeburn 5443: if ($env{'request.role'} !~ /^cr/) {
5444: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5445: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5446: if ($env{'request.role.desc'}) {
5447: $role = $env{'request.role.desc'};
5448: } else {
5449: $role = &mt('Helpdesk[_1]',' '.$2);
5450: }
1.1075.2.115 raeburn 5451: } else {
5452: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5453: }
1.898 raeburn 5454: if ($env{'request.course.sec'}) {
5455: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5456: }
1.359 albertel 5457: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5458: } else {
5459: $role = &Apache::lonnet::plaintext($role);
1.54 www 5460: }
1.433 albertel 5461:
1.359 albertel 5462: if (!$realm) { $realm=' '; }
1.330 albertel 5463:
1.438 albertel 5464: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5465:
1.101 www 5466: # construct main body tag
1.359 albertel 5467: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5468: &Apache::lontexconvert::init_math_support();
1.252 albertel 5469:
1.1075.2.38 raeburn 5470: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5471:
5472: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5473: return $bodytag;
1.1075.2.38 raeburn 5474: }
1.359 albertel 5475:
1.954 raeburn 5476: if ($public) {
1.433 albertel 5477: undef($role);
5478: }
1.359 albertel 5479:
1.762 bisitz 5480: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5481: #
5482: # Extra info if you are the DC
5483: my $dc_info = '';
5484: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5485: $env{'course.'.$env{'request.course.id'}.
5486: '.domain'}.'/'})) {
5487: my $cid = $env{'request.course.id'};
1.917 raeburn 5488: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5489: $dc_info =~ s/\s+$//;
1.359 albertel 5490: }
5491:
1.1075.2.108 raeburn 5492: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5493:
1.1075.2.13 raeburn 5494: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5495:
1.1075.2.38 raeburn 5496:
5497:
1.1075.2.21 raeburn 5498: my $funclist;
5499: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5500: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5501: Apache::lonmenu::serverform();
5502: my $forbodytag;
5503: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5504: $forcereg,$args->{'group'},
5505: $args->{'bread_crumbs'},
5506: $advtoolsref,'',\$forbodytag);
5507: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5508: $funclist = $forbodytag;
5509: }
5510: } else {
1.903 droeschl 5511:
5512: # if ($env{'request.state'} eq 'construct') {
5513: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5514: # }
5515:
1.1075.2.38 raeburn 5516: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5517: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5518:
1.1075.2.38 raeburn 5519: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5520:
1.916 droeschl 5521: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5522: if ($dc_info) {
5523: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5524: }
1.1075.2.38 raeburn 5525: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5526: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5527: return $bodytag;
5528: }
1.894 droeschl 5529:
1.927 raeburn 5530: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5531: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5532: }
1.916 droeschl 5533:
1.1075.2.38 raeburn 5534: $bodytag .= $right;
1.852 droeschl 5535:
1.917 raeburn 5536: if ($dc_info) {
5537: $dc_info = &dc_courseid_toggle($dc_info);
5538: }
5539: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5540:
1.1075.2.61 raeburn 5541: #if directed to not display the secondary menu, don't.
5542: if ($args->{'no_secondary_menu'}) {
5543: return $bodytag;
5544: }
1.903 droeschl 5545: #don't show menus for public users
1.954 raeburn 5546: if (!$public){
1.1075.2.52 raeburn 5547: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5548: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5549: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5550: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5551: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5552: $args->{'bread_crumbs'});
1.1075.2.116 raeburn 5553: } elsif ($forcereg) {
1.1075.2.22 raeburn 5554: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5555: $args->{'group'},
5556: $args->{'hide_buttons'});
1.1075.2.15 raeburn 5557: } else {
1.1075.2.21 raeburn 5558: my $forbodytag;
5559: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5560: $forcereg,$args->{'group'},
5561: $args->{'bread_crumbs'},
5562: $advtoolsref,'',\$forbodytag);
5563: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5564: $bodytag .= $forbodytag;
5565: }
1.920 raeburn 5566: }
1.903 droeschl 5567: }else{
5568: # this is to seperate menu from content when there's no secondary
5569: # menu. Especially needed for public accessible ressources.
5570: $bodytag .= '<hr style="clear:both" />';
5571: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5572: }
1.903 droeschl 5573:
1.235 raeburn 5574: return $bodytag;
1.1075.2.12 raeburn 5575: }
5576:
5577: #
5578: # Top frame rendering, Remote is up
5579: #
5580:
5581: my $imgsrc = $img;
5582: if ($img =~ /^\/adm/) {
5583: $imgsrc = &lonhttpdurl($img);
5584: }
5585: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5586:
1.1075.2.60 raeburn 5587: my $help=($no_inline_link?''
5588: :&Apache::loncommon::top_nav_help('Help'));
5589:
1.1075.2.12 raeburn 5590: # Explicit link to get inline menu
5591: my $menu= ($no_inline_link?''
5592: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5593:
5594: if ($dc_info) {
5595: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5596: }
5597:
1.1075.2.38 raeburn 5598: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5599: unless ($public) {
5600: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5601: undef,'LC_menubuttons_link');
5602: }
5603:
1.1075.2.12 raeburn 5604: unless ($env{'form.inhibitmenu'}) {
5605: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5606: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5607: <li>$help</li>
1.1075.2.12 raeburn 5608: <li>$menu</li>
5609: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5610: }
1.1075.2.13 raeburn 5611: if ($env{'request.state'} eq 'construct') {
5612: if (!$public){
5613: if ($env{'request.state'} eq 'construct') {
5614: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5615: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5616: &Apache::lonhtmlcommon::scripttag('','end').
5617: &Apache::lonmenu::innerregister($forcereg,
5618: $args->{'bread_crumbs'});
5619: }
5620: }
5621: }
1.1075.2.21 raeburn 5622: return $bodytag."\n".$funclist;
1.182 matthew 5623: }
5624:
1.917 raeburn 5625: sub dc_courseid_toggle {
5626: my ($dc_info) = @_;
1.980 raeburn 5627: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5628: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5629: &mt('(More ...)').'</a></span>'.
5630: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5631: }
5632:
1.330 albertel 5633: sub make_attr_string {
5634: my ($register,$attr_ref) = @_;
5635:
5636: if ($attr_ref && !ref($attr_ref)) {
5637: die("addentries Must be a hash ref ".
5638: join(':',caller(1))." ".
5639: join(':',caller(0))." ");
5640: }
5641:
5642: if ($register) {
1.339 albertel 5643: my ($on_load,$on_unload);
5644: foreach my $key (keys(%{$attr_ref})) {
5645: if (lc($key) eq 'onload') {
5646: $on_load.=$attr_ref->{$key}.';';
5647: delete($attr_ref->{$key});
5648:
5649: } elsif (lc($key) eq 'onunload') {
5650: $on_unload.=$attr_ref->{$key}.';';
5651: delete($attr_ref->{$key});
5652: }
5653: }
1.1075.2.12 raeburn 5654: if ($env{'environment.remote'} eq 'on') {
5655: $attr_ref->{'onload'} =
5656: &Apache::lonmenu::loadevents(). $on_load;
5657: $attr_ref->{'onunload'}=
5658: &Apache::lonmenu::unloadevents().$on_unload;
5659: } else {
5660: $attr_ref->{'onload'} = $on_load;
5661: $attr_ref->{'onunload'}= $on_unload;
5662: }
1.330 albertel 5663: }
1.339 albertel 5664:
1.330 albertel 5665: my $attr_string;
1.1075.2.56 raeburn 5666: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5667: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5668: }
5669: return $attr_string;
5670: }
5671:
5672:
1.182 matthew 5673: ###############################################
1.251 albertel 5674: ###############################################
5675:
5676: =pod
5677:
5678: =item * &endbodytag()
5679:
5680: Returns a uniform footer for LON-CAPA web pages.
5681:
1.635 raeburn 5682: Inputs: 1 - optional reference to an args hash
5683: If in the hash, key for noredirectlink has a value which evaluates to true,
5684: a 'Continue' link is not displayed if the page contains an
5685: internal redirect in the <head></head> section,
5686: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5687:
5688: =cut
5689:
5690: sub endbodytag {
1.635 raeburn 5691: my ($args) = @_;
1.1075.2.6 raeburn 5692: my $endbodytag;
5693: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5694: $endbodytag='</body>';
5695: }
1.315 albertel 5696: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5697: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5698: $endbodytag=
5699: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5700: &mt('Continue').'</a>'.
5701: $endbodytag;
5702: }
1.315 albertel 5703: }
1.251 albertel 5704: return $endbodytag;
5705: }
5706:
1.352 albertel 5707: =pod
5708:
5709: =item * &standard_css()
5710:
5711: Returns a style sheet
5712:
5713: Inputs: (all optional)
5714: domain -> force to color decorate a page for a specific
5715: domain
5716: function -> force usage of a specific rolish color scheme
5717: bgcolor -> override the default page bgcolor
5718:
5719: =cut
5720:
1.343 albertel 5721: sub standard_css {
1.345 albertel 5722: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5723: $function = &get_users_function() if (!$function);
5724: my $img = &designparm($function.'.img', $domain);
5725: my $tabbg = &designparm($function.'.tabbg', $domain);
5726: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5727: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5728: #second colour for later usage
1.345 albertel 5729: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5730: my $pgbg_or_bgcolor =
5731: $bgcolor ||
1.352 albertel 5732: &designparm($function.'.pgbg', $domain);
1.382 albertel 5733: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5734: my $alink = &designparm($function.'.alink', $domain);
5735: my $vlink = &designparm($function.'.vlink', $domain);
5736: my $link = &designparm($function.'.link', $domain);
5737:
1.602 albertel 5738: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5739: my $mono = 'monospace';
1.850 bisitz 5740: my $data_table_head = $sidebg;
5741: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5742: my $data_table_dark = '#E0E0E0';
1.470 banghart 5743: my $data_table_darker = '#CCCCCC';
1.349 albertel 5744: my $data_table_highlight = '#FFFF00';
1.352 albertel 5745: my $mail_new = '#FFBB77';
5746: my $mail_new_hover = '#DD9955';
5747: my $mail_read = '#BBBB77';
5748: my $mail_read_hover = '#999944';
5749: my $mail_replied = '#AAAA88';
5750: my $mail_replied_hover = '#888855';
5751: my $mail_other = '#99BBBB';
5752: my $mail_other_hover = '#669999';
1.391 albertel 5753: my $table_header = '#DDDDDD';
1.489 raeburn 5754: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5755: my $lg_border_color = '#C8C8C8';
1.952 onken 5756: my $button_hover = '#BF2317';
1.392 albertel 5757:
1.608 albertel 5758: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5759: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5760: : '0 3px 0 4px';
1.448 albertel 5761:
1.523 albertel 5762:
1.343 albertel 5763: return <<END;
1.947 droeschl 5764:
5765: /* needed for iframe to allow 100% height in FF */
5766: body, html {
5767: margin: 0;
5768: padding: 0 0.5%;
5769: height: 99%; /* to avoid scrollbars */
5770: }
5771:
1.795 www 5772: body {
1.911 bisitz 5773: font-family: $sans;
5774: line-height:130%;
5775: font-size:0.83em;
5776: color:$font;
1.795 www 5777: }
5778:
1.959 onken 5779: a:focus,
5780: a:focus img {
1.795 www 5781: color: red;
5782: }
1.698 harmsja 5783:
1.911 bisitz 5784: form, .inline {
5785: display: inline;
1.795 www 5786: }
1.721 harmsja 5787:
1.795 www 5788: .LC_right {
1.911 bisitz 5789: text-align:right;
1.795 www 5790: }
5791:
5792: .LC_middle {
1.911 bisitz 5793: vertical-align:middle;
1.795 www 5794: }
1.721 harmsja 5795:
1.1075.2.38 raeburn 5796: .LC_floatleft {
5797: float: left;
5798: }
5799:
5800: .LC_floatright {
5801: float: right;
5802: }
5803:
1.911 bisitz 5804: .LC_400Box {
5805: width:400px;
5806: }
1.721 harmsja 5807:
1.947 droeschl 5808: .LC_iframecontainer {
5809: width: 98%;
5810: margin: 0;
5811: position: fixed;
5812: top: 8.5em;
5813: bottom: 0;
5814: }
5815:
5816: .LC_iframecontainer iframe{
5817: border: none;
5818: width: 100%;
5819: height: 100%;
5820: }
5821:
1.778 bisitz 5822: .LC_filename {
5823: font-family: $mono;
5824: white-space:pre;
1.921 bisitz 5825: font-size: 120%;
1.778 bisitz 5826: }
5827:
5828: .LC_fileicon {
5829: border: none;
5830: height: 1.3em;
5831: vertical-align: text-bottom;
5832: margin-right: 0.3em;
5833: text-decoration:none;
5834: }
5835:
1.1008 www 5836: .LC_setting {
5837: text-decoration:underline;
5838: }
5839:
1.350 albertel 5840: .LC_error {
5841: color: red;
5842: }
1.795 www 5843:
1.1075.2.15 raeburn 5844: .LC_warning {
5845: color: darkorange;
5846: }
5847:
1.457 albertel 5848: .LC_diff_removed {
1.733 bisitz 5849: color: red;
1.394 albertel 5850: }
1.532 albertel 5851:
5852: .LC_info,
1.457 albertel 5853: .LC_success,
5854: .LC_diff_added {
1.350 albertel 5855: color: green;
5856: }
1.795 www 5857:
1.802 bisitz 5858: div.LC_confirm_box {
5859: background-color: #FAFAFA;
5860: border: 1px solid $lg_border_color;
5861: margin-right: 0;
5862: padding: 5px;
5863: }
5864:
5865: div.LC_confirm_box .LC_error img,
5866: div.LC_confirm_box .LC_success img {
5867: vertical-align: middle;
5868: }
5869:
1.1075.2.108 raeburn 5870: .LC_maxwidth {
5871: max-width: 100%;
5872: height: auto;
5873: }
5874:
5875: .LC_textsize_mobile {
5876: \@media only screen and (max-device-width: 480px) {
5877: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
5878: }
5879: }
5880:
1.440 albertel 5881: .LC_icon {
1.771 droeschl 5882: border: none;
1.790 droeschl 5883: vertical-align: middle;
1.771 droeschl 5884: }
5885:
1.543 albertel 5886: .LC_docs_spacer {
5887: width: 25px;
5888: height: 1px;
1.771 droeschl 5889: border: none;
1.543 albertel 5890: }
1.346 albertel 5891:
1.532 albertel 5892: .LC_internal_info {
1.735 bisitz 5893: color: #999999;
1.532 albertel 5894: }
5895:
1.794 www 5896: .LC_discussion {
1.1050 www 5897: background: $data_table_dark;
1.911 bisitz 5898: border: 1px solid black;
5899: margin: 2px;
1.794 www 5900: }
5901:
5902: .LC_disc_action_left {
1.1050 www 5903: background: $sidebg;
1.911 bisitz 5904: text-align: left;
1.1050 www 5905: padding: 4px;
5906: margin: 2px;
1.794 www 5907: }
5908:
5909: .LC_disc_action_right {
1.1050 www 5910: background: $sidebg;
1.911 bisitz 5911: text-align: right;
1.1050 www 5912: padding: 4px;
5913: margin: 2px;
1.794 www 5914: }
5915:
5916: .LC_disc_new_item {
1.911 bisitz 5917: background: white;
5918: border: 2px solid red;
1.1050 www 5919: margin: 4px;
5920: padding: 4px;
1.794 www 5921: }
5922:
5923: .LC_disc_old_item {
1.911 bisitz 5924: background: white;
1.1050 www 5925: margin: 4px;
5926: padding: 4px;
1.794 www 5927: }
5928:
1.458 albertel 5929: table.LC_pastsubmission {
5930: border: 1px solid black;
5931: margin: 2px;
5932: }
5933:
1.924 bisitz 5934: table#LC_menubuttons {
1.345 albertel 5935: width: 100%;
5936: background: $pgbg;
1.392 albertel 5937: border: 2px;
1.402 albertel 5938: border-collapse: separate;
1.803 bisitz 5939: padding: 0;
1.345 albertel 5940: }
1.392 albertel 5941:
1.801 tempelho 5942: table#LC_title_bar a {
5943: color: $fontmenu;
5944: }
1.836 bisitz 5945:
1.807 droeschl 5946: table#LC_title_bar {
1.819 tempelho 5947: clear: both;
1.836 bisitz 5948: display: none;
1.807 droeschl 5949: }
5950:
1.795 www 5951: table#LC_title_bar,
1.933 droeschl 5952: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5953: table#LC_title_bar.LC_with_remote {
1.359 albertel 5954: width: 100%;
1.392 albertel 5955: border-color: $pgbg;
5956: border-style: solid;
5957: border-width: $border;
1.379 albertel 5958: background: $pgbg;
1.801 tempelho 5959: color: $fontmenu;
1.392 albertel 5960: border-collapse: collapse;
1.803 bisitz 5961: padding: 0;
1.819 tempelho 5962: margin: 0;
1.359 albertel 5963: }
1.795 www 5964:
1.933 droeschl 5965: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5966: margin: 0;
5967: padding: 0;
1.933 droeschl 5968: position: relative;
5969: list-style: none;
1.913 droeschl 5970: }
1.933 droeschl 5971: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5972: display: inline;
5973: }
1.933 droeschl 5974:
5975: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5976: padding: 0;
1.933 droeschl 5977: margin: 0;
5978: float: left;
1.913 droeschl 5979: }
1.933 droeschl 5980: .LC_breadcrumb_tools_tools {
5981: padding: 0;
5982: margin: 0;
1.913 droeschl 5983: float: right;
5984: }
5985:
1.359 albertel 5986: table#LC_title_bar td {
5987: background: $tabbg;
5988: }
1.795 www 5989:
1.911 bisitz 5990: table#LC_menubuttons img {
1.803 bisitz 5991: border: none;
1.346 albertel 5992: }
1.795 www 5993:
1.842 droeschl 5994: .LC_breadcrumbs_component {
1.911 bisitz 5995: float: right;
5996: margin: 0 1em;
1.357 albertel 5997: }
1.842 droeschl 5998: .LC_breadcrumbs_component img {
1.911 bisitz 5999: vertical-align: middle;
1.777 tempelho 6000: }
1.795 www 6001:
1.1075.2.108 raeburn 6002: .LC_breadcrumbs_hoverable {
6003: background: $sidebg;
6004: }
6005:
1.383 albertel 6006: td.LC_table_cell_checkbox {
6007: text-align: center;
6008: }
1.795 www 6009:
6010: .LC_fontsize_small {
1.911 bisitz 6011: font-size: 70%;
1.705 tempelho 6012: }
6013:
1.844 bisitz 6014: #LC_breadcrumbs {
1.911 bisitz 6015: clear:both;
6016: background: $sidebg;
6017: border-bottom: 1px solid $lg_border_color;
6018: line-height: 2.5em;
1.933 droeschl 6019: overflow: hidden;
1.911 bisitz 6020: margin: 0;
6021: padding: 0;
1.995 raeburn 6022: text-align: left;
1.819 tempelho 6023: }
1.862 bisitz 6024:
1.1075.2.16 raeburn 6025: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6026: clear:both;
6027: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6028: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6029: margin: 0 0 10px 0;
1.966 bisitz 6030: padding: 3px;
1.995 raeburn 6031: text-align: left;
1.822 bisitz 6032: }
6033:
1.795 www 6034: .LC_fontsize_medium {
1.911 bisitz 6035: font-size: 85%;
1.705 tempelho 6036: }
6037:
1.795 www 6038: .LC_fontsize_large {
1.911 bisitz 6039: font-size: 120%;
1.705 tempelho 6040: }
6041:
1.346 albertel 6042: .LC_menubuttons_inline_text {
6043: color: $font;
1.698 harmsja 6044: font-size: 90%;
1.701 harmsja 6045: padding-left:3px;
1.346 albertel 6046: }
6047:
1.934 droeschl 6048: .LC_menubuttons_inline_text img{
6049: vertical-align: middle;
6050: }
6051:
1.1051 www 6052: li.LC_menubuttons_inline_text img {
1.951 onken 6053: cursor:pointer;
1.1002 droeschl 6054: text-decoration: none;
1.951 onken 6055: }
6056:
1.526 www 6057: .LC_menubuttons_link {
6058: text-decoration: none;
6059: }
1.795 www 6060:
1.522 albertel 6061: .LC_menubuttons_category {
1.521 www 6062: color: $font;
1.526 www 6063: background: $pgbg;
1.521 www 6064: font-size: larger;
6065: font-weight: bold;
6066: }
6067:
1.346 albertel 6068: td.LC_menubuttons_text {
1.911 bisitz 6069: color: $font;
1.346 albertel 6070: }
1.706 harmsja 6071:
1.346 albertel 6072: .LC_current_location {
6073: background: $tabbg;
6074: }
1.795 www 6075:
1.938 bisitz 6076: table.LC_data_table {
1.347 albertel 6077: border: 1px solid #000000;
1.402 albertel 6078: border-collapse: separate;
1.426 albertel 6079: border-spacing: 1px;
1.610 albertel 6080: background: $pgbg;
1.347 albertel 6081: }
1.795 www 6082:
1.422 albertel 6083: .LC_data_table_dense {
6084: font-size: small;
6085: }
1.795 www 6086:
1.507 raeburn 6087: table.LC_nested_outer {
6088: border: 1px solid #000000;
1.589 raeburn 6089: border-collapse: collapse;
1.803 bisitz 6090: border-spacing: 0;
1.507 raeburn 6091: width: 100%;
6092: }
1.795 www 6093:
1.879 raeburn 6094: table.LC_innerpickbox,
1.507 raeburn 6095: table.LC_nested {
1.803 bisitz 6096: border: none;
1.589 raeburn 6097: border-collapse: collapse;
1.803 bisitz 6098: border-spacing: 0;
1.507 raeburn 6099: width: 100%;
6100: }
1.795 www 6101:
1.911 bisitz 6102: table.LC_data_table tr th,
6103: table.LC_calendar tr th,
1.879 raeburn 6104: table.LC_prior_tries tr th,
6105: table.LC_innerpickbox tr th {
1.349 albertel 6106: font-weight: bold;
6107: background-color: $data_table_head;
1.801 tempelho 6108: color:$fontmenu;
1.701 harmsja 6109: font-size:90%;
1.347 albertel 6110: }
1.795 www 6111:
1.879 raeburn 6112: table.LC_innerpickbox tr th,
6113: table.LC_innerpickbox tr td {
6114: vertical-align: top;
6115: }
6116:
1.711 raeburn 6117: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6118: background-color: #CCCCCC;
1.711 raeburn 6119: font-weight: bold;
6120: text-align: left;
6121: }
1.795 www 6122:
1.912 bisitz 6123: table.LC_data_table tr.LC_odd_row > td {
6124: background-color: $data_table_light;
6125: padding: 2px;
6126: vertical-align: top;
6127: }
6128:
1.809 bisitz 6129: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6130: background-color: $data_table_light;
1.912 bisitz 6131: vertical-align: top;
6132: }
6133:
6134: table.LC_data_table tr.LC_even_row > td {
6135: background-color: $data_table_dark;
1.425 albertel 6136: padding: 2px;
1.900 bisitz 6137: vertical-align: top;
1.347 albertel 6138: }
1.795 www 6139:
1.809 bisitz 6140: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6141: background-color: $data_table_dark;
1.900 bisitz 6142: vertical-align: top;
1.347 albertel 6143: }
1.795 www 6144:
1.425 albertel 6145: table.LC_data_table tr.LC_data_table_highlight td {
6146: background-color: $data_table_darker;
6147: }
1.795 www 6148:
1.639 raeburn 6149: table.LC_data_table tr td.LC_leftcol_header {
6150: background-color: $data_table_head;
6151: font-weight: bold;
6152: }
1.795 www 6153:
1.451 albertel 6154: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6155: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6156: font-weight: bold;
6157: font-style: italic;
6158: text-align: center;
6159: padding: 8px;
1.347 albertel 6160: }
1.795 www 6161:
1.1075.2.30 raeburn 6162: table.LC_data_table tr.LC_empty_row td,
6163: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6164: background-color: $sidebg;
6165: }
6166:
6167: table.LC_nested tr.LC_empty_row td {
6168: background-color: #FFFFFF;
6169: }
6170:
1.890 droeschl 6171: table.LC_caption {
6172: }
6173:
1.507 raeburn 6174: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6175: padding: 4ex
6176: }
1.795 www 6177:
1.507 raeburn 6178: table.LC_nested_outer tr th {
6179: font-weight: bold;
1.801 tempelho 6180: color:$fontmenu;
1.507 raeburn 6181: background-color: $data_table_head;
1.701 harmsja 6182: font-size: small;
1.507 raeburn 6183: border-bottom: 1px solid #000000;
6184: }
1.795 www 6185:
1.507 raeburn 6186: table.LC_nested_outer tr td.LC_subheader {
6187: background-color: $data_table_head;
6188: font-weight: bold;
6189: font-size: small;
6190: border-bottom: 1px solid #000000;
6191: text-align: right;
1.451 albertel 6192: }
1.795 www 6193:
1.507 raeburn 6194: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6195: background-color: #CCCCCC;
1.451 albertel 6196: font-weight: bold;
6197: font-size: small;
1.507 raeburn 6198: text-align: center;
6199: }
1.795 www 6200:
1.589 raeburn 6201: table.LC_nested tr.LC_info_row td.LC_left_item,
6202: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6203: text-align: left;
1.451 albertel 6204: }
1.795 www 6205:
1.507 raeburn 6206: table.LC_nested td {
1.735 bisitz 6207: background-color: #FFFFFF;
1.451 albertel 6208: font-size: small;
1.507 raeburn 6209: }
1.795 www 6210:
1.507 raeburn 6211: table.LC_nested_outer tr th.LC_right_item,
6212: table.LC_nested tr.LC_info_row td.LC_right_item,
6213: table.LC_nested tr.LC_odd_row td.LC_right_item,
6214: table.LC_nested tr td.LC_right_item {
1.451 albertel 6215: text-align: right;
6216: }
6217:
1.507 raeburn 6218: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6219: background-color: #EEEEEE;
1.451 albertel 6220: }
6221:
1.473 raeburn 6222: table.LC_createuser {
6223: }
6224:
6225: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6226: font-size: small;
1.473 raeburn 6227: }
6228:
6229: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6230: background-color: #CCCCCC;
1.473 raeburn 6231: font-weight: bold;
6232: text-align: center;
6233: }
6234:
1.349 albertel 6235: table.LC_calendar {
6236: border: 1px solid #000000;
6237: border-collapse: collapse;
1.917 raeburn 6238: width: 98%;
1.349 albertel 6239: }
1.795 www 6240:
1.349 albertel 6241: table.LC_calendar_pickdate {
6242: font-size: xx-small;
6243: }
1.795 www 6244:
1.349 albertel 6245: table.LC_calendar tr td {
6246: border: 1px solid #000000;
6247: vertical-align: top;
1.917 raeburn 6248: width: 14%;
1.349 albertel 6249: }
1.795 www 6250:
1.349 albertel 6251: table.LC_calendar tr td.LC_calendar_day_empty {
6252: background-color: $data_table_dark;
6253: }
1.795 www 6254:
1.779 bisitz 6255: table.LC_calendar tr td.LC_calendar_day_current {
6256: background-color: $data_table_highlight;
1.777 tempelho 6257: }
1.795 www 6258:
1.938 bisitz 6259: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6260: background-color: $mail_new;
6261: }
1.795 www 6262:
1.938 bisitz 6263: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6264: background-color: $mail_new_hover;
6265: }
1.795 www 6266:
1.938 bisitz 6267: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6268: background-color: $mail_read;
6269: }
1.795 www 6270:
1.938 bisitz 6271: /*
6272: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6273: background-color: $mail_read_hover;
6274: }
1.938 bisitz 6275: */
1.795 www 6276:
1.938 bisitz 6277: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6278: background-color: $mail_replied;
6279: }
1.795 www 6280:
1.938 bisitz 6281: /*
6282: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6283: background-color: $mail_replied_hover;
6284: }
1.938 bisitz 6285: */
1.795 www 6286:
1.938 bisitz 6287: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6288: background-color: $mail_other;
6289: }
1.795 www 6290:
1.938 bisitz 6291: /*
6292: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6293: background-color: $mail_other_hover;
6294: }
1.938 bisitz 6295: */
1.494 raeburn 6296:
1.777 tempelho 6297: table.LC_data_table tr > td.LC_browser_file,
6298: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6299: background: #AAEE77;
1.389 albertel 6300: }
1.795 www 6301:
1.777 tempelho 6302: table.LC_data_table tr > td.LC_browser_file_locked,
6303: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6304: background: #FFAA99;
1.387 albertel 6305: }
1.795 www 6306:
1.777 tempelho 6307: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6308: background: #888888;
1.779 bisitz 6309: }
1.795 www 6310:
1.777 tempelho 6311: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6312: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6313: background: #F8F866;
1.777 tempelho 6314: }
1.795 www 6315:
1.696 bisitz 6316: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6317: background: #E0E8FF;
1.387 albertel 6318: }
1.696 bisitz 6319:
1.707 bisitz 6320: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6321: /* background: #77FF77; */
1.707 bisitz 6322: }
1.795 www 6323:
1.707 bisitz 6324: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6325: border-right: 8px solid #FFFF77;
1.707 bisitz 6326: }
1.795 www 6327:
1.707 bisitz 6328: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6329: border-right: 8px solid #FFAA77;
1.707 bisitz 6330: }
1.795 www 6331:
1.707 bisitz 6332: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6333: border-right: 8px solid #FF7777;
1.707 bisitz 6334: }
1.795 www 6335:
1.707 bisitz 6336: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6337: border-right: 8px solid #AAFF77;
1.707 bisitz 6338: }
1.795 www 6339:
1.707 bisitz 6340: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6341: border-right: 8px solid #11CC55;
1.707 bisitz 6342: }
6343:
1.388 albertel 6344: span.LC_current_location {
1.701 harmsja 6345: font-size:larger;
1.388 albertel 6346: background: $pgbg;
6347: }
1.387 albertel 6348:
1.1029 www 6349: span.LC_current_nav_location {
6350: font-weight:bold;
6351: background: $sidebg;
6352: }
6353:
1.395 albertel 6354: span.LC_parm_menu_item {
6355: font-size: larger;
6356: }
1.795 www 6357:
1.395 albertel 6358: span.LC_parm_scope_all {
6359: color: red;
6360: }
1.795 www 6361:
1.395 albertel 6362: span.LC_parm_scope_folder {
6363: color: green;
6364: }
1.795 www 6365:
1.395 albertel 6366: span.LC_parm_scope_resource {
6367: color: orange;
6368: }
1.795 www 6369:
1.395 albertel 6370: span.LC_parm_part {
6371: color: blue;
6372: }
1.795 www 6373:
1.911 bisitz 6374: span.LC_parm_folder,
6375: span.LC_parm_symb {
1.395 albertel 6376: font-size: x-small;
6377: font-family: $mono;
6378: color: #AAAAAA;
6379: }
6380:
1.977 bisitz 6381: ul.LC_parm_parmlist li {
6382: display: inline-block;
6383: padding: 0.3em 0.8em;
6384: vertical-align: top;
6385: width: 150px;
6386: border-top:1px solid $lg_border_color;
6387: }
6388:
1.795 www 6389: td.LC_parm_overview_level_menu,
6390: td.LC_parm_overview_map_menu,
6391: td.LC_parm_overview_parm_selectors,
6392: td.LC_parm_overview_restrictions {
1.396 albertel 6393: border: 1px solid black;
6394: border-collapse: collapse;
6395: }
1.795 www 6396:
1.396 albertel 6397: table.LC_parm_overview_restrictions td {
6398: border-width: 1px 4px 1px 4px;
6399: border-style: solid;
6400: border-color: $pgbg;
6401: text-align: center;
6402: }
1.795 www 6403:
1.396 albertel 6404: table.LC_parm_overview_restrictions th {
6405: background: $tabbg;
6406: border-width: 1px 4px 1px 4px;
6407: border-style: solid;
6408: border-color: $pgbg;
6409: }
1.795 www 6410:
1.398 albertel 6411: table#LC_helpmenu {
1.803 bisitz 6412: border: none;
1.398 albertel 6413: height: 55px;
1.803 bisitz 6414: border-spacing: 0;
1.398 albertel 6415: }
6416:
6417: table#LC_helpmenu fieldset legend {
6418: font-size: larger;
6419: }
1.795 www 6420:
1.397 albertel 6421: table#LC_helpmenu_links {
6422: width: 100%;
6423: border: 1px solid black;
6424: background: $pgbg;
1.803 bisitz 6425: padding: 0;
1.397 albertel 6426: border-spacing: 1px;
6427: }
1.795 www 6428:
1.397 albertel 6429: table#LC_helpmenu_links tr td {
6430: padding: 1px;
6431: background: $tabbg;
1.399 albertel 6432: text-align: center;
6433: font-weight: bold;
1.397 albertel 6434: }
1.396 albertel 6435:
1.795 www 6436: table#LC_helpmenu_links a:link,
6437: table#LC_helpmenu_links a:visited,
1.397 albertel 6438: table#LC_helpmenu_links a:active {
6439: text-decoration: none;
6440: color: $font;
6441: }
1.795 www 6442:
1.397 albertel 6443: table#LC_helpmenu_links a:hover {
6444: text-decoration: underline;
6445: color: $vlink;
6446: }
1.396 albertel 6447:
1.417 albertel 6448: .LC_chrt_popup_exists {
6449: border: 1px solid #339933;
6450: margin: -1px;
6451: }
1.795 www 6452:
1.417 albertel 6453: .LC_chrt_popup_up {
6454: border: 1px solid yellow;
6455: margin: -1px;
6456: }
1.795 www 6457:
1.417 albertel 6458: .LC_chrt_popup {
6459: border: 1px solid #8888FF;
6460: background: #CCCCFF;
6461: }
1.795 www 6462:
1.421 albertel 6463: table.LC_pick_box {
6464: border-collapse: separate;
6465: background: white;
6466: border: 1px solid black;
6467: border-spacing: 1px;
6468: }
1.795 www 6469:
1.421 albertel 6470: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6471: background: $sidebg;
1.421 albertel 6472: font-weight: bold;
1.900 bisitz 6473: text-align: left;
1.740 bisitz 6474: vertical-align: top;
1.421 albertel 6475: width: 184px;
6476: padding: 8px;
6477: }
1.795 www 6478:
1.579 raeburn 6479: table.LC_pick_box td.LC_pick_box_value {
6480: text-align: left;
6481: padding: 8px;
6482: }
1.795 www 6483:
1.579 raeburn 6484: table.LC_pick_box td.LC_pick_box_select {
6485: text-align: left;
6486: padding: 8px;
6487: }
1.795 www 6488:
1.424 albertel 6489: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6490: padding: 0;
1.421 albertel 6491: height: 1px;
6492: background: black;
6493: }
1.795 www 6494:
1.421 albertel 6495: table.LC_pick_box td.LC_pick_box_submit {
6496: text-align: right;
6497: }
1.795 www 6498:
1.579 raeburn 6499: table.LC_pick_box td.LC_evenrow_value {
6500: text-align: left;
6501: padding: 8px;
6502: background-color: $data_table_light;
6503: }
1.795 www 6504:
1.579 raeburn 6505: table.LC_pick_box td.LC_oddrow_value {
6506: text-align: left;
6507: padding: 8px;
6508: background-color: $data_table_light;
6509: }
1.795 www 6510:
1.579 raeburn 6511: span.LC_helpform_receipt_cat {
6512: font-weight: bold;
6513: }
1.795 www 6514:
1.424 albertel 6515: table.LC_group_priv_box {
6516: background: white;
6517: border: 1px solid black;
6518: border-spacing: 1px;
6519: }
1.795 www 6520:
1.424 albertel 6521: table.LC_group_priv_box td.LC_pick_box_title {
6522: background: $tabbg;
6523: font-weight: bold;
6524: text-align: right;
6525: width: 184px;
6526: }
1.795 www 6527:
1.424 albertel 6528: table.LC_group_priv_box td.LC_groups_fixed {
6529: background: $data_table_light;
6530: text-align: center;
6531: }
1.795 www 6532:
1.424 albertel 6533: table.LC_group_priv_box td.LC_groups_optional {
6534: background: $data_table_dark;
6535: text-align: center;
6536: }
1.795 www 6537:
1.424 albertel 6538: table.LC_group_priv_box td.LC_groups_functionality {
6539: background: $data_table_darker;
6540: text-align: center;
6541: font-weight: bold;
6542: }
1.795 www 6543:
1.424 albertel 6544: table.LC_group_priv td {
6545: text-align: left;
1.803 bisitz 6546: padding: 0;
1.424 albertel 6547: }
6548:
6549: .LC_navbuttons {
6550: margin: 2ex 0ex 2ex 0ex;
6551: }
1.795 www 6552:
1.423 albertel 6553: .LC_topic_bar {
6554: font-weight: bold;
6555: background: $tabbg;
1.918 wenzelju 6556: margin: 1em 0em 1em 2em;
1.805 bisitz 6557: padding: 3px;
1.918 wenzelju 6558: font-size: 1.2em;
1.423 albertel 6559: }
1.795 www 6560:
1.423 albertel 6561: .LC_topic_bar span {
1.918 wenzelju 6562: left: 0.5em;
6563: position: absolute;
1.423 albertel 6564: vertical-align: middle;
1.918 wenzelju 6565: font-size: 1.2em;
1.423 albertel 6566: }
1.795 www 6567:
1.423 albertel 6568: table.LC_course_group_status {
6569: margin: 20px;
6570: }
1.795 www 6571:
1.423 albertel 6572: table.LC_status_selector td {
6573: vertical-align: top;
6574: text-align: center;
1.424 albertel 6575: padding: 4px;
6576: }
1.795 www 6577:
1.599 albertel 6578: div.LC_feedback_link {
1.616 albertel 6579: clear: both;
1.829 kalberla 6580: background: $sidebg;
1.779 bisitz 6581: width: 100%;
1.829 kalberla 6582: padding-bottom: 10px;
6583: border: 1px $tabbg solid;
1.833 kalberla 6584: height: 22px;
6585: line-height: 22px;
6586: padding-top: 5px;
6587: }
6588:
6589: div.LC_feedback_link img {
6590: height: 22px;
1.867 kalberla 6591: vertical-align:middle;
1.829 kalberla 6592: }
6593:
1.911 bisitz 6594: div.LC_feedback_link a {
1.829 kalberla 6595: text-decoration: none;
1.489 raeburn 6596: }
1.795 www 6597:
1.867 kalberla 6598: div.LC_comblock {
1.911 bisitz 6599: display:inline;
1.867 kalberla 6600: color:$font;
6601: font-size:90%;
6602: }
6603:
6604: div.LC_feedback_link div.LC_comblock {
6605: padding-left:5px;
6606: }
6607:
6608: div.LC_feedback_link div.LC_comblock a {
6609: color:$font;
6610: }
6611:
1.489 raeburn 6612: span.LC_feedback_link {
1.858 bisitz 6613: /* background: $feedback_link_bg; */
1.599 albertel 6614: font-size: larger;
6615: }
1.795 www 6616:
1.599 albertel 6617: span.LC_message_link {
1.858 bisitz 6618: /* background: $feedback_link_bg; */
1.599 albertel 6619: font-size: larger;
6620: position: absolute;
6621: right: 1em;
1.489 raeburn 6622: }
1.421 albertel 6623:
1.515 albertel 6624: table.LC_prior_tries {
1.524 albertel 6625: border: 1px solid #000000;
6626: border-collapse: separate;
6627: border-spacing: 1px;
1.515 albertel 6628: }
1.523 albertel 6629:
1.515 albertel 6630: table.LC_prior_tries td {
1.524 albertel 6631: padding: 2px;
1.515 albertel 6632: }
1.523 albertel 6633:
6634: .LC_answer_correct {
1.795 www 6635: background: lightgreen;
6636: color: darkgreen;
6637: padding: 6px;
1.523 albertel 6638: }
1.795 www 6639:
1.523 albertel 6640: .LC_answer_charged_try {
1.797 www 6641: background: #FFAAAA;
1.795 www 6642: color: darkred;
6643: padding: 6px;
1.523 albertel 6644: }
1.795 www 6645:
1.779 bisitz 6646: .LC_answer_not_charged_try,
1.523 albertel 6647: .LC_answer_no_grade,
6648: .LC_answer_late {
1.795 www 6649: background: lightyellow;
1.523 albertel 6650: color: black;
1.795 www 6651: padding: 6px;
1.523 albertel 6652: }
1.795 www 6653:
1.523 albertel 6654: .LC_answer_previous {
1.795 www 6655: background: lightblue;
6656: color: darkblue;
6657: padding: 6px;
1.523 albertel 6658: }
1.795 www 6659:
1.779 bisitz 6660: .LC_answer_no_message {
1.777 tempelho 6661: background: #FFFFFF;
6662: color: black;
1.795 www 6663: padding: 6px;
1.779 bisitz 6664: }
1.795 www 6665:
1.779 bisitz 6666: .LC_answer_unknown {
6667: background: orange;
6668: color: black;
1.795 www 6669: padding: 6px;
1.777 tempelho 6670: }
1.795 www 6671:
1.529 albertel 6672: span.LC_prior_numerical,
6673: span.LC_prior_string,
6674: span.LC_prior_custom,
6675: span.LC_prior_reaction,
6676: span.LC_prior_math {
1.925 bisitz 6677: font-family: $mono;
1.523 albertel 6678: white-space: pre;
6679: }
6680:
1.525 albertel 6681: span.LC_prior_string {
1.925 bisitz 6682: font-family: $mono;
1.525 albertel 6683: white-space: pre;
6684: }
6685:
1.523 albertel 6686: table.LC_prior_option {
6687: width: 100%;
6688: border-collapse: collapse;
6689: }
1.795 www 6690:
1.911 bisitz 6691: table.LC_prior_rank,
1.795 www 6692: table.LC_prior_match {
1.528 albertel 6693: border-collapse: collapse;
6694: }
1.795 www 6695:
1.528 albertel 6696: table.LC_prior_option tr td,
6697: table.LC_prior_rank tr td,
6698: table.LC_prior_match tr td {
1.524 albertel 6699: border: 1px solid #000000;
1.515 albertel 6700: }
6701:
1.855 bisitz 6702: .LC_nobreak {
1.544 albertel 6703: white-space: nowrap;
1.519 raeburn 6704: }
6705:
1.576 raeburn 6706: span.LC_cusr_emph {
6707: font-style: italic;
6708: }
6709:
1.633 raeburn 6710: span.LC_cusr_subheading {
6711: font-weight: normal;
6712: font-size: 85%;
6713: }
6714:
1.861 bisitz 6715: div.LC_docs_entry_move {
1.859 bisitz 6716: border: 1px solid #BBBBBB;
1.545 albertel 6717: background: #DDDDDD;
1.861 bisitz 6718: width: 22px;
1.859 bisitz 6719: padding: 1px;
6720: margin: 0;
1.545 albertel 6721: }
6722:
1.861 bisitz 6723: table.LC_data_table tr > td.LC_docs_entry_commands,
6724: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6725: font-size: x-small;
6726: }
1.795 www 6727:
1.861 bisitz 6728: .LC_docs_entry_parameter {
6729: white-space: nowrap;
6730: }
6731:
1.544 albertel 6732: .LC_docs_copy {
1.545 albertel 6733: color: #000099;
1.544 albertel 6734: }
1.795 www 6735:
1.544 albertel 6736: .LC_docs_cut {
1.545 albertel 6737: color: #550044;
1.544 albertel 6738: }
1.795 www 6739:
1.544 albertel 6740: .LC_docs_rename {
1.545 albertel 6741: color: #009900;
1.544 albertel 6742: }
1.795 www 6743:
1.544 albertel 6744: .LC_docs_remove {
1.545 albertel 6745: color: #990000;
6746: }
6747:
1.547 albertel 6748: .LC_docs_reinit_warn,
6749: .LC_docs_ext_edit {
6750: font-size: x-small;
6751: }
6752:
1.545 albertel 6753: table.LC_docs_adddocs td,
6754: table.LC_docs_adddocs th {
6755: border: 1px solid #BBBBBB;
6756: padding: 4px;
6757: background: #DDDDDD;
1.543 albertel 6758: }
6759:
1.584 albertel 6760: table.LC_sty_begin {
6761: background: #BBFFBB;
6762: }
1.795 www 6763:
1.584 albertel 6764: table.LC_sty_end {
6765: background: #FFBBBB;
6766: }
6767:
1.589 raeburn 6768: table.LC_double_column {
1.803 bisitz 6769: border-width: 0;
1.589 raeburn 6770: border-collapse: collapse;
6771: width: 100%;
6772: padding: 2px;
6773: }
6774:
6775: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6776: top: 2px;
1.589 raeburn 6777: left: 2px;
6778: width: 47%;
6779: vertical-align: top;
6780: }
6781:
6782: table.LC_double_column tr td.LC_right_col {
6783: top: 2px;
1.779 bisitz 6784: right: 2px;
1.589 raeburn 6785: width: 47%;
6786: vertical-align: top;
6787: }
6788:
1.591 raeburn 6789: div.LC_left_float {
6790: float: left;
6791: padding-right: 5%;
1.597 albertel 6792: padding-bottom: 4px;
1.591 raeburn 6793: }
6794:
6795: div.LC_clear_float_header {
1.597 albertel 6796: padding-bottom: 2px;
1.591 raeburn 6797: }
6798:
6799: div.LC_clear_float_footer {
1.597 albertel 6800: padding-top: 10px;
1.591 raeburn 6801: clear: both;
6802: }
6803:
1.597 albertel 6804: div.LC_grade_show_user {
1.941 bisitz 6805: /* border-left: 5px solid $sidebg; */
6806: border-top: 5px solid #000000;
6807: margin: 50px 0 0 0;
1.936 bisitz 6808: padding: 15px 0 5px 10px;
1.597 albertel 6809: }
1.795 www 6810:
1.936 bisitz 6811: div.LC_grade_show_user_odd_row {
1.941 bisitz 6812: /* border-left: 5px solid #000000; */
6813: }
6814:
6815: div.LC_grade_show_user div.LC_Box {
6816: margin-right: 50px;
1.597 albertel 6817: }
6818:
6819: div.LC_grade_submissions,
6820: div.LC_grade_message_center,
1.936 bisitz 6821: div.LC_grade_info_links {
1.597 albertel 6822: margin: 5px;
6823: width: 99%;
6824: background: #FFFFFF;
6825: }
1.795 www 6826:
1.597 albertel 6827: div.LC_grade_submissions_header,
1.936 bisitz 6828: div.LC_grade_message_center_header {
1.705 tempelho 6829: font-weight: bold;
6830: font-size: large;
1.597 albertel 6831: }
1.795 www 6832:
1.597 albertel 6833: div.LC_grade_submissions_body,
1.936 bisitz 6834: div.LC_grade_message_center_body {
1.597 albertel 6835: border: 1px solid black;
6836: width: 99%;
6837: background: #FFFFFF;
6838: }
1.795 www 6839:
1.613 albertel 6840: table.LC_scantron_action {
6841: width: 100%;
6842: }
1.795 www 6843:
1.613 albertel 6844: table.LC_scantron_action tr th {
1.698 harmsja 6845: font-weight:bold;
6846: font-style:normal;
1.613 albertel 6847: }
1.795 www 6848:
1.779 bisitz 6849: .LC_edit_problem_header,
1.614 albertel 6850: div.LC_edit_problem_footer {
1.705 tempelho 6851: font-weight: normal;
6852: font-size: medium;
1.602 albertel 6853: margin: 2px;
1.1060 bisitz 6854: background-color: $sidebg;
1.600 albertel 6855: }
1.795 www 6856:
1.600 albertel 6857: div.LC_edit_problem_header,
1.602 albertel 6858: div.LC_edit_problem_header div,
1.614 albertel 6859: div.LC_edit_problem_footer,
6860: div.LC_edit_problem_footer div,
1.602 albertel 6861: div.LC_edit_problem_editxml_header,
6862: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 6863: z-index: 100;
1.600 albertel 6864: }
1.795 www 6865:
1.600 albertel 6866: div.LC_edit_problem_header_title {
1.705 tempelho 6867: font-weight: bold;
6868: font-size: larger;
1.602 albertel 6869: background: $tabbg;
6870: padding: 3px;
1.1060 bisitz 6871: margin: 0 0 5px 0;
1.602 albertel 6872: }
1.795 www 6873:
1.602 albertel 6874: table.LC_edit_problem_header_title {
6875: width: 100%;
1.600 albertel 6876: background: $tabbg;
1.602 albertel 6877: }
6878:
1.1075.2.112 raeburn 6879: div.LC_edit_actionbar {
6880: background-color: $sidebg;
6881: margin: 0;
6882: padding: 0;
6883: line-height: 200%;
1.602 albertel 6884: }
1.795 www 6885:
1.1075.2.112 raeburn 6886: div.LC_edit_actionbar div{
6887: padding: 0;
6888: margin: 0;
6889: display: inline-block;
1.600 albertel 6890: }
1.795 www 6891:
1.1075.2.34 raeburn 6892: .LC_edit_opt {
6893: padding-left: 1em;
6894: white-space: nowrap;
6895: }
6896:
1.1075.2.57 raeburn 6897: .LC_edit_problem_latexhelper{
6898: text-align: right;
6899: }
6900:
6901: #LC_edit_problem_colorful div{
6902: margin-left: 40px;
6903: }
6904:
1.1075.2.112 raeburn 6905: #LC_edit_problem_codemirror div{
6906: margin-left: 0px;
6907: }
6908:
1.911 bisitz 6909: img.stift {
1.803 bisitz 6910: border-width: 0;
6911: vertical-align: middle;
1.677 riegler 6912: }
1.680 riegler 6913:
1.923 bisitz 6914: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6915: vertical-align: top;
1.777 tempelho 6916: }
1.795 www 6917:
1.716 raeburn 6918: div.LC_createcourse {
1.911 bisitz 6919: margin: 10px 10px 10px 10px;
1.716 raeburn 6920: }
6921:
1.917 raeburn 6922: .LC_dccid {
1.1075.2.38 raeburn 6923: float: right;
1.917 raeburn 6924: margin: 0.2em 0 0 0;
6925: padding: 0;
6926: font-size: 90%;
6927: display:none;
6928: }
6929:
1.897 wenzelju 6930: ol.LC_primary_menu a:hover,
1.721 harmsja 6931: ol#LC_MenuBreadcrumbs a:hover,
6932: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6933: ul#LC_secondary_menu a:hover,
1.721 harmsja 6934: .LC_FormSectionClearButton input:hover
1.795 www 6935: ul.LC_TabContent li:hover a {
1.952 onken 6936: color:$button_hover;
1.911 bisitz 6937: text-decoration:none;
1.693 droeschl 6938: }
6939:
1.779 bisitz 6940: h1 {
1.911 bisitz 6941: padding: 0;
6942: line-height:130%;
1.693 droeschl 6943: }
1.698 harmsja 6944:
1.911 bisitz 6945: h2,
6946: h3,
6947: h4,
6948: h5,
6949: h6 {
6950: margin: 5px 0 5px 0;
6951: padding: 0;
6952: line-height:130%;
1.693 droeschl 6953: }
1.795 www 6954:
6955: .LC_hcell {
1.911 bisitz 6956: padding:3px 15px 3px 15px;
6957: margin: 0;
6958: background-color:$tabbg;
6959: color:$fontmenu;
6960: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6961: }
1.795 www 6962:
1.840 bisitz 6963: .LC_Box > .LC_hcell {
1.911 bisitz 6964: margin: 0 -10px 10px -10px;
1.835 bisitz 6965: }
6966:
1.721 harmsja 6967: .LC_noBorder {
1.911 bisitz 6968: border: 0;
1.698 harmsja 6969: }
1.693 droeschl 6970:
1.721 harmsja 6971: .LC_FormSectionClearButton input {
1.911 bisitz 6972: background-color:transparent;
6973: border: none;
6974: cursor:pointer;
6975: text-decoration:underline;
1.693 droeschl 6976: }
1.763 bisitz 6977:
6978: .LC_help_open_topic {
1.911 bisitz 6979: color: #FFFFFF;
6980: background-color: #EEEEFF;
6981: margin: 1px;
6982: padding: 4px;
6983: border: 1px solid #000033;
6984: white-space: nowrap;
6985: /* vertical-align: middle; */
1.759 neumanie 6986: }
1.693 droeschl 6987:
1.911 bisitz 6988: dl,
6989: ul,
6990: div,
6991: fieldset {
6992: margin: 10px 10px 10px 0;
6993: /* overflow: hidden; */
1.693 droeschl 6994: }
1.795 www 6995:
1.1075.2.90 raeburn 6996: article.geogebraweb div {
6997: margin: 0;
6998: }
6999:
1.838 bisitz 7000: fieldset > legend {
1.911 bisitz 7001: font-weight: bold;
7002: padding: 0 5px 0 5px;
1.838 bisitz 7003: }
7004:
1.813 bisitz 7005: #LC_nav_bar {
1.911 bisitz 7006: float: left;
1.995 raeburn 7007: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7008: margin: 0 0 2px 0;
1.807 droeschl 7009: }
7010:
1.916 droeschl 7011: #LC_realm {
7012: margin: 0.2em 0 0 0;
7013: padding: 0;
7014: font-weight: bold;
7015: text-align: center;
1.995 raeburn 7016: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7017: }
7018:
1.911 bisitz 7019: #LC_nav_bar em {
7020: font-weight: bold;
7021: font-style: normal;
1.807 droeschl 7022: }
7023:
1.897 wenzelju 7024: ol.LC_primary_menu {
1.934 droeschl 7025: margin: 0;
1.1075.2.2 raeburn 7026: padding: 0;
1.807 droeschl 7027: }
7028:
1.852 droeschl 7029: ol#LC_PathBreadcrumbs {
1.911 bisitz 7030: margin: 0;
1.693 droeschl 7031: }
7032:
1.897 wenzelju 7033: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7034: color: RGB(80, 80, 80);
7035: vertical-align: middle;
7036: text-align: left;
7037: list-style: none;
1.1075.2.112 raeburn 7038: position: relative;
1.1075.2.2 raeburn 7039: float: left;
1.1075.2.112 raeburn 7040: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7041: line-height: 1.5em;
1.1075.2.2 raeburn 7042: }
7043:
1.1075.2.113 raeburn 7044: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7045: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7046: display: block;
7047: margin: 0;
7048: padding: 0 5px 0 10px;
7049: text-decoration: none;
7050: }
7051:
1.1075.2.112 raeburn 7052: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7053: display: inline-block;
7054: width: 95%;
7055: text-align: left;
7056: }
7057:
7058: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7059: display: inline-block;
7060: width: 5%;
7061: float: right;
7062: text-align: right;
7063: font-size: 70%;
7064: }
7065:
7066: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7067: display: none;
1.1075.2.112 raeburn 7068: width: 15em;
1.1075.2.2 raeburn 7069: background-color: $data_table_light;
1.1075.2.112 raeburn 7070: position: absolute;
7071: top: 100%;
7072: }
7073:
7074: ol.LC_primary_menu ul ul {
7075: left: 100%;
7076: top: 0;
1.1075.2.2 raeburn 7077: }
7078:
1.1075.2.112 raeburn 7079: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7080: display: block;
7081: position: absolute;
7082: margin: 0;
7083: padding: 0;
1.1075.2.5 raeburn 7084: z-index: 2;
1.1075.2.2 raeburn 7085: }
7086:
7087: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7088: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7089: font-size: 90%;
1.911 bisitz 7090: vertical-align: top;
1.1075.2.2 raeburn 7091: float: none;
1.1075.2.5 raeburn 7092: border-left: 1px solid black;
7093: border-right: 1px solid black;
1.1075.2.112 raeburn 7094: /* A dark bottom border to visualize different menu options;
7095: overwritten in the create_submenu routine for the last border-bottom of the menu */
7096: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7097: }
7098:
1.1075.2.112 raeburn 7099: ol.LC_primary_menu li li p:hover {
7100: color:$button_hover;
7101: text-decoration:none;
7102: background-color:$data_table_dark;
1.1075.2.2 raeburn 7103: }
7104:
7105: ol.LC_primary_menu li li a:hover {
7106: color:$button_hover;
7107: background-color:$data_table_dark;
1.693 droeschl 7108: }
7109:
1.1075.2.112 raeburn 7110: /* Font-size equal to the size of the predecessors*/
7111: ol.LC_primary_menu li:hover li li {
7112: font-size: 100%;
7113: }
7114:
1.897 wenzelju 7115: ol.LC_primary_menu li img {
1.911 bisitz 7116: vertical-align: bottom;
1.934 droeschl 7117: height: 1.1em;
1.1075.2.3 raeburn 7118: margin: 0.2em 0 0 0;
1.693 droeschl 7119: }
7120:
1.897 wenzelju 7121: ol.LC_primary_menu a {
1.911 bisitz 7122: color: RGB(80, 80, 80);
7123: text-decoration: none;
1.693 droeschl 7124: }
1.795 www 7125:
1.949 droeschl 7126: ol.LC_primary_menu a.LC_new_message {
7127: font-weight:bold;
7128: color: darkred;
7129: }
7130:
1.975 raeburn 7131: ol.LC_docs_parameters {
7132: margin-left: 0;
7133: padding: 0;
7134: list-style: none;
7135: }
7136:
7137: ol.LC_docs_parameters li {
7138: margin: 0;
7139: padding-right: 20px;
7140: display: inline;
7141: }
7142:
1.976 raeburn 7143: ol.LC_docs_parameters li:before {
7144: content: "\\002022 \\0020";
7145: }
7146:
7147: li.LC_docs_parameters_title {
7148: font-weight: bold;
7149: }
7150:
7151: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7152: content: "";
7153: }
7154:
1.897 wenzelju 7155: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7156: clear: right;
1.911 bisitz 7157: color: $fontmenu;
7158: background: $tabbg;
7159: list-style: none;
7160: padding: 0;
7161: margin: 0;
7162: width: 100%;
1.995 raeburn 7163: text-align: left;
1.1075.2.4 raeburn 7164: float: left;
1.808 droeschl 7165: }
7166:
1.897 wenzelju 7167: ul#LC_secondary_menu li {
1.911 bisitz 7168: font-weight: bold;
7169: line-height: 1.8em;
7170: border-right: 1px solid black;
1.1075.2.4 raeburn 7171: float: left;
7172: }
7173:
7174: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7175: background-color: $data_table_light;
7176: }
7177:
7178: ul#LC_secondary_menu li a {
7179: padding: 0 0.8em;
7180: }
7181:
7182: ul#LC_secondary_menu li ul {
7183: display: none;
7184: }
7185:
7186: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7187: display: block;
7188: position: absolute;
7189: margin: 0;
7190: padding: 0;
7191: list-style:none;
7192: float: none;
7193: background-color: $data_table_light;
1.1075.2.5 raeburn 7194: z-index: 2;
1.1075.2.10 raeburn 7195: margin-left: -1px;
1.1075.2.4 raeburn 7196: }
7197:
7198: ul#LC_secondary_menu li ul li {
7199: font-size: 90%;
7200: vertical-align: top;
7201: border-left: 1px solid black;
7202: border-right: 1px solid black;
1.1075.2.33 raeburn 7203: background-color: $data_table_light;
1.1075.2.4 raeburn 7204: list-style:none;
7205: float: none;
7206: }
7207:
7208: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7209: background-color: $data_table_dark;
1.807 droeschl 7210: }
7211:
1.847 tempelho 7212: ul.LC_TabContent {
1.911 bisitz 7213: display:block;
7214: background: $sidebg;
7215: border-bottom: solid 1px $lg_border_color;
7216: list-style:none;
1.1020 raeburn 7217: margin: -1px -10px 0 -10px;
1.911 bisitz 7218: padding: 0;
1.693 droeschl 7219: }
7220:
1.795 www 7221: ul.LC_TabContent li,
7222: ul.LC_TabContentBigger li {
1.911 bisitz 7223: float:left;
1.741 harmsja 7224: }
1.795 www 7225:
1.897 wenzelju 7226: ul#LC_secondary_menu li a {
1.911 bisitz 7227: color: $fontmenu;
7228: text-decoration: none;
1.693 droeschl 7229: }
1.795 www 7230:
1.721 harmsja 7231: ul.LC_TabContent {
1.952 onken 7232: min-height:20px;
1.721 harmsja 7233: }
1.795 www 7234:
7235: ul.LC_TabContent li {
1.911 bisitz 7236: vertical-align:middle;
1.959 onken 7237: padding: 0 16px 0 10px;
1.911 bisitz 7238: background-color:$tabbg;
7239: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7240: border-left: solid 1px $font;
1.721 harmsja 7241: }
1.795 www 7242:
1.847 tempelho 7243: ul.LC_TabContent .right {
1.911 bisitz 7244: float:right;
1.847 tempelho 7245: }
7246:
1.911 bisitz 7247: ul.LC_TabContent li a,
7248: ul.LC_TabContent li {
7249: color:rgb(47,47,47);
7250: text-decoration:none;
7251: font-size:95%;
7252: font-weight:bold;
1.952 onken 7253: min-height:20px;
7254: }
7255:
1.959 onken 7256: ul.LC_TabContent li a:hover,
7257: ul.LC_TabContent li a:focus {
1.952 onken 7258: color: $button_hover;
1.959 onken 7259: background:none;
7260: outline:none;
1.952 onken 7261: }
7262:
7263: ul.LC_TabContent li:hover {
7264: color: $button_hover;
7265: cursor:pointer;
1.721 harmsja 7266: }
1.795 www 7267:
1.911 bisitz 7268: ul.LC_TabContent li.active {
1.952 onken 7269: color: $font;
1.911 bisitz 7270: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7271: border-bottom:solid 1px #FFFFFF;
7272: cursor: default;
1.744 ehlerst 7273: }
1.795 www 7274:
1.959 onken 7275: ul.LC_TabContent li.active a {
7276: color:$font;
7277: background:#FFFFFF;
7278: outline: none;
7279: }
1.1047 raeburn 7280:
7281: ul.LC_TabContent li.goback {
7282: float: left;
7283: border-left: none;
7284: }
7285:
1.870 tempelho 7286: #maincoursedoc {
1.911 bisitz 7287: clear:both;
1.870 tempelho 7288: }
7289:
7290: ul.LC_TabContentBigger {
1.911 bisitz 7291: display:block;
7292: list-style:none;
7293: padding: 0;
1.870 tempelho 7294: }
7295:
1.795 www 7296: ul.LC_TabContentBigger li {
1.911 bisitz 7297: vertical-align:bottom;
7298: height: 30px;
7299: font-size:110%;
7300: font-weight:bold;
7301: color: #737373;
1.841 tempelho 7302: }
7303:
1.957 onken 7304: ul.LC_TabContentBigger li.active {
7305: position: relative;
7306: top: 1px;
7307: }
7308:
1.870 tempelho 7309: ul.LC_TabContentBigger li a {
1.911 bisitz 7310: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7311: height: 30px;
7312: line-height: 30px;
7313: text-align: center;
7314: display: block;
7315: text-decoration: none;
1.958 onken 7316: outline: none;
1.741 harmsja 7317: }
1.795 www 7318:
1.870 tempelho 7319: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7320: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7321: color:$font;
1.744 ehlerst 7322: }
1.795 www 7323:
1.870 tempelho 7324: ul.LC_TabContentBigger li b {
1.911 bisitz 7325: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7326: display: block;
7327: float: left;
7328: padding: 0 30px;
1.957 onken 7329: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7330: }
7331:
1.956 onken 7332: ul.LC_TabContentBigger li:hover b {
7333: color:$button_hover;
7334: }
7335:
1.870 tempelho 7336: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7337: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7338: color:$font;
1.957 onken 7339: border: 0;
1.741 harmsja 7340: }
1.693 droeschl 7341:
1.870 tempelho 7342:
1.862 bisitz 7343: ul.LC_CourseBreadcrumbs {
7344: background: $sidebg;
1.1020 raeburn 7345: height: 2em;
1.862 bisitz 7346: padding-left: 10px;
1.1020 raeburn 7347: margin: 0;
1.862 bisitz 7348: list-style-position: inside;
7349: }
7350:
1.911 bisitz 7351: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7352: ol#LC_PathBreadcrumbs {
1.911 bisitz 7353: padding-left: 10px;
7354: margin: 0;
1.933 droeschl 7355: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7356: }
7357:
1.911 bisitz 7358: ol#LC_MenuBreadcrumbs li,
7359: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7360: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7361: display: inline;
1.933 droeschl 7362: white-space: normal;
1.693 droeschl 7363: }
7364:
1.823 bisitz 7365: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7366: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7367: text-decoration: none;
7368: font-size:90%;
1.693 droeschl 7369: }
1.795 www 7370:
1.969 droeschl 7371: ol#LC_MenuBreadcrumbs h1 {
7372: display: inline;
7373: font-size: 90%;
7374: line-height: 2.5em;
7375: margin: 0;
7376: padding: 0;
7377: }
7378:
1.795 www 7379: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7380: text-decoration:none;
7381: font-size:100%;
7382: font-weight:bold;
1.693 droeschl 7383: }
1.795 www 7384:
1.840 bisitz 7385: .LC_Box {
1.911 bisitz 7386: border: solid 1px $lg_border_color;
7387: padding: 0 10px 10px 10px;
1.746 neumanie 7388: }
1.795 www 7389:
1.1020 raeburn 7390: .LC_DocsBox {
7391: border: solid 1px $lg_border_color;
7392: padding: 0 0 10px 10px;
7393: }
7394:
1.795 www 7395: .LC_AboutMe_Image {
1.911 bisitz 7396: float:left;
7397: margin-right:10px;
1.747 neumanie 7398: }
1.795 www 7399:
7400: .LC_Clear_AboutMe_Image {
1.911 bisitz 7401: clear:left;
1.747 neumanie 7402: }
1.795 www 7403:
1.721 harmsja 7404: dl.LC_ListStyleClean dt {
1.911 bisitz 7405: padding-right: 5px;
7406: display: table-header-group;
1.693 droeschl 7407: }
7408:
1.721 harmsja 7409: dl.LC_ListStyleClean dd {
1.911 bisitz 7410: display: table-row;
1.693 droeschl 7411: }
7412:
1.721 harmsja 7413: .LC_ListStyleClean,
7414: .LC_ListStyleSimple,
7415: .LC_ListStyleNormal,
1.795 www 7416: .LC_ListStyleSpecial {
1.911 bisitz 7417: /* display:block; */
7418: list-style-position: inside;
7419: list-style-type: none;
7420: overflow: hidden;
7421: padding: 0;
1.693 droeschl 7422: }
7423:
1.721 harmsja 7424: .LC_ListStyleSimple li,
7425: .LC_ListStyleSimple dd,
7426: .LC_ListStyleNormal li,
7427: .LC_ListStyleNormal dd,
7428: .LC_ListStyleSpecial li,
1.795 www 7429: .LC_ListStyleSpecial dd {
1.911 bisitz 7430: margin: 0;
7431: padding: 5px 5px 5px 10px;
7432: clear: both;
1.693 droeschl 7433: }
7434:
1.721 harmsja 7435: .LC_ListStyleClean li,
7436: .LC_ListStyleClean dd {
1.911 bisitz 7437: padding-top: 0;
7438: padding-bottom: 0;
1.693 droeschl 7439: }
7440:
1.721 harmsja 7441: .LC_ListStyleSimple dd,
1.795 www 7442: .LC_ListStyleSimple li {
1.911 bisitz 7443: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7444: }
7445:
1.721 harmsja 7446: .LC_ListStyleSpecial li,
7447: .LC_ListStyleSpecial dd {
1.911 bisitz 7448: list-style-type: none;
7449: background-color: RGB(220, 220, 220);
7450: margin-bottom: 4px;
1.693 droeschl 7451: }
7452:
1.721 harmsja 7453: table.LC_SimpleTable {
1.911 bisitz 7454: margin:5px;
7455: border:solid 1px $lg_border_color;
1.795 www 7456: }
1.693 droeschl 7457:
1.721 harmsja 7458: table.LC_SimpleTable tr {
1.911 bisitz 7459: padding: 0;
7460: border:solid 1px $lg_border_color;
1.693 droeschl 7461: }
1.795 www 7462:
7463: table.LC_SimpleTable thead {
1.911 bisitz 7464: background:rgb(220,220,220);
1.693 droeschl 7465: }
7466:
1.721 harmsja 7467: div.LC_columnSection {
1.911 bisitz 7468: display: block;
7469: clear: both;
7470: overflow: hidden;
7471: margin: 0;
1.693 droeschl 7472: }
7473:
1.721 harmsja 7474: div.LC_columnSection>* {
1.911 bisitz 7475: float: left;
7476: margin: 10px 20px 10px 0;
7477: overflow:hidden;
1.693 droeschl 7478: }
1.721 harmsja 7479:
1.795 www 7480: table em {
1.911 bisitz 7481: font-weight: bold;
7482: font-style: normal;
1.748 schulted 7483: }
1.795 www 7484:
1.779 bisitz 7485: table.LC_tableBrowseRes,
1.795 www 7486: table.LC_tableOfContent {
1.911 bisitz 7487: border:none;
7488: border-spacing: 1px;
7489: padding: 3px;
7490: background-color: #FFFFFF;
7491: font-size: 90%;
1.753 droeschl 7492: }
1.789 droeschl 7493:
1.911 bisitz 7494: table.LC_tableOfContent {
7495: border-collapse: collapse;
1.789 droeschl 7496: }
7497:
1.771 droeschl 7498: table.LC_tableBrowseRes a,
1.768 schulted 7499: table.LC_tableOfContent a {
1.911 bisitz 7500: background-color: transparent;
7501: text-decoration: none;
1.753 droeschl 7502: }
7503:
1.795 www 7504: table.LC_tableOfContent img {
1.911 bisitz 7505: border: none;
7506: height: 1.3em;
7507: vertical-align: text-bottom;
7508: margin-right: 0.3em;
1.753 droeschl 7509: }
1.757 schulted 7510:
1.795 www 7511: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7512: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7513: }
7514:
1.795 www 7515: a#LC_content_toolbar_everything {
1.911 bisitz 7516: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7517: }
7518:
1.795 www 7519: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7520: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7521: }
7522:
1.795 www 7523: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7524: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7525: }
7526:
1.795 www 7527: a#LC_content_toolbar_changefolder {
1.911 bisitz 7528: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7529: }
7530:
1.795 www 7531: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7532: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7533: }
7534:
1.1043 raeburn 7535: a#LC_content_toolbar_edittoplevel {
7536: background-image:url(/res/adm/pages/edittoplevel.gif);
7537: }
7538:
1.795 www 7539: ul#LC_toolbar li a:hover {
1.911 bisitz 7540: background-position: bottom center;
1.757 schulted 7541: }
7542:
1.795 www 7543: ul#LC_toolbar {
1.911 bisitz 7544: padding: 0;
7545: margin: 2px;
7546: list-style:none;
7547: position:relative;
7548: background-color:white;
1.1075.2.9 raeburn 7549: overflow: auto;
1.757 schulted 7550: }
7551:
1.795 www 7552: ul#LC_toolbar li {
1.911 bisitz 7553: border:1px solid white;
7554: padding: 0;
7555: margin: 0;
7556: float: left;
7557: display:inline;
7558: vertical-align:middle;
1.1075.2.9 raeburn 7559: white-space: nowrap;
1.911 bisitz 7560: }
1.757 schulted 7561:
1.783 amueller 7562:
1.795 www 7563: a.LC_toolbarItem {
1.911 bisitz 7564: display:block;
7565: padding: 0;
7566: margin: 0;
7567: height: 32px;
7568: width: 32px;
7569: color:white;
7570: border: none;
7571: background-repeat:no-repeat;
7572: background-color:transparent;
1.757 schulted 7573: }
7574:
1.915 droeschl 7575: ul.LC_funclist {
7576: margin: 0;
7577: padding: 0.5em 1em 0.5em 0;
7578: }
7579:
1.933 droeschl 7580: ul.LC_funclist > li:first-child {
7581: font-weight:bold;
7582: margin-left:0.8em;
7583: }
7584:
1.915 droeschl 7585: ul.LC_funclist + ul.LC_funclist {
7586: /*
7587: left border as a seperator if we have more than
7588: one list
7589: */
7590: border-left: 1px solid $sidebg;
7591: /*
7592: this hides the left border behind the border of the
7593: outer box if element is wrapped to the next 'line'
7594: */
7595: margin-left: -1px;
7596: }
7597:
1.843 bisitz 7598: ul.LC_funclist li {
1.915 droeschl 7599: display: inline;
1.782 bisitz 7600: white-space: nowrap;
1.915 droeschl 7601: margin: 0 0 0 25px;
7602: line-height: 150%;
1.782 bisitz 7603: }
7604:
1.974 wenzelju 7605: .LC_hidden {
7606: display: none;
7607: }
7608:
1.1030 www 7609: .LCmodal-overlay {
7610: position:fixed;
7611: top:0;
7612: right:0;
7613: bottom:0;
7614: left:0;
7615: height:100%;
7616: width:100%;
7617: margin:0;
7618: padding:0;
7619: background:#999;
7620: opacity:.75;
7621: filter: alpha(opacity=75);
7622: -moz-opacity: 0.75;
7623: z-index:101;
7624: }
7625:
7626: * html .LCmodal-overlay {
7627: position: absolute;
7628: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7629: }
7630:
7631: .LCmodal-window {
7632: position:fixed;
7633: top:50%;
7634: left:50%;
7635: margin:0;
7636: padding:0;
7637: z-index:102;
7638: }
7639:
7640: * html .LCmodal-window {
7641: position:absolute;
7642: }
7643:
7644: .LCclose-window {
7645: position:absolute;
7646: width:32px;
7647: height:32px;
7648: right:8px;
7649: top:8px;
7650: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7651: text-indent:-99999px;
7652: overflow:hidden;
7653: cursor:pointer;
7654: }
7655:
1.1075.2.17 raeburn 7656: /*
7657: styles used by TTH when "Default set of options to pass to tth/m
7658: when converting TeX" in course settings has been set
7659:
7660: option passed: -t
7661:
7662: */
7663:
7664: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7665: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7666: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7667: td div.norm {line-height:normal;}
7668:
7669: /*
7670: option passed -y3
7671: */
7672:
7673: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7674: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7675: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7676:
1.1075.2.121 raeburn 7677: #LC_minitab_header {
7678: float:left;
7679: width:100%;
7680: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
7681: font-size:93%;
7682: line-height:normal;
7683: margin: 0.5em 0 0.5em 0;
7684: }
7685: #LC_minitab_header ul {
7686: margin:0;
7687: padding:10px 10px 0;
7688: list-style:none;
7689: }
7690: #LC_minitab_header li {
7691: float:left;
7692: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
7693: margin:0;
7694: padding:0 0 0 9px;
7695: }
7696: #LC_minitab_header a {
7697: display:block;
7698: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
7699: padding:5px 15px 4px 6px;
7700: }
7701: #LC_minitab_header #LC_current_minitab {
7702: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
7703: }
7704: #LC_minitab_header #LC_current_minitab a {
7705: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
7706: padding-bottom:5px;
7707: }
7708:
7709:
1.343 albertel 7710: END
7711: }
7712:
1.306 albertel 7713: =pod
7714:
7715: =item * &headtag()
7716:
7717: Returns a uniform footer for LON-CAPA web pages.
7718:
1.307 albertel 7719: Inputs: $title - optional title for the head
7720: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7721: $args - optional arguments
1.319 albertel 7722: force_register - if is true call registerurl so the remote is
7723: informed
1.415 albertel 7724: redirect -> array ref of
7725: 1- seconds before redirect occurs
7726: 2- url to redirect to
7727: 3- whether the side effect should occur
1.315 albertel 7728: (side effect of setting
7729: $env{'internal.head.redirect'} to the url
7730: redirected too)
1.352 albertel 7731: domain -> force to color decorate a page for a specific
7732: domain
7733: function -> force usage of a specific rolish color scheme
7734: bgcolor -> override the default page bgcolor
1.460 albertel 7735: no_auto_mt_title
7736: -> prevent &mt()ing the title arg
1.464 albertel 7737:
1.306 albertel 7738: =cut
7739:
7740: sub headtag {
1.313 albertel 7741: my ($title,$head_extra,$args) = @_;
1.306 albertel 7742:
1.363 albertel 7743: my $function = $args->{'function'} || &get_users_function();
7744: my $domain = $args->{'domain'} || &determinedomain();
7745: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7746: my $httphost = $args->{'use_absolute'};
1.418 albertel 7747: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7748: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7749: #time(),
1.418 albertel 7750: $env{'environment.color.timestamp'},
1.363 albertel 7751: $function,$domain,$bgcolor);
7752:
1.369 www 7753: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7754:
1.308 albertel 7755: my $result =
7756: '<head>'.
1.1075.2.56 raeburn 7757: &font_settings($args);
1.319 albertel 7758:
1.1075.2.72 raeburn 7759: my $inhibitprint;
7760: if ($args->{'print_suppress'}) {
7761: $inhibitprint = &print_suppression();
7762: }
1.1064 raeburn 7763:
1.461 albertel 7764: if (!$args->{'frameset'}) {
7765: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7766: }
1.1075.2.12 raeburn 7767: if ($args->{'force_register'}) {
7768: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7769: }
1.436 albertel 7770: if (!$args->{'no_nav_bar'}
7771: && !$args->{'only_body'}
7772: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7773: $result .= &help_menu_js($httphost);
1.1032 www 7774: $result.=&modal_window();
1.1038 www 7775: $result.=&togglebox_script();
1.1034 www 7776: $result.=&wishlist_window();
1.1041 www 7777: $result.=&LCprogressbarUpdate_script();
1.1034 www 7778: } else {
7779: if ($args->{'add_modal'}) {
7780: $result.=&modal_window();
7781: }
7782: if ($args->{'add_wishlist'}) {
7783: $result.=&wishlist_window();
7784: }
1.1038 www 7785: if ($args->{'add_togglebox'}) {
7786: $result.=&togglebox_script();
7787: }
1.1041 www 7788: if ($args->{'add_progressbar'}) {
7789: $result.=&LCprogressbarUpdate_script();
7790: }
1.436 albertel 7791: }
1.314 albertel 7792: if (ref($args->{'redirect'})) {
1.414 albertel 7793: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7794: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7795: if (!$inhibit_continue) {
7796: $env{'internal.head.redirect'} = $url;
7797: }
1.313 albertel 7798: $result.=<<ADDMETA
7799: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7800: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7801: ADDMETA
1.1075.2.89 raeburn 7802: } else {
7803: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7804: my $requrl = $env{'request.uri'};
7805: if ($requrl eq '') {
7806: $requrl = $ENV{'REQUEST_URI'};
7807: $requrl =~ s/\?.+$//;
7808: }
7809: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7810: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7811: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7812: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7813: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7814: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7815: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7816: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7817: if ($domdefs{'offloadnow'}{$lonhost}) {
7818: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7819: if (($newserver) && ($newserver ne $lonhost)) {
7820: my $numsec = 5;
7821: my $timeout = $numsec * 1000;
7822: my ($newurl,$locknum,%locks,$msg);
7823: if ($env{'request.role.adv'}) {
7824: ($locknum,%locks) = &Apache::lonnet::get_locks();
7825: }
7826: my $disable_submit = 0;
7827: if ($requrl =~ /$LONCAPA::assess_re/) {
7828: $disable_submit = 1;
7829: }
7830: if ($locknum) {
7831: my @lockinfo = sort(values(%locks));
7832: $msg = &mt('Once the following tasks are complete: ')."\\n".
7833: join(", ",sort(values(%locks)))."\\n".
7834: &mt('your session will be transferred to a different server, after you click "Roles".');
7835: } else {
7836: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7837: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7838: }
7839: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7840: $newurl = '/adm/switchserver?otherserver='.$newserver;
7841: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7842: $newurl .= '&role='.$env{'request.role'};
7843: }
7844: if ($env{'request.symb'}) {
7845: $newurl .= '&symb='.$env{'request.symb'};
7846: } else {
7847: $newurl .= '&origurl='.$requrl;
7848: }
7849: }
1.1075.2.98 raeburn 7850: &js_escape(\$msg);
1.1075.2.89 raeburn 7851: $result.=<<OFFLOAD
7852: <meta http-equiv="pragma" content="no-cache" />
7853: <script type="text/javascript">
1.1075.2.92 raeburn 7854: // <![CDATA[
1.1075.2.89 raeburn 7855: function LC_Offload_Now() {
7856: var dest = "$newurl";
7857: if (dest != '') {
7858: window.location.href="$newurl";
7859: }
7860: }
1.1075.2.92 raeburn 7861: \$(document).ready(function () {
7862: window.alert('$msg');
7863: if ($disable_submit) {
1.1075.2.89 raeburn 7864: \$(".LC_hwk_submit").prop("disabled", true);
7865: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 7866: }
7867: setTimeout('LC_Offload_Now()', $timeout);
7868: });
7869: // ]]>
1.1075.2.89 raeburn 7870: </script>
7871: OFFLOAD
7872: }
7873: }
7874: }
7875: }
7876: }
7877: }
1.313 albertel 7878: }
1.306 albertel 7879: if (!defined($title)) {
7880: $title = 'The LearningOnline Network with CAPA';
7881: }
1.460 albertel 7882: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7883: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7884: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7885: if (!$args->{'frameset'}) {
7886: $result .= ' /';
7887: }
7888: $result .= '>'
1.1064 raeburn 7889: .$inhibitprint
1.414 albertel 7890: .$head_extra;
1.1075.2.108 raeburn 7891: my $clientmobile;
7892: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
7893: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
7894: } else {
7895: $clientmobile = $env{'browser.mobile'};
7896: }
7897: if ($clientmobile) {
1.1075.2.42 raeburn 7898: $result .= '
7899: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7900: <meta name="apple-mobile-web-app-capable" content="yes" />';
7901: }
1.1075.2.126 raeburn 7902: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 7903: return $result.'</head>';
1.306 albertel 7904: }
7905:
7906: =pod
7907:
1.340 albertel 7908: =item * &font_settings()
7909:
7910: Returns neccessary <meta> to set the proper encoding
7911:
1.1075.2.56 raeburn 7912: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7913:
7914: =cut
7915:
7916: sub font_settings {
1.1075.2.56 raeburn 7917: my ($args) = @_;
1.340 albertel 7918: my $headerstring='';
1.1075.2.56 raeburn 7919: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7920: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7921: $headerstring.=
1.1075.2.61 raeburn 7922: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7923: if (!$args->{'frameset'}) {
7924: $headerstring.= ' /';
7925: }
7926: $headerstring .= '>'."\n";
1.340 albertel 7927: }
7928: return $headerstring;
7929: }
7930:
1.341 albertel 7931: =pod
7932:
1.1064 raeburn 7933: =item * &print_suppression()
7934:
7935: In course context returns css which causes the body to be blank when media="print",
7936: if printout generation is unavailable for the current resource.
7937:
7938: This could be because:
7939:
7940: (a) printstartdate is in the future
7941:
7942: (b) printenddate is in the past
7943:
7944: (c) there is an active exam block with "printout"
7945: functionality blocked
7946:
7947: Users with pav, pfo or evb privileges are exempt.
7948:
7949: Inputs: none
7950:
7951: =cut
7952:
7953:
7954: sub print_suppression {
7955: my $noprint;
7956: if ($env{'request.course.id'}) {
7957: my $scope = $env{'request.course.id'};
7958: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7959: (&Apache::lonnet::allowed('pfo',$scope))) {
7960: return;
7961: }
7962: if ($env{'request.course.sec'} ne '') {
7963: $scope .= "/$env{'request.course.sec'}";
7964: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7965: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7966: return;
1.1064 raeburn 7967: }
7968: }
7969: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7970: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 7971: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7972: if ($blocked) {
7973: my $checkrole = "cm./$cdom/$cnum";
7974: if ($env{'request.course.sec'} ne '') {
7975: $checkrole .= "/$env{'request.course.sec'}";
7976: }
7977: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7978: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7979: $noprint = 1;
7980: }
7981: }
7982: unless ($noprint) {
7983: my $symb = &Apache::lonnet::symbread();
7984: if ($symb ne '') {
7985: my $navmap = Apache::lonnavmaps::navmap->new();
7986: if (ref($navmap)) {
7987: my $res = $navmap->getBySymb($symb);
7988: if (ref($res)) {
7989: if (!$res->resprintable()) {
7990: $noprint = 1;
7991: }
7992: }
7993: }
7994: }
7995: }
7996: if ($noprint) {
7997: return <<"ENDSTYLE";
7998: <style type="text/css" media="print">
7999: body { display:none }
8000: </style>
8001: ENDSTYLE
8002: }
8003: }
8004: return;
8005: }
8006:
8007: =pod
8008:
1.341 albertel 8009: =item * &xml_begin()
8010:
8011: Returns the needed doctype and <html>
8012:
8013: Inputs: none
8014:
8015: =cut
8016:
8017: sub xml_begin {
1.1075.2.61 raeburn 8018: my ($is_frameset) = @_;
1.341 albertel 8019: my $output='';
8020:
8021: if ($env{'browser.mathml'}) {
8022: $output='<?xml version="1.0"?>'
8023: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8024: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8025:
8026: # .'<!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">] >'
8027: .'<!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">'
8028: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8029: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8030: } elsif ($is_frameset) {
8031: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8032: '<html>'."\n";
1.341 albertel 8033: } else {
1.1075.2.61 raeburn 8034: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8035: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8036: }
8037: return $output;
8038: }
1.340 albertel 8039:
8040: =pod
8041:
1.306 albertel 8042: =item * &start_page()
8043:
8044: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8045:
1.648 raeburn 8046: Inputs:
8047:
8048: =over 4
8049:
8050: $title - optional title for the page
8051:
8052: $head_extra - optional extra HTML to incude inside the <head>
8053:
8054: $args - additional optional args supported are:
8055:
8056: =over 8
8057:
8058: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8059: arg on
1.814 bisitz 8060: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8061: add_entries -> additional attributes to add to the <body>
8062: domain -> force to color decorate a page for a
1.317 albertel 8063: specific domain
1.648 raeburn 8064: function -> force usage of a specific rolish color
1.317 albertel 8065: scheme
1.648 raeburn 8066: redirect -> see &headtag()
8067: bgcolor -> override the default page bg color
8068: js_ready -> return a string ready for being used in
1.317 albertel 8069: a javascript writeln
1.648 raeburn 8070: html_encode -> return a string ready for being used in
1.320 albertel 8071: a html attribute
1.648 raeburn 8072: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8073: $forcereg arg
1.648 raeburn 8074: frameset -> if true will start with a <frameset>
1.330 albertel 8075: rather than <body>
1.648 raeburn 8076: skip_phases -> hash ref of
1.338 albertel 8077: head -> skip the <html><head> generation
8078: body -> skip all <body> generation
1.1075.2.12 raeburn 8079: no_inline_link -> if true and in remote mode, don't show the
8080: 'Switch To Inline Menu' link
1.648 raeburn 8081: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8082: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8083: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8084: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8085: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8086: group -> includes the current group, if page is for a
8087: specific group
1.361 albertel 8088:
1.648 raeburn 8089: =back
1.460 albertel 8090:
1.648 raeburn 8091: =back
1.562 albertel 8092:
1.306 albertel 8093: =cut
8094:
8095: sub start_page {
1.309 albertel 8096: my ($title,$head_extra,$args) = @_;
1.318 albertel 8097: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8098:
1.315 albertel 8099: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8100: my ($result,@advtools);
1.964 droeschl 8101:
1.338 albertel 8102: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8103: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8104: }
8105:
8106: if (! exists($args->{'skip_phases'}{'body'}) ) {
8107: if ($args->{'frameset'}) {
8108: my $attr_string = &make_attr_string($args->{'force_register'},
8109: $args->{'add_entries'});
8110: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8111: } else {
8112: $result .=
8113: &bodytag($title,
8114: $args->{'function'}, $args->{'add_entries'},
8115: $args->{'only_body'}, $args->{'domain'},
8116: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8117: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8118: $args, \@advtools);
1.831 bisitz 8119: }
1.330 albertel 8120: }
1.338 albertel 8121:
1.315 albertel 8122: if ($args->{'js_ready'}) {
1.713 kaisler 8123: $result = &js_ready($result);
1.315 albertel 8124: }
1.320 albertel 8125: if ($args->{'html_encode'}) {
1.713 kaisler 8126: $result = &html_encode($result);
8127: }
8128:
1.813 bisitz 8129: # Preparation for new and consistent functionlist at top of screen
8130: # if ($args->{'functionlist'}) {
8131: # $result .= &build_functionlist();
8132: #}
8133:
1.964 droeschl 8134: # Don't add anything more if only_body wanted or in const space
8135: return $result if $args->{'only_body'}
8136: || $env{'request.state'} eq 'construct';
1.813 bisitz 8137:
8138: #Breadcrumbs
1.758 kaisler 8139: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8140: &Apache::lonhtmlcommon::clear_breadcrumbs();
8141: #if any br links exists, add them to the breadcrumbs
8142: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8143: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8144: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8145: }
8146: }
1.1075.2.19 raeburn 8147: # if @advtools array contains items add then to the breadcrumbs
8148: if (@advtools > 0) {
8149: &Apache::lonmenu::advtools_crumbs(@advtools);
8150: }
1.1075.2.123 raeburn 8151: my $menulink;
8152: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8153: if (exists($args->{'bread_crumbs_nomenu'})) {
8154: $menulink = 0;
8155: } else {
8156: undef($menulink);
8157: }
1.758 kaisler 8158: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8159: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8160: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8161: }else{
1.1075.2.123 raeburn 8162: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8163: }
1.1075.2.24 raeburn 8164: } elsif (($env{'environment.remote'} eq 'on') &&
8165: ($env{'form.inhibitmenu'} ne 'yes') &&
8166: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8167: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8168: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8169: }
1.315 albertel 8170: return $result;
1.306 albertel 8171: }
8172:
8173: sub end_page {
1.315 albertel 8174: my ($args) = @_;
8175: $env{'internal.end_page'}++;
1.330 albertel 8176: my $result;
1.335 albertel 8177: if ($args->{'discussion'}) {
8178: my ($target,$parser);
8179: if (ref($args->{'discussion'})) {
8180: ($target,$parser) =($args->{'discussion'}{'target'},
8181: $args->{'discussion'}{'parser'});
8182: }
8183: $result .= &Apache::lonxml::xmlend($target,$parser);
8184: }
1.330 albertel 8185: if ($args->{'frameset'}) {
8186: $result .= '</frameset>';
8187: } else {
1.635 raeburn 8188: $result .= &endbodytag($args);
1.330 albertel 8189: }
1.1075.2.6 raeburn 8190: unless ($args->{'notbody'}) {
8191: $result .= "\n</html>";
8192: }
1.330 albertel 8193:
1.315 albertel 8194: if ($args->{'js_ready'}) {
1.317 albertel 8195: $result = &js_ready($result);
1.315 albertel 8196: }
1.335 albertel 8197:
1.320 albertel 8198: if ($args->{'html_encode'}) {
8199: $result = &html_encode($result);
8200: }
1.335 albertel 8201:
1.315 albertel 8202: return $result;
8203: }
8204:
1.1034 www 8205: sub wishlist_window {
8206: return(<<'ENDWISHLIST');
1.1046 raeburn 8207: <script type="text/javascript">
1.1034 www 8208: // <![CDATA[
8209: // <!-- BEGIN LON-CAPA Internal
8210: function set_wishlistlink(title, path) {
8211: if (!title) {
8212: title = document.title;
8213: title = title.replace(/^LON-CAPA /,'');
8214: }
1.1075.2.65 raeburn 8215: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8216: title = title.replace("'","\\\'");
1.1034 www 8217: if (!path) {
8218: path = location.pathname;
8219: }
1.1075.2.65 raeburn 8220: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8221: path = path.replace("'","\\\'");
1.1034 www 8222: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8223: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8224: }
8225: // END LON-CAPA Internal -->
8226: // ]]>
8227: </script>
8228: ENDWISHLIST
8229: }
8230:
1.1030 www 8231: sub modal_window {
8232: return(<<'ENDMODAL');
1.1046 raeburn 8233: <script type="text/javascript">
1.1030 www 8234: // <![CDATA[
8235: // <!-- BEGIN LON-CAPA Internal
8236: var modalWindow = {
8237: parent:"body",
8238: windowId:null,
8239: content:null,
8240: width:null,
8241: height:null,
8242: close:function()
8243: {
8244: $(".LCmodal-window").remove();
8245: $(".LCmodal-overlay").remove();
8246: },
8247: open:function()
8248: {
8249: var modal = "";
8250: modal += "<div class=\"LCmodal-overlay\"></div>";
8251: 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;\">";
8252: modal += this.content;
8253: modal += "</div>";
8254:
8255: $(this.parent).append(modal);
8256:
8257: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8258: $(".LCclose-window").click(function(){modalWindow.close();});
8259: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8260: }
8261: };
1.1075.2.42 raeburn 8262: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8263: {
1.1075.2.119 raeburn 8264: source = source.replace(/'/g,"'");
1.1030 www 8265: modalWindow.windowId = "myModal";
8266: modalWindow.width = width;
8267: modalWindow.height = height;
1.1075.2.80 raeburn 8268: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8269: modalWindow.open();
1.1075.2.87 raeburn 8270: };
1.1030 www 8271: // END LON-CAPA Internal -->
8272: // ]]>
8273: </script>
8274: ENDMODAL
8275: }
8276:
8277: sub modal_link {
1.1075.2.42 raeburn 8278: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8279: unless ($width) { $width=480; }
8280: unless ($height) { $height=400; }
1.1031 www 8281: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8282: unless ($transparency) { $transparency='true'; }
8283:
1.1074 raeburn 8284: my $target_attr;
8285: if (defined($target)) {
8286: $target_attr = 'target="'.$target.'"';
8287: }
8288: return <<"ENDLINK";
1.1075.2.42 raeburn 8289: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8290: $linktext</a>
8291: ENDLINK
1.1030 www 8292: }
8293:
1.1032 www 8294: sub modal_adhoc_script {
8295: my ($funcname,$width,$height,$content)=@_;
8296: return (<<ENDADHOC);
1.1046 raeburn 8297: <script type="text/javascript">
1.1032 www 8298: // <![CDATA[
8299: var $funcname = function()
8300: {
8301: modalWindow.windowId = "myModal";
8302: modalWindow.width = $width;
8303: modalWindow.height = $height;
8304: modalWindow.content = '$content';
8305: modalWindow.open();
8306: };
8307: // ]]>
8308: </script>
8309: ENDADHOC
8310: }
8311:
1.1041 www 8312: sub modal_adhoc_inner {
8313: my ($funcname,$width,$height,$content)=@_;
8314: my $innerwidth=$width-20;
8315: $content=&js_ready(
1.1042 www 8316: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8317: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8318: $content.
1.1041 www 8319: &end_scrollbox().
1.1075.2.42 raeburn 8320: &end_page()
1.1041 www 8321: );
8322: return &modal_adhoc_script($funcname,$width,$height,$content);
8323: }
8324:
8325: sub modal_adhoc_window {
8326: my ($funcname,$width,$height,$content,$linktext)=@_;
8327: return &modal_adhoc_inner($funcname,$width,$height,$content).
8328: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8329: }
8330:
8331: sub modal_adhoc_launch {
8332: my ($funcname,$width,$height,$content)=@_;
8333: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8334: <script type="text/javascript">
8335: // <![CDATA[
8336: $funcname();
8337: // ]]>
8338: </script>
8339: ENDLAUNCH
8340: }
8341:
8342: sub modal_adhoc_close {
8343: return (<<ENDCLOSE);
8344: <script type="text/javascript">
8345: // <![CDATA[
8346: modalWindow.close();
8347: // ]]>
8348: </script>
8349: ENDCLOSE
8350: }
8351:
1.1038 www 8352: sub togglebox_script {
8353: return(<<ENDTOGGLE);
8354: <script type="text/javascript">
8355: // <![CDATA[
8356: function LCtoggleDisplay(id,hidetext,showtext) {
8357: link = document.getElementById(id + "link").childNodes[0];
8358: with (document.getElementById(id).style) {
8359: if (display == "none" ) {
8360: display = "inline";
8361: link.nodeValue = hidetext;
8362: } else {
8363: display = "none";
8364: link.nodeValue = showtext;
8365: }
8366: }
8367: }
8368: // ]]>
8369: </script>
8370: ENDTOGGLE
8371: }
8372:
1.1039 www 8373: sub start_togglebox {
8374: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8375: unless ($heading) { $heading=''; } else { $heading.=' '; }
8376: unless ($showtext) { $showtext=&mt('show'); }
8377: unless ($hidetext) { $hidetext=&mt('hide'); }
8378: unless ($headerbg) { $headerbg='#FFFFFF'; }
8379: return &start_data_table().
8380: &start_data_table_header_row().
8381: '<td bgcolor="'.$headerbg.'">'.$heading.
8382: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8383: $showtext.'\')">'.$showtext.'</a>]</td>'.
8384: &end_data_table_header_row().
8385: '<tr id="'.$id.'" style="display:none""><td>';
8386: }
8387:
8388: sub end_togglebox {
8389: return '</td></tr>'.&end_data_table();
8390: }
8391:
1.1041 www 8392: sub LCprogressbar_script {
1.1045 www 8393: my ($id)=@_;
1.1041 www 8394: return(<<ENDPROGRESS);
8395: <script type="text/javascript">
8396: // <![CDATA[
1.1045 www 8397: \$('#progressbar$id').progressbar({
1.1041 www 8398: value: 0,
8399: change: function(event, ui) {
8400: var newVal = \$(this).progressbar('option', 'value');
8401: \$('.pblabel', this).text(LCprogressTxt);
8402: }
8403: });
8404: // ]]>
8405: </script>
8406: ENDPROGRESS
8407: }
8408:
8409: sub LCprogressbarUpdate_script {
8410: return(<<ENDPROGRESSUPDATE);
8411: <style type="text/css">
8412: .ui-progressbar { position:relative; }
8413: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8414: </style>
8415: <script type="text/javascript">
8416: // <![CDATA[
1.1045 www 8417: var LCprogressTxt='---';
8418:
8419: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8420: LCprogressTxt=progresstext;
1.1045 www 8421: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8422: }
8423: // ]]>
8424: </script>
8425: ENDPROGRESSUPDATE
8426: }
8427:
1.1042 www 8428: my $LClastpercent;
1.1045 www 8429: my $LCidcnt;
8430: my $LCcurrentid;
1.1042 www 8431:
1.1041 www 8432: sub LCprogressbar {
1.1042 www 8433: my ($r)=(@_);
8434: $LClastpercent=0;
1.1045 www 8435: $LCidcnt++;
8436: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8437: my $starting=&mt('Starting');
8438: my $content=(<<ENDPROGBAR);
1.1045 www 8439: <div id="progressbar$LCcurrentid">
1.1041 www 8440: <span class="pblabel">$starting</span>
8441: </div>
8442: ENDPROGBAR
1.1045 www 8443: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8444: }
8445:
8446: sub LCprogressbarUpdate {
1.1042 www 8447: my ($r,$val,$text)=@_;
8448: unless ($val) {
8449: if ($LClastpercent) {
8450: $val=$LClastpercent;
8451: } else {
8452: $val=0;
8453: }
8454: }
1.1041 www 8455: if ($val<0) { $val=0; }
8456: if ($val>100) { $val=0; }
1.1042 www 8457: $LClastpercent=$val;
1.1041 www 8458: unless ($text) { $text=$val.'%'; }
8459: $text=&js_ready($text);
1.1044 www 8460: &r_print($r,<<ENDUPDATE);
1.1041 www 8461: <script type="text/javascript">
8462: // <![CDATA[
1.1045 www 8463: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8464: // ]]>
8465: </script>
8466: ENDUPDATE
1.1035 www 8467: }
8468:
1.1042 www 8469: sub LCprogressbarClose {
8470: my ($r)=@_;
8471: $LClastpercent=0;
1.1044 www 8472: &r_print($r,<<ENDCLOSE);
1.1042 www 8473: <script type="text/javascript">
8474: // <![CDATA[
1.1045 www 8475: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8476: // ]]>
8477: </script>
8478: ENDCLOSE
1.1044 www 8479: }
8480:
8481: sub r_print {
8482: my ($r,$to_print)=@_;
8483: if ($r) {
8484: $r->print($to_print);
8485: $r->rflush();
8486: } else {
8487: print($to_print);
8488: }
1.1042 www 8489: }
8490:
1.320 albertel 8491: sub html_encode {
8492: my ($result) = @_;
8493:
1.322 albertel 8494: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8495:
8496: return $result;
8497: }
1.1044 www 8498:
1.317 albertel 8499: sub js_ready {
8500: my ($result) = @_;
8501:
1.323 albertel 8502: $result =~ s/[\n\r]/ /xmsg;
8503: $result =~ s/\\/\\\\/xmsg;
8504: $result =~ s/'/\\'/xmsg;
1.372 albertel 8505: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8506:
8507: return $result;
8508: }
8509:
1.315 albertel 8510: sub validate_page {
8511: if ( exists($env{'internal.start_page'})
1.316 albertel 8512: && $env{'internal.start_page'} > 1) {
8513: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8514: $env{'internal.start_page'}.' '.
1.316 albertel 8515: $ENV{'request.filename'});
1.315 albertel 8516: }
8517: if ( exists($env{'internal.end_page'})
1.316 albertel 8518: && $env{'internal.end_page'} > 1) {
8519: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8520: $env{'internal.end_page'}.' '.
1.316 albertel 8521: $env{'request.filename'});
1.315 albertel 8522: }
8523: if ( exists($env{'internal.start_page'})
8524: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8525: &Apache::lonnet::logthis('start_page called without end_page '.
8526: $env{'request.filename'});
1.315 albertel 8527: }
8528: if ( ! exists($env{'internal.start_page'})
8529: && exists($env{'internal.end_page'})) {
1.316 albertel 8530: &Apache::lonnet::logthis('end_page called without start_page'.
8531: $env{'request.filename'});
1.315 albertel 8532: }
1.306 albertel 8533: }
1.315 albertel 8534:
1.996 www 8535:
8536: sub start_scrollbox {
1.1075.2.56 raeburn 8537: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8538: unless ($outerwidth) { $outerwidth='520px'; }
8539: unless ($width) { $width='500px'; }
8540: unless ($height) { $height='200px'; }
1.1075 raeburn 8541: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8542: if ($id ne '') {
1.1075.2.42 raeburn 8543: $table_id = ' id="table_'.$id.'"';
8544: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8545: }
1.1075 raeburn 8546: if ($bgcolor ne '') {
8547: $tdcol = "background-color: $bgcolor;";
8548: }
1.1075.2.42 raeburn 8549: my $nicescroll_js;
8550: if ($env{'browser.mobile'}) {
8551: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8552: }
1.1075 raeburn 8553: return <<"END";
1.1075.2.42 raeburn 8554: $nicescroll_js
8555:
8556: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8557: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8558: END
1.996 www 8559: }
8560:
8561: sub end_scrollbox {
1.1036 www 8562: return '</div></td></tr></table>';
1.996 www 8563: }
8564:
1.1075.2.42 raeburn 8565: sub nicescroll_javascript {
8566: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8567: my %options;
8568: if (ref($cursor) eq 'HASH') {
8569: %options = %{$cursor};
8570: }
8571: unless ($options{'railalign'} =~ /^left|right$/) {
8572: $options{'railalign'} = 'left';
8573: }
8574: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8575: my $function = &get_users_function();
8576: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8577: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8578: $options{'cursorcolor'} = '#00F';
8579: }
8580: }
8581: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8582: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8583: $options{'cursoropacity'}='1.0';
8584: }
8585: } else {
8586: $options{'cursoropacity'}='1.0';
8587: }
8588: if ($options{'cursorfixedheight'} eq 'none') {
8589: delete($options{'cursorfixedheight'});
8590: } else {
8591: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8592: }
8593: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8594: delete($options{'railoffset'});
8595: }
8596: my @niceoptions;
8597: while (my($key,$value) = each(%options)) {
8598: if ($value =~ /^\{.+\}$/) {
8599: push(@niceoptions,$key.':'.$value);
8600: } else {
8601: push(@niceoptions,$key.':"'.$value.'"');
8602: }
8603: }
8604: my $nicescroll_js = '
8605: $(document).ready(
8606: function() {
8607: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8608: }
8609: );
8610: ';
8611: if ($framecheck) {
8612: $nicescroll_js .= '
8613: function expand_div(caller) {
8614: if (top === self) {
8615: document.getElementById("'.$id.'").style.width = "auto";
8616: document.getElementById("'.$id.'").style.height = "auto";
8617: } else {
8618: try {
8619: if (parent.frames) {
8620: if (parent.frames.length > 1) {
8621: var framesrc = parent.frames[1].location.href;
8622: var currsrc = framesrc.replace(/\#.*$/,"");
8623: if ((caller == "search") || (currsrc == "'.$location.'")) {
8624: document.getElementById("'.$id.'").style.width = "auto";
8625: document.getElementById("'.$id.'").style.height = "auto";
8626: }
8627: }
8628: }
8629: } catch (e) {
8630: return;
8631: }
8632: }
8633: return;
8634: }
8635: ';
8636: }
8637: if ($needjsready) {
8638: $nicescroll_js = '
8639: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8640: } else {
8641: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8642: }
8643: return $nicescroll_js;
8644: }
8645:
1.318 albertel 8646: sub simple_error_page {
1.1075.2.49 raeburn 8647: my ($r,$title,$msg,$args) = @_;
8648: if (ref($args) eq 'HASH') {
8649: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8650: } else {
8651: $msg = &mt($msg);
8652: }
8653:
1.318 albertel 8654: my $page =
8655: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8656: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8657: &Apache::loncommon::end_page();
8658: if (ref($r)) {
8659: $r->print($page);
1.327 albertel 8660: return;
1.318 albertel 8661: }
8662: return $page;
8663: }
1.347 albertel 8664:
8665: {
1.610 albertel 8666: my @row_count;
1.961 onken 8667:
8668: sub start_data_table_count {
8669: unshift(@row_count, 0);
8670: return;
8671: }
8672:
8673: sub end_data_table_count {
8674: shift(@row_count);
8675: return;
8676: }
8677:
1.347 albertel 8678: sub start_data_table {
1.1018 raeburn 8679: my ($add_class,$id) = @_;
1.422 albertel 8680: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8681: my $table_id;
8682: if (defined($id)) {
8683: $table_id = ' id="'.$id.'"';
8684: }
1.961 onken 8685: &start_data_table_count();
1.1018 raeburn 8686: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8687: }
8688:
8689: sub end_data_table {
1.961 onken 8690: &end_data_table_count();
1.389 albertel 8691: return '</table>'."\n";;
1.347 albertel 8692: }
8693:
8694: sub start_data_table_row {
1.974 wenzelju 8695: my ($add_class, $id) = @_;
1.610 albertel 8696: $row_count[0]++;
8697: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8698: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8699: $id = (' id="'.$id.'"') unless ($id eq '');
8700: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8701: }
1.471 banghart 8702:
8703: sub continue_data_table_row {
1.974 wenzelju 8704: my ($add_class, $id) = @_;
1.610 albertel 8705: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8706: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8707: $id = (' id="'.$id.'"') unless ($id eq '');
8708: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8709: }
1.347 albertel 8710:
8711: sub end_data_table_row {
1.389 albertel 8712: return '</tr>'."\n";;
1.347 albertel 8713: }
1.367 www 8714:
1.421 albertel 8715: sub start_data_table_empty_row {
1.707 bisitz 8716: # $row_count[0]++;
1.421 albertel 8717: return '<tr class="LC_empty_row" >'."\n";;
8718: }
8719:
8720: sub end_data_table_empty_row {
8721: return '</tr>'."\n";;
8722: }
8723:
1.367 www 8724: sub start_data_table_header_row {
1.389 albertel 8725: return '<tr class="LC_header_row">'."\n";;
1.367 www 8726: }
8727:
8728: sub end_data_table_header_row {
1.389 albertel 8729: return '</tr>'."\n";;
1.367 www 8730: }
1.890 droeschl 8731:
8732: sub data_table_caption {
8733: my $caption = shift;
8734: return "<caption class=\"LC_caption\">$caption</caption>";
8735: }
1.347 albertel 8736: }
8737:
1.548 albertel 8738: =pod
8739:
8740: =item * &inhibit_menu_check($arg)
8741:
8742: Checks for a inhibitmenu state and generates output to preserve it
8743:
8744: Inputs: $arg - can be any of
8745: - undef - in which case the return value is a string
8746: to add into arguments list of a uri
8747: - 'input' - in which case the return value is a HTML
8748: <form> <input> field of type hidden to
8749: preserve the value
8750: - a url - in which case the return value is the url with
8751: the neccesary cgi args added to preserve the
8752: inhibitmenu state
8753: - a ref to a url - no return value, but the string is
8754: updated to include the neccessary cgi
8755: args to preserve the inhibitmenu state
8756:
8757: =cut
8758:
8759: sub inhibit_menu_check {
8760: my ($arg) = @_;
8761: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8762: if ($arg eq 'input') {
8763: if ($env{'form.inhibitmenu'}) {
8764: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8765: } else {
8766: return
8767: }
8768: }
8769: if ($env{'form.inhibitmenu'}) {
8770: if (ref($arg)) {
8771: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8772: } elsif ($arg eq '') {
8773: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8774: } else {
8775: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8776: }
8777: }
8778: if (!ref($arg)) {
8779: return $arg;
8780: }
8781: }
8782:
1.251 albertel 8783: ###############################################
1.182 matthew 8784:
8785: =pod
8786:
1.549 albertel 8787: =back
8788:
8789: =head1 User Information Routines
8790:
8791: =over 4
8792:
1.405 albertel 8793: =item * &get_users_function()
1.182 matthew 8794:
8795: Used by &bodytag to determine the current users primary role.
8796: Returns either 'student','coordinator','admin', or 'author'.
8797:
8798: =cut
8799:
8800: ###############################################
8801: sub get_users_function {
1.815 tempelho 8802: my $function = 'norole';
1.818 tempelho 8803: if ($env{'request.role'}=~/^(st)/) {
8804: $function='student';
8805: }
1.907 raeburn 8806: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8807: $function='coordinator';
8808: }
1.258 albertel 8809: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8810: $function='admin';
8811: }
1.826 bisitz 8812: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8813: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8814: $function='author';
8815: }
8816: return $function;
1.54 www 8817: }
1.99 www 8818:
8819: ###############################################
8820:
1.233 raeburn 8821: =pod
8822:
1.821 raeburn 8823: =item * &show_course()
8824:
8825: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8826: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8827:
8828: Inputs:
8829: None
8830:
8831: Outputs:
8832: Scalar: 1 if 'Course' to be used, 0 otherwise.
8833:
8834: =cut
8835:
8836: ###############################################
8837: sub show_course {
8838: my $course = !$env{'user.adv'};
8839: if (!$env{'user.adv'}) {
8840: foreach my $env (keys(%env)) {
8841: next if ($env !~ m/^user\.priv\./);
8842: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8843: $course = 0;
8844: last;
8845: }
8846: }
8847: }
8848: return $course;
8849: }
8850:
8851: ###############################################
8852:
8853: =pod
8854:
1.542 raeburn 8855: =item * &check_user_status()
1.274 raeburn 8856:
8857: Determines current status of supplied role for a
8858: specific user. Roles can be active, previous or future.
8859:
8860: Inputs:
8861: user's domain, user's username, course's domain,
1.375 raeburn 8862: course's number, optional section ID.
1.274 raeburn 8863:
8864: Outputs:
8865: role status: active, previous or future.
8866:
8867: =cut
8868:
8869: sub check_user_status {
1.412 raeburn 8870: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8871: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 8872: my @uroles = keys(%userinfo);
1.274 raeburn 8873: my $srchstr;
8874: my $active_chk = 'none';
1.412 raeburn 8875: my $now = time;
1.274 raeburn 8876: if (@uroles > 0) {
1.908 raeburn 8877: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8878: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8879: } else {
1.412 raeburn 8880: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8881: }
8882: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8883: my $role_end = 0;
8884: my $role_start = 0;
8885: $active_chk = 'active';
1.412 raeburn 8886: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8887: $role_end = $1;
8888: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8889: $role_start = $1;
1.274 raeburn 8890: }
8891: }
8892: if ($role_start > 0) {
1.412 raeburn 8893: if ($now < $role_start) {
1.274 raeburn 8894: $active_chk = 'future';
8895: }
8896: }
8897: if ($role_end > 0) {
1.412 raeburn 8898: if ($now > $role_end) {
1.274 raeburn 8899: $active_chk = 'previous';
8900: }
8901: }
8902: }
8903: }
8904: return $active_chk;
8905: }
8906:
8907: ###############################################
8908:
8909: =pod
8910:
1.405 albertel 8911: =item * &get_sections()
1.233 raeburn 8912:
8913: Determines all the sections for a course including
8914: sections with students and sections containing other roles.
1.419 raeburn 8915: Incoming parameters:
8916:
8917: 1. domain
8918: 2. course number
8919: 3. reference to array containing roles for which sections should
8920: be gathered (optional).
8921: 4. reference to array containing status types for which sections
8922: should be gathered (optional).
8923:
8924: If the third argument is undefined, sections are gathered for any role.
8925: If the fourth argument is undefined, sections are gathered for any status.
8926: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8927:
1.374 raeburn 8928: Returns section hash (keys are section IDs, values are
8929: number of users in each section), subject to the
1.419 raeburn 8930: optional roles filter, optional status filter
1.233 raeburn 8931:
8932: =cut
8933:
8934: ###############################################
8935: sub get_sections {
1.419 raeburn 8936: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8937: if (!defined($cdom) || !defined($cnum)) {
8938: my $cid = $env{'request.course.id'};
8939:
8940: return if (!defined($cid));
8941:
8942: $cdom = $env{'course.'.$cid.'.domain'};
8943: $cnum = $env{'course.'.$cid.'.num'};
8944: }
8945:
8946: my %sectioncount;
1.419 raeburn 8947: my $now = time;
1.240 albertel 8948:
1.1075.2.33 raeburn 8949: my $check_students = 1;
8950: my $only_students = 0;
8951: if (ref($possible_roles) eq 'ARRAY') {
8952: if (grep(/^st$/,@{$possible_roles})) {
8953: if (@{$possible_roles} == 1) {
8954: $only_students = 1;
8955: }
8956: } else {
8957: $check_students = 0;
8958: }
8959: }
8960:
8961: if ($check_students) {
1.276 albertel 8962: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8963: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8964: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8965: my $start_index = &Apache::loncoursedata::CL_START();
8966: my $end_index = &Apache::loncoursedata::CL_END();
8967: my $status;
1.366 albertel 8968: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8969: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8970: $data->[$status_index],
8971: $data->[$start_index],
8972: $data->[$end_index]);
8973: if ($stu_status eq 'Active') {
8974: $status = 'active';
8975: } elsif ($end < $now) {
8976: $status = 'previous';
8977: } elsif ($start > $now) {
8978: $status = 'future';
8979: }
8980: if ($section ne '-1' && $section !~ /^\s*$/) {
8981: if ((!defined($possible_status)) || (($status ne '') &&
8982: (grep/^\Q$status\E$/,@{$possible_status}))) {
8983: $sectioncount{$section}++;
8984: }
1.240 albertel 8985: }
8986: }
8987: }
1.1075.2.33 raeburn 8988: if ($only_students) {
8989: return %sectioncount;
8990: }
1.240 albertel 8991: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8992: foreach my $user (sort(keys(%courseroles))) {
8993: if ($user !~ /^(\w{2})/) { next; }
8994: my ($role) = ($user =~ /^(\w{2})/);
8995: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8996: my ($section,$status);
1.240 albertel 8997: if ($role eq 'cr' &&
8998: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8999: $section=$1;
9000: }
9001: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9002: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9003: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9004: if ($end == -1 && $start == -1) {
9005: next; #deleted role
9006: }
9007: if (!defined($possible_status)) {
9008: $sectioncount{$section}++;
9009: } else {
9010: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9011: $status = 'active';
9012: } elsif ($end < $now) {
9013: $status = 'future';
9014: } elsif ($start > $now) {
9015: $status = 'previous';
9016: }
9017: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9018: $sectioncount{$section}++;
9019: }
9020: }
1.233 raeburn 9021: }
1.366 albertel 9022: return %sectioncount;
1.233 raeburn 9023: }
9024:
1.274 raeburn 9025: ###############################################
1.294 raeburn 9026:
9027: =pod
1.405 albertel 9028:
9029: =item * &get_course_users()
9030:
1.275 raeburn 9031: Retrieves usernames:domains for users in the specified course
9032: with specific role(s), and access status.
9033:
9034: Incoming parameters:
1.277 albertel 9035: 1. course domain
9036: 2. course number
9037: 3. access status: users must have - either active,
1.275 raeburn 9038: previous, future, or all.
1.277 albertel 9039: 4. reference to array of permissible roles
1.288 raeburn 9040: 5. reference to array of section restrictions (optional)
9041: 6. reference to results object (hash of hashes).
9042: 7. reference to optional userdata hash
1.609 raeburn 9043: 8. reference to optional statushash
1.630 raeburn 9044: 9. flag if privileged users (except those set to unhide in
9045: course settings) should be excluded
1.609 raeburn 9046: Keys of top level results hash are roles.
1.275 raeburn 9047: Keys of inner hashes are username:domain, with
9048: values set to access type.
1.288 raeburn 9049: Optional userdata hash returns an array with arguments in the
9050: same order as loncoursedata::get_classlist() for student data.
9051:
1.609 raeburn 9052: Optional statushash returns
9053:
1.288 raeburn 9054: Entries for end, start, section and status are blank because
9055: of the possibility of multiple values for non-student roles.
9056:
1.275 raeburn 9057: =cut
1.405 albertel 9058:
1.275 raeburn 9059: ###############################################
1.405 albertel 9060:
1.275 raeburn 9061: sub get_course_users {
1.630 raeburn 9062: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9063: my %idx = ();
1.419 raeburn 9064: my %seclists;
1.288 raeburn 9065:
9066: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9067: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9068: $idx{end} = &Apache::loncoursedata::CL_END();
9069: $idx{start} = &Apache::loncoursedata::CL_START();
9070: $idx{id} = &Apache::loncoursedata::CL_ID();
9071: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9072: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9073: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9074:
1.290 albertel 9075: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9076: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9077: my $now = time;
1.277 albertel 9078: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9079: my $match = 0;
1.412 raeburn 9080: my $secmatch = 0;
1.419 raeburn 9081: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9082: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9083: if ($section eq '') {
9084: $section = 'none';
9085: }
1.291 albertel 9086: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9087: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9088: $secmatch = 1;
9089: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9090: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9091: $secmatch = 1;
9092: }
9093: } else {
1.419 raeburn 9094: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9095: $secmatch = 1;
9096: }
1.290 albertel 9097: }
1.412 raeburn 9098: if (!$secmatch) {
9099: next;
9100: }
1.419 raeburn 9101: }
1.275 raeburn 9102: if (defined($$types{'active'})) {
1.288 raeburn 9103: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9104: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9105: $match = 1;
1.275 raeburn 9106: }
9107: }
9108: if (defined($$types{'previous'})) {
1.609 raeburn 9109: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9110: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9111: $match = 1;
1.275 raeburn 9112: }
9113: }
9114: if (defined($$types{'future'})) {
1.609 raeburn 9115: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9116: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9117: $match = 1;
1.275 raeburn 9118: }
9119: }
1.609 raeburn 9120: if ($match) {
9121: push(@{$seclists{$student}},$section);
9122: if (ref($userdata) eq 'HASH') {
9123: $$userdata{$student} = $$classlist{$student};
9124: }
9125: if (ref($statushash) eq 'HASH') {
9126: $statushash->{$student}{'st'}{$section} = $status;
9127: }
1.288 raeburn 9128: }
1.275 raeburn 9129: }
9130: }
1.412 raeburn 9131: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9132: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9133: my $now = time;
1.609 raeburn 9134: my %displaystatus = ( previous => 'Expired',
9135: active => 'Active',
9136: future => 'Future',
9137: );
1.1075.2.36 raeburn 9138: my (%nothide,@possdoms);
1.630 raeburn 9139: if ($hidepriv) {
9140: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9141: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9142: if ($user !~ /:/) {
9143: $nothide{join(':',split(/[\@]/,$user))}=1;
9144: } else {
9145: $nothide{$user} = 1;
9146: }
9147: }
1.1075.2.36 raeburn 9148: my @possdoms = ($cdom);
9149: if ($coursehash{'checkforpriv'}) {
9150: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9151: }
1.630 raeburn 9152: }
1.439 raeburn 9153: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9154: my $match = 0;
1.412 raeburn 9155: my $secmatch = 0;
1.439 raeburn 9156: my $status;
1.412 raeburn 9157: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9158: $user =~ s/:$//;
1.439 raeburn 9159: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9160: if ($end == -1 || $start == -1) {
9161: next;
9162: }
9163: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9164: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9165: my ($uname,$udom) = split(/:/,$user);
9166: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9167: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9168: $secmatch = 1;
9169: } elsif ($usec eq '') {
1.420 albertel 9170: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9171: $secmatch = 1;
9172: }
9173: } else {
9174: if (grep(/^\Q$usec\E$/,@{$sections})) {
9175: $secmatch = 1;
9176: }
9177: }
9178: if (!$secmatch) {
9179: next;
9180: }
1.288 raeburn 9181: }
1.419 raeburn 9182: if ($usec eq '') {
9183: $usec = 'none';
9184: }
1.275 raeburn 9185: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9186: if ($hidepriv) {
1.1075.2.36 raeburn 9187: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9188: (!$nothide{$uname.':'.$udom})) {
9189: next;
9190: }
9191: }
1.503 raeburn 9192: if ($end > 0 && $end < $now) {
1.439 raeburn 9193: $status = 'previous';
9194: } elsif ($start > $now) {
9195: $status = 'future';
9196: } else {
9197: $status = 'active';
9198: }
1.277 albertel 9199: foreach my $type (keys(%{$types})) {
1.275 raeburn 9200: if ($status eq $type) {
1.420 albertel 9201: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9202: push(@{$$users{$role}{$user}},$type);
9203: }
1.288 raeburn 9204: $match = 1;
9205: }
9206: }
1.419 raeburn 9207: if (($match) && (ref($userdata) eq 'HASH')) {
9208: if (!exists($$userdata{$uname.':'.$udom})) {
9209: &get_user_info($udom,$uname,\%idx,$userdata);
9210: }
1.420 albertel 9211: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9212: push(@{$seclists{$uname.':'.$udom}},$usec);
9213: }
1.609 raeburn 9214: if (ref($statushash) eq 'HASH') {
9215: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9216: }
1.275 raeburn 9217: }
9218: }
9219: }
9220: }
1.290 albertel 9221: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9222: if ((defined($cdom)) && (defined($cnum))) {
9223: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9224: if ( defined($csettings{'internal.courseowner'}) ) {
9225: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9226: next if ($owner eq '');
9227: my ($ownername,$ownerdom);
9228: if ($owner =~ /^([^:]+):([^:]+)$/) {
9229: $ownername = $1;
9230: $ownerdom = $2;
9231: } else {
9232: $ownername = $owner;
9233: $ownerdom = $cdom;
9234: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9235: }
9236: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9237: if (defined($userdata) &&
1.609 raeburn 9238: !exists($$userdata{$owner})) {
9239: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9240: if (!grep(/^none$/,@{$seclists{$owner}})) {
9241: push(@{$seclists{$owner}},'none');
9242: }
9243: if (ref($statushash) eq 'HASH') {
9244: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9245: }
1.290 albertel 9246: }
1.279 raeburn 9247: }
9248: }
9249: }
1.419 raeburn 9250: foreach my $user (keys(%seclists)) {
9251: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9252: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9253: }
1.275 raeburn 9254: }
9255: return;
9256: }
9257:
1.288 raeburn 9258: sub get_user_info {
9259: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9260: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9261: &plainname($uname,$udom,'lastname');
1.291 albertel 9262: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9263: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9264: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9265: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9266: return;
9267: }
1.275 raeburn 9268:
1.472 raeburn 9269: ###############################################
9270:
9271: =pod
9272:
9273: =item * &get_user_quota()
9274:
1.1075.2.41 raeburn 9275: Retrieves quota assigned for storage of user files.
9276: Default is to report quota for portfolio files.
1.472 raeburn 9277:
9278: Incoming parameters:
9279: 1. user's username
9280: 2. user's domain
1.1075.2.41 raeburn 9281: 3. quota name - portfolio, author, or course
9282: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9283: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9284: course
1.472 raeburn 9285:
9286: Returns:
1.1075.2.58 raeburn 9287: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9288: 2. (Optional) Type of setting: custom or default
9289: (individually assigned or default for user's
9290: institutional status).
9291: 3. (Optional) - User's institutional status (e.g., faculty, staff
9292: or student - types as defined in localenroll::inst_usertypes
9293: for user's domain, which determines default quota for user.
9294: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9295:
9296: If a value has been stored in the user's environment,
1.536 raeburn 9297: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9298: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9299:
9300: =cut
9301:
9302: ###############################################
9303:
9304:
9305: sub get_user_quota {
1.1075.2.42 raeburn 9306: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9307: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9308: if (!defined($udom)) {
9309: $udom = $env{'user.domain'};
9310: }
9311: if (!defined($uname)) {
9312: $uname = $env{'user.name'};
9313: }
9314: if (($udom eq '' || $uname eq '') ||
9315: ($udom eq 'public') && ($uname eq 'public')) {
9316: $quota = 0;
1.536 raeburn 9317: $quotatype = 'default';
9318: $defquota = 0;
1.472 raeburn 9319: } else {
1.536 raeburn 9320: my $inststatus;
1.1075.2.41 raeburn 9321: if ($quotaname eq 'course') {
9322: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9323: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9324: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9325: } else {
9326: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9327: $quota = $cenv{'internal.uploadquota'};
9328: }
1.536 raeburn 9329: } else {
1.1075.2.41 raeburn 9330: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9331: if ($quotaname eq 'author') {
9332: $quota = $env{'environment.authorquota'};
9333: } else {
9334: $quota = $env{'environment.portfolioquota'};
9335: }
9336: $inststatus = $env{'environment.inststatus'};
9337: } else {
9338: my %userenv =
9339: &Apache::lonnet::get('environment',['portfolioquota',
9340: 'authorquota','inststatus'],$udom,$uname);
9341: my ($tmp) = keys(%userenv);
9342: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9343: if ($quotaname eq 'author') {
9344: $quota = $userenv{'authorquota'};
9345: } else {
9346: $quota = $userenv{'portfolioquota'};
9347: }
9348: $inststatus = $userenv{'inststatus'};
9349: } else {
9350: undef(%userenv);
9351: }
9352: }
9353: }
9354: if ($quota eq '' || wantarray) {
9355: if ($quotaname eq 'course') {
9356: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9357: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9358: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9359: $defquota = $domdefs{$crstype.'quota'};
9360: }
9361: if ($defquota eq '') {
9362: $defquota = 500;
9363: }
1.1075.2.41 raeburn 9364: } else {
9365: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9366: }
9367: if ($quota eq '') {
9368: $quota = $defquota;
9369: $quotatype = 'default';
9370: } else {
9371: $quotatype = 'custom';
9372: }
1.472 raeburn 9373: }
9374: }
1.536 raeburn 9375: if (wantarray) {
9376: return ($quota,$quotatype,$settingstatus,$defquota);
9377: } else {
9378: return $quota;
9379: }
1.472 raeburn 9380: }
9381:
9382: ###############################################
9383:
9384: =pod
9385:
9386: =item * &default_quota()
9387:
1.536 raeburn 9388: Retrieves default quota assigned for storage of user portfolio files,
9389: given an (optional) user's institutional status.
1.472 raeburn 9390:
9391: Incoming parameters:
1.1075.2.42 raeburn 9392:
1.472 raeburn 9393: 1. domain
1.536 raeburn 9394: 2. (Optional) institutional status(es). This is a : separated list of
9395: status types (e.g., faculty, staff, student etc.)
9396: which apply to the user for whom the default is being retrieved.
9397: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9398: default quota will be returned.
9399: 3. quota name - portfolio, author, or course
9400: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9401:
9402: Returns:
1.1075.2.42 raeburn 9403:
1.1075.2.58 raeburn 9404: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9405: 2. (Optional) institutional type which determined the value of the
9406: default quota.
1.472 raeburn 9407:
9408: If a value has been stored in the domain's configuration db,
9409: it will return that, otherwise it returns 20 (for backwards
9410: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9411: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9412:
1.536 raeburn 9413: If the user's status includes multiple types (e.g., staff and student),
9414: the largest default quota which applies to the user determines the
9415: default quota returned.
9416:
1.472 raeburn 9417: =cut
9418:
9419: ###############################################
9420:
9421:
9422: sub default_quota {
1.1075.2.41 raeburn 9423: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9424: my ($defquota,$settingstatus);
9425: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9426: ['quotas'],$udom);
1.1075.2.41 raeburn 9427: my $key = 'defaultquota';
9428: if ($quotaname eq 'author') {
9429: $key = 'authorquota';
9430: }
1.622 raeburn 9431: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9432: if ($inststatus ne '') {
1.765 raeburn 9433: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9434: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9435: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9436: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9437: if ($defquota eq '') {
1.1075.2.41 raeburn 9438: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9439: $settingstatus = $item;
1.1075.2.41 raeburn 9440: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9441: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9442: $settingstatus = $item;
9443: }
9444: }
1.1075.2.41 raeburn 9445: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9446: if ($quotahash{'quotas'}{$item} ne '') {
9447: if ($defquota eq '') {
9448: $defquota = $quotahash{'quotas'}{$item};
9449: $settingstatus = $item;
9450: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9451: $defquota = $quotahash{'quotas'}{$item};
9452: $settingstatus = $item;
9453: }
1.536 raeburn 9454: }
9455: }
9456: }
9457: }
9458: if ($defquota eq '') {
1.1075.2.41 raeburn 9459: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9460: $defquota = $quotahash{'quotas'}{$key}{'default'};
9461: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9462: $defquota = $quotahash{'quotas'}{'default'};
9463: }
1.536 raeburn 9464: $settingstatus = 'default';
1.1075.2.42 raeburn 9465: if ($defquota eq '') {
9466: if ($quotaname eq 'author') {
9467: $defquota = 500;
9468: }
9469: }
1.536 raeburn 9470: }
9471: } else {
9472: $settingstatus = 'default';
1.1075.2.41 raeburn 9473: if ($quotaname eq 'author') {
9474: $defquota = 500;
9475: } else {
9476: $defquota = 20;
9477: }
1.536 raeburn 9478: }
9479: if (wantarray) {
9480: return ($defquota,$settingstatus);
1.472 raeburn 9481: } else {
1.536 raeburn 9482: return $defquota;
1.472 raeburn 9483: }
9484: }
9485:
1.1075.2.41 raeburn 9486: ###############################################
9487:
9488: =pod
9489:
1.1075.2.42 raeburn 9490: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9491:
9492: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9493: of existing file within authoring space will cause quota for the authoring
9494: space to be exceeded.
9495:
9496: Same, if upload of a file directly to a course/community via Course Editor
9497: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9498:
1.1075.2.61 raeburn 9499: Inputs: 7
1.1075.2.42 raeburn 9500: 1. username or coursenum
1.1075.2.41 raeburn 9501: 2. domain
1.1075.2.42 raeburn 9502: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9503: 4. filename of file for which action is being requested
9504: 5. filesize (kB) of file
9505: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9506: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9507:
9508: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9509: otherwise return null.
9510:
1.1075.2.42 raeburn 9511: =back
9512:
1.1075.2.41 raeburn 9513: =cut
9514:
1.1075.2.42 raeburn 9515: sub excess_filesize_warning {
1.1075.2.59 raeburn 9516: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9517: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9518: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9519: if ($context eq 'author') {
9520: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9521: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9522: } else {
9523: foreach my $subdir ('docs','supplemental') {
9524: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9525: }
9526: }
1.1075.2.41 raeburn 9527: $disk_quota = int($disk_quota * 1000);
9528: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9529: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9530: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9531: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9532: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9533: $disk_quota,$current_disk_usage).
9534: '</p>';
9535: }
9536: return;
9537: }
9538:
9539: ###############################################
9540:
9541:
1.384 raeburn 9542: sub get_secgrprole_info {
9543: my ($cdom,$cnum,$needroles,$type) = @_;
9544: my %sections_count = &get_sections($cdom,$cnum);
9545: my @sections = (sort {$a <=> $b} keys(%sections_count));
9546: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9547: my @groups = sort(keys(%curr_groups));
9548: my $allroles = [];
9549: my $rolehash;
9550: my $accesshash = {
9551: active => 'Currently has access',
9552: future => 'Will have future access',
9553: previous => 'Previously had access',
9554: };
9555: if ($needroles) {
9556: $rolehash = {'all' => 'all'};
1.385 albertel 9557: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9558: if (&Apache::lonnet::error(%user_roles)) {
9559: undef(%user_roles);
9560: }
9561: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9562: my ($role)=split(/\:/,$item,2);
9563: if ($role eq 'cr') { next; }
9564: if ($role =~ /^cr/) {
9565: $$rolehash{$role} = (split('/',$role))[3];
9566: } else {
9567: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9568: }
9569: }
9570: foreach my $key (sort(keys(%{$rolehash}))) {
9571: push(@{$allroles},$key);
9572: }
9573: push (@{$allroles},'st');
9574: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9575: }
9576: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9577: }
9578:
1.555 raeburn 9579: sub user_picker {
1.1075.2.127 raeburn 9580: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 9581: my $currdom = $dom;
1.1075.2.114 raeburn 9582: my @alldoms = &Apache::lonnet::all_domains();
9583: if (@alldoms == 1) {
9584: my %domsrch = &Apache::lonnet::get_dom('configuration',
9585: ['directorysrch'],$alldoms[0]);
9586: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9587: my $showdom = $domdesc;
9588: if ($showdom eq '') {
9589: $showdom = $dom;
9590: }
9591: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9592: if ((!$domsrch{'directorysrch'}{'available'}) &&
9593: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9594: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9595: }
9596: }
9597: }
1.555 raeburn 9598: my %curr_selected = (
9599: srchin => 'dom',
1.580 raeburn 9600: srchby => 'lastname',
1.555 raeburn 9601: );
9602: my $srchterm;
1.625 raeburn 9603: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9604: if ($srch->{'srchby'} ne '') {
9605: $curr_selected{'srchby'} = $srch->{'srchby'};
9606: }
9607: if ($srch->{'srchin'} ne '') {
9608: $curr_selected{'srchin'} = $srch->{'srchin'};
9609: }
9610: if ($srch->{'srchtype'} ne '') {
9611: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9612: }
9613: if ($srch->{'srchdomain'} ne '') {
9614: $currdom = $srch->{'srchdomain'};
9615: }
9616: $srchterm = $srch->{'srchterm'};
9617: }
1.1075.2.98 raeburn 9618: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9619: 'usr' => 'Search criteria',
1.563 raeburn 9620: 'doma' => 'Domain/institution to search',
1.558 albertel 9621: 'uname' => 'username',
9622: 'lastname' => 'last name',
1.555 raeburn 9623: 'lastfirst' => 'last name, first name',
1.558 albertel 9624: 'crs' => 'in this course',
1.576 raeburn 9625: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9626: 'alc' => 'all LON-CAPA',
1.573 raeburn 9627: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9628: 'exact' => 'is',
9629: 'contains' => 'contains',
1.569 raeburn 9630: 'begins' => 'begins with',
1.1075.2.98 raeburn 9631: );
9632: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9633: 'youm' => "You must include some text to search for.",
9634: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9635: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9636: 'yomc' => "You must choose a domain when using an institutional directory search.",
9637: 'ymcd' => "You must choose a domain when using a domain search.",
9638: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9639: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9640: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9641: );
1.1075.2.98 raeburn 9642: &html_escape(\%html_lt);
9643: &js_escape(\%js_lt);
1.1075.2.115 raeburn 9644: my $domform;
1.1075.2.126 raeburn 9645: my $allow_blank = 1;
1.1075.2.115 raeburn 9646: if ($fixeddom) {
1.1075.2.126 raeburn 9647: $allow_blank = 0;
9648: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 9649: } else {
1.1075.2.126 raeburn 9650: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 9651: }
1.563 raeburn 9652: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9653:
9654: my @srchins = ('crs','dom','alc','instd');
9655:
9656: foreach my $option (@srchins) {
9657: # FIXME 'alc' option unavailable until
9658: # loncreateuser::print_user_query_page()
9659: # has been completed.
9660: next if ($option eq 'alc');
1.880 raeburn 9661: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9662: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 9663: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 9664: if ($curr_selected{'srchin'} eq $option) {
9665: $srchinsel .= '
1.1075.2.98 raeburn 9666: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9667: } else {
9668: $srchinsel .= '
1.1075.2.98 raeburn 9669: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9670: }
1.555 raeburn 9671: }
1.563 raeburn 9672: $srchinsel .= "\n </select>\n";
1.555 raeburn 9673:
9674: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9675: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9676: if ($curr_selected{'srchby'} eq $option) {
9677: $srchbysel .= '
1.1075.2.98 raeburn 9678: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9679: } else {
9680: $srchbysel .= '
1.1075.2.98 raeburn 9681: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9682: }
9683: }
9684: $srchbysel .= "\n </select>\n";
9685:
9686: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9687: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9688: if ($curr_selected{'srchtype'} eq $option) {
9689: $srchtypesel .= '
1.1075.2.98 raeburn 9690: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9691: } else {
9692: $srchtypesel .= '
1.1075.2.98 raeburn 9693: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9694: }
9695: }
9696: $srchtypesel .= "\n </select>\n";
9697:
1.558 albertel 9698: my ($newuserscript,$new_user_create);
1.994 raeburn 9699: my $context_dom = $env{'request.role.domain'};
9700: if ($context eq 'requestcrs') {
9701: if ($env{'form.coursedom'} ne '') {
9702: $context_dom = $env{'form.coursedom'};
9703: }
9704: }
1.556 raeburn 9705: if ($forcenewuser) {
1.576 raeburn 9706: if (ref($srch) eq 'HASH') {
1.994 raeburn 9707: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9708: if ($cancreate) {
9709: $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>';
9710: } else {
1.799 bisitz 9711: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9712: my %usertypetext = (
9713: official => 'institutional',
9714: unofficial => 'non-institutional',
9715: );
1.799 bisitz 9716: $new_user_create = '<p class="LC_warning">'
9717: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9718: .' '
9719: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9720: ,'<a href="'.$helplink.'">','</a>')
9721: .'</p><br />';
1.627 raeburn 9722: }
1.576 raeburn 9723: }
9724: }
9725:
1.556 raeburn 9726: $newuserscript = <<"ENDSCRIPT";
9727:
1.570 raeburn 9728: function setSearch(createnew,callingForm) {
1.556 raeburn 9729: if (createnew == 1) {
1.570 raeburn 9730: for (var i=0; i<callingForm.srchby.length; i++) {
9731: if (callingForm.srchby.options[i].value == 'uname') {
9732: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9733: }
9734: }
1.570 raeburn 9735: for (var i=0; i<callingForm.srchin.length; i++) {
9736: if ( callingForm.srchin.options[i].value == 'dom') {
9737: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9738: }
9739: }
1.570 raeburn 9740: for (var i=0; i<callingForm.srchtype.length; i++) {
9741: if (callingForm.srchtype.options[i].value == 'exact') {
9742: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9743: }
9744: }
1.570 raeburn 9745: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9746: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9747: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9748: }
9749: }
9750: }
9751: }
9752: ENDSCRIPT
1.558 albertel 9753:
1.556 raeburn 9754: }
9755:
1.555 raeburn 9756: my $output = <<"END_BLOCK";
1.556 raeburn 9757: <script type="text/javascript">
1.824 bisitz 9758: // <![CDATA[
1.570 raeburn 9759: function validateEntry(callingForm) {
1.558 albertel 9760:
1.556 raeburn 9761: var checkok = 1;
1.558 albertel 9762: var srchin;
1.570 raeburn 9763: for (var i=0; i<callingForm.srchin.length; i++) {
9764: if ( callingForm.srchin[i].checked ) {
9765: srchin = callingForm.srchin[i].value;
1.558 albertel 9766: }
9767: }
9768:
1.570 raeburn 9769: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9770: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9771: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9772: var srchterm = callingForm.srchterm.value;
9773: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9774: var msg = "";
9775:
9776: if (srchterm == "") {
9777: checkok = 0;
1.1075.2.98 raeburn 9778: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9779: }
9780:
1.569 raeburn 9781: if (srchtype== 'begins') {
9782: if (srchterm.length < 2) {
9783: checkok = 0;
1.1075.2.98 raeburn 9784: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9785: }
9786: }
9787:
1.556 raeburn 9788: if (srchtype== 'contains') {
9789: if (srchterm.length < 3) {
9790: checkok = 0;
1.1075.2.98 raeburn 9791: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9792: }
9793: }
9794: if (srchin == 'instd') {
9795: if (srchdomain == '') {
9796: checkok = 0;
1.1075.2.98 raeburn 9797: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9798: }
9799: }
9800: if (srchin == 'dom') {
9801: if (srchdomain == '') {
9802: checkok = 0;
1.1075.2.98 raeburn 9803: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9804: }
9805: }
9806: if (srchby == 'lastfirst') {
9807: if (srchterm.indexOf(",") == -1) {
9808: checkok = 0;
1.1075.2.98 raeburn 9809: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9810: }
9811: if (srchterm.indexOf(",") == srchterm.length -1) {
9812: checkok = 0;
1.1075.2.98 raeburn 9813: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9814: }
9815: }
9816: if (checkok == 0) {
1.1075.2.98 raeburn 9817: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9818: return;
9819: }
9820: if (checkok == 1) {
1.570 raeburn 9821: callingForm.submit();
1.556 raeburn 9822: }
9823: }
9824:
9825: $newuserscript
9826:
1.824 bisitz 9827: // ]]>
1.556 raeburn 9828: </script>
1.558 albertel 9829:
9830: $new_user_create
9831:
1.555 raeburn 9832: END_BLOCK
1.558 albertel 9833:
1.876 raeburn 9834: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 9835: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9836: $domform.
9837: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 9838: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9839: $srchbysel.
9840: $srchtypesel.
9841: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9842: $srchinsel.
9843: &Apache::lonhtmlcommon::row_closure(1).
9844: &Apache::lonhtmlcommon::end_pick_box().
9845: '<br />';
1.1075.2.114 raeburn 9846: return ($output,1);
1.555 raeburn 9847: }
9848:
1.612 raeburn 9849: sub user_rule_check {
1.615 raeburn 9850: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 9851: my ($response,%inst_response);
1.612 raeburn 9852: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 9853: if (keys(%{$usershash}) > 1) {
9854: my (%by_username,%by_id,%userdoms);
9855: my $checkid;
1.612 raeburn 9856: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 9857: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
9858: $checkid = 1;
9859: }
9860: }
9861: foreach my $user (keys(%{$usershash})) {
9862: my ($uname,$udom) = split(/:/,$user);
9863: if ($checkid) {
9864: if (ref($usershash->{$user}) eq 'HASH') {
9865: if ($usershash->{$user}->{'id'} ne '') {
9866: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
9867: $userdoms{$udom} = 1;
9868: if (ref($inst_results) eq 'HASH') {
9869: $inst_results->{$uname.':'.$udom} = {};
9870: }
9871: }
9872: }
9873: } else {
9874: $by_username{$udom}{$uname} = 1;
9875: $userdoms{$udom} = 1;
9876: if (ref($inst_results) eq 'HASH') {
9877: $inst_results->{$uname.':'.$udom} = {};
9878: }
9879: }
9880: }
9881: foreach my $udom (keys(%userdoms)) {
9882: if (!$got_rules->{$udom}) {
9883: my %domconfig = &Apache::lonnet::get_dom('configuration',
9884: ['usercreation'],$udom);
9885: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9886: foreach my $item ('username','id') {
9887: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9888: $$curr_rules{$udom}{$item} =
9889: $domconfig{'usercreation'}{$item.'_rule'};
9890: }
9891: }
9892: }
9893: $got_rules->{$udom} = 1;
9894: }
9895: }
9896: if ($checkid) {
9897: foreach my $udom (keys(%by_id)) {
9898: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
9899: if ($outcome eq 'ok') {
9900: foreach my $id (keys(%{$by_id{$udom}})) {
9901: my $uname = $by_id{$udom}{$id};
9902: $inst_response{$uname.':'.$udom} = $outcome;
9903: }
9904: if (ref($results) eq 'HASH') {
9905: foreach my $uname (keys(%{$results})) {
9906: if (exists($inst_response{$uname.':'.$udom})) {
9907: $inst_response{$uname.':'.$udom} = $outcome;
9908: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9909: }
9910: }
9911: }
9912: }
1.612 raeburn 9913: }
1.615 raeburn 9914: } else {
1.1075.2.99 raeburn 9915: foreach my $udom (keys(%by_username)) {
9916: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
9917: if ($outcome eq 'ok') {
9918: foreach my $uname (keys(%{$by_username{$udom}})) {
9919: $inst_response{$uname.':'.$udom} = $outcome;
9920: }
9921: if (ref($results) eq 'HASH') {
9922: foreach my $uname (keys(%{$results})) {
9923: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9924: }
9925: }
9926: }
9927: }
1.612 raeburn 9928: }
1.1075.2.99 raeburn 9929: } elsif (keys(%{$usershash}) == 1) {
9930: my $user = (keys(%{$usershash}))[0];
9931: my ($uname,$udom) = split(/:/,$user);
9932: if (($udom ne '') && ($uname ne '')) {
9933: if (ref($usershash->{$user}) eq 'HASH') {
9934: if (ref($checks) eq 'HASH') {
9935: if (defined($checks->{'username'})) {
9936: ($inst_response{$user},%{$inst_results->{$user}}) =
9937: &Apache::lonnet::get_instuser($udom,$uname);
9938: } elsif (defined($checks->{'id'})) {
9939: if ($usershash->{$user}->{'id'} ne '') {
9940: ($inst_response{$user},%{$inst_results->{$user}}) =
9941: &Apache::lonnet::get_instuser($udom,undef,
9942: $usershash->{$user}->{'id'});
9943: } else {
9944: ($inst_response{$user},%{$inst_results->{$user}}) =
9945: &Apache::lonnet::get_instuser($udom,$uname);
9946: }
9947: }
9948: } else {
9949: ($inst_response{$user},%{$inst_results->{$user}}) =
9950: &Apache::lonnet::get_instuser($udom,$uname);
9951: return;
9952: }
9953: if (!$got_rules->{$udom}) {
9954: my %domconfig = &Apache::lonnet::get_dom('configuration',
9955: ['usercreation'],$udom);
9956: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9957: foreach my $item ('username','id') {
9958: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9959: $$curr_rules{$udom}{$item} =
9960: $domconfig{'usercreation'}{$item.'_rule'};
9961: }
9962: }
1.585 raeburn 9963: }
1.1075.2.99 raeburn 9964: $got_rules->{$udom} = 1;
1.585 raeburn 9965: }
9966: }
1.1075.2.99 raeburn 9967: } else {
9968: return;
9969: }
9970: } else {
9971: return;
9972: }
9973: foreach my $user (keys(%{$usershash})) {
9974: my ($uname,$udom) = split(/:/,$user);
9975: next if (($udom eq '') || ($uname eq ''));
9976: my $id;
9977: if (ref($inst_results) eq 'HASH') {
9978: if (ref($inst_results->{$user}) eq 'HASH') {
9979: $id = $inst_results->{$user}->{'id'};
9980: }
9981: }
9982: if ($id eq '') {
9983: if (ref($usershash->{$user})) {
9984: $id = $usershash->{$user}->{'id'};
9985: }
1.585 raeburn 9986: }
1.612 raeburn 9987: foreach my $item (keys(%{$checks})) {
9988: if (ref($$curr_rules{$udom}) eq 'HASH') {
9989: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9990: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 9991: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
9992: $$curr_rules{$udom}{$item});
1.612 raeburn 9993: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9994: if ($rule_check{$rule}) {
9995: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 9996: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 9997: if (ref($inst_results) eq 'HASH') {
9998: if (ref($inst_results->{$user}) eq 'HASH') {
9999: if (keys(%{$inst_results->{$user}}) == 0) {
10000: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10001: } elsif ($item eq 'id') {
10002: if ($inst_results->{$user}->{'id'} eq '') {
10003: $$alerts{$item}{$udom}{$uname} = 1;
10004: }
1.615 raeburn 10005: }
1.612 raeburn 10006: }
10007: }
1.615 raeburn 10008: }
10009: last;
1.585 raeburn 10010: }
10011: }
10012: }
10013: }
10014: }
10015: }
10016: }
10017: }
1.612 raeburn 10018: return;
10019: }
10020:
10021: sub user_rule_formats {
10022: my ($domain,$domdesc,$curr_rules,$check) = @_;
10023: my %text = (
10024: 'username' => 'Usernames',
10025: 'id' => 'IDs',
10026: );
10027: my $output;
10028: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10029: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10030: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10031: $output = '<br />'.
10032: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10033: '<span class="LC_cusr_emph">','</span>',$domdesc).
10034: ' <ul>';
1.612 raeburn 10035: foreach my $rule (@{$ruleorder}) {
10036: if (ref($curr_rules) eq 'ARRAY') {
10037: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10038: if (ref($rules->{$rule}) eq 'HASH') {
10039: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10040: $rules->{$rule}{'desc'}.'</li>';
10041: }
10042: }
10043: }
10044: }
10045: $output .= '</ul>';
10046: }
10047: }
10048: return $output;
10049: }
10050:
10051: sub instrule_disallow_msg {
1.615 raeburn 10052: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10053: my $response;
10054: my %text = (
10055: item => 'username',
10056: items => 'usernames',
10057: match => 'matches',
10058: do => 'does',
10059: action => 'a username',
10060: one => 'one',
10061: );
10062: if ($count > 1) {
10063: $text{'item'} = 'usernames';
10064: $text{'match'} ='match';
10065: $text{'do'} = 'do';
10066: $text{'action'} = 'usernames',
10067: $text{'one'} = 'ones';
10068: }
10069: if ($checkitem eq 'id') {
10070: $text{'items'} = 'IDs';
10071: $text{'item'} = 'ID';
10072: $text{'action'} = 'an ID';
1.615 raeburn 10073: if ($count > 1) {
10074: $text{'item'} = 'IDs';
10075: $text{'action'} = 'IDs';
10076: }
1.612 raeburn 10077: }
1.674 bisitz 10078: $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 10079: if ($mode eq 'upload') {
10080: if ($checkitem eq 'username') {
10081: $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'}.");
10082: } elsif ($checkitem eq 'id') {
1.674 bisitz 10083: $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 10084: }
1.669 raeburn 10085: } elsif ($mode eq 'selfcreate') {
10086: if ($checkitem eq 'id') {
10087: $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.");
10088: }
1.615 raeburn 10089: } else {
10090: if ($checkitem eq 'username') {
10091: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10092: } elsif ($checkitem eq 'id') {
10093: $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.");
10094: }
1.612 raeburn 10095: }
10096: return $response;
1.585 raeburn 10097: }
10098:
1.624 raeburn 10099: sub personal_data_fieldtitles {
10100: my %fieldtitles = &Apache::lonlocal::texthash (
10101: id => 'Student/Employee ID',
10102: permanentemail => 'E-mail address',
10103: lastname => 'Last Name',
10104: firstname => 'First Name',
10105: middlename => 'Middle Name',
10106: generation => 'Generation',
10107: gen => 'Generation',
1.765 raeburn 10108: inststatus => 'Affiliation',
1.624 raeburn 10109: );
10110: return %fieldtitles;
10111: }
10112:
1.642 raeburn 10113: sub sorted_inst_types {
10114: my ($dom) = @_;
1.1075.2.70 raeburn 10115: my ($usertypes,$order);
10116: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10117: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10118: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10119: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10120: } else {
10121: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10122: }
1.642 raeburn 10123: my $othertitle = &mt('All users');
10124: if ($env{'request.course.id'}) {
1.668 raeburn 10125: $othertitle = &mt('Any users');
1.642 raeburn 10126: }
10127: my @types;
10128: if (ref($order) eq 'ARRAY') {
10129: @types = @{$order};
10130: }
10131: if (@types == 0) {
10132: if (ref($usertypes) eq 'HASH') {
10133: @types = sort(keys(%{$usertypes}));
10134: }
10135: }
10136: if (keys(%{$usertypes}) > 0) {
10137: $othertitle = &mt('Other users');
10138: }
10139: return ($othertitle,$usertypes,\@types);
10140: }
10141:
1.645 raeburn 10142: sub get_institutional_codes {
10143: my ($settings,$allcourses,$LC_code) = @_;
10144: # Get complete list of course sections to update
10145: my @currsections = ();
10146: my @currxlists = ();
10147: my $coursecode = $$settings{'internal.coursecode'};
10148:
10149: if ($$settings{'internal.sectionnums'} ne '') {
10150: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10151: }
10152:
10153: if ($$settings{'internal.crosslistings'} ne '') {
10154: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10155: }
10156:
10157: if (@currxlists > 0) {
10158: foreach (@currxlists) {
10159: if (m/^([^:]+):(\w*)$/) {
10160: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10161: push(@{$allcourses},$1);
1.645 raeburn 10162: $$LC_code{$1} = $2;
10163: }
10164: }
10165: }
10166: }
10167:
10168: if (@currsections > 0) {
10169: foreach (@currsections) {
10170: if (m/^(\w+):(\w*)$/) {
10171: my $sec = $coursecode.$1;
10172: my $lc_sec = $2;
10173: unless (grep/^$sec$/,@{$allcourses}) {
1.1075.2.119 raeburn 10174: push(@{$allcourses},$sec);
1.645 raeburn 10175: $$LC_code{$sec} = $lc_sec;
10176: }
10177: }
10178: }
10179: }
10180: return;
10181: }
10182:
1.971 raeburn 10183: sub get_standard_codeitems {
10184: return ('Year','Semester','Department','Number','Section');
10185: }
10186:
1.112 bowersj2 10187: =pod
10188:
1.780 raeburn 10189: =head1 Slot Helpers
10190:
10191: =over 4
10192:
10193: =item * sorted_slots()
10194:
1.1040 raeburn 10195: Sorts an array of slot names in order of an optional sort key,
10196: default sort is by slot start time (earliest first).
1.780 raeburn 10197:
10198: Inputs:
10199:
10200: =over 4
10201:
10202: slotsarr - Reference to array of unsorted slot names.
10203:
10204: slots - Reference to hash of hash, where outer hash keys are slot names.
10205:
1.1040 raeburn 10206: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10207:
1.549 albertel 10208: =back
10209:
1.780 raeburn 10210: Returns:
10211:
10212: =over 4
10213:
1.1040 raeburn 10214: sorted - An array of slot names sorted by a specified sort key
10215: (default sort key is start time of the slot).
1.780 raeburn 10216:
10217: =back
10218:
10219: =cut
10220:
10221:
10222: sub sorted_slots {
1.1040 raeburn 10223: my ($slotsarr,$slots,$sortkey) = @_;
10224: if ($sortkey eq '') {
10225: $sortkey = 'starttime';
10226: }
1.780 raeburn 10227: my @sorted;
10228: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10229: @sorted =
10230: sort {
10231: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10232: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10233: }
10234: if (ref($slots->{$a})) { return -1;}
10235: if (ref($slots->{$b})) { return 1;}
10236: return 0;
10237: } @{$slotsarr};
10238: }
10239: return @sorted;
10240: }
10241:
1.1040 raeburn 10242: =pod
10243:
10244: =item * get_future_slots()
10245:
10246: Inputs:
10247:
10248: =over 4
10249:
10250: cnum - course number
10251:
10252: cdom - course domain
10253:
10254: now - current UNIX time
10255:
10256: symb - optional symb
10257:
10258: =back
10259:
10260: Returns:
10261:
10262: =over 4
10263:
10264: sorted_reservable - ref to array of student_schedulable slots currently
10265: reservable, ordered by end date of reservation period.
10266:
10267: reservable_now - ref to hash of student_schedulable slots currently
10268: reservable.
10269:
10270: Keys in inner hash are:
10271: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10272: (b) endreserve: end date of reservation period.
10273: (c) uniqueperiod: start,end dates when slot is to be uniquely
10274: selected.
1.1040 raeburn 10275:
10276: sorted_future - ref to array of student_schedulable slots reservable in
10277: the future, ordered by start date of reservation period.
10278:
10279: future_reservable - ref to hash of student_schedulable slots reservable
10280: in the future.
10281:
10282: Keys in inner hash are:
10283: (a) symb: either blank or symb to which slot use is restricted.
10284: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10285: (c) uniqueperiod: start,end dates when slot is to be uniquely
10286: selected.
1.1040 raeburn 10287:
10288: =back
10289:
10290: =cut
10291:
10292: sub get_future_slots {
10293: my ($cnum,$cdom,$now,$symb) = @_;
10294: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10295: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10296: foreach my $slot (keys(%slots)) {
10297: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10298: if ($symb) {
10299: next if (($slots{$slot}->{'symb'} ne '') &&
10300: ($slots{$slot}->{'symb'} ne $symb));
10301: }
10302: if (($slots{$slot}->{'starttime'} > $now) &&
10303: ($slots{$slot}->{'endtime'} > $now)) {
10304: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10305: my $userallowed = 0;
10306: if ($slots{$slot}->{'allowedsections'}) {
10307: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10308: if (!defined($env{'request.role.sec'})
10309: && grep(/^No section assigned$/,@allowed_sec)) {
10310: $userallowed=1;
10311: } else {
10312: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10313: $userallowed=1;
10314: }
10315: }
10316: unless ($userallowed) {
10317: if (defined($env{'request.course.groups'})) {
10318: my @groups = split(/:/,$env{'request.course.groups'});
10319: foreach my $group (@groups) {
10320: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10321: $userallowed=1;
10322: last;
10323: }
10324: }
10325: }
10326: }
10327: }
10328: if ($slots{$slot}->{'allowedusers'}) {
10329: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10330: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10331: if (grep(/^\Q$user\E$/,@allowed_users)) {
10332: $userallowed = 1;
10333: }
10334: }
10335: next unless($userallowed);
10336: }
10337: my $startreserve = $slots{$slot}->{'startreserve'};
10338: my $endreserve = $slots{$slot}->{'endreserve'};
10339: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10340: my $uniqueperiod;
10341: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10342: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10343: }
1.1040 raeburn 10344: if (($startreserve < $now) &&
10345: (!$endreserve || $endreserve > $now)) {
10346: my $lastres = $endreserve;
10347: if (!$lastres) {
10348: $lastres = $slots{$slot}->{'starttime'};
10349: }
10350: $reservable_now{$slot} = {
10351: symb => $symb,
1.1075.2.104 raeburn 10352: endreserve => $lastres,
10353: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10354: };
10355: } elsif (($startreserve > $now) &&
10356: (!$endreserve || $endreserve > $startreserve)) {
10357: $future_reservable{$slot} = {
10358: symb => $symb,
1.1075.2.104 raeburn 10359: startreserve => $startreserve,
10360: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10361: };
10362: }
10363: }
10364: }
10365: my @unsorted_reservable = keys(%reservable_now);
10366: if (@unsorted_reservable > 0) {
10367: @sorted_reservable =
10368: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10369: }
10370: my @unsorted_future = keys(%future_reservable);
10371: if (@unsorted_future > 0) {
10372: @sorted_future =
10373: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10374: }
10375: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10376: }
1.780 raeburn 10377:
10378: =pod
10379:
1.1057 foxr 10380: =back
10381:
1.549 albertel 10382: =head1 HTTP Helpers
10383:
10384: =over 4
10385:
1.648 raeburn 10386: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10387:
1.258 albertel 10388: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10389: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10390: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10391:
10392: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10393: $possible_names is an ref to an array of form element names. As an example:
10394: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10395: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10396:
10397: =cut
1.1 albertel 10398:
1.6 albertel 10399: sub get_unprocessed_cgi {
1.25 albertel 10400: my ($query,$possible_names)= @_;
1.26 matthew 10401: # $Apache::lonxml::debug=1;
1.356 albertel 10402: foreach my $pair (split(/&/,$query)) {
10403: my ($name, $value) = split(/=/,$pair);
1.369 www 10404: $name = &unescape($name);
1.25 albertel 10405: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10406: $value =~ tr/+/ /;
10407: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10408: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10409: }
1.16 harris41 10410: }
1.6 albertel 10411: }
10412:
1.112 bowersj2 10413: =pod
10414:
1.648 raeburn 10415: =item * &cacheheader()
1.112 bowersj2 10416:
10417: returns cache-controlling header code
10418:
10419: =cut
10420:
1.7 albertel 10421: sub cacheheader {
1.258 albertel 10422: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10423: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10424: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10425: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10426: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10427: return $output;
1.7 albertel 10428: }
10429:
1.112 bowersj2 10430: =pod
10431:
1.648 raeburn 10432: =item * &no_cache($r)
1.112 bowersj2 10433:
10434: specifies header code to not have cache
10435:
10436: =cut
10437:
1.9 albertel 10438: sub no_cache {
1.216 albertel 10439: my ($r) = @_;
10440: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10441: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10442: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10443: $r->no_cache(1);
10444: $r->header_out("Expires" => $date);
10445: $r->header_out("Pragma" => "no-cache");
1.123 www 10446: }
10447:
10448: sub content_type {
1.181 albertel 10449: my ($r,$type,$charset) = @_;
1.299 foxr 10450: if ($r) {
10451: # Note that printout.pl calls this with undef for $r.
10452: &no_cache($r);
10453: }
1.258 albertel 10454: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10455: unless ($charset) {
10456: $charset=&Apache::lonlocal::current_encoding;
10457: }
10458: if ($charset) { $type.='; charset='.$charset; }
10459: if ($r) {
10460: $r->content_type($type);
10461: } else {
10462: print("Content-type: $type\n\n");
10463: }
1.9 albertel 10464: }
1.25 albertel 10465:
1.112 bowersj2 10466: =pod
10467:
1.648 raeburn 10468: =item * &add_to_env($name,$value)
1.112 bowersj2 10469:
1.258 albertel 10470: adds $name to the %env hash with value
1.112 bowersj2 10471: $value, if $name already exists, the entry is converted to an array
10472: reference and $value is added to the array.
10473:
10474: =cut
10475:
1.25 albertel 10476: sub add_to_env {
10477: my ($name,$value)=@_;
1.258 albertel 10478: if (defined($env{$name})) {
10479: if (ref($env{$name})) {
1.25 albertel 10480: #already have multiple values
1.258 albertel 10481: push(@{ $env{$name} },$value);
1.25 albertel 10482: } else {
10483: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10484: my $first=$env{$name};
10485: undef($env{$name});
10486: push(@{ $env{$name} },$first,$value);
1.25 albertel 10487: }
10488: } else {
1.258 albertel 10489: $env{$name}=$value;
1.25 albertel 10490: }
1.31 albertel 10491: }
1.149 albertel 10492:
10493: =pod
10494:
1.648 raeburn 10495: =item * &get_env_multiple($name)
1.149 albertel 10496:
1.258 albertel 10497: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10498: values may be defined and end up as an array ref.
10499:
10500: returns an array of values
10501:
10502: =cut
10503:
10504: sub get_env_multiple {
10505: my ($name) = @_;
10506: my @values;
1.258 albertel 10507: if (defined($env{$name})) {
1.149 albertel 10508: # exists is it an array
1.258 albertel 10509: if (ref($env{$name})) {
10510: @values=@{ $env{$name} };
1.149 albertel 10511: } else {
1.258 albertel 10512: $values[0]=$env{$name};
1.149 albertel 10513: }
10514: }
10515: return(@values);
10516: }
10517:
1.660 raeburn 10518: sub ask_for_embedded_content {
10519: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10520: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10521: %currsubfile,%unused,$rem);
1.1071 raeburn 10522: my $counter = 0;
10523: my $numnew = 0;
1.987 raeburn 10524: my $numremref = 0;
10525: my $numinvalid = 0;
10526: my $numpathchg = 0;
10527: my $numexisting = 0;
1.1071 raeburn 10528: my $numunused = 0;
10529: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10530: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10531: my $heading = &mt('Upload embedded files');
10532: my $buttontext = &mt('Upload');
10533:
1.1075.2.11 raeburn 10534: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10535: if ($actionurl eq '/adm/dependencies') {
10536: $navmap = Apache::lonnavmaps::navmap->new();
10537: }
10538: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10539: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10540: }
1.1075.2.35 raeburn 10541: if (($actionurl eq '/adm/portfolio') ||
10542: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10543: my $current_path='/';
10544: if ($env{'form.currentpath'}) {
10545: $current_path = $env{'form.currentpath'};
10546: }
10547: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10548: $udom = $cdom;
10549: $uname = $cnum;
1.984 raeburn 10550: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10551: } else {
10552: $udom = $env{'user.domain'};
10553: $uname = $env{'user.name'};
10554: $url = '/userfiles/portfolio';
10555: }
1.987 raeburn 10556: $toplevel = $url.'/';
1.984 raeburn 10557: $url .= $current_path;
10558: $getpropath = 1;
1.987 raeburn 10559: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10560: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10561: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10562: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10563: $toplevel = $url;
1.984 raeburn 10564: if ($rest ne '') {
1.987 raeburn 10565: $url .= $rest;
10566: }
10567: } elsif ($actionurl eq '/adm/coursedocs') {
10568: if (ref($args) eq 'HASH') {
1.1071 raeburn 10569: $url = $args->{'docs_url'};
10570: $toplevel = $url;
1.1075.2.11 raeburn 10571: if ($args->{'context'} eq 'paste') {
10572: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10573: ($path) =
10574: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10575: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10576: $fileloc =~ s{^/}{};
10577: }
1.1071 raeburn 10578: }
10579: } elsif ($actionurl eq '/adm/dependencies') {
10580: if ($env{'request.course.id'} ne '') {
10581: if (ref($args) eq 'HASH') {
10582: $url = $args->{'docs_url'};
10583: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10584: $toplevel = $url;
10585: unless ($toplevel =~ m{^/}) {
10586: $toplevel = "/$url";
10587: }
1.1075.2.11 raeburn 10588: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10589: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10590: $path = $1;
10591: } else {
10592: ($path) =
10593: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10594: }
1.1075.2.79 raeburn 10595: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10596: $fileloc = $toplevel;
10597: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10598: my ($udom,$uname,$fname) =
10599: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10600: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10601: } else {
10602: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10603: }
1.1071 raeburn 10604: $fileloc =~ s{^/}{};
10605: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10606: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10607: }
1.987 raeburn 10608: }
1.1075.2.35 raeburn 10609: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10610: $udom = $cdom;
10611: $uname = $cnum;
10612: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10613: $toplevel = $url;
10614: $path = $url;
10615: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10616: $fileloc =~ s{^/}{};
10617: }
10618: foreach my $file (keys(%{$allfiles})) {
10619: my $embed_file;
10620: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10621: $embed_file = $1;
10622: } else {
10623: $embed_file = $file;
10624: }
1.1075.2.55 raeburn 10625: my ($absolutepath,$cleaned_file);
10626: if ($embed_file =~ m{^\w+://}) {
10627: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10628: $newfiles{$cleaned_file} = 1;
10629: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10630: } else {
1.1075.2.55 raeburn 10631: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10632: if ($embed_file =~ m{^/}) {
10633: $absolutepath = $embed_file;
10634: }
1.1075.2.47 raeburn 10635: if ($cleaned_file =~ m{/}) {
10636: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10637: $path = &check_for_traversal($path,$url,$toplevel);
10638: my $item = $fname;
10639: if ($path ne '') {
10640: $item = $path.'/'.$fname;
10641: $subdependencies{$path}{$fname} = 1;
10642: } else {
10643: $dependencies{$item} = 1;
10644: }
10645: if ($absolutepath) {
10646: $mapping{$item} = $absolutepath;
10647: } else {
10648: $mapping{$item} = $embed_file;
10649: }
10650: } else {
10651: $dependencies{$embed_file} = 1;
10652: if ($absolutepath) {
1.1075.2.47 raeburn 10653: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10654: } else {
1.1075.2.47 raeburn 10655: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10656: }
10657: }
1.984 raeburn 10658: }
10659: }
1.1071 raeburn 10660: my $dirptr = 16384;
1.984 raeburn 10661: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10662: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10663: if (($actionurl eq '/adm/portfolio') ||
10664: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10665: my ($sublistref,$listerror) =
10666: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10667: if (ref($sublistref) eq 'ARRAY') {
10668: foreach my $line (@{$sublistref}) {
10669: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10670: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10671: }
1.984 raeburn 10672: }
1.987 raeburn 10673: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10674: if (opendir(my $dir,$url.'/'.$path)) {
10675: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10676: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10677: }
1.1075.2.11 raeburn 10678: } elsif (($actionurl eq '/adm/dependencies') ||
10679: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10680: ($args->{'context'} eq 'paste')) ||
10681: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10682: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10683: my $dir;
10684: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10685: $dir = $fileloc;
10686: } else {
10687: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10688: }
1.1071 raeburn 10689: if ($dir ne '') {
10690: my ($sublistref,$listerror) =
10691: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10692: if (ref($sublistref) eq 'ARRAY') {
10693: foreach my $line (@{$sublistref}) {
10694: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10695: undef,$mtime)=split(/\&/,$line,12);
10696: unless (($testdir&$dirptr) ||
10697: ($file_name =~ /^\.\.?$/)) {
10698: $currsubfile{$path}{$file_name} = [$size,$mtime];
10699: }
10700: }
10701: }
10702: }
1.984 raeburn 10703: }
10704: }
10705: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10706: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10707: my $item = $path.'/'.$file;
10708: unless ($mapping{$item} eq $item) {
10709: $pathchanges{$item} = 1;
10710: }
10711: $existing{$item} = 1;
10712: $numexisting ++;
10713: } else {
10714: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10715: }
10716: }
1.1071 raeburn 10717: if ($actionurl eq '/adm/dependencies') {
10718: foreach my $path (keys(%currsubfile)) {
10719: if (ref($currsubfile{$path}) eq 'HASH') {
10720: foreach my $file (keys(%{$currsubfile{$path}})) {
10721: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10722: next if (($rem ne '') &&
10723: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10724: (ref($navmap) &&
10725: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10726: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10727: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10728: $unused{$path.'/'.$file} = 1;
10729: }
10730: }
10731: }
10732: }
10733: }
1.984 raeburn 10734: }
1.987 raeburn 10735: my %currfile;
1.1075.2.35 raeburn 10736: if (($actionurl eq '/adm/portfolio') ||
10737: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10738: my ($dirlistref,$listerror) =
10739: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10740: if (ref($dirlistref) eq 'ARRAY') {
10741: foreach my $line (@{$dirlistref}) {
10742: my ($file_name,$rest) = split(/\&/,$line,2);
10743: $currfile{$file_name} = 1;
10744: }
1.984 raeburn 10745: }
1.987 raeburn 10746: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10747: if (opendir(my $dir,$url)) {
1.987 raeburn 10748: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10749: map {$currfile{$_} = 1;} @dir_list;
10750: }
1.1075.2.11 raeburn 10751: } elsif (($actionurl eq '/adm/dependencies') ||
10752: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10753: ($args->{'context'} eq 'paste')) ||
10754: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10755: if ($env{'request.course.id'} ne '') {
10756: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10757: if ($dir ne '') {
10758: my ($dirlistref,$listerror) =
10759: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10760: if (ref($dirlistref) eq 'ARRAY') {
10761: foreach my $line (@{$dirlistref}) {
10762: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10763: $size,undef,$mtime)=split(/\&/,$line,12);
10764: unless (($testdir&$dirptr) ||
10765: ($file_name =~ /^\.\.?$/)) {
10766: $currfile{$file_name} = [$size,$mtime];
10767: }
10768: }
10769: }
10770: }
10771: }
1.984 raeburn 10772: }
10773: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10774: if (exists($currfile{$file})) {
1.987 raeburn 10775: unless ($mapping{$file} eq $file) {
10776: $pathchanges{$file} = 1;
10777: }
10778: $existing{$file} = 1;
10779: $numexisting ++;
10780: } else {
1.984 raeburn 10781: $newfiles{$file} = 1;
10782: }
10783: }
1.1071 raeburn 10784: foreach my $file (keys(%currfile)) {
10785: unless (($file eq $filename) ||
10786: ($file eq $filename.'.bak') ||
10787: ($dependencies{$file})) {
1.1075.2.11 raeburn 10788: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10789: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10790: next if (($rem ne '') &&
10791: (($env{"httpref.$rem".$file} ne '') ||
10792: (ref($navmap) &&
10793: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10794: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10795: ($navmap->getResourceByUrl($rem.$1)))))));
10796: }
1.1075.2.11 raeburn 10797: }
1.1071 raeburn 10798: $unused{$file} = 1;
10799: }
10800: }
1.1075.2.11 raeburn 10801: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10802: ($args->{'context'} eq 'paste')) {
10803: $counter = scalar(keys(%existing));
10804: $numpathchg = scalar(keys(%pathchanges));
10805: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10806: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10807: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10808: $counter = scalar(keys(%existing));
10809: $numpathchg = scalar(keys(%pathchanges));
10810: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10811: }
1.984 raeburn 10812: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10813: if ($actionurl eq '/adm/dependencies') {
10814: next if ($embed_file =~ m{^\w+://});
10815: }
1.660 raeburn 10816: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10817: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10818: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10819: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10820: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10821: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10822: }
1.1075.2.35 raeburn 10823: $upload_output .= '</td>';
1.1071 raeburn 10824: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10825: $upload_output.='<td align="right">'.
10826: '<span class="LC_info LC_fontsize_medium">'.
10827: &mt("URL points to web address").'</span>';
1.987 raeburn 10828: $numremref++;
1.660 raeburn 10829: } elsif ($args->{'error_on_invalid_names'}
10830: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10831: $upload_output.='<td align="right"><span class="LC_warning">'.
10832: &mt('Invalid characters').'</span>';
1.987 raeburn 10833: $numinvalid++;
1.660 raeburn 10834: } else {
1.1075.2.35 raeburn 10835: $upload_output .= '<td>'.
10836: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10837: $embed_file,\%mapping,
1.1071 raeburn 10838: $allfiles,$codebase,'upload');
10839: $counter ++;
10840: $numnew ++;
1.987 raeburn 10841: }
10842: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10843: }
10844: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10845: if ($actionurl eq '/adm/dependencies') {
10846: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10847: $modify_output .= &start_data_table_row().
10848: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10849: '<img src="'.&icon($embed_file).'" border="0" />'.
10850: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10851: '<td>'.$size.'</td>'.
10852: '<td>'.$mtime.'</td>'.
10853: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10854: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10855: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10856: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10857: &embedded_file_element('upload_embedded',$counter,
10858: $embed_file,\%mapping,
10859: $allfiles,$codebase,'modify').
10860: '</div></td>'.
10861: &end_data_table_row()."\n";
10862: $counter ++;
10863: } else {
10864: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10865: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10866: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10867: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10868: &Apache::loncommon::end_data_table_row()."\n";
10869: }
10870: }
10871: my $delidx = $counter;
10872: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10873: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10874: $delete_output .= &start_data_table_row().
10875: '<td><img src="'.&icon($oldfile).'" />'.
10876: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10877: '<td>'.$size.'</td>'.
10878: '<td>'.$mtime.'</td>'.
10879: '<td><label><input type="checkbox" name="del_upload_dep" '.
10880: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10881: &embedded_file_element('upload_embedded',$delidx,
10882: $oldfile,\%mapping,$allfiles,
10883: $codebase,'delete').'</td>'.
10884: &end_data_table_row()."\n";
10885: $numunused ++;
10886: $delidx ++;
1.987 raeburn 10887: }
10888: if ($upload_output) {
10889: $upload_output = &start_data_table().
10890: $upload_output.
10891: &end_data_table()."\n";
10892: }
1.1071 raeburn 10893: if ($modify_output) {
10894: $modify_output = &start_data_table().
10895: &start_data_table_header_row().
10896: '<th>'.&mt('File').'</th>'.
10897: '<th>'.&mt('Size (KB)').'</th>'.
10898: '<th>'.&mt('Modified').'</th>'.
10899: '<th>'.&mt('Upload replacement?').'</th>'.
10900: &end_data_table_header_row().
10901: $modify_output.
10902: &end_data_table()."\n";
10903: }
10904: if ($delete_output) {
10905: $delete_output = &start_data_table().
10906: &start_data_table_header_row().
10907: '<th>'.&mt('File').'</th>'.
10908: '<th>'.&mt('Size (KB)').'</th>'.
10909: '<th>'.&mt('Modified').'</th>'.
10910: '<th>'.&mt('Delete?').'</th>'.
10911: &end_data_table_header_row().
10912: $delete_output.
10913: &end_data_table()."\n";
10914: }
1.987 raeburn 10915: my $applies = 0;
10916: if ($numremref) {
10917: $applies ++;
10918: }
10919: if ($numinvalid) {
10920: $applies ++;
10921: }
10922: if ($numexisting) {
10923: $applies ++;
10924: }
1.1071 raeburn 10925: if ($counter || $numunused) {
1.987 raeburn 10926: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10927: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10928: $state.'<h3>'.$heading.'</h3>';
10929: if ($actionurl eq '/adm/dependencies') {
10930: if ($numnew) {
10931: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10932: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10933: $upload_output.'<br />'."\n";
10934: }
10935: if ($numexisting) {
10936: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10937: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10938: $modify_output.'<br />'."\n";
10939: $buttontext = &mt('Save changes');
10940: }
10941: if ($numunused) {
10942: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10943: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10944: $delete_output.'<br />'."\n";
10945: $buttontext = &mt('Save changes');
10946: }
10947: } else {
10948: $output .= $upload_output.'<br />'."\n";
10949: }
10950: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10951: $counter.'" />'."\n";
10952: if ($actionurl eq '/adm/dependencies') {
10953: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10954: $numnew.'" />'."\n";
10955: } elsif ($actionurl eq '') {
1.987 raeburn 10956: $output .= '<input type="hidden" name="phase" value="three" />';
10957: }
10958: } elsif ($applies) {
10959: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10960: if ($applies > 1) {
10961: $output .=
1.1075.2.35 raeburn 10962: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10963: if ($numremref) {
10964: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10965: }
10966: if ($numinvalid) {
10967: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10968: }
10969: if ($numexisting) {
10970: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10971: }
10972: $output .= '</ul><br />';
10973: } elsif ($numremref) {
10974: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10975: } elsif ($numinvalid) {
10976: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10977: } elsif ($numexisting) {
10978: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10979: }
10980: $output .= $upload_output.'<br />';
10981: }
10982: my ($pathchange_output,$chgcount);
1.1071 raeburn 10983: $chgcount = $counter;
1.987 raeburn 10984: if (keys(%pathchanges) > 0) {
10985: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10986: if ($counter) {
1.987 raeburn 10987: $output .= &embedded_file_element('pathchange',$chgcount,
10988: $embed_file,\%mapping,
1.1071 raeburn 10989: $allfiles,$codebase,'change');
1.987 raeburn 10990: } else {
10991: $pathchange_output .=
10992: &start_data_table_row().
10993: '<td><input type ="checkbox" name="namechange" value="'.
10994: $chgcount.'" checked="checked" /></td>'.
10995: '<td>'.$mapping{$embed_file}.'</td>'.
10996: '<td>'.$embed_file.
10997: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10998: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10999: '</td>'.&end_data_table_row();
1.660 raeburn 11000: }
1.987 raeburn 11001: $numpathchg ++;
11002: $chgcount ++;
1.660 raeburn 11003: }
11004: }
1.1075.2.35 raeburn 11005: if (($counter) || ($numunused)) {
1.987 raeburn 11006: if ($numpathchg) {
11007: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11008: $numpathchg.'" />'."\n";
11009: }
11010: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11011: ($actionurl eq '/adm/imsimport')) {
11012: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11013: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11014: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11015: } elsif ($actionurl eq '/adm/dependencies') {
11016: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11017: }
1.1075.2.35 raeburn 11018: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11019: } elsif ($numpathchg) {
11020: my %pathchange = ();
11021: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11022: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11023: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11024: }
1.987 raeburn 11025: }
1.1071 raeburn 11026: return ($output,$counter,$numpathchg);
1.987 raeburn 11027: }
11028:
1.1075.2.47 raeburn 11029: =pod
11030:
11031: =item * clean_path($name)
11032:
11033: Performs clean-up of directories, subdirectories and filename in an
11034: embedded object, referenced in an HTML file which is being uploaded
11035: to a course or portfolio, where
11036: "Upload embedded images/multimedia files if HTML file" checkbox was
11037: checked.
11038:
11039: Clean-up is similar to replacements in lonnet::clean_filename()
11040: except each / between sub-directory and next level is preserved.
11041:
11042: =cut
11043:
11044: sub clean_path {
11045: my ($embed_file) = @_;
11046: $embed_file =~s{^/+}{};
11047: my @contents;
11048: if ($embed_file =~ m{/}) {
11049: @contents = split(/\//,$embed_file);
11050: } else {
11051: @contents = ($embed_file);
11052: }
11053: my $lastidx = scalar(@contents)-1;
11054: for (my $i=0; $i<=$lastidx; $i++) {
11055: $contents[$i]=~s{\\}{/}g;
11056: $contents[$i]=~s/\s+/\_/g;
11057: $contents[$i]=~s{[^/\w\.\-]}{}g;
11058: if ($i == $lastidx) {
11059: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11060: }
11061: }
11062: if ($lastidx > 0) {
11063: return join('/',@contents);
11064: } else {
11065: return $contents[0];
11066: }
11067: }
11068:
1.987 raeburn 11069: sub embedded_file_element {
1.1071 raeburn 11070: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11071: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11072: (ref($codebase) eq 'HASH'));
11073: my $output;
1.1071 raeburn 11074: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11075: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11076: }
11077: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11078: &escape($embed_file).'" />';
11079: unless (($context eq 'upload_embedded') &&
11080: ($mapping->{$embed_file} eq $embed_file)) {
11081: $output .='
11082: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11083: }
11084: my $attrib;
11085: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11086: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11087: }
11088: $output .=
11089: "\n\t\t".
11090: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11091: $attrib.'" />';
11092: if (exists($codebase->{$mapping->{$embed_file}})) {
11093: $output .=
11094: "\n\t\t".
11095: '<input name="codebase_'.$num.'" type="hidden" value="'.
11096: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11097: }
1.987 raeburn 11098: return $output;
1.660 raeburn 11099: }
11100:
1.1071 raeburn 11101: sub get_dependency_details {
11102: my ($currfile,$currsubfile,$embed_file) = @_;
11103: my ($size,$mtime,$showsize,$showmtime);
11104: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11105: if ($embed_file =~ m{/}) {
11106: my ($path,$fname) = split(/\//,$embed_file);
11107: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11108: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11109: }
11110: } else {
11111: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11112: ($size,$mtime) = @{$currfile->{$embed_file}};
11113: }
11114: }
11115: $showsize = $size/1024.0;
11116: $showsize = sprintf("%.1f",$showsize);
11117: if ($mtime > 0) {
11118: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11119: }
11120: }
11121: return ($showsize,$showmtime);
11122: }
11123:
11124: sub ask_embedded_js {
11125: return <<"END";
11126: <script type="text/javascript"">
11127: // <![CDATA[
11128: function toggleBrowse(counter) {
11129: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11130: var fileid = document.getElementById('embedded_item_'+counter);
11131: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11132: if (chkboxid.checked == true) {
11133: uploaddivid.style.display='block';
11134: } else {
11135: uploaddivid.style.display='none';
11136: fileid.value = '';
11137: }
11138: }
11139: // ]]>
11140: </script>
11141:
11142: END
11143: }
11144:
1.661 raeburn 11145: sub upload_embedded {
11146: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11147: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11148: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11149: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11150: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11151: my $orig_uploaded_filename =
11152: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11153: foreach my $type ('orig','ref','attrib','codebase') {
11154: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11155: $env{'form.embedded_'.$type.'_'.$i} =
11156: &unescape($env{'form.embedded_'.$type.'_'.$i});
11157: }
11158: }
1.661 raeburn 11159: my ($path,$fname) =
11160: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11161: # no path, whole string is fname
11162: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11163: $fname = &Apache::lonnet::clean_filename($fname);
11164: # See if there is anything left
11165: next if ($fname eq '');
11166:
11167: # Check if file already exists as a file or directory.
11168: my ($state,$msg);
11169: if ($context eq 'portfolio') {
11170: my $port_path = $dirpath;
11171: if ($group ne '') {
11172: $port_path = "groups/$group/$port_path";
11173: }
1.987 raeburn 11174: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11175: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11176: $dir_root,$port_path,$disk_quota,
11177: $current_disk_usage,$uname,$udom);
11178: if ($state eq 'will_exceed_quota'
1.984 raeburn 11179: || $state eq 'file_locked') {
1.661 raeburn 11180: $output .= $msg;
11181: next;
11182: }
11183: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11184: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11185: if ($state eq 'exists') {
11186: $output .= $msg;
11187: next;
11188: }
11189: }
11190: # Check if extension is valid
11191: if (($fname =~ /\.(\w+)$/) &&
11192: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11193: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11194: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11195: next;
11196: } elsif (($fname =~ /\.(\w+)$/) &&
11197: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11198: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11199: next;
11200: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11201: $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 11202: next;
11203: }
11204: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11205: my $subdir = $path;
11206: $subdir =~ s{/+$}{};
1.661 raeburn 11207: if ($context eq 'portfolio') {
1.984 raeburn 11208: my $result;
11209: if ($state eq 'existingfile') {
11210: $result=
11211: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11212: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11213: } else {
1.984 raeburn 11214: $result=
11215: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11216: $dirpath.
1.1075.2.35 raeburn 11217: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11218: if ($result !~ m|^/uploaded/|) {
11219: $output .= '<span class="LC_error">'
11220: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11221: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11222: .'</span><br />';
11223: next;
11224: } else {
1.987 raeburn 11225: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11226: $path.$fname.'</span>').'<br />';
1.984 raeburn 11227: }
1.661 raeburn 11228: }
1.1075.2.35 raeburn 11229: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11230: my $extendedsubdir = $dirpath.'/'.$subdir;
11231: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11232: my $result =
1.1075.2.35 raeburn 11233: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11234: if ($result !~ m|^/uploaded/|) {
11235: $output .= '<span class="LC_error">'
11236: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11237: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11238: .'</span><br />';
11239: next;
11240: } else {
11241: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11242: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11243: if ($context eq 'syllabus') {
11244: &Apache::lonnet::make_public_indefinitely($result);
11245: }
1.987 raeburn 11246: }
1.661 raeburn 11247: } else {
11248: # Save the file
11249: my $target = $env{'form.embedded_item_'.$i};
11250: my $fullpath = $dir_root.$dirpath.'/'.$path;
11251: my $dest = $fullpath.$fname;
11252: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11253: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11254: my $count;
11255: my $filepath = $dir_root;
1.1027 raeburn 11256: foreach my $subdir (@parts) {
11257: $filepath .= "/$subdir";
11258: if (!-e $filepath) {
1.661 raeburn 11259: mkdir($filepath,0770);
11260: }
11261: }
11262: my $fh;
11263: if (!open($fh,'>'.$dest)) {
11264: &Apache::lonnet::logthis('Failed to create '.$dest);
11265: $output .= '<span class="LC_error">'.
1.1071 raeburn 11266: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11267: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11268: '</span><br />';
11269: } else {
11270: if (!print $fh $env{'form.embedded_item_'.$i}) {
11271: &Apache::lonnet::logthis('Failed to write to '.$dest);
11272: $output .= '<span class="LC_error">'.
1.1071 raeburn 11273: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11274: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11275: '</span><br />';
11276: } else {
1.987 raeburn 11277: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11278: $url.'</span>').'<br />';
11279: unless ($context eq 'testbank') {
11280: $footer .= &mt('View embedded file: [_1]',
11281: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11282: }
11283: }
11284: close($fh);
11285: }
11286: }
11287: if ($env{'form.embedded_ref_'.$i}) {
11288: $pathchange{$i} = 1;
11289: }
11290: }
11291: if ($output) {
11292: $output = '<p>'.$output.'</p>';
11293: }
11294: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11295: $returnflag = 'ok';
1.1071 raeburn 11296: my $numpathchgs = scalar(keys(%pathchange));
11297: if ($numpathchgs > 0) {
1.987 raeburn 11298: if ($context eq 'portfolio') {
11299: $output .= '<p>'.&mt('or').'</p>';
11300: } elsif ($context eq 'testbank') {
1.1071 raeburn 11301: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11302: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11303: $returnflag = 'modify_orightml';
11304: }
11305: }
1.1071 raeburn 11306: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11307: }
11308:
11309: sub modify_html_form {
11310: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11311: my $end = 0;
11312: my $modifyform;
11313: if ($context eq 'upload_embedded') {
11314: return unless (ref($pathchange) eq 'HASH');
11315: if ($env{'form.number_embedded_items'}) {
11316: $end += $env{'form.number_embedded_items'};
11317: }
11318: if ($env{'form.number_pathchange_items'}) {
11319: $end += $env{'form.number_pathchange_items'};
11320: }
11321: if ($end) {
11322: for (my $i=0; $i<$end; $i++) {
11323: if ($i < $env{'form.number_embedded_items'}) {
11324: next unless($pathchange->{$i});
11325: }
11326: $modifyform .=
11327: &start_data_table_row().
11328: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11329: 'checked="checked" /></td>'.
11330: '<td>'.$env{'form.embedded_ref_'.$i}.
11331: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11332: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11333: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11334: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11335: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11336: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11337: '<td>'.$env{'form.embedded_orig_'.$i}.
11338: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11339: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11340: &end_data_table_row();
1.1071 raeburn 11341: }
1.987 raeburn 11342: }
11343: } else {
11344: $modifyform = $pathchgtable;
11345: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11346: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11347: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11348: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11349: }
11350: }
11351: if ($modifyform) {
1.1071 raeburn 11352: if ($actionurl eq '/adm/dependencies') {
11353: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11354: }
1.987 raeburn 11355: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11356: '<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".
11357: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11358: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11359: '</ol></p>'."\n".'<p>'.
11360: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11361: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11362: &start_data_table()."\n".
11363: &start_data_table_header_row().
11364: '<th>'.&mt('Change?').'</th>'.
11365: '<th>'.&mt('Current reference').'</th>'.
11366: '<th>'.&mt('Required reference').'</th>'.
11367: &end_data_table_header_row()."\n".
11368: $modifyform.
11369: &end_data_table().'<br />'."\n".$hiddenstate.
11370: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11371: '</form>'."\n";
11372: }
11373: return;
11374: }
11375:
11376: sub modify_html_refs {
1.1075.2.35 raeburn 11377: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11378: my $container;
11379: if ($context eq 'portfolio') {
11380: $container = $env{'form.container'};
11381: } elsif ($context eq 'coursedoc') {
11382: $container = $env{'form.primaryurl'};
1.1071 raeburn 11383: } elsif ($context eq 'manage_dependencies') {
11384: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11385: $container = "/$container";
1.1075.2.35 raeburn 11386: } elsif ($context eq 'syllabus') {
11387: $container = $url;
1.987 raeburn 11388: } else {
1.1027 raeburn 11389: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11390: }
11391: my (%allfiles,%codebase,$output,$content);
11392: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11393: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11394: if (wantarray) {
11395: return ('',0,0);
11396: } else {
11397: return;
11398: }
11399: }
11400: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11401: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11402: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11403: if (wantarray) {
11404: return ('',0,0);
11405: } else {
11406: return;
11407: }
11408: }
1.987 raeburn 11409: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11410: if ($content eq '-1') {
11411: if (wantarray) {
11412: return ('',0,0);
11413: } else {
11414: return;
11415: }
11416: }
1.987 raeburn 11417: } else {
1.1071 raeburn 11418: unless ($container =~ /^\Q$dir_root\E/) {
11419: if (wantarray) {
11420: return ('',0,0);
11421: } else {
11422: return;
11423: }
11424: }
1.1075.2.128! raeburn 11425: if (open(my $fh,'<',$container)) {
1.987 raeburn 11426: $content = join('', <$fh>);
11427: close($fh);
11428: } else {
1.1071 raeburn 11429: if (wantarray) {
11430: return ('',0,0);
11431: } else {
11432: return;
11433: }
1.987 raeburn 11434: }
11435: }
11436: my ($count,$codebasecount) = (0,0);
11437: my $mm = new File::MMagic;
11438: my $mime_type = $mm->checktype_contents($content);
11439: if ($mime_type eq 'text/html') {
11440: my $parse_result =
11441: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11442: \%codebase,\$content);
11443: if ($parse_result eq 'ok') {
11444: foreach my $i (@changes) {
11445: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11446: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11447: if ($allfiles{$ref}) {
11448: my $newname = $orig;
11449: my ($attrib_regexp,$codebase);
1.1006 raeburn 11450: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11451: if ($attrib_regexp =~ /:/) {
11452: $attrib_regexp =~ s/\:/|/g;
11453: }
11454: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11455: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11456: $count += $numchg;
1.1075.2.35 raeburn 11457: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11458: delete($allfiles{$ref});
1.987 raeburn 11459: }
11460: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11461: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11462: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11463: $codebasecount ++;
11464: }
11465: }
11466: }
1.1075.2.35 raeburn 11467: my $skiprewrites;
1.987 raeburn 11468: if ($count || $codebasecount) {
11469: my $saveresult;
1.1071 raeburn 11470: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11471: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11472: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11473: if ($url eq $container) {
11474: my ($fname) = ($container =~ m{/([^/]+)$});
11475: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11476: $count,'<span class="LC_filename">'.
1.1071 raeburn 11477: $fname.'</span>').'</p>';
1.987 raeburn 11478: } else {
11479: $output = '<p class="LC_error">'.
11480: &mt('Error: update failed for: [_1].',
11481: '<span class="LC_filename">'.
11482: $container.'</span>').'</p>';
11483: }
1.1075.2.35 raeburn 11484: if ($context eq 'syllabus') {
11485: unless ($saveresult eq 'ok') {
11486: $skiprewrites = 1;
11487: }
11488: }
1.987 raeburn 11489: } else {
1.1075.2.128! raeburn 11490: if (open(my $fh,'>',$container)) {
1.987 raeburn 11491: print $fh $content;
11492: close($fh);
11493: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11494: $count,'<span class="LC_filename">'.
11495: $container.'</span>').'</p>';
1.661 raeburn 11496: } else {
1.987 raeburn 11497: $output = '<p class="LC_error">'.
11498: &mt('Error: could not update [_1].',
11499: '<span class="LC_filename">'.
11500: $container.'</span>').'</p>';
1.661 raeburn 11501: }
11502: }
11503: }
1.1075.2.35 raeburn 11504: if (($context eq 'syllabus') && (!$skiprewrites)) {
11505: my ($actionurl,$state);
11506: $actionurl = "/public/$udom/$uname/syllabus";
11507: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11508: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11509: \%codebase,
11510: {'context' => 'rewrites',
11511: 'ignore_remote_references' => 1,});
11512: if (ref($mapping) eq 'HASH') {
11513: my $rewrites = 0;
11514: foreach my $key (keys(%{$mapping})) {
11515: next if ($key =~ m{^https?://});
11516: my $ref = $mapping->{$key};
11517: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11518: my $attrib;
11519: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11520: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11521: }
11522: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11523: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11524: $rewrites += $numchg;
11525: }
11526: }
11527: if ($rewrites) {
11528: my $saveresult;
11529: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11530: if ($url eq $container) {
11531: my ($fname) = ($container =~ m{/([^/]+)$});
11532: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11533: $count,'<span class="LC_filename">'.
11534: $fname.'</span>').'</p>';
11535: } else {
11536: $output .= '<p class="LC_error">'.
11537: &mt('Error: could not update links in [_1].',
11538: '<span class="LC_filename">'.
11539: $container.'</span>').'</p>';
11540:
11541: }
11542: }
11543: }
11544: }
1.987 raeburn 11545: } else {
11546: &logthis('Failed to parse '.$container.
11547: ' to modify references: '.$parse_result);
1.661 raeburn 11548: }
11549: }
1.1071 raeburn 11550: if (wantarray) {
11551: return ($output,$count,$codebasecount);
11552: } else {
11553: return $output;
11554: }
1.661 raeburn 11555: }
11556:
11557: sub check_for_existing {
11558: my ($path,$fname,$element) = @_;
11559: my ($state,$msg);
11560: if (-d $path.'/'.$fname) {
11561: $state = 'exists';
11562: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11563: } elsif (-e $path.'/'.$fname) {
11564: $state = 'exists';
11565: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11566: }
11567: if ($state eq 'exists') {
11568: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11569: }
11570: return ($state,$msg);
11571: }
11572:
11573: sub check_for_upload {
11574: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11575: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11576: my $filesize = length($env{'form.'.$element});
11577: if (!$filesize) {
11578: my $msg = '<span class="LC_error">'.
11579: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11580: '<span class="LC_filename">'.$fname.'</span>',
11581: $filesize).'<br />'.
1.1007 raeburn 11582: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11583: '</span>';
11584: return ('zero_bytes',$msg);
11585: }
11586: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11587: my $getpropath = 1;
1.1021 raeburn 11588: my ($dirlistref,$listerror) =
11589: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11590: my $found_file = 0;
11591: my $locked_file = 0;
1.991 raeburn 11592: my @lockers;
11593: my $navmap;
11594: if ($env{'request.course.id'}) {
11595: $navmap = Apache::lonnavmaps::navmap->new();
11596: }
1.1021 raeburn 11597: if (ref($dirlistref) eq 'ARRAY') {
11598: foreach my $line (@{$dirlistref}) {
11599: my ($file_name,$rest)=split(/\&/,$line,2);
11600: if ($file_name eq $fname){
11601: $file_name = $path.$file_name;
11602: if ($group ne '') {
11603: $file_name = $group.$file_name;
11604: }
11605: $found_file = 1;
11606: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11607: foreach my $lock (@lockers) {
11608: if (ref($lock) eq 'ARRAY') {
11609: my ($symb,$crsid) = @{$lock};
11610: if ($crsid eq $env{'request.course.id'}) {
11611: if (ref($navmap)) {
11612: my $res = $navmap->getBySymb($symb);
11613: foreach my $part (@{$res->parts()}) {
11614: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11615: unless (($slot_status == $res->RESERVED) ||
11616: ($slot_status == $res->RESERVED_LOCATION)) {
11617: $locked_file = 1;
11618: }
1.991 raeburn 11619: }
1.1021 raeburn 11620: } else {
11621: $locked_file = 1;
1.991 raeburn 11622: }
11623: } else {
11624: $locked_file = 1;
11625: }
11626: }
1.1021 raeburn 11627: }
11628: } else {
11629: my @info = split(/\&/,$rest);
11630: my $currsize = $info[6]/1000;
11631: if ($currsize < $filesize) {
11632: my $extra = $filesize - $currsize;
11633: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11634: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11635: &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 11636: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11637: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11638: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11639: return ('will_exceed_quota',$msg);
11640: }
1.984 raeburn 11641: }
11642: }
1.661 raeburn 11643: }
11644: }
11645: }
11646: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11647: my $msg = '<p class="LC_warning">'.
11648: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11649: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11650: return ('will_exceed_quota',$msg);
11651: } elsif ($found_file) {
11652: if ($locked_file) {
1.1075.2.69 raeburn 11653: my $msg = '<p class="LC_warning">';
1.661 raeburn 11654: $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 11655: $msg .= '</p>';
1.661 raeburn 11656: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11657: return ('file_locked',$msg);
11658: } else {
1.1075.2.69 raeburn 11659: my $msg = '<p class="LC_error">';
1.984 raeburn 11660: $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 11661: $msg .= '</p>';
1.984 raeburn 11662: return ('existingfile',$msg);
1.661 raeburn 11663: }
11664: }
11665: }
11666:
1.987 raeburn 11667: sub check_for_traversal {
11668: my ($path,$url,$toplevel) = @_;
11669: my @parts=split(/\//,$path);
11670: my $cleanpath;
11671: my $fullpath = $url;
11672: for (my $i=0;$i<@parts;$i++) {
11673: next if ($parts[$i] eq '.');
11674: if ($parts[$i] eq '..') {
11675: $fullpath =~ s{([^/]+/)$}{};
11676: } else {
11677: $fullpath .= $parts[$i].'/';
11678: }
11679: }
11680: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11681: $cleanpath = $1;
11682: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11683: my $curr_toprel = $1;
11684: my @parts = split(/\//,$curr_toprel);
11685: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11686: my @urlparts = split(/\//,$url_toprel);
11687: my $doubledots;
11688: my $startdiff = -1;
11689: for (my $i=0; $i<@urlparts; $i++) {
11690: if ($startdiff == -1) {
11691: unless ($urlparts[$i] eq $parts[$i]) {
11692: $startdiff = $i;
11693: $doubledots .= '../';
11694: }
11695: } else {
11696: $doubledots .= '../';
11697: }
11698: }
11699: if ($startdiff > -1) {
11700: $cleanpath = $doubledots;
11701: for (my $i=$startdiff; $i<@parts; $i++) {
11702: $cleanpath .= $parts[$i].'/';
11703: }
11704: }
11705: }
11706: $cleanpath =~ s{(/)$}{};
11707: return $cleanpath;
11708: }
1.31 albertel 11709:
1.1053 raeburn 11710: sub is_archive_file {
11711: my ($mimetype) = @_;
11712: if (($mimetype eq 'application/octet-stream') ||
11713: ($mimetype eq 'application/x-stuffit') ||
11714: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11715: return 1;
11716: }
11717: return;
11718: }
11719:
11720: sub decompress_form {
1.1065 raeburn 11721: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11722: my %lt = &Apache::lonlocal::texthash (
11723: this => 'This file is an archive file.',
1.1067 raeburn 11724: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11725: itsc => 'Its contents are as follows:',
1.1053 raeburn 11726: youm => 'You may wish to extract its contents.',
11727: extr => 'Extract contents',
1.1067 raeburn 11728: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11729: proa => 'Process automatically?',
1.1053 raeburn 11730: yes => 'Yes',
11731: no => 'No',
1.1067 raeburn 11732: fold => 'Title for folder containing movie',
11733: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11734: );
1.1065 raeburn 11735: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11736: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11737: my $info = &list_archive_contents($fileloc,\@paths);
11738: if (@paths) {
11739: foreach my $path (@paths) {
11740: $path =~ s{^/}{};
1.1067 raeburn 11741: if ($path =~ m{^([^/]+)/$}) {
11742: $topdir = $1;
11743: }
1.1065 raeburn 11744: if ($path =~ m{^([^/]+)/}) {
11745: $toplevel{$1} = $path;
11746: } else {
11747: $toplevel{$path} = $path;
11748: }
11749: }
11750: }
1.1067 raeburn 11751: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11752: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11753: "$topdir/media/",
11754: "$topdir/media/$topdir.mp4",
11755: "$topdir/media/FirstFrame.png",
11756: "$topdir/media/player.swf",
11757: "$topdir/media/swfobject.js",
11758: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11759: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11760: "$topdir/$topdir.mp4",
11761: "$topdir/$topdir\_config.xml",
11762: "$topdir/$topdir\_controller.swf",
11763: "$topdir/$topdir\_embed.css",
11764: "$topdir/$topdir\_First_Frame.png",
11765: "$topdir/$topdir\_player.html",
11766: "$topdir/$topdir\_Thumbnails.png",
11767: "$topdir/playerProductInstall.swf",
11768: "$topdir/scripts/",
11769: "$topdir/scripts/config_xml.js",
11770: "$topdir/scripts/handlebars.js",
11771: "$topdir/scripts/jquery-1.7.1.min.js",
11772: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11773: "$topdir/scripts/modernizr.js",
11774: "$topdir/scripts/player-min.js",
11775: "$topdir/scripts/swfobject.js",
11776: "$topdir/skins/",
11777: "$topdir/skins/configuration_express.xml",
11778: "$topdir/skins/express_show/",
11779: "$topdir/skins/express_show/player-min.css",
11780: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11781: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11782: "$topdir/$topdir.mp4",
11783: "$topdir/$topdir\_config.xml",
11784: "$topdir/$topdir\_controller.swf",
11785: "$topdir/$topdir\_embed.css",
11786: "$topdir/$topdir\_First_Frame.png",
11787: "$topdir/$topdir\_player.html",
11788: "$topdir/$topdir\_Thumbnails.png",
11789: "$topdir/playerProductInstall.swf",
11790: "$topdir/scripts/",
11791: "$topdir/scripts/config_xml.js",
11792: "$topdir/scripts/techsmith-smart-player.min.js",
11793: "$topdir/skins/",
11794: "$topdir/skins/configuration_express.xml",
11795: "$topdir/skins/express_show/",
11796: "$topdir/skins/express_show/spritesheet.min.css",
11797: "$topdir/skins/express_show/spritesheet.png",
11798: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 11799: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11800: if (@diffs == 0) {
1.1075.2.59 raeburn 11801: $is_camtasia = 6;
11802: } else {
1.1075.2.81 raeburn 11803: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 11804: if (@diffs == 0) {
11805: $is_camtasia = 8;
1.1075.2.81 raeburn 11806: } else {
11807: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11808: if (@diffs == 0) {
11809: $is_camtasia = 8;
11810: }
1.1075.2.59 raeburn 11811: }
1.1067 raeburn 11812: }
11813: }
11814: my $output;
11815: if ($is_camtasia) {
11816: $output = <<"ENDCAM";
11817: <script type="text/javascript" language="Javascript">
11818: // <![CDATA[
11819:
11820: function camtasiaToggle() {
11821: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11822: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11823: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11824: document.getElementById('camtasia_titles').style.display='block';
11825: } else {
11826: document.getElementById('camtasia_titles').style.display='none';
11827: }
11828: }
11829: }
11830: return;
11831: }
11832:
11833: // ]]>
11834: </script>
11835: <p>$lt{'camt'}</p>
11836: ENDCAM
1.1065 raeburn 11837: } else {
1.1067 raeburn 11838: $output = '<p>'.$lt{'this'};
11839: if ($info eq '') {
11840: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11841: } else {
11842: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11843: '<div><pre>'.$info.'</pre></div>';
11844: }
1.1065 raeburn 11845: }
1.1067 raeburn 11846: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11847: my $duplicates;
11848: my $num = 0;
11849: if (ref($dirlist) eq 'ARRAY') {
11850: foreach my $item (@{$dirlist}) {
11851: if (ref($item) eq 'ARRAY') {
11852: if (exists($toplevel{$item->[0]})) {
11853: $duplicates .=
11854: &start_data_table_row().
11855: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11856: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11857: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11858: 'value="1" />'.&mt('Yes').'</label>'.
11859: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11860: '<td>'.$item->[0].'</td>';
11861: if ($item->[2]) {
11862: $duplicates .= '<td>'.&mt('Directory').'</td>';
11863: } else {
11864: $duplicates .= '<td>'.&mt('File').'</td>';
11865: }
11866: $duplicates .= '<td>'.$item->[3].'</td>'.
11867: '<td>'.
11868: &Apache::lonlocal::locallocaltime($item->[4]).
11869: '</td>'.
11870: &end_data_table_row();
11871: $num ++;
11872: }
11873: }
11874: }
11875: }
11876: my $itemcount;
11877: if (@paths > 0) {
11878: $itemcount = scalar(@paths);
11879: } else {
11880: $itemcount = 1;
11881: }
1.1067 raeburn 11882: if ($is_camtasia) {
11883: $output .= $lt{'auto'}.'<br />'.
11884: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11885: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11886: $lt{'yes'}.'</label> <label>'.
11887: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11888: $lt{'no'}.'</label></span><br />'.
11889: '<div id="camtasia_titles" style="display:block">'.
11890: &Apache::lonhtmlcommon::start_pick_box().
11891: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11892: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11893: &Apache::lonhtmlcommon::row_closure().
11894: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11895: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11896: &Apache::lonhtmlcommon::row_closure(1).
11897: &Apache::lonhtmlcommon::end_pick_box().
11898: '</div>';
11899: }
1.1065 raeburn 11900: $output .=
11901: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11902: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11903: "\n";
1.1065 raeburn 11904: if ($duplicates ne '') {
11905: $output .= '<p><span class="LC_warning">'.
11906: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11907: &start_data_table().
11908: &start_data_table_header_row().
11909: '<th>'.&mt('Overwrite?').'</th>'.
11910: '<th>'.&mt('Name').'</th>'.
11911: '<th>'.&mt('Type').'</th>'.
11912: '<th>'.&mt('Size').'</th>'.
11913: '<th>'.&mt('Last modified').'</th>'.
11914: &end_data_table_header_row().
11915: $duplicates.
11916: &end_data_table().
11917: '</p>';
11918: }
1.1067 raeburn 11919: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11920: if (ref($hiddenelements) eq 'HASH') {
11921: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11922: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11923: }
11924: }
11925: $output .= <<"END";
1.1067 raeburn 11926: <br />
1.1053 raeburn 11927: <input type="submit" name="decompress" value="$lt{'extr'}" />
11928: </form>
11929: $noextract
11930: END
11931: return $output;
11932: }
11933:
1.1065 raeburn 11934: sub decompression_utility {
11935: my ($program) = @_;
11936: my @utilities = ('tar','gunzip','bunzip2','unzip');
11937: my $location;
11938: if (grep(/^\Q$program\E$/,@utilities)) {
11939: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11940: '/usr/sbin/') {
11941: if (-x $dir.$program) {
11942: $location = $dir.$program;
11943: last;
11944: }
11945: }
11946: }
11947: return $location;
11948: }
11949:
11950: sub list_archive_contents {
11951: my ($file,$pathsref) = @_;
11952: my (@cmd,$output);
11953: my $needsregexp;
11954: if ($file =~ /\.zip$/) {
11955: @cmd = (&decompression_utility('unzip'),"-l");
11956: $needsregexp = 1;
11957: } elsif (($file =~ m/\.tar\.gz$/) ||
11958: ($file =~ /\.tgz$/)) {
11959: @cmd = (&decompression_utility('tar'),"-ztf");
11960: } elsif ($file =~ /\.tar\.bz2$/) {
11961: @cmd = (&decompression_utility('tar'),"-jtf");
11962: } elsif ($file =~ m|\.tar$|) {
11963: @cmd = (&decompression_utility('tar'),"-tf");
11964: }
11965: if (@cmd) {
11966: undef($!);
11967: undef($@);
11968: if (open(my $fh,"-|", @cmd, $file)) {
11969: while (my $line = <$fh>) {
11970: $output .= $line;
11971: chomp($line);
11972: my $item;
11973: if ($needsregexp) {
11974: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11975: } else {
11976: $item = $line;
11977: }
11978: if ($item ne '') {
11979: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11980: push(@{$pathsref},$item);
11981: }
11982: }
11983: }
11984: close($fh);
11985: }
11986: }
11987: return $output;
11988: }
11989:
1.1053 raeburn 11990: sub decompress_uploaded_file {
11991: my ($file,$dir) = @_;
11992: &Apache::lonnet::appenv({'cgi.file' => $file});
11993: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11994: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11995: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11996: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11997: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11998: my $decompressed = $env{'cgi.decompressed'};
11999: &Apache::lonnet::delenv('cgi.file');
12000: &Apache::lonnet::delenv('cgi.dir');
12001: &Apache::lonnet::delenv('cgi.decompressed');
12002: return ($decompressed,$result);
12003: }
12004:
1.1055 raeburn 12005: sub process_decompression {
12006: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1075.2.128! raeburn 12007: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
! 12008: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
! 12009: &mt('Unexpected file path.').'</p>'."\n";
! 12010: }
! 12011: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
! 12012: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
! 12013: &mt('Unexpected course context.').'</p>'."\n";
! 12014: }
! 12015: unless ($file eq &Apache::lonnet::clean_filename($file)) {
! 12016: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
! 12017: &mt('Filename contained unexpected characters.').'</p>'."\n";
! 12018: }
1.1055 raeburn 12019: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12020: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12021: $error = &mt('Filename not a supported archive file type.').
12022: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12023: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12024: } else {
12025: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12026: if ($docuhome eq 'no_host') {
12027: $error = &mt('Could not determine home server for course.');
12028: } else {
12029: my @ids=&Apache::lonnet::current_machine_ids();
12030: my $currdir = "$dir_root/$destination";
12031: if (grep(/^\Q$docuhome\E$/,@ids)) {
12032: $dir = &LONCAPA::propath($docudom,$docuname).
12033: "$dir_root/$destination";
12034: } else {
12035: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12036: "$dir_root/$docudom/$docuname/$destination";
12037: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12038: $error = &mt('Archive file not found.');
12039: }
12040: }
1.1065 raeburn 12041: my (@to_overwrite,@to_skip);
12042: if ($env{'form.archive_overwrite_total'} > 0) {
12043: my $total = $env{'form.archive_overwrite_total'};
12044: for (my $i=0; $i<$total; $i++) {
12045: if ($env{'form.archive_overwrite_'.$i} == 1) {
12046: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12047: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12048: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12049: }
12050: }
12051: }
12052: my $numskip = scalar(@to_skip);
1.1075.2.128! raeburn 12053: my $numoverwrite = scalar(@to_overwrite);
! 12054: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12055: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12056: } elsif ($dir eq '') {
1.1055 raeburn 12057: $error = &mt('Directory containing archive file unavailable.');
12058: } elsif (!$error) {
1.1065 raeburn 12059: my ($decompressed,$display);
1.1075.2.128! raeburn 12060: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12061: my $tempdir = time.'_'.$$.int(rand(10000));
12062: mkdir("$dir/$tempdir",0755);
1.1075.2.128! raeburn 12063: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
! 12064: ($decompressed,$display) =
! 12065: &decompress_uploaded_file($file,"$dir/$tempdir");
! 12066: foreach my $item (@to_skip) {
! 12067: if (($item ne '') && ($item !~ /\.\./)) {
! 12068: if (-f "$dir/$tempdir/$item") {
! 12069: unlink("$dir/$tempdir/$item");
! 12070: } elsif (-d "$dir/$tempdir/$item") {
! 12071: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
! 12072: }
! 12073: }
! 12074: }
! 12075: foreach my $item (@to_overwrite) {
! 12076: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
! 12077: if (($item ne '') && ($item !~ /\.\./)) {
! 12078: if (-f "$dir/$item") {
! 12079: unlink("$dir/$item");
! 12080: } elsif (-d "$dir/$item") {
! 12081: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
! 12082: }
! 12083: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
! 12084: }
1.1065 raeburn 12085: }
12086: }
1.1075.2.128! raeburn 12087: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
! 12088: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
! 12089: }
1.1065 raeburn 12090: }
12091: } else {
12092: ($decompressed,$display) =
12093: &decompress_uploaded_file($file,$dir);
12094: }
1.1055 raeburn 12095: if ($decompressed eq 'ok') {
1.1065 raeburn 12096: $output = '<p class="LC_info">'.
12097: &mt('Files extracted successfully from archive.').
12098: '</p>'."\n";
1.1055 raeburn 12099: my ($warning,$result,@contents);
12100: my ($newdirlistref,$newlisterror) =
12101: &Apache::lonnet::dirlist($currdir,$docudom,
12102: $docuname,1);
12103: my (%is_dir,%changes,@newitems);
12104: my $dirptr = 16384;
1.1065 raeburn 12105: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12106: foreach my $dir_line (@{$newdirlistref}) {
12107: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1075.2.128! raeburn 12108: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12109: push(@newitems,$item);
12110: if ($dirptr&$testdir) {
12111: $is_dir{$item} = 1;
12112: }
12113: $changes{$item} = 1;
12114: }
12115: }
12116: }
12117: if (keys(%changes) > 0) {
12118: foreach my $item (sort(@newitems)) {
12119: if ($changes{$item}) {
12120: push(@contents,$item);
12121: }
12122: }
12123: }
12124: if (@contents > 0) {
1.1067 raeburn 12125: my $wantform;
12126: unless ($env{'form.autoextract_camtasia'}) {
12127: $wantform = 1;
12128: }
1.1056 raeburn 12129: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12130: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12131: $currdir,\%is_dir,
12132: \%children,\%parent,
1.1056 raeburn 12133: \@contents,\%dirorder,
12134: \%titles,$wantform);
1.1055 raeburn 12135: if ($datatable ne '') {
12136: $output .= &archive_options_form('decompressed',$datatable,
12137: $count,$hiddenelem);
1.1065 raeburn 12138: my $startcount = 6;
1.1055 raeburn 12139: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12140: \%titles,\%children);
1.1055 raeburn 12141: }
1.1067 raeburn 12142: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12143: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12144: my %displayed;
12145: my $total = 1;
12146: $env{'form.archive_directory'} = [];
12147: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12148: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12149: $path =~ s{/$}{};
12150: my $item;
12151: if ($path ne '') {
12152: $item = "$path/$titles{$i}";
12153: } else {
12154: $item = $titles{$i};
12155: }
12156: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12157: if ($item eq $contents[0]) {
12158: push(@{$env{'form.archive_directory'}},$i);
12159: $env{'form.archive_'.$i} = 'display';
12160: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12161: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12162: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12163: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12164: $env{'form.archive_'.$i} = 'display';
12165: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12166: $displayed{'web'} = $i;
12167: } else {
1.1075.2.59 raeburn 12168: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12169: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12170: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12171: push(@{$env{'form.archive_directory'}},$i);
12172: }
12173: $env{'form.archive_'.$i} = 'dependency';
12174: }
12175: $total ++;
12176: }
12177: for (my $i=1; $i<$total; $i++) {
12178: next if ($i == $displayed{'web'});
12179: next if ($i == $displayed{'folder'});
12180: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12181: }
12182: $env{'form.phase'} = 'decompress_cleanup';
12183: $env{'form.archivedelete'} = 1;
12184: $env{'form.archive_count'} = $total-1;
12185: $output .=
12186: &process_extracted_files('coursedocs',$docudom,
12187: $docuname,$destination,
12188: $dir_root,$hiddenelem);
12189: }
1.1055 raeburn 12190: } else {
12191: $warning = &mt('No new items extracted from archive file.');
12192: }
12193: } else {
12194: $output = $display;
12195: $error = &mt('An error occurred during extraction from the archive file.');
12196: }
12197: }
12198: }
12199: }
12200: if ($error) {
12201: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12202: $error.'</p>'."\n";
12203: }
12204: if ($warning) {
12205: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12206: }
12207: return $output;
12208: }
12209:
12210: sub get_extracted {
1.1056 raeburn 12211: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12212: $titles,$wantform) = @_;
1.1055 raeburn 12213: my $count = 0;
12214: my $depth = 0;
12215: my $datatable;
1.1056 raeburn 12216: my @hierarchy;
1.1055 raeburn 12217: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12218: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12219: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12220: foreach my $item (@{$contents}) {
12221: $count ++;
1.1056 raeburn 12222: @{$dirorder->{$count}} = @hierarchy;
12223: $titles->{$count} = $item;
1.1055 raeburn 12224: &archive_hierarchy($depth,$count,$parent,$children);
12225: if ($wantform) {
12226: $datatable .= &archive_row($is_dir->{$item},$item,
12227: $currdir,$depth,$count);
12228: }
12229: if ($is_dir->{$item}) {
12230: $depth ++;
1.1056 raeburn 12231: push(@hierarchy,$count);
12232: $parent->{$depth} = $count;
1.1055 raeburn 12233: $datatable .=
12234: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12235: \$depth,\$count,\@hierarchy,$dirorder,
12236: $children,$parent,$titles,$wantform);
1.1055 raeburn 12237: $depth --;
1.1056 raeburn 12238: pop(@hierarchy);
1.1055 raeburn 12239: }
12240: }
12241: return ($count,$datatable);
12242: }
12243:
12244: sub recurse_extracted_archive {
1.1056 raeburn 12245: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12246: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12247: my $result='';
1.1056 raeburn 12248: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12249: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12250: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12251: return $result;
12252: }
12253: my $dirptr = 16384;
12254: my ($newdirlistref,$newlisterror) =
12255: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12256: if (ref($newdirlistref) eq 'ARRAY') {
12257: foreach my $dir_line (@{$newdirlistref}) {
12258: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12259: unless ($item =~ /^\.+$/) {
12260: $$count ++;
1.1056 raeburn 12261: @{$dirorder->{$$count}} = @{$hierarchy};
12262: $titles->{$$count} = $item;
1.1055 raeburn 12263: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12264:
1.1055 raeburn 12265: my $is_dir;
12266: if ($dirptr&$testdir) {
12267: $is_dir = 1;
12268: }
12269: if ($wantform) {
12270: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12271: }
12272: if ($is_dir) {
12273: $$depth ++;
1.1056 raeburn 12274: push(@{$hierarchy},$$count);
12275: $parent->{$$depth} = $$count;
1.1055 raeburn 12276: $result .=
12277: &recurse_extracted_archive("$currdir/$item",$docudom,
12278: $docuname,$depth,$count,
1.1056 raeburn 12279: $hierarchy,$dirorder,$children,
12280: $parent,$titles,$wantform);
1.1055 raeburn 12281: $$depth --;
1.1056 raeburn 12282: pop(@{$hierarchy});
1.1055 raeburn 12283: }
12284: }
12285: }
12286: }
12287: return $result;
12288: }
12289:
12290: sub archive_hierarchy {
12291: my ($depth,$count,$parent,$children) =@_;
12292: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12293: if (exists($parent->{$depth})) {
12294: $children->{$parent->{$depth}} .= $count.':';
12295: }
12296: }
12297: return;
12298: }
12299:
12300: sub archive_row {
12301: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12302: my ($name) = ($item =~ m{([^/]+)$});
12303: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12304: 'display' => 'Add as file',
1.1055 raeburn 12305: 'dependency' => 'Include as dependency',
12306: 'discard' => 'Discard',
12307: );
12308: if ($is_dir) {
1.1059 raeburn 12309: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12310: }
1.1056 raeburn 12311: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12312: my $offset = 0;
1.1055 raeburn 12313: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12314: $offset ++;
1.1065 raeburn 12315: if ($action ne 'display') {
12316: $offset ++;
12317: }
1.1055 raeburn 12318: $output .= '<td><span class="LC_nobreak">'.
12319: '<label><input type="radio" name="archive_'.$count.
12320: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12321: my $text = $choices{$action};
12322: if ($is_dir) {
12323: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12324: if ($action eq 'display') {
1.1059 raeburn 12325: $text = &mt('Add as folder');
1.1055 raeburn 12326: }
1.1056 raeburn 12327: } else {
12328: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12329:
12330: }
12331: $output .= ' /> '.$choices{$action}.'</label></span>';
12332: if ($action eq 'dependency') {
12333: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12334: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12335: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12336: '<option value=""></option>'."\n".
12337: '</select>'."\n".
12338: '</div>';
1.1059 raeburn 12339: } elsif ($action eq 'display') {
12340: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12341: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12342: '</div>';
1.1055 raeburn 12343: }
1.1056 raeburn 12344: $output .= '</td>';
1.1055 raeburn 12345: }
12346: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12347: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12348: for (my $i=0; $i<$depth; $i++) {
12349: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12350: }
12351: if ($is_dir) {
12352: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12353: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12354: } else {
12355: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12356: }
12357: $output .= ' '.$name.'</td>'."\n".
12358: &end_data_table_row();
12359: return $output;
12360: }
12361:
12362: sub archive_options_form {
1.1065 raeburn 12363: my ($form,$display,$count,$hiddenelem) = @_;
12364: my %lt = &Apache::lonlocal::texthash(
12365: perm => 'Permanently remove archive file?',
12366: hows => 'How should each extracted item be incorporated in the course?',
12367: cont => 'Content actions for all',
12368: addf => 'Add as folder/file',
12369: incd => 'Include as dependency for a displayed file',
12370: disc => 'Discard',
12371: no => 'No',
12372: yes => 'Yes',
12373: save => 'Save',
12374: );
12375: my $output = <<"END";
12376: <form name="$form" method="post" action="">
12377: <p><span class="LC_nobreak">$lt{'perm'}
12378: <label>
12379: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12380: </label>
12381:
12382: <label>
12383: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12384: </span>
12385: </p>
12386: <input type="hidden" name="phase" value="decompress_cleanup" />
12387: <br />$lt{'hows'}
12388: <div class="LC_columnSection">
12389: <fieldset>
12390: <legend>$lt{'cont'}</legend>
12391: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12392: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12393: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12394: </fieldset>
12395: </div>
12396: END
12397: return $output.
1.1055 raeburn 12398: &start_data_table()."\n".
1.1065 raeburn 12399: $display."\n".
1.1055 raeburn 12400: &end_data_table()."\n".
12401: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12402: $hiddenelem.
1.1065 raeburn 12403: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12404: '</form>';
12405: }
12406:
12407: sub archive_javascript {
1.1056 raeburn 12408: my ($startcount,$numitems,$titles,$children) = @_;
12409: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12410: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12411: my $scripttag = <<START;
12412: <script type="text/javascript">
12413: // <![CDATA[
12414:
12415: function checkAll(form,prefix) {
12416: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12417: for (var i=0; i < form.elements.length; i++) {
12418: var id = form.elements[i].id;
12419: if ((id != '') && (id != undefined)) {
12420: if (idstr.test(id)) {
12421: if (form.elements[i].type == 'radio') {
12422: form.elements[i].checked = true;
1.1056 raeburn 12423: var nostart = i-$startcount;
1.1059 raeburn 12424: var offset = nostart%7;
12425: var count = (nostart-offset)/7;
1.1056 raeburn 12426: dependencyCheck(form,count,offset);
1.1055 raeburn 12427: }
12428: }
12429: }
12430: }
12431: }
12432:
12433: function propagateCheck(form,count) {
12434: if (count > 0) {
1.1059 raeburn 12435: var startelement = $startcount + ((count-1) * 7);
12436: for (var j=1; j<6; j++) {
12437: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12438: var item = startelement + j;
12439: if (form.elements[item].type == 'radio') {
12440: if (form.elements[item].checked) {
12441: containerCheck(form,count,j);
12442: break;
12443: }
1.1055 raeburn 12444: }
12445: }
12446: }
12447: }
12448: }
12449:
12450: numitems = $numitems
1.1056 raeburn 12451: var titles = new Array(numitems);
12452: var parents = new Array(numitems);
1.1055 raeburn 12453: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12454: parents[i] = new Array;
1.1055 raeburn 12455: }
1.1059 raeburn 12456: var maintitle = '$maintitle';
1.1055 raeburn 12457:
12458: START
12459:
1.1056 raeburn 12460: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12461: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12462: for (my $i=0; $i<@contents; $i ++) {
12463: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12464: }
12465: }
12466:
1.1056 raeburn 12467: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12468: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12469: }
12470:
1.1055 raeburn 12471: $scripttag .= <<END;
12472:
12473: function containerCheck(form,count,offset) {
12474: if (count > 0) {
1.1056 raeburn 12475: dependencyCheck(form,count,offset);
1.1059 raeburn 12476: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12477: form.elements[item].checked = true;
12478: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12479: if (parents[count].length > 0) {
12480: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12481: containerCheck(form,parents[count][j],offset);
12482: }
12483: }
12484: }
12485: }
12486: }
12487:
12488: function dependencyCheck(form,count,offset) {
12489: if (count > 0) {
1.1059 raeburn 12490: var chosen = (offset+$startcount)+7*(count-1);
12491: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12492: var currtype = form.elements[depitem].type;
12493: if (form.elements[chosen].value == 'dependency') {
12494: document.getElementById('arc_depon_'+count).style.display='block';
12495: form.elements[depitem].options.length = 0;
12496: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12497: for (var i=1; i<=numitems; i++) {
12498: if (i == count) {
12499: continue;
12500: }
1.1059 raeburn 12501: var startelement = $startcount + (i-1) * 7;
12502: for (var j=1; j<6; j++) {
12503: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12504: var item = startelement + j;
12505: if (form.elements[item].type == 'radio') {
12506: if (form.elements[item].checked) {
12507: if (form.elements[item].value == 'display') {
12508: var n = form.elements[depitem].options.length;
12509: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12510: }
12511: }
12512: }
12513: }
12514: }
12515: }
12516: } else {
12517: document.getElementById('arc_depon_'+count).style.display='none';
12518: form.elements[depitem].options.length = 0;
12519: form.elements[depitem].options[0] = new Option('Select','',true,true);
12520: }
1.1059 raeburn 12521: titleCheck(form,count,offset);
1.1056 raeburn 12522: }
12523: }
12524:
12525: function propagateSelect(form,count,offset) {
12526: if (count > 0) {
1.1065 raeburn 12527: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12528: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12529: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12530: if (parents[count].length > 0) {
12531: for (var j=0; j<parents[count].length; j++) {
12532: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12533: }
12534: }
12535: }
12536: }
12537: }
1.1056 raeburn 12538:
12539: function containerSelect(form,count,offset,picked) {
12540: if (count > 0) {
1.1065 raeburn 12541: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12542: if (form.elements[item].type == 'radio') {
12543: if (form.elements[item].value == 'dependency') {
12544: if (form.elements[item+1].type == 'select-one') {
12545: for (var i=0; i<form.elements[item+1].options.length; i++) {
12546: if (form.elements[item+1].options[i].value == picked) {
12547: form.elements[item+1].selectedIndex = i;
12548: break;
12549: }
12550: }
12551: }
12552: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12553: if (parents[count].length > 0) {
12554: for (var j=0; j<parents[count].length; j++) {
12555: containerSelect(form,parents[count][j],offset,picked);
12556: }
12557: }
12558: }
12559: }
12560: }
12561: }
12562: }
12563:
1.1059 raeburn 12564: function titleCheck(form,count,offset) {
12565: if (count > 0) {
12566: var chosen = (offset+$startcount)+7*(count-1);
12567: var depitem = $startcount + ((count-1) * 7) + 2;
12568: var currtype = form.elements[depitem].type;
12569: if (form.elements[chosen].value == 'display') {
12570: document.getElementById('arc_title_'+count).style.display='block';
12571: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12572: document.getElementById('archive_title_'+count).value=maintitle;
12573: }
12574: } else {
12575: document.getElementById('arc_title_'+count).style.display='none';
12576: if (currtype == 'text') {
12577: document.getElementById('archive_title_'+count).value='';
12578: }
12579: }
12580: }
12581: return;
12582: }
12583:
1.1055 raeburn 12584: // ]]>
12585: </script>
12586: END
12587: return $scripttag;
12588: }
12589:
12590: sub process_extracted_files {
1.1067 raeburn 12591: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12592: my $numitems = $env{'form.archive_count'};
1.1075.2.128! raeburn 12593: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 12594: my @ids=&Apache::lonnet::current_machine_ids();
12595: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12596: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12597: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12598: if (grep(/^\Q$docuhome\E$/,@ids)) {
12599: $prefix = &LONCAPA::propath($docudom,$docuname);
12600: $pathtocheck = "$dir_root/$destination";
12601: $dir = $dir_root;
12602: $ishome = 1;
12603: } else {
12604: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12605: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1075.2.128! raeburn 12606: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 12607: }
12608: my $currdir = "$dir_root/$destination";
12609: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12610: if ($env{'form.folderpath'}) {
12611: my @items = split('&',$env{'form.folderpath'});
12612: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12613: if ($env{'form.folderpath'} =~ /\:1$/) {
12614: $containers{'0'}='page';
12615: } else {
12616: $containers{'0'}='sequence';
12617: }
1.1055 raeburn 12618: }
12619: my @archdirs = &get_env_multiple('form.archive_directory');
12620: if ($numitems) {
12621: for (my $i=1; $i<=$numitems; $i++) {
12622: my $path = $env{'form.archive_content_'.$i};
12623: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12624: my $item = $1;
12625: $toplevelitems{$item} = $i;
12626: if (grep(/^\Q$i\E$/,@archdirs)) {
12627: $is_dir{$item} = 1;
12628: }
12629: }
12630: }
12631: }
1.1067 raeburn 12632: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12633: if (keys(%toplevelitems) > 0) {
12634: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12635: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12636: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12637: }
1.1066 raeburn 12638: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12639: if ($numitems) {
12640: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12641: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12642: my $path = $env{'form.archive_content_'.$i};
12643: if ($path =~ /^\Q$pathtocheck\E/) {
12644: if ($env{'form.archive_'.$i} eq 'discard') {
12645: if ($prefix ne '' && $path ne '') {
12646: if (-e $prefix.$path) {
1.1066 raeburn 12647: if ((@archdirs > 0) &&
12648: (grep(/^\Q$i\E$/,@archdirs))) {
12649: $todeletedir{$prefix.$path} = 1;
12650: } else {
12651: $todelete{$prefix.$path} = 1;
12652: }
1.1055 raeburn 12653: }
12654: }
12655: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12656: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12657: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12658: $docstitle = $env{'form.archive_title_'.$i};
12659: if ($docstitle eq '') {
12660: $docstitle = $title;
12661: }
1.1055 raeburn 12662: $outer = 0;
1.1056 raeburn 12663: if (ref($dirorder{$i}) eq 'ARRAY') {
12664: if (@{$dirorder{$i}} > 0) {
12665: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12666: if ($env{'form.archive_'.$item} eq 'display') {
12667: $outer = $item;
12668: last;
12669: }
12670: }
12671: }
12672: }
12673: my ($errtext,$fatal) =
12674: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12675: '/'.$folders{$outer}.'.'.
12676: $containers{$outer});
12677: next if ($fatal);
12678: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12679: if ($context eq 'coursedocs') {
1.1056 raeburn 12680: $mapinner{$i} = time;
1.1055 raeburn 12681: $folders{$i} = 'default_'.$mapinner{$i};
12682: $containers{$i} = 'sequence';
12683: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12684: $folders{$i}.'.'.$containers{$i};
12685: my $newidx = &LONCAPA::map::getresidx();
12686: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12687: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12688: push(@LONCAPA::map::order,$newidx);
12689: my ($outtext,$errtext) =
12690: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12691: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12692: '.'.$containers{$outer},1,1);
1.1056 raeburn 12693: $newseqid{$i} = $newidx;
1.1067 raeburn 12694: unless ($errtext) {
1.1075.2.128! raeburn 12695: $result .= '<li>'.&mt('Folder: [_1] added to course',
! 12696: &HTML::Entities::encode($docstitle,'<>&"'))..
! 12697: '</li>'."\n";
1.1067 raeburn 12698: }
1.1055 raeburn 12699: }
12700: } else {
12701: if ($context eq 'coursedocs') {
12702: my $newidx=&LONCAPA::map::getresidx();
12703: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12704: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12705: $title;
1.1075.2.128! raeburn 12706: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
! 12707: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
! 12708: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
1.1067 raeburn 12709: }
1.1075.2.128! raeburn 12710: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
! 12711: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
! 12712: }
! 12713: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
! 12714: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
! 12715: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
! 12716: unless ($ishome) {
! 12717: my $fetch = "$newdest{$i}/$title";
! 12718: $fetch =~ s/^\Q$prefix$dir\E//;
! 12719: $prompttofetch{$fetch} = 1;
! 12720: }
! 12721: }
! 12722: }
! 12723: $LONCAPA::map::resources[$newidx]=
! 12724: $docstitle.':'.$url.':false:normal:res';
! 12725: push(@LONCAPA::map::order, $newidx);
! 12726: my ($outtext,$errtext)=
! 12727: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
! 12728: $docuname.'/'.$folders{$outer}.
! 12729: '.'.$containers{$outer},1,1);
! 12730: unless ($errtext) {
! 12731: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
! 12732: $result .= '<li>'.&mt('File: [_1] added to course',
! 12733: &HTML::Entities::encode($docstitle,'<>&"')).
! 12734: '</li>'."\n";
! 12735: }
1.1067 raeburn 12736: }
1.1075.2.128! raeburn 12737: } else {
! 12738: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
! 12739: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1067 raeburn 12740: }
1.1055 raeburn 12741: }
12742: }
1.1075.2.11 raeburn 12743: }
12744: } else {
1.1075.2.128! raeburn 12745: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
! 12746: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1075.2.11 raeburn 12747: }
12748: }
12749: for (my $i=1; $i<=$numitems; $i++) {
12750: next unless ($env{'form.archive_'.$i} eq 'dependency');
12751: my $path = $env{'form.archive_content_'.$i};
12752: if ($path =~ /^\Q$pathtocheck\E/) {
12753: my ($title) = ($path =~ m{/([^/]+)$});
12754: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12755: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12756: if (ref($dirorder{$i}) eq 'ARRAY') {
12757: my ($itemidx,$fullpath,$relpath);
12758: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12759: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12760: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12761: if ($dirorder{$i}->[$j] eq $container) {
12762: $itemidx = $j;
1.1056 raeburn 12763: }
12764: }
1.1075.2.11 raeburn 12765: }
12766: if ($itemidx eq '') {
12767: $itemidx = 0;
12768: }
12769: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12770: if ($mapinner{$referrer{$i}}) {
12771: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12772: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12773: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12774: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12775: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12776: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12777: if (!-e $fullpath) {
12778: mkdir($fullpath,0755);
1.1056 raeburn 12779: }
12780: }
1.1075.2.11 raeburn 12781: } else {
12782: last;
1.1056 raeburn 12783: }
1.1075.2.11 raeburn 12784: }
12785: }
12786: } elsif ($newdest{$referrer{$i}}) {
12787: $fullpath = $newdest{$referrer{$i}};
12788: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12789: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12790: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12791: last;
12792: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12793: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12794: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12795: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12796: if (!-e $fullpath) {
12797: mkdir($fullpath,0755);
1.1056 raeburn 12798: }
12799: }
1.1075.2.11 raeburn 12800: } else {
12801: last;
1.1056 raeburn 12802: }
1.1075.2.11 raeburn 12803: }
12804: }
12805: if ($fullpath ne '') {
12806: if (-e "$prefix$path") {
1.1075.2.128! raeburn 12807: unless (rename("$prefix$path","$fullpath/$title")) {
! 12808: $warning .= &mt('Failed to rename dependency').'<br />';
! 12809: }
1.1075.2.11 raeburn 12810: }
12811: if (-e "$fullpath/$title") {
12812: my $showpath;
12813: if ($relpath ne '') {
12814: $showpath = "$relpath/$title";
12815: } else {
12816: $showpath = "/$title";
1.1056 raeburn 12817: }
1.1075.2.128! raeburn 12818: $result .= '<li>'.&mt('[_1] included as a dependency',
! 12819: &HTML::Entities::encode($showpath,'<>&"')).
! 12820: '</li>'."\n";
! 12821: unless ($ishome) {
! 12822: my $fetch = "$fullpath/$title";
! 12823: $fetch =~ s/^\Q$prefix$dir\E//;
! 12824: $prompttofetch{$fetch} = 1;
! 12825: }
1.1055 raeburn 12826: }
12827: }
12828: }
1.1075.2.11 raeburn 12829: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12830: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1075.2.128! raeburn 12831: &HTML::Entities::encode($path,'<>&"'),
! 12832: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
! 12833: '<br />';
1.1055 raeburn 12834: }
12835: } else {
1.1075.2.128! raeburn 12836: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
! 12837: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 12838: }
12839: }
12840: if (keys(%todelete)) {
12841: foreach my $key (keys(%todelete)) {
12842: unlink($key);
1.1066 raeburn 12843: }
12844: }
12845: if (keys(%todeletedir)) {
12846: foreach my $key (keys(%todeletedir)) {
12847: rmdir($key);
12848: }
12849: }
12850: foreach my $dir (sort(keys(%is_dir))) {
12851: if (($pathtocheck ne '') && ($dir ne '')) {
12852: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12853: }
12854: }
1.1067 raeburn 12855: if ($result ne '') {
12856: $output .= '<ul>'."\n".
12857: $result."\n".
12858: '</ul>';
12859: }
12860: unless ($ishome) {
12861: my $replicationfail;
12862: foreach my $item (keys(%prompttofetch)) {
12863: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12864: unless ($fetchresult eq 'ok') {
12865: $replicationfail .= '<li>'.$item.'</li>'."\n";
12866: }
12867: }
12868: if ($replicationfail) {
12869: $output .= '<p class="LC_error">'.
12870: &mt('Course home server failed to retrieve:').'<ul>'.
12871: $replicationfail.
12872: '</ul></p>';
12873: }
12874: }
1.1055 raeburn 12875: } else {
12876: $warning = &mt('No items found in archive.');
12877: }
12878: if ($error) {
12879: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12880: $error.'</p>'."\n";
12881: }
12882: if ($warning) {
12883: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12884: }
12885: return $output;
12886: }
12887:
1.1066 raeburn 12888: sub cleanup_empty_dirs {
12889: my ($path) = @_;
12890: if (($path ne '') && (-d $path)) {
12891: if (opendir(my $dirh,$path)) {
12892: my @dircontents = grep(!/^\./,readdir($dirh));
12893: my $numitems = 0;
12894: foreach my $item (@dircontents) {
12895: if (-d "$path/$item") {
1.1075.2.28 raeburn 12896: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12897: if (-e "$path/$item") {
12898: $numitems ++;
12899: }
12900: } else {
12901: $numitems ++;
12902: }
12903: }
12904: if ($numitems == 0) {
12905: rmdir($path);
12906: }
12907: closedir($dirh);
12908: }
12909: }
12910: return;
12911: }
12912:
1.41 ng 12913: =pod
1.45 matthew 12914:
1.1075.2.56 raeburn 12915: =item * &get_folder_hierarchy()
1.1068 raeburn 12916:
12917: Provides hierarchy of names of folders/sub-folders containing the current
12918: item,
12919:
12920: Inputs: 3
12921: - $navmap - navmaps object
12922:
12923: - $map - url for map (either the trigger itself, or map containing
12924: the resource, which is the trigger).
12925:
12926: - $showitem - 1 => show title for map itself; 0 => do not show.
12927:
12928: Outputs: 1 @pathitems - array of folder/subfolder names.
12929:
12930: =cut
12931:
12932: sub get_folder_hierarchy {
12933: my ($navmap,$map,$showitem) = @_;
12934: my @pathitems;
12935: if (ref($navmap)) {
12936: my $mapres = $navmap->getResourceByUrl($map);
12937: if (ref($mapres)) {
12938: my $pcslist = $mapres->map_hierarchy();
12939: if ($pcslist ne '') {
12940: my @pcs = split(/,/,$pcslist);
12941: foreach my $pc (@pcs) {
12942: if ($pc == 1) {
1.1075.2.38 raeburn 12943: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12944: } else {
12945: my $res = $navmap->getByMapPc($pc);
12946: if (ref($res)) {
12947: my $title = $res->compTitle();
12948: $title =~ s/\W+/_/g;
12949: if ($title ne '') {
12950: push(@pathitems,$title);
12951: }
12952: }
12953: }
12954: }
12955: }
1.1071 raeburn 12956: if ($showitem) {
12957: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12958: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12959: } else {
12960: my $maptitle = $mapres->compTitle();
12961: $maptitle =~ s/\W+/_/g;
12962: if ($maptitle ne '') {
12963: push(@pathitems,$maptitle);
12964: }
1.1068 raeburn 12965: }
12966: }
12967: }
12968: }
12969: return @pathitems;
12970: }
12971:
12972: =pod
12973:
1.1015 raeburn 12974: =item * &get_turnedin_filepath()
12975:
12976: Determines path in a user's portfolio file for storage of files uploaded
12977: to a specific essayresponse or dropbox item.
12978:
12979: Inputs: 3 required + 1 optional.
12980: $symb is symb for resource, $uname and $udom are for current user (required).
12981: $caller is optional (can be "submission", if routine is called when storing
12982: an upoaded file when "Submit Answer" button was pressed).
12983:
12984: Returns array containing $path and $multiresp.
12985: $path is path in portfolio. $multiresp is 1 if this resource contains more
12986: than one file upload item. Callers of routine should append partid as a
12987: subdirectory to $path in cases where $multiresp is 1.
12988:
12989: Called by: homework/essayresponse.pm and homework/structuretags.pm
12990:
12991: =cut
12992:
12993: sub get_turnedin_filepath {
12994: my ($symb,$uname,$udom,$caller) = @_;
12995: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12996: my $turnindir;
12997: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12998: $turnindir = $userhash{'turnindir'};
12999: my ($path,$multiresp);
13000: if ($turnindir eq '') {
13001: if ($caller eq 'submission') {
13002: $turnindir = &mt('turned in');
13003: $turnindir =~ s/\W+/_/g;
13004: my %newhash = (
13005: 'turnindir' => $turnindir,
13006: );
13007: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13008: }
13009: }
13010: if ($turnindir ne '') {
13011: $path = '/'.$turnindir.'/';
13012: my ($multipart,$turnin,@pathitems);
13013: my $navmap = Apache::lonnavmaps::navmap->new();
13014: if (defined($navmap)) {
13015: my $mapres = $navmap->getResourceByUrl($map);
13016: if (ref($mapres)) {
13017: my $pcslist = $mapres->map_hierarchy();
13018: if ($pcslist ne '') {
13019: foreach my $pc (split(/,/,$pcslist)) {
13020: my $res = $navmap->getByMapPc($pc);
13021: if (ref($res)) {
13022: my $title = $res->compTitle();
13023: $title =~ s/\W+/_/g;
13024: if ($title ne '') {
1.1075.2.48 raeburn 13025: if (($pc > 1) && (length($title) > 12)) {
13026: $title = substr($title,0,12);
13027: }
1.1015 raeburn 13028: push(@pathitems,$title);
13029: }
13030: }
13031: }
13032: }
13033: my $maptitle = $mapres->compTitle();
13034: $maptitle =~ s/\W+/_/g;
13035: if ($maptitle ne '') {
1.1075.2.48 raeburn 13036: if (length($maptitle) > 12) {
13037: $maptitle = substr($maptitle,0,12);
13038: }
1.1015 raeburn 13039: push(@pathitems,$maptitle);
13040: }
13041: unless ($env{'request.state'} eq 'construct') {
13042: my $res = $navmap->getBySymb($symb);
13043: if (ref($res)) {
13044: my $partlist = $res->parts();
13045: my $totaluploads = 0;
13046: if (ref($partlist) eq 'ARRAY') {
13047: foreach my $part (@{$partlist}) {
13048: my @types = $res->responseType($part);
13049: my @ids = $res->responseIds($part);
13050: for (my $i=0; $i < scalar(@ids); $i++) {
13051: if ($types[$i] eq 'essay') {
13052: my $partid = $part.'_'.$ids[$i];
13053: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13054: $totaluploads ++;
13055: }
13056: }
13057: }
13058: }
13059: if ($totaluploads > 1) {
13060: $multiresp = 1;
13061: }
13062: }
13063: }
13064: }
13065: } else {
13066: return;
13067: }
13068: } else {
13069: return;
13070: }
13071: my $restitle=&Apache::lonnet::gettitle($symb);
13072: $restitle =~ s/\W+/_/g;
13073: if ($restitle eq '') {
13074: $restitle = ($resurl =~ m{/[^/]+$});
13075: if ($restitle eq '') {
13076: $restitle = time;
13077: }
13078: }
1.1075.2.48 raeburn 13079: if (length($restitle) > 12) {
13080: $restitle = substr($restitle,0,12);
13081: }
1.1015 raeburn 13082: push(@pathitems,$restitle);
13083: $path .= join('/',@pathitems);
13084: }
13085: return ($path,$multiresp);
13086: }
13087:
13088: =pod
13089:
1.464 albertel 13090: =back
1.41 ng 13091:
1.112 bowersj2 13092: =head1 CSV Upload/Handling functions
1.38 albertel 13093:
1.41 ng 13094: =over 4
13095:
1.648 raeburn 13096: =item * &upfile_store($r)
1.41 ng 13097:
13098: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13099: needs $env{'form.upfile'}
1.41 ng 13100: returns $datatoken to be put into hidden field
13101:
13102: =cut
1.31 albertel 13103:
13104: sub upfile_store {
13105: my $r=shift;
1.258 albertel 13106: $env{'form.upfile'}=~s/\r/\n/gs;
13107: $env{'form.upfile'}=~s/\f/\n/gs;
13108: $env{'form.upfile'}=~s/\n+/\n/gs;
13109: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13110:
1.1075.2.128! raeburn 13111: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
! 13112: '_enroll_'.$env{'request.course.id'}.'_'.
! 13113: time.'_'.$$);
! 13114: return if ($datatoken eq '');
! 13115:
1.31 albertel 13116: {
1.158 raeburn 13117: my $datafile = $r->dir_config('lonDaemons').
13118: '/tmp/'.$datatoken.'.tmp';
1.1075.2.128! raeburn 13119: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13120: print $fh $env{'form.upfile'};
1.158 raeburn 13121: close($fh);
13122: }
1.31 albertel 13123: }
13124: return $datatoken;
13125: }
13126:
1.56 matthew 13127: =pod
13128:
1.1075.2.128! raeburn 13129: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13130:
13131: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1075.2.128! raeburn 13132: $datatoken is the name to assign to the temporary file.
1.258 albertel 13133: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13134:
13135: =cut
1.31 albertel 13136:
13137: sub load_tmp_file {
1.1075.2.128! raeburn 13138: my ($r,$datatoken) = @_;
! 13139: return if ($datatoken eq '');
1.31 albertel 13140: my @studentdata=();
13141: {
1.158 raeburn 13142: my $studentfile = $r->dir_config('lonDaemons').
1.1075.2.128! raeburn 13143: '/tmp/'.$datatoken.'.tmp';
! 13144: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13145: @studentdata=<$fh>;
13146: close($fh);
13147: }
1.31 albertel 13148: }
1.258 albertel 13149: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13150: }
13151:
1.1075.2.128! raeburn 13152: sub valid_datatoken {
! 13153: my ($datatoken) = @_;
! 13154: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_$match_domain\_$match_courseid\_\d+_\d+$/) {
! 13155: return $datatoken;
! 13156: }
! 13157: return;
! 13158: }
! 13159:
1.56 matthew 13160: =pod
13161:
1.648 raeburn 13162: =item * &upfile_record_sep()
1.41 ng 13163:
13164: Separate uploaded file into records
13165: returns array of records,
1.258 albertel 13166: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13167:
13168: =cut
1.31 albertel 13169:
13170: sub upfile_record_sep {
1.258 albertel 13171: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13172: } else {
1.248 albertel 13173: my @records;
1.258 albertel 13174: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13175: if ($line=~/^\s*$/) { next; }
13176: push(@records,$line);
13177: }
13178: return @records;
1.31 albertel 13179: }
13180: }
13181:
1.56 matthew 13182: =pod
13183:
1.648 raeburn 13184: =item * &record_sep($record)
1.41 ng 13185:
1.258 albertel 13186: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13187:
13188: =cut
13189:
1.263 www 13190: sub takeleft {
13191: my $index=shift;
13192: return substr('0000'.$index,-4,4);
13193: }
13194:
1.31 albertel 13195: sub record_sep {
13196: my $record=shift;
13197: my %components=();
1.258 albertel 13198: if ($env{'form.upfiletype'} eq 'xml') {
13199: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13200: my $i=0;
1.356 albertel 13201: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13202: $field=~s/^(\"|\')//;
13203: $field=~s/(\"|\')$//;
1.263 www 13204: $components{&takeleft($i)}=$field;
1.31 albertel 13205: $i++;
13206: }
1.258 albertel 13207: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13208: my $i=0;
1.356 albertel 13209: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13210: $field=~s/^(\"|\')//;
13211: $field=~s/(\"|\')$//;
1.263 www 13212: $components{&takeleft($i)}=$field;
1.31 albertel 13213: $i++;
13214: }
13215: } else {
1.561 www 13216: my $separator=',';
1.480 banghart 13217: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13218: $separator=';';
1.480 banghart 13219: }
1.31 albertel 13220: my $i=0;
1.561 www 13221: # the character we are looking for to indicate the end of a quote or a record
13222: my $looking_for=$separator;
13223: # do not add the characters to the fields
13224: my $ignore=0;
13225: # we just encountered a separator (or the beginning of the record)
13226: my $just_found_separator=1;
13227: # store the field we are working on here
13228: my $field='';
13229: # work our way through all characters in record
13230: foreach my $character ($record=~/(.)/g) {
13231: if ($character eq $looking_for) {
13232: if ($character ne $separator) {
13233: # Found the end of a quote, again looking for separator
13234: $looking_for=$separator;
13235: $ignore=1;
13236: } else {
13237: # Found a separator, store away what we got
13238: $components{&takeleft($i)}=$field;
13239: $i++;
13240: $just_found_separator=1;
13241: $ignore=0;
13242: $field='';
13243: }
13244: next;
13245: }
13246: # single or double quotation marks after a separator indicate beginning of a quote
13247: # we are now looking for the end of the quote and need to ignore separators
13248: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13249: $looking_for=$character;
13250: next;
13251: }
13252: # ignore would be true after we reached the end of a quote
13253: if ($ignore) { next; }
13254: if (($just_found_separator) && ($character=~/\s/)) { next; }
13255: $field.=$character;
13256: $just_found_separator=0;
1.31 albertel 13257: }
1.561 www 13258: # catch the very last entry, since we never encountered the separator
13259: $components{&takeleft($i)}=$field;
1.31 albertel 13260: }
13261: return %components;
13262: }
13263:
1.144 matthew 13264: ######################################################
13265: ######################################################
13266:
1.56 matthew 13267: =pod
13268:
1.648 raeburn 13269: =item * &upfile_select_html()
1.41 ng 13270:
1.144 matthew 13271: Return HTML code to select a file from the users machine and specify
13272: the file type.
1.41 ng 13273:
13274: =cut
13275:
1.144 matthew 13276: ######################################################
13277: ######################################################
1.31 albertel 13278: sub upfile_select_html {
1.144 matthew 13279: my %Types = (
13280: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13281: semisv => &mt('Semicolon separated values'),
1.144 matthew 13282: space => &mt('Space separated'),
13283: tab => &mt('Tabulator separated'),
13284: # xml => &mt('HTML/XML'),
13285: );
13286: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13287: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13288: foreach my $type (sort(keys(%Types))) {
13289: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13290: }
13291: $Str .= "</select>\n";
13292: return $Str;
1.31 albertel 13293: }
13294:
1.301 albertel 13295: sub get_samples {
13296: my ($records,$toget) = @_;
13297: my @samples=({});
13298: my $got=0;
13299: foreach my $rec (@$records) {
13300: my %temp = &record_sep($rec);
13301: if (! grep(/\S/, values(%temp))) { next; }
13302: if (%temp) {
13303: $samples[$got]=\%temp;
13304: $got++;
13305: if ($got == $toget) { last; }
13306: }
13307: }
13308: return \@samples;
13309: }
13310:
1.144 matthew 13311: ######################################################
13312: ######################################################
13313:
1.56 matthew 13314: =pod
13315:
1.648 raeburn 13316: =item * &csv_print_samples($r,$records)
1.41 ng 13317:
13318: Prints a table of sample values from each column uploaded $r is an
13319: Apache Request ref, $records is an arrayref from
13320: &Apache::loncommon::upfile_record_sep
13321:
13322: =cut
13323:
1.144 matthew 13324: ######################################################
13325: ######################################################
1.31 albertel 13326: sub csv_print_samples {
13327: my ($r,$records) = @_;
1.662 bisitz 13328: my $samples = &get_samples($records,5);
1.301 albertel 13329:
1.594 raeburn 13330: $r->print(&mt('Samples').'<br />'.&start_data_table().
13331: &start_data_table_header_row());
1.356 albertel 13332: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13333: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13334: $r->print(&end_data_table_header_row());
1.301 albertel 13335: foreach my $hash (@$samples) {
1.594 raeburn 13336: $r->print(&start_data_table_row());
1.356 albertel 13337: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13338: $r->print('<td>');
1.356 albertel 13339: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13340: $r->print('</td>');
13341: }
1.594 raeburn 13342: $r->print(&end_data_table_row());
1.31 albertel 13343: }
1.594 raeburn 13344: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13345: }
13346:
1.144 matthew 13347: ######################################################
13348: ######################################################
13349:
1.56 matthew 13350: =pod
13351:
1.648 raeburn 13352: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13353:
13354: Prints a table to create associations between values and table columns.
1.144 matthew 13355:
1.41 ng 13356: $r is an Apache Request ref,
13357: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13358: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13359:
13360: =cut
13361:
1.144 matthew 13362: ######################################################
13363: ######################################################
1.31 albertel 13364: sub csv_print_select_table {
13365: my ($r,$records,$d) = @_;
1.301 albertel 13366: my $i=0;
13367: my $samples = &get_samples($records,1);
1.144 matthew 13368: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13369: &start_data_table().&start_data_table_header_row().
1.144 matthew 13370: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13371: '<th>'.&mt('Column').'</th>'.
13372: &end_data_table_header_row()."\n");
1.356 albertel 13373: foreach my $array_ref (@$d) {
13374: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13375: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13376:
1.875 bisitz 13377: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13378: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13379: $r->print('<option value="none"></option>');
1.356 albertel 13380: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13381: $r->print('<option value="'.$sample.'"'.
13382: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13383: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13384: }
1.594 raeburn 13385: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13386: $i++;
13387: }
1.594 raeburn 13388: $r->print(&end_data_table());
1.31 albertel 13389: $i--;
13390: return $i;
13391: }
1.56 matthew 13392:
1.144 matthew 13393: ######################################################
13394: ######################################################
13395:
1.56 matthew 13396: =pod
1.31 albertel 13397:
1.648 raeburn 13398: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13399:
13400: Prints a table of sample values from the upload and can make associate samples to internal names.
13401:
13402: $r is an Apache Request ref,
13403: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13404: $d is an array of 2 element arrays (internal name, displayed name)
13405:
13406: =cut
13407:
1.144 matthew 13408: ######################################################
13409: ######################################################
1.31 albertel 13410: sub csv_samples_select_table {
13411: my ($r,$records,$d) = @_;
13412: my $i=0;
1.144 matthew 13413: #
1.662 bisitz 13414: my $max_samples = 5;
13415: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13416: $r->print(&start_data_table().
13417: &start_data_table_header_row().'<th>'.
13418: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13419: &end_data_table_header_row());
1.301 albertel 13420:
13421: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13422: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13423: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13424: foreach my $option (@$d) {
13425: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13426: $r->print('<option value="'.$value.'"'.
1.253 albertel 13427: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13428: $display.'</option>');
1.31 albertel 13429: }
13430: $r->print('</select></td><td>');
1.662 bisitz 13431: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13432: if (defined($samples->[$line]{$key})) {
13433: $r->print($samples->[$line]{$key}."<br />\n");
13434: }
13435: }
1.594 raeburn 13436: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13437: $i++;
13438: }
1.594 raeburn 13439: $r->print(&end_data_table());
1.31 albertel 13440: $i--;
13441: return($i);
1.115 matthew 13442: }
13443:
1.144 matthew 13444: ######################################################
13445: ######################################################
13446:
1.115 matthew 13447: =pod
13448:
1.648 raeburn 13449: =item * &clean_excel_name($name)
1.115 matthew 13450:
13451: Returns a replacement for $name which does not contain any illegal characters.
13452:
13453: =cut
13454:
1.144 matthew 13455: ######################################################
13456: ######################################################
1.115 matthew 13457: sub clean_excel_name {
13458: my ($name) = @_;
13459: $name =~ s/[:\*\?\/\\]//g;
13460: if (length($name) > 31) {
13461: $name = substr($name,0,31);
13462: }
13463: return $name;
1.25 albertel 13464: }
1.84 albertel 13465:
1.85 albertel 13466: =pod
13467:
1.648 raeburn 13468: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13469:
13470: Returns either 1 or undef
13471:
13472: 1 if the part is to be hidden, undef if it is to be shown
13473:
13474: Arguments are:
13475:
13476: $id the id of the part to be checked
13477: $symb, optional the symb of the resource to check
13478: $udom, optional the domain of the user to check for
13479: $uname, optional the username of the user to check for
13480:
13481: =cut
1.84 albertel 13482:
13483: sub check_if_partid_hidden {
13484: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13485: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13486: $symb,$udom,$uname);
1.141 albertel 13487: my $truth=1;
13488: #if the string starts with !, then the list is the list to show not hide
13489: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13490: my @hiddenlist=split(/,/,$hiddenparts);
13491: foreach my $checkid (@hiddenlist) {
1.141 albertel 13492: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13493: }
1.141 albertel 13494: return !$truth;
1.84 albertel 13495: }
1.127 matthew 13496:
1.138 matthew 13497:
13498: ############################################################
13499: ############################################################
13500:
13501: =pod
13502:
1.157 matthew 13503: =back
13504:
1.138 matthew 13505: =head1 cgi-bin script and graphing routines
13506:
1.157 matthew 13507: =over 4
13508:
1.648 raeburn 13509: =item * &get_cgi_id()
1.138 matthew 13510:
13511: Inputs: none
13512:
13513: Returns an id which can be used to pass environment variables
13514: to various cgi-bin scripts. These environment variables will
13515: be removed from the users environment after a given time by
13516: the routine &Apache::lonnet::transfer_profile_to_env.
13517:
13518: =cut
13519:
13520: ############################################################
13521: ############################################################
1.152 albertel 13522: my $uniq=0;
1.136 matthew 13523: sub get_cgi_id {
1.154 albertel 13524: $uniq=($uniq+1)%100000;
1.280 albertel 13525: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13526: }
13527:
1.127 matthew 13528: ############################################################
13529: ############################################################
13530:
13531: =pod
13532:
1.648 raeburn 13533: =item * &DrawBarGraph()
1.127 matthew 13534:
1.138 matthew 13535: Facilitates the plotting of data in a (stacked) bar graph.
13536: Puts plot definition data into the users environment in order for
13537: graph.png to plot it. Returns an <img> tag for the plot.
13538: The bars on the plot are labeled '1','2',...,'n'.
13539:
13540: Inputs:
13541:
13542: =over 4
13543:
13544: =item $Title: string, the title of the plot
13545:
13546: =item $xlabel: string, text describing the X-axis of the plot
13547:
13548: =item $ylabel: string, text describing the Y-axis of the plot
13549:
13550: =item $Max: scalar, the maximum Y value to use in the plot
13551: If $Max is < any data point, the graph will not be rendered.
13552:
1.140 matthew 13553: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13554: they are plotted. If undefined, default values will be used.
13555:
1.178 matthew 13556: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13557:
1.138 matthew 13558: =item @Values: An array of array references. Each array reference holds data
13559: to be plotted in a stacked bar chart.
13560:
1.239 matthew 13561: =item If the final element of @Values is a hash reference the key/value
13562: pairs will be added to the graph definition.
13563:
1.138 matthew 13564: =back
13565:
13566: Returns:
13567:
13568: An <img> tag which references graph.png and the appropriate identifying
13569: information for the plot.
13570:
1.127 matthew 13571: =cut
13572:
13573: ############################################################
13574: ############################################################
1.134 matthew 13575: sub DrawBarGraph {
1.178 matthew 13576: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13577: #
13578: if (! defined($colors)) {
13579: $colors = ['#33ff00',
13580: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13581: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13582: ];
13583: }
1.228 matthew 13584: my $extra_settings = {};
13585: if (ref($Values[-1]) eq 'HASH') {
13586: $extra_settings = pop(@Values);
13587: }
1.127 matthew 13588: #
1.136 matthew 13589: my $identifier = &get_cgi_id();
13590: my $id = 'cgi.'.$identifier;
1.129 matthew 13591: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13592: return '';
13593: }
1.225 matthew 13594: #
13595: my @Labels;
13596: if (defined($labels)) {
13597: @Labels = @$labels;
13598: } else {
13599: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 13600: push(@Labels,$i+1);
1.225 matthew 13601: }
13602: }
13603: #
1.129 matthew 13604: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13605: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13606: my %ValuesHash;
13607: my $NumSets=1;
13608: foreach my $array (@Values) {
13609: next if (! ref($array));
1.136 matthew 13610: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13611: join(',',@$array);
1.129 matthew 13612: }
1.127 matthew 13613: #
1.136 matthew 13614: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13615: if ($NumBars < 3) {
13616: $width = 120+$NumBars*32;
1.220 matthew 13617: $xskip = 1;
1.225 matthew 13618: $bar_width = 30;
13619: } elsif ($NumBars < 5) {
13620: $width = 120+$NumBars*20;
13621: $xskip = 1;
13622: $bar_width = 20;
1.220 matthew 13623: } elsif ($NumBars < 10) {
1.136 matthew 13624: $width = 120+$NumBars*15;
13625: $xskip = 1;
13626: $bar_width = 15;
13627: } elsif ($NumBars <= 25) {
13628: $width = 120+$NumBars*11;
13629: $xskip = 5;
13630: $bar_width = 8;
13631: } elsif ($NumBars <= 50) {
13632: $width = 120+$NumBars*8;
13633: $xskip = 5;
13634: $bar_width = 4;
13635: } else {
13636: $width = 120+$NumBars*8;
13637: $xskip = 5;
13638: $bar_width = 4;
13639: }
13640: #
1.137 matthew 13641: $Max = 1 if ($Max < 1);
13642: if ( int($Max) < $Max ) {
13643: $Max++;
13644: $Max = int($Max);
13645: }
1.127 matthew 13646: $Title = '' if (! defined($Title));
13647: $xlabel = '' if (! defined($xlabel));
13648: $ylabel = '' if (! defined($ylabel));
1.369 www 13649: $ValuesHash{$id.'.title'} = &escape($Title);
13650: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13651: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13652: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13653: $ValuesHash{$id.'.NumBars'} = $NumBars;
13654: $ValuesHash{$id.'.NumSets'} = $NumSets;
13655: $ValuesHash{$id.'.PlotType'} = 'bar';
13656: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13657: $ValuesHash{$id.'.height'} = $height;
13658: $ValuesHash{$id.'.width'} = $width;
13659: $ValuesHash{$id.'.xskip'} = $xskip;
13660: $ValuesHash{$id.'.bar_width'} = $bar_width;
13661: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13662: #
1.228 matthew 13663: # Deal with other parameters
13664: while (my ($key,$value) = each(%$extra_settings)) {
13665: $ValuesHash{$id.'.'.$key} = $value;
13666: }
13667: #
1.646 raeburn 13668: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13669: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13670: }
13671:
13672: ############################################################
13673: ############################################################
13674:
13675: =pod
13676:
1.648 raeburn 13677: =item * &DrawXYGraph()
1.137 matthew 13678:
1.138 matthew 13679: Facilitates the plotting of data in an XY graph.
13680: Puts plot definition data into the users environment in order for
13681: graph.png to plot it. Returns an <img> tag for the plot.
13682:
13683: Inputs:
13684:
13685: =over 4
13686:
13687: =item $Title: string, the title of the plot
13688:
13689: =item $xlabel: string, text describing the X-axis of the plot
13690:
13691: =item $ylabel: string, text describing the Y-axis of the plot
13692:
13693: =item $Max: scalar, the maximum Y value to use in the plot
13694: If $Max is < any data point, the graph will not be rendered.
13695:
13696: =item $colors: Array ref containing the hex color codes for the data to be
13697: plotted in. If undefined, default values will be used.
13698:
13699: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13700:
13701: =item $Ydata: Array ref containing Array refs.
1.185 www 13702: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13703:
13704: =item %Values: hash indicating or overriding any default values which are
13705: passed to graph.png.
13706: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13707:
13708: =back
13709:
13710: Returns:
13711:
13712: An <img> tag which references graph.png and the appropriate identifying
13713: information for the plot.
13714:
1.137 matthew 13715: =cut
13716:
13717: ############################################################
13718: ############################################################
13719: sub DrawXYGraph {
13720: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13721: #
13722: # Create the identifier for the graph
13723: my $identifier = &get_cgi_id();
13724: my $id = 'cgi.'.$identifier;
13725: #
13726: $Title = '' if (! defined($Title));
13727: $xlabel = '' if (! defined($xlabel));
13728: $ylabel = '' if (! defined($ylabel));
13729: my %ValuesHash =
13730: (
1.369 www 13731: $id.'.title' => &escape($Title),
13732: $id.'.xlabel' => &escape($xlabel),
13733: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13734: $id.'.y_max_value'=> $Max,
13735: $id.'.labels' => join(',',@$Xlabels),
13736: $id.'.PlotType' => 'XY',
13737: );
13738: #
13739: if (defined($colors) && ref($colors) eq 'ARRAY') {
13740: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13741: }
13742: #
13743: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13744: return '';
13745: }
13746: my $NumSets=1;
1.138 matthew 13747: foreach my $array (@{$Ydata}){
1.137 matthew 13748: next if (! ref($array));
13749: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13750: }
1.138 matthew 13751: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13752: #
13753: # Deal with other parameters
13754: while (my ($key,$value) = each(%Values)) {
13755: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13756: }
13757: #
1.646 raeburn 13758: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13759: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13760: }
13761:
13762: ############################################################
13763: ############################################################
13764:
13765: =pod
13766:
1.648 raeburn 13767: =item * &DrawXYYGraph()
1.138 matthew 13768:
13769: Facilitates the plotting of data in an XY graph with two Y axes.
13770: Puts plot definition data into the users environment in order for
13771: graph.png to plot it. Returns an <img> tag for the plot.
13772:
13773: Inputs:
13774:
13775: =over 4
13776:
13777: =item $Title: string, the title of the plot
13778:
13779: =item $xlabel: string, text describing the X-axis of the plot
13780:
13781: =item $ylabel: string, text describing the Y-axis of the plot
13782:
13783: =item $colors: Array ref containing the hex color codes for the data to be
13784: plotted in. If undefined, default values will be used.
13785:
13786: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13787:
13788: =item $Ydata1: The first data set
13789:
13790: =item $Min1: The minimum value of the left Y-axis
13791:
13792: =item $Max1: The maximum value of the left Y-axis
13793:
13794: =item $Ydata2: The second data set
13795:
13796: =item $Min2: The minimum value of the right Y-axis
13797:
13798: =item $Max2: The maximum value of the left Y-axis
13799:
13800: =item %Values: hash indicating or overriding any default values which are
13801: passed to graph.png.
13802: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13803:
13804: =back
13805:
13806: Returns:
13807:
13808: An <img> tag which references graph.png and the appropriate identifying
13809: information for the plot.
1.136 matthew 13810:
13811: =cut
13812:
13813: ############################################################
13814: ############################################################
1.137 matthew 13815: sub DrawXYYGraph {
13816: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13817: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13818: #
13819: # Create the identifier for the graph
13820: my $identifier = &get_cgi_id();
13821: my $id = 'cgi.'.$identifier;
13822: #
13823: $Title = '' if (! defined($Title));
13824: $xlabel = '' if (! defined($xlabel));
13825: $ylabel = '' if (! defined($ylabel));
13826: my %ValuesHash =
13827: (
1.369 www 13828: $id.'.title' => &escape($Title),
13829: $id.'.xlabel' => &escape($xlabel),
13830: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13831: $id.'.labels' => join(',',@$Xlabels),
13832: $id.'.PlotType' => 'XY',
13833: $id.'.NumSets' => 2,
1.137 matthew 13834: $id.'.two_axes' => 1,
13835: $id.'.y1_max_value' => $Max1,
13836: $id.'.y1_min_value' => $Min1,
13837: $id.'.y2_max_value' => $Max2,
13838: $id.'.y2_min_value' => $Min2,
1.136 matthew 13839: );
13840: #
1.137 matthew 13841: if (defined($colors) && ref($colors) eq 'ARRAY') {
13842: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13843: }
13844: #
13845: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13846: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13847: return '';
13848: }
13849: my $NumSets=1;
1.137 matthew 13850: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13851: next if (! ref($array));
13852: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13853: }
13854: #
13855: # Deal with other parameters
13856: while (my ($key,$value) = each(%Values)) {
13857: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13858: }
13859: #
1.646 raeburn 13860: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13861: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13862: }
13863:
13864: ############################################################
13865: ############################################################
13866:
13867: =pod
13868:
1.157 matthew 13869: =back
13870:
1.139 matthew 13871: =head1 Statistics helper routines?
13872:
13873: Bad place for them but what the hell.
13874:
1.157 matthew 13875: =over 4
13876:
1.648 raeburn 13877: =item * &chartlink()
1.139 matthew 13878:
13879: Returns a link to the chart for a specific student.
13880:
13881: Inputs:
13882:
13883: =over 4
13884:
13885: =item $linktext: The text of the link
13886:
13887: =item $sname: The students username
13888:
13889: =item $sdomain: The students domain
13890:
13891: =back
13892:
1.157 matthew 13893: =back
13894:
1.139 matthew 13895: =cut
13896:
13897: ############################################################
13898: ############################################################
13899: sub chartlink {
13900: my ($linktext, $sname, $sdomain) = @_;
13901: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13902: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13903: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13904: '">'.$linktext.'</a>';
1.153 matthew 13905: }
13906:
13907: #######################################################
13908: #######################################################
13909:
13910: =pod
13911:
13912: =head1 Course Environment Routines
1.157 matthew 13913:
13914: =over 4
1.153 matthew 13915:
1.648 raeburn 13916: =item * &restore_course_settings()
1.153 matthew 13917:
1.648 raeburn 13918: =item * &store_course_settings()
1.153 matthew 13919:
13920: Restores/Store indicated form parameters from the course environment.
13921: Will not overwrite existing values of the form parameters.
13922:
13923: Inputs:
13924: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13925:
13926: a hash ref describing the data to be stored. For example:
13927:
13928: %Save_Parameters = ('Status' => 'scalar',
13929: 'chartoutputmode' => 'scalar',
13930: 'chartoutputdata' => 'scalar',
13931: 'Section' => 'array',
1.373 raeburn 13932: 'Group' => 'array',
1.153 matthew 13933: 'StudentData' => 'array',
13934: 'Maps' => 'array');
13935:
13936: Returns: both routines return nothing
13937:
1.631 raeburn 13938: =back
13939:
1.153 matthew 13940: =cut
13941:
13942: #######################################################
13943: #######################################################
13944: sub store_course_settings {
1.496 albertel 13945: return &store_settings($env{'request.course.id'},@_);
13946: }
13947:
13948: sub store_settings {
1.153 matthew 13949: # save to the environment
13950: # appenv the same items, just to be safe
1.300 albertel 13951: my $udom = $env{'user.domain'};
13952: my $uname = $env{'user.name'};
1.496 albertel 13953: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13954: my %SaveHash;
13955: my %AppHash;
13956: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13957: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13958: my $envname = 'environment.'.$basename;
1.258 albertel 13959: if (exists($env{'form.'.$setting})) {
1.153 matthew 13960: # Save this value away
13961: if ($type eq 'scalar' &&
1.258 albertel 13962: (! exists($env{$envname}) ||
13963: $env{$envname} ne $env{'form.'.$setting})) {
13964: $SaveHash{$basename} = $env{'form.'.$setting};
13965: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13966: } elsif ($type eq 'array') {
13967: my $stored_form;
1.258 albertel 13968: if (ref($env{'form.'.$setting})) {
1.153 matthew 13969: $stored_form = join(',',
13970: map {
1.369 www 13971: &escape($_);
1.258 albertel 13972: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13973: } else {
13974: $stored_form =
1.369 www 13975: &escape($env{'form.'.$setting});
1.153 matthew 13976: }
13977: # Determine if the array contents are the same.
1.258 albertel 13978: if ($stored_form ne $env{$envname}) {
1.153 matthew 13979: $SaveHash{$basename} = $stored_form;
13980: $AppHash{$envname} = $stored_form;
13981: }
13982: }
13983: }
13984: }
13985: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13986: $udom,$uname);
1.153 matthew 13987: if ($put_result !~ /^(ok|delayed)/) {
13988: &Apache::lonnet::logthis('unable to save form parameters, '.
13989: 'got error:'.$put_result);
13990: }
13991: # Make sure these settings stick around in this session, too
1.646 raeburn 13992: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13993: return;
13994: }
13995:
13996: sub restore_course_settings {
1.499 albertel 13997: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13998: }
13999:
14000: sub restore_settings {
14001: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14002: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14003: next if (exists($env{'form.'.$setting}));
1.496 albertel 14004: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14005: '.'.$setting;
1.258 albertel 14006: if (exists($env{$envname})) {
1.153 matthew 14007: if ($type eq 'scalar') {
1.258 albertel 14008: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14009: } elsif ($type eq 'array') {
1.258 albertel 14010: $env{'form.'.$setting} = [
1.153 matthew 14011: map {
1.369 www 14012: &unescape($_);
1.258 albertel 14013: } split(',',$env{$envname})
1.153 matthew 14014: ];
14015: }
14016: }
14017: }
1.127 matthew 14018: }
14019:
1.618 raeburn 14020: #######################################################
14021: #######################################################
14022:
14023: =pod
14024:
14025: =head1 Domain E-mail Routines
14026:
14027: =over 4
14028:
1.648 raeburn 14029: =item * &build_recipient_list()
1.618 raeburn 14030:
1.1075.2.44 raeburn 14031: Build recipient lists for following types of e-mail:
1.766 raeburn 14032: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14033: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14034: module change checking, student/employee ID conflict checks, as
14035: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14036: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14037:
14038: Inputs:
1.1075.2.44 raeburn 14039: defmail (scalar - email address of default recipient),
14040: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14041: requestsmail, updatesmail, or idconflictsmail).
14042:
1.619 raeburn 14043: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14044:
14045: origmail (scalar - email address of recipient from loncapa.conf,
14046: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14047:
1.655 raeburn 14048: Returns: comma separated list of addresses to which to send e-mail.
14049:
14050: =back
1.618 raeburn 14051:
14052: =cut
14053:
14054: ############################################################
14055: ############################################################
14056: sub build_recipient_list {
1.619 raeburn 14057: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14058: my @recipients;
1.1075.2.122 raeburn 14059: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14060: my %domconfig =
1.1075.2.122 raeburn 14061: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14062: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14063: if (exists($domconfig{'contacts'}{$mailing})) {
14064: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14065: my @contacts = ('adminemail','supportemail');
14066: foreach my $item (@contacts) {
14067: if ($domconfig{'contacts'}{$mailing}{$item}) {
14068: my $addr = $domconfig{'contacts'}{$item};
14069: if (!grep(/^\Q$addr\E$/,@recipients)) {
14070: push(@recipients,$addr);
14071: }
1.619 raeburn 14072: }
1.1075.2.122 raeburn 14073: }
14074: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14075: if ($mailing eq 'helpdeskmail') {
14076: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14077: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14078: my @ok_bccs;
14079: foreach my $bcc (@bccs) {
14080: $bcc =~ s/^\s+//g;
14081: $bcc =~ s/\s+$//g;
14082: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14083: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14084: push(@ok_bccs,$bcc);
14085: }
14086: }
14087: }
14088: if (@ok_bccs > 0) {
14089: $allbcc = join(', ',@ok_bccs);
14090: }
14091: }
14092: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14093: }
14094: }
1.766 raeburn 14095: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14096: $lastresort = $origmail;
1.618 raeburn 14097: }
1.619 raeburn 14098: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14099: $lastresort = $origmail;
14100: }
14101:
1.1075.2.128! raeburn 14102: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1075.2.122 raeburn 14103: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14104: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14105: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14106: my %what = (
14107: perlvar => 1,
14108: );
14109: my $primary = &Apache::lonnet::domain($defdom,'primary');
14110: if ($primary) {
14111: my $gotaddr;
14112: my ($result,$returnhash) =
14113: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14114: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14115: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14116: $lastresort = $returnhash->{'lonSupportEMail'};
14117: $gotaddr = 1;
14118: }
14119: }
14120: unless ($gotaddr) {
14121: my $uintdom = &Apache::lonnet::internet_dom($primary);
14122: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14123: unless ($uintdom eq $intdom) {
14124: my %domconfig =
14125: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14126: if (ref($domconfig{'contacts'}) eq 'HASH') {
14127: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14128: my @contacts = ('adminemail','supportemail');
14129: foreach my $item (@contacts) {
14130: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14131: my $addr = $domconfig{'contacts'}{$item};
14132: if (!grep(/^\Q$addr\E$/,@recipients)) {
14133: push(@recipients,$addr);
14134: }
14135: }
14136: }
14137: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14138: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14139: }
14140: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14141: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14142: my @ok_bccs;
14143: foreach my $bcc (@bccs) {
14144: $bcc =~ s/^\s+//g;
14145: $bcc =~ s/\s+$//g;
14146: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14147: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14148: push(@ok_bccs,$bcc);
14149: }
14150: }
14151: }
14152: if (@ok_bccs > 0) {
14153: $allbcc = join(', ',@ok_bccs);
14154: }
14155: }
14156: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14157: }
14158: }
14159: }
14160: }
14161: }
14162: }
1.618 raeburn 14163: }
1.688 raeburn 14164: if (defined($defmail)) {
14165: if ($defmail ne '') {
14166: push(@recipients,$defmail);
14167: }
1.618 raeburn 14168: }
14169: if ($otheremails) {
1.619 raeburn 14170: my @others;
14171: if ($otheremails =~ /,/) {
14172: @others = split(/,/,$otheremails);
1.618 raeburn 14173: } else {
1.619 raeburn 14174: push(@others,$otheremails);
14175: }
14176: foreach my $addr (@others) {
14177: if (!grep(/^\Q$addr\E$/,@recipients)) {
14178: push(@recipients,$addr);
14179: }
1.618 raeburn 14180: }
14181: }
1.1075.2.128! raeburn 14182: if ($mailing eq 'helpdeskmail') {
1.1075.2.122 raeburn 14183: if ((!@recipients) && ($lastresort ne '')) {
14184: push(@recipients,$lastresort);
14185: }
14186: } elsif ($lastresort ne '') {
14187: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14188: push(@recipients,$lastresort);
14189: }
14190: }
14191: my $recipientlist = join(',',@recipients);
14192: if (wantarray) {
14193: return ($recipientlist,$allbcc,$addtext);
14194: } else {
14195: return $recipientlist;
14196: }
1.618 raeburn 14197: }
14198:
1.127 matthew 14199: ############################################################
14200: ############################################################
1.154 albertel 14201:
1.655 raeburn 14202: =pod
14203:
14204: =head1 Course Catalog Routines
14205:
14206: =over 4
14207:
14208: =item * &gather_categories()
14209:
14210: Converts category definitions - keys of categories hash stored in
14211: coursecategories in configuration.db on the primary library server in a
14212: domain - to an array. Also generates javascript and idx hash used to
14213: generate Domain Coordinator interface for editing Course Categories.
14214:
14215: Inputs:
1.663 raeburn 14216:
1.655 raeburn 14217: categories (reference to hash of category definitions).
1.663 raeburn 14218:
1.655 raeburn 14219: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14220: categories and subcategories).
1.663 raeburn 14221:
1.655 raeburn 14222: idx (reference to hash of counters used in Domain Coordinator interface for
14223: editing Course Categories).
1.663 raeburn 14224:
1.655 raeburn 14225: jsarray (reference to array of categories used to create Javascript arrays for
14226: Domain Coordinator interface for editing Course Categories).
14227:
14228: Returns: nothing
14229:
14230: Side effects: populates cats, idx and jsarray.
14231:
14232: =cut
14233:
14234: sub gather_categories {
14235: my ($categories,$cats,$idx,$jsarray) = @_;
14236: my %counters;
14237: my $num = 0;
14238: foreach my $item (keys(%{$categories})) {
14239: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14240: if ($container eq '' && $depth == 0) {
14241: $cats->[$depth][$categories->{$item}] = $cat;
14242: } else {
14243: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14244: }
14245: my ($escitem,$tail) = split(/:/,$item,2);
14246: if ($counters{$tail} eq '') {
14247: $counters{$tail} = $num;
14248: $num ++;
14249: }
14250: if (ref($idx) eq 'HASH') {
14251: $idx->{$item} = $counters{$tail};
14252: }
14253: if (ref($jsarray) eq 'ARRAY') {
14254: push(@{$jsarray->[$counters{$tail}]},$item);
14255: }
14256: }
14257: return;
14258: }
14259:
14260: =pod
14261:
14262: =item * &extract_categories()
14263:
14264: Used to generate breadcrumb trails for course categories.
14265:
14266: Inputs:
1.663 raeburn 14267:
1.655 raeburn 14268: categories (reference to hash of category definitions).
1.663 raeburn 14269:
1.655 raeburn 14270: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14271: categories and subcategories).
1.663 raeburn 14272:
1.655 raeburn 14273: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14274:
1.655 raeburn 14275: allitems (reference to hash - key is category key
14276: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14277:
1.655 raeburn 14278: idx (reference to hash of counters used in Domain Coordinator interface for
14279: editing Course Categories).
1.663 raeburn 14280:
1.655 raeburn 14281: jsarray (reference to array of categories used to create Javascript arrays for
14282: Domain Coordinator interface for editing Course Categories).
14283:
1.665 raeburn 14284: subcats (reference to hash of arrays containing all subcategories within each
14285: category, -recursive)
14286:
1.655 raeburn 14287: Returns: nothing
14288:
14289: Side effects: populates trails and allitems hash references.
14290:
14291: =cut
14292:
14293: sub extract_categories {
1.665 raeburn 14294: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14295: if (ref($categories) eq 'HASH') {
14296: &gather_categories($categories,$cats,$idx,$jsarray);
14297: if (ref($cats->[0]) eq 'ARRAY') {
14298: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14299: my $name = $cats->[0][$i];
14300: my $item = &escape($name).'::0';
14301: my $trailstr;
14302: if ($name eq 'instcode') {
14303: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14304: } elsif ($name eq 'communities') {
14305: $trailstr = &mt('Communities');
1.655 raeburn 14306: } else {
14307: $trailstr = $name;
14308: }
14309: if ($allitems->{$item} eq '') {
14310: push(@{$trails},$trailstr);
14311: $allitems->{$item} = scalar(@{$trails})-1;
14312: }
14313: my @parents = ($name);
14314: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14315: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14316: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14317: if (ref($subcats) eq 'HASH') {
14318: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14319: }
14320: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14321: }
14322: } else {
14323: if (ref($subcats) eq 'HASH') {
14324: $subcats->{$item} = [];
1.655 raeburn 14325: }
14326: }
14327: }
14328: }
14329: }
14330: return;
14331: }
14332:
14333: =pod
14334:
1.1075.2.56 raeburn 14335: =item * &recurse_categories()
1.655 raeburn 14336:
14337: Recursively used to generate breadcrumb trails for course categories.
14338:
14339: Inputs:
1.663 raeburn 14340:
1.655 raeburn 14341: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14342: categories and subcategories).
1.663 raeburn 14343:
1.655 raeburn 14344: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14345:
14346: category (current course category, for which breadcrumb trail is being generated).
14347:
14348: trails (reference to array of breadcrumb trails for each category).
14349:
1.655 raeburn 14350: allitems (reference to hash - key is category key
14351: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14352:
1.655 raeburn 14353: parents (array containing containers directories for current category,
14354: back to top level).
14355:
14356: Returns: nothing
14357:
14358: Side effects: populates trails and allitems hash references
14359:
14360: =cut
14361:
14362: sub recurse_categories {
1.665 raeburn 14363: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14364: my $shallower = $depth - 1;
14365: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14366: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14367: my $name = $cats->[$depth]{$category}[$k];
14368: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14369: my $trailstr = join(' -> ',(@{$parents},$category));
14370: if ($allitems->{$item} eq '') {
14371: push(@{$trails},$trailstr);
14372: $allitems->{$item} = scalar(@{$trails})-1;
14373: }
14374: my $deeper = $depth+1;
14375: push(@{$parents},$category);
1.665 raeburn 14376: if (ref($subcats) eq 'HASH') {
14377: my $subcat = &escape($name).':'.$category.':'.$depth;
14378: for (my $j=@{$parents}; $j>=0; $j--) {
14379: my $higher;
14380: if ($j > 0) {
14381: $higher = &escape($parents->[$j]).':'.
14382: &escape($parents->[$j-1]).':'.$j;
14383: } else {
14384: $higher = &escape($parents->[$j]).'::'.$j;
14385: }
14386: push(@{$subcats->{$higher}},$subcat);
14387: }
14388: }
14389: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14390: $subcats);
1.655 raeburn 14391: pop(@{$parents});
14392: }
14393: } else {
14394: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14395: my $trailstr = join(' -> ',(@{$parents},$category));
14396: if ($allitems->{$item} eq '') {
14397: push(@{$trails},$trailstr);
14398: $allitems->{$item} = scalar(@{$trails})-1;
14399: }
14400: }
14401: return;
14402: }
14403:
1.663 raeburn 14404: =pod
14405:
1.1075.2.56 raeburn 14406: =item * &assign_categories_table()
1.663 raeburn 14407:
14408: Create a datatable for display of hierarchical categories in a domain,
14409: with checkboxes to allow a course to be categorized.
14410:
14411: Inputs:
14412:
14413: cathash - reference to hash of categories defined for the domain (from
14414: configuration.db)
14415:
14416: currcat - scalar with an & separated list of categories assigned to a course.
14417:
1.919 raeburn 14418: type - scalar contains course type (Course or Community).
14419:
1.1075.2.117 raeburn 14420: disabled - scalar (optional) contains disabled="disabled" if input elements are
14421: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14422:
1.663 raeburn 14423: Returns: $output (markup to be displayed)
14424:
14425: =cut
14426:
14427: sub assign_categories_table {
1.1075.2.117 raeburn 14428: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14429: my $output;
14430: if (ref($cathash) eq 'HASH') {
14431: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14432: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
14433: $maxdepth = scalar(@cats);
14434: if (@cats > 0) {
14435: my $itemcount = 0;
14436: if (ref($cats[0]) eq 'ARRAY') {
14437: my @currcategories;
14438: if ($currcat ne '') {
14439: @currcategories = split('&',$currcat);
14440: }
1.919 raeburn 14441: my $table;
1.663 raeburn 14442: for (my $i=0; $i<@{$cats[0]}; $i++) {
14443: my $parent = $cats[0][$i];
1.919 raeburn 14444: next if ($parent eq 'instcode');
14445: if ($type eq 'Community') {
14446: next unless ($parent eq 'communities');
14447: } else {
14448: next if ($parent eq 'communities');
14449: }
1.663 raeburn 14450: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14451: my $item = &escape($parent).'::0';
14452: my $checked = '';
14453: if (@currcategories > 0) {
14454: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14455: $checked = ' checked="checked"';
1.663 raeburn 14456: }
14457: }
1.919 raeburn 14458: my $parent_title = $parent;
14459: if ($parent eq 'communities') {
14460: $parent_title = &mt('Communities');
14461: }
14462: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14463: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14464: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 14465: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14466: my $depth = 1;
14467: push(@path,$parent);
1.1075.2.117 raeburn 14468: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 14469: pop(@path);
1.919 raeburn 14470: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14471: $itemcount ++;
14472: }
1.919 raeburn 14473: if ($itemcount) {
14474: $output = &Apache::loncommon::start_data_table().
14475: $table.
14476: &Apache::loncommon::end_data_table();
14477: }
1.663 raeburn 14478: }
14479: }
14480: }
14481: return $output;
14482: }
14483:
14484: =pod
14485:
1.1075.2.56 raeburn 14486: =item * &assign_category_rows()
1.663 raeburn 14487:
14488: Create a datatable row for display of nested categories in a domain,
14489: with checkboxes to allow a course to be categorized,called recursively.
14490:
14491: Inputs:
14492:
14493: itemcount - track row number for alternating colors
14494:
14495: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14496: categories and subcategories.
14497:
14498: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14499:
14500: parent - parent of current category item
14501:
14502: path - Array containing all categories back up through the hierarchy from the
14503: current category to the top level.
14504:
14505: currcategories - reference to array of current categories assigned to the course
14506:
1.1075.2.117 raeburn 14507: disabled - scalar (optional) contains disabled="disabled" if input elements are
14508: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14509:
1.663 raeburn 14510: Returns: $output (markup to be displayed).
14511:
14512: =cut
14513:
14514: sub assign_category_rows {
1.1075.2.117 raeburn 14515: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 14516: my ($text,$name,$item,$chgstr);
14517: if (ref($cats) eq 'ARRAY') {
14518: my $maxdepth = scalar(@{$cats});
14519: if (ref($cats->[$depth]) eq 'HASH') {
14520: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14521: my $numchildren = @{$cats->[$depth]{$parent}};
14522: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 14523: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14524: for (my $j=0; $j<$numchildren; $j++) {
14525: $name = $cats->[$depth]{$parent}[$j];
14526: $item = &escape($name).':'.&escape($parent).':'.$depth;
14527: my $deeper = $depth+1;
14528: my $checked = '';
14529: if (ref($currcategories) eq 'ARRAY') {
14530: if (@{$currcategories} > 0) {
14531: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14532: $checked = ' checked="checked"';
1.663 raeburn 14533: }
14534: }
14535: }
1.664 raeburn 14536: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14537: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14538: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 14539: '<input type="hidden" name="catname" value="'.$name.'" />'.
14540: '</td><td>';
1.663 raeburn 14541: if (ref($path) eq 'ARRAY') {
14542: push(@{$path},$name);
1.1075.2.117 raeburn 14543: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 14544: pop(@{$path});
14545: }
14546: $text .= '</td></tr>';
14547: }
14548: $text .= '</table></td>';
14549: }
14550: }
14551: }
14552: return $text;
14553: }
14554:
1.1075.2.69 raeburn 14555: =pod
14556:
14557: =back
14558:
14559: =cut
14560:
1.655 raeburn 14561: ############################################################
14562: ############################################################
14563:
14564:
1.443 albertel 14565: sub commit_customrole {
1.664 raeburn 14566: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14567: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14568: ($start?', '.&mt('starting').' '.localtime($start):'').
14569: ($end?', ending '.localtime($end):'').': <b>'.
14570: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14571: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14572: '</b><br />';
14573: return $output;
14574: }
14575:
14576: sub commit_standardrole {
1.1075.2.31 raeburn 14577: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14578: my ($output,$logmsg,$linefeed);
14579: if ($context eq 'auto') {
14580: $linefeed = "\n";
14581: } else {
14582: $linefeed = "<br />\n";
14583: }
1.443 albertel 14584: if ($three eq 'st') {
1.541 raeburn 14585: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14586: $one,$two,$sec,$context,$credits);
1.541 raeburn 14587: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14588: ($result eq 'unknown_course') || ($result eq 'refused')) {
14589: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14590: } else {
1.541 raeburn 14591: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14592: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14593: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14594: if ($context eq 'auto') {
14595: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14596: } else {
14597: $output .= '<b>'.$result.'</b>'.$linefeed.
14598: &mt('Add to classlist').': <b>ok</b>';
14599: }
14600: $output .= $linefeed;
1.443 albertel 14601: }
14602: } else {
14603: $output = &mt('Assigning').' '.$three.' in '.$url.
14604: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14605: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14606: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14607: if ($context eq 'auto') {
14608: $output .= $result.$linefeed;
14609: } else {
14610: $output .= '<b>'.$result.'</b>'.$linefeed;
14611: }
1.443 albertel 14612: }
14613: return $output;
14614: }
14615:
14616: sub commit_studentrole {
1.1075.2.31 raeburn 14617: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14618: $credits) = @_;
1.626 raeburn 14619: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14620: if ($context eq 'auto') {
14621: $linefeed = "\n";
14622: } else {
14623: $linefeed = '<br />'."\n";
14624: }
1.443 albertel 14625: if (defined($one) && defined($two)) {
14626: my $cid=$one.'_'.$two;
14627: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14628: my $secchange = 0;
14629: my $expire_role_result;
14630: my $modify_section_result;
1.628 raeburn 14631: if ($oldsec ne '-1') {
14632: if ($oldsec ne $sec) {
1.443 albertel 14633: $secchange = 1;
1.628 raeburn 14634: my $now = time;
1.443 albertel 14635: my $uurl='/'.$cid;
14636: $uurl=~s/\_/\//g;
14637: if ($oldsec) {
14638: $uurl.='/'.$oldsec;
14639: }
1.626 raeburn 14640: $oldsecurl = $uurl;
1.628 raeburn 14641: $expire_role_result =
1.652 raeburn 14642: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14643: if ($env{'request.course.sec'} ne '') {
14644: if ($expire_role_result eq 'refused') {
14645: my @roles = ('st');
14646: my @statuses = ('previous');
14647: my @roledoms = ($one);
14648: my $withsec = 1;
14649: my %roleshash =
14650: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14651: \@statuses,\@roles,\@roledoms,$withsec);
14652: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14653: my ($oldstart,$oldend) =
14654: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14655: if ($oldend > 0 && $oldend <= $now) {
14656: $expire_role_result = 'ok';
14657: }
14658: }
14659: }
14660: }
1.443 albertel 14661: $result = $expire_role_result;
14662: }
14663: }
14664: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 14665: $modify_section_result =
14666: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14667: undef,undef,undef,$sec,
14668: $end,$start,'','',$cid,
14669: '',$context,$credits);
1.443 albertel 14670: if ($modify_section_result =~ /^ok/) {
14671: if ($secchange == 1) {
1.628 raeburn 14672: if ($sec eq '') {
14673: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14674: } else {
14675: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14676: }
1.443 albertel 14677: } elsif ($oldsec eq '-1') {
1.628 raeburn 14678: if ($sec eq '') {
14679: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14680: } else {
14681: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14682: }
1.443 albertel 14683: } else {
1.628 raeburn 14684: if ($sec eq '') {
14685: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14686: } else {
14687: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14688: }
1.443 albertel 14689: }
14690: } else {
1.628 raeburn 14691: if ($secchange) {
14692: $$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;
14693: } else {
14694: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14695: }
1.443 albertel 14696: }
14697: $result = $modify_section_result;
14698: } elsif ($secchange == 1) {
1.628 raeburn 14699: if ($oldsec eq '') {
1.1075.2.20 raeburn 14700: $$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 14701: } else {
14702: $$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;
14703: }
1.626 raeburn 14704: if ($expire_role_result eq 'refused') {
14705: my $newsecurl = '/'.$cid;
14706: $newsecurl =~ s/\_/\//g;
14707: if ($sec ne '') {
14708: $newsecurl.='/'.$sec;
14709: }
14710: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14711: if ($sec eq '') {
14712: $$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;
14713: } else {
14714: $$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;
14715: }
14716: }
14717: }
1.443 albertel 14718: }
14719: } else {
1.626 raeburn 14720: $$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 14721: $result = "error: incomplete course id\n";
14722: }
14723: return $result;
14724: }
14725:
1.1075.2.25 raeburn 14726: sub show_role_extent {
14727: my ($scope,$context,$role) = @_;
14728: $scope =~ s{^/}{};
14729: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14730: push(@courseroles,'co');
14731: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14732: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14733: $scope =~ s{/}{_};
14734: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14735: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14736: my ($audom,$auname) = split(/\//,$scope);
14737: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14738: &Apache::loncommon::plainname($auname,$audom).'</span>');
14739: } else {
14740: $scope =~ s{/$}{};
14741: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14742: &Apache::lonnet::domain($scope,'description').'</span>');
14743: }
14744: }
14745:
1.443 albertel 14746: ############################################################
14747: ############################################################
14748:
1.566 albertel 14749: sub check_clone {
1.578 raeburn 14750: my ($args,$linefeed) = @_;
1.566 albertel 14751: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14752: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14753: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14754: my $clonemsg;
14755: my $can_clone = 0;
1.944 raeburn 14756: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14757: if ($lctype ne 'community') {
14758: $lctype = 'course';
14759: }
1.566 albertel 14760: if ($clonehome eq 'no_host') {
1.944 raeburn 14761: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14762: $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'});
14763: } else {
14764: $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'});
14765: }
1.566 albertel 14766: } else {
14767: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14768: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14769: if ($clonedesc{'type'} ne 'Community') {
14770: $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'});
14771: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14772: }
14773: }
1.1075.2.119 raeburn 14774: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 14775: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14776: $can_clone = 1;
14777: } else {
1.1075.2.95 raeburn 14778: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 14779: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 14780: if ($clonehash{'cloners'} eq '') {
14781: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
14782: if ($domdefs{'canclone'}) {
14783: unless ($domdefs{'canclone'} eq 'none') {
14784: if ($domdefs{'canclone'} eq 'domain') {
14785: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
14786: $can_clone = 1;
14787: }
14788: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14789: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
14790: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
14791: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
14792: $can_clone = 1;
14793: }
14794: }
14795: }
1.908 raeburn 14796: }
1.1075.2.95 raeburn 14797: } else {
14798: my @cloners = split(/,/,$clonehash{'cloners'});
14799: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 14800: $can_clone = 1;
1.1075.2.95 raeburn 14801: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 14802: $can_clone = 1;
1.1075.2.96 raeburn 14803: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14804: $can_clone = 1;
1.1075.2.95 raeburn 14805: }
14806: unless ($can_clone) {
1.1075.2.96 raeburn 14807: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14808: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 14809: my (%gotdomdefaults,%gotcodedefaults);
14810: foreach my $cloner (@cloners) {
14811: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
14812: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
14813: my (%codedefaults,@code_order);
14814: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
14815: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
14816: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
14817: }
14818: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
14819: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
14820: }
14821: } else {
14822: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
14823: \%codedefaults,
14824: \@code_order);
14825: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
14826: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
14827: }
14828: if (@code_order > 0) {
14829: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
14830: $cloner,$clonehash{'internal.coursecode'},
14831: $args->{'crscode'})) {
14832: $can_clone = 1;
14833: last;
14834: }
14835: }
14836: }
14837: }
14838: }
1.1075.2.96 raeburn 14839: }
14840: }
14841: unless ($can_clone) {
14842: my $ccrole = 'cc';
14843: if ($args->{'crstype'} eq 'Community') {
14844: $ccrole = 'co';
14845: }
14846: my %roleshash =
14847: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14848: $args->{'ccdomain'},
14849: 'userroles',['active'],[$ccrole],
14850: [$args->{'clonedomain'}]);
14851: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
14852: $can_clone = 1;
14853: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
14854: $args->{'ccuname'},$args->{'ccdomain'})) {
14855: $can_clone = 1;
1.1075.2.95 raeburn 14856: }
14857: }
14858: unless ($can_clone) {
14859: if ($args->{'crstype'} eq 'Community') {
14860: $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'});
14861: } else {
14862: $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 14863: }
1.566 albertel 14864: }
1.578 raeburn 14865: }
1.566 albertel 14866: }
14867: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14868: }
14869:
1.444 albertel 14870: sub construct_course {
1.1075.2.119 raeburn 14871: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
14872: $cnum,$category,$coderef) = @_;
1.444 albertel 14873: my $outcome;
1.541 raeburn 14874: my $linefeed = '<br />'."\n";
14875: if ($context eq 'auto') {
14876: $linefeed = "\n";
14877: }
1.566 albertel 14878:
14879: #
14880: # Are we cloning?
14881: #
14882: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14883: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14884: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14885: if ($context ne 'auto') {
1.578 raeburn 14886: if ($clonemsg ne '') {
14887: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14888: }
1.566 albertel 14889: }
14890: $outcome .= $clonemsg.$linefeed;
14891:
14892: if (!$can_clone) {
14893: return (0,$outcome);
14894: }
14895: }
14896:
1.444 albertel 14897: #
14898: # Open course
14899: #
14900: my $crstype = lc($args->{'crstype'});
14901: my %cenv=();
14902: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14903: $args->{'cdescr'},
14904: $args->{'curl'},
14905: $args->{'course_home'},
14906: $args->{'nonstandard'},
14907: $args->{'crscode'},
14908: $args->{'ccuname'}.':'.
14909: $args->{'ccdomain'},
1.882 raeburn 14910: $args->{'crstype'},
1.885 raeburn 14911: $cnum,$context,$category);
1.444 albertel 14912:
14913: # Note: The testing routines depend on this being output; see
14914: # Utils::Course. This needs to at least be output as a comment
14915: # if anyone ever decides to not show this, and Utils::Course::new
14916: # will need to be suitably modified.
1.541 raeburn 14917: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 14918: if ($$courseid =~ /^error:/) {
14919: return (0,$outcome);
14920: }
14921:
1.444 albertel 14922: #
14923: # Check if created correctly
14924: #
1.479 albertel 14925: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14926: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14927: if ($crsuhome eq 'no_host') {
14928: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14929: return (0,$outcome);
14930: }
1.541 raeburn 14931: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14932:
1.444 albertel 14933: #
1.566 albertel 14934: # Do the cloning
14935: #
14936: if ($can_clone && $cloneid) {
14937: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14938: if ($context ne 'auto') {
14939: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14940: }
14941: $outcome .= $clonemsg.$linefeed;
14942: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14943: # Copy all files
1.637 www 14944: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14945: # Restore URL
1.566 albertel 14946: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14947: # Restore title
1.566 albertel 14948: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14949: # Restore creation date, creator and creation context.
14950: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14951: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14952: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14953: # Mark as cloned
1.566 albertel 14954: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14955: # Need to clone grading mode
14956: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14957: $cenv{'grading'}=$newenv{'grading'};
14958: # Do not clone these environment entries
14959: &Apache::lonnet::del('environment',
14960: ['default_enrollment_start_date',
14961: 'default_enrollment_end_date',
14962: 'question.email',
14963: 'policy.email',
14964: 'comment.email',
14965: 'pch.users.denied',
1.725 raeburn 14966: 'plc.users.denied',
14967: 'hidefromcat',
1.1075.2.36 raeburn 14968: 'checkforpriv',
1.1075.2.59 raeburn 14969: 'categories',
14970: 'internal.uniquecode'],
1.638 www 14971: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 14972: if ($args->{'textbook'}) {
14973: $cenv{'internal.textbook'} = $args->{'textbook'};
14974: }
1.444 albertel 14975: }
1.566 albertel 14976:
1.444 albertel 14977: #
14978: # Set environment (will override cloned, if existing)
14979: #
14980: my @sections = ();
14981: my @xlists = ();
14982: if ($args->{'crstype'}) {
14983: $cenv{'type'}=$args->{'crstype'};
14984: }
14985: if ($args->{'crsid'}) {
14986: $cenv{'courseid'}=$args->{'crsid'};
14987: }
14988: if ($args->{'crscode'}) {
14989: $cenv{'internal.coursecode'}=$args->{'crscode'};
14990: }
14991: if ($args->{'crsquota'} ne '') {
14992: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14993: } else {
14994: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14995: }
14996: if ($args->{'ccuname'}) {
14997: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14998: ':'.$args->{'ccdomain'};
14999: } else {
15000: $cenv{'internal.courseowner'} = $args->{'curruser'};
15001: }
1.1075.2.31 raeburn 15002: if ($args->{'defaultcredits'}) {
15003: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15004: }
1.444 albertel 15005: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15006: if ($args->{'crssections'}) {
15007: $cenv{'internal.sectionnums'} = '';
15008: if ($args->{'crssections'} =~ m/,/) {
15009: @sections = split/,/,$args->{'crssections'};
15010: } else {
15011: $sections[0] = $args->{'crssections'};
15012: }
15013: if (@sections > 0) {
15014: foreach my $item (@sections) {
15015: my ($sec,$gp) = split/:/,$item;
15016: my $class = $args->{'crscode'}.$sec;
15017: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15018: $cenv{'internal.sectionnums'} .= $item.',';
15019: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15020: push(@badclasses,$class);
1.444 albertel 15021: }
15022: }
15023: $cenv{'internal.sectionnums'} =~ s/,$//;
15024: }
15025: }
15026: # do not hide course coordinator from staff listing,
15027: # even if privileged
15028: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15029: # add course coordinator's domain to domains to check for privileged users
15030: # if different to course domain
15031: if ($$crsudom ne $args->{'ccdomain'}) {
15032: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15033: }
1.444 albertel 15034: # add crosslistings
15035: if ($args->{'crsxlist'}) {
15036: $cenv{'internal.crosslistings'}='';
15037: if ($args->{'crsxlist'} =~ m/,/) {
15038: @xlists = split/,/,$args->{'crsxlist'};
15039: } else {
15040: $xlists[0] = $args->{'crsxlist'};
15041: }
15042: if (@xlists > 0) {
15043: foreach my $item (@xlists) {
15044: my ($xl,$gp) = split/:/,$item;
15045: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15046: $cenv{'internal.crosslistings'} .= $item.',';
15047: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15048: push(@badclasses,$xl);
1.444 albertel 15049: }
15050: }
15051: $cenv{'internal.crosslistings'} =~ s/,$//;
15052: }
15053: }
15054: if ($args->{'autoadds'}) {
15055: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15056: }
15057: if ($args->{'autodrops'}) {
15058: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15059: }
15060: # check for notification of enrollment changes
15061: my @notified = ();
15062: if ($args->{'notify_owner'}) {
15063: if ($args->{'ccuname'} ne '') {
15064: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15065: }
15066: }
15067: if ($args->{'notify_dc'}) {
15068: if ($uname ne '') {
1.630 raeburn 15069: push(@notified,$uname.':'.$udom);
1.444 albertel 15070: }
15071: }
15072: if (@notified > 0) {
15073: my $notifylist;
15074: if (@notified > 1) {
15075: $notifylist = join(',',@notified);
15076: } else {
15077: $notifylist = $notified[0];
15078: }
15079: $cenv{'internal.notifylist'} = $notifylist;
15080: }
15081: if (@badclasses > 0) {
15082: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15083: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15084: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15085: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15086: );
1.1075.2.119 raeburn 15087: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15088: &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 15089: if ($context eq 'auto') {
15090: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15091: } else {
1.566 albertel 15092: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15093: }
15094: foreach my $item (@badclasses) {
1.541 raeburn 15095: if ($context eq 'auto') {
1.1075.2.119 raeburn 15096: $outcome .= " - $item\n";
1.541 raeburn 15097: } else {
1.1075.2.119 raeburn 15098: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15099: }
1.1075.2.119 raeburn 15100: }
15101: if ($context eq 'auto') {
15102: $outcome .= $linefeed;
15103: } else {
15104: $outcome .= "</ul><br /><br /></div>\n";
15105: }
1.444 albertel 15106: }
15107: if ($args->{'no_end_date'}) {
15108: $args->{'endaccess'} = 0;
15109: }
15110: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15111: $cenv{'internal.autoend'}=$args->{'enrollend'};
15112: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15113: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15114: if ($args->{'showphotos'}) {
15115: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15116: }
15117: $cenv{'internal.authtype'} = $args->{'authtype'};
15118: $cenv{'internal.autharg'} = $args->{'autharg'};
15119: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15120: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15121: 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');
15122: if ($context eq 'auto') {
15123: $outcome .= $krb_msg;
15124: } else {
1.566 albertel 15125: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15126: }
15127: $outcome .= $linefeed;
1.444 albertel 15128: }
15129: }
15130: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15131: if ($args->{'setpolicy'}) {
15132: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15133: }
15134: if ($args->{'setcontent'}) {
15135: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15136: }
1.1075.2.110 raeburn 15137: if ($args->{'setcomment'}) {
15138: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15139: }
1.444 albertel 15140: }
15141: if ($args->{'reshome'}) {
15142: $cenv{'reshome'}=$args->{'reshome'}.'/';
15143: $cenv{'reshome'}=~s/\/+$/\//;
15144: }
15145: #
15146: # course has keyed access
15147: #
15148: if ($args->{'setkeys'}) {
15149: $cenv{'keyaccess'}='yes';
15150: }
15151: # if specified, key authority is not course, but user
15152: # only active if keyaccess is yes
15153: if ($args->{'keyauth'}) {
1.487 albertel 15154: my ($user,$domain) = split(':',$args->{'keyauth'});
15155: $user = &LONCAPA::clean_username($user);
15156: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15157: if ($user ne '' && $domain ne '') {
1.487 albertel 15158: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15159: }
15160: }
15161:
1.1075.2.59 raeburn 15162: #
15163: # generate and store uniquecode (available to course requester), if course should have one.
15164: #
15165: if ($args->{'uniquecode'}) {
15166: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15167: if ($code) {
15168: $cenv{'internal.uniquecode'} = $code;
15169: my %crsinfo =
15170: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15171: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15172: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15173: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15174: }
15175: if (ref($coderef)) {
15176: $$coderef = $code;
15177: }
15178: }
15179: }
15180:
1.444 albertel 15181: if ($args->{'disresdis'}) {
15182: $cenv{'pch.roles.denied'}='st';
15183: }
15184: if ($args->{'disablechat'}) {
15185: $cenv{'plc.roles.denied'}='st';
15186: }
15187:
15188: # Record we've not yet viewed the Course Initialization Helper for this
15189: # course
15190: $cenv{'course.helper.not.run'} = 1;
15191: #
15192: # Use new Randomseed
15193: #
15194: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15195: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15196: #
15197: # The encryption code and receipt prefix for this course
15198: #
15199: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15200: $cenv{'internal.encpref'}=100+int(9*rand(99));
15201: #
15202: # By default, use standard grading
15203: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15204:
1.541 raeburn 15205: $outcome .= $linefeed.&mt('Setting environment').': '.
15206: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15207: #
15208: # Open all assignments
15209: #
15210: if ($args->{'openall'}) {
15211: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15212: my %storecontent = ($storeunder => time,
15213: $storeunder.'.type' => 'date_start');
15214:
15215: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15216: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15217: }
15218: #
15219: # Set first page
15220: #
15221: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15222: || ($cloneid)) {
1.445 albertel 15223: use LONCAPA::map;
1.444 albertel 15224: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15225:
15226: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15227: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15228:
1.444 albertel 15229: $outcome .= ($fatal?$errtext:'read ok').' - ';
15230: my $title; my $url;
15231: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15232: $title=&mt('Syllabus');
1.444 albertel 15233: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15234: } else {
1.963 raeburn 15235: $title=&mt('Table of Contents');
1.444 albertel 15236: $url='/adm/navmaps';
15237: }
1.445 albertel 15238:
15239: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15240: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15241:
15242: if ($errtext) { $fatal=2; }
1.541 raeburn 15243: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15244: }
1.566 albertel 15245:
15246: return (1,$outcome);
1.444 albertel 15247: }
15248:
1.1075.2.59 raeburn 15249: sub make_unique_code {
15250: my ($cdom,$cnum) = @_;
15251: # get lock on uniquecodes db
15252: my $lockhash = {
15253: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15254: ':'.$env{'user.domain'},
15255: };
15256: my $tries = 0;
15257: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15258: my ($code,$error);
15259:
15260: while (($gotlock ne 'ok') && ($tries<3)) {
15261: $tries ++;
15262: sleep 1;
15263: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15264: }
15265: if ($gotlock eq 'ok') {
15266: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15267: my $gotcode;
15268: my $attempts = 0;
15269: while ((!$gotcode) && ($attempts < 100)) {
15270: $code = &generate_code();
15271: if (!exists($currcodes{$code})) {
15272: $gotcode = 1;
15273: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15274: $error = 'nostore';
15275: }
15276: }
15277: $attempts ++;
15278: }
15279: my @del_lock = ($cnum."\0".'uniquecodes');
15280: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15281: } else {
15282: $error = 'nolock';
15283: }
15284: return ($code,$error);
15285: }
15286:
15287: sub generate_code {
15288: my $code;
15289: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15290: for (my $i=0; $i<6; $i++) {
15291: my $lettnum = int (rand 2);
15292: my $item = '';
15293: if ($lettnum) {
15294: $item = $letts[int( rand(18) )];
15295: } else {
15296: $item = 1+int( rand(8) );
15297: }
15298: $code .= $item;
15299: }
15300: return $code;
15301: }
15302:
1.444 albertel 15303: ############################################################
15304: ############################################################
15305:
1.953 droeschl 15306: #SD
15307: # only Community and Course, or anything else?
1.378 raeburn 15308: sub course_type {
15309: my ($cid) = @_;
15310: if (!defined($cid)) {
15311: $cid = $env{'request.course.id'};
15312: }
1.404 albertel 15313: if (defined($env{'course.'.$cid.'.type'})) {
15314: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15315: } else {
15316: return 'Course';
1.377 raeburn 15317: }
15318: }
1.156 albertel 15319:
1.406 raeburn 15320: sub group_term {
15321: my $crstype = &course_type();
15322: my %names = (
15323: 'Course' => 'group',
1.865 raeburn 15324: 'Community' => 'group',
1.406 raeburn 15325: );
15326: return $names{$crstype};
15327: }
15328:
1.902 raeburn 15329: sub course_types {
1.1075.2.59 raeburn 15330: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15331: my %typename = (
15332: official => 'Official course',
15333: unofficial => 'Unofficial course',
15334: community => 'Community',
1.1075.2.59 raeburn 15335: textbook => 'Textbook course',
1.902 raeburn 15336: );
15337: return (\@types,\%typename);
15338: }
15339:
1.156 albertel 15340: sub icon {
15341: my ($file)=@_;
1.505 albertel 15342: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15343: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15344: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15345: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15346: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15347: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15348: $curfext.".gif") {
15349: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15350: $curfext.".gif";
15351: }
15352: }
1.249 albertel 15353: return &lonhttpdurl($iconname);
1.154 albertel 15354: }
1.84 albertel 15355:
1.575 albertel 15356: sub lonhttpdurl {
1.692 www 15357: #
15358: # Had been used for "small fry" static images on separate port 8080.
15359: # Modify here if lightweight http functionality desired again.
15360: # Currently eliminated due to increasing firewall issues.
15361: #
1.575 albertel 15362: my ($url)=@_;
1.692 www 15363: return $url;
1.215 albertel 15364: }
15365:
1.213 albertel 15366: sub connection_aborted {
15367: my ($r)=@_;
15368: $r->print(" ");$r->rflush();
15369: my $c = $r->connection;
15370: return $c->aborted();
15371: }
15372:
1.221 foxr 15373: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15374: # strings as 'strings'.
15375: sub escape_single {
1.221 foxr 15376: my ($input) = @_;
1.223 albertel 15377: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15378: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15379: return $input;
15380: }
1.223 albertel 15381:
1.222 foxr 15382: # Same as escape_single, but escape's "'s This
15383: # can be used for "strings"
15384: sub escape_double {
15385: my ($input) = @_;
15386: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15387: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15388: return $input;
15389: }
1.223 albertel 15390:
1.222 foxr 15391: # Escapes the last element of a full URL.
15392: sub escape_url {
15393: my ($url) = @_;
1.238 raeburn 15394: my @urlslices = split(/\//, $url,-1);
1.369 www 15395: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15396: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15397: }
1.462 albertel 15398:
1.820 raeburn 15399: sub compare_arrays {
15400: my ($arrayref1,$arrayref2) = @_;
15401: my (@difference,%count);
15402: @difference = ();
15403: %count = ();
15404: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15405: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15406: foreach my $element (keys(%count)) {
15407: if ($count{$element} == 1) {
15408: push(@difference,$element);
15409: }
15410: }
15411: }
15412: return @difference;
15413: }
15414:
1.817 bisitz 15415: # -------------------------------------------------------- Initialize user login
1.462 albertel 15416: sub init_user_environment {
1.463 albertel 15417: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15418: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15419:
15420: my $public=($username eq 'public' && $domain eq 'public');
15421:
15422: # See if old ID present, if so, remove
15423:
1.1062 raeburn 15424: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15425: my $now=time;
15426:
15427: if ($public) {
15428: my $max_public=100;
15429: my $oldest;
15430: my $oldest_time=0;
15431: for(my $next=1;$next<=$max_public;$next++) {
15432: if (-e $lonids."/publicuser_$next.id") {
15433: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15434: if ($mtime<$oldest_time || !$oldest_time) {
15435: $oldest_time=$mtime;
15436: $oldest=$next;
15437: }
15438: } else {
15439: $cookie="publicuser_$next";
15440: last;
15441: }
15442: }
15443: if (!$cookie) { $cookie="publicuser_$oldest"; }
15444: } else {
1.463 albertel 15445: # if this isn't a robot, kill any existing non-robot sessions
15446: if (!$args->{'robot'}) {
15447: opendir(DIR,$lonids);
15448: while ($filename=readdir(DIR)) {
15449: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
15450: unlink($lonids.'/'.$filename);
15451: }
1.462 albertel 15452: }
1.463 albertel 15453: closedir(DIR);
1.1075.2.84 raeburn 15454: # If there is a undeleted lockfile for the user's paste buffer remove it.
15455: my $namespace = 'nohist_courseeditor';
15456: my $lockingkey = 'paste'."\0".'locked_num';
15457: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15458: $domain,$username);
15459: if (exists($lockhash{$lockingkey})) {
15460: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15461: unless ($delresult eq 'ok') {
15462: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15463: }
15464: }
1.462 albertel 15465: }
15466: # Give them a new cookie
1.463 albertel 15467: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15468: : $now.$$.int(rand(10000)));
1.463 albertel 15469: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15470:
15471: # Initialize roles
15472:
1.1062 raeburn 15473: ($userroles,$firstaccenv,$timerintenv) =
15474: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15475: }
15476: # ------------------------------------ Check browser type and MathML capability
15477:
1.1075.2.77 raeburn 15478: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15479: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15480:
15481: # ------------------------------------------------------------- Get environment
15482:
15483: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15484: my ($tmp) = keys(%userenv);
15485: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15486: } else {
15487: undef(%userenv);
15488: }
15489: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15490: $form->{'interface'}=$userenv{'interface'};
15491: }
15492: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15493:
15494: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15495: foreach my $option ('interface','localpath','localres') {
15496: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15497: }
15498: # --------------------------------------------------------- Write first profile
15499:
15500: {
15501: my %initial_env =
15502: ("user.name" => $username,
15503: "user.domain" => $domain,
15504: "user.home" => $authhost,
15505: "browser.type" => $clientbrowser,
15506: "browser.version" => $clientversion,
15507: "browser.mathml" => $clientmathml,
15508: "browser.unicode" => $clientunicode,
15509: "browser.os" => $clientos,
1.1075.2.42 raeburn 15510: "browser.mobile" => $clientmobile,
15511: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 15512: "browser.osversion" => $clientosversion,
1.462 albertel 15513: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15514: "request.course.fn" => '',
15515: "request.course.uri" => '',
15516: "request.course.sec" => '',
15517: "request.role" => 'cm',
15518: "request.role.adv" => $env{'user.adv'},
15519: "request.host" => $ENV{'REMOTE_ADDR'},);
15520:
15521: if ($form->{'localpath'}) {
15522: $initial_env{"browser.localpath"} = $form->{'localpath'};
15523: $initial_env{"browser.localres"} = $form->{'localres'};
15524: }
15525:
15526: if ($form->{'interface'}) {
15527: $form->{'interface'}=~s/\W//gs;
15528: $initial_env{"browser.interface"} = $form->{'interface'};
15529: $env{'browser.interface'}=$form->{'interface'};
15530: }
15531:
1.1075.2.54 raeburn 15532: if ($form->{'iptoken'}) {
15533: my $lonhost = $r->dir_config('lonHostID');
15534: $initial_env{"user.noloadbalance"} = $lonhost;
15535: $env{'user.noloadbalance'} = $lonhost;
15536: }
15537:
1.1075.2.120 raeburn 15538: if ($form->{'noloadbalance'}) {
15539: my @hosts = &Apache::lonnet::current_machine_ids();
15540: my $hosthere = $form->{'noloadbalance'};
15541: if (grep(/^\Q$hosthere\E$/,@hosts)) {
15542: $initial_env{"user.noloadbalance"} = $hosthere;
15543: $env{'user.noloadbalance'} = $hosthere;
15544: }
15545: }
15546:
1.1016 raeburn 15547: unless ($domain eq 'public') {
1.1075.2.125 raeburn 15548: my %is_adv = ( is_adv => $env{'user.adv'} );
15549: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 15550:
1.1075.2.125 raeburn 15551: foreach my $tool ('aboutme','blog','webdav','portfolio') {
15552: $userenv{'availabletools.'.$tool} =
15553: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15554: undef,\%userenv,\%domdef,\%is_adv);
15555: }
1.724 raeburn 15556:
1.1075.2.125 raeburn 15557: foreach my $crstype ('official','unofficial','community','textbook') {
15558: $userenv{'canrequest.'.$crstype} =
15559: &Apache::lonnet::usertools_access($username,$domain,$crstype,
15560: 'reload','requestcourses',
15561: \%userenv,\%domdef,\%is_adv);
15562: }
1.765 raeburn 15563:
1.1075.2.125 raeburn 15564: $userenv{'canrequest.author'} =
15565: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15566: 'reload','requestauthor',
15567: \%userenv,\%domdef,\%is_adv);
15568: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15569: $domain,$username);
15570: my $reqstatus = $reqauthor{'author_status'};
15571: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15572: if (ref($reqauthor{'author'}) eq 'HASH') {
15573: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15574: $reqauthor{'author'}{'timestamp'};
15575: }
1.1075.2.14 raeburn 15576: }
15577: }
15578:
1.462 albertel 15579: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15580:
1.462 albertel 15581: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15582: &GDBM_WRCREAT(),0640)) {
15583: &_add_to_env(\%disk_env,\%initial_env);
15584: &_add_to_env(\%disk_env,\%userenv,'environment.');
15585: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15586: if (ref($firstaccenv) eq 'HASH') {
15587: &_add_to_env(\%disk_env,$firstaccenv);
15588: }
15589: if (ref($timerintenv) eq 'HASH') {
15590: &_add_to_env(\%disk_env,$timerintenv);
15591: }
1.463 albertel 15592: if (ref($args->{'extra_env'})) {
15593: &_add_to_env(\%disk_env,$args->{'extra_env'});
15594: }
1.462 albertel 15595: untie(%disk_env);
15596: } else {
1.705 tempelho 15597: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15598: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15599: return 'error: '.$!;
15600: }
15601: }
15602: $env{'request.role'}='cm';
15603: $env{'request.role.adv'}=$env{'user.adv'};
15604: $env{'browser.type'}=$clientbrowser;
15605:
15606: return $cookie;
15607:
15608: }
15609:
15610: sub _add_to_env {
15611: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15612: if (ref($env_data) eq 'HASH') {
15613: while (my ($key,$value) = each(%$env_data)) {
15614: $idf->{$prefix.$key} = $value;
15615: $env{$prefix.$key} = $value;
15616: }
1.462 albertel 15617: }
15618: }
15619:
1.685 tempelho 15620: # --- Get the symbolic name of a problem and the url
15621: sub get_symb {
15622: my ($request,$silent) = @_;
1.726 raeburn 15623: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15624: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15625: if ($symb eq '') {
15626: if (!$silent) {
1.1071 raeburn 15627: if (ref($request)) {
15628: $request->print("Unable to handle ambiguous references:$url:.");
15629: }
1.685 tempelho 15630: return ();
15631: }
15632: }
15633: &Apache::lonenc::check_decrypt(\$symb);
15634: return ($symb);
15635: }
15636:
15637: # --------------------------------------------------------------Get annotation
15638:
15639: sub get_annotation {
15640: my ($symb,$enc) = @_;
15641:
15642: my $key = $symb;
15643: if (!$enc) {
15644: $key =
15645: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15646: }
15647: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15648: return $annotation{$key};
15649: }
15650:
15651: sub clean_symb {
1.731 raeburn 15652: my ($symb,$delete_enc) = @_;
1.685 tempelho 15653:
15654: &Apache::lonenc::check_decrypt(\$symb);
15655: my $enc = $env{'request.enc'};
1.731 raeburn 15656: if ($delete_enc) {
1.730 raeburn 15657: delete($env{'request.enc'});
15658: }
1.685 tempelho 15659:
15660: return ($symb,$enc);
15661: }
1.462 albertel 15662:
1.1075.2.69 raeburn 15663: ############################################################
15664: ############################################################
15665:
15666: =pod
15667:
15668: =head1 Routines for building display used to search for courses
15669:
15670:
15671: =over 4
15672:
15673: =item * &build_filters()
15674:
15675: Create markup for a table used to set filters to use when selecting
15676: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15677: and quotacheck.pl
15678:
15679:
15680: Inputs:
15681:
15682: filterlist - anonymous array of fields to include as potential filters
15683:
15684: crstype - course type
15685:
15686: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15687: to pop-open a course selector (will contain "extra element").
15688:
15689: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15690:
15691: filter - anonymous hash of criteria and their values
15692:
15693: action - form action
15694:
15695: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15696:
15697: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
15698:
15699: cloneruname - username of owner of new course who wants to clone
15700:
15701: clonerudom - domain of owner of new course who wants to clone
15702:
15703: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15704:
15705: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15706:
15707: codedom - domain
15708:
15709: formname - value of form element named "form".
15710:
15711: fixeddom - domain, if fixed.
15712:
15713: prevphase - value to assign to form element named "phase" when going back to the previous screen
15714:
15715: cnameelement - name of form element in form on opener page which will receive title of selected course
15716:
15717: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15718:
15719: cdomelement - name of form element in form on opener page which will receive domain of selected course
15720:
15721: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15722:
15723: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15724:
15725: clonewarning - warning message about missing information for intended course owner when DC creates a course
15726:
15727:
15728: Returns: $output - HTML for display of search criteria, and hidden form elements.
15729:
15730:
15731: Side Effects: None
15732:
15733: =cut
15734:
15735: # ---------------------------------------------- search for courses based on last activity etc.
15736:
15737: sub build_filters {
15738: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15739: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15740: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15741: $cnameelement,$cnumelement,$cdomelement,$setroles,
15742: $clonetext,$clonewarning) = @_;
15743: my ($list,$jscript);
15744: my $onchange = 'javascript:updateFilters(this)';
15745: my ($domainselectform,$sincefilterform,$createdfilterform,
15746: $ownerdomselectform,$persondomselectform,$instcodeform,
15747: $typeselectform,$instcodetitle);
15748: if ($formname eq '') {
15749: $formname = $caller;
15750: }
15751: foreach my $item (@{$filterlist}) {
15752: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15753: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15754: if ($item eq 'domainfilter') {
15755: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15756: } elsif ($item eq 'coursefilter') {
15757: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15758: } elsif ($item eq 'ownerfilter') {
15759: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15760: } elsif ($item eq 'ownerdomfilter') {
15761: $filter->{'ownerdomfilter'} =
15762: &LONCAPA::clean_domain($filter->{$item});
15763: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15764: 'ownerdomfilter',1);
15765: } elsif ($item eq 'personfilter') {
15766: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15767: } elsif ($item eq 'persondomfilter') {
15768: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15769: 'persondomfilter',1);
15770: } else {
15771: $filter->{$item} =~ s/\W//g;
15772: }
15773: if (!$filter->{$item}) {
15774: $filter->{$item} = '';
15775: }
15776: }
15777: if ($item eq 'domainfilter') {
15778: my $allow_blank = 1;
15779: if ($formname eq 'portform') {
15780: $allow_blank=0;
15781: } elsif ($formname eq 'studentform') {
15782: $allow_blank=0;
15783: }
15784: if ($fixeddom) {
15785: $domainselectform = '<input type="hidden" name="domainfilter"'.
15786: ' value="'.$codedom.'" />'.
15787: &Apache::lonnet::domain($codedom,'description');
15788: } else {
15789: $domainselectform = &select_dom_form($filter->{$item},
15790: 'domainfilter',
15791: $allow_blank,'',$onchange);
15792: }
15793: } else {
15794: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15795: }
15796: }
15797:
15798: # last course activity filter and selection
15799: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15800:
15801: # course created filter and selection
15802: if (exists($filter->{'createdfilter'})) {
15803: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15804: }
15805:
15806: my %lt = &Apache::lonlocal::texthash(
15807: 'cac' => "$crstype Activity",
15808: 'ccr' => "$crstype Created",
15809: 'cde' => "$crstype Title",
15810: 'cdo' => "$crstype Domain",
15811: 'ins' => 'Institutional Code',
15812: 'inc' => 'Institutional Categorization',
15813: 'cow' => "$crstype Owner/Co-owner",
15814: 'cop' => "$crstype Personnel Includes",
15815: 'cog' => 'Type',
15816: );
15817:
15818: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15819: my $typeval = 'Course';
15820: if ($crstype eq 'Community') {
15821: $typeval = 'Community';
15822: }
15823: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15824: } else {
15825: $typeselectform = '<select name="type" size="1"';
15826: if ($onchange) {
15827: $typeselectform .= ' onchange="'.$onchange.'"';
15828: }
15829: $typeselectform .= '>'."\n";
15830: foreach my $posstype ('Course','Community') {
15831: $typeselectform.='<option value="'.$posstype.'"'.
15832: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
15833: }
15834: $typeselectform.="</select>";
15835: }
15836:
15837: my ($cloneableonlyform,$cloneabletitle);
15838: if (exists($filter->{'cloneableonly'})) {
15839: my $cloneableon = '';
15840: my $cloneableoff = ' checked="checked"';
15841: if ($filter->{'cloneableonly'}) {
15842: $cloneableon = $cloneableoff;
15843: $cloneableoff = '';
15844: }
15845: $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>';
15846: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 15847: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 15848: } else {
15849: $cloneabletitle = &mt('Cloneable by you');
15850: }
15851: }
15852: my $officialjs;
15853: if ($crstype eq 'Course') {
15854: if (exists($filter->{'instcodefilter'})) {
15855: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15856: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15857: if ($codedom) {
15858: $officialjs = 1;
15859: ($instcodeform,$jscript,$$numtitlesref) =
15860: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15861: $officialjs,$codetitlesref);
15862: if ($jscript) {
15863: $jscript = '<script type="text/javascript">'."\n".
15864: '// <![CDATA['."\n".
15865: $jscript."\n".
15866: '// ]]>'."\n".
15867: '</script>'."\n";
15868: }
15869: }
15870: if ($instcodeform eq '') {
15871: $instcodeform =
15872: '<input type="text" name="instcodefilter" size="10" value="'.
15873: $list->{'instcodefilter'}.'" />';
15874: $instcodetitle = $lt{'ins'};
15875: } else {
15876: $instcodetitle = $lt{'inc'};
15877: }
15878: if ($fixeddom) {
15879: $instcodetitle .= '<br />('.$codedom.')';
15880: }
15881: }
15882: }
15883: my $output = qq|
15884: <form method="post" name="filterpicker" action="$action">
15885: <input type="hidden" name="form" value="$formname" />
15886: |;
15887: if ($formname eq 'modifycourse') {
15888: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15889: '<input type="hidden" name="prevphase" value="'.
15890: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 15891: } elsif ($formname eq 'quotacheck') {
15892: $output .= qq|
15893: <input type="hidden" name="sortby" value="" />
15894: <input type="hidden" name="sortorder" value="" />
15895: |;
15896: } else {
1.1075.2.69 raeburn 15897: my $name_input;
15898: if ($cnameelement ne '') {
15899: $name_input = '<input type="hidden" name="cnameelement" value="'.
15900: $cnameelement.'" />';
15901: }
15902: $output .= qq|
15903: <input type="hidden" name="cnumelement" value="$cnumelement" />
15904: <input type="hidden" name="cdomelement" value="$cdomelement" />
15905: $name_input
15906: $roleelement
15907: $multelement
15908: $typeelement
15909: |;
15910: if ($formname eq 'portform') {
15911: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
15912: }
15913: }
15914: if ($fixeddom) {
15915: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
15916: }
15917: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
15918: if ($sincefilterform) {
15919: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
15920: .$sincefilterform
15921: .&Apache::lonhtmlcommon::row_closure();
15922: }
15923: if ($createdfilterform) {
15924: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
15925: .$createdfilterform
15926: .&Apache::lonhtmlcommon::row_closure();
15927: }
15928: if ($domainselectform) {
15929: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
15930: .$domainselectform
15931: .&Apache::lonhtmlcommon::row_closure();
15932: }
15933: if ($typeselectform) {
15934: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15935: $output .= $typeselectform;
15936: } else {
15937: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
15938: .$typeselectform
15939: .&Apache::lonhtmlcommon::row_closure();
15940: }
15941: }
15942: if ($instcodeform) {
15943: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
15944: .$instcodeform
15945: .&Apache::lonhtmlcommon::row_closure();
15946: }
15947: if (exists($filter->{'ownerfilter'})) {
15948: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15949: '<table><tr><td>'.&mt('Username').'<br />'.
15950: '<input type="text" name="ownerfilter" size="20" value="'.
15951: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15952: $ownerdomselectform.'</td></tr></table>'.
15953: &Apache::lonhtmlcommon::row_closure();
15954: }
15955: if (exists($filter->{'personfilter'})) {
15956: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15957: '<table><tr><td>'.&mt('Username').'<br />'.
15958: '<input type="text" name="personfilter" size="20" value="'.
15959: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15960: $persondomselectform.'</td></tr></table>'.
15961: &Apache::lonhtmlcommon::row_closure();
15962: }
15963: if (exists($filter->{'coursefilter'})) {
15964: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15965: .'<input type="text" name="coursefilter" size="25" value="'
15966: .$list->{'coursefilter'}.'" />'
15967: .&Apache::lonhtmlcommon::row_closure();
15968: }
15969: if ($cloneableonlyform) {
15970: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15971: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15972: }
15973: if (exists($filter->{'descriptfilter'})) {
15974: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15975: .'<input type="text" name="descriptfilter" size="40" value="'
15976: .$list->{'descriptfilter'}.'" />'
15977: .&Apache::lonhtmlcommon::row_closure(1);
15978: }
15979: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15980: '<input type="hidden" name="updater" value="" />'."\n".
15981: '<input type="submit" name="gosearch" value="'.
15982: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15983: return $jscript.$clonewarning.$output;
15984: }
15985:
15986: =pod
15987:
15988: =item * &timebased_select_form()
15989:
15990: Create markup for a dropdown list used to select a time-based
15991: filter e.g., Course Activity, Course Created, when searching for courses
15992: or communities
15993:
15994: Inputs:
15995:
15996: item - name of form element (sincefilter or createdfilter)
15997:
15998: filter - anonymous hash of criteria and their values
15999:
16000: Returns: HTML for a select box contained a blank, then six time selections,
16001: with value set in incoming form variables currently selected.
16002:
16003: Side Effects: None
16004:
16005: =cut
16006:
16007: sub timebased_select_form {
16008: my ($item,$filter) = @_;
16009: if (ref($filter) eq 'HASH') {
16010: $filter->{$item} =~ s/[^\d-]//g;
16011: if (!$filter->{$item}) { $filter->{$item}=-1; }
16012: return &select_form(
16013: $filter->{$item},
16014: $item,
16015: { '-1' => '',
16016: '86400' => &mt('today'),
16017: '604800' => &mt('last week'),
16018: '2592000' => &mt('last month'),
16019: '7776000' => &mt('last three months'),
16020: '15552000' => &mt('last six months'),
16021: '31104000' => &mt('last year'),
16022: 'select_form_order' =>
16023: ['-1','86400','604800','2592000','7776000',
16024: '15552000','31104000']});
16025: }
16026: }
16027:
16028: =pod
16029:
16030: =item * &js_changer()
16031:
16032: Create script tag containing Javascript used to submit course search form
16033: when course type or domain is changed, and also to hide 'Searching ...' on
16034: page load completion for page showing search result.
16035:
16036: Inputs: None
16037:
16038: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16039:
16040: Side Effects: None
16041:
16042: =cut
16043:
16044: sub js_changer {
16045: return <<ENDJS;
16046: <script type="text/javascript">
16047: // <![CDATA[
16048: function updateFilters(caller) {
16049: if (typeof(caller) != "undefined") {
16050: document.filterpicker.updater.value = caller.name;
16051: }
16052: document.filterpicker.submit();
16053: }
16054:
16055: function hideSearching() {
16056: if (document.getElementById('searching')) {
16057: document.getElementById('searching').style.display = 'none';
16058: }
16059: return;
16060: }
16061:
16062: // ]]>
16063: </script>
16064:
16065: ENDJS
16066: }
16067:
16068: =pod
16069:
16070: =item * &search_courses()
16071:
16072: Process selected filters form course search form and pass to lonnet::courseiddump
16073: to retrieve a hash for which keys are courseIDs which match the selected filters.
16074:
16075: Inputs:
16076:
16077: dom - domain being searched
16078:
16079: type - course type ('Course' or 'Community' or '.' if any).
16080:
16081: filter - anonymous hash of criteria and their values
16082:
16083: numtitles - for institutional codes - number of categories
16084:
16085: cloneruname - optional username of new course owner
16086:
16087: clonerudom - optional domain of new course owner
16088:
1.1075.2.95 raeburn 16089: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16090: (used when DC is using course creation form)
16091:
16092: codetitles - reference to array of titles of components in institutional codes (official courses).
16093:
1.1075.2.95 raeburn 16094: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16095: (and so can clone automatically)
16096:
16097: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16098:
16099: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16100: courses to clone
1.1075.2.69 raeburn 16101:
16102: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16103:
16104:
16105: Side Effects: None
16106:
16107: =cut
16108:
16109:
16110: sub search_courses {
1.1075.2.95 raeburn 16111: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16112: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16113: my (%courses,%showcourses,$cloner);
16114: if (($filter->{'ownerfilter'} ne '') ||
16115: ($filter->{'ownerdomfilter'} ne '')) {
16116: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16117: $filter->{'ownerdomfilter'};
16118: }
16119: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16120: if (!$filter->{$item}) {
16121: $filter->{$item}='.';
16122: }
16123: }
16124: my $now = time;
16125: my $timefilter =
16126: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16127: my ($createdbefore,$createdafter);
16128: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16129: $createdbefore = $now;
16130: $createdafter = $now-$filter->{'createdfilter'};
16131: }
16132: my ($instcodefilter,$regexpok);
16133: if ($numtitles) {
16134: if ($env{'form.official'} eq 'on') {
16135: $instcodefilter =
16136: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16137: $regexpok = 1;
16138: } elsif ($env{'form.official'} eq 'off') {
16139: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16140: unless ($instcodefilter eq '') {
16141: $regexpok = -1;
16142: }
16143: }
16144: } else {
16145: $instcodefilter = $filter->{'instcodefilter'};
16146: }
16147: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16148: if ($type eq '') { $type = '.'; }
16149:
16150: if (($clonerudom ne '') && ($cloneruname ne '')) {
16151: $cloner = $cloneruname.':'.$clonerudom;
16152: }
16153: %courses = &Apache::lonnet::courseiddump($dom,
16154: $filter->{'descriptfilter'},
16155: $timefilter,
16156: $instcodefilter,
16157: $filter->{'combownerfilter'},
16158: $filter->{'coursefilter'},
16159: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16160: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16161: $filter->{'cloneableonly'},
16162: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16163: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16164: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16165: my $ccrole;
16166: if ($type eq 'Community') {
16167: $ccrole = 'co';
16168: } else {
16169: $ccrole = 'cc';
16170: }
16171: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16172: $filter->{'persondomfilter'},
16173: 'userroles',undef,
16174: [$ccrole,'in','ad','ep','ta','cr'],
16175: $dom);
16176: foreach my $role (keys(%rolehash)) {
16177: my ($cnum,$cdom,$courserole) = split(':',$role);
16178: my $cid = $cdom.'_'.$cnum;
16179: if (exists($courses{$cid})) {
16180: if (ref($courses{$cid}) eq 'HASH') {
16181: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16182: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16183: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16184: }
16185: } else {
16186: $courses{$cid}{roles} = [$courserole];
16187: }
16188: $showcourses{$cid} = $courses{$cid};
16189: }
16190: }
16191: }
16192: %courses = %showcourses;
16193: }
16194: return %courses;
16195: }
16196:
16197: =pod
16198:
16199: =back
16200:
1.1075.2.88 raeburn 16201: =head1 Routines for version requirements for current course.
16202:
16203: =over 4
16204:
16205: =item * &check_release_required()
16206:
16207: Compares required LON-CAPA version with version on server, and
16208: if required version is newer looks for a server with the required version.
16209:
16210: Looks first at servers in user's owen domain; if none suitable, looks at
16211: servers in course's domain are permitted to host sessions for user's domain.
16212:
16213: Inputs:
16214:
16215: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16216:
16217: $courseid - Course ID of current course
16218:
16219: $rolecode - User's current role in course (for switchserver query string).
16220:
16221: $required - LON-CAPA version needed by course (format: Major.Minor).
16222:
16223:
16224: Returns:
16225:
16226: $switchserver - query string tp append to /adm/switchserver call (if
16227: current server's LON-CAPA version is too old.
16228:
16229: $warning - Message is displayed if no suitable server could be found.
16230:
16231: =cut
16232:
16233: sub check_release_required {
16234: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16235: my ($switchserver,$warning);
16236: if ($required ne '') {
16237: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16238: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16239: if ($reqdmajor ne '' && $reqdminor ne '') {
16240: my $otherserver;
16241: if (($major eq '' && $minor eq '') ||
16242: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16243: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16244: my $switchlcrev =
16245: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16246: $userdomserver);
16247: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16248: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16249: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16250: my $cdom = $env{'course.'.$courseid.'.domain'};
16251: if ($cdom ne $env{'user.domain'}) {
16252: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16253: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16254: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16255: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16256: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16257: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16258: my $canhost =
16259: &Apache::lonnet::can_host_session($env{'user.domain'},
16260: $coursedomserver,
16261: $remoterev,
16262: $udomdefaults{'remotesessions'},
16263: $defdomdefaults{'hostedsessions'});
16264:
16265: if ($canhost) {
16266: $otherserver = $coursedomserver;
16267: } else {
16268: $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.");
16269: }
16270: } else {
16271: $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).");
16272: }
16273: } else {
16274: $otherserver = $userdomserver;
16275: }
16276: }
16277: if ($otherserver ne '') {
16278: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16279: }
16280: }
16281: }
16282: return ($switchserver,$warning);
16283: }
16284:
16285: =pod
16286:
16287: =item * &check_release_result()
16288:
16289: Inputs:
16290:
16291: $switchwarning - Warning message if no suitable server found to host session.
16292:
16293: $switchserver - query string to append to /adm/switchserver containing lonHostID
16294: and current role.
16295:
16296: Returns: HTML to display with information about requirement to switch server.
16297: Either displaying warning with link to Roles/Courses screen or
16298: display link to switchserver.
16299:
1.1075.2.69 raeburn 16300: =cut
16301:
1.1075.2.88 raeburn 16302: sub check_release_result {
16303: my ($switchwarning,$switchserver) = @_;
16304: my $output = &start_page('Selected course unavailable on this server').
16305: '<p class="LC_warning">';
16306: if ($switchwarning) {
16307: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16308: if (&show_course()) {
16309: $output .= &mt('Display courses');
16310: } else {
16311: $output .= &mt('Display roles');
16312: }
16313: $output .= '</a>';
16314: } elsif ($switchserver) {
16315: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16316: '<br />'.
16317: '<a href="/adm/switchserver?'.$switchserver.'">'.
16318: &mt('Switch Server').
16319: '</a>';
16320: }
16321: $output .= '</p>'.&end_page();
16322: return $output;
16323: }
16324:
16325: =pod
16326:
16327: =item * &needs_coursereinit()
16328:
16329: Determine if course contents stored for user's session needs to be
16330: refreshed, because content has changed since "Big Hash" last tied.
16331:
16332: Check for change is made if time last checked is more than 10 minutes ago
16333: (by default).
16334:
16335: Inputs:
16336:
16337: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16338:
16339: $interval (optional) - Time which may elapse (in s) between last check for content
16340: change in current course. (default: 600 s).
16341:
16342: Returns: an array; first element is:
16343:
16344: =over 4
16345:
16346: 'switch' - if content updates mean user's session
16347: needs to be switched to a server running a newer LON-CAPA version
16348:
16349: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16350: on current server hosting user's session
16351:
16352: '' - if no action required.
16353:
16354: =back
16355:
16356: If first item element is 'switch':
16357:
16358: second item is $switchwarning - Warning message if no suitable server found to host session.
16359:
16360: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16361: and current role.
16362:
16363: otherwise: no other elements returned.
16364:
16365: =back
16366:
16367: =cut
16368:
16369: sub needs_coursereinit {
16370: my ($loncaparev,$interval) = @_;
16371: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16372: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16373: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16374: my $now = time;
16375: if ($interval eq '') {
16376: $interval = 600;
16377: }
16378: if (($now-$env{'request.course.timechecked'})>$interval) {
16379: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16380: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16381: if ($lastchange > $env{'request.course.tied'}) {
16382: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16383: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16384: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16385: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16386: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16387: $curr_reqd_hash{'internal.releaserequired'}});
16388: my ($switchserver,$switchwarning) =
16389: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16390: $curr_reqd_hash{'internal.releaserequired'});
16391: if ($switchwarning ne '' || $switchserver ne '') {
16392: return ('switch',$switchwarning,$switchserver);
16393: }
16394: }
16395: }
16396: return ('update');
16397: }
16398: }
16399: return ();
16400: }
1.1075.2.69 raeburn 16401:
1.1075.2.11 raeburn 16402: sub update_content_constraints {
16403: my ($cdom,$cnum,$chome,$cid) = @_;
16404: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16405: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16406: my %checkresponsetypes;
16407: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16408: my ($item,$name,$value) = split(/:/,$key);
16409: if ($item eq 'resourcetag') {
16410: if ($name eq 'responsetype') {
16411: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16412: }
16413: }
16414: }
16415: my $navmap = Apache::lonnavmaps::navmap->new();
16416: if (defined($navmap)) {
16417: my %allresponses;
16418: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16419: my %responses = $res->responseTypes();
16420: foreach my $key (keys(%responses)) {
16421: next unless(exists($checkresponsetypes{$key}));
16422: $allresponses{$key} += $responses{$key};
16423: }
16424: }
16425: foreach my $key (keys(%allresponses)) {
16426: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16427: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16428: ($reqdmajor,$reqdminor) = ($major,$minor);
16429: }
16430: }
16431: undef($navmap);
16432: }
16433: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16434: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16435: }
16436: return;
16437: }
16438:
1.1075.2.27 raeburn 16439: sub allmaps_incourse {
16440: my ($cdom,$cnum,$chome,$cid) = @_;
16441: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16442: $cid = $env{'request.course.id'};
16443: $cdom = $env{'course.'.$cid.'.domain'};
16444: $cnum = $env{'course.'.$cid.'.num'};
16445: $chome = $env{'course.'.$cid.'.home'};
16446: }
16447: my %allmaps = ();
16448: my $lastchange =
16449: &Apache::lonnet::get_coursechange($cdom,$cnum);
16450: if ($lastchange > $env{'request.course.tied'}) {
16451: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16452: unless ($ferr) {
16453: &update_content_constraints($cdom,$cnum,$chome,$cid);
16454: }
16455: }
16456: my $navmap = Apache::lonnavmaps::navmap->new();
16457: if (defined($navmap)) {
16458: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16459: $allmaps{$res->src()} = 1;
16460: }
16461: }
16462: return \%allmaps;
16463: }
16464:
1.1075.2.11 raeburn 16465: sub parse_supplemental_title {
16466: my ($title) = @_;
16467:
16468: my ($foldertitle,$renametitle);
16469: if ($title =~ /&&&/) {
16470: $title = &HTML::Entites::decode($title);
16471: }
16472: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16473: $renametitle=$4;
16474: my ($time,$uname,$udom) = ($1,$2,$3);
16475: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16476: my $name = &plainname($uname,$udom);
16477: $name = &HTML::Entities::encode($name,'"<>&\'');
16478: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16479: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16480: $name.': <br />'.$foldertitle;
16481: }
16482: if (wantarray) {
16483: return ($title,$foldertitle,$renametitle);
16484: }
16485: return $title;
16486: }
16487:
1.1075.2.43 raeburn 16488: sub recurse_supplemental {
16489: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16490: if ($suppmap) {
16491: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16492: if ($fatal) {
16493: $errors ++;
16494: } else {
16495: if ($#LONCAPA::map::resources > 0) {
16496: foreach my $res (@LONCAPA::map::resources) {
16497: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16498: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 16499: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16500: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 16501: } else {
16502: $numfiles ++;
16503: }
16504: }
16505: }
16506: }
16507: }
16508: }
16509: return ($numfiles,$errors);
16510: }
16511:
1.1075.2.18 raeburn 16512: sub symb_to_docspath {
1.1075.2.119 raeburn 16513: my ($symb,$navmapref) = @_;
16514: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 16515: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16516: if ($resurl=~/\.(sequence|page)$/) {
16517: $mapurl=$resurl;
16518: } elsif ($resurl eq 'adm/navmaps') {
16519: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16520: }
16521: my $mapresobj;
1.1075.2.119 raeburn 16522: unless (ref($$navmapref)) {
16523: $$navmapref = Apache::lonnavmaps::navmap->new();
16524: }
16525: if (ref($$navmapref)) {
16526: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 16527: }
16528: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16529: my $type=$2;
16530: my $path;
16531: if (ref($mapresobj)) {
16532: my $pcslist = $mapresobj->map_hierarchy();
16533: if ($pcslist ne '') {
16534: foreach my $pc (split(/,/,$pcslist)) {
16535: next if ($pc <= 1);
1.1075.2.119 raeburn 16536: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 16537: if (ref($res)) {
16538: my $thisurl = $res->src();
16539: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16540: my $thistitle = $res->title();
16541: $path .= '&'.
16542: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 16543: &escape($thistitle).
1.1075.2.18 raeburn 16544: ':'.$res->randompick().
16545: ':'.$res->randomout().
16546: ':'.$res->encrypted().
16547: ':'.$res->randomorder().
16548: ':'.$res->is_page();
16549: }
16550: }
16551: }
16552: $path =~ s/^\&//;
16553: my $maptitle = $mapresobj->title();
16554: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16555: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16556: }
16557: $path .= (($path ne '')? '&' : '').
16558: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16559: &escape($maptitle).
1.1075.2.18 raeburn 16560: ':'.$mapresobj->randompick().
16561: ':'.$mapresobj->randomout().
16562: ':'.$mapresobj->encrypted().
16563: ':'.$mapresobj->randomorder().
16564: ':'.$mapresobj->is_page();
16565: } else {
16566: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16567: my $ispage = (($type eq 'page')? 1 : '');
16568: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16569: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16570: }
16571: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16572: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 16573: }
16574: unless ($mapurl eq 'default') {
16575: $path = 'default&'.
1.1075.2.46 raeburn 16576: &escape('Main Content').
1.1075.2.18 raeburn 16577: ':::::&'.$path;
16578: }
16579: return $path;
16580: }
16581:
1.1075.2.14 raeburn 16582: sub captcha_display {
16583: my ($context,$lonhost) = @_;
16584: my ($output,$error);
1.1075.2.107 raeburn 16585: my ($captcha,$pubkey,$privkey,$version) =
16586: &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16587: if ($captcha eq 'original') {
16588: $output = &create_captcha();
16589: unless ($output) {
16590: $error = 'captcha';
16591: }
16592: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16593: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 16594: unless ($output) {
16595: $error = 'recaptcha';
16596: }
16597: }
1.1075.2.107 raeburn 16598: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 16599: }
16600:
16601: sub captcha_response {
16602: my ($context,$lonhost) = @_;
16603: my ($captcha_chk,$captcha_error);
1.1075.2.109 raeburn 16604: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16605: if ($captcha eq 'original') {
16606: ($captcha_chk,$captcha_error) = &check_captcha();
16607: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16608: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 16609: } else {
16610: $captcha_chk = 1;
16611: }
16612: return ($captcha_chk,$captcha_error);
16613: }
16614:
16615: sub get_captcha_config {
16616: my ($context,$lonhost) = @_;
1.1075.2.107 raeburn 16617: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 16618: my $hostname = &Apache::lonnet::hostname($lonhost);
16619: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16620: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16621: if ($context eq 'usercreation') {
16622: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16623: if (ref($domconfig{$context}) eq 'HASH') {
16624: $hashtocheck = $domconfig{$context}{'cancreate'};
16625: if (ref($hashtocheck) eq 'HASH') {
16626: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16627: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16628: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16629: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16630: }
16631: if ($privkey && $pubkey) {
16632: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16633: $version = $hashtocheck->{'recaptchaversion'};
16634: if ($version ne '2') {
16635: $version = 1;
16636: }
1.1075.2.14 raeburn 16637: } else {
16638: $captcha = 'original';
16639: }
16640: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16641: $captcha = 'original';
16642: }
16643: }
16644: } else {
16645: $captcha = 'captcha';
16646: }
16647: } elsif ($context eq 'login') {
16648: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16649: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16650: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16651: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
16652: if ($privkey && $pubkey) {
16653: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16654: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
16655: if ($version ne '2') {
16656: $version = 1;
16657: }
1.1075.2.14 raeburn 16658: } else {
16659: $captcha = 'original';
16660: }
16661: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16662: $captcha = 'original';
16663: }
16664: }
1.1075.2.107 raeburn 16665: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 16666: }
16667:
16668: sub create_captcha {
16669: my %captcha_params = &captcha_settings();
16670: my ($output,$maxtries,$tries) = ('',10,0);
16671: while ($tries < $maxtries) {
16672: $tries ++;
16673: my $captcha = Authen::Captcha->new (
16674: output_folder => $captcha_params{'output_dir'},
16675: data_folder => $captcha_params{'db_dir'},
16676: );
16677: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16678:
16679: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16680: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16681: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 16682: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16683: '<br />'.
16684: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 16685: last;
16686: }
16687: }
16688: return $output;
16689: }
16690:
16691: sub captcha_settings {
16692: my %captcha_params = (
16693: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16694: www_output_dir => "/captchaspool",
16695: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16696: numchars => '5',
16697: );
16698: return %captcha_params;
16699: }
16700:
16701: sub check_captcha {
16702: my ($captcha_chk,$captcha_error);
16703: my $code = $env{'form.code'};
16704: my $md5sum = $env{'form.crypt'};
16705: my %captcha_params = &captcha_settings();
16706: my $captcha = Authen::Captcha->new(
16707: output_folder => $captcha_params{'output_dir'},
16708: data_folder => $captcha_params{'db_dir'},
16709: );
1.1075.2.26 raeburn 16710: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 16711: my %captcha_hash = (
16712: 0 => 'Code not checked (file error)',
16713: -1 => 'Failed: code expired',
16714: -2 => 'Failed: invalid code (not in database)',
16715: -3 => 'Failed: invalid code (code does not match crypt)',
16716: );
16717: if ($captcha_chk != 1) {
16718: $captcha_error = $captcha_hash{$captcha_chk}
16719: }
16720: return ($captcha_chk,$captcha_error);
16721: }
16722:
16723: sub create_recaptcha {
1.1075.2.107 raeburn 16724: my ($pubkey,$version) = @_;
16725: if ($version >= 2) {
16726: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
16727: } else {
16728: my $use_ssl;
16729: if ($ENV{'SERVER_PORT'} == 443) {
16730: $use_ssl = 1;
16731: }
16732: my $captcha = Captcha::reCAPTCHA->new;
16733: return $captcha->get_options_setter({theme => 'white'})."\n".
16734: $captcha->get_html($pubkey,undef,$use_ssl).
16735: &mt('If the text is hard to read, [_1] will replace them.',
16736: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
16737: '<br /><br />';
16738: }
1.1075.2.14 raeburn 16739: }
16740:
16741: sub check_recaptcha {
1.1075.2.107 raeburn 16742: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 16743: my $captcha_chk;
1.1075.2.107 raeburn 16744: if ($version >= 2) {
16745: my $ua = LWP::UserAgent->new;
16746: $ua->timeout(10);
16747: my %info = (
16748: secret => $privkey,
16749: response => $env{'form.g-recaptcha-response'},
16750: remoteip => $ENV{'REMOTE_ADDR'},
16751: );
16752: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
16753: if ($response->is_success) {
16754: my $data = JSON::DWIW->from_json($response->decoded_content);
16755: if (ref($data) eq 'HASH') {
16756: if ($data->{'success'}) {
16757: $captcha_chk = 1;
16758: }
16759: }
16760: }
16761: } else {
16762: my $captcha = Captcha::reCAPTCHA->new;
16763: my $captcha_result =
16764: $captcha->check_answer(
16765: $privkey,
16766: $ENV{'REMOTE_ADDR'},
16767: $env{'form.recaptcha_challenge_field'},
16768: $env{'form.recaptcha_response_field'},
16769: );
16770: if ($captcha_result->{is_valid}) {
16771: $captcha_chk = 1;
16772: }
1.1075.2.14 raeburn 16773: }
16774: return $captcha_chk;
16775: }
16776:
1.1075.2.64 raeburn 16777: sub emailusername_info {
1.1075.2.103 raeburn 16778: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 16779: my %titles = &Apache::lonlocal::texthash (
16780: lastname => 'Last Name',
16781: firstname => 'First Name',
16782: institution => 'School/college/university',
16783: location => "School's city, state/province, country",
16784: web => "School's web address",
16785: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 16786: id => 'Student/Employee ID',
1.1075.2.64 raeburn 16787: );
16788: return (\@fields,\%titles);
16789: }
16790:
1.1075.2.56 raeburn 16791: sub cleanup_html {
16792: my ($incoming) = @_;
16793: my $outgoing;
16794: if ($incoming ne '') {
16795: $outgoing = $incoming;
16796: $outgoing =~ s/;/;/g;
16797: $outgoing =~ s/\#/#/g;
16798: $outgoing =~ s/\&/&/g;
16799: $outgoing =~ s/</</g;
16800: $outgoing =~ s/>/>/g;
16801: $outgoing =~ s/\(/(/g;
16802: $outgoing =~ s/\)/)/g;
16803: $outgoing =~ s/"/"/g;
16804: $outgoing =~ s/'/'/g;
16805: $outgoing =~ s/\$/$/g;
16806: $outgoing =~ s{/}{/}g;
16807: $outgoing =~ s/=/=/g;
16808: $outgoing =~ s/\\/\/g
16809: }
16810: return $outgoing;
16811: }
16812:
1.1075.2.74 raeburn 16813: # Checks for critical messages and returns a redirect url if one exists.
16814: # $interval indicates how often to check for messages.
16815: sub critical_redirect {
16816: my ($interval) = @_;
16817: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16818: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16819: $env{'user.name'});
16820: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
16821: my $redirecturl;
16822: if ($what[0]) {
16823: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
16824: $redirecturl='/adm/email?critical=display';
16825: my $url=&Apache::lonnet::absolute_url().$redirecturl;
16826: return (1, $url);
16827: }
16828: }
16829: }
16830: return ();
16831: }
16832:
1.1075.2.64 raeburn 16833: # Use:
16834: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
16835: #
16836: ##################################################
16837: # password associated functions #
16838: ##################################################
16839: sub des_keys {
16840: # Make a new key for DES encryption.
16841: # Each key has two parts which are returned separately.
16842: # Please note: Each key must be passed through the &hex function
16843: # before it is output to the web browser. The hex versions cannot
16844: # be used to decrypt.
16845: my @hexstr=('0','1','2','3','4','5','6','7',
16846: '8','9','a','b','c','d','e','f');
16847: my $lkey='';
16848: for (0..7) {
16849: $lkey.=$hexstr[rand(15)];
16850: }
16851: my $ukey='';
16852: for (0..7) {
16853: $ukey.=$hexstr[rand(15)];
16854: }
16855: return ($lkey,$ukey);
16856: }
16857:
16858: sub des_decrypt {
16859: my ($key,$cyphertext) = @_;
16860: my $keybin=pack("H16",$key);
16861: my $cypher;
16862: if ($Crypt::DES::VERSION>=2.03) {
16863: $cypher=new Crypt::DES $keybin;
16864: } else {
16865: $cypher=new DES $keybin;
16866: }
1.1075.2.106 raeburn 16867: my $plaintext='';
16868: my $cypherlength = length($cyphertext);
16869: my $numchunks = int($cypherlength/32);
16870: for (my $j=0; $j<$numchunks; $j++) {
16871: my $start = $j*32;
16872: my $cypherblock = substr($cyphertext,$start,32);
16873: my $chunk =
16874: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
16875: $chunk .=
16876: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
16877: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
16878: $plaintext .= $chunk;
16879: }
1.1075.2.64 raeburn 16880: return $plaintext;
16881: }
16882:
1.112 bowersj2 16883: 1;
16884: __END__;
1.41 ng 16885:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>