Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.56
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.56! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.55 2013/11/20 05:11:34 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.1075.2.50 raeburn 1237: if ($env{'browser.mobile'}) {
1238: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1239: } else {
1240: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1241: }
1.1037 www 1242: } elsif ($stayOnPage eq 'popup') {
1243: $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 1244: } else {
1.48 bowersj2 1245: $link = "/adm/help/${filename}.hlp";
1246: }
1247:
1248: # Add the text
1.755 neumanie 1249: if ($text ne "") {
1.763 bisitz 1250: $template.='<span class="LC_help_open_topic">'
1251: .'<a target="_top" href="'.$link.'">'
1252: .$text.'</a>';
1.48 bowersj2 1253: }
1254:
1.763 bisitz 1255: # (Always) Add the graphic
1.179 matthew 1256: my $title = &mt('Online Help');
1.667 raeburn 1257: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1258: if ($imgid ne '') {
1259: $imgid = ' id="'.$imgid.'"';
1260: }
1.763 bisitz 1261: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1262: .'<img src="'.$helpicon.'" border="0"'
1263: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1264: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1265: .' /></a>';
1266: if ($text ne "") {
1267: $template.='</span>';
1268: }
1.44 bowersj2 1269: return $template;
1270:
1.106 bowersj2 1271: }
1272:
1273: # This is a quicky function for Latex cheatsheet editing, since it
1274: # appears in at least four places
1275: sub helpLatexCheatsheet {
1.1037 www 1276: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1277: my $out;
1.106 bowersj2 1278: my $addOther = '';
1.732 raeburn 1279: if ($topic) {
1.1037 www 1280: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1281: }
1282: $out = '<span>' # Start cheatsheet
1283: .$addOther
1284: .'<span>'
1.1037 www 1285: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1286: .'</span> <span>'
1.1037 www 1287: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1288: .'</span>';
1.732 raeburn 1289: unless ($not_author) {
1.763 bisitz 1290: $out .= ' <span>'
1.1037 www 1291: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763 bisitz 1292: .'</span>';
1.732 raeburn 1293: }
1.763 bisitz 1294: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1295: return $out;
1.172 www 1296: }
1297:
1.430 albertel 1298: sub general_help {
1299: my $helptopic='Student_Intro';
1300: if ($env{'request.role'}=~/^(ca|au)/) {
1301: $helptopic='Authoring_Intro';
1.907 raeburn 1302: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1303: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1304: } elsif ($env{'request.role'}=~/^dc/) {
1305: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1306: }
1307: return $helptopic;
1308: }
1309:
1310: sub update_help_link {
1311: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1312: my $origurl = $ENV{'REQUEST_URI'};
1313: $origurl=~s|^/~|/priv/|;
1314: my $timestamp = time;
1315: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1316: $$datum = &escape($$datum);
1317: }
1318:
1319: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1320: my $output .= <<"ENDOUTPUT";
1321: <script type="text/javascript">
1.824 bisitz 1322: // <![CDATA[
1.430 albertel 1323: banner_link = '$banner_link';
1.824 bisitz 1324: // ]]>
1.430 albertel 1325: </script>
1326: ENDOUTPUT
1327: return $output;
1328: }
1329:
1330: # now just updates the help link and generates a blue icon
1.193 raeburn 1331: sub help_open_menu {
1.430 albertel 1332: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1333: = @_;
1.949 droeschl 1334: $stayOnPage = 1;
1.430 albertel 1335: my $output;
1336: if ($component_help) {
1337: if (!$text) {
1338: $output=&help_open_topic($component_help,undef,$stayOnPage,
1339: $width,$height);
1340: } else {
1341: my $help_text;
1342: $help_text=&unescape($topic);
1343: $output='<table><tr><td>'.
1344: &help_open_topic($component_help,$help_text,$stayOnPage,
1345: $width,$height).'</td></tr></table>';
1346: }
1347: }
1348: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1349: return $output.$banner_link;
1350: }
1351:
1352: sub top_nav_help {
1353: my ($text) = @_;
1.436 albertel 1354: $text = &mt($text);
1.949 droeschl 1355: my $stay_on_page = 1;
1356:
1.572 banghart 1357: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1358: : "javascript:helpMenu('open')";
1.572 banghart 1359: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1360:
1.201 raeburn 1361: my $title = &mt('Get help');
1.436 albertel 1362:
1363: return <<"END";
1364: $banner_link
1.1075.2.56! raeburn 1365: <a href="$link" title="$title">$text</a>
1.436 albertel 1366: END
1367: }
1368:
1369: sub help_menu_js {
1.1075.2.52 raeburn 1370: my ($httphost) = @_;
1.949 droeschl 1371: my $stayOnPage = 1;
1.436 albertel 1372: my $width = 620;
1373: my $height = 600;
1.430 albertel 1374: my $helptopic=&general_help();
1.1075.2.52 raeburn 1375: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1376: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1377: my $start_page =
1378: &Apache::loncommon::start_page('Help Menu', undef,
1379: {'frameset' => 1,
1380: 'js_ready' => 1,
1.1075.2.52 raeburn 1381: 'use_absolute' => $httphost,
1.331 albertel 1382: 'add_entries' => {
1383: 'border' => '0',
1.579 raeburn 1384: 'rows' => "110,*",},});
1.331 albertel 1385: my $end_page =
1386: &Apache::loncommon::end_page({'frameset' => 1,
1387: 'js_ready' => 1,});
1388:
1.436 albertel 1389: my $template .= <<"ENDTEMPLATE";
1390: <script type="text/javascript">
1.877 bisitz 1391: // <![CDATA[
1.253 albertel 1392: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1393: var banner_link = '';
1.243 raeburn 1394: function helpMenu(target) {
1395: var caller = this;
1396: if (target == 'open') {
1397: var newWindow = null;
1398: try {
1.262 albertel 1399: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1400: }
1401: catch(error) {
1402: writeHelp(caller);
1403: return;
1404: }
1405: if (newWindow) {
1406: caller = newWindow;
1407: }
1.193 raeburn 1408: }
1.243 raeburn 1409: writeHelp(caller);
1410: return;
1411: }
1412: function writeHelp(caller) {
1.1072 raeburn 1413: 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 1414: caller.document.close()
1415: caller.focus()
1.193 raeburn 1416: }
1.877 bisitz 1417: // END LON-CAPA Internal -->
1.253 albertel 1418: // ]]>
1.436 albertel 1419: </script>
1.193 raeburn 1420: ENDTEMPLATE
1421: return $template;
1422: }
1423:
1.172 www 1424: sub help_open_bug {
1425: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1426: unless ($env{'user.adv'}) { return ''; }
1.172 www 1427: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1428: $text = "" if (not defined $text);
1429: $stayOnPage=1;
1.184 albertel 1430: $width = 600 if (not defined $width);
1431: $height = 600 if (not defined $height);
1.172 www 1432:
1433: $topic=~s/\W+/\+/g;
1434: my $link='';
1435: my $template='';
1.379 albertel 1436: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1437: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1438: if (!$stayOnPage)
1439: {
1440: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1441: }
1442: else
1443: {
1444: $link = $url;
1445: }
1446: # Add the text
1447: if ($text ne "")
1448: {
1449: $template .=
1450: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1451: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1452: }
1453:
1454: # Add the graphic
1.179 matthew 1455: my $title = &mt('Report a Bug');
1.215 albertel 1456: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1457: $template .= <<"ENDTEMPLATE";
1.436 albertel 1458: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1459: ENDTEMPLATE
1460: if ($text ne '') { $template.='</td></tr></table>' };
1461: return $template;
1462:
1463: }
1464:
1465: sub help_open_faq {
1466: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1467: unless ($env{'user.adv'}) { return ''; }
1.172 www 1468: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1469: $text = "" if (not defined $text);
1470: $stayOnPage=1;
1471: $width = 350 if (not defined $width);
1472: $height = 400 if (not defined $height);
1473:
1474: $topic=~s/\W+/\+/g;
1475: my $link='';
1476: my $template='';
1477: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1478: if (!$stayOnPage)
1479: {
1480: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1481: }
1482: else
1483: {
1484: $link = $url;
1485: }
1486:
1487: # Add the text
1488: if ($text ne "")
1489: {
1490: $template .=
1.173 www 1491: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1492: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1493: }
1494:
1495: # Add the graphic
1.179 matthew 1496: my $title = &mt('View the FAQ');
1.215 albertel 1497: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1498: $template .= <<"ENDTEMPLATE";
1.436 albertel 1499: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1500: ENDTEMPLATE
1501: if ($text ne '') { $template.='</td></tr></table>' };
1502: return $template;
1503:
1.44 bowersj2 1504: }
1.37 matthew 1505:
1.180 matthew 1506: ###############################################################
1507: ###############################################################
1508:
1.45 matthew 1509: =pod
1510:
1.648 raeburn 1511: =item * &change_content_javascript():
1.256 matthew 1512:
1513: This and the next function allow you to create small sections of an
1514: otherwise static HTML page that you can update on the fly with
1515: Javascript, even in Netscape 4.
1516:
1517: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1518: must be written to the HTML page once. It will prove the Javascript
1519: function "change(name, content)". Calling the change function with the
1520: name of the section
1521: you want to update, matching the name passed to C<changable_area>, and
1522: the new content you want to put in there, will put the content into
1523: that area.
1524:
1525: B<Note>: Netscape 4 only reserves enough space for the changable area
1526: to contain room for the original contents. You need to "make space"
1527: for whatever changes you wish to make, and be B<sure> to check your
1528: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1529: it's adequate for updating a one-line status display, but little more.
1530: This script will set the space to 100% width, so you only need to
1531: worry about height in Netscape 4.
1532:
1533: Modern browsers are much less limiting, and if you can commit to the
1534: user not using Netscape 4, this feature may be used freely with
1535: pretty much any HTML.
1536:
1537: =cut
1538:
1539: sub change_content_javascript {
1540: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1541: if ($env{'browser.type'} eq 'netscape' &&
1542: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1543: return (<<NETSCAPE4);
1544: function change(name, content) {
1545: doc = document.layers[name+"___escape"].layers[0].document;
1546: doc.open();
1547: doc.write(content);
1548: doc.close();
1549: }
1550: NETSCAPE4
1551: } else {
1552: # Otherwise, we need to use semi-standards-compliant code
1553: # (technically, "innerHTML" isn't standard but the equivalent
1554: # is really scary, and every useful browser supports it
1555: return (<<DOMBASED);
1556: function change(name, content) {
1557: element = document.getElementById(name);
1558: element.innerHTML = content;
1559: }
1560: DOMBASED
1561: }
1562: }
1563:
1564: =pod
1565:
1.648 raeburn 1566: =item * &changable_area($name,$origContent):
1.256 matthew 1567:
1568: This provides a "changable area" that can be modified on the fly via
1569: the Javascript code provided in C<change_content_javascript>. $name is
1570: the name you will use to reference the area later; do not repeat the
1571: same name on a given HTML page more then once. $origContent is what
1572: the area will originally contain, which can be left blank.
1573:
1574: =cut
1575:
1576: sub changable_area {
1577: my ($name, $origContent) = @_;
1578:
1.258 albertel 1579: if ($env{'browser.type'} eq 'netscape' &&
1580: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1581: # If this is netscape 4, we need to use the Layer tag
1582: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1583: } else {
1584: return "<span id='$name'>$origContent</span>";
1585: }
1586: }
1587:
1588: =pod
1589:
1.648 raeburn 1590: =item * &viewport_geometry_js
1.590 raeburn 1591:
1592: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1593:
1594: =cut
1595:
1596:
1597: sub viewport_geometry_js {
1598: return <<"GEOMETRY";
1599: var Geometry = {};
1600: function init_geometry() {
1601: if (Geometry.init) { return };
1602: Geometry.init=1;
1603: if (window.innerHeight) {
1604: Geometry.getViewportHeight = function() { return window.innerHeight; };
1605: Geometry.getViewportWidth = function() { return window.innerWidth; };
1606: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1607: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1608: }
1609: else if (document.documentElement && document.documentElement.clientHeight) {
1610: Geometry.getViewportHeight =
1611: function() { return document.documentElement.clientHeight; };
1612: Geometry.getViewportWidth =
1613: function() { return document.documentElement.clientWidth; };
1614:
1615: Geometry.getHorizontalScroll =
1616: function() { return document.documentElement.scrollLeft; };
1617: Geometry.getVerticalScroll =
1618: function() { return document.documentElement.scrollTop; };
1619: }
1620: else if (document.body.clientHeight) {
1621: Geometry.getViewportHeight =
1622: function() { return document.body.clientHeight; };
1623: Geometry.getViewportWidth =
1624: function() { return document.body.clientWidth; };
1625: Geometry.getHorizontalScroll =
1626: function() { return document.body.scrollLeft; };
1627: Geometry.getVerticalScroll =
1628: function() { return document.body.scrollTop; };
1629: }
1630: }
1631:
1632: GEOMETRY
1633: }
1634:
1635: =pod
1636:
1.648 raeburn 1637: =item * &viewport_size_js()
1.590 raeburn 1638:
1639: 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.
1640:
1641: =cut
1642:
1643: sub viewport_size_js {
1644: my $geometry = &viewport_geometry_js();
1645: return <<"DIMS";
1646:
1647: $geometry
1648:
1649: function getViewportDims(width,height) {
1650: init_geometry();
1651: width.value = Geometry.getViewportWidth();
1652: height.value = Geometry.getViewportHeight();
1653: return;
1654: }
1655:
1656: DIMS
1657: }
1658:
1659: =pod
1660:
1.648 raeburn 1661: =item * &resize_textarea_js()
1.565 albertel 1662:
1663: emits the needed javascript to resize a textarea to be as big as possible
1664:
1665: creates a function resize_textrea that takes two IDs first should be
1666: the id of the element to resize, second should be the id of a div that
1667: surrounds everything that comes after the textarea, this routine needs
1668: to be attached to the <body> for the onload and onresize events.
1669:
1.648 raeburn 1670: =back
1.565 albertel 1671:
1672: =cut
1673:
1674: sub resize_textarea_js {
1.590 raeburn 1675: my $geometry = &viewport_geometry_js();
1.565 albertel 1676: return <<"RESIZE";
1677: <script type="text/javascript">
1.824 bisitz 1678: // <![CDATA[
1.590 raeburn 1679: $geometry
1.565 albertel 1680:
1.588 albertel 1681: function getX(element) {
1682: var x = 0;
1683: while (element) {
1684: x += element.offsetLeft;
1685: element = element.offsetParent;
1686: }
1687: return x;
1688: }
1689: function getY(element) {
1690: var y = 0;
1691: while (element) {
1692: y += element.offsetTop;
1693: element = element.offsetParent;
1694: }
1695: return y;
1696: }
1697:
1698:
1.565 albertel 1699: function resize_textarea(textarea_id,bottom_id) {
1700: init_geometry();
1701: var textarea = document.getElementById(textarea_id);
1702: //alert(textarea);
1703:
1.588 albertel 1704: var textarea_top = getY(textarea);
1.565 albertel 1705: var textarea_height = textarea.offsetHeight;
1706: var bottom = document.getElementById(bottom_id);
1.588 albertel 1707: var bottom_top = getY(bottom);
1.565 albertel 1708: var bottom_height = bottom.offsetHeight;
1709: var window_height = Geometry.getViewportHeight();
1.588 albertel 1710: var fudge = 23;
1.565 albertel 1711: var new_height = window_height-fudge-textarea_top-bottom_height;
1712: if (new_height < 300) {
1713: new_height = 300;
1714: }
1715: textarea.style.height=new_height+'px';
1716: }
1.824 bisitz 1717: // ]]>
1.565 albertel 1718: </script>
1719: RESIZE
1720:
1721: }
1722:
1723: =pod
1724:
1.256 matthew 1725: =head1 Excel and CSV file utility routines
1726:
1727: =cut
1728:
1729: ###############################################################
1730: ###############################################################
1731:
1732: =pod
1733:
1.1075.2.56! raeburn 1734: =over 4
! 1735:
1.648 raeburn 1736: =item * &csv_translate($text)
1.37 matthew 1737:
1.185 www 1738: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1739: format.
1740:
1741: =cut
1742:
1.180 matthew 1743: ###############################################################
1744: ###############################################################
1.37 matthew 1745: sub csv_translate {
1746: my $text = shift;
1747: $text =~ s/\"/\"\"/g;
1.209 albertel 1748: $text =~ s/\n/ /g;
1.37 matthew 1749: return $text;
1750: }
1.180 matthew 1751:
1752: ###############################################################
1753: ###############################################################
1754:
1755: =pod
1756:
1.648 raeburn 1757: =item * &define_excel_formats()
1.180 matthew 1758:
1759: Define some commonly used Excel cell formats.
1760:
1761: Currently supported formats:
1762:
1763: =over 4
1764:
1765: =item header
1766:
1767: =item bold
1768:
1769: =item h1
1770:
1771: =item h2
1772:
1773: =item h3
1774:
1.256 matthew 1775: =item h4
1776:
1777: =item i
1778:
1.180 matthew 1779: =item date
1780:
1781: =back
1782:
1783: Inputs: $workbook
1784:
1785: Returns: $format, a hash reference.
1786:
1.1057 foxr 1787:
1.180 matthew 1788: =cut
1789:
1790: ###############################################################
1791: ###############################################################
1792: sub define_excel_formats {
1793: my ($workbook) = @_;
1794: my $format;
1795: $format->{'header'} = $workbook->add_format(bold => 1,
1796: bottom => 1,
1797: align => 'center');
1798: $format->{'bold'} = $workbook->add_format(bold=>1);
1799: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1800: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1801: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1802: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1803: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1804: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1805: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1806: return $format;
1807: }
1808:
1809: ###############################################################
1810: ###############################################################
1.113 bowersj2 1811:
1812: =pod
1813:
1.648 raeburn 1814: =item * &create_workbook()
1.255 matthew 1815:
1816: Create an Excel worksheet. If it fails, output message on the
1817: request object and return undefs.
1818:
1819: Inputs: Apache request object
1820:
1821: Returns (undef) on failure,
1822: Excel worksheet object, scalar with filename, and formats
1823: from &Apache::loncommon::define_excel_formats on success
1824:
1825: =cut
1826:
1827: ###############################################################
1828: ###############################################################
1829: sub create_workbook {
1830: my ($r) = @_;
1831: #
1832: # Create the excel spreadsheet
1833: my $filename = '/prtspool/'.
1.258 albertel 1834: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1835: time.'_'.rand(1000000000).'.xls';
1836: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1837: if (! defined($workbook)) {
1838: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1839: $r->print(
1840: '<p class="LC_error">'
1841: .&mt('Problems occurred in creating the new Excel file.')
1842: .' '.&mt('This error has been logged.')
1843: .' '.&mt('Please alert your LON-CAPA administrator.')
1844: .'</p>'
1845: );
1.255 matthew 1846: return (undef);
1847: }
1848: #
1.1014 foxr 1849: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1850: #
1851: my $format = &Apache::loncommon::define_excel_formats($workbook);
1852: return ($workbook,$filename,$format);
1853: }
1854:
1855: ###############################################################
1856: ###############################################################
1857:
1858: =pod
1859:
1.648 raeburn 1860: =item * &create_text_file()
1.113 bowersj2 1861:
1.542 raeburn 1862: Create a file to write to and eventually make available to the user.
1.256 matthew 1863: If file creation fails, outputs an error message on the request object and
1864: return undefs.
1.113 bowersj2 1865:
1.256 matthew 1866: Inputs: Apache request object, and file suffix
1.113 bowersj2 1867:
1.256 matthew 1868: Returns (undef) on failure,
1869: Filehandle and filename on success.
1.113 bowersj2 1870:
1871: =cut
1872:
1.256 matthew 1873: ###############################################################
1874: ###############################################################
1875: sub create_text_file {
1876: my ($r,$suffix) = @_;
1877: if (! defined($suffix)) { $suffix = 'txt'; };
1878: my $fh;
1879: my $filename = '/prtspool/'.
1.258 albertel 1880: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1881: time.'_'.rand(1000000000).'.'.$suffix;
1882: $fh = Apache::File->new('>/home/httpd'.$filename);
1883: if (! defined($fh)) {
1884: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1885: $r->print(
1886: '<p class="LC_error">'
1887: .&mt('Problems occurred in creating the output file.')
1888: .' '.&mt('This error has been logged.')
1889: .' '.&mt('Please alert your LON-CAPA administrator.')
1890: .'</p>'
1891: );
1.113 bowersj2 1892: }
1.256 matthew 1893: return ($fh,$filename)
1.113 bowersj2 1894: }
1895:
1896:
1.256 matthew 1897: =pod
1.113 bowersj2 1898:
1899: =back
1900:
1901: =cut
1.37 matthew 1902:
1903: ###############################################################
1.33 matthew 1904: ## Home server <option> list generating code ##
1905: ###############################################################
1.35 matthew 1906:
1.169 www 1907: # ------------------------------------------
1908:
1909: sub domain_select {
1910: my ($name,$value,$multiple)=@_;
1911: my %domains=map {
1.514 albertel 1912: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1913: } &Apache::lonnet::all_domains();
1.169 www 1914: if ($multiple) {
1915: $domains{''}=&mt('Any domain');
1.550 albertel 1916: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1917: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1918: } else {
1.550 albertel 1919: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1920: return &select_form($name,$value,\%domains);
1.169 www 1921: }
1922: }
1923:
1.282 albertel 1924: #-------------------------------------------
1925:
1926: =pod
1927:
1.519 raeburn 1928: =head1 Routines for form select boxes
1929:
1930: =over 4
1931:
1.648 raeburn 1932: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1933:
1934: Returns a string containing a <select> element int multiple mode
1935:
1936:
1937: Args:
1938: $name - name of the <select> element
1.506 raeburn 1939: $value - scalar or array ref of values that should already be selected
1.282 albertel 1940: $size - number of rows long the select element is
1.283 albertel 1941: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1942: (shown text should already have been &mt())
1.506 raeburn 1943: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1944:
1.282 albertel 1945: =cut
1946:
1947: #-------------------------------------------
1.169 www 1948: sub multiple_select_form {
1.284 albertel 1949: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1950: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1951: my $output='';
1.191 matthew 1952: if (! defined($size)) {
1953: $size = 4;
1.283 albertel 1954: if (scalar(keys(%$hash))<4) {
1955: $size = scalar(keys(%$hash));
1.191 matthew 1956: }
1957: }
1.734 bisitz 1958: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1959: my @order;
1.506 raeburn 1960: if (ref($order) eq 'ARRAY') {
1961: @order = @{$order};
1962: } else {
1963: @order = sort(keys(%$hash));
1.501 banghart 1964: }
1965: if (exists($$hash{'select_form_order'})) {
1966: @order = @{$$hash{'select_form_order'}};
1967: }
1968:
1.284 albertel 1969: foreach my $key (@order) {
1.356 albertel 1970: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1971: $output.='selected="selected" ' if ($selected{$key});
1972: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1973: }
1974: $output.="</select>\n";
1975: return $output;
1976: }
1977:
1.88 www 1978: #-------------------------------------------
1979:
1980: =pod
1981:
1.970 raeburn 1982: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1983:
1984: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1985: allow a user to select options from a ref to a hash containing:
1986: option_name => displayed text. An optional $onchange can include
1987: a javascript onchange item, e.g., onchange="this.form.submit();"
1988:
1.88 www 1989: See lonrights.pm for an example invocation and use.
1990:
1991: =cut
1992:
1993: #-------------------------------------------
1994: sub select_form {
1.970 raeburn 1995: my ($def,$name,$hashref,$onchange) = @_;
1996: return unless (ref($hashref) eq 'HASH');
1997: if ($onchange) {
1998: $onchange = ' onchange="'.$onchange.'"';
1999: }
2000: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2001: my @keys;
1.970 raeburn 2002: if (exists($hashref->{'select_form_order'})) {
2003: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2004: } else {
1.970 raeburn 2005: @keys=sort(keys(%{$hashref}));
1.128 albertel 2006: }
1.356 albertel 2007: foreach my $key (@keys) {
2008: $selectform.=
2009: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2010: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2011: ">".$hashref->{$key}."</option>\n";
1.88 www 2012: }
2013: $selectform.="</select>";
2014: return $selectform;
2015: }
2016:
1.475 www 2017: # For display filters
2018:
2019: sub display_filter {
1.1074 raeburn 2020: my ($context) = @_;
1.475 www 2021: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2022: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2023: my $phraseinput = 'hidden';
2024: my $includeinput = 'hidden';
2025: my ($checked,$includetypestext);
2026: if ($env{'form.displayfilter'} eq 'containing') {
2027: $phraseinput = 'text';
2028: if ($context eq 'parmslog') {
2029: $includeinput = 'checkbox';
2030: if ($env{'form.includetypes'}) {
2031: $checked = ' checked="checked"';
2032: }
2033: $includetypestext = &mt('Include parameter types');
2034: }
2035: } else {
2036: $includetypestext = ' ';
2037: }
2038: my ($additional,$secondid,$thirdid);
2039: if ($context eq 'parmslog') {
2040: $additional =
2041: '<label><input type="'.$includeinput.'" name="includetypes"'.
2042: $checked.' name="includetypes" value="1" id="includetypes" />'.
2043: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2044: '</label>';
2045: $secondid = 'includetypes';
2046: $thirdid = 'includetypestext';
2047: }
2048: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2049: '$secondid','$thirdid')";
2050: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2051: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2052: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2053: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2054: &mt('Filter: [_1]',
1.477 www 2055: &select_form($env{'form.displayfilter'},
2056: 'displayfilter',
1.970 raeburn 2057: {'currentfolder' => 'Current folder/page',
1.477 www 2058: 'containing' => 'Containing phrase',
1.1074 raeburn 2059: 'none' => 'None'},$onchange)).' '.
2060: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2061: &HTML::Entities::encode($env{'form.containingphrase'}).
2062: '" />'.$additional;
2063: }
2064:
2065: sub display_filter_js {
2066: my $includetext = &mt('Include parameter types');
2067: return <<"ENDJS";
2068:
2069: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2070: var firstType = 'hidden';
2071: if (setter.options[setter.selectedIndex].value == 'containing') {
2072: firstType = 'text';
2073: }
2074: firstObject = document.getElementById(firstid);
2075: if (typeof(firstObject) == 'object') {
2076: if (firstObject.type != firstType) {
2077: changeInputType(firstObject,firstType);
2078: }
2079: }
2080: if (context == 'parmslog') {
2081: var secondType = 'hidden';
2082: if (firstType == 'text') {
2083: secondType = 'checkbox';
2084: }
2085: secondObject = document.getElementById(secondid);
2086: if (typeof(secondObject) == 'object') {
2087: if (secondObject.type != secondType) {
2088: changeInputType(secondObject,secondType);
2089: }
2090: }
2091: var textItem = document.getElementById(thirdid);
2092: var currtext = textItem.innerHTML;
2093: var newtext;
2094: if (firstType == 'text') {
2095: newtext = '$includetext';
2096: } else {
2097: newtext = ' ';
2098: }
2099: if (currtext != newtext) {
2100: textItem.innerHTML = newtext;
2101: }
2102: }
2103: return;
2104: }
2105:
2106: function changeInputType(oldObject,newType) {
2107: var newObject = document.createElement('input');
2108: newObject.type = newType;
2109: if (oldObject.size) {
2110: newObject.size = oldObject.size;
2111: }
2112: if (oldObject.value) {
2113: newObject.value = oldObject.value;
2114: }
2115: if (oldObject.name) {
2116: newObject.name = oldObject.name;
2117: }
2118: if (oldObject.id) {
2119: newObject.id = oldObject.id;
2120: }
2121: oldObject.parentNode.replaceChild(newObject,oldObject);
2122: return;
2123: }
2124:
2125: ENDJS
1.475 www 2126: }
2127:
1.167 www 2128: sub gradeleveldescription {
2129: my $gradelevel=shift;
2130: my %gradelevels=(0 => 'Not specified',
2131: 1 => 'Grade 1',
2132: 2 => 'Grade 2',
2133: 3 => 'Grade 3',
2134: 4 => 'Grade 4',
2135: 5 => 'Grade 5',
2136: 6 => 'Grade 6',
2137: 7 => 'Grade 7',
2138: 8 => 'Grade 8',
2139: 9 => 'Grade 9',
2140: 10 => 'Grade 10',
2141: 11 => 'Grade 11',
2142: 12 => 'Grade 12',
2143: 13 => 'Grade 13',
2144: 14 => '100 Level',
2145: 15 => '200 Level',
2146: 16 => '300 Level',
2147: 17 => '400 Level',
2148: 18 => 'Graduate Level');
2149: return &mt($gradelevels{$gradelevel});
2150: }
2151:
1.163 www 2152: sub select_level_form {
2153: my ($deflevel,$name)=@_;
2154: unless ($deflevel) { $deflevel=0; }
1.167 www 2155: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2156: for (my $i=0; $i<=18; $i++) {
2157: $selectform.="<option value=\"$i\" ".
1.253 albertel 2158: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2159: ">".&gradeleveldescription($i)."</option>\n";
2160: }
2161: $selectform.="</select>";
2162: return $selectform;
1.163 www 2163: }
1.167 www 2164:
1.35 matthew 2165: #-------------------------------------------
2166:
1.45 matthew 2167: =pod
2168:
1.1075.2.42 raeburn 2169: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2170:
2171: Returns a string containing a <select name='$name' size='1'> form to
2172: allow a user to select the domain to preform an operation in.
2173: See loncreateuser.pm for an example invocation and use.
2174:
1.90 www 2175: If the $includeempty flag is set, it also includes an empty choice ("no domain
2176: selected");
2177:
1.743 raeburn 2178: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2179:
1.910 raeburn 2180: 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.
2181:
1.1075.2.36 raeburn 2182: The optional $incdoms is a reference to an array of domains which will be the only available options.
2183:
2184: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2185:
1.35 matthew 2186: =cut
2187:
2188: #-------------------------------------------
1.34 matthew 2189: sub select_dom_form {
1.1075.2.36 raeburn 2190: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2191: if ($onchange) {
1.874 raeburn 2192: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2193: }
1.1075.2.36 raeburn 2194: my (@domains,%exclude);
1.910 raeburn 2195: if (ref($incdoms) eq 'ARRAY') {
2196: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2197: } else {
2198: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2199: }
1.90 www 2200: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2201: if (ref($excdoms) eq 'ARRAY') {
2202: map { $exclude{$_} = 1; } @{$excdoms};
2203: }
1.743 raeburn 2204: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2205: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2206: next if ($exclude{$dom});
1.356 albertel 2207: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2208: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2209: if ($showdomdesc) {
2210: if ($dom ne '') {
2211: my $domdesc = &Apache::lonnet::domain($dom,'description');
2212: if ($domdesc ne '') {
2213: $selectdomain .= ' ('.$domdesc.')';
2214: }
2215: }
2216: }
2217: $selectdomain .= "</option>\n";
1.34 matthew 2218: }
2219: $selectdomain.="</select>";
2220: return $selectdomain;
2221: }
2222:
1.35 matthew 2223: #-------------------------------------------
2224:
1.45 matthew 2225: =pod
2226:
1.648 raeburn 2227: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2228:
1.586 raeburn 2229: input: 4 arguments (two required, two optional) -
2230: $domain - domain of new user
2231: $name - name of form element
2232: $default - Value of 'default' causes a default item to be first
2233: option, and selected by default.
2234: $hide - Value of 'hide' causes hiding of the name of the server,
2235: if 1 server found, or default, if 0 found.
1.594 raeburn 2236: output: returns 2 items:
1.586 raeburn 2237: (a) form element which contains either:
2238: (i) <select name="$name">
2239: <option value="$hostid1">$hostid $servers{$hostid}</option>
2240: <option value="$hostid2">$hostid $servers{$hostid}</option>
2241: </select>
2242: form item if there are multiple library servers in $domain, or
2243: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2244: if there is only one library server in $domain.
2245:
2246: (b) number of library servers found.
2247:
2248: See loncreateuser.pm for example of use.
1.35 matthew 2249:
2250: =cut
2251:
2252: #-------------------------------------------
1.586 raeburn 2253: sub home_server_form_item {
2254: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2255: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2256: my $result;
2257: my $numlib = keys(%servers);
2258: if ($numlib > 1) {
2259: $result .= '<select name="'.$name.'" />'."\n";
2260: if ($default) {
1.804 bisitz 2261: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2262: '</option>'."\n";
2263: }
2264: foreach my $hostid (sort(keys(%servers))) {
2265: $result.= '<option value="'.$hostid.'">'.
2266: $hostid.' '.$servers{$hostid}."</option>\n";
2267: }
2268: $result .= '</select>'."\n";
2269: } elsif ($numlib == 1) {
2270: my $hostid;
2271: foreach my $item (keys(%servers)) {
2272: $hostid = $item;
2273: }
2274: $result .= '<input type="hidden" name="'.$name.'" value="'.
2275: $hostid.'" />';
2276: if (!$hide) {
2277: $result .= $hostid.' '.$servers{$hostid};
2278: }
2279: $result .= "\n";
2280: } elsif ($default) {
2281: $result .= '<input type="hidden" name="'.$name.
2282: '" value="default" />';
2283: if (!$hide) {
2284: $result .= &mt('default');
2285: }
2286: $result .= "\n";
1.33 matthew 2287: }
1.586 raeburn 2288: return ($result,$numlib);
1.33 matthew 2289: }
1.112 bowersj2 2290:
2291: =pod
2292:
1.534 albertel 2293: =back
2294:
1.112 bowersj2 2295: =cut
1.87 matthew 2296:
2297: ###############################################################
1.112 bowersj2 2298: ## Decoding User Agent ##
1.87 matthew 2299: ###############################################################
2300:
2301: =pod
2302:
1.112 bowersj2 2303: =head1 Decoding the User Agent
2304:
2305: =over 4
2306:
2307: =item * &decode_user_agent()
1.87 matthew 2308:
2309: Inputs: $r
2310:
2311: Outputs:
2312:
2313: =over 4
2314:
1.112 bowersj2 2315: =item * $httpbrowser
1.87 matthew 2316:
1.112 bowersj2 2317: =item * $clientbrowser
1.87 matthew 2318:
1.112 bowersj2 2319: =item * $clientversion
1.87 matthew 2320:
1.112 bowersj2 2321: =item * $clientmathml
1.87 matthew 2322:
1.112 bowersj2 2323: =item * $clientunicode
1.87 matthew 2324:
1.112 bowersj2 2325: =item * $clientos
1.87 matthew 2326:
1.1075.2.42 raeburn 2327: =item * $clientmobile
2328:
2329: =item * $clientinfo
2330:
1.87 matthew 2331: =back
2332:
1.157 matthew 2333: =back
2334:
1.87 matthew 2335: =cut
2336:
2337: ###############################################################
2338: ###############################################################
2339: sub decode_user_agent {
1.247 albertel 2340: my ($r)=@_;
1.87 matthew 2341: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2342: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2343: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2344: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2345: my $clientbrowser='unknown';
2346: my $clientversion='0';
2347: my $clientmathml='';
2348: my $clientunicode='0';
1.1075.2.42 raeburn 2349: my $clientmobile=0;
1.87 matthew 2350: for (my $i=0;$i<=$#browsertype;$i++) {
2351: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2352: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2353: $clientbrowser=$bname;
2354: $httpbrowser=~/$vreg/i;
2355: $clientversion=$1;
2356: $clientmathml=($clientversion>=$minv);
2357: $clientunicode=($clientversion>=$univ);
2358: }
2359: }
2360: my $clientos='unknown';
1.1075.2.42 raeburn 2361: my $clientinfo;
1.87 matthew 2362: if (($httpbrowser=~/linux/i) ||
2363: ($httpbrowser=~/unix/i) ||
2364: ($httpbrowser=~/ux/i) ||
2365: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2366: if (($httpbrowser=~/vax/i) ||
2367: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2368: if ($httpbrowser=~/next/i) { $clientos='next'; }
2369: if (($httpbrowser=~/mac/i) ||
2370: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2371: if ($httpbrowser=~/win/i) { $clientos='win'; }
2372: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2373: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2374: $clientmobile=lc($1);
2375: }
2376: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2377: $clientinfo = 'firefox-'.$1;
2378: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2379: $clientinfo = 'chromeframe-'.$1;
2380: }
1.87 matthew 2381: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42 raeburn 2382: $clientunicode,$clientos,$clientmobile,$clientinfo);
1.87 matthew 2383: }
2384:
1.32 matthew 2385: ###############################################################
2386: ## Authentication changing form generation subroutines ##
2387: ###############################################################
2388: ##
2389: ## All of the authform_xxxxxxx subroutines take their inputs in a
2390: ## hash, and have reasonable default values.
2391: ##
2392: ## formname = the name given in the <form> tag.
1.35 matthew 2393: #-------------------------------------------
2394:
1.45 matthew 2395: =pod
2396:
1.112 bowersj2 2397: =head1 Authentication Routines
2398:
2399: =over 4
2400:
1.648 raeburn 2401: =item * &authform_xxxxxx()
1.35 matthew 2402:
2403: The authform_xxxxxx subroutines provide javascript and html forms which
2404: handle some of the conveniences required for authentication forms.
2405: This is not an optimal method, but it works.
2406:
2407: =over 4
2408:
1.112 bowersj2 2409: =item * authform_header
1.35 matthew 2410:
1.112 bowersj2 2411: =item * authform_authorwarning
1.35 matthew 2412:
1.112 bowersj2 2413: =item * authform_nochange
1.35 matthew 2414:
1.112 bowersj2 2415: =item * authform_kerberos
1.35 matthew 2416:
1.112 bowersj2 2417: =item * authform_internal
1.35 matthew 2418:
1.112 bowersj2 2419: =item * authform_filesystem
1.35 matthew 2420:
2421: =back
2422:
1.648 raeburn 2423: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2424:
1.35 matthew 2425: =cut
2426:
2427: #-------------------------------------------
1.32 matthew 2428: sub authform_header{
2429: my %in = (
2430: formname => 'cu',
1.80 albertel 2431: kerb_def_dom => '',
1.32 matthew 2432: @_,
2433: );
2434: $in{'formname'} = 'document.' . $in{'formname'};
2435: my $result='';
1.80 albertel 2436:
2437: #---------------------------------------------- Code for upper case translation
2438: my $Javascript_toUpperCase;
2439: unless ($in{kerb_def_dom}) {
2440: $Javascript_toUpperCase =<<"END";
2441: switch (choice) {
2442: case 'krb': currentform.elements[choicearg].value =
2443: currentform.elements[choicearg].value.toUpperCase();
2444: break;
2445: default:
2446: }
2447: END
2448: } else {
2449: $Javascript_toUpperCase = "";
2450: }
2451:
1.165 raeburn 2452: my $radioval = "'nochange'";
1.591 raeburn 2453: if (defined($in{'curr_authtype'})) {
2454: if ($in{'curr_authtype'} ne '') {
2455: $radioval = "'".$in{'curr_authtype'}."arg'";
2456: }
1.174 matthew 2457: }
1.165 raeburn 2458: my $argfield = 'null';
1.591 raeburn 2459: if (defined($in{'mode'})) {
1.165 raeburn 2460: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2461: if (defined($in{'curr_autharg'})) {
2462: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2463: $argfield = "'$in{'curr_autharg'}'";
2464: }
2465: }
2466: }
2467: }
2468:
1.32 matthew 2469: $result.=<<"END";
2470: var current = new Object();
1.165 raeburn 2471: current.radiovalue = $radioval;
2472: current.argfield = $argfield;
1.32 matthew 2473:
2474: function changed_radio(choice,currentform) {
2475: var choicearg = choice + 'arg';
2476: // If a radio button in changed, we need to change the argfield
2477: if (current.radiovalue != choice) {
2478: current.radiovalue = choice;
2479: if (current.argfield != null) {
2480: currentform.elements[current.argfield].value = '';
2481: }
2482: if (choice == 'nochange') {
2483: current.argfield = null;
2484: } else {
2485: current.argfield = choicearg;
2486: switch(choice) {
2487: case 'krb':
2488: currentform.elements[current.argfield].value =
2489: "$in{'kerb_def_dom'}";
2490: break;
2491: default:
2492: break;
2493: }
2494: }
2495: }
2496: return;
2497: }
1.22 www 2498:
1.32 matthew 2499: function changed_text(choice,currentform) {
2500: var choicearg = choice + 'arg';
2501: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2502: $Javascript_toUpperCase
1.32 matthew 2503: // clear old field
2504: if ((current.argfield != choicearg) && (current.argfield != null)) {
2505: currentform.elements[current.argfield].value = '';
2506: }
2507: current.argfield = choicearg;
2508: }
2509: set_auth_radio_buttons(choice,currentform);
2510: return;
1.20 www 2511: }
1.32 matthew 2512:
2513: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2514: var numauthchoices = currentform.login.length;
2515: if (typeof numauthchoices == "undefined") {
2516: return;
2517: }
1.32 matthew 2518: var i=0;
1.986 raeburn 2519: while (i < numauthchoices) {
1.32 matthew 2520: if (currentform.login[i].value == newvalue) { break; }
2521: i++;
2522: }
1.986 raeburn 2523: if (i == numauthchoices) {
1.32 matthew 2524: return;
2525: }
2526: current.radiovalue = newvalue;
2527: currentform.login[i].checked = true;
2528: return;
2529: }
2530: END
2531: return $result;
2532: }
2533:
1.1075.2.20 raeburn 2534: sub authform_authorwarning {
1.32 matthew 2535: my $result='';
1.144 matthew 2536: $result='<i>'.
2537: &mt('As a general rule, only authors or co-authors should be '.
2538: 'filesystem authenticated '.
2539: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2540: return $result;
2541: }
2542:
1.1075.2.20 raeburn 2543: sub authform_nochange {
1.32 matthew 2544: my %in = (
2545: formname => 'document.cu',
2546: kerb_def_dom => 'MSU.EDU',
2547: @_,
2548: );
1.1075.2.20 raeburn 2549: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2550: my $result;
1.1075.2.20 raeburn 2551: if (!$authnum) {
2552: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2553: } else {
2554: $result = '<label>'.&mt('[_1] Do not change login data',
2555: '<input type="radio" name="login" value="nochange" '.
2556: 'checked="checked" onclick="'.
1.281 albertel 2557: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2558: '</label>';
1.586 raeburn 2559: }
1.32 matthew 2560: return $result;
2561: }
2562:
1.591 raeburn 2563: sub authform_kerberos {
1.32 matthew 2564: my %in = (
2565: formname => 'document.cu',
2566: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2567: kerb_def_auth => 'krb4',
1.32 matthew 2568: @_,
2569: );
1.586 raeburn 2570: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2571: $autharg,$jscall);
1.1075.2.20 raeburn 2572: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2573: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2574: $check5 = ' checked="checked"';
1.80 albertel 2575: } else {
1.772 bisitz 2576: $check4 = ' checked="checked"';
1.80 albertel 2577: }
1.165 raeburn 2578: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2579: if (defined($in{'curr_authtype'})) {
2580: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2581: $krbcheck = ' checked="checked"';
1.623 raeburn 2582: if (defined($in{'mode'})) {
2583: if ($in{'mode'} eq 'modifyuser') {
2584: $krbcheck = '';
2585: }
2586: }
1.591 raeburn 2587: if (defined($in{'curr_kerb_ver'})) {
2588: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2589: $check5 = ' checked="checked"';
1.591 raeburn 2590: $check4 = '';
2591: } else {
1.772 bisitz 2592: $check4 = ' checked="checked"';
1.591 raeburn 2593: $check5 = '';
2594: }
1.586 raeburn 2595: }
1.591 raeburn 2596: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2597: $krbarg = $in{'curr_autharg'};
2598: }
1.586 raeburn 2599: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2600: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2601: $result =
2602: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2603: $in{'curr_autharg'},$krbver);
2604: } else {
2605: $result =
2606: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2607: }
2608: return $result;
2609: }
2610: }
2611: } else {
2612: if ($authnum == 1) {
1.784 bisitz 2613: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2614: }
2615: }
1.586 raeburn 2616: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2617: return;
1.587 raeburn 2618: } elsif ($authtype eq '') {
1.591 raeburn 2619: if (defined($in{'mode'})) {
1.587 raeburn 2620: if ($in{'mode'} eq 'modifycourse') {
2621: if ($authnum == 1) {
1.1075.2.20 raeburn 2622: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2623: }
2624: }
2625: }
1.586 raeburn 2626: }
2627: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2628: if ($authtype eq '') {
2629: $authtype = '<input type="radio" name="login" value="krb" '.
2630: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2631: $krbcheck.' />';
2632: }
2633: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2634: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2635: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2636: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2637: $in{'curr_authtype'} eq 'krb4')) {
2638: $result .= &mt
1.144 matthew 2639: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2640: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2641: '<label>'.$authtype,
1.281 albertel 2642: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2643: 'value="'.$krbarg.'" '.
1.144 matthew 2644: 'onchange="'.$jscall.'" />',
1.281 albertel 2645: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2646: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2647: '</label>');
1.586 raeburn 2648: } elsif ($can_assign{'krb4'}) {
2649: $result .= &mt
2650: ('[_1] Kerberos authenticated with domain [_2] '.
2651: '[_3] Version 4 [_4]',
2652: '<label>'.$authtype,
2653: '</label><input type="text" size="10" name="krbarg" '.
2654: 'value="'.$krbarg.'" '.
2655: 'onchange="'.$jscall.'" />',
2656: '<label><input type="hidden" name="krbver" value="4" />',
2657: '</label>');
2658: } elsif ($can_assign{'krb5'}) {
2659: $result .= &mt
2660: ('[_1] Kerberos authenticated with domain [_2] '.
2661: '[_3] Version 5 [_4]',
2662: '<label>'.$authtype,
2663: '</label><input type="text" size="10" name="krbarg" '.
2664: 'value="'.$krbarg.'" '.
2665: 'onchange="'.$jscall.'" />',
2666: '<label><input type="hidden" name="krbver" value="5" />',
2667: '</label>');
2668: }
1.32 matthew 2669: return $result;
2670: }
2671:
1.1075.2.20 raeburn 2672: sub authform_internal {
1.586 raeburn 2673: my %in = (
1.32 matthew 2674: formname => 'document.cu',
2675: kerb_def_dom => 'MSU.EDU',
2676: @_,
2677: );
1.586 raeburn 2678: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2679: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2680: if (defined($in{'curr_authtype'})) {
2681: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2682: if ($can_assign{'int'}) {
1.772 bisitz 2683: $intcheck = 'checked="checked" ';
1.623 raeburn 2684: if (defined($in{'mode'})) {
2685: if ($in{'mode'} eq 'modifyuser') {
2686: $intcheck = '';
2687: }
2688: }
1.591 raeburn 2689: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2690: $intarg = $in{'curr_autharg'};
2691: }
2692: } else {
2693: $result = &mt('Currently internally authenticated.');
2694: return $result;
1.165 raeburn 2695: }
2696: }
1.586 raeburn 2697: } else {
2698: if ($authnum == 1) {
1.784 bisitz 2699: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2700: }
2701: }
2702: if (!$can_assign{'int'}) {
2703: return;
1.587 raeburn 2704: } elsif ($authtype eq '') {
1.591 raeburn 2705: if (defined($in{'mode'})) {
1.587 raeburn 2706: if ($in{'mode'} eq 'modifycourse') {
2707: if ($authnum == 1) {
1.1075.2.20 raeburn 2708: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2709: }
2710: }
2711: }
1.165 raeburn 2712: }
1.586 raeburn 2713: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2714: if ($authtype eq '') {
2715: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2716: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2717: }
1.605 bisitz 2718: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2719: $intarg.'" onchange="'.$jscall.'" />';
2720: $result = &mt
1.144 matthew 2721: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2722: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2723: $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 2724: return $result;
2725: }
2726:
1.1075.2.20 raeburn 2727: sub authform_local {
1.32 matthew 2728: my %in = (
2729: formname => 'document.cu',
2730: kerb_def_dom => 'MSU.EDU',
2731: @_,
2732: );
1.586 raeburn 2733: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2734: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2735: if (defined($in{'curr_authtype'})) {
2736: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2737: if ($can_assign{'loc'}) {
1.772 bisitz 2738: $loccheck = 'checked="checked" ';
1.623 raeburn 2739: if (defined($in{'mode'})) {
2740: if ($in{'mode'} eq 'modifyuser') {
2741: $loccheck = '';
2742: }
2743: }
1.591 raeburn 2744: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2745: $locarg = $in{'curr_autharg'};
2746: }
2747: } else {
2748: $result = &mt('Currently using local (institutional) authentication.');
2749: return $result;
1.165 raeburn 2750: }
2751: }
1.586 raeburn 2752: } else {
2753: if ($authnum == 1) {
1.784 bisitz 2754: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2755: }
2756: }
2757: if (!$can_assign{'loc'}) {
2758: return;
1.587 raeburn 2759: } elsif ($authtype eq '') {
1.591 raeburn 2760: if (defined($in{'mode'})) {
1.587 raeburn 2761: if ($in{'mode'} eq 'modifycourse') {
2762: if ($authnum == 1) {
1.1075.2.20 raeburn 2763: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2764: }
2765: }
2766: }
1.165 raeburn 2767: }
1.586 raeburn 2768: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2769: if ($authtype eq '') {
2770: $authtype = '<input type="radio" name="login" value="loc" '.
2771: $loccheck.' onchange="'.$jscall.'" onclick="'.
2772: $jscall.'" />';
2773: }
2774: $autharg = '<input type="text" size="10" name="locarg" value="'.
2775: $locarg.'" onchange="'.$jscall.'" />';
2776: $result = &mt('[_1] Local Authentication with argument [_2]',
2777: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2778: return $result;
2779: }
2780:
1.1075.2.20 raeburn 2781: sub authform_filesystem {
1.32 matthew 2782: my %in = (
2783: formname => 'document.cu',
2784: kerb_def_dom => 'MSU.EDU',
2785: @_,
2786: );
1.586 raeburn 2787: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2788: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2789: if (defined($in{'curr_authtype'})) {
2790: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2791: if ($can_assign{'fsys'}) {
1.772 bisitz 2792: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2793: if (defined($in{'mode'})) {
2794: if ($in{'mode'} eq 'modifyuser') {
2795: $fsyscheck = '';
2796: }
2797: }
1.586 raeburn 2798: } else {
2799: $result = &mt('Currently Filesystem Authenticated.');
2800: return $result;
2801: }
2802: }
2803: } else {
2804: if ($authnum == 1) {
1.784 bisitz 2805: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2806: }
2807: }
2808: if (!$can_assign{'fsys'}) {
2809: return;
1.587 raeburn 2810: } elsif ($authtype eq '') {
1.591 raeburn 2811: if (defined($in{'mode'})) {
1.587 raeburn 2812: if ($in{'mode'} eq 'modifycourse') {
2813: if ($authnum == 1) {
1.1075.2.20 raeburn 2814: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2815: }
2816: }
2817: }
1.586 raeburn 2818: }
2819: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2820: if ($authtype eq '') {
2821: $authtype = '<input type="radio" name="login" value="fsys" '.
2822: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2823: $jscall.'" />';
2824: }
2825: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2826: ' onchange="'.$jscall.'" />';
2827: $result = &mt
1.144 matthew 2828: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2829: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2830: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2831: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2832: 'onchange="'.$jscall.'" />');
1.32 matthew 2833: return $result;
2834: }
2835:
1.586 raeburn 2836: sub get_assignable_auth {
2837: my ($dom) = @_;
2838: if ($dom eq '') {
2839: $dom = $env{'request.role.domain'};
2840: }
2841: my %can_assign = (
2842: krb4 => 1,
2843: krb5 => 1,
2844: int => 1,
2845: loc => 1,
2846: );
2847: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2848: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2849: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2850: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2851: my $context;
2852: if ($env{'request.role'} =~ /^au/) {
2853: $context = 'author';
2854: } elsif ($env{'request.role'} =~ /^dc/) {
2855: $context = 'domain';
2856: } elsif ($env{'request.course.id'}) {
2857: $context = 'course';
2858: }
2859: if ($context) {
2860: if (ref($authhash->{$context}) eq 'HASH') {
2861: %can_assign = %{$authhash->{$context}};
2862: }
2863: }
2864: }
2865: }
2866: my $authnum = 0;
2867: foreach my $key (keys(%can_assign)) {
2868: if ($can_assign{$key}) {
2869: $authnum ++;
2870: }
2871: }
2872: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2873: $authnum --;
2874: }
2875: return ($authnum,%can_assign);
2876: }
2877:
1.80 albertel 2878: ###############################################################
2879: ## Get Kerberos Defaults for Domain ##
2880: ###############################################################
2881: ##
2882: ## Returns default kerberos version and an associated argument
2883: ## as listed in file domain.tab. If not listed, provides
2884: ## appropriate default domain and kerberos version.
2885: ##
2886: #-------------------------------------------
2887:
2888: =pod
2889:
1.648 raeburn 2890: =item * &get_kerberos_defaults()
1.80 albertel 2891:
2892: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2893: version and domain. If not found, it defaults to version 4 and the
2894: domain of the server.
1.80 albertel 2895:
1.648 raeburn 2896: =over 4
2897:
1.80 albertel 2898: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2899:
1.648 raeburn 2900: =back
2901:
2902: =back
2903:
1.80 albertel 2904: =cut
2905:
2906: #-------------------------------------------
2907: sub get_kerberos_defaults {
2908: my $domain=shift;
1.641 raeburn 2909: my ($krbdef,$krbdefdom);
2910: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2911: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2912: $krbdef = $domdefaults{'auth_def'};
2913: $krbdefdom = $domdefaults{'auth_arg_def'};
2914: } else {
1.80 albertel 2915: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2916: my $krbdefdom=$1;
2917: $krbdefdom=~tr/a-z/A-Z/;
2918: $krbdef = "krb4";
2919: }
2920: return ($krbdef,$krbdefdom);
2921: }
1.112 bowersj2 2922:
1.32 matthew 2923:
1.46 matthew 2924: ###############################################################
2925: ## Thesaurus Functions ##
2926: ###############################################################
1.20 www 2927:
1.46 matthew 2928: =pod
1.20 www 2929:
1.112 bowersj2 2930: =head1 Thesaurus Functions
2931:
2932: =over 4
2933:
1.648 raeburn 2934: =item * &initialize_keywords()
1.46 matthew 2935:
2936: Initializes the package variable %Keywords if it is empty. Uses the
2937: package variable $thesaurus_db_file.
2938:
2939: =cut
2940:
2941: ###################################################
2942:
2943: sub initialize_keywords {
2944: return 1 if (scalar keys(%Keywords));
2945: # If we are here, %Keywords is empty, so fill it up
2946: # Make sure the file we need exists...
2947: if (! -e $thesaurus_db_file) {
2948: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2949: " failed because it does not exist");
2950: return 0;
2951: }
2952: # Set up the hash as a database
2953: my %thesaurus_db;
2954: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2955: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2956: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2957: $thesaurus_db_file);
2958: return 0;
2959: }
2960: # Get the average number of appearances of a word.
2961: my $avecount = $thesaurus_db{'average.count'};
2962: # Put keywords (those that appear > average) into %Keywords
2963: while (my ($word,$data)=each (%thesaurus_db)) {
2964: my ($count,undef) = split /:/,$data;
2965: $Keywords{$word}++ if ($count > $avecount);
2966: }
2967: untie %thesaurus_db;
2968: # Remove special values from %Keywords.
1.356 albertel 2969: foreach my $value ('total.count','average.count') {
2970: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2971: }
1.46 matthew 2972: return 1;
2973: }
2974:
2975: ###################################################
2976:
2977: =pod
2978:
1.648 raeburn 2979: =item * &keyword($word)
1.46 matthew 2980:
2981: Returns true if $word is a keyword. A keyword is a word that appears more
2982: than the average number of times in the thesaurus database. Calls
2983: &initialize_keywords
2984:
2985: =cut
2986:
2987: ###################################################
1.20 www 2988:
2989: sub keyword {
1.46 matthew 2990: return if (!&initialize_keywords());
2991: my $word=lc(shift());
2992: $word=~s/\W//g;
2993: return exists($Keywords{$word});
1.20 www 2994: }
1.46 matthew 2995:
2996: ###############################################################
2997:
2998: =pod
1.20 www 2999:
1.648 raeburn 3000: =item * &get_related_words()
1.46 matthew 3001:
1.160 matthew 3002: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3003: an array of words. If the keyword is not in the thesaurus, an empty array
3004: will be returned. The order of the words returned is determined by the
3005: database which holds them.
3006:
3007: Uses global $thesaurus_db_file.
3008:
1.1057 foxr 3009:
1.46 matthew 3010: =cut
3011:
3012: ###############################################################
3013: sub get_related_words {
3014: my $keyword = shift;
3015: my %thesaurus_db;
3016: if (! -e $thesaurus_db_file) {
3017: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3018: "failed because the file does not exist");
3019: return ();
3020: }
3021: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3022: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3023: return ();
3024: }
3025: my @Words=();
1.429 www 3026: my $count=0;
1.46 matthew 3027: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3028: # The first element is the number of times
3029: # the word appears. We do not need it now.
1.429 www 3030: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3031: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3032: my $threshold=$mostfrequentcount/10;
3033: foreach my $possibleword (@RelatedWords) {
3034: my ($word,$wordcount)=split(/\,/,$possibleword);
3035: if ($wordcount>$threshold) {
3036: push(@Words,$word);
3037: $count++;
3038: if ($count>10) { last; }
3039: }
1.20 www 3040: }
3041: }
1.46 matthew 3042: untie %thesaurus_db;
3043: return @Words;
1.14 harris41 3044: }
1.46 matthew 3045:
1.112 bowersj2 3046: =pod
3047:
3048: =back
3049:
3050: =cut
1.61 www 3051:
3052: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3053: =pod
3054:
1.112 bowersj2 3055: =head1 User Name Functions
3056:
3057: =over 4
3058:
1.648 raeburn 3059: =item * &plainname($uname,$udom,$first)
1.81 albertel 3060:
1.112 bowersj2 3061: Takes a users logon name and returns it as a string in
1.226 albertel 3062: "first middle last generation" form
3063: if $first is set to 'lastname' then it returns it as
3064: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3065:
3066: =cut
1.61 www 3067:
1.295 www 3068:
1.81 albertel 3069: ###############################################################
1.61 www 3070: sub plainname {
1.226 albertel 3071: my ($uname,$udom,$first)=@_;
1.537 albertel 3072: return if (!defined($uname) || !defined($udom));
1.295 www 3073: my %names=&getnames($uname,$udom);
1.226 albertel 3074: my $name=&Apache::lonnet::format_name($names{'firstname'},
3075: $names{'middlename'},
3076: $names{'lastname'},
3077: $names{'generation'},$first);
3078: $name=~s/^\s+//;
1.62 www 3079: $name=~s/\s+$//;
3080: $name=~s/\s+/ /g;
1.353 albertel 3081: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3082: return $name;
1.61 www 3083: }
1.66 www 3084:
3085: # -------------------------------------------------------------------- Nickname
1.81 albertel 3086: =pod
3087:
1.648 raeburn 3088: =item * &nickname($uname,$udom)
1.81 albertel 3089:
3090: Gets a users name and returns it as a string as
3091:
3092: ""nickname""
1.66 www 3093:
1.81 albertel 3094: if the user has a nickname or
3095:
3096: "first middle last generation"
3097:
3098: if the user does not
3099:
3100: =cut
1.66 www 3101:
3102: sub nickname {
3103: my ($uname,$udom)=@_;
1.537 albertel 3104: return if (!defined($uname) || !defined($udom));
1.295 www 3105: my %names=&getnames($uname,$udom);
1.68 albertel 3106: my $name=$names{'nickname'};
1.66 www 3107: if ($name) {
3108: $name='"'.$name.'"';
3109: } else {
3110: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3111: $names{'lastname'}.' '.$names{'generation'};
3112: $name=~s/\s+$//;
3113: $name=~s/\s+/ /g;
3114: }
3115: return $name;
3116: }
3117:
1.295 www 3118: sub getnames {
3119: my ($uname,$udom)=@_;
1.537 albertel 3120: return if (!defined($uname) || !defined($udom));
1.433 albertel 3121: if ($udom eq 'public' && $uname eq 'public') {
3122: return ('lastname' => &mt('Public'));
3123: }
1.295 www 3124: my $id=$uname.':'.$udom;
3125: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3126: if ($cached) {
3127: return %{$names};
3128: } else {
3129: my %loadnames=&Apache::lonnet::get('environment',
3130: ['firstname','middlename','lastname','generation','nickname'],
3131: $udom,$uname);
3132: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3133: return %loadnames;
3134: }
3135: }
1.61 www 3136:
1.542 raeburn 3137: # -------------------------------------------------------------------- getemails
1.648 raeburn 3138:
1.542 raeburn 3139: =pod
3140:
1.648 raeburn 3141: =item * &getemails($uname,$udom)
1.542 raeburn 3142:
3143: Gets a user's email information and returns it as a hash with keys:
3144: notification, critnotification, permanentemail
3145:
3146: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3147: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3148:
1.648 raeburn 3149:
1.542 raeburn 3150: =cut
3151:
1.648 raeburn 3152:
1.466 albertel 3153: sub getemails {
3154: my ($uname,$udom)=@_;
3155: if ($udom eq 'public' && $uname eq 'public') {
3156: return;
3157: }
1.467 www 3158: if (!$udom) { $udom=$env{'user.domain'}; }
3159: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3160: my $id=$uname.':'.$udom;
3161: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3162: if ($cached) {
3163: return %{$names};
3164: } else {
3165: my %loadnames=&Apache::lonnet::get('environment',
3166: ['notification','critnotification',
3167: 'permanentemail'],
3168: $udom,$uname);
3169: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3170: return %loadnames;
3171: }
3172: }
3173:
1.551 albertel 3174: sub flush_email_cache {
3175: my ($uname,$udom)=@_;
3176: if (!$udom) { $udom =$env{'user.domain'}; }
3177: if (!$uname) { $uname=$env{'user.name'}; }
3178: return if ($udom eq 'public' && $uname eq 'public');
3179: my $id=$uname.':'.$udom;
3180: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3181: }
3182:
1.728 raeburn 3183: # -------------------------------------------------------------------- getlangs
3184:
3185: =pod
3186:
3187: =item * &getlangs($uname,$udom)
3188:
3189: Gets a user's language preference and returns it as a hash with key:
3190: language.
3191:
3192: =cut
3193:
3194:
3195: sub getlangs {
3196: my ($uname,$udom) = @_;
3197: if (!$udom) { $udom =$env{'user.domain'}; }
3198: if (!$uname) { $uname=$env{'user.name'}; }
3199: my $id=$uname.':'.$udom;
3200: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3201: if ($cached) {
3202: return %{$langs};
3203: } else {
3204: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3205: $udom,$uname);
3206: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3207: return %loadlangs;
3208: }
3209: }
3210:
3211: sub flush_langs_cache {
3212: my ($uname,$udom)=@_;
3213: if (!$udom) { $udom =$env{'user.domain'}; }
3214: if (!$uname) { $uname=$env{'user.name'}; }
3215: return if ($udom eq 'public' && $uname eq 'public');
3216: my $id=$uname.':'.$udom;
3217: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3218: }
3219:
1.61 www 3220: # ------------------------------------------------------------------ Screenname
1.81 albertel 3221:
3222: =pod
3223:
1.648 raeburn 3224: =item * &screenname($uname,$udom)
1.81 albertel 3225:
3226: Gets a users screenname and returns it as a string
3227:
3228: =cut
1.61 www 3229:
3230: sub screenname {
3231: my ($uname,$udom)=@_;
1.258 albertel 3232: if ($uname eq $env{'user.name'} &&
3233: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3234: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3235: return $names{'screenname'};
1.62 www 3236: }
3237:
1.212 albertel 3238:
1.802 bisitz 3239: # ------------------------------------------------------------- Confirm Wrapper
3240: =pod
3241:
1.1075.2.42 raeburn 3242: =item * &confirmwrapper($message)
1.802 bisitz 3243:
3244: Wrap messages about completion of operation in box
3245:
3246: =cut
3247:
3248: sub confirmwrapper {
3249: my ($message)=@_;
3250: if ($message) {
3251: return "\n".'<div class="LC_confirm_box">'."\n"
3252: .$message."\n"
3253: .'</div>'."\n";
3254: } else {
3255: return $message;
3256: }
3257: }
3258:
1.62 www 3259: # ------------------------------------------------------------- Message Wrapper
3260:
3261: sub messagewrapper {
1.369 www 3262: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3263: return
1.441 albertel 3264: '<a href="/adm/email?compose=individual&'.
3265: 'recname='.$username.'&recdom='.$domain.
3266: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3267: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3268: }
1.802 bisitz 3269:
1.74 www 3270: # --------------------------------------------------------------- Notes Wrapper
3271:
3272: sub noteswrapper {
3273: my ($link,$un,$do)=@_;
3274: return
1.896 amueller 3275: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3276: }
1.802 bisitz 3277:
1.62 www 3278: # ------------------------------------------------------------- Aboutme Wrapper
3279:
3280: sub aboutmewrapper {
1.1070 raeburn 3281: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3282: if (!defined($username) && !defined($domain)) {
3283: return;
3284: }
1.1075.2.15 raeburn 3285: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3286: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3287: }
3288:
3289: # ------------------------------------------------------------ Syllabus Wrapper
3290:
3291: sub syllabuswrapper {
1.707 bisitz 3292: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3293: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3294: }
1.14 harris41 3295:
1.802 bisitz 3296: # -----------------------------------------------------------------------------
3297:
1.208 matthew 3298: sub track_student_link {
1.887 raeburn 3299: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3300: my $link ="/adm/trackstudent?";
1.208 matthew 3301: my $title = 'View recent activity';
3302: if (defined($sname) && $sname !~ /^\s*$/ &&
3303: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3304: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3305: $title .= ' of this student';
1.268 albertel 3306: }
1.208 matthew 3307: if (defined($target) && $target !~ /^\s*$/) {
3308: $target = qq{target="$target"};
3309: } else {
3310: $target = '';
3311: }
1.268 albertel 3312: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3313: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3314: $title = &mt($title);
3315: $linktext = &mt($linktext);
1.448 albertel 3316: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3317: &help_open_topic('View_recent_activity');
1.208 matthew 3318: }
3319:
1.781 raeburn 3320: sub slot_reservations_link {
3321: my ($linktext,$sname,$sdom,$target) = @_;
3322: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3323: my $title = 'View slot reservation history';
3324: if (defined($sname) && $sname !~ /^\s*$/ &&
3325: defined($sdom) && $sdom !~ /^\s*$/) {
3326: $link .= "&uname=$sname&udom=$sdom";
3327: $title .= ' of this student';
3328: }
3329: if (defined($target) && $target !~ /^\s*$/) {
3330: $target = qq{target="$target"};
3331: } else {
3332: $target = '';
3333: }
3334: $title = &mt($title);
3335: $linktext = &mt($linktext);
3336: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3337: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3338:
3339: }
3340:
1.508 www 3341: # ===================================================== Display a student photo
3342:
3343:
1.509 albertel 3344: sub student_image_tag {
1.508 www 3345: my ($domain,$user)=@_;
3346: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3347: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3348: return '<img src="'.$imgsrc.'" align="right" />';
3349: } else {
3350: return '';
3351: }
3352: }
3353:
1.112 bowersj2 3354: =pod
3355:
3356: =back
3357:
3358: =head1 Access .tab File Data
3359:
3360: =over 4
3361:
1.648 raeburn 3362: =item * &languageids()
1.112 bowersj2 3363:
3364: returns list of all language ids
3365:
3366: =cut
3367:
1.14 harris41 3368: sub languageids {
1.16 harris41 3369: return sort(keys(%language));
1.14 harris41 3370: }
3371:
1.112 bowersj2 3372: =pod
3373:
1.648 raeburn 3374: =item * &languagedescription()
1.112 bowersj2 3375:
3376: returns description of a specified language id
3377:
3378: =cut
3379:
1.14 harris41 3380: sub languagedescription {
1.125 www 3381: my $code=shift;
3382: return ($supported_language{$code}?'* ':'').
3383: $language{$code}.
1.126 www 3384: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3385: }
3386:
1.1048 foxr 3387: =pod
3388:
3389: =item * &plainlanguagedescription
3390:
3391: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3392: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3393:
3394: =cut
3395:
1.145 www 3396: sub plainlanguagedescription {
3397: my $code=shift;
3398: return $language{$code};
3399: }
3400:
1.1048 foxr 3401: =pod
3402:
3403: =item * &supportedlanguagecode
3404:
3405: Returns the supported language code (e.g. sptutf maps to pt) given a language
3406: code.
3407:
3408: =cut
3409:
1.145 www 3410: sub supportedlanguagecode {
3411: my $code=shift;
3412: return $supported_language{$code};
1.97 www 3413: }
3414:
1.112 bowersj2 3415: =pod
3416:
1.1048 foxr 3417: =item * &latexlanguage()
3418:
3419: Given a language key code returns the correspondnig language to use
3420: to select the correct hyphenation on LaTeX printouts. This is undef if there
3421: is no supported hyphenation for the language code.
3422:
3423: =cut
3424:
3425: sub latexlanguage {
3426: my $code = shift;
3427: return $latex_language{$code};
3428: }
3429:
3430: =pod
3431:
3432: =item * &latexhyphenation()
3433:
3434: Same as above but what's supplied is the language as it might be stored
3435: in the metadata.
3436:
3437: =cut
3438:
3439: sub latexhyphenation {
3440: my $key = shift;
3441: return $latex_language_bykey{$key};
3442: }
3443:
3444: =pod
3445:
1.648 raeburn 3446: =item * ©rightids()
1.112 bowersj2 3447:
3448: returns list of all copyrights
3449:
3450: =cut
3451:
3452: sub copyrightids {
3453: return sort(keys(%cprtag));
3454: }
3455:
3456: =pod
3457:
1.648 raeburn 3458: =item * ©rightdescription()
1.112 bowersj2 3459:
3460: returns description of a specified copyright id
3461:
3462: =cut
3463:
3464: sub copyrightdescription {
1.166 www 3465: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3466: }
1.197 matthew 3467:
3468: =pod
3469:
1.648 raeburn 3470: =item * &source_copyrightids()
1.192 taceyjo1 3471:
3472: returns list of all source copyrights
3473:
3474: =cut
3475:
3476: sub source_copyrightids {
3477: return sort(keys(%scprtag));
3478: }
3479:
3480: =pod
3481:
1.648 raeburn 3482: =item * &source_copyrightdescription()
1.192 taceyjo1 3483:
3484: returns description of a specified source copyright id
3485:
3486: =cut
3487:
3488: sub source_copyrightdescription {
3489: return &mt($scprtag{shift(@_)});
3490: }
1.112 bowersj2 3491:
3492: =pod
3493:
1.648 raeburn 3494: =item * &filecategories()
1.112 bowersj2 3495:
3496: returns list of all file categories
3497:
3498: =cut
3499:
3500: sub filecategories {
3501: return sort(keys(%category_extensions));
3502: }
3503:
3504: =pod
3505:
1.648 raeburn 3506: =item * &filecategorytypes()
1.112 bowersj2 3507:
3508: returns list of file types belonging to a given file
3509: category
3510:
3511: =cut
3512:
3513: sub filecategorytypes {
1.356 albertel 3514: my ($cat) = @_;
3515: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3516: }
3517:
3518: =pod
3519:
1.648 raeburn 3520: =item * &fileembstyle()
1.112 bowersj2 3521:
3522: returns embedding style for a specified file type
3523:
3524: =cut
3525:
3526: sub fileembstyle {
3527: return $fe{lc(shift(@_))};
1.169 www 3528: }
3529:
1.351 www 3530: sub filemimetype {
3531: return $fm{lc(shift(@_))};
3532: }
3533:
1.169 www 3534:
3535: sub filecategoryselect {
3536: my ($name,$value)=@_;
1.189 matthew 3537: return &select_form($value,$name,
1.970 raeburn 3538: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3539: }
3540:
3541: =pod
3542:
1.648 raeburn 3543: =item * &filedescription()
1.112 bowersj2 3544:
3545: returns description for a specified file type
3546:
3547: =cut
3548:
3549: sub filedescription {
1.188 matthew 3550: my $file_description = $fd{lc(shift())};
3551: $file_description =~ s:([\[\]]):~$1:g;
3552: return &mt($file_description);
1.112 bowersj2 3553: }
3554:
3555: =pod
3556:
1.648 raeburn 3557: =item * &filedescriptionex()
1.112 bowersj2 3558:
3559: returns description for a specified file type with
3560: extra formatting
3561:
3562: =cut
3563:
3564: sub filedescriptionex {
3565: my $ex=shift;
1.188 matthew 3566: my $file_description = $fd{lc($ex)};
3567: $file_description =~ s:([\[\]]):~$1:g;
3568: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3569: }
3570:
3571: # End of .tab access
3572: =pod
3573:
3574: =back
3575:
3576: =cut
3577:
3578: # ------------------------------------------------------------------ File Types
3579: sub fileextensions {
3580: return sort(keys(%fe));
3581: }
3582:
1.97 www 3583: # ----------------------------------------------------------- Display Languages
3584: # returns a hash with all desired display languages
3585: #
3586:
3587: sub display_languages {
3588: my %languages=();
1.695 raeburn 3589: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3590: $languages{$lang}=1;
1.97 www 3591: }
3592: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3593: if ($env{'form.displaylanguage'}) {
1.356 albertel 3594: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3595: $languages{$lang}=1;
1.97 www 3596: }
3597: }
3598: return %languages;
1.14 harris41 3599: }
3600:
1.582 albertel 3601: sub languages {
3602: my ($possible_langs) = @_;
1.695 raeburn 3603: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3604: if (!ref($possible_langs)) {
3605: if( wantarray ) {
3606: return @preferred_langs;
3607: } else {
3608: return $preferred_langs[0];
3609: }
3610: }
3611: my %possibilities = map { $_ => 1 } (@$possible_langs);
3612: my @preferred_possibilities;
3613: foreach my $preferred_lang (@preferred_langs) {
3614: if (exists($possibilities{$preferred_lang})) {
3615: push(@preferred_possibilities, $preferred_lang);
3616: }
3617: }
3618: if( wantarray ) {
3619: return @preferred_possibilities;
3620: }
3621: return $preferred_possibilities[0];
3622: }
3623:
1.742 raeburn 3624: sub user_lang {
3625: my ($touname,$toudom,$fromcid) = @_;
3626: my @userlangs;
3627: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3628: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3629: $env{'course.'.$fromcid.'.languages'}));
3630: } else {
3631: my %langhash = &getlangs($touname,$toudom);
3632: if ($langhash{'languages'} ne '') {
3633: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3634: } else {
3635: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3636: if ($domdefs{'lang_def'} ne '') {
3637: @userlangs = ($domdefs{'lang_def'});
3638: }
3639: }
3640: }
3641: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3642: my $user_lh = Apache::localize->get_handle(@languages);
3643: return $user_lh;
3644: }
3645:
3646:
1.112 bowersj2 3647: ###############################################################
3648: ## Student Answer Attempts ##
3649: ###############################################################
3650:
3651: =pod
3652:
3653: =head1 Alternate Problem Views
3654:
3655: =over 4
3656:
1.648 raeburn 3657: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3658: $getattempt, $regexp, $gradesub)
3659:
3660: Return string with previous attempt on problem. Arguments:
3661:
3662: =over 4
3663:
3664: =item * $symb: Problem, including path
3665:
3666: =item * $username: username of the desired student
3667:
3668: =item * $domain: domain of the desired student
1.14 harris41 3669:
1.112 bowersj2 3670: =item * $course: Course ID
1.14 harris41 3671:
1.112 bowersj2 3672: =item * $getattempt: Leave blank for all attempts, otherwise put
3673: something
1.14 harris41 3674:
1.112 bowersj2 3675: =item * $regexp: if string matches this regexp, the string will be
3676: sent to $gradesub
1.14 harris41 3677:
1.112 bowersj2 3678: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3679:
1.112 bowersj2 3680: =back
1.14 harris41 3681:
1.112 bowersj2 3682: The output string is a table containing all desired attempts, if any.
1.16 harris41 3683:
1.112 bowersj2 3684: =cut
1.1 albertel 3685:
3686: sub get_previous_attempt {
1.43 ng 3687: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3688: my $prevattempts='';
1.43 ng 3689: no strict 'refs';
1.1 albertel 3690: if ($symb) {
1.3 albertel 3691: my (%returnhash)=
3692: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3693: if ($returnhash{'version'}) {
3694: my %lasthash=();
3695: my $version;
3696: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3697: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3698: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3699: }
1.1 albertel 3700: }
1.596 albertel 3701: $prevattempts=&start_data_table().&start_data_table_header_row();
3702: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3703: my (%typeparts,%lasthidden);
1.945 raeburn 3704: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3705: foreach my $key (sort(keys(%lasthash))) {
3706: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3707: if ($#parts > 0) {
1.31 albertel 3708: my $data=$parts[-1];
1.989 raeburn 3709: next if ($data eq 'foilorder');
1.31 albertel 3710: pop(@parts);
1.1010 www 3711: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3712: if ($data eq 'type') {
3713: unless ($showsurv) {
3714: my $id = join(',',@parts);
3715: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3716: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3717: $lasthidden{$ign.'.'.$id} = 1;
3718: }
1.945 raeburn 3719: }
1.1010 www 3720: }
1.31 albertel 3721: } else {
1.41 ng 3722: if ($#parts == 0) {
3723: $prevattempts.='<th>'.$parts[0].'</th>';
3724: } else {
3725: $prevattempts.='<th>'.$ign.'</th>';
3726: }
1.31 albertel 3727: }
1.16 harris41 3728: }
1.596 albertel 3729: $prevattempts.=&end_data_table_header_row();
1.40 ng 3730: if ($getattempt eq '') {
3731: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3732: my @hidden;
3733: if (%typeparts) {
3734: foreach my $id (keys(%typeparts)) {
3735: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3736: push(@hidden,$id);
3737: }
3738: }
3739: }
3740: $prevattempts.=&start_data_table_row().
3741: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3742: if (@hidden) {
3743: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3744: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3745: my $hide;
3746: foreach my $id (@hidden) {
3747: if ($key =~ /^\Q$id\E/) {
3748: $hide = 1;
3749: last;
3750: }
3751: }
3752: if ($hide) {
3753: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3754: if (($data eq 'award') || ($data eq 'awarddetail')) {
3755: my $value = &format_previous_attempt_value($key,
3756: $returnhash{$version.':'.$key});
3757: $prevattempts.='<td>'.$value.' </td>';
3758: } else {
3759: $prevattempts.='<td> </td>';
3760: }
3761: } else {
3762: if ($key =~ /\./) {
3763: my $value = &format_previous_attempt_value($key,
3764: $returnhash{$version.':'.$key});
3765: $prevattempts.='<td>'.$value.' </td>';
3766: } else {
3767: $prevattempts.='<td> </td>';
3768: }
3769: }
3770: }
3771: } else {
3772: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3773: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3774: my $value = &format_previous_attempt_value($key,
3775: $returnhash{$version.':'.$key});
3776: $prevattempts.='<td>'.$value.' </td>';
3777: }
3778: }
3779: $prevattempts.=&end_data_table_row();
1.40 ng 3780: }
1.1 albertel 3781: }
1.945 raeburn 3782: my @currhidden = keys(%lasthidden);
1.596 albertel 3783: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3784: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3785: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3786: if (%typeparts) {
3787: my $hidden;
3788: foreach my $id (@currhidden) {
3789: if ($key =~ /^\Q$id\E/) {
3790: $hidden = 1;
3791: last;
3792: }
3793: }
3794: if ($hidden) {
3795: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3796: if (($data eq 'award') || ($data eq 'awarddetail')) {
3797: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3798: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3799: $value = &$gradesub($value);
3800: }
3801: $prevattempts.='<td>'.$value.' </td>';
3802: } else {
3803: $prevattempts.='<td> </td>';
3804: }
3805: } else {
3806: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3807: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3808: $value = &$gradesub($value);
3809: }
3810: $prevattempts.='<td>'.$value.' </td>';
3811: }
3812: } else {
3813: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3814: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3815: $value = &$gradesub($value);
3816: }
3817: $prevattempts.='<td>'.$value.' </td>';
3818: }
1.16 harris41 3819: }
1.596 albertel 3820: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3821: } else {
1.596 albertel 3822: $prevattempts=
3823: &start_data_table().&start_data_table_row().
3824: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3825: &end_data_table_row().&end_data_table();
1.1 albertel 3826: }
3827: } else {
1.596 albertel 3828: $prevattempts=
3829: &start_data_table().&start_data_table_row().
3830: '<td>'.&mt('No data.').'</td>'.
3831: &end_data_table_row().&end_data_table();
1.1 albertel 3832: }
1.10 albertel 3833: }
3834:
1.581 albertel 3835: sub format_previous_attempt_value {
3836: my ($key,$value) = @_;
1.1011 www 3837: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3838: $value = &Apache::lonlocal::locallocaltime($value);
3839: } elsif (ref($value) eq 'ARRAY') {
3840: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3841: } elsif ($key =~ /answerstring$/) {
3842: my %answers = &Apache::lonnet::str2hash($value);
3843: my @anskeys = sort(keys(%answers));
3844: if (@anskeys == 1) {
3845: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3846: if ($answer =~ m{\0}) {
3847: $answer =~ s{\0}{,}g;
1.988 raeburn 3848: }
3849: my $tag_internal_answer_name = 'INTERNAL';
3850: if ($anskeys[0] eq $tag_internal_answer_name) {
3851: $value = $answer;
3852: } else {
3853: $value = $anskeys[0].'='.$answer;
3854: }
3855: } else {
3856: foreach my $ans (@anskeys) {
3857: my $answer = $answers{$ans};
1.1001 raeburn 3858: if ($answer =~ m{\0}) {
3859: $answer =~ s{\0}{,}g;
1.988 raeburn 3860: }
3861: $value .= $ans.'='.$answer.'<br />';;
3862: }
3863: }
1.581 albertel 3864: } else {
3865: $value = &unescape($value);
3866: }
3867: return $value;
3868: }
3869:
3870:
1.107 albertel 3871: sub relative_to_absolute {
3872: my ($url,$output)=@_;
3873: my $parser=HTML::TokeParser->new(\$output);
3874: my $token;
3875: my $thisdir=$url;
3876: my @rlinks=();
3877: while ($token=$parser->get_token) {
3878: if ($token->[0] eq 'S') {
3879: if ($token->[1] eq 'a') {
3880: if ($token->[2]->{'href'}) {
3881: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3882: }
3883: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3884: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3885: } elsif ($token->[1] eq 'base') {
3886: $thisdir=$token->[2]->{'href'};
3887: }
3888: }
3889: }
3890: $thisdir=~s-/[^/]*$--;
1.356 albertel 3891: foreach my $link (@rlinks) {
1.726 raeburn 3892: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3893: ($link=~/^\//) ||
3894: ($link=~/^javascript:/i) ||
3895: ($link=~/^mailto:/i) ||
3896: ($link=~/^\#/)) {
3897: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3898: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3899: }
3900: }
3901: # -------------------------------------------------- Deal with Applet codebases
3902: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3903: return $output;
3904: }
3905:
1.112 bowersj2 3906: =pod
3907:
1.648 raeburn 3908: =item * &get_student_view()
1.112 bowersj2 3909:
3910: show a snapshot of what student was looking at
3911:
3912: =cut
3913:
1.10 albertel 3914: sub get_student_view {
1.186 albertel 3915: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3916: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3917: my (%form);
1.10 albertel 3918: my @elements=('symb','courseid','domain','username');
3919: foreach my $element (@elements) {
1.186 albertel 3920: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3921: }
1.186 albertel 3922: if (defined($moreenv)) {
3923: %form=(%form,%{$moreenv});
3924: }
1.236 albertel 3925: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3926: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3927: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3928: $userview=~s/\<body[^\>]*\>//gi;
3929: $userview=~s/\<\/body\>//gi;
3930: $userview=~s/\<html\>//gi;
3931: $userview=~s/\<\/html\>//gi;
3932: $userview=~s/\<head\>//gi;
3933: $userview=~s/\<\/head\>//gi;
3934: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3935: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3936: if (wantarray) {
3937: return ($userview,$response);
3938: } else {
3939: return $userview;
3940: }
3941: }
3942:
3943: sub get_student_view_with_retries {
3944: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3945:
3946: my $ok = 0; # True if we got a good response.
3947: my $content;
3948: my $response;
3949:
3950: # Try to get the student_view done. within the retries count:
3951:
3952: do {
3953: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3954: $ok = $response->is_success;
3955: if (!$ok) {
3956: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3957: }
3958: $retries--;
3959: } while (!$ok && ($retries > 0));
3960:
3961: if (!$ok) {
3962: $content = ''; # On error return an empty content.
3963: }
1.651 www 3964: if (wantarray) {
3965: return ($content, $response);
3966: } else {
3967: return $content;
3968: }
1.11 albertel 3969: }
3970:
1.112 bowersj2 3971: =pod
3972:
1.648 raeburn 3973: =item * &get_student_answers()
1.112 bowersj2 3974:
3975: show a snapshot of how student was answering problem
3976:
3977: =cut
3978:
1.11 albertel 3979: sub get_student_answers {
1.100 sakharuk 3980: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3981: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3982: my (%moreenv);
1.11 albertel 3983: my @elements=('symb','courseid','domain','username');
3984: foreach my $element (@elements) {
1.186 albertel 3985: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3986: }
1.186 albertel 3987: $moreenv{'grade_target'}='answer';
3988: %moreenv=(%form,%moreenv);
1.497 raeburn 3989: $feedurl = &Apache::lonnet::clutter($feedurl);
3990: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3991: return $userview;
1.1 albertel 3992: }
1.116 albertel 3993:
3994: =pod
3995:
3996: =item * &submlink()
3997:
1.242 albertel 3998: Inputs: $text $uname $udom $symb $target
1.116 albertel 3999:
4000: Returns: A link to grades.pm such as to see the SUBM view of a student
4001:
4002: =cut
4003:
4004: ###############################################
4005: sub submlink {
1.242 albertel 4006: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4007: if (!($uname && $udom)) {
4008: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4009: &Apache::lonnet::whichuser($symb);
1.116 albertel 4010: if (!$symb) { $symb=$cursymb; }
4011: }
1.254 matthew 4012: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4013: $symb=&escape($symb);
1.960 bisitz 4014: if ($target) { $target=" target=\"$target\""; }
4015: return
4016: '<a href="/adm/grades?command=submission'.
4017: '&symb='.$symb.
4018: '&student='.$uname.
4019: '&userdom='.$udom.'"'.
4020: $target.'>'.$text.'</a>';
1.242 albertel 4021: }
4022: ##############################################
4023:
4024: =pod
4025:
4026: =item * &pgrdlink()
4027:
4028: Inputs: $text $uname $udom $symb $target
4029:
4030: Returns: A link to grades.pm such as to see the PGRD view of a student
4031:
4032: =cut
4033:
4034: ###############################################
4035: sub pgrdlink {
4036: my $link=&submlink(@_);
4037: $link=~s/(&command=submission)/$1&showgrading=yes/;
4038: return $link;
4039: }
4040: ##############################################
4041:
4042: =pod
4043:
4044: =item * &pprmlink()
4045:
4046: Inputs: $text $uname $udom $symb $target
4047:
4048: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4049: student and a specific resource
1.242 albertel 4050:
4051: =cut
4052:
4053: ###############################################
4054: sub pprmlink {
4055: my ($text,$uname,$udom,$symb,$target)=@_;
4056: if (!($uname && $udom)) {
4057: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4058: &Apache::lonnet::whichuser($symb);
1.242 albertel 4059: if (!$symb) { $symb=$cursymb; }
4060: }
1.254 matthew 4061: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4062: $symb=&escape($symb);
1.242 albertel 4063: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4064: return '<a href="/adm/parmset?command=set&'.
4065: 'symb='.$symb.'&uname='.$uname.
4066: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4067: }
4068: ##############################################
1.37 matthew 4069:
1.112 bowersj2 4070: =pod
4071:
4072: =back
4073:
4074: =cut
4075:
1.37 matthew 4076: ###############################################
1.51 www 4077:
4078:
4079: sub timehash {
1.687 raeburn 4080: my ($thistime) = @_;
4081: my $timezone = &Apache::lonlocal::gettimezone();
4082: my $dt = DateTime->from_epoch(epoch => $thistime)
4083: ->set_time_zone($timezone);
4084: my $wday = $dt->day_of_week();
4085: if ($wday == 7) { $wday = 0; }
4086: return ( 'second' => $dt->second(),
4087: 'minute' => $dt->minute(),
4088: 'hour' => $dt->hour(),
4089: 'day' => $dt->day_of_month(),
4090: 'month' => $dt->month(),
4091: 'year' => $dt->year(),
4092: 'weekday' => $wday,
4093: 'dayyear' => $dt->day_of_year(),
4094: 'dlsav' => $dt->is_dst() );
1.51 www 4095: }
4096:
1.370 www 4097: sub utc_string {
4098: my ($date)=@_;
1.371 www 4099: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4100: }
4101:
1.51 www 4102: sub maketime {
4103: my %th=@_;
1.687 raeburn 4104: my ($epoch_time,$timezone,$dt);
4105: $timezone = &Apache::lonlocal::gettimezone();
4106: eval {
4107: $dt = DateTime->new( year => $th{'year'},
4108: month => $th{'month'},
4109: day => $th{'day'},
4110: hour => $th{'hour'},
4111: minute => $th{'minute'},
4112: second => $th{'second'},
4113: time_zone => $timezone,
4114: );
4115: };
4116: if (!$@) {
4117: $epoch_time = $dt->epoch;
4118: if ($epoch_time) {
4119: return $epoch_time;
4120: }
4121: }
1.51 www 4122: return POSIX::mktime(
4123: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4124: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4125: }
4126:
4127: #########################################
1.51 www 4128:
4129: sub findallcourses {
1.482 raeburn 4130: my ($roles,$uname,$udom) = @_;
1.355 albertel 4131: my %roles;
4132: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4133: my %courses;
1.51 www 4134: my $now=time;
1.482 raeburn 4135: if (!defined($uname)) {
4136: $uname = $env{'user.name'};
4137: }
4138: if (!defined($udom)) {
4139: $udom = $env{'user.domain'};
4140: }
4141: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4142: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4143: if (!%roles) {
4144: %roles = (
4145: cc => 1,
1.907 raeburn 4146: co => 1,
1.482 raeburn 4147: in => 1,
4148: ep => 1,
4149: ta => 1,
4150: cr => 1,
4151: st => 1,
4152: );
4153: }
4154: foreach my $entry (keys(%roleshash)) {
4155: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4156: if ($trole =~ /^cr/) {
4157: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4158: } else {
4159: next if (!exists($roles{$trole}));
4160: }
4161: if ($tend) {
4162: next if ($tend < $now);
4163: }
4164: if ($tstart) {
4165: next if ($tstart > $now);
4166: }
1.1058 raeburn 4167: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4168: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4169: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4170: if ($secpart eq '') {
4171: ($cnum,$role) = split(/_/,$cnumpart);
4172: $sec = 'none';
1.1058 raeburn 4173: $value .= $cnum.'/';
1.482 raeburn 4174: } else {
4175: $cnum = $cnumpart;
4176: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4177: $value .= $cnum.'/'.$sec;
4178: }
4179: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4180: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4181: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4182: }
4183: } else {
4184: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4185: }
1.482 raeburn 4186: }
4187: } else {
4188: foreach my $key (keys(%env)) {
1.483 albertel 4189: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4190: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4191: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4192: next if ($role eq 'ca' || $role eq 'aa');
4193: next if (%roles && !exists($roles{$role}));
4194: my ($starttime,$endtime)=split(/\./,$env{$key});
4195: my $active=1;
4196: if ($starttime) {
4197: if ($now<$starttime) { $active=0; }
4198: }
4199: if ($endtime) {
4200: if ($now>$endtime) { $active=0; }
4201: }
4202: if ($active) {
1.1058 raeburn 4203: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4204: if ($sec eq '') {
4205: $sec = 'none';
1.1058 raeburn 4206: } else {
4207: $value .= $sec;
4208: }
4209: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4210: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4211: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4212: }
4213: } else {
4214: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4215: }
1.474 raeburn 4216: }
4217: }
1.51 www 4218: }
4219: }
1.474 raeburn 4220: return %courses;
1.51 www 4221: }
1.37 matthew 4222:
1.54 www 4223: ###############################################
1.474 raeburn 4224:
4225: sub blockcheck {
1.1062 raeburn 4226: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4227:
4228: if (!defined($udom)) {
4229: $udom = $env{'user.domain'};
4230: }
4231: if (!defined($uname)) {
4232: $uname = $env{'user.name'};
4233: }
4234:
4235: # If uname and udom are for a course, check for blocks in the course.
4236:
4237: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4238: my ($startblock,$endblock,$triggerblock) =
4239: &get_blocks($setters,$activity,$udom,$uname,$url);
4240: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4241: }
1.474 raeburn 4242:
1.502 raeburn 4243: my $startblock = 0;
4244: my $endblock = 0;
1.1062 raeburn 4245: my $triggerblock = '';
1.482 raeburn 4246: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4247:
1.490 raeburn 4248: # If uname is for a user, and activity is course-specific, i.e.,
4249: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4250:
1.490 raeburn 4251: if (($activity eq 'boards' || $activity eq 'chat' ||
4252: $activity eq 'groups') && ($env{'request.course.id'})) {
4253: foreach my $key (keys(%live_courses)) {
4254: if ($key ne $env{'request.course.id'}) {
4255: delete($live_courses{$key});
4256: }
4257: }
4258: }
4259:
4260: my $otheruser = 0;
4261: my %own_courses;
4262: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4263: # Resource belongs to user other than current user.
4264: $otheruser = 1;
4265: # Gather courses for current user
4266: %own_courses =
4267: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4268: }
4269:
4270: # Gather active course roles - course coordinator, instructor,
4271: # exam proctor, ta, student, or custom role.
1.474 raeburn 4272:
4273: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4274: my ($cdom,$cnum);
4275: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4276: $cdom = $env{'course.'.$course.'.domain'};
4277: $cnum = $env{'course.'.$course.'.num'};
4278: } else {
1.490 raeburn 4279: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4280: }
4281: my $no_ownblock = 0;
4282: my $no_userblock = 0;
1.533 raeburn 4283: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4284: # Check if current user has 'evb' priv for this
4285: if (defined($own_courses{$course})) {
4286: foreach my $sec (keys(%{$own_courses{$course}})) {
4287: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4288: if ($sec ne 'none') {
4289: $checkrole .= '/'.$sec;
4290: }
4291: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4292: $no_ownblock = 1;
4293: last;
4294: }
4295: }
4296: }
4297: # if they have 'evb' priv and are currently not playing student
4298: next if (($no_ownblock) &&
4299: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4300: }
1.474 raeburn 4301: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4302: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4303: if ($sec ne 'none') {
1.482 raeburn 4304: $checkrole .= '/'.$sec;
1.474 raeburn 4305: }
1.490 raeburn 4306: if ($otheruser) {
4307: # Resource belongs to user other than current user.
4308: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4309: my (%allroles,%userroles);
4310: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4311: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4312: my ($trole,$tdom,$tnum,$tsec);
4313: if ($entry =~ /^cr/) {
4314: ($trole,$tdom,$tnum,$tsec) =
4315: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4316: } else {
4317: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4318: }
4319: my ($spec,$area,$trest);
4320: $area = '/'.$tdom.'/'.$tnum;
4321: $trest = $tnum;
4322: if ($tsec ne '') {
4323: $area .= '/'.$tsec;
4324: $trest .= '/'.$tsec;
4325: }
4326: $spec = $trole.'.'.$area;
4327: if ($trole =~ /^cr/) {
4328: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4329: $tdom,$spec,$trest,$area);
4330: } else {
4331: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4332: $tdom,$spec,$trest,$area);
4333: }
4334: }
4335: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4336: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4337: if ($1) {
4338: $no_userblock = 1;
4339: last;
4340: }
1.486 raeburn 4341: }
4342: }
1.490 raeburn 4343: } else {
4344: # Resource belongs to current user
4345: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4346: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4347: $no_ownblock = 1;
4348: last;
4349: }
1.474 raeburn 4350: }
4351: }
4352: # if they have the evb priv and are currently not playing student
1.482 raeburn 4353: next if (($no_ownblock) &&
1.491 albertel 4354: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4355: next if ($no_userblock);
1.474 raeburn 4356:
1.866 kalberla 4357: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4358: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4359:
1.1062 raeburn 4360: my ($start,$end,$trigger) =
4361: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4362: if (($start != 0) &&
4363: (($startblock == 0) || ($startblock > $start))) {
4364: $startblock = $start;
1.1062 raeburn 4365: if ($trigger ne '') {
4366: $triggerblock = $trigger;
4367: }
1.502 raeburn 4368: }
4369: if (($end != 0) &&
4370: (($endblock == 0) || ($endblock < $end))) {
4371: $endblock = $end;
1.1062 raeburn 4372: if ($trigger ne '') {
4373: $triggerblock = $trigger;
4374: }
1.502 raeburn 4375: }
1.490 raeburn 4376: }
1.1062 raeburn 4377: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4378: }
4379:
4380: sub get_blocks {
1.1062 raeburn 4381: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4382: my $startblock = 0;
4383: my $endblock = 0;
1.1062 raeburn 4384: my $triggerblock = '';
1.490 raeburn 4385: my $course = $cdom.'_'.$cnum;
4386: $setters->{$course} = {};
4387: $setters->{$course}{'staff'} = [];
4388: $setters->{$course}{'times'} = [];
1.1062 raeburn 4389: $setters->{$course}{'triggers'} = [];
4390: my (@blockers,%triggered);
4391: my $now = time;
4392: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4393: if ($activity eq 'docs') {
4394: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4395: foreach my $block (@blockers) {
4396: if ($block =~ /^firstaccess____(.+)$/) {
4397: my $item = $1;
4398: my $type = 'map';
4399: my $timersymb = $item;
4400: if ($item eq 'course') {
4401: $type = 'course';
4402: } elsif ($item =~ /___\d+___/) {
4403: $type = 'resource';
4404: } else {
4405: $timersymb = &Apache::lonnet::symbread($item);
4406: }
4407: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4408: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4409: $triggered{$block} = {
4410: start => $start,
4411: end => $end,
4412: type => $type,
4413: };
4414: }
4415: }
4416: } else {
4417: foreach my $block (keys(%commblocks)) {
4418: if ($block =~ m/^(\d+)____(\d+)$/) {
4419: my ($start,$end) = ($1,$2);
4420: if ($start <= time && $end >= time) {
4421: if (ref($commblocks{$block}) eq 'HASH') {
4422: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4423: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4424: unless(grep(/^\Q$block\E$/,@blockers)) {
4425: push(@blockers,$block);
4426: }
4427: }
4428: }
4429: }
4430: }
4431: } elsif ($block =~ /^firstaccess____(.+)$/) {
4432: my $item = $1;
4433: my $timersymb = $item;
4434: my $type = 'map';
4435: if ($item eq 'course') {
4436: $type = 'course';
4437: } elsif ($item =~ /___\d+___/) {
4438: $type = 'resource';
4439: } else {
4440: $timersymb = &Apache::lonnet::symbread($item);
4441: }
4442: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4443: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4444: if ($start && $end) {
4445: if (($start <= time) && ($end >= time)) {
4446: unless (grep(/^\Q$block\E$/,@blockers)) {
4447: push(@blockers,$block);
4448: $triggered{$block} = {
4449: start => $start,
4450: end => $end,
4451: type => $type,
4452: };
4453: }
4454: }
1.490 raeburn 4455: }
1.1062 raeburn 4456: }
4457: }
4458: }
4459: foreach my $blocker (@blockers) {
4460: my ($staff_name,$staff_dom,$title,$blocks) =
4461: &parse_block_record($commblocks{$blocker});
4462: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4463: my ($start,$end,$triggertype);
4464: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4465: ($start,$end) = ($1,$2);
4466: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4467: $start = $triggered{$blocker}{'start'};
4468: $end = $triggered{$blocker}{'end'};
4469: $triggertype = $triggered{$blocker}{'type'};
4470: }
4471: if ($start) {
4472: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4473: if ($triggertype) {
4474: push(@{$$setters{$course}{'triggers'}},$triggertype);
4475: } else {
4476: push(@{$$setters{$course}{'triggers'}},0);
4477: }
4478: if ( ($startblock == 0) || ($startblock > $start) ) {
4479: $startblock = $start;
4480: if ($triggertype) {
4481: $triggerblock = $blocker;
1.474 raeburn 4482: }
4483: }
1.1062 raeburn 4484: if ( ($endblock == 0) || ($endblock < $end) ) {
4485: $endblock = $end;
4486: if ($triggertype) {
4487: $triggerblock = $blocker;
4488: }
4489: }
1.474 raeburn 4490: }
4491: }
1.1062 raeburn 4492: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4493: }
4494:
4495: sub parse_block_record {
4496: my ($record) = @_;
4497: my ($setuname,$setudom,$title,$blocks);
4498: if (ref($record) eq 'HASH') {
4499: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4500: $title = &unescape($record->{'event'});
4501: $blocks = $record->{'blocks'};
4502: } else {
4503: my @data = split(/:/,$record,3);
4504: if (scalar(@data) eq 2) {
4505: $title = $data[1];
4506: ($setuname,$setudom) = split(/@/,$data[0]);
4507: } else {
4508: ($setuname,$setudom,$title) = @data;
4509: }
4510: $blocks = { 'com' => 'on' };
4511: }
4512: return ($setuname,$setudom,$title,$blocks);
4513: }
4514:
1.854 kalberla 4515: sub blocking_status {
1.1062 raeburn 4516: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4517: my %setters;
1.890 droeschl 4518:
1.1061 raeburn 4519: # check for active blocking
1.1062 raeburn 4520: my ($startblock,$endblock,$triggerblock) =
4521: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4522: my $blocked = 0;
4523: if ($startblock && $endblock) {
4524: $blocked = 1;
4525: }
1.890 droeschl 4526:
1.1061 raeburn 4527: # caller just wants to know whether a block is active
4528: if (!wantarray) { return $blocked; }
4529:
4530: # build a link to a popup window containing the details
4531: my $querystring = "?activity=$activity";
4532: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4533: if ($activity eq 'port') {
4534: $querystring .= "&udom=$udom" if $udom;
4535: $querystring .= "&uname=$uname" if $uname;
4536: } elsif ($activity eq 'docs') {
4537: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4538: }
1.1061 raeburn 4539:
4540: my $output .= <<'END_MYBLOCK';
4541: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4542: var options = "width=" + w + ",height=" + h + ",";
4543: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4544: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4545: var newWin = window.open(url, wdwName, options);
4546: newWin.focus();
4547: }
1.890 droeschl 4548: END_MYBLOCK
1.854 kalberla 4549:
1.1061 raeburn 4550: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4551:
1.1061 raeburn 4552: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4553: my $text = &mt('Communication Blocked');
4554: if ($activity eq 'docs') {
4555: $text = &mt('Content Access Blocked');
1.1063 raeburn 4556: } elsif ($activity eq 'printout') {
4557: $text = &mt('Printing Blocked');
1.1062 raeburn 4558: }
1.1061 raeburn 4559: $output .= <<"END_BLOCK";
1.867 kalberla 4560: <div class='LC_comblock'>
1.869 kalberla 4561: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4562: title='$text'>
4563: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4564: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4565: title='$text'>$text</a>
1.867 kalberla 4566: </div>
4567:
4568: END_BLOCK
1.474 raeburn 4569:
1.1061 raeburn 4570: return ($blocked, $output);
1.854 kalberla 4571: }
1.490 raeburn 4572:
1.60 matthew 4573: ###############################################
4574:
1.682 raeburn 4575: sub check_ip_acc {
4576: my ($acc)=@_;
4577: &Apache::lonxml::debug("acc is $acc");
4578: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4579: return 1;
4580: }
4581: my $allowed=0;
4582: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4583:
4584: my $name;
4585: foreach my $pattern (split(',',$acc)) {
4586: $pattern =~ s/^\s*//;
4587: $pattern =~ s/\s*$//;
4588: if ($pattern =~ /\*$/) {
4589: #35.8.*
4590: $pattern=~s/\*//;
4591: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4592: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4593: #35.8.3.[34-56]
4594: my $low=$2;
4595: my $high=$3;
4596: $pattern=$1;
4597: if ($ip =~ /^\Q$pattern\E/) {
4598: my $last=(split(/\./,$ip))[3];
4599: if ($last <=$high && $last >=$low) { $allowed=1; }
4600: }
4601: } elsif ($pattern =~ /^\*/) {
4602: #*.msu.edu
4603: $pattern=~s/\*//;
4604: if (!defined($name)) {
4605: use Socket;
4606: my $netaddr=inet_aton($ip);
4607: ($name)=gethostbyaddr($netaddr,AF_INET);
4608: }
4609: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4610: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4611: #127.0.0.1
4612: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4613: } else {
4614: #some.name.com
4615: if (!defined($name)) {
4616: use Socket;
4617: my $netaddr=inet_aton($ip);
4618: ($name)=gethostbyaddr($netaddr,AF_INET);
4619: }
4620: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4621: }
4622: if ($allowed) { last; }
4623: }
4624: return $allowed;
4625: }
4626:
4627: ###############################################
4628:
1.60 matthew 4629: =pod
4630:
1.112 bowersj2 4631: =head1 Domain Template Functions
4632:
4633: =over 4
4634:
4635: =item * &determinedomain()
1.60 matthew 4636:
4637: Inputs: $domain (usually will be undef)
4638:
1.63 www 4639: Returns: Determines which domain should be used for designs
1.60 matthew 4640:
4641: =cut
1.54 www 4642:
1.60 matthew 4643: ###############################################
1.63 www 4644: sub determinedomain {
4645: my $domain=shift;
1.531 albertel 4646: if (! $domain) {
1.60 matthew 4647: # Determine domain if we have not been given one
1.893 raeburn 4648: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4649: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4650: if ($env{'request.role.domain'}) {
4651: $domain=$env{'request.role.domain'};
1.60 matthew 4652: }
4653: }
1.63 www 4654: return $domain;
4655: }
4656: ###############################################
1.517 raeburn 4657:
1.518 albertel 4658: sub devalidate_domconfig_cache {
4659: my ($udom)=@_;
4660: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4661: }
4662:
4663: # ---------------------- Get domain configuration for a domain
4664: sub get_domainconf {
4665: my ($udom) = @_;
4666: my $cachetime=1800;
4667: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4668: if (defined($cached)) { return %{$result}; }
4669:
4670: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4671: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4672: my (%designhash,%legacy);
1.518 albertel 4673: if (keys(%domconfig) > 0) {
4674: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4675: if (keys(%{$domconfig{'login'}})) {
4676: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4677: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4678: if ($key eq 'loginvia') {
4679: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4680: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4681: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4682: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4683: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4684: $designhash{$udom.'.login.loginvia'} = $server;
4685: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4686:
4687: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4688: } else {
1.1013 raeburn 4689: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4690: }
4691: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4692: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4693: }
1.946 raeburn 4694: }
4695: }
4696: }
4697: }
4698: } else {
4699: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4700: $designhash{$udom.'.login.'.$key.'_'.$img} =
4701: $domconfig{'login'}{$key}{$img};
4702: }
1.699 raeburn 4703: }
4704: } else {
4705: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4706: }
1.632 raeburn 4707: }
4708: } else {
4709: $legacy{'login'} = 1;
1.518 albertel 4710: }
1.632 raeburn 4711: } else {
4712: $legacy{'login'} = 1;
1.518 albertel 4713: }
4714: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4715: if (keys(%{$domconfig{'rolecolors'}})) {
4716: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4717: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4718: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4719: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4720: }
1.518 albertel 4721: }
4722: }
1.632 raeburn 4723: } else {
4724: $legacy{'rolecolors'} = 1;
1.518 albertel 4725: }
1.632 raeburn 4726: } else {
4727: $legacy{'rolecolors'} = 1;
1.518 albertel 4728: }
1.948 raeburn 4729: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4730: if ($domconfig{'autoenroll'}{'co-owners'}) {
4731: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4732: }
4733: }
1.632 raeburn 4734: if (keys(%legacy) > 0) {
4735: my %legacyhash = &get_legacy_domconf($udom);
4736: foreach my $item (keys(%legacyhash)) {
4737: if ($item =~ /^\Q$udom\E\.login/) {
4738: if ($legacy{'login'}) {
4739: $designhash{$item} = $legacyhash{$item};
4740: }
4741: } else {
4742: if ($legacy{'rolecolors'}) {
4743: $designhash{$item} = $legacyhash{$item};
4744: }
1.518 albertel 4745: }
4746: }
4747: }
1.632 raeburn 4748: } else {
4749: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4750: }
4751: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4752: $cachetime);
4753: return %designhash;
4754: }
4755:
1.632 raeburn 4756: sub get_legacy_domconf {
4757: my ($udom) = @_;
4758: my %legacyhash;
4759: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4760: my $designfile = $designdir.'/'.$udom.'.tab';
4761: if (-e $designfile) {
4762: if ( open (my $fh,"<$designfile") ) {
4763: while (my $line = <$fh>) {
4764: next if ($line =~ /^\#/);
4765: chomp($line);
4766: my ($key,$val)=(split(/\=/,$line));
4767: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4768: }
4769: close($fh);
4770: }
4771: }
1.1026 raeburn 4772: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4773: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4774: }
4775: return %legacyhash;
4776: }
4777:
1.63 www 4778: =pod
4779:
1.112 bowersj2 4780: =item * &domainlogo()
1.63 www 4781:
4782: Inputs: $domain (usually will be undef)
4783:
4784: Returns: A link to a domain logo, if the domain logo exists.
4785: If the domain logo does not exist, a description of the domain.
4786:
4787: =cut
1.112 bowersj2 4788:
1.63 www 4789: ###############################################
4790: sub domainlogo {
1.517 raeburn 4791: my $domain = &determinedomain(shift);
1.518 albertel 4792: my %designhash = &get_domainconf($domain);
1.517 raeburn 4793: # See if there is a logo
4794: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4795: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4796: if ($imgsrc =~ m{^/(adm|res)/}) {
4797: if ($imgsrc =~ m{^/res/}) {
4798: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4799: &Apache::lonnet::repcopy($local_name);
4800: }
4801: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4802: }
4803: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4804: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4805: return &Apache::lonnet::domain($domain,'description');
1.59 www 4806: } else {
1.60 matthew 4807: return '';
1.59 www 4808: }
4809: }
1.63 www 4810: ##############################################
4811:
4812: =pod
4813:
1.112 bowersj2 4814: =item * &designparm()
1.63 www 4815:
4816: Inputs: $which parameter; $domain (usually will be undef)
4817:
4818: Returns: value of designparamter $which
4819:
4820: =cut
1.112 bowersj2 4821:
1.397 albertel 4822:
1.400 albertel 4823: ##############################################
1.397 albertel 4824: sub designparm {
4825: my ($which,$domain)=@_;
4826: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4827: return $env{'environment.color.'.$which};
1.96 www 4828: }
1.63 www 4829: $domain=&determinedomain($domain);
1.1016 raeburn 4830: my %domdesign;
4831: unless ($domain eq 'public') {
4832: %domdesign = &get_domainconf($domain);
4833: }
1.520 raeburn 4834: my $output;
1.517 raeburn 4835: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4836: $output = $domdesign{$domain.'.'.$which};
1.63 www 4837: } else {
1.520 raeburn 4838: $output = $defaultdesign{$which};
4839: }
4840: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4841: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4842: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4843: if ($output =~ m{^/res/}) {
4844: my $local_name = &Apache::lonnet::filelocation('',$output);
4845: &Apache::lonnet::repcopy($local_name);
4846: }
1.520 raeburn 4847: $output = &lonhttpdurl($output);
4848: }
1.63 www 4849: }
1.520 raeburn 4850: return $output;
1.63 www 4851: }
1.59 www 4852:
1.822 bisitz 4853: ##############################################
4854: =pod
4855:
1.832 bisitz 4856: =item * &authorspace()
4857:
1.1028 raeburn 4858: Inputs: $url (usually will be undef).
1.832 bisitz 4859:
1.1075.2.40 raeburn 4860: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4861: directory being viewed (or for which action is being taken).
4862: If $url is provided, and begins /priv/<domain>/<uname>
4863: the path will be that portion of the $context argument.
4864: Otherwise the path will be for the author space of the current
4865: user when the current role is author, or for that of the
4866: co-author/assistant co-author space when the current role
4867: is co-author or assistant co-author.
1.832 bisitz 4868:
4869: =cut
4870:
4871: sub authorspace {
1.1028 raeburn 4872: my ($url) = @_;
4873: if ($url ne '') {
4874: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4875: return $1;
4876: }
4877: }
1.832 bisitz 4878: my $caname = '';
1.1024 www 4879: my $cadom = '';
1.1028 raeburn 4880: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4881: ($cadom,$caname) =
1.832 bisitz 4882: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4883: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4884: $caname = $env{'user.name'};
1.1024 www 4885: $cadom = $env{'user.domain'};
1.832 bisitz 4886: }
1.1028 raeburn 4887: if (($caname ne '') && ($cadom ne '')) {
4888: return "/priv/$cadom/$caname/";
4889: }
4890: return;
1.832 bisitz 4891: }
4892:
4893: ##############################################
4894: =pod
4895:
1.822 bisitz 4896: =item * &head_subbox()
4897:
4898: Inputs: $content (contains HTML code with page functions, etc.)
4899:
4900: Returns: HTML div with $content
4901: To be included in page header
4902:
4903: =cut
4904:
4905: sub head_subbox {
4906: my ($content)=@_;
4907: my $output =
1.993 raeburn 4908: '<div class="LC_head_subbox">'
1.822 bisitz 4909: .$content
4910: .'</div>'
4911: }
4912:
4913: ##############################################
4914: =pod
4915:
4916: =item * &CSTR_pageheader()
4917:
1.1026 raeburn 4918: Input: (optional) filename from which breadcrumb trail is built.
4919: In most cases no input as needed, as $env{'request.filename'}
4920: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4921:
4922: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 4923: To be included on Authoring Space pages
1.822 bisitz 4924:
4925: =cut
4926:
4927: sub CSTR_pageheader {
1.1026 raeburn 4928: my ($trailfile) = @_;
4929: if ($trailfile eq '') {
4930: $trailfile = $env{'request.filename'};
4931: }
4932:
4933: # this is for resources; directories have customtitle, and crumbs
4934: # and select recent are created in lonpubdir.pm
4935:
4936: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 4937: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 4938: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 4939: my $formaction = "/priv/$udom/$uname/$thisdisfn";
4940: $formaction =~ s{/+}{/}g;
1.822 bisitz 4941:
4942: my $parentpath = '';
4943: my $lastitem = '';
4944: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4945: $parentpath = $1;
4946: $lastitem = $2;
4947: } else {
4948: $lastitem = $thisdisfn;
4949: }
1.921 bisitz 4950:
4951: my $output =
1.822 bisitz 4952: '<div>'
4953: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 4954: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 4955: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4956: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 4957: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 4958:
4959: if ($lastitem) {
4960: $output .=
4961: '<span class="LC_filename">'
4962: .$lastitem
4963: .'</span>';
4964: }
4965: $output .=
4966: '<br />'
1.822 bisitz 4967: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4968: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4969: .'</form>'
4970: .&Apache::lonmenu::constspaceform()
4971: .'</div>';
1.921 bisitz 4972:
4973: return $output;
1.822 bisitz 4974: }
4975:
1.60 matthew 4976: ###############################################
4977: ###############################################
4978:
4979: =pod
4980:
1.112 bowersj2 4981: =back
4982:
1.549 albertel 4983: =head1 HTML Helpers
1.112 bowersj2 4984:
4985: =over 4
4986:
4987: =item * &bodytag()
1.60 matthew 4988:
4989: Returns a uniform header for LON-CAPA web pages.
4990:
4991: Inputs:
4992:
1.112 bowersj2 4993: =over 4
4994:
4995: =item * $title, A title to be displayed on the page.
4996:
4997: =item * $function, the current role (can be undef).
4998:
4999: =item * $addentries, extra parameters for the <body> tag.
5000:
5001: =item * $bodyonly, if defined, only return the <body> tag.
5002:
5003: =item * $domain, if defined, force a given domain.
5004:
5005: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5006: text interface only)
1.60 matthew 5007:
1.814 bisitz 5008: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5009: navigational links
1.317 albertel 5010:
1.338 albertel 5011: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5012:
1.1075.2.12 raeburn 5013: =item * $no_inline_link, if true and in remote mode, don't show the
5014: 'Switch To Inline Menu' link
5015:
1.460 albertel 5016: =item * $args, optional argument valid values are
5017: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5018: inherit_jsmath -> when creating popup window in a page,
5019: should it have jsmath forced on by the
5020: current page
1.460 albertel 5021:
1.1075.2.15 raeburn 5022: =item * $advtoolsref, optional argument, ref to an array containing
5023: inlineremote items to be added in "Functions" menu below
5024: breadcrumbs.
5025:
1.112 bowersj2 5026: =back
5027:
1.60 matthew 5028: Returns: A uniform header for LON-CAPA web pages.
5029: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5030: If $bodyonly is undef or zero, an html string containing a <body> tag and
5031: other decorations will be returned.
5032:
5033: =cut
5034:
1.54 www 5035: sub bodytag {
1.831 bisitz 5036: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5037: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5038:
1.954 raeburn 5039: my $public;
5040: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5041: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5042: $public = 1;
5043: }
1.460 albertel 5044: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5045: my $httphost = $args->{'use_absolute'};
1.339 albertel 5046:
1.183 matthew 5047: $function = &get_users_function() if (!$function);
1.339 albertel 5048: my $img = &designparm($function.'.img',$domain);
5049: my $font = &designparm($function.'.font',$domain);
5050: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5051:
1.803 bisitz 5052: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5053: 'bgcolor' => $pgbg,
1.339 albertel 5054: 'text' => $font,
5055: 'alink' => &designparm($function.'.alink',$domain),
5056: 'vlink' => &designparm($function.'.vlink',$domain),
5057: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5058: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5059:
1.63 www 5060: # role and realm
1.378 raeburn 5061: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5062: if ($role eq 'ca') {
1.479 albertel 5063: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5064: $realm = &plainname($rname,$rdom);
1.378 raeburn 5065: }
1.55 www 5066: # realm
1.258 albertel 5067: if ($env{'request.course.id'}) {
1.378 raeburn 5068: if ($env{'request.role'} !~ /^cr/) {
5069: $role = &Apache::lonnet::plaintext($role,&course_type());
5070: }
1.898 raeburn 5071: if ($env{'request.course.sec'}) {
5072: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5073: }
1.359 albertel 5074: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5075: } else {
5076: $role = &Apache::lonnet::plaintext($role);
1.54 www 5077: }
1.433 albertel 5078:
1.359 albertel 5079: if (!$realm) { $realm=' '; }
1.330 albertel 5080:
1.438 albertel 5081: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5082:
1.101 www 5083: # construct main body tag
1.359 albertel 5084: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5085: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5086:
1.1075.2.38 raeburn 5087: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5088:
5089: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5090: return $bodytag;
1.1075.2.38 raeburn 5091: }
1.359 albertel 5092:
1.954 raeburn 5093: if ($public) {
1.433 albertel 5094: undef($role);
5095: }
1.359 albertel 5096:
1.762 bisitz 5097: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5098: #
5099: # Extra info if you are the DC
5100: my $dc_info = '';
5101: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5102: $env{'course.'.$env{'request.course.id'}.
5103: '.domain'}.'/'})) {
5104: my $cid = $env{'request.course.id'};
1.917 raeburn 5105: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5106: $dc_info =~ s/\s+$//;
1.359 albertel 5107: }
5108:
1.898 raeburn 5109: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.903 droeschl 5110:
1.1075.2.13 raeburn 5111: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5112:
1.1075.2.38 raeburn 5113:
5114:
1.1075.2.21 raeburn 5115: my $funclist;
5116: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5117: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5118: Apache::lonmenu::serverform();
5119: my $forbodytag;
5120: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5121: $forcereg,$args->{'group'},
5122: $args->{'bread_crumbs'},
5123: $advtoolsref,'',\$forbodytag);
5124: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5125: $funclist = $forbodytag;
5126: }
5127: } else {
1.903 droeschl 5128:
5129: # if ($env{'request.state'} eq 'construct') {
5130: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5131: # }
5132:
1.1075.2.38 raeburn 5133: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5134: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5135:
1.1075.2.38 raeburn 5136: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5137:
1.916 droeschl 5138: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5139: if ($dc_info) {
5140: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5141: }
1.1075.2.38 raeburn 5142: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5143: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5144: return $bodytag;
5145: }
1.894 droeschl 5146:
1.927 raeburn 5147: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5148: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5149: }
1.916 droeschl 5150:
1.1075.2.38 raeburn 5151: $bodytag .= $right;
1.852 droeschl 5152:
1.917 raeburn 5153: if ($dc_info) {
5154: $dc_info = &dc_courseid_toggle($dc_info);
5155: }
5156: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5157:
1.903 droeschl 5158: #don't show menus for public users
1.954 raeburn 5159: if (!$public){
1.1075.2.52 raeburn 5160: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5161: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5162: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5163: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5164: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5165: $args->{'bread_crumbs'});
5166: } elsif ($forcereg) {
1.1075.2.22 raeburn 5167: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5168: $args->{'group'});
1.1075.2.15 raeburn 5169: } else {
1.1075.2.21 raeburn 5170: my $forbodytag;
5171: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5172: $forcereg,$args->{'group'},
5173: $args->{'bread_crumbs'},
5174: $advtoolsref,'',\$forbodytag);
5175: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5176: $bodytag .= $forbodytag;
5177: }
1.920 raeburn 5178: }
1.903 droeschl 5179: }else{
5180: # this is to seperate menu from content when there's no secondary
5181: # menu. Especially needed for public accessible ressources.
5182: $bodytag .= '<hr style="clear:both" />';
5183: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5184: }
1.903 droeschl 5185:
1.235 raeburn 5186: return $bodytag;
1.1075.2.12 raeburn 5187: }
5188:
5189: #
5190: # Top frame rendering, Remote is up
5191: #
5192:
5193: my $imgsrc = $img;
5194: if ($img =~ /^\/adm/) {
5195: $imgsrc = &lonhttpdurl($img);
5196: }
5197: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5198:
5199: # Explicit link to get inline menu
5200: my $menu= ($no_inline_link?''
5201: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5202:
5203: if ($dc_info) {
5204: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5205: }
5206:
1.1075.2.38 raeburn 5207: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5208: unless ($public) {
5209: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5210: undef,'LC_menubuttons_link');
5211: }
5212:
1.1075.2.12 raeburn 5213: unless ($env{'form.inhibitmenu'}) {
5214: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5215: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.12 raeburn 5216: <li>$menu</li>
5217: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5218: }
1.1075.2.13 raeburn 5219: if ($env{'request.state'} eq 'construct') {
5220: if (!$public){
5221: if ($env{'request.state'} eq 'construct') {
5222: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5223: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5224: &Apache::lonhtmlcommon::scripttag('','end').
5225: &Apache::lonmenu::innerregister($forcereg,
5226: $args->{'bread_crumbs'});
5227: }
5228: }
5229: }
1.1075.2.21 raeburn 5230: return $bodytag."\n".$funclist;
1.182 matthew 5231: }
5232:
1.917 raeburn 5233: sub dc_courseid_toggle {
5234: my ($dc_info) = @_;
1.980 raeburn 5235: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5236: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5237: &mt('(More ...)').'</a></span>'.
5238: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5239: }
5240:
1.330 albertel 5241: sub make_attr_string {
5242: my ($register,$attr_ref) = @_;
5243:
5244: if ($attr_ref && !ref($attr_ref)) {
5245: die("addentries Must be a hash ref ".
5246: join(':',caller(1))." ".
5247: join(':',caller(0))." ");
5248: }
5249:
5250: if ($register) {
1.339 albertel 5251: my ($on_load,$on_unload);
5252: foreach my $key (keys(%{$attr_ref})) {
5253: if (lc($key) eq 'onload') {
5254: $on_load.=$attr_ref->{$key}.';';
5255: delete($attr_ref->{$key});
5256:
5257: } elsif (lc($key) eq 'onunload') {
5258: $on_unload.=$attr_ref->{$key}.';';
5259: delete($attr_ref->{$key});
5260: }
5261: }
1.1075.2.12 raeburn 5262: if ($env{'environment.remote'} eq 'on') {
5263: $attr_ref->{'onload'} =
5264: &Apache::lonmenu::loadevents(). $on_load;
5265: $attr_ref->{'onunload'}=
5266: &Apache::lonmenu::unloadevents().$on_unload;
5267: } else {
5268: $attr_ref->{'onload'} = $on_load;
5269: $attr_ref->{'onunload'}= $on_unload;
5270: }
1.330 albertel 5271: }
1.339 albertel 5272:
1.330 albertel 5273: my $attr_string;
1.1075.2.56! raeburn 5274: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5275: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5276: }
5277: return $attr_string;
5278: }
5279:
5280:
1.182 matthew 5281: ###############################################
1.251 albertel 5282: ###############################################
5283:
5284: =pod
5285:
5286: =item * &endbodytag()
5287:
5288: Returns a uniform footer for LON-CAPA web pages.
5289:
1.635 raeburn 5290: Inputs: 1 - optional reference to an args hash
5291: If in the hash, key for noredirectlink has a value which evaluates to true,
5292: a 'Continue' link is not displayed if the page contains an
5293: internal redirect in the <head></head> section,
5294: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5295:
5296: =cut
5297:
5298: sub endbodytag {
1.635 raeburn 5299: my ($args) = @_;
1.1075.2.6 raeburn 5300: my $endbodytag;
5301: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5302: $endbodytag='</body>';
5303: }
1.269 albertel 5304: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5305: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5306: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5307: $endbodytag=
5308: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5309: &mt('Continue').'</a>'.
5310: $endbodytag;
5311: }
1.315 albertel 5312: }
1.251 albertel 5313: return $endbodytag;
5314: }
5315:
1.352 albertel 5316: =pod
5317:
5318: =item * &standard_css()
5319:
5320: Returns a style sheet
5321:
5322: Inputs: (all optional)
5323: domain -> force to color decorate a page for a specific
5324: domain
5325: function -> force usage of a specific rolish color scheme
5326: bgcolor -> override the default page bgcolor
5327:
5328: =cut
5329:
1.343 albertel 5330: sub standard_css {
1.345 albertel 5331: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5332: $function = &get_users_function() if (!$function);
5333: my $img = &designparm($function.'.img', $domain);
5334: my $tabbg = &designparm($function.'.tabbg', $domain);
5335: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5336: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5337: #second colour for later usage
1.345 albertel 5338: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5339: my $pgbg_or_bgcolor =
5340: $bgcolor ||
1.352 albertel 5341: &designparm($function.'.pgbg', $domain);
1.382 albertel 5342: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5343: my $alink = &designparm($function.'.alink', $domain);
5344: my $vlink = &designparm($function.'.vlink', $domain);
5345: my $link = &designparm($function.'.link', $domain);
5346:
1.602 albertel 5347: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5348: my $mono = 'monospace';
1.850 bisitz 5349: my $data_table_head = $sidebg;
5350: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5351: my $data_table_dark = '#E0E0E0';
1.470 banghart 5352: my $data_table_darker = '#CCCCCC';
1.349 albertel 5353: my $data_table_highlight = '#FFFF00';
1.352 albertel 5354: my $mail_new = '#FFBB77';
5355: my $mail_new_hover = '#DD9955';
5356: my $mail_read = '#BBBB77';
5357: my $mail_read_hover = '#999944';
5358: my $mail_replied = '#AAAA88';
5359: my $mail_replied_hover = '#888855';
5360: my $mail_other = '#99BBBB';
5361: my $mail_other_hover = '#669999';
1.391 albertel 5362: my $table_header = '#DDDDDD';
1.489 raeburn 5363: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5364: my $lg_border_color = '#C8C8C8';
1.952 onken 5365: my $button_hover = '#BF2317';
1.392 albertel 5366:
1.608 albertel 5367: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5368: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5369: : '0 3px 0 4px';
1.448 albertel 5370:
1.523 albertel 5371:
1.343 albertel 5372: return <<END;
1.947 droeschl 5373:
5374: /* needed for iframe to allow 100% height in FF */
5375: body, html {
5376: margin: 0;
5377: padding: 0 0.5%;
5378: height: 99%; /* to avoid scrollbars */
5379: }
5380:
1.795 www 5381: body {
1.911 bisitz 5382: font-family: $sans;
5383: line-height:130%;
5384: font-size:0.83em;
5385: color:$font;
1.795 www 5386: }
5387:
1.959 onken 5388: a:focus,
5389: a:focus img {
1.795 www 5390: color: red;
5391: }
1.698 harmsja 5392:
1.911 bisitz 5393: form, .inline {
5394: display: inline;
1.795 www 5395: }
1.721 harmsja 5396:
1.795 www 5397: .LC_right {
1.911 bisitz 5398: text-align:right;
1.795 www 5399: }
5400:
5401: .LC_middle {
1.911 bisitz 5402: vertical-align:middle;
1.795 www 5403: }
1.721 harmsja 5404:
1.1075.2.38 raeburn 5405: .LC_floatleft {
5406: float: left;
5407: }
5408:
5409: .LC_floatright {
5410: float: right;
5411: }
5412:
1.911 bisitz 5413: .LC_400Box {
5414: width:400px;
5415: }
1.721 harmsja 5416:
1.947 droeschl 5417: .LC_iframecontainer {
5418: width: 98%;
5419: margin: 0;
5420: position: fixed;
5421: top: 8.5em;
5422: bottom: 0;
5423: }
5424:
5425: .LC_iframecontainer iframe{
5426: border: none;
5427: width: 100%;
5428: height: 100%;
5429: }
5430:
1.778 bisitz 5431: .LC_filename {
5432: font-family: $mono;
5433: white-space:pre;
1.921 bisitz 5434: font-size: 120%;
1.778 bisitz 5435: }
5436:
5437: .LC_fileicon {
5438: border: none;
5439: height: 1.3em;
5440: vertical-align: text-bottom;
5441: margin-right: 0.3em;
5442: text-decoration:none;
5443: }
5444:
1.1008 www 5445: .LC_setting {
5446: text-decoration:underline;
5447: }
5448:
1.350 albertel 5449: .LC_error {
5450: color: red;
5451: }
1.795 www 5452:
1.1075.2.15 raeburn 5453: .LC_warning {
5454: color: darkorange;
5455: }
5456:
1.457 albertel 5457: .LC_diff_removed {
1.733 bisitz 5458: color: red;
1.394 albertel 5459: }
1.532 albertel 5460:
5461: .LC_info,
1.457 albertel 5462: .LC_success,
5463: .LC_diff_added {
1.350 albertel 5464: color: green;
5465: }
1.795 www 5466:
1.802 bisitz 5467: div.LC_confirm_box {
5468: background-color: #FAFAFA;
5469: border: 1px solid $lg_border_color;
5470: margin-right: 0;
5471: padding: 5px;
5472: }
5473:
5474: div.LC_confirm_box .LC_error img,
5475: div.LC_confirm_box .LC_success img {
5476: vertical-align: middle;
5477: }
5478:
1.440 albertel 5479: .LC_icon {
1.771 droeschl 5480: border: none;
1.790 droeschl 5481: vertical-align: middle;
1.771 droeschl 5482: }
5483:
1.543 albertel 5484: .LC_docs_spacer {
5485: width: 25px;
5486: height: 1px;
1.771 droeschl 5487: border: none;
1.543 albertel 5488: }
1.346 albertel 5489:
1.532 albertel 5490: .LC_internal_info {
1.735 bisitz 5491: color: #999999;
1.532 albertel 5492: }
5493:
1.794 www 5494: .LC_discussion {
1.1050 www 5495: background: $data_table_dark;
1.911 bisitz 5496: border: 1px solid black;
5497: margin: 2px;
1.794 www 5498: }
5499:
5500: .LC_disc_action_left {
1.1050 www 5501: background: $sidebg;
1.911 bisitz 5502: text-align: left;
1.1050 www 5503: padding: 4px;
5504: margin: 2px;
1.794 www 5505: }
5506:
5507: .LC_disc_action_right {
1.1050 www 5508: background: $sidebg;
1.911 bisitz 5509: text-align: right;
1.1050 www 5510: padding: 4px;
5511: margin: 2px;
1.794 www 5512: }
5513:
5514: .LC_disc_new_item {
1.911 bisitz 5515: background: white;
5516: border: 2px solid red;
1.1050 www 5517: margin: 4px;
5518: padding: 4px;
1.794 www 5519: }
5520:
5521: .LC_disc_old_item {
1.911 bisitz 5522: background: white;
1.1050 www 5523: margin: 4px;
5524: padding: 4px;
1.794 www 5525: }
5526:
1.458 albertel 5527: table.LC_pastsubmission {
5528: border: 1px solid black;
5529: margin: 2px;
5530: }
5531:
1.924 bisitz 5532: table#LC_menubuttons {
1.345 albertel 5533: width: 100%;
5534: background: $pgbg;
1.392 albertel 5535: border: 2px;
1.402 albertel 5536: border-collapse: separate;
1.803 bisitz 5537: padding: 0;
1.345 albertel 5538: }
1.392 albertel 5539:
1.801 tempelho 5540: table#LC_title_bar a {
5541: color: $fontmenu;
5542: }
1.836 bisitz 5543:
1.807 droeschl 5544: table#LC_title_bar {
1.819 tempelho 5545: clear: both;
1.836 bisitz 5546: display: none;
1.807 droeschl 5547: }
5548:
1.795 www 5549: table#LC_title_bar,
1.933 droeschl 5550: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5551: table#LC_title_bar.LC_with_remote {
1.359 albertel 5552: width: 100%;
1.392 albertel 5553: border-color: $pgbg;
5554: border-style: solid;
5555: border-width: $border;
1.379 albertel 5556: background: $pgbg;
1.801 tempelho 5557: color: $fontmenu;
1.392 albertel 5558: border-collapse: collapse;
1.803 bisitz 5559: padding: 0;
1.819 tempelho 5560: margin: 0;
1.359 albertel 5561: }
1.795 www 5562:
1.933 droeschl 5563: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5564: margin: 0;
5565: padding: 0;
1.933 droeschl 5566: position: relative;
5567: list-style: none;
1.913 droeschl 5568: }
1.933 droeschl 5569: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5570: display: inline;
5571: }
1.933 droeschl 5572:
5573: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5574: padding: 0;
1.933 droeschl 5575: margin: 0;
5576: float: left;
1.913 droeschl 5577: }
1.933 droeschl 5578: .LC_breadcrumb_tools_tools {
5579: padding: 0;
5580: margin: 0;
1.913 droeschl 5581: float: right;
5582: }
5583:
1.359 albertel 5584: table#LC_title_bar td {
5585: background: $tabbg;
5586: }
1.795 www 5587:
1.911 bisitz 5588: table#LC_menubuttons img {
1.803 bisitz 5589: border: none;
1.346 albertel 5590: }
1.795 www 5591:
1.842 droeschl 5592: .LC_breadcrumbs_component {
1.911 bisitz 5593: float: right;
5594: margin: 0 1em;
1.357 albertel 5595: }
1.842 droeschl 5596: .LC_breadcrumbs_component img {
1.911 bisitz 5597: vertical-align: middle;
1.777 tempelho 5598: }
1.795 www 5599:
1.383 albertel 5600: td.LC_table_cell_checkbox {
5601: text-align: center;
5602: }
1.795 www 5603:
5604: .LC_fontsize_small {
1.911 bisitz 5605: font-size: 70%;
1.705 tempelho 5606: }
5607:
1.844 bisitz 5608: #LC_breadcrumbs {
1.911 bisitz 5609: clear:both;
5610: background: $sidebg;
5611: border-bottom: 1px solid $lg_border_color;
5612: line-height: 2.5em;
1.933 droeschl 5613: overflow: hidden;
1.911 bisitz 5614: margin: 0;
5615: padding: 0;
1.995 raeburn 5616: text-align: left;
1.819 tempelho 5617: }
1.862 bisitz 5618:
1.1075.2.16 raeburn 5619: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5620: clear:both;
5621: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5622: border: 1px solid $sidebg;
1.1075.2.16 raeburn 5623: margin: 0 0 10px 0;
1.966 bisitz 5624: padding: 3px;
1.995 raeburn 5625: text-align: left;
1.822 bisitz 5626: }
5627:
1.795 www 5628: .LC_fontsize_medium {
1.911 bisitz 5629: font-size: 85%;
1.705 tempelho 5630: }
5631:
1.795 www 5632: .LC_fontsize_large {
1.911 bisitz 5633: font-size: 120%;
1.705 tempelho 5634: }
5635:
1.346 albertel 5636: .LC_menubuttons_inline_text {
5637: color: $font;
1.698 harmsja 5638: font-size: 90%;
1.701 harmsja 5639: padding-left:3px;
1.346 albertel 5640: }
5641:
1.934 droeschl 5642: .LC_menubuttons_inline_text img{
5643: vertical-align: middle;
5644: }
5645:
1.1051 www 5646: li.LC_menubuttons_inline_text img {
1.951 onken 5647: cursor:pointer;
1.1002 droeschl 5648: text-decoration: none;
1.951 onken 5649: }
5650:
1.526 www 5651: .LC_menubuttons_link {
5652: text-decoration: none;
5653: }
1.795 www 5654:
1.522 albertel 5655: .LC_menubuttons_category {
1.521 www 5656: color: $font;
1.526 www 5657: background: $pgbg;
1.521 www 5658: font-size: larger;
5659: font-weight: bold;
5660: }
5661:
1.346 albertel 5662: td.LC_menubuttons_text {
1.911 bisitz 5663: color: $font;
1.346 albertel 5664: }
1.706 harmsja 5665:
1.346 albertel 5666: .LC_current_location {
5667: background: $tabbg;
5668: }
1.795 www 5669:
1.938 bisitz 5670: table.LC_data_table {
1.347 albertel 5671: border: 1px solid #000000;
1.402 albertel 5672: border-collapse: separate;
1.426 albertel 5673: border-spacing: 1px;
1.610 albertel 5674: background: $pgbg;
1.347 albertel 5675: }
1.795 www 5676:
1.422 albertel 5677: .LC_data_table_dense {
5678: font-size: small;
5679: }
1.795 www 5680:
1.507 raeburn 5681: table.LC_nested_outer {
5682: border: 1px solid #000000;
1.589 raeburn 5683: border-collapse: collapse;
1.803 bisitz 5684: border-spacing: 0;
1.507 raeburn 5685: width: 100%;
5686: }
1.795 www 5687:
1.879 raeburn 5688: table.LC_innerpickbox,
1.507 raeburn 5689: table.LC_nested {
1.803 bisitz 5690: border: none;
1.589 raeburn 5691: border-collapse: collapse;
1.803 bisitz 5692: border-spacing: 0;
1.507 raeburn 5693: width: 100%;
5694: }
1.795 www 5695:
1.911 bisitz 5696: table.LC_data_table tr th,
5697: table.LC_calendar tr th,
1.879 raeburn 5698: table.LC_prior_tries tr th,
5699: table.LC_innerpickbox tr th {
1.349 albertel 5700: font-weight: bold;
5701: background-color: $data_table_head;
1.801 tempelho 5702: color:$fontmenu;
1.701 harmsja 5703: font-size:90%;
1.347 albertel 5704: }
1.795 www 5705:
1.879 raeburn 5706: table.LC_innerpickbox tr th,
5707: table.LC_innerpickbox tr td {
5708: vertical-align: top;
5709: }
5710:
1.711 raeburn 5711: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5712: background-color: #CCCCCC;
1.711 raeburn 5713: font-weight: bold;
5714: text-align: left;
5715: }
1.795 www 5716:
1.912 bisitz 5717: table.LC_data_table tr.LC_odd_row > td {
5718: background-color: $data_table_light;
5719: padding: 2px;
5720: vertical-align: top;
5721: }
5722:
1.809 bisitz 5723: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5724: background-color: $data_table_light;
1.912 bisitz 5725: vertical-align: top;
5726: }
5727:
5728: table.LC_data_table tr.LC_even_row > td {
5729: background-color: $data_table_dark;
1.425 albertel 5730: padding: 2px;
1.900 bisitz 5731: vertical-align: top;
1.347 albertel 5732: }
1.795 www 5733:
1.809 bisitz 5734: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5735: background-color: $data_table_dark;
1.900 bisitz 5736: vertical-align: top;
1.347 albertel 5737: }
1.795 www 5738:
1.425 albertel 5739: table.LC_data_table tr.LC_data_table_highlight td {
5740: background-color: $data_table_darker;
5741: }
1.795 www 5742:
1.639 raeburn 5743: table.LC_data_table tr td.LC_leftcol_header {
5744: background-color: $data_table_head;
5745: font-weight: bold;
5746: }
1.795 www 5747:
1.451 albertel 5748: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5749: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5750: font-weight: bold;
5751: font-style: italic;
5752: text-align: center;
5753: padding: 8px;
1.347 albertel 5754: }
1.795 www 5755:
1.1075.2.30 raeburn 5756: table.LC_data_table tr.LC_empty_row td,
5757: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5758: background-color: $sidebg;
5759: }
5760:
5761: table.LC_nested tr.LC_empty_row td {
5762: background-color: #FFFFFF;
5763: }
5764:
1.890 droeschl 5765: table.LC_caption {
5766: }
5767:
1.507 raeburn 5768: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5769: padding: 4ex
5770: }
1.795 www 5771:
1.507 raeburn 5772: table.LC_nested_outer tr th {
5773: font-weight: bold;
1.801 tempelho 5774: color:$fontmenu;
1.507 raeburn 5775: background-color: $data_table_head;
1.701 harmsja 5776: font-size: small;
1.507 raeburn 5777: border-bottom: 1px solid #000000;
5778: }
1.795 www 5779:
1.507 raeburn 5780: table.LC_nested_outer tr td.LC_subheader {
5781: background-color: $data_table_head;
5782: font-weight: bold;
5783: font-size: small;
5784: border-bottom: 1px solid #000000;
5785: text-align: right;
1.451 albertel 5786: }
1.795 www 5787:
1.507 raeburn 5788: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5789: background-color: #CCCCCC;
1.451 albertel 5790: font-weight: bold;
5791: font-size: small;
1.507 raeburn 5792: text-align: center;
5793: }
1.795 www 5794:
1.589 raeburn 5795: table.LC_nested tr.LC_info_row td.LC_left_item,
5796: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5797: text-align: left;
1.451 albertel 5798: }
1.795 www 5799:
1.507 raeburn 5800: table.LC_nested td {
1.735 bisitz 5801: background-color: #FFFFFF;
1.451 albertel 5802: font-size: small;
1.507 raeburn 5803: }
1.795 www 5804:
1.507 raeburn 5805: table.LC_nested_outer tr th.LC_right_item,
5806: table.LC_nested tr.LC_info_row td.LC_right_item,
5807: table.LC_nested tr.LC_odd_row td.LC_right_item,
5808: table.LC_nested tr td.LC_right_item {
1.451 albertel 5809: text-align: right;
5810: }
5811:
1.507 raeburn 5812: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5813: background-color: #EEEEEE;
1.451 albertel 5814: }
5815:
1.473 raeburn 5816: table.LC_createuser {
5817: }
5818:
5819: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5820: font-size: small;
1.473 raeburn 5821: }
5822:
5823: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5824: background-color: #CCCCCC;
1.473 raeburn 5825: font-weight: bold;
5826: text-align: center;
5827: }
5828:
1.349 albertel 5829: table.LC_calendar {
5830: border: 1px solid #000000;
5831: border-collapse: collapse;
1.917 raeburn 5832: width: 98%;
1.349 albertel 5833: }
1.795 www 5834:
1.349 albertel 5835: table.LC_calendar_pickdate {
5836: font-size: xx-small;
5837: }
1.795 www 5838:
1.349 albertel 5839: table.LC_calendar tr td {
5840: border: 1px solid #000000;
5841: vertical-align: top;
1.917 raeburn 5842: width: 14%;
1.349 albertel 5843: }
1.795 www 5844:
1.349 albertel 5845: table.LC_calendar tr td.LC_calendar_day_empty {
5846: background-color: $data_table_dark;
5847: }
1.795 www 5848:
1.779 bisitz 5849: table.LC_calendar tr td.LC_calendar_day_current {
5850: background-color: $data_table_highlight;
1.777 tempelho 5851: }
1.795 www 5852:
1.938 bisitz 5853: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5854: background-color: $mail_new;
5855: }
1.795 www 5856:
1.938 bisitz 5857: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5858: background-color: $mail_new_hover;
5859: }
1.795 www 5860:
1.938 bisitz 5861: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5862: background-color: $mail_read;
5863: }
1.795 www 5864:
1.938 bisitz 5865: /*
5866: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5867: background-color: $mail_read_hover;
5868: }
1.938 bisitz 5869: */
1.795 www 5870:
1.938 bisitz 5871: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5872: background-color: $mail_replied;
5873: }
1.795 www 5874:
1.938 bisitz 5875: /*
5876: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5877: background-color: $mail_replied_hover;
5878: }
1.938 bisitz 5879: */
1.795 www 5880:
1.938 bisitz 5881: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5882: background-color: $mail_other;
5883: }
1.795 www 5884:
1.938 bisitz 5885: /*
5886: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5887: background-color: $mail_other_hover;
5888: }
1.938 bisitz 5889: */
1.494 raeburn 5890:
1.777 tempelho 5891: table.LC_data_table tr > td.LC_browser_file,
5892: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5893: background: #AAEE77;
1.389 albertel 5894: }
1.795 www 5895:
1.777 tempelho 5896: table.LC_data_table tr > td.LC_browser_file_locked,
5897: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5898: background: #FFAA99;
1.387 albertel 5899: }
1.795 www 5900:
1.777 tempelho 5901: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5902: background: #888888;
1.779 bisitz 5903: }
1.795 www 5904:
1.777 tempelho 5905: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5906: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5907: background: #F8F866;
1.777 tempelho 5908: }
1.795 www 5909:
1.696 bisitz 5910: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5911: background: #E0E8FF;
1.387 albertel 5912: }
1.696 bisitz 5913:
1.707 bisitz 5914: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5915: /* background: #77FF77; */
1.707 bisitz 5916: }
1.795 www 5917:
1.707 bisitz 5918: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5919: border-right: 8px solid #FFFF77;
1.707 bisitz 5920: }
1.795 www 5921:
1.707 bisitz 5922: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5923: border-right: 8px solid #FFAA77;
1.707 bisitz 5924: }
1.795 www 5925:
1.707 bisitz 5926: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5927: border-right: 8px solid #FF7777;
1.707 bisitz 5928: }
1.795 www 5929:
1.707 bisitz 5930: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5931: border-right: 8px solid #AAFF77;
1.707 bisitz 5932: }
1.795 www 5933:
1.707 bisitz 5934: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5935: border-right: 8px solid #11CC55;
1.707 bisitz 5936: }
5937:
1.388 albertel 5938: span.LC_current_location {
1.701 harmsja 5939: font-size:larger;
1.388 albertel 5940: background: $pgbg;
5941: }
1.387 albertel 5942:
1.1029 www 5943: span.LC_current_nav_location {
5944: font-weight:bold;
5945: background: $sidebg;
5946: }
5947:
1.395 albertel 5948: span.LC_parm_menu_item {
5949: font-size: larger;
5950: }
1.795 www 5951:
1.395 albertel 5952: span.LC_parm_scope_all {
5953: color: red;
5954: }
1.795 www 5955:
1.395 albertel 5956: span.LC_parm_scope_folder {
5957: color: green;
5958: }
1.795 www 5959:
1.395 albertel 5960: span.LC_parm_scope_resource {
5961: color: orange;
5962: }
1.795 www 5963:
1.395 albertel 5964: span.LC_parm_part {
5965: color: blue;
5966: }
1.795 www 5967:
1.911 bisitz 5968: span.LC_parm_folder,
5969: span.LC_parm_symb {
1.395 albertel 5970: font-size: x-small;
5971: font-family: $mono;
5972: color: #AAAAAA;
5973: }
5974:
1.977 bisitz 5975: ul.LC_parm_parmlist li {
5976: display: inline-block;
5977: padding: 0.3em 0.8em;
5978: vertical-align: top;
5979: width: 150px;
5980: border-top:1px solid $lg_border_color;
5981: }
5982:
1.795 www 5983: td.LC_parm_overview_level_menu,
5984: td.LC_parm_overview_map_menu,
5985: td.LC_parm_overview_parm_selectors,
5986: td.LC_parm_overview_restrictions {
1.396 albertel 5987: border: 1px solid black;
5988: border-collapse: collapse;
5989: }
1.795 www 5990:
1.396 albertel 5991: table.LC_parm_overview_restrictions td {
5992: border-width: 1px 4px 1px 4px;
5993: border-style: solid;
5994: border-color: $pgbg;
5995: text-align: center;
5996: }
1.795 www 5997:
1.396 albertel 5998: table.LC_parm_overview_restrictions th {
5999: background: $tabbg;
6000: border-width: 1px 4px 1px 4px;
6001: border-style: solid;
6002: border-color: $pgbg;
6003: }
1.795 www 6004:
1.398 albertel 6005: table#LC_helpmenu {
1.803 bisitz 6006: border: none;
1.398 albertel 6007: height: 55px;
1.803 bisitz 6008: border-spacing: 0;
1.398 albertel 6009: }
6010:
6011: table#LC_helpmenu fieldset legend {
6012: font-size: larger;
6013: }
1.795 www 6014:
1.397 albertel 6015: table#LC_helpmenu_links {
6016: width: 100%;
6017: border: 1px solid black;
6018: background: $pgbg;
1.803 bisitz 6019: padding: 0;
1.397 albertel 6020: border-spacing: 1px;
6021: }
1.795 www 6022:
1.397 albertel 6023: table#LC_helpmenu_links tr td {
6024: padding: 1px;
6025: background: $tabbg;
1.399 albertel 6026: text-align: center;
6027: font-weight: bold;
1.397 albertel 6028: }
1.396 albertel 6029:
1.795 www 6030: table#LC_helpmenu_links a:link,
6031: table#LC_helpmenu_links a:visited,
1.397 albertel 6032: table#LC_helpmenu_links a:active {
6033: text-decoration: none;
6034: color: $font;
6035: }
1.795 www 6036:
1.397 albertel 6037: table#LC_helpmenu_links a:hover {
6038: text-decoration: underline;
6039: color: $vlink;
6040: }
1.396 albertel 6041:
1.417 albertel 6042: .LC_chrt_popup_exists {
6043: border: 1px solid #339933;
6044: margin: -1px;
6045: }
1.795 www 6046:
1.417 albertel 6047: .LC_chrt_popup_up {
6048: border: 1px solid yellow;
6049: margin: -1px;
6050: }
1.795 www 6051:
1.417 albertel 6052: .LC_chrt_popup {
6053: border: 1px solid #8888FF;
6054: background: #CCCCFF;
6055: }
1.795 www 6056:
1.421 albertel 6057: table.LC_pick_box {
6058: border-collapse: separate;
6059: background: white;
6060: border: 1px solid black;
6061: border-spacing: 1px;
6062: }
1.795 www 6063:
1.421 albertel 6064: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6065: background: $sidebg;
1.421 albertel 6066: font-weight: bold;
1.900 bisitz 6067: text-align: left;
1.740 bisitz 6068: vertical-align: top;
1.421 albertel 6069: width: 184px;
6070: padding: 8px;
6071: }
1.795 www 6072:
1.579 raeburn 6073: table.LC_pick_box td.LC_pick_box_value {
6074: text-align: left;
6075: padding: 8px;
6076: }
1.795 www 6077:
1.579 raeburn 6078: table.LC_pick_box td.LC_pick_box_select {
6079: text-align: left;
6080: padding: 8px;
6081: }
1.795 www 6082:
1.424 albertel 6083: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6084: padding: 0;
1.421 albertel 6085: height: 1px;
6086: background: black;
6087: }
1.795 www 6088:
1.421 albertel 6089: table.LC_pick_box td.LC_pick_box_submit {
6090: text-align: right;
6091: }
1.795 www 6092:
1.579 raeburn 6093: table.LC_pick_box td.LC_evenrow_value {
6094: text-align: left;
6095: padding: 8px;
6096: background-color: $data_table_light;
6097: }
1.795 www 6098:
1.579 raeburn 6099: table.LC_pick_box td.LC_oddrow_value {
6100: text-align: left;
6101: padding: 8px;
6102: background-color: $data_table_light;
6103: }
1.795 www 6104:
1.579 raeburn 6105: span.LC_helpform_receipt_cat {
6106: font-weight: bold;
6107: }
1.795 www 6108:
1.424 albertel 6109: table.LC_group_priv_box {
6110: background: white;
6111: border: 1px solid black;
6112: border-spacing: 1px;
6113: }
1.795 www 6114:
1.424 albertel 6115: table.LC_group_priv_box td.LC_pick_box_title {
6116: background: $tabbg;
6117: font-weight: bold;
6118: text-align: right;
6119: width: 184px;
6120: }
1.795 www 6121:
1.424 albertel 6122: table.LC_group_priv_box td.LC_groups_fixed {
6123: background: $data_table_light;
6124: text-align: center;
6125: }
1.795 www 6126:
1.424 albertel 6127: table.LC_group_priv_box td.LC_groups_optional {
6128: background: $data_table_dark;
6129: text-align: center;
6130: }
1.795 www 6131:
1.424 albertel 6132: table.LC_group_priv_box td.LC_groups_functionality {
6133: background: $data_table_darker;
6134: text-align: center;
6135: font-weight: bold;
6136: }
1.795 www 6137:
1.424 albertel 6138: table.LC_group_priv td {
6139: text-align: left;
1.803 bisitz 6140: padding: 0;
1.424 albertel 6141: }
6142:
6143: .LC_navbuttons {
6144: margin: 2ex 0ex 2ex 0ex;
6145: }
1.795 www 6146:
1.423 albertel 6147: .LC_topic_bar {
6148: font-weight: bold;
6149: background: $tabbg;
1.918 wenzelju 6150: margin: 1em 0em 1em 2em;
1.805 bisitz 6151: padding: 3px;
1.918 wenzelju 6152: font-size: 1.2em;
1.423 albertel 6153: }
1.795 www 6154:
1.423 albertel 6155: .LC_topic_bar span {
1.918 wenzelju 6156: left: 0.5em;
6157: position: absolute;
1.423 albertel 6158: vertical-align: middle;
1.918 wenzelju 6159: font-size: 1.2em;
1.423 albertel 6160: }
1.795 www 6161:
1.423 albertel 6162: table.LC_course_group_status {
6163: margin: 20px;
6164: }
1.795 www 6165:
1.423 albertel 6166: table.LC_status_selector td {
6167: vertical-align: top;
6168: text-align: center;
1.424 albertel 6169: padding: 4px;
6170: }
1.795 www 6171:
1.599 albertel 6172: div.LC_feedback_link {
1.616 albertel 6173: clear: both;
1.829 kalberla 6174: background: $sidebg;
1.779 bisitz 6175: width: 100%;
1.829 kalberla 6176: padding-bottom: 10px;
6177: border: 1px $tabbg solid;
1.833 kalberla 6178: height: 22px;
6179: line-height: 22px;
6180: padding-top: 5px;
6181: }
6182:
6183: div.LC_feedback_link img {
6184: height: 22px;
1.867 kalberla 6185: vertical-align:middle;
1.829 kalberla 6186: }
6187:
1.911 bisitz 6188: div.LC_feedback_link a {
1.829 kalberla 6189: text-decoration: none;
1.489 raeburn 6190: }
1.795 www 6191:
1.867 kalberla 6192: div.LC_comblock {
1.911 bisitz 6193: display:inline;
1.867 kalberla 6194: color:$font;
6195: font-size:90%;
6196: }
6197:
6198: div.LC_feedback_link div.LC_comblock {
6199: padding-left:5px;
6200: }
6201:
6202: div.LC_feedback_link div.LC_comblock a {
6203: color:$font;
6204: }
6205:
1.489 raeburn 6206: span.LC_feedback_link {
1.858 bisitz 6207: /* background: $feedback_link_bg; */
1.599 albertel 6208: font-size: larger;
6209: }
1.795 www 6210:
1.599 albertel 6211: span.LC_message_link {
1.858 bisitz 6212: /* background: $feedback_link_bg; */
1.599 albertel 6213: font-size: larger;
6214: position: absolute;
6215: right: 1em;
1.489 raeburn 6216: }
1.421 albertel 6217:
1.515 albertel 6218: table.LC_prior_tries {
1.524 albertel 6219: border: 1px solid #000000;
6220: border-collapse: separate;
6221: border-spacing: 1px;
1.515 albertel 6222: }
1.523 albertel 6223:
1.515 albertel 6224: table.LC_prior_tries td {
1.524 albertel 6225: padding: 2px;
1.515 albertel 6226: }
1.523 albertel 6227:
6228: .LC_answer_correct {
1.795 www 6229: background: lightgreen;
6230: color: darkgreen;
6231: padding: 6px;
1.523 albertel 6232: }
1.795 www 6233:
1.523 albertel 6234: .LC_answer_charged_try {
1.797 www 6235: background: #FFAAAA;
1.795 www 6236: color: darkred;
6237: padding: 6px;
1.523 albertel 6238: }
1.795 www 6239:
1.779 bisitz 6240: .LC_answer_not_charged_try,
1.523 albertel 6241: .LC_answer_no_grade,
6242: .LC_answer_late {
1.795 www 6243: background: lightyellow;
1.523 albertel 6244: color: black;
1.795 www 6245: padding: 6px;
1.523 albertel 6246: }
1.795 www 6247:
1.523 albertel 6248: .LC_answer_previous {
1.795 www 6249: background: lightblue;
6250: color: darkblue;
6251: padding: 6px;
1.523 albertel 6252: }
1.795 www 6253:
1.779 bisitz 6254: .LC_answer_no_message {
1.777 tempelho 6255: background: #FFFFFF;
6256: color: black;
1.795 www 6257: padding: 6px;
1.779 bisitz 6258: }
1.795 www 6259:
1.779 bisitz 6260: .LC_answer_unknown {
6261: background: orange;
6262: color: black;
1.795 www 6263: padding: 6px;
1.777 tempelho 6264: }
1.795 www 6265:
1.529 albertel 6266: span.LC_prior_numerical,
6267: span.LC_prior_string,
6268: span.LC_prior_custom,
6269: span.LC_prior_reaction,
6270: span.LC_prior_math {
1.925 bisitz 6271: font-family: $mono;
1.523 albertel 6272: white-space: pre;
6273: }
6274:
1.525 albertel 6275: span.LC_prior_string {
1.925 bisitz 6276: font-family: $mono;
1.525 albertel 6277: white-space: pre;
6278: }
6279:
1.523 albertel 6280: table.LC_prior_option {
6281: width: 100%;
6282: border-collapse: collapse;
6283: }
1.795 www 6284:
1.911 bisitz 6285: table.LC_prior_rank,
1.795 www 6286: table.LC_prior_match {
1.528 albertel 6287: border-collapse: collapse;
6288: }
1.795 www 6289:
1.528 albertel 6290: table.LC_prior_option tr td,
6291: table.LC_prior_rank tr td,
6292: table.LC_prior_match tr td {
1.524 albertel 6293: border: 1px solid #000000;
1.515 albertel 6294: }
6295:
1.855 bisitz 6296: .LC_nobreak {
1.544 albertel 6297: white-space: nowrap;
1.519 raeburn 6298: }
6299:
1.576 raeburn 6300: span.LC_cusr_emph {
6301: font-style: italic;
6302: }
6303:
1.633 raeburn 6304: span.LC_cusr_subheading {
6305: font-weight: normal;
6306: font-size: 85%;
6307: }
6308:
1.861 bisitz 6309: div.LC_docs_entry_move {
1.859 bisitz 6310: border: 1px solid #BBBBBB;
1.545 albertel 6311: background: #DDDDDD;
1.861 bisitz 6312: width: 22px;
1.859 bisitz 6313: padding: 1px;
6314: margin: 0;
1.545 albertel 6315: }
6316:
1.861 bisitz 6317: table.LC_data_table tr > td.LC_docs_entry_commands,
6318: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6319: font-size: x-small;
6320: }
1.795 www 6321:
1.861 bisitz 6322: .LC_docs_entry_parameter {
6323: white-space: nowrap;
6324: }
6325:
1.544 albertel 6326: .LC_docs_copy {
1.545 albertel 6327: color: #000099;
1.544 albertel 6328: }
1.795 www 6329:
1.544 albertel 6330: .LC_docs_cut {
1.545 albertel 6331: color: #550044;
1.544 albertel 6332: }
1.795 www 6333:
1.544 albertel 6334: .LC_docs_rename {
1.545 albertel 6335: color: #009900;
1.544 albertel 6336: }
1.795 www 6337:
1.544 albertel 6338: .LC_docs_remove {
1.545 albertel 6339: color: #990000;
6340: }
6341:
1.547 albertel 6342: .LC_docs_reinit_warn,
6343: .LC_docs_ext_edit {
6344: font-size: x-small;
6345: }
6346:
1.545 albertel 6347: table.LC_docs_adddocs td,
6348: table.LC_docs_adddocs th {
6349: border: 1px solid #BBBBBB;
6350: padding: 4px;
6351: background: #DDDDDD;
1.543 albertel 6352: }
6353:
1.584 albertel 6354: table.LC_sty_begin {
6355: background: #BBFFBB;
6356: }
1.795 www 6357:
1.584 albertel 6358: table.LC_sty_end {
6359: background: #FFBBBB;
6360: }
6361:
1.589 raeburn 6362: table.LC_double_column {
1.803 bisitz 6363: border-width: 0;
1.589 raeburn 6364: border-collapse: collapse;
6365: width: 100%;
6366: padding: 2px;
6367: }
6368:
6369: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6370: top: 2px;
1.589 raeburn 6371: left: 2px;
6372: width: 47%;
6373: vertical-align: top;
6374: }
6375:
6376: table.LC_double_column tr td.LC_right_col {
6377: top: 2px;
1.779 bisitz 6378: right: 2px;
1.589 raeburn 6379: width: 47%;
6380: vertical-align: top;
6381: }
6382:
1.591 raeburn 6383: div.LC_left_float {
6384: float: left;
6385: padding-right: 5%;
1.597 albertel 6386: padding-bottom: 4px;
1.591 raeburn 6387: }
6388:
6389: div.LC_clear_float_header {
1.597 albertel 6390: padding-bottom: 2px;
1.591 raeburn 6391: }
6392:
6393: div.LC_clear_float_footer {
1.597 albertel 6394: padding-top: 10px;
1.591 raeburn 6395: clear: both;
6396: }
6397:
1.597 albertel 6398: div.LC_grade_show_user {
1.941 bisitz 6399: /* border-left: 5px solid $sidebg; */
6400: border-top: 5px solid #000000;
6401: margin: 50px 0 0 0;
1.936 bisitz 6402: padding: 15px 0 5px 10px;
1.597 albertel 6403: }
1.795 www 6404:
1.936 bisitz 6405: div.LC_grade_show_user_odd_row {
1.941 bisitz 6406: /* border-left: 5px solid #000000; */
6407: }
6408:
6409: div.LC_grade_show_user div.LC_Box {
6410: margin-right: 50px;
1.597 albertel 6411: }
6412:
6413: div.LC_grade_submissions,
6414: div.LC_grade_message_center,
1.936 bisitz 6415: div.LC_grade_info_links {
1.597 albertel 6416: margin: 5px;
6417: width: 99%;
6418: background: #FFFFFF;
6419: }
1.795 www 6420:
1.597 albertel 6421: div.LC_grade_submissions_header,
1.936 bisitz 6422: div.LC_grade_message_center_header {
1.705 tempelho 6423: font-weight: bold;
6424: font-size: large;
1.597 albertel 6425: }
1.795 www 6426:
1.597 albertel 6427: div.LC_grade_submissions_body,
1.936 bisitz 6428: div.LC_grade_message_center_body {
1.597 albertel 6429: border: 1px solid black;
6430: width: 99%;
6431: background: #FFFFFF;
6432: }
1.795 www 6433:
1.613 albertel 6434: table.LC_scantron_action {
6435: width: 100%;
6436: }
1.795 www 6437:
1.613 albertel 6438: table.LC_scantron_action tr th {
1.698 harmsja 6439: font-weight:bold;
6440: font-style:normal;
1.613 albertel 6441: }
1.795 www 6442:
1.779 bisitz 6443: .LC_edit_problem_header,
1.614 albertel 6444: div.LC_edit_problem_footer {
1.705 tempelho 6445: font-weight: normal;
6446: font-size: medium;
1.602 albertel 6447: margin: 2px;
1.1060 bisitz 6448: background-color: $sidebg;
1.600 albertel 6449: }
1.795 www 6450:
1.600 albertel 6451: div.LC_edit_problem_header,
1.602 albertel 6452: div.LC_edit_problem_header div,
1.614 albertel 6453: div.LC_edit_problem_footer,
6454: div.LC_edit_problem_footer div,
1.602 albertel 6455: div.LC_edit_problem_editxml_header,
6456: div.LC_edit_problem_editxml_header div {
1.600 albertel 6457: margin-top: 5px;
6458: }
1.795 www 6459:
1.600 albertel 6460: div.LC_edit_problem_header_title {
1.705 tempelho 6461: font-weight: bold;
6462: font-size: larger;
1.602 albertel 6463: background: $tabbg;
6464: padding: 3px;
1.1060 bisitz 6465: margin: 0 0 5px 0;
1.602 albertel 6466: }
1.795 www 6467:
1.602 albertel 6468: table.LC_edit_problem_header_title {
6469: width: 100%;
1.600 albertel 6470: background: $tabbg;
1.602 albertel 6471: }
6472:
6473: div.LC_edit_problem_discards {
6474: float: left;
6475: padding-bottom: 5px;
6476: }
1.795 www 6477:
1.602 albertel 6478: div.LC_edit_problem_saves {
6479: float: right;
6480: padding-bottom: 5px;
1.600 albertel 6481: }
1.795 www 6482:
1.1075.2.34 raeburn 6483: .LC_edit_opt {
6484: padding-left: 1em;
6485: white-space: nowrap;
6486: }
6487:
1.911 bisitz 6488: img.stift {
1.803 bisitz 6489: border-width: 0;
6490: vertical-align: middle;
1.677 riegler 6491: }
1.680 riegler 6492:
1.923 bisitz 6493: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6494: vertical-align: top;
1.777 tempelho 6495: }
1.795 www 6496:
1.716 raeburn 6497: div.LC_createcourse {
1.911 bisitz 6498: margin: 10px 10px 10px 10px;
1.716 raeburn 6499: }
6500:
1.917 raeburn 6501: .LC_dccid {
1.1075.2.38 raeburn 6502: float: right;
1.917 raeburn 6503: margin: 0.2em 0 0 0;
6504: padding: 0;
6505: font-size: 90%;
6506: display:none;
6507: }
6508:
1.897 wenzelju 6509: ol.LC_primary_menu a:hover,
1.721 harmsja 6510: ol#LC_MenuBreadcrumbs a:hover,
6511: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6512: ul#LC_secondary_menu a:hover,
1.721 harmsja 6513: .LC_FormSectionClearButton input:hover
1.795 www 6514: ul.LC_TabContent li:hover a {
1.952 onken 6515: color:$button_hover;
1.911 bisitz 6516: text-decoration:none;
1.693 droeschl 6517: }
6518:
1.779 bisitz 6519: h1 {
1.911 bisitz 6520: padding: 0;
6521: line-height:130%;
1.693 droeschl 6522: }
1.698 harmsja 6523:
1.911 bisitz 6524: h2,
6525: h3,
6526: h4,
6527: h5,
6528: h6 {
6529: margin: 5px 0 5px 0;
6530: padding: 0;
6531: line-height:130%;
1.693 droeschl 6532: }
1.795 www 6533:
6534: .LC_hcell {
1.911 bisitz 6535: padding:3px 15px 3px 15px;
6536: margin: 0;
6537: background-color:$tabbg;
6538: color:$fontmenu;
6539: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6540: }
1.795 www 6541:
1.840 bisitz 6542: .LC_Box > .LC_hcell {
1.911 bisitz 6543: margin: 0 -10px 10px -10px;
1.835 bisitz 6544: }
6545:
1.721 harmsja 6546: .LC_noBorder {
1.911 bisitz 6547: border: 0;
1.698 harmsja 6548: }
1.693 droeschl 6549:
1.721 harmsja 6550: .LC_FormSectionClearButton input {
1.911 bisitz 6551: background-color:transparent;
6552: border: none;
6553: cursor:pointer;
6554: text-decoration:underline;
1.693 droeschl 6555: }
1.763 bisitz 6556:
6557: .LC_help_open_topic {
1.911 bisitz 6558: color: #FFFFFF;
6559: background-color: #EEEEFF;
6560: margin: 1px;
6561: padding: 4px;
6562: border: 1px solid #000033;
6563: white-space: nowrap;
6564: /* vertical-align: middle; */
1.759 neumanie 6565: }
1.693 droeschl 6566:
1.911 bisitz 6567: dl,
6568: ul,
6569: div,
6570: fieldset {
6571: margin: 10px 10px 10px 0;
6572: /* overflow: hidden; */
1.693 droeschl 6573: }
1.795 www 6574:
1.838 bisitz 6575: fieldset > legend {
1.911 bisitz 6576: font-weight: bold;
6577: padding: 0 5px 0 5px;
1.838 bisitz 6578: }
6579:
1.813 bisitz 6580: #LC_nav_bar {
1.911 bisitz 6581: float: left;
1.995 raeburn 6582: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6583: margin: 0 0 2px 0;
1.807 droeschl 6584: }
6585:
1.916 droeschl 6586: #LC_realm {
6587: margin: 0.2em 0 0 0;
6588: padding: 0;
6589: font-weight: bold;
6590: text-align: center;
1.995 raeburn 6591: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6592: }
6593:
1.911 bisitz 6594: #LC_nav_bar em {
6595: font-weight: bold;
6596: font-style: normal;
1.807 droeschl 6597: }
6598:
1.897 wenzelju 6599: ol.LC_primary_menu {
1.934 droeschl 6600: margin: 0;
1.1075.2.2 raeburn 6601: padding: 0;
1.995 raeburn 6602: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6603: }
6604:
1.852 droeschl 6605: ol#LC_PathBreadcrumbs {
1.911 bisitz 6606: margin: 0;
1.693 droeschl 6607: }
6608:
1.897 wenzelju 6609: ol.LC_primary_menu li {
1.1075.2.2 raeburn 6610: color: RGB(80, 80, 80);
6611: vertical-align: middle;
6612: text-align: left;
6613: list-style: none;
6614: float: left;
6615: }
6616:
6617: ol.LC_primary_menu li a {
6618: display: block;
6619: margin: 0;
6620: padding: 0 5px 0 10px;
6621: text-decoration: none;
6622: }
6623:
6624: ol.LC_primary_menu li ul {
6625: display: none;
6626: width: 10em;
6627: background-color: $data_table_light;
6628: }
6629:
6630: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6631: display: block;
6632: position: absolute;
6633: margin: 0;
6634: padding: 0;
1.1075.2.5 raeburn 6635: z-index: 2;
1.1075.2.2 raeburn 6636: }
6637:
6638: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6639: font-size: 90%;
1.911 bisitz 6640: vertical-align: top;
1.1075.2.2 raeburn 6641: float: none;
1.1075.2.5 raeburn 6642: border-left: 1px solid black;
6643: border-right: 1px solid black;
1.1075.2.2 raeburn 6644: }
6645:
6646: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5 raeburn 6647: background-color:$data_table_light;
1.1075.2.2 raeburn 6648: }
6649:
6650: ol.LC_primary_menu li li a:hover {
6651: color:$button_hover;
6652: background-color:$data_table_dark;
1.693 droeschl 6653: }
6654:
1.897 wenzelju 6655: ol.LC_primary_menu li img {
1.911 bisitz 6656: vertical-align: bottom;
1.934 droeschl 6657: height: 1.1em;
1.1075.2.3 raeburn 6658: margin: 0.2em 0 0 0;
1.693 droeschl 6659: }
6660:
1.897 wenzelju 6661: ol.LC_primary_menu a {
1.911 bisitz 6662: color: RGB(80, 80, 80);
6663: text-decoration: none;
1.693 droeschl 6664: }
1.795 www 6665:
1.949 droeschl 6666: ol.LC_primary_menu a.LC_new_message {
6667: font-weight:bold;
6668: color: darkred;
6669: }
6670:
1.975 raeburn 6671: ol.LC_docs_parameters {
6672: margin-left: 0;
6673: padding: 0;
6674: list-style: none;
6675: }
6676:
6677: ol.LC_docs_parameters li {
6678: margin: 0;
6679: padding-right: 20px;
6680: display: inline;
6681: }
6682:
1.976 raeburn 6683: ol.LC_docs_parameters li:before {
6684: content: "\\002022 \\0020";
6685: }
6686:
6687: li.LC_docs_parameters_title {
6688: font-weight: bold;
6689: }
6690:
6691: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6692: content: "";
6693: }
6694:
1.897 wenzelju 6695: ul#LC_secondary_menu {
1.1075.2.23 raeburn 6696: clear: right;
1.911 bisitz 6697: color: $fontmenu;
6698: background: $tabbg;
6699: list-style: none;
6700: padding: 0;
6701: margin: 0;
6702: width: 100%;
1.995 raeburn 6703: text-align: left;
1.1075.2.4 raeburn 6704: float: left;
1.808 droeschl 6705: }
6706:
1.897 wenzelju 6707: ul#LC_secondary_menu li {
1.911 bisitz 6708: font-weight: bold;
6709: line-height: 1.8em;
6710: border-right: 1px solid black;
6711: vertical-align: middle;
1.1075.2.4 raeburn 6712: float: left;
6713: }
6714:
6715: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6716: background-color: $data_table_light;
6717: }
6718:
6719: ul#LC_secondary_menu li a {
6720: padding: 0 0.8em;
6721: }
6722:
6723: ul#LC_secondary_menu li ul {
6724: display: none;
6725: }
6726:
6727: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6728: display: block;
6729: position: absolute;
6730: margin: 0;
6731: padding: 0;
6732: list-style:none;
6733: float: none;
6734: background-color: $data_table_light;
1.1075.2.5 raeburn 6735: z-index: 2;
1.1075.2.10 raeburn 6736: margin-left: -1px;
1.1075.2.4 raeburn 6737: }
6738:
6739: ul#LC_secondary_menu li ul li {
6740: font-size: 90%;
6741: vertical-align: top;
6742: border-left: 1px solid black;
6743: border-right: 1px solid black;
1.1075.2.33 raeburn 6744: background-color: $data_table_light;
1.1075.2.4 raeburn 6745: list-style:none;
6746: float: none;
6747: }
6748:
6749: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6750: background-color: $data_table_dark;
1.807 droeschl 6751: }
6752:
1.847 tempelho 6753: ul.LC_TabContent {
1.911 bisitz 6754: display:block;
6755: background: $sidebg;
6756: border-bottom: solid 1px $lg_border_color;
6757: list-style:none;
1.1020 raeburn 6758: margin: -1px -10px 0 -10px;
1.911 bisitz 6759: padding: 0;
1.693 droeschl 6760: }
6761:
1.795 www 6762: ul.LC_TabContent li,
6763: ul.LC_TabContentBigger li {
1.911 bisitz 6764: float:left;
1.741 harmsja 6765: }
1.795 www 6766:
1.897 wenzelju 6767: ul#LC_secondary_menu li a {
1.911 bisitz 6768: color: $fontmenu;
6769: text-decoration: none;
1.693 droeschl 6770: }
1.795 www 6771:
1.721 harmsja 6772: ul.LC_TabContent {
1.952 onken 6773: min-height:20px;
1.721 harmsja 6774: }
1.795 www 6775:
6776: ul.LC_TabContent li {
1.911 bisitz 6777: vertical-align:middle;
1.959 onken 6778: padding: 0 16px 0 10px;
1.911 bisitz 6779: background-color:$tabbg;
6780: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6781: border-left: solid 1px $font;
1.721 harmsja 6782: }
1.795 www 6783:
1.847 tempelho 6784: ul.LC_TabContent .right {
1.911 bisitz 6785: float:right;
1.847 tempelho 6786: }
6787:
1.911 bisitz 6788: ul.LC_TabContent li a,
6789: ul.LC_TabContent li {
6790: color:rgb(47,47,47);
6791: text-decoration:none;
6792: font-size:95%;
6793: font-weight:bold;
1.952 onken 6794: min-height:20px;
6795: }
6796:
1.959 onken 6797: ul.LC_TabContent li a:hover,
6798: ul.LC_TabContent li a:focus {
1.952 onken 6799: color: $button_hover;
1.959 onken 6800: background:none;
6801: outline:none;
1.952 onken 6802: }
6803:
6804: ul.LC_TabContent li:hover {
6805: color: $button_hover;
6806: cursor:pointer;
1.721 harmsja 6807: }
1.795 www 6808:
1.911 bisitz 6809: ul.LC_TabContent li.active {
1.952 onken 6810: color: $font;
1.911 bisitz 6811: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6812: border-bottom:solid 1px #FFFFFF;
6813: cursor: default;
1.744 ehlerst 6814: }
1.795 www 6815:
1.959 onken 6816: ul.LC_TabContent li.active a {
6817: color:$font;
6818: background:#FFFFFF;
6819: outline: none;
6820: }
1.1047 raeburn 6821:
6822: ul.LC_TabContent li.goback {
6823: float: left;
6824: border-left: none;
6825: }
6826:
1.870 tempelho 6827: #maincoursedoc {
1.911 bisitz 6828: clear:both;
1.870 tempelho 6829: }
6830:
6831: ul.LC_TabContentBigger {
1.911 bisitz 6832: display:block;
6833: list-style:none;
6834: padding: 0;
1.870 tempelho 6835: }
6836:
1.795 www 6837: ul.LC_TabContentBigger li {
1.911 bisitz 6838: vertical-align:bottom;
6839: height: 30px;
6840: font-size:110%;
6841: font-weight:bold;
6842: color: #737373;
1.841 tempelho 6843: }
6844:
1.957 onken 6845: ul.LC_TabContentBigger li.active {
6846: position: relative;
6847: top: 1px;
6848: }
6849:
1.870 tempelho 6850: ul.LC_TabContentBigger li a {
1.911 bisitz 6851: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6852: height: 30px;
6853: line-height: 30px;
6854: text-align: center;
6855: display: block;
6856: text-decoration: none;
1.958 onken 6857: outline: none;
1.741 harmsja 6858: }
1.795 www 6859:
1.870 tempelho 6860: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6861: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6862: color:$font;
1.744 ehlerst 6863: }
1.795 www 6864:
1.870 tempelho 6865: ul.LC_TabContentBigger li b {
1.911 bisitz 6866: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6867: display: block;
6868: float: left;
6869: padding: 0 30px;
1.957 onken 6870: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6871: }
6872:
1.956 onken 6873: ul.LC_TabContentBigger li:hover b {
6874: color:$button_hover;
6875: }
6876:
1.870 tempelho 6877: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6878: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6879: color:$font;
1.957 onken 6880: border: 0;
1.741 harmsja 6881: }
1.693 droeschl 6882:
1.870 tempelho 6883:
1.862 bisitz 6884: ul.LC_CourseBreadcrumbs {
6885: background: $sidebg;
1.1020 raeburn 6886: height: 2em;
1.862 bisitz 6887: padding-left: 10px;
1.1020 raeburn 6888: margin: 0;
1.862 bisitz 6889: list-style-position: inside;
6890: }
6891:
1.911 bisitz 6892: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6893: ol#LC_PathBreadcrumbs {
1.911 bisitz 6894: padding-left: 10px;
6895: margin: 0;
1.933 droeschl 6896: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6897: }
6898:
1.911 bisitz 6899: ol#LC_MenuBreadcrumbs li,
6900: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6901: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6902: display: inline;
1.933 droeschl 6903: white-space: normal;
1.693 droeschl 6904: }
6905:
1.823 bisitz 6906: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6907: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6908: text-decoration: none;
6909: font-size:90%;
1.693 droeschl 6910: }
1.795 www 6911:
1.969 droeschl 6912: ol#LC_MenuBreadcrumbs h1 {
6913: display: inline;
6914: font-size: 90%;
6915: line-height: 2.5em;
6916: margin: 0;
6917: padding: 0;
6918: }
6919:
1.795 www 6920: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6921: text-decoration:none;
6922: font-size:100%;
6923: font-weight:bold;
1.693 droeschl 6924: }
1.795 www 6925:
1.840 bisitz 6926: .LC_Box {
1.911 bisitz 6927: border: solid 1px $lg_border_color;
6928: padding: 0 10px 10px 10px;
1.746 neumanie 6929: }
1.795 www 6930:
1.1020 raeburn 6931: .LC_DocsBox {
6932: border: solid 1px $lg_border_color;
6933: padding: 0 0 10px 10px;
6934: }
6935:
1.795 www 6936: .LC_AboutMe_Image {
1.911 bisitz 6937: float:left;
6938: margin-right:10px;
1.747 neumanie 6939: }
1.795 www 6940:
6941: .LC_Clear_AboutMe_Image {
1.911 bisitz 6942: clear:left;
1.747 neumanie 6943: }
1.795 www 6944:
1.721 harmsja 6945: dl.LC_ListStyleClean dt {
1.911 bisitz 6946: padding-right: 5px;
6947: display: table-header-group;
1.693 droeschl 6948: }
6949:
1.721 harmsja 6950: dl.LC_ListStyleClean dd {
1.911 bisitz 6951: display: table-row;
1.693 droeschl 6952: }
6953:
1.721 harmsja 6954: .LC_ListStyleClean,
6955: .LC_ListStyleSimple,
6956: .LC_ListStyleNormal,
1.795 www 6957: .LC_ListStyleSpecial {
1.911 bisitz 6958: /* display:block; */
6959: list-style-position: inside;
6960: list-style-type: none;
6961: overflow: hidden;
6962: padding: 0;
1.693 droeschl 6963: }
6964:
1.721 harmsja 6965: .LC_ListStyleSimple li,
6966: .LC_ListStyleSimple dd,
6967: .LC_ListStyleNormal li,
6968: .LC_ListStyleNormal dd,
6969: .LC_ListStyleSpecial li,
1.795 www 6970: .LC_ListStyleSpecial dd {
1.911 bisitz 6971: margin: 0;
6972: padding: 5px 5px 5px 10px;
6973: clear: both;
1.693 droeschl 6974: }
6975:
1.721 harmsja 6976: .LC_ListStyleClean li,
6977: .LC_ListStyleClean dd {
1.911 bisitz 6978: padding-top: 0;
6979: padding-bottom: 0;
1.693 droeschl 6980: }
6981:
1.721 harmsja 6982: .LC_ListStyleSimple dd,
1.795 www 6983: .LC_ListStyleSimple li {
1.911 bisitz 6984: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6985: }
6986:
1.721 harmsja 6987: .LC_ListStyleSpecial li,
6988: .LC_ListStyleSpecial dd {
1.911 bisitz 6989: list-style-type: none;
6990: background-color: RGB(220, 220, 220);
6991: margin-bottom: 4px;
1.693 droeschl 6992: }
6993:
1.721 harmsja 6994: table.LC_SimpleTable {
1.911 bisitz 6995: margin:5px;
6996: border:solid 1px $lg_border_color;
1.795 www 6997: }
1.693 droeschl 6998:
1.721 harmsja 6999: table.LC_SimpleTable tr {
1.911 bisitz 7000: padding: 0;
7001: border:solid 1px $lg_border_color;
1.693 droeschl 7002: }
1.795 www 7003:
7004: table.LC_SimpleTable thead {
1.911 bisitz 7005: background:rgb(220,220,220);
1.693 droeschl 7006: }
7007:
1.721 harmsja 7008: div.LC_columnSection {
1.911 bisitz 7009: display: block;
7010: clear: both;
7011: overflow: hidden;
7012: margin: 0;
1.693 droeschl 7013: }
7014:
1.721 harmsja 7015: div.LC_columnSection>* {
1.911 bisitz 7016: float: left;
7017: margin: 10px 20px 10px 0;
7018: overflow:hidden;
1.693 droeschl 7019: }
1.721 harmsja 7020:
1.795 www 7021: table em {
1.911 bisitz 7022: font-weight: bold;
7023: font-style: normal;
1.748 schulted 7024: }
1.795 www 7025:
1.779 bisitz 7026: table.LC_tableBrowseRes,
1.795 www 7027: table.LC_tableOfContent {
1.911 bisitz 7028: border:none;
7029: border-spacing: 1px;
7030: padding: 3px;
7031: background-color: #FFFFFF;
7032: font-size: 90%;
1.753 droeschl 7033: }
1.789 droeschl 7034:
1.911 bisitz 7035: table.LC_tableOfContent {
7036: border-collapse: collapse;
1.789 droeschl 7037: }
7038:
1.771 droeschl 7039: table.LC_tableBrowseRes a,
1.768 schulted 7040: table.LC_tableOfContent a {
1.911 bisitz 7041: background-color: transparent;
7042: text-decoration: none;
1.753 droeschl 7043: }
7044:
1.795 www 7045: table.LC_tableOfContent img {
1.911 bisitz 7046: border: none;
7047: height: 1.3em;
7048: vertical-align: text-bottom;
7049: margin-right: 0.3em;
1.753 droeschl 7050: }
1.757 schulted 7051:
1.795 www 7052: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7053: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7054: }
7055:
1.795 www 7056: a#LC_content_toolbar_everything {
1.911 bisitz 7057: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7058: }
7059:
1.795 www 7060: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7061: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7062: }
7063:
1.795 www 7064: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7065: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7066: }
7067:
1.795 www 7068: a#LC_content_toolbar_changefolder {
1.911 bisitz 7069: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7070: }
7071:
1.795 www 7072: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7073: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7074: }
7075:
1.1043 raeburn 7076: a#LC_content_toolbar_edittoplevel {
7077: background-image:url(/res/adm/pages/edittoplevel.gif);
7078: }
7079:
1.795 www 7080: ul#LC_toolbar li a:hover {
1.911 bisitz 7081: background-position: bottom center;
1.757 schulted 7082: }
7083:
1.795 www 7084: ul#LC_toolbar {
1.911 bisitz 7085: padding: 0;
7086: margin: 2px;
7087: list-style:none;
7088: position:relative;
7089: background-color:white;
1.1075.2.9 raeburn 7090: overflow: auto;
1.757 schulted 7091: }
7092:
1.795 www 7093: ul#LC_toolbar li {
1.911 bisitz 7094: border:1px solid white;
7095: padding: 0;
7096: margin: 0;
7097: float: left;
7098: display:inline;
7099: vertical-align:middle;
1.1075.2.9 raeburn 7100: white-space: nowrap;
1.911 bisitz 7101: }
1.757 schulted 7102:
1.783 amueller 7103:
1.795 www 7104: a.LC_toolbarItem {
1.911 bisitz 7105: display:block;
7106: padding: 0;
7107: margin: 0;
7108: height: 32px;
7109: width: 32px;
7110: color:white;
7111: border: none;
7112: background-repeat:no-repeat;
7113: background-color:transparent;
1.757 schulted 7114: }
7115:
1.915 droeschl 7116: ul.LC_funclist {
7117: margin: 0;
7118: padding: 0.5em 1em 0.5em 0;
7119: }
7120:
1.933 droeschl 7121: ul.LC_funclist > li:first-child {
7122: font-weight:bold;
7123: margin-left:0.8em;
7124: }
7125:
1.915 droeschl 7126: ul.LC_funclist + ul.LC_funclist {
7127: /*
7128: left border as a seperator if we have more than
7129: one list
7130: */
7131: border-left: 1px solid $sidebg;
7132: /*
7133: this hides the left border behind the border of the
7134: outer box if element is wrapped to the next 'line'
7135: */
7136: margin-left: -1px;
7137: }
7138:
1.843 bisitz 7139: ul.LC_funclist li {
1.915 droeschl 7140: display: inline;
1.782 bisitz 7141: white-space: nowrap;
1.915 droeschl 7142: margin: 0 0 0 25px;
7143: line-height: 150%;
1.782 bisitz 7144: }
7145:
1.974 wenzelju 7146: .LC_hidden {
7147: display: none;
7148: }
7149:
1.1030 www 7150: .LCmodal-overlay {
7151: position:fixed;
7152: top:0;
7153: right:0;
7154: bottom:0;
7155: left:0;
7156: height:100%;
7157: width:100%;
7158: margin:0;
7159: padding:0;
7160: background:#999;
7161: opacity:.75;
7162: filter: alpha(opacity=75);
7163: -moz-opacity: 0.75;
7164: z-index:101;
7165: }
7166:
7167: * html .LCmodal-overlay {
7168: position: absolute;
7169: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7170: }
7171:
7172: .LCmodal-window {
7173: position:fixed;
7174: top:50%;
7175: left:50%;
7176: margin:0;
7177: padding:0;
7178: z-index:102;
7179: }
7180:
7181: * html .LCmodal-window {
7182: position:absolute;
7183: }
7184:
7185: .LCclose-window {
7186: position:absolute;
7187: width:32px;
7188: height:32px;
7189: right:8px;
7190: top:8px;
7191: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7192: text-indent:-99999px;
7193: overflow:hidden;
7194: cursor:pointer;
7195: }
7196:
1.1075.2.17 raeburn 7197: /*
7198: styles used by TTH when "Default set of options to pass to tth/m
7199: when converting TeX" in course settings has been set
7200:
7201: option passed: -t
7202:
7203: */
7204:
7205: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7206: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7207: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7208: td div.norm {line-height:normal;}
7209:
7210: /*
7211: option passed -y3
7212: */
7213:
7214: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7215: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7216: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7217:
1.343 albertel 7218: END
7219: }
7220:
1.306 albertel 7221: =pod
7222:
7223: =item * &headtag()
7224:
7225: Returns a uniform footer for LON-CAPA web pages.
7226:
1.307 albertel 7227: Inputs: $title - optional title for the head
7228: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7229: $args - optional arguments
1.319 albertel 7230: force_register - if is true call registerurl so the remote is
7231: informed
1.415 albertel 7232: redirect -> array ref of
7233: 1- seconds before redirect occurs
7234: 2- url to redirect to
7235: 3- whether the side effect should occur
1.315 albertel 7236: (side effect of setting
7237: $env{'internal.head.redirect'} to the url
7238: redirected too)
1.352 albertel 7239: domain -> force to color decorate a page for a specific
7240: domain
7241: function -> force usage of a specific rolish color scheme
7242: bgcolor -> override the default page bgcolor
1.460 albertel 7243: no_auto_mt_title
7244: -> prevent &mt()ing the title arg
1.464 albertel 7245:
1.306 albertel 7246: =cut
7247:
7248: sub headtag {
1.313 albertel 7249: my ($title,$head_extra,$args) = @_;
1.306 albertel 7250:
1.363 albertel 7251: my $function = $args->{'function'} || &get_users_function();
7252: my $domain = $args->{'domain'} || &determinedomain();
7253: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7254: my $httphost = $args->{'use_absolute'};
1.418 albertel 7255: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7256: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7257: #time(),
1.418 albertel 7258: $env{'environment.color.timestamp'},
1.363 albertel 7259: $function,$domain,$bgcolor);
7260:
1.369 www 7261: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7262:
1.308 albertel 7263: my $result =
7264: '<head>'.
1.1075.2.56! raeburn 7265: &font_settings($args);
1.319 albertel 7266:
1.1064 raeburn 7267: my $inhibitprint = &print_suppression();
7268:
1.461 albertel 7269: if (!$args->{'frameset'}) {
7270: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7271: }
1.1075.2.12 raeburn 7272: if ($args->{'force_register'}) {
7273: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7274: }
1.436 albertel 7275: if (!$args->{'no_nav_bar'}
7276: && !$args->{'only_body'}
7277: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7278: $result .= &help_menu_js($httphost);
1.1032 www 7279: $result.=&modal_window();
1.1038 www 7280: $result.=&togglebox_script();
1.1034 www 7281: $result.=&wishlist_window();
1.1041 www 7282: $result.=&LCprogressbarUpdate_script();
1.1034 www 7283: } else {
7284: if ($args->{'add_modal'}) {
7285: $result.=&modal_window();
7286: }
7287: if ($args->{'add_wishlist'}) {
7288: $result.=&wishlist_window();
7289: }
1.1038 www 7290: if ($args->{'add_togglebox'}) {
7291: $result.=&togglebox_script();
7292: }
1.1041 www 7293: if ($args->{'add_progressbar'}) {
7294: $result.=&LCprogressbarUpdate_script();
7295: }
1.436 albertel 7296: }
1.314 albertel 7297: if (ref($args->{'redirect'})) {
1.414 albertel 7298: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7299: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7300: if (!$inhibit_continue) {
7301: $env{'internal.head.redirect'} = $url;
7302: }
1.313 albertel 7303: $result.=<<ADDMETA
7304: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7305: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7306: ADDMETA
7307: }
1.306 albertel 7308: if (!defined($title)) {
7309: $title = 'The LearningOnline Network with CAPA';
7310: }
1.460 albertel 7311: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7312: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 7313: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064 raeburn 7314: .$inhibitprint
1.414 albertel 7315: .$head_extra;
1.1075.2.42 raeburn 7316: if ($env{'browser.mobile'}) {
7317: $result .= '
7318: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7319: <meta name="apple-mobile-web-app-capable" content="yes" />';
7320: }
1.962 droeschl 7321: return $result.'</head>';
1.306 albertel 7322: }
7323:
7324: =pod
7325:
1.340 albertel 7326: =item * &font_settings()
7327:
7328: Returns neccessary <meta> to set the proper encoding
7329:
1.1075.2.56! raeburn 7330: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7331:
7332: =cut
7333:
7334: sub font_settings {
1.1075.2.56! raeburn 7335: my ($args) = @_;
1.340 albertel 7336: my $headerstring='';
1.1075.2.56! raeburn 7337: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
! 7338: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7339: $headerstring.=
1.1075.2.56! raeburn 7340: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'."\n";
1.340 albertel 7341: }
7342: return $headerstring;
7343: }
7344:
1.341 albertel 7345: =pod
7346:
1.1064 raeburn 7347: =item * &print_suppression()
7348:
7349: In course context returns css which causes the body to be blank when media="print",
7350: if printout generation is unavailable for the current resource.
7351:
7352: This could be because:
7353:
7354: (a) printstartdate is in the future
7355:
7356: (b) printenddate is in the past
7357:
7358: (c) there is an active exam block with "printout"
7359: functionality blocked
7360:
7361: Users with pav, pfo or evb privileges are exempt.
7362:
7363: Inputs: none
7364:
7365: =cut
7366:
7367:
7368: sub print_suppression {
7369: my $noprint;
7370: if ($env{'request.course.id'}) {
7371: my $scope = $env{'request.course.id'};
7372: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7373: (&Apache::lonnet::allowed('pfo',$scope))) {
7374: return;
7375: }
7376: if ($env{'request.course.sec'} ne '') {
7377: $scope .= "/$env{'request.course.sec'}";
7378: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7379: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7380: return;
1.1064 raeburn 7381: }
7382: }
7383: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7384: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7385: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7386: if ($blocked) {
7387: my $checkrole = "cm./$cdom/$cnum";
7388: if ($env{'request.course.sec'} ne '') {
7389: $checkrole .= "/$env{'request.course.sec'}";
7390: }
7391: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7392: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7393: $noprint = 1;
7394: }
7395: }
7396: unless ($noprint) {
7397: my $symb = &Apache::lonnet::symbread();
7398: if ($symb ne '') {
7399: my $navmap = Apache::lonnavmaps::navmap->new();
7400: if (ref($navmap)) {
7401: my $res = $navmap->getBySymb($symb);
7402: if (ref($res)) {
7403: if (!$res->resprintable()) {
7404: $noprint = 1;
7405: }
7406: }
7407: }
7408: }
7409: }
7410: if ($noprint) {
7411: return <<"ENDSTYLE";
7412: <style type="text/css" media="print">
7413: body { display:none }
7414: </style>
7415: ENDSTYLE
7416: }
7417: }
7418: return;
7419: }
7420:
7421: =pod
7422:
1.341 albertel 7423: =item * &xml_begin()
7424:
7425: Returns the needed doctype and <html>
7426:
7427: Inputs: none
7428:
7429: =cut
7430:
7431: sub xml_begin {
7432: my $output='';
7433:
7434: if ($env{'browser.mathml'}) {
7435: $output='<?xml version="1.0"?>'
7436: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7437: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7438:
7439: # .'<!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">] >'
7440: .'<!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">'
7441: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7442: .'xmlns="http://www.w3.org/1999/xhtml">';
7443: } else {
1.1075.2.56! raeburn 7444: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n"
! 7445: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7446: }
7447: return $output;
7448: }
1.340 albertel 7449:
7450: =pod
7451:
1.306 albertel 7452: =item * &start_page()
7453:
7454: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7455:
1.648 raeburn 7456: Inputs:
7457:
7458: =over 4
7459:
7460: $title - optional title for the page
7461:
7462: $head_extra - optional extra HTML to incude inside the <head>
7463:
7464: $args - additional optional args supported are:
7465:
7466: =over 8
7467:
7468: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7469: arg on
1.814 bisitz 7470: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7471: add_entries -> additional attributes to add to the <body>
7472: domain -> force to color decorate a page for a
1.317 albertel 7473: specific domain
1.648 raeburn 7474: function -> force usage of a specific rolish color
1.317 albertel 7475: scheme
1.648 raeburn 7476: redirect -> see &headtag()
7477: bgcolor -> override the default page bg color
7478: js_ready -> return a string ready for being used in
1.317 albertel 7479: a javascript writeln
1.648 raeburn 7480: html_encode -> return a string ready for being used in
1.320 albertel 7481: a html attribute
1.648 raeburn 7482: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7483: $forcereg arg
1.648 raeburn 7484: frameset -> if true will start with a <frameset>
1.330 albertel 7485: rather than <body>
1.648 raeburn 7486: skip_phases -> hash ref of
1.338 albertel 7487: head -> skip the <html><head> generation
7488: body -> skip all <body> generation
1.1075.2.12 raeburn 7489: no_inline_link -> if true and in remote mode, don't show the
7490: 'Switch To Inline Menu' link
1.648 raeburn 7491: no_auto_mt_title -> prevent &mt()ing the title arg
7492: inherit_jsmath -> when creating popup window in a page,
7493: should it have jsmath forced on by the
7494: current page
1.867 kalberla 7495: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7496: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7497: group -> includes the current group, if page is for a
7498: specific group
1.361 albertel 7499:
1.648 raeburn 7500: =back
1.460 albertel 7501:
1.648 raeburn 7502: =back
1.562 albertel 7503:
1.306 albertel 7504: =cut
7505:
7506: sub start_page {
1.309 albertel 7507: my ($title,$head_extra,$args) = @_;
1.318 albertel 7508: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7509:
1.315 albertel 7510: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7511: my ($result,@advtools);
1.964 droeschl 7512:
1.338 albertel 7513: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7514: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7515: }
7516:
7517: if (! exists($args->{'skip_phases'}{'body'}) ) {
7518: if ($args->{'frameset'}) {
7519: my $attr_string = &make_attr_string($args->{'force_register'},
7520: $args->{'add_entries'});
7521: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7522: } else {
7523: $result .=
7524: &bodytag($title,
7525: $args->{'function'}, $args->{'add_entries'},
7526: $args->{'only_body'}, $args->{'domain'},
7527: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7528: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7529: $args, \@advtools);
1.831 bisitz 7530: }
1.330 albertel 7531: }
1.338 albertel 7532:
1.315 albertel 7533: if ($args->{'js_ready'}) {
1.713 kaisler 7534: $result = &js_ready($result);
1.315 albertel 7535: }
1.320 albertel 7536: if ($args->{'html_encode'}) {
1.713 kaisler 7537: $result = &html_encode($result);
7538: }
7539:
1.813 bisitz 7540: # Preparation for new and consistent functionlist at top of screen
7541: # if ($args->{'functionlist'}) {
7542: # $result .= &build_functionlist();
7543: #}
7544:
1.964 droeschl 7545: # Don't add anything more if only_body wanted or in const space
7546: return $result if $args->{'only_body'}
7547: || $env{'request.state'} eq 'construct';
1.813 bisitz 7548:
7549: #Breadcrumbs
1.758 kaisler 7550: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7551: &Apache::lonhtmlcommon::clear_breadcrumbs();
7552: #if any br links exists, add them to the breadcrumbs
7553: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7554: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7555: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7556: }
7557: }
1.1075.2.19 raeburn 7558: # if @advtools array contains items add then to the breadcrumbs
7559: if (@advtools > 0) {
7560: &Apache::lonmenu::advtools_crumbs(@advtools);
7561: }
1.758 kaisler 7562:
7563: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7564: if(exists($args->{'bread_crumbs_component'})){
7565: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7566: }else{
7567: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7568: }
1.1075.2.24 raeburn 7569: } elsif (($env{'environment.remote'} eq 'on') &&
7570: ($env{'form.inhibitmenu'} ne 'yes') &&
7571: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7572: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7573: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7574: }
1.315 albertel 7575: return $result;
1.306 albertel 7576: }
7577:
7578: sub end_page {
1.315 albertel 7579: my ($args) = @_;
7580: $env{'internal.end_page'}++;
1.330 albertel 7581: my $result;
1.335 albertel 7582: if ($args->{'discussion'}) {
7583: my ($target,$parser);
7584: if (ref($args->{'discussion'})) {
7585: ($target,$parser) =($args->{'discussion'}{'target'},
7586: $args->{'discussion'}{'parser'});
7587: }
7588: $result .= &Apache::lonxml::xmlend($target,$parser);
7589: }
1.330 albertel 7590: if ($args->{'frameset'}) {
7591: $result .= '</frameset>';
7592: } else {
1.635 raeburn 7593: $result .= &endbodytag($args);
1.330 albertel 7594: }
1.1075.2.6 raeburn 7595: unless ($args->{'notbody'}) {
7596: $result .= "\n</html>";
7597: }
1.330 albertel 7598:
1.315 albertel 7599: if ($args->{'js_ready'}) {
1.317 albertel 7600: $result = &js_ready($result);
1.315 albertel 7601: }
1.335 albertel 7602:
1.320 albertel 7603: if ($args->{'html_encode'}) {
7604: $result = &html_encode($result);
7605: }
1.335 albertel 7606:
1.315 albertel 7607: return $result;
7608: }
7609:
1.1034 www 7610: sub wishlist_window {
7611: return(<<'ENDWISHLIST');
1.1046 raeburn 7612: <script type="text/javascript">
1.1034 www 7613: // <![CDATA[
7614: // <!-- BEGIN LON-CAPA Internal
7615: function set_wishlistlink(title, path) {
7616: if (!title) {
7617: title = document.title;
7618: title = title.replace(/^LON-CAPA /,'');
7619: }
7620: if (!path) {
7621: path = location.pathname;
7622: }
7623: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7624: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7625: }
7626: // END LON-CAPA Internal -->
7627: // ]]>
7628: </script>
7629: ENDWISHLIST
7630: }
7631:
1.1030 www 7632: sub modal_window {
7633: return(<<'ENDMODAL');
1.1046 raeburn 7634: <script type="text/javascript">
1.1030 www 7635: // <![CDATA[
7636: // <!-- BEGIN LON-CAPA Internal
7637: var modalWindow = {
7638: parent:"body",
7639: windowId:null,
7640: content:null,
7641: width:null,
7642: height:null,
7643: close:function()
7644: {
7645: $(".LCmodal-window").remove();
7646: $(".LCmodal-overlay").remove();
7647: },
7648: open:function()
7649: {
7650: var modal = "";
7651: modal += "<div class=\"LCmodal-overlay\"></div>";
7652: 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;\">";
7653: modal += this.content;
7654: modal += "</div>";
7655:
7656: $(this.parent).append(modal);
7657:
7658: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7659: $(".LCclose-window").click(function(){modalWindow.close();});
7660: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7661: }
7662: };
1.1075.2.42 raeburn 7663: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7664: {
7665: modalWindow.windowId = "myModal";
7666: modalWindow.width = width;
7667: modalWindow.height = height;
1.1075.2.42 raeburn 7668: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7669: modalWindow.open();
7670: };
7671: // END LON-CAPA Internal -->
7672: // ]]>
7673: </script>
7674: ENDMODAL
7675: }
7676:
7677: sub modal_link {
1.1075.2.42 raeburn 7678: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7679: unless ($width) { $width=480; }
7680: unless ($height) { $height=400; }
1.1031 www 7681: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 7682: unless ($transparency) { $transparency='true'; }
7683:
1.1074 raeburn 7684: my $target_attr;
7685: if (defined($target)) {
7686: $target_attr = 'target="'.$target.'"';
7687: }
7688: return <<"ENDLINK";
1.1075.2.42 raeburn 7689: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7690: $linktext</a>
7691: ENDLINK
1.1030 www 7692: }
7693:
1.1032 www 7694: sub modal_adhoc_script {
7695: my ($funcname,$width,$height,$content)=@_;
7696: return (<<ENDADHOC);
1.1046 raeburn 7697: <script type="text/javascript">
1.1032 www 7698: // <![CDATA[
7699: var $funcname = function()
7700: {
7701: modalWindow.windowId = "myModal";
7702: modalWindow.width = $width;
7703: modalWindow.height = $height;
7704: modalWindow.content = '$content';
7705: modalWindow.open();
7706: };
7707: // ]]>
7708: </script>
7709: ENDADHOC
7710: }
7711:
1.1041 www 7712: sub modal_adhoc_inner {
7713: my ($funcname,$width,$height,$content)=@_;
7714: my $innerwidth=$width-20;
7715: $content=&js_ready(
1.1042 www 7716: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 7717: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7718: $content.
1.1041 www 7719: &end_scrollbox().
1.1075.2.42 raeburn 7720: &end_page()
1.1041 www 7721: );
7722: return &modal_adhoc_script($funcname,$width,$height,$content);
7723: }
7724:
7725: sub modal_adhoc_window {
7726: my ($funcname,$width,$height,$content,$linktext)=@_;
7727: return &modal_adhoc_inner($funcname,$width,$height,$content).
7728: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7729: }
7730:
7731: sub modal_adhoc_launch {
7732: my ($funcname,$width,$height,$content)=@_;
7733: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7734: <script type="text/javascript">
7735: // <![CDATA[
7736: $funcname();
7737: // ]]>
7738: </script>
7739: ENDLAUNCH
7740: }
7741:
7742: sub modal_adhoc_close {
7743: return (<<ENDCLOSE);
7744: <script type="text/javascript">
7745: // <![CDATA[
7746: modalWindow.close();
7747: // ]]>
7748: </script>
7749: ENDCLOSE
7750: }
7751:
1.1038 www 7752: sub togglebox_script {
7753: return(<<ENDTOGGLE);
7754: <script type="text/javascript">
7755: // <![CDATA[
7756: function LCtoggleDisplay(id,hidetext,showtext) {
7757: link = document.getElementById(id + "link").childNodes[0];
7758: with (document.getElementById(id).style) {
7759: if (display == "none" ) {
7760: display = "inline";
7761: link.nodeValue = hidetext;
7762: } else {
7763: display = "none";
7764: link.nodeValue = showtext;
7765: }
7766: }
7767: }
7768: // ]]>
7769: </script>
7770: ENDTOGGLE
7771: }
7772:
1.1039 www 7773: sub start_togglebox {
7774: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7775: unless ($heading) { $heading=''; } else { $heading.=' '; }
7776: unless ($showtext) { $showtext=&mt('show'); }
7777: unless ($hidetext) { $hidetext=&mt('hide'); }
7778: unless ($headerbg) { $headerbg='#FFFFFF'; }
7779: return &start_data_table().
7780: &start_data_table_header_row().
7781: '<td bgcolor="'.$headerbg.'">'.$heading.
7782: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7783: $showtext.'\')">'.$showtext.'</a>]</td>'.
7784: &end_data_table_header_row().
7785: '<tr id="'.$id.'" style="display:none""><td>';
7786: }
7787:
7788: sub end_togglebox {
7789: return '</td></tr>'.&end_data_table();
7790: }
7791:
1.1041 www 7792: sub LCprogressbar_script {
1.1045 www 7793: my ($id)=@_;
1.1041 www 7794: return(<<ENDPROGRESS);
7795: <script type="text/javascript">
7796: // <![CDATA[
1.1045 www 7797: \$('#progressbar$id').progressbar({
1.1041 www 7798: value: 0,
7799: change: function(event, ui) {
7800: var newVal = \$(this).progressbar('option', 'value');
7801: \$('.pblabel', this).text(LCprogressTxt);
7802: }
7803: });
7804: // ]]>
7805: </script>
7806: ENDPROGRESS
7807: }
7808:
7809: sub LCprogressbarUpdate_script {
7810: return(<<ENDPROGRESSUPDATE);
7811: <style type="text/css">
7812: .ui-progressbar { position:relative; }
7813: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7814: </style>
7815: <script type="text/javascript">
7816: // <![CDATA[
1.1045 www 7817: var LCprogressTxt='---';
7818:
7819: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7820: LCprogressTxt=progresstext;
1.1045 www 7821: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7822: }
7823: // ]]>
7824: </script>
7825: ENDPROGRESSUPDATE
7826: }
7827:
1.1042 www 7828: my $LClastpercent;
1.1045 www 7829: my $LCidcnt;
7830: my $LCcurrentid;
1.1042 www 7831:
1.1041 www 7832: sub LCprogressbar {
1.1042 www 7833: my ($r)=(@_);
7834: $LClastpercent=0;
1.1045 www 7835: $LCidcnt++;
7836: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7837: my $starting=&mt('Starting');
7838: my $content=(<<ENDPROGBAR);
1.1045 www 7839: <div id="progressbar$LCcurrentid">
1.1041 www 7840: <span class="pblabel">$starting</span>
7841: </div>
7842: ENDPROGBAR
1.1045 www 7843: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7844: }
7845:
7846: sub LCprogressbarUpdate {
1.1042 www 7847: my ($r,$val,$text)=@_;
7848: unless ($val) {
7849: if ($LClastpercent) {
7850: $val=$LClastpercent;
7851: } else {
7852: $val=0;
7853: }
7854: }
1.1041 www 7855: if ($val<0) { $val=0; }
7856: if ($val>100) { $val=0; }
1.1042 www 7857: $LClastpercent=$val;
1.1041 www 7858: unless ($text) { $text=$val.'%'; }
7859: $text=&js_ready($text);
1.1044 www 7860: &r_print($r,<<ENDUPDATE);
1.1041 www 7861: <script type="text/javascript">
7862: // <![CDATA[
1.1045 www 7863: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7864: // ]]>
7865: </script>
7866: ENDUPDATE
1.1035 www 7867: }
7868:
1.1042 www 7869: sub LCprogressbarClose {
7870: my ($r)=@_;
7871: $LClastpercent=0;
1.1044 www 7872: &r_print($r,<<ENDCLOSE);
1.1042 www 7873: <script type="text/javascript">
7874: // <![CDATA[
1.1045 www 7875: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7876: // ]]>
7877: </script>
7878: ENDCLOSE
1.1044 www 7879: }
7880:
7881: sub r_print {
7882: my ($r,$to_print)=@_;
7883: if ($r) {
7884: $r->print($to_print);
7885: $r->rflush();
7886: } else {
7887: print($to_print);
7888: }
1.1042 www 7889: }
7890:
1.320 albertel 7891: sub html_encode {
7892: my ($result) = @_;
7893:
1.322 albertel 7894: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7895:
7896: return $result;
7897: }
1.1044 www 7898:
1.317 albertel 7899: sub js_ready {
7900: my ($result) = @_;
7901:
1.323 albertel 7902: $result =~ s/[\n\r]/ /xmsg;
7903: $result =~ s/\\/\\\\/xmsg;
7904: $result =~ s/'/\\'/xmsg;
1.372 albertel 7905: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7906:
7907: return $result;
7908: }
7909:
1.315 albertel 7910: sub validate_page {
7911: if ( exists($env{'internal.start_page'})
1.316 albertel 7912: && $env{'internal.start_page'} > 1) {
7913: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7914: $env{'internal.start_page'}.' '.
1.316 albertel 7915: $ENV{'request.filename'});
1.315 albertel 7916: }
7917: if ( exists($env{'internal.end_page'})
1.316 albertel 7918: && $env{'internal.end_page'} > 1) {
7919: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7920: $env{'internal.end_page'}.' '.
1.316 albertel 7921: $env{'request.filename'});
1.315 albertel 7922: }
7923: if ( exists($env{'internal.start_page'})
7924: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7925: &Apache::lonnet::logthis('start_page called without end_page '.
7926: $env{'request.filename'});
1.315 albertel 7927: }
7928: if ( ! exists($env{'internal.start_page'})
7929: && exists($env{'internal.end_page'})) {
1.316 albertel 7930: &Apache::lonnet::logthis('end_page called without start_page'.
7931: $env{'request.filename'});
1.315 albertel 7932: }
1.306 albertel 7933: }
1.315 albertel 7934:
1.996 www 7935:
7936: sub start_scrollbox {
1.1075.2.56! raeburn 7937: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 7938: unless ($outerwidth) { $outerwidth='520px'; }
7939: unless ($width) { $width='500px'; }
7940: unless ($height) { $height='200px'; }
1.1075 raeburn 7941: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7942: if ($id ne '') {
1.1075.2.42 raeburn 7943: $table_id = ' id="table_'.$id.'"';
7944: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7945: }
1.1075 raeburn 7946: if ($bgcolor ne '') {
7947: $tdcol = "background-color: $bgcolor;";
7948: }
1.1075.2.42 raeburn 7949: my $nicescroll_js;
7950: if ($env{'browser.mobile'}) {
7951: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
7952: }
1.1075 raeburn 7953: return <<"END";
1.1075.2.42 raeburn 7954: $nicescroll_js
7955:
7956: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56! raeburn 7957: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 7958: END
1.996 www 7959: }
7960:
7961: sub end_scrollbox {
1.1036 www 7962: return '</div></td></tr></table>';
1.996 www 7963: }
7964:
1.1075.2.42 raeburn 7965: sub nicescroll_javascript {
7966: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
7967: my %options;
7968: if (ref($cursor) eq 'HASH') {
7969: %options = %{$cursor};
7970: }
7971: unless ($options{'railalign'} =~ /^left|right$/) {
7972: $options{'railalign'} = 'left';
7973: }
7974: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
7975: my $function = &get_users_function();
7976: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
7977: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
7978: $options{'cursorcolor'} = '#00F';
7979: }
7980: }
7981: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
7982: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
7983: $options{'cursoropacity'}='1.0';
7984: }
7985: } else {
7986: $options{'cursoropacity'}='1.0';
7987: }
7988: if ($options{'cursorfixedheight'} eq 'none') {
7989: delete($options{'cursorfixedheight'});
7990: } else {
7991: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
7992: }
7993: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
7994: delete($options{'railoffset'});
7995: }
7996: my @niceoptions;
7997: while (my($key,$value) = each(%options)) {
7998: if ($value =~ /^\{.+\}$/) {
7999: push(@niceoptions,$key.':'.$value);
8000: } else {
8001: push(@niceoptions,$key.':"'.$value.'"');
8002: }
8003: }
8004: my $nicescroll_js = '
8005: $(document).ready(
8006: function() {
8007: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8008: }
8009: );
8010: ';
8011: if ($framecheck) {
8012: $nicescroll_js .= '
8013: function expand_div(caller) {
8014: if (top === self) {
8015: document.getElementById("'.$id.'").style.width = "auto";
8016: document.getElementById("'.$id.'").style.height = "auto";
8017: } else {
8018: try {
8019: if (parent.frames) {
8020: if (parent.frames.length > 1) {
8021: var framesrc = parent.frames[1].location.href;
8022: var currsrc = framesrc.replace(/\#.*$/,"");
8023: if ((caller == "search") || (currsrc == "'.$location.'")) {
8024: document.getElementById("'.$id.'").style.width = "auto";
8025: document.getElementById("'.$id.'").style.height = "auto";
8026: }
8027: }
8028: }
8029: } catch (e) {
8030: return;
8031: }
8032: }
8033: return;
8034: }
8035: ';
8036: }
8037: if ($needjsready) {
8038: $nicescroll_js = '
8039: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8040: } else {
8041: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8042: }
8043: return $nicescroll_js;
8044: }
8045:
1.318 albertel 8046: sub simple_error_page {
1.1075.2.49 raeburn 8047: my ($r,$title,$msg,$args) = @_;
8048: if (ref($args) eq 'HASH') {
8049: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8050: } else {
8051: $msg = &mt($msg);
8052: }
8053:
1.318 albertel 8054: my $page =
8055: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8056: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8057: &Apache::loncommon::end_page();
8058: if (ref($r)) {
8059: $r->print($page);
1.327 albertel 8060: return;
1.318 albertel 8061: }
8062: return $page;
8063: }
1.347 albertel 8064:
8065: {
1.610 albertel 8066: my @row_count;
1.961 onken 8067:
8068: sub start_data_table_count {
8069: unshift(@row_count, 0);
8070: return;
8071: }
8072:
8073: sub end_data_table_count {
8074: shift(@row_count);
8075: return;
8076: }
8077:
1.347 albertel 8078: sub start_data_table {
1.1018 raeburn 8079: my ($add_class,$id) = @_;
1.422 albertel 8080: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8081: my $table_id;
8082: if (defined($id)) {
8083: $table_id = ' id="'.$id.'"';
8084: }
1.961 onken 8085: &start_data_table_count();
1.1018 raeburn 8086: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8087: }
8088:
8089: sub end_data_table {
1.961 onken 8090: &end_data_table_count();
1.389 albertel 8091: return '</table>'."\n";;
1.347 albertel 8092: }
8093:
8094: sub start_data_table_row {
1.974 wenzelju 8095: my ($add_class, $id) = @_;
1.610 albertel 8096: $row_count[0]++;
8097: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8098: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8099: $id = (' id="'.$id.'"') unless ($id eq '');
8100: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8101: }
1.471 banghart 8102:
8103: sub continue_data_table_row {
1.974 wenzelju 8104: my ($add_class, $id) = @_;
1.610 albertel 8105: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8106: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8107: $id = (' id="'.$id.'"') unless ($id eq '');
8108: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8109: }
1.347 albertel 8110:
8111: sub end_data_table_row {
1.389 albertel 8112: return '</tr>'."\n";;
1.347 albertel 8113: }
1.367 www 8114:
1.421 albertel 8115: sub start_data_table_empty_row {
1.707 bisitz 8116: # $row_count[0]++;
1.421 albertel 8117: return '<tr class="LC_empty_row" >'."\n";;
8118: }
8119:
8120: sub end_data_table_empty_row {
8121: return '</tr>'."\n";;
8122: }
8123:
1.367 www 8124: sub start_data_table_header_row {
1.389 albertel 8125: return '<tr class="LC_header_row">'."\n";;
1.367 www 8126: }
8127:
8128: sub end_data_table_header_row {
1.389 albertel 8129: return '</tr>'."\n";;
1.367 www 8130: }
1.890 droeschl 8131:
8132: sub data_table_caption {
8133: my $caption = shift;
8134: return "<caption class=\"LC_caption\">$caption</caption>";
8135: }
1.347 albertel 8136: }
8137:
1.548 albertel 8138: =pod
8139:
8140: =item * &inhibit_menu_check($arg)
8141:
8142: Checks for a inhibitmenu state and generates output to preserve it
8143:
8144: Inputs: $arg - can be any of
8145: - undef - in which case the return value is a string
8146: to add into arguments list of a uri
8147: - 'input' - in which case the return value is a HTML
8148: <form> <input> field of type hidden to
8149: preserve the value
8150: - a url - in which case the return value is the url with
8151: the neccesary cgi args added to preserve the
8152: inhibitmenu state
8153: - a ref to a url - no return value, but the string is
8154: updated to include the neccessary cgi
8155: args to preserve the inhibitmenu state
8156:
8157: =cut
8158:
8159: sub inhibit_menu_check {
8160: my ($arg) = @_;
8161: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8162: if ($arg eq 'input') {
8163: if ($env{'form.inhibitmenu'}) {
8164: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8165: } else {
8166: return
8167: }
8168: }
8169: if ($env{'form.inhibitmenu'}) {
8170: if (ref($arg)) {
8171: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8172: } elsif ($arg eq '') {
8173: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8174: } else {
8175: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8176: }
8177: }
8178: if (!ref($arg)) {
8179: return $arg;
8180: }
8181: }
8182:
1.251 albertel 8183: ###############################################
1.182 matthew 8184:
8185: =pod
8186:
1.549 albertel 8187: =back
8188:
8189: =head1 User Information Routines
8190:
8191: =over 4
8192:
1.405 albertel 8193: =item * &get_users_function()
1.182 matthew 8194:
8195: Used by &bodytag to determine the current users primary role.
8196: Returns either 'student','coordinator','admin', or 'author'.
8197:
8198: =cut
8199:
8200: ###############################################
8201: sub get_users_function {
1.815 tempelho 8202: my $function = 'norole';
1.818 tempelho 8203: if ($env{'request.role'}=~/^(st)/) {
8204: $function='student';
8205: }
1.907 raeburn 8206: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8207: $function='coordinator';
8208: }
1.258 albertel 8209: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8210: $function='admin';
8211: }
1.826 bisitz 8212: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8213: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8214: $function='author';
8215: }
8216: return $function;
1.54 www 8217: }
1.99 www 8218:
8219: ###############################################
8220:
1.233 raeburn 8221: =pod
8222:
1.821 raeburn 8223: =item * &show_course()
8224:
8225: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8226: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8227:
8228: Inputs:
8229: None
8230:
8231: Outputs:
8232: Scalar: 1 if 'Course' to be used, 0 otherwise.
8233:
8234: =cut
8235:
8236: ###############################################
8237: sub show_course {
8238: my $course = !$env{'user.adv'};
8239: if (!$env{'user.adv'}) {
8240: foreach my $env (keys(%env)) {
8241: next if ($env !~ m/^user\.priv\./);
8242: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8243: $course = 0;
8244: last;
8245: }
8246: }
8247: }
8248: return $course;
8249: }
8250:
8251: ###############################################
8252:
8253: =pod
8254:
1.542 raeburn 8255: =item * &check_user_status()
1.274 raeburn 8256:
8257: Determines current status of supplied role for a
8258: specific user. Roles can be active, previous or future.
8259:
8260: Inputs:
8261: user's domain, user's username, course's domain,
1.375 raeburn 8262: course's number, optional section ID.
1.274 raeburn 8263:
8264: Outputs:
8265: role status: active, previous or future.
8266:
8267: =cut
8268:
8269: sub check_user_status {
1.412 raeburn 8270: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8271: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8272: my @uroles = keys %userinfo;
8273: my $srchstr;
8274: my $active_chk = 'none';
1.412 raeburn 8275: my $now = time;
1.274 raeburn 8276: if (@uroles > 0) {
1.908 raeburn 8277: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8278: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8279: } else {
1.412 raeburn 8280: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8281: }
8282: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8283: my $role_end = 0;
8284: my $role_start = 0;
8285: $active_chk = 'active';
1.412 raeburn 8286: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8287: $role_end = $1;
8288: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8289: $role_start = $1;
1.274 raeburn 8290: }
8291: }
8292: if ($role_start > 0) {
1.412 raeburn 8293: if ($now < $role_start) {
1.274 raeburn 8294: $active_chk = 'future';
8295: }
8296: }
8297: if ($role_end > 0) {
1.412 raeburn 8298: if ($now > $role_end) {
1.274 raeburn 8299: $active_chk = 'previous';
8300: }
8301: }
8302: }
8303: }
8304: return $active_chk;
8305: }
8306:
8307: ###############################################
8308:
8309: =pod
8310:
1.405 albertel 8311: =item * &get_sections()
1.233 raeburn 8312:
8313: Determines all the sections for a course including
8314: sections with students and sections containing other roles.
1.419 raeburn 8315: Incoming parameters:
8316:
8317: 1. domain
8318: 2. course number
8319: 3. reference to array containing roles for which sections should
8320: be gathered (optional).
8321: 4. reference to array containing status types for which sections
8322: should be gathered (optional).
8323:
8324: If the third argument is undefined, sections are gathered for any role.
8325: If the fourth argument is undefined, sections are gathered for any status.
8326: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8327:
1.374 raeburn 8328: Returns section hash (keys are section IDs, values are
8329: number of users in each section), subject to the
1.419 raeburn 8330: optional roles filter, optional status filter
1.233 raeburn 8331:
8332: =cut
8333:
8334: ###############################################
8335: sub get_sections {
1.419 raeburn 8336: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8337: if (!defined($cdom) || !defined($cnum)) {
8338: my $cid = $env{'request.course.id'};
8339:
8340: return if (!defined($cid));
8341:
8342: $cdom = $env{'course.'.$cid.'.domain'};
8343: $cnum = $env{'course.'.$cid.'.num'};
8344: }
8345:
8346: my %sectioncount;
1.419 raeburn 8347: my $now = time;
1.240 albertel 8348:
1.1075.2.33 raeburn 8349: my $check_students = 1;
8350: my $only_students = 0;
8351: if (ref($possible_roles) eq 'ARRAY') {
8352: if (grep(/^st$/,@{$possible_roles})) {
8353: if (@{$possible_roles} == 1) {
8354: $only_students = 1;
8355: }
8356: } else {
8357: $check_students = 0;
8358: }
8359: }
8360:
8361: if ($check_students) {
1.276 albertel 8362: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8363: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8364: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8365: my $start_index = &Apache::loncoursedata::CL_START();
8366: my $end_index = &Apache::loncoursedata::CL_END();
8367: my $status;
1.366 albertel 8368: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8369: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8370: $data->[$status_index],
8371: $data->[$start_index],
8372: $data->[$end_index]);
8373: if ($stu_status eq 'Active') {
8374: $status = 'active';
8375: } elsif ($end < $now) {
8376: $status = 'previous';
8377: } elsif ($start > $now) {
8378: $status = 'future';
8379: }
8380: if ($section ne '-1' && $section !~ /^\s*$/) {
8381: if ((!defined($possible_status)) || (($status ne '') &&
8382: (grep/^\Q$status\E$/,@{$possible_status}))) {
8383: $sectioncount{$section}++;
8384: }
1.240 albertel 8385: }
8386: }
8387: }
1.1075.2.33 raeburn 8388: if ($only_students) {
8389: return %sectioncount;
8390: }
1.240 albertel 8391: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8392: foreach my $user (sort(keys(%courseroles))) {
8393: if ($user !~ /^(\w{2})/) { next; }
8394: my ($role) = ($user =~ /^(\w{2})/);
8395: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8396: my ($section,$status);
1.240 albertel 8397: if ($role eq 'cr' &&
8398: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8399: $section=$1;
8400: }
8401: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8402: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8403: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8404: if ($end == -1 && $start == -1) {
8405: next; #deleted role
8406: }
8407: if (!defined($possible_status)) {
8408: $sectioncount{$section}++;
8409: } else {
8410: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8411: $status = 'active';
8412: } elsif ($end < $now) {
8413: $status = 'future';
8414: } elsif ($start > $now) {
8415: $status = 'previous';
8416: }
8417: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8418: $sectioncount{$section}++;
8419: }
8420: }
1.233 raeburn 8421: }
1.366 albertel 8422: return %sectioncount;
1.233 raeburn 8423: }
8424:
1.274 raeburn 8425: ###############################################
1.294 raeburn 8426:
8427: =pod
1.405 albertel 8428:
8429: =item * &get_course_users()
8430:
1.275 raeburn 8431: Retrieves usernames:domains for users in the specified course
8432: with specific role(s), and access status.
8433:
8434: Incoming parameters:
1.277 albertel 8435: 1. course domain
8436: 2. course number
8437: 3. access status: users must have - either active,
1.275 raeburn 8438: previous, future, or all.
1.277 albertel 8439: 4. reference to array of permissible roles
1.288 raeburn 8440: 5. reference to array of section restrictions (optional)
8441: 6. reference to results object (hash of hashes).
8442: 7. reference to optional userdata hash
1.609 raeburn 8443: 8. reference to optional statushash
1.630 raeburn 8444: 9. flag if privileged users (except those set to unhide in
8445: course settings) should be excluded
1.609 raeburn 8446: Keys of top level results hash are roles.
1.275 raeburn 8447: Keys of inner hashes are username:domain, with
8448: values set to access type.
1.288 raeburn 8449: Optional userdata hash returns an array with arguments in the
8450: same order as loncoursedata::get_classlist() for student data.
8451:
1.609 raeburn 8452: Optional statushash returns
8453:
1.288 raeburn 8454: Entries for end, start, section and status are blank because
8455: of the possibility of multiple values for non-student roles.
8456:
1.275 raeburn 8457: =cut
1.405 albertel 8458:
1.275 raeburn 8459: ###############################################
1.405 albertel 8460:
1.275 raeburn 8461: sub get_course_users {
1.630 raeburn 8462: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8463: my %idx = ();
1.419 raeburn 8464: my %seclists;
1.288 raeburn 8465:
8466: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8467: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8468: $idx{end} = &Apache::loncoursedata::CL_END();
8469: $idx{start} = &Apache::loncoursedata::CL_START();
8470: $idx{id} = &Apache::loncoursedata::CL_ID();
8471: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8472: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8473: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8474:
1.290 albertel 8475: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8476: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8477: my $now = time;
1.277 albertel 8478: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8479: my $match = 0;
1.412 raeburn 8480: my $secmatch = 0;
1.419 raeburn 8481: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8482: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8483: if ($section eq '') {
8484: $section = 'none';
8485: }
1.291 albertel 8486: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8487: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8488: $secmatch = 1;
8489: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8490: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8491: $secmatch = 1;
8492: }
8493: } else {
1.419 raeburn 8494: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8495: $secmatch = 1;
8496: }
1.290 albertel 8497: }
1.412 raeburn 8498: if (!$secmatch) {
8499: next;
8500: }
1.419 raeburn 8501: }
1.275 raeburn 8502: if (defined($$types{'active'})) {
1.288 raeburn 8503: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8504: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8505: $match = 1;
1.275 raeburn 8506: }
8507: }
8508: if (defined($$types{'previous'})) {
1.609 raeburn 8509: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8510: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8511: $match = 1;
1.275 raeburn 8512: }
8513: }
8514: if (defined($$types{'future'})) {
1.609 raeburn 8515: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8516: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8517: $match = 1;
1.275 raeburn 8518: }
8519: }
1.609 raeburn 8520: if ($match) {
8521: push(@{$seclists{$student}},$section);
8522: if (ref($userdata) eq 'HASH') {
8523: $$userdata{$student} = $$classlist{$student};
8524: }
8525: if (ref($statushash) eq 'HASH') {
8526: $statushash->{$student}{'st'}{$section} = $status;
8527: }
1.288 raeburn 8528: }
1.275 raeburn 8529: }
8530: }
1.412 raeburn 8531: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8532: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8533: my $now = time;
1.609 raeburn 8534: my %displaystatus = ( previous => 'Expired',
8535: active => 'Active',
8536: future => 'Future',
8537: );
1.1075.2.36 raeburn 8538: my (%nothide,@possdoms);
1.630 raeburn 8539: if ($hidepriv) {
8540: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8541: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8542: if ($user !~ /:/) {
8543: $nothide{join(':',split(/[\@]/,$user))}=1;
8544: } else {
8545: $nothide{$user} = 1;
8546: }
8547: }
1.1075.2.36 raeburn 8548: my @possdoms = ($cdom);
8549: if ($coursehash{'checkforpriv'}) {
8550: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8551: }
1.630 raeburn 8552: }
1.439 raeburn 8553: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8554: my $match = 0;
1.412 raeburn 8555: my $secmatch = 0;
1.439 raeburn 8556: my $status;
1.412 raeburn 8557: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8558: $user =~ s/:$//;
1.439 raeburn 8559: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8560: if ($end == -1 || $start == -1) {
8561: next;
8562: }
8563: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8564: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8565: my ($uname,$udom) = split(/:/,$user);
8566: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8567: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8568: $secmatch = 1;
8569: } elsif ($usec eq '') {
1.420 albertel 8570: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8571: $secmatch = 1;
8572: }
8573: } else {
8574: if (grep(/^\Q$usec\E$/,@{$sections})) {
8575: $secmatch = 1;
8576: }
8577: }
8578: if (!$secmatch) {
8579: next;
8580: }
1.288 raeburn 8581: }
1.419 raeburn 8582: if ($usec eq '') {
8583: $usec = 'none';
8584: }
1.275 raeburn 8585: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8586: if ($hidepriv) {
1.1075.2.36 raeburn 8587: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8588: (!$nothide{$uname.':'.$udom})) {
8589: next;
8590: }
8591: }
1.503 raeburn 8592: if ($end > 0 && $end < $now) {
1.439 raeburn 8593: $status = 'previous';
8594: } elsif ($start > $now) {
8595: $status = 'future';
8596: } else {
8597: $status = 'active';
8598: }
1.277 albertel 8599: foreach my $type (keys(%{$types})) {
1.275 raeburn 8600: if ($status eq $type) {
1.420 albertel 8601: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8602: push(@{$$users{$role}{$user}},$type);
8603: }
1.288 raeburn 8604: $match = 1;
8605: }
8606: }
1.419 raeburn 8607: if (($match) && (ref($userdata) eq 'HASH')) {
8608: if (!exists($$userdata{$uname.':'.$udom})) {
8609: &get_user_info($udom,$uname,\%idx,$userdata);
8610: }
1.420 albertel 8611: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8612: push(@{$seclists{$uname.':'.$udom}},$usec);
8613: }
1.609 raeburn 8614: if (ref($statushash) eq 'HASH') {
8615: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8616: }
1.275 raeburn 8617: }
8618: }
8619: }
8620: }
1.290 albertel 8621: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8622: if ((defined($cdom)) && (defined($cnum))) {
8623: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8624: if ( defined($csettings{'internal.courseowner'}) ) {
8625: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8626: next if ($owner eq '');
8627: my ($ownername,$ownerdom);
8628: if ($owner =~ /^([^:]+):([^:]+)$/) {
8629: $ownername = $1;
8630: $ownerdom = $2;
8631: } else {
8632: $ownername = $owner;
8633: $ownerdom = $cdom;
8634: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8635: }
8636: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8637: if (defined($userdata) &&
1.609 raeburn 8638: !exists($$userdata{$owner})) {
8639: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8640: if (!grep(/^none$/,@{$seclists{$owner}})) {
8641: push(@{$seclists{$owner}},'none');
8642: }
8643: if (ref($statushash) eq 'HASH') {
8644: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8645: }
1.290 albertel 8646: }
1.279 raeburn 8647: }
8648: }
8649: }
1.419 raeburn 8650: foreach my $user (keys(%seclists)) {
8651: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8652: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8653: }
1.275 raeburn 8654: }
8655: return;
8656: }
8657:
1.288 raeburn 8658: sub get_user_info {
8659: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8660: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8661: &plainname($uname,$udom,'lastname');
1.291 albertel 8662: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8663: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8664: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8665: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8666: return;
8667: }
1.275 raeburn 8668:
1.472 raeburn 8669: ###############################################
8670:
8671: =pod
8672:
8673: =item * &get_user_quota()
8674:
1.1075.2.41 raeburn 8675: Retrieves quota assigned for storage of user files.
8676: Default is to report quota for portfolio files.
1.472 raeburn 8677:
8678: Incoming parameters:
8679: 1. user's username
8680: 2. user's domain
1.1075.2.41 raeburn 8681: 3. quota name - portfolio, author, or course
8682: (if no quota name provided, defaults to portfolio).
1.1075.2.42 raeburn 8683: 4. crstype - official, unofficial or community, if quota name is
8684: course
1.472 raeburn 8685:
8686: Returns:
1.536 raeburn 8687: 1. Disk quota (in Mb) assigned to student.
8688: 2. (Optional) Type of setting: custom or default
8689: (individually assigned or default for user's
8690: institutional status).
8691: 3. (Optional) - User's institutional status (e.g., faculty, staff
8692: or student - types as defined in localenroll::inst_usertypes
8693: for user's domain, which determines default quota for user.
8694: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8695:
8696: If a value has been stored in the user's environment,
1.536 raeburn 8697: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 8698: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8699:
8700: =cut
8701:
8702: ###############################################
8703:
8704:
8705: sub get_user_quota {
1.1075.2.42 raeburn 8706: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8707: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8708: if (!defined($udom)) {
8709: $udom = $env{'user.domain'};
8710: }
8711: if (!defined($uname)) {
8712: $uname = $env{'user.name'};
8713: }
8714: if (($udom eq '' || $uname eq '') ||
8715: ($udom eq 'public') && ($uname eq 'public')) {
8716: $quota = 0;
1.536 raeburn 8717: $quotatype = 'default';
8718: $defquota = 0;
1.472 raeburn 8719: } else {
1.536 raeburn 8720: my $inststatus;
1.1075.2.41 raeburn 8721: if ($quotaname eq 'course') {
8722: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8723: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8724: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8725: } else {
8726: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8727: $quota = $cenv{'internal.uploadquota'};
8728: }
1.536 raeburn 8729: } else {
1.1075.2.41 raeburn 8730: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8731: if ($quotaname eq 'author') {
8732: $quota = $env{'environment.authorquota'};
8733: } else {
8734: $quota = $env{'environment.portfolioquota'};
8735: }
8736: $inststatus = $env{'environment.inststatus'};
8737: } else {
8738: my %userenv =
8739: &Apache::lonnet::get('environment',['portfolioquota',
8740: 'authorquota','inststatus'],$udom,$uname);
8741: my ($tmp) = keys(%userenv);
8742: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8743: if ($quotaname eq 'author') {
8744: $quota = $userenv{'authorquota'};
8745: } else {
8746: $quota = $userenv{'portfolioquota'};
8747: }
8748: $inststatus = $userenv{'inststatus'};
8749: } else {
8750: undef(%userenv);
8751: }
8752: }
8753: }
8754: if ($quota eq '' || wantarray) {
8755: if ($quotaname eq 'course') {
8756: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.42 raeburn 8757: if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'community')) {
8758: $defquota = $domdefs{$crstype.'quota'};
8759: }
8760: if ($defquota eq '') {
8761: $defquota = 500;
8762: }
1.1075.2.41 raeburn 8763: } else {
8764: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8765: }
8766: if ($quota eq '') {
8767: $quota = $defquota;
8768: $quotatype = 'default';
8769: } else {
8770: $quotatype = 'custom';
8771: }
1.472 raeburn 8772: }
8773: }
1.536 raeburn 8774: if (wantarray) {
8775: return ($quota,$quotatype,$settingstatus,$defquota);
8776: } else {
8777: return $quota;
8778: }
1.472 raeburn 8779: }
8780:
8781: ###############################################
8782:
8783: =pod
8784:
8785: =item * &default_quota()
8786:
1.536 raeburn 8787: Retrieves default quota assigned for storage of user portfolio files,
8788: given an (optional) user's institutional status.
1.472 raeburn 8789:
8790: Incoming parameters:
1.1075.2.42 raeburn 8791:
1.472 raeburn 8792: 1. domain
1.536 raeburn 8793: 2. (Optional) institutional status(es). This is a : separated list of
8794: status types (e.g., faculty, staff, student etc.)
8795: which apply to the user for whom the default is being retrieved.
8796: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 8797: default quota will be returned.
8798: 3. quota name - portfolio, author, or course
8799: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8800:
8801: Returns:
1.1075.2.42 raeburn 8802:
1.472 raeburn 8803: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 8804: 2. (Optional) institutional type which determined the value of the
8805: default quota.
1.472 raeburn 8806:
8807: If a value has been stored in the domain's configuration db,
8808: it will return that, otherwise it returns 20 (for backwards
8809: compatibility with domains which have not set up a configuration
8810: db file; the original statically defined portfolio quota was 20 Mb).
8811:
1.536 raeburn 8812: If the user's status includes multiple types (e.g., staff and student),
8813: the largest default quota which applies to the user determines the
8814: default quota returned.
8815:
1.472 raeburn 8816: =cut
8817:
8818: ###############################################
8819:
8820:
8821: sub default_quota {
1.1075.2.41 raeburn 8822: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8823: my ($defquota,$settingstatus);
8824: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8825: ['quotas'],$udom);
1.1075.2.41 raeburn 8826: my $key = 'defaultquota';
8827: if ($quotaname eq 'author') {
8828: $key = 'authorquota';
8829: }
1.622 raeburn 8830: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8831: if ($inststatus ne '') {
1.765 raeburn 8832: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8833: foreach my $item (@statuses) {
1.1075.2.41 raeburn 8834: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8835: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8836: if ($defquota eq '') {
1.1075.2.41 raeburn 8837: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8838: $settingstatus = $item;
1.1075.2.41 raeburn 8839: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8840: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8841: $settingstatus = $item;
8842: }
8843: }
1.1075.2.41 raeburn 8844: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8845: if ($quotahash{'quotas'}{$item} ne '') {
8846: if ($defquota eq '') {
8847: $defquota = $quotahash{'quotas'}{$item};
8848: $settingstatus = $item;
8849: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8850: $defquota = $quotahash{'quotas'}{$item};
8851: $settingstatus = $item;
8852: }
1.536 raeburn 8853: }
8854: }
8855: }
8856: }
8857: if ($defquota eq '') {
1.1075.2.41 raeburn 8858: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8859: $defquota = $quotahash{'quotas'}{$key}{'default'};
8860: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8861: $defquota = $quotahash{'quotas'}{'default'};
8862: }
1.536 raeburn 8863: $settingstatus = 'default';
1.1075.2.42 raeburn 8864: if ($defquota eq '') {
8865: if ($quotaname eq 'author') {
8866: $defquota = 500;
8867: }
8868: }
1.536 raeburn 8869: }
8870: } else {
8871: $settingstatus = 'default';
1.1075.2.41 raeburn 8872: if ($quotaname eq 'author') {
8873: $defquota = 500;
8874: } else {
8875: $defquota = 20;
8876: }
1.536 raeburn 8877: }
8878: if (wantarray) {
8879: return ($defquota,$settingstatus);
1.472 raeburn 8880: } else {
1.536 raeburn 8881: return $defquota;
1.472 raeburn 8882: }
8883: }
8884:
1.1075.2.41 raeburn 8885: ###############################################
8886:
8887: =pod
8888:
1.1075.2.42 raeburn 8889: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 8890:
8891: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 8892: of existing file within authoring space will cause quota for the authoring
8893: space to be exceeded.
8894:
8895: Same, if upload of a file directly to a course/community via Course Editor
8896: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 8897:
8898: Inputs: 6
1.1075.2.42 raeburn 8899: 1. username or coursenum
1.1075.2.41 raeburn 8900: 2. domain
1.1075.2.42 raeburn 8901: 3. context ('author' or 'course')
1.1075.2.41 raeburn 8902: 4. filename of file for which action is being requested
8903: 5. filesize (kB) of file
8904: 6. action being taken: copy or upload.
8905:
8906: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
8907: otherwise return null.
8908:
1.1075.2.42 raeburn 8909: =back
8910:
1.1075.2.41 raeburn 8911: =cut
8912:
1.1075.2.42 raeburn 8913: sub excess_filesize_warning {
8914: my ($uname,$udom,$context,$filename,$filesize,$action) = @_;
8915: my $current_disk_usage = 0;
8916: my $disk_quota = &get_user_quota($uname,$udom,$context); #expressed in MB
8917: if ($context eq 'author') {
8918: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8919: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8920: } else {
8921: foreach my $subdir ('docs','supplemental') {
8922: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8923: }
8924: }
1.1075.2.41 raeburn 8925: $disk_quota = int($disk_quota * 1000);
8926: if (($current_disk_usage + $filesize) > $disk_quota) {
8927: return '<p><span class="LC_warning">'.
8928: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
8929: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</span>'.
8930: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
8931: $disk_quota,$current_disk_usage).
8932: '</p>';
8933: }
8934: return;
8935: }
8936:
8937: ###############################################
8938:
8939:
1.384 raeburn 8940: sub get_secgrprole_info {
8941: my ($cdom,$cnum,$needroles,$type) = @_;
8942: my %sections_count = &get_sections($cdom,$cnum);
8943: my @sections = (sort {$a <=> $b} keys(%sections_count));
8944: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8945: my @groups = sort(keys(%curr_groups));
8946: my $allroles = [];
8947: my $rolehash;
8948: my $accesshash = {
8949: active => 'Currently has access',
8950: future => 'Will have future access',
8951: previous => 'Previously had access',
8952: };
8953: if ($needroles) {
8954: $rolehash = {'all' => 'all'};
1.385 albertel 8955: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8956: if (&Apache::lonnet::error(%user_roles)) {
8957: undef(%user_roles);
8958: }
8959: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8960: my ($role)=split(/\:/,$item,2);
8961: if ($role eq 'cr') { next; }
8962: if ($role =~ /^cr/) {
8963: $$rolehash{$role} = (split('/',$role))[3];
8964: } else {
8965: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8966: }
8967: }
8968: foreach my $key (sort(keys(%{$rolehash}))) {
8969: push(@{$allroles},$key);
8970: }
8971: push (@{$allroles},'st');
8972: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8973: }
8974: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8975: }
8976:
1.555 raeburn 8977: sub user_picker {
1.994 raeburn 8978: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8979: my $currdom = $dom;
8980: my %curr_selected = (
8981: srchin => 'dom',
1.580 raeburn 8982: srchby => 'lastname',
1.555 raeburn 8983: );
8984: my $srchterm;
1.625 raeburn 8985: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 8986: if ($srch->{'srchby'} ne '') {
8987: $curr_selected{'srchby'} = $srch->{'srchby'};
8988: }
8989: if ($srch->{'srchin'} ne '') {
8990: $curr_selected{'srchin'} = $srch->{'srchin'};
8991: }
8992: if ($srch->{'srchtype'} ne '') {
8993: $curr_selected{'srchtype'} = $srch->{'srchtype'};
8994: }
8995: if ($srch->{'srchdomain'} ne '') {
8996: $currdom = $srch->{'srchdomain'};
8997: }
8998: $srchterm = $srch->{'srchterm'};
8999: }
9000: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9001: 'usr' => 'Search criteria',
1.563 raeburn 9002: 'doma' => 'Domain/institution to search',
1.558 albertel 9003: 'uname' => 'username',
9004: 'lastname' => 'last name',
1.555 raeburn 9005: 'lastfirst' => 'last name, first name',
1.558 albertel 9006: 'crs' => 'in this course',
1.576 raeburn 9007: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9008: 'alc' => 'all LON-CAPA',
1.573 raeburn 9009: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9010: 'exact' => 'is',
9011: 'contains' => 'contains',
1.569 raeburn 9012: 'begins' => 'begins with',
1.571 raeburn 9013: 'youm' => "You must include some text to search for.",
9014: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9015: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9016: 'yomc' => "You must choose a domain when using an institutional directory search.",
9017: 'ymcd' => "You must choose a domain when using a domain search.",
9018: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9019: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9020: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9021: );
1.563 raeburn 9022: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9023: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9024:
9025: my @srchins = ('crs','dom','alc','instd');
9026:
9027: foreach my $option (@srchins) {
9028: # FIXME 'alc' option unavailable until
9029: # loncreateuser::print_user_query_page()
9030: # has been completed.
9031: next if ($option eq 'alc');
1.880 raeburn 9032: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9033: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9034: if ($curr_selected{'srchin'} eq $option) {
9035: $srchinsel .= '
9036: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9037: } else {
9038: $srchinsel .= '
9039: <option value="'.$option.'">'.$lt{$option}.'</option>';
9040: }
1.555 raeburn 9041: }
1.563 raeburn 9042: $srchinsel .= "\n </select>\n";
1.555 raeburn 9043:
9044: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9045: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9046: if ($curr_selected{'srchby'} eq $option) {
9047: $srchbysel .= '
9048: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9049: } else {
9050: $srchbysel .= '
9051: <option value="'.$option.'">'.$lt{$option}.'</option>';
9052: }
9053: }
9054: $srchbysel .= "\n </select>\n";
9055:
9056: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9057: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9058: if ($curr_selected{'srchtype'} eq $option) {
9059: $srchtypesel .= '
9060: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9061: } else {
9062: $srchtypesel .= '
9063: <option value="'.$option.'">'.$lt{$option}.'</option>';
9064: }
9065: }
9066: $srchtypesel .= "\n </select>\n";
9067:
1.558 albertel 9068: my ($newuserscript,$new_user_create);
1.994 raeburn 9069: my $context_dom = $env{'request.role.domain'};
9070: if ($context eq 'requestcrs') {
9071: if ($env{'form.coursedom'} ne '') {
9072: $context_dom = $env{'form.coursedom'};
9073: }
9074: }
1.556 raeburn 9075: if ($forcenewuser) {
1.576 raeburn 9076: if (ref($srch) eq 'HASH') {
1.994 raeburn 9077: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9078: if ($cancreate) {
9079: $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>';
9080: } else {
1.799 bisitz 9081: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9082: my %usertypetext = (
9083: official => 'institutional',
9084: unofficial => 'non-institutional',
9085: );
1.799 bisitz 9086: $new_user_create = '<p class="LC_warning">'
9087: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9088: .' '
9089: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9090: ,'<a href="'.$helplink.'">','</a>')
9091: .'</p><br />';
1.627 raeburn 9092: }
1.576 raeburn 9093: }
9094: }
9095:
1.556 raeburn 9096: $newuserscript = <<"ENDSCRIPT";
9097:
1.570 raeburn 9098: function setSearch(createnew,callingForm) {
1.556 raeburn 9099: if (createnew == 1) {
1.570 raeburn 9100: for (var i=0; i<callingForm.srchby.length; i++) {
9101: if (callingForm.srchby.options[i].value == 'uname') {
9102: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9103: }
9104: }
1.570 raeburn 9105: for (var i=0; i<callingForm.srchin.length; i++) {
9106: if ( callingForm.srchin.options[i].value == 'dom') {
9107: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9108: }
9109: }
1.570 raeburn 9110: for (var i=0; i<callingForm.srchtype.length; i++) {
9111: if (callingForm.srchtype.options[i].value == 'exact') {
9112: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9113: }
9114: }
1.570 raeburn 9115: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9116: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9117: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9118: }
9119: }
9120: }
9121: }
9122: ENDSCRIPT
1.558 albertel 9123:
1.556 raeburn 9124: }
9125:
1.555 raeburn 9126: my $output = <<"END_BLOCK";
1.556 raeburn 9127: <script type="text/javascript">
1.824 bisitz 9128: // <![CDATA[
1.570 raeburn 9129: function validateEntry(callingForm) {
1.558 albertel 9130:
1.556 raeburn 9131: var checkok = 1;
1.558 albertel 9132: var srchin;
1.570 raeburn 9133: for (var i=0; i<callingForm.srchin.length; i++) {
9134: if ( callingForm.srchin[i].checked ) {
9135: srchin = callingForm.srchin[i].value;
1.558 albertel 9136: }
9137: }
9138:
1.570 raeburn 9139: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9140: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9141: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9142: var srchterm = callingForm.srchterm.value;
9143: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9144: var msg = "";
9145:
9146: if (srchterm == "") {
9147: checkok = 0;
1.571 raeburn 9148: msg += "$lt{'youm'}\\n";
1.556 raeburn 9149: }
9150:
1.569 raeburn 9151: if (srchtype== 'begins') {
9152: if (srchterm.length < 2) {
9153: checkok = 0;
1.571 raeburn 9154: msg += "$lt{'thte'}\\n";
1.569 raeburn 9155: }
9156: }
9157:
1.556 raeburn 9158: if (srchtype== 'contains') {
9159: if (srchterm.length < 3) {
9160: checkok = 0;
1.571 raeburn 9161: msg += "$lt{'thet'}\\n";
1.556 raeburn 9162: }
9163: }
9164: if (srchin == 'instd') {
9165: if (srchdomain == '') {
9166: checkok = 0;
1.571 raeburn 9167: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9168: }
9169: }
9170: if (srchin == 'dom') {
9171: if (srchdomain == '') {
9172: checkok = 0;
1.571 raeburn 9173: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9174: }
9175: }
9176: if (srchby == 'lastfirst') {
9177: if (srchterm.indexOf(",") == -1) {
9178: checkok = 0;
1.571 raeburn 9179: msg += "$lt{'whus'}\\n";
1.556 raeburn 9180: }
9181: if (srchterm.indexOf(",") == srchterm.length -1) {
9182: checkok = 0;
1.571 raeburn 9183: msg += "$lt{'whse'}\\n";
1.556 raeburn 9184: }
9185: }
9186: if (checkok == 0) {
1.571 raeburn 9187: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9188: return;
9189: }
9190: if (checkok == 1) {
1.570 raeburn 9191: callingForm.submit();
1.556 raeburn 9192: }
9193: }
9194:
9195: $newuserscript
9196:
1.824 bisitz 9197: // ]]>
1.556 raeburn 9198: </script>
1.558 albertel 9199:
9200: $new_user_create
9201:
1.555 raeburn 9202: END_BLOCK
1.558 albertel 9203:
1.876 raeburn 9204: $output .= &Apache::lonhtmlcommon::start_pick_box().
9205: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9206: $domform.
9207: &Apache::lonhtmlcommon::row_closure().
9208: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9209: $srchbysel.
9210: $srchtypesel.
9211: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9212: $srchinsel.
9213: &Apache::lonhtmlcommon::row_closure(1).
9214: &Apache::lonhtmlcommon::end_pick_box().
9215: '<br />';
1.555 raeburn 9216: return $output;
9217: }
9218:
1.612 raeburn 9219: sub user_rule_check {
1.615 raeburn 9220: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9221: my $response;
9222: if (ref($usershash) eq 'HASH') {
9223: foreach my $user (keys(%{$usershash})) {
9224: my ($uname,$udom) = split(/:/,$user);
9225: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9226: my ($id,$newuser);
1.612 raeburn 9227: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9228: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9229: $id = $usershash->{$user}->{'id'};
9230: }
9231: my $inst_response;
9232: if (ref($checks) eq 'HASH') {
9233: if (defined($checks->{'username'})) {
1.615 raeburn 9234: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9235: &Apache::lonnet::get_instuser($udom,$uname);
9236: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9237: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9238: &Apache::lonnet::get_instuser($udom,undef,$id);
9239: }
1.615 raeburn 9240: } else {
9241: ($inst_response,%{$inst_results->{$user}}) =
9242: &Apache::lonnet::get_instuser($udom,$uname);
9243: return;
1.612 raeburn 9244: }
1.615 raeburn 9245: if (!$got_rules->{$udom}) {
1.612 raeburn 9246: my %domconfig = &Apache::lonnet::get_dom('configuration',
9247: ['usercreation'],$udom);
9248: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9249: foreach my $item ('username','id') {
1.612 raeburn 9250: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9251: $$curr_rules{$udom}{$item} =
9252: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9253: }
9254: }
9255: }
1.615 raeburn 9256: $got_rules->{$udom} = 1;
1.585 raeburn 9257: }
1.612 raeburn 9258: foreach my $item (keys(%{$checks})) {
9259: if (ref($$curr_rules{$udom}) eq 'HASH') {
9260: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9261: if (@{$$curr_rules{$udom}{$item}} > 0) {
9262: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9263: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9264: if ($rule_check{$rule}) {
9265: $$rulematch{$user}{$item} = $rule;
9266: if ($inst_response eq 'ok') {
1.615 raeburn 9267: if (ref($inst_results) eq 'HASH') {
9268: if (ref($inst_results->{$user}) eq 'HASH') {
9269: if (keys(%{$inst_results->{$user}}) == 0) {
9270: $$alerts{$item}{$udom}{$uname} = 1;
9271: }
1.612 raeburn 9272: }
9273: }
1.615 raeburn 9274: }
9275: last;
1.585 raeburn 9276: }
9277: }
9278: }
9279: }
9280: }
9281: }
9282: }
9283: }
1.612 raeburn 9284: return;
9285: }
9286:
9287: sub user_rule_formats {
9288: my ($domain,$domdesc,$curr_rules,$check) = @_;
9289: my %text = (
9290: 'username' => 'Usernames',
9291: 'id' => 'IDs',
9292: );
9293: my $output;
9294: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9295: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9296: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9297: $output = '<br />'.
9298: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9299: '<span class="LC_cusr_emph">','</span>',$domdesc).
9300: ' <ul>';
1.612 raeburn 9301: foreach my $rule (@{$ruleorder}) {
9302: if (ref($curr_rules) eq 'ARRAY') {
9303: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9304: if (ref($rules->{$rule}) eq 'HASH') {
9305: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9306: $rules->{$rule}{'desc'}.'</li>';
9307: }
9308: }
9309: }
9310: }
9311: $output .= '</ul>';
9312: }
9313: }
9314: return $output;
9315: }
9316:
9317: sub instrule_disallow_msg {
1.615 raeburn 9318: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9319: my $response;
9320: my %text = (
9321: item => 'username',
9322: items => 'usernames',
9323: match => 'matches',
9324: do => 'does',
9325: action => 'a username',
9326: one => 'one',
9327: );
9328: if ($count > 1) {
9329: $text{'item'} = 'usernames';
9330: $text{'match'} ='match';
9331: $text{'do'} = 'do';
9332: $text{'action'} = 'usernames',
9333: $text{'one'} = 'ones';
9334: }
9335: if ($checkitem eq 'id') {
9336: $text{'items'} = 'IDs';
9337: $text{'item'} = 'ID';
9338: $text{'action'} = 'an ID';
1.615 raeburn 9339: if ($count > 1) {
9340: $text{'item'} = 'IDs';
9341: $text{'action'} = 'IDs';
9342: }
1.612 raeburn 9343: }
1.674 bisitz 9344: $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 9345: if ($mode eq 'upload') {
9346: if ($checkitem eq 'username') {
9347: $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'}.");
9348: } elsif ($checkitem eq 'id') {
1.674 bisitz 9349: $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 9350: }
1.669 raeburn 9351: } elsif ($mode eq 'selfcreate') {
9352: if ($checkitem eq 'id') {
9353: $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.");
9354: }
1.615 raeburn 9355: } else {
9356: if ($checkitem eq 'username') {
9357: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9358: } elsif ($checkitem eq 'id') {
9359: $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.");
9360: }
1.612 raeburn 9361: }
9362: return $response;
1.585 raeburn 9363: }
9364:
1.624 raeburn 9365: sub personal_data_fieldtitles {
9366: my %fieldtitles = &Apache::lonlocal::texthash (
9367: id => 'Student/Employee ID',
9368: permanentemail => 'E-mail address',
9369: lastname => 'Last Name',
9370: firstname => 'First Name',
9371: middlename => 'Middle Name',
9372: generation => 'Generation',
9373: gen => 'Generation',
1.765 raeburn 9374: inststatus => 'Affiliation',
1.624 raeburn 9375: );
9376: return %fieldtitles;
9377: }
9378:
1.642 raeburn 9379: sub sorted_inst_types {
9380: my ($dom) = @_;
9381: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9382: my $othertitle = &mt('All users');
9383: if ($env{'request.course.id'}) {
1.668 raeburn 9384: $othertitle = &mt('Any users');
1.642 raeburn 9385: }
9386: my @types;
9387: if (ref($order) eq 'ARRAY') {
9388: @types = @{$order};
9389: }
9390: if (@types == 0) {
9391: if (ref($usertypes) eq 'HASH') {
9392: @types = sort(keys(%{$usertypes}));
9393: }
9394: }
9395: if (keys(%{$usertypes}) > 0) {
9396: $othertitle = &mt('Other users');
9397: }
9398: return ($othertitle,$usertypes,\@types);
9399: }
9400:
1.645 raeburn 9401: sub get_institutional_codes {
9402: my ($settings,$allcourses,$LC_code) = @_;
9403: # Get complete list of course sections to update
9404: my @currsections = ();
9405: my @currxlists = ();
9406: my $coursecode = $$settings{'internal.coursecode'};
9407:
9408: if ($$settings{'internal.sectionnums'} ne '') {
9409: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9410: }
9411:
9412: if ($$settings{'internal.crosslistings'} ne '') {
9413: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9414: }
9415:
9416: if (@currxlists > 0) {
9417: foreach (@currxlists) {
9418: if (m/^([^:]+):(\w*)$/) {
9419: unless (grep/^$1$/,@{$allcourses}) {
9420: push @{$allcourses},$1;
9421: $$LC_code{$1} = $2;
9422: }
9423: }
9424: }
9425: }
9426:
9427: if (@currsections > 0) {
9428: foreach (@currsections) {
9429: if (m/^(\w+):(\w*)$/) {
9430: my $sec = $coursecode.$1;
9431: my $lc_sec = $2;
9432: unless (grep/^$sec$/,@{$allcourses}) {
9433: push @{$allcourses},$sec;
9434: $$LC_code{$sec} = $lc_sec;
9435: }
9436: }
9437: }
9438: }
9439: return;
9440: }
9441:
1.971 raeburn 9442: sub get_standard_codeitems {
9443: return ('Year','Semester','Department','Number','Section');
9444: }
9445:
1.112 bowersj2 9446: =pod
9447:
1.780 raeburn 9448: =head1 Slot Helpers
9449:
9450: =over 4
9451:
9452: =item * sorted_slots()
9453:
1.1040 raeburn 9454: Sorts an array of slot names in order of an optional sort key,
9455: default sort is by slot start time (earliest first).
1.780 raeburn 9456:
9457: Inputs:
9458:
9459: =over 4
9460:
9461: slotsarr - Reference to array of unsorted slot names.
9462:
9463: slots - Reference to hash of hash, where outer hash keys are slot names.
9464:
1.1040 raeburn 9465: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9466:
1.549 albertel 9467: =back
9468:
1.780 raeburn 9469: Returns:
9470:
9471: =over 4
9472:
1.1040 raeburn 9473: sorted - An array of slot names sorted by a specified sort key
9474: (default sort key is start time of the slot).
1.780 raeburn 9475:
9476: =back
9477:
9478: =cut
9479:
9480:
9481: sub sorted_slots {
1.1040 raeburn 9482: my ($slotsarr,$slots,$sortkey) = @_;
9483: if ($sortkey eq '') {
9484: $sortkey = 'starttime';
9485: }
1.780 raeburn 9486: my @sorted;
9487: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9488: @sorted =
9489: sort {
9490: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9491: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9492: }
9493: if (ref($slots->{$a})) { return -1;}
9494: if (ref($slots->{$b})) { return 1;}
9495: return 0;
9496: } @{$slotsarr};
9497: }
9498: return @sorted;
9499: }
9500:
1.1040 raeburn 9501: =pod
9502:
9503: =item * get_future_slots()
9504:
9505: Inputs:
9506:
9507: =over 4
9508:
9509: cnum - course number
9510:
9511: cdom - course domain
9512:
9513: now - current UNIX time
9514:
9515: symb - optional symb
9516:
9517: =back
9518:
9519: Returns:
9520:
9521: =over 4
9522:
9523: sorted_reservable - ref to array of student_schedulable slots currently
9524: reservable, ordered by end date of reservation period.
9525:
9526: reservable_now - ref to hash of student_schedulable slots currently
9527: reservable.
9528:
9529: Keys in inner hash are:
9530: (a) symb: either blank or symb to which slot use is restricted.
9531: (b) endreserve: end date of reservation period.
9532:
9533: sorted_future - ref to array of student_schedulable slots reservable in
9534: the future, ordered by start date of reservation period.
9535:
9536: future_reservable - ref to hash of student_schedulable slots reservable
9537: in the future.
9538:
9539: Keys in inner hash are:
9540: (a) symb: either blank or symb to which slot use is restricted.
9541: (b) startreserve: start date of reservation period.
9542:
9543: =back
9544:
9545: =cut
9546:
9547: sub get_future_slots {
9548: my ($cnum,$cdom,$now,$symb) = @_;
9549: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9550: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9551: foreach my $slot (keys(%slots)) {
9552: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9553: if ($symb) {
9554: next if (($slots{$slot}->{'symb'} ne '') &&
9555: ($slots{$slot}->{'symb'} ne $symb));
9556: }
9557: if (($slots{$slot}->{'starttime'} > $now) &&
9558: ($slots{$slot}->{'endtime'} > $now)) {
9559: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9560: my $userallowed = 0;
9561: if ($slots{$slot}->{'allowedsections'}) {
9562: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9563: if (!defined($env{'request.role.sec'})
9564: && grep(/^No section assigned$/,@allowed_sec)) {
9565: $userallowed=1;
9566: } else {
9567: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9568: $userallowed=1;
9569: }
9570: }
9571: unless ($userallowed) {
9572: if (defined($env{'request.course.groups'})) {
9573: my @groups = split(/:/,$env{'request.course.groups'});
9574: foreach my $group (@groups) {
9575: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9576: $userallowed=1;
9577: last;
9578: }
9579: }
9580: }
9581: }
9582: }
9583: if ($slots{$slot}->{'allowedusers'}) {
9584: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9585: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9586: if (grep(/^\Q$user\E$/,@allowed_users)) {
9587: $userallowed = 1;
9588: }
9589: }
9590: next unless($userallowed);
9591: }
9592: my $startreserve = $slots{$slot}->{'startreserve'};
9593: my $endreserve = $slots{$slot}->{'endreserve'};
9594: my $symb = $slots{$slot}->{'symb'};
9595: if (($startreserve < $now) &&
9596: (!$endreserve || $endreserve > $now)) {
9597: my $lastres = $endreserve;
9598: if (!$lastres) {
9599: $lastres = $slots{$slot}->{'starttime'};
9600: }
9601: $reservable_now{$slot} = {
9602: symb => $symb,
9603: endreserve => $lastres
9604: };
9605: } elsif (($startreserve > $now) &&
9606: (!$endreserve || $endreserve > $startreserve)) {
9607: $future_reservable{$slot} = {
9608: symb => $symb,
9609: startreserve => $startreserve
9610: };
9611: }
9612: }
9613: }
9614: my @unsorted_reservable = keys(%reservable_now);
9615: if (@unsorted_reservable > 0) {
9616: @sorted_reservable =
9617: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9618: }
9619: my @unsorted_future = keys(%future_reservable);
9620: if (@unsorted_future > 0) {
9621: @sorted_future =
9622: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9623: }
9624: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9625: }
1.780 raeburn 9626:
9627: =pod
9628:
1.1057 foxr 9629: =back
9630:
1.549 albertel 9631: =head1 HTTP Helpers
9632:
9633: =over 4
9634:
1.648 raeburn 9635: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9636:
1.258 albertel 9637: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9638: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9639: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9640:
9641: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9642: $possible_names is an ref to an array of form element names. As an example:
9643: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9644: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9645:
9646: =cut
1.1 albertel 9647:
1.6 albertel 9648: sub get_unprocessed_cgi {
1.25 albertel 9649: my ($query,$possible_names)= @_;
1.26 matthew 9650: # $Apache::lonxml::debug=1;
1.356 albertel 9651: foreach my $pair (split(/&/,$query)) {
9652: my ($name, $value) = split(/=/,$pair);
1.369 www 9653: $name = &unescape($name);
1.25 albertel 9654: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9655: $value =~ tr/+/ /;
9656: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9657: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9658: }
1.16 harris41 9659: }
1.6 albertel 9660: }
9661:
1.112 bowersj2 9662: =pod
9663:
1.648 raeburn 9664: =item * &cacheheader()
1.112 bowersj2 9665:
9666: returns cache-controlling header code
9667:
9668: =cut
9669:
1.7 albertel 9670: sub cacheheader {
1.258 albertel 9671: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9672: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9673: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9674: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9675: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9676: return $output;
1.7 albertel 9677: }
9678:
1.112 bowersj2 9679: =pod
9680:
1.648 raeburn 9681: =item * &no_cache($r)
1.112 bowersj2 9682:
9683: specifies header code to not have cache
9684:
9685: =cut
9686:
1.9 albertel 9687: sub no_cache {
1.216 albertel 9688: my ($r) = @_;
9689: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9690: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9691: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9692: $r->no_cache(1);
9693: $r->header_out("Expires" => $date);
9694: $r->header_out("Pragma" => "no-cache");
1.123 www 9695: }
9696:
9697: sub content_type {
1.181 albertel 9698: my ($r,$type,$charset) = @_;
1.299 foxr 9699: if ($r) {
9700: # Note that printout.pl calls this with undef for $r.
9701: &no_cache($r);
9702: }
1.258 albertel 9703: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9704: unless ($charset) {
9705: $charset=&Apache::lonlocal::current_encoding;
9706: }
9707: if ($charset) { $type.='; charset='.$charset; }
9708: if ($r) {
9709: $r->content_type($type);
9710: } else {
9711: print("Content-type: $type\n\n");
9712: }
1.9 albertel 9713: }
1.25 albertel 9714:
1.112 bowersj2 9715: =pod
9716:
1.648 raeburn 9717: =item * &add_to_env($name,$value)
1.112 bowersj2 9718:
1.258 albertel 9719: adds $name to the %env hash with value
1.112 bowersj2 9720: $value, if $name already exists, the entry is converted to an array
9721: reference and $value is added to the array.
9722:
9723: =cut
9724:
1.25 albertel 9725: sub add_to_env {
9726: my ($name,$value)=@_;
1.258 albertel 9727: if (defined($env{$name})) {
9728: if (ref($env{$name})) {
1.25 albertel 9729: #already have multiple values
1.258 albertel 9730: push(@{ $env{$name} },$value);
1.25 albertel 9731: } else {
9732: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9733: my $first=$env{$name};
9734: undef($env{$name});
9735: push(@{ $env{$name} },$first,$value);
1.25 albertel 9736: }
9737: } else {
1.258 albertel 9738: $env{$name}=$value;
1.25 albertel 9739: }
1.31 albertel 9740: }
1.149 albertel 9741:
9742: =pod
9743:
1.648 raeburn 9744: =item * &get_env_multiple($name)
1.149 albertel 9745:
1.258 albertel 9746: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9747: values may be defined and end up as an array ref.
9748:
9749: returns an array of values
9750:
9751: =cut
9752:
9753: sub get_env_multiple {
9754: my ($name) = @_;
9755: my @values;
1.258 albertel 9756: if (defined($env{$name})) {
1.149 albertel 9757: # exists is it an array
1.258 albertel 9758: if (ref($env{$name})) {
9759: @values=@{ $env{$name} };
1.149 albertel 9760: } else {
1.258 albertel 9761: $values[0]=$env{$name};
1.149 albertel 9762: }
9763: }
9764: return(@values);
9765: }
9766:
1.660 raeburn 9767: sub ask_for_embedded_content {
9768: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9769: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 9770: %currsubfile,%unused,$rem);
1.1071 raeburn 9771: my $counter = 0;
9772: my $numnew = 0;
1.987 raeburn 9773: my $numremref = 0;
9774: my $numinvalid = 0;
9775: my $numpathchg = 0;
9776: my $numexisting = 0;
1.1071 raeburn 9777: my $numunused = 0;
9778: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 9779: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9780: my $heading = &mt('Upload embedded files');
9781: my $buttontext = &mt('Upload');
9782:
1.1075.2.11 raeburn 9783: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 9784: if ($actionurl eq '/adm/dependencies') {
9785: $navmap = Apache::lonnavmaps::navmap->new();
9786: }
9787: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9788: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 9789: }
1.1075.2.35 raeburn 9790: if (($actionurl eq '/adm/portfolio') ||
9791: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9792: my $current_path='/';
9793: if ($env{'form.currentpath'}) {
9794: $current_path = $env{'form.currentpath'};
9795: }
9796: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 9797: $udom = $cdom;
9798: $uname = $cnum;
1.984 raeburn 9799: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9800: } else {
9801: $udom = $env{'user.domain'};
9802: $uname = $env{'user.name'};
9803: $url = '/userfiles/portfolio';
9804: }
1.987 raeburn 9805: $toplevel = $url.'/';
1.984 raeburn 9806: $url .= $current_path;
9807: $getpropath = 1;
1.987 raeburn 9808: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9809: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9810: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9811: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9812: $toplevel = $url;
1.984 raeburn 9813: if ($rest ne '') {
1.987 raeburn 9814: $url .= $rest;
9815: }
9816: } elsif ($actionurl eq '/adm/coursedocs') {
9817: if (ref($args) eq 'HASH') {
1.1071 raeburn 9818: $url = $args->{'docs_url'};
9819: $toplevel = $url;
1.1075.2.11 raeburn 9820: if ($args->{'context'} eq 'paste') {
9821: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9822: ($path) =
9823: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9824: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9825: $fileloc =~ s{^/}{};
9826: }
1.1071 raeburn 9827: }
9828: } elsif ($actionurl eq '/adm/dependencies') {
9829: if ($env{'request.course.id'} ne '') {
9830: if (ref($args) eq 'HASH') {
9831: $url = $args->{'docs_url'};
9832: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 9833: $toplevel = $url;
9834: unless ($toplevel =~ m{^/}) {
9835: $toplevel = "/$url";
9836: }
1.1075.2.11 raeburn 9837: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 9838: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9839: $path = $1;
9840: } else {
9841: ($path) =
9842: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9843: }
1.1071 raeburn 9844: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9845: $fileloc =~ s{^/}{};
9846: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9847: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9848: }
1.987 raeburn 9849: }
1.1075.2.35 raeburn 9850: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9851: $udom = $cdom;
9852: $uname = $cnum;
9853: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9854: $toplevel = $url;
9855: $path = $url;
9856: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9857: $fileloc =~ s{^/}{};
9858: }
9859: foreach my $file (keys(%{$allfiles})) {
9860: my $embed_file;
9861: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9862: $embed_file = $1;
9863: } else {
9864: $embed_file = $file;
9865: }
1.1075.2.55 raeburn 9866: my ($absolutepath,$cleaned_file);
9867: if ($embed_file =~ m{^\w+://}) {
9868: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 9869: $newfiles{$cleaned_file} = 1;
9870: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9871: } else {
1.1075.2.55 raeburn 9872: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 9873: if ($embed_file =~ m{^/}) {
9874: $absolutepath = $embed_file;
9875: }
1.1075.2.47 raeburn 9876: if ($cleaned_file =~ m{/}) {
9877: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 9878: $path = &check_for_traversal($path,$url,$toplevel);
9879: my $item = $fname;
9880: if ($path ne '') {
9881: $item = $path.'/'.$fname;
9882: $subdependencies{$path}{$fname} = 1;
9883: } else {
9884: $dependencies{$item} = 1;
9885: }
9886: if ($absolutepath) {
9887: $mapping{$item} = $absolutepath;
9888: } else {
9889: $mapping{$item} = $embed_file;
9890: }
9891: } else {
9892: $dependencies{$embed_file} = 1;
9893: if ($absolutepath) {
1.1075.2.47 raeburn 9894: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 9895: } else {
1.1075.2.47 raeburn 9896: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9897: }
9898: }
1.984 raeburn 9899: }
9900: }
1.1071 raeburn 9901: my $dirptr = 16384;
1.984 raeburn 9902: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9903: $currsubfile{$path} = {};
1.1075.2.35 raeburn 9904: if (($actionurl eq '/adm/portfolio') ||
9905: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9906: my ($sublistref,$listerror) =
9907: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9908: if (ref($sublistref) eq 'ARRAY') {
9909: foreach my $line (@{$sublistref}) {
9910: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9911: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9912: }
1.984 raeburn 9913: }
1.987 raeburn 9914: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9915: if (opendir(my $dir,$url.'/'.$path)) {
9916: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9917: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9918: }
1.1075.2.11 raeburn 9919: } elsif (($actionurl eq '/adm/dependencies') ||
9920: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 9921: ($args->{'context'} eq 'paste')) ||
9922: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9923: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 9924: my $dir;
9925: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9926: $dir = $fileloc;
9927: } else {
9928: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9929: }
1.1071 raeburn 9930: if ($dir ne '') {
9931: my ($sublistref,$listerror) =
9932: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9933: if (ref($sublistref) eq 'ARRAY') {
9934: foreach my $line (@{$sublistref}) {
9935: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9936: undef,$mtime)=split(/\&/,$line,12);
9937: unless (($testdir&$dirptr) ||
9938: ($file_name =~ /^\.\.?$/)) {
9939: $currsubfile{$path}{$file_name} = [$size,$mtime];
9940: }
9941: }
9942: }
9943: }
1.984 raeburn 9944: }
9945: }
9946: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9947: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9948: my $item = $path.'/'.$file;
9949: unless ($mapping{$item} eq $item) {
9950: $pathchanges{$item} = 1;
9951: }
9952: $existing{$item} = 1;
9953: $numexisting ++;
9954: } else {
9955: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9956: }
9957: }
1.1071 raeburn 9958: if ($actionurl eq '/adm/dependencies') {
9959: foreach my $path (keys(%currsubfile)) {
9960: if (ref($currsubfile{$path}) eq 'HASH') {
9961: foreach my $file (keys(%{$currsubfile{$path}})) {
9962: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 9963: next if (($rem ne '') &&
9964: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9965: (ref($navmap) &&
9966: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9967: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9968: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9969: $unused{$path.'/'.$file} = 1;
9970: }
9971: }
9972: }
9973: }
9974: }
1.984 raeburn 9975: }
1.987 raeburn 9976: my %currfile;
1.1075.2.35 raeburn 9977: if (($actionurl eq '/adm/portfolio') ||
9978: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9979: my ($dirlistref,$listerror) =
9980: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9981: if (ref($dirlistref) eq 'ARRAY') {
9982: foreach my $line (@{$dirlistref}) {
9983: my ($file_name,$rest) = split(/\&/,$line,2);
9984: $currfile{$file_name} = 1;
9985: }
1.984 raeburn 9986: }
1.987 raeburn 9987: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9988: if (opendir(my $dir,$url)) {
1.987 raeburn 9989: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 9990: map {$currfile{$_} = 1;} @dir_list;
9991: }
1.1075.2.11 raeburn 9992: } elsif (($actionurl eq '/adm/dependencies') ||
9993: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 9994: ($args->{'context'} eq 'paste')) ||
9995: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9996: if ($env{'request.course.id'} ne '') {
9997: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9998: if ($dir ne '') {
9999: my ($dirlistref,$listerror) =
10000: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10001: if (ref($dirlistref) eq 'ARRAY') {
10002: foreach my $line (@{$dirlistref}) {
10003: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10004: $size,undef,$mtime)=split(/\&/,$line,12);
10005: unless (($testdir&$dirptr) ||
10006: ($file_name =~ /^\.\.?$/)) {
10007: $currfile{$file_name} = [$size,$mtime];
10008: }
10009: }
10010: }
10011: }
10012: }
1.984 raeburn 10013: }
10014: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10015: if (exists($currfile{$file})) {
1.987 raeburn 10016: unless ($mapping{$file} eq $file) {
10017: $pathchanges{$file} = 1;
10018: }
10019: $existing{$file} = 1;
10020: $numexisting ++;
10021: } else {
1.984 raeburn 10022: $newfiles{$file} = 1;
10023: }
10024: }
1.1071 raeburn 10025: foreach my $file (keys(%currfile)) {
10026: unless (($file eq $filename) ||
10027: ($file eq $filename.'.bak') ||
10028: ($dependencies{$file})) {
1.1075.2.11 raeburn 10029: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10030: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10031: next if (($rem ne '') &&
10032: (($env{"httpref.$rem".$file} ne '') ||
10033: (ref($navmap) &&
10034: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10035: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10036: ($navmap->getResourceByUrl($rem.$1)))))));
10037: }
1.1075.2.11 raeburn 10038: }
1.1071 raeburn 10039: $unused{$file} = 1;
10040: }
10041: }
1.1075.2.11 raeburn 10042: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10043: ($args->{'context'} eq 'paste')) {
10044: $counter = scalar(keys(%existing));
10045: $numpathchg = scalar(keys(%pathchanges));
10046: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10047: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10048: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10049: $counter = scalar(keys(%existing));
10050: $numpathchg = scalar(keys(%pathchanges));
10051: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10052: }
1.984 raeburn 10053: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10054: if ($actionurl eq '/adm/dependencies') {
10055: next if ($embed_file =~ m{^\w+://});
10056: }
1.660 raeburn 10057: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10058: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10059: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10060: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10061: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10062: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10063: }
1.1075.2.35 raeburn 10064: $upload_output .= '</td>';
1.1071 raeburn 10065: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10066: $upload_output.='<td align="right">'.
10067: '<span class="LC_info LC_fontsize_medium">'.
10068: &mt("URL points to web address").'</span>';
1.987 raeburn 10069: $numremref++;
1.660 raeburn 10070: } elsif ($args->{'error_on_invalid_names'}
10071: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10072: $upload_output.='<td align="right"><span class="LC_warning">'.
10073: &mt('Invalid characters').'</span>';
1.987 raeburn 10074: $numinvalid++;
1.660 raeburn 10075: } else {
1.1075.2.35 raeburn 10076: $upload_output .= '<td>'.
10077: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10078: $embed_file,\%mapping,
1.1071 raeburn 10079: $allfiles,$codebase,'upload');
10080: $counter ++;
10081: $numnew ++;
1.987 raeburn 10082: }
10083: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10084: }
10085: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10086: if ($actionurl eq '/adm/dependencies') {
10087: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10088: $modify_output .= &start_data_table_row().
10089: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10090: '<img src="'.&icon($embed_file).'" border="0" />'.
10091: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10092: '<td>'.$size.'</td>'.
10093: '<td>'.$mtime.'</td>'.
10094: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10095: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10096: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10097: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10098: &embedded_file_element('upload_embedded',$counter,
10099: $embed_file,\%mapping,
10100: $allfiles,$codebase,'modify').
10101: '</div></td>'.
10102: &end_data_table_row()."\n";
10103: $counter ++;
10104: } else {
10105: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10106: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10107: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10108: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10109: &Apache::loncommon::end_data_table_row()."\n";
10110: }
10111: }
10112: my $delidx = $counter;
10113: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10114: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10115: $delete_output .= &start_data_table_row().
10116: '<td><img src="'.&icon($oldfile).'" />'.
10117: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10118: '<td>'.$size.'</td>'.
10119: '<td>'.$mtime.'</td>'.
10120: '<td><label><input type="checkbox" name="del_upload_dep" '.
10121: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10122: &embedded_file_element('upload_embedded',$delidx,
10123: $oldfile,\%mapping,$allfiles,
10124: $codebase,'delete').'</td>'.
10125: &end_data_table_row()."\n";
10126: $numunused ++;
10127: $delidx ++;
1.987 raeburn 10128: }
10129: if ($upload_output) {
10130: $upload_output = &start_data_table().
10131: $upload_output.
10132: &end_data_table()."\n";
10133: }
1.1071 raeburn 10134: if ($modify_output) {
10135: $modify_output = &start_data_table().
10136: &start_data_table_header_row().
10137: '<th>'.&mt('File').'</th>'.
10138: '<th>'.&mt('Size (KB)').'</th>'.
10139: '<th>'.&mt('Modified').'</th>'.
10140: '<th>'.&mt('Upload replacement?').'</th>'.
10141: &end_data_table_header_row().
10142: $modify_output.
10143: &end_data_table()."\n";
10144: }
10145: if ($delete_output) {
10146: $delete_output = &start_data_table().
10147: &start_data_table_header_row().
10148: '<th>'.&mt('File').'</th>'.
10149: '<th>'.&mt('Size (KB)').'</th>'.
10150: '<th>'.&mt('Modified').'</th>'.
10151: '<th>'.&mt('Delete?').'</th>'.
10152: &end_data_table_header_row().
10153: $delete_output.
10154: &end_data_table()."\n";
10155: }
1.987 raeburn 10156: my $applies = 0;
10157: if ($numremref) {
10158: $applies ++;
10159: }
10160: if ($numinvalid) {
10161: $applies ++;
10162: }
10163: if ($numexisting) {
10164: $applies ++;
10165: }
1.1071 raeburn 10166: if ($counter || $numunused) {
1.987 raeburn 10167: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10168: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10169: $state.'<h3>'.$heading.'</h3>';
10170: if ($actionurl eq '/adm/dependencies') {
10171: if ($numnew) {
10172: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10173: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10174: $upload_output.'<br />'."\n";
10175: }
10176: if ($numexisting) {
10177: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10178: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10179: $modify_output.'<br />'."\n";
10180: $buttontext = &mt('Save changes');
10181: }
10182: if ($numunused) {
10183: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10184: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10185: $delete_output.'<br />'."\n";
10186: $buttontext = &mt('Save changes');
10187: }
10188: } else {
10189: $output .= $upload_output.'<br />'."\n";
10190: }
10191: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10192: $counter.'" />'."\n";
10193: if ($actionurl eq '/adm/dependencies') {
10194: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10195: $numnew.'" />'."\n";
10196: } elsif ($actionurl eq '') {
1.987 raeburn 10197: $output .= '<input type="hidden" name="phase" value="three" />';
10198: }
10199: } elsif ($applies) {
10200: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10201: if ($applies > 1) {
10202: $output .=
1.1075.2.35 raeburn 10203: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10204: if ($numremref) {
10205: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10206: }
10207: if ($numinvalid) {
10208: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10209: }
10210: if ($numexisting) {
10211: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10212: }
10213: $output .= '</ul><br />';
10214: } elsif ($numremref) {
10215: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10216: } elsif ($numinvalid) {
10217: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10218: } elsif ($numexisting) {
10219: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10220: }
10221: $output .= $upload_output.'<br />';
10222: }
10223: my ($pathchange_output,$chgcount);
1.1071 raeburn 10224: $chgcount = $counter;
1.987 raeburn 10225: if (keys(%pathchanges) > 0) {
10226: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10227: if ($counter) {
1.987 raeburn 10228: $output .= &embedded_file_element('pathchange',$chgcount,
10229: $embed_file,\%mapping,
1.1071 raeburn 10230: $allfiles,$codebase,'change');
1.987 raeburn 10231: } else {
10232: $pathchange_output .=
10233: &start_data_table_row().
10234: '<td><input type ="checkbox" name="namechange" value="'.
10235: $chgcount.'" checked="checked" /></td>'.
10236: '<td>'.$mapping{$embed_file}.'</td>'.
10237: '<td>'.$embed_file.
10238: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10239: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10240: '</td>'.&end_data_table_row();
1.660 raeburn 10241: }
1.987 raeburn 10242: $numpathchg ++;
10243: $chgcount ++;
1.660 raeburn 10244: }
10245: }
1.1075.2.35 raeburn 10246: if (($counter) || ($numunused)) {
1.987 raeburn 10247: if ($numpathchg) {
10248: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10249: $numpathchg.'" />'."\n";
10250: }
10251: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10252: ($actionurl eq '/adm/imsimport')) {
10253: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10254: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10255: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10256: } elsif ($actionurl eq '/adm/dependencies') {
10257: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10258: }
1.1075.2.35 raeburn 10259: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10260: } elsif ($numpathchg) {
10261: my %pathchange = ();
10262: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10263: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10264: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10265: }
1.987 raeburn 10266: }
1.1071 raeburn 10267: return ($output,$counter,$numpathchg);
1.987 raeburn 10268: }
10269:
1.1075.2.47 raeburn 10270: =pod
10271:
10272: =item * clean_path($name)
10273:
10274: Performs clean-up of directories, subdirectories and filename in an
10275: embedded object, referenced in an HTML file which is being uploaded
10276: to a course or portfolio, where
10277: "Upload embedded images/multimedia files if HTML file" checkbox was
10278: checked.
10279:
10280: Clean-up is similar to replacements in lonnet::clean_filename()
10281: except each / between sub-directory and next level is preserved.
10282:
10283: =cut
10284:
10285: sub clean_path {
10286: my ($embed_file) = @_;
10287: $embed_file =~s{^/+}{};
10288: my @contents;
10289: if ($embed_file =~ m{/}) {
10290: @contents = split(/\//,$embed_file);
10291: } else {
10292: @contents = ($embed_file);
10293: }
10294: my $lastidx = scalar(@contents)-1;
10295: for (my $i=0; $i<=$lastidx; $i++) {
10296: $contents[$i]=~s{\\}{/}g;
10297: $contents[$i]=~s/\s+/\_/g;
10298: $contents[$i]=~s{[^/\w\.\-]}{}g;
10299: if ($i == $lastidx) {
10300: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10301: }
10302: }
10303: if ($lastidx > 0) {
10304: return join('/',@contents);
10305: } else {
10306: return $contents[0];
10307: }
10308: }
10309:
1.987 raeburn 10310: sub embedded_file_element {
1.1071 raeburn 10311: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10312: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10313: (ref($codebase) eq 'HASH'));
10314: my $output;
1.1071 raeburn 10315: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10316: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10317: }
10318: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10319: &escape($embed_file).'" />';
10320: unless (($context eq 'upload_embedded') &&
10321: ($mapping->{$embed_file} eq $embed_file)) {
10322: $output .='
10323: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10324: }
10325: my $attrib;
10326: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10327: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10328: }
10329: $output .=
10330: "\n\t\t".
10331: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10332: $attrib.'" />';
10333: if (exists($codebase->{$mapping->{$embed_file}})) {
10334: $output .=
10335: "\n\t\t".
10336: '<input name="codebase_'.$num.'" type="hidden" value="'.
10337: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10338: }
1.987 raeburn 10339: return $output;
1.660 raeburn 10340: }
10341:
1.1071 raeburn 10342: sub get_dependency_details {
10343: my ($currfile,$currsubfile,$embed_file) = @_;
10344: my ($size,$mtime,$showsize,$showmtime);
10345: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10346: if ($embed_file =~ m{/}) {
10347: my ($path,$fname) = split(/\//,$embed_file);
10348: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10349: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10350: }
10351: } else {
10352: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10353: ($size,$mtime) = @{$currfile->{$embed_file}};
10354: }
10355: }
10356: $showsize = $size/1024.0;
10357: $showsize = sprintf("%.1f",$showsize);
10358: if ($mtime > 0) {
10359: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10360: }
10361: }
10362: return ($showsize,$showmtime);
10363: }
10364:
10365: sub ask_embedded_js {
10366: return <<"END";
10367: <script type="text/javascript"">
10368: // <![CDATA[
10369: function toggleBrowse(counter) {
10370: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10371: var fileid = document.getElementById('embedded_item_'+counter);
10372: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10373: if (chkboxid.checked == true) {
10374: uploaddivid.style.display='block';
10375: } else {
10376: uploaddivid.style.display='none';
10377: fileid.value = '';
10378: }
10379: }
10380: // ]]>
10381: </script>
10382:
10383: END
10384: }
10385:
1.661 raeburn 10386: sub upload_embedded {
10387: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10388: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10389: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10390: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10391: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10392: my $orig_uploaded_filename =
10393: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10394: foreach my $type ('orig','ref','attrib','codebase') {
10395: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10396: $env{'form.embedded_'.$type.'_'.$i} =
10397: &unescape($env{'form.embedded_'.$type.'_'.$i});
10398: }
10399: }
1.661 raeburn 10400: my ($path,$fname) =
10401: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10402: # no path, whole string is fname
10403: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10404: $fname = &Apache::lonnet::clean_filename($fname);
10405: # See if there is anything left
10406: next if ($fname eq '');
10407:
10408: # Check if file already exists as a file or directory.
10409: my ($state,$msg);
10410: if ($context eq 'portfolio') {
10411: my $port_path = $dirpath;
10412: if ($group ne '') {
10413: $port_path = "groups/$group/$port_path";
10414: }
1.987 raeburn 10415: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10416: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10417: $dir_root,$port_path,$disk_quota,
10418: $current_disk_usage,$uname,$udom);
10419: if ($state eq 'will_exceed_quota'
1.984 raeburn 10420: || $state eq 'file_locked') {
1.661 raeburn 10421: $output .= $msg;
10422: next;
10423: }
10424: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10425: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10426: if ($state eq 'exists') {
10427: $output .= $msg;
10428: next;
10429: }
10430: }
10431: # Check if extension is valid
10432: if (($fname =~ /\.(\w+)$/) &&
10433: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 10434: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10435: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10436: next;
10437: } elsif (($fname =~ /\.(\w+)$/) &&
10438: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10439: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10440: next;
10441: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 10442: $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 10443: next;
10444: }
10445: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 10446: my $subdir = $path;
10447: $subdir =~ s{/+$}{};
1.661 raeburn 10448: if ($context eq 'portfolio') {
1.984 raeburn 10449: my $result;
10450: if ($state eq 'existingfile') {
10451: $result=
10452: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 10453: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10454: } else {
1.984 raeburn 10455: $result=
10456: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10457: $dirpath.
1.1075.2.35 raeburn 10458: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10459: if ($result !~ m|^/uploaded/|) {
10460: $output .= '<span class="LC_error">'
10461: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10462: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10463: .'</span><br />';
10464: next;
10465: } else {
1.987 raeburn 10466: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10467: $path.$fname.'</span>').'<br />';
1.984 raeburn 10468: }
1.661 raeburn 10469: }
1.1075.2.35 raeburn 10470: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
10471: my $extendedsubdir = $dirpath.'/'.$subdir;
10472: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10473: my $result =
1.1075.2.35 raeburn 10474: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10475: if ($result !~ m|^/uploaded/|) {
10476: $output .= '<span class="LC_error">'
10477: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10478: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10479: .'</span><br />';
10480: next;
10481: } else {
10482: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10483: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 10484: if ($context eq 'syllabus') {
10485: &Apache::lonnet::make_public_indefinitely($result);
10486: }
1.987 raeburn 10487: }
1.661 raeburn 10488: } else {
10489: # Save the file
10490: my $target = $env{'form.embedded_item_'.$i};
10491: my $fullpath = $dir_root.$dirpath.'/'.$path;
10492: my $dest = $fullpath.$fname;
10493: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10494: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10495: my $count;
10496: my $filepath = $dir_root;
1.1027 raeburn 10497: foreach my $subdir (@parts) {
10498: $filepath .= "/$subdir";
10499: if (!-e $filepath) {
1.661 raeburn 10500: mkdir($filepath,0770);
10501: }
10502: }
10503: my $fh;
10504: if (!open($fh,'>'.$dest)) {
10505: &Apache::lonnet::logthis('Failed to create '.$dest);
10506: $output .= '<span class="LC_error">'.
1.1071 raeburn 10507: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10508: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10509: '</span><br />';
10510: } else {
10511: if (!print $fh $env{'form.embedded_item_'.$i}) {
10512: &Apache::lonnet::logthis('Failed to write to '.$dest);
10513: $output .= '<span class="LC_error">'.
1.1071 raeburn 10514: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10515: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10516: '</span><br />';
10517: } else {
1.987 raeburn 10518: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10519: $url.'</span>').'<br />';
10520: unless ($context eq 'testbank') {
10521: $footer .= &mt('View embedded file: [_1]',
10522: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10523: }
10524: }
10525: close($fh);
10526: }
10527: }
10528: if ($env{'form.embedded_ref_'.$i}) {
10529: $pathchange{$i} = 1;
10530: }
10531: }
10532: if ($output) {
10533: $output = '<p>'.$output.'</p>';
10534: }
10535: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10536: $returnflag = 'ok';
1.1071 raeburn 10537: my $numpathchgs = scalar(keys(%pathchange));
10538: if ($numpathchgs > 0) {
1.987 raeburn 10539: if ($context eq 'portfolio') {
10540: $output .= '<p>'.&mt('or').'</p>';
10541: } elsif ($context eq 'testbank') {
1.1071 raeburn 10542: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10543: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10544: $returnflag = 'modify_orightml';
10545: }
10546: }
1.1071 raeburn 10547: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10548: }
10549:
10550: sub modify_html_form {
10551: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10552: my $end = 0;
10553: my $modifyform;
10554: if ($context eq 'upload_embedded') {
10555: return unless (ref($pathchange) eq 'HASH');
10556: if ($env{'form.number_embedded_items'}) {
10557: $end += $env{'form.number_embedded_items'};
10558: }
10559: if ($env{'form.number_pathchange_items'}) {
10560: $end += $env{'form.number_pathchange_items'};
10561: }
10562: if ($end) {
10563: for (my $i=0; $i<$end; $i++) {
10564: if ($i < $env{'form.number_embedded_items'}) {
10565: next unless($pathchange->{$i});
10566: }
10567: $modifyform .=
10568: &start_data_table_row().
10569: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10570: 'checked="checked" /></td>'.
10571: '<td>'.$env{'form.embedded_ref_'.$i}.
10572: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10573: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10574: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10575: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10576: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10577: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10578: '<td>'.$env{'form.embedded_orig_'.$i}.
10579: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10580: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10581: &end_data_table_row();
1.1071 raeburn 10582: }
1.987 raeburn 10583: }
10584: } else {
10585: $modifyform = $pathchgtable;
10586: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10587: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10588: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10589: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10590: }
10591: }
10592: if ($modifyform) {
1.1071 raeburn 10593: if ($actionurl eq '/adm/dependencies') {
10594: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10595: }
1.987 raeburn 10596: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10597: '<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".
10598: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10599: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10600: '</ol></p>'."\n".'<p>'.
10601: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10602: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10603: &start_data_table()."\n".
10604: &start_data_table_header_row().
10605: '<th>'.&mt('Change?').'</th>'.
10606: '<th>'.&mt('Current reference').'</th>'.
10607: '<th>'.&mt('Required reference').'</th>'.
10608: &end_data_table_header_row()."\n".
10609: $modifyform.
10610: &end_data_table().'<br />'."\n".$hiddenstate.
10611: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10612: '</form>'."\n";
10613: }
10614: return;
10615: }
10616:
10617: sub modify_html_refs {
1.1075.2.35 raeburn 10618: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10619: my $container;
10620: if ($context eq 'portfolio') {
10621: $container = $env{'form.container'};
10622: } elsif ($context eq 'coursedoc') {
10623: $container = $env{'form.primaryurl'};
1.1071 raeburn 10624: } elsif ($context eq 'manage_dependencies') {
10625: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10626: $container = "/$container";
1.1075.2.35 raeburn 10627: } elsif ($context eq 'syllabus') {
10628: $container = $url;
1.987 raeburn 10629: } else {
1.1027 raeburn 10630: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10631: }
10632: my (%allfiles,%codebase,$output,$content);
10633: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 10634: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10635: if (wantarray) {
10636: return ('',0,0);
10637: } else {
10638: return;
10639: }
10640: }
10641: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10642: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10643: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10644: if (wantarray) {
10645: return ('',0,0);
10646: } else {
10647: return;
10648: }
10649: }
1.987 raeburn 10650: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10651: if ($content eq '-1') {
10652: if (wantarray) {
10653: return ('',0,0);
10654: } else {
10655: return;
10656: }
10657: }
1.987 raeburn 10658: } else {
1.1071 raeburn 10659: unless ($container =~ /^\Q$dir_root\E/) {
10660: if (wantarray) {
10661: return ('',0,0);
10662: } else {
10663: return;
10664: }
10665: }
1.987 raeburn 10666: if (open(my $fh,"<$container")) {
10667: $content = join('', <$fh>);
10668: close($fh);
10669: } else {
1.1071 raeburn 10670: if (wantarray) {
10671: return ('',0,0);
10672: } else {
10673: return;
10674: }
1.987 raeburn 10675: }
10676: }
10677: my ($count,$codebasecount) = (0,0);
10678: my $mm = new File::MMagic;
10679: my $mime_type = $mm->checktype_contents($content);
10680: if ($mime_type eq 'text/html') {
10681: my $parse_result =
10682: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10683: \%codebase,\$content);
10684: if ($parse_result eq 'ok') {
10685: foreach my $i (@changes) {
10686: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10687: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10688: if ($allfiles{$ref}) {
10689: my $newname = $orig;
10690: my ($attrib_regexp,$codebase);
1.1006 raeburn 10691: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10692: if ($attrib_regexp =~ /:/) {
10693: $attrib_regexp =~ s/\:/|/g;
10694: }
10695: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10696: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10697: $count += $numchg;
1.1075.2.35 raeburn 10698: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 10699: delete($allfiles{$ref});
1.987 raeburn 10700: }
10701: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10702: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10703: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10704: $codebasecount ++;
10705: }
10706: }
10707: }
1.1075.2.35 raeburn 10708: my $skiprewrites;
1.987 raeburn 10709: if ($count || $codebasecount) {
10710: my $saveresult;
1.1071 raeburn 10711: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10712: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10713: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10714: if ($url eq $container) {
10715: my ($fname) = ($container =~ m{/([^/]+)$});
10716: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10717: $count,'<span class="LC_filename">'.
1.1071 raeburn 10718: $fname.'</span>').'</p>';
1.987 raeburn 10719: } else {
10720: $output = '<p class="LC_error">'.
10721: &mt('Error: update failed for: [_1].',
10722: '<span class="LC_filename">'.
10723: $container.'</span>').'</p>';
10724: }
1.1075.2.35 raeburn 10725: if ($context eq 'syllabus') {
10726: unless ($saveresult eq 'ok') {
10727: $skiprewrites = 1;
10728: }
10729: }
1.987 raeburn 10730: } else {
10731: if (open(my $fh,">$container")) {
10732: print $fh $content;
10733: close($fh);
10734: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10735: $count,'<span class="LC_filename">'.
10736: $container.'</span>').'</p>';
1.661 raeburn 10737: } else {
1.987 raeburn 10738: $output = '<p class="LC_error">'.
10739: &mt('Error: could not update [_1].',
10740: '<span class="LC_filename">'.
10741: $container.'</span>').'</p>';
1.661 raeburn 10742: }
10743: }
10744: }
1.1075.2.35 raeburn 10745: if (($context eq 'syllabus') && (!$skiprewrites)) {
10746: my ($actionurl,$state);
10747: $actionurl = "/public/$udom/$uname/syllabus";
10748: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10749: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10750: \%codebase,
10751: {'context' => 'rewrites',
10752: 'ignore_remote_references' => 1,});
10753: if (ref($mapping) eq 'HASH') {
10754: my $rewrites = 0;
10755: foreach my $key (keys(%{$mapping})) {
10756: next if ($key =~ m{^https?://});
10757: my $ref = $mapping->{$key};
10758: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10759: my $attrib;
10760: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10761: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10762: }
10763: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10764: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10765: $rewrites += $numchg;
10766: }
10767: }
10768: if ($rewrites) {
10769: my $saveresult;
10770: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10771: if ($url eq $container) {
10772: my ($fname) = ($container =~ m{/([^/]+)$});
10773: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10774: $count,'<span class="LC_filename">'.
10775: $fname.'</span>').'</p>';
10776: } else {
10777: $output .= '<p class="LC_error">'.
10778: &mt('Error: could not update links in [_1].',
10779: '<span class="LC_filename">'.
10780: $container.'</span>').'</p>';
10781:
10782: }
10783: }
10784: }
10785: }
1.987 raeburn 10786: } else {
10787: &logthis('Failed to parse '.$container.
10788: ' to modify references: '.$parse_result);
1.661 raeburn 10789: }
10790: }
1.1071 raeburn 10791: if (wantarray) {
10792: return ($output,$count,$codebasecount);
10793: } else {
10794: return $output;
10795: }
1.661 raeburn 10796: }
10797:
10798: sub check_for_existing {
10799: my ($path,$fname,$element) = @_;
10800: my ($state,$msg);
10801: if (-d $path.'/'.$fname) {
10802: $state = 'exists';
10803: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10804: } elsif (-e $path.'/'.$fname) {
10805: $state = 'exists';
10806: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10807: }
10808: if ($state eq 'exists') {
10809: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10810: }
10811: return ($state,$msg);
10812: }
10813:
10814: sub check_for_upload {
10815: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10816: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10817: my $filesize = length($env{'form.'.$element});
10818: if (!$filesize) {
10819: my $msg = '<span class="LC_error">'.
10820: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10821: '<span class="LC_filename">'.$fname.'</span>',
10822: $filesize).'<br />'.
1.1007 raeburn 10823: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10824: '</span>';
10825: return ('zero_bytes',$msg);
10826: }
10827: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10828: my $getpropath = 1;
1.1021 raeburn 10829: my ($dirlistref,$listerror) =
10830: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10831: my $found_file = 0;
10832: my $locked_file = 0;
1.991 raeburn 10833: my @lockers;
10834: my $navmap;
10835: if ($env{'request.course.id'}) {
10836: $navmap = Apache::lonnavmaps::navmap->new();
10837: }
1.1021 raeburn 10838: if (ref($dirlistref) eq 'ARRAY') {
10839: foreach my $line (@{$dirlistref}) {
10840: my ($file_name,$rest)=split(/\&/,$line,2);
10841: if ($file_name eq $fname){
10842: $file_name = $path.$file_name;
10843: if ($group ne '') {
10844: $file_name = $group.$file_name;
10845: }
10846: $found_file = 1;
10847: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10848: foreach my $lock (@lockers) {
10849: if (ref($lock) eq 'ARRAY') {
10850: my ($symb,$crsid) = @{$lock};
10851: if ($crsid eq $env{'request.course.id'}) {
10852: if (ref($navmap)) {
10853: my $res = $navmap->getBySymb($symb);
10854: foreach my $part (@{$res->parts()}) {
10855: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10856: unless (($slot_status == $res->RESERVED) ||
10857: ($slot_status == $res->RESERVED_LOCATION)) {
10858: $locked_file = 1;
10859: }
1.991 raeburn 10860: }
1.1021 raeburn 10861: } else {
10862: $locked_file = 1;
1.991 raeburn 10863: }
10864: } else {
10865: $locked_file = 1;
10866: }
10867: }
1.1021 raeburn 10868: }
10869: } else {
10870: my @info = split(/\&/,$rest);
10871: my $currsize = $info[6]/1000;
10872: if ($currsize < $filesize) {
10873: my $extra = $filesize - $currsize;
10874: if (($current_disk_usage + $extra) > $disk_quota) {
10875: my $msg = '<span class="LC_error">'.
10876: &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.',
10877: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10878: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10879: $disk_quota,$current_disk_usage);
10880: return ('will_exceed_quota',$msg);
10881: }
1.984 raeburn 10882: }
10883: }
1.661 raeburn 10884: }
10885: }
10886: }
10887: if (($current_disk_usage + $filesize) > $disk_quota){
10888: my $msg = '<span class="LC_error">'.
10889: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10890: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10891: return ('will_exceed_quota',$msg);
10892: } elsif ($found_file) {
10893: if ($locked_file) {
10894: my $msg = '<span class="LC_error">';
10895: $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>');
10896: $msg .= '</span><br />';
10897: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10898: return ('file_locked',$msg);
10899: } else {
10900: my $msg = '<span class="LC_error">';
1.984 raeburn 10901: $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 10902: $msg .= '</span>';
1.984 raeburn 10903: return ('existingfile',$msg);
1.661 raeburn 10904: }
10905: }
10906: }
10907:
1.987 raeburn 10908: sub check_for_traversal {
10909: my ($path,$url,$toplevel) = @_;
10910: my @parts=split(/\//,$path);
10911: my $cleanpath;
10912: my $fullpath = $url;
10913: for (my $i=0;$i<@parts;$i++) {
10914: next if ($parts[$i] eq '.');
10915: if ($parts[$i] eq '..') {
10916: $fullpath =~ s{([^/]+/)$}{};
10917: } else {
10918: $fullpath .= $parts[$i].'/';
10919: }
10920: }
10921: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10922: $cleanpath = $1;
10923: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10924: my $curr_toprel = $1;
10925: my @parts = split(/\//,$curr_toprel);
10926: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10927: my @urlparts = split(/\//,$url_toprel);
10928: my $doubledots;
10929: my $startdiff = -1;
10930: for (my $i=0; $i<@urlparts; $i++) {
10931: if ($startdiff == -1) {
10932: unless ($urlparts[$i] eq $parts[$i]) {
10933: $startdiff = $i;
10934: $doubledots .= '../';
10935: }
10936: } else {
10937: $doubledots .= '../';
10938: }
10939: }
10940: if ($startdiff > -1) {
10941: $cleanpath = $doubledots;
10942: for (my $i=$startdiff; $i<@parts; $i++) {
10943: $cleanpath .= $parts[$i].'/';
10944: }
10945: }
10946: }
10947: $cleanpath =~ s{(/)$}{};
10948: return $cleanpath;
10949: }
1.31 albertel 10950:
1.1053 raeburn 10951: sub is_archive_file {
10952: my ($mimetype) = @_;
10953: if (($mimetype eq 'application/octet-stream') ||
10954: ($mimetype eq 'application/x-stuffit') ||
10955: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10956: return 1;
10957: }
10958: return;
10959: }
10960:
10961: sub decompress_form {
1.1065 raeburn 10962: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10963: my %lt = &Apache::lonlocal::texthash (
10964: this => 'This file is an archive file.',
1.1067 raeburn 10965: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10966: itsc => 'Its contents are as follows:',
1.1053 raeburn 10967: youm => 'You may wish to extract its contents.',
10968: extr => 'Extract contents',
1.1067 raeburn 10969: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10970: proa => 'Process automatically?',
1.1053 raeburn 10971: yes => 'Yes',
10972: no => 'No',
1.1067 raeburn 10973: fold => 'Title for folder containing movie',
10974: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10975: );
1.1065 raeburn 10976: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10977: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10978: my $info = &list_archive_contents($fileloc,\@paths);
10979: if (@paths) {
10980: foreach my $path (@paths) {
10981: $path =~ s{^/}{};
1.1067 raeburn 10982: if ($path =~ m{^([^/]+)/$}) {
10983: $topdir = $1;
10984: }
1.1065 raeburn 10985: if ($path =~ m{^([^/]+)/}) {
10986: $toplevel{$1} = $path;
10987: } else {
10988: $toplevel{$path} = $path;
10989: }
10990: }
10991: }
1.1067 raeburn 10992: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
10993: my @camtasia = ("$topdir/","$topdir/index.html",
10994: "$topdir/media/",
10995: "$topdir/media/$topdir.mp4",
10996: "$topdir/media/FirstFrame.png",
10997: "$topdir/media/player.swf",
10998: "$topdir/media/swfobject.js",
10999: "$topdir/media/expressInstall.swf");
11000: my @diffs = &compare_arrays(\@paths,\@camtasia);
11001: if (@diffs == 0) {
11002: $is_camtasia = 1;
11003: }
11004: }
11005: my $output;
11006: if ($is_camtasia) {
11007: $output = <<"ENDCAM";
11008: <script type="text/javascript" language="Javascript">
11009: // <![CDATA[
11010:
11011: function camtasiaToggle() {
11012: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11013: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
11014: if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
11015:
11016: document.getElementById('camtasia_titles').style.display='block';
11017: } else {
11018: document.getElementById('camtasia_titles').style.display='none';
11019: }
11020: }
11021: }
11022: return;
11023: }
11024:
11025: // ]]>
11026: </script>
11027: <p>$lt{'camt'}</p>
11028: ENDCAM
1.1065 raeburn 11029: } else {
1.1067 raeburn 11030: $output = '<p>'.$lt{'this'};
11031: if ($info eq '') {
11032: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11033: } else {
11034: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11035: '<div><pre>'.$info.'</pre></div>';
11036: }
1.1065 raeburn 11037: }
1.1067 raeburn 11038: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11039: my $duplicates;
11040: my $num = 0;
11041: if (ref($dirlist) eq 'ARRAY') {
11042: foreach my $item (@{$dirlist}) {
11043: if (ref($item) eq 'ARRAY') {
11044: if (exists($toplevel{$item->[0]})) {
11045: $duplicates .=
11046: &start_data_table_row().
11047: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11048: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11049: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11050: 'value="1" />'.&mt('Yes').'</label>'.
11051: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11052: '<td>'.$item->[0].'</td>';
11053: if ($item->[2]) {
11054: $duplicates .= '<td>'.&mt('Directory').'</td>';
11055: } else {
11056: $duplicates .= '<td>'.&mt('File').'</td>';
11057: }
11058: $duplicates .= '<td>'.$item->[3].'</td>'.
11059: '<td>'.
11060: &Apache::lonlocal::locallocaltime($item->[4]).
11061: '</td>'.
11062: &end_data_table_row();
11063: $num ++;
11064: }
11065: }
11066: }
11067: }
11068: my $itemcount;
11069: if (@paths > 0) {
11070: $itemcount = scalar(@paths);
11071: } else {
11072: $itemcount = 1;
11073: }
1.1067 raeburn 11074: if ($is_camtasia) {
11075: $output .= $lt{'auto'}.'<br />'.
11076: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
11077: '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
11078: $lt{'yes'}.'</label> <label>'.
11079: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11080: $lt{'no'}.'</label></span><br />'.
11081: '<div id="camtasia_titles" style="display:block">'.
11082: &Apache::lonhtmlcommon::start_pick_box().
11083: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11084: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11085: &Apache::lonhtmlcommon::row_closure().
11086: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11087: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11088: &Apache::lonhtmlcommon::row_closure(1).
11089: &Apache::lonhtmlcommon::end_pick_box().
11090: '</div>';
11091: }
1.1065 raeburn 11092: $output .=
11093: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11094: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11095: "\n";
1.1065 raeburn 11096: if ($duplicates ne '') {
11097: $output .= '<p><span class="LC_warning">'.
11098: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11099: &start_data_table().
11100: &start_data_table_header_row().
11101: '<th>'.&mt('Overwrite?').'</th>'.
11102: '<th>'.&mt('Name').'</th>'.
11103: '<th>'.&mt('Type').'</th>'.
11104: '<th>'.&mt('Size').'</th>'.
11105: '<th>'.&mt('Last modified').'</th>'.
11106: &end_data_table_header_row().
11107: $duplicates.
11108: &end_data_table().
11109: '</p>';
11110: }
1.1067 raeburn 11111: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11112: if (ref($hiddenelements) eq 'HASH') {
11113: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11114: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11115: }
11116: }
11117: $output .= <<"END";
1.1067 raeburn 11118: <br />
1.1053 raeburn 11119: <input type="submit" name="decompress" value="$lt{'extr'}" />
11120: </form>
11121: $noextract
11122: END
11123: return $output;
11124: }
11125:
1.1065 raeburn 11126: sub decompression_utility {
11127: my ($program) = @_;
11128: my @utilities = ('tar','gunzip','bunzip2','unzip');
11129: my $location;
11130: if (grep(/^\Q$program\E$/,@utilities)) {
11131: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11132: '/usr/sbin/') {
11133: if (-x $dir.$program) {
11134: $location = $dir.$program;
11135: last;
11136: }
11137: }
11138: }
11139: return $location;
11140: }
11141:
11142: sub list_archive_contents {
11143: my ($file,$pathsref) = @_;
11144: my (@cmd,$output);
11145: my $needsregexp;
11146: if ($file =~ /\.zip$/) {
11147: @cmd = (&decompression_utility('unzip'),"-l");
11148: $needsregexp = 1;
11149: } elsif (($file =~ m/\.tar\.gz$/) ||
11150: ($file =~ /\.tgz$/)) {
11151: @cmd = (&decompression_utility('tar'),"-ztf");
11152: } elsif ($file =~ /\.tar\.bz2$/) {
11153: @cmd = (&decompression_utility('tar'),"-jtf");
11154: } elsif ($file =~ m|\.tar$|) {
11155: @cmd = (&decompression_utility('tar'),"-tf");
11156: }
11157: if (@cmd) {
11158: undef($!);
11159: undef($@);
11160: if (open(my $fh,"-|", @cmd, $file)) {
11161: while (my $line = <$fh>) {
11162: $output .= $line;
11163: chomp($line);
11164: my $item;
11165: if ($needsregexp) {
11166: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11167: } else {
11168: $item = $line;
11169: }
11170: if ($item ne '') {
11171: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11172: push(@{$pathsref},$item);
11173: }
11174: }
11175: }
11176: close($fh);
11177: }
11178: }
11179: return $output;
11180: }
11181:
1.1053 raeburn 11182: sub decompress_uploaded_file {
11183: my ($file,$dir) = @_;
11184: &Apache::lonnet::appenv({'cgi.file' => $file});
11185: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11186: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11187: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11188: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11189: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11190: my $decompressed = $env{'cgi.decompressed'};
11191: &Apache::lonnet::delenv('cgi.file');
11192: &Apache::lonnet::delenv('cgi.dir');
11193: &Apache::lonnet::delenv('cgi.decompressed');
11194: return ($decompressed,$result);
11195: }
11196:
1.1055 raeburn 11197: sub process_decompression {
11198: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11199: my ($dir,$error,$warning,$output);
11200: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.1075.2.34 raeburn 11201: $error = &mt('Filename not a supported archive file type.').
11202: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11203: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11204: } else {
11205: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11206: if ($docuhome eq 'no_host') {
11207: $error = &mt('Could not determine home server for course.');
11208: } else {
11209: my @ids=&Apache::lonnet::current_machine_ids();
11210: my $currdir = "$dir_root/$destination";
11211: if (grep(/^\Q$docuhome\E$/,@ids)) {
11212: $dir = &LONCAPA::propath($docudom,$docuname).
11213: "$dir_root/$destination";
11214: } else {
11215: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11216: "$dir_root/$docudom/$docuname/$destination";
11217: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11218: $error = &mt('Archive file not found.');
11219: }
11220: }
1.1065 raeburn 11221: my (@to_overwrite,@to_skip);
11222: if ($env{'form.archive_overwrite_total'} > 0) {
11223: my $total = $env{'form.archive_overwrite_total'};
11224: for (my $i=0; $i<$total; $i++) {
11225: if ($env{'form.archive_overwrite_'.$i} == 1) {
11226: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11227: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11228: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11229: }
11230: }
11231: }
11232: my $numskip = scalar(@to_skip);
11233: if (($numskip > 0) &&
11234: ($numskip == $env{'form.archive_itemcount'})) {
11235: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11236: } elsif ($dir eq '') {
1.1055 raeburn 11237: $error = &mt('Directory containing archive file unavailable.');
11238: } elsif (!$error) {
1.1065 raeburn 11239: my ($decompressed,$display);
11240: if ($numskip > 0) {
11241: my $tempdir = time.'_'.$$.int(rand(10000));
11242: mkdir("$dir/$tempdir",0755);
11243: system("mv $dir/$file $dir/$tempdir/$file");
11244: ($decompressed,$display) =
11245: &decompress_uploaded_file($file,"$dir/$tempdir");
11246: foreach my $item (@to_skip) {
11247: if (($item ne '') && ($item !~ /\.\./)) {
11248: if (-f "$dir/$tempdir/$item") {
11249: unlink("$dir/$tempdir/$item");
11250: } elsif (-d "$dir/$tempdir/$item") {
11251: system("rm -rf $dir/$tempdir/$item");
11252: }
11253: }
11254: }
11255: system("mv $dir/$tempdir/* $dir");
11256: rmdir("$dir/$tempdir");
11257: } else {
11258: ($decompressed,$display) =
11259: &decompress_uploaded_file($file,$dir);
11260: }
1.1055 raeburn 11261: if ($decompressed eq 'ok') {
1.1065 raeburn 11262: $output = '<p class="LC_info">'.
11263: &mt('Files extracted successfully from archive.').
11264: '</p>'."\n";
1.1055 raeburn 11265: my ($warning,$result,@contents);
11266: my ($newdirlistref,$newlisterror) =
11267: &Apache::lonnet::dirlist($currdir,$docudom,
11268: $docuname,1);
11269: my (%is_dir,%changes,@newitems);
11270: my $dirptr = 16384;
1.1065 raeburn 11271: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11272: foreach my $dir_line (@{$newdirlistref}) {
11273: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11274: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11275: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11276: push(@newitems,$item);
11277: if ($dirptr&$testdir) {
11278: $is_dir{$item} = 1;
11279: }
11280: $changes{$item} = 1;
11281: }
11282: }
11283: }
11284: if (keys(%changes) > 0) {
11285: foreach my $item (sort(@newitems)) {
11286: if ($changes{$item}) {
11287: push(@contents,$item);
11288: }
11289: }
11290: }
11291: if (@contents > 0) {
1.1067 raeburn 11292: my $wantform;
11293: unless ($env{'form.autoextract_camtasia'}) {
11294: $wantform = 1;
11295: }
1.1056 raeburn 11296: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11297: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11298: $currdir,\%is_dir,
11299: \%children,\%parent,
1.1056 raeburn 11300: \@contents,\%dirorder,
11301: \%titles,$wantform);
1.1055 raeburn 11302: if ($datatable ne '') {
11303: $output .= &archive_options_form('decompressed',$datatable,
11304: $count,$hiddenelem);
1.1065 raeburn 11305: my $startcount = 6;
1.1055 raeburn 11306: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11307: \%titles,\%children);
1.1055 raeburn 11308: }
1.1067 raeburn 11309: if ($env{'form.autoextract_camtasia'}) {
11310: my %displayed;
11311: my $total = 1;
11312: $env{'form.archive_directory'} = [];
11313: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11314: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11315: $path =~ s{/$}{};
11316: my $item;
11317: if ($path ne '') {
11318: $item = "$path/$titles{$i}";
11319: } else {
11320: $item = $titles{$i};
11321: }
11322: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11323: if ($item eq $contents[0]) {
11324: push(@{$env{'form.archive_directory'}},$i);
11325: $env{'form.archive_'.$i} = 'display';
11326: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11327: $displayed{'folder'} = $i;
11328: } elsif ($item eq "$contents[0]/index.html") {
11329: $env{'form.archive_'.$i} = 'display';
11330: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11331: $displayed{'web'} = $i;
11332: } else {
11333: if ($item eq "$contents[0]/media") {
11334: push(@{$env{'form.archive_directory'}},$i);
11335: }
11336: $env{'form.archive_'.$i} = 'dependency';
11337: }
11338: $total ++;
11339: }
11340: for (my $i=1; $i<$total; $i++) {
11341: next if ($i == $displayed{'web'});
11342: next if ($i == $displayed{'folder'});
11343: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11344: }
11345: $env{'form.phase'} = 'decompress_cleanup';
11346: $env{'form.archivedelete'} = 1;
11347: $env{'form.archive_count'} = $total-1;
11348: $output .=
11349: &process_extracted_files('coursedocs',$docudom,
11350: $docuname,$destination,
11351: $dir_root,$hiddenelem);
11352: }
1.1055 raeburn 11353: } else {
11354: $warning = &mt('No new items extracted from archive file.');
11355: }
11356: } else {
11357: $output = $display;
11358: $error = &mt('An error occurred during extraction from the archive file.');
11359: }
11360: }
11361: }
11362: }
11363: if ($error) {
11364: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11365: $error.'</p>'."\n";
11366: }
11367: if ($warning) {
11368: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11369: }
11370: return $output;
11371: }
11372:
11373: sub get_extracted {
1.1056 raeburn 11374: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11375: $titles,$wantform) = @_;
1.1055 raeburn 11376: my $count = 0;
11377: my $depth = 0;
11378: my $datatable;
1.1056 raeburn 11379: my @hierarchy;
1.1055 raeburn 11380: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11381: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11382: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11383: foreach my $item (@{$contents}) {
11384: $count ++;
1.1056 raeburn 11385: @{$dirorder->{$count}} = @hierarchy;
11386: $titles->{$count} = $item;
1.1055 raeburn 11387: &archive_hierarchy($depth,$count,$parent,$children);
11388: if ($wantform) {
11389: $datatable .= &archive_row($is_dir->{$item},$item,
11390: $currdir,$depth,$count);
11391: }
11392: if ($is_dir->{$item}) {
11393: $depth ++;
1.1056 raeburn 11394: push(@hierarchy,$count);
11395: $parent->{$depth} = $count;
1.1055 raeburn 11396: $datatable .=
11397: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11398: \$depth,\$count,\@hierarchy,$dirorder,
11399: $children,$parent,$titles,$wantform);
1.1055 raeburn 11400: $depth --;
1.1056 raeburn 11401: pop(@hierarchy);
1.1055 raeburn 11402: }
11403: }
11404: return ($count,$datatable);
11405: }
11406:
11407: sub recurse_extracted_archive {
1.1056 raeburn 11408: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11409: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11410: my $result='';
1.1056 raeburn 11411: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11412: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11413: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11414: return $result;
11415: }
11416: my $dirptr = 16384;
11417: my ($newdirlistref,$newlisterror) =
11418: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11419: if (ref($newdirlistref) eq 'ARRAY') {
11420: foreach my $dir_line (@{$newdirlistref}) {
11421: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11422: unless ($item =~ /^\.+$/) {
11423: $$count ++;
1.1056 raeburn 11424: @{$dirorder->{$$count}} = @{$hierarchy};
11425: $titles->{$$count} = $item;
1.1055 raeburn 11426: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11427:
1.1055 raeburn 11428: my $is_dir;
11429: if ($dirptr&$testdir) {
11430: $is_dir = 1;
11431: }
11432: if ($wantform) {
11433: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11434: }
11435: if ($is_dir) {
11436: $$depth ++;
1.1056 raeburn 11437: push(@{$hierarchy},$$count);
11438: $parent->{$$depth} = $$count;
1.1055 raeburn 11439: $result .=
11440: &recurse_extracted_archive("$currdir/$item",$docudom,
11441: $docuname,$depth,$count,
1.1056 raeburn 11442: $hierarchy,$dirorder,$children,
11443: $parent,$titles,$wantform);
1.1055 raeburn 11444: $$depth --;
1.1056 raeburn 11445: pop(@{$hierarchy});
1.1055 raeburn 11446: }
11447: }
11448: }
11449: }
11450: return $result;
11451: }
11452:
11453: sub archive_hierarchy {
11454: my ($depth,$count,$parent,$children) =@_;
11455: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11456: if (exists($parent->{$depth})) {
11457: $children->{$parent->{$depth}} .= $count.':';
11458: }
11459: }
11460: return;
11461: }
11462:
11463: sub archive_row {
11464: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11465: my ($name) = ($item =~ m{([^/]+)$});
11466: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11467: 'display' => 'Add as file',
1.1055 raeburn 11468: 'dependency' => 'Include as dependency',
11469: 'discard' => 'Discard',
11470: );
11471: if ($is_dir) {
1.1059 raeburn 11472: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11473: }
1.1056 raeburn 11474: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11475: my $offset = 0;
1.1055 raeburn 11476: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11477: $offset ++;
1.1065 raeburn 11478: if ($action ne 'display') {
11479: $offset ++;
11480: }
1.1055 raeburn 11481: $output .= '<td><span class="LC_nobreak">'.
11482: '<label><input type="radio" name="archive_'.$count.
11483: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11484: my $text = $choices{$action};
11485: if ($is_dir) {
11486: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11487: if ($action eq 'display') {
1.1059 raeburn 11488: $text = &mt('Add as folder');
1.1055 raeburn 11489: }
1.1056 raeburn 11490: } else {
11491: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11492:
11493: }
11494: $output .= ' /> '.$choices{$action}.'</label></span>';
11495: if ($action eq 'dependency') {
11496: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11497: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11498: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11499: '<option value=""></option>'."\n".
11500: '</select>'."\n".
11501: '</div>';
1.1059 raeburn 11502: } elsif ($action eq 'display') {
11503: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11504: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11505: '</div>';
1.1055 raeburn 11506: }
1.1056 raeburn 11507: $output .= '</td>';
1.1055 raeburn 11508: }
11509: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11510: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11511: for (my $i=0; $i<$depth; $i++) {
11512: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11513: }
11514: if ($is_dir) {
11515: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11516: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11517: } else {
11518: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11519: }
11520: $output .= ' '.$name.'</td>'."\n".
11521: &end_data_table_row();
11522: return $output;
11523: }
11524:
11525: sub archive_options_form {
1.1065 raeburn 11526: my ($form,$display,$count,$hiddenelem) = @_;
11527: my %lt = &Apache::lonlocal::texthash(
11528: perm => 'Permanently remove archive file?',
11529: hows => 'How should each extracted item be incorporated in the course?',
11530: cont => 'Content actions for all',
11531: addf => 'Add as folder/file',
11532: incd => 'Include as dependency for a displayed file',
11533: disc => 'Discard',
11534: no => 'No',
11535: yes => 'Yes',
11536: save => 'Save',
11537: );
11538: my $output = <<"END";
11539: <form name="$form" method="post" action="">
11540: <p><span class="LC_nobreak">$lt{'perm'}
11541: <label>
11542: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11543: </label>
11544:
11545: <label>
11546: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11547: </span>
11548: </p>
11549: <input type="hidden" name="phase" value="decompress_cleanup" />
11550: <br />$lt{'hows'}
11551: <div class="LC_columnSection">
11552: <fieldset>
11553: <legend>$lt{'cont'}</legend>
11554: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11555: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11556: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11557: </fieldset>
11558: </div>
11559: END
11560: return $output.
1.1055 raeburn 11561: &start_data_table()."\n".
1.1065 raeburn 11562: $display."\n".
1.1055 raeburn 11563: &end_data_table()."\n".
11564: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11565: $hiddenelem.
1.1065 raeburn 11566: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11567: '</form>';
11568: }
11569:
11570: sub archive_javascript {
1.1056 raeburn 11571: my ($startcount,$numitems,$titles,$children) = @_;
11572: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11573: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11574: my $scripttag = <<START;
11575: <script type="text/javascript">
11576: // <![CDATA[
11577:
11578: function checkAll(form,prefix) {
11579: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11580: for (var i=0; i < form.elements.length; i++) {
11581: var id = form.elements[i].id;
11582: if ((id != '') && (id != undefined)) {
11583: if (idstr.test(id)) {
11584: if (form.elements[i].type == 'radio') {
11585: form.elements[i].checked = true;
1.1056 raeburn 11586: var nostart = i-$startcount;
1.1059 raeburn 11587: var offset = nostart%7;
11588: var count = (nostart-offset)/7;
1.1056 raeburn 11589: dependencyCheck(form,count,offset);
1.1055 raeburn 11590: }
11591: }
11592: }
11593: }
11594: }
11595:
11596: function propagateCheck(form,count) {
11597: if (count > 0) {
1.1059 raeburn 11598: var startelement = $startcount + ((count-1) * 7);
11599: for (var j=1; j<6; j++) {
11600: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11601: var item = startelement + j;
11602: if (form.elements[item].type == 'radio') {
11603: if (form.elements[item].checked) {
11604: containerCheck(form,count,j);
11605: break;
11606: }
1.1055 raeburn 11607: }
11608: }
11609: }
11610: }
11611: }
11612:
11613: numitems = $numitems
1.1056 raeburn 11614: var titles = new Array(numitems);
11615: var parents = new Array(numitems);
1.1055 raeburn 11616: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11617: parents[i] = new Array;
1.1055 raeburn 11618: }
1.1059 raeburn 11619: var maintitle = '$maintitle';
1.1055 raeburn 11620:
11621: START
11622:
1.1056 raeburn 11623: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11624: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11625: for (my $i=0; $i<@contents; $i ++) {
11626: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11627: }
11628: }
11629:
1.1056 raeburn 11630: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11631: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11632: }
11633:
1.1055 raeburn 11634: $scripttag .= <<END;
11635:
11636: function containerCheck(form,count,offset) {
11637: if (count > 0) {
1.1056 raeburn 11638: dependencyCheck(form,count,offset);
1.1059 raeburn 11639: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11640: form.elements[item].checked = true;
11641: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11642: if (parents[count].length > 0) {
11643: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11644: containerCheck(form,parents[count][j],offset);
11645: }
11646: }
11647: }
11648: }
11649: }
11650:
11651: function dependencyCheck(form,count,offset) {
11652: if (count > 0) {
1.1059 raeburn 11653: var chosen = (offset+$startcount)+7*(count-1);
11654: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11655: var currtype = form.elements[depitem].type;
11656: if (form.elements[chosen].value == 'dependency') {
11657: document.getElementById('arc_depon_'+count).style.display='block';
11658: form.elements[depitem].options.length = 0;
11659: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 11660: for (var i=1; i<=numitems; i++) {
11661: if (i == count) {
11662: continue;
11663: }
1.1059 raeburn 11664: var startelement = $startcount + (i-1) * 7;
11665: for (var j=1; j<6; j++) {
11666: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11667: var item = startelement + j;
11668: if (form.elements[item].type == 'radio') {
11669: if (form.elements[item].checked) {
11670: if (form.elements[item].value == 'display') {
11671: var n = form.elements[depitem].options.length;
11672: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11673: }
11674: }
11675: }
11676: }
11677: }
11678: }
11679: } else {
11680: document.getElementById('arc_depon_'+count).style.display='none';
11681: form.elements[depitem].options.length = 0;
11682: form.elements[depitem].options[0] = new Option('Select','',true,true);
11683: }
1.1059 raeburn 11684: titleCheck(form,count,offset);
1.1056 raeburn 11685: }
11686: }
11687:
11688: function propagateSelect(form,count,offset) {
11689: if (count > 0) {
1.1065 raeburn 11690: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11691: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11692: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11693: if (parents[count].length > 0) {
11694: for (var j=0; j<parents[count].length; j++) {
11695: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11696: }
11697: }
11698: }
11699: }
11700: }
1.1056 raeburn 11701:
11702: function containerSelect(form,count,offset,picked) {
11703: if (count > 0) {
1.1065 raeburn 11704: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11705: if (form.elements[item].type == 'radio') {
11706: if (form.elements[item].value == 'dependency') {
11707: if (form.elements[item+1].type == 'select-one') {
11708: for (var i=0; i<form.elements[item+1].options.length; i++) {
11709: if (form.elements[item+1].options[i].value == picked) {
11710: form.elements[item+1].selectedIndex = i;
11711: break;
11712: }
11713: }
11714: }
11715: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11716: if (parents[count].length > 0) {
11717: for (var j=0; j<parents[count].length; j++) {
11718: containerSelect(form,parents[count][j],offset,picked);
11719: }
11720: }
11721: }
11722: }
11723: }
11724: }
11725: }
11726:
1.1059 raeburn 11727: function titleCheck(form,count,offset) {
11728: if (count > 0) {
11729: var chosen = (offset+$startcount)+7*(count-1);
11730: var depitem = $startcount + ((count-1) * 7) + 2;
11731: var currtype = form.elements[depitem].type;
11732: if (form.elements[chosen].value == 'display') {
11733: document.getElementById('arc_title_'+count).style.display='block';
11734: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11735: document.getElementById('archive_title_'+count).value=maintitle;
11736: }
11737: } else {
11738: document.getElementById('arc_title_'+count).style.display='none';
11739: if (currtype == 'text') {
11740: document.getElementById('archive_title_'+count).value='';
11741: }
11742: }
11743: }
11744: return;
11745: }
11746:
1.1055 raeburn 11747: // ]]>
11748: </script>
11749: END
11750: return $scripttag;
11751: }
11752:
11753: sub process_extracted_files {
1.1067 raeburn 11754: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11755: my $numitems = $env{'form.archive_count'};
11756: return unless ($numitems);
11757: my @ids=&Apache::lonnet::current_machine_ids();
11758: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11759: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11760: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11761: if (grep(/^\Q$docuhome\E$/,@ids)) {
11762: $prefix = &LONCAPA::propath($docudom,$docuname);
11763: $pathtocheck = "$dir_root/$destination";
11764: $dir = $dir_root;
11765: $ishome = 1;
11766: } else {
11767: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11768: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11769: $dir = "$dir_root/$docudom/$docuname";
11770: }
11771: my $currdir = "$dir_root/$destination";
11772: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11773: if ($env{'form.folderpath'}) {
11774: my @items = split('&',$env{'form.folderpath'});
11775: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 11776: if ($env{'form.folderpath'} =~ /\:1$/) {
11777: $containers{'0'}='page';
11778: } else {
11779: $containers{'0'}='sequence';
11780: }
1.1055 raeburn 11781: }
11782: my @archdirs = &get_env_multiple('form.archive_directory');
11783: if ($numitems) {
11784: for (my $i=1; $i<=$numitems; $i++) {
11785: my $path = $env{'form.archive_content_'.$i};
11786: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11787: my $item = $1;
11788: $toplevelitems{$item} = $i;
11789: if (grep(/^\Q$i\E$/,@archdirs)) {
11790: $is_dir{$item} = 1;
11791: }
11792: }
11793: }
11794: }
1.1067 raeburn 11795: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11796: if (keys(%toplevelitems) > 0) {
11797: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11798: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11799: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11800: }
1.1066 raeburn 11801: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11802: if ($numitems) {
11803: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 11804: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11805: my $path = $env{'form.archive_content_'.$i};
11806: if ($path =~ /^\Q$pathtocheck\E/) {
11807: if ($env{'form.archive_'.$i} eq 'discard') {
11808: if ($prefix ne '' && $path ne '') {
11809: if (-e $prefix.$path) {
1.1066 raeburn 11810: if ((@archdirs > 0) &&
11811: (grep(/^\Q$i\E$/,@archdirs))) {
11812: $todeletedir{$prefix.$path} = 1;
11813: } else {
11814: $todelete{$prefix.$path} = 1;
11815: }
1.1055 raeburn 11816: }
11817: }
11818: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11819: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11820: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11821: $docstitle = $env{'form.archive_title_'.$i};
11822: if ($docstitle eq '') {
11823: $docstitle = $title;
11824: }
1.1055 raeburn 11825: $outer = 0;
1.1056 raeburn 11826: if (ref($dirorder{$i}) eq 'ARRAY') {
11827: if (@{$dirorder{$i}} > 0) {
11828: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11829: if ($env{'form.archive_'.$item} eq 'display') {
11830: $outer = $item;
11831: last;
11832: }
11833: }
11834: }
11835: }
11836: my ($errtext,$fatal) =
11837: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11838: '/'.$folders{$outer}.'.'.
11839: $containers{$outer});
11840: next if ($fatal);
11841: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11842: if ($context eq 'coursedocs') {
1.1056 raeburn 11843: $mapinner{$i} = time;
1.1055 raeburn 11844: $folders{$i} = 'default_'.$mapinner{$i};
11845: $containers{$i} = 'sequence';
11846: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11847: $folders{$i}.'.'.$containers{$i};
11848: my $newidx = &LONCAPA::map::getresidx();
11849: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11850: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11851: push(@LONCAPA::map::order,$newidx);
11852: my ($outtext,$errtext) =
11853: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11854: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11855: '.'.$containers{$outer},1,1);
1.1056 raeburn 11856: $newseqid{$i} = $newidx;
1.1067 raeburn 11857: unless ($errtext) {
11858: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11859: }
1.1055 raeburn 11860: }
11861: } else {
11862: if ($context eq 'coursedocs') {
11863: my $newidx=&LONCAPA::map::getresidx();
11864: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11865: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11866: $title;
11867: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11868: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11869: }
11870: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11871: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11872: }
11873: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11874: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11875: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11876: unless ($ishome) {
11877: my $fetch = "$newdest{$i}/$title";
11878: $fetch =~ s/^\Q$prefix$dir\E//;
11879: $prompttofetch{$fetch} = 1;
11880: }
1.1055 raeburn 11881: }
11882: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11883: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11884: push(@LONCAPA::map::order, $newidx);
11885: my ($outtext,$errtext)=
11886: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11887: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11888: '.'.$containers{$outer},1,1);
1.1067 raeburn 11889: unless ($errtext) {
11890: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11891: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11892: }
11893: }
1.1055 raeburn 11894: }
11895: }
1.1075.2.11 raeburn 11896: }
11897: } else {
11898: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11899: }
11900: }
11901: for (my $i=1; $i<=$numitems; $i++) {
11902: next unless ($env{'form.archive_'.$i} eq 'dependency');
11903: my $path = $env{'form.archive_content_'.$i};
11904: if ($path =~ /^\Q$pathtocheck\E/) {
11905: my ($title) = ($path =~ m{/([^/]+)$});
11906: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11907: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11908: if (ref($dirorder{$i}) eq 'ARRAY') {
11909: my ($itemidx,$fullpath,$relpath);
11910: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11911: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11912: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 11913: if ($dirorder{$i}->[$j] eq $container) {
11914: $itemidx = $j;
1.1056 raeburn 11915: }
11916: }
1.1075.2.11 raeburn 11917: }
11918: if ($itemidx eq '') {
11919: $itemidx = 0;
11920: }
11921: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11922: if ($mapinner{$referrer{$i}}) {
11923: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11924: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11925: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11926: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11927: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11928: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11929: if (!-e $fullpath) {
11930: mkdir($fullpath,0755);
1.1056 raeburn 11931: }
11932: }
1.1075.2.11 raeburn 11933: } else {
11934: last;
1.1056 raeburn 11935: }
1.1075.2.11 raeburn 11936: }
11937: }
11938: } elsif ($newdest{$referrer{$i}}) {
11939: $fullpath = $newdest{$referrer{$i}};
11940: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11941: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11942: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11943: last;
11944: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11945: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11946: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11947: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11948: if (!-e $fullpath) {
11949: mkdir($fullpath,0755);
1.1056 raeburn 11950: }
11951: }
1.1075.2.11 raeburn 11952: } else {
11953: last;
1.1056 raeburn 11954: }
1.1075.2.11 raeburn 11955: }
11956: }
11957: if ($fullpath ne '') {
11958: if (-e "$prefix$path") {
11959: system("mv $prefix$path $fullpath/$title");
11960: }
11961: if (-e "$fullpath/$title") {
11962: my $showpath;
11963: if ($relpath ne '') {
11964: $showpath = "$relpath/$title";
11965: } else {
11966: $showpath = "/$title";
1.1056 raeburn 11967: }
1.1075.2.11 raeburn 11968: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
11969: }
11970: unless ($ishome) {
11971: my $fetch = "$fullpath/$title";
11972: $fetch =~ s/^\Q$prefix$dir\E//;
11973: $prompttofetch{$fetch} = 1;
1.1055 raeburn 11974: }
11975: }
11976: }
1.1075.2.11 raeburn 11977: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
11978: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
11979: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 11980: }
11981: } else {
1.1075.2.11 raeburn 11982: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 11983: }
11984: }
11985: if (keys(%todelete)) {
11986: foreach my $key (keys(%todelete)) {
11987: unlink($key);
1.1066 raeburn 11988: }
11989: }
11990: if (keys(%todeletedir)) {
11991: foreach my $key (keys(%todeletedir)) {
11992: rmdir($key);
11993: }
11994: }
11995: foreach my $dir (sort(keys(%is_dir))) {
11996: if (($pathtocheck ne '') && ($dir ne '')) {
11997: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 11998: }
11999: }
1.1067 raeburn 12000: if ($result ne '') {
12001: $output .= '<ul>'."\n".
12002: $result."\n".
12003: '</ul>';
12004: }
12005: unless ($ishome) {
12006: my $replicationfail;
12007: foreach my $item (keys(%prompttofetch)) {
12008: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12009: unless ($fetchresult eq 'ok') {
12010: $replicationfail .= '<li>'.$item.'</li>'."\n";
12011: }
12012: }
12013: if ($replicationfail) {
12014: $output .= '<p class="LC_error">'.
12015: &mt('Course home server failed to retrieve:').'<ul>'.
12016: $replicationfail.
12017: '</ul></p>';
12018: }
12019: }
1.1055 raeburn 12020: } else {
12021: $warning = &mt('No items found in archive.');
12022: }
12023: if ($error) {
12024: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12025: $error.'</p>'."\n";
12026: }
12027: if ($warning) {
12028: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12029: }
12030: return $output;
12031: }
12032:
1.1066 raeburn 12033: sub cleanup_empty_dirs {
12034: my ($path) = @_;
12035: if (($path ne '') && (-d $path)) {
12036: if (opendir(my $dirh,$path)) {
12037: my @dircontents = grep(!/^\./,readdir($dirh));
12038: my $numitems = 0;
12039: foreach my $item (@dircontents) {
12040: if (-d "$path/$item") {
1.1075.2.28 raeburn 12041: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12042: if (-e "$path/$item") {
12043: $numitems ++;
12044: }
12045: } else {
12046: $numitems ++;
12047: }
12048: }
12049: if ($numitems == 0) {
12050: rmdir($path);
12051: }
12052: closedir($dirh);
12053: }
12054: }
12055: return;
12056: }
12057:
1.41 ng 12058: =pod
1.45 matthew 12059:
1.1075.2.56! raeburn 12060: =item * &get_folder_hierarchy()
1.1068 raeburn 12061:
12062: Provides hierarchy of names of folders/sub-folders containing the current
12063: item,
12064:
12065: Inputs: 3
12066: - $navmap - navmaps object
12067:
12068: - $map - url for map (either the trigger itself, or map containing
12069: the resource, which is the trigger).
12070:
12071: - $showitem - 1 => show title for map itself; 0 => do not show.
12072:
12073: Outputs: 1 @pathitems - array of folder/subfolder names.
12074:
12075: =cut
12076:
12077: sub get_folder_hierarchy {
12078: my ($navmap,$map,$showitem) = @_;
12079: my @pathitems;
12080: if (ref($navmap)) {
12081: my $mapres = $navmap->getResourceByUrl($map);
12082: if (ref($mapres)) {
12083: my $pcslist = $mapres->map_hierarchy();
12084: if ($pcslist ne '') {
12085: my @pcs = split(/,/,$pcslist);
12086: foreach my $pc (@pcs) {
12087: if ($pc == 1) {
1.1075.2.38 raeburn 12088: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12089: } else {
12090: my $res = $navmap->getByMapPc($pc);
12091: if (ref($res)) {
12092: my $title = $res->compTitle();
12093: $title =~ s/\W+/_/g;
12094: if ($title ne '') {
12095: push(@pathitems,$title);
12096: }
12097: }
12098: }
12099: }
12100: }
1.1071 raeburn 12101: if ($showitem) {
12102: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12103: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12104: } else {
12105: my $maptitle = $mapres->compTitle();
12106: $maptitle =~ s/\W+/_/g;
12107: if ($maptitle ne '') {
12108: push(@pathitems,$maptitle);
12109: }
1.1068 raeburn 12110: }
12111: }
12112: }
12113: }
12114: return @pathitems;
12115: }
12116:
12117: =pod
12118:
1.1015 raeburn 12119: =item * &get_turnedin_filepath()
12120:
12121: Determines path in a user's portfolio file for storage of files uploaded
12122: to a specific essayresponse or dropbox item.
12123:
12124: Inputs: 3 required + 1 optional.
12125: $symb is symb for resource, $uname and $udom are for current user (required).
12126: $caller is optional (can be "submission", if routine is called when storing
12127: an upoaded file when "Submit Answer" button was pressed).
12128:
12129: Returns array containing $path and $multiresp.
12130: $path is path in portfolio. $multiresp is 1 if this resource contains more
12131: than one file upload item. Callers of routine should append partid as a
12132: subdirectory to $path in cases where $multiresp is 1.
12133:
12134: Called by: homework/essayresponse.pm and homework/structuretags.pm
12135:
12136: =cut
12137:
12138: sub get_turnedin_filepath {
12139: my ($symb,$uname,$udom,$caller) = @_;
12140: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12141: my $turnindir;
12142: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12143: $turnindir = $userhash{'turnindir'};
12144: my ($path,$multiresp);
12145: if ($turnindir eq '') {
12146: if ($caller eq 'submission') {
12147: $turnindir = &mt('turned in');
12148: $turnindir =~ s/\W+/_/g;
12149: my %newhash = (
12150: 'turnindir' => $turnindir,
12151: );
12152: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12153: }
12154: }
12155: if ($turnindir ne '') {
12156: $path = '/'.$turnindir.'/';
12157: my ($multipart,$turnin,@pathitems);
12158: my $navmap = Apache::lonnavmaps::navmap->new();
12159: if (defined($navmap)) {
12160: my $mapres = $navmap->getResourceByUrl($map);
12161: if (ref($mapres)) {
12162: my $pcslist = $mapres->map_hierarchy();
12163: if ($pcslist ne '') {
12164: foreach my $pc (split(/,/,$pcslist)) {
12165: my $res = $navmap->getByMapPc($pc);
12166: if (ref($res)) {
12167: my $title = $res->compTitle();
12168: $title =~ s/\W+/_/g;
12169: if ($title ne '') {
1.1075.2.48 raeburn 12170: if (($pc > 1) && (length($title) > 12)) {
12171: $title = substr($title,0,12);
12172: }
1.1015 raeburn 12173: push(@pathitems,$title);
12174: }
12175: }
12176: }
12177: }
12178: my $maptitle = $mapres->compTitle();
12179: $maptitle =~ s/\W+/_/g;
12180: if ($maptitle ne '') {
1.1075.2.48 raeburn 12181: if (length($maptitle) > 12) {
12182: $maptitle = substr($maptitle,0,12);
12183: }
1.1015 raeburn 12184: push(@pathitems,$maptitle);
12185: }
12186: unless ($env{'request.state'} eq 'construct') {
12187: my $res = $navmap->getBySymb($symb);
12188: if (ref($res)) {
12189: my $partlist = $res->parts();
12190: my $totaluploads = 0;
12191: if (ref($partlist) eq 'ARRAY') {
12192: foreach my $part (@{$partlist}) {
12193: my @types = $res->responseType($part);
12194: my @ids = $res->responseIds($part);
12195: for (my $i=0; $i < scalar(@ids); $i++) {
12196: if ($types[$i] eq 'essay') {
12197: my $partid = $part.'_'.$ids[$i];
12198: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12199: $totaluploads ++;
12200: }
12201: }
12202: }
12203: }
12204: if ($totaluploads > 1) {
12205: $multiresp = 1;
12206: }
12207: }
12208: }
12209: }
12210: } else {
12211: return;
12212: }
12213: } else {
12214: return;
12215: }
12216: my $restitle=&Apache::lonnet::gettitle($symb);
12217: $restitle =~ s/\W+/_/g;
12218: if ($restitle eq '') {
12219: $restitle = ($resurl =~ m{/[^/]+$});
12220: if ($restitle eq '') {
12221: $restitle = time;
12222: }
12223: }
1.1075.2.48 raeburn 12224: if (length($restitle) > 12) {
12225: $restitle = substr($restitle,0,12);
12226: }
1.1015 raeburn 12227: push(@pathitems,$restitle);
12228: $path .= join('/',@pathitems);
12229: }
12230: return ($path,$multiresp);
12231: }
12232:
12233: =pod
12234:
1.464 albertel 12235: =back
1.41 ng 12236:
1.112 bowersj2 12237: =head1 CSV Upload/Handling functions
1.38 albertel 12238:
1.41 ng 12239: =over 4
12240:
1.648 raeburn 12241: =item * &upfile_store($r)
1.41 ng 12242:
12243: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12244: needs $env{'form.upfile'}
1.41 ng 12245: returns $datatoken to be put into hidden field
12246:
12247: =cut
1.31 albertel 12248:
12249: sub upfile_store {
12250: my $r=shift;
1.258 albertel 12251: $env{'form.upfile'}=~s/\r/\n/gs;
12252: $env{'form.upfile'}=~s/\f/\n/gs;
12253: $env{'form.upfile'}=~s/\n+/\n/gs;
12254: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12255:
1.258 albertel 12256: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12257: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12258: {
1.158 raeburn 12259: my $datafile = $r->dir_config('lonDaemons').
12260: '/tmp/'.$datatoken.'.tmp';
12261: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12262: print $fh $env{'form.upfile'};
1.158 raeburn 12263: close($fh);
12264: }
1.31 albertel 12265: }
12266: return $datatoken;
12267: }
12268:
1.56 matthew 12269: =pod
12270:
1.648 raeburn 12271: =item * &load_tmp_file($r)
1.41 ng 12272:
12273: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12274: needs $env{'form.datatoken'},
12275: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12276:
12277: =cut
1.31 albertel 12278:
12279: sub load_tmp_file {
12280: my $r=shift;
12281: my @studentdata=();
12282: {
1.158 raeburn 12283: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12284: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12285: if ( open(my $fh,"<$studentfile") ) {
12286: @studentdata=<$fh>;
12287: close($fh);
12288: }
1.31 albertel 12289: }
1.258 albertel 12290: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12291: }
12292:
1.56 matthew 12293: =pod
12294:
1.648 raeburn 12295: =item * &upfile_record_sep()
1.41 ng 12296:
12297: Separate uploaded file into records
12298: returns array of records,
1.258 albertel 12299: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12300:
12301: =cut
1.31 albertel 12302:
12303: sub upfile_record_sep {
1.258 albertel 12304: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12305: } else {
1.248 albertel 12306: my @records;
1.258 albertel 12307: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12308: if ($line=~/^\s*$/) { next; }
12309: push(@records,$line);
12310: }
12311: return @records;
1.31 albertel 12312: }
12313: }
12314:
1.56 matthew 12315: =pod
12316:
1.648 raeburn 12317: =item * &record_sep($record)
1.41 ng 12318:
1.258 albertel 12319: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12320:
12321: =cut
12322:
1.263 www 12323: sub takeleft {
12324: my $index=shift;
12325: return substr('0000'.$index,-4,4);
12326: }
12327:
1.31 albertel 12328: sub record_sep {
12329: my $record=shift;
12330: my %components=();
1.258 albertel 12331: if ($env{'form.upfiletype'} eq 'xml') {
12332: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12333: my $i=0;
1.356 albertel 12334: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12335: $field=~s/^(\"|\')//;
12336: $field=~s/(\"|\')$//;
1.263 www 12337: $components{&takeleft($i)}=$field;
1.31 albertel 12338: $i++;
12339: }
1.258 albertel 12340: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12341: my $i=0;
1.356 albertel 12342: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12343: $field=~s/^(\"|\')//;
12344: $field=~s/(\"|\')$//;
1.263 www 12345: $components{&takeleft($i)}=$field;
1.31 albertel 12346: $i++;
12347: }
12348: } else {
1.561 www 12349: my $separator=',';
1.480 banghart 12350: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12351: $separator=';';
1.480 banghart 12352: }
1.31 albertel 12353: my $i=0;
1.561 www 12354: # the character we are looking for to indicate the end of a quote or a record
12355: my $looking_for=$separator;
12356: # do not add the characters to the fields
12357: my $ignore=0;
12358: # we just encountered a separator (or the beginning of the record)
12359: my $just_found_separator=1;
12360: # store the field we are working on here
12361: my $field='';
12362: # work our way through all characters in record
12363: foreach my $character ($record=~/(.)/g) {
12364: if ($character eq $looking_for) {
12365: if ($character ne $separator) {
12366: # Found the end of a quote, again looking for separator
12367: $looking_for=$separator;
12368: $ignore=1;
12369: } else {
12370: # Found a separator, store away what we got
12371: $components{&takeleft($i)}=$field;
12372: $i++;
12373: $just_found_separator=1;
12374: $ignore=0;
12375: $field='';
12376: }
12377: next;
12378: }
12379: # single or double quotation marks after a separator indicate beginning of a quote
12380: # we are now looking for the end of the quote and need to ignore separators
12381: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12382: $looking_for=$character;
12383: next;
12384: }
12385: # ignore would be true after we reached the end of a quote
12386: if ($ignore) { next; }
12387: if (($just_found_separator) && ($character=~/\s/)) { next; }
12388: $field.=$character;
12389: $just_found_separator=0;
1.31 albertel 12390: }
1.561 www 12391: # catch the very last entry, since we never encountered the separator
12392: $components{&takeleft($i)}=$field;
1.31 albertel 12393: }
12394: return %components;
12395: }
12396:
1.144 matthew 12397: ######################################################
12398: ######################################################
12399:
1.56 matthew 12400: =pod
12401:
1.648 raeburn 12402: =item * &upfile_select_html()
1.41 ng 12403:
1.144 matthew 12404: Return HTML code to select a file from the users machine and specify
12405: the file type.
1.41 ng 12406:
12407: =cut
12408:
1.144 matthew 12409: ######################################################
12410: ######################################################
1.31 albertel 12411: sub upfile_select_html {
1.144 matthew 12412: my %Types = (
12413: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12414: semisv => &mt('Semicolon separated values'),
1.144 matthew 12415: space => &mt('Space separated'),
12416: tab => &mt('Tabulator separated'),
12417: # xml => &mt('HTML/XML'),
12418: );
12419: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12420: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12421: foreach my $type (sort(keys(%Types))) {
12422: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12423: }
12424: $Str .= "</select>\n";
12425: return $Str;
1.31 albertel 12426: }
12427:
1.301 albertel 12428: sub get_samples {
12429: my ($records,$toget) = @_;
12430: my @samples=({});
12431: my $got=0;
12432: foreach my $rec (@$records) {
12433: my %temp = &record_sep($rec);
12434: if (! grep(/\S/, values(%temp))) { next; }
12435: if (%temp) {
12436: $samples[$got]=\%temp;
12437: $got++;
12438: if ($got == $toget) { last; }
12439: }
12440: }
12441: return \@samples;
12442: }
12443:
1.144 matthew 12444: ######################################################
12445: ######################################################
12446:
1.56 matthew 12447: =pod
12448:
1.648 raeburn 12449: =item * &csv_print_samples($r,$records)
1.41 ng 12450:
12451: Prints a table of sample values from each column uploaded $r is an
12452: Apache Request ref, $records is an arrayref from
12453: &Apache::loncommon::upfile_record_sep
12454:
12455: =cut
12456:
1.144 matthew 12457: ######################################################
12458: ######################################################
1.31 albertel 12459: sub csv_print_samples {
12460: my ($r,$records) = @_;
1.662 bisitz 12461: my $samples = &get_samples($records,5);
1.301 albertel 12462:
1.594 raeburn 12463: $r->print(&mt('Samples').'<br />'.&start_data_table().
12464: &start_data_table_header_row());
1.356 albertel 12465: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12466: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12467: $r->print(&end_data_table_header_row());
1.301 albertel 12468: foreach my $hash (@$samples) {
1.594 raeburn 12469: $r->print(&start_data_table_row());
1.356 albertel 12470: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12471: $r->print('<td>');
1.356 albertel 12472: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12473: $r->print('</td>');
12474: }
1.594 raeburn 12475: $r->print(&end_data_table_row());
1.31 albertel 12476: }
1.594 raeburn 12477: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12478: }
12479:
1.144 matthew 12480: ######################################################
12481: ######################################################
12482:
1.56 matthew 12483: =pod
12484:
1.648 raeburn 12485: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12486:
12487: Prints a table to create associations between values and table columns.
1.144 matthew 12488:
1.41 ng 12489: $r is an Apache Request ref,
12490: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12491: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12492:
12493: =cut
12494:
1.144 matthew 12495: ######################################################
12496: ######################################################
1.31 albertel 12497: sub csv_print_select_table {
12498: my ($r,$records,$d) = @_;
1.301 albertel 12499: my $i=0;
12500: my $samples = &get_samples($records,1);
1.144 matthew 12501: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12502: &start_data_table().&start_data_table_header_row().
1.144 matthew 12503: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12504: '<th>'.&mt('Column').'</th>'.
12505: &end_data_table_header_row()."\n");
1.356 albertel 12506: foreach my $array_ref (@$d) {
12507: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12508: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12509:
1.875 bisitz 12510: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12511: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12512: $r->print('<option value="none"></option>');
1.356 albertel 12513: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12514: $r->print('<option value="'.$sample.'"'.
12515: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12516: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12517: }
1.594 raeburn 12518: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12519: $i++;
12520: }
1.594 raeburn 12521: $r->print(&end_data_table());
1.31 albertel 12522: $i--;
12523: return $i;
12524: }
1.56 matthew 12525:
1.144 matthew 12526: ######################################################
12527: ######################################################
12528:
1.56 matthew 12529: =pod
1.31 albertel 12530:
1.648 raeburn 12531: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12532:
12533: Prints a table of sample values from the upload and can make associate samples to internal names.
12534:
12535: $r is an Apache Request ref,
12536: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12537: $d is an array of 2 element arrays (internal name, displayed name)
12538:
12539: =cut
12540:
1.144 matthew 12541: ######################################################
12542: ######################################################
1.31 albertel 12543: sub csv_samples_select_table {
12544: my ($r,$records,$d) = @_;
12545: my $i=0;
1.144 matthew 12546: #
1.662 bisitz 12547: my $max_samples = 5;
12548: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12549: $r->print(&start_data_table().
12550: &start_data_table_header_row().'<th>'.
12551: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12552: &end_data_table_header_row());
1.301 albertel 12553:
12554: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12555: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12556: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12557: foreach my $option (@$d) {
12558: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12559: $r->print('<option value="'.$value.'"'.
1.253 albertel 12560: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12561: $display.'</option>');
1.31 albertel 12562: }
12563: $r->print('</select></td><td>');
1.662 bisitz 12564: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12565: if (defined($samples->[$line]{$key})) {
12566: $r->print($samples->[$line]{$key}."<br />\n");
12567: }
12568: }
1.594 raeburn 12569: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12570: $i++;
12571: }
1.594 raeburn 12572: $r->print(&end_data_table());
1.31 albertel 12573: $i--;
12574: return($i);
1.115 matthew 12575: }
12576:
1.144 matthew 12577: ######################################################
12578: ######################################################
12579:
1.115 matthew 12580: =pod
12581:
1.648 raeburn 12582: =item * &clean_excel_name($name)
1.115 matthew 12583:
12584: Returns a replacement for $name which does not contain any illegal characters.
12585:
12586: =cut
12587:
1.144 matthew 12588: ######################################################
12589: ######################################################
1.115 matthew 12590: sub clean_excel_name {
12591: my ($name) = @_;
12592: $name =~ s/[:\*\?\/\\]//g;
12593: if (length($name) > 31) {
12594: $name = substr($name,0,31);
12595: }
12596: return $name;
1.25 albertel 12597: }
1.84 albertel 12598:
1.85 albertel 12599: =pod
12600:
1.648 raeburn 12601: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12602:
12603: Returns either 1 or undef
12604:
12605: 1 if the part is to be hidden, undef if it is to be shown
12606:
12607: Arguments are:
12608:
12609: $id the id of the part to be checked
12610: $symb, optional the symb of the resource to check
12611: $udom, optional the domain of the user to check for
12612: $uname, optional the username of the user to check for
12613:
12614: =cut
1.84 albertel 12615:
12616: sub check_if_partid_hidden {
12617: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12618: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12619: $symb,$udom,$uname);
1.141 albertel 12620: my $truth=1;
12621: #if the string starts with !, then the list is the list to show not hide
12622: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12623: my @hiddenlist=split(/,/,$hiddenparts);
12624: foreach my $checkid (@hiddenlist) {
1.141 albertel 12625: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12626: }
1.141 albertel 12627: return !$truth;
1.84 albertel 12628: }
1.127 matthew 12629:
1.138 matthew 12630:
12631: ############################################################
12632: ############################################################
12633:
12634: =pod
12635:
1.157 matthew 12636: =back
12637:
1.138 matthew 12638: =head1 cgi-bin script and graphing routines
12639:
1.157 matthew 12640: =over 4
12641:
1.648 raeburn 12642: =item * &get_cgi_id()
1.138 matthew 12643:
12644: Inputs: none
12645:
12646: Returns an id which can be used to pass environment variables
12647: to various cgi-bin scripts. These environment variables will
12648: be removed from the users environment after a given time by
12649: the routine &Apache::lonnet::transfer_profile_to_env.
12650:
12651: =cut
12652:
12653: ############################################################
12654: ############################################################
1.152 albertel 12655: my $uniq=0;
1.136 matthew 12656: sub get_cgi_id {
1.154 albertel 12657: $uniq=($uniq+1)%100000;
1.280 albertel 12658: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12659: }
12660:
1.127 matthew 12661: ############################################################
12662: ############################################################
12663:
12664: =pod
12665:
1.648 raeburn 12666: =item * &DrawBarGraph()
1.127 matthew 12667:
1.138 matthew 12668: Facilitates the plotting of data in a (stacked) bar graph.
12669: Puts plot definition data into the users environment in order for
12670: graph.png to plot it. Returns an <img> tag for the plot.
12671: The bars on the plot are labeled '1','2',...,'n'.
12672:
12673: Inputs:
12674:
12675: =over 4
12676:
12677: =item $Title: string, the title of the plot
12678:
12679: =item $xlabel: string, text describing the X-axis of the plot
12680:
12681: =item $ylabel: string, text describing the Y-axis of the plot
12682:
12683: =item $Max: scalar, the maximum Y value to use in the plot
12684: If $Max is < any data point, the graph will not be rendered.
12685:
1.140 matthew 12686: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12687: they are plotted. If undefined, default values will be used.
12688:
1.178 matthew 12689: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12690:
1.138 matthew 12691: =item @Values: An array of array references. Each array reference holds data
12692: to be plotted in a stacked bar chart.
12693:
1.239 matthew 12694: =item If the final element of @Values is a hash reference the key/value
12695: pairs will be added to the graph definition.
12696:
1.138 matthew 12697: =back
12698:
12699: Returns:
12700:
12701: An <img> tag which references graph.png and the appropriate identifying
12702: information for the plot.
12703:
1.127 matthew 12704: =cut
12705:
12706: ############################################################
12707: ############################################################
1.134 matthew 12708: sub DrawBarGraph {
1.178 matthew 12709: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12710: #
12711: if (! defined($colors)) {
12712: $colors = ['#33ff00',
12713: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12714: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12715: ];
12716: }
1.228 matthew 12717: my $extra_settings = {};
12718: if (ref($Values[-1]) eq 'HASH') {
12719: $extra_settings = pop(@Values);
12720: }
1.127 matthew 12721: #
1.136 matthew 12722: my $identifier = &get_cgi_id();
12723: my $id = 'cgi.'.$identifier;
1.129 matthew 12724: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12725: return '';
12726: }
1.225 matthew 12727: #
12728: my @Labels;
12729: if (defined($labels)) {
12730: @Labels = @$labels;
12731: } else {
12732: for (my $i=0;$i<@{$Values[0]};$i++) {
12733: push (@Labels,$i+1);
12734: }
12735: }
12736: #
1.129 matthew 12737: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12738: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12739: my %ValuesHash;
12740: my $NumSets=1;
12741: foreach my $array (@Values) {
12742: next if (! ref($array));
1.136 matthew 12743: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12744: join(',',@$array);
1.129 matthew 12745: }
1.127 matthew 12746: #
1.136 matthew 12747: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12748: if ($NumBars < 3) {
12749: $width = 120+$NumBars*32;
1.220 matthew 12750: $xskip = 1;
1.225 matthew 12751: $bar_width = 30;
12752: } elsif ($NumBars < 5) {
12753: $width = 120+$NumBars*20;
12754: $xskip = 1;
12755: $bar_width = 20;
1.220 matthew 12756: } elsif ($NumBars < 10) {
1.136 matthew 12757: $width = 120+$NumBars*15;
12758: $xskip = 1;
12759: $bar_width = 15;
12760: } elsif ($NumBars <= 25) {
12761: $width = 120+$NumBars*11;
12762: $xskip = 5;
12763: $bar_width = 8;
12764: } elsif ($NumBars <= 50) {
12765: $width = 120+$NumBars*8;
12766: $xskip = 5;
12767: $bar_width = 4;
12768: } else {
12769: $width = 120+$NumBars*8;
12770: $xskip = 5;
12771: $bar_width = 4;
12772: }
12773: #
1.137 matthew 12774: $Max = 1 if ($Max < 1);
12775: if ( int($Max) < $Max ) {
12776: $Max++;
12777: $Max = int($Max);
12778: }
1.127 matthew 12779: $Title = '' if (! defined($Title));
12780: $xlabel = '' if (! defined($xlabel));
12781: $ylabel = '' if (! defined($ylabel));
1.369 www 12782: $ValuesHash{$id.'.title'} = &escape($Title);
12783: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12784: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12785: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12786: $ValuesHash{$id.'.NumBars'} = $NumBars;
12787: $ValuesHash{$id.'.NumSets'} = $NumSets;
12788: $ValuesHash{$id.'.PlotType'} = 'bar';
12789: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12790: $ValuesHash{$id.'.height'} = $height;
12791: $ValuesHash{$id.'.width'} = $width;
12792: $ValuesHash{$id.'.xskip'} = $xskip;
12793: $ValuesHash{$id.'.bar_width'} = $bar_width;
12794: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12795: #
1.228 matthew 12796: # Deal with other parameters
12797: while (my ($key,$value) = each(%$extra_settings)) {
12798: $ValuesHash{$id.'.'.$key} = $value;
12799: }
12800: #
1.646 raeburn 12801: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12802: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12803: }
12804:
12805: ############################################################
12806: ############################################################
12807:
12808: =pod
12809:
1.648 raeburn 12810: =item * &DrawXYGraph()
1.137 matthew 12811:
1.138 matthew 12812: Facilitates the plotting of data in an XY graph.
12813: Puts plot definition data into the users environment in order for
12814: graph.png to plot it. Returns an <img> tag for the plot.
12815:
12816: Inputs:
12817:
12818: =over 4
12819:
12820: =item $Title: string, the title of the plot
12821:
12822: =item $xlabel: string, text describing the X-axis of the plot
12823:
12824: =item $ylabel: string, text describing the Y-axis of the plot
12825:
12826: =item $Max: scalar, the maximum Y value to use in the plot
12827: If $Max is < any data point, the graph will not be rendered.
12828:
12829: =item $colors: Array ref containing the hex color codes for the data to be
12830: plotted in. If undefined, default values will be used.
12831:
12832: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12833:
12834: =item $Ydata: Array ref containing Array refs.
1.185 www 12835: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12836:
12837: =item %Values: hash indicating or overriding any default values which are
12838: passed to graph.png.
12839: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12840:
12841: =back
12842:
12843: Returns:
12844:
12845: An <img> tag which references graph.png and the appropriate identifying
12846: information for the plot.
12847:
1.137 matthew 12848: =cut
12849:
12850: ############################################################
12851: ############################################################
12852: sub DrawXYGraph {
12853: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12854: #
12855: # Create the identifier for the graph
12856: my $identifier = &get_cgi_id();
12857: my $id = 'cgi.'.$identifier;
12858: #
12859: $Title = '' if (! defined($Title));
12860: $xlabel = '' if (! defined($xlabel));
12861: $ylabel = '' if (! defined($ylabel));
12862: my %ValuesHash =
12863: (
1.369 www 12864: $id.'.title' => &escape($Title),
12865: $id.'.xlabel' => &escape($xlabel),
12866: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12867: $id.'.y_max_value'=> $Max,
12868: $id.'.labels' => join(',',@$Xlabels),
12869: $id.'.PlotType' => 'XY',
12870: );
12871: #
12872: if (defined($colors) && ref($colors) eq 'ARRAY') {
12873: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12874: }
12875: #
12876: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12877: return '';
12878: }
12879: my $NumSets=1;
1.138 matthew 12880: foreach my $array (@{$Ydata}){
1.137 matthew 12881: next if (! ref($array));
12882: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12883: }
1.138 matthew 12884: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12885: #
12886: # Deal with other parameters
12887: while (my ($key,$value) = each(%Values)) {
12888: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12889: }
12890: #
1.646 raeburn 12891: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12892: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12893: }
12894:
12895: ############################################################
12896: ############################################################
12897:
12898: =pod
12899:
1.648 raeburn 12900: =item * &DrawXYYGraph()
1.138 matthew 12901:
12902: Facilitates the plotting of data in an XY graph with two Y axes.
12903: Puts plot definition data into the users environment in order for
12904: graph.png to plot it. Returns an <img> tag for the plot.
12905:
12906: Inputs:
12907:
12908: =over 4
12909:
12910: =item $Title: string, the title of the plot
12911:
12912: =item $xlabel: string, text describing the X-axis of the plot
12913:
12914: =item $ylabel: string, text describing the Y-axis of the plot
12915:
12916: =item $colors: Array ref containing the hex color codes for the data to be
12917: plotted in. If undefined, default values will be used.
12918:
12919: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12920:
12921: =item $Ydata1: The first data set
12922:
12923: =item $Min1: The minimum value of the left Y-axis
12924:
12925: =item $Max1: The maximum value of the left Y-axis
12926:
12927: =item $Ydata2: The second data set
12928:
12929: =item $Min2: The minimum value of the right Y-axis
12930:
12931: =item $Max2: The maximum value of the left Y-axis
12932:
12933: =item %Values: hash indicating or overriding any default values which are
12934: passed to graph.png.
12935: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12936:
12937: =back
12938:
12939: Returns:
12940:
12941: An <img> tag which references graph.png and the appropriate identifying
12942: information for the plot.
1.136 matthew 12943:
12944: =cut
12945:
12946: ############################################################
12947: ############################################################
1.137 matthew 12948: sub DrawXYYGraph {
12949: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12950: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12951: #
12952: # Create the identifier for the graph
12953: my $identifier = &get_cgi_id();
12954: my $id = 'cgi.'.$identifier;
12955: #
12956: $Title = '' if (! defined($Title));
12957: $xlabel = '' if (! defined($xlabel));
12958: $ylabel = '' if (! defined($ylabel));
12959: my %ValuesHash =
12960: (
1.369 www 12961: $id.'.title' => &escape($Title),
12962: $id.'.xlabel' => &escape($xlabel),
12963: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 12964: $id.'.labels' => join(',',@$Xlabels),
12965: $id.'.PlotType' => 'XY',
12966: $id.'.NumSets' => 2,
1.137 matthew 12967: $id.'.two_axes' => 1,
12968: $id.'.y1_max_value' => $Max1,
12969: $id.'.y1_min_value' => $Min1,
12970: $id.'.y2_max_value' => $Max2,
12971: $id.'.y2_min_value' => $Min2,
1.136 matthew 12972: );
12973: #
1.137 matthew 12974: if (defined($colors) && ref($colors) eq 'ARRAY') {
12975: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12976: }
12977: #
12978: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
12979: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 12980: return '';
12981: }
12982: my $NumSets=1;
1.137 matthew 12983: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 12984: next if (! ref($array));
12985: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 12986: }
12987: #
12988: # Deal with other parameters
12989: while (my ($key,$value) = each(%Values)) {
12990: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 12991: }
12992: #
1.646 raeburn 12993: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 12994: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 12995: }
12996:
12997: ############################################################
12998: ############################################################
12999:
13000: =pod
13001:
1.157 matthew 13002: =back
13003:
1.139 matthew 13004: =head1 Statistics helper routines?
13005:
13006: Bad place for them but what the hell.
13007:
1.157 matthew 13008: =over 4
13009:
1.648 raeburn 13010: =item * &chartlink()
1.139 matthew 13011:
13012: Returns a link to the chart for a specific student.
13013:
13014: Inputs:
13015:
13016: =over 4
13017:
13018: =item $linktext: The text of the link
13019:
13020: =item $sname: The students username
13021:
13022: =item $sdomain: The students domain
13023:
13024: =back
13025:
1.157 matthew 13026: =back
13027:
1.139 matthew 13028: =cut
13029:
13030: ############################################################
13031: ############################################################
13032: sub chartlink {
13033: my ($linktext, $sname, $sdomain) = @_;
13034: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13035: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13036: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13037: '">'.$linktext.'</a>';
1.153 matthew 13038: }
13039:
13040: #######################################################
13041: #######################################################
13042:
13043: =pod
13044:
13045: =head1 Course Environment Routines
1.157 matthew 13046:
13047: =over 4
1.153 matthew 13048:
1.648 raeburn 13049: =item * &restore_course_settings()
1.153 matthew 13050:
1.648 raeburn 13051: =item * &store_course_settings()
1.153 matthew 13052:
13053: Restores/Store indicated form parameters from the course environment.
13054: Will not overwrite existing values of the form parameters.
13055:
13056: Inputs:
13057: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13058:
13059: a hash ref describing the data to be stored. For example:
13060:
13061: %Save_Parameters = ('Status' => 'scalar',
13062: 'chartoutputmode' => 'scalar',
13063: 'chartoutputdata' => 'scalar',
13064: 'Section' => 'array',
1.373 raeburn 13065: 'Group' => 'array',
1.153 matthew 13066: 'StudentData' => 'array',
13067: 'Maps' => 'array');
13068:
13069: Returns: both routines return nothing
13070:
1.631 raeburn 13071: =back
13072:
1.153 matthew 13073: =cut
13074:
13075: #######################################################
13076: #######################################################
13077: sub store_course_settings {
1.496 albertel 13078: return &store_settings($env{'request.course.id'},@_);
13079: }
13080:
13081: sub store_settings {
1.153 matthew 13082: # save to the environment
13083: # appenv the same items, just to be safe
1.300 albertel 13084: my $udom = $env{'user.domain'};
13085: my $uname = $env{'user.name'};
1.496 albertel 13086: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13087: my %SaveHash;
13088: my %AppHash;
13089: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13090: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13091: my $envname = 'environment.'.$basename;
1.258 albertel 13092: if (exists($env{'form.'.$setting})) {
1.153 matthew 13093: # Save this value away
13094: if ($type eq 'scalar' &&
1.258 albertel 13095: (! exists($env{$envname}) ||
13096: $env{$envname} ne $env{'form.'.$setting})) {
13097: $SaveHash{$basename} = $env{'form.'.$setting};
13098: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13099: } elsif ($type eq 'array') {
13100: my $stored_form;
1.258 albertel 13101: if (ref($env{'form.'.$setting})) {
1.153 matthew 13102: $stored_form = join(',',
13103: map {
1.369 www 13104: &escape($_);
1.258 albertel 13105: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13106: } else {
13107: $stored_form =
1.369 www 13108: &escape($env{'form.'.$setting});
1.153 matthew 13109: }
13110: # Determine if the array contents are the same.
1.258 albertel 13111: if ($stored_form ne $env{$envname}) {
1.153 matthew 13112: $SaveHash{$basename} = $stored_form;
13113: $AppHash{$envname} = $stored_form;
13114: }
13115: }
13116: }
13117: }
13118: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13119: $udom,$uname);
1.153 matthew 13120: if ($put_result !~ /^(ok|delayed)/) {
13121: &Apache::lonnet::logthis('unable to save form parameters, '.
13122: 'got error:'.$put_result);
13123: }
13124: # Make sure these settings stick around in this session, too
1.646 raeburn 13125: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13126: return;
13127: }
13128:
13129: sub restore_course_settings {
1.499 albertel 13130: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13131: }
13132:
13133: sub restore_settings {
13134: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13135: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13136: next if (exists($env{'form.'.$setting}));
1.496 albertel 13137: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13138: '.'.$setting;
1.258 albertel 13139: if (exists($env{$envname})) {
1.153 matthew 13140: if ($type eq 'scalar') {
1.258 albertel 13141: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13142: } elsif ($type eq 'array') {
1.258 albertel 13143: $env{'form.'.$setting} = [
1.153 matthew 13144: map {
1.369 www 13145: &unescape($_);
1.258 albertel 13146: } split(',',$env{$envname})
1.153 matthew 13147: ];
13148: }
13149: }
13150: }
1.127 matthew 13151: }
13152:
1.618 raeburn 13153: #######################################################
13154: #######################################################
13155:
13156: =pod
13157:
13158: =head1 Domain E-mail Routines
13159:
13160: =over 4
13161:
1.648 raeburn 13162: =item * &build_recipient_list()
1.618 raeburn 13163:
1.1075.2.44 raeburn 13164: Build recipient lists for following types of e-mail:
1.766 raeburn 13165: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13166: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13167: module change checking, student/employee ID conflict checks, as
13168: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13169: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13170:
13171: Inputs:
1.1075.2.44 raeburn 13172: defmail (scalar - email address of default recipient),
13173: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13174: requestsmail, updatesmail, or idconflictsmail).
13175:
1.619 raeburn 13176: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13177:
13178: origmail (scalar - email address of recipient from loncapa.conf,
13179: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13180:
1.655 raeburn 13181: Returns: comma separated list of addresses to which to send e-mail.
13182:
13183: =back
1.618 raeburn 13184:
13185: =cut
13186:
13187: ############################################################
13188: ############################################################
13189: sub build_recipient_list {
1.619 raeburn 13190: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13191: my @recipients;
13192: my $otheremails;
13193: my %domconfig =
13194: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13195: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13196: if (exists($domconfig{'contacts'}{$mailing})) {
13197: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13198: my @contacts = ('adminemail','supportemail');
13199: foreach my $item (@contacts) {
13200: if ($domconfig{'contacts'}{$mailing}{$item}) {
13201: my $addr = $domconfig{'contacts'}{$item};
13202: if (!grep(/^\Q$addr\E$/,@recipients)) {
13203: push(@recipients,$addr);
13204: }
1.619 raeburn 13205: }
1.766 raeburn 13206: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13207: }
13208: }
1.766 raeburn 13209: } elsif ($origmail ne '') {
13210: push(@recipients,$origmail);
1.618 raeburn 13211: }
1.619 raeburn 13212: } elsif ($origmail ne '') {
13213: push(@recipients,$origmail);
1.618 raeburn 13214: }
1.688 raeburn 13215: if (defined($defmail)) {
13216: if ($defmail ne '') {
13217: push(@recipients,$defmail);
13218: }
1.618 raeburn 13219: }
13220: if ($otheremails) {
1.619 raeburn 13221: my @others;
13222: if ($otheremails =~ /,/) {
13223: @others = split(/,/,$otheremails);
1.618 raeburn 13224: } else {
1.619 raeburn 13225: push(@others,$otheremails);
13226: }
13227: foreach my $addr (@others) {
13228: if (!grep(/^\Q$addr\E$/,@recipients)) {
13229: push(@recipients,$addr);
13230: }
1.618 raeburn 13231: }
13232: }
1.619 raeburn 13233: my $recipientlist = join(',',@recipients);
1.618 raeburn 13234: return $recipientlist;
13235: }
13236:
1.127 matthew 13237: ############################################################
13238: ############################################################
1.154 albertel 13239:
1.655 raeburn 13240: =pod
13241:
13242: =head1 Course Catalog Routines
13243:
13244: =over 4
13245:
13246: =item * &gather_categories()
13247:
13248: Converts category definitions - keys of categories hash stored in
13249: coursecategories in configuration.db on the primary library server in a
13250: domain - to an array. Also generates javascript and idx hash used to
13251: generate Domain Coordinator interface for editing Course Categories.
13252:
13253: Inputs:
1.663 raeburn 13254:
1.655 raeburn 13255: categories (reference to hash of category definitions).
1.663 raeburn 13256:
1.655 raeburn 13257: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13258: categories and subcategories).
1.663 raeburn 13259:
1.655 raeburn 13260: idx (reference to hash of counters used in Domain Coordinator interface for
13261: editing Course Categories).
1.663 raeburn 13262:
1.655 raeburn 13263: jsarray (reference to array of categories used to create Javascript arrays for
13264: Domain Coordinator interface for editing Course Categories).
13265:
13266: Returns: nothing
13267:
13268: Side effects: populates cats, idx and jsarray.
13269:
13270: =cut
13271:
13272: sub gather_categories {
13273: my ($categories,$cats,$idx,$jsarray) = @_;
13274: my %counters;
13275: my $num = 0;
13276: foreach my $item (keys(%{$categories})) {
13277: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13278: if ($container eq '' && $depth == 0) {
13279: $cats->[$depth][$categories->{$item}] = $cat;
13280: } else {
13281: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13282: }
13283: my ($escitem,$tail) = split(/:/,$item,2);
13284: if ($counters{$tail} eq '') {
13285: $counters{$tail} = $num;
13286: $num ++;
13287: }
13288: if (ref($idx) eq 'HASH') {
13289: $idx->{$item} = $counters{$tail};
13290: }
13291: if (ref($jsarray) eq 'ARRAY') {
13292: push(@{$jsarray->[$counters{$tail}]},$item);
13293: }
13294: }
13295: return;
13296: }
13297:
13298: =pod
13299:
13300: =item * &extract_categories()
13301:
13302: Used to generate breadcrumb trails for course categories.
13303:
13304: Inputs:
1.663 raeburn 13305:
1.655 raeburn 13306: categories (reference to hash of category definitions).
1.663 raeburn 13307:
1.655 raeburn 13308: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13309: categories and subcategories).
1.663 raeburn 13310:
1.655 raeburn 13311: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13312:
1.655 raeburn 13313: allitems (reference to hash - key is category key
13314: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13315:
1.655 raeburn 13316: idx (reference to hash of counters used in Domain Coordinator interface for
13317: editing Course Categories).
1.663 raeburn 13318:
1.655 raeburn 13319: jsarray (reference to array of categories used to create Javascript arrays for
13320: Domain Coordinator interface for editing Course Categories).
13321:
1.665 raeburn 13322: subcats (reference to hash of arrays containing all subcategories within each
13323: category, -recursive)
13324:
1.655 raeburn 13325: Returns: nothing
13326:
13327: Side effects: populates trails and allitems hash references.
13328:
13329: =cut
13330:
13331: sub extract_categories {
1.665 raeburn 13332: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13333: if (ref($categories) eq 'HASH') {
13334: &gather_categories($categories,$cats,$idx,$jsarray);
13335: if (ref($cats->[0]) eq 'ARRAY') {
13336: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13337: my $name = $cats->[0][$i];
13338: my $item = &escape($name).'::0';
13339: my $trailstr;
13340: if ($name eq 'instcode') {
13341: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13342: } elsif ($name eq 'communities') {
13343: $trailstr = &mt('Communities');
1.655 raeburn 13344: } else {
13345: $trailstr = $name;
13346: }
13347: if ($allitems->{$item} eq '') {
13348: push(@{$trails},$trailstr);
13349: $allitems->{$item} = scalar(@{$trails})-1;
13350: }
13351: my @parents = ($name);
13352: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13353: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13354: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13355: if (ref($subcats) eq 'HASH') {
13356: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13357: }
13358: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13359: }
13360: } else {
13361: if (ref($subcats) eq 'HASH') {
13362: $subcats->{$item} = [];
1.655 raeburn 13363: }
13364: }
13365: }
13366: }
13367: }
13368: return;
13369: }
13370:
13371: =pod
13372:
1.1075.2.56! raeburn 13373: =item * &recurse_categories()
1.655 raeburn 13374:
13375: Recursively used to generate breadcrumb trails for course categories.
13376:
13377: Inputs:
1.663 raeburn 13378:
1.655 raeburn 13379: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13380: categories and subcategories).
1.663 raeburn 13381:
1.655 raeburn 13382: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13383:
13384: category (current course category, for which breadcrumb trail is being generated).
13385:
13386: trails (reference to array of breadcrumb trails for each category).
13387:
1.655 raeburn 13388: allitems (reference to hash - key is category key
13389: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13390:
1.655 raeburn 13391: parents (array containing containers directories for current category,
13392: back to top level).
13393:
13394: Returns: nothing
13395:
13396: Side effects: populates trails and allitems hash references
13397:
13398: =cut
13399:
13400: sub recurse_categories {
1.665 raeburn 13401: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13402: my $shallower = $depth - 1;
13403: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13404: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13405: my $name = $cats->[$depth]{$category}[$k];
13406: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13407: my $trailstr = join(' -> ',(@{$parents},$category));
13408: if ($allitems->{$item} eq '') {
13409: push(@{$trails},$trailstr);
13410: $allitems->{$item} = scalar(@{$trails})-1;
13411: }
13412: my $deeper = $depth+1;
13413: push(@{$parents},$category);
1.665 raeburn 13414: if (ref($subcats) eq 'HASH') {
13415: my $subcat = &escape($name).':'.$category.':'.$depth;
13416: for (my $j=@{$parents}; $j>=0; $j--) {
13417: my $higher;
13418: if ($j > 0) {
13419: $higher = &escape($parents->[$j]).':'.
13420: &escape($parents->[$j-1]).':'.$j;
13421: } else {
13422: $higher = &escape($parents->[$j]).'::'.$j;
13423: }
13424: push(@{$subcats->{$higher}},$subcat);
13425: }
13426: }
13427: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13428: $subcats);
1.655 raeburn 13429: pop(@{$parents});
13430: }
13431: } else {
13432: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13433: my $trailstr = join(' -> ',(@{$parents},$category));
13434: if ($allitems->{$item} eq '') {
13435: push(@{$trails},$trailstr);
13436: $allitems->{$item} = scalar(@{$trails})-1;
13437: }
13438: }
13439: return;
13440: }
13441:
1.663 raeburn 13442: =pod
13443:
1.1075.2.56! raeburn 13444: =item * &assign_categories_table()
1.663 raeburn 13445:
13446: Create a datatable for display of hierarchical categories in a domain,
13447: with checkboxes to allow a course to be categorized.
13448:
13449: Inputs:
13450:
13451: cathash - reference to hash of categories defined for the domain (from
13452: configuration.db)
13453:
13454: currcat - scalar with an & separated list of categories assigned to a course.
13455:
1.919 raeburn 13456: type - scalar contains course type (Course or Community).
13457:
1.663 raeburn 13458: Returns: $output (markup to be displayed)
13459:
13460: =cut
13461:
13462: sub assign_categories_table {
1.919 raeburn 13463: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13464: my $output;
13465: if (ref($cathash) eq 'HASH') {
13466: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13467: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13468: $maxdepth = scalar(@cats);
13469: if (@cats > 0) {
13470: my $itemcount = 0;
13471: if (ref($cats[0]) eq 'ARRAY') {
13472: my @currcategories;
13473: if ($currcat ne '') {
13474: @currcategories = split('&',$currcat);
13475: }
1.919 raeburn 13476: my $table;
1.663 raeburn 13477: for (my $i=0; $i<@{$cats[0]}; $i++) {
13478: my $parent = $cats[0][$i];
1.919 raeburn 13479: next if ($parent eq 'instcode');
13480: if ($type eq 'Community') {
13481: next unless ($parent eq 'communities');
13482: } else {
13483: next if ($parent eq 'communities');
13484: }
1.663 raeburn 13485: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13486: my $item = &escape($parent).'::0';
13487: my $checked = '';
13488: if (@currcategories > 0) {
13489: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13490: $checked = ' checked="checked"';
1.663 raeburn 13491: }
13492: }
1.919 raeburn 13493: my $parent_title = $parent;
13494: if ($parent eq 'communities') {
13495: $parent_title = &mt('Communities');
13496: }
13497: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13498: '<input type="checkbox" name="usecategory" value="'.
13499: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13500: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13501: my $depth = 1;
13502: push(@path,$parent);
1.919 raeburn 13503: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13504: pop(@path);
1.919 raeburn 13505: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13506: $itemcount ++;
13507: }
1.919 raeburn 13508: if ($itemcount) {
13509: $output = &Apache::loncommon::start_data_table().
13510: $table.
13511: &Apache::loncommon::end_data_table();
13512: }
1.663 raeburn 13513: }
13514: }
13515: }
13516: return $output;
13517: }
13518:
13519: =pod
13520:
1.1075.2.56! raeburn 13521: =item * &assign_category_rows()
1.663 raeburn 13522:
13523: Create a datatable row for display of nested categories in a domain,
13524: with checkboxes to allow a course to be categorized,called recursively.
13525:
13526: Inputs:
13527:
13528: itemcount - track row number for alternating colors
13529:
13530: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13531: categories and subcategories.
13532:
13533: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13534:
13535: parent - parent of current category item
13536:
13537: path - Array containing all categories back up through the hierarchy from the
13538: current category to the top level.
13539:
13540: currcategories - reference to array of current categories assigned to the course
13541:
13542: Returns: $output (markup to be displayed).
13543:
13544: =cut
13545:
13546: sub assign_category_rows {
13547: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13548: my ($text,$name,$item,$chgstr);
13549: if (ref($cats) eq 'ARRAY') {
13550: my $maxdepth = scalar(@{$cats});
13551: if (ref($cats->[$depth]) eq 'HASH') {
13552: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13553: my $numchildren = @{$cats->[$depth]{$parent}};
13554: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 13555: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13556: for (my $j=0; $j<$numchildren; $j++) {
13557: $name = $cats->[$depth]{$parent}[$j];
13558: $item = &escape($name).':'.&escape($parent).':'.$depth;
13559: my $deeper = $depth+1;
13560: my $checked = '';
13561: if (ref($currcategories) eq 'ARRAY') {
13562: if (@{$currcategories} > 0) {
13563: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13564: $checked = ' checked="checked"';
1.663 raeburn 13565: }
13566: }
13567: }
1.664 raeburn 13568: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13569: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13570: $item.'"'.$checked.' />'.$name.'</label></span>'.
13571: '<input type="hidden" name="catname" value="'.$name.'" />'.
13572: '</td><td>';
1.663 raeburn 13573: if (ref($path) eq 'ARRAY') {
13574: push(@{$path},$name);
13575: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13576: pop(@{$path});
13577: }
13578: $text .= '</td></tr>';
13579: }
13580: $text .= '</table></td>';
13581: }
13582: }
13583: }
13584: return $text;
13585: }
13586:
1.655 raeburn 13587: ############################################################
13588: ############################################################
13589:
13590:
1.443 albertel 13591: sub commit_customrole {
1.664 raeburn 13592: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13593: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13594: ($start?', '.&mt('starting').' '.localtime($start):'').
13595: ($end?', ending '.localtime($end):'').': <b>'.
13596: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13597: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13598: '</b><br />';
13599: return $output;
13600: }
13601:
13602: sub commit_standardrole {
1.1075.2.31 raeburn 13603: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13604: my ($output,$logmsg,$linefeed);
13605: if ($context eq 'auto') {
13606: $linefeed = "\n";
13607: } else {
13608: $linefeed = "<br />\n";
13609: }
1.443 albertel 13610: if ($three eq 'st') {
1.541 raeburn 13611: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 13612: $one,$two,$sec,$context,$credits);
1.541 raeburn 13613: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13614: ($result eq 'unknown_course') || ($result eq 'refused')) {
13615: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13616: } else {
1.541 raeburn 13617: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13618: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13619: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13620: if ($context eq 'auto') {
13621: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13622: } else {
13623: $output .= '<b>'.$result.'</b>'.$linefeed.
13624: &mt('Add to classlist').': <b>ok</b>';
13625: }
13626: $output .= $linefeed;
1.443 albertel 13627: }
13628: } else {
13629: $output = &mt('Assigning').' '.$three.' in '.$url.
13630: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13631: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13632: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13633: if ($context eq 'auto') {
13634: $output .= $result.$linefeed;
13635: } else {
13636: $output .= '<b>'.$result.'</b>'.$linefeed;
13637: }
1.443 albertel 13638: }
13639: return $output;
13640: }
13641:
13642: sub commit_studentrole {
1.1075.2.31 raeburn 13643: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13644: $credits) = @_;
1.626 raeburn 13645: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13646: if ($context eq 'auto') {
13647: $linefeed = "\n";
13648: } else {
13649: $linefeed = '<br />'."\n";
13650: }
1.443 albertel 13651: if (defined($one) && defined($two)) {
13652: my $cid=$one.'_'.$two;
13653: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13654: my $secchange = 0;
13655: my $expire_role_result;
13656: my $modify_section_result;
1.628 raeburn 13657: if ($oldsec ne '-1') {
13658: if ($oldsec ne $sec) {
1.443 albertel 13659: $secchange = 1;
1.628 raeburn 13660: my $now = time;
1.443 albertel 13661: my $uurl='/'.$cid;
13662: $uurl=~s/\_/\//g;
13663: if ($oldsec) {
13664: $uurl.='/'.$oldsec;
13665: }
1.626 raeburn 13666: $oldsecurl = $uurl;
1.628 raeburn 13667: $expire_role_result =
1.652 raeburn 13668: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13669: if ($env{'request.course.sec'} ne '') {
13670: if ($expire_role_result eq 'refused') {
13671: my @roles = ('st');
13672: my @statuses = ('previous');
13673: my @roledoms = ($one);
13674: my $withsec = 1;
13675: my %roleshash =
13676: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13677: \@statuses,\@roles,\@roledoms,$withsec);
13678: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13679: my ($oldstart,$oldend) =
13680: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13681: if ($oldend > 0 && $oldend <= $now) {
13682: $expire_role_result = 'ok';
13683: }
13684: }
13685: }
13686: }
1.443 albertel 13687: $result = $expire_role_result;
13688: }
13689: }
13690: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 13691: $modify_section_result =
13692: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13693: undef,undef,undef,$sec,
13694: $end,$start,'','',$cid,
13695: '',$context,$credits);
1.443 albertel 13696: if ($modify_section_result =~ /^ok/) {
13697: if ($secchange == 1) {
1.628 raeburn 13698: if ($sec eq '') {
13699: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13700: } else {
13701: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13702: }
1.443 albertel 13703: } elsif ($oldsec eq '-1') {
1.628 raeburn 13704: if ($sec eq '') {
13705: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13706: } else {
13707: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13708: }
1.443 albertel 13709: } else {
1.628 raeburn 13710: if ($sec eq '') {
13711: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13712: } else {
13713: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13714: }
1.443 albertel 13715: }
13716: } else {
1.628 raeburn 13717: if ($secchange) {
13718: $$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;
13719: } else {
13720: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13721: }
1.443 albertel 13722: }
13723: $result = $modify_section_result;
13724: } elsif ($secchange == 1) {
1.628 raeburn 13725: if ($oldsec eq '') {
1.1075.2.20 raeburn 13726: $$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 13727: } else {
13728: $$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;
13729: }
1.626 raeburn 13730: if ($expire_role_result eq 'refused') {
13731: my $newsecurl = '/'.$cid;
13732: $newsecurl =~ s/\_/\//g;
13733: if ($sec ne '') {
13734: $newsecurl.='/'.$sec;
13735: }
13736: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13737: if ($sec eq '') {
13738: $$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;
13739: } else {
13740: $$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;
13741: }
13742: }
13743: }
1.443 albertel 13744: }
13745: } else {
1.626 raeburn 13746: $$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 13747: $result = "error: incomplete course id\n";
13748: }
13749: return $result;
13750: }
13751:
1.1075.2.25 raeburn 13752: sub show_role_extent {
13753: my ($scope,$context,$role) = @_;
13754: $scope =~ s{^/}{};
13755: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13756: push(@courseroles,'co');
13757: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13758: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13759: $scope =~ s{/}{_};
13760: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13761: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13762: my ($audom,$auname) = split(/\//,$scope);
13763: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13764: &Apache::loncommon::plainname($auname,$audom).'</span>');
13765: } else {
13766: $scope =~ s{/$}{};
13767: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13768: &Apache::lonnet::domain($scope,'description').'</span>');
13769: }
13770: }
13771:
1.443 albertel 13772: ############################################################
13773: ############################################################
13774:
1.566 albertel 13775: sub check_clone {
1.578 raeburn 13776: my ($args,$linefeed) = @_;
1.566 albertel 13777: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13778: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13779: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13780: my $clonemsg;
13781: my $can_clone = 0;
1.944 raeburn 13782: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13783: if ($lctype ne 'community') {
13784: $lctype = 'course';
13785: }
1.566 albertel 13786: if ($clonehome eq 'no_host') {
1.944 raeburn 13787: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13788: $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'});
13789: } else {
13790: $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'});
13791: }
1.566 albertel 13792: } else {
13793: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13794: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13795: if ($clonedesc{'type'} ne 'Community') {
13796: $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'});
13797: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13798: }
13799: }
1.882 raeburn 13800: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13801: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13802: $can_clone = 1;
13803: } else {
13804: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13805: $args->{'clonedomain'},$args->{'clonecourse'});
13806: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13807: if (grep(/^\*$/,@cloners)) {
13808: $can_clone = 1;
13809: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13810: $can_clone = 1;
13811: } else {
1.908 raeburn 13812: my $ccrole = 'cc';
1.944 raeburn 13813: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13814: $ccrole = 'co';
13815: }
1.578 raeburn 13816: my %roleshash =
13817: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13818: $args->{'ccdomain'},
1.908 raeburn 13819: 'userroles',['active'],[$ccrole],
1.578 raeburn 13820: [$args->{'clonedomain'}]);
1.908 raeburn 13821: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13822: $can_clone = 1;
13823: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13824: $can_clone = 1;
13825: } else {
1.944 raeburn 13826: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13827: $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'});
13828: } else {
13829: $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'});
13830: }
1.578 raeburn 13831: }
1.566 albertel 13832: }
1.578 raeburn 13833: }
1.566 albertel 13834: }
13835: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13836: }
13837:
1.444 albertel 13838: sub construct_course {
1.885 raeburn 13839: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 13840: my $outcome;
1.541 raeburn 13841: my $linefeed = '<br />'."\n";
13842: if ($context eq 'auto') {
13843: $linefeed = "\n";
13844: }
1.566 albertel 13845:
13846: #
13847: # Are we cloning?
13848: #
13849: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13850: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13851: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13852: if ($context ne 'auto') {
1.578 raeburn 13853: if ($clonemsg ne '') {
13854: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13855: }
1.566 albertel 13856: }
13857: $outcome .= $clonemsg.$linefeed;
13858:
13859: if (!$can_clone) {
13860: return (0,$outcome);
13861: }
13862: }
13863:
1.444 albertel 13864: #
13865: # Open course
13866: #
13867: my $crstype = lc($args->{'crstype'});
13868: my %cenv=();
13869: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13870: $args->{'cdescr'},
13871: $args->{'curl'},
13872: $args->{'course_home'},
13873: $args->{'nonstandard'},
13874: $args->{'crscode'},
13875: $args->{'ccuname'}.':'.
13876: $args->{'ccdomain'},
1.882 raeburn 13877: $args->{'crstype'},
1.885 raeburn 13878: $cnum,$context,$category);
1.444 albertel 13879:
13880: # Note: The testing routines depend on this being output; see
13881: # Utils::Course. This needs to at least be output as a comment
13882: # if anyone ever decides to not show this, and Utils::Course::new
13883: # will need to be suitably modified.
1.541 raeburn 13884: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13885: if ($$courseid =~ /^error:/) {
13886: return (0,$outcome);
13887: }
13888:
1.444 albertel 13889: #
13890: # Check if created correctly
13891: #
1.479 albertel 13892: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13893: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13894: if ($crsuhome eq 'no_host') {
13895: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13896: return (0,$outcome);
13897: }
1.541 raeburn 13898: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13899:
1.444 albertel 13900: #
1.566 albertel 13901: # Do the cloning
13902: #
13903: if ($can_clone && $cloneid) {
13904: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13905: if ($context ne 'auto') {
13906: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13907: }
13908: $outcome .= $clonemsg.$linefeed;
13909: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13910: # Copy all files
1.637 www 13911: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13912: # Restore URL
1.566 albertel 13913: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13914: # Restore title
1.566 albertel 13915: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13916: # Restore creation date, creator and creation context.
13917: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13918: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13919: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13920: # Mark as cloned
1.566 albertel 13921: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13922: # Need to clone grading mode
13923: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13924: $cenv{'grading'}=$newenv{'grading'};
13925: # Do not clone these environment entries
13926: &Apache::lonnet::del('environment',
13927: ['default_enrollment_start_date',
13928: 'default_enrollment_end_date',
13929: 'question.email',
13930: 'policy.email',
13931: 'comment.email',
13932: 'pch.users.denied',
1.725 raeburn 13933: 'plc.users.denied',
13934: 'hidefromcat',
1.1075.2.36 raeburn 13935: 'checkforpriv',
1.725 raeburn 13936: 'categories'],
1.638 www 13937: $$crsudom,$$crsunum);
1.444 albertel 13938: }
1.566 albertel 13939:
1.444 albertel 13940: #
13941: # Set environment (will override cloned, if existing)
13942: #
13943: my @sections = ();
13944: my @xlists = ();
13945: if ($args->{'crstype'}) {
13946: $cenv{'type'}=$args->{'crstype'};
13947: }
13948: if ($args->{'crsid'}) {
13949: $cenv{'courseid'}=$args->{'crsid'};
13950: }
13951: if ($args->{'crscode'}) {
13952: $cenv{'internal.coursecode'}=$args->{'crscode'};
13953: }
13954: if ($args->{'crsquota'} ne '') {
13955: $cenv{'internal.coursequota'}=$args->{'crsquota'};
13956: } else {
13957: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
13958: }
13959: if ($args->{'ccuname'}) {
13960: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
13961: ':'.$args->{'ccdomain'};
13962: } else {
13963: $cenv{'internal.courseowner'} = $args->{'curruser'};
13964: }
1.1075.2.31 raeburn 13965: if ($args->{'defaultcredits'}) {
13966: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
13967: }
1.444 albertel 13968: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
13969: if ($args->{'crssections'}) {
13970: $cenv{'internal.sectionnums'} = '';
13971: if ($args->{'crssections'} =~ m/,/) {
13972: @sections = split/,/,$args->{'crssections'};
13973: } else {
13974: $sections[0] = $args->{'crssections'};
13975: }
13976: if (@sections > 0) {
13977: foreach my $item (@sections) {
13978: my ($sec,$gp) = split/:/,$item;
13979: my $class = $args->{'crscode'}.$sec;
13980: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
13981: $cenv{'internal.sectionnums'} .= $item.',';
13982: unless ($addcheck eq 'ok') {
13983: push @badclasses, $class;
13984: }
13985: }
13986: $cenv{'internal.sectionnums'} =~ s/,$//;
13987: }
13988: }
13989: # do not hide course coordinator from staff listing,
13990: # even if privileged
13991: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 13992: # add course coordinator's domain to domains to check for privileged users
13993: # if different to course domain
13994: if ($$crsudom ne $args->{'ccdomain'}) {
13995: $cenv{'checkforpriv'} = $args->{'ccdomain'};
13996: }
1.444 albertel 13997: # add crosslistings
13998: if ($args->{'crsxlist'}) {
13999: $cenv{'internal.crosslistings'}='';
14000: if ($args->{'crsxlist'} =~ m/,/) {
14001: @xlists = split/,/,$args->{'crsxlist'};
14002: } else {
14003: $xlists[0] = $args->{'crsxlist'};
14004: }
14005: if (@xlists > 0) {
14006: foreach my $item (@xlists) {
14007: my ($xl,$gp) = split/:/,$item;
14008: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14009: $cenv{'internal.crosslistings'} .= $item.',';
14010: unless ($addcheck eq 'ok') {
14011: push @badclasses, $xl;
14012: }
14013: }
14014: $cenv{'internal.crosslistings'} =~ s/,$//;
14015: }
14016: }
14017: if ($args->{'autoadds'}) {
14018: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14019: }
14020: if ($args->{'autodrops'}) {
14021: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14022: }
14023: # check for notification of enrollment changes
14024: my @notified = ();
14025: if ($args->{'notify_owner'}) {
14026: if ($args->{'ccuname'} ne '') {
14027: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14028: }
14029: }
14030: if ($args->{'notify_dc'}) {
14031: if ($uname ne '') {
1.630 raeburn 14032: push(@notified,$uname.':'.$udom);
1.444 albertel 14033: }
14034: }
14035: if (@notified > 0) {
14036: my $notifylist;
14037: if (@notified > 1) {
14038: $notifylist = join(',',@notified);
14039: } else {
14040: $notifylist = $notified[0];
14041: }
14042: $cenv{'internal.notifylist'} = $notifylist;
14043: }
14044: if (@badclasses > 0) {
14045: my %lt=&Apache::lonlocal::texthash(
14046: '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',
14047: 'dnhr' => 'does not have rights to access enrollment in these classes',
14048: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14049: );
1.541 raeburn 14050: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14051: ' ('.$lt{'adby'}.')';
14052: if ($context eq 'auto') {
14053: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14054: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14055: foreach my $item (@badclasses) {
14056: if ($context eq 'auto') {
14057: $outcome .= " - $item\n";
14058: } else {
14059: $outcome .= "<li>$item</li>\n";
14060: }
14061: }
14062: if ($context eq 'auto') {
14063: $outcome .= $linefeed;
14064: } else {
1.566 albertel 14065: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14066: }
14067: }
1.444 albertel 14068: }
14069: if ($args->{'no_end_date'}) {
14070: $args->{'endaccess'} = 0;
14071: }
14072: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14073: $cenv{'internal.autoend'}=$args->{'enrollend'};
14074: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14075: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14076: if ($args->{'showphotos'}) {
14077: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14078: }
14079: $cenv{'internal.authtype'} = $args->{'authtype'};
14080: $cenv{'internal.autharg'} = $args->{'autharg'};
14081: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14082: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14083: 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');
14084: if ($context eq 'auto') {
14085: $outcome .= $krb_msg;
14086: } else {
1.566 albertel 14087: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14088: }
14089: $outcome .= $linefeed;
1.444 albertel 14090: }
14091: }
14092: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14093: if ($args->{'setpolicy'}) {
14094: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14095: }
14096: if ($args->{'setcontent'}) {
14097: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14098: }
14099: }
14100: if ($args->{'reshome'}) {
14101: $cenv{'reshome'}=$args->{'reshome'}.'/';
14102: $cenv{'reshome'}=~s/\/+$/\//;
14103: }
14104: #
14105: # course has keyed access
14106: #
14107: if ($args->{'setkeys'}) {
14108: $cenv{'keyaccess'}='yes';
14109: }
14110: # if specified, key authority is not course, but user
14111: # only active if keyaccess is yes
14112: if ($args->{'keyauth'}) {
1.487 albertel 14113: my ($user,$domain) = split(':',$args->{'keyauth'});
14114: $user = &LONCAPA::clean_username($user);
14115: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14116: if ($user ne '' && $domain ne '') {
1.487 albertel 14117: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14118: }
14119: }
14120:
14121: if ($args->{'disresdis'}) {
14122: $cenv{'pch.roles.denied'}='st';
14123: }
14124: if ($args->{'disablechat'}) {
14125: $cenv{'plc.roles.denied'}='st';
14126: }
14127:
14128: # Record we've not yet viewed the Course Initialization Helper for this
14129: # course
14130: $cenv{'course.helper.not.run'} = 1;
14131: #
14132: # Use new Randomseed
14133: #
14134: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14135: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14136: #
14137: # The encryption code and receipt prefix for this course
14138: #
14139: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14140: $cenv{'internal.encpref'}=100+int(9*rand(99));
14141: #
14142: # By default, use standard grading
14143: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14144:
1.541 raeburn 14145: $outcome .= $linefeed.&mt('Setting environment').': '.
14146: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14147: #
14148: # Open all assignments
14149: #
14150: if ($args->{'openall'}) {
14151: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14152: my %storecontent = ($storeunder => time,
14153: $storeunder.'.type' => 'date_start');
14154:
14155: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14156: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14157: }
14158: #
14159: # Set first page
14160: #
14161: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14162: || ($cloneid)) {
1.445 albertel 14163: use LONCAPA::map;
1.444 albertel 14164: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14165:
14166: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14167: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14168:
1.444 albertel 14169: $outcome .= ($fatal?$errtext:'read ok').' - ';
14170: my $title; my $url;
14171: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14172: $title=&mt('Syllabus');
1.444 albertel 14173: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14174: } else {
1.963 raeburn 14175: $title=&mt('Table of Contents');
1.444 albertel 14176: $url='/adm/navmaps';
14177: }
1.445 albertel 14178:
14179: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14180: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14181:
14182: if ($errtext) { $fatal=2; }
1.541 raeburn 14183: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14184: }
1.566 albertel 14185:
14186: return (1,$outcome);
1.444 albertel 14187: }
14188:
14189: ############################################################
14190: ############################################################
14191:
1.953 droeschl 14192: #SD
14193: # only Community and Course, or anything else?
1.378 raeburn 14194: sub course_type {
14195: my ($cid) = @_;
14196: if (!defined($cid)) {
14197: $cid = $env{'request.course.id'};
14198: }
1.404 albertel 14199: if (defined($env{'course.'.$cid.'.type'})) {
14200: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14201: } else {
14202: return 'Course';
1.377 raeburn 14203: }
14204: }
1.156 albertel 14205:
1.406 raeburn 14206: sub group_term {
14207: my $crstype = &course_type();
14208: my %names = (
14209: 'Course' => 'group',
1.865 raeburn 14210: 'Community' => 'group',
1.406 raeburn 14211: );
14212: return $names{$crstype};
14213: }
14214:
1.902 raeburn 14215: sub course_types {
14216: my @types = ('official','unofficial','community');
14217: my %typename = (
14218: official => 'Official course',
14219: unofficial => 'Unofficial course',
14220: community => 'Community',
14221: );
14222: return (\@types,\%typename);
14223: }
14224:
1.156 albertel 14225: sub icon {
14226: my ($file)=@_;
1.505 albertel 14227: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14228: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14229: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14230: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14231: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14232: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14233: $curfext.".gif") {
14234: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14235: $curfext.".gif";
14236: }
14237: }
1.249 albertel 14238: return &lonhttpdurl($iconname);
1.154 albertel 14239: }
1.84 albertel 14240:
1.575 albertel 14241: sub lonhttpdurl {
1.692 www 14242: #
14243: # Had been used for "small fry" static images on separate port 8080.
14244: # Modify here if lightweight http functionality desired again.
14245: # Currently eliminated due to increasing firewall issues.
14246: #
1.575 albertel 14247: my ($url)=@_;
1.692 www 14248: return $url;
1.215 albertel 14249: }
14250:
1.213 albertel 14251: sub connection_aborted {
14252: my ($r)=@_;
14253: $r->print(" ");$r->rflush();
14254: my $c = $r->connection;
14255: return $c->aborted();
14256: }
14257:
1.221 foxr 14258: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14259: # strings as 'strings'.
14260: sub escape_single {
1.221 foxr 14261: my ($input) = @_;
1.223 albertel 14262: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14263: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14264: return $input;
14265: }
1.223 albertel 14266:
1.222 foxr 14267: # Same as escape_single, but escape's "'s This
14268: # can be used for "strings"
14269: sub escape_double {
14270: my ($input) = @_;
14271: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14272: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14273: return $input;
14274: }
1.223 albertel 14275:
1.222 foxr 14276: # Escapes the last element of a full URL.
14277: sub escape_url {
14278: my ($url) = @_;
1.238 raeburn 14279: my @urlslices = split(/\//, $url,-1);
1.369 www 14280: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14281: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14282: }
1.462 albertel 14283:
1.820 raeburn 14284: sub compare_arrays {
14285: my ($arrayref1,$arrayref2) = @_;
14286: my (@difference,%count);
14287: @difference = ();
14288: %count = ();
14289: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14290: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14291: foreach my $element (keys(%count)) {
14292: if ($count{$element} == 1) {
14293: push(@difference,$element);
14294: }
14295: }
14296: }
14297: return @difference;
14298: }
14299:
1.817 bisitz 14300: # -------------------------------------------------------- Initialize user login
1.462 albertel 14301: sub init_user_environment {
1.463 albertel 14302: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14303: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14304:
14305: my $public=($username eq 'public' && $domain eq 'public');
14306:
14307: # See if old ID present, if so, remove
14308:
1.1062 raeburn 14309: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14310: my $now=time;
14311:
14312: if ($public) {
14313: my $max_public=100;
14314: my $oldest;
14315: my $oldest_time=0;
14316: for(my $next=1;$next<=$max_public;$next++) {
14317: if (-e $lonids."/publicuser_$next.id") {
14318: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14319: if ($mtime<$oldest_time || !$oldest_time) {
14320: $oldest_time=$mtime;
14321: $oldest=$next;
14322: }
14323: } else {
14324: $cookie="publicuser_$next";
14325: last;
14326: }
14327: }
14328: if (!$cookie) { $cookie="publicuser_$oldest"; }
14329: } else {
1.463 albertel 14330: # if this isn't a robot, kill any existing non-robot sessions
14331: if (!$args->{'robot'}) {
14332: opendir(DIR,$lonids);
14333: while ($filename=readdir(DIR)) {
14334: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14335: unlink($lonids.'/'.$filename);
14336: }
1.462 albertel 14337: }
1.463 albertel 14338: closedir(DIR);
1.462 albertel 14339: }
14340: # Give them a new cookie
1.463 albertel 14341: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14342: : $now.$$.int(rand(10000)));
1.463 albertel 14343: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14344:
14345: # Initialize roles
14346:
1.1062 raeburn 14347: ($userroles,$firstaccenv,$timerintenv) =
14348: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14349: }
14350: # ------------------------------------ Check browser type and MathML capability
14351:
14352: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42 raeburn 14353: $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
1.462 albertel 14354:
14355: # ------------------------------------------------------------- Get environment
14356:
14357: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14358: my ($tmp) = keys(%userenv);
14359: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14360: } else {
14361: undef(%userenv);
14362: }
14363: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14364: $form->{'interface'}=$userenv{'interface'};
14365: }
14366: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14367:
14368: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14369: foreach my $option ('interface','localpath','localres') {
14370: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14371: }
14372: # --------------------------------------------------------- Write first profile
14373:
14374: {
14375: my %initial_env =
14376: ("user.name" => $username,
14377: "user.domain" => $domain,
14378: "user.home" => $authhost,
14379: "browser.type" => $clientbrowser,
14380: "browser.version" => $clientversion,
14381: "browser.mathml" => $clientmathml,
14382: "browser.unicode" => $clientunicode,
14383: "browser.os" => $clientos,
1.1075.2.42 raeburn 14384: "browser.mobile" => $clientmobile,
14385: "browser.info" => $clientinfo,
1.462 albertel 14386: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14387: "request.course.fn" => '',
14388: "request.course.uri" => '',
14389: "request.course.sec" => '',
14390: "request.role" => 'cm',
14391: "request.role.adv" => $env{'user.adv'},
14392: "request.host" => $ENV{'REMOTE_ADDR'},);
14393:
14394: if ($form->{'localpath'}) {
14395: $initial_env{"browser.localpath"} = $form->{'localpath'};
14396: $initial_env{"browser.localres"} = $form->{'localres'};
14397: }
14398:
14399: if ($form->{'interface'}) {
14400: $form->{'interface'}=~s/\W//gs;
14401: $initial_env{"browser.interface"} = $form->{'interface'};
14402: $env{'browser.interface'}=$form->{'interface'};
14403: }
14404:
1.1075.2.54 raeburn 14405: if ($form->{'iptoken'}) {
14406: my $lonhost = $r->dir_config('lonHostID');
14407: $initial_env{"user.noloadbalance"} = $lonhost;
14408: $env{'user.noloadbalance'} = $lonhost;
14409: }
14410:
1.981 raeburn 14411: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14412: my %domdef;
14413: unless ($domain eq 'public') {
14414: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14415: }
1.980 raeburn 14416:
1.1075.2.7 raeburn 14417: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14418: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14419: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14420: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14421: }
14422:
1.864 raeburn 14423: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 14424: $userenv{'canrequest.'.$crstype} =
14425: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14426: 'reload','requestcourses',
14427: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14428: }
14429:
1.1075.2.14 raeburn 14430: $userenv{'canrequest.author'} =
14431: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14432: 'reload','requestauthor',
14433: \%userenv,\%domdef,\%is_adv);
14434: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14435: $domain,$username);
14436: my $reqstatus = $reqauthor{'author_status'};
14437: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14438: if (ref($reqauthor{'author'}) eq 'HASH') {
14439: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14440: $reqauthor{'author'}{'timestamp'};
14441: }
14442: }
14443:
1.462 albertel 14444: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14445:
1.462 albertel 14446: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14447: &GDBM_WRCREAT(),0640)) {
14448: &_add_to_env(\%disk_env,\%initial_env);
14449: &_add_to_env(\%disk_env,\%userenv,'environment.');
14450: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14451: if (ref($firstaccenv) eq 'HASH') {
14452: &_add_to_env(\%disk_env,$firstaccenv);
14453: }
14454: if (ref($timerintenv) eq 'HASH') {
14455: &_add_to_env(\%disk_env,$timerintenv);
14456: }
1.463 albertel 14457: if (ref($args->{'extra_env'})) {
14458: &_add_to_env(\%disk_env,$args->{'extra_env'});
14459: }
1.462 albertel 14460: untie(%disk_env);
14461: } else {
1.705 tempelho 14462: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14463: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14464: return 'error: '.$!;
14465: }
14466: }
14467: $env{'request.role'}='cm';
14468: $env{'request.role.adv'}=$env{'user.adv'};
14469: $env{'browser.type'}=$clientbrowser;
14470:
14471: return $cookie;
14472:
14473: }
14474:
14475: sub _add_to_env {
14476: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14477: if (ref($env_data) eq 'HASH') {
14478: while (my ($key,$value) = each(%$env_data)) {
14479: $idf->{$prefix.$key} = $value;
14480: $env{$prefix.$key} = $value;
14481: }
1.462 albertel 14482: }
14483: }
14484:
1.685 tempelho 14485: # --- Get the symbolic name of a problem and the url
14486: sub get_symb {
14487: my ($request,$silent) = @_;
1.726 raeburn 14488: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14489: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14490: if ($symb eq '') {
14491: if (!$silent) {
1.1071 raeburn 14492: if (ref($request)) {
14493: $request->print("Unable to handle ambiguous references:$url:.");
14494: }
1.685 tempelho 14495: return ();
14496: }
14497: }
14498: &Apache::lonenc::check_decrypt(\$symb);
14499: return ($symb);
14500: }
14501:
14502: # --------------------------------------------------------------Get annotation
14503:
14504: sub get_annotation {
14505: my ($symb,$enc) = @_;
14506:
14507: my $key = $symb;
14508: if (!$enc) {
14509: $key =
14510: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14511: }
14512: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14513: return $annotation{$key};
14514: }
14515:
14516: sub clean_symb {
1.731 raeburn 14517: my ($symb,$delete_enc) = @_;
1.685 tempelho 14518:
14519: &Apache::lonenc::check_decrypt(\$symb);
14520: my $enc = $env{'request.enc'};
1.731 raeburn 14521: if ($delete_enc) {
1.730 raeburn 14522: delete($env{'request.enc'});
14523: }
1.685 tempelho 14524:
14525: return ($symb,$enc);
14526: }
1.462 albertel 14527:
1.990 raeburn 14528: sub build_release_hashes {
14529: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14530: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14531: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14532: (ref($randomizetry) eq 'HASH'));
14533: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14534: my ($item,$name,$value) = split(/:/,$key);
14535: if ($item eq 'parameter') {
14536: if (ref($checkparms->{$name}) eq 'ARRAY') {
14537: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14538: push(@{$checkparms->{$name}},$value);
14539: }
14540: } else {
14541: push(@{$checkparms->{$name}},$value);
14542: }
14543: } elsif ($item eq 'resourcetag') {
14544: if ($name eq 'responsetype') {
14545: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14546: }
14547: } elsif ($item eq 'course') {
14548: if ($name eq 'crstype') {
14549: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14550: }
14551: }
14552: }
14553: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14554: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14555: return;
14556: }
14557:
1.1075.2.11 raeburn 14558: sub update_content_constraints {
14559: my ($cdom,$cnum,$chome,$cid) = @_;
14560: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14561: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14562: my %checkresponsetypes;
14563: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14564: my ($item,$name,$value) = split(/:/,$key);
14565: if ($item eq 'resourcetag') {
14566: if ($name eq 'responsetype') {
14567: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14568: }
14569: }
14570: }
14571: my $navmap = Apache::lonnavmaps::navmap->new();
14572: if (defined($navmap)) {
14573: my %allresponses;
14574: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14575: my %responses = $res->responseTypes();
14576: foreach my $key (keys(%responses)) {
14577: next unless(exists($checkresponsetypes{$key}));
14578: $allresponses{$key} += $responses{$key};
14579: }
14580: }
14581: foreach my $key (keys(%allresponses)) {
14582: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14583: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14584: ($reqdmajor,$reqdminor) = ($major,$minor);
14585: }
14586: }
14587: undef($navmap);
14588: }
14589: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14590: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14591: }
14592: return;
14593: }
14594:
1.1075.2.27 raeburn 14595: sub allmaps_incourse {
14596: my ($cdom,$cnum,$chome,$cid) = @_;
14597: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14598: $cid = $env{'request.course.id'};
14599: $cdom = $env{'course.'.$cid.'.domain'};
14600: $cnum = $env{'course.'.$cid.'.num'};
14601: $chome = $env{'course.'.$cid.'.home'};
14602: }
14603: my %allmaps = ();
14604: my $lastchange =
14605: &Apache::lonnet::get_coursechange($cdom,$cnum);
14606: if ($lastchange > $env{'request.course.tied'}) {
14607: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14608: unless ($ferr) {
14609: &update_content_constraints($cdom,$cnum,$chome,$cid);
14610: }
14611: }
14612: my $navmap = Apache::lonnavmaps::navmap->new();
14613: if (defined($navmap)) {
14614: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14615: $allmaps{$res->src()} = 1;
14616: }
14617: }
14618: return \%allmaps;
14619: }
14620:
1.1075.2.11 raeburn 14621: sub parse_supplemental_title {
14622: my ($title) = @_;
14623:
14624: my ($foldertitle,$renametitle);
14625: if ($title =~ /&&&/) {
14626: $title = &HTML::Entites::decode($title);
14627: }
14628: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14629: $renametitle=$4;
14630: my ($time,$uname,$udom) = ($1,$2,$3);
14631: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14632: my $name = &plainname($uname,$udom);
14633: $name = &HTML::Entities::encode($name,'"<>&\'');
14634: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14635: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14636: $name.': <br />'.$foldertitle;
14637: }
14638: if (wantarray) {
14639: return ($title,$foldertitle,$renametitle);
14640: }
14641: return $title;
14642: }
14643:
1.1075.2.43 raeburn 14644: sub recurse_supplemental {
14645: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
14646: if ($suppmap) {
14647: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
14648: if ($fatal) {
14649: $errors ++;
14650: } else {
14651: if ($#LONCAPA::map::resources > 0) {
14652: foreach my $res (@LONCAPA::map::resources) {
14653: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
14654: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 14655: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
14656: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 14657: } else {
14658: $numfiles ++;
14659: }
14660: }
14661: }
14662: }
14663: }
14664: }
14665: return ($numfiles,$errors);
14666: }
14667:
1.1075.2.18 raeburn 14668: sub symb_to_docspath {
14669: my ($symb) = @_;
14670: return unless ($symb);
14671: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14672: if ($resurl=~/\.(sequence|page)$/) {
14673: $mapurl=$resurl;
14674: } elsif ($resurl eq 'adm/navmaps') {
14675: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14676: }
14677: my $mapresobj;
14678: my $navmap = Apache::lonnavmaps::navmap->new();
14679: if (ref($navmap)) {
14680: $mapresobj = $navmap->getResourceByUrl($mapurl);
14681: }
14682: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14683: my $type=$2;
14684: my $path;
14685: if (ref($mapresobj)) {
14686: my $pcslist = $mapresobj->map_hierarchy();
14687: if ($pcslist ne '') {
14688: foreach my $pc (split(/,/,$pcslist)) {
14689: next if ($pc <= 1);
14690: my $res = $navmap->getByMapPc($pc);
14691: if (ref($res)) {
14692: my $thisurl = $res->src();
14693: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14694: my $thistitle = $res->title();
14695: $path .= '&'.
14696: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 14697: &escape($thistitle).
1.1075.2.18 raeburn 14698: ':'.$res->randompick().
14699: ':'.$res->randomout().
14700: ':'.$res->encrypted().
14701: ':'.$res->randomorder().
14702: ':'.$res->is_page();
14703: }
14704: }
14705: }
14706: $path =~ s/^\&//;
14707: my $maptitle = $mapresobj->title();
14708: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 14709: $maptitle = 'Main Content';
1.1075.2.18 raeburn 14710: }
14711: $path .= (($path ne '')? '&' : '').
14712: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 14713: &escape($maptitle).
1.1075.2.18 raeburn 14714: ':'.$mapresobj->randompick().
14715: ':'.$mapresobj->randomout().
14716: ':'.$mapresobj->encrypted().
14717: ':'.$mapresobj->randomorder().
14718: ':'.$mapresobj->is_page();
14719: } else {
14720: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14721: my $ispage = (($type eq 'page')? 1 : '');
14722: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 14723: $maptitle = 'Main Content';
1.1075.2.18 raeburn 14724: }
14725: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 14726: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 14727: }
14728: unless ($mapurl eq 'default') {
14729: $path = 'default&'.
1.1075.2.46 raeburn 14730: &escape('Main Content').
1.1075.2.18 raeburn 14731: ':::::&'.$path;
14732: }
14733: return $path;
14734: }
14735:
1.1075.2.14 raeburn 14736: sub captcha_display {
14737: my ($context,$lonhost) = @_;
14738: my ($output,$error);
14739: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
14740: if ($captcha eq 'original') {
14741: $output = &create_captcha();
14742: unless ($output) {
14743: $error = 'captcha';
14744: }
14745: } elsif ($captcha eq 'recaptcha') {
14746: $output = &create_recaptcha($pubkey);
14747: unless ($output) {
14748: $error = 'recaptcha';
14749: }
14750: }
14751: return ($output,$error);
14752: }
14753:
14754: sub captcha_response {
14755: my ($context,$lonhost) = @_;
14756: my ($captcha_chk,$captcha_error);
14757: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
14758: if ($captcha eq 'original') {
14759: ($captcha_chk,$captcha_error) = &check_captcha();
14760: } elsif ($captcha eq 'recaptcha') {
14761: $captcha_chk = &check_recaptcha($privkey);
14762: } else {
14763: $captcha_chk = 1;
14764: }
14765: return ($captcha_chk,$captcha_error);
14766: }
14767:
14768: sub get_captcha_config {
14769: my ($context,$lonhost) = @_;
14770: my ($captcha,$pubkey,$privkey,$hashtocheck);
14771: my $hostname = &Apache::lonnet::hostname($lonhost);
14772: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14773: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
14774: if ($context eq 'usercreation') {
14775: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14776: if (ref($domconfig{$context}) eq 'HASH') {
14777: $hashtocheck = $domconfig{$context}{'cancreate'};
14778: if (ref($hashtocheck) eq 'HASH') {
14779: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14780: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14781: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14782: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14783: }
14784: if ($privkey && $pubkey) {
14785: $captcha = 'recaptcha';
14786: } else {
14787: $captcha = 'original';
14788: }
14789: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14790: $captcha = 'original';
14791: }
14792: }
14793: } else {
14794: $captcha = 'captcha';
14795: }
14796: } elsif ($context eq 'login') {
14797: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14798: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14799: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14800: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
14801: if ($privkey && $pubkey) {
14802: $captcha = 'recaptcha';
14803: } else {
14804: $captcha = 'original';
14805: }
14806: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14807: $captcha = 'original';
14808: }
14809: }
14810: return ($captcha,$pubkey,$privkey);
14811: }
14812:
14813: sub create_captcha {
14814: my %captcha_params = &captcha_settings();
14815: my ($output,$maxtries,$tries) = ('',10,0);
14816: while ($tries < $maxtries) {
14817: $tries ++;
14818: my $captcha = Authen::Captcha->new (
14819: output_folder => $captcha_params{'output_dir'},
14820: data_folder => $captcha_params{'db_dir'},
14821: );
14822: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14823:
14824: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14825: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14826: &mt('Type in the letters/numbers shown below').' '.
14827: '<input type="text" size="5" name="code" value="" /><br />'.
14828: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
14829: last;
14830: }
14831: }
14832: return $output;
14833: }
14834:
14835: sub captcha_settings {
14836: my %captcha_params = (
14837: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14838: www_output_dir => "/captchaspool",
14839: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14840: numchars => '5',
14841: );
14842: return %captcha_params;
14843: }
14844:
14845: sub check_captcha {
14846: my ($captcha_chk,$captcha_error);
14847: my $code = $env{'form.code'};
14848: my $md5sum = $env{'form.crypt'};
14849: my %captcha_params = &captcha_settings();
14850: my $captcha = Authen::Captcha->new(
14851: output_folder => $captcha_params{'output_dir'},
14852: data_folder => $captcha_params{'db_dir'},
14853: );
1.1075.2.26 raeburn 14854: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 14855: my %captcha_hash = (
14856: 0 => 'Code not checked (file error)',
14857: -1 => 'Failed: code expired',
14858: -2 => 'Failed: invalid code (not in database)',
14859: -3 => 'Failed: invalid code (code does not match crypt)',
14860: );
14861: if ($captcha_chk != 1) {
14862: $captcha_error = $captcha_hash{$captcha_chk}
14863: }
14864: return ($captcha_chk,$captcha_error);
14865: }
14866:
14867: sub create_recaptcha {
14868: my ($pubkey) = @_;
1.1075.2.51 raeburn 14869: my $use_ssl;
14870: if ($ENV{'SERVER_PORT'} == 443) {
14871: $use_ssl = 1;
14872: }
1.1075.2.14 raeburn 14873: my $captcha = Captcha::reCAPTCHA->new;
14874: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1075.2.51 raeburn 14875: $captcha->get_html($pubkey,undef,$use_ssl).
1.1075.2.14 raeburn 14876: &mt('If either word is hard to read, [_1] will replace them.',
1.1075.2.39 raeburn 14877: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1075.2.14 raeburn 14878: '<br /><br />';
14879: }
14880:
14881: sub check_recaptcha {
14882: my ($privkey) = @_;
14883: my $captcha_chk;
14884: my $captcha = Captcha::reCAPTCHA->new;
14885: my $captcha_result =
14886: $captcha->check_answer(
14887: $privkey,
14888: $ENV{'REMOTE_ADDR'},
14889: $env{'form.recaptcha_challenge_field'},
14890: $env{'form.recaptcha_response_field'},
14891: );
14892: if ($captcha_result->{is_valid}) {
14893: $captcha_chk = 1;
14894: }
14895: return $captcha_chk;
14896: }
14897:
1.1075.2.56! raeburn 14898: sub cleanup_html {
! 14899: my ($incoming) = @_;
! 14900: my $outgoing;
! 14901: if ($incoming ne '') {
! 14902: $outgoing = $incoming;
! 14903: $outgoing =~ s/;/;/g;
! 14904: $outgoing =~ s/\#/#/g;
! 14905: $outgoing =~ s/\&/&/g;
! 14906: $outgoing =~ s/</</g;
! 14907: $outgoing =~ s/>/>/g;
! 14908: $outgoing =~ s/\(/(/g;
! 14909: $outgoing =~ s/\)/)/g;
! 14910: $outgoing =~ s/"/"/g;
! 14911: $outgoing =~ s/'/'/g;
! 14912: $outgoing =~ s/\$/$/g;
! 14913: $outgoing =~ s{/}{/}g;
! 14914: $outgoing =~ s/=/=/g;
! 14915: $outgoing =~ s/\\/\/g
! 14916: }
! 14917: return $outgoing;
! 14918: }
! 14919:
1.41 ng 14920: =pod
14921:
14922: =back
14923:
1.112 bowersj2 14924: =cut
1.41 ng 14925:
1.112 bowersj2 14926: 1;
14927: __END__;
1.41 ng 14928:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>