Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.49
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.49! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.48 2013/08/20 12:02:31 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.479 albertel 72: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 73: use DateTime::TimeZone;
1.687 raeburn 74: use DateTime::Locale::Catalog;
1.1075.2.14 raeburn 75: use Authen::Captcha;
76: use Captcha::reCAPTCHA;
1.117 www 77:
1.517 raeburn 78: # ---------------------------------------------- Designs
79: use vars qw(%defaultdesign);
80:
1.22 www 81: my $readit;
82:
1.517 raeburn 83:
1.157 matthew 84: ##
85: ## Global Variables
86: ##
1.46 matthew 87:
1.643 foxr 88:
89: # ----------------------------------------------- SSI with retries:
90: #
91:
92: =pod
93:
1.648 raeburn 94: =head1 Server Side include with retries:
1.643 foxr 95:
96: =over 4
97:
1.648 raeburn 98: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 99:
100: Performs an ssi with some number of retries. Retries continue either
101: until the result is ok or until the retry count supplied by the
102: caller is exhausted.
103:
104: Inputs:
1.648 raeburn 105:
106: =over 4
107:
1.643 foxr 108: resource - Identifies the resource to insert.
1.648 raeburn 109:
1.643 foxr 110: retries - Count of the number of retries allowed.
1.648 raeburn 111:
1.643 foxr 112: form - Hash that identifies the rendering options.
113:
1.648 raeburn 114: =back
115:
116: Returns:
117:
118: =over 4
119:
1.643 foxr 120: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 121:
1.643 foxr 122: response - The response from the last attempt (which may or may not have been successful.
123:
1.648 raeburn 124: =back
125:
126: =back
127:
1.643 foxr 128: =cut
129:
130: sub ssi_with_retries {
131: my ($resource, $retries, %form) = @_;
132:
133:
134: my $ok = 0; # True if we got a good response.
135: my $content;
136: my $response;
137:
138: # Try to get the ssi done. within the retries count:
139:
140: do {
141: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
142: $ok = $response->is_success;
1.650 www 143: if (!$ok) {
144: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
145: }
1.643 foxr 146: $retries--;
147: } while (!$ok && ($retries > 0));
148:
149: if (!$ok) {
150: $content = ''; # On error return an empty content.
151: }
152: return ($content, $response);
153:
154: }
155:
156:
157:
1.20 www 158: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 159: my %language;
1.124 www 160: my %supported_language;
1.1048 foxr 161: my %latex_language; # For choosing hyphenation in <transl..>
162: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 163: my %cprtag;
1.192 taceyjo1 164: my %scprtag;
1.351 www 165: my %fe; my %fd; my %fm;
1.41 ng 166: my %category_extensions;
1.12 harris41 167:
1.46 matthew 168: # ---------------------------------------------- Thesaurus variables
1.144 matthew 169: #
170: # %Keywords:
171: # A hash used by &keyword to determine if a word is considered a keyword.
172: # $thesaurus_db_file
173: # Scalar containing the full path to the thesaurus database.
1.46 matthew 174:
175: my %Keywords;
176: my $thesaurus_db_file;
177:
1.144 matthew 178: #
179: # Initialize values from language.tab, copyright.tab, filetypes.tab,
180: # thesaurus.tab, and filecategories.tab.
181: #
1.18 www 182: BEGIN {
1.46 matthew 183: # Variable initialization
184: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
185: #
1.22 www 186: unless ($readit) {
1.12 harris41 187: # ------------------------------------------------------------------- languages
188: {
1.158 raeburn 189: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
190: '/language.tab';
191: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 192: while (my $line = <$fh>) {
193: next if ($line=~/^\#/);
194: chomp($line);
1.1048 foxr 195: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 196: $language{$key}=$val.' - '.$enc;
197: if ($sup) {
198: $supported_language{$key}=$sup;
199: }
1.1048 foxr 200: if ($latex) {
201: $latex_language_bykey{$key} = $latex;
202: $latex_language{$two} = $latex;
203: }
1.158 raeburn 204: }
205: close($fh);
206: }
1.12 harris41 207: }
208: # ------------------------------------------------------------------ copyrights
209: {
1.158 raeburn 210: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
211: '/copyright.tab';
212: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 213: while (my $line = <$fh>) {
214: next if ($line=~/^\#/);
215: chomp($line);
216: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 217: $cprtag{$key}=$val;
218: }
219: close($fh);
220: }
1.12 harris41 221: }
1.351 www 222: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 223: {
224: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
225: '/source_copyright.tab';
226: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 227: while (my $line = <$fh>) {
228: next if ($line =~ /^\#/);
229: chomp($line);
230: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 231: $scprtag{$key}=$val;
232: }
233: close($fh);
234: }
235: }
1.63 www 236:
1.517 raeburn 237: # -------------------------------------------------------------- default domain designs
1.63 www 238: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 239: my $designfile = $designdir.'/default.tab';
240: if ( open (my $fh,"<$designfile") ) {
241: while (my $line = <$fh>) {
242: next if ($line =~ /^\#/);
243: chomp($line);
244: my ($key,$val)=(split(/\=/,$line));
245: if ($val) { $defaultdesign{$key}=$val; }
246: }
247: close($fh);
1.63 www 248: }
249:
1.15 harris41 250: # ------------------------------------------------------------- file categories
251: {
1.158 raeburn 252: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
253: '/filecategories.tab';
254: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 255: while (my $line = <$fh>) {
256: next if ($line =~ /^\#/);
257: chomp($line);
258: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 259: push @{$category_extensions{lc($category)}},$extension;
260: }
261: close($fh);
262: }
263:
1.15 harris41 264: }
1.12 harris41 265: # ------------------------------------------------------------------ file types
266: {
1.158 raeburn 267: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
268: '/filetypes.tab';
269: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 270: while (my $line = <$fh>) {
271: next if ($line =~ /^\#/);
272: chomp($line);
273: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 274: if ($descr ne '') {
275: $fe{$ending}=lc($emb);
276: $fd{$ending}=$descr;
1.351 www 277: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 278: }
279: }
280: close($fh);
281: }
1.12 harris41 282: }
1.22 www 283: &Apache::lonnet::logthis(
1.705 tempelho 284: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 285: $readit=1;
1.46 matthew 286: } # end of unless($readit)
1.32 matthew 287:
288: }
1.112 bowersj2 289:
1.42 matthew 290: ###############################################################
291: ## HTML and Javascript Helper Functions ##
292: ###############################################################
293:
294: =pod
295:
1.112 bowersj2 296: =head1 HTML and Javascript Functions
1.42 matthew 297:
1.112 bowersj2 298: =over 4
299:
1.648 raeburn 300: =item * &browser_and_searcher_javascript()
1.112 bowersj2 301:
302: X<browsing, javascript>X<searching, javascript>Returns a string
303: containing javascript with two functions, C<openbrowser> and
304: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
305: tags.
1.42 matthew 306:
1.648 raeburn 307: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 308:
309: inputs: formname, elementname, only, omit
310:
311: formname and elementname indicate the name of the html form and name of
312: the element that the results of the browsing selection are to be placed in.
313:
314: Specifying 'only' will restrict the browser to displaying only files
1.185 www 315: with the given extension. Can be a comma separated list.
1.42 matthew 316:
317: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 318: with the given extension. Can be a comma separated list.
1.42 matthew 319:
1.648 raeburn 320: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 321:
322: Inputs: formname, elementname
323:
324: formname and elementname specify the name of the html form and the name
325: of the element the selection from the search results will be placed in.
1.542 raeburn 326:
1.42 matthew 327: =cut
328:
329: sub browser_and_searcher_javascript {
1.199 albertel 330: my ($mode)=@_;
331: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 332: my $resurl=&escape_single(&lastresurl());
1.42 matthew 333: return <<END;
1.219 albertel 334: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 335: var editbrowser = null;
1.135 albertel 336: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 337: var url = '$resurl/?';
1.42 matthew 338: if (editbrowser == null) {
339: url += 'launch=1&';
340: }
341: url += 'catalogmode=interactive&';
1.199 albertel 342: url += 'mode=$mode&';
1.611 albertel 343: url += 'inhibitmenu=yes&';
1.42 matthew 344: url += 'form=' + formname + '&';
345: if (only != null) {
346: url += 'only=' + only + '&';
1.217 albertel 347: } else {
348: url += 'only=&';
349: }
1.42 matthew 350: if (omit != null) {
351: url += 'omit=' + omit + '&';
1.217 albertel 352: } else {
353: url += 'omit=&';
354: }
1.135 albertel 355: if (titleelement != null) {
356: url += 'titleelement=' + titleelement + '&';
1.217 albertel 357: } else {
358: url += 'titleelement=&';
359: }
1.42 matthew 360: url += 'element=' + elementname + '';
361: var title = 'Browser';
1.435 albertel 362: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 363: options += ',width=700,height=600';
364: editbrowser = open(url,title,options,'1');
365: editbrowser.focus();
366: }
367: var editsearcher;
1.135 albertel 368: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 369: var url = '/adm/searchcat?';
370: if (editsearcher == null) {
371: url += 'launch=1&';
372: }
373: url += 'catalogmode=interactive&';
1.199 albertel 374: url += 'mode=$mode&';
1.42 matthew 375: url += 'form=' + formname + '&';
1.135 albertel 376: if (titleelement != null) {
377: url += 'titleelement=' + titleelement + '&';
1.217 albertel 378: } else {
379: url += 'titleelement=&';
380: }
1.42 matthew 381: url += 'element=' + elementname + '';
382: var title = 'Search';
1.435 albertel 383: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 384: options += ',width=700,height=600';
385: editsearcher = open(url,title,options,'1');
386: editsearcher.focus();
387: }
1.219 albertel 388: // END LON-CAPA Internal -->
1.42 matthew 389: END
1.170 www 390: }
391:
392: sub lastresurl {
1.258 albertel 393: if ($env{'environment.lastresurl'}) {
394: return $env{'environment.lastresurl'}
1.170 www 395: } else {
396: return '/res';
397: }
398: }
399:
400: sub storeresurl {
401: my $resurl=&Apache::lonnet::clutter(shift);
402: unless ($resurl=~/^\/res/) { return 0; }
403: $resurl=~s/\/$//;
404: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 405: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 406: return 1;
1.42 matthew 407: }
408:
1.74 www 409: sub studentbrowser_javascript {
1.111 www 410: unless (
1.258 albertel 411: (($env{'request.course.id'}) &&
1.302 albertel 412: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
413: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
414: '/'.$env{'request.course.sec'})
415: ))
1.258 albertel 416: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 417: ) { return ''; }
1.74 www 418: return (<<'ENDSTDBRW');
1.776 bisitz 419: <script type="text/javascript" language="Javascript">
1.824 bisitz 420: // <![CDATA[
1.74 www 421: var stdeditbrowser;
1.999 www 422: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 423: var url = '/adm/pickstudent?';
424: var filter;
1.558 albertel 425: if (!ignorefilter) {
426: eval('filter=document.'+formname+'.'+uname+'.value;');
427: }
1.74 www 428: if (filter != null) {
429: if (filter != '') {
430: url += 'filter='+filter+'&';
431: }
432: }
433: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 434: '&udomelement='+udom+
435: '&clicker='+clicker;
1.111 www 436: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 437: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 438: var title = 'Student_Browser';
1.74 www 439: var options = 'scrollbars=1,resizable=1,menubar=0';
440: options += ',width=700,height=600';
441: stdeditbrowser = open(url,title,options,'1');
442: stdeditbrowser.focus();
443: }
1.824 bisitz 444: // ]]>
1.74 www 445: </script>
446: ENDSTDBRW
447: }
1.42 matthew 448:
1.1003 www 449: sub resourcebrowser_javascript {
450: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 451: return (<<'ENDRESBRW');
1.1003 www 452: <script type="text/javascript" language="Javascript">
453: // <![CDATA[
454: var reseditbrowser;
1.1004 www 455: function openresbrowser(formname,reslink) {
1.1005 www 456: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 457: var title = 'Resource_Browser';
458: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 459: options += ',width=700,height=500';
1.1004 www 460: reseditbrowser = open(url,title,options,'1');
461: reseditbrowser.focus();
1.1003 www 462: }
463: // ]]>
464: </script>
1.1004 www 465: ENDRESBRW
1.1003 www 466: }
467:
1.74 www 468: sub selectstudent_link {
1.999 www 469: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
470: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
471: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
472: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 473: if ($env{'request.course.id'}) {
1.302 albertel 474: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
475: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
476: '/'.$env{'request.course.sec'})) {
1.111 www 477: return '';
478: }
1.999 www 479: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 480: if ($courseadvonly) {
481: $callargs .= ",'',1,1";
482: }
483: return '<span class="LC_nobreak">'.
484: '<a href="javascript:openstdbrowser('.$callargs.');">'.
485: &mt('Select User').'</a></span>';
1.74 www 486: }
1.258 albertel 487: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 488: $callargs .= ",'',1";
1.793 raeburn 489: return '<span class="LC_nobreak">'.
490: '<a href="javascript:openstdbrowser('.$callargs.');">'.
491: &mt('Select User').'</a></span>';
1.111 www 492: }
493: return '';
1.91 www 494: }
495:
1.1004 www 496: sub selectresource_link {
497: my ($form,$reslink,$arg)=@_;
498:
499: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
500: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
501: unless ($env{'request.course.id'}) { return $arg; }
502: return '<span class="LC_nobreak">'.
503: '<a href="javascript:openresbrowser('.$callargs.');">'.
504: $arg.'</a></span>';
505: }
506:
507:
508:
1.653 raeburn 509: sub authorbrowser_javascript {
510: return <<"ENDAUTHORBRW";
1.776 bisitz 511: <script type="text/javascript" language="JavaScript">
1.824 bisitz 512: // <![CDATA[
1.653 raeburn 513: var stdeditbrowser;
514:
515: function openauthorbrowser(formname,udom) {
516: var url = '/adm/pickauthor?';
517: url += 'form='+formname+'&roledom='+udom;
518: var title = 'Author_Browser';
519: var options = 'scrollbars=1,resizable=1,menubar=0';
520: options += ',width=700,height=600';
521: stdeditbrowser = open(url,title,options,'1');
522: stdeditbrowser.focus();
523: }
524:
1.824 bisitz 525: // ]]>
1.653 raeburn 526: </script>
527: ENDAUTHORBRW
528: }
529:
1.91 www 530: sub coursebrowser_javascript {
1.1075.2.31 raeburn 531: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
532: $credits_element) = @_;
1.932 raeburn 533: my $wintitle = 'Course_Browser';
1.931 raeburn 534: if ($crstype eq 'Community') {
1.932 raeburn 535: $wintitle = 'Community_Browser';
1.909 raeburn 536: }
1.876 raeburn 537: my $id_functions = &javascript_index_functions();
538: my $output = '
1.776 bisitz 539: <script type="text/javascript" language="JavaScript">
1.824 bisitz 540: // <![CDATA[
1.468 raeburn 541: var stdeditbrowser;'."\n";
1.876 raeburn 542:
543: $output .= <<"ENDSTDBRW";
1.909 raeburn 544: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 545: var url = '/adm/pickcourse?';
1.895 raeburn 546: var formid = getFormIdByName(formname);
1.876 raeburn 547: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 548: if (domainfilter != null) {
549: if (domainfilter != '') {
550: url += 'domainfilter='+domainfilter+'&';
551: }
552: }
1.91 www 553: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 554: '&cdomelement='+udom+
555: '&cnameelement='+desc;
1.468 raeburn 556: if (extra_element !=null && extra_element != '') {
1.594 raeburn 557: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 558: url += '&roleelement='+extra_element;
559: if (domainfilter == null || domainfilter == '') {
560: url += '&domainfilter='+extra_element;
561: }
1.234 raeburn 562: }
1.468 raeburn 563: else {
564: if (formname == 'portform') {
565: url += '&setroles='+extra_element;
1.800 raeburn 566: } else {
567: if (formname == 'rules') {
568: url += '&fixeddom='+extra_element;
569: }
1.468 raeburn 570: }
571: }
1.230 raeburn 572: }
1.909 raeburn 573: if (type != null && type != '') {
574: url += '&type='+type;
575: }
576: if (type_elem != null && type_elem != '') {
577: url += '&typeelement='+type_elem;
578: }
1.872 raeburn 579: if (formname == 'ccrs') {
580: var ownername = document.forms[formid].ccuname.value;
581: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
582: url += '&cloner='+ownername+':'+ownerdom;
583: }
1.293 raeburn 584: if (multflag !=null && multflag != '') {
585: url += '&multiple='+multflag;
586: }
1.909 raeburn 587: var title = '$wintitle';
1.91 www 588: var options = 'scrollbars=1,resizable=1,menubar=0';
589: options += ',width=700,height=600';
590: stdeditbrowser = open(url,title,options,'1');
591: stdeditbrowser.focus();
592: }
1.876 raeburn 593: $id_functions
594: ENDSTDBRW
1.1075.2.31 raeburn 595: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
596: $output .= &setsec_javascript($sec_element,$formname,$role_element,
597: $credits_element);
1.876 raeburn 598: }
599: $output .= '
600: // ]]>
601: </script>';
602: return $output;
603: }
604:
605: sub javascript_index_functions {
606: return <<"ENDJS";
607:
608: function getFormIdByName(formname) {
609: for (var i=0;i<document.forms.length;i++) {
610: if (document.forms[i].name == formname) {
611: return i;
612: }
613: }
614: return -1;
615: }
616:
617: function getIndexByName(formid,item) {
618: for (var i=0;i<document.forms[formid].elements.length;i++) {
619: if (document.forms[formid].elements[i].name == item) {
620: return i;
621: }
622: }
623: return -1;
624: }
1.468 raeburn 625:
1.876 raeburn 626: function getDomainFromSelectbox(formname,udom) {
627: var userdom;
628: var formid = getFormIdByName(formname);
629: if (formid > -1) {
630: var domid = getIndexByName(formid,udom);
631: if (domid > -1) {
632: if (document.forms[formid].elements[domid].type == 'select-one') {
633: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
634: }
635: if (document.forms[formid].elements[domid].type == 'hidden') {
636: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 637: }
638: }
639: }
1.876 raeburn 640: return userdom;
641: }
642:
643: ENDJS
1.468 raeburn 644:
1.876 raeburn 645: }
646:
1.1017 raeburn 647: sub javascript_array_indexof {
1.1018 raeburn 648: return <<ENDJS;
1.1017 raeburn 649: <script type="text/javascript" language="JavaScript">
650: // <![CDATA[
651:
652: if (!Array.prototype.indexOf) {
653: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
654: "use strict";
655: if (this === void 0 || this === null) {
656: throw new TypeError();
657: }
658: var t = Object(this);
659: var len = t.length >>> 0;
660: if (len === 0) {
661: return -1;
662: }
663: var n = 0;
664: if (arguments.length > 0) {
665: n = Number(arguments[1]);
666: if (n !== n) { // shortcut for verifying if it's NaN
667: n = 0;
668: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
669: n = (n > 0 || -1) * Math.floor(Math.abs(n));
670: }
671: }
672: if (n >= len) {
673: return -1;
674: }
675: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
676: for (; k < len; k++) {
677: if (k in t && t[k] === searchElement) {
678: return k;
679: }
680: }
681: return -1;
682: }
683: }
684:
685: // ]]>
686: </script>
687:
688: ENDJS
689:
690: }
691:
1.876 raeburn 692: sub userbrowser_javascript {
693: my $id_functions = &javascript_index_functions();
694: return <<"ENDUSERBRW";
695:
1.888 raeburn 696: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 697: var url = '/adm/pickuser?';
698: var userdom = getDomainFromSelectbox(formname,udom);
699: if (userdom != null) {
700: if (userdom != '') {
701: url += 'srchdom='+userdom+'&';
702: }
703: }
704: url += 'form=' + formname + '&unameelement='+uname+
705: '&udomelement='+udom+
706: '&ulastelement='+ulast+
707: '&ufirstelement='+ufirst+
708: '&uemailelement='+uemail+
1.881 raeburn 709: '&hideudomelement='+hideudom+
710: '&coursedom='+crsdom;
1.888 raeburn 711: if ((caller != null) && (caller != undefined)) {
712: url += '&caller='+caller;
713: }
1.876 raeburn 714: var title = 'User_Browser';
715: var options = 'scrollbars=1,resizable=1,menubar=0';
716: options += ',width=700,height=600';
717: var stdeditbrowser = open(url,title,options,'1');
718: stdeditbrowser.focus();
719: }
720:
1.888 raeburn 721: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 722: var formid = getFormIdByName(formname);
723: if (formid > -1) {
1.888 raeburn 724: var unameid = getIndexByName(formid,uname);
1.876 raeburn 725: var domid = getIndexByName(formid,udom);
726: var hidedomid = getIndexByName(formid,origdom);
727: if (hidedomid > -1) {
728: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 729: var unameval = document.forms[formid].elements[unameid].value;
730: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
731: if (domid > -1) {
732: var slct = document.forms[formid].elements[domid];
733: if (slct.type == 'select-one') {
734: var i;
735: for (i=0;i<slct.length;i++) {
736: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
737: }
738: }
739: if (slct.type == 'hidden') {
740: slct.value = fixeddom;
1.876 raeburn 741: }
742: }
1.468 raeburn 743: }
744: }
745: }
1.876 raeburn 746: return;
747: }
748:
749: $id_functions
750: ENDUSERBRW
1.468 raeburn 751: }
752:
753: sub setsec_javascript {
1.1075.2.31 raeburn 754: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 755: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
756: $communityrolestr);
757: if ($role_element ne '') {
758: my @allroles = ('st','ta','ep','in','ad');
759: foreach my $crstype ('Course','Community') {
760: if ($crstype eq 'Community') {
761: foreach my $role (@allroles) {
762: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
763: }
764: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
765: } else {
766: foreach my $role (@allroles) {
767: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
768: }
769: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
770: }
771: }
772: $rolestr = '"'.join('","',@allroles).'"';
773: $courserolestr = '"'.join('","',@courserolenames).'"';
774: $communityrolestr = '"'.join('","',@communityrolenames).'"';
775: }
1.468 raeburn 776: my $setsections = qq|
777: function setSect(sectionlist) {
1.629 raeburn 778: var sectionsArray = new Array();
779: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
780: sectionsArray = sectionlist.split(",");
781: }
1.468 raeburn 782: var numSections = sectionsArray.length;
783: document.$formname.$sec_element.length = 0;
784: if (numSections == 0) {
785: document.$formname.$sec_element.multiple=false;
786: document.$formname.$sec_element.size=1;
787: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
788: } else {
789: if (numSections == 1) {
790: document.$formname.$sec_element.multiple=false;
791: document.$formname.$sec_element.size=1;
792: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
793: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
794: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
795: } else {
796: for (var i=0; i<numSections; i++) {
797: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
798: }
799: document.$formname.$sec_element.multiple=true
800: if (numSections < 3) {
801: document.$formname.$sec_element.size=numSections;
802: } else {
803: document.$formname.$sec_element.size=3;
804: }
805: document.$formname.$sec_element.options[0].selected = false
806: }
807: }
1.91 www 808: }
1.905 raeburn 809:
810: function setRole(crstype) {
1.468 raeburn 811: |;
1.905 raeburn 812: if ($role_element eq '') {
813: $setsections .= ' return;
814: }
815: ';
816: } else {
817: $setsections .= qq|
818: var elementLength = document.$formname.$role_element.length;
819: var allroles = Array($rolestr);
820: var courserolenames = Array($courserolestr);
821: var communityrolenames = Array($communityrolestr);
822: if (elementLength != undefined) {
823: if (document.$formname.$role_element.options[5].value == 'cc') {
824: if (crstype == 'Course') {
825: return;
826: } else {
827: allroles[5] = 'co';
828: for (var i=0; i<6; i++) {
829: document.$formname.$role_element.options[i].value = allroles[i];
830: document.$formname.$role_element.options[i].text = communityrolenames[i];
831: }
832: }
833: } else {
834: if (crstype == 'Community') {
835: return;
836: } else {
837: allroles[5] = 'cc';
838: for (var i=0; i<6; i++) {
839: document.$formname.$role_element.options[i].value = allroles[i];
840: document.$formname.$role_element.options[i].text = courserolenames[i];
841: }
842: }
843: }
844: }
845: return;
846: }
847: |;
848: }
1.1075.2.31 raeburn 849: if ($credits_element) {
850: $setsections .= qq|
851: function setCredits(defaultcredits) {
852: document.$formname.$credits_element.value = defaultcredits;
853: return;
854: }
855: |;
856: }
1.468 raeburn 857: return $setsections;
858: }
859:
1.91 www 860: sub selectcourse_link {
1.909 raeburn 861: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
862: $typeelement) = @_;
863: my $type = $selecttype;
1.871 raeburn 864: my $linktext = &mt('Select Course');
865: if ($selecttype eq 'Community') {
1.909 raeburn 866: $linktext = &mt('Select Community');
1.906 raeburn 867: } elsif ($selecttype eq 'Course/Community') {
868: $linktext = &mt('Select Course/Community');
1.909 raeburn 869: $type = '';
1.1019 raeburn 870: } elsif ($selecttype eq 'Select') {
871: $linktext = &mt('Select');
872: $type = '';
1.871 raeburn 873: }
1.787 bisitz 874: return '<span class="LC_nobreak">'
875: ."<a href='"
876: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
877: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 878: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 879: ."'>".$linktext.'</a>'
1.787 bisitz 880: .'</span>';
1.74 www 881: }
1.42 matthew 882:
1.653 raeburn 883: sub selectauthor_link {
884: my ($form,$udom)=@_;
885: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
886: &mt('Select Author').'</a>';
887: }
888:
1.876 raeburn 889: sub selectuser_link {
1.881 raeburn 890: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 891: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 892: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 893: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 894: ');">'.$linktext.'</a>';
1.876 raeburn 895: }
896:
1.273 raeburn 897: sub check_uncheck_jscript {
898: my $jscript = <<"ENDSCRT";
899: function checkAll(field) {
900: if (field.length > 0) {
901: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 902: if (!field[i].disabled) {
903: field[i].checked = true;
904: }
1.273 raeburn 905: }
906: } else {
1.1075.2.14 raeburn 907: if (!field.disabled) {
908: field.checked = true;
909: }
1.273 raeburn 910: }
911: }
912:
913: function uncheckAll(field) {
914: if (field.length > 0) {
915: for (i = 0; i < field.length; i++) {
916: field[i].checked = false ;
1.543 albertel 917: }
918: } else {
1.273 raeburn 919: field.checked = false ;
920: }
921: }
922: ENDSCRT
923: return $jscript;
924: }
925:
1.656 www 926: sub select_timezone {
1.659 raeburn 927: my ($name,$selected,$onchange,$includeempty)=@_;
928: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
929: if ($includeempty) {
930: $output .= '<option value=""';
931: if (($selected eq '') || ($selected eq 'local')) {
932: $output .= ' selected="selected" ';
933: }
934: $output .= '> </option>';
935: }
1.657 raeburn 936: my @timezones = DateTime::TimeZone->all_names;
937: foreach my $tzone (@timezones) {
938: $output.= '<option value="'.$tzone.'"';
939: if ($tzone eq $selected) {
940: $output.=' selected="selected"';
941: }
942: $output.=">$tzone</option>\n";
1.656 www 943: }
944: $output.="</select>";
945: return $output;
946: }
1.273 raeburn 947:
1.687 raeburn 948: sub select_datelocale {
949: my ($name,$selected,$onchange,$includeempty)=@_;
950: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
951: if ($includeempty) {
952: $output .= '<option value=""';
953: if ($selected eq '') {
954: $output .= ' selected="selected" ';
955: }
956: $output .= '> </option>';
957: }
958: my (@possibles,%locale_names);
959: my @locales = DateTime::Locale::Catalog::Locales;
960: foreach my $locale (@locales) {
961: if (ref($locale) eq 'HASH') {
962: my $id = $locale->{'id'};
963: if ($id ne '') {
964: my $en_terr = $locale->{'en_territory'};
965: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 966: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 967: if (grep(/^en$/,@languages) || !@languages) {
968: if ($en_terr ne '') {
969: $locale_names{$id} = '('.$en_terr.')';
970: } elsif ($native_terr ne '') {
971: $locale_names{$id} = $native_terr;
972: }
973: } else {
974: if ($native_terr ne '') {
975: $locale_names{$id} = $native_terr.' ';
976: } elsif ($en_terr ne '') {
977: $locale_names{$id} = '('.$en_terr.')';
978: }
979: }
980: push (@possibles,$id);
981: }
982: }
983: }
984: foreach my $item (sort(@possibles)) {
985: $output.= '<option value="'.$item.'"';
986: if ($item eq $selected) {
987: $output.=' selected="selected"';
988: }
989: $output.=">$item";
990: if ($locale_names{$item} ne '') {
991: $output.=" $locale_names{$item}</option>\n";
992: }
993: $output.="</option>\n";
994: }
995: $output.="</select>";
996: return $output;
997: }
998:
1.792 raeburn 999: sub select_language {
1000: my ($name,$selected,$includeempty) = @_;
1001: my %langchoices;
1002: if ($includeempty) {
1.1075.2.32 raeburn 1003: %langchoices = ('' => 'No language preference');
1.792 raeburn 1004: }
1005: foreach my $id (&languageids()) {
1006: my $code = &supportedlanguagecode($id);
1007: if ($code) {
1008: $langchoices{$code} = &plainlanguagedescription($id);
1009: }
1010: }
1.1075.2.32 raeburn 1011: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1012: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1013: }
1014:
1.42 matthew 1015: =pod
1.36 matthew 1016:
1.648 raeburn 1017: =item * &linked_select_forms(...)
1.36 matthew 1018:
1019: linked_select_forms returns a string containing a <script></script> block
1020: and html for two <select> menus. The select menus will be linked in that
1021: changing the value of the first menu will result in new values being placed
1022: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1023: order unless a defined order is provided.
1.36 matthew 1024:
1025: linked_select_forms takes the following ordered inputs:
1026:
1027: =over 4
1028:
1.112 bowersj2 1029: =item * $formname, the name of the <form> tag
1.36 matthew 1030:
1.112 bowersj2 1031: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1032:
1.112 bowersj2 1033: =item * $firstdefault, the default value for the first menu
1.36 matthew 1034:
1.112 bowersj2 1035: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1036:
1.112 bowersj2 1037: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1038:
1.112 bowersj2 1039: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1040:
1.609 raeburn 1041: =item * $menuorder, the order of values in the first menu
1042:
1.1075.2.31 raeburn 1043: =item * $onchangefirst, additional javascript call to execute for an onchange
1044: event for the first <select> tag
1045:
1046: =item * $onchangesecond, additional javascript call to execute for an onchange
1047: event for the second <select> tag
1048:
1.41 ng 1049: =back
1050:
1.36 matthew 1051: Below is an example of such a hash. Only the 'text', 'default', and
1052: 'select2' keys must appear as stated. keys(%menu) are the possible
1053: values for the first select menu. The text that coincides with the
1.41 ng 1054: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1055: and text for the second menu are given in the hash pointed to by
1056: $menu{$choice1}->{'select2'}.
1057:
1.112 bowersj2 1058: my %menu = ( A1 => { text =>"Choice A1" ,
1059: default => "B3",
1060: select2 => {
1061: B1 => "Choice B1",
1062: B2 => "Choice B2",
1063: B3 => "Choice B3",
1064: B4 => "Choice B4"
1.609 raeburn 1065: },
1066: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1067: },
1068: A2 => { text =>"Choice A2" ,
1069: default => "C2",
1070: select2 => {
1071: C1 => "Choice C1",
1072: C2 => "Choice C2",
1073: C3 => "Choice C3"
1.609 raeburn 1074: },
1075: order => ['C2','C1','C3'],
1.112 bowersj2 1076: },
1077: A3 => { text =>"Choice A3" ,
1078: default => "D6",
1079: select2 => {
1080: D1 => "Choice D1",
1081: D2 => "Choice D2",
1082: D3 => "Choice D3",
1083: D4 => "Choice D4",
1084: D5 => "Choice D5",
1085: D6 => "Choice D6",
1086: D7 => "Choice D7"
1.609 raeburn 1087: },
1088: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1089: }
1090: );
1.36 matthew 1091:
1092: =cut
1093:
1094: sub linked_select_forms {
1095: my ($formname,
1096: $middletext,
1097: $firstdefault,
1098: $firstselectname,
1099: $secondselectname,
1.609 raeburn 1100: $hashref,
1101: $menuorder,
1.1075.2.31 raeburn 1102: $onchangefirst,
1103: $onchangesecond
1.36 matthew 1104: ) = @_;
1105: my $second = "document.$formname.$secondselectname";
1106: my $first = "document.$formname.$firstselectname";
1107: # output the javascript to do the changing
1108: my $result = '';
1.776 bisitz 1109: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1110: $result.="// <![CDATA[\n";
1.36 matthew 1111: $result.="var select2data = new Object();\n";
1112: $" = '","';
1113: my $debug = '';
1114: foreach my $s1 (sort(keys(%$hashref))) {
1115: $result.="select2data.d_$s1 = new Object();\n";
1116: $result.="select2data.d_$s1.def = new String('".
1117: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1118: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1119: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1120: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1121: @s2values = @{$hashref->{$s1}->{'order'}};
1122: }
1.36 matthew 1123: $result.="\"@s2values\");\n";
1124: $result.="select2data.d_$s1.texts = new Array(";
1125: my @s2texts;
1126: foreach my $value (@s2values) {
1127: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1128: }
1129: $result.="\"@s2texts\");\n";
1130: }
1131: $"=' ';
1132: $result.= <<"END";
1133:
1134: function select1_changed() {
1135: // Determine new choice
1136: var newvalue = "d_" + $first.value;
1137: // update select2
1138: var values = select2data[newvalue].values;
1139: var texts = select2data[newvalue].texts;
1140: var select2def = select2data[newvalue].def;
1141: var i;
1142: // out with the old
1143: for (i = 0; i < $second.options.length; i++) {
1144: $second.options[i] = null;
1145: }
1146: // in with the nuclear
1147: for (i=0;i<values.length; i++) {
1148: $second.options[i] = new Option(values[i]);
1.143 matthew 1149: $second.options[i].value = values[i];
1.36 matthew 1150: $second.options[i].text = texts[i];
1151: if (values[i] == select2def) {
1152: $second.options[i].selected = true;
1153: }
1154: }
1155: }
1.824 bisitz 1156: // ]]>
1.36 matthew 1157: </script>
1158: END
1159: # output the initial values for the selection lists
1.1075.2.31 raeburn 1160: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1161: my @order = sort(keys(%{$hashref}));
1162: if (ref($menuorder) eq 'ARRAY') {
1163: @order = @{$menuorder};
1164: }
1165: foreach my $value (@order) {
1.36 matthew 1166: $result.=" <option value=\"$value\" ";
1.253 albertel 1167: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1168: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1169: }
1170: $result .= "</select>\n";
1171: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1172: $result .= $middletext;
1.1075.2.31 raeburn 1173: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1174: if ($onchangesecond) {
1175: $result .= ' onchange="'.$onchangesecond.'"';
1176: }
1177: $result .= ">\n";
1.36 matthew 1178: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1179:
1180: my @secondorder = sort(keys(%select2));
1181: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1182: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1183: }
1184: foreach my $value (@secondorder) {
1.36 matthew 1185: $result.=" <option value=\"$value\" ";
1.253 albertel 1186: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1187: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1188: }
1189: $result .= "</select>\n";
1190: # return $debug;
1191: return $result;
1192: } # end of sub linked_select_forms {
1193:
1.45 matthew 1194: =pod
1.44 bowersj2 1195:
1.973 raeburn 1196: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1197:
1.112 bowersj2 1198: Returns a string corresponding to an HTML link to the given help
1199: $topic, where $topic corresponds to the name of a .tex file in
1200: /home/httpd/html/adm/help/tex, with underscores replaced by
1201: spaces.
1202:
1203: $text will optionally be linked to the same topic, allowing you to
1204: link text in addition to the graphic. If you do not want to link
1205: text, but wish to specify one of the later parameters, pass an
1206: empty string.
1207:
1208: $stayOnPage is a value that will be interpreted as a boolean. If true,
1209: the link will not open a new window. If false, the link will open
1210: a new window using Javascript. (Default is false.)
1211:
1212: $width and $height are optional numerical parameters that will
1213: override the width and height of the popped up window, which may
1.973 raeburn 1214: be useful for certain help topics with big pictures included.
1215:
1216: $imgid is the id of the img tag used for the help icon. This may be
1217: used in a javascript call to switch the image src. See
1218: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1219:
1220: =cut
1221:
1222: sub help_open_topic {
1.973 raeburn 1223: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1224: $text = "" if (not defined $text);
1.44 bowersj2 1225: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1226: $width = 500 if (not defined $width);
1.44 bowersj2 1227: $height = 400 if (not defined $height);
1228: my $filename = $topic;
1229: $filename =~ s/ /_/g;
1230:
1.48 bowersj2 1231: my $template = "";
1232: my $link;
1.572 banghart 1233:
1.159 www 1234: $topic=~s/\W/\_/g;
1.44 bowersj2 1235:
1.572 banghart 1236: if (!$stayOnPage) {
1.1033 www 1237: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1238: } elsif ($stayOnPage eq 'popup') {
1239: $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 1240: } else {
1.48 bowersj2 1241: $link = "/adm/help/${filename}.hlp";
1242: }
1243:
1244: # Add the text
1.755 neumanie 1245: if ($text ne "") {
1.763 bisitz 1246: $template.='<span class="LC_help_open_topic">'
1247: .'<a target="_top" href="'.$link.'">'
1248: .$text.'</a>';
1.48 bowersj2 1249: }
1250:
1.763 bisitz 1251: # (Always) Add the graphic
1.179 matthew 1252: my $title = &mt('Online Help');
1.667 raeburn 1253: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1254: if ($imgid ne '') {
1255: $imgid = ' id="'.$imgid.'"';
1256: }
1.763 bisitz 1257: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1258: .'<img src="'.$helpicon.'" border="0"'
1259: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1260: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1261: .' /></a>';
1262: if ($text ne "") {
1263: $template.='</span>';
1264: }
1.44 bowersj2 1265: return $template;
1266:
1.106 bowersj2 1267: }
1268:
1269: # This is a quicky function for Latex cheatsheet editing, since it
1270: # appears in at least four places
1271: sub helpLatexCheatsheet {
1.1037 www 1272: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1273: my $out;
1.106 bowersj2 1274: my $addOther = '';
1.732 raeburn 1275: if ($topic) {
1.1037 www 1276: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1277: }
1278: $out = '<span>' # Start cheatsheet
1279: .$addOther
1280: .'<span>'
1.1037 www 1281: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1282: .'</span> <span>'
1.1037 www 1283: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1284: .'</span>';
1.732 raeburn 1285: unless ($not_author) {
1.763 bisitz 1286: $out .= ' <span>'
1.1037 www 1287: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763 bisitz 1288: .'</span>';
1.732 raeburn 1289: }
1.763 bisitz 1290: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1291: return $out;
1.172 www 1292: }
1293:
1.430 albertel 1294: sub general_help {
1295: my $helptopic='Student_Intro';
1296: if ($env{'request.role'}=~/^(ca|au)/) {
1297: $helptopic='Authoring_Intro';
1.907 raeburn 1298: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1299: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1300: } elsif ($env{'request.role'}=~/^dc/) {
1301: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1302: }
1303: return $helptopic;
1304: }
1305:
1306: sub update_help_link {
1307: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1308: my $origurl = $ENV{'REQUEST_URI'};
1309: $origurl=~s|^/~|/priv/|;
1310: my $timestamp = time;
1311: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1312: $$datum = &escape($$datum);
1313: }
1314:
1315: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1316: my $output .= <<"ENDOUTPUT";
1317: <script type="text/javascript">
1.824 bisitz 1318: // <![CDATA[
1.430 albertel 1319: banner_link = '$banner_link';
1.824 bisitz 1320: // ]]>
1.430 albertel 1321: </script>
1322: ENDOUTPUT
1323: return $output;
1324: }
1325:
1326: # now just updates the help link and generates a blue icon
1.193 raeburn 1327: sub help_open_menu {
1.430 albertel 1328: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1329: = @_;
1.949 droeschl 1330: $stayOnPage = 1;
1.430 albertel 1331: my $output;
1332: if ($component_help) {
1333: if (!$text) {
1334: $output=&help_open_topic($component_help,undef,$stayOnPage,
1335: $width,$height);
1336: } else {
1337: my $help_text;
1338: $help_text=&unescape($topic);
1339: $output='<table><tr><td>'.
1340: &help_open_topic($component_help,$help_text,$stayOnPage,
1341: $width,$height).'</td></tr></table>';
1342: }
1343: }
1344: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1345: return $output.$banner_link;
1346: }
1347:
1348: sub top_nav_help {
1349: my ($text) = @_;
1.436 albertel 1350: $text = &mt($text);
1.949 droeschl 1351: my $stay_on_page = 1;
1352:
1.572 banghart 1353: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1354: : "javascript:helpMenu('open')";
1.572 banghart 1355: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1356:
1.201 raeburn 1357: my $title = &mt('Get help');
1.436 albertel 1358:
1359: return <<"END";
1360: $banner_link
1361: <a href="$link" title="$title">$text</a>
1362: END
1363: }
1364:
1365: sub help_menu_js {
1366: my ($text) = @_;
1.949 droeschl 1367: my $stayOnPage = 1;
1.436 albertel 1368: my $width = 620;
1369: my $height = 600;
1.430 albertel 1370: my $helptopic=&general_help();
1371: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1372: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1373: my $start_page =
1374: &Apache::loncommon::start_page('Help Menu', undef,
1375: {'frameset' => 1,
1376: 'js_ready' => 1,
1377: 'add_entries' => {
1378: 'border' => '0',
1.579 raeburn 1379: 'rows' => "110,*",},});
1.331 albertel 1380: my $end_page =
1381: &Apache::loncommon::end_page({'frameset' => 1,
1382: 'js_ready' => 1,});
1383:
1.436 albertel 1384: my $template .= <<"ENDTEMPLATE";
1385: <script type="text/javascript">
1.877 bisitz 1386: // <![CDATA[
1.253 albertel 1387: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1388: var banner_link = '';
1.243 raeburn 1389: function helpMenu(target) {
1390: var caller = this;
1391: if (target == 'open') {
1392: var newWindow = null;
1393: try {
1.262 albertel 1394: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1395: }
1396: catch(error) {
1397: writeHelp(caller);
1398: return;
1399: }
1400: if (newWindow) {
1401: caller = newWindow;
1402: }
1.193 raeburn 1403: }
1.243 raeburn 1404: writeHelp(caller);
1405: return;
1406: }
1407: function writeHelp(caller) {
1.1072 raeburn 1408: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" />\\n<frame name="bodyframe" src="$details_link" />\\n$end_page')
1.243 raeburn 1409: caller.document.close()
1410: caller.focus()
1.193 raeburn 1411: }
1.877 bisitz 1412: // END LON-CAPA Internal -->
1.253 albertel 1413: // ]]>
1.436 albertel 1414: </script>
1.193 raeburn 1415: ENDTEMPLATE
1416: return $template;
1417: }
1418:
1.172 www 1419: sub help_open_bug {
1420: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1421: unless ($env{'user.adv'}) { return ''; }
1.172 www 1422: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1423: $text = "" if (not defined $text);
1424: $stayOnPage=1;
1.184 albertel 1425: $width = 600 if (not defined $width);
1426: $height = 600 if (not defined $height);
1.172 www 1427:
1428: $topic=~s/\W+/\+/g;
1429: my $link='';
1430: my $template='';
1.379 albertel 1431: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1432: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1433: if (!$stayOnPage)
1434: {
1435: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1436: }
1437: else
1438: {
1439: $link = $url;
1440: }
1441: # Add the text
1442: if ($text ne "")
1443: {
1444: $template .=
1445: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1446: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1447: }
1448:
1449: # Add the graphic
1.179 matthew 1450: my $title = &mt('Report a Bug');
1.215 albertel 1451: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1452: $template .= <<"ENDTEMPLATE";
1.436 albertel 1453: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1454: ENDTEMPLATE
1455: if ($text ne '') { $template.='</td></tr></table>' };
1456: return $template;
1457:
1458: }
1459:
1460: sub help_open_faq {
1461: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1462: unless ($env{'user.adv'}) { return ''; }
1.172 www 1463: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1464: $text = "" if (not defined $text);
1465: $stayOnPage=1;
1466: $width = 350 if (not defined $width);
1467: $height = 400 if (not defined $height);
1468:
1469: $topic=~s/\W+/\+/g;
1470: my $link='';
1471: my $template='';
1472: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1473: if (!$stayOnPage)
1474: {
1475: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1476: }
1477: else
1478: {
1479: $link = $url;
1480: }
1481:
1482: # Add the text
1483: if ($text ne "")
1484: {
1485: $template .=
1.173 www 1486: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1487: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1488: }
1489:
1490: # Add the graphic
1.179 matthew 1491: my $title = &mt('View the FAQ');
1.215 albertel 1492: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1493: $template .= <<"ENDTEMPLATE";
1.436 albertel 1494: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1495: ENDTEMPLATE
1496: if ($text ne '') { $template.='</td></tr></table>' };
1497: return $template;
1498:
1.44 bowersj2 1499: }
1.37 matthew 1500:
1.180 matthew 1501: ###############################################################
1502: ###############################################################
1503:
1.45 matthew 1504: =pod
1505:
1.648 raeburn 1506: =item * &change_content_javascript():
1.256 matthew 1507:
1508: This and the next function allow you to create small sections of an
1509: otherwise static HTML page that you can update on the fly with
1510: Javascript, even in Netscape 4.
1511:
1512: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1513: must be written to the HTML page once. It will prove the Javascript
1514: function "change(name, content)". Calling the change function with the
1515: name of the section
1516: you want to update, matching the name passed to C<changable_area>, and
1517: the new content you want to put in there, will put the content into
1518: that area.
1519:
1520: B<Note>: Netscape 4 only reserves enough space for the changable area
1521: to contain room for the original contents. You need to "make space"
1522: for whatever changes you wish to make, and be B<sure> to check your
1523: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1524: it's adequate for updating a one-line status display, but little more.
1525: This script will set the space to 100% width, so you only need to
1526: worry about height in Netscape 4.
1527:
1528: Modern browsers are much less limiting, and if you can commit to the
1529: user not using Netscape 4, this feature may be used freely with
1530: pretty much any HTML.
1531:
1532: =cut
1533:
1534: sub change_content_javascript {
1535: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1536: if ($env{'browser.type'} eq 'netscape' &&
1537: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1538: return (<<NETSCAPE4);
1539: function change(name, content) {
1540: doc = document.layers[name+"___escape"].layers[0].document;
1541: doc.open();
1542: doc.write(content);
1543: doc.close();
1544: }
1545: NETSCAPE4
1546: } else {
1547: # Otherwise, we need to use semi-standards-compliant code
1548: # (technically, "innerHTML" isn't standard but the equivalent
1549: # is really scary, and every useful browser supports it
1550: return (<<DOMBASED);
1551: function change(name, content) {
1552: element = document.getElementById(name);
1553: element.innerHTML = content;
1554: }
1555: DOMBASED
1556: }
1557: }
1558:
1559: =pod
1560:
1.648 raeburn 1561: =item * &changable_area($name,$origContent):
1.256 matthew 1562:
1563: This provides a "changable area" that can be modified on the fly via
1564: the Javascript code provided in C<change_content_javascript>. $name is
1565: the name you will use to reference the area later; do not repeat the
1566: same name on a given HTML page more then once. $origContent is what
1567: the area will originally contain, which can be left blank.
1568:
1569: =cut
1570:
1571: sub changable_area {
1572: my ($name, $origContent) = @_;
1573:
1.258 albertel 1574: if ($env{'browser.type'} eq 'netscape' &&
1575: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1576: # If this is netscape 4, we need to use the Layer tag
1577: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1578: } else {
1579: return "<span id='$name'>$origContent</span>";
1580: }
1581: }
1582:
1583: =pod
1584:
1.648 raeburn 1585: =item * &viewport_geometry_js
1.590 raeburn 1586:
1587: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1588:
1589: =cut
1590:
1591:
1592: sub viewport_geometry_js {
1593: return <<"GEOMETRY";
1594: var Geometry = {};
1595: function init_geometry() {
1596: if (Geometry.init) { return };
1597: Geometry.init=1;
1598: if (window.innerHeight) {
1599: Geometry.getViewportHeight = function() { return window.innerHeight; };
1600: Geometry.getViewportWidth = function() { return window.innerWidth; };
1601: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1602: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1603: }
1604: else if (document.documentElement && document.documentElement.clientHeight) {
1605: Geometry.getViewportHeight =
1606: function() { return document.documentElement.clientHeight; };
1607: Geometry.getViewportWidth =
1608: function() { return document.documentElement.clientWidth; };
1609:
1610: Geometry.getHorizontalScroll =
1611: function() { return document.documentElement.scrollLeft; };
1612: Geometry.getVerticalScroll =
1613: function() { return document.documentElement.scrollTop; };
1614: }
1615: else if (document.body.clientHeight) {
1616: Geometry.getViewportHeight =
1617: function() { return document.body.clientHeight; };
1618: Geometry.getViewportWidth =
1619: function() { return document.body.clientWidth; };
1620: Geometry.getHorizontalScroll =
1621: function() { return document.body.scrollLeft; };
1622: Geometry.getVerticalScroll =
1623: function() { return document.body.scrollTop; };
1624: }
1625: }
1626:
1627: GEOMETRY
1628: }
1629:
1630: =pod
1631:
1.648 raeburn 1632: =item * &viewport_size_js()
1.590 raeburn 1633:
1634: 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.
1635:
1636: =cut
1637:
1638: sub viewport_size_js {
1639: my $geometry = &viewport_geometry_js();
1640: return <<"DIMS";
1641:
1642: $geometry
1643:
1644: function getViewportDims(width,height) {
1645: init_geometry();
1646: width.value = Geometry.getViewportWidth();
1647: height.value = Geometry.getViewportHeight();
1648: return;
1649: }
1650:
1651: DIMS
1652: }
1653:
1654: =pod
1655:
1.648 raeburn 1656: =item * &resize_textarea_js()
1.565 albertel 1657:
1658: emits the needed javascript to resize a textarea to be as big as possible
1659:
1660: creates a function resize_textrea that takes two IDs first should be
1661: the id of the element to resize, second should be the id of a div that
1662: surrounds everything that comes after the textarea, this routine needs
1663: to be attached to the <body> for the onload and onresize events.
1664:
1.648 raeburn 1665: =back
1.565 albertel 1666:
1667: =cut
1668:
1669: sub resize_textarea_js {
1.590 raeburn 1670: my $geometry = &viewport_geometry_js();
1.565 albertel 1671: return <<"RESIZE";
1672: <script type="text/javascript">
1.824 bisitz 1673: // <![CDATA[
1.590 raeburn 1674: $geometry
1.565 albertel 1675:
1.588 albertel 1676: function getX(element) {
1677: var x = 0;
1678: while (element) {
1679: x += element.offsetLeft;
1680: element = element.offsetParent;
1681: }
1682: return x;
1683: }
1684: function getY(element) {
1685: var y = 0;
1686: while (element) {
1687: y += element.offsetTop;
1688: element = element.offsetParent;
1689: }
1690: return y;
1691: }
1692:
1693:
1.565 albertel 1694: function resize_textarea(textarea_id,bottom_id) {
1695: init_geometry();
1696: var textarea = document.getElementById(textarea_id);
1697: //alert(textarea);
1698:
1.588 albertel 1699: var textarea_top = getY(textarea);
1.565 albertel 1700: var textarea_height = textarea.offsetHeight;
1701: var bottom = document.getElementById(bottom_id);
1.588 albertel 1702: var bottom_top = getY(bottom);
1.565 albertel 1703: var bottom_height = bottom.offsetHeight;
1704: var window_height = Geometry.getViewportHeight();
1.588 albertel 1705: var fudge = 23;
1.565 albertel 1706: var new_height = window_height-fudge-textarea_top-bottom_height;
1707: if (new_height < 300) {
1708: new_height = 300;
1709: }
1710: textarea.style.height=new_height+'px';
1711: }
1.824 bisitz 1712: // ]]>
1.565 albertel 1713: </script>
1714: RESIZE
1715:
1716: }
1717:
1718: =pod
1719:
1.256 matthew 1720: =head1 Excel and CSV file utility routines
1721:
1722: =over 4
1723:
1724: =cut
1725:
1726: ###############################################################
1727: ###############################################################
1728:
1729: =pod
1730:
1.648 raeburn 1731: =item * &csv_translate($text)
1.37 matthew 1732:
1.185 www 1733: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1734: format.
1735:
1736: =cut
1737:
1.180 matthew 1738: ###############################################################
1739: ###############################################################
1.37 matthew 1740: sub csv_translate {
1741: my $text = shift;
1742: $text =~ s/\"/\"\"/g;
1.209 albertel 1743: $text =~ s/\n/ /g;
1.37 matthew 1744: return $text;
1745: }
1.180 matthew 1746:
1747: ###############################################################
1748: ###############################################################
1749:
1750: =pod
1751:
1.648 raeburn 1752: =item * &define_excel_formats()
1.180 matthew 1753:
1754: Define some commonly used Excel cell formats.
1755:
1756: Currently supported formats:
1757:
1758: =over 4
1759:
1760: =item header
1761:
1762: =item bold
1763:
1764: =item h1
1765:
1766: =item h2
1767:
1768: =item h3
1769:
1.256 matthew 1770: =item h4
1771:
1772: =item i
1773:
1.180 matthew 1774: =item date
1775:
1776: =back
1777:
1778: Inputs: $workbook
1779:
1780: Returns: $format, a hash reference.
1781:
1.1057 foxr 1782:
1.180 matthew 1783: =cut
1784:
1785: ###############################################################
1786: ###############################################################
1787: sub define_excel_formats {
1788: my ($workbook) = @_;
1789: my $format;
1790: $format->{'header'} = $workbook->add_format(bold => 1,
1791: bottom => 1,
1792: align => 'center');
1793: $format->{'bold'} = $workbook->add_format(bold=>1);
1794: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1795: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1796: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1797: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1798: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1799: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1800: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1801: return $format;
1802: }
1803:
1804: ###############################################################
1805: ###############################################################
1.113 bowersj2 1806:
1807: =pod
1808:
1.648 raeburn 1809: =item * &create_workbook()
1.255 matthew 1810:
1811: Create an Excel worksheet. If it fails, output message on the
1812: request object and return undefs.
1813:
1814: Inputs: Apache request object
1815:
1816: Returns (undef) on failure,
1817: Excel worksheet object, scalar with filename, and formats
1818: from &Apache::loncommon::define_excel_formats on success
1819:
1820: =cut
1821:
1822: ###############################################################
1823: ###############################################################
1824: sub create_workbook {
1825: my ($r) = @_;
1826: #
1827: # Create the excel spreadsheet
1828: my $filename = '/prtspool/'.
1.258 albertel 1829: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1830: time.'_'.rand(1000000000).'.xls';
1831: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1832: if (! defined($workbook)) {
1833: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1834: $r->print(
1835: '<p class="LC_error">'
1836: .&mt('Problems occurred in creating the new Excel file.')
1837: .' '.&mt('This error has been logged.')
1838: .' '.&mt('Please alert your LON-CAPA administrator.')
1839: .'</p>'
1840: );
1.255 matthew 1841: return (undef);
1842: }
1843: #
1.1014 foxr 1844: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1845: #
1846: my $format = &Apache::loncommon::define_excel_formats($workbook);
1847: return ($workbook,$filename,$format);
1848: }
1849:
1850: ###############################################################
1851: ###############################################################
1852:
1853: =pod
1854:
1.648 raeburn 1855: =item * &create_text_file()
1.113 bowersj2 1856:
1.542 raeburn 1857: Create a file to write to and eventually make available to the user.
1.256 matthew 1858: If file creation fails, outputs an error message on the request object and
1859: return undefs.
1.113 bowersj2 1860:
1.256 matthew 1861: Inputs: Apache request object, and file suffix
1.113 bowersj2 1862:
1.256 matthew 1863: Returns (undef) on failure,
1864: Filehandle and filename on success.
1.113 bowersj2 1865:
1866: =cut
1867:
1.256 matthew 1868: ###############################################################
1869: ###############################################################
1870: sub create_text_file {
1871: my ($r,$suffix) = @_;
1872: if (! defined($suffix)) { $suffix = 'txt'; };
1873: my $fh;
1874: my $filename = '/prtspool/'.
1.258 albertel 1875: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1876: time.'_'.rand(1000000000).'.'.$suffix;
1877: $fh = Apache::File->new('>/home/httpd'.$filename);
1878: if (! defined($fh)) {
1879: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1880: $r->print(
1881: '<p class="LC_error">'
1882: .&mt('Problems occurred in creating the output file.')
1883: .' '.&mt('This error has been logged.')
1884: .' '.&mt('Please alert your LON-CAPA administrator.')
1885: .'</p>'
1886: );
1.113 bowersj2 1887: }
1.256 matthew 1888: return ($fh,$filename)
1.113 bowersj2 1889: }
1890:
1891:
1.256 matthew 1892: =pod
1.113 bowersj2 1893:
1894: =back
1895:
1896: =cut
1.37 matthew 1897:
1898: ###############################################################
1.33 matthew 1899: ## Home server <option> list generating code ##
1900: ###############################################################
1.35 matthew 1901:
1.169 www 1902: # ------------------------------------------
1903:
1904: sub domain_select {
1905: my ($name,$value,$multiple)=@_;
1906: my %domains=map {
1.514 albertel 1907: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1908: } &Apache::lonnet::all_domains();
1.169 www 1909: if ($multiple) {
1910: $domains{''}=&mt('Any domain');
1.550 albertel 1911: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1912: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1913: } else {
1.550 albertel 1914: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1915: return &select_form($name,$value,\%domains);
1.169 www 1916: }
1917: }
1918:
1.282 albertel 1919: #-------------------------------------------
1920:
1921: =pod
1922:
1.519 raeburn 1923: =head1 Routines for form select boxes
1924:
1925: =over 4
1926:
1.648 raeburn 1927: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1928:
1929: Returns a string containing a <select> element int multiple mode
1930:
1931:
1932: Args:
1933: $name - name of the <select> element
1.506 raeburn 1934: $value - scalar or array ref of values that should already be selected
1.282 albertel 1935: $size - number of rows long the select element is
1.283 albertel 1936: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1937: (shown text should already have been &mt())
1.506 raeburn 1938: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1939:
1.282 albertel 1940: =cut
1941:
1942: #-------------------------------------------
1.169 www 1943: sub multiple_select_form {
1.284 albertel 1944: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1945: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1946: my $output='';
1.191 matthew 1947: if (! defined($size)) {
1948: $size = 4;
1.283 albertel 1949: if (scalar(keys(%$hash))<4) {
1950: $size = scalar(keys(%$hash));
1.191 matthew 1951: }
1952: }
1.734 bisitz 1953: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1954: my @order;
1.506 raeburn 1955: if (ref($order) eq 'ARRAY') {
1956: @order = @{$order};
1957: } else {
1958: @order = sort(keys(%$hash));
1.501 banghart 1959: }
1960: if (exists($$hash{'select_form_order'})) {
1961: @order = @{$$hash{'select_form_order'}};
1962: }
1963:
1.284 albertel 1964: foreach my $key (@order) {
1.356 albertel 1965: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1966: $output.='selected="selected" ' if ($selected{$key});
1967: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1968: }
1969: $output.="</select>\n";
1970: return $output;
1971: }
1972:
1.88 www 1973: #-------------------------------------------
1974:
1975: =pod
1976:
1.970 raeburn 1977: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1978:
1979: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1980: allow a user to select options from a ref to a hash containing:
1981: option_name => displayed text. An optional $onchange can include
1982: a javascript onchange item, e.g., onchange="this.form.submit();"
1983:
1.88 www 1984: See lonrights.pm for an example invocation and use.
1985:
1986: =cut
1987:
1988: #-------------------------------------------
1989: sub select_form {
1.970 raeburn 1990: my ($def,$name,$hashref,$onchange) = @_;
1991: return unless (ref($hashref) eq 'HASH');
1992: if ($onchange) {
1993: $onchange = ' onchange="'.$onchange.'"';
1994: }
1995: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 1996: my @keys;
1.970 raeburn 1997: if (exists($hashref->{'select_form_order'})) {
1998: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 1999: } else {
1.970 raeburn 2000: @keys=sort(keys(%{$hashref}));
1.128 albertel 2001: }
1.356 albertel 2002: foreach my $key (@keys) {
2003: $selectform.=
2004: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2005: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2006: ">".$hashref->{$key}."</option>\n";
1.88 www 2007: }
2008: $selectform.="</select>";
2009: return $selectform;
2010: }
2011:
1.475 www 2012: # For display filters
2013:
2014: sub display_filter {
1.1074 raeburn 2015: my ($context) = @_;
1.475 www 2016: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2017: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2018: my $phraseinput = 'hidden';
2019: my $includeinput = 'hidden';
2020: my ($checked,$includetypestext);
2021: if ($env{'form.displayfilter'} eq 'containing') {
2022: $phraseinput = 'text';
2023: if ($context eq 'parmslog') {
2024: $includeinput = 'checkbox';
2025: if ($env{'form.includetypes'}) {
2026: $checked = ' checked="checked"';
2027: }
2028: $includetypestext = &mt('Include parameter types');
2029: }
2030: } else {
2031: $includetypestext = ' ';
2032: }
2033: my ($additional,$secondid,$thirdid);
2034: if ($context eq 'parmslog') {
2035: $additional =
2036: '<label><input type="'.$includeinput.'" name="includetypes"'.
2037: $checked.' name="includetypes" value="1" id="includetypes" />'.
2038: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2039: '</label>';
2040: $secondid = 'includetypes';
2041: $thirdid = 'includetypestext';
2042: }
2043: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2044: '$secondid','$thirdid')";
2045: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2046: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2047: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2048: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2049: &mt('Filter: [_1]',
1.477 www 2050: &select_form($env{'form.displayfilter'},
2051: 'displayfilter',
1.970 raeburn 2052: {'currentfolder' => 'Current folder/page',
1.477 www 2053: 'containing' => 'Containing phrase',
1.1074 raeburn 2054: 'none' => 'None'},$onchange)).' '.
2055: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2056: &HTML::Entities::encode($env{'form.containingphrase'}).
2057: '" />'.$additional;
2058: }
2059:
2060: sub display_filter_js {
2061: my $includetext = &mt('Include parameter types');
2062: return <<"ENDJS";
2063:
2064: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2065: var firstType = 'hidden';
2066: if (setter.options[setter.selectedIndex].value == 'containing') {
2067: firstType = 'text';
2068: }
2069: firstObject = document.getElementById(firstid);
2070: if (typeof(firstObject) == 'object') {
2071: if (firstObject.type != firstType) {
2072: changeInputType(firstObject,firstType);
2073: }
2074: }
2075: if (context == 'parmslog') {
2076: var secondType = 'hidden';
2077: if (firstType == 'text') {
2078: secondType = 'checkbox';
2079: }
2080: secondObject = document.getElementById(secondid);
2081: if (typeof(secondObject) == 'object') {
2082: if (secondObject.type != secondType) {
2083: changeInputType(secondObject,secondType);
2084: }
2085: }
2086: var textItem = document.getElementById(thirdid);
2087: var currtext = textItem.innerHTML;
2088: var newtext;
2089: if (firstType == 'text') {
2090: newtext = '$includetext';
2091: } else {
2092: newtext = ' ';
2093: }
2094: if (currtext != newtext) {
2095: textItem.innerHTML = newtext;
2096: }
2097: }
2098: return;
2099: }
2100:
2101: function changeInputType(oldObject,newType) {
2102: var newObject = document.createElement('input');
2103: newObject.type = newType;
2104: if (oldObject.size) {
2105: newObject.size = oldObject.size;
2106: }
2107: if (oldObject.value) {
2108: newObject.value = oldObject.value;
2109: }
2110: if (oldObject.name) {
2111: newObject.name = oldObject.name;
2112: }
2113: if (oldObject.id) {
2114: newObject.id = oldObject.id;
2115: }
2116: oldObject.parentNode.replaceChild(newObject,oldObject);
2117: return;
2118: }
2119:
2120: ENDJS
1.475 www 2121: }
2122:
1.167 www 2123: sub gradeleveldescription {
2124: my $gradelevel=shift;
2125: my %gradelevels=(0 => 'Not specified',
2126: 1 => 'Grade 1',
2127: 2 => 'Grade 2',
2128: 3 => 'Grade 3',
2129: 4 => 'Grade 4',
2130: 5 => 'Grade 5',
2131: 6 => 'Grade 6',
2132: 7 => 'Grade 7',
2133: 8 => 'Grade 8',
2134: 9 => 'Grade 9',
2135: 10 => 'Grade 10',
2136: 11 => 'Grade 11',
2137: 12 => 'Grade 12',
2138: 13 => 'Grade 13',
2139: 14 => '100 Level',
2140: 15 => '200 Level',
2141: 16 => '300 Level',
2142: 17 => '400 Level',
2143: 18 => 'Graduate Level');
2144: return &mt($gradelevels{$gradelevel});
2145: }
2146:
1.163 www 2147: sub select_level_form {
2148: my ($deflevel,$name)=@_;
2149: unless ($deflevel) { $deflevel=0; }
1.167 www 2150: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2151: for (my $i=0; $i<=18; $i++) {
2152: $selectform.="<option value=\"$i\" ".
1.253 albertel 2153: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2154: ">".&gradeleveldescription($i)."</option>\n";
2155: }
2156: $selectform.="</select>";
2157: return $selectform;
1.163 www 2158: }
1.167 www 2159:
1.35 matthew 2160: #-------------------------------------------
2161:
1.45 matthew 2162: =pod
2163:
1.1075.2.42 raeburn 2164: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2165:
2166: Returns a string containing a <select name='$name' size='1'> form to
2167: allow a user to select the domain to preform an operation in.
2168: See loncreateuser.pm for an example invocation and use.
2169:
1.90 www 2170: If the $includeempty flag is set, it also includes an empty choice ("no domain
2171: selected");
2172:
1.743 raeburn 2173: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2174:
1.910 raeburn 2175: 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.
2176:
1.1075.2.36 raeburn 2177: The optional $incdoms is a reference to an array of domains which will be the only available options.
2178:
2179: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2180:
1.35 matthew 2181: =cut
2182:
2183: #-------------------------------------------
1.34 matthew 2184: sub select_dom_form {
1.1075.2.36 raeburn 2185: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2186: if ($onchange) {
1.874 raeburn 2187: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2188: }
1.1075.2.36 raeburn 2189: my (@domains,%exclude);
1.910 raeburn 2190: if (ref($incdoms) eq 'ARRAY') {
2191: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2192: } else {
2193: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2194: }
1.90 www 2195: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2196: if (ref($excdoms) eq 'ARRAY') {
2197: map { $exclude{$_} = 1; } @{$excdoms};
2198: }
1.743 raeburn 2199: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2200: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2201: next if ($exclude{$dom});
1.356 albertel 2202: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2203: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2204: if ($showdomdesc) {
2205: if ($dom ne '') {
2206: my $domdesc = &Apache::lonnet::domain($dom,'description');
2207: if ($domdesc ne '') {
2208: $selectdomain .= ' ('.$domdesc.')';
2209: }
2210: }
2211: }
2212: $selectdomain .= "</option>\n";
1.34 matthew 2213: }
2214: $selectdomain.="</select>";
2215: return $selectdomain;
2216: }
2217:
1.35 matthew 2218: #-------------------------------------------
2219:
1.45 matthew 2220: =pod
2221:
1.648 raeburn 2222: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2223:
1.586 raeburn 2224: input: 4 arguments (two required, two optional) -
2225: $domain - domain of new user
2226: $name - name of form element
2227: $default - Value of 'default' causes a default item to be first
2228: option, and selected by default.
2229: $hide - Value of 'hide' causes hiding of the name of the server,
2230: if 1 server found, or default, if 0 found.
1.594 raeburn 2231: output: returns 2 items:
1.586 raeburn 2232: (a) form element which contains either:
2233: (i) <select name="$name">
2234: <option value="$hostid1">$hostid $servers{$hostid}</option>
2235: <option value="$hostid2">$hostid $servers{$hostid}</option>
2236: </select>
2237: form item if there are multiple library servers in $domain, or
2238: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2239: if there is only one library server in $domain.
2240:
2241: (b) number of library servers found.
2242:
2243: See loncreateuser.pm for example of use.
1.35 matthew 2244:
2245: =cut
2246:
2247: #-------------------------------------------
1.586 raeburn 2248: sub home_server_form_item {
2249: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2250: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2251: my $result;
2252: my $numlib = keys(%servers);
2253: if ($numlib > 1) {
2254: $result .= '<select name="'.$name.'" />'."\n";
2255: if ($default) {
1.804 bisitz 2256: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2257: '</option>'."\n";
2258: }
2259: foreach my $hostid (sort(keys(%servers))) {
2260: $result.= '<option value="'.$hostid.'">'.
2261: $hostid.' '.$servers{$hostid}."</option>\n";
2262: }
2263: $result .= '</select>'."\n";
2264: } elsif ($numlib == 1) {
2265: my $hostid;
2266: foreach my $item (keys(%servers)) {
2267: $hostid = $item;
2268: }
2269: $result .= '<input type="hidden" name="'.$name.'" value="'.
2270: $hostid.'" />';
2271: if (!$hide) {
2272: $result .= $hostid.' '.$servers{$hostid};
2273: }
2274: $result .= "\n";
2275: } elsif ($default) {
2276: $result .= '<input type="hidden" name="'.$name.
2277: '" value="default" />';
2278: if (!$hide) {
2279: $result .= &mt('default');
2280: }
2281: $result .= "\n";
1.33 matthew 2282: }
1.586 raeburn 2283: return ($result,$numlib);
1.33 matthew 2284: }
1.112 bowersj2 2285:
2286: =pod
2287:
1.534 albertel 2288: =back
2289:
1.112 bowersj2 2290: =cut
1.87 matthew 2291:
2292: ###############################################################
1.112 bowersj2 2293: ## Decoding User Agent ##
1.87 matthew 2294: ###############################################################
2295:
2296: =pod
2297:
1.112 bowersj2 2298: =head1 Decoding the User Agent
2299:
2300: =over 4
2301:
2302: =item * &decode_user_agent()
1.87 matthew 2303:
2304: Inputs: $r
2305:
2306: Outputs:
2307:
2308: =over 4
2309:
1.112 bowersj2 2310: =item * $httpbrowser
1.87 matthew 2311:
1.112 bowersj2 2312: =item * $clientbrowser
1.87 matthew 2313:
1.112 bowersj2 2314: =item * $clientversion
1.87 matthew 2315:
1.112 bowersj2 2316: =item * $clientmathml
1.87 matthew 2317:
1.112 bowersj2 2318: =item * $clientunicode
1.87 matthew 2319:
1.112 bowersj2 2320: =item * $clientos
1.87 matthew 2321:
1.1075.2.42 raeburn 2322: =item * $clientmobile
2323:
2324: =item * $clientinfo
2325:
1.87 matthew 2326: =back
2327:
1.157 matthew 2328: =back
2329:
1.87 matthew 2330: =cut
2331:
2332: ###############################################################
2333: ###############################################################
2334: sub decode_user_agent {
1.247 albertel 2335: my ($r)=@_;
1.87 matthew 2336: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2337: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2338: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2339: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2340: my $clientbrowser='unknown';
2341: my $clientversion='0';
2342: my $clientmathml='';
2343: my $clientunicode='0';
1.1075.2.42 raeburn 2344: my $clientmobile=0;
1.87 matthew 2345: for (my $i=0;$i<=$#browsertype;$i++) {
2346: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2347: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2348: $clientbrowser=$bname;
2349: $httpbrowser=~/$vreg/i;
2350: $clientversion=$1;
2351: $clientmathml=($clientversion>=$minv);
2352: $clientunicode=($clientversion>=$univ);
2353: }
2354: }
2355: my $clientos='unknown';
1.1075.2.42 raeburn 2356: my $clientinfo;
1.87 matthew 2357: if (($httpbrowser=~/linux/i) ||
2358: ($httpbrowser=~/unix/i) ||
2359: ($httpbrowser=~/ux/i) ||
2360: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2361: if (($httpbrowser=~/vax/i) ||
2362: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2363: if ($httpbrowser=~/next/i) { $clientos='next'; }
2364: if (($httpbrowser=~/mac/i) ||
2365: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2366: if ($httpbrowser=~/win/i) { $clientos='win'; }
2367: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2368: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2369: $clientmobile=lc($1);
2370: }
2371: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2372: $clientinfo = 'firefox-'.$1;
2373: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2374: $clientinfo = 'chromeframe-'.$1;
2375: }
1.87 matthew 2376: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42 raeburn 2377: $clientunicode,$clientos,$clientmobile,$clientinfo);
1.87 matthew 2378: }
2379:
1.32 matthew 2380: ###############################################################
2381: ## Authentication changing form generation subroutines ##
2382: ###############################################################
2383: ##
2384: ## All of the authform_xxxxxxx subroutines take their inputs in a
2385: ## hash, and have reasonable default values.
2386: ##
2387: ## formname = the name given in the <form> tag.
1.35 matthew 2388: #-------------------------------------------
2389:
1.45 matthew 2390: =pod
2391:
1.112 bowersj2 2392: =head1 Authentication Routines
2393:
2394: =over 4
2395:
1.648 raeburn 2396: =item * &authform_xxxxxx()
1.35 matthew 2397:
2398: The authform_xxxxxx subroutines provide javascript and html forms which
2399: handle some of the conveniences required for authentication forms.
2400: This is not an optimal method, but it works.
2401:
2402: =over 4
2403:
1.112 bowersj2 2404: =item * authform_header
1.35 matthew 2405:
1.112 bowersj2 2406: =item * authform_authorwarning
1.35 matthew 2407:
1.112 bowersj2 2408: =item * authform_nochange
1.35 matthew 2409:
1.112 bowersj2 2410: =item * authform_kerberos
1.35 matthew 2411:
1.112 bowersj2 2412: =item * authform_internal
1.35 matthew 2413:
1.112 bowersj2 2414: =item * authform_filesystem
1.35 matthew 2415:
2416: =back
2417:
1.648 raeburn 2418: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2419:
1.35 matthew 2420: =cut
2421:
2422: #-------------------------------------------
1.32 matthew 2423: sub authform_header{
2424: my %in = (
2425: formname => 'cu',
1.80 albertel 2426: kerb_def_dom => '',
1.32 matthew 2427: @_,
2428: );
2429: $in{'formname'} = 'document.' . $in{'formname'};
2430: my $result='';
1.80 albertel 2431:
2432: #---------------------------------------------- Code for upper case translation
2433: my $Javascript_toUpperCase;
2434: unless ($in{kerb_def_dom}) {
2435: $Javascript_toUpperCase =<<"END";
2436: switch (choice) {
2437: case 'krb': currentform.elements[choicearg].value =
2438: currentform.elements[choicearg].value.toUpperCase();
2439: break;
2440: default:
2441: }
2442: END
2443: } else {
2444: $Javascript_toUpperCase = "";
2445: }
2446:
1.165 raeburn 2447: my $radioval = "'nochange'";
1.591 raeburn 2448: if (defined($in{'curr_authtype'})) {
2449: if ($in{'curr_authtype'} ne '') {
2450: $radioval = "'".$in{'curr_authtype'}."arg'";
2451: }
1.174 matthew 2452: }
1.165 raeburn 2453: my $argfield = 'null';
1.591 raeburn 2454: if (defined($in{'mode'})) {
1.165 raeburn 2455: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2456: if (defined($in{'curr_autharg'})) {
2457: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2458: $argfield = "'$in{'curr_autharg'}'";
2459: }
2460: }
2461: }
2462: }
2463:
1.32 matthew 2464: $result.=<<"END";
2465: var current = new Object();
1.165 raeburn 2466: current.radiovalue = $radioval;
2467: current.argfield = $argfield;
1.32 matthew 2468:
2469: function changed_radio(choice,currentform) {
2470: var choicearg = choice + 'arg';
2471: // If a radio button in changed, we need to change the argfield
2472: if (current.radiovalue != choice) {
2473: current.radiovalue = choice;
2474: if (current.argfield != null) {
2475: currentform.elements[current.argfield].value = '';
2476: }
2477: if (choice == 'nochange') {
2478: current.argfield = null;
2479: } else {
2480: current.argfield = choicearg;
2481: switch(choice) {
2482: case 'krb':
2483: currentform.elements[current.argfield].value =
2484: "$in{'kerb_def_dom'}";
2485: break;
2486: default:
2487: break;
2488: }
2489: }
2490: }
2491: return;
2492: }
1.22 www 2493:
1.32 matthew 2494: function changed_text(choice,currentform) {
2495: var choicearg = choice + 'arg';
2496: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2497: $Javascript_toUpperCase
1.32 matthew 2498: // clear old field
2499: if ((current.argfield != choicearg) && (current.argfield != null)) {
2500: currentform.elements[current.argfield].value = '';
2501: }
2502: current.argfield = choicearg;
2503: }
2504: set_auth_radio_buttons(choice,currentform);
2505: return;
1.20 www 2506: }
1.32 matthew 2507:
2508: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2509: var numauthchoices = currentform.login.length;
2510: if (typeof numauthchoices == "undefined") {
2511: return;
2512: }
1.32 matthew 2513: var i=0;
1.986 raeburn 2514: while (i < numauthchoices) {
1.32 matthew 2515: if (currentform.login[i].value == newvalue) { break; }
2516: i++;
2517: }
1.986 raeburn 2518: if (i == numauthchoices) {
1.32 matthew 2519: return;
2520: }
2521: current.radiovalue = newvalue;
2522: currentform.login[i].checked = true;
2523: return;
2524: }
2525: END
2526: return $result;
2527: }
2528:
1.1075.2.20 raeburn 2529: sub authform_authorwarning {
1.32 matthew 2530: my $result='';
1.144 matthew 2531: $result='<i>'.
2532: &mt('As a general rule, only authors or co-authors should be '.
2533: 'filesystem authenticated '.
2534: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2535: return $result;
2536: }
2537:
1.1075.2.20 raeburn 2538: sub authform_nochange {
1.32 matthew 2539: my %in = (
2540: formname => 'document.cu',
2541: kerb_def_dom => 'MSU.EDU',
2542: @_,
2543: );
1.1075.2.20 raeburn 2544: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2545: my $result;
1.1075.2.20 raeburn 2546: if (!$authnum) {
2547: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2548: } else {
2549: $result = '<label>'.&mt('[_1] Do not change login data',
2550: '<input type="radio" name="login" value="nochange" '.
2551: 'checked="checked" onclick="'.
1.281 albertel 2552: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2553: '</label>';
1.586 raeburn 2554: }
1.32 matthew 2555: return $result;
2556: }
2557:
1.591 raeburn 2558: sub authform_kerberos {
1.32 matthew 2559: my %in = (
2560: formname => 'document.cu',
2561: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2562: kerb_def_auth => 'krb4',
1.32 matthew 2563: @_,
2564: );
1.586 raeburn 2565: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2566: $autharg,$jscall);
1.1075.2.20 raeburn 2567: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2568: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2569: $check5 = ' checked="checked"';
1.80 albertel 2570: } else {
1.772 bisitz 2571: $check4 = ' checked="checked"';
1.80 albertel 2572: }
1.165 raeburn 2573: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2574: if (defined($in{'curr_authtype'})) {
2575: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2576: $krbcheck = ' checked="checked"';
1.623 raeburn 2577: if (defined($in{'mode'})) {
2578: if ($in{'mode'} eq 'modifyuser') {
2579: $krbcheck = '';
2580: }
2581: }
1.591 raeburn 2582: if (defined($in{'curr_kerb_ver'})) {
2583: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2584: $check5 = ' checked="checked"';
1.591 raeburn 2585: $check4 = '';
2586: } else {
1.772 bisitz 2587: $check4 = ' checked="checked"';
1.591 raeburn 2588: $check5 = '';
2589: }
1.586 raeburn 2590: }
1.591 raeburn 2591: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2592: $krbarg = $in{'curr_autharg'};
2593: }
1.586 raeburn 2594: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2595: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2596: $result =
2597: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2598: $in{'curr_autharg'},$krbver);
2599: } else {
2600: $result =
2601: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2602: }
2603: return $result;
2604: }
2605: }
2606: } else {
2607: if ($authnum == 1) {
1.784 bisitz 2608: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2609: }
2610: }
1.586 raeburn 2611: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2612: return;
1.587 raeburn 2613: } elsif ($authtype eq '') {
1.591 raeburn 2614: if (defined($in{'mode'})) {
1.587 raeburn 2615: if ($in{'mode'} eq 'modifycourse') {
2616: if ($authnum == 1) {
1.1075.2.20 raeburn 2617: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2618: }
2619: }
2620: }
1.586 raeburn 2621: }
2622: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2623: if ($authtype eq '') {
2624: $authtype = '<input type="radio" name="login" value="krb" '.
2625: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2626: $krbcheck.' />';
2627: }
2628: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2629: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2630: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2631: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2632: $in{'curr_authtype'} eq 'krb4')) {
2633: $result .= &mt
1.144 matthew 2634: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2635: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2636: '<label>'.$authtype,
1.281 albertel 2637: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2638: 'value="'.$krbarg.'" '.
1.144 matthew 2639: 'onchange="'.$jscall.'" />',
1.281 albertel 2640: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2641: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2642: '</label>');
1.586 raeburn 2643: } elsif ($can_assign{'krb4'}) {
2644: $result .= &mt
2645: ('[_1] Kerberos authenticated with domain [_2] '.
2646: '[_3] Version 4 [_4]',
2647: '<label>'.$authtype,
2648: '</label><input type="text" size="10" name="krbarg" '.
2649: 'value="'.$krbarg.'" '.
2650: 'onchange="'.$jscall.'" />',
2651: '<label><input type="hidden" name="krbver" value="4" />',
2652: '</label>');
2653: } elsif ($can_assign{'krb5'}) {
2654: $result .= &mt
2655: ('[_1] Kerberos authenticated with domain [_2] '.
2656: '[_3] Version 5 [_4]',
2657: '<label>'.$authtype,
2658: '</label><input type="text" size="10" name="krbarg" '.
2659: 'value="'.$krbarg.'" '.
2660: 'onchange="'.$jscall.'" />',
2661: '<label><input type="hidden" name="krbver" value="5" />',
2662: '</label>');
2663: }
1.32 matthew 2664: return $result;
2665: }
2666:
1.1075.2.20 raeburn 2667: sub authform_internal {
1.586 raeburn 2668: my %in = (
1.32 matthew 2669: formname => 'document.cu',
2670: kerb_def_dom => 'MSU.EDU',
2671: @_,
2672: );
1.586 raeburn 2673: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2674: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2675: if (defined($in{'curr_authtype'})) {
2676: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2677: if ($can_assign{'int'}) {
1.772 bisitz 2678: $intcheck = 'checked="checked" ';
1.623 raeburn 2679: if (defined($in{'mode'})) {
2680: if ($in{'mode'} eq 'modifyuser') {
2681: $intcheck = '';
2682: }
2683: }
1.591 raeburn 2684: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2685: $intarg = $in{'curr_autharg'};
2686: }
2687: } else {
2688: $result = &mt('Currently internally authenticated.');
2689: return $result;
1.165 raeburn 2690: }
2691: }
1.586 raeburn 2692: } else {
2693: if ($authnum == 1) {
1.784 bisitz 2694: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2695: }
2696: }
2697: if (!$can_assign{'int'}) {
2698: return;
1.587 raeburn 2699: } elsif ($authtype eq '') {
1.591 raeburn 2700: if (defined($in{'mode'})) {
1.587 raeburn 2701: if ($in{'mode'} eq 'modifycourse') {
2702: if ($authnum == 1) {
1.1075.2.20 raeburn 2703: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2704: }
2705: }
2706: }
1.165 raeburn 2707: }
1.586 raeburn 2708: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2709: if ($authtype eq '') {
2710: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2711: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2712: }
1.605 bisitz 2713: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2714: $intarg.'" onchange="'.$jscall.'" />';
2715: $result = &mt
1.144 matthew 2716: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2717: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2718: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2719: return $result;
2720: }
2721:
1.1075.2.20 raeburn 2722: sub authform_local {
1.32 matthew 2723: my %in = (
2724: formname => 'document.cu',
2725: kerb_def_dom => 'MSU.EDU',
2726: @_,
2727: );
1.586 raeburn 2728: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2729: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2730: if (defined($in{'curr_authtype'})) {
2731: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2732: if ($can_assign{'loc'}) {
1.772 bisitz 2733: $loccheck = 'checked="checked" ';
1.623 raeburn 2734: if (defined($in{'mode'})) {
2735: if ($in{'mode'} eq 'modifyuser') {
2736: $loccheck = '';
2737: }
2738: }
1.591 raeburn 2739: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2740: $locarg = $in{'curr_autharg'};
2741: }
2742: } else {
2743: $result = &mt('Currently using local (institutional) authentication.');
2744: return $result;
1.165 raeburn 2745: }
2746: }
1.586 raeburn 2747: } else {
2748: if ($authnum == 1) {
1.784 bisitz 2749: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2750: }
2751: }
2752: if (!$can_assign{'loc'}) {
2753: return;
1.587 raeburn 2754: } elsif ($authtype eq '') {
1.591 raeburn 2755: if (defined($in{'mode'})) {
1.587 raeburn 2756: if ($in{'mode'} eq 'modifycourse') {
2757: if ($authnum == 1) {
1.1075.2.20 raeburn 2758: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2759: }
2760: }
2761: }
1.165 raeburn 2762: }
1.586 raeburn 2763: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2764: if ($authtype eq '') {
2765: $authtype = '<input type="radio" name="login" value="loc" '.
2766: $loccheck.' onchange="'.$jscall.'" onclick="'.
2767: $jscall.'" />';
2768: }
2769: $autharg = '<input type="text" size="10" name="locarg" value="'.
2770: $locarg.'" onchange="'.$jscall.'" />';
2771: $result = &mt('[_1] Local Authentication with argument [_2]',
2772: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2773: return $result;
2774: }
2775:
1.1075.2.20 raeburn 2776: sub authform_filesystem {
1.32 matthew 2777: my %in = (
2778: formname => 'document.cu',
2779: kerb_def_dom => 'MSU.EDU',
2780: @_,
2781: );
1.586 raeburn 2782: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2783: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2784: if (defined($in{'curr_authtype'})) {
2785: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2786: if ($can_assign{'fsys'}) {
1.772 bisitz 2787: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2788: if (defined($in{'mode'})) {
2789: if ($in{'mode'} eq 'modifyuser') {
2790: $fsyscheck = '';
2791: }
2792: }
1.586 raeburn 2793: } else {
2794: $result = &mt('Currently Filesystem Authenticated.');
2795: return $result;
2796: }
2797: }
2798: } else {
2799: if ($authnum == 1) {
1.784 bisitz 2800: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2801: }
2802: }
2803: if (!$can_assign{'fsys'}) {
2804: return;
1.587 raeburn 2805: } elsif ($authtype eq '') {
1.591 raeburn 2806: if (defined($in{'mode'})) {
1.587 raeburn 2807: if ($in{'mode'} eq 'modifycourse') {
2808: if ($authnum == 1) {
1.1075.2.20 raeburn 2809: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2810: }
2811: }
2812: }
1.586 raeburn 2813: }
2814: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2815: if ($authtype eq '') {
2816: $authtype = '<input type="radio" name="login" value="fsys" '.
2817: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2818: $jscall.'" />';
2819: }
2820: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2821: ' onchange="'.$jscall.'" />';
2822: $result = &mt
1.144 matthew 2823: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2824: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2825: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2826: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2827: 'onchange="'.$jscall.'" />');
1.32 matthew 2828: return $result;
2829: }
2830:
1.586 raeburn 2831: sub get_assignable_auth {
2832: my ($dom) = @_;
2833: if ($dom eq '') {
2834: $dom = $env{'request.role.domain'};
2835: }
2836: my %can_assign = (
2837: krb4 => 1,
2838: krb5 => 1,
2839: int => 1,
2840: loc => 1,
2841: );
2842: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2843: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2844: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2845: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2846: my $context;
2847: if ($env{'request.role'} =~ /^au/) {
2848: $context = 'author';
2849: } elsif ($env{'request.role'} =~ /^dc/) {
2850: $context = 'domain';
2851: } elsif ($env{'request.course.id'}) {
2852: $context = 'course';
2853: }
2854: if ($context) {
2855: if (ref($authhash->{$context}) eq 'HASH') {
2856: %can_assign = %{$authhash->{$context}};
2857: }
2858: }
2859: }
2860: }
2861: my $authnum = 0;
2862: foreach my $key (keys(%can_assign)) {
2863: if ($can_assign{$key}) {
2864: $authnum ++;
2865: }
2866: }
2867: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2868: $authnum --;
2869: }
2870: return ($authnum,%can_assign);
2871: }
2872:
1.80 albertel 2873: ###############################################################
2874: ## Get Kerberos Defaults for Domain ##
2875: ###############################################################
2876: ##
2877: ## Returns default kerberos version and an associated argument
2878: ## as listed in file domain.tab. If not listed, provides
2879: ## appropriate default domain and kerberos version.
2880: ##
2881: #-------------------------------------------
2882:
2883: =pod
2884:
1.648 raeburn 2885: =item * &get_kerberos_defaults()
1.80 albertel 2886:
2887: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2888: version and domain. If not found, it defaults to version 4 and the
2889: domain of the server.
1.80 albertel 2890:
1.648 raeburn 2891: =over 4
2892:
1.80 albertel 2893: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2894:
1.648 raeburn 2895: =back
2896:
2897: =back
2898:
1.80 albertel 2899: =cut
2900:
2901: #-------------------------------------------
2902: sub get_kerberos_defaults {
2903: my $domain=shift;
1.641 raeburn 2904: my ($krbdef,$krbdefdom);
2905: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2906: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2907: $krbdef = $domdefaults{'auth_def'};
2908: $krbdefdom = $domdefaults{'auth_arg_def'};
2909: } else {
1.80 albertel 2910: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2911: my $krbdefdom=$1;
2912: $krbdefdom=~tr/a-z/A-Z/;
2913: $krbdef = "krb4";
2914: }
2915: return ($krbdef,$krbdefdom);
2916: }
1.112 bowersj2 2917:
1.32 matthew 2918:
1.46 matthew 2919: ###############################################################
2920: ## Thesaurus Functions ##
2921: ###############################################################
1.20 www 2922:
1.46 matthew 2923: =pod
1.20 www 2924:
1.112 bowersj2 2925: =head1 Thesaurus Functions
2926:
2927: =over 4
2928:
1.648 raeburn 2929: =item * &initialize_keywords()
1.46 matthew 2930:
2931: Initializes the package variable %Keywords if it is empty. Uses the
2932: package variable $thesaurus_db_file.
2933:
2934: =cut
2935:
2936: ###################################################
2937:
2938: sub initialize_keywords {
2939: return 1 if (scalar keys(%Keywords));
2940: # If we are here, %Keywords is empty, so fill it up
2941: # Make sure the file we need exists...
2942: if (! -e $thesaurus_db_file) {
2943: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2944: " failed because it does not exist");
2945: return 0;
2946: }
2947: # Set up the hash as a database
2948: my %thesaurus_db;
2949: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2950: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2951: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2952: $thesaurus_db_file);
2953: return 0;
2954: }
2955: # Get the average number of appearances of a word.
2956: my $avecount = $thesaurus_db{'average.count'};
2957: # Put keywords (those that appear > average) into %Keywords
2958: while (my ($word,$data)=each (%thesaurus_db)) {
2959: my ($count,undef) = split /:/,$data;
2960: $Keywords{$word}++ if ($count > $avecount);
2961: }
2962: untie %thesaurus_db;
2963: # Remove special values from %Keywords.
1.356 albertel 2964: foreach my $value ('total.count','average.count') {
2965: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2966: }
1.46 matthew 2967: return 1;
2968: }
2969:
2970: ###################################################
2971:
2972: =pod
2973:
1.648 raeburn 2974: =item * &keyword($word)
1.46 matthew 2975:
2976: Returns true if $word is a keyword. A keyword is a word that appears more
2977: than the average number of times in the thesaurus database. Calls
2978: &initialize_keywords
2979:
2980: =cut
2981:
2982: ###################################################
1.20 www 2983:
2984: sub keyword {
1.46 matthew 2985: return if (!&initialize_keywords());
2986: my $word=lc(shift());
2987: $word=~s/\W//g;
2988: return exists($Keywords{$word});
1.20 www 2989: }
1.46 matthew 2990:
2991: ###############################################################
2992:
2993: =pod
1.20 www 2994:
1.648 raeburn 2995: =item * &get_related_words()
1.46 matthew 2996:
1.160 matthew 2997: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2998: an array of words. If the keyword is not in the thesaurus, an empty array
2999: will be returned. The order of the words returned is determined by the
3000: database which holds them.
3001:
3002: Uses global $thesaurus_db_file.
3003:
1.1057 foxr 3004:
1.46 matthew 3005: =cut
3006:
3007: ###############################################################
3008: sub get_related_words {
3009: my $keyword = shift;
3010: my %thesaurus_db;
3011: if (! -e $thesaurus_db_file) {
3012: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3013: "failed because the file does not exist");
3014: return ();
3015: }
3016: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3017: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3018: return ();
3019: }
3020: my @Words=();
1.429 www 3021: my $count=0;
1.46 matthew 3022: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3023: # The first element is the number of times
3024: # the word appears. We do not need it now.
1.429 www 3025: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3026: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3027: my $threshold=$mostfrequentcount/10;
3028: foreach my $possibleword (@RelatedWords) {
3029: my ($word,$wordcount)=split(/\,/,$possibleword);
3030: if ($wordcount>$threshold) {
3031: push(@Words,$word);
3032: $count++;
3033: if ($count>10) { last; }
3034: }
1.20 www 3035: }
3036: }
1.46 matthew 3037: untie %thesaurus_db;
3038: return @Words;
1.14 harris41 3039: }
1.46 matthew 3040:
1.112 bowersj2 3041: =pod
3042:
3043: =back
3044:
3045: =cut
1.61 www 3046:
3047: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3048: =pod
3049:
1.112 bowersj2 3050: =head1 User Name Functions
3051:
3052: =over 4
3053:
1.648 raeburn 3054: =item * &plainname($uname,$udom,$first)
1.81 albertel 3055:
1.112 bowersj2 3056: Takes a users logon name and returns it as a string in
1.226 albertel 3057: "first middle last generation" form
3058: if $first is set to 'lastname' then it returns it as
3059: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3060:
3061: =cut
1.61 www 3062:
1.295 www 3063:
1.81 albertel 3064: ###############################################################
1.61 www 3065: sub plainname {
1.226 albertel 3066: my ($uname,$udom,$first)=@_;
1.537 albertel 3067: return if (!defined($uname) || !defined($udom));
1.295 www 3068: my %names=&getnames($uname,$udom);
1.226 albertel 3069: my $name=&Apache::lonnet::format_name($names{'firstname'},
3070: $names{'middlename'},
3071: $names{'lastname'},
3072: $names{'generation'},$first);
3073: $name=~s/^\s+//;
1.62 www 3074: $name=~s/\s+$//;
3075: $name=~s/\s+/ /g;
1.353 albertel 3076: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3077: return $name;
1.61 www 3078: }
1.66 www 3079:
3080: # -------------------------------------------------------------------- Nickname
1.81 albertel 3081: =pod
3082:
1.648 raeburn 3083: =item * &nickname($uname,$udom)
1.81 albertel 3084:
3085: Gets a users name and returns it as a string as
3086:
3087: ""nickname""
1.66 www 3088:
1.81 albertel 3089: if the user has a nickname or
3090:
3091: "first middle last generation"
3092:
3093: if the user does not
3094:
3095: =cut
1.66 www 3096:
3097: sub nickname {
3098: my ($uname,$udom)=@_;
1.537 albertel 3099: return if (!defined($uname) || !defined($udom));
1.295 www 3100: my %names=&getnames($uname,$udom);
1.68 albertel 3101: my $name=$names{'nickname'};
1.66 www 3102: if ($name) {
3103: $name='"'.$name.'"';
3104: } else {
3105: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3106: $names{'lastname'}.' '.$names{'generation'};
3107: $name=~s/\s+$//;
3108: $name=~s/\s+/ /g;
3109: }
3110: return $name;
3111: }
3112:
1.295 www 3113: sub getnames {
3114: my ($uname,$udom)=@_;
1.537 albertel 3115: return if (!defined($uname) || !defined($udom));
1.433 albertel 3116: if ($udom eq 'public' && $uname eq 'public') {
3117: return ('lastname' => &mt('Public'));
3118: }
1.295 www 3119: my $id=$uname.':'.$udom;
3120: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3121: if ($cached) {
3122: return %{$names};
3123: } else {
3124: my %loadnames=&Apache::lonnet::get('environment',
3125: ['firstname','middlename','lastname','generation','nickname'],
3126: $udom,$uname);
3127: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3128: return %loadnames;
3129: }
3130: }
1.61 www 3131:
1.542 raeburn 3132: # -------------------------------------------------------------------- getemails
1.648 raeburn 3133:
1.542 raeburn 3134: =pod
3135:
1.648 raeburn 3136: =item * &getemails($uname,$udom)
1.542 raeburn 3137:
3138: Gets a user's email information and returns it as a hash with keys:
3139: notification, critnotification, permanentemail
3140:
3141: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3142: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3143:
1.648 raeburn 3144:
1.542 raeburn 3145: =cut
3146:
1.648 raeburn 3147:
1.466 albertel 3148: sub getemails {
3149: my ($uname,$udom)=@_;
3150: if ($udom eq 'public' && $uname eq 'public') {
3151: return;
3152: }
1.467 www 3153: if (!$udom) { $udom=$env{'user.domain'}; }
3154: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3155: my $id=$uname.':'.$udom;
3156: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3157: if ($cached) {
3158: return %{$names};
3159: } else {
3160: my %loadnames=&Apache::lonnet::get('environment',
3161: ['notification','critnotification',
3162: 'permanentemail'],
3163: $udom,$uname);
3164: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3165: return %loadnames;
3166: }
3167: }
3168:
1.551 albertel 3169: sub flush_email_cache {
3170: my ($uname,$udom)=@_;
3171: if (!$udom) { $udom =$env{'user.domain'}; }
3172: if (!$uname) { $uname=$env{'user.name'}; }
3173: return if ($udom eq 'public' && $uname eq 'public');
3174: my $id=$uname.':'.$udom;
3175: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3176: }
3177:
1.728 raeburn 3178: # -------------------------------------------------------------------- getlangs
3179:
3180: =pod
3181:
3182: =item * &getlangs($uname,$udom)
3183:
3184: Gets a user's language preference and returns it as a hash with key:
3185: language.
3186:
3187: =cut
3188:
3189:
3190: sub getlangs {
3191: my ($uname,$udom) = @_;
3192: if (!$udom) { $udom =$env{'user.domain'}; }
3193: if (!$uname) { $uname=$env{'user.name'}; }
3194: my $id=$uname.':'.$udom;
3195: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3196: if ($cached) {
3197: return %{$langs};
3198: } else {
3199: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3200: $udom,$uname);
3201: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3202: return %loadlangs;
3203: }
3204: }
3205:
3206: sub flush_langs_cache {
3207: my ($uname,$udom)=@_;
3208: if (!$udom) { $udom =$env{'user.domain'}; }
3209: if (!$uname) { $uname=$env{'user.name'}; }
3210: return if ($udom eq 'public' && $uname eq 'public');
3211: my $id=$uname.':'.$udom;
3212: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3213: }
3214:
1.61 www 3215: # ------------------------------------------------------------------ Screenname
1.81 albertel 3216:
3217: =pod
3218:
1.648 raeburn 3219: =item * &screenname($uname,$udom)
1.81 albertel 3220:
3221: Gets a users screenname and returns it as a string
3222:
3223: =cut
1.61 www 3224:
3225: sub screenname {
3226: my ($uname,$udom)=@_;
1.258 albertel 3227: if ($uname eq $env{'user.name'} &&
3228: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3229: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3230: return $names{'screenname'};
1.62 www 3231: }
3232:
1.212 albertel 3233:
1.802 bisitz 3234: # ------------------------------------------------------------- Confirm Wrapper
3235: =pod
3236:
1.1075.2.42 raeburn 3237: =item * &confirmwrapper($message)
1.802 bisitz 3238:
3239: Wrap messages about completion of operation in box
3240:
3241: =cut
3242:
3243: sub confirmwrapper {
3244: my ($message)=@_;
3245: if ($message) {
3246: return "\n".'<div class="LC_confirm_box">'."\n"
3247: .$message."\n"
3248: .'</div>'."\n";
3249: } else {
3250: return $message;
3251: }
3252: }
3253:
1.62 www 3254: # ------------------------------------------------------------- Message Wrapper
3255:
3256: sub messagewrapper {
1.369 www 3257: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3258: return
1.441 albertel 3259: '<a href="/adm/email?compose=individual&'.
3260: 'recname='.$username.'&recdom='.$domain.
3261: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3262: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3263: }
1.802 bisitz 3264:
1.74 www 3265: # --------------------------------------------------------------- Notes Wrapper
3266:
3267: sub noteswrapper {
3268: my ($link,$un,$do)=@_;
3269: return
1.896 amueller 3270: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3271: }
1.802 bisitz 3272:
1.62 www 3273: # ------------------------------------------------------------- Aboutme Wrapper
3274:
3275: sub aboutmewrapper {
1.1070 raeburn 3276: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3277: if (!defined($username) && !defined($domain)) {
3278: return;
3279: }
1.1075.2.15 raeburn 3280: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3281: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3282: }
3283:
3284: # ------------------------------------------------------------ Syllabus Wrapper
3285:
3286: sub syllabuswrapper {
1.707 bisitz 3287: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3288: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3289: }
1.14 harris41 3290:
1.802 bisitz 3291: # -----------------------------------------------------------------------------
3292:
1.208 matthew 3293: sub track_student_link {
1.887 raeburn 3294: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3295: my $link ="/adm/trackstudent?";
1.208 matthew 3296: my $title = 'View recent activity';
3297: if (defined($sname) && $sname !~ /^\s*$/ &&
3298: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3299: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3300: $title .= ' of this student';
1.268 albertel 3301: }
1.208 matthew 3302: if (defined($target) && $target !~ /^\s*$/) {
3303: $target = qq{target="$target"};
3304: } else {
3305: $target = '';
3306: }
1.268 albertel 3307: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3308: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3309: $title = &mt($title);
3310: $linktext = &mt($linktext);
1.448 albertel 3311: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3312: &help_open_topic('View_recent_activity');
1.208 matthew 3313: }
3314:
1.781 raeburn 3315: sub slot_reservations_link {
3316: my ($linktext,$sname,$sdom,$target) = @_;
3317: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3318: my $title = 'View slot reservation history';
3319: if (defined($sname) && $sname !~ /^\s*$/ &&
3320: defined($sdom) && $sdom !~ /^\s*$/) {
3321: $link .= "&uname=$sname&udom=$sdom";
3322: $title .= ' of this student';
3323: }
3324: if (defined($target) && $target !~ /^\s*$/) {
3325: $target = qq{target="$target"};
3326: } else {
3327: $target = '';
3328: }
3329: $title = &mt($title);
3330: $linktext = &mt($linktext);
3331: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3332: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3333:
3334: }
3335:
1.508 www 3336: # ===================================================== Display a student photo
3337:
3338:
1.509 albertel 3339: sub student_image_tag {
1.508 www 3340: my ($domain,$user)=@_;
3341: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3342: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3343: return '<img src="'.$imgsrc.'" align="right" />';
3344: } else {
3345: return '';
3346: }
3347: }
3348:
1.112 bowersj2 3349: =pod
3350:
3351: =back
3352:
3353: =head1 Access .tab File Data
3354:
3355: =over 4
3356:
1.648 raeburn 3357: =item * &languageids()
1.112 bowersj2 3358:
3359: returns list of all language ids
3360:
3361: =cut
3362:
1.14 harris41 3363: sub languageids {
1.16 harris41 3364: return sort(keys(%language));
1.14 harris41 3365: }
3366:
1.112 bowersj2 3367: =pod
3368:
1.648 raeburn 3369: =item * &languagedescription()
1.112 bowersj2 3370:
3371: returns description of a specified language id
3372:
3373: =cut
3374:
1.14 harris41 3375: sub languagedescription {
1.125 www 3376: my $code=shift;
3377: return ($supported_language{$code}?'* ':'').
3378: $language{$code}.
1.126 www 3379: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3380: }
3381:
1.1048 foxr 3382: =pod
3383:
3384: =item * &plainlanguagedescription
3385:
3386: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3387: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3388:
3389: =cut
3390:
1.145 www 3391: sub plainlanguagedescription {
3392: my $code=shift;
3393: return $language{$code};
3394: }
3395:
1.1048 foxr 3396: =pod
3397:
3398: =item * &supportedlanguagecode
3399:
3400: Returns the supported language code (e.g. sptutf maps to pt) given a language
3401: code.
3402:
3403: =cut
3404:
1.145 www 3405: sub supportedlanguagecode {
3406: my $code=shift;
3407: return $supported_language{$code};
1.97 www 3408: }
3409:
1.112 bowersj2 3410: =pod
3411:
1.1048 foxr 3412: =item * &latexlanguage()
3413:
3414: Given a language key code returns the correspondnig language to use
3415: to select the correct hyphenation on LaTeX printouts. This is undef if there
3416: is no supported hyphenation for the language code.
3417:
3418: =cut
3419:
3420: sub latexlanguage {
3421: my $code = shift;
3422: return $latex_language{$code};
3423: }
3424:
3425: =pod
3426:
3427: =item * &latexhyphenation()
3428:
3429: Same as above but what's supplied is the language as it might be stored
3430: in the metadata.
3431:
3432: =cut
3433:
3434: sub latexhyphenation {
3435: my $key = shift;
3436: return $latex_language_bykey{$key};
3437: }
3438:
3439: =pod
3440:
1.648 raeburn 3441: =item * ©rightids()
1.112 bowersj2 3442:
3443: returns list of all copyrights
3444:
3445: =cut
3446:
3447: sub copyrightids {
3448: return sort(keys(%cprtag));
3449: }
3450:
3451: =pod
3452:
1.648 raeburn 3453: =item * ©rightdescription()
1.112 bowersj2 3454:
3455: returns description of a specified copyright id
3456:
3457: =cut
3458:
3459: sub copyrightdescription {
1.166 www 3460: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3461: }
1.197 matthew 3462:
3463: =pod
3464:
1.648 raeburn 3465: =item * &source_copyrightids()
1.192 taceyjo1 3466:
3467: returns list of all source copyrights
3468:
3469: =cut
3470:
3471: sub source_copyrightids {
3472: return sort(keys(%scprtag));
3473: }
3474:
3475: =pod
3476:
1.648 raeburn 3477: =item * &source_copyrightdescription()
1.192 taceyjo1 3478:
3479: returns description of a specified source copyright id
3480:
3481: =cut
3482:
3483: sub source_copyrightdescription {
3484: return &mt($scprtag{shift(@_)});
3485: }
1.112 bowersj2 3486:
3487: =pod
3488:
1.648 raeburn 3489: =item * &filecategories()
1.112 bowersj2 3490:
3491: returns list of all file categories
3492:
3493: =cut
3494:
3495: sub filecategories {
3496: return sort(keys(%category_extensions));
3497: }
3498:
3499: =pod
3500:
1.648 raeburn 3501: =item * &filecategorytypes()
1.112 bowersj2 3502:
3503: returns list of file types belonging to a given file
3504: category
3505:
3506: =cut
3507:
3508: sub filecategorytypes {
1.356 albertel 3509: my ($cat) = @_;
3510: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3511: }
3512:
3513: =pod
3514:
1.648 raeburn 3515: =item * &fileembstyle()
1.112 bowersj2 3516:
3517: returns embedding style for a specified file type
3518:
3519: =cut
3520:
3521: sub fileembstyle {
3522: return $fe{lc(shift(@_))};
1.169 www 3523: }
3524:
1.351 www 3525: sub filemimetype {
3526: return $fm{lc(shift(@_))};
3527: }
3528:
1.169 www 3529:
3530: sub filecategoryselect {
3531: my ($name,$value)=@_;
1.189 matthew 3532: return &select_form($value,$name,
1.970 raeburn 3533: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3534: }
3535:
3536: =pod
3537:
1.648 raeburn 3538: =item * &filedescription()
1.112 bowersj2 3539:
3540: returns description for a specified file type
3541:
3542: =cut
3543:
3544: sub filedescription {
1.188 matthew 3545: my $file_description = $fd{lc(shift())};
3546: $file_description =~ s:([\[\]]):~$1:g;
3547: return &mt($file_description);
1.112 bowersj2 3548: }
3549:
3550: =pod
3551:
1.648 raeburn 3552: =item * &filedescriptionex()
1.112 bowersj2 3553:
3554: returns description for a specified file type with
3555: extra formatting
3556:
3557: =cut
3558:
3559: sub filedescriptionex {
3560: my $ex=shift;
1.188 matthew 3561: my $file_description = $fd{lc($ex)};
3562: $file_description =~ s:([\[\]]):~$1:g;
3563: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3564: }
3565:
3566: # End of .tab access
3567: =pod
3568:
3569: =back
3570:
3571: =cut
3572:
3573: # ------------------------------------------------------------------ File Types
3574: sub fileextensions {
3575: return sort(keys(%fe));
3576: }
3577:
1.97 www 3578: # ----------------------------------------------------------- Display Languages
3579: # returns a hash with all desired display languages
3580: #
3581:
3582: sub display_languages {
3583: my %languages=();
1.695 raeburn 3584: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3585: $languages{$lang}=1;
1.97 www 3586: }
3587: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3588: if ($env{'form.displaylanguage'}) {
1.356 albertel 3589: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3590: $languages{$lang}=1;
1.97 www 3591: }
3592: }
3593: return %languages;
1.14 harris41 3594: }
3595:
1.582 albertel 3596: sub languages {
3597: my ($possible_langs) = @_;
1.695 raeburn 3598: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3599: if (!ref($possible_langs)) {
3600: if( wantarray ) {
3601: return @preferred_langs;
3602: } else {
3603: return $preferred_langs[0];
3604: }
3605: }
3606: my %possibilities = map { $_ => 1 } (@$possible_langs);
3607: my @preferred_possibilities;
3608: foreach my $preferred_lang (@preferred_langs) {
3609: if (exists($possibilities{$preferred_lang})) {
3610: push(@preferred_possibilities, $preferred_lang);
3611: }
3612: }
3613: if( wantarray ) {
3614: return @preferred_possibilities;
3615: }
3616: return $preferred_possibilities[0];
3617: }
3618:
1.742 raeburn 3619: sub user_lang {
3620: my ($touname,$toudom,$fromcid) = @_;
3621: my @userlangs;
3622: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3623: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3624: $env{'course.'.$fromcid.'.languages'}));
3625: } else {
3626: my %langhash = &getlangs($touname,$toudom);
3627: if ($langhash{'languages'} ne '') {
3628: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3629: } else {
3630: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3631: if ($domdefs{'lang_def'} ne '') {
3632: @userlangs = ($domdefs{'lang_def'});
3633: }
3634: }
3635: }
3636: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3637: my $user_lh = Apache::localize->get_handle(@languages);
3638: return $user_lh;
3639: }
3640:
3641:
1.112 bowersj2 3642: ###############################################################
3643: ## Student Answer Attempts ##
3644: ###############################################################
3645:
3646: =pod
3647:
3648: =head1 Alternate Problem Views
3649:
3650: =over 4
3651:
1.648 raeburn 3652: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3653: $getattempt, $regexp, $gradesub)
3654:
3655: Return string with previous attempt on problem. Arguments:
3656:
3657: =over 4
3658:
3659: =item * $symb: Problem, including path
3660:
3661: =item * $username: username of the desired student
3662:
3663: =item * $domain: domain of the desired student
1.14 harris41 3664:
1.112 bowersj2 3665: =item * $course: Course ID
1.14 harris41 3666:
1.112 bowersj2 3667: =item * $getattempt: Leave blank for all attempts, otherwise put
3668: something
1.14 harris41 3669:
1.112 bowersj2 3670: =item * $regexp: if string matches this regexp, the string will be
3671: sent to $gradesub
1.14 harris41 3672:
1.112 bowersj2 3673: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3674:
1.112 bowersj2 3675: =back
1.14 harris41 3676:
1.112 bowersj2 3677: The output string is a table containing all desired attempts, if any.
1.16 harris41 3678:
1.112 bowersj2 3679: =cut
1.1 albertel 3680:
3681: sub get_previous_attempt {
1.43 ng 3682: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3683: my $prevattempts='';
1.43 ng 3684: no strict 'refs';
1.1 albertel 3685: if ($symb) {
1.3 albertel 3686: my (%returnhash)=
3687: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3688: if ($returnhash{'version'}) {
3689: my %lasthash=();
3690: my $version;
3691: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3692: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3693: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3694: }
1.1 albertel 3695: }
1.596 albertel 3696: $prevattempts=&start_data_table().&start_data_table_header_row();
3697: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3698: my (%typeparts,%lasthidden);
1.945 raeburn 3699: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3700: foreach my $key (sort(keys(%lasthash))) {
3701: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3702: if ($#parts > 0) {
1.31 albertel 3703: my $data=$parts[-1];
1.989 raeburn 3704: next if ($data eq 'foilorder');
1.31 albertel 3705: pop(@parts);
1.1010 www 3706: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3707: if ($data eq 'type') {
3708: unless ($showsurv) {
3709: my $id = join(',',@parts);
3710: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3711: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3712: $lasthidden{$ign.'.'.$id} = 1;
3713: }
1.945 raeburn 3714: }
1.1010 www 3715: }
1.31 albertel 3716: } else {
1.41 ng 3717: if ($#parts == 0) {
3718: $prevattempts.='<th>'.$parts[0].'</th>';
3719: } else {
3720: $prevattempts.='<th>'.$ign.'</th>';
3721: }
1.31 albertel 3722: }
1.16 harris41 3723: }
1.596 albertel 3724: $prevattempts.=&end_data_table_header_row();
1.40 ng 3725: if ($getattempt eq '') {
3726: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3727: my @hidden;
3728: if (%typeparts) {
3729: foreach my $id (keys(%typeparts)) {
3730: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3731: push(@hidden,$id);
3732: }
3733: }
3734: }
3735: $prevattempts.=&start_data_table_row().
3736: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3737: if (@hidden) {
3738: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3739: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3740: my $hide;
3741: foreach my $id (@hidden) {
3742: if ($key =~ /^\Q$id\E/) {
3743: $hide = 1;
3744: last;
3745: }
3746: }
3747: if ($hide) {
3748: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3749: if (($data eq 'award') || ($data eq 'awarddetail')) {
3750: my $value = &format_previous_attempt_value($key,
3751: $returnhash{$version.':'.$key});
3752: $prevattempts.='<td>'.$value.' </td>';
3753: } else {
3754: $prevattempts.='<td> </td>';
3755: }
3756: } else {
3757: if ($key =~ /\./) {
3758: my $value = &format_previous_attempt_value($key,
3759: $returnhash{$version.':'.$key});
3760: $prevattempts.='<td>'.$value.' </td>';
3761: } else {
3762: $prevattempts.='<td> </td>';
3763: }
3764: }
3765: }
3766: } else {
3767: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3768: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3769: my $value = &format_previous_attempt_value($key,
3770: $returnhash{$version.':'.$key});
3771: $prevattempts.='<td>'.$value.' </td>';
3772: }
3773: }
3774: $prevattempts.=&end_data_table_row();
1.40 ng 3775: }
1.1 albertel 3776: }
1.945 raeburn 3777: my @currhidden = keys(%lasthidden);
1.596 albertel 3778: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3779: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3780: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3781: if (%typeparts) {
3782: my $hidden;
3783: foreach my $id (@currhidden) {
3784: if ($key =~ /^\Q$id\E/) {
3785: $hidden = 1;
3786: last;
3787: }
3788: }
3789: if ($hidden) {
3790: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3791: if (($data eq 'award') || ($data eq 'awarddetail')) {
3792: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3793: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3794: $value = &$gradesub($value);
3795: }
3796: $prevattempts.='<td>'.$value.' </td>';
3797: } else {
3798: $prevattempts.='<td> </td>';
3799: }
3800: } else {
3801: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3802: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3803: $value = &$gradesub($value);
3804: }
3805: $prevattempts.='<td>'.$value.' </td>';
3806: }
3807: } else {
3808: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3809: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3810: $value = &$gradesub($value);
3811: }
3812: $prevattempts.='<td>'.$value.' </td>';
3813: }
1.16 harris41 3814: }
1.596 albertel 3815: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3816: } else {
1.596 albertel 3817: $prevattempts=
3818: &start_data_table().&start_data_table_row().
3819: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3820: &end_data_table_row().&end_data_table();
1.1 albertel 3821: }
3822: } else {
1.596 albertel 3823: $prevattempts=
3824: &start_data_table().&start_data_table_row().
3825: '<td>'.&mt('No data.').'</td>'.
3826: &end_data_table_row().&end_data_table();
1.1 albertel 3827: }
1.10 albertel 3828: }
3829:
1.581 albertel 3830: sub format_previous_attempt_value {
3831: my ($key,$value) = @_;
1.1011 www 3832: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3833: $value = &Apache::lonlocal::locallocaltime($value);
3834: } elsif (ref($value) eq 'ARRAY') {
3835: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3836: } elsif ($key =~ /answerstring$/) {
3837: my %answers = &Apache::lonnet::str2hash($value);
3838: my @anskeys = sort(keys(%answers));
3839: if (@anskeys == 1) {
3840: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3841: if ($answer =~ m{\0}) {
3842: $answer =~ s{\0}{,}g;
1.988 raeburn 3843: }
3844: my $tag_internal_answer_name = 'INTERNAL';
3845: if ($anskeys[0] eq $tag_internal_answer_name) {
3846: $value = $answer;
3847: } else {
3848: $value = $anskeys[0].'='.$answer;
3849: }
3850: } else {
3851: foreach my $ans (@anskeys) {
3852: my $answer = $answers{$ans};
1.1001 raeburn 3853: if ($answer =~ m{\0}) {
3854: $answer =~ s{\0}{,}g;
1.988 raeburn 3855: }
3856: $value .= $ans.'='.$answer.'<br />';;
3857: }
3858: }
1.581 albertel 3859: } else {
3860: $value = &unescape($value);
3861: }
3862: return $value;
3863: }
3864:
3865:
1.107 albertel 3866: sub relative_to_absolute {
3867: my ($url,$output)=@_;
3868: my $parser=HTML::TokeParser->new(\$output);
3869: my $token;
3870: my $thisdir=$url;
3871: my @rlinks=();
3872: while ($token=$parser->get_token) {
3873: if ($token->[0] eq 'S') {
3874: if ($token->[1] eq 'a') {
3875: if ($token->[2]->{'href'}) {
3876: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3877: }
3878: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3879: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3880: } elsif ($token->[1] eq 'base') {
3881: $thisdir=$token->[2]->{'href'};
3882: }
3883: }
3884: }
3885: $thisdir=~s-/[^/]*$--;
1.356 albertel 3886: foreach my $link (@rlinks) {
1.726 raeburn 3887: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3888: ($link=~/^\//) ||
3889: ($link=~/^javascript:/i) ||
3890: ($link=~/^mailto:/i) ||
3891: ($link=~/^\#/)) {
3892: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3893: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3894: }
3895: }
3896: # -------------------------------------------------- Deal with Applet codebases
3897: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3898: return $output;
3899: }
3900:
1.112 bowersj2 3901: =pod
3902:
1.648 raeburn 3903: =item * &get_student_view()
1.112 bowersj2 3904:
3905: show a snapshot of what student was looking at
3906:
3907: =cut
3908:
1.10 albertel 3909: sub get_student_view {
1.186 albertel 3910: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3911: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3912: my (%form);
1.10 albertel 3913: my @elements=('symb','courseid','domain','username');
3914: foreach my $element (@elements) {
1.186 albertel 3915: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3916: }
1.186 albertel 3917: if (defined($moreenv)) {
3918: %form=(%form,%{$moreenv});
3919: }
1.236 albertel 3920: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3921: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3922: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3923: $userview=~s/\<body[^\>]*\>//gi;
3924: $userview=~s/\<\/body\>//gi;
3925: $userview=~s/\<html\>//gi;
3926: $userview=~s/\<\/html\>//gi;
3927: $userview=~s/\<head\>//gi;
3928: $userview=~s/\<\/head\>//gi;
3929: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3930: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3931: if (wantarray) {
3932: return ($userview,$response);
3933: } else {
3934: return $userview;
3935: }
3936: }
3937:
3938: sub get_student_view_with_retries {
3939: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3940:
3941: my $ok = 0; # True if we got a good response.
3942: my $content;
3943: my $response;
3944:
3945: # Try to get the student_view done. within the retries count:
3946:
3947: do {
3948: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3949: $ok = $response->is_success;
3950: if (!$ok) {
3951: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3952: }
3953: $retries--;
3954: } while (!$ok && ($retries > 0));
3955:
3956: if (!$ok) {
3957: $content = ''; # On error return an empty content.
3958: }
1.651 www 3959: if (wantarray) {
3960: return ($content, $response);
3961: } else {
3962: return $content;
3963: }
1.11 albertel 3964: }
3965:
1.112 bowersj2 3966: =pod
3967:
1.648 raeburn 3968: =item * &get_student_answers()
1.112 bowersj2 3969:
3970: show a snapshot of how student was answering problem
3971:
3972: =cut
3973:
1.11 albertel 3974: sub get_student_answers {
1.100 sakharuk 3975: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3976: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3977: my (%moreenv);
1.11 albertel 3978: my @elements=('symb','courseid','domain','username');
3979: foreach my $element (@elements) {
1.186 albertel 3980: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3981: }
1.186 albertel 3982: $moreenv{'grade_target'}='answer';
3983: %moreenv=(%form,%moreenv);
1.497 raeburn 3984: $feedurl = &Apache::lonnet::clutter($feedurl);
3985: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3986: return $userview;
1.1 albertel 3987: }
1.116 albertel 3988:
3989: =pod
3990:
3991: =item * &submlink()
3992:
1.242 albertel 3993: Inputs: $text $uname $udom $symb $target
1.116 albertel 3994:
3995: Returns: A link to grades.pm such as to see the SUBM view of a student
3996:
3997: =cut
3998:
3999: ###############################################
4000: sub submlink {
1.242 albertel 4001: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4002: if (!($uname && $udom)) {
4003: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4004: &Apache::lonnet::whichuser($symb);
1.116 albertel 4005: if (!$symb) { $symb=$cursymb; }
4006: }
1.254 matthew 4007: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4008: $symb=&escape($symb);
1.960 bisitz 4009: if ($target) { $target=" target=\"$target\""; }
4010: return
4011: '<a href="/adm/grades?command=submission'.
4012: '&symb='.$symb.
4013: '&student='.$uname.
4014: '&userdom='.$udom.'"'.
4015: $target.'>'.$text.'</a>';
1.242 albertel 4016: }
4017: ##############################################
4018:
4019: =pod
4020:
4021: =item * &pgrdlink()
4022:
4023: Inputs: $text $uname $udom $symb $target
4024:
4025: Returns: A link to grades.pm such as to see the PGRD view of a student
4026:
4027: =cut
4028:
4029: ###############################################
4030: sub pgrdlink {
4031: my $link=&submlink(@_);
4032: $link=~s/(&command=submission)/$1&showgrading=yes/;
4033: return $link;
4034: }
4035: ##############################################
4036:
4037: =pod
4038:
4039: =item * &pprmlink()
4040:
4041: Inputs: $text $uname $udom $symb $target
4042:
4043: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4044: student and a specific resource
1.242 albertel 4045:
4046: =cut
4047:
4048: ###############################################
4049: sub pprmlink {
4050: my ($text,$uname,$udom,$symb,$target)=@_;
4051: if (!($uname && $udom)) {
4052: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4053: &Apache::lonnet::whichuser($symb);
1.242 albertel 4054: if (!$symb) { $symb=$cursymb; }
4055: }
1.254 matthew 4056: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4057: $symb=&escape($symb);
1.242 albertel 4058: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4059: return '<a href="/adm/parmset?command=set&'.
4060: 'symb='.$symb.'&uname='.$uname.
4061: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4062: }
4063: ##############################################
1.37 matthew 4064:
1.112 bowersj2 4065: =pod
4066:
4067: =back
4068:
4069: =cut
4070:
1.37 matthew 4071: ###############################################
1.51 www 4072:
4073:
4074: sub timehash {
1.687 raeburn 4075: my ($thistime) = @_;
4076: my $timezone = &Apache::lonlocal::gettimezone();
4077: my $dt = DateTime->from_epoch(epoch => $thistime)
4078: ->set_time_zone($timezone);
4079: my $wday = $dt->day_of_week();
4080: if ($wday == 7) { $wday = 0; }
4081: return ( 'second' => $dt->second(),
4082: 'minute' => $dt->minute(),
4083: 'hour' => $dt->hour(),
4084: 'day' => $dt->day_of_month(),
4085: 'month' => $dt->month(),
4086: 'year' => $dt->year(),
4087: 'weekday' => $wday,
4088: 'dayyear' => $dt->day_of_year(),
4089: 'dlsav' => $dt->is_dst() );
1.51 www 4090: }
4091:
1.370 www 4092: sub utc_string {
4093: my ($date)=@_;
1.371 www 4094: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4095: }
4096:
1.51 www 4097: sub maketime {
4098: my %th=@_;
1.687 raeburn 4099: my ($epoch_time,$timezone,$dt);
4100: $timezone = &Apache::lonlocal::gettimezone();
4101: eval {
4102: $dt = DateTime->new( year => $th{'year'},
4103: month => $th{'month'},
4104: day => $th{'day'},
4105: hour => $th{'hour'},
4106: minute => $th{'minute'},
4107: second => $th{'second'},
4108: time_zone => $timezone,
4109: );
4110: };
4111: if (!$@) {
4112: $epoch_time = $dt->epoch;
4113: if ($epoch_time) {
4114: return $epoch_time;
4115: }
4116: }
1.51 www 4117: return POSIX::mktime(
4118: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4119: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4120: }
4121:
4122: #########################################
1.51 www 4123:
4124: sub findallcourses {
1.482 raeburn 4125: my ($roles,$uname,$udom) = @_;
1.355 albertel 4126: my %roles;
4127: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4128: my %courses;
1.51 www 4129: my $now=time;
1.482 raeburn 4130: if (!defined($uname)) {
4131: $uname = $env{'user.name'};
4132: }
4133: if (!defined($udom)) {
4134: $udom = $env{'user.domain'};
4135: }
4136: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4137: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4138: if (!%roles) {
4139: %roles = (
4140: cc => 1,
1.907 raeburn 4141: co => 1,
1.482 raeburn 4142: in => 1,
4143: ep => 1,
4144: ta => 1,
4145: cr => 1,
4146: st => 1,
4147: );
4148: }
4149: foreach my $entry (keys(%roleshash)) {
4150: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4151: if ($trole =~ /^cr/) {
4152: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4153: } else {
4154: next if (!exists($roles{$trole}));
4155: }
4156: if ($tend) {
4157: next if ($tend < $now);
4158: }
4159: if ($tstart) {
4160: next if ($tstart > $now);
4161: }
1.1058 raeburn 4162: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4163: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4164: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4165: if ($secpart eq '') {
4166: ($cnum,$role) = split(/_/,$cnumpart);
4167: $sec = 'none';
1.1058 raeburn 4168: $value .= $cnum.'/';
1.482 raeburn 4169: } else {
4170: $cnum = $cnumpart;
4171: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4172: $value .= $cnum.'/'.$sec;
4173: }
4174: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4175: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4176: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4177: }
4178: } else {
4179: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4180: }
1.482 raeburn 4181: }
4182: } else {
4183: foreach my $key (keys(%env)) {
1.483 albertel 4184: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4185: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4186: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4187: next if ($role eq 'ca' || $role eq 'aa');
4188: next if (%roles && !exists($roles{$role}));
4189: my ($starttime,$endtime)=split(/\./,$env{$key});
4190: my $active=1;
4191: if ($starttime) {
4192: if ($now<$starttime) { $active=0; }
4193: }
4194: if ($endtime) {
4195: if ($now>$endtime) { $active=0; }
4196: }
4197: if ($active) {
1.1058 raeburn 4198: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4199: if ($sec eq '') {
4200: $sec = 'none';
1.1058 raeburn 4201: } else {
4202: $value .= $sec;
4203: }
4204: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4205: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4206: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4207: }
4208: } else {
4209: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4210: }
1.474 raeburn 4211: }
4212: }
1.51 www 4213: }
4214: }
1.474 raeburn 4215: return %courses;
1.51 www 4216: }
1.37 matthew 4217:
1.54 www 4218: ###############################################
1.474 raeburn 4219:
4220: sub blockcheck {
1.1062 raeburn 4221: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4222:
4223: if (!defined($udom)) {
4224: $udom = $env{'user.domain'};
4225: }
4226: if (!defined($uname)) {
4227: $uname = $env{'user.name'};
4228: }
4229:
4230: # If uname and udom are for a course, check for blocks in the course.
4231:
4232: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4233: my ($startblock,$endblock,$triggerblock) =
4234: &get_blocks($setters,$activity,$udom,$uname,$url);
4235: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4236: }
1.474 raeburn 4237:
1.502 raeburn 4238: my $startblock = 0;
4239: my $endblock = 0;
1.1062 raeburn 4240: my $triggerblock = '';
1.482 raeburn 4241: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4242:
1.490 raeburn 4243: # If uname is for a user, and activity is course-specific, i.e.,
4244: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4245:
1.490 raeburn 4246: if (($activity eq 'boards' || $activity eq 'chat' ||
4247: $activity eq 'groups') && ($env{'request.course.id'})) {
4248: foreach my $key (keys(%live_courses)) {
4249: if ($key ne $env{'request.course.id'}) {
4250: delete($live_courses{$key});
4251: }
4252: }
4253: }
4254:
4255: my $otheruser = 0;
4256: my %own_courses;
4257: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4258: # Resource belongs to user other than current user.
4259: $otheruser = 1;
4260: # Gather courses for current user
4261: %own_courses =
4262: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4263: }
4264:
4265: # Gather active course roles - course coordinator, instructor,
4266: # exam proctor, ta, student, or custom role.
1.474 raeburn 4267:
4268: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4269: my ($cdom,$cnum);
4270: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4271: $cdom = $env{'course.'.$course.'.domain'};
4272: $cnum = $env{'course.'.$course.'.num'};
4273: } else {
1.490 raeburn 4274: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4275: }
4276: my $no_ownblock = 0;
4277: my $no_userblock = 0;
1.533 raeburn 4278: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4279: # Check if current user has 'evb' priv for this
4280: if (defined($own_courses{$course})) {
4281: foreach my $sec (keys(%{$own_courses{$course}})) {
4282: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4283: if ($sec ne 'none') {
4284: $checkrole .= '/'.$sec;
4285: }
4286: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4287: $no_ownblock = 1;
4288: last;
4289: }
4290: }
4291: }
4292: # if they have 'evb' priv and are currently not playing student
4293: next if (($no_ownblock) &&
4294: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4295: }
1.474 raeburn 4296: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4297: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4298: if ($sec ne 'none') {
1.482 raeburn 4299: $checkrole .= '/'.$sec;
1.474 raeburn 4300: }
1.490 raeburn 4301: if ($otheruser) {
4302: # Resource belongs to user other than current user.
4303: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4304: my (%allroles,%userroles);
4305: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4306: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4307: my ($trole,$tdom,$tnum,$tsec);
4308: if ($entry =~ /^cr/) {
4309: ($trole,$tdom,$tnum,$tsec) =
4310: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4311: } else {
4312: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4313: }
4314: my ($spec,$area,$trest);
4315: $area = '/'.$tdom.'/'.$tnum;
4316: $trest = $tnum;
4317: if ($tsec ne '') {
4318: $area .= '/'.$tsec;
4319: $trest .= '/'.$tsec;
4320: }
4321: $spec = $trole.'.'.$area;
4322: if ($trole =~ /^cr/) {
4323: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4324: $tdom,$spec,$trest,$area);
4325: } else {
4326: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4327: $tdom,$spec,$trest,$area);
4328: }
4329: }
4330: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4331: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4332: if ($1) {
4333: $no_userblock = 1;
4334: last;
4335: }
1.486 raeburn 4336: }
4337: }
1.490 raeburn 4338: } else {
4339: # Resource belongs to current user
4340: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4341: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4342: $no_ownblock = 1;
4343: last;
4344: }
1.474 raeburn 4345: }
4346: }
4347: # if they have the evb priv and are currently not playing student
1.482 raeburn 4348: next if (($no_ownblock) &&
1.491 albertel 4349: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4350: next if ($no_userblock);
1.474 raeburn 4351:
1.866 kalberla 4352: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4353: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4354:
1.1062 raeburn 4355: my ($start,$end,$trigger) =
4356: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4357: if (($start != 0) &&
4358: (($startblock == 0) || ($startblock > $start))) {
4359: $startblock = $start;
1.1062 raeburn 4360: if ($trigger ne '') {
4361: $triggerblock = $trigger;
4362: }
1.502 raeburn 4363: }
4364: if (($end != 0) &&
4365: (($endblock == 0) || ($endblock < $end))) {
4366: $endblock = $end;
1.1062 raeburn 4367: if ($trigger ne '') {
4368: $triggerblock = $trigger;
4369: }
1.502 raeburn 4370: }
1.490 raeburn 4371: }
1.1062 raeburn 4372: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4373: }
4374:
4375: sub get_blocks {
1.1062 raeburn 4376: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4377: my $startblock = 0;
4378: my $endblock = 0;
1.1062 raeburn 4379: my $triggerblock = '';
1.490 raeburn 4380: my $course = $cdom.'_'.$cnum;
4381: $setters->{$course} = {};
4382: $setters->{$course}{'staff'} = [];
4383: $setters->{$course}{'times'} = [];
1.1062 raeburn 4384: $setters->{$course}{'triggers'} = [];
4385: my (@blockers,%triggered);
4386: my $now = time;
4387: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4388: if ($activity eq 'docs') {
4389: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4390: foreach my $block (@blockers) {
4391: if ($block =~ /^firstaccess____(.+)$/) {
4392: my $item = $1;
4393: my $type = 'map';
4394: my $timersymb = $item;
4395: if ($item eq 'course') {
4396: $type = 'course';
4397: } elsif ($item =~ /___\d+___/) {
4398: $type = 'resource';
4399: } else {
4400: $timersymb = &Apache::lonnet::symbread($item);
4401: }
4402: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4403: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4404: $triggered{$block} = {
4405: start => $start,
4406: end => $end,
4407: type => $type,
4408: };
4409: }
4410: }
4411: } else {
4412: foreach my $block (keys(%commblocks)) {
4413: if ($block =~ m/^(\d+)____(\d+)$/) {
4414: my ($start,$end) = ($1,$2);
4415: if ($start <= time && $end >= time) {
4416: if (ref($commblocks{$block}) eq 'HASH') {
4417: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4418: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4419: unless(grep(/^\Q$block\E$/,@blockers)) {
4420: push(@blockers,$block);
4421: }
4422: }
4423: }
4424: }
4425: }
4426: } elsif ($block =~ /^firstaccess____(.+)$/) {
4427: my $item = $1;
4428: my $timersymb = $item;
4429: my $type = 'map';
4430: if ($item eq 'course') {
4431: $type = 'course';
4432: } elsif ($item =~ /___\d+___/) {
4433: $type = 'resource';
4434: } else {
4435: $timersymb = &Apache::lonnet::symbread($item);
4436: }
4437: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4438: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4439: if ($start && $end) {
4440: if (($start <= time) && ($end >= time)) {
4441: unless (grep(/^\Q$block\E$/,@blockers)) {
4442: push(@blockers,$block);
4443: $triggered{$block} = {
4444: start => $start,
4445: end => $end,
4446: type => $type,
4447: };
4448: }
4449: }
1.490 raeburn 4450: }
1.1062 raeburn 4451: }
4452: }
4453: }
4454: foreach my $blocker (@blockers) {
4455: my ($staff_name,$staff_dom,$title,$blocks) =
4456: &parse_block_record($commblocks{$blocker});
4457: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4458: my ($start,$end,$triggertype);
4459: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4460: ($start,$end) = ($1,$2);
4461: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4462: $start = $triggered{$blocker}{'start'};
4463: $end = $triggered{$blocker}{'end'};
4464: $triggertype = $triggered{$blocker}{'type'};
4465: }
4466: if ($start) {
4467: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4468: if ($triggertype) {
4469: push(@{$$setters{$course}{'triggers'}},$triggertype);
4470: } else {
4471: push(@{$$setters{$course}{'triggers'}},0);
4472: }
4473: if ( ($startblock == 0) || ($startblock > $start) ) {
4474: $startblock = $start;
4475: if ($triggertype) {
4476: $triggerblock = $blocker;
1.474 raeburn 4477: }
4478: }
1.1062 raeburn 4479: if ( ($endblock == 0) || ($endblock < $end) ) {
4480: $endblock = $end;
4481: if ($triggertype) {
4482: $triggerblock = $blocker;
4483: }
4484: }
1.474 raeburn 4485: }
4486: }
1.1062 raeburn 4487: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4488: }
4489:
4490: sub parse_block_record {
4491: my ($record) = @_;
4492: my ($setuname,$setudom,$title,$blocks);
4493: if (ref($record) eq 'HASH') {
4494: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4495: $title = &unescape($record->{'event'});
4496: $blocks = $record->{'blocks'};
4497: } else {
4498: my @data = split(/:/,$record,3);
4499: if (scalar(@data) eq 2) {
4500: $title = $data[1];
4501: ($setuname,$setudom) = split(/@/,$data[0]);
4502: } else {
4503: ($setuname,$setudom,$title) = @data;
4504: }
4505: $blocks = { 'com' => 'on' };
4506: }
4507: return ($setuname,$setudom,$title,$blocks);
4508: }
4509:
1.854 kalberla 4510: sub blocking_status {
1.1062 raeburn 4511: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4512: my %setters;
1.890 droeschl 4513:
1.1061 raeburn 4514: # check for active blocking
1.1062 raeburn 4515: my ($startblock,$endblock,$triggerblock) =
4516: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4517: my $blocked = 0;
4518: if ($startblock && $endblock) {
4519: $blocked = 1;
4520: }
1.890 droeschl 4521:
1.1061 raeburn 4522: # caller just wants to know whether a block is active
4523: if (!wantarray) { return $blocked; }
4524:
4525: # build a link to a popup window containing the details
4526: my $querystring = "?activity=$activity";
4527: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4528: if ($activity eq 'port') {
4529: $querystring .= "&udom=$udom" if $udom;
4530: $querystring .= "&uname=$uname" if $uname;
4531: } elsif ($activity eq 'docs') {
4532: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4533: }
1.1061 raeburn 4534:
4535: my $output .= <<'END_MYBLOCK';
4536: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4537: var options = "width=" + w + ",height=" + h + ",";
4538: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4539: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4540: var newWin = window.open(url, wdwName, options);
4541: newWin.focus();
4542: }
1.890 droeschl 4543: END_MYBLOCK
1.854 kalberla 4544:
1.1061 raeburn 4545: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4546:
1.1061 raeburn 4547: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4548: my $text = &mt('Communication Blocked');
4549: if ($activity eq 'docs') {
4550: $text = &mt('Content Access Blocked');
1.1063 raeburn 4551: } elsif ($activity eq 'printout') {
4552: $text = &mt('Printing Blocked');
1.1062 raeburn 4553: }
1.1061 raeburn 4554: $output .= <<"END_BLOCK";
1.867 kalberla 4555: <div class='LC_comblock'>
1.869 kalberla 4556: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4557: title='$text'>
4558: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4559: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4560: title='$text'>$text</a>
1.867 kalberla 4561: </div>
4562:
4563: END_BLOCK
1.474 raeburn 4564:
1.1061 raeburn 4565: return ($blocked, $output);
1.854 kalberla 4566: }
1.490 raeburn 4567:
1.60 matthew 4568: ###############################################
4569:
1.682 raeburn 4570: sub check_ip_acc {
4571: my ($acc)=@_;
4572: &Apache::lonxml::debug("acc is $acc");
4573: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4574: return 1;
4575: }
4576: my $allowed=0;
4577: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4578:
4579: my $name;
4580: foreach my $pattern (split(',',$acc)) {
4581: $pattern =~ s/^\s*//;
4582: $pattern =~ s/\s*$//;
4583: if ($pattern =~ /\*$/) {
4584: #35.8.*
4585: $pattern=~s/\*//;
4586: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4587: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4588: #35.8.3.[34-56]
4589: my $low=$2;
4590: my $high=$3;
4591: $pattern=$1;
4592: if ($ip =~ /^\Q$pattern\E/) {
4593: my $last=(split(/\./,$ip))[3];
4594: if ($last <=$high && $last >=$low) { $allowed=1; }
4595: }
4596: } elsif ($pattern =~ /^\*/) {
4597: #*.msu.edu
4598: $pattern=~s/\*//;
4599: if (!defined($name)) {
4600: use Socket;
4601: my $netaddr=inet_aton($ip);
4602: ($name)=gethostbyaddr($netaddr,AF_INET);
4603: }
4604: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4605: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4606: #127.0.0.1
4607: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4608: } else {
4609: #some.name.com
4610: if (!defined($name)) {
4611: use Socket;
4612: my $netaddr=inet_aton($ip);
4613: ($name)=gethostbyaddr($netaddr,AF_INET);
4614: }
4615: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4616: }
4617: if ($allowed) { last; }
4618: }
4619: return $allowed;
4620: }
4621:
4622: ###############################################
4623:
1.60 matthew 4624: =pod
4625:
1.112 bowersj2 4626: =head1 Domain Template Functions
4627:
4628: =over 4
4629:
4630: =item * &determinedomain()
1.60 matthew 4631:
4632: Inputs: $domain (usually will be undef)
4633:
1.63 www 4634: Returns: Determines which domain should be used for designs
1.60 matthew 4635:
4636: =cut
1.54 www 4637:
1.60 matthew 4638: ###############################################
1.63 www 4639: sub determinedomain {
4640: my $domain=shift;
1.531 albertel 4641: if (! $domain) {
1.60 matthew 4642: # Determine domain if we have not been given one
1.893 raeburn 4643: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4644: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4645: if ($env{'request.role.domain'}) {
4646: $domain=$env{'request.role.domain'};
1.60 matthew 4647: }
4648: }
1.63 www 4649: return $domain;
4650: }
4651: ###############################################
1.517 raeburn 4652:
1.518 albertel 4653: sub devalidate_domconfig_cache {
4654: my ($udom)=@_;
4655: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4656: }
4657:
4658: # ---------------------- Get domain configuration for a domain
4659: sub get_domainconf {
4660: my ($udom) = @_;
4661: my $cachetime=1800;
4662: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4663: if (defined($cached)) { return %{$result}; }
4664:
4665: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4666: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4667: my (%designhash,%legacy);
1.518 albertel 4668: if (keys(%domconfig) > 0) {
4669: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4670: if (keys(%{$domconfig{'login'}})) {
4671: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4672: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4673: if ($key eq 'loginvia') {
4674: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4675: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4676: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4677: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4678: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4679: $designhash{$udom.'.login.loginvia'} = $server;
4680: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4681:
4682: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4683: } else {
1.1013 raeburn 4684: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4685: }
4686: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4687: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4688: }
1.946 raeburn 4689: }
4690: }
4691: }
4692: }
4693: } else {
4694: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4695: $designhash{$udom.'.login.'.$key.'_'.$img} =
4696: $domconfig{'login'}{$key}{$img};
4697: }
1.699 raeburn 4698: }
4699: } else {
4700: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4701: }
1.632 raeburn 4702: }
4703: } else {
4704: $legacy{'login'} = 1;
1.518 albertel 4705: }
1.632 raeburn 4706: } else {
4707: $legacy{'login'} = 1;
1.518 albertel 4708: }
4709: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4710: if (keys(%{$domconfig{'rolecolors'}})) {
4711: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4712: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4713: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4714: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4715: }
1.518 albertel 4716: }
4717: }
1.632 raeburn 4718: } else {
4719: $legacy{'rolecolors'} = 1;
1.518 albertel 4720: }
1.632 raeburn 4721: } else {
4722: $legacy{'rolecolors'} = 1;
1.518 albertel 4723: }
1.948 raeburn 4724: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4725: if ($domconfig{'autoenroll'}{'co-owners'}) {
4726: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4727: }
4728: }
1.632 raeburn 4729: if (keys(%legacy) > 0) {
4730: my %legacyhash = &get_legacy_domconf($udom);
4731: foreach my $item (keys(%legacyhash)) {
4732: if ($item =~ /^\Q$udom\E\.login/) {
4733: if ($legacy{'login'}) {
4734: $designhash{$item} = $legacyhash{$item};
4735: }
4736: } else {
4737: if ($legacy{'rolecolors'}) {
4738: $designhash{$item} = $legacyhash{$item};
4739: }
1.518 albertel 4740: }
4741: }
4742: }
1.632 raeburn 4743: } else {
4744: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4745: }
4746: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4747: $cachetime);
4748: return %designhash;
4749: }
4750:
1.632 raeburn 4751: sub get_legacy_domconf {
4752: my ($udom) = @_;
4753: my %legacyhash;
4754: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4755: my $designfile = $designdir.'/'.$udom.'.tab';
4756: if (-e $designfile) {
4757: if ( open (my $fh,"<$designfile") ) {
4758: while (my $line = <$fh>) {
4759: next if ($line =~ /^\#/);
4760: chomp($line);
4761: my ($key,$val)=(split(/\=/,$line));
4762: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4763: }
4764: close($fh);
4765: }
4766: }
1.1026 raeburn 4767: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4768: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4769: }
4770: return %legacyhash;
4771: }
4772:
1.63 www 4773: =pod
4774:
1.112 bowersj2 4775: =item * &domainlogo()
1.63 www 4776:
4777: Inputs: $domain (usually will be undef)
4778:
4779: Returns: A link to a domain logo, if the domain logo exists.
4780: If the domain logo does not exist, a description of the domain.
4781:
4782: =cut
1.112 bowersj2 4783:
1.63 www 4784: ###############################################
4785: sub domainlogo {
1.517 raeburn 4786: my $domain = &determinedomain(shift);
1.518 albertel 4787: my %designhash = &get_domainconf($domain);
1.517 raeburn 4788: # See if there is a logo
4789: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4790: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4791: if ($imgsrc =~ m{^/(adm|res)/}) {
4792: if ($imgsrc =~ m{^/res/}) {
4793: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4794: &Apache::lonnet::repcopy($local_name);
4795: }
4796: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4797: }
4798: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4799: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4800: return &Apache::lonnet::domain($domain,'description');
1.59 www 4801: } else {
1.60 matthew 4802: return '';
1.59 www 4803: }
4804: }
1.63 www 4805: ##############################################
4806:
4807: =pod
4808:
1.112 bowersj2 4809: =item * &designparm()
1.63 www 4810:
4811: Inputs: $which parameter; $domain (usually will be undef)
4812:
4813: Returns: value of designparamter $which
4814:
4815: =cut
1.112 bowersj2 4816:
1.397 albertel 4817:
1.400 albertel 4818: ##############################################
1.397 albertel 4819: sub designparm {
4820: my ($which,$domain)=@_;
4821: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4822: return $env{'environment.color.'.$which};
1.96 www 4823: }
1.63 www 4824: $domain=&determinedomain($domain);
1.1016 raeburn 4825: my %domdesign;
4826: unless ($domain eq 'public') {
4827: %domdesign = &get_domainconf($domain);
4828: }
1.520 raeburn 4829: my $output;
1.517 raeburn 4830: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4831: $output = $domdesign{$domain.'.'.$which};
1.63 www 4832: } else {
1.520 raeburn 4833: $output = $defaultdesign{$which};
4834: }
4835: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4836: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4837: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4838: if ($output =~ m{^/res/}) {
4839: my $local_name = &Apache::lonnet::filelocation('',$output);
4840: &Apache::lonnet::repcopy($local_name);
4841: }
1.520 raeburn 4842: $output = &lonhttpdurl($output);
4843: }
1.63 www 4844: }
1.520 raeburn 4845: return $output;
1.63 www 4846: }
1.59 www 4847:
1.822 bisitz 4848: ##############################################
4849: =pod
4850:
1.832 bisitz 4851: =item * &authorspace()
4852:
1.1028 raeburn 4853: Inputs: $url (usually will be undef).
1.832 bisitz 4854:
1.1075.2.40 raeburn 4855: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4856: directory being viewed (or for which action is being taken).
4857: If $url is provided, and begins /priv/<domain>/<uname>
4858: the path will be that portion of the $context argument.
4859: Otherwise the path will be for the author space of the current
4860: user when the current role is author, or for that of the
4861: co-author/assistant co-author space when the current role
4862: is co-author or assistant co-author.
1.832 bisitz 4863:
4864: =cut
4865:
4866: sub authorspace {
1.1028 raeburn 4867: my ($url) = @_;
4868: if ($url ne '') {
4869: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4870: return $1;
4871: }
4872: }
1.832 bisitz 4873: my $caname = '';
1.1024 www 4874: my $cadom = '';
1.1028 raeburn 4875: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4876: ($cadom,$caname) =
1.832 bisitz 4877: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4878: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4879: $caname = $env{'user.name'};
1.1024 www 4880: $cadom = $env{'user.domain'};
1.832 bisitz 4881: }
1.1028 raeburn 4882: if (($caname ne '') && ($cadom ne '')) {
4883: return "/priv/$cadom/$caname/";
4884: }
4885: return;
1.832 bisitz 4886: }
4887:
4888: ##############################################
4889: =pod
4890:
1.822 bisitz 4891: =item * &head_subbox()
4892:
4893: Inputs: $content (contains HTML code with page functions, etc.)
4894:
4895: Returns: HTML div with $content
4896: To be included in page header
4897:
4898: =cut
4899:
4900: sub head_subbox {
4901: my ($content)=@_;
4902: my $output =
1.993 raeburn 4903: '<div class="LC_head_subbox">'
1.822 bisitz 4904: .$content
4905: .'</div>'
4906: }
4907:
4908: ##############################################
4909: =pod
4910:
4911: =item * &CSTR_pageheader()
4912:
1.1026 raeburn 4913: Input: (optional) filename from which breadcrumb trail is built.
4914: In most cases no input as needed, as $env{'request.filename'}
4915: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4916:
4917: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 4918: To be included on Authoring Space pages
1.822 bisitz 4919:
4920: =cut
4921:
4922: sub CSTR_pageheader {
1.1026 raeburn 4923: my ($trailfile) = @_;
4924: if ($trailfile eq '') {
4925: $trailfile = $env{'request.filename'};
4926: }
4927:
4928: # this is for resources; directories have customtitle, and crumbs
4929: # and select recent are created in lonpubdir.pm
4930:
4931: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 4932: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 4933: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 4934: my $formaction = "/priv/$udom/$uname/$thisdisfn";
4935: $formaction =~ s{/+}{/}g;
1.822 bisitz 4936:
4937: my $parentpath = '';
4938: my $lastitem = '';
4939: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4940: $parentpath = $1;
4941: $lastitem = $2;
4942: } else {
4943: $lastitem = $thisdisfn;
4944: }
1.921 bisitz 4945:
4946: my $output =
1.822 bisitz 4947: '<div>'
4948: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 4949: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 4950: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4951: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 4952: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 4953:
4954: if ($lastitem) {
4955: $output .=
4956: '<span class="LC_filename">'
4957: .$lastitem
4958: .'</span>';
4959: }
4960: $output .=
4961: '<br />'
1.822 bisitz 4962: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4963: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4964: .'</form>'
4965: .&Apache::lonmenu::constspaceform()
4966: .'</div>';
1.921 bisitz 4967:
4968: return $output;
1.822 bisitz 4969: }
4970:
1.60 matthew 4971: ###############################################
4972: ###############################################
4973:
4974: =pod
4975:
1.112 bowersj2 4976: =back
4977:
1.549 albertel 4978: =head1 HTML Helpers
1.112 bowersj2 4979:
4980: =over 4
4981:
4982: =item * &bodytag()
1.60 matthew 4983:
4984: Returns a uniform header for LON-CAPA web pages.
4985:
4986: Inputs:
4987:
1.112 bowersj2 4988: =over 4
4989:
4990: =item * $title, A title to be displayed on the page.
4991:
4992: =item * $function, the current role (can be undef).
4993:
4994: =item * $addentries, extra parameters for the <body> tag.
4995:
4996: =item * $bodyonly, if defined, only return the <body> tag.
4997:
4998: =item * $domain, if defined, force a given domain.
4999:
5000: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5001: text interface only)
1.60 matthew 5002:
1.814 bisitz 5003: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5004: navigational links
1.317 albertel 5005:
1.338 albertel 5006: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5007:
1.1075.2.12 raeburn 5008: =item * $no_inline_link, if true and in remote mode, don't show the
5009: 'Switch To Inline Menu' link
5010:
1.460 albertel 5011: =item * $args, optional argument valid values are
5012: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5013: inherit_jsmath -> when creating popup window in a page,
5014: should it have jsmath forced on by the
5015: current page
1.460 albertel 5016:
1.1075.2.15 raeburn 5017: =item * $advtoolsref, optional argument, ref to an array containing
5018: inlineremote items to be added in "Functions" menu below
5019: breadcrumbs.
5020:
1.112 bowersj2 5021: =back
5022:
1.60 matthew 5023: Returns: A uniform header for LON-CAPA web pages.
5024: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5025: If $bodyonly is undef or zero, an html string containing a <body> tag and
5026: other decorations will be returned.
5027:
5028: =cut
5029:
1.54 www 5030: sub bodytag {
1.831 bisitz 5031: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5032: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5033:
1.954 raeburn 5034: my $public;
5035: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5036: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5037: $public = 1;
5038: }
1.460 albertel 5039: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 5040:
1.183 matthew 5041: $function = &get_users_function() if (!$function);
1.339 albertel 5042: my $img = &designparm($function.'.img',$domain);
5043: my $font = &designparm($function.'.font',$domain);
5044: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5045:
1.803 bisitz 5046: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5047: 'bgcolor' => $pgbg,
1.339 albertel 5048: 'text' => $font,
5049: 'alink' => &designparm($function.'.alink',$domain),
5050: 'vlink' => &designparm($function.'.vlink',$domain),
5051: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5052: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5053:
1.63 www 5054: # role and realm
1.378 raeburn 5055: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5056: if ($role eq 'ca') {
1.479 albertel 5057: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5058: $realm = &plainname($rname,$rdom);
1.378 raeburn 5059: }
1.55 www 5060: # realm
1.258 albertel 5061: if ($env{'request.course.id'}) {
1.378 raeburn 5062: if ($env{'request.role'} !~ /^cr/) {
5063: $role = &Apache::lonnet::plaintext($role,&course_type());
5064: }
1.898 raeburn 5065: if ($env{'request.course.sec'}) {
5066: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5067: }
1.359 albertel 5068: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5069: } else {
5070: $role = &Apache::lonnet::plaintext($role);
1.54 www 5071: }
1.433 albertel 5072:
1.359 albertel 5073: if (!$realm) { $realm=' '; }
1.330 albertel 5074:
1.438 albertel 5075: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5076:
1.101 www 5077: # construct main body tag
1.359 albertel 5078: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5079: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5080:
1.1075.2.38 raeburn 5081: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5082:
5083: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5084: return $bodytag;
1.1075.2.38 raeburn 5085: }
1.359 albertel 5086:
1.954 raeburn 5087: if ($public) {
1.433 albertel 5088: undef($role);
5089: }
1.359 albertel 5090:
1.762 bisitz 5091: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5092: #
5093: # Extra info if you are the DC
5094: my $dc_info = '';
5095: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5096: $env{'course.'.$env{'request.course.id'}.
5097: '.domain'}.'/'})) {
5098: my $cid = $env{'request.course.id'};
1.917 raeburn 5099: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5100: $dc_info =~ s/\s+$//;
1.359 albertel 5101: }
5102:
1.898 raeburn 5103: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.903 droeschl 5104:
1.1075.2.13 raeburn 5105: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5106:
1.1075.2.38 raeburn 5107:
5108:
1.1075.2.21 raeburn 5109: my $funclist;
5110: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
5111: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions(), 'start')."\n".
5112: Apache::lonmenu::serverform();
5113: my $forbodytag;
5114: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5115: $forcereg,$args->{'group'},
5116: $args->{'bread_crumbs'},
5117: $advtoolsref,'',\$forbodytag);
5118: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5119: $funclist = $forbodytag;
5120: }
5121: } else {
1.903 droeschl 5122:
5123: # if ($env{'request.state'} eq 'construct') {
5124: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5125: # }
5126:
1.1075.2.38 raeburn 5127: $bodytag .= Apache::lonhtmlcommon::scripttag(
5128: Apache::lonmenu::utilityfunctions(), 'start');
1.359 albertel 5129:
1.1075.2.38 raeburn 5130: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5131:
1.916 droeschl 5132: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5133: if ($dc_info) {
5134: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5135: }
1.1075.2.38 raeburn 5136: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5137: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5138: return $bodytag;
5139: }
1.894 droeschl 5140:
1.927 raeburn 5141: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5142: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5143: }
1.916 droeschl 5144:
1.1075.2.38 raeburn 5145: $bodytag .= $right;
1.852 droeschl 5146:
1.917 raeburn 5147: if ($dc_info) {
5148: $dc_info = &dc_courseid_toggle($dc_info);
5149: }
5150: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5151:
1.903 droeschl 5152: #don't show menus for public users
1.954 raeburn 5153: if (!$public){
1.903 droeschl 5154: $bodytag .= Apache::lonmenu::secondary_menu();
5155: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5156: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5157: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5158: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5159: $args->{'bread_crumbs'});
5160: } elsif ($forcereg) {
1.1075.2.22 raeburn 5161: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5162: $args->{'group'});
1.1075.2.15 raeburn 5163: } else {
1.1075.2.21 raeburn 5164: my $forbodytag;
5165: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5166: $forcereg,$args->{'group'},
5167: $args->{'bread_crumbs'},
5168: $advtoolsref,'',\$forbodytag);
5169: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5170: $bodytag .= $forbodytag;
5171: }
1.920 raeburn 5172: }
1.903 droeschl 5173: }else{
5174: # this is to seperate menu from content when there's no secondary
5175: # menu. Especially needed for public accessible ressources.
5176: $bodytag .= '<hr style="clear:both" />';
5177: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5178: }
1.903 droeschl 5179:
1.235 raeburn 5180: return $bodytag;
1.1075.2.12 raeburn 5181: }
5182:
5183: #
5184: # Top frame rendering, Remote is up
5185: #
5186:
5187: my $imgsrc = $img;
5188: if ($img =~ /^\/adm/) {
5189: $imgsrc = &lonhttpdurl($img);
5190: }
5191: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5192:
5193: # Explicit link to get inline menu
5194: my $menu= ($no_inline_link?''
5195: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5196:
5197: if ($dc_info) {
5198: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5199: }
5200:
1.1075.2.38 raeburn 5201: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5202: unless ($public) {
5203: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5204: undef,'LC_menubuttons_link');
5205: }
5206:
1.1075.2.12 raeburn 5207: unless ($env{'form.inhibitmenu'}) {
5208: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5209: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.12 raeburn 5210: <li>$menu</li>
5211: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5212: }
1.1075.2.13 raeburn 5213: if ($env{'request.state'} eq 'construct') {
5214: if (!$public){
5215: if ($env{'request.state'} eq 'construct') {
5216: $funclist = &Apache::lonhtmlcommon::scripttag(
5217: &Apache::lonmenu::utilityfunctions(), 'start').
5218: &Apache::lonhtmlcommon::scripttag('','end').
5219: &Apache::lonmenu::innerregister($forcereg,
5220: $args->{'bread_crumbs'});
5221: }
5222: }
5223: }
1.1075.2.21 raeburn 5224: return $bodytag."\n".$funclist;
1.182 matthew 5225: }
5226:
1.917 raeburn 5227: sub dc_courseid_toggle {
5228: my ($dc_info) = @_;
1.980 raeburn 5229: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5230: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5231: &mt('(More ...)').'</a></span>'.
5232: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5233: }
5234:
1.330 albertel 5235: sub make_attr_string {
5236: my ($register,$attr_ref) = @_;
5237:
5238: if ($attr_ref && !ref($attr_ref)) {
5239: die("addentries Must be a hash ref ".
5240: join(':',caller(1))." ".
5241: join(':',caller(0))." ");
5242: }
5243:
5244: if ($register) {
1.339 albertel 5245: my ($on_load,$on_unload);
5246: foreach my $key (keys(%{$attr_ref})) {
5247: if (lc($key) eq 'onload') {
5248: $on_load.=$attr_ref->{$key}.';';
5249: delete($attr_ref->{$key});
5250:
5251: } elsif (lc($key) eq 'onunload') {
5252: $on_unload.=$attr_ref->{$key}.';';
5253: delete($attr_ref->{$key});
5254: }
5255: }
1.1075.2.12 raeburn 5256: if ($env{'environment.remote'} eq 'on') {
5257: $attr_ref->{'onload'} =
5258: &Apache::lonmenu::loadevents(). $on_load;
5259: $attr_ref->{'onunload'}=
5260: &Apache::lonmenu::unloadevents().$on_unload;
5261: } else {
5262: $attr_ref->{'onload'} = $on_load;
5263: $attr_ref->{'onunload'}= $on_unload;
5264: }
1.330 albertel 5265: }
1.339 albertel 5266:
1.330 albertel 5267: my $attr_string;
5268: foreach my $attr (keys(%$attr_ref)) {
5269: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5270: }
5271: return $attr_string;
5272: }
5273:
5274:
1.182 matthew 5275: ###############################################
1.251 albertel 5276: ###############################################
5277:
5278: =pod
5279:
5280: =item * &endbodytag()
5281:
5282: Returns a uniform footer for LON-CAPA web pages.
5283:
1.635 raeburn 5284: Inputs: 1 - optional reference to an args hash
5285: If in the hash, key for noredirectlink has a value which evaluates to true,
5286: a 'Continue' link is not displayed if the page contains an
5287: internal redirect in the <head></head> section,
5288: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5289:
5290: =cut
5291:
5292: sub endbodytag {
1.635 raeburn 5293: my ($args) = @_;
1.1075.2.6 raeburn 5294: my $endbodytag;
5295: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5296: $endbodytag='</body>';
5297: }
1.269 albertel 5298: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5299: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5300: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5301: $endbodytag=
5302: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5303: &mt('Continue').'</a>'.
5304: $endbodytag;
5305: }
1.315 albertel 5306: }
1.251 albertel 5307: return $endbodytag;
5308: }
5309:
1.352 albertel 5310: =pod
5311:
5312: =item * &standard_css()
5313:
5314: Returns a style sheet
5315:
5316: Inputs: (all optional)
5317: domain -> force to color decorate a page for a specific
5318: domain
5319: function -> force usage of a specific rolish color scheme
5320: bgcolor -> override the default page bgcolor
5321:
5322: =cut
5323:
1.343 albertel 5324: sub standard_css {
1.345 albertel 5325: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5326: $function = &get_users_function() if (!$function);
5327: my $img = &designparm($function.'.img', $domain);
5328: my $tabbg = &designparm($function.'.tabbg', $domain);
5329: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5330: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5331: #second colour for later usage
1.345 albertel 5332: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5333: my $pgbg_or_bgcolor =
5334: $bgcolor ||
1.352 albertel 5335: &designparm($function.'.pgbg', $domain);
1.382 albertel 5336: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5337: my $alink = &designparm($function.'.alink', $domain);
5338: my $vlink = &designparm($function.'.vlink', $domain);
5339: my $link = &designparm($function.'.link', $domain);
5340:
1.602 albertel 5341: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5342: my $mono = 'monospace';
1.850 bisitz 5343: my $data_table_head = $sidebg;
5344: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5345: my $data_table_dark = '#E0E0E0';
1.470 banghart 5346: my $data_table_darker = '#CCCCCC';
1.349 albertel 5347: my $data_table_highlight = '#FFFF00';
1.352 albertel 5348: my $mail_new = '#FFBB77';
5349: my $mail_new_hover = '#DD9955';
5350: my $mail_read = '#BBBB77';
5351: my $mail_read_hover = '#999944';
5352: my $mail_replied = '#AAAA88';
5353: my $mail_replied_hover = '#888855';
5354: my $mail_other = '#99BBBB';
5355: my $mail_other_hover = '#669999';
1.391 albertel 5356: my $table_header = '#DDDDDD';
1.489 raeburn 5357: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5358: my $lg_border_color = '#C8C8C8';
1.952 onken 5359: my $button_hover = '#BF2317';
1.392 albertel 5360:
1.608 albertel 5361: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5362: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5363: : '0 3px 0 4px';
1.448 albertel 5364:
1.523 albertel 5365:
1.343 albertel 5366: return <<END;
1.947 droeschl 5367:
5368: /* needed for iframe to allow 100% height in FF */
5369: body, html {
5370: margin: 0;
5371: padding: 0 0.5%;
5372: height: 99%; /* to avoid scrollbars */
5373: }
5374:
1.795 www 5375: body {
1.911 bisitz 5376: font-family: $sans;
5377: line-height:130%;
5378: font-size:0.83em;
5379: color:$font;
1.795 www 5380: }
5381:
1.959 onken 5382: a:focus,
5383: a:focus img {
1.795 www 5384: color: red;
5385: }
1.698 harmsja 5386:
1.911 bisitz 5387: form, .inline {
5388: display: inline;
1.795 www 5389: }
1.721 harmsja 5390:
1.795 www 5391: .LC_right {
1.911 bisitz 5392: text-align:right;
1.795 www 5393: }
5394:
5395: .LC_middle {
1.911 bisitz 5396: vertical-align:middle;
1.795 www 5397: }
1.721 harmsja 5398:
1.1075.2.38 raeburn 5399: .LC_floatleft {
5400: float: left;
5401: }
5402:
5403: .LC_floatright {
5404: float: right;
5405: }
5406:
1.911 bisitz 5407: .LC_400Box {
5408: width:400px;
5409: }
1.721 harmsja 5410:
1.947 droeschl 5411: .LC_iframecontainer {
5412: width: 98%;
5413: margin: 0;
5414: position: fixed;
5415: top: 8.5em;
5416: bottom: 0;
5417: }
5418:
5419: .LC_iframecontainer iframe{
5420: border: none;
5421: width: 100%;
5422: height: 100%;
5423: }
5424:
1.778 bisitz 5425: .LC_filename {
5426: font-family: $mono;
5427: white-space:pre;
1.921 bisitz 5428: font-size: 120%;
1.778 bisitz 5429: }
5430:
5431: .LC_fileicon {
5432: border: none;
5433: height: 1.3em;
5434: vertical-align: text-bottom;
5435: margin-right: 0.3em;
5436: text-decoration:none;
5437: }
5438:
1.1008 www 5439: .LC_setting {
5440: text-decoration:underline;
5441: }
5442:
1.350 albertel 5443: .LC_error {
5444: color: red;
5445: }
1.795 www 5446:
1.1075.2.15 raeburn 5447: .LC_warning {
5448: color: darkorange;
5449: }
5450:
1.457 albertel 5451: .LC_diff_removed {
1.733 bisitz 5452: color: red;
1.394 albertel 5453: }
1.532 albertel 5454:
5455: .LC_info,
1.457 albertel 5456: .LC_success,
5457: .LC_diff_added {
1.350 albertel 5458: color: green;
5459: }
1.795 www 5460:
1.802 bisitz 5461: div.LC_confirm_box {
5462: background-color: #FAFAFA;
5463: border: 1px solid $lg_border_color;
5464: margin-right: 0;
5465: padding: 5px;
5466: }
5467:
5468: div.LC_confirm_box .LC_error img,
5469: div.LC_confirm_box .LC_success img {
5470: vertical-align: middle;
5471: }
5472:
1.440 albertel 5473: .LC_icon {
1.771 droeschl 5474: border: none;
1.790 droeschl 5475: vertical-align: middle;
1.771 droeschl 5476: }
5477:
1.543 albertel 5478: .LC_docs_spacer {
5479: width: 25px;
5480: height: 1px;
1.771 droeschl 5481: border: none;
1.543 albertel 5482: }
1.346 albertel 5483:
1.532 albertel 5484: .LC_internal_info {
1.735 bisitz 5485: color: #999999;
1.532 albertel 5486: }
5487:
1.794 www 5488: .LC_discussion {
1.1050 www 5489: background: $data_table_dark;
1.911 bisitz 5490: border: 1px solid black;
5491: margin: 2px;
1.794 www 5492: }
5493:
5494: .LC_disc_action_left {
1.1050 www 5495: background: $sidebg;
1.911 bisitz 5496: text-align: left;
1.1050 www 5497: padding: 4px;
5498: margin: 2px;
1.794 www 5499: }
5500:
5501: .LC_disc_action_right {
1.1050 www 5502: background: $sidebg;
1.911 bisitz 5503: text-align: right;
1.1050 www 5504: padding: 4px;
5505: margin: 2px;
1.794 www 5506: }
5507:
5508: .LC_disc_new_item {
1.911 bisitz 5509: background: white;
5510: border: 2px solid red;
1.1050 www 5511: margin: 4px;
5512: padding: 4px;
1.794 www 5513: }
5514:
5515: .LC_disc_old_item {
1.911 bisitz 5516: background: white;
1.1050 www 5517: margin: 4px;
5518: padding: 4px;
1.794 www 5519: }
5520:
1.458 albertel 5521: table.LC_pastsubmission {
5522: border: 1px solid black;
5523: margin: 2px;
5524: }
5525:
1.924 bisitz 5526: table#LC_menubuttons {
1.345 albertel 5527: width: 100%;
5528: background: $pgbg;
1.392 albertel 5529: border: 2px;
1.402 albertel 5530: border-collapse: separate;
1.803 bisitz 5531: padding: 0;
1.345 albertel 5532: }
1.392 albertel 5533:
1.801 tempelho 5534: table#LC_title_bar a {
5535: color: $fontmenu;
5536: }
1.836 bisitz 5537:
1.807 droeschl 5538: table#LC_title_bar {
1.819 tempelho 5539: clear: both;
1.836 bisitz 5540: display: none;
1.807 droeschl 5541: }
5542:
1.795 www 5543: table#LC_title_bar,
1.933 droeschl 5544: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5545: table#LC_title_bar.LC_with_remote {
1.359 albertel 5546: width: 100%;
1.392 albertel 5547: border-color: $pgbg;
5548: border-style: solid;
5549: border-width: $border;
1.379 albertel 5550: background: $pgbg;
1.801 tempelho 5551: color: $fontmenu;
1.392 albertel 5552: border-collapse: collapse;
1.803 bisitz 5553: padding: 0;
1.819 tempelho 5554: margin: 0;
1.359 albertel 5555: }
1.795 www 5556:
1.933 droeschl 5557: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5558: margin: 0;
5559: padding: 0;
1.933 droeschl 5560: position: relative;
5561: list-style: none;
1.913 droeschl 5562: }
1.933 droeschl 5563: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5564: display: inline;
5565: }
1.933 droeschl 5566:
5567: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5568: padding: 0;
1.933 droeschl 5569: margin: 0;
5570: float: left;
1.913 droeschl 5571: }
1.933 droeschl 5572: .LC_breadcrumb_tools_tools {
5573: padding: 0;
5574: margin: 0;
1.913 droeschl 5575: float: right;
5576: }
5577:
1.359 albertel 5578: table#LC_title_bar td {
5579: background: $tabbg;
5580: }
1.795 www 5581:
1.911 bisitz 5582: table#LC_menubuttons img {
1.803 bisitz 5583: border: none;
1.346 albertel 5584: }
1.795 www 5585:
1.842 droeschl 5586: .LC_breadcrumbs_component {
1.911 bisitz 5587: float: right;
5588: margin: 0 1em;
1.357 albertel 5589: }
1.842 droeschl 5590: .LC_breadcrumbs_component img {
1.911 bisitz 5591: vertical-align: middle;
1.777 tempelho 5592: }
1.795 www 5593:
1.383 albertel 5594: td.LC_table_cell_checkbox {
5595: text-align: center;
5596: }
1.795 www 5597:
5598: .LC_fontsize_small {
1.911 bisitz 5599: font-size: 70%;
1.705 tempelho 5600: }
5601:
1.844 bisitz 5602: #LC_breadcrumbs {
1.911 bisitz 5603: clear:both;
5604: background: $sidebg;
5605: border-bottom: 1px solid $lg_border_color;
5606: line-height: 2.5em;
1.933 droeschl 5607: overflow: hidden;
1.911 bisitz 5608: margin: 0;
5609: padding: 0;
1.995 raeburn 5610: text-align: left;
1.819 tempelho 5611: }
1.862 bisitz 5612:
1.1075.2.16 raeburn 5613: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5614: clear:both;
5615: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5616: border: 1px solid $sidebg;
1.1075.2.16 raeburn 5617: margin: 0 0 10px 0;
1.966 bisitz 5618: padding: 3px;
1.995 raeburn 5619: text-align: left;
1.822 bisitz 5620: }
5621:
1.795 www 5622: .LC_fontsize_medium {
1.911 bisitz 5623: font-size: 85%;
1.705 tempelho 5624: }
5625:
1.795 www 5626: .LC_fontsize_large {
1.911 bisitz 5627: font-size: 120%;
1.705 tempelho 5628: }
5629:
1.346 albertel 5630: .LC_menubuttons_inline_text {
5631: color: $font;
1.698 harmsja 5632: font-size: 90%;
1.701 harmsja 5633: padding-left:3px;
1.346 albertel 5634: }
5635:
1.934 droeschl 5636: .LC_menubuttons_inline_text img{
5637: vertical-align: middle;
5638: }
5639:
1.1051 www 5640: li.LC_menubuttons_inline_text img {
1.951 onken 5641: cursor:pointer;
1.1002 droeschl 5642: text-decoration: none;
1.951 onken 5643: }
5644:
1.526 www 5645: .LC_menubuttons_link {
5646: text-decoration: none;
5647: }
1.795 www 5648:
1.522 albertel 5649: .LC_menubuttons_category {
1.521 www 5650: color: $font;
1.526 www 5651: background: $pgbg;
1.521 www 5652: font-size: larger;
5653: font-weight: bold;
5654: }
5655:
1.346 albertel 5656: td.LC_menubuttons_text {
1.911 bisitz 5657: color: $font;
1.346 albertel 5658: }
1.706 harmsja 5659:
1.346 albertel 5660: .LC_current_location {
5661: background: $tabbg;
5662: }
1.795 www 5663:
1.938 bisitz 5664: table.LC_data_table {
1.347 albertel 5665: border: 1px solid #000000;
1.402 albertel 5666: border-collapse: separate;
1.426 albertel 5667: border-spacing: 1px;
1.610 albertel 5668: background: $pgbg;
1.347 albertel 5669: }
1.795 www 5670:
1.422 albertel 5671: .LC_data_table_dense {
5672: font-size: small;
5673: }
1.795 www 5674:
1.507 raeburn 5675: table.LC_nested_outer {
5676: border: 1px solid #000000;
1.589 raeburn 5677: border-collapse: collapse;
1.803 bisitz 5678: border-spacing: 0;
1.507 raeburn 5679: width: 100%;
5680: }
1.795 www 5681:
1.879 raeburn 5682: table.LC_innerpickbox,
1.507 raeburn 5683: table.LC_nested {
1.803 bisitz 5684: border: none;
1.589 raeburn 5685: border-collapse: collapse;
1.803 bisitz 5686: border-spacing: 0;
1.507 raeburn 5687: width: 100%;
5688: }
1.795 www 5689:
1.911 bisitz 5690: table.LC_data_table tr th,
5691: table.LC_calendar tr th,
1.879 raeburn 5692: table.LC_prior_tries tr th,
5693: table.LC_innerpickbox tr th {
1.349 albertel 5694: font-weight: bold;
5695: background-color: $data_table_head;
1.801 tempelho 5696: color:$fontmenu;
1.701 harmsja 5697: font-size:90%;
1.347 albertel 5698: }
1.795 www 5699:
1.879 raeburn 5700: table.LC_innerpickbox tr th,
5701: table.LC_innerpickbox tr td {
5702: vertical-align: top;
5703: }
5704:
1.711 raeburn 5705: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5706: background-color: #CCCCCC;
1.711 raeburn 5707: font-weight: bold;
5708: text-align: left;
5709: }
1.795 www 5710:
1.912 bisitz 5711: table.LC_data_table tr.LC_odd_row > td {
5712: background-color: $data_table_light;
5713: padding: 2px;
5714: vertical-align: top;
5715: }
5716:
1.809 bisitz 5717: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5718: background-color: $data_table_light;
1.912 bisitz 5719: vertical-align: top;
5720: }
5721:
5722: table.LC_data_table tr.LC_even_row > td {
5723: background-color: $data_table_dark;
1.425 albertel 5724: padding: 2px;
1.900 bisitz 5725: vertical-align: top;
1.347 albertel 5726: }
1.795 www 5727:
1.809 bisitz 5728: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5729: background-color: $data_table_dark;
1.900 bisitz 5730: vertical-align: top;
1.347 albertel 5731: }
1.795 www 5732:
1.425 albertel 5733: table.LC_data_table tr.LC_data_table_highlight td {
5734: background-color: $data_table_darker;
5735: }
1.795 www 5736:
1.639 raeburn 5737: table.LC_data_table tr td.LC_leftcol_header {
5738: background-color: $data_table_head;
5739: font-weight: bold;
5740: }
1.795 www 5741:
1.451 albertel 5742: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5743: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5744: font-weight: bold;
5745: font-style: italic;
5746: text-align: center;
5747: padding: 8px;
1.347 albertel 5748: }
1.795 www 5749:
1.1075.2.30 raeburn 5750: table.LC_data_table tr.LC_empty_row td,
5751: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5752: background-color: $sidebg;
5753: }
5754:
5755: table.LC_nested tr.LC_empty_row td {
5756: background-color: #FFFFFF;
5757: }
5758:
1.890 droeschl 5759: table.LC_caption {
5760: }
5761:
1.507 raeburn 5762: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5763: padding: 4ex
5764: }
1.795 www 5765:
1.507 raeburn 5766: table.LC_nested_outer tr th {
5767: font-weight: bold;
1.801 tempelho 5768: color:$fontmenu;
1.507 raeburn 5769: background-color: $data_table_head;
1.701 harmsja 5770: font-size: small;
1.507 raeburn 5771: border-bottom: 1px solid #000000;
5772: }
1.795 www 5773:
1.507 raeburn 5774: table.LC_nested_outer tr td.LC_subheader {
5775: background-color: $data_table_head;
5776: font-weight: bold;
5777: font-size: small;
5778: border-bottom: 1px solid #000000;
5779: text-align: right;
1.451 albertel 5780: }
1.795 www 5781:
1.507 raeburn 5782: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5783: background-color: #CCCCCC;
1.451 albertel 5784: font-weight: bold;
5785: font-size: small;
1.507 raeburn 5786: text-align: center;
5787: }
1.795 www 5788:
1.589 raeburn 5789: table.LC_nested tr.LC_info_row td.LC_left_item,
5790: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5791: text-align: left;
1.451 albertel 5792: }
1.795 www 5793:
1.507 raeburn 5794: table.LC_nested td {
1.735 bisitz 5795: background-color: #FFFFFF;
1.451 albertel 5796: font-size: small;
1.507 raeburn 5797: }
1.795 www 5798:
1.507 raeburn 5799: table.LC_nested_outer tr th.LC_right_item,
5800: table.LC_nested tr.LC_info_row td.LC_right_item,
5801: table.LC_nested tr.LC_odd_row td.LC_right_item,
5802: table.LC_nested tr td.LC_right_item {
1.451 albertel 5803: text-align: right;
5804: }
5805:
1.507 raeburn 5806: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5807: background-color: #EEEEEE;
1.451 albertel 5808: }
5809:
1.473 raeburn 5810: table.LC_createuser {
5811: }
5812:
5813: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5814: font-size: small;
1.473 raeburn 5815: }
5816:
5817: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5818: background-color: #CCCCCC;
1.473 raeburn 5819: font-weight: bold;
5820: text-align: center;
5821: }
5822:
1.349 albertel 5823: table.LC_calendar {
5824: border: 1px solid #000000;
5825: border-collapse: collapse;
1.917 raeburn 5826: width: 98%;
1.349 albertel 5827: }
1.795 www 5828:
1.349 albertel 5829: table.LC_calendar_pickdate {
5830: font-size: xx-small;
5831: }
1.795 www 5832:
1.349 albertel 5833: table.LC_calendar tr td {
5834: border: 1px solid #000000;
5835: vertical-align: top;
1.917 raeburn 5836: width: 14%;
1.349 albertel 5837: }
1.795 www 5838:
1.349 albertel 5839: table.LC_calendar tr td.LC_calendar_day_empty {
5840: background-color: $data_table_dark;
5841: }
1.795 www 5842:
1.779 bisitz 5843: table.LC_calendar tr td.LC_calendar_day_current {
5844: background-color: $data_table_highlight;
1.777 tempelho 5845: }
1.795 www 5846:
1.938 bisitz 5847: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5848: background-color: $mail_new;
5849: }
1.795 www 5850:
1.938 bisitz 5851: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5852: background-color: $mail_new_hover;
5853: }
1.795 www 5854:
1.938 bisitz 5855: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5856: background-color: $mail_read;
5857: }
1.795 www 5858:
1.938 bisitz 5859: /*
5860: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5861: background-color: $mail_read_hover;
5862: }
1.938 bisitz 5863: */
1.795 www 5864:
1.938 bisitz 5865: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5866: background-color: $mail_replied;
5867: }
1.795 www 5868:
1.938 bisitz 5869: /*
5870: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5871: background-color: $mail_replied_hover;
5872: }
1.938 bisitz 5873: */
1.795 www 5874:
1.938 bisitz 5875: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5876: background-color: $mail_other;
5877: }
1.795 www 5878:
1.938 bisitz 5879: /*
5880: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5881: background-color: $mail_other_hover;
5882: }
1.938 bisitz 5883: */
1.494 raeburn 5884:
1.777 tempelho 5885: table.LC_data_table tr > td.LC_browser_file,
5886: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5887: background: #AAEE77;
1.389 albertel 5888: }
1.795 www 5889:
1.777 tempelho 5890: table.LC_data_table tr > td.LC_browser_file_locked,
5891: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5892: background: #FFAA99;
1.387 albertel 5893: }
1.795 www 5894:
1.777 tempelho 5895: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5896: background: #888888;
1.779 bisitz 5897: }
1.795 www 5898:
1.777 tempelho 5899: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5900: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5901: background: #F8F866;
1.777 tempelho 5902: }
1.795 www 5903:
1.696 bisitz 5904: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5905: background: #E0E8FF;
1.387 albertel 5906: }
1.696 bisitz 5907:
1.707 bisitz 5908: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5909: /* background: #77FF77; */
1.707 bisitz 5910: }
1.795 www 5911:
1.707 bisitz 5912: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5913: border-right: 8px solid #FFFF77;
1.707 bisitz 5914: }
1.795 www 5915:
1.707 bisitz 5916: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5917: border-right: 8px solid #FFAA77;
1.707 bisitz 5918: }
1.795 www 5919:
1.707 bisitz 5920: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5921: border-right: 8px solid #FF7777;
1.707 bisitz 5922: }
1.795 www 5923:
1.707 bisitz 5924: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5925: border-right: 8px solid #AAFF77;
1.707 bisitz 5926: }
1.795 www 5927:
1.707 bisitz 5928: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5929: border-right: 8px solid #11CC55;
1.707 bisitz 5930: }
5931:
1.388 albertel 5932: span.LC_current_location {
1.701 harmsja 5933: font-size:larger;
1.388 albertel 5934: background: $pgbg;
5935: }
1.387 albertel 5936:
1.1029 www 5937: span.LC_current_nav_location {
5938: font-weight:bold;
5939: background: $sidebg;
5940: }
5941:
1.395 albertel 5942: span.LC_parm_menu_item {
5943: font-size: larger;
5944: }
1.795 www 5945:
1.395 albertel 5946: span.LC_parm_scope_all {
5947: color: red;
5948: }
1.795 www 5949:
1.395 albertel 5950: span.LC_parm_scope_folder {
5951: color: green;
5952: }
1.795 www 5953:
1.395 albertel 5954: span.LC_parm_scope_resource {
5955: color: orange;
5956: }
1.795 www 5957:
1.395 albertel 5958: span.LC_parm_part {
5959: color: blue;
5960: }
1.795 www 5961:
1.911 bisitz 5962: span.LC_parm_folder,
5963: span.LC_parm_symb {
1.395 albertel 5964: font-size: x-small;
5965: font-family: $mono;
5966: color: #AAAAAA;
5967: }
5968:
1.977 bisitz 5969: ul.LC_parm_parmlist li {
5970: display: inline-block;
5971: padding: 0.3em 0.8em;
5972: vertical-align: top;
5973: width: 150px;
5974: border-top:1px solid $lg_border_color;
5975: }
5976:
1.795 www 5977: td.LC_parm_overview_level_menu,
5978: td.LC_parm_overview_map_menu,
5979: td.LC_parm_overview_parm_selectors,
5980: td.LC_parm_overview_restrictions {
1.396 albertel 5981: border: 1px solid black;
5982: border-collapse: collapse;
5983: }
1.795 www 5984:
1.396 albertel 5985: table.LC_parm_overview_restrictions td {
5986: border-width: 1px 4px 1px 4px;
5987: border-style: solid;
5988: border-color: $pgbg;
5989: text-align: center;
5990: }
1.795 www 5991:
1.396 albertel 5992: table.LC_parm_overview_restrictions th {
5993: background: $tabbg;
5994: border-width: 1px 4px 1px 4px;
5995: border-style: solid;
5996: border-color: $pgbg;
5997: }
1.795 www 5998:
1.398 albertel 5999: table#LC_helpmenu {
1.803 bisitz 6000: border: none;
1.398 albertel 6001: height: 55px;
1.803 bisitz 6002: border-spacing: 0;
1.398 albertel 6003: }
6004:
6005: table#LC_helpmenu fieldset legend {
6006: font-size: larger;
6007: }
1.795 www 6008:
1.397 albertel 6009: table#LC_helpmenu_links {
6010: width: 100%;
6011: border: 1px solid black;
6012: background: $pgbg;
1.803 bisitz 6013: padding: 0;
1.397 albertel 6014: border-spacing: 1px;
6015: }
1.795 www 6016:
1.397 albertel 6017: table#LC_helpmenu_links tr td {
6018: padding: 1px;
6019: background: $tabbg;
1.399 albertel 6020: text-align: center;
6021: font-weight: bold;
1.397 albertel 6022: }
1.396 albertel 6023:
1.795 www 6024: table#LC_helpmenu_links a:link,
6025: table#LC_helpmenu_links a:visited,
1.397 albertel 6026: table#LC_helpmenu_links a:active {
6027: text-decoration: none;
6028: color: $font;
6029: }
1.795 www 6030:
1.397 albertel 6031: table#LC_helpmenu_links a:hover {
6032: text-decoration: underline;
6033: color: $vlink;
6034: }
1.396 albertel 6035:
1.417 albertel 6036: .LC_chrt_popup_exists {
6037: border: 1px solid #339933;
6038: margin: -1px;
6039: }
1.795 www 6040:
1.417 albertel 6041: .LC_chrt_popup_up {
6042: border: 1px solid yellow;
6043: margin: -1px;
6044: }
1.795 www 6045:
1.417 albertel 6046: .LC_chrt_popup {
6047: border: 1px solid #8888FF;
6048: background: #CCCCFF;
6049: }
1.795 www 6050:
1.421 albertel 6051: table.LC_pick_box {
6052: border-collapse: separate;
6053: background: white;
6054: border: 1px solid black;
6055: border-spacing: 1px;
6056: }
1.795 www 6057:
1.421 albertel 6058: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6059: background: $sidebg;
1.421 albertel 6060: font-weight: bold;
1.900 bisitz 6061: text-align: left;
1.740 bisitz 6062: vertical-align: top;
1.421 albertel 6063: width: 184px;
6064: padding: 8px;
6065: }
1.795 www 6066:
1.579 raeburn 6067: table.LC_pick_box td.LC_pick_box_value {
6068: text-align: left;
6069: padding: 8px;
6070: }
1.795 www 6071:
1.579 raeburn 6072: table.LC_pick_box td.LC_pick_box_select {
6073: text-align: left;
6074: padding: 8px;
6075: }
1.795 www 6076:
1.424 albertel 6077: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6078: padding: 0;
1.421 albertel 6079: height: 1px;
6080: background: black;
6081: }
1.795 www 6082:
1.421 albertel 6083: table.LC_pick_box td.LC_pick_box_submit {
6084: text-align: right;
6085: }
1.795 www 6086:
1.579 raeburn 6087: table.LC_pick_box td.LC_evenrow_value {
6088: text-align: left;
6089: padding: 8px;
6090: background-color: $data_table_light;
6091: }
1.795 www 6092:
1.579 raeburn 6093: table.LC_pick_box td.LC_oddrow_value {
6094: text-align: left;
6095: padding: 8px;
6096: background-color: $data_table_light;
6097: }
1.795 www 6098:
1.579 raeburn 6099: span.LC_helpform_receipt_cat {
6100: font-weight: bold;
6101: }
1.795 www 6102:
1.424 albertel 6103: table.LC_group_priv_box {
6104: background: white;
6105: border: 1px solid black;
6106: border-spacing: 1px;
6107: }
1.795 www 6108:
1.424 albertel 6109: table.LC_group_priv_box td.LC_pick_box_title {
6110: background: $tabbg;
6111: font-weight: bold;
6112: text-align: right;
6113: width: 184px;
6114: }
1.795 www 6115:
1.424 albertel 6116: table.LC_group_priv_box td.LC_groups_fixed {
6117: background: $data_table_light;
6118: text-align: center;
6119: }
1.795 www 6120:
1.424 albertel 6121: table.LC_group_priv_box td.LC_groups_optional {
6122: background: $data_table_dark;
6123: text-align: center;
6124: }
1.795 www 6125:
1.424 albertel 6126: table.LC_group_priv_box td.LC_groups_functionality {
6127: background: $data_table_darker;
6128: text-align: center;
6129: font-weight: bold;
6130: }
1.795 www 6131:
1.424 albertel 6132: table.LC_group_priv td {
6133: text-align: left;
1.803 bisitz 6134: padding: 0;
1.424 albertel 6135: }
6136:
6137: .LC_navbuttons {
6138: margin: 2ex 0ex 2ex 0ex;
6139: }
1.795 www 6140:
1.423 albertel 6141: .LC_topic_bar {
6142: font-weight: bold;
6143: background: $tabbg;
1.918 wenzelju 6144: margin: 1em 0em 1em 2em;
1.805 bisitz 6145: padding: 3px;
1.918 wenzelju 6146: font-size: 1.2em;
1.423 albertel 6147: }
1.795 www 6148:
1.423 albertel 6149: .LC_topic_bar span {
1.918 wenzelju 6150: left: 0.5em;
6151: position: absolute;
1.423 albertel 6152: vertical-align: middle;
1.918 wenzelju 6153: font-size: 1.2em;
1.423 albertel 6154: }
1.795 www 6155:
1.423 albertel 6156: table.LC_course_group_status {
6157: margin: 20px;
6158: }
1.795 www 6159:
1.423 albertel 6160: table.LC_status_selector td {
6161: vertical-align: top;
6162: text-align: center;
1.424 albertel 6163: padding: 4px;
6164: }
1.795 www 6165:
1.599 albertel 6166: div.LC_feedback_link {
1.616 albertel 6167: clear: both;
1.829 kalberla 6168: background: $sidebg;
1.779 bisitz 6169: width: 100%;
1.829 kalberla 6170: padding-bottom: 10px;
6171: border: 1px $tabbg solid;
1.833 kalberla 6172: height: 22px;
6173: line-height: 22px;
6174: padding-top: 5px;
6175: }
6176:
6177: div.LC_feedback_link img {
6178: height: 22px;
1.867 kalberla 6179: vertical-align:middle;
1.829 kalberla 6180: }
6181:
1.911 bisitz 6182: div.LC_feedback_link a {
1.829 kalberla 6183: text-decoration: none;
1.489 raeburn 6184: }
1.795 www 6185:
1.867 kalberla 6186: div.LC_comblock {
1.911 bisitz 6187: display:inline;
1.867 kalberla 6188: color:$font;
6189: font-size:90%;
6190: }
6191:
6192: div.LC_feedback_link div.LC_comblock {
6193: padding-left:5px;
6194: }
6195:
6196: div.LC_feedback_link div.LC_comblock a {
6197: color:$font;
6198: }
6199:
1.489 raeburn 6200: span.LC_feedback_link {
1.858 bisitz 6201: /* background: $feedback_link_bg; */
1.599 albertel 6202: font-size: larger;
6203: }
1.795 www 6204:
1.599 albertel 6205: span.LC_message_link {
1.858 bisitz 6206: /* background: $feedback_link_bg; */
1.599 albertel 6207: font-size: larger;
6208: position: absolute;
6209: right: 1em;
1.489 raeburn 6210: }
1.421 albertel 6211:
1.515 albertel 6212: table.LC_prior_tries {
1.524 albertel 6213: border: 1px solid #000000;
6214: border-collapse: separate;
6215: border-spacing: 1px;
1.515 albertel 6216: }
1.523 albertel 6217:
1.515 albertel 6218: table.LC_prior_tries td {
1.524 albertel 6219: padding: 2px;
1.515 albertel 6220: }
1.523 albertel 6221:
6222: .LC_answer_correct {
1.795 www 6223: background: lightgreen;
6224: color: darkgreen;
6225: padding: 6px;
1.523 albertel 6226: }
1.795 www 6227:
1.523 albertel 6228: .LC_answer_charged_try {
1.797 www 6229: background: #FFAAAA;
1.795 www 6230: color: darkred;
6231: padding: 6px;
1.523 albertel 6232: }
1.795 www 6233:
1.779 bisitz 6234: .LC_answer_not_charged_try,
1.523 albertel 6235: .LC_answer_no_grade,
6236: .LC_answer_late {
1.795 www 6237: background: lightyellow;
1.523 albertel 6238: color: black;
1.795 www 6239: padding: 6px;
1.523 albertel 6240: }
1.795 www 6241:
1.523 albertel 6242: .LC_answer_previous {
1.795 www 6243: background: lightblue;
6244: color: darkblue;
6245: padding: 6px;
1.523 albertel 6246: }
1.795 www 6247:
1.779 bisitz 6248: .LC_answer_no_message {
1.777 tempelho 6249: background: #FFFFFF;
6250: color: black;
1.795 www 6251: padding: 6px;
1.779 bisitz 6252: }
1.795 www 6253:
1.779 bisitz 6254: .LC_answer_unknown {
6255: background: orange;
6256: color: black;
1.795 www 6257: padding: 6px;
1.777 tempelho 6258: }
1.795 www 6259:
1.529 albertel 6260: span.LC_prior_numerical,
6261: span.LC_prior_string,
6262: span.LC_prior_custom,
6263: span.LC_prior_reaction,
6264: span.LC_prior_math {
1.925 bisitz 6265: font-family: $mono;
1.523 albertel 6266: white-space: pre;
6267: }
6268:
1.525 albertel 6269: span.LC_prior_string {
1.925 bisitz 6270: font-family: $mono;
1.525 albertel 6271: white-space: pre;
6272: }
6273:
1.523 albertel 6274: table.LC_prior_option {
6275: width: 100%;
6276: border-collapse: collapse;
6277: }
1.795 www 6278:
1.911 bisitz 6279: table.LC_prior_rank,
1.795 www 6280: table.LC_prior_match {
1.528 albertel 6281: border-collapse: collapse;
6282: }
1.795 www 6283:
1.528 albertel 6284: table.LC_prior_option tr td,
6285: table.LC_prior_rank tr td,
6286: table.LC_prior_match tr td {
1.524 albertel 6287: border: 1px solid #000000;
1.515 albertel 6288: }
6289:
1.855 bisitz 6290: .LC_nobreak {
1.544 albertel 6291: white-space: nowrap;
1.519 raeburn 6292: }
6293:
1.576 raeburn 6294: span.LC_cusr_emph {
6295: font-style: italic;
6296: }
6297:
1.633 raeburn 6298: span.LC_cusr_subheading {
6299: font-weight: normal;
6300: font-size: 85%;
6301: }
6302:
1.861 bisitz 6303: div.LC_docs_entry_move {
1.859 bisitz 6304: border: 1px solid #BBBBBB;
1.545 albertel 6305: background: #DDDDDD;
1.861 bisitz 6306: width: 22px;
1.859 bisitz 6307: padding: 1px;
6308: margin: 0;
1.545 albertel 6309: }
6310:
1.861 bisitz 6311: table.LC_data_table tr > td.LC_docs_entry_commands,
6312: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6313: font-size: x-small;
6314: }
1.795 www 6315:
1.861 bisitz 6316: .LC_docs_entry_parameter {
6317: white-space: nowrap;
6318: }
6319:
1.544 albertel 6320: .LC_docs_copy {
1.545 albertel 6321: color: #000099;
1.544 albertel 6322: }
1.795 www 6323:
1.544 albertel 6324: .LC_docs_cut {
1.545 albertel 6325: color: #550044;
1.544 albertel 6326: }
1.795 www 6327:
1.544 albertel 6328: .LC_docs_rename {
1.545 albertel 6329: color: #009900;
1.544 albertel 6330: }
1.795 www 6331:
1.544 albertel 6332: .LC_docs_remove {
1.545 albertel 6333: color: #990000;
6334: }
6335:
1.547 albertel 6336: .LC_docs_reinit_warn,
6337: .LC_docs_ext_edit {
6338: font-size: x-small;
6339: }
6340:
1.545 albertel 6341: table.LC_docs_adddocs td,
6342: table.LC_docs_adddocs th {
6343: border: 1px solid #BBBBBB;
6344: padding: 4px;
6345: background: #DDDDDD;
1.543 albertel 6346: }
6347:
1.584 albertel 6348: table.LC_sty_begin {
6349: background: #BBFFBB;
6350: }
1.795 www 6351:
1.584 albertel 6352: table.LC_sty_end {
6353: background: #FFBBBB;
6354: }
6355:
1.589 raeburn 6356: table.LC_double_column {
1.803 bisitz 6357: border-width: 0;
1.589 raeburn 6358: border-collapse: collapse;
6359: width: 100%;
6360: padding: 2px;
6361: }
6362:
6363: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6364: top: 2px;
1.589 raeburn 6365: left: 2px;
6366: width: 47%;
6367: vertical-align: top;
6368: }
6369:
6370: table.LC_double_column tr td.LC_right_col {
6371: top: 2px;
1.779 bisitz 6372: right: 2px;
1.589 raeburn 6373: width: 47%;
6374: vertical-align: top;
6375: }
6376:
1.591 raeburn 6377: div.LC_left_float {
6378: float: left;
6379: padding-right: 5%;
1.597 albertel 6380: padding-bottom: 4px;
1.591 raeburn 6381: }
6382:
6383: div.LC_clear_float_header {
1.597 albertel 6384: padding-bottom: 2px;
1.591 raeburn 6385: }
6386:
6387: div.LC_clear_float_footer {
1.597 albertel 6388: padding-top: 10px;
1.591 raeburn 6389: clear: both;
6390: }
6391:
1.597 albertel 6392: div.LC_grade_show_user {
1.941 bisitz 6393: /* border-left: 5px solid $sidebg; */
6394: border-top: 5px solid #000000;
6395: margin: 50px 0 0 0;
1.936 bisitz 6396: padding: 15px 0 5px 10px;
1.597 albertel 6397: }
1.795 www 6398:
1.936 bisitz 6399: div.LC_grade_show_user_odd_row {
1.941 bisitz 6400: /* border-left: 5px solid #000000; */
6401: }
6402:
6403: div.LC_grade_show_user div.LC_Box {
6404: margin-right: 50px;
1.597 albertel 6405: }
6406:
6407: div.LC_grade_submissions,
6408: div.LC_grade_message_center,
1.936 bisitz 6409: div.LC_grade_info_links {
1.597 albertel 6410: margin: 5px;
6411: width: 99%;
6412: background: #FFFFFF;
6413: }
1.795 www 6414:
1.597 albertel 6415: div.LC_grade_submissions_header,
1.936 bisitz 6416: div.LC_grade_message_center_header {
1.705 tempelho 6417: font-weight: bold;
6418: font-size: large;
1.597 albertel 6419: }
1.795 www 6420:
1.597 albertel 6421: div.LC_grade_submissions_body,
1.936 bisitz 6422: div.LC_grade_message_center_body {
1.597 albertel 6423: border: 1px solid black;
6424: width: 99%;
6425: background: #FFFFFF;
6426: }
1.795 www 6427:
1.613 albertel 6428: table.LC_scantron_action {
6429: width: 100%;
6430: }
1.795 www 6431:
1.613 albertel 6432: table.LC_scantron_action tr th {
1.698 harmsja 6433: font-weight:bold;
6434: font-style:normal;
1.613 albertel 6435: }
1.795 www 6436:
1.779 bisitz 6437: .LC_edit_problem_header,
1.614 albertel 6438: div.LC_edit_problem_footer {
1.705 tempelho 6439: font-weight: normal;
6440: font-size: medium;
1.602 albertel 6441: margin: 2px;
1.1060 bisitz 6442: background-color: $sidebg;
1.600 albertel 6443: }
1.795 www 6444:
1.600 albertel 6445: div.LC_edit_problem_header,
1.602 albertel 6446: div.LC_edit_problem_header div,
1.614 albertel 6447: div.LC_edit_problem_footer,
6448: div.LC_edit_problem_footer div,
1.602 albertel 6449: div.LC_edit_problem_editxml_header,
6450: div.LC_edit_problem_editxml_header div {
1.600 albertel 6451: margin-top: 5px;
6452: }
1.795 www 6453:
1.600 albertel 6454: div.LC_edit_problem_header_title {
1.705 tempelho 6455: font-weight: bold;
6456: font-size: larger;
1.602 albertel 6457: background: $tabbg;
6458: padding: 3px;
1.1060 bisitz 6459: margin: 0 0 5px 0;
1.602 albertel 6460: }
1.795 www 6461:
1.602 albertel 6462: table.LC_edit_problem_header_title {
6463: width: 100%;
1.600 albertel 6464: background: $tabbg;
1.602 albertel 6465: }
6466:
6467: div.LC_edit_problem_discards {
6468: float: left;
6469: padding-bottom: 5px;
6470: }
1.795 www 6471:
1.602 albertel 6472: div.LC_edit_problem_saves {
6473: float: right;
6474: padding-bottom: 5px;
1.600 albertel 6475: }
1.795 www 6476:
1.1075.2.34 raeburn 6477: .LC_edit_opt {
6478: padding-left: 1em;
6479: white-space: nowrap;
6480: }
6481:
1.911 bisitz 6482: img.stift {
1.803 bisitz 6483: border-width: 0;
6484: vertical-align: middle;
1.677 riegler 6485: }
1.680 riegler 6486:
1.923 bisitz 6487: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6488: vertical-align: top;
1.777 tempelho 6489: }
1.795 www 6490:
1.716 raeburn 6491: div.LC_createcourse {
1.911 bisitz 6492: margin: 10px 10px 10px 10px;
1.716 raeburn 6493: }
6494:
1.917 raeburn 6495: .LC_dccid {
1.1075.2.38 raeburn 6496: float: right;
1.917 raeburn 6497: margin: 0.2em 0 0 0;
6498: padding: 0;
6499: font-size: 90%;
6500: display:none;
6501: }
6502:
1.897 wenzelju 6503: ol.LC_primary_menu a:hover,
1.721 harmsja 6504: ol#LC_MenuBreadcrumbs a:hover,
6505: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6506: ul#LC_secondary_menu a:hover,
1.721 harmsja 6507: .LC_FormSectionClearButton input:hover
1.795 www 6508: ul.LC_TabContent li:hover a {
1.952 onken 6509: color:$button_hover;
1.911 bisitz 6510: text-decoration:none;
1.693 droeschl 6511: }
6512:
1.779 bisitz 6513: h1 {
1.911 bisitz 6514: padding: 0;
6515: line-height:130%;
1.693 droeschl 6516: }
1.698 harmsja 6517:
1.911 bisitz 6518: h2,
6519: h3,
6520: h4,
6521: h5,
6522: h6 {
6523: margin: 5px 0 5px 0;
6524: padding: 0;
6525: line-height:130%;
1.693 droeschl 6526: }
1.795 www 6527:
6528: .LC_hcell {
1.911 bisitz 6529: padding:3px 15px 3px 15px;
6530: margin: 0;
6531: background-color:$tabbg;
6532: color:$fontmenu;
6533: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6534: }
1.795 www 6535:
1.840 bisitz 6536: .LC_Box > .LC_hcell {
1.911 bisitz 6537: margin: 0 -10px 10px -10px;
1.835 bisitz 6538: }
6539:
1.721 harmsja 6540: .LC_noBorder {
1.911 bisitz 6541: border: 0;
1.698 harmsja 6542: }
1.693 droeschl 6543:
1.721 harmsja 6544: .LC_FormSectionClearButton input {
1.911 bisitz 6545: background-color:transparent;
6546: border: none;
6547: cursor:pointer;
6548: text-decoration:underline;
1.693 droeschl 6549: }
1.763 bisitz 6550:
6551: .LC_help_open_topic {
1.911 bisitz 6552: color: #FFFFFF;
6553: background-color: #EEEEFF;
6554: margin: 1px;
6555: padding: 4px;
6556: border: 1px solid #000033;
6557: white-space: nowrap;
6558: /* vertical-align: middle; */
1.759 neumanie 6559: }
1.693 droeschl 6560:
1.911 bisitz 6561: dl,
6562: ul,
6563: div,
6564: fieldset {
6565: margin: 10px 10px 10px 0;
6566: /* overflow: hidden; */
1.693 droeschl 6567: }
1.795 www 6568:
1.838 bisitz 6569: fieldset > legend {
1.911 bisitz 6570: font-weight: bold;
6571: padding: 0 5px 0 5px;
1.838 bisitz 6572: }
6573:
1.813 bisitz 6574: #LC_nav_bar {
1.911 bisitz 6575: float: left;
1.995 raeburn 6576: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6577: margin: 0 0 2px 0;
1.807 droeschl 6578: }
6579:
1.916 droeschl 6580: #LC_realm {
6581: margin: 0.2em 0 0 0;
6582: padding: 0;
6583: font-weight: bold;
6584: text-align: center;
1.995 raeburn 6585: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6586: }
6587:
1.911 bisitz 6588: #LC_nav_bar em {
6589: font-weight: bold;
6590: font-style: normal;
1.807 droeschl 6591: }
6592:
1.897 wenzelju 6593: ol.LC_primary_menu {
1.934 droeschl 6594: margin: 0;
1.1075.2.2 raeburn 6595: padding: 0;
1.995 raeburn 6596: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6597: }
6598:
1.852 droeschl 6599: ol#LC_PathBreadcrumbs {
1.911 bisitz 6600: margin: 0;
1.693 droeschl 6601: }
6602:
1.897 wenzelju 6603: ol.LC_primary_menu li {
1.1075.2.2 raeburn 6604: color: RGB(80, 80, 80);
6605: vertical-align: middle;
6606: text-align: left;
6607: list-style: none;
6608: float: left;
6609: }
6610:
6611: ol.LC_primary_menu li a {
6612: display: block;
6613: margin: 0;
6614: padding: 0 5px 0 10px;
6615: text-decoration: none;
6616: }
6617:
6618: ol.LC_primary_menu li ul {
6619: display: none;
6620: width: 10em;
6621: background-color: $data_table_light;
6622: }
6623:
6624: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6625: display: block;
6626: position: absolute;
6627: margin: 0;
6628: padding: 0;
1.1075.2.5 raeburn 6629: z-index: 2;
1.1075.2.2 raeburn 6630: }
6631:
6632: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6633: font-size: 90%;
1.911 bisitz 6634: vertical-align: top;
1.1075.2.2 raeburn 6635: float: none;
1.1075.2.5 raeburn 6636: border-left: 1px solid black;
6637: border-right: 1px solid black;
1.1075.2.2 raeburn 6638: }
6639:
6640: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5 raeburn 6641: background-color:$data_table_light;
1.1075.2.2 raeburn 6642: }
6643:
6644: ol.LC_primary_menu li li a:hover {
6645: color:$button_hover;
6646: background-color:$data_table_dark;
1.693 droeschl 6647: }
6648:
1.897 wenzelju 6649: ol.LC_primary_menu li img {
1.911 bisitz 6650: vertical-align: bottom;
1.934 droeschl 6651: height: 1.1em;
1.1075.2.3 raeburn 6652: margin: 0.2em 0 0 0;
1.693 droeschl 6653: }
6654:
1.897 wenzelju 6655: ol.LC_primary_menu a {
1.911 bisitz 6656: color: RGB(80, 80, 80);
6657: text-decoration: none;
1.693 droeschl 6658: }
1.795 www 6659:
1.949 droeschl 6660: ol.LC_primary_menu a.LC_new_message {
6661: font-weight:bold;
6662: color: darkred;
6663: }
6664:
1.975 raeburn 6665: ol.LC_docs_parameters {
6666: margin-left: 0;
6667: padding: 0;
6668: list-style: none;
6669: }
6670:
6671: ol.LC_docs_parameters li {
6672: margin: 0;
6673: padding-right: 20px;
6674: display: inline;
6675: }
6676:
1.976 raeburn 6677: ol.LC_docs_parameters li:before {
6678: content: "\\002022 \\0020";
6679: }
6680:
6681: li.LC_docs_parameters_title {
6682: font-weight: bold;
6683: }
6684:
6685: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6686: content: "";
6687: }
6688:
1.897 wenzelju 6689: ul#LC_secondary_menu {
1.1075.2.23 raeburn 6690: clear: right;
1.911 bisitz 6691: color: $fontmenu;
6692: background: $tabbg;
6693: list-style: none;
6694: padding: 0;
6695: margin: 0;
6696: width: 100%;
1.995 raeburn 6697: text-align: left;
1.1075.2.4 raeburn 6698: float: left;
1.808 droeschl 6699: }
6700:
1.897 wenzelju 6701: ul#LC_secondary_menu li {
1.911 bisitz 6702: font-weight: bold;
6703: line-height: 1.8em;
6704: border-right: 1px solid black;
6705: vertical-align: middle;
1.1075.2.4 raeburn 6706: float: left;
6707: }
6708:
6709: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6710: background-color: $data_table_light;
6711: }
6712:
6713: ul#LC_secondary_menu li a {
6714: padding: 0 0.8em;
6715: }
6716:
6717: ul#LC_secondary_menu li ul {
6718: display: none;
6719: }
6720:
6721: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6722: display: block;
6723: position: absolute;
6724: margin: 0;
6725: padding: 0;
6726: list-style:none;
6727: float: none;
6728: background-color: $data_table_light;
1.1075.2.5 raeburn 6729: z-index: 2;
1.1075.2.10 raeburn 6730: margin-left: -1px;
1.1075.2.4 raeburn 6731: }
6732:
6733: ul#LC_secondary_menu li ul li {
6734: font-size: 90%;
6735: vertical-align: top;
6736: border-left: 1px solid black;
6737: border-right: 1px solid black;
1.1075.2.33 raeburn 6738: background-color: $data_table_light;
1.1075.2.4 raeburn 6739: list-style:none;
6740: float: none;
6741: }
6742:
6743: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6744: background-color: $data_table_dark;
1.807 droeschl 6745: }
6746:
1.847 tempelho 6747: ul.LC_TabContent {
1.911 bisitz 6748: display:block;
6749: background: $sidebg;
6750: border-bottom: solid 1px $lg_border_color;
6751: list-style:none;
1.1020 raeburn 6752: margin: -1px -10px 0 -10px;
1.911 bisitz 6753: padding: 0;
1.693 droeschl 6754: }
6755:
1.795 www 6756: ul.LC_TabContent li,
6757: ul.LC_TabContentBigger li {
1.911 bisitz 6758: float:left;
1.741 harmsja 6759: }
1.795 www 6760:
1.897 wenzelju 6761: ul#LC_secondary_menu li a {
1.911 bisitz 6762: color: $fontmenu;
6763: text-decoration: none;
1.693 droeschl 6764: }
1.795 www 6765:
1.721 harmsja 6766: ul.LC_TabContent {
1.952 onken 6767: min-height:20px;
1.721 harmsja 6768: }
1.795 www 6769:
6770: ul.LC_TabContent li {
1.911 bisitz 6771: vertical-align:middle;
1.959 onken 6772: padding: 0 16px 0 10px;
1.911 bisitz 6773: background-color:$tabbg;
6774: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6775: border-left: solid 1px $font;
1.721 harmsja 6776: }
1.795 www 6777:
1.847 tempelho 6778: ul.LC_TabContent .right {
1.911 bisitz 6779: float:right;
1.847 tempelho 6780: }
6781:
1.911 bisitz 6782: ul.LC_TabContent li a,
6783: ul.LC_TabContent li {
6784: color:rgb(47,47,47);
6785: text-decoration:none;
6786: font-size:95%;
6787: font-weight:bold;
1.952 onken 6788: min-height:20px;
6789: }
6790:
1.959 onken 6791: ul.LC_TabContent li a:hover,
6792: ul.LC_TabContent li a:focus {
1.952 onken 6793: color: $button_hover;
1.959 onken 6794: background:none;
6795: outline:none;
1.952 onken 6796: }
6797:
6798: ul.LC_TabContent li:hover {
6799: color: $button_hover;
6800: cursor:pointer;
1.721 harmsja 6801: }
1.795 www 6802:
1.911 bisitz 6803: ul.LC_TabContent li.active {
1.952 onken 6804: color: $font;
1.911 bisitz 6805: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6806: border-bottom:solid 1px #FFFFFF;
6807: cursor: default;
1.744 ehlerst 6808: }
1.795 www 6809:
1.959 onken 6810: ul.LC_TabContent li.active a {
6811: color:$font;
6812: background:#FFFFFF;
6813: outline: none;
6814: }
1.1047 raeburn 6815:
6816: ul.LC_TabContent li.goback {
6817: float: left;
6818: border-left: none;
6819: }
6820:
1.870 tempelho 6821: #maincoursedoc {
1.911 bisitz 6822: clear:both;
1.870 tempelho 6823: }
6824:
6825: ul.LC_TabContentBigger {
1.911 bisitz 6826: display:block;
6827: list-style:none;
6828: padding: 0;
1.870 tempelho 6829: }
6830:
1.795 www 6831: ul.LC_TabContentBigger li {
1.911 bisitz 6832: vertical-align:bottom;
6833: height: 30px;
6834: font-size:110%;
6835: font-weight:bold;
6836: color: #737373;
1.841 tempelho 6837: }
6838:
1.957 onken 6839: ul.LC_TabContentBigger li.active {
6840: position: relative;
6841: top: 1px;
6842: }
6843:
1.870 tempelho 6844: ul.LC_TabContentBigger li a {
1.911 bisitz 6845: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6846: height: 30px;
6847: line-height: 30px;
6848: text-align: center;
6849: display: block;
6850: text-decoration: none;
1.958 onken 6851: outline: none;
1.741 harmsja 6852: }
1.795 www 6853:
1.870 tempelho 6854: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6855: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6856: color:$font;
1.744 ehlerst 6857: }
1.795 www 6858:
1.870 tempelho 6859: ul.LC_TabContentBigger li b {
1.911 bisitz 6860: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6861: display: block;
6862: float: left;
6863: padding: 0 30px;
1.957 onken 6864: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6865: }
6866:
1.956 onken 6867: ul.LC_TabContentBigger li:hover b {
6868: color:$button_hover;
6869: }
6870:
1.870 tempelho 6871: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6872: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6873: color:$font;
1.957 onken 6874: border: 0;
1.741 harmsja 6875: }
1.693 droeschl 6876:
1.870 tempelho 6877:
1.862 bisitz 6878: ul.LC_CourseBreadcrumbs {
6879: background: $sidebg;
1.1020 raeburn 6880: height: 2em;
1.862 bisitz 6881: padding-left: 10px;
1.1020 raeburn 6882: margin: 0;
1.862 bisitz 6883: list-style-position: inside;
6884: }
6885:
1.911 bisitz 6886: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6887: ol#LC_PathBreadcrumbs {
1.911 bisitz 6888: padding-left: 10px;
6889: margin: 0;
1.933 droeschl 6890: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6891: }
6892:
1.911 bisitz 6893: ol#LC_MenuBreadcrumbs li,
6894: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6895: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6896: display: inline;
1.933 droeschl 6897: white-space: normal;
1.693 droeschl 6898: }
6899:
1.823 bisitz 6900: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6901: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6902: text-decoration: none;
6903: font-size:90%;
1.693 droeschl 6904: }
1.795 www 6905:
1.969 droeschl 6906: ol#LC_MenuBreadcrumbs h1 {
6907: display: inline;
6908: font-size: 90%;
6909: line-height: 2.5em;
6910: margin: 0;
6911: padding: 0;
6912: }
6913:
1.795 www 6914: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6915: text-decoration:none;
6916: font-size:100%;
6917: font-weight:bold;
1.693 droeschl 6918: }
1.795 www 6919:
1.840 bisitz 6920: .LC_Box {
1.911 bisitz 6921: border: solid 1px $lg_border_color;
6922: padding: 0 10px 10px 10px;
1.746 neumanie 6923: }
1.795 www 6924:
1.1020 raeburn 6925: .LC_DocsBox {
6926: border: solid 1px $lg_border_color;
6927: padding: 0 0 10px 10px;
6928: }
6929:
1.795 www 6930: .LC_AboutMe_Image {
1.911 bisitz 6931: float:left;
6932: margin-right:10px;
1.747 neumanie 6933: }
1.795 www 6934:
6935: .LC_Clear_AboutMe_Image {
1.911 bisitz 6936: clear:left;
1.747 neumanie 6937: }
1.795 www 6938:
1.721 harmsja 6939: dl.LC_ListStyleClean dt {
1.911 bisitz 6940: padding-right: 5px;
6941: display: table-header-group;
1.693 droeschl 6942: }
6943:
1.721 harmsja 6944: dl.LC_ListStyleClean dd {
1.911 bisitz 6945: display: table-row;
1.693 droeschl 6946: }
6947:
1.721 harmsja 6948: .LC_ListStyleClean,
6949: .LC_ListStyleSimple,
6950: .LC_ListStyleNormal,
1.795 www 6951: .LC_ListStyleSpecial {
1.911 bisitz 6952: /* display:block; */
6953: list-style-position: inside;
6954: list-style-type: none;
6955: overflow: hidden;
6956: padding: 0;
1.693 droeschl 6957: }
6958:
1.721 harmsja 6959: .LC_ListStyleSimple li,
6960: .LC_ListStyleSimple dd,
6961: .LC_ListStyleNormal li,
6962: .LC_ListStyleNormal dd,
6963: .LC_ListStyleSpecial li,
1.795 www 6964: .LC_ListStyleSpecial dd {
1.911 bisitz 6965: margin: 0;
6966: padding: 5px 5px 5px 10px;
6967: clear: both;
1.693 droeschl 6968: }
6969:
1.721 harmsja 6970: .LC_ListStyleClean li,
6971: .LC_ListStyleClean dd {
1.911 bisitz 6972: padding-top: 0;
6973: padding-bottom: 0;
1.693 droeschl 6974: }
6975:
1.721 harmsja 6976: .LC_ListStyleSimple dd,
1.795 www 6977: .LC_ListStyleSimple li {
1.911 bisitz 6978: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6979: }
6980:
1.721 harmsja 6981: .LC_ListStyleSpecial li,
6982: .LC_ListStyleSpecial dd {
1.911 bisitz 6983: list-style-type: none;
6984: background-color: RGB(220, 220, 220);
6985: margin-bottom: 4px;
1.693 droeschl 6986: }
6987:
1.721 harmsja 6988: table.LC_SimpleTable {
1.911 bisitz 6989: margin:5px;
6990: border:solid 1px $lg_border_color;
1.795 www 6991: }
1.693 droeschl 6992:
1.721 harmsja 6993: table.LC_SimpleTable tr {
1.911 bisitz 6994: padding: 0;
6995: border:solid 1px $lg_border_color;
1.693 droeschl 6996: }
1.795 www 6997:
6998: table.LC_SimpleTable thead {
1.911 bisitz 6999: background:rgb(220,220,220);
1.693 droeschl 7000: }
7001:
1.721 harmsja 7002: div.LC_columnSection {
1.911 bisitz 7003: display: block;
7004: clear: both;
7005: overflow: hidden;
7006: margin: 0;
1.693 droeschl 7007: }
7008:
1.721 harmsja 7009: div.LC_columnSection>* {
1.911 bisitz 7010: float: left;
7011: margin: 10px 20px 10px 0;
7012: overflow:hidden;
1.693 droeschl 7013: }
1.721 harmsja 7014:
1.795 www 7015: table em {
1.911 bisitz 7016: font-weight: bold;
7017: font-style: normal;
1.748 schulted 7018: }
1.795 www 7019:
1.779 bisitz 7020: table.LC_tableBrowseRes,
1.795 www 7021: table.LC_tableOfContent {
1.911 bisitz 7022: border:none;
7023: border-spacing: 1px;
7024: padding: 3px;
7025: background-color: #FFFFFF;
7026: font-size: 90%;
1.753 droeschl 7027: }
1.789 droeschl 7028:
1.911 bisitz 7029: table.LC_tableOfContent {
7030: border-collapse: collapse;
1.789 droeschl 7031: }
7032:
1.771 droeschl 7033: table.LC_tableBrowseRes a,
1.768 schulted 7034: table.LC_tableOfContent a {
1.911 bisitz 7035: background-color: transparent;
7036: text-decoration: none;
1.753 droeschl 7037: }
7038:
1.795 www 7039: table.LC_tableOfContent img {
1.911 bisitz 7040: border: none;
7041: height: 1.3em;
7042: vertical-align: text-bottom;
7043: margin-right: 0.3em;
1.753 droeschl 7044: }
1.757 schulted 7045:
1.795 www 7046: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7047: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7048: }
7049:
1.795 www 7050: a#LC_content_toolbar_everything {
1.911 bisitz 7051: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7052: }
7053:
1.795 www 7054: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7055: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7056: }
7057:
1.795 www 7058: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7059: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7060: }
7061:
1.795 www 7062: a#LC_content_toolbar_changefolder {
1.911 bisitz 7063: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7064: }
7065:
1.795 www 7066: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7067: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7068: }
7069:
1.1043 raeburn 7070: a#LC_content_toolbar_edittoplevel {
7071: background-image:url(/res/adm/pages/edittoplevel.gif);
7072: }
7073:
1.795 www 7074: ul#LC_toolbar li a:hover {
1.911 bisitz 7075: background-position: bottom center;
1.757 schulted 7076: }
7077:
1.795 www 7078: ul#LC_toolbar {
1.911 bisitz 7079: padding: 0;
7080: margin: 2px;
7081: list-style:none;
7082: position:relative;
7083: background-color:white;
1.1075.2.9 raeburn 7084: overflow: auto;
1.757 schulted 7085: }
7086:
1.795 www 7087: ul#LC_toolbar li {
1.911 bisitz 7088: border:1px solid white;
7089: padding: 0;
7090: margin: 0;
7091: float: left;
7092: display:inline;
7093: vertical-align:middle;
1.1075.2.9 raeburn 7094: white-space: nowrap;
1.911 bisitz 7095: }
1.757 schulted 7096:
1.783 amueller 7097:
1.795 www 7098: a.LC_toolbarItem {
1.911 bisitz 7099: display:block;
7100: padding: 0;
7101: margin: 0;
7102: height: 32px;
7103: width: 32px;
7104: color:white;
7105: border: none;
7106: background-repeat:no-repeat;
7107: background-color:transparent;
1.757 schulted 7108: }
7109:
1.915 droeschl 7110: ul.LC_funclist {
7111: margin: 0;
7112: padding: 0.5em 1em 0.5em 0;
7113: }
7114:
1.933 droeschl 7115: ul.LC_funclist > li:first-child {
7116: font-weight:bold;
7117: margin-left:0.8em;
7118: }
7119:
1.915 droeschl 7120: ul.LC_funclist + ul.LC_funclist {
7121: /*
7122: left border as a seperator if we have more than
7123: one list
7124: */
7125: border-left: 1px solid $sidebg;
7126: /*
7127: this hides the left border behind the border of the
7128: outer box if element is wrapped to the next 'line'
7129: */
7130: margin-left: -1px;
7131: }
7132:
1.843 bisitz 7133: ul.LC_funclist li {
1.915 droeschl 7134: display: inline;
1.782 bisitz 7135: white-space: nowrap;
1.915 droeschl 7136: margin: 0 0 0 25px;
7137: line-height: 150%;
1.782 bisitz 7138: }
7139:
1.974 wenzelju 7140: .LC_hidden {
7141: display: none;
7142: }
7143:
1.1030 www 7144: .LCmodal-overlay {
7145: position:fixed;
7146: top:0;
7147: right:0;
7148: bottom:0;
7149: left:0;
7150: height:100%;
7151: width:100%;
7152: margin:0;
7153: padding:0;
7154: background:#999;
7155: opacity:.75;
7156: filter: alpha(opacity=75);
7157: -moz-opacity: 0.75;
7158: z-index:101;
7159: }
7160:
7161: * html .LCmodal-overlay {
7162: position: absolute;
7163: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7164: }
7165:
7166: .LCmodal-window {
7167: position:fixed;
7168: top:50%;
7169: left:50%;
7170: margin:0;
7171: padding:0;
7172: z-index:102;
7173: }
7174:
7175: * html .LCmodal-window {
7176: position:absolute;
7177: }
7178:
7179: .LCclose-window {
7180: position:absolute;
7181: width:32px;
7182: height:32px;
7183: right:8px;
7184: top:8px;
7185: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7186: text-indent:-99999px;
7187: overflow:hidden;
7188: cursor:pointer;
7189: }
7190:
1.1075.2.17 raeburn 7191: /*
7192: styles used by TTH when "Default set of options to pass to tth/m
7193: when converting TeX" in course settings has been set
7194:
7195: option passed: -t
7196:
7197: */
7198:
7199: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7200: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7201: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7202: td div.norm {line-height:normal;}
7203:
7204: /*
7205: option passed -y3
7206: */
7207:
7208: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7209: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7210: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7211:
1.343 albertel 7212: END
7213: }
7214:
1.306 albertel 7215: =pod
7216:
7217: =item * &headtag()
7218:
7219: Returns a uniform footer for LON-CAPA web pages.
7220:
1.307 albertel 7221: Inputs: $title - optional title for the head
7222: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7223: $args - optional arguments
1.319 albertel 7224: force_register - if is true call registerurl so the remote is
7225: informed
1.415 albertel 7226: redirect -> array ref of
7227: 1- seconds before redirect occurs
7228: 2- url to redirect to
7229: 3- whether the side effect should occur
1.315 albertel 7230: (side effect of setting
7231: $env{'internal.head.redirect'} to the url
7232: redirected too)
1.352 albertel 7233: domain -> force to color decorate a page for a specific
7234: domain
7235: function -> force usage of a specific rolish color scheme
7236: bgcolor -> override the default page bgcolor
1.460 albertel 7237: no_auto_mt_title
7238: -> prevent &mt()ing the title arg
1.464 albertel 7239:
1.306 albertel 7240: =cut
7241:
7242: sub headtag {
1.313 albertel 7243: my ($title,$head_extra,$args) = @_;
1.306 albertel 7244:
1.363 albertel 7245: my $function = $args->{'function'} || &get_users_function();
7246: my $domain = $args->{'domain'} || &determinedomain();
7247: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 7248: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7249: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7250: #time(),
1.418 albertel 7251: $env{'environment.color.timestamp'},
1.363 albertel 7252: $function,$domain,$bgcolor);
7253:
1.369 www 7254: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7255:
1.308 albertel 7256: my $result =
7257: '<head>'.
1.461 albertel 7258: &font_settings();
1.319 albertel 7259:
1.1064 raeburn 7260: my $inhibitprint = &print_suppression();
7261:
1.461 albertel 7262: if (!$args->{'frameset'}) {
7263: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7264: }
1.1075.2.12 raeburn 7265: if ($args->{'force_register'}) {
7266: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7267: }
1.436 albertel 7268: if (!$args->{'no_nav_bar'}
7269: && !$args->{'only_body'}
7270: && !$args->{'frameset'}) {
7271: $result .= &help_menu_js();
1.1032 www 7272: $result.=&modal_window();
1.1038 www 7273: $result.=&togglebox_script();
1.1034 www 7274: $result.=&wishlist_window();
1.1041 www 7275: $result.=&LCprogressbarUpdate_script();
1.1034 www 7276: } else {
7277: if ($args->{'add_modal'}) {
7278: $result.=&modal_window();
7279: }
7280: if ($args->{'add_wishlist'}) {
7281: $result.=&wishlist_window();
7282: }
1.1038 www 7283: if ($args->{'add_togglebox'}) {
7284: $result.=&togglebox_script();
7285: }
1.1041 www 7286: if ($args->{'add_progressbar'}) {
7287: $result.=&LCprogressbarUpdate_script();
7288: }
1.436 albertel 7289: }
1.314 albertel 7290: if (ref($args->{'redirect'})) {
1.414 albertel 7291: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7292: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7293: if (!$inhibit_continue) {
7294: $env{'internal.head.redirect'} = $url;
7295: }
1.313 albertel 7296: $result.=<<ADDMETA
7297: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7298: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7299: ADDMETA
7300: }
1.306 albertel 7301: if (!defined($title)) {
7302: $title = 'The LearningOnline Network with CAPA';
7303: }
1.460 albertel 7304: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7305: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 7306: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064 raeburn 7307: .$inhibitprint
1.414 albertel 7308: .$head_extra;
1.1075.2.42 raeburn 7309: if ($env{'browser.mobile'}) {
7310: $result .= '
7311: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7312: <meta name="apple-mobile-web-app-capable" content="yes" />';
7313: }
1.962 droeschl 7314: return $result.'</head>';
1.306 albertel 7315: }
7316:
7317: =pod
7318:
1.340 albertel 7319: =item * &font_settings()
7320:
7321: Returns neccessary <meta> to set the proper encoding
7322:
7323: Inputs: none
7324:
7325: =cut
7326:
7327: sub font_settings {
7328: my $headerstring='';
1.647 www 7329: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 7330: $headerstring.=
7331: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
7332: }
7333: return $headerstring;
7334: }
7335:
1.341 albertel 7336: =pod
7337:
1.1064 raeburn 7338: =item * &print_suppression()
7339:
7340: In course context returns css which causes the body to be blank when media="print",
7341: if printout generation is unavailable for the current resource.
7342:
7343: This could be because:
7344:
7345: (a) printstartdate is in the future
7346:
7347: (b) printenddate is in the past
7348:
7349: (c) there is an active exam block with "printout"
7350: functionality blocked
7351:
7352: Users with pav, pfo or evb privileges are exempt.
7353:
7354: Inputs: none
7355:
7356: =cut
7357:
7358:
7359: sub print_suppression {
7360: my $noprint;
7361: if ($env{'request.course.id'}) {
7362: my $scope = $env{'request.course.id'};
7363: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7364: (&Apache::lonnet::allowed('pfo',$scope))) {
7365: return;
7366: }
7367: if ($env{'request.course.sec'} ne '') {
7368: $scope .= "/$env{'request.course.sec'}";
7369: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7370: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7371: return;
1.1064 raeburn 7372: }
7373: }
7374: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7375: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7376: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7377: if ($blocked) {
7378: my $checkrole = "cm./$cdom/$cnum";
7379: if ($env{'request.course.sec'} ne '') {
7380: $checkrole .= "/$env{'request.course.sec'}";
7381: }
7382: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7383: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7384: $noprint = 1;
7385: }
7386: }
7387: unless ($noprint) {
7388: my $symb = &Apache::lonnet::symbread();
7389: if ($symb ne '') {
7390: my $navmap = Apache::lonnavmaps::navmap->new();
7391: if (ref($navmap)) {
7392: my $res = $navmap->getBySymb($symb);
7393: if (ref($res)) {
7394: if (!$res->resprintable()) {
7395: $noprint = 1;
7396: }
7397: }
7398: }
7399: }
7400: }
7401: if ($noprint) {
7402: return <<"ENDSTYLE";
7403: <style type="text/css" media="print">
7404: body { display:none }
7405: </style>
7406: ENDSTYLE
7407: }
7408: }
7409: return;
7410: }
7411:
7412: =pod
7413:
1.341 albertel 7414: =item * &xml_begin()
7415:
7416: Returns the needed doctype and <html>
7417:
7418: Inputs: none
7419:
7420: =cut
7421:
7422: sub xml_begin {
7423: my $output='';
7424:
7425: if ($env{'browser.mathml'}) {
7426: $output='<?xml version="1.0"?>'
7427: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7428: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7429:
7430: # .'<!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">] >'
7431: .'<!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">'
7432: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7433: .'xmlns="http://www.w3.org/1999/xhtml">';
7434: } else {
1.849 bisitz 7435: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
7436: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 7437: }
7438: return $output;
7439: }
1.340 albertel 7440:
7441: =pod
7442:
1.306 albertel 7443: =item * &start_page()
7444:
7445: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7446:
1.648 raeburn 7447: Inputs:
7448:
7449: =over 4
7450:
7451: $title - optional title for the page
7452:
7453: $head_extra - optional extra HTML to incude inside the <head>
7454:
7455: $args - additional optional args supported are:
7456:
7457: =over 8
7458:
7459: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7460: arg on
1.814 bisitz 7461: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7462: add_entries -> additional attributes to add to the <body>
7463: domain -> force to color decorate a page for a
1.317 albertel 7464: specific domain
1.648 raeburn 7465: function -> force usage of a specific rolish color
1.317 albertel 7466: scheme
1.648 raeburn 7467: redirect -> see &headtag()
7468: bgcolor -> override the default page bg color
7469: js_ready -> return a string ready for being used in
1.317 albertel 7470: a javascript writeln
1.648 raeburn 7471: html_encode -> return a string ready for being used in
1.320 albertel 7472: a html attribute
1.648 raeburn 7473: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7474: $forcereg arg
1.648 raeburn 7475: frameset -> if true will start with a <frameset>
1.330 albertel 7476: rather than <body>
1.648 raeburn 7477: skip_phases -> hash ref of
1.338 albertel 7478: head -> skip the <html><head> generation
7479: body -> skip all <body> generation
1.1075.2.12 raeburn 7480: no_inline_link -> if true and in remote mode, don't show the
7481: 'Switch To Inline Menu' link
1.648 raeburn 7482: no_auto_mt_title -> prevent &mt()ing the title arg
7483: inherit_jsmath -> when creating popup window in a page,
7484: should it have jsmath forced on by the
7485: current page
1.867 kalberla 7486: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7487: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7488: group -> includes the current group, if page is for a
7489: specific group
1.361 albertel 7490:
1.648 raeburn 7491: =back
1.460 albertel 7492:
1.648 raeburn 7493: =back
1.562 albertel 7494:
1.306 albertel 7495: =cut
7496:
7497: sub start_page {
1.309 albertel 7498: my ($title,$head_extra,$args) = @_;
1.318 albertel 7499: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7500:
1.315 albertel 7501: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7502: my ($result,@advtools);
1.964 droeschl 7503:
1.338 albertel 7504: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7505: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7506: }
7507:
7508: if (! exists($args->{'skip_phases'}{'body'}) ) {
7509: if ($args->{'frameset'}) {
7510: my $attr_string = &make_attr_string($args->{'force_register'},
7511: $args->{'add_entries'});
7512: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7513: } else {
7514: $result .=
7515: &bodytag($title,
7516: $args->{'function'}, $args->{'add_entries'},
7517: $args->{'only_body'}, $args->{'domain'},
7518: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7519: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7520: $args, \@advtools);
1.831 bisitz 7521: }
1.330 albertel 7522: }
1.338 albertel 7523:
1.315 albertel 7524: if ($args->{'js_ready'}) {
1.713 kaisler 7525: $result = &js_ready($result);
1.315 albertel 7526: }
1.320 albertel 7527: if ($args->{'html_encode'}) {
1.713 kaisler 7528: $result = &html_encode($result);
7529: }
7530:
1.813 bisitz 7531: # Preparation for new and consistent functionlist at top of screen
7532: # if ($args->{'functionlist'}) {
7533: # $result .= &build_functionlist();
7534: #}
7535:
1.964 droeschl 7536: # Don't add anything more if only_body wanted or in const space
7537: return $result if $args->{'only_body'}
7538: || $env{'request.state'} eq 'construct';
1.813 bisitz 7539:
7540: #Breadcrumbs
1.758 kaisler 7541: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7542: &Apache::lonhtmlcommon::clear_breadcrumbs();
7543: #if any br links exists, add them to the breadcrumbs
7544: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7545: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7546: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7547: }
7548: }
1.1075.2.19 raeburn 7549: # if @advtools array contains items add then to the breadcrumbs
7550: if (@advtools > 0) {
7551: &Apache::lonmenu::advtools_crumbs(@advtools);
7552: }
1.758 kaisler 7553:
7554: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7555: if(exists($args->{'bread_crumbs_component'})){
7556: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7557: }else{
7558: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7559: }
1.1075.2.24 raeburn 7560: } elsif (($env{'environment.remote'} eq 'on') &&
7561: ($env{'form.inhibitmenu'} ne 'yes') &&
7562: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7563: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7564: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7565: }
1.315 albertel 7566: return $result;
1.306 albertel 7567: }
7568:
7569: sub end_page {
1.315 albertel 7570: my ($args) = @_;
7571: $env{'internal.end_page'}++;
1.330 albertel 7572: my $result;
1.335 albertel 7573: if ($args->{'discussion'}) {
7574: my ($target,$parser);
7575: if (ref($args->{'discussion'})) {
7576: ($target,$parser) =($args->{'discussion'}{'target'},
7577: $args->{'discussion'}{'parser'});
7578: }
7579: $result .= &Apache::lonxml::xmlend($target,$parser);
7580: }
1.330 albertel 7581: if ($args->{'frameset'}) {
7582: $result .= '</frameset>';
7583: } else {
1.635 raeburn 7584: $result .= &endbodytag($args);
1.330 albertel 7585: }
1.1075.2.6 raeburn 7586: unless ($args->{'notbody'}) {
7587: $result .= "\n</html>";
7588: }
1.330 albertel 7589:
1.315 albertel 7590: if ($args->{'js_ready'}) {
1.317 albertel 7591: $result = &js_ready($result);
1.315 albertel 7592: }
1.335 albertel 7593:
1.320 albertel 7594: if ($args->{'html_encode'}) {
7595: $result = &html_encode($result);
7596: }
1.335 albertel 7597:
1.315 albertel 7598: return $result;
7599: }
7600:
1.1034 www 7601: sub wishlist_window {
7602: return(<<'ENDWISHLIST');
1.1046 raeburn 7603: <script type="text/javascript">
1.1034 www 7604: // <![CDATA[
7605: // <!-- BEGIN LON-CAPA Internal
7606: function set_wishlistlink(title, path) {
7607: if (!title) {
7608: title = document.title;
7609: title = title.replace(/^LON-CAPA /,'');
7610: }
7611: if (!path) {
7612: path = location.pathname;
7613: }
7614: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7615: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7616: }
7617: // END LON-CAPA Internal -->
7618: // ]]>
7619: </script>
7620: ENDWISHLIST
7621: }
7622:
1.1030 www 7623: sub modal_window {
7624: return(<<'ENDMODAL');
1.1046 raeburn 7625: <script type="text/javascript">
1.1030 www 7626: // <![CDATA[
7627: // <!-- BEGIN LON-CAPA Internal
7628: var modalWindow = {
7629: parent:"body",
7630: windowId:null,
7631: content:null,
7632: width:null,
7633: height:null,
7634: close:function()
7635: {
7636: $(".LCmodal-window").remove();
7637: $(".LCmodal-overlay").remove();
7638: },
7639: open:function()
7640: {
7641: var modal = "";
7642: modal += "<div class=\"LCmodal-overlay\"></div>";
7643: 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;\">";
7644: modal += this.content;
7645: modal += "</div>";
7646:
7647: $(this.parent).append(modal);
7648:
7649: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7650: $(".LCclose-window").click(function(){modalWindow.close();});
7651: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7652: }
7653: };
1.1075.2.42 raeburn 7654: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7655: {
7656: modalWindow.windowId = "myModal";
7657: modalWindow.width = width;
7658: modalWindow.height = height;
1.1075.2.42 raeburn 7659: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7660: modalWindow.open();
7661: };
7662: // END LON-CAPA Internal -->
7663: // ]]>
7664: </script>
7665: ENDMODAL
7666: }
7667:
7668: sub modal_link {
1.1075.2.42 raeburn 7669: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7670: unless ($width) { $width=480; }
7671: unless ($height) { $height=400; }
1.1031 www 7672: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 7673: unless ($transparency) { $transparency='true'; }
7674:
1.1074 raeburn 7675: my $target_attr;
7676: if (defined($target)) {
7677: $target_attr = 'target="'.$target.'"';
7678: }
7679: return <<"ENDLINK";
1.1075.2.42 raeburn 7680: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7681: $linktext</a>
7682: ENDLINK
1.1030 www 7683: }
7684:
1.1032 www 7685: sub modal_adhoc_script {
7686: my ($funcname,$width,$height,$content)=@_;
7687: return (<<ENDADHOC);
1.1046 raeburn 7688: <script type="text/javascript">
1.1032 www 7689: // <![CDATA[
7690: var $funcname = function()
7691: {
7692: modalWindow.windowId = "myModal";
7693: modalWindow.width = $width;
7694: modalWindow.height = $height;
7695: modalWindow.content = '$content';
7696: modalWindow.open();
7697: };
7698: // ]]>
7699: </script>
7700: ENDADHOC
7701: }
7702:
1.1041 www 7703: sub modal_adhoc_inner {
7704: my ($funcname,$width,$height,$content)=@_;
7705: my $innerwidth=$width-20;
7706: $content=&js_ready(
1.1042 www 7707: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 7708: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7709: $content.
1.1041 www 7710: &end_scrollbox().
1.1075.2.42 raeburn 7711: &end_page()
1.1041 www 7712: );
7713: return &modal_adhoc_script($funcname,$width,$height,$content);
7714: }
7715:
7716: sub modal_adhoc_window {
7717: my ($funcname,$width,$height,$content,$linktext)=@_;
7718: return &modal_adhoc_inner($funcname,$width,$height,$content).
7719: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7720: }
7721:
7722: sub modal_adhoc_launch {
7723: my ($funcname,$width,$height,$content)=@_;
7724: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7725: <script type="text/javascript">
7726: // <![CDATA[
7727: $funcname();
7728: // ]]>
7729: </script>
7730: ENDLAUNCH
7731: }
7732:
7733: sub modal_adhoc_close {
7734: return (<<ENDCLOSE);
7735: <script type="text/javascript">
7736: // <![CDATA[
7737: modalWindow.close();
7738: // ]]>
7739: </script>
7740: ENDCLOSE
7741: }
7742:
1.1038 www 7743: sub togglebox_script {
7744: return(<<ENDTOGGLE);
7745: <script type="text/javascript">
7746: // <![CDATA[
7747: function LCtoggleDisplay(id,hidetext,showtext) {
7748: link = document.getElementById(id + "link").childNodes[0];
7749: with (document.getElementById(id).style) {
7750: if (display == "none" ) {
7751: display = "inline";
7752: link.nodeValue = hidetext;
7753: } else {
7754: display = "none";
7755: link.nodeValue = showtext;
7756: }
7757: }
7758: }
7759: // ]]>
7760: </script>
7761: ENDTOGGLE
7762: }
7763:
1.1039 www 7764: sub start_togglebox {
7765: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7766: unless ($heading) { $heading=''; } else { $heading.=' '; }
7767: unless ($showtext) { $showtext=&mt('show'); }
7768: unless ($hidetext) { $hidetext=&mt('hide'); }
7769: unless ($headerbg) { $headerbg='#FFFFFF'; }
7770: return &start_data_table().
7771: &start_data_table_header_row().
7772: '<td bgcolor="'.$headerbg.'">'.$heading.
7773: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7774: $showtext.'\')">'.$showtext.'</a>]</td>'.
7775: &end_data_table_header_row().
7776: '<tr id="'.$id.'" style="display:none""><td>';
7777: }
7778:
7779: sub end_togglebox {
7780: return '</td></tr>'.&end_data_table();
7781: }
7782:
1.1041 www 7783: sub LCprogressbar_script {
1.1045 www 7784: my ($id)=@_;
1.1041 www 7785: return(<<ENDPROGRESS);
7786: <script type="text/javascript">
7787: // <![CDATA[
1.1045 www 7788: \$('#progressbar$id').progressbar({
1.1041 www 7789: value: 0,
7790: change: function(event, ui) {
7791: var newVal = \$(this).progressbar('option', 'value');
7792: \$('.pblabel', this).text(LCprogressTxt);
7793: }
7794: });
7795: // ]]>
7796: </script>
7797: ENDPROGRESS
7798: }
7799:
7800: sub LCprogressbarUpdate_script {
7801: return(<<ENDPROGRESSUPDATE);
7802: <style type="text/css">
7803: .ui-progressbar { position:relative; }
7804: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7805: </style>
7806: <script type="text/javascript">
7807: // <![CDATA[
1.1045 www 7808: var LCprogressTxt='---';
7809:
7810: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7811: LCprogressTxt=progresstext;
1.1045 www 7812: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7813: }
7814: // ]]>
7815: </script>
7816: ENDPROGRESSUPDATE
7817: }
7818:
1.1042 www 7819: my $LClastpercent;
1.1045 www 7820: my $LCidcnt;
7821: my $LCcurrentid;
1.1042 www 7822:
1.1041 www 7823: sub LCprogressbar {
1.1042 www 7824: my ($r)=(@_);
7825: $LClastpercent=0;
1.1045 www 7826: $LCidcnt++;
7827: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7828: my $starting=&mt('Starting');
7829: my $content=(<<ENDPROGBAR);
1.1045 www 7830: <div id="progressbar$LCcurrentid">
1.1041 www 7831: <span class="pblabel">$starting</span>
7832: </div>
7833: ENDPROGBAR
1.1045 www 7834: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7835: }
7836:
7837: sub LCprogressbarUpdate {
1.1042 www 7838: my ($r,$val,$text)=@_;
7839: unless ($val) {
7840: if ($LClastpercent) {
7841: $val=$LClastpercent;
7842: } else {
7843: $val=0;
7844: }
7845: }
1.1041 www 7846: if ($val<0) { $val=0; }
7847: if ($val>100) { $val=0; }
1.1042 www 7848: $LClastpercent=$val;
1.1041 www 7849: unless ($text) { $text=$val.'%'; }
7850: $text=&js_ready($text);
1.1044 www 7851: &r_print($r,<<ENDUPDATE);
1.1041 www 7852: <script type="text/javascript">
7853: // <![CDATA[
1.1045 www 7854: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7855: // ]]>
7856: </script>
7857: ENDUPDATE
1.1035 www 7858: }
7859:
1.1042 www 7860: sub LCprogressbarClose {
7861: my ($r)=@_;
7862: $LClastpercent=0;
1.1044 www 7863: &r_print($r,<<ENDCLOSE);
1.1042 www 7864: <script type="text/javascript">
7865: // <![CDATA[
1.1045 www 7866: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7867: // ]]>
7868: </script>
7869: ENDCLOSE
1.1044 www 7870: }
7871:
7872: sub r_print {
7873: my ($r,$to_print)=@_;
7874: if ($r) {
7875: $r->print($to_print);
7876: $r->rflush();
7877: } else {
7878: print($to_print);
7879: }
1.1042 www 7880: }
7881:
1.320 albertel 7882: sub html_encode {
7883: my ($result) = @_;
7884:
1.322 albertel 7885: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7886:
7887: return $result;
7888: }
1.1044 www 7889:
1.317 albertel 7890: sub js_ready {
7891: my ($result) = @_;
7892:
1.323 albertel 7893: $result =~ s/[\n\r]/ /xmsg;
7894: $result =~ s/\\/\\\\/xmsg;
7895: $result =~ s/'/\\'/xmsg;
1.372 albertel 7896: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7897:
7898: return $result;
7899: }
7900:
1.315 albertel 7901: sub validate_page {
7902: if ( exists($env{'internal.start_page'})
1.316 albertel 7903: && $env{'internal.start_page'} > 1) {
7904: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7905: $env{'internal.start_page'}.' '.
1.316 albertel 7906: $ENV{'request.filename'});
1.315 albertel 7907: }
7908: if ( exists($env{'internal.end_page'})
1.316 albertel 7909: && $env{'internal.end_page'} > 1) {
7910: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7911: $env{'internal.end_page'}.' '.
1.316 albertel 7912: $env{'request.filename'});
1.315 albertel 7913: }
7914: if ( exists($env{'internal.start_page'})
7915: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7916: &Apache::lonnet::logthis('start_page called without end_page '.
7917: $env{'request.filename'});
1.315 albertel 7918: }
7919: if ( ! exists($env{'internal.start_page'})
7920: && exists($env{'internal.end_page'})) {
1.316 albertel 7921: &Apache::lonnet::logthis('end_page called without start_page'.
7922: $env{'request.filename'});
1.315 albertel 7923: }
1.306 albertel 7924: }
1.315 albertel 7925:
1.996 www 7926:
7927: sub start_scrollbox {
1.1075.2.42 raeburn 7928: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready)=@_;
1.998 raeburn 7929: unless ($outerwidth) { $outerwidth='520px'; }
7930: unless ($width) { $width='500px'; }
7931: unless ($height) { $height='200px'; }
1.1075 raeburn 7932: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7933: if ($id ne '') {
1.1075.2.42 raeburn 7934: $table_id = ' id="table_'.$id.'"';
7935: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7936: }
1.1075 raeburn 7937: if ($bgcolor ne '') {
7938: $tdcol = "background-color: $bgcolor;";
7939: }
1.1075.2.42 raeburn 7940: my $nicescroll_js;
7941: if ($env{'browser.mobile'}) {
7942: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
7943: }
1.1075 raeburn 7944: return <<"END";
1.1075.2.42 raeburn 7945: $nicescroll_js
7946:
7947: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
7948: <div style="overflow:auto; width:$width; height: $height;"$div_id>
1.1075 raeburn 7949: END
1.996 www 7950: }
7951:
7952: sub end_scrollbox {
1.1036 www 7953: return '</div></td></tr></table>';
1.996 www 7954: }
7955:
1.1075.2.42 raeburn 7956: sub nicescroll_javascript {
7957: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
7958: my %options;
7959: if (ref($cursor) eq 'HASH') {
7960: %options = %{$cursor};
7961: }
7962: unless ($options{'railalign'} =~ /^left|right$/) {
7963: $options{'railalign'} = 'left';
7964: }
7965: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
7966: my $function = &get_users_function();
7967: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
7968: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
7969: $options{'cursorcolor'} = '#00F';
7970: }
7971: }
7972: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
7973: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
7974: $options{'cursoropacity'}='1.0';
7975: }
7976: } else {
7977: $options{'cursoropacity'}='1.0';
7978: }
7979: if ($options{'cursorfixedheight'} eq 'none') {
7980: delete($options{'cursorfixedheight'});
7981: } else {
7982: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
7983: }
7984: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
7985: delete($options{'railoffset'});
7986: }
7987: my @niceoptions;
7988: while (my($key,$value) = each(%options)) {
7989: if ($value =~ /^\{.+\}$/) {
7990: push(@niceoptions,$key.':'.$value);
7991: } else {
7992: push(@niceoptions,$key.':"'.$value.'"');
7993: }
7994: }
7995: my $nicescroll_js = '
7996: $(document).ready(
7997: function() {
7998: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
7999: }
8000: );
8001: ';
8002: if ($framecheck) {
8003: $nicescroll_js .= '
8004: function expand_div(caller) {
8005: if (top === self) {
8006: document.getElementById("'.$id.'").style.width = "auto";
8007: document.getElementById("'.$id.'").style.height = "auto";
8008: } else {
8009: try {
8010: if (parent.frames) {
8011: if (parent.frames.length > 1) {
8012: var framesrc = parent.frames[1].location.href;
8013: var currsrc = framesrc.replace(/\#.*$/,"");
8014: if ((caller == "search") || (currsrc == "'.$location.'")) {
8015: document.getElementById("'.$id.'").style.width = "auto";
8016: document.getElementById("'.$id.'").style.height = "auto";
8017: }
8018: }
8019: }
8020: } catch (e) {
8021: return;
8022: }
8023: }
8024: return;
8025: }
8026: ';
8027: }
8028: if ($needjsready) {
8029: $nicescroll_js = '
8030: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8031: } else {
8032: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8033: }
8034: return $nicescroll_js;
8035: }
8036:
1.318 albertel 8037: sub simple_error_page {
1.1075.2.49! raeburn 8038: my ($r,$title,$msg,$args) = @_;
! 8039: if (ref($args) eq 'HASH') {
! 8040: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
! 8041: } else {
! 8042: $msg = &mt($msg);
! 8043: }
! 8044:
1.318 albertel 8045: my $page =
8046: &Apache::loncommon::start_page($title).
1.1075.2.49! raeburn 8047: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8048: &Apache::loncommon::end_page();
8049: if (ref($r)) {
8050: $r->print($page);
1.327 albertel 8051: return;
1.318 albertel 8052: }
8053: return $page;
8054: }
1.347 albertel 8055:
8056: {
1.610 albertel 8057: my @row_count;
1.961 onken 8058:
8059: sub start_data_table_count {
8060: unshift(@row_count, 0);
8061: return;
8062: }
8063:
8064: sub end_data_table_count {
8065: shift(@row_count);
8066: return;
8067: }
8068:
1.347 albertel 8069: sub start_data_table {
1.1018 raeburn 8070: my ($add_class,$id) = @_;
1.422 albertel 8071: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8072: my $table_id;
8073: if (defined($id)) {
8074: $table_id = ' id="'.$id.'"';
8075: }
1.961 onken 8076: &start_data_table_count();
1.1018 raeburn 8077: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8078: }
8079:
8080: sub end_data_table {
1.961 onken 8081: &end_data_table_count();
1.389 albertel 8082: return '</table>'."\n";;
1.347 albertel 8083: }
8084:
8085: sub start_data_table_row {
1.974 wenzelju 8086: my ($add_class, $id) = @_;
1.610 albertel 8087: $row_count[0]++;
8088: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8089: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8090: $id = (' id="'.$id.'"') unless ($id eq '');
8091: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8092: }
1.471 banghart 8093:
8094: sub continue_data_table_row {
1.974 wenzelju 8095: my ($add_class, $id) = @_;
1.610 albertel 8096: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8097: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8098: $id = (' id="'.$id.'"') unless ($id eq '');
8099: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8100: }
1.347 albertel 8101:
8102: sub end_data_table_row {
1.389 albertel 8103: return '</tr>'."\n";;
1.347 albertel 8104: }
1.367 www 8105:
1.421 albertel 8106: sub start_data_table_empty_row {
1.707 bisitz 8107: # $row_count[0]++;
1.421 albertel 8108: return '<tr class="LC_empty_row" >'."\n";;
8109: }
8110:
8111: sub end_data_table_empty_row {
8112: return '</tr>'."\n";;
8113: }
8114:
1.367 www 8115: sub start_data_table_header_row {
1.389 albertel 8116: return '<tr class="LC_header_row">'."\n";;
1.367 www 8117: }
8118:
8119: sub end_data_table_header_row {
1.389 albertel 8120: return '</tr>'."\n";;
1.367 www 8121: }
1.890 droeschl 8122:
8123: sub data_table_caption {
8124: my $caption = shift;
8125: return "<caption class=\"LC_caption\">$caption</caption>";
8126: }
1.347 albertel 8127: }
8128:
1.548 albertel 8129: =pod
8130:
8131: =item * &inhibit_menu_check($arg)
8132:
8133: Checks for a inhibitmenu state and generates output to preserve it
8134:
8135: Inputs: $arg - can be any of
8136: - undef - in which case the return value is a string
8137: to add into arguments list of a uri
8138: - 'input' - in which case the return value is a HTML
8139: <form> <input> field of type hidden to
8140: preserve the value
8141: - a url - in which case the return value is the url with
8142: the neccesary cgi args added to preserve the
8143: inhibitmenu state
8144: - a ref to a url - no return value, but the string is
8145: updated to include the neccessary cgi
8146: args to preserve the inhibitmenu state
8147:
8148: =cut
8149:
8150: sub inhibit_menu_check {
8151: my ($arg) = @_;
8152: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8153: if ($arg eq 'input') {
8154: if ($env{'form.inhibitmenu'}) {
8155: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8156: } else {
8157: return
8158: }
8159: }
8160: if ($env{'form.inhibitmenu'}) {
8161: if (ref($arg)) {
8162: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8163: } elsif ($arg eq '') {
8164: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8165: } else {
8166: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8167: }
8168: }
8169: if (!ref($arg)) {
8170: return $arg;
8171: }
8172: }
8173:
1.251 albertel 8174: ###############################################
1.182 matthew 8175:
8176: =pod
8177:
1.549 albertel 8178: =back
8179:
8180: =head1 User Information Routines
8181:
8182: =over 4
8183:
1.405 albertel 8184: =item * &get_users_function()
1.182 matthew 8185:
8186: Used by &bodytag to determine the current users primary role.
8187: Returns either 'student','coordinator','admin', or 'author'.
8188:
8189: =cut
8190:
8191: ###############################################
8192: sub get_users_function {
1.815 tempelho 8193: my $function = 'norole';
1.818 tempelho 8194: if ($env{'request.role'}=~/^(st)/) {
8195: $function='student';
8196: }
1.907 raeburn 8197: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8198: $function='coordinator';
8199: }
1.258 albertel 8200: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8201: $function='admin';
8202: }
1.826 bisitz 8203: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8204: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8205: $function='author';
8206: }
8207: return $function;
1.54 www 8208: }
1.99 www 8209:
8210: ###############################################
8211:
1.233 raeburn 8212: =pod
8213:
1.821 raeburn 8214: =item * &show_course()
8215:
8216: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8217: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8218:
8219: Inputs:
8220: None
8221:
8222: Outputs:
8223: Scalar: 1 if 'Course' to be used, 0 otherwise.
8224:
8225: =cut
8226:
8227: ###############################################
8228: sub show_course {
8229: my $course = !$env{'user.adv'};
8230: if (!$env{'user.adv'}) {
8231: foreach my $env (keys(%env)) {
8232: next if ($env !~ m/^user\.priv\./);
8233: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8234: $course = 0;
8235: last;
8236: }
8237: }
8238: }
8239: return $course;
8240: }
8241:
8242: ###############################################
8243:
8244: =pod
8245:
1.542 raeburn 8246: =item * &check_user_status()
1.274 raeburn 8247:
8248: Determines current status of supplied role for a
8249: specific user. Roles can be active, previous or future.
8250:
8251: Inputs:
8252: user's domain, user's username, course's domain,
1.375 raeburn 8253: course's number, optional section ID.
1.274 raeburn 8254:
8255: Outputs:
8256: role status: active, previous or future.
8257:
8258: =cut
8259:
8260: sub check_user_status {
1.412 raeburn 8261: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8262: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8263: my @uroles = keys %userinfo;
8264: my $srchstr;
8265: my $active_chk = 'none';
1.412 raeburn 8266: my $now = time;
1.274 raeburn 8267: if (@uroles > 0) {
1.908 raeburn 8268: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8269: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8270: } else {
1.412 raeburn 8271: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8272: }
8273: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8274: my $role_end = 0;
8275: my $role_start = 0;
8276: $active_chk = 'active';
1.412 raeburn 8277: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8278: $role_end = $1;
8279: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8280: $role_start = $1;
1.274 raeburn 8281: }
8282: }
8283: if ($role_start > 0) {
1.412 raeburn 8284: if ($now < $role_start) {
1.274 raeburn 8285: $active_chk = 'future';
8286: }
8287: }
8288: if ($role_end > 0) {
1.412 raeburn 8289: if ($now > $role_end) {
1.274 raeburn 8290: $active_chk = 'previous';
8291: }
8292: }
8293: }
8294: }
8295: return $active_chk;
8296: }
8297:
8298: ###############################################
8299:
8300: =pod
8301:
1.405 albertel 8302: =item * &get_sections()
1.233 raeburn 8303:
8304: Determines all the sections for a course including
8305: sections with students and sections containing other roles.
1.419 raeburn 8306: Incoming parameters:
8307:
8308: 1. domain
8309: 2. course number
8310: 3. reference to array containing roles for which sections should
8311: be gathered (optional).
8312: 4. reference to array containing status types for which sections
8313: should be gathered (optional).
8314:
8315: If the third argument is undefined, sections are gathered for any role.
8316: If the fourth argument is undefined, sections are gathered for any status.
8317: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8318:
1.374 raeburn 8319: Returns section hash (keys are section IDs, values are
8320: number of users in each section), subject to the
1.419 raeburn 8321: optional roles filter, optional status filter
1.233 raeburn 8322:
8323: =cut
8324:
8325: ###############################################
8326: sub get_sections {
1.419 raeburn 8327: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8328: if (!defined($cdom) || !defined($cnum)) {
8329: my $cid = $env{'request.course.id'};
8330:
8331: return if (!defined($cid));
8332:
8333: $cdom = $env{'course.'.$cid.'.domain'};
8334: $cnum = $env{'course.'.$cid.'.num'};
8335: }
8336:
8337: my %sectioncount;
1.419 raeburn 8338: my $now = time;
1.240 albertel 8339:
1.1075.2.33 raeburn 8340: my $check_students = 1;
8341: my $only_students = 0;
8342: if (ref($possible_roles) eq 'ARRAY') {
8343: if (grep(/^st$/,@{$possible_roles})) {
8344: if (@{$possible_roles} == 1) {
8345: $only_students = 1;
8346: }
8347: } else {
8348: $check_students = 0;
8349: }
8350: }
8351:
8352: if ($check_students) {
1.276 albertel 8353: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8354: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8355: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8356: my $start_index = &Apache::loncoursedata::CL_START();
8357: my $end_index = &Apache::loncoursedata::CL_END();
8358: my $status;
1.366 albertel 8359: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8360: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8361: $data->[$status_index],
8362: $data->[$start_index],
8363: $data->[$end_index]);
8364: if ($stu_status eq 'Active') {
8365: $status = 'active';
8366: } elsif ($end < $now) {
8367: $status = 'previous';
8368: } elsif ($start > $now) {
8369: $status = 'future';
8370: }
8371: if ($section ne '-1' && $section !~ /^\s*$/) {
8372: if ((!defined($possible_status)) || (($status ne '') &&
8373: (grep/^\Q$status\E$/,@{$possible_status}))) {
8374: $sectioncount{$section}++;
8375: }
1.240 albertel 8376: }
8377: }
8378: }
1.1075.2.33 raeburn 8379: if ($only_students) {
8380: return %sectioncount;
8381: }
1.240 albertel 8382: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8383: foreach my $user (sort(keys(%courseroles))) {
8384: if ($user !~ /^(\w{2})/) { next; }
8385: my ($role) = ($user =~ /^(\w{2})/);
8386: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8387: my ($section,$status);
1.240 albertel 8388: if ($role eq 'cr' &&
8389: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8390: $section=$1;
8391: }
8392: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8393: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8394: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8395: if ($end == -1 && $start == -1) {
8396: next; #deleted role
8397: }
8398: if (!defined($possible_status)) {
8399: $sectioncount{$section}++;
8400: } else {
8401: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8402: $status = 'active';
8403: } elsif ($end < $now) {
8404: $status = 'future';
8405: } elsif ($start > $now) {
8406: $status = 'previous';
8407: }
8408: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8409: $sectioncount{$section}++;
8410: }
8411: }
1.233 raeburn 8412: }
1.366 albertel 8413: return %sectioncount;
1.233 raeburn 8414: }
8415:
1.274 raeburn 8416: ###############################################
1.294 raeburn 8417:
8418: =pod
1.405 albertel 8419:
8420: =item * &get_course_users()
8421:
1.275 raeburn 8422: Retrieves usernames:domains for users in the specified course
8423: with specific role(s), and access status.
8424:
8425: Incoming parameters:
1.277 albertel 8426: 1. course domain
8427: 2. course number
8428: 3. access status: users must have - either active,
1.275 raeburn 8429: previous, future, or all.
1.277 albertel 8430: 4. reference to array of permissible roles
1.288 raeburn 8431: 5. reference to array of section restrictions (optional)
8432: 6. reference to results object (hash of hashes).
8433: 7. reference to optional userdata hash
1.609 raeburn 8434: 8. reference to optional statushash
1.630 raeburn 8435: 9. flag if privileged users (except those set to unhide in
8436: course settings) should be excluded
1.609 raeburn 8437: Keys of top level results hash are roles.
1.275 raeburn 8438: Keys of inner hashes are username:domain, with
8439: values set to access type.
1.288 raeburn 8440: Optional userdata hash returns an array with arguments in the
8441: same order as loncoursedata::get_classlist() for student data.
8442:
1.609 raeburn 8443: Optional statushash returns
8444:
1.288 raeburn 8445: Entries for end, start, section and status are blank because
8446: of the possibility of multiple values for non-student roles.
8447:
1.275 raeburn 8448: =cut
1.405 albertel 8449:
1.275 raeburn 8450: ###############################################
1.405 albertel 8451:
1.275 raeburn 8452: sub get_course_users {
1.630 raeburn 8453: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8454: my %idx = ();
1.419 raeburn 8455: my %seclists;
1.288 raeburn 8456:
8457: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8458: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8459: $idx{end} = &Apache::loncoursedata::CL_END();
8460: $idx{start} = &Apache::loncoursedata::CL_START();
8461: $idx{id} = &Apache::loncoursedata::CL_ID();
8462: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8463: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8464: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8465:
1.290 albertel 8466: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8467: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8468: my $now = time;
1.277 albertel 8469: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8470: my $match = 0;
1.412 raeburn 8471: my $secmatch = 0;
1.419 raeburn 8472: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8473: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8474: if ($section eq '') {
8475: $section = 'none';
8476: }
1.291 albertel 8477: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8478: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8479: $secmatch = 1;
8480: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8481: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8482: $secmatch = 1;
8483: }
8484: } else {
1.419 raeburn 8485: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8486: $secmatch = 1;
8487: }
1.290 albertel 8488: }
1.412 raeburn 8489: if (!$secmatch) {
8490: next;
8491: }
1.419 raeburn 8492: }
1.275 raeburn 8493: if (defined($$types{'active'})) {
1.288 raeburn 8494: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8495: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8496: $match = 1;
1.275 raeburn 8497: }
8498: }
8499: if (defined($$types{'previous'})) {
1.609 raeburn 8500: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8501: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8502: $match = 1;
1.275 raeburn 8503: }
8504: }
8505: if (defined($$types{'future'})) {
1.609 raeburn 8506: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8507: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8508: $match = 1;
1.275 raeburn 8509: }
8510: }
1.609 raeburn 8511: if ($match) {
8512: push(@{$seclists{$student}},$section);
8513: if (ref($userdata) eq 'HASH') {
8514: $$userdata{$student} = $$classlist{$student};
8515: }
8516: if (ref($statushash) eq 'HASH') {
8517: $statushash->{$student}{'st'}{$section} = $status;
8518: }
1.288 raeburn 8519: }
1.275 raeburn 8520: }
8521: }
1.412 raeburn 8522: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8523: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8524: my $now = time;
1.609 raeburn 8525: my %displaystatus = ( previous => 'Expired',
8526: active => 'Active',
8527: future => 'Future',
8528: );
1.1075.2.36 raeburn 8529: my (%nothide,@possdoms);
1.630 raeburn 8530: if ($hidepriv) {
8531: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8532: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8533: if ($user !~ /:/) {
8534: $nothide{join(':',split(/[\@]/,$user))}=1;
8535: } else {
8536: $nothide{$user} = 1;
8537: }
8538: }
1.1075.2.36 raeburn 8539: my @possdoms = ($cdom);
8540: if ($coursehash{'checkforpriv'}) {
8541: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8542: }
1.630 raeburn 8543: }
1.439 raeburn 8544: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8545: my $match = 0;
1.412 raeburn 8546: my $secmatch = 0;
1.439 raeburn 8547: my $status;
1.412 raeburn 8548: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8549: $user =~ s/:$//;
1.439 raeburn 8550: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8551: if ($end == -1 || $start == -1) {
8552: next;
8553: }
8554: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8555: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8556: my ($uname,$udom) = split(/:/,$user);
8557: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8558: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8559: $secmatch = 1;
8560: } elsif ($usec eq '') {
1.420 albertel 8561: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8562: $secmatch = 1;
8563: }
8564: } else {
8565: if (grep(/^\Q$usec\E$/,@{$sections})) {
8566: $secmatch = 1;
8567: }
8568: }
8569: if (!$secmatch) {
8570: next;
8571: }
1.288 raeburn 8572: }
1.419 raeburn 8573: if ($usec eq '') {
8574: $usec = 'none';
8575: }
1.275 raeburn 8576: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8577: if ($hidepriv) {
1.1075.2.36 raeburn 8578: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8579: (!$nothide{$uname.':'.$udom})) {
8580: next;
8581: }
8582: }
1.503 raeburn 8583: if ($end > 0 && $end < $now) {
1.439 raeburn 8584: $status = 'previous';
8585: } elsif ($start > $now) {
8586: $status = 'future';
8587: } else {
8588: $status = 'active';
8589: }
1.277 albertel 8590: foreach my $type (keys(%{$types})) {
1.275 raeburn 8591: if ($status eq $type) {
1.420 albertel 8592: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8593: push(@{$$users{$role}{$user}},$type);
8594: }
1.288 raeburn 8595: $match = 1;
8596: }
8597: }
1.419 raeburn 8598: if (($match) && (ref($userdata) eq 'HASH')) {
8599: if (!exists($$userdata{$uname.':'.$udom})) {
8600: &get_user_info($udom,$uname,\%idx,$userdata);
8601: }
1.420 albertel 8602: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8603: push(@{$seclists{$uname.':'.$udom}},$usec);
8604: }
1.609 raeburn 8605: if (ref($statushash) eq 'HASH') {
8606: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8607: }
1.275 raeburn 8608: }
8609: }
8610: }
8611: }
1.290 albertel 8612: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8613: if ((defined($cdom)) && (defined($cnum))) {
8614: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8615: if ( defined($csettings{'internal.courseowner'}) ) {
8616: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8617: next if ($owner eq '');
8618: my ($ownername,$ownerdom);
8619: if ($owner =~ /^([^:]+):([^:]+)$/) {
8620: $ownername = $1;
8621: $ownerdom = $2;
8622: } else {
8623: $ownername = $owner;
8624: $ownerdom = $cdom;
8625: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8626: }
8627: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8628: if (defined($userdata) &&
1.609 raeburn 8629: !exists($$userdata{$owner})) {
8630: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8631: if (!grep(/^none$/,@{$seclists{$owner}})) {
8632: push(@{$seclists{$owner}},'none');
8633: }
8634: if (ref($statushash) eq 'HASH') {
8635: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8636: }
1.290 albertel 8637: }
1.279 raeburn 8638: }
8639: }
8640: }
1.419 raeburn 8641: foreach my $user (keys(%seclists)) {
8642: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8643: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8644: }
1.275 raeburn 8645: }
8646: return;
8647: }
8648:
1.288 raeburn 8649: sub get_user_info {
8650: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8651: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8652: &plainname($uname,$udom,'lastname');
1.291 albertel 8653: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8654: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8655: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8656: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8657: return;
8658: }
1.275 raeburn 8659:
1.472 raeburn 8660: ###############################################
8661:
8662: =pod
8663:
8664: =item * &get_user_quota()
8665:
1.1075.2.41 raeburn 8666: Retrieves quota assigned for storage of user files.
8667: Default is to report quota for portfolio files.
1.472 raeburn 8668:
8669: Incoming parameters:
8670: 1. user's username
8671: 2. user's domain
1.1075.2.41 raeburn 8672: 3. quota name - portfolio, author, or course
8673: (if no quota name provided, defaults to portfolio).
1.1075.2.42 raeburn 8674: 4. crstype - official, unofficial or community, if quota name is
8675: course
1.472 raeburn 8676:
8677: Returns:
1.536 raeburn 8678: 1. Disk quota (in Mb) assigned to student.
8679: 2. (Optional) Type of setting: custom or default
8680: (individually assigned or default for user's
8681: institutional status).
8682: 3. (Optional) - User's institutional status (e.g., faculty, staff
8683: or student - types as defined in localenroll::inst_usertypes
8684: for user's domain, which determines default quota for user.
8685: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8686:
8687: If a value has been stored in the user's environment,
1.536 raeburn 8688: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 8689: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8690:
8691: =cut
8692:
8693: ###############################################
8694:
8695:
8696: sub get_user_quota {
1.1075.2.42 raeburn 8697: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8698: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8699: if (!defined($udom)) {
8700: $udom = $env{'user.domain'};
8701: }
8702: if (!defined($uname)) {
8703: $uname = $env{'user.name'};
8704: }
8705: if (($udom eq '' || $uname eq '') ||
8706: ($udom eq 'public') && ($uname eq 'public')) {
8707: $quota = 0;
1.536 raeburn 8708: $quotatype = 'default';
8709: $defquota = 0;
1.472 raeburn 8710: } else {
1.536 raeburn 8711: my $inststatus;
1.1075.2.41 raeburn 8712: if ($quotaname eq 'course') {
8713: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8714: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8715: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8716: } else {
8717: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8718: $quota = $cenv{'internal.uploadquota'};
8719: }
1.536 raeburn 8720: } else {
1.1075.2.41 raeburn 8721: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8722: if ($quotaname eq 'author') {
8723: $quota = $env{'environment.authorquota'};
8724: } else {
8725: $quota = $env{'environment.portfolioquota'};
8726: }
8727: $inststatus = $env{'environment.inststatus'};
8728: } else {
8729: my %userenv =
8730: &Apache::lonnet::get('environment',['portfolioquota',
8731: 'authorquota','inststatus'],$udom,$uname);
8732: my ($tmp) = keys(%userenv);
8733: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8734: if ($quotaname eq 'author') {
8735: $quota = $userenv{'authorquota'};
8736: } else {
8737: $quota = $userenv{'portfolioquota'};
8738: }
8739: $inststatus = $userenv{'inststatus'};
8740: } else {
8741: undef(%userenv);
8742: }
8743: }
8744: }
8745: if ($quota eq '' || wantarray) {
8746: if ($quotaname eq 'course') {
8747: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.42 raeburn 8748: if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'community')) {
8749: $defquota = $domdefs{$crstype.'quota'};
8750: }
8751: if ($defquota eq '') {
8752: $defquota = 500;
8753: }
1.1075.2.41 raeburn 8754: } else {
8755: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8756: }
8757: if ($quota eq '') {
8758: $quota = $defquota;
8759: $quotatype = 'default';
8760: } else {
8761: $quotatype = 'custom';
8762: }
1.472 raeburn 8763: }
8764: }
1.536 raeburn 8765: if (wantarray) {
8766: return ($quota,$quotatype,$settingstatus,$defquota);
8767: } else {
8768: return $quota;
8769: }
1.472 raeburn 8770: }
8771:
8772: ###############################################
8773:
8774: =pod
8775:
8776: =item * &default_quota()
8777:
1.536 raeburn 8778: Retrieves default quota assigned for storage of user portfolio files,
8779: given an (optional) user's institutional status.
1.472 raeburn 8780:
8781: Incoming parameters:
1.1075.2.42 raeburn 8782:
1.472 raeburn 8783: 1. domain
1.536 raeburn 8784: 2. (Optional) institutional status(es). This is a : separated list of
8785: status types (e.g., faculty, staff, student etc.)
8786: which apply to the user for whom the default is being retrieved.
8787: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 8788: default quota will be returned.
8789: 3. quota name - portfolio, author, or course
8790: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8791:
8792: Returns:
1.1075.2.42 raeburn 8793:
1.472 raeburn 8794: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 8795: 2. (Optional) institutional type which determined the value of the
8796: default quota.
1.472 raeburn 8797:
8798: If a value has been stored in the domain's configuration db,
8799: it will return that, otherwise it returns 20 (for backwards
8800: compatibility with domains which have not set up a configuration
8801: db file; the original statically defined portfolio quota was 20 Mb).
8802:
1.536 raeburn 8803: If the user's status includes multiple types (e.g., staff and student),
8804: the largest default quota which applies to the user determines the
8805: default quota returned.
8806:
1.472 raeburn 8807: =cut
8808:
8809: ###############################################
8810:
8811:
8812: sub default_quota {
1.1075.2.41 raeburn 8813: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8814: my ($defquota,$settingstatus);
8815: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8816: ['quotas'],$udom);
1.1075.2.41 raeburn 8817: my $key = 'defaultquota';
8818: if ($quotaname eq 'author') {
8819: $key = 'authorquota';
8820: }
1.622 raeburn 8821: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8822: if ($inststatus ne '') {
1.765 raeburn 8823: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8824: foreach my $item (@statuses) {
1.1075.2.41 raeburn 8825: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8826: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8827: if ($defquota eq '') {
1.1075.2.41 raeburn 8828: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8829: $settingstatus = $item;
1.1075.2.41 raeburn 8830: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8831: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8832: $settingstatus = $item;
8833: }
8834: }
1.1075.2.41 raeburn 8835: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8836: if ($quotahash{'quotas'}{$item} ne '') {
8837: if ($defquota eq '') {
8838: $defquota = $quotahash{'quotas'}{$item};
8839: $settingstatus = $item;
8840: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8841: $defquota = $quotahash{'quotas'}{$item};
8842: $settingstatus = $item;
8843: }
1.536 raeburn 8844: }
8845: }
8846: }
8847: }
8848: if ($defquota eq '') {
1.1075.2.41 raeburn 8849: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8850: $defquota = $quotahash{'quotas'}{$key}{'default'};
8851: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8852: $defquota = $quotahash{'quotas'}{'default'};
8853: }
1.536 raeburn 8854: $settingstatus = 'default';
1.1075.2.42 raeburn 8855: if ($defquota eq '') {
8856: if ($quotaname eq 'author') {
8857: $defquota = 500;
8858: }
8859: }
1.536 raeburn 8860: }
8861: } else {
8862: $settingstatus = 'default';
1.1075.2.41 raeburn 8863: if ($quotaname eq 'author') {
8864: $defquota = 500;
8865: } else {
8866: $defquota = 20;
8867: }
1.536 raeburn 8868: }
8869: if (wantarray) {
8870: return ($defquota,$settingstatus);
1.472 raeburn 8871: } else {
1.536 raeburn 8872: return $defquota;
1.472 raeburn 8873: }
8874: }
8875:
1.1075.2.41 raeburn 8876: ###############################################
8877:
8878: =pod
8879:
1.1075.2.42 raeburn 8880: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 8881:
8882: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 8883: of existing file within authoring space will cause quota for the authoring
8884: space to be exceeded.
8885:
8886: Same, if upload of a file directly to a course/community via Course Editor
8887: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 8888:
8889: Inputs: 6
1.1075.2.42 raeburn 8890: 1. username or coursenum
1.1075.2.41 raeburn 8891: 2. domain
1.1075.2.42 raeburn 8892: 3. context ('author' or 'course')
1.1075.2.41 raeburn 8893: 4. filename of file for which action is being requested
8894: 5. filesize (kB) of file
8895: 6. action being taken: copy or upload.
8896:
8897: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
8898: otherwise return null.
8899:
1.1075.2.42 raeburn 8900: =back
8901:
1.1075.2.41 raeburn 8902: =cut
8903:
1.1075.2.42 raeburn 8904: sub excess_filesize_warning {
8905: my ($uname,$udom,$context,$filename,$filesize,$action) = @_;
8906: my $current_disk_usage = 0;
8907: my $disk_quota = &get_user_quota($uname,$udom,$context); #expressed in MB
8908: if ($context eq 'author') {
8909: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8910: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8911: } else {
8912: foreach my $subdir ('docs','supplemental') {
8913: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8914: }
8915: }
1.1075.2.41 raeburn 8916: $disk_quota = int($disk_quota * 1000);
8917: if (($current_disk_usage + $filesize) > $disk_quota) {
8918: return '<p><span class="LC_warning">'.
8919: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
8920: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</span>'.
8921: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
8922: $disk_quota,$current_disk_usage).
8923: '</p>';
8924: }
8925: return;
8926: }
8927:
8928: ###############################################
8929:
8930:
1.384 raeburn 8931: sub get_secgrprole_info {
8932: my ($cdom,$cnum,$needroles,$type) = @_;
8933: my %sections_count = &get_sections($cdom,$cnum);
8934: my @sections = (sort {$a <=> $b} keys(%sections_count));
8935: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8936: my @groups = sort(keys(%curr_groups));
8937: my $allroles = [];
8938: my $rolehash;
8939: my $accesshash = {
8940: active => 'Currently has access',
8941: future => 'Will have future access',
8942: previous => 'Previously had access',
8943: };
8944: if ($needroles) {
8945: $rolehash = {'all' => 'all'};
1.385 albertel 8946: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8947: if (&Apache::lonnet::error(%user_roles)) {
8948: undef(%user_roles);
8949: }
8950: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8951: my ($role)=split(/\:/,$item,2);
8952: if ($role eq 'cr') { next; }
8953: if ($role =~ /^cr/) {
8954: $$rolehash{$role} = (split('/',$role))[3];
8955: } else {
8956: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8957: }
8958: }
8959: foreach my $key (sort(keys(%{$rolehash}))) {
8960: push(@{$allroles},$key);
8961: }
8962: push (@{$allroles},'st');
8963: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8964: }
8965: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8966: }
8967:
1.555 raeburn 8968: sub user_picker {
1.994 raeburn 8969: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8970: my $currdom = $dom;
8971: my %curr_selected = (
8972: srchin => 'dom',
1.580 raeburn 8973: srchby => 'lastname',
1.555 raeburn 8974: );
8975: my $srchterm;
1.625 raeburn 8976: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 8977: if ($srch->{'srchby'} ne '') {
8978: $curr_selected{'srchby'} = $srch->{'srchby'};
8979: }
8980: if ($srch->{'srchin'} ne '') {
8981: $curr_selected{'srchin'} = $srch->{'srchin'};
8982: }
8983: if ($srch->{'srchtype'} ne '') {
8984: $curr_selected{'srchtype'} = $srch->{'srchtype'};
8985: }
8986: if ($srch->{'srchdomain'} ne '') {
8987: $currdom = $srch->{'srchdomain'};
8988: }
8989: $srchterm = $srch->{'srchterm'};
8990: }
8991: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 8992: 'usr' => 'Search criteria',
1.563 raeburn 8993: 'doma' => 'Domain/institution to search',
1.558 albertel 8994: 'uname' => 'username',
8995: 'lastname' => 'last name',
1.555 raeburn 8996: 'lastfirst' => 'last name, first name',
1.558 albertel 8997: 'crs' => 'in this course',
1.576 raeburn 8998: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 8999: 'alc' => 'all LON-CAPA',
1.573 raeburn 9000: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9001: 'exact' => 'is',
9002: 'contains' => 'contains',
1.569 raeburn 9003: 'begins' => 'begins with',
1.571 raeburn 9004: 'youm' => "You must include some text to search for.",
9005: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9006: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9007: 'yomc' => "You must choose a domain when using an institutional directory search.",
9008: 'ymcd' => "You must choose a domain when using a domain search.",
9009: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9010: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9011: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9012: );
1.563 raeburn 9013: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9014: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9015:
9016: my @srchins = ('crs','dom','alc','instd');
9017:
9018: foreach my $option (@srchins) {
9019: # FIXME 'alc' option unavailable until
9020: # loncreateuser::print_user_query_page()
9021: # has been completed.
9022: next if ($option eq 'alc');
1.880 raeburn 9023: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9024: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9025: if ($curr_selected{'srchin'} eq $option) {
9026: $srchinsel .= '
9027: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9028: } else {
9029: $srchinsel .= '
9030: <option value="'.$option.'">'.$lt{$option}.'</option>';
9031: }
1.555 raeburn 9032: }
1.563 raeburn 9033: $srchinsel .= "\n </select>\n";
1.555 raeburn 9034:
9035: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9036: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9037: if ($curr_selected{'srchby'} eq $option) {
9038: $srchbysel .= '
9039: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9040: } else {
9041: $srchbysel .= '
9042: <option value="'.$option.'">'.$lt{$option}.'</option>';
9043: }
9044: }
9045: $srchbysel .= "\n </select>\n";
9046:
9047: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9048: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9049: if ($curr_selected{'srchtype'} eq $option) {
9050: $srchtypesel .= '
9051: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9052: } else {
9053: $srchtypesel .= '
9054: <option value="'.$option.'">'.$lt{$option}.'</option>';
9055: }
9056: }
9057: $srchtypesel .= "\n </select>\n";
9058:
1.558 albertel 9059: my ($newuserscript,$new_user_create);
1.994 raeburn 9060: my $context_dom = $env{'request.role.domain'};
9061: if ($context eq 'requestcrs') {
9062: if ($env{'form.coursedom'} ne '') {
9063: $context_dom = $env{'form.coursedom'};
9064: }
9065: }
1.556 raeburn 9066: if ($forcenewuser) {
1.576 raeburn 9067: if (ref($srch) eq 'HASH') {
1.994 raeburn 9068: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9069: if ($cancreate) {
9070: $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>';
9071: } else {
1.799 bisitz 9072: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9073: my %usertypetext = (
9074: official => 'institutional',
9075: unofficial => 'non-institutional',
9076: );
1.799 bisitz 9077: $new_user_create = '<p class="LC_warning">'
9078: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9079: .' '
9080: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9081: ,'<a href="'.$helplink.'">','</a>')
9082: .'</p><br />';
1.627 raeburn 9083: }
1.576 raeburn 9084: }
9085: }
9086:
1.556 raeburn 9087: $newuserscript = <<"ENDSCRIPT";
9088:
1.570 raeburn 9089: function setSearch(createnew,callingForm) {
1.556 raeburn 9090: if (createnew == 1) {
1.570 raeburn 9091: for (var i=0; i<callingForm.srchby.length; i++) {
9092: if (callingForm.srchby.options[i].value == 'uname') {
9093: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9094: }
9095: }
1.570 raeburn 9096: for (var i=0; i<callingForm.srchin.length; i++) {
9097: if ( callingForm.srchin.options[i].value == 'dom') {
9098: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9099: }
9100: }
1.570 raeburn 9101: for (var i=0; i<callingForm.srchtype.length; i++) {
9102: if (callingForm.srchtype.options[i].value == 'exact') {
9103: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9104: }
9105: }
1.570 raeburn 9106: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9107: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9108: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9109: }
9110: }
9111: }
9112: }
9113: ENDSCRIPT
1.558 albertel 9114:
1.556 raeburn 9115: }
9116:
1.555 raeburn 9117: my $output = <<"END_BLOCK";
1.556 raeburn 9118: <script type="text/javascript">
1.824 bisitz 9119: // <![CDATA[
1.570 raeburn 9120: function validateEntry(callingForm) {
1.558 albertel 9121:
1.556 raeburn 9122: var checkok = 1;
1.558 albertel 9123: var srchin;
1.570 raeburn 9124: for (var i=0; i<callingForm.srchin.length; i++) {
9125: if ( callingForm.srchin[i].checked ) {
9126: srchin = callingForm.srchin[i].value;
1.558 albertel 9127: }
9128: }
9129:
1.570 raeburn 9130: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9131: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9132: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9133: var srchterm = callingForm.srchterm.value;
9134: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9135: var msg = "";
9136:
9137: if (srchterm == "") {
9138: checkok = 0;
1.571 raeburn 9139: msg += "$lt{'youm'}\\n";
1.556 raeburn 9140: }
9141:
1.569 raeburn 9142: if (srchtype== 'begins') {
9143: if (srchterm.length < 2) {
9144: checkok = 0;
1.571 raeburn 9145: msg += "$lt{'thte'}\\n";
1.569 raeburn 9146: }
9147: }
9148:
1.556 raeburn 9149: if (srchtype== 'contains') {
9150: if (srchterm.length < 3) {
9151: checkok = 0;
1.571 raeburn 9152: msg += "$lt{'thet'}\\n";
1.556 raeburn 9153: }
9154: }
9155: if (srchin == 'instd') {
9156: if (srchdomain == '') {
9157: checkok = 0;
1.571 raeburn 9158: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9159: }
9160: }
9161: if (srchin == 'dom') {
9162: if (srchdomain == '') {
9163: checkok = 0;
1.571 raeburn 9164: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9165: }
9166: }
9167: if (srchby == 'lastfirst') {
9168: if (srchterm.indexOf(",") == -1) {
9169: checkok = 0;
1.571 raeburn 9170: msg += "$lt{'whus'}\\n";
1.556 raeburn 9171: }
9172: if (srchterm.indexOf(",") == srchterm.length -1) {
9173: checkok = 0;
1.571 raeburn 9174: msg += "$lt{'whse'}\\n";
1.556 raeburn 9175: }
9176: }
9177: if (checkok == 0) {
1.571 raeburn 9178: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9179: return;
9180: }
9181: if (checkok == 1) {
1.570 raeburn 9182: callingForm.submit();
1.556 raeburn 9183: }
9184: }
9185:
9186: $newuserscript
9187:
1.824 bisitz 9188: // ]]>
1.556 raeburn 9189: </script>
1.558 albertel 9190:
9191: $new_user_create
9192:
1.555 raeburn 9193: END_BLOCK
1.558 albertel 9194:
1.876 raeburn 9195: $output .= &Apache::lonhtmlcommon::start_pick_box().
9196: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9197: $domform.
9198: &Apache::lonhtmlcommon::row_closure().
9199: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9200: $srchbysel.
9201: $srchtypesel.
9202: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9203: $srchinsel.
9204: &Apache::lonhtmlcommon::row_closure(1).
9205: &Apache::lonhtmlcommon::end_pick_box().
9206: '<br />';
1.555 raeburn 9207: return $output;
9208: }
9209:
1.612 raeburn 9210: sub user_rule_check {
1.615 raeburn 9211: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9212: my $response;
9213: if (ref($usershash) eq 'HASH') {
9214: foreach my $user (keys(%{$usershash})) {
9215: my ($uname,$udom) = split(/:/,$user);
9216: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9217: my ($id,$newuser);
1.612 raeburn 9218: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9219: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9220: $id = $usershash->{$user}->{'id'};
9221: }
9222: my $inst_response;
9223: if (ref($checks) eq 'HASH') {
9224: if (defined($checks->{'username'})) {
1.615 raeburn 9225: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9226: &Apache::lonnet::get_instuser($udom,$uname);
9227: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9228: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9229: &Apache::lonnet::get_instuser($udom,undef,$id);
9230: }
1.615 raeburn 9231: } else {
9232: ($inst_response,%{$inst_results->{$user}}) =
9233: &Apache::lonnet::get_instuser($udom,$uname);
9234: return;
1.612 raeburn 9235: }
1.615 raeburn 9236: if (!$got_rules->{$udom}) {
1.612 raeburn 9237: my %domconfig = &Apache::lonnet::get_dom('configuration',
9238: ['usercreation'],$udom);
9239: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9240: foreach my $item ('username','id') {
1.612 raeburn 9241: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9242: $$curr_rules{$udom}{$item} =
9243: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9244: }
9245: }
9246: }
1.615 raeburn 9247: $got_rules->{$udom} = 1;
1.585 raeburn 9248: }
1.612 raeburn 9249: foreach my $item (keys(%{$checks})) {
9250: if (ref($$curr_rules{$udom}) eq 'HASH') {
9251: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9252: if (@{$$curr_rules{$udom}{$item}} > 0) {
9253: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9254: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9255: if ($rule_check{$rule}) {
9256: $$rulematch{$user}{$item} = $rule;
9257: if ($inst_response eq 'ok') {
1.615 raeburn 9258: if (ref($inst_results) eq 'HASH') {
9259: if (ref($inst_results->{$user}) eq 'HASH') {
9260: if (keys(%{$inst_results->{$user}}) == 0) {
9261: $$alerts{$item}{$udom}{$uname} = 1;
9262: }
1.612 raeburn 9263: }
9264: }
1.615 raeburn 9265: }
9266: last;
1.585 raeburn 9267: }
9268: }
9269: }
9270: }
9271: }
9272: }
9273: }
9274: }
1.612 raeburn 9275: return;
9276: }
9277:
9278: sub user_rule_formats {
9279: my ($domain,$domdesc,$curr_rules,$check) = @_;
9280: my %text = (
9281: 'username' => 'Usernames',
9282: 'id' => 'IDs',
9283: );
9284: my $output;
9285: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9286: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9287: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9288: $output = '<br />'.
9289: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9290: '<span class="LC_cusr_emph">','</span>',$domdesc).
9291: ' <ul>';
1.612 raeburn 9292: foreach my $rule (@{$ruleorder}) {
9293: if (ref($curr_rules) eq 'ARRAY') {
9294: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9295: if (ref($rules->{$rule}) eq 'HASH') {
9296: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9297: $rules->{$rule}{'desc'}.'</li>';
9298: }
9299: }
9300: }
9301: }
9302: $output .= '</ul>';
9303: }
9304: }
9305: return $output;
9306: }
9307:
9308: sub instrule_disallow_msg {
1.615 raeburn 9309: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9310: my $response;
9311: my %text = (
9312: item => 'username',
9313: items => 'usernames',
9314: match => 'matches',
9315: do => 'does',
9316: action => 'a username',
9317: one => 'one',
9318: );
9319: if ($count > 1) {
9320: $text{'item'} = 'usernames';
9321: $text{'match'} ='match';
9322: $text{'do'} = 'do';
9323: $text{'action'} = 'usernames',
9324: $text{'one'} = 'ones';
9325: }
9326: if ($checkitem eq 'id') {
9327: $text{'items'} = 'IDs';
9328: $text{'item'} = 'ID';
9329: $text{'action'} = 'an ID';
1.615 raeburn 9330: if ($count > 1) {
9331: $text{'item'} = 'IDs';
9332: $text{'action'} = 'IDs';
9333: }
1.612 raeburn 9334: }
1.674 bisitz 9335: $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 9336: if ($mode eq 'upload') {
9337: if ($checkitem eq 'username') {
9338: $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'}.");
9339: } elsif ($checkitem eq 'id') {
1.674 bisitz 9340: $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 9341: }
1.669 raeburn 9342: } elsif ($mode eq 'selfcreate') {
9343: if ($checkitem eq 'id') {
9344: $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.");
9345: }
1.615 raeburn 9346: } else {
9347: if ($checkitem eq 'username') {
9348: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9349: } elsif ($checkitem eq 'id') {
9350: $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.");
9351: }
1.612 raeburn 9352: }
9353: return $response;
1.585 raeburn 9354: }
9355:
1.624 raeburn 9356: sub personal_data_fieldtitles {
9357: my %fieldtitles = &Apache::lonlocal::texthash (
9358: id => 'Student/Employee ID',
9359: permanentemail => 'E-mail address',
9360: lastname => 'Last Name',
9361: firstname => 'First Name',
9362: middlename => 'Middle Name',
9363: generation => 'Generation',
9364: gen => 'Generation',
1.765 raeburn 9365: inststatus => 'Affiliation',
1.624 raeburn 9366: );
9367: return %fieldtitles;
9368: }
9369:
1.642 raeburn 9370: sub sorted_inst_types {
9371: my ($dom) = @_;
9372: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9373: my $othertitle = &mt('All users');
9374: if ($env{'request.course.id'}) {
1.668 raeburn 9375: $othertitle = &mt('Any users');
1.642 raeburn 9376: }
9377: my @types;
9378: if (ref($order) eq 'ARRAY') {
9379: @types = @{$order};
9380: }
9381: if (@types == 0) {
9382: if (ref($usertypes) eq 'HASH') {
9383: @types = sort(keys(%{$usertypes}));
9384: }
9385: }
9386: if (keys(%{$usertypes}) > 0) {
9387: $othertitle = &mt('Other users');
9388: }
9389: return ($othertitle,$usertypes,\@types);
9390: }
9391:
1.645 raeburn 9392: sub get_institutional_codes {
9393: my ($settings,$allcourses,$LC_code) = @_;
9394: # Get complete list of course sections to update
9395: my @currsections = ();
9396: my @currxlists = ();
9397: my $coursecode = $$settings{'internal.coursecode'};
9398:
9399: if ($$settings{'internal.sectionnums'} ne '') {
9400: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9401: }
9402:
9403: if ($$settings{'internal.crosslistings'} ne '') {
9404: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9405: }
9406:
9407: if (@currxlists > 0) {
9408: foreach (@currxlists) {
9409: if (m/^([^:]+):(\w*)$/) {
9410: unless (grep/^$1$/,@{$allcourses}) {
9411: push @{$allcourses},$1;
9412: $$LC_code{$1} = $2;
9413: }
9414: }
9415: }
9416: }
9417:
9418: if (@currsections > 0) {
9419: foreach (@currsections) {
9420: if (m/^(\w+):(\w*)$/) {
9421: my $sec = $coursecode.$1;
9422: my $lc_sec = $2;
9423: unless (grep/^$sec$/,@{$allcourses}) {
9424: push @{$allcourses},$sec;
9425: $$LC_code{$sec} = $lc_sec;
9426: }
9427: }
9428: }
9429: }
9430: return;
9431: }
9432:
1.971 raeburn 9433: sub get_standard_codeitems {
9434: return ('Year','Semester','Department','Number','Section');
9435: }
9436:
1.112 bowersj2 9437: =pod
9438:
1.780 raeburn 9439: =head1 Slot Helpers
9440:
9441: =over 4
9442:
9443: =item * sorted_slots()
9444:
1.1040 raeburn 9445: Sorts an array of slot names in order of an optional sort key,
9446: default sort is by slot start time (earliest first).
1.780 raeburn 9447:
9448: Inputs:
9449:
9450: =over 4
9451:
9452: slotsarr - Reference to array of unsorted slot names.
9453:
9454: slots - Reference to hash of hash, where outer hash keys are slot names.
9455:
1.1040 raeburn 9456: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9457:
1.549 albertel 9458: =back
9459:
1.780 raeburn 9460: Returns:
9461:
9462: =over 4
9463:
1.1040 raeburn 9464: sorted - An array of slot names sorted by a specified sort key
9465: (default sort key is start time of the slot).
1.780 raeburn 9466:
9467: =back
9468:
9469: =cut
9470:
9471:
9472: sub sorted_slots {
1.1040 raeburn 9473: my ($slotsarr,$slots,$sortkey) = @_;
9474: if ($sortkey eq '') {
9475: $sortkey = 'starttime';
9476: }
1.780 raeburn 9477: my @sorted;
9478: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9479: @sorted =
9480: sort {
9481: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9482: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9483: }
9484: if (ref($slots->{$a})) { return -1;}
9485: if (ref($slots->{$b})) { return 1;}
9486: return 0;
9487: } @{$slotsarr};
9488: }
9489: return @sorted;
9490: }
9491:
1.1040 raeburn 9492: =pod
9493:
9494: =item * get_future_slots()
9495:
9496: Inputs:
9497:
9498: =over 4
9499:
9500: cnum - course number
9501:
9502: cdom - course domain
9503:
9504: now - current UNIX time
9505:
9506: symb - optional symb
9507:
9508: =back
9509:
9510: Returns:
9511:
9512: =over 4
9513:
9514: sorted_reservable - ref to array of student_schedulable slots currently
9515: reservable, ordered by end date of reservation period.
9516:
9517: reservable_now - ref to hash of student_schedulable slots currently
9518: reservable.
9519:
9520: Keys in inner hash are:
9521: (a) symb: either blank or symb to which slot use is restricted.
9522: (b) endreserve: end date of reservation period.
9523:
9524: sorted_future - ref to array of student_schedulable slots reservable in
9525: the future, ordered by start date of reservation period.
9526:
9527: future_reservable - ref to hash of student_schedulable slots reservable
9528: in the future.
9529:
9530: Keys in inner hash are:
9531: (a) symb: either blank or symb to which slot use is restricted.
9532: (b) startreserve: start date of reservation period.
9533:
9534: =back
9535:
9536: =cut
9537:
9538: sub get_future_slots {
9539: my ($cnum,$cdom,$now,$symb) = @_;
9540: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9541: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9542: foreach my $slot (keys(%slots)) {
9543: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9544: if ($symb) {
9545: next if (($slots{$slot}->{'symb'} ne '') &&
9546: ($slots{$slot}->{'symb'} ne $symb));
9547: }
9548: if (($slots{$slot}->{'starttime'} > $now) &&
9549: ($slots{$slot}->{'endtime'} > $now)) {
9550: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9551: my $userallowed = 0;
9552: if ($slots{$slot}->{'allowedsections'}) {
9553: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9554: if (!defined($env{'request.role.sec'})
9555: && grep(/^No section assigned$/,@allowed_sec)) {
9556: $userallowed=1;
9557: } else {
9558: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9559: $userallowed=1;
9560: }
9561: }
9562: unless ($userallowed) {
9563: if (defined($env{'request.course.groups'})) {
9564: my @groups = split(/:/,$env{'request.course.groups'});
9565: foreach my $group (@groups) {
9566: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9567: $userallowed=1;
9568: last;
9569: }
9570: }
9571: }
9572: }
9573: }
9574: if ($slots{$slot}->{'allowedusers'}) {
9575: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9576: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9577: if (grep(/^\Q$user\E$/,@allowed_users)) {
9578: $userallowed = 1;
9579: }
9580: }
9581: next unless($userallowed);
9582: }
9583: my $startreserve = $slots{$slot}->{'startreserve'};
9584: my $endreserve = $slots{$slot}->{'endreserve'};
9585: my $symb = $slots{$slot}->{'symb'};
9586: if (($startreserve < $now) &&
9587: (!$endreserve || $endreserve > $now)) {
9588: my $lastres = $endreserve;
9589: if (!$lastres) {
9590: $lastres = $slots{$slot}->{'starttime'};
9591: }
9592: $reservable_now{$slot} = {
9593: symb => $symb,
9594: endreserve => $lastres
9595: };
9596: } elsif (($startreserve > $now) &&
9597: (!$endreserve || $endreserve > $startreserve)) {
9598: $future_reservable{$slot} = {
9599: symb => $symb,
9600: startreserve => $startreserve
9601: };
9602: }
9603: }
9604: }
9605: my @unsorted_reservable = keys(%reservable_now);
9606: if (@unsorted_reservable > 0) {
9607: @sorted_reservable =
9608: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9609: }
9610: my @unsorted_future = keys(%future_reservable);
9611: if (@unsorted_future > 0) {
9612: @sorted_future =
9613: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9614: }
9615: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9616: }
1.780 raeburn 9617:
9618: =pod
9619:
1.1057 foxr 9620: =back
9621:
1.549 albertel 9622: =head1 HTTP Helpers
9623:
9624: =over 4
9625:
1.648 raeburn 9626: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9627:
1.258 albertel 9628: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9629: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9630: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9631:
9632: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9633: $possible_names is an ref to an array of form element names. As an example:
9634: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9635: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9636:
9637: =cut
1.1 albertel 9638:
1.6 albertel 9639: sub get_unprocessed_cgi {
1.25 albertel 9640: my ($query,$possible_names)= @_;
1.26 matthew 9641: # $Apache::lonxml::debug=1;
1.356 albertel 9642: foreach my $pair (split(/&/,$query)) {
9643: my ($name, $value) = split(/=/,$pair);
1.369 www 9644: $name = &unescape($name);
1.25 albertel 9645: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9646: $value =~ tr/+/ /;
9647: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9648: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9649: }
1.16 harris41 9650: }
1.6 albertel 9651: }
9652:
1.112 bowersj2 9653: =pod
9654:
1.648 raeburn 9655: =item * &cacheheader()
1.112 bowersj2 9656:
9657: returns cache-controlling header code
9658:
9659: =cut
9660:
1.7 albertel 9661: sub cacheheader {
1.258 albertel 9662: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9663: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9664: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9665: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9666: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9667: return $output;
1.7 albertel 9668: }
9669:
1.112 bowersj2 9670: =pod
9671:
1.648 raeburn 9672: =item * &no_cache($r)
1.112 bowersj2 9673:
9674: specifies header code to not have cache
9675:
9676: =cut
9677:
1.9 albertel 9678: sub no_cache {
1.216 albertel 9679: my ($r) = @_;
9680: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9681: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9682: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9683: $r->no_cache(1);
9684: $r->header_out("Expires" => $date);
9685: $r->header_out("Pragma" => "no-cache");
1.123 www 9686: }
9687:
9688: sub content_type {
1.181 albertel 9689: my ($r,$type,$charset) = @_;
1.299 foxr 9690: if ($r) {
9691: # Note that printout.pl calls this with undef for $r.
9692: &no_cache($r);
9693: }
1.258 albertel 9694: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9695: unless ($charset) {
9696: $charset=&Apache::lonlocal::current_encoding;
9697: }
9698: if ($charset) { $type.='; charset='.$charset; }
9699: if ($r) {
9700: $r->content_type($type);
9701: } else {
9702: print("Content-type: $type\n\n");
9703: }
1.9 albertel 9704: }
1.25 albertel 9705:
1.112 bowersj2 9706: =pod
9707:
1.648 raeburn 9708: =item * &add_to_env($name,$value)
1.112 bowersj2 9709:
1.258 albertel 9710: adds $name to the %env hash with value
1.112 bowersj2 9711: $value, if $name already exists, the entry is converted to an array
9712: reference and $value is added to the array.
9713:
9714: =cut
9715:
1.25 albertel 9716: sub add_to_env {
9717: my ($name,$value)=@_;
1.258 albertel 9718: if (defined($env{$name})) {
9719: if (ref($env{$name})) {
1.25 albertel 9720: #already have multiple values
1.258 albertel 9721: push(@{ $env{$name} },$value);
1.25 albertel 9722: } else {
9723: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9724: my $first=$env{$name};
9725: undef($env{$name});
9726: push(@{ $env{$name} },$first,$value);
1.25 albertel 9727: }
9728: } else {
1.258 albertel 9729: $env{$name}=$value;
1.25 albertel 9730: }
1.31 albertel 9731: }
1.149 albertel 9732:
9733: =pod
9734:
1.648 raeburn 9735: =item * &get_env_multiple($name)
1.149 albertel 9736:
1.258 albertel 9737: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9738: values may be defined and end up as an array ref.
9739:
9740: returns an array of values
9741:
9742: =cut
9743:
9744: sub get_env_multiple {
9745: my ($name) = @_;
9746: my @values;
1.258 albertel 9747: if (defined($env{$name})) {
1.149 albertel 9748: # exists is it an array
1.258 albertel 9749: if (ref($env{$name})) {
9750: @values=@{ $env{$name} };
1.149 albertel 9751: } else {
1.258 albertel 9752: $values[0]=$env{$name};
1.149 albertel 9753: }
9754: }
9755: return(@values);
9756: }
9757:
1.660 raeburn 9758: sub ask_for_embedded_content {
9759: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9760: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 9761: %currsubfile,%unused,$rem);
1.1071 raeburn 9762: my $counter = 0;
9763: my $numnew = 0;
1.987 raeburn 9764: my $numremref = 0;
9765: my $numinvalid = 0;
9766: my $numpathchg = 0;
9767: my $numexisting = 0;
1.1071 raeburn 9768: my $numunused = 0;
9769: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
9770: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
9771: my $heading = &mt('Upload embedded files');
9772: my $buttontext = &mt('Upload');
9773:
1.1075.2.35 raeburn 9774: my ($navmap,$cdom,$cnum);
1.1075.2.11 raeburn 9775: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 9776: if ($actionurl eq '/adm/dependencies') {
9777: $navmap = Apache::lonnavmaps::navmap->new();
9778: }
9779: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9780: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 9781: }
1.1075.2.35 raeburn 9782: if (($actionurl eq '/adm/portfolio') ||
9783: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9784: my $current_path='/';
9785: if ($env{'form.currentpath'}) {
9786: $current_path = $env{'form.currentpath'};
9787: }
9788: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 9789: $udom = $cdom;
9790: $uname = $cnum;
1.984 raeburn 9791: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9792: } else {
9793: $udom = $env{'user.domain'};
9794: $uname = $env{'user.name'};
9795: $url = '/userfiles/portfolio';
9796: }
1.987 raeburn 9797: $toplevel = $url.'/';
1.984 raeburn 9798: $url .= $current_path;
9799: $getpropath = 1;
1.987 raeburn 9800: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9801: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9802: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9803: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9804: $toplevel = $url;
1.984 raeburn 9805: if ($rest ne '') {
1.987 raeburn 9806: $url .= $rest;
9807: }
9808: } elsif ($actionurl eq '/adm/coursedocs') {
9809: if (ref($args) eq 'HASH') {
1.1071 raeburn 9810: $url = $args->{'docs_url'};
9811: $toplevel = $url;
1.1075.2.11 raeburn 9812: if ($args->{'context'} eq 'paste') {
9813: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9814: ($path) =
9815: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9816: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9817: $fileloc =~ s{^/}{};
9818: }
1.1071 raeburn 9819: }
9820: } elsif ($actionurl eq '/adm/dependencies') {
9821: if ($env{'request.course.id'} ne '') {
9822: if (ref($args) eq 'HASH') {
9823: $url = $args->{'docs_url'};
9824: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 9825: $toplevel = $url;
9826: unless ($toplevel =~ m{^/}) {
9827: $toplevel = "/$url";
9828: }
1.1075.2.11 raeburn 9829: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 9830: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9831: $path = $1;
9832: } else {
9833: ($path) =
9834: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9835: }
1.1071 raeburn 9836: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9837: $fileloc =~ s{^/}{};
9838: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9839: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9840: }
1.987 raeburn 9841: }
1.1075.2.35 raeburn 9842: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9843: $udom = $cdom;
9844: $uname = $cnum;
9845: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9846: $toplevel = $url;
9847: $path = $url;
9848: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9849: $fileloc =~ s{^/}{};
9850: }
9851: foreach my $file (keys(%{$allfiles})) {
9852: my $embed_file;
9853: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9854: $embed_file = $1;
9855: } else {
9856: $embed_file = $file;
9857: }
1.987 raeburn 9858: my $absolutepath;
1.1075.2.47 raeburn 9859: my $cleaned_file = &clean_path($embed_file);
9860: if ($cleaned_file =~ m{^\w+://}) {
9861: $newfiles{$cleaned_file} = 1;
9862: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9863: } else {
9864: if ($embed_file =~ m{^/}) {
9865: $absolutepath = $embed_file;
9866: }
1.1075.2.47 raeburn 9867: if ($cleaned_file =~ m{/}) {
9868: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 9869: $path = &check_for_traversal($path,$url,$toplevel);
9870: my $item = $fname;
9871: if ($path ne '') {
9872: $item = $path.'/'.$fname;
9873: $subdependencies{$path}{$fname} = 1;
9874: } else {
9875: $dependencies{$item} = 1;
9876: }
9877: if ($absolutepath) {
9878: $mapping{$item} = $absolutepath;
9879: } else {
9880: $mapping{$item} = $embed_file;
9881: }
9882: } else {
9883: $dependencies{$embed_file} = 1;
9884: if ($absolutepath) {
1.1075.2.47 raeburn 9885: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 9886: } else {
1.1075.2.47 raeburn 9887: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9888: }
9889: }
1.984 raeburn 9890: }
9891: }
1.1071 raeburn 9892: my $dirptr = 16384;
1.984 raeburn 9893: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9894: $currsubfile{$path} = {};
1.1075.2.35 raeburn 9895: if (($actionurl eq '/adm/portfolio') ||
9896: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9897: my ($sublistref,$listerror) =
9898: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9899: if (ref($sublistref) eq 'ARRAY') {
9900: foreach my $line (@{$sublistref}) {
9901: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9902: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9903: }
1.984 raeburn 9904: }
1.987 raeburn 9905: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9906: if (opendir(my $dir,$url.'/'.$path)) {
9907: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9908: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9909: }
1.1075.2.11 raeburn 9910: } elsif (($actionurl eq '/adm/dependencies') ||
9911: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 9912: ($args->{'context'} eq 'paste')) ||
9913: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9914: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 9915: my $dir;
9916: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9917: $dir = $fileloc;
9918: } else {
9919: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9920: }
1.1071 raeburn 9921: if ($dir ne '') {
9922: my ($sublistref,$listerror) =
9923: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9924: if (ref($sublistref) eq 'ARRAY') {
9925: foreach my $line (@{$sublistref}) {
9926: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9927: undef,$mtime)=split(/\&/,$line,12);
9928: unless (($testdir&$dirptr) ||
9929: ($file_name =~ /^\.\.?$/)) {
9930: $currsubfile{$path}{$file_name} = [$size,$mtime];
9931: }
9932: }
9933: }
9934: }
1.984 raeburn 9935: }
9936: }
9937: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9938: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9939: my $item = $path.'/'.$file;
9940: unless ($mapping{$item} eq $item) {
9941: $pathchanges{$item} = 1;
9942: }
9943: $existing{$item} = 1;
9944: $numexisting ++;
9945: } else {
9946: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9947: }
9948: }
1.1071 raeburn 9949: if ($actionurl eq '/adm/dependencies') {
9950: foreach my $path (keys(%currsubfile)) {
9951: if (ref($currsubfile{$path}) eq 'HASH') {
9952: foreach my $file (keys(%{$currsubfile{$path}})) {
9953: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 9954: next if (($rem ne '') &&
9955: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9956: (ref($navmap) &&
9957: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9958: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9959: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9960: $unused{$path.'/'.$file} = 1;
9961: }
9962: }
9963: }
9964: }
9965: }
1.984 raeburn 9966: }
1.987 raeburn 9967: my %currfile;
1.1075.2.35 raeburn 9968: if (($actionurl eq '/adm/portfolio') ||
9969: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9970: my ($dirlistref,$listerror) =
9971: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9972: if (ref($dirlistref) eq 'ARRAY') {
9973: foreach my $line (@{$dirlistref}) {
9974: my ($file_name,$rest) = split(/\&/,$line,2);
9975: $currfile{$file_name} = 1;
9976: }
1.984 raeburn 9977: }
1.987 raeburn 9978: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9979: if (opendir(my $dir,$url)) {
1.987 raeburn 9980: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 9981: map {$currfile{$_} = 1;} @dir_list;
9982: }
1.1075.2.11 raeburn 9983: } elsif (($actionurl eq '/adm/dependencies') ||
9984: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 9985: ($args->{'context'} eq 'paste')) ||
9986: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9987: if ($env{'request.course.id'} ne '') {
9988: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9989: if ($dir ne '') {
9990: my ($dirlistref,$listerror) =
9991: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
9992: if (ref($dirlistref) eq 'ARRAY') {
9993: foreach my $line (@{$dirlistref}) {
9994: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
9995: $size,undef,$mtime)=split(/\&/,$line,12);
9996: unless (($testdir&$dirptr) ||
9997: ($file_name =~ /^\.\.?$/)) {
9998: $currfile{$file_name} = [$size,$mtime];
9999: }
10000: }
10001: }
10002: }
10003: }
1.984 raeburn 10004: }
10005: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10006: if (exists($currfile{$file})) {
1.987 raeburn 10007: unless ($mapping{$file} eq $file) {
10008: $pathchanges{$file} = 1;
10009: }
10010: $existing{$file} = 1;
10011: $numexisting ++;
10012: } else {
1.984 raeburn 10013: $newfiles{$file} = 1;
10014: }
10015: }
1.1071 raeburn 10016: foreach my $file (keys(%currfile)) {
10017: unless (($file eq $filename) ||
10018: ($file eq $filename.'.bak') ||
10019: ($dependencies{$file})) {
1.1075.2.11 raeburn 10020: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10021: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10022: next if (($rem ne '') &&
10023: (($env{"httpref.$rem".$file} ne '') ||
10024: (ref($navmap) &&
10025: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10026: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10027: ($navmap->getResourceByUrl($rem.$1)))))));
10028: }
1.1075.2.11 raeburn 10029: }
1.1071 raeburn 10030: $unused{$file} = 1;
10031: }
10032: }
1.1075.2.11 raeburn 10033: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10034: ($args->{'context'} eq 'paste')) {
10035: $counter = scalar(keys(%existing));
10036: $numpathchg = scalar(keys(%pathchanges));
10037: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10038: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10039: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10040: $counter = scalar(keys(%existing));
10041: $numpathchg = scalar(keys(%pathchanges));
10042: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10043: }
1.984 raeburn 10044: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10045: if ($actionurl eq '/adm/dependencies') {
10046: next if ($embed_file =~ m{^\w+://});
10047: }
1.660 raeburn 10048: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10049: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10050: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10051: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10052: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10053: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10054: }
1.1075.2.35 raeburn 10055: $upload_output .= '</td>';
1.1071 raeburn 10056: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10057: $upload_output.='<td align="right">'.
10058: '<span class="LC_info LC_fontsize_medium">'.
10059: &mt("URL points to web address").'</span>';
1.987 raeburn 10060: $numremref++;
1.660 raeburn 10061: } elsif ($args->{'error_on_invalid_names'}
10062: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10063: $upload_output.='<td align="right"><span class="LC_warning">'.
10064: &mt('Invalid characters').'</span>';
1.987 raeburn 10065: $numinvalid++;
1.660 raeburn 10066: } else {
1.1075.2.35 raeburn 10067: $upload_output .= '<td>'.
10068: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10069: $embed_file,\%mapping,
1.1071 raeburn 10070: $allfiles,$codebase,'upload');
10071: $counter ++;
10072: $numnew ++;
1.987 raeburn 10073: }
10074: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10075: }
10076: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10077: if ($actionurl eq '/adm/dependencies') {
10078: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10079: $modify_output .= &start_data_table_row().
10080: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10081: '<img src="'.&icon($embed_file).'" border="0" />'.
10082: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10083: '<td>'.$size.'</td>'.
10084: '<td>'.$mtime.'</td>'.
10085: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10086: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10087: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10088: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10089: &embedded_file_element('upload_embedded',$counter,
10090: $embed_file,\%mapping,
10091: $allfiles,$codebase,'modify').
10092: '</div></td>'.
10093: &end_data_table_row()."\n";
10094: $counter ++;
10095: } else {
10096: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10097: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10098: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10099: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10100: &Apache::loncommon::end_data_table_row()."\n";
10101: }
10102: }
10103: my $delidx = $counter;
10104: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10105: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10106: $delete_output .= &start_data_table_row().
10107: '<td><img src="'.&icon($oldfile).'" />'.
10108: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10109: '<td>'.$size.'</td>'.
10110: '<td>'.$mtime.'</td>'.
10111: '<td><label><input type="checkbox" name="del_upload_dep" '.
10112: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10113: &embedded_file_element('upload_embedded',$delidx,
10114: $oldfile,\%mapping,$allfiles,
10115: $codebase,'delete').'</td>'.
10116: &end_data_table_row()."\n";
10117: $numunused ++;
10118: $delidx ++;
1.987 raeburn 10119: }
10120: if ($upload_output) {
10121: $upload_output = &start_data_table().
10122: $upload_output.
10123: &end_data_table()."\n";
10124: }
1.1071 raeburn 10125: if ($modify_output) {
10126: $modify_output = &start_data_table().
10127: &start_data_table_header_row().
10128: '<th>'.&mt('File').'</th>'.
10129: '<th>'.&mt('Size (KB)').'</th>'.
10130: '<th>'.&mt('Modified').'</th>'.
10131: '<th>'.&mt('Upload replacement?').'</th>'.
10132: &end_data_table_header_row().
10133: $modify_output.
10134: &end_data_table()."\n";
10135: }
10136: if ($delete_output) {
10137: $delete_output = &start_data_table().
10138: &start_data_table_header_row().
10139: '<th>'.&mt('File').'</th>'.
10140: '<th>'.&mt('Size (KB)').'</th>'.
10141: '<th>'.&mt('Modified').'</th>'.
10142: '<th>'.&mt('Delete?').'</th>'.
10143: &end_data_table_header_row().
10144: $delete_output.
10145: &end_data_table()."\n";
10146: }
1.987 raeburn 10147: my $applies = 0;
10148: if ($numremref) {
10149: $applies ++;
10150: }
10151: if ($numinvalid) {
10152: $applies ++;
10153: }
10154: if ($numexisting) {
10155: $applies ++;
10156: }
1.1071 raeburn 10157: if ($counter || $numunused) {
1.987 raeburn 10158: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10159: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10160: $state.'<h3>'.$heading.'</h3>';
10161: if ($actionurl eq '/adm/dependencies') {
10162: if ($numnew) {
10163: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10164: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10165: $upload_output.'<br />'."\n";
10166: }
10167: if ($numexisting) {
10168: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10169: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10170: $modify_output.'<br />'."\n";
10171: $buttontext = &mt('Save changes');
10172: }
10173: if ($numunused) {
10174: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10175: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10176: $delete_output.'<br />'."\n";
10177: $buttontext = &mt('Save changes');
10178: }
10179: } else {
10180: $output .= $upload_output.'<br />'."\n";
10181: }
10182: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10183: $counter.'" />'."\n";
10184: if ($actionurl eq '/adm/dependencies') {
10185: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10186: $numnew.'" />'."\n";
10187: } elsif ($actionurl eq '') {
1.987 raeburn 10188: $output .= '<input type="hidden" name="phase" value="three" />';
10189: }
10190: } elsif ($applies) {
10191: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10192: if ($applies > 1) {
10193: $output .=
1.1075.2.35 raeburn 10194: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10195: if ($numremref) {
10196: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10197: }
10198: if ($numinvalid) {
10199: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10200: }
10201: if ($numexisting) {
10202: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10203: }
10204: $output .= '</ul><br />';
10205: } elsif ($numremref) {
10206: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10207: } elsif ($numinvalid) {
10208: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10209: } elsif ($numexisting) {
10210: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10211: }
10212: $output .= $upload_output.'<br />';
10213: }
10214: my ($pathchange_output,$chgcount);
1.1071 raeburn 10215: $chgcount = $counter;
1.987 raeburn 10216: if (keys(%pathchanges) > 0) {
10217: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10218: if ($counter) {
1.987 raeburn 10219: $output .= &embedded_file_element('pathchange',$chgcount,
10220: $embed_file,\%mapping,
1.1071 raeburn 10221: $allfiles,$codebase,'change');
1.987 raeburn 10222: } else {
10223: $pathchange_output .=
10224: &start_data_table_row().
10225: '<td><input type ="checkbox" name="namechange" value="'.
10226: $chgcount.'" checked="checked" /></td>'.
10227: '<td>'.$mapping{$embed_file}.'</td>'.
10228: '<td>'.$embed_file.
10229: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10230: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10231: '</td>'.&end_data_table_row();
1.660 raeburn 10232: }
1.987 raeburn 10233: $numpathchg ++;
10234: $chgcount ++;
1.660 raeburn 10235: }
10236: }
1.1075.2.35 raeburn 10237: if (($counter) || ($numunused)) {
1.987 raeburn 10238: if ($numpathchg) {
10239: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10240: $numpathchg.'" />'."\n";
10241: }
10242: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10243: ($actionurl eq '/adm/imsimport')) {
10244: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10245: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10246: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10247: } elsif ($actionurl eq '/adm/dependencies') {
10248: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10249: }
1.1075.2.35 raeburn 10250: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10251: } elsif ($numpathchg) {
10252: my %pathchange = ();
10253: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10254: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10255: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10256: }
1.987 raeburn 10257: }
1.1071 raeburn 10258: return ($output,$counter,$numpathchg);
1.987 raeburn 10259: }
10260:
1.1075.2.47 raeburn 10261:
10262: =pod
10263:
10264: =item * clean_path($name)
10265:
10266: Performs clean-up of directories, subdirectories and filename in an
10267: embedded object, referenced in an HTML file which is being uploaded
10268: to a course or portfolio, where
10269: "Upload embedded images/multimedia files if HTML file" checkbox was
10270: checked.
10271:
10272: Clean-up is similar to replacements in lonnet::clean_filename()
10273: except each / between sub-directory and next level is preserved.
10274:
10275: =cut
10276:
10277: sub clean_path {
10278: my ($embed_file) = @_;
10279: $embed_file =~s{^/+}{};
10280: my @contents;
10281: if ($embed_file =~ m{/}) {
10282: @contents = split(/\//,$embed_file);
10283: } else {
10284: @contents = ($embed_file);
10285: }
10286: my $lastidx = scalar(@contents)-1;
10287: for (my $i=0; $i<=$lastidx; $i++) {
10288: $contents[$i]=~s{\\}{/}g;
10289: $contents[$i]=~s/\s+/\_/g;
10290: $contents[$i]=~s{[^/\w\.\-]}{}g;
10291: if ($i == $lastidx) {
10292: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10293: }
10294: }
10295: if ($lastidx > 0) {
10296: return join('/',@contents);
10297: } else {
10298: return $contents[0];
10299: }
10300: }
10301:
1.987 raeburn 10302: sub embedded_file_element {
1.1071 raeburn 10303: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10304: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10305: (ref($codebase) eq 'HASH'));
10306: my $output;
1.1071 raeburn 10307: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10308: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10309: }
10310: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10311: &escape($embed_file).'" />';
10312: unless (($context eq 'upload_embedded') &&
10313: ($mapping->{$embed_file} eq $embed_file)) {
10314: $output .='
10315: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10316: }
10317: my $attrib;
10318: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10319: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10320: }
10321: $output .=
10322: "\n\t\t".
10323: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10324: $attrib.'" />';
10325: if (exists($codebase->{$mapping->{$embed_file}})) {
10326: $output .=
10327: "\n\t\t".
10328: '<input name="codebase_'.$num.'" type="hidden" value="'.
10329: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10330: }
1.987 raeburn 10331: return $output;
1.660 raeburn 10332: }
10333:
1.1071 raeburn 10334: sub get_dependency_details {
10335: my ($currfile,$currsubfile,$embed_file) = @_;
10336: my ($size,$mtime,$showsize,$showmtime);
10337: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10338: if ($embed_file =~ m{/}) {
10339: my ($path,$fname) = split(/\//,$embed_file);
10340: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10341: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10342: }
10343: } else {
10344: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10345: ($size,$mtime) = @{$currfile->{$embed_file}};
10346: }
10347: }
10348: $showsize = $size/1024.0;
10349: $showsize = sprintf("%.1f",$showsize);
10350: if ($mtime > 0) {
10351: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10352: }
10353: }
10354: return ($showsize,$showmtime);
10355: }
10356:
10357: sub ask_embedded_js {
10358: return <<"END";
10359: <script type="text/javascript"">
10360: // <![CDATA[
10361: function toggleBrowse(counter) {
10362: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10363: var fileid = document.getElementById('embedded_item_'+counter);
10364: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10365: if (chkboxid.checked == true) {
10366: uploaddivid.style.display='block';
10367: } else {
10368: uploaddivid.style.display='none';
10369: fileid.value = '';
10370: }
10371: }
10372: // ]]>
10373: </script>
10374:
10375: END
10376: }
10377:
1.661 raeburn 10378: sub upload_embedded {
10379: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10380: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10381: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10382: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10383: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10384: my $orig_uploaded_filename =
10385: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10386: foreach my $type ('orig','ref','attrib','codebase') {
10387: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10388: $env{'form.embedded_'.$type.'_'.$i} =
10389: &unescape($env{'form.embedded_'.$type.'_'.$i});
10390: }
10391: }
1.661 raeburn 10392: my ($path,$fname) =
10393: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10394: # no path, whole string is fname
10395: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10396: $fname = &Apache::lonnet::clean_filename($fname);
10397: # See if there is anything left
10398: next if ($fname eq '');
10399:
10400: # Check if file already exists as a file or directory.
10401: my ($state,$msg);
10402: if ($context eq 'portfolio') {
10403: my $port_path = $dirpath;
10404: if ($group ne '') {
10405: $port_path = "groups/$group/$port_path";
10406: }
1.987 raeburn 10407: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10408: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10409: $dir_root,$port_path,$disk_quota,
10410: $current_disk_usage,$uname,$udom);
10411: if ($state eq 'will_exceed_quota'
1.984 raeburn 10412: || $state eq 'file_locked') {
1.661 raeburn 10413: $output .= $msg;
10414: next;
10415: }
10416: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10417: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10418: if ($state eq 'exists') {
10419: $output .= $msg;
10420: next;
10421: }
10422: }
10423: # Check if extension is valid
10424: if (($fname =~ /\.(\w+)$/) &&
10425: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987 raeburn 10426: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1).'<br />';
1.661 raeburn 10427: next;
10428: } elsif (($fname =~ /\.(\w+)$/) &&
10429: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10430: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10431: next;
10432: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 10433: $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 10434: next;
10435: }
10436: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 10437: my $subdir = $path;
10438: $subdir =~ s{/+$}{};
1.661 raeburn 10439: if ($context eq 'portfolio') {
1.984 raeburn 10440: my $result;
10441: if ($state eq 'existingfile') {
10442: $result=
10443: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 10444: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10445: } else {
1.984 raeburn 10446: $result=
10447: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10448: $dirpath.
1.1075.2.35 raeburn 10449: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10450: if ($result !~ m|^/uploaded/|) {
10451: $output .= '<span class="LC_error">'
10452: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10453: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10454: .'</span><br />';
10455: next;
10456: } else {
1.987 raeburn 10457: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10458: $path.$fname.'</span>').'<br />';
1.984 raeburn 10459: }
1.661 raeburn 10460: }
1.1075.2.35 raeburn 10461: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
10462: my $extendedsubdir = $dirpath.'/'.$subdir;
10463: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10464: my $result =
1.1075.2.35 raeburn 10465: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10466: if ($result !~ m|^/uploaded/|) {
10467: $output .= '<span class="LC_error">'
10468: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10469: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10470: .'</span><br />';
10471: next;
10472: } else {
10473: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10474: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 10475: if ($context eq 'syllabus') {
10476: &Apache::lonnet::make_public_indefinitely($result);
10477: }
1.987 raeburn 10478: }
1.661 raeburn 10479: } else {
10480: # Save the file
10481: my $target = $env{'form.embedded_item_'.$i};
10482: my $fullpath = $dir_root.$dirpath.'/'.$path;
10483: my $dest = $fullpath.$fname;
10484: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10485: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10486: my $count;
10487: my $filepath = $dir_root;
1.1027 raeburn 10488: foreach my $subdir (@parts) {
10489: $filepath .= "/$subdir";
10490: if (!-e $filepath) {
1.661 raeburn 10491: mkdir($filepath,0770);
10492: }
10493: }
10494: my $fh;
10495: if (!open($fh,'>'.$dest)) {
10496: &Apache::lonnet::logthis('Failed to create '.$dest);
10497: $output .= '<span class="LC_error">'.
1.1071 raeburn 10498: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10499: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10500: '</span><br />';
10501: } else {
10502: if (!print $fh $env{'form.embedded_item_'.$i}) {
10503: &Apache::lonnet::logthis('Failed to write to '.$dest);
10504: $output .= '<span class="LC_error">'.
1.1071 raeburn 10505: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10506: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10507: '</span><br />';
10508: } else {
1.987 raeburn 10509: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10510: $url.'</span>').'<br />';
10511: unless ($context eq 'testbank') {
10512: $footer .= &mt('View embedded file: [_1]',
10513: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10514: }
10515: }
10516: close($fh);
10517: }
10518: }
10519: if ($env{'form.embedded_ref_'.$i}) {
10520: $pathchange{$i} = 1;
10521: }
10522: }
10523: if ($output) {
10524: $output = '<p>'.$output.'</p>';
10525: }
10526: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10527: $returnflag = 'ok';
1.1071 raeburn 10528: my $numpathchgs = scalar(keys(%pathchange));
10529: if ($numpathchgs > 0) {
1.987 raeburn 10530: if ($context eq 'portfolio') {
10531: $output .= '<p>'.&mt('or').'</p>';
10532: } elsif ($context eq 'testbank') {
1.1071 raeburn 10533: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10534: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10535: $returnflag = 'modify_orightml';
10536: }
10537: }
1.1071 raeburn 10538: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10539: }
10540:
10541: sub modify_html_form {
10542: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10543: my $end = 0;
10544: my $modifyform;
10545: if ($context eq 'upload_embedded') {
10546: return unless (ref($pathchange) eq 'HASH');
10547: if ($env{'form.number_embedded_items'}) {
10548: $end += $env{'form.number_embedded_items'};
10549: }
10550: if ($env{'form.number_pathchange_items'}) {
10551: $end += $env{'form.number_pathchange_items'};
10552: }
10553: if ($end) {
10554: for (my $i=0; $i<$end; $i++) {
10555: if ($i < $env{'form.number_embedded_items'}) {
10556: next unless($pathchange->{$i});
10557: }
10558: $modifyform .=
10559: &start_data_table_row().
10560: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10561: 'checked="checked" /></td>'.
10562: '<td>'.$env{'form.embedded_ref_'.$i}.
10563: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10564: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10565: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10566: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10567: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10568: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10569: '<td>'.$env{'form.embedded_orig_'.$i}.
10570: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10571: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10572: &end_data_table_row();
1.1071 raeburn 10573: }
1.987 raeburn 10574: }
10575: } else {
10576: $modifyform = $pathchgtable;
10577: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10578: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10579: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10580: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10581: }
10582: }
10583: if ($modifyform) {
1.1071 raeburn 10584: if ($actionurl eq '/adm/dependencies') {
10585: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10586: }
1.987 raeburn 10587: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10588: '<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".
10589: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10590: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10591: '</ol></p>'."\n".'<p>'.
10592: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10593: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10594: &start_data_table()."\n".
10595: &start_data_table_header_row().
10596: '<th>'.&mt('Change?').'</th>'.
10597: '<th>'.&mt('Current reference').'</th>'.
10598: '<th>'.&mt('Required reference').'</th>'.
10599: &end_data_table_header_row()."\n".
10600: $modifyform.
10601: &end_data_table().'<br />'."\n".$hiddenstate.
10602: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10603: '</form>'."\n";
10604: }
10605: return;
10606: }
10607:
10608: sub modify_html_refs {
1.1075.2.35 raeburn 10609: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10610: my $container;
10611: if ($context eq 'portfolio') {
10612: $container = $env{'form.container'};
10613: } elsif ($context eq 'coursedoc') {
10614: $container = $env{'form.primaryurl'};
1.1071 raeburn 10615: } elsif ($context eq 'manage_dependencies') {
10616: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10617: $container = "/$container";
1.1075.2.35 raeburn 10618: } elsif ($context eq 'syllabus') {
10619: $container = $url;
1.987 raeburn 10620: } else {
1.1027 raeburn 10621: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10622: }
10623: my (%allfiles,%codebase,$output,$content);
10624: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 10625: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10626: if (wantarray) {
10627: return ('',0,0);
10628: } else {
10629: return;
10630: }
10631: }
10632: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10633: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10634: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10635: if (wantarray) {
10636: return ('',0,0);
10637: } else {
10638: return;
10639: }
10640: }
1.987 raeburn 10641: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10642: if ($content eq '-1') {
10643: if (wantarray) {
10644: return ('',0,0);
10645: } else {
10646: return;
10647: }
10648: }
1.987 raeburn 10649: } else {
1.1071 raeburn 10650: unless ($container =~ /^\Q$dir_root\E/) {
10651: if (wantarray) {
10652: return ('',0,0);
10653: } else {
10654: return;
10655: }
10656: }
1.987 raeburn 10657: if (open(my $fh,"<$container")) {
10658: $content = join('', <$fh>);
10659: close($fh);
10660: } else {
1.1071 raeburn 10661: if (wantarray) {
10662: return ('',0,0);
10663: } else {
10664: return;
10665: }
1.987 raeburn 10666: }
10667: }
10668: my ($count,$codebasecount) = (0,0);
10669: my $mm = new File::MMagic;
10670: my $mime_type = $mm->checktype_contents($content);
10671: if ($mime_type eq 'text/html') {
10672: my $parse_result =
10673: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10674: \%codebase,\$content);
10675: if ($parse_result eq 'ok') {
10676: foreach my $i (@changes) {
10677: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10678: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10679: if ($allfiles{$ref}) {
10680: my $newname = $orig;
10681: my ($attrib_regexp,$codebase);
1.1006 raeburn 10682: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10683: if ($attrib_regexp =~ /:/) {
10684: $attrib_regexp =~ s/\:/|/g;
10685: }
10686: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10687: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10688: $count += $numchg;
1.1075.2.35 raeburn 10689: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 10690: delete($allfiles{$ref});
1.987 raeburn 10691: }
10692: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10693: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10694: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10695: $codebasecount ++;
10696: }
10697: }
10698: }
1.1075.2.35 raeburn 10699: my $skiprewrites;
1.987 raeburn 10700: if ($count || $codebasecount) {
10701: my $saveresult;
1.1071 raeburn 10702: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10703: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10704: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10705: if ($url eq $container) {
10706: my ($fname) = ($container =~ m{/([^/]+)$});
10707: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10708: $count,'<span class="LC_filename">'.
1.1071 raeburn 10709: $fname.'</span>').'</p>';
1.987 raeburn 10710: } else {
10711: $output = '<p class="LC_error">'.
10712: &mt('Error: update failed for: [_1].',
10713: '<span class="LC_filename">'.
10714: $container.'</span>').'</p>';
10715: }
1.1075.2.35 raeburn 10716: if ($context eq 'syllabus') {
10717: unless ($saveresult eq 'ok') {
10718: $skiprewrites = 1;
10719: }
10720: }
1.987 raeburn 10721: } else {
10722: if (open(my $fh,">$container")) {
10723: print $fh $content;
10724: close($fh);
10725: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10726: $count,'<span class="LC_filename">'.
10727: $container.'</span>').'</p>';
1.661 raeburn 10728: } else {
1.987 raeburn 10729: $output = '<p class="LC_error">'.
10730: &mt('Error: could not update [_1].',
10731: '<span class="LC_filename">'.
10732: $container.'</span>').'</p>';
1.661 raeburn 10733: }
10734: }
10735: }
1.1075.2.35 raeburn 10736: if (($context eq 'syllabus') && (!$skiprewrites)) {
10737: my ($actionurl,$state);
10738: $actionurl = "/public/$udom/$uname/syllabus";
10739: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10740: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10741: \%codebase,
10742: {'context' => 'rewrites',
10743: 'ignore_remote_references' => 1,});
10744: if (ref($mapping) eq 'HASH') {
10745: my $rewrites = 0;
10746: foreach my $key (keys(%{$mapping})) {
10747: next if ($key =~ m{^https?://});
10748: my $ref = $mapping->{$key};
10749: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10750: my $attrib;
10751: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10752: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10753: }
10754: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10755: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10756: $rewrites += $numchg;
10757: }
10758: }
10759: if ($rewrites) {
10760: my $saveresult;
10761: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10762: if ($url eq $container) {
10763: my ($fname) = ($container =~ m{/([^/]+)$});
10764: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10765: $count,'<span class="LC_filename">'.
10766: $fname.'</span>').'</p>';
10767: } else {
10768: $output .= '<p class="LC_error">'.
10769: &mt('Error: could not update links in [_1].',
10770: '<span class="LC_filename">'.
10771: $container.'</span>').'</p>';
10772:
10773: }
10774: }
10775: }
10776: }
1.987 raeburn 10777: } else {
10778: &logthis('Failed to parse '.$container.
10779: ' to modify references: '.$parse_result);
1.661 raeburn 10780: }
10781: }
1.1071 raeburn 10782: if (wantarray) {
10783: return ($output,$count,$codebasecount);
10784: } else {
10785: return $output;
10786: }
1.661 raeburn 10787: }
10788:
10789: sub check_for_existing {
10790: my ($path,$fname,$element) = @_;
10791: my ($state,$msg);
10792: if (-d $path.'/'.$fname) {
10793: $state = 'exists';
10794: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10795: } elsif (-e $path.'/'.$fname) {
10796: $state = 'exists';
10797: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10798: }
10799: if ($state eq 'exists') {
10800: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10801: }
10802: return ($state,$msg);
10803: }
10804:
10805: sub check_for_upload {
10806: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10807: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10808: my $filesize = length($env{'form.'.$element});
10809: if (!$filesize) {
10810: my $msg = '<span class="LC_error">'.
10811: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10812: '<span class="LC_filename">'.$fname.'</span>',
10813: $filesize).'<br />'.
1.1007 raeburn 10814: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10815: '</span>';
10816: return ('zero_bytes',$msg);
10817: }
10818: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10819: my $getpropath = 1;
1.1021 raeburn 10820: my ($dirlistref,$listerror) =
10821: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10822: my $found_file = 0;
10823: my $locked_file = 0;
1.991 raeburn 10824: my @lockers;
10825: my $navmap;
10826: if ($env{'request.course.id'}) {
10827: $navmap = Apache::lonnavmaps::navmap->new();
10828: }
1.1021 raeburn 10829: if (ref($dirlistref) eq 'ARRAY') {
10830: foreach my $line (@{$dirlistref}) {
10831: my ($file_name,$rest)=split(/\&/,$line,2);
10832: if ($file_name eq $fname){
10833: $file_name = $path.$file_name;
10834: if ($group ne '') {
10835: $file_name = $group.$file_name;
10836: }
10837: $found_file = 1;
10838: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10839: foreach my $lock (@lockers) {
10840: if (ref($lock) eq 'ARRAY') {
10841: my ($symb,$crsid) = @{$lock};
10842: if ($crsid eq $env{'request.course.id'}) {
10843: if (ref($navmap)) {
10844: my $res = $navmap->getBySymb($symb);
10845: foreach my $part (@{$res->parts()}) {
10846: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10847: unless (($slot_status == $res->RESERVED) ||
10848: ($slot_status == $res->RESERVED_LOCATION)) {
10849: $locked_file = 1;
10850: }
1.991 raeburn 10851: }
1.1021 raeburn 10852: } else {
10853: $locked_file = 1;
1.991 raeburn 10854: }
10855: } else {
10856: $locked_file = 1;
10857: }
10858: }
1.1021 raeburn 10859: }
10860: } else {
10861: my @info = split(/\&/,$rest);
10862: my $currsize = $info[6]/1000;
10863: if ($currsize < $filesize) {
10864: my $extra = $filesize - $currsize;
10865: if (($current_disk_usage + $extra) > $disk_quota) {
10866: my $msg = '<span class="LC_error">'.
10867: &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.',
10868: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10869: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10870: $disk_quota,$current_disk_usage);
10871: return ('will_exceed_quota',$msg);
10872: }
1.984 raeburn 10873: }
10874: }
1.661 raeburn 10875: }
10876: }
10877: }
10878: if (($current_disk_usage + $filesize) > $disk_quota){
10879: my $msg = '<span class="LC_error">'.
10880: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10881: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10882: return ('will_exceed_quota',$msg);
10883: } elsif ($found_file) {
10884: if ($locked_file) {
10885: my $msg = '<span class="LC_error">';
10886: $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>');
10887: $msg .= '</span><br />';
10888: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10889: return ('file_locked',$msg);
10890: } else {
10891: my $msg = '<span class="LC_error">';
1.984 raeburn 10892: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.661 raeburn 10893: $msg .= '</span>';
1.984 raeburn 10894: return ('existingfile',$msg);
1.661 raeburn 10895: }
10896: }
10897: }
10898:
1.987 raeburn 10899: sub check_for_traversal {
10900: my ($path,$url,$toplevel) = @_;
10901: my @parts=split(/\//,$path);
10902: my $cleanpath;
10903: my $fullpath = $url;
10904: for (my $i=0;$i<@parts;$i++) {
10905: next if ($parts[$i] eq '.');
10906: if ($parts[$i] eq '..') {
10907: $fullpath =~ s{([^/]+/)$}{};
10908: } else {
10909: $fullpath .= $parts[$i].'/';
10910: }
10911: }
10912: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10913: $cleanpath = $1;
10914: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10915: my $curr_toprel = $1;
10916: my @parts = split(/\//,$curr_toprel);
10917: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10918: my @urlparts = split(/\//,$url_toprel);
10919: my $doubledots;
10920: my $startdiff = -1;
10921: for (my $i=0; $i<@urlparts; $i++) {
10922: if ($startdiff == -1) {
10923: unless ($urlparts[$i] eq $parts[$i]) {
10924: $startdiff = $i;
10925: $doubledots .= '../';
10926: }
10927: } else {
10928: $doubledots .= '../';
10929: }
10930: }
10931: if ($startdiff > -1) {
10932: $cleanpath = $doubledots;
10933: for (my $i=$startdiff; $i<@parts; $i++) {
10934: $cleanpath .= $parts[$i].'/';
10935: }
10936: }
10937: }
10938: $cleanpath =~ s{(/)$}{};
10939: return $cleanpath;
10940: }
1.31 albertel 10941:
1.1053 raeburn 10942: sub is_archive_file {
10943: my ($mimetype) = @_;
10944: if (($mimetype eq 'application/octet-stream') ||
10945: ($mimetype eq 'application/x-stuffit') ||
10946: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10947: return 1;
10948: }
10949: return;
10950: }
10951:
10952: sub decompress_form {
1.1065 raeburn 10953: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10954: my %lt = &Apache::lonlocal::texthash (
10955: this => 'This file is an archive file.',
1.1067 raeburn 10956: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10957: itsc => 'Its contents are as follows:',
1.1053 raeburn 10958: youm => 'You may wish to extract its contents.',
10959: extr => 'Extract contents',
1.1067 raeburn 10960: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10961: proa => 'Process automatically?',
1.1053 raeburn 10962: yes => 'Yes',
10963: no => 'No',
1.1067 raeburn 10964: fold => 'Title for folder containing movie',
10965: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10966: );
1.1065 raeburn 10967: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10968: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10969: my $info = &list_archive_contents($fileloc,\@paths);
10970: if (@paths) {
10971: foreach my $path (@paths) {
10972: $path =~ s{^/}{};
1.1067 raeburn 10973: if ($path =~ m{^([^/]+)/$}) {
10974: $topdir = $1;
10975: }
1.1065 raeburn 10976: if ($path =~ m{^([^/]+)/}) {
10977: $toplevel{$1} = $path;
10978: } else {
10979: $toplevel{$path} = $path;
10980: }
10981: }
10982: }
1.1067 raeburn 10983: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
10984: my @camtasia = ("$topdir/","$topdir/index.html",
10985: "$topdir/media/",
10986: "$topdir/media/$topdir.mp4",
10987: "$topdir/media/FirstFrame.png",
10988: "$topdir/media/player.swf",
10989: "$topdir/media/swfobject.js",
10990: "$topdir/media/expressInstall.swf");
10991: my @diffs = &compare_arrays(\@paths,\@camtasia);
10992: if (@diffs == 0) {
10993: $is_camtasia = 1;
10994: }
10995: }
10996: my $output;
10997: if ($is_camtasia) {
10998: $output = <<"ENDCAM";
10999: <script type="text/javascript" language="Javascript">
11000: // <![CDATA[
11001:
11002: function camtasiaToggle() {
11003: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11004: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
11005: if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
11006:
11007: document.getElementById('camtasia_titles').style.display='block';
11008: } else {
11009: document.getElementById('camtasia_titles').style.display='none';
11010: }
11011: }
11012: }
11013: return;
11014: }
11015:
11016: // ]]>
11017: </script>
11018: <p>$lt{'camt'}</p>
11019: ENDCAM
1.1065 raeburn 11020: } else {
1.1067 raeburn 11021: $output = '<p>'.$lt{'this'};
11022: if ($info eq '') {
11023: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11024: } else {
11025: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11026: '<div><pre>'.$info.'</pre></div>';
11027: }
1.1065 raeburn 11028: }
1.1067 raeburn 11029: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11030: my $duplicates;
11031: my $num = 0;
11032: if (ref($dirlist) eq 'ARRAY') {
11033: foreach my $item (@{$dirlist}) {
11034: if (ref($item) eq 'ARRAY') {
11035: if (exists($toplevel{$item->[0]})) {
11036: $duplicates .=
11037: &start_data_table_row().
11038: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11039: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11040: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11041: 'value="1" />'.&mt('Yes').'</label>'.
11042: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11043: '<td>'.$item->[0].'</td>';
11044: if ($item->[2]) {
11045: $duplicates .= '<td>'.&mt('Directory').'</td>';
11046: } else {
11047: $duplicates .= '<td>'.&mt('File').'</td>';
11048: }
11049: $duplicates .= '<td>'.$item->[3].'</td>'.
11050: '<td>'.
11051: &Apache::lonlocal::locallocaltime($item->[4]).
11052: '</td>'.
11053: &end_data_table_row();
11054: $num ++;
11055: }
11056: }
11057: }
11058: }
11059: my $itemcount;
11060: if (@paths > 0) {
11061: $itemcount = scalar(@paths);
11062: } else {
11063: $itemcount = 1;
11064: }
1.1067 raeburn 11065: if ($is_camtasia) {
11066: $output .= $lt{'auto'}.'<br />'.
11067: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
11068: '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
11069: $lt{'yes'}.'</label> <label>'.
11070: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11071: $lt{'no'}.'</label></span><br />'.
11072: '<div id="camtasia_titles" style="display:block">'.
11073: &Apache::lonhtmlcommon::start_pick_box().
11074: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11075: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11076: &Apache::lonhtmlcommon::row_closure().
11077: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11078: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11079: &Apache::lonhtmlcommon::row_closure(1).
11080: &Apache::lonhtmlcommon::end_pick_box().
11081: '</div>';
11082: }
1.1065 raeburn 11083: $output .=
11084: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11085: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11086: "\n";
1.1065 raeburn 11087: if ($duplicates ne '') {
11088: $output .= '<p><span class="LC_warning">'.
11089: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11090: &start_data_table().
11091: &start_data_table_header_row().
11092: '<th>'.&mt('Overwrite?').'</th>'.
11093: '<th>'.&mt('Name').'</th>'.
11094: '<th>'.&mt('Type').'</th>'.
11095: '<th>'.&mt('Size').'</th>'.
11096: '<th>'.&mt('Last modified').'</th>'.
11097: &end_data_table_header_row().
11098: $duplicates.
11099: &end_data_table().
11100: '</p>';
11101: }
1.1067 raeburn 11102: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11103: if (ref($hiddenelements) eq 'HASH') {
11104: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11105: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11106: }
11107: }
11108: $output .= <<"END";
1.1067 raeburn 11109: <br />
1.1053 raeburn 11110: <input type="submit" name="decompress" value="$lt{'extr'}" />
11111: </form>
11112: $noextract
11113: END
11114: return $output;
11115: }
11116:
1.1065 raeburn 11117: sub decompression_utility {
11118: my ($program) = @_;
11119: my @utilities = ('tar','gunzip','bunzip2','unzip');
11120: my $location;
11121: if (grep(/^\Q$program\E$/,@utilities)) {
11122: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11123: '/usr/sbin/') {
11124: if (-x $dir.$program) {
11125: $location = $dir.$program;
11126: last;
11127: }
11128: }
11129: }
11130: return $location;
11131: }
11132:
11133: sub list_archive_contents {
11134: my ($file,$pathsref) = @_;
11135: my (@cmd,$output);
11136: my $needsregexp;
11137: if ($file =~ /\.zip$/) {
11138: @cmd = (&decompression_utility('unzip'),"-l");
11139: $needsregexp = 1;
11140: } elsif (($file =~ m/\.tar\.gz$/) ||
11141: ($file =~ /\.tgz$/)) {
11142: @cmd = (&decompression_utility('tar'),"-ztf");
11143: } elsif ($file =~ /\.tar\.bz2$/) {
11144: @cmd = (&decompression_utility('tar'),"-jtf");
11145: } elsif ($file =~ m|\.tar$|) {
11146: @cmd = (&decompression_utility('tar'),"-tf");
11147: }
11148: if (@cmd) {
11149: undef($!);
11150: undef($@);
11151: if (open(my $fh,"-|", @cmd, $file)) {
11152: while (my $line = <$fh>) {
11153: $output .= $line;
11154: chomp($line);
11155: my $item;
11156: if ($needsregexp) {
11157: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11158: } else {
11159: $item = $line;
11160: }
11161: if ($item ne '') {
11162: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11163: push(@{$pathsref},$item);
11164: }
11165: }
11166: }
11167: close($fh);
11168: }
11169: }
11170: return $output;
11171: }
11172:
1.1053 raeburn 11173: sub decompress_uploaded_file {
11174: my ($file,$dir) = @_;
11175: &Apache::lonnet::appenv({'cgi.file' => $file});
11176: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11177: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11178: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11179: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11180: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11181: my $decompressed = $env{'cgi.decompressed'};
11182: &Apache::lonnet::delenv('cgi.file');
11183: &Apache::lonnet::delenv('cgi.dir');
11184: &Apache::lonnet::delenv('cgi.decompressed');
11185: return ($decompressed,$result);
11186: }
11187:
1.1055 raeburn 11188: sub process_decompression {
11189: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11190: my ($dir,$error,$warning,$output);
11191: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.1075.2.34 raeburn 11192: $error = &mt('Filename not a supported archive file type.').
11193: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11194: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11195: } else {
11196: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11197: if ($docuhome eq 'no_host') {
11198: $error = &mt('Could not determine home server for course.');
11199: } else {
11200: my @ids=&Apache::lonnet::current_machine_ids();
11201: my $currdir = "$dir_root/$destination";
11202: if (grep(/^\Q$docuhome\E$/,@ids)) {
11203: $dir = &LONCAPA::propath($docudom,$docuname).
11204: "$dir_root/$destination";
11205: } else {
11206: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11207: "$dir_root/$docudom/$docuname/$destination";
11208: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11209: $error = &mt('Archive file not found.');
11210: }
11211: }
1.1065 raeburn 11212: my (@to_overwrite,@to_skip);
11213: if ($env{'form.archive_overwrite_total'} > 0) {
11214: my $total = $env{'form.archive_overwrite_total'};
11215: for (my $i=0; $i<$total; $i++) {
11216: if ($env{'form.archive_overwrite_'.$i} == 1) {
11217: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11218: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11219: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11220: }
11221: }
11222: }
11223: my $numskip = scalar(@to_skip);
11224: if (($numskip > 0) &&
11225: ($numskip == $env{'form.archive_itemcount'})) {
11226: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11227: } elsif ($dir eq '') {
1.1055 raeburn 11228: $error = &mt('Directory containing archive file unavailable.');
11229: } elsif (!$error) {
1.1065 raeburn 11230: my ($decompressed,$display);
11231: if ($numskip > 0) {
11232: my $tempdir = time.'_'.$$.int(rand(10000));
11233: mkdir("$dir/$tempdir",0755);
11234: system("mv $dir/$file $dir/$tempdir/$file");
11235: ($decompressed,$display) =
11236: &decompress_uploaded_file($file,"$dir/$tempdir");
11237: foreach my $item (@to_skip) {
11238: if (($item ne '') && ($item !~ /\.\./)) {
11239: if (-f "$dir/$tempdir/$item") {
11240: unlink("$dir/$tempdir/$item");
11241: } elsif (-d "$dir/$tempdir/$item") {
11242: system("rm -rf $dir/$tempdir/$item");
11243: }
11244: }
11245: }
11246: system("mv $dir/$tempdir/* $dir");
11247: rmdir("$dir/$tempdir");
11248: } else {
11249: ($decompressed,$display) =
11250: &decompress_uploaded_file($file,$dir);
11251: }
1.1055 raeburn 11252: if ($decompressed eq 'ok') {
1.1065 raeburn 11253: $output = '<p class="LC_info">'.
11254: &mt('Files extracted successfully from archive.').
11255: '</p>'."\n";
1.1055 raeburn 11256: my ($warning,$result,@contents);
11257: my ($newdirlistref,$newlisterror) =
11258: &Apache::lonnet::dirlist($currdir,$docudom,
11259: $docuname,1);
11260: my (%is_dir,%changes,@newitems);
11261: my $dirptr = 16384;
1.1065 raeburn 11262: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11263: foreach my $dir_line (@{$newdirlistref}) {
11264: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11265: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11266: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11267: push(@newitems,$item);
11268: if ($dirptr&$testdir) {
11269: $is_dir{$item} = 1;
11270: }
11271: $changes{$item} = 1;
11272: }
11273: }
11274: }
11275: if (keys(%changes) > 0) {
11276: foreach my $item (sort(@newitems)) {
11277: if ($changes{$item}) {
11278: push(@contents,$item);
11279: }
11280: }
11281: }
11282: if (@contents > 0) {
1.1067 raeburn 11283: my $wantform;
11284: unless ($env{'form.autoextract_camtasia'}) {
11285: $wantform = 1;
11286: }
1.1056 raeburn 11287: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11288: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11289: $currdir,\%is_dir,
11290: \%children,\%parent,
1.1056 raeburn 11291: \@contents,\%dirorder,
11292: \%titles,$wantform);
1.1055 raeburn 11293: if ($datatable ne '') {
11294: $output .= &archive_options_form('decompressed',$datatable,
11295: $count,$hiddenelem);
1.1065 raeburn 11296: my $startcount = 6;
1.1055 raeburn 11297: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11298: \%titles,\%children);
1.1055 raeburn 11299: }
1.1067 raeburn 11300: if ($env{'form.autoextract_camtasia'}) {
11301: my %displayed;
11302: my $total = 1;
11303: $env{'form.archive_directory'} = [];
11304: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11305: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11306: $path =~ s{/$}{};
11307: my $item;
11308: if ($path ne '') {
11309: $item = "$path/$titles{$i}";
11310: } else {
11311: $item = $titles{$i};
11312: }
11313: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11314: if ($item eq $contents[0]) {
11315: push(@{$env{'form.archive_directory'}},$i);
11316: $env{'form.archive_'.$i} = 'display';
11317: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11318: $displayed{'folder'} = $i;
11319: } elsif ($item eq "$contents[0]/index.html") {
11320: $env{'form.archive_'.$i} = 'display';
11321: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11322: $displayed{'web'} = $i;
11323: } else {
11324: if ($item eq "$contents[0]/media") {
11325: push(@{$env{'form.archive_directory'}},$i);
11326: }
11327: $env{'form.archive_'.$i} = 'dependency';
11328: }
11329: $total ++;
11330: }
11331: for (my $i=1; $i<$total; $i++) {
11332: next if ($i == $displayed{'web'});
11333: next if ($i == $displayed{'folder'});
11334: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11335: }
11336: $env{'form.phase'} = 'decompress_cleanup';
11337: $env{'form.archivedelete'} = 1;
11338: $env{'form.archive_count'} = $total-1;
11339: $output .=
11340: &process_extracted_files('coursedocs',$docudom,
11341: $docuname,$destination,
11342: $dir_root,$hiddenelem);
11343: }
1.1055 raeburn 11344: } else {
11345: $warning = &mt('No new items extracted from archive file.');
11346: }
11347: } else {
11348: $output = $display;
11349: $error = &mt('An error occurred during extraction from the archive file.');
11350: }
11351: }
11352: }
11353: }
11354: if ($error) {
11355: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11356: $error.'</p>'."\n";
11357: }
11358: if ($warning) {
11359: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11360: }
11361: return $output;
11362: }
11363:
11364: sub get_extracted {
1.1056 raeburn 11365: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11366: $titles,$wantform) = @_;
1.1055 raeburn 11367: my $count = 0;
11368: my $depth = 0;
11369: my $datatable;
1.1056 raeburn 11370: my @hierarchy;
1.1055 raeburn 11371: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11372: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11373: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11374: foreach my $item (@{$contents}) {
11375: $count ++;
1.1056 raeburn 11376: @{$dirorder->{$count}} = @hierarchy;
11377: $titles->{$count} = $item;
1.1055 raeburn 11378: &archive_hierarchy($depth,$count,$parent,$children);
11379: if ($wantform) {
11380: $datatable .= &archive_row($is_dir->{$item},$item,
11381: $currdir,$depth,$count);
11382: }
11383: if ($is_dir->{$item}) {
11384: $depth ++;
1.1056 raeburn 11385: push(@hierarchy,$count);
11386: $parent->{$depth} = $count;
1.1055 raeburn 11387: $datatable .=
11388: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11389: \$depth,\$count,\@hierarchy,$dirorder,
11390: $children,$parent,$titles,$wantform);
1.1055 raeburn 11391: $depth --;
1.1056 raeburn 11392: pop(@hierarchy);
1.1055 raeburn 11393: }
11394: }
11395: return ($count,$datatable);
11396: }
11397:
11398: sub recurse_extracted_archive {
1.1056 raeburn 11399: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11400: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11401: my $result='';
1.1056 raeburn 11402: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11403: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11404: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11405: return $result;
11406: }
11407: my $dirptr = 16384;
11408: my ($newdirlistref,$newlisterror) =
11409: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11410: if (ref($newdirlistref) eq 'ARRAY') {
11411: foreach my $dir_line (@{$newdirlistref}) {
11412: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11413: unless ($item =~ /^\.+$/) {
11414: $$count ++;
1.1056 raeburn 11415: @{$dirorder->{$$count}} = @{$hierarchy};
11416: $titles->{$$count} = $item;
1.1055 raeburn 11417: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11418:
1.1055 raeburn 11419: my $is_dir;
11420: if ($dirptr&$testdir) {
11421: $is_dir = 1;
11422: }
11423: if ($wantform) {
11424: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11425: }
11426: if ($is_dir) {
11427: $$depth ++;
1.1056 raeburn 11428: push(@{$hierarchy},$$count);
11429: $parent->{$$depth} = $$count;
1.1055 raeburn 11430: $result .=
11431: &recurse_extracted_archive("$currdir/$item",$docudom,
11432: $docuname,$depth,$count,
1.1056 raeburn 11433: $hierarchy,$dirorder,$children,
11434: $parent,$titles,$wantform);
1.1055 raeburn 11435: $$depth --;
1.1056 raeburn 11436: pop(@{$hierarchy});
1.1055 raeburn 11437: }
11438: }
11439: }
11440: }
11441: return $result;
11442: }
11443:
11444: sub archive_hierarchy {
11445: my ($depth,$count,$parent,$children) =@_;
11446: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11447: if (exists($parent->{$depth})) {
11448: $children->{$parent->{$depth}} .= $count.':';
11449: }
11450: }
11451: return;
11452: }
11453:
11454: sub archive_row {
11455: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11456: my ($name) = ($item =~ m{([^/]+)$});
11457: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11458: 'display' => 'Add as file',
1.1055 raeburn 11459: 'dependency' => 'Include as dependency',
11460: 'discard' => 'Discard',
11461: );
11462: if ($is_dir) {
1.1059 raeburn 11463: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11464: }
1.1056 raeburn 11465: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11466: my $offset = 0;
1.1055 raeburn 11467: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11468: $offset ++;
1.1065 raeburn 11469: if ($action ne 'display') {
11470: $offset ++;
11471: }
1.1055 raeburn 11472: $output .= '<td><span class="LC_nobreak">'.
11473: '<label><input type="radio" name="archive_'.$count.
11474: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11475: my $text = $choices{$action};
11476: if ($is_dir) {
11477: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11478: if ($action eq 'display') {
1.1059 raeburn 11479: $text = &mt('Add as folder');
1.1055 raeburn 11480: }
1.1056 raeburn 11481: } else {
11482: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11483:
11484: }
11485: $output .= ' /> '.$choices{$action}.'</label></span>';
11486: if ($action eq 'dependency') {
11487: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11488: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11489: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11490: '<option value=""></option>'."\n".
11491: '</select>'."\n".
11492: '</div>';
1.1059 raeburn 11493: } elsif ($action eq 'display') {
11494: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11495: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11496: '</div>';
1.1055 raeburn 11497: }
1.1056 raeburn 11498: $output .= '</td>';
1.1055 raeburn 11499: }
11500: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11501: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11502: for (my $i=0; $i<$depth; $i++) {
11503: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11504: }
11505: if ($is_dir) {
11506: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11507: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11508: } else {
11509: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11510: }
11511: $output .= ' '.$name.'</td>'."\n".
11512: &end_data_table_row();
11513: return $output;
11514: }
11515:
11516: sub archive_options_form {
1.1065 raeburn 11517: my ($form,$display,$count,$hiddenelem) = @_;
11518: my %lt = &Apache::lonlocal::texthash(
11519: perm => 'Permanently remove archive file?',
11520: hows => 'How should each extracted item be incorporated in the course?',
11521: cont => 'Content actions for all',
11522: addf => 'Add as folder/file',
11523: incd => 'Include as dependency for a displayed file',
11524: disc => 'Discard',
11525: no => 'No',
11526: yes => 'Yes',
11527: save => 'Save',
11528: );
11529: my $output = <<"END";
11530: <form name="$form" method="post" action="">
11531: <p><span class="LC_nobreak">$lt{'perm'}
11532: <label>
11533: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11534: </label>
11535:
11536: <label>
11537: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11538: </span>
11539: </p>
11540: <input type="hidden" name="phase" value="decompress_cleanup" />
11541: <br />$lt{'hows'}
11542: <div class="LC_columnSection">
11543: <fieldset>
11544: <legend>$lt{'cont'}</legend>
11545: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11546: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11547: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11548: </fieldset>
11549: </div>
11550: END
11551: return $output.
1.1055 raeburn 11552: &start_data_table()."\n".
1.1065 raeburn 11553: $display."\n".
1.1055 raeburn 11554: &end_data_table()."\n".
11555: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11556: $hiddenelem.
1.1065 raeburn 11557: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11558: '</form>';
11559: }
11560:
11561: sub archive_javascript {
1.1056 raeburn 11562: my ($startcount,$numitems,$titles,$children) = @_;
11563: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11564: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11565: my $scripttag = <<START;
11566: <script type="text/javascript">
11567: // <![CDATA[
11568:
11569: function checkAll(form,prefix) {
11570: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11571: for (var i=0; i < form.elements.length; i++) {
11572: var id = form.elements[i].id;
11573: if ((id != '') && (id != undefined)) {
11574: if (idstr.test(id)) {
11575: if (form.elements[i].type == 'radio') {
11576: form.elements[i].checked = true;
1.1056 raeburn 11577: var nostart = i-$startcount;
1.1059 raeburn 11578: var offset = nostart%7;
11579: var count = (nostart-offset)/7;
1.1056 raeburn 11580: dependencyCheck(form,count,offset);
1.1055 raeburn 11581: }
11582: }
11583: }
11584: }
11585: }
11586:
11587: function propagateCheck(form,count) {
11588: if (count > 0) {
1.1059 raeburn 11589: var startelement = $startcount + ((count-1) * 7);
11590: for (var j=1; j<6; j++) {
11591: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11592: var item = startelement + j;
11593: if (form.elements[item].type == 'radio') {
11594: if (form.elements[item].checked) {
11595: containerCheck(form,count,j);
11596: break;
11597: }
1.1055 raeburn 11598: }
11599: }
11600: }
11601: }
11602: }
11603:
11604: numitems = $numitems
1.1056 raeburn 11605: var titles = new Array(numitems);
11606: var parents = new Array(numitems);
1.1055 raeburn 11607: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11608: parents[i] = new Array;
1.1055 raeburn 11609: }
1.1059 raeburn 11610: var maintitle = '$maintitle';
1.1055 raeburn 11611:
11612: START
11613:
1.1056 raeburn 11614: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11615: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11616: for (my $i=0; $i<@contents; $i ++) {
11617: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11618: }
11619: }
11620:
1.1056 raeburn 11621: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11622: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11623: }
11624:
1.1055 raeburn 11625: $scripttag .= <<END;
11626:
11627: function containerCheck(form,count,offset) {
11628: if (count > 0) {
1.1056 raeburn 11629: dependencyCheck(form,count,offset);
1.1059 raeburn 11630: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11631: form.elements[item].checked = true;
11632: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11633: if (parents[count].length > 0) {
11634: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11635: containerCheck(form,parents[count][j],offset);
11636: }
11637: }
11638: }
11639: }
11640: }
11641:
11642: function dependencyCheck(form,count,offset) {
11643: if (count > 0) {
1.1059 raeburn 11644: var chosen = (offset+$startcount)+7*(count-1);
11645: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11646: var currtype = form.elements[depitem].type;
11647: if (form.elements[chosen].value == 'dependency') {
11648: document.getElementById('arc_depon_'+count).style.display='block';
11649: form.elements[depitem].options.length = 0;
11650: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 11651: for (var i=1; i<=numitems; i++) {
11652: if (i == count) {
11653: continue;
11654: }
1.1059 raeburn 11655: var startelement = $startcount + (i-1) * 7;
11656: for (var j=1; j<6; j++) {
11657: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11658: var item = startelement + j;
11659: if (form.elements[item].type == 'radio') {
11660: if (form.elements[item].checked) {
11661: if (form.elements[item].value == 'display') {
11662: var n = form.elements[depitem].options.length;
11663: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11664: }
11665: }
11666: }
11667: }
11668: }
11669: }
11670: } else {
11671: document.getElementById('arc_depon_'+count).style.display='none';
11672: form.elements[depitem].options.length = 0;
11673: form.elements[depitem].options[0] = new Option('Select','',true,true);
11674: }
1.1059 raeburn 11675: titleCheck(form,count,offset);
1.1056 raeburn 11676: }
11677: }
11678:
11679: function propagateSelect(form,count,offset) {
11680: if (count > 0) {
1.1065 raeburn 11681: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11682: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11683: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11684: if (parents[count].length > 0) {
11685: for (var j=0; j<parents[count].length; j++) {
11686: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11687: }
11688: }
11689: }
11690: }
11691: }
1.1056 raeburn 11692:
11693: function containerSelect(form,count,offset,picked) {
11694: if (count > 0) {
1.1065 raeburn 11695: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11696: if (form.elements[item].type == 'radio') {
11697: if (form.elements[item].value == 'dependency') {
11698: if (form.elements[item+1].type == 'select-one') {
11699: for (var i=0; i<form.elements[item+1].options.length; i++) {
11700: if (form.elements[item+1].options[i].value == picked) {
11701: form.elements[item+1].selectedIndex = i;
11702: break;
11703: }
11704: }
11705: }
11706: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11707: if (parents[count].length > 0) {
11708: for (var j=0; j<parents[count].length; j++) {
11709: containerSelect(form,parents[count][j],offset,picked);
11710: }
11711: }
11712: }
11713: }
11714: }
11715: }
11716: }
11717:
1.1059 raeburn 11718: function titleCheck(form,count,offset) {
11719: if (count > 0) {
11720: var chosen = (offset+$startcount)+7*(count-1);
11721: var depitem = $startcount + ((count-1) * 7) + 2;
11722: var currtype = form.elements[depitem].type;
11723: if (form.elements[chosen].value == 'display') {
11724: document.getElementById('arc_title_'+count).style.display='block';
11725: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11726: document.getElementById('archive_title_'+count).value=maintitle;
11727: }
11728: } else {
11729: document.getElementById('arc_title_'+count).style.display='none';
11730: if (currtype == 'text') {
11731: document.getElementById('archive_title_'+count).value='';
11732: }
11733: }
11734: }
11735: return;
11736: }
11737:
1.1055 raeburn 11738: // ]]>
11739: </script>
11740: END
11741: return $scripttag;
11742: }
11743:
11744: sub process_extracted_files {
1.1067 raeburn 11745: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11746: my $numitems = $env{'form.archive_count'};
11747: return unless ($numitems);
11748: my @ids=&Apache::lonnet::current_machine_ids();
11749: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11750: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11751: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11752: if (grep(/^\Q$docuhome\E$/,@ids)) {
11753: $prefix = &LONCAPA::propath($docudom,$docuname);
11754: $pathtocheck = "$dir_root/$destination";
11755: $dir = $dir_root;
11756: $ishome = 1;
11757: } else {
11758: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11759: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11760: $dir = "$dir_root/$docudom/$docuname";
11761: }
11762: my $currdir = "$dir_root/$destination";
11763: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11764: if ($env{'form.folderpath'}) {
11765: my @items = split('&',$env{'form.folderpath'});
11766: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 11767: if ($env{'form.folderpath'} =~ /\:1$/) {
11768: $containers{'0'}='page';
11769: } else {
11770: $containers{'0'}='sequence';
11771: }
1.1055 raeburn 11772: }
11773: my @archdirs = &get_env_multiple('form.archive_directory');
11774: if ($numitems) {
11775: for (my $i=1; $i<=$numitems; $i++) {
11776: my $path = $env{'form.archive_content_'.$i};
11777: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11778: my $item = $1;
11779: $toplevelitems{$item} = $i;
11780: if (grep(/^\Q$i\E$/,@archdirs)) {
11781: $is_dir{$item} = 1;
11782: }
11783: }
11784: }
11785: }
1.1067 raeburn 11786: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11787: if (keys(%toplevelitems) > 0) {
11788: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11789: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11790: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11791: }
1.1066 raeburn 11792: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11793: if ($numitems) {
11794: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 11795: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11796: my $path = $env{'form.archive_content_'.$i};
11797: if ($path =~ /^\Q$pathtocheck\E/) {
11798: if ($env{'form.archive_'.$i} eq 'discard') {
11799: if ($prefix ne '' && $path ne '') {
11800: if (-e $prefix.$path) {
1.1066 raeburn 11801: if ((@archdirs > 0) &&
11802: (grep(/^\Q$i\E$/,@archdirs))) {
11803: $todeletedir{$prefix.$path} = 1;
11804: } else {
11805: $todelete{$prefix.$path} = 1;
11806: }
1.1055 raeburn 11807: }
11808: }
11809: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11810: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11811: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11812: $docstitle = $env{'form.archive_title_'.$i};
11813: if ($docstitle eq '') {
11814: $docstitle = $title;
11815: }
1.1055 raeburn 11816: $outer = 0;
1.1056 raeburn 11817: if (ref($dirorder{$i}) eq 'ARRAY') {
11818: if (@{$dirorder{$i}} > 0) {
11819: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11820: if ($env{'form.archive_'.$item} eq 'display') {
11821: $outer = $item;
11822: last;
11823: }
11824: }
11825: }
11826: }
11827: my ($errtext,$fatal) =
11828: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11829: '/'.$folders{$outer}.'.'.
11830: $containers{$outer});
11831: next if ($fatal);
11832: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11833: if ($context eq 'coursedocs') {
1.1056 raeburn 11834: $mapinner{$i} = time;
1.1055 raeburn 11835: $folders{$i} = 'default_'.$mapinner{$i};
11836: $containers{$i} = 'sequence';
11837: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11838: $folders{$i}.'.'.$containers{$i};
11839: my $newidx = &LONCAPA::map::getresidx();
11840: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11841: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11842: push(@LONCAPA::map::order,$newidx);
11843: my ($outtext,$errtext) =
11844: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11845: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11846: '.'.$containers{$outer},1,1);
1.1056 raeburn 11847: $newseqid{$i} = $newidx;
1.1067 raeburn 11848: unless ($errtext) {
11849: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11850: }
1.1055 raeburn 11851: }
11852: } else {
11853: if ($context eq 'coursedocs') {
11854: my $newidx=&LONCAPA::map::getresidx();
11855: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11856: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11857: $title;
11858: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11859: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11860: }
11861: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11862: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11863: }
11864: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11865: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11866: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11867: unless ($ishome) {
11868: my $fetch = "$newdest{$i}/$title";
11869: $fetch =~ s/^\Q$prefix$dir\E//;
11870: $prompttofetch{$fetch} = 1;
11871: }
1.1055 raeburn 11872: }
11873: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11874: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11875: push(@LONCAPA::map::order, $newidx);
11876: my ($outtext,$errtext)=
11877: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11878: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11879: '.'.$containers{$outer},1,1);
1.1067 raeburn 11880: unless ($errtext) {
11881: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11882: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11883: }
11884: }
1.1055 raeburn 11885: }
11886: }
1.1075.2.11 raeburn 11887: }
11888: } else {
11889: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11890: }
11891: }
11892: for (my $i=1; $i<=$numitems; $i++) {
11893: next unless ($env{'form.archive_'.$i} eq 'dependency');
11894: my $path = $env{'form.archive_content_'.$i};
11895: if ($path =~ /^\Q$pathtocheck\E/) {
11896: my ($title) = ($path =~ m{/([^/]+)$});
11897: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11898: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11899: if (ref($dirorder{$i}) eq 'ARRAY') {
11900: my ($itemidx,$fullpath,$relpath);
11901: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11902: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11903: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 11904: if ($dirorder{$i}->[$j] eq $container) {
11905: $itemidx = $j;
1.1056 raeburn 11906: }
11907: }
1.1075.2.11 raeburn 11908: }
11909: if ($itemidx eq '') {
11910: $itemidx = 0;
11911: }
11912: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11913: if ($mapinner{$referrer{$i}}) {
11914: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11915: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11916: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11917: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11918: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11919: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11920: if (!-e $fullpath) {
11921: mkdir($fullpath,0755);
1.1056 raeburn 11922: }
11923: }
1.1075.2.11 raeburn 11924: } else {
11925: last;
1.1056 raeburn 11926: }
1.1075.2.11 raeburn 11927: }
11928: }
11929: } elsif ($newdest{$referrer{$i}}) {
11930: $fullpath = $newdest{$referrer{$i}};
11931: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11932: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11933: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11934: last;
11935: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11936: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11937: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11938: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11939: if (!-e $fullpath) {
11940: mkdir($fullpath,0755);
1.1056 raeburn 11941: }
11942: }
1.1075.2.11 raeburn 11943: } else {
11944: last;
1.1056 raeburn 11945: }
1.1075.2.11 raeburn 11946: }
11947: }
11948: if ($fullpath ne '') {
11949: if (-e "$prefix$path") {
11950: system("mv $prefix$path $fullpath/$title");
11951: }
11952: if (-e "$fullpath/$title") {
11953: my $showpath;
11954: if ($relpath ne '') {
11955: $showpath = "$relpath/$title";
11956: } else {
11957: $showpath = "/$title";
1.1056 raeburn 11958: }
1.1075.2.11 raeburn 11959: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
11960: }
11961: unless ($ishome) {
11962: my $fetch = "$fullpath/$title";
11963: $fetch =~ s/^\Q$prefix$dir\E//;
11964: $prompttofetch{$fetch} = 1;
1.1055 raeburn 11965: }
11966: }
11967: }
1.1075.2.11 raeburn 11968: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
11969: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
11970: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 11971: }
11972: } else {
1.1075.2.11 raeburn 11973: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 11974: }
11975: }
11976: if (keys(%todelete)) {
11977: foreach my $key (keys(%todelete)) {
11978: unlink($key);
1.1066 raeburn 11979: }
11980: }
11981: if (keys(%todeletedir)) {
11982: foreach my $key (keys(%todeletedir)) {
11983: rmdir($key);
11984: }
11985: }
11986: foreach my $dir (sort(keys(%is_dir))) {
11987: if (($pathtocheck ne '') && ($dir ne '')) {
11988: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 11989: }
11990: }
1.1067 raeburn 11991: if ($result ne '') {
11992: $output .= '<ul>'."\n".
11993: $result."\n".
11994: '</ul>';
11995: }
11996: unless ($ishome) {
11997: my $replicationfail;
11998: foreach my $item (keys(%prompttofetch)) {
11999: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12000: unless ($fetchresult eq 'ok') {
12001: $replicationfail .= '<li>'.$item.'</li>'."\n";
12002: }
12003: }
12004: if ($replicationfail) {
12005: $output .= '<p class="LC_error">'.
12006: &mt('Course home server failed to retrieve:').'<ul>'.
12007: $replicationfail.
12008: '</ul></p>';
12009: }
12010: }
1.1055 raeburn 12011: } else {
12012: $warning = &mt('No items found in archive.');
12013: }
12014: if ($error) {
12015: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12016: $error.'</p>'."\n";
12017: }
12018: if ($warning) {
12019: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12020: }
12021: return $output;
12022: }
12023:
1.1066 raeburn 12024: sub cleanup_empty_dirs {
12025: my ($path) = @_;
12026: if (($path ne '') && (-d $path)) {
12027: if (opendir(my $dirh,$path)) {
12028: my @dircontents = grep(!/^\./,readdir($dirh));
12029: my $numitems = 0;
12030: foreach my $item (@dircontents) {
12031: if (-d "$path/$item") {
1.1075.2.28 raeburn 12032: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12033: if (-e "$path/$item") {
12034: $numitems ++;
12035: }
12036: } else {
12037: $numitems ++;
12038: }
12039: }
12040: if ($numitems == 0) {
12041: rmdir($path);
12042: }
12043: closedir($dirh);
12044: }
12045: }
12046: return;
12047: }
12048:
1.41 ng 12049: =pod
1.45 matthew 12050:
1.1068 raeburn 12051: =item &get_folder_hierarchy()
12052:
12053: Provides hierarchy of names of folders/sub-folders containing the current
12054: item,
12055:
12056: Inputs: 3
12057: - $navmap - navmaps object
12058:
12059: - $map - url for map (either the trigger itself, or map containing
12060: the resource, which is the trigger).
12061:
12062: - $showitem - 1 => show title for map itself; 0 => do not show.
12063:
12064: Outputs: 1 @pathitems - array of folder/subfolder names.
12065:
12066: =cut
12067:
12068: sub get_folder_hierarchy {
12069: my ($navmap,$map,$showitem) = @_;
12070: my @pathitems;
12071: if (ref($navmap)) {
12072: my $mapres = $navmap->getResourceByUrl($map);
12073: if (ref($mapres)) {
12074: my $pcslist = $mapres->map_hierarchy();
12075: if ($pcslist ne '') {
12076: my @pcs = split(/,/,$pcslist);
12077: foreach my $pc (@pcs) {
12078: if ($pc == 1) {
1.1075.2.38 raeburn 12079: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12080: } else {
12081: my $res = $navmap->getByMapPc($pc);
12082: if (ref($res)) {
12083: my $title = $res->compTitle();
12084: $title =~ s/\W+/_/g;
12085: if ($title ne '') {
12086: push(@pathitems,$title);
12087: }
12088: }
12089: }
12090: }
12091: }
1.1071 raeburn 12092: if ($showitem) {
12093: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12094: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12095: } else {
12096: my $maptitle = $mapres->compTitle();
12097: $maptitle =~ s/\W+/_/g;
12098: if ($maptitle ne '') {
12099: push(@pathitems,$maptitle);
12100: }
1.1068 raeburn 12101: }
12102: }
12103: }
12104: }
12105: return @pathitems;
12106: }
12107:
12108: =pod
12109:
1.1015 raeburn 12110: =item * &get_turnedin_filepath()
12111:
12112: Determines path in a user's portfolio file for storage of files uploaded
12113: to a specific essayresponse or dropbox item.
12114:
12115: Inputs: 3 required + 1 optional.
12116: $symb is symb for resource, $uname and $udom are for current user (required).
12117: $caller is optional (can be "submission", if routine is called when storing
12118: an upoaded file when "Submit Answer" button was pressed).
12119:
12120: Returns array containing $path and $multiresp.
12121: $path is path in portfolio. $multiresp is 1 if this resource contains more
12122: than one file upload item. Callers of routine should append partid as a
12123: subdirectory to $path in cases where $multiresp is 1.
12124:
12125: Called by: homework/essayresponse.pm and homework/structuretags.pm
12126:
12127: =cut
12128:
12129: sub get_turnedin_filepath {
12130: my ($symb,$uname,$udom,$caller) = @_;
12131: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12132: my $turnindir;
12133: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12134: $turnindir = $userhash{'turnindir'};
12135: my ($path,$multiresp);
12136: if ($turnindir eq '') {
12137: if ($caller eq 'submission') {
12138: $turnindir = &mt('turned in');
12139: $turnindir =~ s/\W+/_/g;
12140: my %newhash = (
12141: 'turnindir' => $turnindir,
12142: );
12143: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12144: }
12145: }
12146: if ($turnindir ne '') {
12147: $path = '/'.$turnindir.'/';
12148: my ($multipart,$turnin,@pathitems);
12149: my $navmap = Apache::lonnavmaps::navmap->new();
12150: if (defined($navmap)) {
12151: my $mapres = $navmap->getResourceByUrl($map);
12152: if (ref($mapres)) {
12153: my $pcslist = $mapres->map_hierarchy();
12154: if ($pcslist ne '') {
12155: foreach my $pc (split(/,/,$pcslist)) {
12156: my $res = $navmap->getByMapPc($pc);
12157: if (ref($res)) {
12158: my $title = $res->compTitle();
12159: $title =~ s/\W+/_/g;
12160: if ($title ne '') {
1.1075.2.48 raeburn 12161: if (($pc > 1) && (length($title) > 12)) {
12162: $title = substr($title,0,12);
12163: }
1.1015 raeburn 12164: push(@pathitems,$title);
12165: }
12166: }
12167: }
12168: }
12169: my $maptitle = $mapres->compTitle();
12170: $maptitle =~ s/\W+/_/g;
12171: if ($maptitle ne '') {
1.1075.2.48 raeburn 12172: if (length($maptitle) > 12) {
12173: $maptitle = substr($maptitle,0,12);
12174: }
1.1015 raeburn 12175: push(@pathitems,$maptitle);
12176: }
12177: unless ($env{'request.state'} eq 'construct') {
12178: my $res = $navmap->getBySymb($symb);
12179: if (ref($res)) {
12180: my $partlist = $res->parts();
12181: my $totaluploads = 0;
12182: if (ref($partlist) eq 'ARRAY') {
12183: foreach my $part (@{$partlist}) {
12184: my @types = $res->responseType($part);
12185: my @ids = $res->responseIds($part);
12186: for (my $i=0; $i < scalar(@ids); $i++) {
12187: if ($types[$i] eq 'essay') {
12188: my $partid = $part.'_'.$ids[$i];
12189: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12190: $totaluploads ++;
12191: }
12192: }
12193: }
12194: }
12195: if ($totaluploads > 1) {
12196: $multiresp = 1;
12197: }
12198: }
12199: }
12200: }
12201: } else {
12202: return;
12203: }
12204: } else {
12205: return;
12206: }
12207: my $restitle=&Apache::lonnet::gettitle($symb);
12208: $restitle =~ s/\W+/_/g;
12209: if ($restitle eq '') {
12210: $restitle = ($resurl =~ m{/[^/]+$});
12211: if ($restitle eq '') {
12212: $restitle = time;
12213: }
12214: }
1.1075.2.48 raeburn 12215: if (length($restitle) > 12) {
12216: $restitle = substr($restitle,0,12);
12217: }
1.1015 raeburn 12218: push(@pathitems,$restitle);
12219: $path .= join('/',@pathitems);
12220: }
12221: return ($path,$multiresp);
12222: }
12223:
12224: =pod
12225:
1.464 albertel 12226: =back
1.41 ng 12227:
1.112 bowersj2 12228: =head1 CSV Upload/Handling functions
1.38 albertel 12229:
1.41 ng 12230: =over 4
12231:
1.648 raeburn 12232: =item * &upfile_store($r)
1.41 ng 12233:
12234: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12235: needs $env{'form.upfile'}
1.41 ng 12236: returns $datatoken to be put into hidden field
12237:
12238: =cut
1.31 albertel 12239:
12240: sub upfile_store {
12241: my $r=shift;
1.258 albertel 12242: $env{'form.upfile'}=~s/\r/\n/gs;
12243: $env{'form.upfile'}=~s/\f/\n/gs;
12244: $env{'form.upfile'}=~s/\n+/\n/gs;
12245: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12246:
1.258 albertel 12247: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12248: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12249: {
1.158 raeburn 12250: my $datafile = $r->dir_config('lonDaemons').
12251: '/tmp/'.$datatoken.'.tmp';
12252: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12253: print $fh $env{'form.upfile'};
1.158 raeburn 12254: close($fh);
12255: }
1.31 albertel 12256: }
12257: return $datatoken;
12258: }
12259:
1.56 matthew 12260: =pod
12261:
1.648 raeburn 12262: =item * &load_tmp_file($r)
1.41 ng 12263:
12264: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12265: needs $env{'form.datatoken'},
12266: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12267:
12268: =cut
1.31 albertel 12269:
12270: sub load_tmp_file {
12271: my $r=shift;
12272: my @studentdata=();
12273: {
1.158 raeburn 12274: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12275: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12276: if ( open(my $fh,"<$studentfile") ) {
12277: @studentdata=<$fh>;
12278: close($fh);
12279: }
1.31 albertel 12280: }
1.258 albertel 12281: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12282: }
12283:
1.56 matthew 12284: =pod
12285:
1.648 raeburn 12286: =item * &upfile_record_sep()
1.41 ng 12287:
12288: Separate uploaded file into records
12289: returns array of records,
1.258 albertel 12290: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12291:
12292: =cut
1.31 albertel 12293:
12294: sub upfile_record_sep {
1.258 albertel 12295: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12296: } else {
1.248 albertel 12297: my @records;
1.258 albertel 12298: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12299: if ($line=~/^\s*$/) { next; }
12300: push(@records,$line);
12301: }
12302: return @records;
1.31 albertel 12303: }
12304: }
12305:
1.56 matthew 12306: =pod
12307:
1.648 raeburn 12308: =item * &record_sep($record)
1.41 ng 12309:
1.258 albertel 12310: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12311:
12312: =cut
12313:
1.263 www 12314: sub takeleft {
12315: my $index=shift;
12316: return substr('0000'.$index,-4,4);
12317: }
12318:
1.31 albertel 12319: sub record_sep {
12320: my $record=shift;
12321: my %components=();
1.258 albertel 12322: if ($env{'form.upfiletype'} eq 'xml') {
12323: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12324: my $i=0;
1.356 albertel 12325: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12326: $field=~s/^(\"|\')//;
12327: $field=~s/(\"|\')$//;
1.263 www 12328: $components{&takeleft($i)}=$field;
1.31 albertel 12329: $i++;
12330: }
1.258 albertel 12331: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12332: my $i=0;
1.356 albertel 12333: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12334: $field=~s/^(\"|\')//;
12335: $field=~s/(\"|\')$//;
1.263 www 12336: $components{&takeleft($i)}=$field;
1.31 albertel 12337: $i++;
12338: }
12339: } else {
1.561 www 12340: my $separator=',';
1.480 banghart 12341: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12342: $separator=';';
1.480 banghart 12343: }
1.31 albertel 12344: my $i=0;
1.561 www 12345: # the character we are looking for to indicate the end of a quote or a record
12346: my $looking_for=$separator;
12347: # do not add the characters to the fields
12348: my $ignore=0;
12349: # we just encountered a separator (or the beginning of the record)
12350: my $just_found_separator=1;
12351: # store the field we are working on here
12352: my $field='';
12353: # work our way through all characters in record
12354: foreach my $character ($record=~/(.)/g) {
12355: if ($character eq $looking_for) {
12356: if ($character ne $separator) {
12357: # Found the end of a quote, again looking for separator
12358: $looking_for=$separator;
12359: $ignore=1;
12360: } else {
12361: # Found a separator, store away what we got
12362: $components{&takeleft($i)}=$field;
12363: $i++;
12364: $just_found_separator=1;
12365: $ignore=0;
12366: $field='';
12367: }
12368: next;
12369: }
12370: # single or double quotation marks after a separator indicate beginning of a quote
12371: # we are now looking for the end of the quote and need to ignore separators
12372: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12373: $looking_for=$character;
12374: next;
12375: }
12376: # ignore would be true after we reached the end of a quote
12377: if ($ignore) { next; }
12378: if (($just_found_separator) && ($character=~/\s/)) { next; }
12379: $field.=$character;
12380: $just_found_separator=0;
1.31 albertel 12381: }
1.561 www 12382: # catch the very last entry, since we never encountered the separator
12383: $components{&takeleft($i)}=$field;
1.31 albertel 12384: }
12385: return %components;
12386: }
12387:
1.144 matthew 12388: ######################################################
12389: ######################################################
12390:
1.56 matthew 12391: =pod
12392:
1.648 raeburn 12393: =item * &upfile_select_html()
1.41 ng 12394:
1.144 matthew 12395: Return HTML code to select a file from the users machine and specify
12396: the file type.
1.41 ng 12397:
12398: =cut
12399:
1.144 matthew 12400: ######################################################
12401: ######################################################
1.31 albertel 12402: sub upfile_select_html {
1.144 matthew 12403: my %Types = (
12404: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12405: semisv => &mt('Semicolon separated values'),
1.144 matthew 12406: space => &mt('Space separated'),
12407: tab => &mt('Tabulator separated'),
12408: # xml => &mt('HTML/XML'),
12409: );
12410: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12411: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12412: foreach my $type (sort(keys(%Types))) {
12413: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12414: }
12415: $Str .= "</select>\n";
12416: return $Str;
1.31 albertel 12417: }
12418:
1.301 albertel 12419: sub get_samples {
12420: my ($records,$toget) = @_;
12421: my @samples=({});
12422: my $got=0;
12423: foreach my $rec (@$records) {
12424: my %temp = &record_sep($rec);
12425: if (! grep(/\S/, values(%temp))) { next; }
12426: if (%temp) {
12427: $samples[$got]=\%temp;
12428: $got++;
12429: if ($got == $toget) { last; }
12430: }
12431: }
12432: return \@samples;
12433: }
12434:
1.144 matthew 12435: ######################################################
12436: ######################################################
12437:
1.56 matthew 12438: =pod
12439:
1.648 raeburn 12440: =item * &csv_print_samples($r,$records)
1.41 ng 12441:
12442: Prints a table of sample values from each column uploaded $r is an
12443: Apache Request ref, $records is an arrayref from
12444: &Apache::loncommon::upfile_record_sep
12445:
12446: =cut
12447:
1.144 matthew 12448: ######################################################
12449: ######################################################
1.31 albertel 12450: sub csv_print_samples {
12451: my ($r,$records) = @_;
1.662 bisitz 12452: my $samples = &get_samples($records,5);
1.301 albertel 12453:
1.594 raeburn 12454: $r->print(&mt('Samples').'<br />'.&start_data_table().
12455: &start_data_table_header_row());
1.356 albertel 12456: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12457: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12458: $r->print(&end_data_table_header_row());
1.301 albertel 12459: foreach my $hash (@$samples) {
1.594 raeburn 12460: $r->print(&start_data_table_row());
1.356 albertel 12461: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12462: $r->print('<td>');
1.356 albertel 12463: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12464: $r->print('</td>');
12465: }
1.594 raeburn 12466: $r->print(&end_data_table_row());
1.31 albertel 12467: }
1.594 raeburn 12468: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12469: }
12470:
1.144 matthew 12471: ######################################################
12472: ######################################################
12473:
1.56 matthew 12474: =pod
12475:
1.648 raeburn 12476: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12477:
12478: Prints a table to create associations between values and table columns.
1.144 matthew 12479:
1.41 ng 12480: $r is an Apache Request ref,
12481: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12482: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12483:
12484: =cut
12485:
1.144 matthew 12486: ######################################################
12487: ######################################################
1.31 albertel 12488: sub csv_print_select_table {
12489: my ($r,$records,$d) = @_;
1.301 albertel 12490: my $i=0;
12491: my $samples = &get_samples($records,1);
1.144 matthew 12492: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12493: &start_data_table().&start_data_table_header_row().
1.144 matthew 12494: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12495: '<th>'.&mt('Column').'</th>'.
12496: &end_data_table_header_row()."\n");
1.356 albertel 12497: foreach my $array_ref (@$d) {
12498: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12499: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12500:
1.875 bisitz 12501: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12502: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12503: $r->print('<option value="none"></option>');
1.356 albertel 12504: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12505: $r->print('<option value="'.$sample.'"'.
12506: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12507: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12508: }
1.594 raeburn 12509: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12510: $i++;
12511: }
1.594 raeburn 12512: $r->print(&end_data_table());
1.31 albertel 12513: $i--;
12514: return $i;
12515: }
1.56 matthew 12516:
1.144 matthew 12517: ######################################################
12518: ######################################################
12519:
1.56 matthew 12520: =pod
1.31 albertel 12521:
1.648 raeburn 12522: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12523:
12524: Prints a table of sample values from the upload and can make associate samples to internal names.
12525:
12526: $r is an Apache Request ref,
12527: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12528: $d is an array of 2 element arrays (internal name, displayed name)
12529:
12530: =cut
12531:
1.144 matthew 12532: ######################################################
12533: ######################################################
1.31 albertel 12534: sub csv_samples_select_table {
12535: my ($r,$records,$d) = @_;
12536: my $i=0;
1.144 matthew 12537: #
1.662 bisitz 12538: my $max_samples = 5;
12539: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12540: $r->print(&start_data_table().
12541: &start_data_table_header_row().'<th>'.
12542: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12543: &end_data_table_header_row());
1.301 albertel 12544:
12545: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12546: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12547: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12548: foreach my $option (@$d) {
12549: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12550: $r->print('<option value="'.$value.'"'.
1.253 albertel 12551: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12552: $display.'</option>');
1.31 albertel 12553: }
12554: $r->print('</select></td><td>');
1.662 bisitz 12555: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12556: if (defined($samples->[$line]{$key})) {
12557: $r->print($samples->[$line]{$key}."<br />\n");
12558: }
12559: }
1.594 raeburn 12560: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12561: $i++;
12562: }
1.594 raeburn 12563: $r->print(&end_data_table());
1.31 albertel 12564: $i--;
12565: return($i);
1.115 matthew 12566: }
12567:
1.144 matthew 12568: ######################################################
12569: ######################################################
12570:
1.115 matthew 12571: =pod
12572:
1.648 raeburn 12573: =item * &clean_excel_name($name)
1.115 matthew 12574:
12575: Returns a replacement for $name which does not contain any illegal characters.
12576:
12577: =cut
12578:
1.144 matthew 12579: ######################################################
12580: ######################################################
1.115 matthew 12581: sub clean_excel_name {
12582: my ($name) = @_;
12583: $name =~ s/[:\*\?\/\\]//g;
12584: if (length($name) > 31) {
12585: $name = substr($name,0,31);
12586: }
12587: return $name;
1.25 albertel 12588: }
1.84 albertel 12589:
1.85 albertel 12590: =pod
12591:
1.648 raeburn 12592: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12593:
12594: Returns either 1 or undef
12595:
12596: 1 if the part is to be hidden, undef if it is to be shown
12597:
12598: Arguments are:
12599:
12600: $id the id of the part to be checked
12601: $symb, optional the symb of the resource to check
12602: $udom, optional the domain of the user to check for
12603: $uname, optional the username of the user to check for
12604:
12605: =cut
1.84 albertel 12606:
12607: sub check_if_partid_hidden {
12608: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12609: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12610: $symb,$udom,$uname);
1.141 albertel 12611: my $truth=1;
12612: #if the string starts with !, then the list is the list to show not hide
12613: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12614: my @hiddenlist=split(/,/,$hiddenparts);
12615: foreach my $checkid (@hiddenlist) {
1.141 albertel 12616: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12617: }
1.141 albertel 12618: return !$truth;
1.84 albertel 12619: }
1.127 matthew 12620:
1.138 matthew 12621:
12622: ############################################################
12623: ############################################################
12624:
12625: =pod
12626:
1.157 matthew 12627: =back
12628:
1.138 matthew 12629: =head1 cgi-bin script and graphing routines
12630:
1.157 matthew 12631: =over 4
12632:
1.648 raeburn 12633: =item * &get_cgi_id()
1.138 matthew 12634:
12635: Inputs: none
12636:
12637: Returns an id which can be used to pass environment variables
12638: to various cgi-bin scripts. These environment variables will
12639: be removed from the users environment after a given time by
12640: the routine &Apache::lonnet::transfer_profile_to_env.
12641:
12642: =cut
12643:
12644: ############################################################
12645: ############################################################
1.152 albertel 12646: my $uniq=0;
1.136 matthew 12647: sub get_cgi_id {
1.154 albertel 12648: $uniq=($uniq+1)%100000;
1.280 albertel 12649: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12650: }
12651:
1.127 matthew 12652: ############################################################
12653: ############################################################
12654:
12655: =pod
12656:
1.648 raeburn 12657: =item * &DrawBarGraph()
1.127 matthew 12658:
1.138 matthew 12659: Facilitates the plotting of data in a (stacked) bar graph.
12660: Puts plot definition data into the users environment in order for
12661: graph.png to plot it. Returns an <img> tag for the plot.
12662: The bars on the plot are labeled '1','2',...,'n'.
12663:
12664: Inputs:
12665:
12666: =over 4
12667:
12668: =item $Title: string, the title of the plot
12669:
12670: =item $xlabel: string, text describing the X-axis of the plot
12671:
12672: =item $ylabel: string, text describing the Y-axis of the plot
12673:
12674: =item $Max: scalar, the maximum Y value to use in the plot
12675: If $Max is < any data point, the graph will not be rendered.
12676:
1.140 matthew 12677: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12678: they are plotted. If undefined, default values will be used.
12679:
1.178 matthew 12680: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12681:
1.138 matthew 12682: =item @Values: An array of array references. Each array reference holds data
12683: to be plotted in a stacked bar chart.
12684:
1.239 matthew 12685: =item If the final element of @Values is a hash reference the key/value
12686: pairs will be added to the graph definition.
12687:
1.138 matthew 12688: =back
12689:
12690: Returns:
12691:
12692: An <img> tag which references graph.png and the appropriate identifying
12693: information for the plot.
12694:
1.127 matthew 12695: =cut
12696:
12697: ############################################################
12698: ############################################################
1.134 matthew 12699: sub DrawBarGraph {
1.178 matthew 12700: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12701: #
12702: if (! defined($colors)) {
12703: $colors = ['#33ff00',
12704: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12705: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12706: ];
12707: }
1.228 matthew 12708: my $extra_settings = {};
12709: if (ref($Values[-1]) eq 'HASH') {
12710: $extra_settings = pop(@Values);
12711: }
1.127 matthew 12712: #
1.136 matthew 12713: my $identifier = &get_cgi_id();
12714: my $id = 'cgi.'.$identifier;
1.129 matthew 12715: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12716: return '';
12717: }
1.225 matthew 12718: #
12719: my @Labels;
12720: if (defined($labels)) {
12721: @Labels = @$labels;
12722: } else {
12723: for (my $i=0;$i<@{$Values[0]};$i++) {
12724: push (@Labels,$i+1);
12725: }
12726: }
12727: #
1.129 matthew 12728: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12729: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12730: my %ValuesHash;
12731: my $NumSets=1;
12732: foreach my $array (@Values) {
12733: next if (! ref($array));
1.136 matthew 12734: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12735: join(',',@$array);
1.129 matthew 12736: }
1.127 matthew 12737: #
1.136 matthew 12738: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12739: if ($NumBars < 3) {
12740: $width = 120+$NumBars*32;
1.220 matthew 12741: $xskip = 1;
1.225 matthew 12742: $bar_width = 30;
12743: } elsif ($NumBars < 5) {
12744: $width = 120+$NumBars*20;
12745: $xskip = 1;
12746: $bar_width = 20;
1.220 matthew 12747: } elsif ($NumBars < 10) {
1.136 matthew 12748: $width = 120+$NumBars*15;
12749: $xskip = 1;
12750: $bar_width = 15;
12751: } elsif ($NumBars <= 25) {
12752: $width = 120+$NumBars*11;
12753: $xskip = 5;
12754: $bar_width = 8;
12755: } elsif ($NumBars <= 50) {
12756: $width = 120+$NumBars*8;
12757: $xskip = 5;
12758: $bar_width = 4;
12759: } else {
12760: $width = 120+$NumBars*8;
12761: $xskip = 5;
12762: $bar_width = 4;
12763: }
12764: #
1.137 matthew 12765: $Max = 1 if ($Max < 1);
12766: if ( int($Max) < $Max ) {
12767: $Max++;
12768: $Max = int($Max);
12769: }
1.127 matthew 12770: $Title = '' if (! defined($Title));
12771: $xlabel = '' if (! defined($xlabel));
12772: $ylabel = '' if (! defined($ylabel));
1.369 www 12773: $ValuesHash{$id.'.title'} = &escape($Title);
12774: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12775: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12776: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12777: $ValuesHash{$id.'.NumBars'} = $NumBars;
12778: $ValuesHash{$id.'.NumSets'} = $NumSets;
12779: $ValuesHash{$id.'.PlotType'} = 'bar';
12780: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12781: $ValuesHash{$id.'.height'} = $height;
12782: $ValuesHash{$id.'.width'} = $width;
12783: $ValuesHash{$id.'.xskip'} = $xskip;
12784: $ValuesHash{$id.'.bar_width'} = $bar_width;
12785: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12786: #
1.228 matthew 12787: # Deal with other parameters
12788: while (my ($key,$value) = each(%$extra_settings)) {
12789: $ValuesHash{$id.'.'.$key} = $value;
12790: }
12791: #
1.646 raeburn 12792: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12793: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12794: }
12795:
12796: ############################################################
12797: ############################################################
12798:
12799: =pod
12800:
1.648 raeburn 12801: =item * &DrawXYGraph()
1.137 matthew 12802:
1.138 matthew 12803: Facilitates the plotting of data in an XY graph.
12804: Puts plot definition data into the users environment in order for
12805: graph.png to plot it. Returns an <img> tag for the plot.
12806:
12807: Inputs:
12808:
12809: =over 4
12810:
12811: =item $Title: string, the title of the plot
12812:
12813: =item $xlabel: string, text describing the X-axis of the plot
12814:
12815: =item $ylabel: string, text describing the Y-axis of the plot
12816:
12817: =item $Max: scalar, the maximum Y value to use in the plot
12818: If $Max is < any data point, the graph will not be rendered.
12819:
12820: =item $colors: Array ref containing the hex color codes for the data to be
12821: plotted in. If undefined, default values will be used.
12822:
12823: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12824:
12825: =item $Ydata: Array ref containing Array refs.
1.185 www 12826: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12827:
12828: =item %Values: hash indicating or overriding any default values which are
12829: passed to graph.png.
12830: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12831:
12832: =back
12833:
12834: Returns:
12835:
12836: An <img> tag which references graph.png and the appropriate identifying
12837: information for the plot.
12838:
1.137 matthew 12839: =cut
12840:
12841: ############################################################
12842: ############################################################
12843: sub DrawXYGraph {
12844: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12845: #
12846: # Create the identifier for the graph
12847: my $identifier = &get_cgi_id();
12848: my $id = 'cgi.'.$identifier;
12849: #
12850: $Title = '' if (! defined($Title));
12851: $xlabel = '' if (! defined($xlabel));
12852: $ylabel = '' if (! defined($ylabel));
12853: my %ValuesHash =
12854: (
1.369 www 12855: $id.'.title' => &escape($Title),
12856: $id.'.xlabel' => &escape($xlabel),
12857: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12858: $id.'.y_max_value'=> $Max,
12859: $id.'.labels' => join(',',@$Xlabels),
12860: $id.'.PlotType' => 'XY',
12861: );
12862: #
12863: if (defined($colors) && ref($colors) eq 'ARRAY') {
12864: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12865: }
12866: #
12867: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12868: return '';
12869: }
12870: my $NumSets=1;
1.138 matthew 12871: foreach my $array (@{$Ydata}){
1.137 matthew 12872: next if (! ref($array));
12873: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12874: }
1.138 matthew 12875: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12876: #
12877: # Deal with other parameters
12878: while (my ($key,$value) = each(%Values)) {
12879: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12880: }
12881: #
1.646 raeburn 12882: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12883: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12884: }
12885:
12886: ############################################################
12887: ############################################################
12888:
12889: =pod
12890:
1.648 raeburn 12891: =item * &DrawXYYGraph()
1.138 matthew 12892:
12893: Facilitates the plotting of data in an XY graph with two Y axes.
12894: Puts plot definition data into the users environment in order for
12895: graph.png to plot it. Returns an <img> tag for the plot.
12896:
12897: Inputs:
12898:
12899: =over 4
12900:
12901: =item $Title: string, the title of the plot
12902:
12903: =item $xlabel: string, text describing the X-axis of the plot
12904:
12905: =item $ylabel: string, text describing the Y-axis of the plot
12906:
12907: =item $colors: Array ref containing the hex color codes for the data to be
12908: plotted in. If undefined, default values will be used.
12909:
12910: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12911:
12912: =item $Ydata1: The first data set
12913:
12914: =item $Min1: The minimum value of the left Y-axis
12915:
12916: =item $Max1: The maximum value of the left Y-axis
12917:
12918: =item $Ydata2: The second data set
12919:
12920: =item $Min2: The minimum value of the right Y-axis
12921:
12922: =item $Max2: The maximum value of the left Y-axis
12923:
12924: =item %Values: hash indicating or overriding any default values which are
12925: passed to graph.png.
12926: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12927:
12928: =back
12929:
12930: Returns:
12931:
12932: An <img> tag which references graph.png and the appropriate identifying
12933: information for the plot.
1.136 matthew 12934:
12935: =cut
12936:
12937: ############################################################
12938: ############################################################
1.137 matthew 12939: sub DrawXYYGraph {
12940: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12941: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12942: #
12943: # Create the identifier for the graph
12944: my $identifier = &get_cgi_id();
12945: my $id = 'cgi.'.$identifier;
12946: #
12947: $Title = '' if (! defined($Title));
12948: $xlabel = '' if (! defined($xlabel));
12949: $ylabel = '' if (! defined($ylabel));
12950: my %ValuesHash =
12951: (
1.369 www 12952: $id.'.title' => &escape($Title),
12953: $id.'.xlabel' => &escape($xlabel),
12954: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 12955: $id.'.labels' => join(',',@$Xlabels),
12956: $id.'.PlotType' => 'XY',
12957: $id.'.NumSets' => 2,
1.137 matthew 12958: $id.'.two_axes' => 1,
12959: $id.'.y1_max_value' => $Max1,
12960: $id.'.y1_min_value' => $Min1,
12961: $id.'.y2_max_value' => $Max2,
12962: $id.'.y2_min_value' => $Min2,
1.136 matthew 12963: );
12964: #
1.137 matthew 12965: if (defined($colors) && ref($colors) eq 'ARRAY') {
12966: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12967: }
12968: #
12969: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
12970: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 12971: return '';
12972: }
12973: my $NumSets=1;
1.137 matthew 12974: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 12975: next if (! ref($array));
12976: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 12977: }
12978: #
12979: # Deal with other parameters
12980: while (my ($key,$value) = each(%Values)) {
12981: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 12982: }
12983: #
1.646 raeburn 12984: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 12985: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 12986: }
12987:
12988: ############################################################
12989: ############################################################
12990:
12991: =pod
12992:
1.157 matthew 12993: =back
12994:
1.139 matthew 12995: =head1 Statistics helper routines?
12996:
12997: Bad place for them but what the hell.
12998:
1.157 matthew 12999: =over 4
13000:
1.648 raeburn 13001: =item * &chartlink()
1.139 matthew 13002:
13003: Returns a link to the chart for a specific student.
13004:
13005: Inputs:
13006:
13007: =over 4
13008:
13009: =item $linktext: The text of the link
13010:
13011: =item $sname: The students username
13012:
13013: =item $sdomain: The students domain
13014:
13015: =back
13016:
1.157 matthew 13017: =back
13018:
1.139 matthew 13019: =cut
13020:
13021: ############################################################
13022: ############################################################
13023: sub chartlink {
13024: my ($linktext, $sname, $sdomain) = @_;
13025: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13026: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13027: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13028: '">'.$linktext.'</a>';
1.153 matthew 13029: }
13030:
13031: #######################################################
13032: #######################################################
13033:
13034: =pod
13035:
13036: =head1 Course Environment Routines
1.157 matthew 13037:
13038: =over 4
1.153 matthew 13039:
1.648 raeburn 13040: =item * &restore_course_settings()
1.153 matthew 13041:
1.648 raeburn 13042: =item * &store_course_settings()
1.153 matthew 13043:
13044: Restores/Store indicated form parameters from the course environment.
13045: Will not overwrite existing values of the form parameters.
13046:
13047: Inputs:
13048: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13049:
13050: a hash ref describing the data to be stored. For example:
13051:
13052: %Save_Parameters = ('Status' => 'scalar',
13053: 'chartoutputmode' => 'scalar',
13054: 'chartoutputdata' => 'scalar',
13055: 'Section' => 'array',
1.373 raeburn 13056: 'Group' => 'array',
1.153 matthew 13057: 'StudentData' => 'array',
13058: 'Maps' => 'array');
13059:
13060: Returns: both routines return nothing
13061:
1.631 raeburn 13062: =back
13063:
1.153 matthew 13064: =cut
13065:
13066: #######################################################
13067: #######################################################
13068: sub store_course_settings {
1.496 albertel 13069: return &store_settings($env{'request.course.id'},@_);
13070: }
13071:
13072: sub store_settings {
1.153 matthew 13073: # save to the environment
13074: # appenv the same items, just to be safe
1.300 albertel 13075: my $udom = $env{'user.domain'};
13076: my $uname = $env{'user.name'};
1.496 albertel 13077: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13078: my %SaveHash;
13079: my %AppHash;
13080: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13081: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13082: my $envname = 'environment.'.$basename;
1.258 albertel 13083: if (exists($env{'form.'.$setting})) {
1.153 matthew 13084: # Save this value away
13085: if ($type eq 'scalar' &&
1.258 albertel 13086: (! exists($env{$envname}) ||
13087: $env{$envname} ne $env{'form.'.$setting})) {
13088: $SaveHash{$basename} = $env{'form.'.$setting};
13089: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13090: } elsif ($type eq 'array') {
13091: my $stored_form;
1.258 albertel 13092: if (ref($env{'form.'.$setting})) {
1.153 matthew 13093: $stored_form = join(',',
13094: map {
1.369 www 13095: &escape($_);
1.258 albertel 13096: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13097: } else {
13098: $stored_form =
1.369 www 13099: &escape($env{'form.'.$setting});
1.153 matthew 13100: }
13101: # Determine if the array contents are the same.
1.258 albertel 13102: if ($stored_form ne $env{$envname}) {
1.153 matthew 13103: $SaveHash{$basename} = $stored_form;
13104: $AppHash{$envname} = $stored_form;
13105: }
13106: }
13107: }
13108: }
13109: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13110: $udom,$uname);
1.153 matthew 13111: if ($put_result !~ /^(ok|delayed)/) {
13112: &Apache::lonnet::logthis('unable to save form parameters, '.
13113: 'got error:'.$put_result);
13114: }
13115: # Make sure these settings stick around in this session, too
1.646 raeburn 13116: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13117: return;
13118: }
13119:
13120: sub restore_course_settings {
1.499 albertel 13121: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13122: }
13123:
13124: sub restore_settings {
13125: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13126: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13127: next if (exists($env{'form.'.$setting}));
1.496 albertel 13128: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13129: '.'.$setting;
1.258 albertel 13130: if (exists($env{$envname})) {
1.153 matthew 13131: if ($type eq 'scalar') {
1.258 albertel 13132: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13133: } elsif ($type eq 'array') {
1.258 albertel 13134: $env{'form.'.$setting} = [
1.153 matthew 13135: map {
1.369 www 13136: &unescape($_);
1.258 albertel 13137: } split(',',$env{$envname})
1.153 matthew 13138: ];
13139: }
13140: }
13141: }
1.127 matthew 13142: }
13143:
1.618 raeburn 13144: #######################################################
13145: #######################################################
13146:
13147: =pod
13148:
13149: =head1 Domain E-mail Routines
13150:
13151: =over 4
13152:
1.648 raeburn 13153: =item * &build_recipient_list()
1.618 raeburn 13154:
1.1075.2.44 raeburn 13155: Build recipient lists for following types of e-mail:
1.766 raeburn 13156: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13157: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13158: module change checking, student/employee ID conflict checks, as
13159: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13160: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13161:
13162: Inputs:
1.1075.2.44 raeburn 13163: defmail (scalar - email address of default recipient),
13164: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13165: requestsmail, updatesmail, or idconflictsmail).
13166:
1.619 raeburn 13167: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13168:
13169: origmail (scalar - email address of recipient from loncapa.conf,
13170: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13171:
1.655 raeburn 13172: Returns: comma separated list of addresses to which to send e-mail.
13173:
13174: =back
1.618 raeburn 13175:
13176: =cut
13177:
13178: ############################################################
13179: ############################################################
13180: sub build_recipient_list {
1.619 raeburn 13181: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13182: my @recipients;
13183: my $otheremails;
13184: my %domconfig =
13185: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13186: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13187: if (exists($domconfig{'contacts'}{$mailing})) {
13188: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13189: my @contacts = ('adminemail','supportemail');
13190: foreach my $item (@contacts) {
13191: if ($domconfig{'contacts'}{$mailing}{$item}) {
13192: my $addr = $domconfig{'contacts'}{$item};
13193: if (!grep(/^\Q$addr\E$/,@recipients)) {
13194: push(@recipients,$addr);
13195: }
1.619 raeburn 13196: }
1.766 raeburn 13197: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13198: }
13199: }
1.766 raeburn 13200: } elsif ($origmail ne '') {
13201: push(@recipients,$origmail);
1.618 raeburn 13202: }
1.619 raeburn 13203: } elsif ($origmail ne '') {
13204: push(@recipients,$origmail);
1.618 raeburn 13205: }
1.688 raeburn 13206: if (defined($defmail)) {
13207: if ($defmail ne '') {
13208: push(@recipients,$defmail);
13209: }
1.618 raeburn 13210: }
13211: if ($otheremails) {
1.619 raeburn 13212: my @others;
13213: if ($otheremails =~ /,/) {
13214: @others = split(/,/,$otheremails);
1.618 raeburn 13215: } else {
1.619 raeburn 13216: push(@others,$otheremails);
13217: }
13218: foreach my $addr (@others) {
13219: if (!grep(/^\Q$addr\E$/,@recipients)) {
13220: push(@recipients,$addr);
13221: }
1.618 raeburn 13222: }
13223: }
1.619 raeburn 13224: my $recipientlist = join(',',@recipients);
1.618 raeburn 13225: return $recipientlist;
13226: }
13227:
1.127 matthew 13228: ############################################################
13229: ############################################################
1.154 albertel 13230:
1.655 raeburn 13231: =pod
13232:
13233: =head1 Course Catalog Routines
13234:
13235: =over 4
13236:
13237: =item * &gather_categories()
13238:
13239: Converts category definitions - keys of categories hash stored in
13240: coursecategories in configuration.db on the primary library server in a
13241: domain - to an array. Also generates javascript and idx hash used to
13242: generate Domain Coordinator interface for editing Course Categories.
13243:
13244: Inputs:
1.663 raeburn 13245:
1.655 raeburn 13246: categories (reference to hash of category definitions).
1.663 raeburn 13247:
1.655 raeburn 13248: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13249: categories and subcategories).
1.663 raeburn 13250:
1.655 raeburn 13251: idx (reference to hash of counters used in Domain Coordinator interface for
13252: editing Course Categories).
1.663 raeburn 13253:
1.655 raeburn 13254: jsarray (reference to array of categories used to create Javascript arrays for
13255: Domain Coordinator interface for editing Course Categories).
13256:
13257: Returns: nothing
13258:
13259: Side effects: populates cats, idx and jsarray.
13260:
13261: =cut
13262:
13263: sub gather_categories {
13264: my ($categories,$cats,$idx,$jsarray) = @_;
13265: my %counters;
13266: my $num = 0;
13267: foreach my $item (keys(%{$categories})) {
13268: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13269: if ($container eq '' && $depth == 0) {
13270: $cats->[$depth][$categories->{$item}] = $cat;
13271: } else {
13272: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13273: }
13274: my ($escitem,$tail) = split(/:/,$item,2);
13275: if ($counters{$tail} eq '') {
13276: $counters{$tail} = $num;
13277: $num ++;
13278: }
13279: if (ref($idx) eq 'HASH') {
13280: $idx->{$item} = $counters{$tail};
13281: }
13282: if (ref($jsarray) eq 'ARRAY') {
13283: push(@{$jsarray->[$counters{$tail}]},$item);
13284: }
13285: }
13286: return;
13287: }
13288:
13289: =pod
13290:
13291: =item * &extract_categories()
13292:
13293: Used to generate breadcrumb trails for course categories.
13294:
13295: Inputs:
1.663 raeburn 13296:
1.655 raeburn 13297: categories (reference to hash of category definitions).
1.663 raeburn 13298:
1.655 raeburn 13299: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13300: categories and subcategories).
1.663 raeburn 13301:
1.655 raeburn 13302: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13303:
1.655 raeburn 13304: allitems (reference to hash - key is category key
13305: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13306:
1.655 raeburn 13307: idx (reference to hash of counters used in Domain Coordinator interface for
13308: editing Course Categories).
1.663 raeburn 13309:
1.655 raeburn 13310: jsarray (reference to array of categories used to create Javascript arrays for
13311: Domain Coordinator interface for editing Course Categories).
13312:
1.665 raeburn 13313: subcats (reference to hash of arrays containing all subcategories within each
13314: category, -recursive)
13315:
1.655 raeburn 13316: Returns: nothing
13317:
13318: Side effects: populates trails and allitems hash references.
13319:
13320: =cut
13321:
13322: sub extract_categories {
1.665 raeburn 13323: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13324: if (ref($categories) eq 'HASH') {
13325: &gather_categories($categories,$cats,$idx,$jsarray);
13326: if (ref($cats->[0]) eq 'ARRAY') {
13327: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13328: my $name = $cats->[0][$i];
13329: my $item = &escape($name).'::0';
13330: my $trailstr;
13331: if ($name eq 'instcode') {
13332: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13333: } elsif ($name eq 'communities') {
13334: $trailstr = &mt('Communities');
1.655 raeburn 13335: } else {
13336: $trailstr = $name;
13337: }
13338: if ($allitems->{$item} eq '') {
13339: push(@{$trails},$trailstr);
13340: $allitems->{$item} = scalar(@{$trails})-1;
13341: }
13342: my @parents = ($name);
13343: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13344: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13345: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13346: if (ref($subcats) eq 'HASH') {
13347: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13348: }
13349: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13350: }
13351: } else {
13352: if (ref($subcats) eq 'HASH') {
13353: $subcats->{$item} = [];
1.655 raeburn 13354: }
13355: }
13356: }
13357: }
13358: }
13359: return;
13360: }
13361:
13362: =pod
13363:
13364: =item *&recurse_categories()
13365:
13366: Recursively used to generate breadcrumb trails for course categories.
13367:
13368: Inputs:
1.663 raeburn 13369:
1.655 raeburn 13370: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13371: categories and subcategories).
1.663 raeburn 13372:
1.655 raeburn 13373: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13374:
13375: category (current course category, for which breadcrumb trail is being generated).
13376:
13377: trails (reference to array of breadcrumb trails for each category).
13378:
1.655 raeburn 13379: allitems (reference to hash - key is category key
13380: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13381:
1.655 raeburn 13382: parents (array containing containers directories for current category,
13383: back to top level).
13384:
13385: Returns: nothing
13386:
13387: Side effects: populates trails and allitems hash references
13388:
13389: =cut
13390:
13391: sub recurse_categories {
1.665 raeburn 13392: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13393: my $shallower = $depth - 1;
13394: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13395: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13396: my $name = $cats->[$depth]{$category}[$k];
13397: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13398: my $trailstr = join(' -> ',(@{$parents},$category));
13399: if ($allitems->{$item} eq '') {
13400: push(@{$trails},$trailstr);
13401: $allitems->{$item} = scalar(@{$trails})-1;
13402: }
13403: my $deeper = $depth+1;
13404: push(@{$parents},$category);
1.665 raeburn 13405: if (ref($subcats) eq 'HASH') {
13406: my $subcat = &escape($name).':'.$category.':'.$depth;
13407: for (my $j=@{$parents}; $j>=0; $j--) {
13408: my $higher;
13409: if ($j > 0) {
13410: $higher = &escape($parents->[$j]).':'.
13411: &escape($parents->[$j-1]).':'.$j;
13412: } else {
13413: $higher = &escape($parents->[$j]).'::'.$j;
13414: }
13415: push(@{$subcats->{$higher}},$subcat);
13416: }
13417: }
13418: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13419: $subcats);
1.655 raeburn 13420: pop(@{$parents});
13421: }
13422: } else {
13423: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13424: my $trailstr = join(' -> ',(@{$parents},$category));
13425: if ($allitems->{$item} eq '') {
13426: push(@{$trails},$trailstr);
13427: $allitems->{$item} = scalar(@{$trails})-1;
13428: }
13429: }
13430: return;
13431: }
13432:
1.663 raeburn 13433: =pod
13434:
13435: =item *&assign_categories_table()
13436:
13437: Create a datatable for display of hierarchical categories in a domain,
13438: with checkboxes to allow a course to be categorized.
13439:
13440: Inputs:
13441:
13442: cathash - reference to hash of categories defined for the domain (from
13443: configuration.db)
13444:
13445: currcat - scalar with an & separated list of categories assigned to a course.
13446:
1.919 raeburn 13447: type - scalar contains course type (Course or Community).
13448:
1.663 raeburn 13449: Returns: $output (markup to be displayed)
13450:
13451: =cut
13452:
13453: sub assign_categories_table {
1.919 raeburn 13454: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13455: my $output;
13456: if (ref($cathash) eq 'HASH') {
13457: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13458: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13459: $maxdepth = scalar(@cats);
13460: if (@cats > 0) {
13461: my $itemcount = 0;
13462: if (ref($cats[0]) eq 'ARRAY') {
13463: my @currcategories;
13464: if ($currcat ne '') {
13465: @currcategories = split('&',$currcat);
13466: }
1.919 raeburn 13467: my $table;
1.663 raeburn 13468: for (my $i=0; $i<@{$cats[0]}; $i++) {
13469: my $parent = $cats[0][$i];
1.919 raeburn 13470: next if ($parent eq 'instcode');
13471: if ($type eq 'Community') {
13472: next unless ($parent eq 'communities');
13473: } else {
13474: next if ($parent eq 'communities');
13475: }
1.663 raeburn 13476: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13477: my $item = &escape($parent).'::0';
13478: my $checked = '';
13479: if (@currcategories > 0) {
13480: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13481: $checked = ' checked="checked"';
1.663 raeburn 13482: }
13483: }
1.919 raeburn 13484: my $parent_title = $parent;
13485: if ($parent eq 'communities') {
13486: $parent_title = &mt('Communities');
13487: }
13488: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13489: '<input type="checkbox" name="usecategory" value="'.
13490: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13491: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13492: my $depth = 1;
13493: push(@path,$parent);
1.919 raeburn 13494: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13495: pop(@path);
1.919 raeburn 13496: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13497: $itemcount ++;
13498: }
1.919 raeburn 13499: if ($itemcount) {
13500: $output = &Apache::loncommon::start_data_table().
13501: $table.
13502: &Apache::loncommon::end_data_table();
13503: }
1.663 raeburn 13504: }
13505: }
13506: }
13507: return $output;
13508: }
13509:
13510: =pod
13511:
13512: =item *&assign_category_rows()
13513:
13514: Create a datatable row for display of nested categories in a domain,
13515: with checkboxes to allow a course to be categorized,called recursively.
13516:
13517: Inputs:
13518:
13519: itemcount - track row number for alternating colors
13520:
13521: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13522: categories and subcategories.
13523:
13524: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13525:
13526: parent - parent of current category item
13527:
13528: path - Array containing all categories back up through the hierarchy from the
13529: current category to the top level.
13530:
13531: currcategories - reference to array of current categories assigned to the course
13532:
13533: Returns: $output (markup to be displayed).
13534:
13535: =cut
13536:
13537: sub assign_category_rows {
13538: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13539: my ($text,$name,$item,$chgstr);
13540: if (ref($cats) eq 'ARRAY') {
13541: my $maxdepth = scalar(@{$cats});
13542: if (ref($cats->[$depth]) eq 'HASH') {
13543: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13544: my $numchildren = @{$cats->[$depth]{$parent}};
13545: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 13546: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13547: for (my $j=0; $j<$numchildren; $j++) {
13548: $name = $cats->[$depth]{$parent}[$j];
13549: $item = &escape($name).':'.&escape($parent).':'.$depth;
13550: my $deeper = $depth+1;
13551: my $checked = '';
13552: if (ref($currcategories) eq 'ARRAY') {
13553: if (@{$currcategories} > 0) {
13554: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13555: $checked = ' checked="checked"';
1.663 raeburn 13556: }
13557: }
13558: }
1.664 raeburn 13559: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13560: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13561: $item.'"'.$checked.' />'.$name.'</label></span>'.
13562: '<input type="hidden" name="catname" value="'.$name.'" />'.
13563: '</td><td>';
1.663 raeburn 13564: if (ref($path) eq 'ARRAY') {
13565: push(@{$path},$name);
13566: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13567: pop(@{$path});
13568: }
13569: $text .= '</td></tr>';
13570: }
13571: $text .= '</table></td>';
13572: }
13573: }
13574: }
13575: return $text;
13576: }
13577:
1.655 raeburn 13578: ############################################################
13579: ############################################################
13580:
13581:
1.443 albertel 13582: sub commit_customrole {
1.664 raeburn 13583: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13584: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13585: ($start?', '.&mt('starting').' '.localtime($start):'').
13586: ($end?', ending '.localtime($end):'').': <b>'.
13587: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13588: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13589: '</b><br />';
13590: return $output;
13591: }
13592:
13593: sub commit_standardrole {
1.1075.2.31 raeburn 13594: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13595: my ($output,$logmsg,$linefeed);
13596: if ($context eq 'auto') {
13597: $linefeed = "\n";
13598: } else {
13599: $linefeed = "<br />\n";
13600: }
1.443 albertel 13601: if ($three eq 'st') {
1.541 raeburn 13602: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 13603: $one,$two,$sec,$context,$credits);
1.541 raeburn 13604: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13605: ($result eq 'unknown_course') || ($result eq 'refused')) {
13606: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13607: } else {
1.541 raeburn 13608: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13609: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13610: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13611: if ($context eq 'auto') {
13612: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13613: } else {
13614: $output .= '<b>'.$result.'</b>'.$linefeed.
13615: &mt('Add to classlist').': <b>ok</b>';
13616: }
13617: $output .= $linefeed;
1.443 albertel 13618: }
13619: } else {
13620: $output = &mt('Assigning').' '.$three.' in '.$url.
13621: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13622: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13623: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13624: if ($context eq 'auto') {
13625: $output .= $result.$linefeed;
13626: } else {
13627: $output .= '<b>'.$result.'</b>'.$linefeed;
13628: }
1.443 albertel 13629: }
13630: return $output;
13631: }
13632:
13633: sub commit_studentrole {
1.1075.2.31 raeburn 13634: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13635: $credits) = @_;
1.626 raeburn 13636: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13637: if ($context eq 'auto') {
13638: $linefeed = "\n";
13639: } else {
13640: $linefeed = '<br />'."\n";
13641: }
1.443 albertel 13642: if (defined($one) && defined($two)) {
13643: my $cid=$one.'_'.$two;
13644: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13645: my $secchange = 0;
13646: my $expire_role_result;
13647: my $modify_section_result;
1.628 raeburn 13648: if ($oldsec ne '-1') {
13649: if ($oldsec ne $sec) {
1.443 albertel 13650: $secchange = 1;
1.628 raeburn 13651: my $now = time;
1.443 albertel 13652: my $uurl='/'.$cid;
13653: $uurl=~s/\_/\//g;
13654: if ($oldsec) {
13655: $uurl.='/'.$oldsec;
13656: }
1.626 raeburn 13657: $oldsecurl = $uurl;
1.628 raeburn 13658: $expire_role_result =
1.652 raeburn 13659: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13660: if ($env{'request.course.sec'} ne '') {
13661: if ($expire_role_result eq 'refused') {
13662: my @roles = ('st');
13663: my @statuses = ('previous');
13664: my @roledoms = ($one);
13665: my $withsec = 1;
13666: my %roleshash =
13667: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13668: \@statuses,\@roles,\@roledoms,$withsec);
13669: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13670: my ($oldstart,$oldend) =
13671: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13672: if ($oldend > 0 && $oldend <= $now) {
13673: $expire_role_result = 'ok';
13674: }
13675: }
13676: }
13677: }
1.443 albertel 13678: $result = $expire_role_result;
13679: }
13680: }
13681: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 13682: $modify_section_result =
13683: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13684: undef,undef,undef,$sec,
13685: $end,$start,'','',$cid,
13686: '',$context,$credits);
1.443 albertel 13687: if ($modify_section_result =~ /^ok/) {
13688: if ($secchange == 1) {
1.628 raeburn 13689: if ($sec eq '') {
13690: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13691: } else {
13692: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13693: }
1.443 albertel 13694: } elsif ($oldsec eq '-1') {
1.628 raeburn 13695: if ($sec eq '') {
13696: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13697: } else {
13698: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13699: }
1.443 albertel 13700: } else {
1.628 raeburn 13701: if ($sec eq '') {
13702: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13703: } else {
13704: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13705: }
1.443 albertel 13706: }
13707: } else {
1.628 raeburn 13708: if ($secchange) {
13709: $$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;
13710: } else {
13711: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13712: }
1.443 albertel 13713: }
13714: $result = $modify_section_result;
13715: } elsif ($secchange == 1) {
1.628 raeburn 13716: if ($oldsec eq '') {
1.1075.2.20 raeburn 13717: $$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 13718: } else {
13719: $$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;
13720: }
1.626 raeburn 13721: if ($expire_role_result eq 'refused') {
13722: my $newsecurl = '/'.$cid;
13723: $newsecurl =~ s/\_/\//g;
13724: if ($sec ne '') {
13725: $newsecurl.='/'.$sec;
13726: }
13727: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13728: if ($sec eq '') {
13729: $$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;
13730: } else {
13731: $$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;
13732: }
13733: }
13734: }
1.443 albertel 13735: }
13736: } else {
1.626 raeburn 13737: $$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 13738: $result = "error: incomplete course id\n";
13739: }
13740: return $result;
13741: }
13742:
1.1075.2.25 raeburn 13743: sub show_role_extent {
13744: my ($scope,$context,$role) = @_;
13745: $scope =~ s{^/}{};
13746: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13747: push(@courseroles,'co');
13748: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13749: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13750: $scope =~ s{/}{_};
13751: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13752: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13753: my ($audom,$auname) = split(/\//,$scope);
13754: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13755: &Apache::loncommon::plainname($auname,$audom).'</span>');
13756: } else {
13757: $scope =~ s{/$}{};
13758: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13759: &Apache::lonnet::domain($scope,'description').'</span>');
13760: }
13761: }
13762:
1.443 albertel 13763: ############################################################
13764: ############################################################
13765:
1.566 albertel 13766: sub check_clone {
1.578 raeburn 13767: my ($args,$linefeed) = @_;
1.566 albertel 13768: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13769: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13770: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13771: my $clonemsg;
13772: my $can_clone = 0;
1.944 raeburn 13773: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13774: if ($lctype ne 'community') {
13775: $lctype = 'course';
13776: }
1.566 albertel 13777: if ($clonehome eq 'no_host') {
1.944 raeburn 13778: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13779: $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'});
13780: } else {
13781: $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'});
13782: }
1.566 albertel 13783: } else {
13784: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13785: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13786: if ($clonedesc{'type'} ne 'Community') {
13787: $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'});
13788: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13789: }
13790: }
1.882 raeburn 13791: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13792: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13793: $can_clone = 1;
13794: } else {
13795: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13796: $args->{'clonedomain'},$args->{'clonecourse'});
13797: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13798: if (grep(/^\*$/,@cloners)) {
13799: $can_clone = 1;
13800: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13801: $can_clone = 1;
13802: } else {
1.908 raeburn 13803: my $ccrole = 'cc';
1.944 raeburn 13804: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13805: $ccrole = 'co';
13806: }
1.578 raeburn 13807: my %roleshash =
13808: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13809: $args->{'ccdomain'},
1.908 raeburn 13810: 'userroles',['active'],[$ccrole],
1.578 raeburn 13811: [$args->{'clonedomain'}]);
1.908 raeburn 13812: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13813: $can_clone = 1;
13814: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13815: $can_clone = 1;
13816: } else {
1.944 raeburn 13817: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13818: $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'});
13819: } else {
13820: $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'});
13821: }
1.578 raeburn 13822: }
1.566 albertel 13823: }
1.578 raeburn 13824: }
1.566 albertel 13825: }
13826: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13827: }
13828:
1.444 albertel 13829: sub construct_course {
1.885 raeburn 13830: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 13831: my $outcome;
1.541 raeburn 13832: my $linefeed = '<br />'."\n";
13833: if ($context eq 'auto') {
13834: $linefeed = "\n";
13835: }
1.566 albertel 13836:
13837: #
13838: # Are we cloning?
13839: #
13840: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13841: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13842: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13843: if ($context ne 'auto') {
1.578 raeburn 13844: if ($clonemsg ne '') {
13845: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13846: }
1.566 albertel 13847: }
13848: $outcome .= $clonemsg.$linefeed;
13849:
13850: if (!$can_clone) {
13851: return (0,$outcome);
13852: }
13853: }
13854:
1.444 albertel 13855: #
13856: # Open course
13857: #
13858: my $crstype = lc($args->{'crstype'});
13859: my %cenv=();
13860: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13861: $args->{'cdescr'},
13862: $args->{'curl'},
13863: $args->{'course_home'},
13864: $args->{'nonstandard'},
13865: $args->{'crscode'},
13866: $args->{'ccuname'}.':'.
13867: $args->{'ccdomain'},
1.882 raeburn 13868: $args->{'crstype'},
1.885 raeburn 13869: $cnum,$context,$category);
1.444 albertel 13870:
13871: # Note: The testing routines depend on this being output; see
13872: # Utils::Course. This needs to at least be output as a comment
13873: # if anyone ever decides to not show this, and Utils::Course::new
13874: # will need to be suitably modified.
1.541 raeburn 13875: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13876: if ($$courseid =~ /^error:/) {
13877: return (0,$outcome);
13878: }
13879:
1.444 albertel 13880: #
13881: # Check if created correctly
13882: #
1.479 albertel 13883: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13884: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13885: if ($crsuhome eq 'no_host') {
13886: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13887: return (0,$outcome);
13888: }
1.541 raeburn 13889: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13890:
1.444 albertel 13891: #
1.566 albertel 13892: # Do the cloning
13893: #
13894: if ($can_clone && $cloneid) {
13895: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13896: if ($context ne 'auto') {
13897: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13898: }
13899: $outcome .= $clonemsg.$linefeed;
13900: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13901: # Copy all files
1.637 www 13902: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13903: # Restore URL
1.566 albertel 13904: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13905: # Restore title
1.566 albertel 13906: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13907: # Restore creation date, creator and creation context.
13908: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13909: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13910: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13911: # Mark as cloned
1.566 albertel 13912: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13913: # Need to clone grading mode
13914: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13915: $cenv{'grading'}=$newenv{'grading'};
13916: # Do not clone these environment entries
13917: &Apache::lonnet::del('environment',
13918: ['default_enrollment_start_date',
13919: 'default_enrollment_end_date',
13920: 'question.email',
13921: 'policy.email',
13922: 'comment.email',
13923: 'pch.users.denied',
1.725 raeburn 13924: 'plc.users.denied',
13925: 'hidefromcat',
1.1075.2.36 raeburn 13926: 'checkforpriv',
1.725 raeburn 13927: 'categories'],
1.638 www 13928: $$crsudom,$$crsunum);
1.444 albertel 13929: }
1.566 albertel 13930:
1.444 albertel 13931: #
13932: # Set environment (will override cloned, if existing)
13933: #
13934: my @sections = ();
13935: my @xlists = ();
13936: if ($args->{'crstype'}) {
13937: $cenv{'type'}=$args->{'crstype'};
13938: }
13939: if ($args->{'crsid'}) {
13940: $cenv{'courseid'}=$args->{'crsid'};
13941: }
13942: if ($args->{'crscode'}) {
13943: $cenv{'internal.coursecode'}=$args->{'crscode'};
13944: }
13945: if ($args->{'crsquota'} ne '') {
13946: $cenv{'internal.coursequota'}=$args->{'crsquota'};
13947: } else {
13948: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
13949: }
13950: if ($args->{'ccuname'}) {
13951: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
13952: ':'.$args->{'ccdomain'};
13953: } else {
13954: $cenv{'internal.courseowner'} = $args->{'curruser'};
13955: }
1.1075.2.31 raeburn 13956: if ($args->{'defaultcredits'}) {
13957: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
13958: }
1.444 albertel 13959: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
13960: if ($args->{'crssections'}) {
13961: $cenv{'internal.sectionnums'} = '';
13962: if ($args->{'crssections'} =~ m/,/) {
13963: @sections = split/,/,$args->{'crssections'};
13964: } else {
13965: $sections[0] = $args->{'crssections'};
13966: }
13967: if (@sections > 0) {
13968: foreach my $item (@sections) {
13969: my ($sec,$gp) = split/:/,$item;
13970: my $class = $args->{'crscode'}.$sec;
13971: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
13972: $cenv{'internal.sectionnums'} .= $item.',';
13973: unless ($addcheck eq 'ok') {
13974: push @badclasses, $class;
13975: }
13976: }
13977: $cenv{'internal.sectionnums'} =~ s/,$//;
13978: }
13979: }
13980: # do not hide course coordinator from staff listing,
13981: # even if privileged
13982: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 13983: # add course coordinator's domain to domains to check for privileged users
13984: # if different to course domain
13985: if ($$crsudom ne $args->{'ccdomain'}) {
13986: $cenv{'checkforpriv'} = $args->{'ccdomain'};
13987: }
1.444 albertel 13988: # add crosslistings
13989: if ($args->{'crsxlist'}) {
13990: $cenv{'internal.crosslistings'}='';
13991: if ($args->{'crsxlist'} =~ m/,/) {
13992: @xlists = split/,/,$args->{'crsxlist'};
13993: } else {
13994: $xlists[0] = $args->{'crsxlist'};
13995: }
13996: if (@xlists > 0) {
13997: foreach my $item (@xlists) {
13998: my ($xl,$gp) = split/:/,$item;
13999: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14000: $cenv{'internal.crosslistings'} .= $item.',';
14001: unless ($addcheck eq 'ok') {
14002: push @badclasses, $xl;
14003: }
14004: }
14005: $cenv{'internal.crosslistings'} =~ s/,$//;
14006: }
14007: }
14008: if ($args->{'autoadds'}) {
14009: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14010: }
14011: if ($args->{'autodrops'}) {
14012: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14013: }
14014: # check for notification of enrollment changes
14015: my @notified = ();
14016: if ($args->{'notify_owner'}) {
14017: if ($args->{'ccuname'} ne '') {
14018: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14019: }
14020: }
14021: if ($args->{'notify_dc'}) {
14022: if ($uname ne '') {
1.630 raeburn 14023: push(@notified,$uname.':'.$udom);
1.444 albertel 14024: }
14025: }
14026: if (@notified > 0) {
14027: my $notifylist;
14028: if (@notified > 1) {
14029: $notifylist = join(',',@notified);
14030: } else {
14031: $notifylist = $notified[0];
14032: }
14033: $cenv{'internal.notifylist'} = $notifylist;
14034: }
14035: if (@badclasses > 0) {
14036: my %lt=&Apache::lonlocal::texthash(
14037: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course. However, if automated course roster updates are enabled for this class, these particular sections/crosslistings will not contribute towards enrollment, because the user identified as the course owner for this LON-CAPA course',
14038: 'dnhr' => 'does not have rights to access enrollment in these classes',
14039: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14040: );
1.541 raeburn 14041: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14042: ' ('.$lt{'adby'}.')';
14043: if ($context eq 'auto') {
14044: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14045: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14046: foreach my $item (@badclasses) {
14047: if ($context eq 'auto') {
14048: $outcome .= " - $item\n";
14049: } else {
14050: $outcome .= "<li>$item</li>\n";
14051: }
14052: }
14053: if ($context eq 'auto') {
14054: $outcome .= $linefeed;
14055: } else {
1.566 albertel 14056: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14057: }
14058: }
1.444 albertel 14059: }
14060: if ($args->{'no_end_date'}) {
14061: $args->{'endaccess'} = 0;
14062: }
14063: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14064: $cenv{'internal.autoend'}=$args->{'enrollend'};
14065: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14066: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14067: if ($args->{'showphotos'}) {
14068: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14069: }
14070: $cenv{'internal.authtype'} = $args->{'authtype'};
14071: $cenv{'internal.autharg'} = $args->{'autharg'};
14072: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14073: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14074: 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');
14075: if ($context eq 'auto') {
14076: $outcome .= $krb_msg;
14077: } else {
1.566 albertel 14078: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14079: }
14080: $outcome .= $linefeed;
1.444 albertel 14081: }
14082: }
14083: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14084: if ($args->{'setpolicy'}) {
14085: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14086: }
14087: if ($args->{'setcontent'}) {
14088: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14089: }
14090: }
14091: if ($args->{'reshome'}) {
14092: $cenv{'reshome'}=$args->{'reshome'}.'/';
14093: $cenv{'reshome'}=~s/\/+$/\//;
14094: }
14095: #
14096: # course has keyed access
14097: #
14098: if ($args->{'setkeys'}) {
14099: $cenv{'keyaccess'}='yes';
14100: }
14101: # if specified, key authority is not course, but user
14102: # only active if keyaccess is yes
14103: if ($args->{'keyauth'}) {
1.487 albertel 14104: my ($user,$domain) = split(':',$args->{'keyauth'});
14105: $user = &LONCAPA::clean_username($user);
14106: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14107: if ($user ne '' && $domain ne '') {
1.487 albertel 14108: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14109: }
14110: }
14111:
14112: if ($args->{'disresdis'}) {
14113: $cenv{'pch.roles.denied'}='st';
14114: }
14115: if ($args->{'disablechat'}) {
14116: $cenv{'plc.roles.denied'}='st';
14117: }
14118:
14119: # Record we've not yet viewed the Course Initialization Helper for this
14120: # course
14121: $cenv{'course.helper.not.run'} = 1;
14122: #
14123: # Use new Randomseed
14124: #
14125: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14126: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14127: #
14128: # The encryption code and receipt prefix for this course
14129: #
14130: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14131: $cenv{'internal.encpref'}=100+int(9*rand(99));
14132: #
14133: # By default, use standard grading
14134: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14135:
1.541 raeburn 14136: $outcome .= $linefeed.&mt('Setting environment').': '.
14137: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14138: #
14139: # Open all assignments
14140: #
14141: if ($args->{'openall'}) {
14142: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14143: my %storecontent = ($storeunder => time,
14144: $storeunder.'.type' => 'date_start');
14145:
14146: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14147: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14148: }
14149: #
14150: # Set first page
14151: #
14152: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14153: || ($cloneid)) {
1.445 albertel 14154: use LONCAPA::map;
1.444 albertel 14155: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14156:
14157: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14158: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14159:
1.444 albertel 14160: $outcome .= ($fatal?$errtext:'read ok').' - ';
14161: my $title; my $url;
14162: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14163: $title=&mt('Syllabus');
1.444 albertel 14164: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14165: } else {
1.963 raeburn 14166: $title=&mt('Table of Contents');
1.444 albertel 14167: $url='/adm/navmaps';
14168: }
1.445 albertel 14169:
14170: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14171: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14172:
14173: if ($errtext) { $fatal=2; }
1.541 raeburn 14174: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14175: }
1.566 albertel 14176:
14177: return (1,$outcome);
1.444 albertel 14178: }
14179:
14180: ############################################################
14181: ############################################################
14182:
1.953 droeschl 14183: #SD
14184: # only Community and Course, or anything else?
1.378 raeburn 14185: sub course_type {
14186: my ($cid) = @_;
14187: if (!defined($cid)) {
14188: $cid = $env{'request.course.id'};
14189: }
1.404 albertel 14190: if (defined($env{'course.'.$cid.'.type'})) {
14191: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14192: } else {
14193: return 'Course';
1.377 raeburn 14194: }
14195: }
1.156 albertel 14196:
1.406 raeburn 14197: sub group_term {
14198: my $crstype = &course_type();
14199: my %names = (
14200: 'Course' => 'group',
1.865 raeburn 14201: 'Community' => 'group',
1.406 raeburn 14202: );
14203: return $names{$crstype};
14204: }
14205:
1.902 raeburn 14206: sub course_types {
14207: my @types = ('official','unofficial','community');
14208: my %typename = (
14209: official => 'Official course',
14210: unofficial => 'Unofficial course',
14211: community => 'Community',
14212: );
14213: return (\@types,\%typename);
14214: }
14215:
1.156 albertel 14216: sub icon {
14217: my ($file)=@_;
1.505 albertel 14218: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14219: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14220: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14221: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14222: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14223: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14224: $curfext.".gif") {
14225: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14226: $curfext.".gif";
14227: }
14228: }
1.249 albertel 14229: return &lonhttpdurl($iconname);
1.154 albertel 14230: }
1.84 albertel 14231:
1.575 albertel 14232: sub lonhttpdurl {
1.692 www 14233: #
14234: # Had been used for "small fry" static images on separate port 8080.
14235: # Modify here if lightweight http functionality desired again.
14236: # Currently eliminated due to increasing firewall issues.
14237: #
1.575 albertel 14238: my ($url)=@_;
1.692 www 14239: return $url;
1.215 albertel 14240: }
14241:
1.213 albertel 14242: sub connection_aborted {
14243: my ($r)=@_;
14244: $r->print(" ");$r->rflush();
14245: my $c = $r->connection;
14246: return $c->aborted();
14247: }
14248:
1.221 foxr 14249: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14250: # strings as 'strings'.
14251: sub escape_single {
1.221 foxr 14252: my ($input) = @_;
1.223 albertel 14253: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14254: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14255: return $input;
14256: }
1.223 albertel 14257:
1.222 foxr 14258: # Same as escape_single, but escape's "'s This
14259: # can be used for "strings"
14260: sub escape_double {
14261: my ($input) = @_;
14262: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14263: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14264: return $input;
14265: }
1.223 albertel 14266:
1.222 foxr 14267: # Escapes the last element of a full URL.
14268: sub escape_url {
14269: my ($url) = @_;
1.238 raeburn 14270: my @urlslices = split(/\//, $url,-1);
1.369 www 14271: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14272: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14273: }
1.462 albertel 14274:
1.820 raeburn 14275: sub compare_arrays {
14276: my ($arrayref1,$arrayref2) = @_;
14277: my (@difference,%count);
14278: @difference = ();
14279: %count = ();
14280: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14281: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14282: foreach my $element (keys(%count)) {
14283: if ($count{$element} == 1) {
14284: push(@difference,$element);
14285: }
14286: }
14287: }
14288: return @difference;
14289: }
14290:
1.817 bisitz 14291: # -------------------------------------------------------- Initialize user login
1.462 albertel 14292: sub init_user_environment {
1.463 albertel 14293: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14294: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14295:
14296: my $public=($username eq 'public' && $domain eq 'public');
14297:
14298: # See if old ID present, if so, remove
14299:
1.1062 raeburn 14300: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14301: my $now=time;
14302:
14303: if ($public) {
14304: my $max_public=100;
14305: my $oldest;
14306: my $oldest_time=0;
14307: for(my $next=1;$next<=$max_public;$next++) {
14308: if (-e $lonids."/publicuser_$next.id") {
14309: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14310: if ($mtime<$oldest_time || !$oldest_time) {
14311: $oldest_time=$mtime;
14312: $oldest=$next;
14313: }
14314: } else {
14315: $cookie="publicuser_$next";
14316: last;
14317: }
14318: }
14319: if (!$cookie) { $cookie="publicuser_$oldest"; }
14320: } else {
1.463 albertel 14321: # if this isn't a robot, kill any existing non-robot sessions
14322: if (!$args->{'robot'}) {
14323: opendir(DIR,$lonids);
14324: while ($filename=readdir(DIR)) {
14325: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14326: unlink($lonids.'/'.$filename);
14327: }
1.462 albertel 14328: }
1.463 albertel 14329: closedir(DIR);
1.462 albertel 14330: }
14331: # Give them a new cookie
1.463 albertel 14332: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14333: : $now.$$.int(rand(10000)));
1.463 albertel 14334: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14335:
14336: # Initialize roles
14337:
1.1062 raeburn 14338: ($userroles,$firstaccenv,$timerintenv) =
14339: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14340: }
14341: # ------------------------------------ Check browser type and MathML capability
14342:
14343: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42 raeburn 14344: $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
1.462 albertel 14345:
14346: # ------------------------------------------------------------- Get environment
14347:
14348: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14349: my ($tmp) = keys(%userenv);
14350: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14351: } else {
14352: undef(%userenv);
14353: }
14354: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14355: $form->{'interface'}=$userenv{'interface'};
14356: }
14357: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14358:
14359: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14360: foreach my $option ('interface','localpath','localres') {
14361: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14362: }
14363: # --------------------------------------------------------- Write first profile
14364:
14365: {
14366: my %initial_env =
14367: ("user.name" => $username,
14368: "user.domain" => $domain,
14369: "user.home" => $authhost,
14370: "browser.type" => $clientbrowser,
14371: "browser.version" => $clientversion,
14372: "browser.mathml" => $clientmathml,
14373: "browser.unicode" => $clientunicode,
14374: "browser.os" => $clientos,
1.1075.2.42 raeburn 14375: "browser.mobile" => $clientmobile,
14376: "browser.info" => $clientinfo,
1.462 albertel 14377: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14378: "request.course.fn" => '',
14379: "request.course.uri" => '',
14380: "request.course.sec" => '',
14381: "request.role" => 'cm',
14382: "request.role.adv" => $env{'user.adv'},
14383: "request.host" => $ENV{'REMOTE_ADDR'},);
14384:
14385: if ($form->{'localpath'}) {
14386: $initial_env{"browser.localpath"} = $form->{'localpath'};
14387: $initial_env{"browser.localres"} = $form->{'localres'};
14388: }
14389:
14390: if ($form->{'interface'}) {
14391: $form->{'interface'}=~s/\W//gs;
14392: $initial_env{"browser.interface"} = $form->{'interface'};
14393: $env{'browser.interface'}=$form->{'interface'};
14394: }
14395:
1.981 raeburn 14396: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14397: my %domdef;
14398: unless ($domain eq 'public') {
14399: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14400: }
1.980 raeburn 14401:
1.1075.2.7 raeburn 14402: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14403: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14404: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14405: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14406: }
14407:
1.864 raeburn 14408: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 14409: $userenv{'canrequest.'.$crstype} =
14410: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14411: 'reload','requestcourses',
14412: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14413: }
14414:
1.1075.2.14 raeburn 14415: $userenv{'canrequest.author'} =
14416: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14417: 'reload','requestauthor',
14418: \%userenv,\%domdef,\%is_adv);
14419: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14420: $domain,$username);
14421: my $reqstatus = $reqauthor{'author_status'};
14422: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14423: if (ref($reqauthor{'author'}) eq 'HASH') {
14424: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14425: $reqauthor{'author'}{'timestamp'};
14426: }
14427: }
14428:
1.462 albertel 14429: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14430:
1.462 albertel 14431: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14432: &GDBM_WRCREAT(),0640)) {
14433: &_add_to_env(\%disk_env,\%initial_env);
14434: &_add_to_env(\%disk_env,\%userenv,'environment.');
14435: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14436: if (ref($firstaccenv) eq 'HASH') {
14437: &_add_to_env(\%disk_env,$firstaccenv);
14438: }
14439: if (ref($timerintenv) eq 'HASH') {
14440: &_add_to_env(\%disk_env,$timerintenv);
14441: }
1.463 albertel 14442: if (ref($args->{'extra_env'})) {
14443: &_add_to_env(\%disk_env,$args->{'extra_env'});
14444: }
1.462 albertel 14445: untie(%disk_env);
14446: } else {
1.705 tempelho 14447: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14448: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14449: return 'error: '.$!;
14450: }
14451: }
14452: $env{'request.role'}='cm';
14453: $env{'request.role.adv'}=$env{'user.adv'};
14454: $env{'browser.type'}=$clientbrowser;
14455:
14456: return $cookie;
14457:
14458: }
14459:
14460: sub _add_to_env {
14461: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14462: if (ref($env_data) eq 'HASH') {
14463: while (my ($key,$value) = each(%$env_data)) {
14464: $idf->{$prefix.$key} = $value;
14465: $env{$prefix.$key} = $value;
14466: }
1.462 albertel 14467: }
14468: }
14469:
1.685 tempelho 14470: # --- Get the symbolic name of a problem and the url
14471: sub get_symb {
14472: my ($request,$silent) = @_;
1.726 raeburn 14473: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14474: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14475: if ($symb eq '') {
14476: if (!$silent) {
1.1071 raeburn 14477: if (ref($request)) {
14478: $request->print("Unable to handle ambiguous references:$url:.");
14479: }
1.685 tempelho 14480: return ();
14481: }
14482: }
14483: &Apache::lonenc::check_decrypt(\$symb);
14484: return ($symb);
14485: }
14486:
14487: # --------------------------------------------------------------Get annotation
14488:
14489: sub get_annotation {
14490: my ($symb,$enc) = @_;
14491:
14492: my $key = $symb;
14493: if (!$enc) {
14494: $key =
14495: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14496: }
14497: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14498: return $annotation{$key};
14499: }
14500:
14501: sub clean_symb {
1.731 raeburn 14502: my ($symb,$delete_enc) = @_;
1.685 tempelho 14503:
14504: &Apache::lonenc::check_decrypt(\$symb);
14505: my $enc = $env{'request.enc'};
1.731 raeburn 14506: if ($delete_enc) {
1.730 raeburn 14507: delete($env{'request.enc'});
14508: }
1.685 tempelho 14509:
14510: return ($symb,$enc);
14511: }
1.462 albertel 14512:
1.990 raeburn 14513: sub build_release_hashes {
14514: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14515: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14516: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14517: (ref($randomizetry) eq 'HASH'));
14518: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14519: my ($item,$name,$value) = split(/:/,$key);
14520: if ($item eq 'parameter') {
14521: if (ref($checkparms->{$name}) eq 'ARRAY') {
14522: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14523: push(@{$checkparms->{$name}},$value);
14524: }
14525: } else {
14526: push(@{$checkparms->{$name}},$value);
14527: }
14528: } elsif ($item eq 'resourcetag') {
14529: if ($name eq 'responsetype') {
14530: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14531: }
14532: } elsif ($item eq 'course') {
14533: if ($name eq 'crstype') {
14534: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14535: }
14536: }
14537: }
14538: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14539: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14540: return;
14541: }
14542:
1.1075.2.11 raeburn 14543: sub update_content_constraints {
14544: my ($cdom,$cnum,$chome,$cid) = @_;
14545: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14546: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14547: my %checkresponsetypes;
14548: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14549: my ($item,$name,$value) = split(/:/,$key);
14550: if ($item eq 'resourcetag') {
14551: if ($name eq 'responsetype') {
14552: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14553: }
14554: }
14555: }
14556: my $navmap = Apache::lonnavmaps::navmap->new();
14557: if (defined($navmap)) {
14558: my %allresponses;
14559: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14560: my %responses = $res->responseTypes();
14561: foreach my $key (keys(%responses)) {
14562: next unless(exists($checkresponsetypes{$key}));
14563: $allresponses{$key} += $responses{$key};
14564: }
14565: }
14566: foreach my $key (keys(%allresponses)) {
14567: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14568: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14569: ($reqdmajor,$reqdminor) = ($major,$minor);
14570: }
14571: }
14572: undef($navmap);
14573: }
14574: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14575: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14576: }
14577: return;
14578: }
14579:
1.1075.2.27 raeburn 14580: sub allmaps_incourse {
14581: my ($cdom,$cnum,$chome,$cid) = @_;
14582: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14583: $cid = $env{'request.course.id'};
14584: $cdom = $env{'course.'.$cid.'.domain'};
14585: $cnum = $env{'course.'.$cid.'.num'};
14586: $chome = $env{'course.'.$cid.'.home'};
14587: }
14588: my %allmaps = ();
14589: my $lastchange =
14590: &Apache::lonnet::get_coursechange($cdom,$cnum);
14591: if ($lastchange > $env{'request.course.tied'}) {
14592: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14593: unless ($ferr) {
14594: &update_content_constraints($cdom,$cnum,$chome,$cid);
14595: }
14596: }
14597: my $navmap = Apache::lonnavmaps::navmap->new();
14598: if (defined($navmap)) {
14599: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14600: $allmaps{$res->src()} = 1;
14601: }
14602: }
14603: return \%allmaps;
14604: }
14605:
1.1075.2.11 raeburn 14606: sub parse_supplemental_title {
14607: my ($title) = @_;
14608:
14609: my ($foldertitle,$renametitle);
14610: if ($title =~ /&&&/) {
14611: $title = &HTML::Entites::decode($title);
14612: }
14613: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14614: $renametitle=$4;
14615: my ($time,$uname,$udom) = ($1,$2,$3);
14616: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14617: my $name = &plainname($uname,$udom);
14618: $name = &HTML::Entities::encode($name,'"<>&\'');
14619: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14620: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14621: $name.': <br />'.$foldertitle;
14622: }
14623: if (wantarray) {
14624: return ($title,$foldertitle,$renametitle);
14625: }
14626: return $title;
14627: }
14628:
1.1075.2.43 raeburn 14629: sub recurse_supplemental {
14630: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
14631: if ($suppmap) {
14632: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
14633: if ($fatal) {
14634: $errors ++;
14635: } else {
14636: if ($#LONCAPA::map::resources > 0) {
14637: foreach my $res (@LONCAPA::map::resources) {
14638: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
14639: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 14640: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
14641: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 14642: } else {
14643: $numfiles ++;
14644: }
14645: }
14646: }
14647: }
14648: }
14649: }
14650: return ($numfiles,$errors);
14651: }
14652:
1.1075.2.18 raeburn 14653: sub symb_to_docspath {
14654: my ($symb) = @_;
14655: return unless ($symb);
14656: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14657: if ($resurl=~/\.(sequence|page)$/) {
14658: $mapurl=$resurl;
14659: } elsif ($resurl eq 'adm/navmaps') {
14660: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14661: }
14662: my $mapresobj;
14663: my $navmap = Apache::lonnavmaps::navmap->new();
14664: if (ref($navmap)) {
14665: $mapresobj = $navmap->getResourceByUrl($mapurl);
14666: }
14667: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14668: my $type=$2;
14669: my $path;
14670: if (ref($mapresobj)) {
14671: my $pcslist = $mapresobj->map_hierarchy();
14672: if ($pcslist ne '') {
14673: foreach my $pc (split(/,/,$pcslist)) {
14674: next if ($pc <= 1);
14675: my $res = $navmap->getByMapPc($pc);
14676: if (ref($res)) {
14677: my $thisurl = $res->src();
14678: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14679: my $thistitle = $res->title();
14680: $path .= '&'.
14681: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 14682: &escape($thistitle).
1.1075.2.18 raeburn 14683: ':'.$res->randompick().
14684: ':'.$res->randomout().
14685: ':'.$res->encrypted().
14686: ':'.$res->randomorder().
14687: ':'.$res->is_page();
14688: }
14689: }
14690: }
14691: $path =~ s/^\&//;
14692: my $maptitle = $mapresobj->title();
14693: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 14694: $maptitle = 'Main Content';
1.1075.2.18 raeburn 14695: }
14696: $path .= (($path ne '')? '&' : '').
14697: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 14698: &escape($maptitle).
1.1075.2.18 raeburn 14699: ':'.$mapresobj->randompick().
14700: ':'.$mapresobj->randomout().
14701: ':'.$mapresobj->encrypted().
14702: ':'.$mapresobj->randomorder().
14703: ':'.$mapresobj->is_page();
14704: } else {
14705: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14706: my $ispage = (($type eq 'page')? 1 : '');
14707: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 14708: $maptitle = 'Main Content';
1.1075.2.18 raeburn 14709: }
14710: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 14711: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 14712: }
14713: unless ($mapurl eq 'default') {
14714: $path = 'default&'.
1.1075.2.46 raeburn 14715: &escape('Main Content').
1.1075.2.18 raeburn 14716: ':::::&'.$path;
14717: }
14718: return $path;
14719: }
14720:
1.1075.2.14 raeburn 14721: sub captcha_display {
14722: my ($context,$lonhost) = @_;
14723: my ($output,$error);
14724: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
14725: if ($captcha eq 'original') {
14726: $output = &create_captcha();
14727: unless ($output) {
14728: $error = 'captcha';
14729: }
14730: } elsif ($captcha eq 'recaptcha') {
14731: $output = &create_recaptcha($pubkey);
14732: unless ($output) {
14733: $error = 'recaptcha';
14734: }
14735: }
14736: return ($output,$error);
14737: }
14738:
14739: sub captcha_response {
14740: my ($context,$lonhost) = @_;
14741: my ($captcha_chk,$captcha_error);
14742: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
14743: if ($captcha eq 'original') {
14744: ($captcha_chk,$captcha_error) = &check_captcha();
14745: } elsif ($captcha eq 'recaptcha') {
14746: $captcha_chk = &check_recaptcha($privkey);
14747: } else {
14748: $captcha_chk = 1;
14749: }
14750: return ($captcha_chk,$captcha_error);
14751: }
14752:
14753: sub get_captcha_config {
14754: my ($context,$lonhost) = @_;
14755: my ($captcha,$pubkey,$privkey,$hashtocheck);
14756: my $hostname = &Apache::lonnet::hostname($lonhost);
14757: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14758: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
14759: if ($context eq 'usercreation') {
14760: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14761: if (ref($domconfig{$context}) eq 'HASH') {
14762: $hashtocheck = $domconfig{$context}{'cancreate'};
14763: if (ref($hashtocheck) eq 'HASH') {
14764: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14765: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14766: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14767: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14768: }
14769: if ($privkey && $pubkey) {
14770: $captcha = 'recaptcha';
14771: } else {
14772: $captcha = 'original';
14773: }
14774: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14775: $captcha = 'original';
14776: }
14777: }
14778: } else {
14779: $captcha = 'captcha';
14780: }
14781: } elsif ($context eq 'login') {
14782: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14783: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14784: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14785: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
14786: if ($privkey && $pubkey) {
14787: $captcha = 'recaptcha';
14788: } else {
14789: $captcha = 'original';
14790: }
14791: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14792: $captcha = 'original';
14793: }
14794: }
14795: return ($captcha,$pubkey,$privkey);
14796: }
14797:
14798: sub create_captcha {
14799: my %captcha_params = &captcha_settings();
14800: my ($output,$maxtries,$tries) = ('',10,0);
14801: while ($tries < $maxtries) {
14802: $tries ++;
14803: my $captcha = Authen::Captcha->new (
14804: output_folder => $captcha_params{'output_dir'},
14805: data_folder => $captcha_params{'db_dir'},
14806: );
14807: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14808:
14809: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14810: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14811: &mt('Type in the letters/numbers shown below').' '.
14812: '<input type="text" size="5" name="code" value="" /><br />'.
14813: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
14814: last;
14815: }
14816: }
14817: return $output;
14818: }
14819:
14820: sub captcha_settings {
14821: my %captcha_params = (
14822: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14823: www_output_dir => "/captchaspool",
14824: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14825: numchars => '5',
14826: );
14827: return %captcha_params;
14828: }
14829:
14830: sub check_captcha {
14831: my ($captcha_chk,$captcha_error);
14832: my $code = $env{'form.code'};
14833: my $md5sum = $env{'form.crypt'};
14834: my %captcha_params = &captcha_settings();
14835: my $captcha = Authen::Captcha->new(
14836: output_folder => $captcha_params{'output_dir'},
14837: data_folder => $captcha_params{'db_dir'},
14838: );
1.1075.2.26 raeburn 14839: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 14840: my %captcha_hash = (
14841: 0 => 'Code not checked (file error)',
14842: -1 => 'Failed: code expired',
14843: -2 => 'Failed: invalid code (not in database)',
14844: -3 => 'Failed: invalid code (code does not match crypt)',
14845: );
14846: if ($captcha_chk != 1) {
14847: $captcha_error = $captcha_hash{$captcha_chk}
14848: }
14849: return ($captcha_chk,$captcha_error);
14850: }
14851:
14852: sub create_recaptcha {
14853: my ($pubkey) = @_;
14854: my $captcha = Captcha::reCAPTCHA->new;
14855: return $captcha->get_options_setter({theme => 'white'})."\n".
14856: $captcha->get_html($pubkey).
14857: &mt('If either word is hard to read, [_1] will replace them.',
1.1075.2.39 raeburn 14858: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1075.2.14 raeburn 14859: '<br /><br />';
14860: }
14861:
14862: sub check_recaptcha {
14863: my ($privkey) = @_;
14864: my $captcha_chk;
14865: my $captcha = Captcha::reCAPTCHA->new;
14866: my $captcha_result =
14867: $captcha->check_answer(
14868: $privkey,
14869: $ENV{'REMOTE_ADDR'},
14870: $env{'form.recaptcha_challenge_field'},
14871: $env{'form.recaptcha_response_field'},
14872: );
14873: if ($captcha_result->{is_valid}) {
14874: $captcha_chk = 1;
14875: }
14876: return $captcha_chk;
14877: }
14878:
1.41 ng 14879: =pod
14880:
14881: =back
14882:
1.112 bowersj2 14883: =cut
1.41 ng 14884:
1.112 bowersj2 14885: 1;
14886: __END__;
1.41 ng 14887:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>