Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.33
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.33! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.32 2013/03/19 00:49:27 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1075.2.25 raeburn 70: use Apache::lonuserutils();
1.1075.2.27 raeburn 71: use Apache::lonuserstate();
1.479 albertel 72: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 73: use DateTime::TimeZone;
1.687 raeburn 74: use DateTime::Locale::Catalog;
1.1075.2.14 raeburn 75: use Authen::Captcha;
76: use Captcha::reCAPTCHA;
1.117 www 77:
1.517 raeburn 78: # ---------------------------------------------- Designs
79: use vars qw(%defaultdesign);
80:
1.22 www 81: my $readit;
82:
1.517 raeburn 83:
1.157 matthew 84: ##
85: ## Global Variables
86: ##
1.46 matthew 87:
1.643 foxr 88:
89: # ----------------------------------------------- SSI with retries:
90: #
91:
92: =pod
93:
1.648 raeburn 94: =head1 Server Side include with retries:
1.643 foxr 95:
96: =over 4
97:
1.648 raeburn 98: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 99:
100: Performs an ssi with some number of retries. Retries continue either
101: until the result is ok or until the retry count supplied by the
102: caller is exhausted.
103:
104: Inputs:
1.648 raeburn 105:
106: =over 4
107:
1.643 foxr 108: resource - Identifies the resource to insert.
1.648 raeburn 109:
1.643 foxr 110: retries - Count of the number of retries allowed.
1.648 raeburn 111:
1.643 foxr 112: form - Hash that identifies the rendering options.
113:
1.648 raeburn 114: =back
115:
116: Returns:
117:
118: =over 4
119:
1.643 foxr 120: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 121:
1.643 foxr 122: response - The response from the last attempt (which may or may not have been successful.
123:
1.648 raeburn 124: =back
125:
126: =back
127:
1.643 foxr 128: =cut
129:
130: sub ssi_with_retries {
131: my ($resource, $retries, %form) = @_;
132:
133:
134: my $ok = 0; # True if we got a good response.
135: my $content;
136: my $response;
137:
138: # Try to get the ssi done. within the retries count:
139:
140: do {
141: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
142: $ok = $response->is_success;
1.650 www 143: if (!$ok) {
144: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
145: }
1.643 foxr 146: $retries--;
147: } while (!$ok && ($retries > 0));
148:
149: if (!$ok) {
150: $content = ''; # On error return an empty content.
151: }
152: return ($content, $response);
153:
154: }
155:
156:
157:
1.20 www 158: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 159: my %language;
1.124 www 160: my %supported_language;
1.1048 foxr 161: my %latex_language; # For choosing hyphenation in <transl..>
162: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 163: my %cprtag;
1.192 taceyjo1 164: my %scprtag;
1.351 www 165: my %fe; my %fd; my %fm;
1.41 ng 166: my %category_extensions;
1.12 harris41 167:
1.46 matthew 168: # ---------------------------------------------- Thesaurus variables
1.144 matthew 169: #
170: # %Keywords:
171: # A hash used by &keyword to determine if a word is considered a keyword.
172: # $thesaurus_db_file
173: # Scalar containing the full path to the thesaurus database.
1.46 matthew 174:
175: my %Keywords;
176: my $thesaurus_db_file;
177:
1.144 matthew 178: #
179: # Initialize values from language.tab, copyright.tab, filetypes.tab,
180: # thesaurus.tab, and filecategories.tab.
181: #
1.18 www 182: BEGIN {
1.46 matthew 183: # Variable initialization
184: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
185: #
1.22 www 186: unless ($readit) {
1.12 harris41 187: # ------------------------------------------------------------------- languages
188: {
1.158 raeburn 189: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
190: '/language.tab';
191: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 192: while (my $line = <$fh>) {
193: next if ($line=~/^\#/);
194: chomp($line);
1.1048 foxr 195: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 196: $language{$key}=$val.' - '.$enc;
197: if ($sup) {
198: $supported_language{$key}=$sup;
199: }
1.1048 foxr 200: if ($latex) {
201: $latex_language_bykey{$key} = $latex;
202: $latex_language{$two} = $latex;
203: }
1.158 raeburn 204: }
205: close($fh);
206: }
1.12 harris41 207: }
208: # ------------------------------------------------------------------ copyrights
209: {
1.158 raeburn 210: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
211: '/copyright.tab';
212: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 213: while (my $line = <$fh>) {
214: next if ($line=~/^\#/);
215: chomp($line);
216: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 217: $cprtag{$key}=$val;
218: }
219: close($fh);
220: }
1.12 harris41 221: }
1.351 www 222: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 223: {
224: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
225: '/source_copyright.tab';
226: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 227: while (my $line = <$fh>) {
228: next if ($line =~ /^\#/);
229: chomp($line);
230: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 231: $scprtag{$key}=$val;
232: }
233: close($fh);
234: }
235: }
1.63 www 236:
1.517 raeburn 237: # -------------------------------------------------------------- default domain designs
1.63 www 238: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 239: my $designfile = $designdir.'/default.tab';
240: if ( open (my $fh,"<$designfile") ) {
241: while (my $line = <$fh>) {
242: next if ($line =~ /^\#/);
243: chomp($line);
244: my ($key,$val)=(split(/\=/,$line));
245: if ($val) { $defaultdesign{$key}=$val; }
246: }
247: close($fh);
1.63 www 248: }
249:
1.15 harris41 250: # ------------------------------------------------------------- file categories
251: {
1.158 raeburn 252: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
253: '/filecategories.tab';
254: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 255: while (my $line = <$fh>) {
256: next if ($line =~ /^\#/);
257: chomp($line);
258: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 259: push @{$category_extensions{lc($category)}},$extension;
260: }
261: close($fh);
262: }
263:
1.15 harris41 264: }
1.12 harris41 265: # ------------------------------------------------------------------ file types
266: {
1.158 raeburn 267: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
268: '/filetypes.tab';
269: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 270: while (my $line = <$fh>) {
271: next if ($line =~ /^\#/);
272: chomp($line);
273: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 274: if ($descr ne '') {
275: $fe{$ending}=lc($emb);
276: $fd{$ending}=$descr;
1.351 www 277: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 278: }
279: }
280: close($fh);
281: }
1.12 harris41 282: }
1.22 www 283: &Apache::lonnet::logthis(
1.705 tempelho 284: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 285: $readit=1;
1.46 matthew 286: } # end of unless($readit)
1.32 matthew 287:
288: }
1.112 bowersj2 289:
1.42 matthew 290: ###############################################################
291: ## HTML and Javascript Helper Functions ##
292: ###############################################################
293:
294: =pod
295:
1.112 bowersj2 296: =head1 HTML and Javascript Functions
1.42 matthew 297:
1.112 bowersj2 298: =over 4
299:
1.648 raeburn 300: =item * &browser_and_searcher_javascript()
1.112 bowersj2 301:
302: X<browsing, javascript>X<searching, javascript>Returns a string
303: containing javascript with two functions, C<openbrowser> and
304: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
305: tags.
1.42 matthew 306:
1.648 raeburn 307: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 308:
309: inputs: formname, elementname, only, omit
310:
311: formname and elementname indicate the name of the html form and name of
312: the element that the results of the browsing selection are to be placed in.
313:
314: Specifying 'only' will restrict the browser to displaying only files
1.185 www 315: with the given extension. Can be a comma separated list.
1.42 matthew 316:
317: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 318: with the given extension. Can be a comma separated list.
1.42 matthew 319:
1.648 raeburn 320: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 321:
322: Inputs: formname, elementname
323:
324: formname and elementname specify the name of the html form and the name
325: of the element the selection from the search results will be placed in.
1.542 raeburn 326:
1.42 matthew 327: =cut
328:
329: sub browser_and_searcher_javascript {
1.199 albertel 330: my ($mode)=@_;
331: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 332: my $resurl=&escape_single(&lastresurl());
1.42 matthew 333: return <<END;
1.219 albertel 334: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 335: var editbrowser = null;
1.135 albertel 336: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 337: var url = '$resurl/?';
1.42 matthew 338: if (editbrowser == null) {
339: url += 'launch=1&';
340: }
341: url += 'catalogmode=interactive&';
1.199 albertel 342: url += 'mode=$mode&';
1.611 albertel 343: url += 'inhibitmenu=yes&';
1.42 matthew 344: url += 'form=' + formname + '&';
345: if (only != null) {
346: url += 'only=' + only + '&';
1.217 albertel 347: } else {
348: url += 'only=&';
349: }
1.42 matthew 350: if (omit != null) {
351: url += 'omit=' + omit + '&';
1.217 albertel 352: } else {
353: url += 'omit=&';
354: }
1.135 albertel 355: if (titleelement != null) {
356: url += 'titleelement=' + titleelement + '&';
1.217 albertel 357: } else {
358: url += 'titleelement=&';
359: }
1.42 matthew 360: url += 'element=' + elementname + '';
361: var title = 'Browser';
1.435 albertel 362: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 363: options += ',width=700,height=600';
364: editbrowser = open(url,title,options,'1');
365: editbrowser.focus();
366: }
367: var editsearcher;
1.135 albertel 368: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 369: var url = '/adm/searchcat?';
370: if (editsearcher == null) {
371: url += 'launch=1&';
372: }
373: url += 'catalogmode=interactive&';
1.199 albertel 374: url += 'mode=$mode&';
1.42 matthew 375: url += 'form=' + formname + '&';
1.135 albertel 376: if (titleelement != null) {
377: url += 'titleelement=' + titleelement + '&';
1.217 albertel 378: } else {
379: url += 'titleelement=&';
380: }
1.42 matthew 381: url += 'element=' + elementname + '';
382: var title = 'Search';
1.435 albertel 383: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 384: options += ',width=700,height=600';
385: editsearcher = open(url,title,options,'1');
386: editsearcher.focus();
387: }
1.219 albertel 388: // END LON-CAPA Internal -->
1.42 matthew 389: END
1.170 www 390: }
391:
392: sub lastresurl {
1.258 albertel 393: if ($env{'environment.lastresurl'}) {
394: return $env{'environment.lastresurl'}
1.170 www 395: } else {
396: return '/res';
397: }
398: }
399:
400: sub storeresurl {
401: my $resurl=&Apache::lonnet::clutter(shift);
402: unless ($resurl=~/^\/res/) { return 0; }
403: $resurl=~s/\/$//;
404: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 405: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 406: return 1;
1.42 matthew 407: }
408:
1.74 www 409: sub studentbrowser_javascript {
1.111 www 410: unless (
1.258 albertel 411: (($env{'request.course.id'}) &&
1.302 albertel 412: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
413: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
414: '/'.$env{'request.course.sec'})
415: ))
1.258 albertel 416: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 417: ) { return ''; }
1.74 www 418: return (<<'ENDSTDBRW');
1.776 bisitz 419: <script type="text/javascript" language="Javascript">
1.824 bisitz 420: // <![CDATA[
1.74 www 421: var stdeditbrowser;
1.999 www 422: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 423: var url = '/adm/pickstudent?';
424: var filter;
1.558 albertel 425: if (!ignorefilter) {
426: eval('filter=document.'+formname+'.'+uname+'.value;');
427: }
1.74 www 428: if (filter != null) {
429: if (filter != '') {
430: url += 'filter='+filter+'&';
431: }
432: }
433: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 434: '&udomelement='+udom+
435: '&clicker='+clicker;
1.111 www 436: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 437: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 438: var title = 'Student_Browser';
1.74 www 439: var options = 'scrollbars=1,resizable=1,menubar=0';
440: options += ',width=700,height=600';
441: stdeditbrowser = open(url,title,options,'1');
442: stdeditbrowser.focus();
443: }
1.824 bisitz 444: // ]]>
1.74 www 445: </script>
446: ENDSTDBRW
447: }
1.42 matthew 448:
1.1003 www 449: sub resourcebrowser_javascript {
450: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 451: return (<<'ENDRESBRW');
1.1003 www 452: <script type="text/javascript" language="Javascript">
453: // <![CDATA[
454: var reseditbrowser;
1.1004 www 455: function openresbrowser(formname,reslink) {
1.1005 www 456: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 457: var title = 'Resource_Browser';
458: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 459: options += ',width=700,height=500';
1.1004 www 460: reseditbrowser = open(url,title,options,'1');
461: reseditbrowser.focus();
1.1003 www 462: }
463: // ]]>
464: </script>
1.1004 www 465: ENDRESBRW
1.1003 www 466: }
467:
1.74 www 468: sub selectstudent_link {
1.999 www 469: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
470: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
471: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
472: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 473: if ($env{'request.course.id'}) {
1.302 albertel 474: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
475: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
476: '/'.$env{'request.course.sec'})) {
1.111 www 477: return '';
478: }
1.999 www 479: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 480: if ($courseadvonly) {
481: $callargs .= ",'',1,1";
482: }
483: return '<span class="LC_nobreak">'.
484: '<a href="javascript:openstdbrowser('.$callargs.');">'.
485: &mt('Select User').'</a></span>';
1.74 www 486: }
1.258 albertel 487: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 488: $callargs .= ",'',1";
1.793 raeburn 489: return '<span class="LC_nobreak">'.
490: '<a href="javascript:openstdbrowser('.$callargs.');">'.
491: &mt('Select User').'</a></span>';
1.111 www 492: }
493: return '';
1.91 www 494: }
495:
1.1004 www 496: sub selectresource_link {
497: my ($form,$reslink,$arg)=@_;
498:
499: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
500: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
501: unless ($env{'request.course.id'}) { return $arg; }
502: return '<span class="LC_nobreak">'.
503: '<a href="javascript:openresbrowser('.$callargs.');">'.
504: $arg.'</a></span>';
505: }
506:
507:
508:
1.653 raeburn 509: sub authorbrowser_javascript {
510: return <<"ENDAUTHORBRW";
1.776 bisitz 511: <script type="text/javascript" language="JavaScript">
1.824 bisitz 512: // <![CDATA[
1.653 raeburn 513: var stdeditbrowser;
514:
515: function openauthorbrowser(formname,udom) {
516: var url = '/adm/pickauthor?';
517: url += 'form='+formname+'&roledom='+udom;
518: var title = 'Author_Browser';
519: var options = 'scrollbars=1,resizable=1,menubar=0';
520: options += ',width=700,height=600';
521: stdeditbrowser = open(url,title,options,'1');
522: stdeditbrowser.focus();
523: }
524:
1.824 bisitz 525: // ]]>
1.653 raeburn 526: </script>
527: ENDAUTHORBRW
528: }
529:
1.91 www 530: sub coursebrowser_javascript {
1.1075.2.31 raeburn 531: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
532: $credits_element) = @_;
1.932 raeburn 533: my $wintitle = 'Course_Browser';
1.931 raeburn 534: if ($crstype eq 'Community') {
1.932 raeburn 535: $wintitle = 'Community_Browser';
1.909 raeburn 536: }
1.876 raeburn 537: my $id_functions = &javascript_index_functions();
538: my $output = '
1.776 bisitz 539: <script type="text/javascript" language="JavaScript">
1.824 bisitz 540: // <![CDATA[
1.468 raeburn 541: var stdeditbrowser;'."\n";
1.876 raeburn 542:
543: $output .= <<"ENDSTDBRW";
1.909 raeburn 544: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 545: var url = '/adm/pickcourse?';
1.895 raeburn 546: var formid = getFormIdByName(formname);
1.876 raeburn 547: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 548: if (domainfilter != null) {
549: if (domainfilter != '') {
550: url += 'domainfilter='+domainfilter+'&';
551: }
552: }
1.91 www 553: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 554: '&cdomelement='+udom+
555: '&cnameelement='+desc;
1.468 raeburn 556: if (extra_element !=null && extra_element != '') {
1.594 raeburn 557: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 558: url += '&roleelement='+extra_element;
559: if (domainfilter == null || domainfilter == '') {
560: url += '&domainfilter='+extra_element;
561: }
1.234 raeburn 562: }
1.468 raeburn 563: else {
564: if (formname == 'portform') {
565: url += '&setroles='+extra_element;
1.800 raeburn 566: } else {
567: if (formname == 'rules') {
568: url += '&fixeddom='+extra_element;
569: }
1.468 raeburn 570: }
571: }
1.230 raeburn 572: }
1.909 raeburn 573: if (type != null && type != '') {
574: url += '&type='+type;
575: }
576: if (type_elem != null && type_elem != '') {
577: url += '&typeelement='+type_elem;
578: }
1.872 raeburn 579: if (formname == 'ccrs') {
580: var ownername = document.forms[formid].ccuname.value;
581: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
582: url += '&cloner='+ownername+':'+ownerdom;
583: }
1.293 raeburn 584: if (multflag !=null && multflag != '') {
585: url += '&multiple='+multflag;
586: }
1.909 raeburn 587: var title = '$wintitle';
1.91 www 588: var options = 'scrollbars=1,resizable=1,menubar=0';
589: options += ',width=700,height=600';
590: stdeditbrowser = open(url,title,options,'1');
591: stdeditbrowser.focus();
592: }
1.876 raeburn 593: $id_functions
594: ENDSTDBRW
1.1075.2.31 raeburn 595: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
596: $output .= &setsec_javascript($sec_element,$formname,$role_element,
597: $credits_element);
1.876 raeburn 598: }
599: $output .= '
600: // ]]>
601: </script>';
602: return $output;
603: }
604:
605: sub javascript_index_functions {
606: return <<"ENDJS";
607:
608: function getFormIdByName(formname) {
609: for (var i=0;i<document.forms.length;i++) {
610: if (document.forms[i].name == formname) {
611: return i;
612: }
613: }
614: return -1;
615: }
616:
617: function getIndexByName(formid,item) {
618: for (var i=0;i<document.forms[formid].elements.length;i++) {
619: if (document.forms[formid].elements[i].name == item) {
620: return i;
621: }
622: }
623: return -1;
624: }
1.468 raeburn 625:
1.876 raeburn 626: function getDomainFromSelectbox(formname,udom) {
627: var userdom;
628: var formid = getFormIdByName(formname);
629: if (formid > -1) {
630: var domid = getIndexByName(formid,udom);
631: if (domid > -1) {
632: if (document.forms[formid].elements[domid].type == 'select-one') {
633: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
634: }
635: if (document.forms[formid].elements[domid].type == 'hidden') {
636: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 637: }
638: }
639: }
1.876 raeburn 640: return userdom;
641: }
642:
643: ENDJS
1.468 raeburn 644:
1.876 raeburn 645: }
646:
1.1017 raeburn 647: sub javascript_array_indexof {
1.1018 raeburn 648: return <<ENDJS;
1.1017 raeburn 649: <script type="text/javascript" language="JavaScript">
650: // <![CDATA[
651:
652: if (!Array.prototype.indexOf) {
653: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
654: "use strict";
655: if (this === void 0 || this === null) {
656: throw new TypeError();
657: }
658: var t = Object(this);
659: var len = t.length >>> 0;
660: if (len === 0) {
661: return -1;
662: }
663: var n = 0;
664: if (arguments.length > 0) {
665: n = Number(arguments[1]);
666: if (n !== n) { // shortcut for verifying if it's NaN
667: n = 0;
668: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
669: n = (n > 0 || -1) * Math.floor(Math.abs(n));
670: }
671: }
672: if (n >= len) {
673: return -1;
674: }
675: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
676: for (; k < len; k++) {
677: if (k in t && t[k] === searchElement) {
678: return k;
679: }
680: }
681: return -1;
682: }
683: }
684:
685: // ]]>
686: </script>
687:
688: ENDJS
689:
690: }
691:
1.876 raeburn 692: sub userbrowser_javascript {
693: my $id_functions = &javascript_index_functions();
694: return <<"ENDUSERBRW";
695:
1.888 raeburn 696: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 697: var url = '/adm/pickuser?';
698: var userdom = getDomainFromSelectbox(formname,udom);
699: if (userdom != null) {
700: if (userdom != '') {
701: url += 'srchdom='+userdom+'&';
702: }
703: }
704: url += 'form=' + formname + '&unameelement='+uname+
705: '&udomelement='+udom+
706: '&ulastelement='+ulast+
707: '&ufirstelement='+ufirst+
708: '&uemailelement='+uemail+
1.881 raeburn 709: '&hideudomelement='+hideudom+
710: '&coursedom='+crsdom;
1.888 raeburn 711: if ((caller != null) && (caller != undefined)) {
712: url += '&caller='+caller;
713: }
1.876 raeburn 714: var title = 'User_Browser';
715: var options = 'scrollbars=1,resizable=1,menubar=0';
716: options += ',width=700,height=600';
717: var stdeditbrowser = open(url,title,options,'1');
718: stdeditbrowser.focus();
719: }
720:
1.888 raeburn 721: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 722: var formid = getFormIdByName(formname);
723: if (formid > -1) {
1.888 raeburn 724: var unameid = getIndexByName(formid,uname);
1.876 raeburn 725: var domid = getIndexByName(formid,udom);
726: var hidedomid = getIndexByName(formid,origdom);
727: if (hidedomid > -1) {
728: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 729: var unameval = document.forms[formid].elements[unameid].value;
730: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
731: if (domid > -1) {
732: var slct = document.forms[formid].elements[domid];
733: if (slct.type == 'select-one') {
734: var i;
735: for (i=0;i<slct.length;i++) {
736: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
737: }
738: }
739: if (slct.type == 'hidden') {
740: slct.value = fixeddom;
1.876 raeburn 741: }
742: }
1.468 raeburn 743: }
744: }
745: }
1.876 raeburn 746: return;
747: }
748:
749: $id_functions
750: ENDUSERBRW
1.468 raeburn 751: }
752:
753: sub setsec_javascript {
1.1075.2.31 raeburn 754: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 755: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
756: $communityrolestr);
757: if ($role_element ne '') {
758: my @allroles = ('st','ta','ep','in','ad');
759: foreach my $crstype ('Course','Community') {
760: if ($crstype eq 'Community') {
761: foreach my $role (@allroles) {
762: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
763: }
764: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
765: } else {
766: foreach my $role (@allroles) {
767: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
768: }
769: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
770: }
771: }
772: $rolestr = '"'.join('","',@allroles).'"';
773: $courserolestr = '"'.join('","',@courserolenames).'"';
774: $communityrolestr = '"'.join('","',@communityrolenames).'"';
775: }
1.468 raeburn 776: my $setsections = qq|
777: function setSect(sectionlist) {
1.629 raeburn 778: var sectionsArray = new Array();
779: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
780: sectionsArray = sectionlist.split(",");
781: }
1.468 raeburn 782: var numSections = sectionsArray.length;
783: document.$formname.$sec_element.length = 0;
784: if (numSections == 0) {
785: document.$formname.$sec_element.multiple=false;
786: document.$formname.$sec_element.size=1;
787: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
788: } else {
789: if (numSections == 1) {
790: document.$formname.$sec_element.multiple=false;
791: document.$formname.$sec_element.size=1;
792: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
793: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
794: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
795: } else {
796: for (var i=0; i<numSections; i++) {
797: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
798: }
799: document.$formname.$sec_element.multiple=true
800: if (numSections < 3) {
801: document.$formname.$sec_element.size=numSections;
802: } else {
803: document.$formname.$sec_element.size=3;
804: }
805: document.$formname.$sec_element.options[0].selected = false
806: }
807: }
1.91 www 808: }
1.905 raeburn 809:
810: function setRole(crstype) {
1.468 raeburn 811: |;
1.905 raeburn 812: if ($role_element eq '') {
813: $setsections .= ' return;
814: }
815: ';
816: } else {
817: $setsections .= qq|
818: var elementLength = document.$formname.$role_element.length;
819: var allroles = Array($rolestr);
820: var courserolenames = Array($courserolestr);
821: var communityrolenames = Array($communityrolestr);
822: if (elementLength != undefined) {
823: if (document.$formname.$role_element.options[5].value == 'cc') {
824: if (crstype == 'Course') {
825: return;
826: } else {
827: allroles[5] = 'co';
828: for (var i=0; i<6; i++) {
829: document.$formname.$role_element.options[i].value = allroles[i];
830: document.$formname.$role_element.options[i].text = communityrolenames[i];
831: }
832: }
833: } else {
834: if (crstype == 'Community') {
835: return;
836: } else {
837: allroles[5] = 'cc';
838: for (var i=0; i<6; i++) {
839: document.$formname.$role_element.options[i].value = allroles[i];
840: document.$formname.$role_element.options[i].text = courserolenames[i];
841: }
842: }
843: }
844: }
845: return;
846: }
847: |;
848: }
1.1075.2.31 raeburn 849: if ($credits_element) {
850: $setsections .= qq|
851: function setCredits(defaultcredits) {
852: document.$formname.$credits_element.value = defaultcredits;
853: return;
854: }
855: |;
856: }
1.468 raeburn 857: return $setsections;
858: }
859:
1.91 www 860: sub selectcourse_link {
1.909 raeburn 861: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
862: $typeelement) = @_;
863: my $type = $selecttype;
1.871 raeburn 864: my $linktext = &mt('Select Course');
865: if ($selecttype eq 'Community') {
1.909 raeburn 866: $linktext = &mt('Select Community');
1.906 raeburn 867: } elsif ($selecttype eq 'Course/Community') {
868: $linktext = &mt('Select Course/Community');
1.909 raeburn 869: $type = '';
1.1019 raeburn 870: } elsif ($selecttype eq 'Select') {
871: $linktext = &mt('Select');
872: $type = '';
1.871 raeburn 873: }
1.787 bisitz 874: return '<span class="LC_nobreak">'
875: ."<a href='"
876: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
877: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 878: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 879: ."'>".$linktext.'</a>'
1.787 bisitz 880: .'</span>';
1.74 www 881: }
1.42 matthew 882:
1.653 raeburn 883: sub selectauthor_link {
884: my ($form,$udom)=@_;
885: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
886: &mt('Select Author').'</a>';
887: }
888:
1.876 raeburn 889: sub selectuser_link {
1.881 raeburn 890: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 891: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 892: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 893: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 894: ');">'.$linktext.'</a>';
1.876 raeburn 895: }
896:
1.273 raeburn 897: sub check_uncheck_jscript {
898: my $jscript = <<"ENDSCRT";
899: function checkAll(field) {
900: if (field.length > 0) {
901: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 902: if (!field[i].disabled) {
903: field[i].checked = true;
904: }
1.273 raeburn 905: }
906: } else {
1.1075.2.14 raeburn 907: if (!field.disabled) {
908: field.checked = true;
909: }
1.273 raeburn 910: }
911: }
912:
913: function uncheckAll(field) {
914: if (field.length > 0) {
915: for (i = 0; i < field.length; i++) {
916: field[i].checked = false ;
1.543 albertel 917: }
918: } else {
1.273 raeburn 919: field.checked = false ;
920: }
921: }
922: ENDSCRT
923: return $jscript;
924: }
925:
1.656 www 926: sub select_timezone {
1.659 raeburn 927: my ($name,$selected,$onchange,$includeempty)=@_;
928: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
929: if ($includeempty) {
930: $output .= '<option value=""';
931: if (($selected eq '') || ($selected eq 'local')) {
932: $output .= ' selected="selected" ';
933: }
934: $output .= '> </option>';
935: }
1.657 raeburn 936: my @timezones = DateTime::TimeZone->all_names;
937: foreach my $tzone (@timezones) {
938: $output.= '<option value="'.$tzone.'"';
939: if ($tzone eq $selected) {
940: $output.=' selected="selected"';
941: }
942: $output.=">$tzone</option>\n";
1.656 www 943: }
944: $output.="</select>";
945: return $output;
946: }
1.273 raeburn 947:
1.687 raeburn 948: sub select_datelocale {
949: my ($name,$selected,$onchange,$includeempty)=@_;
950: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
951: if ($includeempty) {
952: $output .= '<option value=""';
953: if ($selected eq '') {
954: $output .= ' selected="selected" ';
955: }
956: $output .= '> </option>';
957: }
958: my (@possibles,%locale_names);
959: my @locales = DateTime::Locale::Catalog::Locales;
960: foreach my $locale (@locales) {
961: if (ref($locale) eq 'HASH') {
962: my $id = $locale->{'id'};
963: if ($id ne '') {
964: my $en_terr = $locale->{'en_territory'};
965: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 966: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 967: if (grep(/^en$/,@languages) || !@languages) {
968: if ($en_terr ne '') {
969: $locale_names{$id} = '('.$en_terr.')';
970: } elsif ($native_terr ne '') {
971: $locale_names{$id} = $native_terr;
972: }
973: } else {
974: if ($native_terr ne '') {
975: $locale_names{$id} = $native_terr.' ';
976: } elsif ($en_terr ne '') {
977: $locale_names{$id} = '('.$en_terr.')';
978: }
979: }
980: push (@possibles,$id);
981: }
982: }
983: }
984: foreach my $item (sort(@possibles)) {
985: $output.= '<option value="'.$item.'"';
986: if ($item eq $selected) {
987: $output.=' selected="selected"';
988: }
989: $output.=">$item";
990: if ($locale_names{$item} ne '') {
991: $output.=" $locale_names{$item}</option>\n";
992: }
993: $output.="</option>\n";
994: }
995: $output.="</select>";
996: return $output;
997: }
998:
1.792 raeburn 999: sub select_language {
1000: my ($name,$selected,$includeempty) = @_;
1001: my %langchoices;
1002: if ($includeempty) {
1.1075.2.32 raeburn 1003: %langchoices = ('' => 'No language preference');
1.792 raeburn 1004: }
1005: foreach my $id (&languageids()) {
1006: my $code = &supportedlanguagecode($id);
1007: if ($code) {
1008: $langchoices{$code} = &plainlanguagedescription($id);
1009: }
1010: }
1.1075.2.32 raeburn 1011: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1012: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1013: }
1014:
1.42 matthew 1015: =pod
1.36 matthew 1016:
1.648 raeburn 1017: =item * &linked_select_forms(...)
1.36 matthew 1018:
1019: linked_select_forms returns a string containing a <script></script> block
1020: and html for two <select> menus. The select menus will be linked in that
1021: changing the value of the first menu will result in new values being placed
1022: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1023: order unless a defined order is provided.
1.36 matthew 1024:
1025: linked_select_forms takes the following ordered inputs:
1026:
1027: =over 4
1028:
1.112 bowersj2 1029: =item * $formname, the name of the <form> tag
1.36 matthew 1030:
1.112 bowersj2 1031: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1032:
1.112 bowersj2 1033: =item * $firstdefault, the default value for the first menu
1.36 matthew 1034:
1.112 bowersj2 1035: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1036:
1.112 bowersj2 1037: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1038:
1.112 bowersj2 1039: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1040:
1.609 raeburn 1041: =item * $menuorder, the order of values in the first menu
1042:
1.1075.2.31 raeburn 1043: =item * $onchangefirst, additional javascript call to execute for an onchange
1044: event for the first <select> tag
1045:
1046: =item * $onchangesecond, additional javascript call to execute for an onchange
1047: event for the second <select> tag
1048:
1.41 ng 1049: =back
1050:
1.36 matthew 1051: Below is an example of such a hash. Only the 'text', 'default', and
1052: 'select2' keys must appear as stated. keys(%menu) are the possible
1053: values for the first select menu. The text that coincides with the
1.41 ng 1054: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1055: and text for the second menu are given in the hash pointed to by
1056: $menu{$choice1}->{'select2'}.
1057:
1.112 bowersj2 1058: my %menu = ( A1 => { text =>"Choice A1" ,
1059: default => "B3",
1060: select2 => {
1061: B1 => "Choice B1",
1062: B2 => "Choice B2",
1063: B3 => "Choice B3",
1064: B4 => "Choice B4"
1.609 raeburn 1065: },
1066: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1067: },
1068: A2 => { text =>"Choice A2" ,
1069: default => "C2",
1070: select2 => {
1071: C1 => "Choice C1",
1072: C2 => "Choice C2",
1073: C3 => "Choice C3"
1.609 raeburn 1074: },
1075: order => ['C2','C1','C3'],
1.112 bowersj2 1076: },
1077: A3 => { text =>"Choice A3" ,
1078: default => "D6",
1079: select2 => {
1080: D1 => "Choice D1",
1081: D2 => "Choice D2",
1082: D3 => "Choice D3",
1083: D4 => "Choice D4",
1084: D5 => "Choice D5",
1085: D6 => "Choice D6",
1086: D7 => "Choice D7"
1.609 raeburn 1087: },
1088: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1089: }
1090: );
1.36 matthew 1091:
1092: =cut
1093:
1094: sub linked_select_forms {
1095: my ($formname,
1096: $middletext,
1097: $firstdefault,
1098: $firstselectname,
1099: $secondselectname,
1.609 raeburn 1100: $hashref,
1101: $menuorder,
1.1075.2.31 raeburn 1102: $onchangefirst,
1103: $onchangesecond
1.36 matthew 1104: ) = @_;
1105: my $second = "document.$formname.$secondselectname";
1106: my $first = "document.$formname.$firstselectname";
1107: # output the javascript to do the changing
1108: my $result = '';
1.776 bisitz 1109: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1110: $result.="// <![CDATA[\n";
1.36 matthew 1111: $result.="var select2data = new Object();\n";
1112: $" = '","';
1113: my $debug = '';
1114: foreach my $s1 (sort(keys(%$hashref))) {
1115: $result.="select2data.d_$s1 = new Object();\n";
1116: $result.="select2data.d_$s1.def = new String('".
1117: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1118: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1119: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1120: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1121: @s2values = @{$hashref->{$s1}->{'order'}};
1122: }
1.36 matthew 1123: $result.="\"@s2values\");\n";
1124: $result.="select2data.d_$s1.texts = new Array(";
1125: my @s2texts;
1126: foreach my $value (@s2values) {
1127: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1128: }
1129: $result.="\"@s2texts\");\n";
1130: }
1131: $"=' ';
1132: $result.= <<"END";
1133:
1134: function select1_changed() {
1135: // Determine new choice
1136: var newvalue = "d_" + $first.value;
1137: // update select2
1138: var values = select2data[newvalue].values;
1139: var texts = select2data[newvalue].texts;
1140: var select2def = select2data[newvalue].def;
1141: var i;
1142: // out with the old
1143: for (i = 0; i < $second.options.length; i++) {
1144: $second.options[i] = null;
1145: }
1146: // in with the nuclear
1147: for (i=0;i<values.length; i++) {
1148: $second.options[i] = new Option(values[i]);
1.143 matthew 1149: $second.options[i].value = values[i];
1.36 matthew 1150: $second.options[i].text = texts[i];
1151: if (values[i] == select2def) {
1152: $second.options[i].selected = true;
1153: }
1154: }
1155: }
1.824 bisitz 1156: // ]]>
1.36 matthew 1157: </script>
1158: END
1159: # output the initial values for the selection lists
1.1075.2.31 raeburn 1160: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1161: my @order = sort(keys(%{$hashref}));
1162: if (ref($menuorder) eq 'ARRAY') {
1163: @order = @{$menuorder};
1164: }
1165: foreach my $value (@order) {
1.36 matthew 1166: $result.=" <option value=\"$value\" ";
1.253 albertel 1167: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1168: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1169: }
1170: $result .= "</select>\n";
1171: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1172: $result .= $middletext;
1.1075.2.31 raeburn 1173: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1174: if ($onchangesecond) {
1175: $result .= ' onchange="'.$onchangesecond.'"';
1176: }
1177: $result .= ">\n";
1.36 matthew 1178: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1179:
1180: my @secondorder = sort(keys(%select2));
1181: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1182: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1183: }
1184: foreach my $value (@secondorder) {
1.36 matthew 1185: $result.=" <option value=\"$value\" ";
1.253 albertel 1186: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1187: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1188: }
1189: $result .= "</select>\n";
1190: # return $debug;
1191: return $result;
1192: } # end of sub linked_select_forms {
1193:
1.45 matthew 1194: =pod
1.44 bowersj2 1195:
1.973 raeburn 1196: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1197:
1.112 bowersj2 1198: Returns a string corresponding to an HTML link to the given help
1199: $topic, where $topic corresponds to the name of a .tex file in
1200: /home/httpd/html/adm/help/tex, with underscores replaced by
1201: spaces.
1202:
1203: $text will optionally be linked to the same topic, allowing you to
1204: link text in addition to the graphic. If you do not want to link
1205: text, but wish to specify one of the later parameters, pass an
1206: empty string.
1207:
1208: $stayOnPage is a value that will be interpreted as a boolean. If true,
1209: the link will not open a new window. If false, the link will open
1210: a new window using Javascript. (Default is false.)
1211:
1212: $width and $height are optional numerical parameters that will
1213: override the width and height of the popped up window, which may
1.973 raeburn 1214: be useful for certain help topics with big pictures included.
1215:
1216: $imgid is the id of the img tag used for the help icon. This may be
1217: used in a javascript call to switch the image src. See
1218: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1219:
1220: =cut
1221:
1222: sub help_open_topic {
1.973 raeburn 1223: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1224: $text = "" if (not defined $text);
1.44 bowersj2 1225: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1226: $width = 500 if (not defined $width);
1.44 bowersj2 1227: $height = 400 if (not defined $height);
1228: my $filename = $topic;
1229: $filename =~ s/ /_/g;
1230:
1.48 bowersj2 1231: my $template = "";
1232: my $link;
1.572 banghart 1233:
1.159 www 1234: $topic=~s/\W/\_/g;
1.44 bowersj2 1235:
1.572 banghart 1236: if (!$stayOnPage) {
1.1033 www 1237: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1238: } elsif ($stayOnPage eq 'popup') {
1239: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1240: } else {
1.48 bowersj2 1241: $link = "/adm/help/${filename}.hlp";
1242: }
1243:
1244: # Add the text
1.755 neumanie 1245: if ($text ne "") {
1.763 bisitz 1246: $template.='<span class="LC_help_open_topic">'
1247: .'<a target="_top" href="'.$link.'">'
1248: .$text.'</a>';
1.48 bowersj2 1249: }
1250:
1.763 bisitz 1251: # (Always) Add the graphic
1.179 matthew 1252: my $title = &mt('Online Help');
1.667 raeburn 1253: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1254: if ($imgid ne '') {
1255: $imgid = ' id="'.$imgid.'"';
1256: }
1.763 bisitz 1257: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1258: .'<img src="'.$helpicon.'" border="0"'
1259: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1260: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1261: .' /></a>';
1262: if ($text ne "") {
1263: $template.='</span>';
1264: }
1.44 bowersj2 1265: return $template;
1266:
1.106 bowersj2 1267: }
1268:
1269: # This is a quicky function for Latex cheatsheet editing, since it
1270: # appears in at least four places
1271: sub helpLatexCheatsheet {
1.1037 www 1272: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1273: my $out;
1.106 bowersj2 1274: my $addOther = '';
1.732 raeburn 1275: if ($topic) {
1.1037 www 1276: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1277: }
1278: $out = '<span>' # Start cheatsheet
1279: .$addOther
1280: .'<span>'
1.1037 www 1281: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1282: .'</span> <span>'
1.1037 www 1283: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1284: .'</span>';
1.732 raeburn 1285: unless ($not_author) {
1.763 bisitz 1286: $out .= ' <span>'
1.1037 www 1287: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763 bisitz 1288: .'</span>';
1.732 raeburn 1289: }
1.763 bisitz 1290: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1291: return $out;
1.172 www 1292: }
1293:
1.430 albertel 1294: sub general_help {
1295: my $helptopic='Student_Intro';
1296: if ($env{'request.role'}=~/^(ca|au)/) {
1297: $helptopic='Authoring_Intro';
1.907 raeburn 1298: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1299: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1300: } elsif ($env{'request.role'}=~/^dc/) {
1301: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1302: }
1303: return $helptopic;
1304: }
1305:
1306: sub update_help_link {
1307: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1308: my $origurl = $ENV{'REQUEST_URI'};
1309: $origurl=~s|^/~|/priv/|;
1310: my $timestamp = time;
1311: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1312: $$datum = &escape($$datum);
1313: }
1314:
1315: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1316: my $output .= <<"ENDOUTPUT";
1317: <script type="text/javascript">
1.824 bisitz 1318: // <![CDATA[
1.430 albertel 1319: banner_link = '$banner_link';
1.824 bisitz 1320: // ]]>
1.430 albertel 1321: </script>
1322: ENDOUTPUT
1323: return $output;
1324: }
1325:
1326: # now just updates the help link and generates a blue icon
1.193 raeburn 1327: sub help_open_menu {
1.430 albertel 1328: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1329: = @_;
1.949 droeschl 1330: $stayOnPage = 1;
1.430 albertel 1331: my $output;
1332: if ($component_help) {
1333: if (!$text) {
1334: $output=&help_open_topic($component_help,undef,$stayOnPage,
1335: $width,$height);
1336: } else {
1337: my $help_text;
1338: $help_text=&unescape($topic);
1339: $output='<table><tr><td>'.
1340: &help_open_topic($component_help,$help_text,$stayOnPage,
1341: $width,$height).'</td></tr></table>';
1342: }
1343: }
1344: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1345: return $output.$banner_link;
1346: }
1347:
1348: sub top_nav_help {
1349: my ($text) = @_;
1.436 albertel 1350: $text = &mt($text);
1.949 droeschl 1351: my $stay_on_page = 1;
1352:
1.572 banghart 1353: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1354: : "javascript:helpMenu('open')";
1.572 banghart 1355: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1356:
1.201 raeburn 1357: my $title = &mt('Get help');
1.436 albertel 1358:
1359: return <<"END";
1360: $banner_link
1361: <a href="$link" title="$title">$text</a>
1362: END
1363: }
1364:
1365: sub help_menu_js {
1366: my ($text) = @_;
1.949 droeschl 1367: my $stayOnPage = 1;
1.436 albertel 1368: my $width = 620;
1369: my $height = 600;
1.430 albertel 1370: my $helptopic=&general_help();
1371: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1372: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1373: my $start_page =
1374: &Apache::loncommon::start_page('Help Menu', undef,
1375: {'frameset' => 1,
1376: 'js_ready' => 1,
1377: 'add_entries' => {
1378: 'border' => '0',
1.579 raeburn 1379: 'rows' => "110,*",},});
1.331 albertel 1380: my $end_page =
1381: &Apache::loncommon::end_page({'frameset' => 1,
1382: 'js_ready' => 1,});
1383:
1.436 albertel 1384: my $template .= <<"ENDTEMPLATE";
1385: <script type="text/javascript">
1.877 bisitz 1386: // <![CDATA[
1.253 albertel 1387: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1388: var banner_link = '';
1.243 raeburn 1389: function helpMenu(target) {
1390: var caller = this;
1391: if (target == 'open') {
1392: var newWindow = null;
1393: try {
1.262 albertel 1394: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1395: }
1396: catch(error) {
1397: writeHelp(caller);
1398: return;
1399: }
1400: if (newWindow) {
1401: caller = newWindow;
1402: }
1.193 raeburn 1403: }
1.243 raeburn 1404: writeHelp(caller);
1405: return;
1406: }
1407: function writeHelp(caller) {
1.1072 raeburn 1408: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" />\\n<frame name="bodyframe" src="$details_link" />\\n$end_page')
1.243 raeburn 1409: caller.document.close()
1410: caller.focus()
1.193 raeburn 1411: }
1.877 bisitz 1412: // END LON-CAPA Internal -->
1.253 albertel 1413: // ]]>
1.436 albertel 1414: </script>
1.193 raeburn 1415: ENDTEMPLATE
1416: return $template;
1417: }
1418:
1.172 www 1419: sub help_open_bug {
1420: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1421: unless ($env{'user.adv'}) { return ''; }
1.172 www 1422: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1423: $text = "" if (not defined $text);
1424: $stayOnPage=1;
1.184 albertel 1425: $width = 600 if (not defined $width);
1426: $height = 600 if (not defined $height);
1.172 www 1427:
1428: $topic=~s/\W+/\+/g;
1429: my $link='';
1430: my $template='';
1.379 albertel 1431: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1432: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1433: if (!$stayOnPage)
1434: {
1435: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1436: }
1437: else
1438: {
1439: $link = $url;
1440: }
1441: # Add the text
1442: if ($text ne "")
1443: {
1444: $template .=
1445: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1446: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1447: }
1448:
1449: # Add the graphic
1.179 matthew 1450: my $title = &mt('Report a Bug');
1.215 albertel 1451: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1452: $template .= <<"ENDTEMPLATE";
1.436 albertel 1453: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1454: ENDTEMPLATE
1455: if ($text ne '') { $template.='</td></tr></table>' };
1456: return $template;
1457:
1458: }
1459:
1460: sub help_open_faq {
1461: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1462: unless ($env{'user.adv'}) { return ''; }
1.172 www 1463: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1464: $text = "" if (not defined $text);
1465: $stayOnPage=1;
1466: $width = 350 if (not defined $width);
1467: $height = 400 if (not defined $height);
1468:
1469: $topic=~s/\W+/\+/g;
1470: my $link='';
1471: my $template='';
1472: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1473: if (!$stayOnPage)
1474: {
1475: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1476: }
1477: else
1478: {
1479: $link = $url;
1480: }
1481:
1482: # Add the text
1483: if ($text ne "")
1484: {
1485: $template .=
1.173 www 1486: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1487: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1488: }
1489:
1490: # Add the graphic
1.179 matthew 1491: my $title = &mt('View the FAQ');
1.215 albertel 1492: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1493: $template .= <<"ENDTEMPLATE";
1.436 albertel 1494: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1495: ENDTEMPLATE
1496: if ($text ne '') { $template.='</td></tr></table>' };
1497: return $template;
1498:
1.44 bowersj2 1499: }
1.37 matthew 1500:
1.180 matthew 1501: ###############################################################
1502: ###############################################################
1503:
1.45 matthew 1504: =pod
1505:
1.648 raeburn 1506: =item * &change_content_javascript():
1.256 matthew 1507:
1508: This and the next function allow you to create small sections of an
1509: otherwise static HTML page that you can update on the fly with
1510: Javascript, even in Netscape 4.
1511:
1512: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1513: must be written to the HTML page once. It will prove the Javascript
1514: function "change(name, content)". Calling the change function with the
1515: name of the section
1516: you want to update, matching the name passed to C<changable_area>, and
1517: the new content you want to put in there, will put the content into
1518: that area.
1519:
1520: B<Note>: Netscape 4 only reserves enough space for the changable area
1521: to contain room for the original contents. You need to "make space"
1522: for whatever changes you wish to make, and be B<sure> to check your
1523: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1524: it's adequate for updating a one-line status display, but little more.
1525: This script will set the space to 100% width, so you only need to
1526: worry about height in Netscape 4.
1527:
1528: Modern browsers are much less limiting, and if you can commit to the
1529: user not using Netscape 4, this feature may be used freely with
1530: pretty much any HTML.
1531:
1532: =cut
1533:
1534: sub change_content_javascript {
1535: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1536: if ($env{'browser.type'} eq 'netscape' &&
1537: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1538: return (<<NETSCAPE4);
1539: function change(name, content) {
1540: doc = document.layers[name+"___escape"].layers[0].document;
1541: doc.open();
1542: doc.write(content);
1543: doc.close();
1544: }
1545: NETSCAPE4
1546: } else {
1547: # Otherwise, we need to use semi-standards-compliant code
1548: # (technically, "innerHTML" isn't standard but the equivalent
1549: # is really scary, and every useful browser supports it
1550: return (<<DOMBASED);
1551: function change(name, content) {
1552: element = document.getElementById(name);
1553: element.innerHTML = content;
1554: }
1555: DOMBASED
1556: }
1557: }
1558:
1559: =pod
1560:
1.648 raeburn 1561: =item * &changable_area($name,$origContent):
1.256 matthew 1562:
1563: This provides a "changable area" that can be modified on the fly via
1564: the Javascript code provided in C<change_content_javascript>. $name is
1565: the name you will use to reference the area later; do not repeat the
1566: same name on a given HTML page more then once. $origContent is what
1567: the area will originally contain, which can be left blank.
1568:
1569: =cut
1570:
1571: sub changable_area {
1572: my ($name, $origContent) = @_;
1573:
1.258 albertel 1574: if ($env{'browser.type'} eq 'netscape' &&
1575: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1576: # If this is netscape 4, we need to use the Layer tag
1577: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1578: } else {
1579: return "<span id='$name'>$origContent</span>";
1580: }
1581: }
1582:
1583: =pod
1584:
1.648 raeburn 1585: =item * &viewport_geometry_js
1.590 raeburn 1586:
1587: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1588:
1589: =cut
1590:
1591:
1592: sub viewport_geometry_js {
1593: return <<"GEOMETRY";
1594: var Geometry = {};
1595: function init_geometry() {
1596: if (Geometry.init) { return };
1597: Geometry.init=1;
1598: if (window.innerHeight) {
1599: Geometry.getViewportHeight = function() { return window.innerHeight; };
1600: Geometry.getViewportWidth = function() { return window.innerWidth; };
1601: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1602: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1603: }
1604: else if (document.documentElement && document.documentElement.clientHeight) {
1605: Geometry.getViewportHeight =
1606: function() { return document.documentElement.clientHeight; };
1607: Geometry.getViewportWidth =
1608: function() { return document.documentElement.clientWidth; };
1609:
1610: Geometry.getHorizontalScroll =
1611: function() { return document.documentElement.scrollLeft; };
1612: Geometry.getVerticalScroll =
1613: function() { return document.documentElement.scrollTop; };
1614: }
1615: else if (document.body.clientHeight) {
1616: Geometry.getViewportHeight =
1617: function() { return document.body.clientHeight; };
1618: Geometry.getViewportWidth =
1619: function() { return document.body.clientWidth; };
1620: Geometry.getHorizontalScroll =
1621: function() { return document.body.scrollLeft; };
1622: Geometry.getVerticalScroll =
1623: function() { return document.body.scrollTop; };
1624: }
1625: }
1626:
1627: GEOMETRY
1628: }
1629:
1630: =pod
1631:
1.648 raeburn 1632: =item * &viewport_size_js()
1.590 raeburn 1633:
1634: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1635:
1636: =cut
1637:
1638: sub viewport_size_js {
1639: my $geometry = &viewport_geometry_js();
1640: return <<"DIMS";
1641:
1642: $geometry
1643:
1644: function getViewportDims(width,height) {
1645: init_geometry();
1646: width.value = Geometry.getViewportWidth();
1647: height.value = Geometry.getViewportHeight();
1648: return;
1649: }
1650:
1651: DIMS
1652: }
1653:
1654: =pod
1655:
1.648 raeburn 1656: =item * &resize_textarea_js()
1.565 albertel 1657:
1658: emits the needed javascript to resize a textarea to be as big as possible
1659:
1660: creates a function resize_textrea that takes two IDs first should be
1661: the id of the element to resize, second should be the id of a div that
1662: surrounds everything that comes after the textarea, this routine needs
1663: to be attached to the <body> for the onload and onresize events.
1664:
1.648 raeburn 1665: =back
1.565 albertel 1666:
1667: =cut
1668:
1669: sub resize_textarea_js {
1.590 raeburn 1670: my $geometry = &viewport_geometry_js();
1.565 albertel 1671: return <<"RESIZE";
1672: <script type="text/javascript">
1.824 bisitz 1673: // <![CDATA[
1.590 raeburn 1674: $geometry
1.565 albertel 1675:
1.588 albertel 1676: function getX(element) {
1677: var x = 0;
1678: while (element) {
1679: x += element.offsetLeft;
1680: element = element.offsetParent;
1681: }
1682: return x;
1683: }
1684: function getY(element) {
1685: var y = 0;
1686: while (element) {
1687: y += element.offsetTop;
1688: element = element.offsetParent;
1689: }
1690: return y;
1691: }
1692:
1693:
1.565 albertel 1694: function resize_textarea(textarea_id,bottom_id) {
1695: init_geometry();
1696: var textarea = document.getElementById(textarea_id);
1697: //alert(textarea);
1698:
1.588 albertel 1699: var textarea_top = getY(textarea);
1.565 albertel 1700: var textarea_height = textarea.offsetHeight;
1701: var bottom = document.getElementById(bottom_id);
1.588 albertel 1702: var bottom_top = getY(bottom);
1.565 albertel 1703: var bottom_height = bottom.offsetHeight;
1704: var window_height = Geometry.getViewportHeight();
1.588 albertel 1705: var fudge = 23;
1.565 albertel 1706: var new_height = window_height-fudge-textarea_top-bottom_height;
1707: if (new_height < 300) {
1708: new_height = 300;
1709: }
1710: textarea.style.height=new_height+'px';
1711: }
1.824 bisitz 1712: // ]]>
1.565 albertel 1713: </script>
1714: RESIZE
1715:
1716: }
1717:
1718: =pod
1719:
1.256 matthew 1720: =head1 Excel and CSV file utility routines
1721:
1722: =over 4
1723:
1724: =cut
1725:
1726: ###############################################################
1727: ###############################################################
1728:
1729: =pod
1730:
1.648 raeburn 1731: =item * &csv_translate($text)
1.37 matthew 1732:
1.185 www 1733: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1734: format.
1735:
1736: =cut
1737:
1.180 matthew 1738: ###############################################################
1739: ###############################################################
1.37 matthew 1740: sub csv_translate {
1741: my $text = shift;
1742: $text =~ s/\"/\"\"/g;
1.209 albertel 1743: $text =~ s/\n/ /g;
1.37 matthew 1744: return $text;
1745: }
1.180 matthew 1746:
1747: ###############################################################
1748: ###############################################################
1749:
1750: =pod
1751:
1.648 raeburn 1752: =item * &define_excel_formats()
1.180 matthew 1753:
1754: Define some commonly used Excel cell formats.
1755:
1756: Currently supported formats:
1757:
1758: =over 4
1759:
1760: =item header
1761:
1762: =item bold
1763:
1764: =item h1
1765:
1766: =item h2
1767:
1768: =item h3
1769:
1.256 matthew 1770: =item h4
1771:
1772: =item i
1773:
1.180 matthew 1774: =item date
1775:
1776: =back
1777:
1778: Inputs: $workbook
1779:
1780: Returns: $format, a hash reference.
1781:
1.1057 foxr 1782:
1.180 matthew 1783: =cut
1784:
1785: ###############################################################
1786: ###############################################################
1787: sub define_excel_formats {
1788: my ($workbook) = @_;
1789: my $format;
1790: $format->{'header'} = $workbook->add_format(bold => 1,
1791: bottom => 1,
1792: align => 'center');
1793: $format->{'bold'} = $workbook->add_format(bold=>1);
1794: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1795: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1796: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1797: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1798: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1799: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1800: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1801: return $format;
1802: }
1803:
1804: ###############################################################
1805: ###############################################################
1.113 bowersj2 1806:
1807: =pod
1808:
1.648 raeburn 1809: =item * &create_workbook()
1.255 matthew 1810:
1811: Create an Excel worksheet. If it fails, output message on the
1812: request object and return undefs.
1813:
1814: Inputs: Apache request object
1815:
1816: Returns (undef) on failure,
1817: Excel worksheet object, scalar with filename, and formats
1818: from &Apache::loncommon::define_excel_formats on success
1819:
1820: =cut
1821:
1822: ###############################################################
1823: ###############################################################
1824: sub create_workbook {
1825: my ($r) = @_;
1826: #
1827: # Create the excel spreadsheet
1828: my $filename = '/prtspool/'.
1.258 albertel 1829: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1830: time.'_'.rand(1000000000).'.xls';
1831: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1832: if (! defined($workbook)) {
1833: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1834: $r->print(
1835: '<p class="LC_error">'
1836: .&mt('Problems occurred in creating the new Excel file.')
1837: .' '.&mt('This error has been logged.')
1838: .' '.&mt('Please alert your LON-CAPA administrator.')
1839: .'</p>'
1840: );
1.255 matthew 1841: return (undef);
1842: }
1843: #
1.1014 foxr 1844: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1845: #
1846: my $format = &Apache::loncommon::define_excel_formats($workbook);
1847: return ($workbook,$filename,$format);
1848: }
1849:
1850: ###############################################################
1851: ###############################################################
1852:
1853: =pod
1854:
1.648 raeburn 1855: =item * &create_text_file()
1.113 bowersj2 1856:
1.542 raeburn 1857: Create a file to write to and eventually make available to the user.
1.256 matthew 1858: If file creation fails, outputs an error message on the request object and
1859: return undefs.
1.113 bowersj2 1860:
1.256 matthew 1861: Inputs: Apache request object, and file suffix
1.113 bowersj2 1862:
1.256 matthew 1863: Returns (undef) on failure,
1864: Filehandle and filename on success.
1.113 bowersj2 1865:
1866: =cut
1867:
1.256 matthew 1868: ###############################################################
1869: ###############################################################
1870: sub create_text_file {
1871: my ($r,$suffix) = @_;
1872: if (! defined($suffix)) { $suffix = 'txt'; };
1873: my $fh;
1874: my $filename = '/prtspool/'.
1.258 albertel 1875: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1876: time.'_'.rand(1000000000).'.'.$suffix;
1877: $fh = Apache::File->new('>/home/httpd'.$filename);
1878: if (! defined($fh)) {
1879: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1880: $r->print(
1881: '<p class="LC_error">'
1882: .&mt('Problems occurred in creating the output file.')
1883: .' '.&mt('This error has been logged.')
1884: .' '.&mt('Please alert your LON-CAPA administrator.')
1885: .'</p>'
1886: );
1.113 bowersj2 1887: }
1.256 matthew 1888: return ($fh,$filename)
1.113 bowersj2 1889: }
1890:
1891:
1.256 matthew 1892: =pod
1.113 bowersj2 1893:
1894: =back
1895:
1896: =cut
1.37 matthew 1897:
1898: ###############################################################
1.33 matthew 1899: ## Home server <option> list generating code ##
1900: ###############################################################
1.35 matthew 1901:
1.169 www 1902: # ------------------------------------------
1903:
1904: sub domain_select {
1905: my ($name,$value,$multiple)=@_;
1906: my %domains=map {
1.514 albertel 1907: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1908: } &Apache::lonnet::all_domains();
1.169 www 1909: if ($multiple) {
1910: $domains{''}=&mt('Any domain');
1.550 albertel 1911: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1912: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1913: } else {
1.550 albertel 1914: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1915: return &select_form($name,$value,\%domains);
1.169 www 1916: }
1917: }
1918:
1.282 albertel 1919: #-------------------------------------------
1920:
1921: =pod
1922:
1.519 raeburn 1923: =head1 Routines for form select boxes
1924:
1925: =over 4
1926:
1.648 raeburn 1927: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1928:
1929: Returns a string containing a <select> element int multiple mode
1930:
1931:
1932: Args:
1933: $name - name of the <select> element
1.506 raeburn 1934: $value - scalar or array ref of values that should already be selected
1.282 albertel 1935: $size - number of rows long the select element is
1.283 albertel 1936: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1937: (shown text should already have been &mt())
1.506 raeburn 1938: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1939:
1.282 albertel 1940: =cut
1941:
1942: #-------------------------------------------
1.169 www 1943: sub multiple_select_form {
1.284 albertel 1944: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1945: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1946: my $output='';
1.191 matthew 1947: if (! defined($size)) {
1948: $size = 4;
1.283 albertel 1949: if (scalar(keys(%$hash))<4) {
1950: $size = scalar(keys(%$hash));
1.191 matthew 1951: }
1952: }
1.734 bisitz 1953: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1954: my @order;
1.506 raeburn 1955: if (ref($order) eq 'ARRAY') {
1956: @order = @{$order};
1957: } else {
1958: @order = sort(keys(%$hash));
1.501 banghart 1959: }
1960: if (exists($$hash{'select_form_order'})) {
1961: @order = @{$$hash{'select_form_order'}};
1962: }
1963:
1.284 albertel 1964: foreach my $key (@order) {
1.356 albertel 1965: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1966: $output.='selected="selected" ' if ($selected{$key});
1967: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1968: }
1969: $output.="</select>\n";
1970: return $output;
1971: }
1972:
1.88 www 1973: #-------------------------------------------
1974:
1975: =pod
1976:
1.970 raeburn 1977: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1978:
1979: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1980: allow a user to select options from a ref to a hash containing:
1981: option_name => displayed text. An optional $onchange can include
1982: a javascript onchange item, e.g., onchange="this.form.submit();"
1983:
1.88 www 1984: See lonrights.pm for an example invocation and use.
1985:
1986: =cut
1987:
1988: #-------------------------------------------
1989: sub select_form {
1.970 raeburn 1990: my ($def,$name,$hashref,$onchange) = @_;
1991: return unless (ref($hashref) eq 'HASH');
1992: if ($onchange) {
1993: $onchange = ' onchange="'.$onchange.'"';
1994: }
1995: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 1996: my @keys;
1.970 raeburn 1997: if (exists($hashref->{'select_form_order'})) {
1998: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 1999: } else {
1.970 raeburn 2000: @keys=sort(keys(%{$hashref}));
1.128 albertel 2001: }
1.356 albertel 2002: foreach my $key (@keys) {
2003: $selectform.=
2004: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2005: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2006: ">".$hashref->{$key}."</option>\n";
1.88 www 2007: }
2008: $selectform.="</select>";
2009: return $selectform;
2010: }
2011:
1.475 www 2012: # For display filters
2013:
2014: sub display_filter {
1.1074 raeburn 2015: my ($context) = @_;
1.475 www 2016: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2017: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2018: my $phraseinput = 'hidden';
2019: my $includeinput = 'hidden';
2020: my ($checked,$includetypestext);
2021: if ($env{'form.displayfilter'} eq 'containing') {
2022: $phraseinput = 'text';
2023: if ($context eq 'parmslog') {
2024: $includeinput = 'checkbox';
2025: if ($env{'form.includetypes'}) {
2026: $checked = ' checked="checked"';
2027: }
2028: $includetypestext = &mt('Include parameter types');
2029: }
2030: } else {
2031: $includetypestext = ' ';
2032: }
2033: my ($additional,$secondid,$thirdid);
2034: if ($context eq 'parmslog') {
2035: $additional =
2036: '<label><input type="'.$includeinput.'" name="includetypes"'.
2037: $checked.' name="includetypes" value="1" id="includetypes" />'.
2038: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2039: '</label>';
2040: $secondid = 'includetypes';
2041: $thirdid = 'includetypestext';
2042: }
2043: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2044: '$secondid','$thirdid')";
2045: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2046: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2047: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2048: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2049: &mt('Filter: [_1]',
1.477 www 2050: &select_form($env{'form.displayfilter'},
2051: 'displayfilter',
1.970 raeburn 2052: {'currentfolder' => 'Current folder/page',
1.477 www 2053: 'containing' => 'Containing phrase',
1.1074 raeburn 2054: 'none' => 'None'},$onchange)).' '.
2055: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2056: &HTML::Entities::encode($env{'form.containingphrase'}).
2057: '" />'.$additional;
2058: }
2059:
2060: sub display_filter_js {
2061: my $includetext = &mt('Include parameter types');
2062: return <<"ENDJS";
2063:
2064: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2065: var firstType = 'hidden';
2066: if (setter.options[setter.selectedIndex].value == 'containing') {
2067: firstType = 'text';
2068: }
2069: firstObject = document.getElementById(firstid);
2070: if (typeof(firstObject) == 'object') {
2071: if (firstObject.type != firstType) {
2072: changeInputType(firstObject,firstType);
2073: }
2074: }
2075: if (context == 'parmslog') {
2076: var secondType = 'hidden';
2077: if (firstType == 'text') {
2078: secondType = 'checkbox';
2079: }
2080: secondObject = document.getElementById(secondid);
2081: if (typeof(secondObject) == 'object') {
2082: if (secondObject.type != secondType) {
2083: changeInputType(secondObject,secondType);
2084: }
2085: }
2086: var textItem = document.getElementById(thirdid);
2087: var currtext = textItem.innerHTML;
2088: var newtext;
2089: if (firstType == 'text') {
2090: newtext = '$includetext';
2091: } else {
2092: newtext = ' ';
2093: }
2094: if (currtext != newtext) {
2095: textItem.innerHTML = newtext;
2096: }
2097: }
2098: return;
2099: }
2100:
2101: function changeInputType(oldObject,newType) {
2102: var newObject = document.createElement('input');
2103: newObject.type = newType;
2104: if (oldObject.size) {
2105: newObject.size = oldObject.size;
2106: }
2107: if (oldObject.value) {
2108: newObject.value = oldObject.value;
2109: }
2110: if (oldObject.name) {
2111: newObject.name = oldObject.name;
2112: }
2113: if (oldObject.id) {
2114: newObject.id = oldObject.id;
2115: }
2116: oldObject.parentNode.replaceChild(newObject,oldObject);
2117: return;
2118: }
2119:
2120: ENDJS
1.475 www 2121: }
2122:
1.167 www 2123: sub gradeleveldescription {
2124: my $gradelevel=shift;
2125: my %gradelevels=(0 => 'Not specified',
2126: 1 => 'Grade 1',
2127: 2 => 'Grade 2',
2128: 3 => 'Grade 3',
2129: 4 => 'Grade 4',
2130: 5 => 'Grade 5',
2131: 6 => 'Grade 6',
2132: 7 => 'Grade 7',
2133: 8 => 'Grade 8',
2134: 9 => 'Grade 9',
2135: 10 => 'Grade 10',
2136: 11 => 'Grade 11',
2137: 12 => 'Grade 12',
2138: 13 => 'Grade 13',
2139: 14 => '100 Level',
2140: 15 => '200 Level',
2141: 16 => '300 Level',
2142: 17 => '400 Level',
2143: 18 => 'Graduate Level');
2144: return &mt($gradelevels{$gradelevel});
2145: }
2146:
1.163 www 2147: sub select_level_form {
2148: my ($deflevel,$name)=@_;
2149: unless ($deflevel) { $deflevel=0; }
1.167 www 2150: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2151: for (my $i=0; $i<=18; $i++) {
2152: $selectform.="<option value=\"$i\" ".
1.253 albertel 2153: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2154: ">".&gradeleveldescription($i)."</option>\n";
2155: }
2156: $selectform.="</select>";
2157: return $selectform;
1.163 www 2158: }
1.167 www 2159:
1.35 matthew 2160: #-------------------------------------------
2161:
1.45 matthew 2162: =pod
2163:
1.910 raeburn 2164: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 2165:
2166: Returns a string containing a <select name='$name' size='1'> form to
2167: allow a user to select the domain to preform an operation in.
2168: See loncreateuser.pm for an example invocation and use.
2169:
1.90 www 2170: If the $includeempty flag is set, it also includes an empty choice ("no domain
2171: selected");
2172:
1.743 raeburn 2173: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2174:
1.910 raeburn 2175: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
2176:
2177: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 2178:
1.35 matthew 2179: =cut
2180:
2181: #-------------------------------------------
1.34 matthew 2182: sub select_dom_form {
1.910 raeburn 2183: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 2184: if ($onchange) {
1.874 raeburn 2185: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2186: }
1.910 raeburn 2187: my @domains;
2188: if (ref($incdoms) eq 'ARRAY') {
2189: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2190: } else {
2191: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2192: }
1.90 www 2193: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 2194: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2195: foreach my $dom (@domains) {
2196: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2197: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2198: if ($showdomdesc) {
2199: if ($dom ne '') {
2200: my $domdesc = &Apache::lonnet::domain($dom,'description');
2201: if ($domdesc ne '') {
2202: $selectdomain .= ' ('.$domdesc.')';
2203: }
2204: }
2205: }
2206: $selectdomain .= "</option>\n";
1.34 matthew 2207: }
2208: $selectdomain.="</select>";
2209: return $selectdomain;
2210: }
2211:
1.35 matthew 2212: #-------------------------------------------
2213:
1.45 matthew 2214: =pod
2215:
1.648 raeburn 2216: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2217:
1.586 raeburn 2218: input: 4 arguments (two required, two optional) -
2219: $domain - domain of new user
2220: $name - name of form element
2221: $default - Value of 'default' causes a default item to be first
2222: option, and selected by default.
2223: $hide - Value of 'hide' causes hiding of the name of the server,
2224: if 1 server found, or default, if 0 found.
1.594 raeburn 2225: output: returns 2 items:
1.586 raeburn 2226: (a) form element which contains either:
2227: (i) <select name="$name">
2228: <option value="$hostid1">$hostid $servers{$hostid}</option>
2229: <option value="$hostid2">$hostid $servers{$hostid}</option>
2230: </select>
2231: form item if there are multiple library servers in $domain, or
2232: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2233: if there is only one library server in $domain.
2234:
2235: (b) number of library servers found.
2236:
2237: See loncreateuser.pm for example of use.
1.35 matthew 2238:
2239: =cut
2240:
2241: #-------------------------------------------
1.586 raeburn 2242: sub home_server_form_item {
2243: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2244: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2245: my $result;
2246: my $numlib = keys(%servers);
2247: if ($numlib > 1) {
2248: $result .= '<select name="'.$name.'" />'."\n";
2249: if ($default) {
1.804 bisitz 2250: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2251: '</option>'."\n";
2252: }
2253: foreach my $hostid (sort(keys(%servers))) {
2254: $result.= '<option value="'.$hostid.'">'.
2255: $hostid.' '.$servers{$hostid}."</option>\n";
2256: }
2257: $result .= '</select>'."\n";
2258: } elsif ($numlib == 1) {
2259: my $hostid;
2260: foreach my $item (keys(%servers)) {
2261: $hostid = $item;
2262: }
2263: $result .= '<input type="hidden" name="'.$name.'" value="'.
2264: $hostid.'" />';
2265: if (!$hide) {
2266: $result .= $hostid.' '.$servers{$hostid};
2267: }
2268: $result .= "\n";
2269: } elsif ($default) {
2270: $result .= '<input type="hidden" name="'.$name.
2271: '" value="default" />';
2272: if (!$hide) {
2273: $result .= &mt('default');
2274: }
2275: $result .= "\n";
1.33 matthew 2276: }
1.586 raeburn 2277: return ($result,$numlib);
1.33 matthew 2278: }
1.112 bowersj2 2279:
2280: =pod
2281:
1.534 albertel 2282: =back
2283:
1.112 bowersj2 2284: =cut
1.87 matthew 2285:
2286: ###############################################################
1.112 bowersj2 2287: ## Decoding User Agent ##
1.87 matthew 2288: ###############################################################
2289:
2290: =pod
2291:
1.112 bowersj2 2292: =head1 Decoding the User Agent
2293:
2294: =over 4
2295:
2296: =item * &decode_user_agent()
1.87 matthew 2297:
2298: Inputs: $r
2299:
2300: Outputs:
2301:
2302: =over 4
2303:
1.112 bowersj2 2304: =item * $httpbrowser
1.87 matthew 2305:
1.112 bowersj2 2306: =item * $clientbrowser
1.87 matthew 2307:
1.112 bowersj2 2308: =item * $clientversion
1.87 matthew 2309:
1.112 bowersj2 2310: =item * $clientmathml
1.87 matthew 2311:
1.112 bowersj2 2312: =item * $clientunicode
1.87 matthew 2313:
1.112 bowersj2 2314: =item * $clientos
1.87 matthew 2315:
2316: =back
2317:
1.157 matthew 2318: =back
2319:
1.87 matthew 2320: =cut
2321:
2322: ###############################################################
2323: ###############################################################
2324: sub decode_user_agent {
1.247 albertel 2325: my ($r)=@_;
1.87 matthew 2326: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2327: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2328: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2329: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2330: my $clientbrowser='unknown';
2331: my $clientversion='0';
2332: my $clientmathml='';
2333: my $clientunicode='0';
2334: for (my $i=0;$i<=$#browsertype;$i++) {
2335: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2336: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2337: $clientbrowser=$bname;
2338: $httpbrowser=~/$vreg/i;
2339: $clientversion=$1;
2340: $clientmathml=($clientversion>=$minv);
2341: $clientunicode=($clientversion>=$univ);
2342: }
2343: }
2344: my $clientos='unknown';
2345: if (($httpbrowser=~/linux/i) ||
2346: ($httpbrowser=~/unix/i) ||
2347: ($httpbrowser=~/ux/i) ||
2348: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2349: if (($httpbrowser=~/vax/i) ||
2350: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2351: if ($httpbrowser=~/next/i) { $clientos='next'; }
2352: if (($httpbrowser=~/mac/i) ||
2353: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2354: if ($httpbrowser=~/win/i) { $clientos='win'; }
2355: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2356: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2357: $clientunicode,$clientos,);
2358: }
2359:
1.32 matthew 2360: ###############################################################
2361: ## Authentication changing form generation subroutines ##
2362: ###############################################################
2363: ##
2364: ## All of the authform_xxxxxxx subroutines take their inputs in a
2365: ## hash, and have reasonable default values.
2366: ##
2367: ## formname = the name given in the <form> tag.
1.35 matthew 2368: #-------------------------------------------
2369:
1.45 matthew 2370: =pod
2371:
1.112 bowersj2 2372: =head1 Authentication Routines
2373:
2374: =over 4
2375:
1.648 raeburn 2376: =item * &authform_xxxxxx()
1.35 matthew 2377:
2378: The authform_xxxxxx subroutines provide javascript and html forms which
2379: handle some of the conveniences required for authentication forms.
2380: This is not an optimal method, but it works.
2381:
2382: =over 4
2383:
1.112 bowersj2 2384: =item * authform_header
1.35 matthew 2385:
1.112 bowersj2 2386: =item * authform_authorwarning
1.35 matthew 2387:
1.112 bowersj2 2388: =item * authform_nochange
1.35 matthew 2389:
1.112 bowersj2 2390: =item * authform_kerberos
1.35 matthew 2391:
1.112 bowersj2 2392: =item * authform_internal
1.35 matthew 2393:
1.112 bowersj2 2394: =item * authform_filesystem
1.35 matthew 2395:
2396: =back
2397:
1.648 raeburn 2398: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2399:
1.35 matthew 2400: =cut
2401:
2402: #-------------------------------------------
1.32 matthew 2403: sub authform_header{
2404: my %in = (
2405: formname => 'cu',
1.80 albertel 2406: kerb_def_dom => '',
1.32 matthew 2407: @_,
2408: );
2409: $in{'formname'} = 'document.' . $in{'formname'};
2410: my $result='';
1.80 albertel 2411:
2412: #---------------------------------------------- Code for upper case translation
2413: my $Javascript_toUpperCase;
2414: unless ($in{kerb_def_dom}) {
2415: $Javascript_toUpperCase =<<"END";
2416: switch (choice) {
2417: case 'krb': currentform.elements[choicearg].value =
2418: currentform.elements[choicearg].value.toUpperCase();
2419: break;
2420: default:
2421: }
2422: END
2423: } else {
2424: $Javascript_toUpperCase = "";
2425: }
2426:
1.165 raeburn 2427: my $radioval = "'nochange'";
1.591 raeburn 2428: if (defined($in{'curr_authtype'})) {
2429: if ($in{'curr_authtype'} ne '') {
2430: $radioval = "'".$in{'curr_authtype'}."arg'";
2431: }
1.174 matthew 2432: }
1.165 raeburn 2433: my $argfield = 'null';
1.591 raeburn 2434: if (defined($in{'mode'})) {
1.165 raeburn 2435: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2436: if (defined($in{'curr_autharg'})) {
2437: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2438: $argfield = "'$in{'curr_autharg'}'";
2439: }
2440: }
2441: }
2442: }
2443:
1.32 matthew 2444: $result.=<<"END";
2445: var current = new Object();
1.165 raeburn 2446: current.radiovalue = $radioval;
2447: current.argfield = $argfield;
1.32 matthew 2448:
2449: function changed_radio(choice,currentform) {
2450: var choicearg = choice + 'arg';
2451: // If a radio button in changed, we need to change the argfield
2452: if (current.radiovalue != choice) {
2453: current.radiovalue = choice;
2454: if (current.argfield != null) {
2455: currentform.elements[current.argfield].value = '';
2456: }
2457: if (choice == 'nochange') {
2458: current.argfield = null;
2459: } else {
2460: current.argfield = choicearg;
2461: switch(choice) {
2462: case 'krb':
2463: currentform.elements[current.argfield].value =
2464: "$in{'kerb_def_dom'}";
2465: break;
2466: default:
2467: break;
2468: }
2469: }
2470: }
2471: return;
2472: }
1.22 www 2473:
1.32 matthew 2474: function changed_text(choice,currentform) {
2475: var choicearg = choice + 'arg';
2476: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2477: $Javascript_toUpperCase
1.32 matthew 2478: // clear old field
2479: if ((current.argfield != choicearg) && (current.argfield != null)) {
2480: currentform.elements[current.argfield].value = '';
2481: }
2482: current.argfield = choicearg;
2483: }
2484: set_auth_radio_buttons(choice,currentform);
2485: return;
1.20 www 2486: }
1.32 matthew 2487:
2488: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2489: var numauthchoices = currentform.login.length;
2490: if (typeof numauthchoices == "undefined") {
2491: return;
2492: }
1.32 matthew 2493: var i=0;
1.986 raeburn 2494: while (i < numauthchoices) {
1.32 matthew 2495: if (currentform.login[i].value == newvalue) { break; }
2496: i++;
2497: }
1.986 raeburn 2498: if (i == numauthchoices) {
1.32 matthew 2499: return;
2500: }
2501: current.radiovalue = newvalue;
2502: currentform.login[i].checked = true;
2503: return;
2504: }
2505: END
2506: return $result;
2507: }
2508:
1.1075.2.20 raeburn 2509: sub authform_authorwarning {
1.32 matthew 2510: my $result='';
1.144 matthew 2511: $result='<i>'.
2512: &mt('As a general rule, only authors or co-authors should be '.
2513: 'filesystem authenticated '.
2514: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2515: return $result;
2516: }
2517:
1.1075.2.20 raeburn 2518: sub authform_nochange {
1.32 matthew 2519: my %in = (
2520: formname => 'document.cu',
2521: kerb_def_dom => 'MSU.EDU',
2522: @_,
2523: );
1.1075.2.20 raeburn 2524: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2525: my $result;
1.1075.2.20 raeburn 2526: if (!$authnum) {
2527: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2528: } else {
2529: $result = '<label>'.&mt('[_1] Do not change login data',
2530: '<input type="radio" name="login" value="nochange" '.
2531: 'checked="checked" onclick="'.
1.281 albertel 2532: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2533: '</label>';
1.586 raeburn 2534: }
1.32 matthew 2535: return $result;
2536: }
2537:
1.591 raeburn 2538: sub authform_kerberos {
1.32 matthew 2539: my %in = (
2540: formname => 'document.cu',
2541: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2542: kerb_def_auth => 'krb4',
1.32 matthew 2543: @_,
2544: );
1.586 raeburn 2545: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2546: $autharg,$jscall);
1.1075.2.20 raeburn 2547: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2548: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2549: $check5 = ' checked="checked"';
1.80 albertel 2550: } else {
1.772 bisitz 2551: $check4 = ' checked="checked"';
1.80 albertel 2552: }
1.165 raeburn 2553: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2554: if (defined($in{'curr_authtype'})) {
2555: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2556: $krbcheck = ' checked="checked"';
1.623 raeburn 2557: if (defined($in{'mode'})) {
2558: if ($in{'mode'} eq 'modifyuser') {
2559: $krbcheck = '';
2560: }
2561: }
1.591 raeburn 2562: if (defined($in{'curr_kerb_ver'})) {
2563: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2564: $check5 = ' checked="checked"';
1.591 raeburn 2565: $check4 = '';
2566: } else {
1.772 bisitz 2567: $check4 = ' checked="checked"';
1.591 raeburn 2568: $check5 = '';
2569: }
1.586 raeburn 2570: }
1.591 raeburn 2571: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2572: $krbarg = $in{'curr_autharg'};
2573: }
1.586 raeburn 2574: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2575: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2576: $result =
2577: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2578: $in{'curr_autharg'},$krbver);
2579: } else {
2580: $result =
2581: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2582: }
2583: return $result;
2584: }
2585: }
2586: } else {
2587: if ($authnum == 1) {
1.784 bisitz 2588: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2589: }
2590: }
1.586 raeburn 2591: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2592: return;
1.587 raeburn 2593: } elsif ($authtype eq '') {
1.591 raeburn 2594: if (defined($in{'mode'})) {
1.587 raeburn 2595: if ($in{'mode'} eq 'modifycourse') {
2596: if ($authnum == 1) {
1.1075.2.20 raeburn 2597: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2598: }
2599: }
2600: }
1.586 raeburn 2601: }
2602: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2603: if ($authtype eq '') {
2604: $authtype = '<input type="radio" name="login" value="krb" '.
2605: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2606: $krbcheck.' />';
2607: }
2608: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2609: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2610: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2611: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2612: $in{'curr_authtype'} eq 'krb4')) {
2613: $result .= &mt
1.144 matthew 2614: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2615: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2616: '<label>'.$authtype,
1.281 albertel 2617: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2618: 'value="'.$krbarg.'" '.
1.144 matthew 2619: 'onchange="'.$jscall.'" />',
1.281 albertel 2620: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2621: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2622: '</label>');
1.586 raeburn 2623: } elsif ($can_assign{'krb4'}) {
2624: $result .= &mt
2625: ('[_1] Kerberos authenticated with domain [_2] '.
2626: '[_3] Version 4 [_4]',
2627: '<label>'.$authtype,
2628: '</label><input type="text" size="10" name="krbarg" '.
2629: 'value="'.$krbarg.'" '.
2630: 'onchange="'.$jscall.'" />',
2631: '<label><input type="hidden" name="krbver" value="4" />',
2632: '</label>');
2633: } elsif ($can_assign{'krb5'}) {
2634: $result .= &mt
2635: ('[_1] Kerberos authenticated with domain [_2] '.
2636: '[_3] Version 5 [_4]',
2637: '<label>'.$authtype,
2638: '</label><input type="text" size="10" name="krbarg" '.
2639: 'value="'.$krbarg.'" '.
2640: 'onchange="'.$jscall.'" />',
2641: '<label><input type="hidden" name="krbver" value="5" />',
2642: '</label>');
2643: }
1.32 matthew 2644: return $result;
2645: }
2646:
1.1075.2.20 raeburn 2647: sub authform_internal {
1.586 raeburn 2648: my %in = (
1.32 matthew 2649: formname => 'document.cu',
2650: kerb_def_dom => 'MSU.EDU',
2651: @_,
2652: );
1.586 raeburn 2653: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2654: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2655: if (defined($in{'curr_authtype'})) {
2656: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2657: if ($can_assign{'int'}) {
1.772 bisitz 2658: $intcheck = 'checked="checked" ';
1.623 raeburn 2659: if (defined($in{'mode'})) {
2660: if ($in{'mode'} eq 'modifyuser') {
2661: $intcheck = '';
2662: }
2663: }
1.591 raeburn 2664: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2665: $intarg = $in{'curr_autharg'};
2666: }
2667: } else {
2668: $result = &mt('Currently internally authenticated.');
2669: return $result;
1.165 raeburn 2670: }
2671: }
1.586 raeburn 2672: } else {
2673: if ($authnum == 1) {
1.784 bisitz 2674: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2675: }
2676: }
2677: if (!$can_assign{'int'}) {
2678: return;
1.587 raeburn 2679: } elsif ($authtype eq '') {
1.591 raeburn 2680: if (defined($in{'mode'})) {
1.587 raeburn 2681: if ($in{'mode'} eq 'modifycourse') {
2682: if ($authnum == 1) {
1.1075.2.20 raeburn 2683: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2684: }
2685: }
2686: }
1.165 raeburn 2687: }
1.586 raeburn 2688: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2689: if ($authtype eq '') {
2690: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2691: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2692: }
1.605 bisitz 2693: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2694: $intarg.'" onchange="'.$jscall.'" />';
2695: $result = &mt
1.144 matthew 2696: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2697: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2698: $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 2699: return $result;
2700: }
2701:
1.1075.2.20 raeburn 2702: sub authform_local {
1.32 matthew 2703: my %in = (
2704: formname => 'document.cu',
2705: kerb_def_dom => 'MSU.EDU',
2706: @_,
2707: );
1.586 raeburn 2708: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2709: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2710: if (defined($in{'curr_authtype'})) {
2711: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2712: if ($can_assign{'loc'}) {
1.772 bisitz 2713: $loccheck = 'checked="checked" ';
1.623 raeburn 2714: if (defined($in{'mode'})) {
2715: if ($in{'mode'} eq 'modifyuser') {
2716: $loccheck = '';
2717: }
2718: }
1.591 raeburn 2719: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2720: $locarg = $in{'curr_autharg'};
2721: }
2722: } else {
2723: $result = &mt('Currently using local (institutional) authentication.');
2724: return $result;
1.165 raeburn 2725: }
2726: }
1.586 raeburn 2727: } else {
2728: if ($authnum == 1) {
1.784 bisitz 2729: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2730: }
2731: }
2732: if (!$can_assign{'loc'}) {
2733: return;
1.587 raeburn 2734: } elsif ($authtype eq '') {
1.591 raeburn 2735: if (defined($in{'mode'})) {
1.587 raeburn 2736: if ($in{'mode'} eq 'modifycourse') {
2737: if ($authnum == 1) {
1.1075.2.20 raeburn 2738: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2739: }
2740: }
2741: }
1.165 raeburn 2742: }
1.586 raeburn 2743: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2744: if ($authtype eq '') {
2745: $authtype = '<input type="radio" name="login" value="loc" '.
2746: $loccheck.' onchange="'.$jscall.'" onclick="'.
2747: $jscall.'" />';
2748: }
2749: $autharg = '<input type="text" size="10" name="locarg" value="'.
2750: $locarg.'" onchange="'.$jscall.'" />';
2751: $result = &mt('[_1] Local Authentication with argument [_2]',
2752: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2753: return $result;
2754: }
2755:
1.1075.2.20 raeburn 2756: sub authform_filesystem {
1.32 matthew 2757: my %in = (
2758: formname => 'document.cu',
2759: kerb_def_dom => 'MSU.EDU',
2760: @_,
2761: );
1.586 raeburn 2762: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2763: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2764: if (defined($in{'curr_authtype'})) {
2765: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2766: if ($can_assign{'fsys'}) {
1.772 bisitz 2767: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2768: if (defined($in{'mode'})) {
2769: if ($in{'mode'} eq 'modifyuser') {
2770: $fsyscheck = '';
2771: }
2772: }
1.586 raeburn 2773: } else {
2774: $result = &mt('Currently Filesystem Authenticated.');
2775: return $result;
2776: }
2777: }
2778: } else {
2779: if ($authnum == 1) {
1.784 bisitz 2780: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2781: }
2782: }
2783: if (!$can_assign{'fsys'}) {
2784: return;
1.587 raeburn 2785: } elsif ($authtype eq '') {
1.591 raeburn 2786: if (defined($in{'mode'})) {
1.587 raeburn 2787: if ($in{'mode'} eq 'modifycourse') {
2788: if ($authnum == 1) {
1.1075.2.20 raeburn 2789: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2790: }
2791: }
2792: }
1.586 raeburn 2793: }
2794: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2795: if ($authtype eq '') {
2796: $authtype = '<input type="radio" name="login" value="fsys" '.
2797: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2798: $jscall.'" />';
2799: }
2800: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2801: ' onchange="'.$jscall.'" />';
2802: $result = &mt
1.144 matthew 2803: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2804: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2805: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2806: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2807: 'onchange="'.$jscall.'" />');
1.32 matthew 2808: return $result;
2809: }
2810:
1.586 raeburn 2811: sub get_assignable_auth {
2812: my ($dom) = @_;
2813: if ($dom eq '') {
2814: $dom = $env{'request.role.domain'};
2815: }
2816: my %can_assign = (
2817: krb4 => 1,
2818: krb5 => 1,
2819: int => 1,
2820: loc => 1,
2821: );
2822: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2823: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2824: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2825: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2826: my $context;
2827: if ($env{'request.role'} =~ /^au/) {
2828: $context = 'author';
2829: } elsif ($env{'request.role'} =~ /^dc/) {
2830: $context = 'domain';
2831: } elsif ($env{'request.course.id'}) {
2832: $context = 'course';
2833: }
2834: if ($context) {
2835: if (ref($authhash->{$context}) eq 'HASH') {
2836: %can_assign = %{$authhash->{$context}};
2837: }
2838: }
2839: }
2840: }
2841: my $authnum = 0;
2842: foreach my $key (keys(%can_assign)) {
2843: if ($can_assign{$key}) {
2844: $authnum ++;
2845: }
2846: }
2847: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2848: $authnum --;
2849: }
2850: return ($authnum,%can_assign);
2851: }
2852:
1.80 albertel 2853: ###############################################################
2854: ## Get Kerberos Defaults for Domain ##
2855: ###############################################################
2856: ##
2857: ## Returns default kerberos version and an associated argument
2858: ## as listed in file domain.tab. If not listed, provides
2859: ## appropriate default domain and kerberos version.
2860: ##
2861: #-------------------------------------------
2862:
2863: =pod
2864:
1.648 raeburn 2865: =item * &get_kerberos_defaults()
1.80 albertel 2866:
2867: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2868: version and domain. If not found, it defaults to version 4 and the
2869: domain of the server.
1.80 albertel 2870:
1.648 raeburn 2871: =over 4
2872:
1.80 albertel 2873: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2874:
1.648 raeburn 2875: =back
2876:
2877: =back
2878:
1.80 albertel 2879: =cut
2880:
2881: #-------------------------------------------
2882: sub get_kerberos_defaults {
2883: my $domain=shift;
1.641 raeburn 2884: my ($krbdef,$krbdefdom);
2885: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2886: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2887: $krbdef = $domdefaults{'auth_def'};
2888: $krbdefdom = $domdefaults{'auth_arg_def'};
2889: } else {
1.80 albertel 2890: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2891: my $krbdefdom=$1;
2892: $krbdefdom=~tr/a-z/A-Z/;
2893: $krbdef = "krb4";
2894: }
2895: return ($krbdef,$krbdefdom);
2896: }
1.112 bowersj2 2897:
1.32 matthew 2898:
1.46 matthew 2899: ###############################################################
2900: ## Thesaurus Functions ##
2901: ###############################################################
1.20 www 2902:
1.46 matthew 2903: =pod
1.20 www 2904:
1.112 bowersj2 2905: =head1 Thesaurus Functions
2906:
2907: =over 4
2908:
1.648 raeburn 2909: =item * &initialize_keywords()
1.46 matthew 2910:
2911: Initializes the package variable %Keywords if it is empty. Uses the
2912: package variable $thesaurus_db_file.
2913:
2914: =cut
2915:
2916: ###################################################
2917:
2918: sub initialize_keywords {
2919: return 1 if (scalar keys(%Keywords));
2920: # If we are here, %Keywords is empty, so fill it up
2921: # Make sure the file we need exists...
2922: if (! -e $thesaurus_db_file) {
2923: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2924: " failed because it does not exist");
2925: return 0;
2926: }
2927: # Set up the hash as a database
2928: my %thesaurus_db;
2929: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2930: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2931: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2932: $thesaurus_db_file);
2933: return 0;
2934: }
2935: # Get the average number of appearances of a word.
2936: my $avecount = $thesaurus_db{'average.count'};
2937: # Put keywords (those that appear > average) into %Keywords
2938: while (my ($word,$data)=each (%thesaurus_db)) {
2939: my ($count,undef) = split /:/,$data;
2940: $Keywords{$word}++ if ($count > $avecount);
2941: }
2942: untie %thesaurus_db;
2943: # Remove special values from %Keywords.
1.356 albertel 2944: foreach my $value ('total.count','average.count') {
2945: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2946: }
1.46 matthew 2947: return 1;
2948: }
2949:
2950: ###################################################
2951:
2952: =pod
2953:
1.648 raeburn 2954: =item * &keyword($word)
1.46 matthew 2955:
2956: Returns true if $word is a keyword. A keyword is a word that appears more
2957: than the average number of times in the thesaurus database. Calls
2958: &initialize_keywords
2959:
2960: =cut
2961:
2962: ###################################################
1.20 www 2963:
2964: sub keyword {
1.46 matthew 2965: return if (!&initialize_keywords());
2966: my $word=lc(shift());
2967: $word=~s/\W//g;
2968: return exists($Keywords{$word});
1.20 www 2969: }
1.46 matthew 2970:
2971: ###############################################################
2972:
2973: =pod
1.20 www 2974:
1.648 raeburn 2975: =item * &get_related_words()
1.46 matthew 2976:
1.160 matthew 2977: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2978: an array of words. If the keyword is not in the thesaurus, an empty array
2979: will be returned. The order of the words returned is determined by the
2980: database which holds them.
2981:
2982: Uses global $thesaurus_db_file.
2983:
1.1057 foxr 2984:
1.46 matthew 2985: =cut
2986:
2987: ###############################################################
2988: sub get_related_words {
2989: my $keyword = shift;
2990: my %thesaurus_db;
2991: if (! -e $thesaurus_db_file) {
2992: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2993: "failed because the file does not exist");
2994: return ();
2995: }
2996: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2997: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2998: return ();
2999: }
3000: my @Words=();
1.429 www 3001: my $count=0;
1.46 matthew 3002: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3003: # The first element is the number of times
3004: # the word appears. We do not need it now.
1.429 www 3005: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3006: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3007: my $threshold=$mostfrequentcount/10;
3008: foreach my $possibleword (@RelatedWords) {
3009: my ($word,$wordcount)=split(/\,/,$possibleword);
3010: if ($wordcount>$threshold) {
3011: push(@Words,$word);
3012: $count++;
3013: if ($count>10) { last; }
3014: }
1.20 www 3015: }
3016: }
1.46 matthew 3017: untie %thesaurus_db;
3018: return @Words;
1.14 harris41 3019: }
1.46 matthew 3020:
1.112 bowersj2 3021: =pod
3022:
3023: =back
3024:
3025: =cut
1.61 www 3026:
3027: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3028: =pod
3029:
1.112 bowersj2 3030: =head1 User Name Functions
3031:
3032: =over 4
3033:
1.648 raeburn 3034: =item * &plainname($uname,$udom,$first)
1.81 albertel 3035:
1.112 bowersj2 3036: Takes a users logon name and returns it as a string in
1.226 albertel 3037: "first middle last generation" form
3038: if $first is set to 'lastname' then it returns it as
3039: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3040:
3041: =cut
1.61 www 3042:
1.295 www 3043:
1.81 albertel 3044: ###############################################################
1.61 www 3045: sub plainname {
1.226 albertel 3046: my ($uname,$udom,$first)=@_;
1.537 albertel 3047: return if (!defined($uname) || !defined($udom));
1.295 www 3048: my %names=&getnames($uname,$udom);
1.226 albertel 3049: my $name=&Apache::lonnet::format_name($names{'firstname'},
3050: $names{'middlename'},
3051: $names{'lastname'},
3052: $names{'generation'},$first);
3053: $name=~s/^\s+//;
1.62 www 3054: $name=~s/\s+$//;
3055: $name=~s/\s+/ /g;
1.353 albertel 3056: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3057: return $name;
1.61 www 3058: }
1.66 www 3059:
3060: # -------------------------------------------------------------------- Nickname
1.81 albertel 3061: =pod
3062:
1.648 raeburn 3063: =item * &nickname($uname,$udom)
1.81 albertel 3064:
3065: Gets a users name and returns it as a string as
3066:
3067: ""nickname""
1.66 www 3068:
1.81 albertel 3069: if the user has a nickname or
3070:
3071: "first middle last generation"
3072:
3073: if the user does not
3074:
3075: =cut
1.66 www 3076:
3077: sub nickname {
3078: my ($uname,$udom)=@_;
1.537 albertel 3079: return if (!defined($uname) || !defined($udom));
1.295 www 3080: my %names=&getnames($uname,$udom);
1.68 albertel 3081: my $name=$names{'nickname'};
1.66 www 3082: if ($name) {
3083: $name='"'.$name.'"';
3084: } else {
3085: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3086: $names{'lastname'}.' '.$names{'generation'};
3087: $name=~s/\s+$//;
3088: $name=~s/\s+/ /g;
3089: }
3090: return $name;
3091: }
3092:
1.295 www 3093: sub getnames {
3094: my ($uname,$udom)=@_;
1.537 albertel 3095: return if (!defined($uname) || !defined($udom));
1.433 albertel 3096: if ($udom eq 'public' && $uname eq 'public') {
3097: return ('lastname' => &mt('Public'));
3098: }
1.295 www 3099: my $id=$uname.':'.$udom;
3100: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3101: if ($cached) {
3102: return %{$names};
3103: } else {
3104: my %loadnames=&Apache::lonnet::get('environment',
3105: ['firstname','middlename','lastname','generation','nickname'],
3106: $udom,$uname);
3107: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3108: return %loadnames;
3109: }
3110: }
1.61 www 3111:
1.542 raeburn 3112: # -------------------------------------------------------------------- getemails
1.648 raeburn 3113:
1.542 raeburn 3114: =pod
3115:
1.648 raeburn 3116: =item * &getemails($uname,$udom)
1.542 raeburn 3117:
3118: Gets a user's email information and returns it as a hash with keys:
3119: notification, critnotification, permanentemail
3120:
3121: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3122: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3123:
1.648 raeburn 3124:
1.542 raeburn 3125: =cut
3126:
1.648 raeburn 3127:
1.466 albertel 3128: sub getemails {
3129: my ($uname,$udom)=@_;
3130: if ($udom eq 'public' && $uname eq 'public') {
3131: return;
3132: }
1.467 www 3133: if (!$udom) { $udom=$env{'user.domain'}; }
3134: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3135: my $id=$uname.':'.$udom;
3136: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3137: if ($cached) {
3138: return %{$names};
3139: } else {
3140: my %loadnames=&Apache::lonnet::get('environment',
3141: ['notification','critnotification',
3142: 'permanentemail'],
3143: $udom,$uname);
3144: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3145: return %loadnames;
3146: }
3147: }
3148:
1.551 albertel 3149: sub flush_email_cache {
3150: my ($uname,$udom)=@_;
3151: if (!$udom) { $udom =$env{'user.domain'}; }
3152: if (!$uname) { $uname=$env{'user.name'}; }
3153: return if ($udom eq 'public' && $uname eq 'public');
3154: my $id=$uname.':'.$udom;
3155: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3156: }
3157:
1.728 raeburn 3158: # -------------------------------------------------------------------- getlangs
3159:
3160: =pod
3161:
3162: =item * &getlangs($uname,$udom)
3163:
3164: Gets a user's language preference and returns it as a hash with key:
3165: language.
3166:
3167: =cut
3168:
3169:
3170: sub getlangs {
3171: my ($uname,$udom) = @_;
3172: if (!$udom) { $udom =$env{'user.domain'}; }
3173: if (!$uname) { $uname=$env{'user.name'}; }
3174: my $id=$uname.':'.$udom;
3175: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3176: if ($cached) {
3177: return %{$langs};
3178: } else {
3179: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3180: $udom,$uname);
3181: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3182: return %loadlangs;
3183: }
3184: }
3185:
3186: sub flush_langs_cache {
3187: my ($uname,$udom)=@_;
3188: if (!$udom) { $udom =$env{'user.domain'}; }
3189: if (!$uname) { $uname=$env{'user.name'}; }
3190: return if ($udom eq 'public' && $uname eq 'public');
3191: my $id=$uname.':'.$udom;
3192: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3193: }
3194:
1.61 www 3195: # ------------------------------------------------------------------ Screenname
1.81 albertel 3196:
3197: =pod
3198:
1.648 raeburn 3199: =item * &screenname($uname,$udom)
1.81 albertel 3200:
3201: Gets a users screenname and returns it as a string
3202:
3203: =cut
1.61 www 3204:
3205: sub screenname {
3206: my ($uname,$udom)=@_;
1.258 albertel 3207: if ($uname eq $env{'user.name'} &&
3208: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3209: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3210: return $names{'screenname'};
1.62 www 3211: }
3212:
1.212 albertel 3213:
1.802 bisitz 3214: # ------------------------------------------------------------- Confirm Wrapper
3215: =pod
3216:
3217: =item confirmwrapper
3218:
3219: Wrap messages about completion of operation in box
3220:
3221: =cut
3222:
3223: sub confirmwrapper {
3224: my ($message)=@_;
3225: if ($message) {
3226: return "\n".'<div class="LC_confirm_box">'."\n"
3227: .$message."\n"
3228: .'</div>'."\n";
3229: } else {
3230: return $message;
3231: }
3232: }
3233:
1.62 www 3234: # ------------------------------------------------------------- Message Wrapper
3235:
3236: sub messagewrapper {
1.369 www 3237: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3238: return
1.441 albertel 3239: '<a href="/adm/email?compose=individual&'.
3240: 'recname='.$username.'&recdom='.$domain.
3241: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3242: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3243: }
1.802 bisitz 3244:
1.74 www 3245: # --------------------------------------------------------------- Notes Wrapper
3246:
3247: sub noteswrapper {
3248: my ($link,$un,$do)=@_;
3249: return
1.896 amueller 3250: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3251: }
1.802 bisitz 3252:
1.62 www 3253: # ------------------------------------------------------------- Aboutme Wrapper
3254:
3255: sub aboutmewrapper {
1.1070 raeburn 3256: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3257: if (!defined($username) && !defined($domain)) {
3258: return;
3259: }
1.1075.2.15 raeburn 3260: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3261: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3262: }
3263:
3264: # ------------------------------------------------------------ Syllabus Wrapper
3265:
3266: sub syllabuswrapper {
1.707 bisitz 3267: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3268: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3269: }
1.14 harris41 3270:
1.802 bisitz 3271: # -----------------------------------------------------------------------------
3272:
1.208 matthew 3273: sub track_student_link {
1.887 raeburn 3274: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3275: my $link ="/adm/trackstudent?";
1.208 matthew 3276: my $title = 'View recent activity';
3277: if (defined($sname) && $sname !~ /^\s*$/ &&
3278: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3279: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3280: $title .= ' of this student';
1.268 albertel 3281: }
1.208 matthew 3282: if (defined($target) && $target !~ /^\s*$/) {
3283: $target = qq{target="$target"};
3284: } else {
3285: $target = '';
3286: }
1.268 albertel 3287: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3288: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3289: $title = &mt($title);
3290: $linktext = &mt($linktext);
1.448 albertel 3291: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3292: &help_open_topic('View_recent_activity');
1.208 matthew 3293: }
3294:
1.781 raeburn 3295: sub slot_reservations_link {
3296: my ($linktext,$sname,$sdom,$target) = @_;
3297: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3298: my $title = 'View slot reservation history';
3299: if (defined($sname) && $sname !~ /^\s*$/ &&
3300: defined($sdom) && $sdom !~ /^\s*$/) {
3301: $link .= "&uname=$sname&udom=$sdom";
3302: $title .= ' of this student';
3303: }
3304: if (defined($target) && $target !~ /^\s*$/) {
3305: $target = qq{target="$target"};
3306: } else {
3307: $target = '';
3308: }
3309: $title = &mt($title);
3310: $linktext = &mt($linktext);
3311: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3312: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3313:
3314: }
3315:
1.508 www 3316: # ===================================================== Display a student photo
3317:
3318:
1.509 albertel 3319: sub student_image_tag {
1.508 www 3320: my ($domain,$user)=@_;
3321: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3322: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3323: return '<img src="'.$imgsrc.'" align="right" />';
3324: } else {
3325: return '';
3326: }
3327: }
3328:
1.112 bowersj2 3329: =pod
3330:
3331: =back
3332:
3333: =head1 Access .tab File Data
3334:
3335: =over 4
3336:
1.648 raeburn 3337: =item * &languageids()
1.112 bowersj2 3338:
3339: returns list of all language ids
3340:
3341: =cut
3342:
1.14 harris41 3343: sub languageids {
1.16 harris41 3344: return sort(keys(%language));
1.14 harris41 3345: }
3346:
1.112 bowersj2 3347: =pod
3348:
1.648 raeburn 3349: =item * &languagedescription()
1.112 bowersj2 3350:
3351: returns description of a specified language id
3352:
3353: =cut
3354:
1.14 harris41 3355: sub languagedescription {
1.125 www 3356: my $code=shift;
3357: return ($supported_language{$code}?'* ':'').
3358: $language{$code}.
1.126 www 3359: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3360: }
3361:
1.1048 foxr 3362: =pod
3363:
3364: =item * &plainlanguagedescription
3365:
3366: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3367: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3368:
3369: =cut
3370:
1.145 www 3371: sub plainlanguagedescription {
3372: my $code=shift;
3373: return $language{$code};
3374: }
3375:
1.1048 foxr 3376: =pod
3377:
3378: =item * &supportedlanguagecode
3379:
3380: Returns the supported language code (e.g. sptutf maps to pt) given a language
3381: code.
3382:
3383: =cut
3384:
1.145 www 3385: sub supportedlanguagecode {
3386: my $code=shift;
3387: return $supported_language{$code};
1.97 www 3388: }
3389:
1.112 bowersj2 3390: =pod
3391:
1.1048 foxr 3392: =item * &latexlanguage()
3393:
3394: Given a language key code returns the correspondnig language to use
3395: to select the correct hyphenation on LaTeX printouts. This is undef if there
3396: is no supported hyphenation for the language code.
3397:
3398: =cut
3399:
3400: sub latexlanguage {
3401: my $code = shift;
3402: return $latex_language{$code};
3403: }
3404:
3405: =pod
3406:
3407: =item * &latexhyphenation()
3408:
3409: Same as above but what's supplied is the language as it might be stored
3410: in the metadata.
3411:
3412: =cut
3413:
3414: sub latexhyphenation {
3415: my $key = shift;
3416: return $latex_language_bykey{$key};
3417: }
3418:
3419: =pod
3420:
1.648 raeburn 3421: =item * ©rightids()
1.112 bowersj2 3422:
3423: returns list of all copyrights
3424:
3425: =cut
3426:
3427: sub copyrightids {
3428: return sort(keys(%cprtag));
3429: }
3430:
3431: =pod
3432:
1.648 raeburn 3433: =item * ©rightdescription()
1.112 bowersj2 3434:
3435: returns description of a specified copyright id
3436:
3437: =cut
3438:
3439: sub copyrightdescription {
1.166 www 3440: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3441: }
1.197 matthew 3442:
3443: =pod
3444:
1.648 raeburn 3445: =item * &source_copyrightids()
1.192 taceyjo1 3446:
3447: returns list of all source copyrights
3448:
3449: =cut
3450:
3451: sub source_copyrightids {
3452: return sort(keys(%scprtag));
3453: }
3454:
3455: =pod
3456:
1.648 raeburn 3457: =item * &source_copyrightdescription()
1.192 taceyjo1 3458:
3459: returns description of a specified source copyright id
3460:
3461: =cut
3462:
3463: sub source_copyrightdescription {
3464: return &mt($scprtag{shift(@_)});
3465: }
1.112 bowersj2 3466:
3467: =pod
3468:
1.648 raeburn 3469: =item * &filecategories()
1.112 bowersj2 3470:
3471: returns list of all file categories
3472:
3473: =cut
3474:
3475: sub filecategories {
3476: return sort(keys(%category_extensions));
3477: }
3478:
3479: =pod
3480:
1.648 raeburn 3481: =item * &filecategorytypes()
1.112 bowersj2 3482:
3483: returns list of file types belonging to a given file
3484: category
3485:
3486: =cut
3487:
3488: sub filecategorytypes {
1.356 albertel 3489: my ($cat) = @_;
3490: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3491: }
3492:
3493: =pod
3494:
1.648 raeburn 3495: =item * &fileembstyle()
1.112 bowersj2 3496:
3497: returns embedding style for a specified file type
3498:
3499: =cut
3500:
3501: sub fileembstyle {
3502: return $fe{lc(shift(@_))};
1.169 www 3503: }
3504:
1.351 www 3505: sub filemimetype {
3506: return $fm{lc(shift(@_))};
3507: }
3508:
1.169 www 3509:
3510: sub filecategoryselect {
3511: my ($name,$value)=@_;
1.189 matthew 3512: return &select_form($value,$name,
1.970 raeburn 3513: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3514: }
3515:
3516: =pod
3517:
1.648 raeburn 3518: =item * &filedescription()
1.112 bowersj2 3519:
3520: returns description for a specified file type
3521:
3522: =cut
3523:
3524: sub filedescription {
1.188 matthew 3525: my $file_description = $fd{lc(shift())};
3526: $file_description =~ s:([\[\]]):~$1:g;
3527: return &mt($file_description);
1.112 bowersj2 3528: }
3529:
3530: =pod
3531:
1.648 raeburn 3532: =item * &filedescriptionex()
1.112 bowersj2 3533:
3534: returns description for a specified file type with
3535: extra formatting
3536:
3537: =cut
3538:
3539: sub filedescriptionex {
3540: my $ex=shift;
1.188 matthew 3541: my $file_description = $fd{lc($ex)};
3542: $file_description =~ s:([\[\]]):~$1:g;
3543: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3544: }
3545:
3546: # End of .tab access
3547: =pod
3548:
3549: =back
3550:
3551: =cut
3552:
3553: # ------------------------------------------------------------------ File Types
3554: sub fileextensions {
3555: return sort(keys(%fe));
3556: }
3557:
1.97 www 3558: # ----------------------------------------------------------- Display Languages
3559: # returns a hash with all desired display languages
3560: #
3561:
3562: sub display_languages {
3563: my %languages=();
1.695 raeburn 3564: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3565: $languages{$lang}=1;
1.97 www 3566: }
3567: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3568: if ($env{'form.displaylanguage'}) {
1.356 albertel 3569: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3570: $languages{$lang}=1;
1.97 www 3571: }
3572: }
3573: return %languages;
1.14 harris41 3574: }
3575:
1.582 albertel 3576: sub languages {
3577: my ($possible_langs) = @_;
1.695 raeburn 3578: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3579: if (!ref($possible_langs)) {
3580: if( wantarray ) {
3581: return @preferred_langs;
3582: } else {
3583: return $preferred_langs[0];
3584: }
3585: }
3586: my %possibilities = map { $_ => 1 } (@$possible_langs);
3587: my @preferred_possibilities;
3588: foreach my $preferred_lang (@preferred_langs) {
3589: if (exists($possibilities{$preferred_lang})) {
3590: push(@preferred_possibilities, $preferred_lang);
3591: }
3592: }
3593: if( wantarray ) {
3594: return @preferred_possibilities;
3595: }
3596: return $preferred_possibilities[0];
3597: }
3598:
1.742 raeburn 3599: sub user_lang {
3600: my ($touname,$toudom,$fromcid) = @_;
3601: my @userlangs;
3602: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3603: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3604: $env{'course.'.$fromcid.'.languages'}));
3605: } else {
3606: my %langhash = &getlangs($touname,$toudom);
3607: if ($langhash{'languages'} ne '') {
3608: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3609: } else {
3610: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3611: if ($domdefs{'lang_def'} ne '') {
3612: @userlangs = ($domdefs{'lang_def'});
3613: }
3614: }
3615: }
3616: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3617: my $user_lh = Apache::localize->get_handle(@languages);
3618: return $user_lh;
3619: }
3620:
3621:
1.112 bowersj2 3622: ###############################################################
3623: ## Student Answer Attempts ##
3624: ###############################################################
3625:
3626: =pod
3627:
3628: =head1 Alternate Problem Views
3629:
3630: =over 4
3631:
1.648 raeburn 3632: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3633: $getattempt, $regexp, $gradesub)
3634:
3635: Return string with previous attempt on problem. Arguments:
3636:
3637: =over 4
3638:
3639: =item * $symb: Problem, including path
3640:
3641: =item * $username: username of the desired student
3642:
3643: =item * $domain: domain of the desired student
1.14 harris41 3644:
1.112 bowersj2 3645: =item * $course: Course ID
1.14 harris41 3646:
1.112 bowersj2 3647: =item * $getattempt: Leave blank for all attempts, otherwise put
3648: something
1.14 harris41 3649:
1.112 bowersj2 3650: =item * $regexp: if string matches this regexp, the string will be
3651: sent to $gradesub
1.14 harris41 3652:
1.112 bowersj2 3653: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3654:
1.112 bowersj2 3655: =back
1.14 harris41 3656:
1.112 bowersj2 3657: The output string is a table containing all desired attempts, if any.
1.16 harris41 3658:
1.112 bowersj2 3659: =cut
1.1 albertel 3660:
3661: sub get_previous_attempt {
1.43 ng 3662: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3663: my $prevattempts='';
1.43 ng 3664: no strict 'refs';
1.1 albertel 3665: if ($symb) {
1.3 albertel 3666: my (%returnhash)=
3667: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3668: if ($returnhash{'version'}) {
3669: my %lasthash=();
3670: my $version;
3671: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3672: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3673: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3674: }
1.1 albertel 3675: }
1.596 albertel 3676: $prevattempts=&start_data_table().&start_data_table_header_row();
3677: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3678: my (%typeparts,%lasthidden);
1.945 raeburn 3679: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3680: foreach my $key (sort(keys(%lasthash))) {
3681: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3682: if ($#parts > 0) {
1.31 albertel 3683: my $data=$parts[-1];
1.989 raeburn 3684: next if ($data eq 'foilorder');
1.31 albertel 3685: pop(@parts);
1.1010 www 3686: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3687: if ($data eq 'type') {
3688: unless ($showsurv) {
3689: my $id = join(',',@parts);
3690: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3691: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3692: $lasthidden{$ign.'.'.$id} = 1;
3693: }
1.945 raeburn 3694: }
1.1010 www 3695: }
1.31 albertel 3696: } else {
1.41 ng 3697: if ($#parts == 0) {
3698: $prevattempts.='<th>'.$parts[0].'</th>';
3699: } else {
3700: $prevattempts.='<th>'.$ign.'</th>';
3701: }
1.31 albertel 3702: }
1.16 harris41 3703: }
1.596 albertel 3704: $prevattempts.=&end_data_table_header_row();
1.40 ng 3705: if ($getattempt eq '') {
3706: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3707: my @hidden;
3708: if (%typeparts) {
3709: foreach my $id (keys(%typeparts)) {
3710: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3711: push(@hidden,$id);
3712: }
3713: }
3714: }
3715: $prevattempts.=&start_data_table_row().
3716: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3717: if (@hidden) {
3718: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3719: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3720: my $hide;
3721: foreach my $id (@hidden) {
3722: if ($key =~ /^\Q$id\E/) {
3723: $hide = 1;
3724: last;
3725: }
3726: }
3727: if ($hide) {
3728: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3729: if (($data eq 'award') || ($data eq 'awarddetail')) {
3730: my $value = &format_previous_attempt_value($key,
3731: $returnhash{$version.':'.$key});
3732: $prevattempts.='<td>'.$value.' </td>';
3733: } else {
3734: $prevattempts.='<td> </td>';
3735: }
3736: } else {
3737: if ($key =~ /\./) {
3738: my $value = &format_previous_attempt_value($key,
3739: $returnhash{$version.':'.$key});
3740: $prevattempts.='<td>'.$value.' </td>';
3741: } else {
3742: $prevattempts.='<td> </td>';
3743: }
3744: }
3745: }
3746: } else {
3747: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3748: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3749: my $value = &format_previous_attempt_value($key,
3750: $returnhash{$version.':'.$key});
3751: $prevattempts.='<td>'.$value.' </td>';
3752: }
3753: }
3754: $prevattempts.=&end_data_table_row();
1.40 ng 3755: }
1.1 albertel 3756: }
1.945 raeburn 3757: my @currhidden = keys(%lasthidden);
1.596 albertel 3758: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3759: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3760: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3761: if (%typeparts) {
3762: my $hidden;
3763: foreach my $id (@currhidden) {
3764: if ($key =~ /^\Q$id\E/) {
3765: $hidden = 1;
3766: last;
3767: }
3768: }
3769: if ($hidden) {
3770: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3771: if (($data eq 'award') || ($data eq 'awarddetail')) {
3772: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3773: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3774: $value = &$gradesub($value);
3775: }
3776: $prevattempts.='<td>'.$value.' </td>';
3777: } else {
3778: $prevattempts.='<td> </td>';
3779: }
3780: } else {
3781: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3782: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3783: $value = &$gradesub($value);
3784: }
3785: $prevattempts.='<td>'.$value.' </td>';
3786: }
3787: } else {
3788: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3789: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3790: $value = &$gradesub($value);
3791: }
3792: $prevattempts.='<td>'.$value.' </td>';
3793: }
1.16 harris41 3794: }
1.596 albertel 3795: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3796: } else {
1.596 albertel 3797: $prevattempts=
3798: &start_data_table().&start_data_table_row().
3799: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3800: &end_data_table_row().&end_data_table();
1.1 albertel 3801: }
3802: } else {
1.596 albertel 3803: $prevattempts=
3804: &start_data_table().&start_data_table_row().
3805: '<td>'.&mt('No data.').'</td>'.
3806: &end_data_table_row().&end_data_table();
1.1 albertel 3807: }
1.10 albertel 3808: }
3809:
1.581 albertel 3810: sub format_previous_attempt_value {
3811: my ($key,$value) = @_;
1.1011 www 3812: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3813: $value = &Apache::lonlocal::locallocaltime($value);
3814: } elsif (ref($value) eq 'ARRAY') {
3815: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3816: } elsif ($key =~ /answerstring$/) {
3817: my %answers = &Apache::lonnet::str2hash($value);
3818: my @anskeys = sort(keys(%answers));
3819: if (@anskeys == 1) {
3820: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3821: if ($answer =~ m{\0}) {
3822: $answer =~ s{\0}{,}g;
1.988 raeburn 3823: }
3824: my $tag_internal_answer_name = 'INTERNAL';
3825: if ($anskeys[0] eq $tag_internal_answer_name) {
3826: $value = $answer;
3827: } else {
3828: $value = $anskeys[0].'='.$answer;
3829: }
3830: } else {
3831: foreach my $ans (@anskeys) {
3832: my $answer = $answers{$ans};
1.1001 raeburn 3833: if ($answer =~ m{\0}) {
3834: $answer =~ s{\0}{,}g;
1.988 raeburn 3835: }
3836: $value .= $ans.'='.$answer.'<br />';;
3837: }
3838: }
1.581 albertel 3839: } else {
3840: $value = &unescape($value);
3841: }
3842: return $value;
3843: }
3844:
3845:
1.107 albertel 3846: sub relative_to_absolute {
3847: my ($url,$output)=@_;
3848: my $parser=HTML::TokeParser->new(\$output);
3849: my $token;
3850: my $thisdir=$url;
3851: my @rlinks=();
3852: while ($token=$parser->get_token) {
3853: if ($token->[0] eq 'S') {
3854: if ($token->[1] eq 'a') {
3855: if ($token->[2]->{'href'}) {
3856: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3857: }
3858: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3859: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3860: } elsif ($token->[1] eq 'base') {
3861: $thisdir=$token->[2]->{'href'};
3862: }
3863: }
3864: }
3865: $thisdir=~s-/[^/]*$--;
1.356 albertel 3866: foreach my $link (@rlinks) {
1.726 raeburn 3867: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3868: ($link=~/^\//) ||
3869: ($link=~/^javascript:/i) ||
3870: ($link=~/^mailto:/i) ||
3871: ($link=~/^\#/)) {
3872: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3873: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3874: }
3875: }
3876: # -------------------------------------------------- Deal with Applet codebases
3877: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3878: return $output;
3879: }
3880:
1.112 bowersj2 3881: =pod
3882:
1.648 raeburn 3883: =item * &get_student_view()
1.112 bowersj2 3884:
3885: show a snapshot of what student was looking at
3886:
3887: =cut
3888:
1.10 albertel 3889: sub get_student_view {
1.186 albertel 3890: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3891: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3892: my (%form);
1.10 albertel 3893: my @elements=('symb','courseid','domain','username');
3894: foreach my $element (@elements) {
1.186 albertel 3895: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3896: }
1.186 albertel 3897: if (defined($moreenv)) {
3898: %form=(%form,%{$moreenv});
3899: }
1.236 albertel 3900: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3901: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3902: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3903: $userview=~s/\<body[^\>]*\>//gi;
3904: $userview=~s/\<\/body\>//gi;
3905: $userview=~s/\<html\>//gi;
3906: $userview=~s/\<\/html\>//gi;
3907: $userview=~s/\<head\>//gi;
3908: $userview=~s/\<\/head\>//gi;
3909: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3910: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3911: if (wantarray) {
3912: return ($userview,$response);
3913: } else {
3914: return $userview;
3915: }
3916: }
3917:
3918: sub get_student_view_with_retries {
3919: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3920:
3921: my $ok = 0; # True if we got a good response.
3922: my $content;
3923: my $response;
3924:
3925: # Try to get the student_view done. within the retries count:
3926:
3927: do {
3928: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3929: $ok = $response->is_success;
3930: if (!$ok) {
3931: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3932: }
3933: $retries--;
3934: } while (!$ok && ($retries > 0));
3935:
3936: if (!$ok) {
3937: $content = ''; # On error return an empty content.
3938: }
1.651 www 3939: if (wantarray) {
3940: return ($content, $response);
3941: } else {
3942: return $content;
3943: }
1.11 albertel 3944: }
3945:
1.112 bowersj2 3946: =pod
3947:
1.648 raeburn 3948: =item * &get_student_answers()
1.112 bowersj2 3949:
3950: show a snapshot of how student was answering problem
3951:
3952: =cut
3953:
1.11 albertel 3954: sub get_student_answers {
1.100 sakharuk 3955: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3956: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3957: my (%moreenv);
1.11 albertel 3958: my @elements=('symb','courseid','domain','username');
3959: foreach my $element (@elements) {
1.186 albertel 3960: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3961: }
1.186 albertel 3962: $moreenv{'grade_target'}='answer';
3963: %moreenv=(%form,%moreenv);
1.497 raeburn 3964: $feedurl = &Apache::lonnet::clutter($feedurl);
3965: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3966: return $userview;
1.1 albertel 3967: }
1.116 albertel 3968:
3969: =pod
3970:
3971: =item * &submlink()
3972:
1.242 albertel 3973: Inputs: $text $uname $udom $symb $target
1.116 albertel 3974:
3975: Returns: A link to grades.pm such as to see the SUBM view of a student
3976:
3977: =cut
3978:
3979: ###############################################
3980: sub submlink {
1.242 albertel 3981: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3982: if (!($uname && $udom)) {
3983: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3984: &Apache::lonnet::whichuser($symb);
1.116 albertel 3985: if (!$symb) { $symb=$cursymb; }
3986: }
1.254 matthew 3987: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3988: $symb=&escape($symb);
1.960 bisitz 3989: if ($target) { $target=" target=\"$target\""; }
3990: return
3991: '<a href="/adm/grades?command=submission'.
3992: '&symb='.$symb.
3993: '&student='.$uname.
3994: '&userdom='.$udom.'"'.
3995: $target.'>'.$text.'</a>';
1.242 albertel 3996: }
3997: ##############################################
3998:
3999: =pod
4000:
4001: =item * &pgrdlink()
4002:
4003: Inputs: $text $uname $udom $symb $target
4004:
4005: Returns: A link to grades.pm such as to see the PGRD view of a student
4006:
4007: =cut
4008:
4009: ###############################################
4010: sub pgrdlink {
4011: my $link=&submlink(@_);
4012: $link=~s/(&command=submission)/$1&showgrading=yes/;
4013: return $link;
4014: }
4015: ##############################################
4016:
4017: =pod
4018:
4019: =item * &pprmlink()
4020:
4021: Inputs: $text $uname $udom $symb $target
4022:
4023: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4024: student and a specific resource
1.242 albertel 4025:
4026: =cut
4027:
4028: ###############################################
4029: sub pprmlink {
4030: my ($text,$uname,$udom,$symb,$target)=@_;
4031: if (!($uname && $udom)) {
4032: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4033: &Apache::lonnet::whichuser($symb);
1.242 albertel 4034: if (!$symb) { $symb=$cursymb; }
4035: }
1.254 matthew 4036: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4037: $symb=&escape($symb);
1.242 albertel 4038: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4039: return '<a href="/adm/parmset?command=set&'.
4040: 'symb='.$symb.'&uname='.$uname.
4041: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4042: }
4043: ##############################################
1.37 matthew 4044:
1.112 bowersj2 4045: =pod
4046:
4047: =back
4048:
4049: =cut
4050:
1.37 matthew 4051: ###############################################
1.51 www 4052:
4053:
4054: sub timehash {
1.687 raeburn 4055: my ($thistime) = @_;
4056: my $timezone = &Apache::lonlocal::gettimezone();
4057: my $dt = DateTime->from_epoch(epoch => $thistime)
4058: ->set_time_zone($timezone);
4059: my $wday = $dt->day_of_week();
4060: if ($wday == 7) { $wday = 0; }
4061: return ( 'second' => $dt->second(),
4062: 'minute' => $dt->minute(),
4063: 'hour' => $dt->hour(),
4064: 'day' => $dt->day_of_month(),
4065: 'month' => $dt->month(),
4066: 'year' => $dt->year(),
4067: 'weekday' => $wday,
4068: 'dayyear' => $dt->day_of_year(),
4069: 'dlsav' => $dt->is_dst() );
1.51 www 4070: }
4071:
1.370 www 4072: sub utc_string {
4073: my ($date)=@_;
1.371 www 4074: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4075: }
4076:
1.51 www 4077: sub maketime {
4078: my %th=@_;
1.687 raeburn 4079: my ($epoch_time,$timezone,$dt);
4080: $timezone = &Apache::lonlocal::gettimezone();
4081: eval {
4082: $dt = DateTime->new( year => $th{'year'},
4083: month => $th{'month'},
4084: day => $th{'day'},
4085: hour => $th{'hour'},
4086: minute => $th{'minute'},
4087: second => $th{'second'},
4088: time_zone => $timezone,
4089: );
4090: };
4091: if (!$@) {
4092: $epoch_time = $dt->epoch;
4093: if ($epoch_time) {
4094: return $epoch_time;
4095: }
4096: }
1.51 www 4097: return POSIX::mktime(
4098: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4099: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4100: }
4101:
4102: #########################################
1.51 www 4103:
4104: sub findallcourses {
1.482 raeburn 4105: my ($roles,$uname,$udom) = @_;
1.355 albertel 4106: my %roles;
4107: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4108: my %courses;
1.51 www 4109: my $now=time;
1.482 raeburn 4110: if (!defined($uname)) {
4111: $uname = $env{'user.name'};
4112: }
4113: if (!defined($udom)) {
4114: $udom = $env{'user.domain'};
4115: }
4116: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4117: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4118: if (!%roles) {
4119: %roles = (
4120: cc => 1,
1.907 raeburn 4121: co => 1,
1.482 raeburn 4122: in => 1,
4123: ep => 1,
4124: ta => 1,
4125: cr => 1,
4126: st => 1,
4127: );
4128: }
4129: foreach my $entry (keys(%roleshash)) {
4130: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4131: if ($trole =~ /^cr/) {
4132: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4133: } else {
4134: next if (!exists($roles{$trole}));
4135: }
4136: if ($tend) {
4137: next if ($tend < $now);
4138: }
4139: if ($tstart) {
4140: next if ($tstart > $now);
4141: }
1.1058 raeburn 4142: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4143: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4144: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4145: if ($secpart eq '') {
4146: ($cnum,$role) = split(/_/,$cnumpart);
4147: $sec = 'none';
1.1058 raeburn 4148: $value .= $cnum.'/';
1.482 raeburn 4149: } else {
4150: $cnum = $cnumpart;
4151: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4152: $value .= $cnum.'/'.$sec;
4153: }
4154: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4155: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4156: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4157: }
4158: } else {
4159: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4160: }
1.482 raeburn 4161: }
4162: } else {
4163: foreach my $key (keys(%env)) {
1.483 albertel 4164: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4165: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4166: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4167: next if ($role eq 'ca' || $role eq 'aa');
4168: next if (%roles && !exists($roles{$role}));
4169: my ($starttime,$endtime)=split(/\./,$env{$key});
4170: my $active=1;
4171: if ($starttime) {
4172: if ($now<$starttime) { $active=0; }
4173: }
4174: if ($endtime) {
4175: if ($now>$endtime) { $active=0; }
4176: }
4177: if ($active) {
1.1058 raeburn 4178: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4179: if ($sec eq '') {
4180: $sec = 'none';
1.1058 raeburn 4181: } else {
4182: $value .= $sec;
4183: }
4184: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4185: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4186: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4187: }
4188: } else {
4189: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4190: }
1.474 raeburn 4191: }
4192: }
1.51 www 4193: }
4194: }
1.474 raeburn 4195: return %courses;
1.51 www 4196: }
1.37 matthew 4197:
1.54 www 4198: ###############################################
1.474 raeburn 4199:
4200: sub blockcheck {
1.1062 raeburn 4201: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4202:
4203: if (!defined($udom)) {
4204: $udom = $env{'user.domain'};
4205: }
4206: if (!defined($uname)) {
4207: $uname = $env{'user.name'};
4208: }
4209:
4210: # If uname and udom are for a course, check for blocks in the course.
4211:
4212: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4213: my ($startblock,$endblock,$triggerblock) =
4214: &get_blocks($setters,$activity,$udom,$uname,$url);
4215: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4216: }
1.474 raeburn 4217:
1.502 raeburn 4218: my $startblock = 0;
4219: my $endblock = 0;
1.1062 raeburn 4220: my $triggerblock = '';
1.482 raeburn 4221: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4222:
1.490 raeburn 4223: # If uname is for a user, and activity is course-specific, i.e.,
4224: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4225:
1.490 raeburn 4226: if (($activity eq 'boards' || $activity eq 'chat' ||
4227: $activity eq 'groups') && ($env{'request.course.id'})) {
4228: foreach my $key (keys(%live_courses)) {
4229: if ($key ne $env{'request.course.id'}) {
4230: delete($live_courses{$key});
4231: }
4232: }
4233: }
4234:
4235: my $otheruser = 0;
4236: my %own_courses;
4237: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4238: # Resource belongs to user other than current user.
4239: $otheruser = 1;
4240: # Gather courses for current user
4241: %own_courses =
4242: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4243: }
4244:
4245: # Gather active course roles - course coordinator, instructor,
4246: # exam proctor, ta, student, or custom role.
1.474 raeburn 4247:
4248: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4249: my ($cdom,$cnum);
4250: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4251: $cdom = $env{'course.'.$course.'.domain'};
4252: $cnum = $env{'course.'.$course.'.num'};
4253: } else {
1.490 raeburn 4254: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4255: }
4256: my $no_ownblock = 0;
4257: my $no_userblock = 0;
1.533 raeburn 4258: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4259: # Check if current user has 'evb' priv for this
4260: if (defined($own_courses{$course})) {
4261: foreach my $sec (keys(%{$own_courses{$course}})) {
4262: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4263: if ($sec ne 'none') {
4264: $checkrole .= '/'.$sec;
4265: }
4266: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4267: $no_ownblock = 1;
4268: last;
4269: }
4270: }
4271: }
4272: # if they have 'evb' priv and are currently not playing student
4273: next if (($no_ownblock) &&
4274: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4275: }
1.474 raeburn 4276: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4277: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4278: if ($sec ne 'none') {
1.482 raeburn 4279: $checkrole .= '/'.$sec;
1.474 raeburn 4280: }
1.490 raeburn 4281: if ($otheruser) {
4282: # Resource belongs to user other than current user.
4283: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4284: my (%allroles,%userroles);
4285: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4286: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4287: my ($trole,$tdom,$tnum,$tsec);
4288: if ($entry =~ /^cr/) {
4289: ($trole,$tdom,$tnum,$tsec) =
4290: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4291: } else {
4292: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4293: }
4294: my ($spec,$area,$trest);
4295: $area = '/'.$tdom.'/'.$tnum;
4296: $trest = $tnum;
4297: if ($tsec ne '') {
4298: $area .= '/'.$tsec;
4299: $trest .= '/'.$tsec;
4300: }
4301: $spec = $trole.'.'.$area;
4302: if ($trole =~ /^cr/) {
4303: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4304: $tdom,$spec,$trest,$area);
4305: } else {
4306: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4307: $tdom,$spec,$trest,$area);
4308: }
4309: }
4310: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4311: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4312: if ($1) {
4313: $no_userblock = 1;
4314: last;
4315: }
1.486 raeburn 4316: }
4317: }
1.490 raeburn 4318: } else {
4319: # Resource belongs to current user
4320: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4321: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4322: $no_ownblock = 1;
4323: last;
4324: }
1.474 raeburn 4325: }
4326: }
4327: # if they have the evb priv and are currently not playing student
1.482 raeburn 4328: next if (($no_ownblock) &&
1.491 albertel 4329: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4330: next if ($no_userblock);
1.474 raeburn 4331:
1.866 kalberla 4332: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4333: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4334:
1.1062 raeburn 4335: my ($start,$end,$trigger) =
4336: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4337: if (($start != 0) &&
4338: (($startblock == 0) || ($startblock > $start))) {
4339: $startblock = $start;
1.1062 raeburn 4340: if ($trigger ne '') {
4341: $triggerblock = $trigger;
4342: }
1.502 raeburn 4343: }
4344: if (($end != 0) &&
4345: (($endblock == 0) || ($endblock < $end))) {
4346: $endblock = $end;
1.1062 raeburn 4347: if ($trigger ne '') {
4348: $triggerblock = $trigger;
4349: }
1.502 raeburn 4350: }
1.490 raeburn 4351: }
1.1062 raeburn 4352: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4353: }
4354:
4355: sub get_blocks {
1.1062 raeburn 4356: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4357: my $startblock = 0;
4358: my $endblock = 0;
1.1062 raeburn 4359: my $triggerblock = '';
1.490 raeburn 4360: my $course = $cdom.'_'.$cnum;
4361: $setters->{$course} = {};
4362: $setters->{$course}{'staff'} = [];
4363: $setters->{$course}{'times'} = [];
1.1062 raeburn 4364: $setters->{$course}{'triggers'} = [];
4365: my (@blockers,%triggered);
4366: my $now = time;
4367: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4368: if ($activity eq 'docs') {
4369: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4370: foreach my $block (@blockers) {
4371: if ($block =~ /^firstaccess____(.+)$/) {
4372: my $item = $1;
4373: my $type = 'map';
4374: my $timersymb = $item;
4375: if ($item eq 'course') {
4376: $type = 'course';
4377: } elsif ($item =~ /___\d+___/) {
4378: $type = 'resource';
4379: } else {
4380: $timersymb = &Apache::lonnet::symbread($item);
4381: }
4382: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4383: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4384: $triggered{$block} = {
4385: start => $start,
4386: end => $end,
4387: type => $type,
4388: };
4389: }
4390: }
4391: } else {
4392: foreach my $block (keys(%commblocks)) {
4393: if ($block =~ m/^(\d+)____(\d+)$/) {
4394: my ($start,$end) = ($1,$2);
4395: if ($start <= time && $end >= time) {
4396: if (ref($commblocks{$block}) eq 'HASH') {
4397: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4398: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4399: unless(grep(/^\Q$block\E$/,@blockers)) {
4400: push(@blockers,$block);
4401: }
4402: }
4403: }
4404: }
4405: }
4406: } elsif ($block =~ /^firstaccess____(.+)$/) {
4407: my $item = $1;
4408: my $timersymb = $item;
4409: my $type = 'map';
4410: if ($item eq 'course') {
4411: $type = 'course';
4412: } elsif ($item =~ /___\d+___/) {
4413: $type = 'resource';
4414: } else {
4415: $timersymb = &Apache::lonnet::symbread($item);
4416: }
4417: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4418: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4419: if ($start && $end) {
4420: if (($start <= time) && ($end >= time)) {
4421: unless (grep(/^\Q$block\E$/,@blockers)) {
4422: push(@blockers,$block);
4423: $triggered{$block} = {
4424: start => $start,
4425: end => $end,
4426: type => $type,
4427: };
4428: }
4429: }
1.490 raeburn 4430: }
1.1062 raeburn 4431: }
4432: }
4433: }
4434: foreach my $blocker (@blockers) {
4435: my ($staff_name,$staff_dom,$title,$blocks) =
4436: &parse_block_record($commblocks{$blocker});
4437: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4438: my ($start,$end,$triggertype);
4439: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4440: ($start,$end) = ($1,$2);
4441: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4442: $start = $triggered{$blocker}{'start'};
4443: $end = $triggered{$blocker}{'end'};
4444: $triggertype = $triggered{$blocker}{'type'};
4445: }
4446: if ($start) {
4447: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4448: if ($triggertype) {
4449: push(@{$$setters{$course}{'triggers'}},$triggertype);
4450: } else {
4451: push(@{$$setters{$course}{'triggers'}},0);
4452: }
4453: if ( ($startblock == 0) || ($startblock > $start) ) {
4454: $startblock = $start;
4455: if ($triggertype) {
4456: $triggerblock = $blocker;
1.474 raeburn 4457: }
4458: }
1.1062 raeburn 4459: if ( ($endblock == 0) || ($endblock < $end) ) {
4460: $endblock = $end;
4461: if ($triggertype) {
4462: $triggerblock = $blocker;
4463: }
4464: }
1.474 raeburn 4465: }
4466: }
1.1062 raeburn 4467: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4468: }
4469:
4470: sub parse_block_record {
4471: my ($record) = @_;
4472: my ($setuname,$setudom,$title,$blocks);
4473: if (ref($record) eq 'HASH') {
4474: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4475: $title = &unescape($record->{'event'});
4476: $blocks = $record->{'blocks'};
4477: } else {
4478: my @data = split(/:/,$record,3);
4479: if (scalar(@data) eq 2) {
4480: $title = $data[1];
4481: ($setuname,$setudom) = split(/@/,$data[0]);
4482: } else {
4483: ($setuname,$setudom,$title) = @data;
4484: }
4485: $blocks = { 'com' => 'on' };
4486: }
4487: return ($setuname,$setudom,$title,$blocks);
4488: }
4489:
1.854 kalberla 4490: sub blocking_status {
1.1062 raeburn 4491: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4492: my %setters;
1.890 droeschl 4493:
1.1061 raeburn 4494: # check for active blocking
1.1062 raeburn 4495: my ($startblock,$endblock,$triggerblock) =
4496: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4497: my $blocked = 0;
4498: if ($startblock && $endblock) {
4499: $blocked = 1;
4500: }
1.890 droeschl 4501:
1.1061 raeburn 4502: # caller just wants to know whether a block is active
4503: if (!wantarray) { return $blocked; }
4504:
4505: # build a link to a popup window containing the details
4506: my $querystring = "?activity=$activity";
4507: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4508: if ($activity eq 'port') {
4509: $querystring .= "&udom=$udom" if $udom;
4510: $querystring .= "&uname=$uname" if $uname;
4511: } elsif ($activity eq 'docs') {
4512: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4513: }
1.1061 raeburn 4514:
4515: my $output .= <<'END_MYBLOCK';
4516: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4517: var options = "width=" + w + ",height=" + h + ",";
4518: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4519: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4520: var newWin = window.open(url, wdwName, options);
4521: newWin.focus();
4522: }
1.890 droeschl 4523: END_MYBLOCK
1.854 kalberla 4524:
1.1061 raeburn 4525: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4526:
1.1061 raeburn 4527: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4528: my $text = &mt('Communication Blocked');
4529: if ($activity eq 'docs') {
4530: $text = &mt('Content Access Blocked');
1.1063 raeburn 4531: } elsif ($activity eq 'printout') {
4532: $text = &mt('Printing Blocked');
1.1062 raeburn 4533: }
1.1061 raeburn 4534: $output .= <<"END_BLOCK";
1.867 kalberla 4535: <div class='LC_comblock'>
1.869 kalberla 4536: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4537: title='$text'>
4538: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4539: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4540: title='$text'>$text</a>
1.867 kalberla 4541: </div>
4542:
4543: END_BLOCK
1.474 raeburn 4544:
1.1061 raeburn 4545: return ($blocked, $output);
1.854 kalberla 4546: }
1.490 raeburn 4547:
1.60 matthew 4548: ###############################################
4549:
1.682 raeburn 4550: sub check_ip_acc {
4551: my ($acc)=@_;
4552: &Apache::lonxml::debug("acc is $acc");
4553: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4554: return 1;
4555: }
4556: my $allowed=0;
4557: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4558:
4559: my $name;
4560: foreach my $pattern (split(',',$acc)) {
4561: $pattern =~ s/^\s*//;
4562: $pattern =~ s/\s*$//;
4563: if ($pattern =~ /\*$/) {
4564: #35.8.*
4565: $pattern=~s/\*//;
4566: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4567: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4568: #35.8.3.[34-56]
4569: my $low=$2;
4570: my $high=$3;
4571: $pattern=$1;
4572: if ($ip =~ /^\Q$pattern\E/) {
4573: my $last=(split(/\./,$ip))[3];
4574: if ($last <=$high && $last >=$low) { $allowed=1; }
4575: }
4576: } elsif ($pattern =~ /^\*/) {
4577: #*.msu.edu
4578: $pattern=~s/\*//;
4579: if (!defined($name)) {
4580: use Socket;
4581: my $netaddr=inet_aton($ip);
4582: ($name)=gethostbyaddr($netaddr,AF_INET);
4583: }
4584: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4585: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4586: #127.0.0.1
4587: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4588: } else {
4589: #some.name.com
4590: if (!defined($name)) {
4591: use Socket;
4592: my $netaddr=inet_aton($ip);
4593: ($name)=gethostbyaddr($netaddr,AF_INET);
4594: }
4595: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4596: }
4597: if ($allowed) { last; }
4598: }
4599: return $allowed;
4600: }
4601:
4602: ###############################################
4603:
1.60 matthew 4604: =pod
4605:
1.112 bowersj2 4606: =head1 Domain Template Functions
4607:
4608: =over 4
4609:
4610: =item * &determinedomain()
1.60 matthew 4611:
4612: Inputs: $domain (usually will be undef)
4613:
1.63 www 4614: Returns: Determines which domain should be used for designs
1.60 matthew 4615:
4616: =cut
1.54 www 4617:
1.60 matthew 4618: ###############################################
1.63 www 4619: sub determinedomain {
4620: my $domain=shift;
1.531 albertel 4621: if (! $domain) {
1.60 matthew 4622: # Determine domain if we have not been given one
1.893 raeburn 4623: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4624: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4625: if ($env{'request.role.domain'}) {
4626: $domain=$env{'request.role.domain'};
1.60 matthew 4627: }
4628: }
1.63 www 4629: return $domain;
4630: }
4631: ###############################################
1.517 raeburn 4632:
1.518 albertel 4633: sub devalidate_domconfig_cache {
4634: my ($udom)=@_;
4635: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4636: }
4637:
4638: # ---------------------- Get domain configuration for a domain
4639: sub get_domainconf {
4640: my ($udom) = @_;
4641: my $cachetime=1800;
4642: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4643: if (defined($cached)) { return %{$result}; }
4644:
4645: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4646: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4647: my (%designhash,%legacy);
1.518 albertel 4648: if (keys(%domconfig) > 0) {
4649: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4650: if (keys(%{$domconfig{'login'}})) {
4651: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4652: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4653: if ($key eq 'loginvia') {
4654: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4655: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4656: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4657: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4658: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4659: $designhash{$udom.'.login.loginvia'} = $server;
4660: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4661:
4662: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4663: } else {
1.1013 raeburn 4664: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4665: }
4666: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4667: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4668: }
1.946 raeburn 4669: }
4670: }
4671: }
4672: }
4673: } else {
4674: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4675: $designhash{$udom.'.login.'.$key.'_'.$img} =
4676: $domconfig{'login'}{$key}{$img};
4677: }
1.699 raeburn 4678: }
4679: } else {
4680: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4681: }
1.632 raeburn 4682: }
4683: } else {
4684: $legacy{'login'} = 1;
1.518 albertel 4685: }
1.632 raeburn 4686: } else {
4687: $legacy{'login'} = 1;
1.518 albertel 4688: }
4689: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4690: if (keys(%{$domconfig{'rolecolors'}})) {
4691: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4692: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4693: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4694: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4695: }
1.518 albertel 4696: }
4697: }
1.632 raeburn 4698: } else {
4699: $legacy{'rolecolors'} = 1;
1.518 albertel 4700: }
1.632 raeburn 4701: } else {
4702: $legacy{'rolecolors'} = 1;
1.518 albertel 4703: }
1.948 raeburn 4704: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4705: if ($domconfig{'autoenroll'}{'co-owners'}) {
4706: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4707: }
4708: }
1.632 raeburn 4709: if (keys(%legacy) > 0) {
4710: my %legacyhash = &get_legacy_domconf($udom);
4711: foreach my $item (keys(%legacyhash)) {
4712: if ($item =~ /^\Q$udom\E\.login/) {
4713: if ($legacy{'login'}) {
4714: $designhash{$item} = $legacyhash{$item};
4715: }
4716: } else {
4717: if ($legacy{'rolecolors'}) {
4718: $designhash{$item} = $legacyhash{$item};
4719: }
1.518 albertel 4720: }
4721: }
4722: }
1.632 raeburn 4723: } else {
4724: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4725: }
4726: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4727: $cachetime);
4728: return %designhash;
4729: }
4730:
1.632 raeburn 4731: sub get_legacy_domconf {
4732: my ($udom) = @_;
4733: my %legacyhash;
4734: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4735: my $designfile = $designdir.'/'.$udom.'.tab';
4736: if (-e $designfile) {
4737: if ( open (my $fh,"<$designfile") ) {
4738: while (my $line = <$fh>) {
4739: next if ($line =~ /^\#/);
4740: chomp($line);
4741: my ($key,$val)=(split(/\=/,$line));
4742: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4743: }
4744: close($fh);
4745: }
4746: }
1.1026 raeburn 4747: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4748: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4749: }
4750: return %legacyhash;
4751: }
4752:
1.63 www 4753: =pod
4754:
1.112 bowersj2 4755: =item * &domainlogo()
1.63 www 4756:
4757: Inputs: $domain (usually will be undef)
4758:
4759: Returns: A link to a domain logo, if the domain logo exists.
4760: If the domain logo does not exist, a description of the domain.
4761:
4762: =cut
1.112 bowersj2 4763:
1.63 www 4764: ###############################################
4765: sub domainlogo {
1.517 raeburn 4766: my $domain = &determinedomain(shift);
1.518 albertel 4767: my %designhash = &get_domainconf($domain);
1.517 raeburn 4768: # See if there is a logo
4769: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4770: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4771: if ($imgsrc =~ m{^/(adm|res)/}) {
4772: if ($imgsrc =~ m{^/res/}) {
4773: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4774: &Apache::lonnet::repcopy($local_name);
4775: }
4776: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4777: }
4778: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4779: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4780: return &Apache::lonnet::domain($domain,'description');
1.59 www 4781: } else {
1.60 matthew 4782: return '';
1.59 www 4783: }
4784: }
1.63 www 4785: ##############################################
4786:
4787: =pod
4788:
1.112 bowersj2 4789: =item * &designparm()
1.63 www 4790:
4791: Inputs: $which parameter; $domain (usually will be undef)
4792:
4793: Returns: value of designparamter $which
4794:
4795: =cut
1.112 bowersj2 4796:
1.397 albertel 4797:
1.400 albertel 4798: ##############################################
1.397 albertel 4799: sub designparm {
4800: my ($which,$domain)=@_;
4801: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4802: return $env{'environment.color.'.$which};
1.96 www 4803: }
1.63 www 4804: $domain=&determinedomain($domain);
1.1016 raeburn 4805: my %domdesign;
4806: unless ($domain eq 'public') {
4807: %domdesign = &get_domainconf($domain);
4808: }
1.520 raeburn 4809: my $output;
1.517 raeburn 4810: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4811: $output = $domdesign{$domain.'.'.$which};
1.63 www 4812: } else {
1.520 raeburn 4813: $output = $defaultdesign{$which};
4814: }
4815: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4816: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4817: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4818: if ($output =~ m{^/res/}) {
4819: my $local_name = &Apache::lonnet::filelocation('',$output);
4820: &Apache::lonnet::repcopy($local_name);
4821: }
1.520 raeburn 4822: $output = &lonhttpdurl($output);
4823: }
1.63 www 4824: }
1.520 raeburn 4825: return $output;
1.63 www 4826: }
1.59 www 4827:
1.822 bisitz 4828: ##############################################
4829: =pod
4830:
1.832 bisitz 4831: =item * &authorspace()
4832:
1.1028 raeburn 4833: Inputs: $url (usually will be undef).
1.832 bisitz 4834:
1.1028 raeburn 4835: Returns: Path to Construction Space containing the resource or
4836: directory being viewed (or for which action is being taken).
4837: If $url is provided, and begins /priv/<domain>/<uname>
4838: the path will be that portion of the $context argument.
4839: Otherwise the path will be for the author space of the current
4840: user when the current role is author, or for that of the
4841: co-author/assistant co-author space when the current role
4842: is co-author or assistant co-author.
1.832 bisitz 4843:
4844: =cut
4845:
4846: sub authorspace {
1.1028 raeburn 4847: my ($url) = @_;
4848: if ($url ne '') {
4849: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4850: return $1;
4851: }
4852: }
1.832 bisitz 4853: my $caname = '';
1.1024 www 4854: my $cadom = '';
1.1028 raeburn 4855: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4856: ($cadom,$caname) =
1.832 bisitz 4857: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4858: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4859: $caname = $env{'user.name'};
1.1024 www 4860: $cadom = $env{'user.domain'};
1.832 bisitz 4861: }
1.1028 raeburn 4862: if (($caname ne '') && ($cadom ne '')) {
4863: return "/priv/$cadom/$caname/";
4864: }
4865: return;
1.832 bisitz 4866: }
4867:
4868: ##############################################
4869: =pod
4870:
1.822 bisitz 4871: =item * &head_subbox()
4872:
4873: Inputs: $content (contains HTML code with page functions, etc.)
4874:
4875: Returns: HTML div with $content
4876: To be included in page header
4877:
4878: =cut
4879:
4880: sub head_subbox {
4881: my ($content)=@_;
4882: my $output =
1.993 raeburn 4883: '<div class="LC_head_subbox">'
1.822 bisitz 4884: .$content
4885: .'</div>'
4886: }
4887:
4888: ##############################################
4889: =pod
4890:
4891: =item * &CSTR_pageheader()
4892:
1.1026 raeburn 4893: Input: (optional) filename from which breadcrumb trail is built.
4894: In most cases no input as needed, as $env{'request.filename'}
4895: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4896:
4897: Returns: HTML div with CSTR path and recent box
4898: To be included on Construction Space pages
4899:
4900: =cut
4901:
4902: sub CSTR_pageheader {
1.1026 raeburn 4903: my ($trailfile) = @_;
4904: if ($trailfile eq '') {
4905: $trailfile = $env{'request.filename'};
4906: }
4907:
4908: # this is for resources; directories have customtitle, and crumbs
4909: # and select recent are created in lonpubdir.pm
4910:
4911: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 4912: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 4913: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 4914: my $formaction = "/priv/$udom/$uname/$thisdisfn";
4915: $formaction =~ s{/+}{/}g;
1.822 bisitz 4916:
4917: my $parentpath = '';
4918: my $lastitem = '';
4919: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4920: $parentpath = $1;
4921: $lastitem = $2;
4922: } else {
4923: $lastitem = $thisdisfn;
4924: }
1.921 bisitz 4925:
4926: my $output =
1.822 bisitz 4927: '<div>'
4928: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4929: .'<b>'.&mt('Construction Space:').'</b> '
4930: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4931: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 4932: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 4933:
4934: if ($lastitem) {
4935: $output .=
4936: '<span class="LC_filename">'
4937: .$lastitem
4938: .'</span>';
4939: }
4940: $output .=
4941: '<br />'
1.822 bisitz 4942: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4943: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4944: .'</form>'
4945: .&Apache::lonmenu::constspaceform()
4946: .'</div>';
1.921 bisitz 4947:
4948: return $output;
1.822 bisitz 4949: }
4950:
1.60 matthew 4951: ###############################################
4952: ###############################################
4953:
4954: =pod
4955:
1.112 bowersj2 4956: =back
4957:
1.549 albertel 4958: =head1 HTML Helpers
1.112 bowersj2 4959:
4960: =over 4
4961:
4962: =item * &bodytag()
1.60 matthew 4963:
4964: Returns a uniform header for LON-CAPA web pages.
4965:
4966: Inputs:
4967:
1.112 bowersj2 4968: =over 4
4969:
4970: =item * $title, A title to be displayed on the page.
4971:
4972: =item * $function, the current role (can be undef).
4973:
4974: =item * $addentries, extra parameters for the <body> tag.
4975:
4976: =item * $bodyonly, if defined, only return the <body> tag.
4977:
4978: =item * $domain, if defined, force a given domain.
4979:
4980: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4981: text interface only)
1.60 matthew 4982:
1.814 bisitz 4983: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4984: navigational links
1.317 albertel 4985:
1.338 albertel 4986: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4987:
1.1075.2.12 raeburn 4988: =item * $no_inline_link, if true and in remote mode, don't show the
4989: 'Switch To Inline Menu' link
4990:
1.460 albertel 4991: =item * $args, optional argument valid values are
4992: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4993: inherit_jsmath -> when creating popup window in a page,
4994: should it have jsmath forced on by the
4995: current page
1.460 albertel 4996:
1.1075.2.15 raeburn 4997: =item * $advtoolsref, optional argument, ref to an array containing
4998: inlineremote items to be added in "Functions" menu below
4999: breadcrumbs.
5000:
1.112 bowersj2 5001: =back
5002:
1.60 matthew 5003: Returns: A uniform header for LON-CAPA web pages.
5004: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5005: If $bodyonly is undef or zero, an html string containing a <body> tag and
5006: other decorations will be returned.
5007:
5008: =cut
5009:
1.54 www 5010: sub bodytag {
1.831 bisitz 5011: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5012: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5013:
1.954 raeburn 5014: my $public;
5015: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5016: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5017: $public = 1;
5018: }
1.460 albertel 5019: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 5020:
1.183 matthew 5021: $function = &get_users_function() if (!$function);
1.339 albertel 5022: my $img = &designparm($function.'.img',$domain);
5023: my $font = &designparm($function.'.font',$domain);
5024: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5025:
1.803 bisitz 5026: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5027: 'bgcolor' => $pgbg,
1.339 albertel 5028: 'text' => $font,
5029: 'alink' => &designparm($function.'.alink',$domain),
5030: 'vlink' => &designparm($function.'.vlink',$domain),
5031: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5032: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5033:
1.63 www 5034: # role and realm
1.378 raeburn 5035: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5036: if ($role eq 'ca') {
1.479 albertel 5037: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5038: $realm = &plainname($rname,$rdom);
1.378 raeburn 5039: }
1.55 www 5040: # realm
1.258 albertel 5041: if ($env{'request.course.id'}) {
1.378 raeburn 5042: if ($env{'request.role'} !~ /^cr/) {
5043: $role = &Apache::lonnet::plaintext($role,&course_type());
5044: }
1.898 raeburn 5045: if ($env{'request.course.sec'}) {
5046: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5047: }
1.359 albertel 5048: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5049: } else {
5050: $role = &Apache::lonnet::plaintext($role);
1.54 www 5051: }
1.433 albertel 5052:
1.359 albertel 5053: if (!$realm) { $realm=' '; }
1.330 albertel 5054:
1.438 albertel 5055: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5056:
1.101 www 5057: # construct main body tag
1.359 albertel 5058: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5059: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5060:
1.530 albertel 5061: if ($bodyonly) {
1.60 matthew 5062: return $bodytag;
1.798 tempelho 5063: }
1.359 albertel 5064:
1.410 albertel 5065: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954 raeburn 5066: if ($public) {
1.433 albertel 5067: undef($role);
1.434 albertel 5068: } else {
1.1070 raeburn 5069: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5070: undef,'LC_menubuttons_link');
1.433 albertel 5071: }
1.359 albertel 5072:
1.762 bisitz 5073: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5074: #
5075: # Extra info if you are the DC
5076: my $dc_info = '';
5077: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5078: $env{'course.'.$env{'request.course.id'}.
5079: '.domain'}.'/'})) {
5080: my $cid = $env{'request.course.id'};
1.917 raeburn 5081: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5082: $dc_info =~ s/\s+$//;
1.359 albertel 5083: }
5084:
1.898 raeburn 5085: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5086: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5087:
1.1075.2.13 raeburn 5088: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
5089: return $bodytag;
5090: }
1.903 droeschl 5091:
1.1075.2.13 raeburn 5092: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5093:
1.1075.2.21 raeburn 5094: my $funclist;
5095: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
5096: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions(), 'start')."\n".
5097: Apache::lonmenu::serverform();
5098: my $forbodytag;
5099: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5100: $forcereg,$args->{'group'},
5101: $args->{'bread_crumbs'},
5102: $advtoolsref,'',\$forbodytag);
5103: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5104: $funclist = $forbodytag;
5105: }
5106: } else {
1.903 droeschl 5107:
5108: # if ($env{'request.state'} eq 'construct') {
5109: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5110: # }
5111:
1.359 albertel 5112:
1.1075.2.2 raeburn 5113:
1.916 droeschl 5114: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5115: if ($dc_info) {
5116: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5117: }
1.1075.2.22 raeburn 5118: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
5119: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5120: return $bodytag;
5121: }
1.894 droeschl 5122:
1.927 raeburn 5123: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
5124: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
5125: }
1.916 droeschl 5126:
1.903 droeschl 5127: $bodytag .= Apache::lonhtmlcommon::scripttag(
5128: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 5129:
1.903 droeschl 5130: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 5131:
1.917 raeburn 5132: if ($dc_info) {
5133: $dc_info = &dc_courseid_toggle($dc_info);
5134: }
5135: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5136:
1.903 droeschl 5137: #don't show menus for public users
1.954 raeburn 5138: if (!$public){
1.903 droeschl 5139: $bodytag .= Apache::lonmenu::secondary_menu();
5140: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5141: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5142: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5143: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5144: $args->{'bread_crumbs'});
5145: } elsif ($forcereg) {
1.1075.2.22 raeburn 5146: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5147: $args->{'group'});
1.1075.2.15 raeburn 5148: } else {
1.1075.2.21 raeburn 5149: my $forbodytag;
5150: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5151: $forcereg,$args->{'group'},
5152: $args->{'bread_crumbs'},
5153: $advtoolsref,'',\$forbodytag);
5154: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5155: $bodytag .= $forbodytag;
5156: }
1.920 raeburn 5157: }
1.903 droeschl 5158: }else{
5159: # this is to seperate menu from content when there's no secondary
5160: # menu. Especially needed for public accessible ressources.
5161: $bodytag .= '<hr style="clear:both" />';
5162: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5163: }
1.903 droeschl 5164:
1.235 raeburn 5165: return $bodytag;
1.1075.2.12 raeburn 5166: }
5167:
5168: #
5169: # Top frame rendering, Remote is up
5170: #
5171:
5172: my $imgsrc = $img;
5173: if ($img =~ /^\/adm/) {
5174: $imgsrc = &lonhttpdurl($img);
5175: }
5176: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5177:
5178: # Explicit link to get inline menu
5179: my $menu= ($no_inline_link?''
5180: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5181:
5182: if ($dc_info) {
5183: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5184: }
5185:
5186: unless ($env{'form.inhibitmenu'}) {
5187: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
5188: <ol class="LC_primary_menu LC_right">
5189: <li>$menu</li>
5190: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5191: }
1.1075.2.13 raeburn 5192: if ($env{'request.state'} eq 'construct') {
5193: if (!$public){
5194: if ($env{'request.state'} eq 'construct') {
5195: $funclist = &Apache::lonhtmlcommon::scripttag(
5196: &Apache::lonmenu::utilityfunctions(), 'start').
5197: &Apache::lonhtmlcommon::scripttag('','end').
5198: &Apache::lonmenu::innerregister($forcereg,
5199: $args->{'bread_crumbs'});
5200: }
5201: }
5202: }
1.1075.2.21 raeburn 5203: return $bodytag."\n".$funclist;
1.182 matthew 5204: }
5205:
1.917 raeburn 5206: sub dc_courseid_toggle {
5207: my ($dc_info) = @_;
1.980 raeburn 5208: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5209: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5210: &mt('(More ...)').'</a></span>'.
5211: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5212: }
5213:
1.330 albertel 5214: sub make_attr_string {
5215: my ($register,$attr_ref) = @_;
5216:
5217: if ($attr_ref && !ref($attr_ref)) {
5218: die("addentries Must be a hash ref ".
5219: join(':',caller(1))." ".
5220: join(':',caller(0))." ");
5221: }
5222:
5223: if ($register) {
1.339 albertel 5224: my ($on_load,$on_unload);
5225: foreach my $key (keys(%{$attr_ref})) {
5226: if (lc($key) eq 'onload') {
5227: $on_load.=$attr_ref->{$key}.';';
5228: delete($attr_ref->{$key});
5229:
5230: } elsif (lc($key) eq 'onunload') {
5231: $on_unload.=$attr_ref->{$key}.';';
5232: delete($attr_ref->{$key});
5233: }
5234: }
1.1075.2.12 raeburn 5235: if ($env{'environment.remote'} eq 'on') {
5236: $attr_ref->{'onload'} =
5237: &Apache::lonmenu::loadevents(). $on_load;
5238: $attr_ref->{'onunload'}=
5239: &Apache::lonmenu::unloadevents().$on_unload;
5240: } else {
5241: $attr_ref->{'onload'} = $on_load;
5242: $attr_ref->{'onunload'}= $on_unload;
5243: }
1.330 albertel 5244: }
1.339 albertel 5245:
1.330 albertel 5246: my $attr_string;
5247: foreach my $attr (keys(%$attr_ref)) {
5248: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5249: }
5250: return $attr_string;
5251: }
5252:
5253:
1.182 matthew 5254: ###############################################
1.251 albertel 5255: ###############################################
5256:
5257: =pod
5258:
5259: =item * &endbodytag()
5260:
5261: Returns a uniform footer for LON-CAPA web pages.
5262:
1.635 raeburn 5263: Inputs: 1 - optional reference to an args hash
5264: If in the hash, key for noredirectlink has a value which evaluates to true,
5265: a 'Continue' link is not displayed if the page contains an
5266: internal redirect in the <head></head> section,
5267: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5268:
5269: =cut
5270:
5271: sub endbodytag {
1.635 raeburn 5272: my ($args) = @_;
1.1075.2.6 raeburn 5273: my $endbodytag;
5274: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5275: $endbodytag='</body>';
5276: }
1.269 albertel 5277: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5278: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5279: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5280: $endbodytag=
5281: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5282: &mt('Continue').'</a>'.
5283: $endbodytag;
5284: }
1.315 albertel 5285: }
1.251 albertel 5286: return $endbodytag;
5287: }
5288:
1.352 albertel 5289: =pod
5290:
5291: =item * &standard_css()
5292:
5293: Returns a style sheet
5294:
5295: Inputs: (all optional)
5296: domain -> force to color decorate a page for a specific
5297: domain
5298: function -> force usage of a specific rolish color scheme
5299: bgcolor -> override the default page bgcolor
5300:
5301: =cut
5302:
1.343 albertel 5303: sub standard_css {
1.345 albertel 5304: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5305: $function = &get_users_function() if (!$function);
5306: my $img = &designparm($function.'.img', $domain);
5307: my $tabbg = &designparm($function.'.tabbg', $domain);
5308: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5309: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5310: #second colour for later usage
1.345 albertel 5311: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5312: my $pgbg_or_bgcolor =
5313: $bgcolor ||
1.352 albertel 5314: &designparm($function.'.pgbg', $domain);
1.382 albertel 5315: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5316: my $alink = &designparm($function.'.alink', $domain);
5317: my $vlink = &designparm($function.'.vlink', $domain);
5318: my $link = &designparm($function.'.link', $domain);
5319:
1.602 albertel 5320: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5321: my $mono = 'monospace';
1.850 bisitz 5322: my $data_table_head = $sidebg;
5323: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5324: my $data_table_dark = '#E0E0E0';
1.470 banghart 5325: my $data_table_darker = '#CCCCCC';
1.349 albertel 5326: my $data_table_highlight = '#FFFF00';
1.352 albertel 5327: my $mail_new = '#FFBB77';
5328: my $mail_new_hover = '#DD9955';
5329: my $mail_read = '#BBBB77';
5330: my $mail_read_hover = '#999944';
5331: my $mail_replied = '#AAAA88';
5332: my $mail_replied_hover = '#888855';
5333: my $mail_other = '#99BBBB';
5334: my $mail_other_hover = '#669999';
1.391 albertel 5335: my $table_header = '#DDDDDD';
1.489 raeburn 5336: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5337: my $lg_border_color = '#C8C8C8';
1.952 onken 5338: my $button_hover = '#BF2317';
1.392 albertel 5339:
1.608 albertel 5340: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5341: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5342: : '0 3px 0 4px';
1.448 albertel 5343:
1.523 albertel 5344:
1.343 albertel 5345: return <<END;
1.947 droeschl 5346:
5347: /* needed for iframe to allow 100% height in FF */
5348: body, html {
5349: margin: 0;
5350: padding: 0 0.5%;
5351: height: 99%; /* to avoid scrollbars */
5352: }
5353:
1.795 www 5354: body {
1.911 bisitz 5355: font-family: $sans;
5356: line-height:130%;
5357: font-size:0.83em;
5358: color:$font;
1.795 www 5359: }
5360:
1.959 onken 5361: a:focus,
5362: a:focus img {
1.795 www 5363: color: red;
5364: }
1.698 harmsja 5365:
1.911 bisitz 5366: form, .inline {
5367: display: inline;
1.795 www 5368: }
1.721 harmsja 5369:
1.795 www 5370: .LC_right {
1.911 bisitz 5371: text-align:right;
1.795 www 5372: }
5373:
5374: .LC_middle {
1.911 bisitz 5375: vertical-align:middle;
1.795 www 5376: }
1.721 harmsja 5377:
1.911 bisitz 5378: .LC_400Box {
5379: width:400px;
5380: }
1.721 harmsja 5381:
1.947 droeschl 5382: .LC_iframecontainer {
5383: width: 98%;
5384: margin: 0;
5385: position: fixed;
5386: top: 8.5em;
5387: bottom: 0;
5388: }
5389:
5390: .LC_iframecontainer iframe{
5391: border: none;
5392: width: 100%;
5393: height: 100%;
5394: }
5395:
1.778 bisitz 5396: .LC_filename {
5397: font-family: $mono;
5398: white-space:pre;
1.921 bisitz 5399: font-size: 120%;
1.778 bisitz 5400: }
5401:
5402: .LC_fileicon {
5403: border: none;
5404: height: 1.3em;
5405: vertical-align: text-bottom;
5406: margin-right: 0.3em;
5407: text-decoration:none;
5408: }
5409:
1.1008 www 5410: .LC_setting {
5411: text-decoration:underline;
5412: }
5413:
1.350 albertel 5414: .LC_error {
5415: color: red;
5416: }
1.795 www 5417:
1.1075.2.15 raeburn 5418: .LC_warning {
5419: color: darkorange;
5420: }
5421:
1.457 albertel 5422: .LC_diff_removed {
1.733 bisitz 5423: color: red;
1.394 albertel 5424: }
1.532 albertel 5425:
5426: .LC_info,
1.457 albertel 5427: .LC_success,
5428: .LC_diff_added {
1.350 albertel 5429: color: green;
5430: }
1.795 www 5431:
1.802 bisitz 5432: div.LC_confirm_box {
5433: background-color: #FAFAFA;
5434: border: 1px solid $lg_border_color;
5435: margin-right: 0;
5436: padding: 5px;
5437: }
5438:
5439: div.LC_confirm_box .LC_error img,
5440: div.LC_confirm_box .LC_success img {
5441: vertical-align: middle;
5442: }
5443:
1.440 albertel 5444: .LC_icon {
1.771 droeschl 5445: border: none;
1.790 droeschl 5446: vertical-align: middle;
1.771 droeschl 5447: }
5448:
1.543 albertel 5449: .LC_docs_spacer {
5450: width: 25px;
5451: height: 1px;
1.771 droeschl 5452: border: none;
1.543 albertel 5453: }
1.346 albertel 5454:
1.532 albertel 5455: .LC_internal_info {
1.735 bisitz 5456: color: #999999;
1.532 albertel 5457: }
5458:
1.794 www 5459: .LC_discussion {
1.1050 www 5460: background: $data_table_dark;
1.911 bisitz 5461: border: 1px solid black;
5462: margin: 2px;
1.794 www 5463: }
5464:
5465: .LC_disc_action_left {
1.1050 www 5466: background: $sidebg;
1.911 bisitz 5467: text-align: left;
1.1050 www 5468: padding: 4px;
5469: margin: 2px;
1.794 www 5470: }
5471:
5472: .LC_disc_action_right {
1.1050 www 5473: background: $sidebg;
1.911 bisitz 5474: text-align: right;
1.1050 www 5475: padding: 4px;
5476: margin: 2px;
1.794 www 5477: }
5478:
5479: .LC_disc_new_item {
1.911 bisitz 5480: background: white;
5481: border: 2px solid red;
1.1050 www 5482: margin: 4px;
5483: padding: 4px;
1.794 www 5484: }
5485:
5486: .LC_disc_old_item {
1.911 bisitz 5487: background: white;
1.1050 www 5488: margin: 4px;
5489: padding: 4px;
1.794 www 5490: }
5491:
1.458 albertel 5492: table.LC_pastsubmission {
5493: border: 1px solid black;
5494: margin: 2px;
5495: }
5496:
1.924 bisitz 5497: table#LC_menubuttons {
1.345 albertel 5498: width: 100%;
5499: background: $pgbg;
1.392 albertel 5500: border: 2px;
1.402 albertel 5501: border-collapse: separate;
1.803 bisitz 5502: padding: 0;
1.345 albertel 5503: }
1.392 albertel 5504:
1.801 tempelho 5505: table#LC_title_bar a {
5506: color: $fontmenu;
5507: }
1.836 bisitz 5508:
1.807 droeschl 5509: table#LC_title_bar {
1.819 tempelho 5510: clear: both;
1.836 bisitz 5511: display: none;
1.807 droeschl 5512: }
5513:
1.795 www 5514: table#LC_title_bar,
1.933 droeschl 5515: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5516: table#LC_title_bar.LC_with_remote {
1.359 albertel 5517: width: 100%;
1.392 albertel 5518: border-color: $pgbg;
5519: border-style: solid;
5520: border-width: $border;
1.379 albertel 5521: background: $pgbg;
1.801 tempelho 5522: color: $fontmenu;
1.392 albertel 5523: border-collapse: collapse;
1.803 bisitz 5524: padding: 0;
1.819 tempelho 5525: margin: 0;
1.359 albertel 5526: }
1.795 www 5527:
1.933 droeschl 5528: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5529: margin: 0;
5530: padding: 0;
1.933 droeschl 5531: position: relative;
5532: list-style: none;
1.913 droeschl 5533: }
1.933 droeschl 5534: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5535: display: inline;
5536: }
1.933 droeschl 5537:
5538: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5539: padding: 0;
1.933 droeschl 5540: margin: 0;
5541: float: left;
1.913 droeschl 5542: }
1.933 droeschl 5543: .LC_breadcrumb_tools_tools {
5544: padding: 0;
5545: margin: 0;
1.913 droeschl 5546: float: right;
5547: }
5548:
1.359 albertel 5549: table#LC_title_bar td {
5550: background: $tabbg;
5551: }
1.795 www 5552:
1.911 bisitz 5553: table#LC_menubuttons img {
1.803 bisitz 5554: border: none;
1.346 albertel 5555: }
1.795 www 5556:
1.842 droeschl 5557: .LC_breadcrumbs_component {
1.911 bisitz 5558: float: right;
5559: margin: 0 1em;
1.357 albertel 5560: }
1.842 droeschl 5561: .LC_breadcrumbs_component img {
1.911 bisitz 5562: vertical-align: middle;
1.777 tempelho 5563: }
1.795 www 5564:
1.383 albertel 5565: td.LC_table_cell_checkbox {
5566: text-align: center;
5567: }
1.795 www 5568:
5569: .LC_fontsize_small {
1.911 bisitz 5570: font-size: 70%;
1.705 tempelho 5571: }
5572:
1.844 bisitz 5573: #LC_breadcrumbs {
1.911 bisitz 5574: clear:both;
5575: background: $sidebg;
5576: border-bottom: 1px solid $lg_border_color;
5577: line-height: 2.5em;
1.933 droeschl 5578: overflow: hidden;
1.911 bisitz 5579: margin: 0;
5580: padding: 0;
1.995 raeburn 5581: text-align: left;
1.819 tempelho 5582: }
1.862 bisitz 5583:
1.1075.2.16 raeburn 5584: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5585: clear:both;
5586: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5587: border: 1px solid $sidebg;
1.1075.2.16 raeburn 5588: margin: 0 0 10px 0;
1.966 bisitz 5589: padding: 3px;
1.995 raeburn 5590: text-align: left;
1.822 bisitz 5591: }
5592:
1.795 www 5593: .LC_fontsize_medium {
1.911 bisitz 5594: font-size: 85%;
1.705 tempelho 5595: }
5596:
1.795 www 5597: .LC_fontsize_large {
1.911 bisitz 5598: font-size: 120%;
1.705 tempelho 5599: }
5600:
1.346 albertel 5601: .LC_menubuttons_inline_text {
5602: color: $font;
1.698 harmsja 5603: font-size: 90%;
1.701 harmsja 5604: padding-left:3px;
1.346 albertel 5605: }
5606:
1.934 droeschl 5607: .LC_menubuttons_inline_text img{
5608: vertical-align: middle;
5609: }
5610:
1.1051 www 5611: li.LC_menubuttons_inline_text img {
1.951 onken 5612: cursor:pointer;
1.1002 droeschl 5613: text-decoration: none;
1.951 onken 5614: }
5615:
1.526 www 5616: .LC_menubuttons_link {
5617: text-decoration: none;
5618: }
1.795 www 5619:
1.522 albertel 5620: .LC_menubuttons_category {
1.521 www 5621: color: $font;
1.526 www 5622: background: $pgbg;
1.521 www 5623: font-size: larger;
5624: font-weight: bold;
5625: }
5626:
1.346 albertel 5627: td.LC_menubuttons_text {
1.911 bisitz 5628: color: $font;
1.346 albertel 5629: }
1.706 harmsja 5630:
1.346 albertel 5631: .LC_current_location {
5632: background: $tabbg;
5633: }
1.795 www 5634:
1.938 bisitz 5635: table.LC_data_table {
1.347 albertel 5636: border: 1px solid #000000;
1.402 albertel 5637: border-collapse: separate;
1.426 albertel 5638: border-spacing: 1px;
1.610 albertel 5639: background: $pgbg;
1.347 albertel 5640: }
1.795 www 5641:
1.422 albertel 5642: .LC_data_table_dense {
5643: font-size: small;
5644: }
1.795 www 5645:
1.507 raeburn 5646: table.LC_nested_outer {
5647: border: 1px solid #000000;
1.589 raeburn 5648: border-collapse: collapse;
1.803 bisitz 5649: border-spacing: 0;
1.507 raeburn 5650: width: 100%;
5651: }
1.795 www 5652:
1.879 raeburn 5653: table.LC_innerpickbox,
1.507 raeburn 5654: table.LC_nested {
1.803 bisitz 5655: border: none;
1.589 raeburn 5656: border-collapse: collapse;
1.803 bisitz 5657: border-spacing: 0;
1.507 raeburn 5658: width: 100%;
5659: }
1.795 www 5660:
1.911 bisitz 5661: table.LC_data_table tr th,
5662: table.LC_calendar tr th,
1.879 raeburn 5663: table.LC_prior_tries tr th,
5664: table.LC_innerpickbox tr th {
1.349 albertel 5665: font-weight: bold;
5666: background-color: $data_table_head;
1.801 tempelho 5667: color:$fontmenu;
1.701 harmsja 5668: font-size:90%;
1.347 albertel 5669: }
1.795 www 5670:
1.879 raeburn 5671: table.LC_innerpickbox tr th,
5672: table.LC_innerpickbox tr td {
5673: vertical-align: top;
5674: }
5675:
1.711 raeburn 5676: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5677: background-color: #CCCCCC;
1.711 raeburn 5678: font-weight: bold;
5679: text-align: left;
5680: }
1.795 www 5681:
1.912 bisitz 5682: table.LC_data_table tr.LC_odd_row > td {
5683: background-color: $data_table_light;
5684: padding: 2px;
5685: vertical-align: top;
5686: }
5687:
1.809 bisitz 5688: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5689: background-color: $data_table_light;
1.912 bisitz 5690: vertical-align: top;
5691: }
5692:
5693: table.LC_data_table tr.LC_even_row > td {
5694: background-color: $data_table_dark;
1.425 albertel 5695: padding: 2px;
1.900 bisitz 5696: vertical-align: top;
1.347 albertel 5697: }
1.795 www 5698:
1.809 bisitz 5699: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5700: background-color: $data_table_dark;
1.900 bisitz 5701: vertical-align: top;
1.347 albertel 5702: }
1.795 www 5703:
1.425 albertel 5704: table.LC_data_table tr.LC_data_table_highlight td {
5705: background-color: $data_table_darker;
5706: }
1.795 www 5707:
1.639 raeburn 5708: table.LC_data_table tr td.LC_leftcol_header {
5709: background-color: $data_table_head;
5710: font-weight: bold;
5711: }
1.795 www 5712:
1.451 albertel 5713: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5714: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5715: font-weight: bold;
5716: font-style: italic;
5717: text-align: center;
5718: padding: 8px;
1.347 albertel 5719: }
1.795 www 5720:
1.1075.2.30 raeburn 5721: table.LC_data_table tr.LC_empty_row td,
5722: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5723: background-color: $sidebg;
5724: }
5725:
5726: table.LC_nested tr.LC_empty_row td {
5727: background-color: #FFFFFF;
5728: }
5729:
1.890 droeschl 5730: table.LC_caption {
5731: }
5732:
1.507 raeburn 5733: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5734: padding: 4ex
5735: }
1.795 www 5736:
1.507 raeburn 5737: table.LC_nested_outer tr th {
5738: font-weight: bold;
1.801 tempelho 5739: color:$fontmenu;
1.507 raeburn 5740: background-color: $data_table_head;
1.701 harmsja 5741: font-size: small;
1.507 raeburn 5742: border-bottom: 1px solid #000000;
5743: }
1.795 www 5744:
1.507 raeburn 5745: table.LC_nested_outer tr td.LC_subheader {
5746: background-color: $data_table_head;
5747: font-weight: bold;
5748: font-size: small;
5749: border-bottom: 1px solid #000000;
5750: text-align: right;
1.451 albertel 5751: }
1.795 www 5752:
1.507 raeburn 5753: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5754: background-color: #CCCCCC;
1.451 albertel 5755: font-weight: bold;
5756: font-size: small;
1.507 raeburn 5757: text-align: center;
5758: }
1.795 www 5759:
1.589 raeburn 5760: table.LC_nested tr.LC_info_row td.LC_left_item,
5761: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5762: text-align: left;
1.451 albertel 5763: }
1.795 www 5764:
1.507 raeburn 5765: table.LC_nested td {
1.735 bisitz 5766: background-color: #FFFFFF;
1.451 albertel 5767: font-size: small;
1.507 raeburn 5768: }
1.795 www 5769:
1.507 raeburn 5770: table.LC_nested_outer tr th.LC_right_item,
5771: table.LC_nested tr.LC_info_row td.LC_right_item,
5772: table.LC_nested tr.LC_odd_row td.LC_right_item,
5773: table.LC_nested tr td.LC_right_item {
1.451 albertel 5774: text-align: right;
5775: }
5776:
1.507 raeburn 5777: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5778: background-color: #EEEEEE;
1.451 albertel 5779: }
5780:
1.473 raeburn 5781: table.LC_createuser {
5782: }
5783:
5784: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5785: font-size: small;
1.473 raeburn 5786: }
5787:
5788: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5789: background-color: #CCCCCC;
1.473 raeburn 5790: font-weight: bold;
5791: text-align: center;
5792: }
5793:
1.349 albertel 5794: table.LC_calendar {
5795: border: 1px solid #000000;
5796: border-collapse: collapse;
1.917 raeburn 5797: width: 98%;
1.349 albertel 5798: }
1.795 www 5799:
1.349 albertel 5800: table.LC_calendar_pickdate {
5801: font-size: xx-small;
5802: }
1.795 www 5803:
1.349 albertel 5804: table.LC_calendar tr td {
5805: border: 1px solid #000000;
5806: vertical-align: top;
1.917 raeburn 5807: width: 14%;
1.349 albertel 5808: }
1.795 www 5809:
1.349 albertel 5810: table.LC_calendar tr td.LC_calendar_day_empty {
5811: background-color: $data_table_dark;
5812: }
1.795 www 5813:
1.779 bisitz 5814: table.LC_calendar tr td.LC_calendar_day_current {
5815: background-color: $data_table_highlight;
1.777 tempelho 5816: }
1.795 www 5817:
1.938 bisitz 5818: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5819: background-color: $mail_new;
5820: }
1.795 www 5821:
1.938 bisitz 5822: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5823: background-color: $mail_new_hover;
5824: }
1.795 www 5825:
1.938 bisitz 5826: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5827: background-color: $mail_read;
5828: }
1.795 www 5829:
1.938 bisitz 5830: /*
5831: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5832: background-color: $mail_read_hover;
5833: }
1.938 bisitz 5834: */
1.795 www 5835:
1.938 bisitz 5836: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5837: background-color: $mail_replied;
5838: }
1.795 www 5839:
1.938 bisitz 5840: /*
5841: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5842: background-color: $mail_replied_hover;
5843: }
1.938 bisitz 5844: */
1.795 www 5845:
1.938 bisitz 5846: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5847: background-color: $mail_other;
5848: }
1.795 www 5849:
1.938 bisitz 5850: /*
5851: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5852: background-color: $mail_other_hover;
5853: }
1.938 bisitz 5854: */
1.494 raeburn 5855:
1.777 tempelho 5856: table.LC_data_table tr > td.LC_browser_file,
5857: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5858: background: #AAEE77;
1.389 albertel 5859: }
1.795 www 5860:
1.777 tempelho 5861: table.LC_data_table tr > td.LC_browser_file_locked,
5862: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5863: background: #FFAA99;
1.387 albertel 5864: }
1.795 www 5865:
1.777 tempelho 5866: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5867: background: #888888;
1.779 bisitz 5868: }
1.795 www 5869:
1.777 tempelho 5870: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5871: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5872: background: #F8F866;
1.777 tempelho 5873: }
1.795 www 5874:
1.696 bisitz 5875: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5876: background: #E0E8FF;
1.387 albertel 5877: }
1.696 bisitz 5878:
1.707 bisitz 5879: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5880: /* background: #77FF77; */
1.707 bisitz 5881: }
1.795 www 5882:
1.707 bisitz 5883: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5884: border-right: 8px solid #FFFF77;
1.707 bisitz 5885: }
1.795 www 5886:
1.707 bisitz 5887: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5888: border-right: 8px solid #FFAA77;
1.707 bisitz 5889: }
1.795 www 5890:
1.707 bisitz 5891: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5892: border-right: 8px solid #FF7777;
1.707 bisitz 5893: }
1.795 www 5894:
1.707 bisitz 5895: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5896: border-right: 8px solid #AAFF77;
1.707 bisitz 5897: }
1.795 www 5898:
1.707 bisitz 5899: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5900: border-right: 8px solid #11CC55;
1.707 bisitz 5901: }
5902:
1.388 albertel 5903: span.LC_current_location {
1.701 harmsja 5904: font-size:larger;
1.388 albertel 5905: background: $pgbg;
5906: }
1.387 albertel 5907:
1.1029 www 5908: span.LC_current_nav_location {
5909: font-weight:bold;
5910: background: $sidebg;
5911: }
5912:
1.395 albertel 5913: span.LC_parm_menu_item {
5914: font-size: larger;
5915: }
1.795 www 5916:
1.395 albertel 5917: span.LC_parm_scope_all {
5918: color: red;
5919: }
1.795 www 5920:
1.395 albertel 5921: span.LC_parm_scope_folder {
5922: color: green;
5923: }
1.795 www 5924:
1.395 albertel 5925: span.LC_parm_scope_resource {
5926: color: orange;
5927: }
1.795 www 5928:
1.395 albertel 5929: span.LC_parm_part {
5930: color: blue;
5931: }
1.795 www 5932:
1.911 bisitz 5933: span.LC_parm_folder,
5934: span.LC_parm_symb {
1.395 albertel 5935: font-size: x-small;
5936: font-family: $mono;
5937: color: #AAAAAA;
5938: }
5939:
1.977 bisitz 5940: ul.LC_parm_parmlist li {
5941: display: inline-block;
5942: padding: 0.3em 0.8em;
5943: vertical-align: top;
5944: width: 150px;
5945: border-top:1px solid $lg_border_color;
5946: }
5947:
1.795 www 5948: td.LC_parm_overview_level_menu,
5949: td.LC_parm_overview_map_menu,
5950: td.LC_parm_overview_parm_selectors,
5951: td.LC_parm_overview_restrictions {
1.396 albertel 5952: border: 1px solid black;
5953: border-collapse: collapse;
5954: }
1.795 www 5955:
1.396 albertel 5956: table.LC_parm_overview_restrictions td {
5957: border-width: 1px 4px 1px 4px;
5958: border-style: solid;
5959: border-color: $pgbg;
5960: text-align: center;
5961: }
1.795 www 5962:
1.396 albertel 5963: table.LC_parm_overview_restrictions th {
5964: background: $tabbg;
5965: border-width: 1px 4px 1px 4px;
5966: border-style: solid;
5967: border-color: $pgbg;
5968: }
1.795 www 5969:
1.398 albertel 5970: table#LC_helpmenu {
1.803 bisitz 5971: border: none;
1.398 albertel 5972: height: 55px;
1.803 bisitz 5973: border-spacing: 0;
1.398 albertel 5974: }
5975:
5976: table#LC_helpmenu fieldset legend {
5977: font-size: larger;
5978: }
1.795 www 5979:
1.397 albertel 5980: table#LC_helpmenu_links {
5981: width: 100%;
5982: border: 1px solid black;
5983: background: $pgbg;
1.803 bisitz 5984: padding: 0;
1.397 albertel 5985: border-spacing: 1px;
5986: }
1.795 www 5987:
1.397 albertel 5988: table#LC_helpmenu_links tr td {
5989: padding: 1px;
5990: background: $tabbg;
1.399 albertel 5991: text-align: center;
5992: font-weight: bold;
1.397 albertel 5993: }
1.396 albertel 5994:
1.795 www 5995: table#LC_helpmenu_links a:link,
5996: table#LC_helpmenu_links a:visited,
1.397 albertel 5997: table#LC_helpmenu_links a:active {
5998: text-decoration: none;
5999: color: $font;
6000: }
1.795 www 6001:
1.397 albertel 6002: table#LC_helpmenu_links a:hover {
6003: text-decoration: underline;
6004: color: $vlink;
6005: }
1.396 albertel 6006:
1.417 albertel 6007: .LC_chrt_popup_exists {
6008: border: 1px solid #339933;
6009: margin: -1px;
6010: }
1.795 www 6011:
1.417 albertel 6012: .LC_chrt_popup_up {
6013: border: 1px solid yellow;
6014: margin: -1px;
6015: }
1.795 www 6016:
1.417 albertel 6017: .LC_chrt_popup {
6018: border: 1px solid #8888FF;
6019: background: #CCCCFF;
6020: }
1.795 www 6021:
1.421 albertel 6022: table.LC_pick_box {
6023: border-collapse: separate;
6024: background: white;
6025: border: 1px solid black;
6026: border-spacing: 1px;
6027: }
1.795 www 6028:
1.421 albertel 6029: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6030: background: $sidebg;
1.421 albertel 6031: font-weight: bold;
1.900 bisitz 6032: text-align: left;
1.740 bisitz 6033: vertical-align: top;
1.421 albertel 6034: width: 184px;
6035: padding: 8px;
6036: }
1.795 www 6037:
1.579 raeburn 6038: table.LC_pick_box td.LC_pick_box_value {
6039: text-align: left;
6040: padding: 8px;
6041: }
1.795 www 6042:
1.579 raeburn 6043: table.LC_pick_box td.LC_pick_box_select {
6044: text-align: left;
6045: padding: 8px;
6046: }
1.795 www 6047:
1.424 albertel 6048: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6049: padding: 0;
1.421 albertel 6050: height: 1px;
6051: background: black;
6052: }
1.795 www 6053:
1.421 albertel 6054: table.LC_pick_box td.LC_pick_box_submit {
6055: text-align: right;
6056: }
1.795 www 6057:
1.579 raeburn 6058: table.LC_pick_box td.LC_evenrow_value {
6059: text-align: left;
6060: padding: 8px;
6061: background-color: $data_table_light;
6062: }
1.795 www 6063:
1.579 raeburn 6064: table.LC_pick_box td.LC_oddrow_value {
6065: text-align: left;
6066: padding: 8px;
6067: background-color: $data_table_light;
6068: }
1.795 www 6069:
1.579 raeburn 6070: span.LC_helpform_receipt_cat {
6071: font-weight: bold;
6072: }
1.795 www 6073:
1.424 albertel 6074: table.LC_group_priv_box {
6075: background: white;
6076: border: 1px solid black;
6077: border-spacing: 1px;
6078: }
1.795 www 6079:
1.424 albertel 6080: table.LC_group_priv_box td.LC_pick_box_title {
6081: background: $tabbg;
6082: font-weight: bold;
6083: text-align: right;
6084: width: 184px;
6085: }
1.795 www 6086:
1.424 albertel 6087: table.LC_group_priv_box td.LC_groups_fixed {
6088: background: $data_table_light;
6089: text-align: center;
6090: }
1.795 www 6091:
1.424 albertel 6092: table.LC_group_priv_box td.LC_groups_optional {
6093: background: $data_table_dark;
6094: text-align: center;
6095: }
1.795 www 6096:
1.424 albertel 6097: table.LC_group_priv_box td.LC_groups_functionality {
6098: background: $data_table_darker;
6099: text-align: center;
6100: font-weight: bold;
6101: }
1.795 www 6102:
1.424 albertel 6103: table.LC_group_priv td {
6104: text-align: left;
1.803 bisitz 6105: padding: 0;
1.424 albertel 6106: }
6107:
6108: .LC_navbuttons {
6109: margin: 2ex 0ex 2ex 0ex;
6110: }
1.795 www 6111:
1.423 albertel 6112: .LC_topic_bar {
6113: font-weight: bold;
6114: background: $tabbg;
1.918 wenzelju 6115: margin: 1em 0em 1em 2em;
1.805 bisitz 6116: padding: 3px;
1.918 wenzelju 6117: font-size: 1.2em;
1.423 albertel 6118: }
1.795 www 6119:
1.423 albertel 6120: .LC_topic_bar span {
1.918 wenzelju 6121: left: 0.5em;
6122: position: absolute;
1.423 albertel 6123: vertical-align: middle;
1.918 wenzelju 6124: font-size: 1.2em;
1.423 albertel 6125: }
1.795 www 6126:
1.423 albertel 6127: table.LC_course_group_status {
6128: margin: 20px;
6129: }
1.795 www 6130:
1.423 albertel 6131: table.LC_status_selector td {
6132: vertical-align: top;
6133: text-align: center;
1.424 albertel 6134: padding: 4px;
6135: }
1.795 www 6136:
1.599 albertel 6137: div.LC_feedback_link {
1.616 albertel 6138: clear: both;
1.829 kalberla 6139: background: $sidebg;
1.779 bisitz 6140: width: 100%;
1.829 kalberla 6141: padding-bottom: 10px;
6142: border: 1px $tabbg solid;
1.833 kalberla 6143: height: 22px;
6144: line-height: 22px;
6145: padding-top: 5px;
6146: }
6147:
6148: div.LC_feedback_link img {
6149: height: 22px;
1.867 kalberla 6150: vertical-align:middle;
1.829 kalberla 6151: }
6152:
1.911 bisitz 6153: div.LC_feedback_link a {
1.829 kalberla 6154: text-decoration: none;
1.489 raeburn 6155: }
1.795 www 6156:
1.867 kalberla 6157: div.LC_comblock {
1.911 bisitz 6158: display:inline;
1.867 kalberla 6159: color:$font;
6160: font-size:90%;
6161: }
6162:
6163: div.LC_feedback_link div.LC_comblock {
6164: padding-left:5px;
6165: }
6166:
6167: div.LC_feedback_link div.LC_comblock a {
6168: color:$font;
6169: }
6170:
1.489 raeburn 6171: span.LC_feedback_link {
1.858 bisitz 6172: /* background: $feedback_link_bg; */
1.599 albertel 6173: font-size: larger;
6174: }
1.795 www 6175:
1.599 albertel 6176: span.LC_message_link {
1.858 bisitz 6177: /* background: $feedback_link_bg; */
1.599 albertel 6178: font-size: larger;
6179: position: absolute;
6180: right: 1em;
1.489 raeburn 6181: }
1.421 albertel 6182:
1.515 albertel 6183: table.LC_prior_tries {
1.524 albertel 6184: border: 1px solid #000000;
6185: border-collapse: separate;
6186: border-spacing: 1px;
1.515 albertel 6187: }
1.523 albertel 6188:
1.515 albertel 6189: table.LC_prior_tries td {
1.524 albertel 6190: padding: 2px;
1.515 albertel 6191: }
1.523 albertel 6192:
6193: .LC_answer_correct {
1.795 www 6194: background: lightgreen;
6195: color: darkgreen;
6196: padding: 6px;
1.523 albertel 6197: }
1.795 www 6198:
1.523 albertel 6199: .LC_answer_charged_try {
1.797 www 6200: background: #FFAAAA;
1.795 www 6201: color: darkred;
6202: padding: 6px;
1.523 albertel 6203: }
1.795 www 6204:
1.779 bisitz 6205: .LC_answer_not_charged_try,
1.523 albertel 6206: .LC_answer_no_grade,
6207: .LC_answer_late {
1.795 www 6208: background: lightyellow;
1.523 albertel 6209: color: black;
1.795 www 6210: padding: 6px;
1.523 albertel 6211: }
1.795 www 6212:
1.523 albertel 6213: .LC_answer_previous {
1.795 www 6214: background: lightblue;
6215: color: darkblue;
6216: padding: 6px;
1.523 albertel 6217: }
1.795 www 6218:
1.779 bisitz 6219: .LC_answer_no_message {
1.777 tempelho 6220: background: #FFFFFF;
6221: color: black;
1.795 www 6222: padding: 6px;
1.779 bisitz 6223: }
1.795 www 6224:
1.779 bisitz 6225: .LC_answer_unknown {
6226: background: orange;
6227: color: black;
1.795 www 6228: padding: 6px;
1.777 tempelho 6229: }
1.795 www 6230:
1.529 albertel 6231: span.LC_prior_numerical,
6232: span.LC_prior_string,
6233: span.LC_prior_custom,
6234: span.LC_prior_reaction,
6235: span.LC_prior_math {
1.925 bisitz 6236: font-family: $mono;
1.523 albertel 6237: white-space: pre;
6238: }
6239:
1.525 albertel 6240: span.LC_prior_string {
1.925 bisitz 6241: font-family: $mono;
1.525 albertel 6242: white-space: pre;
6243: }
6244:
1.523 albertel 6245: table.LC_prior_option {
6246: width: 100%;
6247: border-collapse: collapse;
6248: }
1.795 www 6249:
1.911 bisitz 6250: table.LC_prior_rank,
1.795 www 6251: table.LC_prior_match {
1.528 albertel 6252: border-collapse: collapse;
6253: }
1.795 www 6254:
1.528 albertel 6255: table.LC_prior_option tr td,
6256: table.LC_prior_rank tr td,
6257: table.LC_prior_match tr td {
1.524 albertel 6258: border: 1px solid #000000;
1.515 albertel 6259: }
6260:
1.855 bisitz 6261: .LC_nobreak {
1.544 albertel 6262: white-space: nowrap;
1.519 raeburn 6263: }
6264:
1.576 raeburn 6265: span.LC_cusr_emph {
6266: font-style: italic;
6267: }
6268:
1.633 raeburn 6269: span.LC_cusr_subheading {
6270: font-weight: normal;
6271: font-size: 85%;
6272: }
6273:
1.861 bisitz 6274: div.LC_docs_entry_move {
1.859 bisitz 6275: border: 1px solid #BBBBBB;
1.545 albertel 6276: background: #DDDDDD;
1.861 bisitz 6277: width: 22px;
1.859 bisitz 6278: padding: 1px;
6279: margin: 0;
1.545 albertel 6280: }
6281:
1.861 bisitz 6282: table.LC_data_table tr > td.LC_docs_entry_commands,
6283: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6284: font-size: x-small;
6285: }
1.795 www 6286:
1.861 bisitz 6287: .LC_docs_entry_parameter {
6288: white-space: nowrap;
6289: }
6290:
1.544 albertel 6291: .LC_docs_copy {
1.545 albertel 6292: color: #000099;
1.544 albertel 6293: }
1.795 www 6294:
1.544 albertel 6295: .LC_docs_cut {
1.545 albertel 6296: color: #550044;
1.544 albertel 6297: }
1.795 www 6298:
1.544 albertel 6299: .LC_docs_rename {
1.545 albertel 6300: color: #009900;
1.544 albertel 6301: }
1.795 www 6302:
1.544 albertel 6303: .LC_docs_remove {
1.545 albertel 6304: color: #990000;
6305: }
6306:
1.547 albertel 6307: .LC_docs_reinit_warn,
6308: .LC_docs_ext_edit {
6309: font-size: x-small;
6310: }
6311:
1.545 albertel 6312: table.LC_docs_adddocs td,
6313: table.LC_docs_adddocs th {
6314: border: 1px solid #BBBBBB;
6315: padding: 4px;
6316: background: #DDDDDD;
1.543 albertel 6317: }
6318:
1.584 albertel 6319: table.LC_sty_begin {
6320: background: #BBFFBB;
6321: }
1.795 www 6322:
1.584 albertel 6323: table.LC_sty_end {
6324: background: #FFBBBB;
6325: }
6326:
1.589 raeburn 6327: table.LC_double_column {
1.803 bisitz 6328: border-width: 0;
1.589 raeburn 6329: border-collapse: collapse;
6330: width: 100%;
6331: padding: 2px;
6332: }
6333:
6334: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6335: top: 2px;
1.589 raeburn 6336: left: 2px;
6337: width: 47%;
6338: vertical-align: top;
6339: }
6340:
6341: table.LC_double_column tr td.LC_right_col {
6342: top: 2px;
1.779 bisitz 6343: right: 2px;
1.589 raeburn 6344: width: 47%;
6345: vertical-align: top;
6346: }
6347:
1.591 raeburn 6348: div.LC_left_float {
6349: float: left;
6350: padding-right: 5%;
1.597 albertel 6351: padding-bottom: 4px;
1.591 raeburn 6352: }
6353:
6354: div.LC_clear_float_header {
1.597 albertel 6355: padding-bottom: 2px;
1.591 raeburn 6356: }
6357:
6358: div.LC_clear_float_footer {
1.597 albertel 6359: padding-top: 10px;
1.591 raeburn 6360: clear: both;
6361: }
6362:
1.597 albertel 6363: div.LC_grade_show_user {
1.941 bisitz 6364: /* border-left: 5px solid $sidebg; */
6365: border-top: 5px solid #000000;
6366: margin: 50px 0 0 0;
1.936 bisitz 6367: padding: 15px 0 5px 10px;
1.597 albertel 6368: }
1.795 www 6369:
1.936 bisitz 6370: div.LC_grade_show_user_odd_row {
1.941 bisitz 6371: /* border-left: 5px solid #000000; */
6372: }
6373:
6374: div.LC_grade_show_user div.LC_Box {
6375: margin-right: 50px;
1.597 albertel 6376: }
6377:
6378: div.LC_grade_submissions,
6379: div.LC_grade_message_center,
1.936 bisitz 6380: div.LC_grade_info_links {
1.597 albertel 6381: margin: 5px;
6382: width: 99%;
6383: background: #FFFFFF;
6384: }
1.795 www 6385:
1.597 albertel 6386: div.LC_grade_submissions_header,
1.936 bisitz 6387: div.LC_grade_message_center_header {
1.705 tempelho 6388: font-weight: bold;
6389: font-size: large;
1.597 albertel 6390: }
1.795 www 6391:
1.597 albertel 6392: div.LC_grade_submissions_body,
1.936 bisitz 6393: div.LC_grade_message_center_body {
1.597 albertel 6394: border: 1px solid black;
6395: width: 99%;
6396: background: #FFFFFF;
6397: }
1.795 www 6398:
1.613 albertel 6399: table.LC_scantron_action {
6400: width: 100%;
6401: }
1.795 www 6402:
1.613 albertel 6403: table.LC_scantron_action tr th {
1.698 harmsja 6404: font-weight:bold;
6405: font-style:normal;
1.613 albertel 6406: }
1.795 www 6407:
1.779 bisitz 6408: .LC_edit_problem_header,
1.614 albertel 6409: div.LC_edit_problem_footer {
1.705 tempelho 6410: font-weight: normal;
6411: font-size: medium;
1.602 albertel 6412: margin: 2px;
1.1060 bisitz 6413: background-color: $sidebg;
1.600 albertel 6414: }
1.795 www 6415:
1.600 albertel 6416: div.LC_edit_problem_header,
1.602 albertel 6417: div.LC_edit_problem_header div,
1.614 albertel 6418: div.LC_edit_problem_footer,
6419: div.LC_edit_problem_footer div,
1.602 albertel 6420: div.LC_edit_problem_editxml_header,
6421: div.LC_edit_problem_editxml_header div {
1.600 albertel 6422: margin-top: 5px;
6423: }
1.795 www 6424:
1.600 albertel 6425: div.LC_edit_problem_header_title {
1.705 tempelho 6426: font-weight: bold;
6427: font-size: larger;
1.602 albertel 6428: background: $tabbg;
6429: padding: 3px;
1.1060 bisitz 6430: margin: 0 0 5px 0;
1.602 albertel 6431: }
1.795 www 6432:
1.602 albertel 6433: table.LC_edit_problem_header_title {
6434: width: 100%;
1.600 albertel 6435: background: $tabbg;
1.602 albertel 6436: }
6437:
6438: div.LC_edit_problem_discards {
6439: float: left;
6440: padding-bottom: 5px;
6441: }
1.795 www 6442:
1.602 albertel 6443: div.LC_edit_problem_saves {
6444: float: right;
6445: padding-bottom: 5px;
1.600 albertel 6446: }
1.795 www 6447:
1.911 bisitz 6448: img.stift {
1.803 bisitz 6449: border-width: 0;
6450: vertical-align: middle;
1.677 riegler 6451: }
1.680 riegler 6452:
1.923 bisitz 6453: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6454: vertical-align: top;
1.777 tempelho 6455: }
1.795 www 6456:
1.716 raeburn 6457: div.LC_createcourse {
1.911 bisitz 6458: margin: 10px 10px 10px 10px;
1.716 raeburn 6459: }
6460:
1.917 raeburn 6461: .LC_dccid {
6462: margin: 0.2em 0 0 0;
6463: padding: 0;
6464: font-size: 90%;
6465: display:none;
6466: }
6467:
1.897 wenzelju 6468: ol.LC_primary_menu a:hover,
1.721 harmsja 6469: ol#LC_MenuBreadcrumbs a:hover,
6470: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6471: ul#LC_secondary_menu a:hover,
1.721 harmsja 6472: .LC_FormSectionClearButton input:hover
1.795 www 6473: ul.LC_TabContent li:hover a {
1.952 onken 6474: color:$button_hover;
1.911 bisitz 6475: text-decoration:none;
1.693 droeschl 6476: }
6477:
1.779 bisitz 6478: h1 {
1.911 bisitz 6479: padding: 0;
6480: line-height:130%;
1.693 droeschl 6481: }
1.698 harmsja 6482:
1.911 bisitz 6483: h2,
6484: h3,
6485: h4,
6486: h5,
6487: h6 {
6488: margin: 5px 0 5px 0;
6489: padding: 0;
6490: line-height:130%;
1.693 droeschl 6491: }
1.795 www 6492:
6493: .LC_hcell {
1.911 bisitz 6494: padding:3px 15px 3px 15px;
6495: margin: 0;
6496: background-color:$tabbg;
6497: color:$fontmenu;
6498: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6499: }
1.795 www 6500:
1.840 bisitz 6501: .LC_Box > .LC_hcell {
1.911 bisitz 6502: margin: 0 -10px 10px -10px;
1.835 bisitz 6503: }
6504:
1.721 harmsja 6505: .LC_noBorder {
1.911 bisitz 6506: border: 0;
1.698 harmsja 6507: }
1.693 droeschl 6508:
1.721 harmsja 6509: .LC_FormSectionClearButton input {
1.911 bisitz 6510: background-color:transparent;
6511: border: none;
6512: cursor:pointer;
6513: text-decoration:underline;
1.693 droeschl 6514: }
1.763 bisitz 6515:
6516: .LC_help_open_topic {
1.911 bisitz 6517: color: #FFFFFF;
6518: background-color: #EEEEFF;
6519: margin: 1px;
6520: padding: 4px;
6521: border: 1px solid #000033;
6522: white-space: nowrap;
6523: /* vertical-align: middle; */
1.759 neumanie 6524: }
1.693 droeschl 6525:
1.911 bisitz 6526: dl,
6527: ul,
6528: div,
6529: fieldset {
6530: margin: 10px 10px 10px 0;
6531: /* overflow: hidden; */
1.693 droeschl 6532: }
1.795 www 6533:
1.838 bisitz 6534: fieldset > legend {
1.911 bisitz 6535: font-weight: bold;
6536: padding: 0 5px 0 5px;
1.838 bisitz 6537: }
6538:
1.813 bisitz 6539: #LC_nav_bar {
1.911 bisitz 6540: float: left;
1.995 raeburn 6541: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6542: margin: 0 0 2px 0;
1.807 droeschl 6543: }
6544:
1.916 droeschl 6545: #LC_realm {
6546: margin: 0.2em 0 0 0;
6547: padding: 0;
6548: font-weight: bold;
6549: text-align: center;
1.995 raeburn 6550: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6551: }
6552:
1.911 bisitz 6553: #LC_nav_bar em {
6554: font-weight: bold;
6555: font-style: normal;
1.807 droeschl 6556: }
6557:
1.897 wenzelju 6558: ol.LC_primary_menu {
1.911 bisitz 6559: float: right;
1.934 droeschl 6560: margin: 0;
1.1075.2.2 raeburn 6561: padding: 0;
1.995 raeburn 6562: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6563: }
6564:
1.852 droeschl 6565: ol#LC_PathBreadcrumbs {
1.911 bisitz 6566: margin: 0;
1.693 droeschl 6567: }
6568:
1.897 wenzelju 6569: ol.LC_primary_menu li {
1.1075.2.2 raeburn 6570: color: RGB(80, 80, 80);
6571: vertical-align: middle;
6572: text-align: left;
6573: list-style: none;
6574: float: left;
6575: }
6576:
6577: ol.LC_primary_menu li a {
6578: display: block;
6579: margin: 0;
6580: padding: 0 5px 0 10px;
6581: text-decoration: none;
6582: }
6583:
6584: ol.LC_primary_menu li ul {
6585: display: none;
6586: width: 10em;
6587: background-color: $data_table_light;
6588: }
6589:
6590: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6591: display: block;
6592: position: absolute;
6593: margin: 0;
6594: padding: 0;
1.1075.2.5 raeburn 6595: z-index: 2;
1.1075.2.2 raeburn 6596: }
6597:
6598: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6599: font-size: 90%;
1.911 bisitz 6600: vertical-align: top;
1.1075.2.2 raeburn 6601: float: none;
1.1075.2.5 raeburn 6602: border-left: 1px solid black;
6603: border-right: 1px solid black;
1.1075.2.2 raeburn 6604: }
6605:
6606: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5 raeburn 6607: background-color:$data_table_light;
1.1075.2.2 raeburn 6608: }
6609:
6610: ol.LC_primary_menu li li a:hover {
6611: color:$button_hover;
6612: background-color:$data_table_dark;
1.693 droeschl 6613: }
6614:
1.897 wenzelju 6615: ol.LC_primary_menu li img {
1.911 bisitz 6616: vertical-align: bottom;
1.934 droeschl 6617: height: 1.1em;
1.1075.2.3 raeburn 6618: margin: 0.2em 0 0 0;
1.693 droeschl 6619: }
6620:
1.897 wenzelju 6621: ol.LC_primary_menu a {
1.911 bisitz 6622: color: RGB(80, 80, 80);
6623: text-decoration: none;
1.693 droeschl 6624: }
1.795 www 6625:
1.949 droeschl 6626: ol.LC_primary_menu a.LC_new_message {
6627: font-weight:bold;
6628: color: darkred;
6629: }
6630:
1.975 raeburn 6631: ol.LC_docs_parameters {
6632: margin-left: 0;
6633: padding: 0;
6634: list-style: none;
6635: }
6636:
6637: ol.LC_docs_parameters li {
6638: margin: 0;
6639: padding-right: 20px;
6640: display: inline;
6641: }
6642:
1.976 raeburn 6643: ol.LC_docs_parameters li:before {
6644: content: "\\002022 \\0020";
6645: }
6646:
6647: li.LC_docs_parameters_title {
6648: font-weight: bold;
6649: }
6650:
6651: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6652: content: "";
6653: }
6654:
1.897 wenzelju 6655: ul#LC_secondary_menu {
1.1075.2.23 raeburn 6656: clear: right;
1.911 bisitz 6657: color: $fontmenu;
6658: background: $tabbg;
6659: list-style: none;
6660: padding: 0;
6661: margin: 0;
6662: width: 100%;
1.995 raeburn 6663: text-align: left;
1.1075.2.4 raeburn 6664: float: left;
1.808 droeschl 6665: }
6666:
1.897 wenzelju 6667: ul#LC_secondary_menu li {
1.911 bisitz 6668: font-weight: bold;
6669: line-height: 1.8em;
6670: border-right: 1px solid black;
6671: vertical-align: middle;
1.1075.2.4 raeburn 6672: float: left;
6673: }
6674:
6675: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6676: background-color: $data_table_light;
6677: }
6678:
6679: ul#LC_secondary_menu li a {
6680: padding: 0 0.8em;
6681: }
6682:
6683: ul#LC_secondary_menu li ul {
6684: display: none;
6685: }
6686:
6687: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6688: display: block;
6689: position: absolute;
6690: margin: 0;
6691: padding: 0;
6692: list-style:none;
6693: float: none;
6694: background-color: $data_table_light;
1.1075.2.5 raeburn 6695: z-index: 2;
1.1075.2.10 raeburn 6696: margin-left: -1px;
1.1075.2.4 raeburn 6697: }
6698:
6699: ul#LC_secondary_menu li ul li {
6700: font-size: 90%;
6701: vertical-align: top;
6702: border-left: 1px solid black;
6703: border-right: 1px solid black;
1.1075.2.33! raeburn 6704: background-color: $data_table_light;
1.1075.2.4 raeburn 6705: list-style:none;
6706: float: none;
6707: }
6708:
6709: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6710: background-color: $data_table_dark;
1.807 droeschl 6711: }
6712:
1.847 tempelho 6713: ul.LC_TabContent {
1.911 bisitz 6714: display:block;
6715: background: $sidebg;
6716: border-bottom: solid 1px $lg_border_color;
6717: list-style:none;
1.1020 raeburn 6718: margin: -1px -10px 0 -10px;
1.911 bisitz 6719: padding: 0;
1.693 droeschl 6720: }
6721:
1.795 www 6722: ul.LC_TabContent li,
6723: ul.LC_TabContentBigger li {
1.911 bisitz 6724: float:left;
1.741 harmsja 6725: }
1.795 www 6726:
1.897 wenzelju 6727: ul#LC_secondary_menu li a {
1.911 bisitz 6728: color: $fontmenu;
6729: text-decoration: none;
1.693 droeschl 6730: }
1.795 www 6731:
1.721 harmsja 6732: ul.LC_TabContent {
1.952 onken 6733: min-height:20px;
1.721 harmsja 6734: }
1.795 www 6735:
6736: ul.LC_TabContent li {
1.911 bisitz 6737: vertical-align:middle;
1.959 onken 6738: padding: 0 16px 0 10px;
1.911 bisitz 6739: background-color:$tabbg;
6740: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6741: border-left: solid 1px $font;
1.721 harmsja 6742: }
1.795 www 6743:
1.847 tempelho 6744: ul.LC_TabContent .right {
1.911 bisitz 6745: float:right;
1.847 tempelho 6746: }
6747:
1.911 bisitz 6748: ul.LC_TabContent li a,
6749: ul.LC_TabContent li {
6750: color:rgb(47,47,47);
6751: text-decoration:none;
6752: font-size:95%;
6753: font-weight:bold;
1.952 onken 6754: min-height:20px;
6755: }
6756:
1.959 onken 6757: ul.LC_TabContent li a:hover,
6758: ul.LC_TabContent li a:focus {
1.952 onken 6759: color: $button_hover;
1.959 onken 6760: background:none;
6761: outline:none;
1.952 onken 6762: }
6763:
6764: ul.LC_TabContent li:hover {
6765: color: $button_hover;
6766: cursor:pointer;
1.721 harmsja 6767: }
1.795 www 6768:
1.911 bisitz 6769: ul.LC_TabContent li.active {
1.952 onken 6770: color: $font;
1.911 bisitz 6771: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6772: border-bottom:solid 1px #FFFFFF;
6773: cursor: default;
1.744 ehlerst 6774: }
1.795 www 6775:
1.959 onken 6776: ul.LC_TabContent li.active a {
6777: color:$font;
6778: background:#FFFFFF;
6779: outline: none;
6780: }
1.1047 raeburn 6781:
6782: ul.LC_TabContent li.goback {
6783: float: left;
6784: border-left: none;
6785: }
6786:
1.870 tempelho 6787: #maincoursedoc {
1.911 bisitz 6788: clear:both;
1.870 tempelho 6789: }
6790:
6791: ul.LC_TabContentBigger {
1.911 bisitz 6792: display:block;
6793: list-style:none;
6794: padding: 0;
1.870 tempelho 6795: }
6796:
1.795 www 6797: ul.LC_TabContentBigger li {
1.911 bisitz 6798: vertical-align:bottom;
6799: height: 30px;
6800: font-size:110%;
6801: font-weight:bold;
6802: color: #737373;
1.841 tempelho 6803: }
6804:
1.957 onken 6805: ul.LC_TabContentBigger li.active {
6806: position: relative;
6807: top: 1px;
6808: }
6809:
1.870 tempelho 6810: ul.LC_TabContentBigger li a {
1.911 bisitz 6811: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6812: height: 30px;
6813: line-height: 30px;
6814: text-align: center;
6815: display: block;
6816: text-decoration: none;
1.958 onken 6817: outline: none;
1.741 harmsja 6818: }
1.795 www 6819:
1.870 tempelho 6820: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6821: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6822: color:$font;
1.744 ehlerst 6823: }
1.795 www 6824:
1.870 tempelho 6825: ul.LC_TabContentBigger li b {
1.911 bisitz 6826: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6827: display: block;
6828: float: left;
6829: padding: 0 30px;
1.957 onken 6830: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6831: }
6832:
1.956 onken 6833: ul.LC_TabContentBigger li:hover b {
6834: color:$button_hover;
6835: }
6836:
1.870 tempelho 6837: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6838: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6839: color:$font;
1.957 onken 6840: border: 0;
1.741 harmsja 6841: }
1.693 droeschl 6842:
1.870 tempelho 6843:
1.862 bisitz 6844: ul.LC_CourseBreadcrumbs {
6845: background: $sidebg;
1.1020 raeburn 6846: height: 2em;
1.862 bisitz 6847: padding-left: 10px;
1.1020 raeburn 6848: margin: 0;
1.862 bisitz 6849: list-style-position: inside;
6850: }
6851:
1.911 bisitz 6852: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6853: ol#LC_PathBreadcrumbs {
1.911 bisitz 6854: padding-left: 10px;
6855: margin: 0;
1.933 droeschl 6856: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6857: }
6858:
1.911 bisitz 6859: ol#LC_MenuBreadcrumbs li,
6860: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6861: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6862: display: inline;
1.933 droeschl 6863: white-space: normal;
1.693 droeschl 6864: }
6865:
1.823 bisitz 6866: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6867: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6868: text-decoration: none;
6869: font-size:90%;
1.693 droeschl 6870: }
1.795 www 6871:
1.969 droeschl 6872: ol#LC_MenuBreadcrumbs h1 {
6873: display: inline;
6874: font-size: 90%;
6875: line-height: 2.5em;
6876: margin: 0;
6877: padding: 0;
6878: }
6879:
1.795 www 6880: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6881: text-decoration:none;
6882: font-size:100%;
6883: font-weight:bold;
1.693 droeschl 6884: }
1.795 www 6885:
1.840 bisitz 6886: .LC_Box {
1.911 bisitz 6887: border: solid 1px $lg_border_color;
6888: padding: 0 10px 10px 10px;
1.746 neumanie 6889: }
1.795 www 6890:
1.1020 raeburn 6891: .LC_DocsBox {
6892: border: solid 1px $lg_border_color;
6893: padding: 0 0 10px 10px;
6894: }
6895:
1.795 www 6896: .LC_AboutMe_Image {
1.911 bisitz 6897: float:left;
6898: margin-right:10px;
1.747 neumanie 6899: }
1.795 www 6900:
6901: .LC_Clear_AboutMe_Image {
1.911 bisitz 6902: clear:left;
1.747 neumanie 6903: }
1.795 www 6904:
1.721 harmsja 6905: dl.LC_ListStyleClean dt {
1.911 bisitz 6906: padding-right: 5px;
6907: display: table-header-group;
1.693 droeschl 6908: }
6909:
1.721 harmsja 6910: dl.LC_ListStyleClean dd {
1.911 bisitz 6911: display: table-row;
1.693 droeschl 6912: }
6913:
1.721 harmsja 6914: .LC_ListStyleClean,
6915: .LC_ListStyleSimple,
6916: .LC_ListStyleNormal,
1.795 www 6917: .LC_ListStyleSpecial {
1.911 bisitz 6918: /* display:block; */
6919: list-style-position: inside;
6920: list-style-type: none;
6921: overflow: hidden;
6922: padding: 0;
1.693 droeschl 6923: }
6924:
1.721 harmsja 6925: .LC_ListStyleSimple li,
6926: .LC_ListStyleSimple dd,
6927: .LC_ListStyleNormal li,
6928: .LC_ListStyleNormal dd,
6929: .LC_ListStyleSpecial li,
1.795 www 6930: .LC_ListStyleSpecial dd {
1.911 bisitz 6931: margin: 0;
6932: padding: 5px 5px 5px 10px;
6933: clear: both;
1.693 droeschl 6934: }
6935:
1.721 harmsja 6936: .LC_ListStyleClean li,
6937: .LC_ListStyleClean dd {
1.911 bisitz 6938: padding-top: 0;
6939: padding-bottom: 0;
1.693 droeschl 6940: }
6941:
1.721 harmsja 6942: .LC_ListStyleSimple dd,
1.795 www 6943: .LC_ListStyleSimple li {
1.911 bisitz 6944: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6945: }
6946:
1.721 harmsja 6947: .LC_ListStyleSpecial li,
6948: .LC_ListStyleSpecial dd {
1.911 bisitz 6949: list-style-type: none;
6950: background-color: RGB(220, 220, 220);
6951: margin-bottom: 4px;
1.693 droeschl 6952: }
6953:
1.721 harmsja 6954: table.LC_SimpleTable {
1.911 bisitz 6955: margin:5px;
6956: border:solid 1px $lg_border_color;
1.795 www 6957: }
1.693 droeschl 6958:
1.721 harmsja 6959: table.LC_SimpleTable tr {
1.911 bisitz 6960: padding: 0;
6961: border:solid 1px $lg_border_color;
1.693 droeschl 6962: }
1.795 www 6963:
6964: table.LC_SimpleTable thead {
1.911 bisitz 6965: background:rgb(220,220,220);
1.693 droeschl 6966: }
6967:
1.721 harmsja 6968: div.LC_columnSection {
1.911 bisitz 6969: display: block;
6970: clear: both;
6971: overflow: hidden;
6972: margin: 0;
1.693 droeschl 6973: }
6974:
1.721 harmsja 6975: div.LC_columnSection>* {
1.911 bisitz 6976: float: left;
6977: margin: 10px 20px 10px 0;
6978: overflow:hidden;
1.693 droeschl 6979: }
1.721 harmsja 6980:
1.795 www 6981: table em {
1.911 bisitz 6982: font-weight: bold;
6983: font-style: normal;
1.748 schulted 6984: }
1.795 www 6985:
1.779 bisitz 6986: table.LC_tableBrowseRes,
1.795 www 6987: table.LC_tableOfContent {
1.911 bisitz 6988: border:none;
6989: border-spacing: 1px;
6990: padding: 3px;
6991: background-color: #FFFFFF;
6992: font-size: 90%;
1.753 droeschl 6993: }
1.789 droeschl 6994:
1.911 bisitz 6995: table.LC_tableOfContent {
6996: border-collapse: collapse;
1.789 droeschl 6997: }
6998:
1.771 droeschl 6999: table.LC_tableBrowseRes a,
1.768 schulted 7000: table.LC_tableOfContent a {
1.911 bisitz 7001: background-color: transparent;
7002: text-decoration: none;
1.753 droeschl 7003: }
7004:
1.795 www 7005: table.LC_tableOfContent img {
1.911 bisitz 7006: border: none;
7007: height: 1.3em;
7008: vertical-align: text-bottom;
7009: margin-right: 0.3em;
1.753 droeschl 7010: }
1.757 schulted 7011:
1.795 www 7012: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7013: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7014: }
7015:
1.795 www 7016: a#LC_content_toolbar_everything {
1.911 bisitz 7017: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7018: }
7019:
1.795 www 7020: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7021: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7022: }
7023:
1.795 www 7024: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7025: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7026: }
7027:
1.795 www 7028: a#LC_content_toolbar_changefolder {
1.911 bisitz 7029: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7030: }
7031:
1.795 www 7032: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7033: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7034: }
7035:
1.1043 raeburn 7036: a#LC_content_toolbar_edittoplevel {
7037: background-image:url(/res/adm/pages/edittoplevel.gif);
7038: }
7039:
1.795 www 7040: ul#LC_toolbar li a:hover {
1.911 bisitz 7041: background-position: bottom center;
1.757 schulted 7042: }
7043:
1.795 www 7044: ul#LC_toolbar {
1.911 bisitz 7045: padding: 0;
7046: margin: 2px;
7047: list-style:none;
7048: position:relative;
7049: background-color:white;
1.1075.2.9 raeburn 7050: overflow: auto;
1.757 schulted 7051: }
7052:
1.795 www 7053: ul#LC_toolbar li {
1.911 bisitz 7054: border:1px solid white;
7055: padding: 0;
7056: margin: 0;
7057: float: left;
7058: display:inline;
7059: vertical-align:middle;
1.1075.2.9 raeburn 7060: white-space: nowrap;
1.911 bisitz 7061: }
1.757 schulted 7062:
1.783 amueller 7063:
1.795 www 7064: a.LC_toolbarItem {
1.911 bisitz 7065: display:block;
7066: padding: 0;
7067: margin: 0;
7068: height: 32px;
7069: width: 32px;
7070: color:white;
7071: border: none;
7072: background-repeat:no-repeat;
7073: background-color:transparent;
1.757 schulted 7074: }
7075:
1.915 droeschl 7076: ul.LC_funclist {
7077: margin: 0;
7078: padding: 0.5em 1em 0.5em 0;
7079: }
7080:
1.933 droeschl 7081: ul.LC_funclist > li:first-child {
7082: font-weight:bold;
7083: margin-left:0.8em;
7084: }
7085:
1.915 droeschl 7086: ul.LC_funclist + ul.LC_funclist {
7087: /*
7088: left border as a seperator if we have more than
7089: one list
7090: */
7091: border-left: 1px solid $sidebg;
7092: /*
7093: this hides the left border behind the border of the
7094: outer box if element is wrapped to the next 'line'
7095: */
7096: margin-left: -1px;
7097: }
7098:
1.843 bisitz 7099: ul.LC_funclist li {
1.915 droeschl 7100: display: inline;
1.782 bisitz 7101: white-space: nowrap;
1.915 droeschl 7102: margin: 0 0 0 25px;
7103: line-height: 150%;
1.782 bisitz 7104: }
7105:
1.974 wenzelju 7106: .LC_hidden {
7107: display: none;
7108: }
7109:
1.1030 www 7110: .LCmodal-overlay {
7111: position:fixed;
7112: top:0;
7113: right:0;
7114: bottom:0;
7115: left:0;
7116: height:100%;
7117: width:100%;
7118: margin:0;
7119: padding:0;
7120: background:#999;
7121: opacity:.75;
7122: filter: alpha(opacity=75);
7123: -moz-opacity: 0.75;
7124: z-index:101;
7125: }
7126:
7127: * html .LCmodal-overlay {
7128: position: absolute;
7129: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7130: }
7131:
7132: .LCmodal-window {
7133: position:fixed;
7134: top:50%;
7135: left:50%;
7136: margin:0;
7137: padding:0;
7138: z-index:102;
7139: }
7140:
7141: * html .LCmodal-window {
7142: position:absolute;
7143: }
7144:
7145: .LCclose-window {
7146: position:absolute;
7147: width:32px;
7148: height:32px;
7149: right:8px;
7150: top:8px;
7151: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7152: text-indent:-99999px;
7153: overflow:hidden;
7154: cursor:pointer;
7155: }
7156:
1.1075.2.17 raeburn 7157: /*
7158: styles used by TTH when "Default set of options to pass to tth/m
7159: when converting TeX" in course settings has been set
7160:
7161: option passed: -t
7162:
7163: */
7164:
7165: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7166: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7167: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7168: td div.norm {line-height:normal;}
7169:
7170: /*
7171: option passed -y3
7172: */
7173:
7174: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7175: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7176: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7177:
1.343 albertel 7178: END
7179: }
7180:
1.306 albertel 7181: =pod
7182:
7183: =item * &headtag()
7184:
7185: Returns a uniform footer for LON-CAPA web pages.
7186:
1.307 albertel 7187: Inputs: $title - optional title for the head
7188: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7189: $args - optional arguments
1.319 albertel 7190: force_register - if is true call registerurl so the remote is
7191: informed
1.415 albertel 7192: redirect -> array ref of
7193: 1- seconds before redirect occurs
7194: 2- url to redirect to
7195: 3- whether the side effect should occur
1.315 albertel 7196: (side effect of setting
7197: $env{'internal.head.redirect'} to the url
7198: redirected too)
1.352 albertel 7199: domain -> force to color decorate a page for a specific
7200: domain
7201: function -> force usage of a specific rolish color scheme
7202: bgcolor -> override the default page bgcolor
1.460 albertel 7203: no_auto_mt_title
7204: -> prevent &mt()ing the title arg
1.464 albertel 7205:
1.306 albertel 7206: =cut
7207:
7208: sub headtag {
1.313 albertel 7209: my ($title,$head_extra,$args) = @_;
1.306 albertel 7210:
1.363 albertel 7211: my $function = $args->{'function'} || &get_users_function();
7212: my $domain = $args->{'domain'} || &determinedomain();
7213: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 7214: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7215: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7216: #time(),
1.418 albertel 7217: $env{'environment.color.timestamp'},
1.363 albertel 7218: $function,$domain,$bgcolor);
7219:
1.369 www 7220: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7221:
1.308 albertel 7222: my $result =
7223: '<head>'.
1.461 albertel 7224: &font_settings();
1.319 albertel 7225:
1.1064 raeburn 7226: my $inhibitprint = &print_suppression();
7227:
1.461 albertel 7228: if (!$args->{'frameset'}) {
7229: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7230: }
1.1075.2.12 raeburn 7231: if ($args->{'force_register'}) {
7232: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7233: }
1.436 albertel 7234: if (!$args->{'no_nav_bar'}
7235: && !$args->{'only_body'}
7236: && !$args->{'frameset'}) {
7237: $result .= &help_menu_js();
1.1032 www 7238: $result.=&modal_window();
1.1038 www 7239: $result.=&togglebox_script();
1.1034 www 7240: $result.=&wishlist_window();
1.1041 www 7241: $result.=&LCprogressbarUpdate_script();
1.1034 www 7242: } else {
7243: if ($args->{'add_modal'}) {
7244: $result.=&modal_window();
7245: }
7246: if ($args->{'add_wishlist'}) {
7247: $result.=&wishlist_window();
7248: }
1.1038 www 7249: if ($args->{'add_togglebox'}) {
7250: $result.=&togglebox_script();
7251: }
1.1041 www 7252: if ($args->{'add_progressbar'}) {
7253: $result.=&LCprogressbarUpdate_script();
7254: }
1.436 albertel 7255: }
1.314 albertel 7256: if (ref($args->{'redirect'})) {
1.414 albertel 7257: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7258: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7259: if (!$inhibit_continue) {
7260: $env{'internal.head.redirect'} = $url;
7261: }
1.313 albertel 7262: $result.=<<ADDMETA
7263: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7264: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7265: ADDMETA
7266: }
1.306 albertel 7267: if (!defined($title)) {
7268: $title = 'The LearningOnline Network with CAPA';
7269: }
1.460 albertel 7270: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7271: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 7272: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064 raeburn 7273: .$inhibitprint
1.414 albertel 7274: .$head_extra;
1.962 droeschl 7275: return $result.'</head>';
1.306 albertel 7276: }
7277:
7278: =pod
7279:
1.340 albertel 7280: =item * &font_settings()
7281:
7282: Returns neccessary <meta> to set the proper encoding
7283:
7284: Inputs: none
7285:
7286: =cut
7287:
7288: sub font_settings {
7289: my $headerstring='';
1.647 www 7290: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 7291: $headerstring.=
7292: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
7293: }
7294: return $headerstring;
7295: }
7296:
1.341 albertel 7297: =pod
7298:
1.1064 raeburn 7299: =item * &print_suppression()
7300:
7301: In course context returns css which causes the body to be blank when media="print",
7302: if printout generation is unavailable for the current resource.
7303:
7304: This could be because:
7305:
7306: (a) printstartdate is in the future
7307:
7308: (b) printenddate is in the past
7309:
7310: (c) there is an active exam block with "printout"
7311: functionality blocked
7312:
7313: Users with pav, pfo or evb privileges are exempt.
7314:
7315: Inputs: none
7316:
7317: =cut
7318:
7319:
7320: sub print_suppression {
7321: my $noprint;
7322: if ($env{'request.course.id'}) {
7323: my $scope = $env{'request.course.id'};
7324: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7325: (&Apache::lonnet::allowed('pfo',$scope))) {
7326: return;
7327: }
7328: if ($env{'request.course.sec'} ne '') {
7329: $scope .= "/$env{'request.course.sec'}";
7330: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7331: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7332: return;
1.1064 raeburn 7333: }
7334: }
7335: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7336: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7337: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7338: if ($blocked) {
7339: my $checkrole = "cm./$cdom/$cnum";
7340: if ($env{'request.course.sec'} ne '') {
7341: $checkrole .= "/$env{'request.course.sec'}";
7342: }
7343: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7344: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7345: $noprint = 1;
7346: }
7347: }
7348: unless ($noprint) {
7349: my $symb = &Apache::lonnet::symbread();
7350: if ($symb ne '') {
7351: my $navmap = Apache::lonnavmaps::navmap->new();
7352: if (ref($navmap)) {
7353: my $res = $navmap->getBySymb($symb);
7354: if (ref($res)) {
7355: if (!$res->resprintable()) {
7356: $noprint = 1;
7357: }
7358: }
7359: }
7360: }
7361: }
7362: if ($noprint) {
7363: return <<"ENDSTYLE";
7364: <style type="text/css" media="print">
7365: body { display:none }
7366: </style>
7367: ENDSTYLE
7368: }
7369: }
7370: return;
7371: }
7372:
7373: =pod
7374:
1.341 albertel 7375: =item * &xml_begin()
7376:
7377: Returns the needed doctype and <html>
7378:
7379: Inputs: none
7380:
7381: =cut
7382:
7383: sub xml_begin {
7384: my $output='';
7385:
7386: if ($env{'browser.mathml'}) {
7387: $output='<?xml version="1.0"?>'
7388: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7389: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7390:
7391: # .'<!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">] >'
7392: .'<!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">'
7393: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7394: .'xmlns="http://www.w3.org/1999/xhtml">';
7395: } else {
1.849 bisitz 7396: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
7397: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 7398: }
7399: return $output;
7400: }
1.340 albertel 7401:
7402: =pod
7403:
1.306 albertel 7404: =item * &start_page()
7405:
7406: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7407:
1.648 raeburn 7408: Inputs:
7409:
7410: =over 4
7411:
7412: $title - optional title for the page
7413:
7414: $head_extra - optional extra HTML to incude inside the <head>
7415:
7416: $args - additional optional args supported are:
7417:
7418: =over 8
7419:
7420: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7421: arg on
1.814 bisitz 7422: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7423: add_entries -> additional attributes to add to the <body>
7424: domain -> force to color decorate a page for a
1.317 albertel 7425: specific domain
1.648 raeburn 7426: function -> force usage of a specific rolish color
1.317 albertel 7427: scheme
1.648 raeburn 7428: redirect -> see &headtag()
7429: bgcolor -> override the default page bg color
7430: js_ready -> return a string ready for being used in
1.317 albertel 7431: a javascript writeln
1.648 raeburn 7432: html_encode -> return a string ready for being used in
1.320 albertel 7433: a html attribute
1.648 raeburn 7434: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7435: $forcereg arg
1.648 raeburn 7436: frameset -> if true will start with a <frameset>
1.330 albertel 7437: rather than <body>
1.648 raeburn 7438: skip_phases -> hash ref of
1.338 albertel 7439: head -> skip the <html><head> generation
7440: body -> skip all <body> generation
1.1075.2.12 raeburn 7441: no_inline_link -> if true and in remote mode, don't show the
7442: 'Switch To Inline Menu' link
1.648 raeburn 7443: no_auto_mt_title -> prevent &mt()ing the title arg
7444: inherit_jsmath -> when creating popup window in a page,
7445: should it have jsmath forced on by the
7446: current page
1.867 kalberla 7447: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7448: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7449: group -> includes the current group, if page is for a
7450: specific group
1.361 albertel 7451:
1.648 raeburn 7452: =back
1.460 albertel 7453:
1.648 raeburn 7454: =back
1.562 albertel 7455:
1.306 albertel 7456: =cut
7457:
7458: sub start_page {
1.309 albertel 7459: my ($title,$head_extra,$args) = @_;
1.318 albertel 7460: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7461:
1.315 albertel 7462: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7463: my ($result,@advtools);
1.964 droeschl 7464:
1.338 albertel 7465: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7466: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7467: }
7468:
7469: if (! exists($args->{'skip_phases'}{'body'}) ) {
7470: if ($args->{'frameset'}) {
7471: my $attr_string = &make_attr_string($args->{'force_register'},
7472: $args->{'add_entries'});
7473: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7474: } else {
7475: $result .=
7476: &bodytag($title,
7477: $args->{'function'}, $args->{'add_entries'},
7478: $args->{'only_body'}, $args->{'domain'},
7479: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7480: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7481: $args, \@advtools);
1.831 bisitz 7482: }
1.330 albertel 7483: }
1.338 albertel 7484:
1.315 albertel 7485: if ($args->{'js_ready'}) {
1.713 kaisler 7486: $result = &js_ready($result);
1.315 albertel 7487: }
1.320 albertel 7488: if ($args->{'html_encode'}) {
1.713 kaisler 7489: $result = &html_encode($result);
7490: }
7491:
1.813 bisitz 7492: # Preparation for new and consistent functionlist at top of screen
7493: # if ($args->{'functionlist'}) {
7494: # $result .= &build_functionlist();
7495: #}
7496:
1.964 droeschl 7497: # Don't add anything more if only_body wanted or in const space
7498: return $result if $args->{'only_body'}
7499: || $env{'request.state'} eq 'construct';
1.813 bisitz 7500:
7501: #Breadcrumbs
1.758 kaisler 7502: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7503: &Apache::lonhtmlcommon::clear_breadcrumbs();
7504: #if any br links exists, add them to the breadcrumbs
7505: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7506: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7507: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7508: }
7509: }
1.1075.2.19 raeburn 7510: # if @advtools array contains items add then to the breadcrumbs
7511: if (@advtools > 0) {
7512: &Apache::lonmenu::advtools_crumbs(@advtools);
7513: }
1.758 kaisler 7514:
7515: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7516: if(exists($args->{'bread_crumbs_component'})){
7517: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7518: }else{
7519: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7520: }
1.1075.2.24 raeburn 7521: } elsif (($env{'environment.remote'} eq 'on') &&
7522: ($env{'form.inhibitmenu'} ne 'yes') &&
7523: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7524: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7525: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7526: }
1.315 albertel 7527: return $result;
1.306 albertel 7528: }
7529:
7530: sub end_page {
1.315 albertel 7531: my ($args) = @_;
7532: $env{'internal.end_page'}++;
1.330 albertel 7533: my $result;
1.335 albertel 7534: if ($args->{'discussion'}) {
7535: my ($target,$parser);
7536: if (ref($args->{'discussion'})) {
7537: ($target,$parser) =($args->{'discussion'}{'target'},
7538: $args->{'discussion'}{'parser'});
7539: }
7540: $result .= &Apache::lonxml::xmlend($target,$parser);
7541: }
1.330 albertel 7542: if ($args->{'frameset'}) {
7543: $result .= '</frameset>';
7544: } else {
1.635 raeburn 7545: $result .= &endbodytag($args);
1.330 albertel 7546: }
1.1075.2.6 raeburn 7547: unless ($args->{'notbody'}) {
7548: $result .= "\n</html>";
7549: }
1.330 albertel 7550:
1.315 albertel 7551: if ($args->{'js_ready'}) {
1.317 albertel 7552: $result = &js_ready($result);
1.315 albertel 7553: }
1.335 albertel 7554:
1.320 albertel 7555: if ($args->{'html_encode'}) {
7556: $result = &html_encode($result);
7557: }
1.335 albertel 7558:
1.315 albertel 7559: return $result;
7560: }
7561:
1.1034 www 7562: sub wishlist_window {
7563: return(<<'ENDWISHLIST');
1.1046 raeburn 7564: <script type="text/javascript">
1.1034 www 7565: // <![CDATA[
7566: // <!-- BEGIN LON-CAPA Internal
7567: function set_wishlistlink(title, path) {
7568: if (!title) {
7569: title = document.title;
7570: title = title.replace(/^LON-CAPA /,'');
7571: }
7572: if (!path) {
7573: path = location.pathname;
7574: }
7575: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7576: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7577: }
7578: // END LON-CAPA Internal -->
7579: // ]]>
7580: </script>
7581: ENDWISHLIST
7582: }
7583:
1.1030 www 7584: sub modal_window {
7585: return(<<'ENDMODAL');
1.1046 raeburn 7586: <script type="text/javascript">
1.1030 www 7587: // <![CDATA[
7588: // <!-- BEGIN LON-CAPA Internal
7589: var modalWindow = {
7590: parent:"body",
7591: windowId:null,
7592: content:null,
7593: width:null,
7594: height:null,
7595: close:function()
7596: {
7597: $(".LCmodal-window").remove();
7598: $(".LCmodal-overlay").remove();
7599: },
7600: open:function()
7601: {
7602: var modal = "";
7603: modal += "<div class=\"LCmodal-overlay\"></div>";
7604: 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;\">";
7605: modal += this.content;
7606: modal += "</div>";
7607:
7608: $(this.parent).append(modal);
7609:
7610: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7611: $(".LCclose-window").click(function(){modalWindow.close();});
7612: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7613: }
7614: };
1.1031 www 7615: var openMyModal = function(source,width,height,scrolling)
1.1030 www 7616: {
7617: modalWindow.windowId = "myModal";
7618: modalWindow.width = width;
7619: modalWindow.height = height;
1.1031 www 7620: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='true' src='" + source + "'></iframe>";
1.1030 www 7621: modalWindow.open();
7622: };
7623: // END LON-CAPA Internal -->
7624: // ]]>
7625: </script>
7626: ENDMODAL
7627: }
7628:
7629: sub modal_link {
1.1052 www 7630: my ($link,$linktext,$width,$height,$target,$scrolling,$title)=@_;
1.1030 www 7631: unless ($width) { $width=480; }
7632: unless ($height) { $height=400; }
1.1031 www 7633: unless ($scrolling) { $scrolling='yes'; }
1.1074 raeburn 7634: my $target_attr;
7635: if (defined($target)) {
7636: $target_attr = 'target="'.$target.'"';
7637: }
7638: return <<"ENDLINK";
7639: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling'); return false;">
7640: $linktext</a>
7641: ENDLINK
1.1030 www 7642: }
7643:
1.1032 www 7644: sub modal_adhoc_script {
7645: my ($funcname,$width,$height,$content)=@_;
7646: return (<<ENDADHOC);
1.1046 raeburn 7647: <script type="text/javascript">
1.1032 www 7648: // <![CDATA[
7649: var $funcname = function()
7650: {
7651: modalWindow.windowId = "myModal";
7652: modalWindow.width = $width;
7653: modalWindow.height = $height;
7654: modalWindow.content = '$content';
7655: modalWindow.open();
7656: };
7657: // ]]>
7658: </script>
7659: ENDADHOC
7660: }
7661:
1.1041 www 7662: sub modal_adhoc_inner {
7663: my ($funcname,$width,$height,$content)=@_;
7664: my $innerwidth=$width-20;
7665: $content=&js_ready(
1.1042 www 7666: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1041 www 7667: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px').
7668: $content.
7669: &end_scrollbox().
7670: &end_page()
7671: );
7672: return &modal_adhoc_script($funcname,$width,$height,$content);
7673: }
7674:
7675: sub modal_adhoc_window {
7676: my ($funcname,$width,$height,$content,$linktext)=@_;
7677: return &modal_adhoc_inner($funcname,$width,$height,$content).
7678: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7679: }
7680:
7681: sub modal_adhoc_launch {
7682: my ($funcname,$width,$height,$content)=@_;
7683: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7684: <script type="text/javascript">
7685: // <![CDATA[
7686: $funcname();
7687: // ]]>
7688: </script>
7689: ENDLAUNCH
7690: }
7691:
7692: sub modal_adhoc_close {
7693: return (<<ENDCLOSE);
7694: <script type="text/javascript">
7695: // <![CDATA[
7696: modalWindow.close();
7697: // ]]>
7698: </script>
7699: ENDCLOSE
7700: }
7701:
1.1038 www 7702: sub togglebox_script {
7703: return(<<ENDTOGGLE);
7704: <script type="text/javascript">
7705: // <![CDATA[
7706: function LCtoggleDisplay(id,hidetext,showtext) {
7707: link = document.getElementById(id + "link").childNodes[0];
7708: with (document.getElementById(id).style) {
7709: if (display == "none" ) {
7710: display = "inline";
7711: link.nodeValue = hidetext;
7712: } else {
7713: display = "none";
7714: link.nodeValue = showtext;
7715: }
7716: }
7717: }
7718: // ]]>
7719: </script>
7720: ENDTOGGLE
7721: }
7722:
1.1039 www 7723: sub start_togglebox {
7724: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7725: unless ($heading) { $heading=''; } else { $heading.=' '; }
7726: unless ($showtext) { $showtext=&mt('show'); }
7727: unless ($hidetext) { $hidetext=&mt('hide'); }
7728: unless ($headerbg) { $headerbg='#FFFFFF'; }
7729: return &start_data_table().
7730: &start_data_table_header_row().
7731: '<td bgcolor="'.$headerbg.'">'.$heading.
7732: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7733: $showtext.'\')">'.$showtext.'</a>]</td>'.
7734: &end_data_table_header_row().
7735: '<tr id="'.$id.'" style="display:none""><td>';
7736: }
7737:
7738: sub end_togglebox {
7739: return '</td></tr>'.&end_data_table();
7740: }
7741:
1.1041 www 7742: sub LCprogressbar_script {
1.1045 www 7743: my ($id)=@_;
1.1041 www 7744: return(<<ENDPROGRESS);
7745: <script type="text/javascript">
7746: // <![CDATA[
1.1045 www 7747: \$('#progressbar$id').progressbar({
1.1041 www 7748: value: 0,
7749: change: function(event, ui) {
7750: var newVal = \$(this).progressbar('option', 'value');
7751: \$('.pblabel', this).text(LCprogressTxt);
7752: }
7753: });
7754: // ]]>
7755: </script>
7756: ENDPROGRESS
7757: }
7758:
7759: sub LCprogressbarUpdate_script {
7760: return(<<ENDPROGRESSUPDATE);
7761: <style type="text/css">
7762: .ui-progressbar { position:relative; }
7763: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7764: </style>
7765: <script type="text/javascript">
7766: // <![CDATA[
1.1045 www 7767: var LCprogressTxt='---';
7768:
7769: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7770: LCprogressTxt=progresstext;
1.1045 www 7771: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7772: }
7773: // ]]>
7774: </script>
7775: ENDPROGRESSUPDATE
7776: }
7777:
1.1042 www 7778: my $LClastpercent;
1.1045 www 7779: my $LCidcnt;
7780: my $LCcurrentid;
1.1042 www 7781:
1.1041 www 7782: sub LCprogressbar {
1.1042 www 7783: my ($r)=(@_);
7784: $LClastpercent=0;
1.1045 www 7785: $LCidcnt++;
7786: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7787: my $starting=&mt('Starting');
7788: my $content=(<<ENDPROGBAR);
7789: <p>
1.1045 www 7790: <div id="progressbar$LCcurrentid">
1.1041 www 7791: <span class="pblabel">$starting</span>
7792: </div>
7793: </p>
7794: ENDPROGBAR
1.1045 www 7795: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7796: }
7797:
7798: sub LCprogressbarUpdate {
1.1042 www 7799: my ($r,$val,$text)=@_;
7800: unless ($val) {
7801: if ($LClastpercent) {
7802: $val=$LClastpercent;
7803: } else {
7804: $val=0;
7805: }
7806: }
1.1041 www 7807: if ($val<0) { $val=0; }
7808: if ($val>100) { $val=0; }
1.1042 www 7809: $LClastpercent=$val;
1.1041 www 7810: unless ($text) { $text=$val.'%'; }
7811: $text=&js_ready($text);
1.1044 www 7812: &r_print($r,<<ENDUPDATE);
1.1041 www 7813: <script type="text/javascript">
7814: // <![CDATA[
1.1045 www 7815: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7816: // ]]>
7817: </script>
7818: ENDUPDATE
1.1035 www 7819: }
7820:
1.1042 www 7821: sub LCprogressbarClose {
7822: my ($r)=@_;
7823: $LClastpercent=0;
1.1044 www 7824: &r_print($r,<<ENDCLOSE);
1.1042 www 7825: <script type="text/javascript">
7826: // <![CDATA[
1.1045 www 7827: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7828: // ]]>
7829: </script>
7830: ENDCLOSE
1.1044 www 7831: }
7832:
7833: sub r_print {
7834: my ($r,$to_print)=@_;
7835: if ($r) {
7836: $r->print($to_print);
7837: $r->rflush();
7838: } else {
7839: print($to_print);
7840: }
1.1042 www 7841: }
7842:
1.320 albertel 7843: sub html_encode {
7844: my ($result) = @_;
7845:
1.322 albertel 7846: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7847:
7848: return $result;
7849: }
1.1044 www 7850:
1.317 albertel 7851: sub js_ready {
7852: my ($result) = @_;
7853:
1.323 albertel 7854: $result =~ s/[\n\r]/ /xmsg;
7855: $result =~ s/\\/\\\\/xmsg;
7856: $result =~ s/'/\\'/xmsg;
1.372 albertel 7857: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7858:
7859: return $result;
7860: }
7861:
1.315 albertel 7862: sub validate_page {
7863: if ( exists($env{'internal.start_page'})
1.316 albertel 7864: && $env{'internal.start_page'} > 1) {
7865: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7866: $env{'internal.start_page'}.' '.
1.316 albertel 7867: $ENV{'request.filename'});
1.315 albertel 7868: }
7869: if ( exists($env{'internal.end_page'})
1.316 albertel 7870: && $env{'internal.end_page'} > 1) {
7871: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7872: $env{'internal.end_page'}.' '.
1.316 albertel 7873: $env{'request.filename'});
1.315 albertel 7874: }
7875: if ( exists($env{'internal.start_page'})
7876: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7877: &Apache::lonnet::logthis('start_page called without end_page '.
7878: $env{'request.filename'});
1.315 albertel 7879: }
7880: if ( ! exists($env{'internal.start_page'})
7881: && exists($env{'internal.end_page'})) {
1.316 albertel 7882: &Apache::lonnet::logthis('end_page called without start_page'.
7883: $env{'request.filename'});
1.315 albertel 7884: }
1.306 albertel 7885: }
1.315 albertel 7886:
1.996 www 7887:
7888: sub start_scrollbox {
1.1075 raeburn 7889: my ($outerwidth,$width,$height,$id,$bgcolor)=@_;
1.998 raeburn 7890: unless ($outerwidth) { $outerwidth='520px'; }
7891: unless ($width) { $width='500px'; }
7892: unless ($height) { $height='200px'; }
1.1075 raeburn 7893: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7894: if ($id ne '') {
1.1020 raeburn 7895: $table_id = " id='table_$id'";
7896: $div_id = " id='div_$id'";
1.1018 raeburn 7897: }
1.1075 raeburn 7898: if ($bgcolor ne '') {
7899: $tdcol = "background-color: $bgcolor;";
7900: }
7901: return <<"END";
7902: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol"><div style="overflow:auto; width:$width; height: $height;"$div_id>
7903: END
1.996 www 7904: }
7905:
7906: sub end_scrollbox {
1.1036 www 7907: return '</div></td></tr></table>';
1.996 www 7908: }
7909:
1.318 albertel 7910: sub simple_error_page {
7911: my ($r,$title,$msg) = @_;
7912: my $page =
7913: &Apache::loncommon::start_page($title).
1.1075.2.15 raeburn 7914: '<p class="LC_error">'.&mt($msg).'</p>'.
1.318 albertel 7915: &Apache::loncommon::end_page();
7916: if (ref($r)) {
7917: $r->print($page);
1.327 albertel 7918: return;
1.318 albertel 7919: }
7920: return $page;
7921: }
1.347 albertel 7922:
7923: {
1.610 albertel 7924: my @row_count;
1.961 onken 7925:
7926: sub start_data_table_count {
7927: unshift(@row_count, 0);
7928: return;
7929: }
7930:
7931: sub end_data_table_count {
7932: shift(@row_count);
7933: return;
7934: }
7935:
1.347 albertel 7936: sub start_data_table {
1.1018 raeburn 7937: my ($add_class,$id) = @_;
1.422 albertel 7938: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 7939: my $table_id;
7940: if (defined($id)) {
7941: $table_id = ' id="'.$id.'"';
7942: }
1.961 onken 7943: &start_data_table_count();
1.1018 raeburn 7944: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 7945: }
7946:
7947: sub end_data_table {
1.961 onken 7948: &end_data_table_count();
1.389 albertel 7949: return '</table>'."\n";;
1.347 albertel 7950: }
7951:
7952: sub start_data_table_row {
1.974 wenzelju 7953: my ($add_class, $id) = @_;
1.610 albertel 7954: $row_count[0]++;
7955: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7956: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 7957: $id = (' id="'.$id.'"') unless ($id eq '');
7958: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 7959: }
1.471 banghart 7960:
7961: sub continue_data_table_row {
1.974 wenzelju 7962: my ($add_class, $id) = @_;
1.610 albertel 7963: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 7964: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
7965: $id = (' id="'.$id.'"') unless ($id eq '');
7966: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 7967: }
1.347 albertel 7968:
7969: sub end_data_table_row {
1.389 albertel 7970: return '</tr>'."\n";;
1.347 albertel 7971: }
1.367 www 7972:
1.421 albertel 7973: sub start_data_table_empty_row {
1.707 bisitz 7974: # $row_count[0]++;
1.421 albertel 7975: return '<tr class="LC_empty_row" >'."\n";;
7976: }
7977:
7978: sub end_data_table_empty_row {
7979: return '</tr>'."\n";;
7980: }
7981:
1.367 www 7982: sub start_data_table_header_row {
1.389 albertel 7983: return '<tr class="LC_header_row">'."\n";;
1.367 www 7984: }
7985:
7986: sub end_data_table_header_row {
1.389 albertel 7987: return '</tr>'."\n";;
1.367 www 7988: }
1.890 droeschl 7989:
7990: sub data_table_caption {
7991: my $caption = shift;
7992: return "<caption class=\"LC_caption\">$caption</caption>";
7993: }
1.347 albertel 7994: }
7995:
1.548 albertel 7996: =pod
7997:
7998: =item * &inhibit_menu_check($arg)
7999:
8000: Checks for a inhibitmenu state and generates output to preserve it
8001:
8002: Inputs: $arg - can be any of
8003: - undef - in which case the return value is a string
8004: to add into arguments list of a uri
8005: - 'input' - in which case the return value is a HTML
8006: <form> <input> field of type hidden to
8007: preserve the value
8008: - a url - in which case the return value is the url with
8009: the neccesary cgi args added to preserve the
8010: inhibitmenu state
8011: - a ref to a url - no return value, but the string is
8012: updated to include the neccessary cgi
8013: args to preserve the inhibitmenu state
8014:
8015: =cut
8016:
8017: sub inhibit_menu_check {
8018: my ($arg) = @_;
8019: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8020: if ($arg eq 'input') {
8021: if ($env{'form.inhibitmenu'}) {
8022: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8023: } else {
8024: return
8025: }
8026: }
8027: if ($env{'form.inhibitmenu'}) {
8028: if (ref($arg)) {
8029: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8030: } elsif ($arg eq '') {
8031: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8032: } else {
8033: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8034: }
8035: }
8036: if (!ref($arg)) {
8037: return $arg;
8038: }
8039: }
8040:
1.251 albertel 8041: ###############################################
1.182 matthew 8042:
8043: =pod
8044:
1.549 albertel 8045: =back
8046:
8047: =head1 User Information Routines
8048:
8049: =over 4
8050:
1.405 albertel 8051: =item * &get_users_function()
1.182 matthew 8052:
8053: Used by &bodytag to determine the current users primary role.
8054: Returns either 'student','coordinator','admin', or 'author'.
8055:
8056: =cut
8057:
8058: ###############################################
8059: sub get_users_function {
1.815 tempelho 8060: my $function = 'norole';
1.818 tempelho 8061: if ($env{'request.role'}=~/^(st)/) {
8062: $function='student';
8063: }
1.907 raeburn 8064: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8065: $function='coordinator';
8066: }
1.258 albertel 8067: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8068: $function='admin';
8069: }
1.826 bisitz 8070: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8071: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8072: $function='author';
8073: }
8074: return $function;
1.54 www 8075: }
1.99 www 8076:
8077: ###############################################
8078:
1.233 raeburn 8079: =pod
8080:
1.821 raeburn 8081: =item * &show_course()
8082:
8083: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8084: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8085:
8086: Inputs:
8087: None
8088:
8089: Outputs:
8090: Scalar: 1 if 'Course' to be used, 0 otherwise.
8091:
8092: =cut
8093:
8094: ###############################################
8095: sub show_course {
8096: my $course = !$env{'user.adv'};
8097: if (!$env{'user.adv'}) {
8098: foreach my $env (keys(%env)) {
8099: next if ($env !~ m/^user\.priv\./);
8100: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8101: $course = 0;
8102: last;
8103: }
8104: }
8105: }
8106: return $course;
8107: }
8108:
8109: ###############################################
8110:
8111: =pod
8112:
1.542 raeburn 8113: =item * &check_user_status()
1.274 raeburn 8114:
8115: Determines current status of supplied role for a
8116: specific user. Roles can be active, previous or future.
8117:
8118: Inputs:
8119: user's domain, user's username, course's domain,
1.375 raeburn 8120: course's number, optional section ID.
1.274 raeburn 8121:
8122: Outputs:
8123: role status: active, previous or future.
8124:
8125: =cut
8126:
8127: sub check_user_status {
1.412 raeburn 8128: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8129: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8130: my @uroles = keys %userinfo;
8131: my $srchstr;
8132: my $active_chk = 'none';
1.412 raeburn 8133: my $now = time;
1.274 raeburn 8134: if (@uroles > 0) {
1.908 raeburn 8135: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8136: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8137: } else {
1.412 raeburn 8138: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8139: }
8140: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8141: my $role_end = 0;
8142: my $role_start = 0;
8143: $active_chk = 'active';
1.412 raeburn 8144: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8145: $role_end = $1;
8146: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8147: $role_start = $1;
1.274 raeburn 8148: }
8149: }
8150: if ($role_start > 0) {
1.412 raeburn 8151: if ($now < $role_start) {
1.274 raeburn 8152: $active_chk = 'future';
8153: }
8154: }
8155: if ($role_end > 0) {
1.412 raeburn 8156: if ($now > $role_end) {
1.274 raeburn 8157: $active_chk = 'previous';
8158: }
8159: }
8160: }
8161: }
8162: return $active_chk;
8163: }
8164:
8165: ###############################################
8166:
8167: =pod
8168:
1.405 albertel 8169: =item * &get_sections()
1.233 raeburn 8170:
8171: Determines all the sections for a course including
8172: sections with students and sections containing other roles.
1.419 raeburn 8173: Incoming parameters:
8174:
8175: 1. domain
8176: 2. course number
8177: 3. reference to array containing roles for which sections should
8178: be gathered (optional).
8179: 4. reference to array containing status types for which sections
8180: should be gathered (optional).
8181:
8182: If the third argument is undefined, sections are gathered for any role.
8183: If the fourth argument is undefined, sections are gathered for any status.
8184: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8185:
1.374 raeburn 8186: Returns section hash (keys are section IDs, values are
8187: number of users in each section), subject to the
1.419 raeburn 8188: optional roles filter, optional status filter
1.233 raeburn 8189:
8190: =cut
8191:
8192: ###############################################
8193: sub get_sections {
1.419 raeburn 8194: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8195: if (!defined($cdom) || !defined($cnum)) {
8196: my $cid = $env{'request.course.id'};
8197:
8198: return if (!defined($cid));
8199:
8200: $cdom = $env{'course.'.$cid.'.domain'};
8201: $cnum = $env{'course.'.$cid.'.num'};
8202: }
8203:
8204: my %sectioncount;
1.419 raeburn 8205: my $now = time;
1.240 albertel 8206:
1.1075.2.33! raeburn 8207: my $check_students = 1;
! 8208: my $only_students = 0;
! 8209: if (ref($possible_roles) eq 'ARRAY') {
! 8210: if (grep(/^st$/,@{$possible_roles})) {
! 8211: if (@{$possible_roles} == 1) {
! 8212: $only_students = 1;
! 8213: }
! 8214: } else {
! 8215: $check_students = 0;
! 8216: }
! 8217: }
! 8218:
! 8219: if ($check_students) {
1.276 albertel 8220: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8221: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8222: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8223: my $start_index = &Apache::loncoursedata::CL_START();
8224: my $end_index = &Apache::loncoursedata::CL_END();
8225: my $status;
1.366 albertel 8226: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8227: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8228: $data->[$status_index],
8229: $data->[$start_index],
8230: $data->[$end_index]);
8231: if ($stu_status eq 'Active') {
8232: $status = 'active';
8233: } elsif ($end < $now) {
8234: $status = 'previous';
8235: } elsif ($start > $now) {
8236: $status = 'future';
8237: }
8238: if ($section ne '-1' && $section !~ /^\s*$/) {
8239: if ((!defined($possible_status)) || (($status ne '') &&
8240: (grep/^\Q$status\E$/,@{$possible_status}))) {
8241: $sectioncount{$section}++;
8242: }
1.240 albertel 8243: }
8244: }
8245: }
1.1075.2.33! raeburn 8246: if ($only_students) {
! 8247: return %sectioncount;
! 8248: }
1.240 albertel 8249: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8250: foreach my $user (sort(keys(%courseroles))) {
8251: if ($user !~ /^(\w{2})/) { next; }
8252: my ($role) = ($user =~ /^(\w{2})/);
8253: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8254: my ($section,$status);
1.240 albertel 8255: if ($role eq 'cr' &&
8256: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8257: $section=$1;
8258: }
8259: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8260: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8261: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8262: if ($end == -1 && $start == -1) {
8263: next; #deleted role
8264: }
8265: if (!defined($possible_status)) {
8266: $sectioncount{$section}++;
8267: } else {
8268: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8269: $status = 'active';
8270: } elsif ($end < $now) {
8271: $status = 'future';
8272: } elsif ($start > $now) {
8273: $status = 'previous';
8274: }
8275: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8276: $sectioncount{$section}++;
8277: }
8278: }
1.233 raeburn 8279: }
1.366 albertel 8280: return %sectioncount;
1.233 raeburn 8281: }
8282:
1.274 raeburn 8283: ###############################################
1.294 raeburn 8284:
8285: =pod
1.405 albertel 8286:
8287: =item * &get_course_users()
8288:
1.275 raeburn 8289: Retrieves usernames:domains for users in the specified course
8290: with specific role(s), and access status.
8291:
8292: Incoming parameters:
1.277 albertel 8293: 1. course domain
8294: 2. course number
8295: 3. access status: users must have - either active,
1.275 raeburn 8296: previous, future, or all.
1.277 albertel 8297: 4. reference to array of permissible roles
1.288 raeburn 8298: 5. reference to array of section restrictions (optional)
8299: 6. reference to results object (hash of hashes).
8300: 7. reference to optional userdata hash
1.609 raeburn 8301: 8. reference to optional statushash
1.630 raeburn 8302: 9. flag if privileged users (except those set to unhide in
8303: course settings) should be excluded
1.609 raeburn 8304: Keys of top level results hash are roles.
1.275 raeburn 8305: Keys of inner hashes are username:domain, with
8306: values set to access type.
1.288 raeburn 8307: Optional userdata hash returns an array with arguments in the
8308: same order as loncoursedata::get_classlist() for student data.
8309:
1.609 raeburn 8310: Optional statushash returns
8311:
1.288 raeburn 8312: Entries for end, start, section and status are blank because
8313: of the possibility of multiple values for non-student roles.
8314:
1.275 raeburn 8315: =cut
1.405 albertel 8316:
1.275 raeburn 8317: ###############################################
1.405 albertel 8318:
1.275 raeburn 8319: sub get_course_users {
1.630 raeburn 8320: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8321: my %idx = ();
1.419 raeburn 8322: my %seclists;
1.288 raeburn 8323:
8324: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8325: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8326: $idx{end} = &Apache::loncoursedata::CL_END();
8327: $idx{start} = &Apache::loncoursedata::CL_START();
8328: $idx{id} = &Apache::loncoursedata::CL_ID();
8329: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8330: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8331: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8332:
1.290 albertel 8333: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8334: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8335: my $now = time;
1.277 albertel 8336: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8337: my $match = 0;
1.412 raeburn 8338: my $secmatch = 0;
1.419 raeburn 8339: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8340: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8341: if ($section eq '') {
8342: $section = 'none';
8343: }
1.291 albertel 8344: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8345: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8346: $secmatch = 1;
8347: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8348: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8349: $secmatch = 1;
8350: }
8351: } else {
1.419 raeburn 8352: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8353: $secmatch = 1;
8354: }
1.290 albertel 8355: }
1.412 raeburn 8356: if (!$secmatch) {
8357: next;
8358: }
1.419 raeburn 8359: }
1.275 raeburn 8360: if (defined($$types{'active'})) {
1.288 raeburn 8361: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8362: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8363: $match = 1;
1.275 raeburn 8364: }
8365: }
8366: if (defined($$types{'previous'})) {
1.609 raeburn 8367: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8368: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8369: $match = 1;
1.275 raeburn 8370: }
8371: }
8372: if (defined($$types{'future'})) {
1.609 raeburn 8373: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8374: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8375: $match = 1;
1.275 raeburn 8376: }
8377: }
1.609 raeburn 8378: if ($match) {
8379: push(@{$seclists{$student}},$section);
8380: if (ref($userdata) eq 'HASH') {
8381: $$userdata{$student} = $$classlist{$student};
8382: }
8383: if (ref($statushash) eq 'HASH') {
8384: $statushash->{$student}{'st'}{$section} = $status;
8385: }
1.288 raeburn 8386: }
1.275 raeburn 8387: }
8388: }
1.412 raeburn 8389: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8390: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8391: my $now = time;
1.609 raeburn 8392: my %displaystatus = ( previous => 'Expired',
8393: active => 'Active',
8394: future => 'Future',
8395: );
1.630 raeburn 8396: my %nothide;
8397: if ($hidepriv) {
8398: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8399: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8400: if ($user !~ /:/) {
8401: $nothide{join(':',split(/[\@]/,$user))}=1;
8402: } else {
8403: $nothide{$user} = 1;
8404: }
8405: }
8406: }
1.439 raeburn 8407: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8408: my $match = 0;
1.412 raeburn 8409: my $secmatch = 0;
1.439 raeburn 8410: my $status;
1.412 raeburn 8411: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8412: $user =~ s/:$//;
1.439 raeburn 8413: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8414: if ($end == -1 || $start == -1) {
8415: next;
8416: }
8417: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8418: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8419: my ($uname,$udom) = split(/:/,$user);
8420: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8421: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8422: $secmatch = 1;
8423: } elsif ($usec eq '') {
1.420 albertel 8424: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8425: $secmatch = 1;
8426: }
8427: } else {
8428: if (grep(/^\Q$usec\E$/,@{$sections})) {
8429: $secmatch = 1;
8430: }
8431: }
8432: if (!$secmatch) {
8433: next;
8434: }
1.288 raeburn 8435: }
1.419 raeburn 8436: if ($usec eq '') {
8437: $usec = 'none';
8438: }
1.275 raeburn 8439: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8440: if ($hidepriv) {
8441: if ((&Apache::lonnet::privileged($uname,$udom)) &&
8442: (!$nothide{$uname.':'.$udom})) {
8443: next;
8444: }
8445: }
1.503 raeburn 8446: if ($end > 0 && $end < $now) {
1.439 raeburn 8447: $status = 'previous';
8448: } elsif ($start > $now) {
8449: $status = 'future';
8450: } else {
8451: $status = 'active';
8452: }
1.277 albertel 8453: foreach my $type (keys(%{$types})) {
1.275 raeburn 8454: if ($status eq $type) {
1.420 albertel 8455: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8456: push(@{$$users{$role}{$user}},$type);
8457: }
1.288 raeburn 8458: $match = 1;
8459: }
8460: }
1.419 raeburn 8461: if (($match) && (ref($userdata) eq 'HASH')) {
8462: if (!exists($$userdata{$uname.':'.$udom})) {
8463: &get_user_info($udom,$uname,\%idx,$userdata);
8464: }
1.420 albertel 8465: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8466: push(@{$seclists{$uname.':'.$udom}},$usec);
8467: }
1.609 raeburn 8468: if (ref($statushash) eq 'HASH') {
8469: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8470: }
1.275 raeburn 8471: }
8472: }
8473: }
8474: }
1.290 albertel 8475: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8476: if ((defined($cdom)) && (defined($cnum))) {
8477: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8478: if ( defined($csettings{'internal.courseowner'}) ) {
8479: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8480: next if ($owner eq '');
8481: my ($ownername,$ownerdom);
8482: if ($owner =~ /^([^:]+):([^:]+)$/) {
8483: $ownername = $1;
8484: $ownerdom = $2;
8485: } else {
8486: $ownername = $owner;
8487: $ownerdom = $cdom;
8488: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8489: }
8490: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8491: if (defined($userdata) &&
1.609 raeburn 8492: !exists($$userdata{$owner})) {
8493: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8494: if (!grep(/^none$/,@{$seclists{$owner}})) {
8495: push(@{$seclists{$owner}},'none');
8496: }
8497: if (ref($statushash) eq 'HASH') {
8498: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8499: }
1.290 albertel 8500: }
1.279 raeburn 8501: }
8502: }
8503: }
1.419 raeburn 8504: foreach my $user (keys(%seclists)) {
8505: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8506: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8507: }
1.275 raeburn 8508: }
8509: return;
8510: }
8511:
1.288 raeburn 8512: sub get_user_info {
8513: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8514: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8515: &plainname($uname,$udom,'lastname');
1.291 albertel 8516: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8517: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8518: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8519: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8520: return;
8521: }
1.275 raeburn 8522:
1.472 raeburn 8523: ###############################################
8524:
8525: =pod
8526:
8527: =item * &get_user_quota()
8528:
8529: Retrieves quota assigned for storage of portfolio files for a user
8530:
8531: Incoming parameters:
8532: 1. user's username
8533: 2. user's domain
8534:
8535: Returns:
1.536 raeburn 8536: 1. Disk quota (in Mb) assigned to student.
8537: 2. (Optional) Type of setting: custom or default
8538: (individually assigned or default for user's
8539: institutional status).
8540: 3. (Optional) - User's institutional status (e.g., faculty, staff
8541: or student - types as defined in localenroll::inst_usertypes
8542: for user's domain, which determines default quota for user.
8543: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8544:
8545: If a value has been stored in the user's environment,
1.536 raeburn 8546: it will return that, otherwise it returns the maximal default
8547: defined for the user's instituional status(es) in the domain.
1.472 raeburn 8548:
8549: =cut
8550:
8551: ###############################################
8552:
8553:
8554: sub get_user_quota {
8555: my ($uname,$udom) = @_;
1.536 raeburn 8556: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8557: if (!defined($udom)) {
8558: $udom = $env{'user.domain'};
8559: }
8560: if (!defined($uname)) {
8561: $uname = $env{'user.name'};
8562: }
8563: if (($udom eq '' || $uname eq '') ||
8564: ($udom eq 'public') && ($uname eq 'public')) {
8565: $quota = 0;
1.536 raeburn 8566: $quotatype = 'default';
8567: $defquota = 0;
1.472 raeburn 8568: } else {
1.536 raeburn 8569: my $inststatus;
1.472 raeburn 8570: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8571: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 8572: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 8573: } else {
1.536 raeburn 8574: my %userenv =
8575: &Apache::lonnet::get('environment',['portfolioquota',
8576: 'inststatus'],$udom,$uname);
1.472 raeburn 8577: my ($tmp) = keys(%userenv);
8578: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8579: $quota = $userenv{'portfolioquota'};
1.536 raeburn 8580: $inststatus = $userenv{'inststatus'};
1.472 raeburn 8581: } else {
8582: undef(%userenv);
8583: }
8584: }
1.536 raeburn 8585: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 8586: if ($quota eq '') {
1.536 raeburn 8587: $quota = $defquota;
8588: $quotatype = 'default';
8589: } else {
8590: $quotatype = 'custom';
1.472 raeburn 8591: }
8592: }
1.536 raeburn 8593: if (wantarray) {
8594: return ($quota,$quotatype,$settingstatus,$defquota);
8595: } else {
8596: return $quota;
8597: }
1.472 raeburn 8598: }
8599:
8600: ###############################################
8601:
8602: =pod
8603:
8604: =item * &default_quota()
8605:
1.536 raeburn 8606: Retrieves default quota assigned for storage of user portfolio files,
8607: given an (optional) user's institutional status.
1.472 raeburn 8608:
8609: Incoming parameters:
8610: 1. domain
1.536 raeburn 8611: 2. (Optional) institutional status(es). This is a : separated list of
8612: status types (e.g., faculty, staff, student etc.)
8613: which apply to the user for whom the default is being retrieved.
8614: If the institutional status string in undefined, the domain
8615: default quota will be returned.
1.472 raeburn 8616:
8617: Returns:
8618: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 8619: 2. (Optional) institutional type which determined the value of the
8620: default quota.
1.472 raeburn 8621:
8622: If a value has been stored in the domain's configuration db,
8623: it will return that, otherwise it returns 20 (for backwards
8624: compatibility with domains which have not set up a configuration
8625: db file; the original statically defined portfolio quota was 20 Mb).
8626:
1.536 raeburn 8627: If the user's status includes multiple types (e.g., staff and student),
8628: the largest default quota which applies to the user determines the
8629: default quota returned.
8630:
1.780 raeburn 8631: =back
8632:
1.472 raeburn 8633: =cut
8634:
8635: ###############################################
8636:
8637:
8638: sub default_quota {
1.536 raeburn 8639: my ($udom,$inststatus) = @_;
8640: my ($defquota,$settingstatus);
8641: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8642: ['quotas'],$udom);
8643: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8644: if ($inststatus ne '') {
1.765 raeburn 8645: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8646: foreach my $item (@statuses) {
1.711 raeburn 8647: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
8648: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
8649: if ($defquota eq '') {
8650: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
8651: $settingstatus = $item;
8652: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
8653: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
8654: $settingstatus = $item;
8655: }
8656: }
8657: } else {
8658: if ($quotahash{'quotas'}{$item} ne '') {
8659: if ($defquota eq '') {
8660: $defquota = $quotahash{'quotas'}{$item};
8661: $settingstatus = $item;
8662: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8663: $defquota = $quotahash{'quotas'}{$item};
8664: $settingstatus = $item;
8665: }
1.536 raeburn 8666: }
8667: }
8668: }
8669: }
8670: if ($defquota eq '') {
1.711 raeburn 8671: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
8672: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
8673: } else {
8674: $defquota = $quotahash{'quotas'}{'default'};
8675: }
1.536 raeburn 8676: $settingstatus = 'default';
8677: }
8678: } else {
8679: $settingstatus = 'default';
8680: $defquota = 20;
8681: }
8682: if (wantarray) {
8683: return ($defquota,$settingstatus);
1.472 raeburn 8684: } else {
1.536 raeburn 8685: return $defquota;
1.472 raeburn 8686: }
8687: }
8688:
1.384 raeburn 8689: sub get_secgrprole_info {
8690: my ($cdom,$cnum,$needroles,$type) = @_;
8691: my %sections_count = &get_sections($cdom,$cnum);
8692: my @sections = (sort {$a <=> $b} keys(%sections_count));
8693: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8694: my @groups = sort(keys(%curr_groups));
8695: my $allroles = [];
8696: my $rolehash;
8697: my $accesshash = {
8698: active => 'Currently has access',
8699: future => 'Will have future access',
8700: previous => 'Previously had access',
8701: };
8702: if ($needroles) {
8703: $rolehash = {'all' => 'all'};
1.385 albertel 8704: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8705: if (&Apache::lonnet::error(%user_roles)) {
8706: undef(%user_roles);
8707: }
8708: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8709: my ($role)=split(/\:/,$item,2);
8710: if ($role eq 'cr') { next; }
8711: if ($role =~ /^cr/) {
8712: $$rolehash{$role} = (split('/',$role))[3];
8713: } else {
8714: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8715: }
8716: }
8717: foreach my $key (sort(keys(%{$rolehash}))) {
8718: push(@{$allroles},$key);
8719: }
8720: push (@{$allroles},'st');
8721: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8722: }
8723: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8724: }
8725:
1.555 raeburn 8726: sub user_picker {
1.994 raeburn 8727: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8728: my $currdom = $dom;
8729: my %curr_selected = (
8730: srchin => 'dom',
1.580 raeburn 8731: srchby => 'lastname',
1.555 raeburn 8732: );
8733: my $srchterm;
1.625 raeburn 8734: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 8735: if ($srch->{'srchby'} ne '') {
8736: $curr_selected{'srchby'} = $srch->{'srchby'};
8737: }
8738: if ($srch->{'srchin'} ne '') {
8739: $curr_selected{'srchin'} = $srch->{'srchin'};
8740: }
8741: if ($srch->{'srchtype'} ne '') {
8742: $curr_selected{'srchtype'} = $srch->{'srchtype'};
8743: }
8744: if ($srch->{'srchdomain'} ne '') {
8745: $currdom = $srch->{'srchdomain'};
8746: }
8747: $srchterm = $srch->{'srchterm'};
8748: }
8749: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 8750: 'usr' => 'Search criteria',
1.563 raeburn 8751: 'doma' => 'Domain/institution to search',
1.558 albertel 8752: 'uname' => 'username',
8753: 'lastname' => 'last name',
1.555 raeburn 8754: 'lastfirst' => 'last name, first name',
1.558 albertel 8755: 'crs' => 'in this course',
1.576 raeburn 8756: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 8757: 'alc' => 'all LON-CAPA',
1.573 raeburn 8758: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 8759: 'exact' => 'is',
8760: 'contains' => 'contains',
1.569 raeburn 8761: 'begins' => 'begins with',
1.571 raeburn 8762: 'youm' => "You must include some text to search for.",
8763: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
8764: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
8765: 'yomc' => "You must choose a domain when using an institutional directory search.",
8766: 'ymcd' => "You must choose a domain when using a domain search.",
8767: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
8768: 'whse' => "When searching by last,first you must include at least one character in the first name.",
8769: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 8770: );
1.563 raeburn 8771: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
8772: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 8773:
8774: my @srchins = ('crs','dom','alc','instd');
8775:
8776: foreach my $option (@srchins) {
8777: # FIXME 'alc' option unavailable until
8778: # loncreateuser::print_user_query_page()
8779: # has been completed.
8780: next if ($option eq 'alc');
1.880 raeburn 8781: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 8782: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 8783: if ($curr_selected{'srchin'} eq $option) {
8784: $srchinsel .= '
8785: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8786: } else {
8787: $srchinsel .= '
8788: <option value="'.$option.'">'.$lt{$option}.'</option>';
8789: }
1.555 raeburn 8790: }
1.563 raeburn 8791: $srchinsel .= "\n </select>\n";
1.555 raeburn 8792:
8793: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 8794: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 8795: if ($curr_selected{'srchby'} eq $option) {
8796: $srchbysel .= '
8797: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8798: } else {
8799: $srchbysel .= '
8800: <option value="'.$option.'">'.$lt{$option}.'</option>';
8801: }
8802: }
8803: $srchbysel .= "\n </select>\n";
8804:
8805: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 8806: foreach my $option ('begins','contains','exact') {
1.555 raeburn 8807: if ($curr_selected{'srchtype'} eq $option) {
8808: $srchtypesel .= '
8809: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8810: } else {
8811: $srchtypesel .= '
8812: <option value="'.$option.'">'.$lt{$option}.'</option>';
8813: }
8814: }
8815: $srchtypesel .= "\n </select>\n";
8816:
1.558 albertel 8817: my ($newuserscript,$new_user_create);
1.994 raeburn 8818: my $context_dom = $env{'request.role.domain'};
8819: if ($context eq 'requestcrs') {
8820: if ($env{'form.coursedom'} ne '') {
8821: $context_dom = $env{'form.coursedom'};
8822: }
8823: }
1.556 raeburn 8824: if ($forcenewuser) {
1.576 raeburn 8825: if (ref($srch) eq 'HASH') {
1.994 raeburn 8826: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 8827: if ($cancreate) {
8828: $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>';
8829: } else {
1.799 bisitz 8830: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 8831: my %usertypetext = (
8832: official => 'institutional',
8833: unofficial => 'non-institutional',
8834: );
1.799 bisitz 8835: $new_user_create = '<p class="LC_warning">'
8836: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
8837: .' '
8838: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
8839: ,'<a href="'.$helplink.'">','</a>')
8840: .'</p><br />';
1.627 raeburn 8841: }
1.576 raeburn 8842: }
8843: }
8844:
1.556 raeburn 8845: $newuserscript = <<"ENDSCRIPT";
8846:
1.570 raeburn 8847: function setSearch(createnew,callingForm) {
1.556 raeburn 8848: if (createnew == 1) {
1.570 raeburn 8849: for (var i=0; i<callingForm.srchby.length; i++) {
8850: if (callingForm.srchby.options[i].value == 'uname') {
8851: callingForm.srchby.selectedIndex = i;
1.556 raeburn 8852: }
8853: }
1.570 raeburn 8854: for (var i=0; i<callingForm.srchin.length; i++) {
8855: if ( callingForm.srchin.options[i].value == 'dom') {
8856: callingForm.srchin.selectedIndex = i;
1.556 raeburn 8857: }
8858: }
1.570 raeburn 8859: for (var i=0; i<callingForm.srchtype.length; i++) {
8860: if (callingForm.srchtype.options[i].value == 'exact') {
8861: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 8862: }
8863: }
1.570 raeburn 8864: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 8865: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 8866: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 8867: }
8868: }
8869: }
8870: }
8871: ENDSCRIPT
1.558 albertel 8872:
1.556 raeburn 8873: }
8874:
1.555 raeburn 8875: my $output = <<"END_BLOCK";
1.556 raeburn 8876: <script type="text/javascript">
1.824 bisitz 8877: // <![CDATA[
1.570 raeburn 8878: function validateEntry(callingForm) {
1.558 albertel 8879:
1.556 raeburn 8880: var checkok = 1;
1.558 albertel 8881: var srchin;
1.570 raeburn 8882: for (var i=0; i<callingForm.srchin.length; i++) {
8883: if ( callingForm.srchin[i].checked ) {
8884: srchin = callingForm.srchin[i].value;
1.558 albertel 8885: }
8886: }
8887:
1.570 raeburn 8888: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
8889: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
8890: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
8891: var srchterm = callingForm.srchterm.value;
8892: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 8893: var msg = "";
8894:
8895: if (srchterm == "") {
8896: checkok = 0;
1.571 raeburn 8897: msg += "$lt{'youm'}\\n";
1.556 raeburn 8898: }
8899:
1.569 raeburn 8900: if (srchtype== 'begins') {
8901: if (srchterm.length < 2) {
8902: checkok = 0;
1.571 raeburn 8903: msg += "$lt{'thte'}\\n";
1.569 raeburn 8904: }
8905: }
8906:
1.556 raeburn 8907: if (srchtype== 'contains') {
8908: if (srchterm.length < 3) {
8909: checkok = 0;
1.571 raeburn 8910: msg += "$lt{'thet'}\\n";
1.556 raeburn 8911: }
8912: }
8913: if (srchin == 'instd') {
8914: if (srchdomain == '') {
8915: checkok = 0;
1.571 raeburn 8916: msg += "$lt{'yomc'}\\n";
1.556 raeburn 8917: }
8918: }
8919: if (srchin == 'dom') {
8920: if (srchdomain == '') {
8921: checkok = 0;
1.571 raeburn 8922: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 8923: }
8924: }
8925: if (srchby == 'lastfirst') {
8926: if (srchterm.indexOf(",") == -1) {
8927: checkok = 0;
1.571 raeburn 8928: msg += "$lt{'whus'}\\n";
1.556 raeburn 8929: }
8930: if (srchterm.indexOf(",") == srchterm.length -1) {
8931: checkok = 0;
1.571 raeburn 8932: msg += "$lt{'whse'}\\n";
1.556 raeburn 8933: }
8934: }
8935: if (checkok == 0) {
1.571 raeburn 8936: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 8937: return;
8938: }
8939: if (checkok == 1) {
1.570 raeburn 8940: callingForm.submit();
1.556 raeburn 8941: }
8942: }
8943:
8944: $newuserscript
8945:
1.824 bisitz 8946: // ]]>
1.556 raeburn 8947: </script>
1.558 albertel 8948:
8949: $new_user_create
8950:
1.555 raeburn 8951: END_BLOCK
1.558 albertel 8952:
1.876 raeburn 8953: $output .= &Apache::lonhtmlcommon::start_pick_box().
8954: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
8955: $domform.
8956: &Apache::lonhtmlcommon::row_closure().
8957: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
8958: $srchbysel.
8959: $srchtypesel.
8960: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
8961: $srchinsel.
8962: &Apache::lonhtmlcommon::row_closure(1).
8963: &Apache::lonhtmlcommon::end_pick_box().
8964: '<br />';
1.555 raeburn 8965: return $output;
8966: }
8967:
1.612 raeburn 8968: sub user_rule_check {
1.615 raeburn 8969: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 8970: my $response;
8971: if (ref($usershash) eq 'HASH') {
8972: foreach my $user (keys(%{$usershash})) {
8973: my ($uname,$udom) = split(/:/,$user);
8974: next if ($udom eq '' || $uname eq '');
1.615 raeburn 8975: my ($id,$newuser);
1.612 raeburn 8976: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 8977: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 8978: $id = $usershash->{$user}->{'id'};
8979: }
8980: my $inst_response;
8981: if (ref($checks) eq 'HASH') {
8982: if (defined($checks->{'username'})) {
1.615 raeburn 8983: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8984: &Apache::lonnet::get_instuser($udom,$uname);
8985: } elsif (defined($checks->{'id'})) {
1.615 raeburn 8986: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8987: &Apache::lonnet::get_instuser($udom,undef,$id);
8988: }
1.615 raeburn 8989: } else {
8990: ($inst_response,%{$inst_results->{$user}}) =
8991: &Apache::lonnet::get_instuser($udom,$uname);
8992: return;
1.612 raeburn 8993: }
1.615 raeburn 8994: if (!$got_rules->{$udom}) {
1.612 raeburn 8995: my %domconfig = &Apache::lonnet::get_dom('configuration',
8996: ['usercreation'],$udom);
8997: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 8998: foreach my $item ('username','id') {
1.612 raeburn 8999: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9000: $$curr_rules{$udom}{$item} =
9001: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9002: }
9003: }
9004: }
1.615 raeburn 9005: $got_rules->{$udom} = 1;
1.585 raeburn 9006: }
1.612 raeburn 9007: foreach my $item (keys(%{$checks})) {
9008: if (ref($$curr_rules{$udom}) eq 'HASH') {
9009: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9010: if (@{$$curr_rules{$udom}{$item}} > 0) {
9011: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9012: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9013: if ($rule_check{$rule}) {
9014: $$rulematch{$user}{$item} = $rule;
9015: if ($inst_response eq 'ok') {
1.615 raeburn 9016: if (ref($inst_results) eq 'HASH') {
9017: if (ref($inst_results->{$user}) eq 'HASH') {
9018: if (keys(%{$inst_results->{$user}}) == 0) {
9019: $$alerts{$item}{$udom}{$uname} = 1;
9020: }
1.612 raeburn 9021: }
9022: }
1.615 raeburn 9023: }
9024: last;
1.585 raeburn 9025: }
9026: }
9027: }
9028: }
9029: }
9030: }
9031: }
9032: }
1.612 raeburn 9033: return;
9034: }
9035:
9036: sub user_rule_formats {
9037: my ($domain,$domdesc,$curr_rules,$check) = @_;
9038: my %text = (
9039: 'username' => 'Usernames',
9040: 'id' => 'IDs',
9041: );
9042: my $output;
9043: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9044: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9045: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9046: $output = '<br />'.
9047: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9048: '<span class="LC_cusr_emph">','</span>',$domdesc).
9049: ' <ul>';
1.612 raeburn 9050: foreach my $rule (@{$ruleorder}) {
9051: if (ref($curr_rules) eq 'ARRAY') {
9052: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9053: if (ref($rules->{$rule}) eq 'HASH') {
9054: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9055: $rules->{$rule}{'desc'}.'</li>';
9056: }
9057: }
9058: }
9059: }
9060: $output .= '</ul>';
9061: }
9062: }
9063: return $output;
9064: }
9065:
9066: sub instrule_disallow_msg {
1.615 raeburn 9067: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9068: my $response;
9069: my %text = (
9070: item => 'username',
9071: items => 'usernames',
9072: match => 'matches',
9073: do => 'does',
9074: action => 'a username',
9075: one => 'one',
9076: );
9077: if ($count > 1) {
9078: $text{'item'} = 'usernames';
9079: $text{'match'} ='match';
9080: $text{'do'} = 'do';
9081: $text{'action'} = 'usernames',
9082: $text{'one'} = 'ones';
9083: }
9084: if ($checkitem eq 'id') {
9085: $text{'items'} = 'IDs';
9086: $text{'item'} = 'ID';
9087: $text{'action'} = 'an ID';
1.615 raeburn 9088: if ($count > 1) {
9089: $text{'item'} = 'IDs';
9090: $text{'action'} = 'IDs';
9091: }
1.612 raeburn 9092: }
1.674 bisitz 9093: $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 9094: if ($mode eq 'upload') {
9095: if ($checkitem eq 'username') {
9096: $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'}.");
9097: } elsif ($checkitem eq 'id') {
1.674 bisitz 9098: $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 9099: }
1.669 raeburn 9100: } elsif ($mode eq 'selfcreate') {
9101: if ($checkitem eq 'id') {
9102: $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.");
9103: }
1.615 raeburn 9104: } else {
9105: if ($checkitem eq 'username') {
9106: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9107: } elsif ($checkitem eq 'id') {
9108: $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.");
9109: }
1.612 raeburn 9110: }
9111: return $response;
1.585 raeburn 9112: }
9113:
1.624 raeburn 9114: sub personal_data_fieldtitles {
9115: my %fieldtitles = &Apache::lonlocal::texthash (
9116: id => 'Student/Employee ID',
9117: permanentemail => 'E-mail address',
9118: lastname => 'Last Name',
9119: firstname => 'First Name',
9120: middlename => 'Middle Name',
9121: generation => 'Generation',
9122: gen => 'Generation',
1.765 raeburn 9123: inststatus => 'Affiliation',
1.624 raeburn 9124: );
9125: return %fieldtitles;
9126: }
9127:
1.642 raeburn 9128: sub sorted_inst_types {
9129: my ($dom) = @_;
9130: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9131: my $othertitle = &mt('All users');
9132: if ($env{'request.course.id'}) {
1.668 raeburn 9133: $othertitle = &mt('Any users');
1.642 raeburn 9134: }
9135: my @types;
9136: if (ref($order) eq 'ARRAY') {
9137: @types = @{$order};
9138: }
9139: if (@types == 0) {
9140: if (ref($usertypes) eq 'HASH') {
9141: @types = sort(keys(%{$usertypes}));
9142: }
9143: }
9144: if (keys(%{$usertypes}) > 0) {
9145: $othertitle = &mt('Other users');
9146: }
9147: return ($othertitle,$usertypes,\@types);
9148: }
9149:
1.645 raeburn 9150: sub get_institutional_codes {
9151: my ($settings,$allcourses,$LC_code) = @_;
9152: # Get complete list of course sections to update
9153: my @currsections = ();
9154: my @currxlists = ();
9155: my $coursecode = $$settings{'internal.coursecode'};
9156:
9157: if ($$settings{'internal.sectionnums'} ne '') {
9158: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9159: }
9160:
9161: if ($$settings{'internal.crosslistings'} ne '') {
9162: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9163: }
9164:
9165: if (@currxlists > 0) {
9166: foreach (@currxlists) {
9167: if (m/^([^:]+):(\w*)$/) {
9168: unless (grep/^$1$/,@{$allcourses}) {
9169: push @{$allcourses},$1;
9170: $$LC_code{$1} = $2;
9171: }
9172: }
9173: }
9174: }
9175:
9176: if (@currsections > 0) {
9177: foreach (@currsections) {
9178: if (m/^(\w+):(\w*)$/) {
9179: my $sec = $coursecode.$1;
9180: my $lc_sec = $2;
9181: unless (grep/^$sec$/,@{$allcourses}) {
9182: push @{$allcourses},$sec;
9183: $$LC_code{$sec} = $lc_sec;
9184: }
9185: }
9186: }
9187: }
9188: return;
9189: }
9190:
1.971 raeburn 9191: sub get_standard_codeitems {
9192: return ('Year','Semester','Department','Number','Section');
9193: }
9194:
1.112 bowersj2 9195: =pod
9196:
1.780 raeburn 9197: =head1 Slot Helpers
9198:
9199: =over 4
9200:
9201: =item * sorted_slots()
9202:
1.1040 raeburn 9203: Sorts an array of slot names in order of an optional sort key,
9204: default sort is by slot start time (earliest first).
1.780 raeburn 9205:
9206: Inputs:
9207:
9208: =over 4
9209:
9210: slotsarr - Reference to array of unsorted slot names.
9211:
9212: slots - Reference to hash of hash, where outer hash keys are slot names.
9213:
1.1040 raeburn 9214: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9215:
1.549 albertel 9216: =back
9217:
1.780 raeburn 9218: Returns:
9219:
9220: =over 4
9221:
1.1040 raeburn 9222: sorted - An array of slot names sorted by a specified sort key
9223: (default sort key is start time of the slot).
1.780 raeburn 9224:
9225: =back
9226:
9227: =cut
9228:
9229:
9230: sub sorted_slots {
1.1040 raeburn 9231: my ($slotsarr,$slots,$sortkey) = @_;
9232: if ($sortkey eq '') {
9233: $sortkey = 'starttime';
9234: }
1.780 raeburn 9235: my @sorted;
9236: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9237: @sorted =
9238: sort {
9239: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9240: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9241: }
9242: if (ref($slots->{$a})) { return -1;}
9243: if (ref($slots->{$b})) { return 1;}
9244: return 0;
9245: } @{$slotsarr};
9246: }
9247: return @sorted;
9248: }
9249:
1.1040 raeburn 9250: =pod
9251:
9252: =item * get_future_slots()
9253:
9254: Inputs:
9255:
9256: =over 4
9257:
9258: cnum - course number
9259:
9260: cdom - course domain
9261:
9262: now - current UNIX time
9263:
9264: symb - optional symb
9265:
9266: =back
9267:
9268: Returns:
9269:
9270: =over 4
9271:
9272: sorted_reservable - ref to array of student_schedulable slots currently
9273: reservable, ordered by end date of reservation period.
9274:
9275: reservable_now - ref to hash of student_schedulable slots currently
9276: reservable.
9277:
9278: Keys in inner hash are:
9279: (a) symb: either blank or symb to which slot use is restricted.
9280: (b) endreserve: end date of reservation period.
9281:
9282: sorted_future - ref to array of student_schedulable slots reservable in
9283: the future, ordered by start date of reservation period.
9284:
9285: future_reservable - ref to hash of student_schedulable slots reservable
9286: in the future.
9287:
9288: Keys in inner hash are:
9289: (a) symb: either blank or symb to which slot use is restricted.
9290: (b) startreserve: start date of reservation period.
9291:
9292: =back
9293:
9294: =cut
9295:
9296: sub get_future_slots {
9297: my ($cnum,$cdom,$now,$symb) = @_;
9298: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9299: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9300: foreach my $slot (keys(%slots)) {
9301: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9302: if ($symb) {
9303: next if (($slots{$slot}->{'symb'} ne '') &&
9304: ($slots{$slot}->{'symb'} ne $symb));
9305: }
9306: if (($slots{$slot}->{'starttime'} > $now) &&
9307: ($slots{$slot}->{'endtime'} > $now)) {
9308: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9309: my $userallowed = 0;
9310: if ($slots{$slot}->{'allowedsections'}) {
9311: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9312: if (!defined($env{'request.role.sec'})
9313: && grep(/^No section assigned$/,@allowed_sec)) {
9314: $userallowed=1;
9315: } else {
9316: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9317: $userallowed=1;
9318: }
9319: }
9320: unless ($userallowed) {
9321: if (defined($env{'request.course.groups'})) {
9322: my @groups = split(/:/,$env{'request.course.groups'});
9323: foreach my $group (@groups) {
9324: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9325: $userallowed=1;
9326: last;
9327: }
9328: }
9329: }
9330: }
9331: }
9332: if ($slots{$slot}->{'allowedusers'}) {
9333: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9334: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9335: if (grep(/^\Q$user\E$/,@allowed_users)) {
9336: $userallowed = 1;
9337: }
9338: }
9339: next unless($userallowed);
9340: }
9341: my $startreserve = $slots{$slot}->{'startreserve'};
9342: my $endreserve = $slots{$slot}->{'endreserve'};
9343: my $symb = $slots{$slot}->{'symb'};
9344: if (($startreserve < $now) &&
9345: (!$endreserve || $endreserve > $now)) {
9346: my $lastres = $endreserve;
9347: if (!$lastres) {
9348: $lastres = $slots{$slot}->{'starttime'};
9349: }
9350: $reservable_now{$slot} = {
9351: symb => $symb,
9352: endreserve => $lastres
9353: };
9354: } elsif (($startreserve > $now) &&
9355: (!$endreserve || $endreserve > $startreserve)) {
9356: $future_reservable{$slot} = {
9357: symb => $symb,
9358: startreserve => $startreserve
9359: };
9360: }
9361: }
9362: }
9363: my @unsorted_reservable = keys(%reservable_now);
9364: if (@unsorted_reservable > 0) {
9365: @sorted_reservable =
9366: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9367: }
9368: my @unsorted_future = keys(%future_reservable);
9369: if (@unsorted_future > 0) {
9370: @sorted_future =
9371: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9372: }
9373: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9374: }
1.780 raeburn 9375:
9376: =pod
9377:
1.1057 foxr 9378: =back
9379:
1.549 albertel 9380: =head1 HTTP Helpers
9381:
9382: =over 4
9383:
1.648 raeburn 9384: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9385:
1.258 albertel 9386: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9387: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9388: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9389:
9390: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9391: $possible_names is an ref to an array of form element names. As an example:
9392: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9393: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9394:
9395: =cut
1.1 albertel 9396:
1.6 albertel 9397: sub get_unprocessed_cgi {
1.25 albertel 9398: my ($query,$possible_names)= @_;
1.26 matthew 9399: # $Apache::lonxml::debug=1;
1.356 albertel 9400: foreach my $pair (split(/&/,$query)) {
9401: my ($name, $value) = split(/=/,$pair);
1.369 www 9402: $name = &unescape($name);
1.25 albertel 9403: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9404: $value =~ tr/+/ /;
9405: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9406: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9407: }
1.16 harris41 9408: }
1.6 albertel 9409: }
9410:
1.112 bowersj2 9411: =pod
9412:
1.648 raeburn 9413: =item * &cacheheader()
1.112 bowersj2 9414:
9415: returns cache-controlling header code
9416:
9417: =cut
9418:
1.7 albertel 9419: sub cacheheader {
1.258 albertel 9420: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9421: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9422: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9423: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9424: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9425: return $output;
1.7 albertel 9426: }
9427:
1.112 bowersj2 9428: =pod
9429:
1.648 raeburn 9430: =item * &no_cache($r)
1.112 bowersj2 9431:
9432: specifies header code to not have cache
9433:
9434: =cut
9435:
1.9 albertel 9436: sub no_cache {
1.216 albertel 9437: my ($r) = @_;
9438: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9439: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9440: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9441: $r->no_cache(1);
9442: $r->header_out("Expires" => $date);
9443: $r->header_out("Pragma" => "no-cache");
1.123 www 9444: }
9445:
9446: sub content_type {
1.181 albertel 9447: my ($r,$type,$charset) = @_;
1.299 foxr 9448: if ($r) {
9449: # Note that printout.pl calls this with undef for $r.
9450: &no_cache($r);
9451: }
1.258 albertel 9452: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9453: unless ($charset) {
9454: $charset=&Apache::lonlocal::current_encoding;
9455: }
9456: if ($charset) { $type.='; charset='.$charset; }
9457: if ($r) {
9458: $r->content_type($type);
9459: } else {
9460: print("Content-type: $type\n\n");
9461: }
1.9 albertel 9462: }
1.25 albertel 9463:
1.112 bowersj2 9464: =pod
9465:
1.648 raeburn 9466: =item * &add_to_env($name,$value)
1.112 bowersj2 9467:
1.258 albertel 9468: adds $name to the %env hash with value
1.112 bowersj2 9469: $value, if $name already exists, the entry is converted to an array
9470: reference and $value is added to the array.
9471:
9472: =cut
9473:
1.25 albertel 9474: sub add_to_env {
9475: my ($name,$value)=@_;
1.258 albertel 9476: if (defined($env{$name})) {
9477: if (ref($env{$name})) {
1.25 albertel 9478: #already have multiple values
1.258 albertel 9479: push(@{ $env{$name} },$value);
1.25 albertel 9480: } else {
9481: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9482: my $first=$env{$name};
9483: undef($env{$name});
9484: push(@{ $env{$name} },$first,$value);
1.25 albertel 9485: }
9486: } else {
1.258 albertel 9487: $env{$name}=$value;
1.25 albertel 9488: }
1.31 albertel 9489: }
1.149 albertel 9490:
9491: =pod
9492:
1.648 raeburn 9493: =item * &get_env_multiple($name)
1.149 albertel 9494:
1.258 albertel 9495: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9496: values may be defined and end up as an array ref.
9497:
9498: returns an array of values
9499:
9500: =cut
9501:
9502: sub get_env_multiple {
9503: my ($name) = @_;
9504: my @values;
1.258 albertel 9505: if (defined($env{$name})) {
1.149 albertel 9506: # exists is it an array
1.258 albertel 9507: if (ref($env{$name})) {
9508: @values=@{ $env{$name} };
1.149 albertel 9509: } else {
1.258 albertel 9510: $values[0]=$env{$name};
1.149 albertel 9511: }
9512: }
9513: return(@values);
9514: }
9515:
1.660 raeburn 9516: sub ask_for_embedded_content {
9517: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9518: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 9519: %currsubfile,%unused,$rem);
1.1071 raeburn 9520: my $counter = 0;
9521: my $numnew = 0;
1.987 raeburn 9522: my $numremref = 0;
9523: my $numinvalid = 0;
9524: my $numpathchg = 0;
9525: my $numexisting = 0;
1.1071 raeburn 9526: my $numunused = 0;
9527: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
9528: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
9529: my $heading = &mt('Upload embedded files');
9530: my $buttontext = &mt('Upload');
9531:
1.1075.2.11 raeburn 9532: my $navmap;
9533: if ($env{'request.course.id'}) {
9534: $navmap = Apache::lonnavmaps::navmap->new();
9535: }
1.984 raeburn 9536: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
9537: my $current_path='/';
9538: if ($env{'form.currentpath'}) {
9539: $current_path = $env{'form.currentpath'};
9540: }
9541: if ($actionurl eq '/adm/coursegrp_portfolio') {
9542: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9543: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
9544: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9545: } else {
9546: $udom = $env{'user.domain'};
9547: $uname = $env{'user.name'};
9548: $url = '/userfiles/portfolio';
9549: }
1.987 raeburn 9550: $toplevel = $url.'/';
1.984 raeburn 9551: $url .= $current_path;
9552: $getpropath = 1;
1.987 raeburn 9553: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9554: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9555: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9556: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9557: $toplevel = $url;
1.984 raeburn 9558: if ($rest ne '') {
1.987 raeburn 9559: $url .= $rest;
9560: }
9561: } elsif ($actionurl eq '/adm/coursedocs') {
9562: if (ref($args) eq 'HASH') {
1.1071 raeburn 9563: $url = $args->{'docs_url'};
9564: $toplevel = $url;
1.1075.2.11 raeburn 9565: if ($args->{'context'} eq 'paste') {
9566: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9567: ($path) =
9568: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9569: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9570: $fileloc =~ s{^/}{};
9571: }
1.1071 raeburn 9572: }
9573: } elsif ($actionurl eq '/adm/dependencies') {
9574: if ($env{'request.course.id'} ne '') {
9575: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9576: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9577: if (ref($args) eq 'HASH') {
9578: $url = $args->{'docs_url'};
9579: $title = $args->{'docs_title'};
9580: $toplevel = "/$url";
1.1075.2.11 raeburn 9581: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1071 raeburn 9582: ($path) =
9583: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9584: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9585: $fileloc =~ s{^/}{};
9586: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9587: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9588: }
1.987 raeburn 9589: }
9590: }
9591: my $now = time();
9592: foreach my $embed_file (keys(%{$allfiles})) {
9593: my $absolutepath;
9594: if ($embed_file =~ m{^\w+://}) {
9595: $newfiles{$embed_file} = 1;
9596: $mapping{$embed_file} = $embed_file;
9597: } else {
9598: if ($embed_file =~ m{^/}) {
9599: $absolutepath = $embed_file;
9600: $embed_file =~ s{^(/+)}{};
9601: }
9602: if ($embed_file =~ m{/}) {
9603: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
9604: $path = &check_for_traversal($path,$url,$toplevel);
9605: my $item = $fname;
9606: if ($path ne '') {
9607: $item = $path.'/'.$fname;
9608: $subdependencies{$path}{$fname} = 1;
9609: } else {
9610: $dependencies{$item} = 1;
9611: }
9612: if ($absolutepath) {
9613: $mapping{$item} = $absolutepath;
9614: } else {
9615: $mapping{$item} = $embed_file;
9616: }
9617: } else {
9618: $dependencies{$embed_file} = 1;
9619: if ($absolutepath) {
9620: $mapping{$embed_file} = $absolutepath;
9621: } else {
9622: $mapping{$embed_file} = $embed_file;
9623: }
9624: }
1.984 raeburn 9625: }
9626: }
1.1071 raeburn 9627: my $dirptr = 16384;
1.984 raeburn 9628: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9629: $currsubfile{$path} = {};
1.984 raeburn 9630: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9631: my ($sublistref,$listerror) =
9632: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9633: if (ref($sublistref) eq 'ARRAY') {
9634: foreach my $line (@{$sublistref}) {
9635: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9636: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9637: }
1.984 raeburn 9638: }
1.987 raeburn 9639: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9640: if (opendir(my $dir,$url.'/'.$path)) {
9641: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9642: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9643: }
1.1075.2.11 raeburn 9644: } elsif (($actionurl eq '/adm/dependencies') ||
9645: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9646: ($args->{'context'} eq 'paste'))) {
1.1071 raeburn 9647: if ($env{'request.course.id'} ne '') {
9648: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9649: if ($dir ne '') {
9650: my ($sublistref,$listerror) =
9651: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9652: if (ref($sublistref) eq 'ARRAY') {
9653: foreach my $line (@{$sublistref}) {
9654: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9655: undef,$mtime)=split(/\&/,$line,12);
9656: unless (($testdir&$dirptr) ||
9657: ($file_name =~ /^\.\.?$/)) {
9658: $currsubfile{$path}{$file_name} = [$size,$mtime];
9659: }
9660: }
9661: }
9662: }
1.984 raeburn 9663: }
9664: }
9665: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9666: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9667: my $item = $path.'/'.$file;
9668: unless ($mapping{$item} eq $item) {
9669: $pathchanges{$item} = 1;
9670: }
9671: $existing{$item} = 1;
9672: $numexisting ++;
9673: } else {
9674: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9675: }
9676: }
1.1071 raeburn 9677: if ($actionurl eq '/adm/dependencies') {
9678: foreach my $path (keys(%currsubfile)) {
9679: if (ref($currsubfile{$path}) eq 'HASH') {
9680: foreach my $file (keys(%{$currsubfile{$path}})) {
9681: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 9682: next if (($rem ne '') &&
9683: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9684: (ref($navmap) &&
9685: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9686: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9687: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9688: $unused{$path.'/'.$file} = 1;
9689: }
9690: }
9691: }
9692: }
9693: }
1.984 raeburn 9694: }
1.987 raeburn 9695: my %currfile;
1.984 raeburn 9696: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9697: my ($dirlistref,$listerror) =
9698: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9699: if (ref($dirlistref) eq 'ARRAY') {
9700: foreach my $line (@{$dirlistref}) {
9701: my ($file_name,$rest) = split(/\&/,$line,2);
9702: $currfile{$file_name} = 1;
9703: }
1.984 raeburn 9704: }
1.987 raeburn 9705: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9706: if (opendir(my $dir,$url)) {
1.987 raeburn 9707: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 9708: map {$currfile{$_} = 1;} @dir_list;
9709: }
1.1075.2.11 raeburn 9710: } elsif (($actionurl eq '/adm/dependencies') ||
9711: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9712: ($args->{'context'} eq 'paste'))) {
1.1071 raeburn 9713: if ($env{'request.course.id'} ne '') {
9714: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9715: if ($dir ne '') {
9716: my ($dirlistref,$listerror) =
9717: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
9718: if (ref($dirlistref) eq 'ARRAY') {
9719: foreach my $line (@{$dirlistref}) {
9720: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
9721: $size,undef,$mtime)=split(/\&/,$line,12);
9722: unless (($testdir&$dirptr) ||
9723: ($file_name =~ /^\.\.?$/)) {
9724: $currfile{$file_name} = [$size,$mtime];
9725: }
9726: }
9727: }
9728: }
9729: }
1.984 raeburn 9730: }
9731: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 9732: if (exists($currfile{$file})) {
1.987 raeburn 9733: unless ($mapping{$file} eq $file) {
9734: $pathchanges{$file} = 1;
9735: }
9736: $existing{$file} = 1;
9737: $numexisting ++;
9738: } else {
1.984 raeburn 9739: $newfiles{$file} = 1;
9740: }
9741: }
1.1071 raeburn 9742: foreach my $file (keys(%currfile)) {
9743: unless (($file eq $filename) ||
9744: ($file eq $filename.'.bak') ||
9745: ($dependencies{$file})) {
1.1075.2.11 raeburn 9746: if ($actionurl eq '/adm/dependencies') {
9747: next if (($rem ne '') &&
9748: (($env{"httpref.$rem".$file} ne '') ||
9749: (ref($navmap) &&
9750: (($navmap->getResourceByUrl($rem.$file) ne '') ||
9751: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9752: ($navmap->getResourceByUrl($rem.$1)))))));
9753: }
1.1071 raeburn 9754: $unused{$file} = 1;
9755: }
9756: }
1.1075.2.11 raeburn 9757: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9758: ($args->{'context'} eq 'paste')) {
9759: $counter = scalar(keys(%existing));
9760: $numpathchg = scalar(keys(%pathchanges));
9761: return ($output,$counter,$numpathchg,\%existing);
9762: }
1.984 raeburn 9763: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 9764: if ($actionurl eq '/adm/dependencies') {
9765: next if ($embed_file =~ m{^\w+://});
9766: }
1.660 raeburn 9767: $upload_output .= &start_data_table_row().
1.1071 raeburn 9768: '<td><img src="'.&icon($embed_file).'" /> '.
9769: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 9770: unless ($mapping{$embed_file} eq $embed_file) {
9771: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
9772: }
9773: $upload_output .= '</td><td>';
1.1071 raeburn 9774: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.660 raeburn 9775: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.987 raeburn 9776: $numremref++;
1.660 raeburn 9777: } elsif ($args->{'error_on_invalid_names'}
9778: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.987 raeburn 9779: $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
9780: $numinvalid++;
1.660 raeburn 9781: } else {
1.1071 raeburn 9782: $upload_output .= &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 9783: $embed_file,\%mapping,
1.1071 raeburn 9784: $allfiles,$codebase,'upload');
9785: $counter ++;
9786: $numnew ++;
1.987 raeburn 9787: }
9788: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
9789: }
9790: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 9791: if ($actionurl eq '/adm/dependencies') {
9792: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
9793: $modify_output .= &start_data_table_row().
9794: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
9795: '<img src="'.&icon($embed_file).'" border="0" />'.
9796: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
9797: '<td>'.$size.'</td>'.
9798: '<td>'.$mtime.'</td>'.
9799: '<td><label><input type="checkbox" name="mod_upload_dep" '.
9800: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
9801: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
9802: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
9803: &embedded_file_element('upload_embedded',$counter,
9804: $embed_file,\%mapping,
9805: $allfiles,$codebase,'modify').
9806: '</div></td>'.
9807: &end_data_table_row()."\n";
9808: $counter ++;
9809: } else {
9810: $upload_output .= &start_data_table_row().
9811: '<td><span class="LC_filename">'.$embed_file.'</span></td>';
9812: '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
9813: &Apache::loncommon::end_data_table_row()."\n";
9814: }
9815: }
9816: my $delidx = $counter;
9817: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
9818: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
9819: $delete_output .= &start_data_table_row().
9820: '<td><img src="'.&icon($oldfile).'" />'.
9821: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
9822: '<td>'.$size.'</td>'.
9823: '<td>'.$mtime.'</td>'.
9824: '<td><label><input type="checkbox" name="del_upload_dep" '.
9825: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
9826: &embedded_file_element('upload_embedded',$delidx,
9827: $oldfile,\%mapping,$allfiles,
9828: $codebase,'delete').'</td>'.
9829: &end_data_table_row()."\n";
9830: $numunused ++;
9831: $delidx ++;
1.987 raeburn 9832: }
9833: if ($upload_output) {
9834: $upload_output = &start_data_table().
9835: $upload_output.
9836: &end_data_table()."\n";
9837: }
1.1071 raeburn 9838: if ($modify_output) {
9839: $modify_output = &start_data_table().
9840: &start_data_table_header_row().
9841: '<th>'.&mt('File').'</th>'.
9842: '<th>'.&mt('Size (KB)').'</th>'.
9843: '<th>'.&mt('Modified').'</th>'.
9844: '<th>'.&mt('Upload replacement?').'</th>'.
9845: &end_data_table_header_row().
9846: $modify_output.
9847: &end_data_table()."\n";
9848: }
9849: if ($delete_output) {
9850: $delete_output = &start_data_table().
9851: &start_data_table_header_row().
9852: '<th>'.&mt('File').'</th>'.
9853: '<th>'.&mt('Size (KB)').'</th>'.
9854: '<th>'.&mt('Modified').'</th>'.
9855: '<th>'.&mt('Delete?').'</th>'.
9856: &end_data_table_header_row().
9857: $delete_output.
9858: &end_data_table()."\n";
9859: }
1.987 raeburn 9860: my $applies = 0;
9861: if ($numremref) {
9862: $applies ++;
9863: }
9864: if ($numinvalid) {
9865: $applies ++;
9866: }
9867: if ($numexisting) {
9868: $applies ++;
9869: }
1.1071 raeburn 9870: if ($counter || $numunused) {
1.987 raeburn 9871: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
9872: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 9873: $state.'<h3>'.$heading.'</h3>';
9874: if ($actionurl eq '/adm/dependencies') {
9875: if ($numnew) {
9876: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
9877: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
9878: $upload_output.'<br />'."\n";
9879: }
9880: if ($numexisting) {
9881: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
9882: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
9883: $modify_output.'<br />'."\n";
9884: $buttontext = &mt('Save changes');
9885: }
9886: if ($numunused) {
9887: $output .= '<h4>'.&mt('Unused files').'</h4>'.
9888: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
9889: $delete_output.'<br />'."\n";
9890: $buttontext = &mt('Save changes');
9891: }
9892: } else {
9893: $output .= $upload_output.'<br />'."\n";
9894: }
9895: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
9896: $counter.'" />'."\n";
9897: if ($actionurl eq '/adm/dependencies') {
9898: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
9899: $numnew.'" />'."\n";
9900: } elsif ($actionurl eq '') {
1.987 raeburn 9901: $output .= '<input type="hidden" name="phase" value="three" />';
9902: }
9903: } elsif ($applies) {
9904: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
9905: if ($applies > 1) {
9906: $output .=
9907: &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
9908: if ($numremref) {
9909: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
9910: }
9911: if ($numinvalid) {
9912: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
9913: }
9914: if ($numexisting) {
9915: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
9916: }
9917: $output .= '</ul><br />';
9918: } elsif ($numremref) {
9919: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
9920: } elsif ($numinvalid) {
9921: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
9922: } elsif ($numexisting) {
9923: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
9924: }
9925: $output .= $upload_output.'<br />';
9926: }
9927: my ($pathchange_output,$chgcount);
1.1071 raeburn 9928: $chgcount = $counter;
1.987 raeburn 9929: if (keys(%pathchanges) > 0) {
9930: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 9931: if ($counter) {
1.987 raeburn 9932: $output .= &embedded_file_element('pathchange',$chgcount,
9933: $embed_file,\%mapping,
1.1071 raeburn 9934: $allfiles,$codebase,'change');
1.987 raeburn 9935: } else {
9936: $pathchange_output .=
9937: &start_data_table_row().
9938: '<td><input type ="checkbox" name="namechange" value="'.
9939: $chgcount.'" checked="checked" /></td>'.
9940: '<td>'.$mapping{$embed_file}.'</td>'.
9941: '<td>'.$embed_file.
9942: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 9943: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 9944: '</td>'.&end_data_table_row();
1.660 raeburn 9945: }
1.987 raeburn 9946: $numpathchg ++;
9947: $chgcount ++;
1.660 raeburn 9948: }
9949: }
1.1071 raeburn 9950: if ($counter) {
1.987 raeburn 9951: if ($numpathchg) {
9952: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
9953: $numpathchg.'" />'."\n";
9954: }
9955: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9956: ($actionurl eq '/adm/imsimport')) {
9957: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
9958: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
9959: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 9960: } elsif ($actionurl eq '/adm/dependencies') {
9961: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 9962: }
1.1071 raeburn 9963: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 9964: } elsif ($numpathchg) {
9965: my %pathchange = ();
9966: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
9967: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
9968: $output .= '<p>'.&mt('or').'</p>';
9969: }
9970: }
1.1071 raeburn 9971: return ($output,$counter,$numpathchg);
1.987 raeburn 9972: }
9973:
9974: sub embedded_file_element {
1.1071 raeburn 9975: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 9976: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
9977: (ref($codebase) eq 'HASH'));
9978: my $output;
1.1071 raeburn 9979: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 9980: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
9981: }
9982: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
9983: &escape($embed_file).'" />';
9984: unless (($context eq 'upload_embedded') &&
9985: ($mapping->{$embed_file} eq $embed_file)) {
9986: $output .='
9987: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
9988: }
9989: my $attrib;
9990: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
9991: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
9992: }
9993: $output .=
9994: "\n\t\t".
9995: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
9996: $attrib.'" />';
9997: if (exists($codebase->{$mapping->{$embed_file}})) {
9998: $output .=
9999: "\n\t\t".
10000: '<input name="codebase_'.$num.'" type="hidden" value="'.
10001: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10002: }
1.987 raeburn 10003: return $output;
1.660 raeburn 10004: }
10005:
1.1071 raeburn 10006: sub get_dependency_details {
10007: my ($currfile,$currsubfile,$embed_file) = @_;
10008: my ($size,$mtime,$showsize,$showmtime);
10009: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10010: if ($embed_file =~ m{/}) {
10011: my ($path,$fname) = split(/\//,$embed_file);
10012: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10013: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10014: }
10015: } else {
10016: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10017: ($size,$mtime) = @{$currfile->{$embed_file}};
10018: }
10019: }
10020: $showsize = $size/1024.0;
10021: $showsize = sprintf("%.1f",$showsize);
10022: if ($mtime > 0) {
10023: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10024: }
10025: }
10026: return ($showsize,$showmtime);
10027: }
10028:
10029: sub ask_embedded_js {
10030: return <<"END";
10031: <script type="text/javascript"">
10032: // <![CDATA[
10033: function toggleBrowse(counter) {
10034: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10035: var fileid = document.getElementById('embedded_item_'+counter);
10036: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10037: if (chkboxid.checked == true) {
10038: uploaddivid.style.display='block';
10039: } else {
10040: uploaddivid.style.display='none';
10041: fileid.value = '';
10042: }
10043: }
10044: // ]]>
10045: </script>
10046:
10047: END
10048: }
10049:
1.661 raeburn 10050: sub upload_embedded {
10051: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10052: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10053: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10054: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10055: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10056: my $orig_uploaded_filename =
10057: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10058: foreach my $type ('orig','ref','attrib','codebase') {
10059: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10060: $env{'form.embedded_'.$type.'_'.$i} =
10061: &unescape($env{'form.embedded_'.$type.'_'.$i});
10062: }
10063: }
1.661 raeburn 10064: my ($path,$fname) =
10065: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10066: # no path, whole string is fname
10067: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10068: $fname = &Apache::lonnet::clean_filename($fname);
10069: # See if there is anything left
10070: next if ($fname eq '');
10071:
10072: # Check if file already exists as a file or directory.
10073: my ($state,$msg);
10074: if ($context eq 'portfolio') {
10075: my $port_path = $dirpath;
10076: if ($group ne '') {
10077: $port_path = "groups/$group/$port_path";
10078: }
1.987 raeburn 10079: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10080: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10081: $dir_root,$port_path,$disk_quota,
10082: $current_disk_usage,$uname,$udom);
10083: if ($state eq 'will_exceed_quota'
1.984 raeburn 10084: || $state eq 'file_locked') {
1.661 raeburn 10085: $output .= $msg;
10086: next;
10087: }
10088: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10089: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10090: if ($state eq 'exists') {
10091: $output .= $msg;
10092: next;
10093: }
10094: }
10095: # Check if extension is valid
10096: if (($fname =~ /\.(\w+)$/) &&
10097: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987 raeburn 10098: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1).'<br />';
1.661 raeburn 10099: next;
10100: } elsif (($fname =~ /\.(\w+)$/) &&
10101: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10102: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10103: next;
10104: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.987 raeburn 10105: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661 raeburn 10106: next;
10107: }
10108: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
10109: if ($context eq 'portfolio') {
1.984 raeburn 10110: my $result;
10111: if ($state eq 'existingfile') {
10112: $result=
10113: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.987 raeburn 10114: $dirpath.$env{'form.currentpath'}.$path);
1.661 raeburn 10115: } else {
1.984 raeburn 10116: $result=
10117: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10118: $dirpath.
10119: $env{'form.currentpath'}.$path);
1.984 raeburn 10120: if ($result !~ m|^/uploaded/|) {
10121: $output .= '<span class="LC_error">'
10122: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10123: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10124: .'</span><br />';
10125: next;
10126: } else {
1.987 raeburn 10127: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10128: $path.$fname.'</span>').'<br />';
1.984 raeburn 10129: }
1.661 raeburn 10130: }
1.987 raeburn 10131: } elsif ($context eq 'coursedoc') {
10132: my $result =
10133: &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
10134: $dirpath.'/'.$path);
10135: if ($result !~ m|^/uploaded/|) {
10136: $output .= '<span class="LC_error">'
10137: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10138: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10139: .'</span><br />';
10140: next;
10141: } else {
10142: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10143: $path.$fname.'</span>').'<br />';
10144: }
1.661 raeburn 10145: } else {
10146: # Save the file
10147: my $target = $env{'form.embedded_item_'.$i};
10148: my $fullpath = $dir_root.$dirpath.'/'.$path;
10149: my $dest = $fullpath.$fname;
10150: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10151: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10152: my $count;
10153: my $filepath = $dir_root;
1.1027 raeburn 10154: foreach my $subdir (@parts) {
10155: $filepath .= "/$subdir";
10156: if (!-e $filepath) {
1.661 raeburn 10157: mkdir($filepath,0770);
10158: }
10159: }
10160: my $fh;
10161: if (!open($fh,'>'.$dest)) {
10162: &Apache::lonnet::logthis('Failed to create '.$dest);
10163: $output .= '<span class="LC_error">'.
1.1071 raeburn 10164: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10165: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10166: '</span><br />';
10167: } else {
10168: if (!print $fh $env{'form.embedded_item_'.$i}) {
10169: &Apache::lonnet::logthis('Failed to write to '.$dest);
10170: $output .= '<span class="LC_error">'.
1.1071 raeburn 10171: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10172: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10173: '</span><br />';
10174: } else {
1.987 raeburn 10175: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10176: $url.'</span>').'<br />';
10177: unless ($context eq 'testbank') {
10178: $footer .= &mt('View embedded file: [_1]',
10179: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10180: }
10181: }
10182: close($fh);
10183: }
10184: }
10185: if ($env{'form.embedded_ref_'.$i}) {
10186: $pathchange{$i} = 1;
10187: }
10188: }
10189: if ($output) {
10190: $output = '<p>'.$output.'</p>';
10191: }
10192: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10193: $returnflag = 'ok';
1.1071 raeburn 10194: my $numpathchgs = scalar(keys(%pathchange));
10195: if ($numpathchgs > 0) {
1.987 raeburn 10196: if ($context eq 'portfolio') {
10197: $output .= '<p>'.&mt('or').'</p>';
10198: } elsif ($context eq 'testbank') {
1.1071 raeburn 10199: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10200: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10201: $returnflag = 'modify_orightml';
10202: }
10203: }
1.1071 raeburn 10204: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10205: }
10206:
10207: sub modify_html_form {
10208: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10209: my $end = 0;
10210: my $modifyform;
10211: if ($context eq 'upload_embedded') {
10212: return unless (ref($pathchange) eq 'HASH');
10213: if ($env{'form.number_embedded_items'}) {
10214: $end += $env{'form.number_embedded_items'};
10215: }
10216: if ($env{'form.number_pathchange_items'}) {
10217: $end += $env{'form.number_pathchange_items'};
10218: }
10219: if ($end) {
10220: for (my $i=0; $i<$end; $i++) {
10221: if ($i < $env{'form.number_embedded_items'}) {
10222: next unless($pathchange->{$i});
10223: }
10224: $modifyform .=
10225: &start_data_table_row().
10226: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10227: 'checked="checked" /></td>'.
10228: '<td>'.$env{'form.embedded_ref_'.$i}.
10229: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10230: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10231: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10232: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10233: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10234: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10235: '<td>'.$env{'form.embedded_orig_'.$i}.
10236: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10237: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10238: &end_data_table_row();
1.1071 raeburn 10239: }
1.987 raeburn 10240: }
10241: } else {
10242: $modifyform = $pathchgtable;
10243: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10244: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10245: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10246: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10247: }
10248: }
10249: if ($modifyform) {
1.1071 raeburn 10250: if ($actionurl eq '/adm/dependencies') {
10251: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10252: }
1.987 raeburn 10253: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10254: '<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".
10255: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10256: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10257: '</ol></p>'."\n".'<p>'.
10258: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10259: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10260: &start_data_table()."\n".
10261: &start_data_table_header_row().
10262: '<th>'.&mt('Change?').'</th>'.
10263: '<th>'.&mt('Current reference').'</th>'.
10264: '<th>'.&mt('Required reference').'</th>'.
10265: &end_data_table_header_row()."\n".
10266: $modifyform.
10267: &end_data_table().'<br />'."\n".$hiddenstate.
10268: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10269: '</form>'."\n";
10270: }
10271: return;
10272: }
10273:
10274: sub modify_html_refs {
10275: my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
10276: my $container;
10277: if ($context eq 'portfolio') {
10278: $container = $env{'form.container'};
10279: } elsif ($context eq 'coursedoc') {
10280: $container = $env{'form.primaryurl'};
1.1071 raeburn 10281: } elsif ($context eq 'manage_dependencies') {
10282: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10283: $container = "/$container";
1.987 raeburn 10284: } else {
1.1027 raeburn 10285: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10286: }
10287: my (%allfiles,%codebase,$output,$content);
10288: my @changes = &get_env_multiple('form.namechange');
1.1071 raeburn 10289: unless (@changes > 0) {
10290: if (wantarray) {
10291: return ('',0,0);
10292: } else {
10293: return;
10294: }
10295: }
10296: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
10297: ($context eq 'manage_dependencies')) {
10298: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10299: if (wantarray) {
10300: return ('',0,0);
10301: } else {
10302: return;
10303: }
10304: }
1.987 raeburn 10305: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10306: if ($content eq '-1') {
10307: if (wantarray) {
10308: return ('',0,0);
10309: } else {
10310: return;
10311: }
10312: }
1.987 raeburn 10313: } else {
1.1071 raeburn 10314: unless ($container =~ /^\Q$dir_root\E/) {
10315: if (wantarray) {
10316: return ('',0,0);
10317: } else {
10318: return;
10319: }
10320: }
1.987 raeburn 10321: if (open(my $fh,"<$container")) {
10322: $content = join('', <$fh>);
10323: close($fh);
10324: } else {
1.1071 raeburn 10325: if (wantarray) {
10326: return ('',0,0);
10327: } else {
10328: return;
10329: }
1.987 raeburn 10330: }
10331: }
10332: my ($count,$codebasecount) = (0,0);
10333: my $mm = new File::MMagic;
10334: my $mime_type = $mm->checktype_contents($content);
10335: if ($mime_type eq 'text/html') {
10336: my $parse_result =
10337: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10338: \%codebase,\$content);
10339: if ($parse_result eq 'ok') {
10340: foreach my $i (@changes) {
10341: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10342: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10343: if ($allfiles{$ref}) {
10344: my $newname = $orig;
10345: my ($attrib_regexp,$codebase);
1.1006 raeburn 10346: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10347: if ($attrib_regexp =~ /:/) {
10348: $attrib_regexp =~ s/\:/|/g;
10349: }
10350: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10351: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10352: $count += $numchg;
10353: }
10354: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10355: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10356: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10357: $codebasecount ++;
10358: }
10359: }
10360: }
10361: if ($count || $codebasecount) {
10362: my $saveresult;
1.1071 raeburn 10363: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
10364: ($context eq 'manage_dependencies')) {
1.987 raeburn 10365: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10366: if ($url eq $container) {
10367: my ($fname) = ($container =~ m{/([^/]+)$});
10368: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10369: $count,'<span class="LC_filename">'.
1.1071 raeburn 10370: $fname.'</span>').'</p>';
1.987 raeburn 10371: } else {
10372: $output = '<p class="LC_error">'.
10373: &mt('Error: update failed for: [_1].',
10374: '<span class="LC_filename">'.
10375: $container.'</span>').'</p>';
10376: }
10377: } else {
10378: if (open(my $fh,">$container")) {
10379: print $fh $content;
10380: close($fh);
10381: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10382: $count,'<span class="LC_filename">'.
10383: $container.'</span>').'</p>';
1.661 raeburn 10384: } else {
1.987 raeburn 10385: $output = '<p class="LC_error">'.
10386: &mt('Error: could not update [_1].',
10387: '<span class="LC_filename">'.
10388: $container.'</span>').'</p>';
1.661 raeburn 10389: }
10390: }
10391: }
1.987 raeburn 10392: } else {
10393: &logthis('Failed to parse '.$container.
10394: ' to modify references: '.$parse_result);
1.661 raeburn 10395: }
10396: }
1.1071 raeburn 10397: if (wantarray) {
10398: return ($output,$count,$codebasecount);
10399: } else {
10400: return $output;
10401: }
1.661 raeburn 10402: }
10403:
10404: sub check_for_existing {
10405: my ($path,$fname,$element) = @_;
10406: my ($state,$msg);
10407: if (-d $path.'/'.$fname) {
10408: $state = 'exists';
10409: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10410: } elsif (-e $path.'/'.$fname) {
10411: $state = 'exists';
10412: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10413: }
10414: if ($state eq 'exists') {
10415: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10416: }
10417: return ($state,$msg);
10418: }
10419:
10420: sub check_for_upload {
10421: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10422: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10423: my $filesize = length($env{'form.'.$element});
10424: if (!$filesize) {
10425: my $msg = '<span class="LC_error">'.
10426: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10427: '<span class="LC_filename">'.$fname.'</span>',
10428: $filesize).'<br />'.
1.1007 raeburn 10429: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10430: '</span>';
10431: return ('zero_bytes',$msg);
10432: }
10433: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10434: my $getpropath = 1;
1.1021 raeburn 10435: my ($dirlistref,$listerror) =
10436: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10437: my $found_file = 0;
10438: my $locked_file = 0;
1.991 raeburn 10439: my @lockers;
10440: my $navmap;
10441: if ($env{'request.course.id'}) {
10442: $navmap = Apache::lonnavmaps::navmap->new();
10443: }
1.1021 raeburn 10444: if (ref($dirlistref) eq 'ARRAY') {
10445: foreach my $line (@{$dirlistref}) {
10446: my ($file_name,$rest)=split(/\&/,$line,2);
10447: if ($file_name eq $fname){
10448: $file_name = $path.$file_name;
10449: if ($group ne '') {
10450: $file_name = $group.$file_name;
10451: }
10452: $found_file = 1;
10453: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10454: foreach my $lock (@lockers) {
10455: if (ref($lock) eq 'ARRAY') {
10456: my ($symb,$crsid) = @{$lock};
10457: if ($crsid eq $env{'request.course.id'}) {
10458: if (ref($navmap)) {
10459: my $res = $navmap->getBySymb($symb);
10460: foreach my $part (@{$res->parts()}) {
10461: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10462: unless (($slot_status == $res->RESERVED) ||
10463: ($slot_status == $res->RESERVED_LOCATION)) {
10464: $locked_file = 1;
10465: }
1.991 raeburn 10466: }
1.1021 raeburn 10467: } else {
10468: $locked_file = 1;
1.991 raeburn 10469: }
10470: } else {
10471: $locked_file = 1;
10472: }
10473: }
1.1021 raeburn 10474: }
10475: } else {
10476: my @info = split(/\&/,$rest);
10477: my $currsize = $info[6]/1000;
10478: if ($currsize < $filesize) {
10479: my $extra = $filesize - $currsize;
10480: if (($current_disk_usage + $extra) > $disk_quota) {
10481: my $msg = '<span class="LC_error">'.
10482: &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.',
10483: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10484: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10485: $disk_quota,$current_disk_usage);
10486: return ('will_exceed_quota',$msg);
10487: }
1.984 raeburn 10488: }
10489: }
1.661 raeburn 10490: }
10491: }
10492: }
10493: if (($current_disk_usage + $filesize) > $disk_quota){
10494: my $msg = '<span class="LC_error">'.
10495: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10496: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10497: return ('will_exceed_quota',$msg);
10498: } elsif ($found_file) {
10499: if ($locked_file) {
10500: my $msg = '<span class="LC_error">';
10501: $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>');
10502: $msg .= '</span><br />';
10503: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10504: return ('file_locked',$msg);
10505: } else {
10506: my $msg = '<span class="LC_error">';
1.984 raeburn 10507: $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 10508: $msg .= '</span>';
1.984 raeburn 10509: return ('existingfile',$msg);
1.661 raeburn 10510: }
10511: }
10512: }
10513:
1.987 raeburn 10514: sub check_for_traversal {
10515: my ($path,$url,$toplevel) = @_;
10516: my @parts=split(/\//,$path);
10517: my $cleanpath;
10518: my $fullpath = $url;
10519: for (my $i=0;$i<@parts;$i++) {
10520: next if ($parts[$i] eq '.');
10521: if ($parts[$i] eq '..') {
10522: $fullpath =~ s{([^/]+/)$}{};
10523: } else {
10524: $fullpath .= $parts[$i].'/';
10525: }
10526: }
10527: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10528: $cleanpath = $1;
10529: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10530: my $curr_toprel = $1;
10531: my @parts = split(/\//,$curr_toprel);
10532: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10533: my @urlparts = split(/\//,$url_toprel);
10534: my $doubledots;
10535: my $startdiff = -1;
10536: for (my $i=0; $i<@urlparts; $i++) {
10537: if ($startdiff == -1) {
10538: unless ($urlparts[$i] eq $parts[$i]) {
10539: $startdiff = $i;
10540: $doubledots .= '../';
10541: }
10542: } else {
10543: $doubledots .= '../';
10544: }
10545: }
10546: if ($startdiff > -1) {
10547: $cleanpath = $doubledots;
10548: for (my $i=$startdiff; $i<@parts; $i++) {
10549: $cleanpath .= $parts[$i].'/';
10550: }
10551: }
10552: }
10553: $cleanpath =~ s{(/)$}{};
10554: return $cleanpath;
10555: }
1.31 albertel 10556:
1.1053 raeburn 10557: sub is_archive_file {
10558: my ($mimetype) = @_;
10559: if (($mimetype eq 'application/octet-stream') ||
10560: ($mimetype eq 'application/x-stuffit') ||
10561: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10562: return 1;
10563: }
10564: return;
10565: }
10566:
10567: sub decompress_form {
1.1065 raeburn 10568: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10569: my %lt = &Apache::lonlocal::texthash (
10570: this => 'This file is an archive file.',
1.1067 raeburn 10571: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10572: itsc => 'Its contents are as follows:',
1.1053 raeburn 10573: youm => 'You may wish to extract its contents.',
10574: extr => 'Extract contents',
1.1067 raeburn 10575: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10576: proa => 'Process automatically?',
1.1053 raeburn 10577: yes => 'Yes',
10578: no => 'No',
1.1067 raeburn 10579: fold => 'Title for folder containing movie',
10580: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10581: );
1.1065 raeburn 10582: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10583: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10584: my $info = &list_archive_contents($fileloc,\@paths);
10585: if (@paths) {
10586: foreach my $path (@paths) {
10587: $path =~ s{^/}{};
1.1067 raeburn 10588: if ($path =~ m{^([^/]+)/$}) {
10589: $topdir = $1;
10590: }
1.1065 raeburn 10591: if ($path =~ m{^([^/]+)/}) {
10592: $toplevel{$1} = $path;
10593: } else {
10594: $toplevel{$path} = $path;
10595: }
10596: }
10597: }
1.1067 raeburn 10598: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
10599: my @camtasia = ("$topdir/","$topdir/index.html",
10600: "$topdir/media/",
10601: "$topdir/media/$topdir.mp4",
10602: "$topdir/media/FirstFrame.png",
10603: "$topdir/media/player.swf",
10604: "$topdir/media/swfobject.js",
10605: "$topdir/media/expressInstall.swf");
10606: my @diffs = &compare_arrays(\@paths,\@camtasia);
10607: if (@diffs == 0) {
10608: $is_camtasia = 1;
10609: }
10610: }
10611: my $output;
10612: if ($is_camtasia) {
10613: $output = <<"ENDCAM";
10614: <script type="text/javascript" language="Javascript">
10615: // <![CDATA[
10616:
10617: function camtasiaToggle() {
10618: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
10619: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
10620: if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
10621:
10622: document.getElementById('camtasia_titles').style.display='block';
10623: } else {
10624: document.getElementById('camtasia_titles').style.display='none';
10625: }
10626: }
10627: }
10628: return;
10629: }
10630:
10631: // ]]>
10632: </script>
10633: <p>$lt{'camt'}</p>
10634: ENDCAM
1.1065 raeburn 10635: } else {
1.1067 raeburn 10636: $output = '<p>'.$lt{'this'};
10637: if ($info eq '') {
10638: $output .= ' '.$lt{'youm'}.'</p>'."\n";
10639: } else {
10640: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
10641: '<div><pre>'.$info.'</pre></div>';
10642: }
1.1065 raeburn 10643: }
1.1067 raeburn 10644: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 10645: my $duplicates;
10646: my $num = 0;
10647: if (ref($dirlist) eq 'ARRAY') {
10648: foreach my $item (@{$dirlist}) {
10649: if (ref($item) eq 'ARRAY') {
10650: if (exists($toplevel{$item->[0]})) {
10651: $duplicates .=
10652: &start_data_table_row().
10653: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
10654: 'value="0" checked="checked" />'.&mt('No').'</label>'.
10655: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
10656: 'value="1" />'.&mt('Yes').'</label>'.
10657: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
10658: '<td>'.$item->[0].'</td>';
10659: if ($item->[2]) {
10660: $duplicates .= '<td>'.&mt('Directory').'</td>';
10661: } else {
10662: $duplicates .= '<td>'.&mt('File').'</td>';
10663: }
10664: $duplicates .= '<td>'.$item->[3].'</td>'.
10665: '<td>'.
10666: &Apache::lonlocal::locallocaltime($item->[4]).
10667: '</td>'.
10668: &end_data_table_row();
10669: $num ++;
10670: }
10671: }
10672: }
10673: }
10674: my $itemcount;
10675: if (@paths > 0) {
10676: $itemcount = scalar(@paths);
10677: } else {
10678: $itemcount = 1;
10679: }
1.1067 raeburn 10680: if ($is_camtasia) {
10681: $output .= $lt{'auto'}.'<br />'.
10682: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
10683: '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
10684: $lt{'yes'}.'</label> <label>'.
10685: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
10686: $lt{'no'}.'</label></span><br />'.
10687: '<div id="camtasia_titles" style="display:block">'.
10688: &Apache::lonhtmlcommon::start_pick_box().
10689: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
10690: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
10691: &Apache::lonhtmlcommon::row_closure().
10692: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
10693: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
10694: &Apache::lonhtmlcommon::row_closure(1).
10695: &Apache::lonhtmlcommon::end_pick_box().
10696: '</div>';
10697: }
1.1065 raeburn 10698: $output .=
10699: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 10700: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
10701: "\n";
1.1065 raeburn 10702: if ($duplicates ne '') {
10703: $output .= '<p><span class="LC_warning">'.
10704: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
10705: &start_data_table().
10706: &start_data_table_header_row().
10707: '<th>'.&mt('Overwrite?').'</th>'.
10708: '<th>'.&mt('Name').'</th>'.
10709: '<th>'.&mt('Type').'</th>'.
10710: '<th>'.&mt('Size').'</th>'.
10711: '<th>'.&mt('Last modified').'</th>'.
10712: &end_data_table_header_row().
10713: $duplicates.
10714: &end_data_table().
10715: '</p>';
10716: }
1.1067 raeburn 10717: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 10718: if (ref($hiddenelements) eq 'HASH') {
10719: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
10720: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
10721: }
10722: }
10723: $output .= <<"END";
1.1067 raeburn 10724: <br />
1.1053 raeburn 10725: <input type="submit" name="decompress" value="$lt{'extr'}" />
10726: </form>
10727: $noextract
10728: END
10729: return $output;
10730: }
10731:
1.1065 raeburn 10732: sub decompression_utility {
10733: my ($program) = @_;
10734: my @utilities = ('tar','gunzip','bunzip2','unzip');
10735: my $location;
10736: if (grep(/^\Q$program\E$/,@utilities)) {
10737: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
10738: '/usr/sbin/') {
10739: if (-x $dir.$program) {
10740: $location = $dir.$program;
10741: last;
10742: }
10743: }
10744: }
10745: return $location;
10746: }
10747:
10748: sub list_archive_contents {
10749: my ($file,$pathsref) = @_;
10750: my (@cmd,$output);
10751: my $needsregexp;
10752: if ($file =~ /\.zip$/) {
10753: @cmd = (&decompression_utility('unzip'),"-l");
10754: $needsregexp = 1;
10755: } elsif (($file =~ m/\.tar\.gz$/) ||
10756: ($file =~ /\.tgz$/)) {
10757: @cmd = (&decompression_utility('tar'),"-ztf");
10758: } elsif ($file =~ /\.tar\.bz2$/) {
10759: @cmd = (&decompression_utility('tar'),"-jtf");
10760: } elsif ($file =~ m|\.tar$|) {
10761: @cmd = (&decompression_utility('tar'),"-tf");
10762: }
10763: if (@cmd) {
10764: undef($!);
10765: undef($@);
10766: if (open(my $fh,"-|", @cmd, $file)) {
10767: while (my $line = <$fh>) {
10768: $output .= $line;
10769: chomp($line);
10770: my $item;
10771: if ($needsregexp) {
10772: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
10773: } else {
10774: $item = $line;
10775: }
10776: if ($item ne '') {
10777: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
10778: push(@{$pathsref},$item);
10779: }
10780: }
10781: }
10782: close($fh);
10783: }
10784: }
10785: return $output;
10786: }
10787:
1.1053 raeburn 10788: sub decompress_uploaded_file {
10789: my ($file,$dir) = @_;
10790: &Apache::lonnet::appenv({'cgi.file' => $file});
10791: &Apache::lonnet::appenv({'cgi.dir' => $dir});
10792: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
10793: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
10794: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
10795: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
10796: my $decompressed = $env{'cgi.decompressed'};
10797: &Apache::lonnet::delenv('cgi.file');
10798: &Apache::lonnet::delenv('cgi.dir');
10799: &Apache::lonnet::delenv('cgi.decompressed');
10800: return ($decompressed,$result);
10801: }
10802:
1.1055 raeburn 10803: sub process_decompression {
10804: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
10805: my ($dir,$error,$warning,$output);
10806: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
10807: $error = &mt('File name not a supported archive file type.').
10808: '<br />'.&mt('File name should end with one of: [_1].',
10809: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
10810: } else {
10811: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
10812: if ($docuhome eq 'no_host') {
10813: $error = &mt('Could not determine home server for course.');
10814: } else {
10815: my @ids=&Apache::lonnet::current_machine_ids();
10816: my $currdir = "$dir_root/$destination";
10817: if (grep(/^\Q$docuhome\E$/,@ids)) {
10818: $dir = &LONCAPA::propath($docudom,$docuname).
10819: "$dir_root/$destination";
10820: } else {
10821: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
10822: "$dir_root/$docudom/$docuname/$destination";
10823: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
10824: $error = &mt('Archive file not found.');
10825: }
10826: }
1.1065 raeburn 10827: my (@to_overwrite,@to_skip);
10828: if ($env{'form.archive_overwrite_total'} > 0) {
10829: my $total = $env{'form.archive_overwrite_total'};
10830: for (my $i=0; $i<$total; $i++) {
10831: if ($env{'form.archive_overwrite_'.$i} == 1) {
10832: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
10833: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
10834: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
10835: }
10836: }
10837: }
10838: my $numskip = scalar(@to_skip);
10839: if (($numskip > 0) &&
10840: ($numskip == $env{'form.archive_itemcount'})) {
10841: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
10842: } elsif ($dir eq '') {
1.1055 raeburn 10843: $error = &mt('Directory containing archive file unavailable.');
10844: } elsif (!$error) {
1.1065 raeburn 10845: my ($decompressed,$display);
10846: if ($numskip > 0) {
10847: my $tempdir = time.'_'.$$.int(rand(10000));
10848: mkdir("$dir/$tempdir",0755);
10849: system("mv $dir/$file $dir/$tempdir/$file");
10850: ($decompressed,$display) =
10851: &decompress_uploaded_file($file,"$dir/$tempdir");
10852: foreach my $item (@to_skip) {
10853: if (($item ne '') && ($item !~ /\.\./)) {
10854: if (-f "$dir/$tempdir/$item") {
10855: unlink("$dir/$tempdir/$item");
10856: } elsif (-d "$dir/$tempdir/$item") {
10857: system("rm -rf $dir/$tempdir/$item");
10858: }
10859: }
10860: }
10861: system("mv $dir/$tempdir/* $dir");
10862: rmdir("$dir/$tempdir");
10863: } else {
10864: ($decompressed,$display) =
10865: &decompress_uploaded_file($file,$dir);
10866: }
1.1055 raeburn 10867: if ($decompressed eq 'ok') {
1.1065 raeburn 10868: $output = '<p class="LC_info">'.
10869: &mt('Files extracted successfully from archive.').
10870: '</p>'."\n";
1.1055 raeburn 10871: my ($warning,$result,@contents);
10872: my ($newdirlistref,$newlisterror) =
10873: &Apache::lonnet::dirlist($currdir,$docudom,
10874: $docuname,1);
10875: my (%is_dir,%changes,@newitems);
10876: my $dirptr = 16384;
1.1065 raeburn 10877: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 10878: foreach my $dir_line (@{$newdirlistref}) {
10879: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 10880: unless (($item =~ /^\.+$/) || ($item eq $file) ||
10881: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 10882: push(@newitems,$item);
10883: if ($dirptr&$testdir) {
10884: $is_dir{$item} = 1;
10885: }
10886: $changes{$item} = 1;
10887: }
10888: }
10889: }
10890: if (keys(%changes) > 0) {
10891: foreach my $item (sort(@newitems)) {
10892: if ($changes{$item}) {
10893: push(@contents,$item);
10894: }
10895: }
10896: }
10897: if (@contents > 0) {
1.1067 raeburn 10898: my $wantform;
10899: unless ($env{'form.autoextract_camtasia'}) {
10900: $wantform = 1;
10901: }
1.1056 raeburn 10902: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 10903: my ($count,$datatable) = &get_extracted($docudom,$docuname,
10904: $currdir,\%is_dir,
10905: \%children,\%parent,
1.1056 raeburn 10906: \@contents,\%dirorder,
10907: \%titles,$wantform);
1.1055 raeburn 10908: if ($datatable ne '') {
10909: $output .= &archive_options_form('decompressed',$datatable,
10910: $count,$hiddenelem);
1.1065 raeburn 10911: my $startcount = 6;
1.1055 raeburn 10912: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 10913: \%titles,\%children);
1.1055 raeburn 10914: }
1.1067 raeburn 10915: if ($env{'form.autoextract_camtasia'}) {
10916: my %displayed;
10917: my $total = 1;
10918: $env{'form.archive_directory'} = [];
10919: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
10920: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
10921: $path =~ s{/$}{};
10922: my $item;
10923: if ($path ne '') {
10924: $item = "$path/$titles{$i}";
10925: } else {
10926: $item = $titles{$i};
10927: }
10928: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
10929: if ($item eq $contents[0]) {
10930: push(@{$env{'form.archive_directory'}},$i);
10931: $env{'form.archive_'.$i} = 'display';
10932: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
10933: $displayed{'folder'} = $i;
10934: } elsif ($item eq "$contents[0]/index.html") {
10935: $env{'form.archive_'.$i} = 'display';
10936: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
10937: $displayed{'web'} = $i;
10938: } else {
10939: if ($item eq "$contents[0]/media") {
10940: push(@{$env{'form.archive_directory'}},$i);
10941: }
10942: $env{'form.archive_'.$i} = 'dependency';
10943: }
10944: $total ++;
10945: }
10946: for (my $i=1; $i<$total; $i++) {
10947: next if ($i == $displayed{'web'});
10948: next if ($i == $displayed{'folder'});
10949: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
10950: }
10951: $env{'form.phase'} = 'decompress_cleanup';
10952: $env{'form.archivedelete'} = 1;
10953: $env{'form.archive_count'} = $total-1;
10954: $output .=
10955: &process_extracted_files('coursedocs',$docudom,
10956: $docuname,$destination,
10957: $dir_root,$hiddenelem);
10958: }
1.1055 raeburn 10959: } else {
10960: $warning = &mt('No new items extracted from archive file.');
10961: }
10962: } else {
10963: $output = $display;
10964: $error = &mt('An error occurred during extraction from the archive file.');
10965: }
10966: }
10967: }
10968: }
10969: if ($error) {
10970: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
10971: $error.'</p>'."\n";
10972: }
10973: if ($warning) {
10974: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
10975: }
10976: return $output;
10977: }
10978:
10979: sub get_extracted {
1.1056 raeburn 10980: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
10981: $titles,$wantform) = @_;
1.1055 raeburn 10982: my $count = 0;
10983: my $depth = 0;
10984: my $datatable;
1.1056 raeburn 10985: my @hierarchy;
1.1055 raeburn 10986: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 10987: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
10988: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 10989: foreach my $item (@{$contents}) {
10990: $count ++;
1.1056 raeburn 10991: @{$dirorder->{$count}} = @hierarchy;
10992: $titles->{$count} = $item;
1.1055 raeburn 10993: &archive_hierarchy($depth,$count,$parent,$children);
10994: if ($wantform) {
10995: $datatable .= &archive_row($is_dir->{$item},$item,
10996: $currdir,$depth,$count);
10997: }
10998: if ($is_dir->{$item}) {
10999: $depth ++;
1.1056 raeburn 11000: push(@hierarchy,$count);
11001: $parent->{$depth} = $count;
1.1055 raeburn 11002: $datatable .=
11003: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11004: \$depth,\$count,\@hierarchy,$dirorder,
11005: $children,$parent,$titles,$wantform);
1.1055 raeburn 11006: $depth --;
1.1056 raeburn 11007: pop(@hierarchy);
1.1055 raeburn 11008: }
11009: }
11010: return ($count,$datatable);
11011: }
11012:
11013: sub recurse_extracted_archive {
1.1056 raeburn 11014: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11015: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11016: my $result='';
1.1056 raeburn 11017: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11018: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11019: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11020: return $result;
11021: }
11022: my $dirptr = 16384;
11023: my ($newdirlistref,$newlisterror) =
11024: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11025: if (ref($newdirlistref) eq 'ARRAY') {
11026: foreach my $dir_line (@{$newdirlistref}) {
11027: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11028: unless ($item =~ /^\.+$/) {
11029: $$count ++;
1.1056 raeburn 11030: @{$dirorder->{$$count}} = @{$hierarchy};
11031: $titles->{$$count} = $item;
1.1055 raeburn 11032: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11033:
1.1055 raeburn 11034: my $is_dir;
11035: if ($dirptr&$testdir) {
11036: $is_dir = 1;
11037: }
11038: if ($wantform) {
11039: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11040: }
11041: if ($is_dir) {
11042: $$depth ++;
1.1056 raeburn 11043: push(@{$hierarchy},$$count);
11044: $parent->{$$depth} = $$count;
1.1055 raeburn 11045: $result .=
11046: &recurse_extracted_archive("$currdir/$item",$docudom,
11047: $docuname,$depth,$count,
1.1056 raeburn 11048: $hierarchy,$dirorder,$children,
11049: $parent,$titles,$wantform);
1.1055 raeburn 11050: $$depth --;
1.1056 raeburn 11051: pop(@{$hierarchy});
1.1055 raeburn 11052: }
11053: }
11054: }
11055: }
11056: return $result;
11057: }
11058:
11059: sub archive_hierarchy {
11060: my ($depth,$count,$parent,$children) =@_;
11061: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11062: if (exists($parent->{$depth})) {
11063: $children->{$parent->{$depth}} .= $count.':';
11064: }
11065: }
11066: return;
11067: }
11068:
11069: sub archive_row {
11070: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11071: my ($name) = ($item =~ m{([^/]+)$});
11072: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11073: 'display' => 'Add as file',
1.1055 raeburn 11074: 'dependency' => 'Include as dependency',
11075: 'discard' => 'Discard',
11076: );
11077: if ($is_dir) {
1.1059 raeburn 11078: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11079: }
1.1056 raeburn 11080: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11081: my $offset = 0;
1.1055 raeburn 11082: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11083: $offset ++;
1.1065 raeburn 11084: if ($action ne 'display') {
11085: $offset ++;
11086: }
1.1055 raeburn 11087: $output .= '<td><span class="LC_nobreak">'.
11088: '<label><input type="radio" name="archive_'.$count.
11089: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11090: my $text = $choices{$action};
11091: if ($is_dir) {
11092: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11093: if ($action eq 'display') {
1.1059 raeburn 11094: $text = &mt('Add as folder');
1.1055 raeburn 11095: }
1.1056 raeburn 11096: } else {
11097: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11098:
11099: }
11100: $output .= ' /> '.$choices{$action}.'</label></span>';
11101: if ($action eq 'dependency') {
11102: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11103: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11104: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11105: '<option value=""></option>'."\n".
11106: '</select>'."\n".
11107: '</div>';
1.1059 raeburn 11108: } elsif ($action eq 'display') {
11109: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11110: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11111: '</div>';
1.1055 raeburn 11112: }
1.1056 raeburn 11113: $output .= '</td>';
1.1055 raeburn 11114: }
11115: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11116: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11117: for (my $i=0; $i<$depth; $i++) {
11118: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11119: }
11120: if ($is_dir) {
11121: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11122: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11123: } else {
11124: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11125: }
11126: $output .= ' '.$name.'</td>'."\n".
11127: &end_data_table_row();
11128: return $output;
11129: }
11130:
11131: sub archive_options_form {
1.1065 raeburn 11132: my ($form,$display,$count,$hiddenelem) = @_;
11133: my %lt = &Apache::lonlocal::texthash(
11134: perm => 'Permanently remove archive file?',
11135: hows => 'How should each extracted item be incorporated in the course?',
11136: cont => 'Content actions for all',
11137: addf => 'Add as folder/file',
11138: incd => 'Include as dependency for a displayed file',
11139: disc => 'Discard',
11140: no => 'No',
11141: yes => 'Yes',
11142: save => 'Save',
11143: );
11144: my $output = <<"END";
11145: <form name="$form" method="post" action="">
11146: <p><span class="LC_nobreak">$lt{'perm'}
11147: <label>
11148: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11149: </label>
11150:
11151: <label>
11152: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11153: </span>
11154: </p>
11155: <input type="hidden" name="phase" value="decompress_cleanup" />
11156: <br />$lt{'hows'}
11157: <div class="LC_columnSection">
11158: <fieldset>
11159: <legend>$lt{'cont'}</legend>
11160: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11161: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11162: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11163: </fieldset>
11164: </div>
11165: END
11166: return $output.
1.1055 raeburn 11167: &start_data_table()."\n".
1.1065 raeburn 11168: $display."\n".
1.1055 raeburn 11169: &end_data_table()."\n".
11170: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11171: $hiddenelem.
1.1065 raeburn 11172: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11173: '</form>';
11174: }
11175:
11176: sub archive_javascript {
1.1056 raeburn 11177: my ($startcount,$numitems,$titles,$children) = @_;
11178: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11179: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11180: my $scripttag = <<START;
11181: <script type="text/javascript">
11182: // <![CDATA[
11183:
11184: function checkAll(form,prefix) {
11185: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11186: for (var i=0; i < form.elements.length; i++) {
11187: var id = form.elements[i].id;
11188: if ((id != '') && (id != undefined)) {
11189: if (idstr.test(id)) {
11190: if (form.elements[i].type == 'radio') {
11191: form.elements[i].checked = true;
1.1056 raeburn 11192: var nostart = i-$startcount;
1.1059 raeburn 11193: var offset = nostart%7;
11194: var count = (nostart-offset)/7;
1.1056 raeburn 11195: dependencyCheck(form,count,offset);
1.1055 raeburn 11196: }
11197: }
11198: }
11199: }
11200: }
11201:
11202: function propagateCheck(form,count) {
11203: if (count > 0) {
1.1059 raeburn 11204: var startelement = $startcount + ((count-1) * 7);
11205: for (var j=1; j<6; j++) {
11206: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11207: var item = startelement + j;
11208: if (form.elements[item].type == 'radio') {
11209: if (form.elements[item].checked) {
11210: containerCheck(form,count,j);
11211: break;
11212: }
1.1055 raeburn 11213: }
11214: }
11215: }
11216: }
11217: }
11218:
11219: numitems = $numitems
1.1056 raeburn 11220: var titles = new Array(numitems);
11221: var parents = new Array(numitems);
1.1055 raeburn 11222: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11223: parents[i] = new Array;
1.1055 raeburn 11224: }
1.1059 raeburn 11225: var maintitle = '$maintitle';
1.1055 raeburn 11226:
11227: START
11228:
1.1056 raeburn 11229: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11230: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11231: for (my $i=0; $i<@contents; $i ++) {
11232: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11233: }
11234: }
11235:
1.1056 raeburn 11236: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11237: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11238: }
11239:
1.1055 raeburn 11240: $scripttag .= <<END;
11241:
11242: function containerCheck(form,count,offset) {
11243: if (count > 0) {
1.1056 raeburn 11244: dependencyCheck(form,count,offset);
1.1059 raeburn 11245: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11246: form.elements[item].checked = true;
11247: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11248: if (parents[count].length > 0) {
11249: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11250: containerCheck(form,parents[count][j],offset);
11251: }
11252: }
11253: }
11254: }
11255: }
11256:
11257: function dependencyCheck(form,count,offset) {
11258: if (count > 0) {
1.1059 raeburn 11259: var chosen = (offset+$startcount)+7*(count-1);
11260: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11261: var currtype = form.elements[depitem].type;
11262: if (form.elements[chosen].value == 'dependency') {
11263: document.getElementById('arc_depon_'+count).style.display='block';
11264: form.elements[depitem].options.length = 0;
11265: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 11266: for (var i=1; i<=numitems; i++) {
11267: if (i == count) {
11268: continue;
11269: }
1.1059 raeburn 11270: var startelement = $startcount + (i-1) * 7;
11271: for (var j=1; j<6; j++) {
11272: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11273: var item = startelement + j;
11274: if (form.elements[item].type == 'radio') {
11275: if (form.elements[item].checked) {
11276: if (form.elements[item].value == 'display') {
11277: var n = form.elements[depitem].options.length;
11278: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11279: }
11280: }
11281: }
11282: }
11283: }
11284: }
11285: } else {
11286: document.getElementById('arc_depon_'+count).style.display='none';
11287: form.elements[depitem].options.length = 0;
11288: form.elements[depitem].options[0] = new Option('Select','',true,true);
11289: }
1.1059 raeburn 11290: titleCheck(form,count,offset);
1.1056 raeburn 11291: }
11292: }
11293:
11294: function propagateSelect(form,count,offset) {
11295: if (count > 0) {
1.1065 raeburn 11296: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11297: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11298: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11299: if (parents[count].length > 0) {
11300: for (var j=0; j<parents[count].length; j++) {
11301: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11302: }
11303: }
11304: }
11305: }
11306: }
1.1056 raeburn 11307:
11308: function containerSelect(form,count,offset,picked) {
11309: if (count > 0) {
1.1065 raeburn 11310: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11311: if (form.elements[item].type == 'radio') {
11312: if (form.elements[item].value == 'dependency') {
11313: if (form.elements[item+1].type == 'select-one') {
11314: for (var i=0; i<form.elements[item+1].options.length; i++) {
11315: if (form.elements[item+1].options[i].value == picked) {
11316: form.elements[item+1].selectedIndex = i;
11317: break;
11318: }
11319: }
11320: }
11321: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11322: if (parents[count].length > 0) {
11323: for (var j=0; j<parents[count].length; j++) {
11324: containerSelect(form,parents[count][j],offset,picked);
11325: }
11326: }
11327: }
11328: }
11329: }
11330: }
11331: }
11332:
1.1059 raeburn 11333: function titleCheck(form,count,offset) {
11334: if (count > 0) {
11335: var chosen = (offset+$startcount)+7*(count-1);
11336: var depitem = $startcount + ((count-1) * 7) + 2;
11337: var currtype = form.elements[depitem].type;
11338: if (form.elements[chosen].value == 'display') {
11339: document.getElementById('arc_title_'+count).style.display='block';
11340: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11341: document.getElementById('archive_title_'+count).value=maintitle;
11342: }
11343: } else {
11344: document.getElementById('arc_title_'+count).style.display='none';
11345: if (currtype == 'text') {
11346: document.getElementById('archive_title_'+count).value='';
11347: }
11348: }
11349: }
11350: return;
11351: }
11352:
1.1055 raeburn 11353: // ]]>
11354: </script>
11355: END
11356: return $scripttag;
11357: }
11358:
11359: sub process_extracted_files {
1.1067 raeburn 11360: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11361: my $numitems = $env{'form.archive_count'};
11362: return unless ($numitems);
11363: my @ids=&Apache::lonnet::current_machine_ids();
11364: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11365: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11366: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11367: if (grep(/^\Q$docuhome\E$/,@ids)) {
11368: $prefix = &LONCAPA::propath($docudom,$docuname);
11369: $pathtocheck = "$dir_root/$destination";
11370: $dir = $dir_root;
11371: $ishome = 1;
11372: } else {
11373: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11374: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11375: $dir = "$dir_root/$docudom/$docuname";
11376: }
11377: my $currdir = "$dir_root/$destination";
11378: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11379: if ($env{'form.folderpath'}) {
11380: my @items = split('&',$env{'form.folderpath'});
11381: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 11382: if ($env{'form.folderpath'} =~ /\:1$/) {
11383: $containers{'0'}='page';
11384: } else {
11385: $containers{'0'}='sequence';
11386: }
1.1055 raeburn 11387: }
11388: my @archdirs = &get_env_multiple('form.archive_directory');
11389: if ($numitems) {
11390: for (my $i=1; $i<=$numitems; $i++) {
11391: my $path = $env{'form.archive_content_'.$i};
11392: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11393: my $item = $1;
11394: $toplevelitems{$item} = $i;
11395: if (grep(/^\Q$i\E$/,@archdirs)) {
11396: $is_dir{$item} = 1;
11397: }
11398: }
11399: }
11400: }
1.1067 raeburn 11401: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11402: if (keys(%toplevelitems) > 0) {
11403: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11404: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11405: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11406: }
1.1066 raeburn 11407: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11408: if ($numitems) {
11409: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 11410: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11411: my $path = $env{'form.archive_content_'.$i};
11412: if ($path =~ /^\Q$pathtocheck\E/) {
11413: if ($env{'form.archive_'.$i} eq 'discard') {
11414: if ($prefix ne '' && $path ne '') {
11415: if (-e $prefix.$path) {
1.1066 raeburn 11416: if ((@archdirs > 0) &&
11417: (grep(/^\Q$i\E$/,@archdirs))) {
11418: $todeletedir{$prefix.$path} = 1;
11419: } else {
11420: $todelete{$prefix.$path} = 1;
11421: }
1.1055 raeburn 11422: }
11423: }
11424: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11425: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11426: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11427: $docstitle = $env{'form.archive_title_'.$i};
11428: if ($docstitle eq '') {
11429: $docstitle = $title;
11430: }
1.1055 raeburn 11431: $outer = 0;
1.1056 raeburn 11432: if (ref($dirorder{$i}) eq 'ARRAY') {
11433: if (@{$dirorder{$i}} > 0) {
11434: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11435: if ($env{'form.archive_'.$item} eq 'display') {
11436: $outer = $item;
11437: last;
11438: }
11439: }
11440: }
11441: }
11442: my ($errtext,$fatal) =
11443: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11444: '/'.$folders{$outer}.'.'.
11445: $containers{$outer});
11446: next if ($fatal);
11447: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11448: if ($context eq 'coursedocs') {
1.1056 raeburn 11449: $mapinner{$i} = time;
1.1055 raeburn 11450: $folders{$i} = 'default_'.$mapinner{$i};
11451: $containers{$i} = 'sequence';
11452: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11453: $folders{$i}.'.'.$containers{$i};
11454: my $newidx = &LONCAPA::map::getresidx();
11455: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11456: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11457: push(@LONCAPA::map::order,$newidx);
11458: my ($outtext,$errtext) =
11459: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11460: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11461: '.'.$containers{$outer},1,1);
1.1056 raeburn 11462: $newseqid{$i} = $newidx;
1.1067 raeburn 11463: unless ($errtext) {
11464: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11465: }
1.1055 raeburn 11466: }
11467: } else {
11468: if ($context eq 'coursedocs') {
11469: my $newidx=&LONCAPA::map::getresidx();
11470: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11471: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11472: $title;
11473: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11474: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11475: }
11476: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11477: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11478: }
11479: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11480: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11481: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11482: unless ($ishome) {
11483: my $fetch = "$newdest{$i}/$title";
11484: $fetch =~ s/^\Q$prefix$dir\E//;
11485: $prompttofetch{$fetch} = 1;
11486: }
1.1055 raeburn 11487: }
11488: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11489: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11490: push(@LONCAPA::map::order, $newidx);
11491: my ($outtext,$errtext)=
11492: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11493: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 11494: '.'.$containers{$outer},1,1);
1.1067 raeburn 11495: unless ($errtext) {
11496: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11497: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11498: }
11499: }
1.1055 raeburn 11500: }
11501: }
1.1075.2.11 raeburn 11502: }
11503: } else {
11504: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11505: }
11506: }
11507: for (my $i=1; $i<=$numitems; $i++) {
11508: next unless ($env{'form.archive_'.$i} eq 'dependency');
11509: my $path = $env{'form.archive_content_'.$i};
11510: if ($path =~ /^\Q$pathtocheck\E/) {
11511: my ($title) = ($path =~ m{/([^/]+)$});
11512: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11513: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11514: if (ref($dirorder{$i}) eq 'ARRAY') {
11515: my ($itemidx,$fullpath,$relpath);
11516: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11517: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11518: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 11519: if ($dirorder{$i}->[$j] eq $container) {
11520: $itemidx = $j;
1.1056 raeburn 11521: }
11522: }
1.1075.2.11 raeburn 11523: }
11524: if ($itemidx eq '') {
11525: $itemidx = 0;
11526: }
11527: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11528: if ($mapinner{$referrer{$i}}) {
11529: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11530: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11531: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11532: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11533: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11534: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11535: if (!-e $fullpath) {
11536: mkdir($fullpath,0755);
1.1056 raeburn 11537: }
11538: }
1.1075.2.11 raeburn 11539: } else {
11540: last;
1.1056 raeburn 11541: }
1.1075.2.11 raeburn 11542: }
11543: }
11544: } elsif ($newdest{$referrer{$i}}) {
11545: $fullpath = $newdest{$referrer{$i}};
11546: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11547: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11548: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11549: last;
11550: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11551: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11552: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11553: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11554: if (!-e $fullpath) {
11555: mkdir($fullpath,0755);
1.1056 raeburn 11556: }
11557: }
1.1075.2.11 raeburn 11558: } else {
11559: last;
1.1056 raeburn 11560: }
1.1075.2.11 raeburn 11561: }
11562: }
11563: if ($fullpath ne '') {
11564: if (-e "$prefix$path") {
11565: system("mv $prefix$path $fullpath/$title");
11566: }
11567: if (-e "$fullpath/$title") {
11568: my $showpath;
11569: if ($relpath ne '') {
11570: $showpath = "$relpath/$title";
11571: } else {
11572: $showpath = "/$title";
1.1056 raeburn 11573: }
1.1075.2.11 raeburn 11574: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
11575: }
11576: unless ($ishome) {
11577: my $fetch = "$fullpath/$title";
11578: $fetch =~ s/^\Q$prefix$dir\E//;
11579: $prompttofetch{$fetch} = 1;
1.1055 raeburn 11580: }
11581: }
11582: }
1.1075.2.11 raeburn 11583: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
11584: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
11585: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 11586: }
11587: } else {
1.1075.2.11 raeburn 11588: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 11589: }
11590: }
11591: if (keys(%todelete)) {
11592: foreach my $key (keys(%todelete)) {
11593: unlink($key);
1.1066 raeburn 11594: }
11595: }
11596: if (keys(%todeletedir)) {
11597: foreach my $key (keys(%todeletedir)) {
11598: rmdir($key);
11599: }
11600: }
11601: foreach my $dir (sort(keys(%is_dir))) {
11602: if (($pathtocheck ne '') && ($dir ne '')) {
11603: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 11604: }
11605: }
1.1067 raeburn 11606: if ($result ne '') {
11607: $output .= '<ul>'."\n".
11608: $result."\n".
11609: '</ul>';
11610: }
11611: unless ($ishome) {
11612: my $replicationfail;
11613: foreach my $item (keys(%prompttofetch)) {
11614: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
11615: unless ($fetchresult eq 'ok') {
11616: $replicationfail .= '<li>'.$item.'</li>'."\n";
11617: }
11618: }
11619: if ($replicationfail) {
11620: $output .= '<p class="LC_error">'.
11621: &mt('Course home server failed to retrieve:').'<ul>'.
11622: $replicationfail.
11623: '</ul></p>';
11624: }
11625: }
1.1055 raeburn 11626: } else {
11627: $warning = &mt('No items found in archive.');
11628: }
11629: if ($error) {
11630: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11631: $error.'</p>'."\n";
11632: }
11633: if ($warning) {
11634: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11635: }
11636: return $output;
11637: }
11638:
1.1066 raeburn 11639: sub cleanup_empty_dirs {
11640: my ($path) = @_;
11641: if (($path ne '') && (-d $path)) {
11642: if (opendir(my $dirh,$path)) {
11643: my @dircontents = grep(!/^\./,readdir($dirh));
11644: my $numitems = 0;
11645: foreach my $item (@dircontents) {
11646: if (-d "$path/$item") {
1.1075.2.28 raeburn 11647: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 11648: if (-e "$path/$item") {
11649: $numitems ++;
11650: }
11651: } else {
11652: $numitems ++;
11653: }
11654: }
11655: if ($numitems == 0) {
11656: rmdir($path);
11657: }
11658: closedir($dirh);
11659: }
11660: }
11661: return;
11662: }
11663:
1.41 ng 11664: =pod
1.45 matthew 11665:
1.1068 raeburn 11666: =item &get_folder_hierarchy()
11667:
11668: Provides hierarchy of names of folders/sub-folders containing the current
11669: item,
11670:
11671: Inputs: 3
11672: - $navmap - navmaps object
11673:
11674: - $map - url for map (either the trigger itself, or map containing
11675: the resource, which is the trigger).
11676:
11677: - $showitem - 1 => show title for map itself; 0 => do not show.
11678:
11679: Outputs: 1 @pathitems - array of folder/subfolder names.
11680:
11681: =cut
11682:
11683: sub get_folder_hierarchy {
11684: my ($navmap,$map,$showitem) = @_;
11685: my @pathitems;
11686: if (ref($navmap)) {
11687: my $mapres = $navmap->getResourceByUrl($map);
11688: if (ref($mapres)) {
11689: my $pcslist = $mapres->map_hierarchy();
11690: if ($pcslist ne '') {
11691: my @pcs = split(/,/,$pcslist);
11692: foreach my $pc (@pcs) {
11693: if ($pc == 1) {
11694: push(@pathitems,&mt('Main Course Documents'));
11695: } else {
11696: my $res = $navmap->getByMapPc($pc);
11697: if (ref($res)) {
11698: my $title = $res->compTitle();
11699: $title =~ s/\W+/_/g;
11700: if ($title ne '') {
11701: push(@pathitems,$title);
11702: }
11703: }
11704: }
11705: }
11706: }
1.1071 raeburn 11707: if ($showitem) {
11708: if ($mapres->{ID} eq '0.0') {
11709: push(@pathitems,&mt('Main Course Documents'));
11710: } else {
11711: my $maptitle = $mapres->compTitle();
11712: $maptitle =~ s/\W+/_/g;
11713: if ($maptitle ne '') {
11714: push(@pathitems,$maptitle);
11715: }
1.1068 raeburn 11716: }
11717: }
11718: }
11719: }
11720: return @pathitems;
11721: }
11722:
11723: =pod
11724:
1.1015 raeburn 11725: =item * &get_turnedin_filepath()
11726:
11727: Determines path in a user's portfolio file for storage of files uploaded
11728: to a specific essayresponse or dropbox item.
11729:
11730: Inputs: 3 required + 1 optional.
11731: $symb is symb for resource, $uname and $udom are for current user (required).
11732: $caller is optional (can be "submission", if routine is called when storing
11733: an upoaded file when "Submit Answer" button was pressed).
11734:
11735: Returns array containing $path and $multiresp.
11736: $path is path in portfolio. $multiresp is 1 if this resource contains more
11737: than one file upload item. Callers of routine should append partid as a
11738: subdirectory to $path in cases where $multiresp is 1.
11739:
11740: Called by: homework/essayresponse.pm and homework/structuretags.pm
11741:
11742: =cut
11743:
11744: sub get_turnedin_filepath {
11745: my ($symb,$uname,$udom,$caller) = @_;
11746: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
11747: my $turnindir;
11748: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
11749: $turnindir = $userhash{'turnindir'};
11750: my ($path,$multiresp);
11751: if ($turnindir eq '') {
11752: if ($caller eq 'submission') {
11753: $turnindir = &mt('turned in');
11754: $turnindir =~ s/\W+/_/g;
11755: my %newhash = (
11756: 'turnindir' => $turnindir,
11757: );
11758: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
11759: }
11760: }
11761: if ($turnindir ne '') {
11762: $path = '/'.$turnindir.'/';
11763: my ($multipart,$turnin,@pathitems);
11764: my $navmap = Apache::lonnavmaps::navmap->new();
11765: if (defined($navmap)) {
11766: my $mapres = $navmap->getResourceByUrl($map);
11767: if (ref($mapres)) {
11768: my $pcslist = $mapres->map_hierarchy();
11769: if ($pcslist ne '') {
11770: foreach my $pc (split(/,/,$pcslist)) {
11771: my $res = $navmap->getByMapPc($pc);
11772: if (ref($res)) {
11773: my $title = $res->compTitle();
11774: $title =~ s/\W+/_/g;
11775: if ($title ne '') {
11776: push(@pathitems,$title);
11777: }
11778: }
11779: }
11780: }
11781: my $maptitle = $mapres->compTitle();
11782: $maptitle =~ s/\W+/_/g;
11783: if ($maptitle ne '') {
11784: push(@pathitems,$maptitle);
11785: }
11786: unless ($env{'request.state'} eq 'construct') {
11787: my $res = $navmap->getBySymb($symb);
11788: if (ref($res)) {
11789: my $partlist = $res->parts();
11790: my $totaluploads = 0;
11791: if (ref($partlist) eq 'ARRAY') {
11792: foreach my $part (@{$partlist}) {
11793: my @types = $res->responseType($part);
11794: my @ids = $res->responseIds($part);
11795: for (my $i=0; $i < scalar(@ids); $i++) {
11796: if ($types[$i] eq 'essay') {
11797: my $partid = $part.'_'.$ids[$i];
11798: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
11799: $totaluploads ++;
11800: }
11801: }
11802: }
11803: }
11804: if ($totaluploads > 1) {
11805: $multiresp = 1;
11806: }
11807: }
11808: }
11809: }
11810: } else {
11811: return;
11812: }
11813: } else {
11814: return;
11815: }
11816: my $restitle=&Apache::lonnet::gettitle($symb);
11817: $restitle =~ s/\W+/_/g;
11818: if ($restitle eq '') {
11819: $restitle = ($resurl =~ m{/[^/]+$});
11820: if ($restitle eq '') {
11821: $restitle = time;
11822: }
11823: }
11824: push(@pathitems,$restitle);
11825: $path .= join('/',@pathitems);
11826: }
11827: return ($path,$multiresp);
11828: }
11829:
11830: =pod
11831:
1.464 albertel 11832: =back
1.41 ng 11833:
1.112 bowersj2 11834: =head1 CSV Upload/Handling functions
1.38 albertel 11835:
1.41 ng 11836: =over 4
11837:
1.648 raeburn 11838: =item * &upfile_store($r)
1.41 ng 11839:
11840: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 11841: needs $env{'form.upfile'}
1.41 ng 11842: returns $datatoken to be put into hidden field
11843:
11844: =cut
1.31 albertel 11845:
11846: sub upfile_store {
11847: my $r=shift;
1.258 albertel 11848: $env{'form.upfile'}=~s/\r/\n/gs;
11849: $env{'form.upfile'}=~s/\f/\n/gs;
11850: $env{'form.upfile'}=~s/\n+/\n/gs;
11851: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 11852:
1.258 albertel 11853: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
11854: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 11855: {
1.158 raeburn 11856: my $datafile = $r->dir_config('lonDaemons').
11857: '/tmp/'.$datatoken.'.tmp';
11858: if ( open(my $fh,">$datafile") ) {
1.258 albertel 11859: print $fh $env{'form.upfile'};
1.158 raeburn 11860: close($fh);
11861: }
1.31 albertel 11862: }
11863: return $datatoken;
11864: }
11865:
1.56 matthew 11866: =pod
11867:
1.648 raeburn 11868: =item * &load_tmp_file($r)
1.41 ng 11869:
11870: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 11871: needs $env{'form.datatoken'},
11872: sets $env{'form.upfile'} to the contents of the file
1.41 ng 11873:
11874: =cut
1.31 albertel 11875:
11876: sub load_tmp_file {
11877: my $r=shift;
11878: my @studentdata=();
11879: {
1.158 raeburn 11880: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 11881: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 11882: if ( open(my $fh,"<$studentfile") ) {
11883: @studentdata=<$fh>;
11884: close($fh);
11885: }
1.31 albertel 11886: }
1.258 albertel 11887: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 11888: }
11889:
1.56 matthew 11890: =pod
11891:
1.648 raeburn 11892: =item * &upfile_record_sep()
1.41 ng 11893:
11894: Separate uploaded file into records
11895: returns array of records,
1.258 albertel 11896: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 11897:
11898: =cut
1.31 albertel 11899:
11900: sub upfile_record_sep {
1.258 albertel 11901: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 11902: } else {
1.248 albertel 11903: my @records;
1.258 albertel 11904: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 11905: if ($line=~/^\s*$/) { next; }
11906: push(@records,$line);
11907: }
11908: return @records;
1.31 albertel 11909: }
11910: }
11911:
1.56 matthew 11912: =pod
11913:
1.648 raeburn 11914: =item * &record_sep($record)
1.41 ng 11915:
1.258 albertel 11916: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 11917:
11918: =cut
11919:
1.263 www 11920: sub takeleft {
11921: my $index=shift;
11922: return substr('0000'.$index,-4,4);
11923: }
11924:
1.31 albertel 11925: sub record_sep {
11926: my $record=shift;
11927: my %components=();
1.258 albertel 11928: if ($env{'form.upfiletype'} eq 'xml') {
11929: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 11930: my $i=0;
1.356 albertel 11931: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 11932: $field=~s/^(\"|\')//;
11933: $field=~s/(\"|\')$//;
1.263 www 11934: $components{&takeleft($i)}=$field;
1.31 albertel 11935: $i++;
11936: }
1.258 albertel 11937: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 11938: my $i=0;
1.356 albertel 11939: foreach my $field (split(/\t/,$record)) {
1.31 albertel 11940: $field=~s/^(\"|\')//;
11941: $field=~s/(\"|\')$//;
1.263 www 11942: $components{&takeleft($i)}=$field;
1.31 albertel 11943: $i++;
11944: }
11945: } else {
1.561 www 11946: my $separator=',';
1.480 banghart 11947: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 11948: $separator=';';
1.480 banghart 11949: }
1.31 albertel 11950: my $i=0;
1.561 www 11951: # the character we are looking for to indicate the end of a quote or a record
11952: my $looking_for=$separator;
11953: # do not add the characters to the fields
11954: my $ignore=0;
11955: # we just encountered a separator (or the beginning of the record)
11956: my $just_found_separator=1;
11957: # store the field we are working on here
11958: my $field='';
11959: # work our way through all characters in record
11960: foreach my $character ($record=~/(.)/g) {
11961: if ($character eq $looking_for) {
11962: if ($character ne $separator) {
11963: # Found the end of a quote, again looking for separator
11964: $looking_for=$separator;
11965: $ignore=1;
11966: } else {
11967: # Found a separator, store away what we got
11968: $components{&takeleft($i)}=$field;
11969: $i++;
11970: $just_found_separator=1;
11971: $ignore=0;
11972: $field='';
11973: }
11974: next;
11975: }
11976: # single or double quotation marks after a separator indicate beginning of a quote
11977: # we are now looking for the end of the quote and need to ignore separators
11978: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
11979: $looking_for=$character;
11980: next;
11981: }
11982: # ignore would be true after we reached the end of a quote
11983: if ($ignore) { next; }
11984: if (($just_found_separator) && ($character=~/\s/)) { next; }
11985: $field.=$character;
11986: $just_found_separator=0;
1.31 albertel 11987: }
1.561 www 11988: # catch the very last entry, since we never encountered the separator
11989: $components{&takeleft($i)}=$field;
1.31 albertel 11990: }
11991: return %components;
11992: }
11993:
1.144 matthew 11994: ######################################################
11995: ######################################################
11996:
1.56 matthew 11997: =pod
11998:
1.648 raeburn 11999: =item * &upfile_select_html()
1.41 ng 12000:
1.144 matthew 12001: Return HTML code to select a file from the users machine and specify
12002: the file type.
1.41 ng 12003:
12004: =cut
12005:
1.144 matthew 12006: ######################################################
12007: ######################################################
1.31 albertel 12008: sub upfile_select_html {
1.144 matthew 12009: my %Types = (
12010: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12011: semisv => &mt('Semicolon separated values'),
1.144 matthew 12012: space => &mt('Space separated'),
12013: tab => &mt('Tabulator separated'),
12014: # xml => &mt('HTML/XML'),
12015: );
12016: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12017: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12018: foreach my $type (sort(keys(%Types))) {
12019: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12020: }
12021: $Str .= "</select>\n";
12022: return $Str;
1.31 albertel 12023: }
12024:
1.301 albertel 12025: sub get_samples {
12026: my ($records,$toget) = @_;
12027: my @samples=({});
12028: my $got=0;
12029: foreach my $rec (@$records) {
12030: my %temp = &record_sep($rec);
12031: if (! grep(/\S/, values(%temp))) { next; }
12032: if (%temp) {
12033: $samples[$got]=\%temp;
12034: $got++;
12035: if ($got == $toget) { last; }
12036: }
12037: }
12038: return \@samples;
12039: }
12040:
1.144 matthew 12041: ######################################################
12042: ######################################################
12043:
1.56 matthew 12044: =pod
12045:
1.648 raeburn 12046: =item * &csv_print_samples($r,$records)
1.41 ng 12047:
12048: Prints a table of sample values from each column uploaded $r is an
12049: Apache Request ref, $records is an arrayref from
12050: &Apache::loncommon::upfile_record_sep
12051:
12052: =cut
12053:
1.144 matthew 12054: ######################################################
12055: ######################################################
1.31 albertel 12056: sub csv_print_samples {
12057: my ($r,$records) = @_;
1.662 bisitz 12058: my $samples = &get_samples($records,5);
1.301 albertel 12059:
1.594 raeburn 12060: $r->print(&mt('Samples').'<br />'.&start_data_table().
12061: &start_data_table_header_row());
1.356 albertel 12062: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12063: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12064: $r->print(&end_data_table_header_row());
1.301 albertel 12065: foreach my $hash (@$samples) {
1.594 raeburn 12066: $r->print(&start_data_table_row());
1.356 albertel 12067: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12068: $r->print('<td>');
1.356 albertel 12069: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12070: $r->print('</td>');
12071: }
1.594 raeburn 12072: $r->print(&end_data_table_row());
1.31 albertel 12073: }
1.594 raeburn 12074: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12075: }
12076:
1.144 matthew 12077: ######################################################
12078: ######################################################
12079:
1.56 matthew 12080: =pod
12081:
1.648 raeburn 12082: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12083:
12084: Prints a table to create associations between values and table columns.
1.144 matthew 12085:
1.41 ng 12086: $r is an Apache Request ref,
12087: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12088: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12089:
12090: =cut
12091:
1.144 matthew 12092: ######################################################
12093: ######################################################
1.31 albertel 12094: sub csv_print_select_table {
12095: my ($r,$records,$d) = @_;
1.301 albertel 12096: my $i=0;
12097: my $samples = &get_samples($records,1);
1.144 matthew 12098: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12099: &start_data_table().&start_data_table_header_row().
1.144 matthew 12100: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12101: '<th>'.&mt('Column').'</th>'.
12102: &end_data_table_header_row()."\n");
1.356 albertel 12103: foreach my $array_ref (@$d) {
12104: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12105: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12106:
1.875 bisitz 12107: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12108: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12109: $r->print('<option value="none"></option>');
1.356 albertel 12110: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12111: $r->print('<option value="'.$sample.'"'.
12112: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12113: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12114: }
1.594 raeburn 12115: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12116: $i++;
12117: }
1.594 raeburn 12118: $r->print(&end_data_table());
1.31 albertel 12119: $i--;
12120: return $i;
12121: }
1.56 matthew 12122:
1.144 matthew 12123: ######################################################
12124: ######################################################
12125:
1.56 matthew 12126: =pod
1.31 albertel 12127:
1.648 raeburn 12128: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12129:
12130: Prints a table of sample values from the upload and can make associate samples to internal names.
12131:
12132: $r is an Apache Request ref,
12133: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12134: $d is an array of 2 element arrays (internal name, displayed name)
12135:
12136: =cut
12137:
1.144 matthew 12138: ######################################################
12139: ######################################################
1.31 albertel 12140: sub csv_samples_select_table {
12141: my ($r,$records,$d) = @_;
12142: my $i=0;
1.144 matthew 12143: #
1.662 bisitz 12144: my $max_samples = 5;
12145: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12146: $r->print(&start_data_table().
12147: &start_data_table_header_row().'<th>'.
12148: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12149: &end_data_table_header_row());
1.301 albertel 12150:
12151: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12152: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12153: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12154: foreach my $option (@$d) {
12155: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12156: $r->print('<option value="'.$value.'"'.
1.253 albertel 12157: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12158: $display.'</option>');
1.31 albertel 12159: }
12160: $r->print('</select></td><td>');
1.662 bisitz 12161: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12162: if (defined($samples->[$line]{$key})) {
12163: $r->print($samples->[$line]{$key}."<br />\n");
12164: }
12165: }
1.594 raeburn 12166: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12167: $i++;
12168: }
1.594 raeburn 12169: $r->print(&end_data_table());
1.31 albertel 12170: $i--;
12171: return($i);
1.115 matthew 12172: }
12173:
1.144 matthew 12174: ######################################################
12175: ######################################################
12176:
1.115 matthew 12177: =pod
12178:
1.648 raeburn 12179: =item * &clean_excel_name($name)
1.115 matthew 12180:
12181: Returns a replacement for $name which does not contain any illegal characters.
12182:
12183: =cut
12184:
1.144 matthew 12185: ######################################################
12186: ######################################################
1.115 matthew 12187: sub clean_excel_name {
12188: my ($name) = @_;
12189: $name =~ s/[:\*\?\/\\]//g;
12190: if (length($name) > 31) {
12191: $name = substr($name,0,31);
12192: }
12193: return $name;
1.25 albertel 12194: }
1.84 albertel 12195:
1.85 albertel 12196: =pod
12197:
1.648 raeburn 12198: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12199:
12200: Returns either 1 or undef
12201:
12202: 1 if the part is to be hidden, undef if it is to be shown
12203:
12204: Arguments are:
12205:
12206: $id the id of the part to be checked
12207: $symb, optional the symb of the resource to check
12208: $udom, optional the domain of the user to check for
12209: $uname, optional the username of the user to check for
12210:
12211: =cut
1.84 albertel 12212:
12213: sub check_if_partid_hidden {
12214: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12215: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12216: $symb,$udom,$uname);
1.141 albertel 12217: my $truth=1;
12218: #if the string starts with !, then the list is the list to show not hide
12219: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12220: my @hiddenlist=split(/,/,$hiddenparts);
12221: foreach my $checkid (@hiddenlist) {
1.141 albertel 12222: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12223: }
1.141 albertel 12224: return !$truth;
1.84 albertel 12225: }
1.127 matthew 12226:
1.138 matthew 12227:
12228: ############################################################
12229: ############################################################
12230:
12231: =pod
12232:
1.157 matthew 12233: =back
12234:
1.138 matthew 12235: =head1 cgi-bin script and graphing routines
12236:
1.157 matthew 12237: =over 4
12238:
1.648 raeburn 12239: =item * &get_cgi_id()
1.138 matthew 12240:
12241: Inputs: none
12242:
12243: Returns an id which can be used to pass environment variables
12244: to various cgi-bin scripts. These environment variables will
12245: be removed from the users environment after a given time by
12246: the routine &Apache::lonnet::transfer_profile_to_env.
12247:
12248: =cut
12249:
12250: ############################################################
12251: ############################################################
1.152 albertel 12252: my $uniq=0;
1.136 matthew 12253: sub get_cgi_id {
1.154 albertel 12254: $uniq=($uniq+1)%100000;
1.280 albertel 12255: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12256: }
12257:
1.127 matthew 12258: ############################################################
12259: ############################################################
12260:
12261: =pod
12262:
1.648 raeburn 12263: =item * &DrawBarGraph()
1.127 matthew 12264:
1.138 matthew 12265: Facilitates the plotting of data in a (stacked) bar graph.
12266: Puts plot definition data into the users environment in order for
12267: graph.png to plot it. Returns an <img> tag for the plot.
12268: The bars on the plot are labeled '1','2',...,'n'.
12269:
12270: Inputs:
12271:
12272: =over 4
12273:
12274: =item $Title: string, the title of the plot
12275:
12276: =item $xlabel: string, text describing the X-axis of the plot
12277:
12278: =item $ylabel: string, text describing the Y-axis of the plot
12279:
12280: =item $Max: scalar, the maximum Y value to use in the plot
12281: If $Max is < any data point, the graph will not be rendered.
12282:
1.140 matthew 12283: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12284: they are plotted. If undefined, default values will be used.
12285:
1.178 matthew 12286: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12287:
1.138 matthew 12288: =item @Values: An array of array references. Each array reference holds data
12289: to be plotted in a stacked bar chart.
12290:
1.239 matthew 12291: =item If the final element of @Values is a hash reference the key/value
12292: pairs will be added to the graph definition.
12293:
1.138 matthew 12294: =back
12295:
12296: Returns:
12297:
12298: An <img> tag which references graph.png and the appropriate identifying
12299: information for the plot.
12300:
1.127 matthew 12301: =cut
12302:
12303: ############################################################
12304: ############################################################
1.134 matthew 12305: sub DrawBarGraph {
1.178 matthew 12306: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12307: #
12308: if (! defined($colors)) {
12309: $colors = ['#33ff00',
12310: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12311: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12312: ];
12313: }
1.228 matthew 12314: my $extra_settings = {};
12315: if (ref($Values[-1]) eq 'HASH') {
12316: $extra_settings = pop(@Values);
12317: }
1.127 matthew 12318: #
1.136 matthew 12319: my $identifier = &get_cgi_id();
12320: my $id = 'cgi.'.$identifier;
1.129 matthew 12321: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12322: return '';
12323: }
1.225 matthew 12324: #
12325: my @Labels;
12326: if (defined($labels)) {
12327: @Labels = @$labels;
12328: } else {
12329: for (my $i=0;$i<@{$Values[0]};$i++) {
12330: push (@Labels,$i+1);
12331: }
12332: }
12333: #
1.129 matthew 12334: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12335: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12336: my %ValuesHash;
12337: my $NumSets=1;
12338: foreach my $array (@Values) {
12339: next if (! ref($array));
1.136 matthew 12340: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12341: join(',',@$array);
1.129 matthew 12342: }
1.127 matthew 12343: #
1.136 matthew 12344: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12345: if ($NumBars < 3) {
12346: $width = 120+$NumBars*32;
1.220 matthew 12347: $xskip = 1;
1.225 matthew 12348: $bar_width = 30;
12349: } elsif ($NumBars < 5) {
12350: $width = 120+$NumBars*20;
12351: $xskip = 1;
12352: $bar_width = 20;
1.220 matthew 12353: } elsif ($NumBars < 10) {
1.136 matthew 12354: $width = 120+$NumBars*15;
12355: $xskip = 1;
12356: $bar_width = 15;
12357: } elsif ($NumBars <= 25) {
12358: $width = 120+$NumBars*11;
12359: $xskip = 5;
12360: $bar_width = 8;
12361: } elsif ($NumBars <= 50) {
12362: $width = 120+$NumBars*8;
12363: $xskip = 5;
12364: $bar_width = 4;
12365: } else {
12366: $width = 120+$NumBars*8;
12367: $xskip = 5;
12368: $bar_width = 4;
12369: }
12370: #
1.137 matthew 12371: $Max = 1 if ($Max < 1);
12372: if ( int($Max) < $Max ) {
12373: $Max++;
12374: $Max = int($Max);
12375: }
1.127 matthew 12376: $Title = '' if (! defined($Title));
12377: $xlabel = '' if (! defined($xlabel));
12378: $ylabel = '' if (! defined($ylabel));
1.369 www 12379: $ValuesHash{$id.'.title'} = &escape($Title);
12380: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12381: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12382: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12383: $ValuesHash{$id.'.NumBars'} = $NumBars;
12384: $ValuesHash{$id.'.NumSets'} = $NumSets;
12385: $ValuesHash{$id.'.PlotType'} = 'bar';
12386: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12387: $ValuesHash{$id.'.height'} = $height;
12388: $ValuesHash{$id.'.width'} = $width;
12389: $ValuesHash{$id.'.xskip'} = $xskip;
12390: $ValuesHash{$id.'.bar_width'} = $bar_width;
12391: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12392: #
1.228 matthew 12393: # Deal with other parameters
12394: while (my ($key,$value) = each(%$extra_settings)) {
12395: $ValuesHash{$id.'.'.$key} = $value;
12396: }
12397: #
1.646 raeburn 12398: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12399: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12400: }
12401:
12402: ############################################################
12403: ############################################################
12404:
12405: =pod
12406:
1.648 raeburn 12407: =item * &DrawXYGraph()
1.137 matthew 12408:
1.138 matthew 12409: Facilitates the plotting of data in an XY graph.
12410: Puts plot definition data into the users environment in order for
12411: graph.png to plot it. Returns an <img> tag for the plot.
12412:
12413: Inputs:
12414:
12415: =over 4
12416:
12417: =item $Title: string, the title of the plot
12418:
12419: =item $xlabel: string, text describing the X-axis of the plot
12420:
12421: =item $ylabel: string, text describing the Y-axis of the plot
12422:
12423: =item $Max: scalar, the maximum Y value to use in the plot
12424: If $Max is < any data point, the graph will not be rendered.
12425:
12426: =item $colors: Array ref containing the hex color codes for the data to be
12427: plotted in. If undefined, default values will be used.
12428:
12429: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12430:
12431: =item $Ydata: Array ref containing Array refs.
1.185 www 12432: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12433:
12434: =item %Values: hash indicating or overriding any default values which are
12435: passed to graph.png.
12436: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12437:
12438: =back
12439:
12440: Returns:
12441:
12442: An <img> tag which references graph.png and the appropriate identifying
12443: information for the plot.
12444:
1.137 matthew 12445: =cut
12446:
12447: ############################################################
12448: ############################################################
12449: sub DrawXYGraph {
12450: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12451: #
12452: # Create the identifier for the graph
12453: my $identifier = &get_cgi_id();
12454: my $id = 'cgi.'.$identifier;
12455: #
12456: $Title = '' if (! defined($Title));
12457: $xlabel = '' if (! defined($xlabel));
12458: $ylabel = '' if (! defined($ylabel));
12459: my %ValuesHash =
12460: (
1.369 www 12461: $id.'.title' => &escape($Title),
12462: $id.'.xlabel' => &escape($xlabel),
12463: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12464: $id.'.y_max_value'=> $Max,
12465: $id.'.labels' => join(',',@$Xlabels),
12466: $id.'.PlotType' => 'XY',
12467: );
12468: #
12469: if (defined($colors) && ref($colors) eq 'ARRAY') {
12470: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12471: }
12472: #
12473: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12474: return '';
12475: }
12476: my $NumSets=1;
1.138 matthew 12477: foreach my $array (@{$Ydata}){
1.137 matthew 12478: next if (! ref($array));
12479: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12480: }
1.138 matthew 12481: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12482: #
12483: # Deal with other parameters
12484: while (my ($key,$value) = each(%Values)) {
12485: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12486: }
12487: #
1.646 raeburn 12488: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12489: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12490: }
12491:
12492: ############################################################
12493: ############################################################
12494:
12495: =pod
12496:
1.648 raeburn 12497: =item * &DrawXYYGraph()
1.138 matthew 12498:
12499: Facilitates the plotting of data in an XY graph with two Y axes.
12500: Puts plot definition data into the users environment in order for
12501: graph.png to plot it. Returns an <img> tag for the plot.
12502:
12503: Inputs:
12504:
12505: =over 4
12506:
12507: =item $Title: string, the title of the plot
12508:
12509: =item $xlabel: string, text describing the X-axis of the plot
12510:
12511: =item $ylabel: string, text describing the Y-axis of the plot
12512:
12513: =item $colors: Array ref containing the hex color codes for the data to be
12514: plotted in. If undefined, default values will be used.
12515:
12516: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12517:
12518: =item $Ydata1: The first data set
12519:
12520: =item $Min1: The minimum value of the left Y-axis
12521:
12522: =item $Max1: The maximum value of the left Y-axis
12523:
12524: =item $Ydata2: The second data set
12525:
12526: =item $Min2: The minimum value of the right Y-axis
12527:
12528: =item $Max2: The maximum value of the left Y-axis
12529:
12530: =item %Values: hash indicating or overriding any default values which are
12531: passed to graph.png.
12532: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12533:
12534: =back
12535:
12536: Returns:
12537:
12538: An <img> tag which references graph.png and the appropriate identifying
12539: information for the plot.
1.136 matthew 12540:
12541: =cut
12542:
12543: ############################################################
12544: ############################################################
1.137 matthew 12545: sub DrawXYYGraph {
12546: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12547: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12548: #
12549: # Create the identifier for the graph
12550: my $identifier = &get_cgi_id();
12551: my $id = 'cgi.'.$identifier;
12552: #
12553: $Title = '' if (! defined($Title));
12554: $xlabel = '' if (! defined($xlabel));
12555: $ylabel = '' if (! defined($ylabel));
12556: my %ValuesHash =
12557: (
1.369 www 12558: $id.'.title' => &escape($Title),
12559: $id.'.xlabel' => &escape($xlabel),
12560: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 12561: $id.'.labels' => join(',',@$Xlabels),
12562: $id.'.PlotType' => 'XY',
12563: $id.'.NumSets' => 2,
1.137 matthew 12564: $id.'.two_axes' => 1,
12565: $id.'.y1_max_value' => $Max1,
12566: $id.'.y1_min_value' => $Min1,
12567: $id.'.y2_max_value' => $Max2,
12568: $id.'.y2_min_value' => $Min2,
1.136 matthew 12569: );
12570: #
1.137 matthew 12571: if (defined($colors) && ref($colors) eq 'ARRAY') {
12572: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12573: }
12574: #
12575: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
12576: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 12577: return '';
12578: }
12579: my $NumSets=1;
1.137 matthew 12580: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 12581: next if (! ref($array));
12582: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 12583: }
12584: #
12585: # Deal with other parameters
12586: while (my ($key,$value) = each(%Values)) {
12587: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 12588: }
12589: #
1.646 raeburn 12590: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 12591: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 12592: }
12593:
12594: ############################################################
12595: ############################################################
12596:
12597: =pod
12598:
1.157 matthew 12599: =back
12600:
1.139 matthew 12601: =head1 Statistics helper routines?
12602:
12603: Bad place for them but what the hell.
12604:
1.157 matthew 12605: =over 4
12606:
1.648 raeburn 12607: =item * &chartlink()
1.139 matthew 12608:
12609: Returns a link to the chart for a specific student.
12610:
12611: Inputs:
12612:
12613: =over 4
12614:
12615: =item $linktext: The text of the link
12616:
12617: =item $sname: The students username
12618:
12619: =item $sdomain: The students domain
12620:
12621: =back
12622:
1.157 matthew 12623: =back
12624:
1.139 matthew 12625: =cut
12626:
12627: ############################################################
12628: ############################################################
12629: sub chartlink {
12630: my ($linktext, $sname, $sdomain) = @_;
12631: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 12632: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 12633: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 12634: '">'.$linktext.'</a>';
1.153 matthew 12635: }
12636:
12637: #######################################################
12638: #######################################################
12639:
12640: =pod
12641:
12642: =head1 Course Environment Routines
1.157 matthew 12643:
12644: =over 4
1.153 matthew 12645:
1.648 raeburn 12646: =item * &restore_course_settings()
1.153 matthew 12647:
1.648 raeburn 12648: =item * &store_course_settings()
1.153 matthew 12649:
12650: Restores/Store indicated form parameters from the course environment.
12651: Will not overwrite existing values of the form parameters.
12652:
12653: Inputs:
12654: a scalar describing the data (e.g. 'chart', 'problem_analysis')
12655:
12656: a hash ref describing the data to be stored. For example:
12657:
12658: %Save_Parameters = ('Status' => 'scalar',
12659: 'chartoutputmode' => 'scalar',
12660: 'chartoutputdata' => 'scalar',
12661: 'Section' => 'array',
1.373 raeburn 12662: 'Group' => 'array',
1.153 matthew 12663: 'StudentData' => 'array',
12664: 'Maps' => 'array');
12665:
12666: Returns: both routines return nothing
12667:
1.631 raeburn 12668: =back
12669:
1.153 matthew 12670: =cut
12671:
12672: #######################################################
12673: #######################################################
12674: sub store_course_settings {
1.496 albertel 12675: return &store_settings($env{'request.course.id'},@_);
12676: }
12677:
12678: sub store_settings {
1.153 matthew 12679: # save to the environment
12680: # appenv the same items, just to be safe
1.300 albertel 12681: my $udom = $env{'user.domain'};
12682: my $uname = $env{'user.name'};
1.496 albertel 12683: my ($context,$prefix,$Settings) = @_;
1.153 matthew 12684: my %SaveHash;
12685: my %AppHash;
12686: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 12687: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 12688: my $envname = 'environment.'.$basename;
1.258 albertel 12689: if (exists($env{'form.'.$setting})) {
1.153 matthew 12690: # Save this value away
12691: if ($type eq 'scalar' &&
1.258 albertel 12692: (! exists($env{$envname}) ||
12693: $env{$envname} ne $env{'form.'.$setting})) {
12694: $SaveHash{$basename} = $env{'form.'.$setting};
12695: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 12696: } elsif ($type eq 'array') {
12697: my $stored_form;
1.258 albertel 12698: if (ref($env{'form.'.$setting})) {
1.153 matthew 12699: $stored_form = join(',',
12700: map {
1.369 www 12701: &escape($_);
1.258 albertel 12702: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 12703: } else {
12704: $stored_form =
1.369 www 12705: &escape($env{'form.'.$setting});
1.153 matthew 12706: }
12707: # Determine if the array contents are the same.
1.258 albertel 12708: if ($stored_form ne $env{$envname}) {
1.153 matthew 12709: $SaveHash{$basename} = $stored_form;
12710: $AppHash{$envname} = $stored_form;
12711: }
12712: }
12713: }
12714: }
12715: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 12716: $udom,$uname);
1.153 matthew 12717: if ($put_result !~ /^(ok|delayed)/) {
12718: &Apache::lonnet::logthis('unable to save form parameters, '.
12719: 'got error:'.$put_result);
12720: }
12721: # Make sure these settings stick around in this session, too
1.646 raeburn 12722: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 12723: return;
12724: }
12725:
12726: sub restore_course_settings {
1.499 albertel 12727: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 12728: }
12729:
12730: sub restore_settings {
12731: my ($context,$prefix,$Settings) = @_;
1.153 matthew 12732: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 12733: next if (exists($env{'form.'.$setting}));
1.496 albertel 12734: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 12735: '.'.$setting;
1.258 albertel 12736: if (exists($env{$envname})) {
1.153 matthew 12737: if ($type eq 'scalar') {
1.258 albertel 12738: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 12739: } elsif ($type eq 'array') {
1.258 albertel 12740: $env{'form.'.$setting} = [
1.153 matthew 12741: map {
1.369 www 12742: &unescape($_);
1.258 albertel 12743: } split(',',$env{$envname})
1.153 matthew 12744: ];
12745: }
12746: }
12747: }
1.127 matthew 12748: }
12749:
1.618 raeburn 12750: #######################################################
12751: #######################################################
12752:
12753: =pod
12754:
12755: =head1 Domain E-mail Routines
12756:
12757: =over 4
12758:
1.648 raeburn 12759: =item * &build_recipient_list()
1.618 raeburn 12760:
1.884 raeburn 12761: Build recipient lists for five types of e-mail:
1.766 raeburn 12762: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 12763: (d) Help requests, (e) Course requests needing approval, generated by
12764: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
12765: loncoursequeueadmin.pm respectively.
1.618 raeburn 12766:
12767: Inputs:
1.619 raeburn 12768: defmail (scalar - email address of default recipient),
1.618 raeburn 12769: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 12770: defdom (domain for which to retrieve configuration settings),
12771: origmail (scalar - email address of recipient from loncapa.conf,
12772: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 12773:
1.655 raeburn 12774: Returns: comma separated list of addresses to which to send e-mail.
12775:
12776: =back
1.618 raeburn 12777:
12778: =cut
12779:
12780: ############################################################
12781: ############################################################
12782: sub build_recipient_list {
1.619 raeburn 12783: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 12784: my @recipients;
12785: my $otheremails;
12786: my %domconfig =
12787: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
12788: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 12789: if (exists($domconfig{'contacts'}{$mailing})) {
12790: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
12791: my @contacts = ('adminemail','supportemail');
12792: foreach my $item (@contacts) {
12793: if ($domconfig{'contacts'}{$mailing}{$item}) {
12794: my $addr = $domconfig{'contacts'}{$item};
12795: if (!grep(/^\Q$addr\E$/,@recipients)) {
12796: push(@recipients,$addr);
12797: }
1.619 raeburn 12798: }
1.766 raeburn 12799: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 12800: }
12801: }
1.766 raeburn 12802: } elsif ($origmail ne '') {
12803: push(@recipients,$origmail);
1.618 raeburn 12804: }
1.619 raeburn 12805: } elsif ($origmail ne '') {
12806: push(@recipients,$origmail);
1.618 raeburn 12807: }
1.688 raeburn 12808: if (defined($defmail)) {
12809: if ($defmail ne '') {
12810: push(@recipients,$defmail);
12811: }
1.618 raeburn 12812: }
12813: if ($otheremails) {
1.619 raeburn 12814: my @others;
12815: if ($otheremails =~ /,/) {
12816: @others = split(/,/,$otheremails);
1.618 raeburn 12817: } else {
1.619 raeburn 12818: push(@others,$otheremails);
12819: }
12820: foreach my $addr (@others) {
12821: if (!grep(/^\Q$addr\E$/,@recipients)) {
12822: push(@recipients,$addr);
12823: }
1.618 raeburn 12824: }
12825: }
1.619 raeburn 12826: my $recipientlist = join(',',@recipients);
1.618 raeburn 12827: return $recipientlist;
12828: }
12829:
1.127 matthew 12830: ############################################################
12831: ############################################################
1.154 albertel 12832:
1.655 raeburn 12833: =pod
12834:
12835: =head1 Course Catalog Routines
12836:
12837: =over 4
12838:
12839: =item * &gather_categories()
12840:
12841: Converts category definitions - keys of categories hash stored in
12842: coursecategories in configuration.db on the primary library server in a
12843: domain - to an array. Also generates javascript and idx hash used to
12844: generate Domain Coordinator interface for editing Course Categories.
12845:
12846: Inputs:
1.663 raeburn 12847:
1.655 raeburn 12848: categories (reference to hash of category definitions).
1.663 raeburn 12849:
1.655 raeburn 12850: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12851: categories and subcategories).
1.663 raeburn 12852:
1.655 raeburn 12853: idx (reference to hash of counters used in Domain Coordinator interface for
12854: editing Course Categories).
1.663 raeburn 12855:
1.655 raeburn 12856: jsarray (reference to array of categories used to create Javascript arrays for
12857: Domain Coordinator interface for editing Course Categories).
12858:
12859: Returns: nothing
12860:
12861: Side effects: populates cats, idx and jsarray.
12862:
12863: =cut
12864:
12865: sub gather_categories {
12866: my ($categories,$cats,$idx,$jsarray) = @_;
12867: my %counters;
12868: my $num = 0;
12869: foreach my $item (keys(%{$categories})) {
12870: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12871: if ($container eq '' && $depth == 0) {
12872: $cats->[$depth][$categories->{$item}] = $cat;
12873: } else {
12874: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
12875: }
12876: my ($escitem,$tail) = split(/:/,$item,2);
12877: if ($counters{$tail} eq '') {
12878: $counters{$tail} = $num;
12879: $num ++;
12880: }
12881: if (ref($idx) eq 'HASH') {
12882: $idx->{$item} = $counters{$tail};
12883: }
12884: if (ref($jsarray) eq 'ARRAY') {
12885: push(@{$jsarray->[$counters{$tail}]},$item);
12886: }
12887: }
12888: return;
12889: }
12890:
12891: =pod
12892:
12893: =item * &extract_categories()
12894:
12895: Used to generate breadcrumb trails for course categories.
12896:
12897: Inputs:
1.663 raeburn 12898:
1.655 raeburn 12899: categories (reference to hash of category definitions).
1.663 raeburn 12900:
1.655 raeburn 12901: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12902: categories and subcategories).
1.663 raeburn 12903:
1.655 raeburn 12904: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 12905:
1.655 raeburn 12906: allitems (reference to hash - key is category key
12907: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 12908:
1.655 raeburn 12909: idx (reference to hash of counters used in Domain Coordinator interface for
12910: editing Course Categories).
1.663 raeburn 12911:
1.655 raeburn 12912: jsarray (reference to array of categories used to create Javascript arrays for
12913: Domain Coordinator interface for editing Course Categories).
12914:
1.665 raeburn 12915: subcats (reference to hash of arrays containing all subcategories within each
12916: category, -recursive)
12917:
1.655 raeburn 12918: Returns: nothing
12919:
12920: Side effects: populates trails and allitems hash references.
12921:
12922: =cut
12923:
12924: sub extract_categories {
1.665 raeburn 12925: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 12926: if (ref($categories) eq 'HASH') {
12927: &gather_categories($categories,$cats,$idx,$jsarray);
12928: if (ref($cats->[0]) eq 'ARRAY') {
12929: for (my $i=0; $i<@{$cats->[0]}; $i++) {
12930: my $name = $cats->[0][$i];
12931: my $item = &escape($name).'::0';
12932: my $trailstr;
12933: if ($name eq 'instcode') {
12934: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 12935: } elsif ($name eq 'communities') {
12936: $trailstr = &mt('Communities');
1.655 raeburn 12937: } else {
12938: $trailstr = $name;
12939: }
12940: if ($allitems->{$item} eq '') {
12941: push(@{$trails},$trailstr);
12942: $allitems->{$item} = scalar(@{$trails})-1;
12943: }
12944: my @parents = ($name);
12945: if (ref($cats->[1]{$name}) eq 'ARRAY') {
12946: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
12947: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 12948: if (ref($subcats) eq 'HASH') {
12949: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
12950: }
12951: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
12952: }
12953: } else {
12954: if (ref($subcats) eq 'HASH') {
12955: $subcats->{$item} = [];
1.655 raeburn 12956: }
12957: }
12958: }
12959: }
12960: }
12961: return;
12962: }
12963:
12964: =pod
12965:
12966: =item *&recurse_categories()
12967:
12968: Recursively used to generate breadcrumb trails for course categories.
12969:
12970: Inputs:
1.663 raeburn 12971:
1.655 raeburn 12972: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12973: categories and subcategories).
1.663 raeburn 12974:
1.655 raeburn 12975: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 12976:
12977: category (current course category, for which breadcrumb trail is being generated).
12978:
12979: trails (reference to array of breadcrumb trails for each category).
12980:
1.655 raeburn 12981: allitems (reference to hash - key is category key
12982: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 12983:
1.655 raeburn 12984: parents (array containing containers directories for current category,
12985: back to top level).
12986:
12987: Returns: nothing
12988:
12989: Side effects: populates trails and allitems hash references
12990:
12991: =cut
12992:
12993: sub recurse_categories {
1.665 raeburn 12994: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 12995: my $shallower = $depth - 1;
12996: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
12997: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
12998: my $name = $cats->[$depth]{$category}[$k];
12999: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13000: my $trailstr = join(' -> ',(@{$parents},$category));
13001: if ($allitems->{$item} eq '') {
13002: push(@{$trails},$trailstr);
13003: $allitems->{$item} = scalar(@{$trails})-1;
13004: }
13005: my $deeper = $depth+1;
13006: push(@{$parents},$category);
1.665 raeburn 13007: if (ref($subcats) eq 'HASH') {
13008: my $subcat = &escape($name).':'.$category.':'.$depth;
13009: for (my $j=@{$parents}; $j>=0; $j--) {
13010: my $higher;
13011: if ($j > 0) {
13012: $higher = &escape($parents->[$j]).':'.
13013: &escape($parents->[$j-1]).':'.$j;
13014: } else {
13015: $higher = &escape($parents->[$j]).'::'.$j;
13016: }
13017: push(@{$subcats->{$higher}},$subcat);
13018: }
13019: }
13020: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13021: $subcats);
1.655 raeburn 13022: pop(@{$parents});
13023: }
13024: } else {
13025: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13026: my $trailstr = join(' -> ',(@{$parents},$category));
13027: if ($allitems->{$item} eq '') {
13028: push(@{$trails},$trailstr);
13029: $allitems->{$item} = scalar(@{$trails})-1;
13030: }
13031: }
13032: return;
13033: }
13034:
1.663 raeburn 13035: =pod
13036:
13037: =item *&assign_categories_table()
13038:
13039: Create a datatable for display of hierarchical categories in a domain,
13040: with checkboxes to allow a course to be categorized.
13041:
13042: Inputs:
13043:
13044: cathash - reference to hash of categories defined for the domain (from
13045: configuration.db)
13046:
13047: currcat - scalar with an & separated list of categories assigned to a course.
13048:
1.919 raeburn 13049: type - scalar contains course type (Course or Community).
13050:
1.663 raeburn 13051: Returns: $output (markup to be displayed)
13052:
13053: =cut
13054:
13055: sub assign_categories_table {
1.919 raeburn 13056: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13057: my $output;
13058: if (ref($cathash) eq 'HASH') {
13059: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13060: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13061: $maxdepth = scalar(@cats);
13062: if (@cats > 0) {
13063: my $itemcount = 0;
13064: if (ref($cats[0]) eq 'ARRAY') {
13065: my @currcategories;
13066: if ($currcat ne '') {
13067: @currcategories = split('&',$currcat);
13068: }
1.919 raeburn 13069: my $table;
1.663 raeburn 13070: for (my $i=0; $i<@{$cats[0]}; $i++) {
13071: my $parent = $cats[0][$i];
1.919 raeburn 13072: next if ($parent eq 'instcode');
13073: if ($type eq 'Community') {
13074: next unless ($parent eq 'communities');
13075: } else {
13076: next if ($parent eq 'communities');
13077: }
1.663 raeburn 13078: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13079: my $item = &escape($parent).'::0';
13080: my $checked = '';
13081: if (@currcategories > 0) {
13082: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13083: $checked = ' checked="checked"';
1.663 raeburn 13084: }
13085: }
1.919 raeburn 13086: my $parent_title = $parent;
13087: if ($parent eq 'communities') {
13088: $parent_title = &mt('Communities');
13089: }
13090: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13091: '<input type="checkbox" name="usecategory" value="'.
13092: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13093: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13094: my $depth = 1;
13095: push(@path,$parent);
1.919 raeburn 13096: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13097: pop(@path);
1.919 raeburn 13098: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13099: $itemcount ++;
13100: }
1.919 raeburn 13101: if ($itemcount) {
13102: $output = &Apache::loncommon::start_data_table().
13103: $table.
13104: &Apache::loncommon::end_data_table();
13105: }
1.663 raeburn 13106: }
13107: }
13108: }
13109: return $output;
13110: }
13111:
13112: =pod
13113:
13114: =item *&assign_category_rows()
13115:
13116: Create a datatable row for display of nested categories in a domain,
13117: with checkboxes to allow a course to be categorized,called recursively.
13118:
13119: Inputs:
13120:
13121: itemcount - track row number for alternating colors
13122:
13123: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13124: categories and subcategories.
13125:
13126: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13127:
13128: parent - parent of current category item
13129:
13130: path - Array containing all categories back up through the hierarchy from the
13131: current category to the top level.
13132:
13133: currcategories - reference to array of current categories assigned to the course
13134:
13135: Returns: $output (markup to be displayed).
13136:
13137: =cut
13138:
13139: sub assign_category_rows {
13140: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13141: my ($text,$name,$item,$chgstr);
13142: if (ref($cats) eq 'ARRAY') {
13143: my $maxdepth = scalar(@{$cats});
13144: if (ref($cats->[$depth]) eq 'HASH') {
13145: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13146: my $numchildren = @{$cats->[$depth]{$parent}};
13147: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13148: $text .= '<td><table class="LC_datatable">';
13149: for (my $j=0; $j<$numchildren; $j++) {
13150: $name = $cats->[$depth]{$parent}[$j];
13151: $item = &escape($name).':'.&escape($parent).':'.$depth;
13152: my $deeper = $depth+1;
13153: my $checked = '';
13154: if (ref($currcategories) eq 'ARRAY') {
13155: if (@{$currcategories} > 0) {
13156: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13157: $checked = ' checked="checked"';
1.663 raeburn 13158: }
13159: }
13160: }
1.664 raeburn 13161: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13162: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13163: $item.'"'.$checked.' />'.$name.'</label></span>'.
13164: '<input type="hidden" name="catname" value="'.$name.'" />'.
13165: '</td><td>';
1.663 raeburn 13166: if (ref($path) eq 'ARRAY') {
13167: push(@{$path},$name);
13168: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13169: pop(@{$path});
13170: }
13171: $text .= '</td></tr>';
13172: }
13173: $text .= '</table></td>';
13174: }
13175: }
13176: }
13177: return $text;
13178: }
13179:
1.655 raeburn 13180: ############################################################
13181: ############################################################
13182:
13183:
1.443 albertel 13184: sub commit_customrole {
1.664 raeburn 13185: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13186: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13187: ($start?', '.&mt('starting').' '.localtime($start):'').
13188: ($end?', ending '.localtime($end):'').': <b>'.
13189: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13190: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13191: '</b><br />';
13192: return $output;
13193: }
13194:
13195: sub commit_standardrole {
1.1075.2.31 raeburn 13196: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13197: my ($output,$logmsg,$linefeed);
13198: if ($context eq 'auto') {
13199: $linefeed = "\n";
13200: } else {
13201: $linefeed = "<br />\n";
13202: }
1.443 albertel 13203: if ($three eq 'st') {
1.541 raeburn 13204: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 13205: $one,$two,$sec,$context,$credits);
1.541 raeburn 13206: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13207: ($result eq 'unknown_course') || ($result eq 'refused')) {
13208: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13209: } else {
1.541 raeburn 13210: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13211: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13212: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13213: if ($context eq 'auto') {
13214: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13215: } else {
13216: $output .= '<b>'.$result.'</b>'.$linefeed.
13217: &mt('Add to classlist').': <b>ok</b>';
13218: }
13219: $output .= $linefeed;
1.443 albertel 13220: }
13221: } else {
13222: $output = &mt('Assigning').' '.$three.' in '.$url.
13223: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13224: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13225: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13226: if ($context eq 'auto') {
13227: $output .= $result.$linefeed;
13228: } else {
13229: $output .= '<b>'.$result.'</b>'.$linefeed;
13230: }
1.443 albertel 13231: }
13232: return $output;
13233: }
13234:
13235: sub commit_studentrole {
1.1075.2.31 raeburn 13236: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13237: $credits) = @_;
1.626 raeburn 13238: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13239: if ($context eq 'auto') {
13240: $linefeed = "\n";
13241: } else {
13242: $linefeed = '<br />'."\n";
13243: }
1.443 albertel 13244: if (defined($one) && defined($two)) {
13245: my $cid=$one.'_'.$two;
13246: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13247: my $secchange = 0;
13248: my $expire_role_result;
13249: my $modify_section_result;
1.628 raeburn 13250: if ($oldsec ne '-1') {
13251: if ($oldsec ne $sec) {
1.443 albertel 13252: $secchange = 1;
1.628 raeburn 13253: my $now = time;
1.443 albertel 13254: my $uurl='/'.$cid;
13255: $uurl=~s/\_/\//g;
13256: if ($oldsec) {
13257: $uurl.='/'.$oldsec;
13258: }
1.626 raeburn 13259: $oldsecurl = $uurl;
1.628 raeburn 13260: $expire_role_result =
1.652 raeburn 13261: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13262: if ($env{'request.course.sec'} ne '') {
13263: if ($expire_role_result eq 'refused') {
13264: my @roles = ('st');
13265: my @statuses = ('previous');
13266: my @roledoms = ($one);
13267: my $withsec = 1;
13268: my %roleshash =
13269: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13270: \@statuses,\@roles,\@roledoms,$withsec);
13271: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13272: my ($oldstart,$oldend) =
13273: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13274: if ($oldend > 0 && $oldend <= $now) {
13275: $expire_role_result = 'ok';
13276: }
13277: }
13278: }
13279: }
1.443 albertel 13280: $result = $expire_role_result;
13281: }
13282: }
13283: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 13284: $modify_section_result =
13285: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13286: undef,undef,undef,$sec,
13287: $end,$start,'','',$cid,
13288: '',$context,$credits);
1.443 albertel 13289: if ($modify_section_result =~ /^ok/) {
13290: if ($secchange == 1) {
1.628 raeburn 13291: if ($sec eq '') {
13292: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13293: } else {
13294: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13295: }
1.443 albertel 13296: } elsif ($oldsec eq '-1') {
1.628 raeburn 13297: if ($sec eq '') {
13298: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13299: } else {
13300: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13301: }
1.443 albertel 13302: } else {
1.628 raeburn 13303: if ($sec eq '') {
13304: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13305: } else {
13306: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13307: }
1.443 albertel 13308: }
13309: } else {
1.628 raeburn 13310: if ($secchange) {
13311: $$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;
13312: } else {
13313: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13314: }
1.443 albertel 13315: }
13316: $result = $modify_section_result;
13317: } elsif ($secchange == 1) {
1.628 raeburn 13318: if ($oldsec eq '') {
1.1075.2.20 raeburn 13319: $$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 13320: } else {
13321: $$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;
13322: }
1.626 raeburn 13323: if ($expire_role_result eq 'refused') {
13324: my $newsecurl = '/'.$cid;
13325: $newsecurl =~ s/\_/\//g;
13326: if ($sec ne '') {
13327: $newsecurl.='/'.$sec;
13328: }
13329: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13330: if ($sec eq '') {
13331: $$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;
13332: } else {
13333: $$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;
13334: }
13335: }
13336: }
1.443 albertel 13337: }
13338: } else {
1.626 raeburn 13339: $$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 13340: $result = "error: incomplete course id\n";
13341: }
13342: return $result;
13343: }
13344:
1.1075.2.25 raeburn 13345: sub show_role_extent {
13346: my ($scope,$context,$role) = @_;
13347: $scope =~ s{^/}{};
13348: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13349: push(@courseroles,'co');
13350: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13351: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13352: $scope =~ s{/}{_};
13353: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13354: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13355: my ($audom,$auname) = split(/\//,$scope);
13356: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13357: &Apache::loncommon::plainname($auname,$audom).'</span>');
13358: } else {
13359: $scope =~ s{/$}{};
13360: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13361: &Apache::lonnet::domain($scope,'description').'</span>');
13362: }
13363: }
13364:
1.443 albertel 13365: ############################################################
13366: ############################################################
13367:
1.566 albertel 13368: sub check_clone {
1.578 raeburn 13369: my ($args,$linefeed) = @_;
1.566 albertel 13370: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13371: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13372: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13373: my $clonemsg;
13374: my $can_clone = 0;
1.944 raeburn 13375: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13376: if ($lctype ne 'community') {
13377: $lctype = 'course';
13378: }
1.566 albertel 13379: if ($clonehome eq 'no_host') {
1.944 raeburn 13380: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13381: $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'});
13382: } else {
13383: $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'});
13384: }
1.566 albertel 13385: } else {
13386: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13387: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13388: if ($clonedesc{'type'} ne 'Community') {
13389: $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'});
13390: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13391: }
13392: }
1.882 raeburn 13393: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13394: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13395: $can_clone = 1;
13396: } else {
13397: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13398: $args->{'clonedomain'},$args->{'clonecourse'});
13399: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13400: if (grep(/^\*$/,@cloners)) {
13401: $can_clone = 1;
13402: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13403: $can_clone = 1;
13404: } else {
1.908 raeburn 13405: my $ccrole = 'cc';
1.944 raeburn 13406: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13407: $ccrole = 'co';
13408: }
1.578 raeburn 13409: my %roleshash =
13410: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13411: $args->{'ccdomain'},
1.908 raeburn 13412: 'userroles',['active'],[$ccrole],
1.578 raeburn 13413: [$args->{'clonedomain'}]);
1.908 raeburn 13414: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13415: $can_clone = 1;
13416: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13417: $can_clone = 1;
13418: } else {
1.944 raeburn 13419: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13420: $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'});
13421: } else {
13422: $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'});
13423: }
1.578 raeburn 13424: }
1.566 albertel 13425: }
1.578 raeburn 13426: }
1.566 albertel 13427: }
13428: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13429: }
13430:
1.444 albertel 13431: sub construct_course {
1.885 raeburn 13432: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 13433: my $outcome;
1.541 raeburn 13434: my $linefeed = '<br />'."\n";
13435: if ($context eq 'auto') {
13436: $linefeed = "\n";
13437: }
1.566 albertel 13438:
13439: #
13440: # Are we cloning?
13441: #
13442: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13443: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13444: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13445: if ($context ne 'auto') {
1.578 raeburn 13446: if ($clonemsg ne '') {
13447: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13448: }
1.566 albertel 13449: }
13450: $outcome .= $clonemsg.$linefeed;
13451:
13452: if (!$can_clone) {
13453: return (0,$outcome);
13454: }
13455: }
13456:
1.444 albertel 13457: #
13458: # Open course
13459: #
13460: my $crstype = lc($args->{'crstype'});
13461: my %cenv=();
13462: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13463: $args->{'cdescr'},
13464: $args->{'curl'},
13465: $args->{'course_home'},
13466: $args->{'nonstandard'},
13467: $args->{'crscode'},
13468: $args->{'ccuname'}.':'.
13469: $args->{'ccdomain'},
1.882 raeburn 13470: $args->{'crstype'},
1.885 raeburn 13471: $cnum,$context,$category);
1.444 albertel 13472:
13473: # Note: The testing routines depend on this being output; see
13474: # Utils::Course. This needs to at least be output as a comment
13475: # if anyone ever decides to not show this, and Utils::Course::new
13476: # will need to be suitably modified.
1.541 raeburn 13477: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13478: if ($$courseid =~ /^error:/) {
13479: return (0,$outcome);
13480: }
13481:
1.444 albertel 13482: #
13483: # Check if created correctly
13484: #
1.479 albertel 13485: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13486: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13487: if ($crsuhome eq 'no_host') {
13488: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13489: return (0,$outcome);
13490: }
1.541 raeburn 13491: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13492:
1.444 albertel 13493: #
1.566 albertel 13494: # Do the cloning
13495: #
13496: if ($can_clone && $cloneid) {
13497: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13498: if ($context ne 'auto') {
13499: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13500: }
13501: $outcome .= $clonemsg.$linefeed;
13502: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13503: # Copy all files
1.637 www 13504: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13505: # Restore URL
1.566 albertel 13506: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13507: # Restore title
1.566 albertel 13508: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13509: # Restore creation date, creator and creation context.
13510: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13511: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13512: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13513: # Mark as cloned
1.566 albertel 13514: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13515: # Need to clone grading mode
13516: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13517: $cenv{'grading'}=$newenv{'grading'};
13518: # Do not clone these environment entries
13519: &Apache::lonnet::del('environment',
13520: ['default_enrollment_start_date',
13521: 'default_enrollment_end_date',
13522: 'question.email',
13523: 'policy.email',
13524: 'comment.email',
13525: 'pch.users.denied',
1.725 raeburn 13526: 'plc.users.denied',
13527: 'hidefromcat',
13528: 'categories'],
1.638 www 13529: $$crsudom,$$crsunum);
1.444 albertel 13530: }
1.566 albertel 13531:
1.444 albertel 13532: #
13533: # Set environment (will override cloned, if existing)
13534: #
13535: my @sections = ();
13536: my @xlists = ();
13537: if ($args->{'crstype'}) {
13538: $cenv{'type'}=$args->{'crstype'};
13539: }
13540: if ($args->{'crsid'}) {
13541: $cenv{'courseid'}=$args->{'crsid'};
13542: }
13543: if ($args->{'crscode'}) {
13544: $cenv{'internal.coursecode'}=$args->{'crscode'};
13545: }
13546: if ($args->{'crsquota'} ne '') {
13547: $cenv{'internal.coursequota'}=$args->{'crsquota'};
13548: } else {
13549: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
13550: }
13551: if ($args->{'ccuname'}) {
13552: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
13553: ':'.$args->{'ccdomain'};
13554: } else {
13555: $cenv{'internal.courseowner'} = $args->{'curruser'};
13556: }
1.1075.2.31 raeburn 13557: if ($args->{'defaultcredits'}) {
13558: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
13559: }
1.444 albertel 13560: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
13561: if ($args->{'crssections'}) {
13562: $cenv{'internal.sectionnums'} = '';
13563: if ($args->{'crssections'} =~ m/,/) {
13564: @sections = split/,/,$args->{'crssections'};
13565: } else {
13566: $sections[0] = $args->{'crssections'};
13567: }
13568: if (@sections > 0) {
13569: foreach my $item (@sections) {
13570: my ($sec,$gp) = split/:/,$item;
13571: my $class = $args->{'crscode'}.$sec;
13572: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
13573: $cenv{'internal.sectionnums'} .= $item.',';
13574: unless ($addcheck eq 'ok') {
13575: push @badclasses, $class;
13576: }
13577: }
13578: $cenv{'internal.sectionnums'} =~ s/,$//;
13579: }
13580: }
13581: # do not hide course coordinator from staff listing,
13582: # even if privileged
13583: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13584: # add crosslistings
13585: if ($args->{'crsxlist'}) {
13586: $cenv{'internal.crosslistings'}='';
13587: if ($args->{'crsxlist'} =~ m/,/) {
13588: @xlists = split/,/,$args->{'crsxlist'};
13589: } else {
13590: $xlists[0] = $args->{'crsxlist'};
13591: }
13592: if (@xlists > 0) {
13593: foreach my $item (@xlists) {
13594: my ($xl,$gp) = split/:/,$item;
13595: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
13596: $cenv{'internal.crosslistings'} .= $item.',';
13597: unless ($addcheck eq 'ok') {
13598: push @badclasses, $xl;
13599: }
13600: }
13601: $cenv{'internal.crosslistings'} =~ s/,$//;
13602: }
13603: }
13604: if ($args->{'autoadds'}) {
13605: $cenv{'internal.autoadds'}=$args->{'autoadds'};
13606: }
13607: if ($args->{'autodrops'}) {
13608: $cenv{'internal.autodrops'}=$args->{'autodrops'};
13609: }
13610: # check for notification of enrollment changes
13611: my @notified = ();
13612: if ($args->{'notify_owner'}) {
13613: if ($args->{'ccuname'} ne '') {
13614: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
13615: }
13616: }
13617: if ($args->{'notify_dc'}) {
13618: if ($uname ne '') {
1.630 raeburn 13619: push(@notified,$uname.':'.$udom);
1.444 albertel 13620: }
13621: }
13622: if (@notified > 0) {
13623: my $notifylist;
13624: if (@notified > 1) {
13625: $notifylist = join(',',@notified);
13626: } else {
13627: $notifylist = $notified[0];
13628: }
13629: $cenv{'internal.notifylist'} = $notifylist;
13630: }
13631: if (@badclasses > 0) {
13632: my %lt=&Apache::lonlocal::texthash(
13633: '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',
13634: 'dnhr' => 'does not have rights to access enrollment in these classes',
13635: 'adby' => 'as determined by the policies of your institution on access to official classlists'
13636: );
1.541 raeburn 13637: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
13638: ' ('.$lt{'adby'}.')';
13639: if ($context eq 'auto') {
13640: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 13641: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 13642: foreach my $item (@badclasses) {
13643: if ($context eq 'auto') {
13644: $outcome .= " - $item\n";
13645: } else {
13646: $outcome .= "<li>$item</li>\n";
13647: }
13648: }
13649: if ($context eq 'auto') {
13650: $outcome .= $linefeed;
13651: } else {
1.566 albertel 13652: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 13653: }
13654: }
1.444 albertel 13655: }
13656: if ($args->{'no_end_date'}) {
13657: $args->{'endaccess'} = 0;
13658: }
13659: $cenv{'internal.autostart'}=$args->{'enrollstart'};
13660: $cenv{'internal.autoend'}=$args->{'enrollend'};
13661: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
13662: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
13663: if ($args->{'showphotos'}) {
13664: $cenv{'internal.showphotos'}=$args->{'showphotos'};
13665: }
13666: $cenv{'internal.authtype'} = $args->{'authtype'};
13667: $cenv{'internal.autharg'} = $args->{'autharg'};
13668: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
13669: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 13670: 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');
13671: if ($context eq 'auto') {
13672: $outcome .= $krb_msg;
13673: } else {
1.566 albertel 13674: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 13675: }
13676: $outcome .= $linefeed;
1.444 albertel 13677: }
13678: }
13679: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
13680: if ($args->{'setpolicy'}) {
13681: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13682: }
13683: if ($args->{'setcontent'}) {
13684: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13685: }
13686: }
13687: if ($args->{'reshome'}) {
13688: $cenv{'reshome'}=$args->{'reshome'}.'/';
13689: $cenv{'reshome'}=~s/\/+$/\//;
13690: }
13691: #
13692: # course has keyed access
13693: #
13694: if ($args->{'setkeys'}) {
13695: $cenv{'keyaccess'}='yes';
13696: }
13697: # if specified, key authority is not course, but user
13698: # only active if keyaccess is yes
13699: if ($args->{'keyauth'}) {
1.487 albertel 13700: my ($user,$domain) = split(':',$args->{'keyauth'});
13701: $user = &LONCAPA::clean_username($user);
13702: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 13703: if ($user ne '' && $domain ne '') {
1.487 albertel 13704: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 13705: }
13706: }
13707:
13708: if ($args->{'disresdis'}) {
13709: $cenv{'pch.roles.denied'}='st';
13710: }
13711: if ($args->{'disablechat'}) {
13712: $cenv{'plc.roles.denied'}='st';
13713: }
13714:
13715: # Record we've not yet viewed the Course Initialization Helper for this
13716: # course
13717: $cenv{'course.helper.not.run'} = 1;
13718: #
13719: # Use new Randomseed
13720: #
13721: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
13722: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
13723: #
13724: # The encryption code and receipt prefix for this course
13725: #
13726: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
13727: $cenv{'internal.encpref'}=100+int(9*rand(99));
13728: #
13729: # By default, use standard grading
13730: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
13731:
1.541 raeburn 13732: $outcome .= $linefeed.&mt('Setting environment').': '.
13733: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 13734: #
13735: # Open all assignments
13736: #
13737: if ($args->{'openall'}) {
13738: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
13739: my %storecontent = ($storeunder => time,
13740: $storeunder.'.type' => 'date_start');
13741:
13742: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 13743: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 13744: }
13745: #
13746: # Set first page
13747: #
13748: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
13749: || ($cloneid)) {
1.445 albertel 13750: use LONCAPA::map;
1.444 albertel 13751: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 13752:
13753: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
13754: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
13755:
1.444 albertel 13756: $outcome .= ($fatal?$errtext:'read ok').' - ';
13757: my $title; my $url;
13758: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 13759: $title=&mt('Syllabus');
1.444 albertel 13760: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
13761: } else {
1.963 raeburn 13762: $title=&mt('Table of Contents');
1.444 albertel 13763: $url='/adm/navmaps';
13764: }
1.445 albertel 13765:
13766: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
13767: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
13768:
13769: if ($errtext) { $fatal=2; }
1.541 raeburn 13770: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 13771: }
1.566 albertel 13772:
13773: return (1,$outcome);
1.444 albertel 13774: }
13775:
13776: ############################################################
13777: ############################################################
13778:
1.953 droeschl 13779: #SD
13780: # only Community and Course, or anything else?
1.378 raeburn 13781: sub course_type {
13782: my ($cid) = @_;
13783: if (!defined($cid)) {
13784: $cid = $env{'request.course.id'};
13785: }
1.404 albertel 13786: if (defined($env{'course.'.$cid.'.type'})) {
13787: return $env{'course.'.$cid.'.type'};
1.378 raeburn 13788: } else {
13789: return 'Course';
1.377 raeburn 13790: }
13791: }
1.156 albertel 13792:
1.406 raeburn 13793: sub group_term {
13794: my $crstype = &course_type();
13795: my %names = (
13796: 'Course' => 'group',
1.865 raeburn 13797: 'Community' => 'group',
1.406 raeburn 13798: );
13799: return $names{$crstype};
13800: }
13801:
1.902 raeburn 13802: sub course_types {
13803: my @types = ('official','unofficial','community');
13804: my %typename = (
13805: official => 'Official course',
13806: unofficial => 'Unofficial course',
13807: community => 'Community',
13808: );
13809: return (\@types,\%typename);
13810: }
13811:
1.156 albertel 13812: sub icon {
13813: my ($file)=@_;
1.505 albertel 13814: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 13815: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 13816: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 13817: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
13818: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
13819: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
13820: $curfext.".gif") {
13821: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
13822: $curfext.".gif";
13823: }
13824: }
1.249 albertel 13825: return &lonhttpdurl($iconname);
1.154 albertel 13826: }
1.84 albertel 13827:
1.575 albertel 13828: sub lonhttpdurl {
1.692 www 13829: #
13830: # Had been used for "small fry" static images on separate port 8080.
13831: # Modify here if lightweight http functionality desired again.
13832: # Currently eliminated due to increasing firewall issues.
13833: #
1.575 albertel 13834: my ($url)=@_;
1.692 www 13835: return $url;
1.215 albertel 13836: }
13837:
1.213 albertel 13838: sub connection_aborted {
13839: my ($r)=@_;
13840: $r->print(" ");$r->rflush();
13841: my $c = $r->connection;
13842: return $c->aborted();
13843: }
13844:
1.221 foxr 13845: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 13846: # strings as 'strings'.
13847: sub escape_single {
1.221 foxr 13848: my ($input) = @_;
1.223 albertel 13849: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 13850: $input =~ s/\'/\\\'/g; # Esacpe the 's....
13851: return $input;
13852: }
1.223 albertel 13853:
1.222 foxr 13854: # Same as escape_single, but escape's "'s This
13855: # can be used for "strings"
13856: sub escape_double {
13857: my ($input) = @_;
13858: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
13859: $input =~ s/\"/\\\"/g; # Esacpe the "s....
13860: return $input;
13861: }
1.223 albertel 13862:
1.222 foxr 13863: # Escapes the last element of a full URL.
13864: sub escape_url {
13865: my ($url) = @_;
1.238 raeburn 13866: my @urlslices = split(/\//, $url,-1);
1.369 www 13867: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 13868: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 13869: }
1.462 albertel 13870:
1.820 raeburn 13871: sub compare_arrays {
13872: my ($arrayref1,$arrayref2) = @_;
13873: my (@difference,%count);
13874: @difference = ();
13875: %count = ();
13876: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
13877: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
13878: foreach my $element (keys(%count)) {
13879: if ($count{$element} == 1) {
13880: push(@difference,$element);
13881: }
13882: }
13883: }
13884: return @difference;
13885: }
13886:
1.817 bisitz 13887: # -------------------------------------------------------- Initialize user login
1.462 albertel 13888: sub init_user_environment {
1.463 albertel 13889: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 13890: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
13891:
13892: my $public=($username eq 'public' && $domain eq 'public');
13893:
13894: # See if old ID present, if so, remove
13895:
1.1062 raeburn 13896: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 13897: my $now=time;
13898:
13899: if ($public) {
13900: my $max_public=100;
13901: my $oldest;
13902: my $oldest_time=0;
13903: for(my $next=1;$next<=$max_public;$next++) {
13904: if (-e $lonids."/publicuser_$next.id") {
13905: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
13906: if ($mtime<$oldest_time || !$oldest_time) {
13907: $oldest_time=$mtime;
13908: $oldest=$next;
13909: }
13910: } else {
13911: $cookie="publicuser_$next";
13912: last;
13913: }
13914: }
13915: if (!$cookie) { $cookie="publicuser_$oldest"; }
13916: } else {
1.463 albertel 13917: # if this isn't a robot, kill any existing non-robot sessions
13918: if (!$args->{'robot'}) {
13919: opendir(DIR,$lonids);
13920: while ($filename=readdir(DIR)) {
13921: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
13922: unlink($lonids.'/'.$filename);
13923: }
1.462 albertel 13924: }
1.463 albertel 13925: closedir(DIR);
1.462 albertel 13926: }
13927: # Give them a new cookie
1.463 albertel 13928: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 13929: : $now.$$.int(rand(10000)));
1.463 albertel 13930: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 13931:
13932: # Initialize roles
13933:
1.1062 raeburn 13934: ($userroles,$firstaccenv,$timerintenv) =
13935: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 13936: }
13937: # ------------------------------------ Check browser type and MathML capability
13938:
13939: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
13940: $clientunicode,$clientos) = &decode_user_agent($r);
13941:
13942: # ------------------------------------------------------------- Get environment
13943:
13944: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
13945: my ($tmp) = keys(%userenv);
13946: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
13947: } else {
13948: undef(%userenv);
13949: }
13950: if (($userenv{'interface'}) && (!$form->{'interface'})) {
13951: $form->{'interface'}=$userenv{'interface'};
13952: }
13953: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
13954:
13955: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 13956: foreach my $option ('interface','localpath','localres') {
13957: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 13958: }
13959: # --------------------------------------------------------- Write first profile
13960:
13961: {
13962: my %initial_env =
13963: ("user.name" => $username,
13964: "user.domain" => $domain,
13965: "user.home" => $authhost,
13966: "browser.type" => $clientbrowser,
13967: "browser.version" => $clientversion,
13968: "browser.mathml" => $clientmathml,
13969: "browser.unicode" => $clientunicode,
13970: "browser.os" => $clientos,
13971: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
13972: "request.course.fn" => '',
13973: "request.course.uri" => '',
13974: "request.course.sec" => '',
13975: "request.role" => 'cm',
13976: "request.role.adv" => $env{'user.adv'},
13977: "request.host" => $ENV{'REMOTE_ADDR'},);
13978:
13979: if ($form->{'localpath'}) {
13980: $initial_env{"browser.localpath"} = $form->{'localpath'};
13981: $initial_env{"browser.localres"} = $form->{'localres'};
13982: }
13983:
13984: if ($form->{'interface'}) {
13985: $form->{'interface'}=~s/\W//gs;
13986: $initial_env{"browser.interface"} = $form->{'interface'};
13987: $env{'browser.interface'}=$form->{'interface'};
13988: }
13989:
1.981 raeburn 13990: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 13991: my %domdef;
13992: unless ($domain eq 'public') {
13993: %domdef = &Apache::lonnet::get_domain_defaults($domain);
13994: }
1.980 raeburn 13995:
1.1075.2.7 raeburn 13996: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 13997: $userenv{'availabletools.'.$tool} =
1.980 raeburn 13998: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
13999: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14000: }
14001:
1.864 raeburn 14002: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 14003: $userenv{'canrequest.'.$crstype} =
14004: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14005: 'reload','requestcourses',
14006: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14007: }
14008:
1.1075.2.14 raeburn 14009: $userenv{'canrequest.author'} =
14010: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14011: 'reload','requestauthor',
14012: \%userenv,\%domdef,\%is_adv);
14013: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14014: $domain,$username);
14015: my $reqstatus = $reqauthor{'author_status'};
14016: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14017: if (ref($reqauthor{'author'}) eq 'HASH') {
14018: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14019: $reqauthor{'author'}{'timestamp'};
14020: }
14021: }
14022:
1.462 albertel 14023: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14024:
1.462 albertel 14025: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14026: &GDBM_WRCREAT(),0640)) {
14027: &_add_to_env(\%disk_env,\%initial_env);
14028: &_add_to_env(\%disk_env,\%userenv,'environment.');
14029: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14030: if (ref($firstaccenv) eq 'HASH') {
14031: &_add_to_env(\%disk_env,$firstaccenv);
14032: }
14033: if (ref($timerintenv) eq 'HASH') {
14034: &_add_to_env(\%disk_env,$timerintenv);
14035: }
1.463 albertel 14036: if (ref($args->{'extra_env'})) {
14037: &_add_to_env(\%disk_env,$args->{'extra_env'});
14038: }
1.462 albertel 14039: untie(%disk_env);
14040: } else {
1.705 tempelho 14041: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14042: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14043: return 'error: '.$!;
14044: }
14045: }
14046: $env{'request.role'}='cm';
14047: $env{'request.role.adv'}=$env{'user.adv'};
14048: $env{'browser.type'}=$clientbrowser;
14049:
14050: return $cookie;
14051:
14052: }
14053:
14054: sub _add_to_env {
14055: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14056: if (ref($env_data) eq 'HASH') {
14057: while (my ($key,$value) = each(%$env_data)) {
14058: $idf->{$prefix.$key} = $value;
14059: $env{$prefix.$key} = $value;
14060: }
1.462 albertel 14061: }
14062: }
14063:
1.685 tempelho 14064: # --- Get the symbolic name of a problem and the url
14065: sub get_symb {
14066: my ($request,$silent) = @_;
1.726 raeburn 14067: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14068: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14069: if ($symb eq '') {
14070: if (!$silent) {
1.1071 raeburn 14071: if (ref($request)) {
14072: $request->print("Unable to handle ambiguous references:$url:.");
14073: }
1.685 tempelho 14074: return ();
14075: }
14076: }
14077: &Apache::lonenc::check_decrypt(\$symb);
14078: return ($symb);
14079: }
14080:
14081: # --------------------------------------------------------------Get annotation
14082:
14083: sub get_annotation {
14084: my ($symb,$enc) = @_;
14085:
14086: my $key = $symb;
14087: if (!$enc) {
14088: $key =
14089: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14090: }
14091: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14092: return $annotation{$key};
14093: }
14094:
14095: sub clean_symb {
1.731 raeburn 14096: my ($symb,$delete_enc) = @_;
1.685 tempelho 14097:
14098: &Apache::lonenc::check_decrypt(\$symb);
14099: my $enc = $env{'request.enc'};
1.731 raeburn 14100: if ($delete_enc) {
1.730 raeburn 14101: delete($env{'request.enc'});
14102: }
1.685 tempelho 14103:
14104: return ($symb,$enc);
14105: }
1.462 albertel 14106:
1.990 raeburn 14107: sub build_release_hashes {
14108: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14109: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14110: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14111: (ref($randomizetry) eq 'HASH'));
14112: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14113: my ($item,$name,$value) = split(/:/,$key);
14114: if ($item eq 'parameter') {
14115: if (ref($checkparms->{$name}) eq 'ARRAY') {
14116: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14117: push(@{$checkparms->{$name}},$value);
14118: }
14119: } else {
14120: push(@{$checkparms->{$name}},$value);
14121: }
14122: } elsif ($item eq 'resourcetag') {
14123: if ($name eq 'responsetype') {
14124: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14125: }
14126: } elsif ($item eq 'course') {
14127: if ($name eq 'crstype') {
14128: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14129: }
14130: }
14131: }
14132: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14133: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14134: return;
14135: }
14136:
1.1075.2.11 raeburn 14137: sub update_content_constraints {
14138: my ($cdom,$cnum,$chome,$cid) = @_;
14139: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14140: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14141: my %checkresponsetypes;
14142: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14143: my ($item,$name,$value) = split(/:/,$key);
14144: if ($item eq 'resourcetag') {
14145: if ($name eq 'responsetype') {
14146: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14147: }
14148: }
14149: }
14150: my $navmap = Apache::lonnavmaps::navmap->new();
14151: if (defined($navmap)) {
14152: my %allresponses;
14153: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14154: my %responses = $res->responseTypes();
14155: foreach my $key (keys(%responses)) {
14156: next unless(exists($checkresponsetypes{$key}));
14157: $allresponses{$key} += $responses{$key};
14158: }
14159: }
14160: foreach my $key (keys(%allresponses)) {
14161: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14162: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14163: ($reqdmajor,$reqdminor) = ($major,$minor);
14164: }
14165: }
14166: undef($navmap);
14167: }
14168: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14169: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14170: }
14171: return;
14172: }
14173:
1.1075.2.27 raeburn 14174: sub allmaps_incourse {
14175: my ($cdom,$cnum,$chome,$cid) = @_;
14176: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14177: $cid = $env{'request.course.id'};
14178: $cdom = $env{'course.'.$cid.'.domain'};
14179: $cnum = $env{'course.'.$cid.'.num'};
14180: $chome = $env{'course.'.$cid.'.home'};
14181: }
14182: my %allmaps = ();
14183: my $lastchange =
14184: &Apache::lonnet::get_coursechange($cdom,$cnum);
14185: if ($lastchange > $env{'request.course.tied'}) {
14186: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14187: unless ($ferr) {
14188: &update_content_constraints($cdom,$cnum,$chome,$cid);
14189: }
14190: }
14191: my $navmap = Apache::lonnavmaps::navmap->new();
14192: if (defined($navmap)) {
14193: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14194: $allmaps{$res->src()} = 1;
14195: }
14196: }
14197: return \%allmaps;
14198: }
14199:
1.1075.2.11 raeburn 14200: sub parse_supplemental_title {
14201: my ($title) = @_;
14202:
14203: my ($foldertitle,$renametitle);
14204: if ($title =~ /&&&/) {
14205: $title = &HTML::Entites::decode($title);
14206: }
14207: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14208: $renametitle=$4;
14209: my ($time,$uname,$udom) = ($1,$2,$3);
14210: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14211: my $name = &plainname($uname,$udom);
14212: $name = &HTML::Entities::encode($name,'"<>&\'');
14213: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14214: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14215: $name.': <br />'.$foldertitle;
14216: }
14217: if (wantarray) {
14218: return ($title,$foldertitle,$renametitle);
14219: }
14220: return $title;
14221: }
14222:
1.1075.2.18 raeburn 14223: sub symb_to_docspath {
14224: my ($symb) = @_;
14225: return unless ($symb);
14226: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14227: if ($resurl=~/\.(sequence|page)$/) {
14228: $mapurl=$resurl;
14229: } elsif ($resurl eq 'adm/navmaps') {
14230: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14231: }
14232: my $mapresobj;
14233: my $navmap = Apache::lonnavmaps::navmap->new();
14234: if (ref($navmap)) {
14235: $mapresobj = $navmap->getResourceByUrl($mapurl);
14236: }
14237: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14238: my $type=$2;
14239: my $path;
14240: if (ref($mapresobj)) {
14241: my $pcslist = $mapresobj->map_hierarchy();
14242: if ($pcslist ne '') {
14243: foreach my $pc (split(/,/,$pcslist)) {
14244: next if ($pc <= 1);
14245: my $res = $navmap->getByMapPc($pc);
14246: if (ref($res)) {
14247: my $thisurl = $res->src();
14248: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14249: my $thistitle = $res->title();
14250: $path .= '&'.
14251: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
14252: &Apache::lonhtmlcommon::entity_encode($thistitle).
14253: ':'.$res->randompick().
14254: ':'.$res->randomout().
14255: ':'.$res->encrypted().
14256: ':'.$res->randomorder().
14257: ':'.$res->is_page();
14258: }
14259: }
14260: }
14261: $path =~ s/^\&//;
14262: my $maptitle = $mapresobj->title();
14263: if ($mapurl eq 'default') {
14264: $maptitle = 'Main Course Documents';
14265: }
14266: $path .= (($path ne '')? '&' : '').
14267: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
14268: &Apache::lonhtmlcommon::entity_encode($maptitle).
14269: ':'.$mapresobj->randompick().
14270: ':'.$mapresobj->randomout().
14271: ':'.$mapresobj->encrypted().
14272: ':'.$mapresobj->randomorder().
14273: ':'.$mapresobj->is_page();
14274: } else {
14275: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14276: my $ispage = (($type eq 'page')? 1 : '');
14277: if ($mapurl eq 'default') {
14278: $maptitle = 'Main Course Documents';
14279: }
14280: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
14281: &Apache::lonhtmlcommon::entity_encode($maptitle).':::::'.$ispage;
14282: }
14283: unless ($mapurl eq 'default') {
14284: $path = 'default&'.
14285: &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
14286: ':::::&'.$path;
14287: }
14288: return $path;
14289: }
14290:
1.1075.2.14 raeburn 14291: sub captcha_display {
14292: my ($context,$lonhost) = @_;
14293: my ($output,$error);
14294: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
14295: if ($captcha eq 'original') {
14296: $output = &create_captcha();
14297: unless ($output) {
14298: $error = 'captcha';
14299: }
14300: } elsif ($captcha eq 'recaptcha') {
14301: $output = &create_recaptcha($pubkey);
14302: unless ($output) {
14303: $error = 'recaptcha';
14304: }
14305: }
14306: return ($output,$error);
14307: }
14308:
14309: sub captcha_response {
14310: my ($context,$lonhost) = @_;
14311: my ($captcha_chk,$captcha_error);
14312: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
14313: if ($captcha eq 'original') {
14314: ($captcha_chk,$captcha_error) = &check_captcha();
14315: } elsif ($captcha eq 'recaptcha') {
14316: $captcha_chk = &check_recaptcha($privkey);
14317: } else {
14318: $captcha_chk = 1;
14319: }
14320: return ($captcha_chk,$captcha_error);
14321: }
14322:
14323: sub get_captcha_config {
14324: my ($context,$lonhost) = @_;
14325: my ($captcha,$pubkey,$privkey,$hashtocheck);
14326: my $hostname = &Apache::lonnet::hostname($lonhost);
14327: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14328: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
14329: if ($context eq 'usercreation') {
14330: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14331: if (ref($domconfig{$context}) eq 'HASH') {
14332: $hashtocheck = $domconfig{$context}{'cancreate'};
14333: if (ref($hashtocheck) eq 'HASH') {
14334: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14335: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14336: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14337: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14338: }
14339: if ($privkey && $pubkey) {
14340: $captcha = 'recaptcha';
14341: } else {
14342: $captcha = 'original';
14343: }
14344: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14345: $captcha = 'original';
14346: }
14347: }
14348: } else {
14349: $captcha = 'captcha';
14350: }
14351: } elsif ($context eq 'login') {
14352: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14353: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14354: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14355: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
14356: if ($privkey && $pubkey) {
14357: $captcha = 'recaptcha';
14358: } else {
14359: $captcha = 'original';
14360: }
14361: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14362: $captcha = 'original';
14363: }
14364: }
14365: return ($captcha,$pubkey,$privkey);
14366: }
14367:
14368: sub create_captcha {
14369: my %captcha_params = &captcha_settings();
14370: my ($output,$maxtries,$tries) = ('',10,0);
14371: while ($tries < $maxtries) {
14372: $tries ++;
14373: my $captcha = Authen::Captcha->new (
14374: output_folder => $captcha_params{'output_dir'},
14375: data_folder => $captcha_params{'db_dir'},
14376: );
14377: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14378:
14379: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14380: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14381: &mt('Type in the letters/numbers shown below').' '.
14382: '<input type="text" size="5" name="code" value="" /><br />'.
14383: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
14384: last;
14385: }
14386: }
14387: return $output;
14388: }
14389:
14390: sub captcha_settings {
14391: my %captcha_params = (
14392: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14393: www_output_dir => "/captchaspool",
14394: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14395: numchars => '5',
14396: );
14397: return %captcha_params;
14398: }
14399:
14400: sub check_captcha {
14401: my ($captcha_chk,$captcha_error);
14402: my $code = $env{'form.code'};
14403: my $md5sum = $env{'form.crypt'};
14404: my %captcha_params = &captcha_settings();
14405: my $captcha = Authen::Captcha->new(
14406: output_folder => $captcha_params{'output_dir'},
14407: data_folder => $captcha_params{'db_dir'},
14408: );
1.1075.2.26 raeburn 14409: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 14410: my %captcha_hash = (
14411: 0 => 'Code not checked (file error)',
14412: -1 => 'Failed: code expired',
14413: -2 => 'Failed: invalid code (not in database)',
14414: -3 => 'Failed: invalid code (code does not match crypt)',
14415: );
14416: if ($captcha_chk != 1) {
14417: $captcha_error = $captcha_hash{$captcha_chk}
14418: }
14419: return ($captcha_chk,$captcha_error);
14420: }
14421:
14422: sub create_recaptcha {
14423: my ($pubkey) = @_;
14424: my $captcha = Captcha::reCAPTCHA->new;
14425: return $captcha->get_options_setter({theme => 'white'})."\n".
14426: $captcha->get_html($pubkey).
14427: &mt('If either word is hard to read, [_1] will replace them.',
14428: '<image src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
14429: '<br /><br />';
14430: }
14431:
14432: sub check_recaptcha {
14433: my ($privkey) = @_;
14434: my $captcha_chk;
14435: my $captcha = Captcha::reCAPTCHA->new;
14436: my $captcha_result =
14437: $captcha->check_answer(
14438: $privkey,
14439: $ENV{'REMOTE_ADDR'},
14440: $env{'form.recaptcha_challenge_field'},
14441: $env{'form.recaptcha_response_field'},
14442: );
14443: if ($captcha_result->{is_valid}) {
14444: $captcha_chk = 1;
14445: }
14446: return $captcha_chk;
14447: }
14448:
1.41 ng 14449: =pod
14450:
14451: =back
14452:
1.112 bowersj2 14453: =cut
1.41 ng 14454:
1.112 bowersj2 14455: 1;
14456: __END__;
1.41 ng 14457:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>