Annotation of loncom/interface/loncommon.pm, revision 1.1139
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1139 ! raeburn 4: # $Id: loncommon.pm,v 1.1138 2013/07/11 18:24:31 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 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.1091 foxr 75: use Text::Aspell;
1.1094 raeburn 76: use Authen::Captcha;
77: use Captcha::reCAPTCHA;
1.117 www 78:
1.517 raeburn 79: # ---------------------------------------------- Designs
80: use vars qw(%defaultdesign);
81:
1.22 www 82: my $readit;
83:
1.517 raeburn 84:
1.157 matthew 85: ##
86: ## Global Variables
87: ##
1.46 matthew 88:
1.643 foxr 89:
90: # ----------------------------------------------- SSI with retries:
91: #
92:
93: =pod
94:
1.648 raeburn 95: =head1 Server Side include with retries:
1.643 foxr 96:
97: =over 4
98:
1.648 raeburn 99: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 100:
101: Performs an ssi with some number of retries. Retries continue either
102: until the result is ok or until the retry count supplied by the
103: caller is exhausted.
104:
105: Inputs:
1.648 raeburn 106:
107: =over 4
108:
1.643 foxr 109: resource - Identifies the resource to insert.
1.648 raeburn 110:
1.643 foxr 111: retries - Count of the number of retries allowed.
1.648 raeburn 112:
1.643 foxr 113: form - Hash that identifies the rendering options.
114:
1.648 raeburn 115: =back
116:
117: Returns:
118:
119: =over 4
120:
1.643 foxr 121: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 122:
1.643 foxr 123: response - The response from the last attempt (which may or may not have been successful.
124:
1.648 raeburn 125: =back
126:
127: =back
128:
1.643 foxr 129: =cut
130:
131: sub ssi_with_retries {
132: my ($resource, $retries, %form) = @_;
133:
134:
135: my $ok = 0; # True if we got a good response.
136: my $content;
137: my $response;
138:
139: # Try to get the ssi done. within the retries count:
140:
141: do {
142: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
143: $ok = $response->is_success;
1.650 www 144: if (!$ok) {
145: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
146: }
1.643 foxr 147: $retries--;
148: } while (!$ok && ($retries > 0));
149:
150: if (!$ok) {
151: $content = ''; # On error return an empty content.
152: }
153: return ($content, $response);
154:
155: }
156:
157:
158:
1.20 www 159: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 160: my %language;
1.124 www 161: my %supported_language;
1.1088 foxr 162: my %supported_codes;
1.1048 foxr 163: my %latex_language; # For choosing hyphenation in <transl..>
164: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 165: my %cprtag;
1.192 taceyjo1 166: my %scprtag;
1.351 www 167: my %fe; my %fd; my %fm;
1.41 ng 168: my %category_extensions;
1.12 harris41 169:
1.46 matthew 170: # ---------------------------------------------- Thesaurus variables
1.144 matthew 171: #
172: # %Keywords:
173: # A hash used by &keyword to determine if a word is considered a keyword.
174: # $thesaurus_db_file
175: # Scalar containing the full path to the thesaurus database.
1.46 matthew 176:
177: my %Keywords;
178: my $thesaurus_db_file;
179:
1.144 matthew 180: #
181: # Initialize values from language.tab, copyright.tab, filetypes.tab,
182: # thesaurus.tab, and filecategories.tab.
183: #
1.18 www 184: BEGIN {
1.46 matthew 185: # Variable initialization
186: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
187: #
1.22 www 188: unless ($readit) {
1.12 harris41 189: # ------------------------------------------------------------------- languages
190: {
1.158 raeburn 191: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
192: '/language.tab';
193: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 194: while (my $line = <$fh>) {
195: next if ($line=~/^\#/);
196: chomp($line);
1.1088 foxr 197: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 198: $language{$key}=$val.' - '.$enc;
199: if ($sup) {
200: $supported_language{$key}=$sup;
1.1088 foxr 201: $supported_codes{$key} = $code;
1.158 raeburn 202: }
1.1048 foxr 203: if ($latex) {
204: $latex_language_bykey{$key} = $latex;
1.1088 foxr 205: $latex_language{$code} = $latex;
1.1048 foxr 206: }
1.158 raeburn 207: }
208: close($fh);
209: }
1.12 harris41 210: }
211: # ------------------------------------------------------------------ copyrights
212: {
1.158 raeburn 213: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
214: '/copyright.tab';
215: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 216: while (my $line = <$fh>) {
217: next if ($line=~/^\#/);
218: chomp($line);
219: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 220: $cprtag{$key}=$val;
221: }
222: close($fh);
223: }
1.12 harris41 224: }
1.351 www 225: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 226: {
227: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
228: '/source_copyright.tab';
229: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 230: while (my $line = <$fh>) {
231: next if ($line =~ /^\#/);
232: chomp($line);
233: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 234: $scprtag{$key}=$val;
235: }
236: close($fh);
237: }
238: }
1.63 www 239:
1.517 raeburn 240: # -------------------------------------------------------------- default domain designs
1.63 www 241: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 242: my $designfile = $designdir.'/default.tab';
243: if ( open (my $fh,"<$designfile") ) {
244: while (my $line = <$fh>) {
245: next if ($line =~ /^\#/);
246: chomp($line);
247: my ($key,$val)=(split(/\=/,$line));
248: if ($val) { $defaultdesign{$key}=$val; }
249: }
250: close($fh);
1.63 www 251: }
252:
1.15 harris41 253: # ------------------------------------------------------------- file categories
254: {
1.158 raeburn 255: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
256: '/filecategories.tab';
257: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 258: while (my $line = <$fh>) {
259: next if ($line =~ /^\#/);
260: chomp($line);
261: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 262: push @{$category_extensions{lc($category)}},$extension;
263: }
264: close($fh);
265: }
266:
1.15 harris41 267: }
1.12 harris41 268: # ------------------------------------------------------------------ file types
269: {
1.158 raeburn 270: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
271: '/filetypes.tab';
272: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 273: while (my $line = <$fh>) {
274: next if ($line =~ /^\#/);
275: chomp($line);
276: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 277: if ($descr ne '') {
278: $fe{$ending}=lc($emb);
279: $fd{$ending}=$descr;
1.351 www 280: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 281: }
282: }
283: close($fh);
284: }
1.12 harris41 285: }
1.22 www 286: &Apache::lonnet::logthis(
1.705 tempelho 287: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 288: $readit=1;
1.46 matthew 289: } # end of unless($readit)
1.32 matthew 290:
291: }
1.112 bowersj2 292:
1.42 matthew 293: ###############################################################
294: ## HTML and Javascript Helper Functions ##
295: ###############################################################
296:
297: =pod
298:
1.112 bowersj2 299: =head1 HTML and Javascript Functions
1.42 matthew 300:
1.112 bowersj2 301: =over 4
302:
1.648 raeburn 303: =item * &browser_and_searcher_javascript()
1.112 bowersj2 304:
305: X<browsing, javascript>X<searching, javascript>Returns a string
306: containing javascript with two functions, C<openbrowser> and
307: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
308: tags.
1.42 matthew 309:
1.648 raeburn 310: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 311:
312: inputs: formname, elementname, only, omit
313:
314: formname and elementname indicate the name of the html form and name of
315: the element that the results of the browsing selection are to be placed in.
316:
317: Specifying 'only' will restrict the browser to displaying only files
1.185 www 318: with the given extension. Can be a comma separated list.
1.42 matthew 319:
320: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 321: with the given extension. Can be a comma separated list.
1.42 matthew 322:
1.648 raeburn 323: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 324:
325: Inputs: formname, elementname
326:
327: formname and elementname specify the name of the html form and the name
328: of the element the selection from the search results will be placed in.
1.542 raeburn 329:
1.42 matthew 330: =cut
331:
332: sub browser_and_searcher_javascript {
1.199 albertel 333: my ($mode)=@_;
334: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 335: my $resurl=&escape_single(&lastresurl());
1.42 matthew 336: return <<END;
1.219 albertel 337: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 338: var editbrowser = null;
1.135 albertel 339: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 340: var url = '$resurl/?';
1.42 matthew 341: if (editbrowser == null) {
342: url += 'launch=1&';
343: }
344: url += 'catalogmode=interactive&';
1.199 albertel 345: url += 'mode=$mode&';
1.611 albertel 346: url += 'inhibitmenu=yes&';
1.42 matthew 347: url += 'form=' + formname + '&';
348: if (only != null) {
349: url += 'only=' + only + '&';
1.217 albertel 350: } else {
351: url += 'only=&';
352: }
1.42 matthew 353: if (omit != null) {
354: url += 'omit=' + omit + '&';
1.217 albertel 355: } else {
356: url += 'omit=&';
357: }
1.135 albertel 358: if (titleelement != null) {
359: url += 'titleelement=' + titleelement + '&';
1.217 albertel 360: } else {
361: url += 'titleelement=&';
362: }
1.42 matthew 363: url += 'element=' + elementname + '';
364: var title = 'Browser';
1.435 albertel 365: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 366: options += ',width=700,height=600';
367: editbrowser = open(url,title,options,'1');
368: editbrowser.focus();
369: }
370: var editsearcher;
1.135 albertel 371: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 372: var url = '/adm/searchcat?';
373: if (editsearcher == null) {
374: url += 'launch=1&';
375: }
376: url += 'catalogmode=interactive&';
1.199 albertel 377: url += 'mode=$mode&';
1.42 matthew 378: url += 'form=' + formname + '&';
1.135 albertel 379: if (titleelement != null) {
380: url += 'titleelement=' + titleelement + '&';
1.217 albertel 381: } else {
382: url += 'titleelement=&';
383: }
1.42 matthew 384: url += 'element=' + elementname + '';
385: var title = 'Search';
1.435 albertel 386: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 387: options += ',width=700,height=600';
388: editsearcher = open(url,title,options,'1');
389: editsearcher.focus();
390: }
1.219 albertel 391: // END LON-CAPA Internal -->
1.42 matthew 392: END
1.170 www 393: }
394:
395: sub lastresurl {
1.258 albertel 396: if ($env{'environment.lastresurl'}) {
397: return $env{'environment.lastresurl'}
1.170 www 398: } else {
399: return '/res';
400: }
401: }
402:
403: sub storeresurl {
404: my $resurl=&Apache::lonnet::clutter(shift);
405: unless ($resurl=~/^\/res/) { return 0; }
406: $resurl=~s/\/$//;
407: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 408: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 409: return 1;
1.42 matthew 410: }
411:
1.74 www 412: sub studentbrowser_javascript {
1.111 www 413: unless (
1.258 albertel 414: (($env{'request.course.id'}) &&
1.302 albertel 415: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
416: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
417: '/'.$env{'request.course.sec'})
418: ))
1.258 albertel 419: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 420: ) { return ''; }
1.74 www 421: return (<<'ENDSTDBRW');
1.776 bisitz 422: <script type="text/javascript" language="Javascript">
1.824 bisitz 423: // <![CDATA[
1.74 www 424: var stdeditbrowser;
1.999 www 425: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 426: var url = '/adm/pickstudent?';
427: var filter;
1.558 albertel 428: if (!ignorefilter) {
429: eval('filter=document.'+formname+'.'+uname+'.value;');
430: }
1.74 www 431: if (filter != null) {
432: if (filter != '') {
433: url += 'filter='+filter+'&';
434: }
435: }
436: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 437: '&udomelement='+udom+
438: '&clicker='+clicker;
1.111 www 439: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 440: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 441: var title = 'Student_Browser';
1.74 www 442: var options = 'scrollbars=1,resizable=1,menubar=0';
443: options += ',width=700,height=600';
444: stdeditbrowser = open(url,title,options,'1');
445: stdeditbrowser.focus();
446: }
1.824 bisitz 447: // ]]>
1.74 www 448: </script>
449: ENDSTDBRW
450: }
1.42 matthew 451:
1.1003 www 452: sub resourcebrowser_javascript {
453: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 454: return (<<'ENDRESBRW');
1.1003 www 455: <script type="text/javascript" language="Javascript">
456: // <![CDATA[
457: var reseditbrowser;
1.1004 www 458: function openresbrowser(formname,reslink) {
1.1005 www 459: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 460: var title = 'Resource_Browser';
461: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 462: options += ',width=700,height=500';
1.1004 www 463: reseditbrowser = open(url,title,options,'1');
464: reseditbrowser.focus();
1.1003 www 465: }
466: // ]]>
467: </script>
1.1004 www 468: ENDRESBRW
1.1003 www 469: }
470:
1.74 www 471: sub selectstudent_link {
1.999 www 472: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
473: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
474: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
475: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 476: if ($env{'request.course.id'}) {
1.302 albertel 477: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
478: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
479: '/'.$env{'request.course.sec'})) {
1.111 www 480: return '';
481: }
1.999 www 482: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 483: if ($courseadvonly) {
484: $callargs .= ",'',1,1";
485: }
486: return '<span class="LC_nobreak">'.
487: '<a href="javascript:openstdbrowser('.$callargs.');">'.
488: &mt('Select User').'</a></span>';
1.74 www 489: }
1.258 albertel 490: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 491: $callargs .= ",'',1";
1.793 raeburn 492: return '<span class="LC_nobreak">'.
493: '<a href="javascript:openstdbrowser('.$callargs.');">'.
494: &mt('Select User').'</a></span>';
1.111 www 495: }
496: return '';
1.91 www 497: }
498:
1.1004 www 499: sub selectresource_link {
500: my ($form,$reslink,$arg)=@_;
501:
502: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
503: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
504: unless ($env{'request.course.id'}) { return $arg; }
505: return '<span class="LC_nobreak">'.
506: '<a href="javascript:openresbrowser('.$callargs.');">'.
507: $arg.'</a></span>';
508: }
509:
510:
511:
1.653 raeburn 512: sub authorbrowser_javascript {
513: return <<"ENDAUTHORBRW";
1.776 bisitz 514: <script type="text/javascript" language="JavaScript">
1.824 bisitz 515: // <![CDATA[
1.653 raeburn 516: var stdeditbrowser;
517:
518: function openauthorbrowser(formname,udom) {
519: var url = '/adm/pickauthor?';
520: url += 'form='+formname+'&roledom='+udom;
521: var title = 'Author_Browser';
522: var options = 'scrollbars=1,resizable=1,menubar=0';
523: options += ',width=700,height=600';
524: stdeditbrowser = open(url,title,options,'1');
525: stdeditbrowser.focus();
526: }
527:
1.824 bisitz 528: // ]]>
1.653 raeburn 529: </script>
530: ENDAUTHORBRW
531: }
532:
1.91 www 533: sub coursebrowser_javascript {
1.1116 raeburn 534: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
535: $credits_element) = @_;
1.932 raeburn 536: my $wintitle = 'Course_Browser';
1.931 raeburn 537: if ($crstype eq 'Community') {
1.932 raeburn 538: $wintitle = 'Community_Browser';
1.909 raeburn 539: }
1.876 raeburn 540: my $id_functions = &javascript_index_functions();
541: my $output = '
1.776 bisitz 542: <script type="text/javascript" language="JavaScript">
1.824 bisitz 543: // <![CDATA[
1.468 raeburn 544: var stdeditbrowser;'."\n";
1.876 raeburn 545:
546: $output .= <<"ENDSTDBRW";
1.909 raeburn 547: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 548: var url = '/adm/pickcourse?';
1.895 raeburn 549: var formid = getFormIdByName(formname);
1.876 raeburn 550: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 551: if (domainfilter != null) {
552: if (domainfilter != '') {
553: url += 'domainfilter='+domainfilter+'&';
554: }
555: }
1.91 www 556: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 557: '&cdomelement='+udom+
558: '&cnameelement='+desc;
1.468 raeburn 559: if (extra_element !=null && extra_element != '') {
1.594 raeburn 560: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 561: url += '&roleelement='+extra_element;
562: if (domainfilter == null || domainfilter == '') {
563: url += '&domainfilter='+extra_element;
564: }
1.234 raeburn 565: }
1.468 raeburn 566: else {
567: if (formname == 'portform') {
568: url += '&setroles='+extra_element;
1.800 raeburn 569: } else {
570: if (formname == 'rules') {
571: url += '&fixeddom='+extra_element;
572: }
1.468 raeburn 573: }
574: }
1.230 raeburn 575: }
1.909 raeburn 576: if (type != null && type != '') {
577: url += '&type='+type;
578: }
579: if (type_elem != null && type_elem != '') {
580: url += '&typeelement='+type_elem;
581: }
1.872 raeburn 582: if (formname == 'ccrs') {
583: var ownername = document.forms[formid].ccuname.value;
584: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
585: url += '&cloner='+ownername+':'+ownerdom;
586: }
1.293 raeburn 587: if (multflag !=null && multflag != '') {
588: url += '&multiple='+multflag;
589: }
1.909 raeburn 590: var title = '$wintitle';
1.91 www 591: var options = 'scrollbars=1,resizable=1,menubar=0';
592: options += ',width=700,height=600';
593: stdeditbrowser = open(url,title,options,'1');
594: stdeditbrowser.focus();
595: }
1.876 raeburn 596: $id_functions
597: ENDSTDBRW
1.1116 raeburn 598: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
599: $output .= &setsec_javascript($sec_element,$formname,$role_element,
600: $credits_element);
1.876 raeburn 601: }
602: $output .= '
603: // ]]>
604: </script>';
605: return $output;
606: }
607:
608: sub javascript_index_functions {
609: return <<"ENDJS";
610:
611: function getFormIdByName(formname) {
612: for (var i=0;i<document.forms.length;i++) {
613: if (document.forms[i].name == formname) {
614: return i;
615: }
616: }
617: return -1;
618: }
619:
620: function getIndexByName(formid,item) {
621: for (var i=0;i<document.forms[formid].elements.length;i++) {
622: if (document.forms[formid].elements[i].name == item) {
623: return i;
624: }
625: }
626: return -1;
627: }
1.468 raeburn 628:
1.876 raeburn 629: function getDomainFromSelectbox(formname,udom) {
630: var userdom;
631: var formid = getFormIdByName(formname);
632: if (formid > -1) {
633: var domid = getIndexByName(formid,udom);
634: if (domid > -1) {
635: if (document.forms[formid].elements[domid].type == 'select-one') {
636: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
637: }
638: if (document.forms[formid].elements[domid].type == 'hidden') {
639: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 640: }
641: }
642: }
1.876 raeburn 643: return userdom;
644: }
645:
646: ENDJS
1.468 raeburn 647:
1.876 raeburn 648: }
649:
1.1017 raeburn 650: sub javascript_array_indexof {
1.1018 raeburn 651: return <<ENDJS;
1.1017 raeburn 652: <script type="text/javascript" language="JavaScript">
653: // <![CDATA[
654:
655: if (!Array.prototype.indexOf) {
656: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
657: "use strict";
658: if (this === void 0 || this === null) {
659: throw new TypeError();
660: }
661: var t = Object(this);
662: var len = t.length >>> 0;
663: if (len === 0) {
664: return -1;
665: }
666: var n = 0;
667: if (arguments.length > 0) {
668: n = Number(arguments[1]);
1.1088 foxr 669: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 670: n = 0;
671: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
672: n = (n > 0 || -1) * Math.floor(Math.abs(n));
673: }
674: }
675: if (n >= len) {
676: return -1;
677: }
678: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
679: for (; k < len; k++) {
680: if (k in t && t[k] === searchElement) {
681: return k;
682: }
683: }
684: return -1;
685: }
686: }
687:
688: // ]]>
689: </script>
690:
691: ENDJS
692:
693: }
694:
1.876 raeburn 695: sub userbrowser_javascript {
696: my $id_functions = &javascript_index_functions();
697: return <<"ENDUSERBRW";
698:
1.888 raeburn 699: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 700: var url = '/adm/pickuser?';
701: var userdom = getDomainFromSelectbox(formname,udom);
702: if (userdom != null) {
703: if (userdom != '') {
704: url += 'srchdom='+userdom+'&';
705: }
706: }
707: url += 'form=' + formname + '&unameelement='+uname+
708: '&udomelement='+udom+
709: '&ulastelement='+ulast+
710: '&ufirstelement='+ufirst+
711: '&uemailelement='+uemail+
1.881 raeburn 712: '&hideudomelement='+hideudom+
713: '&coursedom='+crsdom;
1.888 raeburn 714: if ((caller != null) && (caller != undefined)) {
715: url += '&caller='+caller;
716: }
1.876 raeburn 717: var title = 'User_Browser';
718: var options = 'scrollbars=1,resizable=1,menubar=0';
719: options += ',width=700,height=600';
720: var stdeditbrowser = open(url,title,options,'1');
721: stdeditbrowser.focus();
722: }
723:
1.888 raeburn 724: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 725: var formid = getFormIdByName(formname);
726: if (formid > -1) {
1.888 raeburn 727: var unameid = getIndexByName(formid,uname);
1.876 raeburn 728: var domid = getIndexByName(formid,udom);
729: var hidedomid = getIndexByName(formid,origdom);
730: if (hidedomid > -1) {
731: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 732: var unameval = document.forms[formid].elements[unameid].value;
733: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
734: if (domid > -1) {
735: var slct = document.forms[formid].elements[domid];
736: if (slct.type == 'select-one') {
737: var i;
738: for (i=0;i<slct.length;i++) {
739: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
740: }
741: }
742: if (slct.type == 'hidden') {
743: slct.value = fixeddom;
1.876 raeburn 744: }
745: }
1.468 raeburn 746: }
747: }
748: }
1.876 raeburn 749: return;
750: }
751:
752: $id_functions
753: ENDUSERBRW
1.468 raeburn 754: }
755:
756: sub setsec_javascript {
1.1116 raeburn 757: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 758: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
759: $communityrolestr);
760: if ($role_element ne '') {
761: my @allroles = ('st','ta','ep','in','ad');
762: foreach my $crstype ('Course','Community') {
763: if ($crstype eq 'Community') {
764: foreach my $role (@allroles) {
765: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
766: }
767: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
768: } else {
769: foreach my $role (@allroles) {
770: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
771: }
772: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
773: }
774: }
775: $rolestr = '"'.join('","',@allroles).'"';
776: $courserolestr = '"'.join('","',@courserolenames).'"';
777: $communityrolestr = '"'.join('","',@communityrolenames).'"';
778: }
1.468 raeburn 779: my $setsections = qq|
780: function setSect(sectionlist) {
1.629 raeburn 781: var sectionsArray = new Array();
782: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
783: sectionsArray = sectionlist.split(",");
784: }
1.468 raeburn 785: var numSections = sectionsArray.length;
786: document.$formname.$sec_element.length = 0;
787: if (numSections == 0) {
788: document.$formname.$sec_element.multiple=false;
789: document.$formname.$sec_element.size=1;
790: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
791: } else {
792: if (numSections == 1) {
793: document.$formname.$sec_element.multiple=false;
794: document.$formname.$sec_element.size=1;
795: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
796: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
797: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
798: } else {
799: for (var i=0; i<numSections; i++) {
800: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
801: }
802: document.$formname.$sec_element.multiple=true
803: if (numSections < 3) {
804: document.$formname.$sec_element.size=numSections;
805: } else {
806: document.$formname.$sec_element.size=3;
807: }
808: document.$formname.$sec_element.options[0].selected = false
809: }
810: }
1.91 www 811: }
1.905 raeburn 812:
813: function setRole(crstype) {
1.468 raeburn 814: |;
1.905 raeburn 815: if ($role_element eq '') {
816: $setsections .= ' return;
817: }
818: ';
819: } else {
820: $setsections .= qq|
821: var elementLength = document.$formname.$role_element.length;
822: var allroles = Array($rolestr);
823: var courserolenames = Array($courserolestr);
824: var communityrolenames = Array($communityrolestr);
825: if (elementLength != undefined) {
826: if (document.$formname.$role_element.options[5].value == 'cc') {
827: if (crstype == 'Course') {
828: return;
829: } else {
830: allroles[5] = 'co';
831: for (var i=0; i<6; i++) {
832: document.$formname.$role_element.options[i].value = allroles[i];
833: document.$formname.$role_element.options[i].text = communityrolenames[i];
834: }
835: }
836: } else {
837: if (crstype == 'Community') {
838: return;
839: } else {
840: allroles[5] = 'cc';
841: for (var i=0; i<6; i++) {
842: document.$formname.$role_element.options[i].value = allroles[i];
843: document.$formname.$role_element.options[i].text = courserolenames[i];
844: }
845: }
846: }
847: }
848: return;
849: }
850: |;
851: }
1.1116 raeburn 852: if ($credits_element) {
853: $setsections .= qq|
854: function setCredits(defaultcredits) {
855: document.$formname.$credits_element.value = defaultcredits;
856: return;
857: }
858: |;
859: }
1.468 raeburn 860: return $setsections;
861: }
862:
1.91 www 863: sub selectcourse_link {
1.909 raeburn 864: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
865: $typeelement) = @_;
866: my $type = $selecttype;
1.871 raeburn 867: my $linktext = &mt('Select Course');
868: if ($selecttype eq 'Community') {
1.909 raeburn 869: $linktext = &mt('Select Community');
1.906 raeburn 870: } elsif ($selecttype eq 'Course/Community') {
871: $linktext = &mt('Select Course/Community');
1.909 raeburn 872: $type = '';
1.1019 raeburn 873: } elsif ($selecttype eq 'Select') {
874: $linktext = &mt('Select');
875: $type = '';
1.871 raeburn 876: }
1.787 bisitz 877: return '<span class="LC_nobreak">'
878: ."<a href='"
879: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
880: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 881: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 882: ."'>".$linktext.'</a>'
1.787 bisitz 883: .'</span>';
1.74 www 884: }
1.42 matthew 885:
1.653 raeburn 886: sub selectauthor_link {
887: my ($form,$udom)=@_;
888: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
889: &mt('Select Author').'</a>';
890: }
891:
1.876 raeburn 892: sub selectuser_link {
1.881 raeburn 893: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 894: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 895: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 896: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 897: ');">'.$linktext.'</a>';
1.876 raeburn 898: }
899:
1.273 raeburn 900: sub check_uncheck_jscript {
901: my $jscript = <<"ENDSCRT";
902: function checkAll(field) {
903: if (field.length > 0) {
904: for (i = 0; i < field.length; i++) {
1.1093 raeburn 905: if (!field[i].disabled) {
906: field[i].checked = true;
907: }
1.273 raeburn 908: }
909: } else {
1.1093 raeburn 910: if (!field.disabled) {
911: field.checked = true;
912: }
1.273 raeburn 913: }
914: }
915:
916: function uncheckAll(field) {
917: if (field.length > 0) {
918: for (i = 0; i < field.length; i++) {
919: field[i].checked = false ;
1.543 albertel 920: }
921: } else {
1.273 raeburn 922: field.checked = false ;
923: }
924: }
925: ENDSCRT
926: return $jscript;
927: }
928:
1.656 www 929: sub select_timezone {
1.659 raeburn 930: my ($name,$selected,$onchange,$includeempty)=@_;
931: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
932: if ($includeempty) {
933: $output .= '<option value=""';
934: if (($selected eq '') || ($selected eq 'local')) {
935: $output .= ' selected="selected" ';
936: }
937: $output .= '> </option>';
938: }
1.657 raeburn 939: my @timezones = DateTime::TimeZone->all_names;
940: foreach my $tzone (@timezones) {
941: $output.= '<option value="'.$tzone.'"';
942: if ($tzone eq $selected) {
943: $output.=' selected="selected"';
944: }
945: $output.=">$tzone</option>\n";
1.656 www 946: }
947: $output.="</select>";
948: return $output;
949: }
1.273 raeburn 950:
1.687 raeburn 951: sub select_datelocale {
952: my ($name,$selected,$onchange,$includeempty)=@_;
953: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
954: if ($includeempty) {
955: $output .= '<option value=""';
956: if ($selected eq '') {
957: $output .= ' selected="selected" ';
958: }
959: $output .= '> </option>';
960: }
961: my (@possibles,%locale_names);
962: my @locales = DateTime::Locale::Catalog::Locales;
963: foreach my $locale (@locales) {
964: if (ref($locale) eq 'HASH') {
965: my $id = $locale->{'id'};
966: if ($id ne '') {
967: my $en_terr = $locale->{'en_territory'};
968: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 969: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 970: if (grep(/^en$/,@languages) || !@languages) {
971: if ($en_terr ne '') {
972: $locale_names{$id} = '('.$en_terr.')';
973: } elsif ($native_terr ne '') {
974: $locale_names{$id} = $native_terr;
975: }
976: } else {
977: if ($native_terr ne '') {
978: $locale_names{$id} = $native_terr.' ';
979: } elsif ($en_terr ne '') {
980: $locale_names{$id} = '('.$en_terr.')';
981: }
982: }
983: push (@possibles,$id);
984: }
985: }
986: }
987: foreach my $item (sort(@possibles)) {
988: $output.= '<option value="'.$item.'"';
989: if ($item eq $selected) {
990: $output.=' selected="selected"';
991: }
992: $output.=">$item";
993: if ($locale_names{$item} ne '') {
994: $output.=" $locale_names{$item}</option>\n";
995: }
996: $output.="</option>\n";
997: }
998: $output.="</select>";
999: return $output;
1000: }
1001:
1.792 raeburn 1002: sub select_language {
1003: my ($name,$selected,$includeempty) = @_;
1004: my %langchoices;
1005: if ($includeempty) {
1.1117 raeburn 1006: %langchoices = ('' => 'No language preference');
1.792 raeburn 1007: }
1008: foreach my $id (&languageids()) {
1009: my $code = &supportedlanguagecode($id);
1010: if ($code) {
1011: $langchoices{$code} = &plainlanguagedescription($id);
1012: }
1013: }
1.1117 raeburn 1014: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1015: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1016: }
1017:
1.42 matthew 1018: =pod
1.36 matthew 1019:
1.1088 foxr 1020:
1021: =item * &list_languages()
1022:
1023: Returns an array reference that is suitable for use in language prompters.
1024: Each array element is itself a two element array. The first element
1025: is the language code. The second element a descsriptiuon of the
1026: language itself. This is suitable for use in e.g.
1027: &Apache::edit::select_arg (once dereferenced that is).
1028:
1029: =cut
1030:
1031: sub list_languages {
1032: my @lang_choices;
1033:
1034: foreach my $id (&languageids()) {
1035: my $code = &supportedlanguagecode($id);
1036: if ($code) {
1037: my $selector = $supported_codes{$id};
1038: my $description = &plainlanguagedescription($id);
1039: push (@lang_choices, [$selector, $description]);
1040: }
1041: }
1042: return \@lang_choices;
1043: }
1044:
1045: =pod
1046:
1.648 raeburn 1047: =item * &linked_select_forms(...)
1.36 matthew 1048:
1049: linked_select_forms returns a string containing a <script></script> block
1050: and html for two <select> menus. The select menus will be linked in that
1051: changing the value of the first menu will result in new values being placed
1052: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1053: order unless a defined order is provided.
1.36 matthew 1054:
1055: linked_select_forms takes the following ordered inputs:
1056:
1057: =over 4
1058:
1.112 bowersj2 1059: =item * $formname, the name of the <form> tag
1.36 matthew 1060:
1.112 bowersj2 1061: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1062:
1.112 bowersj2 1063: =item * $firstdefault, the default value for the first menu
1.36 matthew 1064:
1.112 bowersj2 1065: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1066:
1.112 bowersj2 1067: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1068:
1.112 bowersj2 1069: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1070:
1.609 raeburn 1071: =item * $menuorder, the order of values in the first menu
1072:
1.1115 raeburn 1073: =item * $onchangefirst, additional javascript call to execute for an onchange
1074: event for the first <select> tag
1075:
1076: =item * $onchangesecond, additional javascript call to execute for an onchange
1077: event for the second <select> tag
1078:
1.41 ng 1079: =back
1080:
1.36 matthew 1081: Below is an example of such a hash. Only the 'text', 'default', and
1082: 'select2' keys must appear as stated. keys(%menu) are the possible
1083: values for the first select menu. The text that coincides with the
1.41 ng 1084: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1085: and text for the second menu are given in the hash pointed to by
1086: $menu{$choice1}->{'select2'}.
1087:
1.112 bowersj2 1088: my %menu = ( A1 => { text =>"Choice A1" ,
1089: default => "B3",
1090: select2 => {
1091: B1 => "Choice B1",
1092: B2 => "Choice B2",
1093: B3 => "Choice B3",
1094: B4 => "Choice B4"
1.609 raeburn 1095: },
1096: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1097: },
1098: A2 => { text =>"Choice A2" ,
1099: default => "C2",
1100: select2 => {
1101: C1 => "Choice C1",
1102: C2 => "Choice C2",
1103: C3 => "Choice C3"
1.609 raeburn 1104: },
1105: order => ['C2','C1','C3'],
1.112 bowersj2 1106: },
1107: A3 => { text =>"Choice A3" ,
1108: default => "D6",
1109: select2 => {
1110: D1 => "Choice D1",
1111: D2 => "Choice D2",
1112: D3 => "Choice D3",
1113: D4 => "Choice D4",
1114: D5 => "Choice D5",
1115: D6 => "Choice D6",
1116: D7 => "Choice D7"
1.609 raeburn 1117: },
1118: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1119: }
1120: );
1.36 matthew 1121:
1122: =cut
1123:
1124: sub linked_select_forms {
1125: my ($formname,
1126: $middletext,
1127: $firstdefault,
1128: $firstselectname,
1129: $secondselectname,
1.609 raeburn 1130: $hashref,
1131: $menuorder,
1.1115 raeburn 1132: $onchangefirst,
1133: $onchangesecond
1.36 matthew 1134: ) = @_;
1135: my $second = "document.$formname.$secondselectname";
1136: my $first = "document.$formname.$firstselectname";
1137: # output the javascript to do the changing
1138: my $result = '';
1.776 bisitz 1139: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1140: $result.="// <![CDATA[\n";
1.36 matthew 1141: $result.="var select2data = new Object();\n";
1142: $" = '","';
1143: my $debug = '';
1144: foreach my $s1 (sort(keys(%$hashref))) {
1145: $result.="select2data.d_$s1 = new Object();\n";
1146: $result.="select2data.d_$s1.def = new String('".
1147: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1148: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1149: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1150: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1151: @s2values = @{$hashref->{$s1}->{'order'}};
1152: }
1.36 matthew 1153: $result.="\"@s2values\");\n";
1154: $result.="select2data.d_$s1.texts = new Array(";
1155: my @s2texts;
1156: foreach my $value (@s2values) {
1157: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1158: }
1159: $result.="\"@s2texts\");\n";
1160: }
1161: $"=' ';
1162: $result.= <<"END";
1163:
1164: function select1_changed() {
1165: // Determine new choice
1166: var newvalue = "d_" + $first.value;
1167: // update select2
1168: var values = select2data[newvalue].values;
1169: var texts = select2data[newvalue].texts;
1170: var select2def = select2data[newvalue].def;
1171: var i;
1172: // out with the old
1173: for (i = 0; i < $second.options.length; i++) {
1174: $second.options[i] = null;
1175: }
1176: // in with the nuclear
1177: for (i=0;i<values.length; i++) {
1178: $second.options[i] = new Option(values[i]);
1.143 matthew 1179: $second.options[i].value = values[i];
1.36 matthew 1180: $second.options[i].text = texts[i];
1181: if (values[i] == select2def) {
1182: $second.options[i].selected = true;
1183: }
1184: }
1185: }
1.824 bisitz 1186: // ]]>
1.36 matthew 1187: </script>
1188: END
1189: # output the initial values for the selection lists
1.1115 raeburn 1190: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1191: my @order = sort(keys(%{$hashref}));
1192: if (ref($menuorder) eq 'ARRAY') {
1193: @order = @{$menuorder};
1194: }
1195: foreach my $value (@order) {
1.36 matthew 1196: $result.=" <option value=\"$value\" ";
1.253 albertel 1197: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1198: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1199: }
1200: $result .= "</select>\n";
1201: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1202: $result .= $middletext;
1.1115 raeburn 1203: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1204: if ($onchangesecond) {
1205: $result .= ' onchange="'.$onchangesecond.'"';
1206: }
1207: $result .= ">\n";
1.36 matthew 1208: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1209:
1210: my @secondorder = sort(keys(%select2));
1211: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1212: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1213: }
1214: foreach my $value (@secondorder) {
1.36 matthew 1215: $result.=" <option value=\"$value\" ";
1.253 albertel 1216: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1217: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1218: }
1219: $result .= "</select>\n";
1220: # return $debug;
1221: return $result;
1222: } # end of sub linked_select_forms {
1223:
1.45 matthew 1224: =pod
1.44 bowersj2 1225:
1.973 raeburn 1226: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1227:
1.112 bowersj2 1228: Returns a string corresponding to an HTML link to the given help
1229: $topic, where $topic corresponds to the name of a .tex file in
1230: /home/httpd/html/adm/help/tex, with underscores replaced by
1231: spaces.
1232:
1233: $text will optionally be linked to the same topic, allowing you to
1234: link text in addition to the graphic. If you do not want to link
1235: text, but wish to specify one of the later parameters, pass an
1236: empty string.
1237:
1238: $stayOnPage is a value that will be interpreted as a boolean. If true,
1239: the link will not open a new window. If false, the link will open
1240: a new window using Javascript. (Default is false.)
1241:
1242: $width and $height are optional numerical parameters that will
1243: override the width and height of the popped up window, which may
1.973 raeburn 1244: be useful for certain help topics with big pictures included.
1245:
1246: $imgid is the id of the img tag used for the help icon. This may be
1247: used in a javascript call to switch the image src. See
1248: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1249:
1250: =cut
1251:
1252: sub help_open_topic {
1.973 raeburn 1253: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1254: $text = "" if (not defined $text);
1.44 bowersj2 1255: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1256: $width = 500 if (not defined $width);
1.44 bowersj2 1257: $height = 400 if (not defined $height);
1258: my $filename = $topic;
1259: $filename =~ s/ /_/g;
1260:
1.48 bowersj2 1261: my $template = "";
1262: my $link;
1.572 banghart 1263:
1.159 www 1264: $topic=~s/\W/\_/g;
1.44 bowersj2 1265:
1.572 banghart 1266: if (!$stayOnPage) {
1.1033 www 1267: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1268: } elsif ($stayOnPage eq 'popup') {
1269: $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 1270: } else {
1.48 bowersj2 1271: $link = "/adm/help/${filename}.hlp";
1272: }
1273:
1274: # Add the text
1.755 neumanie 1275: if ($text ne "") {
1.763 bisitz 1276: $template.='<span class="LC_help_open_topic">'
1277: .'<a target="_top" href="'.$link.'">'
1278: .$text.'</a>';
1.48 bowersj2 1279: }
1280:
1.763 bisitz 1281: # (Always) Add the graphic
1.179 matthew 1282: my $title = &mt('Online Help');
1.667 raeburn 1283: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1284: if ($imgid ne '') {
1285: $imgid = ' id="'.$imgid.'"';
1286: }
1.763 bisitz 1287: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1288: .'<img src="'.$helpicon.'" border="0"'
1289: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1290: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1291: .' /></a>';
1292: if ($text ne "") {
1293: $template.='</span>';
1294: }
1.44 bowersj2 1295: return $template;
1296:
1.106 bowersj2 1297: }
1298:
1299: # This is a quicky function for Latex cheatsheet editing, since it
1300: # appears in at least four places
1301: sub helpLatexCheatsheet {
1.1037 www 1302: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1303: my $out;
1.106 bowersj2 1304: my $addOther = '';
1.732 raeburn 1305: if ($topic) {
1.1037 www 1306: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1307: }
1308: $out = '<span>' # Start cheatsheet
1309: .$addOther
1310: .'<span>'
1.1037 www 1311: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1312: .'</span> <span>'
1.1037 www 1313: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1314: .'</span>';
1.732 raeburn 1315: unless ($not_author) {
1.763 bisitz 1316: $out .= ' <span>'
1.1037 www 1317: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763 bisitz 1318: .'</span>';
1.732 raeburn 1319: }
1.763 bisitz 1320: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1321: return $out;
1.172 www 1322: }
1323:
1.430 albertel 1324: sub general_help {
1325: my $helptopic='Student_Intro';
1326: if ($env{'request.role'}=~/^(ca|au)/) {
1327: $helptopic='Authoring_Intro';
1.907 raeburn 1328: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1329: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1330: } elsif ($env{'request.role'}=~/^dc/) {
1331: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1332: }
1333: return $helptopic;
1334: }
1335:
1336: sub update_help_link {
1337: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1338: my $origurl = $ENV{'REQUEST_URI'};
1339: $origurl=~s|^/~|/priv/|;
1340: my $timestamp = time;
1341: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1342: $$datum = &escape($$datum);
1343: }
1344:
1345: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1346: my $output .= <<"ENDOUTPUT";
1347: <script type="text/javascript">
1.824 bisitz 1348: // <![CDATA[
1.430 albertel 1349: banner_link = '$banner_link';
1.824 bisitz 1350: // ]]>
1.430 albertel 1351: </script>
1352: ENDOUTPUT
1353: return $output;
1354: }
1355:
1356: # now just updates the help link and generates a blue icon
1.193 raeburn 1357: sub help_open_menu {
1.430 albertel 1358: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1359: = @_;
1.949 droeschl 1360: $stayOnPage = 1;
1.430 albertel 1361: my $output;
1362: if ($component_help) {
1363: if (!$text) {
1364: $output=&help_open_topic($component_help,undef,$stayOnPage,
1365: $width,$height);
1366: } else {
1367: my $help_text;
1368: $help_text=&unescape($topic);
1369: $output='<table><tr><td>'.
1370: &help_open_topic($component_help,$help_text,$stayOnPage,
1371: $width,$height).'</td></tr></table>';
1372: }
1373: }
1374: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1375: return $output.$banner_link;
1376: }
1377:
1378: sub top_nav_help {
1379: my ($text) = @_;
1.436 albertel 1380: $text = &mt($text);
1.949 droeschl 1381: my $stay_on_page = 1;
1382:
1.572 banghart 1383: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1384: : "javascript:helpMenu('open')";
1.572 banghart 1385: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1386:
1.201 raeburn 1387: my $title = &mt('Get help');
1.436 albertel 1388:
1389: return <<"END";
1390: $banner_link
1391: <a href="$link" title="$title">$text</a>
1392: END
1393: }
1394:
1395: sub help_menu_js {
1396: my ($text) = @_;
1.949 droeschl 1397: my $stayOnPage = 1;
1.436 albertel 1398: my $width = 620;
1399: my $height = 600;
1.430 albertel 1400: my $helptopic=&general_help();
1401: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1402: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1403: my $start_page =
1404: &Apache::loncommon::start_page('Help Menu', undef,
1405: {'frameset' => 1,
1406: 'js_ready' => 1,
1407: 'add_entries' => {
1408: 'border' => '0',
1.579 raeburn 1409: 'rows' => "110,*",},});
1.331 albertel 1410: my $end_page =
1411: &Apache::loncommon::end_page({'frameset' => 1,
1412: 'js_ready' => 1,});
1413:
1.436 albertel 1414: my $template .= <<"ENDTEMPLATE";
1415: <script type="text/javascript">
1.877 bisitz 1416: // <![CDATA[
1.253 albertel 1417: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1418: var banner_link = '';
1.243 raeburn 1419: function helpMenu(target) {
1420: var caller = this;
1421: if (target == 'open') {
1422: var newWindow = null;
1423: try {
1.262 albertel 1424: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1425: }
1426: catch(error) {
1427: writeHelp(caller);
1428: return;
1429: }
1430: if (newWindow) {
1431: caller = newWindow;
1432: }
1.193 raeburn 1433: }
1.243 raeburn 1434: writeHelp(caller);
1435: return;
1436: }
1437: function writeHelp(caller) {
1.1072 raeburn 1438: 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 1439: caller.document.close()
1440: caller.focus()
1.193 raeburn 1441: }
1.877 bisitz 1442: // END LON-CAPA Internal -->
1.253 albertel 1443: // ]]>
1.436 albertel 1444: </script>
1.193 raeburn 1445: ENDTEMPLATE
1446: return $template;
1447: }
1448:
1.172 www 1449: sub help_open_bug {
1450: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1451: unless ($env{'user.adv'}) { return ''; }
1.172 www 1452: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1453: $text = "" if (not defined $text);
1454: $stayOnPage=1;
1.184 albertel 1455: $width = 600 if (not defined $width);
1456: $height = 600 if (not defined $height);
1.172 www 1457:
1458: $topic=~s/\W+/\+/g;
1459: my $link='';
1460: my $template='';
1.379 albertel 1461: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1462: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1463: if (!$stayOnPage)
1464: {
1465: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1466: }
1467: else
1468: {
1469: $link = $url;
1470: }
1471: # Add the text
1472: if ($text ne "")
1473: {
1474: $template .=
1475: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1476: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1477: }
1478:
1479: # Add the graphic
1.179 matthew 1480: my $title = &mt('Report a Bug');
1.215 albertel 1481: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1482: $template .= <<"ENDTEMPLATE";
1.436 albertel 1483: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1484: ENDTEMPLATE
1485: if ($text ne '') { $template.='</td></tr></table>' };
1486: return $template;
1487:
1488: }
1489:
1490: sub help_open_faq {
1491: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1492: unless ($env{'user.adv'}) { return ''; }
1.172 www 1493: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1494: $text = "" if (not defined $text);
1495: $stayOnPage=1;
1496: $width = 350 if (not defined $width);
1497: $height = 400 if (not defined $height);
1498:
1499: $topic=~s/\W+/\+/g;
1500: my $link='';
1501: my $template='';
1502: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1503: if (!$stayOnPage)
1504: {
1505: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1506: }
1507: else
1508: {
1509: $link = $url;
1510: }
1511:
1512: # Add the text
1513: if ($text ne "")
1514: {
1515: $template .=
1.173 www 1516: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1517: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1518: }
1519:
1520: # Add the graphic
1.179 matthew 1521: my $title = &mt('View the FAQ');
1.215 albertel 1522: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1523: $template .= <<"ENDTEMPLATE";
1.436 albertel 1524: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1525: ENDTEMPLATE
1526: if ($text ne '') { $template.='</td></tr></table>' };
1527: return $template;
1528:
1.44 bowersj2 1529: }
1.37 matthew 1530:
1.180 matthew 1531: ###############################################################
1532: ###############################################################
1533:
1.45 matthew 1534: =pod
1535:
1.648 raeburn 1536: =item * &change_content_javascript():
1.256 matthew 1537:
1538: This and the next function allow you to create small sections of an
1539: otherwise static HTML page that you can update on the fly with
1540: Javascript, even in Netscape 4.
1541:
1542: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1543: must be written to the HTML page once. It will prove the Javascript
1544: function "change(name, content)". Calling the change function with the
1545: name of the section
1546: you want to update, matching the name passed to C<changable_area>, and
1547: the new content you want to put in there, will put the content into
1548: that area.
1549:
1550: B<Note>: Netscape 4 only reserves enough space for the changable area
1551: to contain room for the original contents. You need to "make space"
1552: for whatever changes you wish to make, and be B<sure> to check your
1553: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1554: it's adequate for updating a one-line status display, but little more.
1555: This script will set the space to 100% width, so you only need to
1556: worry about height in Netscape 4.
1557:
1558: Modern browsers are much less limiting, and if you can commit to the
1559: user not using Netscape 4, this feature may be used freely with
1560: pretty much any HTML.
1561:
1562: =cut
1563:
1564: sub change_content_javascript {
1565: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1566: if ($env{'browser.type'} eq 'netscape' &&
1567: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1568: return (<<NETSCAPE4);
1569: function change(name, content) {
1570: doc = document.layers[name+"___escape"].layers[0].document;
1571: doc.open();
1572: doc.write(content);
1573: doc.close();
1574: }
1575: NETSCAPE4
1576: } else {
1577: # Otherwise, we need to use semi-standards-compliant code
1578: # (technically, "innerHTML" isn't standard but the equivalent
1579: # is really scary, and every useful browser supports it
1580: return (<<DOMBASED);
1581: function change(name, content) {
1582: element = document.getElementById(name);
1583: element.innerHTML = content;
1584: }
1585: DOMBASED
1586: }
1587: }
1588:
1589: =pod
1590:
1.648 raeburn 1591: =item * &changable_area($name,$origContent):
1.256 matthew 1592:
1593: This provides a "changable area" that can be modified on the fly via
1594: the Javascript code provided in C<change_content_javascript>. $name is
1595: the name you will use to reference the area later; do not repeat the
1596: same name on a given HTML page more then once. $origContent is what
1597: the area will originally contain, which can be left blank.
1598:
1599: =cut
1600:
1601: sub changable_area {
1602: my ($name, $origContent) = @_;
1603:
1.258 albertel 1604: if ($env{'browser.type'} eq 'netscape' &&
1605: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1606: # If this is netscape 4, we need to use the Layer tag
1607: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1608: } else {
1609: return "<span id='$name'>$origContent</span>";
1610: }
1611: }
1612:
1613: =pod
1614:
1.648 raeburn 1615: =item * &viewport_geometry_js
1.590 raeburn 1616:
1617: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1618:
1619: =cut
1620:
1621:
1622: sub viewport_geometry_js {
1623: return <<"GEOMETRY";
1624: var Geometry = {};
1625: function init_geometry() {
1626: if (Geometry.init) { return };
1627: Geometry.init=1;
1628: if (window.innerHeight) {
1629: Geometry.getViewportHeight = function() { return window.innerHeight; };
1630: Geometry.getViewportWidth = function() { return window.innerWidth; };
1631: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1632: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1633: }
1634: else if (document.documentElement && document.documentElement.clientHeight) {
1635: Geometry.getViewportHeight =
1636: function() { return document.documentElement.clientHeight; };
1637: Geometry.getViewportWidth =
1638: function() { return document.documentElement.clientWidth; };
1639:
1640: Geometry.getHorizontalScroll =
1641: function() { return document.documentElement.scrollLeft; };
1642: Geometry.getVerticalScroll =
1643: function() { return document.documentElement.scrollTop; };
1644: }
1645: else if (document.body.clientHeight) {
1646: Geometry.getViewportHeight =
1647: function() { return document.body.clientHeight; };
1648: Geometry.getViewportWidth =
1649: function() { return document.body.clientWidth; };
1650: Geometry.getHorizontalScroll =
1651: function() { return document.body.scrollLeft; };
1652: Geometry.getVerticalScroll =
1653: function() { return document.body.scrollTop; };
1654: }
1655: }
1656:
1657: GEOMETRY
1658: }
1659:
1660: =pod
1661:
1.648 raeburn 1662: =item * &viewport_size_js()
1.590 raeburn 1663:
1664: 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.
1665:
1666: =cut
1667:
1668: sub viewport_size_js {
1669: my $geometry = &viewport_geometry_js();
1670: return <<"DIMS";
1671:
1672: $geometry
1673:
1674: function getViewportDims(width,height) {
1675: init_geometry();
1676: width.value = Geometry.getViewportWidth();
1677: height.value = Geometry.getViewportHeight();
1678: return;
1679: }
1680:
1681: DIMS
1682: }
1683:
1684: =pod
1685:
1.648 raeburn 1686: =item * &resize_textarea_js()
1.565 albertel 1687:
1688: emits the needed javascript to resize a textarea to be as big as possible
1689:
1690: creates a function resize_textrea that takes two IDs first should be
1691: the id of the element to resize, second should be the id of a div that
1692: surrounds everything that comes after the textarea, this routine needs
1693: to be attached to the <body> for the onload and onresize events.
1694:
1.648 raeburn 1695: =back
1.565 albertel 1696:
1697: =cut
1698:
1699: sub resize_textarea_js {
1.590 raeburn 1700: my $geometry = &viewport_geometry_js();
1.565 albertel 1701: return <<"RESIZE";
1702: <script type="text/javascript">
1.824 bisitz 1703: // <![CDATA[
1.590 raeburn 1704: $geometry
1.565 albertel 1705:
1.588 albertel 1706: function getX(element) {
1707: var x = 0;
1708: while (element) {
1709: x += element.offsetLeft;
1710: element = element.offsetParent;
1711: }
1712: return x;
1713: }
1714: function getY(element) {
1715: var y = 0;
1716: while (element) {
1717: y += element.offsetTop;
1718: element = element.offsetParent;
1719: }
1720: return y;
1721: }
1722:
1723:
1.565 albertel 1724: function resize_textarea(textarea_id,bottom_id) {
1725: init_geometry();
1726: var textarea = document.getElementById(textarea_id);
1727: //alert(textarea);
1728:
1.588 albertel 1729: var textarea_top = getY(textarea);
1.565 albertel 1730: var textarea_height = textarea.offsetHeight;
1731: var bottom = document.getElementById(bottom_id);
1.588 albertel 1732: var bottom_top = getY(bottom);
1.565 albertel 1733: var bottom_height = bottom.offsetHeight;
1734: var window_height = Geometry.getViewportHeight();
1.588 albertel 1735: var fudge = 23;
1.565 albertel 1736: var new_height = window_height-fudge-textarea_top-bottom_height;
1737: if (new_height < 300) {
1738: new_height = 300;
1739: }
1740: textarea.style.height=new_height+'px';
1741: }
1.824 bisitz 1742: // ]]>
1.565 albertel 1743: </script>
1744: RESIZE
1745:
1746: }
1747:
1748: =pod
1749:
1.256 matthew 1750: =head1 Excel and CSV file utility routines
1751:
1752: =over 4
1753:
1754: =cut
1755:
1756: ###############################################################
1757: ###############################################################
1758:
1759: =pod
1760:
1.648 raeburn 1761: =item * &csv_translate($text)
1.37 matthew 1762:
1.185 www 1763: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1764: format.
1765:
1766: =cut
1767:
1.180 matthew 1768: ###############################################################
1769: ###############################################################
1.37 matthew 1770: sub csv_translate {
1771: my $text = shift;
1772: $text =~ s/\"/\"\"/g;
1.209 albertel 1773: $text =~ s/\n/ /g;
1.37 matthew 1774: return $text;
1775: }
1.180 matthew 1776:
1777: ###############################################################
1778: ###############################################################
1779:
1780: =pod
1781:
1.648 raeburn 1782: =item * &define_excel_formats()
1.180 matthew 1783:
1784: Define some commonly used Excel cell formats.
1785:
1786: Currently supported formats:
1787:
1788: =over 4
1789:
1790: =item header
1791:
1792: =item bold
1793:
1794: =item h1
1795:
1796: =item h2
1797:
1798: =item h3
1799:
1.256 matthew 1800: =item h4
1801:
1802: =item i
1803:
1.180 matthew 1804: =item date
1805:
1806: =back
1807:
1808: Inputs: $workbook
1809:
1810: Returns: $format, a hash reference.
1811:
1.1057 foxr 1812:
1.180 matthew 1813: =cut
1814:
1815: ###############################################################
1816: ###############################################################
1817: sub define_excel_formats {
1818: my ($workbook) = @_;
1819: my $format;
1820: $format->{'header'} = $workbook->add_format(bold => 1,
1821: bottom => 1,
1822: align => 'center');
1823: $format->{'bold'} = $workbook->add_format(bold=>1);
1824: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1825: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1826: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1827: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1828: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1829: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1830: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1831: return $format;
1832: }
1833:
1834: ###############################################################
1835: ###############################################################
1.113 bowersj2 1836:
1837: =pod
1838:
1.648 raeburn 1839: =item * &create_workbook()
1.255 matthew 1840:
1841: Create an Excel worksheet. If it fails, output message on the
1842: request object and return undefs.
1843:
1844: Inputs: Apache request object
1845:
1846: Returns (undef) on failure,
1847: Excel worksheet object, scalar with filename, and formats
1848: from &Apache::loncommon::define_excel_formats on success
1849:
1850: =cut
1851:
1852: ###############################################################
1853: ###############################################################
1854: sub create_workbook {
1855: my ($r) = @_;
1856: #
1857: # Create the excel spreadsheet
1858: my $filename = '/prtspool/'.
1.258 albertel 1859: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1860: time.'_'.rand(1000000000).'.xls';
1861: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1862: if (! defined($workbook)) {
1863: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1864: $r->print(
1865: '<p class="LC_error">'
1866: .&mt('Problems occurred in creating the new Excel file.')
1867: .' '.&mt('This error has been logged.')
1868: .' '.&mt('Please alert your LON-CAPA administrator.')
1869: .'</p>'
1870: );
1.255 matthew 1871: return (undef);
1872: }
1873: #
1.1014 foxr 1874: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1875: #
1876: my $format = &Apache::loncommon::define_excel_formats($workbook);
1877: return ($workbook,$filename,$format);
1878: }
1879:
1880: ###############################################################
1881: ###############################################################
1882:
1883: =pod
1884:
1.648 raeburn 1885: =item * &create_text_file()
1.113 bowersj2 1886:
1.542 raeburn 1887: Create a file to write to and eventually make available to the user.
1.256 matthew 1888: If file creation fails, outputs an error message on the request object and
1889: return undefs.
1.113 bowersj2 1890:
1.256 matthew 1891: Inputs: Apache request object, and file suffix
1.113 bowersj2 1892:
1.256 matthew 1893: Returns (undef) on failure,
1894: Filehandle and filename on success.
1.113 bowersj2 1895:
1896: =cut
1897:
1.256 matthew 1898: ###############################################################
1899: ###############################################################
1900: sub create_text_file {
1901: my ($r,$suffix) = @_;
1902: if (! defined($suffix)) { $suffix = 'txt'; };
1903: my $fh;
1904: my $filename = '/prtspool/'.
1.258 albertel 1905: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1906: time.'_'.rand(1000000000).'.'.$suffix;
1907: $fh = Apache::File->new('>/home/httpd'.$filename);
1908: if (! defined($fh)) {
1909: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1910: $r->print(
1911: '<p class="LC_error">'
1912: .&mt('Problems occurred in creating the output file.')
1913: .' '.&mt('This error has been logged.')
1914: .' '.&mt('Please alert your LON-CAPA administrator.')
1915: .'</p>'
1916: );
1.113 bowersj2 1917: }
1.256 matthew 1918: return ($fh,$filename)
1.113 bowersj2 1919: }
1920:
1921:
1.256 matthew 1922: =pod
1.113 bowersj2 1923:
1924: =back
1925:
1926: =cut
1.37 matthew 1927:
1928: ###############################################################
1.33 matthew 1929: ## Home server <option> list generating code ##
1930: ###############################################################
1.35 matthew 1931:
1.169 www 1932: # ------------------------------------------
1933:
1934: sub domain_select {
1935: my ($name,$value,$multiple)=@_;
1936: my %domains=map {
1.514 albertel 1937: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1938: } &Apache::lonnet::all_domains();
1.169 www 1939: if ($multiple) {
1940: $domains{''}=&mt('Any domain');
1.550 albertel 1941: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1942: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1943: } else {
1.550 albertel 1944: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1945: return &select_form($name,$value,\%domains);
1.169 www 1946: }
1947: }
1948:
1.282 albertel 1949: #-------------------------------------------
1950:
1951: =pod
1952:
1.519 raeburn 1953: =head1 Routines for form select boxes
1954:
1955: =over 4
1956:
1.648 raeburn 1957: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1958:
1959: Returns a string containing a <select> element int multiple mode
1960:
1961:
1962: Args:
1963: $name - name of the <select> element
1.506 raeburn 1964: $value - scalar or array ref of values that should already be selected
1.282 albertel 1965: $size - number of rows long the select element is
1.283 albertel 1966: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1967: (shown text should already have been &mt())
1.506 raeburn 1968: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1969:
1.282 albertel 1970: =cut
1971:
1972: #-------------------------------------------
1.169 www 1973: sub multiple_select_form {
1.284 albertel 1974: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1975: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1976: my $output='';
1.191 matthew 1977: if (! defined($size)) {
1978: $size = 4;
1.283 albertel 1979: if (scalar(keys(%$hash))<4) {
1980: $size = scalar(keys(%$hash));
1.191 matthew 1981: }
1982: }
1.734 bisitz 1983: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1984: my @order;
1.506 raeburn 1985: if (ref($order) eq 'ARRAY') {
1986: @order = @{$order};
1987: } else {
1988: @order = sort(keys(%$hash));
1.501 banghart 1989: }
1990: if (exists($$hash{'select_form_order'})) {
1991: @order = @{$$hash{'select_form_order'}};
1992: }
1993:
1.284 albertel 1994: foreach my $key (@order) {
1.356 albertel 1995: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1996: $output.='selected="selected" ' if ($selected{$key});
1997: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1998: }
1999: $output.="</select>\n";
2000: return $output;
2001: }
2002:
1.88 www 2003: #-------------------------------------------
2004:
2005: =pod
2006:
1.970 raeburn 2007: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 2008:
2009: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2010: allow a user to select options from a ref to a hash containing:
2011: option_name => displayed text. An optional $onchange can include
2012: a javascript onchange item, e.g., onchange="this.form.submit();"
2013:
1.88 www 2014: See lonrights.pm for an example invocation and use.
2015:
2016: =cut
2017:
2018: #-------------------------------------------
2019: sub select_form {
1.970 raeburn 2020: my ($def,$name,$hashref,$onchange) = @_;
2021: return unless (ref($hashref) eq 'HASH');
2022: if ($onchange) {
2023: $onchange = ' onchange="'.$onchange.'"';
2024: }
2025: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2026: my @keys;
1.970 raeburn 2027: if (exists($hashref->{'select_form_order'})) {
2028: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2029: } else {
1.970 raeburn 2030: @keys=sort(keys(%{$hashref}));
1.128 albertel 2031: }
1.356 albertel 2032: foreach my $key (@keys) {
2033: $selectform.=
2034: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2035: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2036: ">".$hashref->{$key}."</option>\n";
1.88 www 2037: }
2038: $selectform.="</select>";
2039: return $selectform;
2040: }
2041:
1.475 www 2042: # For display filters
2043:
2044: sub display_filter {
1.1074 raeburn 2045: my ($context) = @_;
1.475 www 2046: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2047: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2048: my $phraseinput = 'hidden';
2049: my $includeinput = 'hidden';
2050: my ($checked,$includetypestext);
2051: if ($env{'form.displayfilter'} eq 'containing') {
2052: $phraseinput = 'text';
2053: if ($context eq 'parmslog') {
2054: $includeinput = 'checkbox';
2055: if ($env{'form.includetypes'}) {
2056: $checked = ' checked="checked"';
2057: }
2058: $includetypestext = &mt('Include parameter types');
2059: }
2060: } else {
2061: $includetypestext = ' ';
2062: }
2063: my ($additional,$secondid,$thirdid);
2064: if ($context eq 'parmslog') {
2065: $additional =
2066: '<label><input type="'.$includeinput.'" name="includetypes"'.
2067: $checked.' name="includetypes" value="1" id="includetypes" />'.
2068: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2069: '</label>';
2070: $secondid = 'includetypes';
2071: $thirdid = 'includetypestext';
2072: }
2073: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2074: '$secondid','$thirdid')";
2075: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2076: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2077: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2078: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2079: &mt('Filter: [_1]',
1.477 www 2080: &select_form($env{'form.displayfilter'},
2081: 'displayfilter',
1.970 raeburn 2082: {'currentfolder' => 'Current folder/page',
1.477 www 2083: 'containing' => 'Containing phrase',
1.1074 raeburn 2084: 'none' => 'None'},$onchange)).' '.
2085: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2086: &HTML::Entities::encode($env{'form.containingphrase'}).
2087: '" />'.$additional;
2088: }
2089:
2090: sub display_filter_js {
2091: my $includetext = &mt('Include parameter types');
2092: return <<"ENDJS";
2093:
2094: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2095: var firstType = 'hidden';
2096: if (setter.options[setter.selectedIndex].value == 'containing') {
2097: firstType = 'text';
2098: }
2099: firstObject = document.getElementById(firstid);
2100: if (typeof(firstObject) == 'object') {
2101: if (firstObject.type != firstType) {
2102: changeInputType(firstObject,firstType);
2103: }
2104: }
2105: if (context == 'parmslog') {
2106: var secondType = 'hidden';
2107: if (firstType == 'text') {
2108: secondType = 'checkbox';
2109: }
2110: secondObject = document.getElementById(secondid);
2111: if (typeof(secondObject) == 'object') {
2112: if (secondObject.type != secondType) {
2113: changeInputType(secondObject,secondType);
2114: }
2115: }
2116: var textItem = document.getElementById(thirdid);
2117: var currtext = textItem.innerHTML;
2118: var newtext;
2119: if (firstType == 'text') {
2120: newtext = '$includetext';
2121: } else {
2122: newtext = ' ';
2123: }
2124: if (currtext != newtext) {
2125: textItem.innerHTML = newtext;
2126: }
2127: }
2128: return;
2129: }
2130:
2131: function changeInputType(oldObject,newType) {
2132: var newObject = document.createElement('input');
2133: newObject.type = newType;
2134: if (oldObject.size) {
2135: newObject.size = oldObject.size;
2136: }
2137: if (oldObject.value) {
2138: newObject.value = oldObject.value;
2139: }
2140: if (oldObject.name) {
2141: newObject.name = oldObject.name;
2142: }
2143: if (oldObject.id) {
2144: newObject.id = oldObject.id;
2145: }
2146: oldObject.parentNode.replaceChild(newObject,oldObject);
2147: return;
2148: }
2149:
2150: ENDJS
1.475 www 2151: }
2152:
1.167 www 2153: sub gradeleveldescription {
2154: my $gradelevel=shift;
2155: my %gradelevels=(0 => 'Not specified',
2156: 1 => 'Grade 1',
2157: 2 => 'Grade 2',
2158: 3 => 'Grade 3',
2159: 4 => 'Grade 4',
2160: 5 => 'Grade 5',
2161: 6 => 'Grade 6',
2162: 7 => 'Grade 7',
2163: 8 => 'Grade 8',
2164: 9 => 'Grade 9',
2165: 10 => 'Grade 10',
2166: 11 => 'Grade 11',
2167: 12 => 'Grade 12',
2168: 13 => 'Grade 13',
2169: 14 => '100 Level',
2170: 15 => '200 Level',
2171: 16 => '300 Level',
2172: 17 => '400 Level',
2173: 18 => 'Graduate Level');
2174: return &mt($gradelevels{$gradelevel});
2175: }
2176:
1.163 www 2177: sub select_level_form {
2178: my ($deflevel,$name)=@_;
2179: unless ($deflevel) { $deflevel=0; }
1.167 www 2180: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2181: for (my $i=0; $i<=18; $i++) {
2182: $selectform.="<option value=\"$i\" ".
1.253 albertel 2183: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2184: ">".&gradeleveldescription($i)."</option>\n";
2185: }
2186: $selectform.="</select>";
2187: return $selectform;
1.163 www 2188: }
1.167 www 2189:
1.35 matthew 2190: #-------------------------------------------
2191:
1.45 matthew 2192: =pod
2193:
1.1121 raeburn 2194: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2195:
2196: Returns a string containing a <select name='$name' size='1'> form to
2197: allow a user to select the domain to preform an operation in.
2198: See loncreateuser.pm for an example invocation and use.
2199:
1.90 www 2200: If the $includeempty flag is set, it also includes an empty choice ("no domain
2201: selected");
2202:
1.743 raeburn 2203: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2204:
1.910 raeburn 2205: 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.
2206:
1.1121 raeburn 2207: The optional $incdoms is a reference to an array of domains which will be the only available options.
2208:
2209: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2210:
1.35 matthew 2211: =cut
2212:
2213: #-------------------------------------------
1.34 matthew 2214: sub select_dom_form {
1.1121 raeburn 2215: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2216: if ($onchange) {
1.874 raeburn 2217: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2218: }
1.1121 raeburn 2219: my (@domains,%exclude);
1.910 raeburn 2220: if (ref($incdoms) eq 'ARRAY') {
2221: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2222: } else {
2223: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2224: }
1.90 www 2225: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2226: if (ref($excdoms) eq 'ARRAY') {
2227: map { $exclude{$_} = 1; } @{$excdoms};
2228: }
1.743 raeburn 2229: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2230: foreach my $dom (@domains) {
1.1121 raeburn 2231: next if ($exclude{$dom});
1.356 albertel 2232: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2233: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2234: if ($showdomdesc) {
2235: if ($dom ne '') {
2236: my $domdesc = &Apache::lonnet::domain($dom,'description');
2237: if ($domdesc ne '') {
2238: $selectdomain .= ' ('.$domdesc.')';
2239: }
2240: }
2241: }
2242: $selectdomain .= "</option>\n";
1.34 matthew 2243: }
2244: $selectdomain.="</select>";
2245: return $selectdomain;
2246: }
2247:
1.35 matthew 2248: #-------------------------------------------
2249:
1.45 matthew 2250: =pod
2251:
1.648 raeburn 2252: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2253:
1.586 raeburn 2254: input: 4 arguments (two required, two optional) -
2255: $domain - domain of new user
2256: $name - name of form element
2257: $default - Value of 'default' causes a default item to be first
2258: option, and selected by default.
2259: $hide - Value of 'hide' causes hiding of the name of the server,
2260: if 1 server found, or default, if 0 found.
1.594 raeburn 2261: output: returns 2 items:
1.586 raeburn 2262: (a) form element which contains either:
2263: (i) <select name="$name">
2264: <option value="$hostid1">$hostid $servers{$hostid}</option>
2265: <option value="$hostid2">$hostid $servers{$hostid}</option>
2266: </select>
2267: form item if there are multiple library servers in $domain, or
2268: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2269: if there is only one library server in $domain.
2270:
2271: (b) number of library servers found.
2272:
2273: See loncreateuser.pm for example of use.
1.35 matthew 2274:
2275: =cut
2276:
2277: #-------------------------------------------
1.586 raeburn 2278: sub home_server_form_item {
2279: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2280: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2281: my $result;
2282: my $numlib = keys(%servers);
2283: if ($numlib > 1) {
2284: $result .= '<select name="'.$name.'" />'."\n";
2285: if ($default) {
1.804 bisitz 2286: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2287: '</option>'."\n";
2288: }
2289: foreach my $hostid (sort(keys(%servers))) {
2290: $result.= '<option value="'.$hostid.'">'.
2291: $hostid.' '.$servers{$hostid}."</option>\n";
2292: }
2293: $result .= '</select>'."\n";
2294: } elsif ($numlib == 1) {
2295: my $hostid;
2296: foreach my $item (keys(%servers)) {
2297: $hostid = $item;
2298: }
2299: $result .= '<input type="hidden" name="'.$name.'" value="'.
2300: $hostid.'" />';
2301: if (!$hide) {
2302: $result .= $hostid.' '.$servers{$hostid};
2303: }
2304: $result .= "\n";
2305: } elsif ($default) {
2306: $result .= '<input type="hidden" name="'.$name.
2307: '" value="default" />';
2308: if (!$hide) {
2309: $result .= &mt('default');
2310: }
2311: $result .= "\n";
1.33 matthew 2312: }
1.586 raeburn 2313: return ($result,$numlib);
1.33 matthew 2314: }
1.112 bowersj2 2315:
2316: =pod
2317:
1.534 albertel 2318: =back
2319:
1.112 bowersj2 2320: =cut
1.87 matthew 2321:
2322: ###############################################################
1.112 bowersj2 2323: ## Decoding User Agent ##
1.87 matthew 2324: ###############################################################
2325:
2326: =pod
2327:
1.112 bowersj2 2328: =head1 Decoding the User Agent
2329:
2330: =over 4
2331:
2332: =item * &decode_user_agent()
1.87 matthew 2333:
2334: Inputs: $r
2335:
2336: Outputs:
2337:
2338: =over 4
2339:
1.112 bowersj2 2340: =item * $httpbrowser
1.87 matthew 2341:
1.112 bowersj2 2342: =item * $clientbrowser
1.87 matthew 2343:
1.112 bowersj2 2344: =item * $clientversion
1.87 matthew 2345:
1.112 bowersj2 2346: =item * $clientmathml
1.87 matthew 2347:
1.112 bowersj2 2348: =item * $clientunicode
1.87 matthew 2349:
1.112 bowersj2 2350: =item * $clientos
1.87 matthew 2351:
1.1137 raeburn 2352: =item * $clientmobile
2353:
1.87 matthew 2354: =back
2355:
1.157 matthew 2356: =back
2357:
1.87 matthew 2358: =cut
2359:
2360: ###############################################################
2361: ###############################################################
2362: sub decode_user_agent {
1.247 albertel 2363: my ($r)=@_;
1.87 matthew 2364: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2365: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2366: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2367: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2368: my $clientbrowser='unknown';
2369: my $clientversion='0';
2370: my $clientmathml='';
2371: my $clientunicode='0';
1.1137 raeburn 2372: my $clientmobile=0;
1.87 matthew 2373: for (my $i=0;$i<=$#browsertype;$i++) {
2374: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2375: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2376: $clientbrowser=$bname;
2377: $httpbrowser=~/$vreg/i;
2378: $clientversion=$1;
2379: $clientmathml=($clientversion>=$minv);
2380: $clientunicode=($clientversion>=$univ);
2381: }
2382: }
2383: my $clientos='unknown';
2384: if (($httpbrowser=~/linux/i) ||
2385: ($httpbrowser=~/unix/i) ||
2386: ($httpbrowser=~/ux/i) ||
2387: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2388: if (($httpbrowser=~/vax/i) ||
2389: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2390: if ($httpbrowser=~/next/i) { $clientos='next'; }
2391: if (($httpbrowser=~/mac/i) ||
2392: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2393: if ($httpbrowser=~/win/i) { $clientos='win'; }
2394: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2395: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2396: $clientmobile=lc($1);
2397: }
1.87 matthew 2398: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1137 raeburn 2399: $clientunicode,$clientos,$clientmobile);
1.87 matthew 2400: }
2401:
1.32 matthew 2402: ###############################################################
2403: ## Authentication changing form generation subroutines ##
2404: ###############################################################
2405: ##
2406: ## All of the authform_xxxxxxx subroutines take their inputs in a
2407: ## hash, and have reasonable default values.
2408: ##
2409: ## formname = the name given in the <form> tag.
1.35 matthew 2410: #-------------------------------------------
2411:
1.45 matthew 2412: =pod
2413:
1.112 bowersj2 2414: =head1 Authentication Routines
2415:
2416: =over 4
2417:
1.648 raeburn 2418: =item * &authform_xxxxxx()
1.35 matthew 2419:
2420: The authform_xxxxxx subroutines provide javascript and html forms which
2421: handle some of the conveniences required for authentication forms.
2422: This is not an optimal method, but it works.
2423:
2424: =over 4
2425:
1.112 bowersj2 2426: =item * authform_header
1.35 matthew 2427:
1.112 bowersj2 2428: =item * authform_authorwarning
1.35 matthew 2429:
1.112 bowersj2 2430: =item * authform_nochange
1.35 matthew 2431:
1.112 bowersj2 2432: =item * authform_kerberos
1.35 matthew 2433:
1.112 bowersj2 2434: =item * authform_internal
1.35 matthew 2435:
1.112 bowersj2 2436: =item * authform_filesystem
1.35 matthew 2437:
2438: =back
2439:
1.648 raeburn 2440: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2441:
1.35 matthew 2442: =cut
2443:
2444: #-------------------------------------------
1.32 matthew 2445: sub authform_header{
2446: my %in = (
2447: formname => 'cu',
1.80 albertel 2448: kerb_def_dom => '',
1.32 matthew 2449: @_,
2450: );
2451: $in{'formname'} = 'document.' . $in{'formname'};
2452: my $result='';
1.80 albertel 2453:
2454: #---------------------------------------------- Code for upper case translation
2455: my $Javascript_toUpperCase;
2456: unless ($in{kerb_def_dom}) {
2457: $Javascript_toUpperCase =<<"END";
2458: switch (choice) {
2459: case 'krb': currentform.elements[choicearg].value =
2460: currentform.elements[choicearg].value.toUpperCase();
2461: break;
2462: default:
2463: }
2464: END
2465: } else {
2466: $Javascript_toUpperCase = "";
2467: }
2468:
1.165 raeburn 2469: my $radioval = "'nochange'";
1.591 raeburn 2470: if (defined($in{'curr_authtype'})) {
2471: if ($in{'curr_authtype'} ne '') {
2472: $radioval = "'".$in{'curr_authtype'}."arg'";
2473: }
1.174 matthew 2474: }
1.165 raeburn 2475: my $argfield = 'null';
1.591 raeburn 2476: if (defined($in{'mode'})) {
1.165 raeburn 2477: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2478: if (defined($in{'curr_autharg'})) {
2479: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2480: $argfield = "'$in{'curr_autharg'}'";
2481: }
2482: }
2483: }
2484: }
2485:
1.32 matthew 2486: $result.=<<"END";
2487: var current = new Object();
1.165 raeburn 2488: current.radiovalue = $radioval;
2489: current.argfield = $argfield;
1.32 matthew 2490:
2491: function changed_radio(choice,currentform) {
2492: var choicearg = choice + 'arg';
2493: // If a radio button in changed, we need to change the argfield
2494: if (current.radiovalue != choice) {
2495: current.radiovalue = choice;
2496: if (current.argfield != null) {
2497: currentform.elements[current.argfield].value = '';
2498: }
2499: if (choice == 'nochange') {
2500: current.argfield = null;
2501: } else {
2502: current.argfield = choicearg;
2503: switch(choice) {
2504: case 'krb':
2505: currentform.elements[current.argfield].value =
2506: "$in{'kerb_def_dom'}";
2507: break;
2508: default:
2509: break;
2510: }
2511: }
2512: }
2513: return;
2514: }
1.22 www 2515:
1.32 matthew 2516: function changed_text(choice,currentform) {
2517: var choicearg = choice + 'arg';
2518: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2519: $Javascript_toUpperCase
1.32 matthew 2520: // clear old field
2521: if ((current.argfield != choicearg) && (current.argfield != null)) {
2522: currentform.elements[current.argfield].value = '';
2523: }
2524: current.argfield = choicearg;
2525: }
2526: set_auth_radio_buttons(choice,currentform);
2527: return;
1.20 www 2528: }
1.32 matthew 2529:
2530: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2531: var numauthchoices = currentform.login.length;
2532: if (typeof numauthchoices == "undefined") {
2533: return;
2534: }
1.32 matthew 2535: var i=0;
1.986 raeburn 2536: while (i < numauthchoices) {
1.32 matthew 2537: if (currentform.login[i].value == newvalue) { break; }
2538: i++;
2539: }
1.986 raeburn 2540: if (i == numauthchoices) {
1.32 matthew 2541: return;
2542: }
2543: current.radiovalue = newvalue;
2544: currentform.login[i].checked = true;
2545: return;
2546: }
2547: END
2548: return $result;
2549: }
2550:
1.1106 raeburn 2551: sub authform_authorwarning {
1.32 matthew 2552: my $result='';
1.144 matthew 2553: $result='<i>'.
2554: &mt('As a general rule, only authors or co-authors should be '.
2555: 'filesystem authenticated '.
2556: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2557: return $result;
2558: }
2559:
1.1106 raeburn 2560: sub authform_nochange {
1.32 matthew 2561: my %in = (
2562: formname => 'document.cu',
2563: kerb_def_dom => 'MSU.EDU',
2564: @_,
2565: );
1.1106 raeburn 2566: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2567: my $result;
1.1104 raeburn 2568: if (!$authnum) {
1.1105 raeburn 2569: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2570: } else {
2571: $result = '<label>'.&mt('[_1] Do not change login data',
2572: '<input type="radio" name="login" value="nochange" '.
2573: 'checked="checked" onclick="'.
1.281 albertel 2574: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2575: '</label>';
1.586 raeburn 2576: }
1.32 matthew 2577: return $result;
2578: }
2579:
1.591 raeburn 2580: sub authform_kerberos {
1.32 matthew 2581: my %in = (
2582: formname => 'document.cu',
2583: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2584: kerb_def_auth => 'krb4',
1.32 matthew 2585: @_,
2586: );
1.586 raeburn 2587: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2588: $autharg,$jscall);
1.1106 raeburn 2589: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2590: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2591: $check5 = ' checked="checked"';
1.80 albertel 2592: } else {
1.772 bisitz 2593: $check4 = ' checked="checked"';
1.80 albertel 2594: }
1.165 raeburn 2595: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2596: if (defined($in{'curr_authtype'})) {
2597: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2598: $krbcheck = ' checked="checked"';
1.623 raeburn 2599: if (defined($in{'mode'})) {
2600: if ($in{'mode'} eq 'modifyuser') {
2601: $krbcheck = '';
2602: }
2603: }
1.591 raeburn 2604: if (defined($in{'curr_kerb_ver'})) {
2605: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2606: $check5 = ' checked="checked"';
1.591 raeburn 2607: $check4 = '';
2608: } else {
1.772 bisitz 2609: $check4 = ' checked="checked"';
1.591 raeburn 2610: $check5 = '';
2611: }
1.586 raeburn 2612: }
1.591 raeburn 2613: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2614: $krbarg = $in{'curr_autharg'};
2615: }
1.586 raeburn 2616: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2617: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2618: $result =
2619: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2620: $in{'curr_autharg'},$krbver);
2621: } else {
2622: $result =
2623: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2624: }
2625: return $result;
2626: }
2627: }
2628: } else {
2629: if ($authnum == 1) {
1.784 bisitz 2630: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2631: }
2632: }
1.586 raeburn 2633: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2634: return;
1.587 raeburn 2635: } elsif ($authtype eq '') {
1.591 raeburn 2636: if (defined($in{'mode'})) {
1.587 raeburn 2637: if ($in{'mode'} eq 'modifycourse') {
2638: if ($authnum == 1) {
1.1104 raeburn 2639: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2640: }
2641: }
2642: }
1.586 raeburn 2643: }
2644: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2645: if ($authtype eq '') {
2646: $authtype = '<input type="radio" name="login" value="krb" '.
2647: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2648: $krbcheck.' />';
2649: }
2650: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2651: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2652: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2653: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2654: $in{'curr_authtype'} eq 'krb4')) {
2655: $result .= &mt
1.144 matthew 2656: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2657: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2658: '<label>'.$authtype,
1.281 albertel 2659: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2660: 'value="'.$krbarg.'" '.
1.144 matthew 2661: 'onchange="'.$jscall.'" />',
1.281 albertel 2662: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2663: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2664: '</label>');
1.586 raeburn 2665: } elsif ($can_assign{'krb4'}) {
2666: $result .= &mt
2667: ('[_1] Kerberos authenticated with domain [_2] '.
2668: '[_3] Version 4 [_4]',
2669: '<label>'.$authtype,
2670: '</label><input type="text" size="10" name="krbarg" '.
2671: 'value="'.$krbarg.'" '.
2672: 'onchange="'.$jscall.'" />',
2673: '<label><input type="hidden" name="krbver" value="4" />',
2674: '</label>');
2675: } elsif ($can_assign{'krb5'}) {
2676: $result .= &mt
2677: ('[_1] Kerberos authenticated with domain [_2] '.
2678: '[_3] Version 5 [_4]',
2679: '<label>'.$authtype,
2680: '</label><input type="text" size="10" name="krbarg" '.
2681: 'value="'.$krbarg.'" '.
2682: 'onchange="'.$jscall.'" />',
2683: '<label><input type="hidden" name="krbver" value="5" />',
2684: '</label>');
2685: }
1.32 matthew 2686: return $result;
2687: }
2688:
1.1106 raeburn 2689: sub authform_internal {
1.586 raeburn 2690: my %in = (
1.32 matthew 2691: formname => 'document.cu',
2692: kerb_def_dom => 'MSU.EDU',
2693: @_,
2694: );
1.586 raeburn 2695: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2696: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2697: if (defined($in{'curr_authtype'})) {
2698: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2699: if ($can_assign{'int'}) {
1.772 bisitz 2700: $intcheck = 'checked="checked" ';
1.623 raeburn 2701: if (defined($in{'mode'})) {
2702: if ($in{'mode'} eq 'modifyuser') {
2703: $intcheck = '';
2704: }
2705: }
1.591 raeburn 2706: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2707: $intarg = $in{'curr_autharg'};
2708: }
2709: } else {
2710: $result = &mt('Currently internally authenticated.');
2711: return $result;
1.165 raeburn 2712: }
2713: }
1.586 raeburn 2714: } else {
2715: if ($authnum == 1) {
1.784 bisitz 2716: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2717: }
2718: }
2719: if (!$can_assign{'int'}) {
2720: return;
1.587 raeburn 2721: } elsif ($authtype eq '') {
1.591 raeburn 2722: if (defined($in{'mode'})) {
1.587 raeburn 2723: if ($in{'mode'} eq 'modifycourse') {
2724: if ($authnum == 1) {
1.1104 raeburn 2725: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2726: }
2727: }
2728: }
1.165 raeburn 2729: }
1.586 raeburn 2730: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2731: if ($authtype eq '') {
2732: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2733: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2734: }
1.605 bisitz 2735: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2736: $intarg.'" onchange="'.$jscall.'" />';
2737: $result = &mt
1.144 matthew 2738: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2739: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2740: $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 2741: return $result;
2742: }
2743:
1.1104 raeburn 2744: sub authform_local {
1.32 matthew 2745: my %in = (
2746: formname => 'document.cu',
2747: kerb_def_dom => 'MSU.EDU',
2748: @_,
2749: );
1.586 raeburn 2750: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2751: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2752: if (defined($in{'curr_authtype'})) {
2753: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2754: if ($can_assign{'loc'}) {
1.772 bisitz 2755: $loccheck = 'checked="checked" ';
1.623 raeburn 2756: if (defined($in{'mode'})) {
2757: if ($in{'mode'} eq 'modifyuser') {
2758: $loccheck = '';
2759: }
2760: }
1.591 raeburn 2761: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2762: $locarg = $in{'curr_autharg'};
2763: }
2764: } else {
2765: $result = &mt('Currently using local (institutional) authentication.');
2766: return $result;
1.165 raeburn 2767: }
2768: }
1.586 raeburn 2769: } else {
2770: if ($authnum == 1) {
1.784 bisitz 2771: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2772: }
2773: }
2774: if (!$can_assign{'loc'}) {
2775: return;
1.587 raeburn 2776: } elsif ($authtype eq '') {
1.591 raeburn 2777: if (defined($in{'mode'})) {
1.587 raeburn 2778: if ($in{'mode'} eq 'modifycourse') {
2779: if ($authnum == 1) {
1.1104 raeburn 2780: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2781: }
2782: }
2783: }
1.165 raeburn 2784: }
1.586 raeburn 2785: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2786: if ($authtype eq '') {
2787: $authtype = '<input type="radio" name="login" value="loc" '.
2788: $loccheck.' onchange="'.$jscall.'" onclick="'.
2789: $jscall.'" />';
2790: }
2791: $autharg = '<input type="text" size="10" name="locarg" value="'.
2792: $locarg.'" onchange="'.$jscall.'" />';
2793: $result = &mt('[_1] Local Authentication with argument [_2]',
2794: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2795: return $result;
2796: }
2797:
1.1106 raeburn 2798: sub authform_filesystem {
1.32 matthew 2799: my %in = (
2800: formname => 'document.cu',
2801: kerb_def_dom => 'MSU.EDU',
2802: @_,
2803: );
1.586 raeburn 2804: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2805: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2806: if (defined($in{'curr_authtype'})) {
2807: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2808: if ($can_assign{'fsys'}) {
1.772 bisitz 2809: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2810: if (defined($in{'mode'})) {
2811: if ($in{'mode'} eq 'modifyuser') {
2812: $fsyscheck = '';
2813: }
2814: }
1.586 raeburn 2815: } else {
2816: $result = &mt('Currently Filesystem Authenticated.');
2817: return $result;
2818: }
2819: }
2820: } else {
2821: if ($authnum == 1) {
1.784 bisitz 2822: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2823: }
2824: }
2825: if (!$can_assign{'fsys'}) {
2826: return;
1.587 raeburn 2827: } elsif ($authtype eq '') {
1.591 raeburn 2828: if (defined($in{'mode'})) {
1.587 raeburn 2829: if ($in{'mode'} eq 'modifycourse') {
2830: if ($authnum == 1) {
1.1104 raeburn 2831: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2832: }
2833: }
2834: }
1.586 raeburn 2835: }
2836: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2837: if ($authtype eq '') {
2838: $authtype = '<input type="radio" name="login" value="fsys" '.
2839: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2840: $jscall.'" />';
2841: }
2842: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2843: ' onchange="'.$jscall.'" />';
2844: $result = &mt
1.144 matthew 2845: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2846: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2847: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2848: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2849: 'onchange="'.$jscall.'" />');
1.32 matthew 2850: return $result;
2851: }
2852:
1.586 raeburn 2853: sub get_assignable_auth {
2854: my ($dom) = @_;
2855: if ($dom eq '') {
2856: $dom = $env{'request.role.domain'};
2857: }
2858: my %can_assign = (
2859: krb4 => 1,
2860: krb5 => 1,
2861: int => 1,
2862: loc => 1,
2863: );
2864: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2865: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2866: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2867: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2868: my $context;
2869: if ($env{'request.role'} =~ /^au/) {
2870: $context = 'author';
2871: } elsif ($env{'request.role'} =~ /^dc/) {
2872: $context = 'domain';
2873: } elsif ($env{'request.course.id'}) {
2874: $context = 'course';
2875: }
2876: if ($context) {
2877: if (ref($authhash->{$context}) eq 'HASH') {
2878: %can_assign = %{$authhash->{$context}};
2879: }
2880: }
2881: }
2882: }
2883: my $authnum = 0;
2884: foreach my $key (keys(%can_assign)) {
2885: if ($can_assign{$key}) {
2886: $authnum ++;
2887: }
2888: }
2889: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2890: $authnum --;
2891: }
2892: return ($authnum,%can_assign);
2893: }
2894:
1.80 albertel 2895: ###############################################################
2896: ## Get Kerberos Defaults for Domain ##
2897: ###############################################################
2898: ##
2899: ## Returns default kerberos version and an associated argument
2900: ## as listed in file domain.tab. If not listed, provides
2901: ## appropriate default domain and kerberos version.
2902: ##
2903: #-------------------------------------------
2904:
2905: =pod
2906:
1.648 raeburn 2907: =item * &get_kerberos_defaults()
1.80 albertel 2908:
2909: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2910: version and domain. If not found, it defaults to version 4 and the
2911: domain of the server.
1.80 albertel 2912:
1.648 raeburn 2913: =over 4
2914:
1.80 albertel 2915: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2916:
1.648 raeburn 2917: =back
2918:
2919: =back
2920:
1.80 albertel 2921: =cut
2922:
2923: #-------------------------------------------
2924: sub get_kerberos_defaults {
2925: my $domain=shift;
1.641 raeburn 2926: my ($krbdef,$krbdefdom);
2927: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2928: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2929: $krbdef = $domdefaults{'auth_def'};
2930: $krbdefdom = $domdefaults{'auth_arg_def'};
2931: } else {
1.80 albertel 2932: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2933: my $krbdefdom=$1;
2934: $krbdefdom=~tr/a-z/A-Z/;
2935: $krbdef = "krb4";
2936: }
2937: return ($krbdef,$krbdefdom);
2938: }
1.112 bowersj2 2939:
1.32 matthew 2940:
1.46 matthew 2941: ###############################################################
2942: ## Thesaurus Functions ##
2943: ###############################################################
1.20 www 2944:
1.46 matthew 2945: =pod
1.20 www 2946:
1.112 bowersj2 2947: =head1 Thesaurus Functions
2948:
2949: =over 4
2950:
1.648 raeburn 2951: =item * &initialize_keywords()
1.46 matthew 2952:
2953: Initializes the package variable %Keywords if it is empty. Uses the
2954: package variable $thesaurus_db_file.
2955:
2956: =cut
2957:
2958: ###################################################
2959:
2960: sub initialize_keywords {
2961: return 1 if (scalar keys(%Keywords));
2962: # If we are here, %Keywords is empty, so fill it up
2963: # Make sure the file we need exists...
2964: if (! -e $thesaurus_db_file) {
2965: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2966: " failed because it does not exist");
2967: return 0;
2968: }
2969: # Set up the hash as a database
2970: my %thesaurus_db;
2971: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2972: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2973: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2974: $thesaurus_db_file);
2975: return 0;
2976: }
2977: # Get the average number of appearances of a word.
2978: my $avecount = $thesaurus_db{'average.count'};
2979: # Put keywords (those that appear > average) into %Keywords
2980: while (my ($word,$data)=each (%thesaurus_db)) {
2981: my ($count,undef) = split /:/,$data;
2982: $Keywords{$word}++ if ($count > $avecount);
2983: }
2984: untie %thesaurus_db;
2985: # Remove special values from %Keywords.
1.356 albertel 2986: foreach my $value ('total.count','average.count') {
2987: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2988: }
1.46 matthew 2989: return 1;
2990: }
2991:
2992: ###################################################
2993:
2994: =pod
2995:
1.648 raeburn 2996: =item * &keyword($word)
1.46 matthew 2997:
2998: Returns true if $word is a keyword. A keyword is a word that appears more
2999: than the average number of times in the thesaurus database. Calls
3000: &initialize_keywords
3001:
3002: =cut
3003:
3004: ###################################################
1.20 www 3005:
3006: sub keyword {
1.46 matthew 3007: return if (!&initialize_keywords());
3008: my $word=lc(shift());
3009: $word=~s/\W//g;
3010: return exists($Keywords{$word});
1.20 www 3011: }
1.46 matthew 3012:
3013: ###############################################################
3014:
3015: =pod
1.20 www 3016:
1.648 raeburn 3017: =item * &get_related_words()
1.46 matthew 3018:
1.160 matthew 3019: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3020: an array of words. If the keyword is not in the thesaurus, an empty array
3021: will be returned. The order of the words returned is determined by the
3022: database which holds them.
3023:
3024: Uses global $thesaurus_db_file.
3025:
1.1057 foxr 3026:
1.46 matthew 3027: =cut
3028:
3029: ###############################################################
3030: sub get_related_words {
3031: my $keyword = shift;
3032: my %thesaurus_db;
3033: if (! -e $thesaurus_db_file) {
3034: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3035: "failed because the file does not exist");
3036: return ();
3037: }
3038: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3039: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3040: return ();
3041: }
3042: my @Words=();
1.429 www 3043: my $count=0;
1.46 matthew 3044: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3045: # The first element is the number of times
3046: # the word appears. We do not need it now.
1.429 www 3047: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3048: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3049: my $threshold=$mostfrequentcount/10;
3050: foreach my $possibleword (@RelatedWords) {
3051: my ($word,$wordcount)=split(/\,/,$possibleword);
3052: if ($wordcount>$threshold) {
3053: push(@Words,$word);
3054: $count++;
3055: if ($count>10) { last; }
3056: }
1.20 www 3057: }
3058: }
1.46 matthew 3059: untie %thesaurus_db;
3060: return @Words;
1.14 harris41 3061: }
1.1090 foxr 3062: ###############################################################
3063: #
3064: # Spell checking
3065: #
3066:
3067: =pod
3068:
3069: =head1 Spell checking
3070:
3071: =over 4
3072:
3073: =item * &check_spelling($wordlist $language)
3074:
3075: Takes a string containing words and feeds it to an external
3076: spellcheck program via a pipeline. Returns a string containing
3077: them mis-spelled words.
3078:
3079: Parameters:
3080:
3081: =over 4
3082:
3083: =item - $wordlist
3084:
3085: String that will be fed into the spellcheck program.
3086:
3087: =item - $language
3088:
3089: Language string that specifies the language for which the spell
3090: check will be performed.
3091:
3092: =back
3093:
3094: =back
3095:
3096: Note: This sub assumes that aspell is installed.
3097:
3098:
3099: =cut
3100:
1.46 matthew 3101:
1.112 bowersj2 3102: =pod
3103:
3104: =back
3105:
3106: =cut
1.61 www 3107:
1.1090 foxr 3108: sub check_spelling {
3109: my ($wordlist, $language) = @_;
1.1091 foxr 3110: my @misspellings;
3111:
3112: # Generate the speller and set the langauge.
3113: # if explicitly selected:
1.1090 foxr 3114:
1.1091 foxr 3115: my $speller = Text::Aspell->new;
1.1090 foxr 3116: if ($language) {
1.1091 foxr 3117: $speller->set_option('lang', $language);
1.1090 foxr 3118: }
3119:
1.1091 foxr 3120: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3121:
1.1091 foxr 3122: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3123:
1.1091 foxr 3124: foreach my $word (@words) {
3125: if(! $speller->check($word)) {
3126: push(@misspellings, $word);
1.1090 foxr 3127: }
3128: }
1.1091 foxr 3129: return join(' ', @misspellings);
3130:
1.1090 foxr 3131: }
3132:
1.61 www 3133: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3134: =pod
3135:
1.112 bowersj2 3136: =head1 User Name Functions
3137:
3138: =over 4
3139:
1.648 raeburn 3140: =item * &plainname($uname,$udom,$first)
1.81 albertel 3141:
1.112 bowersj2 3142: Takes a users logon name and returns it as a string in
1.226 albertel 3143: "first middle last generation" form
3144: if $first is set to 'lastname' then it returns it as
3145: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3146:
3147: =cut
1.61 www 3148:
1.295 www 3149:
1.81 albertel 3150: ###############################################################
1.61 www 3151: sub plainname {
1.226 albertel 3152: my ($uname,$udom,$first)=@_;
1.537 albertel 3153: return if (!defined($uname) || !defined($udom));
1.295 www 3154: my %names=&getnames($uname,$udom);
1.226 albertel 3155: my $name=&Apache::lonnet::format_name($names{'firstname'},
3156: $names{'middlename'},
3157: $names{'lastname'},
3158: $names{'generation'},$first);
3159: $name=~s/^\s+//;
1.62 www 3160: $name=~s/\s+$//;
3161: $name=~s/\s+/ /g;
1.353 albertel 3162: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3163: return $name;
1.61 www 3164: }
1.66 www 3165:
3166: # -------------------------------------------------------------------- Nickname
1.81 albertel 3167: =pod
3168:
1.648 raeburn 3169: =item * &nickname($uname,$udom)
1.81 albertel 3170:
3171: Gets a users name and returns it as a string as
3172:
3173: ""nickname""
1.66 www 3174:
1.81 albertel 3175: if the user has a nickname or
3176:
3177: "first middle last generation"
3178:
3179: if the user does not
3180:
3181: =cut
1.66 www 3182:
3183: sub nickname {
3184: my ($uname,$udom)=@_;
1.537 albertel 3185: return if (!defined($uname) || !defined($udom));
1.295 www 3186: my %names=&getnames($uname,$udom);
1.68 albertel 3187: my $name=$names{'nickname'};
1.66 www 3188: if ($name) {
3189: $name='"'.$name.'"';
3190: } else {
3191: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3192: $names{'lastname'}.' '.$names{'generation'};
3193: $name=~s/\s+$//;
3194: $name=~s/\s+/ /g;
3195: }
3196: return $name;
3197: }
3198:
1.295 www 3199: sub getnames {
3200: my ($uname,$udom)=@_;
1.537 albertel 3201: return if (!defined($uname) || !defined($udom));
1.433 albertel 3202: if ($udom eq 'public' && $uname eq 'public') {
3203: return ('lastname' => &mt('Public'));
3204: }
1.295 www 3205: my $id=$uname.':'.$udom;
3206: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3207: if ($cached) {
3208: return %{$names};
3209: } else {
3210: my %loadnames=&Apache::lonnet::get('environment',
3211: ['firstname','middlename','lastname','generation','nickname'],
3212: $udom,$uname);
3213: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3214: return %loadnames;
3215: }
3216: }
1.61 www 3217:
1.542 raeburn 3218: # -------------------------------------------------------------------- getemails
1.648 raeburn 3219:
1.542 raeburn 3220: =pod
3221:
1.648 raeburn 3222: =item * &getemails($uname,$udom)
1.542 raeburn 3223:
3224: Gets a user's email information and returns it as a hash with keys:
3225: notification, critnotification, permanentemail
3226:
3227: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3228: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3229:
1.648 raeburn 3230:
1.542 raeburn 3231: =cut
3232:
1.648 raeburn 3233:
1.466 albertel 3234: sub getemails {
3235: my ($uname,$udom)=@_;
3236: if ($udom eq 'public' && $uname eq 'public') {
3237: return;
3238: }
1.467 www 3239: if (!$udom) { $udom=$env{'user.domain'}; }
3240: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3241: my $id=$uname.':'.$udom;
3242: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3243: if ($cached) {
3244: return %{$names};
3245: } else {
3246: my %loadnames=&Apache::lonnet::get('environment',
3247: ['notification','critnotification',
3248: 'permanentemail'],
3249: $udom,$uname);
3250: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3251: return %loadnames;
3252: }
3253: }
3254:
1.551 albertel 3255: sub flush_email_cache {
3256: my ($uname,$udom)=@_;
3257: if (!$udom) { $udom =$env{'user.domain'}; }
3258: if (!$uname) { $uname=$env{'user.name'}; }
3259: return if ($udom eq 'public' && $uname eq 'public');
3260: my $id=$uname.':'.$udom;
3261: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3262: }
3263:
1.728 raeburn 3264: # -------------------------------------------------------------------- getlangs
3265:
3266: =pod
3267:
3268: =item * &getlangs($uname,$udom)
3269:
3270: Gets a user's language preference and returns it as a hash with key:
3271: language.
3272:
3273: =cut
3274:
3275:
3276: sub getlangs {
3277: my ($uname,$udom) = @_;
3278: if (!$udom) { $udom =$env{'user.domain'}; }
3279: if (!$uname) { $uname=$env{'user.name'}; }
3280: my $id=$uname.':'.$udom;
3281: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3282: if ($cached) {
3283: return %{$langs};
3284: } else {
3285: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3286: $udom,$uname);
3287: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3288: return %loadlangs;
3289: }
3290: }
3291:
3292: sub flush_langs_cache {
3293: my ($uname,$udom)=@_;
3294: if (!$udom) { $udom =$env{'user.domain'}; }
3295: if (!$uname) { $uname=$env{'user.name'}; }
3296: return if ($udom eq 'public' && $uname eq 'public');
3297: my $id=$uname.':'.$udom;
3298: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3299: }
3300:
1.61 www 3301: # ------------------------------------------------------------------ Screenname
1.81 albertel 3302:
3303: =pod
3304:
1.648 raeburn 3305: =item * &screenname($uname,$udom)
1.81 albertel 3306:
3307: Gets a users screenname and returns it as a string
3308:
3309: =cut
1.61 www 3310:
3311: sub screenname {
3312: my ($uname,$udom)=@_;
1.258 albertel 3313: if ($uname eq $env{'user.name'} &&
3314: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3315: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3316: return $names{'screenname'};
1.62 www 3317: }
3318:
1.212 albertel 3319:
1.802 bisitz 3320: # ------------------------------------------------------------- Confirm Wrapper
3321: =pod
3322:
3323: =item confirmwrapper
3324:
3325: Wrap messages about completion of operation in box
3326:
3327: =cut
3328:
3329: sub confirmwrapper {
3330: my ($message)=@_;
3331: if ($message) {
3332: return "\n".'<div class="LC_confirm_box">'."\n"
3333: .$message."\n"
3334: .'</div>'."\n";
3335: } else {
3336: return $message;
3337: }
3338: }
3339:
1.62 www 3340: # ------------------------------------------------------------- Message Wrapper
3341:
3342: sub messagewrapper {
1.369 www 3343: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3344: return
1.441 albertel 3345: '<a href="/adm/email?compose=individual&'.
3346: 'recname='.$username.'&recdom='.$domain.
3347: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3348: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3349: }
1.802 bisitz 3350:
1.74 www 3351: # --------------------------------------------------------------- Notes Wrapper
3352:
3353: sub noteswrapper {
3354: my ($link,$un,$do)=@_;
3355: return
1.896 amueller 3356: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3357: }
1.802 bisitz 3358:
1.62 www 3359: # ------------------------------------------------------------- Aboutme Wrapper
3360:
3361: sub aboutmewrapper {
1.1070 raeburn 3362: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3363: if (!defined($username) && !defined($domain)) {
3364: return;
3365: }
1.1096 raeburn 3366: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3367: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3368: }
3369:
3370: # ------------------------------------------------------------ Syllabus Wrapper
3371:
3372: sub syllabuswrapper {
1.707 bisitz 3373: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3374: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3375: }
1.14 harris41 3376:
1.802 bisitz 3377: # -----------------------------------------------------------------------------
3378:
1.208 matthew 3379: sub track_student_link {
1.887 raeburn 3380: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3381: my $link ="/adm/trackstudent?";
1.208 matthew 3382: my $title = 'View recent activity';
3383: if (defined($sname) && $sname !~ /^\s*$/ &&
3384: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3385: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3386: $title .= ' of this student';
1.268 albertel 3387: }
1.208 matthew 3388: if (defined($target) && $target !~ /^\s*$/) {
3389: $target = qq{target="$target"};
3390: } else {
3391: $target = '';
3392: }
1.268 albertel 3393: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3394: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3395: $title = &mt($title);
3396: $linktext = &mt($linktext);
1.448 albertel 3397: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3398: &help_open_topic('View_recent_activity');
1.208 matthew 3399: }
3400:
1.781 raeburn 3401: sub slot_reservations_link {
3402: my ($linktext,$sname,$sdom,$target) = @_;
3403: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3404: my $title = 'View slot reservation history';
3405: if (defined($sname) && $sname !~ /^\s*$/ &&
3406: defined($sdom) && $sdom !~ /^\s*$/) {
3407: $link .= "&uname=$sname&udom=$sdom";
3408: $title .= ' of this student';
3409: }
3410: if (defined($target) && $target !~ /^\s*$/) {
3411: $target = qq{target="$target"};
3412: } else {
3413: $target = '';
3414: }
3415: $title = &mt($title);
3416: $linktext = &mt($linktext);
3417: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3418: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3419:
3420: }
3421:
1.508 www 3422: # ===================================================== Display a student photo
3423:
3424:
1.509 albertel 3425: sub student_image_tag {
1.508 www 3426: my ($domain,$user)=@_;
3427: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3428: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3429: return '<img src="'.$imgsrc.'" align="right" />';
3430: } else {
3431: return '';
3432: }
3433: }
3434:
1.112 bowersj2 3435: =pod
3436:
3437: =back
3438:
3439: =head1 Access .tab File Data
3440:
3441: =over 4
3442:
1.648 raeburn 3443: =item * &languageids()
1.112 bowersj2 3444:
3445: returns list of all language ids
3446:
3447: =cut
3448:
1.14 harris41 3449: sub languageids {
1.16 harris41 3450: return sort(keys(%language));
1.14 harris41 3451: }
3452:
1.112 bowersj2 3453: =pod
3454:
1.648 raeburn 3455: =item * &languagedescription()
1.112 bowersj2 3456:
3457: returns description of a specified language id
3458:
3459: =cut
3460:
1.14 harris41 3461: sub languagedescription {
1.125 www 3462: my $code=shift;
3463: return ($supported_language{$code}?'* ':'').
3464: $language{$code}.
1.126 www 3465: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3466: }
3467:
1.1048 foxr 3468: =pod
3469:
3470: =item * &plainlanguagedescription
3471:
3472: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3473: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3474:
3475: =cut
3476:
1.145 www 3477: sub plainlanguagedescription {
3478: my $code=shift;
3479: return $language{$code};
3480: }
3481:
1.1048 foxr 3482: =pod
3483:
3484: =item * &supportedlanguagecode
3485:
3486: Returns the supported language code (e.g. sptutf maps to pt) given a language
3487: code.
3488:
3489: =cut
3490:
1.145 www 3491: sub supportedlanguagecode {
3492: my $code=shift;
3493: return $supported_language{$code};
1.97 www 3494: }
3495:
1.112 bowersj2 3496: =pod
3497:
1.1048 foxr 3498: =item * &latexlanguage()
3499:
3500: Given a language key code returns the correspondnig language to use
3501: to select the correct hyphenation on LaTeX printouts. This is undef if there
3502: is no supported hyphenation for the language code.
3503:
3504: =cut
3505:
3506: sub latexlanguage {
3507: my $code = shift;
3508: return $latex_language{$code};
3509: }
3510:
3511: =pod
3512:
3513: =item * &latexhyphenation()
3514:
3515: Same as above but what's supplied is the language as it might be stored
3516: in the metadata.
3517:
3518: =cut
3519:
3520: sub latexhyphenation {
3521: my $key = shift;
3522: return $latex_language_bykey{$key};
3523: }
3524:
3525: =pod
3526:
1.648 raeburn 3527: =item * ©rightids()
1.112 bowersj2 3528:
3529: returns list of all copyrights
3530:
3531: =cut
3532:
3533: sub copyrightids {
3534: return sort(keys(%cprtag));
3535: }
3536:
3537: =pod
3538:
1.648 raeburn 3539: =item * ©rightdescription()
1.112 bowersj2 3540:
3541: returns description of a specified copyright id
3542:
3543: =cut
3544:
3545: sub copyrightdescription {
1.166 www 3546: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3547: }
1.197 matthew 3548:
3549: =pod
3550:
1.648 raeburn 3551: =item * &source_copyrightids()
1.192 taceyjo1 3552:
3553: returns list of all source copyrights
3554:
3555: =cut
3556:
3557: sub source_copyrightids {
3558: return sort(keys(%scprtag));
3559: }
3560:
3561: =pod
3562:
1.648 raeburn 3563: =item * &source_copyrightdescription()
1.192 taceyjo1 3564:
3565: returns description of a specified source copyright id
3566:
3567: =cut
3568:
3569: sub source_copyrightdescription {
3570: return &mt($scprtag{shift(@_)});
3571: }
1.112 bowersj2 3572:
3573: =pod
3574:
1.648 raeburn 3575: =item * &filecategories()
1.112 bowersj2 3576:
3577: returns list of all file categories
3578:
3579: =cut
3580:
3581: sub filecategories {
3582: return sort(keys(%category_extensions));
3583: }
3584:
3585: =pod
3586:
1.648 raeburn 3587: =item * &filecategorytypes()
1.112 bowersj2 3588:
3589: returns list of file types belonging to a given file
3590: category
3591:
3592: =cut
3593:
3594: sub filecategorytypes {
1.356 albertel 3595: my ($cat) = @_;
3596: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3597: }
3598:
3599: =pod
3600:
1.648 raeburn 3601: =item * &fileembstyle()
1.112 bowersj2 3602:
3603: returns embedding style for a specified file type
3604:
3605: =cut
3606:
3607: sub fileembstyle {
3608: return $fe{lc(shift(@_))};
1.169 www 3609: }
3610:
1.351 www 3611: sub filemimetype {
3612: return $fm{lc(shift(@_))};
3613: }
3614:
1.169 www 3615:
3616: sub filecategoryselect {
3617: my ($name,$value)=@_;
1.189 matthew 3618: return &select_form($value,$name,
1.970 raeburn 3619: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3620: }
3621:
3622: =pod
3623:
1.648 raeburn 3624: =item * &filedescription()
1.112 bowersj2 3625:
3626: returns description for a specified file type
3627:
3628: =cut
3629:
3630: sub filedescription {
1.188 matthew 3631: my $file_description = $fd{lc(shift())};
3632: $file_description =~ s:([\[\]]):~$1:g;
3633: return &mt($file_description);
1.112 bowersj2 3634: }
3635:
3636: =pod
3637:
1.648 raeburn 3638: =item * &filedescriptionex()
1.112 bowersj2 3639:
3640: returns description for a specified file type with
3641: extra formatting
3642:
3643: =cut
3644:
3645: sub filedescriptionex {
3646: my $ex=shift;
1.188 matthew 3647: my $file_description = $fd{lc($ex)};
3648: $file_description =~ s:([\[\]]):~$1:g;
3649: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3650: }
3651:
3652: # End of .tab access
3653: =pod
3654:
3655: =back
3656:
3657: =cut
3658:
3659: # ------------------------------------------------------------------ File Types
3660: sub fileextensions {
3661: return sort(keys(%fe));
3662: }
3663:
1.97 www 3664: # ----------------------------------------------------------- Display Languages
3665: # returns a hash with all desired display languages
3666: #
3667:
3668: sub display_languages {
3669: my %languages=();
1.695 raeburn 3670: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3671: $languages{$lang}=1;
1.97 www 3672: }
3673: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3674: if ($env{'form.displaylanguage'}) {
1.356 albertel 3675: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3676: $languages{$lang}=1;
1.97 www 3677: }
3678: }
3679: return %languages;
1.14 harris41 3680: }
3681:
1.582 albertel 3682: sub languages {
3683: my ($possible_langs) = @_;
1.695 raeburn 3684: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3685: if (!ref($possible_langs)) {
3686: if( wantarray ) {
3687: return @preferred_langs;
3688: } else {
3689: return $preferred_langs[0];
3690: }
3691: }
3692: my %possibilities = map { $_ => 1 } (@$possible_langs);
3693: my @preferred_possibilities;
3694: foreach my $preferred_lang (@preferred_langs) {
3695: if (exists($possibilities{$preferred_lang})) {
3696: push(@preferred_possibilities, $preferred_lang);
3697: }
3698: }
3699: if( wantarray ) {
3700: return @preferred_possibilities;
3701: }
3702: return $preferred_possibilities[0];
3703: }
3704:
1.742 raeburn 3705: sub user_lang {
3706: my ($touname,$toudom,$fromcid) = @_;
3707: my @userlangs;
3708: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3709: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3710: $env{'course.'.$fromcid.'.languages'}));
3711: } else {
3712: my %langhash = &getlangs($touname,$toudom);
3713: if ($langhash{'languages'} ne '') {
3714: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3715: } else {
3716: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3717: if ($domdefs{'lang_def'} ne '') {
3718: @userlangs = ($domdefs{'lang_def'});
3719: }
3720: }
3721: }
3722: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3723: my $user_lh = Apache::localize->get_handle(@languages);
3724: return $user_lh;
3725: }
3726:
3727:
1.112 bowersj2 3728: ###############################################################
3729: ## Student Answer Attempts ##
3730: ###############################################################
3731:
3732: =pod
3733:
3734: =head1 Alternate Problem Views
3735:
3736: =over 4
3737:
1.648 raeburn 3738: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3739: $getattempt, $regexp, $gradesub)
3740:
3741: Return string with previous attempt on problem. Arguments:
3742:
3743: =over 4
3744:
3745: =item * $symb: Problem, including path
3746:
3747: =item * $username: username of the desired student
3748:
3749: =item * $domain: domain of the desired student
1.14 harris41 3750:
1.112 bowersj2 3751: =item * $course: Course ID
1.14 harris41 3752:
1.112 bowersj2 3753: =item * $getattempt: Leave blank for all attempts, otherwise put
3754: something
1.14 harris41 3755:
1.112 bowersj2 3756: =item * $regexp: if string matches this regexp, the string will be
3757: sent to $gradesub
1.14 harris41 3758:
1.112 bowersj2 3759: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3760:
1.112 bowersj2 3761: =back
1.14 harris41 3762:
1.112 bowersj2 3763: The output string is a table containing all desired attempts, if any.
1.16 harris41 3764:
1.112 bowersj2 3765: =cut
1.1 albertel 3766:
3767: sub get_previous_attempt {
1.43 ng 3768: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3769: my $prevattempts='';
1.43 ng 3770: no strict 'refs';
1.1 albertel 3771: if ($symb) {
1.3 albertel 3772: my (%returnhash)=
3773: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3774: if ($returnhash{'version'}) {
3775: my %lasthash=();
3776: my $version;
3777: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3778: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3779: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3780: }
1.1 albertel 3781: }
1.596 albertel 3782: $prevattempts=&start_data_table().&start_data_table_header_row();
3783: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3784: my (%typeparts,%lasthidden);
1.945 raeburn 3785: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3786: foreach my $key (sort(keys(%lasthash))) {
3787: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3788: if ($#parts > 0) {
1.31 albertel 3789: my $data=$parts[-1];
1.989 raeburn 3790: next if ($data eq 'foilorder');
1.31 albertel 3791: pop(@parts);
1.1010 www 3792: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3793: if ($data eq 'type') {
3794: unless ($showsurv) {
3795: my $id = join(',',@parts);
3796: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3797: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3798: $lasthidden{$ign.'.'.$id} = 1;
3799: }
1.945 raeburn 3800: }
1.1010 www 3801: }
1.31 albertel 3802: } else {
1.41 ng 3803: if ($#parts == 0) {
3804: $prevattempts.='<th>'.$parts[0].'</th>';
3805: } else {
3806: $prevattempts.='<th>'.$ign.'</th>';
3807: }
1.31 albertel 3808: }
1.16 harris41 3809: }
1.596 albertel 3810: $prevattempts.=&end_data_table_header_row();
1.40 ng 3811: if ($getattempt eq '') {
3812: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3813: my @hidden;
3814: if (%typeparts) {
3815: foreach my $id (keys(%typeparts)) {
3816: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3817: push(@hidden,$id);
3818: }
3819: }
3820: }
3821: $prevattempts.=&start_data_table_row().
3822: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3823: if (@hidden) {
3824: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3825: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3826: my $hide;
3827: foreach my $id (@hidden) {
3828: if ($key =~ /^\Q$id\E/) {
3829: $hide = 1;
3830: last;
3831: }
3832: }
3833: if ($hide) {
3834: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3835: if (($data eq 'award') || ($data eq 'awarddetail')) {
3836: my $value = &format_previous_attempt_value($key,
3837: $returnhash{$version.':'.$key});
3838: $prevattempts.='<td>'.$value.' </td>';
3839: } else {
3840: $prevattempts.='<td> </td>';
3841: }
3842: } else {
3843: if ($key =~ /\./) {
3844: my $value = &format_previous_attempt_value($key,
3845: $returnhash{$version.':'.$key});
3846: $prevattempts.='<td>'.$value.' </td>';
3847: } else {
3848: $prevattempts.='<td> </td>';
3849: }
3850: }
3851: }
3852: } else {
3853: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3854: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3855: my $value = &format_previous_attempt_value($key,
3856: $returnhash{$version.':'.$key});
3857: $prevattempts.='<td>'.$value.' </td>';
3858: }
3859: }
3860: $prevattempts.=&end_data_table_row();
1.40 ng 3861: }
1.1 albertel 3862: }
1.945 raeburn 3863: my @currhidden = keys(%lasthidden);
1.596 albertel 3864: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3865: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3866: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3867: if (%typeparts) {
3868: my $hidden;
3869: foreach my $id (@currhidden) {
3870: if ($key =~ /^\Q$id\E/) {
3871: $hidden = 1;
3872: last;
3873: }
3874: }
3875: if ($hidden) {
3876: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3877: if (($data eq 'award') || ($data eq 'awarddetail')) {
3878: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3879: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3880: $value = &$gradesub($value);
3881: }
3882: $prevattempts.='<td>'.$value.' </td>';
3883: } else {
3884: $prevattempts.='<td> </td>';
3885: }
3886: } else {
3887: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3888: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3889: $value = &$gradesub($value);
3890: }
3891: $prevattempts.='<td>'.$value.' </td>';
3892: }
3893: } else {
3894: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3895: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3896: $value = &$gradesub($value);
3897: }
3898: $prevattempts.='<td>'.$value.' </td>';
3899: }
1.16 harris41 3900: }
1.596 albertel 3901: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3902: } else {
1.596 albertel 3903: $prevattempts=
3904: &start_data_table().&start_data_table_row().
3905: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3906: &end_data_table_row().&end_data_table();
1.1 albertel 3907: }
3908: } else {
1.596 albertel 3909: $prevattempts=
3910: &start_data_table().&start_data_table_row().
3911: '<td>'.&mt('No data.').'</td>'.
3912: &end_data_table_row().&end_data_table();
1.1 albertel 3913: }
1.10 albertel 3914: }
3915:
1.581 albertel 3916: sub format_previous_attempt_value {
3917: my ($key,$value) = @_;
1.1011 www 3918: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3919: $value = &Apache::lonlocal::locallocaltime($value);
3920: } elsif (ref($value) eq 'ARRAY') {
3921: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3922: } elsif ($key =~ /answerstring$/) {
3923: my %answers = &Apache::lonnet::str2hash($value);
3924: my @anskeys = sort(keys(%answers));
3925: if (@anskeys == 1) {
3926: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3927: if ($answer =~ m{\0}) {
3928: $answer =~ s{\0}{,}g;
1.988 raeburn 3929: }
3930: my $tag_internal_answer_name = 'INTERNAL';
3931: if ($anskeys[0] eq $tag_internal_answer_name) {
3932: $value = $answer;
3933: } else {
3934: $value = $anskeys[0].'='.$answer;
3935: }
3936: } else {
3937: foreach my $ans (@anskeys) {
3938: my $answer = $answers{$ans};
1.1001 raeburn 3939: if ($answer =~ m{\0}) {
3940: $answer =~ s{\0}{,}g;
1.988 raeburn 3941: }
3942: $value .= $ans.'='.$answer.'<br />';;
3943: }
3944: }
1.581 albertel 3945: } else {
3946: $value = &unescape($value);
3947: }
3948: return $value;
3949: }
3950:
3951:
1.107 albertel 3952: sub relative_to_absolute {
3953: my ($url,$output)=@_;
3954: my $parser=HTML::TokeParser->new(\$output);
3955: my $token;
3956: my $thisdir=$url;
3957: my @rlinks=();
3958: while ($token=$parser->get_token) {
3959: if ($token->[0] eq 'S') {
3960: if ($token->[1] eq 'a') {
3961: if ($token->[2]->{'href'}) {
3962: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3963: }
3964: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3965: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3966: } elsif ($token->[1] eq 'base') {
3967: $thisdir=$token->[2]->{'href'};
3968: }
3969: }
3970: }
3971: $thisdir=~s-/[^/]*$--;
1.356 albertel 3972: foreach my $link (@rlinks) {
1.726 raeburn 3973: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3974: ($link=~/^\//) ||
3975: ($link=~/^javascript:/i) ||
3976: ($link=~/^mailto:/i) ||
3977: ($link=~/^\#/)) {
3978: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3979: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3980: }
3981: }
3982: # -------------------------------------------------- Deal with Applet codebases
3983: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3984: return $output;
3985: }
3986:
1.112 bowersj2 3987: =pod
3988:
1.648 raeburn 3989: =item * &get_student_view()
1.112 bowersj2 3990:
3991: show a snapshot of what student was looking at
3992:
3993: =cut
3994:
1.10 albertel 3995: sub get_student_view {
1.186 albertel 3996: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3997: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3998: my (%form);
1.10 albertel 3999: my @elements=('symb','courseid','domain','username');
4000: foreach my $element (@elements) {
1.186 albertel 4001: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4002: }
1.186 albertel 4003: if (defined($moreenv)) {
4004: %form=(%form,%{$moreenv});
4005: }
1.236 albertel 4006: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4007: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4008: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4009: $userview=~s/\<body[^\>]*\>//gi;
4010: $userview=~s/\<\/body\>//gi;
4011: $userview=~s/\<html\>//gi;
4012: $userview=~s/\<\/html\>//gi;
4013: $userview=~s/\<head\>//gi;
4014: $userview=~s/\<\/head\>//gi;
4015: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4016: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4017: if (wantarray) {
4018: return ($userview,$response);
4019: } else {
4020: return $userview;
4021: }
4022: }
4023:
4024: sub get_student_view_with_retries {
4025: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4026:
4027: my $ok = 0; # True if we got a good response.
4028: my $content;
4029: my $response;
4030:
4031: # Try to get the student_view done. within the retries count:
4032:
4033: do {
4034: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4035: $ok = $response->is_success;
4036: if (!$ok) {
4037: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4038: }
4039: $retries--;
4040: } while (!$ok && ($retries > 0));
4041:
4042: if (!$ok) {
4043: $content = ''; # On error return an empty content.
4044: }
1.651 www 4045: if (wantarray) {
4046: return ($content, $response);
4047: } else {
4048: return $content;
4049: }
1.11 albertel 4050: }
4051:
1.112 bowersj2 4052: =pod
4053:
1.648 raeburn 4054: =item * &get_student_answers()
1.112 bowersj2 4055:
4056: show a snapshot of how student was answering problem
4057:
4058: =cut
4059:
1.11 albertel 4060: sub get_student_answers {
1.100 sakharuk 4061: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4062: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4063: my (%moreenv);
1.11 albertel 4064: my @elements=('symb','courseid','domain','username');
4065: foreach my $element (@elements) {
1.186 albertel 4066: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4067: }
1.186 albertel 4068: $moreenv{'grade_target'}='answer';
4069: %moreenv=(%form,%moreenv);
1.497 raeburn 4070: $feedurl = &Apache::lonnet::clutter($feedurl);
4071: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4072: return $userview;
1.1 albertel 4073: }
1.116 albertel 4074:
4075: =pod
4076:
4077: =item * &submlink()
4078:
1.242 albertel 4079: Inputs: $text $uname $udom $symb $target
1.116 albertel 4080:
4081: Returns: A link to grades.pm such as to see the SUBM view of a student
4082:
4083: =cut
4084:
4085: ###############################################
4086: sub submlink {
1.242 albertel 4087: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4088: if (!($uname && $udom)) {
4089: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4090: &Apache::lonnet::whichuser($symb);
1.116 albertel 4091: if (!$symb) { $symb=$cursymb; }
4092: }
1.254 matthew 4093: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4094: $symb=&escape($symb);
1.960 bisitz 4095: if ($target) { $target=" target=\"$target\""; }
4096: return
4097: '<a href="/adm/grades?command=submission'.
4098: '&symb='.$symb.
4099: '&student='.$uname.
4100: '&userdom='.$udom.'"'.
4101: $target.'>'.$text.'</a>';
1.242 albertel 4102: }
4103: ##############################################
4104:
4105: =pod
4106:
4107: =item * &pgrdlink()
4108:
4109: Inputs: $text $uname $udom $symb $target
4110:
4111: Returns: A link to grades.pm such as to see the PGRD view of a student
4112:
4113: =cut
4114:
4115: ###############################################
4116: sub pgrdlink {
4117: my $link=&submlink(@_);
4118: $link=~s/(&command=submission)/$1&showgrading=yes/;
4119: return $link;
4120: }
4121: ##############################################
4122:
4123: =pod
4124:
4125: =item * &pprmlink()
4126:
4127: Inputs: $text $uname $udom $symb $target
4128:
4129: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4130: student and a specific resource
1.242 albertel 4131:
4132: =cut
4133:
4134: ###############################################
4135: sub pprmlink {
4136: my ($text,$uname,$udom,$symb,$target)=@_;
4137: if (!($uname && $udom)) {
4138: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4139: &Apache::lonnet::whichuser($symb);
1.242 albertel 4140: if (!$symb) { $symb=$cursymb; }
4141: }
1.254 matthew 4142: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4143: $symb=&escape($symb);
1.242 albertel 4144: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4145: return '<a href="/adm/parmset?command=set&'.
4146: 'symb='.$symb.'&uname='.$uname.
4147: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4148: }
4149: ##############################################
1.37 matthew 4150:
1.112 bowersj2 4151: =pod
4152:
4153: =back
4154:
4155: =cut
4156:
1.37 matthew 4157: ###############################################
1.51 www 4158:
4159:
4160: sub timehash {
1.687 raeburn 4161: my ($thistime) = @_;
4162: my $timezone = &Apache::lonlocal::gettimezone();
4163: my $dt = DateTime->from_epoch(epoch => $thistime)
4164: ->set_time_zone($timezone);
4165: my $wday = $dt->day_of_week();
4166: if ($wday == 7) { $wday = 0; }
4167: return ( 'second' => $dt->second(),
4168: 'minute' => $dt->minute(),
4169: 'hour' => $dt->hour(),
4170: 'day' => $dt->day_of_month(),
4171: 'month' => $dt->month(),
4172: 'year' => $dt->year(),
4173: 'weekday' => $wday,
4174: 'dayyear' => $dt->day_of_year(),
4175: 'dlsav' => $dt->is_dst() );
1.51 www 4176: }
4177:
1.370 www 4178: sub utc_string {
4179: my ($date)=@_;
1.371 www 4180: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4181: }
4182:
1.51 www 4183: sub maketime {
4184: my %th=@_;
1.687 raeburn 4185: my ($epoch_time,$timezone,$dt);
4186: $timezone = &Apache::lonlocal::gettimezone();
4187: eval {
4188: $dt = DateTime->new( year => $th{'year'},
4189: month => $th{'month'},
4190: day => $th{'day'},
4191: hour => $th{'hour'},
4192: minute => $th{'minute'},
4193: second => $th{'second'},
4194: time_zone => $timezone,
4195: );
4196: };
4197: if (!$@) {
4198: $epoch_time = $dt->epoch;
4199: if ($epoch_time) {
4200: return $epoch_time;
4201: }
4202: }
1.51 www 4203: return POSIX::mktime(
4204: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4205: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4206: }
4207:
4208: #########################################
1.51 www 4209:
4210: sub findallcourses {
1.482 raeburn 4211: my ($roles,$uname,$udom) = @_;
1.355 albertel 4212: my %roles;
4213: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4214: my %courses;
1.51 www 4215: my $now=time;
1.482 raeburn 4216: if (!defined($uname)) {
4217: $uname = $env{'user.name'};
4218: }
4219: if (!defined($udom)) {
4220: $udom = $env{'user.domain'};
4221: }
4222: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4223: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4224: if (!%roles) {
4225: %roles = (
4226: cc => 1,
1.907 raeburn 4227: co => 1,
1.482 raeburn 4228: in => 1,
4229: ep => 1,
4230: ta => 1,
4231: cr => 1,
4232: st => 1,
4233: );
4234: }
4235: foreach my $entry (keys(%roleshash)) {
4236: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4237: if ($trole =~ /^cr/) {
4238: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4239: } else {
4240: next if (!exists($roles{$trole}));
4241: }
4242: if ($tend) {
4243: next if ($tend < $now);
4244: }
4245: if ($tstart) {
4246: next if ($tstart > $now);
4247: }
1.1058 raeburn 4248: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4249: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4250: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4251: if ($secpart eq '') {
4252: ($cnum,$role) = split(/_/,$cnumpart);
4253: $sec = 'none';
1.1058 raeburn 4254: $value .= $cnum.'/';
1.482 raeburn 4255: } else {
4256: $cnum = $cnumpart;
4257: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4258: $value .= $cnum.'/'.$sec;
4259: }
4260: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4261: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4262: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4263: }
4264: } else {
4265: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4266: }
1.482 raeburn 4267: }
4268: } else {
4269: foreach my $key (keys(%env)) {
1.483 albertel 4270: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4271: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4272: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4273: next if ($role eq 'ca' || $role eq 'aa');
4274: next if (%roles && !exists($roles{$role}));
4275: my ($starttime,$endtime)=split(/\./,$env{$key});
4276: my $active=1;
4277: if ($starttime) {
4278: if ($now<$starttime) { $active=0; }
4279: }
4280: if ($endtime) {
4281: if ($now>$endtime) { $active=0; }
4282: }
4283: if ($active) {
1.1058 raeburn 4284: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4285: if ($sec eq '') {
4286: $sec = 'none';
1.1058 raeburn 4287: } else {
4288: $value .= $sec;
4289: }
4290: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4291: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4292: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4293: }
4294: } else {
4295: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4296: }
1.474 raeburn 4297: }
4298: }
1.51 www 4299: }
4300: }
1.474 raeburn 4301: return %courses;
1.51 www 4302: }
1.37 matthew 4303:
1.54 www 4304: ###############################################
1.474 raeburn 4305:
4306: sub blockcheck {
1.1062 raeburn 4307: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4308:
4309: if (!defined($udom)) {
4310: $udom = $env{'user.domain'};
4311: }
4312: if (!defined($uname)) {
4313: $uname = $env{'user.name'};
4314: }
4315:
4316: # If uname and udom are for a course, check for blocks in the course.
4317:
4318: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4319: my ($startblock,$endblock,$triggerblock) =
4320: &get_blocks($setters,$activity,$udom,$uname,$url);
4321: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4322: }
1.474 raeburn 4323:
1.502 raeburn 4324: my $startblock = 0;
4325: my $endblock = 0;
1.1062 raeburn 4326: my $triggerblock = '';
1.482 raeburn 4327: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4328:
1.490 raeburn 4329: # If uname is for a user, and activity is course-specific, i.e.,
4330: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4331:
1.490 raeburn 4332: if (($activity eq 'boards' || $activity eq 'chat' ||
4333: $activity eq 'groups') && ($env{'request.course.id'})) {
4334: foreach my $key (keys(%live_courses)) {
4335: if ($key ne $env{'request.course.id'}) {
4336: delete($live_courses{$key});
4337: }
4338: }
4339: }
4340:
4341: my $otheruser = 0;
4342: my %own_courses;
4343: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4344: # Resource belongs to user other than current user.
4345: $otheruser = 1;
4346: # Gather courses for current user
4347: %own_courses =
4348: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4349: }
4350:
4351: # Gather active course roles - course coordinator, instructor,
4352: # exam proctor, ta, student, or custom role.
1.474 raeburn 4353:
4354: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4355: my ($cdom,$cnum);
4356: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4357: $cdom = $env{'course.'.$course.'.domain'};
4358: $cnum = $env{'course.'.$course.'.num'};
4359: } else {
1.490 raeburn 4360: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4361: }
4362: my $no_ownblock = 0;
4363: my $no_userblock = 0;
1.533 raeburn 4364: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4365: # Check if current user has 'evb' priv for this
4366: if (defined($own_courses{$course})) {
4367: foreach my $sec (keys(%{$own_courses{$course}})) {
4368: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4369: if ($sec ne 'none') {
4370: $checkrole .= '/'.$sec;
4371: }
4372: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4373: $no_ownblock = 1;
4374: last;
4375: }
4376: }
4377: }
4378: # if they have 'evb' priv and are currently not playing student
4379: next if (($no_ownblock) &&
4380: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4381: }
1.474 raeburn 4382: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4383: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4384: if ($sec ne 'none') {
1.482 raeburn 4385: $checkrole .= '/'.$sec;
1.474 raeburn 4386: }
1.490 raeburn 4387: if ($otheruser) {
4388: # Resource belongs to user other than current user.
4389: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4390: my (%allroles,%userroles);
4391: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4392: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4393: my ($trole,$tdom,$tnum,$tsec);
4394: if ($entry =~ /^cr/) {
4395: ($trole,$tdom,$tnum,$tsec) =
4396: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4397: } else {
4398: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4399: }
4400: my ($spec,$area,$trest);
4401: $area = '/'.$tdom.'/'.$tnum;
4402: $trest = $tnum;
4403: if ($tsec ne '') {
4404: $area .= '/'.$tsec;
4405: $trest .= '/'.$tsec;
4406: }
4407: $spec = $trole.'.'.$area;
4408: if ($trole =~ /^cr/) {
4409: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4410: $tdom,$spec,$trest,$area);
4411: } else {
4412: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4413: $tdom,$spec,$trest,$area);
4414: }
4415: }
4416: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4417: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4418: if ($1) {
4419: $no_userblock = 1;
4420: last;
4421: }
1.486 raeburn 4422: }
4423: }
1.490 raeburn 4424: } else {
4425: # Resource belongs to current user
4426: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4427: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4428: $no_ownblock = 1;
4429: last;
4430: }
1.474 raeburn 4431: }
4432: }
4433: # if they have the evb priv and are currently not playing student
1.482 raeburn 4434: next if (($no_ownblock) &&
1.491 albertel 4435: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4436: next if ($no_userblock);
1.474 raeburn 4437:
1.866 kalberla 4438: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4439: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4440:
1.1062 raeburn 4441: my ($start,$end,$trigger) =
4442: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4443: if (($start != 0) &&
4444: (($startblock == 0) || ($startblock > $start))) {
4445: $startblock = $start;
1.1062 raeburn 4446: if ($trigger ne '') {
4447: $triggerblock = $trigger;
4448: }
1.502 raeburn 4449: }
4450: if (($end != 0) &&
4451: (($endblock == 0) || ($endblock < $end))) {
4452: $endblock = $end;
1.1062 raeburn 4453: if ($trigger ne '') {
4454: $triggerblock = $trigger;
4455: }
1.502 raeburn 4456: }
1.490 raeburn 4457: }
1.1062 raeburn 4458: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4459: }
4460:
4461: sub get_blocks {
1.1062 raeburn 4462: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4463: my $startblock = 0;
4464: my $endblock = 0;
1.1062 raeburn 4465: my $triggerblock = '';
1.490 raeburn 4466: my $course = $cdom.'_'.$cnum;
4467: $setters->{$course} = {};
4468: $setters->{$course}{'staff'} = [];
4469: $setters->{$course}{'times'} = [];
1.1062 raeburn 4470: $setters->{$course}{'triggers'} = [];
4471: my (@blockers,%triggered);
4472: my $now = time;
4473: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4474: if ($activity eq 'docs') {
4475: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4476: foreach my $block (@blockers) {
4477: if ($block =~ /^firstaccess____(.+)$/) {
4478: my $item = $1;
4479: my $type = 'map';
4480: my $timersymb = $item;
4481: if ($item eq 'course') {
4482: $type = 'course';
4483: } elsif ($item =~ /___\d+___/) {
4484: $type = 'resource';
4485: } else {
4486: $timersymb = &Apache::lonnet::symbread($item);
4487: }
4488: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4489: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4490: $triggered{$block} = {
4491: start => $start,
4492: end => $end,
4493: type => $type,
4494: };
4495: }
4496: }
4497: } else {
4498: foreach my $block (keys(%commblocks)) {
4499: if ($block =~ m/^(\d+)____(\d+)$/) {
4500: my ($start,$end) = ($1,$2);
4501: if ($start <= time && $end >= time) {
4502: if (ref($commblocks{$block}) eq 'HASH') {
4503: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4504: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4505: unless(grep(/^\Q$block\E$/,@blockers)) {
4506: push(@blockers,$block);
4507: }
4508: }
4509: }
4510: }
4511: }
4512: } elsif ($block =~ /^firstaccess____(.+)$/) {
4513: my $item = $1;
4514: my $timersymb = $item;
4515: my $type = 'map';
4516: if ($item eq 'course') {
4517: $type = 'course';
4518: } elsif ($item =~ /___\d+___/) {
4519: $type = 'resource';
4520: } else {
4521: $timersymb = &Apache::lonnet::symbread($item);
4522: }
4523: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4524: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4525: if ($start && $end) {
4526: if (($start <= time) && ($end >= time)) {
4527: unless (grep(/^\Q$block\E$/,@blockers)) {
4528: push(@blockers,$block);
4529: $triggered{$block} = {
4530: start => $start,
4531: end => $end,
4532: type => $type,
4533: };
4534: }
4535: }
1.490 raeburn 4536: }
1.1062 raeburn 4537: }
4538: }
4539: }
4540: foreach my $blocker (@blockers) {
4541: my ($staff_name,$staff_dom,$title,$blocks) =
4542: &parse_block_record($commblocks{$blocker});
4543: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4544: my ($start,$end,$triggertype);
4545: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4546: ($start,$end) = ($1,$2);
4547: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4548: $start = $triggered{$blocker}{'start'};
4549: $end = $triggered{$blocker}{'end'};
4550: $triggertype = $triggered{$blocker}{'type'};
4551: }
4552: if ($start) {
4553: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4554: if ($triggertype) {
4555: push(@{$$setters{$course}{'triggers'}},$triggertype);
4556: } else {
4557: push(@{$$setters{$course}{'triggers'}},0);
4558: }
4559: if ( ($startblock == 0) || ($startblock > $start) ) {
4560: $startblock = $start;
4561: if ($triggertype) {
4562: $triggerblock = $blocker;
1.474 raeburn 4563: }
4564: }
1.1062 raeburn 4565: if ( ($endblock == 0) || ($endblock < $end) ) {
4566: $endblock = $end;
4567: if ($triggertype) {
4568: $triggerblock = $blocker;
4569: }
4570: }
1.474 raeburn 4571: }
4572: }
1.1062 raeburn 4573: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4574: }
4575:
4576: sub parse_block_record {
4577: my ($record) = @_;
4578: my ($setuname,$setudom,$title,$blocks);
4579: if (ref($record) eq 'HASH') {
4580: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4581: $title = &unescape($record->{'event'});
4582: $blocks = $record->{'blocks'};
4583: } else {
4584: my @data = split(/:/,$record,3);
4585: if (scalar(@data) eq 2) {
4586: $title = $data[1];
4587: ($setuname,$setudom) = split(/@/,$data[0]);
4588: } else {
4589: ($setuname,$setudom,$title) = @data;
4590: }
4591: $blocks = { 'com' => 'on' };
4592: }
4593: return ($setuname,$setudom,$title,$blocks);
4594: }
4595:
1.854 kalberla 4596: sub blocking_status {
1.1062 raeburn 4597: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4598: my %setters;
1.890 droeschl 4599:
1.1061 raeburn 4600: # check for active blocking
1.1062 raeburn 4601: my ($startblock,$endblock,$triggerblock) =
4602: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4603: my $blocked = 0;
4604: if ($startblock && $endblock) {
4605: $blocked = 1;
4606: }
1.890 droeschl 4607:
1.1061 raeburn 4608: # caller just wants to know whether a block is active
4609: if (!wantarray) { return $blocked; }
4610:
4611: # build a link to a popup window containing the details
4612: my $querystring = "?activity=$activity";
4613: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4614: if ($activity eq 'port') {
4615: $querystring .= "&udom=$udom" if $udom;
4616: $querystring .= "&uname=$uname" if $uname;
4617: } elsif ($activity eq 'docs') {
4618: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4619: }
1.1061 raeburn 4620:
4621: my $output .= <<'END_MYBLOCK';
4622: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4623: var options = "width=" + w + ",height=" + h + ",";
4624: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4625: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4626: var newWin = window.open(url, wdwName, options);
4627: newWin.focus();
4628: }
1.890 droeschl 4629: END_MYBLOCK
1.854 kalberla 4630:
1.1061 raeburn 4631: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4632:
1.1061 raeburn 4633: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4634: my $text = &mt('Communication Blocked');
4635: if ($activity eq 'docs') {
4636: $text = &mt('Content Access Blocked');
1.1063 raeburn 4637: } elsif ($activity eq 'printout') {
4638: $text = &mt('Printing Blocked');
1.1062 raeburn 4639: }
1.1061 raeburn 4640: $output .= <<"END_BLOCK";
1.867 kalberla 4641: <div class='LC_comblock'>
1.869 kalberla 4642: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4643: title='$text'>
4644: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4645: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4646: title='$text'>$text</a>
1.867 kalberla 4647: </div>
4648:
4649: END_BLOCK
1.474 raeburn 4650:
1.1061 raeburn 4651: return ($blocked, $output);
1.854 kalberla 4652: }
1.490 raeburn 4653:
1.60 matthew 4654: ###############################################
4655:
1.682 raeburn 4656: sub check_ip_acc {
4657: my ($acc)=@_;
4658: &Apache::lonxml::debug("acc is $acc");
4659: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4660: return 1;
4661: }
4662: my $allowed=0;
4663: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4664:
4665: my $name;
4666: foreach my $pattern (split(',',$acc)) {
4667: $pattern =~ s/^\s*//;
4668: $pattern =~ s/\s*$//;
4669: if ($pattern =~ /\*$/) {
4670: #35.8.*
4671: $pattern=~s/\*//;
4672: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4673: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4674: #35.8.3.[34-56]
4675: my $low=$2;
4676: my $high=$3;
4677: $pattern=$1;
4678: if ($ip =~ /^\Q$pattern\E/) {
4679: my $last=(split(/\./,$ip))[3];
4680: if ($last <=$high && $last >=$low) { $allowed=1; }
4681: }
4682: } elsif ($pattern =~ /^\*/) {
4683: #*.msu.edu
4684: $pattern=~s/\*//;
4685: if (!defined($name)) {
4686: use Socket;
4687: my $netaddr=inet_aton($ip);
4688: ($name)=gethostbyaddr($netaddr,AF_INET);
4689: }
4690: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4691: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4692: #127.0.0.1
4693: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4694: } else {
4695: #some.name.com
4696: if (!defined($name)) {
4697: use Socket;
4698: my $netaddr=inet_aton($ip);
4699: ($name)=gethostbyaddr($netaddr,AF_INET);
4700: }
4701: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4702: }
4703: if ($allowed) { last; }
4704: }
4705: return $allowed;
4706: }
4707:
4708: ###############################################
4709:
1.60 matthew 4710: =pod
4711:
1.112 bowersj2 4712: =head1 Domain Template Functions
4713:
4714: =over 4
4715:
4716: =item * &determinedomain()
1.60 matthew 4717:
4718: Inputs: $domain (usually will be undef)
4719:
1.63 www 4720: Returns: Determines which domain should be used for designs
1.60 matthew 4721:
4722: =cut
1.54 www 4723:
1.60 matthew 4724: ###############################################
1.63 www 4725: sub determinedomain {
4726: my $domain=shift;
1.531 albertel 4727: if (! $domain) {
1.60 matthew 4728: # Determine domain if we have not been given one
1.893 raeburn 4729: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4730: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4731: if ($env{'request.role.domain'}) {
4732: $domain=$env{'request.role.domain'};
1.60 matthew 4733: }
4734: }
1.63 www 4735: return $domain;
4736: }
4737: ###############################################
1.517 raeburn 4738:
1.518 albertel 4739: sub devalidate_domconfig_cache {
4740: my ($udom)=@_;
4741: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4742: }
4743:
4744: # ---------------------- Get domain configuration for a domain
4745: sub get_domainconf {
4746: my ($udom) = @_;
4747: my $cachetime=1800;
4748: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4749: if (defined($cached)) { return %{$result}; }
4750:
4751: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4752: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4753: my (%designhash,%legacy);
1.518 albertel 4754: if (keys(%domconfig) > 0) {
4755: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4756: if (keys(%{$domconfig{'login'}})) {
4757: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4758: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4759: if ($key eq 'loginvia') {
4760: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4761: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4762: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4763: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4764: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4765: $designhash{$udom.'.login.loginvia'} = $server;
4766: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4767:
4768: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4769: } else {
1.1013 raeburn 4770: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4771: }
4772: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4773: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4774: }
1.946 raeburn 4775: }
4776: }
4777: }
4778: }
4779: } else {
4780: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4781: $designhash{$udom.'.login.'.$key.'_'.$img} =
4782: $domconfig{'login'}{$key}{$img};
4783: }
1.699 raeburn 4784: }
4785: } else {
4786: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4787: }
1.632 raeburn 4788: }
4789: } else {
4790: $legacy{'login'} = 1;
1.518 albertel 4791: }
1.632 raeburn 4792: } else {
4793: $legacy{'login'} = 1;
1.518 albertel 4794: }
4795: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4796: if (keys(%{$domconfig{'rolecolors'}})) {
4797: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4798: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4799: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4800: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4801: }
1.518 albertel 4802: }
4803: }
1.632 raeburn 4804: } else {
4805: $legacy{'rolecolors'} = 1;
1.518 albertel 4806: }
1.632 raeburn 4807: } else {
4808: $legacy{'rolecolors'} = 1;
1.518 albertel 4809: }
1.948 raeburn 4810: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4811: if ($domconfig{'autoenroll'}{'co-owners'}) {
4812: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4813: }
4814: }
1.632 raeburn 4815: if (keys(%legacy) > 0) {
4816: my %legacyhash = &get_legacy_domconf($udom);
4817: foreach my $item (keys(%legacyhash)) {
4818: if ($item =~ /^\Q$udom\E\.login/) {
4819: if ($legacy{'login'}) {
4820: $designhash{$item} = $legacyhash{$item};
4821: }
4822: } else {
4823: if ($legacy{'rolecolors'}) {
4824: $designhash{$item} = $legacyhash{$item};
4825: }
1.518 albertel 4826: }
4827: }
4828: }
1.632 raeburn 4829: } else {
4830: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4831: }
4832: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4833: $cachetime);
4834: return %designhash;
4835: }
4836:
1.632 raeburn 4837: sub get_legacy_domconf {
4838: my ($udom) = @_;
4839: my %legacyhash;
4840: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4841: my $designfile = $designdir.'/'.$udom.'.tab';
4842: if (-e $designfile) {
4843: if ( open (my $fh,"<$designfile") ) {
4844: while (my $line = <$fh>) {
4845: next if ($line =~ /^\#/);
4846: chomp($line);
4847: my ($key,$val)=(split(/\=/,$line));
4848: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4849: }
4850: close($fh);
4851: }
4852: }
1.1026 raeburn 4853: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4854: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4855: }
4856: return %legacyhash;
4857: }
4858:
1.63 www 4859: =pod
4860:
1.112 bowersj2 4861: =item * &domainlogo()
1.63 www 4862:
4863: Inputs: $domain (usually will be undef)
4864:
4865: Returns: A link to a domain logo, if the domain logo exists.
4866: If the domain logo does not exist, a description of the domain.
4867:
4868: =cut
1.112 bowersj2 4869:
1.63 www 4870: ###############################################
4871: sub domainlogo {
1.517 raeburn 4872: my $domain = &determinedomain(shift);
1.518 albertel 4873: my %designhash = &get_domainconf($domain);
1.517 raeburn 4874: # See if there is a logo
4875: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4876: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4877: if ($imgsrc =~ m{^/(adm|res)/}) {
4878: if ($imgsrc =~ m{^/res/}) {
4879: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4880: &Apache::lonnet::repcopy($local_name);
4881: }
4882: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4883: }
4884: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4885: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4886: return &Apache::lonnet::domain($domain,'description');
1.59 www 4887: } else {
1.60 matthew 4888: return '';
1.59 www 4889: }
4890: }
1.63 www 4891: ##############################################
4892:
4893: =pod
4894:
1.112 bowersj2 4895: =item * &designparm()
1.63 www 4896:
4897: Inputs: $which parameter; $domain (usually will be undef)
4898:
4899: Returns: value of designparamter $which
4900:
4901: =cut
1.112 bowersj2 4902:
1.397 albertel 4903:
1.400 albertel 4904: ##############################################
1.397 albertel 4905: sub designparm {
4906: my ($which,$domain)=@_;
4907: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4908: return $env{'environment.color.'.$which};
1.96 www 4909: }
1.63 www 4910: $domain=&determinedomain($domain);
1.1016 raeburn 4911: my %domdesign;
4912: unless ($domain eq 'public') {
4913: %domdesign = &get_domainconf($domain);
4914: }
1.520 raeburn 4915: my $output;
1.517 raeburn 4916: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4917: $output = $domdesign{$domain.'.'.$which};
1.63 www 4918: } else {
1.520 raeburn 4919: $output = $defaultdesign{$which};
4920: }
4921: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4922: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4923: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4924: if ($output =~ m{^/res/}) {
4925: my $local_name = &Apache::lonnet::filelocation('',$output);
4926: &Apache::lonnet::repcopy($local_name);
4927: }
1.520 raeburn 4928: $output = &lonhttpdurl($output);
4929: }
1.63 www 4930: }
1.520 raeburn 4931: return $output;
1.63 www 4932: }
1.59 www 4933:
1.822 bisitz 4934: ##############################################
4935: =pod
4936:
1.832 bisitz 4937: =item * &authorspace()
4938:
1.1028 raeburn 4939: Inputs: $url (usually will be undef).
1.832 bisitz 4940:
1.1132 raeburn 4941: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4942: directory being viewed (or for which action is being taken).
4943: If $url is provided, and begins /priv/<domain>/<uname>
4944: the path will be that portion of the $context argument.
4945: Otherwise the path will be for the author space of the current
4946: user when the current role is author, or for that of the
4947: co-author/assistant co-author space when the current role
4948: is co-author or assistant co-author.
1.832 bisitz 4949:
4950: =cut
4951:
4952: sub authorspace {
1.1028 raeburn 4953: my ($url) = @_;
4954: if ($url ne '') {
4955: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4956: return $1;
4957: }
4958: }
1.832 bisitz 4959: my $caname = '';
1.1024 www 4960: my $cadom = '';
1.1028 raeburn 4961: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4962: ($cadom,$caname) =
1.832 bisitz 4963: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4964: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4965: $caname = $env{'user.name'};
1.1024 www 4966: $cadom = $env{'user.domain'};
1.832 bisitz 4967: }
1.1028 raeburn 4968: if (($caname ne '') && ($cadom ne '')) {
4969: return "/priv/$cadom/$caname/";
4970: }
4971: return;
1.832 bisitz 4972: }
4973:
4974: ##############################################
4975: =pod
4976:
1.822 bisitz 4977: =item * &head_subbox()
4978:
4979: Inputs: $content (contains HTML code with page functions, etc.)
4980:
4981: Returns: HTML div with $content
4982: To be included in page header
4983:
4984: =cut
4985:
4986: sub head_subbox {
4987: my ($content)=@_;
4988: my $output =
1.993 raeburn 4989: '<div class="LC_head_subbox">'
1.822 bisitz 4990: .$content
4991: .'</div>'
4992: }
4993:
4994: ##############################################
4995: =pod
4996:
4997: =item * &CSTR_pageheader()
4998:
1.1026 raeburn 4999: Input: (optional) filename from which breadcrumb trail is built.
5000: In most cases no input as needed, as $env{'request.filename'}
5001: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5002:
5003: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5004: To be included on Authoring Space pages
1.822 bisitz 5005:
5006: =cut
5007:
5008: sub CSTR_pageheader {
1.1026 raeburn 5009: my ($trailfile) = @_;
5010: if ($trailfile eq '') {
5011: $trailfile = $env{'request.filename'};
5012: }
5013:
5014: # this is for resources; directories have customtitle, and crumbs
5015: # and select recent are created in lonpubdir.pm
5016:
5017: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5018: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5019: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5020: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5021: $formaction =~ s{/+}{/}g;
1.822 bisitz 5022:
5023: my $parentpath = '';
5024: my $lastitem = '';
5025: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5026: $parentpath = $1;
5027: $lastitem = $2;
5028: } else {
5029: $lastitem = $thisdisfn;
5030: }
1.921 bisitz 5031:
5032: my $output =
1.822 bisitz 5033: '<div>'
5034: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1132 raeburn 5035: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5036: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5037: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5038: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5039:
5040: if ($lastitem) {
5041: $output .=
5042: '<span class="LC_filename">'
5043: .$lastitem
5044: .'</span>';
5045: }
5046: $output .=
5047: '<br />'
1.822 bisitz 5048: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5049: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5050: .'</form>'
5051: .&Apache::lonmenu::constspaceform()
5052: .'</div>';
1.921 bisitz 5053:
5054: return $output;
1.822 bisitz 5055: }
5056:
1.60 matthew 5057: ###############################################
5058: ###############################################
5059:
5060: =pod
5061:
1.112 bowersj2 5062: =back
5063:
1.549 albertel 5064: =head1 HTML Helpers
1.112 bowersj2 5065:
5066: =over 4
5067:
5068: =item * &bodytag()
1.60 matthew 5069:
5070: Returns a uniform header for LON-CAPA web pages.
5071:
5072: Inputs:
5073:
1.112 bowersj2 5074: =over 4
5075:
5076: =item * $title, A title to be displayed on the page.
5077:
5078: =item * $function, the current role (can be undef).
5079:
5080: =item * $addentries, extra parameters for the <body> tag.
5081:
5082: =item * $bodyonly, if defined, only return the <body> tag.
5083:
5084: =item * $domain, if defined, force a given domain.
5085:
5086: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5087: text interface only)
1.60 matthew 5088:
1.814 bisitz 5089: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5090: navigational links
1.317 albertel 5091:
1.338 albertel 5092: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5093:
1.460 albertel 5094: =item * $args, optional argument valid values are
5095: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5096: inherit_jsmath -> when creating popup window in a page,
5097: should it have jsmath forced on by the
5098: current page
1.460 albertel 5099:
1.1096 raeburn 5100: =item * $advtoolsref, optional argument, ref to an array containing
5101: inlineremote items to be added in "Functions" menu below
5102: breadcrumbs.
5103:
1.112 bowersj2 5104: =back
5105:
1.60 matthew 5106: Returns: A uniform header for LON-CAPA web pages.
5107: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5108: If $bodyonly is undef or zero, an html string containing a <body> tag and
5109: other decorations will be returned.
5110:
5111: =cut
5112:
1.54 www 5113: sub bodytag {
1.831 bisitz 5114: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5115: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5116:
1.954 raeburn 5117: my $public;
5118: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5119: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5120: $public = 1;
5121: }
1.460 albertel 5122: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 5123:
1.183 matthew 5124: $function = &get_users_function() if (!$function);
1.339 albertel 5125: my $img = &designparm($function.'.img',$domain);
5126: my $font = &designparm($function.'.font',$domain);
5127: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5128:
1.803 bisitz 5129: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5130: 'bgcolor' => $pgbg,
1.339 albertel 5131: 'text' => $font,
5132: 'alink' => &designparm($function.'.alink',$domain),
5133: 'vlink' => &designparm($function.'.vlink',$domain),
5134: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5135: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5136:
1.63 www 5137: # role and realm
1.378 raeburn 5138: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5139: if ($role eq 'ca') {
1.479 albertel 5140: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5141: $realm = &plainname($rname,$rdom);
1.378 raeburn 5142: }
1.55 www 5143: # realm
1.258 albertel 5144: if ($env{'request.course.id'}) {
1.378 raeburn 5145: if ($env{'request.role'} !~ /^cr/) {
5146: $role = &Apache::lonnet::plaintext($role,&course_type());
5147: }
1.898 raeburn 5148: if ($env{'request.course.sec'}) {
5149: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5150: }
1.359 albertel 5151: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5152: } else {
5153: $role = &Apache::lonnet::plaintext($role);
1.54 www 5154: }
1.433 albertel 5155:
1.359 albertel 5156: if (!$realm) { $realm=' '; }
1.330 albertel 5157:
1.438 albertel 5158: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5159:
1.101 www 5160: # construct main body tag
1.359 albertel 5161: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5162: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5163:
1.1131 raeburn 5164: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5165:
1.1130 raeburn 5166: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5167: return $bodytag;
1.1130 raeburn 5168: }
1.359 albertel 5169:
1.954 raeburn 5170: if ($public) {
1.433 albertel 5171: undef($role);
5172: }
1.359 albertel 5173:
1.762 bisitz 5174: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5175: #
5176: # Extra info if you are the DC
5177: my $dc_info = '';
5178: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5179: $env{'course.'.$env{'request.course.id'}.
5180: '.domain'}.'/'})) {
5181: my $cid = $env{'request.course.id'};
1.917 raeburn 5182: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5183: $dc_info =~ s/\s+$//;
1.359 albertel 5184: }
5185:
1.898 raeburn 5186: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5187:
1.903 droeschl 5188: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5189:
5190: # if ($env{'request.state'} eq 'construct') {
5191: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5192: # }
5193:
1.1130 raeburn 5194: $bodytag .= Apache::lonhtmlcommon::scripttag(
5195: Apache::lonmenu::utilityfunctions(), 'start');
1.359 albertel 5196:
1.1130 raeburn 5197: my ($left,$right) = Apache::lonmenu::primary_menu();
1.359 albertel 5198:
1.916 droeschl 5199: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5200: if ($dc_info) {
5201: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5202: }
1.1130 raeburn 5203: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5204: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5205: return $bodytag;
5206: }
1.894 droeschl 5207:
1.927 raeburn 5208: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5209: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5210: }
1.916 droeschl 5211:
1.1130 raeburn 5212: $bodytag .= $right;
1.852 droeschl 5213:
1.917 raeburn 5214: if ($dc_info) {
5215: $dc_info = &dc_courseid_toggle($dc_info);
5216: }
5217: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5218:
1.903 droeschl 5219: #don't show menus for public users
1.954 raeburn 5220: if (!$public){
1.903 droeschl 5221: $bodytag .= Apache::lonmenu::secondary_menu();
5222: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5223: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5224: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5225: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5226: $args->{'bread_crumbs'});
1.1096 raeburn 5227: } elsif ($forcereg) {
5228: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5229: $args->{'group'});
5230: } else {
5231: $bodytag .=
5232: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5233: $forcereg,$args->{'group'},
5234: $args->{'bread_crumbs'},
5235: $advtoolsref);
1.920 raeburn 5236: }
1.903 droeschl 5237: }else{
5238: # this is to seperate menu from content when there's no secondary
5239: # menu. Especially needed for public accessible ressources.
5240: $bodytag .= '<hr style="clear:both" />';
5241: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5242: }
1.903 droeschl 5243:
1.235 raeburn 5244: return $bodytag;
1.182 matthew 5245: }
5246:
1.917 raeburn 5247: sub dc_courseid_toggle {
5248: my ($dc_info) = @_;
1.980 raeburn 5249: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5250: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5251: &mt('(More ...)').'</a></span>'.
5252: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5253: }
5254:
1.330 albertel 5255: sub make_attr_string {
5256: my ($register,$attr_ref) = @_;
5257:
5258: if ($attr_ref && !ref($attr_ref)) {
5259: die("addentries Must be a hash ref ".
5260: join(':',caller(1))." ".
5261: join(':',caller(0))." ");
5262: }
5263:
5264: if ($register) {
1.339 albertel 5265: my ($on_load,$on_unload);
5266: foreach my $key (keys(%{$attr_ref})) {
5267: if (lc($key) eq 'onload') {
5268: $on_load.=$attr_ref->{$key}.';';
5269: delete($attr_ref->{$key});
5270:
5271: } elsif (lc($key) eq 'onunload') {
5272: $on_unload.=$attr_ref->{$key}.';';
5273: delete($attr_ref->{$key});
5274: }
5275: }
1.953 droeschl 5276: $attr_ref->{'onload'} = $on_load;
5277: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5278: }
1.339 albertel 5279:
1.330 albertel 5280: my $attr_string;
5281: foreach my $attr (keys(%$attr_ref)) {
5282: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5283: }
5284: return $attr_string;
5285: }
5286:
5287:
1.182 matthew 5288: ###############################################
1.251 albertel 5289: ###############################################
5290:
5291: =pod
5292:
5293: =item * &endbodytag()
5294:
5295: Returns a uniform footer for LON-CAPA web pages.
5296:
1.635 raeburn 5297: Inputs: 1 - optional reference to an args hash
5298: If in the hash, key for noredirectlink has a value which evaluates to true,
5299: a 'Continue' link is not displayed if the page contains an
5300: internal redirect in the <head></head> section,
5301: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5302:
5303: =cut
5304:
5305: sub endbodytag {
1.635 raeburn 5306: my ($args) = @_;
1.1080 raeburn 5307: my $endbodytag;
5308: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5309: $endbodytag='</body>';
5310: }
1.269 albertel 5311: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5312: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5313: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5314: $endbodytag=
5315: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5316: &mt('Continue').'</a>'.
5317: $endbodytag;
5318: }
1.315 albertel 5319: }
1.251 albertel 5320: return $endbodytag;
5321: }
5322:
1.352 albertel 5323: =pod
5324:
5325: =item * &standard_css()
5326:
5327: Returns a style sheet
5328:
5329: Inputs: (all optional)
5330: domain -> force to color decorate a page for a specific
5331: domain
5332: function -> force usage of a specific rolish color scheme
5333: bgcolor -> override the default page bgcolor
5334:
5335: =cut
5336:
1.343 albertel 5337: sub standard_css {
1.345 albertel 5338: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5339: $function = &get_users_function() if (!$function);
5340: my $img = &designparm($function.'.img', $domain);
5341: my $tabbg = &designparm($function.'.tabbg', $domain);
5342: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5343: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5344: #second colour for later usage
1.345 albertel 5345: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5346: my $pgbg_or_bgcolor =
5347: $bgcolor ||
1.352 albertel 5348: &designparm($function.'.pgbg', $domain);
1.382 albertel 5349: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5350: my $alink = &designparm($function.'.alink', $domain);
5351: my $vlink = &designparm($function.'.vlink', $domain);
5352: my $link = &designparm($function.'.link', $domain);
5353:
1.602 albertel 5354: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5355: my $mono = 'monospace';
1.850 bisitz 5356: my $data_table_head = $sidebg;
5357: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5358: my $data_table_dark = '#E0E0E0';
1.470 banghart 5359: my $data_table_darker = '#CCCCCC';
1.349 albertel 5360: my $data_table_highlight = '#FFFF00';
1.352 albertel 5361: my $mail_new = '#FFBB77';
5362: my $mail_new_hover = '#DD9955';
5363: my $mail_read = '#BBBB77';
5364: my $mail_read_hover = '#999944';
5365: my $mail_replied = '#AAAA88';
5366: my $mail_replied_hover = '#888855';
5367: my $mail_other = '#99BBBB';
5368: my $mail_other_hover = '#669999';
1.391 albertel 5369: my $table_header = '#DDDDDD';
1.489 raeburn 5370: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5371: my $lg_border_color = '#C8C8C8';
1.952 onken 5372: my $button_hover = '#BF2317';
1.392 albertel 5373:
1.608 albertel 5374: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5375: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5376: : '0 3px 0 4px';
1.448 albertel 5377:
1.523 albertel 5378:
1.343 albertel 5379: return <<END;
1.947 droeschl 5380:
5381: /* needed for iframe to allow 100% height in FF */
5382: body, html {
5383: margin: 0;
5384: padding: 0 0.5%;
5385: height: 99%; /* to avoid scrollbars */
5386: }
5387:
1.795 www 5388: body {
1.911 bisitz 5389: font-family: $sans;
5390: line-height:130%;
5391: font-size:0.83em;
5392: color:$font;
1.795 www 5393: }
5394:
1.959 onken 5395: a:focus,
5396: a:focus img {
1.795 www 5397: color: red;
5398: }
1.698 harmsja 5399:
1.911 bisitz 5400: form, .inline {
5401: display: inline;
1.795 www 5402: }
1.721 harmsja 5403:
1.795 www 5404: .LC_right {
1.911 bisitz 5405: text-align:right;
1.795 www 5406: }
5407:
5408: .LC_middle {
1.911 bisitz 5409: vertical-align:middle;
1.795 www 5410: }
1.721 harmsja 5411:
1.1130 raeburn 5412: .LC_floatleft {
5413: float: left;
5414: }
5415:
5416: .LC_floatright {
5417: float: right;
5418: }
5419:
1.911 bisitz 5420: .LC_400Box {
5421: width:400px;
5422: }
1.721 harmsja 5423:
1.947 droeschl 5424: .LC_iframecontainer {
5425: width: 98%;
5426: margin: 0;
5427: position: fixed;
5428: top: 8.5em;
5429: bottom: 0;
5430: }
5431:
5432: .LC_iframecontainer iframe{
5433: border: none;
5434: width: 100%;
5435: height: 100%;
5436: }
5437:
1.778 bisitz 5438: .LC_filename {
5439: font-family: $mono;
5440: white-space:pre;
1.921 bisitz 5441: font-size: 120%;
1.778 bisitz 5442: }
5443:
5444: .LC_fileicon {
5445: border: none;
5446: height: 1.3em;
5447: vertical-align: text-bottom;
5448: margin-right: 0.3em;
5449: text-decoration:none;
5450: }
5451:
1.1008 www 5452: .LC_setting {
5453: text-decoration:underline;
5454: }
5455:
1.350 albertel 5456: .LC_error {
5457: color: red;
5458: }
1.795 www 5459:
1.1097 bisitz 5460: .LC_warning {
5461: color: darkorange;
5462: }
5463:
1.457 albertel 5464: .LC_diff_removed {
1.733 bisitz 5465: color: red;
1.394 albertel 5466: }
1.532 albertel 5467:
5468: .LC_info,
1.457 albertel 5469: .LC_success,
5470: .LC_diff_added {
1.350 albertel 5471: color: green;
5472: }
1.795 www 5473:
1.802 bisitz 5474: div.LC_confirm_box {
5475: background-color: #FAFAFA;
5476: border: 1px solid $lg_border_color;
5477: margin-right: 0;
5478: padding: 5px;
5479: }
5480:
5481: div.LC_confirm_box .LC_error img,
5482: div.LC_confirm_box .LC_success img {
5483: vertical-align: middle;
5484: }
5485:
1.440 albertel 5486: .LC_icon {
1.771 droeschl 5487: border: none;
1.790 droeschl 5488: vertical-align: middle;
1.771 droeschl 5489: }
5490:
1.543 albertel 5491: .LC_docs_spacer {
5492: width: 25px;
5493: height: 1px;
1.771 droeschl 5494: border: none;
1.543 albertel 5495: }
1.346 albertel 5496:
1.532 albertel 5497: .LC_internal_info {
1.735 bisitz 5498: color: #999999;
1.532 albertel 5499: }
5500:
1.794 www 5501: .LC_discussion {
1.1050 www 5502: background: $data_table_dark;
1.911 bisitz 5503: border: 1px solid black;
5504: margin: 2px;
1.794 www 5505: }
5506:
5507: .LC_disc_action_left {
1.1050 www 5508: background: $sidebg;
1.911 bisitz 5509: text-align: left;
1.1050 www 5510: padding: 4px;
5511: margin: 2px;
1.794 www 5512: }
5513:
5514: .LC_disc_action_right {
1.1050 www 5515: background: $sidebg;
1.911 bisitz 5516: text-align: right;
1.1050 www 5517: padding: 4px;
5518: margin: 2px;
1.794 www 5519: }
5520:
5521: .LC_disc_new_item {
1.911 bisitz 5522: background: white;
5523: border: 2px solid red;
1.1050 www 5524: margin: 4px;
5525: padding: 4px;
1.794 www 5526: }
5527:
5528: .LC_disc_old_item {
1.911 bisitz 5529: background: white;
1.1050 www 5530: margin: 4px;
5531: padding: 4px;
1.794 www 5532: }
5533:
1.458 albertel 5534: table.LC_pastsubmission {
5535: border: 1px solid black;
5536: margin: 2px;
5537: }
5538:
1.924 bisitz 5539: table#LC_menubuttons {
1.345 albertel 5540: width: 100%;
5541: background: $pgbg;
1.392 albertel 5542: border: 2px;
1.402 albertel 5543: border-collapse: separate;
1.803 bisitz 5544: padding: 0;
1.345 albertel 5545: }
1.392 albertel 5546:
1.801 tempelho 5547: table#LC_title_bar a {
5548: color: $fontmenu;
5549: }
1.836 bisitz 5550:
1.807 droeschl 5551: table#LC_title_bar {
1.819 tempelho 5552: clear: both;
1.836 bisitz 5553: display: none;
1.807 droeschl 5554: }
5555:
1.795 www 5556: table#LC_title_bar,
1.933 droeschl 5557: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5558: table#LC_title_bar.LC_with_remote {
1.359 albertel 5559: width: 100%;
1.392 albertel 5560: border-color: $pgbg;
5561: border-style: solid;
5562: border-width: $border;
1.379 albertel 5563: background: $pgbg;
1.801 tempelho 5564: color: $fontmenu;
1.392 albertel 5565: border-collapse: collapse;
1.803 bisitz 5566: padding: 0;
1.819 tempelho 5567: margin: 0;
1.359 albertel 5568: }
1.795 www 5569:
1.933 droeschl 5570: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5571: margin: 0;
5572: padding: 0;
1.933 droeschl 5573: position: relative;
5574: list-style: none;
1.913 droeschl 5575: }
1.933 droeschl 5576: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5577: display: inline;
5578: }
1.933 droeschl 5579:
5580: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5581: padding: 0;
1.933 droeschl 5582: margin: 0;
5583: float: left;
1.913 droeschl 5584: }
1.933 droeschl 5585: .LC_breadcrumb_tools_tools {
5586: padding: 0;
5587: margin: 0;
1.913 droeschl 5588: float: right;
5589: }
5590:
1.359 albertel 5591: table#LC_title_bar td {
5592: background: $tabbg;
5593: }
1.795 www 5594:
1.911 bisitz 5595: table#LC_menubuttons img {
1.803 bisitz 5596: border: none;
1.346 albertel 5597: }
1.795 www 5598:
1.842 droeschl 5599: .LC_breadcrumbs_component {
1.911 bisitz 5600: float: right;
5601: margin: 0 1em;
1.357 albertel 5602: }
1.842 droeschl 5603: .LC_breadcrumbs_component img {
1.911 bisitz 5604: vertical-align: middle;
1.777 tempelho 5605: }
1.795 www 5606:
1.383 albertel 5607: td.LC_table_cell_checkbox {
5608: text-align: center;
5609: }
1.795 www 5610:
5611: .LC_fontsize_small {
1.911 bisitz 5612: font-size: 70%;
1.705 tempelho 5613: }
5614:
1.844 bisitz 5615: #LC_breadcrumbs {
1.911 bisitz 5616: clear:both;
5617: background: $sidebg;
5618: border-bottom: 1px solid $lg_border_color;
5619: line-height: 2.5em;
1.933 droeschl 5620: overflow: hidden;
1.911 bisitz 5621: margin: 0;
5622: padding: 0;
1.995 raeburn 5623: text-align: left;
1.819 tempelho 5624: }
1.862 bisitz 5625:
1.1098 bisitz 5626: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5627: clear:both;
5628: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5629: border: 1px solid $sidebg;
1.1098 bisitz 5630: margin: 0 0 10px 0;
1.966 bisitz 5631: padding: 3px;
1.995 raeburn 5632: text-align: left;
1.822 bisitz 5633: }
5634:
1.795 www 5635: .LC_fontsize_medium {
1.911 bisitz 5636: font-size: 85%;
1.705 tempelho 5637: }
5638:
1.795 www 5639: .LC_fontsize_large {
1.911 bisitz 5640: font-size: 120%;
1.705 tempelho 5641: }
5642:
1.346 albertel 5643: .LC_menubuttons_inline_text {
5644: color: $font;
1.698 harmsja 5645: font-size: 90%;
1.701 harmsja 5646: padding-left:3px;
1.346 albertel 5647: }
5648:
1.934 droeschl 5649: .LC_menubuttons_inline_text img{
5650: vertical-align: middle;
5651: }
5652:
1.1051 www 5653: li.LC_menubuttons_inline_text img {
1.951 onken 5654: cursor:pointer;
1.1002 droeschl 5655: text-decoration: none;
1.951 onken 5656: }
5657:
1.526 www 5658: .LC_menubuttons_link {
5659: text-decoration: none;
5660: }
1.795 www 5661:
1.522 albertel 5662: .LC_menubuttons_category {
1.521 www 5663: color: $font;
1.526 www 5664: background: $pgbg;
1.521 www 5665: font-size: larger;
5666: font-weight: bold;
5667: }
5668:
1.346 albertel 5669: td.LC_menubuttons_text {
1.911 bisitz 5670: color: $font;
1.346 albertel 5671: }
1.706 harmsja 5672:
1.346 albertel 5673: .LC_current_location {
5674: background: $tabbg;
5675: }
1.795 www 5676:
1.938 bisitz 5677: table.LC_data_table {
1.347 albertel 5678: border: 1px solid #000000;
1.402 albertel 5679: border-collapse: separate;
1.426 albertel 5680: border-spacing: 1px;
1.610 albertel 5681: background: $pgbg;
1.347 albertel 5682: }
1.795 www 5683:
1.422 albertel 5684: .LC_data_table_dense {
5685: font-size: small;
5686: }
1.795 www 5687:
1.507 raeburn 5688: table.LC_nested_outer {
5689: border: 1px solid #000000;
1.589 raeburn 5690: border-collapse: collapse;
1.803 bisitz 5691: border-spacing: 0;
1.507 raeburn 5692: width: 100%;
5693: }
1.795 www 5694:
1.879 raeburn 5695: table.LC_innerpickbox,
1.507 raeburn 5696: table.LC_nested {
1.803 bisitz 5697: border: none;
1.589 raeburn 5698: border-collapse: collapse;
1.803 bisitz 5699: border-spacing: 0;
1.507 raeburn 5700: width: 100%;
5701: }
1.795 www 5702:
1.911 bisitz 5703: table.LC_data_table tr th,
5704: table.LC_calendar tr th,
1.879 raeburn 5705: table.LC_prior_tries tr th,
5706: table.LC_innerpickbox tr th {
1.349 albertel 5707: font-weight: bold;
5708: background-color: $data_table_head;
1.801 tempelho 5709: color:$fontmenu;
1.701 harmsja 5710: font-size:90%;
1.347 albertel 5711: }
1.795 www 5712:
1.879 raeburn 5713: table.LC_innerpickbox tr th,
5714: table.LC_innerpickbox tr td {
5715: vertical-align: top;
5716: }
5717:
1.711 raeburn 5718: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5719: background-color: #CCCCCC;
1.711 raeburn 5720: font-weight: bold;
5721: text-align: left;
5722: }
1.795 www 5723:
1.912 bisitz 5724: table.LC_data_table tr.LC_odd_row > td {
5725: background-color: $data_table_light;
5726: padding: 2px;
5727: vertical-align: top;
5728: }
5729:
1.809 bisitz 5730: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5731: background-color: $data_table_light;
1.912 bisitz 5732: vertical-align: top;
5733: }
5734:
5735: table.LC_data_table tr.LC_even_row > td {
5736: background-color: $data_table_dark;
1.425 albertel 5737: padding: 2px;
1.900 bisitz 5738: vertical-align: top;
1.347 albertel 5739: }
1.795 www 5740:
1.809 bisitz 5741: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5742: background-color: $data_table_dark;
1.900 bisitz 5743: vertical-align: top;
1.347 albertel 5744: }
1.795 www 5745:
1.425 albertel 5746: table.LC_data_table tr.LC_data_table_highlight td {
5747: background-color: $data_table_darker;
5748: }
1.795 www 5749:
1.639 raeburn 5750: table.LC_data_table tr td.LC_leftcol_header {
5751: background-color: $data_table_head;
5752: font-weight: bold;
5753: }
1.795 www 5754:
1.451 albertel 5755: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5756: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5757: font-weight: bold;
5758: font-style: italic;
5759: text-align: center;
5760: padding: 8px;
1.347 albertel 5761: }
1.795 www 5762:
1.1114 raeburn 5763: table.LC_data_table tr.LC_empty_row td,
5764: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5765: background-color: $sidebg;
5766: }
5767:
5768: table.LC_nested tr.LC_empty_row td {
5769: background-color: #FFFFFF;
5770: }
5771:
1.890 droeschl 5772: table.LC_caption {
5773: }
5774:
1.507 raeburn 5775: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5776: padding: 4ex
5777: }
1.795 www 5778:
1.507 raeburn 5779: table.LC_nested_outer tr th {
5780: font-weight: bold;
1.801 tempelho 5781: color:$fontmenu;
1.507 raeburn 5782: background-color: $data_table_head;
1.701 harmsja 5783: font-size: small;
1.507 raeburn 5784: border-bottom: 1px solid #000000;
5785: }
1.795 www 5786:
1.507 raeburn 5787: table.LC_nested_outer tr td.LC_subheader {
5788: background-color: $data_table_head;
5789: font-weight: bold;
5790: font-size: small;
5791: border-bottom: 1px solid #000000;
5792: text-align: right;
1.451 albertel 5793: }
1.795 www 5794:
1.507 raeburn 5795: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5796: background-color: #CCCCCC;
1.451 albertel 5797: font-weight: bold;
5798: font-size: small;
1.507 raeburn 5799: text-align: center;
5800: }
1.795 www 5801:
1.589 raeburn 5802: table.LC_nested tr.LC_info_row td.LC_left_item,
5803: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5804: text-align: left;
1.451 albertel 5805: }
1.795 www 5806:
1.507 raeburn 5807: table.LC_nested td {
1.735 bisitz 5808: background-color: #FFFFFF;
1.451 albertel 5809: font-size: small;
1.507 raeburn 5810: }
1.795 www 5811:
1.507 raeburn 5812: table.LC_nested_outer tr th.LC_right_item,
5813: table.LC_nested tr.LC_info_row td.LC_right_item,
5814: table.LC_nested tr.LC_odd_row td.LC_right_item,
5815: table.LC_nested tr td.LC_right_item {
1.451 albertel 5816: text-align: right;
5817: }
5818:
1.507 raeburn 5819: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5820: background-color: #EEEEEE;
1.451 albertel 5821: }
5822:
1.473 raeburn 5823: table.LC_createuser {
5824: }
5825:
5826: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5827: font-size: small;
1.473 raeburn 5828: }
5829:
5830: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5831: background-color: #CCCCCC;
1.473 raeburn 5832: font-weight: bold;
5833: text-align: center;
5834: }
5835:
1.349 albertel 5836: table.LC_calendar {
5837: border: 1px solid #000000;
5838: border-collapse: collapse;
1.917 raeburn 5839: width: 98%;
1.349 albertel 5840: }
1.795 www 5841:
1.349 albertel 5842: table.LC_calendar_pickdate {
5843: font-size: xx-small;
5844: }
1.795 www 5845:
1.349 albertel 5846: table.LC_calendar tr td {
5847: border: 1px solid #000000;
5848: vertical-align: top;
1.917 raeburn 5849: width: 14%;
1.349 albertel 5850: }
1.795 www 5851:
1.349 albertel 5852: table.LC_calendar tr td.LC_calendar_day_empty {
5853: background-color: $data_table_dark;
5854: }
1.795 www 5855:
1.779 bisitz 5856: table.LC_calendar tr td.LC_calendar_day_current {
5857: background-color: $data_table_highlight;
1.777 tempelho 5858: }
1.795 www 5859:
1.938 bisitz 5860: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5861: background-color: $mail_new;
5862: }
1.795 www 5863:
1.938 bisitz 5864: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5865: background-color: $mail_new_hover;
5866: }
1.795 www 5867:
1.938 bisitz 5868: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5869: background-color: $mail_read;
5870: }
1.795 www 5871:
1.938 bisitz 5872: /*
5873: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5874: background-color: $mail_read_hover;
5875: }
1.938 bisitz 5876: */
1.795 www 5877:
1.938 bisitz 5878: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5879: background-color: $mail_replied;
5880: }
1.795 www 5881:
1.938 bisitz 5882: /*
5883: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5884: background-color: $mail_replied_hover;
5885: }
1.938 bisitz 5886: */
1.795 www 5887:
1.938 bisitz 5888: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5889: background-color: $mail_other;
5890: }
1.795 www 5891:
1.938 bisitz 5892: /*
5893: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5894: background-color: $mail_other_hover;
5895: }
1.938 bisitz 5896: */
1.494 raeburn 5897:
1.777 tempelho 5898: table.LC_data_table tr > td.LC_browser_file,
5899: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5900: background: #AAEE77;
1.389 albertel 5901: }
1.795 www 5902:
1.777 tempelho 5903: table.LC_data_table tr > td.LC_browser_file_locked,
5904: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5905: background: #FFAA99;
1.387 albertel 5906: }
1.795 www 5907:
1.777 tempelho 5908: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5909: background: #888888;
1.779 bisitz 5910: }
1.795 www 5911:
1.777 tempelho 5912: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5913: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5914: background: #F8F866;
1.777 tempelho 5915: }
1.795 www 5916:
1.696 bisitz 5917: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5918: background: #E0E8FF;
1.387 albertel 5919: }
1.696 bisitz 5920:
1.707 bisitz 5921: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5922: /* background: #77FF77; */
1.707 bisitz 5923: }
1.795 www 5924:
1.707 bisitz 5925: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5926: border-right: 8px solid #FFFF77;
1.707 bisitz 5927: }
1.795 www 5928:
1.707 bisitz 5929: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5930: border-right: 8px solid #FFAA77;
1.707 bisitz 5931: }
1.795 www 5932:
1.707 bisitz 5933: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5934: border-right: 8px solid #FF7777;
1.707 bisitz 5935: }
1.795 www 5936:
1.707 bisitz 5937: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5938: border-right: 8px solid #AAFF77;
1.707 bisitz 5939: }
1.795 www 5940:
1.707 bisitz 5941: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5942: border-right: 8px solid #11CC55;
1.707 bisitz 5943: }
5944:
1.388 albertel 5945: span.LC_current_location {
1.701 harmsja 5946: font-size:larger;
1.388 albertel 5947: background: $pgbg;
5948: }
1.387 albertel 5949:
1.1029 www 5950: span.LC_current_nav_location {
5951: font-weight:bold;
5952: background: $sidebg;
5953: }
5954:
1.395 albertel 5955: span.LC_parm_menu_item {
5956: font-size: larger;
5957: }
1.795 www 5958:
1.395 albertel 5959: span.LC_parm_scope_all {
5960: color: red;
5961: }
1.795 www 5962:
1.395 albertel 5963: span.LC_parm_scope_folder {
5964: color: green;
5965: }
1.795 www 5966:
1.395 albertel 5967: span.LC_parm_scope_resource {
5968: color: orange;
5969: }
1.795 www 5970:
1.395 albertel 5971: span.LC_parm_part {
5972: color: blue;
5973: }
1.795 www 5974:
1.911 bisitz 5975: span.LC_parm_folder,
5976: span.LC_parm_symb {
1.395 albertel 5977: font-size: x-small;
5978: font-family: $mono;
5979: color: #AAAAAA;
5980: }
5981:
1.977 bisitz 5982: ul.LC_parm_parmlist li {
5983: display: inline-block;
5984: padding: 0.3em 0.8em;
5985: vertical-align: top;
5986: width: 150px;
5987: border-top:1px solid $lg_border_color;
5988: }
5989:
1.795 www 5990: td.LC_parm_overview_level_menu,
5991: td.LC_parm_overview_map_menu,
5992: td.LC_parm_overview_parm_selectors,
5993: td.LC_parm_overview_restrictions {
1.396 albertel 5994: border: 1px solid black;
5995: border-collapse: collapse;
5996: }
1.795 www 5997:
1.396 albertel 5998: table.LC_parm_overview_restrictions td {
5999: border-width: 1px 4px 1px 4px;
6000: border-style: solid;
6001: border-color: $pgbg;
6002: text-align: center;
6003: }
1.795 www 6004:
1.396 albertel 6005: table.LC_parm_overview_restrictions th {
6006: background: $tabbg;
6007: border-width: 1px 4px 1px 4px;
6008: border-style: solid;
6009: border-color: $pgbg;
6010: }
1.795 www 6011:
1.398 albertel 6012: table#LC_helpmenu {
1.803 bisitz 6013: border: none;
1.398 albertel 6014: height: 55px;
1.803 bisitz 6015: border-spacing: 0;
1.398 albertel 6016: }
6017:
6018: table#LC_helpmenu fieldset legend {
6019: font-size: larger;
6020: }
1.795 www 6021:
1.397 albertel 6022: table#LC_helpmenu_links {
6023: width: 100%;
6024: border: 1px solid black;
6025: background: $pgbg;
1.803 bisitz 6026: padding: 0;
1.397 albertel 6027: border-spacing: 1px;
6028: }
1.795 www 6029:
1.397 albertel 6030: table#LC_helpmenu_links tr td {
6031: padding: 1px;
6032: background: $tabbg;
1.399 albertel 6033: text-align: center;
6034: font-weight: bold;
1.397 albertel 6035: }
1.396 albertel 6036:
1.795 www 6037: table#LC_helpmenu_links a:link,
6038: table#LC_helpmenu_links a:visited,
1.397 albertel 6039: table#LC_helpmenu_links a:active {
6040: text-decoration: none;
6041: color: $font;
6042: }
1.795 www 6043:
1.397 albertel 6044: table#LC_helpmenu_links a:hover {
6045: text-decoration: underline;
6046: color: $vlink;
6047: }
1.396 albertel 6048:
1.417 albertel 6049: .LC_chrt_popup_exists {
6050: border: 1px solid #339933;
6051: margin: -1px;
6052: }
1.795 www 6053:
1.417 albertel 6054: .LC_chrt_popup_up {
6055: border: 1px solid yellow;
6056: margin: -1px;
6057: }
1.795 www 6058:
1.417 albertel 6059: .LC_chrt_popup {
6060: border: 1px solid #8888FF;
6061: background: #CCCCFF;
6062: }
1.795 www 6063:
1.421 albertel 6064: table.LC_pick_box {
6065: border-collapse: separate;
6066: background: white;
6067: border: 1px solid black;
6068: border-spacing: 1px;
6069: }
1.795 www 6070:
1.421 albertel 6071: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6072: background: $sidebg;
1.421 albertel 6073: font-weight: bold;
1.900 bisitz 6074: text-align: left;
1.740 bisitz 6075: vertical-align: top;
1.421 albertel 6076: width: 184px;
6077: padding: 8px;
6078: }
1.795 www 6079:
1.579 raeburn 6080: table.LC_pick_box td.LC_pick_box_value {
6081: text-align: left;
6082: padding: 8px;
6083: }
1.795 www 6084:
1.579 raeburn 6085: table.LC_pick_box td.LC_pick_box_select {
6086: text-align: left;
6087: padding: 8px;
6088: }
1.795 www 6089:
1.424 albertel 6090: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6091: padding: 0;
1.421 albertel 6092: height: 1px;
6093: background: black;
6094: }
1.795 www 6095:
1.421 albertel 6096: table.LC_pick_box td.LC_pick_box_submit {
6097: text-align: right;
6098: }
1.795 www 6099:
1.579 raeburn 6100: table.LC_pick_box td.LC_evenrow_value {
6101: text-align: left;
6102: padding: 8px;
6103: background-color: $data_table_light;
6104: }
1.795 www 6105:
1.579 raeburn 6106: table.LC_pick_box td.LC_oddrow_value {
6107: text-align: left;
6108: padding: 8px;
6109: background-color: $data_table_light;
6110: }
1.795 www 6111:
1.579 raeburn 6112: span.LC_helpform_receipt_cat {
6113: font-weight: bold;
6114: }
1.795 www 6115:
1.424 albertel 6116: table.LC_group_priv_box {
6117: background: white;
6118: border: 1px solid black;
6119: border-spacing: 1px;
6120: }
1.795 www 6121:
1.424 albertel 6122: table.LC_group_priv_box td.LC_pick_box_title {
6123: background: $tabbg;
6124: font-weight: bold;
6125: text-align: right;
6126: width: 184px;
6127: }
1.795 www 6128:
1.424 albertel 6129: table.LC_group_priv_box td.LC_groups_fixed {
6130: background: $data_table_light;
6131: text-align: center;
6132: }
1.795 www 6133:
1.424 albertel 6134: table.LC_group_priv_box td.LC_groups_optional {
6135: background: $data_table_dark;
6136: text-align: center;
6137: }
1.795 www 6138:
1.424 albertel 6139: table.LC_group_priv_box td.LC_groups_functionality {
6140: background: $data_table_darker;
6141: text-align: center;
6142: font-weight: bold;
6143: }
1.795 www 6144:
1.424 albertel 6145: table.LC_group_priv td {
6146: text-align: left;
1.803 bisitz 6147: padding: 0;
1.424 albertel 6148: }
6149:
6150: .LC_navbuttons {
6151: margin: 2ex 0ex 2ex 0ex;
6152: }
1.795 www 6153:
1.423 albertel 6154: .LC_topic_bar {
6155: font-weight: bold;
6156: background: $tabbg;
1.918 wenzelju 6157: margin: 1em 0em 1em 2em;
1.805 bisitz 6158: padding: 3px;
1.918 wenzelju 6159: font-size: 1.2em;
1.423 albertel 6160: }
1.795 www 6161:
1.423 albertel 6162: .LC_topic_bar span {
1.918 wenzelju 6163: left: 0.5em;
6164: position: absolute;
1.423 albertel 6165: vertical-align: middle;
1.918 wenzelju 6166: font-size: 1.2em;
1.423 albertel 6167: }
1.795 www 6168:
1.423 albertel 6169: table.LC_course_group_status {
6170: margin: 20px;
6171: }
1.795 www 6172:
1.423 albertel 6173: table.LC_status_selector td {
6174: vertical-align: top;
6175: text-align: center;
1.424 albertel 6176: padding: 4px;
6177: }
1.795 www 6178:
1.599 albertel 6179: div.LC_feedback_link {
1.616 albertel 6180: clear: both;
1.829 kalberla 6181: background: $sidebg;
1.779 bisitz 6182: width: 100%;
1.829 kalberla 6183: padding-bottom: 10px;
6184: border: 1px $tabbg solid;
1.833 kalberla 6185: height: 22px;
6186: line-height: 22px;
6187: padding-top: 5px;
6188: }
6189:
6190: div.LC_feedback_link img {
6191: height: 22px;
1.867 kalberla 6192: vertical-align:middle;
1.829 kalberla 6193: }
6194:
1.911 bisitz 6195: div.LC_feedback_link a {
1.829 kalberla 6196: text-decoration: none;
1.489 raeburn 6197: }
1.795 www 6198:
1.867 kalberla 6199: div.LC_comblock {
1.911 bisitz 6200: display:inline;
1.867 kalberla 6201: color:$font;
6202: font-size:90%;
6203: }
6204:
6205: div.LC_feedback_link div.LC_comblock {
6206: padding-left:5px;
6207: }
6208:
6209: div.LC_feedback_link div.LC_comblock a {
6210: color:$font;
6211: }
6212:
1.489 raeburn 6213: span.LC_feedback_link {
1.858 bisitz 6214: /* background: $feedback_link_bg; */
1.599 albertel 6215: font-size: larger;
6216: }
1.795 www 6217:
1.599 albertel 6218: span.LC_message_link {
1.858 bisitz 6219: /* background: $feedback_link_bg; */
1.599 albertel 6220: font-size: larger;
6221: position: absolute;
6222: right: 1em;
1.489 raeburn 6223: }
1.421 albertel 6224:
1.515 albertel 6225: table.LC_prior_tries {
1.524 albertel 6226: border: 1px solid #000000;
6227: border-collapse: separate;
6228: border-spacing: 1px;
1.515 albertel 6229: }
1.523 albertel 6230:
1.515 albertel 6231: table.LC_prior_tries td {
1.524 albertel 6232: padding: 2px;
1.515 albertel 6233: }
1.523 albertel 6234:
6235: .LC_answer_correct {
1.795 www 6236: background: lightgreen;
6237: color: darkgreen;
6238: padding: 6px;
1.523 albertel 6239: }
1.795 www 6240:
1.523 albertel 6241: .LC_answer_charged_try {
1.797 www 6242: background: #FFAAAA;
1.795 www 6243: color: darkred;
6244: padding: 6px;
1.523 albertel 6245: }
1.795 www 6246:
1.779 bisitz 6247: .LC_answer_not_charged_try,
1.523 albertel 6248: .LC_answer_no_grade,
6249: .LC_answer_late {
1.795 www 6250: background: lightyellow;
1.523 albertel 6251: color: black;
1.795 www 6252: padding: 6px;
1.523 albertel 6253: }
1.795 www 6254:
1.523 albertel 6255: .LC_answer_previous {
1.795 www 6256: background: lightblue;
6257: color: darkblue;
6258: padding: 6px;
1.523 albertel 6259: }
1.795 www 6260:
1.779 bisitz 6261: .LC_answer_no_message {
1.777 tempelho 6262: background: #FFFFFF;
6263: color: black;
1.795 www 6264: padding: 6px;
1.779 bisitz 6265: }
1.795 www 6266:
1.779 bisitz 6267: .LC_answer_unknown {
6268: background: orange;
6269: color: black;
1.795 www 6270: padding: 6px;
1.777 tempelho 6271: }
1.795 www 6272:
1.529 albertel 6273: span.LC_prior_numerical,
6274: span.LC_prior_string,
6275: span.LC_prior_custom,
6276: span.LC_prior_reaction,
6277: span.LC_prior_math {
1.925 bisitz 6278: font-family: $mono;
1.523 albertel 6279: white-space: pre;
6280: }
6281:
1.525 albertel 6282: span.LC_prior_string {
1.925 bisitz 6283: font-family: $mono;
1.525 albertel 6284: white-space: pre;
6285: }
6286:
1.523 albertel 6287: table.LC_prior_option {
6288: width: 100%;
6289: border-collapse: collapse;
6290: }
1.795 www 6291:
1.911 bisitz 6292: table.LC_prior_rank,
1.795 www 6293: table.LC_prior_match {
1.528 albertel 6294: border-collapse: collapse;
6295: }
1.795 www 6296:
1.528 albertel 6297: table.LC_prior_option tr td,
6298: table.LC_prior_rank tr td,
6299: table.LC_prior_match tr td {
1.524 albertel 6300: border: 1px solid #000000;
1.515 albertel 6301: }
6302:
1.855 bisitz 6303: .LC_nobreak {
1.544 albertel 6304: white-space: nowrap;
1.519 raeburn 6305: }
6306:
1.576 raeburn 6307: span.LC_cusr_emph {
6308: font-style: italic;
6309: }
6310:
1.633 raeburn 6311: span.LC_cusr_subheading {
6312: font-weight: normal;
6313: font-size: 85%;
6314: }
6315:
1.861 bisitz 6316: div.LC_docs_entry_move {
1.859 bisitz 6317: border: 1px solid #BBBBBB;
1.545 albertel 6318: background: #DDDDDD;
1.861 bisitz 6319: width: 22px;
1.859 bisitz 6320: padding: 1px;
6321: margin: 0;
1.545 albertel 6322: }
6323:
1.861 bisitz 6324: table.LC_data_table tr > td.LC_docs_entry_commands,
6325: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6326: font-size: x-small;
6327: }
1.795 www 6328:
1.861 bisitz 6329: .LC_docs_entry_parameter {
6330: white-space: nowrap;
6331: }
6332:
1.544 albertel 6333: .LC_docs_copy {
1.545 albertel 6334: color: #000099;
1.544 albertel 6335: }
1.795 www 6336:
1.544 albertel 6337: .LC_docs_cut {
1.545 albertel 6338: color: #550044;
1.544 albertel 6339: }
1.795 www 6340:
1.544 albertel 6341: .LC_docs_rename {
1.545 albertel 6342: color: #009900;
1.544 albertel 6343: }
1.795 www 6344:
1.544 albertel 6345: .LC_docs_remove {
1.545 albertel 6346: color: #990000;
6347: }
6348:
1.547 albertel 6349: .LC_docs_reinit_warn,
6350: .LC_docs_ext_edit {
6351: font-size: x-small;
6352: }
6353:
1.545 albertel 6354: table.LC_docs_adddocs td,
6355: table.LC_docs_adddocs th {
6356: border: 1px solid #BBBBBB;
6357: padding: 4px;
6358: background: #DDDDDD;
1.543 albertel 6359: }
6360:
1.584 albertel 6361: table.LC_sty_begin {
6362: background: #BBFFBB;
6363: }
1.795 www 6364:
1.584 albertel 6365: table.LC_sty_end {
6366: background: #FFBBBB;
6367: }
6368:
1.589 raeburn 6369: table.LC_double_column {
1.803 bisitz 6370: border-width: 0;
1.589 raeburn 6371: border-collapse: collapse;
6372: width: 100%;
6373: padding: 2px;
6374: }
6375:
6376: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6377: top: 2px;
1.589 raeburn 6378: left: 2px;
6379: width: 47%;
6380: vertical-align: top;
6381: }
6382:
6383: table.LC_double_column tr td.LC_right_col {
6384: top: 2px;
1.779 bisitz 6385: right: 2px;
1.589 raeburn 6386: width: 47%;
6387: vertical-align: top;
6388: }
6389:
1.591 raeburn 6390: div.LC_left_float {
6391: float: left;
6392: padding-right: 5%;
1.597 albertel 6393: padding-bottom: 4px;
1.591 raeburn 6394: }
6395:
6396: div.LC_clear_float_header {
1.597 albertel 6397: padding-bottom: 2px;
1.591 raeburn 6398: }
6399:
6400: div.LC_clear_float_footer {
1.597 albertel 6401: padding-top: 10px;
1.591 raeburn 6402: clear: both;
6403: }
6404:
1.597 albertel 6405: div.LC_grade_show_user {
1.941 bisitz 6406: /* border-left: 5px solid $sidebg; */
6407: border-top: 5px solid #000000;
6408: margin: 50px 0 0 0;
1.936 bisitz 6409: padding: 15px 0 5px 10px;
1.597 albertel 6410: }
1.795 www 6411:
1.936 bisitz 6412: div.LC_grade_show_user_odd_row {
1.941 bisitz 6413: /* border-left: 5px solid #000000; */
6414: }
6415:
6416: div.LC_grade_show_user div.LC_Box {
6417: margin-right: 50px;
1.597 albertel 6418: }
6419:
6420: div.LC_grade_submissions,
6421: div.LC_grade_message_center,
1.936 bisitz 6422: div.LC_grade_info_links {
1.597 albertel 6423: margin: 5px;
6424: width: 99%;
6425: background: #FFFFFF;
6426: }
1.795 www 6427:
1.597 albertel 6428: div.LC_grade_submissions_header,
1.936 bisitz 6429: div.LC_grade_message_center_header {
1.705 tempelho 6430: font-weight: bold;
6431: font-size: large;
1.597 albertel 6432: }
1.795 www 6433:
1.597 albertel 6434: div.LC_grade_submissions_body,
1.936 bisitz 6435: div.LC_grade_message_center_body {
1.597 albertel 6436: border: 1px solid black;
6437: width: 99%;
6438: background: #FFFFFF;
6439: }
1.795 www 6440:
1.613 albertel 6441: table.LC_scantron_action {
6442: width: 100%;
6443: }
1.795 www 6444:
1.613 albertel 6445: table.LC_scantron_action tr th {
1.698 harmsja 6446: font-weight:bold;
6447: font-style:normal;
1.613 albertel 6448: }
1.795 www 6449:
1.779 bisitz 6450: .LC_edit_problem_header,
1.614 albertel 6451: div.LC_edit_problem_footer {
1.705 tempelho 6452: font-weight: normal;
6453: font-size: medium;
1.602 albertel 6454: margin: 2px;
1.1060 bisitz 6455: background-color: $sidebg;
1.600 albertel 6456: }
1.795 www 6457:
1.600 albertel 6458: div.LC_edit_problem_header,
1.602 albertel 6459: div.LC_edit_problem_header div,
1.614 albertel 6460: div.LC_edit_problem_footer,
6461: div.LC_edit_problem_footer div,
1.602 albertel 6462: div.LC_edit_problem_editxml_header,
6463: div.LC_edit_problem_editxml_header div {
1.600 albertel 6464: margin-top: 5px;
6465: }
1.795 www 6466:
1.600 albertel 6467: div.LC_edit_problem_header_title {
1.705 tempelho 6468: font-weight: bold;
6469: font-size: larger;
1.602 albertel 6470: background: $tabbg;
6471: padding: 3px;
1.1060 bisitz 6472: margin: 0 0 5px 0;
1.602 albertel 6473: }
1.795 www 6474:
1.602 albertel 6475: table.LC_edit_problem_header_title {
6476: width: 100%;
1.600 albertel 6477: background: $tabbg;
1.602 albertel 6478: }
6479:
6480: div.LC_edit_problem_discards {
6481: float: left;
6482: padding-bottom: 5px;
6483: }
1.795 www 6484:
1.602 albertel 6485: div.LC_edit_problem_saves {
6486: float: right;
6487: padding-bottom: 5px;
1.600 albertel 6488: }
1.795 www 6489:
1.1124 bisitz 6490: .LC_edit_opt {
6491: padding-left: 1em;
6492: white-space: nowrap;
6493: }
6494:
1.911 bisitz 6495: img.stift {
1.803 bisitz 6496: border-width: 0;
6497: vertical-align: middle;
1.677 riegler 6498: }
1.680 riegler 6499:
1.923 bisitz 6500: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6501: vertical-align: top;
1.777 tempelho 6502: }
1.795 www 6503:
1.716 raeburn 6504: div.LC_createcourse {
1.911 bisitz 6505: margin: 10px 10px 10px 10px;
1.716 raeburn 6506: }
6507:
1.917 raeburn 6508: .LC_dccid {
1.1130 raeburn 6509: float: right;
1.917 raeburn 6510: margin: 0.2em 0 0 0;
6511: padding: 0;
6512: font-size: 90%;
6513: display:none;
6514: }
6515:
1.897 wenzelju 6516: ol.LC_primary_menu a:hover,
1.721 harmsja 6517: ol#LC_MenuBreadcrumbs a:hover,
6518: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6519: ul#LC_secondary_menu a:hover,
1.721 harmsja 6520: .LC_FormSectionClearButton input:hover
1.795 www 6521: ul.LC_TabContent li:hover a {
1.952 onken 6522: color:$button_hover;
1.911 bisitz 6523: text-decoration:none;
1.693 droeschl 6524: }
6525:
1.779 bisitz 6526: h1 {
1.911 bisitz 6527: padding: 0;
6528: line-height:130%;
1.693 droeschl 6529: }
1.698 harmsja 6530:
1.911 bisitz 6531: h2,
6532: h3,
6533: h4,
6534: h5,
6535: h6 {
6536: margin: 5px 0 5px 0;
6537: padding: 0;
6538: line-height:130%;
1.693 droeschl 6539: }
1.795 www 6540:
6541: .LC_hcell {
1.911 bisitz 6542: padding:3px 15px 3px 15px;
6543: margin: 0;
6544: background-color:$tabbg;
6545: color:$fontmenu;
6546: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6547: }
1.795 www 6548:
1.840 bisitz 6549: .LC_Box > .LC_hcell {
1.911 bisitz 6550: margin: 0 -10px 10px -10px;
1.835 bisitz 6551: }
6552:
1.721 harmsja 6553: .LC_noBorder {
1.911 bisitz 6554: border: 0;
1.698 harmsja 6555: }
1.693 droeschl 6556:
1.721 harmsja 6557: .LC_FormSectionClearButton input {
1.911 bisitz 6558: background-color:transparent;
6559: border: none;
6560: cursor:pointer;
6561: text-decoration:underline;
1.693 droeschl 6562: }
1.763 bisitz 6563:
6564: .LC_help_open_topic {
1.911 bisitz 6565: color: #FFFFFF;
6566: background-color: #EEEEFF;
6567: margin: 1px;
6568: padding: 4px;
6569: border: 1px solid #000033;
6570: white-space: nowrap;
6571: /* vertical-align: middle; */
1.759 neumanie 6572: }
1.693 droeschl 6573:
1.911 bisitz 6574: dl,
6575: ul,
6576: div,
6577: fieldset {
6578: margin: 10px 10px 10px 0;
6579: /* overflow: hidden; */
1.693 droeschl 6580: }
1.795 www 6581:
1.838 bisitz 6582: fieldset > legend {
1.911 bisitz 6583: font-weight: bold;
6584: padding: 0 5px 0 5px;
1.838 bisitz 6585: }
6586:
1.813 bisitz 6587: #LC_nav_bar {
1.911 bisitz 6588: float: left;
1.995 raeburn 6589: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6590: margin: 0 0 2px 0;
1.807 droeschl 6591: }
6592:
1.916 droeschl 6593: #LC_realm {
6594: margin: 0.2em 0 0 0;
6595: padding: 0;
6596: font-weight: bold;
6597: text-align: center;
1.995 raeburn 6598: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6599: }
6600:
1.911 bisitz 6601: #LC_nav_bar em {
6602: font-weight: bold;
6603: font-style: normal;
1.807 droeschl 6604: }
6605:
1.897 wenzelju 6606: ol.LC_primary_menu {
1.934 droeschl 6607: margin: 0;
1.1076 raeburn 6608: padding: 0;
1.995 raeburn 6609: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6610: }
6611:
1.852 droeschl 6612: ol#LC_PathBreadcrumbs {
1.911 bisitz 6613: margin: 0;
1.693 droeschl 6614: }
6615:
1.897 wenzelju 6616: ol.LC_primary_menu li {
1.1076 raeburn 6617: color: RGB(80, 80, 80);
6618: vertical-align: middle;
6619: text-align: left;
6620: list-style: none;
6621: float: left;
6622: }
6623:
6624: ol.LC_primary_menu li a {
6625: display: block;
6626: margin: 0;
6627: padding: 0 5px 0 10px;
6628: text-decoration: none;
6629: }
6630:
6631: ol.LC_primary_menu li ul {
6632: display: none;
6633: width: 10em;
6634: background-color: $data_table_light;
6635: }
6636:
6637: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6638: display: block;
6639: position: absolute;
6640: margin: 0;
6641: padding: 0;
1.1078 raeburn 6642: z-index: 2;
1.1076 raeburn 6643: }
6644:
6645: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6646: font-size: 90%;
1.911 bisitz 6647: vertical-align: top;
1.1076 raeburn 6648: float: none;
1.1079 raeburn 6649: border-left: 1px solid black;
6650: border-right: 1px solid black;
1.1076 raeburn 6651: }
6652:
6653: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1078 raeburn 6654: background-color:$data_table_light;
1.1076 raeburn 6655: }
6656:
6657: ol.LC_primary_menu li li a:hover {
6658: color:$button_hover;
6659: background-color:$data_table_dark;
1.693 droeschl 6660: }
6661:
1.897 wenzelju 6662: ol.LC_primary_menu li img {
1.911 bisitz 6663: vertical-align: bottom;
1.934 droeschl 6664: height: 1.1em;
1.1077 raeburn 6665: margin: 0.2em 0 0 0;
1.693 droeschl 6666: }
6667:
1.897 wenzelju 6668: ol.LC_primary_menu a {
1.911 bisitz 6669: color: RGB(80, 80, 80);
6670: text-decoration: none;
1.693 droeschl 6671: }
1.795 www 6672:
1.949 droeschl 6673: ol.LC_primary_menu a.LC_new_message {
6674: font-weight:bold;
6675: color: darkred;
6676: }
6677:
1.975 raeburn 6678: ol.LC_docs_parameters {
6679: margin-left: 0;
6680: padding: 0;
6681: list-style: none;
6682: }
6683:
6684: ol.LC_docs_parameters li {
6685: margin: 0;
6686: padding-right: 20px;
6687: display: inline;
6688: }
6689:
1.976 raeburn 6690: ol.LC_docs_parameters li:before {
6691: content: "\\002022 \\0020";
6692: }
6693:
6694: li.LC_docs_parameters_title {
6695: font-weight: bold;
6696: }
6697:
6698: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6699: content: "";
6700: }
6701:
1.897 wenzelju 6702: ul#LC_secondary_menu {
1.1107 raeburn 6703: clear: right;
1.911 bisitz 6704: color: $fontmenu;
6705: background: $tabbg;
6706: list-style: none;
6707: padding: 0;
6708: margin: 0;
6709: width: 100%;
1.995 raeburn 6710: text-align: left;
1.1107 raeburn 6711: float: left;
1.808 droeschl 6712: }
6713:
1.897 wenzelju 6714: ul#LC_secondary_menu li {
1.911 bisitz 6715: font-weight: bold;
6716: line-height: 1.8em;
1.1107 raeburn 6717: border-right: 1px solid black;
6718: float: left;
6719: }
6720:
6721: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6722: background-color: $data_table_light;
6723: }
6724:
6725: ul#LC_secondary_menu li a {
1.911 bisitz 6726: padding: 0 0.8em;
1.1107 raeburn 6727: }
6728:
6729: ul#LC_secondary_menu li ul {
6730: display: none;
6731: }
6732:
6733: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6734: display: block;
6735: position: absolute;
6736: margin: 0;
6737: padding: 0;
6738: list-style:none;
6739: float: none;
6740: background-color: $data_table_light;
6741: z-index: 2;
6742: margin-left: -1px;
6743: }
6744:
6745: ul#LC_secondary_menu li ul li {
6746: font-size: 90%;
6747: vertical-align: top;
6748: border-left: 1px solid black;
1.911 bisitz 6749: border-right: 1px solid black;
1.1119 raeburn 6750: background-color: $data_table_light;
1.1107 raeburn 6751: list-style:none;
6752: float: none;
6753: }
6754:
6755: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6756: background-color: $data_table_dark;
1.807 droeschl 6757: }
6758:
1.847 tempelho 6759: ul.LC_TabContent {
1.911 bisitz 6760: display:block;
6761: background: $sidebg;
6762: border-bottom: solid 1px $lg_border_color;
6763: list-style:none;
1.1020 raeburn 6764: margin: -1px -10px 0 -10px;
1.911 bisitz 6765: padding: 0;
1.693 droeschl 6766: }
6767:
1.795 www 6768: ul.LC_TabContent li,
6769: ul.LC_TabContentBigger li {
1.911 bisitz 6770: float:left;
1.741 harmsja 6771: }
1.795 www 6772:
1.897 wenzelju 6773: ul#LC_secondary_menu li a {
1.911 bisitz 6774: color: $fontmenu;
6775: text-decoration: none;
1.693 droeschl 6776: }
1.795 www 6777:
1.721 harmsja 6778: ul.LC_TabContent {
1.952 onken 6779: min-height:20px;
1.721 harmsja 6780: }
1.795 www 6781:
6782: ul.LC_TabContent li {
1.911 bisitz 6783: vertical-align:middle;
1.959 onken 6784: padding: 0 16px 0 10px;
1.911 bisitz 6785: background-color:$tabbg;
6786: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6787: border-left: solid 1px $font;
1.721 harmsja 6788: }
1.795 www 6789:
1.847 tempelho 6790: ul.LC_TabContent .right {
1.911 bisitz 6791: float:right;
1.847 tempelho 6792: }
6793:
1.911 bisitz 6794: ul.LC_TabContent li a,
6795: ul.LC_TabContent li {
6796: color:rgb(47,47,47);
6797: text-decoration:none;
6798: font-size:95%;
6799: font-weight:bold;
1.952 onken 6800: min-height:20px;
6801: }
6802:
1.959 onken 6803: ul.LC_TabContent li a:hover,
6804: ul.LC_TabContent li a:focus {
1.952 onken 6805: color: $button_hover;
1.959 onken 6806: background:none;
6807: outline:none;
1.952 onken 6808: }
6809:
6810: ul.LC_TabContent li:hover {
6811: color: $button_hover;
6812: cursor:pointer;
1.721 harmsja 6813: }
1.795 www 6814:
1.911 bisitz 6815: ul.LC_TabContent li.active {
1.952 onken 6816: color: $font;
1.911 bisitz 6817: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6818: border-bottom:solid 1px #FFFFFF;
6819: cursor: default;
1.744 ehlerst 6820: }
1.795 www 6821:
1.959 onken 6822: ul.LC_TabContent li.active a {
6823: color:$font;
6824: background:#FFFFFF;
6825: outline: none;
6826: }
1.1047 raeburn 6827:
6828: ul.LC_TabContent li.goback {
6829: float: left;
6830: border-left: none;
6831: }
6832:
1.870 tempelho 6833: #maincoursedoc {
1.911 bisitz 6834: clear:both;
1.870 tempelho 6835: }
6836:
6837: ul.LC_TabContentBigger {
1.911 bisitz 6838: display:block;
6839: list-style:none;
6840: padding: 0;
1.870 tempelho 6841: }
6842:
1.795 www 6843: ul.LC_TabContentBigger li {
1.911 bisitz 6844: vertical-align:bottom;
6845: height: 30px;
6846: font-size:110%;
6847: font-weight:bold;
6848: color: #737373;
1.841 tempelho 6849: }
6850:
1.957 onken 6851: ul.LC_TabContentBigger li.active {
6852: position: relative;
6853: top: 1px;
6854: }
6855:
1.870 tempelho 6856: ul.LC_TabContentBigger li a {
1.911 bisitz 6857: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6858: height: 30px;
6859: line-height: 30px;
6860: text-align: center;
6861: display: block;
6862: text-decoration: none;
1.958 onken 6863: outline: none;
1.741 harmsja 6864: }
1.795 www 6865:
1.870 tempelho 6866: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6867: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6868: color:$font;
1.744 ehlerst 6869: }
1.795 www 6870:
1.870 tempelho 6871: ul.LC_TabContentBigger li b {
1.911 bisitz 6872: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6873: display: block;
6874: float: left;
6875: padding: 0 30px;
1.957 onken 6876: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6877: }
6878:
1.956 onken 6879: ul.LC_TabContentBigger li:hover b {
6880: color:$button_hover;
6881: }
6882:
1.870 tempelho 6883: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6884: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6885: color:$font;
1.957 onken 6886: border: 0;
1.741 harmsja 6887: }
1.693 droeschl 6888:
1.870 tempelho 6889:
1.862 bisitz 6890: ul.LC_CourseBreadcrumbs {
6891: background: $sidebg;
1.1020 raeburn 6892: height: 2em;
1.862 bisitz 6893: padding-left: 10px;
1.1020 raeburn 6894: margin: 0;
1.862 bisitz 6895: list-style-position: inside;
6896: }
6897:
1.911 bisitz 6898: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6899: ol#LC_PathBreadcrumbs {
1.911 bisitz 6900: padding-left: 10px;
6901: margin: 0;
1.933 droeschl 6902: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6903: }
6904:
1.911 bisitz 6905: ol#LC_MenuBreadcrumbs li,
6906: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6907: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6908: display: inline;
1.933 droeschl 6909: white-space: normal;
1.693 droeschl 6910: }
6911:
1.823 bisitz 6912: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6913: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6914: text-decoration: none;
6915: font-size:90%;
1.693 droeschl 6916: }
1.795 www 6917:
1.969 droeschl 6918: ol#LC_MenuBreadcrumbs h1 {
6919: display: inline;
6920: font-size: 90%;
6921: line-height: 2.5em;
6922: margin: 0;
6923: padding: 0;
6924: }
6925:
1.795 www 6926: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6927: text-decoration:none;
6928: font-size:100%;
6929: font-weight:bold;
1.693 droeschl 6930: }
1.795 www 6931:
1.840 bisitz 6932: .LC_Box {
1.911 bisitz 6933: border: solid 1px $lg_border_color;
6934: padding: 0 10px 10px 10px;
1.746 neumanie 6935: }
1.795 www 6936:
1.1020 raeburn 6937: .LC_DocsBox {
6938: border: solid 1px $lg_border_color;
6939: padding: 0 0 10px 10px;
6940: }
6941:
1.795 www 6942: .LC_AboutMe_Image {
1.911 bisitz 6943: float:left;
6944: margin-right:10px;
1.747 neumanie 6945: }
1.795 www 6946:
6947: .LC_Clear_AboutMe_Image {
1.911 bisitz 6948: clear:left;
1.747 neumanie 6949: }
1.795 www 6950:
1.721 harmsja 6951: dl.LC_ListStyleClean dt {
1.911 bisitz 6952: padding-right: 5px;
6953: display: table-header-group;
1.693 droeschl 6954: }
6955:
1.721 harmsja 6956: dl.LC_ListStyleClean dd {
1.911 bisitz 6957: display: table-row;
1.693 droeschl 6958: }
6959:
1.721 harmsja 6960: .LC_ListStyleClean,
6961: .LC_ListStyleSimple,
6962: .LC_ListStyleNormal,
1.795 www 6963: .LC_ListStyleSpecial {
1.911 bisitz 6964: /* display:block; */
6965: list-style-position: inside;
6966: list-style-type: none;
6967: overflow: hidden;
6968: padding: 0;
1.693 droeschl 6969: }
6970:
1.721 harmsja 6971: .LC_ListStyleSimple li,
6972: .LC_ListStyleSimple dd,
6973: .LC_ListStyleNormal li,
6974: .LC_ListStyleNormal dd,
6975: .LC_ListStyleSpecial li,
1.795 www 6976: .LC_ListStyleSpecial dd {
1.911 bisitz 6977: margin: 0;
6978: padding: 5px 5px 5px 10px;
6979: clear: both;
1.693 droeschl 6980: }
6981:
1.721 harmsja 6982: .LC_ListStyleClean li,
6983: .LC_ListStyleClean dd {
1.911 bisitz 6984: padding-top: 0;
6985: padding-bottom: 0;
1.693 droeschl 6986: }
6987:
1.721 harmsja 6988: .LC_ListStyleSimple dd,
1.795 www 6989: .LC_ListStyleSimple li {
1.911 bisitz 6990: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6991: }
6992:
1.721 harmsja 6993: .LC_ListStyleSpecial li,
6994: .LC_ListStyleSpecial dd {
1.911 bisitz 6995: list-style-type: none;
6996: background-color: RGB(220, 220, 220);
6997: margin-bottom: 4px;
1.693 droeschl 6998: }
6999:
1.721 harmsja 7000: table.LC_SimpleTable {
1.911 bisitz 7001: margin:5px;
7002: border:solid 1px $lg_border_color;
1.795 www 7003: }
1.693 droeschl 7004:
1.721 harmsja 7005: table.LC_SimpleTable tr {
1.911 bisitz 7006: padding: 0;
7007: border:solid 1px $lg_border_color;
1.693 droeschl 7008: }
1.795 www 7009:
7010: table.LC_SimpleTable thead {
1.911 bisitz 7011: background:rgb(220,220,220);
1.693 droeschl 7012: }
7013:
1.721 harmsja 7014: div.LC_columnSection {
1.911 bisitz 7015: display: block;
7016: clear: both;
7017: overflow: hidden;
7018: margin: 0;
1.693 droeschl 7019: }
7020:
1.721 harmsja 7021: div.LC_columnSection>* {
1.911 bisitz 7022: float: left;
7023: margin: 10px 20px 10px 0;
7024: overflow:hidden;
1.693 droeschl 7025: }
1.721 harmsja 7026:
1.795 www 7027: table em {
1.911 bisitz 7028: font-weight: bold;
7029: font-style: normal;
1.748 schulted 7030: }
1.795 www 7031:
1.779 bisitz 7032: table.LC_tableBrowseRes,
1.795 www 7033: table.LC_tableOfContent {
1.911 bisitz 7034: border:none;
7035: border-spacing: 1px;
7036: padding: 3px;
7037: background-color: #FFFFFF;
7038: font-size: 90%;
1.753 droeschl 7039: }
1.789 droeschl 7040:
1.911 bisitz 7041: table.LC_tableOfContent {
7042: border-collapse: collapse;
1.789 droeschl 7043: }
7044:
1.771 droeschl 7045: table.LC_tableBrowseRes a,
1.768 schulted 7046: table.LC_tableOfContent a {
1.911 bisitz 7047: background-color: transparent;
7048: text-decoration: none;
1.753 droeschl 7049: }
7050:
1.795 www 7051: table.LC_tableOfContent img {
1.911 bisitz 7052: border: none;
7053: height: 1.3em;
7054: vertical-align: text-bottom;
7055: margin-right: 0.3em;
1.753 droeschl 7056: }
1.757 schulted 7057:
1.795 www 7058: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7059: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7060: }
7061:
1.795 www 7062: a#LC_content_toolbar_everything {
1.911 bisitz 7063: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7064: }
7065:
1.795 www 7066: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7067: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7068: }
7069:
1.795 www 7070: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7071: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7072: }
7073:
1.795 www 7074: a#LC_content_toolbar_changefolder {
1.911 bisitz 7075: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7076: }
7077:
1.795 www 7078: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7079: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7080: }
7081:
1.1043 raeburn 7082: a#LC_content_toolbar_edittoplevel {
7083: background-image:url(/res/adm/pages/edittoplevel.gif);
7084: }
7085:
1.795 www 7086: ul#LC_toolbar li a:hover {
1.911 bisitz 7087: background-position: bottom center;
1.757 schulted 7088: }
7089:
1.795 www 7090: ul#LC_toolbar {
1.911 bisitz 7091: padding: 0;
7092: margin: 2px;
7093: list-style:none;
7094: position:relative;
7095: background-color:white;
1.1082 raeburn 7096: overflow: auto;
1.757 schulted 7097: }
7098:
1.795 www 7099: ul#LC_toolbar li {
1.911 bisitz 7100: border:1px solid white;
7101: padding: 0;
7102: margin: 0;
7103: float: left;
7104: display:inline;
7105: vertical-align:middle;
1.1082 raeburn 7106: white-space: nowrap;
1.911 bisitz 7107: }
1.757 schulted 7108:
1.783 amueller 7109:
1.795 www 7110: a.LC_toolbarItem {
1.911 bisitz 7111: display:block;
7112: padding: 0;
7113: margin: 0;
7114: height: 32px;
7115: width: 32px;
7116: color:white;
7117: border: none;
7118: background-repeat:no-repeat;
7119: background-color:transparent;
1.757 schulted 7120: }
7121:
1.915 droeschl 7122: ul.LC_funclist {
7123: margin: 0;
7124: padding: 0.5em 1em 0.5em 0;
7125: }
7126:
1.933 droeschl 7127: ul.LC_funclist > li:first-child {
7128: font-weight:bold;
7129: margin-left:0.8em;
7130: }
7131:
1.915 droeschl 7132: ul.LC_funclist + ul.LC_funclist {
7133: /*
7134: left border as a seperator if we have more than
7135: one list
7136: */
7137: border-left: 1px solid $sidebg;
7138: /*
7139: this hides the left border behind the border of the
7140: outer box if element is wrapped to the next 'line'
7141: */
7142: margin-left: -1px;
7143: }
7144:
1.843 bisitz 7145: ul.LC_funclist li {
1.915 droeschl 7146: display: inline;
1.782 bisitz 7147: white-space: nowrap;
1.915 droeschl 7148: margin: 0 0 0 25px;
7149: line-height: 150%;
1.782 bisitz 7150: }
7151:
1.974 wenzelju 7152: .LC_hidden {
7153: display: none;
7154: }
7155:
1.1030 www 7156: .LCmodal-overlay {
7157: position:fixed;
7158: top:0;
7159: right:0;
7160: bottom:0;
7161: left:0;
7162: height:100%;
7163: width:100%;
7164: margin:0;
7165: padding:0;
7166: background:#999;
7167: opacity:.75;
7168: filter: alpha(opacity=75);
7169: -moz-opacity: 0.75;
7170: z-index:101;
7171: }
7172:
7173: * html .LCmodal-overlay {
7174: position: absolute;
7175: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7176: }
7177:
7178: .LCmodal-window {
7179: position:fixed;
7180: top:50%;
7181: left:50%;
7182: margin:0;
7183: padding:0;
7184: z-index:102;
7185: }
7186:
7187: * html .LCmodal-window {
7188: position:absolute;
7189: }
7190:
7191: .LCclose-window {
7192: position:absolute;
7193: width:32px;
7194: height:32px;
7195: right:8px;
7196: top:8px;
7197: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7198: text-indent:-99999px;
7199: overflow:hidden;
7200: cursor:pointer;
7201: }
7202:
1.1100 raeburn 7203: /*
7204: styles used by TTH when "Default set of options to pass to tth/m
7205: when converting TeX" in course settings has been set
7206:
7207: option passed: -t
7208:
7209: */
7210:
7211: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7212: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7213: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7214: td div.norm {line-height:normal;}
7215:
7216: /*
7217: option passed -y3
7218: */
7219:
7220: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7221: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7222: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7223:
1.343 albertel 7224: END
7225: }
7226:
1.306 albertel 7227: =pod
7228:
7229: =item * &headtag()
7230:
7231: Returns a uniform footer for LON-CAPA web pages.
7232:
1.307 albertel 7233: Inputs: $title - optional title for the head
7234: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7235: $args - optional arguments
1.319 albertel 7236: force_register - if is true call registerurl so the remote is
7237: informed
1.415 albertel 7238: redirect -> array ref of
7239: 1- seconds before redirect occurs
7240: 2- url to redirect to
7241: 3- whether the side effect should occur
1.315 albertel 7242: (side effect of setting
7243: $env{'internal.head.redirect'} to the url
7244: redirected too)
1.352 albertel 7245: domain -> force to color decorate a page for a specific
7246: domain
7247: function -> force usage of a specific rolish color scheme
7248: bgcolor -> override the default page bgcolor
1.460 albertel 7249: no_auto_mt_title
7250: -> prevent &mt()ing the title arg
1.464 albertel 7251:
1.306 albertel 7252: =cut
7253:
7254: sub headtag {
1.313 albertel 7255: my ($title,$head_extra,$args) = @_;
1.306 albertel 7256:
1.363 albertel 7257: my $function = $args->{'function'} || &get_users_function();
7258: my $domain = $args->{'domain'} || &determinedomain();
7259: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 7260: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7261: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7262: #time(),
1.418 albertel 7263: $env{'environment.color.timestamp'},
1.363 albertel 7264: $function,$domain,$bgcolor);
7265:
1.369 www 7266: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7267:
1.308 albertel 7268: my $result =
7269: '<head>'.
1.461 albertel 7270: &font_settings();
1.319 albertel 7271:
1.1064 raeburn 7272: my $inhibitprint = &print_suppression();
7273:
1.461 albertel 7274: if (!$args->{'frameset'}) {
7275: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7276: }
1.962 droeschl 7277: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7278: $result .= Apache::lonxml::display_title();
1.319 albertel 7279: }
1.436 albertel 7280: if (!$args->{'no_nav_bar'}
7281: && !$args->{'only_body'}
7282: && !$args->{'frameset'}) {
7283: $result .= &help_menu_js();
1.1032 www 7284: $result.=&modal_window();
1.1038 www 7285: $result.=&togglebox_script();
1.1034 www 7286: $result.=&wishlist_window();
1.1041 www 7287: $result.=&LCprogressbarUpdate_script();
1.1034 www 7288: } else {
7289: if ($args->{'add_modal'}) {
7290: $result.=&modal_window();
7291: }
7292: if ($args->{'add_wishlist'}) {
7293: $result.=&wishlist_window();
7294: }
1.1038 www 7295: if ($args->{'add_togglebox'}) {
7296: $result.=&togglebox_script();
7297: }
1.1041 www 7298: if ($args->{'add_progressbar'}) {
7299: $result.=&LCprogressbarUpdate_script();
7300: }
1.436 albertel 7301: }
1.314 albertel 7302: if (ref($args->{'redirect'})) {
1.414 albertel 7303: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7304: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7305: if (!$inhibit_continue) {
7306: $env{'internal.head.redirect'} = $url;
7307: }
1.313 albertel 7308: $result.=<<ADDMETA
7309: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7310: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7311: ADDMETA
7312: }
1.306 albertel 7313: if (!defined($title)) {
7314: $title = 'The LearningOnline Network with CAPA';
7315: }
1.460 albertel 7316: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7317: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 7318: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064 raeburn 7319: .$inhibitprint
1.414 albertel 7320: .$head_extra;
1.1137 raeburn 7321: if ($env{'browser.mobile'}) {
7322: $result .= '
7323: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7324: <meta name="apple-mobile-web-app-capable" content="yes" />';
7325: }
1.962 droeschl 7326: return $result.'</head>';
1.306 albertel 7327: }
7328:
7329: =pod
7330:
1.340 albertel 7331: =item * &font_settings()
7332:
7333: Returns neccessary <meta> to set the proper encoding
7334:
7335: Inputs: none
7336:
7337: =cut
7338:
7339: sub font_settings {
7340: my $headerstring='';
1.647 www 7341: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 7342: $headerstring.=
7343: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
7344: }
7345: return $headerstring;
7346: }
7347:
1.341 albertel 7348: =pod
7349:
1.1064 raeburn 7350: =item * &print_suppression()
7351:
7352: In course context returns css which causes the body to be blank when media="print",
7353: if printout generation is unavailable for the current resource.
7354:
7355: This could be because:
7356:
7357: (a) printstartdate is in the future
7358:
7359: (b) printenddate is in the past
7360:
7361: (c) there is an active exam block with "printout"
7362: functionality blocked
7363:
7364: Users with pav, pfo or evb privileges are exempt.
7365:
7366: Inputs: none
7367:
7368: =cut
7369:
7370:
7371: sub print_suppression {
7372: my $noprint;
7373: if ($env{'request.course.id'}) {
7374: my $scope = $env{'request.course.id'};
7375: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7376: (&Apache::lonnet::allowed('pfo',$scope))) {
7377: return;
7378: }
7379: if ($env{'request.course.sec'} ne '') {
7380: $scope .= "/$env{'request.course.sec'}";
7381: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7382: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7383: return;
1.1064 raeburn 7384: }
7385: }
7386: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7387: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7388: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7389: if ($blocked) {
7390: my $checkrole = "cm./$cdom/$cnum";
7391: if ($env{'request.course.sec'} ne '') {
7392: $checkrole .= "/$env{'request.course.sec'}";
7393: }
7394: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7395: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7396: $noprint = 1;
7397: }
7398: }
7399: unless ($noprint) {
7400: my $symb = &Apache::lonnet::symbread();
7401: if ($symb ne '') {
7402: my $navmap = Apache::lonnavmaps::navmap->new();
7403: if (ref($navmap)) {
7404: my $res = $navmap->getBySymb($symb);
7405: if (ref($res)) {
7406: if (!$res->resprintable()) {
7407: $noprint = 1;
7408: }
7409: }
7410: }
7411: }
7412: }
7413: if ($noprint) {
7414: return <<"ENDSTYLE";
7415: <style type="text/css" media="print">
7416: body { display:none }
7417: </style>
7418: ENDSTYLE
7419: }
7420: }
7421: return;
7422: }
7423:
7424: =pod
7425:
1.341 albertel 7426: =item * &xml_begin()
7427:
7428: Returns the needed doctype and <html>
7429:
7430: Inputs: none
7431:
7432: =cut
7433:
7434: sub xml_begin {
7435: my $output='';
7436:
7437: if ($env{'browser.mathml'}) {
7438: $output='<?xml version="1.0"?>'
7439: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7440: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7441:
7442: # .'<!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">] >'
7443: .'<!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">'
7444: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7445: .'xmlns="http://www.w3.org/1999/xhtml">';
7446: } else {
1.849 bisitz 7447: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
7448: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 7449: }
7450: return $output;
7451: }
1.340 albertel 7452:
7453: =pod
7454:
1.306 albertel 7455: =item * &start_page()
7456:
7457: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7458:
1.648 raeburn 7459: Inputs:
7460:
7461: =over 4
7462:
7463: $title - optional title for the page
7464:
7465: $head_extra - optional extra HTML to incude inside the <head>
7466:
7467: $args - additional optional args supported are:
7468:
7469: =over 8
7470:
7471: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7472: arg on
1.814 bisitz 7473: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7474: add_entries -> additional attributes to add to the <body>
7475: domain -> force to color decorate a page for a
1.317 albertel 7476: specific domain
1.648 raeburn 7477: function -> force usage of a specific rolish color
1.317 albertel 7478: scheme
1.648 raeburn 7479: redirect -> see &headtag()
7480: bgcolor -> override the default page bg color
7481: js_ready -> return a string ready for being used in
1.317 albertel 7482: a javascript writeln
1.648 raeburn 7483: html_encode -> return a string ready for being used in
1.320 albertel 7484: a html attribute
1.648 raeburn 7485: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7486: $forcereg arg
1.648 raeburn 7487: frameset -> if true will start with a <frameset>
1.330 albertel 7488: rather than <body>
1.648 raeburn 7489: skip_phases -> hash ref of
1.338 albertel 7490: head -> skip the <html><head> generation
7491: body -> skip all <body> generation
1.648 raeburn 7492: no_auto_mt_title -> prevent &mt()ing the title arg
7493: inherit_jsmath -> when creating popup window in a page,
7494: should it have jsmath forced on by the
7495: current page
1.867 kalberla 7496: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7497: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 7498: group -> includes the current group, if page is for a
7499: specific group
1.361 albertel 7500:
1.648 raeburn 7501: =back
1.460 albertel 7502:
1.648 raeburn 7503: =back
1.562 albertel 7504:
1.306 albertel 7505: =cut
7506:
7507: sub start_page {
1.309 albertel 7508: my ($title,$head_extra,$args) = @_;
1.318 albertel 7509: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7510:
1.315 albertel 7511: $env{'internal.start_page'}++;
1.1096 raeburn 7512: my ($result,@advtools);
1.964 droeschl 7513:
1.338 albertel 7514: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7515: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7516: }
7517:
7518: if (! exists($args->{'skip_phases'}{'body'}) ) {
7519: if ($args->{'frameset'}) {
7520: my $attr_string = &make_attr_string($args->{'force_register'},
7521: $args->{'add_entries'});
7522: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7523: } else {
7524: $result .=
7525: &bodytag($title,
7526: $args->{'function'}, $args->{'add_entries'},
7527: $args->{'only_body'}, $args->{'domain'},
7528: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 7529: $args->{'bgcolor'}, $args,
7530: \@advtools);
1.831 bisitz 7531: }
1.330 albertel 7532: }
1.338 albertel 7533:
1.315 albertel 7534: if ($args->{'js_ready'}) {
1.713 kaisler 7535: $result = &js_ready($result);
1.315 albertel 7536: }
1.320 albertel 7537: if ($args->{'html_encode'}) {
1.713 kaisler 7538: $result = &html_encode($result);
7539: }
7540:
1.813 bisitz 7541: # Preparation for new and consistent functionlist at top of screen
7542: # if ($args->{'functionlist'}) {
7543: # $result .= &build_functionlist();
7544: #}
7545:
1.964 droeschl 7546: # Don't add anything more if only_body wanted or in const space
7547: return $result if $args->{'only_body'}
7548: || $env{'request.state'} eq 'construct';
1.813 bisitz 7549:
7550: #Breadcrumbs
1.758 kaisler 7551: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7552: &Apache::lonhtmlcommon::clear_breadcrumbs();
7553: #if any br links exists, add them to the breadcrumbs
7554: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7555: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7556: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7557: }
7558: }
1.1096 raeburn 7559: # if @advtools array contains items add then to the breadcrumbs
7560: if (@advtools > 0) {
7561: &Apache::lonmenu::advtools_crumbs(@advtools);
7562: }
1.758 kaisler 7563:
7564: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7565: if(exists($args->{'bread_crumbs_component'})){
7566: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7567: }else{
7568: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7569: }
1.320 albertel 7570: }
1.315 albertel 7571: return $result;
1.306 albertel 7572: }
7573:
7574: sub end_page {
1.315 albertel 7575: my ($args) = @_;
7576: $env{'internal.end_page'}++;
1.330 albertel 7577: my $result;
1.335 albertel 7578: if ($args->{'discussion'}) {
7579: my ($target,$parser);
7580: if (ref($args->{'discussion'})) {
7581: ($target,$parser) =($args->{'discussion'}{'target'},
7582: $args->{'discussion'}{'parser'});
7583: }
7584: $result .= &Apache::lonxml::xmlend($target,$parser);
7585: }
1.330 albertel 7586: if ($args->{'frameset'}) {
7587: $result .= '</frameset>';
7588: } else {
1.635 raeburn 7589: $result .= &endbodytag($args);
1.330 albertel 7590: }
1.1080 raeburn 7591: unless ($args->{'notbody'}) {
7592: $result .= "\n</html>";
7593: }
1.330 albertel 7594:
1.315 albertel 7595: if ($args->{'js_ready'}) {
1.317 albertel 7596: $result = &js_ready($result);
1.315 albertel 7597: }
1.335 albertel 7598:
1.320 albertel 7599: if ($args->{'html_encode'}) {
7600: $result = &html_encode($result);
7601: }
1.335 albertel 7602:
1.315 albertel 7603: return $result;
7604: }
7605:
1.1034 www 7606: sub wishlist_window {
7607: return(<<'ENDWISHLIST');
1.1046 raeburn 7608: <script type="text/javascript">
1.1034 www 7609: // <![CDATA[
7610: // <!-- BEGIN LON-CAPA Internal
7611: function set_wishlistlink(title, path) {
7612: if (!title) {
7613: title = document.title;
7614: title = title.replace(/^LON-CAPA /,'');
7615: }
7616: if (!path) {
7617: path = location.pathname;
7618: }
7619: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7620: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7621: }
7622: // END LON-CAPA Internal -->
7623: // ]]>
7624: </script>
7625: ENDWISHLIST
7626: }
7627:
1.1030 www 7628: sub modal_window {
7629: return(<<'ENDMODAL');
1.1046 raeburn 7630: <script type="text/javascript">
1.1030 www 7631: // <![CDATA[
7632: // <!-- BEGIN LON-CAPA Internal
7633: var modalWindow = {
7634: parent:"body",
7635: windowId:null,
7636: content:null,
7637: width:null,
7638: height:null,
7639: close:function()
7640: {
7641: $(".LCmodal-window").remove();
7642: $(".LCmodal-overlay").remove();
7643: },
7644: open:function()
7645: {
7646: var modal = "";
7647: modal += "<div class=\"LCmodal-overlay\"></div>";
7648: 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;\">";
7649: modal += this.content;
7650: modal += "</div>";
7651:
7652: $(this.parent).append(modal);
7653:
7654: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7655: $(".LCclose-window").click(function(){modalWindow.close();});
7656: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7657: }
7658: };
1.1031 www 7659: var openMyModal = function(source,width,height,scrolling)
1.1030 www 7660: {
7661: modalWindow.windowId = "myModal";
7662: modalWindow.width = width;
7663: modalWindow.height = height;
1.1031 www 7664: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='true' src='" + source + "'></iframe>";
1.1030 www 7665: modalWindow.open();
7666: };
7667: // END LON-CAPA Internal -->
7668: // ]]>
7669: </script>
7670: ENDMODAL
7671: }
7672:
7673: sub modal_link {
1.1052 www 7674: my ($link,$linktext,$width,$height,$target,$scrolling,$title)=@_;
1.1030 www 7675: unless ($width) { $width=480; }
7676: unless ($height) { $height=400; }
1.1031 www 7677: unless ($scrolling) { $scrolling='yes'; }
1.1074 raeburn 7678: my $target_attr;
7679: if (defined($target)) {
7680: $target_attr = 'target="'.$target.'"';
7681: }
7682: return <<"ENDLINK";
7683: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling'); return false;">
7684: $linktext</a>
7685: ENDLINK
1.1030 www 7686: }
7687:
1.1032 www 7688: sub modal_adhoc_script {
7689: my ($funcname,$width,$height,$content)=@_;
7690: return (<<ENDADHOC);
1.1046 raeburn 7691: <script type="text/javascript">
1.1032 www 7692: // <![CDATA[
7693: var $funcname = function()
7694: {
7695: modalWindow.windowId = "myModal";
7696: modalWindow.width = $width;
7697: modalWindow.height = $height;
7698: modalWindow.content = '$content';
7699: modalWindow.open();
7700: };
7701: // ]]>
7702: </script>
7703: ENDADHOC
7704: }
7705:
1.1041 www 7706: sub modal_adhoc_inner {
7707: my ($funcname,$width,$height,$content)=@_;
7708: my $innerwidth=$width-20;
7709: $content=&js_ready(
1.1042 www 7710: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1137 raeburn 7711: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','modal').
1.1041 www 7712: $content.
7713: &end_scrollbox().
7714: &end_page()
7715: );
7716: return &modal_adhoc_script($funcname,$width,$height,$content);
7717: }
7718:
7719: sub modal_adhoc_window {
7720: my ($funcname,$width,$height,$content,$linktext)=@_;
7721: return &modal_adhoc_inner($funcname,$width,$height,$content).
7722: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7723: }
7724:
7725: sub modal_adhoc_launch {
7726: my ($funcname,$width,$height,$content)=@_;
7727: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7728: <script type="text/javascript">
7729: // <![CDATA[
7730: $funcname();
7731: // ]]>
7732: </script>
7733: ENDLAUNCH
7734: }
7735:
7736: sub modal_adhoc_close {
7737: return (<<ENDCLOSE);
7738: <script type="text/javascript">
7739: // <![CDATA[
7740: modalWindow.close();
7741: // ]]>
7742: </script>
7743: ENDCLOSE
7744: }
7745:
1.1038 www 7746: sub togglebox_script {
7747: return(<<ENDTOGGLE);
7748: <script type="text/javascript">
7749: // <![CDATA[
7750: function LCtoggleDisplay(id,hidetext,showtext) {
7751: link = document.getElementById(id + "link").childNodes[0];
7752: with (document.getElementById(id).style) {
7753: if (display == "none" ) {
7754: display = "inline";
7755: link.nodeValue = hidetext;
7756: } else {
7757: display = "none";
7758: link.nodeValue = showtext;
7759: }
7760: }
7761: }
7762: // ]]>
7763: </script>
7764: ENDTOGGLE
7765: }
7766:
1.1039 www 7767: sub start_togglebox {
7768: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7769: unless ($heading) { $heading=''; } else { $heading.=' '; }
7770: unless ($showtext) { $showtext=&mt('show'); }
7771: unless ($hidetext) { $hidetext=&mt('hide'); }
7772: unless ($headerbg) { $headerbg='#FFFFFF'; }
7773: return &start_data_table().
7774: &start_data_table_header_row().
7775: '<td bgcolor="'.$headerbg.'">'.$heading.
7776: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7777: $showtext.'\')">'.$showtext.'</a>]</td>'.
7778: &end_data_table_header_row().
7779: '<tr id="'.$id.'" style="display:none""><td>';
7780: }
7781:
7782: sub end_togglebox {
7783: return '</td></tr>'.&end_data_table();
7784: }
7785:
1.1041 www 7786: sub LCprogressbar_script {
1.1045 www 7787: my ($id)=@_;
1.1041 www 7788: return(<<ENDPROGRESS);
7789: <script type="text/javascript">
7790: // <![CDATA[
1.1045 www 7791: \$('#progressbar$id').progressbar({
1.1041 www 7792: value: 0,
7793: change: function(event, ui) {
7794: var newVal = \$(this).progressbar('option', 'value');
7795: \$('.pblabel', this).text(LCprogressTxt);
7796: }
7797: });
7798: // ]]>
7799: </script>
7800: ENDPROGRESS
7801: }
7802:
7803: sub LCprogressbarUpdate_script {
7804: return(<<ENDPROGRESSUPDATE);
7805: <style type="text/css">
7806: .ui-progressbar { position:relative; }
7807: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7808: </style>
7809: <script type="text/javascript">
7810: // <![CDATA[
1.1045 www 7811: var LCprogressTxt='---';
7812:
7813: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7814: LCprogressTxt=progresstext;
1.1045 www 7815: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7816: }
7817: // ]]>
7818: </script>
7819: ENDPROGRESSUPDATE
7820: }
7821:
1.1042 www 7822: my $LClastpercent;
1.1045 www 7823: my $LCidcnt;
7824: my $LCcurrentid;
1.1042 www 7825:
1.1041 www 7826: sub LCprogressbar {
1.1042 www 7827: my ($r)=(@_);
7828: $LClastpercent=0;
1.1045 www 7829: $LCidcnt++;
7830: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7831: my $starting=&mt('Starting');
7832: my $content=(<<ENDPROGBAR);
1.1045 www 7833: <div id="progressbar$LCcurrentid">
1.1041 www 7834: <span class="pblabel">$starting</span>
7835: </div>
7836: ENDPROGBAR
1.1045 www 7837: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7838: }
7839:
7840: sub LCprogressbarUpdate {
1.1042 www 7841: my ($r,$val,$text)=@_;
7842: unless ($val) {
7843: if ($LClastpercent) {
7844: $val=$LClastpercent;
7845: } else {
7846: $val=0;
7847: }
7848: }
1.1041 www 7849: if ($val<0) { $val=0; }
7850: if ($val>100) { $val=0; }
1.1042 www 7851: $LClastpercent=$val;
1.1041 www 7852: unless ($text) { $text=$val.'%'; }
7853: $text=&js_ready($text);
1.1044 www 7854: &r_print($r,<<ENDUPDATE);
1.1041 www 7855: <script type="text/javascript">
7856: // <![CDATA[
1.1045 www 7857: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7858: // ]]>
7859: </script>
7860: ENDUPDATE
1.1035 www 7861: }
7862:
1.1042 www 7863: sub LCprogressbarClose {
7864: my ($r)=@_;
7865: $LClastpercent=0;
1.1044 www 7866: &r_print($r,<<ENDCLOSE);
1.1042 www 7867: <script type="text/javascript">
7868: // <![CDATA[
1.1045 www 7869: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7870: // ]]>
7871: </script>
7872: ENDCLOSE
1.1044 www 7873: }
7874:
7875: sub r_print {
7876: my ($r,$to_print)=@_;
7877: if ($r) {
7878: $r->print($to_print);
7879: $r->rflush();
7880: } else {
7881: print($to_print);
7882: }
1.1042 www 7883: }
7884:
1.320 albertel 7885: sub html_encode {
7886: my ($result) = @_;
7887:
1.322 albertel 7888: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7889:
7890: return $result;
7891: }
1.1044 www 7892:
1.317 albertel 7893: sub js_ready {
7894: my ($result) = @_;
7895:
1.323 albertel 7896: $result =~ s/[\n\r]/ /xmsg;
7897: $result =~ s/\\/\\\\/xmsg;
7898: $result =~ s/'/\\'/xmsg;
1.372 albertel 7899: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7900:
7901: return $result;
7902: }
7903:
1.315 albertel 7904: sub validate_page {
7905: if ( exists($env{'internal.start_page'})
1.316 albertel 7906: && $env{'internal.start_page'} > 1) {
7907: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7908: $env{'internal.start_page'}.' '.
1.316 albertel 7909: $ENV{'request.filename'});
1.315 albertel 7910: }
7911: if ( exists($env{'internal.end_page'})
1.316 albertel 7912: && $env{'internal.end_page'} > 1) {
7913: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7914: $env{'internal.end_page'}.' '.
1.316 albertel 7915: $env{'request.filename'});
1.315 albertel 7916: }
7917: if ( exists($env{'internal.start_page'})
7918: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7919: &Apache::lonnet::logthis('start_page called without end_page '.
7920: $env{'request.filename'});
1.315 albertel 7921: }
7922: if ( ! exists($env{'internal.start_page'})
7923: && exists($env{'internal.end_page'})) {
1.316 albertel 7924: &Apache::lonnet::logthis('end_page called without start_page'.
7925: $env{'request.filename'});
1.315 albertel 7926: }
1.306 albertel 7927: }
1.315 albertel 7928:
1.996 www 7929:
7930: sub start_scrollbox {
1.1138 raeburn 7931: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor) = @_;
1.998 raeburn 7932: unless ($outerwidth) { $outerwidth='520px'; }
7933: unless ($width) { $width='500px'; }
7934: unless ($height) { $height='200px'; }
1.1075 raeburn 7935: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7936: if ($id ne '') {
1.1020 raeburn 7937: $table_id = " id='table_$id'";
1.1137 raeburn 7938: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 7939: }
1.1075 raeburn 7940: if ($bgcolor ne '') {
7941: $tdcol = "background-color: $bgcolor;";
7942: }
1.1137 raeburn 7943: my $nicescroll_js;
7944: if ($env{'browser.mobile'}) {
1.1138 raeburn 7945: my %options;
7946: if (ref($cursor) eq 'HASH') {
7947: %options = %{$cursor};
7948: }
7949: unless ($options{'railalign'} =~ /^left|right$/) {
7950: $options{'railalign'} = 'left';
7951: }
7952: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
7953: my $function = &get_users_function();
7954: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
7955: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
7956: $options{'cursorcolor'} = '#00F';
7957: }
7958: }
7959: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
7960: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
7961: $options{'cursoropacity'}='1.0';
7962: }
7963: } else {
7964: $options{'cursoropacity'}='1.0';
7965: }
7966: if ($options{'cursorfixedheight'} eq 'none') {
7967: delete($options{'cursorfixedheight'});
7968: } else {
7969: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
7970: }
7971: unless ($options{'railoffset'} =~ /^{[\w\:\d]+}$/) {
7972: delete($options{'railoffset'});
7973: }
7974: my @niceoptions;
7975: while (my($key,$value) = each(%options)) {
7976: if ($value =~ /^\{.+\}$/) {
7977: push(@niceoptions,$key.':'.$value);
7978: } else {
7979: push(@niceoptions,$key.':"'.$value.'"');
7980: }
7981: }
1.1137 raeburn 7982: $nicescroll_js = '
7983: <script type="text/javascript">
7984: // <![CDATA[
7985: $(document).ready(
7986: function() {
1.1138 raeburn 7987: $("#div_'.$id.'").niceScroll({'.join(',',@niceoptions).'});
1.1137 raeburn 7988: }
7989: );
7990:
7991: // ]]>
7992: </script>
7993: ';
7994: }
7995:
1.1075 raeburn 7996: return <<"END";
1.1137 raeburn 7997: $nicescroll_js
7998:
7999: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
8000: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8001: END
1.996 www 8002: }
8003:
8004: sub end_scrollbox {
1.1036 www 8005: return '</div></td></tr></table>';
1.996 www 8006: }
8007:
1.318 albertel 8008: sub simple_error_page {
8009: my ($r,$title,$msg) = @_;
8010: my $page =
8011: &Apache::loncommon::start_page($title).
1.1097 bisitz 8012: '<p class="LC_error">'.&mt($msg).'</p>'.
1.318 albertel 8013: &Apache::loncommon::end_page();
8014: if (ref($r)) {
8015: $r->print($page);
1.327 albertel 8016: return;
1.318 albertel 8017: }
8018: return $page;
8019: }
1.347 albertel 8020:
8021: {
1.610 albertel 8022: my @row_count;
1.961 onken 8023:
8024: sub start_data_table_count {
8025: unshift(@row_count, 0);
8026: return;
8027: }
8028:
8029: sub end_data_table_count {
8030: shift(@row_count);
8031: return;
8032: }
8033:
1.347 albertel 8034: sub start_data_table {
1.1018 raeburn 8035: my ($add_class,$id) = @_;
1.422 albertel 8036: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8037: my $table_id;
8038: if (defined($id)) {
8039: $table_id = ' id="'.$id.'"';
8040: }
1.961 onken 8041: &start_data_table_count();
1.1018 raeburn 8042: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8043: }
8044:
8045: sub end_data_table {
1.961 onken 8046: &end_data_table_count();
1.389 albertel 8047: return '</table>'."\n";;
1.347 albertel 8048: }
8049:
8050: sub start_data_table_row {
1.974 wenzelju 8051: my ($add_class, $id) = @_;
1.610 albertel 8052: $row_count[0]++;
8053: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8054: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8055: $id = (' id="'.$id.'"') unless ($id eq '');
8056: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8057: }
1.471 banghart 8058:
8059: sub continue_data_table_row {
1.974 wenzelju 8060: my ($add_class, $id) = @_;
1.610 albertel 8061: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8062: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8063: $id = (' id="'.$id.'"') unless ($id eq '');
8064: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8065: }
1.347 albertel 8066:
8067: sub end_data_table_row {
1.389 albertel 8068: return '</tr>'."\n";;
1.347 albertel 8069: }
1.367 www 8070:
1.421 albertel 8071: sub start_data_table_empty_row {
1.707 bisitz 8072: # $row_count[0]++;
1.421 albertel 8073: return '<tr class="LC_empty_row" >'."\n";;
8074: }
8075:
8076: sub end_data_table_empty_row {
8077: return '</tr>'."\n";;
8078: }
8079:
1.367 www 8080: sub start_data_table_header_row {
1.389 albertel 8081: return '<tr class="LC_header_row">'."\n";;
1.367 www 8082: }
8083:
8084: sub end_data_table_header_row {
1.389 albertel 8085: return '</tr>'."\n";;
1.367 www 8086: }
1.890 droeschl 8087:
8088: sub data_table_caption {
8089: my $caption = shift;
8090: return "<caption class=\"LC_caption\">$caption</caption>";
8091: }
1.347 albertel 8092: }
8093:
1.548 albertel 8094: =pod
8095:
8096: =item * &inhibit_menu_check($arg)
8097:
8098: Checks for a inhibitmenu state and generates output to preserve it
8099:
8100: Inputs: $arg - can be any of
8101: - undef - in which case the return value is a string
8102: to add into arguments list of a uri
8103: - 'input' - in which case the return value is a HTML
8104: <form> <input> field of type hidden to
8105: preserve the value
8106: - a url - in which case the return value is the url with
8107: the neccesary cgi args added to preserve the
8108: inhibitmenu state
8109: - a ref to a url - no return value, but the string is
8110: updated to include the neccessary cgi
8111: args to preserve the inhibitmenu state
8112:
8113: =cut
8114:
8115: sub inhibit_menu_check {
8116: my ($arg) = @_;
8117: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8118: if ($arg eq 'input') {
8119: if ($env{'form.inhibitmenu'}) {
8120: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8121: } else {
8122: return
8123: }
8124: }
8125: if ($env{'form.inhibitmenu'}) {
8126: if (ref($arg)) {
8127: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8128: } elsif ($arg eq '') {
8129: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8130: } else {
8131: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8132: }
8133: }
8134: if (!ref($arg)) {
8135: return $arg;
8136: }
8137: }
8138:
1.251 albertel 8139: ###############################################
1.182 matthew 8140:
8141: =pod
8142:
1.549 albertel 8143: =back
8144:
8145: =head1 User Information Routines
8146:
8147: =over 4
8148:
1.405 albertel 8149: =item * &get_users_function()
1.182 matthew 8150:
8151: Used by &bodytag to determine the current users primary role.
8152: Returns either 'student','coordinator','admin', or 'author'.
8153:
8154: =cut
8155:
8156: ###############################################
8157: sub get_users_function {
1.815 tempelho 8158: my $function = 'norole';
1.818 tempelho 8159: if ($env{'request.role'}=~/^(st)/) {
8160: $function='student';
8161: }
1.907 raeburn 8162: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8163: $function='coordinator';
8164: }
1.258 albertel 8165: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8166: $function='admin';
8167: }
1.826 bisitz 8168: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8169: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8170: $function='author';
8171: }
8172: return $function;
1.54 www 8173: }
1.99 www 8174:
8175: ###############################################
8176:
1.233 raeburn 8177: =pod
8178:
1.821 raeburn 8179: =item * &show_course()
8180:
8181: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8182: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8183:
8184: Inputs:
8185: None
8186:
8187: Outputs:
8188: Scalar: 1 if 'Course' to be used, 0 otherwise.
8189:
8190: =cut
8191:
8192: ###############################################
8193: sub show_course {
8194: my $course = !$env{'user.adv'};
8195: if (!$env{'user.adv'}) {
8196: foreach my $env (keys(%env)) {
8197: next if ($env !~ m/^user\.priv\./);
8198: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8199: $course = 0;
8200: last;
8201: }
8202: }
8203: }
8204: return $course;
8205: }
8206:
8207: ###############################################
8208:
8209: =pod
8210:
1.542 raeburn 8211: =item * &check_user_status()
1.274 raeburn 8212:
8213: Determines current status of supplied role for a
8214: specific user. Roles can be active, previous or future.
8215:
8216: Inputs:
8217: user's domain, user's username, course's domain,
1.375 raeburn 8218: course's number, optional section ID.
1.274 raeburn 8219:
8220: Outputs:
8221: role status: active, previous or future.
8222:
8223: =cut
8224:
8225: sub check_user_status {
1.412 raeburn 8226: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8227: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8228: my @uroles = keys %userinfo;
8229: my $srchstr;
8230: my $active_chk = 'none';
1.412 raeburn 8231: my $now = time;
1.274 raeburn 8232: if (@uroles > 0) {
1.908 raeburn 8233: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8234: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8235: } else {
1.412 raeburn 8236: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8237: }
8238: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8239: my $role_end = 0;
8240: my $role_start = 0;
8241: $active_chk = 'active';
1.412 raeburn 8242: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8243: $role_end = $1;
8244: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8245: $role_start = $1;
1.274 raeburn 8246: }
8247: }
8248: if ($role_start > 0) {
1.412 raeburn 8249: if ($now < $role_start) {
1.274 raeburn 8250: $active_chk = 'future';
8251: }
8252: }
8253: if ($role_end > 0) {
1.412 raeburn 8254: if ($now > $role_end) {
1.274 raeburn 8255: $active_chk = 'previous';
8256: }
8257: }
8258: }
8259: }
8260: return $active_chk;
8261: }
8262:
8263: ###############################################
8264:
8265: =pod
8266:
1.405 albertel 8267: =item * &get_sections()
1.233 raeburn 8268:
8269: Determines all the sections for a course including
8270: sections with students and sections containing other roles.
1.419 raeburn 8271: Incoming parameters:
8272:
8273: 1. domain
8274: 2. course number
8275: 3. reference to array containing roles for which sections should
8276: be gathered (optional).
8277: 4. reference to array containing status types for which sections
8278: should be gathered (optional).
8279:
8280: If the third argument is undefined, sections are gathered for any role.
8281: If the fourth argument is undefined, sections are gathered for any status.
8282: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8283:
1.374 raeburn 8284: Returns section hash (keys are section IDs, values are
8285: number of users in each section), subject to the
1.419 raeburn 8286: optional roles filter, optional status filter
1.233 raeburn 8287:
8288: =cut
8289:
8290: ###############################################
8291: sub get_sections {
1.419 raeburn 8292: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8293: if (!defined($cdom) || !defined($cnum)) {
8294: my $cid = $env{'request.course.id'};
8295:
8296: return if (!defined($cid));
8297:
8298: $cdom = $env{'course.'.$cid.'.domain'};
8299: $cnum = $env{'course.'.$cid.'.num'};
8300: }
8301:
8302: my %sectioncount;
1.419 raeburn 8303: my $now = time;
1.240 albertel 8304:
1.1118 raeburn 8305: my $check_students = 1;
8306: my $only_students = 0;
8307: if (ref($possible_roles) eq 'ARRAY') {
8308: if (grep(/^st$/,@{$possible_roles})) {
8309: if (@{$possible_roles} == 1) {
8310: $only_students = 1;
8311: }
8312: } else {
8313: $check_students = 0;
8314: }
8315: }
8316:
8317: if ($check_students) {
1.276 albertel 8318: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8319: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8320: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8321: my $start_index = &Apache::loncoursedata::CL_START();
8322: my $end_index = &Apache::loncoursedata::CL_END();
8323: my $status;
1.366 albertel 8324: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8325: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8326: $data->[$status_index],
8327: $data->[$start_index],
8328: $data->[$end_index]);
8329: if ($stu_status eq 'Active') {
8330: $status = 'active';
8331: } elsif ($end < $now) {
8332: $status = 'previous';
8333: } elsif ($start > $now) {
8334: $status = 'future';
8335: }
8336: if ($section ne '-1' && $section !~ /^\s*$/) {
8337: if ((!defined($possible_status)) || (($status ne '') &&
8338: (grep/^\Q$status\E$/,@{$possible_status}))) {
8339: $sectioncount{$section}++;
8340: }
1.240 albertel 8341: }
8342: }
8343: }
1.1118 raeburn 8344: if ($only_students) {
8345: return %sectioncount;
8346: }
1.240 albertel 8347: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8348: foreach my $user (sort(keys(%courseroles))) {
8349: if ($user !~ /^(\w{2})/) { next; }
8350: my ($role) = ($user =~ /^(\w{2})/);
8351: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8352: my ($section,$status);
1.240 albertel 8353: if ($role eq 'cr' &&
8354: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8355: $section=$1;
8356: }
8357: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8358: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8359: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8360: if ($end == -1 && $start == -1) {
8361: next; #deleted role
8362: }
8363: if (!defined($possible_status)) {
8364: $sectioncount{$section}++;
8365: } else {
8366: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8367: $status = 'active';
8368: } elsif ($end < $now) {
8369: $status = 'future';
8370: } elsif ($start > $now) {
8371: $status = 'previous';
8372: }
8373: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8374: $sectioncount{$section}++;
8375: }
8376: }
1.233 raeburn 8377: }
1.366 albertel 8378: return %sectioncount;
1.233 raeburn 8379: }
8380:
1.274 raeburn 8381: ###############################################
1.294 raeburn 8382:
8383: =pod
1.405 albertel 8384:
8385: =item * &get_course_users()
8386:
1.275 raeburn 8387: Retrieves usernames:domains for users in the specified course
8388: with specific role(s), and access status.
8389:
8390: Incoming parameters:
1.277 albertel 8391: 1. course domain
8392: 2. course number
8393: 3. access status: users must have - either active,
1.275 raeburn 8394: previous, future, or all.
1.277 albertel 8395: 4. reference to array of permissible roles
1.288 raeburn 8396: 5. reference to array of section restrictions (optional)
8397: 6. reference to results object (hash of hashes).
8398: 7. reference to optional userdata hash
1.609 raeburn 8399: 8. reference to optional statushash
1.630 raeburn 8400: 9. flag if privileged users (except those set to unhide in
8401: course settings) should be excluded
1.609 raeburn 8402: Keys of top level results hash are roles.
1.275 raeburn 8403: Keys of inner hashes are username:domain, with
8404: values set to access type.
1.288 raeburn 8405: Optional userdata hash returns an array with arguments in the
8406: same order as loncoursedata::get_classlist() for student data.
8407:
1.609 raeburn 8408: Optional statushash returns
8409:
1.288 raeburn 8410: Entries for end, start, section and status are blank because
8411: of the possibility of multiple values for non-student roles.
8412:
1.275 raeburn 8413: =cut
1.405 albertel 8414:
1.275 raeburn 8415: ###############################################
1.405 albertel 8416:
1.275 raeburn 8417: sub get_course_users {
1.630 raeburn 8418: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8419: my %idx = ();
1.419 raeburn 8420: my %seclists;
1.288 raeburn 8421:
8422: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8423: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8424: $idx{end} = &Apache::loncoursedata::CL_END();
8425: $idx{start} = &Apache::loncoursedata::CL_START();
8426: $idx{id} = &Apache::loncoursedata::CL_ID();
8427: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8428: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8429: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8430:
1.290 albertel 8431: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8432: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8433: my $now = time;
1.277 albertel 8434: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8435: my $match = 0;
1.412 raeburn 8436: my $secmatch = 0;
1.419 raeburn 8437: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8438: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8439: if ($section eq '') {
8440: $section = 'none';
8441: }
1.291 albertel 8442: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8443: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8444: $secmatch = 1;
8445: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8446: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8447: $secmatch = 1;
8448: }
8449: } else {
1.419 raeburn 8450: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8451: $secmatch = 1;
8452: }
1.290 albertel 8453: }
1.412 raeburn 8454: if (!$secmatch) {
8455: next;
8456: }
1.419 raeburn 8457: }
1.275 raeburn 8458: if (defined($$types{'active'})) {
1.288 raeburn 8459: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8460: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8461: $match = 1;
1.275 raeburn 8462: }
8463: }
8464: if (defined($$types{'previous'})) {
1.609 raeburn 8465: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8466: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8467: $match = 1;
1.275 raeburn 8468: }
8469: }
8470: if (defined($$types{'future'})) {
1.609 raeburn 8471: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8472: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8473: $match = 1;
1.275 raeburn 8474: }
8475: }
1.609 raeburn 8476: if ($match) {
8477: push(@{$seclists{$student}},$section);
8478: if (ref($userdata) eq 'HASH') {
8479: $$userdata{$student} = $$classlist{$student};
8480: }
8481: if (ref($statushash) eq 'HASH') {
8482: $statushash->{$student}{'st'}{$section} = $status;
8483: }
1.288 raeburn 8484: }
1.275 raeburn 8485: }
8486: }
1.412 raeburn 8487: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8488: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8489: my $now = time;
1.609 raeburn 8490: my %displaystatus = ( previous => 'Expired',
8491: active => 'Active',
8492: future => 'Future',
8493: );
1.1121 raeburn 8494: my (%nothide,@possdoms);
1.630 raeburn 8495: if ($hidepriv) {
8496: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8497: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8498: if ($user !~ /:/) {
8499: $nothide{join(':',split(/[\@]/,$user))}=1;
8500: } else {
8501: $nothide{$user} = 1;
8502: }
8503: }
1.1121 raeburn 8504: my @possdoms = ($cdom);
8505: if ($coursehash{'checkforpriv'}) {
8506: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8507: }
1.630 raeburn 8508: }
1.439 raeburn 8509: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8510: my $match = 0;
1.412 raeburn 8511: my $secmatch = 0;
1.439 raeburn 8512: my $status;
1.412 raeburn 8513: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8514: $user =~ s/:$//;
1.439 raeburn 8515: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8516: if ($end == -1 || $start == -1) {
8517: next;
8518: }
8519: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8520: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8521: my ($uname,$udom) = split(/:/,$user);
8522: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8523: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8524: $secmatch = 1;
8525: } elsif ($usec eq '') {
1.420 albertel 8526: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8527: $secmatch = 1;
8528: }
8529: } else {
8530: if (grep(/^\Q$usec\E$/,@{$sections})) {
8531: $secmatch = 1;
8532: }
8533: }
8534: if (!$secmatch) {
8535: next;
8536: }
1.288 raeburn 8537: }
1.419 raeburn 8538: if ($usec eq '') {
8539: $usec = 'none';
8540: }
1.275 raeburn 8541: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8542: if ($hidepriv) {
1.1121 raeburn 8543: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8544: (!$nothide{$uname.':'.$udom})) {
8545: next;
8546: }
8547: }
1.503 raeburn 8548: if ($end > 0 && $end < $now) {
1.439 raeburn 8549: $status = 'previous';
8550: } elsif ($start > $now) {
8551: $status = 'future';
8552: } else {
8553: $status = 'active';
8554: }
1.277 albertel 8555: foreach my $type (keys(%{$types})) {
1.275 raeburn 8556: if ($status eq $type) {
1.420 albertel 8557: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8558: push(@{$$users{$role}{$user}},$type);
8559: }
1.288 raeburn 8560: $match = 1;
8561: }
8562: }
1.419 raeburn 8563: if (($match) && (ref($userdata) eq 'HASH')) {
8564: if (!exists($$userdata{$uname.':'.$udom})) {
8565: &get_user_info($udom,$uname,\%idx,$userdata);
8566: }
1.420 albertel 8567: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8568: push(@{$seclists{$uname.':'.$udom}},$usec);
8569: }
1.609 raeburn 8570: if (ref($statushash) eq 'HASH') {
8571: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8572: }
1.275 raeburn 8573: }
8574: }
8575: }
8576: }
1.290 albertel 8577: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8578: if ((defined($cdom)) && (defined($cnum))) {
8579: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8580: if ( defined($csettings{'internal.courseowner'}) ) {
8581: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8582: next if ($owner eq '');
8583: my ($ownername,$ownerdom);
8584: if ($owner =~ /^([^:]+):([^:]+)$/) {
8585: $ownername = $1;
8586: $ownerdom = $2;
8587: } else {
8588: $ownername = $owner;
8589: $ownerdom = $cdom;
8590: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8591: }
8592: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8593: if (defined($userdata) &&
1.609 raeburn 8594: !exists($$userdata{$owner})) {
8595: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8596: if (!grep(/^none$/,@{$seclists{$owner}})) {
8597: push(@{$seclists{$owner}},'none');
8598: }
8599: if (ref($statushash) eq 'HASH') {
8600: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8601: }
1.290 albertel 8602: }
1.279 raeburn 8603: }
8604: }
8605: }
1.419 raeburn 8606: foreach my $user (keys(%seclists)) {
8607: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8608: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8609: }
1.275 raeburn 8610: }
8611: return;
8612: }
8613:
1.288 raeburn 8614: sub get_user_info {
8615: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8616: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8617: &plainname($uname,$udom,'lastname');
1.291 albertel 8618: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8619: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8620: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8621: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8622: return;
8623: }
1.275 raeburn 8624:
1.472 raeburn 8625: ###############################################
8626:
8627: =pod
8628:
8629: =item * &get_user_quota()
8630:
1.1134 raeburn 8631: Retrieves quota assigned for storage of user files.
8632: Default is to report quota for portfolio files.
1.472 raeburn 8633:
8634: Incoming parameters:
8635: 1. user's username
8636: 2. user's domain
1.1134 raeburn 8637: 3. quota name - portfolio, author, or course
1.1136 raeburn 8638: (if no quota name provided, defaults to portfolio).
8639: 4. crstype - official, unofficial or community, if quota name is
8640: course
1.472 raeburn 8641:
8642: Returns:
1.536 raeburn 8643: 1. Disk quota (in Mb) assigned to student.
8644: 2. (Optional) Type of setting: custom or default
8645: (individually assigned or default for user's
8646: institutional status).
8647: 3. (Optional) - User's institutional status (e.g., faculty, staff
8648: or student - types as defined in localenroll::inst_usertypes
8649: for user's domain, which determines default quota for user.
8650: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8651:
8652: If a value has been stored in the user's environment,
1.536 raeburn 8653: it will return that, otherwise it returns the maximal default
1.1134 raeburn 8654: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8655:
8656: =cut
8657:
8658: ###############################################
8659:
8660:
8661: sub get_user_quota {
1.1136 raeburn 8662: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8663: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8664: if (!defined($udom)) {
8665: $udom = $env{'user.domain'};
8666: }
8667: if (!defined($uname)) {
8668: $uname = $env{'user.name'};
8669: }
8670: if (($udom eq '' || $uname eq '') ||
8671: ($udom eq 'public') && ($uname eq 'public')) {
8672: $quota = 0;
1.536 raeburn 8673: $quotatype = 'default';
8674: $defquota = 0;
1.472 raeburn 8675: } else {
1.536 raeburn 8676: my $inststatus;
1.1134 raeburn 8677: if ($quotaname eq 'course') {
8678: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8679: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8680: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8681: } else {
8682: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8683: $quota = $cenv{'internal.uploadquota'};
8684: }
1.536 raeburn 8685: } else {
1.1134 raeburn 8686: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8687: if ($quotaname eq 'author') {
8688: $quota = $env{'environment.authorquota'};
8689: } else {
8690: $quota = $env{'environment.portfolioquota'};
8691: }
8692: $inststatus = $env{'environment.inststatus'};
8693: } else {
8694: my %userenv =
8695: &Apache::lonnet::get('environment',['portfolioquota',
8696: 'authorquota','inststatus'],$udom,$uname);
8697: my ($tmp) = keys(%userenv);
8698: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8699: if ($quotaname eq 'author') {
8700: $quota = $userenv{'authorquota'};
8701: } else {
8702: $quota = $userenv{'portfolioquota'};
8703: }
8704: $inststatus = $userenv{'inststatus'};
8705: } else {
8706: undef(%userenv);
8707: }
8708: }
8709: }
8710: if ($quota eq '' || wantarray) {
8711: if ($quotaname eq 'course') {
8712: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1136 raeburn 8713: if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'community')) {
8714: $defquota = $domdefs{$crstype.'quota'};
8715: }
8716: if ($defquota eq '') {
8717: $defquota = 500;
8718: }
1.1134 raeburn 8719: } else {
8720: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8721: }
8722: if ($quota eq '') {
8723: $quota = $defquota;
8724: $quotatype = 'default';
8725: } else {
8726: $quotatype = 'custom';
8727: }
1.472 raeburn 8728: }
8729: }
1.536 raeburn 8730: if (wantarray) {
8731: return ($quota,$quotatype,$settingstatus,$defquota);
8732: } else {
8733: return $quota;
8734: }
1.472 raeburn 8735: }
8736:
8737: ###############################################
8738:
8739: =pod
8740:
8741: =item * &default_quota()
8742:
1.536 raeburn 8743: Retrieves default quota assigned for storage of user portfolio files,
8744: given an (optional) user's institutional status.
1.472 raeburn 8745:
8746: Incoming parameters:
8747: 1. domain
1.536 raeburn 8748: 2. (Optional) institutional status(es). This is a : separated list of
8749: status types (e.g., faculty, staff, student etc.)
8750: which apply to the user for whom the default is being retrieved.
8751: If the institutional status string in undefined, the domain
1.1134 raeburn 8752: default quota will be returned.
8753: 3. quota name - portfolio, author, or course
8754: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8755:
8756: Returns:
8757: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 8758: 2. (Optional) institutional type which determined the value of the
8759: default quota.
1.472 raeburn 8760:
8761: If a value has been stored in the domain's configuration db,
8762: it will return that, otherwise it returns 20 (for backwards
8763: compatibility with domains which have not set up a configuration
8764: db file; the original statically defined portfolio quota was 20 Mb).
8765:
1.536 raeburn 8766: If the user's status includes multiple types (e.g., staff and student),
8767: the largest default quota which applies to the user determines the
8768: default quota returned.
8769:
1.780 raeburn 8770: =back
8771:
1.472 raeburn 8772: =cut
8773:
8774: ###############################################
8775:
8776:
8777: sub default_quota {
1.1134 raeburn 8778: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8779: my ($defquota,$settingstatus);
8780: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8781: ['quotas'],$udom);
1.1134 raeburn 8782: my $key = 'defaultquota';
8783: if ($quotaname eq 'author') {
8784: $key = 'authorquota';
8785: }
1.622 raeburn 8786: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8787: if ($inststatus ne '') {
1.765 raeburn 8788: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8789: foreach my $item (@statuses) {
1.1134 raeburn 8790: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8791: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8792: if ($defquota eq '') {
1.1134 raeburn 8793: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8794: $settingstatus = $item;
1.1134 raeburn 8795: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8796: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8797: $settingstatus = $item;
8798: }
8799: }
1.1134 raeburn 8800: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8801: if ($quotahash{'quotas'}{$item} ne '') {
8802: if ($defquota eq '') {
8803: $defquota = $quotahash{'quotas'}{$item};
8804: $settingstatus = $item;
8805: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8806: $defquota = $quotahash{'quotas'}{$item};
8807: $settingstatus = $item;
8808: }
1.536 raeburn 8809: }
8810: }
8811: }
8812: }
8813: if ($defquota eq '') {
1.1134 raeburn 8814: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8815: $defquota = $quotahash{'quotas'}{$key}{'default'};
8816: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8817: $defquota = $quotahash{'quotas'}{'default'};
8818: }
1.536 raeburn 8819: $settingstatus = 'default';
1.1139 ! raeburn 8820: if ($defquota eq '') {
! 8821: if ($quotaname eq 'author') {
! 8822: $defquota = 500;
! 8823: }
! 8824: }
1.536 raeburn 8825: }
8826: } else {
8827: $settingstatus = 'default';
1.1134 raeburn 8828: if ($quotaname eq 'author') {
8829: $defquota = 500;
8830: } else {
8831: $defquota = 20;
8832: }
1.536 raeburn 8833: }
8834: if (wantarray) {
8835: return ($defquota,$settingstatus);
1.472 raeburn 8836: } else {
1.536 raeburn 8837: return $defquota;
1.472 raeburn 8838: }
8839: }
8840:
1.1135 raeburn 8841: ###############################################
8842:
8843: =pod
8844:
1.1136 raeburn 8845: =item * &excess_filesize_warning()
1.1135 raeburn 8846:
8847: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 8848: of existing file within authoring space will cause quota for the authoring
8849: space to be exceeded,
8850:
8851: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 8852: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 8853:
8854: Inputs: 6
1.1136 raeburn 8855: 1. username or coursenum
1.1135 raeburn 8856: 2. domain
1.1136 raeburn 8857: 3. context ('author' or 'course')
1.1135 raeburn 8858: 4. filename of file for which action is being requested
8859: 5. filesize (kB) of file
8860: 6. action being taken: copy or upload.
8861:
8862: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
8863: otherwise return null.
8864:
8865: =cut
8866:
1.1136 raeburn 8867: sub excess_filesize_warning {
8868: my ($uname,$udom,$context,$filename,$filesize,$action) = @_;
8869: my $current_disk_usage = 0;
8870: my $disk_quota = &get_user_quota($uname,$udom,$context); #expressed in MB
8871: if ($context eq 'author') {
8872: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8873: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8874: } else {
8875: foreach my $subdir ('docs','supplemental') {
8876: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8877: }
8878: }
1.1135 raeburn 8879: $disk_quota = int($disk_quota * 1000);
8880: if (($current_disk_usage + $filesize) > $disk_quota) {
8881: return '<p><span class="LC_warning">'.
8882: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
8883: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</span>'.
8884: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
8885: $disk_quota,$current_disk_usage).
8886: '</p>';
8887: }
8888: return;
8889: }
8890:
8891: ###############################################
8892:
8893:
1.1136 raeburn 8894:
8895:
1.384 raeburn 8896: sub get_secgrprole_info {
8897: my ($cdom,$cnum,$needroles,$type) = @_;
8898: my %sections_count = &get_sections($cdom,$cnum);
8899: my @sections = (sort {$a <=> $b} keys(%sections_count));
8900: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8901: my @groups = sort(keys(%curr_groups));
8902: my $allroles = [];
8903: my $rolehash;
8904: my $accesshash = {
8905: active => 'Currently has access',
8906: future => 'Will have future access',
8907: previous => 'Previously had access',
8908: };
8909: if ($needroles) {
8910: $rolehash = {'all' => 'all'};
1.385 albertel 8911: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8912: if (&Apache::lonnet::error(%user_roles)) {
8913: undef(%user_roles);
8914: }
8915: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8916: my ($role)=split(/\:/,$item,2);
8917: if ($role eq 'cr') { next; }
8918: if ($role =~ /^cr/) {
8919: $$rolehash{$role} = (split('/',$role))[3];
8920: } else {
8921: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8922: }
8923: }
8924: foreach my $key (sort(keys(%{$rolehash}))) {
8925: push(@{$allroles},$key);
8926: }
8927: push (@{$allroles},'st');
8928: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8929: }
8930: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8931: }
8932:
1.555 raeburn 8933: sub user_picker {
1.994 raeburn 8934: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8935: my $currdom = $dom;
8936: my %curr_selected = (
8937: srchin => 'dom',
1.580 raeburn 8938: srchby => 'lastname',
1.555 raeburn 8939: );
8940: my $srchterm;
1.625 raeburn 8941: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 8942: if ($srch->{'srchby'} ne '') {
8943: $curr_selected{'srchby'} = $srch->{'srchby'};
8944: }
8945: if ($srch->{'srchin'} ne '') {
8946: $curr_selected{'srchin'} = $srch->{'srchin'};
8947: }
8948: if ($srch->{'srchtype'} ne '') {
8949: $curr_selected{'srchtype'} = $srch->{'srchtype'};
8950: }
8951: if ($srch->{'srchdomain'} ne '') {
8952: $currdom = $srch->{'srchdomain'};
8953: }
8954: $srchterm = $srch->{'srchterm'};
8955: }
8956: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 8957: 'usr' => 'Search criteria',
1.563 raeburn 8958: 'doma' => 'Domain/institution to search',
1.558 albertel 8959: 'uname' => 'username',
8960: 'lastname' => 'last name',
1.555 raeburn 8961: 'lastfirst' => 'last name, first name',
1.558 albertel 8962: 'crs' => 'in this course',
1.576 raeburn 8963: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 8964: 'alc' => 'all LON-CAPA',
1.573 raeburn 8965: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 8966: 'exact' => 'is',
8967: 'contains' => 'contains',
1.569 raeburn 8968: 'begins' => 'begins with',
1.571 raeburn 8969: 'youm' => "You must include some text to search for.",
8970: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
8971: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
8972: 'yomc' => "You must choose a domain when using an institutional directory search.",
8973: 'ymcd' => "You must choose a domain when using a domain search.",
8974: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
8975: 'whse' => "When searching by last,first you must include at least one character in the first name.",
8976: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 8977: );
1.563 raeburn 8978: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
8979: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 8980:
8981: my @srchins = ('crs','dom','alc','instd');
8982:
8983: foreach my $option (@srchins) {
8984: # FIXME 'alc' option unavailable until
8985: # loncreateuser::print_user_query_page()
8986: # has been completed.
8987: next if ($option eq 'alc');
1.880 raeburn 8988: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 8989: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 8990: if ($curr_selected{'srchin'} eq $option) {
8991: $srchinsel .= '
8992: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8993: } else {
8994: $srchinsel .= '
8995: <option value="'.$option.'">'.$lt{$option}.'</option>';
8996: }
1.555 raeburn 8997: }
1.563 raeburn 8998: $srchinsel .= "\n </select>\n";
1.555 raeburn 8999:
9000: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9001: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9002: if ($curr_selected{'srchby'} eq $option) {
9003: $srchbysel .= '
9004: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9005: } else {
9006: $srchbysel .= '
9007: <option value="'.$option.'">'.$lt{$option}.'</option>';
9008: }
9009: }
9010: $srchbysel .= "\n </select>\n";
9011:
9012: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9013: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9014: if ($curr_selected{'srchtype'} eq $option) {
9015: $srchtypesel .= '
9016: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9017: } else {
9018: $srchtypesel .= '
9019: <option value="'.$option.'">'.$lt{$option}.'</option>';
9020: }
9021: }
9022: $srchtypesel .= "\n </select>\n";
9023:
1.558 albertel 9024: my ($newuserscript,$new_user_create);
1.994 raeburn 9025: my $context_dom = $env{'request.role.domain'};
9026: if ($context eq 'requestcrs') {
9027: if ($env{'form.coursedom'} ne '') {
9028: $context_dom = $env{'form.coursedom'};
9029: }
9030: }
1.556 raeburn 9031: if ($forcenewuser) {
1.576 raeburn 9032: if (ref($srch) eq 'HASH') {
1.994 raeburn 9033: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9034: if ($cancreate) {
9035: $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>';
9036: } else {
1.799 bisitz 9037: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9038: my %usertypetext = (
9039: official => 'institutional',
9040: unofficial => 'non-institutional',
9041: );
1.799 bisitz 9042: $new_user_create = '<p class="LC_warning">'
9043: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9044: .' '
9045: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9046: ,'<a href="'.$helplink.'">','</a>')
9047: .'</p><br />';
1.627 raeburn 9048: }
1.576 raeburn 9049: }
9050: }
9051:
1.556 raeburn 9052: $newuserscript = <<"ENDSCRIPT";
9053:
1.570 raeburn 9054: function setSearch(createnew,callingForm) {
1.556 raeburn 9055: if (createnew == 1) {
1.570 raeburn 9056: for (var i=0; i<callingForm.srchby.length; i++) {
9057: if (callingForm.srchby.options[i].value == 'uname') {
9058: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9059: }
9060: }
1.570 raeburn 9061: for (var i=0; i<callingForm.srchin.length; i++) {
9062: if ( callingForm.srchin.options[i].value == 'dom') {
9063: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9064: }
9065: }
1.570 raeburn 9066: for (var i=0; i<callingForm.srchtype.length; i++) {
9067: if (callingForm.srchtype.options[i].value == 'exact') {
9068: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9069: }
9070: }
1.570 raeburn 9071: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9072: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9073: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9074: }
9075: }
9076: }
9077: }
9078: ENDSCRIPT
1.558 albertel 9079:
1.556 raeburn 9080: }
9081:
1.555 raeburn 9082: my $output = <<"END_BLOCK";
1.556 raeburn 9083: <script type="text/javascript">
1.824 bisitz 9084: // <![CDATA[
1.570 raeburn 9085: function validateEntry(callingForm) {
1.558 albertel 9086:
1.556 raeburn 9087: var checkok = 1;
1.558 albertel 9088: var srchin;
1.570 raeburn 9089: for (var i=0; i<callingForm.srchin.length; i++) {
9090: if ( callingForm.srchin[i].checked ) {
9091: srchin = callingForm.srchin[i].value;
1.558 albertel 9092: }
9093: }
9094:
1.570 raeburn 9095: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9096: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9097: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9098: var srchterm = callingForm.srchterm.value;
9099: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9100: var msg = "";
9101:
9102: if (srchterm == "") {
9103: checkok = 0;
1.571 raeburn 9104: msg += "$lt{'youm'}\\n";
1.556 raeburn 9105: }
9106:
1.569 raeburn 9107: if (srchtype== 'begins') {
9108: if (srchterm.length < 2) {
9109: checkok = 0;
1.571 raeburn 9110: msg += "$lt{'thte'}\\n";
1.569 raeburn 9111: }
9112: }
9113:
1.556 raeburn 9114: if (srchtype== 'contains') {
9115: if (srchterm.length < 3) {
9116: checkok = 0;
1.571 raeburn 9117: msg += "$lt{'thet'}\\n";
1.556 raeburn 9118: }
9119: }
9120: if (srchin == 'instd') {
9121: if (srchdomain == '') {
9122: checkok = 0;
1.571 raeburn 9123: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9124: }
9125: }
9126: if (srchin == 'dom') {
9127: if (srchdomain == '') {
9128: checkok = 0;
1.571 raeburn 9129: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9130: }
9131: }
9132: if (srchby == 'lastfirst') {
9133: if (srchterm.indexOf(",") == -1) {
9134: checkok = 0;
1.571 raeburn 9135: msg += "$lt{'whus'}\\n";
1.556 raeburn 9136: }
9137: if (srchterm.indexOf(",") == srchterm.length -1) {
9138: checkok = 0;
1.571 raeburn 9139: msg += "$lt{'whse'}\\n";
1.556 raeburn 9140: }
9141: }
9142: if (checkok == 0) {
1.571 raeburn 9143: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9144: return;
9145: }
9146: if (checkok == 1) {
1.570 raeburn 9147: callingForm.submit();
1.556 raeburn 9148: }
9149: }
9150:
9151: $newuserscript
9152:
1.824 bisitz 9153: // ]]>
1.556 raeburn 9154: </script>
1.558 albertel 9155:
9156: $new_user_create
9157:
1.555 raeburn 9158: END_BLOCK
1.558 albertel 9159:
1.876 raeburn 9160: $output .= &Apache::lonhtmlcommon::start_pick_box().
9161: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9162: $domform.
9163: &Apache::lonhtmlcommon::row_closure().
9164: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9165: $srchbysel.
9166: $srchtypesel.
9167: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9168: $srchinsel.
9169: &Apache::lonhtmlcommon::row_closure(1).
9170: &Apache::lonhtmlcommon::end_pick_box().
9171: '<br />';
1.555 raeburn 9172: return $output;
9173: }
9174:
1.612 raeburn 9175: sub user_rule_check {
1.615 raeburn 9176: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9177: my $response;
9178: if (ref($usershash) eq 'HASH') {
9179: foreach my $user (keys(%{$usershash})) {
9180: my ($uname,$udom) = split(/:/,$user);
9181: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9182: my ($id,$newuser);
1.612 raeburn 9183: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9184: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9185: $id = $usershash->{$user}->{'id'};
9186: }
9187: my $inst_response;
9188: if (ref($checks) eq 'HASH') {
9189: if (defined($checks->{'username'})) {
1.615 raeburn 9190: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9191: &Apache::lonnet::get_instuser($udom,$uname);
9192: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9193: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9194: &Apache::lonnet::get_instuser($udom,undef,$id);
9195: }
1.615 raeburn 9196: } else {
9197: ($inst_response,%{$inst_results->{$user}}) =
9198: &Apache::lonnet::get_instuser($udom,$uname);
9199: return;
1.612 raeburn 9200: }
1.615 raeburn 9201: if (!$got_rules->{$udom}) {
1.612 raeburn 9202: my %domconfig = &Apache::lonnet::get_dom('configuration',
9203: ['usercreation'],$udom);
9204: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9205: foreach my $item ('username','id') {
1.612 raeburn 9206: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9207: $$curr_rules{$udom}{$item} =
9208: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9209: }
9210: }
9211: }
1.615 raeburn 9212: $got_rules->{$udom} = 1;
1.585 raeburn 9213: }
1.612 raeburn 9214: foreach my $item (keys(%{$checks})) {
9215: if (ref($$curr_rules{$udom}) eq 'HASH') {
9216: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9217: if (@{$$curr_rules{$udom}{$item}} > 0) {
9218: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9219: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9220: if ($rule_check{$rule}) {
9221: $$rulematch{$user}{$item} = $rule;
9222: if ($inst_response eq 'ok') {
1.615 raeburn 9223: if (ref($inst_results) eq 'HASH') {
9224: if (ref($inst_results->{$user}) eq 'HASH') {
9225: if (keys(%{$inst_results->{$user}}) == 0) {
9226: $$alerts{$item}{$udom}{$uname} = 1;
9227: }
1.612 raeburn 9228: }
9229: }
1.615 raeburn 9230: }
9231: last;
1.585 raeburn 9232: }
9233: }
9234: }
9235: }
9236: }
9237: }
9238: }
9239: }
1.612 raeburn 9240: return;
9241: }
9242:
9243: sub user_rule_formats {
9244: my ($domain,$domdesc,$curr_rules,$check) = @_;
9245: my %text = (
9246: 'username' => 'Usernames',
9247: 'id' => 'IDs',
9248: );
9249: my $output;
9250: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9251: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9252: if (@{$ruleorder} > 0) {
1.1102 raeburn 9253: $output = '<br />'.
9254: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9255: '<span class="LC_cusr_emph">','</span>',$domdesc).
9256: ' <ul>';
1.612 raeburn 9257: foreach my $rule (@{$ruleorder}) {
9258: if (ref($curr_rules) eq 'ARRAY') {
9259: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9260: if (ref($rules->{$rule}) eq 'HASH') {
9261: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9262: $rules->{$rule}{'desc'}.'</li>';
9263: }
9264: }
9265: }
9266: }
9267: $output .= '</ul>';
9268: }
9269: }
9270: return $output;
9271: }
9272:
9273: sub instrule_disallow_msg {
1.615 raeburn 9274: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9275: my $response;
9276: my %text = (
9277: item => 'username',
9278: items => 'usernames',
9279: match => 'matches',
9280: do => 'does',
9281: action => 'a username',
9282: one => 'one',
9283: );
9284: if ($count > 1) {
9285: $text{'item'} = 'usernames';
9286: $text{'match'} ='match';
9287: $text{'do'} = 'do';
9288: $text{'action'} = 'usernames',
9289: $text{'one'} = 'ones';
9290: }
9291: if ($checkitem eq 'id') {
9292: $text{'items'} = 'IDs';
9293: $text{'item'} = 'ID';
9294: $text{'action'} = 'an ID';
1.615 raeburn 9295: if ($count > 1) {
9296: $text{'item'} = 'IDs';
9297: $text{'action'} = 'IDs';
9298: }
1.612 raeburn 9299: }
1.674 bisitz 9300: $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 9301: if ($mode eq 'upload') {
9302: if ($checkitem eq 'username') {
9303: $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'}.");
9304: } elsif ($checkitem eq 'id') {
1.674 bisitz 9305: $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 9306: }
1.669 raeburn 9307: } elsif ($mode eq 'selfcreate') {
9308: if ($checkitem eq 'id') {
9309: $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.");
9310: }
1.615 raeburn 9311: } else {
9312: if ($checkitem eq 'username') {
9313: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9314: } elsif ($checkitem eq 'id') {
9315: $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.");
9316: }
1.612 raeburn 9317: }
9318: return $response;
1.585 raeburn 9319: }
9320:
1.624 raeburn 9321: sub personal_data_fieldtitles {
9322: my %fieldtitles = &Apache::lonlocal::texthash (
9323: id => 'Student/Employee ID',
9324: permanentemail => 'E-mail address',
9325: lastname => 'Last Name',
9326: firstname => 'First Name',
9327: middlename => 'Middle Name',
9328: generation => 'Generation',
9329: gen => 'Generation',
1.765 raeburn 9330: inststatus => 'Affiliation',
1.624 raeburn 9331: );
9332: return %fieldtitles;
9333: }
9334:
1.642 raeburn 9335: sub sorted_inst_types {
9336: my ($dom) = @_;
9337: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9338: my $othertitle = &mt('All users');
9339: if ($env{'request.course.id'}) {
1.668 raeburn 9340: $othertitle = &mt('Any users');
1.642 raeburn 9341: }
9342: my @types;
9343: if (ref($order) eq 'ARRAY') {
9344: @types = @{$order};
9345: }
9346: if (@types == 0) {
9347: if (ref($usertypes) eq 'HASH') {
9348: @types = sort(keys(%{$usertypes}));
9349: }
9350: }
9351: if (keys(%{$usertypes}) > 0) {
9352: $othertitle = &mt('Other users');
9353: }
9354: return ($othertitle,$usertypes,\@types);
9355: }
9356:
1.645 raeburn 9357: sub get_institutional_codes {
9358: my ($settings,$allcourses,$LC_code) = @_;
9359: # Get complete list of course sections to update
9360: my @currsections = ();
9361: my @currxlists = ();
9362: my $coursecode = $$settings{'internal.coursecode'};
9363:
9364: if ($$settings{'internal.sectionnums'} ne '') {
9365: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9366: }
9367:
9368: if ($$settings{'internal.crosslistings'} ne '') {
9369: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9370: }
9371:
9372: if (@currxlists > 0) {
9373: foreach (@currxlists) {
9374: if (m/^([^:]+):(\w*)$/) {
9375: unless (grep/^$1$/,@{$allcourses}) {
9376: push @{$allcourses},$1;
9377: $$LC_code{$1} = $2;
9378: }
9379: }
9380: }
9381: }
9382:
9383: if (@currsections > 0) {
9384: foreach (@currsections) {
9385: if (m/^(\w+):(\w*)$/) {
9386: my $sec = $coursecode.$1;
9387: my $lc_sec = $2;
9388: unless (grep/^$sec$/,@{$allcourses}) {
9389: push @{$allcourses},$sec;
9390: $$LC_code{$sec} = $lc_sec;
9391: }
9392: }
9393: }
9394: }
9395: return;
9396: }
9397:
1.971 raeburn 9398: sub get_standard_codeitems {
9399: return ('Year','Semester','Department','Number','Section');
9400: }
9401:
1.112 bowersj2 9402: =pod
9403:
1.780 raeburn 9404: =head1 Slot Helpers
9405:
9406: =over 4
9407:
9408: =item * sorted_slots()
9409:
1.1040 raeburn 9410: Sorts an array of slot names in order of an optional sort key,
9411: default sort is by slot start time (earliest first).
1.780 raeburn 9412:
9413: Inputs:
9414:
9415: =over 4
9416:
9417: slotsarr - Reference to array of unsorted slot names.
9418:
9419: slots - Reference to hash of hash, where outer hash keys are slot names.
9420:
1.1040 raeburn 9421: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9422:
1.549 albertel 9423: =back
9424:
1.780 raeburn 9425: Returns:
9426:
9427: =over 4
9428:
1.1040 raeburn 9429: sorted - An array of slot names sorted by a specified sort key
9430: (default sort key is start time of the slot).
1.780 raeburn 9431:
9432: =back
9433:
9434: =cut
9435:
9436:
9437: sub sorted_slots {
1.1040 raeburn 9438: my ($slotsarr,$slots,$sortkey) = @_;
9439: if ($sortkey eq '') {
9440: $sortkey = 'starttime';
9441: }
1.780 raeburn 9442: my @sorted;
9443: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9444: @sorted =
9445: sort {
9446: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9447: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9448: }
9449: if (ref($slots->{$a})) { return -1;}
9450: if (ref($slots->{$b})) { return 1;}
9451: return 0;
9452: } @{$slotsarr};
9453: }
9454: return @sorted;
9455: }
9456:
1.1040 raeburn 9457: =pod
9458:
9459: =item * get_future_slots()
9460:
9461: Inputs:
9462:
9463: =over 4
9464:
9465: cnum - course number
9466:
9467: cdom - course domain
9468:
9469: now - current UNIX time
9470:
9471: symb - optional symb
9472:
9473: =back
9474:
9475: Returns:
9476:
9477: =over 4
9478:
9479: sorted_reservable - ref to array of student_schedulable slots currently
9480: reservable, ordered by end date of reservation period.
9481:
9482: reservable_now - ref to hash of student_schedulable slots currently
9483: reservable.
9484:
9485: Keys in inner hash are:
9486: (a) symb: either blank or symb to which slot use is restricted.
9487: (b) endreserve: end date of reservation period.
9488:
9489: sorted_future - ref to array of student_schedulable slots reservable in
9490: the future, ordered by start date of reservation period.
9491:
9492: future_reservable - ref to hash of student_schedulable slots reservable
9493: in the future.
9494:
9495: Keys in inner hash are:
9496: (a) symb: either blank or symb to which slot use is restricted.
9497: (b) startreserve: start date of reservation period.
9498:
9499: =back
9500:
9501: =cut
9502:
9503: sub get_future_slots {
9504: my ($cnum,$cdom,$now,$symb) = @_;
9505: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9506: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9507: foreach my $slot (keys(%slots)) {
9508: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9509: if ($symb) {
9510: next if (($slots{$slot}->{'symb'} ne '') &&
9511: ($slots{$slot}->{'symb'} ne $symb));
9512: }
9513: if (($slots{$slot}->{'starttime'} > $now) &&
9514: ($slots{$slot}->{'endtime'} > $now)) {
9515: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9516: my $userallowed = 0;
9517: if ($slots{$slot}->{'allowedsections'}) {
9518: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9519: if (!defined($env{'request.role.sec'})
9520: && grep(/^No section assigned$/,@allowed_sec)) {
9521: $userallowed=1;
9522: } else {
9523: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9524: $userallowed=1;
9525: }
9526: }
9527: unless ($userallowed) {
9528: if (defined($env{'request.course.groups'})) {
9529: my @groups = split(/:/,$env{'request.course.groups'});
9530: foreach my $group (@groups) {
9531: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9532: $userallowed=1;
9533: last;
9534: }
9535: }
9536: }
9537: }
9538: }
9539: if ($slots{$slot}->{'allowedusers'}) {
9540: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9541: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9542: if (grep(/^\Q$user\E$/,@allowed_users)) {
9543: $userallowed = 1;
9544: }
9545: }
9546: next unless($userallowed);
9547: }
9548: my $startreserve = $slots{$slot}->{'startreserve'};
9549: my $endreserve = $slots{$slot}->{'endreserve'};
9550: my $symb = $slots{$slot}->{'symb'};
9551: if (($startreserve < $now) &&
9552: (!$endreserve || $endreserve > $now)) {
9553: my $lastres = $endreserve;
9554: if (!$lastres) {
9555: $lastres = $slots{$slot}->{'starttime'};
9556: }
9557: $reservable_now{$slot} = {
9558: symb => $symb,
9559: endreserve => $lastres
9560: };
9561: } elsif (($startreserve > $now) &&
9562: (!$endreserve || $endreserve > $startreserve)) {
9563: $future_reservable{$slot} = {
9564: symb => $symb,
9565: startreserve => $startreserve
9566: };
9567: }
9568: }
9569: }
9570: my @unsorted_reservable = keys(%reservable_now);
9571: if (@unsorted_reservable > 0) {
9572: @sorted_reservable =
9573: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9574: }
9575: my @unsorted_future = keys(%future_reservable);
9576: if (@unsorted_future > 0) {
9577: @sorted_future =
9578: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9579: }
9580: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9581: }
1.780 raeburn 9582:
9583: =pod
9584:
1.1057 foxr 9585: =back
9586:
1.549 albertel 9587: =head1 HTTP Helpers
9588:
9589: =over 4
9590:
1.648 raeburn 9591: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9592:
1.258 albertel 9593: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9594: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9595: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9596:
9597: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9598: $possible_names is an ref to an array of form element names. As an example:
9599: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9600: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9601:
9602: =cut
1.1 albertel 9603:
1.6 albertel 9604: sub get_unprocessed_cgi {
1.25 albertel 9605: my ($query,$possible_names)= @_;
1.26 matthew 9606: # $Apache::lonxml::debug=1;
1.356 albertel 9607: foreach my $pair (split(/&/,$query)) {
9608: my ($name, $value) = split(/=/,$pair);
1.369 www 9609: $name = &unescape($name);
1.25 albertel 9610: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9611: $value =~ tr/+/ /;
9612: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9613: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9614: }
1.16 harris41 9615: }
1.6 albertel 9616: }
9617:
1.112 bowersj2 9618: =pod
9619:
1.648 raeburn 9620: =item * &cacheheader()
1.112 bowersj2 9621:
9622: returns cache-controlling header code
9623:
9624: =cut
9625:
1.7 albertel 9626: sub cacheheader {
1.258 albertel 9627: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9628: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9629: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9630: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9631: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9632: return $output;
1.7 albertel 9633: }
9634:
1.112 bowersj2 9635: =pod
9636:
1.648 raeburn 9637: =item * &no_cache($r)
1.112 bowersj2 9638:
9639: specifies header code to not have cache
9640:
9641: =cut
9642:
1.9 albertel 9643: sub no_cache {
1.216 albertel 9644: my ($r) = @_;
9645: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9646: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9647: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9648: $r->no_cache(1);
9649: $r->header_out("Expires" => $date);
9650: $r->header_out("Pragma" => "no-cache");
1.123 www 9651: }
9652:
9653: sub content_type {
1.181 albertel 9654: my ($r,$type,$charset) = @_;
1.299 foxr 9655: if ($r) {
9656: # Note that printout.pl calls this with undef for $r.
9657: &no_cache($r);
9658: }
1.258 albertel 9659: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9660: unless ($charset) {
9661: $charset=&Apache::lonlocal::current_encoding;
9662: }
9663: if ($charset) { $type.='; charset='.$charset; }
9664: if ($r) {
9665: $r->content_type($type);
9666: } else {
9667: print("Content-type: $type\n\n");
9668: }
1.9 albertel 9669: }
1.25 albertel 9670:
1.112 bowersj2 9671: =pod
9672:
1.648 raeburn 9673: =item * &add_to_env($name,$value)
1.112 bowersj2 9674:
1.258 albertel 9675: adds $name to the %env hash with value
1.112 bowersj2 9676: $value, if $name already exists, the entry is converted to an array
9677: reference and $value is added to the array.
9678:
9679: =cut
9680:
1.25 albertel 9681: sub add_to_env {
9682: my ($name,$value)=@_;
1.258 albertel 9683: if (defined($env{$name})) {
9684: if (ref($env{$name})) {
1.25 albertel 9685: #already have multiple values
1.258 albertel 9686: push(@{ $env{$name} },$value);
1.25 albertel 9687: } else {
9688: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9689: my $first=$env{$name};
9690: undef($env{$name});
9691: push(@{ $env{$name} },$first,$value);
1.25 albertel 9692: }
9693: } else {
1.258 albertel 9694: $env{$name}=$value;
1.25 albertel 9695: }
1.31 albertel 9696: }
1.149 albertel 9697:
9698: =pod
9699:
1.648 raeburn 9700: =item * &get_env_multiple($name)
1.149 albertel 9701:
1.258 albertel 9702: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9703: values may be defined and end up as an array ref.
9704:
9705: returns an array of values
9706:
9707: =cut
9708:
9709: sub get_env_multiple {
9710: my ($name) = @_;
9711: my @values;
1.258 albertel 9712: if (defined($env{$name})) {
1.149 albertel 9713: # exists is it an array
1.258 albertel 9714: if (ref($env{$name})) {
9715: @values=@{ $env{$name} };
1.149 albertel 9716: } else {
1.258 albertel 9717: $values[0]=$env{$name};
1.149 albertel 9718: }
9719: }
9720: return(@values);
9721: }
9722:
1.660 raeburn 9723: sub ask_for_embedded_content {
9724: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9725: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 9726: %currsubfile,%unused,$rem);
1.1071 raeburn 9727: my $counter = 0;
9728: my $numnew = 0;
1.987 raeburn 9729: my $numremref = 0;
9730: my $numinvalid = 0;
9731: my $numpathchg = 0;
9732: my $numexisting = 0;
1.1071 raeburn 9733: my $numunused = 0;
9734: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
9735: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
9736: my $heading = &mt('Upload embedded files');
9737: my $buttontext = &mt('Upload');
9738:
1.1123 raeburn 9739: my ($navmap,$cdom,$cnum);
1.1085 raeburn 9740: if ($env{'request.course.id'}) {
1.1123 raeburn 9741: if ($actionurl eq '/adm/dependencies') {
9742: $navmap = Apache::lonnavmaps::navmap->new();
9743: }
9744: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9745: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 9746: }
1.1123 raeburn 9747: if (($actionurl eq '/adm/portfolio') ||
9748: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9749: my $current_path='/';
9750: if ($env{'form.currentpath'}) {
9751: $current_path = $env{'form.currentpath'};
9752: }
9753: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 9754: $udom = $cdom;
9755: $uname = $cnum;
1.984 raeburn 9756: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9757: } else {
9758: $udom = $env{'user.domain'};
9759: $uname = $env{'user.name'};
9760: $url = '/userfiles/portfolio';
9761: }
1.987 raeburn 9762: $toplevel = $url.'/';
1.984 raeburn 9763: $url .= $current_path;
9764: $getpropath = 1;
1.987 raeburn 9765: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9766: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9767: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9768: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9769: $toplevel = $url;
1.984 raeburn 9770: if ($rest ne '') {
1.987 raeburn 9771: $url .= $rest;
9772: }
9773: } elsif ($actionurl eq '/adm/coursedocs') {
9774: if (ref($args) eq 'HASH') {
1.1071 raeburn 9775: $url = $args->{'docs_url'};
9776: $toplevel = $url;
1.1084 raeburn 9777: if ($args->{'context'} eq 'paste') {
9778: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9779: ($path) =
9780: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9781: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9782: $fileloc =~ s{^/}{};
9783: }
1.1071 raeburn 9784: }
1.1084 raeburn 9785: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 9786: if ($env{'request.course.id'} ne '') {
9787: if (ref($args) eq 'HASH') {
9788: $url = $args->{'docs_url'};
9789: $title = $args->{'docs_title'};
1.1126 raeburn 9790: $toplevel = $url;
9791: unless ($toplevel =~ m{^/}) {
9792: $toplevel = "/$url";
9793: }
1.1085 raeburn 9794: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 9795: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9796: $path = $1;
9797: } else {
9798: ($path) =
9799: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9800: }
1.1071 raeburn 9801: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9802: $fileloc =~ s{^/}{};
9803: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9804: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9805: }
1.987 raeburn 9806: }
1.1123 raeburn 9807: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9808: $udom = $cdom;
9809: $uname = $cnum;
9810: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9811: $toplevel = $url;
9812: $path = $url;
9813: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9814: $fileloc =~ s{^/}{};
1.987 raeburn 9815: }
1.1126 raeburn 9816: foreach my $file (keys(%{$allfiles})) {
9817: my $embed_file;
9818: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9819: $embed_file = $1;
9820: } else {
9821: $embed_file = $file;
9822: }
1.987 raeburn 9823: my $absolutepath;
9824: if ($embed_file =~ m{^\w+://}) {
9825: $newfiles{$embed_file} = 1;
9826: $mapping{$embed_file} = $embed_file;
9827: } else {
9828: if ($embed_file =~ m{^/}) {
9829: $absolutepath = $embed_file;
9830: $embed_file =~ s{^(/+)}{};
9831: }
9832: if ($embed_file =~ m{/}) {
9833: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
9834: $path = &check_for_traversal($path,$url,$toplevel);
9835: my $item = $fname;
9836: if ($path ne '') {
9837: $item = $path.'/'.$fname;
9838: $subdependencies{$path}{$fname} = 1;
9839: } else {
9840: $dependencies{$item} = 1;
9841: }
9842: if ($absolutepath) {
9843: $mapping{$item} = $absolutepath;
9844: } else {
9845: $mapping{$item} = $embed_file;
9846: }
9847: } else {
9848: $dependencies{$embed_file} = 1;
9849: if ($absolutepath) {
9850: $mapping{$embed_file} = $absolutepath;
9851: } else {
9852: $mapping{$embed_file} = $embed_file;
9853: }
9854: }
1.984 raeburn 9855: }
9856: }
1.1071 raeburn 9857: my $dirptr = 16384;
1.984 raeburn 9858: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9859: $currsubfile{$path} = {};
1.1123 raeburn 9860: if (($actionurl eq '/adm/portfolio') ||
9861: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9862: my ($sublistref,$listerror) =
9863: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9864: if (ref($sublistref) eq 'ARRAY') {
9865: foreach my $line (@{$sublistref}) {
9866: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9867: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9868: }
1.984 raeburn 9869: }
1.987 raeburn 9870: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9871: if (opendir(my $dir,$url.'/'.$path)) {
9872: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9873: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9874: }
1.1084 raeburn 9875: } elsif (($actionurl eq '/adm/dependencies') ||
9876: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 9877: ($args->{'context'} eq 'paste')) ||
9878: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9879: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 9880: my $dir;
9881: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9882: $dir = $fileloc;
9883: } else {
9884: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9885: }
1.1071 raeburn 9886: if ($dir ne '') {
9887: my ($sublistref,$listerror) =
9888: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9889: if (ref($sublistref) eq 'ARRAY') {
9890: foreach my $line (@{$sublistref}) {
9891: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9892: undef,$mtime)=split(/\&/,$line,12);
9893: unless (($testdir&$dirptr) ||
9894: ($file_name =~ /^\.\.?$/)) {
9895: $currsubfile{$path}{$file_name} = [$size,$mtime];
9896: }
9897: }
9898: }
9899: }
1.984 raeburn 9900: }
9901: }
9902: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9903: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9904: my $item = $path.'/'.$file;
9905: unless ($mapping{$item} eq $item) {
9906: $pathchanges{$item} = 1;
9907: }
9908: $existing{$item} = 1;
9909: $numexisting ++;
9910: } else {
9911: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9912: }
9913: }
1.1071 raeburn 9914: if ($actionurl eq '/adm/dependencies') {
9915: foreach my $path (keys(%currsubfile)) {
9916: if (ref($currsubfile{$path}) eq 'HASH') {
9917: foreach my $file (keys(%{$currsubfile{$path}})) {
9918: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 9919: next if (($rem ne '') &&
9920: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9921: (ref($navmap) &&
9922: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9923: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9924: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9925: $unused{$path.'/'.$file} = 1;
9926: }
9927: }
9928: }
9929: }
9930: }
1.984 raeburn 9931: }
1.987 raeburn 9932: my %currfile;
1.1123 raeburn 9933: if (($actionurl eq '/adm/portfolio') ||
9934: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9935: my ($dirlistref,$listerror) =
9936: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9937: if (ref($dirlistref) eq 'ARRAY') {
9938: foreach my $line (@{$dirlistref}) {
9939: my ($file_name,$rest) = split(/\&/,$line,2);
9940: $currfile{$file_name} = 1;
9941: }
1.984 raeburn 9942: }
1.987 raeburn 9943: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9944: if (opendir(my $dir,$url)) {
1.987 raeburn 9945: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 9946: map {$currfile{$_} = 1;} @dir_list;
9947: }
1.1084 raeburn 9948: } elsif (($actionurl eq '/adm/dependencies') ||
9949: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 9950: ($args->{'context'} eq 'paste')) ||
9951: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9952: if ($env{'request.course.id'} ne '') {
9953: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9954: if ($dir ne '') {
9955: my ($dirlistref,$listerror) =
9956: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
9957: if (ref($dirlistref) eq 'ARRAY') {
9958: foreach my $line (@{$dirlistref}) {
9959: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
9960: $size,undef,$mtime)=split(/\&/,$line,12);
9961: unless (($testdir&$dirptr) ||
9962: ($file_name =~ /^\.\.?$/)) {
9963: $currfile{$file_name} = [$size,$mtime];
9964: }
9965: }
9966: }
9967: }
9968: }
1.984 raeburn 9969: }
9970: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 9971: if (exists($currfile{$file})) {
1.987 raeburn 9972: unless ($mapping{$file} eq $file) {
9973: $pathchanges{$file} = 1;
9974: }
9975: $existing{$file} = 1;
9976: $numexisting ++;
9977: } else {
1.984 raeburn 9978: $newfiles{$file} = 1;
9979: }
9980: }
1.1071 raeburn 9981: foreach my $file (keys(%currfile)) {
9982: unless (($file eq $filename) ||
9983: ($file eq $filename.'.bak') ||
9984: ($dependencies{$file})) {
1.1085 raeburn 9985: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 9986: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
9987: next if (($rem ne '') &&
9988: (($env{"httpref.$rem".$file} ne '') ||
9989: (ref($navmap) &&
9990: (($navmap->getResourceByUrl($rem.$file) ne '') ||
9991: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9992: ($navmap->getResourceByUrl($rem.$1)))))));
9993: }
1.1085 raeburn 9994: }
1.1071 raeburn 9995: $unused{$file} = 1;
9996: }
9997: }
1.1084 raeburn 9998: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9999: ($args->{'context'} eq 'paste')) {
10000: $counter = scalar(keys(%existing));
10001: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 10002: return ($output,$counter,$numpathchg,\%existing);
10003: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10004: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10005: $counter = scalar(keys(%existing));
10006: $numpathchg = scalar(keys(%pathchanges));
10007: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 10008: }
1.984 raeburn 10009: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10010: if ($actionurl eq '/adm/dependencies') {
10011: next if ($embed_file =~ m{^\w+://});
10012: }
1.660 raeburn 10013: $upload_output .= &start_data_table_row().
1.1123 raeburn 10014: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10015: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10016: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 10017: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10018: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10019: }
1.1123 raeburn 10020: $upload_output .= '</td>';
1.1071 raeburn 10021: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 10022: $upload_output.='<td align="right">'.
10023: '<span class="LC_info LC_fontsize_medium">'.
10024: &mt("URL points to web address").'</span>';
1.987 raeburn 10025: $numremref++;
1.660 raeburn 10026: } elsif ($args->{'error_on_invalid_names'}
10027: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 10028: $upload_output.='<td align="right"><span class="LC_warning">'.
10029: &mt('Invalid characters').'</span>';
1.987 raeburn 10030: $numinvalid++;
1.660 raeburn 10031: } else {
1.1123 raeburn 10032: $upload_output .= '<td>'.
10033: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10034: $embed_file,\%mapping,
1.1071 raeburn 10035: $allfiles,$codebase,'upload');
10036: $counter ++;
10037: $numnew ++;
1.987 raeburn 10038: }
10039: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10040: }
10041: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10042: if ($actionurl eq '/adm/dependencies') {
10043: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10044: $modify_output .= &start_data_table_row().
10045: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10046: '<img src="'.&icon($embed_file).'" border="0" />'.
10047: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10048: '<td>'.$size.'</td>'.
10049: '<td>'.$mtime.'</td>'.
10050: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10051: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10052: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10053: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10054: &embedded_file_element('upload_embedded',$counter,
10055: $embed_file,\%mapping,
10056: $allfiles,$codebase,'modify').
10057: '</div></td>'.
10058: &end_data_table_row()."\n";
10059: $counter ++;
10060: } else {
10061: $upload_output .= &start_data_table_row().
1.1123 raeburn 10062: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10063: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10064: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10065: &Apache::loncommon::end_data_table_row()."\n";
10066: }
10067: }
10068: my $delidx = $counter;
10069: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10070: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10071: $delete_output .= &start_data_table_row().
10072: '<td><img src="'.&icon($oldfile).'" />'.
10073: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10074: '<td>'.$size.'</td>'.
10075: '<td>'.$mtime.'</td>'.
10076: '<td><label><input type="checkbox" name="del_upload_dep" '.
10077: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10078: &embedded_file_element('upload_embedded',$delidx,
10079: $oldfile,\%mapping,$allfiles,
10080: $codebase,'delete').'</td>'.
10081: &end_data_table_row()."\n";
10082: $numunused ++;
10083: $delidx ++;
1.987 raeburn 10084: }
10085: if ($upload_output) {
10086: $upload_output = &start_data_table().
10087: $upload_output.
10088: &end_data_table()."\n";
10089: }
1.1071 raeburn 10090: if ($modify_output) {
10091: $modify_output = &start_data_table().
10092: &start_data_table_header_row().
10093: '<th>'.&mt('File').'</th>'.
10094: '<th>'.&mt('Size (KB)').'</th>'.
10095: '<th>'.&mt('Modified').'</th>'.
10096: '<th>'.&mt('Upload replacement?').'</th>'.
10097: &end_data_table_header_row().
10098: $modify_output.
10099: &end_data_table()."\n";
10100: }
10101: if ($delete_output) {
10102: $delete_output = &start_data_table().
10103: &start_data_table_header_row().
10104: '<th>'.&mt('File').'</th>'.
10105: '<th>'.&mt('Size (KB)').'</th>'.
10106: '<th>'.&mt('Modified').'</th>'.
10107: '<th>'.&mt('Delete?').'</th>'.
10108: &end_data_table_header_row().
10109: $delete_output.
10110: &end_data_table()."\n";
10111: }
1.987 raeburn 10112: my $applies = 0;
10113: if ($numremref) {
10114: $applies ++;
10115: }
10116: if ($numinvalid) {
10117: $applies ++;
10118: }
10119: if ($numexisting) {
10120: $applies ++;
10121: }
1.1071 raeburn 10122: if ($counter || $numunused) {
1.987 raeburn 10123: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10124: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10125: $state.'<h3>'.$heading.'</h3>';
10126: if ($actionurl eq '/adm/dependencies') {
10127: if ($numnew) {
10128: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10129: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10130: $upload_output.'<br />'."\n";
10131: }
10132: if ($numexisting) {
10133: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10134: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10135: $modify_output.'<br />'."\n";
10136: $buttontext = &mt('Save changes');
10137: }
10138: if ($numunused) {
10139: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10140: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10141: $delete_output.'<br />'."\n";
10142: $buttontext = &mt('Save changes');
10143: }
10144: } else {
10145: $output .= $upload_output.'<br />'."\n";
10146: }
10147: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10148: $counter.'" />'."\n";
10149: if ($actionurl eq '/adm/dependencies') {
10150: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10151: $numnew.'" />'."\n";
10152: } elsif ($actionurl eq '') {
1.987 raeburn 10153: $output .= '<input type="hidden" name="phase" value="three" />';
10154: }
10155: } elsif ($applies) {
10156: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10157: if ($applies > 1) {
10158: $output .=
1.1123 raeburn 10159: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10160: if ($numremref) {
10161: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10162: }
10163: if ($numinvalid) {
10164: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10165: }
10166: if ($numexisting) {
10167: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10168: }
10169: $output .= '</ul><br />';
10170: } elsif ($numremref) {
10171: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10172: } elsif ($numinvalid) {
10173: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10174: } elsif ($numexisting) {
10175: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10176: }
10177: $output .= $upload_output.'<br />';
10178: }
10179: my ($pathchange_output,$chgcount);
1.1071 raeburn 10180: $chgcount = $counter;
1.987 raeburn 10181: if (keys(%pathchanges) > 0) {
10182: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10183: if ($counter) {
1.987 raeburn 10184: $output .= &embedded_file_element('pathchange',$chgcount,
10185: $embed_file,\%mapping,
1.1071 raeburn 10186: $allfiles,$codebase,'change');
1.987 raeburn 10187: } else {
10188: $pathchange_output .=
10189: &start_data_table_row().
10190: '<td><input type ="checkbox" name="namechange" value="'.
10191: $chgcount.'" checked="checked" /></td>'.
10192: '<td>'.$mapping{$embed_file}.'</td>'.
10193: '<td>'.$embed_file.
10194: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10195: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10196: '</td>'.&end_data_table_row();
1.660 raeburn 10197: }
1.987 raeburn 10198: $numpathchg ++;
10199: $chgcount ++;
1.660 raeburn 10200: }
10201: }
1.1127 raeburn 10202: if (($counter) || ($numunused)) {
1.987 raeburn 10203: if ($numpathchg) {
10204: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10205: $numpathchg.'" />'."\n";
10206: }
10207: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10208: ($actionurl eq '/adm/imsimport')) {
10209: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10210: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10211: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10212: } elsif ($actionurl eq '/adm/dependencies') {
10213: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10214: }
1.1123 raeburn 10215: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10216: } elsif ($numpathchg) {
10217: my %pathchange = ();
10218: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10219: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10220: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 10221: }
1.987 raeburn 10222: }
1.1071 raeburn 10223: return ($output,$counter,$numpathchg);
1.987 raeburn 10224: }
10225:
10226: sub embedded_file_element {
1.1071 raeburn 10227: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10228: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10229: (ref($codebase) eq 'HASH'));
10230: my $output;
1.1071 raeburn 10231: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10232: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10233: }
10234: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10235: &escape($embed_file).'" />';
10236: unless (($context eq 'upload_embedded') &&
10237: ($mapping->{$embed_file} eq $embed_file)) {
10238: $output .='
10239: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10240: }
10241: my $attrib;
10242: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10243: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10244: }
10245: $output .=
10246: "\n\t\t".
10247: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10248: $attrib.'" />';
10249: if (exists($codebase->{$mapping->{$embed_file}})) {
10250: $output .=
10251: "\n\t\t".
10252: '<input name="codebase_'.$num.'" type="hidden" value="'.
10253: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10254: }
1.987 raeburn 10255: return $output;
1.660 raeburn 10256: }
10257:
1.1071 raeburn 10258: sub get_dependency_details {
10259: my ($currfile,$currsubfile,$embed_file) = @_;
10260: my ($size,$mtime,$showsize,$showmtime);
10261: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10262: if ($embed_file =~ m{/}) {
10263: my ($path,$fname) = split(/\//,$embed_file);
10264: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10265: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10266: }
10267: } else {
10268: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10269: ($size,$mtime) = @{$currfile->{$embed_file}};
10270: }
10271: }
10272: $showsize = $size/1024.0;
10273: $showsize = sprintf("%.1f",$showsize);
10274: if ($mtime > 0) {
10275: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10276: }
10277: }
10278: return ($showsize,$showmtime);
10279: }
10280:
10281: sub ask_embedded_js {
10282: return <<"END";
10283: <script type="text/javascript"">
10284: // <![CDATA[
10285: function toggleBrowse(counter) {
10286: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10287: var fileid = document.getElementById('embedded_item_'+counter);
10288: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10289: if (chkboxid.checked == true) {
10290: uploaddivid.style.display='block';
10291: } else {
10292: uploaddivid.style.display='none';
10293: fileid.value = '';
10294: }
10295: }
10296: // ]]>
10297: </script>
10298:
10299: END
10300: }
10301:
1.661 raeburn 10302: sub upload_embedded {
10303: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10304: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10305: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10306: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10307: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10308: my $orig_uploaded_filename =
10309: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10310: foreach my $type ('orig','ref','attrib','codebase') {
10311: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10312: $env{'form.embedded_'.$type.'_'.$i} =
10313: &unescape($env{'form.embedded_'.$type.'_'.$i});
10314: }
10315: }
1.661 raeburn 10316: my ($path,$fname) =
10317: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10318: # no path, whole string is fname
10319: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10320: $fname = &Apache::lonnet::clean_filename($fname);
10321: # See if there is anything left
10322: next if ($fname eq '');
10323:
10324: # Check if file already exists as a file or directory.
10325: my ($state,$msg);
10326: if ($context eq 'portfolio') {
10327: my $port_path = $dirpath;
10328: if ($group ne '') {
10329: $port_path = "groups/$group/$port_path";
10330: }
1.987 raeburn 10331: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10332: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10333: $dir_root,$port_path,$disk_quota,
10334: $current_disk_usage,$uname,$udom);
10335: if ($state eq 'will_exceed_quota'
1.984 raeburn 10336: || $state eq 'file_locked') {
1.661 raeburn 10337: $output .= $msg;
10338: next;
10339: }
10340: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10341: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10342: if ($state eq 'exists') {
10343: $output .= $msg;
10344: next;
10345: }
10346: }
10347: # Check if extension is valid
10348: if (($fname =~ /\.(\w+)$/) &&
10349: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987 raeburn 10350: $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 10351: next;
10352: } elsif (($fname =~ /\.(\w+)$/) &&
10353: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10354: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10355: next;
10356: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 10357: $output .= &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661 raeburn 10358: next;
10359: }
10360: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 10361: my $subdir = $path;
10362: $subdir =~ s{/+$}{};
1.661 raeburn 10363: if ($context eq 'portfolio') {
1.984 raeburn 10364: my $result;
10365: if ($state eq 'existingfile') {
10366: $result=
10367: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 10368: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10369: } else {
1.984 raeburn 10370: $result=
10371: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10372: $dirpath.
1.1123 raeburn 10373: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10374: if ($result !~ m|^/uploaded/|) {
10375: $output .= '<span class="LC_error">'
10376: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10377: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10378: .'</span><br />';
10379: next;
10380: } else {
1.987 raeburn 10381: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10382: $path.$fname.'</span>').'<br />';
1.984 raeburn 10383: }
1.661 raeburn 10384: }
1.1123 raeburn 10385: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 10386: my $extendedsubdir = $dirpath.'/'.$subdir;
10387: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10388: my $result =
1.1126 raeburn 10389: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10390: if ($result !~ m|^/uploaded/|) {
10391: $output .= '<span class="LC_error">'
10392: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10393: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10394: .'</span><br />';
10395: next;
10396: } else {
10397: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10398: $path.$fname.'</span>').'<br />';
1.1125 raeburn 10399: if ($context eq 'syllabus') {
10400: &Apache::lonnet::make_public_indefinitely($result);
10401: }
1.987 raeburn 10402: }
1.661 raeburn 10403: } else {
10404: # Save the file
10405: my $target = $env{'form.embedded_item_'.$i};
10406: my $fullpath = $dir_root.$dirpath.'/'.$path;
10407: my $dest = $fullpath.$fname;
10408: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10409: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10410: my $count;
10411: my $filepath = $dir_root;
1.1027 raeburn 10412: foreach my $subdir (@parts) {
10413: $filepath .= "/$subdir";
10414: if (!-e $filepath) {
1.661 raeburn 10415: mkdir($filepath,0770);
10416: }
10417: }
10418: my $fh;
10419: if (!open($fh,'>'.$dest)) {
10420: &Apache::lonnet::logthis('Failed to create '.$dest);
10421: $output .= '<span class="LC_error">'.
1.1071 raeburn 10422: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10423: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10424: '</span><br />';
10425: } else {
10426: if (!print $fh $env{'form.embedded_item_'.$i}) {
10427: &Apache::lonnet::logthis('Failed to write to '.$dest);
10428: $output .= '<span class="LC_error">'.
1.1071 raeburn 10429: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10430: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10431: '</span><br />';
10432: } else {
1.987 raeburn 10433: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10434: $url.'</span>').'<br />';
10435: unless ($context eq 'testbank') {
10436: $footer .= &mt('View embedded file: [_1]',
10437: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10438: }
10439: }
10440: close($fh);
10441: }
10442: }
10443: if ($env{'form.embedded_ref_'.$i}) {
10444: $pathchange{$i} = 1;
10445: }
10446: }
10447: if ($output) {
10448: $output = '<p>'.$output.'</p>';
10449: }
10450: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10451: $returnflag = 'ok';
1.1071 raeburn 10452: my $numpathchgs = scalar(keys(%pathchange));
10453: if ($numpathchgs > 0) {
1.987 raeburn 10454: if ($context eq 'portfolio') {
10455: $output .= '<p>'.&mt('or').'</p>';
10456: } elsif ($context eq 'testbank') {
1.1071 raeburn 10457: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10458: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10459: $returnflag = 'modify_orightml';
10460: }
10461: }
1.1071 raeburn 10462: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10463: }
10464:
10465: sub modify_html_form {
10466: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10467: my $end = 0;
10468: my $modifyform;
10469: if ($context eq 'upload_embedded') {
10470: return unless (ref($pathchange) eq 'HASH');
10471: if ($env{'form.number_embedded_items'}) {
10472: $end += $env{'form.number_embedded_items'};
10473: }
10474: if ($env{'form.number_pathchange_items'}) {
10475: $end += $env{'form.number_pathchange_items'};
10476: }
10477: if ($end) {
10478: for (my $i=0; $i<$end; $i++) {
10479: if ($i < $env{'form.number_embedded_items'}) {
10480: next unless($pathchange->{$i});
10481: }
10482: $modifyform .=
10483: &start_data_table_row().
10484: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10485: 'checked="checked" /></td>'.
10486: '<td>'.$env{'form.embedded_ref_'.$i}.
10487: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10488: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10489: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10490: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10491: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10492: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10493: '<td>'.$env{'form.embedded_orig_'.$i}.
10494: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10495: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10496: &end_data_table_row();
1.1071 raeburn 10497: }
1.987 raeburn 10498: }
10499: } else {
10500: $modifyform = $pathchgtable;
10501: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10502: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10503: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10504: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10505: }
10506: }
10507: if ($modifyform) {
1.1071 raeburn 10508: if ($actionurl eq '/adm/dependencies') {
10509: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10510: }
1.987 raeburn 10511: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10512: '<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".
10513: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10514: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10515: '</ol></p>'."\n".'<p>'.
10516: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10517: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10518: &start_data_table()."\n".
10519: &start_data_table_header_row().
10520: '<th>'.&mt('Change?').'</th>'.
10521: '<th>'.&mt('Current reference').'</th>'.
10522: '<th>'.&mt('Required reference').'</th>'.
10523: &end_data_table_header_row()."\n".
10524: $modifyform.
10525: &end_data_table().'<br />'."\n".$hiddenstate.
10526: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10527: '</form>'."\n";
10528: }
10529: return;
10530: }
10531:
10532: sub modify_html_refs {
1.1123 raeburn 10533: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10534: my $container;
10535: if ($context eq 'portfolio') {
10536: $container = $env{'form.container'};
10537: } elsif ($context eq 'coursedoc') {
10538: $container = $env{'form.primaryurl'};
1.1071 raeburn 10539: } elsif ($context eq 'manage_dependencies') {
10540: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10541: $container = "/$container";
1.1123 raeburn 10542: } elsif ($context eq 'syllabus') {
10543: $container = $url;
1.987 raeburn 10544: } else {
1.1027 raeburn 10545: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10546: }
10547: my (%allfiles,%codebase,$output,$content);
10548: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 10549: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10550: if (wantarray) {
10551: return ('',0,0);
10552: } else {
10553: return;
10554: }
10555: }
10556: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10557: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10558: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10559: if (wantarray) {
10560: return ('',0,0);
10561: } else {
10562: return;
10563: }
10564: }
1.987 raeburn 10565: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10566: if ($content eq '-1') {
10567: if (wantarray) {
10568: return ('',0,0);
10569: } else {
10570: return;
10571: }
10572: }
1.987 raeburn 10573: } else {
1.1071 raeburn 10574: unless ($container =~ /^\Q$dir_root\E/) {
10575: if (wantarray) {
10576: return ('',0,0);
10577: } else {
10578: return;
10579: }
10580: }
1.987 raeburn 10581: if (open(my $fh,"<$container")) {
10582: $content = join('', <$fh>);
10583: close($fh);
10584: } else {
1.1071 raeburn 10585: if (wantarray) {
10586: return ('',0,0);
10587: } else {
10588: return;
10589: }
1.987 raeburn 10590: }
10591: }
10592: my ($count,$codebasecount) = (0,0);
10593: my $mm = new File::MMagic;
10594: my $mime_type = $mm->checktype_contents($content);
10595: if ($mime_type eq 'text/html') {
10596: my $parse_result =
10597: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10598: \%codebase,\$content);
10599: if ($parse_result eq 'ok') {
10600: foreach my $i (@changes) {
10601: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10602: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10603: if ($allfiles{$ref}) {
10604: my $newname = $orig;
10605: my ($attrib_regexp,$codebase);
1.1006 raeburn 10606: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10607: if ($attrib_regexp =~ /:/) {
10608: $attrib_regexp =~ s/\:/|/g;
10609: }
10610: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10611: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10612: $count += $numchg;
1.1123 raeburn 10613: $allfiles{$newname} = $allfiles{$ref};
1.987 raeburn 10614: }
10615: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10616: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10617: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10618: $codebasecount ++;
10619: }
10620: }
10621: }
1.1123 raeburn 10622: my $skiprewrites;
1.987 raeburn 10623: if ($count || $codebasecount) {
10624: my $saveresult;
1.1071 raeburn 10625: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10626: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10627: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10628: if ($url eq $container) {
10629: my ($fname) = ($container =~ m{/([^/]+)$});
10630: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10631: $count,'<span class="LC_filename">'.
1.1071 raeburn 10632: $fname.'</span>').'</p>';
1.987 raeburn 10633: } else {
10634: $output = '<p class="LC_error">'.
10635: &mt('Error: update failed for: [_1].',
10636: '<span class="LC_filename">'.
10637: $container.'</span>').'</p>';
10638: }
1.1123 raeburn 10639: if ($context eq 'syllabus') {
10640: unless ($saveresult eq 'ok') {
10641: $skiprewrites = 1;
10642: }
10643: }
1.987 raeburn 10644: } else {
10645: if (open(my $fh,">$container")) {
10646: print $fh $content;
10647: close($fh);
10648: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10649: $count,'<span class="LC_filename">'.
10650: $container.'</span>').'</p>';
1.661 raeburn 10651: } else {
1.987 raeburn 10652: $output = '<p class="LC_error">'.
10653: &mt('Error: could not update [_1].',
10654: '<span class="LC_filename">'.
10655: $container.'</span>').'</p>';
1.661 raeburn 10656: }
10657: }
10658: }
1.1123 raeburn 10659: if (($context eq 'syllabus') && (!$skiprewrites)) {
10660: my ($actionurl,$state);
10661: $actionurl = "/public/$udom/$uname/syllabus";
10662: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10663: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10664: \%codebase,
10665: {'context' => 'rewrites',
10666: 'ignore_remote_references' => 1,});
10667: if (ref($mapping) eq 'HASH') {
10668: my $rewrites = 0;
10669: foreach my $key (keys(%{$mapping})) {
10670: next if ($key =~ m{^https?://});
10671: my $ref = $mapping->{$key};
10672: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10673: my $attrib;
10674: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10675: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10676: }
10677: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10678: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10679: $rewrites += $numchg;
10680: }
10681: }
10682: if ($rewrites) {
10683: my $saveresult;
10684: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10685: if ($url eq $container) {
10686: my ($fname) = ($container =~ m{/([^/]+)$});
10687: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10688: $count,'<span class="LC_filename">'.
10689: $fname.'</span>').'</p>';
10690: } else {
10691: $output .= '<p class="LC_error">'.
10692: &mt('Error: could not update links in [_1].',
10693: '<span class="LC_filename">'.
10694: $container.'</span>').'</p>';
10695:
10696: }
10697: }
10698: }
10699: }
1.987 raeburn 10700: } else {
10701: &logthis('Failed to parse '.$container.
10702: ' to modify references: '.$parse_result);
1.661 raeburn 10703: }
10704: }
1.1071 raeburn 10705: if (wantarray) {
10706: return ($output,$count,$codebasecount);
10707: } else {
10708: return $output;
10709: }
1.661 raeburn 10710: }
10711:
10712: sub check_for_existing {
10713: my ($path,$fname,$element) = @_;
10714: my ($state,$msg);
10715: if (-d $path.'/'.$fname) {
10716: $state = 'exists';
10717: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10718: } elsif (-e $path.'/'.$fname) {
10719: $state = 'exists';
10720: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10721: }
10722: if ($state eq 'exists') {
10723: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10724: }
10725: return ($state,$msg);
10726: }
10727:
10728: sub check_for_upload {
10729: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10730: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10731: my $filesize = length($env{'form.'.$element});
10732: if (!$filesize) {
10733: my $msg = '<span class="LC_error">'.
10734: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10735: '<span class="LC_filename">'.$fname.'</span>',
10736: $filesize).'<br />'.
1.1007 raeburn 10737: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10738: '</span>';
10739: return ('zero_bytes',$msg);
10740: }
10741: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10742: my $getpropath = 1;
1.1021 raeburn 10743: my ($dirlistref,$listerror) =
10744: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10745: my $found_file = 0;
10746: my $locked_file = 0;
1.991 raeburn 10747: my @lockers;
10748: my $navmap;
10749: if ($env{'request.course.id'}) {
10750: $navmap = Apache::lonnavmaps::navmap->new();
10751: }
1.1021 raeburn 10752: if (ref($dirlistref) eq 'ARRAY') {
10753: foreach my $line (@{$dirlistref}) {
10754: my ($file_name,$rest)=split(/\&/,$line,2);
10755: if ($file_name eq $fname){
10756: $file_name = $path.$file_name;
10757: if ($group ne '') {
10758: $file_name = $group.$file_name;
10759: }
10760: $found_file = 1;
10761: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10762: foreach my $lock (@lockers) {
10763: if (ref($lock) eq 'ARRAY') {
10764: my ($symb,$crsid) = @{$lock};
10765: if ($crsid eq $env{'request.course.id'}) {
10766: if (ref($navmap)) {
10767: my $res = $navmap->getBySymb($symb);
10768: foreach my $part (@{$res->parts()}) {
10769: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10770: unless (($slot_status == $res->RESERVED) ||
10771: ($slot_status == $res->RESERVED_LOCATION)) {
10772: $locked_file = 1;
10773: }
1.991 raeburn 10774: }
1.1021 raeburn 10775: } else {
10776: $locked_file = 1;
1.991 raeburn 10777: }
10778: } else {
10779: $locked_file = 1;
10780: }
10781: }
1.1021 raeburn 10782: }
10783: } else {
10784: my @info = split(/\&/,$rest);
10785: my $currsize = $info[6]/1000;
10786: if ($currsize < $filesize) {
10787: my $extra = $filesize - $currsize;
10788: if (($current_disk_usage + $extra) > $disk_quota) {
10789: my $msg = '<span class="LC_error">'.
10790: &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.',
10791: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10792: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10793: $disk_quota,$current_disk_usage);
10794: return ('will_exceed_quota',$msg);
10795: }
1.984 raeburn 10796: }
10797: }
1.661 raeburn 10798: }
10799: }
10800: }
10801: if (($current_disk_usage + $filesize) > $disk_quota){
10802: my $msg = '<span class="LC_error">'.
10803: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10804: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10805: return ('will_exceed_quota',$msg);
10806: } elsif ($found_file) {
10807: if ($locked_file) {
10808: my $msg = '<span class="LC_error">';
10809: $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>');
10810: $msg .= '</span><br />';
10811: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10812: return ('file_locked',$msg);
10813: } else {
10814: my $msg = '<span class="LC_error">';
1.984 raeburn 10815: $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 10816: $msg .= '</span>';
1.984 raeburn 10817: return ('existingfile',$msg);
1.661 raeburn 10818: }
10819: }
10820: }
10821:
1.987 raeburn 10822: sub check_for_traversal {
10823: my ($path,$url,$toplevel) = @_;
10824: my @parts=split(/\//,$path);
10825: my $cleanpath;
10826: my $fullpath = $url;
10827: for (my $i=0;$i<@parts;$i++) {
10828: next if ($parts[$i] eq '.');
10829: if ($parts[$i] eq '..') {
10830: $fullpath =~ s{([^/]+/)$}{};
10831: } else {
10832: $fullpath .= $parts[$i].'/';
10833: }
10834: }
10835: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10836: $cleanpath = $1;
10837: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10838: my $curr_toprel = $1;
10839: my @parts = split(/\//,$curr_toprel);
10840: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10841: my @urlparts = split(/\//,$url_toprel);
10842: my $doubledots;
10843: my $startdiff = -1;
10844: for (my $i=0; $i<@urlparts; $i++) {
10845: if ($startdiff == -1) {
10846: unless ($urlparts[$i] eq $parts[$i]) {
10847: $startdiff = $i;
10848: $doubledots .= '../';
10849: }
10850: } else {
10851: $doubledots .= '../';
10852: }
10853: }
10854: if ($startdiff > -1) {
10855: $cleanpath = $doubledots;
10856: for (my $i=$startdiff; $i<@parts; $i++) {
10857: $cleanpath .= $parts[$i].'/';
10858: }
10859: }
10860: }
10861: $cleanpath =~ s{(/)$}{};
10862: return $cleanpath;
10863: }
1.31 albertel 10864:
1.1053 raeburn 10865: sub is_archive_file {
10866: my ($mimetype) = @_;
10867: if (($mimetype eq 'application/octet-stream') ||
10868: ($mimetype eq 'application/x-stuffit') ||
10869: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10870: return 1;
10871: }
10872: return;
10873: }
10874:
10875: sub decompress_form {
1.1065 raeburn 10876: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10877: my %lt = &Apache::lonlocal::texthash (
10878: this => 'This file is an archive file.',
1.1067 raeburn 10879: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10880: itsc => 'Its contents are as follows:',
1.1053 raeburn 10881: youm => 'You may wish to extract its contents.',
10882: extr => 'Extract contents',
1.1067 raeburn 10883: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10884: proa => 'Process automatically?',
1.1053 raeburn 10885: yes => 'Yes',
10886: no => 'No',
1.1067 raeburn 10887: fold => 'Title for folder containing movie',
10888: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10889: );
1.1065 raeburn 10890: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10891: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10892: my $info = &list_archive_contents($fileloc,\@paths);
10893: if (@paths) {
10894: foreach my $path (@paths) {
10895: $path =~ s{^/}{};
1.1067 raeburn 10896: if ($path =~ m{^([^/]+)/$}) {
10897: $topdir = $1;
10898: }
1.1065 raeburn 10899: if ($path =~ m{^([^/]+)/}) {
10900: $toplevel{$1} = $path;
10901: } else {
10902: $toplevel{$path} = $path;
10903: }
10904: }
10905: }
1.1067 raeburn 10906: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
10907: my @camtasia = ("$topdir/","$topdir/index.html",
10908: "$topdir/media/",
10909: "$topdir/media/$topdir.mp4",
10910: "$topdir/media/FirstFrame.png",
10911: "$topdir/media/player.swf",
10912: "$topdir/media/swfobject.js",
10913: "$topdir/media/expressInstall.swf");
10914: my @diffs = &compare_arrays(\@paths,\@camtasia);
10915: if (@diffs == 0) {
10916: $is_camtasia = 1;
10917: }
10918: }
10919: my $output;
10920: if ($is_camtasia) {
10921: $output = <<"ENDCAM";
10922: <script type="text/javascript" language="Javascript">
10923: // <![CDATA[
10924:
10925: function camtasiaToggle() {
10926: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
10927: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
10928: if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
10929:
10930: document.getElementById('camtasia_titles').style.display='block';
10931: } else {
10932: document.getElementById('camtasia_titles').style.display='none';
10933: }
10934: }
10935: }
10936: return;
10937: }
10938:
10939: // ]]>
10940: </script>
10941: <p>$lt{'camt'}</p>
10942: ENDCAM
1.1065 raeburn 10943: } else {
1.1067 raeburn 10944: $output = '<p>'.$lt{'this'};
10945: if ($info eq '') {
10946: $output .= ' '.$lt{'youm'}.'</p>'."\n";
10947: } else {
10948: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
10949: '<div><pre>'.$info.'</pre></div>';
10950: }
1.1065 raeburn 10951: }
1.1067 raeburn 10952: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 10953: my $duplicates;
10954: my $num = 0;
10955: if (ref($dirlist) eq 'ARRAY') {
10956: foreach my $item (@{$dirlist}) {
10957: if (ref($item) eq 'ARRAY') {
10958: if (exists($toplevel{$item->[0]})) {
10959: $duplicates .=
10960: &start_data_table_row().
10961: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
10962: 'value="0" checked="checked" />'.&mt('No').'</label>'.
10963: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
10964: 'value="1" />'.&mt('Yes').'</label>'.
10965: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
10966: '<td>'.$item->[0].'</td>';
10967: if ($item->[2]) {
10968: $duplicates .= '<td>'.&mt('Directory').'</td>';
10969: } else {
10970: $duplicates .= '<td>'.&mt('File').'</td>';
10971: }
10972: $duplicates .= '<td>'.$item->[3].'</td>'.
10973: '<td>'.
10974: &Apache::lonlocal::locallocaltime($item->[4]).
10975: '</td>'.
10976: &end_data_table_row();
10977: $num ++;
10978: }
10979: }
10980: }
10981: }
10982: my $itemcount;
10983: if (@paths > 0) {
10984: $itemcount = scalar(@paths);
10985: } else {
10986: $itemcount = 1;
10987: }
1.1067 raeburn 10988: if ($is_camtasia) {
10989: $output .= $lt{'auto'}.'<br />'.
10990: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
10991: '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
10992: $lt{'yes'}.'</label> <label>'.
10993: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
10994: $lt{'no'}.'</label></span><br />'.
10995: '<div id="camtasia_titles" style="display:block">'.
10996: &Apache::lonhtmlcommon::start_pick_box().
10997: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
10998: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
10999: &Apache::lonhtmlcommon::row_closure().
11000: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11001: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11002: &Apache::lonhtmlcommon::row_closure(1).
11003: &Apache::lonhtmlcommon::end_pick_box().
11004: '</div>';
11005: }
1.1065 raeburn 11006: $output .=
11007: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11008: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11009: "\n";
1.1065 raeburn 11010: if ($duplicates ne '') {
11011: $output .= '<p><span class="LC_warning">'.
11012: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11013: &start_data_table().
11014: &start_data_table_header_row().
11015: '<th>'.&mt('Overwrite?').'</th>'.
11016: '<th>'.&mt('Name').'</th>'.
11017: '<th>'.&mt('Type').'</th>'.
11018: '<th>'.&mt('Size').'</th>'.
11019: '<th>'.&mt('Last modified').'</th>'.
11020: &end_data_table_header_row().
11021: $duplicates.
11022: &end_data_table().
11023: '</p>';
11024: }
1.1067 raeburn 11025: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11026: if (ref($hiddenelements) eq 'HASH') {
11027: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11028: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11029: }
11030: }
11031: $output .= <<"END";
1.1067 raeburn 11032: <br />
1.1053 raeburn 11033: <input type="submit" name="decompress" value="$lt{'extr'}" />
11034: </form>
11035: $noextract
11036: END
11037: return $output;
11038: }
11039:
1.1065 raeburn 11040: sub decompression_utility {
11041: my ($program) = @_;
11042: my @utilities = ('tar','gunzip','bunzip2','unzip');
11043: my $location;
11044: if (grep(/^\Q$program\E$/,@utilities)) {
11045: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11046: '/usr/sbin/') {
11047: if (-x $dir.$program) {
11048: $location = $dir.$program;
11049: last;
11050: }
11051: }
11052: }
11053: return $location;
11054: }
11055:
11056: sub list_archive_contents {
11057: my ($file,$pathsref) = @_;
11058: my (@cmd,$output);
11059: my $needsregexp;
11060: if ($file =~ /\.zip$/) {
11061: @cmd = (&decompression_utility('unzip'),"-l");
11062: $needsregexp = 1;
11063: } elsif (($file =~ m/\.tar\.gz$/) ||
11064: ($file =~ /\.tgz$/)) {
11065: @cmd = (&decompression_utility('tar'),"-ztf");
11066: } elsif ($file =~ /\.tar\.bz2$/) {
11067: @cmd = (&decompression_utility('tar'),"-jtf");
11068: } elsif ($file =~ m|\.tar$|) {
11069: @cmd = (&decompression_utility('tar'),"-tf");
11070: }
11071: if (@cmd) {
11072: undef($!);
11073: undef($@);
11074: if (open(my $fh,"-|", @cmd, $file)) {
11075: while (my $line = <$fh>) {
11076: $output .= $line;
11077: chomp($line);
11078: my $item;
11079: if ($needsregexp) {
11080: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11081: } else {
11082: $item = $line;
11083: }
11084: if ($item ne '') {
11085: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11086: push(@{$pathsref},$item);
11087: }
11088: }
11089: }
11090: close($fh);
11091: }
11092: }
11093: return $output;
11094: }
11095:
1.1053 raeburn 11096: sub decompress_uploaded_file {
11097: my ($file,$dir) = @_;
11098: &Apache::lonnet::appenv({'cgi.file' => $file});
11099: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11100: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11101: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11102: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11103: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11104: my $decompressed = $env{'cgi.decompressed'};
11105: &Apache::lonnet::delenv('cgi.file');
11106: &Apache::lonnet::delenv('cgi.dir');
11107: &Apache::lonnet::delenv('cgi.decompressed');
11108: return ($decompressed,$result);
11109: }
11110:
1.1055 raeburn 11111: sub process_decompression {
11112: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11113: my ($dir,$error,$warning,$output);
11114: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
1.1120 bisitz 11115: $error = &mt('Filename not a supported archive file type.').
11116: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11117: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11118: } else {
11119: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11120: if ($docuhome eq 'no_host') {
11121: $error = &mt('Could not determine home server for course.');
11122: } else {
11123: my @ids=&Apache::lonnet::current_machine_ids();
11124: my $currdir = "$dir_root/$destination";
11125: if (grep(/^\Q$docuhome\E$/,@ids)) {
11126: $dir = &LONCAPA::propath($docudom,$docuname).
11127: "$dir_root/$destination";
11128: } else {
11129: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11130: "$dir_root/$docudom/$docuname/$destination";
11131: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11132: $error = &mt('Archive file not found.');
11133: }
11134: }
1.1065 raeburn 11135: my (@to_overwrite,@to_skip);
11136: if ($env{'form.archive_overwrite_total'} > 0) {
11137: my $total = $env{'form.archive_overwrite_total'};
11138: for (my $i=0; $i<$total; $i++) {
11139: if ($env{'form.archive_overwrite_'.$i} == 1) {
11140: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11141: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11142: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11143: }
11144: }
11145: }
11146: my $numskip = scalar(@to_skip);
11147: if (($numskip > 0) &&
11148: ($numskip == $env{'form.archive_itemcount'})) {
11149: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11150: } elsif ($dir eq '') {
1.1055 raeburn 11151: $error = &mt('Directory containing archive file unavailable.');
11152: } elsif (!$error) {
1.1065 raeburn 11153: my ($decompressed,$display);
11154: if ($numskip > 0) {
11155: my $tempdir = time.'_'.$$.int(rand(10000));
11156: mkdir("$dir/$tempdir",0755);
11157: system("mv $dir/$file $dir/$tempdir/$file");
11158: ($decompressed,$display) =
11159: &decompress_uploaded_file($file,"$dir/$tempdir");
11160: foreach my $item (@to_skip) {
11161: if (($item ne '') && ($item !~ /\.\./)) {
11162: if (-f "$dir/$tempdir/$item") {
11163: unlink("$dir/$tempdir/$item");
11164: } elsif (-d "$dir/$tempdir/$item") {
11165: system("rm -rf $dir/$tempdir/$item");
11166: }
11167: }
11168: }
11169: system("mv $dir/$tempdir/* $dir");
11170: rmdir("$dir/$tempdir");
11171: } else {
11172: ($decompressed,$display) =
11173: &decompress_uploaded_file($file,$dir);
11174: }
1.1055 raeburn 11175: if ($decompressed eq 'ok') {
1.1065 raeburn 11176: $output = '<p class="LC_info">'.
11177: &mt('Files extracted successfully from archive.').
11178: '</p>'."\n";
1.1055 raeburn 11179: my ($warning,$result,@contents);
11180: my ($newdirlistref,$newlisterror) =
11181: &Apache::lonnet::dirlist($currdir,$docudom,
11182: $docuname,1);
11183: my (%is_dir,%changes,@newitems);
11184: my $dirptr = 16384;
1.1065 raeburn 11185: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11186: foreach my $dir_line (@{$newdirlistref}) {
11187: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11188: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11189: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11190: push(@newitems,$item);
11191: if ($dirptr&$testdir) {
11192: $is_dir{$item} = 1;
11193: }
11194: $changes{$item} = 1;
11195: }
11196: }
11197: }
11198: if (keys(%changes) > 0) {
11199: foreach my $item (sort(@newitems)) {
11200: if ($changes{$item}) {
11201: push(@contents,$item);
11202: }
11203: }
11204: }
11205: if (@contents > 0) {
1.1067 raeburn 11206: my $wantform;
11207: unless ($env{'form.autoextract_camtasia'}) {
11208: $wantform = 1;
11209: }
1.1056 raeburn 11210: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11211: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11212: $currdir,\%is_dir,
11213: \%children,\%parent,
1.1056 raeburn 11214: \@contents,\%dirorder,
11215: \%titles,$wantform);
1.1055 raeburn 11216: if ($datatable ne '') {
11217: $output .= &archive_options_form('decompressed',$datatable,
11218: $count,$hiddenelem);
1.1065 raeburn 11219: my $startcount = 6;
1.1055 raeburn 11220: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11221: \%titles,\%children);
1.1055 raeburn 11222: }
1.1067 raeburn 11223: if ($env{'form.autoextract_camtasia'}) {
11224: my %displayed;
11225: my $total = 1;
11226: $env{'form.archive_directory'} = [];
11227: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11228: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11229: $path =~ s{/$}{};
11230: my $item;
11231: if ($path ne '') {
11232: $item = "$path/$titles{$i}";
11233: } else {
11234: $item = $titles{$i};
11235: }
11236: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11237: if ($item eq $contents[0]) {
11238: push(@{$env{'form.archive_directory'}},$i);
11239: $env{'form.archive_'.$i} = 'display';
11240: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11241: $displayed{'folder'} = $i;
11242: } elsif ($item eq "$contents[0]/index.html") {
11243: $env{'form.archive_'.$i} = 'display';
11244: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11245: $displayed{'web'} = $i;
11246: } else {
11247: if ($item eq "$contents[0]/media") {
11248: push(@{$env{'form.archive_directory'}},$i);
11249: }
11250: $env{'form.archive_'.$i} = 'dependency';
11251: }
11252: $total ++;
11253: }
11254: for (my $i=1; $i<$total; $i++) {
11255: next if ($i == $displayed{'web'});
11256: next if ($i == $displayed{'folder'});
11257: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11258: }
11259: $env{'form.phase'} = 'decompress_cleanup';
11260: $env{'form.archivedelete'} = 1;
11261: $env{'form.archive_count'} = $total-1;
11262: $output .=
11263: &process_extracted_files('coursedocs',$docudom,
11264: $docuname,$destination,
11265: $dir_root,$hiddenelem);
11266: }
1.1055 raeburn 11267: } else {
11268: $warning = &mt('No new items extracted from archive file.');
11269: }
11270: } else {
11271: $output = $display;
11272: $error = &mt('An error occurred during extraction from the archive file.');
11273: }
11274: }
11275: }
11276: }
11277: if ($error) {
11278: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11279: $error.'</p>'."\n";
11280: }
11281: if ($warning) {
11282: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11283: }
11284: return $output;
11285: }
11286:
11287: sub get_extracted {
1.1056 raeburn 11288: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11289: $titles,$wantform) = @_;
1.1055 raeburn 11290: my $count = 0;
11291: my $depth = 0;
11292: my $datatable;
1.1056 raeburn 11293: my @hierarchy;
1.1055 raeburn 11294: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11295: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11296: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11297: foreach my $item (@{$contents}) {
11298: $count ++;
1.1056 raeburn 11299: @{$dirorder->{$count}} = @hierarchy;
11300: $titles->{$count} = $item;
1.1055 raeburn 11301: &archive_hierarchy($depth,$count,$parent,$children);
11302: if ($wantform) {
11303: $datatable .= &archive_row($is_dir->{$item},$item,
11304: $currdir,$depth,$count);
11305: }
11306: if ($is_dir->{$item}) {
11307: $depth ++;
1.1056 raeburn 11308: push(@hierarchy,$count);
11309: $parent->{$depth} = $count;
1.1055 raeburn 11310: $datatable .=
11311: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11312: \$depth,\$count,\@hierarchy,$dirorder,
11313: $children,$parent,$titles,$wantform);
1.1055 raeburn 11314: $depth --;
1.1056 raeburn 11315: pop(@hierarchy);
1.1055 raeburn 11316: }
11317: }
11318: return ($count,$datatable);
11319: }
11320:
11321: sub recurse_extracted_archive {
1.1056 raeburn 11322: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11323: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11324: my $result='';
1.1056 raeburn 11325: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11326: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11327: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11328: return $result;
11329: }
11330: my $dirptr = 16384;
11331: my ($newdirlistref,$newlisterror) =
11332: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11333: if (ref($newdirlistref) eq 'ARRAY') {
11334: foreach my $dir_line (@{$newdirlistref}) {
11335: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11336: unless ($item =~ /^\.+$/) {
11337: $$count ++;
1.1056 raeburn 11338: @{$dirorder->{$$count}} = @{$hierarchy};
11339: $titles->{$$count} = $item;
1.1055 raeburn 11340: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11341:
1.1055 raeburn 11342: my $is_dir;
11343: if ($dirptr&$testdir) {
11344: $is_dir = 1;
11345: }
11346: if ($wantform) {
11347: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11348: }
11349: if ($is_dir) {
11350: $$depth ++;
1.1056 raeburn 11351: push(@{$hierarchy},$$count);
11352: $parent->{$$depth} = $$count;
1.1055 raeburn 11353: $result .=
11354: &recurse_extracted_archive("$currdir/$item",$docudom,
11355: $docuname,$depth,$count,
1.1056 raeburn 11356: $hierarchy,$dirorder,$children,
11357: $parent,$titles,$wantform);
1.1055 raeburn 11358: $$depth --;
1.1056 raeburn 11359: pop(@{$hierarchy});
1.1055 raeburn 11360: }
11361: }
11362: }
11363: }
11364: return $result;
11365: }
11366:
11367: sub archive_hierarchy {
11368: my ($depth,$count,$parent,$children) =@_;
11369: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11370: if (exists($parent->{$depth})) {
11371: $children->{$parent->{$depth}} .= $count.':';
11372: }
11373: }
11374: return;
11375: }
11376:
11377: sub archive_row {
11378: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11379: my ($name) = ($item =~ m{([^/]+)$});
11380: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11381: 'display' => 'Add as file',
1.1055 raeburn 11382: 'dependency' => 'Include as dependency',
11383: 'discard' => 'Discard',
11384: );
11385: if ($is_dir) {
1.1059 raeburn 11386: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11387: }
1.1056 raeburn 11388: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11389: my $offset = 0;
1.1055 raeburn 11390: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11391: $offset ++;
1.1065 raeburn 11392: if ($action ne 'display') {
11393: $offset ++;
11394: }
1.1055 raeburn 11395: $output .= '<td><span class="LC_nobreak">'.
11396: '<label><input type="radio" name="archive_'.$count.
11397: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11398: my $text = $choices{$action};
11399: if ($is_dir) {
11400: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11401: if ($action eq 'display') {
1.1059 raeburn 11402: $text = &mt('Add as folder');
1.1055 raeburn 11403: }
1.1056 raeburn 11404: } else {
11405: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11406:
11407: }
11408: $output .= ' /> '.$choices{$action}.'</label></span>';
11409: if ($action eq 'dependency') {
11410: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11411: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11412: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11413: '<option value=""></option>'."\n".
11414: '</select>'."\n".
11415: '</div>';
1.1059 raeburn 11416: } elsif ($action eq 'display') {
11417: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11418: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11419: '</div>';
1.1055 raeburn 11420: }
1.1056 raeburn 11421: $output .= '</td>';
1.1055 raeburn 11422: }
11423: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11424: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11425: for (my $i=0; $i<$depth; $i++) {
11426: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11427: }
11428: if ($is_dir) {
11429: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11430: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11431: } else {
11432: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11433: }
11434: $output .= ' '.$name.'</td>'."\n".
11435: &end_data_table_row();
11436: return $output;
11437: }
11438:
11439: sub archive_options_form {
1.1065 raeburn 11440: my ($form,$display,$count,$hiddenelem) = @_;
11441: my %lt = &Apache::lonlocal::texthash(
11442: perm => 'Permanently remove archive file?',
11443: hows => 'How should each extracted item be incorporated in the course?',
11444: cont => 'Content actions for all',
11445: addf => 'Add as folder/file',
11446: incd => 'Include as dependency for a displayed file',
11447: disc => 'Discard',
11448: no => 'No',
11449: yes => 'Yes',
11450: save => 'Save',
11451: );
11452: my $output = <<"END";
11453: <form name="$form" method="post" action="">
11454: <p><span class="LC_nobreak">$lt{'perm'}
11455: <label>
11456: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11457: </label>
11458:
11459: <label>
11460: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11461: </span>
11462: </p>
11463: <input type="hidden" name="phase" value="decompress_cleanup" />
11464: <br />$lt{'hows'}
11465: <div class="LC_columnSection">
11466: <fieldset>
11467: <legend>$lt{'cont'}</legend>
11468: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11469: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11470: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11471: </fieldset>
11472: </div>
11473: END
11474: return $output.
1.1055 raeburn 11475: &start_data_table()."\n".
1.1065 raeburn 11476: $display."\n".
1.1055 raeburn 11477: &end_data_table()."\n".
11478: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11479: $hiddenelem.
1.1065 raeburn 11480: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11481: '</form>';
11482: }
11483:
11484: sub archive_javascript {
1.1056 raeburn 11485: my ($startcount,$numitems,$titles,$children) = @_;
11486: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11487: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11488: my $scripttag = <<START;
11489: <script type="text/javascript">
11490: // <![CDATA[
11491:
11492: function checkAll(form,prefix) {
11493: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11494: for (var i=0; i < form.elements.length; i++) {
11495: var id = form.elements[i].id;
11496: if ((id != '') && (id != undefined)) {
11497: if (idstr.test(id)) {
11498: if (form.elements[i].type == 'radio') {
11499: form.elements[i].checked = true;
1.1056 raeburn 11500: var nostart = i-$startcount;
1.1059 raeburn 11501: var offset = nostart%7;
11502: var count = (nostart-offset)/7;
1.1056 raeburn 11503: dependencyCheck(form,count,offset);
1.1055 raeburn 11504: }
11505: }
11506: }
11507: }
11508: }
11509:
11510: function propagateCheck(form,count) {
11511: if (count > 0) {
1.1059 raeburn 11512: var startelement = $startcount + ((count-1) * 7);
11513: for (var j=1; j<6; j++) {
11514: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11515: var item = startelement + j;
11516: if (form.elements[item].type == 'radio') {
11517: if (form.elements[item].checked) {
11518: containerCheck(form,count,j);
11519: break;
11520: }
1.1055 raeburn 11521: }
11522: }
11523: }
11524: }
11525: }
11526:
11527: numitems = $numitems
1.1056 raeburn 11528: var titles = new Array(numitems);
11529: var parents = new Array(numitems);
1.1055 raeburn 11530: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11531: parents[i] = new Array;
1.1055 raeburn 11532: }
1.1059 raeburn 11533: var maintitle = '$maintitle';
1.1055 raeburn 11534:
11535: START
11536:
1.1056 raeburn 11537: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11538: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11539: for (my $i=0; $i<@contents; $i ++) {
11540: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11541: }
11542: }
11543:
1.1056 raeburn 11544: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11545: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11546: }
11547:
1.1055 raeburn 11548: $scripttag .= <<END;
11549:
11550: function containerCheck(form,count,offset) {
11551: if (count > 0) {
1.1056 raeburn 11552: dependencyCheck(form,count,offset);
1.1059 raeburn 11553: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11554: form.elements[item].checked = true;
11555: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11556: if (parents[count].length > 0) {
11557: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11558: containerCheck(form,parents[count][j],offset);
11559: }
11560: }
11561: }
11562: }
11563: }
11564:
11565: function dependencyCheck(form,count,offset) {
11566: if (count > 0) {
1.1059 raeburn 11567: var chosen = (offset+$startcount)+7*(count-1);
11568: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11569: var currtype = form.elements[depitem].type;
11570: if (form.elements[chosen].value == 'dependency') {
11571: document.getElementById('arc_depon_'+count).style.display='block';
11572: form.elements[depitem].options.length = 0;
11573: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 11574: for (var i=1; i<=numitems; i++) {
11575: if (i == count) {
11576: continue;
11577: }
1.1059 raeburn 11578: var startelement = $startcount + (i-1) * 7;
11579: for (var j=1; j<6; j++) {
11580: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11581: var item = startelement + j;
11582: if (form.elements[item].type == 'radio') {
11583: if (form.elements[item].checked) {
11584: if (form.elements[item].value == 'display') {
11585: var n = form.elements[depitem].options.length;
11586: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11587: }
11588: }
11589: }
11590: }
11591: }
11592: }
11593: } else {
11594: document.getElementById('arc_depon_'+count).style.display='none';
11595: form.elements[depitem].options.length = 0;
11596: form.elements[depitem].options[0] = new Option('Select','',true,true);
11597: }
1.1059 raeburn 11598: titleCheck(form,count,offset);
1.1056 raeburn 11599: }
11600: }
11601:
11602: function propagateSelect(form,count,offset) {
11603: if (count > 0) {
1.1065 raeburn 11604: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11605: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11606: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11607: if (parents[count].length > 0) {
11608: for (var j=0; j<parents[count].length; j++) {
11609: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11610: }
11611: }
11612: }
11613: }
11614: }
1.1056 raeburn 11615:
11616: function containerSelect(form,count,offset,picked) {
11617: if (count > 0) {
1.1065 raeburn 11618: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11619: if (form.elements[item].type == 'radio') {
11620: if (form.elements[item].value == 'dependency') {
11621: if (form.elements[item+1].type == 'select-one') {
11622: for (var i=0; i<form.elements[item+1].options.length; i++) {
11623: if (form.elements[item+1].options[i].value == picked) {
11624: form.elements[item+1].selectedIndex = i;
11625: break;
11626: }
11627: }
11628: }
11629: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11630: if (parents[count].length > 0) {
11631: for (var j=0; j<parents[count].length; j++) {
11632: containerSelect(form,parents[count][j],offset,picked);
11633: }
11634: }
11635: }
11636: }
11637: }
11638: }
11639: }
11640:
1.1059 raeburn 11641: function titleCheck(form,count,offset) {
11642: if (count > 0) {
11643: var chosen = (offset+$startcount)+7*(count-1);
11644: var depitem = $startcount + ((count-1) * 7) + 2;
11645: var currtype = form.elements[depitem].type;
11646: if (form.elements[chosen].value == 'display') {
11647: document.getElementById('arc_title_'+count).style.display='block';
11648: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11649: document.getElementById('archive_title_'+count).value=maintitle;
11650: }
11651: } else {
11652: document.getElementById('arc_title_'+count).style.display='none';
11653: if (currtype == 'text') {
11654: document.getElementById('archive_title_'+count).value='';
11655: }
11656: }
11657: }
11658: return;
11659: }
11660:
1.1055 raeburn 11661: // ]]>
11662: </script>
11663: END
11664: return $scripttag;
11665: }
11666:
11667: sub process_extracted_files {
1.1067 raeburn 11668: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11669: my $numitems = $env{'form.archive_count'};
11670: return unless ($numitems);
11671: my @ids=&Apache::lonnet::current_machine_ids();
11672: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11673: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11674: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11675: if (grep(/^\Q$docuhome\E$/,@ids)) {
11676: $prefix = &LONCAPA::propath($docudom,$docuname);
11677: $pathtocheck = "$dir_root/$destination";
11678: $dir = $dir_root;
11679: $ishome = 1;
11680: } else {
11681: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11682: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11683: $dir = "$dir_root/$docudom/$docuname";
11684: }
11685: my $currdir = "$dir_root/$destination";
11686: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11687: if ($env{'form.folderpath'}) {
11688: my @items = split('&',$env{'form.folderpath'});
11689: $folders{'0'} = $items[-2];
1.1099 raeburn 11690: if ($env{'form.folderpath'} =~ /\:1$/) {
11691: $containers{'0'}='page';
11692: } else {
11693: $containers{'0'}='sequence';
11694: }
1.1055 raeburn 11695: }
11696: my @archdirs = &get_env_multiple('form.archive_directory');
11697: if ($numitems) {
11698: for (my $i=1; $i<=$numitems; $i++) {
11699: my $path = $env{'form.archive_content_'.$i};
11700: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11701: my $item = $1;
11702: $toplevelitems{$item} = $i;
11703: if (grep(/^\Q$i\E$/,@archdirs)) {
11704: $is_dir{$item} = 1;
11705: }
11706: }
11707: }
11708: }
1.1067 raeburn 11709: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11710: if (keys(%toplevelitems) > 0) {
11711: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11712: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11713: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11714: }
1.1066 raeburn 11715: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11716: if ($numitems) {
11717: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 11718: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11719: my $path = $env{'form.archive_content_'.$i};
11720: if ($path =~ /^\Q$pathtocheck\E/) {
11721: if ($env{'form.archive_'.$i} eq 'discard') {
11722: if ($prefix ne '' && $path ne '') {
11723: if (-e $prefix.$path) {
1.1066 raeburn 11724: if ((@archdirs > 0) &&
11725: (grep(/^\Q$i\E$/,@archdirs))) {
11726: $todeletedir{$prefix.$path} = 1;
11727: } else {
11728: $todelete{$prefix.$path} = 1;
11729: }
1.1055 raeburn 11730: }
11731: }
11732: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11733: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11734: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11735: $docstitle = $env{'form.archive_title_'.$i};
11736: if ($docstitle eq '') {
11737: $docstitle = $title;
11738: }
1.1055 raeburn 11739: $outer = 0;
1.1056 raeburn 11740: if (ref($dirorder{$i}) eq 'ARRAY') {
11741: if (@{$dirorder{$i}} > 0) {
11742: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11743: if ($env{'form.archive_'.$item} eq 'display') {
11744: $outer = $item;
11745: last;
11746: }
11747: }
11748: }
11749: }
11750: my ($errtext,$fatal) =
11751: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11752: '/'.$folders{$outer}.'.'.
11753: $containers{$outer});
11754: next if ($fatal);
11755: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11756: if ($context eq 'coursedocs') {
1.1056 raeburn 11757: $mapinner{$i} = time;
1.1055 raeburn 11758: $folders{$i} = 'default_'.$mapinner{$i};
11759: $containers{$i} = 'sequence';
11760: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11761: $folders{$i}.'.'.$containers{$i};
11762: my $newidx = &LONCAPA::map::getresidx();
11763: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11764: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11765: push(@LONCAPA::map::order,$newidx);
11766: my ($outtext,$errtext) =
11767: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11768: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11769: '.'.$containers{$outer},1,1);
1.1056 raeburn 11770: $newseqid{$i} = $newidx;
1.1067 raeburn 11771: unless ($errtext) {
11772: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11773: }
1.1055 raeburn 11774: }
11775: } else {
11776: if ($context eq 'coursedocs') {
11777: my $newidx=&LONCAPA::map::getresidx();
11778: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11779: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11780: $title;
11781: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11782: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11783: }
11784: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11785: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11786: }
11787: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11788: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11789: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11790: unless ($ishome) {
11791: my $fetch = "$newdest{$i}/$title";
11792: $fetch =~ s/^\Q$prefix$dir\E//;
11793: $prompttofetch{$fetch} = 1;
11794: }
1.1055 raeburn 11795: }
11796: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11797: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11798: push(@LONCAPA::map::order, $newidx);
11799: my ($outtext,$errtext)=
11800: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11801: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11802: '.'.$containers{$outer},1,1);
1.1067 raeburn 11803: unless ($errtext) {
11804: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11805: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11806: }
11807: }
1.1055 raeburn 11808: }
11809: }
1.1086 raeburn 11810: }
11811: } else {
11812: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11813: }
11814: }
11815: for (my $i=1; $i<=$numitems; $i++) {
11816: next unless ($env{'form.archive_'.$i} eq 'dependency');
11817: my $path = $env{'form.archive_content_'.$i};
11818: if ($path =~ /^\Q$pathtocheck\E/) {
11819: my ($title) = ($path =~ m{/([^/]+)$});
11820: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11821: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11822: if (ref($dirorder{$i}) eq 'ARRAY') {
11823: my ($itemidx,$fullpath,$relpath);
11824: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11825: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11826: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 11827: if ($dirorder{$i}->[$j] eq $container) {
11828: $itemidx = $j;
1.1056 raeburn 11829: }
11830: }
1.1086 raeburn 11831: }
11832: if ($itemidx eq '') {
11833: $itemidx = 0;
11834: }
11835: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11836: if ($mapinner{$referrer{$i}}) {
11837: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11838: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11839: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11840: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11841: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11842: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11843: if (!-e $fullpath) {
11844: mkdir($fullpath,0755);
1.1056 raeburn 11845: }
11846: }
1.1086 raeburn 11847: } else {
11848: last;
1.1056 raeburn 11849: }
1.1086 raeburn 11850: }
11851: }
11852: } elsif ($newdest{$referrer{$i}}) {
11853: $fullpath = $newdest{$referrer{$i}};
11854: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11855: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11856: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11857: last;
11858: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11859: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11860: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11861: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11862: if (!-e $fullpath) {
11863: mkdir($fullpath,0755);
1.1056 raeburn 11864: }
11865: }
1.1086 raeburn 11866: } else {
11867: last;
1.1056 raeburn 11868: }
1.1055 raeburn 11869: }
11870: }
1.1086 raeburn 11871: if ($fullpath ne '') {
11872: if (-e "$prefix$path") {
11873: system("mv $prefix$path $fullpath/$title");
11874: }
11875: if (-e "$fullpath/$title") {
11876: my $showpath;
11877: if ($relpath ne '') {
11878: $showpath = "$relpath/$title";
11879: } else {
11880: $showpath = "/$title";
11881: }
11882: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
11883: }
11884: unless ($ishome) {
11885: my $fetch = "$fullpath/$title";
11886: $fetch =~ s/^\Q$prefix$dir\E//;
11887: $prompttofetch{$fetch} = 1;
11888: }
11889: }
1.1055 raeburn 11890: }
1.1086 raeburn 11891: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
11892: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
11893: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 11894: }
11895: } else {
11896: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11897: }
11898: }
11899: if (keys(%todelete)) {
11900: foreach my $key (keys(%todelete)) {
11901: unlink($key);
1.1066 raeburn 11902: }
11903: }
11904: if (keys(%todeletedir)) {
11905: foreach my $key (keys(%todeletedir)) {
11906: rmdir($key);
11907: }
11908: }
11909: foreach my $dir (sort(keys(%is_dir))) {
11910: if (($pathtocheck ne '') && ($dir ne '')) {
11911: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 11912: }
11913: }
1.1067 raeburn 11914: if ($result ne '') {
11915: $output .= '<ul>'."\n".
11916: $result."\n".
11917: '</ul>';
11918: }
11919: unless ($ishome) {
11920: my $replicationfail;
11921: foreach my $item (keys(%prompttofetch)) {
11922: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
11923: unless ($fetchresult eq 'ok') {
11924: $replicationfail .= '<li>'.$item.'</li>'."\n";
11925: }
11926: }
11927: if ($replicationfail) {
11928: $output .= '<p class="LC_error">'.
11929: &mt('Course home server failed to retrieve:').'<ul>'.
11930: $replicationfail.
11931: '</ul></p>';
11932: }
11933: }
1.1055 raeburn 11934: } else {
11935: $warning = &mt('No items found in archive.');
11936: }
11937: if ($error) {
11938: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11939: $error.'</p>'."\n";
11940: }
11941: if ($warning) {
11942: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11943: }
11944: return $output;
11945: }
11946:
1.1066 raeburn 11947: sub cleanup_empty_dirs {
11948: my ($path) = @_;
11949: if (($path ne '') && (-d $path)) {
11950: if (opendir(my $dirh,$path)) {
11951: my @dircontents = grep(!/^\./,readdir($dirh));
11952: my $numitems = 0;
11953: foreach my $item (@dircontents) {
11954: if (-d "$path/$item") {
1.1111 raeburn 11955: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 11956: if (-e "$path/$item") {
11957: $numitems ++;
11958: }
11959: } else {
11960: $numitems ++;
11961: }
11962: }
11963: if ($numitems == 0) {
11964: rmdir($path);
11965: }
11966: closedir($dirh);
11967: }
11968: }
11969: return;
11970: }
11971:
1.41 ng 11972: =pod
1.45 matthew 11973:
1.1068 raeburn 11974: =item &get_folder_hierarchy()
11975:
11976: Provides hierarchy of names of folders/sub-folders containing the current
11977: item,
11978:
11979: Inputs: 3
11980: - $navmap - navmaps object
11981:
11982: - $map - url for map (either the trigger itself, or map containing
11983: the resource, which is the trigger).
11984:
11985: - $showitem - 1 => show title for map itself; 0 => do not show.
11986:
11987: Outputs: 1 @pathitems - array of folder/subfolder names.
11988:
11989: =cut
11990:
11991: sub get_folder_hierarchy {
11992: my ($navmap,$map,$showitem) = @_;
11993: my @pathitems;
11994: if (ref($navmap)) {
11995: my $mapres = $navmap->getResourceByUrl($map);
11996: if (ref($mapres)) {
11997: my $pcslist = $mapres->map_hierarchy();
11998: if ($pcslist ne '') {
11999: my @pcs = split(/,/,$pcslist);
12000: foreach my $pc (@pcs) {
12001: if ($pc == 1) {
1.1129 raeburn 12002: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12003: } else {
12004: my $res = $navmap->getByMapPc($pc);
12005: if (ref($res)) {
12006: my $title = $res->compTitle();
12007: $title =~ s/\W+/_/g;
12008: if ($title ne '') {
12009: push(@pathitems,$title);
12010: }
12011: }
12012: }
12013: }
12014: }
1.1071 raeburn 12015: if ($showitem) {
12016: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 12017: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12018: } else {
12019: my $maptitle = $mapres->compTitle();
12020: $maptitle =~ s/\W+/_/g;
12021: if ($maptitle ne '') {
12022: push(@pathitems,$maptitle);
12023: }
1.1068 raeburn 12024: }
12025: }
12026: }
12027: }
12028: return @pathitems;
12029: }
12030:
12031: =pod
12032:
1.1015 raeburn 12033: =item * &get_turnedin_filepath()
12034:
12035: Determines path in a user's portfolio file for storage of files uploaded
12036: to a specific essayresponse or dropbox item.
12037:
12038: Inputs: 3 required + 1 optional.
12039: $symb is symb for resource, $uname and $udom are for current user (required).
12040: $caller is optional (can be "submission", if routine is called when storing
12041: an upoaded file when "Submit Answer" button was pressed).
12042:
12043: Returns array containing $path and $multiresp.
12044: $path is path in portfolio. $multiresp is 1 if this resource contains more
12045: than one file upload item. Callers of routine should append partid as a
12046: subdirectory to $path in cases where $multiresp is 1.
12047:
12048: Called by: homework/essayresponse.pm and homework/structuretags.pm
12049:
12050: =cut
12051:
12052: sub get_turnedin_filepath {
12053: my ($symb,$uname,$udom,$caller) = @_;
12054: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12055: my $turnindir;
12056: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12057: $turnindir = $userhash{'turnindir'};
12058: my ($path,$multiresp);
12059: if ($turnindir eq '') {
12060: if ($caller eq 'submission') {
12061: $turnindir = &mt('turned in');
12062: $turnindir =~ s/\W+/_/g;
12063: my %newhash = (
12064: 'turnindir' => $turnindir,
12065: );
12066: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12067: }
12068: }
12069: if ($turnindir ne '') {
12070: $path = '/'.$turnindir.'/';
12071: my ($multipart,$turnin,@pathitems);
12072: my $navmap = Apache::lonnavmaps::navmap->new();
12073: if (defined($navmap)) {
12074: my $mapres = $navmap->getResourceByUrl($map);
12075: if (ref($mapres)) {
12076: my $pcslist = $mapres->map_hierarchy();
12077: if ($pcslist ne '') {
12078: foreach my $pc (split(/,/,$pcslist)) {
12079: my $res = $navmap->getByMapPc($pc);
12080: if (ref($res)) {
12081: my $title = $res->compTitle();
12082: $title =~ s/\W+/_/g;
12083: if ($title ne '') {
12084: push(@pathitems,$title);
12085: }
12086: }
12087: }
12088: }
12089: my $maptitle = $mapres->compTitle();
12090: $maptitle =~ s/\W+/_/g;
12091: if ($maptitle ne '') {
12092: push(@pathitems,$maptitle);
12093: }
12094: unless ($env{'request.state'} eq 'construct') {
12095: my $res = $navmap->getBySymb($symb);
12096: if (ref($res)) {
12097: my $partlist = $res->parts();
12098: my $totaluploads = 0;
12099: if (ref($partlist) eq 'ARRAY') {
12100: foreach my $part (@{$partlist}) {
12101: my @types = $res->responseType($part);
12102: my @ids = $res->responseIds($part);
12103: for (my $i=0; $i < scalar(@ids); $i++) {
12104: if ($types[$i] eq 'essay') {
12105: my $partid = $part.'_'.$ids[$i];
12106: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12107: $totaluploads ++;
12108: }
12109: }
12110: }
12111: }
12112: if ($totaluploads > 1) {
12113: $multiresp = 1;
12114: }
12115: }
12116: }
12117: }
12118: } else {
12119: return;
12120: }
12121: } else {
12122: return;
12123: }
12124: my $restitle=&Apache::lonnet::gettitle($symb);
12125: $restitle =~ s/\W+/_/g;
12126: if ($restitle eq '') {
12127: $restitle = ($resurl =~ m{/[^/]+$});
12128: if ($restitle eq '') {
12129: $restitle = time;
12130: }
12131: }
12132: push(@pathitems,$restitle);
12133: $path .= join('/',@pathitems);
12134: }
12135: return ($path,$multiresp);
12136: }
12137:
12138: =pod
12139:
1.464 albertel 12140: =back
1.41 ng 12141:
1.112 bowersj2 12142: =head1 CSV Upload/Handling functions
1.38 albertel 12143:
1.41 ng 12144: =over 4
12145:
1.648 raeburn 12146: =item * &upfile_store($r)
1.41 ng 12147:
12148: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12149: needs $env{'form.upfile'}
1.41 ng 12150: returns $datatoken to be put into hidden field
12151:
12152: =cut
1.31 albertel 12153:
12154: sub upfile_store {
12155: my $r=shift;
1.258 albertel 12156: $env{'form.upfile'}=~s/\r/\n/gs;
12157: $env{'form.upfile'}=~s/\f/\n/gs;
12158: $env{'form.upfile'}=~s/\n+/\n/gs;
12159: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12160:
1.258 albertel 12161: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12162: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12163: {
1.158 raeburn 12164: my $datafile = $r->dir_config('lonDaemons').
12165: '/tmp/'.$datatoken.'.tmp';
12166: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12167: print $fh $env{'form.upfile'};
1.158 raeburn 12168: close($fh);
12169: }
1.31 albertel 12170: }
12171: return $datatoken;
12172: }
12173:
1.56 matthew 12174: =pod
12175:
1.648 raeburn 12176: =item * &load_tmp_file($r)
1.41 ng 12177:
12178: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12179: needs $env{'form.datatoken'},
12180: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12181:
12182: =cut
1.31 albertel 12183:
12184: sub load_tmp_file {
12185: my $r=shift;
12186: my @studentdata=();
12187: {
1.158 raeburn 12188: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12189: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12190: if ( open(my $fh,"<$studentfile") ) {
12191: @studentdata=<$fh>;
12192: close($fh);
12193: }
1.31 albertel 12194: }
1.258 albertel 12195: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12196: }
12197:
1.56 matthew 12198: =pod
12199:
1.648 raeburn 12200: =item * &upfile_record_sep()
1.41 ng 12201:
12202: Separate uploaded file into records
12203: returns array of records,
1.258 albertel 12204: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12205:
12206: =cut
1.31 albertel 12207:
12208: sub upfile_record_sep {
1.258 albertel 12209: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12210: } else {
1.248 albertel 12211: my @records;
1.258 albertel 12212: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12213: if ($line=~/^\s*$/) { next; }
12214: push(@records,$line);
12215: }
12216: return @records;
1.31 albertel 12217: }
12218: }
12219:
1.56 matthew 12220: =pod
12221:
1.648 raeburn 12222: =item * &record_sep($record)
1.41 ng 12223:
1.258 albertel 12224: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12225:
12226: =cut
12227:
1.263 www 12228: sub takeleft {
12229: my $index=shift;
12230: return substr('0000'.$index,-4,4);
12231: }
12232:
1.31 albertel 12233: sub record_sep {
12234: my $record=shift;
12235: my %components=();
1.258 albertel 12236: if ($env{'form.upfiletype'} eq 'xml') {
12237: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12238: my $i=0;
1.356 albertel 12239: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12240: $field=~s/^(\"|\')//;
12241: $field=~s/(\"|\')$//;
1.263 www 12242: $components{&takeleft($i)}=$field;
1.31 albertel 12243: $i++;
12244: }
1.258 albertel 12245: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12246: my $i=0;
1.356 albertel 12247: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12248: $field=~s/^(\"|\')//;
12249: $field=~s/(\"|\')$//;
1.263 www 12250: $components{&takeleft($i)}=$field;
1.31 albertel 12251: $i++;
12252: }
12253: } else {
1.561 www 12254: my $separator=',';
1.480 banghart 12255: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12256: $separator=';';
1.480 banghart 12257: }
1.31 albertel 12258: my $i=0;
1.561 www 12259: # the character we are looking for to indicate the end of a quote or a record
12260: my $looking_for=$separator;
12261: # do not add the characters to the fields
12262: my $ignore=0;
12263: # we just encountered a separator (or the beginning of the record)
12264: my $just_found_separator=1;
12265: # store the field we are working on here
12266: my $field='';
12267: # work our way through all characters in record
12268: foreach my $character ($record=~/(.)/g) {
12269: if ($character eq $looking_for) {
12270: if ($character ne $separator) {
12271: # Found the end of a quote, again looking for separator
12272: $looking_for=$separator;
12273: $ignore=1;
12274: } else {
12275: # Found a separator, store away what we got
12276: $components{&takeleft($i)}=$field;
12277: $i++;
12278: $just_found_separator=1;
12279: $ignore=0;
12280: $field='';
12281: }
12282: next;
12283: }
12284: # single or double quotation marks after a separator indicate beginning of a quote
12285: # we are now looking for the end of the quote and need to ignore separators
12286: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12287: $looking_for=$character;
12288: next;
12289: }
12290: # ignore would be true after we reached the end of a quote
12291: if ($ignore) { next; }
12292: if (($just_found_separator) && ($character=~/\s/)) { next; }
12293: $field.=$character;
12294: $just_found_separator=0;
1.31 albertel 12295: }
1.561 www 12296: # catch the very last entry, since we never encountered the separator
12297: $components{&takeleft($i)}=$field;
1.31 albertel 12298: }
12299: return %components;
12300: }
12301:
1.144 matthew 12302: ######################################################
12303: ######################################################
12304:
1.56 matthew 12305: =pod
12306:
1.648 raeburn 12307: =item * &upfile_select_html()
1.41 ng 12308:
1.144 matthew 12309: Return HTML code to select a file from the users machine and specify
12310: the file type.
1.41 ng 12311:
12312: =cut
12313:
1.144 matthew 12314: ######################################################
12315: ######################################################
1.31 albertel 12316: sub upfile_select_html {
1.144 matthew 12317: my %Types = (
12318: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12319: semisv => &mt('Semicolon separated values'),
1.144 matthew 12320: space => &mt('Space separated'),
12321: tab => &mt('Tabulator separated'),
12322: # xml => &mt('HTML/XML'),
12323: );
12324: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12325: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12326: foreach my $type (sort(keys(%Types))) {
12327: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12328: }
12329: $Str .= "</select>\n";
12330: return $Str;
1.31 albertel 12331: }
12332:
1.301 albertel 12333: sub get_samples {
12334: my ($records,$toget) = @_;
12335: my @samples=({});
12336: my $got=0;
12337: foreach my $rec (@$records) {
12338: my %temp = &record_sep($rec);
12339: if (! grep(/\S/, values(%temp))) { next; }
12340: if (%temp) {
12341: $samples[$got]=\%temp;
12342: $got++;
12343: if ($got == $toget) { last; }
12344: }
12345: }
12346: return \@samples;
12347: }
12348:
1.144 matthew 12349: ######################################################
12350: ######################################################
12351:
1.56 matthew 12352: =pod
12353:
1.648 raeburn 12354: =item * &csv_print_samples($r,$records)
1.41 ng 12355:
12356: Prints a table of sample values from each column uploaded $r is an
12357: Apache Request ref, $records is an arrayref from
12358: &Apache::loncommon::upfile_record_sep
12359:
12360: =cut
12361:
1.144 matthew 12362: ######################################################
12363: ######################################################
1.31 albertel 12364: sub csv_print_samples {
12365: my ($r,$records) = @_;
1.662 bisitz 12366: my $samples = &get_samples($records,5);
1.301 albertel 12367:
1.594 raeburn 12368: $r->print(&mt('Samples').'<br />'.&start_data_table().
12369: &start_data_table_header_row());
1.356 albertel 12370: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12371: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12372: $r->print(&end_data_table_header_row());
1.301 albertel 12373: foreach my $hash (@$samples) {
1.594 raeburn 12374: $r->print(&start_data_table_row());
1.356 albertel 12375: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12376: $r->print('<td>');
1.356 albertel 12377: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12378: $r->print('</td>');
12379: }
1.594 raeburn 12380: $r->print(&end_data_table_row());
1.31 albertel 12381: }
1.594 raeburn 12382: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12383: }
12384:
1.144 matthew 12385: ######################################################
12386: ######################################################
12387:
1.56 matthew 12388: =pod
12389:
1.648 raeburn 12390: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12391:
12392: Prints a table to create associations between values and table columns.
1.144 matthew 12393:
1.41 ng 12394: $r is an Apache Request ref,
12395: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12396: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12397:
12398: =cut
12399:
1.144 matthew 12400: ######################################################
12401: ######################################################
1.31 albertel 12402: sub csv_print_select_table {
12403: my ($r,$records,$d) = @_;
1.301 albertel 12404: my $i=0;
12405: my $samples = &get_samples($records,1);
1.144 matthew 12406: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12407: &start_data_table().&start_data_table_header_row().
1.144 matthew 12408: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12409: '<th>'.&mt('Column').'</th>'.
12410: &end_data_table_header_row()."\n");
1.356 albertel 12411: foreach my $array_ref (@$d) {
12412: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12413: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12414:
1.875 bisitz 12415: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12416: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12417: $r->print('<option value="none"></option>');
1.356 albertel 12418: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12419: $r->print('<option value="'.$sample.'"'.
12420: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12421: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12422: }
1.594 raeburn 12423: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12424: $i++;
12425: }
1.594 raeburn 12426: $r->print(&end_data_table());
1.31 albertel 12427: $i--;
12428: return $i;
12429: }
1.56 matthew 12430:
1.144 matthew 12431: ######################################################
12432: ######################################################
12433:
1.56 matthew 12434: =pod
1.31 albertel 12435:
1.648 raeburn 12436: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12437:
12438: Prints a table of sample values from the upload and can make associate samples to internal names.
12439:
12440: $r is an Apache Request ref,
12441: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12442: $d is an array of 2 element arrays (internal name, displayed name)
12443:
12444: =cut
12445:
1.144 matthew 12446: ######################################################
12447: ######################################################
1.31 albertel 12448: sub csv_samples_select_table {
12449: my ($r,$records,$d) = @_;
12450: my $i=0;
1.144 matthew 12451: #
1.662 bisitz 12452: my $max_samples = 5;
12453: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12454: $r->print(&start_data_table().
12455: &start_data_table_header_row().'<th>'.
12456: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12457: &end_data_table_header_row());
1.301 albertel 12458:
12459: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12460: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12461: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12462: foreach my $option (@$d) {
12463: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12464: $r->print('<option value="'.$value.'"'.
1.253 albertel 12465: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12466: $display.'</option>');
1.31 albertel 12467: }
12468: $r->print('</select></td><td>');
1.662 bisitz 12469: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12470: if (defined($samples->[$line]{$key})) {
12471: $r->print($samples->[$line]{$key}."<br />\n");
12472: }
12473: }
1.594 raeburn 12474: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12475: $i++;
12476: }
1.594 raeburn 12477: $r->print(&end_data_table());
1.31 albertel 12478: $i--;
12479: return($i);
1.115 matthew 12480: }
12481:
1.144 matthew 12482: ######################################################
12483: ######################################################
12484:
1.115 matthew 12485: =pod
12486:
1.648 raeburn 12487: =item * &clean_excel_name($name)
1.115 matthew 12488:
12489: Returns a replacement for $name which does not contain any illegal characters.
12490:
12491: =cut
12492:
1.144 matthew 12493: ######################################################
12494: ######################################################
1.115 matthew 12495: sub clean_excel_name {
12496: my ($name) = @_;
12497: $name =~ s/[:\*\?\/\\]//g;
12498: if (length($name) > 31) {
12499: $name = substr($name,0,31);
12500: }
12501: return $name;
1.25 albertel 12502: }
1.84 albertel 12503:
1.85 albertel 12504: =pod
12505:
1.648 raeburn 12506: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12507:
12508: Returns either 1 or undef
12509:
12510: 1 if the part is to be hidden, undef if it is to be shown
12511:
12512: Arguments are:
12513:
12514: $id the id of the part to be checked
12515: $symb, optional the symb of the resource to check
12516: $udom, optional the domain of the user to check for
12517: $uname, optional the username of the user to check for
12518:
12519: =cut
1.84 albertel 12520:
12521: sub check_if_partid_hidden {
12522: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12523: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12524: $symb,$udom,$uname);
1.141 albertel 12525: my $truth=1;
12526: #if the string starts with !, then the list is the list to show not hide
12527: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12528: my @hiddenlist=split(/,/,$hiddenparts);
12529: foreach my $checkid (@hiddenlist) {
1.141 albertel 12530: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12531: }
1.141 albertel 12532: return !$truth;
1.84 albertel 12533: }
1.127 matthew 12534:
1.138 matthew 12535:
12536: ############################################################
12537: ############################################################
12538:
12539: =pod
12540:
1.157 matthew 12541: =back
12542:
1.138 matthew 12543: =head1 cgi-bin script and graphing routines
12544:
1.157 matthew 12545: =over 4
12546:
1.648 raeburn 12547: =item * &get_cgi_id()
1.138 matthew 12548:
12549: Inputs: none
12550:
12551: Returns an id which can be used to pass environment variables
12552: to various cgi-bin scripts. These environment variables will
12553: be removed from the users environment after a given time by
12554: the routine &Apache::lonnet::transfer_profile_to_env.
12555:
12556: =cut
12557:
12558: ############################################################
12559: ############################################################
1.152 albertel 12560: my $uniq=0;
1.136 matthew 12561: sub get_cgi_id {
1.154 albertel 12562: $uniq=($uniq+1)%100000;
1.280 albertel 12563: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12564: }
12565:
1.127 matthew 12566: ############################################################
12567: ############################################################
12568:
12569: =pod
12570:
1.648 raeburn 12571: =item * &DrawBarGraph()
1.127 matthew 12572:
1.138 matthew 12573: Facilitates the plotting of data in a (stacked) bar graph.
12574: Puts plot definition data into the users environment in order for
12575: graph.png to plot it. Returns an <img> tag for the plot.
12576: The bars on the plot are labeled '1','2',...,'n'.
12577:
12578: Inputs:
12579:
12580: =over 4
12581:
12582: =item $Title: string, the title of the plot
12583:
12584: =item $xlabel: string, text describing the X-axis of the plot
12585:
12586: =item $ylabel: string, text describing the Y-axis of the plot
12587:
12588: =item $Max: scalar, the maximum Y value to use in the plot
12589: If $Max is < any data point, the graph will not be rendered.
12590:
1.140 matthew 12591: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12592: they are plotted. If undefined, default values will be used.
12593:
1.178 matthew 12594: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12595:
1.138 matthew 12596: =item @Values: An array of array references. Each array reference holds data
12597: to be plotted in a stacked bar chart.
12598:
1.239 matthew 12599: =item If the final element of @Values is a hash reference the key/value
12600: pairs will be added to the graph definition.
12601:
1.138 matthew 12602: =back
12603:
12604: Returns:
12605:
12606: An <img> tag which references graph.png and the appropriate identifying
12607: information for the plot.
12608:
1.127 matthew 12609: =cut
12610:
12611: ############################################################
12612: ############################################################
1.134 matthew 12613: sub DrawBarGraph {
1.178 matthew 12614: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12615: #
12616: if (! defined($colors)) {
12617: $colors = ['#33ff00',
12618: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12619: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12620: ];
12621: }
1.228 matthew 12622: my $extra_settings = {};
12623: if (ref($Values[-1]) eq 'HASH') {
12624: $extra_settings = pop(@Values);
12625: }
1.127 matthew 12626: #
1.136 matthew 12627: my $identifier = &get_cgi_id();
12628: my $id = 'cgi.'.$identifier;
1.129 matthew 12629: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12630: return '';
12631: }
1.225 matthew 12632: #
12633: my @Labels;
12634: if (defined($labels)) {
12635: @Labels = @$labels;
12636: } else {
12637: for (my $i=0;$i<@{$Values[0]};$i++) {
12638: push (@Labels,$i+1);
12639: }
12640: }
12641: #
1.129 matthew 12642: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12643: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12644: my %ValuesHash;
12645: my $NumSets=1;
12646: foreach my $array (@Values) {
12647: next if (! ref($array));
1.136 matthew 12648: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12649: join(',',@$array);
1.129 matthew 12650: }
1.127 matthew 12651: #
1.136 matthew 12652: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12653: if ($NumBars < 3) {
12654: $width = 120+$NumBars*32;
1.220 matthew 12655: $xskip = 1;
1.225 matthew 12656: $bar_width = 30;
12657: } elsif ($NumBars < 5) {
12658: $width = 120+$NumBars*20;
12659: $xskip = 1;
12660: $bar_width = 20;
1.220 matthew 12661: } elsif ($NumBars < 10) {
1.136 matthew 12662: $width = 120+$NumBars*15;
12663: $xskip = 1;
12664: $bar_width = 15;
12665: } elsif ($NumBars <= 25) {
12666: $width = 120+$NumBars*11;
12667: $xskip = 5;
12668: $bar_width = 8;
12669: } elsif ($NumBars <= 50) {
12670: $width = 120+$NumBars*8;
12671: $xskip = 5;
12672: $bar_width = 4;
12673: } else {
12674: $width = 120+$NumBars*8;
12675: $xskip = 5;
12676: $bar_width = 4;
12677: }
12678: #
1.137 matthew 12679: $Max = 1 if ($Max < 1);
12680: if ( int($Max) < $Max ) {
12681: $Max++;
12682: $Max = int($Max);
12683: }
1.127 matthew 12684: $Title = '' if (! defined($Title));
12685: $xlabel = '' if (! defined($xlabel));
12686: $ylabel = '' if (! defined($ylabel));
1.369 www 12687: $ValuesHash{$id.'.title'} = &escape($Title);
12688: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12689: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12690: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12691: $ValuesHash{$id.'.NumBars'} = $NumBars;
12692: $ValuesHash{$id.'.NumSets'} = $NumSets;
12693: $ValuesHash{$id.'.PlotType'} = 'bar';
12694: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12695: $ValuesHash{$id.'.height'} = $height;
12696: $ValuesHash{$id.'.width'} = $width;
12697: $ValuesHash{$id.'.xskip'} = $xskip;
12698: $ValuesHash{$id.'.bar_width'} = $bar_width;
12699: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12700: #
1.228 matthew 12701: # Deal with other parameters
12702: while (my ($key,$value) = each(%$extra_settings)) {
12703: $ValuesHash{$id.'.'.$key} = $value;
12704: }
12705: #
1.646 raeburn 12706: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12707: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12708: }
12709:
12710: ############################################################
12711: ############################################################
12712:
12713: =pod
12714:
1.648 raeburn 12715: =item * &DrawXYGraph()
1.137 matthew 12716:
1.138 matthew 12717: Facilitates the plotting of data in an XY graph.
12718: Puts plot definition data into the users environment in order for
12719: graph.png to plot it. Returns an <img> tag for the plot.
12720:
12721: Inputs:
12722:
12723: =over 4
12724:
12725: =item $Title: string, the title of the plot
12726:
12727: =item $xlabel: string, text describing the X-axis of the plot
12728:
12729: =item $ylabel: string, text describing the Y-axis of the plot
12730:
12731: =item $Max: scalar, the maximum Y value to use in the plot
12732: If $Max is < any data point, the graph will not be rendered.
12733:
12734: =item $colors: Array ref containing the hex color codes for the data to be
12735: plotted in. If undefined, default values will be used.
12736:
12737: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12738:
12739: =item $Ydata: Array ref containing Array refs.
1.185 www 12740: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12741:
12742: =item %Values: hash indicating or overriding any default values which are
12743: passed to graph.png.
12744: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12745:
12746: =back
12747:
12748: Returns:
12749:
12750: An <img> tag which references graph.png and the appropriate identifying
12751: information for the plot.
12752:
1.137 matthew 12753: =cut
12754:
12755: ############################################################
12756: ############################################################
12757: sub DrawXYGraph {
12758: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12759: #
12760: # Create the identifier for the graph
12761: my $identifier = &get_cgi_id();
12762: my $id = 'cgi.'.$identifier;
12763: #
12764: $Title = '' if (! defined($Title));
12765: $xlabel = '' if (! defined($xlabel));
12766: $ylabel = '' if (! defined($ylabel));
12767: my %ValuesHash =
12768: (
1.369 www 12769: $id.'.title' => &escape($Title),
12770: $id.'.xlabel' => &escape($xlabel),
12771: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12772: $id.'.y_max_value'=> $Max,
12773: $id.'.labels' => join(',',@$Xlabels),
12774: $id.'.PlotType' => 'XY',
12775: );
12776: #
12777: if (defined($colors) && ref($colors) eq 'ARRAY') {
12778: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12779: }
12780: #
12781: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12782: return '';
12783: }
12784: my $NumSets=1;
1.138 matthew 12785: foreach my $array (@{$Ydata}){
1.137 matthew 12786: next if (! ref($array));
12787: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12788: }
1.138 matthew 12789: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12790: #
12791: # Deal with other parameters
12792: while (my ($key,$value) = each(%Values)) {
12793: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12794: }
12795: #
1.646 raeburn 12796: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12797: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12798: }
12799:
12800: ############################################################
12801: ############################################################
12802:
12803: =pod
12804:
1.648 raeburn 12805: =item * &DrawXYYGraph()
1.138 matthew 12806:
12807: Facilitates the plotting of data in an XY graph with two Y axes.
12808: Puts plot definition data into the users environment in order for
12809: graph.png to plot it. Returns an <img> tag for the plot.
12810:
12811: Inputs:
12812:
12813: =over 4
12814:
12815: =item $Title: string, the title of the plot
12816:
12817: =item $xlabel: string, text describing the X-axis of the plot
12818:
12819: =item $ylabel: string, text describing the Y-axis of the plot
12820:
12821: =item $colors: Array ref containing the hex color codes for the data to be
12822: plotted in. If undefined, default values will be used.
12823:
12824: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12825:
12826: =item $Ydata1: The first data set
12827:
12828: =item $Min1: The minimum value of the left Y-axis
12829:
12830: =item $Max1: The maximum value of the left Y-axis
12831:
12832: =item $Ydata2: The second data set
12833:
12834: =item $Min2: The minimum value of the right Y-axis
12835:
12836: =item $Max2: The maximum value of the left Y-axis
12837:
12838: =item %Values: hash indicating or overriding any default values which are
12839: passed to graph.png.
12840: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12841:
12842: =back
12843:
12844: Returns:
12845:
12846: An <img> tag which references graph.png and the appropriate identifying
12847: information for the plot.
1.136 matthew 12848:
12849: =cut
12850:
12851: ############################################################
12852: ############################################################
1.137 matthew 12853: sub DrawXYYGraph {
12854: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12855: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12856: #
12857: # Create the identifier for the graph
12858: my $identifier = &get_cgi_id();
12859: my $id = 'cgi.'.$identifier;
12860: #
12861: $Title = '' if (! defined($Title));
12862: $xlabel = '' if (! defined($xlabel));
12863: $ylabel = '' if (! defined($ylabel));
12864: my %ValuesHash =
12865: (
1.369 www 12866: $id.'.title' => &escape($Title),
12867: $id.'.xlabel' => &escape($xlabel),
12868: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 12869: $id.'.labels' => join(',',@$Xlabels),
12870: $id.'.PlotType' => 'XY',
12871: $id.'.NumSets' => 2,
1.137 matthew 12872: $id.'.two_axes' => 1,
12873: $id.'.y1_max_value' => $Max1,
12874: $id.'.y1_min_value' => $Min1,
12875: $id.'.y2_max_value' => $Max2,
12876: $id.'.y2_min_value' => $Min2,
1.136 matthew 12877: );
12878: #
1.137 matthew 12879: if (defined($colors) && ref($colors) eq 'ARRAY') {
12880: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12881: }
12882: #
12883: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
12884: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 12885: return '';
12886: }
12887: my $NumSets=1;
1.137 matthew 12888: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 12889: next if (! ref($array));
12890: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 12891: }
12892: #
12893: # Deal with other parameters
12894: while (my ($key,$value) = each(%Values)) {
12895: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 12896: }
12897: #
1.646 raeburn 12898: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 12899: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 12900: }
12901:
12902: ############################################################
12903: ############################################################
12904:
12905: =pod
12906:
1.157 matthew 12907: =back
12908:
1.139 matthew 12909: =head1 Statistics helper routines?
12910:
12911: Bad place for them but what the hell.
12912:
1.157 matthew 12913: =over 4
12914:
1.648 raeburn 12915: =item * &chartlink()
1.139 matthew 12916:
12917: Returns a link to the chart for a specific student.
12918:
12919: Inputs:
12920:
12921: =over 4
12922:
12923: =item $linktext: The text of the link
12924:
12925: =item $sname: The students username
12926:
12927: =item $sdomain: The students domain
12928:
12929: =back
12930:
1.157 matthew 12931: =back
12932:
1.139 matthew 12933: =cut
12934:
12935: ############################################################
12936: ############################################################
12937: sub chartlink {
12938: my ($linktext, $sname, $sdomain) = @_;
12939: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 12940: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 12941: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 12942: '">'.$linktext.'</a>';
1.153 matthew 12943: }
12944:
12945: #######################################################
12946: #######################################################
12947:
12948: =pod
12949:
12950: =head1 Course Environment Routines
1.157 matthew 12951:
12952: =over 4
1.153 matthew 12953:
1.648 raeburn 12954: =item * &restore_course_settings()
1.153 matthew 12955:
1.648 raeburn 12956: =item * &store_course_settings()
1.153 matthew 12957:
12958: Restores/Store indicated form parameters from the course environment.
12959: Will not overwrite existing values of the form parameters.
12960:
12961: Inputs:
12962: a scalar describing the data (e.g. 'chart', 'problem_analysis')
12963:
12964: a hash ref describing the data to be stored. For example:
12965:
12966: %Save_Parameters = ('Status' => 'scalar',
12967: 'chartoutputmode' => 'scalar',
12968: 'chartoutputdata' => 'scalar',
12969: 'Section' => 'array',
1.373 raeburn 12970: 'Group' => 'array',
1.153 matthew 12971: 'StudentData' => 'array',
12972: 'Maps' => 'array');
12973:
12974: Returns: both routines return nothing
12975:
1.631 raeburn 12976: =back
12977:
1.153 matthew 12978: =cut
12979:
12980: #######################################################
12981: #######################################################
12982: sub store_course_settings {
1.496 albertel 12983: return &store_settings($env{'request.course.id'},@_);
12984: }
12985:
12986: sub store_settings {
1.153 matthew 12987: # save to the environment
12988: # appenv the same items, just to be safe
1.300 albertel 12989: my $udom = $env{'user.domain'};
12990: my $uname = $env{'user.name'};
1.496 albertel 12991: my ($context,$prefix,$Settings) = @_;
1.153 matthew 12992: my %SaveHash;
12993: my %AppHash;
12994: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 12995: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 12996: my $envname = 'environment.'.$basename;
1.258 albertel 12997: if (exists($env{'form.'.$setting})) {
1.153 matthew 12998: # Save this value away
12999: if ($type eq 'scalar' &&
1.258 albertel 13000: (! exists($env{$envname}) ||
13001: $env{$envname} ne $env{'form.'.$setting})) {
13002: $SaveHash{$basename} = $env{'form.'.$setting};
13003: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13004: } elsif ($type eq 'array') {
13005: my $stored_form;
1.258 albertel 13006: if (ref($env{'form.'.$setting})) {
1.153 matthew 13007: $stored_form = join(',',
13008: map {
1.369 www 13009: &escape($_);
1.258 albertel 13010: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13011: } else {
13012: $stored_form =
1.369 www 13013: &escape($env{'form.'.$setting});
1.153 matthew 13014: }
13015: # Determine if the array contents are the same.
1.258 albertel 13016: if ($stored_form ne $env{$envname}) {
1.153 matthew 13017: $SaveHash{$basename} = $stored_form;
13018: $AppHash{$envname} = $stored_form;
13019: }
13020: }
13021: }
13022: }
13023: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13024: $udom,$uname);
1.153 matthew 13025: if ($put_result !~ /^(ok|delayed)/) {
13026: &Apache::lonnet::logthis('unable to save form parameters, '.
13027: 'got error:'.$put_result);
13028: }
13029: # Make sure these settings stick around in this session, too
1.646 raeburn 13030: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13031: return;
13032: }
13033:
13034: sub restore_course_settings {
1.499 albertel 13035: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13036: }
13037:
13038: sub restore_settings {
13039: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13040: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13041: next if (exists($env{'form.'.$setting}));
1.496 albertel 13042: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13043: '.'.$setting;
1.258 albertel 13044: if (exists($env{$envname})) {
1.153 matthew 13045: if ($type eq 'scalar') {
1.258 albertel 13046: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13047: } elsif ($type eq 'array') {
1.258 albertel 13048: $env{'form.'.$setting} = [
1.153 matthew 13049: map {
1.369 www 13050: &unescape($_);
1.258 albertel 13051: } split(',',$env{$envname})
1.153 matthew 13052: ];
13053: }
13054: }
13055: }
1.127 matthew 13056: }
13057:
1.618 raeburn 13058: #######################################################
13059: #######################################################
13060:
13061: =pod
13062:
13063: =head1 Domain E-mail Routines
13064:
13065: =over 4
13066:
1.648 raeburn 13067: =item * &build_recipient_list()
1.618 raeburn 13068:
1.884 raeburn 13069: Build recipient lists for five types of e-mail:
1.766 raeburn 13070: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 13071: (d) Help requests, (e) Course requests needing approval, generated by
13072: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
13073: loncoursequeueadmin.pm respectively.
1.618 raeburn 13074:
13075: Inputs:
1.619 raeburn 13076: defmail (scalar - email address of default recipient),
1.618 raeburn 13077: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 13078: defdom (domain for which to retrieve configuration settings),
13079: origmail (scalar - email address of recipient from loncapa.conf,
13080: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13081:
1.655 raeburn 13082: Returns: comma separated list of addresses to which to send e-mail.
13083:
13084: =back
1.618 raeburn 13085:
13086: =cut
13087:
13088: ############################################################
13089: ############################################################
13090: sub build_recipient_list {
1.619 raeburn 13091: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13092: my @recipients;
13093: my $otheremails;
13094: my %domconfig =
13095: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13096: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13097: if (exists($domconfig{'contacts'}{$mailing})) {
13098: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13099: my @contacts = ('adminemail','supportemail');
13100: foreach my $item (@contacts) {
13101: if ($domconfig{'contacts'}{$mailing}{$item}) {
13102: my $addr = $domconfig{'contacts'}{$item};
13103: if (!grep(/^\Q$addr\E$/,@recipients)) {
13104: push(@recipients,$addr);
13105: }
1.619 raeburn 13106: }
1.766 raeburn 13107: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13108: }
13109: }
1.766 raeburn 13110: } elsif ($origmail ne '') {
13111: push(@recipients,$origmail);
1.618 raeburn 13112: }
1.619 raeburn 13113: } elsif ($origmail ne '') {
13114: push(@recipients,$origmail);
1.618 raeburn 13115: }
1.688 raeburn 13116: if (defined($defmail)) {
13117: if ($defmail ne '') {
13118: push(@recipients,$defmail);
13119: }
1.618 raeburn 13120: }
13121: if ($otheremails) {
1.619 raeburn 13122: my @others;
13123: if ($otheremails =~ /,/) {
13124: @others = split(/,/,$otheremails);
1.618 raeburn 13125: } else {
1.619 raeburn 13126: push(@others,$otheremails);
13127: }
13128: foreach my $addr (@others) {
13129: if (!grep(/^\Q$addr\E$/,@recipients)) {
13130: push(@recipients,$addr);
13131: }
1.618 raeburn 13132: }
13133: }
1.619 raeburn 13134: my $recipientlist = join(',',@recipients);
1.618 raeburn 13135: return $recipientlist;
13136: }
13137:
1.127 matthew 13138: ############################################################
13139: ############################################################
1.154 albertel 13140:
1.655 raeburn 13141: =pod
13142:
13143: =head1 Course Catalog Routines
13144:
13145: =over 4
13146:
13147: =item * &gather_categories()
13148:
13149: Converts category definitions - keys of categories hash stored in
13150: coursecategories in configuration.db on the primary library server in a
13151: domain - to an array. Also generates javascript and idx hash used to
13152: generate Domain Coordinator interface for editing Course Categories.
13153:
13154: Inputs:
1.663 raeburn 13155:
1.655 raeburn 13156: categories (reference to hash of category definitions).
1.663 raeburn 13157:
1.655 raeburn 13158: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13159: categories and subcategories).
1.663 raeburn 13160:
1.655 raeburn 13161: idx (reference to hash of counters used in Domain Coordinator interface for
13162: editing Course Categories).
1.663 raeburn 13163:
1.655 raeburn 13164: jsarray (reference to array of categories used to create Javascript arrays for
13165: Domain Coordinator interface for editing Course Categories).
13166:
13167: Returns: nothing
13168:
13169: Side effects: populates cats, idx and jsarray.
13170:
13171: =cut
13172:
13173: sub gather_categories {
13174: my ($categories,$cats,$idx,$jsarray) = @_;
13175: my %counters;
13176: my $num = 0;
13177: foreach my $item (keys(%{$categories})) {
13178: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13179: if ($container eq '' && $depth == 0) {
13180: $cats->[$depth][$categories->{$item}] = $cat;
13181: } else {
13182: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13183: }
13184: my ($escitem,$tail) = split(/:/,$item,2);
13185: if ($counters{$tail} eq '') {
13186: $counters{$tail} = $num;
13187: $num ++;
13188: }
13189: if (ref($idx) eq 'HASH') {
13190: $idx->{$item} = $counters{$tail};
13191: }
13192: if (ref($jsarray) eq 'ARRAY') {
13193: push(@{$jsarray->[$counters{$tail}]},$item);
13194: }
13195: }
13196: return;
13197: }
13198:
13199: =pod
13200:
13201: =item * &extract_categories()
13202:
13203: Used to generate breadcrumb trails for course categories.
13204:
13205: Inputs:
1.663 raeburn 13206:
1.655 raeburn 13207: categories (reference to hash of category definitions).
1.663 raeburn 13208:
1.655 raeburn 13209: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13210: categories and subcategories).
1.663 raeburn 13211:
1.655 raeburn 13212: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13213:
1.655 raeburn 13214: allitems (reference to hash - key is category key
13215: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13216:
1.655 raeburn 13217: idx (reference to hash of counters used in Domain Coordinator interface for
13218: editing Course Categories).
1.663 raeburn 13219:
1.655 raeburn 13220: jsarray (reference to array of categories used to create Javascript arrays for
13221: Domain Coordinator interface for editing Course Categories).
13222:
1.665 raeburn 13223: subcats (reference to hash of arrays containing all subcategories within each
13224: category, -recursive)
13225:
1.655 raeburn 13226: Returns: nothing
13227:
13228: Side effects: populates trails and allitems hash references.
13229:
13230: =cut
13231:
13232: sub extract_categories {
1.665 raeburn 13233: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13234: if (ref($categories) eq 'HASH') {
13235: &gather_categories($categories,$cats,$idx,$jsarray);
13236: if (ref($cats->[0]) eq 'ARRAY') {
13237: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13238: my $name = $cats->[0][$i];
13239: my $item = &escape($name).'::0';
13240: my $trailstr;
13241: if ($name eq 'instcode') {
13242: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13243: } elsif ($name eq 'communities') {
13244: $trailstr = &mt('Communities');
1.655 raeburn 13245: } else {
13246: $trailstr = $name;
13247: }
13248: if ($allitems->{$item} eq '') {
13249: push(@{$trails},$trailstr);
13250: $allitems->{$item} = scalar(@{$trails})-1;
13251: }
13252: my @parents = ($name);
13253: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13254: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13255: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13256: if (ref($subcats) eq 'HASH') {
13257: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13258: }
13259: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13260: }
13261: } else {
13262: if (ref($subcats) eq 'HASH') {
13263: $subcats->{$item} = [];
1.655 raeburn 13264: }
13265: }
13266: }
13267: }
13268: }
13269: return;
13270: }
13271:
13272: =pod
13273:
13274: =item *&recurse_categories()
13275:
13276: Recursively used to generate breadcrumb trails for course categories.
13277:
13278: Inputs:
1.663 raeburn 13279:
1.655 raeburn 13280: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13281: categories and subcategories).
1.663 raeburn 13282:
1.655 raeburn 13283: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13284:
13285: category (current course category, for which breadcrumb trail is being generated).
13286:
13287: trails (reference to array of breadcrumb trails for each category).
13288:
1.655 raeburn 13289: allitems (reference to hash - key is category key
13290: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13291:
1.655 raeburn 13292: parents (array containing containers directories for current category,
13293: back to top level).
13294:
13295: Returns: nothing
13296:
13297: Side effects: populates trails and allitems hash references
13298:
13299: =cut
13300:
13301: sub recurse_categories {
1.665 raeburn 13302: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13303: my $shallower = $depth - 1;
13304: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13305: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13306: my $name = $cats->[$depth]{$category}[$k];
13307: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13308: my $trailstr = join(' -> ',(@{$parents},$category));
13309: if ($allitems->{$item} eq '') {
13310: push(@{$trails},$trailstr);
13311: $allitems->{$item} = scalar(@{$trails})-1;
13312: }
13313: my $deeper = $depth+1;
13314: push(@{$parents},$category);
1.665 raeburn 13315: if (ref($subcats) eq 'HASH') {
13316: my $subcat = &escape($name).':'.$category.':'.$depth;
13317: for (my $j=@{$parents}; $j>=0; $j--) {
13318: my $higher;
13319: if ($j > 0) {
13320: $higher = &escape($parents->[$j]).':'.
13321: &escape($parents->[$j-1]).':'.$j;
13322: } else {
13323: $higher = &escape($parents->[$j]).'::'.$j;
13324: }
13325: push(@{$subcats->{$higher}},$subcat);
13326: }
13327: }
13328: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13329: $subcats);
1.655 raeburn 13330: pop(@{$parents});
13331: }
13332: } else {
13333: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13334: my $trailstr = join(' -> ',(@{$parents},$category));
13335: if ($allitems->{$item} eq '') {
13336: push(@{$trails},$trailstr);
13337: $allitems->{$item} = scalar(@{$trails})-1;
13338: }
13339: }
13340: return;
13341: }
13342:
1.663 raeburn 13343: =pod
13344:
13345: =item *&assign_categories_table()
13346:
13347: Create a datatable for display of hierarchical categories in a domain,
13348: with checkboxes to allow a course to be categorized.
13349:
13350: Inputs:
13351:
13352: cathash - reference to hash of categories defined for the domain (from
13353: configuration.db)
13354:
13355: currcat - scalar with an & separated list of categories assigned to a course.
13356:
1.919 raeburn 13357: type - scalar contains course type (Course or Community).
13358:
1.663 raeburn 13359: Returns: $output (markup to be displayed)
13360:
13361: =cut
13362:
13363: sub assign_categories_table {
1.919 raeburn 13364: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13365: my $output;
13366: if (ref($cathash) eq 'HASH') {
13367: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13368: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13369: $maxdepth = scalar(@cats);
13370: if (@cats > 0) {
13371: my $itemcount = 0;
13372: if (ref($cats[0]) eq 'ARRAY') {
13373: my @currcategories;
13374: if ($currcat ne '') {
13375: @currcategories = split('&',$currcat);
13376: }
1.919 raeburn 13377: my $table;
1.663 raeburn 13378: for (my $i=0; $i<@{$cats[0]}; $i++) {
13379: my $parent = $cats[0][$i];
1.919 raeburn 13380: next if ($parent eq 'instcode');
13381: if ($type eq 'Community') {
13382: next unless ($parent eq 'communities');
13383: } else {
13384: next if ($parent eq 'communities');
13385: }
1.663 raeburn 13386: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13387: my $item = &escape($parent).'::0';
13388: my $checked = '';
13389: if (@currcategories > 0) {
13390: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13391: $checked = ' checked="checked"';
1.663 raeburn 13392: }
13393: }
1.919 raeburn 13394: my $parent_title = $parent;
13395: if ($parent eq 'communities') {
13396: $parent_title = &mt('Communities');
13397: }
13398: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13399: '<input type="checkbox" name="usecategory" value="'.
13400: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13401: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13402: my $depth = 1;
13403: push(@path,$parent);
1.919 raeburn 13404: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13405: pop(@path);
1.919 raeburn 13406: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13407: $itemcount ++;
13408: }
1.919 raeburn 13409: if ($itemcount) {
13410: $output = &Apache::loncommon::start_data_table().
13411: $table.
13412: &Apache::loncommon::end_data_table();
13413: }
1.663 raeburn 13414: }
13415: }
13416: }
13417: return $output;
13418: }
13419:
13420: =pod
13421:
13422: =item *&assign_category_rows()
13423:
13424: Create a datatable row for display of nested categories in a domain,
13425: with checkboxes to allow a course to be categorized,called recursively.
13426:
13427: Inputs:
13428:
13429: itemcount - track row number for alternating colors
13430:
13431: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13432: categories and subcategories.
13433:
13434: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13435:
13436: parent - parent of current category item
13437:
13438: path - Array containing all categories back up through the hierarchy from the
13439: current category to the top level.
13440:
13441: currcategories - reference to array of current categories assigned to the course
13442:
13443: Returns: $output (markup to be displayed).
13444:
13445: =cut
13446:
13447: sub assign_category_rows {
13448: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13449: my ($text,$name,$item,$chgstr);
13450: if (ref($cats) eq 'ARRAY') {
13451: my $maxdepth = scalar(@{$cats});
13452: if (ref($cats->[$depth]) eq 'HASH') {
13453: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13454: my $numchildren = @{$cats->[$depth]{$parent}};
13455: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13456: $text .= '<td><table class="LC_datatable">';
13457: for (my $j=0; $j<$numchildren; $j++) {
13458: $name = $cats->[$depth]{$parent}[$j];
13459: $item = &escape($name).':'.&escape($parent).':'.$depth;
13460: my $deeper = $depth+1;
13461: my $checked = '';
13462: if (ref($currcategories) eq 'ARRAY') {
13463: if (@{$currcategories} > 0) {
13464: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13465: $checked = ' checked="checked"';
1.663 raeburn 13466: }
13467: }
13468: }
1.664 raeburn 13469: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13470: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13471: $item.'"'.$checked.' />'.$name.'</label></span>'.
13472: '<input type="hidden" name="catname" value="'.$name.'" />'.
13473: '</td><td>';
1.663 raeburn 13474: if (ref($path) eq 'ARRAY') {
13475: push(@{$path},$name);
13476: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13477: pop(@{$path});
13478: }
13479: $text .= '</td></tr>';
13480: }
13481: $text .= '</table></td>';
13482: }
13483: }
13484: }
13485: return $text;
13486: }
13487:
1.655 raeburn 13488: ############################################################
13489: ############################################################
13490:
13491:
1.443 albertel 13492: sub commit_customrole {
1.664 raeburn 13493: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13494: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13495: ($start?', '.&mt('starting').' '.localtime($start):'').
13496: ($end?', ending '.localtime($end):'').': <b>'.
13497: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13498: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13499: '</b><br />';
13500: return $output;
13501: }
13502:
13503: sub commit_standardrole {
1.1116 raeburn 13504: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13505: my ($output,$logmsg,$linefeed);
13506: if ($context eq 'auto') {
13507: $linefeed = "\n";
13508: } else {
13509: $linefeed = "<br />\n";
13510: }
1.443 albertel 13511: if ($three eq 'st') {
1.541 raeburn 13512: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 13513: $one,$two,$sec,$context,$credits);
1.541 raeburn 13514: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13515: ($result eq 'unknown_course') || ($result eq 'refused')) {
13516: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13517: } else {
1.541 raeburn 13518: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13519: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13520: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13521: if ($context eq 'auto') {
13522: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13523: } else {
13524: $output .= '<b>'.$result.'</b>'.$linefeed.
13525: &mt('Add to classlist').': <b>ok</b>';
13526: }
13527: $output .= $linefeed;
1.443 albertel 13528: }
13529: } else {
13530: $output = &mt('Assigning').' '.$three.' in '.$url.
13531: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13532: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13533: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13534: if ($context eq 'auto') {
13535: $output .= $result.$linefeed;
13536: } else {
13537: $output .= '<b>'.$result.'</b>'.$linefeed;
13538: }
1.443 albertel 13539: }
13540: return $output;
13541: }
13542:
13543: sub commit_studentrole {
1.1116 raeburn 13544: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13545: $credits) = @_;
1.626 raeburn 13546: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13547: if ($context eq 'auto') {
13548: $linefeed = "\n";
13549: } else {
13550: $linefeed = '<br />'."\n";
13551: }
1.443 albertel 13552: if (defined($one) && defined($two)) {
13553: my $cid=$one.'_'.$two;
13554: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13555: my $secchange = 0;
13556: my $expire_role_result;
13557: my $modify_section_result;
1.628 raeburn 13558: if ($oldsec ne '-1') {
13559: if ($oldsec ne $sec) {
1.443 albertel 13560: $secchange = 1;
1.628 raeburn 13561: my $now = time;
1.443 albertel 13562: my $uurl='/'.$cid;
13563: $uurl=~s/\_/\//g;
13564: if ($oldsec) {
13565: $uurl.='/'.$oldsec;
13566: }
1.626 raeburn 13567: $oldsecurl = $uurl;
1.628 raeburn 13568: $expire_role_result =
1.652 raeburn 13569: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13570: if ($env{'request.course.sec'} ne '') {
13571: if ($expire_role_result eq 'refused') {
13572: my @roles = ('st');
13573: my @statuses = ('previous');
13574: my @roledoms = ($one);
13575: my $withsec = 1;
13576: my %roleshash =
13577: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13578: \@statuses,\@roles,\@roledoms,$withsec);
13579: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13580: my ($oldstart,$oldend) =
13581: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13582: if ($oldend > 0 && $oldend <= $now) {
13583: $expire_role_result = 'ok';
13584: }
13585: }
13586: }
13587: }
1.443 albertel 13588: $result = $expire_role_result;
13589: }
13590: }
13591: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 13592: $modify_section_result =
13593: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13594: undef,undef,undef,$sec,
13595: $end,$start,'','',$cid,
13596: '',$context,$credits);
1.443 albertel 13597: if ($modify_section_result =~ /^ok/) {
13598: if ($secchange == 1) {
1.628 raeburn 13599: if ($sec eq '') {
13600: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13601: } else {
13602: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13603: }
1.443 albertel 13604: } elsif ($oldsec eq '-1') {
1.628 raeburn 13605: if ($sec eq '') {
13606: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13607: } else {
13608: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13609: }
1.443 albertel 13610: } else {
1.628 raeburn 13611: if ($sec eq '') {
13612: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13613: } else {
13614: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13615: }
1.443 albertel 13616: }
13617: } else {
1.1115 raeburn 13618: if ($secchange) {
1.628 raeburn 13619: $$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;
13620: } else {
13621: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13622: }
1.443 albertel 13623: }
13624: $result = $modify_section_result;
13625: } elsif ($secchange == 1) {
1.628 raeburn 13626: if ($oldsec eq '') {
1.1103 raeburn 13627: $$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 13628: } else {
13629: $$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;
13630: }
1.626 raeburn 13631: if ($expire_role_result eq 'refused') {
13632: my $newsecurl = '/'.$cid;
13633: $newsecurl =~ s/\_/\//g;
13634: if ($sec ne '') {
13635: $newsecurl.='/'.$sec;
13636: }
13637: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13638: if ($sec eq '') {
13639: $$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;
13640: } else {
13641: $$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;
13642: }
13643: }
13644: }
1.443 albertel 13645: }
13646: } else {
1.626 raeburn 13647: $$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 13648: $result = "error: incomplete course id\n";
13649: }
13650: return $result;
13651: }
13652:
1.1108 raeburn 13653: sub show_role_extent {
13654: my ($scope,$context,$role) = @_;
13655: $scope =~ s{^/}{};
13656: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13657: push(@courseroles,'co');
13658: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13659: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13660: $scope =~ s{/}{_};
13661: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13662: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13663: my ($audom,$auname) = split(/\//,$scope);
13664: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13665: &Apache::loncommon::plainname($auname,$audom).'</span>');
13666: } else {
13667: $scope =~ s{/$}{};
13668: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13669: &Apache::lonnet::domain($scope,'description').'</span>');
13670: }
13671: }
13672:
1.443 albertel 13673: ############################################################
13674: ############################################################
13675:
1.566 albertel 13676: sub check_clone {
1.578 raeburn 13677: my ($args,$linefeed) = @_;
1.566 albertel 13678: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13679: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13680: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13681: my $clonemsg;
13682: my $can_clone = 0;
1.944 raeburn 13683: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13684: if ($lctype ne 'community') {
13685: $lctype = 'course';
13686: }
1.566 albertel 13687: if ($clonehome eq 'no_host') {
1.944 raeburn 13688: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13689: $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'});
13690: } else {
13691: $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'});
13692: }
1.566 albertel 13693: } else {
13694: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13695: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13696: if ($clonedesc{'type'} ne 'Community') {
13697: $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'});
13698: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13699: }
13700: }
1.882 raeburn 13701: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13702: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13703: $can_clone = 1;
13704: } else {
13705: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13706: $args->{'clonedomain'},$args->{'clonecourse'});
13707: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13708: if (grep(/^\*$/,@cloners)) {
13709: $can_clone = 1;
13710: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13711: $can_clone = 1;
13712: } else {
1.908 raeburn 13713: my $ccrole = 'cc';
1.944 raeburn 13714: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13715: $ccrole = 'co';
13716: }
1.578 raeburn 13717: my %roleshash =
13718: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13719: $args->{'ccdomain'},
1.908 raeburn 13720: 'userroles',['active'],[$ccrole],
1.578 raeburn 13721: [$args->{'clonedomain'}]);
1.908 raeburn 13722: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13723: $can_clone = 1;
13724: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13725: $can_clone = 1;
13726: } else {
1.944 raeburn 13727: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13728: $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'});
13729: } else {
13730: $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'});
13731: }
1.578 raeburn 13732: }
1.566 albertel 13733: }
1.578 raeburn 13734: }
1.566 albertel 13735: }
13736: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13737: }
13738:
1.444 albertel 13739: sub construct_course {
1.885 raeburn 13740: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 13741: my $outcome;
1.541 raeburn 13742: my $linefeed = '<br />'."\n";
13743: if ($context eq 'auto') {
13744: $linefeed = "\n";
13745: }
1.566 albertel 13746:
13747: #
13748: # Are we cloning?
13749: #
13750: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13751: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13752: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13753: if ($context ne 'auto') {
1.578 raeburn 13754: if ($clonemsg ne '') {
13755: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13756: }
1.566 albertel 13757: }
13758: $outcome .= $clonemsg.$linefeed;
13759:
13760: if (!$can_clone) {
13761: return (0,$outcome);
13762: }
13763: }
13764:
1.444 albertel 13765: #
13766: # Open course
13767: #
13768: my $crstype = lc($args->{'crstype'});
13769: my %cenv=();
13770: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13771: $args->{'cdescr'},
13772: $args->{'curl'},
13773: $args->{'course_home'},
13774: $args->{'nonstandard'},
13775: $args->{'crscode'},
13776: $args->{'ccuname'}.':'.
13777: $args->{'ccdomain'},
1.882 raeburn 13778: $args->{'crstype'},
1.885 raeburn 13779: $cnum,$context,$category);
1.444 albertel 13780:
13781: # Note: The testing routines depend on this being output; see
13782: # Utils::Course. This needs to at least be output as a comment
13783: # if anyone ever decides to not show this, and Utils::Course::new
13784: # will need to be suitably modified.
1.541 raeburn 13785: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13786: if ($$courseid =~ /^error:/) {
13787: return (0,$outcome);
13788: }
13789:
1.444 albertel 13790: #
13791: # Check if created correctly
13792: #
1.479 albertel 13793: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13794: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13795: if ($crsuhome eq 'no_host') {
13796: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13797: return (0,$outcome);
13798: }
1.541 raeburn 13799: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13800:
1.444 albertel 13801: #
1.566 albertel 13802: # Do the cloning
13803: #
13804: if ($can_clone && $cloneid) {
13805: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13806: if ($context ne 'auto') {
13807: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13808: }
13809: $outcome .= $clonemsg.$linefeed;
13810: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13811: # Copy all files
1.637 www 13812: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13813: # Restore URL
1.566 albertel 13814: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13815: # Restore title
1.566 albertel 13816: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13817: # Restore creation date, creator and creation context.
13818: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13819: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13820: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13821: # Mark as cloned
1.566 albertel 13822: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13823: # Need to clone grading mode
13824: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13825: $cenv{'grading'}=$newenv{'grading'};
13826: # Do not clone these environment entries
13827: &Apache::lonnet::del('environment',
13828: ['default_enrollment_start_date',
13829: 'default_enrollment_end_date',
13830: 'question.email',
13831: 'policy.email',
13832: 'comment.email',
13833: 'pch.users.denied',
1.725 raeburn 13834: 'plc.users.denied',
13835: 'hidefromcat',
1.1121 raeburn 13836: 'checkforpriv',
1.725 raeburn 13837: 'categories'],
1.638 www 13838: $$crsudom,$$crsunum);
1.444 albertel 13839: }
1.566 albertel 13840:
1.444 albertel 13841: #
13842: # Set environment (will override cloned, if existing)
13843: #
13844: my @sections = ();
13845: my @xlists = ();
13846: if ($args->{'crstype'}) {
13847: $cenv{'type'}=$args->{'crstype'};
13848: }
13849: if ($args->{'crsid'}) {
13850: $cenv{'courseid'}=$args->{'crsid'};
13851: }
13852: if ($args->{'crscode'}) {
13853: $cenv{'internal.coursecode'}=$args->{'crscode'};
13854: }
13855: if ($args->{'crsquota'} ne '') {
13856: $cenv{'internal.coursequota'}=$args->{'crsquota'};
13857: } else {
13858: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
13859: }
13860: if ($args->{'ccuname'}) {
13861: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
13862: ':'.$args->{'ccdomain'};
13863: } else {
13864: $cenv{'internal.courseowner'} = $args->{'curruser'};
13865: }
1.1116 raeburn 13866: if ($args->{'defaultcredits'}) {
13867: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
13868: }
1.444 albertel 13869: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
13870: if ($args->{'crssections'}) {
13871: $cenv{'internal.sectionnums'} = '';
13872: if ($args->{'crssections'} =~ m/,/) {
13873: @sections = split/,/,$args->{'crssections'};
13874: } else {
13875: $sections[0] = $args->{'crssections'};
13876: }
13877: if (@sections > 0) {
13878: foreach my $item (@sections) {
13879: my ($sec,$gp) = split/:/,$item;
13880: my $class = $args->{'crscode'}.$sec;
13881: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
13882: $cenv{'internal.sectionnums'} .= $item.',';
13883: unless ($addcheck eq 'ok') {
13884: push @badclasses, $class;
13885: }
13886: }
13887: $cenv{'internal.sectionnums'} =~ s/,$//;
13888: }
13889: }
13890: # do not hide course coordinator from staff listing,
13891: # even if privileged
13892: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 13893: # add course coordinator's domain to domains to check for privileged users
13894: # if different to course domain
13895: if ($$crsudom ne $args->{'ccdomain'}) {
13896: $cenv{'checkforpriv'} = $args->{'ccdomain'};
13897: }
1.444 albertel 13898: # add crosslistings
13899: if ($args->{'crsxlist'}) {
13900: $cenv{'internal.crosslistings'}='';
13901: if ($args->{'crsxlist'} =~ m/,/) {
13902: @xlists = split/,/,$args->{'crsxlist'};
13903: } else {
13904: $xlists[0] = $args->{'crsxlist'};
13905: }
13906: if (@xlists > 0) {
13907: foreach my $item (@xlists) {
13908: my ($xl,$gp) = split/:/,$item;
13909: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
13910: $cenv{'internal.crosslistings'} .= $item.',';
13911: unless ($addcheck eq 'ok') {
13912: push @badclasses, $xl;
13913: }
13914: }
13915: $cenv{'internal.crosslistings'} =~ s/,$//;
13916: }
13917: }
13918: if ($args->{'autoadds'}) {
13919: $cenv{'internal.autoadds'}=$args->{'autoadds'};
13920: }
13921: if ($args->{'autodrops'}) {
13922: $cenv{'internal.autodrops'}=$args->{'autodrops'};
13923: }
13924: # check for notification of enrollment changes
13925: my @notified = ();
13926: if ($args->{'notify_owner'}) {
13927: if ($args->{'ccuname'} ne '') {
13928: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
13929: }
13930: }
13931: if ($args->{'notify_dc'}) {
13932: if ($uname ne '') {
1.630 raeburn 13933: push(@notified,$uname.':'.$udom);
1.444 albertel 13934: }
13935: }
13936: if (@notified > 0) {
13937: my $notifylist;
13938: if (@notified > 1) {
13939: $notifylist = join(',',@notified);
13940: } else {
13941: $notifylist = $notified[0];
13942: }
13943: $cenv{'internal.notifylist'} = $notifylist;
13944: }
13945: if (@badclasses > 0) {
13946: my %lt=&Apache::lonlocal::texthash(
13947: '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',
13948: 'dnhr' => 'does not have rights to access enrollment in these classes',
13949: 'adby' => 'as determined by the policies of your institution on access to official classlists'
13950: );
1.541 raeburn 13951: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
13952: ' ('.$lt{'adby'}.')';
13953: if ($context eq 'auto') {
13954: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 13955: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 13956: foreach my $item (@badclasses) {
13957: if ($context eq 'auto') {
13958: $outcome .= " - $item\n";
13959: } else {
13960: $outcome .= "<li>$item</li>\n";
13961: }
13962: }
13963: if ($context eq 'auto') {
13964: $outcome .= $linefeed;
13965: } else {
1.566 albertel 13966: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 13967: }
13968: }
1.444 albertel 13969: }
13970: if ($args->{'no_end_date'}) {
13971: $args->{'endaccess'} = 0;
13972: }
13973: $cenv{'internal.autostart'}=$args->{'enrollstart'};
13974: $cenv{'internal.autoend'}=$args->{'enrollend'};
13975: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
13976: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
13977: if ($args->{'showphotos'}) {
13978: $cenv{'internal.showphotos'}=$args->{'showphotos'};
13979: }
13980: $cenv{'internal.authtype'} = $args->{'authtype'};
13981: $cenv{'internal.autharg'} = $args->{'autharg'};
13982: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
13983: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 13984: 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');
13985: if ($context eq 'auto') {
13986: $outcome .= $krb_msg;
13987: } else {
1.566 albertel 13988: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 13989: }
13990: $outcome .= $linefeed;
1.444 albertel 13991: }
13992: }
13993: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
13994: if ($args->{'setpolicy'}) {
13995: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13996: }
13997: if ($args->{'setcontent'}) {
13998: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13999: }
14000: }
14001: if ($args->{'reshome'}) {
14002: $cenv{'reshome'}=$args->{'reshome'}.'/';
14003: $cenv{'reshome'}=~s/\/+$/\//;
14004: }
14005: #
14006: # course has keyed access
14007: #
14008: if ($args->{'setkeys'}) {
14009: $cenv{'keyaccess'}='yes';
14010: }
14011: # if specified, key authority is not course, but user
14012: # only active if keyaccess is yes
14013: if ($args->{'keyauth'}) {
1.487 albertel 14014: my ($user,$domain) = split(':',$args->{'keyauth'});
14015: $user = &LONCAPA::clean_username($user);
14016: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14017: if ($user ne '' && $domain ne '') {
1.487 albertel 14018: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14019: }
14020: }
14021:
14022: if ($args->{'disresdis'}) {
14023: $cenv{'pch.roles.denied'}='st';
14024: }
14025: if ($args->{'disablechat'}) {
14026: $cenv{'plc.roles.denied'}='st';
14027: }
14028:
14029: # Record we've not yet viewed the Course Initialization Helper for this
14030: # course
14031: $cenv{'course.helper.not.run'} = 1;
14032: #
14033: # Use new Randomseed
14034: #
14035: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14036: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14037: #
14038: # The encryption code and receipt prefix for this course
14039: #
14040: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14041: $cenv{'internal.encpref'}=100+int(9*rand(99));
14042: #
14043: # By default, use standard grading
14044: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14045:
1.541 raeburn 14046: $outcome .= $linefeed.&mt('Setting environment').': '.
14047: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14048: #
14049: # Open all assignments
14050: #
14051: if ($args->{'openall'}) {
14052: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14053: my %storecontent = ($storeunder => time,
14054: $storeunder.'.type' => 'date_start');
14055:
14056: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14057: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14058: }
14059: #
14060: # Set first page
14061: #
14062: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14063: || ($cloneid)) {
1.445 albertel 14064: use LONCAPA::map;
1.444 albertel 14065: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14066:
14067: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14068: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14069:
1.444 albertel 14070: $outcome .= ($fatal?$errtext:'read ok').' - ';
14071: my $title; my $url;
14072: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14073: $title=&mt('Syllabus');
1.444 albertel 14074: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14075: } else {
1.963 raeburn 14076: $title=&mt('Table of Contents');
1.444 albertel 14077: $url='/adm/navmaps';
14078: }
1.445 albertel 14079:
14080: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14081: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14082:
14083: if ($errtext) { $fatal=2; }
1.541 raeburn 14084: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14085: }
1.566 albertel 14086:
14087: return (1,$outcome);
1.444 albertel 14088: }
14089:
14090: ############################################################
14091: ############################################################
14092:
1.953 droeschl 14093: #SD
14094: # only Community and Course, or anything else?
1.378 raeburn 14095: sub course_type {
14096: my ($cid) = @_;
14097: if (!defined($cid)) {
14098: $cid = $env{'request.course.id'};
14099: }
1.404 albertel 14100: if (defined($env{'course.'.$cid.'.type'})) {
14101: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14102: } else {
14103: return 'Course';
1.377 raeburn 14104: }
14105: }
1.156 albertel 14106:
1.406 raeburn 14107: sub group_term {
14108: my $crstype = &course_type();
14109: my %names = (
14110: 'Course' => 'group',
1.865 raeburn 14111: 'Community' => 'group',
1.406 raeburn 14112: );
14113: return $names{$crstype};
14114: }
14115:
1.902 raeburn 14116: sub course_types {
14117: my @types = ('official','unofficial','community');
14118: my %typename = (
14119: official => 'Official course',
14120: unofficial => 'Unofficial course',
14121: community => 'Community',
14122: );
14123: return (\@types,\%typename);
14124: }
14125:
1.156 albertel 14126: sub icon {
14127: my ($file)=@_;
1.505 albertel 14128: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14129: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14130: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14131: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14132: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14133: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14134: $curfext.".gif") {
14135: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14136: $curfext.".gif";
14137: }
14138: }
1.249 albertel 14139: return &lonhttpdurl($iconname);
1.154 albertel 14140: }
1.84 albertel 14141:
1.575 albertel 14142: sub lonhttpdurl {
1.692 www 14143: #
14144: # Had been used for "small fry" static images on separate port 8080.
14145: # Modify here if lightweight http functionality desired again.
14146: # Currently eliminated due to increasing firewall issues.
14147: #
1.575 albertel 14148: my ($url)=@_;
1.692 www 14149: return $url;
1.215 albertel 14150: }
14151:
1.213 albertel 14152: sub connection_aborted {
14153: my ($r)=@_;
14154: $r->print(" ");$r->rflush();
14155: my $c = $r->connection;
14156: return $c->aborted();
14157: }
14158:
1.221 foxr 14159: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14160: # strings as 'strings'.
14161: sub escape_single {
1.221 foxr 14162: my ($input) = @_;
1.223 albertel 14163: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14164: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14165: return $input;
14166: }
1.223 albertel 14167:
1.222 foxr 14168: # Same as escape_single, but escape's "'s This
14169: # can be used for "strings"
14170: sub escape_double {
14171: my ($input) = @_;
14172: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14173: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14174: return $input;
14175: }
1.223 albertel 14176:
1.222 foxr 14177: # Escapes the last element of a full URL.
14178: sub escape_url {
14179: my ($url) = @_;
1.238 raeburn 14180: my @urlslices = split(/\//, $url,-1);
1.369 www 14181: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14182: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14183: }
1.462 albertel 14184:
1.820 raeburn 14185: sub compare_arrays {
14186: my ($arrayref1,$arrayref2) = @_;
14187: my (@difference,%count);
14188: @difference = ();
14189: %count = ();
14190: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14191: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14192: foreach my $element (keys(%count)) {
14193: if ($count{$element} == 1) {
14194: push(@difference,$element);
14195: }
14196: }
14197: }
14198: return @difference;
14199: }
14200:
1.817 bisitz 14201: # -------------------------------------------------------- Initialize user login
1.462 albertel 14202: sub init_user_environment {
1.463 albertel 14203: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14204: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14205:
14206: my $public=($username eq 'public' && $domain eq 'public');
14207:
14208: # See if old ID present, if so, remove
14209:
1.1062 raeburn 14210: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14211: my $now=time;
14212:
14213: if ($public) {
14214: my $max_public=100;
14215: my $oldest;
14216: my $oldest_time=0;
14217: for(my $next=1;$next<=$max_public;$next++) {
14218: if (-e $lonids."/publicuser_$next.id") {
14219: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14220: if ($mtime<$oldest_time || !$oldest_time) {
14221: $oldest_time=$mtime;
14222: $oldest=$next;
14223: }
14224: } else {
14225: $cookie="publicuser_$next";
14226: last;
14227: }
14228: }
14229: if (!$cookie) { $cookie="publicuser_$oldest"; }
14230: } else {
1.463 albertel 14231: # if this isn't a robot, kill any existing non-robot sessions
14232: if (!$args->{'robot'}) {
14233: opendir(DIR,$lonids);
14234: while ($filename=readdir(DIR)) {
14235: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14236: unlink($lonids.'/'.$filename);
14237: }
1.462 albertel 14238: }
1.463 albertel 14239: closedir(DIR);
1.462 albertel 14240: }
14241: # Give them a new cookie
1.463 albertel 14242: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14243: : $now.$$.int(rand(10000)));
1.463 albertel 14244: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14245:
14246: # Initialize roles
14247:
1.1062 raeburn 14248: ($userroles,$firstaccenv,$timerintenv) =
14249: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14250: }
14251: # ------------------------------------ Check browser type and MathML capability
14252:
14253: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1137 raeburn 14254: $clientunicode,$clientos,$clientmobile) = &decode_user_agent($r);
1.462 albertel 14255:
14256: # ------------------------------------------------------------- Get environment
14257:
14258: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14259: my ($tmp) = keys(%userenv);
14260: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14261: } else {
14262: undef(%userenv);
14263: }
14264: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14265: $form->{'interface'}=$userenv{'interface'};
14266: }
14267: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14268:
14269: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14270: foreach my $option ('interface','localpath','localres') {
14271: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14272: }
14273: # --------------------------------------------------------- Write first profile
14274:
14275: {
14276: my %initial_env =
14277: ("user.name" => $username,
14278: "user.domain" => $domain,
14279: "user.home" => $authhost,
14280: "browser.type" => $clientbrowser,
14281: "browser.version" => $clientversion,
14282: "browser.mathml" => $clientmathml,
14283: "browser.unicode" => $clientunicode,
14284: "browser.os" => $clientos,
1.1137 raeburn 14285: "browser.mobile" => $clientmobile,
1.462 albertel 14286: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14287: "request.course.fn" => '',
14288: "request.course.uri" => '',
14289: "request.course.sec" => '',
14290: "request.role" => 'cm',
14291: "request.role.adv" => $env{'user.adv'},
14292: "request.host" => $ENV{'REMOTE_ADDR'},);
14293:
14294: if ($form->{'localpath'}) {
14295: $initial_env{"browser.localpath"} = $form->{'localpath'};
14296: $initial_env{"browser.localres"} = $form->{'localres'};
14297: }
14298:
14299: if ($form->{'interface'}) {
14300: $form->{'interface'}=~s/\W//gs;
14301: $initial_env{"browser.interface"} = $form->{'interface'};
14302: $env{'browser.interface'}=$form->{'interface'};
14303: }
14304:
1.981 raeburn 14305: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14306: my %domdef;
14307: unless ($domain eq 'public') {
14308: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14309: }
1.980 raeburn 14310:
1.1081 raeburn 14311: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14312: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14313: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14314: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14315: }
14316:
1.864 raeburn 14317: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 14318: $userenv{'canrequest.'.$crstype} =
14319: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14320: 'reload','requestcourses',
14321: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14322: }
14323:
1.1092 raeburn 14324: $userenv{'canrequest.author'} =
14325: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14326: 'reload','requestauthor',
14327: \%userenv,\%domdef,\%is_adv);
14328: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14329: $domain,$username);
14330: my $reqstatus = $reqauthor{'author_status'};
14331: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14332: if (ref($reqauthor{'author'}) eq 'HASH') {
14333: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14334: $reqauthor{'author'}{'timestamp'};
14335: }
14336: }
14337:
1.462 albertel 14338: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14339:
1.462 albertel 14340: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14341: &GDBM_WRCREAT(),0640)) {
14342: &_add_to_env(\%disk_env,\%initial_env);
14343: &_add_to_env(\%disk_env,\%userenv,'environment.');
14344: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14345: if (ref($firstaccenv) eq 'HASH') {
14346: &_add_to_env(\%disk_env,$firstaccenv);
14347: }
14348: if (ref($timerintenv) eq 'HASH') {
14349: &_add_to_env(\%disk_env,$timerintenv);
14350: }
1.463 albertel 14351: if (ref($args->{'extra_env'})) {
14352: &_add_to_env(\%disk_env,$args->{'extra_env'});
14353: }
1.462 albertel 14354: untie(%disk_env);
14355: } else {
1.705 tempelho 14356: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14357: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14358: return 'error: '.$!;
14359: }
14360: }
14361: $env{'request.role'}='cm';
14362: $env{'request.role.adv'}=$env{'user.adv'};
14363: $env{'browser.type'}=$clientbrowser;
14364:
14365: return $cookie;
14366:
14367: }
14368:
14369: sub _add_to_env {
14370: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14371: if (ref($env_data) eq 'HASH') {
14372: while (my ($key,$value) = each(%$env_data)) {
14373: $idf->{$prefix.$key} = $value;
14374: $env{$prefix.$key} = $value;
14375: }
1.462 albertel 14376: }
14377: }
14378:
1.685 tempelho 14379: # --- Get the symbolic name of a problem and the url
14380: sub get_symb {
14381: my ($request,$silent) = @_;
1.726 raeburn 14382: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14383: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14384: if ($symb eq '') {
14385: if (!$silent) {
1.1071 raeburn 14386: if (ref($request)) {
14387: $request->print("Unable to handle ambiguous references:$url:.");
14388: }
1.685 tempelho 14389: return ();
14390: }
14391: }
14392: &Apache::lonenc::check_decrypt(\$symb);
14393: return ($symb);
14394: }
14395:
14396: # --------------------------------------------------------------Get annotation
14397:
14398: sub get_annotation {
14399: my ($symb,$enc) = @_;
14400:
14401: my $key = $symb;
14402: if (!$enc) {
14403: $key =
14404: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14405: }
14406: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14407: return $annotation{$key};
14408: }
14409:
14410: sub clean_symb {
1.731 raeburn 14411: my ($symb,$delete_enc) = @_;
1.685 tempelho 14412:
14413: &Apache::lonenc::check_decrypt(\$symb);
14414: my $enc = $env{'request.enc'};
1.731 raeburn 14415: if ($delete_enc) {
1.730 raeburn 14416: delete($env{'request.enc'});
14417: }
1.685 tempelho 14418:
14419: return ($symb,$enc);
14420: }
1.462 albertel 14421:
1.990 raeburn 14422: sub build_release_hashes {
14423: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14424: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14425: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14426: (ref($randomizetry) eq 'HASH'));
14427: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14428: my ($item,$name,$value) = split(/:/,$key);
14429: if ($item eq 'parameter') {
14430: if (ref($checkparms->{$name}) eq 'ARRAY') {
14431: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14432: push(@{$checkparms->{$name}},$value);
14433: }
14434: } else {
14435: push(@{$checkparms->{$name}},$value);
14436: }
14437: } elsif ($item eq 'resourcetag') {
14438: if ($name eq 'responsetype') {
14439: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14440: }
14441: } elsif ($item eq 'course') {
14442: if ($name eq 'crstype') {
14443: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14444: }
14445: }
14446: }
14447: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14448: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14449: return;
14450: }
14451:
1.1083 raeburn 14452: sub update_content_constraints {
14453: my ($cdom,$cnum,$chome,$cid) = @_;
14454: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14455: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14456: my %checkresponsetypes;
14457: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14458: my ($item,$name,$value) = split(/:/,$key);
14459: if ($item eq 'resourcetag') {
14460: if ($name eq 'responsetype') {
14461: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14462: }
14463: }
14464: }
14465: my $navmap = Apache::lonnavmaps::navmap->new();
14466: if (defined($navmap)) {
14467: my %allresponses;
14468: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14469: my %responses = $res->responseTypes();
14470: foreach my $key (keys(%responses)) {
14471: next unless(exists($checkresponsetypes{$key}));
14472: $allresponses{$key} += $responses{$key};
14473: }
14474: }
14475: foreach my $key (keys(%allresponses)) {
14476: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14477: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14478: ($reqdmajor,$reqdminor) = ($major,$minor);
14479: }
14480: }
14481: undef($navmap);
14482: }
14483: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14484: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14485: }
14486: return;
14487: }
14488:
1.1110 raeburn 14489: sub allmaps_incourse {
14490: my ($cdom,$cnum,$chome,$cid) = @_;
14491: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14492: $cid = $env{'request.course.id'};
14493: $cdom = $env{'course.'.$cid.'.domain'};
14494: $cnum = $env{'course.'.$cid.'.num'};
14495: $chome = $env{'course.'.$cid.'.home'};
14496: }
14497: my %allmaps = ();
14498: my $lastchange =
14499: &Apache::lonnet::get_coursechange($cdom,$cnum);
14500: if ($lastchange > $env{'request.course.tied'}) {
14501: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14502: unless ($ferr) {
14503: &update_content_constraints($cdom,$cnum,$chome,$cid);
14504: }
14505: }
14506: my $navmap = Apache::lonnavmaps::navmap->new();
14507: if (defined($navmap)) {
14508: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14509: $allmaps{$res->src()} = 1;
14510: }
14511: }
14512: return \%allmaps;
14513: }
14514:
1.1083 raeburn 14515: sub parse_supplemental_title {
14516: my ($title) = @_;
14517:
14518: my ($foldertitle,$renametitle);
14519: if ($title =~ /&&&/) {
14520: $title = &HTML::Entites::decode($title);
14521: }
14522: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14523: $renametitle=$4;
14524: my ($time,$uname,$udom) = ($1,$2,$3);
14525: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14526: my $name = &plainname($uname,$udom);
14527: $name = &HTML::Entities::encode($name,'"<>&\'');
14528: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14529: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14530: $name.': <br />'.$foldertitle;
14531: }
14532: if (wantarray) {
14533: return ($title,$foldertitle,$renametitle);
14534: }
14535: return $title;
14536: }
14537:
1.1101 raeburn 14538: sub symb_to_docspath {
14539: my ($symb) = @_;
14540: return unless ($symb);
14541: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14542: if ($resurl=~/\.(sequence|page)$/) {
14543: $mapurl=$resurl;
14544: } elsif ($resurl eq 'adm/navmaps') {
14545: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14546: }
14547: my $mapresobj;
14548: my $navmap = Apache::lonnavmaps::navmap->new();
14549: if (ref($navmap)) {
14550: $mapresobj = $navmap->getResourceByUrl($mapurl);
14551: }
14552: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14553: my $type=$2;
14554: my $path;
14555: if (ref($mapresobj)) {
14556: my $pcslist = $mapresobj->map_hierarchy();
14557: if ($pcslist ne '') {
14558: foreach my $pc (split(/,/,$pcslist)) {
14559: next if ($pc <= 1);
14560: my $res = $navmap->getByMapPc($pc);
14561: if (ref($res)) {
14562: my $thisurl = $res->src();
14563: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14564: my $thistitle = $res->title();
14565: $path .= '&'.
14566: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
14567: &Apache::lonhtmlcommon::entity_encode($thistitle).
14568: ':'.$res->randompick().
14569: ':'.$res->randomout().
14570: ':'.$res->encrypted().
14571: ':'.$res->randomorder().
14572: ':'.$res->is_page();
14573: }
14574: }
14575: }
14576: $path =~ s/^\&//;
14577: my $maptitle = $mapresobj->title();
14578: if ($mapurl eq 'default') {
1.1129 raeburn 14579: $maptitle = 'Main Content';
1.1101 raeburn 14580: }
14581: $path .= (($path ne '')? '&' : '').
14582: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
14583: &Apache::lonhtmlcommon::entity_encode($maptitle).
14584: ':'.$mapresobj->randompick().
14585: ':'.$mapresobj->randomout().
14586: ':'.$mapresobj->encrypted().
14587: ':'.$mapresobj->randomorder().
14588: ':'.$mapresobj->is_page();
14589: } else {
14590: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14591: my $ispage = (($type eq 'page')? 1 : '');
14592: if ($mapurl eq 'default') {
1.1129 raeburn 14593: $maptitle = 'Main Content';
1.1101 raeburn 14594: }
14595: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
14596: &Apache::lonhtmlcommon::entity_encode($maptitle).':::::'.$ispage;
14597: }
14598: unless ($mapurl eq 'default') {
14599: $path = 'default&'.
1.1129 raeburn 14600: &Apache::lonhtmlcommon::entity_encode('Main Content').
1.1101 raeburn 14601: ':::::&'.$path;
14602: }
14603: return $path;
14604: }
14605:
1.1094 raeburn 14606: sub captcha_display {
14607: my ($context,$lonhost) = @_;
14608: my ($output,$error);
14609: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14610: if ($captcha eq 'original') {
1.1094 raeburn 14611: $output = &create_captcha();
14612: unless ($output) {
14613: $error = 'captcha';
14614: }
14615: } elsif ($captcha eq 'recaptcha') {
14616: $output = &create_recaptcha($pubkey);
14617: unless ($output) {
1.1095 raeburn 14618: $error = 'recaptcha';
1.1094 raeburn 14619: }
14620: }
14621: return ($output,$error);
14622: }
14623:
14624: sub captcha_response {
14625: my ($context,$lonhost) = @_;
14626: my ($captcha_chk,$captcha_error);
14627: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14628: if ($captcha eq 'original') {
1.1094 raeburn 14629: ($captcha_chk,$captcha_error) = &check_captcha();
14630: } elsif ($captcha eq 'recaptcha') {
14631: $captcha_chk = &check_recaptcha($privkey);
14632: } else {
14633: $captcha_chk = 1;
14634: }
14635: return ($captcha_chk,$captcha_error);
14636: }
14637:
14638: sub get_captcha_config {
14639: my ($context,$lonhost) = @_;
1.1095 raeburn 14640: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 14641: my $hostname = &Apache::lonnet::hostname($lonhost);
14642: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14643: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 14644: if ($context eq 'usercreation') {
14645: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14646: if (ref($domconfig{$context}) eq 'HASH') {
14647: $hashtocheck = $domconfig{$context}{'cancreate'};
14648: if (ref($hashtocheck) eq 'HASH') {
14649: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14650: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14651: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14652: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14653: }
14654: if ($privkey && $pubkey) {
14655: $captcha = 'recaptcha';
14656: } else {
14657: $captcha = 'original';
14658: }
14659: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14660: $captcha = 'original';
14661: }
1.1094 raeburn 14662: }
1.1095 raeburn 14663: } else {
14664: $captcha = 'captcha';
14665: }
14666: } elsif ($context eq 'login') {
14667: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14668: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14669: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14670: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 14671: if ($privkey && $pubkey) {
14672: $captcha = 'recaptcha';
1.1095 raeburn 14673: } else {
14674: $captcha = 'original';
1.1094 raeburn 14675: }
1.1095 raeburn 14676: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14677: $captcha = 'original';
1.1094 raeburn 14678: }
14679: }
14680: return ($captcha,$pubkey,$privkey);
14681: }
14682:
14683: sub create_captcha {
14684: my %captcha_params = &captcha_settings();
14685: my ($output,$maxtries,$tries) = ('',10,0);
14686: while ($tries < $maxtries) {
14687: $tries ++;
14688: my $captcha = Authen::Captcha->new (
14689: output_folder => $captcha_params{'output_dir'},
14690: data_folder => $captcha_params{'db_dir'},
14691: );
14692: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14693:
14694: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14695: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14696: &mt('Type in the letters/numbers shown below').' '.
14697: '<input type="text" size="5" name="code" value="" /><br />'.
14698: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
14699: last;
14700: }
14701: }
14702: return $output;
14703: }
14704:
14705: sub captcha_settings {
14706: my %captcha_params = (
14707: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14708: www_output_dir => "/captchaspool",
14709: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14710: numchars => '5',
14711: );
14712: return %captcha_params;
14713: }
14714:
14715: sub check_captcha {
14716: my ($captcha_chk,$captcha_error);
14717: my $code = $env{'form.code'};
14718: my $md5sum = $env{'form.crypt'};
14719: my %captcha_params = &captcha_settings();
14720: my $captcha = Authen::Captcha->new(
14721: output_folder => $captcha_params{'output_dir'},
14722: data_folder => $captcha_params{'db_dir'},
14723: );
1.1109 raeburn 14724: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 14725: my %captcha_hash = (
14726: 0 => 'Code not checked (file error)',
14727: -1 => 'Failed: code expired',
14728: -2 => 'Failed: invalid code (not in database)',
14729: -3 => 'Failed: invalid code (code does not match crypt)',
14730: );
14731: if ($captcha_chk != 1) {
14732: $captcha_error = $captcha_hash{$captcha_chk}
14733: }
14734: return ($captcha_chk,$captcha_error);
14735: }
14736:
14737: sub create_recaptcha {
14738: my ($pubkey) = @_;
14739: my $captcha = Captcha::reCAPTCHA->new;
14740: return $captcha->get_options_setter({theme => 'white'})."\n".
14741: $captcha->get_html($pubkey).
14742: &mt('If either word is hard to read, [_1] will replace them.',
1.1133 raeburn 14743: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1094 raeburn 14744: '<br /><br />';
14745: }
14746:
14747: sub check_recaptcha {
14748: my ($privkey) = @_;
14749: my $captcha_chk;
14750: my $captcha = Captcha::reCAPTCHA->new;
14751: my $captcha_result =
14752: $captcha->check_answer(
14753: $privkey,
14754: $ENV{'REMOTE_ADDR'},
14755: $env{'form.recaptcha_challenge_field'},
14756: $env{'form.recaptcha_response_field'},
14757: );
14758: if ($captcha_result->{is_valid}) {
14759: $captcha_chk = 1;
14760: }
14761: return $captcha_chk;
14762: }
14763:
1.41 ng 14764: =pod
14765:
14766: =back
14767:
1.112 bowersj2 14768: =cut
1.41 ng 14769:
1.112 bowersj2 14770: 1;
14771: __END__;
1.41 ng 14772:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>