Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.55
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.55! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.54 2013/09/29 06:57:54 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
1365: <a href="$link" title="$title">$text</a>
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: =over 4
1728:
1729: =cut
1730:
1731: ###############################################################
1732: ###############################################################
1733:
1734: =pod
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;
5274: foreach my $attr (keys(%$attr_ref)) {
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.461 albertel 7265: &font_settings();
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:
7330: Inputs: none
7331:
7332: =cut
7333:
7334: sub font_settings {
7335: my $headerstring='';
1.647 www 7336: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 7337: $headerstring.=
7338: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
7339: }
7340: return $headerstring;
7341: }
7342:
1.341 albertel 7343: =pod
7344:
1.1064 raeburn 7345: =item * &print_suppression()
7346:
7347: In course context returns css which causes the body to be blank when media="print",
7348: if printout generation is unavailable for the current resource.
7349:
7350: This could be because:
7351:
7352: (a) printstartdate is in the future
7353:
7354: (b) printenddate is in the past
7355:
7356: (c) there is an active exam block with "printout"
7357: functionality blocked
7358:
7359: Users with pav, pfo or evb privileges are exempt.
7360:
7361: Inputs: none
7362:
7363: =cut
7364:
7365:
7366: sub print_suppression {
7367: my $noprint;
7368: if ($env{'request.course.id'}) {
7369: my $scope = $env{'request.course.id'};
7370: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7371: (&Apache::lonnet::allowed('pfo',$scope))) {
7372: return;
7373: }
7374: if ($env{'request.course.sec'} ne '') {
7375: $scope .= "/$env{'request.course.sec'}";
7376: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7377: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7378: return;
1.1064 raeburn 7379: }
7380: }
7381: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7382: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7383: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7384: if ($blocked) {
7385: my $checkrole = "cm./$cdom/$cnum";
7386: if ($env{'request.course.sec'} ne '') {
7387: $checkrole .= "/$env{'request.course.sec'}";
7388: }
7389: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7390: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7391: $noprint = 1;
7392: }
7393: }
7394: unless ($noprint) {
7395: my $symb = &Apache::lonnet::symbread();
7396: if ($symb ne '') {
7397: my $navmap = Apache::lonnavmaps::navmap->new();
7398: if (ref($navmap)) {
7399: my $res = $navmap->getBySymb($symb);
7400: if (ref($res)) {
7401: if (!$res->resprintable()) {
7402: $noprint = 1;
7403: }
7404: }
7405: }
7406: }
7407: }
7408: if ($noprint) {
7409: return <<"ENDSTYLE";
7410: <style type="text/css" media="print">
7411: body { display:none }
7412: </style>
7413: ENDSTYLE
7414: }
7415: }
7416: return;
7417: }
7418:
7419: =pod
7420:
1.341 albertel 7421: =item * &xml_begin()
7422:
7423: Returns the needed doctype and <html>
7424:
7425: Inputs: none
7426:
7427: =cut
7428:
7429: sub xml_begin {
7430: my $output='';
7431:
7432: if ($env{'browser.mathml'}) {
7433: $output='<?xml version="1.0"?>'
7434: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7435: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7436:
7437: # .'<!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">] >'
7438: .'<!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">'
7439: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7440: .'xmlns="http://www.w3.org/1999/xhtml">';
7441: } else {
1.849 bisitz 7442: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
7443: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 7444: }
7445: return $output;
7446: }
1.340 albertel 7447:
7448: =pod
7449:
1.306 albertel 7450: =item * &start_page()
7451:
7452: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7453:
1.648 raeburn 7454: Inputs:
7455:
7456: =over 4
7457:
7458: $title - optional title for the page
7459:
7460: $head_extra - optional extra HTML to incude inside the <head>
7461:
7462: $args - additional optional args supported are:
7463:
7464: =over 8
7465:
7466: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7467: arg on
1.814 bisitz 7468: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7469: add_entries -> additional attributes to add to the <body>
7470: domain -> force to color decorate a page for a
1.317 albertel 7471: specific domain
1.648 raeburn 7472: function -> force usage of a specific rolish color
1.317 albertel 7473: scheme
1.648 raeburn 7474: redirect -> see &headtag()
7475: bgcolor -> override the default page bg color
7476: js_ready -> return a string ready for being used in
1.317 albertel 7477: a javascript writeln
1.648 raeburn 7478: html_encode -> return a string ready for being used in
1.320 albertel 7479: a html attribute
1.648 raeburn 7480: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7481: $forcereg arg
1.648 raeburn 7482: frameset -> if true will start with a <frameset>
1.330 albertel 7483: rather than <body>
1.648 raeburn 7484: skip_phases -> hash ref of
1.338 albertel 7485: head -> skip the <html><head> generation
7486: body -> skip all <body> generation
1.1075.2.12 raeburn 7487: no_inline_link -> if true and in remote mode, don't show the
7488: 'Switch To Inline Menu' link
1.648 raeburn 7489: no_auto_mt_title -> prevent &mt()ing the title arg
7490: inherit_jsmath -> when creating popup window in a page,
7491: should it have jsmath forced on by the
7492: current page
1.867 kalberla 7493: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7494: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7495: group -> includes the current group, if page is for a
7496: specific group
1.361 albertel 7497:
1.648 raeburn 7498: =back
1.460 albertel 7499:
1.648 raeburn 7500: =back
1.562 albertel 7501:
1.306 albertel 7502: =cut
7503:
7504: sub start_page {
1.309 albertel 7505: my ($title,$head_extra,$args) = @_;
1.318 albertel 7506: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7507:
1.315 albertel 7508: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7509: my ($result,@advtools);
1.964 droeschl 7510:
1.338 albertel 7511: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7512: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7513: }
7514:
7515: if (! exists($args->{'skip_phases'}{'body'}) ) {
7516: if ($args->{'frameset'}) {
7517: my $attr_string = &make_attr_string($args->{'force_register'},
7518: $args->{'add_entries'});
7519: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7520: } else {
7521: $result .=
7522: &bodytag($title,
7523: $args->{'function'}, $args->{'add_entries'},
7524: $args->{'only_body'}, $args->{'domain'},
7525: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7526: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7527: $args, \@advtools);
1.831 bisitz 7528: }
1.330 albertel 7529: }
1.338 albertel 7530:
1.315 albertel 7531: if ($args->{'js_ready'}) {
1.713 kaisler 7532: $result = &js_ready($result);
1.315 albertel 7533: }
1.320 albertel 7534: if ($args->{'html_encode'}) {
1.713 kaisler 7535: $result = &html_encode($result);
7536: }
7537:
1.813 bisitz 7538: # Preparation for new and consistent functionlist at top of screen
7539: # if ($args->{'functionlist'}) {
7540: # $result .= &build_functionlist();
7541: #}
7542:
1.964 droeschl 7543: # Don't add anything more if only_body wanted or in const space
7544: return $result if $args->{'only_body'}
7545: || $env{'request.state'} eq 'construct';
1.813 bisitz 7546:
7547: #Breadcrumbs
1.758 kaisler 7548: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7549: &Apache::lonhtmlcommon::clear_breadcrumbs();
7550: #if any br links exists, add them to the breadcrumbs
7551: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7552: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7553: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7554: }
7555: }
1.1075.2.19 raeburn 7556: # if @advtools array contains items add then to the breadcrumbs
7557: if (@advtools > 0) {
7558: &Apache::lonmenu::advtools_crumbs(@advtools);
7559: }
1.758 kaisler 7560:
7561: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7562: if(exists($args->{'bread_crumbs_component'})){
7563: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7564: }else{
7565: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7566: }
1.1075.2.24 raeburn 7567: } elsif (($env{'environment.remote'} eq 'on') &&
7568: ($env{'form.inhibitmenu'} ne 'yes') &&
7569: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7570: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7571: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7572: }
1.315 albertel 7573: return $result;
1.306 albertel 7574: }
7575:
7576: sub end_page {
1.315 albertel 7577: my ($args) = @_;
7578: $env{'internal.end_page'}++;
1.330 albertel 7579: my $result;
1.335 albertel 7580: if ($args->{'discussion'}) {
7581: my ($target,$parser);
7582: if (ref($args->{'discussion'})) {
7583: ($target,$parser) =($args->{'discussion'}{'target'},
7584: $args->{'discussion'}{'parser'});
7585: }
7586: $result .= &Apache::lonxml::xmlend($target,$parser);
7587: }
1.330 albertel 7588: if ($args->{'frameset'}) {
7589: $result .= '</frameset>';
7590: } else {
1.635 raeburn 7591: $result .= &endbodytag($args);
1.330 albertel 7592: }
1.1075.2.6 raeburn 7593: unless ($args->{'notbody'}) {
7594: $result .= "\n</html>";
7595: }
1.330 albertel 7596:
1.315 albertel 7597: if ($args->{'js_ready'}) {
1.317 albertel 7598: $result = &js_ready($result);
1.315 albertel 7599: }
1.335 albertel 7600:
1.320 albertel 7601: if ($args->{'html_encode'}) {
7602: $result = &html_encode($result);
7603: }
1.335 albertel 7604:
1.315 albertel 7605: return $result;
7606: }
7607:
1.1034 www 7608: sub wishlist_window {
7609: return(<<'ENDWISHLIST');
1.1046 raeburn 7610: <script type="text/javascript">
1.1034 www 7611: // <![CDATA[
7612: // <!-- BEGIN LON-CAPA Internal
7613: function set_wishlistlink(title, path) {
7614: if (!title) {
7615: title = document.title;
7616: title = title.replace(/^LON-CAPA /,'');
7617: }
7618: if (!path) {
7619: path = location.pathname;
7620: }
7621: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7622: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7623: }
7624: // END LON-CAPA Internal -->
7625: // ]]>
7626: </script>
7627: ENDWISHLIST
7628: }
7629:
1.1030 www 7630: sub modal_window {
7631: return(<<'ENDMODAL');
1.1046 raeburn 7632: <script type="text/javascript">
1.1030 www 7633: // <![CDATA[
7634: // <!-- BEGIN LON-CAPA Internal
7635: var modalWindow = {
7636: parent:"body",
7637: windowId:null,
7638: content:null,
7639: width:null,
7640: height:null,
7641: close:function()
7642: {
7643: $(".LCmodal-window").remove();
7644: $(".LCmodal-overlay").remove();
7645: },
7646: open:function()
7647: {
7648: var modal = "";
7649: modal += "<div class=\"LCmodal-overlay\"></div>";
7650: 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;\">";
7651: modal += this.content;
7652: modal += "</div>";
7653:
7654: $(this.parent).append(modal);
7655:
7656: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7657: $(".LCclose-window").click(function(){modalWindow.close();});
7658: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7659: }
7660: };
1.1075.2.42 raeburn 7661: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7662: {
7663: modalWindow.windowId = "myModal";
7664: modalWindow.width = width;
7665: modalWindow.height = height;
1.1075.2.42 raeburn 7666: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7667: modalWindow.open();
7668: };
7669: // END LON-CAPA Internal -->
7670: // ]]>
7671: </script>
7672: ENDMODAL
7673: }
7674:
7675: sub modal_link {
1.1075.2.42 raeburn 7676: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7677: unless ($width) { $width=480; }
7678: unless ($height) { $height=400; }
1.1031 www 7679: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 7680: unless ($transparency) { $transparency='true'; }
7681:
1.1074 raeburn 7682: my $target_attr;
7683: if (defined($target)) {
7684: $target_attr = 'target="'.$target.'"';
7685: }
7686: return <<"ENDLINK";
1.1075.2.42 raeburn 7687: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7688: $linktext</a>
7689: ENDLINK
1.1030 www 7690: }
7691:
1.1032 www 7692: sub modal_adhoc_script {
7693: my ($funcname,$width,$height,$content)=@_;
7694: return (<<ENDADHOC);
1.1046 raeburn 7695: <script type="text/javascript">
1.1032 www 7696: // <![CDATA[
7697: var $funcname = function()
7698: {
7699: modalWindow.windowId = "myModal";
7700: modalWindow.width = $width;
7701: modalWindow.height = $height;
7702: modalWindow.content = '$content';
7703: modalWindow.open();
7704: };
7705: // ]]>
7706: </script>
7707: ENDADHOC
7708: }
7709:
1.1041 www 7710: sub modal_adhoc_inner {
7711: my ($funcname,$width,$height,$content)=@_;
7712: my $innerwidth=$width-20;
7713: $content=&js_ready(
1.1042 www 7714: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 7715: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7716: $content.
1.1041 www 7717: &end_scrollbox().
1.1075.2.42 raeburn 7718: &end_page()
1.1041 www 7719: );
7720: return &modal_adhoc_script($funcname,$width,$height,$content);
7721: }
7722:
7723: sub modal_adhoc_window {
7724: my ($funcname,$width,$height,$content,$linktext)=@_;
7725: return &modal_adhoc_inner($funcname,$width,$height,$content).
7726: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7727: }
7728:
7729: sub modal_adhoc_launch {
7730: my ($funcname,$width,$height,$content)=@_;
7731: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7732: <script type="text/javascript">
7733: // <![CDATA[
7734: $funcname();
7735: // ]]>
7736: </script>
7737: ENDLAUNCH
7738: }
7739:
7740: sub modal_adhoc_close {
7741: return (<<ENDCLOSE);
7742: <script type="text/javascript">
7743: // <![CDATA[
7744: modalWindow.close();
7745: // ]]>
7746: </script>
7747: ENDCLOSE
7748: }
7749:
1.1038 www 7750: sub togglebox_script {
7751: return(<<ENDTOGGLE);
7752: <script type="text/javascript">
7753: // <![CDATA[
7754: function LCtoggleDisplay(id,hidetext,showtext) {
7755: link = document.getElementById(id + "link").childNodes[0];
7756: with (document.getElementById(id).style) {
7757: if (display == "none" ) {
7758: display = "inline";
7759: link.nodeValue = hidetext;
7760: } else {
7761: display = "none";
7762: link.nodeValue = showtext;
7763: }
7764: }
7765: }
7766: // ]]>
7767: </script>
7768: ENDTOGGLE
7769: }
7770:
1.1039 www 7771: sub start_togglebox {
7772: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7773: unless ($heading) { $heading=''; } else { $heading.=' '; }
7774: unless ($showtext) { $showtext=&mt('show'); }
7775: unless ($hidetext) { $hidetext=&mt('hide'); }
7776: unless ($headerbg) { $headerbg='#FFFFFF'; }
7777: return &start_data_table().
7778: &start_data_table_header_row().
7779: '<td bgcolor="'.$headerbg.'">'.$heading.
7780: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7781: $showtext.'\')">'.$showtext.'</a>]</td>'.
7782: &end_data_table_header_row().
7783: '<tr id="'.$id.'" style="display:none""><td>';
7784: }
7785:
7786: sub end_togglebox {
7787: return '</td></tr>'.&end_data_table();
7788: }
7789:
1.1041 www 7790: sub LCprogressbar_script {
1.1045 www 7791: my ($id)=@_;
1.1041 www 7792: return(<<ENDPROGRESS);
7793: <script type="text/javascript">
7794: // <![CDATA[
1.1045 www 7795: \$('#progressbar$id').progressbar({
1.1041 www 7796: value: 0,
7797: change: function(event, ui) {
7798: var newVal = \$(this).progressbar('option', 'value');
7799: \$('.pblabel', this).text(LCprogressTxt);
7800: }
7801: });
7802: // ]]>
7803: </script>
7804: ENDPROGRESS
7805: }
7806:
7807: sub LCprogressbarUpdate_script {
7808: return(<<ENDPROGRESSUPDATE);
7809: <style type="text/css">
7810: .ui-progressbar { position:relative; }
7811: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7812: </style>
7813: <script type="text/javascript">
7814: // <![CDATA[
1.1045 www 7815: var LCprogressTxt='---';
7816:
7817: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7818: LCprogressTxt=progresstext;
1.1045 www 7819: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7820: }
7821: // ]]>
7822: </script>
7823: ENDPROGRESSUPDATE
7824: }
7825:
1.1042 www 7826: my $LClastpercent;
1.1045 www 7827: my $LCidcnt;
7828: my $LCcurrentid;
1.1042 www 7829:
1.1041 www 7830: sub LCprogressbar {
1.1042 www 7831: my ($r)=(@_);
7832: $LClastpercent=0;
1.1045 www 7833: $LCidcnt++;
7834: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7835: my $starting=&mt('Starting');
7836: my $content=(<<ENDPROGBAR);
1.1045 www 7837: <div id="progressbar$LCcurrentid">
1.1041 www 7838: <span class="pblabel">$starting</span>
7839: </div>
7840: ENDPROGBAR
1.1045 www 7841: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7842: }
7843:
7844: sub LCprogressbarUpdate {
1.1042 www 7845: my ($r,$val,$text)=@_;
7846: unless ($val) {
7847: if ($LClastpercent) {
7848: $val=$LClastpercent;
7849: } else {
7850: $val=0;
7851: }
7852: }
1.1041 www 7853: if ($val<0) { $val=0; }
7854: if ($val>100) { $val=0; }
1.1042 www 7855: $LClastpercent=$val;
1.1041 www 7856: unless ($text) { $text=$val.'%'; }
7857: $text=&js_ready($text);
1.1044 www 7858: &r_print($r,<<ENDUPDATE);
1.1041 www 7859: <script type="text/javascript">
7860: // <![CDATA[
1.1045 www 7861: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7862: // ]]>
7863: </script>
7864: ENDUPDATE
1.1035 www 7865: }
7866:
1.1042 www 7867: sub LCprogressbarClose {
7868: my ($r)=@_;
7869: $LClastpercent=0;
1.1044 www 7870: &r_print($r,<<ENDCLOSE);
1.1042 www 7871: <script type="text/javascript">
7872: // <![CDATA[
1.1045 www 7873: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7874: // ]]>
7875: </script>
7876: ENDCLOSE
1.1044 www 7877: }
7878:
7879: sub r_print {
7880: my ($r,$to_print)=@_;
7881: if ($r) {
7882: $r->print($to_print);
7883: $r->rflush();
7884: } else {
7885: print($to_print);
7886: }
1.1042 www 7887: }
7888:
1.320 albertel 7889: sub html_encode {
7890: my ($result) = @_;
7891:
1.322 albertel 7892: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7893:
7894: return $result;
7895: }
1.1044 www 7896:
1.317 albertel 7897: sub js_ready {
7898: my ($result) = @_;
7899:
1.323 albertel 7900: $result =~ s/[\n\r]/ /xmsg;
7901: $result =~ s/\\/\\\\/xmsg;
7902: $result =~ s/'/\\'/xmsg;
1.372 albertel 7903: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7904:
7905: return $result;
7906: }
7907:
1.315 albertel 7908: sub validate_page {
7909: if ( exists($env{'internal.start_page'})
1.316 albertel 7910: && $env{'internal.start_page'} > 1) {
7911: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7912: $env{'internal.start_page'}.' '.
1.316 albertel 7913: $ENV{'request.filename'});
1.315 albertel 7914: }
7915: if ( exists($env{'internal.end_page'})
1.316 albertel 7916: && $env{'internal.end_page'} > 1) {
7917: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7918: $env{'internal.end_page'}.' '.
1.316 albertel 7919: $env{'request.filename'});
1.315 albertel 7920: }
7921: if ( exists($env{'internal.start_page'})
7922: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7923: &Apache::lonnet::logthis('start_page called without end_page '.
7924: $env{'request.filename'});
1.315 albertel 7925: }
7926: if ( ! exists($env{'internal.start_page'})
7927: && exists($env{'internal.end_page'})) {
1.316 albertel 7928: &Apache::lonnet::logthis('end_page called without start_page'.
7929: $env{'request.filename'});
1.315 albertel 7930: }
1.306 albertel 7931: }
1.315 albertel 7932:
1.996 www 7933:
7934: sub start_scrollbox {
1.1075.2.42 raeburn 7935: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready)=@_;
1.998 raeburn 7936: unless ($outerwidth) { $outerwidth='520px'; }
7937: unless ($width) { $width='500px'; }
7938: unless ($height) { $height='200px'; }
1.1075 raeburn 7939: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7940: if ($id ne '') {
1.1075.2.42 raeburn 7941: $table_id = ' id="table_'.$id.'"';
7942: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7943: }
1.1075 raeburn 7944: if ($bgcolor ne '') {
7945: $tdcol = "background-color: $bgcolor;";
7946: }
1.1075.2.42 raeburn 7947: my $nicescroll_js;
7948: if ($env{'browser.mobile'}) {
7949: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
7950: }
1.1075 raeburn 7951: return <<"END";
1.1075.2.42 raeburn 7952: $nicescroll_js
7953:
7954: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
7955: <div style="overflow:auto; width:$width; height: $height;"$div_id>
1.1075 raeburn 7956: END
1.996 www 7957: }
7958:
7959: sub end_scrollbox {
1.1036 www 7960: return '</div></td></tr></table>';
1.996 www 7961: }
7962:
1.1075.2.42 raeburn 7963: sub nicescroll_javascript {
7964: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
7965: my %options;
7966: if (ref($cursor) eq 'HASH') {
7967: %options = %{$cursor};
7968: }
7969: unless ($options{'railalign'} =~ /^left|right$/) {
7970: $options{'railalign'} = 'left';
7971: }
7972: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
7973: my $function = &get_users_function();
7974: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
7975: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
7976: $options{'cursorcolor'} = '#00F';
7977: }
7978: }
7979: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
7980: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
7981: $options{'cursoropacity'}='1.0';
7982: }
7983: } else {
7984: $options{'cursoropacity'}='1.0';
7985: }
7986: if ($options{'cursorfixedheight'} eq 'none') {
7987: delete($options{'cursorfixedheight'});
7988: } else {
7989: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
7990: }
7991: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
7992: delete($options{'railoffset'});
7993: }
7994: my @niceoptions;
7995: while (my($key,$value) = each(%options)) {
7996: if ($value =~ /^\{.+\}$/) {
7997: push(@niceoptions,$key.':'.$value);
7998: } else {
7999: push(@niceoptions,$key.':"'.$value.'"');
8000: }
8001: }
8002: my $nicescroll_js = '
8003: $(document).ready(
8004: function() {
8005: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8006: }
8007: );
8008: ';
8009: if ($framecheck) {
8010: $nicescroll_js .= '
8011: function expand_div(caller) {
8012: if (top === self) {
8013: document.getElementById("'.$id.'").style.width = "auto";
8014: document.getElementById("'.$id.'").style.height = "auto";
8015: } else {
8016: try {
8017: if (parent.frames) {
8018: if (parent.frames.length > 1) {
8019: var framesrc = parent.frames[1].location.href;
8020: var currsrc = framesrc.replace(/\#.*$/,"");
8021: if ((caller == "search") || (currsrc == "'.$location.'")) {
8022: document.getElementById("'.$id.'").style.width = "auto";
8023: document.getElementById("'.$id.'").style.height = "auto";
8024: }
8025: }
8026: }
8027: } catch (e) {
8028: return;
8029: }
8030: }
8031: return;
8032: }
8033: ';
8034: }
8035: if ($needjsready) {
8036: $nicescroll_js = '
8037: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8038: } else {
8039: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8040: }
8041: return $nicescroll_js;
8042: }
8043:
1.318 albertel 8044: sub simple_error_page {
1.1075.2.49 raeburn 8045: my ($r,$title,$msg,$args) = @_;
8046: if (ref($args) eq 'HASH') {
8047: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8048: } else {
8049: $msg = &mt($msg);
8050: }
8051:
1.318 albertel 8052: my $page =
8053: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8054: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8055: &Apache::loncommon::end_page();
8056: if (ref($r)) {
8057: $r->print($page);
1.327 albertel 8058: return;
1.318 albertel 8059: }
8060: return $page;
8061: }
1.347 albertel 8062:
8063: {
1.610 albertel 8064: my @row_count;
1.961 onken 8065:
8066: sub start_data_table_count {
8067: unshift(@row_count, 0);
8068: return;
8069: }
8070:
8071: sub end_data_table_count {
8072: shift(@row_count);
8073: return;
8074: }
8075:
1.347 albertel 8076: sub start_data_table {
1.1018 raeburn 8077: my ($add_class,$id) = @_;
1.422 albertel 8078: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8079: my $table_id;
8080: if (defined($id)) {
8081: $table_id = ' id="'.$id.'"';
8082: }
1.961 onken 8083: &start_data_table_count();
1.1018 raeburn 8084: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8085: }
8086:
8087: sub end_data_table {
1.961 onken 8088: &end_data_table_count();
1.389 albertel 8089: return '</table>'."\n";;
1.347 albertel 8090: }
8091:
8092: sub start_data_table_row {
1.974 wenzelju 8093: my ($add_class, $id) = @_;
1.610 albertel 8094: $row_count[0]++;
8095: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8096: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8097: $id = (' id="'.$id.'"') unless ($id eq '');
8098: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8099: }
1.471 banghart 8100:
8101: sub continue_data_table_row {
1.974 wenzelju 8102: my ($add_class, $id) = @_;
1.610 albertel 8103: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8104: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8105: $id = (' id="'.$id.'"') unless ($id eq '');
8106: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8107: }
1.347 albertel 8108:
8109: sub end_data_table_row {
1.389 albertel 8110: return '</tr>'."\n";;
1.347 albertel 8111: }
1.367 www 8112:
1.421 albertel 8113: sub start_data_table_empty_row {
1.707 bisitz 8114: # $row_count[0]++;
1.421 albertel 8115: return '<tr class="LC_empty_row" >'."\n";;
8116: }
8117:
8118: sub end_data_table_empty_row {
8119: return '</tr>'."\n";;
8120: }
8121:
1.367 www 8122: sub start_data_table_header_row {
1.389 albertel 8123: return '<tr class="LC_header_row">'."\n";;
1.367 www 8124: }
8125:
8126: sub end_data_table_header_row {
1.389 albertel 8127: return '</tr>'."\n";;
1.367 www 8128: }
1.890 droeschl 8129:
8130: sub data_table_caption {
8131: my $caption = shift;
8132: return "<caption class=\"LC_caption\">$caption</caption>";
8133: }
1.347 albertel 8134: }
8135:
1.548 albertel 8136: =pod
8137:
8138: =item * &inhibit_menu_check($arg)
8139:
8140: Checks for a inhibitmenu state and generates output to preserve it
8141:
8142: Inputs: $arg - can be any of
8143: - undef - in which case the return value is a string
8144: to add into arguments list of a uri
8145: - 'input' - in which case the return value is a HTML
8146: <form> <input> field of type hidden to
8147: preserve the value
8148: - a url - in which case the return value is the url with
8149: the neccesary cgi args added to preserve the
8150: inhibitmenu state
8151: - a ref to a url - no return value, but the string is
8152: updated to include the neccessary cgi
8153: args to preserve the inhibitmenu state
8154:
8155: =cut
8156:
8157: sub inhibit_menu_check {
8158: my ($arg) = @_;
8159: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8160: if ($arg eq 'input') {
8161: if ($env{'form.inhibitmenu'}) {
8162: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8163: } else {
8164: return
8165: }
8166: }
8167: if ($env{'form.inhibitmenu'}) {
8168: if (ref($arg)) {
8169: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8170: } elsif ($arg eq '') {
8171: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8172: } else {
8173: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8174: }
8175: }
8176: if (!ref($arg)) {
8177: return $arg;
8178: }
8179: }
8180:
1.251 albertel 8181: ###############################################
1.182 matthew 8182:
8183: =pod
8184:
1.549 albertel 8185: =back
8186:
8187: =head1 User Information Routines
8188:
8189: =over 4
8190:
1.405 albertel 8191: =item * &get_users_function()
1.182 matthew 8192:
8193: Used by &bodytag to determine the current users primary role.
8194: Returns either 'student','coordinator','admin', or 'author'.
8195:
8196: =cut
8197:
8198: ###############################################
8199: sub get_users_function {
1.815 tempelho 8200: my $function = 'norole';
1.818 tempelho 8201: if ($env{'request.role'}=~/^(st)/) {
8202: $function='student';
8203: }
1.907 raeburn 8204: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8205: $function='coordinator';
8206: }
1.258 albertel 8207: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8208: $function='admin';
8209: }
1.826 bisitz 8210: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8211: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8212: $function='author';
8213: }
8214: return $function;
1.54 www 8215: }
1.99 www 8216:
8217: ###############################################
8218:
1.233 raeburn 8219: =pod
8220:
1.821 raeburn 8221: =item * &show_course()
8222:
8223: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8224: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8225:
8226: Inputs:
8227: None
8228:
8229: Outputs:
8230: Scalar: 1 if 'Course' to be used, 0 otherwise.
8231:
8232: =cut
8233:
8234: ###############################################
8235: sub show_course {
8236: my $course = !$env{'user.adv'};
8237: if (!$env{'user.adv'}) {
8238: foreach my $env (keys(%env)) {
8239: next if ($env !~ m/^user\.priv\./);
8240: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8241: $course = 0;
8242: last;
8243: }
8244: }
8245: }
8246: return $course;
8247: }
8248:
8249: ###############################################
8250:
8251: =pod
8252:
1.542 raeburn 8253: =item * &check_user_status()
1.274 raeburn 8254:
8255: Determines current status of supplied role for a
8256: specific user. Roles can be active, previous or future.
8257:
8258: Inputs:
8259: user's domain, user's username, course's domain,
1.375 raeburn 8260: course's number, optional section ID.
1.274 raeburn 8261:
8262: Outputs:
8263: role status: active, previous or future.
8264:
8265: =cut
8266:
8267: sub check_user_status {
1.412 raeburn 8268: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8269: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8270: my @uroles = keys %userinfo;
8271: my $srchstr;
8272: my $active_chk = 'none';
1.412 raeburn 8273: my $now = time;
1.274 raeburn 8274: if (@uroles > 0) {
1.908 raeburn 8275: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8276: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8277: } else {
1.412 raeburn 8278: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8279: }
8280: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8281: my $role_end = 0;
8282: my $role_start = 0;
8283: $active_chk = 'active';
1.412 raeburn 8284: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8285: $role_end = $1;
8286: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8287: $role_start = $1;
1.274 raeburn 8288: }
8289: }
8290: if ($role_start > 0) {
1.412 raeburn 8291: if ($now < $role_start) {
1.274 raeburn 8292: $active_chk = 'future';
8293: }
8294: }
8295: if ($role_end > 0) {
1.412 raeburn 8296: if ($now > $role_end) {
1.274 raeburn 8297: $active_chk = 'previous';
8298: }
8299: }
8300: }
8301: }
8302: return $active_chk;
8303: }
8304:
8305: ###############################################
8306:
8307: =pod
8308:
1.405 albertel 8309: =item * &get_sections()
1.233 raeburn 8310:
8311: Determines all the sections for a course including
8312: sections with students and sections containing other roles.
1.419 raeburn 8313: Incoming parameters:
8314:
8315: 1. domain
8316: 2. course number
8317: 3. reference to array containing roles for which sections should
8318: be gathered (optional).
8319: 4. reference to array containing status types for which sections
8320: should be gathered (optional).
8321:
8322: If the third argument is undefined, sections are gathered for any role.
8323: If the fourth argument is undefined, sections are gathered for any status.
8324: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8325:
1.374 raeburn 8326: Returns section hash (keys are section IDs, values are
8327: number of users in each section), subject to the
1.419 raeburn 8328: optional roles filter, optional status filter
1.233 raeburn 8329:
8330: =cut
8331:
8332: ###############################################
8333: sub get_sections {
1.419 raeburn 8334: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8335: if (!defined($cdom) || !defined($cnum)) {
8336: my $cid = $env{'request.course.id'};
8337:
8338: return if (!defined($cid));
8339:
8340: $cdom = $env{'course.'.$cid.'.domain'};
8341: $cnum = $env{'course.'.$cid.'.num'};
8342: }
8343:
8344: my %sectioncount;
1.419 raeburn 8345: my $now = time;
1.240 albertel 8346:
1.1075.2.33 raeburn 8347: my $check_students = 1;
8348: my $only_students = 0;
8349: if (ref($possible_roles) eq 'ARRAY') {
8350: if (grep(/^st$/,@{$possible_roles})) {
8351: if (@{$possible_roles} == 1) {
8352: $only_students = 1;
8353: }
8354: } else {
8355: $check_students = 0;
8356: }
8357: }
8358:
8359: if ($check_students) {
1.276 albertel 8360: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8361: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8362: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8363: my $start_index = &Apache::loncoursedata::CL_START();
8364: my $end_index = &Apache::loncoursedata::CL_END();
8365: my $status;
1.366 albertel 8366: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8367: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8368: $data->[$status_index],
8369: $data->[$start_index],
8370: $data->[$end_index]);
8371: if ($stu_status eq 'Active') {
8372: $status = 'active';
8373: } elsif ($end < $now) {
8374: $status = 'previous';
8375: } elsif ($start > $now) {
8376: $status = 'future';
8377: }
8378: if ($section ne '-1' && $section !~ /^\s*$/) {
8379: if ((!defined($possible_status)) || (($status ne '') &&
8380: (grep/^\Q$status\E$/,@{$possible_status}))) {
8381: $sectioncount{$section}++;
8382: }
1.240 albertel 8383: }
8384: }
8385: }
1.1075.2.33 raeburn 8386: if ($only_students) {
8387: return %sectioncount;
8388: }
1.240 albertel 8389: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8390: foreach my $user (sort(keys(%courseroles))) {
8391: if ($user !~ /^(\w{2})/) { next; }
8392: my ($role) = ($user =~ /^(\w{2})/);
8393: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8394: my ($section,$status);
1.240 albertel 8395: if ($role eq 'cr' &&
8396: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8397: $section=$1;
8398: }
8399: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8400: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8401: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8402: if ($end == -1 && $start == -1) {
8403: next; #deleted role
8404: }
8405: if (!defined($possible_status)) {
8406: $sectioncount{$section}++;
8407: } else {
8408: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8409: $status = 'active';
8410: } elsif ($end < $now) {
8411: $status = 'future';
8412: } elsif ($start > $now) {
8413: $status = 'previous';
8414: }
8415: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8416: $sectioncount{$section}++;
8417: }
8418: }
1.233 raeburn 8419: }
1.366 albertel 8420: return %sectioncount;
1.233 raeburn 8421: }
8422:
1.274 raeburn 8423: ###############################################
1.294 raeburn 8424:
8425: =pod
1.405 albertel 8426:
8427: =item * &get_course_users()
8428:
1.275 raeburn 8429: Retrieves usernames:domains for users in the specified course
8430: with specific role(s), and access status.
8431:
8432: Incoming parameters:
1.277 albertel 8433: 1. course domain
8434: 2. course number
8435: 3. access status: users must have - either active,
1.275 raeburn 8436: previous, future, or all.
1.277 albertel 8437: 4. reference to array of permissible roles
1.288 raeburn 8438: 5. reference to array of section restrictions (optional)
8439: 6. reference to results object (hash of hashes).
8440: 7. reference to optional userdata hash
1.609 raeburn 8441: 8. reference to optional statushash
1.630 raeburn 8442: 9. flag if privileged users (except those set to unhide in
8443: course settings) should be excluded
1.609 raeburn 8444: Keys of top level results hash are roles.
1.275 raeburn 8445: Keys of inner hashes are username:domain, with
8446: values set to access type.
1.288 raeburn 8447: Optional userdata hash returns an array with arguments in the
8448: same order as loncoursedata::get_classlist() for student data.
8449:
1.609 raeburn 8450: Optional statushash returns
8451:
1.288 raeburn 8452: Entries for end, start, section and status are blank because
8453: of the possibility of multiple values for non-student roles.
8454:
1.275 raeburn 8455: =cut
1.405 albertel 8456:
1.275 raeburn 8457: ###############################################
1.405 albertel 8458:
1.275 raeburn 8459: sub get_course_users {
1.630 raeburn 8460: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8461: my %idx = ();
1.419 raeburn 8462: my %seclists;
1.288 raeburn 8463:
8464: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8465: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8466: $idx{end} = &Apache::loncoursedata::CL_END();
8467: $idx{start} = &Apache::loncoursedata::CL_START();
8468: $idx{id} = &Apache::loncoursedata::CL_ID();
8469: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8470: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8471: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8472:
1.290 albertel 8473: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8474: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8475: my $now = time;
1.277 albertel 8476: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8477: my $match = 0;
1.412 raeburn 8478: my $secmatch = 0;
1.419 raeburn 8479: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8480: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8481: if ($section eq '') {
8482: $section = 'none';
8483: }
1.291 albertel 8484: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8485: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8486: $secmatch = 1;
8487: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8488: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8489: $secmatch = 1;
8490: }
8491: } else {
1.419 raeburn 8492: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8493: $secmatch = 1;
8494: }
1.290 albertel 8495: }
1.412 raeburn 8496: if (!$secmatch) {
8497: next;
8498: }
1.419 raeburn 8499: }
1.275 raeburn 8500: if (defined($$types{'active'})) {
1.288 raeburn 8501: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8502: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8503: $match = 1;
1.275 raeburn 8504: }
8505: }
8506: if (defined($$types{'previous'})) {
1.609 raeburn 8507: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8508: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8509: $match = 1;
1.275 raeburn 8510: }
8511: }
8512: if (defined($$types{'future'})) {
1.609 raeburn 8513: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8514: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8515: $match = 1;
1.275 raeburn 8516: }
8517: }
1.609 raeburn 8518: if ($match) {
8519: push(@{$seclists{$student}},$section);
8520: if (ref($userdata) eq 'HASH') {
8521: $$userdata{$student} = $$classlist{$student};
8522: }
8523: if (ref($statushash) eq 'HASH') {
8524: $statushash->{$student}{'st'}{$section} = $status;
8525: }
1.288 raeburn 8526: }
1.275 raeburn 8527: }
8528: }
1.412 raeburn 8529: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8530: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8531: my $now = time;
1.609 raeburn 8532: my %displaystatus = ( previous => 'Expired',
8533: active => 'Active',
8534: future => 'Future',
8535: );
1.1075.2.36 raeburn 8536: my (%nothide,@possdoms);
1.630 raeburn 8537: if ($hidepriv) {
8538: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8539: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8540: if ($user !~ /:/) {
8541: $nothide{join(':',split(/[\@]/,$user))}=1;
8542: } else {
8543: $nothide{$user} = 1;
8544: }
8545: }
1.1075.2.36 raeburn 8546: my @possdoms = ($cdom);
8547: if ($coursehash{'checkforpriv'}) {
8548: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8549: }
1.630 raeburn 8550: }
1.439 raeburn 8551: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8552: my $match = 0;
1.412 raeburn 8553: my $secmatch = 0;
1.439 raeburn 8554: my $status;
1.412 raeburn 8555: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8556: $user =~ s/:$//;
1.439 raeburn 8557: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8558: if ($end == -1 || $start == -1) {
8559: next;
8560: }
8561: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8562: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8563: my ($uname,$udom) = split(/:/,$user);
8564: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8565: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8566: $secmatch = 1;
8567: } elsif ($usec eq '') {
1.420 albertel 8568: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8569: $secmatch = 1;
8570: }
8571: } else {
8572: if (grep(/^\Q$usec\E$/,@{$sections})) {
8573: $secmatch = 1;
8574: }
8575: }
8576: if (!$secmatch) {
8577: next;
8578: }
1.288 raeburn 8579: }
1.419 raeburn 8580: if ($usec eq '') {
8581: $usec = 'none';
8582: }
1.275 raeburn 8583: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8584: if ($hidepriv) {
1.1075.2.36 raeburn 8585: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8586: (!$nothide{$uname.':'.$udom})) {
8587: next;
8588: }
8589: }
1.503 raeburn 8590: if ($end > 0 && $end < $now) {
1.439 raeburn 8591: $status = 'previous';
8592: } elsif ($start > $now) {
8593: $status = 'future';
8594: } else {
8595: $status = 'active';
8596: }
1.277 albertel 8597: foreach my $type (keys(%{$types})) {
1.275 raeburn 8598: if ($status eq $type) {
1.420 albertel 8599: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8600: push(@{$$users{$role}{$user}},$type);
8601: }
1.288 raeburn 8602: $match = 1;
8603: }
8604: }
1.419 raeburn 8605: if (($match) && (ref($userdata) eq 'HASH')) {
8606: if (!exists($$userdata{$uname.':'.$udom})) {
8607: &get_user_info($udom,$uname,\%idx,$userdata);
8608: }
1.420 albertel 8609: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8610: push(@{$seclists{$uname.':'.$udom}},$usec);
8611: }
1.609 raeburn 8612: if (ref($statushash) eq 'HASH') {
8613: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8614: }
1.275 raeburn 8615: }
8616: }
8617: }
8618: }
1.290 albertel 8619: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8620: if ((defined($cdom)) && (defined($cnum))) {
8621: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8622: if ( defined($csettings{'internal.courseowner'}) ) {
8623: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8624: next if ($owner eq '');
8625: my ($ownername,$ownerdom);
8626: if ($owner =~ /^([^:]+):([^:]+)$/) {
8627: $ownername = $1;
8628: $ownerdom = $2;
8629: } else {
8630: $ownername = $owner;
8631: $ownerdom = $cdom;
8632: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8633: }
8634: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8635: if (defined($userdata) &&
1.609 raeburn 8636: !exists($$userdata{$owner})) {
8637: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8638: if (!grep(/^none$/,@{$seclists{$owner}})) {
8639: push(@{$seclists{$owner}},'none');
8640: }
8641: if (ref($statushash) eq 'HASH') {
8642: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8643: }
1.290 albertel 8644: }
1.279 raeburn 8645: }
8646: }
8647: }
1.419 raeburn 8648: foreach my $user (keys(%seclists)) {
8649: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8650: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8651: }
1.275 raeburn 8652: }
8653: return;
8654: }
8655:
1.288 raeburn 8656: sub get_user_info {
8657: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8658: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8659: &plainname($uname,$udom,'lastname');
1.291 albertel 8660: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8661: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8662: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8663: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8664: return;
8665: }
1.275 raeburn 8666:
1.472 raeburn 8667: ###############################################
8668:
8669: =pod
8670:
8671: =item * &get_user_quota()
8672:
1.1075.2.41 raeburn 8673: Retrieves quota assigned for storage of user files.
8674: Default is to report quota for portfolio files.
1.472 raeburn 8675:
8676: Incoming parameters:
8677: 1. user's username
8678: 2. user's domain
1.1075.2.41 raeburn 8679: 3. quota name - portfolio, author, or course
8680: (if no quota name provided, defaults to portfolio).
1.1075.2.42 raeburn 8681: 4. crstype - official, unofficial or community, if quota name is
8682: course
1.472 raeburn 8683:
8684: Returns:
1.536 raeburn 8685: 1. Disk quota (in Mb) assigned to student.
8686: 2. (Optional) Type of setting: custom or default
8687: (individually assigned or default for user's
8688: institutional status).
8689: 3. (Optional) - User's institutional status (e.g., faculty, staff
8690: or student - types as defined in localenroll::inst_usertypes
8691: for user's domain, which determines default quota for user.
8692: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8693:
8694: If a value has been stored in the user's environment,
1.536 raeburn 8695: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 8696: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8697:
8698: =cut
8699:
8700: ###############################################
8701:
8702:
8703: sub get_user_quota {
1.1075.2.42 raeburn 8704: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8705: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8706: if (!defined($udom)) {
8707: $udom = $env{'user.domain'};
8708: }
8709: if (!defined($uname)) {
8710: $uname = $env{'user.name'};
8711: }
8712: if (($udom eq '' || $uname eq '') ||
8713: ($udom eq 'public') && ($uname eq 'public')) {
8714: $quota = 0;
1.536 raeburn 8715: $quotatype = 'default';
8716: $defquota = 0;
1.472 raeburn 8717: } else {
1.536 raeburn 8718: my $inststatus;
1.1075.2.41 raeburn 8719: if ($quotaname eq 'course') {
8720: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8721: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8722: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8723: } else {
8724: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8725: $quota = $cenv{'internal.uploadquota'};
8726: }
1.536 raeburn 8727: } else {
1.1075.2.41 raeburn 8728: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8729: if ($quotaname eq 'author') {
8730: $quota = $env{'environment.authorquota'};
8731: } else {
8732: $quota = $env{'environment.portfolioquota'};
8733: }
8734: $inststatus = $env{'environment.inststatus'};
8735: } else {
8736: my %userenv =
8737: &Apache::lonnet::get('environment',['portfolioquota',
8738: 'authorquota','inststatus'],$udom,$uname);
8739: my ($tmp) = keys(%userenv);
8740: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8741: if ($quotaname eq 'author') {
8742: $quota = $userenv{'authorquota'};
8743: } else {
8744: $quota = $userenv{'portfolioquota'};
8745: }
8746: $inststatus = $userenv{'inststatus'};
8747: } else {
8748: undef(%userenv);
8749: }
8750: }
8751: }
8752: if ($quota eq '' || wantarray) {
8753: if ($quotaname eq 'course') {
8754: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.42 raeburn 8755: if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'community')) {
8756: $defquota = $domdefs{$crstype.'quota'};
8757: }
8758: if ($defquota eq '') {
8759: $defquota = 500;
8760: }
1.1075.2.41 raeburn 8761: } else {
8762: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8763: }
8764: if ($quota eq '') {
8765: $quota = $defquota;
8766: $quotatype = 'default';
8767: } else {
8768: $quotatype = 'custom';
8769: }
1.472 raeburn 8770: }
8771: }
1.536 raeburn 8772: if (wantarray) {
8773: return ($quota,$quotatype,$settingstatus,$defquota);
8774: } else {
8775: return $quota;
8776: }
1.472 raeburn 8777: }
8778:
8779: ###############################################
8780:
8781: =pod
8782:
8783: =item * &default_quota()
8784:
1.536 raeburn 8785: Retrieves default quota assigned for storage of user portfolio files,
8786: given an (optional) user's institutional status.
1.472 raeburn 8787:
8788: Incoming parameters:
1.1075.2.42 raeburn 8789:
1.472 raeburn 8790: 1. domain
1.536 raeburn 8791: 2. (Optional) institutional status(es). This is a : separated list of
8792: status types (e.g., faculty, staff, student etc.)
8793: which apply to the user for whom the default is being retrieved.
8794: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 8795: default quota will be returned.
8796: 3. quota name - portfolio, author, or course
8797: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8798:
8799: Returns:
1.1075.2.42 raeburn 8800:
1.472 raeburn 8801: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 8802: 2. (Optional) institutional type which determined the value of the
8803: default quota.
1.472 raeburn 8804:
8805: If a value has been stored in the domain's configuration db,
8806: it will return that, otherwise it returns 20 (for backwards
8807: compatibility with domains which have not set up a configuration
8808: db file; the original statically defined portfolio quota was 20 Mb).
8809:
1.536 raeburn 8810: If the user's status includes multiple types (e.g., staff and student),
8811: the largest default quota which applies to the user determines the
8812: default quota returned.
8813:
1.472 raeburn 8814: =cut
8815:
8816: ###############################################
8817:
8818:
8819: sub default_quota {
1.1075.2.41 raeburn 8820: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8821: my ($defquota,$settingstatus);
8822: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8823: ['quotas'],$udom);
1.1075.2.41 raeburn 8824: my $key = 'defaultquota';
8825: if ($quotaname eq 'author') {
8826: $key = 'authorquota';
8827: }
1.622 raeburn 8828: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8829: if ($inststatus ne '') {
1.765 raeburn 8830: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8831: foreach my $item (@statuses) {
1.1075.2.41 raeburn 8832: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8833: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8834: if ($defquota eq '') {
1.1075.2.41 raeburn 8835: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8836: $settingstatus = $item;
1.1075.2.41 raeburn 8837: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8838: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8839: $settingstatus = $item;
8840: }
8841: }
1.1075.2.41 raeburn 8842: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8843: if ($quotahash{'quotas'}{$item} ne '') {
8844: if ($defquota eq '') {
8845: $defquota = $quotahash{'quotas'}{$item};
8846: $settingstatus = $item;
8847: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8848: $defquota = $quotahash{'quotas'}{$item};
8849: $settingstatus = $item;
8850: }
1.536 raeburn 8851: }
8852: }
8853: }
8854: }
8855: if ($defquota eq '') {
1.1075.2.41 raeburn 8856: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8857: $defquota = $quotahash{'quotas'}{$key}{'default'};
8858: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8859: $defquota = $quotahash{'quotas'}{'default'};
8860: }
1.536 raeburn 8861: $settingstatus = 'default';
1.1075.2.42 raeburn 8862: if ($defquota eq '') {
8863: if ($quotaname eq 'author') {
8864: $defquota = 500;
8865: }
8866: }
1.536 raeburn 8867: }
8868: } else {
8869: $settingstatus = 'default';
1.1075.2.41 raeburn 8870: if ($quotaname eq 'author') {
8871: $defquota = 500;
8872: } else {
8873: $defquota = 20;
8874: }
1.536 raeburn 8875: }
8876: if (wantarray) {
8877: return ($defquota,$settingstatus);
1.472 raeburn 8878: } else {
1.536 raeburn 8879: return $defquota;
1.472 raeburn 8880: }
8881: }
8882:
1.1075.2.41 raeburn 8883: ###############################################
8884:
8885: =pod
8886:
1.1075.2.42 raeburn 8887: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 8888:
8889: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 8890: of existing file within authoring space will cause quota for the authoring
8891: space to be exceeded.
8892:
8893: Same, if upload of a file directly to a course/community via Course Editor
8894: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 8895:
8896: Inputs: 6
1.1075.2.42 raeburn 8897: 1. username or coursenum
1.1075.2.41 raeburn 8898: 2. domain
1.1075.2.42 raeburn 8899: 3. context ('author' or 'course')
1.1075.2.41 raeburn 8900: 4. filename of file for which action is being requested
8901: 5. filesize (kB) of file
8902: 6. action being taken: copy or upload.
8903:
8904: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
8905: otherwise return null.
8906:
1.1075.2.42 raeburn 8907: =back
8908:
1.1075.2.41 raeburn 8909: =cut
8910:
1.1075.2.42 raeburn 8911: sub excess_filesize_warning {
8912: my ($uname,$udom,$context,$filename,$filesize,$action) = @_;
8913: my $current_disk_usage = 0;
8914: my $disk_quota = &get_user_quota($uname,$udom,$context); #expressed in MB
8915: if ($context eq 'author') {
8916: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8917: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8918: } else {
8919: foreach my $subdir ('docs','supplemental') {
8920: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8921: }
8922: }
1.1075.2.41 raeburn 8923: $disk_quota = int($disk_quota * 1000);
8924: if (($current_disk_usage + $filesize) > $disk_quota) {
8925: return '<p><span class="LC_warning">'.
8926: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
8927: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</span>'.
8928: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
8929: $disk_quota,$current_disk_usage).
8930: '</p>';
8931: }
8932: return;
8933: }
8934:
8935: ###############################################
8936:
8937:
1.384 raeburn 8938: sub get_secgrprole_info {
8939: my ($cdom,$cnum,$needroles,$type) = @_;
8940: my %sections_count = &get_sections($cdom,$cnum);
8941: my @sections = (sort {$a <=> $b} keys(%sections_count));
8942: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8943: my @groups = sort(keys(%curr_groups));
8944: my $allroles = [];
8945: my $rolehash;
8946: my $accesshash = {
8947: active => 'Currently has access',
8948: future => 'Will have future access',
8949: previous => 'Previously had access',
8950: };
8951: if ($needroles) {
8952: $rolehash = {'all' => 'all'};
1.385 albertel 8953: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8954: if (&Apache::lonnet::error(%user_roles)) {
8955: undef(%user_roles);
8956: }
8957: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8958: my ($role)=split(/\:/,$item,2);
8959: if ($role eq 'cr') { next; }
8960: if ($role =~ /^cr/) {
8961: $$rolehash{$role} = (split('/',$role))[3];
8962: } else {
8963: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8964: }
8965: }
8966: foreach my $key (sort(keys(%{$rolehash}))) {
8967: push(@{$allroles},$key);
8968: }
8969: push (@{$allroles},'st');
8970: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8971: }
8972: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8973: }
8974:
1.555 raeburn 8975: sub user_picker {
1.994 raeburn 8976: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8977: my $currdom = $dom;
8978: my %curr_selected = (
8979: srchin => 'dom',
1.580 raeburn 8980: srchby => 'lastname',
1.555 raeburn 8981: );
8982: my $srchterm;
1.625 raeburn 8983: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 8984: if ($srch->{'srchby'} ne '') {
8985: $curr_selected{'srchby'} = $srch->{'srchby'};
8986: }
8987: if ($srch->{'srchin'} ne '') {
8988: $curr_selected{'srchin'} = $srch->{'srchin'};
8989: }
8990: if ($srch->{'srchtype'} ne '') {
8991: $curr_selected{'srchtype'} = $srch->{'srchtype'};
8992: }
8993: if ($srch->{'srchdomain'} ne '') {
8994: $currdom = $srch->{'srchdomain'};
8995: }
8996: $srchterm = $srch->{'srchterm'};
8997: }
8998: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 8999: 'usr' => 'Search criteria',
1.563 raeburn 9000: 'doma' => 'Domain/institution to search',
1.558 albertel 9001: 'uname' => 'username',
9002: 'lastname' => 'last name',
1.555 raeburn 9003: 'lastfirst' => 'last name, first name',
1.558 albertel 9004: 'crs' => 'in this course',
1.576 raeburn 9005: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9006: 'alc' => 'all LON-CAPA',
1.573 raeburn 9007: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9008: 'exact' => 'is',
9009: 'contains' => 'contains',
1.569 raeburn 9010: 'begins' => 'begins with',
1.571 raeburn 9011: 'youm' => "You must include some text to search for.",
9012: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9013: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9014: 'yomc' => "You must choose a domain when using an institutional directory search.",
9015: 'ymcd' => "You must choose a domain when using a domain search.",
9016: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9017: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9018: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9019: );
1.563 raeburn 9020: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9021: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9022:
9023: my @srchins = ('crs','dom','alc','instd');
9024:
9025: foreach my $option (@srchins) {
9026: # FIXME 'alc' option unavailable until
9027: # loncreateuser::print_user_query_page()
9028: # has been completed.
9029: next if ($option eq 'alc');
1.880 raeburn 9030: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9031: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9032: if ($curr_selected{'srchin'} eq $option) {
9033: $srchinsel .= '
9034: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9035: } else {
9036: $srchinsel .= '
9037: <option value="'.$option.'">'.$lt{$option}.'</option>';
9038: }
1.555 raeburn 9039: }
1.563 raeburn 9040: $srchinsel .= "\n </select>\n";
1.555 raeburn 9041:
9042: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9043: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9044: if ($curr_selected{'srchby'} eq $option) {
9045: $srchbysel .= '
9046: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9047: } else {
9048: $srchbysel .= '
9049: <option value="'.$option.'">'.$lt{$option}.'</option>';
9050: }
9051: }
9052: $srchbysel .= "\n </select>\n";
9053:
9054: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9055: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9056: if ($curr_selected{'srchtype'} eq $option) {
9057: $srchtypesel .= '
9058: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9059: } else {
9060: $srchtypesel .= '
9061: <option value="'.$option.'">'.$lt{$option}.'</option>';
9062: }
9063: }
9064: $srchtypesel .= "\n </select>\n";
9065:
1.558 albertel 9066: my ($newuserscript,$new_user_create);
1.994 raeburn 9067: my $context_dom = $env{'request.role.domain'};
9068: if ($context eq 'requestcrs') {
9069: if ($env{'form.coursedom'} ne '') {
9070: $context_dom = $env{'form.coursedom'};
9071: }
9072: }
1.556 raeburn 9073: if ($forcenewuser) {
1.576 raeburn 9074: if (ref($srch) eq 'HASH') {
1.994 raeburn 9075: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9076: if ($cancreate) {
9077: $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>';
9078: } else {
1.799 bisitz 9079: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9080: my %usertypetext = (
9081: official => 'institutional',
9082: unofficial => 'non-institutional',
9083: );
1.799 bisitz 9084: $new_user_create = '<p class="LC_warning">'
9085: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9086: .' '
9087: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9088: ,'<a href="'.$helplink.'">','</a>')
9089: .'</p><br />';
1.627 raeburn 9090: }
1.576 raeburn 9091: }
9092: }
9093:
1.556 raeburn 9094: $newuserscript = <<"ENDSCRIPT";
9095:
1.570 raeburn 9096: function setSearch(createnew,callingForm) {
1.556 raeburn 9097: if (createnew == 1) {
1.570 raeburn 9098: for (var i=0; i<callingForm.srchby.length; i++) {
9099: if (callingForm.srchby.options[i].value == 'uname') {
9100: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9101: }
9102: }
1.570 raeburn 9103: for (var i=0; i<callingForm.srchin.length; i++) {
9104: if ( callingForm.srchin.options[i].value == 'dom') {
9105: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9106: }
9107: }
1.570 raeburn 9108: for (var i=0; i<callingForm.srchtype.length; i++) {
9109: if (callingForm.srchtype.options[i].value == 'exact') {
9110: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9111: }
9112: }
1.570 raeburn 9113: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9114: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9115: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9116: }
9117: }
9118: }
9119: }
9120: ENDSCRIPT
1.558 albertel 9121:
1.556 raeburn 9122: }
9123:
1.555 raeburn 9124: my $output = <<"END_BLOCK";
1.556 raeburn 9125: <script type="text/javascript">
1.824 bisitz 9126: // <![CDATA[
1.570 raeburn 9127: function validateEntry(callingForm) {
1.558 albertel 9128:
1.556 raeburn 9129: var checkok = 1;
1.558 albertel 9130: var srchin;
1.570 raeburn 9131: for (var i=0; i<callingForm.srchin.length; i++) {
9132: if ( callingForm.srchin[i].checked ) {
9133: srchin = callingForm.srchin[i].value;
1.558 albertel 9134: }
9135: }
9136:
1.570 raeburn 9137: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9138: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9139: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9140: var srchterm = callingForm.srchterm.value;
9141: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9142: var msg = "";
9143:
9144: if (srchterm == "") {
9145: checkok = 0;
1.571 raeburn 9146: msg += "$lt{'youm'}\\n";
1.556 raeburn 9147: }
9148:
1.569 raeburn 9149: if (srchtype== 'begins') {
9150: if (srchterm.length < 2) {
9151: checkok = 0;
1.571 raeburn 9152: msg += "$lt{'thte'}\\n";
1.569 raeburn 9153: }
9154: }
9155:
1.556 raeburn 9156: if (srchtype== 'contains') {
9157: if (srchterm.length < 3) {
9158: checkok = 0;
1.571 raeburn 9159: msg += "$lt{'thet'}\\n";
1.556 raeburn 9160: }
9161: }
9162: if (srchin == 'instd') {
9163: if (srchdomain == '') {
9164: checkok = 0;
1.571 raeburn 9165: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9166: }
9167: }
9168: if (srchin == 'dom') {
9169: if (srchdomain == '') {
9170: checkok = 0;
1.571 raeburn 9171: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9172: }
9173: }
9174: if (srchby == 'lastfirst') {
9175: if (srchterm.indexOf(",") == -1) {
9176: checkok = 0;
1.571 raeburn 9177: msg += "$lt{'whus'}\\n";
1.556 raeburn 9178: }
9179: if (srchterm.indexOf(",") == srchterm.length -1) {
9180: checkok = 0;
1.571 raeburn 9181: msg += "$lt{'whse'}\\n";
1.556 raeburn 9182: }
9183: }
9184: if (checkok == 0) {
1.571 raeburn 9185: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9186: return;
9187: }
9188: if (checkok == 1) {
1.570 raeburn 9189: callingForm.submit();
1.556 raeburn 9190: }
9191: }
9192:
9193: $newuserscript
9194:
1.824 bisitz 9195: // ]]>
1.556 raeburn 9196: </script>
1.558 albertel 9197:
9198: $new_user_create
9199:
1.555 raeburn 9200: END_BLOCK
1.558 albertel 9201:
1.876 raeburn 9202: $output .= &Apache::lonhtmlcommon::start_pick_box().
9203: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9204: $domform.
9205: &Apache::lonhtmlcommon::row_closure().
9206: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9207: $srchbysel.
9208: $srchtypesel.
9209: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9210: $srchinsel.
9211: &Apache::lonhtmlcommon::row_closure(1).
9212: &Apache::lonhtmlcommon::end_pick_box().
9213: '<br />';
1.555 raeburn 9214: return $output;
9215: }
9216:
1.612 raeburn 9217: sub user_rule_check {
1.615 raeburn 9218: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9219: my $response;
9220: if (ref($usershash) eq 'HASH') {
9221: foreach my $user (keys(%{$usershash})) {
9222: my ($uname,$udom) = split(/:/,$user);
9223: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9224: my ($id,$newuser);
1.612 raeburn 9225: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9226: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9227: $id = $usershash->{$user}->{'id'};
9228: }
9229: my $inst_response;
9230: if (ref($checks) eq 'HASH') {
9231: if (defined($checks->{'username'})) {
1.615 raeburn 9232: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9233: &Apache::lonnet::get_instuser($udom,$uname);
9234: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9235: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9236: &Apache::lonnet::get_instuser($udom,undef,$id);
9237: }
1.615 raeburn 9238: } else {
9239: ($inst_response,%{$inst_results->{$user}}) =
9240: &Apache::lonnet::get_instuser($udom,$uname);
9241: return;
1.612 raeburn 9242: }
1.615 raeburn 9243: if (!$got_rules->{$udom}) {
1.612 raeburn 9244: my %domconfig = &Apache::lonnet::get_dom('configuration',
9245: ['usercreation'],$udom);
9246: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9247: foreach my $item ('username','id') {
1.612 raeburn 9248: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9249: $$curr_rules{$udom}{$item} =
9250: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9251: }
9252: }
9253: }
1.615 raeburn 9254: $got_rules->{$udom} = 1;
1.585 raeburn 9255: }
1.612 raeburn 9256: foreach my $item (keys(%{$checks})) {
9257: if (ref($$curr_rules{$udom}) eq 'HASH') {
9258: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9259: if (@{$$curr_rules{$udom}{$item}} > 0) {
9260: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9261: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9262: if ($rule_check{$rule}) {
9263: $$rulematch{$user}{$item} = $rule;
9264: if ($inst_response eq 'ok') {
1.615 raeburn 9265: if (ref($inst_results) eq 'HASH') {
9266: if (ref($inst_results->{$user}) eq 'HASH') {
9267: if (keys(%{$inst_results->{$user}}) == 0) {
9268: $$alerts{$item}{$udom}{$uname} = 1;
9269: }
1.612 raeburn 9270: }
9271: }
1.615 raeburn 9272: }
9273: last;
1.585 raeburn 9274: }
9275: }
9276: }
9277: }
9278: }
9279: }
9280: }
9281: }
1.612 raeburn 9282: return;
9283: }
9284:
9285: sub user_rule_formats {
9286: my ($domain,$domdesc,$curr_rules,$check) = @_;
9287: my %text = (
9288: 'username' => 'Usernames',
9289: 'id' => 'IDs',
9290: );
9291: my $output;
9292: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9293: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9294: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9295: $output = '<br />'.
9296: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9297: '<span class="LC_cusr_emph">','</span>',$domdesc).
9298: ' <ul>';
1.612 raeburn 9299: foreach my $rule (@{$ruleorder}) {
9300: if (ref($curr_rules) eq 'ARRAY') {
9301: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9302: if (ref($rules->{$rule}) eq 'HASH') {
9303: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9304: $rules->{$rule}{'desc'}.'</li>';
9305: }
9306: }
9307: }
9308: }
9309: $output .= '</ul>';
9310: }
9311: }
9312: return $output;
9313: }
9314:
9315: sub instrule_disallow_msg {
1.615 raeburn 9316: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9317: my $response;
9318: my %text = (
9319: item => 'username',
9320: items => 'usernames',
9321: match => 'matches',
9322: do => 'does',
9323: action => 'a username',
9324: one => 'one',
9325: );
9326: if ($count > 1) {
9327: $text{'item'} = 'usernames';
9328: $text{'match'} ='match';
9329: $text{'do'} = 'do';
9330: $text{'action'} = 'usernames',
9331: $text{'one'} = 'ones';
9332: }
9333: if ($checkitem eq 'id') {
9334: $text{'items'} = 'IDs';
9335: $text{'item'} = 'ID';
9336: $text{'action'} = 'an ID';
1.615 raeburn 9337: if ($count > 1) {
9338: $text{'item'} = 'IDs';
9339: $text{'action'} = 'IDs';
9340: }
1.612 raeburn 9341: }
1.674 bisitz 9342: $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 9343: if ($mode eq 'upload') {
9344: if ($checkitem eq 'username') {
9345: $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'}.");
9346: } elsif ($checkitem eq 'id') {
1.674 bisitz 9347: $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 9348: }
1.669 raeburn 9349: } elsif ($mode eq 'selfcreate') {
9350: if ($checkitem eq 'id') {
9351: $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.");
9352: }
1.615 raeburn 9353: } else {
9354: if ($checkitem eq 'username') {
9355: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9356: } elsif ($checkitem eq 'id') {
9357: $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.");
9358: }
1.612 raeburn 9359: }
9360: return $response;
1.585 raeburn 9361: }
9362:
1.624 raeburn 9363: sub personal_data_fieldtitles {
9364: my %fieldtitles = &Apache::lonlocal::texthash (
9365: id => 'Student/Employee ID',
9366: permanentemail => 'E-mail address',
9367: lastname => 'Last Name',
9368: firstname => 'First Name',
9369: middlename => 'Middle Name',
9370: generation => 'Generation',
9371: gen => 'Generation',
1.765 raeburn 9372: inststatus => 'Affiliation',
1.624 raeburn 9373: );
9374: return %fieldtitles;
9375: }
9376:
1.642 raeburn 9377: sub sorted_inst_types {
9378: my ($dom) = @_;
9379: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9380: my $othertitle = &mt('All users');
9381: if ($env{'request.course.id'}) {
1.668 raeburn 9382: $othertitle = &mt('Any users');
1.642 raeburn 9383: }
9384: my @types;
9385: if (ref($order) eq 'ARRAY') {
9386: @types = @{$order};
9387: }
9388: if (@types == 0) {
9389: if (ref($usertypes) eq 'HASH') {
9390: @types = sort(keys(%{$usertypes}));
9391: }
9392: }
9393: if (keys(%{$usertypes}) > 0) {
9394: $othertitle = &mt('Other users');
9395: }
9396: return ($othertitle,$usertypes,\@types);
9397: }
9398:
1.645 raeburn 9399: sub get_institutional_codes {
9400: my ($settings,$allcourses,$LC_code) = @_;
9401: # Get complete list of course sections to update
9402: my @currsections = ();
9403: my @currxlists = ();
9404: my $coursecode = $$settings{'internal.coursecode'};
9405:
9406: if ($$settings{'internal.sectionnums'} ne '') {
9407: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9408: }
9409:
9410: if ($$settings{'internal.crosslistings'} ne '') {
9411: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9412: }
9413:
9414: if (@currxlists > 0) {
9415: foreach (@currxlists) {
9416: if (m/^([^:]+):(\w*)$/) {
9417: unless (grep/^$1$/,@{$allcourses}) {
9418: push @{$allcourses},$1;
9419: $$LC_code{$1} = $2;
9420: }
9421: }
9422: }
9423: }
9424:
9425: if (@currsections > 0) {
9426: foreach (@currsections) {
9427: if (m/^(\w+):(\w*)$/) {
9428: my $sec = $coursecode.$1;
9429: my $lc_sec = $2;
9430: unless (grep/^$sec$/,@{$allcourses}) {
9431: push @{$allcourses},$sec;
9432: $$LC_code{$sec} = $lc_sec;
9433: }
9434: }
9435: }
9436: }
9437: return;
9438: }
9439:
1.971 raeburn 9440: sub get_standard_codeitems {
9441: return ('Year','Semester','Department','Number','Section');
9442: }
9443:
1.112 bowersj2 9444: =pod
9445:
1.780 raeburn 9446: =head1 Slot Helpers
9447:
9448: =over 4
9449:
9450: =item * sorted_slots()
9451:
1.1040 raeburn 9452: Sorts an array of slot names in order of an optional sort key,
9453: default sort is by slot start time (earliest first).
1.780 raeburn 9454:
9455: Inputs:
9456:
9457: =over 4
9458:
9459: slotsarr - Reference to array of unsorted slot names.
9460:
9461: slots - Reference to hash of hash, where outer hash keys are slot names.
9462:
1.1040 raeburn 9463: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9464:
1.549 albertel 9465: =back
9466:
1.780 raeburn 9467: Returns:
9468:
9469: =over 4
9470:
1.1040 raeburn 9471: sorted - An array of slot names sorted by a specified sort key
9472: (default sort key is start time of the slot).
1.780 raeburn 9473:
9474: =back
9475:
9476: =cut
9477:
9478:
9479: sub sorted_slots {
1.1040 raeburn 9480: my ($slotsarr,$slots,$sortkey) = @_;
9481: if ($sortkey eq '') {
9482: $sortkey = 'starttime';
9483: }
1.780 raeburn 9484: my @sorted;
9485: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9486: @sorted =
9487: sort {
9488: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9489: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9490: }
9491: if (ref($slots->{$a})) { return -1;}
9492: if (ref($slots->{$b})) { return 1;}
9493: return 0;
9494: } @{$slotsarr};
9495: }
9496: return @sorted;
9497: }
9498:
1.1040 raeburn 9499: =pod
9500:
9501: =item * get_future_slots()
9502:
9503: Inputs:
9504:
9505: =over 4
9506:
9507: cnum - course number
9508:
9509: cdom - course domain
9510:
9511: now - current UNIX time
9512:
9513: symb - optional symb
9514:
9515: =back
9516:
9517: Returns:
9518:
9519: =over 4
9520:
9521: sorted_reservable - ref to array of student_schedulable slots currently
9522: reservable, ordered by end date of reservation period.
9523:
9524: reservable_now - ref to hash of student_schedulable slots currently
9525: reservable.
9526:
9527: Keys in inner hash are:
9528: (a) symb: either blank or symb to which slot use is restricted.
9529: (b) endreserve: end date of reservation period.
9530:
9531: sorted_future - ref to array of student_schedulable slots reservable in
9532: the future, ordered by start date of reservation period.
9533:
9534: future_reservable - ref to hash of student_schedulable slots reservable
9535: in the future.
9536:
9537: Keys in inner hash are:
9538: (a) symb: either blank or symb to which slot use is restricted.
9539: (b) startreserve: start date of reservation period.
9540:
9541: =back
9542:
9543: =cut
9544:
9545: sub get_future_slots {
9546: my ($cnum,$cdom,$now,$symb) = @_;
9547: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9548: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9549: foreach my $slot (keys(%slots)) {
9550: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9551: if ($symb) {
9552: next if (($slots{$slot}->{'symb'} ne '') &&
9553: ($slots{$slot}->{'symb'} ne $symb));
9554: }
9555: if (($slots{$slot}->{'starttime'} > $now) &&
9556: ($slots{$slot}->{'endtime'} > $now)) {
9557: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9558: my $userallowed = 0;
9559: if ($slots{$slot}->{'allowedsections'}) {
9560: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9561: if (!defined($env{'request.role.sec'})
9562: && grep(/^No section assigned$/,@allowed_sec)) {
9563: $userallowed=1;
9564: } else {
9565: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9566: $userallowed=1;
9567: }
9568: }
9569: unless ($userallowed) {
9570: if (defined($env{'request.course.groups'})) {
9571: my @groups = split(/:/,$env{'request.course.groups'});
9572: foreach my $group (@groups) {
9573: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9574: $userallowed=1;
9575: last;
9576: }
9577: }
9578: }
9579: }
9580: }
9581: if ($slots{$slot}->{'allowedusers'}) {
9582: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9583: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9584: if (grep(/^\Q$user\E$/,@allowed_users)) {
9585: $userallowed = 1;
9586: }
9587: }
9588: next unless($userallowed);
9589: }
9590: my $startreserve = $slots{$slot}->{'startreserve'};
9591: my $endreserve = $slots{$slot}->{'endreserve'};
9592: my $symb = $slots{$slot}->{'symb'};
9593: if (($startreserve < $now) &&
9594: (!$endreserve || $endreserve > $now)) {
9595: my $lastres = $endreserve;
9596: if (!$lastres) {
9597: $lastres = $slots{$slot}->{'starttime'};
9598: }
9599: $reservable_now{$slot} = {
9600: symb => $symb,
9601: endreserve => $lastres
9602: };
9603: } elsif (($startreserve > $now) &&
9604: (!$endreserve || $endreserve > $startreserve)) {
9605: $future_reservable{$slot} = {
9606: symb => $symb,
9607: startreserve => $startreserve
9608: };
9609: }
9610: }
9611: }
9612: my @unsorted_reservable = keys(%reservable_now);
9613: if (@unsorted_reservable > 0) {
9614: @sorted_reservable =
9615: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9616: }
9617: my @unsorted_future = keys(%future_reservable);
9618: if (@unsorted_future > 0) {
9619: @sorted_future =
9620: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9621: }
9622: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9623: }
1.780 raeburn 9624:
9625: =pod
9626:
1.1057 foxr 9627: =back
9628:
1.549 albertel 9629: =head1 HTTP Helpers
9630:
9631: =over 4
9632:
1.648 raeburn 9633: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9634:
1.258 albertel 9635: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9636: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9637: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9638:
9639: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9640: $possible_names is an ref to an array of form element names. As an example:
9641: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9642: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9643:
9644: =cut
1.1 albertel 9645:
1.6 albertel 9646: sub get_unprocessed_cgi {
1.25 albertel 9647: my ($query,$possible_names)= @_;
1.26 matthew 9648: # $Apache::lonxml::debug=1;
1.356 albertel 9649: foreach my $pair (split(/&/,$query)) {
9650: my ($name, $value) = split(/=/,$pair);
1.369 www 9651: $name = &unescape($name);
1.25 albertel 9652: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9653: $value =~ tr/+/ /;
9654: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9655: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9656: }
1.16 harris41 9657: }
1.6 albertel 9658: }
9659:
1.112 bowersj2 9660: =pod
9661:
1.648 raeburn 9662: =item * &cacheheader()
1.112 bowersj2 9663:
9664: returns cache-controlling header code
9665:
9666: =cut
9667:
1.7 albertel 9668: sub cacheheader {
1.258 albertel 9669: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9670: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9671: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9672: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9673: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9674: return $output;
1.7 albertel 9675: }
9676:
1.112 bowersj2 9677: =pod
9678:
1.648 raeburn 9679: =item * &no_cache($r)
1.112 bowersj2 9680:
9681: specifies header code to not have cache
9682:
9683: =cut
9684:
1.9 albertel 9685: sub no_cache {
1.216 albertel 9686: my ($r) = @_;
9687: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9688: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9689: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9690: $r->no_cache(1);
9691: $r->header_out("Expires" => $date);
9692: $r->header_out("Pragma" => "no-cache");
1.123 www 9693: }
9694:
9695: sub content_type {
1.181 albertel 9696: my ($r,$type,$charset) = @_;
1.299 foxr 9697: if ($r) {
9698: # Note that printout.pl calls this with undef for $r.
9699: &no_cache($r);
9700: }
1.258 albertel 9701: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9702: unless ($charset) {
9703: $charset=&Apache::lonlocal::current_encoding;
9704: }
9705: if ($charset) { $type.='; charset='.$charset; }
9706: if ($r) {
9707: $r->content_type($type);
9708: } else {
9709: print("Content-type: $type\n\n");
9710: }
1.9 albertel 9711: }
1.25 albertel 9712:
1.112 bowersj2 9713: =pod
9714:
1.648 raeburn 9715: =item * &add_to_env($name,$value)
1.112 bowersj2 9716:
1.258 albertel 9717: adds $name to the %env hash with value
1.112 bowersj2 9718: $value, if $name already exists, the entry is converted to an array
9719: reference and $value is added to the array.
9720:
9721: =cut
9722:
1.25 albertel 9723: sub add_to_env {
9724: my ($name,$value)=@_;
1.258 albertel 9725: if (defined($env{$name})) {
9726: if (ref($env{$name})) {
1.25 albertel 9727: #already have multiple values
1.258 albertel 9728: push(@{ $env{$name} },$value);
1.25 albertel 9729: } else {
9730: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9731: my $first=$env{$name};
9732: undef($env{$name});
9733: push(@{ $env{$name} },$first,$value);
1.25 albertel 9734: }
9735: } else {
1.258 albertel 9736: $env{$name}=$value;
1.25 albertel 9737: }
1.31 albertel 9738: }
1.149 albertel 9739:
9740: =pod
9741:
1.648 raeburn 9742: =item * &get_env_multiple($name)
1.149 albertel 9743:
1.258 albertel 9744: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9745: values may be defined and end up as an array ref.
9746:
9747: returns an array of values
9748:
9749: =cut
9750:
9751: sub get_env_multiple {
9752: my ($name) = @_;
9753: my @values;
1.258 albertel 9754: if (defined($env{$name})) {
1.149 albertel 9755: # exists is it an array
1.258 albertel 9756: if (ref($env{$name})) {
9757: @values=@{ $env{$name} };
1.149 albertel 9758: } else {
1.258 albertel 9759: $values[0]=$env{$name};
1.149 albertel 9760: }
9761: }
9762: return(@values);
9763: }
9764:
1.660 raeburn 9765: sub ask_for_embedded_content {
9766: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9767: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 9768: %currsubfile,%unused,$rem);
1.1071 raeburn 9769: my $counter = 0;
9770: my $numnew = 0;
1.987 raeburn 9771: my $numremref = 0;
9772: my $numinvalid = 0;
9773: my $numpathchg = 0;
9774: my $numexisting = 0;
1.1071 raeburn 9775: my $numunused = 0;
9776: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 9777: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9778: my $heading = &mt('Upload embedded files');
9779: my $buttontext = &mt('Upload');
9780:
1.1075.2.11 raeburn 9781: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 9782: if ($actionurl eq '/adm/dependencies') {
9783: $navmap = Apache::lonnavmaps::navmap->new();
9784: }
9785: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9786: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 9787: }
1.1075.2.35 raeburn 9788: if (($actionurl eq '/adm/portfolio') ||
9789: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9790: my $current_path='/';
9791: if ($env{'form.currentpath'}) {
9792: $current_path = $env{'form.currentpath'};
9793: }
9794: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 9795: $udom = $cdom;
9796: $uname = $cnum;
1.984 raeburn 9797: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9798: } else {
9799: $udom = $env{'user.domain'};
9800: $uname = $env{'user.name'};
9801: $url = '/userfiles/portfolio';
9802: }
1.987 raeburn 9803: $toplevel = $url.'/';
1.984 raeburn 9804: $url .= $current_path;
9805: $getpropath = 1;
1.987 raeburn 9806: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9807: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9808: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9809: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9810: $toplevel = $url;
1.984 raeburn 9811: if ($rest ne '') {
1.987 raeburn 9812: $url .= $rest;
9813: }
9814: } elsif ($actionurl eq '/adm/coursedocs') {
9815: if (ref($args) eq 'HASH') {
1.1071 raeburn 9816: $url = $args->{'docs_url'};
9817: $toplevel = $url;
1.1075.2.11 raeburn 9818: if ($args->{'context'} eq 'paste') {
9819: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9820: ($path) =
9821: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9822: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9823: $fileloc =~ s{^/}{};
9824: }
1.1071 raeburn 9825: }
9826: } elsif ($actionurl eq '/adm/dependencies') {
9827: if ($env{'request.course.id'} ne '') {
9828: if (ref($args) eq 'HASH') {
9829: $url = $args->{'docs_url'};
9830: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 9831: $toplevel = $url;
9832: unless ($toplevel =~ m{^/}) {
9833: $toplevel = "/$url";
9834: }
1.1075.2.11 raeburn 9835: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 9836: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9837: $path = $1;
9838: } else {
9839: ($path) =
9840: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9841: }
1.1071 raeburn 9842: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9843: $fileloc =~ s{^/}{};
9844: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9845: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9846: }
1.987 raeburn 9847: }
1.1075.2.35 raeburn 9848: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9849: $udom = $cdom;
9850: $uname = $cnum;
9851: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9852: $toplevel = $url;
9853: $path = $url;
9854: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9855: $fileloc =~ s{^/}{};
9856: }
9857: foreach my $file (keys(%{$allfiles})) {
9858: my $embed_file;
9859: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9860: $embed_file = $1;
9861: } else {
9862: $embed_file = $file;
9863: }
1.1075.2.55! raeburn 9864: my ($absolutepath,$cleaned_file);
! 9865: if ($embed_file =~ m{^\w+://}) {
! 9866: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 9867: $newfiles{$cleaned_file} = 1;
9868: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9869: } else {
1.1075.2.55! raeburn 9870: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 9871: if ($embed_file =~ m{^/}) {
9872: $absolutepath = $embed_file;
9873: }
1.1075.2.47 raeburn 9874: if ($cleaned_file =~ m{/}) {
9875: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 9876: $path = &check_for_traversal($path,$url,$toplevel);
9877: my $item = $fname;
9878: if ($path ne '') {
9879: $item = $path.'/'.$fname;
9880: $subdependencies{$path}{$fname} = 1;
9881: } else {
9882: $dependencies{$item} = 1;
9883: }
9884: if ($absolutepath) {
9885: $mapping{$item} = $absolutepath;
9886: } else {
9887: $mapping{$item} = $embed_file;
9888: }
9889: } else {
9890: $dependencies{$embed_file} = 1;
9891: if ($absolutepath) {
1.1075.2.47 raeburn 9892: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 9893: } else {
1.1075.2.47 raeburn 9894: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9895: }
9896: }
1.984 raeburn 9897: }
9898: }
1.1071 raeburn 9899: my $dirptr = 16384;
1.984 raeburn 9900: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9901: $currsubfile{$path} = {};
1.1075.2.35 raeburn 9902: if (($actionurl eq '/adm/portfolio') ||
9903: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9904: my ($sublistref,$listerror) =
9905: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9906: if (ref($sublistref) eq 'ARRAY') {
9907: foreach my $line (@{$sublistref}) {
9908: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9909: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9910: }
1.984 raeburn 9911: }
1.987 raeburn 9912: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9913: if (opendir(my $dir,$url.'/'.$path)) {
9914: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9915: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9916: }
1.1075.2.11 raeburn 9917: } elsif (($actionurl eq '/adm/dependencies') ||
9918: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 9919: ($args->{'context'} eq 'paste')) ||
9920: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9921: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 9922: my $dir;
9923: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9924: $dir = $fileloc;
9925: } else {
9926: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9927: }
1.1071 raeburn 9928: if ($dir ne '') {
9929: my ($sublistref,$listerror) =
9930: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9931: if (ref($sublistref) eq 'ARRAY') {
9932: foreach my $line (@{$sublistref}) {
9933: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9934: undef,$mtime)=split(/\&/,$line,12);
9935: unless (($testdir&$dirptr) ||
9936: ($file_name =~ /^\.\.?$/)) {
9937: $currsubfile{$path}{$file_name} = [$size,$mtime];
9938: }
9939: }
9940: }
9941: }
1.984 raeburn 9942: }
9943: }
9944: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9945: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9946: my $item = $path.'/'.$file;
9947: unless ($mapping{$item} eq $item) {
9948: $pathchanges{$item} = 1;
9949: }
9950: $existing{$item} = 1;
9951: $numexisting ++;
9952: } else {
9953: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9954: }
9955: }
1.1071 raeburn 9956: if ($actionurl eq '/adm/dependencies') {
9957: foreach my $path (keys(%currsubfile)) {
9958: if (ref($currsubfile{$path}) eq 'HASH') {
9959: foreach my $file (keys(%{$currsubfile{$path}})) {
9960: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 9961: next if (($rem ne '') &&
9962: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9963: (ref($navmap) &&
9964: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9965: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9966: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9967: $unused{$path.'/'.$file} = 1;
9968: }
9969: }
9970: }
9971: }
9972: }
1.984 raeburn 9973: }
1.987 raeburn 9974: my %currfile;
1.1075.2.35 raeburn 9975: if (($actionurl eq '/adm/portfolio') ||
9976: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9977: my ($dirlistref,$listerror) =
9978: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9979: if (ref($dirlistref) eq 'ARRAY') {
9980: foreach my $line (@{$dirlistref}) {
9981: my ($file_name,$rest) = split(/\&/,$line,2);
9982: $currfile{$file_name} = 1;
9983: }
1.984 raeburn 9984: }
1.987 raeburn 9985: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9986: if (opendir(my $dir,$url)) {
1.987 raeburn 9987: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 9988: map {$currfile{$_} = 1;} @dir_list;
9989: }
1.1075.2.11 raeburn 9990: } elsif (($actionurl eq '/adm/dependencies') ||
9991: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 9992: ($args->{'context'} eq 'paste')) ||
9993: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9994: if ($env{'request.course.id'} ne '') {
9995: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9996: if ($dir ne '') {
9997: my ($dirlistref,$listerror) =
9998: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
9999: if (ref($dirlistref) eq 'ARRAY') {
10000: foreach my $line (@{$dirlistref}) {
10001: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10002: $size,undef,$mtime)=split(/\&/,$line,12);
10003: unless (($testdir&$dirptr) ||
10004: ($file_name =~ /^\.\.?$/)) {
10005: $currfile{$file_name} = [$size,$mtime];
10006: }
10007: }
10008: }
10009: }
10010: }
1.984 raeburn 10011: }
10012: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10013: if (exists($currfile{$file})) {
1.987 raeburn 10014: unless ($mapping{$file} eq $file) {
10015: $pathchanges{$file} = 1;
10016: }
10017: $existing{$file} = 1;
10018: $numexisting ++;
10019: } else {
1.984 raeburn 10020: $newfiles{$file} = 1;
10021: }
10022: }
1.1071 raeburn 10023: foreach my $file (keys(%currfile)) {
10024: unless (($file eq $filename) ||
10025: ($file eq $filename.'.bak') ||
10026: ($dependencies{$file})) {
1.1075.2.11 raeburn 10027: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10028: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10029: next if (($rem ne '') &&
10030: (($env{"httpref.$rem".$file} ne '') ||
10031: (ref($navmap) &&
10032: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10033: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10034: ($navmap->getResourceByUrl($rem.$1)))))));
10035: }
1.1075.2.11 raeburn 10036: }
1.1071 raeburn 10037: $unused{$file} = 1;
10038: }
10039: }
1.1075.2.11 raeburn 10040: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10041: ($args->{'context'} eq 'paste')) {
10042: $counter = scalar(keys(%existing));
10043: $numpathchg = scalar(keys(%pathchanges));
10044: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10045: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10046: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10047: $counter = scalar(keys(%existing));
10048: $numpathchg = scalar(keys(%pathchanges));
10049: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10050: }
1.984 raeburn 10051: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10052: if ($actionurl eq '/adm/dependencies') {
10053: next if ($embed_file =~ m{^\w+://});
10054: }
1.660 raeburn 10055: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10056: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10057: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10058: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10059: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10060: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10061: }
1.1075.2.35 raeburn 10062: $upload_output .= '</td>';
1.1071 raeburn 10063: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10064: $upload_output.='<td align="right">'.
10065: '<span class="LC_info LC_fontsize_medium">'.
10066: &mt("URL points to web address").'</span>';
1.987 raeburn 10067: $numremref++;
1.660 raeburn 10068: } elsif ($args->{'error_on_invalid_names'}
10069: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10070: $upload_output.='<td align="right"><span class="LC_warning">'.
10071: &mt('Invalid characters').'</span>';
1.987 raeburn 10072: $numinvalid++;
1.660 raeburn 10073: } else {
1.1075.2.35 raeburn 10074: $upload_output .= '<td>'.
10075: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10076: $embed_file,\%mapping,
1.1071 raeburn 10077: $allfiles,$codebase,'upload');
10078: $counter ++;
10079: $numnew ++;
1.987 raeburn 10080: }
10081: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10082: }
10083: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10084: if ($actionurl eq '/adm/dependencies') {
10085: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10086: $modify_output .= &start_data_table_row().
10087: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10088: '<img src="'.&icon($embed_file).'" border="0" />'.
10089: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10090: '<td>'.$size.'</td>'.
10091: '<td>'.$mtime.'</td>'.
10092: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10093: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10094: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10095: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10096: &embedded_file_element('upload_embedded',$counter,
10097: $embed_file,\%mapping,
10098: $allfiles,$codebase,'modify').
10099: '</div></td>'.
10100: &end_data_table_row()."\n";
10101: $counter ++;
10102: } else {
10103: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10104: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10105: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10106: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10107: &Apache::loncommon::end_data_table_row()."\n";
10108: }
10109: }
10110: my $delidx = $counter;
10111: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10112: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10113: $delete_output .= &start_data_table_row().
10114: '<td><img src="'.&icon($oldfile).'" />'.
10115: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10116: '<td>'.$size.'</td>'.
10117: '<td>'.$mtime.'</td>'.
10118: '<td><label><input type="checkbox" name="del_upload_dep" '.
10119: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10120: &embedded_file_element('upload_embedded',$delidx,
10121: $oldfile,\%mapping,$allfiles,
10122: $codebase,'delete').'</td>'.
10123: &end_data_table_row()."\n";
10124: $numunused ++;
10125: $delidx ++;
1.987 raeburn 10126: }
10127: if ($upload_output) {
10128: $upload_output = &start_data_table().
10129: $upload_output.
10130: &end_data_table()."\n";
10131: }
1.1071 raeburn 10132: if ($modify_output) {
10133: $modify_output = &start_data_table().
10134: &start_data_table_header_row().
10135: '<th>'.&mt('File').'</th>'.
10136: '<th>'.&mt('Size (KB)').'</th>'.
10137: '<th>'.&mt('Modified').'</th>'.
10138: '<th>'.&mt('Upload replacement?').'</th>'.
10139: &end_data_table_header_row().
10140: $modify_output.
10141: &end_data_table()."\n";
10142: }
10143: if ($delete_output) {
10144: $delete_output = &start_data_table().
10145: &start_data_table_header_row().
10146: '<th>'.&mt('File').'</th>'.
10147: '<th>'.&mt('Size (KB)').'</th>'.
10148: '<th>'.&mt('Modified').'</th>'.
10149: '<th>'.&mt('Delete?').'</th>'.
10150: &end_data_table_header_row().
10151: $delete_output.
10152: &end_data_table()."\n";
10153: }
1.987 raeburn 10154: my $applies = 0;
10155: if ($numremref) {
10156: $applies ++;
10157: }
10158: if ($numinvalid) {
10159: $applies ++;
10160: }
10161: if ($numexisting) {
10162: $applies ++;
10163: }
1.1071 raeburn 10164: if ($counter || $numunused) {
1.987 raeburn 10165: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10166: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10167: $state.'<h3>'.$heading.'</h3>';
10168: if ($actionurl eq '/adm/dependencies') {
10169: if ($numnew) {
10170: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10171: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10172: $upload_output.'<br />'."\n";
10173: }
10174: if ($numexisting) {
10175: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10176: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10177: $modify_output.'<br />'."\n";
10178: $buttontext = &mt('Save changes');
10179: }
10180: if ($numunused) {
10181: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10182: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10183: $delete_output.'<br />'."\n";
10184: $buttontext = &mt('Save changes');
10185: }
10186: } else {
10187: $output .= $upload_output.'<br />'."\n";
10188: }
10189: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10190: $counter.'" />'."\n";
10191: if ($actionurl eq '/adm/dependencies') {
10192: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10193: $numnew.'" />'."\n";
10194: } elsif ($actionurl eq '') {
1.987 raeburn 10195: $output .= '<input type="hidden" name="phase" value="three" />';
10196: }
10197: } elsif ($applies) {
10198: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10199: if ($applies > 1) {
10200: $output .=
1.1075.2.35 raeburn 10201: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10202: if ($numremref) {
10203: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10204: }
10205: if ($numinvalid) {
10206: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10207: }
10208: if ($numexisting) {
10209: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10210: }
10211: $output .= '</ul><br />';
10212: } elsif ($numremref) {
10213: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10214: } elsif ($numinvalid) {
10215: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10216: } elsif ($numexisting) {
10217: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10218: }
10219: $output .= $upload_output.'<br />';
10220: }
10221: my ($pathchange_output,$chgcount);
1.1071 raeburn 10222: $chgcount = $counter;
1.987 raeburn 10223: if (keys(%pathchanges) > 0) {
10224: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10225: if ($counter) {
1.987 raeburn 10226: $output .= &embedded_file_element('pathchange',$chgcount,
10227: $embed_file,\%mapping,
1.1071 raeburn 10228: $allfiles,$codebase,'change');
1.987 raeburn 10229: } else {
10230: $pathchange_output .=
10231: &start_data_table_row().
10232: '<td><input type ="checkbox" name="namechange" value="'.
10233: $chgcount.'" checked="checked" /></td>'.
10234: '<td>'.$mapping{$embed_file}.'</td>'.
10235: '<td>'.$embed_file.
10236: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10237: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10238: '</td>'.&end_data_table_row();
1.660 raeburn 10239: }
1.987 raeburn 10240: $numpathchg ++;
10241: $chgcount ++;
1.660 raeburn 10242: }
10243: }
1.1075.2.35 raeburn 10244: if (($counter) || ($numunused)) {
1.987 raeburn 10245: if ($numpathchg) {
10246: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10247: $numpathchg.'" />'."\n";
10248: }
10249: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10250: ($actionurl eq '/adm/imsimport')) {
10251: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10252: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10253: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10254: } elsif ($actionurl eq '/adm/dependencies') {
10255: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10256: }
1.1075.2.35 raeburn 10257: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10258: } elsif ($numpathchg) {
10259: my %pathchange = ();
10260: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10261: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10262: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10263: }
1.987 raeburn 10264: }
1.1071 raeburn 10265: return ($output,$counter,$numpathchg);
1.987 raeburn 10266: }
10267:
1.1075.2.47 raeburn 10268:
10269: =pod
10270:
10271: =item * clean_path($name)
10272:
10273: Performs clean-up of directories, subdirectories and filename in an
10274: embedded object, referenced in an HTML file which is being uploaded
10275: to a course or portfolio, where
10276: "Upload embedded images/multimedia files if HTML file" checkbox was
10277: checked.
10278:
10279: Clean-up is similar to replacements in lonnet::clean_filename()
10280: except each / between sub-directory and next level is preserved.
10281:
10282: =cut
10283:
10284: sub clean_path {
10285: my ($embed_file) = @_;
10286: $embed_file =~s{^/+}{};
10287: my @contents;
10288: if ($embed_file =~ m{/}) {
10289: @contents = split(/\//,$embed_file);
10290: } else {
10291: @contents = ($embed_file);
10292: }
10293: my $lastidx = scalar(@contents)-1;
10294: for (my $i=0; $i<=$lastidx; $i++) {
10295: $contents[$i]=~s{\\}{/}g;
10296: $contents[$i]=~s/\s+/\_/g;
10297: $contents[$i]=~s{[^/\w\.\-]}{}g;
10298: if ($i == $lastidx) {
10299: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10300: }
10301: }
10302: if ($lastidx > 0) {
10303: return join('/',@contents);
10304: } else {
10305: return $contents[0];
10306: }
10307: }
10308:
1.987 raeburn 10309: sub embedded_file_element {
1.1071 raeburn 10310: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10311: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10312: (ref($codebase) eq 'HASH'));
10313: my $output;
1.1071 raeburn 10314: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10315: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10316: }
10317: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10318: &escape($embed_file).'" />';
10319: unless (($context eq 'upload_embedded') &&
10320: ($mapping->{$embed_file} eq $embed_file)) {
10321: $output .='
10322: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10323: }
10324: my $attrib;
10325: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10326: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10327: }
10328: $output .=
10329: "\n\t\t".
10330: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10331: $attrib.'" />';
10332: if (exists($codebase->{$mapping->{$embed_file}})) {
10333: $output .=
10334: "\n\t\t".
10335: '<input name="codebase_'.$num.'" type="hidden" value="'.
10336: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10337: }
1.987 raeburn 10338: return $output;
1.660 raeburn 10339: }
10340:
1.1071 raeburn 10341: sub get_dependency_details {
10342: my ($currfile,$currsubfile,$embed_file) = @_;
10343: my ($size,$mtime,$showsize,$showmtime);
10344: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10345: if ($embed_file =~ m{/}) {
10346: my ($path,$fname) = split(/\//,$embed_file);
10347: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10348: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10349: }
10350: } else {
10351: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10352: ($size,$mtime) = @{$currfile->{$embed_file}};
10353: }
10354: }
10355: $showsize = $size/1024.0;
10356: $showsize = sprintf("%.1f",$showsize);
10357: if ($mtime > 0) {
10358: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10359: }
10360: }
10361: return ($showsize,$showmtime);
10362: }
10363:
10364: sub ask_embedded_js {
10365: return <<"END";
10366: <script type="text/javascript"">
10367: // <![CDATA[
10368: function toggleBrowse(counter) {
10369: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10370: var fileid = document.getElementById('embedded_item_'+counter);
10371: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10372: if (chkboxid.checked == true) {
10373: uploaddivid.style.display='block';
10374: } else {
10375: uploaddivid.style.display='none';
10376: fileid.value = '';
10377: }
10378: }
10379: // ]]>
10380: </script>
10381:
10382: END
10383: }
10384:
1.661 raeburn 10385: sub upload_embedded {
10386: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10387: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10388: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10389: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10390: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10391: my $orig_uploaded_filename =
10392: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10393: foreach my $type ('orig','ref','attrib','codebase') {
10394: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10395: $env{'form.embedded_'.$type.'_'.$i} =
10396: &unescape($env{'form.embedded_'.$type.'_'.$i});
10397: }
10398: }
1.661 raeburn 10399: my ($path,$fname) =
10400: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10401: # no path, whole string is fname
10402: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10403: $fname = &Apache::lonnet::clean_filename($fname);
10404: # See if there is anything left
10405: next if ($fname eq '');
10406:
10407: # Check if file already exists as a file or directory.
10408: my ($state,$msg);
10409: if ($context eq 'portfolio') {
10410: my $port_path = $dirpath;
10411: if ($group ne '') {
10412: $port_path = "groups/$group/$port_path";
10413: }
1.987 raeburn 10414: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10415: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10416: $dir_root,$port_path,$disk_quota,
10417: $current_disk_usage,$uname,$udom);
10418: if ($state eq 'will_exceed_quota'
1.984 raeburn 10419: || $state eq 'file_locked') {
1.661 raeburn 10420: $output .= $msg;
10421: next;
10422: }
10423: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10424: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10425: if ($state eq 'exists') {
10426: $output .= $msg;
10427: next;
10428: }
10429: }
10430: # Check if extension is valid
10431: if (($fname =~ /\.(\w+)$/) &&
10432: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 10433: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10434: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10435: next;
10436: } elsif (($fname =~ /\.(\w+)$/) &&
10437: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10438: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10439: next;
10440: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 10441: $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 10442: next;
10443: }
10444: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 10445: my $subdir = $path;
10446: $subdir =~ s{/+$}{};
1.661 raeburn 10447: if ($context eq 'portfolio') {
1.984 raeburn 10448: my $result;
10449: if ($state eq 'existingfile') {
10450: $result=
10451: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 10452: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10453: } else {
1.984 raeburn 10454: $result=
10455: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10456: $dirpath.
1.1075.2.35 raeburn 10457: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10458: if ($result !~ m|^/uploaded/|) {
10459: $output .= '<span class="LC_error">'
10460: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10461: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10462: .'</span><br />';
10463: next;
10464: } else {
1.987 raeburn 10465: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10466: $path.$fname.'</span>').'<br />';
1.984 raeburn 10467: }
1.661 raeburn 10468: }
1.1075.2.35 raeburn 10469: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
10470: my $extendedsubdir = $dirpath.'/'.$subdir;
10471: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10472: my $result =
1.1075.2.35 raeburn 10473: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10474: if ($result !~ m|^/uploaded/|) {
10475: $output .= '<span class="LC_error">'
10476: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10477: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10478: .'</span><br />';
10479: next;
10480: } else {
10481: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10482: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 10483: if ($context eq 'syllabus') {
10484: &Apache::lonnet::make_public_indefinitely($result);
10485: }
1.987 raeburn 10486: }
1.661 raeburn 10487: } else {
10488: # Save the file
10489: my $target = $env{'form.embedded_item_'.$i};
10490: my $fullpath = $dir_root.$dirpath.'/'.$path;
10491: my $dest = $fullpath.$fname;
10492: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10493: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10494: my $count;
10495: my $filepath = $dir_root;
1.1027 raeburn 10496: foreach my $subdir (@parts) {
10497: $filepath .= "/$subdir";
10498: if (!-e $filepath) {
1.661 raeburn 10499: mkdir($filepath,0770);
10500: }
10501: }
10502: my $fh;
10503: if (!open($fh,'>'.$dest)) {
10504: &Apache::lonnet::logthis('Failed to create '.$dest);
10505: $output .= '<span class="LC_error">'.
1.1071 raeburn 10506: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10507: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10508: '</span><br />';
10509: } else {
10510: if (!print $fh $env{'form.embedded_item_'.$i}) {
10511: &Apache::lonnet::logthis('Failed to write to '.$dest);
10512: $output .= '<span class="LC_error">'.
1.1071 raeburn 10513: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10514: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10515: '</span><br />';
10516: } else {
1.987 raeburn 10517: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10518: $url.'</span>').'<br />';
10519: unless ($context eq 'testbank') {
10520: $footer .= &mt('View embedded file: [_1]',
10521: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10522: }
10523: }
10524: close($fh);
10525: }
10526: }
10527: if ($env{'form.embedded_ref_'.$i}) {
10528: $pathchange{$i} = 1;
10529: }
10530: }
10531: if ($output) {
10532: $output = '<p>'.$output.'</p>';
10533: }
10534: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10535: $returnflag = 'ok';
1.1071 raeburn 10536: my $numpathchgs = scalar(keys(%pathchange));
10537: if ($numpathchgs > 0) {
1.987 raeburn 10538: if ($context eq 'portfolio') {
10539: $output .= '<p>'.&mt('or').'</p>';
10540: } elsif ($context eq 'testbank') {
1.1071 raeburn 10541: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10542: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10543: $returnflag = 'modify_orightml';
10544: }
10545: }
1.1071 raeburn 10546: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10547: }
10548:
10549: sub modify_html_form {
10550: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10551: my $end = 0;
10552: my $modifyform;
10553: if ($context eq 'upload_embedded') {
10554: return unless (ref($pathchange) eq 'HASH');
10555: if ($env{'form.number_embedded_items'}) {
10556: $end += $env{'form.number_embedded_items'};
10557: }
10558: if ($env{'form.number_pathchange_items'}) {
10559: $end += $env{'form.number_pathchange_items'};
10560: }
10561: if ($end) {
10562: for (my $i=0; $i<$end; $i++) {
10563: if ($i < $env{'form.number_embedded_items'}) {
10564: next unless($pathchange->{$i});
10565: }
10566: $modifyform .=
10567: &start_data_table_row().
10568: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10569: 'checked="checked" /></td>'.
10570: '<td>'.$env{'form.embedded_ref_'.$i}.
10571: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10572: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10573: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10574: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10575: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10576: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10577: '<td>'.$env{'form.embedded_orig_'.$i}.
10578: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10579: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10580: &end_data_table_row();
1.1071 raeburn 10581: }
1.987 raeburn 10582: }
10583: } else {
10584: $modifyform = $pathchgtable;
10585: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10586: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10587: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10588: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10589: }
10590: }
10591: if ($modifyform) {
1.1071 raeburn 10592: if ($actionurl eq '/adm/dependencies') {
10593: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10594: }
1.987 raeburn 10595: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10596: '<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".
10597: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10598: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10599: '</ol></p>'."\n".'<p>'.
10600: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10601: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10602: &start_data_table()."\n".
10603: &start_data_table_header_row().
10604: '<th>'.&mt('Change?').'</th>'.
10605: '<th>'.&mt('Current reference').'</th>'.
10606: '<th>'.&mt('Required reference').'</th>'.
10607: &end_data_table_header_row()."\n".
10608: $modifyform.
10609: &end_data_table().'<br />'."\n".$hiddenstate.
10610: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10611: '</form>'."\n";
10612: }
10613: return;
10614: }
10615:
10616: sub modify_html_refs {
1.1075.2.35 raeburn 10617: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10618: my $container;
10619: if ($context eq 'portfolio') {
10620: $container = $env{'form.container'};
10621: } elsif ($context eq 'coursedoc') {
10622: $container = $env{'form.primaryurl'};
1.1071 raeburn 10623: } elsif ($context eq 'manage_dependencies') {
10624: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10625: $container = "/$container";
1.1075.2.35 raeburn 10626: } elsif ($context eq 'syllabus') {
10627: $container = $url;
1.987 raeburn 10628: } else {
1.1027 raeburn 10629: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10630: }
10631: my (%allfiles,%codebase,$output,$content);
10632: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 10633: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10634: if (wantarray) {
10635: return ('',0,0);
10636: } else {
10637: return;
10638: }
10639: }
10640: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10641: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10642: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10643: if (wantarray) {
10644: return ('',0,0);
10645: } else {
10646: return;
10647: }
10648: }
1.987 raeburn 10649: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10650: if ($content eq '-1') {
10651: if (wantarray) {
10652: return ('',0,0);
10653: } else {
10654: return;
10655: }
10656: }
1.987 raeburn 10657: } else {
1.1071 raeburn 10658: unless ($container =~ /^\Q$dir_root\E/) {
10659: if (wantarray) {
10660: return ('',0,0);
10661: } else {
10662: return;
10663: }
10664: }
1.987 raeburn 10665: if (open(my $fh,"<$container")) {
10666: $content = join('', <$fh>);
10667: close($fh);
10668: } else {
1.1071 raeburn 10669: if (wantarray) {
10670: return ('',0,0);
10671: } else {
10672: return;
10673: }
1.987 raeburn 10674: }
10675: }
10676: my ($count,$codebasecount) = (0,0);
10677: my $mm = new File::MMagic;
10678: my $mime_type = $mm->checktype_contents($content);
10679: if ($mime_type eq 'text/html') {
10680: my $parse_result =
10681: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10682: \%codebase,\$content);
10683: if ($parse_result eq 'ok') {
10684: foreach my $i (@changes) {
10685: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10686: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10687: if ($allfiles{$ref}) {
10688: my $newname = $orig;
10689: my ($attrib_regexp,$codebase);
1.1006 raeburn 10690: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10691: if ($attrib_regexp =~ /:/) {
10692: $attrib_regexp =~ s/\:/|/g;
10693: }
10694: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10695: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10696: $count += $numchg;
1.1075.2.35 raeburn 10697: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 10698: delete($allfiles{$ref});
1.987 raeburn 10699: }
10700: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10701: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10702: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10703: $codebasecount ++;
10704: }
10705: }
10706: }
1.1075.2.35 raeburn 10707: my $skiprewrites;
1.987 raeburn 10708: if ($count || $codebasecount) {
10709: my $saveresult;
1.1071 raeburn 10710: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 10711: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10712: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10713: if ($url eq $container) {
10714: my ($fname) = ($container =~ m{/([^/]+)$});
10715: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10716: $count,'<span class="LC_filename">'.
1.1071 raeburn 10717: $fname.'</span>').'</p>';
1.987 raeburn 10718: } else {
10719: $output = '<p class="LC_error">'.
10720: &mt('Error: update failed for: [_1].',
10721: '<span class="LC_filename">'.
10722: $container.'</span>').'</p>';
10723: }
1.1075.2.35 raeburn 10724: if ($context eq 'syllabus') {
10725: unless ($saveresult eq 'ok') {
10726: $skiprewrites = 1;
10727: }
10728: }
1.987 raeburn 10729: } else {
10730: if (open(my $fh,">$container")) {
10731: print $fh $content;
10732: close($fh);
10733: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10734: $count,'<span class="LC_filename">'.
10735: $container.'</span>').'</p>';
1.661 raeburn 10736: } else {
1.987 raeburn 10737: $output = '<p class="LC_error">'.
10738: &mt('Error: could not update [_1].',
10739: '<span class="LC_filename">'.
10740: $container.'</span>').'</p>';
1.661 raeburn 10741: }
10742: }
10743: }
1.1075.2.35 raeburn 10744: if (($context eq 'syllabus') && (!$skiprewrites)) {
10745: my ($actionurl,$state);
10746: $actionurl = "/public/$udom/$uname/syllabus";
10747: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10748: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10749: \%codebase,
10750: {'context' => 'rewrites',
10751: 'ignore_remote_references' => 1,});
10752: if (ref($mapping) eq 'HASH') {
10753: my $rewrites = 0;
10754: foreach my $key (keys(%{$mapping})) {
10755: next if ($key =~ m{^https?://});
10756: my $ref = $mapping->{$key};
10757: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10758: my $attrib;
10759: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10760: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10761: }
10762: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10763: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10764: $rewrites += $numchg;
10765: }
10766: }
10767: if ($rewrites) {
10768: my $saveresult;
10769: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10770: if ($url eq $container) {
10771: my ($fname) = ($container =~ m{/([^/]+)$});
10772: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10773: $count,'<span class="LC_filename">'.
10774: $fname.'</span>').'</p>';
10775: } else {
10776: $output .= '<p class="LC_error">'.
10777: &mt('Error: could not update links in [_1].',
10778: '<span class="LC_filename">'.
10779: $container.'</span>').'</p>';
10780:
10781: }
10782: }
10783: }
10784: }
1.987 raeburn 10785: } else {
10786: &logthis('Failed to parse '.$container.
10787: ' to modify references: '.$parse_result);
1.661 raeburn 10788: }
10789: }
1.1071 raeburn 10790: if (wantarray) {
10791: return ($output,$count,$codebasecount);
10792: } else {
10793: return $output;
10794: }
1.661 raeburn 10795: }
10796:
10797: sub check_for_existing {
10798: my ($path,$fname,$element) = @_;
10799: my ($state,$msg);
10800: if (-d $path.'/'.$fname) {
10801: $state = 'exists';
10802: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10803: } elsif (-e $path.'/'.$fname) {
10804: $state = 'exists';
10805: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10806: }
10807: if ($state eq 'exists') {
10808: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10809: }
10810: return ($state,$msg);
10811: }
10812:
10813: sub check_for_upload {
10814: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10815: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10816: my $filesize = length($env{'form.'.$element});
10817: if (!$filesize) {
10818: my $msg = '<span class="LC_error">'.
10819: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10820: '<span class="LC_filename">'.$fname.'</span>',
10821: $filesize).'<br />'.
1.1007 raeburn 10822: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10823: '</span>';
10824: return ('zero_bytes',$msg);
10825: }
10826: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10827: my $getpropath = 1;
1.1021 raeburn 10828: my ($dirlistref,$listerror) =
10829: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10830: my $found_file = 0;
10831: my $locked_file = 0;
1.991 raeburn 10832: my @lockers;
10833: my $navmap;
10834: if ($env{'request.course.id'}) {
10835: $navmap = Apache::lonnavmaps::navmap->new();
10836: }
1.1021 raeburn 10837: if (ref($dirlistref) eq 'ARRAY') {
10838: foreach my $line (@{$dirlistref}) {
10839: my ($file_name,$rest)=split(/\&/,$line,2);
10840: if ($file_name eq $fname){
10841: $file_name = $path.$file_name;
10842: if ($group ne '') {
10843: $file_name = $group.$file_name;
10844: }
10845: $found_file = 1;
10846: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10847: foreach my $lock (@lockers) {
10848: if (ref($lock) eq 'ARRAY') {
10849: my ($symb,$crsid) = @{$lock};
10850: if ($crsid eq $env{'request.course.id'}) {
10851: if (ref($navmap)) {
10852: my $res = $navmap->getBySymb($symb);
10853: foreach my $part (@{$res->parts()}) {
10854: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10855: unless (($slot_status == $res->RESERVED) ||
10856: ($slot_status == $res->RESERVED_LOCATION)) {
10857: $locked_file = 1;
10858: }
1.991 raeburn 10859: }
1.1021 raeburn 10860: } else {
10861: $locked_file = 1;
1.991 raeburn 10862: }
10863: } else {
10864: $locked_file = 1;
10865: }
10866: }
1.1021 raeburn 10867: }
10868: } else {
10869: my @info = split(/\&/,$rest);
10870: my $currsize = $info[6]/1000;
10871: if ($currsize < $filesize) {
10872: my $extra = $filesize - $currsize;
10873: if (($current_disk_usage + $extra) > $disk_quota) {
10874: my $msg = '<span class="LC_error">'.
10875: &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.',
10876: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10877: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10878: $disk_quota,$current_disk_usage);
10879: return ('will_exceed_quota',$msg);
10880: }
1.984 raeburn 10881: }
10882: }
1.661 raeburn 10883: }
10884: }
10885: }
10886: if (($current_disk_usage + $filesize) > $disk_quota){
10887: my $msg = '<span class="LC_error">'.
10888: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10889: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10890: return ('will_exceed_quota',$msg);
10891: } elsif ($found_file) {
10892: if ($locked_file) {
10893: my $msg = '<span class="LC_error">';
10894: $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>');
10895: $msg .= '</span><br />';
10896: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10897: return ('file_locked',$msg);
10898: } else {
10899: my $msg = '<span class="LC_error">';
1.984 raeburn 10900: $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 10901: $msg .= '</span>';
1.984 raeburn 10902: return ('existingfile',$msg);
1.661 raeburn 10903: }
10904: }
10905: }
10906:
1.987 raeburn 10907: sub check_for_traversal {
10908: my ($path,$url,$toplevel) = @_;
10909: my @parts=split(/\//,$path);
10910: my $cleanpath;
10911: my $fullpath = $url;
10912: for (my $i=0;$i<@parts;$i++) {
10913: next if ($parts[$i] eq '.');
10914: if ($parts[$i] eq '..') {
10915: $fullpath =~ s{([^/]+/)$}{};
10916: } else {
10917: $fullpath .= $parts[$i].'/';
10918: }
10919: }
10920: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10921: $cleanpath = $1;
10922: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10923: my $curr_toprel = $1;
10924: my @parts = split(/\//,$curr_toprel);
10925: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10926: my @urlparts = split(/\//,$url_toprel);
10927: my $doubledots;
10928: my $startdiff = -1;
10929: for (my $i=0; $i<@urlparts; $i++) {
10930: if ($startdiff == -1) {
10931: unless ($urlparts[$i] eq $parts[$i]) {
10932: $startdiff = $i;
10933: $doubledots .= '../';
10934: }
10935: } else {
10936: $doubledots .= '../';
10937: }
10938: }
10939: if ($startdiff > -1) {
10940: $cleanpath = $doubledots;
10941: for (my $i=$startdiff; $i<@parts; $i++) {
10942: $cleanpath .= $parts[$i].'/';
10943: }
10944: }
10945: }
10946: $cleanpath =~ s{(/)$}{};
10947: return $cleanpath;
10948: }
1.31 albertel 10949:
1.1053 raeburn 10950: sub is_archive_file {
10951: my ($mimetype) = @_;
10952: if (($mimetype eq 'application/octet-stream') ||
10953: ($mimetype eq 'application/x-stuffit') ||
10954: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10955: return 1;
10956: }
10957: return;
10958: }
10959:
10960: sub decompress_form {
1.1065 raeburn 10961: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10962: my %lt = &Apache::lonlocal::texthash (
10963: this => 'This file is an archive file.',
1.1067 raeburn 10964: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10965: itsc => 'Its contents are as follows:',
1.1053 raeburn 10966: youm => 'You may wish to extract its contents.',
10967: extr => 'Extract contents',
1.1067 raeburn 10968: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10969: proa => 'Process automatically?',
1.1053 raeburn 10970: yes => 'Yes',
10971: no => 'No',
1.1067 raeburn 10972: fold => 'Title for folder containing movie',
10973: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10974: );
1.1065 raeburn 10975: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10976: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10977: my $info = &list_archive_contents($fileloc,\@paths);
10978: if (@paths) {
10979: foreach my $path (@paths) {
10980: $path =~ s{^/}{};
1.1067 raeburn 10981: if ($path =~ m{^([^/]+)/$}) {
10982: $topdir = $1;
10983: }
1.1065 raeburn 10984: if ($path =~ m{^([^/]+)/}) {
10985: $toplevel{$1} = $path;
10986: } else {
10987: $toplevel{$path} = $path;
10988: }
10989: }
10990: }
1.1067 raeburn 10991: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
10992: my @camtasia = ("$topdir/","$topdir/index.html",
10993: "$topdir/media/",
10994: "$topdir/media/$topdir.mp4",
10995: "$topdir/media/FirstFrame.png",
10996: "$topdir/media/player.swf",
10997: "$topdir/media/swfobject.js",
10998: "$topdir/media/expressInstall.swf");
10999: my @diffs = &compare_arrays(\@paths,\@camtasia);
11000: if (@diffs == 0) {
11001: $is_camtasia = 1;
11002: }
11003: }
11004: my $output;
11005: if ($is_camtasia) {
11006: $output = <<"ENDCAM";
11007: <script type="text/javascript" language="Javascript">
11008: // <![CDATA[
11009:
11010: function camtasiaToggle() {
11011: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11012: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
11013: if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
11014:
11015: document.getElementById('camtasia_titles').style.display='block';
11016: } else {
11017: document.getElementById('camtasia_titles').style.display='none';
11018: }
11019: }
11020: }
11021: return;
11022: }
11023:
11024: // ]]>
11025: </script>
11026: <p>$lt{'camt'}</p>
11027: ENDCAM
1.1065 raeburn 11028: } else {
1.1067 raeburn 11029: $output = '<p>'.$lt{'this'};
11030: if ($info eq '') {
11031: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11032: } else {
11033: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11034: '<div><pre>'.$info.'</pre></div>';
11035: }
1.1065 raeburn 11036: }
1.1067 raeburn 11037: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11038: my $duplicates;
11039: my $num = 0;
11040: if (ref($dirlist) eq 'ARRAY') {
11041: foreach my $item (@{$dirlist}) {
11042: if (ref($item) eq 'ARRAY') {
11043: if (exists($toplevel{$item->[0]})) {
11044: $duplicates .=
11045: &start_data_table_row().
11046: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11047: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11048: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11049: 'value="1" />'.&mt('Yes').'</label>'.
11050: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11051: '<td>'.$item->[0].'</td>';
11052: if ($item->[2]) {
11053: $duplicates .= '<td>'.&mt('Directory').'</td>';
11054: } else {
11055: $duplicates .= '<td>'.&mt('File').'</td>';
11056: }
11057: $duplicates .= '<td>'.$item->[3].'</td>'.
11058: '<td>'.
11059: &Apache::lonlocal::locallocaltime($item->[4]).
11060: '</td>'.
11061: &end_data_table_row();
11062: $num ++;
11063: }
11064: }
11065: }
11066: }
11067: my $itemcount;
11068: if (@paths > 0) {
11069: $itemcount = scalar(@paths);
11070: } else {
11071: $itemcount = 1;
11072: }
1.1067 raeburn 11073: if ($is_camtasia) {
11074: $output .= $lt{'auto'}.'<br />'.
11075: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
11076: '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
11077: $lt{'yes'}.'</label> <label>'.
11078: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11079: $lt{'no'}.'</label></span><br />'.
11080: '<div id="camtasia_titles" style="display:block">'.
11081: &Apache::lonhtmlcommon::start_pick_box().
11082: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11083: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11084: &Apache::lonhtmlcommon::row_closure().
11085: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11086: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11087: &Apache::lonhtmlcommon::row_closure(1).
11088: &Apache::lonhtmlcommon::end_pick_box().
11089: '</div>';
11090: }
1.1065 raeburn 11091: $output .=
11092: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11093: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11094: "\n";
1.1065 raeburn 11095: if ($duplicates ne '') {
11096: $output .= '<p><span class="LC_warning">'.
11097: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11098: &start_data_table().
11099: &start_data_table_header_row().
11100: '<th>'.&mt('Overwrite?').'</th>'.
11101: '<th>'.&mt('Name').'</th>'.
11102: '<th>'.&mt('Type').'</th>'.
11103: '<th>'.&mt('Size').'</th>'.
11104: '<th>'.&mt('Last modified').'</th>'.
11105: &end_data_table_header_row().
11106: $duplicates.
11107: &end_data_table().
11108: '</p>';
11109: }
1.1067 raeburn 11110: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11111: if (ref($hiddenelements) eq 'HASH') {
11112: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11113: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11114: }
11115: }
11116: $output .= <<"END";
1.1067 raeburn 11117: <br />
1.1053 raeburn 11118: <input type="submit" name="decompress" value="$lt{'extr'}" />
11119: </form>
11120: $noextract
11121: END
11122: return $output;
11123: }
11124:
1.1065 raeburn 11125: sub decompression_utility {
11126: my ($program) = @_;
11127: my @utilities = ('tar','gunzip','bunzip2','unzip');
11128: my $location;
11129: if (grep(/^\Q$program\E$/,@utilities)) {
11130: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11131: '/usr/sbin/') {
11132: if (-x $dir.$program) {
11133: $location = $dir.$program;
11134: last;
11135: }
11136: }
11137: }
11138: return $location;
11139: }
11140:
11141: sub list_archive_contents {
11142: my ($file,$pathsref) = @_;
11143: my (@cmd,$output);
11144: my $needsregexp;
11145: if ($file =~ /\.zip$/) {
11146: @cmd = (&decompression_utility('unzip'),"-l");
11147: $needsregexp = 1;
11148: } elsif (($file =~ m/\.tar\.gz$/) ||
11149: ($file =~ /\.tgz$/)) {
11150: @cmd = (&decompression_utility('tar'),"-ztf");
11151: } elsif ($file =~ /\.tar\.bz2$/) {
11152: @cmd = (&decompression_utility('tar'),"-jtf");
11153: } elsif ($file =~ m|\.tar$|) {
11154: @cmd = (&decompression_utility('tar'),"-tf");
11155: }
11156: if (@cmd) {
11157: undef($!);
11158: undef($@);
11159: if (open(my $fh,"-|", @cmd, $file)) {
11160: while (my $line = <$fh>) {
11161: $output .= $line;
11162: chomp($line);
11163: my $item;
11164: if ($needsregexp) {
11165: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11166: } else {
11167: $item = $line;
11168: }
11169: if ($item ne '') {
11170: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11171: push(@{$pathsref},$item);
11172: }
11173: }
11174: }
11175: close($fh);
11176: }
11177: }
11178: return $output;
11179: }
11180:
1.1053 raeburn 11181: sub decompress_uploaded_file {
11182: my ($file,$dir) = @_;
11183: &Apache::lonnet::appenv({'cgi.file' => $file});
11184: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11185: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11186: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11187: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11188: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11189: my $decompressed = $env{'cgi.decompressed'};
11190: &Apache::lonnet::delenv('cgi.file');
11191: &Apache::lonnet::delenv('cgi.dir');
11192: &Apache::lonnet::delenv('cgi.decompressed');
11193: return ($decompressed,$result);
11194: }
11195:
1.1055 raeburn 11196: sub process_decompression {
11197: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11198: my ($dir,$error,$warning,$output);
11199: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.1075.2.34 raeburn 11200: $error = &mt('Filename not a supported archive file type.').
11201: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11202: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11203: } else {
11204: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11205: if ($docuhome eq 'no_host') {
11206: $error = &mt('Could not determine home server for course.');
11207: } else {
11208: my @ids=&Apache::lonnet::current_machine_ids();
11209: my $currdir = "$dir_root/$destination";
11210: if (grep(/^\Q$docuhome\E$/,@ids)) {
11211: $dir = &LONCAPA::propath($docudom,$docuname).
11212: "$dir_root/$destination";
11213: } else {
11214: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11215: "$dir_root/$docudom/$docuname/$destination";
11216: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11217: $error = &mt('Archive file not found.');
11218: }
11219: }
1.1065 raeburn 11220: my (@to_overwrite,@to_skip);
11221: if ($env{'form.archive_overwrite_total'} > 0) {
11222: my $total = $env{'form.archive_overwrite_total'};
11223: for (my $i=0; $i<$total; $i++) {
11224: if ($env{'form.archive_overwrite_'.$i} == 1) {
11225: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11226: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11227: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11228: }
11229: }
11230: }
11231: my $numskip = scalar(@to_skip);
11232: if (($numskip > 0) &&
11233: ($numskip == $env{'form.archive_itemcount'})) {
11234: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11235: } elsif ($dir eq '') {
1.1055 raeburn 11236: $error = &mt('Directory containing archive file unavailable.');
11237: } elsif (!$error) {
1.1065 raeburn 11238: my ($decompressed,$display);
11239: if ($numskip > 0) {
11240: my $tempdir = time.'_'.$$.int(rand(10000));
11241: mkdir("$dir/$tempdir",0755);
11242: system("mv $dir/$file $dir/$tempdir/$file");
11243: ($decompressed,$display) =
11244: &decompress_uploaded_file($file,"$dir/$tempdir");
11245: foreach my $item (@to_skip) {
11246: if (($item ne '') && ($item !~ /\.\./)) {
11247: if (-f "$dir/$tempdir/$item") {
11248: unlink("$dir/$tempdir/$item");
11249: } elsif (-d "$dir/$tempdir/$item") {
11250: system("rm -rf $dir/$tempdir/$item");
11251: }
11252: }
11253: }
11254: system("mv $dir/$tempdir/* $dir");
11255: rmdir("$dir/$tempdir");
11256: } else {
11257: ($decompressed,$display) =
11258: &decompress_uploaded_file($file,$dir);
11259: }
1.1055 raeburn 11260: if ($decompressed eq 'ok') {
1.1065 raeburn 11261: $output = '<p class="LC_info">'.
11262: &mt('Files extracted successfully from archive.').
11263: '</p>'."\n";
1.1055 raeburn 11264: my ($warning,$result,@contents);
11265: my ($newdirlistref,$newlisterror) =
11266: &Apache::lonnet::dirlist($currdir,$docudom,
11267: $docuname,1);
11268: my (%is_dir,%changes,@newitems);
11269: my $dirptr = 16384;
1.1065 raeburn 11270: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11271: foreach my $dir_line (@{$newdirlistref}) {
11272: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11273: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11274: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11275: push(@newitems,$item);
11276: if ($dirptr&$testdir) {
11277: $is_dir{$item} = 1;
11278: }
11279: $changes{$item} = 1;
11280: }
11281: }
11282: }
11283: if (keys(%changes) > 0) {
11284: foreach my $item (sort(@newitems)) {
11285: if ($changes{$item}) {
11286: push(@contents,$item);
11287: }
11288: }
11289: }
11290: if (@contents > 0) {
1.1067 raeburn 11291: my $wantform;
11292: unless ($env{'form.autoextract_camtasia'}) {
11293: $wantform = 1;
11294: }
1.1056 raeburn 11295: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11296: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11297: $currdir,\%is_dir,
11298: \%children,\%parent,
1.1056 raeburn 11299: \@contents,\%dirorder,
11300: \%titles,$wantform);
1.1055 raeburn 11301: if ($datatable ne '') {
11302: $output .= &archive_options_form('decompressed',$datatable,
11303: $count,$hiddenelem);
1.1065 raeburn 11304: my $startcount = 6;
1.1055 raeburn 11305: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11306: \%titles,\%children);
1.1055 raeburn 11307: }
1.1067 raeburn 11308: if ($env{'form.autoextract_camtasia'}) {
11309: my %displayed;
11310: my $total = 1;
11311: $env{'form.archive_directory'} = [];
11312: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11313: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11314: $path =~ s{/$}{};
11315: my $item;
11316: if ($path ne '') {
11317: $item = "$path/$titles{$i}";
11318: } else {
11319: $item = $titles{$i};
11320: }
11321: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11322: if ($item eq $contents[0]) {
11323: push(@{$env{'form.archive_directory'}},$i);
11324: $env{'form.archive_'.$i} = 'display';
11325: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11326: $displayed{'folder'} = $i;
11327: } elsif ($item eq "$contents[0]/index.html") {
11328: $env{'form.archive_'.$i} = 'display';
11329: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11330: $displayed{'web'} = $i;
11331: } else {
11332: if ($item eq "$contents[0]/media") {
11333: push(@{$env{'form.archive_directory'}},$i);
11334: }
11335: $env{'form.archive_'.$i} = 'dependency';
11336: }
11337: $total ++;
11338: }
11339: for (my $i=1; $i<$total; $i++) {
11340: next if ($i == $displayed{'web'});
11341: next if ($i == $displayed{'folder'});
11342: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11343: }
11344: $env{'form.phase'} = 'decompress_cleanup';
11345: $env{'form.archivedelete'} = 1;
11346: $env{'form.archive_count'} = $total-1;
11347: $output .=
11348: &process_extracted_files('coursedocs',$docudom,
11349: $docuname,$destination,
11350: $dir_root,$hiddenelem);
11351: }
1.1055 raeburn 11352: } else {
11353: $warning = &mt('No new items extracted from archive file.');
11354: }
11355: } else {
11356: $output = $display;
11357: $error = &mt('An error occurred during extraction from the archive file.');
11358: }
11359: }
11360: }
11361: }
11362: if ($error) {
11363: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11364: $error.'</p>'."\n";
11365: }
11366: if ($warning) {
11367: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11368: }
11369: return $output;
11370: }
11371:
11372: sub get_extracted {
1.1056 raeburn 11373: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11374: $titles,$wantform) = @_;
1.1055 raeburn 11375: my $count = 0;
11376: my $depth = 0;
11377: my $datatable;
1.1056 raeburn 11378: my @hierarchy;
1.1055 raeburn 11379: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11380: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11381: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11382: foreach my $item (@{$contents}) {
11383: $count ++;
1.1056 raeburn 11384: @{$dirorder->{$count}} = @hierarchy;
11385: $titles->{$count} = $item;
1.1055 raeburn 11386: &archive_hierarchy($depth,$count,$parent,$children);
11387: if ($wantform) {
11388: $datatable .= &archive_row($is_dir->{$item},$item,
11389: $currdir,$depth,$count);
11390: }
11391: if ($is_dir->{$item}) {
11392: $depth ++;
1.1056 raeburn 11393: push(@hierarchy,$count);
11394: $parent->{$depth} = $count;
1.1055 raeburn 11395: $datatable .=
11396: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11397: \$depth,\$count,\@hierarchy,$dirorder,
11398: $children,$parent,$titles,$wantform);
1.1055 raeburn 11399: $depth --;
1.1056 raeburn 11400: pop(@hierarchy);
1.1055 raeburn 11401: }
11402: }
11403: return ($count,$datatable);
11404: }
11405:
11406: sub recurse_extracted_archive {
1.1056 raeburn 11407: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11408: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11409: my $result='';
1.1056 raeburn 11410: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11411: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11412: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11413: return $result;
11414: }
11415: my $dirptr = 16384;
11416: my ($newdirlistref,$newlisterror) =
11417: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11418: if (ref($newdirlistref) eq 'ARRAY') {
11419: foreach my $dir_line (@{$newdirlistref}) {
11420: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11421: unless ($item =~ /^\.+$/) {
11422: $$count ++;
1.1056 raeburn 11423: @{$dirorder->{$$count}} = @{$hierarchy};
11424: $titles->{$$count} = $item;
1.1055 raeburn 11425: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11426:
1.1055 raeburn 11427: my $is_dir;
11428: if ($dirptr&$testdir) {
11429: $is_dir = 1;
11430: }
11431: if ($wantform) {
11432: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11433: }
11434: if ($is_dir) {
11435: $$depth ++;
1.1056 raeburn 11436: push(@{$hierarchy},$$count);
11437: $parent->{$$depth} = $$count;
1.1055 raeburn 11438: $result .=
11439: &recurse_extracted_archive("$currdir/$item",$docudom,
11440: $docuname,$depth,$count,
1.1056 raeburn 11441: $hierarchy,$dirorder,$children,
11442: $parent,$titles,$wantform);
1.1055 raeburn 11443: $$depth --;
1.1056 raeburn 11444: pop(@{$hierarchy});
1.1055 raeburn 11445: }
11446: }
11447: }
11448: }
11449: return $result;
11450: }
11451:
11452: sub archive_hierarchy {
11453: my ($depth,$count,$parent,$children) =@_;
11454: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11455: if (exists($parent->{$depth})) {
11456: $children->{$parent->{$depth}} .= $count.':';
11457: }
11458: }
11459: return;
11460: }
11461:
11462: sub archive_row {
11463: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11464: my ($name) = ($item =~ m{([^/]+)$});
11465: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11466: 'display' => 'Add as file',
1.1055 raeburn 11467: 'dependency' => 'Include as dependency',
11468: 'discard' => 'Discard',
11469: );
11470: if ($is_dir) {
1.1059 raeburn 11471: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11472: }
1.1056 raeburn 11473: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11474: my $offset = 0;
1.1055 raeburn 11475: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11476: $offset ++;
1.1065 raeburn 11477: if ($action ne 'display') {
11478: $offset ++;
11479: }
1.1055 raeburn 11480: $output .= '<td><span class="LC_nobreak">'.
11481: '<label><input type="radio" name="archive_'.$count.
11482: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11483: my $text = $choices{$action};
11484: if ($is_dir) {
11485: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11486: if ($action eq 'display') {
1.1059 raeburn 11487: $text = &mt('Add as folder');
1.1055 raeburn 11488: }
1.1056 raeburn 11489: } else {
11490: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11491:
11492: }
11493: $output .= ' /> '.$choices{$action}.'</label></span>';
11494: if ($action eq 'dependency') {
11495: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11496: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11497: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11498: '<option value=""></option>'."\n".
11499: '</select>'."\n".
11500: '</div>';
1.1059 raeburn 11501: } elsif ($action eq 'display') {
11502: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11503: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11504: '</div>';
1.1055 raeburn 11505: }
1.1056 raeburn 11506: $output .= '</td>';
1.1055 raeburn 11507: }
11508: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11509: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11510: for (my $i=0; $i<$depth; $i++) {
11511: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11512: }
11513: if ($is_dir) {
11514: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11515: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11516: } else {
11517: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11518: }
11519: $output .= ' '.$name.'</td>'."\n".
11520: &end_data_table_row();
11521: return $output;
11522: }
11523:
11524: sub archive_options_form {
1.1065 raeburn 11525: my ($form,$display,$count,$hiddenelem) = @_;
11526: my %lt = &Apache::lonlocal::texthash(
11527: perm => 'Permanently remove archive file?',
11528: hows => 'How should each extracted item be incorporated in the course?',
11529: cont => 'Content actions for all',
11530: addf => 'Add as folder/file',
11531: incd => 'Include as dependency for a displayed file',
11532: disc => 'Discard',
11533: no => 'No',
11534: yes => 'Yes',
11535: save => 'Save',
11536: );
11537: my $output = <<"END";
11538: <form name="$form" method="post" action="">
11539: <p><span class="LC_nobreak">$lt{'perm'}
11540: <label>
11541: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11542: </label>
11543:
11544: <label>
11545: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11546: </span>
11547: </p>
11548: <input type="hidden" name="phase" value="decompress_cleanup" />
11549: <br />$lt{'hows'}
11550: <div class="LC_columnSection">
11551: <fieldset>
11552: <legend>$lt{'cont'}</legend>
11553: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11554: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11555: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11556: </fieldset>
11557: </div>
11558: END
11559: return $output.
1.1055 raeburn 11560: &start_data_table()."\n".
1.1065 raeburn 11561: $display."\n".
1.1055 raeburn 11562: &end_data_table()."\n".
11563: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11564: $hiddenelem.
1.1065 raeburn 11565: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11566: '</form>';
11567: }
11568:
11569: sub archive_javascript {
1.1056 raeburn 11570: my ($startcount,$numitems,$titles,$children) = @_;
11571: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11572: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11573: my $scripttag = <<START;
11574: <script type="text/javascript">
11575: // <![CDATA[
11576:
11577: function checkAll(form,prefix) {
11578: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11579: for (var i=0; i < form.elements.length; i++) {
11580: var id = form.elements[i].id;
11581: if ((id != '') && (id != undefined)) {
11582: if (idstr.test(id)) {
11583: if (form.elements[i].type == 'radio') {
11584: form.elements[i].checked = true;
1.1056 raeburn 11585: var nostart = i-$startcount;
1.1059 raeburn 11586: var offset = nostart%7;
11587: var count = (nostart-offset)/7;
1.1056 raeburn 11588: dependencyCheck(form,count,offset);
1.1055 raeburn 11589: }
11590: }
11591: }
11592: }
11593: }
11594:
11595: function propagateCheck(form,count) {
11596: if (count > 0) {
1.1059 raeburn 11597: var startelement = $startcount + ((count-1) * 7);
11598: for (var j=1; j<6; j++) {
11599: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11600: var item = startelement + j;
11601: if (form.elements[item].type == 'radio') {
11602: if (form.elements[item].checked) {
11603: containerCheck(form,count,j);
11604: break;
11605: }
1.1055 raeburn 11606: }
11607: }
11608: }
11609: }
11610: }
11611:
11612: numitems = $numitems
1.1056 raeburn 11613: var titles = new Array(numitems);
11614: var parents = new Array(numitems);
1.1055 raeburn 11615: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11616: parents[i] = new Array;
1.1055 raeburn 11617: }
1.1059 raeburn 11618: var maintitle = '$maintitle';
1.1055 raeburn 11619:
11620: START
11621:
1.1056 raeburn 11622: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11623: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11624: for (my $i=0; $i<@contents; $i ++) {
11625: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11626: }
11627: }
11628:
1.1056 raeburn 11629: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11630: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11631: }
11632:
1.1055 raeburn 11633: $scripttag .= <<END;
11634:
11635: function containerCheck(form,count,offset) {
11636: if (count > 0) {
1.1056 raeburn 11637: dependencyCheck(form,count,offset);
1.1059 raeburn 11638: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11639: form.elements[item].checked = true;
11640: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11641: if (parents[count].length > 0) {
11642: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11643: containerCheck(form,parents[count][j],offset);
11644: }
11645: }
11646: }
11647: }
11648: }
11649:
11650: function dependencyCheck(form,count,offset) {
11651: if (count > 0) {
1.1059 raeburn 11652: var chosen = (offset+$startcount)+7*(count-1);
11653: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11654: var currtype = form.elements[depitem].type;
11655: if (form.elements[chosen].value == 'dependency') {
11656: document.getElementById('arc_depon_'+count).style.display='block';
11657: form.elements[depitem].options.length = 0;
11658: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 11659: for (var i=1; i<=numitems; i++) {
11660: if (i == count) {
11661: continue;
11662: }
1.1059 raeburn 11663: var startelement = $startcount + (i-1) * 7;
11664: for (var j=1; j<6; j++) {
11665: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11666: var item = startelement + j;
11667: if (form.elements[item].type == 'radio') {
11668: if (form.elements[item].checked) {
11669: if (form.elements[item].value == 'display') {
11670: var n = form.elements[depitem].options.length;
11671: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11672: }
11673: }
11674: }
11675: }
11676: }
11677: }
11678: } else {
11679: document.getElementById('arc_depon_'+count).style.display='none';
11680: form.elements[depitem].options.length = 0;
11681: form.elements[depitem].options[0] = new Option('Select','',true,true);
11682: }
1.1059 raeburn 11683: titleCheck(form,count,offset);
1.1056 raeburn 11684: }
11685: }
11686:
11687: function propagateSelect(form,count,offset) {
11688: if (count > 0) {
1.1065 raeburn 11689: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11690: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11691: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11692: if (parents[count].length > 0) {
11693: for (var j=0; j<parents[count].length; j++) {
11694: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11695: }
11696: }
11697: }
11698: }
11699: }
1.1056 raeburn 11700:
11701: function containerSelect(form,count,offset,picked) {
11702: if (count > 0) {
1.1065 raeburn 11703: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11704: if (form.elements[item].type == 'radio') {
11705: if (form.elements[item].value == 'dependency') {
11706: if (form.elements[item+1].type == 'select-one') {
11707: for (var i=0; i<form.elements[item+1].options.length; i++) {
11708: if (form.elements[item+1].options[i].value == picked) {
11709: form.elements[item+1].selectedIndex = i;
11710: break;
11711: }
11712: }
11713: }
11714: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11715: if (parents[count].length > 0) {
11716: for (var j=0; j<parents[count].length; j++) {
11717: containerSelect(form,parents[count][j],offset,picked);
11718: }
11719: }
11720: }
11721: }
11722: }
11723: }
11724: }
11725:
1.1059 raeburn 11726: function titleCheck(form,count,offset) {
11727: if (count > 0) {
11728: var chosen = (offset+$startcount)+7*(count-1);
11729: var depitem = $startcount + ((count-1) * 7) + 2;
11730: var currtype = form.elements[depitem].type;
11731: if (form.elements[chosen].value == 'display') {
11732: document.getElementById('arc_title_'+count).style.display='block';
11733: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11734: document.getElementById('archive_title_'+count).value=maintitle;
11735: }
11736: } else {
11737: document.getElementById('arc_title_'+count).style.display='none';
11738: if (currtype == 'text') {
11739: document.getElementById('archive_title_'+count).value='';
11740: }
11741: }
11742: }
11743: return;
11744: }
11745:
1.1055 raeburn 11746: // ]]>
11747: </script>
11748: END
11749: return $scripttag;
11750: }
11751:
11752: sub process_extracted_files {
1.1067 raeburn 11753: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11754: my $numitems = $env{'form.archive_count'};
11755: return unless ($numitems);
11756: my @ids=&Apache::lonnet::current_machine_ids();
11757: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11758: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11759: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11760: if (grep(/^\Q$docuhome\E$/,@ids)) {
11761: $prefix = &LONCAPA::propath($docudom,$docuname);
11762: $pathtocheck = "$dir_root/$destination";
11763: $dir = $dir_root;
11764: $ishome = 1;
11765: } else {
11766: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11767: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11768: $dir = "$dir_root/$docudom/$docuname";
11769: }
11770: my $currdir = "$dir_root/$destination";
11771: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11772: if ($env{'form.folderpath'}) {
11773: my @items = split('&',$env{'form.folderpath'});
11774: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 11775: if ($env{'form.folderpath'} =~ /\:1$/) {
11776: $containers{'0'}='page';
11777: } else {
11778: $containers{'0'}='sequence';
11779: }
1.1055 raeburn 11780: }
11781: my @archdirs = &get_env_multiple('form.archive_directory');
11782: if ($numitems) {
11783: for (my $i=1; $i<=$numitems; $i++) {
11784: my $path = $env{'form.archive_content_'.$i};
11785: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11786: my $item = $1;
11787: $toplevelitems{$item} = $i;
11788: if (grep(/^\Q$i\E$/,@archdirs)) {
11789: $is_dir{$item} = 1;
11790: }
11791: }
11792: }
11793: }
1.1067 raeburn 11794: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11795: if (keys(%toplevelitems) > 0) {
11796: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11797: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11798: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11799: }
1.1066 raeburn 11800: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11801: if ($numitems) {
11802: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 11803: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11804: my $path = $env{'form.archive_content_'.$i};
11805: if ($path =~ /^\Q$pathtocheck\E/) {
11806: if ($env{'form.archive_'.$i} eq 'discard') {
11807: if ($prefix ne '' && $path ne '') {
11808: if (-e $prefix.$path) {
1.1066 raeburn 11809: if ((@archdirs > 0) &&
11810: (grep(/^\Q$i\E$/,@archdirs))) {
11811: $todeletedir{$prefix.$path} = 1;
11812: } else {
11813: $todelete{$prefix.$path} = 1;
11814: }
1.1055 raeburn 11815: }
11816: }
11817: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11818: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11819: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11820: $docstitle = $env{'form.archive_title_'.$i};
11821: if ($docstitle eq '') {
11822: $docstitle = $title;
11823: }
1.1055 raeburn 11824: $outer = 0;
1.1056 raeburn 11825: if (ref($dirorder{$i}) eq 'ARRAY') {
11826: if (@{$dirorder{$i}} > 0) {
11827: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11828: if ($env{'form.archive_'.$item} eq 'display') {
11829: $outer = $item;
11830: last;
11831: }
11832: }
11833: }
11834: }
11835: my ($errtext,$fatal) =
11836: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11837: '/'.$folders{$outer}.'.'.
11838: $containers{$outer});
11839: next if ($fatal);
11840: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11841: if ($context eq 'coursedocs') {
1.1056 raeburn 11842: $mapinner{$i} = time;
1.1055 raeburn 11843: $folders{$i} = 'default_'.$mapinner{$i};
11844: $containers{$i} = 'sequence';
11845: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11846: $folders{$i}.'.'.$containers{$i};
11847: my $newidx = &LONCAPA::map::getresidx();
11848: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11849: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11850: push(@LONCAPA::map::order,$newidx);
11851: my ($outtext,$errtext) =
11852: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11853: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11854: '.'.$containers{$outer},1,1);
1.1056 raeburn 11855: $newseqid{$i} = $newidx;
1.1067 raeburn 11856: unless ($errtext) {
11857: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11858: }
1.1055 raeburn 11859: }
11860: } else {
11861: if ($context eq 'coursedocs') {
11862: my $newidx=&LONCAPA::map::getresidx();
11863: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11864: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11865: $title;
11866: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11867: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11868: }
11869: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11870: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11871: }
11872: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11873: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11874: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11875: unless ($ishome) {
11876: my $fetch = "$newdest{$i}/$title";
11877: $fetch =~ s/^\Q$prefix$dir\E//;
11878: $prompttofetch{$fetch} = 1;
11879: }
1.1055 raeburn 11880: }
11881: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11882: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11883: push(@LONCAPA::map::order, $newidx);
11884: my ($outtext,$errtext)=
11885: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11886: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11887: '.'.$containers{$outer},1,1);
1.1067 raeburn 11888: unless ($errtext) {
11889: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11890: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11891: }
11892: }
1.1055 raeburn 11893: }
11894: }
1.1075.2.11 raeburn 11895: }
11896: } else {
11897: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11898: }
11899: }
11900: for (my $i=1; $i<=$numitems; $i++) {
11901: next unless ($env{'form.archive_'.$i} eq 'dependency');
11902: my $path = $env{'form.archive_content_'.$i};
11903: if ($path =~ /^\Q$pathtocheck\E/) {
11904: my ($title) = ($path =~ m{/([^/]+)$});
11905: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11906: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11907: if (ref($dirorder{$i}) eq 'ARRAY') {
11908: my ($itemidx,$fullpath,$relpath);
11909: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11910: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11911: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 11912: if ($dirorder{$i}->[$j] eq $container) {
11913: $itemidx = $j;
1.1056 raeburn 11914: }
11915: }
1.1075.2.11 raeburn 11916: }
11917: if ($itemidx eq '') {
11918: $itemidx = 0;
11919: }
11920: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11921: if ($mapinner{$referrer{$i}}) {
11922: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11923: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11924: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11925: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11926: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11927: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11928: if (!-e $fullpath) {
11929: mkdir($fullpath,0755);
1.1056 raeburn 11930: }
11931: }
1.1075.2.11 raeburn 11932: } else {
11933: last;
1.1056 raeburn 11934: }
1.1075.2.11 raeburn 11935: }
11936: }
11937: } elsif ($newdest{$referrer{$i}}) {
11938: $fullpath = $newdest{$referrer{$i}};
11939: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11940: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11941: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11942: last;
11943: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11944: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11945: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11946: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11947: if (!-e $fullpath) {
11948: mkdir($fullpath,0755);
1.1056 raeburn 11949: }
11950: }
1.1075.2.11 raeburn 11951: } else {
11952: last;
1.1056 raeburn 11953: }
1.1075.2.11 raeburn 11954: }
11955: }
11956: if ($fullpath ne '') {
11957: if (-e "$prefix$path") {
11958: system("mv $prefix$path $fullpath/$title");
11959: }
11960: if (-e "$fullpath/$title") {
11961: my $showpath;
11962: if ($relpath ne '') {
11963: $showpath = "$relpath/$title";
11964: } else {
11965: $showpath = "/$title";
1.1056 raeburn 11966: }
1.1075.2.11 raeburn 11967: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
11968: }
11969: unless ($ishome) {
11970: my $fetch = "$fullpath/$title";
11971: $fetch =~ s/^\Q$prefix$dir\E//;
11972: $prompttofetch{$fetch} = 1;
1.1055 raeburn 11973: }
11974: }
11975: }
1.1075.2.11 raeburn 11976: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
11977: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
11978: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 11979: }
11980: } else {
1.1075.2.11 raeburn 11981: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 11982: }
11983: }
11984: if (keys(%todelete)) {
11985: foreach my $key (keys(%todelete)) {
11986: unlink($key);
1.1066 raeburn 11987: }
11988: }
11989: if (keys(%todeletedir)) {
11990: foreach my $key (keys(%todeletedir)) {
11991: rmdir($key);
11992: }
11993: }
11994: foreach my $dir (sort(keys(%is_dir))) {
11995: if (($pathtocheck ne '') && ($dir ne '')) {
11996: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 11997: }
11998: }
1.1067 raeburn 11999: if ($result ne '') {
12000: $output .= '<ul>'."\n".
12001: $result."\n".
12002: '</ul>';
12003: }
12004: unless ($ishome) {
12005: my $replicationfail;
12006: foreach my $item (keys(%prompttofetch)) {
12007: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12008: unless ($fetchresult eq 'ok') {
12009: $replicationfail .= '<li>'.$item.'</li>'."\n";
12010: }
12011: }
12012: if ($replicationfail) {
12013: $output .= '<p class="LC_error">'.
12014: &mt('Course home server failed to retrieve:').'<ul>'.
12015: $replicationfail.
12016: '</ul></p>';
12017: }
12018: }
1.1055 raeburn 12019: } else {
12020: $warning = &mt('No items found in archive.');
12021: }
12022: if ($error) {
12023: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12024: $error.'</p>'."\n";
12025: }
12026: if ($warning) {
12027: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12028: }
12029: return $output;
12030: }
12031:
1.1066 raeburn 12032: sub cleanup_empty_dirs {
12033: my ($path) = @_;
12034: if (($path ne '') && (-d $path)) {
12035: if (opendir(my $dirh,$path)) {
12036: my @dircontents = grep(!/^\./,readdir($dirh));
12037: my $numitems = 0;
12038: foreach my $item (@dircontents) {
12039: if (-d "$path/$item") {
1.1075.2.28 raeburn 12040: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12041: if (-e "$path/$item") {
12042: $numitems ++;
12043: }
12044: } else {
12045: $numitems ++;
12046: }
12047: }
12048: if ($numitems == 0) {
12049: rmdir($path);
12050: }
12051: closedir($dirh);
12052: }
12053: }
12054: return;
12055: }
12056:
1.41 ng 12057: =pod
1.45 matthew 12058:
1.1068 raeburn 12059: =item &get_folder_hierarchy()
12060:
12061: Provides hierarchy of names of folders/sub-folders containing the current
12062: item,
12063:
12064: Inputs: 3
12065: - $navmap - navmaps object
12066:
12067: - $map - url for map (either the trigger itself, or map containing
12068: the resource, which is the trigger).
12069:
12070: - $showitem - 1 => show title for map itself; 0 => do not show.
12071:
12072: Outputs: 1 @pathitems - array of folder/subfolder names.
12073:
12074: =cut
12075:
12076: sub get_folder_hierarchy {
12077: my ($navmap,$map,$showitem) = @_;
12078: my @pathitems;
12079: if (ref($navmap)) {
12080: my $mapres = $navmap->getResourceByUrl($map);
12081: if (ref($mapres)) {
12082: my $pcslist = $mapres->map_hierarchy();
12083: if ($pcslist ne '') {
12084: my @pcs = split(/,/,$pcslist);
12085: foreach my $pc (@pcs) {
12086: if ($pc == 1) {
1.1075.2.38 raeburn 12087: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12088: } else {
12089: my $res = $navmap->getByMapPc($pc);
12090: if (ref($res)) {
12091: my $title = $res->compTitle();
12092: $title =~ s/\W+/_/g;
12093: if ($title ne '') {
12094: push(@pathitems,$title);
12095: }
12096: }
12097: }
12098: }
12099: }
1.1071 raeburn 12100: if ($showitem) {
12101: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12102: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12103: } else {
12104: my $maptitle = $mapres->compTitle();
12105: $maptitle =~ s/\W+/_/g;
12106: if ($maptitle ne '') {
12107: push(@pathitems,$maptitle);
12108: }
1.1068 raeburn 12109: }
12110: }
12111: }
12112: }
12113: return @pathitems;
12114: }
12115:
12116: =pod
12117:
1.1015 raeburn 12118: =item * &get_turnedin_filepath()
12119:
12120: Determines path in a user's portfolio file for storage of files uploaded
12121: to a specific essayresponse or dropbox item.
12122:
12123: Inputs: 3 required + 1 optional.
12124: $symb is symb for resource, $uname and $udom are for current user (required).
12125: $caller is optional (can be "submission", if routine is called when storing
12126: an upoaded file when "Submit Answer" button was pressed).
12127:
12128: Returns array containing $path and $multiresp.
12129: $path is path in portfolio. $multiresp is 1 if this resource contains more
12130: than one file upload item. Callers of routine should append partid as a
12131: subdirectory to $path in cases where $multiresp is 1.
12132:
12133: Called by: homework/essayresponse.pm and homework/structuretags.pm
12134:
12135: =cut
12136:
12137: sub get_turnedin_filepath {
12138: my ($symb,$uname,$udom,$caller) = @_;
12139: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12140: my $turnindir;
12141: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12142: $turnindir = $userhash{'turnindir'};
12143: my ($path,$multiresp);
12144: if ($turnindir eq '') {
12145: if ($caller eq 'submission') {
12146: $turnindir = &mt('turned in');
12147: $turnindir =~ s/\W+/_/g;
12148: my %newhash = (
12149: 'turnindir' => $turnindir,
12150: );
12151: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12152: }
12153: }
12154: if ($turnindir ne '') {
12155: $path = '/'.$turnindir.'/';
12156: my ($multipart,$turnin,@pathitems);
12157: my $navmap = Apache::lonnavmaps::navmap->new();
12158: if (defined($navmap)) {
12159: my $mapres = $navmap->getResourceByUrl($map);
12160: if (ref($mapres)) {
12161: my $pcslist = $mapres->map_hierarchy();
12162: if ($pcslist ne '') {
12163: foreach my $pc (split(/,/,$pcslist)) {
12164: my $res = $navmap->getByMapPc($pc);
12165: if (ref($res)) {
12166: my $title = $res->compTitle();
12167: $title =~ s/\W+/_/g;
12168: if ($title ne '') {
1.1075.2.48 raeburn 12169: if (($pc > 1) && (length($title) > 12)) {
12170: $title = substr($title,0,12);
12171: }
1.1015 raeburn 12172: push(@pathitems,$title);
12173: }
12174: }
12175: }
12176: }
12177: my $maptitle = $mapres->compTitle();
12178: $maptitle =~ s/\W+/_/g;
12179: if ($maptitle ne '') {
1.1075.2.48 raeburn 12180: if (length($maptitle) > 12) {
12181: $maptitle = substr($maptitle,0,12);
12182: }
1.1015 raeburn 12183: push(@pathitems,$maptitle);
12184: }
12185: unless ($env{'request.state'} eq 'construct') {
12186: my $res = $navmap->getBySymb($symb);
12187: if (ref($res)) {
12188: my $partlist = $res->parts();
12189: my $totaluploads = 0;
12190: if (ref($partlist) eq 'ARRAY') {
12191: foreach my $part (@{$partlist}) {
12192: my @types = $res->responseType($part);
12193: my @ids = $res->responseIds($part);
12194: for (my $i=0; $i < scalar(@ids); $i++) {
12195: if ($types[$i] eq 'essay') {
12196: my $partid = $part.'_'.$ids[$i];
12197: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12198: $totaluploads ++;
12199: }
12200: }
12201: }
12202: }
12203: if ($totaluploads > 1) {
12204: $multiresp = 1;
12205: }
12206: }
12207: }
12208: }
12209: } else {
12210: return;
12211: }
12212: } else {
12213: return;
12214: }
12215: my $restitle=&Apache::lonnet::gettitle($symb);
12216: $restitle =~ s/\W+/_/g;
12217: if ($restitle eq '') {
12218: $restitle = ($resurl =~ m{/[^/]+$});
12219: if ($restitle eq '') {
12220: $restitle = time;
12221: }
12222: }
1.1075.2.48 raeburn 12223: if (length($restitle) > 12) {
12224: $restitle = substr($restitle,0,12);
12225: }
1.1015 raeburn 12226: push(@pathitems,$restitle);
12227: $path .= join('/',@pathitems);
12228: }
12229: return ($path,$multiresp);
12230: }
12231:
12232: =pod
12233:
1.464 albertel 12234: =back
1.41 ng 12235:
1.112 bowersj2 12236: =head1 CSV Upload/Handling functions
1.38 albertel 12237:
1.41 ng 12238: =over 4
12239:
1.648 raeburn 12240: =item * &upfile_store($r)
1.41 ng 12241:
12242: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12243: needs $env{'form.upfile'}
1.41 ng 12244: returns $datatoken to be put into hidden field
12245:
12246: =cut
1.31 albertel 12247:
12248: sub upfile_store {
12249: my $r=shift;
1.258 albertel 12250: $env{'form.upfile'}=~s/\r/\n/gs;
12251: $env{'form.upfile'}=~s/\f/\n/gs;
12252: $env{'form.upfile'}=~s/\n+/\n/gs;
12253: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12254:
1.258 albertel 12255: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12256: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12257: {
1.158 raeburn 12258: my $datafile = $r->dir_config('lonDaemons').
12259: '/tmp/'.$datatoken.'.tmp';
12260: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12261: print $fh $env{'form.upfile'};
1.158 raeburn 12262: close($fh);
12263: }
1.31 albertel 12264: }
12265: return $datatoken;
12266: }
12267:
1.56 matthew 12268: =pod
12269:
1.648 raeburn 12270: =item * &load_tmp_file($r)
1.41 ng 12271:
12272: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12273: needs $env{'form.datatoken'},
12274: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12275:
12276: =cut
1.31 albertel 12277:
12278: sub load_tmp_file {
12279: my $r=shift;
12280: my @studentdata=();
12281: {
1.158 raeburn 12282: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12283: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12284: if ( open(my $fh,"<$studentfile") ) {
12285: @studentdata=<$fh>;
12286: close($fh);
12287: }
1.31 albertel 12288: }
1.258 albertel 12289: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12290: }
12291:
1.56 matthew 12292: =pod
12293:
1.648 raeburn 12294: =item * &upfile_record_sep()
1.41 ng 12295:
12296: Separate uploaded file into records
12297: returns array of records,
1.258 albertel 12298: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12299:
12300: =cut
1.31 albertel 12301:
12302: sub upfile_record_sep {
1.258 albertel 12303: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12304: } else {
1.248 albertel 12305: my @records;
1.258 albertel 12306: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12307: if ($line=~/^\s*$/) { next; }
12308: push(@records,$line);
12309: }
12310: return @records;
1.31 albertel 12311: }
12312: }
12313:
1.56 matthew 12314: =pod
12315:
1.648 raeburn 12316: =item * &record_sep($record)
1.41 ng 12317:
1.258 albertel 12318: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12319:
12320: =cut
12321:
1.263 www 12322: sub takeleft {
12323: my $index=shift;
12324: return substr('0000'.$index,-4,4);
12325: }
12326:
1.31 albertel 12327: sub record_sep {
12328: my $record=shift;
12329: my %components=();
1.258 albertel 12330: if ($env{'form.upfiletype'} eq 'xml') {
12331: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12332: my $i=0;
1.356 albertel 12333: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12334: $field=~s/^(\"|\')//;
12335: $field=~s/(\"|\')$//;
1.263 www 12336: $components{&takeleft($i)}=$field;
1.31 albertel 12337: $i++;
12338: }
1.258 albertel 12339: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12340: my $i=0;
1.356 albertel 12341: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12342: $field=~s/^(\"|\')//;
12343: $field=~s/(\"|\')$//;
1.263 www 12344: $components{&takeleft($i)}=$field;
1.31 albertel 12345: $i++;
12346: }
12347: } else {
1.561 www 12348: my $separator=',';
1.480 banghart 12349: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12350: $separator=';';
1.480 banghart 12351: }
1.31 albertel 12352: my $i=0;
1.561 www 12353: # the character we are looking for to indicate the end of a quote or a record
12354: my $looking_for=$separator;
12355: # do not add the characters to the fields
12356: my $ignore=0;
12357: # we just encountered a separator (or the beginning of the record)
12358: my $just_found_separator=1;
12359: # store the field we are working on here
12360: my $field='';
12361: # work our way through all characters in record
12362: foreach my $character ($record=~/(.)/g) {
12363: if ($character eq $looking_for) {
12364: if ($character ne $separator) {
12365: # Found the end of a quote, again looking for separator
12366: $looking_for=$separator;
12367: $ignore=1;
12368: } else {
12369: # Found a separator, store away what we got
12370: $components{&takeleft($i)}=$field;
12371: $i++;
12372: $just_found_separator=1;
12373: $ignore=0;
12374: $field='';
12375: }
12376: next;
12377: }
12378: # single or double quotation marks after a separator indicate beginning of a quote
12379: # we are now looking for the end of the quote and need to ignore separators
12380: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12381: $looking_for=$character;
12382: next;
12383: }
12384: # ignore would be true after we reached the end of a quote
12385: if ($ignore) { next; }
12386: if (($just_found_separator) && ($character=~/\s/)) { next; }
12387: $field.=$character;
12388: $just_found_separator=0;
1.31 albertel 12389: }
1.561 www 12390: # catch the very last entry, since we never encountered the separator
12391: $components{&takeleft($i)}=$field;
1.31 albertel 12392: }
12393: return %components;
12394: }
12395:
1.144 matthew 12396: ######################################################
12397: ######################################################
12398:
1.56 matthew 12399: =pod
12400:
1.648 raeburn 12401: =item * &upfile_select_html()
1.41 ng 12402:
1.144 matthew 12403: Return HTML code to select a file from the users machine and specify
12404: the file type.
1.41 ng 12405:
12406: =cut
12407:
1.144 matthew 12408: ######################################################
12409: ######################################################
1.31 albertel 12410: sub upfile_select_html {
1.144 matthew 12411: my %Types = (
12412: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12413: semisv => &mt('Semicolon separated values'),
1.144 matthew 12414: space => &mt('Space separated'),
12415: tab => &mt('Tabulator separated'),
12416: # xml => &mt('HTML/XML'),
12417: );
12418: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12419: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12420: foreach my $type (sort(keys(%Types))) {
12421: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12422: }
12423: $Str .= "</select>\n";
12424: return $Str;
1.31 albertel 12425: }
12426:
1.301 albertel 12427: sub get_samples {
12428: my ($records,$toget) = @_;
12429: my @samples=({});
12430: my $got=0;
12431: foreach my $rec (@$records) {
12432: my %temp = &record_sep($rec);
12433: if (! grep(/\S/, values(%temp))) { next; }
12434: if (%temp) {
12435: $samples[$got]=\%temp;
12436: $got++;
12437: if ($got == $toget) { last; }
12438: }
12439: }
12440: return \@samples;
12441: }
12442:
1.144 matthew 12443: ######################################################
12444: ######################################################
12445:
1.56 matthew 12446: =pod
12447:
1.648 raeburn 12448: =item * &csv_print_samples($r,$records)
1.41 ng 12449:
12450: Prints a table of sample values from each column uploaded $r is an
12451: Apache Request ref, $records is an arrayref from
12452: &Apache::loncommon::upfile_record_sep
12453:
12454: =cut
12455:
1.144 matthew 12456: ######################################################
12457: ######################################################
1.31 albertel 12458: sub csv_print_samples {
12459: my ($r,$records) = @_;
1.662 bisitz 12460: my $samples = &get_samples($records,5);
1.301 albertel 12461:
1.594 raeburn 12462: $r->print(&mt('Samples').'<br />'.&start_data_table().
12463: &start_data_table_header_row());
1.356 albertel 12464: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12465: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12466: $r->print(&end_data_table_header_row());
1.301 albertel 12467: foreach my $hash (@$samples) {
1.594 raeburn 12468: $r->print(&start_data_table_row());
1.356 albertel 12469: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12470: $r->print('<td>');
1.356 albertel 12471: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12472: $r->print('</td>');
12473: }
1.594 raeburn 12474: $r->print(&end_data_table_row());
1.31 albertel 12475: }
1.594 raeburn 12476: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12477: }
12478:
1.144 matthew 12479: ######################################################
12480: ######################################################
12481:
1.56 matthew 12482: =pod
12483:
1.648 raeburn 12484: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12485:
12486: Prints a table to create associations between values and table columns.
1.144 matthew 12487:
1.41 ng 12488: $r is an Apache Request ref,
12489: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12490: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12491:
12492: =cut
12493:
1.144 matthew 12494: ######################################################
12495: ######################################################
1.31 albertel 12496: sub csv_print_select_table {
12497: my ($r,$records,$d) = @_;
1.301 albertel 12498: my $i=0;
12499: my $samples = &get_samples($records,1);
1.144 matthew 12500: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12501: &start_data_table().&start_data_table_header_row().
1.144 matthew 12502: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12503: '<th>'.&mt('Column').'</th>'.
12504: &end_data_table_header_row()."\n");
1.356 albertel 12505: foreach my $array_ref (@$d) {
12506: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12507: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12508:
1.875 bisitz 12509: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12510: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12511: $r->print('<option value="none"></option>');
1.356 albertel 12512: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12513: $r->print('<option value="'.$sample.'"'.
12514: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12515: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12516: }
1.594 raeburn 12517: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12518: $i++;
12519: }
1.594 raeburn 12520: $r->print(&end_data_table());
1.31 albertel 12521: $i--;
12522: return $i;
12523: }
1.56 matthew 12524:
1.144 matthew 12525: ######################################################
12526: ######################################################
12527:
1.56 matthew 12528: =pod
1.31 albertel 12529:
1.648 raeburn 12530: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12531:
12532: Prints a table of sample values from the upload and can make associate samples to internal names.
12533:
12534: $r is an Apache Request ref,
12535: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12536: $d is an array of 2 element arrays (internal name, displayed name)
12537:
12538: =cut
12539:
1.144 matthew 12540: ######################################################
12541: ######################################################
1.31 albertel 12542: sub csv_samples_select_table {
12543: my ($r,$records,$d) = @_;
12544: my $i=0;
1.144 matthew 12545: #
1.662 bisitz 12546: my $max_samples = 5;
12547: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12548: $r->print(&start_data_table().
12549: &start_data_table_header_row().'<th>'.
12550: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12551: &end_data_table_header_row());
1.301 albertel 12552:
12553: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12554: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12555: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12556: foreach my $option (@$d) {
12557: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12558: $r->print('<option value="'.$value.'"'.
1.253 albertel 12559: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12560: $display.'</option>');
1.31 albertel 12561: }
12562: $r->print('</select></td><td>');
1.662 bisitz 12563: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12564: if (defined($samples->[$line]{$key})) {
12565: $r->print($samples->[$line]{$key}."<br />\n");
12566: }
12567: }
1.594 raeburn 12568: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12569: $i++;
12570: }
1.594 raeburn 12571: $r->print(&end_data_table());
1.31 albertel 12572: $i--;
12573: return($i);
1.115 matthew 12574: }
12575:
1.144 matthew 12576: ######################################################
12577: ######################################################
12578:
1.115 matthew 12579: =pod
12580:
1.648 raeburn 12581: =item * &clean_excel_name($name)
1.115 matthew 12582:
12583: Returns a replacement for $name which does not contain any illegal characters.
12584:
12585: =cut
12586:
1.144 matthew 12587: ######################################################
12588: ######################################################
1.115 matthew 12589: sub clean_excel_name {
12590: my ($name) = @_;
12591: $name =~ s/[:\*\?\/\\]//g;
12592: if (length($name) > 31) {
12593: $name = substr($name,0,31);
12594: }
12595: return $name;
1.25 albertel 12596: }
1.84 albertel 12597:
1.85 albertel 12598: =pod
12599:
1.648 raeburn 12600: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12601:
12602: Returns either 1 or undef
12603:
12604: 1 if the part is to be hidden, undef if it is to be shown
12605:
12606: Arguments are:
12607:
12608: $id the id of the part to be checked
12609: $symb, optional the symb of the resource to check
12610: $udom, optional the domain of the user to check for
12611: $uname, optional the username of the user to check for
12612:
12613: =cut
1.84 albertel 12614:
12615: sub check_if_partid_hidden {
12616: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12617: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12618: $symb,$udom,$uname);
1.141 albertel 12619: my $truth=1;
12620: #if the string starts with !, then the list is the list to show not hide
12621: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12622: my @hiddenlist=split(/,/,$hiddenparts);
12623: foreach my $checkid (@hiddenlist) {
1.141 albertel 12624: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12625: }
1.141 albertel 12626: return !$truth;
1.84 albertel 12627: }
1.127 matthew 12628:
1.138 matthew 12629:
12630: ############################################################
12631: ############################################################
12632:
12633: =pod
12634:
1.157 matthew 12635: =back
12636:
1.138 matthew 12637: =head1 cgi-bin script and graphing routines
12638:
1.157 matthew 12639: =over 4
12640:
1.648 raeburn 12641: =item * &get_cgi_id()
1.138 matthew 12642:
12643: Inputs: none
12644:
12645: Returns an id which can be used to pass environment variables
12646: to various cgi-bin scripts. These environment variables will
12647: be removed from the users environment after a given time by
12648: the routine &Apache::lonnet::transfer_profile_to_env.
12649:
12650: =cut
12651:
12652: ############################################################
12653: ############################################################
1.152 albertel 12654: my $uniq=0;
1.136 matthew 12655: sub get_cgi_id {
1.154 albertel 12656: $uniq=($uniq+1)%100000;
1.280 albertel 12657: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12658: }
12659:
1.127 matthew 12660: ############################################################
12661: ############################################################
12662:
12663: =pod
12664:
1.648 raeburn 12665: =item * &DrawBarGraph()
1.127 matthew 12666:
1.138 matthew 12667: Facilitates the plotting of data in a (stacked) bar graph.
12668: Puts plot definition data into the users environment in order for
12669: graph.png to plot it. Returns an <img> tag for the plot.
12670: The bars on the plot are labeled '1','2',...,'n'.
12671:
12672: Inputs:
12673:
12674: =over 4
12675:
12676: =item $Title: string, the title of the plot
12677:
12678: =item $xlabel: string, text describing the X-axis of the plot
12679:
12680: =item $ylabel: string, text describing the Y-axis of the plot
12681:
12682: =item $Max: scalar, the maximum Y value to use in the plot
12683: If $Max is < any data point, the graph will not be rendered.
12684:
1.140 matthew 12685: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12686: they are plotted. If undefined, default values will be used.
12687:
1.178 matthew 12688: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12689:
1.138 matthew 12690: =item @Values: An array of array references. Each array reference holds data
12691: to be plotted in a stacked bar chart.
12692:
1.239 matthew 12693: =item If the final element of @Values is a hash reference the key/value
12694: pairs will be added to the graph definition.
12695:
1.138 matthew 12696: =back
12697:
12698: Returns:
12699:
12700: An <img> tag which references graph.png and the appropriate identifying
12701: information for the plot.
12702:
1.127 matthew 12703: =cut
12704:
12705: ############################################################
12706: ############################################################
1.134 matthew 12707: sub DrawBarGraph {
1.178 matthew 12708: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12709: #
12710: if (! defined($colors)) {
12711: $colors = ['#33ff00',
12712: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12713: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12714: ];
12715: }
1.228 matthew 12716: my $extra_settings = {};
12717: if (ref($Values[-1]) eq 'HASH') {
12718: $extra_settings = pop(@Values);
12719: }
1.127 matthew 12720: #
1.136 matthew 12721: my $identifier = &get_cgi_id();
12722: my $id = 'cgi.'.$identifier;
1.129 matthew 12723: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12724: return '';
12725: }
1.225 matthew 12726: #
12727: my @Labels;
12728: if (defined($labels)) {
12729: @Labels = @$labels;
12730: } else {
12731: for (my $i=0;$i<@{$Values[0]};$i++) {
12732: push (@Labels,$i+1);
12733: }
12734: }
12735: #
1.129 matthew 12736: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12737: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12738: my %ValuesHash;
12739: my $NumSets=1;
12740: foreach my $array (@Values) {
12741: next if (! ref($array));
1.136 matthew 12742: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12743: join(',',@$array);
1.129 matthew 12744: }
1.127 matthew 12745: #
1.136 matthew 12746: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12747: if ($NumBars < 3) {
12748: $width = 120+$NumBars*32;
1.220 matthew 12749: $xskip = 1;
1.225 matthew 12750: $bar_width = 30;
12751: } elsif ($NumBars < 5) {
12752: $width = 120+$NumBars*20;
12753: $xskip = 1;
12754: $bar_width = 20;
1.220 matthew 12755: } elsif ($NumBars < 10) {
1.136 matthew 12756: $width = 120+$NumBars*15;
12757: $xskip = 1;
12758: $bar_width = 15;
12759: } elsif ($NumBars <= 25) {
12760: $width = 120+$NumBars*11;
12761: $xskip = 5;
12762: $bar_width = 8;
12763: } elsif ($NumBars <= 50) {
12764: $width = 120+$NumBars*8;
12765: $xskip = 5;
12766: $bar_width = 4;
12767: } else {
12768: $width = 120+$NumBars*8;
12769: $xskip = 5;
12770: $bar_width = 4;
12771: }
12772: #
1.137 matthew 12773: $Max = 1 if ($Max < 1);
12774: if ( int($Max) < $Max ) {
12775: $Max++;
12776: $Max = int($Max);
12777: }
1.127 matthew 12778: $Title = '' if (! defined($Title));
12779: $xlabel = '' if (! defined($xlabel));
12780: $ylabel = '' if (! defined($ylabel));
1.369 www 12781: $ValuesHash{$id.'.title'} = &escape($Title);
12782: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12783: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12784: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12785: $ValuesHash{$id.'.NumBars'} = $NumBars;
12786: $ValuesHash{$id.'.NumSets'} = $NumSets;
12787: $ValuesHash{$id.'.PlotType'} = 'bar';
12788: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12789: $ValuesHash{$id.'.height'} = $height;
12790: $ValuesHash{$id.'.width'} = $width;
12791: $ValuesHash{$id.'.xskip'} = $xskip;
12792: $ValuesHash{$id.'.bar_width'} = $bar_width;
12793: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12794: #
1.228 matthew 12795: # Deal with other parameters
12796: while (my ($key,$value) = each(%$extra_settings)) {
12797: $ValuesHash{$id.'.'.$key} = $value;
12798: }
12799: #
1.646 raeburn 12800: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12801: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12802: }
12803:
12804: ############################################################
12805: ############################################################
12806:
12807: =pod
12808:
1.648 raeburn 12809: =item * &DrawXYGraph()
1.137 matthew 12810:
1.138 matthew 12811: Facilitates the plotting of data in an XY graph.
12812: Puts plot definition data into the users environment in order for
12813: graph.png to plot it. Returns an <img> tag for the plot.
12814:
12815: Inputs:
12816:
12817: =over 4
12818:
12819: =item $Title: string, the title of the plot
12820:
12821: =item $xlabel: string, text describing the X-axis of the plot
12822:
12823: =item $ylabel: string, text describing the Y-axis of the plot
12824:
12825: =item $Max: scalar, the maximum Y value to use in the plot
12826: If $Max is < any data point, the graph will not be rendered.
12827:
12828: =item $colors: Array ref containing the hex color codes for the data to be
12829: plotted in. If undefined, default values will be used.
12830:
12831: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12832:
12833: =item $Ydata: Array ref containing Array refs.
1.185 www 12834: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12835:
12836: =item %Values: hash indicating or overriding any default values which are
12837: passed to graph.png.
12838: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12839:
12840: =back
12841:
12842: Returns:
12843:
12844: An <img> tag which references graph.png and the appropriate identifying
12845: information for the plot.
12846:
1.137 matthew 12847: =cut
12848:
12849: ############################################################
12850: ############################################################
12851: sub DrawXYGraph {
12852: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12853: #
12854: # Create the identifier for the graph
12855: my $identifier = &get_cgi_id();
12856: my $id = 'cgi.'.$identifier;
12857: #
12858: $Title = '' if (! defined($Title));
12859: $xlabel = '' if (! defined($xlabel));
12860: $ylabel = '' if (! defined($ylabel));
12861: my %ValuesHash =
12862: (
1.369 www 12863: $id.'.title' => &escape($Title),
12864: $id.'.xlabel' => &escape($xlabel),
12865: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12866: $id.'.y_max_value'=> $Max,
12867: $id.'.labels' => join(',',@$Xlabels),
12868: $id.'.PlotType' => 'XY',
12869: );
12870: #
12871: if (defined($colors) && ref($colors) eq 'ARRAY') {
12872: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12873: }
12874: #
12875: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12876: return '';
12877: }
12878: my $NumSets=1;
1.138 matthew 12879: foreach my $array (@{$Ydata}){
1.137 matthew 12880: next if (! ref($array));
12881: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12882: }
1.138 matthew 12883: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12884: #
12885: # Deal with other parameters
12886: while (my ($key,$value) = each(%Values)) {
12887: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12888: }
12889: #
1.646 raeburn 12890: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12891: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12892: }
12893:
12894: ############################################################
12895: ############################################################
12896:
12897: =pod
12898:
1.648 raeburn 12899: =item * &DrawXYYGraph()
1.138 matthew 12900:
12901: Facilitates the plotting of data in an XY graph with two Y axes.
12902: Puts plot definition data into the users environment in order for
12903: graph.png to plot it. Returns an <img> tag for the plot.
12904:
12905: Inputs:
12906:
12907: =over 4
12908:
12909: =item $Title: string, the title of the plot
12910:
12911: =item $xlabel: string, text describing the X-axis of the plot
12912:
12913: =item $ylabel: string, text describing the Y-axis of the plot
12914:
12915: =item $colors: Array ref containing the hex color codes for the data to be
12916: plotted in. If undefined, default values will be used.
12917:
12918: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12919:
12920: =item $Ydata1: The first data set
12921:
12922: =item $Min1: The minimum value of the left Y-axis
12923:
12924: =item $Max1: The maximum value of the left Y-axis
12925:
12926: =item $Ydata2: The second data set
12927:
12928: =item $Min2: The minimum value of the right Y-axis
12929:
12930: =item $Max2: The maximum value of the left Y-axis
12931:
12932: =item %Values: hash indicating or overriding any default values which are
12933: passed to graph.png.
12934: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12935:
12936: =back
12937:
12938: Returns:
12939:
12940: An <img> tag which references graph.png and the appropriate identifying
12941: information for the plot.
1.136 matthew 12942:
12943: =cut
12944:
12945: ############################################################
12946: ############################################################
1.137 matthew 12947: sub DrawXYYGraph {
12948: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12949: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12950: #
12951: # Create the identifier for the graph
12952: my $identifier = &get_cgi_id();
12953: my $id = 'cgi.'.$identifier;
12954: #
12955: $Title = '' if (! defined($Title));
12956: $xlabel = '' if (! defined($xlabel));
12957: $ylabel = '' if (! defined($ylabel));
12958: my %ValuesHash =
12959: (
1.369 www 12960: $id.'.title' => &escape($Title),
12961: $id.'.xlabel' => &escape($xlabel),
12962: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 12963: $id.'.labels' => join(',',@$Xlabels),
12964: $id.'.PlotType' => 'XY',
12965: $id.'.NumSets' => 2,
1.137 matthew 12966: $id.'.two_axes' => 1,
12967: $id.'.y1_max_value' => $Max1,
12968: $id.'.y1_min_value' => $Min1,
12969: $id.'.y2_max_value' => $Max2,
12970: $id.'.y2_min_value' => $Min2,
1.136 matthew 12971: );
12972: #
1.137 matthew 12973: if (defined($colors) && ref($colors) eq 'ARRAY') {
12974: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12975: }
12976: #
12977: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
12978: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 12979: return '';
12980: }
12981: my $NumSets=1;
1.137 matthew 12982: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 12983: next if (! ref($array));
12984: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 12985: }
12986: #
12987: # Deal with other parameters
12988: while (my ($key,$value) = each(%Values)) {
12989: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 12990: }
12991: #
1.646 raeburn 12992: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 12993: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 12994: }
12995:
12996: ############################################################
12997: ############################################################
12998:
12999: =pod
13000:
1.157 matthew 13001: =back
13002:
1.139 matthew 13003: =head1 Statistics helper routines?
13004:
13005: Bad place for them but what the hell.
13006:
1.157 matthew 13007: =over 4
13008:
1.648 raeburn 13009: =item * &chartlink()
1.139 matthew 13010:
13011: Returns a link to the chart for a specific student.
13012:
13013: Inputs:
13014:
13015: =over 4
13016:
13017: =item $linktext: The text of the link
13018:
13019: =item $sname: The students username
13020:
13021: =item $sdomain: The students domain
13022:
13023: =back
13024:
1.157 matthew 13025: =back
13026:
1.139 matthew 13027: =cut
13028:
13029: ############################################################
13030: ############################################################
13031: sub chartlink {
13032: my ($linktext, $sname, $sdomain) = @_;
13033: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13034: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13035: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13036: '">'.$linktext.'</a>';
1.153 matthew 13037: }
13038:
13039: #######################################################
13040: #######################################################
13041:
13042: =pod
13043:
13044: =head1 Course Environment Routines
1.157 matthew 13045:
13046: =over 4
1.153 matthew 13047:
1.648 raeburn 13048: =item * &restore_course_settings()
1.153 matthew 13049:
1.648 raeburn 13050: =item * &store_course_settings()
1.153 matthew 13051:
13052: Restores/Store indicated form parameters from the course environment.
13053: Will not overwrite existing values of the form parameters.
13054:
13055: Inputs:
13056: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13057:
13058: a hash ref describing the data to be stored. For example:
13059:
13060: %Save_Parameters = ('Status' => 'scalar',
13061: 'chartoutputmode' => 'scalar',
13062: 'chartoutputdata' => 'scalar',
13063: 'Section' => 'array',
1.373 raeburn 13064: 'Group' => 'array',
1.153 matthew 13065: 'StudentData' => 'array',
13066: 'Maps' => 'array');
13067:
13068: Returns: both routines return nothing
13069:
1.631 raeburn 13070: =back
13071:
1.153 matthew 13072: =cut
13073:
13074: #######################################################
13075: #######################################################
13076: sub store_course_settings {
1.496 albertel 13077: return &store_settings($env{'request.course.id'},@_);
13078: }
13079:
13080: sub store_settings {
1.153 matthew 13081: # save to the environment
13082: # appenv the same items, just to be safe
1.300 albertel 13083: my $udom = $env{'user.domain'};
13084: my $uname = $env{'user.name'};
1.496 albertel 13085: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13086: my %SaveHash;
13087: my %AppHash;
13088: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13089: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13090: my $envname = 'environment.'.$basename;
1.258 albertel 13091: if (exists($env{'form.'.$setting})) {
1.153 matthew 13092: # Save this value away
13093: if ($type eq 'scalar' &&
1.258 albertel 13094: (! exists($env{$envname}) ||
13095: $env{$envname} ne $env{'form.'.$setting})) {
13096: $SaveHash{$basename} = $env{'form.'.$setting};
13097: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13098: } elsif ($type eq 'array') {
13099: my $stored_form;
1.258 albertel 13100: if (ref($env{'form.'.$setting})) {
1.153 matthew 13101: $stored_form = join(',',
13102: map {
1.369 www 13103: &escape($_);
1.258 albertel 13104: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13105: } else {
13106: $stored_form =
1.369 www 13107: &escape($env{'form.'.$setting});
1.153 matthew 13108: }
13109: # Determine if the array contents are the same.
1.258 albertel 13110: if ($stored_form ne $env{$envname}) {
1.153 matthew 13111: $SaveHash{$basename} = $stored_form;
13112: $AppHash{$envname} = $stored_form;
13113: }
13114: }
13115: }
13116: }
13117: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13118: $udom,$uname);
1.153 matthew 13119: if ($put_result !~ /^(ok|delayed)/) {
13120: &Apache::lonnet::logthis('unable to save form parameters, '.
13121: 'got error:'.$put_result);
13122: }
13123: # Make sure these settings stick around in this session, too
1.646 raeburn 13124: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13125: return;
13126: }
13127:
13128: sub restore_course_settings {
1.499 albertel 13129: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13130: }
13131:
13132: sub restore_settings {
13133: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13134: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13135: next if (exists($env{'form.'.$setting}));
1.496 albertel 13136: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13137: '.'.$setting;
1.258 albertel 13138: if (exists($env{$envname})) {
1.153 matthew 13139: if ($type eq 'scalar') {
1.258 albertel 13140: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13141: } elsif ($type eq 'array') {
1.258 albertel 13142: $env{'form.'.$setting} = [
1.153 matthew 13143: map {
1.369 www 13144: &unescape($_);
1.258 albertel 13145: } split(',',$env{$envname})
1.153 matthew 13146: ];
13147: }
13148: }
13149: }
1.127 matthew 13150: }
13151:
1.618 raeburn 13152: #######################################################
13153: #######################################################
13154:
13155: =pod
13156:
13157: =head1 Domain E-mail Routines
13158:
13159: =over 4
13160:
1.648 raeburn 13161: =item * &build_recipient_list()
1.618 raeburn 13162:
1.1075.2.44 raeburn 13163: Build recipient lists for following types of e-mail:
1.766 raeburn 13164: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13165: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13166: module change checking, student/employee ID conflict checks, as
13167: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13168: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13169:
13170: Inputs:
1.1075.2.44 raeburn 13171: defmail (scalar - email address of default recipient),
13172: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13173: requestsmail, updatesmail, or idconflictsmail).
13174:
1.619 raeburn 13175: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13176:
13177: origmail (scalar - email address of recipient from loncapa.conf,
13178: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13179:
1.655 raeburn 13180: Returns: comma separated list of addresses to which to send e-mail.
13181:
13182: =back
1.618 raeburn 13183:
13184: =cut
13185:
13186: ############################################################
13187: ############################################################
13188: sub build_recipient_list {
1.619 raeburn 13189: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13190: my @recipients;
13191: my $otheremails;
13192: my %domconfig =
13193: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13194: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13195: if (exists($domconfig{'contacts'}{$mailing})) {
13196: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13197: my @contacts = ('adminemail','supportemail');
13198: foreach my $item (@contacts) {
13199: if ($domconfig{'contacts'}{$mailing}{$item}) {
13200: my $addr = $domconfig{'contacts'}{$item};
13201: if (!grep(/^\Q$addr\E$/,@recipients)) {
13202: push(@recipients,$addr);
13203: }
1.619 raeburn 13204: }
1.766 raeburn 13205: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13206: }
13207: }
1.766 raeburn 13208: } elsif ($origmail ne '') {
13209: push(@recipients,$origmail);
1.618 raeburn 13210: }
1.619 raeburn 13211: } elsif ($origmail ne '') {
13212: push(@recipients,$origmail);
1.618 raeburn 13213: }
1.688 raeburn 13214: if (defined($defmail)) {
13215: if ($defmail ne '') {
13216: push(@recipients,$defmail);
13217: }
1.618 raeburn 13218: }
13219: if ($otheremails) {
1.619 raeburn 13220: my @others;
13221: if ($otheremails =~ /,/) {
13222: @others = split(/,/,$otheremails);
1.618 raeburn 13223: } else {
1.619 raeburn 13224: push(@others,$otheremails);
13225: }
13226: foreach my $addr (@others) {
13227: if (!grep(/^\Q$addr\E$/,@recipients)) {
13228: push(@recipients,$addr);
13229: }
1.618 raeburn 13230: }
13231: }
1.619 raeburn 13232: my $recipientlist = join(',',@recipients);
1.618 raeburn 13233: return $recipientlist;
13234: }
13235:
1.127 matthew 13236: ############################################################
13237: ############################################################
1.154 albertel 13238:
1.655 raeburn 13239: =pod
13240:
13241: =head1 Course Catalog Routines
13242:
13243: =over 4
13244:
13245: =item * &gather_categories()
13246:
13247: Converts category definitions - keys of categories hash stored in
13248: coursecategories in configuration.db on the primary library server in a
13249: domain - to an array. Also generates javascript and idx hash used to
13250: generate Domain Coordinator interface for editing Course Categories.
13251:
13252: Inputs:
1.663 raeburn 13253:
1.655 raeburn 13254: categories (reference to hash of category definitions).
1.663 raeburn 13255:
1.655 raeburn 13256: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13257: categories and subcategories).
1.663 raeburn 13258:
1.655 raeburn 13259: idx (reference to hash of counters used in Domain Coordinator interface for
13260: editing Course Categories).
1.663 raeburn 13261:
1.655 raeburn 13262: jsarray (reference to array of categories used to create Javascript arrays for
13263: Domain Coordinator interface for editing Course Categories).
13264:
13265: Returns: nothing
13266:
13267: Side effects: populates cats, idx and jsarray.
13268:
13269: =cut
13270:
13271: sub gather_categories {
13272: my ($categories,$cats,$idx,$jsarray) = @_;
13273: my %counters;
13274: my $num = 0;
13275: foreach my $item (keys(%{$categories})) {
13276: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13277: if ($container eq '' && $depth == 0) {
13278: $cats->[$depth][$categories->{$item}] = $cat;
13279: } else {
13280: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13281: }
13282: my ($escitem,$tail) = split(/:/,$item,2);
13283: if ($counters{$tail} eq '') {
13284: $counters{$tail} = $num;
13285: $num ++;
13286: }
13287: if (ref($idx) eq 'HASH') {
13288: $idx->{$item} = $counters{$tail};
13289: }
13290: if (ref($jsarray) eq 'ARRAY') {
13291: push(@{$jsarray->[$counters{$tail}]},$item);
13292: }
13293: }
13294: return;
13295: }
13296:
13297: =pod
13298:
13299: =item * &extract_categories()
13300:
13301: Used to generate breadcrumb trails for course categories.
13302:
13303: Inputs:
1.663 raeburn 13304:
1.655 raeburn 13305: categories (reference to hash of category definitions).
1.663 raeburn 13306:
1.655 raeburn 13307: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13308: categories and subcategories).
1.663 raeburn 13309:
1.655 raeburn 13310: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13311:
1.655 raeburn 13312: allitems (reference to hash - key is category key
13313: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13314:
1.655 raeburn 13315: idx (reference to hash of counters used in Domain Coordinator interface for
13316: editing Course Categories).
1.663 raeburn 13317:
1.655 raeburn 13318: jsarray (reference to array of categories used to create Javascript arrays for
13319: Domain Coordinator interface for editing Course Categories).
13320:
1.665 raeburn 13321: subcats (reference to hash of arrays containing all subcategories within each
13322: category, -recursive)
13323:
1.655 raeburn 13324: Returns: nothing
13325:
13326: Side effects: populates trails and allitems hash references.
13327:
13328: =cut
13329:
13330: sub extract_categories {
1.665 raeburn 13331: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13332: if (ref($categories) eq 'HASH') {
13333: &gather_categories($categories,$cats,$idx,$jsarray);
13334: if (ref($cats->[0]) eq 'ARRAY') {
13335: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13336: my $name = $cats->[0][$i];
13337: my $item = &escape($name).'::0';
13338: my $trailstr;
13339: if ($name eq 'instcode') {
13340: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13341: } elsif ($name eq 'communities') {
13342: $trailstr = &mt('Communities');
1.655 raeburn 13343: } else {
13344: $trailstr = $name;
13345: }
13346: if ($allitems->{$item} eq '') {
13347: push(@{$trails},$trailstr);
13348: $allitems->{$item} = scalar(@{$trails})-1;
13349: }
13350: my @parents = ($name);
13351: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13352: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13353: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13354: if (ref($subcats) eq 'HASH') {
13355: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13356: }
13357: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13358: }
13359: } else {
13360: if (ref($subcats) eq 'HASH') {
13361: $subcats->{$item} = [];
1.655 raeburn 13362: }
13363: }
13364: }
13365: }
13366: }
13367: return;
13368: }
13369:
13370: =pod
13371:
13372: =item *&recurse_categories()
13373:
13374: Recursively used to generate breadcrumb trails for course categories.
13375:
13376: Inputs:
1.663 raeburn 13377:
1.655 raeburn 13378: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13379: categories and subcategories).
1.663 raeburn 13380:
1.655 raeburn 13381: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13382:
13383: category (current course category, for which breadcrumb trail is being generated).
13384:
13385: trails (reference to array of breadcrumb trails for each category).
13386:
1.655 raeburn 13387: allitems (reference to hash - key is category key
13388: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13389:
1.655 raeburn 13390: parents (array containing containers directories for current category,
13391: back to top level).
13392:
13393: Returns: nothing
13394:
13395: Side effects: populates trails and allitems hash references
13396:
13397: =cut
13398:
13399: sub recurse_categories {
1.665 raeburn 13400: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13401: my $shallower = $depth - 1;
13402: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13403: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13404: my $name = $cats->[$depth]{$category}[$k];
13405: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13406: my $trailstr = join(' -> ',(@{$parents},$category));
13407: if ($allitems->{$item} eq '') {
13408: push(@{$trails},$trailstr);
13409: $allitems->{$item} = scalar(@{$trails})-1;
13410: }
13411: my $deeper = $depth+1;
13412: push(@{$parents},$category);
1.665 raeburn 13413: if (ref($subcats) eq 'HASH') {
13414: my $subcat = &escape($name).':'.$category.':'.$depth;
13415: for (my $j=@{$parents}; $j>=0; $j--) {
13416: my $higher;
13417: if ($j > 0) {
13418: $higher = &escape($parents->[$j]).':'.
13419: &escape($parents->[$j-1]).':'.$j;
13420: } else {
13421: $higher = &escape($parents->[$j]).'::'.$j;
13422: }
13423: push(@{$subcats->{$higher}},$subcat);
13424: }
13425: }
13426: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13427: $subcats);
1.655 raeburn 13428: pop(@{$parents});
13429: }
13430: } else {
13431: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13432: my $trailstr = join(' -> ',(@{$parents},$category));
13433: if ($allitems->{$item} eq '') {
13434: push(@{$trails},$trailstr);
13435: $allitems->{$item} = scalar(@{$trails})-1;
13436: }
13437: }
13438: return;
13439: }
13440:
1.663 raeburn 13441: =pod
13442:
13443: =item *&assign_categories_table()
13444:
13445: Create a datatable for display of hierarchical categories in a domain,
13446: with checkboxes to allow a course to be categorized.
13447:
13448: Inputs:
13449:
13450: cathash - reference to hash of categories defined for the domain (from
13451: configuration.db)
13452:
13453: currcat - scalar with an & separated list of categories assigned to a course.
13454:
1.919 raeburn 13455: type - scalar contains course type (Course or Community).
13456:
1.663 raeburn 13457: Returns: $output (markup to be displayed)
13458:
13459: =cut
13460:
13461: sub assign_categories_table {
1.919 raeburn 13462: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13463: my $output;
13464: if (ref($cathash) eq 'HASH') {
13465: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13466: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13467: $maxdepth = scalar(@cats);
13468: if (@cats > 0) {
13469: my $itemcount = 0;
13470: if (ref($cats[0]) eq 'ARRAY') {
13471: my @currcategories;
13472: if ($currcat ne '') {
13473: @currcategories = split('&',$currcat);
13474: }
1.919 raeburn 13475: my $table;
1.663 raeburn 13476: for (my $i=0; $i<@{$cats[0]}; $i++) {
13477: my $parent = $cats[0][$i];
1.919 raeburn 13478: next if ($parent eq 'instcode');
13479: if ($type eq 'Community') {
13480: next unless ($parent eq 'communities');
13481: } else {
13482: next if ($parent eq 'communities');
13483: }
1.663 raeburn 13484: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13485: my $item = &escape($parent).'::0';
13486: my $checked = '';
13487: if (@currcategories > 0) {
13488: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13489: $checked = ' checked="checked"';
1.663 raeburn 13490: }
13491: }
1.919 raeburn 13492: my $parent_title = $parent;
13493: if ($parent eq 'communities') {
13494: $parent_title = &mt('Communities');
13495: }
13496: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13497: '<input type="checkbox" name="usecategory" value="'.
13498: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13499: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13500: my $depth = 1;
13501: push(@path,$parent);
1.919 raeburn 13502: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13503: pop(@path);
1.919 raeburn 13504: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13505: $itemcount ++;
13506: }
1.919 raeburn 13507: if ($itemcount) {
13508: $output = &Apache::loncommon::start_data_table().
13509: $table.
13510: &Apache::loncommon::end_data_table();
13511: }
1.663 raeburn 13512: }
13513: }
13514: }
13515: return $output;
13516: }
13517:
13518: =pod
13519:
13520: =item *&assign_category_rows()
13521:
13522: Create a datatable row for display of nested categories in a domain,
13523: with checkboxes to allow a course to be categorized,called recursively.
13524:
13525: Inputs:
13526:
13527: itemcount - track row number for alternating colors
13528:
13529: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13530: categories and subcategories.
13531:
13532: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13533:
13534: parent - parent of current category item
13535:
13536: path - Array containing all categories back up through the hierarchy from the
13537: current category to the top level.
13538:
13539: currcategories - reference to array of current categories assigned to the course
13540:
13541: Returns: $output (markup to be displayed).
13542:
13543: =cut
13544:
13545: sub assign_category_rows {
13546: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13547: my ($text,$name,$item,$chgstr);
13548: if (ref($cats) eq 'ARRAY') {
13549: my $maxdepth = scalar(@{$cats});
13550: if (ref($cats->[$depth]) eq 'HASH') {
13551: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13552: my $numchildren = @{$cats->[$depth]{$parent}};
13553: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 13554: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13555: for (my $j=0; $j<$numchildren; $j++) {
13556: $name = $cats->[$depth]{$parent}[$j];
13557: $item = &escape($name).':'.&escape($parent).':'.$depth;
13558: my $deeper = $depth+1;
13559: my $checked = '';
13560: if (ref($currcategories) eq 'ARRAY') {
13561: if (@{$currcategories} > 0) {
13562: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13563: $checked = ' checked="checked"';
1.663 raeburn 13564: }
13565: }
13566: }
1.664 raeburn 13567: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13568: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13569: $item.'"'.$checked.' />'.$name.'</label></span>'.
13570: '<input type="hidden" name="catname" value="'.$name.'" />'.
13571: '</td><td>';
1.663 raeburn 13572: if (ref($path) eq 'ARRAY') {
13573: push(@{$path},$name);
13574: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13575: pop(@{$path});
13576: }
13577: $text .= '</td></tr>';
13578: }
13579: $text .= '</table></td>';
13580: }
13581: }
13582: }
13583: return $text;
13584: }
13585:
1.655 raeburn 13586: ############################################################
13587: ############################################################
13588:
13589:
1.443 albertel 13590: sub commit_customrole {
1.664 raeburn 13591: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13592: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13593: ($start?', '.&mt('starting').' '.localtime($start):'').
13594: ($end?', ending '.localtime($end):'').': <b>'.
13595: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13596: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13597: '</b><br />';
13598: return $output;
13599: }
13600:
13601: sub commit_standardrole {
1.1075.2.31 raeburn 13602: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13603: my ($output,$logmsg,$linefeed);
13604: if ($context eq 'auto') {
13605: $linefeed = "\n";
13606: } else {
13607: $linefeed = "<br />\n";
13608: }
1.443 albertel 13609: if ($three eq 'st') {
1.541 raeburn 13610: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 13611: $one,$two,$sec,$context,$credits);
1.541 raeburn 13612: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13613: ($result eq 'unknown_course') || ($result eq 'refused')) {
13614: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13615: } else {
1.541 raeburn 13616: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13617: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13618: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13619: if ($context eq 'auto') {
13620: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13621: } else {
13622: $output .= '<b>'.$result.'</b>'.$linefeed.
13623: &mt('Add to classlist').': <b>ok</b>';
13624: }
13625: $output .= $linefeed;
1.443 albertel 13626: }
13627: } else {
13628: $output = &mt('Assigning').' '.$three.' in '.$url.
13629: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13630: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13631: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13632: if ($context eq 'auto') {
13633: $output .= $result.$linefeed;
13634: } else {
13635: $output .= '<b>'.$result.'</b>'.$linefeed;
13636: }
1.443 albertel 13637: }
13638: return $output;
13639: }
13640:
13641: sub commit_studentrole {
1.1075.2.31 raeburn 13642: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13643: $credits) = @_;
1.626 raeburn 13644: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13645: if ($context eq 'auto') {
13646: $linefeed = "\n";
13647: } else {
13648: $linefeed = '<br />'."\n";
13649: }
1.443 albertel 13650: if (defined($one) && defined($two)) {
13651: my $cid=$one.'_'.$two;
13652: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13653: my $secchange = 0;
13654: my $expire_role_result;
13655: my $modify_section_result;
1.628 raeburn 13656: if ($oldsec ne '-1') {
13657: if ($oldsec ne $sec) {
1.443 albertel 13658: $secchange = 1;
1.628 raeburn 13659: my $now = time;
1.443 albertel 13660: my $uurl='/'.$cid;
13661: $uurl=~s/\_/\//g;
13662: if ($oldsec) {
13663: $uurl.='/'.$oldsec;
13664: }
1.626 raeburn 13665: $oldsecurl = $uurl;
1.628 raeburn 13666: $expire_role_result =
1.652 raeburn 13667: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13668: if ($env{'request.course.sec'} ne '') {
13669: if ($expire_role_result eq 'refused') {
13670: my @roles = ('st');
13671: my @statuses = ('previous');
13672: my @roledoms = ($one);
13673: my $withsec = 1;
13674: my %roleshash =
13675: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13676: \@statuses,\@roles,\@roledoms,$withsec);
13677: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13678: my ($oldstart,$oldend) =
13679: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13680: if ($oldend > 0 && $oldend <= $now) {
13681: $expire_role_result = 'ok';
13682: }
13683: }
13684: }
13685: }
1.443 albertel 13686: $result = $expire_role_result;
13687: }
13688: }
13689: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 13690: $modify_section_result =
13691: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13692: undef,undef,undef,$sec,
13693: $end,$start,'','',$cid,
13694: '',$context,$credits);
1.443 albertel 13695: if ($modify_section_result =~ /^ok/) {
13696: if ($secchange == 1) {
1.628 raeburn 13697: if ($sec eq '') {
13698: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13699: } else {
13700: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13701: }
1.443 albertel 13702: } elsif ($oldsec eq '-1') {
1.628 raeburn 13703: if ($sec eq '') {
13704: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13705: } else {
13706: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13707: }
1.443 albertel 13708: } else {
1.628 raeburn 13709: if ($sec eq '') {
13710: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13711: } else {
13712: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13713: }
1.443 albertel 13714: }
13715: } else {
1.628 raeburn 13716: if ($secchange) {
13717: $$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;
13718: } else {
13719: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13720: }
1.443 albertel 13721: }
13722: $result = $modify_section_result;
13723: } elsif ($secchange == 1) {
1.628 raeburn 13724: if ($oldsec eq '') {
1.1075.2.20 raeburn 13725: $$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 13726: } else {
13727: $$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;
13728: }
1.626 raeburn 13729: if ($expire_role_result eq 'refused') {
13730: my $newsecurl = '/'.$cid;
13731: $newsecurl =~ s/\_/\//g;
13732: if ($sec ne '') {
13733: $newsecurl.='/'.$sec;
13734: }
13735: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13736: if ($sec eq '') {
13737: $$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;
13738: } else {
13739: $$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;
13740: }
13741: }
13742: }
1.443 albertel 13743: }
13744: } else {
1.626 raeburn 13745: $$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 13746: $result = "error: incomplete course id\n";
13747: }
13748: return $result;
13749: }
13750:
1.1075.2.25 raeburn 13751: sub show_role_extent {
13752: my ($scope,$context,$role) = @_;
13753: $scope =~ s{^/}{};
13754: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13755: push(@courseroles,'co');
13756: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13757: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13758: $scope =~ s{/}{_};
13759: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13760: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13761: my ($audom,$auname) = split(/\//,$scope);
13762: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13763: &Apache::loncommon::plainname($auname,$audom).'</span>');
13764: } else {
13765: $scope =~ s{/$}{};
13766: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13767: &Apache::lonnet::domain($scope,'description').'</span>');
13768: }
13769: }
13770:
1.443 albertel 13771: ############################################################
13772: ############################################################
13773:
1.566 albertel 13774: sub check_clone {
1.578 raeburn 13775: my ($args,$linefeed) = @_;
1.566 albertel 13776: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13777: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13778: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13779: my $clonemsg;
13780: my $can_clone = 0;
1.944 raeburn 13781: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13782: if ($lctype ne 'community') {
13783: $lctype = 'course';
13784: }
1.566 albertel 13785: if ($clonehome eq 'no_host') {
1.944 raeburn 13786: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13787: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
13788: } else {
13789: $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'});
13790: }
1.566 albertel 13791: } else {
13792: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13793: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13794: if ($clonedesc{'type'} ne 'Community') {
13795: $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'});
13796: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13797: }
13798: }
1.882 raeburn 13799: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13800: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13801: $can_clone = 1;
13802: } else {
13803: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13804: $args->{'clonedomain'},$args->{'clonecourse'});
13805: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13806: if (grep(/^\*$/,@cloners)) {
13807: $can_clone = 1;
13808: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13809: $can_clone = 1;
13810: } else {
1.908 raeburn 13811: my $ccrole = 'cc';
1.944 raeburn 13812: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13813: $ccrole = 'co';
13814: }
1.578 raeburn 13815: my %roleshash =
13816: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13817: $args->{'ccdomain'},
1.908 raeburn 13818: 'userroles',['active'],[$ccrole],
1.578 raeburn 13819: [$args->{'clonedomain'}]);
1.908 raeburn 13820: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13821: $can_clone = 1;
13822: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13823: $can_clone = 1;
13824: } else {
1.944 raeburn 13825: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13826: $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'});
13827: } else {
13828: $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'});
13829: }
1.578 raeburn 13830: }
1.566 albertel 13831: }
1.578 raeburn 13832: }
1.566 albertel 13833: }
13834: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13835: }
13836:
1.444 albertel 13837: sub construct_course {
1.885 raeburn 13838: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 13839: my $outcome;
1.541 raeburn 13840: my $linefeed = '<br />'."\n";
13841: if ($context eq 'auto') {
13842: $linefeed = "\n";
13843: }
1.566 albertel 13844:
13845: #
13846: # Are we cloning?
13847: #
13848: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13849: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13850: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13851: if ($context ne 'auto') {
1.578 raeburn 13852: if ($clonemsg ne '') {
13853: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13854: }
1.566 albertel 13855: }
13856: $outcome .= $clonemsg.$linefeed;
13857:
13858: if (!$can_clone) {
13859: return (0,$outcome);
13860: }
13861: }
13862:
1.444 albertel 13863: #
13864: # Open course
13865: #
13866: my $crstype = lc($args->{'crstype'});
13867: my %cenv=();
13868: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13869: $args->{'cdescr'},
13870: $args->{'curl'},
13871: $args->{'course_home'},
13872: $args->{'nonstandard'},
13873: $args->{'crscode'},
13874: $args->{'ccuname'}.':'.
13875: $args->{'ccdomain'},
1.882 raeburn 13876: $args->{'crstype'},
1.885 raeburn 13877: $cnum,$context,$category);
1.444 albertel 13878:
13879: # Note: The testing routines depend on this being output; see
13880: # Utils::Course. This needs to at least be output as a comment
13881: # if anyone ever decides to not show this, and Utils::Course::new
13882: # will need to be suitably modified.
1.541 raeburn 13883: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13884: if ($$courseid =~ /^error:/) {
13885: return (0,$outcome);
13886: }
13887:
1.444 albertel 13888: #
13889: # Check if created correctly
13890: #
1.479 albertel 13891: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13892: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13893: if ($crsuhome eq 'no_host') {
13894: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13895: return (0,$outcome);
13896: }
1.541 raeburn 13897: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13898:
1.444 albertel 13899: #
1.566 albertel 13900: # Do the cloning
13901: #
13902: if ($can_clone && $cloneid) {
13903: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13904: if ($context ne 'auto') {
13905: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13906: }
13907: $outcome .= $clonemsg.$linefeed;
13908: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13909: # Copy all files
1.637 www 13910: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13911: # Restore URL
1.566 albertel 13912: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13913: # Restore title
1.566 albertel 13914: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13915: # Restore creation date, creator and creation context.
13916: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13917: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13918: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13919: # Mark as cloned
1.566 albertel 13920: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13921: # Need to clone grading mode
13922: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13923: $cenv{'grading'}=$newenv{'grading'};
13924: # Do not clone these environment entries
13925: &Apache::lonnet::del('environment',
13926: ['default_enrollment_start_date',
13927: 'default_enrollment_end_date',
13928: 'question.email',
13929: 'policy.email',
13930: 'comment.email',
13931: 'pch.users.denied',
1.725 raeburn 13932: 'plc.users.denied',
13933: 'hidefromcat',
1.1075.2.36 raeburn 13934: 'checkforpriv',
1.725 raeburn 13935: 'categories'],
1.638 www 13936: $$crsudom,$$crsunum);
1.444 albertel 13937: }
1.566 albertel 13938:
1.444 albertel 13939: #
13940: # Set environment (will override cloned, if existing)
13941: #
13942: my @sections = ();
13943: my @xlists = ();
13944: if ($args->{'crstype'}) {
13945: $cenv{'type'}=$args->{'crstype'};
13946: }
13947: if ($args->{'crsid'}) {
13948: $cenv{'courseid'}=$args->{'crsid'};
13949: }
13950: if ($args->{'crscode'}) {
13951: $cenv{'internal.coursecode'}=$args->{'crscode'};
13952: }
13953: if ($args->{'crsquota'} ne '') {
13954: $cenv{'internal.coursequota'}=$args->{'crsquota'};
13955: } else {
13956: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
13957: }
13958: if ($args->{'ccuname'}) {
13959: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
13960: ':'.$args->{'ccdomain'};
13961: } else {
13962: $cenv{'internal.courseowner'} = $args->{'curruser'};
13963: }
1.1075.2.31 raeburn 13964: if ($args->{'defaultcredits'}) {
13965: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
13966: }
1.444 albertel 13967: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
13968: if ($args->{'crssections'}) {
13969: $cenv{'internal.sectionnums'} = '';
13970: if ($args->{'crssections'} =~ m/,/) {
13971: @sections = split/,/,$args->{'crssections'};
13972: } else {
13973: $sections[0] = $args->{'crssections'};
13974: }
13975: if (@sections > 0) {
13976: foreach my $item (@sections) {
13977: my ($sec,$gp) = split/:/,$item;
13978: my $class = $args->{'crscode'}.$sec;
13979: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
13980: $cenv{'internal.sectionnums'} .= $item.',';
13981: unless ($addcheck eq 'ok') {
13982: push @badclasses, $class;
13983: }
13984: }
13985: $cenv{'internal.sectionnums'} =~ s/,$//;
13986: }
13987: }
13988: # do not hide course coordinator from staff listing,
13989: # even if privileged
13990: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 13991: # add course coordinator's domain to domains to check for privileged users
13992: # if different to course domain
13993: if ($$crsudom ne $args->{'ccdomain'}) {
13994: $cenv{'checkforpriv'} = $args->{'ccdomain'};
13995: }
1.444 albertel 13996: # add crosslistings
13997: if ($args->{'crsxlist'}) {
13998: $cenv{'internal.crosslistings'}='';
13999: if ($args->{'crsxlist'} =~ m/,/) {
14000: @xlists = split/,/,$args->{'crsxlist'};
14001: } else {
14002: $xlists[0] = $args->{'crsxlist'};
14003: }
14004: if (@xlists > 0) {
14005: foreach my $item (@xlists) {
14006: my ($xl,$gp) = split/:/,$item;
14007: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14008: $cenv{'internal.crosslistings'} .= $item.',';
14009: unless ($addcheck eq 'ok') {
14010: push @badclasses, $xl;
14011: }
14012: }
14013: $cenv{'internal.crosslistings'} =~ s/,$//;
14014: }
14015: }
14016: if ($args->{'autoadds'}) {
14017: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14018: }
14019: if ($args->{'autodrops'}) {
14020: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14021: }
14022: # check for notification of enrollment changes
14023: my @notified = ();
14024: if ($args->{'notify_owner'}) {
14025: if ($args->{'ccuname'} ne '') {
14026: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14027: }
14028: }
14029: if ($args->{'notify_dc'}) {
14030: if ($uname ne '') {
1.630 raeburn 14031: push(@notified,$uname.':'.$udom);
1.444 albertel 14032: }
14033: }
14034: if (@notified > 0) {
14035: my $notifylist;
14036: if (@notified > 1) {
14037: $notifylist = join(',',@notified);
14038: } else {
14039: $notifylist = $notified[0];
14040: }
14041: $cenv{'internal.notifylist'} = $notifylist;
14042: }
14043: if (@badclasses > 0) {
14044: my %lt=&Apache::lonlocal::texthash(
14045: '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',
14046: 'dnhr' => 'does not have rights to access enrollment in these classes',
14047: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14048: );
1.541 raeburn 14049: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14050: ' ('.$lt{'adby'}.')';
14051: if ($context eq 'auto') {
14052: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14053: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14054: foreach my $item (@badclasses) {
14055: if ($context eq 'auto') {
14056: $outcome .= " - $item\n";
14057: } else {
14058: $outcome .= "<li>$item</li>\n";
14059: }
14060: }
14061: if ($context eq 'auto') {
14062: $outcome .= $linefeed;
14063: } else {
1.566 albertel 14064: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14065: }
14066: }
1.444 albertel 14067: }
14068: if ($args->{'no_end_date'}) {
14069: $args->{'endaccess'} = 0;
14070: }
14071: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14072: $cenv{'internal.autoend'}=$args->{'enrollend'};
14073: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14074: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14075: if ($args->{'showphotos'}) {
14076: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14077: }
14078: $cenv{'internal.authtype'} = $args->{'authtype'};
14079: $cenv{'internal.autharg'} = $args->{'autharg'};
14080: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14081: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14082: 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');
14083: if ($context eq 'auto') {
14084: $outcome .= $krb_msg;
14085: } else {
1.566 albertel 14086: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14087: }
14088: $outcome .= $linefeed;
1.444 albertel 14089: }
14090: }
14091: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14092: if ($args->{'setpolicy'}) {
14093: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14094: }
14095: if ($args->{'setcontent'}) {
14096: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14097: }
14098: }
14099: if ($args->{'reshome'}) {
14100: $cenv{'reshome'}=$args->{'reshome'}.'/';
14101: $cenv{'reshome'}=~s/\/+$/\//;
14102: }
14103: #
14104: # course has keyed access
14105: #
14106: if ($args->{'setkeys'}) {
14107: $cenv{'keyaccess'}='yes';
14108: }
14109: # if specified, key authority is not course, but user
14110: # only active if keyaccess is yes
14111: if ($args->{'keyauth'}) {
1.487 albertel 14112: my ($user,$domain) = split(':',$args->{'keyauth'});
14113: $user = &LONCAPA::clean_username($user);
14114: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14115: if ($user ne '' && $domain ne '') {
1.487 albertel 14116: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14117: }
14118: }
14119:
14120: if ($args->{'disresdis'}) {
14121: $cenv{'pch.roles.denied'}='st';
14122: }
14123: if ($args->{'disablechat'}) {
14124: $cenv{'plc.roles.denied'}='st';
14125: }
14126:
14127: # Record we've not yet viewed the Course Initialization Helper for this
14128: # course
14129: $cenv{'course.helper.not.run'} = 1;
14130: #
14131: # Use new Randomseed
14132: #
14133: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14134: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14135: #
14136: # The encryption code and receipt prefix for this course
14137: #
14138: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14139: $cenv{'internal.encpref'}=100+int(9*rand(99));
14140: #
14141: # By default, use standard grading
14142: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14143:
1.541 raeburn 14144: $outcome .= $linefeed.&mt('Setting environment').': '.
14145: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14146: #
14147: # Open all assignments
14148: #
14149: if ($args->{'openall'}) {
14150: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14151: my %storecontent = ($storeunder => time,
14152: $storeunder.'.type' => 'date_start');
14153:
14154: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14155: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14156: }
14157: #
14158: # Set first page
14159: #
14160: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14161: || ($cloneid)) {
1.445 albertel 14162: use LONCAPA::map;
1.444 albertel 14163: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14164:
14165: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14166: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14167:
1.444 albertel 14168: $outcome .= ($fatal?$errtext:'read ok').' - ';
14169: my $title; my $url;
14170: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14171: $title=&mt('Syllabus');
1.444 albertel 14172: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14173: } else {
1.963 raeburn 14174: $title=&mt('Table of Contents');
1.444 albertel 14175: $url='/adm/navmaps';
14176: }
1.445 albertel 14177:
14178: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14179: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14180:
14181: if ($errtext) { $fatal=2; }
1.541 raeburn 14182: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14183: }
1.566 albertel 14184:
14185: return (1,$outcome);
1.444 albertel 14186: }
14187:
14188: ############################################################
14189: ############################################################
14190:
1.953 droeschl 14191: #SD
14192: # only Community and Course, or anything else?
1.378 raeburn 14193: sub course_type {
14194: my ($cid) = @_;
14195: if (!defined($cid)) {
14196: $cid = $env{'request.course.id'};
14197: }
1.404 albertel 14198: if (defined($env{'course.'.$cid.'.type'})) {
14199: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14200: } else {
14201: return 'Course';
1.377 raeburn 14202: }
14203: }
1.156 albertel 14204:
1.406 raeburn 14205: sub group_term {
14206: my $crstype = &course_type();
14207: my %names = (
14208: 'Course' => 'group',
1.865 raeburn 14209: 'Community' => 'group',
1.406 raeburn 14210: );
14211: return $names{$crstype};
14212: }
14213:
1.902 raeburn 14214: sub course_types {
14215: my @types = ('official','unofficial','community');
14216: my %typename = (
14217: official => 'Official course',
14218: unofficial => 'Unofficial course',
14219: community => 'Community',
14220: );
14221: return (\@types,\%typename);
14222: }
14223:
1.156 albertel 14224: sub icon {
14225: my ($file)=@_;
1.505 albertel 14226: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14227: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14228: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14229: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14230: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14231: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14232: $curfext.".gif") {
14233: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14234: $curfext.".gif";
14235: }
14236: }
1.249 albertel 14237: return &lonhttpdurl($iconname);
1.154 albertel 14238: }
1.84 albertel 14239:
1.575 albertel 14240: sub lonhttpdurl {
1.692 www 14241: #
14242: # Had been used for "small fry" static images on separate port 8080.
14243: # Modify here if lightweight http functionality desired again.
14244: # Currently eliminated due to increasing firewall issues.
14245: #
1.575 albertel 14246: my ($url)=@_;
1.692 www 14247: return $url;
1.215 albertel 14248: }
14249:
1.213 albertel 14250: sub connection_aborted {
14251: my ($r)=@_;
14252: $r->print(" ");$r->rflush();
14253: my $c = $r->connection;
14254: return $c->aborted();
14255: }
14256:
1.221 foxr 14257: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14258: # strings as 'strings'.
14259: sub escape_single {
1.221 foxr 14260: my ($input) = @_;
1.223 albertel 14261: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14262: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14263: return $input;
14264: }
1.223 albertel 14265:
1.222 foxr 14266: # Same as escape_single, but escape's "'s This
14267: # can be used for "strings"
14268: sub escape_double {
14269: my ($input) = @_;
14270: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14271: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14272: return $input;
14273: }
1.223 albertel 14274:
1.222 foxr 14275: # Escapes the last element of a full URL.
14276: sub escape_url {
14277: my ($url) = @_;
1.238 raeburn 14278: my @urlslices = split(/\//, $url,-1);
1.369 www 14279: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14280: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14281: }
1.462 albertel 14282:
1.820 raeburn 14283: sub compare_arrays {
14284: my ($arrayref1,$arrayref2) = @_;
14285: my (@difference,%count);
14286: @difference = ();
14287: %count = ();
14288: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14289: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14290: foreach my $element (keys(%count)) {
14291: if ($count{$element} == 1) {
14292: push(@difference,$element);
14293: }
14294: }
14295: }
14296: return @difference;
14297: }
14298:
1.817 bisitz 14299: # -------------------------------------------------------- Initialize user login
1.462 albertel 14300: sub init_user_environment {
1.463 albertel 14301: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14302: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14303:
14304: my $public=($username eq 'public' && $domain eq 'public');
14305:
14306: # See if old ID present, if so, remove
14307:
1.1062 raeburn 14308: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14309: my $now=time;
14310:
14311: if ($public) {
14312: my $max_public=100;
14313: my $oldest;
14314: my $oldest_time=0;
14315: for(my $next=1;$next<=$max_public;$next++) {
14316: if (-e $lonids."/publicuser_$next.id") {
14317: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14318: if ($mtime<$oldest_time || !$oldest_time) {
14319: $oldest_time=$mtime;
14320: $oldest=$next;
14321: }
14322: } else {
14323: $cookie="publicuser_$next";
14324: last;
14325: }
14326: }
14327: if (!$cookie) { $cookie="publicuser_$oldest"; }
14328: } else {
1.463 albertel 14329: # if this isn't a robot, kill any existing non-robot sessions
14330: if (!$args->{'robot'}) {
14331: opendir(DIR,$lonids);
14332: while ($filename=readdir(DIR)) {
14333: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14334: unlink($lonids.'/'.$filename);
14335: }
1.462 albertel 14336: }
1.463 albertel 14337: closedir(DIR);
1.462 albertel 14338: }
14339: # Give them a new cookie
1.463 albertel 14340: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14341: : $now.$$.int(rand(10000)));
1.463 albertel 14342: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14343:
14344: # Initialize roles
14345:
1.1062 raeburn 14346: ($userroles,$firstaccenv,$timerintenv) =
14347: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14348: }
14349: # ------------------------------------ Check browser type and MathML capability
14350:
14351: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.42 raeburn 14352: $clientunicode,$clientos,$clientmobile,$clientinfo) = &decode_user_agent($r);
1.462 albertel 14353:
14354: # ------------------------------------------------------------- Get environment
14355:
14356: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14357: my ($tmp) = keys(%userenv);
14358: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14359: } else {
14360: undef(%userenv);
14361: }
14362: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14363: $form->{'interface'}=$userenv{'interface'};
14364: }
14365: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14366:
14367: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14368: foreach my $option ('interface','localpath','localres') {
14369: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14370: }
14371: # --------------------------------------------------------- Write first profile
14372:
14373: {
14374: my %initial_env =
14375: ("user.name" => $username,
14376: "user.domain" => $domain,
14377: "user.home" => $authhost,
14378: "browser.type" => $clientbrowser,
14379: "browser.version" => $clientversion,
14380: "browser.mathml" => $clientmathml,
14381: "browser.unicode" => $clientunicode,
14382: "browser.os" => $clientos,
1.1075.2.42 raeburn 14383: "browser.mobile" => $clientmobile,
14384: "browser.info" => $clientinfo,
1.462 albertel 14385: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14386: "request.course.fn" => '',
14387: "request.course.uri" => '',
14388: "request.course.sec" => '',
14389: "request.role" => 'cm',
14390: "request.role.adv" => $env{'user.adv'},
14391: "request.host" => $ENV{'REMOTE_ADDR'},);
14392:
14393: if ($form->{'localpath'}) {
14394: $initial_env{"browser.localpath"} = $form->{'localpath'};
14395: $initial_env{"browser.localres"} = $form->{'localres'};
14396: }
14397:
14398: if ($form->{'interface'}) {
14399: $form->{'interface'}=~s/\W//gs;
14400: $initial_env{"browser.interface"} = $form->{'interface'};
14401: $env{'browser.interface'}=$form->{'interface'};
14402: }
14403:
1.1075.2.54 raeburn 14404: if ($form->{'iptoken'}) {
14405: my $lonhost = $r->dir_config('lonHostID');
14406: $initial_env{"user.noloadbalance"} = $lonhost;
14407: $env{'user.noloadbalance'} = $lonhost;
14408: }
14409:
1.981 raeburn 14410: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14411: my %domdef;
14412: unless ($domain eq 'public') {
14413: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14414: }
1.980 raeburn 14415:
1.1075.2.7 raeburn 14416: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14417: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14418: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14419: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14420: }
14421:
1.864 raeburn 14422: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 14423: $userenv{'canrequest.'.$crstype} =
14424: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14425: 'reload','requestcourses',
14426: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14427: }
14428:
1.1075.2.14 raeburn 14429: $userenv{'canrequest.author'} =
14430: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14431: 'reload','requestauthor',
14432: \%userenv,\%domdef,\%is_adv);
14433: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14434: $domain,$username);
14435: my $reqstatus = $reqauthor{'author_status'};
14436: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14437: if (ref($reqauthor{'author'}) eq 'HASH') {
14438: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14439: $reqauthor{'author'}{'timestamp'};
14440: }
14441: }
14442:
1.462 albertel 14443: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14444:
1.462 albertel 14445: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14446: &GDBM_WRCREAT(),0640)) {
14447: &_add_to_env(\%disk_env,\%initial_env);
14448: &_add_to_env(\%disk_env,\%userenv,'environment.');
14449: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14450: if (ref($firstaccenv) eq 'HASH') {
14451: &_add_to_env(\%disk_env,$firstaccenv);
14452: }
14453: if (ref($timerintenv) eq 'HASH') {
14454: &_add_to_env(\%disk_env,$timerintenv);
14455: }
1.463 albertel 14456: if (ref($args->{'extra_env'})) {
14457: &_add_to_env(\%disk_env,$args->{'extra_env'});
14458: }
1.462 albertel 14459: untie(%disk_env);
14460: } else {
1.705 tempelho 14461: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14462: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14463: return 'error: '.$!;
14464: }
14465: }
14466: $env{'request.role'}='cm';
14467: $env{'request.role.adv'}=$env{'user.adv'};
14468: $env{'browser.type'}=$clientbrowser;
14469:
14470: return $cookie;
14471:
14472: }
14473:
14474: sub _add_to_env {
14475: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14476: if (ref($env_data) eq 'HASH') {
14477: while (my ($key,$value) = each(%$env_data)) {
14478: $idf->{$prefix.$key} = $value;
14479: $env{$prefix.$key} = $value;
14480: }
1.462 albertel 14481: }
14482: }
14483:
1.685 tempelho 14484: # --- Get the symbolic name of a problem and the url
14485: sub get_symb {
14486: my ($request,$silent) = @_;
1.726 raeburn 14487: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14488: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14489: if ($symb eq '') {
14490: if (!$silent) {
1.1071 raeburn 14491: if (ref($request)) {
14492: $request->print("Unable to handle ambiguous references:$url:.");
14493: }
1.685 tempelho 14494: return ();
14495: }
14496: }
14497: &Apache::lonenc::check_decrypt(\$symb);
14498: return ($symb);
14499: }
14500:
14501: # --------------------------------------------------------------Get annotation
14502:
14503: sub get_annotation {
14504: my ($symb,$enc) = @_;
14505:
14506: my $key = $symb;
14507: if (!$enc) {
14508: $key =
14509: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14510: }
14511: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14512: return $annotation{$key};
14513: }
14514:
14515: sub clean_symb {
1.731 raeburn 14516: my ($symb,$delete_enc) = @_;
1.685 tempelho 14517:
14518: &Apache::lonenc::check_decrypt(\$symb);
14519: my $enc = $env{'request.enc'};
1.731 raeburn 14520: if ($delete_enc) {
1.730 raeburn 14521: delete($env{'request.enc'});
14522: }
1.685 tempelho 14523:
14524: return ($symb,$enc);
14525: }
1.462 albertel 14526:
1.990 raeburn 14527: sub build_release_hashes {
14528: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14529: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14530: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14531: (ref($randomizetry) eq 'HASH'));
14532: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14533: my ($item,$name,$value) = split(/:/,$key);
14534: if ($item eq 'parameter') {
14535: if (ref($checkparms->{$name}) eq 'ARRAY') {
14536: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14537: push(@{$checkparms->{$name}},$value);
14538: }
14539: } else {
14540: push(@{$checkparms->{$name}},$value);
14541: }
14542: } elsif ($item eq 'resourcetag') {
14543: if ($name eq 'responsetype') {
14544: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14545: }
14546: } elsif ($item eq 'course') {
14547: if ($name eq 'crstype') {
14548: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14549: }
14550: }
14551: }
14552: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14553: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14554: return;
14555: }
14556:
1.1075.2.11 raeburn 14557: sub update_content_constraints {
14558: my ($cdom,$cnum,$chome,$cid) = @_;
14559: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14560: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14561: my %checkresponsetypes;
14562: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14563: my ($item,$name,$value) = split(/:/,$key);
14564: if ($item eq 'resourcetag') {
14565: if ($name eq 'responsetype') {
14566: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14567: }
14568: }
14569: }
14570: my $navmap = Apache::lonnavmaps::navmap->new();
14571: if (defined($navmap)) {
14572: my %allresponses;
14573: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14574: my %responses = $res->responseTypes();
14575: foreach my $key (keys(%responses)) {
14576: next unless(exists($checkresponsetypes{$key}));
14577: $allresponses{$key} += $responses{$key};
14578: }
14579: }
14580: foreach my $key (keys(%allresponses)) {
14581: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14582: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14583: ($reqdmajor,$reqdminor) = ($major,$minor);
14584: }
14585: }
14586: undef($navmap);
14587: }
14588: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14589: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14590: }
14591: return;
14592: }
14593:
1.1075.2.27 raeburn 14594: sub allmaps_incourse {
14595: my ($cdom,$cnum,$chome,$cid) = @_;
14596: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14597: $cid = $env{'request.course.id'};
14598: $cdom = $env{'course.'.$cid.'.domain'};
14599: $cnum = $env{'course.'.$cid.'.num'};
14600: $chome = $env{'course.'.$cid.'.home'};
14601: }
14602: my %allmaps = ();
14603: my $lastchange =
14604: &Apache::lonnet::get_coursechange($cdom,$cnum);
14605: if ($lastchange > $env{'request.course.tied'}) {
14606: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14607: unless ($ferr) {
14608: &update_content_constraints($cdom,$cnum,$chome,$cid);
14609: }
14610: }
14611: my $navmap = Apache::lonnavmaps::navmap->new();
14612: if (defined($navmap)) {
14613: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14614: $allmaps{$res->src()} = 1;
14615: }
14616: }
14617: return \%allmaps;
14618: }
14619:
1.1075.2.11 raeburn 14620: sub parse_supplemental_title {
14621: my ($title) = @_;
14622:
14623: my ($foldertitle,$renametitle);
14624: if ($title =~ /&&&/) {
14625: $title = &HTML::Entites::decode($title);
14626: }
14627: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14628: $renametitle=$4;
14629: my ($time,$uname,$udom) = ($1,$2,$3);
14630: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14631: my $name = &plainname($uname,$udom);
14632: $name = &HTML::Entities::encode($name,'"<>&\'');
14633: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14634: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14635: $name.': <br />'.$foldertitle;
14636: }
14637: if (wantarray) {
14638: return ($title,$foldertitle,$renametitle);
14639: }
14640: return $title;
14641: }
14642:
1.1075.2.43 raeburn 14643: sub recurse_supplemental {
14644: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
14645: if ($suppmap) {
14646: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
14647: if ($fatal) {
14648: $errors ++;
14649: } else {
14650: if ($#LONCAPA::map::resources > 0) {
14651: foreach my $res (@LONCAPA::map::resources) {
14652: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
14653: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 14654: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
14655: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 14656: } else {
14657: $numfiles ++;
14658: }
14659: }
14660: }
14661: }
14662: }
14663: }
14664: return ($numfiles,$errors);
14665: }
14666:
1.1075.2.18 raeburn 14667: sub symb_to_docspath {
14668: my ($symb) = @_;
14669: return unless ($symb);
14670: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14671: if ($resurl=~/\.(sequence|page)$/) {
14672: $mapurl=$resurl;
14673: } elsif ($resurl eq 'adm/navmaps') {
14674: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14675: }
14676: my $mapresobj;
14677: my $navmap = Apache::lonnavmaps::navmap->new();
14678: if (ref($navmap)) {
14679: $mapresobj = $navmap->getResourceByUrl($mapurl);
14680: }
14681: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14682: my $type=$2;
14683: my $path;
14684: if (ref($mapresobj)) {
14685: my $pcslist = $mapresobj->map_hierarchy();
14686: if ($pcslist ne '') {
14687: foreach my $pc (split(/,/,$pcslist)) {
14688: next if ($pc <= 1);
14689: my $res = $navmap->getByMapPc($pc);
14690: if (ref($res)) {
14691: my $thisurl = $res->src();
14692: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14693: my $thistitle = $res->title();
14694: $path .= '&'.
14695: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 14696: &escape($thistitle).
1.1075.2.18 raeburn 14697: ':'.$res->randompick().
14698: ':'.$res->randomout().
14699: ':'.$res->encrypted().
14700: ':'.$res->randomorder().
14701: ':'.$res->is_page();
14702: }
14703: }
14704: }
14705: $path =~ s/^\&//;
14706: my $maptitle = $mapresobj->title();
14707: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 14708: $maptitle = 'Main Content';
1.1075.2.18 raeburn 14709: }
14710: $path .= (($path ne '')? '&' : '').
14711: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 14712: &escape($maptitle).
1.1075.2.18 raeburn 14713: ':'.$mapresobj->randompick().
14714: ':'.$mapresobj->randomout().
14715: ':'.$mapresobj->encrypted().
14716: ':'.$mapresobj->randomorder().
14717: ':'.$mapresobj->is_page();
14718: } else {
14719: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14720: my $ispage = (($type eq 'page')? 1 : '');
14721: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 14722: $maptitle = 'Main Content';
1.1075.2.18 raeburn 14723: }
14724: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 14725: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 14726: }
14727: unless ($mapurl eq 'default') {
14728: $path = 'default&'.
1.1075.2.46 raeburn 14729: &escape('Main Content').
1.1075.2.18 raeburn 14730: ':::::&'.$path;
14731: }
14732: return $path;
14733: }
14734:
1.1075.2.14 raeburn 14735: sub captcha_display {
14736: my ($context,$lonhost) = @_;
14737: my ($output,$error);
14738: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
14739: if ($captcha eq 'original') {
14740: $output = &create_captcha();
14741: unless ($output) {
14742: $error = 'captcha';
14743: }
14744: } elsif ($captcha eq 'recaptcha') {
14745: $output = &create_recaptcha($pubkey);
14746: unless ($output) {
14747: $error = 'recaptcha';
14748: }
14749: }
14750: return ($output,$error);
14751: }
14752:
14753: sub captcha_response {
14754: my ($context,$lonhost) = @_;
14755: my ($captcha_chk,$captcha_error);
14756: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
14757: if ($captcha eq 'original') {
14758: ($captcha_chk,$captcha_error) = &check_captcha();
14759: } elsif ($captcha eq 'recaptcha') {
14760: $captcha_chk = &check_recaptcha($privkey);
14761: } else {
14762: $captcha_chk = 1;
14763: }
14764: return ($captcha_chk,$captcha_error);
14765: }
14766:
14767: sub get_captcha_config {
14768: my ($context,$lonhost) = @_;
14769: my ($captcha,$pubkey,$privkey,$hashtocheck);
14770: my $hostname = &Apache::lonnet::hostname($lonhost);
14771: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14772: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
14773: if ($context eq 'usercreation') {
14774: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14775: if (ref($domconfig{$context}) eq 'HASH') {
14776: $hashtocheck = $domconfig{$context}{'cancreate'};
14777: if (ref($hashtocheck) eq 'HASH') {
14778: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14779: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14780: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14781: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14782: }
14783: if ($privkey && $pubkey) {
14784: $captcha = 'recaptcha';
14785: } else {
14786: $captcha = 'original';
14787: }
14788: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14789: $captcha = 'original';
14790: }
14791: }
14792: } else {
14793: $captcha = 'captcha';
14794: }
14795: } elsif ($context eq 'login') {
14796: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14797: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14798: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14799: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
14800: if ($privkey && $pubkey) {
14801: $captcha = 'recaptcha';
14802: } else {
14803: $captcha = 'original';
14804: }
14805: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14806: $captcha = 'original';
14807: }
14808: }
14809: return ($captcha,$pubkey,$privkey);
14810: }
14811:
14812: sub create_captcha {
14813: my %captcha_params = &captcha_settings();
14814: my ($output,$maxtries,$tries) = ('',10,0);
14815: while ($tries < $maxtries) {
14816: $tries ++;
14817: my $captcha = Authen::Captcha->new (
14818: output_folder => $captcha_params{'output_dir'},
14819: data_folder => $captcha_params{'db_dir'},
14820: );
14821: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14822:
14823: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14824: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14825: &mt('Type in the letters/numbers shown below').' '.
14826: '<input type="text" size="5" name="code" value="" /><br />'.
14827: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
14828: last;
14829: }
14830: }
14831: return $output;
14832: }
14833:
14834: sub captcha_settings {
14835: my %captcha_params = (
14836: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14837: www_output_dir => "/captchaspool",
14838: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14839: numchars => '5',
14840: );
14841: return %captcha_params;
14842: }
14843:
14844: sub check_captcha {
14845: my ($captcha_chk,$captcha_error);
14846: my $code = $env{'form.code'};
14847: my $md5sum = $env{'form.crypt'};
14848: my %captcha_params = &captcha_settings();
14849: my $captcha = Authen::Captcha->new(
14850: output_folder => $captcha_params{'output_dir'},
14851: data_folder => $captcha_params{'db_dir'},
14852: );
1.1075.2.26 raeburn 14853: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 14854: my %captcha_hash = (
14855: 0 => 'Code not checked (file error)',
14856: -1 => 'Failed: code expired',
14857: -2 => 'Failed: invalid code (not in database)',
14858: -3 => 'Failed: invalid code (code does not match crypt)',
14859: );
14860: if ($captcha_chk != 1) {
14861: $captcha_error = $captcha_hash{$captcha_chk}
14862: }
14863: return ($captcha_chk,$captcha_error);
14864: }
14865:
14866: sub create_recaptcha {
14867: my ($pubkey) = @_;
1.1075.2.51 raeburn 14868: my $use_ssl;
14869: if ($ENV{'SERVER_PORT'} == 443) {
14870: $use_ssl = 1;
14871: }
1.1075.2.14 raeburn 14872: my $captcha = Captcha::reCAPTCHA->new;
14873: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1075.2.51 raeburn 14874: $captcha->get_html($pubkey,undef,$use_ssl).
1.1075.2.14 raeburn 14875: &mt('If either word is hard to read, [_1] will replace them.',
1.1075.2.39 raeburn 14876: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1075.2.14 raeburn 14877: '<br /><br />';
14878: }
14879:
14880: sub check_recaptcha {
14881: my ($privkey) = @_;
14882: my $captcha_chk;
14883: my $captcha = Captcha::reCAPTCHA->new;
14884: my $captcha_result =
14885: $captcha->check_answer(
14886: $privkey,
14887: $ENV{'REMOTE_ADDR'},
14888: $env{'form.recaptcha_challenge_field'},
14889: $env{'form.recaptcha_response_field'},
14890: );
14891: if ($captcha_result->{is_valid}) {
14892: $captcha_chk = 1;
14893: }
14894: return $captcha_chk;
14895: }
14896:
1.41 ng 14897: =pod
14898:
14899: =back
14900:
1.112 bowersj2 14901: =cut
1.41 ng 14902:
1.112 bowersj2 14903: 1;
14904: __END__;
1.41 ng 14905:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>